Structure to hold driver interface -> function mapping. More...
Structure to hold driver interface -> function mapping.
The send/receive functions expect/return a full ethernet frame (dst mac, src mac, ethertype, payload, no checksum).
#include <netdev.h>
Data Fields | |
int(* | send )(netdev_t *dev, const iolist_t *iolist) |
Start transmission of the given frame and return directly. | |
int(* | confirm_send )(netdev_t *dev, void *info) |
Fetch the status of a transmission and perform any potential cleanup. | |
int(* | recv )(netdev_t *dev, void *buf, size_t len, void *info) |
Drop a received frame, OR get the length of a received frame, OR get a received frame. | |
int(* | init )(netdev_t *dev) |
the driver's initialization function | |
void(* | isr )(netdev_t *dev) |
a driver's user-space ISR handler | |
int(* | get )(netdev_t *dev, netopt_t opt, void *value, size_t max_len) |
Get an option value from a given network device. | |
int(* | set )(netdev_t *dev, netopt_t opt, const void *value, size_t value_len) |
Set an option value for a given network device. | |
int(* netdev_driver::confirm_send) (netdev_t *dev, void *info) |
Fetch the status of a transmission and perform any potential cleanup.
[in] | dev | Network device descriptor. Must not be NULL. |
[out] | info | Device class specific type to fetch transmission info. May be NULL if not needed by upper layer. May be ignored by driver. |
-EAGAIN | Transmission still ongoing. (Call later again!) |
-EHOSTUNREACH | Layer 2 ACK timeout |
-EBUSY | Medium is busy. (E.g. Auto-CCA failed / timed out, collision detected) |
-ENETDOWN | Interface is not connected / powered down |
-EIO | Any kind of transmission error Use info for more details |
<0 | Other error. (Please use a negative errno code.) |
-EAGAIN
. -EAGAIN
after that event was received. Get an option value from a given network device.
(dev != NULL)
max_len
must be of exactly that length (see netopt documentation for type) max_len
must greater or equal the required length (see netopt documentation for type) value
must have the natural alignment of its type (see netopt documentation for type)[in] | dev | network device descriptor |
[in] | opt | option type |
[out] | value | pointer to store the option's value in |
[in] | max_len | maximal amount of byte that fit into value |
value
-ENOTSUP | if opt is not provided by the device |
int(* netdev_driver::init) (netdev_t *dev) |
void(* netdev_driver::isr) (netdev_t *dev) |
a driver's user-space ISR handler
(dev != NULL)
This function will be called from a network stack's loop when being notified by netdev_isr.
It is supposed to call netdev->event_callback() for each occurring event.
See receive frame flow description for details.
[in] | dev | network device descriptor. Must not be NULL. |
int(* netdev_driver::recv) (netdev_t *dev, void *buf, size_t len, void *info) |
Drop a received frame, OR get the length of a received frame, OR get a received frame.
(dev != NULL)
Supposed to be called from netdev->event_callback()
If buf
== NULL and len
== 0, returns the frame size – or an upper bound estimation of the size – without dropping the frame. If buf
== NULL and len
> 0, drops the frame and returns the frame size.
If called with buf
!= NULL and len
is smaller than the received frame:
buf
becomes invalid. (The driver may use the memory to implement the dropping - or may not change it.)-ENOBUFS
is returned[in] | dev | network device descriptor. Must not be NULL. |
[out] | buf | buffer to write into or NULL to return the frame size. |
[in] | len | maximum number of bytes to read. If buf is NULL the currently buffered frame is dropped when len > 0. Must not be 0 when buf != NULL. |
[out] | info | status information for the received frame. Might be of different type for different netdev devices. May be NULL if not needed or applicable. |
-ENOBUFS | if supplied buffer is too small |
Start transmission of the given frame and return directly.
(dev != NULL) && (iolist != NULL)
[in] | dev | Network device descriptor. Must not be NULL. |
[in] | iolist | IO vector list to send. Elements of this list may have iolist_t::iol_size == 0 and (in this case only) iolist_t::iol_data == 0. |
-EBUSY | Driver is temporarily unable to send, e.g. because an incoming frame on a half-duplex medium is received |
-ENETDOWN | Device is powered down |
<0 | Other error |
0 | Transmission successfully started |
>0 | Number of bytes transmitted (transmission already complete) |
This function will cause the driver to start the transmission in an async fashion. The driver will "own" the iolist
until a subsequent call to netdev_driver_t::confirm_send returns something different than -EAGAIN
. The driver must signal completion using the NETDEV_EVENT_TX_COMPLETE event, regardless of success or failure.
If the driver implements blocking send (e.g. because it writes out the frame byte-by-byte over a serial line) it can also return the number of bytes transmitted here directly. In this case it MUST NOT emit a NETDEV_EVENT_TX_COMPLETE event, netdev_driver_t::confirm_send will never be called but should still be implemented to signal conformance to the new API.
Old drivers might not be ported to the new API and have netdev_driver_t::confirm_send set to NULL
. In that case the driver will return the number of bytes transmitted on success (instead of 0
) and will likely block until completion.
Set an option value for a given network device.
(dev != NULL)
value_len
must be of exactly that length (see netopt documentation for type) value_len
must lesser or equal the required length (see netopt documentation for type) value
must have the natural alignment of its type (see netopt documentation for type)[in] | dev | network device descriptor |
[in] | opt | option type |
[in] | value | value to set |
[in] | value_len | the length of value |
value
-ENOTSUP | if opt is not configurable for the device |
-EINVAL | if value is an invalid value with regards to opt |