diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-09-08 23:48:45 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2024-09-09 02:13:25 +0200 |
| commit | 3ac38e917cc56530fa9b3515fd28a1f576b285e8 (patch) | |
| tree | 8eb79a2fc36d9b9fc8626b90079834dd3dd983f7 /cyw43/src | |
| parent | 74e724f96869680da4893ad7024676bef1c57334 (diff) | |
cyw43: use enum for ioctl instead of consts.
Diffstat (limited to 'cyw43/src')
| -rw-r--r-- | cyw43/src/consts.rs | 299 | ||||
| -rw-r--r-- | cyw43/src/control.rs | 59 | ||||
| -rw-r--r-- | cyw43/src/ioctl.rs | 5 | ||||
| -rw-r--r-- | cyw43/src/runner.rs | 4 |
4 files changed, 319 insertions, 48 deletions
diff --git a/cyw43/src/consts.rs b/cyw43/src/consts.rs index b6e22e61d..d47e5097a 100644 --- a/cyw43/src/consts.rs +++ b/cyw43/src/consts.rs | |||
| @@ -113,17 +113,6 @@ pub(crate) const IRQ_F1_INTR: u16 = 0x2000; | |||
| 113 | pub(crate) const IRQ_F2_INTR: u16 = 0x4000; | 113 | pub(crate) const IRQ_F2_INTR: u16 = 0x4000; |
| 114 | pub(crate) const IRQ_F3_INTR: u16 = 0x8000; | 114 | pub(crate) const IRQ_F3_INTR: u16 = 0x8000; |
| 115 | 115 | ||
| 116 | pub(crate) const IOCTL_CMD_UP: u32 = 2; | ||
| 117 | pub(crate) const IOCTL_CMD_DOWN: u32 = 3; | ||
| 118 | pub(crate) const IOCTL_CMD_SET_SSID: u32 = 26; | ||
| 119 | pub(crate) const IOCTL_CMD_SET_CHANNEL: u32 = 30; | ||
| 120 | pub(crate) const IOCTL_CMD_DISASSOC: u32 = 52; | ||
| 121 | pub(crate) const IOCTL_CMD_ANTDIV: u32 = 64; | ||
| 122 | pub(crate) const IOCTL_CMD_SET_AP: u32 = 118; | ||
| 123 | pub(crate) const IOCTL_CMD_SET_VAR: u32 = 263; | ||
| 124 | pub(crate) const IOCTL_CMD_GET_VAR: u32 = 262; | ||
| 125 | pub(crate) const IOCTL_CMD_SET_PASSPHRASE: u32 = 268; | ||
| 126 | |||
| 127 | pub(crate) const CHANNEL_TYPE_CONTROL: u8 = 0; | 116 | pub(crate) const CHANNEL_TYPE_CONTROL: u8 = 0; |
| 128 | pub(crate) const CHANNEL_TYPE_EVENT: u8 = 1; | 117 | pub(crate) const CHANNEL_TYPE_EVENT: u8 = 1; |
| 129 | pub(crate) const CHANNEL_TYPE_DATA: u8 = 2; | 118 | pub(crate) const CHANNEL_TYPE_DATA: u8 = 2; |
| @@ -376,3 +365,291 @@ impl core::fmt::Display for FormatInterrupt { | |||
| 376 | core::fmt::Debug::fmt(self, f) | 365 | core::fmt::Debug::fmt(self, f) |
| 377 | } | 366 | } |
| 378 | } | 367 | } |
| 368 | |||
| 369 | #[derive(Copy, Clone, Debug)] | ||
| 370 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 371 | #[repr(u32)] | ||
| 372 | pub(crate) enum Ioctl { | ||
| 373 | GetMagic = 0, | ||
| 374 | GetVersion = 1, | ||
| 375 | Up = 2, | ||
| 376 | Down = 3, | ||
| 377 | GetLoop = 4, | ||
| 378 | SetLoop = 5, | ||
| 379 | Dump = 6, | ||
| 380 | GetMsglevel = 7, | ||
| 381 | SetMsglevel = 8, | ||
| 382 | GetPromisc = 9, | ||
| 383 | SetPromisc = 10, | ||
| 384 | GetRate = 12, | ||
| 385 | GetInstance = 14, | ||
| 386 | GetInfra = 19, | ||
| 387 | SetInfra = 20, | ||
| 388 | GetAuth = 21, | ||
| 389 | SetAuth = 22, | ||
| 390 | GetBssid = 23, | ||
| 391 | SetBssid = 24, | ||
| 392 | GetSsid = 25, | ||
| 393 | SetSsid = 26, | ||
| 394 | Restart = 27, | ||
| 395 | GetChannel = 29, | ||
| 396 | SetChannel = 30, | ||
| 397 | GetSrl = 31, | ||
| 398 | SetSrl = 32, | ||
| 399 | GetLrl = 33, | ||
| 400 | SetLrl = 34, | ||
| 401 | GetPlcphdr = 35, | ||
| 402 | SetPlcphdr = 36, | ||
| 403 | GetRadio = 37, | ||
| 404 | SetRadio = 38, | ||
| 405 | GetPhytype = 39, | ||
| 406 | DumpRate = 40, | ||
| 407 | SetRateParams = 41, | ||
| 408 | GetKey = 44, | ||
| 409 | SetKey = 45, | ||
| 410 | GetRegulatory = 46, | ||
| 411 | SetRegulatory = 47, | ||
| 412 | GetPassiveScan = 48, | ||
| 413 | SetPassiveScan = 49, | ||
| 414 | Scan = 50, | ||
| 415 | ScanResults = 51, | ||
| 416 | Disassoc = 52, | ||
| 417 | Reassoc = 53, | ||
| 418 | GetRoamTrigger = 54, | ||
| 419 | SetRoamTrigger = 55, | ||
| 420 | GetRoamDelta = 56, | ||
| 421 | SetRoamDelta = 57, | ||
| 422 | GetRoamScanPeriod = 58, | ||
| 423 | SetRoamScanPeriod = 59, | ||
| 424 | Evm = 60, | ||
| 425 | GetTxant = 61, | ||
| 426 | SetTxant = 62, | ||
| 427 | GetAntdiv = 63, | ||
| 428 | SetAntdiv = 64, | ||
| 429 | GetClosed = 67, | ||
| 430 | SetClosed = 68, | ||
| 431 | GetMaclist = 69, | ||
| 432 | SetMaclist = 70, | ||
| 433 | GetRateset = 71, | ||
| 434 | SetRateset = 72, | ||
| 435 | Longtrain = 74, | ||
| 436 | GetBcnprd = 75, | ||
| 437 | SetBcnprd = 76, | ||
| 438 | GetDtimprd = 77, | ||
| 439 | SetDtimprd = 78, | ||
| 440 | GetSrom = 79, | ||
| 441 | SetSrom = 80, | ||
| 442 | GetWepRestrict = 81, | ||
| 443 | SetWepRestrict = 82, | ||
| 444 | GetCountry = 83, | ||
| 445 | SetCountry = 84, | ||
| 446 | GetPm = 85, | ||
| 447 | SetPm = 86, | ||
| 448 | GetWake = 87, | ||
| 449 | SetWake = 88, | ||
| 450 | GetForcelink = 90, | ||
| 451 | SetForcelink = 91, | ||
| 452 | FreqAccuracy = 92, | ||
| 453 | CarrierSuppress = 93, | ||
| 454 | GetPhyreg = 94, | ||
| 455 | SetPhyreg = 95, | ||
| 456 | GetRadioreg = 96, | ||
| 457 | SetRadioreg = 97, | ||
| 458 | GetRevinfo = 98, | ||
| 459 | GetUcantdiv = 99, | ||
| 460 | SetUcantdiv = 100, | ||
| 461 | RReg = 101, | ||
| 462 | WReg = 102, | ||
| 463 | GetMacmode = 105, | ||
| 464 | SetMacmode = 106, | ||
| 465 | GetMonitor = 107, | ||
| 466 | SetMonitor = 108, | ||
| 467 | GetGmode = 109, | ||
| 468 | SetGmode = 110, | ||
| 469 | GetLegacyErp = 111, | ||
| 470 | SetLegacyErp = 112, | ||
| 471 | GetRxAnt = 113, | ||
| 472 | GetCurrRateset = 114, | ||
| 473 | GetScansuppress = 115, | ||
| 474 | SetScansuppress = 116, | ||
| 475 | GetAp = 117, | ||
| 476 | SetAp = 118, | ||
| 477 | GetEapRestrict = 119, | ||
| 478 | SetEapRestrict = 120, | ||
| 479 | ScbAuthorize = 121, | ||
| 480 | ScbDeauthorize = 122, | ||
| 481 | GetWdslist = 123, | ||
| 482 | SetWdslist = 124, | ||
| 483 | GetAtim = 125, | ||
| 484 | SetAtim = 126, | ||
| 485 | GetRssi = 127, | ||
| 486 | GetPhyantdiv = 128, | ||
| 487 | SetPhyantdiv = 129, | ||
| 488 | ApRxOnly = 130, | ||
| 489 | GetTxPathPwr = 131, | ||
| 490 | SetTxPathPwr = 132, | ||
| 491 | GetWsec = 133, | ||
| 492 | SetWsec = 134, | ||
| 493 | GetPhyNoise = 135, | ||
| 494 | GetBssInfo = 136, | ||
| 495 | GetPktcnts = 137, | ||
| 496 | GetLazywds = 138, | ||
| 497 | SetLazywds = 139, | ||
| 498 | GetBandlist = 140, | ||
| 499 | GetBand = 141, | ||
| 500 | SetBand = 142, | ||
| 501 | ScbDeauthenticate = 143, | ||
| 502 | GetShortslot = 144, | ||
| 503 | GetShortslotOverride = 145, | ||
| 504 | SetShortslotOverride = 146, | ||
| 505 | GetShortslotRestrict = 147, | ||
| 506 | SetShortslotRestrict = 148, | ||
| 507 | GetGmodeProtection = 149, | ||
| 508 | GetGmodeProtectionOverride = 150, | ||
| 509 | SetGmodeProtectionOverride = 151, | ||
| 510 | Upgrade = 152, | ||
| 511 | GetIgnoreBcns = 155, | ||
| 512 | SetIgnoreBcns = 156, | ||
| 513 | GetScbTimeout = 157, | ||
| 514 | SetScbTimeout = 158, | ||
| 515 | GetAssoclist = 159, | ||
| 516 | GetClk = 160, | ||
| 517 | SetClk = 161, | ||
| 518 | GetUp = 162, | ||
| 519 | Out = 163, | ||
| 520 | GetWpaAuth = 164, | ||
| 521 | SetWpaAuth = 165, | ||
| 522 | GetUcflags = 166, | ||
| 523 | SetUcflags = 167, | ||
| 524 | GetPwridx = 168, | ||
| 525 | SetPwridx = 169, | ||
| 526 | GetTssi = 170, | ||
| 527 | GetSupRatesetOverride = 171, | ||
| 528 | SetSupRatesetOverride = 172, | ||
| 529 | GetProtectionControl = 178, | ||
| 530 | SetProtectionControl = 179, | ||
| 531 | GetPhylist = 180, | ||
| 532 | EncryptStrength = 181, | ||
| 533 | DecryptStatus = 182, | ||
| 534 | GetKeySeq = 183, | ||
| 535 | GetScanChannelTime = 184, | ||
| 536 | SetScanChannelTime = 185, | ||
| 537 | GetScanUnassocTime = 186, | ||
| 538 | SetScanUnassocTime = 187, | ||
| 539 | GetScanHomeTime = 188, | ||
| 540 | SetScanHomeTime = 189, | ||
| 541 | GetScanNprobes = 190, | ||
| 542 | SetScanNprobes = 191, | ||
| 543 | GetPrbRespTimeout = 192, | ||
| 544 | SetPrbRespTimeout = 193, | ||
| 545 | GetAtten = 194, | ||
| 546 | SetAtten = 195, | ||
| 547 | GetShmem = 196, | ||
| 548 | SetShmem = 197, | ||
| 549 | SetWsecTest = 200, | ||
| 550 | ScbDeauthenticateForReason = 201, | ||
| 551 | TkipCountermeasures = 202, | ||
| 552 | GetPiomode = 203, | ||
| 553 | SetPiomode = 204, | ||
| 554 | SetAssocPrefer = 205, | ||
| 555 | GetAssocPrefer = 206, | ||
| 556 | SetRoamPrefer = 207, | ||
| 557 | GetRoamPrefer = 208, | ||
| 558 | SetLed = 209, | ||
| 559 | GetLed = 210, | ||
| 560 | GetInterferenceMode = 211, | ||
| 561 | SetInterferenceMode = 212, | ||
| 562 | GetChannelQa = 213, | ||
| 563 | StartChannelQa = 214, | ||
| 564 | GetChannelSel = 215, | ||
| 565 | StartChannelSel = 216, | ||
| 566 | GetValidChannels = 217, | ||
| 567 | GetFakefrag = 218, | ||
| 568 | SetFakefrag = 219, | ||
| 569 | GetPwroutPercentage = 220, | ||
| 570 | SetPwroutPercentage = 221, | ||
| 571 | SetBadFramePreempt = 222, | ||
| 572 | GetBadFramePreempt = 223, | ||
| 573 | SetLeapList = 224, | ||
| 574 | GetLeapList = 225, | ||
| 575 | GetCwmin = 226, | ||
| 576 | SetCwmin = 227, | ||
| 577 | GetCwmax = 228, | ||
| 578 | SetCwmax = 229, | ||
| 579 | GetWet = 230, | ||
| 580 | SetWet = 231, | ||
| 581 | GetPub = 232, | ||
| 582 | GetKeyPrimary = 235, | ||
| 583 | SetKeyPrimary = 236, | ||
| 584 | GetAciArgs = 238, | ||
| 585 | SetAciArgs = 239, | ||
| 586 | UnsetCallback = 240, | ||
| 587 | SetCallback = 241, | ||
| 588 | GetRadar = 242, | ||
| 589 | SetRadar = 243, | ||
| 590 | SetSpectManagment = 244, | ||
| 591 | GetSpectManagment = 245, | ||
| 592 | WdsGetRemoteHwaddr = 246, | ||
| 593 | WdsGetWpaSup = 247, | ||
| 594 | SetCsScanTimer = 248, | ||
| 595 | GetCsScanTimer = 249, | ||
| 596 | MeasureRequest = 250, | ||
| 597 | Init = 251, | ||
| 598 | SendQuiet = 252, | ||
| 599 | Keepalive = 253, | ||
| 600 | SendPwrConstraint = 254, | ||
| 601 | UpgradeStatus = 255, | ||
| 602 | CurrentPwr = 256, | ||
| 603 | GetScanPassiveTime = 257, | ||
| 604 | SetScanPassiveTime = 258, | ||
| 605 | LegacyLinkBehavior = 259, | ||
| 606 | GetChannelsInCountry = 260, | ||
| 607 | GetCountryList = 261, | ||
| 608 | GetVar = 262, | ||
| 609 | SetVar = 263, | ||
| 610 | NvramGet = 264, | ||
| 611 | NvramSet = 265, | ||
| 612 | NvramDump = 266, | ||
| 613 | Reboot = 267, | ||
| 614 | SetWsecPmk = 268, | ||
| 615 | GetAuthMode = 269, | ||
| 616 | SetAuthMode = 270, | ||
| 617 | GetWakeentry = 271, | ||
| 618 | SetWakeentry = 272, | ||
| 619 | NdconfigItem = 273, | ||
| 620 | Nvotpw = 274, | ||
| 621 | Otpw = 275, | ||
| 622 | IovBlockGet = 276, | ||
| 623 | IovModulesGet = 277, | ||
| 624 | SoftReset = 278, | ||
| 625 | GetAllowMode = 279, | ||
| 626 | SetAllowMode = 280, | ||
| 627 | GetDesiredBssid = 281, | ||
| 628 | SetDesiredBssid = 282, | ||
| 629 | DisassocMyap = 283, | ||
| 630 | GetNbands = 284, | ||
| 631 | GetBandstates = 285, | ||
| 632 | GetWlcBssInfo = 286, | ||
| 633 | GetAssocInfo = 287, | ||
| 634 | GetOidPhy = 288, | ||
| 635 | SetOidPhy = 289, | ||
| 636 | SetAssocTime = 290, | ||
| 637 | GetDesiredSsid = 291, | ||
| 638 | GetChanspec = 292, | ||
| 639 | GetAssocState = 293, | ||
| 640 | SetPhyState = 294, | ||
| 641 | GetScanPending = 295, | ||
| 642 | GetScanreqPending = 296, | ||
| 643 | GetPrevRoamReason = 297, | ||
| 644 | SetPrevRoamReason = 298, | ||
| 645 | GetBandstatesPi = 299, | ||
| 646 | GetPhyState = 300, | ||
| 647 | GetBssWpaRsn = 301, | ||
| 648 | GetBssWpa2Rsn = 302, | ||
| 649 | GetBssBcnTs = 303, | ||
| 650 | GetIntDisassoc = 304, | ||
| 651 | SetNumPeers = 305, | ||
| 652 | GetNumBss = 306, | ||
| 653 | GetWsecPmk = 318, | ||
| 654 | GetRandomBytes = 319, | ||
| 655 | } | ||
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 | ||
diff --git a/cyw43/src/ioctl.rs b/cyw43/src/ioctl.rs index 61524c274..3186370cc 100644 --- a/cyw43/src/ioctl.rs +++ b/cyw43/src/ioctl.rs | |||
| @@ -4,6 +4,7 @@ use core::task::{Poll, Waker}; | |||
| 4 | 4 | ||
| 5 | use embassy_sync::waitqueue::WakerRegistration; | 5 | use embassy_sync::waitqueue::WakerRegistration; |
| 6 | 6 | ||
| 7 | use crate::consts::Ioctl; | ||
| 7 | use crate::fmt::Bytes; | 8 | use crate::fmt::Bytes; |
| 8 | 9 | ||
| 9 | #[derive(Clone, Copy)] | 10 | #[derive(Clone, Copy)] |
| @@ -16,7 +17,7 @@ pub enum IoctlType { | |||
| 16 | pub struct PendingIoctl { | 17 | pub struct PendingIoctl { |
| 17 | pub buf: *mut [u8], | 18 | pub buf: *mut [u8], |
| 18 | pub kind: IoctlType, | 19 | pub kind: IoctlType, |
| 19 | pub cmd: u32, | 20 | pub cmd: Ioctl, |
| 20 | pub iface: u32, | 21 | pub iface: u32, |
| 21 | } | 22 | } |
| 22 | 23 | ||
| @@ -101,7 +102,7 @@ impl IoctlState { | |||
| 101 | self.state.set(IoctlStateInner::Done { resp_len: 0 }); | 102 | self.state.set(IoctlStateInner::Done { resp_len: 0 }); |
| 102 | } | 103 | } |
| 103 | 104 | ||
| 104 | pub async fn do_ioctl(&self, kind: IoctlType, cmd: u32, iface: u32, buf: &mut [u8]) -> usize { | 105 | pub async fn do_ioctl(&self, kind: IoctlType, cmd: Ioctl, iface: u32, buf: &mut [u8]) -> usize { |
| 105 | self.state | 106 | self.state |
| 106 | .set(IoctlStateInner::Pending(PendingIoctl { buf, kind, cmd, iface })); | 107 | .set(IoctlStateInner::Pending(PendingIoctl { buf, kind, cmd, iface })); |
| 107 | self.wake_runner(); | 108 | self.wake_runner(); |
diff --git a/cyw43/src/runner.rs b/cyw43/src/runner.rs index 959718341..77910b281 100644 --- a/cyw43/src/runner.rs +++ b/cyw43/src/runner.rs | |||
| @@ -560,7 +560,7 @@ where | |||
| 560 | self.sdpcm_seq != self.sdpcm_seq_max && self.sdpcm_seq_max.wrapping_sub(self.sdpcm_seq) & 0x80 == 0 | 560 | self.sdpcm_seq != self.sdpcm_seq_max && self.sdpcm_seq_max.wrapping_sub(self.sdpcm_seq) & 0x80 == 0 |
| 561 | } | 561 | } |
| 562 | 562 | ||
| 563 | async fn send_ioctl(&mut self, kind: IoctlType, cmd: u32, iface: u32, data: &[u8], buf: &mut [u32; 512]) { | 563 | async fn send_ioctl(&mut self, kind: IoctlType, cmd: Ioctl, iface: u32, data: &[u8], buf: &mut [u32; 512]) { |
| 564 | let buf8 = slice8_mut(buf); | 564 | let buf8 = slice8_mut(buf); |
| 565 | 565 | ||
| 566 | let total_len = SdpcmHeader::SIZE + CdcHeader::SIZE + data.len(); | 566 | let total_len = SdpcmHeader::SIZE + CdcHeader::SIZE + data.len(); |
| @@ -582,7 +582,7 @@ where | |||
| 582 | }; | 582 | }; |
| 583 | 583 | ||
| 584 | let cdc_header = CdcHeader { | 584 | let cdc_header = CdcHeader { |
| 585 | cmd: cmd, | 585 | cmd: cmd as u32, |
| 586 | len: data.len() as _, | 586 | len: data.len() as _, |
| 587 | flags: kind as u16 | (iface as u16) << 12, | 587 | flags: kind as u16 | (iface as u16) << 12, |
| 588 | id: self.ioctl_id, | 588 | id: self.ioctl_id, |
