v2.0.0
cyw43_ll.h
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 <stdint.h>
39#include "cyw43_config.h"
40
41// External interface
42
47
54// IOCTL commands
55// Bottom bit is used to indicate "set", so divide by 2 to get real ioctl value
56#define CYW43_IOCTL_GET_SSID (0x32)
57#define CYW43_IOCTL_GET_CHANNEL (0x3a)
58#define CYW43_IOCTL_SET_DISASSOC (0x69)
59#define CYW43_IOCTL_GET_ANTDIV (0x7e)
60#define CYW43_IOCTL_SET_ANTDIV (0x81)
61#define CYW43_IOCTL_SET_MONITOR (0xd9)
62#define CYW43_IOCTL_GET_RSSI (0xfe)
63#define CYW43_IOCTL_GET_VAR (0x20c)
64#define CYW43_IOCTL_SET_VAR (0x20f)
65
66// Async events, event_type field
67#define CYW43_EV_SET_SSID (0)
68#define CYW43_EV_JOIN (1)
69#define CYW43_EV_AUTH (3)
70#define CYW43_EV_DEAUTH (5)
71#define CYW43_EV_DEAUTH_IND (6)
72#define CYW43_EV_ASSOC (7)
73#define CYW43_EV_DISASSOC (11)
74#define CYW43_EV_DISASSOC_IND (12)
75#define CYW43_EV_LINK (16)
76#define CYW43_EV_PRUNE (23)
77#define CYW43_EV_PSK_SUP (46)
78#define CYW43_EV_ESCAN_RESULT (69)
79#define CYW43_EV_CSA_COMPLETE_IND (80)
80#define CYW43_EV_ASSOC_REQ_IE (87)
81#define CYW43_EV_ASSOC_RESP_IE (88)
82
83// Event status values
84#define CYW43_STATUS_SUCCESS (0)
85#define CYW43_STATUS_FAIL (1)
86#define CYW43_STATUS_TIMEOUT (2)
87#define CYW43_STATUS_NO_NETWORKS (3)
88#define CYW43_STATUS_ABORT (4)
89#define CYW43_STATUS_NO_ACK (5)
90#define CYW43_STATUS_UNSOLICITED (6)
91#define CYW43_STATUS_ATTEMPT (7)
92#define CYW43_STATUS_PARTIAL (8)
93#define CYW43_STATUS_NEWSCAN (9)
94#define CYW43_STATUS_NEWASSOC (10)
95
96// Values used for STA and AP auth settings
97#define CYW43_SUP_DISCONNECTED (0) // Disconnected
98#define CYW43_SUP_CONNECTING (1) // Connecting
99#define CYW43_SUP_IDREQUIRED (2) // ID Required
100#define CYW43_SUP_AUTHENTICATING (3) // Authenticating
101#define CYW43_SUP_AUTHENTICATED (4) // Authenticated
102#define CYW43_SUP_KEYXCHANGE (5) // Key Exchange
103#define CYW43_SUP_KEYED (6) // Key Exchanged
104#define CYW43_SUP_TIMEOUT (7) // Timeout
105#define CYW43_SUP_LAST_BASIC_STATE (8) // Last Basic State
106#define CYW43_SUP_KEYXCHANGE_WAIT_M1 CYW43_SUP_AUTHENTICATED // Waiting to receive handshake msg M1
107#define CYW43_SUP_KEYXCHANGE_PREP_M2 CYW43_SUP_KEYXCHANGE // Preparing to send handshake msg M2
108#define CYW43_SUP_KEYXCHANGE_WAIT_M3 CYW43_SUP_LAST_BASIC_STATE // Waiting to receive handshake msg M3
109#define CYW43_SUP_KEYXCHANGE_PREP_M4 (9) // Preparing to send handshake msg M4
110#define CYW43_SUP_KEYXCHANGE_WAIT_G1 (10) // Waiting to receive handshake msg G1
111#define CYW43_SUP_KEYXCHANGE_PREP_G2 (11) // Preparing to send handshake msg G2
112
113// Values for AP auth setting
114#define CYW43_REASON_INITIAL_ASSOC (0) // initial assoc
115#define CYW43_REASON_LOW_RSSI (1) // roamed due to low RSSI
116#define CYW43_REASON_DEAUTH (2) // roamed due to DEAUTH indication
117#define CYW43_REASON_DISASSOC (3) // roamed due to DISASSOC indication
118#define CYW43_REASON_BCNS_LOST (4) // roamed due to lost beacons
119#define CYW43_REASON_FAST_ROAM_FAILED (5) // roamed due to fast roam failure
120#define CYW43_REASON_DIRECTED_ROAM (6) // roamed due to request by AP
121#define CYW43_REASON_TSPEC_REJECTED (7) // roamed due to TSPEC rejection
122#define CYW43_REASON_BETTER_AP (8) // roamed due to finding better AP
123
124// prune reason codes
125#define CYW43_REASON_PRUNE_ENCR_MISMATCH (1) // encryption mismatch
126#define CYW43_REASON_PRUNE_BCAST_BSSID (2) // AP uses a broadcast BSSID
127#define CYW43_REASON_PRUNE_MAC_DENY (3) // STA's MAC addr is in AP's MAC deny list
128#define CYW43_REASON_PRUNE_MAC_NA (4) // STA's MAC addr is not in AP's MAC allow list
129#define CYW43_REASON_PRUNE_REG_PASSV (5) // AP not allowed due to regulatory restriction
130#define CYW43_REASON_PRUNE_SPCT_MGMT (6) // AP does not support STA locale spectrum mgmt
131#define CYW43_REASON_PRUNE_RADAR (7) // AP is on a radar channel of STA locale
132#define CYW43_REASON_RSN_MISMATCH (8) // STA does not support AP's RSN
133#define CYW43_REASON_PRUNE_NO_COMMON_RATES (9) // No rates in common with AP
134#define CYW43_REASON_PRUNE_BASIC_RATES (10) // STA does not support all basic rates of BSS
135#define CYW43_REASON_PRUNE_CCXFAST_PREVAP (11) // CCX FAST ROAM: prune previous AP
136#define CYW43_REASON_PRUNE_CIPHER_NA (12) // BSS's cipher not supported
137#define CYW43_REASON_PRUNE_KNOWN_STA (13) // AP is already known to us as a STA
138#define CYW43_REASON_PRUNE_CCXFAST_DROAM (14) // CCX FAST ROAM: prune unqualified AP
139#define CYW43_REASON_PRUNE_WDS_PEER (15) // AP is already known to us as a WDS peer
140#define CYW43_REASON_PRUNE_QBSS_LOAD (16) // QBSS LOAD - AAC is too low
141#define CYW43_REASON_PRUNE_HOME_AP (17) // prune home AP
142#define CYW43_REASON_PRUNE_AP_BLOCKED (18) // prune blocked AP
143#define CYW43_REASON_PRUNE_NO_DIAG_SUPPORT (19) // prune due to diagnostic mode not supported
144
145// WPA failure reason codes carried in the WLC_E_PSK_SUP event
146#define CYW43_REASON_SUP_OTHER (0) // Other reason
147#define CYW43_REASON_SUP_DECRYPT_KEY_DATA (1) // Decryption of key data failed
148#define CYW43_REASON_SUP_BAD_UCAST_WEP128 (2) // Illegal use of ucast WEP128
149#define CYW43_REASON_SUP_BAD_UCAST_WEP40 (3) // Illegal use of ucast WEP40
150#define CYW43_REASON_SUP_UNSUP_KEY_LEN (4) // Unsupported key length
151#define CYW43_REASON_SUP_PW_KEY_CIPHER (5) // Unicast cipher mismatch in pairwise key
152#define CYW43_REASON_SUP_MSG3_TOO_MANY_IE (6) // WPA IE contains > 1 RSN IE in key msg 3
153#define CYW43_REASON_SUP_MSG3_IE_MISMATCH (7) // WPA IE mismatch in key message 3
154#define CYW43_REASON_SUP_NO_INSTALL_FLAG (8) // INSTALL flag unset in 4-way msg
155#define CYW43_REASON_SUP_MSG3_NO_GTK (9) // encapsulated GTK missing from msg 3
156#define CYW43_REASON_SUP_GRP_KEY_CIPHER (10) // Multicast cipher mismatch in group key
157#define CYW43_REASON_SUP_GRP_MSG1_NO_GTK (11) // encapsulated GTK missing from group msg 1
158#define CYW43_REASON_SUP_GTK_DECRYPT_FAIL (12) // GTK decrypt failure
159#define CYW43_REASON_SUP_SEND_FAIL (13) // message send failure
160#define CYW43_REASON_SUP_DEAUTH (14) // received FC_DEAUTH
161#define CYW43_REASON_SUP_WPA_PSK_TMO (15) // WPA PSK 4-way handshake timeout
162
169#define CYW43_AUTH_OPEN (0)
170#define CYW43_AUTH_WPA_TKIP_PSK (0x00200002)
171#define CYW43_AUTH_WPA2_AES_PSK (0x00400004)
172#define CYW43_AUTH_WPA2_MIXED_PSK (0x00400006)
173#define CYW43_AUTH_WPA3_SAE_AES_PSK (0x01000004)
174#define CYW43_AUTH_WPA3_WPA2_AES_PSK (0x01400004)
176
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#define CYW43_BACKPLANE_READ_PAD_LEN_BYTES 16
188#define CYW43_LL_STATE_SIZE_WORDS 526 + 5 + ((CYW43_BACKPLANE_READ_PAD_LEN_BYTES / 4) + 1)
189#else // SDIO
190#define CYW43_BUS_MAX_BLOCK_SIZE 16384
191#define CYW43_BACKPLANE_READ_PAD_LEN_BYTES 0
192#define CYW43_LL_STATE_SIZE_WORDS 526 + 5
193#endif
194
198#define CYW43_CHANNEL_NONE (0xffffffff)
199
205enum {
206 CYW43_ITF_STA,
207 CYW43_ITF_AP,
208};
210
215 typedef struct _cyw43_ev_scan_result_t {
216 uint32_t _0[5];
217 uint8_t bssid[6];
218 uint16_t _1[2];
219 uint8_t ssid_len;
220 uint8_t ssid[32];
221 uint32_t _2[5];
222 uint16_t channel;
223 uint16_t _3;
224 uint8_t auth_mode;
225 int16_t rssi;
226} cyw43_ev_scan_result_t;
228
229 typedef struct _cyw43_async_event_t {
230 uint16_t _0;
231 uint16_t flags;
232 uint32_t event_type;
233 uint32_t status;
234 uint32_t reason;
235 uint8_t _1[30];
236 uint8_t interface;
237 uint8_t _2;
238 union {
239 cyw43_ev_scan_result_t scan_result;
240 } u;
241} cyw43_async_event_t;
242
247 typedef struct _cyw43_wifi_scan_options_t {
248 uint32_t version;
249 uint16_t action;
250 uint16_t _;
251 uint32_t ssid_len;
252 uint8_t ssid[32];
253 uint8_t bssid[6];
254 int8_t bss_type;
255 int8_t scan_type;
256 int32_t nprobes;
257 int32_t active_time;
258 int32_t passive_time;
259 int32_t home_time;
260 int32_t channel_num;
261 uint16_t channel_list[1];
262} cyw43_wifi_scan_options_t;
264
265 typedef struct _cyw43_ll_t {
266 uint32_t opaque[CYW43_LL_STATE_SIZE_WORDS]; // note: array of words
267} cyw43_ll_t;
268
269void cyw43_ll_init(cyw43_ll_t *self, void *cb_data);
270void cyw43_ll_deinit(cyw43_ll_t *self);
271
272int cyw43_ll_bus_init(cyw43_ll_t *self, const uint8_t *mac);
273void cyw43_ll_bus_sleep(cyw43_ll_t *self, bool can_sleep);
274void cyw43_ll_process_packets(cyw43_ll_t *self);
275int cyw43_ll_ioctl(cyw43_ll_t *self, uint32_t cmd, size_t len, uint8_t *buf, uint32_t iface);
276int cyw43_ll_send_ethernet(cyw43_ll_t *self, int itf, size_t len, const void *buf, bool is_pbuf);
277
278int cyw43_ll_wifi_on(cyw43_ll_t *self, uint32_t country);
279int 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);
280int 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);
281int cyw43_ll_wifi_scan(cyw43_ll_t *self, cyw43_wifi_scan_options_t *opts);
282
283int 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);
284void cyw43_ll_wifi_set_wpa_auth(cyw43_ll_t *self);
285void cyw43_ll_wifi_rejoin(cyw43_ll_t *self);
286int cyw43_ll_wifi_get_bssid(cyw43_ll_t *self_in, uint8_t *bssid);
287
288int 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);
289int cyw43_ll_wifi_ap_set_up(cyw43_ll_t *self, bool up);
290int cyw43_ll_wifi_ap_get_stas(cyw43_ll_t *self, int *num_stas, uint8_t *macs);
291
292#if CYW43_GPIO
293int cyw43_ll_gpio_set(cyw43_ll_t *self, int gpio_n, bool gpio_en);
294int cyw43_ll_gpio_get(cyw43_ll_t *self_in, int gpio_n, bool *gpio_en);
295#endif
296
297// Get mac address
298int cyw43_ll_wifi_get_mac(cyw43_ll_t *self_in, uint8_t *addr);
299
300// Add/remove multicast address
301int cyw43_ll_wifi_update_multicast_filter(cyw43_ll_t *self_in, uint8_t *addr, bool add);
302
303// Returns true while there's work to do
304bool cyw43_ll_has_work(cyw43_ll_t *self);
305bool cyw43_ll_bt_has_work(cyw43_ll_t *self);
306
307// Callbacks to be provided by mid-level interface
308int cyw43_cb_read_host_interrupt_pin(void *cb_data);
309void cyw43_cb_ensure_awake(void *cb_data);
310void cyw43_cb_process_async_event(void *cb_data, const cyw43_async_event_t *ev);
311void cyw43_cb_process_ethernet(void *cb_data, int itf, size_t len, const uint8_t *buf);
312
313// Low level methods used for bluetooth
314void cyw43_ll_write_backplane_reg(cyw43_ll_t *self_in, uint32_t addr, uint32_t val);
315uint32_t cyw43_ll_read_backplane_reg(cyw43_ll_t *self_in, uint32_t addr);
316int cyw43_ll_write_backplane_mem(cyw43_ll_t *self_in, uint32_t addr, uint32_t len, const uint8_t *buf);
317int cyw43_ll_read_backplane_mem(cyw43_ll_t *self_in, uint32_t addr, uint32_t len, uint8_t *buf);
318
320
321#endif // CYW43_INCLUDED_CYW43_LL_H
cyw43_wifi_scan_options_t
struct _cyw43_wifi_scan_options_t cyw43_wifi_scan_options_t
wifi scan options passed to cyw43_wifi_scan
cyw43_ev_scan_result_t
struct _cyw43_ev_scan_result_t cyw43_ev_scan_result_t
Structure to return wifi scan results.
CYW43_ITF_STA
@ CYW43_ITF_STA
Client interface STA mode.
Definition: cyw43_ll.h:206
CYW43_ITF_AP
@ CYW43_ITF_AP
Access point (AP) interface mode.
Definition: cyw43_ll.h:207
_cyw43_async_event_t
Definition: cyw43_ll.h:229
_cyw43_ev_scan_result_t
Structure to return wifi scan results.
Definition: cyw43_ll.h:215
_cyw43_ev_scan_result_t::auth_mode
uint8_t auth_mode
wifi auth mode CYW43_AUTH_
Definition: cyw43_ll.h:224
_cyw43_ev_scan_result_t::rssi
int16_t rssi
signal strength
Definition: cyw43_ll.h:225
_cyw43_ev_scan_result_t::ssid_len
uint8_t ssid_len
length of wlan access point name
Definition: cyw43_ll.h:219
_cyw43_ev_scan_result_t::ssid
uint8_t ssid[32]
wlan access point name
Definition: cyw43_ll.h:220
_cyw43_ev_scan_result_t::bssid
uint8_t bssid[6]
access point mac address
Definition: cyw43_ll.h:217
_cyw43_ev_scan_result_t::channel
uint16_t channel
wifi channel
Definition: cyw43_ll.h:222
_cyw43_ll_t
Definition: cyw43_ll.h:265
_cyw43_wifi_scan_options_t
wifi scan options passed to cyw43_wifi_scan
Definition: cyw43_ll.h:247
_cyw43_wifi_scan_options_t::ssid
uint8_t ssid[32]
ssid name
Definition: cyw43_ll.h:252
_cyw43_wifi_scan_options_t::home_time
int32_t home_time
home time (not used)
Definition: cyw43_ll.h:259
_cyw43_wifi_scan_options_t::passive_time
int32_t passive_time
passive time (not used)
Definition: cyw43_ll.h:258
_cyw43_wifi_scan_options_t::scan_type
int8_t scan_type
scan type 0=active, 1=passive
Definition: cyw43_ll.h:255
_cyw43_wifi_scan_options_t::channel_num
int32_t channel_num
number of channels (not used)
Definition: cyw43_ll.h:260
_cyw43_wifi_scan_options_t::version
uint32_t version
version (not used)
Definition: cyw43_ll.h:248
_cyw43_wifi_scan_options_t::_
uint16_t _
not used
Definition: cyw43_ll.h:250
_cyw43_wifi_scan_options_t::channel_list
uint16_t channel_list[1]
channel list (not used)
Definition: cyw43_ll.h:261
_cyw43_wifi_scan_options_t::active_time
int32_t active_time
active time (not used)
Definition: cyw43_ll.h:257
_cyw43_wifi_scan_options_t::bssid
uint8_t bssid[6]
bssid (not used)
Definition: cyw43_ll.h:253
_cyw43_wifi_scan_options_t::action
uint16_t action
action (not used)
Definition: cyw43_ll.h:249
_cyw43_wifi_scan_options_t::nprobes
int32_t nprobes
number of probes (not used)
Definition: cyw43_ll.h:256
_cyw43_wifi_scan_options_t::bss_type
int8_t bss_type
bssid type (not used)
Definition: cyw43_ll.h:254
_cyw43_wifi_scan_options_t::ssid_len
uint32_t ssid_len
ssid length, 0=all
Definition: cyw43_ll.h:251