Skip to content

Commit 22c82dc

Browse files
authored
Merge pull request #10692 from vmedcy/pr/psoc6-hal
PSOC6: initial integration of Cypress HAL
2 parents 237ad40 + b652407 commit 22c82dc

File tree

761 files changed

+204533
-87458
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

761 files changed

+204533
-87458
lines changed

features/FEATURE_BLE/targets/TARGET_Cypress/TARGET_CYW43XXX/firmware/TARGET_43012/w_bt_firmware_controller.c

Lines changed: 3882 additions & 0 deletions
Large diffs are not rendered by default.

features/FEATURE_BLE/targets/TARGET_Cypress/TARGET_CYW43XXX/firmware/TARGET_4343W/w_bt_firmware_controller.c

Lines changed: 2086 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 501 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
/* WHD implementation of NetworkInterfaceAPI
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_STA_INTERFACE_H
19+
#define WHD_STA_INTERFACE_H
20+
21+
#include "netsocket/WiFiInterface.h"
22+
#include "netsocket/EMACInterface.h"
23+
#include "netsocket/OnboardNetworkStack.h"
24+
#include "whd_emac.h"
25+
#include "whd_types_int.h"
26+
27+
struct ol_desc;
28+
29+
/** WhdSTAInterface class
30+
* Implementation of the NetworkStack for the WHD
31+
*/
32+
class WhdSTAInterface : public WiFiInterface, public EMACInterface {
33+
public:
34+
35+
class OlmInterface {
36+
public:
37+
/** Get the default OLM interface. */
38+
static OlmInterface &get_default_instance();
39+
40+
OlmInterface(struct ol_desc *list = NULL) {}
41+
42+
virtual int init_ols(void *whd, void *ip)
43+
{
44+
return 0;
45+
}
46+
virtual int sleep()
47+
{
48+
return 0;
49+
}
50+
virtual int wake()
51+
{
52+
return 0;
53+
}
54+
55+
virtual void deinit_ols(void) {}
56+
};
57+
58+
WhdSTAInterface(
59+
WHD_EMAC &emac = WHD_EMAC::get_instance(),
60+
OnboardNetworkStack &stack = OnboardNetworkStack::get_default_instance(),
61+
OlmInterface &olm = OlmInterface::get_default_instance());
62+
63+
static WhdSTAInterface *get_default_instance();
64+
65+
/* Turn on the wifi device*/
66+
void wifi_on();
67+
68+
/** Start the interface
69+
*
70+
* Attempts to connect to a WiFi network. Requires ssid and passphrase to be set.
71+
* If passphrase is invalid, NSAPI_ERROR_AUTH_ERROR is returned.
72+
*
73+
* @return 0 on success, negative error code on failure
74+
*/
75+
nsapi_error_t connect();
76+
77+
/** Start the interface
78+
*
79+
* Attempts to connect to a WiFi network.
80+
*
81+
* @param ssid Name of the network to connect to
82+
* @param pass Security passphrase to connect to the network
83+
* @param security Type of encryption for connection (Default: NSAPI_SECURITY_NONE)
84+
* @param channel This parameter is not supported, setting it to anything else than 0 will result in NSAPI_ERROR_UNSUPPORTED
85+
* @return 0 on success, or error code on failure
86+
*/
87+
nsapi_error_t connect(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE, uint8_t channel = 0);
88+
89+
/** Stop the interface
90+
* @return 0 on success, negative on failure
91+
*/
92+
nsapi_error_t disconnect();
93+
94+
/** Set the WiFi network credentials
95+
*
96+
* @param ssid Name of the network to connect to
97+
* @param pass Security passphrase to connect to the network
98+
* @param security Type of encryption for connection
99+
* (defaults to NSAPI_SECURITY_NONE)
100+
* @return 0 on success, or error code on failure
101+
*/
102+
nsapi_error_t set_credentials(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE);
103+
104+
/** Set the WiFi network channel - NOT SUPPORTED
105+
*
106+
* This function is not supported and will return NSAPI_ERROR_UNSUPPORTED
107+
*
108+
* @param channel Channel on which the connection is to be made, or 0 for any (Default: 0)
109+
* @return Not supported, returns NSAPI_ERROR_UNSUPPORTED
110+
*/
111+
nsapi_error_t set_channel(uint8_t channel)
112+
{
113+
if (channel != 0) {
114+
return NSAPI_ERROR_UNSUPPORTED;
115+
}
116+
117+
return 0;
118+
}
119+
120+
/** Gets the current radio signal strength for active connection
121+
*
122+
* @return Connection strength in dBm (negative value)
123+
*/
124+
int8_t get_rssi();
125+
126+
/** Scan for available networks
127+
*
128+
* This function will block.
129+
*
130+
* @param ap Pointer to allocated array to store discovered AP
131+
* @param count Size of allocated @a res array, or 0 to only count available AP
132+
* @param timeout Timeout in milliseconds; 0 for no timeout (Default: 0)
133+
* @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error
134+
* see @a nsapi_error
135+
*/
136+
int scan(WiFiAccessPoint *res, unsigned count);
137+
138+
/* is interface connected, if yes return WICED_SUCCESS else WICED_NOT_CONNECTED */
139+
int is_interface_connected();
140+
141+
/* get bssid of the AP if success return WICED_SUCCESS else WICED_ERROR */
142+
int get_bssid(uint8_t *bssid);
143+
144+
/* print WHD log (this routine will malloc/free a buffer
145+
* You need to enable printing with WHD_LOGGING_BUFFER_ENABLE
146+
*/
147+
int whd_log_print(void);
148+
149+
/* read WHD log */
150+
int whd_log_read(char *buffer, int buffer_size);
151+
152+
/* Get EDCF AC params */
153+
nsapi_error_t wifi_get_ac_params_sta(void *ac_param);
154+
155+
/* get iovar value */
156+
int wifi_get_iovar_value(const char *iovar, uint32_t *value);
157+
158+
/* set iovar value */
159+
int wifi_set_iovar_value(const char *iovar, uint32_t value);
160+
161+
/* set ioctl value */
162+
int wifi_set_ioctl_value(uint32_t ioctl, uint32_t value) ;
163+
164+
/* set wifi interface up */
165+
int wifi_set_up(void);
166+
167+
/* set wifi interface down */
168+
int wifi_set_down(void);
169+
170+
/** Set Offload Manager Information
171+
* NOTE: Only allowed while disconnected
172+
*
173+
* @param olm Offload Manager info structure
174+
* @return true if completed successfully
175+
* false if Interface is connected
176+
*/
177+
int set_olm(OlmInterface *olm)
178+
{
179+
if (get_connection_status() == NSAPI_STATUS_DISCONNECTED) {
180+
_olm = olm;
181+
return true;
182+
}
183+
return false;
184+
}
185+
186+
/** Network stack is suspended
187+
*
188+
* @return 0 if successful
189+
*/
190+
int net_suspended()
191+
{
192+
int ret = _olm->sleep();
193+
return ret;
194+
}
195+
196+
/** Network stack is resuming
197+
*
198+
* @return 0 if successful
199+
*/
200+
int net_resuming()
201+
{
202+
int ret = _olm->wake();
203+
return ret;
204+
}
205+
private:
206+
207+
char _ssid[33]; /* The longest possible name (defined in 802.11) +1 for the \0 */
208+
char _pass[64]; /* The longest allowed passphrase + 1 */
209+
nsapi_security_t _security;
210+
WHD_EMAC &_whd_emac;
211+
OlmInterface *_olm;
212+
};
213+
214+
extern int wiced_leave_ap(int interface);
215+
#endif
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/* Wiced implementation of NetworkInterfaceAPI
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+
#include "nsapi.h"
19+
#include "lwipopts.h"
20+
#include "WhdSoftAPInterface.h"
21+
#include "nsapi.h"
22+
#include "lwipopts.h"
23+
#include "lwip/etharp.h"
24+
#include "lwip/ethip6.h"
25+
#include "rtos.h"
26+
#include "whd_emac.h"
27+
#include "whd_wifi_api.h"
28+
29+
extern int whd_toerror(whd_result_t res);
30+
extern nsapi_security_t whd_tosecurity(whd_security_t sec);
31+
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+
34+
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+
38+
WhdSoftAPInterface::WhdSoftAPInterface(WHD_EMAC &emac, OnboardNetworkStack &stack)
39+
: EMACInterface(emac, stack),
40+
_whd_emac(emac)
41+
{
42+
43+
}
44+
45+
46+
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)
48+
{
49+
nsapi_error_t err;
50+
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;
57+
}
58+
_interface->attach(_connection_status_cb);
59+
}
60+
61+
// setup ssid
62+
whd_ssid_t whd_ssid;
63+
strncpy((char *)whd_ssid.value, ssid, SSID_NAME_SIZE);
64+
whd_ssid.value[SSID_NAME_SIZE - 1] = '\0';
65+
whd_ssid.length = strlen((char *)whd_ssid.value);
66+
67+
// choose network security
68+
whd_security_t whd_security = whd_fromsecurity(security);
69+
70+
/* set up the AP info */
71+
err = whd_wifi_init_ap(_whd_emac.ifp, &whd_ssid, whd_security, (const uint8_t *)pass,
72+
strlen(pass), channel);
73+
if (err != NSAPI_ERROR_OK) {
74+
printf("whd_wifi_init_ap() ERROR: %d\n", err);
75+
return err;
76+
}
77+
78+
if (ie_info) {
79+
err = whd_wifi_manage_custom_ie(_whd_emac.ifp, WHD_ADD_CUSTOM_IE, (const uint8_t *)ie_info->oui,
80+
ie_info->subtype, (const void *)ie_info->data, ie_info->length, ie_info->which_packets);
81+
if (err != NSAPI_ERROR_OK) {
82+
printf("whd_wifi_manage_custom_ie() ERROR: %d\n", err);
83+
return err;
84+
}
85+
}
86+
87+
err = whd_wifi_start_ap(_whd_emac.ifp);
88+
if (err != NSAPI_ERROR_OK) {
89+
printf("whd_wifi_start_ap() ERROR: %d\n", err);
90+
return err;
91+
}
92+
93+
// Set static IP address for SoftAP and bring up
94+
set_dhcp(false);
95+
96+
if (whd_wifi_is_ready_to_transceive(_whd_emac.ifp) == WHD_SUCCESS) {
97+
whd_emac_wifi_link_state_changed(true, _whd_emac.ifp);
98+
}
99+
100+
// bring up
101+
err = _interface->bringup(_dhcp,
102+
_ip_address[0] ? _ip_address : 0,
103+
_netmask[0] ? _netmask : 0,
104+
_gateway[0] ? _gateway : 0,
105+
DEFAULT_STACK);
106+
if (err != NSAPI_ERROR_OK) {
107+
printf("bringup() ERROR: %d\n", err);
108+
}
109+
return err;
110+
}
111+
112+
113+
114+
int WhdSoftAPInterface::stop(void)
115+
{
116+
return whd_wifi_stop_ap(_whd_emac.ifp);
117+
}
118+
119+
int WhdSoftAPInterface::remove_custom_ie(const whd_custom_ie_info_t *ie_info)
120+
{
121+
return whd_wifi_manage_custom_ie(_whd_emac.ifp, WHD_REMOVE_CUSTOM_IE, (const uint8_t *)ie_info->oui,
122+
ie_info->subtype, (const void *)ie_info->data, ie_info->length, ie_info->which_packets);
123+
}
124+
125+
int WhdSoftAPInterface::get_associated_client_list(void *client_list_buffer, uint16_t buffer_length)
126+
{
127+
128+
return whd_wifi_get_associated_client_list(_whd_emac.ifp, client_list_buffer, buffer_length);
129+
}
130+
131+
int WhdSoftAPInterface::register_event_handler(whd_event_handler_t softap_event_handler)
132+
{
133+
return whd_management_set_event_handler(_whd_emac.ifp, ap_client_events, softap_event_handler, NULL, &ap_event_entry);
134+
}
135+
136+
int WhdSoftAPInterface::unregister_event_handler(void)
137+
{
138+
return whd_wifi_deregister_event_handler(_whd_emac.ifp, ap_event_entry);
139+
}

0 commit comments

Comments
 (0)