Moep Library  2.0-nc
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups
Device

The Device API contains the functionality used to manage moep devices. More...

Files

file  dev.h
 

Typedefs

typedef struct moep_dev * moep_dev_t
 a moep device More...
 
typedef int(* dev_status_cb )(void *, int)
 a device status callback More...
 
typedef int(* rx_handler )(moep_dev_t dev, moep_frame_t frame)
 a receive handler More...
 
typedef int(* rx_raw_handler )(moep_dev_t dev, u8 *buf, size_t buflen)
 

Functions

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...
 

Detailed Description

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.

Typedef Documentation

typedef struct moep_dev* moep_dev_t

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
datauser specified data
statusthe transmission status of the device
Return values
0on success
nonzeroon error, errno should be set appropriately.
typedef int(* rx_handler)(moep_dev_t dev, moep_frame_t frame)

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
devthe moep device on which the frame was received
framethe frame
Return values
0on success
nonzeroon error, errno should be set appropriately.

Function Documentation

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
devthe moep device
statusthe receive status
Return values
0on success
-1on error, errno is set appropriately.
int moep_dev_get_tx_status ( moep_dev_t  dev)

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
devthe moep device
Returns
This function returns nonzero if the device accepts frames for transmission and 0 otherwise.
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

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
cbthe callback function
datathe argument for the callback function
Return values
0on success
-1on error, errno is set appropriately.
int moep_dev_pair ( moep_dev_t  dev1,
moep_dev_t  dev2 
)

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
dev1a moep device
dev2another moep device
Return values
0on success
-1on error, errno is set appropriately.
rx_handler moep_dev_get_rx_handler ( moep_dev_t  dev)

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
devthe moep device
Returns
This function returns a function pointer to the rx handler of the moep device.
rx_handler moep_dev_set_rx_handler ( moep_dev_t  dev,
rx_handler  handler 
)

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
devthe moep device
handlerthe rx handler
Returns
This function returns the previous rx handler.
int moep_dev_tx ( moep_dev_t  dev,
moep_frame_t  frame 
)

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
devthe moep device
framethe frame
Return values
0on success
-1on 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.
ENOMEMNot enough memory available
moep_frame_t moep_dev_frame_create ( moep_dev_t  dev)

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
devthe moep device
Returns
This function returns a moep frame.
Return values
NULLon error, errno is set appropriately.
Errors
ENOMEMNot enough memory available
moep_frame_t moep_dev_frame_decode ( moep_dev_t  dev,
u8 *  buf,
size_t  buflen 
)

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
devthe moep device
bufthe buffer with the frame
buflenthe length of the buffer
Returns
This function returns a moep frame.
Return values
NULLon error, errno is set appropriately.
void moep_dev_frame_convert ( moep_dev_t  dev,
moep_frame_t  frame 
)

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
devthe moep device
framethe frame
void moep_dev_close ( moep_dev_t  dev)

close a moep device

The function moep_dev_close() is used to close a moep device.

Parameters
devthe moep device