Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for WiFi band scan results #326

Draft
wants to merge 4 commits into
base: feature/add-wifi-band-support
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/platform/silabs/NetworkCommissioningWiFiDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ void SlWiFiDriver::OnScanWiFiNetworkDone(wfx_wifi_scan_result_t * aScanResult)
scanResponse.ssidLen = aScanResult->ssid_length;
memcpy(scanResponse.ssid, aScanResult->ssid, scanResponse.ssidLen);
memcpy(scanResponse.bssid, aScanResult->bssid, sizeof(scanResponse.bssid));
scanResponse.wiFiBand = aScanResult->wiFiBand;

mScanResponseIter.Add(&scanResponse);
}
Expand Down
9 changes: 6 additions & 3 deletions src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ extern "C" {
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER

using namespace chip::DeviceLayer::Silabs;
using WiFiBandEnum = chip::app::Clusters::NetworkCommissioning::WiFiBandEnum;

// TODO : Temporary work-around for wifi-init failure in 917NCP ACX module boards.
// Can be removed after Wiseconnect fixes region code for all ACX module boards.
Expand Down Expand Up @@ -200,9 +201,9 @@ sl_status_t BackgroundScanCallback(sl_wifi_event_t event, sl_wifi_scan_result_t
{
wfx_wifi_scan_result_t currentScanResult = { 0 };

// Lenght excludes null-character
size_t scannedSsidLenght = strnlen(reinterpret_cast<char *>(result->scan_info[i].ssid), WFX_MAX_SSID_LENGTH);
chip::ByteSpan scannedSsidSpan(result->scan_info[i].ssid, scannedSsidLenght);
// Length excludes null-character
size_t scannedSsidLength = strnlen(reinterpret_cast<char *>(result->scan_info[i].ssid), WFX_MAX_SSID_LENGTH);
chip::ByteSpan scannedSsidSpan(result->scan_info[i].ssid, scannedSsidLength);

// Copy the scanned SSID to the current scan ssid buffer that will be forwarded to the callback
chip::MutableByteSpan currentScanSsid(currentScanResult.ssid, WFX_MAX_SSID_LENGTH);
Expand All @@ -217,6 +218,8 @@ sl_status_t BackgroundScanCallback(sl_wifi_event_t event, sl_wifi_scan_result_t
currentScanResult.security = static_cast<wfx_sec_t>(result->scan_info[i].security_mode);
currentScanResult.rssi = (-1) * result->scan_info[i].rssi_val; // The returned value is positive - we need to flip it
currentScanResult.chan = result->scan_info[i].rf_channel;
// TODO: change this when SDK provides values
currentScanResult.wiFiBand = WiFiBandEnum::k2g4;

// if user has provided ssid, check if the current scan result ssid matches the user provided ssid
if (!requestedSsidSpan.empty())
Expand Down
4 changes: 3 additions & 1 deletion src/platform/silabs/wifi/WifiInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ constexpr size_t kWifiMacAddressLength = 6;
#define WFX_MAX_SSID_LENGTH (32)
#define MAX_JOIN_RETRIES_COUNT (5)

using WiFiBandEnum = chip::app::Clusters::NetworkCommissioning::WiFiBandEnum;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We avoid as much as possible to use using in a header file since this will propagate to any file that includes the header.

We should use the long name here.


/* Note that these are same as RSI_security */
typedef enum
{
Expand All @@ -73,6 +75,7 @@ typedef struct wfx_wifi_scan_result
uint8_t bssid[kWifiMacAddressLength];
uint8_t chan;
int16_t rssi; /* I suspect this is in dBm - so signed */
WiFiBandEnum wiFiBand;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the plan to clean up this structure in this PR or in a follow up? When we modify the legacy interface elements, we should refactor them as we go.

} wfx_wifi_scan_result_t;
using ScanCallback = void (*)(wfx_wifi_scan_result_t *);

Expand Down Expand Up @@ -412,7 +415,6 @@ class WifiInterface
*/
virtual void CancelScanNetworks() = 0;

using WiFiBandEnum = app::Clusters::NetworkCommissioning::WiFiBandEnum;
/**
* @brief Provide all the frequency bands supported by the Wi-Fi interface.
*
Expand Down
3 changes: 3 additions & 0 deletions src/platform/silabs/wifi/rs911x/WifiInterfaceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ extern "C" {
WfxRsi_t wfx_rsi;

using namespace chip::DeviceLayer::Silabs;
using WiFiBandEnum = chip::app::Clusters::NetworkCommissioning::WiFiBandEnum;

namespace {

Expand Down Expand Up @@ -376,6 +377,8 @@ void WifiInterfaceImpl::ProcessEvent(WifiPlatformEvent event)
chip::MutableByteSpan bssidSpan(ap.bssid, kWifiMacAddressLength);
chip::ByteSpan scanBssidSpan(scan.bssid, kWifiMacAddressLength);
chip::CopySpanToMutableSpan(scanBssidSpan, bssidSpan);
// TODO: change this when SDK provides values
ap.wiFiBand = WiFiBandEnum::k2g4;

wfx_rsi.scan_cb(&ap);

Expand Down
3 changes: 3 additions & 0 deletions src/platform/silabs/wifi/wf200/WifiInterfaceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
using namespace ::chip;
using namespace ::chip::DeviceLayer;
using namespace ::chip::DeviceLayer::Silabs;
using WiFiBandEnum = chip::app::Clusters::NetworkCommissioning::WiFiBandEnum;

// TODO: This is a workaround because we depend on the platform lib which depends on the platform implementation.
// As such we can't depend on the platform here as well
Expand Down Expand Up @@ -483,6 +484,8 @@ static void sl_wfx_scan_result_callback(sl_wfx_scan_result_ind_body_t * scan_res

ap->scan.chan = scan_result->channel;
ap->scan.rssi = ConvertRcpiToRssi(scan_result->rcpi);
// WF200 only supports 2.4GHz band
ap->scan.wiFiBand = WiFiBandEnum::k2g4;

chip::ByteSpan scannedBssid(scan_result->mac, kWifiMacAddressLength);
chip::MutableByteSpan outputBssid(ap->scan.bssid, kWifiMacAddressLength);
Expand Down