diff options
Diffstat (limited to 'cyw43/src')
| -rw-r--r-- | cyw43/src/consts.rs | 1 | ||||
| -rw-r--r-- | cyw43/src/control.rs | 21 | ||||
| -rw-r--r-- | cyw43/src/fmt.rs | 18 | ||||
| -rw-r--r-- | cyw43/src/lib.rs | 2 |
4 files changed, 31 insertions, 11 deletions
diff --git a/cyw43/src/consts.rs b/cyw43/src/consts.rs index 1f6551589..4e2836f3b 100644 --- a/cyw43/src/consts.rs +++ b/cyw43/src/consts.rs | |||
| @@ -96,6 +96,7 @@ pub(crate) const IOCTL_CMD_UP: u32 = 2; | |||
| 96 | pub(crate) const IOCTL_CMD_DOWN: u32 = 3; | 96 | pub(crate) const IOCTL_CMD_DOWN: u32 = 3; |
| 97 | pub(crate) const IOCTL_CMD_SET_SSID: u32 = 26; | 97 | pub(crate) const IOCTL_CMD_SET_SSID: u32 = 26; |
| 98 | pub(crate) const IOCTL_CMD_SET_CHANNEL: u32 = 30; | 98 | pub(crate) const IOCTL_CMD_SET_CHANNEL: u32 = 30; |
| 99 | pub(crate) const IOCTL_CMD_DISASSOC: u32 = 52; | ||
| 99 | pub(crate) const IOCTL_CMD_ANTDIV: u32 = 64; | 100 | pub(crate) const IOCTL_CMD_ANTDIV: u32 = 64; |
| 100 | pub(crate) const IOCTL_CMD_SET_AP: u32 = 118; | 101 | pub(crate) const IOCTL_CMD_SET_AP: u32 = 118; |
| 101 | pub(crate) const IOCTL_CMD_SET_VAR: u32 = 263; | 102 | pub(crate) const IOCTL_CMD_SET_VAR: u32 = 263; |
diff --git a/cyw43/src/control.rs b/cyw43/src/control.rs index c67614dd6..a6d1f0bf5 100644 --- a/cyw43/src/control.rs +++ b/cyw43/src/control.rs | |||
| @@ -124,7 +124,7 @@ impl<'a> Control<'a> { | |||
| 124 | Timer::after(Duration::from_millis(100)).await; | 124 | Timer::after(Duration::from_millis(100)).await; |
| 125 | 125 | ||
| 126 | // set wifi up | 126 | // set wifi up |
| 127 | self.ioctl(IoctlType::Set, IOCTL_CMD_UP, 0, &mut []).await; | 127 | self.up().await; |
| 128 | 128 | ||
| 129 | Timer::after(Duration::from_millis(100)).await; | 129 | Timer::after(Duration::from_millis(100)).await; |
| 130 | 130 | ||
| @@ -138,6 +138,16 @@ impl<'a> Control<'a> { | |||
| 138 | debug!("INIT DONE"); | 138 | debug!("INIT DONE"); |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | /// Set the WiFi interface up. | ||
| 142 | async fn up(&mut self) { | ||
| 143 | self.ioctl(IoctlType::Set, IOCTL_CMD_UP, 0, &mut []).await; | ||
| 144 | } | ||
| 145 | |||
| 146 | /// Set the interface down. | ||
| 147 | async fn down(&mut self) { | ||
| 148 | self.ioctl(IoctlType::Set, IOCTL_CMD_DOWN, 0, &mut []).await; | ||
| 149 | } | ||
| 150 | |||
| 141 | pub async fn set_power_management(&mut self, mode: PowerManagementMode) { | 151 | pub async fn set_power_management(&mut self, mode: PowerManagementMode) { |
| 142 | // power save mode | 152 | // power save mode |
| 143 | let mode_num = mode.mode(); | 153 | let mode_num = mode.mode(); |
| @@ -256,13 +266,13 @@ impl<'a> Control<'a> { | |||
| 256 | } | 266 | } |
| 257 | 267 | ||
| 258 | // Temporarily set wifi down | 268 | // Temporarily set wifi down |
| 259 | self.ioctl(IoctlType::Set, IOCTL_CMD_DOWN, 0, &mut []).await; | 269 | self.down().await; |
| 260 | 270 | ||
| 261 | // Turn off APSTA mode | 271 | // Turn off APSTA mode |
| 262 | self.set_iovar_u32("apsta", 0).await; | 272 | self.set_iovar_u32("apsta", 0).await; |
| 263 | 273 | ||
| 264 | // Set wifi up again | 274 | // Set wifi up again |
| 265 | self.ioctl(IoctlType::Set, IOCTL_CMD_UP, 0, &mut []).await; | 275 | self.up().await; |
| 266 | 276 | ||
| 267 | // Turn on AP mode | 277 | // Turn on AP mode |
| 268 | self.ioctl_set_u32(IOCTL_CMD_SET_AP, 0, 1).await; | 278 | self.ioctl_set_u32(IOCTL_CMD_SET_AP, 0, 1).await; |
| @@ -423,6 +433,11 @@ impl<'a> Control<'a> { | |||
| 423 | events: &self.events, | 433 | events: &self.events, |
| 424 | } | 434 | } |
| 425 | } | 435 | } |
| 436 | /// Leave the wifi, with which we are currently associated. | ||
| 437 | pub async fn leave(&mut self) { | ||
| 438 | self.ioctl(IoctlType::Set, IOCTL_CMD_DISASSOC, 0, &mut []).await; | ||
| 439 | info!("Disassociated") | ||
| 440 | } | ||
| 426 | } | 441 | } |
| 427 | 442 | ||
| 428 | pub struct Scanner<'a> { | 443 | pub struct Scanner<'a> { |
diff --git a/cyw43/src/fmt.rs b/cyw43/src/fmt.rs index 9534c101c..78e583c1c 100644 --- a/cyw43/src/fmt.rs +++ b/cyw43/src/fmt.rs | |||
| @@ -83,14 +83,17 @@ macro_rules! todo { | |||
| 83 | }; | 83 | }; |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | #[cfg(not(feature = "defmt"))] | ||
| 86 | macro_rules! unreachable { | 87 | macro_rules! unreachable { |
| 87 | ($($x:tt)*) => { | 88 | ($($x:tt)*) => { |
| 88 | { | 89 | ::core::unreachable!($($x)*) |
| 89 | #[cfg(not(feature = "defmt"))] | 90 | }; |
| 90 | ::core::unreachable!($($x)*); | 91 | } |
| 91 | #[cfg(feature = "defmt")] | 92 | |
| 92 | ::defmt::unreachable!($($x)*); | 93 | #[cfg(feature = "defmt")] |
| 93 | } | 94 | macro_rules! unreachable { |
| 95 | ($($x:tt)*) => { | ||
| 96 | ::defmt::unreachable!($($x)*) | ||
| 94 | }; | 97 | }; |
| 95 | } | 98 | } |
| 96 | 99 | ||
| @@ -226,7 +229,8 @@ impl<T, E> Try for Result<T, E> { | |||
| 226 | } | 229 | } |
| 227 | } | 230 | } |
| 228 | 231 | ||
| 229 | pub struct Bytes<'a>(pub &'a [u8]); | 232 | #[allow(unused)] |
| 233 | pub(crate) struct Bytes<'a>(pub &'a [u8]); | ||
| 230 | 234 | ||
| 231 | impl<'a> Debug for Bytes<'a> { | 235 | impl<'a> Debug for Bytes<'a> { |
| 232 | fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | 236 | fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { |
diff --git a/cyw43/src/lib.rs b/cyw43/src/lib.rs index 30a3d5f26..6b124cf7f 100644 --- a/cyw43/src/lib.rs +++ b/cyw43/src/lib.rs | |||
| @@ -27,7 +27,7 @@ use ioctl::IoctlState; | |||
| 27 | 27 | ||
| 28 | use crate::bus::Bus; | 28 | use crate::bus::Bus; |
| 29 | pub use crate::bus::SpiBusCyw43; | 29 | pub use crate::bus::SpiBusCyw43; |
| 30 | pub use crate::control::{Control, Error as ControlError}; | 30 | pub use crate::control::{Control, Error as ControlError, Scanner}; |
| 31 | pub use crate::runner::Runner; | 31 | pub use crate::runner::Runner; |
| 32 | pub use crate::structs::BssInfo; | 32 | pub use crate::structs::BssInfo; |
| 33 | 33 | ||
