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/control.rs | |
| parent | 5659269c8fb2f7d03d4a903e4ad48c8268668f0a (diff) | |
Add AP mode (unencrypted)
Diffstat (limited to 'src/control.rs')
| -rw-r--r-- | src/control.rs | 37 |
1 files changed, 37 insertions, 0 deletions
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()); |
