Merge #1161
1161: WIP: Smoltcp socket config r=Dirbaio a=Czocher This PR updates the smoltcp version to the newest master one as well as implements the feature specified in #1154 - to allow the dhcpv4 socket to be configured. Currently it should be considered a WIP PR - requires testing. `@Dirbaio` can you have a look and check if this is compatible with what we discussed on the matrix channel? Co-authored-by: Paweł Jan Czochański <pawel@czochanski.pl> Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
This commit is contained in:
commit
539a8107e2
@ -51,7 +51,7 @@ atomic-polyfill = { version = "1.0" }
|
|||||||
[dependencies.smoltcp]
|
[dependencies.smoltcp]
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
git = "https://github.com/smoltcp-rs/smoltcp"
|
git = "https://github.com/smoltcp-rs/smoltcp"
|
||||||
rev = "b7a7c4b1c56e8d4c2524c1e3a056c745a13cc09f"
|
rev = "5740b765749b95c18aace5de8dc21cab75ba33d4"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = [
|
features = [
|
||||||
"proto-ipv4",
|
"proto-ipv4",
|
||||||
|
@ -2,6 +2,7 @@ use core::task::Context;
|
|||||||
|
|
||||||
use embassy_net_driver::{Capabilities, Checksum, Driver, Medium, RxToken, TxToken};
|
use embassy_net_driver::{Capabilities, Checksum, Driver, Medium, RxToken, TxToken};
|
||||||
use smoltcp::phy;
|
use smoltcp::phy;
|
||||||
|
use smoltcp::time::Instant;
|
||||||
|
|
||||||
pub(crate) struct DriverAdapter<'d, 'c, T>
|
pub(crate) struct DriverAdapter<'d, 'c, T>
|
||||||
where
|
where
|
||||||
@ -19,14 +20,14 @@ where
|
|||||||
type RxToken<'a> = RxTokenAdapter<T::RxToken<'a>> where Self: 'a;
|
type RxToken<'a> = RxTokenAdapter<T::RxToken<'a>> where Self: 'a;
|
||||||
type TxToken<'a> = TxTokenAdapter<T::TxToken<'a>> where Self: 'a;
|
type TxToken<'a> = TxTokenAdapter<T::TxToken<'a>> where Self: 'a;
|
||||||
|
|
||||||
fn receive(&mut self) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> {
|
fn receive(&mut self, _timestamp: Instant) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> {
|
||||||
self.inner
|
self.inner
|
||||||
.receive(self.cx.as_deref_mut().unwrap())
|
.receive(self.cx.as_deref_mut().unwrap())
|
||||||
.map(|(rx, tx)| (RxTokenAdapter(rx), TxTokenAdapter(tx)))
|
.map(|(rx, tx)| (RxTokenAdapter(rx), TxTokenAdapter(tx)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a transmit token.
|
/// Construct a transmit token.
|
||||||
fn transmit(&mut self) -> Option<Self::TxToken<'_>> {
|
fn transmit(&mut self, _timestamp: Instant) -> Option<Self::TxToken<'_>> {
|
||||||
self.inner.transmit(self.cx.as_deref_mut().unwrap()).map(TxTokenAdapter)
|
self.inner.transmit(self.cx.as_deref_mut().unwrap()).map(TxTokenAdapter)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,9 +77,9 @@ impl<T> phy::RxToken for RxTokenAdapter<T>
|
|||||||
where
|
where
|
||||||
T: RxToken,
|
T: RxToken,
|
||||||
{
|
{
|
||||||
fn consume<R, F>(self, _timestamp: smoltcp::time::Instant, f: F) -> smoltcp::Result<R>
|
fn consume<R, F>(self, f: F) -> R
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut [u8]) -> smoltcp::Result<R>,
|
F: FnOnce(&mut [u8]) -> R,
|
||||||
{
|
{
|
||||||
self.0.consume(|buf| f(buf))
|
self.0.consume(|buf| f(buf))
|
||||||
}
|
}
|
||||||
@ -92,9 +93,9 @@ impl<T> phy::TxToken for TxTokenAdapter<T>
|
|||||||
where
|
where
|
||||||
T: TxToken,
|
T: TxToken,
|
||||||
{
|
{
|
||||||
fn consume<R, F>(self, _timestamp: smoltcp::time::Instant, len: usize, f: F) -> smoltcp::Result<R>
|
fn consume<R, F>(self, len: usize, f: F) -> R
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut [u8]) -> smoltcp::Result<R>,
|
F: FnOnce(&mut [u8]) -> R,
|
||||||
{
|
{
|
||||||
self.0.consume(len, |buf| f(buf))
|
self.0.consume(len, |buf| f(buf))
|
||||||
}
|
}
|
||||||
|
@ -25,11 +25,11 @@ use futures::pin_mut;
|
|||||||
use heapless::Vec;
|
use heapless::Vec;
|
||||||
#[cfg(feature = "dhcpv4")]
|
#[cfg(feature = "dhcpv4")]
|
||||||
use smoltcp::iface::SocketHandle;
|
use smoltcp::iface::SocketHandle;
|
||||||
use smoltcp::iface::{Interface, InterfaceBuilder, SocketSet, SocketStorage};
|
use smoltcp::iface::{Interface, SocketSet, SocketStorage};
|
||||||
#[cfg(feature = "medium-ethernet")]
|
|
||||||
use smoltcp::iface::{Neighbor, NeighborCache, Route, Routes};
|
|
||||||
#[cfg(feature = "dhcpv4")]
|
#[cfg(feature = "dhcpv4")]
|
||||||
use smoltcp::socket::dhcpv4;
|
use smoltcp::socket::dhcpv4;
|
||||||
|
use smoltcp::socket::dhcpv4::RetryConfig;
|
||||||
|
use smoltcp::time::Duration;
|
||||||
// smoltcp reexports
|
// smoltcp reexports
|
||||||
pub use smoltcp::time::{Duration as SmolDuration, Instant as SmolInstant};
|
pub use smoltcp::time::{Duration as SmolDuration, Instant as SmolInstant};
|
||||||
#[cfg(feature = "medium-ethernet")]
|
#[cfg(feature = "medium-ethernet")]
|
||||||
@ -45,40 +45,53 @@ use crate::device::DriverAdapter;
|
|||||||
const LOCAL_PORT_MIN: u16 = 1025;
|
const LOCAL_PORT_MIN: u16 = 1025;
|
||||||
const LOCAL_PORT_MAX: u16 = 65535;
|
const LOCAL_PORT_MAX: u16 = 65535;
|
||||||
|
|
||||||
pub struct StackResources<const ADDR: usize, const SOCK: usize, const NEIGHBOR: usize> {
|
pub struct StackResources<const SOCK: usize> {
|
||||||
addresses: [IpCidr; ADDR],
|
|
||||||
sockets: [SocketStorage<'static>; SOCK],
|
sockets: [SocketStorage<'static>; SOCK],
|
||||||
|
|
||||||
#[cfg(feature = "medium-ethernet")]
|
|
||||||
routes: [Option<(IpCidr, Route)>; 1],
|
|
||||||
#[cfg(feature = "medium-ethernet")]
|
|
||||||
neighbor_cache: [Option<(IpAddress, Neighbor)>; NEIGHBOR],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const ADDR: usize, const SOCK: usize, const NEIGHBOR: usize> StackResources<ADDR, SOCK, NEIGHBOR> {
|
impl<const SOCK: usize> StackResources<SOCK> {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
addresses: [IpCidr::new(Ipv4Address::UNSPECIFIED.into(), 32); ADDR],
|
|
||||||
sockets: [SocketStorage::EMPTY; SOCK],
|
sockets: [SocketStorage::EMPTY; SOCK],
|
||||||
#[cfg(feature = "medium-ethernet")]
|
|
||||||
routes: [None; 1],
|
|
||||||
#[cfg(feature = "medium-ethernet")]
|
|
||||||
neighbor_cache: [None; NEIGHBOR],
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct Config {
|
pub struct StaticConfig {
|
||||||
pub address: Ipv4Cidr,
|
pub address: Ipv4Cidr,
|
||||||
pub gateway: Option<Ipv4Address>,
|
pub gateway: Option<Ipv4Address>,
|
||||||
pub dns_servers: Vec<Ipv4Address, 3>,
|
pub dns_servers: Vec<Ipv4Address, 3>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum ConfigStrategy {
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
Static(Config),
|
pub struct DhcpConfig {
|
||||||
|
pub max_lease_duration: Option<Duration>,
|
||||||
|
pub retry_config: RetryConfig,
|
||||||
|
/// Ignore NAKs.
|
||||||
|
pub ignore_naks: bool,
|
||||||
|
/// Server port config
|
||||||
|
pub server_port: u16,
|
||||||
|
/// Client port config
|
||||||
|
pub client_port: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for DhcpConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
max_lease_duration: Default::default(),
|
||||||
|
retry_config: Default::default(),
|
||||||
|
ignore_naks: Default::default(),
|
||||||
|
server_port: smoltcp::wire::DHCP_SERVER_PORT,
|
||||||
|
client_port: smoltcp::wire::DHCP_CLIENT_PORT,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum Config {
|
||||||
|
Static(StaticConfig),
|
||||||
#[cfg(feature = "dhcpv4")]
|
#[cfg(feature = "dhcpv4")]
|
||||||
Dhcp,
|
Dhcp(DhcpConfig),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Stack<D: Driver> {
|
pub struct Stack<D: Driver> {
|
||||||
@ -89,43 +102,42 @@ pub struct Stack<D: Driver> {
|
|||||||
struct Inner<D: Driver> {
|
struct Inner<D: Driver> {
|
||||||
device: D,
|
device: D,
|
||||||
link_up: bool,
|
link_up: bool,
|
||||||
config: Option<Config>,
|
config: Option<StaticConfig>,
|
||||||
#[cfg(feature = "dhcpv4")]
|
#[cfg(feature = "dhcpv4")]
|
||||||
dhcp_socket: Option<SocketHandle>,
|
dhcp_socket: Option<SocketHandle>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct SocketStack {
|
pub(crate) struct SocketStack {
|
||||||
pub(crate) sockets: SocketSet<'static>,
|
pub(crate) sockets: SocketSet<'static>,
|
||||||
pub(crate) iface: Interface<'static>,
|
pub(crate) iface: Interface,
|
||||||
pub(crate) waker: WakerRegistration,
|
pub(crate) waker: WakerRegistration,
|
||||||
next_local_port: u16,
|
next_local_port: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Driver + 'static> Stack<D> {
|
impl<D: Driver + 'static> Stack<D> {
|
||||||
pub fn new<const ADDR: usize, const SOCK: usize, const NEIGH: usize>(
|
pub fn new<const SOCK: usize>(
|
||||||
mut device: D,
|
mut device: D,
|
||||||
config: ConfigStrategy,
|
config: Config,
|
||||||
resources: &'static mut StackResources<ADDR, SOCK, NEIGH>,
|
resources: &'static mut StackResources<SOCK>,
|
||||||
random_seed: u64,
|
random_seed: u64,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
#[cfg(feature = "medium-ethernet")]
|
#[cfg(feature = "medium-ethernet")]
|
||||||
let medium = device.capabilities().medium;
|
let medium = device.capabilities().medium;
|
||||||
|
|
||||||
let mut b = InterfaceBuilder::new();
|
let mut iface_cfg = smoltcp::iface::Config::new();
|
||||||
b = b.ip_addrs(&mut resources.addresses[..]);
|
iface_cfg.random_seed = random_seed;
|
||||||
b = b.random_seed(random_seed);
|
|
||||||
|
|
||||||
#[cfg(feature = "medium-ethernet")]
|
#[cfg(feature = "medium-ethernet")]
|
||||||
if medium == Medium::Ethernet {
|
if medium == Medium::Ethernet {
|
||||||
b = b.hardware_addr(HardwareAddress::Ethernet(EthernetAddress(device.ethernet_address())));
|
iface_cfg.hardware_addr = Some(HardwareAddress::Ethernet(EthernetAddress(device.ethernet_address())));
|
||||||
b = b.neighbor_cache(NeighborCache::new(&mut resources.neighbor_cache[..]));
|
|
||||||
b = b.routes(Routes::new(&mut resources.routes[..]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let iface = b.finalize(&mut DriverAdapter {
|
let iface = Interface::new(
|
||||||
inner: &mut device,
|
iface_cfg,
|
||||||
cx: None,
|
&mut DriverAdapter {
|
||||||
});
|
inner: &mut device,
|
||||||
|
cx: None,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
let sockets = SocketSet::new(&mut resources.sockets[..]);
|
let sockets = SocketSet::new(&mut resources.sockets[..]);
|
||||||
|
|
||||||
@ -146,10 +158,12 @@ impl<D: Driver + 'static> Stack<D> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
match config {
|
match config {
|
||||||
ConfigStrategy::Static(config) => inner.apply_config(&mut socket, config),
|
Config::Static(config) => inner.apply_config(&mut socket, config),
|
||||||
#[cfg(feature = "dhcpv4")]
|
#[cfg(feature = "dhcpv4")]
|
||||||
ConfigStrategy::Dhcp => {
|
Config::Dhcp(config) => {
|
||||||
let handle = socket.sockets.add(smoltcp::socket::dhcpv4::Socket::new());
|
let mut dhcp_socket = smoltcp::socket::dhcpv4::Socket::new();
|
||||||
|
inner.apply_dhcp_config(&mut dhcp_socket, config);
|
||||||
|
let handle = socket.sockets.add(dhcp_socket);
|
||||||
inner.dhcp_socket = Some(handle);
|
inner.dhcp_socket = Some(handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -180,7 +194,7 @@ impl<D: Driver + 'static> Stack<D> {
|
|||||||
self.with(|_s, i| i.config.is_some())
|
self.with(|_s, i| i.config.is_some())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn config(&self) -> Option<Config> {
|
pub fn config(&self) -> Option<StaticConfig> {
|
||||||
self.with(|_s, i| i.config.clone())
|
self.with(|_s, i| i.config.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,7 +209,7 @@ impl<D: Driver + 'static> Stack<D> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl SocketStack {
|
impl SocketStack {
|
||||||
#[allow(clippy::absurd_extreme_comparisons)]
|
#[allow(clippy::absurd_extreme_comparisons, dead_code)]
|
||||||
pub fn get_local_port(&mut self) -> u16 {
|
pub fn get_local_port(&mut self) -> u16 {
|
||||||
let res = self.next_local_port;
|
let res = self.next_local_port;
|
||||||
self.next_local_port = if res >= LOCAL_PORT_MAX { LOCAL_PORT_MIN } else { res + 1 };
|
self.next_local_port = if res >= LOCAL_PORT_MAX { LOCAL_PORT_MIN } else { res + 1 };
|
||||||
@ -204,14 +218,20 @@ impl SocketStack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<D: Driver + 'static> Inner<D> {
|
impl<D: Driver + 'static> Inner<D> {
|
||||||
fn apply_config(&mut self, s: &mut SocketStack, config: Config) {
|
fn apply_config(&mut self, s: &mut SocketStack, config: StaticConfig) {
|
||||||
#[cfg(feature = "medium-ethernet")]
|
#[cfg(feature = "medium-ethernet")]
|
||||||
let medium = self.device.capabilities().medium;
|
let medium = self.device.capabilities().medium;
|
||||||
|
|
||||||
debug!("Acquired IP configuration:");
|
debug!("Acquired IP configuration:");
|
||||||
|
|
||||||
debug!(" IP address: {}", config.address);
|
debug!(" IP address: {}", config.address);
|
||||||
self.set_ipv4_addr(s, config.address);
|
s.iface.update_ip_addrs(|addrs| {
|
||||||
|
if addrs.is_empty() {
|
||||||
|
addrs.push(IpCidr::Ipv4(config.address)).unwrap();
|
||||||
|
} else {
|
||||||
|
addrs[0] = IpCidr::Ipv4(config.address);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
#[cfg(feature = "medium-ethernet")]
|
#[cfg(feature = "medium-ethernet")]
|
||||||
if medium == Medium::Ethernet {
|
if medium == Medium::Ethernet {
|
||||||
@ -230,13 +250,20 @@ impl<D: Driver + 'static> Inner<D> {
|
|||||||
self.config = Some(config)
|
self.config = Some(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn apply_dhcp_config(&self, socket: &mut smoltcp::socket::dhcpv4::Socket, config: DhcpConfig) {
|
||||||
|
socket.set_ignore_naks(config.ignore_naks);
|
||||||
|
socket.set_max_lease_duration(config.max_lease_duration);
|
||||||
|
socket.set_ports(config.server_port, config.client_port);
|
||||||
|
socket.set_retry_config(config.retry_config);
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(unused)] // used only with dhcp
|
#[allow(unused)] // used only with dhcp
|
||||||
fn unapply_config(&mut self, s: &mut SocketStack) {
|
fn unapply_config(&mut self, s: &mut SocketStack) {
|
||||||
#[cfg(feature = "medium-ethernet")]
|
#[cfg(feature = "medium-ethernet")]
|
||||||
let medium = self.device.capabilities().medium;
|
let medium = self.device.capabilities().medium;
|
||||||
|
|
||||||
debug!("Lost IP configuration");
|
debug!("Lost IP configuration");
|
||||||
self.set_ipv4_addr(s, Ipv4Cidr::new(Ipv4Address::UNSPECIFIED, 0));
|
s.iface.update_ip_addrs(|ip_addrs| ip_addrs.clear());
|
||||||
#[cfg(feature = "medium-ethernet")]
|
#[cfg(feature = "medium-ethernet")]
|
||||||
if medium == Medium::Ethernet {
|
if medium == Medium::Ethernet {
|
||||||
s.iface.routes_mut().remove_default_ipv4_route();
|
s.iface.routes_mut().remove_default_ipv4_route();
|
||||||
@ -244,13 +271,6 @@ impl<D: Driver + 'static> Inner<D> {
|
|||||||
self.config = None
|
self.config = None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_ipv4_addr(&mut self, s: &mut SocketStack, cidr: Ipv4Cidr) {
|
|
||||||
s.iface.update_ip_addrs(|addrs| {
|
|
||||||
let dest = addrs.iter_mut().next().unwrap();
|
|
||||||
*dest = IpCidr::Ipv4(cidr);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
fn poll(&mut self, cx: &mut Context<'_>, s: &mut SocketStack) {
|
fn poll(&mut self, cx: &mut Context<'_>, s: &mut SocketStack) {
|
||||||
s.waker.register(cx.waker());
|
s.waker.register(cx.waker());
|
||||||
|
|
||||||
@ -266,11 +286,7 @@ impl<D: Driver + 'static> Inner<D> {
|
|||||||
cx: Some(cx),
|
cx: Some(cx),
|
||||||
inner: &mut self.device,
|
inner: &mut self.device,
|
||||||
};
|
};
|
||||||
if s.iface.poll(timestamp, &mut smoldev, &mut s.sockets).is_err() {
|
s.iface.poll(timestamp, &mut smoldev, &mut s.sockets);
|
||||||
// If poll() returns error, it may not be done yet, so poll again later.
|
|
||||||
cx.waker().wake_by_ref();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update link up
|
// Update link up
|
||||||
let old_link_up = self.link_up;
|
let old_link_up = self.link_up;
|
||||||
@ -290,7 +306,7 @@ impl<D: Driver + 'static> Inner<D> {
|
|||||||
None => {}
|
None => {}
|
||||||
Some(dhcpv4::Event::Deconfigured) => self.unapply_config(s),
|
Some(dhcpv4::Event::Deconfigured) => self.unapply_config(s),
|
||||||
Some(dhcpv4::Event::Configured(config)) => {
|
Some(dhcpv4::Event::Configured(config)) => {
|
||||||
let config = Config {
|
let config = StaticConfig {
|
||||||
address: config.address,
|
address: config.address,
|
||||||
gateway: config.router,
|
gateway: config.router,
|
||||||
dns_servers: config.dns_servers,
|
dns_servers: config.dns_servers,
|
||||||
|
@ -101,8 +101,8 @@ async fn main(spawner: Spawner) {
|
|||||||
let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(singleton!(NetState::new()), our_mac_addr);
|
let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(singleton!(NetState::new()), our_mac_addr);
|
||||||
unwrap!(spawner.spawn(usb_ncm_task(runner)));
|
unwrap!(spawner.spawn(usb_ncm_task(runner)));
|
||||||
|
|
||||||
let config = embassy_net::ConfigStrategy::Dhcp;
|
let config = embassy_net::Config::Dhcp(Default::default());
|
||||||
//let config = embassy_net::ConfigStrategy::Static(embassy_net::Config {
|
//let config = embassy_net::Config::Static(embassy_net::StaticConfig {
|
||||||
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
||||||
// dns_servers: Vec::new(),
|
// dns_servers: Vec::new(),
|
||||||
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
||||||
@ -115,12 +115,7 @@ async fn main(spawner: Spawner) {
|
|||||||
let seed = u64::from_le_bytes(seed);
|
let seed = u64::from_le_bytes(seed);
|
||||||
|
|
||||||
// Init network stack
|
// Init network stack
|
||||||
let stack = &*singleton!(Stack::new(
|
let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed));
|
||||||
device,
|
|
||||||
config,
|
|
||||||
singleton!(StackResources::<1, 2, 8>::new()),
|
|
||||||
seed
|
|
||||||
));
|
|
||||||
|
|
||||||
unwrap!(spawner.spawn(net_task(stack)));
|
unwrap!(spawner.spawn(net_task(stack)));
|
||||||
|
|
||||||
|
@ -92,8 +92,8 @@ async fn main(spawner: Spawner) {
|
|||||||
let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(singleton!(NetState::new()), our_mac_addr);
|
let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(singleton!(NetState::new()), our_mac_addr);
|
||||||
unwrap!(spawner.spawn(usb_ncm_task(runner)));
|
unwrap!(spawner.spawn(usb_ncm_task(runner)));
|
||||||
|
|
||||||
let config = embassy_net::ConfigStrategy::Dhcp;
|
let config = embassy_net::Config::Dhcp(Default::default());
|
||||||
//let config = embassy_net::ConfigStrategy::Static(embassy_net::Config {
|
//let config = embassy_net::Config::Static(embassy_net::StaticConfig {
|
||||||
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
||||||
// dns_servers: Vec::new(),
|
// dns_servers: Vec::new(),
|
||||||
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
||||||
@ -103,12 +103,7 @@ async fn main(spawner: Spawner) {
|
|||||||
let seed = 1234; // guaranteed random, chosen by a fair dice roll
|
let seed = 1234; // guaranteed random, chosen by a fair dice roll
|
||||||
|
|
||||||
// Init network stack
|
// Init network stack
|
||||||
let stack = &*singleton!(Stack::new(
|
let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed));
|
||||||
device,
|
|
||||||
config,
|
|
||||||
singleton!(StackResources::<1, 2, 8>::new()),
|
|
||||||
seed
|
|
||||||
));
|
|
||||||
|
|
||||||
unwrap!(spawner.spawn(net_task(stack)));
|
unwrap!(spawner.spawn(net_task(stack)));
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ async-io = "1.6.0"
|
|||||||
env_logger = "0.9.0"
|
env_logger = "0.9.0"
|
||||||
futures = { version = "0.3.17" }
|
futures = { version = "0.3.17" }
|
||||||
log = "0.4.14"
|
log = "0.4.14"
|
||||||
nix = "0.22.1"
|
nix = "0.26.2"
|
||||||
libc = "0.2.101"
|
libc = "0.2.101"
|
||||||
clap = { version = "3.0.0-beta.5", features = ["derive"] }
|
clap = { version = "3.0.0-beta.5", features = ["derive"] }
|
||||||
rand_core = { version = "0.6.3", features = ["std"] }
|
rand_core = { version = "0.6.3", features = ["std"] }
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
#![feature(type_alias_impl_trait)]
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
|
use std::default::Default;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use embassy_executor::{Executor, Spawner};
|
use embassy_executor::{Executor, Spawner};
|
||||||
use embassy_net::tcp::TcpSocket;
|
use embassy_net::tcp::TcpSocket;
|
||||||
use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, Stack, StackResources};
|
use embassy_net::{Config, Ipv4Address, Ipv4Cidr, Stack, StackResources};
|
||||||
use embedded_io::asynch::Write;
|
use embedded_io::asynch::Write;
|
||||||
use heapless::Vec;
|
use heapless::Vec;
|
||||||
use log::*;
|
use log::*;
|
||||||
@ -48,13 +50,13 @@ async fn main_task(spawner: Spawner) {
|
|||||||
|
|
||||||
// Choose between dhcp or static ip
|
// Choose between dhcp or static ip
|
||||||
let config = if opts.static_ip {
|
let config = if opts.static_ip {
|
||||||
ConfigStrategy::Static(embassy_net::Config {
|
Config::Static(embassy_net::StaticConfig {
|
||||||
address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24),
|
address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24),
|
||||||
dns_servers: Vec::new(),
|
dns_servers: Vec::new(),
|
||||||
gateway: Some(Ipv4Address::new(192, 168, 69, 1)),
|
gateway: Some(Ipv4Address::new(192, 168, 69, 1)),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
ConfigStrategy::Dhcp
|
Config::Dhcp(Default::default())
|
||||||
};
|
};
|
||||||
|
|
||||||
// Generate random seed
|
// Generate random seed
|
||||||
@ -63,12 +65,7 @@ async fn main_task(spawner: Spawner) {
|
|||||||
let seed = u64::from_le_bytes(seed);
|
let seed = u64::from_le_bytes(seed);
|
||||||
|
|
||||||
// Init network stack
|
// Init network stack
|
||||||
let stack = &*singleton!(Stack::new(
|
let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed));
|
||||||
device,
|
|
||||||
config,
|
|
||||||
singleton!(StackResources::<1, 2, 8>::new()),
|
|
||||||
seed
|
|
||||||
));
|
|
||||||
|
|
||||||
// Launch network task
|
// Launch network task
|
||||||
spawner.spawn(net_task(stack)).unwrap();
|
spawner.spawn(net_task(stack)).unwrap();
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use embassy_executor::{Executor, Spawner};
|
use embassy_executor::{Executor, Spawner};
|
||||||
use embassy_net::udp::UdpSocket;
|
use embassy_net::udp::UdpSocket;
|
||||||
use embassy_net::{ConfigStrategy, Ipv4Address, Ipv4Cidr, PacketMetadata, Stack, StackResources};
|
use embassy_net::{Config, Ipv4Address, Ipv4Cidr, PacketMetadata, Stack, StackResources};
|
||||||
use heapless::Vec;
|
use heapless::Vec;
|
||||||
use log::*;
|
use log::*;
|
||||||
use rand_core::{OsRng, RngCore};
|
use rand_core::{OsRng, RngCore};
|
||||||
@ -47,13 +47,13 @@ async fn main_task(spawner: Spawner) {
|
|||||||
|
|
||||||
// Choose between dhcp or static ip
|
// Choose between dhcp or static ip
|
||||||
let config = if opts.static_ip {
|
let config = if opts.static_ip {
|
||||||
ConfigStrategy::Static(embassy_net::Config {
|
Config::Static(embassy_net::StaticConfig {
|
||||||
address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24),
|
address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24),
|
||||||
dns_servers: Vec::new(),
|
dns_servers: Vec::new(),
|
||||||
gateway: Some(Ipv4Address::new(192, 168, 69, 1)),
|
gateway: Some(Ipv4Address::new(192, 168, 69, 1)),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
ConfigStrategy::Dhcp
|
Config::Dhcp(Default::default())
|
||||||
};
|
};
|
||||||
|
|
||||||
// Generate random seed
|
// Generate random seed
|
||||||
@ -62,12 +62,7 @@ async fn main_task(spawner: Spawner) {
|
|||||||
let seed = u64::from_le_bytes(seed);
|
let seed = u64::from_le_bytes(seed);
|
||||||
|
|
||||||
// Init network stack
|
// Init network stack
|
||||||
let stack = &*singleton!(Stack::new(
|
let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed));
|
||||||
device,
|
|
||||||
config,
|
|
||||||
singleton!(StackResources::<1, 2, 8>::new()),
|
|
||||||
seed
|
|
||||||
));
|
|
||||||
|
|
||||||
// Launch network task
|
// Launch network task
|
||||||
spawner.spawn(net_task(stack)).unwrap();
|
spawner.spawn(net_task(stack)).unwrap();
|
||||||
|
@ -69,20 +69,15 @@ async fn main(spawner: Spawner) -> ! {
|
|||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
|
|
||||||
let config = embassy_net::ConfigStrategy::Dhcp;
|
let config = embassy_net::Config::Dhcp(Default::default());
|
||||||
//let config = embassy_net::ConfigStrategy::Static(embassy_net::Config {
|
//let config = embassy_net::Config::Static(embassy_net::StaticConfig {
|
||||||
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
||||||
// dns_servers: Vec::new(),
|
// dns_servers: Vec::new(),
|
||||||
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
||||||
//});
|
//});
|
||||||
|
|
||||||
// Init network stack
|
// Init network stack
|
||||||
let stack = &*singleton!(Stack::new(
|
let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed));
|
||||||
device,
|
|
||||||
config,
|
|
||||||
singleton!(StackResources::<1, 2, 8>::new()),
|
|
||||||
seed
|
|
||||||
));
|
|
||||||
|
|
||||||
// Launch network task
|
// Launch network task
|
||||||
unwrap!(spawner.spawn(net_task(&stack)));
|
unwrap!(spawner.spawn(net_task(&stack)));
|
||||||
|
@ -70,20 +70,15 @@ async fn main(spawner: Spawner) -> ! {
|
|||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
|
|
||||||
let config = embassy_net::ConfigStrategy::Dhcp;
|
let config = embassy_net::Config::Dhcp(Default::default());
|
||||||
//let config = embassy_net::ConfigStrategy::Static(embassy_net::Config {
|
//let config = embassy_net::Config::Static(embassy_net::StaticConfig {
|
||||||
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
||||||
// dns_servers: Vec::new(),
|
// dns_servers: Vec::new(),
|
||||||
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
||||||
//});
|
//});
|
||||||
|
|
||||||
// Init network stack
|
// Init network stack
|
||||||
let stack = &*singleton!(Stack::new(
|
let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed));
|
||||||
device,
|
|
||||||
config,
|
|
||||||
singleton!(StackResources::<1, 2, 8>::new()),
|
|
||||||
seed
|
|
||||||
));
|
|
||||||
|
|
||||||
// Launch network task
|
// Launch network task
|
||||||
unwrap!(spawner.spawn(net_task(&stack)));
|
unwrap!(spawner.spawn(net_task(&stack)));
|
||||||
|
@ -71,20 +71,15 @@ async fn main(spawner: Spawner) -> ! {
|
|||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
|
|
||||||
let config = embassy_net::ConfigStrategy::Dhcp;
|
let config = embassy_net::Config::Dhcp(Default::default());
|
||||||
//let config = embassy_net::ConfigStrategy::Static(embassy_net::Config {
|
//let config = embassy_net::Config::StaticConfig(embassy_net::Config {
|
||||||
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
||||||
// dns_servers: Vec::new(),
|
// dns_servers: Vec::new(),
|
||||||
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
||||||
//});
|
//});
|
||||||
|
|
||||||
// Init network stack
|
// Init network stack
|
||||||
let stack = &*singleton!(Stack::new(
|
let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed));
|
||||||
device,
|
|
||||||
config,
|
|
||||||
singleton!(StackResources::<1, 2, 8>::new()),
|
|
||||||
seed
|
|
||||||
));
|
|
||||||
|
|
||||||
// Launch network task
|
// Launch network task
|
||||||
unwrap!(spawner.spawn(net_task(&stack)));
|
unwrap!(spawner.spawn(net_task(&stack)));
|
||||||
|
@ -98,8 +98,8 @@ async fn main(spawner: Spawner) {
|
|||||||
let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(singleton!(NetState::new()), our_mac_addr);
|
let (runner, device) = class.into_embassy_net_device::<MTU, 4, 4>(singleton!(NetState::new()), our_mac_addr);
|
||||||
unwrap!(spawner.spawn(usb_ncm_task(runner)));
|
unwrap!(spawner.spawn(usb_ncm_task(runner)));
|
||||||
|
|
||||||
let config = embassy_net::ConfigStrategy::Dhcp;
|
let config = embassy_net::Config::Dhcp(Default::default());
|
||||||
//let config = embassy_net::ConfigStrategy::Static(embassy_net::Config {
|
//let config = embassy_net::Config::Static(embassy_net::StaticConfig {
|
||||||
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
// address: Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24),
|
||||||
// dns_servers: Vec::new(),
|
// dns_servers: Vec::new(),
|
||||||
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
||||||
@ -110,12 +110,7 @@ async fn main(spawner: Spawner) {
|
|||||||
let seed = rng.next_u64();
|
let seed = rng.next_u64();
|
||||||
|
|
||||||
// Init network stack
|
// Init network stack
|
||||||
let stack = &*singleton!(Stack::new(
|
let stack = &*singleton!(Stack::new(device, config, singleton!(StackResources::<2>::new()), seed));
|
||||||
device,
|
|
||||||
config,
|
|
||||||
singleton!(StackResources::<1, 2, 8>::new()),
|
|
||||||
seed
|
|
||||||
));
|
|
||||||
|
|
||||||
unwrap!(spawner.spawn(net_task(stack)));
|
unwrap!(spawner.spawn(net_task(stack)));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user