aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/consts.rs3
-rw-r--r--src/control.rs37
-rw-r--r--src/structs.rs9
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;
93pub(crate) const IRQ_F3_INTR: u16 = 0x8000; 93pub(crate) const IRQ_F3_INTR: u16 = 0x8000;
94 94
95pub(crate) const IOCTL_CMD_UP: u32 = 2; 95pub(crate) const IOCTL_CMD_UP: u32 = 2;
96pub(crate) const IOCTL_CMD_DOWN: u32 = 3;
96pub(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;
97pub(crate) const IOCTL_CMD_ANTDIV: u32 = 64; 99pub(crate) const IOCTL_CMD_ANTDIV: u32 = 64;
100pub(crate) const IOCTL_CMD_SET_AP: u32 = 118;
98pub(crate) const IOCTL_CMD_SET_VAR: u32 = 263; 101pub(crate) const IOCTL_CMD_SET_VAR: u32 = 263;
99pub(crate) const IOCTL_CMD_GET_VAR: u32 = 262; 102pub(crate) const IOCTL_CMD_GET_VAR: u32 = 262;
100pub(crate) const IOCTL_CMD_SET_PASSPHRASE: u32 = 268; 103pub(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)]
395pub struct SsidInfoWithIndex {
396 pub index: u32,
397 pub ssid_info: SsidInfo,
398}
399impl_bytes!(SsidInfoWithIndex);
400
401#[derive(Clone, Copy)]
402#[cfg_attr(feature = "defmt", derive(defmt::Format))]
403#[repr(C)]
395pub struct EventMask { 404pub struct EventMask {
396 pub iface: u32, 405 pub iface: u32,
397 pub events: [u8; 24], 406 pub events: [u8; 24],