1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#![no_std]
use heapless::String;
use no_std_net::Ipv4Addr;
#[macro_use]
extern crate bitflags;
mod codec;
mod ids;
#[derive(Debug, Clone, PartialEq)]
pub enum Err<E> {
Parsing(nom::Err<()>),
CRCMismatch,
TXErr,
NotOurs,
RPCErr(E),
ResponseOverrun,
Unknown,
}
impl<E> From<nom::Err<()>> for Err<E> {
fn from(nom_err: nom::Err<()>) -> Self {
Err::Parsing::<E>(nom_err)
}
}
pub use codec::{FrameHeader, Header};
pub trait RPC {
type ReturnValue;
type Error;
fn header(&self, seq: u32) -> Header;
fn args(&self, _buff: &mut heapless::Vec<u8, heapless::consts::U64>) {}
fn parse(&mut self, data: &[u8]) -> Result<Self::ReturnValue, Err<Self::Error>>;
}
mod system_rpcs;
mod tcpip_rpcs;
mod wifi_rpcs;
pub mod rpcs {
pub use crate::system_rpcs::*;
pub use crate::tcpip_rpcs::*;
pub use crate::wifi_rpcs::*;
}
#[derive(Debug, Clone, Copy)]
#[repr(u32)]
pub enum L3Interface {
Station = 0,
AP = 1,
}
#[derive(Debug, Copy, Clone)]
#[repr(u32)]
pub enum WifiMode {
None = 0,
Station = 1,
AP = 2,
StationAndAP = 3,
Promiscuous = 4,
P2P = 5,
}
#[derive(Debug, Copy, Clone)]
#[allow(dead_code)]
#[repr(u32)]
pub enum BssType {
Infra = 0,
Adhoc = 1,
Any = 2,
Unknown = core::u32::MAX,
}
bitflags! {
pub struct Security: u32 {
const WEP_ENABLED = 1;
const TKIP_ENABLED = 2;
const AES_ENABLED = 4;
const AES_CMAC_ENABLED = 0x10;
const SHARED_ENABLED = 0x00008000;
const WPA_SECURITY = 0x00200000;
const WPA2_SECURITY = 0x00400000;
const WPA3_SECURITY = 0x00800000;
const WPS_ENABLED = 0x10000000;
const WEP_PSK = Self::WEP_ENABLED.bits;
const WEP_SHARED = Self::WEP_ENABLED.bits | Self::SHARED_ENABLED.bits;
const WPA_TKIP_PSK = Self::WPA_SECURITY.bits | Self::TKIP_ENABLED.bits;
const WPA_AES_PSK = Self::WPA_SECURITY.bits | Self::AES_ENABLED.bits;
const WPA2_AES_PSK = Self::WPA2_SECURITY.bits | Self::AES_ENABLED.bits;
const WPA2_TKIP_PSK = Self::WPA2_SECURITY.bits | Self::TKIP_ENABLED.bits;
const WPA2_MIXED_PSK = Self::WPA2_SECURITY.bits | Self::AES_ENABLED.bits | Self::TKIP_ENABLED.bits;
const WPA_WPA2_MIXED = Self::WPA_SECURITY.bits | Self::WPA2_SECURITY.bits;
const WPA2_AES_CMAC = Self::WPA2_SECURITY.bits | Self::AES_CMAC_ENABLED.bits;
const WPS_OPEN = Self::WPS_ENABLED.bits;
const WPS_SECURE = Self::WPS_ENABLED.bits | Self::AES_ENABLED.bits;
const WPS3_AES_PSK = Self::WPA3_SECURITY.bits | Self::AES_ENABLED.bits;
}
}
#[derive(Debug, Copy, Clone)]
#[allow(dead_code)]
#[repr(u32)]
pub enum WPS {
Default = 0x0000,
UserSpecifed = 0x0001,
MachineSpecified = 0x0002,
Rekey = 0x0003,
Pushbutton = 0x0004,
RegistrarSpecified = 0x0005,
None = 0x0006,
Wsc = 0x0007,
}
#[derive(Debug, Copy, Clone, PartialEq)]
#[allow(dead_code)]
#[repr(u32)]
pub enum Band {
_5Ghz = 0,
_24Ghz = 1,
}
#[derive(Copy, Clone)]
#[repr(packed)]
pub struct BSSID(pub [u8; 6]);
impl core::fmt::Debug for BSSID {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let table = b"0123456789abcdef";
let mut out = [0u8; 12 + 6 - 1];
for i in 0..(12 + 6 - 1) {
let b = self.0[i / 3];
out[i] = match (i + 1) % 3 {
0 => ':' as u8,
1 => table[(b >> 4) as usize],
2 => table[(b & 0xf) as usize],
_ => '?' as u8,
}
}
f.write_str(core::str::from_utf8(&out).unwrap())
}
}
#[derive(Copy, Clone)]
#[repr(packed)]
pub struct SSID {
len: u8,
value: [u8; 33],
}
impl core::fmt::Debug for SSID {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
#[allow(unused_unsafe)]
unsafe {
f.write_str(core::str::from_utf8(&self.value[..self.len as usize]).unwrap())
}
}
}
impl<N> Into<String<N>> for SSID
where
N: heapless::ArrayLength<u8>,
{
fn into(self) -> String<N> {
let mut out = String::new();
#[allow(unused_unsafe)]
unsafe {
for i in 0..self.len as usize {
out.push(self.value[i] as char).ok();
}
}
out
}
}
#[derive(Debug, Clone)]
pub struct IPInfo {
pub ip: Ipv4Addr,
pub netmask: Ipv4Addr,
pub gateway: Ipv4Addr,
}