|
54 | 54 | #include "wfx_host_events.h"
|
55 | 55 | #include "wfx_rsi.h"
|
56 | 56 |
|
| 57 | +// TODO convert this file to cpp and use CodeUtils.h |
| 58 | +#ifndef MIN |
| 59 | +#define MIN(a, b) ((a) < (b) ? (a) : (b)) |
| 60 | +#endif |
| 61 | + |
57 | 62 | /* Rsi driver Task will use as its stack */
|
58 | 63 | StackType_t driverRsiTaskStack[WFX_RSI_WLAN_TASK_SZ] = { 0 };
|
59 | 64 |
|
@@ -691,50 +696,40 @@ void wfx_rsi_task(void * arg)
|
691 | 696 | {
|
692 | 697 | if (!(wfx_rsi.dev_state & WFX_RSI_ST_SCANSTARTED))
|
693 | 698 | {
|
694 |
| - SILABS_LOG("%s: start SSID scan", __func__); |
695 |
| - int x; |
696 |
| - wfx_wifi_scan_result_t ap; |
697 |
| - rsi_scan_info_t * scan; |
698 |
| - int32_t status; |
699 |
| - uint8_t bgscan_results[BG_SCAN_RES_SIZE] = { 0 }; |
700 |
| - status = rsi_wlan_bgscan_profile(1, (rsi_rsp_scan_t *) bgscan_results, BG_SCAN_RES_SIZE); |
701 |
| - |
702 |
| - SILABS_LOG("%s: status: %02x size = %d", __func__, status, BG_SCAN_RES_SIZE); |
703 |
| - rsi_rsp_scan_t * rsp = (rsi_rsp_scan_t *) bgscan_results; |
| 699 | + rsi_rsp_scan_t scan_rsp = { 0 }; |
| 700 | + int32_t status = rsi_wlan_bgscan_profile(1, &scan_rsp, sizeof(scan_rsp)); |
| 701 | + |
704 | 702 | if (status)
|
705 | 703 | {
|
706 |
| - /* |
707 |
| - * Scan is done - failed |
708 |
| - */ |
| 704 | + SILABS_LOG("SSID scan failed: %02x ", status); |
709 | 705 | }
|
710 | 706 | else
|
711 |
| - for (x = 0; x < rsp->scan_count[0]; x++) |
| 707 | + { |
| 708 | + rsi_scan_info_t * scan; |
| 709 | + wfx_wifi_scan_result_t ap; |
| 710 | + for (int x = 0; x < scan_rsp.scan_count[0]; x++) |
712 | 711 | {
|
713 |
| - scan = &rsp->scan_info[x]; |
714 |
| - strcpy(&ap.ssid[0], (char *) &scan->ssid[0]); |
715 |
| - if (wfx_rsi.scan_ssid) |
| 712 | + scan = &scan_rsp.scan_info[x]; |
| 713 | + // is it a scan all or target scan |
| 714 | + if (!wfx_rsi.scan_ssid || |
| 715 | + (wfx_rsi.scan_ssid && strcmp(wfx_rsi.scan_ssid, (char *) scan->ssid) == CMP_SUCCESS)) |
716 | 716 | {
|
717 |
| - SILABS_LOG("Inside scan_ssid"); |
718 |
| - SILABS_LOG("SCAN SSID: %s , ap scan: %s", wfx_rsi.scan_ssid, ap.ssid); |
719 |
| - if (strcmp(wfx_rsi.scan_ssid, ap.ssid) == CMP_SUCCESS) |
720 |
| - { |
721 |
| - SILABS_LOG("Inside ap details"); |
722 |
| - ap.security = scan->security_mode; |
723 |
| - ap.rssi = (-1) * scan->rssi_val; |
724 |
| - memcpy(&ap.bssid[0], &scan->bssid[0], BSSID_MAX_STR_LEN); |
725 |
| - (*wfx_rsi.scan_cb)(&ap); |
726 |
| - } |
727 |
| - } |
728 |
| - else |
729 |
| - { |
730 |
| - SILABS_LOG("Inside else"); |
| 717 | + strncpy(ap.ssid, (char *) scan->ssid, MIN(sizeof(ap.ssid), sizeof(scan->ssid))); |
731 | 718 | ap.security = scan->security_mode;
|
732 | 719 | ap.rssi = (-1) * scan->rssi_val;
|
733 |
| - ap.chan = scan->rf_channel; |
734 |
| - memcpy(&ap.bssid[0], &scan->bssid[0], BSSID_MAX_STR_LEN); |
| 720 | + configASSERT(sizeof(ap.bssid) >= BSSID_MAX_STR_LEN); |
| 721 | + configASSERT(sizeof(scan->bssid) >= BSSID_MAX_STR_LEN); |
| 722 | + memcpy(ap.bssid, scan->bssid, BSSID_MAX_STR_LEN); |
735 | 723 | (*wfx_rsi.scan_cb)(&ap);
|
| 724 | + |
| 725 | + if (wfx_rsi.scan_ssid) |
| 726 | + { |
| 727 | + break; // we found the targeted ssid. |
| 728 | + } |
736 | 729 | }
|
737 | 730 | }
|
| 731 | + } |
| 732 | + |
738 | 733 | wfx_rsi.dev_state &= ~WFX_RSI_ST_SCANSTARTED;
|
739 | 734 | /* Terminate with end of scan which is no ap sent back */
|
740 | 735 | (*wfx_rsi.scan_cb)((wfx_wifi_scan_result_t *) 0);
|
|
0 commit comments