pub const MAX_SSID_LEN: usize = 32;
pub(crate) const MAX_WEP_KEY_LEN: usize = 26;
#[cfg(feature = "wep")]
pub(crate) const MIN_WEP_KEY_LEN: usize = 10;
pub const MAX_PSK_KEY_LEN: usize = 63;
pub(crate) const MIN_PSK_KEY_LEN: usize = 8;
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(crate) const CONNECT_AP_PACKET_SIZE: usize = 108;
pub(crate) const ENABLE_AP_PACKET_SIZE: usize = 136;
pub(crate) const SET_SOCK_OPTS_PACKET_SIZE: usize = 8;
#[cfg(feature = "ssl")]
pub(crate) const SET_SSL_SOCK_OPTS_PACKET_SIZE: usize = 72;
pub(crate) const SOCKET_BUFFER_MAX_LENGTH: usize = 1500;
pub(crate) const PRNG_PACKET_SIZE: usize = 8;
#[cfg(feature = "large_rng")]
pub(crate) const PRNG_DATA_LENGTH: usize = 1600 - 4 - PRNG_PACKET_SIZE;
#[cfg(not(feature = "large_rng"))]
pub(crate) const PRNG_DATA_LENGTH: usize = 32;
#[cfg(feature = "flash-rw")]
pub(crate) const FLASH_PAGE_SIZE: usize = 256;
#[cfg(feature = "experimental-ecc")]
pub(crate) const SSL_ECC_REQ_PACKET_SIZE: usize = 112;
#[cfg(feature = "ssl")]
pub(crate) const SSL_CS_MAX_PACKET_SIZE: usize = 4;
#[cfg(feature = "ethernet")]
pub(crate) const NET_XFER_PACKET_SIZE: usize = 4;
#[cfg(feature = "ethernet")]
pub const MAX_TX_ETHERNET_PACKET_SIZE: usize = 65501;
#[repr(u32)]
pub enum Regs {
WakeClock = 0x01,
HostToCortusComm = 0x0b,
EnableClock = 0x0f,
ChipReset = 0x1400,
ChipHalt = 0x1118,
CortusIrq = 0x20300,
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,
#[cfg(feature = "flash-rw")]
FlashCommandCount = 0x10204,
#[cfg(feature = "flash-rw")]
FlashDataCount = 0x10208,
#[cfg(feature = "flash-rw")]
FlashBuffer1 = 0x1020c,
#[cfg(feature = "flash-rw")]
FlashBuffer2 = 0x10210,
#[cfg(feature = "flash-rw")]
FlashBufferDirectory = 0x10214,
#[cfg(feature = "flash-rw")]
FlashTransferDone = 0x10218,
#[cfg(feature = "flash-rw")]
FlashDmaAddress = 0x1021c,
#[cfg(feature = "flash-rw")]
FlashMsbControl = 0x10220,
#[cfg(feature = "flash-rw")]
FlashTransmitControl = 0x10224,
#[cfg(feature = "flash-rw")]
FlashSharedMemory = 0xd0000,
#[cfg(feature = "flash-rw")]
FlashPinMux = 0x1410,
}
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 {
NoError,
ScanFail,
JoinFail,
AuthFail,
AssocFail,
ConnInProgress,
ConnListEmpty,
Unhandled,
}
impl From<u8> for WifiConnError {
fn from(val: u8) -> Self {
match val {
0 => Self::NoError,
1 => Self::ScanFail,
2 => Self::JoinFail,
3 => Self::AuthFail,
4 => Self::AssocFail,
5 => Self::ConnInProgress,
232 => Self::ConnInProgress,
233 => Self::JoinFail,
234 => Self::ScanFail,
235 => Self::ConnListEmpty,
_ => 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)
}
}
#[derive(Copy, Clone)]
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, EnableAp = 0x46, DisableAp = 0x47, }
impl From<WifiRequest> for u8 {
fn from(val: WifiRequest) -> Self {
val as Self
}
}
#[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, #[cfg(feature = "ssl")]
SslConnect = 0x4B, #[cfg(feature = "ssl")]
SslSend = 0x4C, #[cfg(feature = "ssl")]
SslRecv = 0x4D, #[cfg(feature = "ssl")]
SslClose = 0x4E, SetSocketOption = 0x4F, #[cfg(feature = "ssl")]
SslCreate = 0x50, #[cfg(feature = "ssl")]
SslSetSockOpt = 0x51, #[cfg(feature = "ssl")]
SslBind = 0x54, #[cfg(feature = "ssl")]
SslExpCheck = 0x55,
}
impl From<IpCode> for u8 {
fn from(val: IpCode) -> Self {
val as Self
}
}
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,
#[cfg(feature = "ssl")]
0x4B => Self::SslConnect,
#[cfg(feature = "ssl")]
0x4C => Self::SslSend,
#[cfg(feature = "ssl")]
0x4D => Self::SslRecv,
#[cfg(feature = "ssl")]
0x4E => Self::SslClose,
0x4F => Self::SetSocketOption,
#[cfg(feature = "ssl")]
0x50 => Self::SslCreate,
#[cfg(feature = "ssl")]
0x51 => Self::SslSetSockOpt,
0x52 => Self::Ping,
#[cfg(feature = "ssl")]
0x54 => Self::SslBind,
#[cfg(feature = "ssl")]
0x55 => Self::SslExpCheck,
_ => Self::Unhandled,
}
}
}
#[cfg(feature = "experimental-ota")]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, PartialEq, Default)]
pub(crate) enum OtaResponse {
#[default]
Unhandled,
OtaNotifyUpdateInfo = 0x6A, OtaUpdateStatus = 0x6B, }
#[cfg(feature = "experimental-ota")]
impl From<u8> for OtaResponse {
fn from(v: u8) -> Self {
match v {
0x6A => Self::OtaNotifyUpdateInfo,
0x6B => Self::OtaUpdateStatus,
_ => Self::Unhandled,
}
}
}
#[cfg(feature = "experimental-ota")]
#[allow(dead_code)]
#[derive(Copy, Clone)]
pub(crate) enum OtaRequest {
SetUrl = 0x64, NotifyUpdate = 0x65, ScheduleToNotify = 0x66, StartFirmwareUpdate = 0x67, SwitchFirmware = 0x68, RollbackFirmware = 0x69, RequestTest = 0x6C, StartCortusFirmwareUpdate = 0x6D, SwitchCortusFirmware = 0x6E, RollbackCortusFirmware = 0x6F, Abort = 0x70, }
#[cfg(feature = "experimental-ota")]
impl From<OtaRequest> for u8 {
fn from(val: OtaRequest) -> Self {
val as u8
}
}
#[cfg(feature = "experimental-ota")]
#[repr(u8)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum OtaUpdateError {
NoError = 0,
GenericFail = 1,
InvalidArguments = 2,
InvalidRollbackImage = 3,
InvalidFlashSize = 4,
AlreadyEnabled = 5,
UpdateInProgress = 6,
ImageVerificationFailed = 7,
ConnectionError = 8,
ServerError = 9,
Aborted = 10,
Unhandled = 0xff,
}
#[cfg(feature = "experimental-ota")]
impl From<u8> for OtaUpdateError {
fn from(val: u8) -> Self {
match val {
0 => Self::NoError,
1 => Self::GenericFail,
2 => Self::InvalidArguments,
3 => Self::InvalidRollbackImage,
4 => Self::InvalidFlashSize,
5 => Self::AlreadyEnabled,
6 => Self::UpdateInProgress,
7 => Self::ImageVerificationFailed,
8 => Self::ConnectionError,
9 => Self::ServerError,
10 => Self::Aborted,
_ => Self::Unhandled,
}
}
}
#[cfg(feature = "experimental-ota")]
#[repr(u8)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, PartialEq, Clone, Copy)]
pub(crate) enum OtaUpdateStatus {
Download = 1,
SwitchingFirmware = 2,
Rollback = 3,
Abort = 4,
Unhandled = 0xff,
}
#[cfg(feature = "experimental-ota")]
impl From<u8> for OtaUpdateStatus {
fn from(val: u8) -> Self {
match val {
1 => Self::Download,
2 => Self::SwitchingFirmware,
3 => Self::Rollback,
4 => Self::Abort,
_ => Self::Unhandled,
}
}
}
#[cfg(feature = "ssl")]
#[repr(u8)]
#[derive(Debug, PartialEq, Clone, Copy)]
pub(crate) enum SslRequest {
Unhandled = 0xff, SendEccResponse = 0x02, NotifyCrl = 0x03, SendCertificate = 0x04, SetCipherSuites = 0x05, }
#[cfg(feature = "ssl")]
#[repr(u8)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, PartialEq, Clone, Copy)]
pub(crate) enum SslResponse {
EccReqUpdate = 0x01, CipherSuiteUpdate = 0x06, Unhandled = 0xff, }
#[cfg(feature = "ssl")]
impl From<SslRequest> for u8 {
fn from(val: SslRequest) -> Self {
val as u8
}
}
#[cfg(feature = "ssl")]
impl From<SslResponse> for u8 {
fn from(val: SslResponse) -> Self {
val as u8
}
}
#[cfg(feature = "ssl")]
impl From<u8> for SslResponse {
fn from(val: u8) -> Self {
match val {
0x01 => SslResponse::EccReqUpdate,
0x06 => SslResponse::CipherSuiteUpdate,
_ => SslResponse::Unhandled,
}
}
}
#[cfg(feature = "ssl")]
impl From<u8> for SslRequest {
fn from(val: u8) -> Self {
match val {
0x02 => SslRequest::SendEccResponse,
0x03 => SslRequest::NotifyCrl,
0x04 => SslRequest::SendCertificate,
0x05 => SslRequest::SetCipherSuites,
_ => SslRequest::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,
}
}
}
#[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,
}
}
}
impl From<i16> for SocketError {
fn from(v: i16) -> Self {
let u8_val = v as u8;
u8_val.into()
}
}
impl core::fmt::Display for SocketError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let msg = match self {
Self::Unhandled => "Unhandled socket error",
Self::NoError => "No error",
Self::InvalidAddress => "Invalid address",
Self::AddrAlreadyInUse => "Address already in use",
Self::MaxTcpSock => "Maximum TCP sockets reached",
Self::MaxUdpSock => "Maximum UDP sockets reached",
Self::InvalidArg => "Invalid argument",
Self::MaxListenSock => "Maximum listen sockets reached",
Self::Invalid => "Invalid socket",
Self::AddrIsRequired => "Address is required",
Self::ConnAborted => "Connection aborted",
Self::Timeout => "Socket timeout",
Self::BufferFull => "Buffer full",
};
f.write_str(msg)
}
}
#[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, }
}
}
#[cfg(feature = "ssl")]
#[repr(u32)]
pub enum SslCertExpiryOpt {
Disabled = 0x00,
Enabled = 0x01,
EnabledIfSysTime = 0x02,
}
#[cfg(feature = "ssl")]
impl From<SslCertExpiryOpt> for u32 {
fn from(opt: SslCertExpiryOpt) -> Self {
opt as Self
}
}
#[cfg(feature = "experimental-ecc")]
#[repr(u16)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum EccRequestType {
#[default]
None = 0,
ClientEcdh = 1,
ServerEcdh = 2,
GenerateKey = 3,
GenerateSignature = 4,
VerifySignature = 5,
Unknown,
}
#[cfg(feature = "experimental-ecc")]
impl From<EccRequestType> for u16 {
fn from(val: EccRequestType) -> Self {
val as u16
}
}
#[cfg(feature = "experimental-ecc")]
impl From<u16> for EccRequestType {
fn from(val: u16) -> Self {
match val {
0 => Self::None,
1 => Self::ClientEcdh,
2 => Self::ServerEcdh,
3 => Self::GenerateKey,
4 => Self::GenerateSignature,
5 => Self::VerifySignature,
_ => Self::Unknown,
}
}
}
#[cfg(feature = "experimental-ecc")]
#[repr(u16)]
#[derive(Debug, PartialEq, Default)]
pub enum EccCurveType {
Secp192r1 = 19,
Secp256r1 = 23,
Secp384r1 = 24,
Secp521r1 = 25,
#[default]
Unknown,
}
#[cfg(feature = "experimental-ecc")]
impl From<EccCurveType> for u16 {
fn from(val: EccCurveType) -> Self {
val as u16
}
}
#[cfg(feature = "experimental-ecc")]
impl From<u16> for EccCurveType {
fn from(val: u16) -> Self {
match val {
19 => Self::Secp192r1,
23 => Self::Secp256r1,
24 => Self::Secp384r1,
25 => Self::Secp521r1,
_ => Self::Unknown,
}
}
}
#[repr(u32)]
pub enum SslCipherSuite {
RsaWithAes128CbcSha = 0x01,
RsaWithAes128CbcSha256 = 0x02,
DheRsaWithAes128CbcSha = 0x04,
DheRsaWithAes128CbcSha256 = 0x08,
RsaWithAes128GcmSha256 = 0x10,
DheRsaWithAes128GcmSha256 = 0x20,
RsaWithAes256CbcSha = 0x40,
RsaWithAes256CbcSha256 = 0x80,
DheRsaWithAes256CbcSha = 0x100,
DheRsaWithAes256CbcSha256 = 0x200,
#[cfg(feature = "experimental-ecc")]
EcdheRsaWithAes128CbcSha = 0x400,
#[cfg(feature = "experimental-ecc")]
EcdheRsaWithAes256CbcSha = 0x800,
#[cfg(feature = "experimental-ecc")]
EcdheRsaWithAes128CbcSha256 = 0x1000,
#[cfg(feature = "experimental-ecc")]
EcdheEcdsaWithAes128CbcSha256 = 0x2000,
#[cfg(feature = "experimental-ecc")]
EcdheRsaWithAes128GcmSha256 = 0x4000,
#[cfg(feature = "experimental-ecc")]
EcdheEcdsaWithAes128GcmSha256 = 0x8000,
#[cfg(feature = "experimental-ecc")]
EccOnlyAes128 = 0xA000,
#[cfg(feature = "experimental-ecc")]
EccAllAes128 = 0xF400,
NoEccAes128 = 0x3F,
NoEccAes256 = 0x3C0,
AllRsaAesNoDheEcc = 0xD3,
AllCiphers = 0xFFFF,
}
impl From<SslCipherSuite> for u32 {
fn from(val: SslCipherSuite) -> Self {
val as u32
}
}
#[repr(u32)]
#[derive(Clone, Copy)]
pub enum BootMode {
Normal = 0x00,
#[cfg(feature = "ethernet")]
Ethernet = 0x80,
}
impl From<BootMode> for u32 {
fn from(val: BootMode) -> u32 {
val as u32
}
}