From ba4be5eb47decde1585812cb26c30b0cc92166f8 Mon Sep 17 00:00:00 2001 From: shiyifan Date: Thu, 29 Aug 2024 14:55:02 +0800 Subject: [PATCH 1/2] Fixing Logic Problems Signed-off-by: shiyifan --- .../wifi_direct_cpp/adapter/p2p_adapter.cpp | 11 +++++----- .../wifi_direct_cpp/adapter/p2p_adapter.h | 2 +- .../processor/p2p_v1_processor.cpp | 22 +++++++++---------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/core/connection/wifi_direct_cpp/adapter/p2p_adapter.cpp b/core/connection/wifi_direct_cpp/adapter/p2p_adapter.cpp index 9e0f6942f..34f19d07f 100644 --- a/core/connection/wifi_direct_cpp/adapter/p2p_adapter.cpp +++ b/core/connection/wifi_direct_cpp/adapter/p2p_adapter.cpp @@ -38,7 +38,7 @@ 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::GetFrequency5GListIntArray(std::vector &frequencyList) +int32_t P2pAdapter::GetChannel5GListIntArray(std::vector &channels) { int array[CHANNEL_ARRAY_NUM_MAX] {}; auto ret = Hid2dGetChannelListFor5G(array, CHANNEL_ARRAY_NUM_MAX); @@ -47,7 +47,7 @@ int32_t P2pAdapter::GetFrequency5GListIntArray(std::vector &frequencyList) int count = 0; while (array[count]) { - frequencyList.push_back(array[count]); + channels.push_back(array[count]); count++; } @@ -198,12 +198,13 @@ int32_t P2pAdapter::GetStationFrequencyWithFilter() int32_t frequency = P2pAdapter::GetStationFrequency(); CONN_CHECK_AND_RETURN_RET_LOGW(frequency > 0, FREQUENCY_INVALID, CONN_WIFI_DIRECT, "invalid frequency"); if (WifiDirectUtils::Is5GBand(frequency)) { - std::vector frequencyArray; - auto ret = P2pAdapter::GetFrequency5GListIntArray(frequencyArray); + std::vector channelArray; + auto ret = P2pAdapter::GetChannel5GListIntArray(channelArray); if (ret != SOFTBUS_OK) { return ret; } - if (WifiDirectUtils::IsInChannelList(frequency, frequencyArray)) { + int32_t channel = WifiDirectUtils::FrequencyToChannel(frequency); + if (WifiDirectUtils::IsInChannelList(channel, channelArray)) { return frequency; } return FREQUENCY_INVALID; diff --git a/core/connection/wifi_direct_cpp/adapter/p2p_adapter.h b/core/connection/wifi_direct_cpp/adapter/p2p_adapter.h index dfa103cd3..0ee177c94 100644 --- a/core/connection/wifi_direct_cpp/adapter/p2p_adapter.h +++ b/core/connection/wifi_direct_cpp/adapter/p2p_adapter.h @@ -60,7 +60,7 @@ public: std::vector clientDevices; }; - static int32_t GetFrequency5GListIntArray(std::vector &frequencyList); + static int32_t GetChannel5GListIntArray(std::vector &frequencyList); static bool IsWifiP2pEnabled(); static std::string GetInterfaceCoexistCap(); static int32_t GetStationFrequency(); diff --git a/core/connection/wifi_direct_cpp/processor/p2p_v1_processor.cpp b/core/connection/wifi_direct_cpp/processor/p2p_v1_processor.cpp index 6d4692966..ec0c3d9cc 100644 --- a/core/connection/wifi_direct_cpp/processor/p2p_v1_processor.cpp +++ b/core/connection/wifi_direct_cpp/processor/p2p_v1_processor.cpp @@ -943,11 +943,11 @@ int P2pV1Processor::ProcessConnectRequestAsGc(std::shared_ptr int P2pV1Processor::SendConnectResponseAsNone(const NegotiateChannel &channel, const std::string &remoteMac) { - std::vector frequencyList; - auto ret = P2pAdapter::GetFrequency5GListIntArray(frequencyList); + std::vector channels; + auto ret = P2pAdapter::GetChannel5GListIntArray(channels); CONN_CHECK_AND_RETURN_RET_LOGW( ret == SOFTBUS_OK, ret, CONN_WIFI_DIRECT, "get 5g channels failed, error=%{public}d", ret); - auto channelString = WifiDirectUtils::ChannelListToString(frequencyList); + auto channelString = WifiDirectUtils::ChannelListToString(channels); std::string selfWifiConfig; ret = P2pAdapter::GetSelfWifiConfigInfo(selfWifiConfig); @@ -1287,11 +1287,11 @@ int P2pV1Processor::ProcessAuthHandShakeRequest(std::shared_ptr frequencyList; - int32_t ret = P2pAdapter::GetFrequency5GListIntArray(frequencyList); + std::vector channels; + int32_t ret = P2pAdapter::GetFrequency5GListIntArray(channels); CONN_CHECK_AND_RETURN_RET_LOGW( - ret == SOFTBUS_OK, ret, CONN_WIFI_DIRECT, "get 5g frequencyList failed, error=%{public}d", ret); - auto channelString = WifiDirectUtils::ChannelListToString(frequencyList); + ret == SOFTBUS_OK, ret, CONN_WIFI_DIRECT, "get 5g channels failed, error=%{public}d", ret); + auto channelString = WifiDirectUtils::ChannelListToString(channels); std::string selfWifiConfig; ret = P2pAdapter::GetSelfWifiConfigInfo(selfWifiConfig); @@ -1697,12 +1697,12 @@ int P2pV1Processor::ChooseFrequency(int gcFreq, const std::vector &gcChanne } } - std::vector goFrequencyList; - int32_t ret = P2pAdapter::GetFrequency5GListIntArray(goFrequencyList); + std::vector goChannels; + int32_t ret = P2pAdapter::GetFrequency5GListIntArray(goChannels); CONN_CHECK_AND_RETURN_RET_LOGW( - ret == SOFTBUS_OK, ret, CONN_WIFI_DIRECT, "get local goFrequencyList list failed, error=%{public}d", ret); + ret == SOFTBUS_OK, ret, CONN_WIFI_DIRECT, "get local Channels list failed, error=%{public}d", ret); - for (auto goChannel : goFrequencyList) { + for (auto goChannel : goChannels) { if (std::find(gcChannels.begin(), gcChannels.end(), goChannel) != gcChannels.end()) { return WifiDirectUtils::ChannelToFrequency(goChannel); } From 5b767e4f3d30b2a0151181c8b92aa7eee2a9c7e8 Mon Sep 17 00:00:00 2001 From: shiyifan Date: Thu, 29 Aug 2024 07:28:10 +0000 Subject: [PATCH 2/2] update core/connection/wifi_direct_cpp/processor/p2p_v1_processor.cpp. Signed-off-by: shiyifan --- .../connection/wifi_direct_cpp/processor/p2p_v1_processor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/connection/wifi_direct_cpp/processor/p2p_v1_processor.cpp b/core/connection/wifi_direct_cpp/processor/p2p_v1_processor.cpp index ec0c3d9cc..0ef66f965 100644 --- a/core/connection/wifi_direct_cpp/processor/p2p_v1_processor.cpp +++ b/core/connection/wifi_direct_cpp/processor/p2p_v1_processor.cpp @@ -1288,7 +1288,7 @@ int P2pV1Processor::ProcessAuthHandShakeRequest(std::shared_ptr channels; - int32_t ret = P2pAdapter::GetFrequency5GListIntArray(channels); + int32_t ret = P2pAdapter::GetChannel5GListIntArray(channels); CONN_CHECK_AND_RETURN_RET_LOGW( ret == SOFTBUS_OK, ret, CONN_WIFI_DIRECT, "get 5g channels failed, error=%{public}d", ret); auto channelString = WifiDirectUtils::ChannelListToString(channels); @@ -1698,7 +1698,7 @@ int P2pV1Processor::ChooseFrequency(int gcFreq, const std::vector &gcChanne } std::vector goChannels; - int32_t ret = P2pAdapter::GetFrequency5GListIntArray(goChannels); + int32_t ret = P2pAdapter::GetChannel5GListIntArray(goChannels); CONN_CHECK_AND_RETURN_RET_LOGW( ret == SOFTBUS_OK, ret, CONN_WIFI_DIRECT, "get local Channels list failed, error=%{public}d", ret);