!6201 同步代码

Merge pull request !6201 from 范妮娜/master
This commit is contained in:
openharmony_ci 2024-05-24 06:53:13 +00:00 committed by Gitee
commit 0c217aee4c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
29 changed files with 992 additions and 631 deletions

View File

@ -181,8 +181,7 @@ int32_t AuthGetLatestAuthSeqListByType(const char *udid, int64_t *seqList, uint6
DiscoveryType type);
/* for ProxyChannel & P2P TcpDirectchannel */
void AuthGetLatestIdByUuid(const char *uuid, AuthLinkType type, bool isMeta, AuthHandle *authHandle);
int32_t AuthGetAuthHandleByIndex(const AuthConnInfo *connInfo, bool isServer, int32_t index,
AuthHandle *authHandle);
int32_t AuthGetAuthHandleByIndex(const AuthConnInfo *connInfo, bool isServer, int32_t index, AuthHandle *authHandle);
int64_t AuthGetIdByConnInfo(const AuthConnInfo *connInfo, bool isServer, bool isMeta);
int64_t AuthGetIdByUuid(const char *uuid, AuthLinkType type, bool isServer, bool isMeta);

View File

@ -260,6 +260,7 @@ void AuthCloseConn(AuthHandle authHandle)
}
AuthMetaCloseConn(authHandle.authId);
}
int32_t AuthAllocConn(const char *networkId, uint32_t authRequestId, AuthConnCallback *callback)
{
if (networkId == NULL || callback == NULL) {

View File

@ -1505,7 +1505,6 @@ static int32_t GetUdidShortHash(const AuthConnInfo *connInfo, char *udidBuf, uin
return SOFTBUS_OK;
}
static void DfxRecordLnnConnectEnd(uint32_t requestId, uint64_t connId, const AuthConnInfo *connInfo, int32_t reason)
{
LnnEventExtra extra = { 0 };
@ -1997,8 +1996,8 @@ void AuthHandleLeaveLNN(AuthHandle authHandle)
if (auth->connInfo[authHandle.type].type == AUTH_LINK_TYPE_WIFI) {
DisconnectAuthDevice(&auth->connId[authHandle.type]);
}
DelAuthManager(auth, authHandle.type);
AuthFreeConn(&authHandle);
DelAuthManager(auth, authHandle.type);
ReleaseAuthLock();
}
@ -2169,11 +2168,6 @@ int32_t GetAuthLinkTypeList(const char *networkId, AuthLinkTypeList *linkTypeLis
AUTH_LOGE(AUTH_CONN, "get peer uuid fail");
return SOFTBUS_ERR;
}
char udid[UDID_BUF_LEN] = {0};
if (LnnGetRemoteStrInfo(networkId, STRING_KEY_DEV_UDID, udid, UDID_BUF_LEN) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_CONN, "get peer udid fail");
return SOFTBUS_ERR;
}
AuthLinkType linkList[] = {AUTH_LINK_TYPE_ENHANCED_P2P, AUTH_LINK_TYPE_WIFI,
AUTH_LINK_TYPE_P2P, AUTH_LINK_TYPE_BR, AUTH_LINK_TYPE_BLE};
AuthConnInfo connInfo;
@ -2186,12 +2180,8 @@ int32_t GetAuthLinkTypeList(const char *networkId, AuthLinkTypeList *linkTypeLis
if (GetAuthConnInfoByUuid(uuid, linkList[i], &connInfo) != SOFTBUS_OK) {
continue;
}
if (linkList[i] == AUTH_LINK_TYPE_ENHANCED_P2P || linkList[i] == AUTH_LINK_TYPE_P2P) {
if (!IsAuthReuseP2p(networkId, udid, linkList[i])) {
continue;
}
}
if (linkList[i] == AUTH_LINK_TYPE_BLE && !CheckActiveAuthConnection(&connInfo)) {
if ((linkList[i] == AUTH_LINK_TYPE_BLE || linkList[i] == AUTH_LINK_TYPE_BR) &&
!CheckActiveAuthConnection(&connInfo)) {
AUTH_LOGI(AUTH_CONN, "auth ble connection not active");
continue;
}
@ -2200,6 +2190,11 @@ int32_t GetAuthLinkTypeList(const char *networkId, AuthLinkTypeList *linkTypeLis
linkTypeList->linkTypeNum++;
}
if (linkTypeList->linkTypeNum == 0) {
if (TryGetBrConnInfo(uuid, &connInfo) == SOFTBUS_OK) {
linkTypeList->linkType[linkTypeList->linkTypeNum] = AUTH_LINK_TYPE_BR;
linkTypeList->linkTypeNum++;
return SOFTBUS_OK;
}
AUTH_LOGE(AUTH_CONN, "no available auth link");
return SOFTBUS_ERR;
}
@ -3057,7 +3052,8 @@ static void AuthOnLaneAllocSuccess(uint32_t laneHandle, const LaneConnInfo *lane
AUTH_LOGE(AUTH_CONN, "memset_s authConnInfo fail");
return;
}
if (GetAuthConn(uuid, laneConnInfo->type, &authConnInfo) != SOFTBUS_OK) {
if (GetAuthConn(uuid, laneConnInfo->type, &authConnInfo) != SOFTBUS_OK &&
laneConnInfo->type == LANE_BR && TryGetBrConnInfo(uuid, &authConnInfo) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_CONN, "GetAuthConn fail");
return;
}
@ -3100,7 +3096,7 @@ static void AuthOnLaneAllocFail(uint32_t laneHandle, int32_t reason)
}
}
static int32_t AuthGetRequestOption(const char *networkId, LaneAllocInfo *allocInfo)
static int32_t AuthGetLaneAllocInfo(const char *networkId, LaneAllocInfo *allocInfo)
{
if (networkId == NULL || allocInfo == NULL) {
AUTH_LOGE(AUTH_CONN, "param invalid");
@ -3160,7 +3156,7 @@ int32_t AuthAllocLane(const char *networkId, uint32_t authRequestId, AuthConnCal
return SOFTBUS_MEM_ERR;
}
if (AuthGetRequestOption(networkId, &allocInfo) != SOFTBUS_OK) {
if (AuthGetLaneAllocInfo(networkId, &allocInfo) != SOFTBUS_OK) {
AUTH_LOGE(AUTH_CONN, "auth get requestOption fail");
GetLaneManager()->lnnFreeLane(laneHandle);
return SOFTBUS_ERR;

View File

@ -24,7 +24,6 @@
extern "C" {
#endif
int32_t ConvertAuthLinkToLaneLink(AuthLinkTypeList *authLinkType, LanePreferredLinkList *laneLinkType);
LaneInterface *CtrlLaneGetInstance(void);
bool IsAuthReuseP2p(const char *networkId, const char *udid, AuthLinkType authType);

View File

@ -34,6 +34,7 @@ typedef struct {
int32_t (*cancelLane)(uint32_t laneHandle);
int32_t (*freeLane)(uint32_t laneHandle);
} LaneInterface;
#ifdef __cplusplus
}
#endif

View File

@ -122,7 +122,7 @@ int32_t FindLaneResourceByLinkType(const char *peerUdid, LaneLinkType type, Lane
int32_t AddLaneResourceToPool(const LaneLinkInfo *linkInfo, uint64_t laneId, bool isServerSide);
int32_t DelLaneResourceByLaneId(uint64_t laneId, bool isServerSide);
int32_t FindLaneResourceByLaneId(uint64_t laneId, LaneResource *resource);
uint64_t ApplyLaneId(const char *localUdid, const char *remoteUdid, LaneLinkType linkType);
uint64_t GenerateLaneId(const char *localUdid, const char *remoteUdid, LaneLinkType linkType);
int32_t ClearLaneResourceByLaneId(uint64_t laneId);
#ifdef __cplusplus

View File

@ -50,9 +50,6 @@ int32_t PostLaneStateChangeMessage(LaneState state, const char *peerUdid, const
void RemoveDelayDestroyMessage(uint64_t laneId);
void DelLogicAndLaneRelationship(uint64_t laneId);
int32_t CtrlFree(uint32_t laneHandle);
int32_t CtrlAlloc(uint32_t laneHandle, const LaneAllocInfo *allocInfo, const LaneAllocListener *listener);
#ifdef __cplusplus
}
#endif

View File

@ -18,24 +18,46 @@
#include <securec.h>
#include "auth_interface.h"
#include "bus_center_manager.h"
#include "lnn_lane_common.h"
#include "lnn_lane_interface.h"
#include "lnn_log.h"
#include "lnn_trans_lane.h"
#include "lnn_lane_select.h"
#include "softbus_adapter_mem.h"
#include "softbus_errcode.h"
#include "wifi_direct_manager.h"
static LaneInterface g_ctrlLaneObject = {
.allocLaneByQos = CtrlAlloc,
.freeLane = CtrlFree,
};
typedef struct {
ListNode node;
uint32_t laneHandle;
uint64_t laneId;
uint32_t linkListIdx;
LaneAllocInfo allocInfo;
LanePreferredLinkList linkList;
LaneAllocListener listener;
} CtrlReqInfo;
LaneInterface *CtrlLaneGetInstance(void)
typedef struct {
uint32_t cnt;
ListNode list;
} CtrlLaneList;
static SoftBusMutex g_ctrlLaneMutex;
static CtrlLaneList *g_ctrlReqList = NULL;
static int32_t CtrlTriggerLink(uint32_t laneHandle);
static int32_t Lock(void)
{
return &g_ctrlLaneObject;
return SoftBusMutexLock(&g_ctrlLaneMutex);
}
int32_t ConvertAuthLinkToLaneLink(AuthLinkTypeList *authLinkType, LanePreferredLinkList *laneLinkType)
static void Unlock(void)
{
(void)SoftBusMutexUnlock(&g_ctrlLaneMutex);
}
static int32_t ConvertAuthLinkToLaneLink(AuthLinkTypeList *authLinkType, LanePreferredLinkList *laneLinkType)
{
if (authLinkType == NULL || laneLinkType == NULL) {
LNN_LOGE(LNN_LANE, "param invalid");
@ -45,8 +67,8 @@ int32_t ConvertAuthLinkToLaneLink(AuthLinkTypeList *authLinkType, LanePreferredL
for (uint32_t i = 0; i < authLinkType->linkTypeNum; ++i) {
switch (authLinkType->linkType[i]) {
case AUTH_LINK_TYPE_WIFI:
laneLinkType->linkType[laneLinkType->linkTypeNum++] = LANE_WLAN_2P4G;
laneLinkType->linkType[laneLinkType->linkTypeNum++] = LANE_WLAN_5G;
laneLinkType->linkType[laneLinkType->linkTypeNum++] = LANE_WLAN_2P4G;
break;
case AUTH_LINK_TYPE_BR:
laneLinkType->linkType[laneLinkType->linkTypeNum++] = LANE_BR;
@ -85,4 +107,383 @@ bool IsAuthReuseP2p(const char *networkId, const char *udid, AuthLinkType authTy
} else {
return false;
}
}
static int32_t GetCtrlReqInfo(uint32_t laneHandle, CtrlReqInfo *reqInfo)
{
if (reqInfo == NULL || laneHandle == INVALID_LANE_REQ_ID) {
return SOFTBUS_INVALID_PARAM;
}
if (Lock() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get lock fail");
return SOFTBUS_LOCK_ERR;
}
CtrlReqInfo *item = NULL;
LIST_FOR_EACH_ENTRY(item, &g_ctrlReqList->list, CtrlReqInfo, node) {
if (item->laneHandle == laneHandle) {
if (memcpy_s(reqInfo, sizeof(CtrlReqInfo), item, sizeof(CtrlReqInfo)) != EOK) {
LNN_LOGE(LNN_LANE, "memcpy CtrlReqInfo fail");
Unlock();
return SOFTBUS_MEM_ERR;
}
Unlock();
return SOFTBUS_OK;
}
}
Unlock();
return SOFTBUS_ERR;
}
static void DeleteCtrlRequestNode(uint32_t laneHandle)
{
if (Lock() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get lock fail");
return;
}
CtrlReqInfo *item = NULL;
CtrlReqInfo *next = NULL;
LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_ctrlReqList->list, CtrlReqInfo, node) {
if (item->laneHandle == laneHandle) {
ListDelete(&item->node);
SoftBusFree(item);
g_ctrlReqList->cnt--;
break;
}
}
Unlock();
}
static void CtrlLinkFail(uint32_t laneHandle, int32_t reason, LaneLinkType linkType)
{
(void)linkType;
CtrlReqInfo reqInfo;
(void)memset_s(&reqInfo, sizeof(CtrlReqInfo), 0, sizeof(CtrlReqInfo));
if (GetCtrlReqInfo(laneHandle, &reqInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get lane reqInfo fail");
return;
}
if (reqInfo.linkListIdx >= reqInfo.linkList.linkTypeNum) {
reqInfo.listener.onLaneAllocFail(laneHandle, reason);
FreeLaneReqId(laneHandle);
DeleteCtrlRequestNode(laneHandle);
return;
}
CtrlTriggerLink(laneHandle);
}
static void UpdateCtrlReqInfo(uint32_t laneHandle, uint64_t laneId)
{
if (Lock() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get lock fail");
return;
}
CtrlReqInfo *item = NULL;
LIST_FOR_EACH_ENTRY(item, &g_ctrlReqList->list, CtrlReqInfo, node) {
if (item->laneHandle == laneHandle) {
item->laneId = laneId;
Unlock();
return;
}
}
Unlock();
}
static void CtrlNotifyLaneAllocSuccess(uint32_t laneHandle, uint64_t laneId, const LaneLinkInfo *info)
{
UpdateCtrlReqInfo(laneHandle, laneId);
CtrlReqInfo reqInfo;
(void)memset_s(&reqInfo, sizeof(CtrlReqInfo), 0, sizeof(CtrlReqInfo));
if (GetCtrlReqInfo(laneHandle, &reqInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get lane reqInfo fail");
return;
}
LaneProfile profile;
LaneConnInfo connInfo;
(void)memset_s(&profile, sizeof(LaneProfile), 0, sizeof(LaneProfile));
if (LaneInfoProcess(info, &connInfo, &profile) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "lane alloc success, but laneInfo proc fail");
return;
}
LNN_LOGI(LNN_LANE, "ctrl notify laneAlloc succ, laneHandle=%{public}u, linkType=%{public}d, "
"laneId=%{public}" PRIu64 "", laneHandle, info->type, laneId);
connInfo.laneId = laneId;
reqInfo.listener.onLaneAllocSuccess(laneHandle, &connInfo);
}
static void CtrlLinkSuccess(uint32_t laneHandle, LaneLinkType linkType, const LaneLinkInfo *linkInfo)
{
if (linkInfo == NULL) {
LNN_LOGE(LNN_LANE, "linkSuccess param invalid");
return;
}
char localUdid[UDID_BUF_LEN] = {0};
if (LnnGetLocalStrInfo(STRING_KEY_DEV_UDID, localUdid, UDID_BUF_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get udid fail, laneHandle=%{public}u", laneHandle);
CtrlLinkFail(laneHandle, SOFTBUS_ERR, linkType);
return;
}
uint64_t laneId = GenerateLaneId(localUdid, linkInfo->peerUdid, linkInfo->type);
if (laneId == INVALID_LANE_ID) {
LNN_LOGE(LNN_LANE, "generate laneId fail, laneHandle=%{public}u", laneHandle);
CtrlLinkFail(laneHandle, SOFTBUS_ERR, linkType);
return;
}
int32_t ret = AddLaneResourceToPool(linkInfo, laneId, false);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "add linkInfo item fail, laneHandle=%{public}u", laneHandle);
CtrlLinkFail(laneHandle, ret, linkType);
return;
}
CtrlNotifyLaneAllocSuccess(laneHandle, laneId, linkInfo);
}
static int32_t CreateLinkRequestNode(const LaneAllocInfo *allocInfo, LinkRequest *requestInfo)
{
requestInfo->networkDelegate = allocInfo->extendInfo.networkDelegate;
requestInfo->pid = allocInfo->pid;
requestInfo->acceptableProtocols = allocInfo->acceptableProtocols;
requestInfo->transType = allocInfo->transType;
if (memcpy_s(requestInfo->peerNetworkId, NETWORK_ID_BUF_LEN,
allocInfo->networkId, NETWORK_ID_BUF_LEN) != EOK) {
LNN_LOGE(LNN_LANE, "memcpy networkId fail");
return SOFTBUS_MEM_ERR;
}
if (memcpy_s(requestInfo->peerBleMac, MAX_MAC_LEN, allocInfo->extendInfo.peerBleMac, MAX_MAC_LEN) != EOK) {
LNN_LOGE(LNN_LANE, "memcpy peerBleMac fail");
return SOFTBUS_MEM_ERR;
}
return SOFTBUS_OK;
}
static int32_t CreateCtrlReqNode(uint32_t laneHandle, const LaneAllocInfo *allocInfo,
const LaneAllocListener *listener, LanePreferredLinkList *recommendLinkList)
{
CtrlReqInfo *newNode = (CtrlReqInfo *)SoftBusCalloc(sizeof(CtrlReqInfo));
if (newNode == NULL) {
LNN_LOGE(LNN_LANE, "malloc fail");
return SOFTBUS_MALLOC_ERR;
}
if (memcpy_s(&newNode->allocInfo, sizeof(LaneAllocInfo), allocInfo, sizeof(LaneAllocInfo)) != EOK ||
memcpy_s(&newNode->listener, sizeof(LaneAllocListener), listener, sizeof(LaneAllocListener)) != EOK ||
memcpy_s(&newNode->linkList, sizeof(LanePreferredLinkList), recommendLinkList,
sizeof(LanePreferredLinkList)) != EOK) {
LNN_LOGE(LNN_LANE, "memcpy fail for lane alloc listener");
SoftBusFree(newNode);
return SOFTBUS_MEM_ERR;
}
newNode->laneHandle = laneHandle;
newNode->linkListIdx = 0;
ListInit(&newNode->node);
if (Lock() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get lock fail");
SoftBusFree(newNode);
return SOFTBUS_LOCK_ERR;
}
ListTailInsert(&g_ctrlReqList->list, &newNode->node);
g_ctrlReqList->cnt++;
Unlock();
return SOFTBUS_OK;
}
static CtrlReqInfo *GetCtrlReqInfoWithoutLock(uint32_t laneHandle)
{
CtrlReqInfo *item = NULL;
LIST_FOR_EACH_ENTRY(item, &g_ctrlReqList->list, CtrlReqInfo, node) {
if (item->laneHandle == laneHandle) {
return item;
}
}
return NULL;
}
static int32_t CtrlTriggerLink(uint32_t laneHandle)
{
if (Lock() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get lock fail");
return SOFTBUS_LOCK_ERR;
}
CtrlReqInfo *reqInfo = GetCtrlReqInfoWithoutLock(laneHandle);
if (reqInfo == NULL) {
LNN_LOGE(LNN_LANE, "get lane reqInfo fail");
Unlock();
return SOFTBUS_ERR;
}
LaneLinkCb linkCb = {
.OnLaneLinkSuccess = CtrlLinkSuccess,
.OnLaneLinkFail = CtrlLinkFail,
};
LinkRequest requestInfo = {0};
do {
if (CreateLinkRequestNode(&reqInfo->allocInfo, &requestInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "Create LinkRequestNode fail.");
break;
}
requestInfo.linkType = reqInfo->linkList.linkType[reqInfo->linkListIdx];
reqInfo->linkListIdx++;
Unlock();
if (BuildLink(&requestInfo, laneHandle, &linkCb) == SOFTBUS_OK) {
return SOFTBUS_OK;
}
} while (false);
linkCb.OnLaneLinkFail(laneHandle, SOFTBUS_ERR, requestInfo.linkType);
return SOFTBUS_ERR;
}
static int32_t AllocCtrlLane(uint32_t laneHandle, const LaneAllocInfo *allocInfo, const LaneAllocListener *listener)
{
AuthLinkTypeList authList;
if (memset_s(&authList, sizeof(AuthLinkTypeList), 0, sizeof(AuthLinkTypeList)) != EOK) {
LNN_LOGE(LNN_LANE, "memset_s authList fail");
return SOFTBUS_ERR;
}
if (GetAuthLinkTypeList(allocInfo->networkId, &authList) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get authList fail");
return SOFTBUS_ERR;
}
LanePreferredLinkList request;
if (memset_s(&request, sizeof(LanePreferredLinkList), 0, sizeof(LanePreferredLinkList)) != EOK) {
LNN_LOGE(LNN_LANE, "memset_s request fail");
return SOFTBUS_ERR;
}
if (ConvertAuthLinkToLaneLink(&authList, &request) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "convert authLink to laneLink fail");
return SOFTBUS_ERR;
}
LanePreferredLinkList *recommendLinkList = (LanePreferredLinkList *)SoftBusCalloc(sizeof(LanePreferredLinkList));
if (recommendLinkList == NULL) {
LNN_LOGE(LNN_LANE, "calloc recommendLinkList fail");
return SOFTBUS_MALLOC_ERR;
}
recommendLinkList->linkTypeNum = 0;
if (SelectAuthLane(allocInfo->networkId, &request, recommendLinkList) != SOFTBUS_OK ||
recommendLinkList->linkTypeNum == 0) {
SoftBusFree(recommendLinkList);
LNN_LOGE(LNN_LANE, "no abailable link resources, laneHandle=%{public}u", laneHandle);
return SOFTBUS_ERR;
}
for (uint32_t i = 0; i < recommendLinkList->linkTypeNum; ++i) {
LNN_LOGI(LNN_LANE, "auth expect recommendLinkList nums=%{public}u, priority=%{public}u, link=%{public}u",
recommendLinkList->linkTypeNum, i, recommendLinkList->linkType[i]);
}
if (CreateCtrlReqNode(laneHandle, allocInfo, listener, recommendLinkList) != SOFTBUS_OK) {
SoftBusFree(recommendLinkList);
LNN_LOGE(LNN_LANE, "create ctrlReqInfo node fail.");
return SOFTBUS_ERR;
}
if (CtrlTriggerLink(laneHandle) != SOFTBUS_OK) {
SoftBusFree(recommendLinkList);
LNN_LOGE(LNN_LANE, "trigger link fail, laneHandle=%{public}u", laneHandle);
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
static int32_t CtrlAlloc(uint32_t laneHandle, const LaneAllocInfo *allocInfo, const LaneAllocListener *listener)
{
if (laneHandle == INVALID_LANE_REQ_ID || allocInfo == NULL || allocInfo->type != LANE_TYPE_CTRL) {
LNN_LOGE(LNN_LANE, "param invalid");
return SOFTBUS_INVALID_PARAM;
}
if (AllocCtrlLane(laneHandle, allocInfo, listener) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "alloc valid lane fail, laneHandle=%{public}u", laneHandle);
FreeLaneReqId(laneHandle);
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
static void CtrlInit(const ILaneIdStateListener *listener)
{
if (g_ctrlReqList != NULL) {
LNN_LOGW(LNN_LANE, "already init");
return;
}
if (SoftBusMutexInit(&g_ctrlLaneMutex, NULL) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "ctrlLane mutex init fail");
return;
}
g_ctrlReqList = (CtrlLaneList *)SoftBusCalloc(sizeof(CtrlLaneList));
if (g_ctrlReqList == NULL) {
LNN_LOGE(LNN_LANE, "ctrlLane malloc fail");
(void)SoftBusMutexDestroy(&g_ctrlLaneMutex);
return;
}
ListInit(&g_ctrlReqList->list);
}
static void CtrlDeinit(void)
{
if (g_ctrlReqList == NULL) {
return;
}
if (Lock() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get lock fail");
return;
}
CtrlReqInfo *item = NULL;
CtrlReqInfo *nextItem = NULL;
LIST_FOR_EACH_ENTRY_SAFE(item, nextItem, &g_ctrlReqList->list, CtrlReqInfo, node) {
ListDelete(&item->node);
SoftBusFree(item);
g_ctrlReqList->cnt--;
}
Unlock();
(void)SoftBusMutexDestroy(&g_ctrlLaneMutex);
SoftBusFree(g_ctrlReqList);
g_ctrlReqList = NULL;
}
static int32_t FreeLaneLink(uint32_t laneHandle, uint64_t laneId)
{
LaneResource resourceItem;
(void)memset_s(&resourceItem, sizeof(LaneResource), 0, sizeof(LaneResource));
if (FindLaneResourceByLaneId(laneId, &resourceItem) != SOFTBUS_OK) {
return SOFTBUS_ERR;
}
char networkId[NETWORK_ID_BUF_LEN] = { 0 };
if (LnnGetNetworkIdByUdid(resourceItem.link.peerUdid, networkId, sizeof(networkId)) != SOFTBUS_OK) {
return SOFTBUS_ERR;
}
DestroyLink(networkId, laneHandle, resourceItem.link.type);
DelLaneResourceByLaneId(laneId, false);
return SOFTBUS_OK;
}
static int32_t CtrlFree(uint32_t laneHandle)
{
if (Lock() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get lock fail");
return SOFTBUS_LOCK_ERR;
}
CtrlReqInfo *item = NULL;
CtrlReqInfo *next = NULL;
LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_ctrlReqList->list, CtrlReqInfo, node) {
if (item->laneHandle == laneHandle) {
ListDelete(&item->node);
g_ctrlReqList->cnt--;
Unlock();
FreeLaneLink(laneHandle, item->laneId);
SoftBusFree(item);
FreeLaneReqId(laneHandle);
return SOFTBUS_OK;
}
}
Unlock();
LNN_LOGI(LNN_LANE, "no find lane need free, laneHandle=%{public}u", laneHandle);
FreeLaneReqId(laneHandle);
return SOFTBUS_OK;
}
static LaneInterface g_ctrlLaneObject = {
.init = CtrlInit,
.allocLaneByQos = CtrlAlloc,
.freeLane = CtrlFree,
.deinit = CtrlDeinit,
};
LaneInterface *CtrlLaneGetInstance(void)
{
return &g_ctrlLaneObject;
}

View File

@ -25,18 +25,22 @@
#include "lnn_distributed_net_ledger.h"
#include "lnn_lane_assign.h"
#include "lnn_lane_common.h"
#include "lnn_lane_def.h"
#include "lnn_lane_interface.h"
#include "lnn_lane_link.h"
#include "lnn_lane_model.h"
#include "lnn_lane_query.h"
#include "lnn_lane_score.h"
#include "lnn_lane_select.h"
#include "lnn_log.h"
#include "lnn_trans_lane.h"
#include "lnn_lane_reliability.h"
#include "message_handler.h"
#include "softbus_adapter_mem.h"
#include "softbus_common.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_utils.h"
#define ID_SHIFT_STEP 5
#define ID_CALC_MASK 0x1F
@ -324,11 +328,11 @@ static int32_t LnnReAllocLane(uint32_t laneReqId, uint64_t laneId, const LaneAll
{
if (!AllocInfoCheck(allocInfo, listener)) {
LNN_LOGE(LNN_LANE, "lane realloc info invalid");
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
if (g_laneObject[allocInfo->type] == NULL) {
LNN_LOGE(LNN_LANE, "laneType is not supported. laneType=%{public}d", allocInfo->type);
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
LNN_LOGI(LNN_LANE, "realloc lane enter, laneReqId=%{public}u, laneId=%{public}" PRIu64 ", laneType=%{public}d, "
"transType=%{public}d, minBW=%{public}u, maxLaneLatency=%{public}u, minLaneLatency=%{public}u",
@ -339,6 +343,19 @@ static int32_t LnnReAllocLane(uint32_t laneReqId, uint64_t laneId, const LaneAll
int32_t result = g_laneObject[allocInfo->type]->reallocLaneByQos(laneReqId, laneId, allocInfo, listener);
if (result != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "realloc lane fail, laneReqId=%{public}u, result=%{public}d", laneReqId, result);
return result;
}
return SOFTBUS_OK;
}
static int32_t CheckLaneObject(uint32_t laneReqId, LaneType *type)
{
*type = laneReqId >> LANE_REQ_ID_TYPE_SHIFT;
if (*type >= LANE_TYPE_BUTT) {
LNN_LOGE(LNN_LANE, "laneType invalid");
return SOFTBUS_ERR;
}
if (g_laneObject[*type] == NULL) {
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
@ -346,38 +363,32 @@ static int32_t LnnReAllocLane(uint32_t laneReqId, uint64_t laneId, const LaneAll
static int32_t LnnCancelLane(uint32_t laneReqId)
{
LaneType type = laneReqId >> LANE_REQ_ID_TYPE_SHIFT;
if (type >= LANE_TYPE_BUTT) {
LaneType type;
if (CheckLaneObject(laneReqId, &type) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "laneType invalid");
return SOFTBUS_ERR;
}
if (g_laneObject[type] == NULL) {
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
LNN_LOGD(LNN_LANE, "cancel lane enter, laneReqId=%{public}u", laneReqId);
int32_t result = g_laneObject[type]->cancelLane(laneReqId);
if (result != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "freeLane fail, result=%{public}d", result);
return SOFTBUS_ERR;
LNN_LOGE(LNN_LANE, "cancelLane fail, result=%{public}d", result);
return result;
}
return SOFTBUS_OK;
}
static int32_t LnnFreeLink(uint32_t laneReqId)
{
LaneType type = laneReqId >> LANE_REQ_ID_TYPE_SHIFT;
if (type >= LANE_TYPE_BUTT) {
LaneType type;
if (CheckLaneObject(laneReqId, &type) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "laneType invalid");
return SOFTBUS_ERR;
}
if (g_laneObject[type] == NULL) {
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
LNN_LOGD(LNN_LANE, "free lane enter, laneReqId=%{public}u", laneReqId);
int32_t result = g_laneObject[type]->freeLane(laneReqId);
if (result != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "freeLane fail, result=%{public}d", result);
return SOFTBUS_ERR;
return result;
}
return SOFTBUS_OK;
}
@ -403,11 +414,11 @@ int32_t LnnRequestLane(uint32_t laneReqId, const LaneRequestOption *request,
{
if (RequestInfoCheck(request, listener) == false) {
LNN_LOGE(LNN_LANE, "lane requestInfo invalid");
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
if (g_laneObject[request->type] == NULL) {
LNN_LOGE(LNN_LANE, "lane type is not supported. type=%{public}d", request->type);
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
int32_t result;
LNN_LOGI(LNN_LANE, "laneRequest, laneReqId=%{public}u, laneType=%{public}d, transType=%{public}d",
@ -419,21 +430,18 @@ int32_t LnnRequestLane(uint32_t laneReqId, const LaneRequestOption *request,
result = g_laneObject[request->type]->allocLane(laneReqId, request, listener);
if (result != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "alloc lane fail, result=%{public}d", result);
return SOFTBUS_ERR;
return result;
}
LNN_LOGI(LNN_LANE, "request lane success, laneReqId=%{public}u", laneReqId);
return SOFTBUS_OK;
return result;
}
int32_t LnnFreeLane(uint32_t laneReqId)
{
LaneType type = laneReqId >> LANE_REQ_ID_TYPE_SHIFT;
if (type >= LANE_TYPE_BUTT) {
LaneType type;
if (CheckLaneObject(laneReqId, &type) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "laneType invalid");
return SOFTBUS_ERR;
}
if (g_laneObject[type] == NULL) {
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
LNN_LOGD(LNN_LANE, "free lane enter, laneReqId=%{public}u", laneReqId);
int32_t result = g_laneObject[type]->freeLane(laneReqId);
@ -514,6 +522,7 @@ int32_t InitLane(void)
g_laneObject[LANE_TYPE_CTRL] = CtrlLaneGetInstance();
if (g_laneObject[LANE_TYPE_CTRL] != NULL) {
LNN_LOGI(LNN_LANE, "ctrl get instance succ");
g_laneObject[LANE_TYPE_CTRL]->init(&g_laneIdListener);
}
ListInit(&g_laneListenerList.list);
g_laneListenerList.cnt = 0;
@ -528,5 +537,8 @@ void DeinitLane(void)
if (g_laneObject[LANE_TYPE_TRANS] != NULL) {
g_laneObject[LANE_TYPE_TRANS]->deinit();
}
if (g_laneObject[LANE_TYPE_CTRL] != NULL) {
g_laneObject[LANE_TYPE_CTRL]->deinit();
}
(void)SoftBusMutexDestroy(&g_laneMutex);
}

View File

@ -18,6 +18,7 @@
#include <securec.h>
#include "anonymizer.h"
#include "bus_center_info_key.h"
#include "bus_center_manager.h"
#include "lnn_distributed_net_ledger.h"
#include "lnn_lane.h"
@ -37,8 +38,11 @@
#include "softbus_adapter_crypto.h"
#include "softbus_conn_ble_connection.h"
#include "softbus_conn_ble_manager.h"
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_network_utils.h"
#include "softbus_protocol_def.h"
#include "softbus_utils.h"
#include "trans_network_statistics.h"
#define IF_NAME_BR "br0"
@ -63,7 +67,7 @@ static void LaneUnlock(void)
(void)SoftBusMutexUnlock(&g_laneResource.lock);
}
uint64_t ApplyLaneId(const char *localUdid, const char *remoteUdid, LaneLinkType linkType)
uint64_t GenerateLaneId(const char *localUdid, const char *remoteUdid, LaneLinkType linkType)
{
if (localUdid == NULL || remoteUdid == NULL) {
LNN_LOGE(LNN_LANE, "udid is NULL");
@ -91,7 +95,8 @@ uint64_t ApplyLaneId(const char *localUdid, const char *remoteUdid, LaneLinkType
LNN_LOGE(LNN_LANE, "generate laneId hash fail");
return INVALID_LANE_ID;
}
if (memcpy_s(&laneId, sizeof(laneId), laneIdHash, sizeof(laneId)) != EOK) {
uint32_t len = sizeof(laneId) <= LANE_ID_HASH_LEN ? sizeof(laneId) : LANE_ID_HASH_LEN;
if (memcpy_s(&laneId, sizeof(laneId), laneIdHash, len) != EOK) {
LNN_LOGE(LNN_LANE, "memcpy laneId hash fail");
return INVALID_LANE_ID;
}
@ -109,30 +114,30 @@ uint64_t ApplyLaneId(const char *localUdid, const char *remoteUdid, LaneLinkType
return INVALID_LANE_ID;
}
static bool isValidLinkAddr(const LaneResource *resourceItem, const LaneLinkInfo *linkInfoItem)
static bool IsValidLinkAddr(const LaneLinkInfo *sourceLink, const LaneLinkInfo *linkInfoItem)
{
switch (resourceItem->link.type) {
switch (sourceLink->type) {
case LANE_BR:
if (strncmp(resourceItem->link.linkInfo.br.brMac, linkInfoItem->linkInfo.br.brMac, BT_MAC_LEN) != 0) {
if (strncmp(sourceLink->linkInfo.br.brMac, linkInfoItem->linkInfo.br.brMac, BT_MAC_LEN) != 0) {
break;
}
return true;
case LANE_BLE:
case LANE_COC:
if (strncmp(resourceItem->link.linkInfo.ble.bleMac, linkInfoItem->linkInfo.ble.bleMac, BT_MAC_LEN) != 0) {
if (strncmp(sourceLink->linkInfo.ble.bleMac, linkInfoItem->linkInfo.ble.bleMac, BT_MAC_LEN) != 0) {
break;
}
return true;
case LANE_P2P:
case LANE_HML:
if (strncmp(resourceItem->link.linkInfo.p2p.connInfo.peerIp,
if (strncmp(sourceLink->linkInfo.p2p.connInfo.peerIp,
linkInfoItem->linkInfo.p2p.connInfo.peerIp, IP_LEN) != 0) {
break;
}
return true;
case LANE_BLE_DIRECT:
case LANE_COC_DIRECT:
if (strncmp(resourceItem->link.linkInfo.bleDirect.networkId, linkInfoItem->linkInfo.bleDirect.networkId,
if (strncmp(sourceLink->linkInfo.bleDirect.networkId, linkInfoItem->linkInfo.bleDirect.networkId,
NETWORK_ID_BUF_LEN) != 0) {
break;
}
@ -140,17 +145,16 @@ static bool isValidLinkAddr(const LaneResource *resourceItem, const LaneLinkInfo
case LANE_WLAN_5G:
case LANE_WLAN_2P4G:
case LANE_ETH:
if (strncmp(resourceItem->link.linkInfo.wlan.connInfo.addr,
if (strncmp(sourceLink->linkInfo.wlan.connInfo.addr,
linkInfoItem->linkInfo.wlan.connInfo.addr, MAX_SOCKET_ADDR_LEN) != 0) {
break;
}
return true;
default:
LNN_LOGE(LNN_LANE, "invalid linkType=%{public}d", resourceItem->link.type);
LNN_LOGE(LNN_LANE, "invalid linkType=%{public}d", sourceLink->type);
return false;
}
LNN_LOGE(LNN_LANE, "lane resource is different form input link addr, laneId=%{public}" PRIu64 "",
resourceItem->laneId);
LNN_LOGE(LNN_LANE, "lane resource is different form input link addr, linkType=%{public}d", sourceLink->type);
return false;
}
@ -161,7 +165,7 @@ static LaneResource* GetValidLaneResource(const LaneLinkInfo *linkInfoItem)
LIST_FOR_EACH_ENTRY_SAFE(item, next, &g_laneResource.list, LaneResource, node) {
if (linkInfoItem->type == item->link.type &&
strncmp(item->link.peerUdid, linkInfoItem->peerUdid, UDID_BUF_LEN) == 0 &&
isValidLinkAddr(item, linkInfoItem)) {
IsValidLinkAddr(&(item->link), linkInfoItem)) {
return item;
}
}
@ -281,18 +285,25 @@ static bool IsNeedDelResource(uint64_t laneId, bool isServerSide, LaneResource *
if (item->clientRef == 0) {
ListDelete(&item->node);
SoftBusFree(item);
g_laneResource.cnt--;
if (g_laneResource.cnt != 0) {
g_laneResource.cnt--;
}
} else {
item->isServerSide = false;
}
} else {
isServer = item->isServerSide;
ref = --item->clientRef;
ref = item->clientRef;
if (item->clientRef != 0) {
ref = --item->clientRef;
}
if (!isServer && ref == 0) {
DeleteNetworkResourceByLaneId(laneId);
ListDelete(&item->node);
SoftBusFree(item);
g_laneResource.cnt--;
if (g_laneResource.cnt != 0) {
g_laneResource.cnt--;
}
}
}
LNN_LOGI(LNN_LANE, "del laneId=%{public}" PRIu64 " resource, isServer=%{public}d, clientRef=%{public}u",
@ -394,7 +405,7 @@ int32_t FindLaneResourceByLinkType(const char *peerUdid, LaneLinkType type, Lane
Anonymize(peerUdid, &anonyPeerUdid);
LNN_LOGE(LNN_LANE, "no find lane resource by linktype=%{public}d, peerUdid=%{public}s", type, anonyPeerUdid);
AnonymizeFree(anonyPeerUdid);
return SOFTBUS_ERR;
return SOFTBUS_LANE_RESOURCE_NOT_FIND;
}
int32_t FindLaneResourceByLinkAddr(const LaneLinkInfo *info, LaneResource *resource)
@ -795,7 +806,7 @@ static int32_t LaneLinkOfP2pReuse(uint32_t reqId, const LinkRequest *reqInfo, co
uint16_t port;
if (!LaneGetP2PReuseMac(reqInfo->peerNetworkId, ipAddr, MAX_SOCKET_ADDR_LEN, &port)) {
LNN_LOGE(LNN_LANE, "p2p resue get addr failed");
return SOFTBUS_NOT_FIND;
return SOFTBUS_LANE_NOT_FIND;
}
linkInfo.linkInfo.wlan.connInfo.protocol = LNN_PROTOCOL_IP;
linkInfo.linkInfo.wlan.connInfo.port = port;
@ -883,13 +894,13 @@ static ProtocolType LnnLaneSelectProtocol(LnnNetIfType ifType, const char *netWo
if (req.selectedProtocol == 0) {
req.selectedProtocol = LNN_PROTOCOL_IP;
}
return req.selectedProtocol;
}
static int32_t FillWlanLinkInfo(ProtocolType protocol, const LinkRequest *reqInfo, LaneLinkInfo *linkInfo)
{
int32_t ret = SOFTBUS_OK;
int32_t ret = SOFTBUS_LANE_DETECT_FAIL;
int32_t port = 0;
if (reqInfo->transType == LANE_T_MSG) {
ret = LnnGetRemoteNumInfo(reqInfo->peerNetworkId, NUM_KEY_PROXY_PORT, &port);
@ -934,9 +945,11 @@ static int32_t CreateWlanLinkInfo(ProtocolType protocol, const LinkRequest *reqI
return SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
}
if (strnlen(linkInfo->linkInfo.wlan.connInfo.addr, sizeof(linkInfo->linkInfo.wlan.connInfo.addr)) == 0 ||
strnlen(linkInfo->linkInfo.wlan.connInfo.addr,
sizeof(linkInfo->linkInfo.wlan.connInfo.addr)) == MAX_SOCKET_ADDR_LEN ||
strncmp(linkInfo->linkInfo.wlan.connInfo.addr, "127.0.0.1", strlen("127.0.0.1")) == 0) {
LNN_LOGE(LNN_LANE, "Wlan ip not found");
return SOFTBUS_MEM_ERR;
return SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
}
} else {
if (LnnGetRemoteStrInfo(reqInfo->peerNetworkId, STRING_KEY_NODE_ADDR, linkInfo->linkInfo.wlan.connInfo.addr,

View File

@ -131,6 +131,7 @@ static SoftBusHandler g_guideChannelHandler;
#define INVAILD_AUTH_ID (-1)
#define INVALID_P2P_REQUEST_ID (-1)
#define LANE_REQ_ID_TYPE_SHIFT 28
typedef int32_t (*GuideLinkByType)(const LinkRequest *request, uint32_t laneReqId, const LaneLinkCb *callback);
@ -149,7 +150,7 @@ static int32_t GetPreferAuthConnInfo(const char *networkId, AuthConnInfo *connIn
char uuid[UDID_BUF_LEN] = {0};
if (LnnGetRemoteStrInfo(networkId, STRING_KEY_UUID, uuid, sizeof(uuid)) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get peer uuid fail");
return SOFTBUS_ERR;
return SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
}
int32_t ret = AuthGetP2pConnInfo(uuid, connInfo, isMetaAuth);
if (ret != SOFTBUS_OK) {
@ -241,7 +242,7 @@ static int32_t GetP2pLinkDownParam(uint32_t authRequestId, uint32_t p2pRequestId
}
LinkUnlock();
LNN_LOGE(LNN_LANE, "request item not found, authRequestId=%{public}u", authRequestId);
return SOFTBUS_ERR;
return SOFTBUS_LANE_NOT_FIND;
}
static void DelP2pLinkedByAuthReqId(uint32_t authRequestId)
@ -271,6 +272,7 @@ static void OnConnOpenFailedForDisconnect(uint32_t authRequestId, int32_t reason
info.requestId = GetWifiDirectManager()->getRequestId();
AuthHandle authHandle = { .authId = INVAILD_AUTH_ID };
if (GetP2pLinkDownParam(authRequestId, info.requestId, &info, authHandle) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get p2p linkdown param fail, authRequestId=%{public}u", authRequestId);
goto FAIL;
}
struct WifiDirectDisconnectCallback callback = {
@ -302,6 +304,7 @@ static void OnConnOpenedForDisconnect(uint32_t authRequestId, AuthHandle authHan
info.negoChannel.type = NEGO_CHANNEL_AUTH;
info.negoChannel.handle.authHandle = authHandle;
if (GetP2pLinkDownParam(authRequestId, info.requestId, &info, authHandle) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get p2p linkdown param fail, authRequestId=%{public}u", authRequestId);
goto FAIL;
}
struct WifiDirectDisconnectCallback callback = {
@ -348,12 +351,12 @@ static int32_t GetFeatureCap(const char *networkId, uint64_t *local, uint64_t *r
int32_t ret = LnnGetLocalNumU64Info(NUM_KEY_FEATURE_CAPA, local);
if (ret != SOFTBUS_OK || *local == 0) {
LNN_LOGE(LNN_LANE, "LnnGetLocalNumInfo err, ret=%{public}d, local=%{public}" PRIu64, ret, *local);
return SOFTBUS_ERR;
return SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
}
ret = LnnGetRemoteNumU64Info(networkId, NUM_KEY_FEATURE_CAPA, remote);
if (ret != SOFTBUS_OK || *remote == 0) {
LNN_LOGE(LNN_LANE, "LnnGetRemoteNumInfo err, ret=%{public}d, remote=%{public}" PRIu64, ret, *remote);
return SOFTBUS_ERR;
return SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
}
return SOFTBUS_OK;
}
@ -381,10 +384,10 @@ static int32_t GetP2pLinkReqParamByChannelRequetId(
wifiDirectInfo->bandWidth = item->p2pInfo.bandWidth;
wifiDirectInfo->pid = item->laneRequestInfo.pid;
if (strcpy_s(wifiDirectInfo->remoteNetworkId, sizeof(wifiDirectInfo->remoteNetworkId),
item->laneRequestInfo.networkId) != EOK) {
item->laneRequestInfo.networkId) != EOK) {
LNN_LOGE(LNN_LANE, "copy networkId failed");
LinkUnlock();
return SOFTBUS_MEM_ERR;
return SOFTBUS_STRCPY_ERR;
}
wifiDirectInfo->isNetworkDelegate = item->p2pInfo.networkDelegate;
wifiDirectInfo->connectType = item->laneRequestInfo.linkType == LANE_HML ?
@ -417,14 +420,14 @@ static int32_t GetP2pLinkReqParamByAuthHandle(uint32_t authRequestId, uint32_t p
wifiDirectInfo->remoteMac, sizeof(wifiDirectInfo->remoteMac)) != SOFTBUS_OK) {
LinkUnlock();
LNN_LOGE(LNN_LANE, "get remote p2p mac fail");
return SOFTBUS_ERR;
return SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
}
wifiDirectInfo->pid = item->laneRequestInfo.pid;
if (strcpy_s(wifiDirectInfo->remoteNetworkId, sizeof(wifiDirectInfo->remoteNetworkId),
item->laneRequestInfo.networkId) != EOK) {
item->laneRequestInfo.networkId) != EOK) {
LNN_LOGE(LNN_LANE, "copy networkId failed");
LinkUnlock();
return SOFTBUS_ERR;
return SOFTBUS_STRCPY_ERR;
}
wifiDirectInfo->bandWidth = item->p2pInfo.bandWidth;
wifiDirectInfo->isNetworkDelegate = item->p2pInfo.networkDelegate;
@ -437,7 +440,7 @@ static int32_t GetP2pLinkReqParamByAuthHandle(uint32_t authRequestId, uint32_t p
}
LinkUnlock();
LNN_LOGE(LNN_LANE, "request item not found, authRequestId=%{public}u", authRequestId);
return SOFTBUS_ERR;
return SOFTBUS_LANE_GUIDE_BUILD_FAIL;
}
static int32_t GetP2pLinkReqByReqId(AsyncResultType type, uint32_t requestId, P2pLinkReqList *info)
@ -463,7 +466,7 @@ static int32_t GetP2pLinkReqByReqId(AsyncResultType type, uint32_t requestId, P2
}
LinkUnlock();
LNN_LOGE(LNN_LANE, "P2pLinkReq item not found, type=%{public}d, requestId=%{public}u.", type, requestId);
return SOFTBUS_NOT_FIND;
return SOFTBUS_LANE_NOT_FIND;
}
static int32_t DelP2pLinkReqByReqId(AsyncResultType type, uint32_t requestId)
@ -605,11 +608,11 @@ static void NotifyLinkSucc(AsyncResultType type, uint32_t requestId, LaneLinkInf
return;
}
(void)DelP2pLinkReqByReqId(type, requestId);
DelGuideInfoItem(reqInfo.laneRequestInfo.laneReqId, reqInfo.laneRequestInfo.linkType);
LaneLinkType throryLinkType = reqInfo.laneRequestInfo.linkType;
if (reqInfo.laneRequestInfo.linkType != linkInfo->type) {
LNN_LOGI(LNN_LANE, "not return specified link, requestId=%{public}u", requestId);
LNN_LOGI(LNN_LANE, "not return throry linkType=%{public}d, requestId=%{public}u", throryLinkType, requestId);
}
DelGuideInfoItem(reqInfo.laneRequestInfo.laneReqId, throryLinkType);
int32_t ret = AddNewP2pLinkedInfo(&reqInfo, linkId);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "add new p2p linked info fail, laneReqId=%{public}u", reqInfo.laneRequestInfo.laneReqId);
@ -618,8 +621,9 @@ static void NotifyLinkSucc(AsyncResultType type, uint32_t requestId, LaneLinkInf
}
} else {
if (reqInfo.laneRequestInfo.cb.OnLaneLinkSuccess != NULL) {
LNN_LOGI(LNN_LANE, "wifidirect conn succ, laneReqId=%{public}u, linktype=%{public}d, requestId=%{public}u, "
"linkId=%{public}d", reqInfo.laneRequestInfo.laneReqId, linkInfo->type, requestId, linkId);
LNN_LOGI(LNN_LANE, "wifidirect conn succ, laneReqId=%{public}u, actual linkType=%{public}d, "
"requestId=%{public}u, linkId=%{public}d",
reqInfo.laneRequestInfo.laneReqId, linkInfo->type, requestId, linkId);
reqInfo.laneRequestInfo.cb.OnLaneLinkSuccess(reqInfo.laneRequestInfo.laneReqId, throryLinkType, linkInfo);
}
}
@ -743,7 +747,7 @@ static void HandleGuideChannelAsyncFail(AsyncResultType type, uint32_t requestId
LNN_LOGI(LNN_LANE, "handle guide channel async fail, type=%{public}d, laneReqId=%{public}u, linkType=%{public}d",
type, laneReqId, linkType);
HandleGuideChannelRetry(laneReqId, linkType, reason);
}
}
static void OnWifiDirectConnectFailure(uint32_t p2pRequestId, int32_t reason)
{
@ -759,7 +763,6 @@ static void OnWifiDirectConnectFailure(uint32_t p2pRequestId, int32_t reason)
LNN_LOGI(LNN_LANE, "guide channel retry, requestId=%{public}u, reason=%{public}d", p2pRequestId, reason);
HandleGuideChannelAsyncFail(ASYNC_RESULT_P2P, p2pRequestId, reason);
} else {
LNN_LOGI(LNN_LANE, "wifidirect conn fail, requestId=%{public}u, reason=%{public}d", p2pRequestId, reason);
NotifyLinkFail(ASYNC_RESULT_P2P, p2pRequestId, reason);
}
}
@ -810,7 +813,7 @@ static int32_t UpdateP2pLinkReq(P2pLinkReqList *p2pReqInfo, uint32_t laneReqId)
(void)memset_s(&reqInfo, sizeof(TransReqInfo), 0, sizeof(TransReqInfo));
if (GetTransReqInfoByLaneReqId(laneReqId, &reqInfo) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get TransReqInfo fail, laneReqId=%{public}u", laneReqId);
return SOFTBUS_ERR;
return SOFTBUS_LANE_GUIDE_BUILD_FAIL;
}
if (reqInfo.isWithQos) {
p2pReqInfo->p2pInfo.bandWidth = reqInfo.allocInfo.qosRequire.minBW;
@ -824,6 +827,16 @@ static int32_t UpdateP2pLinkReq(P2pLinkReqList *p2pReqInfo, uint32_t laneReqId)
return SOFTBUS_OK;
}
static int32_t ParseLaneTypeByLaneReqId(uint32_t laneReqId, LaneType *laneType)
{
if (laneReqId == INVALID_LANE_REQ_ID || laneType == NULL) {
LNN_LOGE(LNN_LANE, "[ParseLaneType]invalid param");
return SOFTBUS_INVALID_PARAM;
}
*laneType = (LaneType)(laneReqId >> LANE_REQ_ID_TYPE_SHIFT);
return SOFTBUS_OK;
}
static int32_t AddP2pLinkReqItem(AsyncResultType type, uint32_t requestId, uint32_t laneReqId,
const LinkRequest *request, const LaneLinkCb *callback)
{
@ -841,7 +854,12 @@ static int32_t AddP2pLinkReqItem(AsyncResultType type, uint32_t requestId, uint3
SoftBusFree(item);
return SOFTBUS_MEM_ERR;
}
if (UpdateP2pLinkReq(item, laneReqId) != SOFTBUS_OK) {
LaneType laneType;
if (ParseLaneTypeByLaneReqId(laneReqId, &laneType) != SOFTBUS_OK) {
SoftBusFree(item);
return SOFTBUS_ERR;
}
if (laneType == LANE_TYPE_TRANS && UpdateP2pLinkReq(item, laneReqId) != SOFTBUS_OK) {
SoftBusFree(item);
return SOFTBUS_LANE_GUIDE_BUILD_FAIL;
}
@ -869,7 +887,7 @@ static int32_t UpdateP2pLinkedList(int32_t linkId, uint32_t authRequestId)
{
if (LinkLock() != 0) {
LNN_LOGE(LNN_LANE, "lock fail");
return SOFTBUS_ERR;
return SOFTBUS_LOCK_ERR;
}
P2pLinkedList *item = NULL;
LIST_FOR_EACH_ENTRY(item, g_p2pLinkedList, P2pLinkedList, node) {
@ -880,7 +898,7 @@ static int32_t UpdateP2pLinkedList(int32_t linkId, uint32_t authRequestId)
}
}
LinkUnlock();
return SOFTBUS_ERR;
return SOFTBUS_NOT_FIND;
}
static int32_t OpenAuthToDisconnP2p(const char *networkId, int32_t linkId)
@ -888,29 +906,32 @@ static int32_t OpenAuthToDisconnP2p(const char *networkId, int32_t linkId)
char uuid[UDID_BUF_LEN] = {0};
if (LnnGetRemoteStrInfo(networkId, STRING_KEY_UUID, uuid, sizeof(uuid)) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get peer uuid fail");
return SOFTBUS_ERR;
return SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
}
AuthConnInfo connInfo;
(void)memset_s(&connInfo, sizeof(AuthConnInfo), 0, sizeof(AuthConnInfo));
bool isMetaAuth = GetChannelAuthType(networkId);
if (GetPreferAuthConnInfo(networkId, &connInfo, isMetaAuth) != SOFTBUS_OK) {
int32_t ret = GetPreferAuthConnInfo(networkId, &connInfo, isMetaAuth);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "no auth conn exist");
return SOFTBUS_ERR;
return ret;
}
uint32_t authRequestId = AuthGenRequestId();
if (UpdateP2pLinkedList(linkId, authRequestId) != SOFTBUS_OK) {
ret = UpdateP2pLinkedList(linkId, authRequestId);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "update linkedInfo fail");
return SOFTBUS_ERR;
return ret;
}
AuthConnCallback cb = {
.onConnOpened = OnConnOpenedForDisconnect,
.onConnOpenFailed = OnConnOpenFailedForDisconnect
.onConnOpenFailed = OnConnOpenFailedForDisconnect,
};
LNN_LOGI(LNN_LANE, "open auth to disconnect WD, linkId=%{public}d, authRequestId=%{public}u",
linkId, authRequestId);
if (AuthOpenConn(&connInfo, authRequestId, &cb, isMetaAuth) != SOFTBUS_OK) {
ret = AuthOpenConn(&connInfo, authRequestId, &cb, isMetaAuth);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "open auth conn fail, authRequestId=%{public}u", authRequestId);
return SOFTBUS_ERR;
return ret;
}
return SOFTBUS_OK;
}
@ -994,7 +1015,7 @@ static int32_t OpenAuthToConnP2p(const LinkRequest *request, uint32_t laneReqId,
AuthConnCallback cb = {
.onConnOpened = OnAuthConnOpened,
.onConnOpenFailed = OnAuthConnOpenFailed
.onConnOpenFailed = OnAuthConnOpenFailed,
};
LNN_LOGI(LNN_LANE, "open auth with authRequestId=%{public}u", authRequestId);
ret = AuthOpenConn(&connInfo, authRequestId, &cb, isMetaAuth);
@ -1116,19 +1137,20 @@ static int32_t CheckTransReqInfo(const LinkRequest *request, uint32_t laneReqId)
{
TransReqInfo reqInfo;
(void)memset_s(&reqInfo, sizeof(TransReqInfo), 0, sizeof(TransReqInfo));
if (GetTransReqInfoByLaneReqId(laneReqId, &reqInfo) != SOFTBUS_OK) {
int32_t ret = GetTransReqInfoByLaneReqId(laneReqId, &reqInfo);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get TransReqInfo fail, laneReqId=%{public}u", laneReqId);
return SOFTBUS_ERR;
return ret;
}
if (reqInfo.isWithQos) {
if (request->linkType == LANE_P2P) {
LNN_LOGE(LNN_LANE, "request linkType=%{public}d", request->linkType);
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
} else {
if (request->p2pOnly) {
LNN_LOGE(LNN_LANE, "request p2pOnly=%{public}d", request->p2pOnly);
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
}
return SOFTBUS_OK;
@ -1140,13 +1162,6 @@ static int32_t OpenBleTriggerToConn(const LinkRequest *request, uint32_t laneReq
LNN_LOGI(LNN_LANE, "ble trigger not support p2p");
return SOFTBUS_INVALID_PARAM;
}
AuthConnInfo connInfo;
(void)memset_s(&connInfo, sizeof(AuthConnInfo), 0, sizeof(AuthConnInfo));
bool isMetaAuth = GetAuthType(request->peerNetworkId);
if (GetPreferAuth(request->peerNetworkId, &connInfo, isMetaAuth) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "no auth conn exist");
return SOFTBUS_ERR;
}
struct WifiDirectConnectInfo wifiDirectInfo;
(void)memset_s(&wifiDirectInfo, sizeof(wifiDirectInfo), 0, sizeof(wifiDirectInfo));
wifiDirectInfo.requestId = GetWifiDirectManager()->getRequestId();
@ -1154,11 +1169,10 @@ static int32_t OpenBleTriggerToConn(const LinkRequest *request, uint32_t laneReq
LNN_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, LNN_LANE, "add new connect node failed");
wifiDirectInfo.pid = request->pid;
wifiDirectInfo.connectType = WIFI_DIRECT_CONNECT_TYPE_BLE_TRIGGER_HML;
ret = strcpy_s(wifiDirectInfo.remoteNetworkId, NETWORK_ID_BUF_LEN, request->peerNetworkId);
if (ret != SOFTBUS_OK) {
if (strcpy_s(wifiDirectInfo.remoteNetworkId, NETWORK_ID_BUF_LEN, request->peerNetworkId) != EOK) {
LNN_LOGE(LNN_LANE, "copy networkId failed");
(void)DelP2pLinkReqByReqId(ASYNC_RESULT_P2P, wifiDirectInfo.requestId);
return SOFTBUS_MEM_ERR;
return SOFTBUS_STRCPY_ERR;
}
wifiDirectInfo.isNetworkDelegate = request->networkDelegate;
@ -1244,19 +1258,20 @@ static int32_t ConnectWifiDirectWithReuse(const LinkRequest *request, uint32_t l
wifiDirectInfo.pid = request->pid;
wifiDirectInfo.connectType = GetWifiDirectManager()->supportHmlTwo() ?
WIFI_DIRECT_CONNECT_TYPE_BLE_TRIGGER_HML : WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_HML;
if (strcpy_s(wifiDirectInfo.remoteNetworkId, NETWORK_ID_BUF_LEN, request->peerNetworkId) != SOFTBUS_OK) {
if (strcpy_s(wifiDirectInfo.remoteNetworkId, NETWORK_ID_BUF_LEN, request->peerNetworkId) != EOK) {
LNN_LOGE(LNN_LANE, "strcpy fail");
return SOFTBUS_ERR;
return SOFTBUS_STRCPY_ERR;
}
if (LnnGetRemoteStrInfo(request->peerNetworkId, STRING_KEY_WIFIDIRECT_ADDR,
wifiDirectInfo.remoteMac, sizeof(wifiDirectInfo.remoteMac)) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get remote mac fail, laneReqId=%{public}u", laneReqId);
return SOFTBUS_ERR;
return SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
}
wifiDirectInfo.isNetworkDelegate = request->networkDelegate;
if (AddP2pLinkReqItem(ASYNC_RESULT_P2P, wifiDirectInfo.requestId, laneReqId, request, callback) != SOFTBUS_OK) {
int32_t ret = AddP2pLinkReqItem(ASYNC_RESULT_P2P, wifiDirectInfo.requestId, laneReqId, request, callback);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "add p2plinkinfo fail, laneReqId=%{public}u", laneReqId);
return SOFTBUS_ERR;
return ret;
}
struct WifiDirectConnectCallback cb = {
.onConnectSuccess = OnWifiDirectConnectSuccess,
@ -1264,9 +1279,9 @@ static int32_t ConnectWifiDirectWithReuse(const LinkRequest *request, uint32_t l
};
LNN_LOGI(LNN_LANE, "wifidirect reuse connect with p2pRequestId=%{public}u, connectType=%{public}d",
wifiDirectInfo.requestId, wifiDirectInfo.connectType);
int32_t ret = GetWifiDirectManager()->connectDevice(&wifiDirectInfo, &cb);
ret = GetWifiDirectManager()->connectDevice(&wifiDirectInfo, &cb);
if (ret != SOFTBUS_OK) {
NotifyLinkFail(ASYNC_RESULT_P2P, wifiDirectInfo.requestId, ret);
(void)DelP2pLinkReqByReqId(ASYNC_RESULT_P2P, wifiDirectInfo.requestId);
return ret;
}
return SOFTBUS_OK;
@ -1276,22 +1291,23 @@ static int32_t TryWifiDirectReuse(const LinkRequest *request, uint32_t laneReqId
{
if (request->linkType != LANE_HML && request->linkType != LANE_P2P) {
LNN_LOGE(LNN_LANE, "not support wifi direct reuse");
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
char peerUdid[UDID_BUF_LEN] = {0};
if (LnnGetRemoteStrInfo(request->peerNetworkId, STRING_KEY_DEV_UDID, peerUdid, UDID_BUF_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get udid error");
return SOFTBUS_ERR;
return SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
}
LaneResource resourceItem;
(void)memset_s(&resourceItem, sizeof(LaneResource), 0, sizeof(LaneResource));
if (FindLaneResourceByLinkType(peerUdid, request->linkType, &resourceItem) != SOFTBUS_OK) {
int32_t ret = FindLaneResourceByLinkType(peerUdid, request->linkType, &resourceItem);
if (ret != SOFTBUS_OK) {
LNN_LOGI(LNN_LANE, "not find lane resource");
return SOFTBUS_ERR;
return ret;
}
if (GetWifiDirectManager()->isNegotiateChannelNeeded(request->peerNetworkId, WIFI_DIRECT_LINK_TYPE_HML)) {
LNN_LOGE(LNN_LANE, "laneId=%{public}" PRIu64 " exist but need nego channel", resourceItem.laneId);
return SOFTBUS_ERR;
return SOFTBUS_LANE_GUIDE_BUILD_FAIL;
}
LNN_LOGI(LNN_LANE, "wifidirect exist reuse link, laneId=%{public}" PRIu64 "", resourceItem.laneId);
return ConnectWifiDirectWithReuse(request, laneReqId, callback);
@ -1528,7 +1544,8 @@ int32_t LnnConnectP2p(const LinkRequest *request, uint32_t laneReqId, const Lane
return SOFTBUS_INVALID_PARAM;
}
if (g_p2pLinkList == NULL) {
LNN_CHECK_AND_RETURN_RET_LOGE(LnnP2pInit() == SOFTBUS_OK, SOFTBUS_ERR, LNN_LANE, "p2p not init");
int32_t ret = LnnP2pInit();
LNN_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, LNN_LANE, "p2p not init");
}
bool isMetaAuth = GetAuthType(request->peerNetworkId);
if (isMetaAuth) {

View File

@ -147,7 +147,10 @@ int32_t DelLaneBusinessInfoItem(LaneType laneType, uint64_t laneId)
}
LaneBusinessInfo *item = GetLaneBusinessInfoWithoutLock(&laneBusinessInfo);
if (item != NULL) {
uint32_t ref = --item->ref;
uint32_t ref = item->ref;
if (item->ref != 0) {
ref = --item->ref;
}
if (ref == 0) {
ListDelete(&item->node);
SoftBusFree(item);
@ -171,7 +174,7 @@ static int32_t FindLaneBusinessInfoByLinkInfo(const LaneLinkInfo *laneLinkInfo,
LNN_LOGE(LNN_LANE, "get udid fail");
return SOFTBUS_ERR;
}
uint64_t laneId = ApplyLaneId(localUdid, laneLinkInfo->peerUdid, laneLinkInfo->type);
uint64_t laneId = GenerateLaneId(localUdid, laneLinkInfo->peerUdid, laneLinkInfo->type);
if (LaneListenerLock() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "lane listener lock fail");
return SOFTBUS_LOCK_ERR;
@ -262,7 +265,7 @@ int32_t LaneLinkupNotify(const char *peerUdid, const LaneLinkInfo *laneLinkInfo)
LNN_LOGE(LNN_LANE, "get udid fail");
return SOFTBUS_ERR;
}
uint64_t laneId = ApplyLaneId(localUdid, peerUdid, laneLinkInfo->type);
uint64_t laneId = GenerateLaneId(localUdid, peerUdid, laneLinkInfo->type);
for (uint32_t i = 0; i < LANE_TYPE_BUTT; i++) {
if (listenerList[i].listener.onLaneLinkup != NULL) {
LNN_LOGI(LNN_LANE, "notify lane linkup, laneType=%{public}u", i);
@ -384,7 +387,7 @@ static void LnnOnWifiDirectDeviceOffline(const char *peerMac, const char *peerIp
static void LnnOnWifiDirectRoleChange(enum WifiDirectRole oldRole, enum WifiDirectRole newRole)
{
LNN_LOGD(LNN_LANE, "lnn wifidirect roleChange");
LNN_LOGD(LNN_LANE, "lnn wifiDirect roleChange");
(void)oldRole;
(void)newRole;
}
@ -462,9 +465,9 @@ static void LnnOnWifiDirectConnectedForSink(const char *remoteMac, const char *r
return;
}
laneLinkInfo.type = LANE_HML;
uint64_t laneId = ApplyLaneId(localUdid, laneLinkInfo.peerUdid, laneLinkInfo.type);
uint64_t laneId = GenerateLaneId(localUdid, laneLinkInfo.peerUdid, laneLinkInfo.type);
if (laneId == INVALID_LANE_ID) {
LNN_LOGE(LNN_LANE, "apply laneid fail");
LNN_LOGE(LNN_LANE, "generate laneid fail");
return;
}
if (AddLaneResourceToPool(&laneLinkInfo, laneId, true) != SOFTBUS_OK) {

View File

@ -243,7 +243,7 @@ static int32_t NotifyWlanDetectResult(LaneDetectInfo *requestItem, bool isSendSu
ListInit(&detectInfoList);
int32_t ret = GetAllDetectInfoWithDetectId(requestItem->laneDetectId, &detectInfoList);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get all detect info fail, laneDetectId=%{public}u", requestItem->laneDetectId);
LNN_LOGE(LNN_LANE, "get all detect info fail, detectId=%{public}u", requestItem->laneDetectId);
return ret;
}
LaneDetectInfo *item = NULL;
@ -284,7 +284,7 @@ static int32_t LaneDetectOnDataEvent(ListenerModule module, int32_t events, int3
LNN_LOGE(LNN_LANE, "wlan detect info not found by fd=%{public}d", fd);
(void)DelTrigger(LANE, fd, WRITE_TRIGGER);
ConnShutdownSocket(fd);
return SOFTBUS_NOT_FIND;
return SOFTBUS_LANE_NOT_FIND;
}
LNN_LOGI(LNN_LANE, "wlan connect success, detectId=%{public}u, fd=%{public}d", requestItem.laneDetectId, fd);
(void)DelTrigger(LANE, fd, WRITE_TRIGGER);

View File

@ -18,8 +18,11 @@
#include <securec.h>
#include "anonymizer.h"
#include "bus_center_manager.h"
#include "common_list.h"
#include "lnn_common_utils.h"
#include "lnn_distributed_net_ledger.h"
#include "lnn_lane_link.h"
#include "lnn_log.h"
#include "lnn_parameter_utils.h"
#include "lnn_select_rule.h"
@ -27,8 +30,7 @@
#include "softbus_def.h"
#include "softbus_errcode.h"
#include "softbus_utils.h"
#include "lnn_select_rule.h"
#include "lnn_common_utils.h"
#include "wifi_direct_manager.h"
#define INVALID_LINK (-1)
#define MESH_MAGIC_NUMBER 0x5A5A5A5A
@ -215,7 +217,7 @@ static int32_t PreProcLaneSelect(const char *networkId, const LaneSelectParam *r
Anonymize(networkId, &anonyNetworkId);
LNN_LOGE(LNN_LANE, "device not online, cancel selectLane, networkId=%{public}s", anonyNetworkId);
AnonymizeFree(anonyNetworkId);
return SOFTBUS_ERR;
return SOFTBUS_NETWORK_NODE_OFFLINE;
}
return SOFTBUS_OK;
}
@ -318,7 +320,7 @@ int32_t SelectLane(const char *networkId, const LaneSelectParam *request,
LanePreferredLinkList *recommendList, uint32_t *listNum)
{
if (PreProcLaneSelect(networkId, request, recommendList, listNum) != SOFTBUS_OK) {
return SOFTBUS_ERR;
return SOFTBUS_LANE_SELECT_FAIL;
}
char *anonyNetworkId = NULL;
Anonymize(networkId, &anonyNetworkId);
@ -336,15 +338,15 @@ int32_t SelectLane(const char *networkId, const LaneSelectParam *request,
if (resNum == 0) {
LNN_LOGE(LNN_LANE, "there is none linkResource can be used");
*listNum = 0;
return SOFTBUS_ERR;
return SOFTBUS_LANE_SELECT_FAIL;
}
if (!HmlIsExist(resList, resNum) && LaneAddHml(networkId, resList, &resNum) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "LaneAddHml fail");
return SOFTBUS_ERR;
return SOFTBUS_LANE_SELECT_FAIL;
}
if (AdjustLanePriority(networkId, request, resList, resNum) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "AdjustLanePriority fail");
return SOFTBUS_ERR;
return SOFTBUS_LANE_SELECT_FAIL;
}
recommendList->linkTypeNum = resNum;
@ -482,6 +484,31 @@ int32_t SelectExpectLanesByQos(const char *networkId, const LaneSelectParam *req
return SOFTBUS_OK;
}
static bool IsAuthReuseWifiDirect(const char *networkId, LaneLinkType linkType)
{
char udid[UDID_BUF_LEN] = {0};
if (LnnGetRemoteStrInfo(networkId, STRING_KEY_DEV_UDID, udid, UDID_BUF_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get peer udid fail");
return false;
}
LaneResource resoureItem;
if (memset_s(&resoureItem, sizeof(LaneResource), 0, sizeof(LaneResource)) != EOK) {
LNN_LOGE(LNN_LANE, "memset_s LaneResource fail");
return false;
}
if (linkType == LANE_HML && FindLaneResourceByLinkType(udid, LANE_HML, &resoureItem) == SOFTBUS_OK &&
!GetWifiDirectManager()->isNegotiateChannelNeeded(networkId, WIFI_DIRECT_LINK_TYPE_HML)) {
LNN_LOGI(LNN_LANE, "can use HML");
return true;
} else if (linkType == LANE_P2P && FindLaneResourceByLinkType(udid, LANE_P2P, &resoureItem) == SOFTBUS_OK &&
!GetWifiDirectManager()->isNegotiateChannelNeeded(networkId, WIFI_DIRECT_LINK_TYPE_P2P)) {
LNN_LOGI(LNN_LANE, "can use P2P");
return true;
} else {
return false;
}
}
int32_t SelectAuthLane(const char *networkId, LanePreferredLinkList *request,
LanePreferredLinkList *recommendList)
{
@ -490,6 +517,10 @@ int32_t SelectAuthLane(const char *networkId, LanePreferredLinkList *request,
}
recommendList->linkTypeNum = 0;
for (uint32_t i = 0; i < request->linkTypeNum; ++i) {
if ((request->linkType[i] == LANE_HML || request->linkType[i] == LANE_P2P) &&
!IsAuthReuseWifiDirect(networkId, request->linkType[i])) {
continue;
}
if (IsValidLane(networkId, request->linkType[i])) {
recommendList->linkType[recommendList->linkTypeNum] = request->linkType[i];
recommendList->linkTypeNum++;

View File

@ -522,7 +522,7 @@ static void DecideRetryLinks(const char *networkId, const LaneSelectParam *reque
}
}
static void UpdataHmlPriority(const char *peerNetWorkId, const LaneSelectParam *request,
static void UpdateHmlPriority(const char *peerNetWorkId, const LaneSelectParam *request,
LaneLinkType *linkList, uint32_t *linksNum)
{
char peerUdid[UDID_BUF_LEN] = {0};
@ -539,6 +539,10 @@ static void UpdataHmlPriority(const char *peerNetWorkId, const LaneSelectParam *
}
LNN_LOGI(LNN_LANE, "hml exist reuse laneId=%{public}" PRIu64 ", update priority", resourceItem.laneId);
LaneLinkType tmpList[LANE_LINK_TYPE_BUTT] = {0};
if (*linksNum > LANE_LINK_TYPE_BUTT) {
LNN_LOGE(LNN_LANE, "link num exceed lisk list");
return;
}
uint32_t num = 0;
tmpList[num++] = LANE_HML;
for (uint32_t i = 0; i < *linksNum; i++) {
@ -564,6 +568,10 @@ static void DelHasAllocedLink(uint64_t allocedLaneId, LaneLinkType *linkList, ui
}
uint32_t num = 0;
LaneLinkType tmpList[LANE_LINK_TYPE_BUTT] = {0};
if (*linksNum > LANE_LINK_TYPE_BUTT) {
LNN_LOGE(LNN_LANE, "link num exceed lisk list");
return;
}
for (uint32_t i = 0; i < *linksNum; i++) {
if (linkList[i] != resourceItem.link.type) {
tmpList[num++] = linkList[i];
@ -628,7 +636,7 @@ int32_t DecideAvailableLane(const char *networkId, const LaneSelectParam *reques
uint32_t linksNum = 0;
DecideOptimalLinks(networkId, request, linkList, &linksNum);
DecideRetryLinks(networkId, request, linkList, &linksNum);
UpdataHmlPriority(networkId, request, linkList, &linksNum);
UpdateHmlPriority(networkId, request, linkList, &linksNum);
if (request->allocedLaneId != INVALID_LANE_ID) {
DelHasAllocedLink(request->allocedLaneId, linkList, &linksNum);
}

View File

@ -20,7 +20,6 @@
#include "anonymizer.h"
#include "bus_center_manager.h"
#include "common_list.h"
#include "lnn_ctrl_lane.h"
#include "lnn_lane.h"
#include "lnn_lane_common.h"
#include "lnn_lane_def.h"
@ -51,7 +50,7 @@ typedef enum {
MSG_TYPE_LANE_STATE_CHANGE,
MSG_TYPE_DELAY_DESTROY_LINK,
MSG_TYPE_LANE_DETECT_TIMEOUT,
MSG_TYPE_LANE_RESULT_TIMEOUT,
MSG_TYPE_LANE_LINK_TIMEOUT,
} LaneMsgType;
typedef struct {
@ -81,6 +80,7 @@ typedef struct {
uint32_t linkRetryIdx;
bool networkDelegate;
int32_t p2pErrCode;
uint64_t startTime;
uint64_t restTime;
char peerBleMac[MAX_MAC_LEN];
LaneTransType transType;
@ -145,24 +145,26 @@ static int32_t LnnLanePostMsgToHandler(int32_t msgType, uint64_t param1, uint64_
return SOFTBUS_OK;
}
static int32_t RemoveLaneTimeout(const SoftBusMessage *msg, void *data)
static int32_t RemoveLinkTimeout(const SoftBusMessage *msg, void *data)
{
LaneTimeoutInfo *info = (LaneTimeoutInfo *)data;
if (msg->what != MSG_TYPE_LANE_RESULT_TIMEOUT || msg->arg1 != info->laneReqId) {
return SOFTBUS_ERR;
if (msg->what != MSG_TYPE_LANE_LINK_TIMEOUT || msg->arg1 != info->laneReqId) {
return SOFTBUS_INVALID_PARAM;
}
if (info->linkType == LANE_LINK_TYPE_BUTT) {
LNN_LOGI(LNN_LANE, "remove build link timeout message succ. laneReqId=%{public}u, linkType=%{public}d",
info->laneReqId, info->linkType);
return SOFTBUS_OK;
}
if (msg->arg2 == info->linkType) {
LNN_LOGI(LNN_LANE, "remove build link timeout message succ. laneReqId=%{public}u, linkType=%{public}d",
info->laneReqId, info->linkType);
return SOFTBUS_OK;
}
LNN_LOGE(LNN_LANE, "remove build link timeout message fail. laneReqId=%{public}u, linkType=%{public}d",
info->laneReqId, info->linkType);
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
static void RemoveLaneTimeoutMessage(uint32_t laneReqId, LaneLinkType linkType)
static void RemoveLinkTimeoutMessage(uint32_t laneReqId, LaneLinkType linkType)
{
LNN_LOGI(LNN_LANE, "remove build link timeout message. laneReqId=%{public}u, linkType=%{public}d",
laneReqId, linkType);
@ -171,7 +173,7 @@ static void RemoveLaneTimeoutMessage(uint32_t laneReqId, LaneLinkType linkType)
.linkType = linkType,
};
g_laneLoopHandler.looper->RemoveMessageCustom(g_laneLoopHandler.looper, &g_laneLoopHandler,
RemoveLaneTimeout, &info);
RemoveLinkTimeout, &info);
}
static void LinkSuccess(uint32_t laneReqId, LaneLinkType linkType, const LaneLinkInfo *linkInfo)
@ -180,10 +182,11 @@ static void LinkSuccess(uint32_t laneReqId, LaneLinkType linkType, const LaneLin
LNN_LOGE(LNN_LANE, "linkSuccess param invalid");
return;
}
RemoveLaneTimeoutMessage(laneReqId, linkType);
RemoveLinkTimeoutMessage(laneReqId, linkType);
LaneLinkInfo *linkParam = (LaneLinkInfo *)SoftBusCalloc(sizeof(LaneLinkInfo));
if (linkParam == NULL) {
LNN_LOGE(LNN_LANE, "linkSuccess info malloc fail");
(void)LnnLanePostMsgToHandler(MSG_TYPE_LANE_LINK_FAIL, laneReqId, SOFTBUS_MALLOC_ERR, NULL, 0);
return;
}
if (memcpy_s(linkParam, sizeof(LaneLinkInfo), linkInfo, sizeof(LaneLinkInfo)) != EOK) {
@ -200,15 +203,16 @@ static void LinkSuccess(uint32_t laneReqId, LaneLinkType linkType, const LaneLin
static void LinkFail(uint32_t laneReqId, int32_t reason, LaneLinkType linkType)
{
RemoveLaneTimeoutMessage(laneReqId, linkType);
RemoveLinkTimeoutMessage(laneReqId, linkType);
LinkFailInfo *failInfo = (LinkFailInfo *)SoftBusCalloc(sizeof(LinkFailInfo));
if (failInfo == NULL) {
LNN_LOGE(LNN_LANE, "failInfo malloc fail");
(void)LnnLanePostMsgToHandler(MSG_TYPE_LANE_LINK_FAIL, laneReqId, SOFTBUS_MALLOC_ERR, NULL, 0);
return;
}
failInfo->reason = reason;
failInfo->linkType = linkType;
if (LnnLanePostMsgToHandler(MSG_TYPE_LANE_LINK_FAIL, laneReqId, 0, failInfo, 0) != SOFTBUS_OK) {
if (LnnLanePostMsgToHandler(MSG_TYPE_LANE_LINK_FAIL, laneReqId, reason, failInfo, 0) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "post lanelink fail msg err");
SoftBusFree(failInfo);
}
@ -233,11 +237,11 @@ static void DeleteLaneLinkNode(uint32_t laneReqId)
Unlock();
}
static int32_t PostLaneTimeoutMessage(uint32_t laneReqId, LaneLinkType linkType, uint64_t delayMillis)
static int32_t PostLinkTimeoutMessage(uint32_t laneReqId, LaneLinkType linkType, uint64_t delayMillis)
{
LNN_LOGI(LNN_LANE, "post build link timeout message, laneReqId=%{public}u, linkType=%{public}d",
laneReqId, linkType);
return LnnLanePostMsgToHandler(MSG_TYPE_LANE_RESULT_TIMEOUT, laneReqId, linkType, NULL, delayMillis);
return LnnLanePostMsgToHandler(MSG_TYPE_LANE_LINK_TIMEOUT, laneReqId, linkType, NULL, delayMillis);
}
static void InitStatusList(LaneLinkNodeInfo *linkNode)
@ -277,7 +281,9 @@ static int32_t TriggerLink(uint32_t laneReqId, TransOption *request,
linkNode->p2pOnly = request->p2pOnly;
linkNode->p2pErrCode = SOFTBUS_OK;
linkNode->acceptableProtocols = request->acceptableProtocols;
linkNode->startTime = SoftBusGetSysTimeMs();
linkNode->restTime = DEFAULT_LINK_LATENCY;
linkNode->isCompleted = false;
InitStatusList(linkNode);
ListInit(&linkNode->node);
if (Lock() != SOFTBUS_OK) {
@ -292,11 +298,6 @@ static int32_t TriggerLink(uint32_t laneReqId, TransOption *request,
DeleteLaneLinkNode(laneReqId);
return ret;
}
ret = PostLaneTimeoutMessage(laneReqId, LANE_LINK_TYPE_BUTT, DEFAULT_LINK_LATENCY);
if (ret != SOFTBUS_OK) {
DeleteLaneLinkNode(laneReqId);
return ret;
}
return SOFTBUS_OK;
}
@ -393,11 +394,12 @@ static int32_t TriggerLinkWithQos(uint32_t laneReqId, const LaneAllocInfo *alloc
linkNode->linkList = recommendLinkList;
linkNode->pid = allocInfo->pid;
linkNode->networkDelegate = allocInfo->extendInfo.networkDelegate;
linkNode->p2pErrCode = SOFTBUS_OK;
linkNode->p2pErrCode = SOFTBUS_LANE_TRIGGER_LINK_FAIL;
linkNode->acceptableProtocols = allocInfo->acceptableProtocols;
linkNode->startTime = SoftBusGetSysTimeMs();
linkNode->restTime = allocInfo->qosRequire.maxLaneLatency != 0 ?
allocInfo->qosRequire.maxLaneLatency : DEFAULT_LINK_LATENCY;
uint64_t maxLaneLatency = linkNode->restTime;
linkNode->isCompleted = false;
InitStatusList(linkNode);
ListInit(&linkNode->node);
if (Lock() != SOFTBUS_OK) {
@ -412,11 +414,6 @@ static int32_t TriggerLinkWithQos(uint32_t laneReqId, const LaneAllocInfo *alloc
DeleteLaneLinkNode(laneReqId);
return ret;
}
ret = PostLaneTimeoutMessage(laneReqId, LANE_LINK_TYPE_BUTT, maxLaneLatency);
if (ret != SOFTBUS_OK) {
DeleteLaneLinkNode(laneReqId);
return ret;
}
return SOFTBUS_OK;
}
@ -485,8 +482,9 @@ static int32_t AllocValidLane(uint32_t laneReqId, uint64_t allocLaneId, const La
static int32_t AllocLaneByQos(uint32_t laneReqId, const LaneAllocInfo *allocInfo, const LaneAllocListener *listener)
{
if (laneReqId == INVALID_LANE_REQ_ID || allocInfo == NULL || allocInfo->type != LANE_TYPE_TRANS) {
LNN_LOGE(LNN_LANE, "AllocLane param invalid");
if (laneReqId == INVALID_LANE_REQ_ID || allocInfo == NULL ||
allocInfo->type != LANE_TYPE_TRANS || listener == NULL) {
LNN_LOGE(LNN_LANE, "allocLane param invalid");
return SOFTBUS_INVALID_PARAM;
}
int32_t ret = AllocValidLane(laneReqId, INVALID_LANE_ID, allocInfo, listener);
@ -502,14 +500,15 @@ static int32_t ReallocLaneByQos(uint32_t laneReqId, uint64_t laneId, const LaneA
const LaneAllocListener *listener)
{
if (laneReqId == INVALID_LANE_REQ_ID || allocInfo == NULL || allocInfo->type != LANE_TYPE_TRANS ||
laneId == INVALID_LANE_ID) {
LNN_LOGE(LNN_LANE, "AllocLane param invalid");
listener == NULL || laneId == INVALID_LANE_ID) {
LNN_LOGE(LNN_LANE, "reallocLane param invalid");
return SOFTBUS_INVALID_PARAM;
}
if (AllocValidLane(laneReqId, laneId, allocInfo, listener) != SOFTBUS_OK) {
int32_t ret = AllocValidLane(laneReqId, laneId, allocInfo, listener);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "alloc valid lane fail, laneReqId=%{public}u", laneReqId);
FreeLaneReqId(laneReqId);
return SOFTBUS_ERR;
return ret;
}
return SOFTBUS_OK;
}
@ -530,37 +529,38 @@ static int32_t Alloc(uint32_t laneReqId, const LaneRequestOption *request, const
}
LanePreferredLinkList *recommendLinkList = (LanePreferredLinkList *)SoftBusMalloc(sizeof(LanePreferredLinkList));
if (recommendLinkList == NULL) {
return SOFTBUS_ERR;
return SOFTBUS_MALLOC_ERR;
}
recommendLinkList->linkTypeNum = 0;
uint32_t listNum = 0;
if (SelectLane((const char *)transRequest->networkId, &selectParam, recommendLinkList, &listNum) != SOFTBUS_OK) {
SoftBusFree(recommendLinkList);
return SOFTBUS_ERR;
return SOFTBUS_LANE_SELECT_FAIL;
}
if (recommendLinkList->linkTypeNum == 0) {
LNN_LOGE(LNN_LANE, "no link resources available, alloc fail");
SoftBusFree(recommendLinkList);
return SOFTBUS_ERR;
return SOFTBUS_LANE_SELECT_FAIL;
}
LNN_LOGI(LNN_LANE, "select lane link success, linkNum=%{public}d, laneReqId=%{public}u", listNum, laneReqId);
TransReqInfo *newItem = CreateRequestNode(laneReqId, transRequest, listener);
if (newItem == NULL) {
SoftBusFree(recommendLinkList);
return SOFTBUS_ERR;
return SOFTBUS_MEM_ERR;
}
if (Lock() != SOFTBUS_OK) {
SoftBusFree(newItem);
SoftBusFree(recommendLinkList);
return SOFTBUS_ERR;
return SOFTBUS_LOCK_ERR;
}
ListTailInsert(&g_requestList->list, &newItem->node);
g_requestList->cnt++;
Unlock();
if (TriggerLink(laneReqId, transRequest, recommendLinkList) != SOFTBUS_OK) {
int32_t ret = TriggerLink(laneReqId, transRequest, recommendLinkList);
if (ret != SOFTBUS_OK) {
SoftBusFree(recommendLinkList);
DeleteRequestNode(laneReqId);
return SOFTBUS_ERR;
return ret;
}
return SOFTBUS_OK;
}
@ -604,7 +604,7 @@ static int32_t CancelLane(uint32_t laneReqId)
if (item->isNotified) {
Unlock();
LNN_LOGE(LNN_LANE, "cancel lane fail, lane result has notified, laneReqId=%{public}u", laneReqId);
return SOFTBUS_ERR;
return SOFTBUS_INVALID_PARAM;
}
item->isCanceled = true;
Unlock();
@ -614,7 +614,7 @@ static int32_t CancelLane(uint32_t laneReqId)
}
Unlock();
LNN_LOGE(LNN_LANE, "cancel lane fail, lane reqinfo not find, laneReqId=%{public}u", laneReqId);
return SOFTBUS_ERR;
return SOFTBUS_NOT_FIND;
}
static void IsNeedDelayFreeLane(uint32_t laneReqId, uint64_t laneId, bool *isDelayFree)
@ -635,7 +635,7 @@ static void IsNeedDelayFreeLane(uint32_t laneReqId, uint64_t laneId, bool *isDel
return;
}
static int32_t Freelink(uint32_t laneReqId, uint64_t laneId, LaneType type)
static int32_t FreeLink(uint32_t laneReqId, uint64_t laneId, LaneType type)
{
(void)DelLaneBusinessInfoItem(type, laneId);
bool isDelayDestroy = false;
@ -652,7 +652,7 @@ static int32_t Free(uint32_t laneReqId)
{
if (Lock() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get lock fail");
return SOFTBUS_ERR;
return SOFTBUS_LOCK_ERR;
}
LaneType type = (LaneType)(laneReqId >> LANE_REQ_ID_TYPE_SHIFT);
TransReqInfo *item = NULL;
@ -662,7 +662,7 @@ static int32_t Free(uint32_t laneReqId)
ListDelete(&item->node);
g_requestList->cnt--;
Unlock();
Freelink(laneReqId, item->laneId, type);
FreeLink(laneReqId, item->laneId, type);
SoftBusFree(item);
FreeLaneReqId(laneReqId);
return SOFTBUS_OK;
@ -728,9 +728,6 @@ static void NotifyLaneAllocSuccess(uint32_t laneReqId, uint64_t laneId, const La
static void NotifyLaneAllocFail(uint32_t laneReqId, int32_t reason)
{
if (reason == SOFTBUS_OK) {
reason = SOFTBUS_LANE_SELECT_FAIL;
}
UpdateReqInfoWithLaneReqId(laneReqId, INVALID_LANE_ID);
TransReqInfo reqInfo;
(void)memset_s(&reqInfo, sizeof(TransReqInfo), 0, sizeof(TransReqInfo));
@ -808,8 +805,7 @@ static void LaneTriggerLink(SoftBusMessage *msg)
.OnLaneLinkSuccess = LinkSuccess,
.OnLaneLinkFail = LinkFail,
};
LinkRequest requestInfo;
(void)memset_s(&requestInfo, sizeof(LinkRequest), 0, sizeof(LinkRequest));
LinkRequest requestInfo = {0};
if (Lock() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get lock fail");
return;
@ -822,11 +818,6 @@ static void LaneTriggerLink(SoftBusMessage *msg)
}
int32_t ret = SOFTBUS_LANE_TRIGGER_LINK_FAIL;
do {
if (nodeInfo->linkRetryIdx >= nodeInfo->listNum) {
LNN_LOGE(LNN_LANE, "All linkType have been tried");
Unlock();
break;
}
ret = CreateLinkRequestNode(nodeInfo, &requestInfo);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "Create LinkRequestNode fail.");
@ -836,9 +827,8 @@ static void LaneTriggerLink(SoftBusMessage *msg)
nodeInfo->linkRetryIdx++;
nodeInfo->statusList[requestInfo.linkType].status = BUILD_LINK_STATUS_BUILDING;
Unlock();
uint64_t delayMillis = g_laneLatency[requestInfo.linkType] * 9 / 10;
// latancy * 9 / 10: timeout for each type of build link
(void)PostLaneTimeoutMessage(laneReqId, requestInfo.linkType, delayMillis);
uint64_t delayMillis = g_laneLatency[requestInfo.linkType];
(void)PostLinkTimeoutMessage(laneReqId, requestInfo.linkType, delayMillis);
ret = BuildLink(&requestInfo, laneReqId, &linkCb);
if (ret == SOFTBUS_OK) {
return;
@ -874,16 +864,16 @@ static int32_t UpdateLinkStatus(uint32_t laneReqId, BuildLinkStatus status, Lane
if (status == BUILD_LINK_STATUS_SUCC) {
FreeUnusedLink(laneReqId, linkInfo);
}
return SOFTBUS_ERR;
return SOFTBUS_NOT_FIND;
}
if (nodeInfo->isCompleted) {
Unlock();
LNN_LOGE(LNN_LANE, "build link has completed, not need update link status. laneReqId=%{public}u, "
LNN_LOGI(LNN_LANE, "build link has completed, not need update link status. laneReqId=%{public}u, "
"linkType=%{public}d", laneReqId, linkType);
if (status == BUILD_LINK_STATUS_SUCC) {
FreeUnusedLink(laneReqId, linkInfo);
}
return SOFTBUS_ERR;
return SOFTBUS_LANE_TRIGGER_LINK_FAIL;
}
LNN_LOGI(LNN_LANE, "update link status, laneReqId=%{public}u, status=%{public}d, linkType=%{public}d",
laneReqId, status, linkType);
@ -893,10 +883,10 @@ static int32_t UpdateLinkStatus(uint32_t laneReqId, BuildLinkStatus status, Lane
return SOFTBUS_OK;
}
if (memcpy_s(&(nodeInfo->statusList[linkType].linkInfo), sizeof(LaneLinkInfo), linkInfo,
sizeof(LaneLinkInfo)) != EOK) {
sizeof(LaneLinkInfo)) != EOK) {
LNN_LOGE(LNN_LANE, "linkParam memcpy fail, laneReqId=%{public}u", laneReqId);
Unlock();
return SOFTBUS_ERR;
return SOFTBUS_MEM_ERR;
}
Unlock();
return SOFTBUS_OK;
@ -918,7 +908,10 @@ static bool IsNeedNotifySucc(uint32_t laneReqId)
for (uint32_t i = 0; i < nodeInfo->listNum; i++) {
LaneLinkType linkType = nodeInfo->linkList->linkType[i];
if (nodeInfo->statusList[linkType].status == BUILD_LINK_STATUS_BUILDING) {
Unlock();
isBuilding = true;
LNN_LOGE(LNN_LANE, "has exist building link, laneReqId=%{public}u", laneReqId);
return false;
}
if (!isBuilding && nodeInfo->statusList[linkType].status == BUILD_LINK_STATUS_SUCC) {
nodeInfo->isCompleted = true;
@ -940,16 +933,16 @@ static int32_t GetLaneLinkInfo(uint32_t laneReqId, LaneLinkType *type, LaneLinkI
if (nodeInfo == NULL) {
Unlock();
LNN_LOGE(LNN_LANE, "get lane link node info fail, laneReqId=%{public}u", laneReqId);
return SOFTBUS_ERR;
return SOFTBUS_NOT_FIND;
}
for (uint32_t i = 0; i < nodeInfo->listNum; i++) {
LaneLinkType linkType = nodeInfo->linkList->linkType[i];
if (nodeInfo->statusList[linkType].status == BUILD_LINK_STATUS_SUCC) {
if (memcpy_s(info, sizeof(LaneLinkInfo), &(nodeInfo->statusList[linkType].linkInfo),
sizeof(LaneLinkInfo)) != EOK) {
sizeof(LaneLinkInfo)) != EOK) {
Unlock();
LNN_LOGE(LNN_LANE, "info memcpy fail, laneReqId=%{public}u", laneReqId);
return SOFTBUS_ERR;
return SOFTBUS_MEM_ERR;
}
*type = linkType;
Unlock();
@ -958,7 +951,7 @@ static int32_t GetLaneLinkInfo(uint32_t laneReqId, LaneLinkType *type, LaneLinkI
}
Unlock();
LNN_LOGE(LNN_LANE, "not found LaneLinkInfo, laneReqId=%{public}u", laneReqId);
return SOFTBUS_ERR;
return SOFTBUS_NOT_FIND;
}
static void FreeLowPriorityLink(uint32_t laneReqId, LaneLinkType linkType)
@ -980,7 +973,7 @@ static void FreeLowPriorityLink(uint32_t laneReqId, LaneLinkType linkType)
LaneLinkType type = nodeInfo->linkList->linkType[i];
if (type != linkType && nodeInfo->statusList[type].status == BUILD_LINK_STATUS_SUCC) {
if (memcpy_s(&statusList[listNum++], sizeof(LinkStatusInfo), &nodeInfo->statusList[type],
sizeof(LinkStatusInfo)) != EOK) {
sizeof(LinkStatusInfo)) != EOK) {
continue;
}
}
@ -995,29 +988,29 @@ static void NotifyLinkSucc(uint32_t laneReqId)
{
LaneLinkType linkType;
LaneLinkInfo info;
int32_t ret = SOFTBUS_LANE_TRIGGER_LINK_FAIL;
(void)memset_s(&info, sizeof(LaneLinkInfo), 0, sizeof(LaneLinkInfo));
if (GetLaneLinkInfo(laneReqId, &linkType, &info) != SOFTBUS_OK) {
ret = GetLaneLinkInfo(laneReqId, &linkType, &info);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get LaneLinkInfo fail, laneReqId=%{public}u", laneReqId);
NotifyLaneAllocFail(laneReqId, SOFTBUS_LANE_TRIGGER_LINK_FAIL);
return;
goto FAIL;
}
char localUdid[UDID_BUF_LEN] = {0};
if (LnnGetLocalStrInfo(STRING_KEY_DEV_UDID, localUdid, UDID_BUF_LEN) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get udid fail, laneReqId=%{public}u", laneReqId);
NotifyLaneAllocFail(laneReqId, SOFTBUS_LANE_TRIGGER_LINK_FAIL);
return;
ret = SOFTBUS_LANE_GET_LEDGER_INFO_ERR;
goto FAIL;
}
uint64_t laneId = ApplyLaneId(localUdid, info.peerUdid, info.type);
uint64_t laneId = GenerateLaneId(localUdid, info.peerUdid, info.type);
if (laneId == INVALID_LANE_ID) {
LNN_LOGE(LNN_LANE, "apply laneId fail, laneReqId=%{public}u", laneReqId);
NotifyLaneAllocFail(laneReqId, SOFTBUS_LANE_TRIGGER_LINK_FAIL);
return;
LNN_LOGE(LNN_LANE, "generate laneId fail, laneReqId=%{public}u", laneReqId);
ret = SOFTBUS_LANE_ID_GENERATE_FAIL;
goto FAIL;
}
int32_t ret = AddLaneResourceToPool(&info, laneId, false);
ret = AddLaneResourceToPool(&info, laneId, false);
if (ret != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "add linkInfo item fail, laneReqId=%{public}u", laneReqId);
NotifyLaneAllocFail(laneReqId, SOFTBUS_LANE_TRIGGER_LINK_FAIL);
return;
goto FAIL;
}
NotifyLaneAllocSuccess(laneReqId, laneId, &info);
FreeLowPriorityLink(laneReqId, linkType);
@ -1026,6 +1019,9 @@ static void NotifyLinkSucc(uint32_t laneReqId)
AddLaneBusinessInfoItem(laneType, laneId) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "create laneBusinessInfo fail, laneReqId=%{public}u", laneReqId);
}
return;
FAIL:
NotifyLaneAllocFail(laneReqId, ret);
}
static void LaneLinkSuccess(SoftBusMessage *msg)
@ -1044,80 +1040,119 @@ static void LaneLinkSuccess(SoftBusMessage *msg)
}
SoftBusFree(info);
if (IsNeedNotifySucc(laneReqId)) {
RemoveLaneTimeoutMessage(laneReqId, LANE_LINK_TYPE_BUTT);
RemoveLinkTimeoutMessage(laneReqId, LANE_LINK_TYPE_BUTT);
NotifyLinkSucc(laneReqId);
DeleteLaneLinkNode(laneReqId);
}
}
static void NotifyRetryOrFail(uint32_t laneReqId, LaneLinkType linkType, int32_t reason)
static bool IsNeedNotifyFail(uint32_t laneReqId, int32_t reason, int32_t *failReason)
{
int32_t failReason = SOFTBUS_ERR;
bool allFail = false;
bool needRetry = false;
bool notifyFail = false;
if (Lock() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get lock fail");
return true;
}
LaneLinkNodeInfo *nodeInfo = GetLaneLinkNodeWithoutLock(laneReqId);
if (nodeInfo == NULL) {
Unlock();
LNN_LOGE(LNN_LANE, "get lane link node info fail, laneReqId=%{public}u", laneReqId);
return true;
}
if ((reason >= ERROR_WIFI_DIRECT_END && reason <= ERROR_BASE) ||
(reason >= V1_ERROR_END && reason <= V1_ERROR_START) || nodeInfo->linkRetryIdx == 1) {
nodeInfo->p2pErrCode = reason;
}
*failReason = nodeInfo->p2pErrCode;
uint64_t costTime = SoftBusGetSysTimeMs() - nodeInfo->startTime;
if (costTime >= nodeInfo->restTime || nodeInfo->linkRetryIdx >= nodeInfo->listNum) {
LNN_LOGE(LNN_LANE, "link retry exceed limit, laneReqId=%{public}u", laneReqId);
notifyFail = true;
}
if (!notifyFail) {
nodeInfo->isCompleted = notifyFail ? true : false;
Unlock();
return notifyFail;
}
for (uint32_t i = 0; i < nodeInfo->linkRetryIdx; i++) {
LaneLinkType linkType = nodeInfo->linkList->linkType[i];
if (nodeInfo->statusList[linkType].status != BUILD_LINK_STATUS_FAIL) {
notifyFail = false;
}
}
nodeInfo->isCompleted = notifyFail ? true : false;
Unlock();
return notifyFail;
}
static void BuildLinkRetry(uint32_t laneReqId)
{
bool needRetry = true;
if (Lock() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get lock fail");
NotifyLaneAllocFail(laneReqId, SOFTBUS_LOCK_ERR);
return;
}
LaneLinkNodeInfo *nodeInfo = GetLaneLinkNodeWithoutLock(laneReqId);
if (nodeInfo == NULL) {
Unlock();
LNN_LOGE(LNN_LANE, "get lane link node info fail, laneReqId=%{public}u", laneReqId);
NotifyLaneAllocFail(laneReqId, SOFTBUS_NOT_FIND);
return;
}
if ((reason >= ERROR_WIFI_DIRECT_END && reason <= ERROR_WIFI_DIRECT_START) ||
(reason >= V1_ERROR_END && reason <= V1_ERROR_START) || nodeInfo->linkRetryIdx == 1) {
nodeInfo->p2pErrCode = reason;
}
failReason = nodeInfo->p2pErrCode;
if (nodeInfo->linkRetryIdx >= nodeInfo->listNum) {
LNN_LOGE(LNN_LANE, "All linkType have been tried, laneReqId=%{public}u", laneReqId);
allFail = true;
} else {
needRetry = true;
uint64_t costTime = SoftBusGetSysTimeMs() - nodeInfo->startTime;
if (costTime >= nodeInfo->restTime || nodeInfo->linkRetryIdx >= nodeInfo->listNum) {
LNN_LOGE(LNN_LANE, "link retry exceed limit, laneReqId=%{public}u", laneReqId);
Unlock();
return;
}
for (uint32_t i = 0; i < nodeInfo->linkRetryIdx; i++) {
LaneLinkType linkType = nodeInfo->linkList->linkType[i];
if (nodeInfo->statusList[linkType].status != BUILD_LINK_STATUS_FAIL) {
allFail = false;
}
if (nodeInfo->statusList[linkType].status == BUILD_LINK_STATUS_SUCC) {
LNN_LOGI(LNN_LANE, "has exist high priority succ link, laneReqId=%{public}u", laneReqId);
needRetry = false;
}
if (nodeInfo->linkRetryIdx < nodeInfo->listNum &&
nodeInfo->linkList->linkType[nodeInfo->linkRetryIdx] == LANE_P2P && linkType == LANE_HML &&
nodeInfo->statusList[linkType].status == BUILD_LINK_STATUS_BUILDING) {
LNN_LOGI(LNN_LANE, "refuse same type link repeat build, laneReqId=%{public}u", laneReqId);
needRetry = false;
}
}
nodeInfo->isCompleted = allFail ? true : false;
Unlock();
if (allFail) {
RemoveLaneTimeoutMessage(laneReqId, LANE_LINK_TYPE_BUTT);
NotifyLaneAllocFail(laneReqId, failReason);
DeleteLaneLinkNode(laneReqId);
}
if (needRetry) {
LNN_LOGI(LNN_LANE, "continue to build link, laneReqId=%{public}u", laneReqId);
(void)LnnLanePostMsgToHandler(MSG_TYPE_LANE_TRIGGER_LINK, laneReqId, 0, NULL, 0);
}
}
static void LaneLinkFail(SoftBusMessage *msg)
{
uint32_t laneReqId = (uint32_t)msg->arg1;
int32_t failReason = (int32_t)msg->arg2;
if (msg->obj == NULL) {
LNN_LOGE(LNN_LANE, "invalid msg->obj");
NotifyLaneAllocFail(laneReqId, failReason);
return;
}
LinkFailInfo *failInfo = (LinkFailInfo *)msg->obj;
int32_t reason = failInfo->reason;
LaneLinkType linkType = failInfo->linkType;
SoftBusFree(failInfo);
uint32_t laneReqId = (uint32_t)msg->arg1;
LNN_LOGI(LNN_LANE, "lane link fail, laneReqId=%{public}u, reason=%{public}d", laneReqId, reason);
if (UpdateLinkStatus(laneReqId, BUILD_LINK_STATUS_FAIL, linkType, NULL) != SOFTBUS_OK) {
return;
}
if (IsNeedNotifySucc(laneReqId)) {
RemoveLaneTimeoutMessage(laneReqId, LANE_LINK_TYPE_BUTT);
RemoveLinkTimeoutMessage(laneReqId, LANE_LINK_TYPE_BUTT);
NotifyLinkSucc(laneReqId);
DeleteLaneLinkNode(laneReqId);
} else if (IsNeedNotifyFail(laneReqId, reason, &failReason)) {
RemoveLinkTimeoutMessage(laneReqId, LANE_LINK_TYPE_BUTT);
NotifyLaneAllocFail(laneReqId, failReason);
DeleteLaneLinkNode(laneReqId);
} else {
NotifyRetryOrFail(laneReqId, linkType, reason);
BuildLinkRetry(laneReqId);
}
}
@ -1161,8 +1196,10 @@ static void HandleDetectTimeout(SoftBusMessage *msg)
NotifyDetectTimeout(detectId);
}
static void HandleWholeProcessTimeout(uint32_t laneReqId)
static void HandleLinkTimeout(SoftBusMessage *msg)
{
uint32_t laneReqId = (uint32_t)msg->arg1;
LaneLinkType timeoutLinkType = (LaneLinkType)msg->arg2;
if (Lock() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get lock fail");
return;
@ -1173,49 +1210,17 @@ static void HandleWholeProcessTimeout(uint32_t laneReqId)
LNN_LOGE(LNN_LANE, "get lane link node info fail, laneReqId=%{public}u", laneReqId);
return;
}
int32_t failReason = nodeInfo->p2pErrCode;
if (nodeInfo->p2pErrCode == SOFTBUS_OK) {
nodeInfo->p2pErrCode = SOFTBUS_TIMOUT;
failReason = SOFTBUS_TIMOUT;
}
bool hasSucc = false;
for (uint32_t i = 0; i < nodeInfo->listNum; i++) {
LaneLinkType linkType = nodeInfo->linkList->linkType[i];
if (nodeInfo->statusList[linkType].status == BUILD_LINK_STATUS_SUCC) {
hasSucc = true;
break;
}
}
nodeInfo->isCompleted = true;
Unlock();
if (hasSucc) {
NotifyLinkSucc(laneReqId);
} else {
NotifyLaneAllocFail(laneReqId, failReason);
}
DeleteLaneLinkNode(laneReqId);
}
static void HandleTypeProcessTimeout(uint32_t laneReqId)
{
if (Lock() != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get lock fail");
return;
}
LaneLinkNodeInfo *nodeInfo = GetLaneLinkNodeWithoutLock(laneReqId);
if (nodeInfo == NULL) {
Unlock();
LNN_LOGE(LNN_LANE, "get lane link node info fail, laneReqId=%{public}u", laneReqId);
return;
}
if (nodeInfo->linkRetryIdx >= nodeInfo->listNum) {
LNN_LOGE(LNN_LANE, "All linkType have been tried, laneReqId=%{public}u", laneReqId);
uint64_t costTime = SoftBusGetSysTimeMs() - nodeInfo->startTime;
if (costTime >= nodeInfo->restTime || nodeInfo->linkRetryIdx >= nodeInfo->listNum) {
LNN_LOGE(LNN_LANE, "link retry exceed limit, laneReqId=%{public}u", laneReqId);
Unlock();
return;
}
for (uint32_t i = 0; i < nodeInfo->linkRetryIdx; i++) {
LaneLinkType linkType = nodeInfo->linkList->linkType[i];
if (nodeInfo->statusList[linkType].status == BUILD_LINK_STATUS_SUCC) {
LNN_LOGI(LNN_LANE, "a successful link already exist, laneReqId=%{public}u, linkType=%{public}d",
laneReqId, linkType);
Unlock();
return;
}
@ -1231,20 +1236,11 @@ static void HandleTypeProcessTimeout(uint32_t laneReqId)
}
}
Unlock();
LNN_LOGI(LNN_LANE, "continue to build link, laneReqId=%{public}u, timeoutLinkType=%{public}d",
laneReqId, timeoutLinkType);
(void)LnnLanePostMsgToHandler(MSG_TYPE_LANE_TRIGGER_LINK, laneReqId, 0, NULL, 0);
}
static void HandleLaneTimeout(SoftBusMessage *msg)
{
uint32_t laneReqId = (uint32_t)msg->arg1;
LaneLinkType linkType = (LaneLinkType)msg->arg2;
if (linkType == LANE_LINK_TYPE_BUTT) {
HandleWholeProcessTimeout(laneReqId);
} else {
HandleTypeProcessTimeout(laneReqId);
}
}
static void MsgHandler(SoftBusMessage *msg)
{
if (msg == NULL) {
@ -1269,8 +1265,8 @@ static void MsgHandler(SoftBusMessage *msg)
case MSG_TYPE_LANE_DETECT_TIMEOUT:
HandleDetectTimeout(msg);
break;
case MSG_TYPE_LANE_RESULT_TIMEOUT:
HandleLaneTimeout(msg);
case MSG_TYPE_LANE_LINK_TIMEOUT:
HandleLinkTimeout(msg);
break;
default:
LNN_LOGE(LNN_LANE, "msg type=%{public}d cannot found", msg->what);
@ -1448,70 +1444,6 @@ int32_t PostLaneStateChangeMessage(LaneState state, const char *peerUdid, const
return SOFTBUS_OK;
}
static int32_t AllocAuthLane(uint32_t laneHandle, const LaneAllocInfo *allocInfo, const LaneAllocListener *listener)
{
AuthLinkTypeList authList;
if (memset_s(&authList, sizeof(AuthLinkTypeList), 0, sizeof(AuthLinkTypeList)) != EOK) {
LNN_LOGE(LNN_LANE, "memset_s authList fail");
return SOFTBUS_ERR;
}
if (GetAuthLinkTypeList(allocInfo->networkId, &authList) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "get authList fail");
return SOFTBUS_ERR;
}
LanePreferredLinkList request;
if (memset_s(&request, sizeof(LanePreferredLinkList), 0, sizeof(LanePreferredLinkList)) != EOK) {
LNN_LOGE(LNN_LANE, "memset_s request fail");
return SOFTBUS_ERR;
}
if (ConvertAuthLinkToLaneLink(&authList, &request) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "convert authLink to laneLink fail");
return SOFTBUS_ERR;
}
LanePreferredLinkList *recommendLinkList = (LanePreferredLinkList *)SoftBusCalloc(sizeof(LanePreferredLinkList));
if (recommendLinkList == NULL) {
LNN_LOGE(LNN_LANE, "calloc recommendLinkList fail");
return SOFTBUS_MALLOC_ERR;
}
recommendLinkList->linkTypeNum = 0;
if (SelectAuthLane(allocInfo->networkId, &request, recommendLinkList) != SOFTBUS_OK ||
recommendLinkList->linkTypeNum == 0) {
SoftBusFree(recommendLinkList);
LNN_LOGE(LNN_LANE, "no abailable link resources, laneHandle=%{public}u", laneHandle);
return SOFTBUS_ERR;
}
for (uint32_t i = 0; i < recommendLinkList->linkTypeNum; ++i) {
LNN_LOGI(LNN_LANE, "auth expect recommendLinkList nums=%{public}u, priority=%{public}u, link=%{public}u",
recommendLinkList->linkTypeNum, i, recommendLinkList->linkType[i]);
}
if (StartTriggerLink(laneHandle, allocInfo, listener, recommendLinkList) != SOFTBUS_OK) {
SoftBusFree(recommendLinkList);
LNN_LOGE(LNN_LANE, "trigger link fail, laneHandle=%{public}u", laneHandle);
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
int32_t CtrlAlloc(uint32_t laneHandle, const LaneAllocInfo *allocInfo, const LaneAllocListener *listener)
{
if (laneHandle == INVALID_LANE_REQ_ID || allocInfo == NULL || allocInfo->type != LANE_TYPE_CTRL) {
LNN_LOGE(LNN_LANE, "param invalid");
return SOFTBUS_INVALID_PARAM;
}
if (AllocAuthLane(laneHandle, allocInfo, listener) != SOFTBUS_OK) {
LNN_LOGE(LNN_LANE, "alloc valid lane fail, laneHandle=%{public}u", laneHandle);
FreeLaneReqId(laneHandle);
return SOFTBUS_ERR;
}
return SOFTBUS_OK;
}
int32_t CtrlFree(uint32_t laneHandle)
{
return Free(laneHandle);
}
static int32_t RemoveDelayDestroy(const SoftBusMessage *msg, void *data)
{
uint64_t *laneId = (uint64_t *)data;

View File

@ -389,6 +389,8 @@ enum SoftBusErrNo {
SOFTBUS_LANE_DETECT_FAIL,
SOFTBUS_LANE_ID_GENERATE_FAIL,
SOFTBUS_LANE_GUIDE_BUILD_FAIL,
SOFTBUS_LANE_NOT_FIND,
SOFTBUS_LANE_RESOURCE_NOT_FIND,
/* errno begin: -((203 << 21) | (2 << 16) | 0xFFFF) */
SOFTBUS_CONN_ERR_BASE = SOFTBUS_ERRNO(CONN_SUB_MODULE_CODE),

View File

@ -166,7 +166,6 @@ ohos_unittest("AuthEnhanceMockTest") {
"$dsoftbus_root_path/core/adapter/authentication/include",
"$dsoftbus_root_path/core/bus_center/service/include",
"$dsoftbus_root_path/core/connection/ble/include",
"$dsoftbus_root_path/core/connection/wifi_direct/utils",
"$dsoftbus_root_path/core/connection/wifi_direct_cpp",
]
@ -270,7 +269,6 @@ ohos_unittest("AuthTestCallBackTest") {
"$dsoftbus_root_path/core/bus_center/service/include",
"$dsoftbus_root_path/core/adapter/authentication/include",
"$dsoftbus_root_path/core/connection/ble/include",
"$dsoftbus_root_path/core/connection/wifi_direct/utils",
"$dsoftbus_root_path/core/connection/wifi_direct_cpp",
]
@ -337,9 +335,6 @@ ohos_unittest("AuthOtherTest") {
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/heartbeat/include",
"$dsoftbus_root_path/core/bus_center/service/include",
"$dsoftbus_root_path/core/adapter/authentication/include",
"$dsoftbus_root_path/core/connection/wifi_direct/utils",
"$dsoftbus_root_path/core/authentication/interface",
"$dsoftbus_root_path/tests/core/bus_center/mock_common/include",
"$dsoftbus_root_path/core/connection/wifi_direct_cpp",
]
@ -634,9 +629,6 @@ ohos_unittest("AuthManagerTest") {
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/heartbeat/include",
"$dsoftbus_root_path/core/bus_center/service/include",
"$dsoftbus_root_path/core/adapter/authentication/include",
"$dsoftbus_root_path/core/connection/wifi_direct/utils",
"$dsoftbus_root_path/core/connection/wifi_direct",
"$dsoftbus_root_path/tests/core/bus_center/mock_common/include",
]
deps = [

View File

@ -192,13 +192,13 @@ HWTEST_F(AuthLaneTest, AUTH_GET_REQUEST_OPTION_TEST_001, TestSize.Level1)
LaneAllocInfo allocInfo;
(void)memset_s(&allocInfo, sizeof(LaneAllocInfo), 0, sizeof(LaneAllocInfo));
int32_t ret = AuthGetRequestOption(nullptr, &allocInfo);
int32_t ret = AuthGetLaneAllocInfo(nullptr, &allocInfo);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
ret = AuthGetRequestOption(NETWORK_ID, nullptr);
ret = AuthGetLaneAllocInfo(NETWORK_ID, nullptr);
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
ret = AuthGetRequestOption(NETWORK_ID, &allocInfo);
ret = AuthGetLaneAllocInfo(NETWORK_ID, &allocInfo);
EXPECT_TRUE(ret == SOFTBUS_OK);
}

View File

@ -1319,6 +1319,7 @@ ohos_unittest("LNNLaneMockTest") {
"$dsoftbus_root_path/core/adapter/bus_center/include",
"$dsoftbus_root_path/core/authentication/include",
"$dsoftbus_root_path/core/authentication/interface",
"$dsoftbus_root_path/core/bus_center/interface",
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/lane_manager/include",
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/lane_manager/src",
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/include",
@ -1326,9 +1327,8 @@ ohos_unittest("LNNLaneMockTest") {
"$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/lnn/net_ledger/common/include",
"$dsoftbus_root_path/core/bus_center/interface",
"$dsoftbus_root_path/core/bus_center/utils/include",
"$dsoftbus_root_path/core/bus_center/service/include",
"$dsoftbus_root_path/core/bus_center/utils/include",
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/core/common/dfx/interface/include",
"$dsoftbus_root_path/adapter/common/include",
@ -1337,21 +1337,18 @@ ohos_unittest("LNNLaneMockTest") {
"$dsoftbus_root_path/core/connection/interface",
"$dsoftbus_root_path/core/connection/p2p/interface",
"$dsoftbus_root_path/core/connection/p2p/common/include",
"$dsoftbus_root_path/core/connection/wifi_direct/utils",
"$dsoftbus_root_path/core/discovery/manager/include",
"$dsoftbus_root_path/core/discovery/interface",
"$dsoftbus_root_path/interfaces/inner_kits/lnn",
"$dsoftbus_root_path/interfaces/kits/bus_center",
"$dsoftbus_root_path/interfaces/kits/common",
"$dsoftbus_root_path/interfaces/kits/discovery",
"$dsoftbus_root_path/adapter/common/net/bluetooth/include",
"//commonlibrary/c_utils/base/include",
"//foundation/communication/wifi/wifi/interfaces/kits/c",
"//foundation/communication/wifi/wifi/frameworks/native/include",
"//third_party/cJSON",
"unittest/common/",
"$dsoftbus_root_path/core/connection/ble/include",
"$dsoftbus_root_path/core/connection/wifi_direct/utils",
"$dsoftbus_root_path/core/connection/wifi_direct_cpp",
]
@ -1442,8 +1439,6 @@ ohos_unittest("LNNLaneLinkTest") {
module_out_path = module_output_path
sources = [
"$dsoftbus_root_path/adapter/common/net/wifi/common/softbus_wifi_api_adapter_virtual.c",
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/lane_manager/src/lnn_ctrl_lane.c",
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/lane_manager/src/lnn_lane_common.c",
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/lane_manager/src/lnn_lane_score_virtual.c",
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/lane_manager/src/lnn_select_rule.c",
"$dsoftbus_root_path/core/bus_center/service/src/bus_center_manager.c",
@ -1564,7 +1559,6 @@ ohos_unittest("LNNTransLaneMockTest") {
"//commonlibrary/c_utils/base/include",
"//foundation/communication/wifi/wifi/interfaces/kits/c",
"//foundation/communication/wifi/wifi/frameworks/native/include",
"$dsoftbus_root_path/adapter/common/net/bluetooth/include",
"//third_party/cJSON",
"unittest/common/",
"$dsoftbus_root_path/core/connection/wifi_direct_cpp",
@ -1668,6 +1662,7 @@ ohos_unittest("LNNDiscoveryInterfaceTest") {
ohos_unittest("LNNLaneListenerTest") {
module_out_path = module_output_path
sources = [
"$dsoftbus_root_path/core/bus_center/service/src/bus_center_manager.c",
"$dsoftbus_root_path/tests/core/bus_center/lnn/lane/src/lnn_lane_deps_mock.cpp",
"$dsoftbus_root_path/tests/core/bus_center/lnn/lane_listener/lnn_lane_listener_deps_mock.cpp",
"$dsoftbus_root_path/tests/core/bus_center/lnn/lane_listener/lnn_lane_listener_test.cpp",
@ -1679,27 +1674,32 @@ ohos_unittest("LNNLaneListenerTest") {
"$dsoftbus_root_path/core/authentication/include",
"$dsoftbus_root_path/core/authentication/interface",
"$dsoftbus_root_path/core/bus_center/interface",
"$dsoftbus_root_path/core/bus_center/lnn/decision_center/include",
"$dsoftbus_root_path/core/bus_center/lnn/disc_mgr/include",
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/common/include",
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/lane_manager/include",
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/lane_manager/src",
"$dsoftbus_root_path/core/bus_center/lnn/meta_node/include",
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/include",
"$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/monitor/include",
"$dsoftbus_root_path/core/bus_center/service/include",
"$dsoftbus_root_path/core/bus_center/utils/include",
"$dsoftbus_root_path/core/connection/ble/include",
"$dsoftbus_root_path/core/connection/wifi_direct/utils",
"$dsoftbus_root_path/core/connection/wifi_direct_cpp",
"$dsoftbus_root_path/core/discovery/interface",
"$dsoftbus_root_path/core/discovery/manager/include",
"$dsoftbus_root_path/interfaces/inner_kits/lnn",
"$dsoftbus_root_path/interfaces/kits/discovery",
]
deps = [
"$dsoftbus_root_path/adapter:softbus_adapter",
"$dsoftbus_root_path/core/common:softbus_utils",
"$dsoftbus_root_path/core/common/dfx/log:softbus_dfx_log",
"$dsoftbus_root_path/core/frame:softbus_server",
"//third_party/googletest:gmock",
"//third_party/googletest:gtest_main",
]

View File

@ -38,7 +38,6 @@
#include "softbus_wifi_api_adapter.h"
#include "lnn_lane_reliability.h"
#include "lnn_lane_reliability.c"
#include "utils/wifi_direct_utils.h"
#include "wifi_direct_error_code.h"
namespace OHOS {
@ -245,6 +244,46 @@ static void CreateAllocInfoForAllocTest(LaneType laneType, LaneTransType transTy
allocInfo->qosRequire.minLaneLatency = DEFAULT_QOSINFO_MIN_LATENCY;
}
/*
* @tc.name: LANE_ALLOC_ErrTest_001
* @tc.desc: lane errcode test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneMockTest, LANE_ALLOC_ERRTEST_001, TestSize.Level1)
{
const LnnLaneManager *laneManager = GetLaneManager();
LaneType laneType = LANE_TYPE_TRANS;
uint32_t laneReqId = laneManager->lnnGetLaneHandle(laneType);
EXPECT_TRUE(laneReqId != INVALID_LANE_REQ_ID);
LaneAllocListener listenerCb = {
.onLaneAllocSuccess = OnLaneAllocSuccessForP2p,
.onLaneAllocFail = OnLaneAllocFail,
};
NiceMock<LnnWifiAdpterInterfaceMock> wifiMock;
wifiMock.SetDefaultResult();
EXPECT_CALL(wifiMock, LnnConnectP2p(NotNull(), laneReqId, NotNull()))
.WillRepeatedly(LnnWifiAdpterInterfaceMock::ActionOfOnConnectP2pFail);
NiceMock<IsLinkEnabledDepsInterfaceMock> enabledMock;
EXPECT_CALL(enabledMock, IsLinkEnabled).WillRepeatedly(Return(false));
NiceMock<LaneDepsInterfaceMock> mock;
mock.SetDefaultResult(reinterpret_cast<NodeInfo *>(&g_NodeInfo));
mock.SetDefaultResultForAlloc(63, 63, 0, 0);
EXPECT_CALL(mock, ConnOpenClientSocket).WillRepeatedly(Return(SOFTBUS_CONN_FAIL));
LaneAllocInfo allocInfo;
ASSERT_EQ(memset_s(&allocInfo, sizeof(LaneAllocInfo), 0, sizeof(LaneAllocInfo)), EOK);
CreateAllocInfoForAllocTest(laneType, LANE_T_MSG, DEFAULT_QOSINFO_MIN_BW + HIGH_BW, &allocInfo);
int32_t ret = laneManager->lnnAllocLane(laneReqId, &allocInfo, &listenerCb);
EXPECT_EQ(ret, SOFTBUS_OK);
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_FOR_LOOP_COMPLETION_MS));
EXPECT_EQ(g_errCode, ERROR_WIFI_OFF);
ret = laneManager->lnnFreeLane(laneReqId);
EXPECT_TRUE(ret == SOFTBUS_OK);
}
/*
* @tc.name: LANE_ALLOC_Test_001
* @tc.desc: lane request for Wlan2p4G MSG HIGH BW
@ -576,27 +615,27 @@ HWTEST_F(LNNLaneMockTest, LANE_RE_ALLOC_Test_001, TestSize.Level1)
EXPECT_TRUE(laneReqId != INVALID_LANE_REQ_ID);
int32_t ret = laneManager->lnnReAllocLane(laneReqId, LANE_ID_BASE, nullptr, &g_listener);
EXPECT_EQ(ret, SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
LaneAllocInfo allocInfo;
ASSERT_EQ(memset_s(&allocInfo, sizeof(LaneAllocInfo), 0, sizeof(LaneAllocInfo)), EOK);
allocInfo.type = LANE_TYPE_BUTT;
ret = laneManager->lnnReAllocLane(laneReqId, LANE_ID_BASE, &allocInfo, nullptr);
EXPECT_EQ(ret, SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
ret = laneManager->lnnReAllocLane(laneReqId, LANE_ID_BASE, &allocInfo, &g_listener);
EXPECT_EQ(ret, SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
ret = laneManager->lnnReAllocLane(INVALID_LANE_REQ_ID, LANE_ID_BASE, &allocInfo, &g_listener);
EXPECT_EQ(ret, SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
ret = laneManager->lnnReAllocLane(laneReqId, INVALID_LANE_ID, &allocInfo, &g_listener);
EXPECT_EQ(ret, SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
allocInfo.type = LANE_TYPE_HDLC;
ret = laneManager->lnnReAllocLane(laneReqId, INVALID_LANE_ID, &allocInfo, &g_listener);
EXPECT_EQ(ret, SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
}
/*
@ -776,46 +815,6 @@ HWTEST_F(LNNLaneMockTest, LANE_RE_ALLOC_Test_005, TestSize.Level1)
EXPECT_TRUE(ret == SOFTBUS_OK);
}
/*
* @tc.name: LANE_ALLOC_ErrTest_001
* @tc.desc: lane errcode test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneMockTest, LANE_ALLOC_ERRTEST_001, TestSize.Level1)
{
const LnnLaneManager *laneManager = GetLaneManager();
LaneType laneType = LANE_TYPE_TRANS;
uint32_t laneReqId = laneManager->lnnGetLaneHandle(laneType);
EXPECT_TRUE(laneReqId != INVALID_LANE_REQ_ID);
LaneAllocListener listenerCb = {
.onLaneAllocSuccess = OnLaneAllocSuccessForP2p,
.onLaneAllocFail = OnLaneAllocFail,
};
NiceMock<LnnWifiAdpterInterfaceMock> wifiMock;
wifiMock.SetDefaultResult();
EXPECT_CALL(wifiMock, LnnConnectP2p(NotNull(), laneReqId, NotNull()))
.WillRepeatedly(LnnWifiAdpterInterfaceMock::ActionOfOnConnectP2pFail);
NiceMock<IsLinkEnabledDepsInterfaceMock> enabledMock;
EXPECT_CALL(enabledMock, IsLinkEnabled).WillRepeatedly(Return(false));
NiceMock<LaneDepsInterfaceMock> mock;
mock.SetDefaultResult(reinterpret_cast<NodeInfo *>(&g_NodeInfo));
mock.SetDefaultResultForAlloc(63, 63, 0, 0);
EXPECT_CALL(mock, ConnOpenClientSocket).WillRepeatedly(Return(SOFTBUS_CONN_FAIL));
LaneAllocInfo allocInfo;
ASSERT_EQ(memset_s(&allocInfo, sizeof(LaneAllocInfo), 0, sizeof(LaneAllocInfo)), EOK);
CreateAllocInfoForAllocTest(laneType, LANE_T_MSG, DEFAULT_QOSINFO_MIN_BW + HIGH_BW, &allocInfo);
int32_t ret = laneManager->lnnAllocLane(laneReqId, &allocInfo, &listenerCb);
EXPECT_EQ(ret, SOFTBUS_OK);
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_FOR_LOOP_COMPLETION_MS));
EXPECT_EQ(g_errCode, ERROR_WIFI_OFF);
ret = laneManager->lnnFreeLane(laneReqId);
EXPECT_TRUE(ret == SOFTBUS_OK);
}
/*
* @tc.name: LANE_CANCEL_Test_001
* @tc.desc: lane cancel
@ -850,7 +849,7 @@ HWTEST_F(LNNLaneMockTest, LANE_CANCEL_Test_001, TestSize.Level1)
EXPECT_EQ(ret, SOFTBUS_OK);
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_FOR_LOOP_COMPLETION_MS));
ret = laneManager->lnnCancelLane(laneReqId);
EXPECT_EQ(ret, SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
ret = laneManager->lnnFreeLane(laneReqId);
EXPECT_TRUE(ret == SOFTBUS_OK);
}
@ -932,7 +931,7 @@ HWTEST_F(LNNLaneMockTest, LANE_CANCEL_Test_003, TestSize.Level1)
ret = laneManager->lnnFreeLane(laneReqId);
EXPECT_TRUE(ret == SOFTBUS_OK);
ret = laneManager->lnnCancelLane(laneReqId);
EXPECT_EQ(ret, SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_NOT_FIND);
}
/*
@ -947,7 +946,7 @@ HWTEST_F(LNNLaneMockTest, LANE_FREE_001, TestSize.Level1)
LaneType laneType = LANE_TYPE_BUTT;
uint32_t laneReqId = laneManager->lnnGetLaneHandle(laneType);
int32_t ret = laneManager->lnnFreeLane(laneReqId);
EXPECT_EQ(ret, SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
laneType = LANE_TYPE_TRANS;
laneReqId = laneManager->lnnGetLaneHandle(laneType);
@ -1160,7 +1159,7 @@ HWTEST_F(LNNLaneMockTest, LNN_SELECT_LANE_001, TestSize.Level1)
selectParam.list.linkType[1] = LANE_LINK_TYPE_BUTT;
int32_t ret = SelectLane(NODE_NETWORK_ID, nullptr, linkList, &listNum);
EXPECT_EQ(ret, SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_LANE_SELECT_FAIL);
mock.SetDefaultResult(reinterpret_cast<NodeInfo *>(&g_NodeInfo));
EXPECT_CALL(mock, LnnGetLocalNumInfo).WillRepeatedly(Return(SOFTBUS_ERR));
@ -1169,7 +1168,7 @@ HWTEST_F(LNNLaneMockTest, LNN_SELECT_LANE_001, TestSize.Level1)
LnnWifiAdpterInterfaceMock wifiMock;
wifiMock.SetDefaultResult();
ret = SelectLane(NODE_NETWORK_ID, &selectParam, linkList, &listNum);
EXPECT_EQ(ret, SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_LANE_SELECT_FAIL);
EXPECT_CALL(mock, LnnGetLocalNumInfo)
.WillRepeatedly(DoAll(SetArgPointee<1>(0), Return(SOFTBUS_OK)));
@ -1177,11 +1176,11 @@ HWTEST_F(LNNLaneMockTest, LNN_SELECT_LANE_001, TestSize.Level1)
.WillRepeatedly(DoAll(SetArgPointee<2>(0), Return(SOFTBUS_OK)));
EXPECT_CALL(mock, LnnGetOnlineStateById).WillRepeatedly(Return(true));
ret = SelectLane(NODE_NETWORK_ID, &selectParam, linkList, &listNum);
EXPECT_EQ(ret, SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_LANE_SELECT_FAIL);
selectParam.transType = LANE_T_MIX;
ret = SelectLane(NODE_NETWORK_ID, &selectParam, linkList, &listNum);
EXPECT_EQ(ret, SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_LANE_SELECT_FAIL);
SoftBusFree(linkList);
}
@ -1212,14 +1211,14 @@ HWTEST_F(LNNLaneMockTest, LNN_SELECT_LANE_002, TestSize.Level1)
LnnWifiAdpterInterfaceMock wifiMock;
wifiMock.SetDefaultResult();
int32_t ret = SelectLane(NODE_NETWORK_ID, &selectParam, linkList, &listNum);
EXPECT_EQ(ret, SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_LANE_SELECT_FAIL);
EXPECT_CALL(mock, LnnGetLocalNumInfo)
.WillRepeatedly(DoAll(SetArgPointee<1>(1), Return(SOFTBUS_OK)));
EXPECT_CALL(mock, LnnGetRemoteNumInfo)
.WillRepeatedly(DoAll(SetArgPointee<2>(1), Return(SOFTBUS_OK)));
ret = SelectLane(NODE_NETWORK_ID, &selectParam, linkList, &listNum);
EXPECT_EQ(ret, SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_LANE_SELECT_FAIL);
SoftBusFree(linkList);
}
@ -1259,7 +1258,7 @@ HWTEST_F(LNNLaneMockTest, LNN_SELECT_LANE_003, TestSize.Level1)
EXPECT_CALL(mock, LnnGetRemoteNumU64Info).WillRepeatedly(Return(SOFTBUS_ERR));
wifiMock.SetDefaultResult();
int32_t ret = SelectLane(NODE_NETWORK_ID, &selectParam, &linkList, &listNum);
EXPECT_EQ(ret, SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_LANE_SELECT_FAIL);
node.discoveryType = 3;
EXPECT_CALL(mock, LnnGetRemoteNodeInfoById)
@ -1273,7 +1272,7 @@ HWTEST_F(LNNLaneMockTest, LNN_SELECT_LANE_003, TestSize.Level1)
EXPECT_CALL(mock, LnnGetRemoteNumU64Info)
.WillRepeatedly(DoAll(SetArgPointee<2>(1), Return(SOFTBUS_OK)));
ret = SelectLane(NODE_NETWORK_ID, &selectParam, &linkList, &listNum);
EXPECT_EQ(ret, SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_LANE_SELECT_FAIL);
}
/*
@ -1488,14 +1487,14 @@ HWTEST_F(LNNLaneMockTest, LNN_BUILD_LINK_004, TestSize.Level1)
EXPECT_CALL(mock, ConnBleGetClientConnectionByUdid).WillRepeatedly(Return(nullptr));
ON_CALL(mock, LnnGetRemoteStrInfo).WillByDefault(Return(SOFTBUS_ERR));
ret = BuildLink(&reqInfo, 0, &cb);
EXPECT_TRUE(ret == SOFTBUS_LANE_GET_LEDGER_INFO_ERR);
EXPECT_NE(ret, SOFTBUS_OK);
EXPECT_CALL(mock, LnnGetRemoteStrInfo).WillRepeatedly(Return(SOFTBUS_OK));
ON_CALL(mock, SoftBusGenerateStrHash).WillByDefault(Return(SOFTBUS_ERR));
ret = BuildLink(&reqInfo, 0, &cb);
EXPECT_TRUE(ret == SOFTBUS_MEM_ERR);
EXPECT_NE(ret, SOFTBUS_OK);
ret = BuildLink(&reqInfo, 0, &cb);
EXPECT_TRUE(ret == SOFTBUS_MEM_ERR);
EXPECT_NE(ret, SOFTBUS_OK);
}
/*
@ -1568,7 +1567,7 @@ HWTEST_F(LNNLaneMockTest, LNN_BUILD_LINK_006, TestSize.Level1)
(void)strcpy_s(request->peerNetworkId, NETWORK_ID_BUF_LEN, networkIdNotFound);
ret = BuildLink(request, reqId, &cb);
EXPECT_TRUE(ret == SOFTBUS_NOT_FIND);
EXPECT_TRUE(ret == SOFTBUS_LANE_NOT_FIND);
SoftBusFree(request);
LaneDeleteP2pAddress(networkId, true);
}
@ -1774,20 +1773,20 @@ HWTEST_F(LNNLaneMockTest, LNN_SELECT_EXPECT_LANES_BY_QOS_001, TestSize.Level1)
.WillRepeatedly(DoAll(SetArgPointee<2>(0), Return(SOFTBUS_OK)));
EXPECT_CALL(mock, LnnGetOnlineStateById).WillRepeatedly(Return(true));
ret = SelectExpectLanesByQos(NODE_NETWORK_ID, &selectParam, &linkList);
EXPECT_EQ(ret, SOFTBUS_OK);
EXPECT_EQ(ret, SOFTBUS_LANE_SELECT_FAIL);
selectParam.qosRequire.minBW = DEFAULT_QOSINFO_MIN_BW + LOW_BW;
ret = SelectExpectLanesByQos(NODE_NETWORK_ID, &selectParam, &linkList);
EXPECT_EQ(ret, SOFTBUS_OK);
EXPECT_EQ(ret, SOFTBUS_LANE_SELECT_FAIL);
selectParam.qosRequire.minBW = DEFAULT_QOSINFO_MIN_BW + HIGH_BW;
ret = SelectExpectLanesByQos(NODE_NETWORK_ID, &selectParam, &linkList);
EXPECT_EQ(ret, SOFTBUS_OK);
EXPECT_EQ(ret, SOFTBUS_LANE_SELECT_FAIL);
selectParam.transType = LANE_T_MIX;
ret = SelectExpectLanesByQos(NODE_NETWORK_ID, &selectParam, &linkList);
EXPECT_EQ(ret, SOFTBUS_OK);
EXPECT_EQ(ret, SOFTBUS_LANE_SELECT_FAIL);
}
/*
@ -2035,7 +2034,7 @@ HWTEST_F(LNNLaneMockTest, LANE_DECISION_MODELS_001, TestSize.Level1)
EXPECT_CALL(mock, LnnGetOnlineStateById).WillRepeatedly(Return(true));
int32_t ret = DecideAvailableLane(NODE_NETWORK_ID, &selectParam, &linkList);
EXPECT_EQ(ret, SOFTBUS_OK);
EXPECT_EQ(ret, SOFTBUS_LANE_SELECT_FAIL);
}
/*
@ -2123,7 +2122,7 @@ HWTEST_F(LNNLaneMockTest, LANE_FIND_LANERESOURCE_BY_LINKTYPE_001, TestSize.Level
EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
ret = FindLaneResourceByLinkType(PEER_UDID, LANE_HML, &laneResourse);
EXPECT_EQ(ret, SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_LANE_RESOURCE_NOT_FIND);
uint64_t laneId = LANE_ID_BASE;
uint32_t clientRef = 0;
@ -2132,10 +2131,10 @@ HWTEST_F(LNNLaneMockTest, LANE_FIND_LANERESOURCE_BY_LINKTYPE_001, TestSize.Level
clientRef++;
ret = FindLaneResourceByLinkType(LOCAL_UDID, LANE_HML, &laneResourse);
EXPECT_EQ(ret, SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_LANE_RESOURCE_NOT_FIND);
ret = FindLaneResourceByLinkType(PEER_UDID, LANE_P2P, &laneResourse);
EXPECT_EQ(ret, SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_LANE_RESOURCE_NOT_FIND);
ret = FindLaneResourceByLinkType(PEER_UDID, LANE_HML, &laneResourse);
EXPECT_EQ(ret, SOFTBUS_OK);
@ -2261,7 +2260,7 @@ HWTEST_F(LNNLaneMockTest, LANE_DETECT_RELIABILITY_002, TestSize.Level1)
EXPECT_EQ(ret, SOFTBUS_OK);
ret = LaneDetectOnDataEvent(module, events, FD);
EXPECT_EQ(ret, SOFTBUS_NOT_FIND);
EXPECT_EQ(ret, SOFTBUS_LANE_NOT_FIND);
EXPECT_CALL(mock, ConnOpenClientSocket).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(mock, AddTrigger).WillRepeatedly(Return(SOFTBUS_OK));
@ -2449,22 +2448,22 @@ HWTEST_F(LNNLaneMockTest, LANE_DEL_AND_ADD_LANERESOURCEITEM_002, TestSize.Level1
}
/*
* @tc.name: LANE_APPLY_LANE_ID_001
* @tc.desc: LANE APPLY LANE ID
* @tc.name: LANE_GENERATE_LANE_ID_001
* @tc.desc: LANE GENERATE LANE ID
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneMockTest, LANE_APPLY_LANE_ID_001, TestSize.Level1)
HWTEST_F(LNNLaneMockTest, LANE_GENERATE_LANE_ID_001, TestSize.Level1)
{
LaneDepsInterfaceMock laneMock;
EXPECT_CALL(laneMock, SoftBusGenerateStrHash)
.WillOnce(Return(SOFTBUS_ERR))
.WillRepeatedly(LaneDepsInterfaceMock::ActionOfGenerateStrHash);
uint64_t laneId = ApplyLaneId(LOCAL_UDID, PEER_UDID, LANE_HML);
uint64_t laneId = GenerateLaneId(LOCAL_UDID, PEER_UDID, LANE_HML);
EXPECT_EQ(laneId, INVALID_LANE_ID);
laneId = ApplyLaneId(LOCAL_UDID, PEER_UDID, LANE_HML);
laneId = GenerateLaneId(LOCAL_UDID, PEER_UDID, LANE_HML);
EXPECT_NE(laneId, INVALID_LANE_ID);
}
@ -2561,7 +2560,6 @@ HWTEST_F(LNNLaneMockTest, LNN_AUTH_ALLOC_TEST_001, TestSize.Level1)
EXPECT_CALL(mock, GetAuthLinkTypeList)
.WillRepeatedly(DoAll(SetArgPointee<1>(mockList), Return(SOFTBUS_OK)));
ret = laneManager->lnnAllocLane(laneReqId, &allocInfo, &g_listener);
EXPECT_EQ(ret, SOFTBUS_OK);
CondWait();
EXPECT_EQ(ret, SOFTBUS_ERR);
}
} // namespace OHOS

View File

@ -49,7 +49,7 @@ int32_t TransLaneDepsInterfaceMock::ActionOfLaneLinkSuccess(const LinkRequest *r
int32_t TransLaneDepsInterfaceMock::ActionOfLaneLinkFail(const LinkRequest *reqInfo,
uint32_t reqId, const LaneLinkCb *cb)
{
cb->OnLaneLinkFail(reqId, SOFTBUS_LANE_ID_GENERATE_FAIL, reqInfo->linkType);
cb->OnLaneLinkFail(reqId, SOFTBUS_LANE_TRIGGER_LINK_FAIL, reqInfo->linkType);
return SOFTBUS_OK;
}
@ -101,6 +101,7 @@ int32_t AddLaneResourceToPool(const LaneLinkInfo *linkInfo, uint64_t laneId, boo
{
return GetTransLaneIf()->AddLaneResourceToPool(linkInfo, laneId, isServerSide);
}
int32_t DelLaneResourceByLaneId(uint64_t laneId, bool isServerSide)
{
return GetTransLaneIf()->DelLaneResourceByLaneId(laneId, isServerSide);
@ -141,9 +142,9 @@ int32_t LaneLinkdownNotify(const char *peerUdid, const LaneLinkInfo *laneLinkInf
return GetTransLaneIf()->LaneLinkdownNotify(peerUdid, laneLinkInfo);
}
uint64_t ApplyLaneId(const char *localUdid, const char *remoteUdid, LaneLinkType linkType)
uint64_t GenerateLaneId(const char *localUdid, const char *remoteUdid, LaneLinkType linkType)
{
return GetTransLaneIf()->ApplyLaneId(localUdid, remoteUdid, linkType);
return GetTransLaneIf()->GenerateLaneId(localUdid, remoteUdid, linkType);
}
}
} // namespace OHOS

View File

@ -50,7 +50,7 @@ public:
virtual int32_t DelLaneBusinessInfoItem(LaneType laneType, uint64_t laneId) = 0;
virtual int32_t LaneLinkupNotify(const char *peerUdid, const LaneLinkInfo *laneLinkInfo) = 0;
virtual int32_t LaneLinkdownNotify(const char *peerUdid, const LaneLinkInfo *laneLinkInfo) = 0;
virtual uint64_t ApplyLaneId(const char *localUdid, const char *remoteUdid, LaneLinkType linkType) = 0;
virtual uint64_t GenerateLaneId(const char *localUdid, const char *remoteUdid, LaneLinkType linkType) = 0;
};
class TransLaneDepsInterfaceMock : public TransLaneDepsInterface {
@ -74,7 +74,8 @@ public:
MOCK_METHOD2(DelLaneBusinessInfoItem, int32_t (LaneType laneType, uint64_t laneId));
MOCK_METHOD2(LaneLinkupNotify, int32_t (const char *peerUdid, const LaneLinkInfo *laneLinkInfo));
MOCK_METHOD2(LaneLinkdownNotify, int32_t (const char *peerUdid, const LaneLinkInfo *laneLinkInfo));
MOCK_METHOD3(ApplyLaneId, uint64_t (const char *localUdid, const char *remoteUdid, LaneLinkType linkType));
MOCK_METHOD3(GenerateLaneId, uint64_t (const char *localUdid, const char *remoteUdid, LaneLinkType linkType));
static int32_t ActionOfLaneLinkSuccess(const LinkRequest *reqInfo, uint32_t reqId, const LaneLinkCb *cb);
static int32_t ActionOfLaneLinkFail(const LinkRequest *reqInfo, uint32_t reqId, const LaneLinkCb *cb);
};

View File

@ -19,10 +19,10 @@
#include <securec.h>
#include "lnn_trans_lane.h"
#include "lnn_lane_deps_mock.h"
#include "lnn_lane_score_virtual.c"
#include "lnn_trans_lane_deps_mock.h"
#include "softbus_error_code.h"
namespace OHOS {
using namespace testing::ext;
@ -148,9 +148,12 @@ HWTEST_F(LNNTransLaneMockTest, LNN_TRANS_LANE_003, TestSize.Level1)
uint32_t laneReqId = 1;
LaneAllocInfo allocInfo;
allocInfo.type = LANE_TYPE_TRANS;
EXPECT_CALL(laneMock, SelectExpectLaneByParameter).WillOnce(Return(SOFTBUS_ERR));
EXPECT_CALL(laneMock, SelectExpectLanesByQos).WillOnce(Return(SOFTBUS_OK));
int32_t ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, nullptr);
LaneAllocListener listenerCb = {
.onLaneAllocSuccess = OnLaneAllocSuccess,
.onLaneAllocFail = OnLaneAllocFail,
};
int32_t ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &listenerCb);
EXPECT_TRUE(ret != SOFTBUS_OK);
EXPECT_EQ(ret, SOFTBUS_LANE_SELECT_FAIL);
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay 200ms for looper completion.
transObj->deinit();
@ -189,7 +192,7 @@ HWTEST_F(LNNTransLaneMockTest, LNN_TRANS_LANE_004, TestSize.Level1)
int32_t ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &listenerCb);
EXPECT_EQ(ret, SOFTBUS_OK);
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay 200ms for looper completion.
EXPECT_EQ(g_errCode, SOFTBUS_LANE_TRIGGER_LINK_FAIL);
EXPECT_EQ(g_errCode, SOFTBUS_LANE_ID_GENERATE_FAIL);
transObj->deinit();
}
@ -226,7 +229,7 @@ HWTEST_F(LNNTransLaneMockTest, LNN_TRANS_LANE_005, TestSize.Level1)
int32_t ret = transObj->allocLaneByQos(laneReqId, (const LaneAllocInfo *)&allocInfo, &listenerCb);
EXPECT_EQ(ret, SOFTBUS_OK);
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay 200ms for looper completion.
EXPECT_EQ(g_errCode, SOFTBUS_LANE_ID_GENERATE_FAIL);
EXPECT_EQ(g_errCode, SOFTBUS_LANE_TRIGGER_LINK_FAIL);
transObj->deinit();
}

View File

@ -31,7 +31,6 @@ using namespace testing;
constexpr char NODE_NETWORK_ID[] = "123456789";
constexpr char BRMAC[] = "testBrMac";
constexpr char ERRORBRMAC[] = "\0testBrMac";
constexpr int32_t SYNCFAIL = 0;
constexpr int32_t SYNCSUCC = 1;
constexpr int32_t ASYNCFAIL = 2;
@ -320,7 +319,9 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfSync_001, TestSize.Level1)
EXPECT_CALL(laneLinkMock, TransProxyPipelineOpenChannel).WillRepeatedly(Return(SOFTBUS_ERR));
ret = LnnConnectP2p(&request, laneReqId, &cb);
EXPECT_EQ(SOFTBUS_ERR, ret);
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
EXPECT_EQ(SOFTBUS_ERR, g_laneLinkResult);
LnnDestroyP2p();
}
@ -366,6 +367,7 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfSync_002, TestSize.Level1)
EXPECT_CALL(laneLinkMock, TransProxyPipelineOpenChannel).WillRepeatedly(Return(SOFTBUS_ERR));
ret = LnnConnectP2p(&request, laneReqId, &cb);
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);
LnnDestroyP2p();
@ -413,6 +415,7 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfSync_003, TestSize.Level1)
EXPECT_CALL(laneLinkMock, TransProxyPipelineOpenChannel).WillRepeatedly(Return(SOFTBUS_OK));
ret = LnnConnectP2p(&request, laneReqId, &cb);
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);
LnnDestroyP2p();
@ -456,7 +459,9 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfSync_004, TestSize.Level1)
EXPECT_CALL(linkMock, AuthOpenConn).WillRepeatedly(Return(SOFTBUS_ERR));
ret = LnnConnectP2p(&request, laneReqId, &cb);
EXPECT_EQ(SOFTBUS_ERR, ret);
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
EXPECT_EQ(SOFTBUS_ERR, g_laneLinkResult);
LnnDestroyP2p();
}
@ -498,6 +503,7 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfSync_005, TestSize.Level1)
EXPECT_CALL(linkMock, AuthOpenConn).WillRepeatedly(Return(SOFTBUS_OK));
ret = LnnConnectP2p(&request, laneReqId, &cb);
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);
LnnDestroyP2p();
@ -506,7 +512,7 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfSync_005, TestSize.Level1)
/*
* @tc.name: GuideChannelRetryOfSync_006
* @tc.desc: test GuideChannelRetryOfSync:
* LANE_ACTIVE_AUTH_TRIGGER(fail)->LANE_BLE_TRIGGER(fail)->LANE_ACTIVE_BR_TRIGGER(fail)->LANE_NEW_AUTH_TRIGGER(fail)
* LANE_ACTIVE_AUTH_TRIGGER(fail)->LANE_BLE_TRIGGER(fail)->LANE_NEW_AUTH_TRIGGER(fail)
* @tc.type: FUNC
* @tc.require:
*/
@ -536,11 +542,9 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfSync_006, TestSize.Level1)
EXPECT_CALL(linkMock, LnnGetLocalNumU64Info).WillRepeatedly(DoAll(SetArgPointee<1>(local), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetRemoteNumU64Info).WillRepeatedly(DoAll(SetArgPointee<2>(remote), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetRemoteStrInfo).WillOnce(Return(SOFTBUS_NOT_FIND)).WillOnce(Return(SOFTBUS_OK))
.WillOnce(DoAll(SetArrayArgument<2>(BRMAC, BRMAC + BT_MAC_LEN), Return(SOFTBUS_OK)))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, AuthDeviceCheckConnInfo).WillOnce(Return(false)).WillOnce(Return(false))
.WillRepeatedly(Return(true));
EXPECT_CALL(linkMock, CheckActiveConnection).WillRepeatedly(Return(true));
EXPECT_CALL(linkMock, AuthGetPreferConnInfo).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneLinkMock, GetTransReqInfoByLaneReqId).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, AuthGenRequestId).WillRepeatedly(Return(requestId));
@ -548,14 +552,16 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfSync_006, TestSize.Level1)
EXPECT_CALL(linkMock, GetWifiDirectManager).WillRepeatedly(Return(&g_manager));
ret = LnnConnectP2p(&request, laneReqId, &cb);
EXPECT_EQ(SOFTBUS_ERR, ret);
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
EXPECT_EQ(SOFTBUS_ERR, g_laneLinkResult);
LnnDestroyP2p();
}
/*
* @tc.name: GuideChannelRetryOfSync_007
* @tc.desc: test GuideChannelRetryOfSync:
* LANE_ACTIVE_AUTH_TRIGGER(fail)->LANE_BLE_TRIGGER(fail)->LANE_ACTIVE_BR_TRIGGER(pass)->LANE_NEW_AUTH_TRIGGER
* LANE_ACTIVE_AUTH_TRIGGER(fail)->LANE_BLE_TRIGGER(fail)->LANE_NEW_AUTH_TRIGGER(pass)
* @tc.type: FUNC
* @tc.require:
*/
@ -585,10 +591,8 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfSync_007, TestSize.Level1)
EXPECT_CALL(linkMock, LnnGetLocalNumU64Info).WillRepeatedly(DoAll(SetArgPointee<1>(local), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetRemoteNumU64Info).WillRepeatedly(DoAll(SetArgPointee<2>(remote), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetRemoteStrInfo).WillOnce(Return(SOFTBUS_NOT_FIND)).WillOnce(Return(SOFTBUS_OK))
.WillOnce(DoAll(SetArrayArgument<2>(BRMAC, BRMAC + BT_MAC_LEN), Return(SOFTBUS_OK)))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, AuthDeviceCheckConnInfo).WillRepeatedly(Return(true));
EXPECT_CALL(linkMock, CheckActiveConnection).WillRepeatedly(Return(true));
EXPECT_CALL(linkMock, AuthGetPreferConnInfo).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneLinkMock, GetTransReqInfoByLaneReqId).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, AuthGenRequestId).WillRepeatedly(Return(requestId));
@ -596,6 +600,7 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfSync_007, TestSize.Level1)
EXPECT_CALL(linkMock, GetWifiDirectManager).WillRepeatedly(Return(&g_manager));
ret = LnnConnectP2p(&request, laneReqId, &cb);
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);
LnnDestroyP2p();
@ -603,60 +608,11 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfSync_007, TestSize.Level1)
/*
* @tc.name: GuideChannelRetryOfSync_008
* @tc.desc: test GuideChannelRetryOfSync:
* LANE_BLE_TRIGGER(fail)->LANE_ACTIVE_BR_TRIGGER(fail)->LANE_NEW_AUTH_TRIGGER(pass)
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfSync_008, TestSize.Level1)
{
LinkRequest request;
(void)memset_s(&request, sizeof(LinkRequest), 0, sizeof(LinkRequest));
int32_t ret = strcpy_s(request.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
EXPECT_EQ(EOK, ret);
request.linkType = LANE_HML;
request.pid = SYNCFAIL;
const LaneLinkCb cb = {
.OnLaneLinkSuccess = OnLaneLinkSuccess,
.OnLaneLinkFail = OnLaneLinkFail,
};
uint32_t laneReqId = 10;
int32_t value = 3;
uint64_t local = 1 << BIT_BLE_TRIGGER_CONNECTION;
uint64_t remote = 1 << BIT_BLE_TRIGGER_CONNECTION;
uint32_t requestId = 1;
LaneDepsInterfaceMock linkMock;
LaneLinkDepsInterfaceMock laneLinkMock;
EXPECT_CALL(linkMock, LnnGetRemoteNumInfo).WillRepeatedly(DoAll(SetArgPointee<2>(value), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetLocalNumU64Info).WillRepeatedly(DoAll(SetArgPointee<1>(local), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetRemoteNumU64Info).WillRepeatedly(DoAll(SetArgPointee<2>(remote), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetRemoteStrInfo).WillOnce(Return(SOFTBUS_NOT_FIND)).WillOnce(Return(SOFTBUS_OK))
.WillOnce(DoAll(SetArrayArgument<2>(BRMAC, BRMAC + BT_MAC_LEN), Return(SOFTBUS_OK)))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, AuthDeviceCheckConnInfo).WillRepeatedly(Return(false));
EXPECT_CALL(linkMock, CheckActiveConnection).WillRepeatedly(Return(true));
EXPECT_CALL(linkMock, AuthGetPreferConnInfo).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneLinkMock, GetTransReqInfoByLaneReqId).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, AuthGenRequestId).WillRepeatedly(Return(requestId));
EXPECT_CALL(linkMock, AuthOpenConn).WillOnce(Return(SOFTBUS_ERR)).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, GetWifiDirectManager).WillRepeatedly(Return(&g_manager));
ret = LnnConnectP2p(&request, laneReqId, &cb);
EXPECT_EQ(SOFTBUS_OK, ret);
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);
LnnDestroyP2p();
}
/*
* @tc.name: GuideChannelRetryOfSync_009
* @tc.desc: test GuideChannelRetryOfSync:LANE_ACTIVE_AUTH_TRIGGER(fail)->LANE_BLE_TRIGGER(pass)->LANE_NEW_AUTH_TRIGGER
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfSync_009, TestSize.Level1)
HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfSync_008, TestSize.Level1)
{
LinkRequest request;
(void)memset_s(&request, sizeof(LinkRequest), 0, sizeof(LinkRequest));
@ -682,7 +638,7 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfSync_009, TestSize.Level1)
EXPECT_CALL(linkMock, LnnGetLocalNumU64Info).WillRepeatedly(DoAll(SetArgPointee<1>(local), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetRemoteNumU64Info).WillRepeatedly(DoAll(SetArgPointee<2>(remote), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetRemoteStrInfo).WillOnce(Return(SOFTBUS_NOT_FIND)).WillOnce(Return(SOFTBUS_OK))
.WillOnce(Return(SOFTBUS_NOT_FIND)).WillRepeatedly(Return(SOFTBUS_OK));
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, AuthDeviceCheckConnInfo).WillRepeatedly(Return(true));
EXPECT_CALL(linkMock, AuthGetPreferConnInfo).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneLinkMock, GetTransReqInfoByLaneReqId).WillRepeatedly(Return(SOFTBUS_OK));
@ -691,18 +647,19 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfSync_009, TestSize.Level1)
EXPECT_CALL(linkMock, GetWifiDirectManager).WillRepeatedly(Return(&g_manager));
ret = LnnConnectP2p(&request, laneReqId, &cb);
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);
LnnDestroyP2p();
}
/*
* @tc.name: GuideChannelRetryOfSync_010
* @tc.name: GuideChannelRetryOfSync_009
* @tc.desc: test GuideChannelRetryOfSync:LANE_BLE_TRIGGER(pass)->LANE_NEW_AUTH_TRIGGER
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfSync_010, TestSize.Level1)
HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfSync_009, TestSize.Level1)
{
LinkRequest request;
(void)memset_s(&request, sizeof(LinkRequest), 0, sizeof(LinkRequest));
@ -727,13 +684,13 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfSync_010, TestSize.Level1)
EXPECT_CALL(linkMock, LnnGetLocalNumU64Info).WillRepeatedly(DoAll(SetArgPointee<1>(local), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetRemoteNumU64Info).WillRepeatedly(DoAll(SetArgPointee<2>(remote), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetRemoteStrInfo).WillOnce(Return(SOFTBUS_NOT_FIND)).WillOnce(Return(SOFTBUS_NOT_FIND))
.WillOnce(DoAll(SetArrayArgument<2>(ERRORBRMAC, ERRORBRMAC + BT_MAC_LEN), Return(SOFTBUS_OK)))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, AuthGetPreferConnInfo).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneLinkMock, GetTransReqInfoByLaneReqId).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, GetWifiDirectManager).WillRepeatedly(Return(&g_manager));
ret = LnnConnectP2p(&request, laneReqId, &cb);
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);
LnnDestroyP2p();
@ -784,7 +741,7 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfAsync_001, TestSize.Level1)
.WillRepeatedly(laneLinkMock.ActionOfChannelOpenFailed);
ret = LnnConnectP2p(&request, laneReqId, &cb);
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay 200ms for looper completion.
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
EXPECT_EQ(SOFTBUS_ERR, g_laneLinkResult);
LnnDestroyP2p();
@ -839,7 +796,7 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfAsync_002, TestSize.Level1)
EXPECT_CALL(linkMock, AuthGetP2pConnInfo).WillRepeatedly(Return(SOFTBUS_OK));
ret = LnnConnectP2p(&request, laneReqId, &cb);
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay 200ms for looper completion.
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
EXPECT_EQ(SOFTBUS_OK, g_laneLinkResult);
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);
@ -893,7 +850,7 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfAsync_003, TestSize.Level1)
EXPECT_CALL(linkMock, AuthGetP2pConnInfo).WillRepeatedly(Return(SOFTBUS_ERR));
ret = LnnConnectP2p(&request, laneReqId, &cb);
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay 200ms for looper completion.
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
EXPECT_EQ(SOFTBUS_OK, g_laneLinkResult);
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);
@ -946,7 +903,7 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfAsync_004, TestSize.Level1)
EXPECT_CALL(linkMock, AuthGetP2pConnInfo).WillRepeatedly(Return(SOFTBUS_OK));
ret = LnnConnectP2p(&request, laneReqId, &cb);
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay 200ms for looper completion.
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
EXPECT_EQ(SOFTBUS_OK, g_laneLinkResult);
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);
@ -956,7 +913,7 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfAsync_004, TestSize.Level1)
/*
* @tc.name: GuideChannelRetryOfAsync_005
* @tc.desc: test GuideChannelRetryOfAsync:
* LANE_ACTIVE_AUTH_TRIGGER(fail)->LANE_BLE_TRIGGER(fail)->LANE_ACTIVE_BR_TRIGGER(fail)->LANE_NEW_AUTH_TRIGGER(fail)
* LANE_ACTIVE_AUTH_TRIGGER(fail)->LANE_BLE_TRIGGER(fail)->LANE_NEW_AUTH_TRIGGER(fail)
* @tc.type: FUNC
* @tc.require:
*/
@ -986,10 +943,8 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfAsync_005, TestSize.Level1)
EXPECT_CALL(linkMock, LnnGetLocalNumU64Info).WillRepeatedly(DoAll(SetArgPointee<1>(local), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetRemoteNumU64Info).WillRepeatedly(DoAll(SetArgPointee<2>(remote), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetRemoteStrInfo).WillOnce(Return(SOFTBUS_NOT_FIND)).WillOnce(Return(SOFTBUS_OK))
.WillOnce(DoAll(SetArrayArgument<2>(BRMAC, BRMAC + BT_MAC_LEN), Return(SOFTBUS_OK)))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, AuthDeviceCheckConnInfo).WillRepeatedly(Return(true));
EXPECT_CALL(linkMock, CheckActiveConnection).WillRepeatedly(Return(true));
EXPECT_CALL(linkMock, AuthGetPreferConnInfo).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneLinkMock, GetTransReqInfoByLaneReqId).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, AuthGenRequestId).WillRepeatedly(Return(requestId));
@ -997,7 +952,7 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfAsync_005, TestSize.Level1)
EXPECT_CALL(linkMock, GetWifiDirectManager).WillRepeatedly(Return(&g_manager));
ret = LnnConnectP2p(&request, laneReqId, &cb);
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay 200ms for looper completion.
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
EXPECT_EQ(SOFTBUS_ERR, g_laneLinkResult);
LnnDestroyP2p();
@ -1006,7 +961,7 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfAsync_005, TestSize.Level1)
/*
* @tc.name: GuideChannelRetryOfAsync_006
* @tc.desc: test GuideChannelRetryOfAsync:
* LANE_BLE_TRIGGER(fail)->LANE_ACTIVE_BR_TRIGGER(fail)->LANE_NEW_AUTH_TRIGGER(opened-fail)
* LANE_ACTIVE_AUTH_TRIGGER(fail)->LANE_BLE_TRIGGER(fail)->LANE_NEW_AUTH_TRIGGER(opened-fail)
* @tc.type: FUNC
* @tc.require:
*/
@ -1036,10 +991,8 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfAsync_006, TestSize.Level1)
EXPECT_CALL(linkMock, LnnGetLocalNumU64Info).WillRepeatedly(DoAll(SetArgPointee<1>(local), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetRemoteNumU64Info).WillRepeatedly(DoAll(SetArgPointee<2>(remote), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetRemoteStrInfo).WillOnce(Return(SOFTBUS_NOT_FIND)).WillOnce(Return(SOFTBUS_OK))
.WillOnce(DoAll(SetArrayArgument<2>(BRMAC, BRMAC + BT_MAC_LEN), Return(SOFTBUS_OK)))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, AuthDeviceCheckConnInfo).WillRepeatedly(Return(false));
EXPECT_CALL(linkMock, CheckActiveConnection).WillRepeatedly(Return(true));
EXPECT_CALL(linkMock, AuthDeviceCheckConnInfo).WillRepeatedly(Return(true));
EXPECT_CALL(linkMock, AuthGetPreferConnInfo).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneLinkMock, GetTransReqInfoByLaneReqId).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, AuthGenRequestId).WillRepeatedly(Return(requestId));
@ -1049,7 +1002,7 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfAsync_006, TestSize.Level1)
EXPECT_CALL(linkMock, AuthCloseConn).WillRepeatedly(Return());
ret = LnnConnectP2p(&request, laneReqId, &cb);
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay 200ms for looper completion.
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
EXPECT_EQ(SOFTBUS_ERR, g_laneLinkResult);
LnnDestroyP2p();
@ -1057,63 +1010,11 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfAsync_006, TestSize.Level1)
/*
* @tc.name: GuideChannelRetryOfAsync_007
* @tc.desc: test GuideChannelRetryOfAsync:
* LANE_ACTIVE_AUTH_TRIGGER(fail)->LANE_BLE_TRIGGER(fail)->LANE_NEW_AUTH_TRIGGER(opened-fail)
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfAsync_007, TestSize.Level1)
{
LinkRequest request;
(void)memset_s(&request, sizeof(LinkRequest), 0, sizeof(LinkRequest));
int32_t ret = strcpy_s(request.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
EXPECT_EQ(EOK, ret);
request.linkType = LANE_HML;
request.pid = ASYNCFAIL;
const LaneLinkCb cb = {
.OnLaneLinkSuccess = OnLaneLinkSuccess,
.OnLaneLinkFail = OnLaneLinkFail,
};
uint32_t laneReqId = 10;
int32_t value = 3;
uint64_t local = 1 << BIT_BLE_TRIGGER_CONNECTION;
uint64_t remote = 1 << BIT_BLE_TRIGGER_CONNECTION;
uint32_t requestId = 1;
LaneDepsInterfaceMock linkMock;
LaneLinkDepsInterfaceMock laneLinkMock;
EXPECT_CALL(linkMock, LnnGetRemoteNumInfo).WillRepeatedly(DoAll(SetArgPointee<2>(value), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetLocalNumU64Info).WillRepeatedly(DoAll(SetArgPointee<1>(local), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetRemoteNumU64Info).WillRepeatedly(DoAll(SetArgPointee<2>(remote), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetRemoteStrInfo).WillOnce(Return(SOFTBUS_NOT_FIND)).WillOnce(Return(SOFTBUS_OK))
.WillOnce(DoAll(SetArrayArgument<2>(BRMAC, BRMAC + BT_MAC_LEN), Return(SOFTBUS_OK)))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, AuthDeviceCheckConnInfo).WillRepeatedly(Return(true));
EXPECT_CALL(linkMock, CheckActiveConnection).WillRepeatedly(Return(false));
EXPECT_CALL(linkMock, AuthGetPreferConnInfo).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneLinkMock, GetTransReqInfoByLaneReqId).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, AuthGenRequestId).WillRepeatedly(Return(requestId));
EXPECT_CALL(linkMock, AuthOpenConn(_, requestId, NotNull(), _)).WillOnce(linkMock.ActionOfConnOpenFailed)
.WillRepeatedly(linkMock.ActionOfConnOpened);
EXPECT_CALL(linkMock, GetWifiDirectManager).WillRepeatedly(Return(&g_manager));
EXPECT_CALL(linkMock, AuthCloseConn).WillRepeatedly(Return());
ret = LnnConnectP2p(&request, laneReqId, &cb);
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay 200ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
EXPECT_EQ(SOFTBUS_ERR, g_laneLinkResult);
LnnDestroyP2p();
}
/*
* @tc.name: GuideChannelRetryOfAsync_008
* @tc.desc: test GuideChannelRetryOfAsync:LANE_ACTIVE_AUTH_TRIGGER(fail)->LANE_BLE_TRIGGER(pass)->LANE_NEW_AUTH_TRIGGER
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfAsync_008, TestSize.Level1)
HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfAsync_007, TestSize.Level1)
{
LinkRequest request;
(void)memset_s(&request, sizeof(LinkRequest), 0, sizeof(LinkRequest));
@ -1139,7 +1040,7 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfAsync_008, TestSize.Level1)
EXPECT_CALL(linkMock, LnnGetLocalNumU64Info).WillRepeatedly(DoAll(SetArgPointee<1>(local), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetRemoteNumU64Info).WillRepeatedly(DoAll(SetArgPointee<2>(remote), Return(SOFTBUS_OK)));
EXPECT_CALL(linkMock, LnnGetRemoteStrInfo).WillOnce(Return(SOFTBUS_NOT_FIND)).WillOnce(Return(SOFTBUS_OK))
.WillOnce(Return(SOFTBUS_NOT_FIND)).WillRepeatedly(Return(SOFTBUS_OK));
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(linkMock, AuthDeviceCheckConnInfo).WillRepeatedly(Return(true));
EXPECT_CALL(linkMock, AuthGetPreferConnInfo).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(laneLinkMock, GetTransReqInfoByLaneReqId).WillRepeatedly(Return(SOFTBUS_OK));
@ -1150,7 +1051,7 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetryOfAsync_008, TestSize.Level1)
EXPECT_CALL(linkMock, AuthGetP2pConnInfo).WillRepeatedly(Return(SOFTBUS_OK));
ret = LnnConnectP2p(&request, laneReqId, &cb);
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay 200ms for looper completion.
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
EXPECT_EQ(SOFTBUS_OK, g_laneLinkResult);
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);
@ -1204,7 +1105,7 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetry_001, TestSize.Level1)
.WillRepeatedly(laneLinkMock.ActionOfChannelOpenFailed);
ret = LnnConnectP2p(&request, laneReqId, &cb);
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay 200ms for looper completion.
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
EXPECT_EQ(SOFTBUS_ERR, g_laneLinkResult);
LnnDestroyP2p();
@ -1256,7 +1157,7 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetry_002, TestSize.Level1)
EXPECT_CALL(laneLinkMock, TransProxyPipelineOpenChannel).WillRepeatedly(Return(SOFTBUS_ERR));
ret = LnnConnectP2p(&request, laneReqId, &cb);
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay 200ms for looper completion.
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
EXPECT_EQ(SOFTBUS_ERR, g_laneLinkResult);
LnnDestroyP2p();
@ -1309,7 +1210,7 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetry_003, TestSize.Level1)
.WillRepeatedly(laneLinkMock.ActionOfChannelOpenFailed);
ret = LnnConnectP2p(&request, laneReqId, &cb);
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay 200ms for looper completion.
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
LnnDestroyP2p();
}
@ -1364,7 +1265,7 @@ HWTEST_F(LNNLaneLinkTest, GuideChannelRetry_004, TestSize.Level1)
EXPECT_CALL(linkMock, AuthGetP2pConnInfo).WillRepeatedly(Return(SOFTBUS_OK));
ret = LnnConnectP2p(&request, laneReqId, &cb);
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // delay 200ms for looper completion.
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // delay 500ms for looper completion.
EXPECT_EQ(SOFTBUS_OK, ret);
EXPECT_EQ(SOFTBUS_OK, g_laneLinkResult);
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);

View File

@ -40,21 +40,60 @@ int32_t FreeLaneResource(const LaneResource *resourceItem)
{
return GetLaneListenerDepsInterface()->FreeLaneResource(resourceItem);
}
int32_t LaneInfoProcess(const LaneLinkInfo *linkInfo, LaneConnInfo *connInfo, LaneProfile *profile)
{
return GetLaneListenerDepsInterface()->LaneInfoProcess(linkInfo, connInfo, profile);
}
int32_t PostLaneStateChangeMessage(LaneState state, const char *peerUdid, const LaneLinkInfo *laneLinkInfo)
{
return GetLaneListenerDepsInterface()->PostLaneStateChangeMessage(state, peerUdid, laneLinkInfo);
}
int32_t FindLaneResourceByLinkAddr(const LaneLinkInfo *infoItem, LaneResource *resourceItem)
{
return GetLaneListenerDepsInterface()->FindLaneResourceByLinkAddr(infoItem, resourceItem);
}
uint64_t ApplyLaneId(const char *localUdid, const char *remoteUdid, LaneLinkType linkType)
uint64_t GenerateLaneId(const char *localUdid, const char *remoteUdid, LaneLinkType linkType)
{
return GetLaneListenerDepsInterface()->ApplyLaneId(localUdid, remoteUdid, linkType);
return GetLaneListenerDepsInterface()->GenerateLaneId(localUdid, remoteUdid, linkType);
}
int32_t FindLaneResourceByLinkType(const char *peerUdid, LaneLinkType type, LaneResource *resource)
{
return GetLaneListenerDepsInterface()->FindLaneResourceByLinkType(peerUdid, type, resource);
}
void DelLogicAndLaneRelationship(uint64_t laneId)
{
GetLaneListenerDepsInterface()->DelLogicAndLaneRelationship(laneId);
}
int32_t ClearLaneResourceByLaneId(uint64_t laneId)
{
return GetLaneListenerDepsInterface()->ClearLaneResourceByLaneId(laneId);
}
void RemoveDelayDestroyMessage(uint64_t laneId)
{
GetLaneListenerDepsInterface()->RemoveDelayDestroyMessage(laneId);
}
LnnLaneManager* GetLaneManager(void)
{
return GetLaneListenerDepsInterface()->GetLaneManager();
}
int32_t AddLaneResourceToPool(const LaneLinkInfo *linkInfo, uint64_t laneId, bool isServerSide)
{
return GetLaneListenerDepsInterface()->AddLaneResourceToPool(linkInfo, laneId, isServerSide);
}
int32_t DelLaneResourceByLaneId(uint64_t laneId, bool isServerSide)
{
return GetLaneListenerDepsInterface()->DelLaneResourceByLaneId(laneId, isServerSide);
}
}
} // namespace OHOS

View File

@ -34,7 +34,14 @@ public:
virtual int32_t PostLaneStateChangeMessage(LaneState state, const char *peerUdid,
const LaneLinkInfo *laneLinkInfo) = 0;
virtual int32_t FindLaneResourceByLinkAddr(const LaneLinkInfo *infoItem, LaneResource *resourceItem) = 0;
virtual uint64_t ApplyLaneId(const char *localUdid, const char *remoteUdid, LaneLinkType linkType) = 0;
virtual uint64_t GenerateLaneId(const char *localUdid, const char *remoteUdid, LaneLinkType linkType) = 0;
virtual int32_t FindLaneResourceByLinkType(const char *peerUdid, LaneLinkType type, LaneResource *resource) = 0;
virtual void DelLogicAndLaneRelationship(uint64_t laneId) = 0;
virtual int32_t ClearLaneResourceByLaneId(uint64_t laneId) = 0;
virtual void RemoveDelayDestroyMessage(uint64_t laneId) = 0;
virtual LnnLaneManager* GetLaneManager(void) = 0;
virtual int32_t AddLaneResourceToPool(const LaneLinkInfo *linkInfo, uint64_t laneId, bool isServerSide) = 0;
virtual int32_t DelLaneResourceByLaneId(uint64_t laneId, bool isServerSide) = 0;
};
class LaneListenerDepsInterfaceMock : public LaneListenerDepsInterface {
@ -48,7 +55,14 @@ public:
MOCK_METHOD3(PostLaneStateChangeMessage, int32_t (LaneState state, const char *peerUdid,
const LaneLinkInfo *laneLinkInfo));
MOCK_METHOD2(FindLaneResourceByLinkAddr, int32_t (const LaneLinkInfo *infoItem, LaneResource *resourceItem));
MOCK_METHOD3(ApplyLaneId, uint64_t (const char *localUdid, const char *remoteUdid, LaneLinkType linkType));
MOCK_METHOD3(GenerateLaneId, uint64_t (const char *localUdid, const char *remoteUdid, LaneLinkType linkType));
MOCK_METHOD3(FindLaneResourceByLinkType, int32_t (const char *peerUdid, LaneLinkType type, LaneResource *resource));
MOCK_METHOD1(DelLogicAndLaneRelationship, void (uint64_t laneId));
MOCK_METHOD1(ClearLaneResourceByLaneId, int32_t (uint64_t laneId));
MOCK_METHOD1(RemoveDelayDestroyMessage, void (uint64_t laneId));
MOCK_METHOD0(GetLaneManager, LnnLaneManager* (void));
MOCK_METHOD3(AddLaneResourceToPool, int32_t (const LaneLinkInfo *linkInfo, uint64_t laneId, bool isServerSide));
MOCK_METHOD2(DelLaneResourceByLaneId, int32_t (uint64_t laneId, bool isServerSide));
};
} // namespace OHOS
#endif // LNN_LANE_LISTENER_DEPS_MOCK_H

View File

@ -297,7 +297,7 @@ HWTEST_F(LNNLaneListenerTest, LNN_LANE_FIND_BUSINESS_INFO_BY_LANE_INFO_001, Test
LaneListenerDepsInterfaceMock listenerMock;
EXPECT_CALL(listenerMock, FindLaneResourceByLinkAddr)
.WillRepeatedly(DoAll(SetArgPointee<1>(laneResource), Return(SOFTBUS_OK)));
EXPECT_CALL(listenerMock, ApplyLaneId).WillRepeatedly(Return(LANE_ID_P2P));
EXPECT_CALL(listenerMock, GenerateLaneId).WillRepeatedly(Return(LANE_ID_P2P));
LaneDepsInterfaceMock laneMock;
EXPECT_CALL(laneMock, LnnGetLocalStrInfo).WillRepeatedly(Return(SOFTBUS_OK));
@ -454,7 +454,7 @@ HWTEST_F(LNNLaneListenerTest, LNN_LANE_LINKUP_NOTIFY_001, TestSize.Level1)
EXPECT_CALL(laneMock, LnnGetLocalStrInfo).WillOnce(Return(SOFTBUS_ERR)).WillRepeatedly(Return(SOFTBUS_OK));
LaneListenerDepsInterfaceMock listenerMock;
EXPECT_CALL(listenerMock, LaneInfoProcess).WillOnce(Return(SOFTBUS_ERR)).WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(listenerMock, ApplyLaneId).WillRepeatedly(Return(LANE_ID_HML));
EXPECT_CALL(listenerMock, GenerateLaneId).WillRepeatedly(Return(LANE_ID_HML));
ret = LaneLinkupNotify(PEER_UDID, &linkInfo);
EXPECT_EQ(SOFTBUS_ERR, ret);
@ -497,7 +497,7 @@ HWTEST_F(LNNLaneListenerTest, LNN_LANE_LINKDOWN_NOTIFY_001, TestSize.Level1)
LaneListenerDepsInterfaceMock listenerMock;
EXPECT_CALL(listenerMock, FindLaneResourceByLinkAddr)
.WillRepeatedly(DoAll(SetArgPointee<1>(laneResource), Return(SOFTBUS_OK)));
EXPECT_CALL(listenerMock, ApplyLaneId).WillRepeatedly(Return(LANE_ID_HML));
EXPECT_CALL(listenerMock, GenerateLaneId).WillRepeatedly(Return(LANE_ID_HML));
LaneDepsInterfaceMock laneMock;
EXPECT_CALL(laneMock, LnnGetLocalStrInfo).WillRepeatedly(Return(SOFTBUS_OK));
@ -563,7 +563,7 @@ HWTEST_F(LNNLaneListenerTest, LNN_LANE_LINKDOWN_NOTIFY_002, TestSize.Level1)
EXPECT_CALL(listenerMock, LaneInfoProcess)
.WillOnce(Return(SOFTBUS_ERR))
.WillRepeatedly(Return(SOFTBUS_OK));
EXPECT_CALL(listenerMock, ApplyLaneId).WillRepeatedly(Return(LANE_ID_HML));
EXPECT_CALL(listenerMock, GenerateLaneId).WillRepeatedly(Return(LANE_ID_HML));
LaneDepsInterfaceMock laneMock;
EXPECT_CALL(laneMock, LnnGetLocalStrInfo).WillRepeatedly(Return(SOFTBUS_OK));
LaneLinkInfo linkInfo;

View File

@ -340,7 +340,7 @@ HWTEST_F(LaneTest, LANE_LINK_Test_001, TestSize.Level1)
};
uint32_t requestId = 0x5A5A;
ret = BuildLink(&reqInfo, requestId, &linkCb);
EXPECT_TRUE(ret == SOFTBUS_ERR);
EXPECT_EQ(ret, SOFTBUS_OK);
ConnServerDeinit();
}