mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2025-02-14 16:00:32 +00:00
feat:add the 'GetMacInfoBySession' interface
Signed-off-by: yueyan <yueyan8@huawei.com>
This commit is contained in:
parent
79d885ddbf
commit
dd030a0590
@ -166,6 +166,11 @@ typedef struct {
|
||||
LaneRttLevel rttLevel;
|
||||
} QosInfo;
|
||||
|
||||
typedef struct {
|
||||
char localMac[MAX_MAC_LEN];
|
||||
char remoteMac[MAX_MAC_LEN];
|
||||
} LnnMacInfo;
|
||||
|
||||
typedef struct {
|
||||
char networkId[NETWORK_ID_BUF_LEN];
|
||||
LaneTransType transType;
|
||||
@ -241,7 +246,7 @@ int32_t LnnQueryLaneResource(const LaneQueryInfo *queryInfo, const QosInfo *qosI
|
||||
uint32_t ApplyLaneReqId(LaneType type);
|
||||
int32_t LnnRequestLane(uint32_t laneReqId, const LaneRequestOption *request, const ILaneListener *listener);
|
||||
int32_t LnnFreeLane(uint32_t laneReqId);
|
||||
|
||||
int32_t GetMacInfoByLaneId(uint64_t laneId, LnnMacInfo *macInfo);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_utils.h"
|
||||
#include "wifi_direct_manager.h"
|
||||
|
||||
#define ID_SHIFT_STEP 5
|
||||
#define ID_CALC_MASK 0x1F
|
||||
@ -475,6 +476,68 @@ int32_t LnnFreeLane(uint32_t laneReqId)
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t GetWifiDirectMacInfo(char *localIp, LnnMacInfo *macInfo)
|
||||
{
|
||||
LnnMacInfo dupMacInfo;
|
||||
(void)memset_s(&dupMacInfo, sizeof(LnnMacInfo), 0, sizeof(LnnMacInfo));
|
||||
struct WifiDirectManager *wifiDirectMgr = GetWifiDirectManager();
|
||||
if (wifiDirectMgr == NULL) {
|
||||
LNN_LOGE(LNN_LANE, "get wifi direct manager fail");
|
||||
return SOFTBUS_NOT_FIND;
|
||||
}
|
||||
int32_t ret = wifiDirectMgr->getLocalAndRemoteMacByLocalIp(localIp, dupMacInfo.localMac, MAX_MAC_LEN,
|
||||
dupMacInfo.remoteMac, MAX_MAC_LEN);
|
||||
char *anonyIp = NULL;
|
||||
Anonymize(localIp, &anonyIp);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LNN_LOGE(LNN_LANE, "localIp=%{public}s get Mac fail, ret=%{public}d", anonyIp, ret);
|
||||
AnonymizeFree(anonyIp);
|
||||
return ret;
|
||||
}
|
||||
if (strcpy_s(macInfo->localMac, MAX_MAC_LEN, dupMacInfo.localMac) != EOK ||
|
||||
strcpy_s(macInfo->remoteMac, MAX_MAC_LEN, dupMacInfo.remoteMac) != EOK) {
|
||||
LNN_LOGE(LNN_LANE, "strcpy MacInfo fail");
|
||||
AnonymizeFree(anonyIp);
|
||||
return SOFTBUS_STRCPY_ERR;
|
||||
}
|
||||
char *anonyLocalMac = NULL;
|
||||
char *anonyRemoteMac = NULL;
|
||||
Anonymize(macInfo->localMac, &anonyLocalMac);
|
||||
Anonymize(macInfo->remoteMac, &anonyRemoteMac);
|
||||
LNN_LOGI(LNN_LANE, "get mac by ip done, localMac=%{public}s, remoteMac=%{public}s, localIp=%{public}s",
|
||||
anonyLocalMac, anonyRemoteMac, anonyIp);
|
||||
AnonymizeFree(anonyLocalMac);
|
||||
AnonymizeFree(anonyRemoteMac);
|
||||
AnonymizeFree(anonyIp);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t GetMacInfoByLaneId(uint64_t laneId, LnnMacInfo *macInfo)
|
||||
{
|
||||
if (laneId == INVALID_LANE_ID || macInfo == NULL) {
|
||||
LNN_LOGE(LNN_LANE, "laneId is invalid or macInfo is null");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
LaneResource laneLinkInfo;
|
||||
(void)memset_s(&laneLinkInfo, sizeof(LaneResource), 0, sizeof(LaneResource));
|
||||
int32_t ret = FindLaneResourceByLaneId(laneId, &laneLinkInfo);
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LNN_LOGE(LNN_LANE, "laneId=%{public}" PRIu64 " find lane link info fail, ret=%{public}d", laneId, ret);
|
||||
return SOFTBUS_NOT_FIND;
|
||||
}
|
||||
if (laneLinkInfo.link.type != LANE_P2P && laneLinkInfo.link.type != LANE_P2P_REUSE &&
|
||||
laneLinkInfo.link.type != LANE_HML) {
|
||||
LNN_LOGE(LNN_LANE, "lane type=%{public}d is invalid", laneLinkInfo.link.type);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
char localIp[IP_LEN] = {0};
|
||||
if (memcpy_s(localIp, IP_LEN, laneLinkInfo.link.linkInfo.p2p.connInfo.localIp, IP_LEN) != EOK) {
|
||||
LNN_LOGE(LNN_LANE, "memcpy ip from lanelinkInfo fail");
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
return GetWifiDirectMacInfo(localIp, macInfo);
|
||||
}
|
||||
|
||||
int32_t LnnQueryLaneResource(const LaneQueryInfo *queryInfo, const QosInfo *qosInfo)
|
||||
{
|
||||
if (queryInfo == NULL || qosInfo == NULL) {
|
||||
|
@ -295,11 +295,20 @@ int32_t P2pAdapter::GetGroupInfo(WifiDirectP2pGroupInfo &groupInfoOut)
|
||||
groupInfoOut.frequency = info.frequency;
|
||||
groupInfoOut.interface = info.interface;
|
||||
std::vector<uint8_t> devAddrArray(info.owner.devAddr, info.owner.devAddr + sizeof(info.owner.devAddr));
|
||||
groupInfoOut.groupOwner = WifiDirectUtils::MacArrayToString(devAddrArray);
|
||||
std::vector<uint8_t> devRandomAddrArray(info.owner.randomDevAddr, info.owner.randomDevAddr +
|
||||
sizeof(info.owner.randomDevAddr));
|
||||
groupInfoOut.groupOwner.address = WifiDirectUtils::MacArrayToString(devAddrArray);
|
||||
groupInfoOut.groupOwner.randomMac = WifiDirectUtils::MacArrayToString(devRandomAddrArray);
|
||||
for (auto i = 0; i < info.clientDevicesSize; i++) {
|
||||
std::vector<uint8_t> clientAddrArray(
|
||||
info.clientDevices[i].devAddr, info.clientDevices[i].devAddr + sizeof(info.clientDevices[i].devAddr));
|
||||
groupInfoOut.clientDevices.push_back(WifiDirectUtils::MacArrayToString(clientAddrArray));
|
||||
std::vector<uint8_t> clientRandomAddrArray(
|
||||
info.clientDevices[i].randomDevAddr, info.clientDevices[i].randomDevAddr +
|
||||
sizeof(info.clientDevices[i].randomDevAddr));
|
||||
WifiDirectP2pDeviceInfo deviceInfo;
|
||||
deviceInfo.address = WifiDirectUtils::MacArrayToString(clientAddrArray);
|
||||
deviceInfo.randomMac = WifiDirectUtils::MacArrayToString(clientRandomAddrArray);
|
||||
groupInfoOut.clientDevices.push_back(deviceInfo);
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
@ -47,12 +47,17 @@ public:
|
||||
std::string interface;
|
||||
};
|
||||
|
||||
struct WifiDirectP2pDeviceInfo {
|
||||
std::string address;
|
||||
std::string randomMac;
|
||||
};
|
||||
|
||||
struct WifiDirectP2pGroupInfo {
|
||||
bool isGroupOwner;
|
||||
int32_t frequency;
|
||||
std::string interface;
|
||||
std::string groupOwner;
|
||||
std::vector<std::string> clientDevices;
|
||||
WifiDirectP2pDeviceInfo groupOwner;
|
||||
std::vector<WifiDirectP2pDeviceInfo> clientDevices;
|
||||
};
|
||||
|
||||
static int32_t GetChannel5GListIntArray(std::vector<int> &channels);
|
||||
|
@ -129,7 +129,7 @@ void P2pAvailableState::OnP2pConnectionChangeEvent(
|
||||
|
||||
CONN_LOGI(CONN_WIFI_DIRECT, "remove joining client, clientDeviceSize=%{public}zu", groupInfo->clientDevices.size());
|
||||
for (const auto &client : groupInfo->clientDevices) {
|
||||
P2pEntity::GetInstance().RemoveNewClientJoining(client);
|
||||
P2pEntity::GetInstance().RemoveNewClientJoining(client.address);
|
||||
}
|
||||
|
||||
int reuseCount = 0;
|
||||
|
@ -14,6 +14,7 @@
|
||||
*/
|
||||
#include "p2p_entity.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <future>
|
||||
|
||||
#include "bus_center_manager.h"
|
||||
@ -48,7 +49,7 @@ void SyncLnnInfoForP2p(
|
||||
CONN_LOGE(CONN_WIFI_DIRECT, "set lnn my mac failed");
|
||||
}
|
||||
|
||||
auto goMac = groupInfo->isGroupOwner ? "" : groupInfo->groupOwner;
|
||||
auto goMac = groupInfo->isGroupOwner ? "" : groupInfo->groupOwner.address;
|
||||
ret = LnnSetLocalStrInfo(STRING_KEY_P2P_GO_MAC, goMac.c_str());
|
||||
if (ret != SOFTBUS_OK) {
|
||||
CONN_LOGE(CONN_WIFI_DIRECT, "set lnn go mac failed");
|
||||
@ -465,34 +466,37 @@ void P2pEntity::UpdateInterfaceManager(
|
||||
UpdateInterfaceInfo(localMac, groupInfo);
|
||||
}
|
||||
|
||||
static void UpdateInnerLink(const std::shared_ptr<P2pAdapter::WifiDirectP2pGroupInfo> &groupInfo)
|
||||
static void UpdateInnerLink(const std::shared_ptr<P2pAdapter::WifiDirectP2pGroupInfo> &groupInfo,
|
||||
const std::string &localMac)
|
||||
{
|
||||
auto frequency = groupInfo->frequency;
|
||||
if (!groupInfo->isGroupOwner) {
|
||||
CONN_LOGI(CONN_WIFI_DIRECT, "not group owner, groupOwnerMac=%{public}s",
|
||||
WifiDirectAnonymizeMac(groupInfo->groupOwner).c_str());
|
||||
LinkManager::GetInstance().ProcessIfPresent(groupInfo->groupOwner, [frequency](InnerLink &link) {
|
||||
link.SetState(InnerLink::LinkState::CONNECTED);
|
||||
link.SetFrequency(frequency);
|
||||
});
|
||||
WifiDirectAnonymizeMac(groupInfo->groupOwner.address).c_str());
|
||||
LinkManager::GetInstance().ProcessIfPresent(groupInfo->groupOwner.address, [frequency, groupInfo, localMac]
|
||||
(InnerLink &link) {
|
||||
link.SetState(InnerLink::LinkState::CONNECTED);
|
||||
link.SetFrequency(frequency);
|
||||
link.SetRemoteDynamicMac(groupInfo->groupOwner.randomMac);
|
||||
link.SetLocalDynamicMac(localMac);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
std::string ip;
|
||||
InterfaceManager::GetInstance().ReadInterface(InterfaceInfo::P2P, [&ip](const InterfaceInfo &interface) {
|
||||
ip = interface.GetIpString().ToIpString();
|
||||
return SOFTBUS_OK;
|
||||
});
|
||||
|
||||
for (const auto &client : groupInfo->clientDevices) {
|
||||
CONN_LOGI(CONN_WIFI_DIRECT, "remoteMac=%{public}s", WifiDirectAnonymizeMac(client).c_str());
|
||||
LinkManager::GetInstance().ProcessIfPresent(client, [ip, frequency](InnerLink &link) {
|
||||
CONN_LOGI(CONN_WIFI_DIRECT, "remoteMac=%{public}s", WifiDirectAnonymizeMac(client.address).c_str());
|
||||
LinkManager::GetInstance().ProcessIfPresent(client.address, [ip, frequency, client, localMac](InnerLink &link) {
|
||||
link.SetState(InnerLink::LinkState::CONNECTED);
|
||||
link.SetFrequency(frequency);
|
||||
link.SetLocalIpv4(ip);
|
||||
link.SetRemoteDynamicMac(client.randomMac);
|
||||
link.SetLocalDynamicMac(localMac);
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<std::string> invalidLinks;
|
||||
auto clients = groupInfo->clientDevices;
|
||||
LinkManager::GetInstance().ForEach([&invalidLinks, clients](const InnerLink &link) {
|
||||
@ -502,8 +506,9 @@ static void UpdateInnerLink(const std::shared_ptr<P2pAdapter::WifiDirectP2pGroup
|
||||
if (link.GetState() == InnerLink::LinkState::CONNECTING) {
|
||||
return false;
|
||||
}
|
||||
auto exist = std::find(clients.begin(), clients.end(), link.GetRemoteBaseMac()) != clients.end();
|
||||
if (!exist) {
|
||||
if (std::none_of(clients.begin(), clients.end(), [&link](const P2pAdapter::WifiDirectP2pDeviceInfo &item) {
|
||||
return item.address == link.GetRemoteBaseMac();
|
||||
})) {
|
||||
invalidLinks.push_back(link.GetRemoteDeviceId());
|
||||
}
|
||||
// return false to range all link
|
||||
@ -522,7 +527,10 @@ void P2pEntity::UpdateLinkManager(
|
||||
return;
|
||||
}
|
||||
CONN_CHECK_AND_RETURN_LOGE(groupInfo, CONN_WIFI_DIRECT, "groupInfo is null");
|
||||
UpdateInnerLink(groupInfo);
|
||||
std::string dynamicMac;
|
||||
auto ret = P2pAdapter::GetDynamicMacAddress(dynamicMac);
|
||||
CONN_CHECK_AND_RETURN_LOGE(ret == SOFTBUS_OK, CONN_WIFI_DIRECT, "get dynamic mac failed, error=%{public}d", ret);
|
||||
UpdateInnerLink(groupInfo, dynamicMac);
|
||||
}
|
||||
|
||||
void P2pEntity::UpdateInterfaceManagerWhenStateChanged(P2pState state)
|
||||
|
@ -284,6 +284,35 @@ static int32_t GetRemoteUuidByIp(const char *remoteIp, char *uuid, int32_t uuidS
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t GetLocalAndRemoteMacByLocalIp(const char *localIp, char *localMac, size_t localMacSize, char *remoteMac,
|
||||
size_t remoteMacSize)
|
||||
{
|
||||
bool found = false;
|
||||
OHOS::SoftBus::LinkManager::GetInstance().ForEach([&] (const OHOS::SoftBus::InnerLink &innerLink) {
|
||||
if (innerLink.GetLocalIpv4() == localIp || innerLink.GetLocalIpv6() == localIp) {
|
||||
found = true;
|
||||
if (strcpy_s(localMac, localMacSize, innerLink.GetLocalDynamicMac().c_str()) != EOK) {
|
||||
found = false;
|
||||
}
|
||||
if (strcpy_s(remoteMac, remoteMacSize, innerLink.GetRemoteDynamicMac().c_str()) != EOK) {
|
||||
found = false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (!found) {
|
||||
CONN_LOGI(CONN_WIFI_DIRECT, "not found %{public}s", OHOS::SoftBus::WifiDirectAnonymizeIp(localIp).c_str());
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
CONN_LOGI(CONN_WIFI_DIRECT, "localIp=%{public}s localMac=%{public}s remoteMac=%{public}s",
|
||||
OHOS::SoftBus::WifiDirectAnonymizeIp(localIp).c_str(), OHOS::SoftBus::WifiDirectAnonymizeMac(localMac).c_str(),
|
||||
OHOS::SoftBus::WifiDirectAnonymizeMac(remoteMac).c_str());
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void NotifyOnline(const char *remoteMac, const char *remoteIp, const char *remoteUuid, bool isSource)
|
||||
{
|
||||
CONN_LOGI(CONN_WIFI_DIRECT, "remoteMac=%{public}s, remoteIp=%{public}s remoteUuid=%{public}s",
|
||||
@ -403,6 +432,7 @@ static struct WifiDirectManager g_manager = {
|
||||
.getLocalIpByUuid = GetLocalIpByUuid,
|
||||
.getLocalIpByRemoteIp = GetLocalIpByRemoteIp,
|
||||
.getRemoteUuidByIp = GetRemoteUuidByIp,
|
||||
.getLocalAndRemoteMacByLocalIp = GetLocalAndRemoteMacByLocalIp,
|
||||
|
||||
.supportHmlTwo = SupportHmlTwo,
|
||||
.isWifiP2pEnabled = IsWifiP2pEnabled,
|
||||
|
@ -50,6 +50,8 @@ struct WifiDirectManager {
|
||||
int32_t (*getLocalIpByUuid)(const char *uuid, char *localIp, int32_t localIpSize);
|
||||
int32_t (*getLocalIpByRemoteIp)(const char *remoteIp, char *localIp, int32_t localIpSize);
|
||||
int32_t (*getRemoteUuidByIp)(const char *remoteIp, char *uuid, int32_t uuidSize);
|
||||
int32_t (*getLocalAndRemoteMacByLocalIp)(const char *localIp, char *localMac, size_t localMacSize, char *remoteMac,
|
||||
size_t remoteMacSize);
|
||||
|
||||
bool (*supportHmlTwo)(void);
|
||||
bool (*isWifiP2pEnabled)(void);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@ -19,6 +19,7 @@
|
||||
#include <stdint.h>
|
||||
#include "lnn_lane_interface.h"
|
||||
#include "softbus_app_info.h"
|
||||
#include "softbus_conn_interface.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -82,6 +83,8 @@ int32_t TransGetSocketChannelLaneInfoBySession(
|
||||
|
||||
int32_t TransGetPidFromSocketChannelInfoBySession(const char *sessionName, int32_t sessionId, int32_t *pid);
|
||||
|
||||
int32_t TransGetConnectTypeByChannelId(int32_t channelId, ConnectType *connectType);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
@ -282,10 +282,7 @@ int32_t TransOpenChannel(const SessionParam *param, TransInfo *transInfo)
|
||||
param->sessionName, param->sessionId, transInfo->channelId, transInfo->channelType);
|
||||
TransSetSocketChannelStateByChannel(
|
||||
transInfo->channelId, transInfo->channelType, CORE_SESSION_STATE_CHANNEL_OPENED);
|
||||
if (((ChannelType)transInfo->channelType == CHANNEL_TYPE_TCP_DIRECT) &&
|
||||
(connOpt.type != CONNECT_P2P) && (connOpt.type != CONNECT_HML)) {
|
||||
TransFreeLane(laneHandle, param->isQosLane);
|
||||
} else if (TransLaneMgrAddLane(transInfo->channelId, transInfo->channelType, &connInfo,
|
||||
if (TransLaneMgrAddLane(transInfo->channelId, transInfo->channelType, &connInfo,
|
||||
laneHandle, param->isQosLane, &appInfo->myData) != SOFTBUS_OK) {
|
||||
SoftbusRecordOpenSessionKpi(appInfo->myData.pkgName,
|
||||
appInfo->linkType, SOFTBUS_EVT_OPEN_SESSION_FAIL, GetSoftbusRecordTimeMillis() - appInfo->timeStart);
|
||||
|
@ -801,4 +801,72 @@ int32_t TransGetPidFromSocketChannelInfoBySession(const char *sessionName, int32
|
||||
(void)SoftBusMutexUnlock(&(g_socketChannelList->lock));
|
||||
AnonymizeLogSessionNameWhenNotFound(sessionName, sessionId);
|
||||
return SOFTBUS_NOT_FIND;
|
||||
}
|
||||
|
||||
static ConnectType ConvertLaneLinkTypeToConnectType(LaneLinkType laneLinkType)
|
||||
{
|
||||
switch (laneLinkType) {
|
||||
case LANE_BR:
|
||||
return CONNECT_BR;
|
||||
case LANE_BLE:
|
||||
case LANE_COC:
|
||||
return CONNECT_BLE;
|
||||
case LANE_P2P:
|
||||
return CONNECT_P2P;
|
||||
case LANE_WLAN_2P4G:
|
||||
case LANE_WLAN_5G:
|
||||
case LANE_ETH:
|
||||
return CONNECT_TCP;
|
||||
case LANE_P2P_REUSE:
|
||||
return CONNECT_P2P_REUSE;
|
||||
case LANE_BLE_DIRECT:
|
||||
case LANE_COC_DIRECT:
|
||||
return CONNECT_BLE_DIRECT;
|
||||
case LANE_HML:
|
||||
return CONNECT_HML;
|
||||
case LANE_BLE_REUSE:
|
||||
return CONNECT_BLE;
|
||||
default:
|
||||
return CONNECT_TYPE_MAX;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t TransGetConnectTypeByChannelId(int32_t channelId, ConnectType *connectType)
|
||||
{
|
||||
if (connectType == NULL) {
|
||||
TRANS_LOGE(TRANS_INIT, "connectType is null");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (g_channelLaneList == NULL) {
|
||||
TRANS_LOGE(TRANS_INIT, "trans lane manager hasn't init.");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (SoftBusMutexLock(&(g_channelLaneList->lock)) != SOFTBUS_OK) {
|
||||
TRANS_LOGE(TRANS_SVC, "lock failed");
|
||||
return SOFTBUS_LOCK_ERR;
|
||||
}
|
||||
|
||||
TransLaneInfo *item = NULL;
|
||||
LIST_FOR_EACH_ENTRY(item, &(g_channelLaneList->list), TransLaneInfo, node) {
|
||||
if (item->channelId != channelId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ConnectType connType = ConvertLaneLinkTypeToConnectType(item->laneConnInfo.type);
|
||||
if (connType >= CONNECT_TYPE_MAX) {
|
||||
TRANS_LOGE(TRANS_SVC, "invalid connectType=%{public}d. linkType=%{public}d, channelId=%{public}d",
|
||||
connType, item->laneConnInfo.type, channelId);
|
||||
(void)SoftBusMutexUnlock(&(g_channelLaneList->lock));
|
||||
return SOFTBUS_CONN_INVALID_CONN_TYPE;
|
||||
}
|
||||
|
||||
*connectType = connType;
|
||||
(void)SoftBusMutexUnlock(&(g_channelLaneList->lock));
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
(void)SoftBusMutexUnlock(&(g_channelLaneList->lock));
|
||||
TRANS_LOGE(TRANS_SVC, "can not find connectType by channelId=%{public}d", channelId);
|
||||
return SOFTBUS_TRANS_INVALID_CHANNEL_ID;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Copyright (c) 2021-2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
@ -80,6 +80,11 @@ config("dsoftbus_sdk_interface") {
|
||||
include_dirs +=
|
||||
[ "$dsoftbus_root_path/dsoftbus_enhance/interfaces/kits/bus_center" ]
|
||||
}
|
||||
|
||||
if (schema_enhanced) {
|
||||
include_dirs +=
|
||||
[ "$dsoftbus_root_path/dsoftbus_enhance/interfaces/kits/transport" ]
|
||||
}
|
||||
}
|
||||
|
||||
target(build_type, "softbus_client") {
|
||||
|
@ -508,6 +508,7 @@
|
||||
"UnregistDirSchema";
|
||||
"TransRegistDirSchema";
|
||||
"TransUnRegistDirSchema";
|
||||
"GetMacInfoBySession";
|
||||
extern "C++" {
|
||||
OHOS::StreamAdaptor*;
|
||||
Communication::SoftBus*;
|
||||
|
@ -1452,6 +1452,7 @@ 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_lane.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",
|
||||
|
@ -86,5 +86,25 @@ int32_t LaneDetectReliability(uint32_t laneReqId, const LaneLinkInfo *linkInfo,
|
||||
{
|
||||
return GetLaneLinkDepsInterface()->LaneDetectReliability(laneReqId, linkInfo, callback);
|
||||
}
|
||||
|
||||
int32_t FindLaneResourceByLaneId(uint64_t laneId, LaneResource *resource)
|
||||
{
|
||||
return GetLaneLinkDepsInterface()->FindLaneResourceByLaneId(laneId, resource);
|
||||
}
|
||||
|
||||
int32_t InitLaneLink(void)
|
||||
{
|
||||
return GetLaneLinkDepsInterface()->InitLaneLink();
|
||||
}
|
||||
|
||||
int32_t AddLaneResourceToPool(const LaneLinkInfo *linkInfo, uint64_t laneId, bool isServerSide)
|
||||
{
|
||||
return GetLaneLinkDepsInterface()->AddLaneResourceToPool(linkInfo, laneId, isServerSide);
|
||||
}
|
||||
|
||||
int32_t DelLaneResourceByLaneId(uint64_t laneId, bool isServerSide)
|
||||
{
|
||||
return GetLaneLinkDepsInterface()->DelLaneResourceByLaneId(laneId, isServerSide);
|
||||
}
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
@ -36,6 +36,10 @@ public:
|
||||
virtual int32_t FindLaneResourceByLinkType(const char *peerUdid, LaneLinkType type, LaneResource *resource) = 0;
|
||||
virtual int32_t LaneDetectReliability(uint32_t laneReqId, const LaneLinkInfo *linkInfo,
|
||||
const LaneLinkCb *callback) = 0;
|
||||
virtual int32_t FindLaneResourceByLaneId(uint64_t laneId, LaneResource *resource) = 0;
|
||||
virtual int32_t InitLaneLink(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 LaneLinkDepsInterfaceMock : public LaneLinkDepsInterface {
|
||||
@ -52,6 +56,10 @@ public:
|
||||
MOCK_METHOD3(FindLaneResourceByLinkType, int32_t (const char *peerUdid, LaneLinkType type, LaneResource *resource));
|
||||
MOCK_METHOD3(LaneDetectReliability, int32_t (uint32_t laneReqId, const LaneLinkInfo *linkInfo,
|
||||
const LaneLinkCb *callback));
|
||||
MOCK_METHOD2(FindLaneResourceByLaneId, int32_t (uint64_t laneId, LaneResource *resource));
|
||||
MOCK_METHOD0(InitLaneLink, int32_t (void));
|
||||
MOCK_METHOD3(AddLaneResourceToPool, int32_t (const LaneLinkInfo *linkInfo, uint64_t laneId, bool isServerSide));
|
||||
MOCK_METHOD2(DelLaneResourceByLaneId, int32_t (uint64_t laneId, bool isServerSide));
|
||||
|
||||
static int32_t ActionOfChannelOpenFailed(int32_t requestId, const char *networkId,
|
||||
const TransProxyPipelineChannelOption *option, const ITransProxyPipelineCallback *callback);
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "lnn_feature_capability.h"
|
||||
#include "lnn_lane_common.h"
|
||||
#include "lnn_lane_deps_mock.h"
|
||||
#include "lnn_lane_interface.h"
|
||||
#include "lnn_lane_link_deps_mock.h"
|
||||
#include "lnn_lane_link_p2p.h"
|
||||
#include "lnn_select_rule.h"
|
||||
@ -35,6 +36,8 @@ constexpr int32_t SYNCFAIL = 0;
|
||||
constexpr int32_t SYNCSUCC = 1;
|
||||
constexpr int32_t ASYNCFAIL = 2;
|
||||
constexpr int32_t ASYNCSUCC = 3;
|
||||
constexpr int32_t USEABLE_LANE_ID = 1234567;
|
||||
constexpr char USEABLE_IP[] = "192.168.1.1";
|
||||
|
||||
int32_t g_laneLinkResult = SOFTBUS_INVALID_PARAM;
|
||||
|
||||
@ -84,6 +87,21 @@ static void OnLaneLinkFail(uint32_t reqId, int32_t reason, LaneLinkType linkType
|
||||
return;
|
||||
}
|
||||
|
||||
static int32_t GetLocalAndRemoteMacByLocalIp(
|
||||
const char *localIp, char *localMac, size_t localMacSize, char *remoteMac, size_t remoteMacSize)
|
||||
{
|
||||
(void)localIp;
|
||||
(void)localMac;
|
||||
(void)localMacSize;
|
||||
(void)remoteMac;
|
||||
(void)remoteMacSize;
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static struct WifiDirectManager manager = {
|
||||
.getLocalAndRemoteMacByLocalIp = GetLocalAndRemoteMacByLocalIp,
|
||||
};
|
||||
|
||||
static bool IsNegotiateChannelNeeded(const char *remoteNetworkId, enum WifiDirectLinkType linkType)
|
||||
{
|
||||
return false;
|
||||
@ -1395,4 +1413,53 @@ HWTEST_F(LNNLaneLinkTest, LnnCancelWifiDirect_001, TestSize.Level1)
|
||||
LnnDisconnectP2p(NODE_NETWORK_ID, laneReqId);
|
||||
LnnDestroyP2p();
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: GET_MAC_INFO_BY_LANE_ID_TEST_001
|
||||
* @tc.desc: GetMacInfoByLaneId test
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(LNNLaneLinkTest, GET_MAC_INFO_BY_LANE_ID_TEST_001, TestSize.Level1)
|
||||
{
|
||||
uint64_t laneId = INVALID_LANE_ID;
|
||||
LnnMacInfo macInfo;
|
||||
memset_s(&macInfo, sizeof(LnnMacInfo), 0, sizeof(LnnMacInfo));
|
||||
int32_t ret = GetMacInfoByLaneId(laneId, &macInfo);
|
||||
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
|
||||
ret = GetMacInfoByLaneId(USEABLE_LANE_ID, NULL);
|
||||
EXPECT_TRUE(ret == SOFTBUS_INVALID_PARAM);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: GET_MAC_INFO_BY_LANE_ID_MOCK_TEST_002
|
||||
* @tc.desc: GetMacInfoByLaneId test
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(LNNLaneLinkTest, GET_MAC_INFO_BY_LANE_ID_MOCK_TEST_002, TestSize.Level1)
|
||||
{
|
||||
LaneDepsInterfaceMock laneMock;
|
||||
LaneLinkDepsInterfaceMock laneDepMock;
|
||||
int32_t ret = InitLaneLink();
|
||||
EXPECT_TRUE(ret == SOFTBUS_OK);
|
||||
LnnMacInfo macInfo;
|
||||
LaneResource resource = {
|
||||
.laneId = USEABLE_LANE_ID,
|
||||
.link.type = LANE_HML,
|
||||
};
|
||||
(void)strcpy_s(resource.link.linkInfo.wlan.connInfo.addr, MAX_SOCKET_ADDR_LEN, USEABLE_IP);
|
||||
memset_s(&macInfo, sizeof(LnnMacInfo), 0, sizeof(LnnMacInfo));
|
||||
EXPECT_CALL(laneMock, GetWifiDirectManager).WillOnce(Return(NULL)).WillRepeatedly(Return(&manager));
|
||||
EXPECT_CALL(laneDepMock, FindLaneResourceByLaneId).WillOnce(Return(SOFTBUS_ERR))
|
||||
.WillRepeatedly(DoAll(SetArgPointee<LANE_MOCK_PARAM2>(resource), Return(SOFTBUS_OK)));
|
||||
EXPECT_CALL(laneDepMock, DelLaneResourceByLaneId).WillRepeatedly(Return(SOFTBUS_OK));
|
||||
ret = GetMacInfoByLaneId(USEABLE_LANE_ID, &macInfo);
|
||||
EXPECT_TRUE(ret == SOFTBUS_NOT_FIND);
|
||||
ret = GetMacInfoByLaneId(USEABLE_LANE_ID, &macInfo);
|
||||
EXPECT_TRUE(ret == SOFTBUS_NOT_FIND);
|
||||
|
||||
ret = DelLaneResourceByLaneId(USEABLE_LANE_ID, false);
|
||||
EXPECT_TRUE(ret == SOFTBUS_OK);
|
||||
}
|
||||
} // namespace OHOS
|
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Copyright (c) 2022-2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
@ -25,6 +25,22 @@ trans_enhance_test = exec_script("$dsoftbus_root_path/check_sub_module.py",
|
||||
],
|
||||
"value")
|
||||
|
||||
trans_enhance_fuzz_dir = "dsoftbus_enhance/test/sdk/transmission/fuzztest"
|
||||
trans_enhance_fuzz_test = exec_script("$dsoftbus_root_path/check_sub_module.py",
|
||||
[
|
||||
"$native_source_path",
|
||||
"$trans_enhance_fuzz_dir",
|
||||
],
|
||||
"value")
|
||||
|
||||
trans_enhance_mt_dir = "dsoftbus_enhance/test/sdk/transmission/moduletest"
|
||||
trans_enhance_mt_test = exec_script("$dsoftbus_root_path/check_sub_module.py",
|
||||
[
|
||||
"$native_source_path",
|
||||
"$trans_enhance_mt_dir",
|
||||
],
|
||||
"value")
|
||||
|
||||
group("benchmarktest") {
|
||||
testonly = true
|
||||
deps = [ "benchmarktest:benchmarktest" ]
|
||||
@ -33,6 +49,9 @@ group("benchmarktest") {
|
||||
group("fuzztest") {
|
||||
testonly = true
|
||||
deps = [ "fuzztest:fuzztest" ]
|
||||
if (trans_enhance_fuzz_test) {
|
||||
deps += [ "$dsoftbus_root_path/dsoftbus_enhance/test/sdk/transmission/fuzztest:fuzztest" ]
|
||||
}
|
||||
}
|
||||
|
||||
group("integration_test") {
|
||||
@ -43,6 +62,9 @@ group("integration_test") {
|
||||
group("moduletest") {
|
||||
testonly = true
|
||||
deps = [ "moduletest:moduletest" ]
|
||||
if (trans_enhance_mt_test) {
|
||||
deps += [ "$dsoftbus_root_path/dsoftbus_enhance/test/sdk/transmission/moduletest:moduletest" ]
|
||||
}
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
|
Loading…
x
Reference in New Issue
Block a user