aboutsummaryrefslogtreecommitdiff
path: root/cyw43/src/control.rs
diff options
context:
space:
mode:
authorCirrus <[email protected]>2024-04-28 15:22:11 -0700
committerCirrus <[email protected]>2024-04-28 15:22:11 -0700
commitd2f6ce5afd9f6d2587b6b78d82dbe06437a7c96c (patch)
treece1b29c5361d42be4fb786daad44e92478a10bc0 /cyw43/src/control.rs
parent08314b0940ba212620ab268708f5aab57aff0bba (diff)
cyw43: Add function to join WPA2 network with precomputed PSK.
With flags = 0 in PassphraseInfo, CYW firmware skips the PBKDF2 PSK derivation. This makes it possible avoid storing unhashed passwords. The wpa_passphrase utility may be used to generate this PSK.
Diffstat (limited to 'cyw43/src/control.rs')
-rw-r--r--cyw43/src/control.rs45
1 files changed, 35 insertions, 10 deletions
diff --git a/cyw43/src/control.rs b/cyw43/src/control.rs
index a3808f56f..0b7123eb9 100644
--- a/cyw43/src/control.rs
+++ b/cyw43/src/control.rs
@@ -228,8 +228,12 @@ impl<'a> Control<'a> {
228 self.wait_for_join(i).await 228 self.wait_for_join(i).await
229 } 229 }
230 230
231 /// Join an protected network with the provided ssid and passphrase. 231 /// Join a protected network with the provided ssid and [`PassphraseInfo`].
232 pub async fn join_wpa2(&mut self, ssid: &str, passphrase: &str) -> Result<(), Error> { 232 pub async fn join_wpa2_passphrase_info(
233 &mut self,
234 ssid: &str,
235 passphrase_info: &mut PassphraseInfo,
236 ) -> Result<(), Error> {
233 self.set_iovar_u32("ampdu_ba_wsize", 8).await; 237 self.set_iovar_u32("ampdu_ba_wsize", 8).await;
234 238
235 self.ioctl_set_u32(134, 0, 4).await; // wsec = wpa2 239 self.ioctl_set_u32(134, 0, 4).await; // wsec = wpa2
@@ -239,14 +243,13 @@ impl<'a> Control<'a> {
239 243
240 Timer::after_millis(100).await; 244 Timer::after_millis(100).await;
241 245
242 let mut pfi = PassphraseInfo { 246 self.ioctl(
243 len: passphrase.len() as _, 247 IoctlType::Set,
244 flags: 1, 248 IOCTL_CMD_SET_PASSPHRASE,
245 passphrase: [0; 64], 249 0,
246 }; 250 &mut passphrase_info.to_bytes(),
247 pfi.passphrase[..passphrase.len()].copy_from_slice(passphrase.as_bytes()); 251 )
248 self.ioctl(IoctlType::Set, IOCTL_CMD_SET_PASSPHRASE, 0, &mut pfi.to_bytes()) 252 .await; // WLC_SET_WSEC_PMK
249 .await; // WLC_SET_WSEC_PMK
250 253
251 self.ioctl_set_u32(20, 0, 1).await; // set_infra = 1 254 self.ioctl_set_u32(20, 0, 1).await; // set_infra = 1
252 self.ioctl_set_u32(22, 0, 0).await; // set_auth = 0 (open) 255 self.ioctl_set_u32(22, 0, 0).await; // set_auth = 0 (open)
@@ -261,6 +264,28 @@ impl<'a> Control<'a> {
261 self.wait_for_join(i).await 264 self.wait_for_join(i).await
262 } 265 }
263 266
267 /// Join a protected network with the provided ssid and passphrase.
268 pub async fn join_wpa2(&mut self, ssid: &str, passphrase: &str) -> Result<(), Error> {
269 let mut pfi = PassphraseInfo {
270 len: passphrase.len() as _,
271 flags: 1,
272 passphrase: [0; 64],
273 };
274 pfi.passphrase[..passphrase.len()].copy_from_slice(passphrase.as_bytes());
275 self.join_wpa2_passphrase_info(ssid, &mut pfi).await
276 }
277
278 /// Join a protected network with the provided ssid and precomputed PSK.
279 pub async fn join_wpa2_psk(&mut self, ssid: &str, psk: &[u8; 32]) -> Result<(), Error> {
280 let mut pfi = PassphraseInfo {
281 len: psk.len() as _,
282 flags: 0,
283 passphrase: [0; 64],
284 };
285 pfi.passphrase[..psk.len()].copy_from_slice(psk);
286 self.join_wpa2_passphrase_info(ssid, &mut pfi).await
287 }
288
264 async fn wait_for_join(&mut self, i: SsidInfo) -> Result<(), Error> { 289 async fn wait_for_join(&mut self, i: SsidInfo) -> Result<(), Error> {
265 self.events.mask.enable(&[Event::SET_SSID, Event::AUTH]); 290 self.events.mask.enable(&[Event::SET_SSID, Event::AUTH]);
266 let mut subscriber = self.events.queue.subscriber().unwrap(); 291 let mut subscriber = self.events.queue.subscriber().unwrap();