pub const MAX_SSID_LEN: usize = 32;
pub(crate) const MAX_WEP_KEY_LEN: usize = 26;
pub const MAX_PSK_KEY_LEN: usize = 63;
pub const MAX_HOST_NAME_LEN: usize = 63;
pub(crate) const START_PROVISION_PACKET_SIZE: usize = 204;
pub(crate) const PROVISIONING_INFO_PACKET_SIZE: usize = 100;
pub const MAX_S802_PASSWORD_LEN: usize = 40;
pub const MAX_S802_USERNAME_LEN: usize = 20;
pub enum Regs {
SpiConfig = 0xE824,
ChipId = 0x1000,
EFuseRead = 0x1014,
NmiState = 0x108c,
ChipRev = 0x13f4,
NmiPinMux0 = 0x1408,
NmiGp1 = 0x14A0,
NmiIntrEnable = 0x1a00,
NmiRev = 0x207ac,
WaitForHost = 0x207bc,
NmiGp2 = 0xC0008,
BootRom = 0xC000C,
WifiHostRcvCtrl0 = 0x1070,
WifiHostRcvCtrl1 = 0x1084,
WifiHostRcvCtrl2 = 0x1078,
WifiHostRcvCtrl3 = 0x106c,
WifiHostRcvCtrl4 = 0x150400,
}
impl From<Regs> for u32 {
fn from(val: Regs) -> Self {
val as u32
}
}
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, PartialEq)]
pub enum WifiConnError {
Unhandled,
ScanFail,
JoinFail,
AuthFail,
AssocFail,
ConnInProgress,
}
impl From<u8> for WifiConnError {
fn from(val: u8) -> Self {
match val {
1 => Self::ScanFail,
2 => Self::JoinFail,
3 => Self::AuthFail,
4 => Self::AssocFail,
5 => Self::ConnInProgress,
_ => Self::Unhandled,
}
}
}
impl core::fmt::Display for WifiConnError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{:?}", self)
}
}
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, PartialEq, Default, Clone, Copy)]
pub enum AuthType {
#[default]
Invalid,
Open,
WpaPSK,
WEP,
S802_1X,
}
impl From<u8> for AuthType {
fn from(val: u8) -> Self {
match val {
1 => Self::Open,
2 => Self::WpaPSK,
3 => Self::WEP,
4 => Self::S802_1X,
_ => Self::Invalid,
}
}
}
impl From<AuthType> for u8 {
fn from(val: AuthType) -> Self {
val as Self
}
}
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, PartialEq, Default)]
pub enum WifiConnState {
#[default]
Unhandled,
Disconnected,
Connected,
}
impl From<u8> for WifiConnState {
fn from(val: u8) -> Self {
match val {
0 => Self::Disconnected,
1 => Self::Connected,
_ => Self::Unhandled,
}
}
}
impl core::fmt::Display for WifiConnState {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{:?}", self)
}
}
#[allow(dead_code)] pub enum WifiRequest {
Restart = 0x01, SetMacAddress = 0x02, CurrentRssi = 0x03, GetConnInfo = 0x05, SetDeviceName = 0x07, StartProvisionMode = 0x08, StopProvisionMode = 0x0A, SetSysTime = 0x0B, EnableSntpClient = 0x0C, DisableSntpClient = 0x0D, CustInfoElement = 0x0F, Scan = 0x10, ScanResult = 0x12, SetScanOption = 0x14, SetScanRegion = 0x15, SetPowerProfile = 0x16, SetTxPower = 0x17, SetBatteryVoltage = 0x18, SetEnableLogs = 0x19, GetSysTime = 0x1A, SendEthernetPacket = 0x1C, SetMacMcast = 0x1E, GetPrng = 0x1F, ScanSsidList = 0x21, SetGains = 0x22, PassiveScan = 0x23, Connect = 0x28, DefaultConnect = 0x29, Disconnect = 0x2B, Sleep = 0x2D, WpsScan = 0x2E, Wps = 0x2F, DisableWps = 0x31, EnableMonitoring = 0x35, DisableMonitoring = 0x36, SendWifiPacket = 0x38, LsnInt = 0x39, Doze = 0x3A, }
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, PartialEq, Default)]
#[rustfmt::skip] pub enum WifiResponse {
#[default]
Unhandled,
CurrentRssi, ConnInfo, ProvisionInfo, ScanDone, ScanResult, GetSysTime, GetPrng, DefaultConnect, DhcpConf, ConStateChanged, IpConflict, ClientInfo, Wps, EthernetRxPacket, WifiRxPacket,
}
#[rustfmt::skip] impl From<u8> for WifiResponse {
fn from(v: u8) -> Self {
match v {
0x04 => Self::CurrentRssi, 0x06 => Self::ConnInfo, 0x09 => Self::ProvisionInfo, 0x11 => Self::ScanDone, 0x13 => Self::ScanResult, 0x1B => Self::GetSysTime, 0x20 => Self::GetPrng, 0x2A => Self::DefaultConnect, 0x2C => Self::ConStateChanged, 0x32 => Self::DhcpConf, 0x34 => Self::IpConflict, 0x2F => Self::Wps, 0x65 => Self::ClientInfo, 0x1D => Self::EthernetRxPacket, 0x37 => Self::WifiRxPacket,
_ => Self::Unhandled,
}
}
}
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, PartialEq, Default, Clone, Copy)]
pub enum IpCode {
#[default]
Unhandled,
Bind = 0x41, Listen = 0x42, Accept = 0x43, Connect = 0x44, Send = 0x45, Recv = 0x46, SendTo = 0x47, RecvFrom = 0x48, Close = 0x49, DnsResolve = 0x4A, Ping = 0x52, SslConnect = 0x4B, SslSend = 0x4C, SslRecv = 0x4D, SslClose = 0x4E, SetSocketOption = 0x4F, SslCreate = 0x50, SslSetSockOpt = 0x51, SslBind = 0x54, SslExpCheck = 0x55,
}
impl From<u8> for IpCode {
fn from(v: u8) -> Self {
match v {
0x41 => Self::Bind,
0x42 => Self::Listen,
0x43 => Self::Accept,
0x44 => Self::Connect,
0x45 => Self::Send,
0x46 => Self::Recv,
0x47 => Self::SendTo,
0x48 => Self::RecvFrom,
0x49 => Self::Close,
0x4A => Self::DnsResolve,
0x4B => Self::SslConnect,
0x4C => Self::SslSend,
0x4D => Self::SslRecv,
0x4E => Self::SslClose,
0x4F => Self::SetSocketOption,
0x50 => Self::SslCreate,
0x51 => Self::SslSetSockOpt,
0x52 => Self::Ping,
0x54 => Self::SslBind,
0x55 => Self::SslExpCheck,
_ => Self::Unhandled,
}
}
}
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, PartialEq, Default, Clone, Copy)]
pub enum PingError {
Unhandled = -1000,
#[default]
NoError = 0, DestinationUnreachable = 1,
Timeout = 2,
}
impl From<u8> for PingError {
fn from(v: u8) -> Self {
match v {
0 => Self::NoError,
1 => Self::DestinationUnreachable,
2 => Self::Timeout,
_ => Self::Unhandled,
}
}
}
#[allow(dead_code)] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, PartialEq, Default, Clone, Copy)]
pub enum SocketError {
Unhandled = -1000,
#[default]
NoError = 0, InvalidAddress = -1, AddrAlreadyInUse = -2, MaxTcpSock = -3, MaxUdpSock = -4, InvalidArg = -6, MaxListenSock = -7, Invalid = -9, AddrIsRequired = -11, ConnAborted = -12, Timeout = -13, BufferFull = -14, }
impl From<u8> for SocketError {
fn from(v: u8) -> Self {
match v {
0 => Self::NoError,
255 => Self::InvalidAddress,
254 => Self::AddrAlreadyInUse,
253 => Self::MaxTcpSock,
252 => Self::MaxUdpSock,
250 => Self::InvalidArg,
249 => Self::MaxListenSock,
247 => Self::Invalid,
245 => Self::AddrIsRequired,
244 => Self::ConnAborted,
243 => Self::Timeout,
242 => Self::BufferFull,
_ => Self::Unhandled,
}
}
}
#[repr(u8)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum WifiChannel {
Channel1 = 1, Channel2 = 2,
Channel3 = 3,
Channel4 = 4,
Channel5 = 5,
Channel6 = 6,
Channel7 = 7,
Channel8 = 8,
Channel9 = 9,
Channel10 = 10,
Channel11 = 11,
Channel12 = 12,
Channel13 = 13,
Channel14 = 14,
ChannelAll = 255,
}
impl From<u8> for WifiChannel {
fn from(n: u8) -> Self {
match n {
1 => WifiChannel::Channel1,
2 => WifiChannel::Channel2,
3 => WifiChannel::Channel3,
4 => WifiChannel::Channel4,
5 => WifiChannel::Channel5,
6 => WifiChannel::Channel6,
7 => WifiChannel::Channel7,
8 => WifiChannel::Channel8,
9 => WifiChannel::Channel9,
10 => WifiChannel::Channel10,
11 => WifiChannel::Channel11,
12 => WifiChannel::Channel12,
13 => WifiChannel::Channel13,
14 => WifiChannel::Channel14,
255 => WifiChannel::ChannelAll,
_ => WifiChannel::Channel1, }
}
}
impl From<WifiChannel> for u8 {
fn from(val: WifiChannel) -> Self {
val as Self
}
}
#[cfg(feature = "wep")]
#[repr(u8)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum WepKeyIndex {
NoKey = 0,
Key1 = 1,
Key2 = 2,
Key3 = 3,
Key4 = 4,
}
#[cfg(feature = "wep")]
impl From<WepKeyIndex> for u8 {
fn from(val: WepKeyIndex) -> Self {
val as Self
}
}
#[cfg(feature = "wep")]
impl From<u8> for WepKeyIndex {
fn from(n: u8) -> Self {
match n {
0 => WepKeyIndex::NoKey,
1 => WepKeyIndex::Key1,
2 => WepKeyIndex::Key2,
3 => WepKeyIndex::Key3,
4 => WepKeyIndex::Key4,
_ => WepKeyIndex::NoKey, }
}
}