From db6c1b33adddb2fd5201fc551e14740321615c1e Mon Sep 17 00:00:00 2001 From: Patryk Lipinski Date: Thu, 14 Mar 2024 10:08:13 +0100 Subject: [PATCH] [nrf noup] Wifi directed scan with single scan This commit implements directed scaning and single ssid scaning while commisioning. Signed-off-by: Patryk Lipinski --- src/platform/nrfconnect/wifi/WiFiManager.cpp | 24 +++++++++++++++----- src/platform/nrfconnect/wifi/WiFiManager.h | 2 ++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/platform/nrfconnect/wifi/WiFiManager.cpp b/src/platform/nrfconnect/wifi/WiFiManager.cpp index ce17308bf4..c1197215ee 100644 --- a/src/platform/nrfconnect/wifi/WiFiManager.cpp +++ b/src/platform/nrfconnect/wifi/WiFiManager.cpp @@ -188,14 +188,26 @@ CHIP_ERROR WiFiManager::Scan(const ByteSpan & ssid, ScanResultCallback resultCal mWiFiState = WIFI_STATE_SCANNING; mSsidFound = false; - if (0 != net_mgmt(NET_REQUEST_WIFI_SCAN, mNetIf, NULL, 0)) + if (!ssid.empty()) { - ChipLogError(DeviceLayer, "Scan request failed"); - return CHIP_ERROR_INTERNAL; + memcpy(mScanSsidBuffer, ssid.data(), ssid.size()); + mScanParams.ssids[0] = reinterpret_cast(&mScanSsidBuffer); + if (0 != net_mgmt(NET_REQUEST_WIFI_SCAN, mNetIf, &mScanParams, sizeof(mScanParams))) + { + ChipLogError(DeviceLayer, "Scan request failed"); + return CHIP_ERROR_INTERNAL; + } + } + else + { + if (0 != net_mgmt(NET_REQUEST_WIFI_SCAN, mNetIf, NULL, 0)) + { + ChipLogError(DeviceLayer, "Scan request failed"); + return CHIP_ERROR_INTERNAL; + } } ChipLogDetail(DeviceLayer, "WiFi scanning started..."); - return CHIP_NO_ERROR; } @@ -420,8 +432,8 @@ void WiFiManager::ConnectHandler(Platform::UniquePtr data) { CHIP_ERROR err = SystemLayer().ScheduleLambda([capturedData = data.get()] { Platform::UniquePtr safePtr(capturedData); - uint8_t * rawData = safePtr.get(); - const wifi_status * status = reinterpret_cast(rawData); + uint8_t * rawData = safePtr.get(); + const wifi_status * status = reinterpret_cast(rawData); if (status->status) { diff --git a/src/platform/nrfconnect/wifi/WiFiManager.h b/src/platform/nrfconnect/wifi/WiFiManager.h index 9ddb5dea27..2bf3f1b840 100644 --- a/src/platform/nrfconnect/wifi/WiFiManager.h +++ b/src/platform/nrfconnect/wifi/WiFiManager.h @@ -219,6 +219,8 @@ class WiFiManager net_if * mNetIf{ nullptr }; ConnectionParams mWiFiParams{}; ConnectionHandling mHandling; + struct wifi_scan_params mScanParams; + char mScanSsidBuffer[DeviceLayer::Internal::kMaxWiFiSSIDLength] = { 0 }; wifi_iface_state mWiFiState; wifi_iface_state mCachedWiFiState; net_mgmt_event_callback mWiFiMgmtClbk{};