Skip to content

Commit 3f6e0d3

Browse files
committed
fixing the scan for the wifi
1 parent d22a2e2 commit 3f6e0d3

File tree

4 files changed

+32
-18
lines changed

4 files changed

+32
-18
lines changed

examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp

+15-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <stdio.h>
2323
#include <stdlib.h>
2424
#include <string.h>
25-
25+
#include "silabs_utils.h"
2626
#if (SL_MATTER_GN_BUILD == 0)
2727
#include "sl_matter_wifi_config.h"
2828
#endif // SL_MATTER_GN_BUILD
@@ -43,6 +43,7 @@
4343
#include <lib/support/CHIPMemString.h>
4444
#include <lib/support/CodeUtils.h>
4545
#include <lib/support/logging/CHIPLogging.h>
46+
#include <platform/CHIPDeviceLayer.h>
4647

4748
extern "C" {
4849
#include "sl_net.h"
@@ -543,27 +544,36 @@ sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result)
543544
{
544545
memset(&cur_scan_result, 0, sizeof(cur_scan_result));
545546

546-
cur_scan_result.ssid_length = strnlen((char *) scan_result->scan_info[idx].ssid,
547-
chip::min<size_t>(sizeof(scan_result->scan_info[idx].ssid), WFX_MAX_SSID_LENGTH));
547+
// cur_scan_result.ssid_length = strnlen((char *) scan_result->scan_info[idx].ssid,
548+
// chip::min<size_t>(sizeof(scan_result->scan_info[idx].ssid) + 1, WFX_MAX_SSID_LENGTH));
549+
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
548550
chip::Platform::CopyString(cur_scan_result.ssid, cur_scan_result.ssid_length, (char *) scan_result->scan_info[idx].ssid);
549551

552+
SILABS_LOG("ssid : %s", cur_scan_result.ssid);
553+
SILABS_LOG("scan ssid : %s", wfx_rsi.scan_ssid);
550554
// if user has provided ssid, then check if the current scan result ssid matches the user provided ssid
551555
if (wfx_rsi.scan_ssid != NULL &&
552-
(strncmp(wfx_rsi.scan_ssid, cur_scan_result.ssid, MIN(strlen(wfx_rsi.scan_ssid), strlen(cur_scan_result.ssid))) ==
556+
(strncmp(wfx_rsi.scan_ssid, cur_scan_result.ssid, MIN(strlen(wfx_rsi.scan_ssid), strlen(cur_scan_result.ssid))) !=
553557
CMP_SUCCESS))
554558
{
559+
SILABS_LOG("%d",__LINE__);
555560
continue;
556561
}
557562
cur_scan_result.security = static_cast<wfx_sec_t>(scan_result->scan_info[idx].security_mode);
558563
cur_scan_result.rssi = (-1) * scan_result->scan_info[idx].rssi_val;
559564
memcpy(cur_scan_result.bssid, scan_result->scan_info[idx].bssid, BSSID_LEN);
560565
wfx_rsi.scan_cb(&cur_scan_result);
566+
SILABS_LOG("%d",__LINE__);
561567

562568
// if user has not provided the ssid, then call the callback for each scan result
563569
if (wfx_rsi.scan_ssid == NULL)
564570
{
571+
SILABS_LOG("%d",__LINE__);
572+
565573
continue;
566574
}
575+
SILABS_LOG("%d",__LINE__);
576+
567577
break;
568578
}
569579

@@ -604,7 +614,7 @@ static void wfx_rsi_save_ap_info(void) // translation
604614
sl_wifi_ssid_t ssid_arg;
605615
memset(&ssid_arg, 0, sizeof(ssid_arg));
606616
ssid_arg.length = wfx_rsi.sec.ssid_length;
607-
chip::Platform::CopyString((char *) &ssid_arg.value[0], ssid_arg.length, wfx_rsi.sec.ssid);
617+
memcpy((char *) &ssid_arg.value[0], wfx_rsi.sec.ssid, ssid_arg.length);
608618
sl_wifi_set_scan_callback(scan_callback_handler, NULL);
609619
scan_results_complete = false;
610620
#ifndef EXP_BOARD

examples/platform/silabs/efr32/rs911x/rsi_if.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -755,8 +755,9 @@ void ProcessEvent(WfxEvent_t inEvent)
755755
scan = &scan_rsp.scan_info[x];
756756
// clear structure and calculate size of SSID
757757
memset(&ap, 0, sizeof(ap));
758-
ap.ssid_length =
759-
strnlen(reinterpret_cast<char *>(scan->ssid), chip::min<size_t>(sizeof(scan->ssid), WFX_MAX_SSID_LENGTH));
758+
// ap.ssid_length =
759+
// strnlen(reinterpret_cast<char *>(scan->ssid), chip::min<size_t>(sizeof(scan->ssid) + 1, WFX_MAX_SSID_LENGTH));
760+
ap.ssid_length = chip::min<size_t>(strnlen(ap.ssid) + 1, WFX_MAX_SSID_LENGTH); // +1 for null termination
760761
chip::Platform::CopyString(ap.ssid, ap.ssid_length, reinterpret_cast<char *>(scan->ssid));
761762

762763
// check if the scanned ssid is the one we are looking for

examples/platform/silabs/efr32/wf200/host_if.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,8 @@ int32_t wfx_get_ap_info(wfx_wifi_scan_result_t * ap)
736736
{
737737
int32_t signal_strength;
738738

739-
ap->ssid_length = strnlen(ap_info.ssid, chip::min<size_t>(sizeof(ap_info.ssid), WFX_MAX_SSID_LENGTH));
739+
ap->ssid_length = chip::min<size_t>(strlen(ap_info.ssid) + 1, WFX_MAX_SSID_LENGTH); // +1 for null termination
740+
// ap->ssid_length = strnlen(ap_info.ssid, chip::min<size_t>(sizeof(ap_info.ssid) + 1, WFX_MAX_SSID_LENGTH));
740741
chip::Platform::CopyString(ap->ssid, ap->ssid_length, ap_info.ssid);
741742
memcpy(ap->bssid, ap_info.bssid, sizeof(ap_info.bssid));
742743
ap->security = ap_info.security;
@@ -1184,7 +1185,7 @@ bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *))
11841185
VerifyOrReturnError(scan_cb != nullptr, false);
11851186
if (ssid)
11861187
{
1187-
scan_ssid_length = strnlen(ssid, WFX_MAX_SSID_LENGTH);
1188+
scan_ssid_length = chip::min<size_t>(strnlen(ssid) + 1, WFX_MAX_SSID_LENGTH); // +1 for null termination
11881189
scan_ssid = reinterpret_cast<char *>(chip::Platform::MemoryAlloc(scan_ssid_length));
11891190
VerifyOrReturnError(scan_ssid != nullptr, false);
11901191
Platform::CopyString(scan_ssid, scan_ssid_length, ssid);

examples/platform/silabs/wifi/wfx_rsi_host.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <lib/support/CHIPMemString.h>
2929
#include <lib/support/CodeUtils.h>
3030
#include <lib/support/logging/CHIPLogging.h>
31-
3231
#include "wfx_host_events.h"
3332
#include "wfx_rsi.h"
3433

@@ -362,18 +361,21 @@ int32_t wfx_reset_counts(void)
362361
* @return returns ture if successful,
363362
* false otherwise
364363
*******************************************************************************/
364+
#include "silabs_utils.h"
365365
bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *))
366366
{
367367
// check if already in progress
368-
VerifyOrReturnError(wfx_rsi.scan_cb != nullptr, false);
368+
VerifyOrReturnError(wfx_rsi.scan_cb == nullptr, false);
369369
wfx_rsi.scan_cb = callback;
370-
371-
VerifyOrReturnError(ssid != nullptr, false);
372-
wfx_rsi.scan_ssid_length = strnlen(ssid, chip::min<size_t>(sizeof(ssid), WFX_MAX_SSID_LENGTH));
373-
wfx_rsi.scan_ssid = reinterpret_cast<char *>(chip::Platform::MemoryAlloc(wfx_rsi.scan_ssid_length));
374-
VerifyOrReturnError(wfx_rsi.scan_ssid != nullptr, false);
375-
chip::Platform::CopyString(wfx_rsi.scan_ssid, wfx_rsi.scan_ssid_length, ssid);
376-
370+
// if SSID is provided to scan only that SSID
371+
if(ssid) {
372+
// wfx_rsi.scan_ssid_length = strnlen(ssid, chip::min<size_t>((strlen(ssid) + 1), WFX_MA X_SSID_LENGTH));
373+
wfx_rsi.scan_ssid_length = chip::min<size_t>(strnlen(ssid, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength) + 1, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength);
374+
wfx_rsi.scan_ssid = reinterpret_cast<char *>(chip::Platform::MemoryAlloc(wfx_rsi.scan_ssid_length));
375+
VerifyOrReturnError(wfx_rsi.scan_ssid != nullptr, false);
376+
chip::Platform::CopyString(wfx_rsi.scan_ssid, wfx_rsi.scan_ssid_length, ssid);
377+
SILABS_LOG("%s hhhh %s %d %d", wfx_rsi.scan_ssid, ssid, wfx_rsi.scan_ssid_length, strlen(ssid));
378+
}
377379
WfxEvent_t event;
378380
event.eventType = WFX_EVT_SCAN;
379381
WfxPostEvent(&event);

0 commit comments

Comments
 (0)