Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A script to configure libcomposite USB Ethernet Gadget that will be recognised by Windows based on
cd /sys/kernel/config/usb_gadget/
mkdir -p pi4
cd pi4
echo 0x1d6b > idVendor # Linux Foundation
echo 0x0100 > idProduct # change to get Windows to rescan while testing
echo 0x0100 > bcdDevice # v1.0.0
echo 0x0200 > bcdUSB # USB2
echo 0xEF > bDeviceClass
echo 0x02 > bDeviceSubClass
echo 0x01 > bDeviceProtocol
mkdir -p strings/0x409
echo "fedcba9876543212" > strings/0x409/serialnumber
echo "Ben Hardill" > strings/0x409/manufacturer
echo "PI4 USB Device" > strings/0x409/product
mkdir -p configs/c.1/strings/0x409
echo "Config 1: RNDIS network" > configs/c.1/strings/0x409/configuration
echo 250 > configs/c.1/MaxPower
echo 0x80 > configs/c.1/bmAttributes
# Add functions here
# see gadget configurations below
# End functions
mkdir -p functions/rndis.usb0
echo $HOST > functions/rndis.usb0/host_addr
echo $SELF > functions/rndis.usb0/dev_addr
mkdir -p os_desc
echo 1 > os_desc/use
echo 0xbc > os_desc/b_vendor_code
echo MSTF100 > os_desc/qw_sign
mkdir -p functions/rndis.usb0/os_desc/interface.rndis
echo RNDIS > functions/rndis.usb0/os_desc/interface.rndis/compatible_id
echo 5162001 > functions/rndis.usb0/os_desc/interface.rndis/sub_compatible_id
ln -s functions/rndis.usb0 configs/c.1/
UCD_DRIVER=$(ls /sys/class/udc | cut -f1 | head -n 1)
sleep 0.2
udevadm settle -t 5 || :
#ifup usb0
sleep 2
service dnsmasq restart
Copy link

hardillb commented Feb 23, 2020

While this matches the P4wnP1 script it doesn't work on my Windows 10 machine, but it's the starting point. It works with Linux and I'll test it on a Mac later.

Copy link

hardillb commented Feb 24, 2020

Yeah, this doesn't seem to work on OSx either.

Copy link

boistordu commented Apr 24, 2020

any breakthrough yet?
I've tried different script but since they are all for the pi 0, I don't know if it is really compatible for the pi4 which I try to use with. None of them works. Only the one of geekman and yours are giving me a RNDIS device at least but the drivers can't be found apparently.
That's the result you had too ?

Copy link

boistordu commented Apr 24, 2020

Copy link

matthiesenj commented Dec 10, 2021

@boistordu I can confirm that the gadget stuff from the link you posted works with my Windows 10 (without manually installing drivers) connected to a Pi compute module 4 through the CM4 IO board. Other gadget configs I tried didn't work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment