74 lines
2.1 KiB
Plaintext
Executable File
74 lines
2.1 KiB
Plaintext
Executable File
#!/sbin/openrc-run
|
|
# OpenRC service for USB ConfigFS NCM Ethernet gadget (172.16.42.1/24).
|
|
|
|
description="Geminux USB NCM networking gadget"
|
|
|
|
G=/sys/kernel/config/usb_gadget/g1
|
|
|
|
depend() {
|
|
need localmount
|
|
after bootmisc
|
|
}
|
|
|
|
start() {
|
|
ebegin "Configuring Geminux USB NCM gadget"
|
|
mount -t configfs none /sys/kernel/config 2>/dev/null || true
|
|
if [ ! -d /sys/kernel/config/usb_gadget ]; then
|
|
ewarn "USB ConfigFS not available; skipping usb0 gadget"
|
|
eend 0
|
|
return 0
|
|
fi
|
|
|
|
for role_file in /sys/class/usb_role/*/role; do
|
|
[ -w "$role_file" ] || continue
|
|
if [ "$(cat "$role_file" 2>/dev/null || true)" = "none" ]; then
|
|
echo "device" > "$role_file" 2>/dev/null || true
|
|
fi
|
|
done
|
|
|
|
udc_name="$(ls -1 /sys/class/udc 2>/dev/null | head -n1 || true)"
|
|
if [ -z "$udc_name" ]; then
|
|
ewarn "No UDC controller present; skipping usb0 gadget"
|
|
eend 0
|
|
return 0
|
|
fi
|
|
|
|
mkdir -p "$G" "$G/strings/0x409" "$G/configs/c.1/strings/0x409" "$G/functions/ncm.usb0"
|
|
echo "0x1d6b" > "$G/idVendor"
|
|
echo "0x0104" > "$G/idProduct"
|
|
echo "0x0100" > "$G/bcdDevice"
|
|
echo "0x0200" > "$G/bcdUSB"
|
|
echo "Planet Computers" > "$G/strings/0x409/manufacturer"
|
|
echo "Gemini PDA Geminux USB NCM" > "$G/strings/0x409/product"
|
|
echo "geminux-x27" > "$G/strings/0x409/serialnumber"
|
|
echo "42:00:17:42:00:01" > "$G/functions/ncm.usb0/dev_addr" 2>/dev/null || true
|
|
echo "42:00:17:42:00:02" > "$G/functions/ncm.usb0/host_addr" 2>/dev/null || true
|
|
echo "NCM Network" > "$G/configs/c.1/strings/0x409/configuration"
|
|
echo 250 > "$G/configs/c.1/MaxPower"
|
|
ln -sfn "$G/functions/ncm.usb0" "$G/configs/c.1/ncm.usb0"
|
|
|
|
if [ -z "$(cat "$G/UDC" 2>/dev/null || true)" ]; then
|
|
echo "$udc_name" > "$G/UDC" 2>/dev/null || true
|
|
fi
|
|
|
|
i=0
|
|
while [ "$i" -lt 10 ] && ! ip link show usb0 >/dev/null 2>&1; do
|
|
usleep 100000 2>/dev/null || sleep 1
|
|
i=$((i + 1))
|
|
done
|
|
|
|
if ip link show usb0 >/dev/null 2>&1; then
|
|
ip addr replace 172.16.42.1/24 dev usb0 2>/dev/null || true
|
|
ip link set usb0 up 2>/dev/null || true
|
|
fi
|
|
eend 0
|
|
}
|
|
|
|
stop() {
|
|
ebegin "Stopping Geminux USB NCM gadget"
|
|
if [ -w "$G/UDC" ]; then
|
|
echo "" > "$G/UDC" 2>/dev/null || true
|
|
fi
|
|
eend 0
|
|
}
|