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

6 changes: 3 additions & 3 deletions examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,11 +545,11 @@ 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<size_t>(sizeof(scan_result->scan_info[idx].ssid), WFX_MAX_SSID_LENGTH));
chip::Platform::CopyString(cur_scan_result.ssid, cur_scan_result.ssid_length, (char *) scan_result->scan_info[idx].ssid);
chip::Platform::CopyString(cur_scan_result.ssid, cur_scan_result.ssid_length + 1, (char *) scan_result->scan_info[idx].ssid); // +1 for null termination
jmartinez-silabs marked this conversation as resolved.
Show resolved Hide resolved
chirag-silabs marked this conversation as resolved.
Show resolved Hide resolved

// 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 +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;
chirag-silabs marked this conversation as resolved.
Show resolved Hide resolved
chip::Platform::CopyString((char *) &ssid_arg.value[0], ssid_arg.length, wfx_rsi.sec.ssid);
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
Expand Down
2 changes: 1 addition & 1 deletion examples/platform/silabs/efr32/rs911x/rsi_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ void ProcessEvent(WfxEvent_t inEvent)
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));
chip::Platform::CopyString(ap.ssid, ap.ssid_length, reinterpret_cast<char *>(scan->ssid));
chip::Platform::CopyString(ap.ssid, ap.ssid_length + 1, reinterpret_cast<char *>(scan->ssid)); // +1 for null termination
chirag-silabs marked this conversation as resolved.
Show resolved Hide resolved

// 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)
Expand Down
8 changes: 4 additions & 4 deletions examples/platform/silabs/efr32/wf200/host_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +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<size_t>(sizeof(ap_info.ssid), WFX_MAX_SSID_LENGTH));
chip::Platform::CopyString(ap->ssid, ap->ssid_length, ap_info.ssid);
chip::Platform::CopyString(ap->ssid, ap->ssid_length + 1, ap_info.ssid); // +1 for null termination
chirag-silabs marked this conversation as resolved.
Show resolved Hide resolved
memcpy(ap->bssid, ap_info.bssid, sizeof(ap_info.bssid));
ap->security = ap_info.security;
ap->chan = ap_info.chan;
Expand Down Expand Up @@ -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 = strnlen(ssid, WFX_MAX_SSID_LENGTH);
scan_ssid = reinterpret_cast<char *>(chip::Platform::MemoryAlloc(scan_ssid_length));
scan_ssid_length = strnlen(ssid, chip::min<size_t>(sizeof(ssid), WFX_MAX_SSID_LENGTH));
scan_ssid = reinterpret_cast<char *>(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);
Expand Down
16 changes: 8 additions & 8 deletions examples/platform/silabs/wifi/wfx_rsi_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,15 +365,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 = 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 + 1));
VerifyOrReturnError(wfx_rsi.scan_ssid != nullptr, false);
chip::Platform::CopyString(wfx_rsi.scan_ssid, wfx_rsi.scan_ssid_length + 1, ssid);
}
WfxEvent_t event;
event.eventType = WFX_EVT_SCAN;
WfxPostEvent(&event);
Expand Down
Loading