From 4098a61ef04e42294b182f4b0bf44ced97c706a0 Mon Sep 17 00:00:00 2001 From: Frostie314159 Date: Mon, 28 Aug 2023 21:02:38 +0200 Subject: [PATCH 1/5] cyw43: Fix warning in event.rs. Allow non_upper_case_globals, to prevent the compiler from spitting out a warning about the Event enum. --- cyw43/src/events.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cyw43/src/events.rs b/cyw43/src/events.rs index a94c49a0..ce0e7e37 100644 --- a/cyw43/src/events.rs +++ b/cyw43/src/events.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -#![allow(non_camel_case_types)] +#![allow(non_camel_case_types, non_upper_case_globals)] use core::cell::RefCell; From 05ee02b5933dc8e87f3714294d272aa4cb23aefb Mon Sep 17 00:00:00 2001 From: Frostie314159 Date: Mon, 28 Aug 2023 21:32:31 +0200 Subject: [PATCH 2/5] cyw43: Introduce seperate up/down functions. Create two helper functions, for setting the interface up/down. --- cyw43/src/control.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cyw43/src/control.rs b/cyw43/src/control.rs index c67614dd..d2f6e4a0 100644 --- a/cyw43/src/control.rs +++ b/cyw43/src/control.rs @@ -124,7 +124,7 @@ impl<'a> Control<'a> { Timer::after(Duration::from_millis(100)).await; // set wifi up - self.ioctl(IoctlType::Set, IOCTL_CMD_UP, 0, &mut []).await; + self.up().await; Timer::after(Duration::from_millis(100)).await; @@ -138,6 +138,16 @@ impl<'a> Control<'a> { 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) { // power save mode let mode_num = mode.mode(); @@ -256,13 +266,13 @@ impl<'a> Control<'a> { } // Temporarily set wifi down - self.ioctl(IoctlType::Set, IOCTL_CMD_DOWN, 0, &mut []).await; + self.down().await; // Turn off APSTA mode self.set_iovar_u32("apsta", 0).await; // Set wifi up again - self.ioctl(IoctlType::Set, IOCTL_CMD_UP, 0, &mut []).await; + self.up().await; // Turn on AP mode self.ioctl_set_u32(IOCTL_CMD_SET_AP, 0, 1).await; From e0256939141ab8e4670f58e87886d0266c1d462c Mon Sep 17 00:00:00 2001 From: Frostie314159 Date: Mon, 28 Aug 2023 21:34:14 +0200 Subject: [PATCH 3/5] cyw43: Create leave function on Control struct. Create a function, which disassociates us, from the currently connected infra. --- cyw43/src/consts.rs | 1 + cyw43/src/control.rs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/cyw43/src/consts.rs b/cyw43/src/consts.rs index 1f655158..4e2836f3 100644 --- a/cyw43/src/consts.rs +++ b/cyw43/src/consts.rs @@ -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_SET_SSID: u32 = 26; 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_SET_AP: u32 = 118; pub(crate) const IOCTL_CMD_SET_VAR: u32 = 263; diff --git a/cyw43/src/control.rs b/cyw43/src/control.rs index d2f6e4a0..a6d1f0bf 100644 --- a/cyw43/src/control.rs +++ b/cyw43/src/control.rs @@ -433,6 +433,11 @@ impl<'a> Control<'a> { 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> { From 0eeefd3dbf86cc2a590a34a2e1ac2dd80204faf2 Mon Sep 17 00:00:00 2001 From: Frostie314159 Date: Tue, 29 Aug 2023 23:05:05 +0200 Subject: [PATCH 4/5] cyw43: Make Scanner public. --- cyw43/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cyw43/src/lib.rs b/cyw43/src/lib.rs index 30a3d5f2..6b124cf7 100644 --- a/cyw43/src/lib.rs +++ b/cyw43/src/lib.rs @@ -27,7 +27,7 @@ use ioctl::IoctlState; use crate::bus::Bus; 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::structs::BssInfo; From 98f55fa54dd4fd585e90211919f025a7025301a6 Mon Sep 17 00:00:00 2001 From: Frostie314159 Date: Wed, 30 Aug 2023 09:59:47 +0200 Subject: [PATCH 5/5] Reverted patch for lint fix. --- cyw43/src/events.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cyw43/src/events.rs b/cyw43/src/events.rs index ce0e7e37..a94c49a0 100644 --- a/cyw43/src/events.rs +++ b/cyw43/src/events.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -#![allow(non_camel_case_types, non_upper_case_globals)] +#![allow(non_camel_case_types)] use core::cell::RefCell;