[][src]Module smoltcp::phy

Access to networking hardware.

The phy module deals with the network devices. It provides a trait for transmitting and receiving frames, Device and implementations of it:

Examples

An implementation of the Device trait for a simple hardware Ethernet controller could look as follows:

use smoltcp::Result;
use smoltcp::phy::{self, DeviceCapabilities, Device};
use smoltcp::time::Instant;

struct StmPhy {
    rx_buffer: [u8; 1536],
    tx_buffer: [u8; 1536],
}

impl<'a> StmPhy {
    fn new() -> StmPhy {
        StmPhy {
            rx_buffer: [0; 1536],
            tx_buffer: [0; 1536],
        }
    }
}

impl<'a> phy::Device<'a> for StmPhy {
    type RxToken = StmPhyRxToken<'a>;
    type TxToken = StmPhyTxToken<'a>;

    fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> {
        Some((StmPhyRxToken(&mut self.rx_buffer[..]),
              StmPhyTxToken(&mut self.tx_buffer[..])))
    }

    fn transmit(&'a mut self) -> Option<Self::TxToken> {
        Some(StmPhyTxToken(&mut self.tx_buffer[..]))
    }

    fn capabilities(&self) -> DeviceCapabilities {
        let mut caps = DeviceCapabilities::default();
        caps.max_transmission_unit = 1536;
        caps.max_burst_size = Some(1);
        caps
    }
}

struct StmPhyRxToken<'a>(&'a [u8]);

impl<'a> phy::RxToken for StmPhyRxToken<'a> {
    fn consume<R, F>(self, _timestamp: Instant, f: F) -> Result<R>
        where F: FnOnce(&[u8]) -> Result<R>
    {
        // TODO: receive packet into buffer
        let result = f(self.0);
        println!("rx called");
        result
    }
}

struct StmPhyTxToken<'a>(&'a mut [u8]);

impl<'a> phy::TxToken for StmPhyTxToken<'a> {
    fn consume<R, F>(self, _timestamp: Instant, len: usize, f: F) -> Result<R>
        where F: FnOnce(&mut [u8]) -> Result<R>
    {
        let result = f(&mut self.0[..len]);
        println!("tx called {}", len);
        // TODO: send packet out
        result
    }
}

Structs

ChecksumCapabilities

A description of checksum behavior for every supported protocol.

DeviceCapabilities

A description of device capabilities.

FaultInjector

A fault injector device.

Loopback

A loopback device.

PcapWriter

A packet capture writer device.

RawSocket

A socket that captures or transmits the complete frame.

TapInterface

A virtual Ethernet interface.

Tracer

A tracer device.

Enums

Checksum

A description of checksum behavior for a particular protocol.

PcapLinkType

Captured packet header type.

PcapMode

Packet capture mode.

Traits

Device

An interface for sending and receiving raw network frames.

PcapSink

A packet capture sink.

RxToken

A token to receive a single network packet.

TxToken

A token to transmit a single network packet.

Functions

wait

Wait until given file descriptor becomes readable, but no longer than given timeout.

Type Definitions

EthernetTracer

A tracer device for Ethernet frames.