#![cfg_attr(not(test), no_std)]
#![allow(unused)]
#![deny(rustdoc::broken_intra_doc_links)]
#![doc = include_str!("../README.md")]
pub mod bus;
mod cursor;
mod device;
mod host;
pub mod net;
pub mod raw_device;
pub mod register;
mod socket;
pub mod tcp;
pub mod udp;
mod uninitialized_device;
#[doc(inline)]
pub use self::{
device::{Device, DeviceState},
host::{Dhcp, Host, HostConfig, Manual},
net::MacAddress,
uninitialized_device::{InitializeError, UninitializedDevice},
};
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialOrd, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum OnWakeOnLan {
InvokeInterrupt = 0b00100000,
Ignore = 0b00000000,
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialOrd, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum OnPingRequest {
Respond = 0b00000000,
Ignore = 0b00010000,
}
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialOrd, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum ConnectionType {
PPoE = 0b00001000,
Ethernet = 0b00000000,
}
#[derive(Copy, Clone, Debug, PartialOrd, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum ArpResponses {
Cache = 0b00000000,
DropAfterUse = 0b00000010,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Mode {
pub on_wake_on_lan: OnWakeOnLan,
pub on_ping_request: OnPingRequest,
pub connection_type: ConnectionType,
pub arp_responses: ArpResponses,
}
impl Mode {
pub fn to_register(self) -> [u8; 1] {
[self.to_u8()]
}
pub fn to_u8(self) -> u8 {
let mut register = 0;
register |= self.on_wake_on_lan as u8;
register |= self.on_ping_request as u8;
register |= self.connection_type as u8;
register |= self.arp_responses as u8;
register
}
}
impl Default for Mode {
fn default() -> Self {
Self {
on_wake_on_lan: OnWakeOnLan::Ignore,
on_ping_request: OnPingRequest::Respond,
connection_type: ConnectionType::Ethernet,
arp_responses: ArpResponses::DropAfterUse,
}
}
}
#[cfg(test)]
mod test {
use crate::Mode;
#[test]
fn test_mode_register() {
let ping_respond_and_force_arp = Mode {
on_wake_on_lan: crate::OnWakeOnLan::Ignore,
on_ping_request: crate::OnPingRequest::Respond,
connection_type: crate::ConnectionType::Ethernet,
arp_responses: crate::ArpResponses::Cache,
};
assert_eq!(0b0000_0000, ping_respond_and_force_arp.to_u8());
let all_enabled = Mode {
on_wake_on_lan: crate::OnWakeOnLan::InvokeInterrupt,
on_ping_request: crate::OnPingRequest::Respond,
connection_type: crate::ConnectionType::PPoE,
arp_responses: crate::ArpResponses::DropAfterUse,
};
assert_eq!(0b0010_1010, all_enabled.to_u8());
}
}