sys: net: replace dev_eth with netdev2, adapt native tap driver
parent
78b4bf6f58
commit
ef972735dc
@ -1,5 +1,4 @@
|
||||
ifneq (,$(filter gnrc_netif_default,$(USEMODULE)))
|
||||
USEMODULE += dev_eth_tap
|
||||
USEMODULE += gnrc_netdev_eth
|
||||
USEMODULE += gnrc_nomac
|
||||
USEMODULE += netdev2_tap
|
||||
USEMODULE += gnrc_netdev2
|
||||
endif
|
||||
|
@ -1,5 +1,3 @@
|
||||
MODULE = dev_eth_tap
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
|
||||
INCLUDES = $(NATIVEINCLUDES)
|
@ -1,3 +0,0 @@
|
||||
MODULE = dev_eth_autoinit
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "net/dev_eth.h"
|
||||
#include "dev_eth_autoinit.h"
|
||||
|
||||
#ifdef MODULE_DEV_ETH_TAP
|
||||
#include "dev_eth_tap.h"
|
||||
#endif
|
||||
|
||||
#ifdef MODULE_ENCX24J600
|
||||
#include "encx24j600.h"
|
||||
encx24j600_t dev_eth_encx24j600;
|
||||
#endif
|
||||
|
||||
dev_eth_t * const dev_eth_devices[] = {
|
||||
#ifdef MODULE_DEV_ETH_TAP
|
||||
[DEV_ETH_TAP] = (dev_eth_t*)&dev_eth_tap,
|
||||
#endif
|
||||
#ifdef MODULE_ENCX24J600
|
||||
[DEV_ETH_ENCX24J600] = (dev_eth_t*)&dev_eth_encx24j600,
|
||||
#endif
|
||||
};
|
||||
|
||||
void dev_eth_autoinit(void)
|
||||
{
|
||||
#ifdef MODULE_ENCX24J600
|
||||
/* TODO: use sensible defines */
|
||||
encx24j600_setup(&dev_eth_encx24j600, SPI_0, GPIO_1, GPIO_2);
|
||||
#endif
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* @ingroup auto_init_gnrc_netif
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Auto initialization for netdev Ethernet network interfaces
|
||||
*
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
* @author Oliver Hahm <oliver.hahm@inria.fr>
|
||||
*/
|
||||
|
||||
#ifdef MODULE_GNRC_NETDEV_ETH
|
||||
|
||||
#include "board.h"
|
||||
#include "net/gnrc/nomac.h"
|
||||
#include "net/gnrc.h"
|
||||
|
||||
#include "net/gnrc/netdev_eth.h"
|
||||
#include "net/dev_eth.h"
|
||||
#include "dev_eth_tap.h"
|
||||
|
||||
#define ENABLE_DEBUG (0)
|
||||
#include "debug.h"
|
||||
|
||||
/**
|
||||
* @brief Define stack parameters for the MAC layer thread
|
||||
* @{
|
||||
*/
|
||||
#define NETDEV_ETH_MAC_STACKSIZE (THREAD_STACKSIZE_DEFAULT)
|
||||
#define NETDEV_ETH_MAC_PRIO (THREAD_PRIORITY_MAIN - 4)
|
||||
|
||||
static char _nomac_stack[NETDEV_ETH_MAC_STACKSIZE];
|
||||
|
||||
void auto_init_gnrc_netdev_eth(void)
|
||||
{
|
||||
DEBUG("Initializing NETDEV_ETH device\n");
|
||||
int res = gnrc_netdev_eth_init(&gnrc_netdev_eth, (dev_eth_t*)&dev_eth_tap);
|
||||
|
||||
if (res < 0) {
|
||||
DEBUG("Error initializing NETDEV_ETH device!");
|
||||
}
|
||||
else {
|
||||
gnrc_nomac_init(_nomac_stack, NETDEV_ETH_MAC_STACKSIZE, NETDEV_ETH_MAC_PRIO,
|
||||
"tapnet", (gnrc_netdev_t *)&gnrc_netdev_eth);
|
||||
}
|
||||
}
|
||||
#else
|
||||
typedef int dont_be_pedantic;
|
||||
#endif /* MODULE_GNRC_NETDEV_ETH */
|
||||
|
||||
/** @} */
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup auto_init_ng_netif
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Auto initialization for ethernet devices
|
||||
*
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*/
|
||||
|
||||
#ifdef MODULE_NETDEV2_TAP
|
||||
|
||||
#define ENABLE_DEBUG (1)
|
||||
#include "debug.h"
|
||||
|
||||
#include "netdev2_tap.h"
|
||||
#include "net/gnrc/gnrc_netdev2_eth.h"
|
||||
|
||||
extern netdev2_tap_t netdev2_tap;
|
||||
|
||||
/**
|
||||
* @brief Define stack parameters for the MAC layer thread
|
||||
* @{
|
||||
*/
|
||||
#define TAP_MAC_STACKSIZE (THREAD_STACKSIZE_DEFAULT + DEBUG_EXTRA_STACKSIZE)
|
||||
#define TAP_MAC_PRIO (THREAD_PRIORITY_MAIN - 3)
|
||||
|
||||
/**
|
||||
* @brief Stacks for the MAC layer threads
|
||||
*/
|
||||
static char _netdev2_eth_stack[TAP_MAC_STACKSIZE + DEBUG_EXTRA_STACKSIZE];
|
||||
static gnrc_netdev2_t _gnrc_netdev2_tap;
|
||||
|
||||
void auto_init_netdev2_tap(void)
|
||||
{
|
||||
gnrc_netdev2_eth_init(&_gnrc_netdev2_tap, (netdev2_t*)&netdev2_tap);
|
||||
|
||||
gnrc_netdev2_init(_netdev2_eth_stack, TAP_MAC_STACKSIZE,
|
||||
TAP_MAC_PRIO, "gnrc_netdev2_tap", &_gnrc_netdev2_tap);
|
||||
}
|
||||
|
||||
#else
|
||||
typedef int dont_be_pedantic;
|
||||
#endif /* MODULE_NETDEV2_TAP */
|
||||
/** @} */
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup sys_net_dev_eth dev_eth auto setup
|
||||
* @ingroup net_ethernet
|
||||
* @file
|
||||
* @brief Automatically setup available ethernet devices
|
||||
* @{
|
||||
*
|
||||
* @brief header for dev_eth automatic initialization
|
||||
*
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*/
|
||||
|
||||
#ifndef DEV_ETH_AUTOINIT_H
|
||||
#define DEV_ETH_AUTOINIT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief enum for available ethernet devices
|
||||
*/
|
||||
enum {
|
||||
#ifdef MODULE_DEV_ETH_TAP
|
||||
DEV_ETH_TAP,
|
||||
#endif
|
||||
#ifdef MODULE_ENCX24J600
|
||||
DEV_ETH_ENCX24J600,
|
||||
#endif
|
||||
/* must be last: */
|
||||
NUM_DEV_ETH
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Array of const pointers to available ethernet devices
|
||||
*/
|
||||
extern dev_eth_t *const dev_eth_devices[];
|
||||
|
||||
/**
|
||||
* @brief Automatically sets up available dev_eth ethernet devices
|
||||
*
|
||||
* ... by calling the respective *_setup() functions if available.
|
||||
*/
|
||||
void dev_eth_autoinit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/** @} */
|
||||
#endif /* DEV_ETH_AUTOINIT_H */
|
@ -1,216 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
* Ell-i open source co-operative
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup net_dev_eth Low-Level Driver Interface
|
||||
* @ingroup net_ethernet
|
||||
* @brief Low-level ethernet driver interface
|
||||
*
|
||||
* This interface is supposed to be a low-level interface for ethernet drivers.
|
||||
* In order to be universally usable, it leaves out many implementation details
|
||||
* to the implementation of an actual network stack using this interface.
|
||||
*
|
||||
* In order to write a driver for this interface, you have to
|
||||
*
|
||||
* 1. create a (possibly const) eth_driver_t structure for your device type,
|
||||
* implement it's functions
|
||||
*
|
||||
* 2. create a dev_eth_t structure, used as device state and handle, for each device
|
||||
*
|
||||
* In order to use this interface, you have to
|
||||
*
|
||||
* 1. implement dev_eth_isr, dev_eth_rx_handler and dev_eth_linkstate_handler
|
||||
* 2. run a loop that get's notified by dev_eth_isr
|
||||
*
|
||||
* A devices send function should always be able to send a frame (and make sure of proper locking).
|
||||
*
|
||||
* Receive packet flow:
|
||||
*
|
||||
* 1. Ethernet driver receives packet, executes driver's internal ISR.
|
||||
* 2. driver's internal ISR should do minimal acknowledging and house keeping and then
|
||||
* call dev_eth_isr
|
||||
* 3. dev_eth_isr should notify a user of this API (e.g., the network stack's L2 thread)
|
||||
* 4. That thread executes the driver's user-space isr (dev->driver->isr)
|
||||
* 5. user space ISR handles less timing critical stuff, eventually calling
|
||||
* dev_eth_linkstate_handler and / or dev_eth_rx_handler
|
||||
*
|
||||
* Check out the dev_eth test application as example.
|
||||
*
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Definitions low-level ethernet driver interface
|
||||
*
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*/
|
||||
|
||||
#ifndef DEV_ETH_H
|
||||
#define DEV_ETH_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include "ethernet/hdr.h"
|
||||
|
||||
/**
|
||||
* @brief Structure to hold driver state
|
||||
*
|
||||
* Supposed to be extended by driver implementations.
|
||||
* The extended structure should contain all variable driver state.
|
||||
*/
|
||||
typedef struct dev_eth {
|
||||
const struct eth_driver *driver; /**< ptr to that driver's interface.
|
||||
driver->init() expects this to be present,
|
||||
so set this before using the device. */
|
||||
} dev_eth_t;
|
||||
|
||||
/**
|
||||
* @brief 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).
|
||||
*/
|
||||
typedef struct eth_driver {
|
||||
/**
|
||||
* @brief Send ethernet frame
|
||||
*
|
||||
* Expects a full ethernet frame (dst mac, src mac, ethertype, payload,
|
||||
* no checksum).
|
||||
*
|
||||
* @param buf buffer to read from
|
||||
* @param len nr of bytes to send
|
||||
*
|
||||
* @return nr of bytes sent, or <=0 on error
|
||||
*/
|
||||
int (*send)(dev_eth_t *dev, char* buf, int len);
|
||||
|
||||
/**
|
||||
* @brief Get a received ethernet frame
|
||||
*
|
||||
* Supposed to be called from dev_eth_rx_handler().
|
||||
*
|
||||
* Make sure buf can hold the maximum expected ethernet frame size.
|
||||
*
|
||||
* @param buf buffer to write to
|
||||
* @param len maximum nr. of bytes to read
|
||||
*
|
||||
* @return nr of bytes read or <=0 on error
|
||||
*/
|
||||
int (*recv)(dev_eth_t *dev, char* buf, int len);
|
||||
|
||||
/**
|
||||
* @brief get the device's MAC address
|
||||
*
|
||||
* @param buf location to write to. Make sure this is can take least 6 bytes
|
||||
*/
|
||||
void (*get_mac_addr)(dev_eth_t *dev, uint8_t *buf);
|
||||
|
||||
/**
|
||||
* @brief get the device's promiscous status
|
||||
*
|
||||
* Default is not promiscous.
|
||||
* Promiscous means, receive all ethernet frames.
|
||||
* Not promiscous means only receive broadcast, multicast or frames with
|
||||
* the device's MAC address as dst address.
|
||||
*
|
||||
* @return 1 for promiscous, 0 for not promiscous
|
||||
*/
|
||||
int (*get_promiscous)(dev_eth_t *dev);
|
||||
/**
|
||||
* @brief set the devices promiscous mode
|
||||
*
|
||||
* @param value 1 for promiscous, 0 for not promiscous
|
||||
* @return the new value (device might not support wanted mode)
|
||||
*/
|
||||
int (*set_promiscous)(dev_eth_t *dev, int value);
|
||||
/**
|
||||
* @brief the driver's initialization function
|
||||
*
|
||||
* @return <=0 on error, >0 on success
|
||||
*/
|
||||
int (*init)(dev_eth_t *dev);
|
||||
/**
|
||||
* @brief the driver's cleanup function (optional)
|
||||
*/
|
||||
void (*cleanup)(dev_eth_t *dev);
|
||||
/**
|
||||
* @brief a driver's user-space ISR handler
|
||||
*
|
||||
* This function will be called from a network stack's loop when being notified
|
||||
* by dev_eth_isr.
|
||||
*
|
||||
* It is supposed to call dev_eth_rx_handler for each available received packed,
|
||||
* and dev_eth_linkstate_handler whenever a link state change event occurs.
|
||||
*
|
||||
* See receive packet flow description for details.
|
||||
*/
|
||||
void (*isr)(dev_eth_t *dev);
|
||||
} eth_driver_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize a device given by dev (convenience function)
|
||||
*
|
||||
* The device given as parameter *must* be previously setup by the
|
||||
* drivers *_setup() function.
|
||||
*
|
||||
*/
|
||||
static inline int dev_eth_init(dev_eth_t *dev) {
|
||||
return dev->driver->init(dev);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Cleanup a device given by dev (convenience function)
|
||||
*
|
||||
* This function is to be called on reboot if the init function is not
|
||||
* idempotent.
|
||||
*
|
||||
*/
|
||||
static inline void dev_eth_cleanup(dev_eth_t *dev) {
|
||||
if (dev->driver->cleanup) {
|
||||
dev->driver->cleanup(dev);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief global dev_eth interrupt handling function.
|
||||
*
|
||||
* This function should be called from your device's ISR from whithin ISR context.
|
||||
* It is supposed to wake up a waiting user-space event loop.
|
||||
*/
|
||||
extern void dev_eth_isr(dev_eth_t *dev);
|
||||
|
||||
/**
|
||||
* @brief dev_eth event callback for packets that were received.
|
||||
*
|
||||
* This function should be called from whithin your driver's isr()
|
||||
* (as defined in eth_driver_t), once for every packet that was received.
|
||||
*
|
||||
* It needs to call dev->driver->recv() in order to get received packet
|
||||
* from the driver.
|
||||
*/
|
||||
extern void dev_eth_rx_handler(dev_eth_t *dev);
|
||||
|
||||
/**
|
||||
* @brief dev_eth ethernet link state handler
|
||||
*
|
||||
* This function should be called from whithin your driver's isr()
|
||||
* (as defined in eth_driver_t) for every layer 2 link state change.
|
||||
*
|
||||
* @param dev device that triggered the event
|
||||
* @param newstate 1 for "link established", 0 for "link down"
|
||||
*/
|
||||
extern void dev_eth_linkstate_handler(dev_eth_t *dev, int newstate);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/** @} */
|
||||
#endif /* DEV_ETH_H */
|
@ -1,3 +0,0 @@
|
||||
MODULE = gnrc_netdev_eth
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
@ -1,581 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Ludwig Ortmann <ludwig.ortmann@fu-berlin.de>,
|
||||
* Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
* Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup sys_net_link_layer
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
*
|
||||
* @author Ludwig Ortmann <ludwig.ortmann@fu-berlin.de>
|
||||
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "byteorder.h"
|
||||
#include "net/eui64.h"
|
||||
#include "net/ethernet.h"
|
||||
#include "net/ethertype.h"
|
||||
#include "net/ipv6/hdr.h"
|
||||
#include "net/gnrc/netdev.h"
|
||||
#include "net/gnrc/netif/hdr.h"
|
||||
#include "net/gnrc/pkt.h"
|
||||
#include "net/gnrc/pktbuf.h"
|
||||
#include "net/gnrc/netdev_eth.h"
|
||||
#include "net/dev_eth.h"
|
||||
#include "od.h"
|
||||
#include "thread.h"
|
||||
#include "utlist.h"
|
||||
|
||||
#define ENABLE_DEBUG (0)
|
||||
#include "debug.h"
|
||||
|
||||
gnrc_netdev_eth_t gnrc_netdev_eth;
|
||||
|
||||
static uint8_t send_buffer[ETHERNET_MAX_LEN];
|
||||
static uint8_t recv_buffer[ETHERNET_MAX_LEN];
|
||||
|
||||
#define _ISR_EVENT_RX (1U)
|
||||
|
||||
/* driver function definitions */
|
||||
static int _send_data(gnrc_netdev_t *netdev, gnrc_pktsnip_t *pkt);
|
||||
static int _add_event_callback(gnrc_netdev_t *dev, gnrc_netdev_event_cb_t cb);
|
||||
static int _rem_event_callback(gnrc_netdev_t *dev, gnrc_netdev_event_cb_t cb);
|
||||
static int _get(gnrc_netdev_t *dev, netopt_t opt, void *value, size_t max_len);
|
||||
static int _set(gnrc_netdev_t *dev, netopt_t opt, void *value, size_t value_len);
|
||||
static void _isr_event(gnrc_netdev_t *dev, uint32_t event_type);
|
||||
|
||||
/* netdev driver struct */
|
||||
const gnrc_netdev_driver_t gnrc_netdev_eth_driver = {
|
||||
_send_data,
|
||||
_add_event_callback,
|
||||
_rem_event_callback,
|
||||
_get,
|
||||
_set,
|
||||
_isr_event,
|
||||
};
|
||||
|
||||
/* These functions are not used */
|
||||
#if !(defined(__FreeBSD__) || defined(__MACH__))
|
||||
/* internal function definitions */
|
||||
static inline bool _is_addr_broadcast(uint8_t *addr)
|
||||
{
|
||||
return ((addr[0] == 0xff) && (addr[1] == 0xff) && (addr[2] == 0xff) &&
|
||||
(addr[3] == 0xff) && (addr[4] == 0xff) && (addr[5] == 0xff));
|
||||
}
|
||||
|
||||
static inline bool _is_addr_multicast(uint8_t *addr)
|
||||
{
|
||||
/* source: http://ieee802.org/secmail/pdfocSP2xXA6d.pdf */
|
||||
return (addr[0] & 0x01);
|
||||
}
|
||||
#endif /* !(defined(__FreeBSD__) || defined(__MACH__)) */
|
||||
|
||||
|
||||
/* build Ethernet packet from pkt */
|
||||
static int _marshall_ethernet(gnrc_netdev_eth_t *dev, uint8_t *buffer, gnrc_pktsnip_t *pkt);
|
||||
|
||||
/* build ISR handler for ISR events */
|
||||
void _trigger_isr_event(void);
|
||||
|
||||
static int _send_data(gnrc_netdev_t *netdev, gnrc_pktsnip_t *pkt)
|
||||
{
|
||||
int nsent, to_send;
|
||||
gnrc_netdev_eth_t *dev = (gnrc_netdev_eth_t *)netdev;
|
||||
|
||||
DEBUG("gnrc_netdev_eth: send data ");
|
||||
|
||||
if (pkt == NULL) {
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
if ((dev == NULL) || (netdev->driver != &gnrc_netdev_eth_driver)) {
|
||||
DEBUG("[wrong device descriptor]\n");
|
||||
gnrc_pktbuf_release(pkt);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
DEBUG("\n");
|
||||
|
||||
to_send = _marshall_ethernet(dev, send_buffer, pkt);
|
||||
gnrc_pktbuf_release(pkt);
|
||||
|
||||
if (to_send < 0) {
|
||||
errno = -to_send;
|
||||
DEBUG("marshall\n");
|
||||
return to_send;
|
||||
}
|
||||
|
||||
DEBUG("gnrc_netdev_eth: send %d bytes\n", to_send);
|
||||
#if defined(MODULE_OD) && ENABLE_DEBUG
|
||||
od_hex_dump(send_buffer, to_send, OD_WIDTH_DEFAULT);
|
||||
#endif
|
||||
|
||||
dev_eth_t *ethdev = dev->ethdev;
|
||||
if ((nsent = ethdev->driver->send(ethdev, (char*)send_buffer, to_send)) < 0) {
|
||||
DEBUG("write\n");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return nsent;
|
||||
}
|
||||
|
||||
static int _add_event_callback(gnrc_netdev_t *dev, gnrc_netdev_event_cb_t cb)
|
||||
{
|
||||
DEBUG("gnrc_netdev_eth: add event callback");
|
||||
|
||||
if ((dev == NULL) || (dev->driver != &gnrc_netdev_eth_driver)) {
|
||||
DEBUG(" [wrong device descriptor]\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (dev->event_cb != NULL) {
|
||||
DEBUG(" [no space left]\n");
|
||||
return -ENOBUFS;
|
||||
}
|
||||
|
||||
DEBUG("\n");
|
||||
dev->event_cb = cb;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _rem_event_callback(gnrc_netdev_t *dev, gnrc_netdev_event_cb_t cb)
|
||||
{
|
||||
DEBUG("gnrc_netdev_eth: remove event callback");
|
||||
|
||||
if ((dev == NULL) || (dev->driver != &gnrc_netdev_eth_driver)) {
|
||||
DEBUG(" [wrong device descriptor]\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (dev->event_cb != cb) {
|
||||
DEBUG(" [not found]\n");
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
DEBUG("\n");
|
||||
dev->event_cb = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* individual option getters to be called by _get() */
|
||||
static inline int _get_addr(gnrc_netdev_eth_t *netdev, uint8_t *value, size_t max_len)
|
||||
{
|
||||
if (max_len < ETHERNET_ADDR_LEN) {
|
||||
/* value buffer not big enough */
|
||||
return -EOVERFLOW;
|
||||
}
|
||||
|
||||
dev_eth_t *dev = netdev->ethdev;
|
||||
dev->driver->get_mac_addr(dev, value);
|
||||
|
||||
return ETHERNET_ADDR_LEN;
|
||||
}
|
||||
|
||||
static inline int _get_addr_len(uint16_t *value, size_t max_len)
|
||||
{
|
||||
if (max_len != sizeof(uint16_t)) {
|
||||
/* value buffer not big enough */
|
||||
return -EOVERFLOW;
|
||||
}
|
||||
|
||||
*value = ETHERNET_ADDR_LEN;
|
||||
|
||||
return sizeof(uint16_t);
|
||||
}
|
||||
|
||||
static inline int _get_iid(gnrc_netdev_eth_t *netdev, eui64_t *value, size_t max_len)
|
||||
{
|
||||
if (max_len < sizeof(eui64_t)) {
|
||||
/* value buffer not big enough */
|
||||
return -EOVERFLOW;
|
||||
}
|
||||
|
||||
dev_eth_t *dev = netdev->ethdev;
|
||||
uint8_t addr[ETHERNET_ADDR_LEN];
|
||||
dev->driver->get_mac_addr(dev, addr);
|
||||
ethernet_get_iid(value, addr);
|
||||
|
||||
return sizeof(eui64_t);
|
||||
}
|
||||
|
||||
static inline int _get_max_pkt_sz(uint16_t *value, size_t max_len)
|
||||
{
|
||||
if (max_len != sizeof(uint16_t)) {
|
||||
/* value buffer not big enough */
|
||||
return -EOVERFLOW;
|
||||
}
|
||||
|
||||
*value = ETHERNET_DATA_LEN;
|
||||
|
||||
return sizeof(uint16_t);
|
||||
}
|
||||
|
||||
static inline int _get_promiscousmode(gnrc_netdev_eth_t *netdev, netopt_enable_t *value,
|
||||
size_t max_len)
|
||||
{
|
||||
if (max_len != sizeof(netopt_enable_t)) {
|
||||
/* value buffer not big enough */
|
||||
return -EOVERFLOW;
|
||||
}
|
||||
|
||||
|
||||
dev_eth_t *dev = netdev->ethdev;
|
||||
*value = (netopt_enable_t)dev->driver->get_promiscous(dev);
|
||||
|
||||
return sizeof(netopt_enable_t);
|
||||
}
|
||||
|
||||
static int _get(gnrc_netdev_t *dev, netopt_t opt, void *value, size_t max_len)
|
||||
{
|
||||
DEBUG("gnrc_netdev_eth: get ");
|
||||
|
||||
if ((dev == NULL) || (dev->driver != &gnrc_netdev_eth_driver)) {
|
||||
DEBUG("[wrong device descriptor]\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
switch (opt) {
|
||||
case NETOPT_ADDRESS:
|
||||
DEBUG("address\n");
|
||||
return _get_addr((gnrc_netdev_eth_t *)dev, value, max_len);
|
||||
|
||||
case NETOPT_ADDR_LEN:
|
||||
DEBUG("address length\n");
|
||||
return _get_addr_len(value, max_len);
|
||||
|
||||
case NETOPT_IPV6_IID:
|
||||
DEBUG("IPv6 IID\n");
|
||||
return _get_iid((gnrc_netdev_eth_t *)dev, value, max_len);
|
||||
|
||||
case NETOPT_MAX_PACKET_SIZE:
|
||||
DEBUG("maximum packet size\n");
|
||||
return _get_max_pkt_sz(value, max_len);
|
||||
|
||||
case NETOPT_PROMISCUOUSMODE:
|
||||
DEBUG("promiscous mode\n");
|
||||
return _get_promiscousmode((gnrc_netdev_eth_t *)dev, value, max_len);
|
||||
|
||||
case NETOPT_IS_WIRED:
|
||||
DEBUG("is wired\n");
|
||||
return 1;
|
||||
|
||||
default:
|
||||
DEBUG("[not supported: %d]\n", opt);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
}
|
||||
|
||||
/* individual option getters to be called by _get() */
|
||||
static inline int _set_promiscousmode(gnrc_netdev_eth_t *netdev, netopt_enable_t *value,
|
||||
size_t value_len)
|
||||
{
|
||||
if (value_len != sizeof(netopt_enable_t)) {
|
||||
/* value buffer not big enough */
|
||||
return -EOVERFLOW;
|
||||
}
|
||||
|
||||
dev_eth_t *dev = netdev->ethdev;
|
||||
|
||||
dev->driver->set_promiscous(dev, (uint8_t)*value);
|
||||
|
||||
return sizeof(netopt_enable_t);
|
||||
}
|
||||
|
||||
static int _set(gnrc_netdev_t *dev, netopt_t opt, void *value, size_t value_len)
|
||||
{
|
||||
DEBUG("gnrc_netdev_eth: set ");
|
||||
|
||||
if ((dev == NULL) || (dev->driver != &gnrc_netdev_eth_driver)) {
|
||||
DEBUG("[wrong device descriptor]\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
switch (opt) {
|
||||
case NETOPT_PROMISCUOUSMODE:
|
||||
DEBUG("promiscous mode\n");
|
||||
return _set_promiscousmode((gnrc_netdev_eth_t *)dev, value, value_len);
|
||||
|
||||
default:
|
||||
DEBUG("[not supported: %d]\n", opt);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
}
|
||||
|
||||
/* individual event handlers called by _isr_event() */
|
||||
static void _rx_event(gnrc_netdev_eth_t *dev);
|
||||
|
||||
static void _isr_event(gnrc_netdev_t *dev, uint32_t event_type)
|
||||
{
|
||||
DEBUG("gnrc_netdev_eth: ISR event ");
|
||||
|
||||
if ((dev == NULL) || (dev->driver != &gnrc_netdev_eth_driver)) {
|
||||
return;
|
||||
}
|
||||
|
||||
gnrc_netdev_eth_t *netdev = (gnrc_netdev_eth_t*)dev;
|
||||
|
||||
switch (event_type) {
|
||||
case _ISR_EVENT_RX:
|
||||
|
||||
DEBUG("[ISR]\n");
|
||||
|
||||
#ifdef NETDEV_ETH_DELAY_SEND
|
||||
DEBUG("netdev_eth: delaying send...\n");
|
||||
volatile int i = NETDEV_ETH_DELAY_SEND;
|
||||
while(i--);
|
||||
DEBUG("netdev_eth: delay done.\n");
|
||||
#endif
|
||||
|
||||
dev_eth_t *ethdev = netdev->ethdev;
|
||||