!6360 support for enhanced p2p

Merge pull request !6360 from wuchunbo/master
This commit is contained in:
openharmony_ci 2024-05-31 09:30:43 +00:00 committed by Gitee
commit 5794782ab5
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
47 changed files with 674 additions and 195 deletions

View File

@ -52,6 +52,7 @@ typedef enum {
AUTH_LINK_TYPE_BLE,
AUTH_LINK_TYPE_P2P,
AUTH_LINK_TYPE_ENHANCED_P2P,
AUTH_LINK_TYPE_RAW_ENHANCED_P2P,
AUTH_LINK_TYPE_NORMALIZED,
AUTH_LINK_TYPE_MAX,
} AuthLinkType;

View File

@ -443,7 +443,7 @@ int32_t UnRegisterLaneListener(LaneType type)
}
static void LnnOnWifiDirectConnectedForSink(const char *remoteMac, const char *remoteIp, const char *remoteUuid,
enum WifiDirectLinkType type)
enum WifiDirectLinkType type, int channelId)
{
if (remoteMac == NULL || remoteIp == NULL || remoteUuid == NULL) {
LNN_LOGE(LNN_LANE, "invalid param");

View File

@ -31,6 +31,7 @@ typedef enum {
CONN_BLE_DIRECT,
CONN_BROADCAST,
CONN_NEWIP,
CONN_ACTION,
CONN_TEST,
} ConnLogLabelEnum;
@ -45,6 +46,7 @@ static const SoftBusLogLabel CONN_LABELS[MODULE_DOMAIN_MAX_LEN] = {
{CONN_BLE_DIRECT, 0xd005766, "ConnBD"},
{CONN_BROADCAST, 0xd005767, "ConnBC"},
{CONN_NEWIP, 0xd005768, "ConnNewIp"},
{CONN_ACTION, 0xd005769, "ConnAction"},
{CONN_TEST, DOMAIN_ID_TEST, "ConnTest"},
};

View File

@ -50,6 +50,11 @@ ohos_static_library("wifi_direct") {
"$dsoftbus_root_path/core/connection/wifi_direct_cpp",
]
if (!defined(ohos_lite)) {
wifi_direct_connection_inc +=
[ "$dsoftbus_root_path/adapter/common/include/OS_adapter_define/linux" ]
}
wifi_direct_connection_external_deps = []
if (dsoftbus_feature_conn_p2p == true &&
@ -94,6 +99,8 @@ ohos_static_library("wifi_direct") {
"$wifi_direct_path/utils/wifi_direct_anonymous.cpp",
"$wifi_direct_path/utils/duration_statistic.cpp",
"$wifi_direct_path/utils/wifi_direct_trace.cpp",
"$wifi_direct_path/utils/wifi_direct_timer.cpp",
"$wifi_direct_path/utils/wifi_direct_work_queue.cpp",
"$wifi_direct_path/utils/wifi_direct_utils.cpp",
"$wifi_direct_path/wifi_direct_executor.cpp",
"$wifi_direct_path/wifi_direct_initiator.cpp",

View File

@ -34,6 +34,7 @@
namespace OHOS::SoftBus {
static constexpr char DEFAULT_NET_MASK[] = "255.255.255.0";
static constexpr int CHANNEL_ARRAY_NUM_MAX = 256;
static constexpr int DECIMAL_BASE = 10;
int32_t P2pAdapter::GetChannel5GListIntArray(std::vector<int> &channels)
{

View File

@ -37,13 +37,18 @@ AuthNegotiateChannel::AuthNegotiateChannel(const AuthHandle &handle)
auto ret = AuthGetDeviceUuid(handle_.authId, remoteUuid, UUID_BUF_LEN);
CONN_CHECK_AND_RETURN_LOGE(ret == SOFTBUS_OK, CONN_WIFI_DIRECT, "auth get device id failed");
remoteDeviceId_ = remoteUuid;
auto remoteNetworkId = WifiDirectUtils::UuidToNetworkId(remoteUuid);
if (!WifiDirectUtils::IsDeviceOnline(remoteNetworkId)) {
CONN_LOGI(CONN_WIFI_DIRECT, "diff account");
remoteDeviceId_ = "";
}
CONN_LOGI(CONN_WIFI_DIRECT, "remoteDeviceId=%{public}s", WifiDirectAnonymizeDeviceId(remoteDeviceId_).c_str());
}
AuthNegotiateChannel::~AuthNegotiateChannel()
{
CONN_LOGI(CONN_WIFI_DIRECT, "enter");
if (close_) {
CONN_LOGI(CONN_WIFI_DIRECT, "close auth");
AuthCloseConn(handle_);
}
}
@ -84,14 +89,14 @@ static int64_t GenerateSequence()
int AuthNegotiateChannel::SendMessage(const NegotiateMessage &msg) const
{
CONN_LOGI(CONN_WIFI_DIRECT, "msgType=%{public}s", msg.MessageTypeToString().c_str());
ProtocolType type { ProtocolType::JSON };
if (WifiDirectUtils::IsLocalSupportTlv() && WifiDirectUtils::IsRemoteSupportTlv(remoteDeviceId_)) {
type = ProtocolType::TLV;
ProtocolType type { ProtocolType::TLV };
if (!remoteDeviceId_.empty() && !WifiDirectUtils::IsLocalSupportTlv() &&
!WifiDirectUtils::IsRemoteSupportTlv(remoteDeviceId_)) {
type = ProtocolType::JSON;
}
auto *protocol = WifiDirectProtocolFactory::CreateProtocol(type);
auto protocol = WifiDirectProtocolFactory::CreateProtocol(type);
std::vector<uint8_t> output;
msg.Marshalling(*protocol, output);
delete protocol;
AuthTransData dataInfo = {
.module = MODULE_P2P_LINK,
@ -107,18 +112,22 @@ int AuthNegotiateChannel::SendMessage(const NegotiateMessage &msg) const
static void OnAuthDataReceived(AuthHandle handle, const AuthTransData *data)
{
ProtocolType type { ProtocolType::JSON };
ProtocolType type { ProtocolType::TLV };
auto channel = std::make_shared<AuthNegotiateChannel>(handle);
auto remoteDeviceId = channel->GetRemoteDeviceId();
if (WifiDirectUtils::IsLocalSupportTlv() && WifiDirectUtils::IsRemoteSupportTlv(remoteDeviceId)) {
type = ProtocolType::TLV;
if (!remoteDeviceId.empty() && !WifiDirectUtils::IsLocalSupportTlv() &&
!WifiDirectUtils::IsRemoteSupportTlv(remoteDeviceId)) {
type = ProtocolType::JSON;
}
auto *protocol = WifiDirectProtocolFactory::CreateProtocol(type);
auto protocol = WifiDirectProtocolFactory::CreateProtocol(type);
std::vector<uint8_t> input;
input.insert(input.end(), data->data, data->data + data->len);
NegotiateMessage msg;
msg.Unmarshalling(*protocol, input);
delete protocol;
if (remoteDeviceId.empty()) {
CONN_LOGI(CONN_WIFI_DIRECT, "use remote mac as device id");
remoteDeviceId = msg.GetLinkInfo().GetRemoteBaseMac();
}
msg.SetRemoteDeviceId(remoteDeviceId);
NegotiateCommand command(msg, channel);
@ -212,29 +221,35 @@ void AuthNegotiateChannel::OnConnOpenFailed(uint32_t requestId, int32_t reason)
int AuthNegotiateChannel::OpenConnection(const OpenParam &param, const std::shared_ptr<AuthNegotiateChannel> &channel)
{
bool isMeta = false;
bool needUdid = true;
if (channel != nullptr) {
isMeta = channel->IsMeta();
}
if (param.remoteUuid.length() < UUID_BUF_LEN - 1) {
isMeta = true;
needUdid = false;
}
CONN_LOGI(CONN_WIFI_DIRECT, "remoteUuid=%{public}s, remoteIp=%{public}s, remotePort=%{public}d, isMeta=%{public}d",
WifiDirectAnonymizeDeviceId(param.remoteUuid).c_str(), WifiDirectAnonymizeIp(param.remoteIp).c_str(),
param.remotePort, isMeta);
const char *remoteUdid = LnnConvertDLidToUdid(param.remoteUuid.c_str(), CATEGORY_UUID);
CONN_CHECK_AND_RETURN_RET_LOGE(
remoteUdid != nullptr && strlen(remoteUdid) != 0, SOFTBUS_ERR, CONN_WIFI_DIRECT, "get remote udid failed");
CONN_LOGI(CONN_WIFI_DIRECT, "remoteUdid=%{public}s", WifiDirectAnonymizeDeviceId(remoteUdid).c_str());
AuthConnInfo authConnInfo {};
authConnInfo.type = param.type;
authConnInfo.info.ipInfo.port = param.remotePort;
authConnInfo.info.ipInfo.moduleId = param.module;
if (isMeta) {
if (isMeta && needUdid) {
authConnInfo.info.ipInfo.authId = channel->handle_.authId;
}
int32_t ret = strcpy_s(authConnInfo.info.ipInfo.ip, sizeof(authConnInfo.info.ipInfo.ip), param.remoteIp.c_str());
auto ret = strcpy_s(authConnInfo.info.ipInfo.ip, IP_LEN, param.remoteIp.c_str());
CONN_CHECK_AND_RETURN_RET_LOGW(ret == EOK, SOFTBUS_ERR, CONN_WIFI_DIRECT, "copy ip failed");
ret = strcpy_s(authConnInfo.info.ipInfo.udid, UDID_BUF_LEN, remoteUdid);
CONN_CHECK_AND_RETURN_RET_LOGE(ret == EOK, SOFTBUS_ERR, CONN_WIFI_DIRECT, "copy udid failed");
if (needUdid) {
const char *remoteUdid = LnnConvertDLidToUdid(param.remoteUuid.c_str(), CATEGORY_UUID);
CONN_CHECK_AND_RETURN_RET_LOGE(remoteUdid != nullptr && strlen(remoteUdid) != 0,
SOFTBUS_ERR, CONN_WIFI_DIRECT, "get remote udid failed");
ret = strcpy_s(authConnInfo.info.ipInfo.udid, UDID_BUF_LEN, remoteUdid);
CONN_CHECK_AND_RETURN_RET_LOGE(ret == EOK, SOFTBUS_ERR, CONN_WIFI_DIRECT, "copy udid failed");
}
AuthConnCallback authConnCallback = {
.onConnOpened = AuthNegotiateChannel::OnConnOpened,

View File

@ -43,12 +43,11 @@ static void OnDataReceived(int32_t channelId, const char *data, uint32_t len)
type = ProtocolType::TLV;
}
auto *protocol = WifiDirectProtocolFactory::CreateProtocol(type);
auto protocol = WifiDirectProtocolFactory::CreateProtocol(type);
std::vector<uint8_t> input;
input.insert(input.end(), data, data + len);
NegotiateMessage msg;
msg.Unmarshalling(*protocol, input);
delete protocol;
msg.SetRemoteDeviceId(remoteDeviceId);
NegotiateCommand command(msg, channel);
@ -103,10 +102,9 @@ int CoCProxyNegotiateChannel::SendMessage(const NegotiateMessage &msg) const
if (WifiDirectUtils::IsLocalSupportTlv() && WifiDirectUtils::IsRemoteSupportTlv(remoteDeviceId_)) {
type = ProtocolType::TLV;
}
auto *protocol = WifiDirectProtocolFactory::CreateProtocol(type);
auto protocol = WifiDirectProtocolFactory::CreateProtocol(type);
std::vector<uint8_t> output;
msg.Marshalling(*protocol, output);
delete protocol;
auto ret = TransProxyPipelineSendMessage(
channelId_, output.data(), static_cast<uint32_t>(output.size()), MSG_TYPE_P2P_NEGO);

View File

@ -17,7 +17,6 @@
#include <cstring>
#include "conn_log.h"
#include "channel/auth_negotiate_channel.h"
#include "channel/dummy_negotiate_channel.h"
#include "channel/proxy_negotiate_channel.h"
@ -72,15 +71,16 @@ WifiDirectConnectCallback ConnectCommand::GetConnectCallback() const
void ConnectCommand::OnSuccess(const WifiDirectLink &link) const
{
CONN_LOGI(CONN_WIFI_DIRECT,
"requestId=%{public}u linkId=%{public}d, localIp=%{public}s, remoteIp=%{public}s, remotePort=%{public}d, "
"linkType=%{public}d",
"requestId=%{public}u, linkId=%{public}d, localIp=%{public}s, remoteIp=%{public}s, remotePort=%{public}d, "
"linkType=%{public}d, isReuse=%{public}d, bw=%{public}d, channelId=%{public}d",
info_.info_.requestId, link.linkId, WifiDirectAnonymizeIp(link.localIp).c_str(),
WifiDirectAnonymizeIp(link.remoteIp).c_str(), link.remotePort, link.linkType);
WifiDirectAnonymizeIp(link.remoteIp).c_str(), link.remotePort, link.linkType, link.isReuse,
link.bandWidth, link.channelId);
DfxRecord(true, OK);
callback_.onConnectSuccess(info_.info_.requestId, &link);
}
void ConnectCommand::OnFailure(WifiDirectErrorCode reason) const
void ConnectCommand::OnFailure(int reason) const
{
CONN_LOGI(CONN_WIFI_DIRECT, "requestId=%{public}u, reason=%{public}d", info_.info_.requestId, reason);
DfxRecord(false, reason);
@ -108,12 +108,12 @@ void ConnectCommand::PreferNegotiateChannel()
info_.channel_ = innerLink->GetNegotiateChannel();
}
bool ConnectCommand::IsSameCommand(const WifiDirectConnectInfo &info)
bool ConnectCommand::IsSameCommand(const WifiDirectConnectInfo &info) const
{
return (info.requestId == info_.info_.requestId) && (info.pid == info_.info_.pid);
}
void ConnectCommand::DfxRecord(bool isSuccess, WifiDirectErrorCode reason) const
void ConnectCommand::DfxRecord(bool isSuccess, int reason) const
{
if (isSuccess) {
DurationStatistic::GetInstance().Record(info_.info_.requestId, TotalEnd);
@ -130,7 +130,7 @@ void ConnectCommand::DfxRecord(bool isSuccess, WifiDirectErrorCode reason) const
DurationStatistic::GetInstance().Clear(info_.info_.requestId);
ConnEventExtra extra = {
.result = EVENT_STAGE_RESULT_FAILED,
.errcode = static_cast<int32_t>(reason),
.errcode = reason,
.requestId = static_cast<int32_t>(info_.info_.requestId),
};
FillConnEventExtra(extra);

View File

@ -46,8 +46,8 @@ public:
bool HasRetried() const { return hasRetried_; }
void OnSuccess(const WifiDirectLink &link) const;
void OnFailure(WifiDirectErrorCode reason) const;
bool IsSameCommand(const WifiDirectConnectInfo &info);
void OnFailure(int reason) const;
bool IsSameCommand(const WifiDirectConnectInfo &info) const;
protected:
ConnectInfo info_;
@ -55,7 +55,7 @@ protected:
mutable std::string remoteDeviceId_;
bool hasRetried_ = false;
void DfxRecord(bool isSuccess, WifiDirectErrorCode reason) const;
void DfxRecord(bool isSuccess, int reason) const;
void FillConnEventExtra(ConnEventExtra &extra) const;
};
}

View File

@ -86,7 +86,7 @@ void DisconnectCommand::OnSuccess() const
callback_.onDisconnectSuccess(info_.info_.requestId);
}
void DisconnectCommand::OnFailure(WifiDirectErrorCode reason) const
void DisconnectCommand::OnFailure(int reason) const
{
CONN_LOGI(CONN_WIFI_DIRECT, "requestId=%{public}u, reason=%{public}d", info_.info_.requestId, reason);
callback_.onDisconnectFailure(info_.info_.requestId, reason);

View File

@ -41,7 +41,7 @@ public:
std::shared_ptr<NegotiateChannel> GetNegotiateChannel() const;
void OnSuccess() const;
void OnFailure(WifiDirectErrorCode reason) const;
void OnFailure(int reason) const;
protected:
DisconnectInfo info_;

View File

@ -17,7 +17,6 @@
#include <memory>
#include <string>
#include "processor/wifi_direct_processor.h"
namespace OHOS::SoftBus {
enum class CommandType {

View File

@ -247,7 +247,17 @@ void InnerLink::SetRemoteIpv6(const std::string &value)
Set(InnerLinKey::REMOTE_IPV6, value);
}
void InnerLink::GenerateLink(uint32_t requestId, int pid, WifiDirectLink &link)
bool InnerLink::HasPtk() const
{
return Get(InnerLinKey::HAS_PTK, false);
}
void InnerLink::SetPtk(bool value)
{
Set(InnerLinKey::HAS_PTK, value);
}
void InnerLink::GenerateLink(uint32_t requestId, int pid, WifiDirectLink &link, bool ipv4)
{
link.linkId = LinkManager::GetInstance().AllocateLinkId();
AddId(link.linkId, requestId, pid);
@ -262,13 +272,20 @@ void InnerLink::GenerateLink(uint32_t requestId, int pid, WifiDirectLink &link)
link.linkType = WIFI_DIRECT_LINK_TYPE_INVALID;
break;
}
auto localIpv4 = GetLocalIpv4();
if (strcpy_s(link.localIp, IP_STR_MAX_LEN, localIpv4.c_str()) != EOK) {
std::string localIp;
std::string remoteIp;
if (ipv4 || GetLocalIpv6().empty()) {
localIp = GetLocalIpv4();
remoteIp = GetRemoteIpv4();
} else {
localIp = GetLocalIpv6();
remoteIp = GetRemoteIpv6();
}
if (strcpy_s(link.localIp, IP_STR_MAX_LEN, localIp.c_str()) != EOK) {
CONN_LOGI(CONN_WIFI_DIRECT, "local ip cpy failed, link id=%{public}d", link.linkId);
// fall-through
}
auto remoteIpv4 = GetRemoteIpv4();
if (strcpy_s(link.remoteIp, IP_STR_MAX_LEN, remoteIpv4.c_str()) != EOK) {
if (strcpy_s(link.remoteIp, IP_STR_MAX_LEN, remoteIp.c_str()) != EOK) {
CONN_LOGI(CONN_WIFI_DIRECT, "remote ip cpy failed, link id=%{public}d", link.linkId);
// fall-through
}
@ -327,8 +344,8 @@ void InnerLink::Dump() const
object["REMOTE_BASE_MAC"] = WifiDirectAnonymizeMac(GetRemoteBaseMac());
object["LOCAL_IPV4"] = WifiDirectAnonymizeIp(GetLocalIpv4());
object["REMOTE_IPV4"] = WifiDirectAnonymizeIp(GetRemoteIpv4());
object["LOCAL_IPV6"] = GetLocalIpv6();
object["REMOTE_IPV6"] = GetRemoteIpv6();
object["LOCAL_IPV6"] = WifiDirectAnonymizeIp(GetLocalIpv6());
object["REMOTE_IPV6"] = WifiDirectAnonymizeIp(GetRemoteIpv6());
object["IS_BEING_USED_BY_LOCAL"] = IsBeingUsedByLocal();
object["IS_BEING_USED_BY_REMOTE"] = IsBeingUsedByRemote();
object["FREQUENCY"] = GetFrequency();

View File

@ -48,6 +48,7 @@ enum class InnerLinKey {
LISTENER_MODULE_ID = 18,
LOCAL_IPV6 = 19,
REMOTE_IPV6 = 20,
HAS_PTK = 21,
};
struct LinkIdStruct {
@ -133,7 +134,10 @@ public:
std::string GetRemoteIpv6() const;
void SetRemoteIpv6(const std::string &value);
void GenerateLink(uint32_t requestId, int pid, WifiDirectLink &link);
bool HasPtk() const;
void SetPtk(bool value);
void GenerateLink(uint32_t requestId, int pid, WifiDirectLink &link, bool ipv4);
void RemoveId(int linkId);
bool IsContainId(int linkId) const;

View File

@ -183,6 +183,11 @@ std::string InterfaceInfo::GetName() const
return Get(InterfaceInfoKey::INTERFACE_NAME, std::string(""));
}
std::vector<uint8_t> InterfaceInfo::GetChannelAndBandWidth() const
{
return Get(InterfaceInfoKey::CHANNEL_AND_BANDWIDTH, std::vector<uint8_t>());
}
void InterfaceInfo::SetIpString(const Ipv4Info &ipv4Info)
{
Set(InterfaceInfoKey::IPV4, ipv4Info);
@ -281,6 +286,16 @@ int InterfaceInfo::GetCenter20M() const
return Get(InterfaceInfoKey::CENTER_20M, 0);
}
void InterfaceInfo::SetBandWidth(int value)
{
Set(InterfaceInfoKey::BANDWIDTH, value);
}
int InterfaceInfo::GetBandWidth() const
{
return Get(InterfaceInfoKey::BANDWIDTH, 0);
}
void InterfaceInfo::SetIsEnable(bool value)
{
Set(InterfaceInfoKey::IS_ENABLE, value);
@ -377,5 +392,4 @@ void InterfaceInfo::DecreaseRefCount()
Set(InterfaceInfoKey::REUSE_COUNT, count);
CONN_LOGI(CONN_WIFI_DIRECT, "reuseCount = %{public}d", count);
}
} // namespace OHOS::SoftBus

View File

@ -75,6 +75,8 @@ public:
void SetName(const std::string &value);
std::string GetName() const;
std::vector<uint8_t> GetChannelAndBandWidth() const;
void SetIpString(const Ipv4Info &ipv4Info);
Ipv4Info GetIpString() const;
@ -104,6 +106,9 @@ public:
void SetCenter20M(int value);
int GetCenter20M() const;
void SetBandWidth(int value);
int GetBandWidth() const;
void SetIsEnable(bool value);
bool IsEnable() const;

View File

@ -43,6 +43,7 @@ template<> InfoContainer<LinkInfoKey>::KeyTypeTable InfoContainer<LinkInfoKey>::
{ LinkInfoKey::REMOTE_BASE_MAC, Serializable::ValueType::STRING },
{ LinkInfoKey::LOCAL_IPV6, Serializable::ValueType::STRING },
{ LinkInfoKey::REMOTE_IPV6, Serializable::ValueType::STRING },
{ LinkInfoKey::CUSTOM_PORT, Serializable::ValueType::INT },
};
LinkInfo::LinkInfo(const std::string &localInterface, const std::string &remoteInterface, LinkMode localMode,
@ -72,7 +73,7 @@ int LinkInfo::Marshalling(WifiDirectProtocol &protocol, std::vector<uint8_t> &ou
break;
case Serializable::ValueType::STRING: {
const auto &data = std::any_cast<const std::string &>(value);
protocol.Write(static_cast<int>(key), type, (uint8_t *)data.c_str(), data.length() + 1);
protocol.Write(static_cast<int>(key), type, (uint8_t *)data.c_str(), data.length());
}
break;
case Serializable::ValueType::IPV4_INFO: {
@ -107,11 +108,9 @@ int LinkInfo::Unmarshalling(WifiDirectProtocol &protocol, const std::vector<uint
case Serializable::ValueType::INT:
Set(LinkInfoKey(key), *(int *)(data));
break;
case Serializable::ValueType::STRING: {
std::string str(std::string(reinterpret_cast<const char *>(data)), 0, size);
Set(LinkInfoKey(key), str);
case Serializable::ValueType::STRING:
Set(LinkInfoKey(key), std::string(reinterpret_cast<const char *>(data), size));
break;
}
case Serializable::ValueType::IPV4_INFO: {
Ipv4Info ipv4Info;
ipv4Info.Unmarshalling(data, size);
@ -343,7 +342,7 @@ void LinkInfo::SetLocalIpv6(const std::string &value)
Set(LinkInfoKey::LOCAL_IPV6, value);
}
std::string LinkInfo::GetLocalIpv6()
std::string LinkInfo::GetLocalIpv6() const
{
return Get(LinkInfoKey::LOCAL_IPV6, std::string());
}
@ -353,8 +352,18 @@ void LinkInfo::SetRemoteIpv6(const std::string &value)
Set(LinkInfoKey::REMOTE_IPV6, value);
}
std::string LinkInfo::GetRemoteIpv6()
std::string LinkInfo::GetRemoteIpv6() const
{
return Get(LinkInfoKey::REMOTE_IPV6, std::string());
}
void LinkInfo::SetCustomPort(int value)
{
Set(LinkInfoKey::CUSTOM_PORT, value);
}
int LinkInfo::GetCustomPort()
{
return Get(LinkInfoKey::CUSTOM_PORT, 0);
}
}

View File

@ -47,6 +47,7 @@ enum class LinkInfoKey {
IS_CLIENT = 20,
LOCAL_IPV6 = 21,
REMOTE_IPV6 = 22,
CUSTOM_PORT = 23,
};
class LinkInfo : public Serializable, public InfoContainer<LinkInfoKey> {
@ -132,10 +133,13 @@ public:
bool GetIsClient() const;
void SetLocalIpv6(const std::string &value);
std::string GetLocalIpv6();
std::string GetLocalIpv6() const;
void SetRemoteIpv6(const std::string &value);
std::string GetRemoteIpv6();
std::string GetRemoteIpv6() const;
void SetCustomPort(int value);
int GetCustomPort();
};
}
#endif

View File

@ -153,6 +153,18 @@ void LinkManager::RemoveLink(InnerLink::LinkType type, const std::string &remote
}
}
void LinkManager::RemoveLink(const std::string &remoteMac)
{
std::lock_guard lock(lock_);
for (const auto &[key, value] : links_) {
if (remoteMac == value->GetRemoteBaseMac() && value->GetState() == InnerLink::LinkState::CONNECTED) {
CONN_LOGD(CONN_WIFI_DIRECT, "remoteMac=%{public}s", WifiDirectAnonymizeMac(remoteMac).c_str());
links_.erase(key);
return;
}
}
}
void LinkManager::RemoveLinks(InnerLink::LinkType type)
{
std::lock_guard lock(lock_);
@ -172,13 +184,26 @@ void LinkManager::RemoveLinks(InnerLink::LinkType type)
}
}
std::shared_ptr<InnerLink> LinkManager::GetReuseLink(const std::string &remoteMac)
{
std::lock_guard lock(lock_);
for (const auto &[key, link] : links_) {
if (link->GetRemoteBaseMac() == remoteMac && link->GetState() == InnerLink::LinkState::CONNECTED) {
return link;
}
}
CONN_LOGE(CONN_WIFI_DIRECT, "not find remoteMac=%{public}s", WifiDirectAnonymizeMac(remoteMac).c_str());
return nullptr;
}
std::shared_ptr<InnerLink> LinkManager::GetReuseLink(
WifiDirectConnectType connectType, const std::string &remoteDeviceId)
{
WifiDirectLinkType linkType = WIFI_DIRECT_LINK_TYPE_P2P;
if (connectType == WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_HML ||
connectType == WIFI_DIRECT_CONNECT_TYPE_BLE_TRIGGER_HML ||
connectType == WIFI_DIRECT_CONNECT_TYPE_AUTH_TRIGGER_HML) {
connectType == WIFI_DIRECT_CONNECT_TYPE_AUTH_TRIGGER_HML ||
connectType == WIFI_DIRECT_CONNECT_TYPE_ACTION_TRIGGER_HML) {
linkType = WIFI_DIRECT_LINK_TYPE_HML;
}
@ -198,11 +223,28 @@ std::shared_ptr<InnerLink> LinkManager::GetReuseLink(
std::lock_guard lock(lock_);
auto iterator = links_.find({linkType, remoteDeviceId});
if (iterator == links_.end() || iterator->second->GetState() != InnerLink::LinkState::CONNECTED) {
CONN_LOGE(CONN_WIFI_DIRECT, "not find remoteDeviceId=%{public}s",
WifiDirectAnonymizeDeviceId(remoteDeviceId).c_str());
return nullptr;
}
return iterator->second;
}
void LinkManager::RefreshRelationShip(const std::string &remoteDeviceId, const std::string &remoteMac)
{
std::lock_guard lock(lock_);
auto it = links_.find({ InnerLink::LinkType::HML, remoteMac });
if (it == links_.end()) {
CONN_LOGE(CONN_WIFI_DIRECT, "not find %{public}s", WifiDirectAnonymizeMac(remoteMac).c_str());
return;
}
auto link = it->second;
links_.erase(it);
link->SetRemoteDeviceId(remoteDeviceId);
links_.insert({{ InnerLink::LinkType::HML, remoteDeviceId }, link });
}
void LinkManager::Dump() const
{
std::lock_guard lock(lock_);

View File

@ -47,10 +47,14 @@ public:
bool ProcessIfPresent(int linkId, const Handler &handler);
void RemoveLink(InnerLink::LinkType type, const std::string &remoteDeviceId);
void RemoveLink(const std::string &remoteMac);
void RemoveLinks(InnerLink::LinkType type);
std::shared_ptr<InnerLink> GetReuseLink(const std::string &remoteMac);
std::shared_ptr<InnerLink> GetReuseLink(WifiDirectConnectType connectType, const std::string &remoteDeviceId);
std::shared_ptr<InnerLink> GetReuseLink(WifiDirectLinkType linkType, const std::string &remoteDeviceId);
void RefreshRelationShip(const std::string &remoteDeviceId, const std::string &remoteMac);
void Dump() const;
private:

View File

@ -113,7 +113,9 @@ static std::map<NegotiateMessageType, std::string> g_messageNameMap = {
{ NegotiateMessageType::CMD_RENEGOTIATE_REQ, "CMD_RENEGOTIATE_REQ" },
{ NegotiateMessageType::CMD_RENEGOTIATE_RESP, "CMD_RENEGOTIATE_RESP" },
{ NegotiateMessageType::CMD_AUTH_HAND_SHAKE, "CMD_AUTH_HAND_SHAKE" },
{ NegotiateMessageType::CMD_AUTH_HAND_SHAKE_RSP, "CMD_AUTH_HAND_SHAKE_RSP" },
{ NegotiateMessageType::CMD_V3_REQ, "CMD_V3_REQ" },
{ NegotiateMessageType::CMD_V3_RSP, "CMD_V3_RSP" },
};
static std::map<LegacyCommandType, std::string> g_legacyMessageNameMap = {
@ -170,7 +172,7 @@ int NegotiateMessage::Marshalling(WifiDirectProtocol &protocol, std::vector<uint
break;
case Serializable::ValueType::STRING: {
auto data = std::any_cast<std::string>(value);
protocol.Write(static_cast<int>(key), type, (uint8_t *)data.c_str(), data.length() + 1);
protocol.Write(static_cast<int>(key), type, (uint8_t *)data.c_str(), data.length());
}
break;
case Serializable::ValueType::BYTE_ARRAY: {
@ -212,21 +214,20 @@ void NegotiateMessage::MarshallingInterfaceArray(WifiDirectProtocol &protocol) c
{
auto interfaceArray = GetInterfaceInfoArray();
for (const auto &interface : interfaceArray) {
WifiDirectProtocol *pro = WifiDirectProtocolFactory::CreateProtocol(protocol.GetType());
auto pro = WifiDirectProtocolFactory::CreateProtocol(protocol.GetType());
if (pro != nullptr) {
std::vector<uint8_t> interfaceOutput;
pro->SetFormat(protocol.GetFormat());
interface.Marshalling(*pro, interfaceOutput);
protocol.Write(static_cast<int>(NegotiateMessageKey::INTERFACE_INFO_ARRAY),
Serializable::ValueType::INTERFACE_INFO_ARRAY, interfaceOutput.data(), interfaceOutput.size());
delete pro;
}
}
}
void NegotiateMessage::MarshallingLinkInfo(WifiDirectProtocol &protocol) const
{
WifiDirectProtocol *pro = WifiDirectProtocolFactory::CreateProtocol(protocol.GetType());
auto pro = WifiDirectProtocolFactory::CreateProtocol(protocol.GetType());
if (pro == nullptr) {
CONN_LOGE(CONN_WIFI_DIRECT, "create protocol failed");
return;
@ -238,7 +239,6 @@ void NegotiateMessage::MarshallingLinkInfo(WifiDirectProtocol &protocol) const
linkInfo.Marshalling(*pro, output);
protocol.Write(static_cast<int>(NegotiateMessageKey::LINK_INFO), Serializable::ValueType::LINK_INFO, output.data(),
output.size());
delete pro;
}
int NegotiateMessage::Unmarshalling(WifiDirectProtocol &protocol, const std::vector<uint8_t> &input)
@ -298,7 +298,7 @@ void NegotiateMessage::UnmarshallingIpv4Array(uint8_t *data, size_t size)
void NegotiateMessage::UnmarshallingInterfaceArray(WifiDirectProtocol &protocol, uint8_t *data, size_t size)
{
WifiDirectProtocol *pro = WifiDirectProtocolFactory::CreateProtocol(protocol.GetType());
auto pro = WifiDirectProtocolFactory::CreateProtocol(protocol.GetType());
if (pro == nullptr) {
return;
}
@ -314,7 +314,7 @@ void NegotiateMessage::UnmarshallingInterfaceArray(WifiDirectProtocol &protocol,
void NegotiateMessage::UnmarshallingLinkInfo(WifiDirectProtocol &protocol, uint8_t *data, size_t size)
{
WifiDirectProtocol *pro = WifiDirectProtocolFactory::CreateProtocol(protocol.GetType());
auto pro = WifiDirectProtocolFactory::CreateProtocol(protocol.GetType());
if (pro == nullptr) {
return;
}

View File

@ -74,6 +74,7 @@ enum class NegotiateMessageType {
CMD_RENEGOTIATE_REQ = 53,
CMD_RENEGOTIATE_RESP = 54,
CMD_AUTH_HAND_SHAKE = 55,
CMD_AUTH_HAND_SHAKE_RSP = 56,
CMD_V3_REQ = 100,
CMD_V3_RSP = 101,

View File

@ -18,7 +18,6 @@
#include "softbus_error_code.h"
namespace OHOS::SoftBus {
static constexpr int LENGTH_HEADER = 2;
template <>
InfoContainer<WifiConfigInfoKey>::KeyTypeTable InfoContainer<WifiConfigInfoKey>::keyTypeTable_ = {
{WifiConfigInfoKey::INTERFACE_INFO_ARRAY, Serializable::ValueType::INTERFACE_INFO_ARRAY},
@ -27,22 +26,15 @@ InfoContainer<WifiConfigInfoKey>::KeyTypeTable InfoContainer<WifiConfigInfoKey>:
WifiConfigInfo::WifiConfigInfo(std::vector<uint8_t> &config)
{
std::vector<uint8_t> configInfo = config;
configInfo.erase(configInfo.begin(), configInfo.begin() + LENGTH_HEADER);
WifiDirectProtocol *pro = WifiDirectProtocolFactory::CreateProtocol(ProtocolType::TLV);
auto pro = WifiDirectProtocolFactory::CreateProtocol(ProtocolType::TLV);
if (pro == nullptr) {
CONN_LOGE(CONN_WIFI_DIRECT, "create tlv protocol failed");
return;
}
pro->SetFormat(ProtocolFormat { TlvProtocol::TLV_TAG_SIZE, TlvProtocol::TLV_LENGTH_SIZE1 });
Unmarshalling(*pro, configInfo);
delete pro;
Unmarshalling(*pro, std::vector<uint8_t>(config.begin() + HEADER_LEN, config.end()));
}
WifiConfigInfo::~WifiConfigInfo() { }
WifiConfigInfo::WifiConfigInfo() { }
int WifiConfigInfo::Unmarshalling(WifiDirectProtocol &protocol, const std::vector<uint8_t> &input)
{
int key = 0;
@ -67,14 +59,13 @@ void WifiConfigInfo::MarshallingInterfaceArray(WifiDirectProtocol &protocol) con
{
auto interfaceArray = GetInterfaceInfoArray();
for (const auto &interface : interfaceArray) {
WifiDirectProtocol *pro = WifiDirectProtocolFactory::CreateProtocol(protocol.GetType());
auto pro = WifiDirectProtocolFactory::CreateProtocol(protocol.GetType());
if (pro != nullptr) {
std::vector<uint8_t> interfaceOutput;
std::vector<uint8_t> output;
pro->SetFormat(protocol.GetFormat());
interface.Marshalling(*pro, interfaceOutput);
interface.Marshalling(*pro, output);
protocol.Write(static_cast<int>(WifiConfigInfoKey::INTERFACE_INFO_ARRAY),
Serializable::ValueType::INTERFACE_INFO_ARRAY, interfaceOutput.data(), interfaceOutput.size());
delete pro;
Serializable::ValueType::INTERFACE_INFO_ARRAY, output.data(), output.size());
}
}
}
@ -97,21 +88,14 @@ int WifiConfigInfo::Marshalling(WifiDirectProtocol &protocol, std::vector<uint8_
void WifiConfigInfo::UnmarshallingInterfaceArray(WifiDirectProtocol &protocol, uint8_t *data, size_t size)
{
if (data == nullptr) {
CONN_LOGW(CONN_WIFI_DIRECT, "invalil para data");
return;
}
WifiDirectProtocol *pro = WifiDirectProtocolFactory::CreateProtocol(protocol.GetType());
if (pro == nullptr) {
CONN_LOGW(CONN_WIFI_DIRECT, "create protocol failed");
return;
}
CONN_CHECK_AND_RETURN_LOGW(data != nullptr, CONN_WIFI_DIRECT, "data is nullptr");
auto pro = WifiDirectProtocolFactory::CreateProtocol(protocol.GetType());
CONN_CHECK_AND_RETURN_LOGE(pro != nullptr, CONN_WIFI_DIRECT, "create protocol failed");
pro->SetFormat(ProtocolFormat { TlvProtocol::TLV_TAG_SIZE, TlvProtocol::TLV_LENGTH_SIZE1 });
InterfaceInfo info;
std::vector<uint8_t> input(data, data + size);
info.Unmarshalling(*pro, input);
delete pro;
auto interfaceArray = GetInterfaceInfoArray();
interfaceArray.push_back(info);
SetInterfaceInfoArray(interfaceArray);
@ -147,5 +131,4 @@ std::string WifiConfigInfo::GetDeviceId() const
{
return Get(WifiConfigInfoKey::DEVICE_ID, std::string(""));
}
} // namespace OHOS::SoftBus
} // namespace OHOS::SoftBus

View File

@ -46,15 +46,13 @@ enum class WifiConfigInfoKey {
class WifiConfigInfo : public Serializable, public InfoContainer<WifiConfigInfoKey> {
public:
WifiConfigInfo();
WifiConfigInfo() = default;
explicit WifiConfigInfo(std::vector<uint8_t> &config);
~WifiConfigInfo();
~WifiConfigInfo() override = default;
int Marshalling(WifiDirectProtocol &protocol, std::vector<uint8_t> &output) const override;
int Unmarshalling(WifiDirectProtocol &protocol, const std::vector<uint8_t> &input) override;
static void MarshallingString(
WifiDirectProtocol &protocol, InterfaceInfoKey key, Serializable::ValueType type, const std::string &value);
/* Get/Set */
void SetInterfaceInfoArray(const std::vector<InterfaceInfo> &value);
std::vector<InterfaceInfo> GetInterfaceInfoArray() const;
InterfaceInfo GetInterfaceInfo(const std::string &name) const;
@ -63,6 +61,7 @@ public:
std::string GetDeviceId() const;
private:
static constexpr int HEADER_LEN = 2;
void MarshallingInterfaceArray(WifiDirectProtocol &protocol) const;
void UnmarshallingInterfaceArray(WifiDirectProtocol &protocol, uint8_t *data, size_t size);
};

View File

@ -54,10 +54,12 @@ P2pV1Processor::~P2pV1Processor()
StopTimer();
timer_.Shutdown();
RemoveExclusive();
WifiDirectUtils::SerialFlowExit();
}
[[noreturn]] void P2pV1Processor::Run()
{
WifiDirectUtils::SerialFlowEnter();
for (;;) {
(this->*state_)();
}
@ -1051,7 +1053,8 @@ int P2pV1Processor::ProcessReuseResponse(std::shared_ptr<NegotiateCommand> &comm
auto pid = connectCommand_->GetConnectInfo().info_.pid;
WifiDirectLink dlink {};
auto success = LinkManager::GetInstance().ProcessIfPresent(remoteMac, [requestId, pid, &dlink](InnerLink &link) {
link.GenerateLink(requestId, pid, dlink);
link.GenerateLink(requestId, pid, dlink, true);
dlink.channelId = WifiDirectUtils::FrequencyToChannel(link.GetFrequency());
});
CONN_CHECK_AND_RETURN_RET_LOGW(success, SOFTBUS_ERR, CONN_WIFI_DIRECT, "update inner link failed");
connectCommand_->OnSuccess(dlink);
@ -1104,7 +1107,8 @@ int P2pV1Processor::ProcessAuthHandShakeRequest(std::shared_ptr<NegotiateCommand
link.SetNegotiateChannel(channel);
if (connectCommand_ != nullptr) {
link.GenerateLink(connectCommand_->GetConnectInfo().info_.requestId,
connectCommand_->GetConnectInfo().info_.pid, dlink);
connectCommand_->GetConnectInfo().info_.pid, dlink, true);
dlink.channelId = WifiDirectUtils::FrequencyToChannel(link.GetFrequency());
}
});
CONN_CHECK_AND_RETURN_RET_LOGW(success, SOFTBUS_NOT_FIND, CONN_WIFI_DIRECT,
@ -1258,8 +1262,9 @@ int P2pV1Processor::ProcessConnectResponseAsGo(std::shared_ptr<NegotiateCommand>
remoteMac, [msg, requestId, pid, &dlink, &alreadyAuthHandShake](InnerLink &link) {
link.SetState(InnerLink::LinkState::CONNECTED);
link.SetRemoteIpv4(msg.GetLegacyP2pIp());
link.GenerateLink(requestId, pid, dlink);
link.GenerateLink(requestId, pid, dlink, true);
link.GetNegotiateChannel();
dlink.channelId = WifiDirectUtils::FrequencyToChannel(link.GetFrequency());
alreadyAuthHandShake = link.GetNegotiateChannel() != nullptr;
});
CONN_CHECK_AND_RETURN_RET_LOGW(success, SOFTBUS_NOT_FIND, CONN_WIFI_DIRECT, "update inner link failed");
@ -1314,7 +1319,8 @@ int P2pV1Processor::ProcessConnectResponseWithGoInfoAsNone(std::shared_ptr<Negot
WifiDirectLink dlink {};
auto success = LinkManager::GetInstance().ProcessIfPresent(
InnerLink::LinkType::P2P, command->GetRemoteDeviceId(), [requestId, pid, &dlink](InnerLink &link) {
link.GenerateLink(requestId, pid, dlink);
link.GenerateLink(requestId, pid, dlink, true);
dlink.channelId = WifiDirectUtils::FrequencyToChannel(link.GetFrequency());
});
CONN_CHECK_AND_RETURN_RET_LOGW(success, SOFTBUS_ERR, CONN_WIFI_DIRECT, "update inner link failed");
connectCommand_->OnSuccess(dlink);
@ -1364,7 +1370,8 @@ int P2pV1Processor::ProcessConnectResponseAtWaitAuthHandShake(std::shared_ptr<Ne
auto success = LinkManager::GetInstance().ProcessIfPresent(
remoteMac, [msg, requestId, pid, &dlink, &alreadyAuthHandShake](InnerLink &link) {
link.SetState(InnerLink::LinkState::CONNECTED);
link.GenerateLink(requestId, pid, dlink);
link.GenerateLink(requestId, pid, dlink, true);
dlink.channelId = WifiDirectUtils::FrequencyToChannel(link.GetFrequency());
});
CONN_CHECK_AND_RETURN_RET_LOGW(success, SOFTBUS_NOT_FIND, CONN_WIFI_DIRECT,
"link not found, remoteMac=%{public}s", WifiDirectAnonymizeMac(remoteMac).c_str());
@ -1562,7 +1569,7 @@ int P2pV1Processor::ReuseLink(const std::shared_ptr<ConnectCommand> &command, In
if (isBeingUsedByLocal) {
CONN_LOGI(CONN_WIFI_DIRECT, "reuse success");
WifiDirectLink dlink {};
link.GenerateLink(requestId, pid, dlink);
link.GenerateLink(requestId, pid, dlink, true);
command->OnSuccess(dlink);
Terminate();
return SOFTBUS_OK;

View File

@ -26,20 +26,20 @@ class WifiDirectCommand;
class WifiDirectProcessor {
public:
explicit WifiDirectProcessor(const std::string &remoteUuid)
: remoteDeviceId_(remoteUuid), acceptNegotiateData_(true) {};
: remoteDeviceId_(remoteUuid), acceptNegotiateData_(true) {}
virtual ~WifiDirectProcessor() = default;
void BindExecutor(WifiDirectExecutor *executor)
{
executor_ = executor;
};
}
virtual void Run() = 0;
void SetRejectNegotiateData()
{
acceptNegotiateData_ = false;
};
}
bool CanAcceptNegotiateData(WifiDirectCommand &command)
{
@ -47,7 +47,7 @@ public:
return false;
}
return CanAcceptNegotiateDataAtState(command);
};
}
virtual bool CanAcceptNegotiateDataAtState(WifiDirectCommand &command) = 0;
virtual void HandleCommandAfterTerminate(WifiDirectCommand &command) = 0;

View File

@ -15,19 +15,20 @@
#ifndef WIFI_DIRECT_PROTOCOL_FACTORY_H
#define WIFI_DIRECT_PROTOCOL_FACTORY_H
#include <memory>
#include "json_protocol.h"
#include "tlv_protocol.h"
namespace OHOS::SoftBus {
class WifiDirectProtocolFactory {
public:
static WifiDirectProtocol *CreateProtocol(ProtocolType type)
static std::shared_ptr<WifiDirectProtocol> CreateProtocol(ProtocolType type)
{
switch (type) {
case ProtocolType::JSON:
return new (std::nothrow) JsonProtocol();
return std::make_shared<JsonProtocol>();
case ProtocolType::TLV:
return new (std::nothrow) TlvProtocol();
return std::make_shared<TlvProtocol>();
default:
return nullptr;
}

View File

@ -0,0 +1,97 @@
/*
* Copyright (c) 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "wifi_direct_timer.h"
#include "conn_log.h"
#include "message_handler.h"
#include "softbus_adapter_mem.h"
namespace OHOS::SoftBus {
WifiDirectTimer::WifiDirectTimer(const std::string &name)
: name_(name)
{
}
WifiDirectTimer::~WifiDirectTimer()
{
}
void WifiDirectTimer::WorkHandler(void *data)
{
std::lock_guard lock(timerIdMapLock_);
auto *timer = static_cast<TimerDescriptor *>(data);
CONN_LOGI(CONN_WIFI_DIRECT, "timerId=%{public}d", timer->timerId);
timer->callback();
timerIdMap_.erase(timer->timerId);
SoftBusFree(timer);
if (timerIdMap_.empty()) {
CONN_LOGI(CONN_WIFI_DIRECT, "destroy work queue");
workQueue_ = nullptr;
}
}
int32_t WifiDirectTimer::Register(const TimerCallback &callback, int32_t timeout)
{
std::lock_guard lock(timerIdMapLock_);
auto *timer = static_cast<TimerDescriptor *>(SoftBusCalloc(sizeof(TimerDescriptor)));
CONN_CHECK_AND_RETURN_RET_LOGE(timer != nullptr, TIMER_ID_INVALID, CONN_WIFI_DIRECT, "malloc timer failed");
auto *work = static_cast<WifiDirectWorkQueue::Work *>(SoftBusCalloc(sizeof(WifiDirectWorkQueue::Work)));
if (work == nullptr) {
SoftBusFree(timer);
CONN_LOGE(CONN_WIFI_DIRECT, "malloc work failed");
return TIMER_ID_INVALID;
}
if (timerIdMap_.empty()) {
workQueue_ = std::make_shared<WifiDirectWorkQueue>();
}
work->work = WorkHandler ;
work->data = timer;
timer->timerId = AllocTimerId();
timer->callback = callback;
timerIdMap_.insert({ timer->timerId, timer });
workQueue_->ScheduleDelayWork(work, timeout);
CONN_LOGI(CONN_WIFI_DIRECT, "timerId=%{public}d timeout=%d", timer->timerId, timeout);
return timer->timerId;
}
void WifiDirectTimer::Unregister(int32_t timerId)
{
std::lock_guard lock(timerIdMapLock_);
CONN_LOGI(CONN_WIFI_DIRECT, "timerId=%{public}d", timerId);
auto it = timerIdMap_.find(timerId);
if (it == timerIdMap_.end()) {
CONN_LOGE(CONN_WIFI_DIRECT, "not find timerId=%{public}d", timerId);
return;
}
workQueue_->RemoveWork(it->second->work);
SoftBusFree(it->second);
timerIdMap_.erase(it);
if (timerIdMap_.empty()) {
CONN_LOGI(CONN_WIFI_DIRECT, "destroy work queue");
workQueue_ = nullptr;
}
}
int32_t WifiDirectTimer::AllocTimerId()
{
if (timerId_ < 0) {
timerId_ = 0;
}
return timerId_++;
}
}

View File

@ -0,0 +1,56 @@
/*
* Copyright (c) 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef WIFI_DIRECT_TIMER_H
#define WIFI_DIRECT_TIMER_H
#include <functional>
#include <string>
#include <memory>
#include <map>
#include <mutex>
#include "wifi_direct_work_queue.h"
namespace OHOS::SoftBus {
class WifiDirectTimer {
public:
static constexpr int TIMER_ID_INVALID = -1;
using TimerCallback = std::function<void()>;
struct TimerDescriptor {
int32_t timerId;
WifiDirectWorkQueue::Work *work;
TimerCallback callback;
};
explicit WifiDirectTimer(const std::string &name);
~WifiDirectTimer();
int32_t Register(const TimerCallback &callback, int32_t timeout);
void Unregister(int32_t timerId);
private:
std::string name_;
static int32_t AllocTimerId();
static void WorkHandler(void *data);
static inline int32_t timerId_ = 0;
static inline int32_t timerCount_ = 0;
static inline std::mutex timerIdMapLock_;
static inline std::map<int32_t, TimerDescriptor*> timerIdMap_;
static inline std::shared_ptr<WifiDirectWorkQueue> workQueue_;
};
}
#endif

View File

@ -18,6 +18,7 @@
#include "conn_log.h"
#include "lnn_p2p_info.h"
#include "lnn_feature_capability.h"
#include "lnn_distributed_net_ledger.h"
#include "securec.h"
#include "softbus_error_code.h"
#include "syspara/parameters.h"
@ -201,6 +202,16 @@ bool WifiDirectUtils::IsLocalSupportTlv()
return IsFeatureSupport(capability, BIT_WIFI_DIRECT_TLV_NEGOTIATION);
}
void WifiDirectUtils::SetLocalWifiDirectMac(const std::string &mac)
{
LnnSetLocalStrInfo(STRING_KEY_WIFIDIRECT_ADDR, mac.c_str());
}
bool WifiDirectUtils::IsDeviceOnline(const std::string &remoteNetworkId)
{
return LnnGetOnlineStateById(remoteNetworkId.c_str(), CATEGORY_NETWORK_ID);
}
static constexpr int MAC_BYTE_HEX_SIZE = 4;
std::string WifiDirectUtils::MacArrayToString(const std::vector<uint8_t> &macArray)
{
@ -217,6 +228,12 @@ std::string WifiDirectUtils::MacArrayToString(const std::vector<uint8_t> &macArr
return macString;
}
std::string WifiDirectUtils::MacArrayToString(const uint8_t *mac, int size)
{
std::vector<uint8_t> macArray(mac, mac + size);
return MacArrayToString(macArray);
}
static constexpr int BASE_HEX = 16;
std::vector<uint8_t> WifiDirectUtils::MacStringToArray(const std::string &macString)
{
@ -247,6 +264,27 @@ std::vector<uint8_t> WifiDirectUtils::GetInterfaceMacAddr(const std::string &int
return macArray;
}
std::string WifiDirectUtils::GetInterfaceIpv6Addr(const std::string &name)
{
struct ifaddrs *allAddr = nullptr;
auto ret = getifaddrs(&allAddr);
CONN_CHECK_AND_RETURN_RET_LOGE(ret == 0, "", CONN_WIFI_DIRECT, "getifaddrs failed, errno=%{public}d", errno);
for (struct ifaddrs *ifa = allAddr; ifa != nullptr; ifa = ifa->ifa_next) {
if (ifa->ifa_addr == nullptr || ifa->ifa_addr->sa_family != AF_INET6 || ifa->ifa_netmask == nullptr ||
strcmp(ifa->ifa_name, name.c_str()) != 0) {
continue;
}
char ip[IP_LEN] {};
auto *addr = reinterpret_cast<struct sockaddr_in6 *>(ifa->ifa_addr);
inet_ntop(AF_INET6, &addr->sin6_addr.s6_addr, ip, sizeof(ip));
return ip;
}
freeifaddrs(allAddr);
return "";
}
std::vector<Ipv4Info> WifiDirectUtils::GetLocalIpv4Infos()
{
std::vector<Ipv4Info> ipv4Infos;
@ -420,4 +458,38 @@ int WifiDirectUtils::BandWidthEnumToNumber(WifiDirectBandWidth bandWidth)
return BAND_WIDTH_80M_NUMBER;
}
}
void WifiDirectUtils::SerialFlowEnter()
{
std::unique_lock lock(serialParallelLock_);
CONN_LOGI(CONN_WIFI_DIRECT, "serialCount=%{public}d, parallelCount=%{public}d", serialCount_, parallelCount_);
serialParallelCv_.wait(lock, [] () { return parallelCount_ == 0; });
serialCount_++;
CONN_LOGI(CONN_WIFI_DIRECT, "serialCount=%{public}d, parallelCount=%{public}d", serialCount_, parallelCount_);
}
void WifiDirectUtils::SerialFlowExit()
{
std::unique_lock lock(serialParallelLock_);
serialCount_--;
CONN_LOGI(CONN_WIFI_DIRECT, "serialCount=%{public}d, parallelCount=%{public}d", serialCount_, parallelCount_);
serialParallelCv_.notify_all();
}
void WifiDirectUtils::ParallelFlowEnter()
{
std::unique_lock lock(serialParallelLock_);
CONN_LOGI(CONN_WIFI_DIRECT, "serialCount=%{public}d, parallelCount=%{public}d", serialCount_, parallelCount_);
serialParallelCv_.wait(lock, [] () { return serialCount_ == 0; });
parallelCount_++;
CONN_LOGI(CONN_WIFI_DIRECT, "serialCount=%{public}d, parallelCount=%{public}d", serialCount_, parallelCount_);
}
void WifiDirectUtils::ParallelFlowExit()
{
std::unique_lock lock(serialParallelLock_);
parallelCount_--;
CONN_LOGI(CONN_WIFI_DIRECT, "serialCount=%{public}d, parallelCount=%{public}d", serialCount_, parallelCount_);
serialParallelCv_.notify_all();
}
} // namespace OHOS::SoftBus

View File

@ -16,6 +16,7 @@
#define WIFI_DIRECT_UTILS_H
#include <cinttypes>
#include <condition_variable>
#include <vector>
#include <string>
@ -59,10 +60,14 @@ public:
static std::vector<uint8_t> GetRemotePtk(const std::string &remoteNetworkId);
static bool IsRemoteSupportTlv(const std::string &remoteDeviceId);
static bool IsLocalSupportTlv();
static void SetLocalWifiDirectMac(const std::string &mac);
static bool IsDeviceOnline(const std::string &remoteNetworkId);
static std::vector<uint8_t> MacStringToArray(const std::string &macString);
static std::string MacArrayToString(const std::vector<uint8_t> &macArray);
static std::string MacArrayToString(const uint8_t *mac, int size);
static std::vector<uint8_t> GetInterfaceMacAddr(const std::string &interface);
static std::string GetInterfaceIpv6Addr(const std::string &name);
static std::vector<Ipv4Info> GetLocalIpv4Infos();
@ -84,6 +89,17 @@ public:
static constexpr int BAND_WIDTH_160M_NUMBER = 160 << 20;
static WifiDirectBandWidth BandWidthNumberToEnum(int bandWidth);
static int BandWidthEnumToNumber(WifiDirectBandWidth bandWidth);
static void SerialFlowEnter();
static void SerialFlowExit();
static void ParallelFlowEnter();
static void ParallelFlowExit();
private:
static inline std::mutex serialParallelLock_;
static inline std::condition_variable serialParallelCv_;
static inline int serialCount_ = 0;
static inline int parallelCount_ = 0;
};
}

View File

@ -0,0 +1,83 @@
/*
* Copyright (c) 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "wifi_direct_work_queue.h"
#include "conn_log.h"
#include "softbus_adapter_mem.h"
#include "softbus_error_code.h"
namespace OHOS::SoftBus {
static void MessageHandler(SoftBusMessage *msg)
{
auto *work = static_cast<WifiDirectWorkQueue::Work *>(msg->obj);
work->work(work->data);
}
static void DeleteMessage(SoftBusMessage *msg)
{
SoftBusFree(msg->obj);
SoftBusFree(msg);
}
static int CompareMessage(const SoftBusMessage *msg, void *data)
{
if (msg->obj == data) {
return SOFTBUS_OK;
}
return SOFTBUS_ERR;
}
WifiDirectWorkQueue::WifiDirectWorkQueue()
{
SoftBusLooper *looper = CreateNewLooper("WDWQ_Lp");
if (looper == nullptr) {
CONN_LOGE(CONN_WIFI_DIRECT, "create looper failed");
return;
}
CONN_LOGI(CONN_WIFI_DIRECT, "create looper success");
handler_.looper = looper;
handler_.HandleMessage = MessageHandler;
}
WifiDirectWorkQueue::~WifiDirectWorkQueue()
{
if (handler_.looper != nullptr) {
CONN_LOGI(CONN_WIFI_DIRECT, "destroy looper success");
DestroyLooper(handler_.looper);
}
}
void WifiDirectWorkQueue::ScheduleDelayWork(const Work *work, uint64_t timeMs)
{
CONN_CHECK_AND_RETURN_LOGE(handler_.looper != nullptr, CONN_WIFI_DIRECT, "looper is null");
auto *msg = static_cast<SoftBusMessage *>(SoftBusCalloc(sizeof(SoftBusMessage)));
CONN_CHECK_AND_RETURN_LOGE(msg != nullptr, CONN_WIFI_DIRECT, "msg is null");
msg->handler = &handler_;
msg->obj = (void *)work;
msg->FreeMessage = DeleteMessage;
if (timeMs > 0) {
handler_.looper->PostMessageDelay(handler_.looper, msg, timeMs);
} else {
handler_.looper->PostMessage(handler_.looper, msg);
}
}
void WifiDirectWorkQueue::RemoveWork(const Work *work)
{
CONN_CHECK_AND_RETURN_LOGE(handler_.looper != nullptr, CONN_WIFI_DIRECT, "looper is null");
handler_.looper->RemoveMessageCustom(handler_.looper, &handler_, CompareMessage, (void *)work);
}
}

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef WIFI_DIRECT_WORK_QUEUE_H
#define WIFI_DIRECT_WORK_QUEUE_H
#include <functional>
#include "message_handler.h"
namespace OHOS::SoftBus {
class WifiDirectWorkQueue {
public:
using WorkFunction = std::function<void(void *data)>;
struct Work {
WorkFunction work;
void *data;
};
WifiDirectWorkQueue();
~WifiDirectWorkQueue();
void ScheduleDelayWork(const Work *work, uint64_t timeMs);
void RemoveWork(const Work *work);
private:
SoftBusHandler handler_ {};
};
}
#endif

View File

@ -34,11 +34,6 @@
#define DEFAULT_PREFIX_LEN 24
#define REQUEST_ID_INVALID (-1)
#define LINK_ID_INVALID (-1)
#define TIMER_ID_INVALID (-1)
#define DECIMAL_BASE 10
#define HEX_BASE 16
#define HML_IP_NET_PREFIX "172.30."
#define BYPASS_MAC "FF:FF:FF:FF:FF:FF"

View File

@ -356,6 +356,12 @@ enum WifiDirectErrorCode {
/* Error code retry for avoid block */
ERROR_RETRY_FOR_AVOID_BLOCK = ERROR_BASE - 6624,
/* Error code no wifi config info */
ERROR_NO_WIFI_CONFIG_INFO = ERROR_BASE - 6625,
/* Error code start action listen failed */
ERROR_START_ACTION_LISTEN_FAILED = ERROR_BASE - 6626,
/* Error code representing end position of wifi direct errors */
ERROR_WIFI_DIRECT_END = ERROR_BASE - 6999,

View File

@ -13,11 +13,7 @@
* limitations under the License.
*/
#include "wifi_direct_ip_manager.h"
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <sstream>
#include "securec.h"
#include "conn_log.h"
#include "net_conn_client.h"
#include "softbus_error_code.h"
@ -25,31 +21,32 @@
#include "utils/wifi_direct_utils.h"
namespace OHOS::SoftBus {
static constexpr int32_t U_L_BIT = 0x2;
static constexpr uint8_t INSERT_BYTE_0 = 0xff;
static constexpr uint8_t INSERT_BYTE_1 = 0xfe;
static constexpr int INSERT_POS = 3;
static constexpr int IPV6_PREFIX = 64;
static constexpr int32_t HML_IP_NET_END = 256;
static constexpr int32_t HEXADECIMAL = 16;
static constexpr int32_t U_L_BIT = 7;
static constexpr int32_t GROUP_LENGTH = 4;
static constexpr int32_t EIGHT = 8;
static constexpr int32_t TWO_DIVISION = 2;
static constexpr int32_t IPV6_PREFIX = 64;
static constexpr char HML_IP_PREFIX[] = "172.30.";
static constexpr char HML_IP_SOURCE_SUFFIX[] = ".2";
static constexpr char HML_IP_SINK_SUFFIX[] = ".1";
static constexpr char BITS_TO_BE_INSERTED[] = ":FF:FE";
std::string WifiDirectIpManager::ApplyIpv6(const std::string &mac)
{
CONN_CHECK_AND_RETURN_RET_LOGE(!mac.empty(), "", CONN_WIFI_DIRECT, "mac is null");
std::bitset<EUI_64_IDENTIFIER_LEN> eui64Bits = GetEUI64Identifier(mac);
std::string eui64String = BitsetToIPv6(eui64Bits);
std::string ipv6String = "FE80:";
for (int i = 0; i < GROUP_LENGTH; i++) {
ipv6String += ":";
ipv6String += eui64String.substr(i * GROUP_LENGTH, GROUP_LENGTH);
auto array = WifiDirectUtils::MacStringToArray(mac);
if ((array[0] & U_L_BIT) == 0) {
array[0] |= U_L_BIT;
} else {
array[0] &= ~U_L_BIT;
}
// FE80:0200:02FF:FE0D:4891
ipv6String += "%chba0";
return ipv6String;
array.insert(array.begin() + INSERT_POS, { INSERT_BYTE_0, INSERT_BYTE_1 });
char result[IP_STR_MAX_LEN] {};
auto ret = sprintf_s(result, sizeof(result), "fe80::%x%02x:%x%02x:%x%02x:%x%02x%%chba0",
array[0], array[1], array[2], array[3], array[4], array[5], array[6], array[7]);
CONN_CHECK_AND_RETURN_RET_LOGE(ret > 0, "", CONN_WIFI_DIRECT, "format failed");
return result;
}
int32_t WifiDirectIpManager::ApplyIpv4(
@ -89,32 +86,6 @@ std::string WifiDirectIpManager::ApplySubNet(
return "";
}
std::bitset<WifiDirectIpManager::EUI_64_IDENTIFIER_LEN> WifiDirectIpManager::GetEUI64Identifier(const std::string &mac)
{
std::bitset<EUI_64_IDENTIFIER_LEN> eui64Bits;
std::string macTMp(mac);
macTMp.insert(mac.length() / TWO_DIVISION, BITS_TO_BE_INSERTED);
std::stringstream ss(macTMp);
std::string segment;
while (std::getline(ss, segment, ':')) {
eui64Bits <<= EIGHT;
eui64Bits |= std::bitset<EUI_64_IDENTIFIER_LEN>(std::stoi(segment, nullptr, HEXADECIMAL));
}
eui64Bits.flip(EUI_64_IDENTIFIER_LEN - U_L_BIT);
return eui64Bits;
}
std::string WifiDirectIpManager::BitsetToIPv6(const std::bitset<EUI_64_IDENTIFIER_LEN> &eui64Bits)
{
std::string eui64String;
std::string binary = eui64Bits.to_string();
std::stringstream ss;
ss << std::hex << std::setfill('0') << std::setw(HEXADECIMAL) << std::uppercase << eui64Bits.to_ulong();
eui64String = ss.str();
return eui64String;
}
int32_t WifiDirectIpManager::ConfigIpv6(const std::string &interface, const std::string &ip)
{
auto ret = OHOS::NetManagerStandard::NetConnClient::GetInstance().AddInterfaceAddress(interface, ip, IPV6_PREFIX);

View File

@ -59,8 +59,6 @@ public:
static constexpr int32_t LOCAL_NETWORK_ID = 99;
static std::string ApplySubNet(const std::vector<Ipv4Info> &localArray, const std::vector<Ipv4Info> &remoteArray);
static std::bitset<EUI_64_IDENTIFIER_LEN> GetEUI64Identifier(const std::string &mac);
static std::string BitsetToIPv6(const std::bitset<EUI_64_IDENTIFIER_LEN> &eui64Bits);
static int32_t GetNetworkGateWay(const std::string &ipString, std::string &gateWay);
static int32_t GetNetworkDestination(const std::string &ipString, std::string &destination);

View File

@ -156,6 +156,15 @@ static int32_t PrejudgeAvailability(const char *remoteNetworkId, enum WifiDirect
return SOFTBUS_OK;
}
static void RefreshRelationShip(const char *remoteUuid, const char *remoteMac)
{
CONN_LOGI(CONN_WIFI_DIRECT, "remoteUuid=%{public}s, remoteMac=%{public}s",
OHOS::SoftBus::WifiDirectAnonymizeDeviceId(remoteUuid).c_str(),
OHOS::SoftBus::WifiDirectAnonymizeMac(remoteMac).c_str());
OHOS::SoftBus::LinkManager::GetInstance().RefreshRelationShip(remoteUuid, remoteMac);
OHOS::SoftBus::LinkManager::GetInstance().Dump();
}
static bool IsDeviceOnline(const char *remoteMac)
{
bool isOnline = false;
@ -206,6 +215,13 @@ static int32_t GetLocalIpByRemoteIpOnce(const char *remoteIp, char *localIp, int
}
return true;
}
if (innerLink.GetRemoteIpv6() == remoteIp) {
found = true;
if (strcpy_s(localIp, localIpSize, innerLink.GetLocalIpv6().c_str()) != EOK) {
found = false;
}
return true;
}
return false;
});
@ -247,6 +263,13 @@ static int32_t GetRemoteUuidByIp(const char *remoteIp, char *uuid, int32_t uuidS
}
return true;
}
if (innerLink.GetRemoteIpv6() == remoteIp) {
found = true;
if (strcpy_s(uuid, uuidSize, innerLink.GetRemoteDeviceId().c_str()) != EOK) {
found = false;
}
return true;
}
return false;
});
@ -300,12 +323,12 @@ static void NotifyRoleChange(enum WifiDirectRole oldRole, enum WifiDirectRole ne
}
static void NotifyConnectedForSink(
const char *remoteMac, const char *remoteIp, const char *remoteUuid, enum WifiDirectLinkType type)
const char *remoteMac, const char *remoteIp, const char *remoteUuid, enum WifiDirectLinkType type, int channelId)
{
std::lock_guard lock(g_listenerLock);
for (auto listener : g_listeners) {
if (listener.onConnectedForSink != nullptr) {
listener.onConnectedForSink(remoteMac, remoteIp, remoteUuid, type);
listener.onConnectedForSink(remoteMac, remoteIp, remoteUuid, type, channelId);
}
}
}
@ -373,6 +396,8 @@ static struct WifiDirectManager g_manager = {
.prejudgeAvailability = PrejudgeAvailability,
.isNegotiateChannelNeeded = IsNegotiateChannelNeeded,
.refreshRelationShip = RefreshRelationShip,
.isDeviceOnline = IsDeviceOnline,
.getLocalIpByUuid = GetLocalIpByUuid,
.getLocalIpByRemoteIp = GetLocalIpByRemoteIp,

View File

@ -27,9 +27,9 @@ struct WifiDirectStatusListener {
void (*onDeviceOnLine)(const char *remoteMac, const char *remoteIp, const char *remoteUuid, bool isSource);
void (*onDeviceOffLine)(const char *remoteMac, const char *remoteIp, const char *remoteUuid, const char *localIp);
void (*onConnectedForSink)(const char *remoteMac, const char *remoteIp, const char *remoteUuid,
enum WifiDirectLinkType type);
enum WifiDirectLinkType type, int channelId);
void (*onDisconnectedForSink)(const char *remoteMac, const char *remoteIp, const char *remoteUuid,
enum WifiDirectLinkType type);
enum WifiDirectLinkType type);
};
struct WifiDirectManager {
@ -44,6 +44,8 @@ struct WifiDirectManager {
int32_t (*prejudgeAvailability)(const char *remoteNetworkId, enum WifiDirectLinkType linkType);
bool (*isNegotiateChannelNeeded)(const char *remoteNetworkId, enum WifiDirectLinkType linkType);
void (*refreshRelationShip)(const char *remoteUuid, const char *remoteMac);
bool (*isDeviceOnline)(const char *remoteMac);
int32_t (*getLocalIpByUuid)(const char *uuid, char *localIp, int32_t localIpSize);
int32_t (*getLocalIpByRemoteIp)(const char *remoteIp, char *localIp, int32_t localIpSize);
@ -59,10 +61,10 @@ struct WifiDirectManager {
void (*notifyOnline)(const char *remoteMac, const char *remoteIp, const char *remoteUuid, bool isSource);
void (*notifyOffline)(const char *remoteMac, const char *remoteIp, const char *remoteUuid, const char *localIp);
void (*notifyRoleChange)(enum WifiDirectRole oldRole, enum WifiDirectRole newRole);
void (*notifyConnectedForSink)(
const char *remoteMac, const char *remoteIp, const char *remoteUuid, enum WifiDirectLinkType type);
void (*notifyDisconnectedForSink)(
const char *remoteMac, const char *remoteIp, const char *remoteUuid, enum WifiDirectLinkType type);
void (*notifyConnectedForSink)(const char *remoteMac, const char *remoteIp, const char *remoteUuid,
enum WifiDirectLinkType type, int channelId);
void (*notifyDisconnectedForSink)(const char *remoteMac, const char *remoteIp, const char *remoteUuid,
enum WifiDirectLinkType type);
};
/* singleton */

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 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

View File

@ -32,8 +32,7 @@ int WifiDirectRoleOption::GetExpectedRole(
expectedRole = WIFI_DIRECT_API_ROLE_GC | WIFI_DIRECT_API_ROLE_GO;
}
isStrict = false;
} else if (type == WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_HML || type == WIFI_DIRECT_CONNECT_TYPE_BLE_TRIGGER_HML ||
type == WIFI_DIRECT_CONNECT_TYPE_AUTH_TRIGGER_HML) {
} else if (type == WIFI_DIRECT_CONNECT_TYPE_AUTH_NEGO_HML) {
enum WifiDirectRole role = GetExpectedP2pRole(networkId);
if (role == WIFI_DIRECT_ROLE_GC) {
expectedRole = WIFI_DIRECT_API_ROLE_GC | WIFI_DIRECT_API_ROLE_HML;
@ -43,6 +42,10 @@ int WifiDirectRoleOption::GetExpectedRole(
expectedRole = WIFI_DIRECT_API_ROLE_GC | WIFI_DIRECT_API_ROLE_GO | WIFI_DIRECT_API_ROLE_HML;
}
isStrict = false;
} else if (type == WIFI_DIRECT_CONNECT_TYPE_BLE_TRIGGER_HML ||
type == WIFI_DIRECT_CONNECT_TYPE_AUTH_TRIGGER_HML || type == WIFI_DIRECT_CONNECT_TYPE_ACTION_TRIGGER_HML) {
expectedRole = WIFI_DIRECT_API_ROLE_HML;
isStrict = true;
} else {
CONN_LOGW(CONN_WIFI_DIRECT, "type invalid. type=%{public}d", type);
return SOFTBUS_INVALID_PARAM;

View File

@ -90,7 +90,8 @@ public:
std::lock_guard lock(executorLock_);
auto it = executors_.find(remoteDeviceId);
if (it == executors_.end()) {
CONN_LOGI(CONN_WIFI_DIRECT, "executor not exist");
CONN_LOGE(CONN_WIFI_DIRECT, "executor not exist, remoteDeviceId=%{public}s",
WifiDirectAnonymizeDeviceId(remoteDeviceId).c_str());
return;
}

View File

@ -92,6 +92,8 @@ struct WifiDirectLink {
int32_t remotePort;
enum WifiDirectLinkType linkType;
enum WifiDirectBandWidth bandWidth;
bool isReuse;
int channelId;
};
enum WifiDirectNegoChannelType {

View File

@ -35,12 +35,15 @@ ohos_unittest("WifiDirectIpManagerTest") {
"$dsoftbus_root_path/core/bus_center/interface",
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/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/discovery/manager/include",
"$dsoftbus_root_path/core/discovery/interface",
"$dsoftbus_root_path/core/transmission/trans_channel/proxy/include",
"$dsoftbus_root_path/core/common/dfx/interface/include",
"$dsoftbus_root_path/core/common/include",
"$dsoftbus_root_path/tests/core/connection/wifi_direct_cpp",
"$dsoftbus_root_path/core/authentication/interface",
"$dsoftbus_root_path/core/connection/interface",
"$dsoftbus_root_path/tests/core/connection/wifi_direct_cpp",
]
sources = [
"$dsoftbus_root_path/tests/core/connection/wifi_direct_cpp/net_conn_client.cpp",
@ -49,15 +52,18 @@ ohos_unittest("WifiDirectIpManagerTest") {
"$wifi_direct_cpp_path/utils/wifi_direct_utils.cpp",
"$wifi_direct_cpp_path/wifi_direct_ip_manager.cpp",
"wifi_direct_ip_manager_test.cpp",
"wifi_direct_mock.cpp",
]
deps = [
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
external_deps = [
"bounds_checking_function:libsec_shared",
"c_utils:utils",
"hilog:libhilog",
"init:libbegetutil",
"wifi:wifi_sdk",
]
}

View File

@ -33,20 +33,6 @@ public:
void TearDown() override { }
};
/*
* @tc.name: GetEUI64Identifier
* @tc.desc: check GetEUI64Identifier methods
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(WifiDirectIpManagerTest, GetEUI64Identifier, TestSize.Level1)
{
std::string mac("00:00:02:0d:48:91");
std::bitset<WifiDirectIpManager::EUI_64_IDENTIFIER_LEN> ret =
WifiDirectIpManager::GetInstance().GetEUI64Identifier(mac);
EXPECT_EQ(ret.to_string(), "0000001000000000000000101111111111111110000011010100100010010001");
}
/*
* @tc.name: ApplyIpv6
* @tc.desc: check ApplyIpv6 methods,when mac is null
@ -244,4 +230,4 @@ HWTEST_F(WifiDirectIpManagerTest, AddAndDeleteInterfaceAddress, TestSize.Level1)
EXPECT_EQ(ret, SOFTBUS_ERR);
}
} // namespace OHOS::SoftBus
} // namespace OHOS::SoftBus

View File

@ -82,6 +82,11 @@ int32_t LnnGetRemoteBoolInfo(const char *networkId, InfoKey key, bool *info)
return OHOS::SoftBus::WifiDirectInterfaceMock::GetMock()->LnnGetRemoteBoolInfo(networkId, key, info);
}
bool LnnGetOnlineStateById(const char *id, IdCategory type)
{
return OHOS::SoftBus::WifiDirectInterfaceMock::GetMock()->LnnGetOnlineStateById(id, type);
}
int32_t AuthStartListeningForWifiDirect(AuthLinkType type, const char *ip,
int32_t port, ListenerModule *moduleId)
{
@ -381,4 +386,4 @@ WifiErrorCode WifiDirectInterfaceMock::DestroyGroupTimeOutAction()
return WIFI_SUCCESS;
}
}
// namespace OHOS::SoftBus
// namespace OHOS::SoftBus

View File

@ -50,6 +50,7 @@ public:
virtual int32_t LnnGetRemoteStrInfo(const char *netWorkId, InfoKey key, char *info, uint32_t len) = 0;
virtual int32_t LnnGetNetworkIdByUuid(const char *uuid, char *buf, uint32_t len) = 0;
virtual int32_t LnnGetRemoteBoolInfo(const char *networkId, InfoKey key, bool *info) = 0;
virtual bool LnnGetOnlineStateById(const char *id, IdCategory type) = 0;
virtual void AuthCloseConn(AuthHandle authHandle) = 0;
virtual void AuthStopListeningForWifiDirect(AuthLinkType type, ListenerModule moduleId) = 0;
virtual int32_t AuthStartListeningForWifiDirect(AuthLinkType type, const char *ip,
@ -111,6 +112,7 @@ public:
MOCK_METHOD(int32_t, LnnGetRemoteStrInfo, (const char*, InfoKey, char*, uint32_t), (override));
MOCK_METHOD(int32_t, LnnGetNetworkIdByUuid, (const char *, char *, uint32_t), (override));
MOCK_METHOD(int32_t, LnnGetRemoteBoolInfo, (const char *, InfoKey, bool*), (override));
MOCK_METHOD(bool, LnnGetOnlineStateById, (const char *, IdCategory), (override));
MOCK_METHOD(void, AuthCloseConn, (AuthHandle), (override));
MOCK_METHOD(void, AuthStopListeningForWifiDirect, (AuthLinkType, ListenerModule), (override));
MOCK_METHOD(int32_t, AuthStartListeningForWifiDirect,
@ -127,7 +129,7 @@ public:
MOCK_METHOD(int32_t, LnnSyncP2pInfo, (), (override));
MOCK_METHOD(uint64_t, LnnGetFeatureCapabilty, (), (override));
MOCK_METHOD(bool, IsFeatureSupport, (uint64_t, FeatureCapability), (override));
MOCK_METHOD(WifiErrorCode, GetLinkedInfo, (WifiLinkedInfo *), (override));
MOCK_METHOD(WifiErrorCode, Hid2dGetRecommendChannel,
(const RecommendChannelRequest *, RecommendChannelResponse *), (override));
@ -175,4 +177,4 @@ private:
} // namespace OHOS::SoftBus
#endif // WIFI_DIRECT_MOCK_H
#endif // WIFI_DIRECT_MOCK_H