cyw43_ll.h
Go to the documentation of this file.
1 /*
2  * This file is part of the cyw43-driver
3  *
4  * Copyright (C) 2019-2022 George Robotics Pty Ltd
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  * 3. Any redistribution, use, or modification in source or binary form is done
15  * solely for personal benefit and not for any commercial purpose or for
16  * monetary gain.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE LICENSOR AND COPYRIGHT OWNER "AS IS" AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL THE LICENSOR OR COPYRIGHT OWNER BE LIABLE FOR
22  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * This software is also available for use with certain devices under different
30  * terms, as set out in the top level LICENSE file. For commercial licensing
31  * options please email contact@georgerobotics.com.au.
32  */
33 
34 #ifndef CYW43_INCLUDED_CYW43_LL_H
35 #define CYW43_INCLUDED_CYW43_LL_H
36 
37 #include <stdbool.h>
38 #include "cyw43_config.h"
39 
40 // External interface
41 
45 
52 // IOCTL commands
53 // Bottom bit is used to indicate "set", so divide by 2 to get real ioctl value
54 #define CYW43_IOCTL_GET_SSID (0x32)
55 #define CYW43_IOCTL_GET_CHANNEL (0x3a)
56 #define CYW43_IOCTL_SET_DISASSOC (0x69)
57 #define CYW43_IOCTL_GET_ANTDIV (0x7e)
58 #define CYW43_IOCTL_SET_ANTDIV (0x81)
59 #define CYW43_IOCTL_SET_MONITOR (0xd9)
60 #define CYW43_IOCTL_GET_RSSI (0xfe)
61 #define CYW43_IOCTL_GET_VAR (0x20c)
62 #define CYW43_IOCTL_SET_VAR (0x20f)
63 
64 // Async events, event_type field
65 #define CYW43_EV_SET_SSID (0)
66 #define CYW43_EV_JOIN (1)
67 #define CYW43_EV_AUTH (3)
68 #define CYW43_EV_DEAUTH (5)
69 #define CYW43_EV_DEAUTH_IND (6)
70 #define CYW43_EV_ASSOC (7)
71 #define CYW43_EV_DISASSOC (11)
72 #define CYW43_EV_DISASSOC_IND (12)
73 #define CYW43_EV_LINK (16)
74 #define CYW43_EV_PRUNE (23)
75 #define CYW43_EV_PSK_SUP (46)
76 #define CYW43_EV_ESCAN_RESULT (69)
77 #define CYW43_EV_CSA_COMPLETE_IND (80)
78 #define CYW43_EV_ASSOC_REQ_IE (87)
79 #define CYW43_EV_ASSOC_RESP_IE (88)
80 
81 // Event status values
82 #define CYW43_STATUS_SUCCESS (0)
83 #define CYW43_STATUS_FAIL (1)
84 #define CYW43_STATUS_TIMEOUT (2)
85 #define CYW43_STATUS_NO_NETWORKS (3)
86 #define CYW43_STATUS_ABORT (4)
87 #define CYW43_STATUS_NO_ACK (5)
88 #define CYW43_STATUS_UNSOLICITED (6)
89 #define CYW43_STATUS_ATTEMPT (7)
90 #define CYW43_STATUS_PARTIAL (8)
91 #define CYW43_STATUS_NEWSCAN (9)
92 #define CYW43_STATUS_NEWASSOC (10)
93 
94 // Values used for STA and AP auth settings
95 #define CYW43_SUP_DISCONNECTED (0) // Disconnected
96 #define CYW43_SUP_CONNECTING (1) // Connecting
97 #define CYW43_SUP_IDREQUIRED (2) // ID Required
98 #define CYW43_SUP_AUTHENTICATING (3) // Authenticating
99 #define CYW43_SUP_AUTHENTICATED (4) // Authenticated
100 #define CYW43_SUP_KEYXCHANGE (5) // Key Exchange
101 #define CYW43_SUP_KEYED (6) // Key Exchanged
102 #define CYW43_SUP_TIMEOUT (7) // Timeout
103 #define CYW43_SUP_LAST_BASIC_STATE (8) // Last Basic State
104 #define CYW43_SUP_KEYXCHANGE_WAIT_M1 CYW43_SUP_AUTHENTICATED // Waiting to receive handshake msg M1
105 #define CYW43_SUP_KEYXCHANGE_PREP_M2 CYW43_SUP_KEYXCHANGE // Preparing to send handshake msg M2
106 #define CYW43_SUP_KEYXCHANGE_WAIT_M3 CYW43_SUP_LAST_BASIC_STATE // Waiting to receive handshake msg M3
107 #define CYW43_SUP_KEYXCHANGE_PREP_M4 (9) // Preparing to send handshake msg M4
108 #define CYW43_SUP_KEYXCHANGE_WAIT_G1 (10) // Waiting to receive handshake msg G1
109 #define CYW43_SUP_KEYXCHANGE_PREP_G2 (11) // Preparing to send handshake msg G2
110 
111 // Values for AP auth setting
112 #define CYW43_REASON_INITIAL_ASSOC (0) // initial assoc
113 #define CYW43_REASON_LOW_RSSI (1) // roamed due to low RSSI
114 #define CYW43_REASON_DEAUTH (2) // roamed due to DEAUTH indication
115 #define CYW43_REASON_DISASSOC (3) // roamed due to DISASSOC indication
116 #define CYW43_REASON_BCNS_LOST (4) // roamed due to lost beacons
117 #define CYW43_REASON_FAST_ROAM_FAILED (5) // roamed due to fast roam failure
118 #define CYW43_REASON_DIRECTED_ROAM (6) // roamed due to request by AP
119 #define CYW43_REASON_TSPEC_REJECTED (7) // roamed due to TSPEC rejection
120 #define CYW43_REASON_BETTER_AP (8) // roamed due to finding better AP
121 
122 // prune reason codes
123 #define CYW43_REASON_PRUNE_ENCR_MISMATCH (1) // encryption mismatch
124 #define CYW43_REASON_PRUNE_BCAST_BSSID (2) // AP uses a broadcast BSSID
125 #define CYW43_REASON_PRUNE_MAC_DENY (3) // STA's MAC addr is in AP's MAC deny list
126 #define CYW43_REASON_PRUNE_MAC_NA (4) // STA's MAC addr is not in AP's MAC allow list
127 #define CYW43_REASON_PRUNE_REG_PASSV (5) // AP not allowed due to regulatory restriction
128 #define CYW43_REASON_PRUNE_SPCT_MGMT (6) // AP does not support STA locale spectrum mgmt
129 #define CYW43_REASON_PRUNE_RADAR (7) // AP is on a radar channel of STA locale
130 #define CYW43_REASON_RSN_MISMATCH (8) // STA does not support AP's RSN
131 #define CYW43_REASON_PRUNE_NO_COMMON_RATES (9) // No rates in common with AP
132 #define CYW43_REASON_PRUNE_BASIC_RATES (10) // STA does not support all basic rates of BSS
133 #define CYW43_REASON_PRUNE_CCXFAST_PREVAP (11) // CCX FAST ROAM: prune previous AP
134 #define CYW43_REASON_PRUNE_CIPHER_NA (12) // BSS's cipher not supported
135 #define CYW43_REASON_PRUNE_KNOWN_STA (13) // AP is already known to us as a STA
136 #define CYW43_REASON_PRUNE_CCXFAST_DROAM (14) // CCX FAST ROAM: prune unqualified AP
137 #define CYW43_REASON_PRUNE_WDS_PEER (15) // AP is already known to us as a WDS peer
138 #define CYW43_REASON_PRUNE_QBSS_LOAD (16) // QBSS LOAD - AAC is too low
139 #define CYW43_REASON_PRUNE_HOME_AP (17) // prune home AP
140 #define CYW43_REASON_PRUNE_AP_BLOCKED (18) // prune blocked AP
141 #define CYW43_REASON_PRUNE_NO_DIAG_SUPPORT (19) // prune due to diagnostic mode not supported
142 
143 // WPA failure reason codes carried in the WLC_E_PSK_SUP event
144 #define CYW43_REASON_SUP_OTHER (0) // Other reason
145 #define CYW43_REASON_SUP_DECRYPT_KEY_DATA (1) // Decryption of key data failed
146 #define CYW43_REASON_SUP_BAD_UCAST_WEP128 (2) // Illegal use of ucast WEP128
147 #define CYW43_REASON_SUP_BAD_UCAST_WEP40 (3) // Illegal use of ucast WEP40
148 #define CYW43_REASON_SUP_UNSUP_KEY_LEN (4) // Unsupported key length
149 #define CYW43_REASON_SUP_PW_KEY_CIPHER (5) // Unicast cipher mismatch in pairwise key
150 #define CYW43_REASON_SUP_MSG3_TOO_MANY_IE (6) // WPA IE contains > 1 RSN IE in key msg 3
151 #define CYW43_REASON_SUP_MSG3_IE_MISMATCH (7) // WPA IE mismatch in key message 3
152 #define CYW43_REASON_SUP_NO_INSTALL_FLAG (8) // INSTALL flag unset in 4-way msg
153 #define CYW43_REASON_SUP_MSG3_NO_GTK (9) // encapsulated GTK missing from msg 3
154 #define CYW43_REASON_SUP_GRP_KEY_CIPHER (10) // Multicast cipher mismatch in group key
155 #define CYW43_REASON_SUP_GRP_MSG1_NO_GTK (11) // encapsulated GTK missing from group msg 1
156 #define CYW43_REASON_SUP_GTK_DECRYPT_FAIL (12) // GTK decrypt failure
157 #define CYW43_REASON_SUP_SEND_FAIL (13) // message send failure
158 #define CYW43_REASON_SUP_DEAUTH (14) // received FC_DEAUTH
159 #define CYW43_REASON_SUP_WPA_PSK_TMO (15) // WPA PSK 4-way handshake timeout
160 
161 // Values used for STA and AP auth settings
162 #define CYW43_WPA_AUTH_PSK (0x0004)
163 #define CYW43_WPA2_AUTH_PSK (0x0080)
164 
170 #define CYW43_AUTH_OPEN (0)
172 #define CYW43_AUTH_WPA_TKIP_PSK (0x00200002)
173 #define CYW43_AUTH_WPA2_AES_PSK (0x00400004)
174 #define CYW43_AUTH_WPA2_MIXED_PSK (0x00400006)
175 
177 
180 #define CYW43_NO_POWERSAVE_MODE (0)
181 #define CYW43_PM1_POWERSAVE_MODE (1)
182 #define CYW43_PM2_POWERSAVE_MODE (2)
183 
184 // The maximum block size for transfers on the bus.
185 #if CYW43_USE_SPI
186 #define CYW43_BUS_MAX_BLOCK_SIZE 64
187 #else // SDIO
188 #define CYW43_BUS_MAX_BLOCK_SIZE 16384
189 #endif
190 
194 #define CYW43_CHANNEL_NONE (0xffffffff)
195 
196 
200 enum {
204 };
206 
210 typedef struct _cyw43_ev_scan_result_t {
212  uint32_t _0[5];
213  uint8_t bssid[6];
214  uint16_t _1[2];
215  uint8_t ssid_len;
216  uint8_t ssid[32];
217  uint32_t _2[5];
218  uint16_t channel;
219  uint16_t _3;
220  uint8_t auth_mode;
221  int16_t rssi;
224 
225 typedef struct _cyw43_async_event_t {
226  uint16_t _0;
227  uint16_t flags;
228  uint32_t event_type;
229  uint32_t status;
230  uint32_t reason;
231  uint8_t _1[30];
232  uint8_t interface;
233  uint8_t _2;
234  union {
235  cyw43_ev_scan_result_t scan_result;
236  } u;
238 
242 typedef struct _cyw43_wifi_scan_options_t {
244  uint32_t version;
245  uint16_t action;
246  uint16_t _;
247  uint32_t ssid_len;
248  uint8_t ssid[32];
249  uint8_t bssid[6];
250  int8_t bss_type;
251  int8_t scan_type;
252  int32_t nprobes;
253  int32_t active_time;
254  int32_t passive_time;
255  int32_t home_time;
256  int32_t channel_num;
257  uint16_t channel_list[1];
260 
261 typedef struct _cyw43_ll_t {
262  uint32_t opaque[526 + 7]; // note: array of words
263 } cyw43_ll_t;
264 
265 void cyw43_ll_init(cyw43_ll_t *self, void *cb_data);
266 void cyw43_ll_deinit(cyw43_ll_t *self);
267 
268 int cyw43_ll_bus_init(cyw43_ll_t *self, const uint8_t *mac);
269 void cyw43_ll_bus_sleep(cyw43_ll_t *self, bool can_sleep);
270 void cyw43_ll_process_packets(cyw43_ll_t *self);
271 int cyw43_ll_ioctl(cyw43_ll_t *self, uint32_t cmd, size_t len, uint8_t *buf, uint32_t iface);
272 int cyw43_ll_send_ethernet(cyw43_ll_t *self, int itf, size_t len, const void *buf, bool is_pbuf);
273 
274 int cyw43_ll_wifi_on(cyw43_ll_t *self, uint32_t country);
275 int cyw43_ll_wifi_pm(cyw43_ll_t *self, uint32_t pm, uint32_t pm_sleep_ret, uint32_t li_bcn, uint32_t li_dtim, uint32_t li_assoc);
276 int cyw43_ll_wifi_get_pm(cyw43_ll_t *self, uint32_t *pm, uint32_t *pm_sleep_ret, uint32_t *li_bcn, uint32_t *li_dtim, uint32_t *li_assoc);
277 int cyw43_ll_wifi_scan(cyw43_ll_t *self, cyw43_wifi_scan_options_t *opts);
278 
279 int cyw43_ll_wifi_join(cyw43_ll_t *self, size_t ssid_len, const uint8_t *ssid, size_t key_len, const uint8_t *key, uint32_t auth_type, const uint8_t *bssid, uint32_t channel);
280 void cyw43_ll_wifi_set_wpa_auth(cyw43_ll_t *self);
281 void cyw43_ll_wifi_rejoin(cyw43_ll_t *self);
282 int cyw43_ll_wifi_get_bssid(cyw43_ll_t *self_in, uint8_t *bssid);
283 
284 int cyw43_ll_wifi_ap_init(cyw43_ll_t *self, size_t ssid_len, const uint8_t *ssid, uint32_t auth, size_t key_len, const uint8_t *key, uint32_t channel);
285 int cyw43_ll_wifi_ap_set_up(cyw43_ll_t *self, bool up);
286 int cyw43_ll_wifi_ap_get_stas(cyw43_ll_t *self, int *num_stas, uint8_t *macs);
287 
288 #if CYW43_GPIO
289 int cyw43_ll_gpio_set(cyw43_ll_t *self, int gpio_n, bool gpio_en);
290 int cyw43_ll_gpio_get(cyw43_ll_t *self_in, int gpio_n, bool *gpio_en);
291 #endif
292 
293 // Get mac address
294 int cyw43_ll_wifi_get_mac(cyw43_ll_t *self_in, uint8_t *addr);
295 
296 // Add/remove multicast address
297 int cyw43_ll_wifi_update_multicast_filter(cyw43_ll_t *self_in, uint8_t *addr, bool add);
298 
299 // Returns true while there's work to do
300 bool cyw43_ll_has_work(cyw43_ll_t *self);
301 bool cyw43_ll_bt_has_work(cyw43_ll_t *self);
302 
303 // Callbacks to be provided by mid-level interface
304 int cyw43_cb_read_host_interrupt_pin(void *cb_data);
305 void cyw43_cb_ensure_awake(void *cb_data);
306 void cyw43_cb_process_async_event(void *cb_data, const cyw43_async_event_t *ev);
307 void cyw43_cb_process_ethernet(void *cb_data, int itf, size_t len, const uint8_t *buf);
308 
309 // Low level methods used for bluetooth
310 void cyw43_ll_write_backplane_reg(cyw43_ll_t *self_in, uint32_t addr, uint32_t val);
311 uint32_t cyw43_ll_read_backplane_reg(cyw43_ll_t *self_in, uint32_t addr);
312 int cyw43_ll_write_backplane_mem(cyw43_ll_t *self_in, uint32_t addr, uint32_t len, const uint8_t *buf);
313 int cyw43_ll_read_backplane_mem(cyw43_ll_t *self_in, uint32_t addr, uint32_t len, uint8_t *buf);
314 
316 
317 #endif // CYW43_INCLUDED_CYW43_LL_H
wifi scan options passed to cyw43_wifi_scan
Definition: cyw43_ll.h:243
int32_t passive_time
passive time (not used)
Definition: cyw43_ll.h:254
Definition: cyw43_ll.h:261
uint32_t version
version (not used)
Definition: cyw43_ll.h:244
Access point (AP) interface mode.
Definition: cyw43_ll.h:203
uint16_t channel
wifi channel
Definition: cyw43_ll.h:218
uint8_t ssid_len
length of wlan access point name
Definition: cyw43_ll.h:215
int32_t home_time
home time (not used)
Definition: cyw43_ll.h:255
Structure to return wifi scan results.
Definition: cyw43_ll.h:211
uint8_t auth_mode
wifi auth mode CYW43_AUTH_
Definition: cyw43_ll.h:220
int8_t scan_type
scan type 0=active, 1=passive
Definition: cyw43_ll.h:251
uint16_t action
action (not used)
Definition: cyw43_ll.h:245
int8_t bss_type
bssid type (not used)
Definition: cyw43_ll.h:250
uint16_t _
not used
Definition: cyw43_ll.h:246
Client interface STA mode.
Definition: cyw43_ll.h:202
int32_t channel_num
number of channels (not used)
Definition: cyw43_ll.h:256
uint32_t ssid_len
ssid length, 0=all
Definition: cyw43_ll.h:247
Definition: cyw43_ll.h:225
int16_t rssi
signal strength
Definition: cyw43_ll.h:221
uint8_t bssid[6]
access point mac address
Definition: cyw43_ll.h:213
int32_t nprobes
number of probes (not used)
Definition: cyw43_ll.h:252
int32_t active_time
active time (not used)
Definition: cyw43_ll.h:253
struct _cyw43_wifi_scan_options_t cyw43_wifi_scan_options_t
wifi scan options passed to cyw43_wifi_scan
uint8_t ssid[32]
wlan access point name
Definition: cyw43_ll.h:216
struct _cyw43_ev_scan_result_t cyw43_ev_scan_result_t
Structure to return wifi scan results.