The motivation for adding an network gadget for me is to have an improved RDP experience in addition to other things.
Here are the steps to add a Windows 10 compatible network gadget
Step 1 : Upgrade packages. this will pull in the otg-device overlay
$ sudo apt update && sudo apt dist-upgrade -y
Step 2 : Enable OTG device mode
$ sudo nano /boot/env.txt
append otg-device if it is not already to overlays=, example
overlays=uart3 pwm_f i2c3 otg-device
CTRL+s and CTRL+x to save and exit
Step 3 : Reboot
$ sync && sudo reboot
Step 4 : Add RNDIS gadget setup script.
$ sudo nano /usr/local/bin/rndis-gadget
Copy and paste the following â/usr/local/bin/rndis-gadgetâ. CTRL+s and CTRL+x to save and exit.
#!/bin/sh
#
# Create Windows 10 compatible RNDIS USB Gadget
#
. /etc/fenix-release
GADGET=/sys/kernel/config/usb_gadget/g1
if [ -d $GADGET ]; then
echo âExiting⌠RNDIS Gadget existsâ
exit 0
fi
F_RNDIS=$GADGET/functions/rndis.0
SERIAL="$(grep Serial /proc/cpuinfo | grep -o -P â.{0,12}$â)"
MAC="$(echo ${SERIAL} | sed âs/(\w\w)/:\1/gâ | cut -b 2-)"
MAC_HOST=â12$(echo ${MAC} | cut -b 3-)â
MAC_DEV=â02$(echo ${MAC} | cut -b 3-)â
UDC="$(ls /sys/class/udc/ | awk â{print $1}â)"
mkdir $GADGET
echo â0x1d6bâ > $GADGET/idVendor # Linux Foundation
echo â0x0104â > $GADGET/idProduct
echo â0x0100â > $GADGET/bcdDevice
echo â0x0200â > $GADGET/bcdUSB
echo â0xEFâ > $GADGET/bDeviceClass
echo â0x04â > $GADGET/bDeviceSubClass
echo â0x01â > $GADGET/bDeviceProtocol
# Set Strings
mkdir $GADGET/strings/0x409
echo $SERIAL > $GADGET/strings/0x409/serialnumber
echo âKhadasâ > $GADGET/strings/0x409/manufacturer
echo $BOARD > $GADGET/strings/0x409/product
# Create Config
mkdir $GADGET/configs/c.1
mkdir $GADGET/configs/c.1/strings/0x409
echo âRNDIS Gadgetâ > $GADGET/configs/c.1/strings/0x409/configuration
echo â500â > $GADGET/configs/c.1/MaxPower
echo â0x80â > $GADGET/configs/c.1/bmAttributes # USB_OTG_SRP | USB_OTG_HNP
# Create RNDIS function
mkdir $F_RNDIS
echo $MAC_HOST > $F_RNDIS/host_addr
echo $MAC_DEV > $F_RNDIS/dev_addr
# OS Descriptors
echo â1â > $GADGET/os_desc/use
echo â0xbcâ > $GADGET/os_desc/b_vendor_code
echo âMSFT100â > $GADGET/os_desc/qw_sign
mkdir -p $F_RNDIS/os_desc/interface.rndis
echo âRNDISâ > $F_RNDIS/os_desc/interface.rndis/compatible_id
echo â5162001â > $F_RNDIS/os_desc/interface.rndis/sub_compatible_id
# Bind function to configuration
ln -s $F_RNDIS $GADGET/configs/c.1/
ln -s $GADGET/configs/c.1/ $GADGET/os_desc
# Enable the Gadget
echo $UDC > $GADGET/UDC
echo âDone creating RNDIS USB GadgetâŚ$(cat $F_RNDIS/ifname)â
exit 0
Step 5 : Make ârndis-gadgetâ executable
$ sudo chmod +x /usr/local/bin/rndis-gadget
Step 6 : Add systemd service file
$ sudo systemctl edit --force rndis-gadget.service --full
Copy and paste the following into the editor. CTRL+s and CTRL+x to save and exit.
[Unit]
Description=RNDIS over USB
DefaultDependencies=no
After=systemd-update-utmp-runlevel.service
[Service]
Type=oneshot
ExecStart=/usr/local/bin/rndis-gadget
RemainAfterExit=true
[Install]
WantedBy=sysinit.target
Step 7 : Test 'RNDIS over USBâ
$ sudo systemctl start rndis-gadget.service
$ ip a
to confirm usb0
shows up.
On your PC, check if the VIM is listed as âRemote NDIS Compatible Deviceâ under the Device Manager->Network adapters
Step 8 : Enable âRNDIS over USBâ on boot
$ sudo systemctl enable rndis-gadget.service
WE ARE NOT DONE YET
The final step is to decide who is going to provide the IP address to both the VIM and the PC it is connected.
Pick one of the following three options
Option 1. Static IP for both VIM and PC (Easy)
$ echo $'# RNDIS Gadget\nallow-hotplug usb0\niface usb0 inet static\naddress 192.168.10.100\nnetmask 255.255.255.0\ngateway 192.168.10.1' | sudo tee /etc/network/interfaces.d/interface.rndis
On your Linux/Mac/Windows PC setup the network interface to static IP with following
Address: 192.168.10.101
Netmask: 255.255.255.0
Gateway: 192.168.10.1
Option 2. PC providing the IP to VIM
$ echo $'# RNDIS Gadget\nallow-hotplug usb0\niface usb0 inet dhcp' | sudo tee /etc/network/interfaces.d/interface.rndis
Windows : Use âInternet Connection Sharingâ
Linux Network Manager : Set the interface âShared Connectionâ feature
Option 3. VIM providing the IP to PC (Instructions not complete)
Add interface usb0 to NetworkManager managed devices
$ sudo sed -i '/unmanaged-devices/{/,except:interface-name:usb0/! s/$/,except:interface-name:usb0/}'
Create NetworkManager connection
$ sudo nmcli connection add type ethernet ifname usb0 ipv4.method shared ipv6.method ignore con-name local-rndis
Reboot for the changes to take effect.