aboutsummaryrefslogtreecommitdiff
path: root/src/control.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/control.rs')
-rw-r--r--src/control.rs21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/control.rs b/src/control.rs
index 30d5d0924..0c06009b9 100644
--- a/src/control.rs
+++ b/src/control.rs
@@ -6,7 +6,7 @@ use embassy_time::{Duration, Timer};
6 6
7pub use crate::bus::SpiBusCyw43; 7pub use crate::bus::SpiBusCyw43;
8use crate::consts::*; 8use crate::consts::*;
9use crate::events::{Event, EventQueue}; 9use crate::events::{Event, Events};
10use crate::fmt::Bytes; 10use crate::fmt::Bytes;
11use crate::ioctl::{IoctlState, IoctlType}; 11use crate::ioctl::{IoctlState, IoctlType};
12use crate::structs::*; 12use crate::structs::*;
@@ -14,15 +14,15 @@ use crate::{countries, PowerManagementMode};
14 14
15pub struct Control<'a> { 15pub struct Control<'a> {
16 state_ch: ch::StateRunner<'a>, 16 state_ch: ch::StateRunner<'a>,
17 event_sub: &'a EventQueue, 17 events: &'a Events,
18 ioctl_state: &'a IoctlState, 18 ioctl_state: &'a IoctlState,
19} 19}
20 20
21impl<'a> Control<'a> { 21impl<'a> Control<'a> {
22 pub(crate) fn new(state_ch: ch::StateRunner<'a>, event_sub: &'a EventQueue, ioctl_state: &'a IoctlState) -> Self { 22 pub(crate) fn new(state_ch: ch::StateRunner<'a>, event_sub: &'a Events, ioctl_state: &'a IoctlState) -> Self {
23 Self { 23 Self {
24 state_ch, 24 state_ch,
25 event_sub, 25 events: event_sub,
26 ioctl_state, 26 ioctl_state,
27 } 27 }
28 } 28 }
@@ -195,24 +195,27 @@ impl<'a> Control<'a> {
195 } 195 }
196 196
197 async fn wait_for_join(&mut self, i: SsidInfo) { 197 async fn wait_for_join(&mut self, i: SsidInfo) {
198 let mut subscriber = self.event_sub.subscriber().unwrap(); 198 self.events.mask.enable(&[Event::JOIN, Event::AUTH]);
199 let mut subscriber = self.events.queue.subscriber().unwrap();
200 // the actual join operation starts here
201 // we make sure to enable events before so we don't miss any
199 self.ioctl(IoctlType::Set, IOCTL_CMD_SET_SSID, 0, &mut i.to_bytes()) 202 self.ioctl(IoctlType::Set, IOCTL_CMD_SET_SSID, 0, &mut i.to_bytes())
200 .await; 203 .await;
201 // set_ssid 204 // set_ssid
202 205
203 loop { 206 loop {
204 let msg = subscriber.next_message_pure().await; 207 let msg = subscriber.next_message_pure().await;
205 if msg.event_type == Event::AUTH && msg.status != 0 { 208 if msg.header.event_type == Event::AUTH && msg.header.status != EStatus::SUCCESS {
206 // retry 209 // retry
207 warn!("JOIN failed with status={}", msg.status); 210 warn!("JOIN failed with status={}", msg.header.status);
208 self.ioctl(IoctlType::Set, IOCTL_CMD_SET_SSID, 0, &mut i.to_bytes()) 211 self.ioctl(IoctlType::Set, IOCTL_CMD_SET_SSID, 0, &mut i.to_bytes())
209 .await; 212 .await;
210 } else if msg.event_type == Event::JOIN && msg.status == 0 { 213 } else if msg.header.event_type == Event::JOIN && msg.header.status == EStatus::SUCCESS {
211 // successful join 214 // successful join
212 break; 215 break;
213 } 216 }
214 } 217 }
215 218 self.events.mask.disable_all();
216 self.state_ch.set_link_state(LinkState::Up); 219 self.state_ch.set_link_state(LinkState::Up);
217 info!("JOINED"); 220 info!("JOINED");
218 } 221 }