-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathbb-start-acm-ncm-rndis-old-gadget
executable file
·206 lines (171 loc) · 7.01 KB
/
bb-start-acm-ncm-rndis-old-gadget
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/bin/sh -e
#
# Copyright (c) 2013-2021 Robert Nelson <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#Based off:
#https://github.com/beagleboard/meta-beagleboard/blob/master/meta-beagleboard-extras/recipes-support/usb-gadget/gadget-init/g-ether-load.sh
if [ -f /etc/default/bb-mac-addr ] ; then
. /etc/default/bb-mac-addr
elif [ -f /usr/bin/bb-setup-mac-address ] ; then
/usr/bin/bb-setup-mac-address
sync
. /etc/default/bb-mac-addr
fi
if [ -f /etc/default/bb-boot ] ; then
. /etc/default/bb-boot
fi
if [ -f /etc/default/generic-sys-mods ] ; then
. /etc/default/generic-sys-mods
fi
log="usb_gadget:"
usb_gadget="/sys/kernel/config/usb_gadget"
# idVendor 0x1d6b Linux Foundation
# idProduct 0x0104 Multifunction Composite Gadget
# bcdDevice 4.04
# bcdUSB 2.00
usb_idVendor="0x1d6b"
usb_idProduct="0x0104"
usb_bcdDevice="0x0404"
usb_bcdUSB="0x0200"
usb_serialnr="000000"
usb_product="USB Device"
usb_iserialnumber="1234BBBK5678"
#usb_iserialnumber="$(cat /proc/device-tree/serial-number)"
usb_imanufacturer="BeagleBoard.org"
usb_iproduct="$(cat /proc/device-tree/model | sed "s/ /_/g" | tr -d '\000')"
#usb0 mass_storage
usb_ms_stall=0
usb_ms_cdrom=0
usb_ms_nofua=1
usb_ms_removable=1
usb_ms_ro=1
usb_ms_imagefile=/etc/bbb.io/templates/beagle-getting-started.img
#mac address:
#cpsw_0_mac = eth0 - wlan0 (in eeprom)
#cpsw_1_mac = usb0 (BeagleBone Side) (in eeprom)
#cpsw_2_mac = usb0 (USB host, pc side) ((cpsw_0_mac + cpsw_2_mac) /2 )
#cpsw_3_mac = wl18xx (AP) (cpsw_0_mac + 3)
#cpsw_4_mac = usb1 (BeagleBone Side)
#cpsw_5_mac = usb1 (USB host, pc side)
if [ -f /etc/default/usb-oem ] ; then
. /etc/default/usb-oem
fi
run_libcomposite () {
if [ ! -d /sys/kernel/config/usb_gadget/g_multi/ ] ; then
echo "${log} Creating g_multi"
mkdir -p /sys/kernel/config/usb_gadget/g_multi || true
cd /sys/kernel/config/usb_gadget/g_multi
echo ${usb_bcdUSB} > bcdUSB
echo ${usb_idVendor} > idVendor # Linux Foundation
echo ${usb_idProduct} > idProduct # Multifunction Composite Gadget
echo ${usb_bcdDevice} > bcdDevice
#0x409 = english strings...
mkdir -p strings/0x409
echo ${usb_iserialnumber} > strings/0x409/serialnumber
echo ${usb_imanufacturer} > strings/0x409/manufacturer
echo ${usb_iproduct} > strings/0x409/product
mkdir -p configs/c.1/strings/0x409
echo "BeagleBone Composite" > configs/c.1/strings/0x409/configuration
echo 500 > configs/c.1/MaxPower
if [ ! "x${USB_RNDIS_DISABLED}" = "xyes" ]; then
mkdir -p functions/rndis.usb0
if [ ! "x${USB0_HOST_ADDR}" = "x" ] ; then
echo ${USB0_HOST_ADDR} > functions/rndis.usb0/host_addr
echo ${USB0_DEV_ADDR} > functions/rndis.usb0/dev_addr
fi
# Starting with kernel 4.14, we can do this to match Microsoft's built-in RNDIS driver.
# Earlier kernels require the patch below as a work-around instead:
# https://github.com/beagleboard/linux/commit/e94487c59cec8ba32dc1eb83900297858fdc590b
if [ -f functions/rndis.usb0/class ]; then
echo EF > functions/rndis.usb0/class
echo 04 > functions/rndis.usb0/subclass
echo 01 > functions/rndis.usb0/protocol
fi
# Add OS Descriptors for the latest Windows 10 rndiscmp.inf
# https://answers.microsoft.com/en-us/windows/forum/windows_10-networking-winpc/windows-10-vs-remote-ndis-ethernet-usbgadget-not/cb30520a-753c-4219-b908-ad3d45590447
# https://www.spinics.net/lists/linux-usb/msg107185.html
echo 1 > os_desc/use
echo 0xCD > os_desc/b_vendor_code || true
echo MSFT100 > os_desc/qw_sign
echo "RNDIS" > functions/rndis.usb0/os_desc/interface.rndis/compatible_id
echo "5162001" > functions/rndis.usb0/os_desc/interface.rndis/sub_compatible_id
mkdir -p configs/c.1
ln -s configs/c.1 os_desc
mkdir -p functions/rndis.usb0/os_desc/interface.rndis/Icons
echo 2 > functions/rndis.usb0/os_desc/interface.rndis/Icons/type
echo "%SystemRoot%\\system32\\shell32.dll,-233" > functions/rndis.usb0/os_desc/interface.rndis/Icons/data
mkdir -p functions/rndis.usb0/os_desc/interface.rndis/Label
echo 1 > functions/rndis.usb0/os_desc/interface.rndis/Label/type
echo "BeagleBone USB Ethernet" > functions/rndis.usb0/os_desc/interface.rndis/Label/data
ln -s functions/rndis.usb0 configs/c.1/
mkdir -p functions/ncm.usb0
if [ ! "x${USB1_HOST_ADDR}" = "x" ] ; then
echo ${USB1_HOST_ADDR} > functions/ncm.usb0/host_addr
echo ${USB1_DEV_ADDR} > functions/ncm.usb0/dev_addr
fi
ln -s functions/ncm.usb0 configs/c.1/
else
mkdir -p functions/ncm.usb0
if [ ! "x${USB0_HOST_ADDR}" = "x" ] ; then
echo ${USB0_HOST_ADDR} > functions/ncm.usb0/host_addr
echo ${USB0_DEV_ADDR} > functions/ncm.usb0/dev_addr
fi
ln -s functions/ncm.usb0 configs/c.1/
fi
mkdir -p functions/acm.usb0
ln -s functions/acm.usb0 configs/c.1/
if [ ! "x${USB_IMAGE_FILE_DISABLED}" = "xyes" ]; then
if [ -f ${usb_ms_imagefile} ] ; then
echo "${log} enable USB mass_storage img file"
mkdir -p functions/mass_storage.usb0
echo ${usb_ms_stall} > functions/mass_storage.usb0/stall
echo ${usb_ms_cdrom} > functions/mass_storage.usb0/lun.0/cdrom
echo ${usb_ms_nofua} > functions/mass_storage.usb0/lun.0/nofua
echo ${usb_ms_removable} > functions/mass_storage.usb0/lun.0/removable
echo ${usb_ms_ro} > functions/mass_storage.usb0/lun.0/ro
echo ${usb_ms_imagefile} > functions/mass_storage.usb0/lun.0/file
ln -s functions/mass_storage.usb0 configs/c.1/
fi
fi
#mkdir -p functions/mass_storage.usb0
#echo 0 > functions/mass_storage.usb0/stall
#echo /dev/nbd0 > functions/mass_storage.usb0/lun.0/file
#ln -s functions/mass_storage.usb0 configs/c.1/
#if [ -f /usr/bin/umtprd ] ; then
# mkdir -p functions/ffs.mtp
# ln -s functions/ffs.mtp configs/c.1
# mkdir /dev/ffs-mtp
# mount -t functionfs mtp /dev/ffs-mtp
# /usr/bin/umtprd &
# sleep 1
#fi
fi
cd /sys/kernel/config/usb_gadget/g_multi
ls /sys/class/udc/ > UDC
echo "${log} g_multi Created"
}
use_libcomposite () {
echo "${log} Looking for libcomposite"
if [ -d /sys/kernel/config/usb_gadget/ ] ; then
run_libcomposite
fi
}
use_libcomposite
#