aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-08-30 14:04:27 +0000
committerGitHub <[email protected]>2023-08-30 14:04:27 +0000
commit5adc80f6d9136abbaa8e0c49bcd0de2b963560f6 (patch)
tree803175f0c5b0de2ae49769db770c557ac41f04d5
parentfdb2c4946aeef968704c358fb52d5fea69e80dcc (diff)
parent98f55fa54dd4fd585e90211919f025a7025301a6 (diff)
Merge pull request #1838 from Frostie314159/cyw43-next
cyw43: Add utility functions.
-rw-r--r--cyw43/src/consts.rs1
-rw-r--r--cyw43/src/control.rs21
-rw-r--r--cyw43/src/lib.rs2
3 files changed, 20 insertions, 4 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;
96pub(crate) const IOCTL_CMD_DOWN: u32 = 3; 96pub(crate) const IOCTL_CMD_DOWN: u32 = 3;
97pub(crate) const IOCTL_CMD_SET_SSID: u32 = 26; 97pub(crate) const IOCTL_CMD_SET_SSID: u32 = 26;
98pub(crate) const IOCTL_CMD_SET_CHANNEL: u32 = 30; 98pub(crate) const IOCTL_CMD_SET_CHANNEL: u32 = 30;
99pub(crate) const IOCTL_CMD_DISASSOC: u32 = 52;
99pub(crate) const IOCTL_CMD_ANTDIV: u32 = 64; 100pub(crate) const IOCTL_CMD_ANTDIV: u32 = 64;
100pub(crate) const IOCTL_CMD_SET_AP: u32 = 118; 101pub(crate) const IOCTL_CMD_SET_AP: u32 = 118;
101pub(crate) const IOCTL_CMD_SET_VAR: u32 = 263; 102pub(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
428pub struct Scanner<'a> { 443pub struct Scanner<'a> {
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
28use crate::bus::Bus; 28use crate::bus::Bus;
29pub use crate::bus::SpiBusCyw43; 29pub use crate::bus::SpiBusCyw43;
30pub use crate::control::{Control, Error as ControlError}; 30pub use crate::control::{Control, Error as ControlError, Scanner};
31pub use crate::runner::Runner; 31pub use crate::runner::Runner;
32pub use crate::structs::BssInfo; 32pub use crate::structs::BssInfo;
33 33