diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-07-12 04:17:07 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-07-12 04:17:07 +0200 |
| commit | e1fd7dfc40bbb1ccbab511fb1e0d7a1120ae68a0 (patch) | |
| tree | e8f9eee7925979aa326cde5be15a0c44ad3c3f31 /src/lib.rs | |
| parent | 18b11e7417e1338fb18e6ceda609f2a0841d7a57 (diff) | |
wpa2 join... still nothing.
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 59 |
1 files changed, 54 insertions, 5 deletions
diff --git a/src/lib.rs b/src/lib.rs index 6a1b7970c..70fa7edee 100644 --- a/src/lib.rs +++ b/src/lib.rs | |||
| @@ -250,8 +250,8 @@ impl<'a> Control<'a> { | |||
| 250 | info!("Configuring misc stuff..."); | 250 | info!("Configuring misc stuff..."); |
| 251 | 251 | ||
| 252 | self.set_iovar_u32("bus:txglom", 0).await; | 252 | self.set_iovar_u32("bus:txglom", 0).await; |
| 253 | //self.set_iovar_u32("apsta", 1).await; | 253 | self.set_iovar_u32("apsta", 1).await; |
| 254 | self.set_iovar("cur_etheraddr", &[02, 03, 04, 05, 06, 07]).await; | 254 | //self.set_iovar("cur_etheraddr", &[02, 03, 04, 05, 06, 07]).await; |
| 255 | 255 | ||
| 256 | let country = countries::WORLD_WIDE_XX; | 256 | let country = countries::WORLD_WIDE_XX; |
| 257 | let country_info = CountryInfo { | 257 | let country_info = CountryInfo { |
| @@ -267,9 +267,13 @@ impl<'a> Control<'a> { | |||
| 267 | self.ioctl_set_u32(64, 0, 0).await; // WLC_SET_ANTDIV | 267 | self.ioctl_set_u32(64, 0, 0).await; // WLC_SET_ANTDIV |
| 268 | 268 | ||
| 269 | self.set_iovar_u32("bus:txglom", 0).await; | 269 | self.set_iovar_u32("bus:txglom", 0).await; |
| 270 | //self.set_iovar_u32("apsta", 1).await; | 270 | Timer::after(Duration::from_millis(100)).await; |
| 271 | //self.set_iovar_u32("apsta", 1).await; // this crashes, also we already did it before...?? | ||
| 272 | Timer::after(Duration::from_millis(100)).await; | ||
| 271 | self.set_iovar_u32("ampdu_ba_wsize", 8).await; | 273 | self.set_iovar_u32("ampdu_ba_wsize", 8).await; |
| 274 | Timer::after(Duration::from_millis(100)).await; | ||
| 272 | self.set_iovar_u32("ampdu_mpdu", 4).await; | 275 | self.set_iovar_u32("ampdu_mpdu", 4).await; |
| 276 | Timer::after(Duration::from_millis(100)).await; | ||
| 273 | //self.set_iovar_u32("ampdu_rx_factor", 0).await; // this crashes | 277 | //self.set_iovar_u32("ampdu_rx_factor", 0).await; // this crashes |
| 274 | 278 | ||
| 275 | Timer::after(Duration::from_millis(100)).await; | 279 | Timer::after(Duration::from_millis(100)).await; |
| @@ -281,12 +285,20 @@ impl<'a> Control<'a> { | |||
| 281 | }; | 285 | }; |
| 282 | self.set_iovar("bsscfg:event_msgs", &evts.to_bytes()).await; | 286 | self.set_iovar("bsscfg:event_msgs", &evts.to_bytes()).await; |
| 283 | 287 | ||
| 288 | Timer::after(Duration::from_millis(100)).await; | ||
| 289 | |||
| 284 | // set wifi up | 290 | // set wifi up |
| 285 | self.ioctl(2, 2, 0, &mut []).await; | 291 | self.ioctl(2, 2, 0, &mut []).await; |
| 286 | 292 | ||
| 287 | Timer::after(Duration::from_millis(100)).await; | 293 | Timer::after(Duration::from_millis(100)).await; |
| 288 | 294 | ||
| 289 | self.ioctl_set_u32(86, 0, 0).await; // no power save | 295 | // power save mode 2 |
| 296 | self.set_iovar_u32("pm2_sleep_ret", 0xc8).await; | ||
| 297 | self.set_iovar_u32("bcn_li_bcn", 1).await; | ||
| 298 | self.set_iovar_u32("bcn_li_dtim", 1).await; | ||
| 299 | self.set_iovar_u32("assoc_listen", 10).await; | ||
| 300 | self.ioctl_set_u32(0x86, 0, 2).await; | ||
| 301 | |||
| 290 | self.ioctl_set_u32(110, 0, 1).await; // SET_GMODE = auto | 302 | self.ioctl_set_u32(110, 0, 1).await; // SET_GMODE = auto |
| 291 | self.ioctl_set_u32(142, 0, 0).await; // SET_BAND = any | 303 | self.ioctl_set_u32(142, 0, 0).await; // SET_BAND = any |
| 292 | 304 | ||
| @@ -295,7 +307,9 @@ impl<'a> Control<'a> { | |||
| 295 | info!("INIT DONE"); | 307 | info!("INIT DONE"); |
| 296 | } | 308 | } |
| 297 | 309 | ||
| 298 | pub async fn join(&mut self, ssid: &str) { | 310 | pub async fn join_open(&mut self, ssid: &str) { |
| 311 | self.set_iovar_u32("ampdu_ba_wsize", 8).await; | ||
| 312 | |||
| 299 | self.ioctl_set_u32(134, 0, 0).await; // wsec = open | 313 | self.ioctl_set_u32(134, 0, 0).await; // wsec = open |
| 300 | self.set_iovar_u32x2("bsscfg:sup_wpa", 0, 0).await; | 314 | self.set_iovar_u32x2("bsscfg:sup_wpa", 0, 0).await; |
| 301 | self.ioctl_set_u32(20, 0, 1).await; // set_infra = 1 | 315 | self.ioctl_set_u32(20, 0, 1).await; // set_infra = 1 |
| @@ -311,6 +325,38 @@ impl<'a> Control<'a> { | |||
| 311 | info!("JOINED"); | 325 | info!("JOINED"); |
| 312 | } | 326 | } |
| 313 | 327 | ||
| 328 | pub async fn join_wpa2(&mut self, ssid: &str, passphrase: &str) { | ||
| 329 | self.set_iovar_u32("ampdu_ba_wsize", 8).await; | ||
| 330 | |||
| 331 | self.ioctl_set_u32(134, 0, 4).await; // wsec = wpa2 | ||
| 332 | self.set_iovar_u32x2("bsscfg:sup_wpa", 0, 1).await; | ||
| 333 | self.set_iovar_u32x2("bsscfg:sup_wpa2_eapver", 0, 0xFFFF_FFFF).await; | ||
| 334 | self.set_iovar_u32x2("bsscfg:sup_wpa_tmo", 0, 2500).await; | ||
| 335 | |||
| 336 | Timer::after(Duration::from_millis(100)).await; | ||
| 337 | |||
| 338 | let mut pfi = PassphraseInfo { | ||
| 339 | len: passphrase.len() as _, | ||
| 340 | flags: 1, | ||
| 341 | passphrase: [0; 64], | ||
| 342 | }; | ||
| 343 | pfi.passphrase[..passphrase.len()].copy_from_slice(passphrase.as_bytes()); | ||
| 344 | self.ioctl(2, 268, 0, &mut pfi.to_bytes()).await; // WLC_SET_WSEC_PMK | ||
| 345 | |||
| 346 | self.ioctl_set_u32(20, 0, 1).await; // set_infra = 1 | ||
| 347 | self.ioctl_set_u32(22, 0, 0).await; // set_auth = 0 (open) | ||
| 348 | self.ioctl_set_u32(165, 0, 0x80).await; // set_wpa_auth | ||
| 349 | |||
| 350 | let mut i = SsidInfo { | ||
| 351 | len: ssid.len() as _, | ||
| 352 | ssid: [0; 32], | ||
| 353 | }; | ||
| 354 | i.ssid[..ssid.len()].copy_from_slice(ssid.as_bytes()); | ||
| 355 | self.ioctl(2, 26, 0, &mut i.to_bytes()).await; // set_ssid | ||
| 356 | |||
| 357 | info!("JOINED"); | ||
| 358 | } | ||
| 359 | |||
| 314 | async fn set_iovar_u32x2(&mut self, name: &str, val1: u32, val2: u32) { | 360 | async fn set_iovar_u32x2(&mut self, name: &str, val1: u32, val2: u32) { |
| 315 | let mut buf = [0; 8]; | 361 | let mut buf = [0; 8]; |
| 316 | buf[0..4].copy_from_slice(&val1.to_le_bytes()); | 362 | buf[0..4].copy_from_slice(&val1.to_le_bytes()); |
| @@ -362,6 +408,9 @@ impl<'a> Control<'a> { | |||
| 362 | async fn ioctl(&mut self, kind: u32, cmd: u32, iface: u32, buf: &mut [u8]) -> usize { | 408 | async fn ioctl(&mut self, kind: u32, cmd: u32, iface: u32, buf: &mut [u8]) -> usize { |
| 363 | // TODO cancel ioctl on future drop. | 409 | // TODO cancel ioctl on future drop. |
| 364 | 410 | ||
| 411 | // snail mode 🐌 | ||
| 412 | Timer::after(Duration::from_millis(100)).await; | ||
| 413 | |||
| 365 | while !matches!(self.state.ioctl_state.get(), IoctlState::Idle) { | 414 | while !matches!(self.state.ioctl_state.get(), IoctlState::Idle) { |
| 366 | yield_now().await; | 415 | yield_now().await; |
| 367 | } | 416 | } |
