@@ -36,14 +36,16 @@ typedef struct _wifi_scan_hdl {
36
36
37
37
#define MAX_SCAN_TIMEOUT (15000 )
38
38
39
+ static bool _inited = false ;
40
+
39
41
static rtw_result_t scan_result_handler ( rtw_scan_handler_result_t * malloced_scan_result )
40
42
{
41
43
wifi_scan_hdl *scan_handler = (wifi_scan_hdl *)malloced_scan_result->user_data ;
42
44
if (malloced_scan_result->scan_complete != RTW_TRUE) {
43
45
if (scan_handler->ap_details && scan_handler->scan_num > scan_handler->ap_num ){
44
- nsapi_wifi_ap_t ap;
46
+ nsapi_wifi_ap_t ap;
45
47
rtw_scan_result_t * record = &malloced_scan_result->ap_details ;
46
- record->SSID .val [record->SSID .len ] = 0 ; /* Ensure the SSID is null terminated */
48
+ record->SSID .val [record->SSID .len ] = 0 ; /* Ensure the SSID is null terminated */
47
49
memset ((void *)&ap, 0x00 , sizeof (nsapi_wifi_ap_t ));
48
50
memcpy (ap.ssid , record->SSID .val , record->SSID .len );
49
51
memcpy (ap.bssid , record->BSSID .octet , 6 );
@@ -88,7 +90,7 @@ RTWInterface::RTWInterface(bool debug)
88
90
{
89
91
emac_interface_t *emac;
90
92
int ret;
91
- extern u32 GlobalDebugEnable;
93
+ extern u32 GlobalDebugEnable;
92
94
93
95
GlobalDebugEnable = debug?1 :0 ;
94
96
emac = wlan_emac_init_interface ();
@@ -97,10 +99,13 @@ RTWInterface::RTWInterface(bool debug)
97
99
return ;
98
100
}
99
101
emac->ops .power_up (emac);
100
- ret = mbed_lwip_init (emac);
101
- if (ret != 0 ) {
102
- printf (" Error init RTWInterface!(%d)\r\n " , ret);
103
- return ;
102
+ if (_inited == false ) {
103
+ ret = mbed_lwip_init (emac);
104
+ if (ret != 0 ) {
105
+ printf (" Error init RTWInterface!(%d)\r\n " , ret);
106
+ return ;
107
+ }
108
+ _inited = true ;
104
109
}
105
110
}
106
111
@@ -177,7 +182,7 @@ nsapi_error_t RTWInterface::connect()
177
182
break ;
178
183
case NSAPI_SECURITY_NONE:
179
184
sec = RTW_SECURITY_OPEN;
180
- break ;
185
+ break ;
181
186
default :
182
187
return NSAPI_ERROR_PARAMETER;
183
188
}
@@ -186,7 +191,7 @@ nsapi_error_t RTWInterface::connect()
186
191
uint8_t pscan_config = PSCAN_ENABLE;
187
192
wifi_set_pscan_chan (&_channel, &pscan_config, 1 );
188
193
}
189
-
194
+
190
195
ret = wifi_connect (_ssid, sec, _pass, strlen (_ssid), strlen (_pass), 0 , (void *)NULL );
191
196
if (ret != RTW_SUCCESS) {
192
197
printf (" failed: %d\r\n " , ret);
@@ -237,7 +242,7 @@ int8_t RTWInterface::get_rssi()
237
242
}
238
243
239
244
nsapi_error_t RTWInterface::connect (const char *ssid, const char *pass,
240
- nsapi_security_t security, uint8_t channel)
245
+ nsapi_security_t security, uint8_t channel)
241
246
{
242
247
set_credentials (ssid, pass, security);
243
248
set_channel (channel);
@@ -249,9 +254,10 @@ nsapi_error_t RTWInterface::disconnect()
249
254
char essid[33 ];
250
255
251
256
wlan_emac_link_change (false );
257
+ mbed_lwip_bringdown ();
252
258
if (wifi_is_connected_to_ap () != RTW_SUCCESS)
253
259
return NSAPI_ERROR_NO_CONNECTION;
254
- if (wifi_disconnect ()<0 ){
260
+ if (wifi_disconnect ()<0 ){
255
261
return NSAPI_ERROR_DEVICE_ERROR;
256
262
}
257
263
while (1 ){
0 commit comments