Skip to content

Commit 555c7db

Browse files
authored
Merge pull request #13416 from dustin-crossman/pr/cysbsyskit_update_6.2.0
Update CYSBSYSKIT_01
2 parents b3c1922 + fbeae96 commit 555c7db

File tree

34 files changed

+1815
-1224
lines changed

34 files changed

+1815
-1224
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright 2018-2020 Cypress Semiconductor Corporation
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include <cstdlib>
19+
#include <utility>
20+
#include "SclAccessPoint.h"
21+
22+
SclAccessPoint::SclAccessPoint(nsapi_wifi_ap_t ap, scl_bss_type_t bss_type, uint8_t *ie_ptr, uint32_t ie_len) :
23+
WiFiAccessPoint(ap), _bss_type(bss_type)
24+
{
25+
_ie_ptr = (uint8_t *)malloc(ie_len * sizeof(uint8_t));
26+
if (_ie_ptr != NULL) {
27+
_ie_len = ie_len;
28+
memcpy(_ie_ptr, ie_ptr, ie_len);
29+
}
30+
}
31+
32+
SclAccessPoint &SclAccessPoint::operator=(SclAccessPoint &&rhs)
33+
{
34+
if (this != &rhs) {
35+
WiFiAccessPoint::operator=(rhs);
36+
_bss_type = rhs._bss_type;
37+
_ie_ptr = rhs._ie_ptr;
38+
_ie_len = rhs._ie_len;
39+
rhs._ie_ptr = NULL;
40+
rhs._ie_len = 0;
41+
}
42+
return *this;
43+
}
44+
45+
scl_bss_type_t SclAccessPoint::get_bss_type() const
46+
{
47+
return _bss_type;
48+
}
49+
50+
uint8_t *SclAccessPoint::get_ie_data() const
51+
{
52+
return _ie_ptr;
53+
}
54+
55+
uint32_t SclAccessPoint::get_ie_len() const
56+
{
57+
return _ie_len;
58+
}
59+
60+
SclAccessPoint::~SclAccessPoint()
61+
{
62+
if (_ie_ptr != NULL) {
63+
free(_ie_ptr);
64+
}
65+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright 2018-2020 Cypress Semiconductor Corporation
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef SCL_ACCESS_POINT_H
19+
#define SCL_ACCESS_POINT_H
20+
21+
#include "netsocket/WiFiAccessPoint.h"
22+
#include "scl_types.h"
23+
24+
/* Enum for scan result type */
25+
enum scan_result_type {
26+
SRES_TYPE_WIFI_ACCESS_POINT,
27+
SRES_TYPE_SCL_ACCESS_POINT
28+
};
29+
30+
/** SclAccessPoint class
31+
*
32+
* Class that represents a Scl Access Point
33+
* which contains additional Scl specific information
34+
*/
35+
class SclAccessPoint : public WiFiAccessPoint {
36+
public:
37+
SclAccessPoint() : WiFiAccessPoint() {};
38+
SclAccessPoint(nsapi_wifi_ap_t ap, scl_bss_type_t bss_type, uint8_t *ie_ptr, uint32_t ie_len);
39+
40+
/** Define move assignment and prevent copy-assignment
41+
*
42+
* Due to IE element data could have large memory footprint,
43+
* only move assignment is allowed.
44+
*/
45+
SclAccessPoint &operator=(SclAccessPoint &&rhs);
46+
SclAccessPoint &operator=(const SclAccessPoint &rhs) = delete;
47+
48+
/** Get SCL access point's bss type
49+
*
50+
* @return The scl_bss_type_t of the access point
51+
*/
52+
scl_bss_type_t get_bss_type() const;
53+
54+
/** Get SCL access point's IE data
55+
*
56+
* @return The pointer to ie data buffer
57+
*/
58+
uint8_t *get_ie_data() const;
59+
60+
/** Get SCL access point's IE length
61+
*
62+
* @return The ie data length
63+
*/
64+
uint32_t get_ie_len() const;
65+
66+
virtual ~SclAccessPoint();
67+
68+
private:
69+
scl_bss_type_t _bss_type;
70+
uint8_t *_ie_ptr; /**< Pointer to received Beacon/Probe Response IE(Information Element) */
71+
uint32_t _ie_len; /**< Length of IE(Information Element) */
72+
};
73+
74+
#endif

connectivity/drivers/emac/TARGET_Cypress/COMPONENT_SCL/interface/SclSTAInterface.cpp

Lines changed: 136 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
#include "scl_emac.h"
2828
#include "scl_ipc.h"
2929
#include "mbed_wait_api.h"
30-
31-
30+
#include "SclAccessPoint.h"
31+
#include "scl_buffer_api.h"
3232
/** @file
3333
* Provides SCL interface functions to be used with WiFiInterface or NetworkInterface Objects
3434
*/
@@ -43,8 +43,31 @@ struct scl_tx_net_credentials {
4343
const char *network_passphrase;
4444
} scl_tx_network_credentials;
4545

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;
4659
network_params_t network_parameter;
4760

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+
4871
int scl_toerror(scl_result_t res)
4972
{
5073
switch (res) {
@@ -93,14 +116,22 @@ nsapi_security_t scl_tosecurity(scl_security_t sec)
93116
case SCL_SECURITY_WEP_SHARED:
94117
return NSAPI_SECURITY_WEP;
95118
case SCL_SECURITY_WPA_TKIP_PSK:
119+
case SCL_SECURITY_WPA_AES_PSK:
96120
case SCL_SECURITY_WPA_TKIP_ENT:
121+
case SCL_SECURITY_WPA_AES_ENT:
122+
case SCL_SECURITY_WPA_MIXED_ENT:
97123
return NSAPI_SECURITY_WPA;
98124
case SCL_SECURITY_WPA2_MIXED_PSK:
125+
case SCL_SECURITY_WPA2_WPA_PSK:
126+
case SCL_SECURITY_WPA2_WPA_TKIP_PSK:
99127
return NSAPI_SECURITY_WPA_WPA2;
128+
case SCL_SECURITY_WPA2_MIXED_ENT:
129+
return NSAPI_SECURITY_WPA2_ENT;
100130
case SCL_SECURITY_WPA2_AES_PSK:
101131
case SCL_SECURITY_WPA2_AES_ENT:
102132
case SCL_SECURITY_WPA2_FBT_PSK:
103133
case SCL_SECURITY_WPA2_FBT_ENT:
134+
case SCL_SECURITY_WPA2_TKIP_ENT:
104135
return NSAPI_SECURITY_WPA2;
105136
default:
106137
return NSAPI_SECURITY_UNKNOWN;
@@ -125,12 +156,13 @@ scl_security_t scl_fromsecurity(nsapi_security_t sec)
125156
}
126157
}
127158

128-
SclSTAInterface::SclSTAInterface(SCL_EMAC &emac, OnboardNetworkStack &stack)
159+
SclSTAInterface::SclSTAInterface(SCL_EMAC &emac, OnboardNetworkStack &stack, scl_interface_shared_info_t &shared)
129160
: EMACInterface(emac, stack),
130161
_ssid("\0"),
131162
_pass("\0"),
132163
_security(NSAPI_SECURITY_NONE),
133-
_scl_emac(emac)
164+
_scl_emac(emac),
165+
_iface_shared(shared)
134166
{
135167
}
136168

@@ -180,7 +212,7 @@ nsapi_error_t SclSTAInterface::connect()
180212
uint32_t connection_status = 0;
181213

182214
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) ) {
184216
scl_tx_network_credentials.ssid_len = strlen(_ssid);
185217
} else {
186218
return NSAPI_ERROR_PARAMETER;
@@ -288,10 +320,106 @@ nsapi_error_t SclSTAInterface::disconnect()
288320
return NSAPI_ERROR_OK;
289321
}
290322

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)
292421
{
293-
/* To Do */
294-
return NSAPI_ERROR_UNSUPPORTED;
422+
return internal_scan(aps, count, SRES_TYPE_WIFI_ACCESS_POINT);
295423
}
296424

297425
int8_t SclSTAInterface::get_rssi()

connectivity/drivers/emac/TARGET_Cypress/COMPONENT_SCL/interface/SclSTAInterface.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include "scl_emac.h"
3030
#include "scl_wifi_api.h"
3131
#include "scl_types.h"
32+
#include "SclAccessPoint.h"
33+
#include "scl_interface.h"
3234
#define MAX_SSID_LENGTH (33) /**< Maximum ssid length */
3335
#define MAX_PASSWORD_LENGTH (64) /**< Maximum password length */
3436

@@ -40,7 +42,8 @@ class SclSTAInterface : public WiFiInterface, public EMACInterface {
4042

4143
SclSTAInterface(
4244
SCL_EMAC &emac = SCL_EMAC::get_instance(),
43-
OnboardNetworkStack &stack = OnboardNetworkStack::get_default_instance());
45+
OnboardNetworkStack &stack = OnboardNetworkStack::get_default_instance(),
46+
scl_interface_shared_info_t &shared = scl_iface_shared);
4447

4548
/** Gets the current instance of the SclSTAInterface
4649
*
@@ -127,11 +130,16 @@ class SclSTAInterface : public WiFiInterface, public EMACInterface {
127130
*/
128131
int8_t get_rssi();
129132

130-
/** Scans for available networks - NOT SUPPORTED
133+
/** Scan for available networks in WiFiAccessPoint format
131134
*
132-
* @return NSAPI_ERROR_UNSUPPORTED
135+
* This function will block.
136+
*
137+
* @param aps Pointer to allocated array of WiFiAccessPoint format for discovered AP
138+
* @param count Size of allocated @a res array, or 0 to only count available AP
139+
* @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error
140+
* see @a nsapi_error
133141
*/
134-
int scan(WiFiAccessPoint *res, unsigned count);
142+
int scan(WiFiAccessPoint *aps, unsigned count);
135143

136144
/** This function is used to indicate if the device is connected to the network.
137145
*
@@ -154,12 +162,15 @@ class SclSTAInterface : public WiFiInterface, public EMACInterface {
154162
* @return SCL_SUCCESS if the Wi-Fi interface is set up successfully.
155163
*/
156164
int wifi_set_up(void);
165+
protected:
166+
int internal_scan(WiFiAccessPoint *aps, unsigned count, scan_result_type sres_type);
157167

158168
private:
159169

160170
char _ssid[MAX_SSID_LENGTH]; /**< The longest possible name (defined in 802.11) +1 for the \0 */
161171
char _pass[MAX_PASSWORD_LENGTH]; /**< The longest allowed passphrase + 1 */
162172
nsapi_security_t _security; /**< Security type */
163173
SCL_EMAC &_scl_emac; /**< SCL_EMAC object */
174+
scl_interface_shared_info_t &_iface_shared;
164175
};
165176
#endif /* ifndef SCL_STA_INTERFACE_H */

0 commit comments

Comments
 (0)