diff options
Diffstat (limited to 'cyw43/src/control.rs')
| -rw-r--r-- | cyw43/src/control.rs | 59 |
1 files changed, 26 insertions, 33 deletions
diff --git a/cyw43/src/control.rs b/cyw43/src/control.rs index 22c52bd96..48be772c0 100644 --- a/cyw43/src/control.rs +++ b/cyw43/src/control.rs | |||
| @@ -109,7 +109,7 @@ impl<'a> Control<'a> { | |||
| 109 | buf[0..8].copy_from_slice(b"clmload\x00"); | 109 | buf[0..8].copy_from_slice(b"clmload\x00"); |
| 110 | buf[8..20].copy_from_slice(&header.to_bytes()); | 110 | buf[8..20].copy_from_slice(&header.to_bytes()); |
| 111 | buf[20..][..chunk.len()].copy_from_slice(&chunk); | 111 | buf[20..][..chunk.len()].copy_from_slice(&chunk); |
| 112 | self.ioctl(IoctlType::Set, IOCTL_CMD_SET_VAR, 0, &mut buf[..8 + 12 + chunk.len()]) | 112 | self.ioctl(IoctlType::Set, Ioctl::SetVar, 0, &mut buf[..8 + 12 + chunk.len()]) |
| 113 | .await; | 113 | .await; |
| 114 | } | 114 | } |
| 115 | 115 | ||
| @@ -145,7 +145,7 @@ impl<'a> Control<'a> { | |||
| 145 | Timer::after_millis(100).await; | 145 | Timer::after_millis(100).await; |
| 146 | 146 | ||
| 147 | // Set antenna to chip antenna | 147 | // Set antenna to chip antenna |
| 148 | self.ioctl_set_u32(IOCTL_CMD_ANTDIV, 0, 0).await; | 148 | self.ioctl_set_u32(Ioctl::SetAntdiv, 0, 0).await; |
| 149 | 149 | ||
| 150 | self.set_iovar_u32("bus:txglom", 0).await; | 150 | self.set_iovar_u32("bus:txglom", 0).await; |
| 151 | Timer::after_millis(100).await; | 151 | Timer::after_millis(100).await; |
| @@ -183,8 +183,8 @@ impl<'a> Control<'a> { | |||
| 183 | 183 | ||
| 184 | Timer::after_millis(100).await; | 184 | Timer::after_millis(100).await; |
| 185 | 185 | ||
| 186 | self.ioctl_set_u32(110, 0, 1).await; // SET_GMODE = auto | 186 | self.ioctl_set_u32(Ioctl::SetGmode, 0, 1).await; // SET_GMODE = auto |
| 187 | self.ioctl_set_u32(142, 0, 0).await; // SET_BAND = any | 187 | self.ioctl_set_u32(Ioctl::SetBand, 0, 0).await; // SET_BAND = any |
| 188 | 188 | ||
| 189 | Timer::after_millis(100).await; | 189 | Timer::after_millis(100).await; |
| 190 | 190 | ||
| @@ -195,12 +195,12 @@ impl<'a> Control<'a> { | |||
| 195 | 195 | ||
| 196 | /// Set the WiFi interface up. | 196 | /// Set the WiFi interface up. |
| 197 | async fn up(&mut self) { | 197 | async fn up(&mut self) { |
| 198 | self.ioctl(IoctlType::Set, IOCTL_CMD_UP, 0, &mut []).await; | 198 | self.ioctl(IoctlType::Set, Ioctl::Up, 0, &mut []).await; |
| 199 | } | 199 | } |
| 200 | 200 | ||
| 201 | /// Set the interface down. | 201 | /// Set the interface down. |
| 202 | async fn down(&mut self) { | 202 | async fn down(&mut self) { |
| 203 | self.ioctl(IoctlType::Set, IOCTL_CMD_DOWN, 0, &mut []).await; | 203 | self.ioctl(IoctlType::Set, Ioctl::Down, 0, &mut []).await; |
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | /// Set power management mode. | 206 | /// Set power management mode. |
| @@ -213,17 +213,17 @@ impl<'a> Control<'a> { | |||
| 213 | self.set_iovar_u32("bcn_li_dtim", mode.dtim_period() as u32).await; | 213 | self.set_iovar_u32("bcn_li_dtim", mode.dtim_period() as u32).await; |
| 214 | self.set_iovar_u32("assoc_listen", mode.assoc() as u32).await; | 214 | self.set_iovar_u32("assoc_listen", mode.assoc() as u32).await; |
| 215 | } | 215 | } |
| 216 | self.ioctl_set_u32(86, 0, mode_num).await; | 216 | self.ioctl_set_u32(Ioctl::SetPm, 0, mode_num).await; |
| 217 | } | 217 | } |
| 218 | 218 | ||
| 219 | /// Join an unprotected network with the provided ssid. | 219 | /// Join an unprotected network with the provided ssid. |
| 220 | pub async fn join_open(&mut self, ssid: &str) -> Result<(), Error> { | 220 | pub async fn join_open(&mut self, ssid: &str) -> Result<(), Error> { |
| 221 | self.set_iovar_u32("ampdu_ba_wsize", 8).await; | 221 | self.set_iovar_u32("ampdu_ba_wsize", 8).await; |
| 222 | 222 | ||
| 223 | self.ioctl_set_u32(134, 0, 0).await; // wsec = open | 223 | self.ioctl_set_u32(Ioctl::SetWsec, 0, 0).await; // wsec = open |
| 224 | self.set_iovar_u32x2("bsscfg:sup_wpa", 0, 0).await; | 224 | self.set_iovar_u32x2("bsscfg:sup_wpa", 0, 0).await; |
| 225 | self.ioctl_set_u32(20, 0, 1).await; // set_infra = 1 | 225 | self.ioctl_set_u32(Ioctl::SetInfra, 0, 1).await; // set_infra = 1 |
| 226 | self.ioctl_set_u32(22, 0, 0).await; // set_auth = open (0) | 226 | self.ioctl_set_u32(Ioctl::SetAuth, 0, 0).await; // set_auth = open (0) |
| 227 | 227 | ||
| 228 | let mut i = SsidInfo { | 228 | let mut i = SsidInfo { |
| 229 | len: ssid.len() as _, | 229 | len: ssid.len() as _, |
| @@ -238,24 +238,19 @@ impl<'a> Control<'a> { | |||
| 238 | async fn join_wpa2_passphrase_info(&mut self, ssid: &str, passphrase_info: &PassphraseInfo) -> Result<(), Error> { | 238 | async fn join_wpa2_passphrase_info(&mut self, ssid: &str, passphrase_info: &PassphraseInfo) -> Result<(), Error> { |
| 239 | self.set_iovar_u32("ampdu_ba_wsize", 8).await; | 239 | self.set_iovar_u32("ampdu_ba_wsize", 8).await; |
| 240 | 240 | ||
| 241 | self.ioctl_set_u32(134, 0, 4).await; // wsec = wpa2 | 241 | self.ioctl_set_u32(Ioctl::SetWsec, 0, 4).await; // wsec = open |
| 242 | self.set_iovar_u32x2("bsscfg:sup_wpa", 0, 1).await; | 242 | self.set_iovar_u32x2("bsscfg:sup_wpa", 0, 1).await; |
| 243 | self.set_iovar_u32x2("bsscfg:sup_wpa2_eapver", 0, 0xFFFF_FFFF).await; | 243 | self.set_iovar_u32x2("bsscfg:sup_wpa2_eapver", 0, 0xFFFF_FFFF).await; |
| 244 | self.set_iovar_u32x2("bsscfg:sup_wpa_tmo", 0, 2500).await; | 244 | self.set_iovar_u32x2("bsscfg:sup_wpa_tmo", 0, 2500).await; |
| 245 | 245 | ||
| 246 | Timer::after_millis(100).await; | 246 | Timer::after_millis(100).await; |
| 247 | 247 | ||
| 248 | self.ioctl( | 248 | self.ioctl(IoctlType::Set, Ioctl::SetWsecPmk, 0, &mut passphrase_info.to_bytes()) |
| 249 | IoctlType::Set, | 249 | .await; // WLC_SET_WSEC_PMK |
| 250 | IOCTL_CMD_SET_PASSPHRASE, | ||
| 251 | 0, | ||
| 252 | &mut passphrase_info.to_bytes(), | ||
| 253 | ) | ||
| 254 | .await; // WLC_SET_WSEC_PMK | ||
| 255 | 250 | ||
| 256 | self.ioctl_set_u32(20, 0, 1).await; // set_infra = 1 | 251 | self.ioctl_set_u32(Ioctl::SetInfra, 0, 1).await; // set_infra = 1 |
| 257 | self.ioctl_set_u32(22, 0, 0).await; // set_auth = 0 (open) | 252 | self.ioctl_set_u32(Ioctl::SetAuth, 0, 0).await; // set_auth = 0 (open) |
| 258 | self.ioctl_set_u32(165, 0, 0x80).await; // set_wpa_auth | 253 | self.ioctl_set_u32(Ioctl::SetWpaAuth, 0, 0x80).await; |
| 259 | 254 | ||
| 260 | let mut i = SsidInfo { | 255 | let mut i = SsidInfo { |
| 261 | len: ssid.len() as _, | 256 | len: ssid.len() as _, |
| @@ -294,9 +289,7 @@ impl<'a> Control<'a> { | |||
| 294 | // the actual join operation starts here | 289 | // the actual join operation starts here |
| 295 | // we make sure to enable events before so we don't miss any | 290 | // we make sure to enable events before so we don't miss any |
| 296 | 291 | ||
| 297 | // set_ssid | 292 | self.ioctl(IoctlType::Set, Ioctl::SetSsid, 0, &mut i.to_bytes()).await; |
| 298 | self.ioctl(IoctlType::Set, IOCTL_CMD_SET_SSID, 0, &mut i.to_bytes()) | ||
| 299 | .await; | ||
| 300 | 293 | ||
| 301 | // to complete the join, we wait for a SET_SSID event | 294 | // to complete the join, we wait for a SET_SSID event |
| 302 | // we also save the AUTH status for the user, it may be interesting | 295 | // we also save the AUTH status for the user, it may be interesting |
| @@ -357,7 +350,7 @@ impl<'a> Control<'a> { | |||
| 357 | self.up().await; | 350 | self.up().await; |
| 358 | 351 | ||
| 359 | // Turn on AP mode | 352 | // Turn on AP mode |
| 360 | self.ioctl_set_u32(IOCTL_CMD_SET_AP, 0, 1).await; | 353 | self.ioctl_set_u32(Ioctl::SetAp, 0, 1).await; |
| 361 | 354 | ||
| 362 | // Set SSID | 355 | // Set SSID |
| 363 | let mut i = SsidInfoWithIndex { | 356 | let mut i = SsidInfoWithIndex { |
| @@ -371,7 +364,7 @@ impl<'a> Control<'a> { | |||
| 371 | self.set_iovar("bsscfg:ssid", &i.to_bytes()).await; | 364 | self.set_iovar("bsscfg:ssid", &i.to_bytes()).await; |
| 372 | 365 | ||
| 373 | // Set channel number | 366 | // Set channel number |
| 374 | self.ioctl_set_u32(IOCTL_CMD_SET_CHANNEL, 0, channel as u32).await; | 367 | self.ioctl_set_u32(Ioctl::SetChannel, 0, channel as u32).await; |
| 375 | 368 | ||
| 376 | // Set security | 369 | // Set security |
| 377 | self.set_iovar_u32x2("bsscfg:wsec", 0, (security as u32) & 0xFF).await; | 370 | self.set_iovar_u32x2("bsscfg:wsec", 0, (security as u32) & 0xFF).await; |
| @@ -388,7 +381,7 @@ impl<'a> Control<'a> { | |||
| 388 | passphrase: [0; 64], | 381 | passphrase: [0; 64], |
| 389 | }; | 382 | }; |
| 390 | pfi.passphrase[..passphrase.as_bytes().len()].copy_from_slice(passphrase.as_bytes()); | 383 | pfi.passphrase[..passphrase.as_bytes().len()].copy_from_slice(passphrase.as_bytes()); |
| 391 | self.ioctl(IoctlType::Set, IOCTL_CMD_SET_PASSPHRASE, 0, &mut pfi.to_bytes()) | 384 | self.ioctl(IoctlType::Set, Ioctl::SetWsecPmk, 0, &mut pfi.to_bytes()) |
| 392 | .await; | 385 | .await; |
| 393 | } | 386 | } |
| 394 | 387 | ||
| @@ -405,7 +398,7 @@ impl<'a> Control<'a> { | |||
| 405 | self.set_iovar_u32x2("bss", 0, 0).await; // bss = BSS_DOWN | 398 | self.set_iovar_u32x2("bss", 0, 0).await; // bss = BSS_DOWN |
| 406 | 399 | ||
| 407 | // Turn off AP mode | 400 | // Turn off AP mode |
| 408 | self.ioctl_set_u32(IOCTL_CMD_SET_AP, 0, 0).await; | 401 | self.ioctl_set_u32(Ioctl::SetAp, 0, 0).await; |
| 409 | 402 | ||
| 410 | // Temporarily set wifi down | 403 | // Temporarily set wifi down |
| 411 | self.down().await; | 404 | self.down().await; |
| @@ -496,7 +489,7 @@ impl<'a> Control<'a> { | |||
| 496 | buf[name.len() + 1..][..val.len()].copy_from_slice(val); | 489 | buf[name.len() + 1..][..val.len()].copy_from_slice(val); |
| 497 | 490 | ||
| 498 | let total_len = name.len() + 1 + val.len(); | 491 | let total_len = name.len() + 1 + val.len(); |
| 499 | self.ioctl(IoctlType::Set, IOCTL_CMD_SET_VAR, 0, &mut buf[..total_len]) | 492 | self.ioctl(IoctlType::Set, Ioctl::SetVar, 0, &mut buf[..total_len]) |
| 500 | .await; | 493 | .await; |
| 501 | } | 494 | } |
| 502 | 495 | ||
| @@ -510,7 +503,7 @@ impl<'a> Control<'a> { | |||
| 510 | 503 | ||
| 511 | let total_len = max(name.len() + 1, res.len()); | 504 | let total_len = max(name.len() + 1, res.len()); |
| 512 | let res_len = self | 505 | let res_len = self |
| 513 | .ioctl(IoctlType::Get, IOCTL_CMD_GET_VAR, 0, &mut buf[..total_len]) | 506 | .ioctl(IoctlType::Get, Ioctl::GetVar, 0, &mut buf[..total_len]) |
| 514 | .await; | 507 | .await; |
| 515 | 508 | ||
| 516 | let out_len = min(res.len(), res_len); | 509 | let out_len = min(res.len(), res_len); |
| @@ -518,12 +511,12 @@ impl<'a> Control<'a> { | |||
| 518 | out_len | 511 | out_len |
| 519 | } | 512 | } |
| 520 | 513 | ||
| 521 | async fn ioctl_set_u32(&mut self, cmd: u32, iface: u32, val: u32) { | 514 | async fn ioctl_set_u32(&mut self, cmd: Ioctl, iface: u32, val: u32) { |
| 522 | let mut buf = val.to_le_bytes(); | 515 | let mut buf = val.to_le_bytes(); |
| 523 | self.ioctl(IoctlType::Set, cmd, iface, &mut buf).await; | 516 | self.ioctl(IoctlType::Set, cmd, iface, &mut buf).await; |
| 524 | } | 517 | } |
| 525 | 518 | ||
| 526 | async fn ioctl(&mut self, kind: IoctlType, cmd: u32, iface: u32, buf: &mut [u8]) -> usize { | 519 | async fn ioctl(&mut self, kind: IoctlType, cmd: Ioctl, iface: u32, buf: &mut [u8]) -> usize { |
| 527 | struct CancelOnDrop<'a>(&'a IoctlState); | 520 | struct CancelOnDrop<'a>(&'a IoctlState); |
| 528 | 521 | ||
| 529 | impl CancelOnDrop<'_> { | 522 | impl CancelOnDrop<'_> { |
| @@ -615,7 +608,7 @@ impl<'a> Control<'a> { | |||
| 615 | } | 608 | } |
| 616 | /// Leave the wifi, with which we are currently associated. | 609 | /// Leave the wifi, with which we are currently associated. |
| 617 | pub async fn leave(&mut self) { | 610 | pub async fn leave(&mut self) { |
| 618 | self.ioctl(IoctlType::Set, IOCTL_CMD_DISASSOC, 0, &mut []).await; | 611 | self.ioctl(IoctlType::Set, Ioctl::Disassoc, 0, &mut []).await; |
| 619 | info!("Disassociated") | 612 | info!("Disassociated") |
| 620 | } | 613 | } |
| 621 | 614 | ||
