1
- /* Wiced implementation of NetworkInterfaceAPI
2
- * Copyright (c) 2017 -2019 ARM Limited
1
+ /*
2
+ * Copyright (c) 2018 -2019 ARM Limited
3
3
* SPDX-License-Identifier: Apache-2.0
4
4
*
5
5
* Licensed under the Apache License, Version 2.0 (the "License");
15
15
* limitations under the License.
16
16
*/
17
17
18
+
18
19
#include " nsapi.h"
19
20
#include " lwipopts.h"
20
21
#include " WhdSoftAPInterface.h"
29
30
extern int whd_toerror (whd_result_t res);
30
31
extern nsapi_security_t whd_tosecurity (whd_security_t sec);
31
32
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 ;
33
41
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
+ }
34
59
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 ;
37
60
38
61
WhdSoftAPInterface::WhdSoftAPInterface (WHD_EMAC &emac, OnboardNetworkStack &stack)
39
62
: EMACInterface(emac, stack),
@@ -44,18 +67,24 @@ WhdSoftAPInterface::WhdSoftAPInterface(WHD_EMAC &emac, OnboardNetworkStack &stac
44
67
45
68
46
69
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 )
48
71
{
49
72
nsapi_error_t err;
50
73
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 ;
57
80
}
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;
59
88
}
60
89
61
90
// setup ssid
@@ -75,6 +104,27 @@ int WhdSoftAPInterface::start(const char *ssid, const char *pass, nsapi_security
75
104
return err;
76
105
}
77
106
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
+
78
128
if (ie_info) {
79
129
err = whd_wifi_manage_custom_ie (_whd_emac.ifp , WHD_ADD_CUSTOM_IE, (const uint8_t *)ie_info->oui ,
80
130
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
94
144
set_dhcp (false );
95
145
96
146
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 );
98
148
}
99
149
100
- // bring up
101
150
err = _interface->bringup (_dhcp,
102
151
_ip_address[0 ] ? _ip_address : 0 ,
103
152
_netmask[0 ] ? _netmask : 0 ,
@@ -130,10 +179,11 @@ int WhdSoftAPInterface::get_associated_client_list(void *client_list_buffer, uin
130
179
131
180
int WhdSoftAPInterface::register_event_handler (whd_event_handler_t softap_event_handler)
132
181
{
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);
134
184
}
135
185
136
186
int WhdSoftAPInterface::unregister_event_handler (void )
137
187
{
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] );
139
189
}
0 commit comments