From 252664c1b0b4d81c34953c92bdcec84f7b5d3986 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 29 Oct 2025 18:24:57 +0100 Subject: net-esp-hosted: switch from noproto to micropb. --- embassy-net-esp-hosted/Cargo.toml | 5 +- embassy-net-esp-hosted/build.rs | 33 ++ embassy-net-esp-hosted/src/control.rs | 69 ++-- embassy-net-esp-hosted/src/lib.rs | 28 +- embassy-net-esp-hosted/src/proto.rs | 656 ---------------------------------- 5 files changed, 94 insertions(+), 697 deletions(-) create mode 100644 embassy-net-esp-hosted/build.rs delete mode 100644 embassy-net-esp-hosted/src/proto.rs (limited to 'embassy-net-esp-hosted') diff --git a/embassy-net-esp-hosted/Cargo.toml b/embassy-net-esp-hosted/Cargo.toml index f148f4762..2442b3235 100644 --- a/embassy-net-esp-hosted/Cargo.toml +++ b/embassy-net-esp-hosted/Cargo.toml @@ -25,9 +25,12 @@ embassy-net-driver-channel = { version = "0.3.2", path = "../embassy-net-driver- embedded-hal = { version = "1.0" } embedded-hal-async = { version = "1.0" } -noproto = "0.1.0" +micropb = { version = "0.4.0", default-features = false, features = ["container-heapless", "encode", "decode"] } heapless = "0.8" +[build-dependencies] +micropb-gen = "0.4.0" + [package.metadata.embassy_docs] src_base = "https://github.com/embassy-rs/embassy/blob/embassy-net-esp-hosted-v$VERSION/embassy-net-esp-hosted/src/" src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-net-esp-hosted/src/" diff --git a/embassy-net-esp-hosted/build.rs b/embassy-net-esp-hosted/build.rs new file mode 100644 index 000000000..1e9b8cffd --- /dev/null +++ b/embassy-net-esp-hosted/build.rs @@ -0,0 +1,33 @@ +fn main() { + let out_dir = std::env::var("OUT_DIR").unwrap(); + + let mut g = micropb_gen::Generator::new(); + g.use_container_heapless(); + + g.configure( + ".", + micropb_gen::Config::new() + .max_bytes(32) // For ssid, mac, etc - strings + .max_len(16) // For repeated fields + .type_attributes("#[cfg_attr(feature = \"defmt\", derive(defmt::Format))]"), + ); + + // Special config for things that need to be larger + g.configure( + ".CtrlMsg_Req_OTAWrite.ota_data", + micropb_gen::Config::new().max_bytes(1024), + ); + g.configure( + ".CtrlMsg_Event_ESPInit.init_data", + micropb_gen::Config::new().max_bytes(64), + ); + g.configure( + ".CtrlMsg_Req_VendorIEData.payload", + micropb_gen::Config::new().max_bytes(64), + ); + + g.compile_protos(&["src/esp_hosted_config.proto"], format!("{}/proto.rs", out_dir)) + .unwrap(); + + println!("cargo:rerun-if-changed=src/esp_hosted_config.proto"); +} diff --git a/embassy-net-esp-hosted/src/control.rs b/embassy-net-esp-hosted/src/control.rs index cbc194877..a7f5168c2 100644 --- a/embassy-net-esp-hosted/src/control.rs +++ b/embassy-net-esp-hosted/src/control.rs @@ -1,6 +1,7 @@ use embassy_net_driver_channel as ch; use embassy_net_driver_channel::driver::{HardwareAddress, LinkState}; use heapless::String; +use micropb::{MessageDecode, MessageEncode, PbEncoder}; use crate::ioctl::Shared; use crate::proto::{self, CtrlMsg}; @@ -38,7 +39,7 @@ enum WifiMode { ApSta = 3, } -pub use proto::CtrlWifiSecProt as Security; +pub use proto::Ctrl_WifiSecProt as Security; /// WiFi status. #[derive(Clone, Debug)] @@ -59,18 +60,18 @@ pub struct Status { macro_rules! ioctl { ($self:ident, $req_variant:ident, $resp_variant:ident, $req:ident, $resp:ident) => { let mut msg = proto::CtrlMsg { - msg_id: proto::CtrlMsgId::$req_variant as _, - msg_type: proto::CtrlMsgType::Req as _, - payload: Some(proto::CtrlMsgPayload::$req_variant($req)), + r#msg_id: proto::CtrlMsgId::$req_variant, + r#msg_type: proto::CtrlMsgType::Req, + r#payload: Some(proto::CtrlMsg_::Payload::$req_variant($req)), }; $self.ioctl(&mut msg).await?; #[allow(unused_mut)] - let Some(proto::CtrlMsgPayload::$resp_variant(mut $resp)) = msg.payload else { + let Some(proto::CtrlMsg_::Payload::$resp_variant(mut $resp)) = msg.payload else { warn!("unexpected response variant"); return Err(Error::Internal); }; if $resp.resp != 0 { - return Err(Error::Failed($resp.resp)); + return Err(Error::Failed($resp.resp as u32)); } }; } @@ -100,26 +101,28 @@ impl<'a> Control<'a> { /// Get the current status. pub async fn get_status(&mut self) -> Result { - let req = proto::CtrlMsgReqGetApConfig {}; + let req = proto::CtrlMsg_Req_GetAPConfig {}; ioctl!(self, ReqGetApConfig, RespGetApConfig, req, resp); - trim_nulls(&mut resp.ssid); + let ssid = core::str::from_utf8(&resp.ssid).map_err(|_| Error::Internal)?; + let ssid = String::try_from(ssid.trim_end_matches('\0')).map_err(|_| Error::Internal)?; + let bssid_str = core::str::from_utf8(&resp.bssid).map_err(|_| Error::Internal)?; Ok(Status { - ssid: resp.ssid, - bssid: parse_mac(&resp.bssid)?, + ssid, + bssid: parse_mac(bssid_str)?, rssi: resp.rssi as _, - channel: resp.chnl, + channel: resp.chnl as u32, security: resp.sec_prot, }) } /// Connect to the network identified by ssid using the provided password. pub async fn connect(&mut self, ssid: &str, password: &str) -> Result<(), Error> { - let req = proto::CtrlMsgReqConnectAp { - ssid: unwrap!(String::try_from(ssid)), - pwd: unwrap!(String::try_from(password)), - bssid: String::new(), - listen_interval: 3, - is_wpa3_supported: true, + let req = proto::CtrlMsg_Req_ConnectAP { + r#ssid: unwrap!(String::try_from(ssid)), + r#pwd: unwrap!(String::try_from(password)), + r#bssid: String::new(), + r#listen_interval: 3, + r#is_wpa3_supported: true, }; ioctl!(self, ReqConnectAp, RespConnectAp, req, resp); self.state_ch.set_link_state(LinkState::Up); @@ -128,7 +131,7 @@ impl<'a> Control<'a> { /// Disconnect from any currently connected network. pub async fn disconnect(&mut self) -> Result<(), Error> { - let req = proto::CtrlMsgReqGetStatus {}; + let req = proto::CtrlMsg_Req_GetStatus {}; ioctl!(self, ReqDisconnectAp, RespDisconnectAp, req, resp); self.state_ch.set_link_state(LinkState::Down); Ok(()) @@ -136,21 +139,25 @@ impl<'a> Control<'a> { /// duration in seconds, clamped to [10, 3600] async fn set_heartbeat(&mut self, duration: u32) -> Result<(), Error> { - let req = proto::CtrlMsgReqConfigHeartbeat { enable: true, duration }; + let req = proto::CtrlMsg_Req_ConfigHeartbeat { + r#enable: true, + r#duration: duration as i32, + }; ioctl!(self, ReqConfigHeartbeat, RespConfigHeartbeat, req, resp); Ok(()) } async fn get_mac_addr(&mut self) -> Result<[u8; 6], Error> { - let req = proto::CtrlMsgReqGetMacAddress { - mode: WifiMode::Sta as _, + let req = proto::CtrlMsg_Req_GetMacAddress { + r#mode: WifiMode::Sta as _, }; ioctl!(self, ReqGetMacAddress, RespGetMacAddress, req, resp); - parse_mac(&resp.mac) + let mac_str = core::str::from_utf8(&resp.mac).map_err(|_| Error::Internal)?; + parse_mac(mac_str) } async fn set_wifi_mode(&mut self, mode: u32) -> Result<(), Error> { - let req = proto::CtrlMsgReqSetMode { mode }; + let req = proto::CtrlMsg_Req_SetMode { r#mode: mode as i32 }; ioctl!(self, ReqSetWifiMode, RespSetWifiMode, req, resp); Ok(()) @@ -160,11 +167,15 @@ impl<'a> Control<'a> { debug!("ioctl req: {:?}", &msg); let mut buf = [0u8; 128]; + let buf_len = buf.len(); - let req_len = noproto::write(msg, &mut buf).map_err(|_| { + let mut encoder = PbEncoder::new(&mut buf[..]); + msg.encode(&mut encoder).map_err(|_| { warn!("failed to serialize control request"); Error::Internal })?; + let remaining = encoder.into_writer(); + let req_len = buf_len - remaining.len(); struct CancelOnDrop<'a>(&'a Shared); @@ -186,8 +197,8 @@ impl<'a> Control<'a> { ioctl.defuse(); - *msg = noproto::read(&buf[..resp_len]).map_err(|_| { - warn!("failed to serialize control request"); + msg.decode_from_bytes(&buf[..resp_len]).map_err(|_| { + warn!("failed to deserialize control response"); Error::Internal })?; debug!("ioctl resp: {:?}", msg); @@ -221,9 +232,3 @@ fn parse_mac(mac: &str) -> Result<[u8; 6], Error> { } Ok(res) } - -fn trim_nulls(s: &mut String) { - while s.chars().rev().next() == Some(0 as char) { - s.pop(); - } -} diff --git a/embassy-net-esp-hosted/src/lib.rs b/embassy-net-esp-hosted/src/lib.rs index 8da0cd4dc..1fbed3e83 100644 --- a/embassy-net-esp-hosted/src/lib.rs +++ b/embassy-net-esp-hosted/src/lib.rs @@ -10,9 +10,19 @@ use embassy_time::{Duration, Instant, Timer}; use embedded_hal::digital::OutputPin; use crate::ioctl::{PendingIoctl, Shared}; -use crate::proto::{CtrlMsg, CtrlMsgPayload}; - -mod proto; +use crate::proto::{CtrlMsg, CtrlMsg_}; + +mod proto { + #![allow(unused)] + #![allow(non_snake_case)] + #![allow(non_camel_case_types)] + #![allow(non_upper_case_globals)] + #![allow(missing_docs)] + #![allow(clippy::all)] + + // Include the generated protobuf code from micropb-gen + include!(concat!(env!("OUT_DIR"), "/proto.rs")); +} // must be first mod fmt; @@ -313,10 +323,12 @@ where } fn handle_event(&mut self, data: &[u8]) { - let Ok(event) = noproto::read::(data) else { + use micropb::MessageDecode; + let mut event = CtrlMsg::default(); + if event.decode_from_bytes(data).is_err() { warn!("failed to parse event"); return; - }; + } debug!("event: {:?}", &event); @@ -326,9 +338,9 @@ where }; match payload { - CtrlMsgPayload::EventEspInit(_) => self.shared.init_done(), - CtrlMsgPayload::EventHeartbeat(_) => self.heartbeat_deadline = Instant::now() + HEARTBEAT_MAX_GAP, - CtrlMsgPayload::EventStationDisconnectFromAp(e) => { + CtrlMsg_::Payload::EventEspInit(_) => self.shared.init_done(), + CtrlMsg_::Payload::EventHeartbeat(_) => self.heartbeat_deadline = Instant::now() + HEARTBEAT_MAX_GAP, + CtrlMsg_::Payload::EventStationDisconnectFromAp(e) => { info!("disconnected, code {}", e.resp); self.state_ch.set_link_state(LinkState::Down); } diff --git a/embassy-net-esp-hosted/src/proto.rs b/embassy-net-esp-hosted/src/proto.rs deleted file mode 100644 index 089ded677..000000000 --- a/embassy-net-esp-hosted/src/proto.rs +++ /dev/null @@ -1,656 +0,0 @@ -#![allow(unused)] - -use heapless::{String, Vec}; - -/// internal supporting structures for CtrlMsg - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct ScanResult { - #[noproto(tag = "1")] - pub ssid: String<32>, - #[noproto(tag = "2")] - pub chnl: u32, - #[noproto(tag = "3")] - pub rssi: u32, - #[noproto(tag = "4")] - pub bssid: String<32>, - #[noproto(tag = "5")] - pub sec_prot: CtrlWifiSecProt, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct ConnectedStaList { - #[noproto(tag = "1")] - pub mac: String<32>, - #[noproto(tag = "2")] - pub rssi: u32, -} -/// * Req/Resp structure * - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgReqGetMacAddress { - #[noproto(tag = "1")] - pub mode: u32, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgRespGetMacAddress { - #[noproto(tag = "1")] - pub mac: String<32>, - #[noproto(tag = "2")] - pub resp: u32, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgReqGetMode {} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgRespGetMode { - #[noproto(tag = "1")] - pub mode: u32, - #[noproto(tag = "2")] - pub resp: u32, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgReqSetMode { - #[noproto(tag = "1")] - pub mode: u32, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgRespSetMode { - #[noproto(tag = "1")] - pub resp: u32, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgReqGetStatus {} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgRespGetStatus { - #[noproto(tag = "1")] - pub resp: u32, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgReqSetMacAddress { - #[noproto(tag = "1")] - pub mac: String<32>, - #[noproto(tag = "2")] - pub mode: u32, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgRespSetMacAddress { - #[noproto(tag = "1")] - pub resp: u32, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgReqGetApConfig {} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgRespGetApConfig { - #[noproto(tag = "1")] - pub ssid: String<32>, - #[noproto(tag = "2")] - pub bssid: String<32>, - #[noproto(tag = "3")] - pub rssi: u32, - #[noproto(tag = "4")] - pub chnl: u32, - #[noproto(tag = "5")] - pub sec_prot: CtrlWifiSecProt, - #[noproto(tag = "6")] - pub resp: u32, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgReqConnectAp { - #[noproto(tag = "1")] - pub ssid: String<32>, - #[noproto(tag = "2")] - pub pwd: String<32>, - #[noproto(tag = "3")] - pub bssid: String<32>, - #[noproto(tag = "4")] - pub is_wpa3_supported: bool, - #[noproto(tag = "5")] - pub listen_interval: u32, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgRespConnectAp { - #[noproto(tag = "1")] - pub resp: u32, - #[noproto(tag = "2")] - pub mac: String<32>, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgReqGetSoftApConfig {} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgRespGetSoftApConfig { - #[noproto(tag = "1")] - pub ssid: String<32>, - #[noproto(tag = "2")] - pub pwd: String<32>, - #[noproto(tag = "3")] - pub chnl: u32, - #[noproto(tag = "4")] - pub sec_prot: CtrlWifiSecProt, - #[noproto(tag = "5")] - pub max_conn: u32, - #[noproto(tag = "6")] - pub ssid_hidden: bool, - #[noproto(tag = "7")] - pub bw: u32, - #[noproto(tag = "8")] - pub resp: u32, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgReqStartSoftAp { - #[noproto(tag = "1")] - pub ssid: String<32>, - #[noproto(tag = "2")] - pub pwd: String<32>, - #[noproto(tag = "3")] - pub chnl: u32, - #[noproto(tag = "4")] - pub sec_prot: CtrlWifiSecProt, - #[noproto(tag = "5")] - pub max_conn: u32, - #[noproto(tag = "6")] - pub ssid_hidden: bool, - #[noproto(tag = "7")] - pub bw: u32, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgRespStartSoftAp { - #[noproto(tag = "1")] - pub resp: u32, - #[noproto(tag = "2")] - pub mac: String<32>, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgReqScanResult {} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgRespScanResult { - #[noproto(tag = "1")] - pub count: u32, - #[noproto(repeated, tag = "2")] - pub entries: Vec, - #[noproto(tag = "3")] - pub resp: u32, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgReqSoftApConnectedSta {} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgRespSoftApConnectedSta { - #[noproto(tag = "1")] - pub num: u32, - #[noproto(repeated, tag = "2")] - pub stations: Vec, - #[noproto(tag = "3")] - pub resp: u32, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgReqOtaBegin {} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgRespOtaBegin { - #[noproto(tag = "1")] - pub resp: u32, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgReqOtaWrite { - #[noproto(tag = "1")] - pub ota_data: Vec, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgRespOtaWrite { - #[noproto(tag = "1")] - pub resp: u32, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgReqOtaEnd {} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgRespOtaEnd { - #[noproto(tag = "1")] - pub resp: u32, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgReqVendorIeData { - #[noproto(tag = "1")] - pub element_id: u32, - #[noproto(tag = "2")] - pub length: u32, - #[noproto(tag = "3")] - pub vendor_oui: Vec, - #[noproto(tag = "4")] - pub vendor_oui_type: u32, - #[noproto(tag = "5")] - pub payload: Vec, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgReqSetSoftApVendorSpecificIe { - #[noproto(tag = "1")] - pub enable: bool, - #[noproto(tag = "2")] - pub r#type: CtrlVendorIeType, - #[noproto(tag = "3")] - pub idx: CtrlVendorIeid, - #[noproto(optional, tag = "4")] - pub vendor_ie_data: Option, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgRespSetSoftApVendorSpecificIe { - #[noproto(tag = "1")] - pub resp: u32, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgReqSetWifiMaxTxPower { - #[noproto(tag = "1")] - pub wifi_max_tx_power: u32, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgRespSetWifiMaxTxPower { - #[noproto(tag = "1")] - pub resp: u32, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgReqGetWifiCurrTxPower {} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgRespGetWifiCurrTxPower { - #[noproto(tag = "1")] - pub wifi_curr_tx_power: u32, - #[noproto(tag = "2")] - pub resp: u32, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgReqConfigHeartbeat { - #[noproto(tag = "1")] - pub enable: bool, - #[noproto(tag = "2")] - pub duration: u32, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgRespConfigHeartbeat { - #[noproto(tag = "1")] - pub resp: u32, -} -/// * Event structure * - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgEventEspInit { - #[noproto(tag = "1")] - pub init_data: Vec, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgEventHeartbeat { - #[noproto(tag = "1")] - pub hb_num: u32, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgEventStationDisconnectFromAp { - #[noproto(tag = "1")] - pub resp: u32, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsgEventStationDisconnectFromEspSoftAp { - #[noproto(tag = "1")] - pub resp: u32, - #[noproto(tag = "2")] - pub mac: String<32>, -} - -#[derive(Debug, Default, Clone, Eq, PartialEq, noproto::Message)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) struct CtrlMsg { - /// msg_type could be req, resp or Event - #[noproto(tag = "1")] - pub msg_type: CtrlMsgType, - /// msg id - #[noproto(tag = "2")] - pub msg_id: CtrlMsgId, - /// union of all msg ids - #[noproto( - oneof, - tags = "101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 301, 302, 303, 304" - )] - pub payload: Option, -} - -/// union of all msg ids -#[derive(Debug, Clone, Eq, PartialEq, noproto::Oneof)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) enum CtrlMsgPayload { - /// * Requests * - #[noproto(tag = "101")] - ReqGetMacAddress(CtrlMsgReqGetMacAddress), - #[noproto(tag = "102")] - ReqSetMacAddress(CtrlMsgReqSetMacAddress), - #[noproto(tag = "103")] - ReqGetWifiMode(CtrlMsgReqGetMode), - #[noproto(tag = "104")] - ReqSetWifiMode(CtrlMsgReqSetMode), - #[noproto(tag = "105")] - ReqScanApList(CtrlMsgReqScanResult), - #[noproto(tag = "106")] - ReqGetApConfig(CtrlMsgReqGetApConfig), - #[noproto(tag = "107")] - ReqConnectAp(CtrlMsgReqConnectAp), - #[noproto(tag = "108")] - ReqDisconnectAp(CtrlMsgReqGetStatus), - #[noproto(tag = "109")] - ReqGetSoftapConfig(CtrlMsgReqGetSoftApConfig), - #[noproto(tag = "110")] - ReqSetSoftapVendorSpecificIe(CtrlMsgReqSetSoftApVendorSpecificIe), - #[noproto(tag = "111")] - ReqStartSoftap(CtrlMsgReqStartSoftAp), - #[noproto(tag = "112")] - ReqSoftapConnectedStasList(CtrlMsgReqSoftApConnectedSta), - #[noproto(tag = "113")] - ReqStopSoftap(CtrlMsgReqGetStatus), - #[noproto(tag = "114")] - ReqSetPowerSaveMode(CtrlMsgReqSetMode), - #[noproto(tag = "115")] - ReqGetPowerSaveMode(CtrlMsgReqGetMode), - #[noproto(tag = "116")] - ReqOtaBegin(CtrlMsgReqOtaBegin), - #[noproto(tag = "117")] - ReqOtaWrite(CtrlMsgReqOtaWrite), - #[noproto(tag = "118")] - ReqOtaEnd(CtrlMsgReqOtaEnd), - #[noproto(tag = "119")] - ReqSetWifiMaxTxPower(CtrlMsgReqSetWifiMaxTxPower), - #[noproto(tag = "120")] - ReqGetWifiCurrTxPower(CtrlMsgReqGetWifiCurrTxPower), - #[noproto(tag = "121")] - ReqConfigHeartbeat(CtrlMsgReqConfigHeartbeat), - /// * Responses * - #[noproto(tag = "201")] - RespGetMacAddress(CtrlMsgRespGetMacAddress), - #[noproto(tag = "202")] - RespSetMacAddress(CtrlMsgRespSetMacAddress), - #[noproto(tag = "203")] - RespGetWifiMode(CtrlMsgRespGetMode), - #[noproto(tag = "204")] - RespSetWifiMode(CtrlMsgRespSetMode), - #[noproto(tag = "205")] - RespScanApList(CtrlMsgRespScanResult), - #[noproto(tag = "206")] - RespGetApConfig(CtrlMsgRespGetApConfig), - #[noproto(tag = "207")] - RespConnectAp(CtrlMsgRespConnectAp), - #[noproto(tag = "208")] - RespDisconnectAp(CtrlMsgRespGetStatus), - #[noproto(tag = "209")] - RespGetSoftapConfig(CtrlMsgRespGetSoftApConfig), - #[noproto(tag = "210")] - RespSetSoftapVendorSpecificIe(CtrlMsgRespSetSoftApVendorSpecificIe), - #[noproto(tag = "211")] - RespStartSoftap(CtrlMsgRespStartSoftAp), - #[noproto(tag = "212")] - RespSoftapConnectedStasList(CtrlMsgRespSoftApConnectedSta), - #[noproto(tag = "213")] - RespStopSoftap(CtrlMsgRespGetStatus), - #[noproto(tag = "214")] - RespSetPowerSaveMode(CtrlMsgRespSetMode), - #[noproto(tag = "215")] - RespGetPowerSaveMode(CtrlMsgRespGetMode), - #[noproto(tag = "216")] - RespOtaBegin(CtrlMsgRespOtaBegin), - #[noproto(tag = "217")] - RespOtaWrite(CtrlMsgRespOtaWrite), - #[noproto(tag = "218")] - RespOtaEnd(CtrlMsgRespOtaEnd), - #[noproto(tag = "219")] - RespSetWifiMaxTxPower(CtrlMsgRespSetWifiMaxTxPower), - #[noproto(tag = "220")] - RespGetWifiCurrTxPower(CtrlMsgRespGetWifiCurrTxPower), - #[noproto(tag = "221")] - RespConfigHeartbeat(CtrlMsgRespConfigHeartbeat), - /// * Notifications * - #[noproto(tag = "301")] - EventEspInit(CtrlMsgEventEspInit), - #[noproto(tag = "302")] - EventHeartbeat(CtrlMsgEventHeartbeat), - #[noproto(tag = "303")] - EventStationDisconnectFromAp(CtrlMsgEventStationDisconnectFromAp), - #[noproto(tag = "304")] - EventStationDisconnectFromEspSoftAp(CtrlMsgEventStationDisconnectFromEspSoftAp), -} - -/// Enums similar to ESP IDF -#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord, noproto::Enumeration)] -#[repr(u32)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) enum CtrlVendorIeType { - #[default] - Beacon = 0, - ProbeReq = 1, - ProbeResp = 2, - AssocReq = 3, - AssocResp = 4, -} - -#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord, noproto::Enumeration)] -#[repr(u32)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) enum CtrlVendorIeid { - #[default] - Id0 = 0, - Id1 = 1, -} - -#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord, noproto::Enumeration)] -#[repr(u32)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) enum CtrlWifiMode { - #[default] - None = 0, - Sta = 1, - Ap = 2, - Apsta = 3, -} - -#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord, noproto::Enumeration)] -#[repr(u32)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) enum CtrlWifiBw { - #[default] - BwInvalid = 0, - Ht20 = 1, - Ht40 = 2, -} - -#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord, noproto::Enumeration)] -#[repr(u32)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) enum CtrlWifiPowerSave { - #[default] - PsInvalid = 0, - MinModem = 1, - MaxModem = 2, -} - -/// Wifi Security Settings -#[allow(missing_docs)] -#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord, noproto::Enumeration)] -#[repr(u32)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub enum CtrlWifiSecProt { - #[default] - Open = 0, - Wep = 1, - WpaPsk = 2, - Wpa2Psk = 3, - WpaWpa2Psk = 4, - Wpa2Enterprise = 5, - Wpa3Psk = 6, - Wpa2Wpa3Psk = 7, -} - -/// enums for Control path -#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord, noproto::Enumeration)] -#[repr(u32)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) enum CtrlStatus { - #[default] - Connected = 0, - NotConnected = 1, - NoApFound = 2, - ConnectionFail = 3, - InvalidArgument = 4, - OutOfRange = 5, -} - -#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord, noproto::Enumeration)] -#[repr(u32)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) enum CtrlMsgType { - #[default] - MsgTypeInvalid = 0, - Req = 1, - Resp = 2, - Event = 3, - MsgTypeMax = 4, -} - -#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord, noproto::Enumeration)] -#[repr(u32)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub(crate) enum CtrlMsgId { - #[default] - MsgIdInvalid = 0, - /// * Request Msgs * - ReqBase = 100, - ReqGetMacAddress = 101, - ReqSetMacAddress = 102, - ReqGetWifiMode = 103, - ReqSetWifiMode = 104, - ReqGetApScanList = 105, - ReqGetApConfig = 106, - ReqConnectAp = 107, - ReqDisconnectAp = 108, - ReqGetSoftApConfig = 109, - ReqSetSoftApVendorSpecificIe = 110, - ReqStartSoftAp = 111, - ReqGetSoftApConnectedStaList = 112, - ReqStopSoftAp = 113, - ReqSetPowerSaveMode = 114, - ReqGetPowerSaveMode = 115, - ReqOtaBegin = 116, - ReqOtaWrite = 117, - ReqOtaEnd = 118, - ReqSetWifiMaxTxPower = 119, - ReqGetWifiCurrTxPower = 120, - ReqConfigHeartbeat = 121, - /// Add new control path command response before Req_Max - /// and update Req_Max - ReqMax = 122, - /// * Response Msgs * - RespBase = 200, - RespGetMacAddress = 201, - RespSetMacAddress = 202, - RespGetWifiMode = 203, - RespSetWifiMode = 204, - RespGetApScanList = 205, - RespGetApConfig = 206, - RespConnectAp = 207, - RespDisconnectAp = 208, - RespGetSoftApConfig = 209, - RespSetSoftApVendorSpecificIe = 210, - RespStartSoftAp = 211, - RespGetSoftApConnectedStaList = 212, - RespStopSoftAp = 213, - RespSetPowerSaveMode = 214, - RespGetPowerSaveMode = 215, - RespOtaBegin = 216, - RespOtaWrite = 217, - RespOtaEnd = 218, - RespSetWifiMaxTxPower = 219, - RespGetWifiCurrTxPower = 220, - RespConfigHeartbeat = 221, - /// Add new control path command response before Resp_Max - /// and update Resp_Max - RespMax = 222, - /// * Event Msgs * - EventBase = 300, - EventEspInit = 301, - EventHeartbeat = 302, - EventStationDisconnectFromAp = 303, - EventStationDisconnectFromEspSoftAp = 304, - /// Add new control path command notification before Event_Max - /// and update Event_Max - EventMax = 305, -} -- cgit