2015-02-06 18:36:40 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Martine Lenders <mlenders@inf.fu-berlin.de>
|
|
|
|
* Copyright (C) 2015 Freie Universität Berlin
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2015-02-13 12:40:14 +01:00
|
|
|
* @defgroup net_ng_netdev Network device driver interface
|
2015-02-10 14:22:15 +01:00
|
|
|
* @ingroup net
|
2015-02-06 18:36:40 +01:00
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Network device driver interface definition.
|
|
|
|
*
|
|
|
|
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
|
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
|
|
|
*/
|
|
|
|
|
2015-02-10 14:22:36 +01:00
|
|
|
#ifndef NG_NETDEV_H_
|
|
|
|
#define NG_NETDEV_H_
|
2015-02-06 18:36:40 +01:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2015-01-22 15:30:27 +01:00
|
|
|
#include "net/ng_pkt.h"
|
2015-02-06 18:36:40 +01:00
|
|
|
#include "net/ng_netconf.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Type for @ref msg_t if device fired an event
|
|
|
|
*/
|
2015-02-10 17:59:06 +01:00
|
|
|
#define NG_NETDEV_MSG_TYPE_EVENT (0x0100)
|
2015-02-06 18:36:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Possible event types that are send from the device driver to the
|
|
|
|
* MAC layer
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
NETDEV_EVENT_RX_STARTED = 0x0001, /**< started to receive a packet */
|
|
|
|
NETDEV_EVENT_RX_COMPLETE = 0x0002, /**< finished receiving a packet */
|
|
|
|
NETDEV_EVENT_TX_STARTED = 0x0004, /**< started to transfer a packet */
|
|
|
|
NETDEV_EVENT_TX_COMPLETE = 0x0008, /**< finished transferring packet */
|
|
|
|
/* expand this list if needed */
|
|
|
|
} ng_netdev_event_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Event callback for signaling event to a MAC layer
|
|
|
|
*
|
|
|
|
* @param[in] type type of the event
|
|
|
|
* @param[in] arg event argument, can e.g. contain a pktsnip_t pointer
|
|
|
|
*/
|
|
|
|
typedef void (*ng_netdev_event_cb_t)(ng_netdev_event_t type, void *arg);
|
|
|
|
|
|
|
|
/**
|
2015-02-13 12:40:14 +01:00
|
|
|
* @brief Forward declaration of ng_netdev_t due to cyclic dependency to
|
|
|
|
* @ref ng_netdev_driver_t.
|
|
|
|
*
|
|
|
|
* @see ng_netdev
|
2015-02-06 18:36:40 +01:00
|
|
|
*/
|
|
|
|
typedef struct ng_netdev ng_netdev_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Network device API definition.
|
|
|
|
*
|
|
|
|
* @details This is a set of functions that must be implemented by any driver
|
|
|
|
* for a network device.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
/**
|
|
|
|
* @brief Send data via a given network device
|
|
|
|
*
|
|
|
|
* @param[in] dev network device descriptor
|
|
|
|
* @param[in] pkt pointer to the data in the packet buffer
|
|
|
|
*
|
|
|
|
* @return number of bytes that were actually send out
|
2015-02-13 12:40:14 +01:00
|
|
|
* @return -ENODEV if @p dev is invalid
|
2015-02-06 18:36:40 +01:00
|
|
|
* @return -ENOMSG if pkt is invalid
|
|
|
|
*/
|
|
|
|
int (*send_data)(ng_netdev_t *dev, ng_pktsnip_t *pkt);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Registers an event callback to a given network device
|
|
|
|
*
|
|
|
|
* @param[in] dev network device descriptor
|
|
|
|
* @param[in] cb function that is called on events
|
|
|
|
*
|
|
|
|
* @return 0 on success
|
2015-02-13 12:40:14 +01:00
|
|
|
* @return -ENODEV if @p dev is invalid
|
2015-02-06 18:36:40 +01:00
|
|
|
* @return -ENOBUFS if maximum number of callbacks is exceeded
|
|
|
|
*/
|
|
|
|
int (*add_event_callback)(ng_netdev_t *dev, ng_netdev_event_cb_t cb);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Unregisters an event callback from a given network device
|
|
|
|
*
|
|
|
|
* @param[in] dev network device descriptor
|
|
|
|
* @param[in] cb callback function
|
|
|
|
*
|
|
|
|
* @return 0 on success
|
2015-02-13 12:40:14 +01:00
|
|
|
* @return -ENODEV if @p dev is invalid
|
2015-02-18 18:05:23 +01:00
|
|
|
* @return -ENOENT if callback was not registered
|
2015-02-06 18:36:40 +01:00
|
|
|
*/
|
|
|
|
int (*rem_event_callback)(ng_netdev_t *dev, ng_netdev_event_cb_t cb);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get an option value from a given network device
|
|
|
|
*
|
|
|
|
* @param[in] dev network device descriptor
|
|
|
|
* @param[in] opt option type
|
|
|
|
* @param[out] value pointer to store the option's value in
|
2015-03-13 19:39:32 +01:00
|
|
|
* @param[in] max_len maximal amount of byte that fit into @p value
|
2015-02-06 18:36:40 +01:00
|
|
|
*
|
2015-03-13 19:39:32 +01:00
|
|
|
* @return number of bytes written to @p value
|
2015-02-13 12:40:14 +01:00
|
|
|
* @return -ENODEV if @p dev is invalid
|
|
|
|
* @return -ENOTSUP if @p opt is not supported
|
|
|
|
* @return -EOVERFLOW if available space in @p value given in
|
2015-03-13 19:39:32 +01:00
|
|
|
* @p max_len is too small to store the option value
|
|
|
|
* @return -ECANCELED if internal driver error occurred
|
2015-02-06 18:36:40 +01:00
|
|
|
*/
|
|
|
|
int (*get)(ng_netdev_t *dev, ng_netconf_opt_t opt,
|
2015-03-13 19:39:32 +01:00
|
|
|
void *value, size_t max_len);
|
2015-02-06 18:36:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set an option value for a given network device
|
|
|
|
*
|
|
|
|
* @param[in] dev network device descriptor
|
|
|
|
* @param[in] opt option type
|
|
|
|
* @param[in] value value to set
|
2015-02-13 12:40:14 +01:00
|
|
|
* @param[in] value_len the length of @p value
|
2015-02-06 18:36:40 +01:00
|
|
|
*
|
2015-03-13 19:39:32 +01:00
|
|
|
* @return number of bytes used from @p value
|
2015-02-13 12:40:14 +01:00
|
|
|
* @return -ENODEV if @p dev is invalid
|
|
|
|
* @return -ENOTSUP if @p opt is not supported
|
|
|
|
* @return -EINVAL if @p value is invalid
|
2015-03-13 19:39:32 +01:00
|
|
|
* @return -ECANCELED if internal driver error occurred
|
2015-02-06 18:36:40 +01:00
|
|
|
*/
|
|
|
|
int (*set)(ng_netdev_t *dev, ng_netconf_opt_t opt,
|
|
|
|
void *value, size_t value_len);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This function is called by a MAC layer when a message of type
|
2015-03-08 22:41:35 +01:00
|
|
|
* @ref NG_NETDEV_MSG_TYPE_EVENT was received
|
2015-02-06 18:36:40 +01:00
|
|
|
*
|
|
|
|
* @param[in] dev network device descriptor
|
2015-03-08 22:41:35 +01:00
|
|
|
* @param[in] event_type event type, given by msg_t::content::value
|
|
|
|
* in the received message
|
2015-02-06 18:36:40 +01:00
|
|
|
*/
|
2015-03-08 22:42:35 +01:00
|
|
|
void (*isr_event)(ng_netdev_t *dev, uint32_t event_type);
|
2015-02-06 18:36:40 +01:00
|
|
|
} ng_netdev_driver_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The netdev data-structure holds the minimum information needed for
|
|
|
|
* interaction with MAC layers and can be expanded with device
|
|
|
|
* specific fields
|
|
|
|
*
|
|
|
|
* The netdev structure is the parent for all network device driver descriptors.
|
2015-02-13 12:40:14 +01:00
|
|
|
*
|
|
|
|
* @see ng_netdev_t
|
2015-02-06 18:36:40 +01:00
|
|
|
*/
|
|
|
|
struct ng_netdev {
|
|
|
|
ng_netdev_driver_t *driver; /**< pointer to the devices interface */
|
|
|
|
ng_netdev_event_cb_t event_cb; /**< netdev event callback */
|
|
|
|
kernel_pid_t mac_pid; /**< the driver's thread's PID */
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-02-10 14:22:36 +01:00
|
|
|
#endif /* NG_NETDEV_H_ */
|
2015-02-06 18:36:40 +01:00
|
|
|
/** @} */
|