Merge branch 'master' of gitee.com:openharmony/communication_dsoftbus into master

Signed-off-by: wudy1212 <wudayong1@huawei.com>
This commit is contained in:
wudy1212 2022-09-26 03:01:27 +00:00 committed by Gitee
commit b2da9d7361
67 changed files with 1691 additions and 222 deletions

View File

@ -117,6 +117,7 @@ static void DelayInitFunction(void *para)
g_driverCtrl.softbusService = HdfIoServiceBind(DRIVER_SERVICE_NAME);
if (g_driverCtrl.softbusService == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get hdf dsoftbus service fail(%d)", retry);
LnnAsyncCallbackDelayHelper(GetLooper(LOOP_TYPE_DEFAULT), DelayInitFunction, NULL, BIND_HDF_DELAY);
++retry;
return;
}

View File

@ -30,7 +30,7 @@ static int32_t ParseReply(struct HdfSBuf *rspData, uint8_t *reply, uint32_t repl
uint32_t dataSize;
if (reply == NULL) {
return SOFTBUS_OK;
return SOFTBUS_ERR;
}
if (!HdfSbufReadBuffer(rspData, (const void **)&data, &dataSize)) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "read cmd reply fail");

View File

@ -143,6 +143,9 @@ static int32_t GetRtAttr(struct rtattr *rta, int32_t len, uint16_t type, uint8_t
bool LnnIsLinkReady(const char *iface)
{
if (iface == NULL) {
return false;
}
struct ifinfomsg *info = NULL;
struct {
struct nlmsghdr hdr;

View File

@ -34,6 +34,7 @@
#include "lnn_network_manager.h"
#include "securec.h"
#include "softbus_adapter_errcode.h"
#include "softbus_adapter_mem.h"
#include "softbus_adapter_socket.h"
#include "softbus_adapter_thread.h"
#include "softbus_errcode.h"
@ -44,7 +45,7 @@
(((len) >= (int32_t)(sizeof(struct nlmsghdr))) && (((nlh)->nlmsg_len) >= sizeof(struct nlmsghdr)) && \
((int32_t)((nlh)->nlmsg_len) <= (len)))
#define DEFAULT_NETLINK_RECVBUF (4 * 1024)
#define DEFAULT_NETLINK_RECVBUF (8 * 1024)
static int32_t CreateNetlinkSocket(void)
{
@ -144,7 +145,6 @@ static void *NetlinkMonitorThread(void *para)
{
int32_t sockFd;
int32_t len;
uint8_t buffer[DEFAULT_NETLINK_RECVBUF];
struct nlmsghdr *nlh = NULL;
(void)para;
@ -154,7 +154,13 @@ static void *NetlinkMonitorThread(void *para)
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "create netlink socket failed");
return NULL;
}
uint8_t *buffer = (uint8_t *)SoftBusCalloc(DEFAULT_NETLINK_RECVBUF * sizeof(uint8_t));
if (buffer == NULL) {
close(sockFd);
return NULL;
}
while (true) {
(void)memset_s(buffer, DEFAULT_NETLINK_RECVBUF, 0, DEFAULT_NETLINK_RECVBUF);
len = SoftBusSocketRecv(sockFd, buffer, DEFAULT_NETLINK_RECVBUF, 0);
if (len < 0 && len == SOFTBUS_ADAPTER_SOCKET_EINTR) {
continue;
@ -185,6 +191,7 @@ static void *NetlinkMonitorThread(void *para)
}
}
close(sockFd);
SoftBusFree(buffer);
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "netlink monitor thread exit");
return NULL;
}

View File

@ -49,8 +49,10 @@ int32_t LnnInitProductMonitorImpl(void)
if (HdfDeviceRegisterEventListener(g_serv, &g_listener) != HDF_SUCCESS) {
HILOG_WARN(SOFTBUS_HILOG_ID, "fail to register event listener");
HdfIoServiceRecycle(g_serv);
g_serv = NULL;
return SOFTBUS_OK;
}
HILOG_ERROR(SOFTBUS_HILOG_ID, "start success...");
HILOG_INFO(SOFTBUS_HILOG_ID, "start success...");
return SOFTBUS_OK;
}

View File

@ -160,7 +160,7 @@ static void LnnSubscribeWifiService(void *para)
if (subscriberPtr->SubscribeWifiConnStateEvent() == SOFTBUS_OK &&
subscriberPtr->SubscribeWifiPowerStateEvent() == SOFTBUS_OK &&
subscriberPtr->SubscribeAPConnStateEvent() == SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "subscribe wifiservice conn and power state success");
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "subscribe wifiservice conn and power state success");
} else {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "subscribe wifiservice event fail");
retry++;

View File

@ -24,6 +24,7 @@
#include "softbus_adapter_thread.h"
#include "softbus_errcode.h"
#include "softbus_log.h"
#include "softbus_utils.h"
#define SOFTBUS_SCAN_CLIENT_ID 0
#define ADV_MAX_NUM 4
@ -40,8 +41,11 @@ typedef struct {
typedef struct {
bool isUsed;
bool isNeedReset;
bool isScanning;
SoftBusBleScanParams param;
SoftBusBleScanFilter *filter;
uint8_t filterSize;
SoftBusScanListener *listener;
} ScanListener;
@ -174,6 +178,23 @@ static unsigned char ConvertScanType(unsigned char scanType)
}
}
static int ConvertScanMode(unsigned short scanInterval, unsigned short scanWindow)
{
if (scanInterval == SOFTBUS_BLE_SCAN_INTERVAL_P2 && scanWindow == SOFTBUS_BLE_SCAN_WINDOW_P2) {
return OHOS_BLE_SCAN_MODE_OP_P2_60_3000;
}
if (scanInterval == SOFTBUS_BLE_SCAN_INTERVAL_P10 && scanWindow == SOFTBUS_BLE_SCAN_WINDOW_P10) {
return OHOS_BLE_SCAN_MODE_OP_P10_60_600;
}
if (scanInterval == SOFTBUS_BLE_SCAN_INTERVAL_P25 && scanWindow == SOFTBUS_BLE_SCAN_WINDOW_P25) {
return OHOS_BLE_SCAN_MODE_OP_P25_60_240;
}
if (scanInterval == SOFTBUS_BLE_SCAN_INTERVAL_P100 && scanWindow == SOFTBUS_BLE_SCAN_WINDOW_P100) {
return OHOS_BLE_SCAN_MODE_OP_P100_1000_1000;
}
return OHOS_BLE_SCAN_MODE_LOW_POWER;
}
void ConvertScanParam(const SoftBusBleScanParams *src, BleScanParams *dst)
{
if (src == NULL || dst == NULL) {
@ -186,6 +207,108 @@ void ConvertScanParam(const SoftBusBleScanParams *src, BleScanParams *dst)
dst->scanFilterPolicy = ConvertScanFilterPolicy(src->scanFilterPolicy);
}
static void SetAndGetSuitableScanConfig(int listenerId, const SoftBusBleScanParams *params, BleScanConfigs *configs)
{
static int lastScanMode = OHOS_BLE_SCAN_MODE_LOW_POWER;
if (params == NULL || configs == NULL) {
return;
}
(void)memset_s(configs, sizeof(BleScanConfigs), 0x0, sizeof(BleScanConfigs));
g_scanListener[listenerId].param = *params;
for (int index = 0; index < SCAN_MAX_NUM; index++) {
if (!g_scanListener[index].isUsed || (!g_scanListener[index].isScanning && index != listenerId)) {
continue;
}
int scanMode = ConvertScanMode(g_scanListener[index].param.scanInterval,
g_scanListener[index].param.scanWindow);
if (scanMode > configs->scanMode) {
configs->scanMode = scanMode;
}
}
if (lastScanMode != configs->scanMode) {
g_scanListener[listenerId].isNeedReset = true;
lastScanMode = configs->scanMode;
}
}
static void DumpBleScanFilter(BleScanNativeFilter *nativeFilter, uint8_t filterSize)
{
#define HEX_STR_MULTIPLE_NUM 2
if (nativeFilter == NULL || filterSize == 0) {
return;
}
while (filterSize-- > 0) {
if ((nativeFilter + filterSize) == NULL) {
continue;
}
int32_t len = (nativeFilter + filterSize)->serviceDataLength;
int32_t hexLen = (nativeFilter + filterSize)->serviceDataLength * HEX_STR_MULTIPLE_NUM + 1;
char *serviceData = (char *)SoftBusCalloc(sizeof(char) * hexLen);
if (serviceData == NULL) {
continue;
}
char *serviceDataMask = (char *)SoftBusCalloc(sizeof(char) * hexLen);
if (serviceDataMask == NULL) {
SoftBusFree(serviceData);
serviceData = NULL;
continue;
}
(void)ConvertBytesToHexString(serviceData, hexLen, (nativeFilter + filterSize)->serviceData, len);
(void)ConvertBytesToHexString(serviceDataMask, hexLen, (nativeFilter + filterSize)->serviceDataMask, len);
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "BLE Scan Filter id:%d [serviceData:%s, serviceDataMask:%s]",
filterSize, serviceData, serviceDataMask);
SoftBusFree(serviceData);
SoftBusFree(serviceDataMask);
}
}
static void GetAllNativeScanFilter(int thisListenerId, BleScanNativeFilter **nativeFilter, uint8_t *filterSize)
{
uint8_t nativeSize = 0;
if (nativeFilter == NULL || filterSize == NULL) {
return;
}
for (int index = 0; index < SCAN_MAX_NUM; index++) {
if (!g_scanListener[index].isUsed || (!g_scanListener[index].isScanning && index != thisListenerId)) {
g_scanListener[index].isNeedReset = false;
continue;
}
g_scanListener[index].isNeedReset = true;
nativeSize += g_scanListener[index].filterSize;
}
*filterSize = nativeSize;
*nativeFilter = (BleScanNativeFilter *)SoftBusCalloc(sizeof(BleScanNativeFilter) * nativeSize);
if (*nativeFilter == NULL) {
*filterSize = 0;
return;
}
for (int index = 0; index < SCAN_MAX_NUM; index++) {
if (!g_scanListener[index].isNeedReset) {
continue;
}
uint8_t size = g_scanListener[index].filterSize;
const SoftBusBleScanFilter *filter = g_scanListener[index].filter;
while (size-- > 0) {
nativeSize--;
(*nativeFilter + nativeSize)->address = (filter + size)->address;
(*nativeFilter + nativeSize)->deviceName = (filter + size)->deviceName;
(*nativeFilter + nativeSize)->manufactureData = (filter + size)->manufactureData;
(*nativeFilter + nativeSize)->manufactureDataLength = (filter + size)->manufactureDataLength;
(*nativeFilter + nativeSize)->manufactureDataMask = (filter + size)->manufactureDataMask;
(*nativeFilter + nativeSize)->manufactureId = (filter + size)->manufactureId;
(*nativeFilter + nativeSize)->serviceData = (filter + size)->serviceData;
(*nativeFilter + nativeSize)->serviceDataLength = (filter + size)->serviceDataLength;
(*nativeFilter + nativeSize)->serviceDataMask = (filter + size)->serviceDataMask;
(*nativeFilter + nativeSize)->serviceUuid = (filter + size)->serviceUuid;
(*nativeFilter + nativeSize)->serviceUuidLength = (filter + size)->serviceUuidLength;
(*nativeFilter + nativeSize)->serviceUuidMask = (filter + size)->serviceUuidMask;
}
}
}
static void ConvertScanResult(const BtScanResultData *src, SoftBusBleScanResult *dst)
{
if (src == NULL || dst == NULL) {
@ -632,10 +755,10 @@ int SoftBusAddScanListener(const SoftBusScanListener *listener)
}
for (int index = 0; index < SCAN_MAX_NUM; index++) {
if (!g_scanListener[index].isUsed) {
(void)memset_s(g_scanListener + index, sizeof(ScanListener), 0x0, sizeof(ScanListener));
g_scanListener[index].isUsed = true;
g_scanListener[index].isNeedReset = true;
g_scanListener[index].isScanning = false;
(void)memset_s(&g_scanListener[index].param, sizeof(SoftBusBleScanParams),
0x0, sizeof(SoftBusBleScanParams));
g_scanListener[index].listener = (SoftBusScanListener *)listener;
SoftBusMutexUnlock(&g_scanerLock);
return index;
@ -645,6 +768,50 @@ int SoftBusAddScanListener(const SoftBusScanListener *listener)
return SOFTBUS_ERR;
}
static void FreeScanFilter(int listenerId)
{
uint8_t filterSize = g_scanListener[listenerId].filterSize;
SoftBusBleScanFilter *filter = g_scanListener[listenerId].filter;
if (filter == NULL || filterSize == 0) {
return;
}
if (!g_scanListener[listenerId].isUsed) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_DBG, "ScanListener id:%d is not in use", listenerId);
return;
}
while (filterSize-- > 0) {
if ((filter + filterSize) == NULL) {
continue;
}
if ((filter + filterSize)->address != NULL) {
SoftBusFree((filter + filterSize)->address);
}
if ((filter + filterSize)->deviceName != NULL) {
SoftBusFree((filter + filterSize)->deviceName);
}
if ((filter + filterSize)->serviceUuid != NULL) {
SoftBusFree((filter + filterSize)->serviceUuid);
}
if ((filter + filterSize)->serviceUuidMask != NULL) {
SoftBusFree((filter + filterSize)->serviceUuidMask);
}
if ((filter + filterSize)->serviceData != NULL) {
SoftBusFree((filter + filterSize)->serviceData);
}
if ((filter + filterSize)->serviceDataMask != NULL) {
SoftBusFree((filter + filterSize)->serviceDataMask);
}
if ((filter + filterSize)->manufactureData != NULL) {
SoftBusFree((filter + filterSize)->manufactureData);
}
if ((filter + filterSize)->manufactureDataMask != NULL) {
SoftBusFree((filter + filterSize)->manufactureDataMask);
}
}
SoftBusFree(filter);
}
int SoftBusRemoveScanListener(int listenerId)
{
if (listenerId < 0 || listenerId >= SCAN_MAX_NUM) {
@ -654,15 +821,20 @@ int SoftBusRemoveScanListener(int listenerId)
return SOFTBUS_LOCK_ERR;
}
g_scanListener[listenerId].isUsed = false;
g_scanListener[listenerId].isNeedReset = true;
g_scanListener[listenerId].isScanning = false;
g_scanListener[listenerId].listener = NULL;
FreeScanFilter(listenerId);
SoftBusMutexUnlock(&g_scanerLock);
return SOFTBUS_OK;
}
static bool CheckNeedStartScan(void)
static bool CheckNeedReStartScan(void)
{
for (int listenerId = 0; listenerId < SCAN_MAX_NUM; listenerId++) {
if (g_scanListener[listenerId].isNeedReset) {
return true;
}
if (g_scanListener[listenerId].isScanning) {
return false;
}
@ -683,6 +855,27 @@ static bool CheckNeedStopScan(int listenerId)
return true;
}
int SoftBusSetScanFilter(int listenerId, const SoftBusBleScanFilter *filter, uint8_t filterSize)
{
if (filter == NULL || filterSize == 0) {
return SOFTBUS_INVALID_PARAM;
}
if (SoftBusMutexLock(&g_scanerLock) != 0) {
return SOFTBUS_LOCK_ERR;
}
if (!g_scanListener[listenerId].isUsed) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "ScanListener id:%d is not in use", listenerId);
SoftBusMutexUnlock(&g_scanerLock);
return SOFTBUS_ERR;
}
FreeScanFilter(listenerId);
g_scanListener[listenerId].filter = filter;
g_scanListener[listenerId].filterSize = filterSize;
g_scanListener[listenerId].isNeedReset = true;
SoftBusMutexUnlock(&g_scanerLock);
return SOFTBUS_OK;
}
int SoftBusStartScan(int listenerId, const SoftBusBleScanParams *param)
{
if (param == NULL) {
@ -696,9 +889,16 @@ int SoftBusStartScan(int listenerId, const SoftBusBleScanParams *param)
SoftBusMutexUnlock(&g_scanerLock);
return SOFTBUS_ERR;
}
BleScanConfigs scanConfig;
SetAndGetSuitableScanConfig(listenerId, param, &scanConfig);
int status = SOFTBUS_BT_STATUS_SUCCESS;
if (CheckNeedStartScan()) {
status = BleOhosStatusToSoftBus(BleStartScan());
if (CheckNeedReStartScan()) {
uint8_t filterSize = 0;
BleScanNativeFilter *nativeFilter = NULL;
GetAllNativeScanFilter(listenerId, &nativeFilter, &filterSize);
DumpBleScanFilter(nativeFilter, filterSize);
status = BleOhosStatusToSoftBus(BleStartScanEx(&scanConfig, nativeFilter, filterSize));
SoftBusFree(nativeFilter);
}
if (status != SOFTBUS_BT_STATUS_SUCCESS) {
SoftBusMutexUnlock(&g_scanerLock);

View File

@ -89,6 +89,9 @@ static void GattcRegisterNotificationCallback(int clientId, int status)
static void GattcNotificationCallback(int clientId, BtGattReadData *notifyData, int status)
{
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "GattcNotificationCallback, id=%d, status=%d", clientId, status);
if (notifyData == NULL) {
return;
}
SoftBusGattcNotify notify;
notify.dataLen = notifyData->dataLen;
notify.charaUuid.uuidLen = notifyData->attribute.characteristic.characteristicUuid.uuidLen;

View File

@ -24,6 +24,16 @@ extern "C" {
#endif
#endif
// Bluetooth scan duty cycle, unit: ms
#define SOFTBUS_BLE_SCAN_INTERVAL_P2 3000
#define SOFTBUS_BLE_SCAN_INTERVAL_P10 600
#define SOFTBUS_BLE_SCAN_INTERVAL_P25 240
#define SOFTBUS_BLE_SCAN_INTERVAL_P100 1000
#define SOFTBUS_BLE_SCAN_WINDOW_P2 60
#define SOFTBUS_BLE_SCAN_WINDOW_P10 60
#define SOFTBUS_BLE_SCAN_WINDOW_P25 60
#define SOFTBUS_BLE_SCAN_WINDOW_P100 1000
typedef enum {
SOFTBUS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE = 0x00,
SOFTBUS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE_DIRECTED = 0x04,
@ -90,6 +100,21 @@ typedef struct {
unsigned char scanFilterPolicy;
} SoftBusBleScanParams;
typedef struct {
char *address;
char *deviceName;
unsigned int serviceUuidLength;
unsigned char *serviceUuid;
unsigned char *serviceUuidMask;
unsigned int serviceDataLength;
unsigned char *serviceData;
unsigned char *serviceDataMask;
unsigned int manufactureDataLength;
unsigned char *manufactureData;
unsigned char *manufactureDataMask;
unsigned short manufactureId;
} SoftBusBleScanFilter;
typedef enum {
SOFTBUS_BLE_DATA_COMPLETE = 0x00,
SOFTBUS_BLE_DATA_INCOMPLETE_MORE_TO_COME = 0x01,
@ -152,7 +177,9 @@ int SoftBusAddScanListener(const SoftBusScanListener *listener);
int SoftBusRemoveScanListener(int listenerId);
int SoftBusStartScan(int listnerId, const SoftBusBleScanParams *param);
int SoftBusSetScanFilter(int listenerId, const SoftBusBleScanFilter *filter, uint8_t filterSize);
int SoftBusStartScan(int listenerId, const SoftBusBleScanParams *param);
int SoftBusStopScan(int listenerId);

View File

@ -22,7 +22,7 @@ extern "C" {
#endif
int32_t LnnGetOhosAccountInfo(uint8_t *accountHash, uint32_t len);
bool LnnIsDefaultOhosAccount(const uint8_t *accountHash, uint32_t len);
bool LnnIsDefaultOhosAccount(void);
#ifdef __cplusplus
}

View File

@ -15,6 +15,8 @@
#include "lnn_ohos_account.h"
#include <securec.h>
#include "bus_center_manager.h"
#include "ohos_account_kits.h"
#include "os_account_manager.h"
#include "softbus_adapter_crypto.h"
@ -64,11 +66,13 @@ int32_t LnnGetOhosAccountInfo(uint8_t *accountHash, uint32_t len)
accountInfo.second.uid_.c_str(), accountInfo.second.uid_.length());
}
bool LnnIsDefaultOhosAccount(const uint8_t *accountHash, uint32_t len)
bool LnnIsDefaultOhosAccount(void)
{
uint8_t localAccountHash[SHA_256_HASH_LEN] = {0};
uint8_t defaultAccountHash[SHA_256_HASH_LEN] = {0};
if (accountHash == nullptr || len > SHA_256_HASH_LEN) {
if (LnnGetLocalByteInfo(BYTE_KEY_USERID_HASH, localAccountHash, SHA_256_HASH_LEN) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get local accountHash fail");
return false;
}
if (SoftBusGenerateStrHash((const unsigned char *)DEFAULT_USER_ID.c_str(), DEFAULT_USER_ID.length(),
@ -76,5 +80,5 @@ bool LnnIsDefaultOhosAccount(const uint8_t *accountHash, uint32_t len)
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "generate default ohos account hash fail");
return false;
}
return memcmp(accountHash, defaultAccountHash, len) == 0;
return memcmp(localAccountHash, defaultAccountHash, SHA_256_HASH_LEN) == 0;
}

View File

@ -37,11 +37,9 @@ int32_t LnnGetOhosAccountInfo(uint8_t *accountHash, uint32_t len)
return SOFTBUS_OK;
}
bool LnnIsDefaultOhosAccount(const uint8_t *accountHash, uint32_t len)
bool LnnIsDefaultOhosAccount(void)
{
(void)accountHash;
(void)len;
return true;
return false;
}
int32_t LnnInitDeviceNameMonitorImpl(void)

View File

@ -221,6 +221,7 @@ static const GroupAuthManager *InitHichain(void)
const GroupAuthManager *gaIns = GetGaInstance();
if (gaIns == NULL) {
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_ERROR, "hichain GetGaInstance fail.");
DestroyDeviceAuthService();
return NULL;
}
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_INFO, "hichain init succ.");

View File

@ -24,6 +24,7 @@
#include "auth_session_fsm.h"
#include "auth_session_message.h"
#include "bus_center_manager.h"
#include "lnn_decision_db.h"
#include "softbus_adapter_mem.h"
#define MAX_AUTH_VALID_PERIOD (30 * 60 * 1000L) /* 30 mins */
@ -515,6 +516,7 @@ static void OnDeviceNotTrusted(const char *peerUdid)
{
RemoveNotPassedAuthManagerByUdid(peerUdid);
AuthSessionHandleDeviceNotTrusted(peerUdid);
LnnDeleteSpecificTrustedDevInfo(peerUdid);
if (g_verifyListener.onDeviceNotTrusted == NULL) {
SoftBusLog(SOFTBUS_LOG_AUTH, SOFTBUS_LOG_WARN, "onDeviceNotTrusted not set.");
return;

View File

@ -136,7 +136,8 @@ int64_t AuthGetIdByP2pMac(const char *p2pMac, AuthLinkType type, bool isServer)
{
(void)p2pMac;
(void)type;
return isServer;
(void)isServer;
return AUTH_INVALID_ID;
}
uint32_t AuthGetEncryptSize(uint32_t inLen)

View File

@ -89,7 +89,9 @@ if (defined(ohos_lite)) {
"$dsoftbus_root_path/sdk/frame/$os_type/include",
"//utils/system/safwk/native/include",
]
bus_center_server_external_deps += bus_center_adapter_external_deps
bus_center_server_deps += [ "//utils/native/base:utils" ]
bus_center_server_external_deps =
bus_center_adapter_external_deps + bus_center_ledger_external_deps
bus_center_server_external_deps += [ "c_utils:utils" ]
}

View File

@ -27,9 +27,10 @@ int32_t LnnStartHeartbeatFrameDelay(void);
int32_t LnnSetHeartbeatMediumParam(const LnnHeartbeatMediumParam *param);
int32_t LnnOfflineTimingByHeartbeat(const char *networkId, ConnectionAddrType addrType);
int32_t LnnShiftLNNGear(const char *pkgName, const char *callerId, const char *targetNetworkId, const GearMode *mode);
void LnnUpdateHeartbeatInfo(LnnHeartbeatUpdateInfoType type);
void LnnHbOnAuthGroupCreated(const char *groupId);
void LnnHbOnAuthGroupDeleted(const char *groupId);
void LnnHbOnAuthGroupCreated(void);
void LnnHbOnAuthGroupDeleted(void);
int32_t LnnInitHeartbeat(void);
void LnnDeinitHeartbeat(void);

View File

@ -43,6 +43,7 @@ typedef enum {
EVENT_HB_CHECK_DEV_STATUS,
EVENT_HB_STOP_SPECIFIC,
EVENT_HB_SET_MEDIUM_PARAM,
EVENT_HB_UPDATE_SEND_INFO,
EVENT_HB_MAX,
} LnnHeartbeatEventType;
@ -87,6 +88,7 @@ int32_t LnnPostTransStateMsgToHbFsm(LnnHeartbeatFsm *hbFsm, LnnHeartbeatEventTyp
int32_t LnnPostSetMediumParamMsgToHbFsm(LnnHeartbeatFsm *hbFsm, const LnnHeartbeatMediumParam *para);
int32_t LnnPostCheckDevStatusMsgToHbFsm(LnnHeartbeatFsm *hbFsm, const LnnCheckDevStatusMsgPara *para,
uint64_t delayMillis);
int32_t LnnPostUpdateSendInfoMsgToHbFsm(LnnHeartbeatFsm *hbFsm, LnnHeartbeatUpdateInfoType type);
void LnnRemoveSendEndMsg(LnnHeartbeatFsm *hbFsm, LnnHeartbeatType type, bool *isRemoved);
void LnnRemoveCheckDevStatusMsg(LnnHeartbeatFsm *hbFsm, LnnCheckDevStatusMsgPara *msgPara);

View File

@ -61,6 +61,7 @@ typedef struct {
int32_t (*onSendOneHbBegin)(const LnnHeartbeatCustSendData *custData);
int32_t (*onSendOneHbEnd)(void);
int32_t (*onSetMediumParam)(const LnnHeartbeatMediumParam *param);
int32_t (*onUpdateSendInfo)(LnnHeartbeatUpdateInfoType type);
int32_t (*onStopHbByType)(void);
void (*deinit)(void);
} LnnHeartbeatMediumMgr;
@ -69,6 +70,7 @@ int32_t LnnHbMediumMgrSetParam(const LnnHeartbeatMediumParam *param);
int32_t LnnHbMediumMgrSendBegin(LnnHeartbeatCustSendData *custData);
int32_t LnnHbMediumMgrSendEnd(LnnHeartbeatType *type);
int32_t LnnHbMediumMgrStop(LnnHeartbeatType *type);
int32_t LnnHbMediumMgrUpdateSendInfo(LnnHeartbeatUpdateInfoType type);
int32_t LnnHbMediumMgrInit(void);
void LnnHbMediumMgrDeinit(void);

View File

@ -44,6 +44,7 @@ int32_t LnnStartHeartbeat(void);
int32_t LnnStopHeartbeatByType(LnnHeartbeatType type);
int32_t LnnStartOfflineTimingStrategy(const char *networkId, ConnectionAddrType addrType);
int32_t LnnStopOfflineTimingStrategy(const char *networkId, ConnectionAddrType addrType);
int32_t LnnUpdateSendInfoStrategy(LnnHeartbeatUpdateInfoType type);
bool LnnIsHeartbeatEnable(LnnHeartbeatType type);
int32_t LnnEnableHeartbeatByType(LnnHeartbeatType type, bool isEnable);

View File

@ -29,13 +29,13 @@ extern "C" {
#define HB_SHORT_UDID_HASH_LEN 8
#define HB_SHORT_UDID_HASH_HEX_LEN 16
#define HB_SHORT_ACCOUNT_HASH_LEN 2
#define HB_SHA_HASH_LEN 32
#define HB_FSM_NAME_LEN 32
#define HB_TIME_FACTOR (1000LL)
#define HB_SEND_ONCE_LEN (10 * HB_TIME_FACTOR)
#define HB_CHECK_DELAY_LEN (15 * HB_TIME_FACTOR)
#define HB_CHECK_OFFLINE_TOLERANCE_LEN (5 * HB_TIME_FACTOR + HB_SEND_ONCE_LEN)
#define HB_SEND_RELAY_LEN (4 * HB_TIME_FACTOR)
#define HB_CHECK_DELAY_LEN HB_SEND_ONCE_LEN
#define HB_CHECK_OFFLINE_TOLERANCE_LEN HB_SEND_ONCE_LEN
#define HB_ENABLE_DELAY_LEN (2 * HB_TIME_FACTOR + HB_SEND_ONCE_LEN)
#define HB_REMOVE_REPEAD_RECV_LEN HB_SEND_ONCE_LEN
@ -59,6 +59,13 @@ typedef enum {
STRATEGY_HB_RECV_REMOVE_REPEAT,
} LnnHeartbeatStrategyType;
typedef enum {
UPDATE_HB_INFO_MIN = 0,
UPDATE_HB_ACCOUNT_INFO,
UPDATE_HB_NETWORK_INFO,
UPDATE_HB_MAX_INFO,
} LnnHeartbeatUpdateInfoType;
typedef bool (*VisitHbTypeCb)(LnnHeartbeatType *typeSet, LnnHeartbeatType eachType, void *data);
bool LnnVisitHbTypeSet(VisitHbTypeCb callback, LnnHeartbeatType *typeSet, void *data);

View File

@ -49,6 +49,14 @@ static int32_t SetBleMediumParam(const LnnHeartbeatMediumParam *param)
return SOFTBUS_NOT_IMPLEMENT;
}
static int32_t UpdateBleSendInfo(LnnHeartbeatUpdateInfoType type)
{
(void)type;
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "ble heartbeat stub impl update send info");
return SOFTBUS_NOT_IMPLEMENT;
}
static int32_t StopBleHeartbeat(void)
{
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "ble heartbeat stub impl beat stop");
@ -67,6 +75,7 @@ static LnnHeartbeatMediumMgr g_bleMgr = {
.onSendOneHbBegin = BleHeartbeatOnceBegin,
.onSendOneHbEnd = BleHeartbeatOnceEnd,
.onSetMediumParam = SetBleMediumParam,
.onUpdateSendInfo = UpdateBleSendInfo,
.onStopHbByType = StopBleHeartbeat,
.deinit = DeinitBleHeartbeat,
};

View File

@ -26,6 +26,7 @@
#include "lnn_heartbeat_strategy.h"
#include "lnn_ohos_account.h"
#include "softbus_adapter_ble_gatt.h"
#include "softbus_adapter_mem.h"
#include "softbus_errcode.h"
#include "softbus_log.h"
@ -41,11 +42,6 @@
#define HB_LOOPBACK_IP "127.0.0.1"
#define HB_SCREEN_ON_BLE_SCAN_INTERVAL 600
#define HB_SCREEN_ON_BLE_SCAN_WINDOW 60
#define HB_SCREEN_OFF_BLE_SCAN_INTERVAL 3000
#define HB_SCREEN_OFF_BLE_SCAN_WINDOW 60
#define HB_SAME_AUTH_GROUP_INDEX 1
#define HB_POINT_TO_POINT_INDEX 256
@ -138,12 +134,12 @@ static void HbScreenStateChangeEventHandler(const LnnEventBasicInfo *info)
SoftBusScreenState state = (SoftBusScreenState)event->status;
switch (state) {
case SOFTBUS_SCREEN_ON:
param.info.ble.scanInterval = HB_SCREEN_ON_BLE_SCAN_INTERVAL;
param.info.ble.scanWindow = HB_SCREEN_ON_BLE_SCAN_WINDOW;
param.info.ble.scanInterval = SOFTBUS_BLE_SCAN_INTERVAL_P10;
param.info.ble.scanWindow = SOFTBUS_BLE_SCAN_WINDOW_P10;
break;
case SOFTBUS_SCREEN_OFF:
param.info.ble.scanInterval = HB_SCREEN_OFF_BLE_SCAN_INTERVAL;
param.info.ble.scanWindow = HB_SCREEN_OFF_BLE_SCAN_WINDOW;
param.info.ble.scanInterval = SOFTBUS_BLE_SCAN_INTERVAL_P10;
param.info.ble.scanWindow = SOFTBUS_BLE_SCAN_WINDOW_P10;
break;
default:
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_DBG, "HB ctrl reset ble scan medium param get invalid state");
@ -171,7 +167,6 @@ static bool HbHasTrustedDeviceRelation(void)
{
uint32_t sameGroupCnt, pointGroupCnt;
char *accountGroups = NULL;
uint8_t localAccountHash[SHA_256_HASH_LEN] = {0};
/* device auth service inited by auth_manager.c */
DeviceGroupManager *gmInstance = GetGmInstance();
@ -190,13 +185,9 @@ static bool HbHasTrustedDeviceRelation(void)
return false;
}
HbFreeAccountGroups(accountGroups);
if (LnnGetLocalByteInfo(BYTE_KEY_USERID_HASH, localAccountHash, SHA_256_HASH_LEN) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "HB get local account hash fail");
return false;
}
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_DBG, "HB ctrl get sameGroupCnt: %u and pointGroupCnt: %u",
sameGroupCnt, pointGroupCnt);
if (LnnIsDefaultOhosAccount(localAccountHash, SHA_256_HASH_LEN) && sameGroupCnt == 0 && pointGroupCnt == 0) {
if (LnnIsDefaultOhosAccount() && sameGroupCnt == 0 && pointGroupCnt == 0) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_DBG, "HB no login account, no trusted relationship");
return false;
}
@ -207,6 +198,10 @@ static bool HbHasTrustedDeviceRelation(void)
int32_t LnnStartHeartbeatFrameDelay(void)
{
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "heartbeat(HB) FSM start.");
if (LnnHbMediumMgrInit() != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "HB medium manager init fail");
return SOFTBUS_ERR;
}
if (LnnStartNewHbStrategyFsm() != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "HB ctrl start strategy fsm fail");
return SOFTBUS_ERR;
@ -268,9 +263,13 @@ int32_t LnnShiftLNNGear(const char *pkgName, const char *callerId, const char *t
return SOFTBUS_OK;
}
void LnnHbOnAuthGroupCreated(const char *groupId)
void LnnUpdateHeartbeatInfo(LnnHeartbeatUpdateInfoType type)
{
LnnUpdateSendInfoStrategy(type);
}
void LnnHbOnAuthGroupCreated(void)
{
(void)groupId;
int32_t ret;
#ifdef HB_CONDITION_HAS_TRUSTED_RELATION
@ -288,9 +287,8 @@ void LnnHbOnAuthGroupCreated(const char *groupId)
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "HB send once ble broadcast to notify account group created.");
}
void LnnHbOnAuthGroupDeleted(const char *groupId)
void LnnHbOnAuthGroupDeleted(void)
{
(void)groupId;
int32_t ret;
ret = LnnStartHbByTypeAndStrategy(HEARTBEAT_TYPE_BLE_V0, STRATEGY_HB_SEND_SINGLE, false);
@ -311,10 +309,6 @@ void LnnHbOnAuthGroupDeleted(const char *groupId)
int32_t LnnInitHeartbeat(void)
{
if (LnnHbMediumMgrInit() != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "HB medium manager init fail");
return SOFTBUS_ERR;
}
if (LnnHbStrategyInit() != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "HB strategy module init fail!");
return SOFTBUS_ERR;

View File

@ -51,14 +51,21 @@ int32_t LnnShiftLNNGear(const char *pkgName, const char *callerId, const char *t
return SOFTBUS_NOT_IMPLEMENT;
}
void LnnHbOnAuthGroupCreated(const char *groupId)
void LnnUpdateHeartbeatInfo(LnnHeartbeatUpdateInfoType type)
{
(void)groupId;
(void)type;
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "heartbeat stub update send info");
}
void LnnHbOnAuthGroupDeleted(const char *groupId)
void LnnHbOnAuthGroupCreated(void)
{
(void)groupId;
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "heartbeat stub process auth group created");
}
void LnnHbOnAuthGroupDeleted(void)
{
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "heartbeat stub process auth group deleted");
}
int32_t LnnInitHeartbeat(void)

View File

@ -55,6 +55,7 @@ static int32_t OnSendOneHbBegin(FsmStateMachine *fsm, int32_t msgType, void *par
static int32_t OnSendOneHbEnd(FsmStateMachine *fsm, int32_t msgType, void *para);
static int32_t OnProcessSendOnce(FsmStateMachine *fsm, int32_t msgType, void *para);
static int32_t OnSetMediumParam(FsmStateMachine *fsm, int32_t msgType, void *para);
static int32_t OnUpdateSendInfo(FsmStateMachine *fsm, int32_t msgType, void *para);
static LnnHeartbeatStateHandler g_hbNoneStateHandler[] = {
{EVENT_HB_CHECK_DEV_STATUS, OnCheckDevStatus},
@ -73,6 +74,7 @@ static LnnHeartbeatStateHandler g_normalNodeHandler[] = {
{EVENT_HB_AS_NORMAL_NODE, OnTransHbFsmState},
{EVENT_HB_IN_NONE_STATE, OnTransHbFsmState},
{EVENT_HB_SET_MEDIUM_PARAM, OnSetMediumParam},
{EVENT_HB_UPDATE_SEND_INFO, OnUpdateSendInfo},
{EVENT_HB_STOP_SPECIFIC, OnStopHbByType},
};
@ -85,6 +87,7 @@ static LnnHeartbeatStateHandler g_masterNodeHandler[] = {
{EVENT_HB_AS_NORMAL_NODE, OnTransHbFsmState},
{EVENT_HB_IN_NONE_STATE, OnTransHbFsmState},
{EVENT_HB_SET_MEDIUM_PARAM, OnSetMediumParam},
{EVENT_HB_UPDATE_SEND_INFO, OnUpdateSendInfo},
{EVENT_HB_STOP_SPECIFIC, OnStopHbByType},
};
@ -536,6 +539,14 @@ static int32_t OnSetMediumParam(FsmStateMachine *fsm, int32_t msgType, void *par
return ret;
}
static int32_t OnUpdateSendInfo(FsmStateMachine *fsm, int32_t msgType, void *para)
{
(void)fsm;
(void)msgType;
return LnnHbMediumMgrUpdateSendInfo((LnnHeartbeatUpdateInfoType)(uintptr_t)para);
}
static void TryAsMasterNodeNextLoop(FsmStateMachine *fsm)
{
uint64_t delayMillis;
@ -987,3 +998,12 @@ int32_t LnnPostCheckDevStatusMsgToHbFsm(LnnHeartbeatFsm *hbFsm, const LnnCheckDe
}
return SOFTBUS_OK;
}
int32_t LnnPostUpdateSendInfoMsgToHbFsm(LnnHeartbeatFsm *hbFsm, LnnHeartbeatUpdateInfoType type)
{
if (hbFsm == NULL || type <= UPDATE_HB_INFO_MIN || type >= UPDATE_HB_MAX_INFO) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "HB post update info msg get invalid param");
return SOFTBUS_INVALID_PARAM;
}
return LnnFsmPostMessage(&hbFsm->fsm, EVENT_HB_UPDATE_SEND_INFO, (void *)(uintptr_t)type);
}

View File

@ -153,7 +153,7 @@ static bool HbIsRepeatedRecvInfo(const char *udidHash, ConnectionAddrType type,
static int32_t GenerateHexStringHash(const unsigned char *str, uint32_t len, char *hashStr)
{
int32_t ret;
unsigned char hashResult[HB_SHA_HASH_LEN] = {0};
uint8_t hashResult[SHA_256_HASH_LEN] = {0};
if (str == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "HB generate str hash invalid param");
@ -198,7 +198,8 @@ static const NodeInfo *HbGetOnlineNodeByRecvInfo(const char *recvUdidHash, const
continue;
}
if (strncmp(udidHash, recvUdidHash, HB_SHORT_UDID_HASH_HEX_LEN) == 0) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_DBG, "HB node udidHash:%s is online", udidHash);
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_DBG, "HB node udidHash:%s is online",
AnonymizesNetworkID(udidHash));
SoftBusFree(info);
return nodeInfo;
}
@ -232,24 +233,6 @@ static int32_t HbUpdateOfflineTimingByRecvInfo(const char *networkId, Connection
return SOFTBUS_OK;
}
static bool HbIsSameAccount(const char *accountHash, uint32_t len)
{
uint8_t localAccountHash[SHA_256_HASH_LEN] = {0};
if (LnnGetLocalByteInfo(BYTE_KEY_USERID_HASH, localAccountHash, SHA_256_HASH_LEN) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "HB IsSameAccount get local accountHash fail");
return true;
}
if (memcmp(accountHash, localAccountHash, len) != 0) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "HB IsNotSameAccount. [my %02x %02x : peer %02x %02x]",
localAccountHash[0], localAccountHash[1], accountHash[0], accountHash[1]);
return false;
}
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "HB IsSameAccount. [my %02x %02x : peer %02x %02x]",
localAccountHash[0], localAccountHash[1], accountHash[0], accountHash[1]);
return true;
}
static int32_t HbMediumMgrRecvProcess(DeviceInfo *device, int32_t weight, int32_t masterWeight, LnnHeartbeatType hbType)
{
uint64_t nowTime;
@ -266,24 +249,22 @@ static int32_t HbMediumMgrRecvProcess(DeviceInfo *device, int32_t weight, int32_
return SOFTBUS_NETWORK_HEARTBEAT_REPEATED;
}
if (HbSaveRecvTimeToRemoveRepeat(device, weight, masterWeight, nowTime) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "HB save recv time fail, udidHash:%s", device->devId);
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "HB save recv time fail, udidHash:%s",
AnonymizesUDID(device->devId));
return SOFTBUS_ERR;
}
if (!HbIsSameAccount(device->accountHash, HB_SHORT_ACCOUNT_HASH_LEN)) {
return SOFTBUS_NETWORK_NODE_OFFLINE;
}
devTypeStr = LnnConvertIdToDeviceType((uint16_t)device->devType);
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, ">> heartbeat(HB) OnTock [udidHash:%s, devTypeHex:%02X, "
"devTypeStr:%s, ConnectionAddrType:%d, peerWeight:%d, masterWeight:%d, nowTime:%" PRIu64 "]",
device->devId, device->devType, devTypeStr != NULL ? devTypeStr : "", device->addr[0].type, weight,
masterWeight, nowTime);
AnonymizesUDID(device->devId), device->devType, devTypeStr != NULL ? devTypeStr : "",
device->addr[0].type, weight, masterWeight, nowTime);
const NodeInfo *nodeInfo = HbGetOnlineNodeByRecvInfo(device->devId, device->addr[0].type);
if (nodeInfo != NULL) {
return HbUpdateOfflineTimingByRecvInfo(nodeInfo->networkId, device->addr[0].type, hbType, nowTime);
}
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "heartbeat(HB) find device, udidHash:%s, ConnectionAddrType:%02X",
device->devId, device->addr[0].type);
AnonymizesUDID(device->devId), device->addr[0].type);
if (LnnNotifyDiscoveryDevice(device->addr) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "HB mgr recv process notify device found fail");
return SOFTBUS_ERR;
@ -304,7 +285,8 @@ static int32_t HbMediumMgrRecvHigherWeight(const char *udidHash, int32_t weight,
}
nodeInfo = HbGetOnlineNodeByRecvInfo(udidHash, type);
if (nodeInfo == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_DBG, "HB recv higher weight udidhash:%s is not online yet", udidHash);
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_DBG, "HB recv higher weight udidhash:%s is not online yet",
AnonymizesUDID(udidHash));
return SOFTBUS_OK;
}
if (LnnGetLocalStrInfo(STRING_KEY_MASTER_NODE_UDID, masterUdid, sizeof(masterUdid)) != SOFTBUS_OK) {
@ -320,7 +302,8 @@ static int32_t HbMediumMgrRecvHigherWeight(const char *udidHash, int32_t weight,
if (isFromMaster) {
LnnSetHbAsMasterNodeState(false);
}
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "HB recv higher weight udidHash:%s, weight:%d", udidHash, weight);
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "HB recv higher weight udidHash:%s, weight:%d",
AnonymizesUDID(udidHash), weight);
return SOFTBUS_OK;
}
@ -332,7 +315,7 @@ static void HbMediumMgrRelayProcess(const char *udidHash, ConnectionAddrType typ
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "HB mgr relay get invalid param");
return;
}
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_DBG, "HB mgr relay process, udidhash:%s", udidHash);
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_DBG, "HB mgr relay process, udidhash:%s", AnonymizesUDID(udidHash));
if (LnnStartHbByTypeAndStrategy(hbType, STRATEGY_HB_SEND_SINGLE, true) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "HB mgr relay process fail");
return;
@ -403,8 +386,8 @@ void LnnDumpHbMgrRecvList(void)
}
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_DBG, "DumpRecvList count:%d [i:%d, udidHash:%s, "
"deviceType:%s, ConnectionAddrType:%02X, weight:%d, masterWeight:%d, lastRecvTime:%" PRIu64 "]",
g_hbRecvList->cnt, dumpCount, item->device->devId, deviceType, item->device->addr[0].type,
item->weight, item->masterWeight, item->lastRecvTime);
g_hbRecvList->cnt, dumpCount, AnonymizesUDID(item->device->devId), deviceType,
item->device->addr[0].type, item->weight, item->masterWeight, item->lastRecvTime);
}
(void)SoftBusMutexUnlock(&g_hbRecvList->lock);
}
@ -436,10 +419,11 @@ void LnnDumpHbOnlineNodeList(void)
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "HB get timeStamp err, nodeInfo i=%d", i);
continue;
}
char *deviceTypeStr = LnnConvertIdToDeviceType(nodeInfo->deviceInfo.deviceTypeId);
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_DBG, "DumpOnlineNodeList count:%d [i:%d, deviceName:%s, "
"deviceTypeId:%d, masterWeight:%d, discoveryType:%d, oldTimeStamp:%" PRIu64 "]", infoNum, i + 1,
nodeInfo->deviceInfo.deviceName, nodeInfo->deviceInfo.deviceTypeId, nodeInfo->masterWeight,
nodeInfo->discoveryType, oldTimeStamp);
"deviceTypeId:%d, deviceTypeStr:%s, masterWeight:%d, discoveryType:%d, oldTimeStamp:%" PRIu64 "]",
infoNum, i + 1, nodeInfo->deviceInfo.deviceName, nodeInfo->deviceInfo.deviceTypeId,
deviceTypeStr != NULL ? deviceTypeStr : "", nodeInfo->masterWeight, nodeInfo->discoveryType, oldTimeStamp);
}
SoftBusFree(info);
}
@ -608,6 +592,22 @@ int32_t LnnHbMediumMgrSetParam(const LnnHeartbeatMediumParam *param)
return SOFTBUS_OK;
}
int32_t LnnHbMediumMgrUpdateSendInfo(LnnHeartbeatUpdateInfoType type)
{
int32_t i;
for (i = 0; i < HB_MAX_TYPE_COUNT; ++i) {
if (g_hbMeidumMgr[i] == NULL || g_hbMeidumMgr[i]->onUpdateSendInfo == NULL) {
continue;
}
if (g_hbMeidumMgr[i]->onUpdateSendInfo(type) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "HB manager update send info fail, i=%d", i);
return SOFTBUS_ERR;
}
}
return SOFTBUS_OK;
}
static bool VisitRegistHeartbeatMediumMgr(LnnHeartbeatType *typeSet, LnnHeartbeatType eachType, void *data)
{
(void)typeSet;

View File

@ -108,6 +108,10 @@ static int32_t GetGearModeFromSettingList(GearMode *mode, const ListNode *gearMo
nowTime = times.sec * HB_TIME_FACTOR + times.usec / HB_TIME_FACTOR;
DumpGearModeSettingList(nowTime, gearModeList);
LIST_FOR_EACH_ENTRY_SAFE(info, nextInfo, gearModeList, GearModeStorageInfo, node) {
if (*gearModeCnt == 0) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_DBG, "HB get Gearmode from setting list is empty");
return SOFTBUS_NETWORK_HEARTBEAT_EMPTY_LIST;
}
if (info->lifetimeStamp < nowTime && info->lifetimeStamp != HB_GEARMODE_LIFETIME_PERMANENT) {
ListDelete(&info->node);
SoftBusFree((void *)info->callerId);
@ -170,13 +174,12 @@ int32_t LnnGetGearModeBySpecificType(GearMode *mode, LnnHeartbeatType type)
(void)SoftBusMutexUnlock(&g_hbStrategyMutex);
return SOFTBUS_NETWORK_HEARTBEAT_EMPTY_LIST;
}
if (GetGearModeFromSettingList(mode, &paramMgr->gearModeList, &paramMgr->gearModeCnt) != SOFTBUS_OK) {
int32_t ret = GetGearModeFromSettingList(mode, &paramMgr->gearModeList, &paramMgr->gearModeCnt);
if (ret != SOFTBUS_OK && ret != SOFTBUS_NETWORK_HEARTBEAT_EMPTY_LIST) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "HB get Gearmode from setting list err");
(void)SoftBusMutexUnlock(&g_hbStrategyMutex);
return SOFTBUS_ERR;
}
(void)SoftBusMutexUnlock(&g_hbStrategyMutex);
return SOFTBUS_OK;
return ret;
}
static int32_t FirstSetGearModeByCallerId(const char *callerId, int64_t nowTime, ListNode *list, const GearMode *mode)
@ -277,7 +280,6 @@ static int32_t ProcessSendOnceStrategy(LnnHeartbeatFsm *hbFsm, const LnnProcessS
const GearMode *mode)
{
bool isRemoved = true;
bool wakeupFlag = false;
LnnHeartbeatType registedHbType = msgPara->hbType;
(void)LnnVisitHbTypeSet(VisitClearUnRegistedHbType, &registedHbType, NULL);
@ -290,16 +292,18 @@ static int32_t ProcessSendOnceStrategy(LnnHeartbeatFsm *hbFsm, const LnnProcessS
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_WARN, "HB send once is beginning, hbType:%d", msgPara->hbType);
return SOFTBUS_OK;
}
wakeupFlag = mode != NULL ? mode->wakeupFlag : false;
bool wakeupFlag = mode != NULL ? mode->wakeupFlag : false;
if (LnnPostSendBeginMsgToHbFsm(hbFsm, registedHbType, wakeupFlag, msgPara->isRelay) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "HB send once begin fail, hbType:%d", registedHbType);
return SOFTBUS_ERR;
}
if (LnnPostSendEndMsgToHbFsm(hbFsm, registedHbType, HB_SEND_ONCE_LEN) != SOFTBUS_OK) {
bool isRelayV0 = msgPara->isRelay && registedHbType == HEARTBEAT_TYPE_BLE_V0;
if (LnnPostSendEndMsgToHbFsm(hbFsm, registedHbType, isRelayV0 ? HB_SEND_RELAY_LEN :
HB_SEND_ONCE_LEN) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "HB send once end fail, hbType:%d", registedHbType);
return SOFTBUS_ERR;
}
if (msgPara->isRelay && registedHbType == HEARTBEAT_TYPE_BLE_V0) {
if (isRelayV0) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_DBG, "HB send once but dont check status, hbType:%d", registedHbType);
return SOFTBUS_OK;
}
@ -718,6 +722,11 @@ int32_t LnnSetHbAsMasterNodeState(bool isMasterNode)
return LnnPostTransStateMsgToHbFsm(g_hbFsm, isMasterNode ? EVENT_HB_AS_MASTER_NODE : EVENT_HB_AS_NORMAL_NODE);
}
int32_t LnnUpdateSendInfoStrategy(LnnHeartbeatUpdateInfoType type)
{
return LnnPostUpdateSendInfoMsgToHbFsm(g_hbFsm, type);
}
int32_t LnnHbStrategyInit(void)
{
if (SoftBusMutexInit(&g_hbStrategyMutex, NULL) != 0) {

View File

@ -70,6 +70,7 @@ if (dsoftbus_feature_lnn_net) {
}
if (dsoftbus_feature_lnn_heartbeat) {
bus_center_hub_inc += [
"$dsoftbus_root_path/adapter/common/net/bluetooth/include",
"$dsoftbus_core_path/core/adapter/bus_center/include",
"$dsoftbus_core_path/core/authentication/include",
"$dsoftbus_core_path/connection/p2p/interface",
@ -101,7 +102,7 @@ if (dsoftbus_feature_lnn_net && dsoftbus_feature_lnn_time_sync && enhanced) {
bus_center_hub_deps += [ "$dsoftbus_root_path/dsoftbus_enhance/core/bus_center/lnn/lane_hub/time_sync:dsoftbus_time_sync_impl" ]
}
if (dsoftbus_feature_lnn_net && dsoftbus_feature_lnn_heartbeat && enhanced) {
bus_center_hub_deps += [ "$dsoftbus_root_path/dsoftbus_enhance/core/bus_center/lnn/lane_hub/heartbeat:dsoftbus_heartbeat_impl" ]
bus_center_hub_deps += [ "$dsoftbus_root_path/dsoftbus_enhance/core/bus_center/lnn/lane_hub/heartbeat:dsoftbus_ble_heartbeat" ]
}
if (dsoftbus_feature_lnn_net && dsoftbus_feature_qos && enhanced) {
bus_center_hub_deps += [ "$dsoftbus_root_path/dsoftbus_enhance/core/bus_center/lnn/lane_hub/lane_statistics:dsoftbus_lane_statistics" ]

View File

@ -66,9 +66,10 @@ static int32_t LaneLinkOfBr(uint32_t reqId, const LinkRequest *reqInfo, const La
return SOFTBUS_ERR;
}
LaneLinkInfo linkInfo;
(void)memset_s(&linkInfo, sizeof(LaneLinkInfo), 0, sizeof(LaneLinkInfo));
int32_t ret = LnnGetRemoteStrInfo(reqInfo->peerNetworkId, STRING_KEY_BT_MAC,
linkInfo.linkInfo.br.brMac, BT_MAC_LEN);
if (ret != SOFTBUS_OK) {
if (ret != SOFTBUS_OK || strlen(linkInfo.linkInfo.br.brMac) == 0) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "LnnGetRemoteStrInfo brmac is failed");
return SOFTBUS_ERR;
}

View File

@ -21,6 +21,7 @@
#include "bus_center_event.h"
#include "bus_center_manager.h"
#include "lnn_connection_addr_utils.h"
#include "lnn_decision_db.h"
#include "lnn_distributed_net_ledger.h"
#include "lnn_heartbeat_ctrl.h"
#include "lnn_net_builder.h"
@ -166,6 +167,7 @@ static void ReportResult(const char *udid, ReportCategory report)
break;
case REPORT_ONLINE:
LnnNotifyOnlineState(true, &basic);
LnnInsertSpecificTrustedDevInfo(udid);
break;
case REPORT_NONE:
/* fall-through */

View File

@ -1578,6 +1578,10 @@ int32_t LnnInitNetBuilderDelay(void)
}
LnnSetLocalStrInfo(STRING_KEY_MASTER_NODE_UDID, udid);
LnnSetLocalNumInfo(NUM_KEY_MASTER_NODE_WEIGHT, LnnGetLocalWeight());
if (LnnInitFastOffline() != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "fast offline init fail!");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
@ -1597,6 +1601,7 @@ void LnnDeinitNetBuilder(void)
LnnDeinitTopoManager();
LnnDeinitP2p();
LnnDeinitSyncInfoManager();
LnnDeinitFastOffline();
g_netBuilder.isInit = false;
}

View File

@ -108,7 +108,10 @@ void OnReceiveDeviceName(LnnSyncInfoType type, const char *networkId, const uint
{
char udid[UDID_BUF_LEN];
BssTransInfo *bssTranInfo = NULL;
if (msg == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "%s: msg is null", __func__);
return;
}
if (type != LNN_INFO_TYPE_DEVICE_NAME) {
return;
}

View File

@ -45,7 +45,6 @@
#define LNN_RELATION_JOIN_THREAD 1
#define RELATION_CHANGED_MSG_DELAY (5 * 1000)
#define STR_OFFSET 20
#define TOPO_HASH_TABLE_SIZE 16
@ -201,8 +200,8 @@ static void ClearTopoTable(void)
for (i = 0; i < TOPO_HASH_TABLE_SIZE; ++i) {
LIST_FOR_EACH_ENTRY_SAFE(item, itemNext, &g_topoTable.table[i], TopoTableItem, node) {
LIST_FOR_EACH_ENTRY_SAFE(info, infoNext, &item->joinList, TopoInfo, node) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "delete topo info: ***%s/***%s",
item->udid + STR_OFFSET, info->peerUdid + STR_OFFSET);
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "delete topo info, local:%s, peer:%s",
AnonymizesUDID(item->udid), AnonymizesUDID(info->peerUdid));
ListDelete(&info->node);
SoftBusFree(info);
}
@ -395,8 +394,8 @@ static int32_t UpdateLocalTopo(const char *udid, const char *peerUdid, const uin
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "add topo info fail");
return SOFTBUS_MEM_ERR;
}
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "add topo info: ***%s/***%s", udid + STR_OFFSET,
peerUdid + STR_OFFSET);
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "add topo info: local:%s peer:%s",
AnonymizesUDID(udid), AnonymizesUDID(peerUdid));
} else {
if (IsSameRelation(topoInfo->relation, relation, len)) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "relation are same");
@ -407,8 +406,8 @@ static int32_t UpdateLocalTopo(const char *udid, const char *peerUdid, const uin
return SOFTBUS_MEM_ERR;
}
if (!hasRelation) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "delete topo info: ***%s/***%s",
topoItem->udid + STR_OFFSET, topoInfo->peerUdid + STR_OFFSET);
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "delete topo info: local:%s peer:%s",
AnonymizesUDID(topoItem->udid), AnonymizesUDID(topoInfo->peerUdid));
ListDelete(&topoInfo->node);
SoftBusFree(topoInfo);
topoItem->count--;

View File

@ -336,25 +336,28 @@ static void OnAccountChanged(void)
return;
}
if (memcmp(accountHash, localAccountHash, SHA_256_HASH_LEN) == EOK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "OnAccountChanged account not change");
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_DBG, "OnAccountChanged account not change");
return;
}
LnnSetLocalByteInfo(BYTE_KEY_USERID_HASH, accountHash, SHA_256_HASH_LEN);
DiscDeviceInfoChanged(TYPE_ACCOUNT);
LnnUpdateHeartbeatInfo(UPDATE_HB_ACCOUNT_INFO);
}
static void OnGroupCreated(const char *groupId)
{
(void)groupId;
RestartCoapDiscovery();
OnAccountChanged();
LnnHbOnAuthGroupCreated(groupId);
LnnHbOnAuthGroupCreated();
}
static void OnGroupDeleted(const char *groupId)
{
(void)groupId;
OnAccountChanged();
LnnHbOnAuthGroupDeleted(groupId);
LnnHbOnAuthGroupDeleted();
}
static GroupChangeListener g_groupChangeListener = {

View File

@ -0,0 +1,43 @@
/*
* 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_HUKS_UTILS_H
#define LNN_HUKS_UTILS_H
#include "hks_api.h"
#include "hks_param.h"
#include "hks_type.h"
#include "softbus_common.h"
#ifdef __cplusplus
extern "C" {
#endif
#define LNN_HUKS_AES_COMMON_SIZE 1024
int32_t LnnGenerateKeyByHuks(struct HksBlob *keyAlias);
int32_t LnnDeleteKeyByHuks(struct HksBlob *keyAlias);
int32_t LnnEncryptDataByHuks(const struct HksBlob *keyAlias, const struct HksBlob *inData, struct HksBlob *outData);
int32_t LnnDecryptDataByHuks(const struct HksBlob *keyAlias, const struct HksBlob *inData, struct HksBlob *outData);
int32_t LnnGenerateRandomByHuks(uint8_t *randomKey, uint32_t len);
int32_t LnnInitHuksInterface(void);
void LnnDeinitHuksInterface(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,349 @@
/*
* 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_huks_utils.h"
#include <securec.h>
#include "softbus_adapter_mem.h"
#include "softbus_errcode.h"
#include "softbus_log.h"
#define LNN_HUKS_MAX_UPDATE_TIMES 4
#define LNN_HUKS_MAX_UPDATE_SIZE 64
#define LNN_HUKS_MAX_OUTDATA_SIZE (LNN_HUKS_MAX_UPDATE_SIZE * LNN_HUKS_MAX_UPDATE_TIMES)
#define LNN_HUKS_IV_SIZE 16
static uint8_t g_huksIv[LNN_HUKS_IV_SIZE] = {0};
static struct HksParam g_genParams[] = {
{
.tag = HKS_TAG_ALGORITHM,
.uint32Param = HKS_ALG_AES
}, {
.tag = HKS_TAG_PURPOSE,
.uint32Param = HKS_KEY_PURPOSE_ENCRYPT | HKS_KEY_PURPOSE_DECRYPT
}, {
.tag = HKS_TAG_KEY_SIZE,
.uint32Param = HKS_AES_KEY_SIZE_128
}, {
.tag = HKS_TAG_PADDING,
.uint32Param = HKS_PADDING_NONE
}, {
.tag = HKS_TAG_BLOCK_MODE,
.uint32Param = HKS_MODE_CBC
}
};
static struct HksParam g_encryptParams[] = {
{
.tag = HKS_TAG_ALGORITHM,
.uint32Param = HKS_ALG_AES
}, {
.tag = HKS_TAG_PURPOSE,
.uint32Param = HKS_KEY_PURPOSE_ENCRYPT
}, {
.tag = HKS_TAG_KEY_SIZE,
.uint32Param = HKS_AES_KEY_SIZE_128
}, {
.tag = HKS_TAG_PADDING,
.uint32Param = HKS_PADDING_NONE
}, {
.tag = HKS_TAG_BLOCK_MODE,
.uint32Param = HKS_MODE_CBC
}, {
.tag = HKS_TAG_DIGEST,
.uint32Param = HKS_DIGEST_NONE
}, {
.tag = HKS_TAG_IV,
.blob = {
.size = LNN_HUKS_IV_SIZE,
.data = (uint8_t *)g_huksIv
}
}
};
static struct HksParam g_decryptParams[] = {
{
.tag = HKS_TAG_ALGORITHM,
.uint32Param = HKS_ALG_AES
}, {
.tag = HKS_TAG_PURPOSE,
.uint32Param = HKS_KEY_PURPOSE_DECRYPT
}, {
.tag = HKS_TAG_KEY_SIZE,
.uint32Param = HKS_AES_KEY_SIZE_128
}, {
.tag = HKS_TAG_PADDING,
.uint32Param = HKS_PADDING_NONE
}, {
.tag = HKS_TAG_BLOCK_MODE,
.uint32Param = HKS_MODE_CBC
}, {
.tag = HKS_TAG_DIGEST,
.uint32Param = HKS_DIGEST_NONE
}, {
.tag = HKS_TAG_IV,
.blob = {
.size = LNN_HUKS_IV_SIZE,
.data = (uint8_t *)g_huksIv
}
}
};
static struct HksParamSet *g_genParamSet = NULL;
static struct HksParamSet *g_encryptParamSet = NULL;
static struct HksParamSet *g_decryptParamSet = NULL;
static int32_t LoopFinishByHuks(const struct HksBlob *handle, const struct HksParamSet *paramSet,
const struct HksBlob *inDataSeg, uint8_t *cur, uint32_t *outDataSize)
{
struct HksBlob outDataFinish = {inDataSeg->size * LNN_HUKS_MAX_UPDATE_TIMES, NULL};
outDataFinish.data = (uint8_t *)SoftBusCalloc(outDataFinish.size);
if (outDataFinish.data == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "calloc outDataFinish.data fail");
return SOFTBUS_MEM_ERR;
}
int32_t ret = HksFinish(handle, paramSet, inDataSeg, &outDataFinish);
if (ret != HKS_SUCCESS) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "huks finish fail, huks errcode:%d", ret);
SoftBusFree(outDataFinish.data);
return SOFTBUS_ERR;
}
(void)memcpy_s(cur, outDataFinish.size, outDataFinish.data, outDataFinish.size);
*outDataSize += outDataFinish.size;
SoftBusFree(outDataFinish.data);
return SOFTBUS_OK;
}
static int32_t UpdateLoopFinishByHuks(const struct HksBlob *handle, const struct HksParamSet *paramSet,
const struct HksBlob *inData, struct HksBlob *outData)
{
struct HksBlob inDataSeg = *inData;
uint8_t *lastPtr = inData->data + inData->size - 1;
struct HksBlob outDataSeg = {LNN_HUKS_MAX_OUTDATA_SIZE, NULL};
uint8_t *cur = outData->data;
outData->size = 0;
inDataSeg.size = LNN_HUKS_MAX_UPDATE_SIZE;
bool isFinished = false;
while (inDataSeg.data <= lastPtr) {
if (inDataSeg.data + LNN_HUKS_MAX_UPDATE_SIZE <= lastPtr) {
outDataSeg.size = LNN_HUKS_MAX_OUTDATA_SIZE;
} else {
isFinished = true;
inDataSeg.size = lastPtr - inDataSeg.data + 1;
break;
}
outDataSeg.data = (uint8_t *)SoftBusCalloc(outDataSeg.size);
if (outDataSeg.data == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "calloc outDataSeg.data fail");
return SOFTBUS_MEM_ERR;
}
int32_t ret = HksUpdate(handle, paramSet, &inDataSeg, &outDataSeg);
if (ret != HKS_SUCCESS) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "huks update fail, huks errcode:%d", ret);
SoftBusFree(outDataSeg.data);
return SOFTBUS_ERR;
}
(void)memcpy_s(cur, outDataSeg.size, outDataSeg.data, outDataSeg.size);
cur += outDataSeg.size;
outData->size += outDataSeg.size;
SoftBusFree(outDataSeg.data);
if ((isFinished == false) && (inDataSeg.data + LNN_HUKS_MAX_UPDATE_SIZE > lastPtr)) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "data has exceeded max size before the process finished");
return SOFTBUS_ERR;
}
inDataSeg.data += LNN_HUKS_MAX_UPDATE_SIZE;
}
return LoopFinishByHuks(handle, paramSet, &inDataSeg, cur, &outData->size);
}
static int32_t InitParamSetByHuks(struct HksParamSet **paramSet, const struct HksParam *params, uint32_t paramcount)
{
int32_t ret = HksInitParamSet(paramSet);
if (ret != HKS_SUCCESS) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "huks init param set fail, huks errcode:%d", ret);
return SOFTBUS_ERR;
}
ret = HksAddParams(*paramSet, params, paramcount);
if (ret != HKS_SUCCESS) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "huks add param set fail, huks errcode:%d", ret);
HksFreeParamSet(paramSet);
return SOFTBUS_ERR;
}
ret = HksBuildParamSet(paramSet);
if (ret != HKS_SUCCESS) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "huks build param set fail, huks errcode:%d", ret);
HksFreeParamSet(paramSet);
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
int32_t LnnInitHuksInterface(void)
{
int32_t ret = HksInitialize();
if (ret != HKS_SUCCESS) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "initialize huks fail, huks errcode:%d", ret);
return SOFTBUS_ERR;
}
if (InitParamSetByHuks(&g_genParamSet, g_genParams,
sizeof(g_genParams) / sizeof(struct HksParam)) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "huks init gen param set fail");
return SOFTBUS_ERR;
}
if (InitParamSetByHuks(&g_encryptParamSet, g_encryptParams,
sizeof(g_encryptParams) / sizeof(struct HksParam)) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "huks init encrypt param set fail");
return SOFTBUS_ERR;
}
if (InitParamSetByHuks(&g_decryptParamSet, g_decryptParams,
sizeof(g_decryptParams) / sizeof(struct HksParam)) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "huks init decrypt param set fail");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
void LnnDeinitHuksInterface(void)
{
if (g_genParamSet != NULL) {
HksFreeParamSet(&g_genParamSet);
}
if (g_encryptParamSet != NULL) {
HksFreeParamSet(&g_encryptParamSet);
}
if (g_decryptParamSet != NULL) {
HksFreeParamSet(&g_decryptParamSet);
}
}
int32_t LnnGenerateKeyByHuks(struct HksBlob *keyAlias)
{
if (keyAlias == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
if (HksKeyExist(keyAlias, NULL) == HKS_SUCCESS) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_DBG, "huks key has generated");
return SOFTBUS_OK;
}
int32_t ret = HksGenerateKey(keyAlias, g_genParamSet, NULL);
if (ret != HKS_SUCCESS) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "huks generate key fail, huks errcode:%d", ret);
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
int32_t LnnDeleteKeyByHuks(struct HksBlob *keyAlias)
{
if (keyAlias == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
if (HksKeyExist(keyAlias, NULL) != HKS_SUCCESS) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_DBG, "huks key has deleted");
return SOFTBUS_OK;
}
int32_t ret = HksDeleteKey(keyAlias, g_genParamSet);
if (ret != HKS_SUCCESS) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "huks delete key fail, huks errcode:%d", ret);
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
int32_t LnnEncryptDataByHuks(const struct HksBlob *keyAlias, const struct HksBlob *inData, struct HksBlob *outData)
{
if (keyAlias == NULL || inData == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
uint8_t handleE[sizeof(uint64_t)] = {0};
struct HksBlob handleEncrypt = {sizeof(uint64_t), handleE};
int32_t ret = HksInit(keyAlias, g_encryptParamSet, &handleEncrypt, NULL);
if (ret != HKS_SUCCESS) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "huks encrypt data init fail, huks errcode:%d", ret);
return SOFTBUS_ERR;
}
uint8_t cipher[LNN_HUKS_AES_COMMON_SIZE] = {0};
struct HksBlob cipherText = {LNN_HUKS_AES_COMMON_SIZE, cipher};
if (UpdateLoopFinishByHuks(&handleEncrypt, g_encryptParamSet, inData, &cipherText) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "huks encrypt data update and finish fail");
return SOFTBUS_ERR;
}
outData->size = cipherText.size;
if (memcpy_s(outData->data, cipherText.size, cipherText.data, cipherText.size) != EOK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "huks memcpy_s encrypt data fail");
return SOFTBUS_MEM_ERR;
}
(void)memset_s(cipher, sizeof(cipher), 0x0, sizeof(cipher));
return SOFTBUS_OK;
}
int32_t LnnDecryptDataByHuks(const struct HksBlob *keyAlias, const struct HksBlob *inData, struct HksBlob *outData)
{
if (keyAlias == NULL || inData == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "invalid param");
return SOFTBUS_INVALID_PARAM;
}
uint8_t handleD[sizeof(uint64_t)] = {0};
struct HksBlob handleDecrypt = {sizeof(uint64_t), handleD};
int32_t ret = HksInit(keyAlias, g_decryptParamSet, &handleDecrypt, NULL);
if (ret != HKS_SUCCESS) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "huks decrypt data init fail, huks errcode:%d", ret);
return SOFTBUS_ERR;
}
uint8_t plain[LNN_HUKS_AES_COMMON_SIZE] = {0};
struct HksBlob plainText = {LNN_HUKS_AES_COMMON_SIZE, plain};
if (UpdateLoopFinishByHuks(&handleDecrypt, g_decryptParamSet, inData, &plainText) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "huks decrypt data update and finish fail");
return SOFTBUS_ERR;
}
outData->size = plainText.size;
if (memcpy_s(outData->data, plainText.size, plainText.data, plainText.size) != EOK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "huks memcpy_s decrypt data fail");
return SOFTBUS_MEM_ERR;
}
(void)memset_s(plain, sizeof(plain), 0x0, sizeof(plain));
return SOFTBUS_OK;
}
int32_t LnnGenerateRandomByHuks(uint8_t *random, uint32_t len)
{
struct HksBlob tmp = {0};
tmp.size = len;
tmp.data = (uint8_t *)SoftBusCalloc(tmp.size);
if (tmp.data == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "malloc random key fail");
return SOFTBUS_MALLOC_ERR;
}
int32_t ret = HksGenerateRandom(NULL, &tmp);
if (ret != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "generate random key fail, huks errcode:%d", ret);
SoftBusFree(tmp.data);
return SOFTBUS_ERR;
}
if (memcpy_s(random, len, tmp.data, len) != EOK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "memcpy_s random key fail");
SoftBusFree(tmp.data);
return SOFTBUS_MEM_ERR;
}
SoftBusFree(tmp.data);
return SOFTBUS_OK;
}

View File

@ -19,7 +19,9 @@
#include <securec.h>
#include "bus_center_manager.h"
#include "lnn_decision_db.h"
#include "lnn_distributed_net_ledger.h"
#include "lnn_huks_utils.h"
#include "lnn_local_net_ledger.h"
#include "lnn_meta_node_ledger.h"
#include "softbus_errcode.h"
@ -41,12 +43,24 @@ int32_t LnnInitNetLedger(void)
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "init meta node ledger fail!");
return SOFTBUS_ERR;
}
if (LnnInitHuksInterface() != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "init huks interface fail!");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
int32_t LnnInitNetLedgerDelay(void)
{
return LnnInitLocalLedgerDelay();
if (LnnInitLocalLedgerDelay() != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "delay init local ledger fail!");
return SOFTBUS_ERR;
}
if (LnnInitDecisionDbDelay() != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "delay init decision db fail!");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
void LnnDeinitNetLedger(void)
@ -54,6 +68,7 @@ void LnnDeinitNetLedger(void)
LnnDeinitMetaNodeLedger();
LnnDeinitDistributedLedger();
LnnDeinitLocalLedger();
LnnDeinitHuksInterface();
}
static int32_t LnnGetNodeKeyInfoLocal(const char *networkId, int key, uint8_t *info, uint32_t infoLen)

View File

@ -0,0 +1,34 @@
/*
* 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_DECISION_DB_H
#define LNN_DECISION_DB_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
int32_t LnnInsertSpecificTrustedDevInfo(const char *udid);
int32_t LnnDeleteSpecificTrustedDevInfo(const char *udid);
int32_t LnnGetTrustedDevInfoFromDb(char **udidArray, uint32_t *num);
int32_t LnnInitDecisionDbDelay(void);
#ifdef __cplusplus
}
#endif
#endif // LNN_DECISION_DB_H

View File

@ -0,0 +1,409 @@
/*
* 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_decision_db.h"
#include <securec.h>
#include "bus_center_manager.h"
#include "lnn_async_callback_utils.h"
#include "lnn_file_utils.h"
#include "lnn_heartbeat_ctrl.h"
#include "lnn_huks_utils.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_errcode.h"
#include "softbus_log.h"
#include "softbus_utils.h"
#define LNN_DB_KEY_LEN 1024
#define LNN_DB_KEY_AILAS "dsoftbus_decision_db_key_alias"
static struct HksBlob g_keyAlias = {sizeof(LNN_DB_KEY_AILAS), (uint8_t *)LNN_DB_KEY_AILAS};
static int32_t EncryptDecisionDbKey(uint8_t *dbKey, uint32_t len)
{
struct HksBlob plainData = {0};
struct HksBlob encryptData = {0};
encryptData.data = (uint8_t *)SoftBusCalloc(len);
if (encryptData.data == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "calloc encrypt dbKey fail");
return SOFTBUS_MEM_ERR;
}
plainData.size = len;
plainData.data = dbKey;
if (LnnEncryptDataByHuks(&g_keyAlias, &plainData, &encryptData) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "encrypt dbKey by huks fail");
SoftBusFree(encryptData.data);
return SOFTBUS_ERR;
}
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_WARN, "encrypt dbKey log for audit");
(void)memset_s(plainData.data, len, 0x0, len);
if (memcpy_s(dbKey, len, encryptData.data, len) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "memcpy_s dbKey fail");
SoftBusFree(encryptData.data);
return SOFTBUS_MEM_ERR;
}
SoftBusFree(encryptData.data);
return SOFTBUS_OK;
}
static int32_t DecryptDecisionDbKey(uint8_t *dbKey, uint32_t len)
{
struct HksBlob encryptData = {0};
struct HksBlob decryptData = {0};
decryptData.data = (uint8_t *)SoftBusCalloc(LNN_HUKS_AES_COMMON_SIZE);
if (decryptData.data == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "calloc decrypt dbKey fail");
return SOFTBUS_MEM_ERR;
}
encryptData.size = len;
encryptData.data = dbKey;
if (LnnDecryptDataByHuks(&g_keyAlias, &encryptData, &decryptData) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "decrypt dbKey by huks fail");
return SOFTBUS_ERR;
}
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_WARN, "decrypt dbKey log for audit");
return SOFTBUS_OK;
}
static int32_t GetDecisionDbKey(uint8_t *dbKey, uint32_t len)
{
char dbKeyFilePath[SOFTBUS_MAX_PATH_LEN];
if (LnnGetFullStoragePath(LNN_FILE_ID_DB_KEY, dbKeyFilePath, SOFTBUS_MAX_PATH_LEN) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get dbKey save path fail");
return SOFTBUS_ERR;
}
do {
if (SoftBusAccessFile(dbKeyFilePath, SOFTBUS_F_OK) == SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_DBG, "dbKey file is exist");
break;
}
if (LnnGenerateRandomByHuks(dbKey, len) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "generate random dbKey fail");
return SOFTBUS_ERR;
}
if (EncryptDecisionDbKey(dbKey, len) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "encrypt dbKey fail");
return SOFTBUS_ERR;
}
if (SoftBusWriteFile(dbKeyFilePath, (char *)dbKey, len) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "write dbKey to file fail");
return SOFTBUS_ERR;
}
} while (false);
if (SoftBusReadFullFile(dbKeyFilePath, (char *)dbKey, len) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "read dbKey from file fail");
return SOFTBUS_ERR;
}
if (DecryptDecisionDbKey(dbKey, len) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "decrypt dbKey fail");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
static int32_t EncryptDecisionDb(DbContext *ctx)
{
uint8_t dbKey[LNN_DB_KEY_LEN] = {0};
if (GetDecisionDbKey(dbKey, sizeof(dbKey)) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get decision dbKey fail");
return SOFTBUS_ERR;
}
if (EncryptedDb(ctx, dbKey, sizeof(dbKey)) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "encrypt decision db fail");
return SOFTBUS_ERR;
}
(void)memset_s(dbKey, sizeof(dbKey), 0x0, sizeof(dbKey));
return SOFTBUS_OK;
}
static int32_t BuildTrustedDevInfoRecord(const char *udid, TrustedDevInfoRecord *record)
{
uint8_t accountHash[SHA_256_HASH_LEN] = {0};
char accountHexHash[SHA_256_HEX_HASH_LEN] = {0};
if (udid == NULL || record == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
if (LnnGetLocalByteInfo(BYTE_KEY_USERID_HASH, accountHash, SHA_256_HASH_LEN) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get local account hash failed.");
return SOFTBUS_ERR;
}
if (memset_s(record, sizeof(TrustedDevInfoRecord), 0, sizeof(TrustedDevInfoRecord)) != EOK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "memset_s record failed.");
return SOFTBUS_MEM_ERR;
}
if (ConvertBytesToHexString(accountHexHash, SHA_256_HEX_HASH_LEN, accountHash, SHA_256_HASH_LEN) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "convert accountHash failed.");
return SOFTBUS_ERR;
}
if (strcpy_s(record->accountHexHash, sizeof(record->accountHexHash), accountHexHash) != EOK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "memcpy_s account hash failed.");
return SOFTBUS_MEM_ERR;
}
if (strcpy_s(record->udid, sizeof(record->udid), udid) != EOK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "memcpy_s udid hash failed.");
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
}
static void CompleteUpdateTrustedDevInfo(void *para)
{
(void)para;
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_DBG, "complete trusted dev info update enter.");
LnnUpdateHeartbeatInfo(UPDATE_HB_NETWORK_INFO);
}
static void InsertTrustedDevInfoRecord(void *param)
{
DbContext *ctx = NULL;
TrustedDevInfoRecord record;
char *udid = (char *)param;
if (udid == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "invalid param.");
return;
}
if (BuildTrustedDevInfoRecord(udid, &record) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "build insert trusted dev info record failed.");
SoftBusFree(udid);
return;
}
if (OpenDatabase(&ctx) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "open database failed.");
SoftBusFree(udid);
return;
}
do {
if (EncryptDecisionDb(ctx) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "encrypt database failed.");
break;
}
if (InsertRecord(ctx, TABLE_TRUSTED_DEV_INFO, (uint8_t *)&record) == SOFTBUS_OK) {
(void)LnnAsyncCallbackHelper(GetLooper(LOOP_TYPE_DEFAULT), CompleteUpdateTrustedDevInfo, NULL);
}
} while (false);
if (CloseDatabase(ctx) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "close database failed.");
SoftBusFree(udid);
return;
}
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "insert udid:%s to trusted dev info table.", AnonymizesUDID(udid));
SoftBusFree(udid);
}
static void RemoveTrustedDevInfoRecord(void *param)
{
DbContext *ctx = NULL;
TrustedDevInfoRecord record;
char *udid = (char *)param;
if (udid == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "invalid param.");
return;
}
if (BuildTrustedDevInfoRecord(udid, &record) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "build remove trusted dev info record failed.");
SoftBusFree(udid);
return;
}
if (OpenDatabase(&ctx) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "open database failed.");
SoftBusFree(udid);
return;
}
do {
if (EncryptDecisionDb(ctx) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "encrypt database failed.");
break;
}
if (RemoveRecordByKey(ctx, TABLE_TRUSTED_DEV_INFO, (uint8_t *)&record) == SOFTBUS_OK) {
(void)LnnAsyncCallbackHelper(GetLooper(LOOP_TYPE_DEFAULT), CompleteUpdateTrustedDevInfo, NULL);
}
} while (false);
if (CloseDatabase(ctx) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "close database failed.");
}
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "remove udid:%s from trusted dev info table.", AnonymizesUDID(udid));
SoftBusFree(udid);
}
int32_t LnnInsertSpecificTrustedDevInfo(const char *udid)
{
char *dupUdid = NULL;
if (udid == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
dupUdid = (char *)SoftBusMalloc(UDID_BUF_LEN);
if (dupUdid == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "malloc dupUdid failed.");
return SOFTBUS_MALLOC_ERR;
}
if (strcpy_s(dupUdid, UDID_BUF_LEN, udid) != EOK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "strcpy_s dupUdid failed.");
SoftBusFree(dupUdid);
return SOFTBUS_ERR;
}
if (LnnAsyncCallbackHelper(GetLooper(LOOP_TYPE_DEFAULT), InsertTrustedDevInfoRecord,
(void *)dupUdid) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "async call insert trusted dev info failed.");
SoftBusFree(dupUdid);
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
int32_t LnnDeleteSpecificTrustedDevInfo(const char *udid)
{
char *dupUdid = NULL;
if (udid == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "invalid param.");
return SOFTBUS_INVALID_PARAM;
}
dupUdid = (char *)SoftBusMalloc(UDID_BUF_LEN);
if (dupUdid == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "malloc dupUdid failed.");
return SOFTBUS_MALLOC_ERR;
}
if (strcpy_s(dupUdid, UDID_BUF_LEN, udid) != EOK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "strcpy_s dupUdid failed.");
SoftBusFree(dupUdid);
return SOFTBUS_ERR;
}
if (LnnAsyncCallbackHelper(GetLooper(LOOP_TYPE_DEFAULT), RemoveTrustedDevInfoRecord,
(void *)dupUdid) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "async call remove trusted dev info failed.");
SoftBusFree(dupUdid);
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
static int32_t GetTrustedDevInfoRecord(DbContext *ctx, const char *accountHexHash,
char **udidArray, uint32_t *num)
{
if (EncryptDecisionDb(ctx) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "encrypt database failed.");
*udidArray = NULL;
*num = 0;
return SOFTBUS_ERR;
}
*num = GetRecordNumByKey(ctx, TABLE_TRUSTED_DEV_INFO, (uint8_t *)accountHexHash);
if (*num == 0) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_WARN, "get none trusted dev info");
*udidArray = NULL;
return SOFTBUS_OK;
}
*udidArray = (char *)SoftBusCalloc(*num * UDID_BUF_LEN);
if (*udidArray == NULL) {
*num = 0;
return SOFTBUS_MALLOC_ERR;
}
if (QueryRecordByKey(ctx, TABLE_TRUSTED_DEV_INFO, (uint8_t *)accountHexHash,
(uint8_t **)udidArray, *num) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "query udidArray failed.");
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
int32_t LnnGetTrustedDevInfoFromDb(char **udidArray, uint32_t *num)
{
uint8_t accountHash[SHA_256_HASH_LEN] = {0};
char accountHexHash[SHA_256_HEX_HASH_LEN] = {0};
DbContext *ctx = NULL;
if (udidArray == NULL || num == NULL) {
return SOFTBUS_INVALID_PARAM;
}
if (LnnGetLocalByteInfo(BYTE_KEY_USERID_HASH, accountHash, SHA_256_HASH_LEN) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get local account hash failed.");
return SOFTBUS_ERR;
}
if (ConvertBytesToHexString(accountHexHash, SHA_256_HEX_HASH_LEN, accountHash, SHA_256_HASH_LEN) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "convert accountHash failed.");
return SOFTBUS_ERR;
}
if (OpenDatabase(&ctx) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "open database failed.");
return SOFTBUS_ERR;
}
int32_t rc = GetTrustedDevInfoRecord(ctx, accountHexHash, udidArray, num);
if (rc != SOFTBUS_OK && *udidArray != NULL) {
SoftBusFree(*udidArray);
*udidArray = NULL;
}
if (CloseDatabase(ctx) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "close database failed.");
return SOFTBUS_ERR;
}
return rc;
}
static int32_t InitTrustedDevInfoTableDelay(void)
{
bool isExist = false;
int32_t rc = SOFTBUS_ERR;
DbContext *ctx = NULL;
if (OpenDatabase(&ctx) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "open database failed.");
return SOFTBUS_ERR;
}
do {
if (EncryptDecisionDb(ctx) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "encrypt database failed.");
break;
}
if (CheckTableExist(ctx, TABLE_TRUSTED_DEV_INFO, &isExist) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "check table exist failed.");
break;
}
if (!isExist && CreateTable(ctx, TABLE_TRUSTED_DEV_INFO) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "create trusted dev info table failed.");
break;
}
rc = SOFTBUS_OK;
} while (false);
if (CloseDatabase(ctx) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "close database failed.");
return SOFTBUS_ERR;
}
return rc;
}
int32_t LnnInitDecisionDbDelay(void)
{
if (LnnGenerateKeyByHuks(&g_keyAlias) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "generate decision db huks key fail");
return SOFTBUS_ERR;
}
return InitTrustedDevInfoTableDelay();
}

View File

@ -0,0 +1,50 @@
/*
* 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_decision_db.h"
#include "softbus_errcode.h"
#include "softbus_log.h"
int32_t LnnInsertSpecificTrustedDevInfo(const char *udid)
{
(void)udid;
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "insert trusted dev info not implemented.");
return SOFTBUS_NOT_IMPLEMENT;
}
int32_t LnnDeleteSpecificTrustedDevInfo(const char *udid)
{
(void)udid;
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "remove trusted dev info not implemented.");
return SOFTBUS_NOT_IMPLEMENT;
}
int32_t LnnGetTrustedDevInfoFromDb(char **udidArray, uint32_t *num)
{
(void)udidArray;
(void)num;
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get trusted dev info not implemented.");
return SOFTBUS_NOT_IMPLEMENT;
}
int32_t LnnInitDecisionDbDelay(void)
{
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "init decision db not implemented.");
return SOFTBUS_OK;
}

View File

@ -764,7 +764,11 @@ static void MergeLnnInfo(const NodeInfo *oldInfo, NodeInfo *info)
for (i = 0; i < CONNECTION_ADDR_MAX; ++i) {
info->relation[i] += oldInfo->relation[i];
info->relation[i] &= LNN_RELATION_MASK;
info->authChannelId[i] = oldInfo->authChannelId[i];
if (oldInfo->authChannelId[i] != 0) {
info->authChannelId[i] = oldInfo->authChannelId[i];
}
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO,
"Update authChannelId: %d, addrType=%d.", info->authChannelId[i], i);
}
}
@ -868,6 +872,7 @@ ReportCategory LnnSetNodeOffline(const char *udid, ConnectionAddrType type, int3
SoftBusMutexUnlock(&g_distributedNetLedger.lock);
return REPORT_NONE;
}
info->authChannelId[type] = 0;
LnnClearDiscoveryType(info, LnnConvAddrTypeToDiscType(type));
if (info->discoveryType != 0) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "discoveryType=%u after clear, not need to report offline.",
@ -1461,7 +1466,8 @@ const NodeInfo *LnnGetOnlineNodeByUdidHash(const char *recvUdidHash)
continue;
}
if (memcmp(shortUdidHash, recvUdidHash, SHORT_UDID_HASH_LEN) == 0) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "node shortUdidHash:%s is online", shortUdidHash);
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "node shortUdidHash:%s is online",
AnonymizesUDID((const char *)shortUdidHash));
SoftBusFree(info);
return nodeInfo;
}
@ -1478,7 +1484,8 @@ static void RefreshDeviceInfoByDevId(DeviceInfo *device, const InnerDeviceInfoAd
}
const NodeInfo *nodeInfo = LnnGetOnlineNodeByUdidHash(device->devId);
if (nodeInfo == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "device udidhash:%s is not online", device->devId);
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "device udidhash:%s is not online",
AnonymizesUDID(device->devId));
return;
}
if (memcpy_s(device->devId, DISC_MAX_DEVICE_ID_LEN, nodeInfo->deviceInfo.deviceUdid, UDID_BUF_LEN) != EOK) {

View File

@ -15,6 +15,7 @@ import("//foundation/communication/dsoftbus/dsoftbus.gni")
bus_center_ledger_src = [
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/common/src/lnn_device_info.c",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/common/src/lnn_huks_utils.c",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/common/src/lnn_net_capability.c",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/common/src/lnn_net_ledger.c",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/common/src/lnn_node_info.c",
@ -31,9 +32,35 @@ if (dsoftbus_feature_lnn_meta_node) {
bus_center_ledger_src += [ "$dsoftbus_root_path/core/bus_center/lnn/net_ledger/distributed_ledger/src/lnn_meta_node_ledger_virtual.c" ]
}
bus_center_ledger_inc = [
"$dsoftbus_root_path/adapter/common/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/common/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/distributed_ledger/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/decision_db/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/local_ledger/include",
"$dsoftbus_root_path/core/bus_center/utils/include",
"//base/security/huks/interfaces/innerkits/huks_standard/main/include",
]
bus_center_ledger_deps = []
bus_center_ledger_external_deps = []
net_ledger_native_source_path = rebase_path("$dsoftbus_root_path")
net_ledger_dep_dir = "dsoftbus_enhance/core/bus_center/lnn/lane_hub"
net_ledger_enhanced = exec_script("$dsoftbus_root_path/check_sub_module.py",
[
"$net_ledger_native_source_path",
"$net_ledger_dep_dir",
],
"value")
if (defined(ohos_lite)) {
bus_center_ledger_src += [ "$dsoftbus_root_path/core/bus_center/lnn/net_ledger/decision_db/src/lnn_decision_db_virtual.c" ]
bus_center_ledger_deps +=
[ "//base/security/huks/interfaces/innerkits/huks_lite:huks_3.0_sdk" ]
} else {
if (net_ledger_enhanced) {
bus_center_ledger_src += [ "$dsoftbus_root_path/core/bus_center/lnn/net_ledger/decision_db/src/lnn_decision_db.c" ]
} else {
bus_center_ledger_src += [ "$dsoftbus_root_path/core/bus_center/lnn/net_ledger/decision_db/src/lnn_decision_db_virtual.c" ]
}
bus_center_ledger_external_deps += [ "huks:libhukssdk" ]
}

View File

@ -26,7 +26,6 @@
#include "lnn_network_manager.h"
#include "lnn_net_builder.h"
#include "lnn_net_ledger.h"
#include "lnn_fast_offline.h"
#include "softbus_errcode.h"
#include "softbus_feature_config.h"
#include "softbus_log.h"
@ -177,10 +176,6 @@ 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;
}
@ -193,6 +188,5 @@ void BusCenterServerDeinit(void)
LnnDeinitNetworkManager();
LnnDeinitBusCenterEvent();
LnnDeinitNetLedger();
LnnDeinitFastOffline();
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "bus center server deinit");
}

View File

@ -25,6 +25,7 @@ extern "C" {
typedef enum {
LNN_FILE_ID_UUID,
LNN_FILE_ID_DB_KEY,
LNN_FILE_ID_MAX
} LnnFileId;

View File

@ -22,6 +22,9 @@
bool LnnIsSameConnectionAddr(const ConnectionAddr *addr1, const ConnectionAddr *addr2)
{
if (addr1 == NULL || addr2 == NULL) {
return false;
}
if (addr1->type != addr2->type) {
return false;
}

View File

@ -32,7 +32,8 @@ typedef struct {
static char g_storagePath[SOFTBUS_MAX_PATH_LEN] = {0};
static FilePathInfo g_filePath[LNN_FILE_ID_MAX] = {
{ LNN_FILE_ID_UUID, "/dsoftbus/uuid" }
{ LNN_FILE_ID_UUID, "/dsoftbus/uuid" },
{ LNN_FILE_ID_DB_KEY, "/dsoftbus/dbKey" },
};
static int32_t InitStorageConfigPath(void)
@ -52,6 +53,10 @@ static int32_t InitStorageConfigPath(void)
int32_t LnnGetFullStoragePath(LnnFileId id, char *path, uint32_t len)
{
if (path == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "%s: path is null", __func__);
return SOFTBUS_INVALID_PARAM;
}
if (strlen(g_storagePath) == 0) {
if (InitStorageConfigPath() != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "init storage config path fail");

View File

@ -19,6 +19,9 @@
void ConvertVoidToPublishInfo(const void *info, PublishInfo *pubInfo)
{
if (info == NULL || pubInfo == NULL) {
return;
}
char *info1 = (char *)info;
pubInfo->publishId = *(int32_t *)info1;
info1 += sizeof(int32_t);
@ -42,6 +45,9 @@ void ConvertVoidToPublishInfo(const void *info, PublishInfo *pubInfo)
void ConvertVoidToSubscribeInfo(const void *info, SubscribeInfo *subInfo)
{
if (info == NULL || subInfo == NULL) {
return;
}
char *info1 = (char *)info;
subInfo->subscribeId = *(int32_t *)info1;
info1 += sizeof(int32_t);

View File

@ -34,7 +34,7 @@ static int32_t GetUuidFromFile(char *id, uint32_t len)
rc = LnnGetFullStoragePath(LNN_FILE_ID_UUID, uuidFilePath, SOFTBUS_MAX_PATH_LEN);
if (rc != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "get uuid save path fail");
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get uuid save path fail");
return SOFTBUS_ERR;
}
if (SoftBusReadFullFile(uuidFilePath, id, len) != SOFTBUS_OK) {

View File

@ -53,8 +53,10 @@ typedef enum {
CLOSE_TRANS_ROLLBACK
} CloseTransactionType;
/* read supports multithreading, and write only supports single thread {@link LOOP_TYPE_DEFAULT}. */
int32_t OpenDatabase(DbContext **ctx);
int32_t CloseDatabase(DbContext *ctx);
int32_t CreateTable(DbContext *ctx, TableNameID id);
int32_t DeleteTable(DbContext *ctx, TableNameID id);
int32_t CheckTableExist(DbContext *ctx, TableNameID id, bool *isExist);
@ -67,8 +69,8 @@ int32_t QueryRecordByKey(DbContext *ctx, TableNameID id, uint8_t *data, uint8_t
int32_t OpenTransaction(DbContext *ctx);
int32_t CloseTransaction(DbContext *ctx, CloseTransactionType type);
int32_t EncryptedDb(DbContext *ctx, const char *password, uint32_t len);
int32_t UpdateDbPassword(DbContext *ctx, const char *password, uint32_t len);
int32_t EncryptedDb(DbContext *ctx, const uint8_t *password, uint32_t len);
int32_t UpdateDbPassword(DbContext *ctx, const uint8_t *password, uint32_t len);
int32_t BindParaInt(DbContext *ctx, int32_t idx, int32_t value);
int32_t BindParaInt64(DbContext *ctx, int32_t idx, int64_t value);

View File

@ -74,7 +74,7 @@ SoftBusMessage *MallocMessage(void)
{
SoftBusMessage *msg = (SoftBusMessage *)SoftBusMalloc(sizeof(SoftBusMessage));
if (msg == NULL) {
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "malloc SoftBusMessage failed");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "malloc SoftBusMessage failed");
return NULL;
}
(void)memset_s(msg, sizeof(SoftBusMessage), 0, sizeof(SoftBusMessage));

View File

@ -57,19 +57,19 @@ typedef struct {
* @brief The SQL statement of TrustedDeviceInfo table.
*
* This table is used to store the trusted relationship, and its name is TrustedDeviceInfo in {@link DATABASE_NAME}.
* After each networking, record the udidhash value according to the device account.
* After each networking, record the udid value according to the device account.
*/
#define TABLE_NAME_OF_TRUSTED_DEV_INFO "TrustedDeviceInfo"
#define SQL_CREATE_TRUSTED_DEV_INFO_TABLE "CREATE TABLE IF NOT EXISTS "TABLE_NAME_OF_TRUSTED_DEV_INFO" \
(accountHash TEXT NOT NULL, \
udidHash TEXT NOT NULL, \
primary key(accountHash, udidHash));"
udid TEXT NOT NULL, \
primary key(accountHash, udid));"
#define SQL_INSERT_TRUSTED_DEV_INFO "INSERT INTO "TABLE_NAME_OF_TRUSTED_DEV_INFO" \
(accountHash, udidHash) VALUES (?, ?)"
#define SQL_SEARCH_TRUSTED_DEV_INFO_BY_ID "SELECT udidHash FROM "TABLE_NAME_OF_TRUSTED_DEV_INFO" \
(accountHash, udid) VALUES (?, ?)"
#define SQL_SEARCH_TRUSTED_DEV_INFO_BY_ID "SELECT udid FROM "TABLE_NAME_OF_TRUSTED_DEV_INFO" \
WHERE accountHash = ?"
#define SQL_REMOVE_TRUSTED_DEV_INFO_BY_ID "DELETE FROM "TABLE_NAME_OF_TRUSTED_DEV_INFO" \
WHERE accountHash = ? AND udidHash = ?"
WHERE accountHash = ? AND udid = ?"
static int32_t BindInsertTrustedDevInfoCb(DbContext *ctx, int32_t paraNum, uint8_t *data);
static int32_t BindSelectTrustedDevInfoCb(DbContext *ctx, int32_t paraNum, uint8_t *data);
@ -180,7 +180,7 @@ static int32_t QueryData(DbContext *ctx, const char *sql, uint32_t len, BindPara
} else {
ctx->state |= DB_STATE_QUERYING;
}
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "QueryData done, state: %d", ctx->state);
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_DBG, "QueryData done, state: %d", ctx->state);
return rc;
}
@ -194,7 +194,7 @@ static int32_t QueryDataNext(DbContext *ctx)
(void)sqlite3_finalize(ctx->stmt);
ctx->stmt = NULL;
}
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "QueryDataNext done, state: %d", ctx->state);
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_DBG, "QueryDataNext done, state: %d", ctx->state);
return rc;
}
@ -233,7 +233,8 @@ int32_t OpenDatabase(DbContext **ctx)
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "invalid parameters");
return SOFTBUS_INVALID_PARAM;
}
rc = sqlite3_open_v2(DATABASE_NAME, &sqlite, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
rc = sqlite3_open_v2(DATABASE_NAME, &sqlite, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE |
SQLITE_OPEN_NOMUTEX, NULL);
if (rc != SQLITE_OK || sqlite == NULL) {
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "sqlite3_open_v2 fail: %s", sqlite3_errmsg(sqlite));
(void)sqlite3_close_v2(sqlite);
@ -351,7 +352,7 @@ int32_t InsertRecord(DbContext *ctx, TableNameID id, uint8_t *data)
}
(void)sqlite3_finalize(ctx->stmt);
ctx->stmt = NULL;
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "insert data done");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_DBG, "insert data done");
return rc;
}
@ -373,7 +374,7 @@ int32_t RemoveRecordByKey(DbContext *ctx, TableNameID id, uint8_t *data)
}
(void)sqlite3_finalize(ctx->stmt);
ctx->stmt = NULL;
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "remove data done");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_DBG, "remove data done");
return rc;
}
@ -400,7 +401,7 @@ int32_t RemoveAllRecord(DbContext *ctx, TableNameID id)
}
(void)sqlite3_finalize(ctx->stmt);
ctx->stmt = NULL;
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "remove data done");
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_DBG, "remove data done");
return rc;
}
@ -517,11 +518,11 @@ int32_t CloseTransaction(DbContext *ctx, CloseTransactionType type)
return rc;
}
int32_t EncryptedDb(DbContext *ctx, const char *password, uint32_t len)
int32_t EncryptedDb(DbContext *ctx, const uint8_t *password, uint32_t len)
{
int32_t rc;
if (!CheckDbContextParam(ctx) || password == NULL || password[0] == '\0' || strlen(password) != len) {
if (!CheckDbContextParam(ctx) || password == NULL) {
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "invalid parameters");
return SOFTBUS_INVALID_PARAM;
}
@ -533,11 +534,11 @@ int32_t EncryptedDb(DbContext *ctx, const char *password, uint32_t len)
return SOFTBUS_OK;
}
int32_t UpdateDbPassword(DbContext *ctx, const char *password, uint32_t len)
int32_t UpdateDbPassword(DbContext *ctx, const uint8_t *password, uint32_t len)
{
int32_t rc;
if (!CheckDbContextParam(ctx) || password == NULL || password[0] == '\0' || strlen(password) != len) {
if (!CheckDbContextParam(ctx) || password == NULL) {
SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "invalid parameters");
return SOFTBUS_INVALID_PARAM;
}

View File

@ -93,7 +93,7 @@ void P2pLinkSetGoIp(const char *ip)
if (ret != EOK) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "strcpy error");
}
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_DBG, "set go ip %s", g_goIp);
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "set go ip");
}
void P2pLinkSetGoMac(const char *mac)

View File

@ -37,7 +37,7 @@ static void UpdateP2pGoGroup(const P2pLinkGroup *group)
P2pLinkUpdateDeviceByMagicGroups(group);
if (P2pLinkGetGoPort() <= 0) {
ret = P2pLinkGetP2pIpAddress(p2pIp, sizeof(p2pIp));
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_DBG, "get my ip %s, ret %d", p2pIp, ret);
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "get my ip, ret %d", ret);
if (ret != SOFTBUS_ERR) {
P2pLinkSetMyIp(p2pIp);
port = AuthStartListening(AUTH_LINK_TYPE_P2P, p2pIp, 0);
@ -58,7 +58,7 @@ static void UpdateP2pGcGroup(void)
if (P2pLinkGetDhcpState() == true) {
ret = P2pLinkGetP2pIpAddress(p2pIp, sizeof(p2pIp));
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_DBG, "get dhcp ip %s, ret %d", p2pIp, ret);
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "get dhcp ip ret %d", ret);
if (ret != SOFTBUS_ERR) {
P2pLinkSetMyIp(p2pIp);
}

View File

@ -309,8 +309,7 @@ void P2pLinkConningCallback(const ConnectingNode *item, int32_t ret, int32_t fai
}
} else {
if (devInfo->cb.onConnected != 0) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_DBG, "notify OK reqid %d, peerip %s myip %s",
devInfo->requestId, item->peerIp, item->myIp);
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_INFO, "notify OK reqid %d", devInfo->requestId);
devInfo->cb.onConnected(devInfo->requestId, item->myIp, item->peerIp);
}
}

View File

@ -85,7 +85,7 @@ static void P2pLinkNeoDataProcess(P2pLoopMsg msgType, void *param)
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "%s:invalid param.", __func__);
return;
}
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_DBG, "recv msg = %s.", info->data);
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_DBG, "recv msg");
cJSON *json = cJSON_Parse((char *)info->data);
if (json == NULL) {
SoftBusFree(info);

View File

@ -254,7 +254,6 @@ static int32_t PackAndSendMsg(int64_t authId, bool isRequestMsg, const void *msg
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "cjson unformatted failed.");
return SOFTBUS_ERR;
}
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_DBG, "json msg = %s.", msgStr);
if (P2pLinkSendMessage(authId, msgStr, strlen(msgStr) + 1) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_CONN, SOFTBUS_LOG_ERROR, "P2p link negotiation send message failed.");
cJSON_free(msgStr);

View File

@ -19,6 +19,7 @@
#define INT32_MAX_BIT_NUM 32
#define MAX_CAP_NUM (CAPABILITY_NUM * INT32_MAX_BIT_NUM)
#define BLE_SCAN_FILTER_LEN 7
#define CUST_DATA_MAX_LEN 14
#define SOFTBUS_BLE_CLIENT_ID 0x1
@ -36,6 +37,7 @@
#define POS_PACKET_LENGTH 3
#define POS_AD_TYPE 4
#define POS_UUID 5
#define UUID_LEN 2
#define ADV_HEAD_LEN 7
#define RSP_HEAD_LEN 4

View File

@ -146,10 +146,10 @@ typedef struct {
} BleOption;
static ScanSetting g_scanTable[FREQ_BUTT] = {
{60, 3000},
{60, 600},
{60, 240},
{1000, 1000}
{SOFTBUS_BLE_SCAN_WINDOW_P2, SOFTBUS_BLE_SCAN_INTERVAL_P2},
{SOFTBUS_BLE_SCAN_WINDOW_P10, SOFTBUS_BLE_SCAN_INTERVAL_P10},
{SOFTBUS_BLE_SCAN_WINDOW_P25, SOFTBUS_BLE_SCAN_INTERVAL_P25},
{SOFTBUS_BLE_SCAN_WINDOW_P100, SOFTBUS_BLE_SCAN_INTERVAL_P100}
};
static DiscInnerCallback *g_discBleInnerCb = NULL;
@ -332,7 +332,7 @@ static void ProcessDisConPacket(const unsigned char *advData, uint32_t advLen, D
}
(void)SoftBusMutexLock(&g_bleInfoLock);
if ((foundInfo->capabilityBitmap[0] & g_bleInfoManager[BLE_PUBLISH | BLE_PASSIVE].capBitMap[0]) == 0x0) {
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_INFO, "don't match passive publish capBitMap");
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_DBG, "don't match passive publish capBitMap");
(void)SoftBusMutexUnlock(&g_bleInfoLock);
return;
}
@ -1625,6 +1625,52 @@ static int32_t DiscBleLooperInit(void)
return SOFTBUS_OK;
}
static void DiscFreeBleScanFilter(SoftBusBleScanFilter **filter)
{
if (*filter == NULL) {
return;
}
if ((*filter)->serviceData != NULL) {
SoftBusFree((*filter)->serviceData);
(*filter)->serviceData = NULL;
}
if ((*filter)->serviceDataMask != NULL) {
SoftBusFree((*filter)->serviceDataMask);
(*filter)->serviceDataMask = NULL;
}
SoftBusFree(*filter);
}
static void DiscBleSetScanFilter(int32_t listenerId)
{
SoftBusBleScanFilter *filter = NULL;
filter = (SoftBusBleScanFilter *)SoftBusCalloc(sizeof(SoftBusBleScanFilter));
filter->serviceData = (unsigned char *)SoftBusCalloc(BLE_SCAN_FILTER_LEN);
filter->serviceDataMask = (unsigned char *)SoftBusCalloc(BLE_SCAN_FILTER_LEN);
if (filter == NULL || filter->serviceData == NULL || filter->serviceDataMask == NULL) {
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "calloc scan filter fail");
DiscFreeBleScanFilter(&filter);
return;
}
filter->serviceDataLength = BLE_SCAN_FILTER_LEN;
filter->serviceData[0] = BLE_UUID & BYTE_MASK;
filter->serviceData[1] = (BLE_UUID >> BYTE_SHIFT_BIT) & BYTE_MASK;
filter->serviceData[UUID_LEN + POS_VERSION] = BLE_VERSION;
filter->serviceData[UUID_LEN + POS_BUSINESS] = DISTRIBUTE_BUSINESS;
filter->serviceData[UUID_LEN + POS_BUSINESS_EXTENSION] = BIT_CUST_DATA_TYPE;
filter->serviceDataMask[0] = BYTE_MASK;
filter->serviceDataMask[1] = BYTE_MASK;
filter->serviceDataMask[UUID_LEN + POS_VERSION] = BYTE_MASK;
filter->serviceDataMask[UUID_LEN + POS_BUSINESS] = BYTE_MASK;
filter->serviceDataMask[UUID_LEN + POS_BUSINESS_EXTENSION] = BIT_CUST_DATA_TYPE;
if (SoftBusSetScanFilter(listenerId, filter, 1) != SOFTBUS_OK) {
SoftBusLog(SOFTBUS_LOG_DISC, SOFTBUS_LOG_ERROR, "set scan filter fail");
DiscFreeBleScanFilter(&filter);
return;
}
}
static int32_t InitBleListener(void)
{
g_bleListener.stateListenerId = SoftBusAddBtStateListener(&g_stateChangedListener);
@ -1632,6 +1678,7 @@ static int32_t InitBleListener(void)
if (g_bleListener.stateListenerId < 0 || g_bleListener.scanListenerId < 0) {
return SOFTBUS_ERR;
}
DiscBleSetScanFilter(g_bleListener.scanListenerId);
return SOFTBUS_OK;
}

View File

@ -149,10 +149,10 @@ void SoftBusServerStub::InitMemberFuncMap()
void SoftBusServerStub::InitMemberPermissionMap()
{
memberPermissionMap_[SERVER_START_DISCOVERY] = nullptr;
memberPermissionMap_[SERVER_STOP_DISCOVERY] = nullptr;
memberPermissionMap_[SERVER_PUBLISH_SERVICE] = nullptr;
memberPermissionMap_[SERVER_UNPUBLISH_SERVICE] = nullptr;
memberPermissionMap_[SERVER_START_DISCOVERY] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
memberPermissionMap_[SERVER_STOP_DISCOVERY] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
memberPermissionMap_[SERVER_PUBLISH_SERVICE] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
memberPermissionMap_[SERVER_UNPUBLISH_SERVICE] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
memberPermissionMap_[MANAGE_REGISTER_SERVICE] = nullptr;
memberPermissionMap_[SERVER_CREATE_SESSION_SERVER] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
memberPermissionMap_[SERVER_REMOVE_SESSION_SERVER] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;

View File

@ -519,7 +519,7 @@ bool VtpStreamSocket::Connect(const IpAndPort &remote)
}
SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_DBG,
"Connect to server(addr:%s, server port:%d)", remote.ip.c_str(), remote.port);
"Connect to server(server port:%d)", remote.port);
remoteIpPort_ = remote;
struct sockaddr_in remoteSockAddr;
@ -897,7 +897,7 @@ bool VtpStreamSocket::Accept()
}
SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_DBG,
"Accept a client(addr:%s, server port:%d)", remoteIpPort_.ip.c_str(), remoteIpPort_.port);
"Accept a client(server port:%d)", remoteIpPort_.port);
SetDefaultConfig(fd);
if (SetSocketEpollMode(fd) != ERR_OK) {

View File

@ -26,6 +26,7 @@ ohos_unittest("LNNTest") {
"net_builder/lnn_topo_manager_test.cpp",
"unittest/lane_test.cpp",
"unittest/ledger_lane_hub_test.cpp",
"unittest/lnn_huks_test.cpp",
"unittest/net_builder_test.cpp",
]
@ -56,6 +57,7 @@ ohos_unittest("LNNTest") {
"$dsoftbus_root_path/core/discovery/manager/include",
"$dsoftbus_root_path/core/discovery/interface",
"$dsoftbus_root_path/interfaces/kits/discovery",
"//base/security/huks/interfaces/innerkits/huks_standard/main/include",
]
deps = [
@ -75,6 +77,7 @@ ohos_unittest("LNNTest") {
external_deps = [
"c_utils:utils",
"hilog:libhilog",
"huks:libhukssdk",
]
}
}
@ -134,38 +137,6 @@ ohos_unittest("LNNNetBuilderTest") {
}
}
ohos_unittest("SqliteTest") {
module_out_path = module_output_path
sources = [ "unittest/sqlite3_utils_test.cpp" ]
include_dirs = [
"$dsoftbus_root_path/adapter/common/include",
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/interfaces/kits/bus_center",
"$dsoftbus_root_path/interfaces/kits/common",
"//commonlibrary/c_utils/base/include",
]
deps = [
"$dsoftbus_root_path/adapter:softbus_adapter",
"$dsoftbus_root_path/core/common:softbus_utils",
"//third_party/googletest:gtest_main",
"//third_party/sqlite:sqlite",
]
if (is_standard_system) {
external_deps = [
"c_utils:utils",
"hiviewdfx_hilog_native:libhilog",
]
} else {
external_deps = [
"c_utils:utils",
"hilog:libhilog",
]
}
}
native_source_path = rebase_path("$dsoftbus_root_path")
dep_dir = "dsoftbus_enhance/core/bus_center/lnn/lane_hub"
enhanced_test = exec_script("$dsoftbus_root_path/check_sub_module.py",
@ -180,7 +151,6 @@ group("unittest") {
deps = [
":LNNNetBuilderTest",
":LNNTest",
":SqliteTest",
]
if (enhanced_test) {
deps += [

View File

@ -0,0 +1,157 @@
/*
* 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 <cstring>
#include <gtest/gtest.h>
#include <securec.h>
#include "lnn_huks_utils.h"
#include "softbus_adapter_mem.h"
#include "softbus_errcode.h"
namespace OHOS {
using namespace testing::ext;
static constexpr char KEY_ALIAS[] = "dsoftbus_test_key_alias";
static constexpr char RANDOM_KEY[] = "b0d8bfed90d1e018c84f0a1abd4cbcc7f33481b42476719b401b1d70d3998a7c";
static struct HksBlob g_keyAlias = {0};
class LnnHuksUtilsTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void LnnHuksUtilsTest::SetUpTestCase()
{
g_keyAlias.size = strlen(KEY_ALIAS);
g_keyAlias.data = (uint8_t *)KEY_ALIAS;
EXPECT_EQ(LnnInitHuksInterface(), SOFTBUS_OK);
}
void LnnHuksUtilsTest::TearDownTestCase()
{
LnnDeinitHuksInterface();
}
void LnnHuksUtilsTest::SetUp()
{
}
void LnnHuksUtilsTest::TearDown()
{
(void)LnnDeleteKeyByHuks(&g_keyAlias);
}
/*
* @tc.name: Generate_Key_Test_001
* @tc.desc: generate key test
* @tc.type: FUNC
* @tc.require: I5RHYE
*/
HWTEST_F(LnnHuksUtilsTest, Generate_Key_Test_01, TestSize.Level0)
{
struct HksBlob keyAlias = {0};
keyAlias.size = strlen(KEY_ALIAS);
keyAlias.data = (uint8_t *)KEY_ALIAS;
EXPECT_EQ(LnnGenerateKeyByHuks(&keyAlias), SOFTBUS_OK);
}
/*
* @tc.name: Generate_Key_Test_002
* @tc.desc: generate key twice test
* @tc.type: FUNC
* @tc.require: I5RHYE
*/
HWTEST_F(LnnHuksUtilsTest, Generate_Key_Test_02, TestSize.Level0)
{
struct HksBlob keyAlias = {0};
keyAlias.size = strlen(KEY_ALIAS);
keyAlias.data = (uint8_t *)KEY_ALIAS;
EXPECT_EQ(LnnGenerateKeyByHuks(&keyAlias), SOFTBUS_OK);
EXPECT_EQ(LnnGenerateKeyByHuks(&keyAlias), SOFTBUS_OK);
}
/*
* @tc.name: Generate_Random_Test_001
* @tc.desc: generate randowm key test
* @tc.type: FUNC
* @tc.require: I5RHYE
*/
HWTEST_F(LnnHuksUtilsTest, Generate_Random_Test_01, TestSize.Level0)
{
uint8_t randomKey[LNN_HUKS_AES_COMMON_SIZE] = {0};
EXPECT_EQ(LnnGenerateRandomByHuks(randomKey, LNN_HUKS_AES_COMMON_SIZE), SOFTBUS_OK);
}
/*
* @tc.name: Encrypt_Data_Test_001
* @tc.desc: encrypt data test
* @tc.type: FUNC
* @tc.require: I5RHYE
*/
HWTEST_F(LnnHuksUtilsTest, Encrypt_Data_Test_01, TestSize.Level0)
{
struct HksBlob inData = {0};
inData.size = strlen(RANDOM_KEY);
inData.data = (uint8_t *)RANDOM_KEY;
struct HksBlob outData = {0};
outData.data = (uint8_t *)SoftBusCalloc(LNN_HUKS_AES_COMMON_SIZE);
ASSERT_NE(outData.data, nullptr);
EXPECT_EQ(LnnGenerateKeyByHuks(&g_keyAlias), SOFTBUS_OK);
EXPECT_EQ(LnnEncryptDataByHuks(&g_keyAlias, &inData, &outData), SOFTBUS_OK);
EXPECT_NE(memcmp(inData.data, outData.data, inData.size), 0);
SoftBusFree(outData.data);
}
/*
* @tc.name: Decrypt_Data_Test_001
* @tc.desc: decrypt data test
* @tc.type: FUNC
* @tc.require: I5RHYE
*/
HWTEST_F(LnnHuksUtilsTest, Decrypt_Data_Test_01, TestSize.Level0)
{
struct HksBlob plainData = {0};
plainData.size = strlen(RANDOM_KEY);
plainData.data = (uint8_t *)RANDOM_KEY;
struct HksBlob encryptData = {0};
encryptData.data = (uint8_t *)SoftBusCalloc(LNN_HUKS_AES_COMMON_SIZE);
ASSERT_NE(encryptData.data, nullptr);
struct HksBlob decryptData = {0};
decryptData.data = (uint8_t *)SoftBusCalloc(LNN_HUKS_AES_COMMON_SIZE);
ASSERT_NE(decryptData.data, nullptr);
EXPECT_EQ(LnnGenerateKeyByHuks(&g_keyAlias), SOFTBUS_OK);
EXPECT_EQ(LnnEncryptDataByHuks(&g_keyAlias, &plainData, &encryptData), SOFTBUS_OK);
EXPECT_NE(memcmp(plainData.data, encryptData.data, plainData.size), 0);
EXPECT_EQ(LnnDecryptDataByHuks(&g_keyAlias, &encryptData, &decryptData), SOFTBUS_OK);
EXPECT_EQ(memcmp(decryptData.data, plainData.data, decryptData.size), 0);
SoftBusFree(encryptData.data);
SoftBusFree(decryptData.data);
}
} // namespace OHOS

View File

@ -43,8 +43,43 @@ if (defined(ohos_lite)) {
deps = [ "$dsoftbus_root_path/core/common:softbus_utils" ]
}
ohos_unittest("SqliteTest") {
module_out_path = module_output_path
sources = [ "unittest/sqlite3_utils_test.cpp" ]
include_dirs = [
"$dsoftbus_root_path/adapter/common/include",
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/interfaces/kits/bus_center",
"$dsoftbus_root_path/interfaces/kits/common",
"//commonlibrary/c_utils/base/include",
]
deps = [
"$dsoftbus_root_path/adapter:softbus_adapter",
"$dsoftbus_root_path/core/common:softbus_utils",
"//third_party/googletest:gtest_main",
"//third_party/sqlite:sqlite",
]
if (is_standard_system) {
external_deps = [
"c_utils:utils",
"hiviewdfx_hilog_native:libhilog",
]
} else {
external_deps = [
"c_utils:utils",
"hilog:libhilog",
]
}
}
group("unittest") {
testonly = true
deps = [ ":softbus_utils_test" ]
deps = [
":SqliteTest",
":softbus_utils_test",
]
}
}

View File

@ -30,8 +30,8 @@ constexpr char DEVICE1_HASH[] = "6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d4
constexpr char DEVICE2_HASH[] = "d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35";
constexpr char USER1_ID[] = "4e07408562bedb8b60ce05c1decfe3ad16b72230967de01f640b7e4729b49fce";
constexpr char USER2_ID[] = "4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a";
constexpr char PASSWORD1[] = "ef2d127de37b942baad06145e54b0c619a1f22327b2ebbcfbec78f5564afe39d";
constexpr char PASSWORD2[] = "e7f6c011776e8db7cd330b54174fd76f7d0216b612387a5ffcfb81e6f0919683";
constexpr uint8_t PASSWORD1[] = "ef2d127de37b942baad06145e54b0c619a1f22327b2ebbcfbec78f5564afe39d";
constexpr uint8_t PASSWORD2[] = "e7f6c011776e8db7cd330b54174fd76f7d0216b612387a5ffcfb81e6f0919683";
static TrustedDevInfoRecord g_record1, g_record2, g_record3;
@ -163,7 +163,7 @@ HWTEST_F(Sqlite3UtilsTest, Create_and_Encrypt_Database_Test_001, TestSize.Level0
EXPECT_EQ(OpenDatabase(&ctx), SOFTBUS_OK);
ASSERT_TRUE(ctx != nullptr);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, strlen(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, sizeof(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(CheckTableExist(ctx, TABLE_TRUSTED_DEV_INFO, &isExist), SOFTBUS_OK);
EXPECT_TRUE(!isExist);
EXPECT_EQ(CreateTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
@ -187,7 +187,7 @@ HWTEST_F(Sqlite3UtilsTest, Create_and_Encrypt_Database_Test_002, TestSize.Level0
EXPECT_EQ(OpenDatabase(&ctx), SOFTBUS_OK);
ASSERT_TRUE(ctx != nullptr);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, strlen(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, sizeof(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(CreateTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(DeleteTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(CloseDatabase(ctx), SOFTBUS_OK);
@ -200,7 +200,7 @@ HWTEST_F(Sqlite3UtilsTest, Create_and_Encrypt_Database_Test_002, TestSize.Level0
EXPECT_EQ(OpenDatabase(&ctx), SOFTBUS_OK);
ASSERT_TRUE(ctx != nullptr);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, strlen(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, sizeof(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(CreateTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(DeleteTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(CloseDatabase(ctx), SOFTBUS_OK);
@ -224,28 +224,28 @@ HWTEST_F(Sqlite3UtilsTest, Create_and_Encrypt_Database_Test_003, TestSize.Level0
EXPECT_EQ(OpenDatabase(&ctx), SOFTBUS_OK);
ASSERT_TRUE(ctx != nullptr);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, strlen(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, sizeof(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(CreateTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(DeleteTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(CloseDatabase(ctx), SOFTBUS_OK);
EXPECT_EQ(OpenDatabase(&ctx), SOFTBUS_OK);
ASSERT_TRUE(ctx != nullptr);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD2, strlen(PASSWORD2)), SOFTBUS_OK);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD2, sizeof(PASSWORD2)), SOFTBUS_OK);
EXPECT_NE(CreateTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_NE(DeleteTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(CloseDatabase(ctx), SOFTBUS_OK);
EXPECT_EQ(OpenDatabase(&ctx), SOFTBUS_OK);
ASSERT_TRUE(ctx != nullptr);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, strlen(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, sizeof(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(CreateTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(DeleteTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(CloseDatabase(ctx), SOFTBUS_OK);
EXPECT_EQ(OpenDatabase(&ctx), SOFTBUS_OK);
ASSERT_TRUE(ctx != nullptr);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD2, strlen(PASSWORD2)), SOFTBUS_OK);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD2, sizeof(PASSWORD2)), SOFTBUS_OK);
EXPECT_NE(CreateTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_NE(DeleteTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(CloseDatabase(ctx), SOFTBUS_OK);
@ -263,28 +263,28 @@ HWTEST_F(Sqlite3UtilsTest, Create_and_Encrypt_Database_Test_004, TestSize.Level0
EXPECT_EQ(OpenDatabase(&ctx), SOFTBUS_OK);
ASSERT_TRUE(ctx != nullptr);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, strlen(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, sizeof(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(CreateTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(DeleteTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(CloseDatabase(ctx), SOFTBUS_OK);
EXPECT_EQ(OpenDatabase(&ctx), SOFTBUS_OK);
ASSERT_TRUE(ctx != nullptr);
EXPECT_EQ(UpdateDbPassword(ctx, PASSWORD1, strlen(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(UpdateDbPassword(ctx, PASSWORD1, sizeof(PASSWORD1)), SOFTBUS_OK);
EXPECT_NE(CreateTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_NE(DeleteTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(CloseDatabase(ctx), SOFTBUS_OK);
EXPECT_EQ(OpenDatabase(&ctx), SOFTBUS_OK);
ASSERT_TRUE(ctx != nullptr);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, strlen(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, sizeof(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(CreateTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(DeleteTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(CloseDatabase(ctx), SOFTBUS_OK);
EXPECT_EQ(OpenDatabase(&ctx), SOFTBUS_OK);
ASSERT_TRUE(ctx != nullptr);
EXPECT_EQ(UpdateDbPassword(ctx, PASSWORD1, strlen(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(UpdateDbPassword(ctx, PASSWORD1, sizeof(PASSWORD1)), SOFTBUS_OK);
EXPECT_NE(CreateTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_NE(DeleteTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(CloseDatabase(ctx), SOFTBUS_OK);
@ -302,29 +302,29 @@ HWTEST_F(Sqlite3UtilsTest, Create_and_Encrypt_Database_Test_005, TestSize.Level0
EXPECT_EQ(OpenDatabase(&ctx), SOFTBUS_OK);
ASSERT_TRUE(ctx != nullptr);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, strlen(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, sizeof(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(CreateTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(DeleteTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(CloseDatabase(ctx), SOFTBUS_OK);
EXPECT_EQ(OpenDatabase(&ctx), SOFTBUS_OK);
ASSERT_TRUE(ctx != nullptr);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, strlen(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(UpdateDbPassword(ctx, PASSWORD2, strlen(PASSWORD2)), SOFTBUS_OK);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, sizeof(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(UpdateDbPassword(ctx, PASSWORD2, sizeof(PASSWORD2)), SOFTBUS_OK);
EXPECT_EQ(CreateTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(DeleteTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(CloseDatabase(ctx), SOFTBUS_OK);
EXPECT_EQ(OpenDatabase(&ctx), SOFTBUS_OK);
ASSERT_TRUE(ctx != nullptr);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, strlen(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, sizeof(PASSWORD1)), SOFTBUS_OK);
EXPECT_NE(CreateTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_NE(DeleteTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(CloseDatabase(ctx), SOFTBUS_OK);
EXPECT_EQ(OpenDatabase(&ctx), SOFTBUS_OK);
ASSERT_TRUE(ctx != nullptr);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD2, strlen(PASSWORD2)), SOFTBUS_OK);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD2, sizeof(PASSWORD2)), SOFTBUS_OK);
EXPECT_EQ(CreateTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(DeleteTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(CloseDatabase(ctx), SOFTBUS_OK);
@ -342,7 +342,7 @@ HWTEST_F(Sqlite3UtilsTest, Insert_data_Inerface_Test_001, TestSize.Level0)
EXPECT_EQ(OpenDatabase(&ctx), SOFTBUS_OK);
ASSERT_TRUE(ctx != nullptr);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, strlen(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, sizeof(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(GetRecordNumByKey(ctx, TABLE_TRUSTED_DEV_INFO, (uint8_t *)USER1_ID), 0);
EXPECT_EQ(CreateTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(GetRecordNumByKey(ctx, TABLE_TRUSTED_DEV_INFO, (uint8_t *)USER1_ID), 0);
@ -365,7 +365,7 @@ HWTEST_F(Sqlite3UtilsTest, Insert_data_Inerface_Test_002, TestSize.Level0)
EXPECT_EQ(OpenDatabase(&ctx), SOFTBUS_OK);
ASSERT_TRUE(ctx != nullptr);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, strlen(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, sizeof(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(CreateTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(InsertRecord(ctx, TABLE_TRUSTED_DEV_INFO, (uint8_t *)&g_record1), SOFTBUS_OK);
EXPECT_NE(InsertRecord(ctx, TABLE_TRUSTED_DEV_INFO, (uint8_t *)&g_record1), SOFTBUS_OK);
@ -390,7 +390,7 @@ HWTEST_F(Sqlite3UtilsTest, Remove_data_Inerface_Test_001, TestSize.Level0)
EXPECT_EQ(OpenDatabase(&ctx), SOFTBUS_OK);
ASSERT_TRUE(ctx != nullptr);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, strlen(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, sizeof(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(CreateTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(InsertRecord(ctx, TABLE_TRUSTED_DEV_INFO, (uint8_t *)&g_record1), SOFTBUS_OK);
EXPECT_EQ(GetRecordNumByKey(ctx, TABLE_TRUSTED_DEV_INFO, (uint8_t *)USER1_ID), 1);
@ -414,7 +414,7 @@ HWTEST_F(Sqlite3UtilsTest, Remove_data_Inerface_Test_002, TestSize.Level0)
EXPECT_EQ(OpenDatabase(&ctx), SOFTBUS_OK);
ASSERT_TRUE(ctx != nullptr);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, strlen(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, sizeof(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(CreateTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(InsertRecord(ctx, TABLE_TRUSTED_DEV_INFO, (uint8_t *)&g_record1), SOFTBUS_OK);
EXPECT_EQ(GetRecordNumByKey(ctx, TABLE_TRUSTED_DEV_INFO, (uint8_t *)USER1_ID), 1);
@ -438,7 +438,7 @@ HWTEST_F(Sqlite3UtilsTest, Remove_data_Inerface_Test_003, TestSize.Level0)
EXPECT_EQ(OpenDatabase(&ctx), SOFTBUS_OK);
ASSERT_TRUE(ctx != nullptr);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, strlen(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, sizeof(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(CreateTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(InsertRecord(ctx, TABLE_TRUSTED_DEV_INFO, (uint8_t *)&g_record1), SOFTBUS_OK);
EXPECT_EQ(GetRecordNumByKey(ctx, TABLE_TRUSTED_DEV_INFO, (uint8_t *)USER1_ID), 1);
@ -464,7 +464,7 @@ HWTEST_F(Sqlite3UtilsTest, Query_data_Inerface_Test_001, TestSize.Level0)
EXPECT_EQ(OpenDatabase(&ctx), SOFTBUS_OK);
ASSERT_TRUE(ctx != nullptr);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, strlen(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, sizeof(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(CreateTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(InsertRecord(ctx, TABLE_TRUSTED_DEV_INFO, (uint8_t *)&g_record1), SOFTBUS_OK);
num = GetRecordNumByKey(ctx, TABLE_TRUSTED_DEV_INFO, (uint8_t *)USER1_ID);
@ -493,7 +493,7 @@ HWTEST_F(Sqlite3UtilsTest, Query_data_Inerface_Test_002, TestSize.Level0)
EXPECT_EQ(OpenDatabase(&ctx), SOFTBUS_OK);
ASSERT_TRUE(ctx != nullptr);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, strlen(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, sizeof(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(CreateTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(InsertRecord(ctx, TABLE_TRUSTED_DEV_INFO, (uint8_t *)&g_record1), SOFTBUS_OK);
EXPECT_EQ(InsertRecord(ctx, TABLE_TRUSTED_DEV_INFO, (uint8_t *)&g_record2), SOFTBUS_OK);
@ -523,7 +523,7 @@ HWTEST_F(Sqlite3UtilsTest, Open_and_Close_Transaction_Test_001, TestSize.Level0)
EXPECT_EQ(OpenDatabase(&ctx), SOFTBUS_OK);
ASSERT_TRUE(ctx != nullptr);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, strlen(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, sizeof(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(CreateTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(OpenTransaction(ctx), SOFTBUS_OK);
EXPECT_EQ(InsertRecord(ctx, TABLE_TRUSTED_DEV_INFO, (uint8_t *)&g_record1), SOFTBUS_OK);
@ -547,7 +547,7 @@ HWTEST_F(Sqlite3UtilsTest, Open_and_Close_Transaction_Test_002, TestSize.Level0)
EXPECT_EQ(OpenDatabase(&ctx), SOFTBUS_OK);
ASSERT_TRUE(ctx != nullptr);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, strlen(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(EncryptedDb(ctx, PASSWORD1, sizeof(PASSWORD1)), SOFTBUS_OK);
EXPECT_EQ(CreateTable(ctx, TABLE_TRUSTED_DEV_INFO), SOFTBUS_OK);
EXPECT_EQ(OpenTransaction(ctx), SOFTBUS_OK);
EXPECT_EQ(InsertRecord(ctx, TABLE_TRUSTED_DEV_INFO, (uint8_t *)&g_record1), SOFTBUS_OK);

View File

@ -33,7 +33,6 @@ public:
static void TearDownTestCase();
void SetUp();
void TearDown();
void AddPermission();
};
void BusCenterHeartbeatSdkTest::SetUpTestCase()

View File

@ -32,7 +32,6 @@ public:
static void TearDownTestCase();
void SetUp();
void TearDown();
void AddPermission();
};
void BusCenterMetaNodeSdkTest::SetUpTestCase()

View File

@ -40,7 +40,6 @@ public:
static void TearDownTestCase();
void SetUp();
void TearDown();
void AddPermission();
};
void BusCenterSdkTest::SetUpTestCase()