From ef164871a1bd2d4f04c429f8e1b9290252a1975b Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 16 Jul 2022 23:11:13 +0800 Subject: [PATCH] move COM link error handling up the stack a bit this allows us to have better error reporting and handle the cases where the EC is updating and just generating random vectors more...palatable. --- services/com/src/lib.rs | 8 +++++++- services/com/src/main.rs | 3 ++- services/net/src/main.rs | 27 +++++++++++++++++++++++---- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/services/com/src/lib.rs b/services/com/src/lib.rs index 83e14c375..132339e10 100644 --- a/services/com/src/lib.rs +++ b/services/com/src/lib.rs @@ -514,7 +514,13 @@ impl Com { 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) + if (config.mac[0] & 0xFE) == 0x01 || + (config.addr[0] & 0xF0) == 0xE0 { + // something is wrong with the COM; probably the link is being reset or not in a proper state. + Err(xous::Error::BadAddress) + } else { + Ok(config) + } } pub fn wlan_debug(&self) -> Result { diff --git a/services/com/src/main.rs b/services/com/src/main.rs index c06bddd9c..c99662797 100644 --- a/services/com/src/main.rs +++ b/services/com/src/main.rs @@ -1014,7 +1014,8 @@ fn main() -> ! { multicast is self.mac[0] & 0x1 == 1 -> this gets set when 0xDDDD or 0xDEAD is transmitted as EC is in reset broadcast is 0xFF's -> this is unlikely to be sent, it only is sent if the EC won't configure at all */ - prealloc[1] &= 0xFF_FE; // this ensures the "safety" of a reported MAC, even if the EC is broken and avoiding system panic (issue #152) + // punting this to the lib side of things, so we can return an error and not just a bogus value. + // prealloc[1] &= 0xFF_FE; // this ensures the "safety" of a reported MAC, even if the EC is broken and avoiding system panic (issue #152) buffer.replace(prealloc).expect("couldn't return result on FlashOp"); } Some(Opcode::WlanFetchPacket) => { diff --git a/services/net/src/main.rs b/services/net/src/main.rs index 24ea35b7b..8bdf24d21 100644 --- a/services/net/src/main.rs +++ b/services/net/src/main.rs @@ -251,7 +251,21 @@ fn main() -> ! { let routes = Routes::new(BTreeMap::new()); // build the device - let hw_config = com.wlan_get_config().expect("couldn't fetch initial wifi MAC"); + let hw_config = match com.wlan_get_config() { + Ok(config) => config, + Err(e) => { + log::error!("Something is wrong with the EC, got {:?} when requesting a MAC address. Trying our best to bodge through it.", e); + Ipv4Conf { + dhcp: com_rs_ref::DhcpState::Invalid, + mac: [2, 2, 4, 5, 6, 2], + addr: [169, 254, 0, 2], // link local address + gtwy: [169, 254, 0, 1], // something bogus + mask: [255, 255, 0, 0,], + dns1: [1, 1, 1, 1], + dns2: [8, 8, 8, 8], + } + } + }; log::debug!("My MAC address is: {:x?}", hw_config.mac); let device = device::NetPhy::new(&xns); // needed by ICMP to determine if we should compute checksums @@ -1046,9 +1060,14 @@ fn main() -> ! { ComIntSources::WlanIpConfigUpdate => { // right now the WLAN implementation only does IPV4. So IPV6 compatibility ends here. // if IPV6 gets added to the EC/COM bus, ideally this is one of a couple spots in Xous that needs a tweak. - let config = com - .wlan_get_config() - .expect("couldn't retrieve updated ipv4 config"); + let config = match com + .wlan_get_config() { + Ok(config) => config, + Err(e) => { + log::error!("WLAN config interrupt was bogus. EC is probably updating? Ignoring. Error: {:?}", e); + continue; + } + }; log::info!("Network config acquired: {:?}", config); log::info!("{}NET.OK,{:?},{}", xous::BOOKEND_START,