diff --git a/Cargo.lock b/Cargo.lock index f34cbea99..1db0a23a6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -459,7 +459,7 @@ dependencies = [ [[package]] name = "com_rs" version = "0.1.0" -source = "git+https://github.com/betrusted-io/com_rs.git?rev=a8f282291cbc54ea9c6d6195caab029a1c7abd57#a8f282291cbc54ea9c6d6195caab029a1c7abd57" +source = "git+https://github.com/betrusted-io/com_rs.git?rev=1effb7eaebbec59f7fda4a678e2d36efafc2e673#1effb7eaebbec59f7fda4a678e2d36efafc2e673" [[package]] name = "com_rs-ref" diff --git a/imports/com_rs-ref/Cargo.toml b/imports/com_rs-ref/Cargo.toml index 834cbffe5..9ec1a9303 100644 --- a/imports/com_rs-ref/Cargo.toml +++ b/imports/com_rs-ref/Cargo.toml @@ -7,7 +7,7 @@ description = "com_rs import package" # Dependency policy: fully specify dependencies to the minor version number [dependencies] -com_rs = { git = "https://github.com/betrusted-io/com_rs.git", rev = "a8f282291cbc54ea9c6d6195caab029a1c7abd57" } +com_rs = { git = "https://github.com/betrusted-io/com_rs.git", rev = "1effb7eaebbec59f7fda4a678e2d36efafc2e673" } #com_rs = { path = "../../../betrusted-ec/sw/com_rs" } diff --git a/services/com/src/api.rs b/services/com/src/api.rs index b2a8124a2..5e8bfdc50 100644 --- a/services/com/src/api.rs +++ b/services/com/src/api.rs @@ -118,6 +118,19 @@ impl WlanStatus { } } +#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Default)] +pub struct WlanDebug { + pub tx_errs: u32, + pub drops: u32, + // config(2) - control - alloc_fail(2) - alloc_oversize(2) - alloc_count + pub config: u32, + pub control: u16, + pub alloc_fail: u32, + pub alloc_oversize: u32, + pub alloc_free_count: u16, +} + + #[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)] pub(crate) enum Opcode { /// Reset the COM link - useful after an EC reset @@ -244,6 +257,9 @@ pub(crate) enum Opcode { /// wlan: send net packet WlanSendPacket, + /// wlan: debug infos + WlanDebug, + /// sets the EC-side com interrupt mask IntSetMask, diff --git a/services/com/src/lib.rs b/services/com/src/lib.rs index e2fbf2e8f..2c0d7a22c 100644 --- a/services/com/src/lib.rs +++ b/services/com/src/lib.rs @@ -467,6 +467,14 @@ impl Com { Ok(config) } + pub fn wlan_debug(&self) -> Result { + let prealloc = WlanDebug::default(); + let mut buf = Buffer::into_buf(prealloc).or(Err(xous::Error::InternalError))?; + buf.lend_mut(self.conn, Opcode::WlanDebug.to_u32().expect("WlanDebug failed")).or(Err(xous::Error::InternalError))?; + let response = buf.to_original().expect("Couldn't convert WlanDebug buffer"); + Ok(response) + } + pub fn wlan_fetch_packet(&self, pkt: &mut [u8]) -> Result<(), xous::Error> { if pkt.len() > NET_MTU { return Err(xous::Error::OutOfMemory) diff --git a/services/com/src/main.rs b/services/com/src/main.rs index 81f6c02e7..288a003d6 100644 --- a/services/com/src/main.rs +++ b/services/com/src/main.rs @@ -929,6 +929,38 @@ fn xmain() -> ! { .expect("couldn't return IntFetchVector"); } }), + Some(Opcode::WlanDebug) => { + com.txrx(ComState::WLAN_GET_ERRCOUNTS.verb); + let mut tx_errs_16 = [0u16; 2]; + let mut drops_16 = [0u16; 2]; + tx_errs_16[0] = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)); + tx_errs_16[1] = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)); + drops_16[0] = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)); + drops_16[1] = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)); + com.txrx(ComState::WF200_DEBUG.verb); + let mut config_16 = [0u16; 2]; + config_16[0] = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)); + config_16[1] = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)); + let control = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)); + let mut alloc_fail_16 = [0u16; 2]; + alloc_fail_16[0] = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)); + alloc_fail_16[1] = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)); + let mut alloc_oversize_16 = [0u16; 2]; + alloc_oversize_16[0] = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)); + alloc_oversize_16[1] = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)); + let alloc_free_count = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)); + let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) }; + let debug = WlanDebug { + tx_errs: from_le_words(tx_errs_16), + drops: from_le_words(drops_16), + config: from_le_words(config_16), + control, + alloc_fail: from_le_words(alloc_fail_16), + alloc_oversize: from_le_words(alloc_oversize_16), + alloc_free_count, + }; + buffer.replace(debug).unwrap(); + }, None => {error!("unknown opcode"); break}, } @@ -963,7 +995,8 @@ fn parse_version(com: &mut crate::implementation::XousCom) -> u32 { dst[1] = src.to_le_bytes()[1]; } // translate u8 array into &str - let revstr = core::str::from_utf8(&rev_bytes[..rev_ret[0] as usize]).expect("gitrev is not valid utf-8"); + let len_checked = if rev_ret[0] as usize <= rev_bytes.len() { rev_ret[0] as usize} else {rev_bytes.len()}; + let revstr = core::str::from_utf8(&rev_bytes[..len_checked]).unwrap_or("v0.0.0-0-xxxxxxx"); // fake version number for hosted mode // parse &str -- we do it here not in the EC, because the EC is memory-constrained // v0.9.5-2-gb3e2868 exemplar template let hyphenstr: Vec<&str> = revstr[1..].split('-').collect(); // drop the leading 'v' by doing [1..] @@ -982,4 +1015,8 @@ fn parse_version(com: &mut crate::implementation::XousCom) -> u32 { 0 }; (commit & 0xff) as u32 | ((rev & 0xff) as u32) << 8 | (((minor & 0xff) as u32) << 16) | (((major & 0xff) as u32) << 24) +} + +fn from_le_words(words: [u16; 2]) -> u32 { + words[0] as u32 | (words[1] as u32) << 16 } \ No newline at end of file diff --git a/services/net/src/api.rs b/services/net/src/api.rs index 222d54b6e..88ca1f434 100644 --- a/services/net/src/api.rs +++ b/services/net/src/api.rs @@ -49,6 +49,10 @@ pub(crate) enum Opcode { PingSetTimeout, PingGetTimeout, + /// Link Management, + GetIpv4Config, + Reset, + /// [Internal] com llio interrupt callback ComInterrupt, /// [Internal] run the network stack code diff --git a/services/net/src/connection_manager.rs b/services/net/src/connection_manager.rs index cdec26e32..c879d0c5d 100644 --- a/services/net/src/connection_manager.rs +++ b/services/net/src/connection_manager.rs @@ -20,6 +20,7 @@ pub(crate) fn connection_manager(sid: xous::SID, activity_interval: Arc NetManager { + NetManager { + netconn: NetConn::new(&xous_names::XousNames::new().unwrap()).expect("can't connect to Net Server"), + } + } + pub fn get_ipv4_config(&self) -> Option { + let storage = Some(Ipv4Conf::default().encode_u16()); + let mut buf = Buffer::into_buf(storage).expect("Couldn't convert to memory structure"); + buf.lend_mut(self.netconn.conn(), Opcode::GetIpv4Config.to_u32().unwrap()).expect("Couldn't execute GetIpv4Config opcode"); + let maybe_config = buf.to_original().expect("couldn't restore config structure"); + if let Some(config) = maybe_config { + let ipv4 = Ipv4Conf::decode_u16(&config); + Some(ipv4) + } else { + None + } + } + pub fn reset(&self) { + send_message( + self.netconn.conn(), + Message::new_blocking_scalar(Opcode::Reset.to_usize().unwrap(), 0, 0, 0, 0), + ).expect("couldn't send reset"); + } +} \ No newline at end of file diff --git a/services/net/src/main.rs b/services/net/src/main.rs index fc74a81f6..20a8e4c26 100644 --- a/services/net/src/main.rs +++ b/services/net/src/main.rs @@ -950,6 +950,38 @@ fn xmain() -> ! { } } } + Some(Opcode::GetIpv4Config) => { + let mut buffer = unsafe { + Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) + }; + let ser = if let Some(config) = net_config { + Some(config.encode_u16()) + } else { + None + }; + buffer.replace(ser).expect("couldn't return config"); + }, + Some(Opcode::Reset) => { + net_config = None; + let neighbor_cache = NeighborCache::new(BTreeMap::new()); + let ip_addrs = [IpCidr::new(Ipv4Address::UNSPECIFIED.into(), 0)]; + let routes = Routes::new(BTreeMap::new()); + let device = device::NetPhy::new(&xns); + let medium = device.capabilities().medium; + let mut builder = InterfaceBuilder::new(device) + .ip_addrs(ip_addrs) + .routes(routes); + if medium == Medium::Ethernet { + builder = builder + .ethernet_addr(EthernetAddress::from_bytes(&[0; 6])) + .neighbor_cache(neighbor_cache); + } + iface = builder.finalize(); + iface.routes_mut().remove_default_ipv4_route(); + dns_allclear_hook.notify(); + // question: do we need to clear the UDP and ICMP states? + xous::return_scalar(msg.sender, 1).unwrap(); + } Some(Opcode::SuspendResume) => xous::msg_scalar_unpack!(msg, token, _, _, _, { // handle an suspend/resume state stuff here. right now, it's a NOP susres.suspend_until_resume(token).expect("couldn't execute suspend/resume"); diff --git a/services/shellchat/src/cmds/wlan.rs b/services/shellchat/src/cmds/wlan.rs index 2b354e472..d2e9abd9f 100644 --- a/services/shellchat/src/cmds/wlan.rs +++ b/services/shellchat/src/cmds/wlan.rs @@ -132,6 +132,10 @@ impl<'a> ShellCmdApi<'a> for Wlan { Err(e) => write!(ret, "Error: {:?}", e), }; } + "debug" => { + let debug = env.com.wlan_debug().expect("couldn't issue debug command"); + write!(ret, "{:x?}", debug).unwrap(); + } _ => { show_help = true; }