1#![allow(unused)]
2
3use defmt::{Format, println};
8use heapless::Vec;
9use num_enum::TryFromPrimitive;
10
11use crate::{
12 rpc::{
13 WireType,
14 WireType::{Len, Varint},
15 write_rpc,
16 },
17 wifi::{InitConfig, ScanConfig},
18};
19
20const MAX_DATA_SIZE: usize = 300; #[derive(Clone, Copy, PartialEq, TryFromPrimitive, Format)]
23#[repr(u16)]
24pub enum RpcId {
26 MsgIdInvalid = 0,
27 ReqBase = 256,
28 ReqGetMacAddress = 257,
29 ReqSetMacAddress = 258,
30 ReqGetWifiMode = 259,
31 ReqSetWifiMode = 260,
32
33 ReqWifiSetPs = 270,
34 ReqWifiGetPs = 271,
35
36 ReqOtaBegin = 272,
37 ReqOtaWrite = 273,
38 ReqOtaEnd = 274,
39
40 ReqWifiSetMaxTxPower = 275,
41 ReqWifiGetMaxTxPower = 276,
42
43 ReqConfigHeartbeat = 277,
44
45 ReqWifiInit = 278,
46 ReqWifiDeinit = 279,
47 ReqWifiStart = 280,
48 ReqWifiStop = 281,
49 ReqWifiConnect = 282,
50 ReqWifiDisconnect = 283,
51 ReqWifiSetConfig = 284,
52 ReqWifiGetConfig = 285,
53
54 ReqWifiScanStart = 286,
55 ReqWifiScanStop = 287,
56 ReqWifiScanGetApNum = 288,
57 ReqWifiScanGetApRecords = 289,
58 ReqWifiClearApList = 290,
59
60 ReqWifiRestore = 291,
61 ReqWifiClearFastConnect = 292,
62 ReqWifiDeauthSta = 293,
63 ReqWifiStaGetApInfo = 294,
64
65 ReqWifiSetProtocol = 297,
66 ReqWifiGetProtocol = 298,
67 ReqWifiSetBandwidth = 299,
68 ReqWifiGetBandwidth = 300,
69 ReqWifiSetChannel = 301,
70 ReqWifiGetChannel = 302,
71 ReqWifiSetCountry = 303,
72 ReqWifiGetCountry = 304,
73
74 ReqWifiSetPromiscuous = 305,
75 ReqWifiGetPromiscuous = 306,
76 ReqWifiSetPromiscuousFilter = 307,
77 ReqWifiGetPromiscuousFilter = 308,
78 ReqWifiSetPromiscuousCtrlFilter = 309,
79 ReqWifiGetPromiscuousCtrlFilter = 310,
80
81 ReqWifiApGetStaList = 311,
82 ReqWifiApGetStaAid = 312,
83 ReqWifiSetStorage = 313,
84 ReqWifiSetVendorIe = 314,
85 ReqWifiSetEventMask = 315,
86 ReqWifiGetEventMask = 316,
87 ReqWifi80211Tx = 317,
88
89 ReqWifiSetCsiConfig = 318,
90 ReqWifiSetCsi = 319,
91
92 ReqWifiSetAntGpio = 320,
93 ReqWifiGetAntGpio = 321,
94 ReqWifiSetAnt = 322,
95 ReqWifiGetAnt = 323,
96
97 ReqWifiGetTsfTime = 324,
98 ReqWifiSetInactiveTime = 325,
99 ReqWifiGetInactiveTime = 326,
100 ReqWifiStatisDump = 327,
101 ReqWifiSetRssiThreshold = 328,
102
103 ReqWifiFtmInitiateSession = 329,
104 ReqWifiFtmEndSession = 330,
105 ReqWifiFtmRespSetOffset = 331,
106
107 ReqWifiConfig11bRate = 332,
108 ReqWifiConnectionlessModuleSetWakeInterval = 333,
109 ReqWifiSetCountryCode = 334,
110 ReqWifiGetCountryCode = 335,
111 ReqWifiConfig80211TxRate = 336,
112 ReqWifiDisablePmfConfig = 337,
113 ReqWifiStaGetAid = 338,
114 ReqWifiStaGetNegotiatedPhymode = 339,
115 ReqWifiSetDynamicCs = 340,
116 ReqWifiStaGetRssi = 341,
117
118 ReqWifiSetProtocols = 342,
119 ReqWifiGetProtocols = 343,
120 ReqWifiSetBandwidths = 344,
121 ReqWifiGetBandwidths = 345,
122 ReqWifiSetBand = 346,
123 ReqWifiGetBand = 347,
124 ReqWifiSetBandMode = 348,
125 ReqWifiGetBandMode = 349,
126
127 ReqGetCoprocessorFwVersion = 350,
128 ReqWifiScanGetApRecord = 351,
129 ReqMax = 352,
130
131 RespBase = 512,
132 RespGetMacAddress = 513,
133 RespSetMacAddress = 514,
134 RespGetWifiMode = 515,
135 RespSetWifiMode = 516,
136
137 RespWifiSetPs = 526,
138 RespWifiGetPs = 527,
139
140 RespOtaBegin = 528,
141 RespOtaWrite = 529,
142 RespOtaEnd = 530,
143
144 RespWifiSetMaxTxPower = 531,
145 RespWifiGetMaxTxPower = 532,
146
147 RespConfigHeartbeat = 533,
148
149 RespWifiInit = 534,
150 RespWifiDeinit = 535,
151 RespWifiStart = 536,
152 RespWifiStop = 537,
153 RespWifiConnect = 538,
154 RespWifiDisconnect = 539,
155 RespWifiSetConfig = 540,
156 RespWifiGetConfig = 541,
157
158 RespWifiScanStart = 542,
159 RespWifiScanStop = 543,
160 RespWifiScanGetApNum = 544,
161 RespWifiScanGetApRecords = 545,
162 RespWifiClearApList = 546,
163
164 RespWifiRestore = 547,
165 RespWifiClearFastConnect = 548,
166 RespWifiDeauthSta = 549,
167 RespWifiStaGetApInfo = 550,
168
169 RespWifiSetProtocol = 553,
170 RespWifiGetProtocol = 554,
171 RespWifiSetBandwidth = 555,
172 RespWifiGetBandwidth = 556,
173 RespWifiSetChannel = 557,
174 RespWifiGetChannel = 558,
175 RespWifiSetCountry = 559,
176 RespWifiGetCountry = 560,
177
178 RespWifiSetPromiscuous = 561,
179 RespWifiGetPromiscuous = 562,
180 RespWifiSetPromiscuousFilter = 563,
181 RespWifiGetPromiscuousFilter = 564,
182 RespWifiSetPromiscuousCtrlFilter = 565,
183 RespWifiGetPromiscuousCtrlFilter = 566,
184
185 RespWifiApGetStaList = 567,
186 RespWifiApGetStaAid = 568,
187 RespWifiSetStorage = 569,
188 RespWifiSetVendorIe = 570,
189 RespWifiSetEventMask = 571,
190 RespWifiGetEventMask = 572,
191 RespWifi80211Tx = 573,
192
193 RespWifiSetCsiConfig = 574,
194 RespWifiSetCsi = 575,
195
196 RespWifiSetAntGpio = 576,
197 RespWifiGetAntGpio = 577,
198 RespWifiSetAnt = 578,
199 RespWifiGetAnt = 579,
200
201 RespWifiGetTsfTime = 580,
202 RespWifiSetInactiveTime = 581,
203 RespWifiGetInactiveTime = 582,
204 RespWifiStatisDump = 583,
205 RespWifiSetRssiThreshold = 584,
206
207 RespWifiFtmInitiateSession = 585,
208 RespWifiFtmEndSession = 586,
209 RespWifiFtmRespSetOffset = 587,
210
211 RespWifiConfig11bRate = 588,
212 RespWifiConnectionlessModuleSetWakeInterval = 589,
213 RespWifiSetCountryCode = 590,
214 RespWifiGetCountryCode = 591,
215 RespWifiConfig80211TxRate = 592,
216 RespWifiDisablePmfConfig = 593,
217 RespWifiStaGetAid = 594,
218 RespWifiStaGetNegotiatedPhymode = 595,
219 RespWifiSetDynamicCs = 596,
220 RespWifiStaGetRssi = 597,
221
222 RespWifiSetProtocols = 598,
223 RespWifiGetProtocols = 599,
224 RespWifiSetBandwidths = 600,
225 RespWifiGetBandwidths = 601,
226 RespWifiSetBand = 602,
227 RespWifiGetBand = 603,
228 RespWifiSetBandMode = 604,
229 RespWifiGetBandMode = 605,
230
231 RespGetCoprocessorFwVersion = 606,
232 RespWifiScanGetApRecord = 607,
233 RespMax = 608,
234
235 EventBase = 768,
236 EventEspInit = 769,
237 EventHeartbeat = 770,
238 EventApStaConnected = 771,
239 EventApStaDisconnected = 772,
240 EventWifiEventNoArgs = 773,
241 EventStaScanDone = 774,
242 EventStaConnected = 775,
243 EventStaDisconnected = 776,
244 EventMax = 777,
245}
246
247#[derive(Format)]
249pub struct WifiScanThreshold {
250 pub rssi: i32,
251 pub authmode: i32,
252}
253
254#[derive(Format)]
256pub struct WifiPmfConfig {
257 pub capable: bool,
258 pub required: bool,
259}
260
261pub struct WifiApConfig {
264 pub ssid: Vec<u8, 30>,
265 pub password: Vec<u8, 30>,
266 pub ssid_len: u32,
267 pub channel: u32,
268 pub authmode: i32,
269 pub ssid_hidden: u32,
270 pub max_connection: u32,
271 pub beacon_interval: u32,
272 pub pairwise_cipher: i32,
273 pub ftm_responder: bool,
274 pub pmf_cfg: WifiPmfConfig,
275 pub sae_pwe_h2e: i32,
276}
277
278pub struct WifiStaConfig {
281 pub ssid: Vec<u8, 30>,
282 pub password: Vec<u8, 30>,
283 pub scan_method: i32,
284 pub bssid_set: bool,
285 pub bssid: Vec<u8, 30>,
286 pub channel: u32,
287 pub listen_interval: u32,
288 pub sort_method: i32,
289 pub threshold: WifiScanThreshold,
290 pub pmf_cfg: WifiPmfConfig,
291 pub bitmask: u32,
292 pub sae_pwe_h2e: i32,
293 pub failure_retry_cnt: u32,
294 pub he_bitmask: u32,
295 pub sae_h2e_identifier: Vec<u8, 30>,
296}
297
298pub enum WifiConfig {
301 Ap(WifiApConfig),
302 Sta(WifiStaConfig),
303}
304
305pub struct WifiStaInfo {
308 pub mac: Vec<u8, 30>,
309 pub rssi: i32,
310 pub bitmask: u32,
311}
312
313pub struct WifiStaList {
316 pub sta: Vec<WifiStaInfo, 30>,
317 pub num: i32,
318}
319
320#[derive(Format)]
321pub struct RpcReqConfigHeartbeat {
322 pub enable: bool,
323 pub duration: i32,
325}
326
327impl RpcReqConfigHeartbeat {
328 pub fn to_bytes(&self, buf: &mut [u8]) -> usize {
329 let mut i = 0;
330
331 write_rpc(buf, 1, WireType::Varint, self.enable as u64, &mut i);
332 write_rpc(buf, 2, WireType::Varint, self.duration as u64, &mut i);
333
334 i
335 }
336}
337
338#[derive(Format)]
339pub struct EventHeartbeat {
340 pub number: u32,
342}
343
344#[derive(Format)]
346pub struct RpcReqWifiInit {
347 pub cfg: InitConfig,
348}
349
350impl RpcReqWifiInit {
351 pub fn to_bytes(&self, buf: &mut [u8]) -> usize {
352 let c = &self.cfg;
353 let v = WireType::Varint;
354
355 let mut buf_init_cfg = [0; 80]; let cfg_len = self.cfg.to_bytes(&mut buf_init_cfg);
359
360 let mut i = 0;
361 write_rpc(buf, 1, WireType::Len, cfg_len as u64, &mut i);
362
363 buf[i..i + cfg_len].copy_from_slice(&buf_init_cfg[..cfg_len]);
364 i += cfg_len;
365
366 i
367 }
368}
369
370#[derive(Default)]
372pub struct RpcReqWifiScanStart {
373 pub config: ScanConfig,
374 pub block: bool,
377 pub config_set: i32,
380}
381
382impl RpcReqWifiScanStart {
383 pub fn to_bytes(&self, buf: &mut [u8]) -> usize {
384 let mut i = 0;
385
386 let mut cfg_buf = [0; 30]; let cfg_len = self.config.to_bytes(&mut cfg_buf);
388
389 write_rpc(buf, 1, Len, cfg_len as u64, &mut i);
390 buf[i..i + cfg_len].copy_from_slice(&cfg_buf[..cfg_len]);
391 i += cfg_len;
392
393 write_rpc(buf, 2, Varint, self.block as u64, &mut i);
394 write_rpc(buf, 3, Varint, self.config_set as u64, &mut i);
395
396 i
397 }
398}
399
400#[derive(Format)]
401pub struct RpcReqWifiSetChannel {
402 pub primary: i32,
403 pub second: i32,
404}
405
406#[derive(Format)]
407pub struct RpcRespWifiGetChannel {
408 pub primary: i32,
409 pub second: i32,
410}