Config problems with OpenWRT23/25 on Rasberry Pi in USB-OTG gadget mode

Raspberry Pis have a single dedicated USB-On-The-Go USB-port, using it means the Pi does then not act as the USB-host, but as USB gadget device.

With this the Pi is said to be usable with OpenWRT, such that the Pi can be directly connected to a host PC via USB cable. If configured properly and attached to PC, a virtual COM-port and/or network adapter is said to appear on the PC, which can then be used for admin access to the Pi device via Putty Serial or SSH connection.

It would be super nice, to have this option as a fallback admin access option on the Pi.

  • I see there is a 4 year old other thread talking about this, but that did not help me.
  • There are countless recipies on the Internet and the usual AIs explain a lot, how to do this, but none helped for me.
  • The most helpful Youtube tutorial for me so far was: https://www.youtube.com/watch?v=BYPsi10kavk, but even then I did not succeed to configure network-over-usb-admin-access.

The first part of the video shows, how to configure Serial over USB via kmod-usb-gadget-serial. This is what actually did work for me.

The second part of the video shows, how to configure both Serial over USB + network over USB.
Sadly. I keep failing on this. I tried twice with Raspberry Pi 4 with vanilla OpenWRT 23.05 and vanilla 25.12rc5.

#packages (“composite” is said to enable both network-over-usb and serial-over-usb)
kmod-usb-dwc2 kmod-usb-gadget-cdc-composite

#/boot/config.txt:
include distroconfig.txt
[all]
dtoverlay=dwc2

#/etc/inittab:
::sysinit:/etc/init.d/rcS S boot
::shutdown:/etc/init.d/rcS K shutdown
::askconsole:/usr/libexec/login.sh
tty1::askfirst:/usr/libexec/login.sh
ttyGS0::askfirst:/usr/libexec/login.sh

#/etc/rc.local:
modprobe g_cdc
sleep 5
ifup otg
exit 0

#/etc/config/system
…other default stuff…
option ttylogin '1' # changed this from 0 to 1

#/etc/config/network:
(running modprobe g_cdc or modprobe g_ether once before committing)

config interface 'loopback'
option device 'lo'
option proto 'static'
list ipaddr '127.0.0.1/8'

config globals 'globals'
option dhcp_default_duid '00046ef1de018083451eaa7a1372380e531f'
option ula_prefix 'fde4:3233:d255::/48'
option packet_steering '1'

config device
option name 'br-lan'
option type 'bridge'
list ports 'eth0'

config interface 'lan'
option device 'br-lan'
option proto 'static'
list ipaddr '192.168.1.1/24'
option ip6assign '60'

config interface 'wwan'
option proto 'dhcp'

config interface 'otg'
option proto 'static'
option device 'usb0'
option auto '0'
option ipaddr '192.168.100.1'
option netmask '255.255.255.0'

#/etc/config/firewall:
…other default stuff…

config zone
option name 'lan'
option input 'ACCEPT'
option output 'ACCEPT'
option forward 'ACCEPT'
list network 'lan'
list network 'otg'

#/etc/network/dhcp
…other default stuff…

config dhcp 'otg'
option interface 'otg'
option start '100'
option limit '150'
option leasetime '12h'
option dhcpv4 'server'

Result fails so far:
Once connecting to the PC, the PC shows a broken COM port in device manager, but no clues of a network-over-USB interface appearing.

  • I can still flawlessly administrate the Pi4 via its regular LAN-port (including installing additional packages via WiFi-WAN). So from my perspective it is not the usual OpenWRT network config that fails, rather it seems neither the serial-over-usb–COM-port and the network-over-usb-LAN adapter do not work, as nothing gets detected on the PC, when connecting via USB-OTG port. Feels like something of the kernel module or its config might be missing.
  • when instead of kmod-usb-gadget-cdc-composite using kmod-usb-gadget-serial, I do see a working COM port on the Windows11-PC immediately once USB-connected and can successfully access it via Putty-serial according to the first part of the video, but using kmod-usb-gadget-cdc-composite for a virtual network adapter leeds to a dead end so far. Even other Internet OTG recipies did not help, just show more exotic packages that did not help. Either CDC-composite feels broken or there is some mysterious config secret that i have missed so far.

Has anyone succeed with network over USB-OTG gadget mode on a Raspberry Pi with a recent OpenWRT 23, 24 or 25rc?

I don't have a clue about this specific setup. But if you say serial is working what about ethernet only (kmod-usb-gadget-eth)? To narrow it down and support your suspicion about the combo driver.

If it is not working are there any errors within logread or within the windows device manager (https://support.microsoft.com/en-us/topic/error-codes-in-device-manager-in-windows-524e9e89-4dee-8883-0afa-6bca0456324e)

Does it work under Linux? Maybe you can see more valueable error messages within a linux client system connecting the raspberry pi/openwrt.

Thanks for your help. So far I was mostly curious, if someone else had succeeded with it.

Unter OpenWRT, the log files seem to look like that it properly loads the OTG network driver, there is also no clue of an error message. Just when attached to Windows/x86, nothing happens. Unlike in the serial-over-usb example which did work (Windows then showed a virtual COM-port once connected), but nothing happening under Windows in the network driver variant.

I have not yet found the time, to start the next hands on attempt.

In the meantime I’ve at least found out one thing: USB standards seem to supports 2 different network driver standards: one of them is called “CDC” and MacOS supports precisely that, but Windows does not. That non-supported CDC network variant is the one included in the composite driver. And it is the reason, why the composite driver works in the linked videoturorial, as the author was not using a Windows PC, but MacOS.

I plan to do do another attempt with 25.12.1 and the network driver.
I did a detour first and installed Raspberry OS and updated the Broadcom EEPRom first (not sure if I ever did this, since when I bought the Rpi4 a few years ago). Since R OS is now on 1 SDCard, I might try to find a tutorial for the network driver/OTG mode on R OS first.

I also still need to try an OTG-connection with Linux on a physical PC.

Once I go for another attempt and find something new, I will update this thread.