diff --git a/core/authentication/src/auth_session_json.c b/core/authentication/src/auth_session_json.c index 20bc4591761d119555248ffad92aaa961e11aa1e..1d78c931a0c9edc70bf0dfbcddb072be20b873eb 100644 --- a/core/authentication/src/auth_session_json.c +++ b/core/authentication/src/auth_session_json.c @@ -91,6 +91,7 @@ #define BLE_MAC "BLE_MAC" #define CONN_CAP "CONN_CAP" #define AUTH_CAP "AUTH_CAP" +#define HB_CAP "HB_CAP" #define SW_VERSION "SW_VERSION" #define MASTER_UDID "MASTER_UDID" #define MASTER_WEIGHT "MASTER_WEIGHT" @@ -1357,6 +1358,7 @@ static int32_t PackCommonEx(JsonObj *json, const NodeInfo *info) !JSON_AddStringToObject(json, VERSION_TYPE, info->versionType) || !JSON_AddInt32ToObject(json, CONN_CAP, info->netCapacity) || !JSON_AddInt32ToObject(json, AUTH_CAP, info->authCapacity) || + !JSON_AddInt32ToObject(json, HB_CAP, info->heartbeatCapacity) || !JSON_AddInt16ToObject(json, DATA_CHANGE_FLAG, info->dataChangeFlag) || !JSON_AddBoolToObject(json, IS_CHARGING, info->batteryInfo.isCharging) || !JSON_AddBoolToObject(json, BLE_P2P, info->isBleP2p) || @@ -1528,6 +1530,7 @@ static void ParseCommonJsonInfo(const JsonObj *json, NodeInfo *info, bool isMeta (void)JSON_GetStringFromOject(json, VERSION_TYPE, info->versionType, VERSION_MAX_LEN); (void)JSON_GetInt32FromOject(json, CONN_CAP, (int32_t *)&info->netCapacity); (void)JSON_GetInt32FromOject(json, AUTH_CAP, (int32_t *)&info->authCapacity); + (void)JSON_GetInt32FromOject(json, HB_CAP, (int32_t *)&info->heartbeatCapacity); info->isBleP2p = false; (void)JSON_GetBoolFromOject(json, BLE_P2P, &info->isBleP2p); (void)JSON_GetInt16FromOject(json, DATA_CHANGE_FLAG, (int16_t *)&info->dataChangeFlag); diff --git a/core/bus_center/interface/bus_center_manager.h b/core/bus_center/interface/bus_center_manager.h index c23debb6c39d6f684c9640dfb55c3b420827ba4a..9dc2d68d085052a09f35e8b32196a7e51bbad8b7 100644 --- a/core/bus_center/interface/bus_center_manager.h +++ b/core/bus_center/interface/bus_center_manager.h @@ -86,6 +86,7 @@ int32_t LnnGetConnSubFeatureByUdidHashStr(const char *udidHashStr, uint64_t *con int32_t LnnSetLocalUnifiedName(const char *unifiedName); bool LnnIsMasterNode(void); void SoftBusDumpBusCenterPrintInfo(int fd, NodeBasicInfo *nodeInfo); +int32_t LnnRequestCheckOnlineStatus(const char *networkId, uint64_t timeout); int32_t LnnServerJoin(ConnectionAddr *addr, const char *pkgName); int32_t LnnServerLeave(const char *networkId, const char *pkgName); diff --git a/core/bus_center/lnn/lane_hub/heartbeat/include/lnn_heartbeat_ctrl.h b/core/bus_center/lnn/lane_hub/heartbeat/include/lnn_heartbeat_ctrl.h index dcea2dc98baf10d82327f107fe3f08463a79d9a7..2305ce2dc44b75c08c4ebdd33d1f4691a7a65e49 100644 --- a/core/bus_center/lnn/lane_hub/heartbeat/include/lnn_heartbeat_ctrl.h +++ b/core/bus_center/lnn/lane_hub/heartbeat/include/lnn_heartbeat_ctrl.h @@ -38,6 +38,7 @@ void LnnRequestBleDiscoveryProcess(int32_t strategy, int64_t timeout); void LnnHbOnTrustedRelationIncreased(int32_t groupType); void LnnHbOnTrustedRelationReduced(void); +int32_t LnnTriggerDirectHeartbeat(const char *networkId, uint64_t timeout); int32_t LnnInitHeartbeat(void); void LnnDeinitHeartbeat(void); diff --git a/core/bus_center/lnn/lane_hub/heartbeat/include/lnn_heartbeat_fsm.h b/core/bus_center/lnn/lane_hub/heartbeat/include/lnn_heartbeat_fsm.h index 15e68a25cb2d89d56568b050e6d54a567517b130..08df618ddba41a301eccf968fe7a2c15ecb9522b 100644 --- a/core/bus_center/lnn/lane_hub/heartbeat/include/lnn_heartbeat_fsm.h +++ b/core/bus_center/lnn/lane_hub/heartbeat/include/lnn_heartbeat_fsm.h @@ -73,6 +73,7 @@ typedef struct { bool hasNetworkId; bool isWakeUp; const char networkId[NETWORK_ID_BUF_LEN]; + uint64_t checkDelay; } LnnCheckDevStatusMsgPara; typedef struct { @@ -83,6 +84,9 @@ typedef struct { bool isNeedRestart; bool hasScanRsp; bool isFirstBegin; + bool isDirectBoardcast; + char networkId[NETWORK_ID_BUF_LEN]; + uint64_t checkDelay; } LnnProcessSendOnceMsgPara; int32_t LnnStartHeartbeatFsm(LnnHeartbeatFsm *hbFsm); diff --git a/core/bus_center/lnn/lane_hub/heartbeat/include/lnn_heartbeat_medium_mgr.h b/core/bus_center/lnn/lane_hub/heartbeat/include/lnn_heartbeat_medium_mgr.h index 4856b15ccd4d3b85d2972770de14f28b51c0cb74..38af0699e620bf3273636a0e770785ec7b9b224e 100644 --- a/core/bus_center/lnn/lane_hub/heartbeat/include/lnn_heartbeat_medium_mgr.h +++ b/core/bus_center/lnn/lane_hub/heartbeat/include/lnn_heartbeat_medium_mgr.h @@ -65,6 +65,8 @@ typedef struct { bool isFirstBegin; bool isNeedRestart; bool hasScanRsp; + bool isDirectBoardcast; + char networkId[NETWORK_ID_BUF_LEN]; } LnnHeartbeatSendBeginData; typedef struct { diff --git a/core/bus_center/lnn/lane_hub/heartbeat/include/lnn_heartbeat_strategy.h b/core/bus_center/lnn/lane_hub/heartbeat/include/lnn_heartbeat_strategy.h index d9114b854519fe2719f0bff6993465ad56c8d580..2bc547e055b15d0bac13e0f0c9bd12632a3f196c 100644 --- a/core/bus_center/lnn/lane_hub/heartbeat/include/lnn_heartbeat_strategy.h +++ b/core/bus_center/lnn/lane_hub/heartbeat/include/lnn_heartbeat_strategy.h @@ -40,6 +40,8 @@ int32_t LnnGetHbStrategyManager( int32_t LnnStartNewHbStrategyFsm(void); int32_t LnnStartHbByTypeAndStrategy(LnnHeartbeatType hbType, LnnHeartbeatStrategyType strategyType, bool isRelay); +int32_t LnnStartHbByTypeAndStrategyDirectly(LnnHeartbeatType hbType, LnnHeartbeatStrategyType strategyType, + bool isRelay, const char *networkId, uint64_t timeout); int32_t LnnStartHeartbeat(uint64_t delayMillis); int32_t LnnStopHeartbeatByType(LnnHeartbeatType type); int32_t LnnStopV0HeartbeatAndNotTransState(); diff --git a/core/bus_center/lnn/lane_hub/heartbeat/include/lnn_heartbeat_utils.h b/core/bus_center/lnn/lane_hub/heartbeat/include/lnn_heartbeat_utils.h index 70cb987f9b6efc2f869f2ceb5460bd491e69a6c6..1142c52d5902d4942a218bb75dfa001601865395 100644 --- a/core/bus_center/lnn/lane_hub/heartbeat/include/lnn_heartbeat_utils.h +++ b/core/bus_center/lnn/lane_hub/heartbeat/include/lnn_heartbeat_utils.h @@ -51,6 +51,7 @@ extern "C" { #define HB_RESTART_LEN (3 * HB_TIME_FACTOR) #define HB_PERIOD_DUMP_LOCAL_INFO_LEN (5 * 60 * HB_TIME_FACTOR) #define HB_SEND_RELAY_LEN_ONCE (3 * HB_TIME_FACTOR) +#define HB_SEND_DIRECT_LEN_ONCE (5 * HB_TIME_FACTOR) #define HB_OFFLINE_PERIOD 2 #define HB_SEND_EACH_SEPARATELY_LEN (2 * HB_TIME_FACTOR) // Split and send a single heartbeat @@ -102,6 +103,7 @@ typedef enum { STRATEGY_HB_SEND_ADJUSTABLE_PERIOD, STRATEGY_HB_RECV_SINGLE = 3, STRATEGY_HB_RECV_REMOVE_REPEAT, + STRATEGY_HB_SEND_DIRECT, } LnnHeartbeatStrategyType; typedef enum { @@ -123,8 +125,13 @@ typedef struct { uint32_t switchLevel; int32_t preferChannel; uint8_t shortUuid[HB_SHORT_UUID_LEN]; + uint8_t hbVersion; } HbRespData; +typedef enum { + BIT_SUPPORT_DIRECT_TRIGGER = 0, +} HeartbeatCapability; + #define STATE_VERSION_INVALID (-1) #define ENABLE_COC_CAP (1 << 0) #define P2P_GO (1 << 1) @@ -154,6 +161,7 @@ void LnnDumpLocalBasicInfo(void); void LnnDumpOnlineDeviceInfo(void); uint32_t GenerateRandomNumForHb(uint32_t randMin, uint32_t randMax); bool LnnIsMultiDeviceOnline(void); +bool LnnIsSupportHeartbeatCap(uint32_t hbCapacity, HeartbeatCapability capaBit); #ifdef __cplusplus } diff --git a/core/bus_center/lnn/lane_hub/heartbeat/src/lnn_ble_heartbeat_virtual.c b/core/bus_center/lnn/lane_hub/heartbeat/src/lnn_ble_heartbeat_virtual.c index 0414236bd98fa4e11a8e5eaece5033959ceda512..fe2c4df9d072fca502a1cda8e33fece20bbdb3c9 100644 --- a/core/bus_center/lnn/lane_hub/heartbeat/src/lnn_ble_heartbeat_virtual.c +++ b/core/bus_center/lnn/lane_hub/heartbeat/src/lnn_ble_heartbeat_virtual.c @@ -15,6 +15,7 @@ #include "lnn_ble_heartbeat.h" +#include "bus_center_manager.h" #include "lnn_heartbeat_medium_mgr.h" #include "lnn_log.h" #include "softbus_errcode.h" @@ -107,3 +108,10 @@ int32_t LnnSendBroadcastInfoToLp(void) } void LnnAdjustScanPolicy(void) { } + +int32_t LnnRequestCheckOnlineStatus(const char *networkId, uint64_t timeout) +{ + (void)networkId; + (void)timeout; + return SOFTBUS_NOT_IMPLEMENT; +} diff --git a/core/bus_center/lnn/lane_hub/heartbeat/src/lnn_heartbeat_ctrl.c b/core/bus_center/lnn/lane_hub/heartbeat/src/lnn_heartbeat_ctrl.c index 72d68f5cdc55be13b8674fac5ea5a22ac07ece9b..e7005905bcbf5bc000069949d613f0679479e71d 100644 --- a/core/bus_center/lnn/lane_hub/heartbeat/src/lnn_heartbeat_ctrl.c +++ b/core/bus_center/lnn/lane_hub/heartbeat/src/lnn_heartbeat_ctrl.c @@ -1202,6 +1202,18 @@ int32_t LnnTriggerDataLevelHeartbeat(void) return SOFTBUS_OK; } +int32_t LnnTriggerDirectHeartbeat(const char *networkId, uint64_t timeout) +{ + LNN_LOGD(LNN_HEART_BEAT, "LnnTriggerDirectHeartbeat"); + int32_t ret = LnnStartHbByTypeAndStrategyDirectly(HEARTBEAT_TYPE_BLE_V0, STRATEGY_HB_SEND_DIRECT, + false, networkId, timeout); + if (ret != SOFTBUS_OK) { + LNN_LOGE(LNN_HEART_BEAT, "ctrl start direct ble heartbeat fail"); + return ret; + } + return SOFTBUS_OK; +} + int32_t LnnTriggerCloudSyncHeartbeat(void) { LNN_LOGD(LNN_HEART_BEAT, "LnnTriggerCloudSyncHeartbeat"); diff --git a/core/bus_center/lnn/lane_hub/heartbeat/src/lnn_heartbeat_fsm.c b/core/bus_center/lnn/lane_hub/heartbeat/src/lnn_heartbeat_fsm.c index 5cdd7f440f22c7f8504873d2d38e566b6155f190..3c854eeec0b3e9e300054cb5a3e19b0f5fb6bb8d 100644 --- a/core/bus_center/lnn/lane_hub/heartbeat/src/lnn_heartbeat_fsm.c +++ b/core/bus_center/lnn/lane_hub/heartbeat/src/lnn_heartbeat_fsm.c @@ -808,7 +808,7 @@ static int32_t ProcessLostHeartbeat(const char *networkId, LnnHeartbeatType type return SOFTBUS_OK; } -static bool IsTimestampExceedLimit(uint64_t nowTime, uint64_t oldTimeStamp, LnnHeartbeatType hbType) +static bool IsTimestampExceedLimit(uint64_t nowTime, uint64_t oldTimeStamp, LnnHeartbeatType hbType, uint64_t delayTime) { GearMode mode; (void)memset_s(&mode, sizeof(GearMode), 0, sizeof(GearMode)); @@ -816,7 +816,7 @@ static bool IsTimestampExceedLimit(uint64_t nowTime, uint64_t oldTimeStamp, LnnH switch (hbType) { case HEARTBEAT_TYPE_BLE_V0: - if ((nowTime - oldTimeStamp) <= HB_CHECK_OFFLINE_TOLERANCE_LEN) { + if ((nowTime - oldTimeStamp) <= delayTime) { return false; } break; @@ -868,7 +868,7 @@ static void CheckDevStatusByNetworkId(LnnHeartbeatFsm *hbFsm, const char *networ } SoftBusGetTime(×); nowTime = (uint64_t)times.sec * HB_TIME_FACTOR + (uint64_t)times.usec / HB_TIME_FACTOR; - if (!IsTimestampExceedLimit(nowTime, oldTimeStamp, hbType)) { + if (!IsTimestampExceedLimit(nowTime, oldTimeStamp, hbType, msgPara->checkDelay)) { Anonymize(networkId, &anonyNetworkId); LNN_LOGD(LNN_HEART_BEAT, "check dev status receive heartbeat in time, networkId=%{public}s, " "nowTime=%{public}" PRIu64 ", oldTimeStamp=%{public}" PRIu64, anonyNetworkId, nowTime, oldTimeStamp); @@ -1170,6 +1170,11 @@ int32_t LnnPostSendBeginMsgToHbFsm(LnnHeartbeatFsm *hbFsm, LnnHeartbeatType type custData->isNeedRestart = msgPara->isNeedRestart; custData->hasScanRsp = msgPara->hasScanRsp; custData->isFirstBegin = msgPara->isFirstBegin; + custData->isDirectBoardcast = msgPara->isDirectBoardcast; + if (strcpy_s(custData->networkId, NETWORK_ID_BUF_LEN, msgPara->networkId) != EOK) { + LNN_LOGE(LNN_HEART_BEAT, "cpy networkId fail"); + return SOFTBUS_MEM_ERR; + } if (LnnFsmPostMessageDelay(&hbFsm->fsm, EVENT_HB_SEND_ONE_BEGIN, (void *)custData, delayMillis) != SOFTBUS_OK) { LNN_LOGE(LNN_HEART_BEAT, "post send begin msg to hbFsm fail"); SoftBusFree(custData); @@ -1268,8 +1273,8 @@ int32_t LnnPostSetMediumParamMsgToHbFsm(LnnHeartbeatFsm *hbFsm, const LnnHeartbe return SOFTBUS_OK; } -int32_t LnnPostCheckDevStatusMsgToHbFsm(LnnHeartbeatFsm *hbFsm, - const LnnCheckDevStatusMsgPara *para, uint64_t delayMillis) +int32_t LnnPostCheckDevStatusMsgToHbFsm(LnnHeartbeatFsm *hbFsm, const LnnCheckDevStatusMsgPara *para, + uint64_t delayMillis) { LnnCheckDevStatusMsgPara *dupPara = NULL; @@ -1290,6 +1295,7 @@ int32_t LnnPostCheckDevStatusMsgToHbFsm(LnnHeartbeatFsm *hbFsm, SoftBusFree(dupPara); return SOFTBUS_MEM_ERR; } + dupPara->checkDelay = delayMillis; if (LnnFsmPostMessageDelay(&hbFsm->fsm, EVENT_HB_CHECK_DEV_STATUS, (void *)dupPara, delayMillis) != SOFTBUS_OK) { LNN_LOGE(LNN_HEART_BEAT, "post check dev status msg to hbFsm fail"); SoftBusFree(dupPara); diff --git a/core/bus_center/lnn/lane_hub/heartbeat/src/lnn_heartbeat_medium_mgr.c b/core/bus_center/lnn/lane_hub/heartbeat/src/lnn_heartbeat_medium_mgr.c index 5118f7490cba7a6f6a73649709f3311f53b79427..2a557c01ef9653d1af0c0fceda15fa6e9554b8ab 100644 --- a/core/bus_center/lnn/lane_hub/heartbeat/src/lnn_heartbeat_medium_mgr.c +++ b/core/bus_center/lnn/lane_hub/heartbeat/src/lnn_heartbeat_medium_mgr.c @@ -54,10 +54,11 @@ #define INVALID_BR_MAC_ADDR "00:00:00:00:00:00" +#define HB_VERSION_V2 0x04 #define HB_RECV_INFO_SAVE_LEN (60 * 60 * HB_TIME_FACTOR) #define HB_REAUTH_TIME (10 * HB_TIME_FACTOR) #define HB_DFX_DELAY_TIME (7 * HB_TIME_FACTOR) -#define PC_RESTRICT_TIME 3 +#define PC_RESTRICT_TIME 3 typedef struct { ListNode node; DeviceInfo *device; @@ -673,8 +674,8 @@ static int32_t HbAddAsyncProcessCallbackDelay(DeviceInfo *device, bool *IsRestri return SOFTBUS_OK; } -static int32_t SoftBusNetNodeResult( - DeviceInfo *device, HbRespData *hbResp, bool isConnect, ConnectOnlineReason connectReason) +static int32_t SoftBusNetNodeResult(DeviceInfo *device, HbRespData *hbResp, bool isConnect, + ConnectOnlineReason connectReason, bool isDirectlyHb) { char *anonyUdid = NULL; Anonymize(device->devId, &anonyUdid); @@ -704,6 +705,9 @@ static int32_t SoftBusNetNodeResult( LNN_LOGE(LNN_HEART_BEAT, "mgr recv process notify device found fail"); return SOFTBUS_ERR; } + if (isDirectlyHb) { + return SOFTBUS_NETWORK_HEARTBEAT_DIRECT; + } if (isConnect) { return SOFTBUS_NETWORK_NODE_OFFLINE; } else { @@ -868,6 +872,19 @@ static int32_t CheckJoinLnnRequest( return SOFTBUS_OK; } +static bool IsDirectlyHeartBeat(DeviceInfo *device, HbRespData *hbResp) +{ + if (device == NULL || hbResp == NULL) { + LNN_LOGE(LNN_HEART_BEAT, "device or resp is null"); + return false; + } + if (hbResp->hbVersion == HB_VERSION_V2) { + LNN_LOGE(LNN_HEART_BEAT, "hb version is v2"); + return true; + } + return false; +} + static int32_t HbNotifyReceiveDevice(DeviceInfo *device, const LnnHeartbeatWeight *mediumWeight, LnnHeartbeatType hbType, bool isOnlineDirectly, HbRespData *hbResp) { @@ -893,15 +910,16 @@ static int32_t HbNotifyReceiveDevice(DeviceInfo *device, const LnnHeartbeatWeigh HbDumpRecvDeviceInfo(device, mediumWeight->weight, mediumWeight->localMasterWeight, hbType, nowTime); NodeInfo nodeInfo; (void)memset_s(&nodeInfo, sizeof(NodeInfo), 0, sizeof(NodeInfo)); + bool isDirectlyHb = IsDirectlyHeartBeat(device, hbResp); if (HbGetOnlineNodeByRecvInfo(device->devId, device->addr[0].type, &nodeInfo, hbResp) == SOFTBUS_OK) { - if (!HbIsNeedReAuth(&nodeInfo, device->accountHash) && - !IsUuidChange(nodeInfo.uuid, hbResp, HB_SHORT_UUID_LEN, device)) { + if (isDirectlyHb || (!HbIsNeedReAuth(&nodeInfo, device->accountHash) && + !IsUuidChange(nodeInfo.uuid, hbResp, HB_SHORT_UUID_LEN, device))) { (void)SoftBusMutexUnlock(&g_hbRecvList->lock); return HbUpdateOfflineTimingByRecvInfo(nodeInfo.networkId, device->addr[0].type, hbType, nowTime); } - int32_t ret = HbOnlineNodeAuth(device, storedInfo, nowTime); + res = HbOnlineNodeAuth(device, storedInfo, nowTime); (void)SoftBusMutexUnlock(&g_hbRecvList->lock); - return ret; + return res; } ConnectOnlineReason connectReason = CONNECT_INITIAL_VALUE; bool isConnect = false; @@ -916,7 +934,7 @@ static int32_t HbNotifyReceiveDevice(DeviceInfo *device, const LnnHeartbeatWeigh return SOFTBUS_NETWORK_HEARTBEAT_REPEATED; } (void)SoftBusMutexUnlock(&g_hbRecvList->lock); - return SoftBusNetNodeResult(device, hbResp, isConnect, connectReason); + return SoftBusNetNodeResult(device, hbResp, isConnect, connectReason, isDirectlyHb); } static int32_t HbMediumMgrRecvProcess(DeviceInfo *device, const LnnHeartbeatWeight *mediumWeight, diff --git a/core/bus_center/lnn/lane_hub/heartbeat/src/lnn_heartbeat_strategy.c b/core/bus_center/lnn/lane_hub/heartbeat/src/lnn_heartbeat_strategy.c index 00415fc7710957d017fb017a711077af8b45bdaf..06bf2eda69583c4fdf8b1438880d726260f6981a 100644 --- a/core/bus_center/lnn/lane_hub/heartbeat/src/lnn_heartbeat_strategy.c +++ b/core/bus_center/lnn/lane_hub/heartbeat/src/lnn_heartbeat_strategy.c @@ -23,6 +23,7 @@ #include "lnn_heartbeat_fsm.h" #include "lnn_heartbeat_medium_mgr.h" #include "lnn_heartbeat_utils.h" +#include "lnn_local_net_ledger.h" #include "lnn_log.h" #include "bus_center_manager.h" @@ -58,6 +59,7 @@ static LnnHeartbeatParamManager *g_hbParamMgr[HB_MAX_TYPE_COUNT] = { 0 }; static int32_t SingleSendStrategy(LnnHeartbeatFsm *hbFsm, void *obj); static int32_t FixedPeriodSendStrategy(LnnHeartbeatFsm *hbFsm, void *obj); static int32_t AdjustablePeriodSendStrategy(LnnHeartbeatFsm *hbFsm, void *obj); +static int32_t DirectAdvSendStrategy(LnnHeartbeatFsm *hbFsm, void *obj); static LnnHeartbeatStrategyManager g_hbStrategyMgr[] = { [STRATEGY_HB_SEND_SINGLE] = { @@ -81,6 +83,10 @@ static LnnHeartbeatStrategyManager g_hbStrategyMgr[] = { .supportType = HEARTBEAT_TYPE_BLE_V0 | HEARTBEAT_TYPE_BLE_V1, .onProcess = NULL, }, + [STRATEGY_HB_SEND_DIRECT] = { + .supportType = HEARTBEAT_TYPE_BLE_V0, + .onProcess = DirectAdvSendStrategy, + }, }; static void DumpGearModeSettingList(int64_t nowTime, const ListNode *gearModeList) @@ -518,6 +524,39 @@ static int32_t SendEachSeparately(LnnHeartbeatFsm *hbFsm, LnnProcessSendOnceMsgP return OtherHeartbeatSplit(hbFsm, msgPara, wakeupFlag, registedHbType); } +static int32_t SendDirectBoardcast(LnnHeartbeatFsm *hbFsm, LnnProcessSendOnceMsgPara *msgPara, const GearMode *mode, + LnnHeartbeatType registedHbType, bool isRelayV0) +{ + LNN_LOGI(LNN_HEART_BEAT, "hbType=%{public}d, isRelay=%{public}d", registedHbType, msgPara->isRelay); + bool wakeupFlag = mode != NULL ? mode->wakeupFlag : false; + + msgPara->isSyncData = false; + msgPara->hasScanRsp = true; + msgPara->isNeedRestart = true; + msgPara->isFirstBegin = false; + uint32_t delayTime = 0; + int32_t ret = LnnPostSendBeginMsgToHbFsm(hbFsm, registedHbType, true, msgPara, delayTime); + if (ret != SOFTBUS_OK) { + LNN_LOGE(LNN_HEART_BEAT, "HB send once first begin fail, hbType=%{public}d", registedHbType); + return ret; + } + LnnHeartbeatType splitHbType = registedHbType; + (void)LnnVisitHbTypeSet(VisitClearNoneSplitHbType, &splitHbType, NULL); + LnnHeartbeatSendEndData endData = { + .hbType = splitHbType, + .wakeupFlag = wakeupFlag, + .isRelay = msgPara->isRelay, + .isLastEnd = true, + }; + delayTime += HB_SEND_DIRECT_LEN_ONCE; + ret = LnnPostSendEndMsgToHbFsm(hbFsm, &endData, delayTime); + if (ret != SOFTBUS_OK) { + LNN_LOGE(LNN_HEART_BEAT, "HB send once last end fail, hbType=%{public}d", registedHbType); + return ret; + } + return SOFTBUS_OK; +} + static bool VisitClearUnRegistedHbType(LnnHeartbeatType *typeSet, LnnHeartbeatType eachType, void *data) { (void)data; @@ -529,6 +568,28 @@ static bool VisitClearUnRegistedHbType(LnnHeartbeatType *typeSet, LnnHeartbeatTy return true; } +static int32_t ProcessCheckDevStatusMsg(LnnHeartbeatFsm *hbFsm, LnnProcessSendOnceMsgPara *msgPara, + LnnHeartbeatType registedHbType, bool wakeupFlag) +{ + LnnCheckDevStatusMsgPara checkMsg = { .hbType = registedHbType, .hasNetworkId = false, .isWakeUp = wakeupFlag }; + LnnRemoveCheckDevStatusMsg(hbFsm, &checkMsg); + uint64_t checkDelay = HB_CHECK_DELAY_LEN; + if (msgPara->isDirectBoardcast) { + checkDelay = msgPara->checkDelay; + checkMsg.hasNetworkId = true; + if (strcpy_s((char *)checkMsg.networkId, NETWORK_ID_BUF_LEN, msgPara->networkId) != EOK) { + LNN_LOGE(LNN_HEART_BEAT, "copy networkId fail"); + return SOFTBUS_MEM_ERR; + } + } + int32_t ret = LnnPostCheckDevStatusMsgToHbFsm(hbFsm, &checkMsg, checkDelay); + if (ret != SOFTBUS_OK) { + LNN_LOGE(LNN_HEART_BEAT, "HB send once post check msg fail, hbType=%{public}d", registedHbType); + return ret; + } + return SOFTBUS_OK; +} + static int32_t ProcessSendOnceStrategy(LnnHeartbeatFsm *hbFsm, LnnProcessSendOnceMsgPara *msgPara, const GearMode *mode) { bool isRemoved = true; @@ -548,22 +609,23 @@ static int32_t ProcessSendOnceStrategy(LnnHeartbeatFsm *hbFsm, LnnProcessSendOnc } LnnFsmRemoveMessage(&hbFsm->fsm, EVENT_HB_SEND_ONE_BEGIN); bool isRelayV0 = msgPara->isRelay && registedHbType == HEARTBEAT_TYPE_BLE_V0; - if (SendEachSeparately(hbFsm, msgPara, mode, registedHbType, isRelayV0) != SOFTBUS_OK) { - LNN_LOGE(LNN_HEART_BEAT, "HB send each separately fail, hbType=%{public}d", registedHbType); - return SOFTBUS_ERR; + if (msgPara->isDirectBoardcast) { + if (SendDirectBoardcast(hbFsm, msgPara, mode, registedHbType, isRelayV0) != SOFTBUS_OK) { + LNN_LOGE(LNN_HEART_BEAT, "HB send direct boardcast fail, hbType=%{public}d", registedHbType); + return SOFTBUS_NETWORK_HEARTBEAT_SEND_ERR; + } + } else { + if (SendEachSeparately(hbFsm, msgPara, mode, registedHbType, isRelayV0) != SOFTBUS_OK) { + LNN_LOGE(LNN_HEART_BEAT, "HB send each separately fail, hbType=%{public}d", registedHbType); + return SOFTBUS_NETWORK_HEARTBEAT_SEND_ERR; + } } if (isRelayV0) { LNN_LOGD(LNN_HEART_BEAT, "HB send once but dont check status, hbType=%{public}d", registedHbType); return SOFTBUS_OK; } registedHbType &= (~(HEARTBEAT_TYPE_BLE_V3)); - LnnCheckDevStatusMsgPara checkMsg = { .hbType = registedHbType, .hasNetworkId = false, .isWakeUp = wakeupFlag }; - LnnRemoveCheckDevStatusMsg(hbFsm, &checkMsg); - if (LnnPostCheckDevStatusMsgToHbFsm(hbFsm, &checkMsg, HB_CHECK_DELAY_LEN) != SOFTBUS_OK) { - LNN_LOGE(LNN_HEART_BEAT, "HB send once post check msg fail, hbType=%{public}d", registedHbType); - return SOFTBUS_ERR; - } - return SOFTBUS_OK; + return ProcessCheckDevStatusMsg(hbFsm, msgPara, registedHbType, wakeupFlag); } static int32_t SingleSendStrategy(LnnHeartbeatFsm *hbFsm, void *obj) @@ -632,6 +694,20 @@ static int32_t AdjustablePeriodSendStrategy(LnnHeartbeatFsm *hbFsm, void *obj) return SOFTBUS_OK; } +static int32_t DirectAdvSendStrategy(LnnHeartbeatFsm *hbFsm, void *obj) +{ + LnnProcessSendOnceMsgPara *msgPara = (LnnProcessSendOnceMsgPara *)obj; + if (msgPara->strategyType != STRATEGY_HB_SEND_DIRECT) { + LNN_LOGE(LNN_HEART_BEAT, "HB send get invaild strategy"); + return SOFTBUS_INVALID_PARAM; + } + if (ProcessSendOnceStrategy(hbFsm, msgPara, NULL) != SOFTBUS_OK) { + LNN_LOGE(LNN_HEART_BEAT, "HB single send process send once fail"); + return SOFTBUS_NETWORK_HEARTBEAT_SEND_ERR; + } + return SOFTBUS_OK; +} + static int32_t RegistParamMgrBySpecificType(LnnHeartbeatType type) { LnnHeartbeatParamManager *paramMgr = NULL; @@ -952,6 +1028,32 @@ int32_t LnnStartHbByTypeAndStrategy(LnnHeartbeatType hbType, LnnHeartbeatStrateg return SOFTBUS_OK; } +int32_t LnnStartHbByTypeAndStrategyDirectly(LnnHeartbeatType hbType, LnnHeartbeatStrategyType strategyType, + bool isRelay, const char *networkId, uint64_t timeout) +{ + if (networkId == NULL) { + LNN_LOGE(LNN_HEART_BEAT, "invaild param"); + return SOFTBUS_INVALID_PARAM; + } + LnnProcessSendOnceMsgPara msgPara = { + .hbType = hbType, + .strategyType = strategyType, + .isRelay = isRelay, + .isSyncData = false, + .isDirectBoardcast = true, + .checkDelay = timeout, + }; + if (strcpy_s((char *)msgPara.networkId, NETWORK_ID_BUF_LEN, networkId) != EOK) { + LNN_LOGE(LNN_HEART_BEAT, "get local nodeInfo fail"); + return SOFTBUS_MEM_ERR; + } + if (LnnPostNextSendOnceMsgToHbFsm(g_hbFsm, &msgPara, 0) != SOFTBUS_OK) { + LNN_LOGE(LNN_HEART_BEAT, "HB start heartbeat fail, type=%{public}d", hbType); + return SOFTBUS_NETWORK_HEARTBEAT_SEND_ERR; + } + return SOFTBUS_OK; +} + int32_t LnnStartHeartbeat(uint64_t delayMillis) { LNN_LOGI(LNN_HEART_BEAT, "heartbeat(HB) process start delay=%{public}" PRIu64 "msec", delayMillis); diff --git a/core/bus_center/lnn/lane_hub/heartbeat/src/lnn_heartbeat_utils.c b/core/bus_center/lnn/lane_hub/heartbeat/src/lnn_heartbeat_utils.c index 1c0b0b1d0a659a1aa8a59781176dc65b99891e75..30cd7d9c8d1d54ad2125714e4cde0d219ecc6ed8 100644 --- a/core/bus_center/lnn/lane_hub/heartbeat/src/lnn_heartbeat_utils.c +++ b/core/bus_center/lnn/lane_hub/heartbeat/src/lnn_heartbeat_utils.c @@ -595,3 +595,8 @@ bool LnnIsMultiDeviceOnline(void) return GetOnlineInfoNum(&onlineNum) == SOFTBUS_OK && onlineNum >= HB_MULTI_DEVICE_THRESHOLD; } + +bool LnnIsSupportHeartbeatCap(uint32_t hbCapacity, HeartbeatCapability capaBit) +{ + return ((hbCapacity & (1 << (uint32_t) capaBit)) != 0); +} \ No newline at end of file diff --git a/core/bus_center/lnn/lane_hub/lane_manager/src/lnn_lane_link_p2p.c b/core/bus_center/lnn/lane_hub/lane_manager/src/lnn_lane_link_p2p.c index a44c0c4ed67531866f79298eb9b3c7a8c1b13969..92e9301c562376d5f58a59a5c5024a5fc7c4018c 100644 --- a/core/bus_center/lnn/lane_hub/lane_manager/src/lnn_lane_link_p2p.c +++ b/core/bus_center/lnn/lane_hub/lane_manager/src/lnn_lane_link_p2p.c @@ -150,11 +150,12 @@ static SoftBusHandler g_guideChannelHandler; static ListNode *g_authSessionServerList = NULL; static SoftBusMutex g_AuthTagLock; -#define INVAILD_AUTH_ID (-1) -#define INVALID_P2P_REQUEST_ID (-1) -#define LANE_REQ_ID_TYPE_SHIFT 28 +#define INVAILD_AUTH_ID (-1) +#define INVALID_P2P_REQUEST_ID (-1) +#define LANE_REQ_ID_TYPE_SHIFT 28 #define SHORT_RANGE_PTK_NOT_MATCH_CODE 4 -#define SOFTBUS_LNN_PTK_NOT_MATCH (SOFTBUS_ERRNO(SHORT_DISTANCE_MAPPING_MODULE_CODE) + SHORT_RANGE_PTK_NOT_MATCH_CODE) +#define BLE_TRIGGER_TIMEOUT 3000 +#define SOFTBUS_LNN_PTK_NOT_MATCH (SOFTBUS_ERRNO(SHORT_DISTANCE_MAPPING_MODULE_CODE) + SHORT_RANGE_PTK_NOT_MATCH_CODE) typedef int32_t (*GuideLinkByType)(const LinkRequest *request, uint32_t laneReqId, const LaneLinkCb *callback); @@ -1102,6 +1103,17 @@ static void HandleGuideChannelAsyncFail(AsyncResultType type, uint32_t requestId HandleGuideChannelRetry(laneReqId, linkType, reason); } +static int32_t GetCurrentGuideType(uint32_t laneReqId, LaneLinkType linkType, WdGuideType *guideType) +{ + WdGuideInfo guideInfo = {0}; + if (GetGuideInfo(laneReqId, linkType, &guideInfo) != SOFTBUS_OK) { + LNN_LOGE(LNN_LANE, "get guide channel info fail."); + return SOFTBUS_LANE_NOT_FOUND; + } + *guideType = guideInfo.guideList[guideInfo.guideIdx]; + return SOFTBUS_OK; +} + static int32_t HandleWifiDirectConflict(uint32_t p2pRequestId, LinkConflictType conflictType) { P2pLinkReqList reqInfo; @@ -1119,6 +1131,26 @@ static int32_t HandleWifiDirectConflict(uint32_t p2pRequestId, LinkConflictType return SOFTBUS_OK; } +static void HandleActionTriggerError(uint32_t p2pRequestId) +{ + P2pLinkReqList reqInfo = { 0 }; + if (GetP2pLinkReqByReqId(ASYNC_RESULT_P2P, p2pRequestId, &reqInfo) != SOFTBUS_OK) { + LNN_LOGE(LNN_LANE, "get p2pLinkReq fail, type=%{public}d, requestId=%{public}u", + ASYNC_RESULT_P2P, p2pRequestId); + return; + } + WdGuideType guideType = LANE_CHANNEL_BUTT; + if (GetCurrentGuideType(reqInfo.laneRequestInfo.laneReqId, reqInfo.laneRequestInfo.linkType, + &guideType) != SOFTBUS_OK) { + LNN_LOGE(LNN_LANE, "GetCurrentGuideType fail"); + return; + } + LNN_LOGI(LNN_LANE, "current guideType=%{public}d", guideType); + if (guideType == LANE_ACTION_TRIGGER || guideType == LANE_BLE_TRIGGER) { + (void)LnnRequestCheckOnlineStatus(reqInfo.laneRequestInfo.networkId, BLE_TRIGGER_TIMEOUT); + } +} + static void OnWifiDirectConnectFailure(uint32_t p2pRequestId, int32_t reason) { LNN_LOGI(LNN_LANE, "wifidirect conn fail, requestId=%{public}u, reason=%{public}d", p2pRequestId, reason); @@ -1144,6 +1176,9 @@ static void OnWifiDirectConnectFailure(uint32_t p2pRequestId, int32_t reason) HandleGuideChannelAsyncFail(ASYNC_RESULT_P2P, p2pRequestId, reason); return; } + if (reason == SOFTBUS_CONN_CONNECT_GROUP_TIMEOUT || reason == SOFTBUS_CONN_HV2_BLE_TRIGGER_TIMEOUT) { + HandleActionTriggerError(p2pRequestId); + } LinkConflictType conflictType = GetConflictTypeWithErrcode(reason); if (conflictType == CONFLICT_THREE_VAP || conflictType == CONFLICT_ROLE || conflictType == CONFLICT_LINK_NUM_LIMITED) { @@ -1644,17 +1679,6 @@ static int32_t GetPreferAuthByType(const char *networkId, AuthLinkType type, Aut return AuthGetConnInfoByType(uuid, type, connInfo, isMetaAuth); } -static int32_t GetCurrentGuideType(uint32_t laneReqId, LaneLinkType linkType, WdGuideType *guideType) -{ - WdGuideInfo guideInfo = {0}; - if (GetGuideInfo(laneReqId, linkType, &guideInfo) != SOFTBUS_OK) { - LNN_LOGE(LNN_LANE, "get guide channel info fail."); - return SOFTBUS_LANE_NOT_FOUND; - } - *guideType = guideInfo.guideList[guideInfo.guideIdx]; - return SOFTBUS_OK; -} - static int32_t GetAuthConnInfoWithoutMeta(const LinkRequest *request, uint32_t laneReqId, AuthConnInfo *connInfo, bool isMetaAuth) { diff --git a/core/bus_center/lnn/net_builder/include/lnn_data_cloud_sync.h b/core/bus_center/lnn/net_builder/include/lnn_data_cloud_sync.h index 85061f5891f33fbcfdd8d4c02cb2143fabdbf95a..531d6ef4b69d5b76f1ed41a35c048bfe17a70698 100644 --- a/core/bus_center/lnn/net_builder/include/lnn_data_cloud_sync.h +++ b/core/bus_center/lnn/net_builder/include/lnn_data_cloud_sync.h @@ -48,6 +48,7 @@ typedef struct { uint64_t feature; uint64_t connSubFeature; uint32_t authCapacity; + uint32_t heartbeatCapacity; int32_t osType; char osVersion[OS_VERSION_BUF_LEN]; int32_t stateVersion; diff --git a/core/bus_center/lnn/net_builder/include/lnn_device_info_recovery.h b/core/bus_center/lnn/net_builder/include/lnn_device_info_recovery.h index 80633f6c57f7de2d6fef8d5c82f614acc8ff3c02..9e4d7133e5a047c1abe3ffd56059ce4683b57b18 100644 --- a/core/bus_center/lnn/net_builder/include/lnn_device_info_recovery.h +++ b/core/bus_center/lnn/net_builder/include/lnn_device_info_recovery.h @@ -68,6 +68,7 @@ extern "C" { #define DEVICE_INFO_CONN_CAP "CONN_CAP" #define DEVICE_INFO_NEW_CONN_CAP "NEW_CONN_CAP" #define DEVICE_INFO_AUTH_CAP "AUTH_CAP" +#define DEVICE_INFO_HB_CAP "HB_CAP" #define DEVICE_INFO_EXTDATA "EXTDATA" #define DEVICE_INFO_STATE_VERSION "STATE_VERSION" #define DEVICE_INFO_LOCAL_STATE_VERSION "LOCAL_STATE_VERSION" diff --git a/core/bus_center/lnn/net_builder/src/lnn_data_cloud_sync.c b/core/bus_center/lnn/net_builder/src/lnn_data_cloud_sync.c index 280ca4eaed2cfc723f96224796596477a5dd0d03..239b6653dd602149d7b5d6133c460c9d4dd2a476 100644 --- a/core/bus_center/lnn/net_builder/src/lnn_data_cloud_sync.c +++ b/core/bus_center/lnn/net_builder/src/lnn_data_cloud_sync.c @@ -174,6 +174,9 @@ static int32_t DBNumInfoSyncToCache(NodeInfo *cacheInfo, char *fieldName, const } else if (strcmp(fieldName, DEVICE_INFO_AUTH_CAP) == 0) { cacheInfo->authCapacity = (uint32_t)atoi(value); LNN_LOGI(LNN_BUILDER, "success. authCapacity=%{public}u", cacheInfo->authCapacity); + } else if (strcmp(fieldName, DEVICE_INFO_HB_CAP) == 0) { + cacheInfo->heartbeatCapacity = (uint32_t)atoi(value); + LNN_LOGI(LNN_BUILDER, "success. heartbeatCapacity=%{public}u", cacheInfo->heartbeatCapacity); } LNN_LOGD(LNN_BUILDER, "success."); return SOFTBUS_OK; @@ -761,15 +764,15 @@ static void PrintSyncNodeInfo(const NodeInfo *cacheInfo) "Sync NodeInfo: WIFI_VERSION=%{public}" PRId64 ", BLE_VERSION=%{public}" PRId64 ", ACCOUNT_ID=%{public}s, TRANSPORT_PROTOCOL=%{public}" PRIu64 ", FEATURE=%{public}" PRIu64 ", CONN_SUB_FEATURE=%{public}" PRIu64 ", TIMESTAMP=%{public}" PRIu64 ", " - "P2P_MAC_ADDR=%{public}s, PKG_VERSION=%{public}s, DEVICE_NAME=%{public}s, " - "AUTH_CAP=%{public}u, OS_TYPE=%{public}d, OS_VERSION=%{public}s, BLE_P2P=%{public}d, BT_MAC=%{public}s, " + "P2P_MAC_ADDR=%{public}s, PKG_VERSION=%{public}s, DEVICE_NAME=%{public}s, AUTH_CAP=%{public}u, " + "HB_CAP=%{public}u, OS_TYPE=%{public}d, OS_VERSION=%{public}s, BLE_P2P=%{public}d, BT_MAC=%{public}s, " "DEVICE_TYPE=%{public}d, SW_VERSION=%{public}s, DEVICE_UDID=%{public}s, DEVICE_UUID=%{public}s, " "NETWORK_ID=%{public}s, STATE_VERSION=%{public}d, BROADCAST_CIPHER_KEY=%{public}02x, " "BROADCAST_CIPHER_IV=%{public}02x, IRK=%{public}02x, PUB_MAC=%{public}02x, PTK=%{public}02x, " "DEVICE_VERSION=%{public}s", cacheInfo->wifiVersion, cacheInfo->bleVersion, AnonymizeWrapper(anonyAccountId), cacheInfo->supportedProtocols, cacheInfo->feature, cacheInfo->connSubFeature, cacheInfo->updateTimestamp, anonyP2pMac, cacheInfo->pkgVersion, - anonyDeviceName, cacheInfo->authCapacity, cacheInfo->deviceInfo.osType, + anonyDeviceName, cacheInfo->authCapacity, cacheInfo->heartbeatCapacity, cacheInfo->deviceInfo.osType, cacheInfo->deviceInfo.osVersion, cacheInfo->isBleP2p, anonyMacAddr, cacheInfo->deviceInfo.deviceTypeId, cacheInfo->softBusVersion, anonyUdid, anonyUuid, anonyNetworkId, cacheInfo->stateVersion, *cacheInfo->cipherInfo.key, *cacheInfo->cipherInfo.iv, *cacheInfo->rpaInfo.peerIrk, diff --git a/core/bus_center/lnn/net_ledger/common/include/lnn_node_info.h b/core/bus_center/lnn/net_ledger/common/include/lnn_node_info.h index 69325c0b63411e86192c0520bb41885f0638662c..a040c193581537964c5b6e1fab8cae01506731e0 100644 --- a/core/bus_center/lnn/net_ledger/common/include/lnn_node_info.h +++ b/core/bus_center/lnn/net_ledger/common/include/lnn_node_info.h @@ -142,6 +142,7 @@ typedef struct { ConnectStatus status; uint32_t netCapacity; uint32_t authCapacity; + uint32_t heartbeatCapacity; uint32_t discoveryType; DeviceBasicInfo deviceInfo; ConnectInfo connectInfo; diff --git a/core/bus_center/lnn/net_ledger/local_ledger/src/lnn_local_net_ledger.c b/core/bus_center/lnn/net_ledger/local_ledger/src/lnn_local_net_ledger.c index 5d7d69dc78391e7a40270ff4a8c538c6c3fc0039..31955989b3f4b2d05b0126b3d6c90c9934d1f180 100644 --- a/core/bus_center/lnn/net_ledger/local_ledger/src/lnn_local_net_ledger.c +++ b/core/bus_center/lnn/net_ledger/local_ledger/src/lnn_local_net_ledger.c @@ -47,6 +47,7 @@ #define SOFTBUS_BUSCENTER_DUMP_LOCALDEVICEINFO "local_device_info" #define ALL_GROUP_TYPE 0xF #define MAX_STATE_VERSION 0xFF +#define DEFAULT_SUPPORT_HBCAPACITY 0x1 #define DEFAULT_CONN_SUB_FEATURE 1 #define CACHE_KEY_LENGTH 32 #define STATE_VERSION_VALUE_LENGTH 8 @@ -2210,6 +2211,7 @@ int32_t LnnInitLocalLedger(void) } nodeInfo->groupType = ALL_GROUP_TYPE; nodeInfo->discoveryType = 0; + nodeInfo->heartbeatCapacity = DEFAULT_SUPPORT_HBCAPACITY; nodeInfo->netCapacity = LnnGetNetCapabilty(); nodeInfo->authCapacity = GetAuthCapacity(); nodeInfo->feature = LnnGetFeatureCapabilty(); diff --git a/interfaces/kits/common/softbus_error_code.h b/interfaces/kits/common/softbus_error_code.h index 13bbfcb023601a25e65f67ad5655b144b0db3979..edb203c4268a486a2c07d79c661b7fe2a3fd3c0b 100644 --- a/interfaces/kits/common/softbus_error_code.h +++ b/interfaces/kits/common/softbus_error_code.h @@ -527,6 +527,9 @@ enum SoftBusErrNo { SOFTBUS_NETWORK_READINT32_FAILED, SOFTBUS_NETWORK_SEND_REQUEST_FAILED, SOFTBUS_NETWORK_REJECT_REQUEST, + SOFTBUS_NETWORK_HEARTBEAT_SEND_ERR, + SOFTBUS_NETWORK_HEARTBEAT_DIRECT, + SOFTBUS_NETWORK_NOT_SUPPORT, /* errno begin: -((203 << 21) | (4 << 16) | (1 << 12) | 0x0FFF) */ SOFTBUS_LANE_ERR_BASE = SOFTBUS_SUB_ERRNO(LNN_SUB_MODULE_CODE, LNN_LANE_MODULE_CODE), diff --git a/tests/core/bus_center/lnn/lane/include/lnn_lane_deps_mock.h b/tests/core/bus_center/lnn/lane/include/lnn_lane_deps_mock.h index 0040263526c18e229688effcac61106f95f355da..6b31aec6171c432d027ed4fdd17b9799327bb35a 100644 --- a/tests/core/bus_center/lnn/lane/include/lnn_lane_deps_mock.h +++ b/tests/core/bus_center/lnn/lane/include/lnn_lane_deps_mock.h @@ -113,6 +113,7 @@ public: virtual int SoftBusGetBtState() = 0; virtual int32_t LnnGetAllOnlineNodeInfo(NodeBasicInfo **info, int32_t *infoNum) = 0; virtual void AddNetworkResource(NetworkResource *networkResource) = 0; + virtual int32_t LnnRequestCheckOnlineStatus(const char *networkId, uint64_t timeout) = 0; }; class LaneDepsInterfaceMock : public LaneDepsInterface { @@ -177,6 +178,7 @@ public: MOCK_METHOD0(SoftBusGetBtState, int (void)); MOCK_METHOD2(LnnGetAllOnlineNodeInfo, int32_t (NodeBasicInfo **info, int32_t *infoNum)); MOCK_METHOD1(AddNetworkResource, void (NetworkResource *)); + MOCK_METHOD2(LnnRequestCheckOnlineStatus, int32_t (const char *networkId, uint64_t timeout)); void SetDefaultResult(NodeInfo *info); void SetDefaultResultForAlloc(int32_t localNetCap, int32_t remoteNetCap, int32_t localFeatureCap, int32_t remoteFeatureCap); diff --git a/tests/core/bus_center/lnn/lane/src/lnn_lane_deps_mock.cpp b/tests/core/bus_center/lnn/lane/src/lnn_lane_deps_mock.cpp index b637c15d338ada4141abf1e46fd7a576bac5ad7b..4805744687de297ed2ea3029398ec683a25c86ca 100644 --- a/tests/core/bus_center/lnn/lane/src/lnn_lane_deps_mock.cpp +++ b/tests/core/bus_center/lnn/lane/src/lnn_lane_deps_mock.cpp @@ -440,5 +440,10 @@ void AddNetworkResource(NetworkResource *networkResource) { return GetLaneDepsInterface()->AddNetworkResource(networkResource); } + +int32_t LnnRequestCheckOnlineStatus(const char *networkId, uint64_t timeout) +{ + return GetLaneDepsInterface()->LnnRequestCheckOnlineStatus(networkId, timeout); +} } } // namespace OHOS \ No newline at end of file diff --git a/tests/core/bus_center/test/BUILD.gn b/tests/core/bus_center/test/BUILD.gn index d553e9ed03b322475cf93d22583396b52aafa002..13c1dcefc309a7acff02b9305f92319d3ef50b3c 100644 --- a/tests/core/bus_center/test/BUILD.gn +++ b/tests/core/bus_center/test/BUILD.gn @@ -205,6 +205,7 @@ ohos_unittest("HeartBeatStrategyTest") { "$dsoftbus_root_path/core/bus_center/lnn/net_buscenter/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/local_ledger/include", "$dsoftbus_root_path/core/bus_center/utils/include", "$dsoftbus_root_path/core/discovery/interface", "$dsoftbus_root_path/core/discovery/manager/include", diff --git a/tests/core/bus_center/test/heartbeat/hb_fsm_test.cpp b/tests/core/bus_center/test/heartbeat/hb_fsm_test.cpp index a16d349a46819f30b73d112248a16c476452ac41..f714e06e062defdcc17bebb7d88065938a626770 100644 --- a/tests/core/bus_center/test/heartbeat/hb_fsm_test.cpp +++ b/tests/core/bus_center/test/heartbeat/hb_fsm_test.cpp @@ -40,6 +40,7 @@ namespace OHOS { #define TEST_TIME1 450 #define TEST_TIME2 500 #define TEST_TIME3 2000000 +#define CHECK_DELAY_LEN 10000 constexpr int32_t MSGTYPE = 2; using namespace testing::ext; using namespace testing; @@ -426,15 +427,15 @@ HWTEST_F(HeartBeatFSMTest, IsTimestampExceedLimitTest_01, TestSize.Level1) EXPECT_CALL(heartbeatFsmMock, LnnGetGearModeBySpecificType) .WillOnce(Return(SOFTBUS_ERR)) .WillRepeatedly(Return(SOFTBUS_OK)); - bool ret = IsTimestampExceedLimit(TEST_TIME2, TEST_TIME1, HEARTBEAT_TYPE_BLE_V0); + bool ret = IsTimestampExceedLimit(TEST_TIME2, TEST_TIME1, HEARTBEAT_TYPE_BLE_V0, CHECK_DELAY_LEN); EXPECT_FALSE(ret); - ret = IsTimestampExceedLimit(TEST_TIME3, TEST_TIME1, HEARTBEAT_TYPE_BLE_V0); + ret = IsTimestampExceedLimit(TEST_TIME3, TEST_TIME1, HEARTBEAT_TYPE_BLE_V0, CHECK_DELAY_LEN); EXPECT_TRUE(ret); - ret = IsTimestampExceedLimit(TEST_TIME2, TEST_TIME1, HEARTBEAT_TYPE_BLE_V1); + ret = IsTimestampExceedLimit(TEST_TIME2, TEST_TIME1, HEARTBEAT_TYPE_BLE_V1, CHECK_DELAY_LEN); EXPECT_FALSE(ret); - ret = IsTimestampExceedLimit(TEST_TIME2, TEST_TIME1, HEARTBEAT_TYPE_BLE_V1); + ret = IsTimestampExceedLimit(TEST_TIME2, TEST_TIME1, HEARTBEAT_TYPE_BLE_V1, CHECK_DELAY_LEN); EXPECT_FALSE(ret); - ret = IsTimestampExceedLimit(TEST_TIME3, TEST_TIME1, HEARTBEAT_TYPE_BLE_V1); + ret = IsTimestampExceedLimit(TEST_TIME3, TEST_TIME1, HEARTBEAT_TYPE_BLE_V1, CHECK_DELAY_LEN); EXPECT_TRUE(ret); } diff --git a/tests/core/bus_center/test/heartbeat/hb_medium_mgr_test.cpp b/tests/core/bus_center/test/heartbeat/hb_medium_mgr_test.cpp index 7852efac41b0e9c644ed510c9b46d730e789270f..99e00dbc0de00165fc93bd0b9657df36403c0ef3 100644 --- a/tests/core/bus_center/test/heartbeat/hb_medium_mgr_test.cpp +++ b/tests/core/bus_center/test/heartbeat/hb_medium_mgr_test.cpp @@ -846,11 +846,11 @@ HWTEST_F(HeartBeatMediumTest, SoftBusNetNodeResult_TEST01, TestSize.Level1) .WillOnce(Return(SOFTBUS_ERR)) .WillRepeatedly(Return(SOFTBUS_OK)); EXPECT_CALL(heartBeatMock, IsExistLnnDfxNodeByUdidHash).WillRepeatedly(Return(true)); - int32_t ret = SoftBusNetNodeResult(&device, &hbResp, false, connectReason); + int32_t ret = SoftBusNetNodeResult(&device, &hbResp, false, connectReason, false); EXPECT_TRUE(ret == SOFTBUS_ERR); - ret = SoftBusNetNodeResult(&device, &hbResp, false, connectReason); + ret = SoftBusNetNodeResult(&device, &hbResp, false, connectReason, false); EXPECT_TRUE(ret == SOFTBUS_NETWORK_NODE_DIRECT_ONLINE); - ret = SoftBusNetNodeResult(&device, &hbResp, true, connectReason); + ret = SoftBusNetNodeResult(&device, &hbResp, true, connectReason, false); EXPECT_TRUE(ret == SOFTBUS_NETWORK_NODE_OFFLINE); }