mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
add a loopback re-queue function to the com
the caller also needs to schedule the rx function explicitly, not handled by these functions.
This commit is contained in:
parent
7606d244e8
commit
f282cce900
1 changed files with 26 additions and 1 deletions
|
|
@ -10,7 +10,8 @@ use com_rs_ref::{DhcpState, LinkState};
|
|||
use xous::{send_message, Error, CID, Message, msg_scalar_unpack};
|
||||
use xous_ipc::{String, Buffer};
|
||||
use num_traits::{ToPrimitive, FromPrimitive};
|
||||
|
||||
use std::collections::VecDeque;
|
||||
use std::cell::RefCell;
|
||||
pub use com_rs_ref::serdes::Ipv4Conf;
|
||||
use xous_semver::SemVer;
|
||||
|
||||
|
|
@ -47,6 +48,9 @@ pub struct Com {
|
|||
battstats_sid: Option<xous::SID>,
|
||||
ec_lock_id: Option<[u32; 4]>,
|
||||
ec_acquired: bool,
|
||||
/// this is a hack to make loopbacks work on smoltcp. Work-around taken from Redox, but tracking this issue as well:
|
||||
/// https://github.com/smoltcp-rs/smoltcp/issues/50 and https://github.com/smoltcp-rs/smoltcp/issues/55
|
||||
loopback_buf: RefCell::<VecDeque::<Vec::<u8>>>,
|
||||
}
|
||||
impl Com {
|
||||
pub fn new(xns: &xous_names::XousNames) -> Result<Self, xous::Error> {
|
||||
|
|
@ -57,6 +61,7 @@ impl Com {
|
|||
battstats_sid: None,
|
||||
ec_lock_id: None,
|
||||
ec_acquired: false,
|
||||
loopback_buf: RefCell::new(VecDeque::new()),
|
||||
})
|
||||
}
|
||||
pub fn conn(&self) -> CID {self.conn}
|
||||
|
|
@ -535,6 +540,19 @@ impl Com {
|
|||
if pkt.len() > NET_MTU {
|
||||
return Err(xous::Error::OutOfMemory)
|
||||
}
|
||||
{
|
||||
// this is a hack to make loopbacks work on smoltcp. Work-around taken from Redox, but tracking this issue as well:
|
||||
// https://github.com/smoltcp-rs/smoltcp/issues/50 and https://github.com/smoltcp-rs/smoltcp/issues/55
|
||||
// Inject the loopback packets. loopback packets always take priority, for now.
|
||||
if let Some(loop_packet) = self.loopback_buf.borrow_mut().pop_front() {
|
||||
// pkt.len() is almost always not loop_packet.len(), just copy the first bit that can fit and the rest is garbarge...
|
||||
for (&s, d) in loop_packet.iter().zip(pkt.iter_mut()) {
|
||||
*d = s;
|
||||
}
|
||||
// skips polling the COM -- let's hope there wasn't a race condition on the interrupt
|
||||
return Ok(())
|
||||
}
|
||||
}
|
||||
let mut prealloc: [u8; NET_MTU] = [0; NET_MTU];
|
||||
let len_bytes = (pkt.len() as u16).to_be_bytes();
|
||||
prealloc[0] = len_bytes[0];
|
||||
|
|
@ -548,6 +566,13 @@ impl Com {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
// this is a hack to make loopbacks work on smoltcp. Work-around taken from Redox, but tracking this issue as well:
|
||||
// https://github.com/smoltcp-rs/smoltcp/issues/50 and https://github.com/smoltcp-rs/smoltcp/issues/55
|
||||
// this function handles enqueuing packets for local injection
|
||||
pub fn wlan_queue_loopback(&self, pk: &[u8]) {
|
||||
self.loopback_buf.borrow_mut().push_back(pk.to_vec());
|
||||
}
|
||||
|
||||
pub fn wlan_send_packet(&self, pkt: &[u8]) -> Result<(), xous::Error> {
|
||||
if pkt.len() > NET_MTU {
|
||||
return Err(xous::Error::OutOfMemory)
|
||||
|
|
|
|||
Loading…
Reference in a new issue