1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/drivers/netdev_eth/netdev_eth.c
Martine Lenders 29842bb5e4 netdev2: rename to netdev and remove gnrc_netdev
With some minor hand-edits I used the following chain of commands:

```sh
git rm sys/include/net/gnrc/netdev.h
git grep --name-only -i netdev2 | \
        xargs sed -i -e 's/^\(NETDEV\)2\(.*\)\( [("]\)/\1\2 \3/g' \
                     -e 's/\(netdev\)2\(.*\)\( \/\*\*<\)/\1\2 \3/I' \
                     -e 's/\(netdev\)2/\1/gI'
git add -p
git commit --amend
git ls-tree --full-tree -r HEAD --name-only | \
        grep "netdev2" | xargs -I'{}' dirname '{}' | uniq | \
        grep "netdev2" | while read dir; do
                new_dir="$(echo "$dir" | sed "s/netdev2/netdev/g")"
                git mv -f "$dir" "$new_dir"
        done
git commit --amend
git ls-tree --full-tree -r HEAD --name-only | \
        grep "netdev2" | while read file; do
                new_file="$(echo "$file" | sed "s/netdev2/netdev/g")"
                git mv -f "$file" "$new_file"
        done
git commit --amend
git grep --name-only "\<drivers_netdev_netdev\>" | \
        xargs sed -i "s/\<drivers_netdev_netdev\>/drivers_netdev_api/g"
git add -p
git commit --amend
```
2017-03-15 09:31:20 +01:00

116 lines
2.5 KiB
C

/*
* 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 driver_netdev_eth
* @{
*
* @file
* @brief Common code for netdev ethernet drivers
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
*
* @}
*/
#include <assert.h>
#include <errno.h>
#include "net/netdev.h"
#include "net/eui64.h"
#include "net/ethernet.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
static int _get_iid(netdev_t *netdev, eui64_t *value, size_t max_len)
{
if (max_len < sizeof(eui64_t)) {
return -EOVERFLOW;
}
uint8_t addr[ETHERNET_ADDR_LEN];
netdev->driver->get(netdev, NETOPT_ADDRESS, addr, ETHERNET_ADDR_LEN);
ethernet_get_iid(value, addr);
return sizeof(eui64_t);
}
int netdev_eth_get(netdev_t *dev, netopt_t opt, void *value, size_t max_len)
{
int res = 0;
switch (opt) {
case NETOPT_DEVICE_TYPE:
{
uint16_t *tgt = (uint16_t *)value;
*tgt = NETDEV_TYPE_ETHERNET;
res = 2;
break;
}
case NETOPT_ADDR_LEN:
case NETOPT_SRC_LEN:
{
assert(max_len == 2);
uint16_t *tgt = (uint16_t*)value;
*tgt=6;
res = sizeof(uint16_t);
break;
}
case NETOPT_MAX_PACKET_SIZE:
{
assert(max_len >= 2);
uint16_t *val = (uint16_t*) value;
*val = ETHERNET_DATA_LEN;
res = sizeof(uint16_t);
break;
}
case NETOPT_IS_WIRED:
{
res = 1;
break;
}
case NETOPT_IPV6_IID:
{
return _get_iid(dev, value, max_len);
}
#ifdef MODULE_NETSTATS_L2
case NETOPT_STATS:
{
assert(max_len >= sizeof(uintptr_t));
*((netstats_t**)value) = &dev->stats;
res = sizeof(uintptr_t);
break;
}
#endif
default:
{
res = -ENOTSUP;
break;
}
}
return res;
}
int netdev_eth_set(netdev_t *dev, netopt_t opt, void *value, size_t value_len)
{
(void)dev;
(void)value;
(void)value_len;
int res = 0;
switch (opt) {
default:
return -ENOTSUP;
}
return res;
}