Use a single USB-C cable to transfer data between RaspberryPi 4B and iPad 仅仅使用一根USB-C to C的数据线来连接树莓派和iPad等设备,方便在外出等网络不方便的地方连接使用 可以使用和Wi-Fi连接时的全部功能,包括但不限于:80端口网站,22端口SSH等其他任何服务
ECM/NCM的支持在Linux/(类)Unix比较好,可以做到即插即用的水平。在Android/HarmonyOS/Windows上需要对应的驱动(待完成) RNDIS在Android与Windows支持较好,可以参阅这篇文章完成配置(未验证)
功能实现演示:
https://www.bilibili.com/video/BV1GF411v7R6/
iPad Air 4(USB3.0);MacBook Pro 2021(Thunderbolt4/USB4)
(我自己没有足够的设备完成测试,欢迎大家测试后在Issue放出结果)建议使用手动配置,自动配置可能会遇到无法分配IP的问题
git clone https://github.com/TANG617/RaspberryPi-One-Wire.git
cd RaspberryPi-One-Wire
chmod +x ./raspi_usb_c.sh
sudo ./raspi_usb_c.sh
/boot/config.txt
末尾写入dtoverlay=dwc2
。/boot/cmdline.txt
末尾写入modules-load=dwc2
。/etc/modules
末尾写入libcomposite
。/etc/dhcpcd.conf
末尾写入denyinterfaces usb0
。sudo apt-get install dnsmasq
。/etc/dnsmasq.d/usb
,并写入interface=usb0
dhcp-range=10.55.0.2,10.55.0.6,255.255.255.248,1h
dhcp-option=3
leasefile-ro
/etc/network/interfaces.d/usb0
,并写入auto usb0
allow-hotplug usb0
iface usb0 inet static
address 10.55.0.1
netmask 255.255.255.248
/root/usb.sh
,并写入#!/bin/bash
cd /sys/kernel/config/usb_gadget/
mkdir -p pi4
cd pi4
echo 0x1d6b > idVendor # Linux Foundation
echo 0x0104 > idProduct # Multifunction Composite Gadget
echo 0x0100 > bcdDevice # v1.0.0
echo 0x0200 > bcdUSB # USB2
echo 0xEF > bDeviceClass
echo 0x02 > bDeviceSubClass
echo 0x01 > bDeviceProtocol
mkdir -p strings/0x409
echo "fedcba9876543211" > strings/0x409/serialnumber
echo "Ben Hardill" > strings/0x409/manufacturer
echo "PI4 USB Device" > strings/0x409/product
mkdir -p configs/c.1/strings/0x409
echo "Config 1: ECM network" > configs/c.1/strings/0x409/configuration
echo 250 > configs/c.1/MaxPower
# Add functions here
# see gadget configurations below
# End functions
mkdir -p functions/ecm.usb0
HOST="00:dc:c8:f7:75:14" # "HostPC"
SELF="00:dd:dc:eb:6d:a1" # "BadUSB"
echo $HOST > functions/ecm.usb0/host_addr
echo $SELF > functions/ecm.usb0/dev_addr
ln -s functions/ecm.usb0 configs/c.1/
udevadm settle -t 5 || :
ls /sys/class/udc > UDC
ifup usb0
service dnsmasq restart
/root/usb.sh
设置为可执行,chmod +x /root/usb.sh
。/etc/rc.local
文件的exit 0
之前添加/root/usb.sh
。