Power & Source of Big Ideas

Can you create a guide to configure OTG ethernet mode

Moderators: chensy, FATechsupport

Hi,

I'd like to use the USB-port as a linux OTG gadget under debian - can you create a guide and provide necessary files similar to ADB? I can see the drivers being loaded from usbcore during boot but there is no module to load with modprobe that sticks.

The idea is to connect the USB-C to windows laptop and use ethernet over the cable (RNDIS / g_ether for raspberry pi) so that the NanoPi Zero2 becomes a VPN device



Thanks
For anyones interested I did this myself - after too much digging into linux configfs it led me to the /usr/bin/usbdevice (and -wrapper file).

Below should be enough to get the NanoPi Zero2 working as an OTG RNDIS ethernet adapter over the USB-C port, I ended up creating these files to get everything up and running from bootup:

/etc/usbdevice.d/usbrndis.sh (with +x permission)

Code: Select all

#!/bin/sh
#
# Place this file into directory (create if not existing) /etc/usbdevice.d/
#
USB_FUNCS='rndis'


/lib/systemd/system/usbrndis.service
followed by: systemctl enable usbrndis

Code: Select all

# Service file for USB RNDIS
#
# - place this file into /lib/systemd/system
# - run: systemctl enable usbrndis
#

[Unit]
Description=Manage USB RNDIS systemd environment
DefaultDependencies=no
Before=network.target

[Service]
Type=simple
ExecStart=/usr/bin/usbdevice start
ExecStop=/usr/bin/usbdevice stop
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target


Restart system and check dmesg for usb0 messages, should see random macs assigned:
dmesg | grep usb0

Finally to add (if not using nmcli) IP addresses
/etc/network/interfaces.d/usb0.conf

Code: Select all

allow-hotplug usb0
iface usb0 inet static
        address 192.168.30.1/24


If using Network Manager/nmcli there is a restriction that has to be lifted to make usb0 permanently managed, place
/usr/lib/udev/rules.d/85-nm-unmanaged.rules
into
/etc/udev/rules.d/
and replace the line

Code: Select all

ENV{DEVTYPE}=="gadget", ENV{NM_UNMANAGED}="1"

with

Code: Select all

ENV{DEVTYPE}=="gadget", ENV{NM_UNMANAGED}="0"


and then nmcli dev set usb0 managed yes

That's it

Who is online

In total there are 2 users online :: 0 registered, 0 hidden and 2 guests (based on users active over the past 5 minutes)
Most users ever online was 5185 on Wed Jan 22, 2020 1:44 pm

Users browsing this forum: No registered users and 2 guests