2015-11-30 14:01:23 +01:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2018-06-01 12:09:01 +02:00
|
|
|
* @ingroup drivers_netdev_eth
|
2015-11-30 14:01:23 +01:00
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
2017-02-15 13:07:34 +01:00
|
|
|
* @brief Common code for netdev ethernet drivers
|
2015-11-30 14:01:23 +01:00
|
|
|
*
|
|
|
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2017-02-15 13:07:34 +01:00
|
|
|
#include "net/netdev.h"
|
2018-12-06 19:02:22 +01:00
|
|
|
#include "net/eui48.h"
|
2015-11-30 14:01:23 +01:00
|
|
|
#include "net/eui64.h"
|
|
|
|
#include "net/ethernet.h"
|
|
|
|
|
2020-10-22 11:34:31 +02:00
|
|
|
#define ENABLE_DEBUG 0
|
2015-11-30 14:01:23 +01:00
|
|
|
#include "debug.h"
|
|
|
|
|
2017-02-15 13:07:34 +01:00
|
|
|
int netdev_eth_get(netdev_t *dev, netopt_t opt, void *value, size_t max_len)
|
2015-11-30 14:01:23 +01:00
|
|
|
{
|
|
|
|
int res = 0;
|
|
|
|
|
2020-06-25 10:55:49 +02:00
|
|
|
#ifndef MODULE_L2FILTER
|
|
|
|
(void)dev;
|
|
|
|
#endif
|
|
|
|
(void)max_len; /* only used in assert() */
|
2015-11-30 14:01:23 +01:00
|
|
|
switch (opt) {
|
|
|
|
case NETOPT_DEVICE_TYPE:
|
|
|
|
{
|
|
|
|
uint16_t *tgt = (uint16_t *)value;
|
2017-02-15 13:07:34 +01:00
|
|
|
*tgt = NETDEV_TYPE_ETHERNET;
|
2015-11-30 14:01:23 +01:00
|
|
|
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;
|
|
|
|
}
|
2019-02-04 12:45:00 +01:00
|
|
|
case NETOPT_MAX_PDU_SIZE:
|
2015-11-30 14:01:23 +01:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2017-05-16 16:29:28 +02:00
|
|
|
#ifdef MODULE_L2FILTER
|
|
|
|
case NETOPT_L2FILTER:
|
|
|
|
{
|
|
|
|
assert(max_len >= sizeof(l2filter_t **));
|
|
|
|
*((l2filter_t **)value) = dev->filter;
|
|
|
|
res = sizeof(l2filter_t **);
|
|
|
|
break;
|
|
|
|
}
|
2016-02-11 23:06:07 +01:00
|
|
|
#endif
|
2015-11-30 14:01:23 +01:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
res = -ENOTSUP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2017-08-25 07:34:03 +02:00
|
|
|
int netdev_eth_set(netdev_t *dev, netopt_t opt, const void *value, size_t value_len)
|
2015-11-30 14:01:23 +01:00
|
|
|
{
|
2017-05-16 16:29:28 +02:00
|
|
|
#ifndef MODULE_L2FILTER
|
2015-11-30 14:01:23 +01:00
|
|
|
(void)dev;
|
2017-05-16 16:29:28 +02:00
|
|
|
#endif
|
2015-11-30 14:01:23 +01:00
|
|
|
(void)value;
|
|
|
|
(void)value_len;
|
|
|
|
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
switch (opt) {
|
2017-05-16 16:29:28 +02:00
|
|
|
|
|
|
|
#ifdef MODULE_L2FILTER
|
|
|
|
case NETOPT_L2FILTER:
|
|
|
|
res = l2filter_add(dev->filter, value, value_len);
|
|
|
|
break;
|
|
|
|
case NETOPT_L2FILTER_RM:
|
|
|
|
res = l2filter_rm(dev->filter, value, value_len);
|
|
|
|
break;
|
|
|
|
#endif
|
2015-11-30 14:01:23 +01:00
|
|
|
default:
|
2017-05-16 16:29:28 +02:00
|
|
|
res = -ENOTSUP;
|
|
|
|
break;
|
2015-11-30 14:01:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|