mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Add Intel PIE based API to set Hotspot client scan channel
PiperOrigin-RevId: 586019580
This commit is contained in:
@@ -16,8 +16,6 @@
|
||||
#include <exception>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/platform/feature_flags.h"
|
||||
@@ -261,15 +259,16 @@ bool WifiHotspotMedium::StartWifiHotspot(
|
||||
platform::config_package_nearby::nearby_platform_feature::
|
||||
kEnableIntelPieSdk)) {
|
||||
WifiIntel& intel_wifi{WifiIntel::GetInstance()};
|
||||
intel_wifi.Start();
|
||||
int GO_channel = static_cast<int>(intel_wifi.GetGOChannel());
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "Intel PIE enabled, Hotspot is running on channel: "
|
||||
<< GO_channel;
|
||||
intel_wifi.Stop();
|
||||
hotspot_credentials_->SetFrequency(
|
||||
WifiUtils::ConvertChannelToFrequencyMhz(GO_channel,
|
||||
WifiBandType::kUnknown));
|
||||
if (intel_wifi.Start()) {
|
||||
int GO_channel = static_cast<int>(intel_wifi.GetGOChannel());
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "Intel PIE enabled, Hotspot is running on channel: "
|
||||
<< GO_channel;
|
||||
intel_wifi.Stop();
|
||||
hotspot_credentials_->SetFrequency(
|
||||
WifiUtils::ConvertChannelToFrequencyMhz(GO_channel,
|
||||
WifiBandType::kUnknown));
|
||||
}
|
||||
} else {
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "Intel PIE disabled, Can't extract Hotspot channel info!";
|
||||
@@ -441,9 +440,17 @@ bool WifiHotspotMedium::ConnectWifiHotspot(
|
||||
|
||||
// SoftAP is an abbreviation for "software enabled access point".
|
||||
WiFiAvailableNetwork nearby_softap{nullptr};
|
||||
|
||||
auto channel = WifiUtils::ConvertFrequencyMhzToChannel(
|
||||
hotspot_credentials_->GetFrequency());
|
||||
WifiIntel& intel_wifi{WifiIntel::GetInstance()};
|
||||
bool intel_wifi_started = intel_wifi.Start();
|
||||
if (intel_wifi_started) {
|
||||
intel_wifi.SetScanFilter(channel);
|
||||
}
|
||||
|
||||
NEARBY_LOGS(INFO) << "Scanning for Nearby Hotspot SSID: "
|
||||
<< hotspot_credentials_->GetSSID();
|
||||
|
||||
// First time scan may not find our target hotspot, try 2 more times can
|
||||
// almost guarantee to find the Hotspot
|
||||
wifi_adapter_.ScanAsync().get();
|
||||
@@ -453,8 +460,8 @@ bool WifiHotspotMedium::ConnectWifiHotspot(
|
||||
platform::config_package_nearby::nearby_platform_feature::
|
||||
kWifiHotspotScanMaxRetries);
|
||||
|
||||
NEARBY_LOGS(INFO) << "maximum scan retries=" << wifi_hotspot_max_scans;
|
||||
for (int i = 0; i < wifi_hotspot_max_scans; i++) {
|
||||
int i;
|
||||
for (i = 0; i < wifi_hotspot_max_scans; i++) {
|
||||
for (const auto& network :
|
||||
wifi_adapter_.NetworkReport().AvailableNetworks()) {
|
||||
if (!wifi_connected_network_ && !ssid.empty() &&
|
||||
@@ -473,12 +480,19 @@ bool WifiHotspotMedium::ConnectWifiHotspot(
|
||||
NEARBY_LOGS(INFO) << "Scan ... ";
|
||||
wifi_adapter_.ScanAsync().get();
|
||||
}
|
||||
NEARBY_LOGS(INFO) << "Finish scanning "
|
||||
<< (nearby_softap ? "successfully" : "failed") << " with "
|
||||
<< i+1 << " times trying.";
|
||||
|
||||
if (intel_wifi_started) {
|
||||
intel_wifi.ResetScanFilter();
|
||||
intel_wifi.Stop();
|
||||
}
|
||||
|
||||
if (!nearby_softap) {
|
||||
NEARBY_LOGS(INFO) << "Hotspot is not found";
|
||||
return false;
|
||||
}
|
||||
|
||||
PasswordCredential creds;
|
||||
creds.Password(winrt::to_hstring(hotspot_credentials_->GetPassword()));
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
@@ -97,9 +98,13 @@ typedef MUROC_RET(APIENTRY* WIFIGETADAPTERLIST)( // NOLINT
|
||||
typedef MUROC_RET(APIENTRY* REGISTERINTELCB)(
|
||||
MurocDefs::PINTEL_CALLBACK pIntelCallback);
|
||||
typedef MUROC_RET(APIENTRY* GETRADIOSTATE)(HADAPTER hAdapter, bool* bEnabled);
|
||||
typedef MUROC_RET(APIENTRY* WIFIPANQUERYPREFFEDCHANNELSETTING)(
|
||||
typedef MUROC_RET(APIENTRY* WIFIPANQUERYPREFERREDCHANNELSETTING)(
|
||||
HADAPTER hAdapter, PINTEL_WIFI_HEADER pHeader,
|
||||
void* pOutQueryPreferredChannel);
|
||||
typedef MUROC_RET(APIENTRY* WIFILEGACYGOSETSCANFILTER)(
|
||||
HADAPTER hAdapter, PINTEL_WIFI_HEADER pHeader, void* pInputData);
|
||||
typedef MUROC_RET(APIENTRY* WIFIPANRESETLEGACYGOSCANFILTER)(
|
||||
HADAPTER hAdapter, PINTEL_WIFI_HEADER pHeader);
|
||||
typedef MUROC_RET(APIENTRY* DEREGISTERINTELCB)(
|
||||
MurocDefs::INTEL_EVENT_CALLBACK fnCallbac);
|
||||
typedef MUROC_RET(APIENTRY* FREELISTMEMORY)(void* pList);
|
||||
@@ -137,7 +142,7 @@ WifiIntel& WifiIntel::GetInstance() {
|
||||
return *instance;
|
||||
}
|
||||
|
||||
void WifiIntel::Start() {
|
||||
bool WifiIntel::Start() {
|
||||
NEARBY_LOGS(INFO) << "WifiIntel::Start()";
|
||||
#ifndef NO_INTEL_PIE
|
||||
muroc_api_dll_handle_ = PIEDllLoader();
|
||||
@@ -156,6 +161,7 @@ void WifiIntel::Start() {
|
||||
#else
|
||||
NEARBY_LOGS(INFO) << "NO_INTEL_PIE found, skip";
|
||||
#endif
|
||||
return intel_wifi_valid_;
|
||||
}
|
||||
|
||||
void WifiIntel::Stop() {
|
||||
@@ -175,7 +181,7 @@ void WifiIntel::Stop() {
|
||||
|
||||
int8_t WifiIntel::GetGOChannel() {
|
||||
#ifndef NO_INTEL_PIE
|
||||
WIFIPANQUERYPREFFEDCHANNELSETTING WifiPanQueryPreferredChannelSettingFunc =
|
||||
WIFIPANQUERYPREFERREDCHANNELSETTING WifiPanQueryPreferredChannelSettingFunc =
|
||||
nullptr;
|
||||
int8_t channel = -1;
|
||||
DWORD dwError = ERROR_SUCCESS; // NOLINT
|
||||
@@ -186,7 +192,7 @@ int8_t WifiIntel::GetGOChannel() {
|
||||
if (!intel_wifi_valid_) return channel;
|
||||
|
||||
WifiPanQueryPreferredChannelSettingFunc =
|
||||
(WIFIPANQUERYPREFFEDCHANNELSETTING)GetProcAddress( // NOLINT
|
||||
(WIFIPANQUERYPREFERREDCHANNELSETTING)GetProcAddress( // NOLINT
|
||||
muroc_api_dll_handle_,
|
||||
"WifiPanQueryPreferredChannelSetting");
|
||||
|
||||
@@ -226,6 +232,101 @@ int8_t WifiIntel::GetGOChannel() {
|
||||
#endif
|
||||
}
|
||||
|
||||
bool WifiIntel::SetScanFilter(int channel) {
|
||||
#ifndef NO_INTEL_PIE
|
||||
WIFILEGACYGOSETSCANFILTER WifiLegacyGoSetScanFilterFunc =
|
||||
nullptr;
|
||||
DWORD dwError = ERROR_SUCCESS; // NOLINT
|
||||
MUROC_RET murocApiRetVal = IWLAN_E_FAILURE; // NOLINT
|
||||
INTEL_WIFI_HEADER intelWifiHeader;
|
||||
MurocDefs::WIFI_LEGACY_GO_SCAN_FILTER scanFilter;
|
||||
|
||||
if (channel <= 0) return false;
|
||||
if (!intel_wifi_valid_) return false;
|
||||
|
||||
NEARBY_LOGS(INFO) << "Set scan channel:" << channel;
|
||||
WifiLegacyGoSetScanFilterFunc =
|
||||
(WIFILEGACYGOSETSCANFILTER)GetProcAddress( // NOLINT
|
||||
muroc_api_dll_handle_,
|
||||
"WifiLegacyGoSetScanFilter");
|
||||
|
||||
if (WifiLegacyGoSetScanFilterFunc == nullptr) {
|
||||
dwError = GetLastError(); // NOLINT
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "GetProcAddress WifiLegacyGoSetScanFilterFunc error: "
|
||||
<< dwError;
|
||||
return false;
|
||||
}
|
||||
NEARBY_LOGS(VERBOSE)
|
||||
<< "Load WifiLegacyGoSetScanFilterFunc API completed successfully";
|
||||
|
||||
intelWifiHeader.dwSize =
|
||||
sizeof(MurocDefs::WIFI_LEGACY_GO_SCAN_FILTER);
|
||||
memset(&scanFilter, 0, sizeof(scanFilter));
|
||||
scanFilter.channel = (UINT8)channel;
|
||||
murocApiRetVal = WifiLegacyGoSetScanFilterFunc(
|
||||
wifi_adapter_handle_, &intelWifiHeader, (void*)&scanFilter);
|
||||
|
||||
if (murocApiRetVal == IWLAN_E_SUCCESS) { // NOLINT
|
||||
NEARBY_LOGS(INFO) << "Calling WifiLegacyGoSetScanFilter API "
|
||||
"succeeded, set scan channel to "
|
||||
<< channel;
|
||||
return true;
|
||||
}
|
||||
NEARBY_LOGS(INFO) << "Calling WifiLegacyGoSetScanFilter API "
|
||||
"failed with error: "
|
||||
<< murocApiRetVal;
|
||||
|
||||
return false;
|
||||
#else
|
||||
NEARBY_LOGS(INFO) << "NO_INTEL_PIE found, return -1";
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool WifiIntel::ResetScanFilter() {
|
||||
#ifndef NO_INTEL_PIE
|
||||
WIFIPANRESETLEGACYGOSCANFILTER WifiPanReSetLegacyGoScanFilterFunc =
|
||||
nullptr;
|
||||
DWORD dwError = ERROR_SUCCESS; // NOLINT
|
||||
MUROC_RET murocApiRetVal = IWLAN_E_FAILURE; // NOLINT
|
||||
INTEL_WIFI_HEADER intelWifiHeader;
|
||||
|
||||
if (!intel_wifi_valid_) return false;
|
||||
|
||||
WifiPanReSetLegacyGoScanFilterFunc =
|
||||
(WIFIPANRESETLEGACYGOSCANFILTER)GetProcAddress( // NOLINT
|
||||
muroc_api_dll_handle_,
|
||||
"WifiPanReSetLegacyGoScanFilter");
|
||||
|
||||
if (WifiPanReSetLegacyGoScanFilterFunc == nullptr) {
|
||||
dwError = GetLastError(); // NOLINT
|
||||
NEARBY_LOGS(INFO)
|
||||
<< "GetProcAddress WifiPanReSetLegacyGoScanFilterFunc error: "
|
||||
<< dwError;
|
||||
return false;
|
||||
}
|
||||
NEARBY_LOGS(VERBOSE)
|
||||
<< "Load WifiPanReSetLegacyGoScanFilterFunc API completed successfully";
|
||||
intelWifiHeader.dwSize = 0;
|
||||
murocApiRetVal = WifiPanReSetLegacyGoScanFilterFunc(
|
||||
wifi_adapter_handle_, &intelWifiHeader);
|
||||
|
||||
if (murocApiRetVal == IWLAN_E_SUCCESS) { // NOLINT
|
||||
NEARBY_LOGS(INFO) << "Calling WifiPanReSetLegacyGoScanFilter API succeeded";
|
||||
return true;
|
||||
}
|
||||
NEARBY_LOGS(INFO) << "Calling WifiPanQueryPreferredChannelSetting API "
|
||||
"failed with error: "
|
||||
<< murocApiRetVal;
|
||||
|
||||
return false;
|
||||
#else
|
||||
NEARBY_LOGS(INFO) << "NO_INTEL_PIE found, return -1";
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef NO_INTEL_PIE
|
||||
wchar_t* GetEntireRegistryDeviceList() {
|
||||
CONFIGRET configRet = CR_SUCCESS;
|
||||
|
||||
@@ -43,9 +43,12 @@ class WifiIntel {
|
||||
|
||||
static WifiIntel& GetInstance();
|
||||
bool IsValid() const { return intel_wifi_valid_; }
|
||||
void Start();
|
||||
bool Start();
|
||||
void Stop();
|
||||
int8_t GetGOChannel();
|
||||
bool SetScanFilter(int channel);
|
||||
bool ResetScanFilter();
|
||||
|
||||
|
||||
private:
|
||||
// This is a singleton object, for which destructor will never be called.
|
||||
|
||||
Reference in New Issue
Block a user