aboutsummaryrefslogtreecommitdiff
path: root/src/control.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/control.rs')
-rw-r--r--src/control.rs32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/control.rs b/src/control.rs
index 440246498..e1ad06e6b 100644
--- a/src/control.rs
+++ b/src/control.rs
@@ -227,6 +227,20 @@ impl<'a> Control<'a> {
227 } 227 }
228 228
229 pub async fn start_ap_open(&mut self, ssid: &str, channel: u8) { 229 pub async fn start_ap_open(&mut self, ssid: &str, channel: u8) {
230 self.start_ap(ssid, "", Security::OPEN, channel).await;
231 }
232
233 pub async fn start_ap_wpa2(&mut self, ssid: &str, passphrase: &str, channel: u8) {
234 self.start_ap(ssid, passphrase, Security::WPA2_AES_PSK, channel).await;
235 }
236
237 async fn start_ap(&mut self, ssid: &str, passphrase: &str, security: Security, channel: u8) {
238 if security != Security::OPEN
239 && (passphrase.as_bytes().len() < MIN_PSK_LEN || passphrase.as_bytes().len() > MAX_PSK_LEN)
240 {
241 panic!("Passphrase is too short or too long");
242 }
243
230 // Temporarily set wifi down 244 // Temporarily set wifi down
231 self.ioctl(IoctlType::Set, IOCTL_CMD_DOWN, 0, &mut []).await; 245 self.ioctl(IoctlType::Set, IOCTL_CMD_DOWN, 0, &mut []).await;
232 246
@@ -254,7 +268,23 @@ impl<'a> Control<'a> {
254 self.ioctl_set_u32(IOCTL_CMD_SET_CHANNEL, 0, channel as u32).await; 268 self.ioctl_set_u32(IOCTL_CMD_SET_CHANNEL, 0, channel as u32).await;
255 269
256 // Set security 270 // Set security
257 self.set_iovar_u32x2("bsscfg:wsec", 0, 0).await; // wsec = open 271 self.set_iovar_u32x2("bsscfg:wsec", 0, (security as u32) & 0xFF).await;
272
273 if security != Security::OPEN {
274 self.set_iovar_u32x2("bsscfg:wpa_auth", 0, 0x0084).await; // wpa_auth = WPA2_AUTH_PSK | WPA_AUTH_PSK
275
276 Timer::after(Duration::from_millis(100)).await;
277
278 // Set passphrase
279 let mut pfi = PassphraseInfo {
280 len: passphrase.as_bytes().len() as _,
281 flags: 1, // WSEC_PASSPHRASE
282 passphrase: [0; 64],
283 };
284 pfi.passphrase[..passphrase.as_bytes().len()].copy_from_slice(passphrase.as_bytes());
285 self.ioctl(IoctlType::Set, IOCTL_CMD_SET_PASSPHRASE, 0, &mut pfi.to_bytes())
286 .await;
287 }
258 288
259 // Change mutlicast rate from 1 Mbps to 11 Mbps 289 // Change mutlicast rate from 1 Mbps to 11 Mbps
260 self.set_iovar_u32("2g_mrate", 11000000 / 500000).await; 290 self.set_iovar_u32("2g_mrate", 11000000 / 500000).await;