Skip to content

Commit

Permalink
Added changes for scan failure
Browse files Browse the repository at this point in the history
  • Loading branch information
shgutte committed Oct 31, 2023
1 parent bde950a commit ff46fa7
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ bool is_wifi_disconnection_event = false;

/* Declare a variable to hold connection time intervals */
uint32_t retryInterval = WLAN_MIN_RETRY_TIMER_MS;
volatile bool scan_results_complete = false;
volatile bool bg_scan_results_complete = false;
#define WIFI_SCAN_TIMEOUT_TICK 10000

extern osSemaphoreId_t sl_rs_ble_init_sem;
osSemaphoreId_t sl_scan_results_sem;
osSemaphoreId_t sl_bg_scan_results_sem;

/*
* This file implements the interface to the wifi sdk
Expand Down Expand Up @@ -295,12 +296,12 @@ sl_status_t scan_callback_handler(sl_wifi_event_t event, sl_wifi_scan_result_t *
if (CHECK_IF_EVENT_FAILED(event))
{
callback_status = *(sl_status_t *) scan_result;
scan_results_complete = true;
#if WIFI_ENABLE_SECURITY_WPA3_TRANSITION
wfx_rsi.sec.security = WFX_SEC_WPA3;
#else
wfx_rsi.sec.security = WFX_SEC_WPA2;
#endif /* WIFI_ENABLE_SECURITY_WPA3_TRANSITION */
osSemaphoreRelease(sl_scan_results_sem);
return SL_STATUS_FAIL;
}
wfx_rsi.sec.security = WFX_SEC_UNSPECIFIED;
Expand Down Expand Up @@ -336,7 +337,7 @@ sl_status_t scan_callback_handler(sl_wifi_event_t event, sl_wifi_scan_result_t *
break;
}
wfx_rsi.dev_state &= ~WFX_RSI_ST_SCANSTARTED;
scan_results_complete = true;
osSemaphoreRelease(sl_scan_results_sem);
return SL_STATUS_OK;
}
sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result)
Expand Down Expand Up @@ -380,7 +381,7 @@ sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result)
sl_status_t bg_scan_callback_handler(sl_wifi_event_t event, sl_wifi_scan_result_t * result, uint32_t result_length, void * arg)
{
callback_status = show_scan_results(result);
bg_scan_results_complete = true;
osSemaphoreRelease(sl_bg_scan_results_sem);
return SL_STATUS_OK;
}
/***************************************************************************************
Expand All @@ -405,16 +406,19 @@ static void wfx_rsi_save_ap_info() // translation
ssid_arg.length = strlen(wfx_rsi.sec.ssid);
memcpy(ssid_arg.value, (int8_t *) &wfx_rsi.sec.ssid[0], ssid_arg.length);
sl_wifi_set_scan_callback(scan_callback_handler, NULL);
scan_results_complete = false;
status = sl_wifi_start_scan(SL_WIFI_CLIENT_2_4GHZ_INTERFACE, &ssid_arg, &wifi_scan_configuration);
if (SL_STATUS_IN_PROGRESS == status)
{
const uint32_t start = osKernelGetTickCount();
while (!scan_results_complete && (osKernelGetTickCount() - start) <= WIFI_SCAN_TIMEOUT_TICK)
//! This semaphore is waiting for scan result.
osStatus_t callback_sem_status = osSemaphoreAcquire(sl_scan_results_sem, WIFI_SCAN_TIMEOUT_TICK);
if (callback_sem_status == osOK )
{
osThreadYield();
status = callback_status;
}
else
{
status = SL_STATUS_TIMEOUT;
}
status = scan_results_complete ? callback_status : SL_STATUS_TIMEOUT;
}
}

Expand Down Expand Up @@ -691,17 +695,19 @@ void wfx_rsi_task(void * arg)
}
sl_wifi_set_scan_callback(bg_scan_callback_handler, NULL);
wfx_rsi.dev_state |= WFX_RSI_ST_SCANSTARTED;
bg_scan_results_complete = false;
status = sl_wifi_start_scan(SL_WIFI_CLIENT_2_4GHZ_INTERFACE, NULL, &wifi_scan_configuration);
if (SL_STATUS_IN_PROGRESS == status)
{
printf("Scanning...\r\n");
const uint32_t start = osKernelGetTickCount();
while (!bg_scan_results_complete && (osKernelGetTickCount() - start) <= WIFI_SCAN_TIMEOUT_TICK)
//! This semaphore is waiting for bg scan result.
osStatus_t callback_sem_status = osSemaphoreAcquire(sl_bg_scan_results_sem, WIFI_SCAN_TIMEOUT_TICK);
if (callback_sem_status == osOK )
{
status = callback_status;
}
else
{
osThreadYield();
status = SL_STATUS_TIMEOUT;
}
status = bg_scan_results_complete ? callback_status : SL_STATUS_TIMEOUT;
}
}
}
Expand Down

0 comments on commit ff46fa7

Please sign in to comment.