Skip to content

Commit 7b16166

Browse files
committed
Allow WhdAccessPoint scan result with extended parameters
- Add WhdAccessPoint to include additional WHD scan info - To save memory, only move assignment is supported for WhdAccessPoint - Add scan_whd to scan for WhdAccessPoint - Set set_blocking(false) to unsupported by return NSAPI_ERROR_UNSUPPORTED
1 parent 1798c24 commit 7b16166

File tree

5 files changed

+210
-9
lines changed

5 files changed

+210
-9
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* WHD Access Point Interface Implementation
2+
* Copyright (c) 2018-2019 ARM Limited
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 "WhdAccessPoint.h"
21+
22+
WhdAccessPoint::WhdAccessPoint(nsapi_wifi_ap_t ap, whd_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 * sizeof(uint8_t));
29+
}
30+
}
31+
32+
WhdAccessPoint &WhdAccessPoint::operator=(WhdAccessPoint &&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+
whd_bss_type_t WhdAccessPoint::get_bss_type() const
46+
{
47+
return _bss_type;
48+
}
49+
50+
uint8_t *WhdAccessPoint::get_ie_data() const
51+
{
52+
return _ie_ptr;
53+
}
54+
55+
uint32_t WhdAccessPoint::get_ie_len() const
56+
{
57+
return _ie_len;
58+
}
59+
60+
WhdAccessPoint::~WhdAccessPoint()
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+
/* WHD Access Point Interface
2+
* Copyright (c) 2017-2019 ARM Limited
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 WHD_ACCESS_POINT_H
19+
#define WHD_ACCESS_POINT_H
20+
21+
#include "netsocket/WiFiAccessPoint.h"
22+
#include "whd_types.h"
23+
24+
/* Enum for scan result type */
25+
enum scan_result_type {
26+
SRES_TYPE_WIFI_ACCESS_POINT,
27+
SRES_TYPE_WHD_ACCESS_POINT
28+
};
29+
30+
/** WhdAccessPoint class
31+
*
32+
* Class that represents a Whd Access Point
33+
* which contains additional Whd specific information
34+
*/
35+
class WhdAccessPoint : public WiFiAccessPoint {
36+
public:
37+
WhdAccessPoint() : WiFiAccessPoint() {};
38+
WhdAccessPoint(nsapi_wifi_ap_t ap, whd_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+
WhdAccessPoint &operator=(WhdAccessPoint &&rhs);
46+
WhdAccessPoint &operator=(const WhdAccessPoint &rhs) = delete;
47+
48+
/** Get WHD access point's bss type
49+
*
50+
* @return The whd_bss_type_t of the access point
51+
*/
52+
whd_bss_type_t get_bss_type() const;
53+
54+
/** Get WHD 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 WHD access point's IE length
61+
*
62+
* @return The ie data length
63+
*/
64+
uint32_t get_ie_len() const;
65+
66+
virtual ~WhdAccessPoint();
67+
68+
private:
69+
whd_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

features/netsocket/emac-drivers/TARGET_WHD/interface/WhdSTAInterface.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
struct whd_scan_userdata {
3939
rtos::Semaphore *sema;
40+
scan_result_type sres_type;
4041
WiFiAccessPoint *aps;
4142
std::vector<whd_scan_result_t> *result_buff;
4243
unsigned count;
@@ -173,6 +174,7 @@ static void *whd_wifi_link_state_change_handler(whd_interface_t ifp,
173174
return handler_user_data;
174175
}
175176

177+
176178
MBED_WEAK WhdSTAInterface::OlmInterface &WhdSTAInterface::OlmInterface::get_default_instance()
177179
{
178180
static OlmInterface olm;
@@ -395,7 +397,6 @@ static void whd_scan_handler(whd_scan_result_t **result_ptr,
395397
if (data->count > 0 && data->aps != NULL) {
396398
// get ap stats
397399
nsapi_wifi_ap ap;
398-
399400
uint8_t length = record->SSID.length;
400401
if (length < sizeof(ap.ssid) - 1) {
401402
length = sizeof(ap.ssid) - 1;
@@ -408,24 +409,29 @@ static void whd_scan_handler(whd_scan_result_t **result_ptr,
408409
ap.security = whd_tosecurity(record->security);
409410
ap.rssi = record->signal_strength;
410411
ap.channel = record->channel;
411-
data->aps[data->offset] = WiFiAccessPoint(ap);
412+
if (data->sres_type == SRES_TYPE_WIFI_ACCESS_POINT) {
413+
data->aps[data->offset] = WiFiAccessPoint(ap);
414+
} else if (data->sres_type == SRES_TYPE_WHD_ACCESS_POINT) {
415+
WhdAccessPoint *aps_sres = static_cast<WhdAccessPoint *>(data->aps);
416+
aps_sres[data->offset] = std::move(WhdAccessPoint(ap, record->bss_type,
417+
record->ie_ptr, record->ie_len));
418+
}
412419
}
413420

414421
// store to result_buff for future duplication removal
415422
data->result_buff->push_back(*record);
416423
data->offset = data->result_buff->size();
417-
418424
}
419425

420-
421-
int WhdSTAInterface::scan(WiFiAccessPoint *aps, unsigned count)
426+
int WhdSTAInterface::internal_scan(WiFiAccessPoint *aps, unsigned count, scan_result_type sres_type)
422427
{
423428
// initialize wiced, this is noop if already init
424429
if (!_whd_emac.powered_up) {
425430
_whd_emac.power_up();
426431
}
427432

428433
interal_scan_data.sema = new Semaphore();
434+
interal_scan_data.sres_type = sres_type;
429435
interal_scan_data.aps = aps;
430436
interal_scan_data.count = count;
431437
interal_scan_data.offset = 0;
@@ -449,6 +455,16 @@ int WhdSTAInterface::scan(WiFiAccessPoint *aps, unsigned count)
449455
return res;
450456
}
451457

458+
int WhdSTAInterface::scan(WiFiAccessPoint *aps, unsigned count)
459+
{
460+
return internal_scan(aps, count, SRES_TYPE_WIFI_ACCESS_POINT);
461+
}
462+
463+
int WhdSTAInterface::scan_whd(WhdAccessPoint *aps, unsigned count)
464+
{
465+
return internal_scan(aps, count, SRES_TYPE_WHD_ACCESS_POINT);
466+
}
467+
452468
int WhdSTAInterface::is_interface_connected(void)
453469
{
454470
if (!_whd_emac.ifp) {

features/netsocket/emac-drivers/TARGET_WHD/interface/WhdSTAInterface.h

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "netsocket/WiFiInterface.h"
2222
#include "netsocket/EMACInterface.h"
2323
#include "netsocket/OnboardNetworkStack.h"
24+
#include "WhdAccessPoint.h"
2425
#include "whd_emac.h"
2526
#include "whd_types_int.h"
2627

@@ -31,7 +32,6 @@ struct ol_desc;
3132
*/
3233
class WhdSTAInterface : public WiFiInterface, public EMACInterface {
3334
public:
34-
3535
class OlmInterface {
3636
public:
3737
/** Get the default OLM interface. */
@@ -117,24 +117,52 @@ class WhdSTAInterface : public WiFiInterface, public EMACInterface {
117117
return 0;
118118
}
119119

120+
/** Set blocking status of interface.
121+
* Nonblocking mode unsupported.
122+
*
123+
* @param blocking true if connect is blocking
124+
* @return 0 on success, negative error code on failure
125+
*/
126+
nsapi_error_t set_blocking(bool blocking)
127+
{
128+
if (blocking) {
129+
_blocking = blocking;
130+
return NSAPI_ERROR_OK;
131+
} else {
132+
return NSAPI_ERROR_UNSUPPORTED;
133+
}
134+
}
135+
120136
/** Gets the current radio signal strength for active connection
121137
*
122138
* @return Connection strength in dBm (negative value)
123139
*/
124140
int8_t get_rssi();
125141

126-
/** Scan for available networks
142+
/** Scan for available networks in WiFiAccessPoint format
127143
*
128144
* This function will block.
129145
*
130-
* @param ap Pointer to allocated array to store discovered AP
146+
* @param ap Pointer to allocated array of WiFiAccessPoint format for discovered AP
131147
* @param count Size of allocated @a res array, or 0 to only count available AP
132148
* @param timeout Timeout in milliseconds; 0 for no timeout (Default: 0)
133149
* @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error
134150
* see @a nsapi_error
135151
*/
136152
int scan(WiFiAccessPoint *res, unsigned count);
137153

154+
/** Scan for available networks in WhdAccessPoint format
155+
*
156+
* This function will block.
157+
*
158+
* @param ap Pointer to allocated array of WhdAccessPoint format for discovered AP
159+
* @param count Size of allocated @a res array, or 0 to only count available AP
160+
* @param timeout Timeout in milliseconds; 0 for no timeout (Default: 0)
161+
* @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error
162+
* see @a nsapi_error
163+
*/
164+
int scan_whd(WhdAccessPoint *res, unsigned count);
165+
138166
/* is interface connected, if yes return WICED_SUCCESS else WICED_NOT_CONNECTED */
139167
int is_interface_connected();
140168

@@ -208,8 +236,11 @@ class WhdSTAInterface : public WiFiInterface, public EMACInterface {
208236
int ret = _olm->wake();
209237
return ret;
210238
}
211-
private:
212239

240+
protected:
241+
int internal_scan(WiFiAccessPoint *aps, unsigned count, scan_result_type sres_type);
242+
243+
private:
213244
char _ssid[33]; /* The longest possible name (defined in 802.11) +1 for the \0 */
214245
char _pass[64]; /* The longest allowed passphrase + 1 */
215246
nsapi_security_t _security;

features/netsocket/emac-drivers/TARGET_WHD/interface/WhdSoftAPInterface.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,21 @@ class WhdSoftAPInterface : public EMACInterface {
131131
*/
132132
int unregister_event_handler(void);
133133

134+
/** Set blocking status of interface.
135+
* Nonblocking mode unsupported.
136+
*
137+
* @param blocking true if connect is blocking
138+
* @return 0 on success, negative error code on failure
139+
*/
140+
nsapi_error_t set_blocking(bool blocking)
141+
{
142+
if (blocking) {
143+
_blocking = blocking;
144+
return NSAPI_ERROR_OK;
145+
} else {
146+
return NSAPI_ERROR_UNSUPPORTED;
147+
}
148+
}
134149

135150
protected:
136151
WHD_EMAC &_whd_emac;

0 commit comments

Comments
 (0)