From 5e411f3562cd7eb7ddbfd9a632a46c96554bb527 Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 29 Sep 2023 06:36:27 +0800 Subject: [PATCH] clean up warnings, fix icmp init --- services/net/src/api.rs | 1 - services/net/src/api/rkyv_enum.rs | 3 --- services/net/src/device.rs | 4 ---- services/net/src/main.rs | 19 +++++++++++-------- services/net/src/std_glue.rs | 4 ---- services/net/src/std_tcplistener.rs | 9 ++------- services/net/src/std_tcpstream.rs | 7 +++---- services/net/src/std_udp.rs | 10 +--------- 8 files changed, 17 insertions(+), 40 deletions(-) diff --git a/services/net/src/api.rs b/services/net/src/api.rs index 8166894bd..1e1461bc4 100644 --- a/services/net/src/api.rs +++ b/services/net/src/api.rs @@ -458,7 +458,6 @@ pub fn ipaddress_to_ipaddr(other: IpAddress) -> IpAddr { let octets = ipv6.0; IpAddr::V6(Ipv6Addr::from(octets)) } - _ => unimplemented!(), } } diff --git a/services/net/src/api/rkyv_enum.rs b/services/net/src/api/rkyv_enum.rs index b2c4f72ef..ad8dade13 100644 --- a/services/net/src/api/rkyv_enum.rs +++ b/services/net/src/api/rkyv_enum.rs @@ -59,9 +59,6 @@ impl From for NetIpAddr { match other { IpAddress::Ipv4(ipv4) => NetIpAddr::Ipv4(ipv4.0), IpAddress::Ipv6(ipv6) => NetIpAddr::Ipv6(ipv6.0), - _ => { - panic!("Invalid IpAddress") - } } } } diff --git a/services/net/src/device.rs b/services/net/src/device.rs index 0984099f3..c33b68fbf 100644 --- a/services/net/src/device.rs +++ b/services/net/src/device.rs @@ -6,10 +6,6 @@ use smoltcp::wire::{ArpPacket, ArpRepr, ArpOperation, Ipv4Address, EthernetAddre use num_traits::*; use std::convert::TryInto; -use smoltcp::{ - time::Instant, -}; - use crate::{MAC_ADDRESS_LSB, MAC_ADDRESS_MSB}; use core::sync::atomic::Ordering; use std::collections::VecDeque; diff --git a/services/net/src/main.rs b/services/net/src/main.rs index 1a6130411..0e45f450b 100644 --- a/services/net/src/main.rs +++ b/services/net/src/main.rs @@ -12,7 +12,7 @@ use std_udp::*; mod std_tcplistener; use std_tcplistener::*; -use com::api::{ComIntSources, Ipv4Conf, NET_MTU}; +use com::api::{ComIntSources, Ipv4Conf}; use num_traits::*; mod connection_manager; @@ -23,16 +23,16 @@ mod tests; #[cfg(feature="btest")] mod btests; -use std::collections::{BTreeMap, HashMap, BTreeSet}; +use std::collections::HashMap; use std::convert::TryInto; use xous::{msg_blocking_scalar_unpack, msg_scalar_unpack, send_message, Message, CID, SID}; use xous_ipc::Buffer; use byteorder::{ByteOrder, NetworkEndian}; use smoltcp::iface::{Interface, Config, SocketSet}; -use smoltcp::phy::{Device, Medium, Tracer}; +use smoltcp::phy::{Device, Tracer}; use smoltcp::socket::{tcp, udp, icmp}; -use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address, Ipv4Cidr, IpEndpoint}; +use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address, IpEndpoint}; use smoltcp::wire::{Icmpv4Packet, Icmpv4Repr, Icmpv6Packet, Icmpv6Repr}; use core::num::NonZeroU64; @@ -51,7 +51,6 @@ pub static MAC_ADDRESS_LSB: AtomicU32 = AtomicU32::new(0); pub static MAC_ADDRESS_MSB: AtomicU16 = AtomicU16::new(0); const PING_DEFAULT_TIMEOUT_MS: u32 = 10_000; -const MAX_DELAY_THREADS: u32 = 9; const PING_IDENT: u16 = 0x22b; #[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)] @@ -247,6 +246,12 @@ fn main() -> ! { let tcp4_handle = sockets.add(tcp4_socket); */ let icmp_handle = sockets.add(icmp_socket); + { // put in a block to retire the icmp_socket variable in this scope + let icmp_socket = sockets.get_mut::(icmp_handle); + icmp_socket + .bind(icmp::Endpoint::Ident(PING_IDENT)) + .expect("couldn't bind to icmp socket"); + } // ------------- libstd variant ----------- // Each process keeps track of its own sockets. These are kept in a Vec. When a handle @@ -498,7 +503,6 @@ fn main() -> ! { &device_caps.checksum, ); } - _ => unimplemented!(), } seq += 1; // fire off a Pump to get the stack to actually transmit the ping; this call merely queues it for sending @@ -1295,7 +1299,7 @@ fn main() -> ! { } } }), - Some(Opcode::NetPump) => msg_scalar_unpack!(msg, wup_hi, wup_lo, _, _, { + Some(Opcode::NetPump) => msg_scalar_unpack!(msg, _, _, _, _, { log::trace!("NetPump"); let now = timer.elapsed_ms(); let timestamp = Instant::from_millis(now as i64); @@ -1890,7 +1894,6 @@ fn main() -> ! { log::error!("got unhandled ICMP type, ignoring!"); } } - _ => unimplemented!(), } } } diff --git a/services/net/src/std_glue.rs b/services/net/src/std_glue.rs index 5deb96f75..7bc33b355 100644 --- a/services/net/src/std_glue.rs +++ b/services/net/src/std_glue.rs @@ -40,10 +40,6 @@ pub(crate) fn write_address(address: IpAddress, data: &mut [u8]) -> Option { - *i.next()? = 0; - Some(1) - } } } diff --git a/services/net/src/std_tcplistener.rs b/services/net/src/std_tcplistener.rs index a92a41e73..8995b6763 100644 --- a/services/net/src/std_tcplistener.rs +++ b/services/net/src/std_tcplistener.rs @@ -4,7 +4,7 @@ use smoltcp::socket::tcp; pub(crate) fn std_tcp_listen( mut msg: xous::MessageEnvelope, - iface: &mut Interface, + _iface: &mut Interface, sockets: &mut SocketSet, our_sockets: &mut Vec>, trng: &trng::Trng, @@ -46,7 +46,6 @@ pub(crate) fn std_tcp_listen( let tcp_socket = tcp::Socket::new(tcp_rx_buffer, tcp_tx_buffer); let handle = sockets.add(tcp_socket); - let cx = iface.context(); let tcp_socket = sockets.get_mut::(handle); loop { @@ -55,7 +54,6 @@ pub(crate) fn std_tcp_listen( .map_err(|e| match e { smoltcp::socket::tcp::ListenError::InvalidState => NetError::SocketInUse, smoltcp::socket::tcp::ListenError::Unaddressable => NetError::Unaddressable, - _ => NetError::LibraryError, }) { match e { @@ -97,7 +95,7 @@ pub(crate) fn std_tcp_listen( pub(crate) fn std_tcp_accept( mut msg: xous::MessageEnvelope, - iface: &mut Interface, + _iface: &mut Interface, sockets: &mut SocketSet, tcp_accept_waiting: &mut Vec>, tcp_server_remote_close_poll: &mut Vec, @@ -174,9 +172,6 @@ pub(crate) fn tcp_accept_success(buf: &mut [u8], fd: u16, ep: IpEndpoint) { *d = s; } } - _ => { - buf[3] = 0; // this is the invalid/error type - } } let port = ep.port.to_le_bytes(); buf[20] = port[0]; diff --git a/services/net/src/std_tcpstream.rs b/services/net/src/std_tcpstream.rs index 703a25989..5e440c587 100644 --- a/services/net/src/std_tcpstream.rs +++ b/services/net/src/std_tcpstream.rs @@ -53,7 +53,6 @@ pub(crate) fn std_tcp_connect( .map_err(|e| match e { smoltcp::socket::tcp::ConnectError::InvalidState => NetError::SocketInUse, smoltcp::socket::tcp::ConnectError::Unaddressable => NetError::Unaddressable, - _ => NetError::LibraryError, }) { log::debug!("couldn't connect: {:?}", e); @@ -76,7 +75,7 @@ pub(crate) fn std_tcp_connect( pub(crate) fn std_tcp_tx( mut msg: xous::MessageEnvelope, timer: &Ticktimer, - iface: &mut Interface, + _iface: &mut Interface, sockets: &mut SocketSet, tcp_tx_waiting: &mut Vec>, our_sockets: &Vec>, @@ -150,7 +149,7 @@ pub(crate) fn std_tcp_tx( pub(crate) fn std_tcp_rx( mut msg: xous::MessageEnvelope, timer: &Ticktimer, - iface: &mut Interface, + _iface: &mut Interface, sockets: &mut SocketSet, tcp_rx_waiting: &mut Vec>, our_sockets: &Vec>, @@ -228,7 +227,7 @@ pub(crate) fn std_tcp_rx( pub(crate) fn std_tcp_peek( mut msg: xous::MessageEnvelope, timer: &Ticktimer, - iface: &mut Interface, + _iface: &mut Interface, sockets: &mut SocketSet, our_sockets: &Vec>, tcp_peek_waiting: &mut Vec>, diff --git a/services/net/src/std_udp.rs b/services/net/src/std_udp.rs index f8ff4c8ea..cf4f9a965 100644 --- a/services/net/src/std_udp.rs +++ b/services/net/src/std_udp.rs @@ -1,5 +1,4 @@ use crate::*; -use crate::device::NetPhy; use smoltcp::wire::{IpEndpoint, IpAddress}; use ticktimer_server::Ticktimer; @@ -8,11 +7,9 @@ use ticktimer_server::Ticktimer; /// Sockets are stored in the PID/SocketHandle HashMap `process_sockets` (this is shared with TCP) /// `recv` requests create `UpdStdState` objects, that are stored in a `udp_rx` Vec. -const BUFLEN: usize = NET_MTU as usize; - pub(crate) fn std_udp_bind( mut msg: xous::MessageEnvelope, - iface: &mut Interface, + _iface: &mut Interface, sockets: &mut SocketSet, our_sockets: &mut Vec>, ) { @@ -55,7 +52,6 @@ pub(crate) fn std_udp_bind( .map_err(|e| match e { smoltcp::socket::udp::BindError::InvalidState => NetError::SocketInUse, smoltcp::socket::udp::BindError::Unaddressable => NetError::Unaddressable, - _ => NetError::LibraryError, }) { log::trace!("couldn't connect: {:?}", e); @@ -249,7 +245,6 @@ pub(crate) fn std_udp_tx( .map_err(|e| match e { smoltcp::socket::udp::BindError::InvalidState => NetError::WouldBlock, smoltcp::socket::udp::BindError::Unaddressable => NetError::Unaddressable, - _ => NetError::LibraryError, }) { std_failure(msg, e); return; @@ -286,9 +281,6 @@ pub(crate) fn udp_rx_success(buf: &mut [u8], rx: &[u8], ep: IpEndpoint) { *d = s; } } - _ => { - buf[3] = 0; // this is the invalid/error type - } } let port = ep.port.to_le_bytes(); buf[20] = port[0];