From fbd0bc542fb99a08030413af77c5206850bf85f5 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 15 Jan 2022 15:13:51 +0800 Subject: [PATCH] detect when the WF200 goes catatonic and reset it This is not the fix I was hoping for for connection stability, but unfortunately this is where we are at. The problem is that at some point the WF200 throws a "host interface error"; but the error codes show no specific error. After throwing this error, it can respond to some basic commands (such as the one asking what the current status and error codes are), but higher level APIs seem to time out. There's no command to bring the WF200 stack to a sane state (like a warm reset or buffer flush) as far as I can see, so, the solution is to detect the issue and send a reset to the WF200. This keeps the link up in the long term, but you will experience drop-outs about once every 2-3 hours for about 20 seconds while the system detects and fixes the problem. I think for this one, more data will be needed from customer units to see if this could be just a local network issue with my config or a more pervasive problem. --- services/net/src/connection_manager.rs | 32 +++++++++++++++++++------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/services/net/src/connection_manager.rs b/services/net/src/connection_manager.rs index c879d0c5d..af7f98ffd 100644 --- a/services/net/src/connection_manager.rs +++ b/services/net/src/connection_manager.rs @@ -14,7 +14,9 @@ pub(crate) enum ConnectionManagerOpcode { Quit, } #[allow(dead_code)] -const POLL_INTERVAL_MS: usize = 10_151; // stagger slightly off of an integer-seconds interval to even out loads +const POLL_INTERVAL_MS: usize = 20_151; // stagger slightly off of an integer-seconds interval to even out loads +#[allow(dead_code)] +const BOOT_POLL_INTERVAL_MS: usize = 5_758; // a slightly faster poll during boot so we acquire wifi faster once PDDB is mounted pub(crate) fn connection_manager(sid: xous::SID, activity_interval: Arc) { let tt = ticktimer_server::Ticktimer::new().unwrap(); @@ -36,25 +38,34 @@ pub(crate) fn connection_manager(sid: xous::SID, activity_interval: Arc msg_scalar_unpack!(msg, poll_interval, _, _, _, { + Some(ConnectionManagerOpcode::Run) => msg_scalar_unpack!(msg, _, _, _, _, { if !run { run = true; - send_message(self_cid, Message::new_scalar(ConnectionManagerOpcode::Poll.to_usize().unwrap(), poll_interval, 0, 0, 0)).expect("couldn't kick off next poll"); + send_message(self_cid, Message::new_scalar(ConnectionManagerOpcode::Poll.to_usize().unwrap(), 0, 0, 0, 0)).expect("couldn't kick off next poll"); } }), - Some(ConnectionManagerOpcode::Poll) => msg_scalar_unpack!(msg, next_poll, _, _, _, { - if activity_interval.fetch_add(POLL_INTERVAL_MS as u32, Ordering::SeqCst) > POLL_INTERVAL_MS as u32 { + Some(ConnectionManagerOpcode::Poll) => msg_scalar_unpack!(msg, _, _, _, _, { + if activity_interval.fetch_add(current_interval as u32, Ordering::SeqCst) > current_interval as u32 { log::info!("wlan activity interval timeout"); // if the pddb isn't mounted, don't even bother checking -- we can't connect until we have a place to get keys if pddb.is_mounted() && rev_ok { + mounted = true; // the status check code is going to get refactored, so this is a "bare minimum" check let status = com.wlan_status().unwrap(); let config = netmgr.get_ipv4_config(); + if status.link_state == com_rs_ref::LinkState::WFXError { + com.wlan_leave().expect("couldn't issue leave command"); // this may not be received by the wf200, *but* it will also re-init the DHCP stack on the EC + netmgr.reset(); // this will clear our internal net state + // the wfx chip is wedged. kick it. This call has a built-in 2 second delay. + com.wifi_reset().expect("couldn't reset the wf200 chip"); + } let needs_reconnect = if status.link_state == com_rs_ref::LinkState::Connected { if let Some(config) = config { // check that the EC's view of the world is synchronized with our view @@ -102,8 +113,13 @@ pub(crate) fn connection_manager(sid: xous::SID, activity_interval: Arc