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

[SL-TEMP] Fixing the scan for the WiFi devices #81

11 changes: 4 additions & 7 deletions examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#if (SL_MATTER_GN_BUILD == 0)
#include "sl_matter_wifi_config.h"
#endif // SL_MATTER_GN_BUILD
Expand All @@ -43,6 +42,7 @@
#include <lib/support/CHIPMemString.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/logging/CHIPLogging.h>
#include <platform/CHIPDeviceLayer.h>

extern "C" {
#include "sl_net.h"
Expand Down Expand Up @@ -542,14 +542,11 @@ sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result)
for (int idx = 0; idx < (int) scan_result->scan_count; idx++)
{
memset(&cur_scan_result, 0, sizeof(cur_scan_result));

cur_scan_result.ssid_length = strnlen((char *) scan_result->scan_info[idx].ssid,
chip::min<size_t>(sizeof(scan_result->scan_info[idx].ssid), WFX_MAX_SSID_LENGTH));
cur_scan_result.ssid_length = chip::min<size_t>(strnlen((char *) scan_result->scan_info[idx].ssid, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength) + 1, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength); // +1 for null termination
chip::Platform::CopyString(cur_scan_result.ssid, cur_scan_result.ssid_length, (char *) scan_result->scan_info[idx].ssid);

// if user has provided ssid, then check if the current scan result ssid matches the user provided ssid
if (wfx_rsi.scan_ssid != NULL &&
(strncmp(wfx_rsi.scan_ssid, cur_scan_result.ssid, MIN(strlen(wfx_rsi.scan_ssid), strlen(cur_scan_result.ssid))) ==
(strncmp(wfx_rsi.scan_ssid, cur_scan_result.ssid, MIN(strlen(wfx_rsi.scan_ssid), strlen(cur_scan_result.ssid))) !=
CMP_SUCCESS))
{
continue;
Expand Down Expand Up @@ -604,7 +601,7 @@ static void wfx_rsi_save_ap_info(void) // translation
sl_wifi_ssid_t ssid_arg;
memset(&ssid_arg, 0, sizeof(ssid_arg));
ssid_arg.length = wfx_rsi.sec.ssid_length;
chip::Platform::CopyString((char *) &ssid_arg.value[0], ssid_arg.length, wfx_rsi.sec.ssid);
memcpy((char *) &ssid_arg.value[0], wfx_rsi.sec.ssid, ssid_arg.length);
sl_wifi_set_scan_callback(scan_callback_handler, NULL);
scan_results_complete = false;
#ifndef EXP_BOARD
Expand Down
3 changes: 1 addition & 2 deletions examples/platform/silabs/efr32/rs911x/rsi_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,7 @@ void ProcessEvent(WfxEvent_t inEvent)
scan = &scan_rsp.scan_info[x];
// clear structure and calculate size of SSID
memset(&ap, 0, sizeof(ap));
ap.ssid_length =
strnlen(reinterpret_cast<char *>(scan->ssid), chip::min<size_t>(sizeof(scan->ssid), WFX_MAX_SSID_LENGTH));
ap.ssid_length = chip::min<size_t>(strnlen(ap.ssid, WFX_MAX_SSID_LENGTH) + 1, WFX_MAX_SSID_LENGTH); // +1 for null termination
chip::Platform::CopyString(ap.ssid, ap.ssid_length, reinterpret_cast<char *>(scan->ssid));

// check if the scanned ssid is the one we are looking for
Expand Down
4 changes: 2 additions & 2 deletions examples/platform/silabs/efr32/wf200/host_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ int32_t wfx_get_ap_info(wfx_wifi_scan_result_t * ap)
{
int32_t signal_strength;

ap->ssid_length = strnlen(ap_info.ssid, chip::min<size_t>(sizeof(ap_info.ssid), WFX_MAX_SSID_LENGTH));
ap->ssid_length = chip::min<size_t>(strlen(ap_info.ssid) + 1, WFX_MAX_SSID_LENGTH); // +1 for null termination
chip::Platform::CopyString(ap->ssid, ap->ssid_length, ap_info.ssid);
memcpy(ap->bssid, ap_info.bssid, sizeof(ap_info.bssid));
ap->security = ap_info.security;
Expand Down Expand Up @@ -1184,7 +1184,7 @@ bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *))
VerifyOrReturnError(scan_cb != nullptr, false);
if (ssid)
{
scan_ssid_length = strnlen(ssid, WFX_MAX_SSID_LENGTH);
scan_ssid_length = chip::min<size_t>(strnlen(ssid, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength) + 1, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength); // +1 for null termination
scan_ssid = reinterpret_cast<char *>(chip::Platform::MemoryAlloc(scan_ssid_length));
VerifyOrReturnError(scan_ssid != nullptr, false);
Platform::CopyString(scan_ssid, scan_ssid_length, ssid);
Expand Down
17 changes: 8 additions & 9 deletions examples/platform/silabs/wifi/wfx_rsi_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <lib/support/CHIPMemString.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/logging/CHIPLogging.h>

#include "wfx_host_events.h"
#include "wfx_rsi.h"

Expand Down Expand Up @@ -365,15 +364,15 @@ int32_t wfx_reset_counts(void)
bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *))
{
// check if already in progress
VerifyOrReturnError(wfx_rsi.scan_cb != nullptr, false);
VerifyOrReturnError(wfx_rsi.scan_cb == nullptr, false);
wfx_rsi.scan_cb = callback;

VerifyOrReturnError(ssid != nullptr, false);
wfx_rsi.scan_ssid_length = strnlen(ssid, chip::min<size_t>(sizeof(ssid), WFX_MAX_SSID_LENGTH));
wfx_rsi.scan_ssid = reinterpret_cast<char *>(chip::Platform::MemoryAlloc(wfx_rsi.scan_ssid_length));
VerifyOrReturnError(wfx_rsi.scan_ssid != nullptr, false);
chip::Platform::CopyString(wfx_rsi.scan_ssid, wfx_rsi.scan_ssid_length, ssid);

// if SSID is provided to scan only that SSID
if(ssid) {
wfx_rsi.scan_ssid_length = chip::min<size_t>(strnlen(ssid, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength) + 1, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength); // +1 for null termination
wfx_rsi.scan_ssid = reinterpret_cast<char *>(chip::Platform::MemoryAlloc(wfx_rsi.scan_ssid_length));
VerifyOrReturnError(wfx_rsi.scan_ssid != nullptr, false);
chip::Platform::CopyString(wfx_rsi.scan_ssid, wfx_rsi.scan_ssid_length, ssid);
}
WfxEvent_t event;
event.eventType = WFX_EVT_SCAN;
WfxPostEvent(&event);
Expand Down
Loading