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.
This commit is contained in:
bunnie 2022-07-16 23:11:13 +08:00
parent 37154f3350
commit ef164871a1
3 changed files with 32 additions and 6 deletions

View file

@ -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<WlanDebug, xous::Error> {

View file

@ -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) => {

View file

@ -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,