Skip to content

Commit

Permalink
[nrf noup] Wifi directed scan with single scan
Browse files Browse the repository at this point in the history
This commit implements directed scaning and
single ssid scaning while commisioning.

Signed-off-by: Patryk Lipinski <patryk.lipinski@nordicsemi.no>
  • Loading branch information
LipinskiPNordicSemi committed Mar 14, 2024
1 parent 7653e6c commit db6c1b3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/platform/nrfconnect/wifi/WiFiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char *>(&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;
}

Expand Down Expand Up @@ -420,8 +432,8 @@ void WiFiManager::ConnectHandler(Platform::UniquePtr<uint8_t> data)
{
CHIP_ERROR err = SystemLayer().ScheduleLambda([capturedData = data.get()] {
Platform::UniquePtr<uint8_t> safePtr(capturedData);
uint8_t * rawData = safePtr.get();
const wifi_status * status = reinterpret_cast<const wifi_status *>(rawData);
uint8_t * rawData = safePtr.get();
const wifi_status * status = reinterpret_cast<const wifi_status *>(rawData);

if (status->status)
{
Expand Down
2 changes: 2 additions & 0 deletions src/platform/nrfconnect/wifi/WiFiManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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{};
Expand Down

0 comments on commit db6c1b3

Please sign in to comment.