mirror of
https://github.com/apache/nuttx.git
synced 2026-06-07 09:18:00 +08:00
Ethernet Over USB net helper script and docs
- for CDC ECM driver Squashed commit of the following: commit aa9a715498e15ad46d43318a663d296f38160cf8 Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 16:42:52 2020 -0800 code formatting; removed ping commit 56520b7f7e2b7f03697eacc2f2b5450b0f7af676 Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 16:42:32 2020 -0800 add description of netusb.sh helper script commit afee3d33b1e66138afb7e9713d86b765ceab55b0 Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 16:41:40 2020 -0800 readme formatting commit 772e36021f4aee2ba1df408ad29d8b9adedeed9f Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 11:38:50 2020 -0800 updated readme, removed redundant configs commit 082785178aa6e0d1578034b4b163785fdcb61f22 Author: Adam Feuer <adam@starcat.io> Date: Sat Feb 22 17:40:05 2020 -0800 README, defconfig, and helper script improvements
This commit is contained in:
@@ -787,6 +787,25 @@ mkdeps.c, cnvwindeps.c, mkwindeps.sh, and mknulldeps.sh
|
||||
eventually be solvable but for now continue to use mkwindeps.sh in
|
||||
that mixed environment.
|
||||
|
||||
|
||||
netusb.sh
|
||||
---------
|
||||
|
||||
Helper script used to set up the CDC ECM Ethernet Over USB driver,
|
||||
host routes, and IP Tables rules to support networking with a NuttX
|
||||
system that has a CDC ECM Ethernet Over USB driver configured. Only
|
||||
supported on Linux.
|
||||
|
||||
General usage:
|
||||
|
||||
$ ./tools/netusb.sh
|
||||
Usage: tools/netusb.sh <main-interface> <usb-net-interface> <on|off>
|
||||
|
||||
This has been tested on the SAMA5D3-Xplained board; see
|
||||
`boards/arm/sama5/sama5d3-xplained/README.txt` for more information on how
|
||||
to configure the CDC ECM driver for that board.
|
||||
|
||||
|
||||
README.txt
|
||||
----------
|
||||
|
||||
|
||||
Executable
+71
@@ -0,0 +1,71 @@
|
||||
#!/bin/bash
|
||||
|
||||
#****************************************************************************
|
||||
# tools/simhostroute.sh
|
||||
#
|
||||
# Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
# contributor license agreements. See the NOTICE file distributed with
|
||||
# this work for additional information regarding copyright ownership. The
|
||||
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance with the
|
||||
# License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
#****************************************************************************
|
||||
|
||||
# USB Ethernet Gadget interface helper script - sets up nuttx to access
|
||||
# the internet via a host route and IP Tables.
|
||||
|
||||
IP_NET="10.0.0.0/24"
|
||||
IP_NETMASK="255.255.255.0"
|
||||
IP_BROADCAST="10.0.0.255"
|
||||
IP_HOST="10.0.0.1"
|
||||
IP_NUTTX="10.0.0.2"
|
||||
|
||||
if [ $# != 3 ]; then
|
||||
echo "Usage: $0 <main-interface> <usb-net-interface> <on|off>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
IF_HOST=$1
|
||||
IF_USB=$2
|
||||
STATUS=$3
|
||||
|
||||
net_off() {
|
||||
ip route delete $IP_NET
|
||||
ip route delete $IP_NUTTX/32
|
||||
|
||||
# delete nat rules to clean up
|
||||
iptables -t nat -D POSTROUTING -o $IF_HOST -j MASQUERADE
|
||||
iptables -D FORWARD -i $IF_HOST -o $IF_USB -m state --state RELATED,ESTABLISHED -j ACCEPT
|
||||
iptables -D FORWARD -i $IF_USB -o $IF_HOST -j ACCEPT
|
||||
|
||||
ip route show
|
||||
ifconfig $IF_USB down
|
||||
}
|
||||
|
||||
if [ "$STATUS" == "on" ]; then
|
||||
net_off
|
||||
ifconfig $IF_USB up
|
||||
ifconfig -a
|
||||
ifconfig $IF_USB add $IP_HOST
|
||||
ifconfig $IF_USB:0 broadcast $IP_BROADCAST netmask $IP_NETMASK
|
||||
ip route add $IP_NET dev $IF_USB src $IP_HOST
|
||||
ip route add $IP_NUTTX/32 dev $IF_USB src $IP_HOST
|
||||
|
||||
# nat to allow NuttX to access the internet
|
||||
iptables -t nat -A POSTROUTING -o $IF_HOST -j MASQUERADE
|
||||
iptables -A FORWARD -i $IF_HOST -o $IF_USB -m state --state RELATED,ESTABLISHED -j ACCEPT
|
||||
iptables -A FORWARD -i $IF_USB -o $IF_HOST -j ACCEPT
|
||||
|
||||
ip route show
|
||||
else
|
||||
net_off
|
||||
fi
|
||||
Reference in New Issue
Block a user