mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-27 07:21:18 +01:00
netdev_tap: make 'wired' property configurable
`netdev_tap` is a virtual interface, make it possible to simulate both a wired and a wireless interface.
This commit is contained in:
parent
039e9937a4
commit
f61c12e008
@ -25,6 +25,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "net/netdev.h"
|
||||
|
||||
#include "net/ethernet/hdr.h"
|
||||
@ -43,7 +44,8 @@ typedef struct netdev_tap {
|
||||
char tap_name[IFNAMSIZ]; /**< host dev file name */
|
||||
int tap_fd; /**< host file descriptor for the TAP */
|
||||
uint8_t addr[ETHERNET_ADDR_LEN]; /**< The MAC address of the TAP */
|
||||
uint8_t promiscuous; /**< Flag for promiscuous mode */
|
||||
bool promiscuous; /**< Flag for promiscuous mode */
|
||||
bool wired; /**< Flag for wired mode */
|
||||
} netdev_tap_t;
|
||||
|
||||
/**
|
||||
@ -52,6 +54,8 @@ typedef struct netdev_tap {
|
||||
typedef struct {
|
||||
char **tap_name; /**< Name of the host system's tap
|
||||
interface to bind to. */
|
||||
bool wired; /**< Interface should behave like a
|
||||
wired interface. */
|
||||
} netdev_tap_params_t;
|
||||
|
||||
/**
|
||||
|
||||
@ -94,6 +94,12 @@ static inline int _set_promiscuous(netdev_t *netdev, int value)
|
||||
return value;
|
||||
}
|
||||
|
||||
static inline int _get_wired(netdev_t *netdev)
|
||||
{
|
||||
netdev_tap_t *dev = container_of(netdev, netdev_tap_t, netdev);
|
||||
return dev->wired;
|
||||
}
|
||||
|
||||
static inline void _isr(netdev_t *netdev)
|
||||
{
|
||||
if (netdev->event_callback) {
|
||||
@ -124,6 +130,16 @@ static int _get(netdev_t *dev, netopt_t opt, void *value, size_t max_len)
|
||||
*((bool*)value) = (bool)_get_promiscuous(dev);
|
||||
res = sizeof(bool);
|
||||
break;
|
||||
case NETOPT_IS_WIRED:
|
||||
if (!_get_wired(dev)) {
|
||||
res = -ENOTSUP;
|
||||
} else {
|
||||
if (value) {
|
||||
*((bool*)value) = true;
|
||||
}
|
||||
res = sizeof(bool);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
res = netdev_eth_get(dev, opt, value, max_len);
|
||||
break;
|
||||
@ -294,6 +310,7 @@ void netdev_tap_setup(netdev_tap_t *dev, const netdev_tap_params_t *params, int
|
||||
dev->netdev.driver = &netdev_driver_tap;
|
||||
strncpy(dev->tap_name, *(params->tap_name), IFNAMSIZ - 1);
|
||||
dev->tap_name[IFNAMSIZ - 1] = '\0';
|
||||
dev->wired = params->wired;
|
||||
netdev_register(&dev->netdev, NETDEV_TAP, index);
|
||||
}
|
||||
|
||||
|
||||
@ -655,6 +655,7 @@ __attribute__((constructor)) static void startup(int argc, char **argv, char **e
|
||||
#ifdef MODULE_NETDEV_TAP
|
||||
for (int i = 0; i < NETDEV_TAP_MAX; i++) {
|
||||
netdev_tap_params[i].tap_name = &argv[optind + i];
|
||||
netdev_tap_params[i].wired = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user