diff options
| author | Satoshi Tanaka <[email protected]> | 2023-05-01 04:30:21 +0900 |
|---|---|---|
| committer | Satoshi Tanaka <[email protected]> | 2023-05-01 04:30:21 +0900 |
| commit | 099ec7443bed2183397005b4e8ebfcd2492e2b4c (patch) | |
| tree | 8dc673d4f48001b65a53d6ae4db960985d77b073 /src | |
| parent | 5659269c8fb2f7d03d4a903e4ad48c8268668f0a (diff) | |
Add AP mode (unencrypted)
Diffstat (limited to 'src')
| -rw-r--r-- | src/consts.rs | 3 | ||||
| -rw-r--r-- | src/control.rs | 37 | ||||
| -rw-r--r-- | src/structs.rs | 9 |
3 files changed, 49 insertions, 0 deletions
diff --git a/src/consts.rs b/src/consts.rs index 18502bd1a..ade3cb2c5 100644 --- a/src/consts.rs +++ b/src/consts.rs | |||
| @@ -93,8 +93,11 @@ pub(crate) const IRQ_F2_INTR: u16 = 0x4000; | |||
| 93 | pub(crate) const IRQ_F3_INTR: u16 = 0x8000; | 93 | pub(crate) const IRQ_F3_INTR: u16 = 0x8000; |
| 94 | 94 | ||
| 95 | pub(crate) const IOCTL_CMD_UP: u32 = 2; | 95 | pub(crate) const IOCTL_CMD_UP: u32 = 2; |
| 96 | pub(crate) const IOCTL_CMD_DOWN: u32 = 3; | ||
| 96 | 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; | ||
| 97 | pub(crate) const IOCTL_CMD_ANTDIV: u32 = 64; | 99 | pub(crate) const IOCTL_CMD_ANTDIV: u32 = 64; |
| 100 | pub(crate) const IOCTL_CMD_SET_AP: u32 = 118; | ||
| 98 | pub(crate) const IOCTL_CMD_SET_VAR: u32 = 263; | 101 | pub(crate) const IOCTL_CMD_SET_VAR: u32 = 263; |
| 99 | pub(crate) const IOCTL_CMD_GET_VAR: u32 = 262; | 102 | pub(crate) const IOCTL_CMD_GET_VAR: u32 = 262; |
| 100 | pub(crate) const IOCTL_CMD_SET_PASSPHRASE: u32 = 268; | 103 | pub(crate) const IOCTL_CMD_SET_PASSPHRASE: u32 = 268; |
diff --git a/src/control.rs b/src/control.rs index 934bade23..440246498 100644 --- a/src/control.rs +++ b/src/control.rs | |||
| @@ -226,6 +226,43 @@ impl<'a> Control<'a> { | |||
| 226 | .await | 226 | .await |
| 227 | } | 227 | } |
| 228 | 228 | ||
| 229 | pub async fn start_ap_open(&mut self, ssid: &str, channel: u8) { | ||
| 230 | // Temporarily set wifi down | ||
| 231 | self.ioctl(IoctlType::Set, IOCTL_CMD_DOWN, 0, &mut []).await; | ||
| 232 | |||
| 233 | // Turn off APSTA mode | ||
| 234 | self.set_iovar_u32("apsta", 0).await; | ||
| 235 | |||
| 236 | // Set wifi up again | ||
| 237 | self.ioctl(IoctlType::Set, IOCTL_CMD_UP, 0, &mut []).await; | ||
| 238 | |||
| 239 | // Turn on AP mode | ||
| 240 | self.ioctl_set_u32(IOCTL_CMD_SET_AP, 0, 1).await; | ||
| 241 | |||
| 242 | // Set SSID | ||
| 243 | let mut i = SsidInfoWithIndex { | ||
| 244 | index: 0, | ||
| 245 | ssid_info: SsidInfo { | ||
| 246 | len: ssid.as_bytes().len() as _, | ||
| 247 | ssid: [0; 32], | ||
| 248 | }, | ||
| 249 | }; | ||
| 250 | i.ssid_info.ssid[..ssid.as_bytes().len()].copy_from_slice(ssid.as_bytes()); | ||
| 251 | self.set_iovar("bsscfg:ssid", &i.to_bytes()).await; | ||
| 252 | |||
| 253 | // Set channel number | ||
| 254 | self.ioctl_set_u32(IOCTL_CMD_SET_CHANNEL, 0, channel as u32).await; | ||
| 255 | |||
| 256 | // Set security | ||
| 257 | self.set_iovar_u32x2("bsscfg:wsec", 0, 0).await; // wsec = open | ||
| 258 | |||
| 259 | // Change mutlicast rate from 1 Mbps to 11 Mbps | ||
| 260 | self.set_iovar_u32("2g_mrate", 11000000 / 500000).await; | ||
| 261 | |||
| 262 | // Start AP | ||
| 263 | self.set_iovar_u32x2("bss", 0, 1).await; // bss = BSS_UP | ||
| 264 | } | ||
| 265 | |||
| 229 | async fn set_iovar_u32x2(&mut self, name: &str, val1: u32, val2: u32) { | 266 | async fn set_iovar_u32x2(&mut self, name: &str, val1: u32, val2: u32) { |
| 230 | let mut buf = [0; 8]; | 267 | let mut buf = [0; 8]; |
| 231 | buf[0..4].copy_from_slice(&val1.to_le_bytes()); | 268 | buf[0..4].copy_from_slice(&val1.to_le_bytes()); |
diff --git a/src/structs.rs b/src/structs.rs index d01d5a65c..3b646e1a8 100644 --- a/src/structs.rs +++ b/src/structs.rs | |||
| @@ -392,6 +392,15 @@ impl_bytes!(PassphraseInfo); | |||
| 392 | #[derive(Clone, Copy)] | 392 | #[derive(Clone, Copy)] |
| 393 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 393 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 394 | #[repr(C)] | 394 | #[repr(C)] |
| 395 | pub struct SsidInfoWithIndex { | ||
| 396 | pub index: u32, | ||
| 397 | pub ssid_info: SsidInfo, | ||
| 398 | } | ||
| 399 | impl_bytes!(SsidInfoWithIndex); | ||
| 400 | |||
| 401 | #[derive(Clone, Copy)] | ||
| 402 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 403 | #[repr(C)] | ||
| 395 | pub struct EventMask { | 404 | pub struct EventMask { |
| 396 | pub iface: u32, | 405 | pub iface: u32, |
| 397 | pub events: [u8; 24], | 406 | pub events: [u8; 24], |
