@@ -46,6 +46,12 @@ struct whd_scan_userdata {
46
46
47
47
static whd_scan_userdata interal_scan_data;
48
48
static whd_scan_result_t internal_scan_result;
49
+ static uint16_t sta_link_update_entry = 0xFF ;
50
+ static const whd_event_num_t sta_link_change_events[] = {
51
+ WLC_E_SET_SSID, WLC_E_LINK, WLC_E_AUTH, WLC_E_ASSOC, WLC_E_DEAUTH_IND, WLC_E_DISASSOC_IND, WLC_E_DISASSOC,
52
+ WLC_E_REASSOC, WLC_E_PSK_SUP, WLC_E_ACTION_FRAME_COMPLETE, WLC_E_NONE
53
+ };
54
+
49
55
50
56
extern " C" void whd_emac_wifi_link_state_changed (whd_interface_t ifp, whd_bool_t state_up);
51
57
@@ -143,6 +149,30 @@ whd_security_t whd_fromsecurity(nsapi_security_t sec)
143
149
}
144
150
}
145
151
152
+ static void *whd_wifi_link_state_change_handler (whd_interface_t ifp,
153
+ const whd_event_header_t *event_header,
154
+ const uint8_t *event_data,
155
+ void *handler_user_data)
156
+ {
157
+ UNUSED_PARAMETER (event_data);
158
+
159
+ if (event_header->bsscfgidx >= WHD_INTERFACE_MAX) {
160
+ WPRINT_WHD_DEBUG ((" %s: event_header: Bad interface\n " , __FUNCTION__));
161
+ return NULL ;
162
+ }
163
+
164
+ if (event_header->event_type == WLC_E_DEAUTH_IND ||
165
+ event_header->event_type == WLC_E_DISASSOC_IND) {
166
+ whd_emac_wifi_link_state_changed (ifp, WHD_FALSE);
167
+ }
168
+
169
+ if (whd_wifi_is_ready_to_transceive (ifp) == WHD_SUCCESS) {
170
+ whd_emac_wifi_link_state_changed (ifp, WHD_TRUE);
171
+ }
172
+
173
+ return handler_user_data;
174
+ }
175
+
146
176
MBED_WEAK WhdSTAInterface::OlmInterface &WhdSTAInterface::OlmInterface::get_default_instance ()
147
177
{
148
178
static OlmInterface olm;
@@ -204,12 +234,19 @@ nsapi_error_t WhdSTAInterface::connect()
204
234
205
235
#define MAX_RETRY_COUNT ( 5 )
206
236
int i;
237
+ whd_result_t res;
207
238
208
239
// initialize wiced, this is noop if already init
209
240
if (!_whd_emac.powered_up ) {
210
241
_whd_emac.power_up ();
211
242
}
212
243
244
+ res = whd_management_set_event_handler (_whd_emac.ifp , sta_link_change_events,
245
+ whd_wifi_link_state_change_handler, NULL , &sta_link_update_entry);
246
+ if (res != WHD_SUCCESS) {
247
+ return whd_toerror (res);
248
+ }
249
+
213
250
if (!_interface) {
214
251
nsapi_error_t err = _stack.add_ethernet_interface (_emac, true , &_interface);
215
252
if (err != NSAPI_ERROR_OK) {
@@ -239,7 +276,6 @@ nsapi_error_t WhdSTAInterface::connect()
239
276
whd_security_t security = whd_fromsecurity (_security);
240
277
241
278
// join the network
242
- whd_result_t res;
243
279
for (i = 0 ; i < MAX_RETRY_COUNT; i++) {
244
280
res = (whd_result_t )whd_wifi_join (_whd_emac.ifp ,
245
281
&ssid,
@@ -290,6 +326,12 @@ nsapi_error_t WhdSTAInterface::disconnect()
290
326
if (res != WHD_SUCCESS) {
291
327
return whd_toerror (res);
292
328
}
329
+ whd_emac_wifi_link_state_changed (_whd_emac.ifp , WHD_FALSE);
330
+
331
+ res = whd_wifi_deregister_event_handler (_whd_emac.ifp , sta_link_update_entry);
332
+ if (res != WHD_SUCCESS) {
333
+ return whd_toerror (res);
334
+ }
293
335
294
336
// de-init Offload Manager
295
337
if (_olm != NULL ) {
0 commit comments