28
28
#include " osdep_service.h"
29
29
30
30
typedef struct _wifi_scan_hdl {
31
- int scan_num;
31
+ void *scan_sema;
32
+ nsapi_size_t ap_num;
33
+ nsapi_size_t scan_num;
32
34
WiFiAccessPoint *ap_details;
33
35
} wifi_scan_hdl;
34
36
35
37
#define MAX_SCAN_TIMEOUT (15000 )
36
- static void *scan_sema = NULL ;
37
- static signed int ApNum = 0 ;
38
38
39
39
static rtw_result_t scan_result_handler ( rtw_scan_handler_result_t * malloced_scan_result )
40
40
{
41
+ wifi_scan_hdl *scan_handler = (wifi_scan_hdl *)malloced_scan_result->user_data ;
41
42
if (malloced_scan_result->scan_complete != RTW_TRUE) {
42
- wifi_scan_hdl *scan_handler = (wifi_scan_hdl *)malloced_scan_result->user_data ;
43
- if (scan_handler->ap_details && scan_handler->scan_num > ApNum){
43
+ if (scan_handler->ap_details && scan_handler->scan_num > scan_handler->ap_num ){
44
44
nsapi_wifi_ap_t ap;
45
45
rtw_scan_result_t * record = &malloced_scan_result->ap_details ;
46
46
record->SSID .val [record->SSID .len ] = 0 ; /* Ensure the SSID is null terminated */
@@ -74,13 +74,13 @@ static rtw_result_t scan_result_handler( rtw_scan_handler_result_t* malloced_sca
74
74
ap.rssi = record->signal_strength ;
75
75
ap.channel = record->channel ;
76
76
WiFiAccessPoint *accesspoint = new WiFiAccessPoint (ap);
77
- memcpy (&scan_handler->ap_details [ApNum ], accesspoint, sizeof (WiFiAccessPoint));
77
+ memcpy (&scan_handler->ap_details [scan_handler-> ap_num ], accesspoint, sizeof (WiFiAccessPoint));
78
78
delete[] accesspoint;
79
79
}
80
- ApNum ++;
80
+ scan_handler-> ap_num ++;
81
81
} else {
82
82
// scan done
83
- rtw_up_sema (&scan_sema);
83
+ rtw_up_sema (&scan_handler-> scan_sema );
84
84
}
85
85
return RTW_SUCCESS;
86
86
}
@@ -182,21 +182,21 @@ nsapi_error_t RTWInterface::connect()
182
182
nsapi_error_t RTWInterface::scan (WiFiAccessPoint *res, unsigned count)
183
183
{
184
184
static wifi_scan_hdl scan_handler;
185
- ApNum = 0 ;
186
- if (!scan_sema)
187
- rtw_init_sema (&scan_sema, 0 );
185
+ scan_handler. ap_num = 0 ;
186
+ if (!scan_handler. scan_sema )
187
+ rtw_init_sema (&scan_handler. scan_sema , 0 );
188
188
scan_handler.scan_num = count;
189
189
scan_handler.ap_details = res;
190
190
if (wifi_scan_networks (scan_result_handler, (void *)&scan_handler) != RTW_SUCCESS){
191
191
printf (" wifi scan failed\n\r " );
192
192
return NSAPI_ERROR_DEVICE_ERROR;
193
193
}
194
- if (rtw_down_timeout_sema ( &scan_sema, MAX_SCAN_TIMEOUT ) == RTW_FALSE) {
194
+ if (rtw_down_timeout_sema ( &scan_handler. scan_sema , MAX_SCAN_TIMEOUT ) == RTW_FALSE) {
195
195
printf (" wifi scan timeout\r\n " );
196
196
return NSAPI_ERROR_DEVICE_ERROR;
197
197
}
198
- if (count <= 0 || count > ApNum )
199
- count = ApNum ;
198
+ if (count <= 0 || count > scan_handler. ap_num )
199
+ count = scan_handler. ap_num ;
200
200
201
201
return count;
202
202
}
@@ -279,4 +279,4 @@ const char *RTWInterface::get_gateway()
279
279
NetworkStack *RTWInterface::get_stack ()
280
280
{
281
281
return nsapi_create_stack (&lwip_stack);
282
- }
282
+ }
0 commit comments