Description:code sync

Feature or Bugfix:Bugfix
Binary Source:NA

Signed-off-by: sun-jiashun-123 <sunjiashun@huawei.com>
This commit is contained in:
sun-jiashun-123 2024-11-12 16:19:38 +08:00
parent 1fd2ef2514
commit b3472e8cd5
70 changed files with 624 additions and 365 deletions

View File

@ -1629,8 +1629,8 @@ static int32_t StartScanSub(int32_t listenerId)
DISC_LOGI(DISC_BROADCAST, "start service srvType=%{public}s, listenerId=%{public}d, adapterId=%{public}d,"
"interval=%{public}hu, window=%{public}hu, callCount=%{public}u",
GetSrvType(g_scanManager[listenerId].srvType), listenerId, g_scanManager[listenerId].adapterScanId,
adapterParam.scanInterval, adapterParam.scanWindow, callCount++);
GetSrvType(g_scanManager[listenerId].srvType), listenerId,
g_scanManager[listenerId].adapterScanId, adapterParam.scanInterval, adapterParam.scanWindow, callCount++);
int32_t ret = g_interface[g_interfaceId]->StartScan(g_scanManager[listenerId].adapterScanId, &adapterParam,
adapterFilter, filterSize);
g_scanManager[listenerId].isNeedReset = false;

View File

@ -61,10 +61,6 @@ static EVP_CIPHER *GetCtrAlgorithmByKeyLen(uint32_t keyLen)
static int32_t OpensslEvpInit(EVP_CIPHER_CTX **ctx, const AesGcmCipherKey *cipherkey, bool mode)
{
if (cipherkey == NULL) {
COMM_LOGE(COMM_ADAPTER, "Encrypt invalid para.");
return SOFTBUS_INVALID_PARAM;
}
EVP_CIPHER *cipher = GetGcmAlgorithmByKeyLen(cipherkey->keyLen);
if (cipher == NULL) {
COMM_LOGE(COMM_ADAPTER, "get cipher fail.");

View File

@ -22,7 +22,6 @@
#include "anonymizer.h"
#include "lnn_kv_adapter.h"
#include "lnn_log.h"
#include "lnn_ohos_account.h"
#include "lnn_parameter_utils.h"
#include "softbus_errcode.h"
@ -301,14 +300,6 @@ int32_t KVAdapter::Get(const std::string &key, std::string &value)
DistributedKv::Status KVAdapter::GetKvStorePtr()
{
LNN_LOGI(LNN_LEDGER, "called");
bool isLogIn = false;
if (LnnIsDefaultOhosAccount()) {
LNN_LOGI(LNN_LEDGER, "no account log in, enableCloud=false");
isLogIn = false;
} else {
LNN_LOGI(LNN_LEDGER, "account already log in, enableCloud=true");
isLogIn = true;
}
DistributedKv::Options options = {
.encrypt = true,
.autoSync = false,
@ -317,7 +308,7 @@ DistributedKv::Status KVAdapter::GetKvStorePtr()
.area = 1,
.kvStoreType = KvStoreType::SINGLE_VERSION,
.baseDir = DATABASE_DIR,
.cloudConfig = { .enableCloud = isLogIn, .autoSync = true }
.cloudConfig = { .enableCloud = false, .autoSync = true }
};
DistributedKv::Status status;
{

View File

@ -73,6 +73,7 @@ if (dsoftbus_feature_lnn_net) {
]
auth_server_inc += [
"$dsoftbus_root_path/adapter/common/include/",
"$dsoftbus_root_path/core/adapter/huks/include/",
"$dsoftbus_root_path/dsoftbus_enhance/core/authentication/ccmp/include/",
]
} else {

View File

@ -83,6 +83,7 @@ if (expression) { \
#define MASK_UINT64_L32 0x00000000FFFFFFFF
#define MASK_UINT64_H32 0xFFFFFFFF00000000
#define AUTH_REQUEST_TIMTOUR 30000
/* ble network advdata take 8 bytes of UDID hash */
#define SHORT_HASH_LEN 8
#define SOFTBUS_SUB_SYSTEM 203

View File

@ -38,20 +38,20 @@ extern "C" {
typedef struct {
int64_t authId;
bool isServer;
/* 连接信息 */
/* connInfo */
uint64_t connId[AUTH_LINK_TYPE_MAX];
AuthConnInfo connInfo[AUTH_LINK_TYPE_MAX];
uint64_t lastActiveTime;
/* 密钥信息 */
/* sessionKeyInfo */
int64_t lastAuthSeq[AUTH_LINK_TYPE_MAX];
uint64_t lastVerifyTime;
SessionKeyList sessionKeyList;
/* 设备信息 */
/* deviceInfo */
char p2pMac[MAC_LEN];
char udid[UDID_BUF_LEN];
char uuid[UUID_BUF_LEN];
SoftBusVersion version;
/* 认证状态 */
/* authState */
bool hasAuthPassed[AUTH_LINK_TYPE_MAX];
ListNode node;
} AuthManager;

View File

@ -491,7 +491,7 @@ int32_t GetPeerUdidByNetworkId(const char *networkId, char *udid, uint32_t len)
cacheInfo.deviceInfo.deviceUdid[0] != '\0') {
if (strcpy_s(udid, len, cacheInfo.deviceInfo.deviceUdid) != EOK) {
AUTH_LOGE(AUTH_CONN, "copy deviceUdid failed");
return SOFTBUS_MEM_ERR;
return SOFTBUS_STRCPY_ERR;
}
return SOFTBUS_OK;
}
@ -560,4 +560,4 @@ void PrintAuthConnInfo(const AuthConnInfo *connInfo)
default:
break;
}
}
}

View File

@ -558,7 +558,7 @@ static int32_t ConnectCommDevice(const AuthConnInfo *info, uint32_t requestId, C
};
ret = ConnConnectDevice(&option, requestId, &result);
if (ret != SOFTBUS_OK) {
AUTH_LOGE(AUTH_CONN, "ConnConnectDevice fail=%{public}d", ret);
AUTH_LOGE(AUTH_CONN, "ConnConnectDevice fail. ret=%{public}d", ret);
return ret;
}
return SOFTBUS_OK;
@ -778,6 +778,7 @@ int32_t AuthStartListening(AuthLinkType type, const char *ip, int32_t port)
.protocol = LNN_PROTOCOL_IP,
},
};
if (strcpy_s(info.socketOption.addr, sizeof(info.socketOption.addr), ip) != EOK) {
AUTH_LOGE(AUTH_CONN, "strcpy_s ip fail");
return SOFTBUS_STRCPY_ERR;
@ -834,7 +835,7 @@ int32_t AuthStartListeningForWifiDirect(AuthLinkType type, const char *ip, int32
AUTH_CHECK_AND_RETURN_RET_LOGE(local.socketOption.moduleId < UNUSE_BUTT, SOFTBUS_ERR, AUTH_CONN,
"alloc listener module id failed");
} else {
AUTH_LOGE(AUTH_CONN, "type invalid. type=%{public}d", type);
AUTH_LOGE(AUTH_CONN, "invalid type=%{public}d", type);
return SOFTBUS_INVALID_PARAM;
}
@ -854,7 +855,7 @@ int32_t AuthStartListeningForWifiDirect(AuthLinkType type, const char *ip, int32
void AuthStopListeningForWifiDirect(AuthLinkType type, ListenerModule moduleId)
{
AUTH_CHECK_AND_RETURN_LOGE(type == AUTH_LINK_TYPE_P2P || type == AUTH_LINK_TYPE_ENHANCED_P2P, AUTH_CONN,
"type invalid. type=%{public}d", type);
"invalid type=%{public}d", type);
LocalListenerInfo local = {
.type = CONNECT_TCP,
.socketOption = {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 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
@ -16,7 +16,7 @@
#include "auth_device.h"
#include <securec.h>
#include "anonymizer.h"
#include "auth_connection.h"
#include "auth_hichain.h"
#include "auth_log.h"

View File

@ -224,6 +224,10 @@ int32_t AuthCheckSessionKeyValidByAuthHandle(const AuthHandle *authHandle)
AUTH_LOGE(AUTH_CONN, "param is null");
return SOFTBUS_INVALID_PARAM;
}
if (authHandle->type < AUTH_LINK_TYPE_WIFI || authHandle->type >= AUTH_LINK_TYPE_MAX) {
AUTH_LOGE(AUTH_CONN, "authHandle type error");
return SOFTBUS_INVALID_PARAM;
}
AuthManager *auth = GetAuthManagerByAuthId(authHandle->authId);
if (auth == NULL) {
AUTH_LOGE(AUTH_CONN, "not found auth manager, type=%{public}d, authId=%{public}" PRId64,

View File

@ -216,4 +216,4 @@ void NotifyNormalizeRequestFail(int64_t authSeq, int32_t ret)
}
}
SoftBusFree(requests);
}
}

View File

@ -15,6 +15,8 @@
#include "auth_request.h"
#include <securec.h>
#include "auth_common.h"
#include "auth_log.h"
#include "softbus_adapter_mem.h"

View File

@ -335,7 +335,7 @@ static int32_t GetEnhancedP2pAuthKey(const char *udidHash, AuthSessionInfo *info
/* first, reuse ble authKey */
if (AuthFindLatestNormalizeKey(udidHash, deviceKey, true) == SOFTBUS_OK ||
AuthFindDeviceKey(udidHash, AUTH_LINK_TYPE_BLE, deviceKey) == SOFTBUS_OK) {
AUTH_LOGD(AUTH_FSM, "get authKey succ");
AUTH_LOGD(AUTH_FSM, "get ble authKey succ");
return SOFTBUS_OK;
}
/* second, reuse wifi authKey */
@ -1029,7 +1029,7 @@ static void UnPackVersionByDeviceId(JsonObj *obj, AuthSessionInfo *info)
OptInt(obj, AUTH_START_STATE, (int32_t *)&info->peerState, AUTH_STATE_COMPATIBLE);
}
static int32_t UnpackWifiInfoFromJsonObj(JsonObj *obj, AuthSessionInfo *info)
static int32_t IsCmdMatchByDeviceId(JsonObj *obj, AuthSessionInfo *info)
{
char cmd[CMD_TAG_LEN] = {0};
if (!JSON_GetStringFromOject(obj, CMD_TAG, cmd, CMD_TAG_LEN)) {
@ -1063,7 +1063,7 @@ int32_t UnpackDeviceIdJson(const char *msg, uint32_t len, AuthSessionInfo *info)
AUTH_LOGE(AUTH_FSM, "json parse fail");
return SOFTBUS_INVALID_PARAM;
}
int32_t ret = UnpackWifiInfoFromJsonObj(obj, info);
int32_t ret = IsCmdMatchByDeviceId(obj, info);
if (ret != SOFTBUS_OK) {
JSON_Delete(obj);
return ret;
@ -1075,12 +1075,12 @@ int32_t UnpackDeviceIdJson(const char *msg, uint32_t len, AuthSessionInfo *info)
}
UnPackVersionByDeviceId(obj, info);
if (SetExchangeIdTypeAndValue(obj, info) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "set exchange id type or value failed");
AUTH_LOGE(AUTH_FSM, "set exchange id type or value fail");
JSON_Delete(obj);
return SOFTBUS_ERR;
}
if (info->connInfo.type != AUTH_LINK_TYPE_WIFI) {
char compressParse[PARSE_UNCOMPRESS_STRING_BUFF_LEN] = { 0 };
char compressParse[PARSE_UNCOMPRESS_STRING_BUFF_LEN] = {0};
OptString(obj, SUPPORT_INFO_COMPRESS, compressParse, PARSE_UNCOMPRESS_STRING_BUFF_LEN, FALSE_STRING_TAG);
SetCompressFlag(compressParse, &info->isSupportCompress);
}
@ -1307,12 +1307,14 @@ static int32_t PackCipherRpaInfo(JsonObj *json, const NodeInfo *info)
info->rpaInfo.peerIrk, LFINDER_IRK_LEN) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "convert peerIrk to string fail.");
(void)memset_s(cipherKey, SESSION_KEY_STR_LEN, 0, SESSION_KEY_STR_LEN);
(void)memset_s(cipherIv, BROADCAST_IV_STR_LEN, 0, BROADCAST_IV_STR_LEN);
return SOFTBUS_ERR;
}
if (ConvertBytesToHexString(pubMac, LFINDER_MAC_ADDR_STR_LEN,
info->rpaInfo.publicAddress, LFINDER_MAC_ADDR_LEN) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "convert publicAddress to string fail.");
(void)memset_s(cipherKey, SESSION_KEY_STR_LEN, 0, SESSION_KEY_STR_LEN);
(void)memset_s(cipherIv, BROADCAST_IV_STR_LEN, 0, BROADCAST_IV_STR_LEN);
(void)memset_s(peerIrk, LFINDER_IRK_STR_LEN, 0, LFINDER_IRK_STR_LEN);
return SOFTBUS_ERR;
}
@ -1322,6 +1324,7 @@ static int32_t PackCipherRpaInfo(JsonObj *json, const NodeInfo *info)
(void)JSON_AddStringToObject(json, PUB_MAC, pubMac);
DumpRpaCipherKey(cipherKey, cipherIv, peerIrk, "pack broadcast cipher key");
(void)memset_s(cipherKey, SESSION_KEY_STR_LEN, 0, SESSION_KEY_STR_LEN);
(void)memset_s(cipherIv, BROADCAST_IV_STR_LEN, 0, BROADCAST_IV_STR_LEN);
(void)memset_s(peerIrk, LFINDER_IRK_STR_LEN, 0, LFINDER_IRK_STR_LEN);
int32_t ret = UpdateBroadcastCipherKey(info);
if (ret != SOFTBUS_OK) {
@ -1872,7 +1875,7 @@ static int32_t UnpackDeviceInfoBtV1(const JsonObj *json, NodeInfo *info)
}
if (strcpy_s(info->networkId, NETWORK_ID_BUF_LEN, info->uuid) != EOK) {
AUTH_LOGE(AUTH_FSM, "strcpy networkId fail");
return SOFTBUS_ERR;
return SOFTBUS_STRCPY_ERR;
}
return SOFTBUS_OK;
}
@ -1957,8 +1960,7 @@ static void UpdateLocalNetBrMac(void)
SoftBusGetBtState() == BLE_ENABLE) {
char brMac[BT_MAC_LEN] = {0};
SoftBusBtAddr mac = {0};
int32_t ret = 0;
ret = SoftBusGetBtMacAddr(&mac);
int32_t ret = SoftBusGetBtMacAddr(&mac);
if (ret != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "get bt mac addr fail, do not update local brmac");
return;

View File

@ -50,7 +50,7 @@ static void RemoveOldKey(SessionKeyList *list)
if (num <= SESSION_KEY_MAX_NUM) {
return;
}
SessionKeyItem *oldKey = NULL;
uint64_t oldKeyUseTime = UINT64_MAX;
LIST_FOR_EACH_ENTRY(item, (const ListNode *)list, SessionKeyItem, node) {
@ -427,6 +427,7 @@ int32_t EncryptData(const SessionKeyList *list, AuthLinkType type, const InDataI
SessionKey sessionKey;
if (GetLatestSessionKey(list, type, &index, &sessionKey) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_FSM, "get key fail");
AUTH_LOGD(AUTH_FSM, "keyLen=%{public}d", sessionKey.len);
return SOFTBUS_ENCRYPT_ERR;
}
/* pack key index */

View File

@ -37,6 +37,7 @@
#include "lnn_feature_capability.h"
#include "lnn_local_net_ledger.h"
#include "lnn_network_manager.h"
#include "lnn_node_info.h"
#include "softbus_adapter_json.h"
#include "softbus_adapter_mem.h"
#include "softbus_adapter_socket.h"
@ -45,6 +46,7 @@
#include "softbus_def.h"
#include "softbus_error_code.h"
#include "softbus_feature_config.h"
#include "softbus_json_utils.h"
#include "softbus_socket.h"
#define FLAG_COMPRESS_DEVICE_INFO 1

View File

@ -291,7 +291,7 @@ static int32_t OnConnectEvent(ListenerModule module, int32_t cfd, const ConnectO
ConnShutdownSocket(cfd);
return SOFTBUS_ERR;
}
if (module != AUTH && module != AUTH_P2P && module != AUTH_RAW_P2P_CLIENT &&!IsEnhanceP2pModuleId(module)) {
if (module != AUTH && module != AUTH_P2P && module != AUTH_RAW_P2P_CLIENT && !IsEnhanceP2pModuleId(module)) {
AUTH_LOGI(AUTH_CONN, "newip auth process");
if (RouteBuildServerAuthManager(cfd, clientAddr) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_CONN, "build auth manager fail.");
@ -393,7 +393,7 @@ static int32_t SocketConnectInner(const char *localIp, const char *peerIp, int32
}
int32_t fd = ret;
TriggerType triggerMode = isBlockMode ? READ_TRIGGER : WRITE_TRIGGER;
if (AuthTcpCreateListener(AUTH, fd, triggerMode) != SOFTBUS_OK) {
if (AuthTcpCreateListener(module, fd, triggerMode) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_CONN, "AddTrigger fail.");
ConnShutdownSocket(fd);
return AUTH_INVALID_FD;
@ -401,7 +401,7 @@ static int32_t SocketConnectInner(const char *localIp, const char *peerIp, int32
if (ConnSetTcpKeepalive(fd, (int32_t)DEFAULT_FREQ_CYCLE, TCP_KEEPALIVE_INTERVAL, TCP_KEEPALIVE_DEFAULT_COUNT) !=
SOFTBUS_OK) {
AUTH_LOGE(AUTH_CONN, "set tcp keep alive fail.");
(void)DelTrigger(AUTH, fd, triggerMode);
(void)DelTrigger(module, fd, triggerMode);
ConnShutdownSocket(fd);
return AUTH_INVALID_FD;
}

View File

@ -19,7 +19,7 @@
#include "softbus_error_code.h"
#include <stdint.h>
bool IsSupportUDIDAbatement()
bool IsSupportUDIDAbatement(void)
{
return false;
}

View File

@ -53,14 +53,6 @@ void AuthClearDeviceKey(void)
{
}
int32_t AuthFindNormalizeKeyByServerSide(const char *udidHash, bool isServer, AuthDeviceKeyInfo *deviceKey)
{
(void)udidHash;
(void)isServer;
(void)deviceKey;
return SOFTBUS_NOT_IMPLEMENT;
}
int32_t AuthFindLatestNormalizeKey(const char *udidHash, AuthDeviceKeyInfo *deviceKey, bool clearOldKey)
{
(void)udidHash;
@ -86,3 +78,11 @@ void AuthUpdateKeyIndex(const char *udidHash, int32_t keyType, int64_t index, bo
(void)index;
(void)isServer;
}
int32_t AuthFindNormalizeKeyByServerSide(const char *udidHash, bool isServer, AuthDeviceKeyInfo *deviceKey)
{
(void)udidHash;
(void)isServer;
(void)deviceKey;
return SOFTBUS_NOT_IMPLEMENT;
}

View File

@ -46,6 +46,7 @@ int32_t AuthNotifyResultByUuid(const char *uuid, int32_t reason, int64_t *authId
{
(void)uuid;
(void)reason;
(void)authId;
return SOFTBUS_OK;
}
@ -62,5 +63,5 @@ int32_t AuthMetaInitPtkProc(void)
void AuthMetaDeinitPtkProc(void)
{
return;
}

View File

@ -107,5 +107,6 @@ int32_t StartSocketListening(ListenerModule module, const LocalListenerInfo *inf
void StopSocketListening(ListenerModule moduleId)
{
(void)moduleId;
return;
}

View File

@ -138,7 +138,7 @@ lnn_lp_enhanced = exec_script("$dsoftbus_root_path/check_sub_module.py",
"value")
if (lnn_lp_enhanced) {
import("../../dsoftbus_enhance/adapter/common/adapter_mlps.gni")
import("../../dsoftbus_enhance/adapter/common/mlps/adapter_mlps.gni")
bus_center_server_inc += adapter_mlps_inc
bus_center_server_src += adapter_mlps_src
}

View File

@ -90,12 +90,12 @@ typedef enum {
BOOL_KEY_END,
BYTE_KEY_BEGIN,
BYTE_KEY_ACCOUNT_HASH = BYTE_KEY_BEGIN,
BYTE_KEY_REMOTE_PTK,
BYTE_KEY_STATIC_CAPABILITY,
BYTE_KEY_IRK,
BYTE_KEY_PUB_MAC,
BYTE_KEY_BROADCAST_CIPHER_KEY,
BYTE_KEY_BROADCAST_CIPHER_IV,
BYTE_KEY_REMOTE_PTK,
BYTE_KEY_STATIC_CAPABILITY,
BYTE_KEY_UDID_HASH,
BYTE_KEY_END,
INFO_KEY_MAX,

View File

@ -69,6 +69,7 @@ int32_t LnnGetLocalNumU32Info(InfoKey key, uint32_t *info);
int32_t LnnSetLocalNumU32Info(InfoKey key, uint32_t info);
int32_t LnnSetLocalByteInfo(InfoKey key, const uint8_t *info, uint32_t len);
int32_t LnnGetLocalByteInfo(InfoKey key, uint8_t *info, uint32_t len);
int32_t LnnGetLocalBoolInfo(InfoKey key, bool *info, uint32_t len);
bool LnnIsLSANode(const NodeBasicInfo *info);
int32_t LnnGetAllOnlineNodeInfo(NodeBasicInfo **info, int32_t *infoNum);
int32_t LnnGetAllOnlineAndMetaNodeInfo(NodeBasicInfo **info, int32_t *infoNum);

View File

@ -211,13 +211,8 @@ int32_t ClientOnRefreshDeviceFound(
int32_t ClientOnDataLevelChanged(const char *pkgName, int32_t pid, const char *networkId,
const DataLevelInfo *dataLevelInfo)
{
if (pkgName == nullptr) {
LNN_LOGE(LNN_EVENT, "pkgName is null");
return SOFTBUS_INVALID_PARAM;
}
if (networkId == nullptr) {
LNN_LOGE(LNN_EVENT, "networkId is null");
if (pkgName == nullptr || networkId == nullptr || dataLevelInfo == nullptr) {
LNN_LOGE(LNN_EVENT, "param is invalid");
return SOFTBUS_INVALID_PARAM;
}

View File

@ -442,7 +442,7 @@ int32_t BusCenterClientProxy::OnHichainProofException(
const char *pkgName, const char *proofInfo, uint32_t proofLen, uint16_t deviceTypeId, int32_t errCode)
{
if (pkgName == nullptr) {
LNN_LOGE(LNN_EVENT, "invalid parameters");
LNN_LOGE(LNN_EVENT, "invalid parameter");
return SOFTBUS_INVALID_PARAM;
}
sptr<IRemoteObject> remote = Remote();

View File

@ -69,7 +69,7 @@ int32_t LnnUnPublishService(const char *pkgName, int32_t publishId, bool isInner
if (!isInnerRequest) {
if ((ret = DiscUnPublishService(pkgName, publishId)) != SOFTBUS_OK) {
DfxRecordLnnDiscServiceEnd(DISC_SERVER_STOP_PUBLISH, pkgName, ret);
LNN_LOGE(LNN_BUILDER, "DiscUnPublishService failed\n");
LNN_LOGD(LNN_BUILDER, "DiscUnPublishService failed\n");
return SOFTBUS_DISCOVER_COAP_STOP_PUBLISH_FAIL;
}
return SOFTBUS_OK;

View File

@ -133,7 +133,7 @@ typedef struct {
typedef enum {
BIT_SUPPORT_DIRECT_TRIGGER = 0,
BIT_SUPPORT_SCREEN_STATUS = 0,
BIT_SUPPORT_SCREEN_STATUS = 1,
} HeartbeatCapability;
#define STATE_VERSION_INVALID (-1)

View File

@ -142,6 +142,30 @@ void SetScreenState(SoftBusScreenState state)
g_hbConditionState.screenState = state;
}
static void HbRefreshConditionState(void)
{
if (SoftBusGetBtState() == BLE_ENABLE) {
g_hbConditionState.btState = SOFTBUS_BLE_TURN_ON;
}
LnnUpdateOhosAccount(false);
if (!LnnIsDefaultOhosAccount()) {
g_hbConditionState.accountState = SOFTBUS_ACCOUNT_LOG_IN;
}
if (IsActiveOsAccountUnlocked()) {
g_hbConditionState.lockState = SOFTBUS_SCREEN_UNLOCK;
}
TrustedReturnType ret = AuthHasTrustedRelation();
if (ret == TRUSTED_RELATION_YES) {
g_hbConditionState.hasTrustedRelation = true;
} else if (ret == TRUSTED_RELATION_NO) {
g_hbConditionState.hasTrustedRelation = false;
}
if (g_hbConditionState.lockState == SOFTBUS_SCREEN_UNLOCK &&
(g_hbConditionState.accountState == SOFTBUS_ACCOUNT_LOG_IN || g_hbConditionState.hasTrustedRelation)) {
g_hbConditionState.heartbeatEnable = IsEnableSoftBusHeartbeat();
}
}
static void HbIpAddrChangeEventHandler(const LnnEventBasicInfo *info)
{
char localIp[IP_LEN] = { 0 };
@ -192,6 +216,7 @@ static void HbSendCheckOffLineMessage(LnnHeartbeatType hbType)
static void HbConditionChanged(bool isOnlySetState)
{
HbRefreshConditionState();
bool isEnable = IsHeartbeatEnable();
if (g_enableState == isEnable) {
LNN_LOGI(LNN_HEART_BEAT, "ctrl ignore same enable request, isEnable=%{public}d", isEnable);
@ -215,6 +240,7 @@ static void HbConditionChanged(bool isOnlySetState)
LNN_LOGE(LNN_HEART_BEAT, "start ble heartbeat fail");
}
g_enableState = true;
LnnStartHeartbeat(0);
} else {
LNN_LOGD(LNN_HEART_BEAT, "condition changed to disabled");
if (LnnStopHeartbeatByType(HEARTBEAT_TYPE_BLE_V0 | HEARTBEAT_TYPE_BLE_V1 | HEARTBEAT_TYPE_BLE_V3) !=
@ -404,7 +430,6 @@ static void HbBtStateChangeEventHandler(const LnnEventBasicInfo *info)
break;
case SOFTBUS_BLE_TURN_OFF:
LNN_LOGI(LNN_HEART_BEAT, "HB handle SOFTBUS_BLE_TURN_OFF");
LnnUpdateHeartbeatInfo(UPDATE_BT_STATE_CLOSE_INFO);
HbConditionChanged(false);
DfxRecordBleTriggerTimestamp(BLE_TURN_OFF);
ClearAuthLimitMap();
@ -496,7 +521,7 @@ static void HbChangeMediumParamByState(SoftBusScreenState state)
LNN_LOGD(LNN_HEART_BEAT, "ctrl reset ble scan medium param get invalid state");
return;
}
if (LnnSetMediumParamBySpecificType(&param) != SOFTBUS_OK) {
if (!LnnIsLocalSupportBurstFeature() && (LnnSetMediumParamBySpecificType(&param) != SOFTBUS_OK)) {
LNN_LOGE(LNN_HEART_BEAT, "ctrl reset ble scan medium param fail");
return;
}
@ -540,6 +565,7 @@ static int32_t HbTryCloudSync(void)
static void HbScreenOnOnceTryCloudSync(void)
{
HbRefreshConditionState();
if (g_hbConditionState.screenState == SOFTBUS_SCREEN_ON && !g_isScreenOnOnce &&
g_hbConditionState.accountState == SOFTBUS_ACCOUNT_LOG_IN &&
g_hbConditionState.lockState == SOFTBUS_SCREEN_UNLOCK) {
@ -556,19 +582,18 @@ static void DfxRecordScreenChangeTimestamp(LnnTriggerReason reason)
static void HbScreenOnChangeEventHandler(int64_t nowTime)
{
LNN_LOGI(LNN_HEART_BEAT, "HB handle SOFTBUS_SCREEN_ON");
g_lastScreenOnTime = nowTime;
g_isScreenOnOnce = true;
(void)LnnUpdateLocalScreenStatus(true);
HbRemoveCheckOffLineMessage(HEARTBEAT_TYPE_BLE_V1);
HbChangeMediumParamByState(g_hbConditionState.screenState);
g_lastScreenOnTime = nowTime;
if (g_lastScreenOnTime - g_lastScreenOffTime >= HB_SCREEN_ON_COAP_TIME) {
LNN_LOGD(LNN_HEART_BEAT, "screen on start coap discovery");
RestartCoapDiscovery();
}
if (LnnStartHbByTypeAndStrategy(
HEARTBEAT_TYPE_BLE_V0 | HEARTBEAT_TYPE_BLE_V3, STRATEGY_HB_SEND_SINGLE, false) != SOFTBUS_OK) {
LNN_LOGE(LNN_HEART_BEAT, "start ble heartbeat failed");
return;
int32_t ret = LnnStartHbByTypeAndStrategy(
HEARTBEAT_TYPE_BLE_V0 | HEARTBEAT_TYPE_BLE_V3, STRATEGY_HB_SEND_SINGLE, false);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_HEART_BEAT, "start ble heartbeat failed, ret=%{public}d", ret);
}
DfxRecordScreenChangeTimestamp(SCREEN_ON);
}
@ -643,6 +668,7 @@ static void HbScreenLockChangeEventHandler(const LnnEventBasicInfo *info)
switch (lockState) {
case SOFTBUS_SCREEN_UNLOCK:
LNN_LOGI(LNN_HEART_BEAT, "HB handle SOFTBUS_SCREEN_UNLOCK");
HbRefreshConditionState();
if (g_hbConditionState.screenState == SOFTBUS_SCREEN_ON &&
g_hbConditionState.accountState == SOFTBUS_ACCOUNT_LOG_IN) {
LnnAsyncCallbackDelayHelper(
@ -677,7 +703,6 @@ static void HbAccountStateChangeEventHandler(const LnnEventBasicInfo *info)
switch (accountState) {
case SOFTBUS_ACCOUNT_LOG_IN:
LNN_LOGI(LNN_HEART_BEAT, "HB handle SOFTBUS_ACCOUNT_LOG_IN");
LnnUpdateOhosAccount(false);
LnnAsyncCallbackDelayHelper(
GetLooper(LOOP_TYPE_DEFAULT), HbDelaySetHighScanParam, NULL, HB_CLOUD_SYNC_DELAY_LEN);
LnnAsyncCallbackDelayHelper(GetLooper(LOOP_TYPE_DEFAULT), HbDelaySetNormalScanParam, NULL,
@ -867,30 +892,6 @@ static void HbLpEventHandler(const LnnEventBasicInfo *info)
static void HbTryRecoveryNetwork(void)
{
if (SoftBusGetBtState() == BLE_ENABLE) {
g_hbConditionState.btState = SOFTBUS_BLE_TURN_ON;
}
if (!LnnIsDefaultOhosAccount()) {
g_hbConditionState.accountState = SOFTBUS_ACCOUNT_LOG_IN;
if (LnnSetCloudAbility(true) != SOFTBUS_OK) {
LNN_LOGE(LNN_HEART_BEAT, "SetCloudAbility false");
}
}
if (IsActiveOsAccountUnlocked()) {
g_hbConditionState.lockState = SOFTBUS_SCREEN_UNLOCK;
}
TrustedReturnType ret = AuthHasTrustedRelation();
if (ret == TRUSTED_RELATION_YES) {
g_hbConditionState.hasTrustedRelation = true;
} else if (ret == TRUSTED_RELATION_NO) {
g_hbConditionState.hasTrustedRelation = false;
}
if (g_hbConditionState.lockState == SOFTBUS_SCREEN_UNLOCK &&
(g_hbConditionState.accountState == SOFTBUS_ACCOUNT_LOG_IN || g_hbConditionState.hasTrustedRelation)) {
g_hbConditionState.heartbeatEnable = IsEnableSoftBusHeartbeat();
}
LNN_LOGI(LNN_HEART_BEAT, "try to recovery heartbeat network, relation=%{public}d",
g_hbConditionState.hasTrustedRelation);
HbConditionChanged(true);
}
@ -1303,4 +1304,4 @@ void LnnRegDataLevelChangeCb(const IDataLevelChangeCallback *callback)
void LnnUnregDataLevelChangeCb(void)
{
LnnBleHbUnregDataLevelChangeCb();
}
}

View File

@ -34,8 +34,10 @@
#include "softbus_adapter_mem.h"
#include "softbus_adapter_timer.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_hisysevt_bus_center.h"
#include "softbus_utils.h"
#define TO_HEARTBEAT_FSM(ptr) CONTAINER_OF(ptr, LnnHeartbeatFsm, fsm)
@ -728,7 +730,7 @@ static int32_t OnTransHbFsmState(FsmStateMachine *fsm, int32_t msgType, void *pa
break;
default:
LNN_LOGE(LNN_HEART_BEAT, "process transact state get invalid msgType");
return SOFTBUS_INVALID_PARAM;
return SOFTBUS_NETWORK_HB_TRANSACT_PROCESS_FAIL;
}
hbFsm = TO_HEARTBEAT_FSM(fsm);
if (hbFsm->state == nextState) {
@ -848,7 +850,6 @@ static void CheckDevStatusByNetworkId(LnnHeartbeatFsm *hbFsm, const char *networ
LnnHeartbeatType hbType = msgPara->hbType;
NodeInfo nodeInfo;
SoftBusSysTime times = {0};
uint64_t nowTime;
(void)memset_s(&nodeInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
if (LnnGetRemoteNodeInfoById(networkId, CATEGORY_NETWORK_ID, &nodeInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_HEART_BEAT, "check dev status get nodeInfo fail");
@ -858,7 +859,7 @@ static void CheckDevStatusByNetworkId(LnnHeartbeatFsm *hbFsm, const char *networ
if (!LnnHasDiscoveryType(&nodeInfo, discType)) {
Anonymize(networkId, &anonyNetworkId);
LNN_LOGE(LNN_HEART_BEAT,
"check dev status node doesn't have discType. networkId=%{public}s, discType=%{public}d",
"check dev status doesn't have discType. networkId=%{public}s, discType=%{public}d",
AnonymizeWrapper(anonyNetworkId), discType);
AnonymizeFree(anonyNetworkId);
return;
@ -870,7 +871,7 @@ static void CheckDevStatusByNetworkId(LnnHeartbeatFsm *hbFsm, const char *networ
return;
}
SoftBusGetTime(&times);
nowTime = (uint64_t)times.sec * HB_TIME_FACTOR + (uint64_t)times.usec / HB_TIME_FACTOR;
uint64_t nowTime = (uint64_t)times.sec * HB_TIME_FACTOR + (uint64_t)times.usec / HB_TIME_FACTOR;
if (!IsTimestampExceedLimit(nowTime, oldTimeStamp, hbType, msgPara->checkDelay)) {
Anonymize(networkId, &anonyNetworkId);
LNN_LOGD(LNN_HEART_BEAT, "receive heartbeat in time, networkId=%{public}s, nowTime=%{public}" PRIu64 ", "
@ -888,6 +889,8 @@ static void CheckDevStatusByNetworkId(LnnHeartbeatFsm *hbFsm, const char *networ
}
if (ProcessLostHeartbeat(networkId, hbType, msgPara->isWakeUp) != SOFTBUS_OK) {
LNN_LOGE(LNN_HEART_BEAT, "process dev lost err, networkId=%{public}s", AnonymizeWrapper(anonyNetworkId));
AnonymizeFree(anonyNetworkId);
return;
}
AnonymizeFree(anonyNetworkId);
}
@ -1194,7 +1197,6 @@ int32_t LnnPostSendEndMsgToHbFsm(LnnHeartbeatFsm *hbFsm, LnnHeartbeatSendEndData
uint64_t delayMillis)
{
LnnHeartbeatSendEndData *dupData = NULL;
if (hbFsm == NULL || custData == NULL) {
LNN_LOGE(LNN_HEART_BEAT, "post send end msg get invalid param");
return SOFTBUS_INVALID_PARAM;

View File

@ -36,6 +36,7 @@
#include "lnn_distributed_net_ledger.h"
#include "lnn_event.h"
#include "lnn_feature_capability.h"
#include "lnn_heartbeat_fsm.h"
#include "lnn_heartbeat_strategy.h"
#include "lnn_heartbeat_utils.h"
#include "lnn_lane_vap_info.h"
@ -341,6 +342,11 @@ static bool HbIsRepeatedJoinLnnRequest(LnnHeartbeatRecvInfo *storedInfo, uint64_
return false;
}
if (nowTime - storedInfo->lastJoinLnnTime < HB_REPEAD_JOIN_LNN_THRESHOLD) {
char *anonyUdid = NULL;
AnonymizeUdid(storedInfo->device->devId, &anonyUdid);
LNN_LOGD(LNN_HEART_BEAT, "recv but ignore repeated join lnn request, udidHash=%{public}s",
AnonymizeWrapper(anonyUdid));
AnonymizeFree(anonyUdid);
return true;
}
storedInfo->lastJoinLnnTime = nowTime;
@ -474,7 +480,7 @@ static bool IsInvalidBrmac(const char *macAddr)
static bool IsUuidChange(const char *oldUuid, const HbRespData *hbResp, uint32_t len)
{
uint8_t zeroUuid[UUID_BUF_LEN] = { 0 };
char zeroUuid[UUID_BUF_LEN] = { 0 };
uint8_t uuidHash[SHA_256_HASH_LEN] = { 0 };
if (oldUuid == NULL || hbResp == NULL) {
@ -1025,7 +1031,7 @@ static int32_t HbMediumMgrRecvHigherWeight(
static void HbMediumMgrRecvLpInfo(const char *networkId, uint64_t nowTime)
{
if (HbUpdateOfflineTimingByRecvInfo(networkId, CONNECTION_ADDR_BLE, HEARTBEAT_TYPE_BLE_V0, nowTime) != SOFTBUS_OK) {
if (HbUpdateOfflineTimingByRecvInfo(networkId, CONNECTION_ADDR_BLE, HEARTBEAT_TYPE_BLE_V4, nowTime) != SOFTBUS_OK) {
LNN_LOGE(LNN_HEART_BEAT, "HB medium mgr update time stamp fail");
}
}
@ -1412,6 +1418,7 @@ static bool VisitRegistHeartbeatMediumMgr(LnnHeartbeatType *typeSet, LnnHeartbea
int32_t LnnRegistHeartbeatMediumMgr(LnnHeartbeatMediumMgr *mgr)
{
// TODO: One-to-one correspondence between LnnHeartbeatMediumMgr and implementation.
if (mgr == NULL) {
LNN_LOGE(LNN_HEART_BEAT, "regist manager get invalid param");
return SOFTBUS_INVALID_PARAM;

View File

@ -27,11 +27,14 @@
#include "lnn_log.h"
#include "bus_center_manager.h"
#include "lnn_distributed_net_ledger.h"
#include "lnn_feature_capability.h"
#include "softbus_adapter_mem.h"
#include "softbus_adapter_thread.h"
#include "softbus_adapter_timer.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_utils.h"
#define HB_GEARMODE_MAX_SET_CNT 100
#define HB_GEARMODE_LIFETIME_PERMANENT (-1)
@ -422,6 +425,7 @@ static int32_t RelayHeartbeatV1Split(
{
msgPara->isFirstBegin = true;
msgPara->isNeedRestart = true;
msgPara->hasScanRsp = true;
if (LnnPostSendBeginMsgToHbFsm(hbFsm, registedHbType, wakeupFlag, msgPara, 0) != SOFTBUS_OK) {
LNN_LOGE(LNN_HEART_BEAT, "HB send once first begin fail, hbType=%{public}u", registedHbType);
return SOFTBUS_NETWORK_POST_MSG_FAIL;

View File

@ -172,33 +172,27 @@ static bool HbHasActiveHmlConnection(const char *networkId)
bool LnnHasActiveConnection(const char *networkId, ConnectionAddrType addrType)
{
bool hasBrConn = false;
bool hasBleConn = false;
bool hasP2pConn = false;
bool hasHmlConn = false;
bool ret = false;
if (networkId == NULL || addrType >= CONNECTION_ADDR_MAX) {
LNN_LOGE(LNN_HEART_BEAT, "HB check active connection get invalid param");
return false;
return ret;
}
switch (addrType) {
case CONNECTION_ADDR_WLAN:
case CONNECTION_ADDR_ETH:
case CONNECTION_ADDR_BR:
break;
case CONNECTION_ADDR_BLE:
hasBrConn = HbHasActiveBrConnection(networkId);
hasBleConn = HbHasActiveBleConnection(networkId);
hasP2pConn = HbHasActiveP2pConnection(networkId);
hasHmlConn = HbHasActiveHmlConnection(networkId);
ret = HbHasActiveBrConnection(networkId) || HbHasActiveBleConnection(networkId) ||
HbHasActiveP2pConnection(networkId) || HbHasActiveHmlConnection(networkId);
char *anonyNetworkId = NULL;
Anonymize(networkId, &anonyNetworkId);
LNN_LOGI(LNN_HEART_BEAT,
"HB check active connection networkId=%{public}s, "
"BR=%{public}d, BLE=%{public}d, P2P=%{public}d, HML=%{public}d",
AnonymizeWrapper(anonyNetworkId), hasBrConn, hasBleConn, hasP2pConn, hasHmlConn);
LNN_LOGI(LNN_HEART_BEAT, "HB has active BT/BLE/P2P/HML connection. networkId=%{public}s, ret=%{public}s",
AnonymizeWrapper(anonyNetworkId), ret ? "true" : "false");
AnonymizeFree(anonyNetworkId);
return hasBrConn || hasBleConn || hasP2pConn || hasHmlConn;
return ret;
default:
break;
}
@ -214,8 +208,9 @@ bool LnnVisitHbTypeSet(VisitHbTypeCb callback, LnnHeartbeatType *typeSet, void *
LNN_LOGE(LNN_HEART_BEAT, "HB visit typeSet get invalid param");
return false;
}
LnnHeartbeatType tmp = *typeSet;
for (i = HEARTBEAT_TYPE_MIN; i < HEARTBEAT_TYPE_MAX; i <<= 1) {
if ((i & *typeSet) == 0) {
if ((i & tmp) == 0) {
continue;
}
isFinish = callback(typeSet, i, data);

View File

@ -1475,7 +1475,7 @@ static void OnWifiDirectConnectFailure(uint32_t p2pRequestId, int32_t reason)
return;
}
if (reason == SOFTBUS_CONN_HV3_WAIT_CONNECTION_TIMEOUT ||
reason == SOFTBUS_CONN_HV2_BLE_TRIGGER_TIMEOUT) {
reason == SOFTBUS_CONN_HV2_WAIT_CONNECT_RESPONSE_TIMEOUT) {
HandleActionTriggerError(p2pRequestId);
}
LinkConflictType conflictType = GetConflictTypeWithErrcode(reason);
@ -1984,7 +1984,7 @@ static int32_t GetAuthConnInfoWithoutMeta(const LinkRequest *request, uint32_t l
WdGuideType guideType = LANE_CHANNEL_BUTT;
int32_t ret = GetCurrentGuideType(laneReqId, request->linkType, &guideType);
if (ret != SOFTBUS_OK) {
LNN_LOGI(LNN_LANE, "get current guide channel info fail");
LNN_LOGE(LNN_LANE, "get current guide channel info fail");
return ret;
}
if (guideType == LANE_ACTIVE_BR_NEGO || guideType == LANE_NEW_AUTH_NEGO) {

View File

@ -32,4 +32,4 @@ void ClearMetaNodeRequestByPid(const char *pkgName, int32_t pid);
#ifdef __cplusplus
}
#endif
#endif //LNN_META_NODE_INTERFACE_H
#endif // LNN_META_NODE_INTERFACE_H

View File

@ -71,6 +71,7 @@ typedef enum {
void LnnInitCloudSyncModule(void);
void LnnDeInitCloudSyncModule(void);
int32_t LnnLedgerAllDataSyncToDB(NodeInfo *info);
int32_t LnnAsyncCallLedgerAllDataSyncToDB(NodeInfo *info);
int32_t LnnLedgerDataChangeSyncToDB(const char *key, const char *value, size_t valueLength);
int32_t LnnDeleteSyncToDB(void);
int32_t LnnDeleteDevInfoSyncToDB(const char *udid, int64_t accountId);

View File

@ -58,7 +58,7 @@ if (dsoftbus_feature_lnn_net) {
"$dsoftbus_root_path/dsoftbus_enhance/core/bus_center/lnn/net_builder/fast_online/lnn_secure_storage.c",
]
bus_center_builder_inc =
[ "$dsoftbus_root_path/dsoftbus_enhance/adapter/common/mlps/interface" ]
[ "$dsoftbus_root_path/dsoftbus_enhance/adapter/common/mlps/include" ]
}
} else {
bus_center_builder_src = [

View File

@ -405,7 +405,7 @@ static void ReportLnnResultEvt(LnnConnectionFsm *connFsm, int32_t retCode)
return;
}
uint64_t constTime =
(uint64_t)(connFsm->statisticData.beginOnlineTime - connFsm->statisticData.beginJoinLnnTime);
(uint64_t)(connFsm->statisticData.beginOnlineTime - connFsm->statisticData.beginJoinLnnTime);
if (SoftBusRecordBusCenterResult(linkType, constTime) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "report static lnn duration fail");
}
@ -859,7 +859,7 @@ static void GetConnectOnlineReason(LnnConntionInfo *connInfo, uint32_t *connOnli
} else {
peerReason = (uint8_t)connInfo->nodeInfo->stateVersionReason;
}
*connOnlineReason =
((connectReason << BLE_CONNECT_ONLINE_REASON) | (peerReason << PEER_DEVICE_STATE_VERSION_CHANGE) | localReason);
LNN_LOGI(LNN_BUILDER,
@ -1504,8 +1504,8 @@ bool LnnIsNeedCleanConnectionFsm(const NodeInfo *nodeInfo, ConnectionAddrType ty
(void)memset_s(&oldNodeInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
int32_t ret = LnnGetRemoteNodeInfoById(nodeInfo->deviceInfo.deviceUdid, CATEGORY_UDID, &oldNodeInfo);
if (ret != SOFTBUS_OK || !LnnIsNodeOnline(nodeInfo)) {
LNN_LOGW(LNN_BUILDER, "device is node online");
if (ret != SOFTBUS_OK || !LnnIsNodeOnline(&oldNodeInfo)) {
LNN_LOGW(LNN_BUILDER, "device is not online, ret=%{public}d", ret);
return false;
}
if (IsBasicNodeInfoChanged(&oldNodeInfo, nodeInfo, false)) {
@ -1607,7 +1607,7 @@ static void OnlineStateEnter(FsmStateMachine *fsm)
LNN_LOGI(LNN_BUILDER,
"online state enter. [id=%{public}u], networkId=%{public}s, udid=%{public}s, "
"uuid=%{public}s, deviceName=%{public}s, peer%{public}s",
connFsm->id, anonyNetworkId, isNodeInfoValid ? AnonymizeWrapper(anonyUdid) : "",
connFsm->id, AnonymizeWrapper(anonyNetworkId), isNodeInfoValid ? AnonymizeWrapper(anonyUdid) : "",
isNodeInfoValid ? AnonymizeWrapper(anonyUuid) : "",
isNodeInfoValid ? AnonymizeWrapper(anonyDeviceName) : "",
LnnPrintConnectionAddr(&connFsm->connInfo.addr));
@ -1615,6 +1615,10 @@ static void OnlineStateEnter(FsmStateMachine *fsm)
AnonymizeFree(anonyUdid);
AnonymizeFree(anonyUuid);
AnonymizeFree(anonyDeviceName);
} else {
LNN_LOGI(LNN_BUILDER,
"online state enter. [id=%{public}u], networkId=%{public}s, peer%{public}s",
connFsm->id, AnonymizeWrapper(anonyNetworkId), LnnPrintConnectionAddr(&connFsm->connInfo.addr));
}
AnonymizeFree(anonyNetworkId);
LnnNotifyOOBEStateChangeEvent(SOFTBUS_FACK_OOBE_END);
@ -1724,12 +1728,16 @@ static void LeavingStateEnter(FsmStateMachine *fsm)
LNN_LOGI(LNN_BUILDER,
"leaving state enter. [id=%{public}u], networkId=%{public}s, udid=%{public}s, deviceName=%{public}s, "
"peer%{public}s",
connFsm->id, anonyNetworkId, isNodeInfoValid ? AnonymizeWrapper(anonyUdid) : "",
connFsm->id, AnonymizeWrapper(anonyNetworkId), isNodeInfoValid ? AnonymizeWrapper(anonyUdid) : "",
isNodeInfoValid ? AnonymizeWrapper(anonyDeviceName) : "",
LnnPrintConnectionAddr(&connFsm->connInfo.addr));
if (isNodeInfoValid) {
AnonymizeFree(anonyUdid);
AnonymizeFree(anonyDeviceName);
} else {
LNN_LOGI(LNN_BUILDER,
"leaving state enter. [id=%{public}u], networkId=%{public}s, peer%{public}s",
connFsm->id, AnonymizeWrapper(anonyNetworkId), LnnPrintConnectionAddr(&connFsm->connInfo.addr));
}
AnonymizeFree(anonyNetworkId);
if (CheckDeadFlag(connFsm, true)) {

View File

@ -33,6 +33,12 @@ int32_t LnnLedgerAllDataSyncToDB(NodeInfo *info)
return SOFTBUS_NOT_IMPLEMENT;
}
int32_t LnnAsyncCallLedgerAllDataSyncToDB(NodeInfo *info)
{
(void)info;
return SOFTBUS_NOT_IMPLEMENT;
}
int32_t LnnLedgerDataChangeSyncToDB(const char *key, const char *value, size_t valueLength)
{
(void)key;

View File

@ -42,9 +42,15 @@
#include "softbus_adapter_json.h"
#include "message_handler.h"
#define DELAY_LEN 1000
#define MAX_TRY 10
#define KEY_NICK_NAME "KEY_NICK_NAME"
#define KEY_ACCOUNT "KEY_ACCOUNT"
static int32_t g_tryGetDevnameNums = 0;
static bool g_needSubscribeAccount = false;
static void UpdataLocalFromSetting(void *p);
static int32_t LnnSyncDeviceName(const char *networkId)
{
const char *deviceName = NULL;
@ -66,6 +72,40 @@ static int32_t LnnSyncDeviceName(const char *networkId)
return SOFTBUS_OK;
}
static int32_t LnnSyncDeviceNickName(const char *networkId)
{
int64_t accountId = 0;
const NodeInfo *info = LnnGetLocalNodeInfo();
if (info == NULL) {
LNN_LOGE(LNN_BUILDER, "get local nodeInfo fail");
return SOFTBUS_ERR;
}
(void)GetCurrentAccount(&accountId);
JsonObj *json = JSON_CreateObject();
if (json == NULL) {
return SOFTBUS_ERR;
}
if (!JSON_AddStringToObject(json, KEY_NICK_NAME, info->deviceInfo.nickName) ||
!JSON_AddInt64ToObject(json, KEY_ACCOUNT, accountId)) {
LNN_LOGE(LNN_BUILDER, "sync device name fail");
JSON_Delete(json);
return SOFTBUS_ERR;
}
char *msg = JSON_PrintUnformatted(json);
JSON_Delete(json);
if (msg == NULL) {
return SOFTBUS_ERR;
}
if (LnnSendSyncInfoMsg(LNN_INFO_TYPE_NICK_NAME, networkId, (const uint8_t *)msg,
strlen(msg) + 1, NULL) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "send sync nickName fail");
JSON_Free(msg);
return SOFTBUS_ERR;
}
JSON_Free(msg);
return SOFTBUS_OK;
}
static void OnReceiveDeviceName(LnnSyncInfoType type, const char *networkId, const uint8_t *msg, uint32_t len)
{
char udid[UDID_BUF_LEN];
@ -75,8 +115,8 @@ static void OnReceiveDeviceName(LnnSyncInfoType type, const char *networkId, con
return;
}
char deviceName[DEVICE_NAME_BUF_LEN + 1] = {0};
if (strcpy_s(deviceName, DEVICE_NAME_BUF_LEN + 1, (char *)msg) != EOK) {
LNN_LOGE(LNN_BUILDER, "strcpy fail");
if (memcpy_s(deviceName, DEVICE_NAME_BUF_LEN, msg, len) != EOK) {
LNN_LOGE(LNN_BUILDER, "memcpy fail");
return;
}
char *anonyNetworkId = NULL;
@ -84,7 +124,7 @@ static void OnReceiveDeviceName(LnnSyncInfoType type, const char *networkId, con
char *anonyDeviceName = NULL;
Anonymize(deviceName, &anonyDeviceName);
LNN_LOGI(LNN_BUILDER, "recv device name changed. deviceName=%{public}s, networkId=%{public}s",
AnonymizeWrapper(anonyDeviceName), AnonymizeWrapper(anonyNetworkId));
anonyDeviceName, anonyNetworkId);
AnonymizeFree(anonyNetworkId);
AnonymizeFree(anonyDeviceName);
if (LnnConvertDlId(networkId, CATEGORY_NETWORK_ID, CATEGORY_UDID, udid, UDID_BUF_LEN) != SOFTBUS_OK) {
@ -145,7 +185,7 @@ static void SetDisplayName(char *displayName, const char *nickName, const NodeIn
}
char *anonyDeviceName = NULL;
Anonymize(displayName, &anonyDeviceName);
LNN_LOGI(LNN_BUILDER, "peer deviceName=%{public}s", AnonymizeWrapper(anonyDeviceName));
LNN_LOGI(LNN_BUILDER, "peer deviceName=%{public}s", anonyDeviceName);
AnonymizeFree(anonyDeviceName);
}
@ -155,7 +195,7 @@ static void NickNameMsgProc(const char *networkId, int64_t accountId, const char
LNN_CHECK_AND_RETURN_LOGE(localNodeInfo != NULL, LNN_BUILDER, "local devinfo nullptr");
char *anonyNickName = NULL;
Anonymize(nickName, &anonyNickName);
LNN_LOGI(LNN_BUILDER, "nickName is=%{public}s", AnonymizeWrapper(anonyNickName));
LNN_LOGI(LNN_BUILDER, "nickName is=%{public}s", anonyNickName);
AnonymizeFree(anonyNickName);
char displayName[DEVICE_NAME_BUF_LEN] = {0};
NodeInfo peerNodeInfo;
@ -172,7 +212,6 @@ static void NickNameMsgProc(const char *networkId, int64_t accountId, const char
LNN_LOGE(LNN_BUILDER, "set remote device nick name fail");
return;
}
char *anonyUnifiedDefaultName = NULL;
Anonymize(peerNodeInfo.deviceInfo.unifiedDefaultName, &anonyUnifiedDefaultName);
anonyNickName = NULL;
@ -183,8 +222,7 @@ static void NickNameMsgProc(const char *networkId, int64_t accountId, const char
Anonymize(peerNodeInfo.deviceInfo.deviceName, &anonyDeviceName);
LNN_LOGI(LNN_BUILDER, "peer unifiedDefaultName=%{public}s, nickName=%{public}s, "
"unifiedName=%{public}s, deviceName=%{public}s",
AnonymizeWrapper(anonyUnifiedDefaultName), AnonymizeWrapper(anonyNickName),
AnonymizeWrapper(anonyUnifiedName), AnonymizeWrapper(anonyDeviceName));
anonyUnifiedDefaultName, anonyNickName, anonyUnifiedName, anonyDeviceName);
AnonymizeFree(anonyUnifiedDefaultName);
AnonymizeFree(anonyNickName);
AnonymizeFree(anonyUnifiedName);
@ -224,32 +262,28 @@ static void OnReceiveDeviceNickName(LnnSyncInfoType type, const char *networkId,
NickNameMsgProc(networkId, accountId, nickName);
}
int32_t LnnSetLocalDeviceName(const char *pkgName, const char *displayName)
static void HandlerGetDeviceName(const char *deviceName)
{
(void)pkgName;
if (displayName == NULL) {
LNN_LOGE(LNN_BUILDER, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
char localDevName[DEVICE_NAME_BUF_LEN] = {0};
if (LnnGetLocalStrInfo(STRING_KEY_DEV_NAME, localDevName, sizeof(localDevName)) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get local devcice name failed");
return SOFTBUS_NETWORK_GET_NODE_INFO_ERR;
}
if (strcmp(localDevName, displayName) == 0) {
LNN_LOGI(LNN_BUILDER, "device name not change, ignore this msg");
return SOFTBUS_OK;
}
if (LnnSetLocalStrInfo(STRING_KEY_DEV_NAME, displayName) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set local devcice name failed");
return SOFTBUS_NETWORK_SET_NODE_INFO_ERR;
}
DiscDeviceInfoChanged(TYPE_LOCAL_DEVICE_NAME);
int32_t infoNum = 0;
NodeBasicInfo *info = NULL;
char name[DEVICE_NAME_BUF_LEN] = {0};
if (LnnGetSettingDeviceName(name, DEVICE_NAME_BUF_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set device name fail");
return;
}
if (LnnSetLocalStrInfo(STRING_KEY_DEV_NAME, name) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set device name fail");
}
char unifiedName[DEVICE_NAME_BUF_LEN] = {0};
if (LnnGetUnifiedDeviceName(unifiedName, DEVICE_NAME_BUF_LEN) == SOFTBUS_OK) {
if (LnnSetLocalUnifiedName(unifiedName) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set device unifiedName fail");
}
}
DiscDeviceInfoChanged(TYPE_LOCAL_DEVICE_NAME);
if (LnnGetAllOnlineNodeInfo(&info, &infoNum) != SOFTBUS_OK) {
LNN_LOGI(LNN_BUILDER, "get online node fail");
return SOFTBUS_NETWORK_GET_ALL_NODE_INFO_ERR;
return;
}
for (int32_t i = 0; i < infoNum; i++) {
if (LnnIsLSANode(&info[i])) {
@ -260,8 +294,221 @@ int32_t LnnSetLocalDeviceName(const char *pkgName, const char *displayName)
}
}
SoftBusFree(info);
}
static bool IsDeviceNeedSyncNickName(const char *networkId)
{
NodeInfo nodeInfo;
(void)memset_s(&nodeInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo));
if (LnnGetRemoteNodeInfoById(networkId, CATEGORY_NETWORK_ID, &nodeInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get node info fail");
return false;
}
return IsFeatureSupport(nodeInfo.feature, BIT_SUPPORT_UNIFORM_NAME_CAPABILITY);
}
static void NotifyNickNameChange(void)
{
NodeBasicInfo *info = NULL;
int32_t infoNum = 0;
if (LnnGetAllOnlineNodeInfo(&info, &infoNum) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get online node fail");
return;
}
for (int32_t i = 0; i < infoNum; i++) {
if (!IsDeviceNeedSyncNickName(info[i].networkId)) {
continue;
}
if (LnnSyncDeviceNickName(info[i].networkId) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "LnnSyncDeviceNickName fail");
}
}
SoftBusFree(info);
}
static void HandlerGetDeviceNickName(const char *displayName)
{
(void)displayName;
char nickName[DEVICE_NAME_BUF_LEN] = {0};
NodeInfo *localNodeInfo = (NodeInfo *)LnnGetLocalNodeInfo();
if (localNodeInfo == NULL) {
LNN_LOGE(LNN_BUILDER, "local devinfo nullptr");
return;
}
char unifiedName[DEVICE_NAME_BUF_LEN] = {0};
if (LnnGetUnifiedDeviceName(unifiedName, DEVICE_NAME_BUF_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get device unified name fail");
return;
}
if (strlen(localNodeInfo->deviceInfo.unifiedName) != 0) {
if (LnnSetLocalUnifiedName(unifiedName) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set device unifiedName fail");
}
}
char unifiedDefault[DEVICE_NAME_BUF_LEN] = {0};
if (LnnGetUnifiedDefaultDeviceName(unifiedDefault, DEVICE_NAME_BUF_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get defaultDeviceName fail");
return;
}
if (strlen(unifiedDefault) != 0) {
if (LnnSetLocalStrInfo(STRING_KEY_DEV_UNIFIED_DEFAULT_NAME, unifiedDefault) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set device unifiedDefaultName fail");
}
}
if (LnnGetSettingNickName(unifiedDefault, unifiedName,
nickName, DEVICE_NAME_BUF_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "get nickName fail");
return;
}
if (strlen(nickName) == 0) {
if (strcpy_s(localNodeInfo->deviceInfo.nickName, DEVICE_NAME_BUF_LEN, "") != EOK) {
LNN_LOGE(LNN_BUILDER, "strcpy fail");
}
} else {
if (LnnSetLocalStrInfo(STRING_KEY_DEV_NICK_NAME, nickName) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "set device nickName fail");
}
}
NotifyNickNameChange();
}
static void LnnHandlerGetDeviceName(DeviceNameType type, const char *name)
{
if (type == DEVICE_NAME_TYPE_DEV_NAME) {
HandlerGetDeviceName(name);
} else if (type == DEVICE_NAME_TYPE_NICK_NAME) {
HandlerGetDeviceNickName(name);
} else {
LNN_LOGW(LNN_BUILDER, "invalid type=%{public}d", type);
}
LnnNotifyLocalNetworkIdChanged();
return SOFTBUS_OK;
}
static void UpdateLocalExtendDeviceName(const char *deviceName, char *unifiedName, char *unifiedDefaultName,
char *nickName)
{
if (LnnGetUnifiedDeviceName(unifiedName, DEVICE_NAME_BUF_LEN) == SOFTBUS_OK && strlen(unifiedName) != 0) {
if (LnnSetLocalStrInfo(STRING_KEY_DEV_UNIFIED_NAME, unifiedName) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "UpdateLocalFromSetting set unified name fail");
}
}
if (LnnGetUnifiedDefaultDeviceName(unifiedDefaultName, DEVICE_NAME_BUF_LEN) == SOFTBUS_OK &&
strlen(unifiedDefaultName) != 0) {
if (LnnSetLocalStrInfo(STRING_KEY_DEV_UNIFIED_DEFAULT_NAME, unifiedDefaultName) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "UpdateLocalFromSetting set default unified name fail");
}
}
if (LnnGetSettingNickName(deviceName, unifiedName, nickName, DEVICE_NAME_BUF_LEN) == SOFTBUS_OK &&
strlen(nickName) != 0) {
if (LnnSetLocalStrInfo(STRING_KEY_DEV_NICK_NAME, nickName) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "UpdateLocalFromSetting set nick name fail");
}
}
}
static void AccountBootEventHandle(const char *key, const char *value, void *context)
{
(void)context;
LNN_LOGI(LNN_EVENT, "account is ready, key=%{public}s, value=%{public}s", key, value);
if (strcmp(key, BOOTEVENT_ACCOUNT_READY) != 0 || strcmp(value, "true") != 0) {
return;
}
g_tryGetDevnameNums = 0;
g_needSubscribeAccount = false;
int32_t ret = LnnAsyncCallbackDelayHelper(GetLooper(LOOP_TYPE_DEFAULT), UpdataLocalFromSetting, NULL, 0);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_EVENT, "async call boot event fail");
}
}
static void PrintLocalExtendDeviceName(const char *deviceName, const char *unifiedName,
const char *unifiedDefaultName, const char *nickName)
{
char *anonyDeviceName = NULL;
Anonymize(deviceName, &anonyDeviceName);
char *anonyUnifiedName = NULL;
Anonymize(unifiedName, &anonyUnifiedName);
char *anonyUnifiedDefaultName = NULL;
Anonymize(unifiedDefaultName, &anonyUnifiedDefaultName);
char *anonyNickName = NULL;
Anonymize(nickName, &anonyNickName);
LNN_LOGI(LNN_BUILDER, "UpdateLocalFromSetting done, deviceName=%{public}s, unifiedName=%{public}s, "
"unifiedDefaultName=%{public}s, nickName=%{public}s",
anonyDeviceName, anonyUnifiedName, anonyUnifiedDefaultName, anonyNickName);
AnonymizeFree(anonyDeviceName);
AnonymizeFree(anonyUnifiedName);
AnonymizeFree(anonyUnifiedDefaultName);
AnonymizeFree(anonyNickName);
}
static void UpdataLocalFromSetting(void *p)
{
(void)p;
char deviceName[DEVICE_NAME_BUF_LEN] = {0};
char unifiedName[DEVICE_NAME_BUF_LEN] = {0};
char unifiedDefaultName[DEVICE_NAME_BUF_LEN] = {0};
char nickName[DEVICE_NAME_BUF_LEN] = {0};
if (LnnGetSettingDeviceName(deviceName, DEVICE_NAME_BUF_LEN) != SOFTBUS_OK) {
g_tryGetDevnameNums++;
LNN_LOGI(LNN_BUILDER, "g_tryGetDevnameNums=%{public}d, needSubscribe=%{public}d",
g_tryGetDevnameNums, g_needSubscribeAccount);
if (g_tryGetDevnameNums < MAX_TRY) {
SoftBusLooper *looper = GetLooper(LOOP_TYPE_DEFAULT);
if (looper == NULL) {
LNN_LOGE(LNN_BUILDER, "looper is null");
return;
}
int ret = LnnAsyncCallbackDelayHelper(looper, UpdataLocalFromSetting, NULL, DELAY_LEN);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "init UpdataLocalFromSetting fail");
}
return;
}
if (!g_needSubscribeAccount) {
LNN_LOGE(LNN_BUILDER, "update device name fail");
RegisterNameMonitor();
return;
}
LNN_LOGI(LNN_BUILDER, "account or database not ready, retry after account ready");
if (LnnSubscribeAccountBootEvent(AccountBootEventHandle) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "watch account server fail");
RegisterNameMonitor();
}
return;
}
if (LnnSetLocalStrInfo(STRING_KEY_DEV_NAME, deviceName) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "UpdataLocalFromSetting set device name fail");
}
UpdateLocalExtendDeviceName(deviceName, unifiedName, unifiedDefaultName, nickName);
RegisterNameMonitor();
DiscDeviceInfoChanged(TYPE_LOCAL_DEVICE_NAME);
LnnNotifyLocalNetworkIdChanged();
PrintLocalExtendDeviceName(deviceName, unifiedName, unifiedDefaultName, nickName);
}
static void RegisterDeviceNameHandle(void)
{
LnnInitGetDeviceName(LnnHandlerGetDeviceName);
}
void UpdateDeviceName(void *p)
{
g_needSubscribeAccount = true;
RegisterDeviceNameHandle();
UpdataLocalFromSetting(p);
}
static void LnnAccountStateChangeHandler(const LnnEventBasicInfo *info)
{
if (info == NULL || info->event != LNN_EVENT_ACCOUNT_CHANGED) {
LNN_LOGE(LNN_BUILDER, "invalid param");
return;
}
const LnnMonitorHbStateChangedEvent *event = (const LnnMonitorHbStateChangedEvent *)info;
SoftBusAccountState accountState = (SoftBusAccountState)event->status;
LNN_LOGD(LNN_BUILDER, "account state=%{public}d", accountState);
HandlerGetDeviceNickName(NULL);
return;
}
int32_t LnnInitDevicename(void)
@ -270,11 +517,16 @@ int32_t LnnInitDevicename(void)
if (ret != SOFTBUS_OK) {
return ret;
}
if (LnnRegisterEventHandler(LNN_EVENT_ACCOUNT_CHANGED, LnnAccountStateChangeHandler) != SOFTBUS_OK) {
LNN_LOGE(LNN_BUILDER, "regist account change evt handler fail");
return SOFTBUS_ERR;
}
return LnnRegSyncInfoHandler(LNN_INFO_TYPE_NICK_NAME, OnReceiveDeviceNickName);
}
void LnnDeinitDevicename(void)
{
(void)LnnUnregSyncInfoHandler(LNN_INFO_TYPE_DEVICE_NAME, OnReceiveDeviceName);
LnnUnregisterEventHandler(LNN_EVENT_ACCOUNT_CHANGED, LnnAccountStateChangeHandler);
(void)LnnUnregSyncInfoHandler(LNN_INFO_TYPE_NICK_NAME, OnReceiveDeviceNickName);
}

View File

@ -40,6 +40,7 @@
#include "lnn_distributed_net_ledger.h"
#include "lnn_fast_offline.h"
#include "lnn_heartbeat_utils.h"
#include "lnn_kv_adapter_wrapper.h"
#include "lnn_link_finder.h"
#include "lnn_local_net_ledger.h"
#include "lnn_log.h"

View File

@ -483,13 +483,12 @@ static void DeinitNodeInfoSync(void)
static void NetBuilderConfigInit(void)
{
if (SoftbusGetConfig(SOFTBUS_INT_MAX_LNN_CONNECTION_CNT,
(unsigned char *)&LnnGetNetBuilder()->maxConnCount, sizeof(LnnGetNetBuilder()->maxConnCount)) != SOFTBUS_OK) {
if (SoftbusGetConfig(SOFTBUS_INT_MAX_LNN_CONNECTION_CNT, (unsigned char *)&LnnGetNetBuilder()->maxConnCount,
sizeof(LnnGetNetBuilder()->maxConnCount)) != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "get lnn max connection count fail, use default value");
LnnGetNetBuilder()->maxConnCount = DEFAULT_MAX_LNN_CONNECTION_COUNT;
}
if (SoftbusGetConfig(SOFTBUS_INT_LNN_MAX_CONCURRENT_NUM,
(unsigned char *)&LnnGetNetBuilder()->maxConcurrentCount,
if (SoftbusGetConfig(SOFTBUS_INT_LNN_MAX_CONCURRENT_NUM, (unsigned char *)&LnnGetNetBuilder()->maxConcurrentCount,
sizeof(LnnGetNetBuilder()->maxConcurrentCount)) != SOFTBUS_OK) {
LNN_LOGE(LNN_INIT, "get lnn max conncurent count fail, use default value");
LnnGetNetBuilder()->maxConcurrentCount = 0;
@ -841,4 +840,4 @@ void LnnDeinitNetBuilder(void)
LnnDeinitFastOffline();
LnnDeinitSyncInfoManager();
LnnGetNetBuilder()->isInit = false;
}
}

View File

@ -159,7 +159,8 @@ LnnConnectionFsm *StartNewConnectionFsm(const ConnectionAddr *addr, const char *
LnnConnectionFsm *connFsm = NULL;
if (LnnGetNetBuilder()->connCount >= LnnGetNetBuilder()->maxConnCount) {
LNN_LOGE(LNN_BUILDER, "current connection num exceeds max limit, connCount=%{public}d", LnnGetNetBuilder()->connCount);
LNN_LOGE(LNN_BUILDER, "current connection num exceeds max limit, connCount=%{public}d",
LnnGetNetBuilder()->connCount);
return NULL;
}
connFsm = LnnCreateConnectionFsm(addr, pkgName, isNeedConnect);

View File

@ -21,6 +21,7 @@
#include "lnn_device_info.h"
#include "lnn_log.h"
#include "softbus_adapter_crypto.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#define MAX_WEIGHT_VALUE 1000

View File

@ -17,8 +17,8 @@
#include <securec.h>
#include "auth_device_common_key.h"
#include "anonymizer.h"
#include "auth_device_common_key.h"
#include "bus_center_manager.h"
#include "lnn_async_callback_utils.h"
#include "lnn_distributed_net_ledger.h"
@ -33,6 +33,7 @@
#include "softbus_adapter_mem.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_json_utils.h"
#include "wifi_direct_manager.h"
#define JSON_KEY_P2P_ROLE "P2P_ROLE"

View File

@ -115,4 +115,3 @@ void LnnDeinitPtk(void)
{
return;
}

View File

@ -281,7 +281,7 @@ static SyncInfoMsg *DumpMsgExcludeListNode(const SyncInfoMsg *msg)
static int32_t DumpSyncInfoMsgList(const ListNode *srcList, ListNode *dstList)
{
if (srcList == NULL || dstList ==NULL) {
if (srcList == NULL || dstList == NULL) {
LNN_LOGE(LNN_BUILDER, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
@ -300,7 +300,7 @@ static int32_t DumpSyncInfoMsgList(const ListNode *srcList, ListNode *dstList)
return SOFTBUS_OK;
}
static SyncChannelInfo *DumpSyncChannelInfo(SyncChannelInfo *info)
static SyncChannelInfo *DumpSyncChannelInfo(const SyncChannelInfo *info)
{
SyncChannelInfo *newInfo = (SyncChannelInfo *)SoftBusCalloc(sizeof(SyncChannelInfo));
if (newInfo == NULL) {

View File

@ -19,11 +19,13 @@
#include "lnn_connection_addr_utils.h"
#include "lnn_distributed_net_ledger.h"
#include "lnn_local_net_ledger.h"
#include "lnn_log.h"
#include "lnn_net_builder.h"
#include "lnn_sync_info_manager.h"
#include "softbus_adapter_mem.h"
#include "softbus_adapter_socket.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_wifi_api_adapter.h"

View File

@ -26,11 +26,13 @@
#include "lnn_log.h"
#include "lnn_sync_info_manager.h"
#include "softbus_adapter_crypto.h"
#include "softbus_adapter_json.h"
#include "softbus_adapter_mem.h"
#include "softbus_adapter_thread.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_feature_config.h"
#include "softbus_json_utils.h"
#include "softbus_json_utils.h""
#define JSON_KEY_TYPE "type"
#define JSON_KEY_SEQ "seq"

View File

@ -198,7 +198,8 @@ static void OnBtNetifStatusChanged(LnnPhysicalSubnet *subnet, void *status)
case BT_SUBNET_MANAGER_EVENT_IF_DOWN:
if (type == LNN_NETIF_TYPE_BR) {
ret = DisableBrSubnet(subnet);
} else if (type == LNN_NETIF_TYPE_BLE) {
}
if (type == LNN_NETIF_TYPE_BLE) {
ret = DisableBleSubnet(subnet);
}
break;

View File

@ -14,6 +14,8 @@
*/
#include <securec.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "anonymizer.h"
@ -35,8 +37,12 @@
#include "lnn_physical_subnet_manager.h"
#include "message_handler.h"
#include "softbus_adapter_mem.h"
#include "softbus_adapter_thread.h"
#include "softbus_adapter_timer.h"
#include "softbus_common.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_feature_config.h"
#include "softbus_protocol_def.h"
#include "trans_tcp_direct_listener.h"
#include "conn_coap.h"

View File

@ -443,7 +443,7 @@ static void OnGroupCreated(const char *groupId, int32_t groupType)
{
(void)groupId;
LNN_LOGI(LNN_BUILDER, "OnGroupCreated, groupType=%{public}d", groupType);
LnnUpdateOhosAccount(true);
LnnUpdateOhosAccount(false);
LnnHbOnTrustedRelationIncreased(groupType);
if (groupType == AUTH_IDENTICAL_ACCOUNT_GROUP) {
LnnNotifyAccountStateChangeEvent(SOFTBUS_ACCOUNT_LOG_IN);

View File

@ -20,6 +20,7 @@
#include "lnn_log.h"
#include "lnn_network_manager.h"
#include "softbus_adapter_thread.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#define MAX_SUPPORTED_PHYSICAL_SUBNET 6

View File

@ -15,6 +15,8 @@
#include "lnn_feature_capability.h"
#include <stdint.h>
#include "lnn_log.h"
#include "softbus_errcode.h"
#include "softbus_feature_config.h"

View File

@ -15,7 +15,9 @@
#include "lnn_net_capability.h"
#include <stdint.h>
#include "lnn_log.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_feature_config.h"

View File

@ -40,6 +40,7 @@
#include "lnn_p2p_info.h"
#include "lnn_settingdata_event_monitor.h"
#include "lnn_oobe_manager.h"
#include "softbus_adapter_mem.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_utils.h"
@ -220,6 +221,9 @@ int32_t LnnInitEventMoniterDelay(void)
if (LnnInitCommonEventMonitorImpl() != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "delay init LnnInitCommonEventMonitorImpl fail");
return SOFTBUS_ERR;
}
if (LnnInitDeviceNameMonitorImpl() != SOFTBUS_OK) {
}
LnnInitOOBEStateMonitorImpl();
return SOFTBUS_OK;
@ -268,6 +272,8 @@ static int32_t LnnGetNodeKeyInfoLocal(const char *networkId, int key, uint8_t *i
return LnnGetLocalStrInfo(STRING_KEY_P2P_IP, (char *)info, infoLen);
case NODE_KEY_DEVICE_SECURITY_LEVEL:
return LnnGetLocalNumInfo(NUM_KEY_DEVICE_SECURITY_LEVEL, (int32_t *)info);
case NODE_KEY_DEVICE_SCREEN_STATUS:
return LnnGetLocalBoolInfo(BOOL_KEY_SCREEN_STATUS, (bool *)info, NODE_SCREEN_STATUS_LEN)
default:
LNN_LOGE(LNN_LEDGER, "invalid node key type=%{public}d", key);
return SOFTBUS_ERR;
@ -710,8 +716,8 @@ static int32_t SoftbusDumpPrintBroadcastCipher(int fd, NodeBasicInfo *nodeInfo)
char broadcastCipherStr[SESSION_KEY_STR_LEN] = {0};
if (ConvertBytesToHexString(broadcastCipherStr, SESSION_KEY_STR_LEN,
broadcastCipher, SESSION_KEY_LENGTH) != SOFTBUS_OK) {
(void)memset_s(broadcastCipher, SESSION_KEY_LENGTH, 0, SESSION_KEY_LENGTH);
LNN_LOGE(LNN_LEDGER, "convert broadcastCipher to string fail.");
(void)memset_s(broadcastCipher, SESSION_KEY_LENGTH, 0, SESSION_KEY_LENGTH);
return SOFTBUS_BYTE_CONVERT_FAIL;
}
char *anonyBroadcastCipher = NULL;

View File

@ -21,6 +21,7 @@
#include "anonymizer.h"
#include "lnn_log.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_utils.h"
@ -28,6 +29,7 @@
#define STATIC_LEVEL_INVALID 0xFFFF
#define SWITCH_LEVEL_INVALID 0xFFFFFFFF
#define SWTICH_LENGTH_INVALID 0xFFFF
#define SWITCH_MAX_LENGTH 24
bool LnnHasDiscoveryType(const NodeInfo *info, DiscoveryType type)
{
@ -125,6 +127,7 @@ void LnnSetBtMac(NodeInfo *info, const char *mac)
if (strncpy_s(info->connectInfo.macAddr, MAC_LEN, mac, strlen(mac)) != EOK) {
LNN_LOGE(LNN_LEDGER, "str copy error");
}
return;
}
const char *LnnGetBleMac(const NodeInfo *info)
@ -516,6 +519,19 @@ int32_t LnnSetSupportedProtocols(NodeInfo *info, uint64_t protocols)
return SOFTBUS_OK;
}
int32_t LnnSetWifiDirectAddr(NodeInfo *info, const char *wifiDirectAddr)
{
if (info == NULL || wifiDirectAddr == NULL) {
LNN_LOGE(LNN_LEDGER, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
if (strcpy_s(info->wifiDirectAddr, sizeof(info->wifiDirectAddr), wifiDirectAddr) != EOK) {
LNN_LOGE(LNN_LEDGER, "strcpy_s wifidirect addr err");
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
}
int32_t LnnSetStaticCapability(NodeInfo *info, uint8_t *cap, uint32_t len)
{
if (info == NULL || cap == NULL) {
@ -563,19 +579,6 @@ int32_t LnnSetPtk(NodeInfo *info, const char *remotePtk)
return SOFTBUS_OK;
}
int32_t LnnSetWifiDirectAddr(NodeInfo *info, const char *wifiDirectAddr)
{
if (info == NULL || wifiDirectAddr == NULL) {
LNN_LOGE(LNN_LEDGER, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
if (strcpy_s(info->wifiDirectAddr, sizeof(info->wifiDirectAddr), wifiDirectAddr) != EOK) {
LNN_LOGE(LNN_LEDGER, "strcpy_s wifidirect addr err");
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
}
void LnnDumpRemotePtk(const char *oldPtk, const char *newPtk, const char *log)
{
char ptkStr[PTK_STR_LEN] = { 0 };

View File

@ -27,9 +27,11 @@
#include "lnn_log.h"
#include "sqlite3_utils.h"
#include "softbus_adapter_crypto.h"
#include "softbus_adapter_file.h"
#include "softbus_adapter_mem.h"
#include "softbus_common.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_utils.h"

View File

@ -57,6 +57,12 @@ int32_t LnnInitDecisionDbDelay(void)
return SOFTBUS_OK;
}
int32_t LnnGenerateCeParams(void)
{
LNN_LOGI(LNN_INIT, "LnnGenerateCeParams not implemented");
return SOFTBUS_OK;
}
int32_t UpdateRecoveryDeviceInfoFromDb(void)
{
return SOFTBUS_OK;
@ -67,28 +73,3 @@ int32_t LnnCheckGenerateSoftBusKeyByHuks(void)
LNN_LOGI(LNN_INIT, "check generate softbus key by huks not implemented");
return SOFTBUS_OK;
}
int32_t EncryptStorageData(LnnEncryptDataLevel level, uint8_t *dbKey, uint32_t len)
{
(void)level;
(void)dbKey;
(void)len;
LNN_LOGI(LNN_INIT, "EncryptStorageData not implemented");
return SOFTBUS_OK;
}
int32_t DecryptStorageData(LnnEncryptDataLevel level, uint8_t *dbKey, uint32_t len)
{
(void)level;
(void)dbKey;
(void)len;
LNN_LOGI(LNN_INIT, "DecryptStorageData not implemented");
return SOFTBUS_OK;
}
int32_t LnnGenerateCeParams(void)
{
LNN_LOGI(LNN_INIT, "LnnGenerateCeParams not implemented");
return SOFTBUS_OK;
}

View File

@ -93,8 +93,8 @@ int32_t LnnSetDLSessionPort(const char *id, IdCategory type, int32_t sessionPort
int32_t LnnSetDLAuthPort(const char *id, IdCategory type, int32_t authPort);
int32_t LnnSetDLP2pIp(const char *id, IdCategory type, const char *p2pIp);
NodeInfo *LnnGetNodeInfoById(const char *id, IdCategory type);
bool LnnSetDlPtk(const char *networkId, const char *remotePtk);
bool LnnSetDLWifiDirectAddr(const char *networkId, const char *addr);
bool LnnSetDlPtk(const char *networkId, const char *remotePtk);
int32_t LnnGetOsTypeByNetworkId(const char *networkId, int32_t *osType);
int32_t LnnSetDLUnifiedDeviceName(const char *udid, const char *name);
int32_t LnnSetDLUnifiedDefaultDeviceName(const char *udid, const char *name);

View File

@ -955,6 +955,16 @@ static void GetAndSaveRemoteDeviceInfo(NodeInfo *deviceInfo, NodeInfo *info)
sizeof(info->rpaInfo.peerIrk)) != EOK) {
LNN_LOGE(LNN_LEDGER, "memcpy_s Irk fail");
return;
}
if (memcpy_s(deviceInfo->cipherInfo.key, sizeof(deviceInfo->cipherInfo.key), info->cipherInfo.key,
sizeof(info->cipherInfo.key)) != EOK) {
LNN_LOGE(LNN_LEDGER, "memcpy_s cipherInfo.key fail");
return;
}
if (memcpy_s(deviceInfo->cipherInfo.iv, sizeof(deviceInfo->cipherInfo.iv), info->cipherInfo.iv,
sizeof(info->cipherInfo.iv)) != EOK) {
LNN_LOGE(LNN_LEDGER, "memcpy_s cipherInfo.iv fail");
return;
}
LnnDumpRemotePtk(deviceInfo->remotePtk, info->remotePtk, "get and save remote device info");
if (memcpy_s(deviceInfo->remotePtk, PTK_DEFAULT_LEN, info->remotePtk, PTK_DEFAULT_LEN) != EOK) {
@ -1285,14 +1295,6 @@ static ReportCategory ClearAuthChannelId(NodeInfo *info, ConnectionAddrType type
return REPORT_OFFLINE;
}
static void LnnCleanNodeInfo(NodeInfo *info)
{
LnnSetNodeConnStatus(info, STATUS_OFFLINE);
LnnClearAuthTypeValue(&info->AuthTypeValue, ONLINE_HICHAIN);
SoftBusMutexUnlock(&g_distributedNetLedger.lock);
LNN_LOGI(LNN_LEDGER, "need to report offline");
}
ReportCategory LnnSetNodeOffline(const char *udid, ConnectionAddrType type, int32_t authId)
{
NodeInfo *info = NULL;
@ -1336,7 +1338,10 @@ ReportCategory LnnSetNodeOffline(const char *udid, ConnectionAddrType type, int3
LNN_LOGI(LNN_LEDGER, "the state is already offline, no need to report offline");
return REPORT_NONE;
}
LnnCleanNodeInfo(info);
LnnSetNodeConnStatus(info, STATUS_OFFLINE);
LnnClearAuthTypeValue(&info->AuthTypeValue, ONLINE_HICHAIN);
SoftBusMutexUnlock(&g_distributedNetLedger.lock);
LNN_LOGI(LNN_LEDGER, "need to report offline");
DfxRecordLnnSetNodeOfflineEnd(udid, (int32_t)MapGetSize(&map->udidMap), SOFTBUS_OK);
return REPORT_OFFLINE;
}
@ -1513,11 +1518,11 @@ static void UpdateDistributedLedger(NodeInfo *newInfo, NodeInfo *oldInfo)
LNN_LOGE(LNN_LEDGER, "strcpy_s p2pMac to distributed ledger fail");
}
if (memcpy_s((char *)oldInfo->rpaInfo.peerIrk, LFINDER_IRK_LEN, (char *)newInfo->rpaInfo.peerIrk,
LFINDER_IRK_LEN) != EOK) {
LFINDER_IRK_LEN) != EOK) {
LNN_LOGE(LNN_LEDGER, "memcpy_s peerIrk to distributed ledger fail");
}
if (memcpy_s((char *)oldInfo->rpaInfo.publicAddress, LFINDER_MAC_ADDR_LEN, (char *)newInfo->rpaInfo.publicAddress,
LFINDER_MAC_ADDR_LEN) != EOK) {
LFINDER_MAC_ADDR_LEN) != EOK) {
LNN_LOGE(LNN_LEDGER, "memcpy_s publicAddress to distributed ledger fail");
}
if (memcpy_s((char *)oldInfo->cipherInfo.key, SESSION_KEY_LENGTH, newInfo->cipherInfo.key, SESSION_KEY_LENGTH) !=

View File

@ -209,28 +209,6 @@ static int32_t DlGetMasterUdid(const char *networkId, bool checkOnline, void *bu
return SOFTBUS_OK;
}
static int32_t DlGetNodeBleMac(const char *networkId, bool checkOnline, void *buf, uint32_t len)
{
(void)checkOnline;
NodeInfo *info = NULL;
RETURN_IF_GET_NODE_VALID(networkId, buf, info);
if (strlen(info->connectInfo.bleMacAddr) == 0) {
LNN_LOGE(LNN_LEDGER, "ble mac is invalid.");
return SOFTBUS_ERR;
}
if (info->bleMacRefreshSwitch != 0) {
uint64_t currentTimeMs = GetCurrentTime();
LNN_CHECK_AND_RETURN_RET_LOGE(info->connectInfo.latestTime + BLE_ADV_LOST_TIME >= currentTimeMs, SOFTBUS_ERR,
LNN_LEDGER, "ble mac out date, lastAdvTime=%{public}" PRIu64 ", now=%{public}" PRIu64,
info->connectInfo.latestTime, currentTimeMs);
}
if (strcpy_s((char *)buf, len, info->connectInfo.bleMacAddr) != EOK) {
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
}
static int32_t DlGetRemotePtk(const char *networkId, bool checkOnline, void *buf, uint32_t len)
{
(void)checkOnline;
@ -293,6 +271,28 @@ static int32_t DlGetStaticCap(const char *networkId, bool checkOnline, void *buf
return SOFTBUS_OK;
}
static int32_t DlGetNodeBleMac(const char *networkId, bool checkOnline, void *buf, uint32_t len)
{
(void)checkOnline;
NodeInfo *info = NULL;
RETURN_IF_GET_NODE_VALID(networkId, buf, info);
if (strlen(info->connectInfo.bleMacAddr) == 0) {
LNN_LOGE(LNN_LEDGER, "ble mac is invalid.");
return SOFTBUS_ERR;
}
if (info->bleMacRefreshSwitch != 0) {
uint64_t currentTimeMs = GetCurrentTime();
LNN_CHECK_AND_RETURN_RET_LOGE(info->connectInfo.latestTime + BLE_ADV_LOST_TIME >= currentTimeMs, SOFTBUS_ERR,
LNN_LEDGER, "ble mac out date, lastAdvTime=%{public}" PRIu64 ", now=%{public}" PRIu64,
info->connectInfo.latestTime, currentTimeMs);
}
if (strcpy_s((char *)buf, len, info->connectInfo.bleMacAddr) != EOK) {
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
}
void LnnUpdateNodeBleMac(const char *networkId, char *bleMac, uint32_t len)
{
if ((networkId == NULL) || (bleMac == NULL) || (len != MAC_LEN)) {
@ -814,12 +814,12 @@ static DistributedLedgerKey g_dlKeyTable[] = {
{BOOL_KEY_TLV_NEGOTIATION, DlGetNodeTlvNegoFlag},
{BOOL_KEY_SCREEN_STATUS, DlGetNodeScreenOnFlag},
{BYTE_KEY_ACCOUNT_HASH, DlGetAccountHash},
{BYTE_KEY_REMOTE_PTK, DlGetRemotePtk},
{BYTE_KEY_STATIC_CAPABILITY, DlGetStaticCap},
{BYTE_KEY_IRK, DlGetDeviceIrk},
{BYTE_KEY_PUB_MAC, DlGetDevicePubMac},
{BYTE_KEY_BROADCAST_CIPHER_KEY, DlGetDeviceCipherInfoKey},
{BYTE_KEY_BROADCAST_CIPHER_IV, DlGetDeviceCipherInfoIv},
{BYTE_KEY_REMOTE_PTK, DlGetRemotePtk},
{BYTE_KEY_STATIC_CAPABILITY, DlGetStaticCap}
};
bool LnnSetDLDeviceInfoName(const char *udid, const char *name)
@ -1888,4 +1888,4 @@ bool LnnSetDLWifiDirectAddr(const char *networkId, const char *addr)
EXIT:
SoftBusMutexUnlock(&(LnnGetDistributedNetLedger()->lock));
return false;
}
}

View File

@ -201,6 +201,20 @@ static int32_t LlGetUuid(void *buf, uint32_t len)
return SOFTBUS_OK;
}
static int32_t L1GetNodeScreenOnFlag(void *buf, uint32_t len)
{
if (buf == NULL) {
LNN_LOGE(LNN_LEDGER, "buf is NULL");
return SOFTBUS_INVALID_PARAM;
}
if (len != NODE_SCREEN_STATUS_LEN) {
LNN_LOGE(LNN_LEDGER, "buf len=%{public}d is invalid", len);
return SOFTBUS_INVALID_PARAM;
}
*((bool *)buf) = g_localNetLedger.localInfo.isScreenOn;
return SOFTBUS_OK;
}
static int32_t UpdateLocalDeviceUdid(const void *buf)
{
NodeInfo *info = &g_localNetLedger.localInfo;
@ -366,7 +380,7 @@ static int32_t LocalUpdateNetworkIdTimeStamp(const void *buf)
return SOFTBUS_INVALID_PARAM;
}
info->networkIdTimestamp = *((int64_t *)buf);
LNN_LOGD(LNN_LEDGER, "local networkId timeStamp=%{public}" PRId64, info->networkIdTimestamp);
LNN_LOGI(LNN_LEDGER, "local networkId timeStamp=%{public}" PRId64, info->networkIdTimestamp);
return SOFTBUS_OK;
}
@ -633,7 +647,7 @@ static int32_t UpdateStateVersion(const void *buf)
LNN_LOGE(LNN_LEDGER, "memcpy fail");
return SOFTBUS_MEM_ERR;
}
if (LnnLedgerAllDataSyncToDB(&nodeInfo) != SOFTBUS_OK) {
if (LnnAsyncCallLedgerAllDataSyncToDB(&nodeInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "ledger stateversion change sync to cloud failed");
}
return SOFTBUS_OK;
@ -1110,7 +1124,7 @@ static int32_t UpdateLocalDeviceName(const void *name)
LNN_LOGE(LNN_LEDGER, "memcpy fail");
return SOFTBUS_MEM_ERR;
}
if (LnnLedgerAllDataSyncToDB(&nodeInfo) != SOFTBUS_OK) {
if (LnnAsyncCallLedgerAllDataSyncToDB(&nodeInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "ledger device name change sync to cloud failed");
}
}
@ -1178,7 +1192,7 @@ static int32_t UpdateUnifiedDefaultName(const void *name)
LNN_LOGE(LNN_LEDGER, "memcpy fail");
return SOFTBUS_MEM_ERR;
}
if (LnnLedgerAllDataSyncToDB(&nodeInfo) != SOFTBUS_OK) {
if (LnnAsyncCallLedgerAllDataSyncToDB(&nodeInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "ledger unified default device name change sync to cloud failed");
}
}
@ -1211,7 +1225,7 @@ static int32_t UpdateNickName(const void *name)
LNN_LOGE(LNN_LEDGER, "memcpy fail");
return SOFTBUS_MEM_ERR;
}
if (LnnLedgerAllDataSyncToDB(&nodeInfo) != SOFTBUS_OK) {
if (LnnAsyncCallLedgerAllDataSyncToDB(&nodeInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "ledger nick name change sync to cloud failed");
}
}
@ -1257,7 +1271,7 @@ static int32_t UpdateLocalNetworkId(const void *id)
LNN_LOGE(LNN_LEDGER, "memcpy fail");
return SOFTBUS_MEM_ERR;
}
if (LnnLedgerAllDataSyncToDB(&nodeInfo) != SOFTBUS_OK) {
if (LnnAsyncCallLedgerAllDataSyncToDB(&nodeInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "ledger networkId change sync to cloud failed");
}
return SOFTBUS_OK;
@ -1397,7 +1411,7 @@ static int32_t UpdateLocalBtMac(const void *mac)
LNN_LOGE(LNN_LEDGER, "memcpy fail");
return SOFTBUS_MEM_ERR;
}
if (LnnLedgerAllDataSyncToDB(&nodeInfo) != SOFTBUS_OK) {
if (LnnAsyncCallLedgerAllDataSyncToDB(&nodeInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "ledger btMac change sync to cloud failed");
}
return SOFTBUS_OK;
@ -1560,7 +1574,7 @@ void LnnUpdateStateVersion(StateVersionChangeReason reason)
LNN_LOGE(LNN_LEDGER, "memcpy fail");
return;
}
if (LnnLedgerAllDataSyncToDB(&nodeInfo) != SOFTBUS_OK) {
if (LnnAsyncCallLedgerAllDataSyncToDB(&nodeInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "ledger stateversion change sync to cloud failed");
}
}
@ -1836,16 +1850,17 @@ static LocalLedgerKey g_localKeyTable[] = {
{NUM_KEY_ACCOUNT_LONG, sizeof(int64_t), LocalGetNodeAccountId, LocalUpdateNodeAccountId},
{NUM_KEY_BLE_START_TIME, sizeof(int64_t), LocalGetNodeBleStartTime, LocalUpdateBleStartTime},
{NUM_KEY_CONN_SUB_FEATURE_CAPA, -1, L1GetConnSubFeatureCapa, UpdateLocalConnSubFeatureCapability},
{NUM_KEY_STATIC_CAP_LEN, sizeof(int32_t), LlGetStaticCapLen, LlUpdateStaticCapLen},
{NUM_KEY_DEVICE_SECURITY_LEVEL, sizeof(int32_t), LlGetDeviceSecurityLevel, LlUpdateDeviceSecurityLevel},
{BYTE_KEY_IRK, LFINDER_IRK_LEN, LlGetIrk, UpdateLocalIrk},
{BYTE_KEY_PUB_MAC, LFINDER_MAC_ADDR_LEN, LlGetPubMac, UpdateLocalPubMac},
{BYTE_KEY_BROADCAST_CIPHER_KEY, SESSION_KEY_LENGTH, LlGetCipherInfoKey, UpdateLocalCipherInfoKey},
{BYTE_KEY_BROADCAST_CIPHER_IV, BROADCAST_IV_LEN, LlGetCipherInfoIv, UpdateLocalCipherInfoIv},
{NUM_KEY_STATIC_CAP_LEN, sizeof(int32_t), LlGetStaticCapLen, LlUpdateStaticCapLen},
{NUM_KEY_DEVICE_SECURITY_LEVEL, sizeof(int32_t), LlGetDeviceSecurityLevel, LlUpdateDeviceSecurityLevel},
{NUM_KEY_NETWORK_ID_TIMESTAMP, sizeof(int64_t), LocalGetNetworkIdTimeStamp, LocalUpdateNetworkIdTimeStamp},
{BYTE_KEY_ACCOUNT_HASH, SHA_256_HASH_LEN, LlGetAccount, LlUpdateAccount},
{BYTE_KEY_STATIC_CAPABILITY, STATIC_CAP_LEN, LlGetStaticCapability, LlUpdateStaticCapability},
{BYTE_KEY_UDID_HASH, SHA_256_HASH_LEN, LlGetUdidHash, NULL},
{BOOL_KEY_SCREEN_STATUS, NODE_SCREEN_STATUS_LEN, L1GetNodeScreenOnFlag, NULL},
};
int32_t LnnGetLocalStrInfo(InfoKey key, char *info, uint32_t len)
@ -1909,6 +1924,36 @@ static int32_t LnnGetLocalInfo(InfoKey key, void* info, uint32_t infoSize)
return SOFTBUS_ERR;
}
int32_t LnnGetLocalBoolInfo(InfoKey key, bool *info, uint32_t len)
{
uint32_t i;
int32_t ret;
if (key >= BOOL_KEY_END) {
LNN_LOGE(LNN_LEDGER, "KEY error");
return SOFTBUS_INVALID_PARAM;
}
if (info == NULL) {
LNN_LOGE(LNN_LEDGER, "info is NULL");
return SOFTBUS_INVALID_PARAM;
}
if (SoftBusMutexLock(&g_localNetLedger.lock) != 0) {
LNN_LOGE(LNN_LEDGER, "lock mutex fail");
return SOFTBUS_LOCK_ERR;
}
for (i = 0; i < sizeof(g_localKeyTable) / sizeof(LocalLedgerKey); i++) {
if (key == g_localKeyTable[i].key) {
if (g_localKeyTable[i].getInfo != NULL) {
ret = g_localKeyTable[i].getInfo((void *)info, len);
SoftBusMutexUnlock(&g_localNetLedger.lock);
return ret;
}
}
}
SoftBusMutexUnlock(&g_localNetLedger.lock);
LNN_LOGE(LNN_LEDGER, "KEY NOT exist");
return SOFTBUS_ERR;
}
static bool JudgeString(const char *info, int32_t len)
{
return (len <= 0) ? false : IsValidString(info, (uint32_t)len);

View File

@ -753,7 +753,7 @@ void LnnNotifySingleOffLineEvent(const ConnectionAddr *addr, NodeBasicInfo *basi
void LnnNotifyLpReportEvent(SoftBusLpEventType type)
{
if (type < SOFTBUS_MSDP_MOVEMENT_AND_STATIONARY || type >= SOFTBUS_LP_EVENT_UNKNOWN) {
LNN_LOGW(LNN_EVENT, "bad lp event type = %{public}d", type);
LNN_LOGW(LNN_EVENT, "bad lp event type=%{public}d", type);
return;
}
LnnLpReportEvent event = {.basic.event = LNN_EVENT_LP_EVENT_REPORT, .type = type};

View File

@ -32,7 +32,6 @@ typedef enum {
LNN_FILE_ID_BROADCAST_KEY,
LNN_FILE_ID_PTK_KEY,
LNN_FILE_ID_IRK_KEY,
LNN_FILE_ID_DEVICEIRK_KEY,
LNN_FILE_ID_BROADCAST_CIPHER,
LNN_FILE_ID_MAX
} LnnFileId;

View File

@ -41,7 +41,6 @@ static FilePathInfo g_filePath[LNN_FILE_ID_MAX] = {
{ LNN_FILE_ID_BROADCAST_KEY, "/dsoftbus/broadcastkey" },
{ LNN_FILE_ID_PTK_KEY, "/dsoftbus/ptkkey" },
{ LNN_FILE_ID_IRK_KEY, "/dsoftbus/irk" },
{ LNN_FILE_ID_DEVICEIRK_KEY, "/dsoftbus/deviceirk" },
{ LNN_FILE_ID_BROADCAST_CIPHER, "/dsoftbus/cipher" },
};

View File

@ -21,7 +21,6 @@
#include <securec.h>
#include "anonymizer.h"
#include "lnn_decision_db.h"
#include "lnn_file_utils.h"
#include "lnn_log.h"
#include "lnn_node_info.h"
@ -98,96 +97,26 @@ int32_t LnnGenLocalUuid(char *uuid, uint32_t len)
return SOFTBUS_OK;
}
static int32_t IrkAnonymizePrint(unsigned char *irk)
{
if (irk == NULL) {
return SOFTBUS_INVALID_PARAM;
}
char irkStr[LFINDER_IRK_STR_LEN] = {0};
if (ConvertBytesToHexString(irkStr, LFINDER_IRK_STR_LEN, irk, LFINDER_IRK_LEN) != SOFTBUS_OK) {
LNN_LOGW(LNN_STATE, "convert irk to string fail");
return SOFTBUS_ERR;
}
char *anonyIrk = NULL;
Anonymize(irkStr, &anonyIrk);
LNN_LOGI(LNN_STATE, "get irk success:irk=%{public}s", AnonymizeWrapper(anonyIrk));
AnonymizeFree(anonyIrk);
(void)memset_s(irkStr, LFINDER_IRK_STR_LEN, 0, LFINDER_IRK_STR_LEN);
return SOFTBUS_OK;
}
static int32_t EncryptSaveIrk(const char *filePath, unsigned char *irk, uint32_t len)
{
if (EncryptStorageData(LNN_ENCRYPT_LEVEL_DE, (uint8_t *)irk, len) != SOFTBUS_OK) {
LNN_LOGE(LNN_STATE, "encrypt irk fail");
return SOFTBUS_ERR;
}
if (SoftBusWriteFile(filePath, (char *)irk, len) != SOFTBUS_OK) {
LNN_LOGE(LNN_STATE, "write encrypted irk to file failed");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
static int32_t GetIrkFromOldFile(const char *irkFilePath, const char *encryptIrkFilePath,
unsigned char *irk, uint32_t len)
{
unsigned char locaIrk[LFINDER_IRK_LEN] = {0};
if (SoftBusReadFullFile(irkFilePath, (char *)locaIrk, len) != SOFTBUS_OK) {
if (SoftBusGenerateRandomArray(locaIrk, len) != SOFTBUS_OK) {
LNN_LOGE(LNN_STATE, "generate deviceIrk id fail");
return SOFTBUS_ERR;
}
}
if (memcpy_s(irk, len, locaIrk, LFINDER_IRK_LEN) != EOK) {
LNN_LOGE(LNN_STATE, "copy irk id fail");
(void)memset_s(locaIrk, LFINDER_IRK_LEN, 0, LFINDER_IRK_LEN);
return SOFTBUS_ERR;
}
if (IrkAnonymizePrint(irk) != SOFTBUS_OK) {
LNN_LOGE(LNN_STATE, "print anonymize irk failed");
}
if (EncryptSaveIrk(encryptIrkFilePath, locaIrk, len) != SOFTBUS_OK) {
LNN_LOGE(LNN_STATE, "save deviceIrk id fail");
(void)memset_s(locaIrk, LFINDER_IRK_LEN, 0, LFINDER_IRK_LEN);
return SOFTBUS_ERR;
}
if (IrkAnonymizePrint(locaIrk) != SOFTBUS_OK) {
LNN_LOGE(LNN_STATE, "print anonymize encrypted irk failed");
}
(void)memset_s(locaIrk, LFINDER_IRK_LEN, 0, LFINDER_IRK_LEN);
return SOFTBUS_OK;
}
static int32_t GetIrkFromFile(unsigned char *irk, uint32_t len)
{
int32_t rc;
char irkFilePath[SOFTBUS_MAX_PATH_LEN] = {0};
char encryptIrkFilePath[SOFTBUS_MAX_PATH_LEN] = {0};
rc = LnnGetFullStoragePath(LNN_FILE_ID_DEVICEIRK_KEY, encryptIrkFilePath, SOFTBUS_MAX_PATH_LEN);
if (rc != SOFTBUS_OK) {
LNN_LOGE(LNN_STATE, "get deviceIrk save path fail");
return SOFTBUS_ERR;
}
if (SoftBusReadFullFile(encryptIrkFilePath, (char *)irk, len) == SOFTBUS_OK) {
if (DecryptStorageData(LNN_ENCRYPT_LEVEL_DE, (uint8_t *)irk, len) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "decrypt deviceIrk fail");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
LNN_LOGI(LNN_STATE, "device irk file not exist");
rc = LnnGetFullStoragePath(LNN_FILE_ID_IRK_KEY, irkFilePath, SOFTBUS_MAX_PATH_LEN);
if (rc != SOFTBUS_OK) {
LNN_LOGE(LNN_STATE, "get irk save path fail");
return SOFTBUS_ERR;
}
if (GetIrkFromOldFile(irkFilePath, encryptIrkFilePath, irk, len) != SOFTBUS_OK) {
LNN_LOGE(LNN_STATE, "get old irk fail");
return SOFTBUS_ERR;
if (SoftBusReadFullFile(irkFilePath, (char *)irk, len) != SOFTBUS_OK) {
if (SoftBusGenerateRandomArray(irk, len) != SOFTBUS_OK) {
LNN_LOGE(LNN_STATE, "generate irk id fail");
return SOFTBUS_ERR;
}
if (SoftBusWriteFile(irkFilePath, (char *)irk, len) != SOFTBUS_OK) {
LNN_LOGE(LNN_STATE, "write irk to file failed");
return SOFTBUS_ERR;
}
}
SoftBusRemoveFile(irkFilePath);
return SOFTBUS_OK;
}
@ -216,14 +145,12 @@ int32_t LnnGenLocalIrk(unsigned char *irk, uint32_t len)
char irkStr[LFINDER_IRK_STR_LEN] = {0};
if (ConvertBytesToHexString(irkStr, LFINDER_IRK_STR_LEN, irk, LFINDER_IRK_LEN) != SOFTBUS_OK) {
LNN_LOGW(LNN_STATE, "convert irk to string fail, just is dump, ignore this warning");
(void)memset_s(locaIrk, LFINDER_IRK_LEN, 0, LFINDER_IRK_LEN);
return SOFTBUS_OK;
}
char *anonyIrk = NULL;
Anonymize(irkStr, &anonyIrk);
LNN_LOGI(LNN_STATE, "get irk success:irk=%{public}s", AnonymizeWrapper(anonyIrk));
AnonymizeFree(anonyIrk);
(void)memset_s(locaIrk, LFINDER_IRK_LEN, 0, LFINDER_IRK_LEN);
(void)memset_s(irkStr, LFINDER_IRK_STR_LEN, 0, LFINDER_IRK_STR_LEN);
return SOFTBUS_OK;
}

View File

@ -31,10 +31,9 @@
namespace OHOS {
sptr<IRemoteObject> g_remoteProxy = nullptr;
namespace {
uint32_t g_getSystemAbilityId = 2;
const std::u16string SAMANAGER_INTERFACE_TOKEN = u"ohos.samgr.accessToken";
sptr<IRemoteObject> GetSystemAbility()
static sptr<IRemoteObject> GetSystemAbility()
{
MessageParcel data;
@ -60,7 +59,6 @@ sptr<IRemoteObject> GetSystemAbility()
}
return reply.ReadRemoteObject();
}
}
int32_t BusCenterServerProxy::BusCenterServerProxyStandardInit(void)
{
@ -774,6 +772,7 @@ int32_t BusCenterServerProxy::RefreshLNN(const char *pkgName, const SubscribeInf
LNN_LOGE(LNN_EVENT, "remote is nullptr");
return SOFTBUS_IPC_ERR;
}
MessageParcel data;
if (!data.WriteInterfaceToken(GetDescriptor())) {
LNN_LOGE(LNN_EVENT, "write InterfaceToken failed");
@ -983,7 +982,7 @@ int32_t BusCenterServerProxy::ShiftLNNGear(const char *pkgName, const char *call
return SOFTBUS_ERR;
}
bool targetNetworkIdIsNull = targetNetworkId == nullptr;
bool targetNetworkIdIsNull = targetNetworkId == nullptr ? true : false;
MessageParcel data;
if (!data.WriteInterfaceToken(GetDescriptor())) {
LNN_LOGE(LNN_EVENT, "write InterfaceToken failed");
@ -1075,7 +1074,7 @@ int32_t BusCenterServerProxy::GetBusCenterExObj(sptr<IRemoteObject> &object)
}
MessageParcel data;
if (!data.WriteInterfaceToken(GetDescriptor())) {
LNN_LOGE(LNN_EVENT, "write InterfaceToken failed!");
LNN_LOGE(LNN_EVENT, "GetBusCenterExObj write InterfaceToken failed!");
return SOFTBUS_ERR;
}
MessageParcel reply;
@ -1086,7 +1085,7 @@ int32_t BusCenterServerProxy::GetBusCenterExObj(sptr<IRemoteObject> &object)
return SOFTBUS_ERR;
}
if (!reply.ReadInt32(ret)) {
LNN_LOGE(LNN_EVENT, "send ret failed");
LNN_LOGE(LNN_EVENT, "GetBusCenterExObj send ret failed");
return SOFTBUS_ERR;
}
if (ret == SOFTBUS_OK) {

View File

@ -16,6 +16,9 @@
#ifndef CLIENT_BUS_CENTER_MANAGER_H
#define CLIENT_BUS_CENTER_MANAGER_H
#include <stdbool.h>
#include <stdint.h>
#include "data_level.h"
#include "data_level_inner.h"
#include "softbus_bus_center.h"

View File

@ -668,7 +668,7 @@ int32_t SetNodeDataChangeFlagInner(const char *pkgName, const char *networkId, u
int32_t RegDataLevelChangeCbInner(const char *pkgName, IDataLevelCb *callback)
{
LNN_LOGI(LNN_STATE, "RegDataLevelChangeCbInner enter");
LNN_LOGI(LNN_STATE, "enter");
g_busCenterClient.dataLevelCb = *callback;
if (strcpy_s(g_regDataLevelChangePkgName, PKG_NAME_SIZE_MAX, pkgName) != EOK) {
LNN_LOGE(LNN_STATE, "copy pkgName fail");
@ -725,7 +725,7 @@ int32_t JoinLNNInner(const char *pkgName, ConnectionAddr *target, OnJoinLNNResul
int32_t rc;
if (!g_busCenterClient.isInit) {
LNN_LOGE(LNN_STATE, "buscenter client not init");
LNN_LOGE(LNN_STATE, "join lnn not init");
return SOFTBUS_NO_INIT;
}
if (SoftBusMutexLock(&g_busCenterClient.lock) != SOFTBUS_OK) {
@ -761,7 +761,7 @@ int32_t LeaveLNNInner(const char *pkgName, const char *networkId, OnLeaveLNNResu
int32_t rc;
if (!g_busCenterClient.isInit) {
LNN_LOGE(LNN_STATE, "buscenter client not init");
LNN_LOGE(LNN_STATE, "leave lnn not init");
return SOFTBUS_NO_INIT;
}
if (SoftBusMutexLock(&g_busCenterClient.lock) != SOFTBUS_OK) {
@ -829,7 +829,7 @@ int32_t RegNodeDeviceStateCbInner(const char *pkgName, INodeStateCb *callback)
return SOFTBUS_INVALID_PARAM;
}
if (!g_busCenterClient.isInit) {
LNN_LOGE(LNN_STATE, "buscenter client not init");
LNN_LOGE(LNN_STATE, "reg node state cb not init");
return SOFTBUS_NO_INIT;
}
if (SoftBusMutexLock(&g_busCenterClient.lock) != SOFTBUS_OK) {
@ -875,7 +875,7 @@ int32_t UnregNodeDeviceStateCbInner(INodeStateCb *callback)
NodeStateCallbackItem *next = NULL;
if (!g_busCenterClient.isInit) {
LNN_LOGE(LNN_STATE, "buscenter client not init");
LNN_LOGE(LNN_STATE, "unreg node state cb not init");
return SOFTBUS_NO_INIT;
}
if (SoftBusMutexLock(&g_busCenterClient.lock) != SOFTBUS_OK) {
@ -902,7 +902,7 @@ int32_t StartTimeSyncInner(const char *pkgName, const char *targetNetworkId, Tim
int32_t rc = SOFTBUS_ERR;
if (!g_busCenterClient.isInit) {
LNN_LOGE(LNN_STATE, "buscenter client not init");
LNN_LOGE(LNN_STATE, "start time sync not init");
return SOFTBUS_NO_INIT;
}
if (SoftBusMutexLock(&g_busCenterClient.lock) != SOFTBUS_OK) {
@ -934,7 +934,7 @@ int32_t StopTimeSyncInner(const char *pkgName, const char *targetNetworkId)
TimeSyncCallbackItem *item = NULL;
if (!g_busCenterClient.isInit) {
LNN_LOGE(LNN_STATE, "buscenter client not init");
LNN_LOGE(LNN_STATE, "stop time sync cb list not init");
return SOFTBUS_NO_INIT;
}
if (SoftBusMutexLock(&g_busCenterClient.lock) != SOFTBUS_OK) {
@ -1041,7 +1041,7 @@ int32_t SetLocalDeviceNameInner(const char *pkgName, const char *displayName)
return ServerIpcSetLocalDeviceName(pkgName, displayName);
}
NO_SANITIZE("cfi") int32_t LnnOnJoinResult(void *addr, const char *networkId, int32_t retCode)
int32_t LnnOnJoinResult(void *addr, const char *networkId, int32_t retCode)
{
JoinLNNCbListItem *item = NULL;
ConnectionAddr *connAddr = (ConnectionAddr *)addr;
@ -1087,7 +1087,7 @@ int32_t LnnOnLeaveResult(const char *networkId, int32_t retCode)
return SOFTBUS_INVALID_PARAM;
}
if (!g_busCenterClient.isInit) {
LNN_LOGE(LNN_STATE, "buscenter client not init");
LNN_LOGE(LNN_STATE, "leave cb not init");
return SOFTBUS_ERR;
}
@ -1359,7 +1359,7 @@ int32_t LnnOnTimeSyncResult(const void *info, int32_t retCode)
return SOFTBUS_INVALID_PARAM;
}
if (!g_busCenterClient.isInit) {
LNN_LOGE(LNN_STATE, "buscenter client not init");
LNN_LOGE(LNN_STATE, "time sync cb not init");
return SOFTBUS_ERR;
}

View File

@ -279,10 +279,7 @@ int32_t GetNodeKeyInfo(const char *pkgName, const char *networkId, NodeDeviceInf
if (ret != SOFTBUS_OK) {
return ret;
}
if (memset_s(info, infoLen, 0, infoLen) != EOK) {
LNN_LOGE(LNN_STATE, "memset nodekey info failed");
return SOFTBUS_MEM_ERR;
}
(void)memset_s(memset_s(info, infoLen, 0, infoLen));
return GetNodeKeyInfoInner(pkgName, networkId, key, info, infoLen);
}
@ -305,8 +302,8 @@ int32_t SetNodeDataChangeFlag(const char *pkgName, const char *networkId, uint16
int32_t RegDataLevelChangeCb(const char *pkgName, IDataLevelCb *callback)
{
if (pkgName == NULL) {
LNN_LOGE(LNN_STATE, "pkgName is null");
if (pkgName == NULL || callback == NULL) {
LNN_LOGE(LNN_STATE, "pkgName or callback is null");
return SOFTBUS_INVALID_PARAM;
}
if (strcmp(g_dbPkgName, pkgName) != 0) {