Merge pull request #1838 from Frostie314159/cyw43-next

cyw43: Add utility functions.
This commit is contained in:
Dario Nieuwenhuis 2023-08-30 14:04:27 +00:00 committed by GitHub
commit 5adc80f6d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 4 deletions

View File

@ -96,6 +96,7 @@ pub(crate) const IOCTL_CMD_UP: u32 = 2;
pub(crate) const IOCTL_CMD_DOWN: u32 = 3; pub(crate) const IOCTL_CMD_DOWN: u32 = 3;
pub(crate) const IOCTL_CMD_SET_SSID: u32 = 26; pub(crate) const IOCTL_CMD_SET_SSID: u32 = 26;
pub(crate) const IOCTL_CMD_SET_CHANNEL: u32 = 30; pub(crate) const IOCTL_CMD_SET_CHANNEL: u32 = 30;
pub(crate) const IOCTL_CMD_DISASSOC: u32 = 52;
pub(crate) const IOCTL_CMD_ANTDIV: u32 = 64; pub(crate) const IOCTL_CMD_ANTDIV: u32 = 64;
pub(crate) const IOCTL_CMD_SET_AP: u32 = 118; pub(crate) const IOCTL_CMD_SET_AP: u32 = 118;
pub(crate) const IOCTL_CMD_SET_VAR: u32 = 263; pub(crate) const IOCTL_CMD_SET_VAR: u32 = 263;

View File

@ -124,7 +124,7 @@ impl<'a> Control<'a> {
Timer::after(Duration::from_millis(100)).await; Timer::after(Duration::from_millis(100)).await;
// set wifi up // set wifi up
self.ioctl(IoctlType::Set, IOCTL_CMD_UP, 0, &mut []).await; self.up().await;
Timer::after(Duration::from_millis(100)).await; Timer::after(Duration::from_millis(100)).await;
@ -138,6 +138,16 @@ impl<'a> Control<'a> {
debug!("INIT DONE"); debug!("INIT DONE");
} }
/// Set the WiFi interface up.
async fn up(&mut self) {
self.ioctl(IoctlType::Set, IOCTL_CMD_UP, 0, &mut []).await;
}
/// Set the interface down.
async fn down(&mut self) {
self.ioctl(IoctlType::Set, IOCTL_CMD_DOWN, 0, &mut []).await;
}
pub async fn set_power_management(&mut self, mode: PowerManagementMode) { pub async fn set_power_management(&mut self, mode: PowerManagementMode) {
// power save mode // power save mode
let mode_num = mode.mode(); let mode_num = mode.mode();
@ -256,13 +266,13 @@ impl<'a> Control<'a> {
} }
// Temporarily set wifi down // Temporarily set wifi down
self.ioctl(IoctlType::Set, IOCTL_CMD_DOWN, 0, &mut []).await; self.down().await;
// Turn off APSTA mode // Turn off APSTA mode
self.set_iovar_u32("apsta", 0).await; self.set_iovar_u32("apsta", 0).await;
// Set wifi up again // Set wifi up again
self.ioctl(IoctlType::Set, IOCTL_CMD_UP, 0, &mut []).await; self.up().await;
// Turn on AP mode // Turn on AP mode
self.ioctl_set_u32(IOCTL_CMD_SET_AP, 0, 1).await; self.ioctl_set_u32(IOCTL_CMD_SET_AP, 0, 1).await;
@ -423,6 +433,11 @@ impl<'a> Control<'a> {
events: &self.events, events: &self.events,
} }
} }
/// Leave the wifi, with which we are currently associated.
pub async fn leave(&mut self) {
self.ioctl(IoctlType::Set, IOCTL_CMD_DISASSOC, 0, &mut []).await;
info!("Disassociated")
}
} }
pub struct Scanner<'a> { pub struct Scanner<'a> {

View File

@ -27,7 +27,7 @@ use ioctl::IoctlState;
use crate::bus::Bus; use crate::bus::Bus;
pub use crate::bus::SpiBusCyw43; pub use crate::bus::SpiBusCyw43;
pub use crate::control::{Control, Error as ControlError}; pub use crate::control::{Control, Error as ControlError, Scanner};
pub use crate::runner::Runner; pub use crate::runner::Runner;
pub use crate::structs::BssInfo; pub use crate::structs::BssInfo;