@@ -9,6 +9,9 @@ use crate::socket::WakerRegistration;
99
1010use crate :: storage:: Empty ;
1111
12+ use crate :: wire:: EthernetFrame ;
13+ use crate :: wire:: EthernetRepr ;
14+
1215/// Error returned by [`Socket::send`]
1316#[ derive( Debug , PartialEq , Eq , Clone , Copy ) ]
1417#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
@@ -294,6 +297,42 @@ impl<'a> Socket<'a> {
294297 self . rx_buffer . payload_bytes_count ( )
295298 }
296299
300+ pub ( crate ) fn accepts ( & self , eth_repr : & EthernetRepr ) -> bool {
301+ match self . ethertype {
302+ Some ( e) if e == eth_repr. ethertype . into ( ) => true ,
303+ Some ( _) => false ,
304+ None => true ,
305+ }
306+ }
307+
308+ pub ( crate ) fn process ( & mut self , _cx : & mut Context , eth_repr : & EthernetRepr , payload : & [ u8 ] ) {
309+ debug_assert ! ( self . accepts( eth_repr) ) ;
310+
311+ let header_len = eth_repr. buffer_len ( ) ;
312+ let total_len = header_len + payload. len ( ) ;
313+
314+ net_trace ! (
315+ "eth:{}: receiving {} octets" ,
316+ self . ethertype. unwrap_or( 0 ) ,
317+ total_len
318+ ) ;
319+
320+ match self . rx_buffer . enqueue ( total_len, ( ) ) {
321+ Ok ( buf) => {
322+ let mut frame = EthernetFrame :: new_checked ( buf) . expect ( "internal ethernet error" ) ;
323+ eth_repr. emit ( & mut frame) ;
324+ frame. payload_mut ( ) . copy_from_slice ( payload) ;
325+ }
326+ Err ( _) => net_trace ! (
327+ "eth:{}: buffer full, dropped incoming packet" ,
328+ self . ethertype. unwrap_or( 0 )
329+ ) ,
330+ }
331+
332+ #[ cfg( feature = "async" ) ]
333+ self . rx_waker . wake ( ) ;
334+ }
335+
297336 pub ( crate ) fn poll_at ( & self , _cx : & mut Context ) -> PollAt {
298337 if self . tx_buffer . is_empty ( ) {
299338 PollAt :: Ingress
0 commit comments