27
27
#include " scl_emac.h"
28
28
#include " scl_ipc.h"
29
29
#include " mbed_wait_api.h"
30
-
31
-
30
+ # include " SclAccessPoint.h "
31
+ # include " scl_buffer_api.h "
32
32
/* * @file
33
33
* Provides SCL interface functions to be used with WiFiInterface or NetworkInterface Objects
34
34
*/
@@ -43,8 +43,31 @@ struct scl_tx_net_credentials {
43
43
const char *network_passphrase;
44
44
} scl_tx_network_credentials;
45
45
46
+
47
+ struct scl_scan_userdata {
48
+ rtos::Semaphore *sema;
49
+ scan_result_type sres_type;
50
+ WiFiAccessPoint *aps;
51
+ std::vector<scl_scan_result_t > *result_buff;
52
+ unsigned count;
53
+ unsigned offset;
54
+ bool scan_in_progress;
55
+ };
56
+
57
+ static scl_scan_userdata interal_scan_data;
58
+ static scl_scan_result_t internal_scan_result;
46
59
network_params_t network_parameter;
47
60
61
+ /* Internal scan callback that handles the scan results */
62
+ void scl_scan_handler (scl_scan_result_t *result_ptr,void *user_data, scl_scan_status_t status);
63
+
64
+ #define CMP_MAC ( a, b ) (((((unsigned char *)a)[0 ])==(((unsigned char *)b)[0 ]))&& \
65
+ ((((unsigned char *)a)[1 ])==(((unsigned char *)b)[1 ]))&& \
66
+ ((((unsigned char *)a)[2 ])==(((unsigned char *)b)[2 ]))&& \
67
+ ((((unsigned char *)a)[3 ])==(((unsigned char *)b)[3 ]))&& \
68
+ ((((unsigned char *)a)[4 ])==(((unsigned char *)b)[4 ]))&& \
69
+ ((((unsigned char *)a)[5 ])==(((unsigned char *)b)[5 ])))
70
+
48
71
int scl_toerror (scl_result_t res)
49
72
{
50
73
switch (res) {
@@ -93,14 +116,22 @@ nsapi_security_t scl_tosecurity(scl_security_t sec)
93
116
case SCL_SECURITY_WEP_SHARED:
94
117
return NSAPI_SECURITY_WEP;
95
118
case SCL_SECURITY_WPA_TKIP_PSK:
119
+ case SCL_SECURITY_WPA_AES_PSK:
96
120
case SCL_SECURITY_WPA_TKIP_ENT:
121
+ case SCL_SECURITY_WPA_AES_ENT:
122
+ case SCL_SECURITY_WPA_MIXED_ENT:
97
123
return NSAPI_SECURITY_WPA;
98
124
case SCL_SECURITY_WPA2_MIXED_PSK:
125
+ case SCL_SECURITY_WPA2_WPA_PSK:
126
+ case SCL_SECURITY_WPA2_WPA_TKIP_PSK:
99
127
return NSAPI_SECURITY_WPA_WPA2;
128
+ case SCL_SECURITY_WPA2_MIXED_ENT:
129
+ return NSAPI_SECURITY_WPA2_ENT;
100
130
case SCL_SECURITY_WPA2_AES_PSK:
101
131
case SCL_SECURITY_WPA2_AES_ENT:
102
132
case SCL_SECURITY_WPA2_FBT_PSK:
103
133
case SCL_SECURITY_WPA2_FBT_ENT:
134
+ case SCL_SECURITY_WPA2_TKIP_ENT:
104
135
return NSAPI_SECURITY_WPA2;
105
136
default :
106
137
return NSAPI_SECURITY_UNKNOWN;
@@ -125,12 +156,13 @@ scl_security_t scl_fromsecurity(nsapi_security_t sec)
125
156
}
126
157
}
127
158
128
- SclSTAInterface::SclSTAInterface (SCL_EMAC &emac, OnboardNetworkStack &stack)
159
+ SclSTAInterface::SclSTAInterface (SCL_EMAC &emac, OnboardNetworkStack &stack, scl_interface_shared_info_t &shared )
129
160
: EMACInterface(emac, stack),
130
161
_ssid(" \0 " ),
131
162
_pass(" \0 " ),
132
163
_security(NSAPI_SECURITY_NONE),
133
- _scl_emac(emac)
164
+ _scl_emac(emac),
165
+ _iface_shared(shared)
134
166
{
135
167
}
136
168
@@ -180,7 +212,7 @@ nsapi_error_t SclSTAInterface::connect()
180
212
uint32_t connection_status = 0 ;
181
213
182
214
scl_tx_network_credentials.network_ssid = _ssid;
183
- if ((strlen (_ssid) < MAX_SSID_LENGTH) && (strlen (_ssid) > MIN_SSID_LENGTH)) {
215
+ if ((strlen (_ssid) < MAX_SSID_LENGTH) && (strlen (_ssid) > MIN_SSID_LENGTH) ) {
184
216
scl_tx_network_credentials.ssid_len = strlen (_ssid);
185
217
} else {
186
218
return NSAPI_ERROR_PARAMETER;
@@ -288,10 +320,106 @@ nsapi_error_t SclSTAInterface::disconnect()
288
320
return NSAPI_ERROR_OK;
289
321
}
290
322
291
- int SclSTAInterface::scan (WiFiAccessPoint *res, unsigned count)
323
+ void scl_scan_handler (scl_scan_result_t *result_ptr,
324
+ void *user_data, scl_scan_status_t status)
325
+ {
326
+ scl_scan_userdata *data = (scl_scan_userdata *)&interal_scan_data;
327
+ scl_scan_result_t *record = result_ptr;
328
+ unsigned int i;
329
+ nsapi_wifi_ap ap;
330
+ uint8_t length;
331
+
332
+ /* Even after stopping scan, some results will still come as results are already present in the queue */
333
+ if (data->scan_in_progress == false ) {
334
+ return ;
335
+ }
336
+
337
+ // finished scan, either succesfully or through an abort
338
+ if (status != SCL_SCAN_INCOMPLETE) {
339
+ data->scan_in_progress = false ;
340
+ data->sema ->release ();
341
+ return ;
342
+ }
343
+
344
+ // can't really keep anymore scan results
345
+ if (data->count > 0 && data->offset >= data->count ) {
346
+ /* We can not abort the scan as this function is getting executed in SCL context,
347
+ Note that to call any SCL API, caller function should not in SCL context */
348
+ return ;
349
+ }
350
+
351
+ for (i = 0 ; i < data->result_buff ->size (); i++) {
352
+ if (memcmp (((*data->result_buff )[i].BSSID .octet ),(record->BSSID .octet ),sizeof (scl_mac_t )) == 0 ) {
353
+ return ;
354
+ }
355
+ }
356
+
357
+ if (data->count > 0 && (data->aps != NULL )) {
358
+ // get ap stats
359
+ length = record->SSID .length ;
360
+ if (length < (sizeof (ap.ssid ) - 1 )) {
361
+ length = sizeof (ap.ssid ) - 1 ;
362
+ }
363
+ memcpy (ap.ssid , record->SSID .value , length);
364
+ ap.ssid [length] = ' \0 ' ;
365
+
366
+ memcpy (ap.bssid , record->BSSID .octet , sizeof (ap.bssid ));
367
+
368
+ ap.security = scl_tosecurity (record->security );
369
+ ap.rssi = record->signal_strength ;
370
+ ap.channel = record->channel ;
371
+ if (data->sres_type == SRES_TYPE_WIFI_ACCESS_POINT) {
372
+ data->aps [data->offset ] = WiFiAccessPoint (ap);
373
+ } else if (data->sres_type == SRES_TYPE_SCL_ACCESS_POINT) {
374
+ SclAccessPoint *aps_sres = static_cast <SclAccessPoint *>(data->aps );
375
+ aps_sres[data->offset ] = std::move (SclAccessPoint (ap, record->bss_type ,
376
+ record->ie_ptr , record->ie_len ));
377
+ }
378
+ }
379
+
380
+ // store to result_buff for future duplication removal
381
+ data->result_buff ->push_back (*record);
382
+ data->offset = data->result_buff ->size ();
383
+ }
384
+
385
+ int SclSTAInterface::internal_scan (WiFiAccessPoint *aps, unsigned count, scan_result_type sres_type)
386
+ {
387
+ ScopedMutexLock lock (_iface_shared.mutex );
388
+ scl_result_t scl_res;
389
+ int res;
390
+
391
+ // initialize wifi, this is noop if already init
392
+ if (!_scl_emac.powered_up ) {
393
+ if (!_scl_emac.power_up ()) {
394
+ return NSAPI_ERROR_DEVICE_ERROR;
395
+ }
396
+ }
397
+
398
+ interal_scan_data.sema = new Semaphore ();
399
+ interal_scan_data.sres_type = sres_type;
400
+ interal_scan_data.aps = aps;
401
+ interal_scan_data.count = count;
402
+ interal_scan_data.offset = 0 ;
403
+ interal_scan_data.scan_in_progress = true ;
404
+ interal_scan_data.result_buff = new std::vector<scl_scan_result_t >();
405
+
406
+ scl_res = (scl_result_t )scl_wifi_scan (SCL_SCAN_TYPE_ACTIVE, SCL_BSS_TYPE_ANY,
407
+ NULL , NULL , NULL , NULL , scl_scan_handler, &internal_scan_result, &interal_scan_data);
408
+ if (scl_res != SCL_SUCCESS) {
409
+ res = scl_toerror (scl_res);
410
+ } else {
411
+ /* This semaphore will be released in scan callback once the scan is completed */
412
+ interal_scan_data.sema ->acquire ();
413
+ res = interal_scan_data.offset ;
414
+ }
415
+ delete interal_scan_data.sema ;
416
+ delete interal_scan_data.result_buff ;
417
+ return res;
418
+ }
419
+
420
+ int SclSTAInterface::scan (WiFiAccessPoint *aps, unsigned count)
292
421
{
293
- /* To Do */
294
- return NSAPI_ERROR_UNSUPPORTED;
422
+ return internal_scan (aps, count, SRES_TYPE_WIFI_ACCESS_POINT);
295
423
}
296
424
297
425
int8_t SclSTAInterface::get_rssi ()
0 commit comments