2021-02-03 05:09:37 +01:00
|
|
|
use heapless::consts::*;
|
|
|
|
use heapless::Vec;
|
|
|
|
use smoltcp::time::Instant;
|
|
|
|
use smoltcp::wire::{Ipv4Address, Ipv4Cidr};
|
|
|
|
|
|
|
|
use crate::fmt::*;
|
|
|
|
use crate::{Interface, SocketSet};
|
|
|
|
|
|
|
|
mod statik;
|
|
|
|
pub use statik::StaticConfigurator;
|
|
|
|
|
2021-04-07 19:06:45 +02:00
|
|
|
#[cfg(feature = "dhcpv4")]
|
|
|
|
mod dhcp;
|
|
|
|
#[cfg(feature = "dhcpv4")]
|
|
|
|
pub use dhcp::DhcpConfigurator;
|
|
|
|
|
|
|
|
/// Return value for the `Configurator::poll` function
|
2021-02-03 05:09:37 +01:00
|
|
|
#[derive(Debug, Clone)]
|
2021-04-07 19:06:45 +02:00
|
|
|
pub enum Event {
|
|
|
|
/// No change has occured to the configuration.
|
|
|
|
NoChange,
|
|
|
|
/// Configuration has been lost (for example, DHCP lease has expired)
|
|
|
|
Deconfigured,
|
|
|
|
/// Configuration has been newly acquired, or modified.
|
|
|
|
Configured(Config),
|
2021-02-03 05:09:37 +01:00
|
|
|
}
|
|
|
|
|
2021-04-12 18:13:22 +02:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
2021-04-07 19:06:45 +02:00
|
|
|
pub struct Config {
|
2021-02-03 05:09:37 +01:00
|
|
|
pub address: Ipv4Cidr,
|
2021-04-07 19:06:45 +02:00
|
|
|
pub gateway: Option<Ipv4Address>,
|
2021-02-03 05:09:37 +01:00
|
|
|
pub dns_servers: Vec<Ipv4Address, U3>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait Configurator {
|
2021-04-07 19:06:45 +02:00
|
|
|
fn poll(&mut self, iface: &mut Interface, sockets: &mut SocketSet, timestamp: Instant)
|
|
|
|
-> Event;
|
2021-02-03 05:09:37 +01:00
|
|
|
}
|