diff options
| author | kbleeke <[email protected]> | 2023-03-02 19:22:43 +0100 |
|---|---|---|
| committer | kbleeke <[email protected]> | 2023-03-27 11:10:29 +0200 |
| commit | 472138122542d6c47e666c8e6bb16cc6635ede0a (patch) | |
| tree | a3cecb7730757d45a336205812af28b7fdc3d8bb | |
| parent | 5da6108bec0c977841df21ae4140c4ac61a5369f (diff) | |
also wait for join event in join_open
| -rw-r--r-- | src/control.rs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/control.rs b/src/control.rs index 8bfa033ba..79677b554 100644 --- a/src/control.rs +++ b/src/control.rs | |||
| @@ -134,7 +134,6 @@ impl<'a> Control<'a> { | |||
| 134 | Timer::after(Duration::from_millis(100)).await; | 134 | Timer::after(Duration::from_millis(100)).await; |
| 135 | 135 | ||
| 136 | self.state_ch.set_ethernet_address(mac_addr); | 136 | self.state_ch.set_ethernet_address(mac_addr); |
| 137 | self.state_ch.set_link_state(LinkState::Up); // TODO do on join/leave | ||
| 138 | 137 | ||
| 139 | info!("INIT DONE"); | 138 | info!("INIT DONE"); |
| 140 | } | 139 | } |
| @@ -164,10 +163,8 @@ impl<'a> Control<'a> { | |||
| 164 | ssid: [0; 32], | 163 | ssid: [0; 32], |
| 165 | }; | 164 | }; |
| 166 | i.ssid[..ssid.len()].copy_from_slice(ssid.as_bytes()); | 165 | i.ssid[..ssid.len()].copy_from_slice(ssid.as_bytes()); |
| 167 | self.ioctl(IoctlType::Set, IOCTL_CMD_SET_SSID, 0, &mut i.to_bytes()) | ||
| 168 | .await; // set_ssid | ||
| 169 | 166 | ||
| 170 | info!("JOINED"); | 167 | self.wait_for_join(i).await; |
| 171 | } | 168 | } |
| 172 | 169 | ||
| 173 | pub async fn join_wpa2(&mut self, ssid: &str, passphrase: &str) { | 170 | pub async fn join_wpa2(&mut self, ssid: &str, passphrase: &str) { |
| @@ -199,21 +196,29 @@ impl<'a> Control<'a> { | |||
| 199 | }; | 196 | }; |
| 200 | i.ssid[..ssid.len()].copy_from_slice(ssid.as_bytes()); | 197 | i.ssid[..ssid.len()].copy_from_slice(ssid.as_bytes()); |
| 201 | 198 | ||
| 199 | self.wait_for_join(i).await; | ||
| 200 | } | ||
| 201 | |||
| 202 | async fn wait_for_join(&mut self, i: SsidInfo) { | ||
| 202 | let mut subscriber = self.event_sub.subscriber().unwrap(); | 203 | let mut subscriber = self.event_sub.subscriber().unwrap(); |
| 203 | self.ioctl(IoctlType::Set, 26, 0, &mut i.to_bytes()).await; // set_ssid | 204 | self.ioctl(IoctlType::Set, IOCTL_CMD_SET_SSID, 0, &mut i.to_bytes()) |
| 205 | .await; | ||
| 206 | // set_ssid | ||
| 204 | 207 | ||
| 205 | loop { | 208 | loop { |
| 206 | let msg = subscriber.next_message_pure().await; | 209 | let msg = subscriber.next_message_pure().await; |
| 207 | if msg.event_type == Event::AUTH && msg.status != 0 { | 210 | if msg.event_type == Event::AUTH && msg.status != 0 { |
| 208 | // retry | 211 | // retry |
| 209 | warn!("JOIN failed with status={}", msg.status); | 212 | warn!("JOIN failed with status={}", msg.status); |
| 210 | self.ioctl(IoctlType::Set, 26, 0, &mut i.to_bytes()).await; | 213 | self.ioctl(IoctlType::Set, IOCTL_CMD_SET_SSID, 0, &mut i.to_bytes()) |
| 214 | .await; | ||
| 211 | } else if msg.event_type == Event::JOIN && msg.status == 0 { | 215 | } else if msg.event_type == Event::JOIN && msg.status == 0 { |
| 212 | // successful join | 216 | // successful join |
| 213 | break; | 217 | break; |
| 214 | } | 218 | } |
| 215 | } | 219 | } |
| 216 | 220 | ||
| 221 | self.state_ch.set_link_state(LinkState::Up); | ||
| 217 | info!("JOINED"); | 222 | info!("JOINED"); |
| 218 | } | 223 | } |
| 219 | 224 | ||
