diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-09-22 14:17:09 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-09-22 14:17:09 +0200 |
| commit | 9db9333d0569ca8e86301f643e42abd37f3b7118 (patch) | |
| tree | da9d3a170c901867954c649a6bdc4cd55c13506d /src | |
| parent | e7d30194e370bd266d6a49d9eddbcd0866480615 (diff) | |
| parent | 483edf694b399779636b6bfd8cf243eb430d1323 (diff) | |
Merge pull request #15 from danbev/ioctl-header-type
Introduce IoctlType enum for IOCTL types
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/lib.rs b/src/lib.rs index d09be5062..a6b26188d 100644 --- a/src/lib.rs +++ b/src/lib.rs | |||
| @@ -139,6 +139,12 @@ const CHANNEL_TYPE_CONTROL: u8 = 0; | |||
| 139 | const CHANNEL_TYPE_EVENT: u8 = 1; | 139 | const CHANNEL_TYPE_EVENT: u8 = 1; |
| 140 | const CHANNEL_TYPE_DATA: u8 = 2; | 140 | const CHANNEL_TYPE_DATA: u8 = 2; |
| 141 | 141 | ||
| 142 | #[derive(Clone, Copy)] | ||
| 143 | pub enum IoctlType { | ||
| 144 | Get = 0, | ||
| 145 | Set = 2, | ||
| 146 | } | ||
| 147 | |||
| 142 | #[derive(Clone, Copy, PartialEq, Eq)] | 148 | #[derive(Clone, Copy, PartialEq, Eq)] |
| 143 | enum Core { | 149 | enum Core { |
| 144 | WLAN = 0, | 150 | WLAN = 0, |
| @@ -212,7 +218,7 @@ enum IoctlState { | |||
| 212 | Idle, | 218 | Idle, |
| 213 | 219 | ||
| 214 | Pending { | 220 | Pending { |
| 215 | kind: u32, | 221 | kind: IoctlType, |
| 216 | cmd: u32, | 222 | cmd: u32, |
| 217 | iface: u32, | 223 | iface: u32, |
| 218 | buf: *mut [u8], | 224 | buf: *mut [u8], |
| @@ -276,7 +282,7 @@ impl<'a> Control<'a> { | |||
| 276 | buf[0..8].copy_from_slice(b"clmload\x00"); | 282 | buf[0..8].copy_from_slice(b"clmload\x00"); |
| 277 | buf[8..20].copy_from_slice(&header.to_bytes()); | 283 | buf[8..20].copy_from_slice(&header.to_bytes()); |
| 278 | buf[20..][..chunk.len()].copy_from_slice(&chunk); | 284 | buf[20..][..chunk.len()].copy_from_slice(&chunk); |
| 279 | self.ioctl(2, IOCTL_CMD_SET_VAR, 0, &mut buf[..8 + 12 + chunk.len()]) | 285 | self.ioctl(IoctlType::Set, IOCTL_CMD_SET_VAR, 0, &mut buf[..8 + 12 + chunk.len()]) |
| 280 | .await; | 286 | .await; |
| 281 | } | 287 | } |
| 282 | 288 | ||
| @@ -337,7 +343,7 @@ impl<'a> Control<'a> { | |||
| 337 | Timer::after(Duration::from_millis(100)).await; | 343 | Timer::after(Duration::from_millis(100)).await; |
| 338 | 344 | ||
| 339 | // set wifi up | 345 | // set wifi up |
| 340 | self.ioctl(2, IOCTL_CMD_UP, 0, &mut []).await; | 346 | self.ioctl(IoctlType::Set, IOCTL_CMD_UP, 0, &mut []).await; |
| 341 | 347 | ||
| 342 | Timer::after(Duration::from_millis(100)).await; | 348 | Timer::after(Duration::from_millis(100)).await; |
| 343 | 349 | ||
| @@ -374,7 +380,8 @@ impl<'a> Control<'a> { | |||
| 374 | ssid: [0; 32], | 380 | ssid: [0; 32], |
| 375 | }; | 381 | }; |
| 376 | i.ssid[..ssid.len()].copy_from_slice(ssid.as_bytes()); | 382 | i.ssid[..ssid.len()].copy_from_slice(ssid.as_bytes()); |
| 377 | self.ioctl(2, IOCTL_CMD_SET_SSID, 0, &mut i.to_bytes()).await; // set_ssid | 383 | self.ioctl(IoctlType::Set, IOCTL_CMD_SET_SSID, 0, &mut i.to_bytes()) |
| 384 | .await; // set_ssid | ||
| 378 | 385 | ||
| 379 | info!("JOINED"); | 386 | info!("JOINED"); |
| 380 | } | 387 | } |
| @@ -395,7 +402,8 @@ impl<'a> Control<'a> { | |||
| 395 | passphrase: [0; 64], | 402 | passphrase: [0; 64], |
| 396 | }; | 403 | }; |
| 397 | pfi.passphrase[..passphrase.len()].copy_from_slice(passphrase.as_bytes()); | 404 | pfi.passphrase[..passphrase.len()].copy_from_slice(passphrase.as_bytes()); |
| 398 | self.ioctl(2, IOCTL_CMD_SET_PASSPHRASE, 0, &mut pfi.to_bytes()).await; // WLC_SET_WSEC_PMK | 405 | self.ioctl(IoctlType::Set, IOCTL_CMD_SET_PASSPHRASE, 0, &mut pfi.to_bytes()) |
| 406 | .await; // WLC_SET_WSEC_PMK | ||
| 399 | 407 | ||
| 400 | self.ioctl_set_u32(20, 0, 1).await; // set_infra = 1 | 408 | self.ioctl_set_u32(20, 0, 1).await; // set_infra = 1 |
| 401 | self.ioctl_set_u32(22, 0, 0).await; // set_auth = 0 (open) | 409 | self.ioctl_set_u32(22, 0, 0).await; // set_auth = 0 (open) |
| @@ -406,7 +414,7 @@ impl<'a> Control<'a> { | |||
| 406 | ssid: [0; 32], | 414 | ssid: [0; 32], |
| 407 | }; | 415 | }; |
| 408 | i.ssid[..ssid.len()].copy_from_slice(ssid.as_bytes()); | 416 | i.ssid[..ssid.len()].copy_from_slice(ssid.as_bytes()); |
| 409 | self.ioctl(2, 26, 0, &mut i.to_bytes()).await; // set_ssid | 417 | self.ioctl(IoctlType::Set, 26, 0, &mut i.to_bytes()).await; // set_ssid |
| 410 | 418 | ||
| 411 | info!("JOINED"); | 419 | info!("JOINED"); |
| 412 | } | 420 | } |
| @@ -444,7 +452,8 @@ impl<'a> Control<'a> { | |||
| 444 | buf[name.len() + 1..][..val.len()].copy_from_slice(val); | 452 | buf[name.len() + 1..][..val.len()].copy_from_slice(val); |
| 445 | 453 | ||
| 446 | let total_len = name.len() + 1 + val.len(); | 454 | let total_len = name.len() + 1 + val.len(); |
| 447 | self.ioctl(2, IOCTL_CMD_SET_VAR, 0, &mut buf[..total_len]).await; | 455 | self.ioctl(IoctlType::Set, IOCTL_CMD_SET_VAR, 0, &mut buf[..total_len]) |
| 456 | .await; | ||
| 448 | } | 457 | } |
| 449 | 458 | ||
| 450 | // TODO this is not really working, it always returns all zeros. | 459 | // TODO this is not really working, it always returns all zeros. |
| @@ -456,7 +465,9 @@ impl<'a> Control<'a> { | |||
| 456 | buf[name.len()] = 0; | 465 | buf[name.len()] = 0; |
| 457 | 466 | ||
| 458 | let total_len = max(name.len() + 1, res.len()); | 467 | let total_len = max(name.len() + 1, res.len()); |
| 459 | let res_len = self.ioctl(0, IOCTL_CMD_GET_VAR, 0, &mut buf[..total_len]).await; | 468 | let res_len = self |
| 469 | .ioctl(IoctlType::Get, IOCTL_CMD_GET_VAR, 0, &mut buf[..total_len]) | ||
| 470 | .await; | ||
| 460 | 471 | ||
| 461 | let out_len = min(res.len(), res_len); | 472 | let out_len = min(res.len(), res_len); |
| 462 | res[..out_len].copy_from_slice(&buf[..out_len]); | 473 | res[..out_len].copy_from_slice(&buf[..out_len]); |
| @@ -465,10 +476,10 @@ impl<'a> Control<'a> { | |||
| 465 | 476 | ||
| 466 | async fn ioctl_set_u32(&mut self, cmd: u32, iface: u32, val: u32) { | 477 | async fn ioctl_set_u32(&mut self, cmd: u32, iface: u32, val: u32) { |
| 467 | let mut buf = val.to_le_bytes(); | 478 | let mut buf = val.to_le_bytes(); |
| 468 | self.ioctl(2, cmd, 0, &mut buf).await; | 479 | self.ioctl(IoctlType::Set, cmd, 0, &mut buf).await; |
| 469 | } | 480 | } |
| 470 | 481 | ||
| 471 | async fn ioctl(&mut self, kind: u32, cmd: u32, iface: u32, buf: &mut [u8]) -> usize { | 482 | async fn ioctl(&mut self, kind: IoctlType, cmd: u32, iface: u32, buf: &mut [u8]) -> usize { |
| 472 | // TODO cancel ioctl on future drop. | 483 | // TODO cancel ioctl on future drop. |
| 473 | 484 | ||
| 474 | while !matches!(self.state.ioctl_state.get(), IoctlState::Idle) { | 485 | while !matches!(self.state.ioctl_state.get(), IoctlState::Idle) { |
| @@ -942,7 +953,7 @@ where | |||
| 942 | self.sdpcm_seq != self.sdpcm_seq_max && self.sdpcm_seq_max.wrapping_sub(self.sdpcm_seq) & 0x80 == 0 | 953 | self.sdpcm_seq != self.sdpcm_seq_max && self.sdpcm_seq_max.wrapping_sub(self.sdpcm_seq) & 0x80 == 0 |
| 943 | } | 954 | } |
| 944 | 955 | ||
| 945 | async fn send_ioctl(&mut self, kind: u32, cmd: u32, iface: u32, data: &[u8]) { | 956 | async fn send_ioctl(&mut self, kind: IoctlType, cmd: u32, iface: u32, data: &[u8]) { |
| 946 | let mut buf = [0; 512]; | 957 | let mut buf = [0; 512]; |
| 947 | let buf8 = slice8_mut(&mut buf); | 958 | let buf8 = slice8_mut(&mut buf); |
| 948 | 959 | ||
