Skip to content

Commit e64fdba

Browse files
author
Kyle Kearney
committed
Update BSP and WifiInterface for WHD Changes
1 parent 5d819eb commit e64fdba

File tree

8 files changed

+213
-177
lines changed

8 files changed

+213
-177
lines changed

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

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,18 @@
3636
((((unsigned char*)a)[5])==(((unsigned char*)b)[5])))
3737

3838
struct whd_scan_userdata {
39-
Semaphore *sema;
39+
rtos::Semaphore *sema;
4040
WiFiAccessPoint *aps;
4141
std::vector<whd_scan_result_t> *result_buff;
4242
unsigned count;
4343
unsigned offset;
44-
whd_interface_t ifp;
4544
bool scan_in_progress;
4645
};
4746

4847
static whd_scan_userdata interal_scan_data;
4948
static whd_scan_result_t internal_scan_result;
5049

51-
extern "C" void whd_emac_wifi_link_state_changed(bool state_up, whd_interface_t ifp);
50+
extern "C" void whd_emac_wifi_link_state_changed(whd_interface_t ifp, whd_bool_t state_up);
5251

5352

5453
int whd_toerror(whd_result_t res)
@@ -182,8 +181,8 @@ nsapi_error_t WhdSTAInterface::set_credentials(const char *ssid, const char *pas
182181
{
183182
if ((ssid == NULL) ||
184183
(strlen(ssid) == 0) ||
185-
(pass == NULL && ( security != NSAPI_SECURITY_NONE && security != NSAPI_SECURITY_WPA2_ENT)) ||
186-
(strlen(pass) == 0 && ( security != NSAPI_SECURITY_NONE && security != NSAPI_SECURITY_WPA2_ENT)) ||
184+
(pass == NULL && (security != NSAPI_SECURITY_NONE && security != NSAPI_SECURITY_WPA2_ENT)) ||
185+
(strlen(pass) == 0 && (security != NSAPI_SECURITY_NONE && security != NSAPI_SECURITY_WPA2_ENT)) ||
187186
(strlen(pass) > 63 && (security == NSAPI_SECURITY_WPA2 || security == NSAPI_SECURITY_WPA || security == NSAPI_SECURITY_WPA_WPA2))
188187
) {
189188
return NSAPI_ERROR_PARAMETER;
@@ -256,7 +255,7 @@ nsapi_error_t WhdSTAInterface::connect()
256255
}
257256

258257
if (whd_wifi_is_ready_to_transceive(_whd_emac.ifp) == WHD_SUCCESS) {
259-
whd_emac_wifi_link_state_changed(true, _whd_emac.ifp);
258+
whd_emac_wifi_link_state_changed(_whd_emac.ifp, WHD_TRUE);
260259
}
261260

262261
// bring up
@@ -351,7 +350,7 @@ static void whd_scan_handler(whd_scan_result_t **result_ptr,
351350
}
352351
}
353352

354-
if (data->count > 0) {
353+
if (data->count > 0 && data->aps != NULL) {
355354
// get ap stats
356355
nsapi_wifi_ap ap;
357356

@@ -388,7 +387,6 @@ int WhdSTAInterface::scan(WiFiAccessPoint *aps, unsigned count)
388387
interal_scan_data.aps = aps;
389388
interal_scan_data.count = count;
390389
interal_scan_data.offset = 0;
391-
interal_scan_data.ifp = _whd_emac.ifp;
392390
interal_scan_data.scan_in_progress = true;
393391
interal_scan_data.result_buff = new std::vector<whd_scan_result_t>();
394392
whd_result_t whd_res;
@@ -400,12 +398,8 @@ int WhdSTAInterface::scan(WiFiAccessPoint *aps, unsigned count)
400398
if (whd_res != WHD_SUCCESS) {
401399
res = whd_toerror(whd_res);
402400
} else {
403-
int tok = interal_scan_data.sema->wait();
404-
if (tok < 1) {
405-
res = NSAPI_ERROR_WOULD_BLOCK;
406-
} else {
407-
res = interal_scan_data.offset;
408-
}
401+
interal_scan_data.sema->acquire();
402+
res = interal_scan_data.offset;
409403
}
410404

411405
delete interal_scan_data.sema;
@@ -415,6 +409,9 @@ int WhdSTAInterface::scan(WiFiAccessPoint *aps, unsigned count)
415409

416410
int WhdSTAInterface::is_interface_connected(void)
417411
{
412+
if (!_whd_emac.ifp) {
413+
return WHD_INTERFACE_NOT_UP;
414+
}
418415
_whd_emac.ifp->role = WHD_STA_ROLE;
419416
if ((whd_wifi_is_ready_to_transceive(_whd_emac.ifp) == WHD_SUCCESS)) {
420417
return WHD_SUCCESS;
@@ -489,6 +486,13 @@ int WhdSTAInterface::wifi_set_ioctl_value(uint32_t ioctl, uint32_t value)
489486
return res;
490487
}
491488

489+
int WhdSTAInterface::wifi_get_ifp(whd_interface_t *ifp)
490+
{
491+
int res = WHD_SUCCESS;
492+
*ifp = _whd_emac.ifp;
493+
return res;
494+
}
495+
492496
int WhdSTAInterface::wifi_set_up(void)
493497
{
494498
int res = WHD_SUCCESS;
@@ -502,3 +506,10 @@ int WhdSTAInterface::wifi_set_down(void)
502506
res = whd_wifi_set_down(_whd_emac.ifp);
503507
return res;
504508
}
509+
510+
int WhdSTAInterface::wifi_set_coex_config(whd_coex_config_t *coex_config)
511+
{
512+
int res = WHD_SUCCESS;
513+
res = whd_wifi_set_coex_config(_whd_emac.ifp, coex_config);
514+
return res;
515+
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,18 @@ class WhdSTAInterface : public WiFiInterface, public EMACInterface {
161161
/* set ioctl value */
162162
int wifi_set_ioctl_value(uint32_t ioctl, uint32_t value) ;
163163

164+
/* get WHD ifp value */
165+
int wifi_get_ifp(whd_interface_t *ifp);
166+
164167
/* set wifi interface up */
165168
int wifi_set_up(void);
166169

167170
/* set wifi interface down */
168171
int wifi_set_down(void);
169172

173+
/* set wifi coex configuration */
174+
int wifi_set_coex_config(whd_coex_config_t *coex_config);
175+
170176
/** Set Offload Manager Information
171177
* NOTE: Only allowed while disconnected
172178
*
@@ -211,5 +217,4 @@ class WhdSTAInterface : public WiFiInterface, public EMACInterface {
211217
OlmInterface *_olm;
212218
};
213219

214-
extern int wiced_leave_ap(int interface);
215220
#endif

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

Lines changed: 67 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/* Wiced implementation of NetworkInterfaceAPI
2-
* Copyright (c) 2017-2019 ARM Limited
1+
/*
2+
* Copyright (c) 2018-2019 ARM Limited
33
* SPDX-License-Identifier: Apache-2.0
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,6 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18+
1819
#include "nsapi.h"
1920
#include "lwipopts.h"
2021
#include "WhdSoftAPInterface.h"
@@ -29,11 +30,33 @@
2930
extern int whd_toerror(whd_result_t res);
3031
extern nsapi_security_t whd_tosecurity(whd_security_t sec);
3132
extern whd_security_t whd_fromsecurity(nsapi_security_t sec);
32-
extern "C" void whd_emac_wifi_link_state_changed(bool state_up, whd_interface_t ifp);
33+
extern "C" void whd_emac_wifi_link_state_changed(whd_interface_t ifp, whd_bool_t state_up);
34+
35+
static const whd_event_num_t ap_events[] = { WLC_E_LINK, WLC_E_IF, WLC_E_DEAUTH, WLC_E_DEAUTH_IND, WLC_E_DISASSOC, WLC_E_DISASSOC_IND, WLC_E_ASSOC_IND, WLC_E_REASSOC_IND, WLC_E_NONE };
36+
37+
static void *whd_default_handle_softap_events(whd_interface_t ifp, const whd_event_header_t *event_header,
38+
const uint8_t *event_data, void *handler_user_data)
39+
{
40+
whd_driver_t whd_driver = ifp->whd_driver;
3341

42+
UNUSED_PARAMETER(event_header);
43+
UNUSED_PARAMETER(event_data);
44+
UNUSED_PARAMETER(handler_user_data);
45+
46+
WHD_IOCTL_LOG_ADD_EVENT(whd_driver, event_header->event_type, event_header->flags, event_header->reason);
47+
48+
if ((event_header->event_type == (whd_event_num_t)WLC_E_LINK) ||
49+
(event_header->event_type == WLC_E_IF)) {
50+
if (osSemaphoreGetCount(whd_driver->ap_info.whd_wifi_sleep_flag) < 1) {
51+
osStatus_t result = osSemaphoreRelease(whd_driver->ap_info.whd_wifi_sleep_flag);
52+
if (result != osOK) {
53+
printf("Release whd_wifi_sleep_flag ERROR: %d", result);
54+
}
55+
}
56+
}
57+
return handler_user_data;
58+
}
3459

35-
static const whd_event_num_t ap_client_events[] = { WLC_E_DEAUTH, WLC_E_DEAUTH_IND, WLC_E_DISASSOC, WLC_E_DISASSOC_IND, WLC_E_ASSOC_IND, WLC_E_REASSOC_IND, WLC_E_NONE };
36-
static uint16_t ap_event_entry = 2;
3760

3861
WhdSoftAPInterface::WhdSoftAPInterface(WHD_EMAC &emac, OnboardNetworkStack &stack)
3962
: EMACInterface(emac, stack),
@@ -44,18 +67,24 @@ WhdSoftAPInterface::WhdSoftAPInterface(WHD_EMAC &emac, OnboardNetworkStack &stac
4467

4568

4669
int WhdSoftAPInterface::start(const char *ssid, const char *pass, nsapi_security_t security, uint8_t channel,
47-
bool start_dhcp_server, const whd_custom_ie_info_t *ie_info)
70+
bool start_dhcp_server, const whd_custom_ie_info_t *ie_info, bool ap_sta_concur)
4871
{
4972
nsapi_error_t err;
5073

51-
/* set up our interface */
52-
if (!_interface) {
53-
nsapi_error_t err = _stack.add_ethernet_interface(_emac, true, &_interface);
54-
if (err != NSAPI_ERROR_OK) {
55-
_interface = NULL;
56-
return err;
74+
// power up primary emac interface first
75+
if (ap_sta_concur) {
76+
WHD_EMAC &emac_prime = WHD_EMAC::get_instance(WHD_STA_ROLE);
77+
if (!emac_prime.power_up()) {
78+
printf("Primary interface power up ERROR!\n");
79+
return NSAPI_ERROR_DEVICE_ERROR;
5780
}
58-
_interface->attach(_connection_status_cb);
81+
}
82+
83+
// set concurrency mode and power up secondary, the bsp init is done by primary emac
84+
_whd_emac.ap_sta_concur = ap_sta_concur;
85+
if (!_whd_emac.power_up()) {
86+
printf("Secondary interface power up ERROR!\n");
87+
return NSAPI_ERROR_DEVICE_ERROR;
5988
}
6089

6190
// setup ssid
@@ -75,6 +104,27 @@ int WhdSoftAPInterface::start(const char *ssid, const char *pass, nsapi_security
75104
return err;
76105
}
77106

107+
// update default softap interface event handler
108+
err = unregister_event_handler();
109+
if (err != NSAPI_ERROR_OK) {
110+
printf("unregister_event_handler() ERROR: %d\n", err);
111+
return err;
112+
}
113+
err = register_event_handler(whd_default_handle_softap_events);
114+
if (err != NSAPI_ERROR_OK) {
115+
printf("register_event_handler() ERROR: %d\n", err);
116+
return err;
117+
}
118+
119+
if (!_interface) {
120+
nsapi_error_t err = _stack.add_ethernet_interface(_whd_emac, true, &_interface);
121+
if (err != NSAPI_ERROR_OK) {
122+
_interface = NULL;
123+
return err;
124+
}
125+
_interface->attach(_connection_status_cb);
126+
}
127+
78128
if (ie_info) {
79129
err = whd_wifi_manage_custom_ie(_whd_emac.ifp, WHD_ADD_CUSTOM_IE, (const uint8_t *)ie_info->oui,
80130
ie_info->subtype, (const void *)ie_info->data, ie_info->length, ie_info->which_packets);
@@ -94,10 +144,9 @@ int WhdSoftAPInterface::start(const char *ssid, const char *pass, nsapi_security
94144
set_dhcp(false);
95145

96146
if (whd_wifi_is_ready_to_transceive(_whd_emac.ifp) == WHD_SUCCESS) {
97-
whd_emac_wifi_link_state_changed(true, _whd_emac.ifp);
147+
whd_emac_wifi_link_state_changed(_whd_emac.ifp, WHD_TRUE);
98148
}
99149

100-
// bring up
101150
err = _interface->bringup(_dhcp,
102151
_ip_address[0] ? _ip_address : 0,
103152
_netmask[0] ? _netmask : 0,
@@ -130,10 +179,11 @@ int WhdSoftAPInterface::get_associated_client_list(void *client_list_buffer, uin
130179

131180
int WhdSoftAPInterface::register_event_handler(whd_event_handler_t softap_event_handler)
132181
{
133-
return whd_management_set_event_handler(_whd_emac.ifp, ap_client_events, softap_event_handler, NULL, &ap_event_entry);
182+
uint16_t ap_events_entry = _whd_emac.ifp->event_reg_list[WHD_AP_EVENT_ENTRY];
183+
return whd_management_set_event_handler(_whd_emac.ifp, ap_events, softap_event_handler, NULL, &ap_events_entry);
134184
}
135185

136186
int WhdSoftAPInterface::unregister_event_handler(void)
137187
{
138-
return whd_wifi_deregister_event_handler(_whd_emac.ifp, ap_event_entry);
188+
return whd_wifi_deregister_event_handler(_whd_emac.ifp, _whd_emac.ifp->event_reg_list[WHD_AP_EVENT_ENTRY]);
139189
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/* WHD SoftAP implementation of SoftAPInterface
2-
* Copyright (c) 2017-2019 ARM Limited
1+
/*
2+
* Copyright (c) 2018-2019 ARM Limited
33
* SPDX-License-Identifier: Apache-2.0
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -70,14 +70,15 @@ class WhdSoftAPInterface : public EMACInterface {
7070
* @param pass Security passphrase for connection to SoftAP
7171
* @param security Type of encryption for connection
7272
* @param channel Channel for SoftAP
73-
* @param start_dhcp_server start dhcp server for connection
74-
* @param[in] Optional Custom IE
73+
* @param start_dhcp_server Start dhcp server for connection
74+
* @param whd_custom_ie Optional Custom IE
75+
* @param ap_sta_concur Enable STA+AP concurrency mode
7576
*
7677
* @return 0 on success, or error code on failure
7778
* see @a nsapi_error
7879
*/
7980
int start(const char *ssid, const char *pass, nsapi_security_t security, uint8_t channel,
80-
bool start_dhcp_server = true, const whd_custom_ie_info_t *ie_info = NULL);
81+
bool start_dhcp_server = true, const whd_custom_ie_info_t *ie_info = NULL, bool ap_sta_concur = false);
8182

8283
/**
8384
* Remove Wi-Fi custom IE

0 commit comments

Comments
 (0)