mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
intermediate commit trying to trace down how this receive process works.
This commit is contained in:
parent
e06d946bcd
commit
26069c023a
5 changed files with 46 additions and 33 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -2050,7 +2050,6 @@ checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e"
|
|||
[[package]]
|
||||
name = "smoltcp"
|
||||
version = "0.8.0"
|
||||
source = "git+https://github.com/smoltcp-rs/smoltcp.git#35e833e33dfd3e4efc3eb7d5de06bec17c54b011"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"byteorder",
|
||||
|
|
|
|||
|
|
@ -434,8 +434,8 @@ impl Com {
|
|||
pub fn wlan_get_config(&self) -> Result<Ipv4Conf, xous::Error> {
|
||||
let prealloc = Ipv4Conf::default().encode_u16();
|
||||
let mut buf = Buffer::into_buf(prealloc).or(Err(xous::Error::InternalError))?;
|
||||
buf.lend_mut(self.conn, Opcode::WlanGetConfig.to_u32().unwrap()).or(Err(xous::Error::InternalError))?;
|
||||
let response = buf.to_original().unwrap();
|
||||
buf.lend_mut(self.conn, Opcode::WlanGetConfig.to_u32().expect("WlanGetConfig failed")).or(Err(xous::Error::InternalError))?;
|
||||
let response = buf.to_original().expect("Couldn't convert WlanGetConfig buffer");
|
||||
let config = Ipv4Conf::decode_u16(&response);
|
||||
Ok(config)
|
||||
}
|
||||
|
|
@ -449,8 +449,8 @@ impl Com {
|
|||
prealloc[0] = len_bytes[0];
|
||||
prealloc[1] = len_bytes[1];
|
||||
let mut buf = Buffer::into_buf(prealloc).or(Err(xous::Error::InternalError))?;
|
||||
buf.lend_mut(self.conn, Opcode::WlanFetchPacket.to_u32().unwrap()).or(Err(xous::Error::InternalError))?;
|
||||
let response = buf.as_flat::<[u8; NET_MTU], _>().unwrap();
|
||||
buf.lend_mut(self.conn, Opcode::WlanFetchPacket.to_u32().expect("WlanFetchPacket failed")).or(Err(xous::Error::InternalError))?;
|
||||
let response = buf.as_flat::<[u8; NET_MTU], _>().expect("couldn't convert WlanFetchPacket buffer");
|
||||
for (&src, dst) in response.iter().zip(pkt.iter_mut()) {
|
||||
*dst = src;
|
||||
}
|
||||
|
|
@ -469,7 +469,7 @@ impl Com {
|
|||
*dst = src;
|
||||
}
|
||||
let buf = Buffer::into_buf(prealloc).or(Err(xous::Error::InternalError))?;
|
||||
buf.send(self.conn, Opcode::WlanSendPacket.to_u32().unwrap()).or(Err(xous::Error::InternalError))?;
|
||||
buf.send(self.conn, Opcode::WlanSendPacket.to_u32().expect("WlanSendPacket failed")).or(Err(xous::Error::InternalError))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,8 +23,10 @@ byteorder = { version = "1.0", default-features = false }
|
|||
# ugh. have to reference `main` directly because they haven't pushed a new tag in months, and none
|
||||
# of the worked examples match the actual documentation now.
|
||||
# pin at a commit, at least, so we aren't building on shifting sand
|
||||
git = "https://github.com/smoltcp-rs/smoltcp.git"
|
||||
commit = "35e833e33dfd3e4efc3eb7d5de06bec17c54b011"
|
||||
#git = "https://github.com/smoltcp-rs/smoltcp.git"
|
||||
#commit = "35e833e33dfd3e4efc3eb7d5de06bec17c54b011"
|
||||
path = "../../../smoltcp"
|
||||
features = ["verbose"]
|
||||
#version = "0.7.5"
|
||||
#features = ["proto-ipv4"]
|
||||
|
||||
|
|
|
|||
|
|
@ -2,16 +2,10 @@ use com::Com;
|
|||
use com::api::NET_MTU;
|
||||
|
||||
use smoltcp::Result;
|
||||
use smoltcp::phy::{self, DeviceCapabilities, Device, Medium};
|
||||
use smoltcp::phy::{self, DeviceCapabilities, Medium};
|
||||
|
||||
use smoltcp::iface::{InterfaceBuilder, NeighborCache, Routes};
|
||||
use smoltcp::socket::{IcmpEndpoint, IcmpPacketMetadata, IcmpSocket, IcmpSocketBuffer, SocketSet};
|
||||
use smoltcp::wire::{
|
||||
EthernetAddress, Icmpv4Packet, Icmpv4Repr, Icmpv6Packet, Icmpv6Repr, IpAddress, IpCidr,
|
||||
Ipv4Address, Ipv6Address,
|
||||
};
|
||||
use smoltcp::{
|
||||
time::{Duration, Instant},
|
||||
time::Instant,
|
||||
};
|
||||
|
||||
pub struct NetPhy {
|
||||
|
|
@ -74,13 +68,22 @@ impl<'a, 'c> phy::RxToken for NetPhyRxToken<'a> {
|
|||
fn consume<R, F>(mut self, _timestamp: Instant, f: F) -> Result<R>
|
||||
where F: FnOnce(&mut [u8]) -> Result<R>
|
||||
{
|
||||
if let Some(rx_len) = self.rx_avail {
|
||||
self.com.wlan_fetch_packet(&mut self.buf[..rx_len as usize]).unwrap();
|
||||
if let Some(rx_len) = self.rx_avail.take() {
|
||||
self.com.wlan_fetch_packet(&mut self.buf[..rx_len as usize]).expect("Couldn't call wlan_fetch_packet in device adapter");
|
||||
self.buf = &mut self.buf[..rx_len as usize];
|
||||
log::info!("rxbuf: {:x?}", self.buf);
|
||||
}
|
||||
// else, the buf is not updated -- and it would be empty, yielding no availability
|
||||
|
||||
let result = f(&mut self.buf);
|
||||
log::info!("rx called");
|
||||
match result {
|
||||
Err(e) => {
|
||||
log::info!("rx err: {:?}", e);
|
||||
}
|
||||
_ => {
|
||||
log::info!("rx result: {:x?}", self.buf);
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ use num_traits::*;
|
|||
use com::api::{Ipv4Conf, NET_MTU, ComIntSources};
|
||||
|
||||
mod device;
|
||||
use device::*;
|
||||
|
||||
use byteorder::{ByteOrder, NetworkEndian};
|
||||
use std::cmp;
|
||||
|
|
@ -34,7 +33,7 @@ macro_rules! send_icmp_ping {
|
|||
data: &$echo_payload,
|
||||
};
|
||||
|
||||
let icmp_payload = $socket.send(icmp_repr.buffer_len(), $remote_addr).unwrap();
|
||||
let icmp_payload = $socket.send(icmp_repr.buffer_len(), $remote_addr).expect("couldn't send ping");
|
||||
|
||||
let icmp_packet = $packet_type::new_unchecked(icmp_payload);
|
||||
(icmp_repr, icmp_packet)
|
||||
|
|
@ -66,7 +65,7 @@ where
|
|||
DeviceT: for<'d> Device<'d>,
|
||||
{
|
||||
iface.update_ip_addrs(|addrs| {
|
||||
let dest = addrs.iter_mut().next().unwrap();
|
||||
let dest = addrs.iter_mut().next().expect("trouble updating ipv4 addresses in routing table");
|
||||
*dest = IpCidr::Ipv4(cidr);
|
||||
});
|
||||
}
|
||||
|
|
@ -88,7 +87,7 @@ impl SmoltcpTimer {
|
|||
#[xous::xous_main]
|
||||
fn xmain() -> ! {
|
||||
log_server::init_wait().unwrap();
|
||||
log::set_max_level(log::LevelFilter::Info);
|
||||
log::set_max_level(log::LevelFilter::Trace);
|
||||
log::info!("my PID is {}", xous::process::id());
|
||||
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
|
|
@ -142,6 +141,7 @@ fn xmain() -> ! {
|
|||
// link storage
|
||||
let timer = SmoltcpTimer::new();
|
||||
let neighbor_cache = NeighborCache::new(BTreeMap::new());
|
||||
let ip_addrs = [IpCidr::new(Ipv4Address::UNSPECIFIED.into(), 0)];
|
||||
let mut routes_storage = [None; 1];
|
||||
let routes = Routes::new(&mut routes_storage[..]);
|
||||
|
||||
|
|
@ -149,7 +149,7 @@ fn xmain() -> ! {
|
|||
let device_caps = device.capabilities();
|
||||
let medium = device.capabilities().medium;
|
||||
let mut builder = InterfaceBuilder::new(device)
|
||||
.ip_addrs([IpCidr::new(IpAddress::v4(0, 0, 0, 0), 24,)])
|
||||
.ip_addrs(ip_addrs)
|
||||
.routes(routes);
|
||||
if medium == Medium::Ethernet {
|
||||
builder = builder
|
||||
|
|
@ -182,7 +182,7 @@ fn xmain() -> ! {
|
|||
log::warn!("Battery is critical! TODO: go into SHIP mode");
|
||||
},
|
||||
ComIntSources::WlanIpConfigUpdate => {
|
||||
let config = com.wlan_get_config().unwrap();
|
||||
let config = com.wlan_get_config().expect("couldn't retrieve updated ipv4 config");
|
||||
net_config = Some(config);
|
||||
log::info!("Network config updated: {:?}", config);
|
||||
let mac = EthernetAddress::from_bytes(&config.mac);
|
||||
|
|
@ -203,34 +203,41 @@ fn xmain() -> ! {
|
|||
);
|
||||
|
||||
iface.routes_mut().remove_default_ipv4_route();
|
||||
iface.routes_mut().add_default_ipv4_route(default_v4_gw).unwrap();
|
||||
match iface.routes_mut().add_default_ipv4_route(default_v4_gw) {
|
||||
Ok(route) => log::info!("routing table updated successfully: {:?}", route),
|
||||
Err(e) => log::info!("routing table update error: {}", e),
|
||||
}
|
||||
},
|
||||
ComIntSources::WlanRxReady => {
|
||||
if let Some(_config) = net_config {
|
||||
if let Some(rxlen) = maybe_rxlen {
|
||||
match iface.device_mut().push_rx_avail(rxlen) {
|
||||
None => {},
|
||||
None => log::info!("pushed {} bytes avail to iface", rxlen),
|
||||
Some(_) => log::warn!("Got more packets, but smoltcp didn't receive them"),
|
||||
}
|
||||
|
||||
// now fire off the smoltcp receive machine....
|
||||
{
|
||||
let timestamp = timer.now();
|
||||
log::info!("entering poll");
|
||||
match iface.poll(&mut sockets, timestamp) {
|
||||
Ok(_) => {}
|
||||
Ok(_) => { log::info!("poll OK") }
|
||||
Err(e) => {
|
||||
log::debug!("poll error: {}", e);
|
||||
}
|
||||
}
|
||||
log::info!("leaving poll");
|
||||
{
|
||||
let timestamp = timer.now();
|
||||
let mut socket = sockets.get::<IcmpSocket>(icmp_handle);
|
||||
if !socket.is_open() {
|
||||
socket.bind(IcmpEndpoint::Ident(ident)).unwrap();
|
||||
log::info!("bind to icmp");
|
||||
socket.bind(IcmpEndpoint::Ident(ident)).expect("couldn't bind to icmp socket");
|
||||
send_at = timestamp;
|
||||
}
|
||||
|
||||
if socket.can_send() && seq_no < count as u16 && send_at <= timestamp {
|
||||
log::info!("send icmp {}", count);
|
||||
NetworkEndian::write_i64(&mut echo_payload, timestamp.total_millis());
|
||||
|
||||
match ping_remote_addr {
|
||||
|
|
@ -255,13 +262,15 @@ fn xmain() -> ! {
|
|||
}
|
||||
|
||||
if socket.can_recv() {
|
||||
let (payload, _) = socket.recv().unwrap();
|
||||
log::info!("socket can_recv()");
|
||||
let (payload, _) = socket.recv().expect("couldn't receive on socket despite asserting availability");
|
||||
log::info!("payload: {:x?}", payload);
|
||||
|
||||
match ping_remote_addr {
|
||||
IpAddress::Ipv4(_) => {
|
||||
let icmp_packet = Icmpv4Packet::new_checked(&payload).unwrap();
|
||||
let icmp_packet = Icmpv4Packet::new_checked(&payload).expect("couldn't make icmp payload");
|
||||
let icmp_repr =
|
||||
Icmpv4Repr::parse(&icmp_packet, &device_caps.checksum).unwrap();
|
||||
Icmpv4Repr::parse(&icmp_packet, &device_caps.checksum).expect("error parsing icmp4 repr");
|
||||
get_icmp_pong!(
|
||||
Icmpv4Repr,
|
||||
icmp_repr,
|
||||
|
|
@ -301,7 +310,7 @@ fn xmain() -> ! {
|
|||
}
|
||||
},
|
||||
ComIntSources::WlanSsidScanDone => {
|
||||
|
||||
log::info!("got ssid scan done");
|
||||
},
|
||||
_ => {
|
||||
log::error!("Invalid interrupt type received");
|
||||
|
|
|
|||
Loading…
Reference in a new issue