aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-07-11 05:19:31 +0200
committerDario Nieuwenhuis <[email protected]>2022-07-11 05:19:31 +0200
commit30b7800f9ae0a7f26e292dbe55cc67fbe2d1b131 (patch)
treec12af936e5c919405deb09623fd9a02929c112df /src
parent7ddcacac7bbfaed303dcda7d14ab29cad94fd570 (diff)
add event printing, add join but not working yet.
Diffstat (limited to 'src')
-rw-r--r--src/events.rs281
-rw-r--r--src/lib.rs80
-rw-r--r--src/structs.rs55
3 files changed, 410 insertions, 6 deletions
diff --git a/src/events.rs b/src/events.rs
new file mode 100644
index 000000000..b35b12faa
--- /dev/null
+++ b/src/events.rs
@@ -0,0 +1,281 @@
1#![allow(unused)]
2
3use core::num;
4
5#[derive(Clone, Copy, PartialEq, Eq, num_enum::FromPrimitive)]
6#[cfg_attr(feature = "defmt", derive(defmt::Format))]
7#[repr(u8)]
8pub enum Event {
9 #[num_enum(default)]
10 Unknown = 0xFF,
11 /// indicates status of set SSID
12 SET_SSID = 0,
13 /// differentiates join IBSS from found (START) IBSS
14 JOIN = 1,
15 /// STA founded an IBSS or AP started a BSS
16 START = 2,
17 /// 802.11 AUTH request
18 AUTH = 3,
19 /// 802.11 AUTH indication
20 AUTH_IND = 4,
21 /// 802.11 DEAUTH request
22 DEAUTH = 5,
23 /// 802.11 DEAUTH indication
24 DEAUTH_IND = 6,
25 /// 802.11 ASSOC request
26 ASSOC = 7,
27 /// 802.11 ASSOC indication
28 ASSOC_IND = 8,
29 /// 802.11 REASSOC request
30 REASSOC = 9,
31 /// 802.11 REASSOC indication
32 REASSOC_IND = 10,
33 /// 802.11 DISASSOC request
34 DISASSOC = 11,
35 /// 802.11 DISASSOC indication
36 DISASSOC_IND = 12,
37 /// 802.11h Quiet period started
38 QUIET_START = 13,
39 /// 802.11h Quiet period ended
40 QUIET_END = 14,
41 /// BEACONS received/lost indication
42 BEACON_RX = 15,
43 /// generic link indication
44 LINK = 16,
45 /// TKIP MIC error occurred
46 MIC_ERROR = 17,
47 /// NDIS style link indication
48 NDIS_LINK = 18,
49 /// roam attempt occurred: indicate status & reason
50 ROAM = 19,
51 /// change in dot11FailedCount (txfail)
52 TXFAIL = 20,
53 /// WPA2 pmkid cache indication
54 PMKID_CACHE = 21,
55 /// current AP's TSF value went backward
56 RETROGRADE_TSF = 22,
57 /// AP was pruned from join list for reason
58 PRUNE = 23,
59 /// report AutoAuth table entry match for join attempt
60 AUTOAUTH = 24,
61 /// Event encapsulating an EAPOL message
62 EAPOL_MSG = 25,
63 /// Scan results are ready or scan was aborted
64 SCAN_COMPLETE = 26,
65 /// indicate to host addts fail/success
66 ADDTS_IND = 27,
67 /// indicate to host delts fail/success
68 DELTS_IND = 28,
69 /// indicate to host of beacon transmit
70 BCNSENT_IND = 29,
71 /// Send the received beacon up to the host
72 BCNRX_MSG = 30,
73 /// indicate to host loss of beacon
74 BCNLOST_MSG = 31,
75 /// before attempting to roam
76 ROAM_PREP = 32,
77 /// PFN network found event
78 PFN_NET_FOUND = 33,
79 /// PFN network lost event
80 PFN_NET_LOST = 34,
81 RESET_COMPLETE = 35,
82 JOIN_START = 36,
83 ROAM_START = 37,
84 ASSOC_START = 38,
85 IBSS_ASSOC = 39,
86 RADIO = 40,
87 /// PSM microcode watchdog fired
88 PSM_WATCHDOG = 41,
89 /// CCX association start
90 CCX_ASSOC_START = 42,
91 /// CCX association abort
92 CCX_ASSOC_ABORT = 43,
93 /// probe request received
94 PROBREQ_MSG = 44,
95 SCAN_CONFIRM_IND = 45,
96 /// WPA Handshake
97 PSK_SUP = 46,
98 COUNTRY_CODE_CHANGED = 47,
99 /// WMMAC excedded medium time
100 EXCEEDED_MEDIUM_TIME = 48,
101 /// WEP ICV error occurred
102 ICV_ERROR = 49,
103 /// Unsupported unicast encrypted frame
104 UNICAST_DECODE_ERROR = 50,
105 /// Unsupported multicast encrypted frame
106 MULTICAST_DECODE_ERROR = 51,
107 TRACE = 52,
108 /// BT-AMP HCI event
109 BTA_HCI_EVENT = 53,
110 /// I/F change (for wlan host notification)
111 IF = 54,
112 /// P2P Discovery listen state expires
113 P2P_DISC_LISTEN_COMPLETE = 55,
114 /// indicate RSSI change based on configured levels
115 RSSI = 56,
116 /// PFN best network batching event
117 PFN_BEST_BATCHING = 57,
118 EXTLOG_MSG = 58,
119 /// Action frame reception
120 ACTION_FRAME = 59,
121 /// Action frame Tx complete
122 ACTION_FRAME_COMPLETE = 60,
123 /// assoc request received
124 PRE_ASSOC_IND = 61,
125 /// re-assoc request received
126 PRE_REASSOC_IND = 62,
127 /// channel adopted (xxx: obsoleted)
128 CHANNEL_ADOPTED = 63,
129 /// AP started
130 AP_STARTED = 64,
131 /// AP stopped due to DFS
132 DFS_AP_STOP = 65,
133 /// AP resumed due to DFS
134 DFS_AP_RESUME = 66,
135 /// WAI stations event
136 WAI_STA_EVENT = 67,
137 /// event encapsulating an WAI message
138 WAI_MSG = 68,
139 /// escan result event
140 ESCAN_RESULT = 69,
141 /// action frame off channel complete
142 ACTION_FRAME_OFF_CHAN_COMPLETE = 70,
143 /// probe response received
144 PROBRESP_MSG = 71,
145 /// P2P Probe request received
146 P2P_PROBREQ_MSG = 72,
147 DCS_REQUEST = 73,
148 /// credits for D11 FIFOs. [AC0,AC1,AC2,AC3,BC_MC,ATIM]
149 FIFO_CREDIT_MAP = 74,
150 /// Received action frame event WITH wl_event_rx_frame_data_t header
151 ACTION_FRAME_RX = 75,
152 /// Wake Event timer fired, used for wake WLAN test mode
153 WAKE_EVENT = 76,
154 /// Radio measurement complete
155 RM_COMPLETE = 77,
156 /// Synchronize TSF with the host
157 HTSFSYNC = 78,
158 /// request an overlay IOCTL/iovar from the host
159 OVERLAY_REQ = 79,
160 CSA_COMPLETE_IND = 80,
161 /// excess PM Wake Event to inform host
162 EXCESS_PM_WAKE_EVENT = 81,
163 /// no PFN networks around
164 PFN_SCAN_NONE = 82,
165 /// last found PFN network gets lost
166 PFN_SCAN_ALLGONE = 83,
167 GTK_PLUMBED = 84,
168 /// 802.11 ASSOC indication for NDIS only
169 ASSOC_IND_NDIS = 85,
170 /// 802.11 REASSOC indication for NDIS only
171 REASSOC_IND_NDIS = 86,
172 ASSOC_REQ_IE = 87,
173 ASSOC_RESP_IE = 88,
174 /// association recreated on resume
175 ASSOC_RECREATED = 89,
176 /// rx action frame event for NDIS only
177 ACTION_FRAME_RX_NDIS = 90,
178 /// authentication request received
179 AUTH_REQ = 91,
180 /// fast assoc recreation failed
181 SPEEDY_RECREATE_FAIL = 93,
182 /// port-specific event and payload (e.g. NDIS)
183 NATIVE = 94,
184 /// event for tx pkt delay suddently jump
185 PKTDELAY_IND = 95,
186 /// AWDL AW period starts
187 AWDL_AW = 96,
188 /// AWDL Master/Slave/NE master role event
189 AWDL_ROLE = 97,
190 /// Generic AWDL event
191 AWDL_EVENT = 98,
192 /// NIC AF txstatus
193 NIC_AF_TXS = 99,
194 /// NAN event
195 NAN = 100,
196 BEACON_FRAME_RX = 101,
197 /// desired service found
198 SERVICE_FOUND = 102,
199 /// GAS fragment received
200 GAS_FRAGMENT_RX = 103,
201 /// GAS sessions all complete
202 GAS_COMPLETE = 104,
203 /// New device found by p2p offload
204 P2PO_ADD_DEVICE = 105,
205 /// device has been removed by p2p offload
206 P2PO_DEL_DEVICE = 106,
207 /// WNM event to notify STA enter sleep mode
208 WNM_STA_SLEEP = 107,
209 /// Indication of MAC tx failures (exhaustion of 802.11 retries) exceeding threshold(s)
210 TXFAIL_THRESH = 108,
211 /// Proximity Detection event
212 PROXD = 109,
213 /// AWDL RX Probe response
214 AWDL_RX_PRB_RESP = 111,
215 /// AWDL RX Action Frames
216 AWDL_RX_ACT_FRAME = 112,
217 /// AWDL Wowl nulls
218 AWDL_WOWL_NULLPKT = 113,
219 /// AWDL Phycal status
220 AWDL_PHYCAL_STATUS = 114,
221 /// AWDL OOB AF status
222 AWDL_OOB_AF_STATUS = 115,
223 /// Interleaved Scan status
224 AWDL_SCAN_STATUS = 116,
225 /// AWDL AW Start
226 AWDL_AW_START = 117,
227 /// AWDL AW End
228 AWDL_AW_END = 118,
229 /// AWDL AW Extensions
230 AWDL_AW_EXT = 119,
231 AWDL_PEER_CACHE_CONTROL = 120,
232 CSA_START_IND = 121,
233 CSA_DONE_IND = 122,
234 CSA_FAILURE_IND = 123,
235 /// CCA based channel quality report
236 CCA_CHAN_QUAL = 124,
237 /// to report change in BSSID while roaming
238 BSSID = 125,
239 /// tx error indication
240 TX_STAT_ERROR = 126,
241 /// credit check for BCMC supported
242 BCMC_CREDIT_SUPPORT = 127,
243 /// psta primary interface indication
244 PSTA_PRIMARY_INTF_IND = 128,
245 /// Handover Request Initiated
246 BT_WIFI_HANDOVER_REQ = 130,
247 /// Southpaw TxInhibit notification
248 SPW_TXINHIBIT = 131,
249 /// FBT Authentication Request Indication
250 FBT_AUTH_REQ_IND = 132,
251 /// Enhancement addition for RSSI
252 RSSI_LQM = 133,
253 /// Full probe/beacon (IEs etc) results
254 PFN_GSCAN_FULL_RESULT = 134,
255 /// Significant change in rssi of bssids being tracked
256 PFN_SWC = 135,
257 /// a STA been authroized for traffic
258 AUTHORIZED = 136,
259 /// probe req with wl_event_rx_frame_data_t header
260 PROBREQ_MSG_RX = 137,
261 /// PFN completed scan of network list
262 PFN_SCAN_COMPLETE = 138,
263 /// RMC Event
264 RMC_EVENT = 139,
265 /// DPSTA interface indication
266 DPSTA_INTF_IND = 140,
267 /// RRM Event
268 RRM = 141,
269 /// ULP entry event
270 ULP = 146,
271 /// TCP Keep Alive Offload Event
272 TKO = 151,
273 /// authentication request received
274 EXT_AUTH_REQ = 187,
275 /// authentication request received
276 EXT_AUTH_FRAME_RX = 188,
277 /// mgmt frame Tx complete
278 MGMT_FRAME_TXSTATUS = 189,
279 /// highest val + 1 for range checking
280 LAST = 190,
281}
diff --git a/src/lib.rs b/src/lib.rs
index 698c52f49..040caed86 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -7,6 +7,7 @@
7pub(crate) mod fmt; 7pub(crate) mod fmt;
8 8
9mod countries; 9mod countries;
10mod events;
10mod structs; 11mod structs;
11 12
12use core::cell::Cell; 13use core::cell::Cell;
@@ -253,9 +254,52 @@ impl<'a> Control<'a> {
253 }; 254 };
254 self.set_iovar("country", &country_info.to_bytes()).await; 255 self.set_iovar("country", &country_info.to_bytes()).await;
255 256
257 // set country takes some time, next ioctls fail if we don't wait.
258 Timer::after(Duration::from_millis(100)).await;
259
260 // self.set_iovar_u32("ampdu_ba_wsize", 8).await;
261 // self.set_iovar_u32("ampdu_mpdu", 4).await;
262 // self.set_iovar_u32("ampdu_rx_factor", 0).await; // this crashes
263
264 Timer::after(Duration::from_millis(100)).await;
265
266 // evts
267 let mut evts = EventMask {
268 iface: 0,
269 events: [0xFF; 24],
270 };
271 self.set_iovar("bsscfg:event_msgs", &evts.to_bytes()).await;
272
273 // set wifi up
274 self.ioctl(2, 2, 0, &[]).await;
275
276 Timer::after(Duration::from_millis(100)).await;
277
256 info!("INIT DONE"); 278 info!("INIT DONE");
257 } 279 }
258 280
281 pub async fn join(&mut self, ssid: &str) {
282 self.ioctl_set_u32(134, 0, 0).await; // wsec = open
283 self.set_iovar_u32x2("bsscfg:sup_wpa", 0, 0).await;
284 self.ioctl_set_u32(20, 0, 1).await; // set_infra = 1
285 self.ioctl_set_u32(22, 0, 0).await; // set_auth = open (0)
286
287 let mut i = SsidInfo {
288 len: ssid.len() as _,
289 ssid: [0; 32],
290 };
291 i.ssid[..ssid.len()].copy_from_slice(ssid.as_bytes());
292 self.ioctl(2, 26, 0, &i.to_bytes()).await; // set_ssid
293
294 info!("JOINED");
295 }
296
297 async fn set_iovar_u32x2(&mut self, name: &str, val1: u32, val2: u32) {
298 let mut buf = [0; 8];
299 buf[0..4].copy_from_slice(&val1.to_le_bytes());
300 buf[4..8].copy_from_slice(&val2.to_le_bytes());
301 self.set_iovar(name, &buf).await
302 }
259 async fn set_iovar_u32(&mut self, name: &str, val: u32) { 303 async fn set_iovar_u32(&mut self, name: &str, val: u32) {
260 self.set_iovar(name, &val.to_le_bytes()).await 304 self.set_iovar(name, &val.to_le_bytes()).await
261 } 305 }
@@ -272,6 +316,10 @@ impl<'a> Control<'a> {
272 self.ioctl(2, 263, 0, &buf[..total_len]).await; 316 self.ioctl(2, 263, 0, &buf[..total_len]).await;
273 } 317 }
274 318
319 async fn ioctl_set_u32(&mut self, cmd: u32, iface: u32, val: u32) {
320 self.ioctl(2, cmd, 0, &val.to_le_bytes()).await
321 }
322
275 async fn ioctl(&mut self, kind: u32, cmd: u32, iface: u32, buf: &[u8]) { 323 async fn ioctl(&mut self, kind: u32, cmd: u32, iface: u32, buf: &[u8]) {
276 // TODO cancel ioctl on future drop. 324 // TODO cancel ioctl on future drop.
277 325
@@ -488,7 +536,7 @@ impl<'a, PWR: Pin, CS: Pin, CLK: Pin, DIO: Pin> Runner<'a, PWR, CS, CLK, DIO> {
488 } 536 }
489 self.cs.set_high(); 537 self.cs.set_high();
490 538
491 info!("rx {:02x}", &buf[..(len as usize).min(48)]); 539 //info!("rx {:02x}", &buf[..(len as usize).min(36)]);
492 540
493 self.rx(&buf[..len as usize]); 541 self.rx(&buf[..len as usize]);
494 } 542 }
@@ -528,14 +576,38 @@ impl<'a, PWR: Pin, CS: Pin, CLK: Pin, DIO: Pin> Runner<'a, PWR, CS, CLK, DIO> {
528 return; 576 return;
529 } 577 }
530 578
531 let cdc_header = 579 let cdc_header = CdcHeader::from_bytes(payload[..CdcHeader::SIZE].try_into().unwrap());
532 CdcHeader::from_bytes(payload[..CdcHeader::SIZE].try_into().unwrap());
533 580
534 if cdc_header.id == self.state.ioctl_id.get() { 581 if cdc_header.id == self.state.ioctl_id.get() {
535 assert_eq!(cdc_header.status, 0); // todo propagate error 582 assert_eq!(cdc_header.status, 0); // todo propagate error
536 self.state.ioctl_state.set(IoctlState::Done); 583 self.state.ioctl_state.set(IoctlState::Done);
537 } 584 }
538 } 585 }
586 1 => {
587 let bcd_header = BcdHeader::from_bytes(&payload[..BcdHeader::SIZE].try_into().unwrap());
588 //info!("{}", bcd_header);
589
590 let packet_start = BcdHeader::SIZE + 4 * bcd_header.data_offset as usize;
591 if packet_start > payload.len() {
592 warn!("packet start out of range.");
593 return;
594 }
595 let packet = &payload[packet_start..];
596 //info!("rx {:02x}", &packet[..(packet.len() as usize).min(36)]);
597
598 let evt = EventHeader::from_bytes(&packet[24..][..EventHeader::SIZE].try_into().unwrap());
599 let evt_num = evt.event_type.to_be() as u8;
600 let evt_data_len = evt.datalen.to_be() as u8;
601 let evt_data = &packet[24 + EventHeader::SIZE..][..evt_data_len as usize];
602 info!(
603 "=== EVENT {} ({}) {} {:02x}",
604 events::Event::from(evt_num),
605 evt_num,
606 evt,
607 evt_data
608 );
609 }
610
539 _ => {} 611 _ => {}
540 } 612 }
541 } 613 }
@@ -575,7 +647,7 @@ impl<'a, PWR: Pin, CS: Pin, CLK: Pin, DIO: Pin> Runner<'a, PWR, CS, CLK, DIO> {
575 647
576 let total_len = (total_len + 3) & !3; // round up to 4byte 648 let total_len = (total_len + 3) & !3; // round up to 4byte
577 649
578 info!("tx {:02x}", &buf[..total_len.min(48)]); 650 //info!("tx {:02x}", &buf[..total_len.min(48)]);
579 651
580 let cmd = cmd_word(true, true, FUNC_WLAN, 0, total_len as _); 652 let cmd = cmd_word(true, true, FUNC_WLAN, 0, total_len as _);
581 self.cs.set_low(); 653 self.cs.set_low();
diff --git a/src/structs.rs b/src/structs.rs
index bce9ab9ff..8a98d5227 100644
--- a/src/structs.rs
+++ b/src/structs.rs
@@ -15,6 +15,7 @@ macro_rules! impl_bytes {
15} 15}
16 16
17#[derive(Clone, Copy)] 17#[derive(Clone, Copy)]
18#[cfg_attr(feature = "defmt", derive(defmt::Format))]
18#[repr(C)] 19#[repr(C)]
19pub struct SdpcmHeader { 20pub struct SdpcmHeader {
20 pub len: u16, 21 pub len: u16,
@@ -37,6 +38,7 @@ pub struct SdpcmHeader {
37impl_bytes!(SdpcmHeader); 38impl_bytes!(SdpcmHeader);
38 39
39#[derive(Clone, Copy)] 40#[derive(Clone, Copy)]
41#[cfg_attr(feature = "defmt", derive(defmt::Format))]
40#[repr(C)] 42#[repr(C)]
41pub struct CdcHeader { 43pub struct CdcHeader {
42 pub cmd: u32, 44 pub cmd: u32,
@@ -49,8 +51,9 @@ pub struct CdcHeader {
49impl_bytes!(CdcHeader); 51impl_bytes!(CdcHeader);
50 52
51#[derive(Clone, Copy)] 53#[derive(Clone, Copy)]
54#[cfg_attr(feature = "defmt", derive(defmt::Format))]
52#[repr(C)] 55#[repr(C)]
53pub struct BdcHeader { 56pub struct BcdHeader {
54 pub flags: u8, 57 pub flags: u8,
55 /// 802.1d Priority (low 3 bits) 58 /// 802.1d Priority (low 3 bits)
56 pub priority: u8, 59 pub priority: u8,
@@ -58,7 +61,36 @@ pub struct BdcHeader {
58 /// Offset from end of BDC header to packet data, in 4-uint8_t words. Leaves room for optional headers. 61 /// Offset from end of BDC header to packet data, in 4-uint8_t words. Leaves room for optional headers.
59 pub data_offset: u8, 62 pub data_offset: u8,
60} 63}
61impl_bytes!(BdcHeader); 64impl_bytes!(BcdHeader);
65
66#[derive(Clone, Copy)]
67#[cfg_attr(feature = "defmt", derive(defmt::Format))]
68#[repr(C)]
69pub struct EventHeader {
70 /// version
71 pub version: u16,
72 /// see flags below
73 pub flags: u16,
74 /// Message (see below)
75 pub event_type: u32,
76 /// Status code (see below)
77 pub status: u32,
78 /// Reason code (if applicable)
79 pub reason: u32,
80 /// WLC_E_AUTH
81 pub auth_type: u32,
82 /// data buf
83 pub datalen: u32,
84 /// Station address (if applicable)
85 pub addr: [u8; 6],
86 /// name of the incoming packet interface
87 pub ifname: [u8; 16],
88 /// destination OS i/f index
89 pub ifidx: u8,
90 /// source bsscfg index
91 pub bsscfgidx: u8,
92}
93impl_bytes!(EventHeader);
62 94
63#[derive(Clone, Copy)] 95#[derive(Clone, Copy)]
64#[repr(C)] 96#[repr(C)]
@@ -78,6 +110,7 @@ pub const DOWNLOAD_FLAG_HANDLER_VER: u16 = 0x1000;
78pub const DOWNLOAD_TYPE_CLM: u16 = 2; 110pub const DOWNLOAD_TYPE_CLM: u16 = 2;
79 111
80#[derive(Clone, Copy)] 112#[derive(Clone, Copy)]
113#[cfg_attr(feature = "defmt", derive(defmt::Format))]
81#[repr(C)] 114#[repr(C)]
82pub struct CountryInfo { 115pub struct CountryInfo {
83 pub country_abbrev: [u8; 4], 116 pub country_abbrev: [u8; 4],
@@ -85,3 +118,21 @@ pub struct CountryInfo {
85 pub country_code: [u8; 4], 118 pub country_code: [u8; 4],
86} 119}
87impl_bytes!(CountryInfo); 120impl_bytes!(CountryInfo);
121
122#[derive(Clone, Copy)]
123#[cfg_attr(feature = "defmt", derive(defmt::Format))]
124#[repr(C)]
125pub struct SsidInfo {
126 pub len: u32,
127 pub ssid: [u8; 32],
128}
129impl_bytes!(SsidInfo);
130
131#[derive(Clone, Copy)]
132#[cfg_attr(feature = "defmt", derive(defmt::Format))]
133#[repr(C)]
134pub struct EventMask {
135 pub iface: u32,
136 pub events: [u8; 24],
137}
138impl_bytes!(EventMask);