stop getty@ttyGS0.service so we can remove gadget
[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 HOST="48:6f:73:74:50:43"
16 RNDIS="42:61:64:55:53:42"
17 RNDIS="" # disabled
18 ECM="42:61:64:55:53:43"
19
20 echo 0x04b3 > idVendor
21 echo 0x4010 > idProduct
22
23 echo 0x0100 > bcdDevice # v1.0.0
24 mkdir -p strings/0x409
25 echo "badc0deddeadbeef" > strings/0x409/serialnumber
26 echo "wismna" > strings/0x409/manufacturer
27 echo "PiZero" > strings/0x409/product
28
29 if [ ! -z "$RNDIS" ]; then
30         # Config 1: RNDIS
31         mkdir -p configs/c.1/strings/0x409
32         echo "0x80" > configs/c.1/bmAttributes
33         echo 250 > configs/c.1/MaxPower
34         echo "Config 1: RNDIS network" > configs/c.1/strings/0x409/configuration
35
36         echo "1" > os_desc/use
37         echo "0xcd" > os_desc/b_vendor_code
38         echo "MSFT100" > os_desc/qw_sign
39
40         mkdir -p functions/rndis.usb0
41         echo $RNDIS > functions/rndis.usb0/dev_addr
42         echo $HOST > functions/rndis.usb0/host_addr
43         echo "RNDIS" > functions/rndis.usb0/os_desc/interface.rndis/compatible_id
44         echo "5162001" > functions/rndis.usb0/os_desc/interface.rndis/sub_compatible_id
45 fi
46
47 # Config 2: CDC ECM
48 mkdir -p configs/c.2/strings/0x409
49 echo "Config 2: ECM network" > configs/c.2/strings/0x409/configuration
50 echo 250 > configs/c.2/MaxPower
51
52 mkdir -p functions/ecm.usb0
53 # first byte of address must be even
54 echo $HOST > functions/ecm.usb0/host_addr
55 echo $ECM > functions/ecm.usb0/dev_addr
56
57 # Create the CDC ACM function
58 mkdir -p functions/acm.gs0
59
60 # Link everything and bind the USB device
61 if [ ! -z "$RNDIS" ]; then
62         ln -s configs/c.1 os_desc
63         ln -s functions/rndis.usb0 configs/c.1
64 fi
65
66 ln -s functions/ecm.usb0 configs/c.2
67 ln -s functions/acm.gs0 configs/c.2
68 # End functions
69 ls /sys/class/udc > UDC