mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
examples/gnrc_border_router: add CDC-ECM uplink
Optionally executes pyterm from CDC-ECM start_network.sh The shell script exits and cleans up instantly unless there is a blocking program running at the end. Users can supply a serial port to display in pyterm, or alternatively just wait if it is a "headless" deployment.
This commit is contained in:
parent
fe7700c7de
commit
2c3987def0
104
dist/tools/usb-cdc-ecm/start_network.sh
vendored
Executable file
104
dist/tools/usb-cdc-ecm/start_network.sh
vendored
Executable file
@ -0,0 +1,104 @@
|
||||
#!/bin/sh
|
||||
|
||||
USB_CDC_ECM_DIR="$(dirname $(readlink -f $0))"
|
||||
|
||||
INTERFACE_CHECK_COUNTER=5 # 5 attempts to find usb interface
|
||||
|
||||
find_interface() {
|
||||
INTERFACE=$(ls -A /sys/bus/usb/drivers/cdc_ether/*/net/ 2>/dev/null)
|
||||
INTERFACE_CHECK=$(echo -n ${INTERFACE} | head -c1 | wc -c)
|
||||
if [ ${INTERFACE_CHECK} -eq 0 -a ${INTERFACE_CHECK_COUNTER} != 0 ]; then
|
||||
# We want to have multiple opportunities to find the USB interface
|
||||
# as sometimes it can take a few seconds for it to enumerate after
|
||||
# the device has been flashed.
|
||||
sleep 1
|
||||
((INTERFACE_CHECK_COUNTER=INTERFACE_CHECK_COUNTER-1))
|
||||
find_interface
|
||||
fi
|
||||
INTERFACE=${INTERFACE%/}
|
||||
}
|
||||
|
||||
echo "Waiting for network interface."
|
||||
find_interface
|
||||
|
||||
if [ ${INTERFACE_CHECK} -eq 0 ]; then
|
||||
echo "Unable to find network interface"
|
||||
exit 1
|
||||
else
|
||||
echo "Found interface: ${INTERFACE}"
|
||||
fi
|
||||
|
||||
setup_interface() {
|
||||
sysctl -w net.ipv6.conf.${INTERFACE}.forwarding=1
|
||||
sysctl -w net.ipv6.conf.${INTERFACE}.accept_ra=0
|
||||
ip link set ${INTERFACE} up
|
||||
ip a a fe80::1/64 dev ${INTERFACE}
|
||||
ip a a fd00:dead:beef::1/128 dev lo
|
||||
ip route add ${PREFIX} via fe80::2 dev ${INTERFACE}
|
||||
}
|
||||
|
||||
cleanup_interface() {
|
||||
ip a d fe80::1/64 dev ${INTERFACE}
|
||||
ip a d fd00:dead:beef::1/128 dev lo
|
||||
ip route del ${PREFIX} via fe80::2 dev ${INTERFACE}
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
echo "Cleaning up..."
|
||||
cleanup_interface
|
||||
if [ -n "${UHCPD_PID}" ]; then
|
||||
kill ${UHCPD_PID}
|
||||
fi
|
||||
if [ -n "${DHCPD_PIDFILE}" ]; then
|
||||
kill "$(cat ${DHCPD_PIDFILE})"
|
||||
rm "${DHCPD_PIDFILE}"
|
||||
fi
|
||||
trap "" INT QUIT TERM EXIT
|
||||
}
|
||||
|
||||
start_uhcpd() {
|
||||
${UHCPD} ${INTERFACE} ${PREFIX} > /dev/null &
|
||||
UHCPD_PID=$!
|
||||
}
|
||||
|
||||
start_dhcpd() {
|
||||
DHCPD_PIDFILE=$(mktemp)
|
||||
${DHCPD} -d -p ${DHCPD_PIDFILE} ${INTERFACE} ${PREFIX} 2> /dev/null
|
||||
}
|
||||
|
||||
if [ "$1" = "-d" ] || [ "$1" = "--use-dhcpv6" ]; then
|
||||
USE_DHCPV6=1
|
||||
shift 1
|
||||
else
|
||||
USE_DHCPV6=0
|
||||
fi
|
||||
|
||||
PREFIX=$1
|
||||
[ -z "${PREFIX}" ] && {
|
||||
echo "usage: $0 [-d|--use-dhcpv6] <prefix> [<serial-port>]"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ ! -z "$2" ]; then
|
||||
PORT=$2
|
||||
fi
|
||||
|
||||
trap "cleanup" INT QUIT TERM EXIT
|
||||
|
||||
setup_interface
|
||||
|
||||
if [ ${USE_DHCPV6} -eq 1 ]; then
|
||||
DHCPD="$(readlink -f "${USB_CDC_ECM_DIR}/../dhcpv6-pd_ia/")/dhcpv6-pd_ia.py"
|
||||
start_dhcpd
|
||||
else
|
||||
UHCPD="$(readlink -f "${USB_CDC_ECM_DIR}/../uhcpd/bin")/uhcpd"
|
||||
start_uhcpd
|
||||
fi
|
||||
|
||||
if [ -z "${PORT}" ]; then
|
||||
echo "Network enabled over CDC-ECM"
|
||||
read -n 1 -s -p "Press any key to stop"
|
||||
echo
|
||||
else
|
||||
${USB_CDC_ECM_DIR}/../pyterm/pyterm -p "${PORT}"
|
||||
fi
|
@ -11,8 +11,8 @@ RIOTBASE ?= $(CURDIR)/../..
|
||||
UPLINK ?= ethos
|
||||
|
||||
# Check if the selected Uplink is valid
|
||||
ifeq (,$(filter ethos slip wifi,$(UPLINK)))
|
||||
$(error Supported uplinks are `ethos`, `slip` and `wifi`)
|
||||
ifeq (,$(filter ethos slip cdc-ecm wifi,$(UPLINK)))
|
||||
$(error Supported uplinks are `ethos`, `slip`, `cdc-ecm` and `wifi`)
|
||||
endif
|
||||
|
||||
# Set the SSID and password of your WiFi network here
|
||||
@ -89,6 +89,8 @@ ifeq (,$(filter native,$(BOARD)))
|
||||
# ethos baudrate can be configured from make command
|
||||
ETHOS_BAUDRATE ?= 115200
|
||||
include $(CURDIR)/Makefile.ethos.conf
|
||||
else ifeq (cdc-ecm,$(UPLINK))
|
||||
include $(CURDIR)/Makefile.cdc-ecm.conf
|
||||
else ifeq (wifi,$(UPLINK))
|
||||
# SSID and Password need to be configured
|
||||
include $(CURDIR)/Makefile.wifi.conf
|
||||
|
12
examples/gnrc_border_router/Makefile.cdc-ecm.conf
Normal file
12
examples/gnrc_border_router/Makefile.cdc-ecm.conf
Normal file
@ -0,0 +1,12 @@
|
||||
# USB Modules
|
||||
USEMODULE += auto_init_usbus
|
||||
USEMODULE += usbus_cdc_ecm
|
||||
|
||||
ifeq (1,$(USE_DHCPV6))
|
||||
FLAGS_EXTRAS += --use-dhcpv6
|
||||
endif
|
||||
|
||||
# Configure terminal parameters for UHCP
|
||||
TERMDEPS += host-tools
|
||||
TERMPROG ?= sudo sh $(RIOTTOOLS)/usb-cdc-ecm/start_network.sh
|
||||
TERMFLAGS ?= $(FLAGS_EXTRAS) $(IPV6_PREFIX) $(PORT)
|
Loading…
Reference in New Issue
Block a user