Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@hardillb

This comment has been minimized.

Copy link
Owner Author

@hardillb 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.

@hardillb

This comment has been minimized.

Copy link
Owner Author

@hardillb hardillb commented Feb 24, 2020

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

@boistordu

This comment has been minimized.

Copy link

@boistordu 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 ?

@boistordu

This comment has been minimized.

Copy link

@boistordu boistordu commented Apr 24, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.