From 7ca375b0e4e6844155f4f788d0768e015c838bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cwangyougang=E2=80=9D?= Date: Sat, 3 Sep 2022 03:56:14 +0000 Subject: [PATCH 1/2] feat:fast offline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: “wangyougang” --- .../bluetooth/ble/softbus_adapter_ble_gatt.c | 2 +- core/authentication/include/auth_manager.h | 1 + .../authentication/src/auth_session_message.c | 5 ++- .../interface/bus_center_info_key.h | 1 + .../net_builder/include/lnn_fast_offline.h | 28 +++++++++++++ .../lnn/net_builder/include/lnn_net_builder.h | 1 + .../lnn/net_builder/net_builder.gni | 16 +++++++ .../src/lnn_fast_offline_virtual.c | 37 ++++++++++++++++ .../lnn/net_builder/src/lnn_net_builder.c | 2 + .../net_ledger/common/include/lnn_node_info.h | 1 + .../net_ledger/common/src/lnn_net_ledger.c | 4 ++ .../src/lnn_distributed_net_ledger.c | 12 ++++++ .../local_ledger/src/lnn_local_net_ledger.c | 42 ++++++++++++++++++- .../service/src/bus_center_manager.c | 5 +++ .../kits/bus_center/softbus_bus_center.h | 1 + 15 files changed, 155 insertions(+), 3 deletions(-) create mode 100644 core/bus_center/lnn/net_builder/include/lnn_fast_offline.h create mode 100644 core/bus_center/lnn/net_builder/src/lnn_fast_offline_virtual.c diff --git a/adapter/common/net/bluetooth/ble/softbus_adapter_ble_gatt.c b/adapter/common/net/bluetooth/ble/softbus_adapter_ble_gatt.c index 0d02b08b4c..9915834c46 100644 --- a/adapter/common/net/bluetooth/ble/softbus_adapter_ble_gatt.c +++ b/adapter/common/net/bluetooth/ble/softbus_adapter_ble_gatt.c @@ -27,7 +27,7 @@ #define SOFTBUS_SCAN_CLIENT_ID 0 #define ADV_MAX_NUM 4 -#define SCAN_MAX_NUM 2 +#define SCAN_MAX_NUM 3 typedef struct { int advId; diff --git a/core/authentication/include/auth_manager.h b/core/authentication/include/auth_manager.h index 0582a3782f..d38fbea6bb 100644 --- a/core/authentication/include/auth_manager.h +++ b/core/authentication/include/auth_manager.h @@ -24,6 +24,7 @@ #include "auth_session_fsm.h" #include "auth_session_key.h" #include "common_list.h" +#include "lnn_fast_offline.h" #ifdef __cplusplus #if __cplusplus diff --git a/core/authentication/src/auth_session_message.c b/core/authentication/src/auth_session_message.c index 1c383c943d..2033e94eec 100644 --- a/core/authentication/src/auth_session_message.c +++ b/core/authentication/src/auth_session_message.c @@ -62,6 +62,7 @@ #define P2P_MAC_ADDR "P2P_MAC_ADDR" #define P2P_ROLE "P2P_ROLE" #define TRANSPORT_PROTOCOL "TRANSPORT_PROTOCOL" +#define BLE_OFFLINE_CODE "BLE_OFFLINE_CODE" #define BUS_V1 1 #define BUS_V2 2 @@ -217,6 +218,7 @@ static void UnpackCommon(const cJSON *json, NodeInfo *info, SoftBusVersion versi (void)GetJsonObjectBoolItem(json, BLE_P2P, &info->isBleP2p); (void)GetJsonObjectNumberItem(json, P2P_ROLE, &info->p2pInfo.p2pRole); (void)GetJsonObjectStringItem(json, P2P_MAC_ADDR, info->p2pInfo.p2pMac, MAC_LEN); + (void)GetJsonObjectInt32Item(json, BLE_OFFLINE_CODE, (int *)&info->offLineCode); } static int32_t PackBt(cJSON *json, const NodeInfo *info, SoftBusVersion version) @@ -250,7 +252,8 @@ static int32_t PackWiFi(cJSON *json, const NodeInfo *info, SoftBusVersion versio !AddNumberToJsonObject(json, BUS_MIN_VERSION, BUS_V1) || !AddNumberToJsonObject(json, AUTH_PORT, LnnGetAuthPort(info)) || !AddNumberToJsonObject(json, SESSION_PORT, LnnGetSessionPort(info)) || - !AddNumberToJsonObject(json, PROXY_PORT, LnnGetProxyPort(info))) { + !AddNumberToJsonObject(json, PROXY_PORT, LnnGetProxyPort(info)) || + !AddNumberToJsonObject(json, BLE_OFFLINE_CODE, info->offLineCode)) { SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "add wifi info fail."); return SOFTBUS_ERR; } diff --git a/core/bus_center/interface/bus_center_info_key.h b/core/bus_center/interface/bus_center_info_key.h index 065bd12736..ca4dac41ae 100644 --- a/core/bus_center/interface/bus_center_info_key.h +++ b/core/bus_center/interface/bus_center_info_key.h @@ -52,6 +52,7 @@ typedef enum { NUM_KEY_P2P_ROLE, NUM_KEY_DISCOVERY_TYPE, NUM_KEY_TRANS_PROTOCOLS, + NUM_KEY_OFFLINE_CODE, NUM_KEY_END, BYTE_KEY_BEGIN, BYTE_KEY_USERID_HASH, diff --git a/core/bus_center/lnn/net_builder/include/lnn_fast_offline.h b/core/bus_center/lnn/net_builder/include/lnn_fast_offline.h new file mode 100644 index 0000000000..ed4a0ff03c --- /dev/null +++ b/core/bus_center/lnn/net_builder/include/lnn_fast_offline.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LNN_FAST_OFFLINE_H +#define LNN_FAST_OFFLINE_H + +#include + +#include "softbus_errcode.h" +#include "softbus_log.h" + +int32_t LnnBleFastOfflineOnceBegin(void); +int32_t LnnInitFastOffline(void); +int32_t LnnDeinitFastOffline(); + +#endif \ No newline at end of file diff --git a/core/bus_center/lnn/net_builder/include/lnn_net_builder.h b/core/bus_center/lnn/net_builder/include/lnn_net_builder.h index ea9bcd92a8..59249a259f 100644 --- a/core/bus_center/lnn/net_builder/include/lnn_net_builder.h +++ b/core/bus_center/lnn/net_builder/include/lnn_net_builder.h @@ -21,6 +21,7 @@ #include "auth_interface.h" #include "lnn_sync_info_manager.h" #include "softbus_bus_center.h" +#include "lnn_fast_offline.h" #ifdef __cplusplus extern "C" { diff --git a/core/bus_center/lnn/net_builder/net_builder.gni b/core/bus_center/lnn/net_builder/net_builder.gni index 6981abe42b..0e278ca97f 100644 --- a/core/bus_center/lnn/net_builder/net_builder.gni +++ b/core/bus_center/lnn/net_builder/net_builder.gni @@ -13,6 +13,15 @@ import("//foundation/communication/dsoftbus/dsoftbus.gni") +native_source_path = rebase_path("$dsoftbus_root_path") +lnn_dep_dir = "dsoftbus_enhance/core/bus_center/lnn/net_builder" +enhanced = exec_script("$dsoftbus_root_path/check_sub_module.py", + [ + "$native_source_path", + "$lnn_dep_dir", + ], + "value") + if (dsoftbus_feature_lnn_net) { bus_center_builder_src = [ "$dsoftbus_root_path/core/bus_center/lnn/net_builder/src/lnn_connection_fsm.c", @@ -22,6 +31,9 @@ if (dsoftbus_feature_lnn_net) { "$dsoftbus_root_path/core/bus_center/lnn/net_builder/src/lnn_sync_info_manager.c", "$dsoftbus_root_path/core/bus_center/lnn/net_builder/src/lnn_topo_manager.c", ] + if (!enhanced) { + bus_center_builder_src += [ "$dsoftbus_root_path/core/bus_center/lnn/net_builder/src/lnn_fast_offline_virtual.c" ] + } } else { bus_center_builder_src = [ "$dsoftbus_root_path/core/bus_center/lnn/net_builder/src/lnn_net_builder_virtual.c" ] } @@ -31,3 +43,7 @@ bus_center_builder_inc = [ "$dsoftbus_root_path/core/common/dfx/hisysevent_adapter/include", ] bus_center_builder_deps = [] + +if (dsoftbus_feature_lnn_net && enhanced) { + bus_center_builder_deps += [ "$dsoftbus_root_path/dsoftbus_enhance/core/bus_center/lnn/net_builder/fast_offline:fast_offline" ] +} diff --git a/core/bus_center/lnn/net_builder/src/lnn_fast_offline_virtual.c b/core/bus_center/lnn/net_builder/src/lnn_fast_offline_virtual.c new file mode 100644 index 0000000000..097008ec83 --- /dev/null +++ b/core/bus_center/lnn/net_builder/src/lnn_fast_offline_virtual.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "lnn_fast_offline.h" + +#include "softbus_errcode.h" +#include "softbus_log.h" + +int32_t LnnBleFastOfflineOnceBegin(void) +{ + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "LnnBleFastOfflineOnceBegin virtual ok!"); + return SOFTBUS_OK; +} + +int32_t LnnInitFastOffline(void) +{ + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "Init fast offline virtual ok!"); + return SOFTBUS_OK; +} + +int32_t LnnDeinitFastOffline(void) +{ + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "Deinit fast offline virtual ok!"); + return SOFTBUS_OK; +} \ No newline at end of file diff --git a/core/bus_center/lnn/net_builder/src/lnn_net_builder.c b/core/bus_center/lnn/net_builder/src/lnn_net_builder.c index 29bd831e3b..bb08105d09 100644 --- a/core/bus_center/lnn/net_builder/src/lnn_net_builder.c +++ b/core/bus_center/lnn/net_builder/src/lnn_net_builder.c @@ -40,6 +40,7 @@ #include "softbus_feature_config.h" #include "softbus_json_utils.h" #include "softbus_log.h" +#include "lnn_fast_offline.h" #define LNN_CONN_CAPABILITY_MSG_LEN 8 #define DEFAULT_MAX_LNN_CONNECTION_COUNT 10 @@ -1550,6 +1551,7 @@ void LnnDeinitNetBuilder(void) LnnDeinitTopoManager(); LnnDeinitP2p(); LnnDeinitSyncInfoManager(); + LnnDeinitFastOffline(); g_netBuilder.isInit = false; } diff --git a/core/bus_center/lnn/net_ledger/common/include/lnn_node_info.h b/core/bus_center/lnn/net_ledger/common/include/lnn_node_info.h index 02a62f37ae..38551e4151 100644 --- a/core/bus_center/lnn/net_ledger/common/include/lnn_node_info.h +++ b/core/bus_center/lnn/net_ledger/common/include/lnn_node_info.h @@ -87,6 +87,7 @@ typedef struct { P2pInfo p2pInfo; uint64_t supportedProtocols; char accountHash[SHA_256_HASH_LEN]; + uint32_t offLineCode; } NodeInfo; const char *LnnGetDeviceUdid(const NodeInfo *info); diff --git a/core/bus_center/lnn/net_ledger/common/src/lnn_net_ledger.c b/core/bus_center/lnn/net_ledger/common/src/lnn_net_ledger.c index 986ce1e0a4..ab3556e2e9 100644 --- a/core/bus_center/lnn/net_ledger/common/src/lnn_net_ledger.c +++ b/core/bus_center/lnn/net_ledger/common/src/lnn_net_ledger.c @@ -78,6 +78,8 @@ static int32_t LnnGetNodeKeyInfoLocal(const char *networkId, int key, uint8_t *i return LnnGetLocalNumInfo(NUM_KEY_NET_CAP, (int32_t *)info); case NODE_KEY_NETWORK_TYPE: return LnnGetLocalNumInfo(NUM_KEY_DISCOVERY_TYPE, (int32_t *)info); + case NODE_KEY_BLE_OFFLINE_CODE: + return LnnGetLocalNumInfo(NUM_KEY_OFFLINE_CODE, (int32_t *)info); default: SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "invalid node key type: %d", key); return SOFTBUS_ERR; @@ -105,6 +107,8 @@ static int32_t LnnGetNodeKeyInfoRemote(const char *networkId, int key, uint8_t * return LnnGetRemoteNumInfo(networkId, NUM_KEY_NET_CAP, (int32_t *)info); case NODE_KEY_NETWORK_TYPE: return LnnGetRemoteNumInfo(networkId, NUM_KEY_DISCOVERY_TYPE, (int32_t *)info); + case NODE_KEY_BLE_OFFLINE_CODE: + return LnnGetRemoteNumInfo(networkId, NUM_KEY_OFFLINE_CODE, (int32_t *)info); default: SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "invalid node key type: %d", key); return SOFTBUS_ERR; diff --git a/core/bus_center/lnn/net_ledger/distributed_ledger/src/lnn_distributed_net_ledger.c b/core/bus_center/lnn/net_ledger/distributed_ledger/src/lnn_distributed_net_ledger.c index d6b9e45804..448b7efdaf 100644 --- a/core/bus_center/lnn/net_ledger/distributed_ledger/src/lnn_distributed_net_ledger.c +++ b/core/bus_center/lnn/net_ledger/distributed_ledger/src/lnn_distributed_net_ledger.c @@ -385,6 +385,17 @@ static int32_t DlGetDeviceUuid(const char *networkId, void *buf, uint32_t len) return SOFTBUS_OK; } +static int32_t DlGetDeviceOfflineCode(const char *networkId, void *buf, uint32_t len) +{ + NodeInfo *info = NULL; + RETURN_IF_GET_NODE_VALID(networkId, buf, info); + if (memcpy_s(buf, len, &(info->offLineCode), sizeof(info->offLineCode)) != EOK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "memcpy_s offLineCode ERROR!"); + return SOFTBUS_MEM_ERR; + } + return SOFTBUS_OK; +} + static int32_t DlGetDeviceUdid(const char *networkId, void *buf, uint32_t len) { const char *udid = NULL; @@ -664,6 +675,7 @@ static DistributedLedgerKey g_dlKeyTable[] = { {NUM_KEY_DISCOVERY_TYPE, DlGetNetType}, {NUM_KEY_MASTER_NODE_WEIGHT, DlGetMasterWeight}, {NUM_KEY_P2P_ROLE, DlGetP2pRole}, + {NUM_KEY_OFFLINE_CODE, DlGetDeviceOfflineCode}, }; static char *CreateCnnCodeKey(const char *uuid, DiscoveryType type) diff --git a/core/bus_center/lnn/net_ledger/local_ledger/src/lnn_local_net_ledger.c b/core/bus_center/lnn/net_ledger/local_ledger/src/lnn_local_net_ledger.c index a18073fa6c..dbede93fd0 100644 --- a/core/bus_center/lnn/net_ledger/local_ledger/src/lnn_local_net_ledger.c +++ b/core/bus_center/lnn/net_ledger/local_ledger/src/lnn_local_net_ledger.c @@ -30,11 +30,13 @@ #include "softbus_log.h" #include "softbus_utils.h" #include "softbus_hidumper_buscenter.h" +#include "softbus_adapter_crypto.h" #define SOFTBUS_VERSION "hm.1.0.0" #define VERSION_TYPE_LITE "LITE" #define VERSION_TYPE_DEFAULT "" #define NUM_BUF_SIZE 4 +#define OFFLINE_CODE_LEN 4 #define SOFTBUS_BUSCENTER_DUMP_LOCALDEVICEINFO "local_device_info" @@ -95,6 +97,20 @@ static int32_t LlGetNetworkId(void *buf, uint32_t len) return SOFTBUS_OK; } +static int32_t LlGetOffLineCode(void *buf, uint32_t len) +{ + NodeInfo *info = &g_localNetLedger.localInfo; + if (buf == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "buf is null!"); + return SOFTBUS_INVALID_PARAM; + } + if (memcpy_s(buf, len, &(info->offLineCode), sizeof(info->offLineCode)) != EOK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "memcpy_s offLineCode ERROR!"); + return SOFTBUS_MEM_ERR; + } + return SOFTBUS_OK; +} + static int32_t LlGetUuid(void *buf, uint32_t len) { NodeInfo *info = &g_localNetLedger.localInfo; @@ -462,6 +478,19 @@ static int32_t InitLocalVersionType(NodeInfo *info) return SOFTBUS_OK; } +static int32_t InitOffLineCode(NodeInfo *info) +{ + if (info == NULL) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "fail:para error!"); + return SOFTBUS_INVALID_PARAM; + } + if (SoftBusGenerateRandomArray((unsigned char *)(&(info->offLineCode)), sizeof(info->offLineCode)) != SOFTBUS_OK) { + HILOG_ERROR(SOFTBUS_HILOG_ID, "generate offLineCode error."); + return SOFTBUS_MEM_ERR; + } + return SOFTBUS_OK; +} + static int32_t InitConnectInfo(ConnectInfo *info) { if (info == NULL) { @@ -500,6 +529,11 @@ static int32_t UpdateLocalNetworkId(const void *id) return ModifyId(g_localNetLedger.localInfo.networkId, NETWORK_ID_BUF_LEN, (char *)id); } +static int32_t LlUpdateLocalOffLineCode(const void *id) +{ + return ModifyId((char*)&(g_localNetLedger.localInfo.offLineCode), OFFLINE_CODE_LEN, (char *)id); +} + static int32_t UpdateLocalUuid(const void *id) { return ModifyId(g_localNetLedger.localInfo.uuid, UUID_BUF_LEN, (char *)id); @@ -694,7 +728,8 @@ static LocalLedgerKey g_localKeyTable[] = { {NUM_KEY_MASTER_NODE_WEIGHT, -1, L1GetMasterNodeWeight, UpdateMasgerNodeWeight}, {NUM_KEY_P2P_ROLE, -1, L1GetP2pRole, UpdateP2pRole}, {NUM_KEY_TRANS_PROTOCOLS, sizeof(int64_t), LlGetSupportedProtocols, LlUpdateSupportedProtocols}, - {BYTE_KEY_USERID_HASH, SHA_256_HASH_LEN, LlGetAccount, LlUpdateAccount} + {BYTE_KEY_USERID_HASH, SHA_256_HASH_LEN, LlGetAccount, LlUpdateAccount}, + {NUM_KEY_OFFLINE_CODE, OFFLINE_CODE_LEN, LlGetOffLineCode, LlUpdateLocalOffLineCode} }; int32_t LnnGetLocalStrInfo(InfoKey key, char *info, uint32_t len) @@ -913,6 +948,11 @@ int32_t LnnInitLocalLedger(void) } nodeInfo->netCapacity = LnnGetNetCapabilty(); DeviceBasicInfo *deviceInfo = &nodeInfo->deviceInfo; + if (InitOffLineCode(nodeInfo) != SOFTBUS_OK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Init offLineCode error!"); + g_localNetLedger.status = LL_INIT_SUCCESS; + return SOFTBUS_OK; + } if (InitLocalDeviceInfo(deviceInfo) != SOFTBUS_OK) { SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "init local device info error!"); goto EXIT; diff --git a/core/bus_center/service/src/bus_center_manager.c b/core/bus_center/service/src/bus_center_manager.c index 7d341e1ff7..adf9409016 100644 --- a/core/bus_center/service/src/bus_center_manager.c +++ b/core/bus_center/service/src/bus_center_manager.c @@ -30,6 +30,7 @@ #include "softbus_feature_config.h" #include "softbus_log.h" #include "softbus_utils.h" +#include "lnn_fast_offline.h" #define DEFAULT_DELAY_LEN 1000 #define RETRY_MAX 10 @@ -176,6 +177,10 @@ int32_t BusCenterServerInit(void) SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "start delay init fail!"); return SOFTBUS_ERR; } + if (LnnInitFastOffline() != SOFTBUS_OK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "fast offline init fail!"); + return SOFTBUS_ERR; + } SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "bus center server init ok"); return SOFTBUS_OK; } diff --git a/interfaces/kits/bus_center/softbus_bus_center.h b/interfaces/kits/bus_center/softbus_bus_center.h index 51b0f799f0..24f2271f0c 100644 --- a/interfaces/kits/bus_center/softbus_bus_center.h +++ b/interfaces/kits/bus_center/softbus_bus_center.h @@ -136,6 +136,7 @@ typedef enum { NODE_KEY_DEV_NAME, /**< Device name in string format */ NODE_KEY_NETWORK_CAPABILITY, /**< Network capability in number format */ NODE_KEY_NETWORK_TYPE, /**< Network type in number format */ + NODE_KEY_BLE_OFFLINE_CODE, /**< Ble offlinecode in string format */ } NodeDeviceInfoKey; /** -- Gitee From 05515eb93db099ba5e3fcba59ce9ffb107f8c683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cwangyougang=E2=80=9D?= Date: Sat, 3 Sep 2022 07:06:37 +0000 Subject: [PATCH 2/2] feat:fast offline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: “wangyougang” --- core/authentication/include/auth_manager.h | 1 - .../authentication/src/auth_session_message.c | 6 +-- .../interface/bus_center_info_key.h | 2 +- .../net_builder/include/lnn_fast_offline.h | 2 +- .../lnn/net_builder/include/lnn_net_builder.h | 1 - .../src/lnn_fast_offline_virtual.c | 3 +- .../lnn/net_builder/src/lnn_net_builder.c | 2 +- .../net_ledger/common/include/lnn_node_info.h | 4 +- .../net_ledger/common/src/lnn_net_ledger.c | 8 ++-- .../src/lnn_distributed_net_ledger.c | 11 ++++-- .../local_ledger/src/lnn_local_net_ledger.c | 37 ++++++++++--------- 11 files changed, 41 insertions(+), 36 deletions(-) diff --git a/core/authentication/include/auth_manager.h b/core/authentication/include/auth_manager.h index d38fbea6bb..0582a3782f 100644 --- a/core/authentication/include/auth_manager.h +++ b/core/authentication/include/auth_manager.h @@ -24,7 +24,6 @@ #include "auth_session_fsm.h" #include "auth_session_key.h" #include "common_list.h" -#include "lnn_fast_offline.h" #ifdef __cplusplus #if __cplusplus diff --git a/core/authentication/src/auth_session_message.c b/core/authentication/src/auth_session_message.c index 2033e94eec..900cf54ff7 100644 --- a/core/authentication/src/auth_session_message.c +++ b/core/authentication/src/auth_session_message.c @@ -62,7 +62,7 @@ #define P2P_MAC_ADDR "P2P_MAC_ADDR" #define P2P_ROLE "P2P_ROLE" #define TRANSPORT_PROTOCOL "TRANSPORT_PROTOCOL" -#define BLE_OFFLINE_CODE "BLE_OFFLINE_CODE" +#define BLE_OFFLINE_CODE "OFFLINE_CODE" #define BUS_V1 1 #define BUS_V2 2 @@ -218,7 +218,7 @@ static void UnpackCommon(const cJSON *json, NodeInfo *info, SoftBusVersion versi (void)GetJsonObjectBoolItem(json, BLE_P2P, &info->isBleP2p); (void)GetJsonObjectNumberItem(json, P2P_ROLE, &info->p2pInfo.p2pRole); (void)GetJsonObjectStringItem(json, P2P_MAC_ADDR, info->p2pInfo.p2pMac, MAC_LEN); - (void)GetJsonObjectInt32Item(json, BLE_OFFLINE_CODE, (int *)&info->offLineCode); + (void)GetJsonObjectStringItem(json, BLE_OFFLINE_CODE, info->offlineCode, OFFLINE_CODE_LEN); } static int32_t PackBt(cJSON *json, const NodeInfo *info, SoftBusVersion version) @@ -253,7 +253,7 @@ static int32_t PackWiFi(cJSON *json, const NodeInfo *info, SoftBusVersion versio !AddNumberToJsonObject(json, AUTH_PORT, LnnGetAuthPort(info)) || !AddNumberToJsonObject(json, SESSION_PORT, LnnGetSessionPort(info)) || !AddNumberToJsonObject(json, PROXY_PORT, LnnGetProxyPort(info)) || - !AddNumberToJsonObject(json, BLE_OFFLINE_CODE, info->offLineCode)) { + !AddStringToJsonObject(json, BLE_OFFLINE_CODE, info->offlineCode)) { SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "add wifi info fail."); return SOFTBUS_ERR; } diff --git a/core/bus_center/interface/bus_center_info_key.h b/core/bus_center/interface/bus_center_info_key.h index ca4dac41ae..0963198ed9 100644 --- a/core/bus_center/interface/bus_center_info_key.h +++ b/core/bus_center/interface/bus_center_info_key.h @@ -41,6 +41,7 @@ typedef enum { STRING_KEY_P2P_MAC, STRING_KEY_P2P_GO_MAC, STRING_KEY_NODE_ADDR, + STRING_KEY_OFFLINE_CODE, STRING_KEY_END, NUM_KEY_BEGIN = 100, NUM_KEY_SESSION_PORT = NUM_KEY_BEGIN, @@ -52,7 +53,6 @@ typedef enum { NUM_KEY_P2P_ROLE, NUM_KEY_DISCOVERY_TYPE, NUM_KEY_TRANS_PROTOCOLS, - NUM_KEY_OFFLINE_CODE, NUM_KEY_END, BYTE_KEY_BEGIN, BYTE_KEY_USERID_HASH, diff --git a/core/bus_center/lnn/net_builder/include/lnn_fast_offline.h b/core/bus_center/lnn/net_builder/include/lnn_fast_offline.h index ed4a0ff03c..55879d6ec3 100644 --- a/core/bus_center/lnn/net_builder/include/lnn_fast_offline.h +++ b/core/bus_center/lnn/net_builder/include/lnn_fast_offline.h @@ -23,6 +23,6 @@ int32_t LnnBleFastOfflineOnceBegin(void); int32_t LnnInitFastOffline(void); -int32_t LnnDeinitFastOffline(); +void LnnDeinitFastOffline(void); #endif \ No newline at end of file diff --git a/core/bus_center/lnn/net_builder/include/lnn_net_builder.h b/core/bus_center/lnn/net_builder/include/lnn_net_builder.h index 59249a259f..ea9bcd92a8 100644 --- a/core/bus_center/lnn/net_builder/include/lnn_net_builder.h +++ b/core/bus_center/lnn/net_builder/include/lnn_net_builder.h @@ -21,7 +21,6 @@ #include "auth_interface.h" #include "lnn_sync_info_manager.h" #include "softbus_bus_center.h" -#include "lnn_fast_offline.h" #ifdef __cplusplus extern "C" { diff --git a/core/bus_center/lnn/net_builder/src/lnn_fast_offline_virtual.c b/core/bus_center/lnn/net_builder/src/lnn_fast_offline_virtual.c index 097008ec83..06fc98707c 100644 --- a/core/bus_center/lnn/net_builder/src/lnn_fast_offline_virtual.c +++ b/core/bus_center/lnn/net_builder/src/lnn_fast_offline_virtual.c @@ -30,8 +30,7 @@ int32_t LnnInitFastOffline(void) return SOFTBUS_OK; } -int32_t LnnDeinitFastOffline(void) +void LnnDeinitFastOffline(void) { SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "Deinit fast offline virtual ok!"); - return SOFTBUS_OK; } \ No newline at end of file diff --git a/core/bus_center/lnn/net_builder/src/lnn_net_builder.c b/core/bus_center/lnn/net_builder/src/lnn_net_builder.c index bb08105d09..429486392b 100644 --- a/core/bus_center/lnn/net_builder/src/lnn_net_builder.c +++ b/core/bus_center/lnn/net_builder/src/lnn_net_builder.c @@ -27,6 +27,7 @@ #include "lnn_connection_fsm.h" #include "lnn_discovery_manager.h" #include "lnn_distributed_net_ledger.h" +#include "lnn_fast_offline.h" #include "lnn_local_net_ledger.h" #include "lnn_network_id.h" #include "lnn_network_manager.h" @@ -40,7 +41,6 @@ #include "softbus_feature_config.h" #include "softbus_json_utils.h" #include "softbus_log.h" -#include "lnn_fast_offline.h" #define LNN_CONN_CAPABILITY_MSG_LEN 8 #define DEFAULT_MAX_LNN_CONNECTION_COUNT 10 diff --git a/core/bus_center/lnn/net_ledger/common/include/lnn_node_info.h b/core/bus_center/lnn/net_ledger/common/include/lnn_node_info.h index 38551e4151..570db4f928 100644 --- a/core/bus_center/lnn/net_ledger/common/include/lnn_node_info.h +++ b/core/bus_center/lnn/net_ledger/common/include/lnn_node_info.h @@ -28,6 +28,8 @@ extern "C" { #endif #define WIFI_SSID_LEN 32 #define WIFI_MAC_LEN 6 +#define OFFLINE_CODE_LEN 32 +#define OFFLINE_CODE_BYTE_SIZE 4 #define LNN_RELATION_MASK 0x03 @@ -87,7 +89,7 @@ typedef struct { P2pInfo p2pInfo; uint64_t supportedProtocols; char accountHash[SHA_256_HASH_LEN]; - uint32_t offLineCode; + char offlineCode[OFFLINE_CODE_LEN]; } NodeInfo; const char *LnnGetDeviceUdid(const NodeInfo *info); diff --git a/core/bus_center/lnn/net_ledger/common/src/lnn_net_ledger.c b/core/bus_center/lnn/net_ledger/common/src/lnn_net_ledger.c index ab3556e2e9..269e78764f 100644 --- a/core/bus_center/lnn/net_ledger/common/src/lnn_net_ledger.c +++ b/core/bus_center/lnn/net_ledger/common/src/lnn_net_ledger.c @@ -74,12 +74,12 @@ static int32_t LnnGetNodeKeyInfoLocal(const char *networkId, int key, uint8_t *i return LnnGetLocalStrInfo(STRING_KEY_WLAN_IP, (char *)info, infoLen); case NODE_KEY_DEV_NAME: return LnnGetLocalStrInfo(STRING_KEY_DEV_NAME, (char *)info, infoLen); + case NODE_KEY_BLE_OFFLINE_CODE: + return LnnGetLocalStrInfo(STRING_KEY_OFFLINE_CODE, (char *)info, infoLen); case NODE_KEY_NETWORK_CAPABILITY: return LnnGetLocalNumInfo(NUM_KEY_NET_CAP, (int32_t *)info); case NODE_KEY_NETWORK_TYPE: return LnnGetLocalNumInfo(NUM_KEY_DISCOVERY_TYPE, (int32_t *)info); - case NODE_KEY_BLE_OFFLINE_CODE: - return LnnGetLocalNumInfo(NUM_KEY_OFFLINE_CODE, (int32_t *)info); default: SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "invalid node key type: %d", key); return SOFTBUS_ERR; @@ -103,12 +103,12 @@ static int32_t LnnGetNodeKeyInfoRemote(const char *networkId, int key, uint8_t * return LnnGetRemoteStrInfo(networkId, STRING_KEY_WLAN_IP, (char *)info, infoLen); case NODE_KEY_DEV_NAME: return LnnGetRemoteStrInfo(networkId, STRING_KEY_DEV_NAME, (char *)info, infoLen); + case NODE_KEY_BLE_OFFLINE_CODE: + return LnnGetRemoteStrInfo(networkId, STRING_KEY_OFFLINE_CODE, (char *)info, infoLen); case NODE_KEY_NETWORK_CAPABILITY: return LnnGetRemoteNumInfo(networkId, NUM_KEY_NET_CAP, (int32_t *)info); case NODE_KEY_NETWORK_TYPE: return LnnGetRemoteNumInfo(networkId, NUM_KEY_DISCOVERY_TYPE, (int32_t *)info); - case NODE_KEY_BLE_OFFLINE_CODE: - return LnnGetRemoteNumInfo(networkId, NUM_KEY_OFFLINE_CODE, (int32_t *)info); default: SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "invalid node key type: %d", key); return SOFTBUS_ERR; diff --git a/core/bus_center/lnn/net_ledger/distributed_ledger/src/lnn_distributed_net_ledger.c b/core/bus_center/lnn/net_ledger/distributed_ledger/src/lnn_distributed_net_ledger.c index 448b7efdaf..430d82a12d 100644 --- a/core/bus_center/lnn/net_ledger/distributed_ledger/src/lnn_distributed_net_ledger.c +++ b/core/bus_center/lnn/net_ledger/distributed_ledger/src/lnn_distributed_net_ledger.c @@ -22,6 +22,7 @@ #include #include "lnn_connection_addr_utils.h" +#include "lnn_fast_offline.h" #include "lnn_lane_info.h" #include "lnn_map.h" #include "softbus_adapter_mem.h" @@ -389,8 +390,8 @@ static int32_t DlGetDeviceOfflineCode(const char *networkId, void *buf, uint32_t { NodeInfo *info = NULL; RETURN_IF_GET_NODE_VALID(networkId, buf, info); - if (memcpy_s(buf, len, &(info->offLineCode), sizeof(info->offLineCode)) != EOK) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "memcpy_s offLineCode ERROR!"); + if (memcpy_s(buf, len, info->offlineCode, OFFLINE_CODE_LEN) != EOK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "memcpy_s offlinecode ERROR!"); return SOFTBUS_MEM_ERR; } return SOFTBUS_OK; @@ -668,6 +669,7 @@ static DistributedLedgerKey g_dlKeyTable[] = { {STRING_KEY_P2P_MAC, DlGetP2pMac}, {STRING_KEY_P2P_GO_MAC, DlGetP2pGoMac}, {STRING_KEY_NODE_ADDR, DlGetNodeAddr}, + {STRING_KEY_OFFLINE_CODE, DlGetDeviceOfflineCode}, {NUM_KEY_SESSION_PORT, DlGetSessionPort}, {NUM_KEY_AUTH_PORT, DlGetAuthPort}, {NUM_KEY_PROXY_PORT, DlGetProxyPort}, @@ -675,7 +677,6 @@ static DistributedLedgerKey g_dlKeyTable[] = { {NUM_KEY_DISCOVERY_TYPE, DlGetNetType}, {NUM_KEY_MASTER_NODE_WEIGHT, DlGetMasterWeight}, {NUM_KEY_P2P_ROLE, DlGetP2pRole}, - {NUM_KEY_OFFLINE_CODE, DlGetDeviceOfflineCode}, }; static char *CreateCnnCodeKey(const char *uuid, DiscoveryType type) @@ -852,6 +853,10 @@ ReportCategory LnnSetNodeOffline(const char *udid, ConnectionAddrType type, int3 return REPORT_NONE; } LnnClearDiscoveryType(info, LnnConvAddrTypeToDiscType(type)); + if (!LnnHasDiscoveryType(info, DISCOVERY_TYPE_WIFI) && (type == CONNECTION_ADDR_WLAN || + type == CONNECTION_ADDR_ETH)) { + LnnBleFastOfflineOnceBegin(); + } if (info->discoveryType != 0) { SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "discoveryType=%u after clear, not need to report offline.", info->discoveryType); diff --git a/core/bus_center/lnn/net_ledger/local_ledger/src/lnn_local_net_ledger.c b/core/bus_center/lnn/net_ledger/local_ledger/src/lnn_local_net_ledger.c index dbede93fd0..3363ab4107 100644 --- a/core/bus_center/lnn/net_ledger/local_ledger/src/lnn_local_net_ledger.c +++ b/core/bus_center/lnn/net_ledger/local_ledger/src/lnn_local_net_ledger.c @@ -18,25 +18,23 @@ #include #include #include - #include #include "bus_center_adapter.h" #include "bus_center_manager.h" #include "lnn_ohos_account.h" #include "lnn_p2p_info.h" +#include "softbus_adapter_crypto.h" #include "softbus_adapter_thread.h" #include "softbus_errcode.h" #include "softbus_log.h" #include "softbus_utils.h" #include "softbus_hidumper_buscenter.h" -#include "softbus_adapter_crypto.h" #define SOFTBUS_VERSION "hm.1.0.0" #define VERSION_TYPE_LITE "LITE" #define VERSION_TYPE_DEFAULT "" #define NUM_BUF_SIZE 4 -#define OFFLINE_CODE_LEN 4 #define SOFTBUS_BUSCENTER_DUMP_LOCALDEVICEINFO "local_device_info" @@ -101,11 +99,11 @@ static int32_t LlGetOffLineCode(void *buf, uint32_t len) { NodeInfo *info = &g_localNetLedger.localInfo; if (buf == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "buf is null!"); + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "buf of offlinecode is null!"); return SOFTBUS_INVALID_PARAM; } - if (memcpy_s(buf, len, &(info->offLineCode), sizeof(info->offLineCode)) != EOK) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "memcpy_s offLineCode ERROR!"); + if (memcpy_s(buf, len, info->offlineCode, OFFLINE_CODE_LEN) != EOK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "memcpy_s offlinecode ERROR!"); return SOFTBUS_MEM_ERR; } return SOFTBUS_OK; @@ -478,15 +476,19 @@ static int32_t InitLocalVersionType(NodeInfo *info) return SOFTBUS_OK; } -static int32_t InitOffLineCode(NodeInfo *info) +static int32_t InitOfflineCode(NodeInfo *info) { if (info == NULL) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "fail:para error!"); + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "info of offlinecode is null!"); return SOFTBUS_INVALID_PARAM; } - if (SoftBusGenerateRandomArray((unsigned char *)(&(info->offLineCode)), sizeof(info->offLineCode)) != SOFTBUS_OK) { - HILOG_ERROR(SOFTBUS_HILOG_ID, "generate offLineCode error."); - return SOFTBUS_MEM_ERR; + if (memset_s(info->offlineCode, OFFLINE_CODE_BYTE_SIZE, 0, OFFLINE_CODE_BYTE_SIZE) != EOK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "offlineCode memset_s failed"); + return SOFTBUS_ERR; + } + if (SoftBusGenerateRandomArray((unsigned char *)info->offlineCode, OFFLINE_CODE_BYTE_SIZE) != SOFTBUS_OK) { + HILOG_ERROR(SOFTBUS_HILOG_ID, "generate offlinecode error."); + return SOFTBUS_ERR; } return SOFTBUS_OK; } @@ -531,7 +533,7 @@ static int32_t UpdateLocalNetworkId(const void *id) static int32_t LlUpdateLocalOffLineCode(const void *id) { - return ModifyId((char*)&(g_localNetLedger.localInfo.offLineCode), OFFLINE_CODE_LEN, (char *)id); + return ModifyId(g_localNetLedger.localInfo.offlineCode, OFFLINE_CODE_LEN, (char *)id); } static int32_t UpdateLocalUuid(const void *id) @@ -719,6 +721,7 @@ static LocalLedgerKey g_localKeyTable[] = { {STRING_KEY_NODE_ADDR, SHORT_ADDRESS_MAX_LEN, LlGetNodeAddr, LlUpdateNodeAddr}, {STRING_KEY_P2P_MAC, MAC_LEN, LlGetP2pMac, UpdateP2pMac}, {STRING_KEY_P2P_GO_MAC, MAC_LEN, LlGetP2pGoMac, UpdateP2pGoMac}, + {STRING_KEY_OFFLINE_CODE, OFFLINE_CODE_LEN, LlGetOffLineCode, LlUpdateLocalOffLineCode}, {NUM_KEY_SESSION_PORT, -1, LlGetSessionPort, UpdateLocalSessionPort}, {NUM_KEY_AUTH_PORT, -1, LlGetAuthPort, UpdateLocalAuthPort}, {NUM_KEY_PROXY_PORT, -1, LlGetProxyPort, UpdateLocalProxyPort}, @@ -728,8 +731,7 @@ static LocalLedgerKey g_localKeyTable[] = { {NUM_KEY_MASTER_NODE_WEIGHT, -1, L1GetMasterNodeWeight, UpdateMasgerNodeWeight}, {NUM_KEY_P2P_ROLE, -1, L1GetP2pRole, UpdateP2pRole}, {NUM_KEY_TRANS_PROTOCOLS, sizeof(int64_t), LlGetSupportedProtocols, LlUpdateSupportedProtocols}, - {BYTE_KEY_USERID_HASH, SHA_256_HASH_LEN, LlGetAccount, LlUpdateAccount}, - {NUM_KEY_OFFLINE_CODE, OFFLINE_CODE_LEN, LlGetOffLineCode, LlUpdateLocalOffLineCode} + {BYTE_KEY_USERID_HASH, SHA_256_HASH_LEN, LlGetAccount, LlUpdateAccount} }; int32_t LnnGetLocalStrInfo(InfoKey key, char *info, uint32_t len) @@ -948,10 +950,9 @@ int32_t LnnInitLocalLedger(void) } nodeInfo->netCapacity = LnnGetNetCapabilty(); DeviceBasicInfo *deviceInfo = &nodeInfo->deviceInfo; - if (InitOffLineCode(nodeInfo) != SOFTBUS_OK) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Init offLineCode error!"); - g_localNetLedger.status = LL_INIT_SUCCESS; - return SOFTBUS_OK; + if (InitOfflineCode(nodeInfo) != SOFTBUS_OK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "init offlineCode error!"); + goto EXIT; } if (InitLocalDeviceInfo(deviceInfo) != SOFTBUS_OK) { SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "init local device info error!"); -- Gitee