little more details and links
[linux-usb-otg] / rndis-ecm-adm.sh
1 #!/bin/sh
2 #
3 # HackPi
4 #  by wismna
5 #  http://github.com/wismna/raspberry-pi/hackpi
6 #  14/01/2017
7 #
8
9 cd /sys/kernel/config/usb_gadget/
10 mkdir -p g1
11 cd g1
12
13 OS=`cat /home/pi/os.txt`
14 HOST="48:6f:73:74:50:43"
15 SELF0="42:61:64:55:53:42"
16 SELF1="42:61:64:55:53:43"
17
18 echo 0x04b3 > idVendor
19 echo 0x4010 > idProduct
20
21 echo 0x0100 > bcdDevice # v1.0.0
22 mkdir -p strings/0x409
23 echo "badc0deddeadbeef" > strings/0x409/serialnumber
24 echo "wismna" > strings/0x409/manufacturer
25 echo "PiZero" > strings/0x409/product
26
27 if [ "$OS" != "MacOs" ]; then
28         # Config 1: RNDIS
29         mkdir -p configs/c.1/strings/0x409
30         echo "0x80" > configs/c.1/bmAttributes
31         echo 250 > configs/c.1/MaxPower
32         echo "Config 1: RNDIS network" > configs/c.1/strings/0x409/configuration
33
34         echo "1" > os_desc/use
35         echo "0xcd" > os_desc/b_vendor_code
36         echo "MSFT100" > os_desc/qw_sign
37
38         mkdir -p functions/rndis.usb0
39         echo $SELF0 > functions/rndis.usb0/dev_addr
40         echo $HOST > functions/rndis.usb0/host_addr
41         echo "RNDIS" > functions/rndis.usb0/os_desc/interface.rndis/compatible_id
42         echo "5162001" > functions/rndis.usb0/os_desc/interface.rndis/sub_compatible_id
43 fi
44
45 # Config 2: CDC ECM
46 mkdir -p configs/c.2/strings/0x409
47 echo "Config 2: ECM network" > configs/c.2/strings/0x409/configuration
48 echo 250 > configs/c.2/MaxPower
49
50 mkdir -p functions/ecm.usb0
51 # first byte of address must be even
52 echo $HOST > functions/ecm.usb0/host_addr
53 echo $SELF1 > functions/ecm.usb0/dev_addr
54
55 # Create the CDC ACM function
56 mkdir -p functions/acm.gs0
57
58 # Link everything and bind the USB device
59 if [ "$OS" != "MacOs" ]; then
60         ln -s configs/c.1 os_desc
61         ln -s functions/rndis.usb0 configs/c.1
62 fi
63
64 ln -s functions/ecm.usb0 configs/c.2
65 ln -s functions/acm.gs0 configs/c.2
66 # End functions
67 ls /sys/class/udc > UDC