Merge pull request #11356 from kyle-cypress/pr/whd-link-state-fix

Fix WHD link state change event handling
pull/11382/head
Martin Kojtal 2019-08-30 07:44:40 +02:00 committed by GitHub
commit c99b150bcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 4 deletions

View File

@ -46,6 +46,12 @@ struct whd_scan_userdata {
static whd_scan_userdata interal_scan_data; static whd_scan_userdata interal_scan_data;
static whd_scan_result_t internal_scan_result; static whd_scan_result_t internal_scan_result;
static uint16_t sta_link_update_entry = 0xFF;
static const whd_event_num_t sta_link_change_events[] = {
WLC_E_SET_SSID, WLC_E_LINK, WLC_E_AUTH, WLC_E_ASSOC, WLC_E_DEAUTH_IND, WLC_E_DISASSOC_IND, WLC_E_DISASSOC,
WLC_E_REASSOC, WLC_E_PSK_SUP, WLC_E_ACTION_FRAME_COMPLETE, WLC_E_NONE
};
extern "C" void whd_emac_wifi_link_state_changed(whd_interface_t ifp, whd_bool_t state_up); extern "C" void whd_emac_wifi_link_state_changed(whd_interface_t ifp, whd_bool_t state_up);
@ -143,6 +149,30 @@ whd_security_t whd_fromsecurity(nsapi_security_t sec)
} }
} }
static void *whd_wifi_link_state_change_handler(whd_interface_t ifp,
const whd_event_header_t *event_header,
const uint8_t *event_data,
void *handler_user_data)
{
UNUSED_PARAMETER(event_data);
if (event_header->bsscfgidx >= WHD_INTERFACE_MAX) {
WPRINT_WHD_DEBUG(("%s: event_header: Bad interface\n", __FUNCTION__));
return NULL;
}
if (event_header->event_type == WLC_E_DEAUTH_IND ||
event_header->event_type == WLC_E_DISASSOC_IND) {
whd_emac_wifi_link_state_changed(ifp, WHD_FALSE);
}
if (whd_wifi_is_ready_to_transceive(ifp) == WHD_SUCCESS) {
whd_emac_wifi_link_state_changed(ifp, WHD_TRUE);
}
return handler_user_data;
}
MBED_WEAK WhdSTAInterface::OlmInterface &WhdSTAInterface::OlmInterface::get_default_instance() MBED_WEAK WhdSTAInterface::OlmInterface &WhdSTAInterface::OlmInterface::get_default_instance()
{ {
static OlmInterface olm; static OlmInterface olm;
@ -204,12 +234,19 @@ nsapi_error_t WhdSTAInterface::connect()
#define MAX_RETRY_COUNT ( 5 ) #define MAX_RETRY_COUNT ( 5 )
int i; int i;
whd_result_t res;
// initialize wiced, this is noop if already init // initialize wiced, this is noop if already init
if (!_whd_emac.powered_up) { if (!_whd_emac.powered_up) {
_whd_emac.power_up(); _whd_emac.power_up();
} }
res = whd_management_set_event_handler(_whd_emac.ifp, sta_link_change_events,
whd_wifi_link_state_change_handler, NULL, &sta_link_update_entry);
if (res != WHD_SUCCESS) {
return whd_toerror(res);
}
if (!_interface) { if (!_interface) {
nsapi_error_t err = _stack.add_ethernet_interface(_emac, true, &_interface); nsapi_error_t err = _stack.add_ethernet_interface(_emac, true, &_interface);
if (err != NSAPI_ERROR_OK) { if (err != NSAPI_ERROR_OK) {
@ -239,7 +276,6 @@ nsapi_error_t WhdSTAInterface::connect()
whd_security_t security = whd_fromsecurity(_security); whd_security_t security = whd_fromsecurity(_security);
// join the network // join the network
whd_result_t res;
for (i = 0; i < MAX_RETRY_COUNT; i++) { for (i = 0; i < MAX_RETRY_COUNT; i++) {
res = (whd_result_t)whd_wifi_join(_whd_emac.ifp, res = (whd_result_t)whd_wifi_join(_whd_emac.ifp,
&ssid, &ssid,
@ -290,6 +326,12 @@ nsapi_error_t WhdSTAInterface::disconnect()
if (res != WHD_SUCCESS) { if (res != WHD_SUCCESS) {
return whd_toerror(res); return whd_toerror(res);
} }
whd_emac_wifi_link_state_changed(_whd_emac.ifp, WHD_FALSE);
res = whd_wifi_deregister_event_handler(_whd_emac.ifp, sta_link_update_entry);
if (res != WHD_SUCCESS) {
return whd_toerror(res);
}
// de-init Offload Manager // de-init Offload Manager
if (_olm != NULL) { if (_olm != NULL) {

View File

@ -115,7 +115,6 @@ bool WHD_EMAC::power_up()
if (CY_RSLT_SUCCESS == res) { if (CY_RSLT_SUCCESS == res) {
drvp = cybsp_get_wifi_driver(); drvp = cybsp_get_wifi_driver();
powered_up = true; powered_up = true;
ifp->whd_link_update_callback = whd_emac_wifi_link_state_changed;
if (link_state && emac_link_state_cb) { if (link_state && emac_link_state_cb) {
emac_link_state_cb(link_state); emac_link_state_cb(link_state);
} }
@ -291,5 +290,3 @@ extern "C"
} }
} // extern "C" } // extern "C"