|
22 | 22 | #include "ble_config.h" |
23 | 23 | #include "sl_status.h" |
24 | 24 | #include "sl_wifi_device.h" |
| 25 | + |
| 26 | +#include <algorithm> |
25 | 27 | #include <app/icd/server/ICDServerConfig.h> |
26 | 28 | #include <cmsis_os2.h> |
27 | 29 | #include <inet/IPAddress.h> |
28 | 30 | #include <lib/support/CHIPMem.h> |
29 | 31 | #include <lib/support/CHIPMemString.h> |
30 | 32 | #include <lib/support/logging/CHIPLogging.h> |
| 33 | +#include <platform/NetworkCommissioning.h> |
31 | 34 | #include <platform/silabs/wifi/SiWx/WifiInterfaceImpl.h> |
32 | 35 | #include <sl_cmsis_os2_common.h> |
33 | 36 |
|
@@ -271,60 +274,58 @@ sl_status_t BackgroundScanCallback(sl_wifi_event_t event, sl_wifi_scan_result_t |
271 | 274 | VerifyOrReturnError(result != nullptr, SL_STATUS_NULL_POINTER); |
272 | 275 | VerifyOrReturnError(wfx_rsi.scan_cb != nullptr, SL_STATUS_INVALID_HANDLE); |
273 | 276 |
|
274 | | - sl_wifi_ssid_t * requestedSsidPtr = nullptr; |
275 | | - chip::ByteSpan requestedSsidSpan; |
276 | | - // arg is the requested SSID pointer passed during sl_wifi_set_scan_callback |
| 277 | + chip::ByteSpan requestedSsidSpan = {}; |
| 278 | + |
| 279 | + // arg is set to requested SSID if provided in sl_wifi_set_scan_callback |
277 | 280 | if (arg != nullptr) |
278 | 281 | { |
279 | | - requestedSsidPtr = reinterpret_cast<sl_wifi_ssid_t *>(arg); |
280 | | - requestedSsidSpan = chip::ByteSpan(requestedSsidPtr->value, requestedSsidPtr->length); |
| 282 | + sl_wifi_ssid_t * requestedSsidPtr = static_cast<sl_wifi_ssid_t *>(arg); |
| 283 | + requestedSsidSpan = chip::ByteSpan(requestedSsidPtr->value, requestedSsidPtr->length); |
281 | 284 | } |
282 | 285 |
|
283 | 286 | uint32_t nbreResults = result->scan_count; |
284 | 287 | for (uint32_t i = 0; i < nbreResults; i++) |
285 | 288 | { |
286 | | - wfx_wifi_scan_result_t currentScanResult = { 0 }; |
287 | | - |
288 | 289 | // Length excludes null-character |
289 | | - size_t scannedSsidLength = strnlen(reinterpret_cast<char *>(result->scan_info[i].ssid), kMaxWiFiSSIDLength); |
290 | | - chip::ByteSpan scannedSsidSpan(result->scan_info[i].ssid, scannedSsidLength); |
291 | | - |
292 | | - // Copy the scanned SSID to the current scan ssid buffer that will be forwarded to the callback |
293 | | - chip::MutableByteSpan currentScanSsid(currentScanResult.ssid, kMaxWiFiSSIDLength); |
294 | | - ReturnValueOnFailure(chip::CopySpanToMutableSpan(scannedSsidSpan, currentScanSsid), |
295 | | - SL_STATUS_SI91X_MEMORY_IS_NOT_SUFFICIENT); |
296 | | - currentScanResult.ssid_length = currentScanSsid.size(); |
297 | | - |
298 | | - chip::ByteSpan inBssid(result->scan_info[i].bssid, kWiFiBSSIDLength); |
299 | | - chip::MutableByteSpan outBssid(currentScanResult.bssid, kWiFiBSSIDLength); |
300 | | - ReturnValueOnFailure(chip::CopySpanToMutableSpan(inBssid, outBssid), SL_STATUS_SI91X_MEMORY_IS_NOT_SUFFICIENT); |
301 | | - |
302 | | - currentScanResult.security = |
303 | | - ConvertSlWifiSecurityToBitmap(static_cast<sl_wifi_security_t>(result->scan_info[i].security_mode)); |
304 | | - currentScanResult.rssi = (-1) * result->scan_info[i].rssi_val; // The returned value is positive - we need to flip it |
305 | | - currentScanResult.chan = result->scan_info[i].rf_channel; |
306 | | - // TODO: change this when SDK provides values |
307 | | - currentScanResult.wiFiBand = WiFiBandEnum::k2g4; |
308 | | - |
309 | | - // if user has provided ssid, check if the current scan result ssid matches the user provided ssid |
310 | | - // NOTE: background scan does not filter by ssid, so we need to do it here |
311 | | - if (!requestedSsidSpan.empty()) |
312 | | - { |
313 | | - if (requestedSsidSpan.data_equal(currentScanSsid)) |
314 | | - { |
315 | | - wfx_rsi.scan_cb(¤tScanResult); |
316 | | - } |
317 | | - } |
318 | | - else // No ssid was provide - forward all results |
| 290 | + size_t ssidLen = strnlen(reinterpret_cast<char *>(result->scan_info[i].ssid), kMaxWiFiSSIDLength); |
| 291 | + chip::ByteSpan ssidSpan(result->scan_info[i].ssid, ssidLen); |
| 292 | + |
| 293 | + if (requestedSsidSpan.empty() || requestedSsidSpan.data_equal(ssidSpan)) |
319 | 294 | { |
| 295 | + |
| 296 | + // Create a new scan response for the current scan result |
| 297 | + chip::DeviceLayer::NetworkCommissioning::WiFiScanResponse currentScanResult = {}; |
| 298 | + |
| 299 | + // Copy the scanned SSID to the scan response |
| 300 | + chip::MutableByteSpan responseSsidSpan(currentScanResult.ssid, kMaxWiFiSSIDLength); |
| 301 | + VerifyOrReturnError(chip::CopySpanToMutableSpan(ssidSpan, responseSsidSpan) == CHIP_NO_ERROR, |
| 302 | + SL_STATUS_SI91X_MEMORY_IS_NOT_SUFFICIENT); |
| 303 | + currentScanResult.ssidLen = static_cast<uint8_t>(ssidLen); |
| 304 | + |
| 305 | + // Copy the BSSID to the scan response |
| 306 | + chip::ByteSpan bssidSpan(result->scan_info[i].bssid, kWiFiBSSIDLength); |
| 307 | + chip::MutableByteSpan responseBssidSpan(currentScanResult.bssid, kWiFiBSSIDLength); |
| 308 | + VerifyOrReturnError(chip::CopySpanToMutableSpan(bssidSpan, responseBssidSpan) == CHIP_NO_ERROR, |
| 309 | + SL_STATUS_SI91X_MEMORY_IS_NOT_SUFFICIENT); |
| 310 | + |
| 311 | + // Convert the RSSI to a int8_t value |
| 312 | + int16_t rssi = std::clamp(((-1) * result->scan_info[i].rssi_val), INT8_MIN, INT8_MAX); |
| 313 | + |
| 314 | + currentScanResult.signal.strength = static_cast<int8_t>(rssi); |
| 315 | + currentScanResult.signal.type = chip::DeviceLayer::NetworkCommissioning::WirelessSignalType::kdBm; |
| 316 | + |
| 317 | + currentScanResult.channel = static_cast<uint16_t>(result->scan_info[i].rf_channel); |
| 318 | + currentScanResult.wiFiBand = WiFiBandEnum::k2g4; |
| 319 | + |
| 320 | + currentScanResult.security = |
| 321 | + ConvertSlWifiSecurityToBitmap(static_cast<sl_wifi_security_t>(result->scan_info[i].security_mode)); |
| 322 | + |
320 | 323 | wfx_rsi.scan_cb(¤tScanResult); |
321 | 324 | } |
322 | 325 | } |
323 | | - |
| 326 | + // null callback to indicate that the scan is complete |
324 | 327 | wfx_rsi.scan_cb(nullptr); |
325 | | - // cleanup and return |
326 | 328 | wfx_rsi.scan_cb = nullptr; |
327 | | - |
328 | 329 | wfx_rsi.dev_state.Clear(WifiInterface::WifiState::kScanStarted); |
329 | 330 | osSemaphoreRelease(sScanCompleteSemaphore); |
330 | 331 |
|
@@ -807,7 +808,7 @@ sl_status_t WifiInterfaceImpl::JoinCallback(sl_wifi_event_t event, char * result |
807 | 808 | return status; |
808 | 809 | } |
809 | 810 |
|
810 | | -CHIP_ERROR WifiInterfaceImpl::GetAccessPointInfo(wfx_wifi_scan_result_t & info) |
| 811 | +CHIP_ERROR WifiInterfaceImpl::GetAccessPointInfo(NetworkCommissioning::WiFiScanResponse & info) |
811 | 812 | { |
812 | 813 | // TODO: Convert this to a int8 |
813 | 814 | int32_t rssi = 0; |
@@ -836,19 +837,21 @@ CHIP_ERROR WifiInterfaceImpl::GetAccessPointInfo(wfx_wifi_scan_result_t & info) |
836 | 837 | } |
837 | 838 |
|
838 | 839 | info.security = wfx_rsi.credentials.security; |
839 | | - info.chan = wfx_rsi.ap_chan; |
| 840 | + info.channel = wfx_rsi.ap_chan; |
| 841 | + info.wiFiBand = WiFiBandEnum::k2g4; |
840 | 842 |
|
841 | 843 | chip::MutableByteSpan output(info.ssid, kMaxWiFiSSIDLength); |
842 | 844 | chip::ByteSpan ssid(wfx_rsi.credentials.ssid, wfx_rsi.credentials.ssidLen); |
843 | 845 | ReturnErrorOnFailure(chip::CopySpanToMutableSpan(ssid, output)); |
844 | | - info.ssid_length = output.size(); |
| 846 | + info.ssidLen = static_cast<uint8_t>(output.size()); |
845 | 847 | chip::ByteSpan apBssidSpan(wfx_rsi.ap_bssid.data(), wfx_rsi.ap_bssid.size()); |
846 | 848 | chip::MutableByteSpan bssidSpan(info.bssid, kWiFiBSSIDLength); |
847 | 849 | ReturnErrorOnFailure(chip::CopySpanToMutableSpan(apBssidSpan, bssidSpan)); |
848 | 850 |
|
849 | 851 | // TODO: add error processing |
850 | 852 | sl_wifi_get_signal_strength(SL_WIFI_CLIENT_INTERFACE, &(rssi)); |
851 | | - info.rssi = rssi; |
| 853 | + info.signal.strength = static_cast<int8_t>(std::clamp(rssi, static_cast<int32_t>(INT8_MIN), static_cast<int32_t>(INT8_MAX))); |
| 854 | + info.signal.type = NetworkCommissioning::WirelessSignalType::kdBm; |
852 | 855 | return CHIP_NO_ERROR; |
853 | 856 | } |
854 | 857 |
|
|
0 commit comments