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