From 7c56b89d581c647467d1f627f943c8901eb5be97 Mon Sep 17 00:00:00 2001 From: chirag-silabs Date: Wed, 30 Oct 2024 10:57:25 +0530 Subject: [PATCH 01/10] fixing the scan for the wifi --- .../silabs/SiWx917/SiWx917/sl_wifi_if.cpp | 20 ++++++++++++++----- .../platform/silabs/efr32/rs911x/rsi_if.cpp | 5 +++-- .../platform/silabs/efr32/wf200/host_if.cpp | 5 +++-- .../platform/silabs/wifi/wfx_rsi_host.cpp | 20 ++++++++++--------- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp index c65a97ea3a..d19532e635 100644 --- a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp +++ b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp @@ -22,7 +22,7 @@ #include #include #include - +#include "silabs_utils.h" #if (SL_MATTER_GN_BUILD == 0) #include "sl_matter_wifi_config.h" #endif // SL_MATTER_GN_BUILD @@ -43,6 +43,7 @@ #include #include #include +#include extern "C" { #include "sl_net.h" @@ -543,27 +544,36 @@ sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result) { memset(&cur_scan_result, 0, sizeof(cur_scan_result)); - cur_scan_result.ssid_length = strnlen((char *) scan_result->scan_info[idx].ssid, - chip::min(sizeof(scan_result->scan_info[idx].ssid), WFX_MAX_SSID_LENGTH)); + // cur_scan_result.ssid_length = strnlen((char *) scan_result->scan_info[idx].ssid, + // chip::min(sizeof(scan_result->scan_info[idx].ssid) + 1, WFX_MAX_SSID_LENGTH)); + cur_scan_result.ssid_length = chip::min(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); + SILABS_LOG("ssid : %s", cur_scan_result.ssid); + SILABS_LOG("scan ssid : %s", wfx_rsi.scan_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)) { + SILABS_LOG("%d",__LINE__); continue; } cur_scan_result.security = static_cast(scan_result->scan_info[idx].security_mode); cur_scan_result.rssi = (-1) * scan_result->scan_info[idx].rssi_val; memcpy(cur_scan_result.bssid, scan_result->scan_info[idx].bssid, BSSID_LEN); wfx_rsi.scan_cb(&cur_scan_result); + SILABS_LOG("%d",__LINE__); // if user has not provided the ssid, then call the callback for each scan result if (wfx_rsi.scan_ssid == NULL) { + SILABS_LOG("%d",__LINE__); + continue; } + SILABS_LOG("%d",__LINE__); + break; } @@ -604,7 +614,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 diff --git a/examples/platform/silabs/efr32/rs911x/rsi_if.cpp b/examples/platform/silabs/efr32/rs911x/rsi_if.cpp index cedfc05cd5..4bbbedb07f 100644 --- a/examples/platform/silabs/efr32/rs911x/rsi_if.cpp +++ b/examples/platform/silabs/efr32/rs911x/rsi_if.cpp @@ -755,8 +755,9 @@ 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(scan->ssid), chip::min(sizeof(scan->ssid), WFX_MAX_SSID_LENGTH)); + // ap.ssid_length = + // strnlen(reinterpret_cast(scan->ssid), chip::min(sizeof(scan->ssid) + 1, WFX_MAX_SSID_LENGTH)); + ap.ssid_length = chip::min(strnlen(ap.ssid) + 1, WFX_MAX_SSID_LENGTH); // +1 for null termination chip::Platform::CopyString(ap.ssid, ap.ssid_length, reinterpret_cast(scan->ssid)); // check if the scanned ssid is the one we are looking for diff --git a/examples/platform/silabs/efr32/wf200/host_if.cpp b/examples/platform/silabs/efr32/wf200/host_if.cpp index 044ecc6e97..0c71c6b340 100644 --- a/examples/platform/silabs/efr32/wf200/host_if.cpp +++ b/examples/platform/silabs/efr32/wf200/host_if.cpp @@ -736,7 +736,8 @@ 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(sizeof(ap_info.ssid), WFX_MAX_SSID_LENGTH)); + ap->ssid_length = chip::min(strlen(ap_info.ssid) + 1, WFX_MAX_SSID_LENGTH); // +1 for null termination + // ap->ssid_length = strnlen(ap_info.ssid, chip::min(sizeof(ap_info.ssid) + 1, WFX_MAX_SSID_LENGTH)); 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; @@ -1184,7 +1185,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(strnlen(ssid) + 1, WFX_MAX_SSID_LENGTH); // +1 for null termination scan_ssid = reinterpret_cast(chip::Platform::MemoryAlloc(scan_ssid_length)); VerifyOrReturnError(scan_ssid != nullptr, false); Platform::CopyString(scan_ssid, scan_ssid_length, ssid); diff --git a/examples/platform/silabs/wifi/wfx_rsi_host.cpp b/examples/platform/silabs/wifi/wfx_rsi_host.cpp index 130d9c90d1..bcb72977ce 100644 --- a/examples/platform/silabs/wifi/wfx_rsi_host.cpp +++ b/examples/platform/silabs/wifi/wfx_rsi_host.cpp @@ -28,7 +28,6 @@ #include #include #include - #include "wfx_host_events.h" #include "wfx_rsi.h" @@ -362,18 +361,21 @@ int32_t wfx_reset_counts(void) * @return returns ture if successful, * false otherwise *******************************************************************************/ +#include "silabs_utils.h" 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(sizeof(ssid), WFX_MAX_SSID_LENGTH)); - wfx_rsi.scan_ssid = reinterpret_cast(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 = strnlen(ssid, chip::min((strlen(ssid) + 1), WFX_MA X_SSID_LENGTH)); + wfx_rsi.scan_ssid_length = chip::min(strnlen(ssid, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength) + 1, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength); + wfx_rsi.scan_ssid = reinterpret_cast(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); + SILABS_LOG("%s hhhh %s %d %d", wfx_rsi.scan_ssid, ssid, wfx_rsi.scan_ssid_length, strlen(ssid)); + } WfxEvent_t event; event.eventType = WFX_EVT_SCAN; WfxPostEvent(&event); From ff8ff4885e795e198d453054cb24eb34b406fe64 Mon Sep 17 00:00:00 2001 From: chirag-silabs Date: Wed, 30 Oct 2024 11:12:27 +0530 Subject: [PATCH 02/10] removing the unused code --- .../platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp | 13 ------------- examples/platform/silabs/efr32/rs911x/rsi_if.cpp | 5 ++--- examples/platform/silabs/efr32/wf200/host_if.cpp | 2 +- examples/platform/silabs/wifi/wfx_rsi_host.cpp | 5 +---- 4 files changed, 4 insertions(+), 21 deletions(-) diff --git a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp index d19532e635..d562e72e8f 100644 --- a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp +++ b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp @@ -22,7 +22,6 @@ #include #include #include -#include "silabs_utils.h" #if (SL_MATTER_GN_BUILD == 0) #include "sl_matter_wifi_config.h" #endif // SL_MATTER_GN_BUILD @@ -543,37 +542,25 @@ 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(sizeof(scan_result->scan_info[idx].ssid) + 1, WFX_MAX_SSID_LENGTH)); cur_scan_result.ssid_length = chip::min(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); - - SILABS_LOG("ssid : %s", cur_scan_result.ssid); - SILABS_LOG("scan ssid : %s", wfx_rsi.scan_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))) != CMP_SUCCESS)) { - SILABS_LOG("%d",__LINE__); continue; } cur_scan_result.security = static_cast(scan_result->scan_info[idx].security_mode); cur_scan_result.rssi = (-1) * scan_result->scan_info[idx].rssi_val; memcpy(cur_scan_result.bssid, scan_result->scan_info[idx].bssid, BSSID_LEN); wfx_rsi.scan_cb(&cur_scan_result); - SILABS_LOG("%d",__LINE__); // if user has not provided the ssid, then call the callback for each scan result if (wfx_rsi.scan_ssid == NULL) { - SILABS_LOG("%d",__LINE__); - continue; } - SILABS_LOG("%d",__LINE__); - break; } diff --git a/examples/platform/silabs/efr32/rs911x/rsi_if.cpp b/examples/platform/silabs/efr32/rs911x/rsi_if.cpp index 4bbbedb07f..bd3ca6dde6 100644 --- a/examples/platform/silabs/efr32/rs911x/rsi_if.cpp +++ b/examples/platform/silabs/efr32/rs911x/rsi_if.cpp @@ -58,6 +58,7 @@ extern "C" { #include #include #include +#include #define WFX_QUEUE_SIZE 10 @@ -755,9 +756,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(scan->ssid), chip::min(sizeof(scan->ssid) + 1, WFX_MAX_SSID_LENGTH)); - ap.ssid_length = chip::min(strnlen(ap.ssid) + 1, WFX_MAX_SSID_LENGTH); // +1 for null termination + ap.ssid_length = chip::min(strnlen(ap.ssid, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength) + 1, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength); // +1 for null termination chip::Platform::CopyString(ap.ssid, ap.ssid_length, reinterpret_cast(scan->ssid)); // check if the scanned ssid is the one we are looking for diff --git a/examples/platform/silabs/efr32/wf200/host_if.cpp b/examples/platform/silabs/efr32/wf200/host_if.cpp index 0c71c6b340..7e47ca4c6b 100644 --- a/examples/platform/silabs/efr32/wf200/host_if.cpp +++ b/examples/platform/silabs/efr32/wf200/host_if.cpp @@ -1185,7 +1185,7 @@ bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *)) VerifyOrReturnError(scan_cb != nullptr, false); if (ssid) { - scan_ssid_length = chip::min(strnlen(ssid) + 1, WFX_MAX_SSID_LENGTH); // +1 for null termination + scan_ssid_length = chip::min(strnlen(ssid, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength) + 1, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength); // +1 for null termination scan_ssid = reinterpret_cast(chip::Platform::MemoryAlloc(scan_ssid_length)); VerifyOrReturnError(scan_ssid != nullptr, false); Platform::CopyString(scan_ssid, scan_ssid_length, ssid); diff --git a/examples/platform/silabs/wifi/wfx_rsi_host.cpp b/examples/platform/silabs/wifi/wfx_rsi_host.cpp index bcb72977ce..b299b2fa4d 100644 --- a/examples/platform/silabs/wifi/wfx_rsi_host.cpp +++ b/examples/platform/silabs/wifi/wfx_rsi_host.cpp @@ -361,7 +361,6 @@ int32_t wfx_reset_counts(void) * @return returns ture if successful, * false otherwise *******************************************************************************/ -#include "silabs_utils.h" bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *)) { // check if already in progress @@ -369,12 +368,10 @@ bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *)) wfx_rsi.scan_cb = callback; // if SSID is provided to scan only that SSID if(ssid) { - // wfx_rsi.scan_ssid_length = strnlen(ssid, chip::min((strlen(ssid) + 1), WFX_MA X_SSID_LENGTH)); - wfx_rsi.scan_ssid_length = chip::min(strnlen(ssid, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength) + 1, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength); + wfx_rsi.scan_ssid_length = chip::min(strnlen(ssid, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength) + 1, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength); // +1 for null termination wfx_rsi.scan_ssid = reinterpret_cast(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); - SILABS_LOG("%s hhhh %s %d %d", wfx_rsi.scan_ssid, ssid, wfx_rsi.scan_ssid_length, strlen(ssid)); } WfxEvent_t event; event.eventType = WFX_EVT_SCAN; From 7f20f4c6833634927a6b31161ba7854c50e74f96 Mon Sep 17 00:00:00 2001 From: chirag-silabs Date: Wed, 30 Oct 2024 11:34:47 +0530 Subject: [PATCH 03/10] removing the commneted code --- examples/platform/silabs/efr32/wf200/host_if.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/platform/silabs/efr32/wf200/host_if.cpp b/examples/platform/silabs/efr32/wf200/host_if.cpp index 7e47ca4c6b..3699a943d4 100644 --- a/examples/platform/silabs/efr32/wf200/host_if.cpp +++ b/examples/platform/silabs/efr32/wf200/host_if.cpp @@ -737,7 +737,6 @@ int32_t wfx_get_ap_info(wfx_wifi_scan_result_t * ap) int32_t signal_strength; ap->ssid_length = chip::min(strlen(ap_info.ssid) + 1, WFX_MAX_SSID_LENGTH); // +1 for null termination - // ap->ssid_length = strnlen(ap_info.ssid, chip::min(sizeof(ap_info.ssid) + 1, WFX_MAX_SSID_LENGTH)); 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; From fc15c9fe63fd48b0659af523e7b8a4b0cef6f6ae Mon Sep 17 00:00:00 2001 From: chirag-silabs Date: Wed, 30 Oct 2024 16:59:50 +0530 Subject: [PATCH 04/10] fixing the build for rs9116 --- examples/platform/silabs/efr32/rs911x/rsi_if.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/platform/silabs/efr32/rs911x/rsi_if.cpp b/examples/platform/silabs/efr32/rs911x/rsi_if.cpp index bd3ca6dde6..3893e75d87 100644 --- a/examples/platform/silabs/efr32/rs911x/rsi_if.cpp +++ b/examples/platform/silabs/efr32/rs911x/rsi_if.cpp @@ -58,7 +58,6 @@ extern "C" { #include #include #include -#include #define WFX_QUEUE_SIZE 10 @@ -756,7 +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 = chip::min(strnlen(ap.ssid, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength) + 1, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength); // +1 for null termination + ap.ssid_length = chip::min(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(scan->ssid)); // check if the scanned ssid is the one we are looking for From da46aeeccc4bc802bb738f854f269ea59302c2bf Mon Sep 17 00:00:00 2001 From: chirag-silabs Date: Thu, 31 Oct 2024 10:10:29 +0530 Subject: [PATCH 05/10] addressing review comments --- .../platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp | 11 +++++++---- examples/platform/silabs/efr32/rs911x/rsi_if.cpp | 5 +++-- examples/platform/silabs/efr32/wf200/host_if.cpp | 10 +++++----- examples/platform/silabs/wifi/wfx_rsi_host.cpp | 8 +++++--- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp index d562e72e8f..3f6badeb64 100644 --- a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp +++ b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp @@ -22,6 +22,7 @@ #include #include #include + #if (SL_MATTER_GN_BUILD == 0) #include "sl_matter_wifi_config.h" #endif // SL_MATTER_GN_BUILD @@ -42,7 +43,6 @@ #include #include #include -#include extern "C" { #include "sl_net.h" @@ -542,8 +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 = chip::min(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); + + cur_scan_result.ssid_length = strnlen((char *) scan_result->scan_info[idx].ssid, + chip::min(sizeof(scan_result->scan_info[idx].ssid), WFX_MAX_SSID_LENGTH)); + chip::Platform::CopyString(cur_scan_result.ssid, cur_scan_result.ssid_length + 1, (char *) scan_result->scan_info[idx].ssid); // +1 for null termination + // 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))) != @@ -601,7 +604,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; - memcpy((char *) &ssid_arg.value[0], wfx_rsi.sec.ssid, ssid_arg.length); + chip::Platform::CopyString((char *) &ssid_arg.value[0], ssid_arg.length + 1, wfx_rsi.sec.ssid); // +1 for null termination sl_wifi_set_scan_callback(scan_callback_handler, NULL); scan_results_complete = false; #ifndef EXP_BOARD diff --git a/examples/platform/silabs/efr32/rs911x/rsi_if.cpp b/examples/platform/silabs/efr32/rs911x/rsi_if.cpp index 3893e75d87..4a006de3e5 100644 --- a/examples/platform/silabs/efr32/rs911x/rsi_if.cpp +++ b/examples/platform/silabs/efr32/rs911x/rsi_if.cpp @@ -755,8 +755,9 @@ 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 = chip::min(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(scan->ssid)); + ap.ssid_length = + strnlen(reinterpret_cast(scan->ssid), chip::min(sizeof(scan->ssid), WFX_MAX_SSID_LENGTH)); + chip::Platform::CopyString(ap.ssid, ap.ssid_length + 1, reinterpret_cast(scan->ssid)); // +1 for null termination // check if the scanned ssid is the one we are looking for if (wfx_rsi.scan_ssid_length != 0 && strncmp(wfx_rsi.scan_ssid, ap.ssid, WFX_MAX_SSID_LENGTH) != CMP_SUCCESS) diff --git a/examples/platform/silabs/efr32/wf200/host_if.cpp b/examples/platform/silabs/efr32/wf200/host_if.cpp index 3699a943d4..aee184eceb 100644 --- a/examples/platform/silabs/efr32/wf200/host_if.cpp +++ b/examples/platform/silabs/efr32/wf200/host_if.cpp @@ -736,8 +736,8 @@ int32_t wfx_get_ap_info(wfx_wifi_scan_result_t * ap) { int32_t signal_strength; - ap->ssid_length = chip::min(strlen(ap_info.ssid) + 1, WFX_MAX_SSID_LENGTH); // +1 for null termination - chip::Platform::CopyString(ap->ssid, ap->ssid_length, ap_info.ssid); + ap->ssid_length = strnlen(ap_info.ssid, chip::min(sizeof(ap_info.ssid), WFX_MAX_SSID_LENGTH)); + chip::Platform::CopyString(ap->ssid, ap->ssid_length + 1, ap_info.ssid); // +1 for null termination memcpy(ap->bssid, ap_info.bssid, sizeof(ap_info.bssid)); ap->security = ap_info.security; ap->chan = ap_info.chan; @@ -1184,10 +1184,10 @@ bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *)) VerifyOrReturnError(scan_cb != nullptr, false); if (ssid) { - scan_ssid_length = chip::min(strnlen(ssid, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength) + 1, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength); // +1 for null termination - scan_ssid = reinterpret_cast(chip::Platform::MemoryAlloc(scan_ssid_length)); + scan_ssid_length = strnlen(ssid, chip::min(sizeof(ssid), WFX_MAX_SSID_LENGTH)); + scan_ssid = reinterpret_cast(chip::Platform::MemoryAlloc(scan_ssid_length + 1)); VerifyOrReturnError(scan_ssid != nullptr, false); - Platform::CopyString(scan_ssid, scan_ssid_length, ssid); + Platform::CopyString(scan_ssid, scan_ssid_length + 1, ssid); } scan_cb = callback; xEventGroupSetBits(sl_wfx_event_group, SL_WFX_SCAN_START); diff --git a/examples/platform/silabs/wifi/wfx_rsi_host.cpp b/examples/platform/silabs/wifi/wfx_rsi_host.cpp index b299b2fa4d..9e34c333c0 100644 --- a/examples/platform/silabs/wifi/wfx_rsi_host.cpp +++ b/examples/platform/silabs/wifi/wfx_rsi_host.cpp @@ -28,6 +28,7 @@ #include #include #include + #include "wfx_host_events.h" #include "wfx_rsi.h" @@ -368,10 +369,11 @@ bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *)) wfx_rsi.scan_cb = callback; // if SSID is provided to scan only that SSID if(ssid) { - wfx_rsi.scan_ssid_length = chip::min(strnlen(ssid, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength) + 1, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength); // +1 for null termination - wfx_rsi.scan_ssid = reinterpret_cast(chip::Platform::MemoryAlloc(wfx_rsi.scan_ssid_length)); + // wfx_rsi.scan_ssid_length = chip::min(strnlen(ssid, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength) + 1, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength); // +1 for null termination + wfx_rsi.scan_ssid_length = strnlen(ssid, chip::min(sizeof(ssid), WFX_MAX_SSID_LENGTH)); + wfx_rsi.scan_ssid = reinterpret_cast(chip::Platform::MemoryAlloc(wfx_rsi.scan_ssid_length + 1)); VerifyOrReturnError(wfx_rsi.scan_ssid != nullptr, false); - chip::Platform::CopyString(wfx_rsi.scan_ssid, wfx_rsi.scan_ssid_length, ssid); + chip::Platform::CopyString(wfx_rsi.scan_ssid, wfx_rsi.scan_ssid_length + 1, ssid); } WfxEvent_t event; event.eventType = WFX_EVT_SCAN; From 8d60acc51729ee69f478809180b42a8737c16bf2 Mon Sep 17 00:00:00 2001 From: chirag-silabs Date: Thu, 31 Oct 2024 10:11:25 +0530 Subject: [PATCH 06/10] removing the unused code --- examples/platform/silabs/wifi/wfx_rsi_host.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/platform/silabs/wifi/wfx_rsi_host.cpp b/examples/platform/silabs/wifi/wfx_rsi_host.cpp index 9e34c333c0..df64e915d4 100644 --- a/examples/platform/silabs/wifi/wfx_rsi_host.cpp +++ b/examples/platform/silabs/wifi/wfx_rsi_host.cpp @@ -369,7 +369,6 @@ bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *)) wfx_rsi.scan_cb = callback; // if SSID is provided to scan only that SSID if(ssid) { - // wfx_rsi.scan_ssid_length = chip::min(strnlen(ssid, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength) + 1, chip::DeviceLayer::Internal::kMaxWiFiSSIDLength); // +1 for null termination wfx_rsi.scan_ssid_length = strnlen(ssid, chip::min(sizeof(ssid), WFX_MAX_SSID_LENGTH)); wfx_rsi.scan_ssid = reinterpret_cast(chip::Platform::MemoryAlloc(wfx_rsi.scan_ssid_length + 1)); VerifyOrReturnError(wfx_rsi.scan_ssid != nullptr, false); From f159b884925bcd8d43263854a6069e22cfad4fc5 Mon Sep 17 00:00:00 2001 From: chirag-silabs <100861685+chirag-silabs@users.noreply.github.com> Date: Thu, 31 Oct 2024 20:45:25 +0530 Subject: [PATCH 07/10] Update examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp Co-authored-by: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> --- examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp index 3f6badeb64..3389f7802d 100644 --- a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp +++ b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp @@ -545,6 +545,7 @@ sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result) cur_scan_result.ssid_length = strnlen((char *) scan_result->scan_info[idx].ssid, chip::min(sizeof(scan_result->scan_info[idx].ssid), WFX_MAX_SSID_LENGTH)); + // cur_scan_result.ssid is of size WFX_MAX_SSID_LENGTH+1, we are safe with the cur_scan_result.ssid_length calculated above chip::Platform::CopyString(cur_scan_result.ssid, cur_scan_result.ssid_length + 1, (char *) scan_result->scan_info[idx].ssid); // +1 for null termination // if user has provided ssid, then check if the current scan result ssid matches the user provided ssid From 09515b065b19f05d5d2c63830c5ff06d84c641b9 Mon Sep 17 00:00:00 2001 From: chirag-silabs <100861685+chirag-silabs@users.noreply.github.com> Date: Thu, 31 Oct 2024 20:45:34 +0530 Subject: [PATCH 08/10] Update examples/platform/silabs/efr32/rs911x/rsi_if.cpp Co-authored-by: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> --- examples/platform/silabs/efr32/rs911x/rsi_if.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/platform/silabs/efr32/rs911x/rsi_if.cpp b/examples/platform/silabs/efr32/rs911x/rsi_if.cpp index 4a006de3e5..4510978329 100644 --- a/examples/platform/silabs/efr32/rs911x/rsi_if.cpp +++ b/examples/platform/silabs/efr32/rs911x/rsi_if.cpp @@ -757,6 +757,7 @@ void ProcessEvent(WfxEvent_t inEvent) memset(&ap, 0, sizeof(ap)); ap.ssid_length = strnlen(reinterpret_cast(scan->ssid), chip::min(sizeof(scan->ssid), WFX_MAX_SSID_LENGTH)); + // ap.ssid is of size WFX_MAX_SSID_LENGTH+1, we are safe with the ap.ssid_length calculated above chip::Platform::CopyString(ap.ssid, ap.ssid_length + 1, reinterpret_cast(scan->ssid)); // +1 for null termination // check if the scanned ssid is the one we are looking for From c3f71bf112843c4bb60419a45699828e8cd233da Mon Sep 17 00:00:00 2001 From: chirag-silabs <100861685+chirag-silabs@users.noreply.github.com> Date: Thu, 31 Oct 2024 20:45:41 +0530 Subject: [PATCH 09/10] Update examples/platform/silabs/efr32/wf200/host_if.cpp Co-authored-by: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> --- examples/platform/silabs/efr32/wf200/host_if.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/platform/silabs/efr32/wf200/host_if.cpp b/examples/platform/silabs/efr32/wf200/host_if.cpp index aee184eceb..f1686b0aa8 100644 --- a/examples/platform/silabs/efr32/wf200/host_if.cpp +++ b/examples/platform/silabs/efr32/wf200/host_if.cpp @@ -737,6 +737,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(sizeof(ap_info.ssid), WFX_MAX_SSID_LENGTH)); + // ap->ssid is of size WFX_MAX_SSID_LENGTH+1, we are safe with the ap->ssid_length calculated above chip::Platform::CopyString(ap->ssid, ap->ssid_length + 1, ap_info.ssid); // +1 for null termination memcpy(ap->bssid, ap_info.bssid, sizeof(ap_info.bssid)); ap->security = ap_info.security; From 5cf0d8e37c2acdc9da09b89f793eb9abe85aa370 Mon Sep 17 00:00:00 2001 From: chirag-silabs Date: Thu, 31 Oct 2024 22:32:59 +0530 Subject: [PATCH 10/10] Updating based on the suggestion --- examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp index 3389f7802d..47c9aa51cd 100644 --- a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp +++ b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp @@ -604,7 +604,7 @@ static void wfx_rsi_save_ap_info(void) // translation #endif sl_wifi_ssid_t ssid_arg; memset(&ssid_arg, 0, sizeof(ssid_arg)); - ssid_arg.length = wfx_rsi.sec.ssid_length; + ssid_arg.length = chip::min(wfx_rsi.sec.ssid_length, sizeof(ssid_arg.value) - 1); chip::Platform::CopyString((char *) &ssid_arg.value[0], ssid_arg.length + 1, wfx_rsi.sec.ssid); // +1 for null termination sl_wifi_set_scan_callback(scan_callback_handler, NULL); scan_results_complete = false;