diff --git a/services/net/src/api.rs b/services/net/src/api.rs index 04d1d7a8f..4a901f750 100644 --- a/services/net/src/api.rs +++ b/services/net/src/api.rs @@ -66,6 +66,7 @@ pub(crate) enum Opcode { SubscribeWifiStats, UnsubWifiStats, FetchSsidList, + ConnMgrStartStop, /// [Internal] com llio interrupt callback ComInterrupt, diff --git a/services/net/src/lib.rs b/services/net/src/lib.rs index 02241bd81..142722c29 100644 --- a/services/net/src/lib.rs +++ b/services/net/src/lib.rs @@ -160,6 +160,16 @@ impl NetManager { } Ok(ret) } + pub fn connection_manager_stop(&self) -> Result<(), xous::Error> { + send_message(self.netconn.conn(), + Message::new_scalar(Opcode::ConnMgrStartStop.to_usize().unwrap(), 0, 0,0, 0) + ).map(|_| ()) + } + pub fn connection_manager_run(&self) -> Result<(), xous::Error> { + send_message(self.netconn.conn(), + Message::new_scalar(Opcode::ConnMgrStartStop.to_usize().unwrap(), 1, 0,0, 0) + ).map(|_| ()) + } } impl Drop for NetManager { fn drop(&mut self) { diff --git a/services/net/src/main.rs b/services/net/src/main.rs index 98f6f75c1..540556056 100644 --- a/services/net/src/main.rs +++ b/services/net/src/main.rs @@ -9,7 +9,7 @@ use com::api::{ComIntSources, Ipv4Conf, NET_MTU}; mod device; mod connection_manager; -use xous::{Message, CID, SID, msg_scalar_unpack, msg_blocking_scalar_unpack}; +use xous::{Message, CID, SID, msg_scalar_unpack, msg_blocking_scalar_unpack, send_message}; use xous_ipc::Buffer; use std::collections::BTreeMap; use std::collections::HashMap; @@ -1437,6 +1437,23 @@ fn xmain() -> ! { let ret_list = buf.to_original::().expect("couldn't restore original"); buffer.replace(ret_list).expect("couldn't return config"); }, + Some(Opcode::ConnMgrStartStop) => msg_scalar_unpack!(msg, code, _, _, _, { + if code == 0 { // 0 is stop, 1 is start + send_message(cm_cid, + Message::new_scalar( + connection_manager::ConnectionManagerOpcode::Stop.to_usize().unwrap(), + 0, 0, 0, 0) + ).expect("couldn't send stop message"); + } else if code == 1 { + send_message(cm_cid, + Message::new_scalar( + connection_manager::ConnectionManagerOpcode::Run.to_usize().unwrap(), + 0, 0, 0, 0) + ).expect("couldn't send stop message"); + } else { + log::error!("Got incorrect start/stop code: {}", code); + } + }), Some(Opcode::Reset) => { net_config = None; let neighbor_cache = NeighborCache::new(BTreeMap::new()); diff --git a/services/shellchat/src/cmds/ecup.rs b/services/shellchat/src/cmds/ecup.rs index d6a4d19f0..ded96b70f 100644 --- a/services/shellchat/src/cmds/ecup.rs +++ b/services/shellchat/src/cmds/ecup.rs @@ -443,6 +443,7 @@ impl<'a> ShellCmdApi<'a> for EcUpdate { if let Some(sub_cmd) = tokens.next() { match sub_cmd { "fw" => { + env.netmgr.connection_manager_stop().unwrap(); self.in_progress = true; let start = env.ticktimer.elapsed_ms(); self.start_time = Some(start); @@ -452,6 +453,7 @@ impl<'a> ShellCmdApi<'a> for EcUpdate { write!(ret, "Starting EC firmware update").unwrap(); } "gw" => { + env.netmgr.connection_manager_stop().unwrap(); self.in_progress = true; let start = env.ticktimer.elapsed_ms(); self.start_time = Some(start); @@ -468,6 +470,7 @@ impl<'a> ShellCmdApi<'a> for EcUpdate { write!(ret, "EC has been reset, and new firmware loaded.").unwrap(); } "wf200" => { + env.netmgr.connection_manager_stop().unwrap(); self.in_progress = true; let start = env.ticktimer.elapsed_ms(); self.start_time = Some(start); @@ -483,6 +486,7 @@ impl<'a> ShellCmdApi<'a> for EcUpdate { return Ok(Some(ret)); } + env.netmgr.connection_manager_stop().unwrap(); self.in_progress = true; let start = env.ticktimer.elapsed_ms(); self.start_time = Some(start); @@ -523,14 +527,17 @@ impl<'a> ShellCmdApi<'a> for EcUpdate { }, Some(UpdateResult::ProgramDone) => { write!(ret, "Programming of {} bytes done in {:.1}s. Please restart EC with `ecup reset`.", progress, elapsed / 1000.0).unwrap(); + env.netmgr.connection_manager_run().unwrap(); self.in_progress = false; }, Some(UpdateResult::AutoDone) => { write!(ret, "Autoupdate of EC finished. Shutting down now...").unwrap(); + env.netmgr.connection_manager_run().unwrap(); self.in_progress = false; }, Some(UpdateResult::Abort) => { write!(ret, "Programming aborted in {:.1}s. Did you stage all the firmware objects?", elapsed / 1000.0).unwrap(); + env.netmgr.connection_manager_run().unwrap(); self.in_progress = false; } _ => write!(ret, "Got unknown update callback: {:?}", result_code).unwrap()