diff options
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/src/lib.rs b/src/lib.rs index f0a7aaa0f..1b7d603d7 100644 --- a/src/lib.rs +++ b/src/lib.rs | |||
| @@ -20,13 +20,15 @@ use core::slice; | |||
| 20 | use ch::driver::LinkState; | 20 | use ch::driver::LinkState; |
| 21 | use embassy_futures::yield_now; | 21 | use embassy_futures::yield_now; |
| 22 | use embassy_net_driver_channel as ch; | 22 | use embassy_net_driver_channel as ch; |
| 23 | use embassy_sync::pubsub::PubSubBehavior; | ||
| 23 | use embassy_time::{block_for, Duration, Timer}; | 24 | use embassy_time::{block_for, Duration, Timer}; |
| 24 | use embedded_hal_1::digital::OutputPin; | 25 | use embedded_hal_1::digital::OutputPin; |
| 26 | use events::EventQueue; | ||
| 25 | 27 | ||
| 26 | use crate::bus::Bus; | 28 | use crate::bus::Bus; |
| 27 | pub use crate::bus::SpiBusCyw43; | 29 | pub use crate::bus::SpiBusCyw43; |
| 28 | use crate::consts::*; | 30 | use crate::consts::*; |
| 29 | use crate::events::Event; | 31 | use crate::events::{Event, EventStatus}; |
| 30 | use crate::structs::*; | 32 | use crate::structs::*; |
| 31 | 33 | ||
| 32 | const MTU: usize = 1514; | 34 | const MTU: usize = 1514; |
| @@ -128,6 +130,7 @@ enum IoctlState { | |||
| 128 | pub struct State { | 130 | pub struct State { |
| 129 | ioctl_state: Cell<IoctlState>, | 131 | ioctl_state: Cell<IoctlState>, |
| 130 | ch: ch::State<MTU, 4, 4>, | 132 | ch: ch::State<MTU, 4, 4>, |
| 133 | events: EventQueue, | ||
| 131 | } | 134 | } |
| 132 | 135 | ||
| 133 | impl State { | 136 | impl State { |
| @@ -135,12 +138,14 @@ impl State { | |||
| 135 | Self { | 138 | Self { |
| 136 | ioctl_state: Cell::new(IoctlState::Idle), | 139 | ioctl_state: Cell::new(IoctlState::Idle), |
| 137 | ch: ch::State::new(), | 140 | ch: ch::State::new(), |
| 141 | events: EventQueue::new(), | ||
| 138 | } | 142 | } |
| 139 | } | 143 | } |
| 140 | } | 144 | } |
| 141 | 145 | ||
| 142 | pub struct Control<'a> { | 146 | pub struct Control<'a> { |
| 143 | state_ch: ch::StateRunner<'a>, | 147 | state_ch: ch::StateRunner<'a>, |
| 148 | event_sub: &'a EventQueue, | ||
| 144 | ioctl_state: &'a Cell<IoctlState>, | 149 | ioctl_state: &'a Cell<IoctlState>, |
| 145 | } | 150 | } |
| 146 | 151 | ||
| @@ -314,6 +319,7 @@ impl<'a> Control<'a> { | |||
| 314 | evts.unset(Event::PROBREQ_MSG_RX); | 319 | evts.unset(Event::PROBREQ_MSG_RX); |
| 315 | evts.unset(Event::PROBRESP_MSG); | 320 | evts.unset(Event::PROBRESP_MSG); |
| 316 | evts.unset(Event::PROBRESP_MSG); | 321 | evts.unset(Event::PROBRESP_MSG); |
| 322 | evts.unset(Event::ROAM); | ||
| 317 | 323 | ||
| 318 | self.set_iovar("bsscfg:event_msgs", &evts.to_bytes()).await; | 324 | self.set_iovar("bsscfg:event_msgs", &evts.to_bytes()).await; |
| 319 | 325 | ||
| @@ -394,8 +400,22 @@ impl<'a> Control<'a> { | |||
| 394 | ssid: [0; 32], | 400 | ssid: [0; 32], |
| 395 | }; | 401 | }; |
| 396 | i.ssid[..ssid.len()].copy_from_slice(ssid.as_bytes()); | 402 | i.ssid[..ssid.len()].copy_from_slice(ssid.as_bytes()); |
| 403 | |||
| 404 | let mut subscriber = self.event_sub.subscriber().unwrap(); | ||
| 397 | self.ioctl(IoctlType::Set, 26, 0, &mut i.to_bytes()).await; // set_ssid | 405 | self.ioctl(IoctlType::Set, 26, 0, &mut i.to_bytes()).await; // set_ssid |
| 398 | 406 | ||
| 407 | loop { | ||
| 408 | let msg = subscriber.next_message_pure().await; | ||
| 409 | if msg.event_type == Event::AUTH && msg.status != 0 { | ||
| 410 | // retry | ||
| 411 | defmt::warn!("JOIN failed with status={}", msg.status); | ||
| 412 | self.ioctl(IoctlType::Set, 26, 0, &mut i.to_bytes()).await; | ||
| 413 | } else if msg.event_type == Event::JOIN && msg.status == 0 { | ||
| 414 | // successful join | ||
| 415 | break; | ||
| 416 | } | ||
| 417 | } | ||
| 418 | |||
| 399 | info!("JOINED"); | 419 | info!("JOINED"); |
| 400 | } | 420 | } |
| 401 | 421 | ||
| @@ -490,6 +510,8 @@ pub struct Runner<'a, PWR, SPI> { | |||
| 490 | sdpcm_seq: u8, | 510 | sdpcm_seq: u8, |
| 491 | sdpcm_seq_max: u8, | 511 | sdpcm_seq_max: u8, |
| 492 | 512 | ||
| 513 | events: &'a EventQueue, | ||
| 514 | |||
| 493 | #[cfg(feature = "firmware-logs")] | 515 | #[cfg(feature = "firmware-logs")] |
| 494 | log: LogState, | 516 | log: LogState, |
| 495 | } | 517 | } |
| @@ -526,6 +548,8 @@ where | |||
| 526 | sdpcm_seq: 0, | 548 | sdpcm_seq: 0, |
| 527 | sdpcm_seq_max: 1, | 549 | sdpcm_seq_max: 1, |
| 528 | 550 | ||
| 551 | events: &state.events, | ||
| 552 | |||
| 529 | #[cfg(feature = "firmware-logs")] | 553 | #[cfg(feature = "firmware-logs")] |
| 530 | log: LogState { | 554 | log: LogState { |
| 531 | addr: 0, | 555 | addr: 0, |
| @@ -541,6 +565,7 @@ where | |||
| 541 | device, | 565 | device, |
| 542 | Control { | 566 | Control { |
| 543 | state_ch, | 567 | state_ch, |
| 568 | event_sub: &&state.events, | ||
| 544 | ioctl_state: &state.ioctl_state, | 569 | ioctl_state: &state.ioctl_state, |
| 545 | }, | 570 | }, |
| 546 | runner, | 571 | runner, |
| @@ -882,13 +907,16 @@ where | |||
| 882 | return; | 907 | return; |
| 883 | } | 908 | } |
| 884 | 909 | ||
| 910 | let evt_type = events::Event::from(event_packet.msg.event_type as u8); | ||
| 885 | let evt_data = &bcd_packet[EventMessage::SIZE..][..event_packet.msg.datalen as usize]; | 911 | let evt_data = &bcd_packet[EventMessage::SIZE..][..event_packet.msg.datalen as usize]; |
| 886 | debug!( | 912 | debug!("=== EVENT {}: {} {:02x}", evt_type, event_packet.msg, evt_data); |
| 887 | "=== EVENT {}: {} {:02x}", | 913 | |
| 888 | events::Event::from(event_packet.msg.event_type as u8), | 914 | if evt_type == events::Event::AUTH || evt_type == events::Event::JOIN { |
| 889 | event_packet.msg, | 915 | self.events.publish_immediate(EventStatus { |
| 890 | evt_data | 916 | status: event_packet.msg.status, |
| 891 | ); | 917 | event_type: evt_type, |
| 918 | }); | ||
| 919 | } | ||
| 892 | } | 920 | } |
| 893 | CHANNEL_TYPE_DATA => { | 921 | CHANNEL_TYPE_DATA => { |
| 894 | let bcd_header = BcdHeader::from_bytes(&payload[..BcdHeader::SIZE].try_into().unwrap()); | 922 | let bcd_header = BcdHeader::from_bytes(&payload[..BcdHeader::SIZE].try_into().unwrap()); |
