Skip to content

Instantly share code, notes, and snippets.

@hardillb
Last active December 10, 2021 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hardillb/200428f7d06ab406bf0bbf216256e834 to your computer and use it in GitHub Desktop.
Save hardillb/200428f7d06ab406bf0bbf216256e834 to your computer and use it in GitHub Desktop.
A script to configure libcomposite USB Ethernet Gadget that will be recognised by Windows based on https://github.com/RoganDawes/P4wnP1/blob/62b5c40d9461e4b80998c54830625d6c855833f0/boot/init_usb.sh
#!/bin/bash
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
HOST="00:dc:c8:f7:75:14"
SELF="00:dd:dc:eb:6d:a1"
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)
echo $UCD_DRIVER > UDC
sleep 0.2
udevadm settle -t 5 || :
#ifup usb0
sleep 2
service dnsmasq restart
@changemenemo
Copy link

@matthiesenj
Copy link

@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