mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 10:12:45 +01:00
socket_zep: allow to specify MAC address of ZEP device
Add a command-line parameter for setting the EUI-64 of a ZEP device. This allows a native node to use a persistent ZEP address across reboots.
This commit is contained in:
parent
61bce4dc9c
commit
17199dbb1c
42
boards/native/include/eui_provider_params.h
Normal file
42
boards/native/include/eui_provider_params.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2020 ML!PA Consulting GmbH
|
||||
*
|
||||
* 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 boards_native
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief EUI providers found on the board
|
||||
*
|
||||
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com>
|
||||
*/
|
||||
#ifndef EUI_PROVIDER_PARAMS_H
|
||||
#define EUI_PROVIDER_PARAMS_H
|
||||
|
||||
#include "native_cli_eui_provider.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @name EUI sources on the board
|
||||
* EUI-64 can be provided with the -Z command line argument
|
||||
* @{
|
||||
*/
|
||||
#define EUI64_PROVIDER_FUNC native_cli_get_eui64
|
||||
#define EUI64_PROVIDER_TYPE NETDEV_ANY
|
||||
#define EUI64_PROVIDER_INDEX NETDEV_INDEX_ANY
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* EUI_PROVIDER_PARAMS_H */
|
||||
/** @} */
|
@ -30,6 +30,10 @@ ifneq (,$(filter backtrace,$(USEMODULE)))
|
||||
DIRS += backtrace
|
||||
endif
|
||||
|
||||
ifneq (,$(filter native_cli_eui_provider,$(USEMODULE)))
|
||||
DIRS += cli_eui_provider
|
||||
endif
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
|
||||
INCLUDES = $(NATIVEINCLUDES)
|
||||
|
@ -21,6 +21,14 @@ ifneq (,$(filter periph_rtc,$(USEMODULE)))
|
||||
USEMODULE += xtimer
|
||||
endif
|
||||
|
||||
ifneq (,$(filter eui_provider,$(USEMODULE)))
|
||||
USEMODULE += native_cli_eui_provider
|
||||
endif
|
||||
|
||||
ifneq (,$(filter native_cli_eui_provider,$(USEMODULE)))
|
||||
USEMODULE += l2util
|
||||
endif
|
||||
|
||||
USEMODULE += periph
|
||||
|
||||
# UART is needed by startup.c
|
||||
|
3
cpu/native/cli_eui_provider/Makefile
Normal file
3
cpu/native/cli_eui_provider/Makefile
Normal file
@ -0,0 +1,3 @@
|
||||
MODULE := native_cli_eui_provider
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
65
cpu/native/cli_eui_provider/eui_provider.c
Normal file
65
cpu/native/cli_eui_provider/eui_provider.c
Normal file
@ -0,0 +1,65 @@
|
||||
/**
|
||||
* Native CPU EUI provider
|
||||
*
|
||||
* Copyright (C) 2020 Benjamin Valentin
|
||||
*
|
||||
* 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 cpu_native
|
||||
* @{
|
||||
* @file
|
||||
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "net/l2util.h"
|
||||
#include "native_cli_eui_provider.h"
|
||||
#include "list.h"
|
||||
|
||||
#include "native_internal.h"
|
||||
|
||||
/* list of user supplied EUI-64s */
|
||||
typedef struct {
|
||||
list_node_t node;
|
||||
eui64_t addr;
|
||||
} native_eui64_list_t;
|
||||
|
||||
static list_node_t head;
|
||||
|
||||
/* parse EUI-64 from command line */
|
||||
void native_cli_add_eui64(const char *s)
|
||||
{
|
||||
_native_syscall_enter();
|
||||
native_eui64_list_t *e = real_malloc(sizeof(native_eui64_list_t));
|
||||
_native_syscall_leave();
|
||||
|
||||
size_t res = l2util_addr_from_str(s, e->addr.uint8);
|
||||
assert(res <= sizeof(eui64_t));
|
||||
|
||||
/* if the provided address exceeds eui64_t, l2util_addr_from_str()
|
||||
* *will* corrupt memory. */
|
||||
if (res > sizeof(eui64_t)) {
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
list_add(&head, &e->node);
|
||||
}
|
||||
|
||||
/* callback for EUI provider */
|
||||
int native_cli_get_eui64(uint8_t index, eui64_t *addr)
|
||||
{
|
||||
uint8_t cnt = 0;
|
||||
for (list_node_t *e = head.next; e != NULL; e = e->next) {
|
||||
if (cnt++ == index) {
|
||||
*addr = container_of(e, native_eui64_list_t, node)->addr;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
50
cpu/native/include/native_cli_eui_provider.h
Normal file
50
cpu/native/include/native_cli_eui_provider.h
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Benjamin Valentin
|
||||
*
|
||||
* 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 cpu_native
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Command-line EUI provider for native
|
||||
*
|
||||
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com>
|
||||
*/
|
||||
|
||||
#ifndef NATIVE_CLI_EUI_PROVIDER_H
|
||||
#define NATIVE_CLI_EUI_PROVIDER_H
|
||||
|
||||
#include "net/eui64.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @name parse a string as an EUI-64 and add it to the list of EUI-64s
|
||||
*
|
||||
* @param s[in] EUI-64 as hexadecimal string representation
|
||||
*/
|
||||
void native_cli_add_eui64(const char *s);
|
||||
|
||||
/**
|
||||
* @name Get a command-line provided EUI-64
|
||||
*
|
||||
* @param index index of ZEP device
|
||||
* @param addr[out] user supplied EUI-64
|
||||
*
|
||||
* @return 0 on success, negatvie if no more EUIs are available.
|
||||
*/
|
||||
int native_cli_get_eui64(uint8_t index, eui64_t *addr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NATIVE_CLI_EUI_PROVIDER_H */
|
||||
/** @} */
|
@ -181,8 +181,6 @@ int register_interrupt(int sig, _native_callback_t handler);
|
||||
*/
|
||||
int unregister_interrupt(int sig);
|
||||
|
||||
//#include <sys/param.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -84,6 +84,9 @@ netdev_tap_params_t netdev_tap_params[NETDEV_TAP_MAX];
|
||||
#ifdef MODULE_PERIPH_GPIO_LINUX
|
||||
#include "gpiodev_linux.h"
|
||||
#endif
|
||||
#ifdef MODULE_NATIVE_CLI_EUI_PROVIDER
|
||||
#include "native_cli_eui_provider.h"
|
||||
#endif
|
||||
#ifdef MODULE_SOCKET_ZEP
|
||||
#include "socket_zep_params.h"
|
||||
|
||||
@ -107,6 +110,9 @@ static const char short_opts[] = ":hi:s:deEoc:"
|
||||
#ifdef MODULE_SOCKET_ZEP
|
||||
"z:"
|
||||
#endif
|
||||
#ifdef MODULE_NATIVE_CLI_EUI_PROVIDER
|
||||
"U:"
|
||||
#endif
|
||||
#ifdef MODULE_PERIPH_SPIDEV_LINUX
|
||||
"p:"
|
||||
#endif
|
||||
@ -133,6 +139,9 @@ static const struct option long_opts[] = {
|
||||
#ifdef MODULE_SOCKET_ZEP
|
||||
{ "zep", required_argument, NULL, 'z' },
|
||||
#endif
|
||||
#ifdef MODULE_NATIVE_CLI_EUI_PROVIDER
|
||||
{ "eui64", required_argument, NULL, 'U' },
|
||||
#endif
|
||||
#ifdef MODULE_PERIPH_SPIDEV_LINUX
|
||||
{ "spi", required_argument, NULL, 'p' },
|
||||
#endif
|
||||
@ -281,6 +290,9 @@ void usage_exit(int status)
|
||||
real_printf(" -z <laddr>:<lport>,<raddr>:<rport>");
|
||||
}
|
||||
#endif
|
||||
#ifdef MODULE_NATIVE_CLI_EUI_PROVIDER
|
||||
real_printf(" [--eui64 <eui64> …]");
|
||||
#endif
|
||||
#ifdef MODULE_PERIPH_SPIDEV_LINUX
|
||||
real_printf(" [-p <b>:<d>:<spidev>]");
|
||||
#endif
|
||||
@ -323,6 +335,11 @@ void usage_exit(int status)
|
||||
" The ZEP interface connects to the remote address and may listen\n"
|
||||
" on a local address.\n"
|
||||
" Required to be provided SOCKET_ZEP_MAX times\n"
|
||||
#endif
|
||||
#ifdef MODULE_NATIVE_CLI_EUI_PROVIDER
|
||||
" -U <eui64>, --eui64=<eui64>\n"
|
||||
" provide a ZEP interface with EUI-64 (MAC address)\n"
|
||||
" This argument can be provided multiple times\n"
|
||||
#endif
|
||||
);
|
||||
#ifdef MODULE_MTD_NATIVE
|
||||
@ -414,6 +431,7 @@ static void _zep_params_setup(char *zep_str, int zep)
|
||||
&socket_zep_params[zep].remote_port);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/** @brief Initialization function pointer type */
|
||||
@ -531,6 +549,11 @@ __attribute__((constructor)) static void startup(int argc, char **argv, char **e
|
||||
_zep_params_setup(optarg, zeps++);
|
||||
break;
|
||||
#endif
|
||||
#ifdef MODULE_NATIVE_CLI_EUI_PROVIDER
|
||||
case 'U':
|
||||
native_cli_add_eui64(optarg);
|
||||
break;
|
||||
#endif
|
||||
#ifdef MODULE_PERIPH_SPIDEV_LINUX
|
||||
case 'p': {
|
||||
long bus = strtol(optarg, &optarg, 10);
|
||||
|
Loading…
Reference in New Issue
Block a user