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