The Device API contains the functionality used to manage moep devices.
More...
|
int | moep_dev_set_rx_status (moep_dev_t dev, int status) |
| set the receive status of a moep device More...
|
|
int | moep_dev_get_tx_status (moep_dev_t dev) |
| get the transmission status of a device More...
|
|
int | moep_dev_set_tx_status_cb (moep_dev_t dev, dev_status_cb cb, void *data) |
| set the transmission status callback of a device More...
|
|
int | moep_dev_pair (moep_dev_t dev1, moep_dev_t dev2) |
| pair off two moep devices More...
|
|
rx_handler | moep_dev_get_rx_handler (moep_dev_t dev) |
| return the rx handler of a moep device More...
|
|
rx_handler | moep_dev_set_rx_handler (moep_dev_t dev, rx_handler handler) |
| set the rx handler of a moep device More...
|
|
int | moep_dev_tx (moep_dev_t dev, moep_frame_t frame) |
| transmit a frame More...
|
|
rx_raw_handler | moep_dev_get_rx_raw_handler (moep_dev_t dev) |
|
rx_raw_handler | moep_dev_set_rx_raw_handler (moep_dev_t dev, rx_raw_handler handler) |
|
int | moep_dev_tx_raw (moep_dev_t dev, u8 *buf, size_t buflen) |
|
moep_frame_t | moep_dev_frame_create (moep_dev_t dev) |
| create a frame More...
|
|
moep_frame_t | moep_dev_frame_decode (moep_dev_t dev, u8 *buf, size_t buflen) |
| decode a frame More...
|
|
void | moep_dev_frame_convert (moep_dev_t dev, moep_frame_t frame) |
| convert a frame More...
|
|
void | moep_dev_close (moep_dev_t dev) |
| close a moep device More...
|
|
The Device API contains the functionality used to manage moep devices.
This is the generic API available for all moep devices. Specialized functions are provided by the respective module.
a moep device
This is the opaque representation of a device.
typedef int(* dev_status_cb)(void *, int) |
a device status callback
A dev_status_cb() is a function that is called by a moep device if its transmission status changes.
- Parameters
-
data | user specified data |
status | the transmission status of the device |
- Return values
-
0 | on success |
nonzero | on error, errno should be set appropriately. |
a receive handler
A rx_handler() is a function pointer that is called by moep_select() when a frame was received. The frame must be destroyed when it is no longer needed. The handler is called with signals blocked, as they are blocked when entering moep_select(). When using moep_run() all signals are blocked. A rx_ handler must not block, otherwise a deadlock can occur. For this reason moep_dev_tx() also does not block.
- Parameters
-
dev | the moep device on which the frame was received |
frame | the frame |
- Return values
-
0 | on success |
nonzero | on error, errno should be set appropriately. |
int moep_dev_set_rx_status |
( |
moep_dev_t |
dev, |
|
|
int |
status |
|
) |
| |
set the receive status of a moep device
The function moep_dev_set_rx_status() is used to set the receive status of a moep device. If the status is 0, the device will not receive any frames. If the status is nonzero, the device will wait for incoming frames.
- Parameters
-
dev | the moep device |
status | the receive status |
- Return values
-
0 | on success |
-1 | on error, errno is set appropriately. |
get the transmission status of a device
The function moep_dev_get_tx_status() is used to get the transmission status of a moep device, i.e., if it is able to queue frames for transmission.
- Parameters
-
- Returns
- This function returns nonzero if the device accepts frames for transmission and 0 otherwise.
set the transmission status callback of a device
The function moep_dev_set_tx_status_cb() is used to register a callback. This callback is called whenever the transmission status (see moep_dev_get_tx_status()) changes. The callback is called with the specified data and the new status.
- Parameters
-
cb | the callback function |
data | the argument for the callback function |
- Return values
-
0 | on success |
-1 | on error, errno is set appropriately. |
pair off two moep devices
The function moep_dev_pair() is used to pair off two moep devices. It sets the receive events of the two devices to the tranmission event of the respective other device.
- Parameters
-
dev1 | a moep device |
dev2 | another moep device |
- Return values
-
0 | on success |
-1 | on error, errno is set appropriately. |
return the rx handler of a moep device
The function moep_dev_get_rx_handler() is used to get the receive handler of the moep device.
- Parameters
-
- Returns
- This function returns a function pointer to the rx handler of the moep device.
set the rx handler of a moep device
The function moep_dev_set_rx_handler() is used to set the receive handler of the moep device.
- Parameters
-
dev | the moep device |
handler | the rx handler |
- Returns
- This function returns the previous rx handler.
transmit a frame
The function moep_dev_tx() is used to transmit a frame through the moep device. This function does not actually transmit the frame, but only puts it into an internal send queue. Be sure to call moep_select() or moep_run() afterwards to schedule the transmission of the frame (except you have already called it, because you are inside a rx handler). This function does not block.
- Parameters
-
dev | the moep device |
frame | the frame |
- Return values
-
0 | on success |
-1 | on error, errno is set appropriately |
- Errors
- These are some standard errors generated by this function. Additionally the errors generated by moep_frame_encode() are relevant here.
ENOMEM | Not enough memory available |
create a frame
The function moep_dev_frame_create() is used to create a frame that is able to be sent through the device dev.
- Parameters
-
- Returns
- This function returns a moep frame.
- Return values
-
NULL | on error, errno is set appropriately. |
- Errors
ENOMEM | Not enough memory available |
decode a frame
The function moep_dev_frame_decode() decodes a frame from the buffer buf and creates a moep frame with the parsed content. The parsing is done suitable for the frame format specified by dev.
- Parameters
-
dev | the moep device |
buf | the buffer with the frame |
buflen | the length of the buffer |
- Returns
- This function returns a moep frame.
- Return values
-
NULL | on error, errno is set appropriately. |
convert a frame
The function moep_dev_frame_convert() is used to convert the headers to the format required by the moep device dev. This function does not convert any header data, it only removes the old headers and creates new empty headers in the specified format. This function is useful if you want to convert a frame, without copying the payload.
- Parameters
-
dev | the moep device |
frame | the frame |
close a moep device
The function moep_dev_close() is used to close a moep device.
- Parameters
-