├── .github └── FUNDING.yml ├── .gitignore ├── LICENSE ├── README.md ├── create-image ├── etc ├── dnsmasq.d │ └── usb0 └── network │ └── interfaces.d │ └── usb0 ├── lib └── systemd │ └── system │ └── usbgadget.service ├── macos-rndis.txt ├── setup.sh └── usr └── local └── sbin ├── usb-gadget.sh ├── usb-gadget.sh-alternate └── usb-gadget.sh-orig /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [hardillb] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.img 2 | *.zip 3 | userconf.txt 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Raspbery Pi USB Gadget Image Builder 2 | 3 | A script to add USB Ethernet Gadget configuration to a standard Raspbian Lite SD Card image. 4 | This should work with Raspberry Pi Zero, Zero W and 4. 5 | 6 | Currently only tested on Linux and with Docker Desktop + WSL on Windows 10, but should also run on OSx 7 | 8 | Doesn't work with current Bullseye based images 9 | 10 | 11 | ## Requirements 12 | 13 | - Docker 14 | - expect 15 | 16 | ## Install 17 | 18 | Clone the repo 19 | 20 | ``` 21 | git clone https://github.com/hardillb/rpi-gadget-image-creator.git 22 | ``` 23 | 24 | Copy the raspbian lite image into the `rpi-gadget-image-creator` directory. 25 | 26 | ## Running 27 | 28 | ``` 29 | ./setup.sh 2019-09-26-raspbian-buster-lite.img 30 | ``` 31 | 32 | To build a 64bit OS image you need to add `-64` before the image name. 64bit versions will run on Pi 3 and Pi 4 hardware. 33 | 34 | ``` 35 | ./setup.sh -64 2020-08-20-raspios-buster-arm64.img 36 | ``` 37 | 38 | 39 | Once complete you can write the image file to a SD Card with any of the usual tools e.g. `dd` or `balena-etch`. 40 | You can find instructions on the Raspberry Pi website [here](https://www.raspberrypi.org/documentation/installation/installing-images/README.md) 41 | 42 | ## TODO 43 | 44 | Look at repackaging everything into an extention to DockerPi so the whole thing runs in the container. 45 | -------------------------------------------------------------------------------- /create-image: -------------------------------------------------------------------------------- 1 | #!/usr/bin/expect -- 2 | 3 | set timeout -1 4 | proc slurp {file} { 5 | set fh [open $file r] 6 | set ret [read $fh] 7 | close $fh 8 | return $ret 9 | } 10 | 11 | if { $argc == 1 } { 12 | set imageName [lindex $argv 0] 13 | set 64bit "false" 14 | puts "32bit" 15 | } elseif { $argc == 2 } { 16 | set imageName [lindex $argv 1] 17 | set 64bit "true" 18 | puts "64bit" 19 | } 20 | 21 | if {[string trimleft $imageName] eq ""} { 22 | puts "No Image file provided" 23 | exit 24 | } 25 | 26 | set cwd [file normalize [file dirname $argv0]] 27 | set imagePath [file join $cwd $imageName] 28 | puts $imageName 29 | puts $imagePath\n 30 | 31 | if { $64bit == "true" } { 32 | spawn docker run --name dockerpi -it --rm -v $imagePath:/sdcard/filesystem.img lukechilds/dockerpi:vm pi3 33 | } else { 34 | spawn docker run --name dockerpi -it --rm -v $imagePath:/sdcard/filesystem.img lukechilds/dockerpi:vm 35 | } 36 | 37 | expect "raspberrypi login: " 38 | send "pi\n" 39 | expect "Password: " 40 | #send "raspberry\n" 41 | send $env(PASSWORD) 42 | send "\n" 43 | 44 | expect "$ " 45 | send "sudo apt-get update\n" 46 | expect "$ " 47 | send "sudo apt-get -y install dnsmasq\n" 48 | expect "$ " 49 | send "sudo apt-get clean\n" 50 | expect "$ " 51 | send "sudo su -\n" 52 | 53 | set file [slurp "etc/dnsmasq.d/usb0"] 54 | expect "# " 55 | send "cat <> /etc/dnsmasq.d/usb0\n" 56 | send "$file\n" 57 | send "EOF\n" 58 | 59 | set file [slurp "etc/network/interfaces.d/usb0"] 60 | expect "# " 61 | send "cat <> /etc/network/interfaces.d/usb0\n" 62 | send "$file\n" 63 | send "EOF\n" 64 | 65 | set file [slurp "usr/local/sbin/usb-gadget.sh"] 66 | expect "# " 67 | send "cat <> /usr/local/sbin/usb-gadget.sh\n" 68 | send "$file\n" 69 | send "EOF\n" 70 | expect "# " 71 | send "chmod +x /usr/local/sbin/usb-gadget.sh\n" 72 | 73 | set file [slurp "lib/systemd/system/usbgadget.service"] 74 | expect "# " 75 | send "cat <> /lib/systemd/system/usbgadget.service\n" 76 | send "$file\n" 77 | send "EOF\n" 78 | expect "# " 79 | send "systemctl enable usbgadget.service\n" 80 | 81 | expect "# " 82 | send "echo dtoverlay=dwc2 >> /boot/config.txt\n" 83 | 84 | expect "# " 85 | send "sed -i 's/$/ modules-load=dwc2/' /boot/cmdline.txt \n" 86 | 87 | expect "# " 88 | send "touch /boot/ssh\n" 89 | 90 | expect "# " 91 | send "echo libcomposite >> /etc/modules\n" 92 | 93 | expect "# " 94 | send "echo denyinterfaces usb0 usb1 br0 >> /etc/dhcpcd.conf\n" 95 | 96 | expect "# " 97 | send "sudo systemctl enable getty@ttyGS0.service\n" 98 | 99 | expect "# " 100 | send "poweroff\n" 101 | 102 | expect "Reboot failed -- System halted" 103 | exec docker stop dockerpi 104 | exit 105 | -------------------------------------------------------------------------------- /etc/dnsmasq.d/usb0: -------------------------------------------------------------------------------- 1 | dhcp-authoritative 2 | dhcp-rapid-commit 3 | no-ping 4 | interface=br0 5 | dhcp-range=10.55.0.2,10.55.0.6,255.255.255.248,1h 6 | dhcp-option=3 7 | leasefile-ro 8 | -------------------------------------------------------------------------------- /etc/network/interfaces.d/usb0: -------------------------------------------------------------------------------- 1 | auto br0 2 | iface br0 inet static 3 | address 10.55.0.1 4 | netmask 255.255.255.248 5 | bridge_ports usb0 usb1 6 | bridge_stp off 7 | bridge_fd 0 8 | bridge_waitport 0 9 | 10 | 11 | #auto usb0 12 | #allow-hotplug usb0 13 | #iface usb0 inet static 14 | # address 10.55.0.1 15 | # netmask 255.255.255.248 16 | 17 | #auto usb1 18 | #allow-hotplug usb1 19 | #iface sub1 inet static 20 | # address 10.55.1.1 21 | # netmask 255.255.255.248 22 | -------------------------------------------------------------------------------- /lib/systemd/system/usbgadget.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=My USB gadget 3 | After=network-online.target 4 | Wants=network-online.target 5 | #After=systemd-modules-load.service 6 | 7 | [Service] 8 | Type=oneshot 9 | RemainAfterExit=yes 10 | ExecStart=/usr/local/sbin/usb-gadget.sh 11 | 12 | [Install] 13 | WantedBy=sysinit.target 14 | -------------------------------------------------------------------------------- /macos-rndis.txt: -------------------------------------------------------------------------------- 1 | https://www.joshuawise.com/horndis#notes_about_specific_mac_os_x_versions 2 | 3 | 4 | -------------------------------------------------------------------------------- /setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $# -eq 0 ]]; then 4 | echo "You must pass a image file" 5 | exit 6 | fi 7 | 8 | if [[ $# -eq 2 ]]; then 9 | 64BIT=1 10 | fi 11 | OFFSET=$(fdisk -l $1 | grep W95 | awk '/^[^ ]*1/{ print $2*512 }') 12 | mkdir boot 13 | sudo mount -o loop,offset=$OFFSET $1 boot 14 | 15 | read -rsp "Please enter password for pi user: " PASSWORD 16 | echo 17 | PASS=$(echo $PASSWORD | openssl passwd -6 -stdin) 18 | echo "pi:$PASS" > userconf.txt 19 | 20 | sudo cp userconf.txt boot/userconf.txt 21 | sudo sync 22 | 23 | sudo umount boot 24 | rmdir boot 25 | export PASSWORD 26 | if [[ 64BIT eq 1 ]]; then 27 | ./create-image -64 $1 28 | else 29 | ./create-image $1 30 | fi 31 | -------------------------------------------------------------------------------- /usr/local/sbin/usb-gadget.sh: -------------------------------------------------------------------------------- 1 | usb-gadget.sh-orig -------------------------------------------------------------------------------- /usr/local/sbin/usb-gadget.sh-alternate: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gadget=/sys/kernel/config/usb_gadget/pi4 3 | usb_version="0x0200" # USB 2.0 4 | device_class="0xEF" 5 | device_subclass="0x02" 6 | bcd_device="0x0100" # v1.0.0 7 | device_protocol="0x01" 8 | vendor_id="0x1d50" 9 | product_id="0x60c7" 10 | #vendor_id="0x1d6b" # Linux Foundation 11 | #product_id="0x0104" # Multifunction composite gadget 12 | manufacturer="Ian" 13 | product="RPi4 USB Gadget" 14 | serial="fedcba9876543211" 15 | attr="0x80" # Bus powered 16 | power="250" 17 | config1="RNDIS" 18 | config2="CDC" 19 | ms_vendor_code="0xcd" # Microsoft 20 | ms_qw_sign="MSFT100" # also Microsoft (if you couldn't tell) 21 | ms_compat_id="RNDIS" # matches Windows RNDIS Drivers 22 | ms_subcompat_id="5162001" # matches Windows RNDIS 6.0 Driver 23 | 24 | mac="01:23:45:67:89:ab" 25 | dev_mac="02$(echo ${mac} | cut -b 3-)" 26 | host_mac="12$(echo ${mac} | cut -b 3-)" 27 | mkdir -p ${gadget} 28 | echo "${usb_version}" > ${gadget}/bcdUSB 29 | echo "${device_class}" > ${gadget}/bDeviceClass 30 | echo "${device_subclass}" > ${gadget}/bDeviceSubClass 31 | echo "${vendor_id}" > ${gadget}/idVendor 32 | echo "${product_id}" > ${gadget}/idProduct 33 | echo "${bcd_device}" > ${gadget}/bcdDevice 34 | echo "${device_protocol}" > ${gadget}/bDeviceProtocol 35 | mkdir -p ${gadget}/strings/0x409 36 | echo "${manufacturer}" > ${gadget}/strings/0x409/manufacturer 37 | echo "${product}" > ${gadget}/strings/0x409/product 38 | echo "${serial}" > ${gadget}/strings/0x409/serialnumber 39 | mkdir ${gadget}/configs/c.1 40 | echo "${attr}" > ${gadget}/configs/c.1/bmAttributes 41 | echo "${power}" > ${gadget}/configs/c.1/MaxPower 42 | mkdir -p ${gadget}/configs/c.1/strings/0x409 43 | echo "${config1}" > ${gadget}/configs/c.1/strings/0x409/configuration 44 | mkdir -p ${gadget}/os_desc 45 | echo "1" > ${gadget}/os_desc/use 46 | echo "${ms_vendor_code}" > ${gadget}/os_desc/b_vendor_code 47 | echo "${ms_qw_sign}" > ${gadget}/os_desc/qw_sign 48 | mkdir -p ${gadget}/functions/rndis.usb0 49 | echo "${dev_mac}" > ${gadget}/functions/rndis.usb0/dev_addr 50 | echo "${host_mac}" > ${gadget}/functions/rndis.usb0/host_addr 51 | echo "${ms_compat_id}" > ${gadget}/functions/rndis.usb0/os_desc/interface.rndis/compatible_id 52 | echo "${ms_subcompat_id}" > ${gadget}/functions/rndis.usb0/os_desc/interface.rndis/sub_compatible_id 53 | 54 | mkdir -p ${gadget}/functions/acm.usb0 55 | 56 | #mkdir ${gadget}/configs/c.2 57 | #echo "${attr}" > ${gadget}/configs/c.2/bmAttributes 58 | #echo "${power}" > ${gadget}/configs/c.2/MaxPower 59 | #mkdir -p ${gadget}/configs/c.2/strings/0x409 60 | #echo "${config2}" > ${gadget}/configs/c.2/strings/0x409/configuration 61 | #mkdir -p ${gadget}/functions/ecm.usb0 62 | #echo "${dev_mac}" > ${gadget}/functions/ecm.usb0/dev_addr 63 | #echo "${host_mac}" > ${gadget}/functions/ecm.usb0/host_addr 64 | 65 | ln -s ${gadget}/configs/c.1 ${gadget}/os_desc 66 | ln -s ${gadget}/functions/rndis.usb0 ${gadget}/configs/c.1 67 | ln -s ${gadget}/functions/acm.usb0 ${gadget}/configs/c.1/ 68 | 69 | #ln -s ${gadget}/functions/ecm.usb0 ${gadget}/configs/c.2 70 | 71 | ls /sys/class/udc > ${gadget}/UDC 72 | udevadm settle -t 5 || : 73 | ifup usb0 74 | #service dnsmasq restart -------------------------------------------------------------------------------- /usr/local/sbin/usb-gadget.sh-orig: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd /sys/kernel/config/usb_gadget/ 4 | mkdir -p display-pi 5 | cd display-pi 6 | echo 0x1d6b > idVendor # Linux Foundation 7 | echo 0x0104 > idProduct # Multifunction Composite Gadget 8 | echo 0x0103 > bcdDevice # v1.0.3 9 | echo 0x0320 > bcdUSB # USB2 10 | echo 2 > bDeviceClass 11 | #echo 0x02 > bDeviceSubClass 12 | #echo 0x01 > bDeviceProtocol 13 | mkdir -p strings/0x409 14 | echo "fedcba9876543213" > strings/0x409/serialnumber 15 | echo "Ben Hardill" > strings/0x409/manufacturer 16 | echo "Display-Pi USB Device" > strings/0x409/product 17 | mkdir -p configs/c.1/strings/0x409 18 | echo "CDC" > configs/c.1/strings/0x409/configuration 19 | echo 250 > configs/c.1/MaxPower 20 | echo 0x80 > configs/c.1/bmAttributes 21 | # Add functions here 22 | # see gadget configurations below 23 | # End functions 24 | 25 | mkdir -p functions/ecm.usb0 26 | HOST="00:dc:c8:f7:75:15" # "HostPC" 27 | SELF="00:dd:dc:eb:6d:a1" # "BadUSB" 28 | echo $HOST > functions/ecm.usb0/host_addr 29 | echo $SELF > functions/ecm.usb0/dev_addr 30 | ln -s functions/ecm.usb0 configs/c.1/ 31 | 32 | #RNDIS 33 | mkdir -p configs/c.2 34 | echo 0x80 > configs/c.2/bmAttributes 35 | echo 0x250 > configs/c.2/MaxPower 36 | mkdir -p configs/c.2/strings/0x409 37 | echo "RNDIS" > configs/c.2/strings/0x409/configuration 38 | 39 | echo "1" > os_desc/use 40 | echo "0xcd" > os_desc/b_vendor_code 41 | echo "MSFT100" > os_desc/qw_sign 42 | 43 | mkdir -p functions/rndis.usb0 44 | HOST_R="00:dc:c8:f7:75:16" 45 | SELF_R="00:dd:dc:eb:6d:a2" 46 | echo $HOST_R > functions/rndis.usb0/dev_addr 47 | echo $SELF_R > functions/rndis.usb0/host_addr 48 | echo "RNDIS" > functions/rndis.usb0/os_desc/interface.rndis/compatible_id 49 | echo "5162001" > functions/rndis.usb0/os_desc/interface.rndis/sub_compatible_id 50 | 51 | ln -s functions/rndis.usb0 configs/c.2 52 | ln -s configs/c.2 os_desc 53 | 54 | 55 | mkdir -p functions/acm.usb0 56 | ln -s functions/acm.usb0 configs/c.1/ 57 | 58 | #mkdir -p functions/mass_storage.usb0 59 | #echo 0 > functions/mass_storage.usb0/stall 60 | #echo 0 > functions/mass_storage.usb0/lun.0/cdrom 61 | #echo 1 > functions/mass_storage.usb0/lun.0/ro 62 | #echo 0 > functions/mass_storage.usb0/lun.0/nofua 63 | #echo /opt/disk.img > functions/mass_storage.usb0/lun.0/file 64 | #ln -s functions/mass_storage.usb0 configs/c.1/ 65 | 66 | 67 | udevadm settle -t 5 || : 68 | ls /sys/class/udc > UDC 69 | 70 | sleep 5 71 | 72 | ip link set usb0 up 73 | ip link set usb1 up 74 | 75 | ifup br0 76 | brctl addif br0 usb0 77 | brctl addif br0 usb1 78 | 79 | --------------------------------------------------------------------------------