Skip to content

Commit

Permalink
WiP adding Android tethering with generic instructions at https://wik…
Browse files Browse the repository at this point in the history
…i.gentoo.org/wiki/Android_USB_tethering

First attempt with gadget failed https://forums.gentoo.org/viewtopic-t-1095940.html

Works with latest GrapheneOS (and expected all supported devices)

TODO:
- network-init-recovery:
  - time sync is failing against DNS address (phone doesn't provide) and talking to ntp.pool.org either
  - Prompts to for user to connect phone and instructions on how to setup phone should be given
modules/linux + board config:
- maybe ANDROID_TETHER is too generic and should be called GRAPHENEOS_TETHER instead
general:
- network-init-recovery is one size fits all.
  - Maybe put calls into functions and permit passing validating existing interfaces as arguments

Otherwise we have network when network-init-recovery is called and phone is plugged in USB tether mode

Goal of all this is to be able to download and boot TinyCore + custom package
(wyng: never forget)
  • Loading branch information
tlaurion committed Apr 22, 2023
1 parent 400f71d commit bd228c5
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 28 deletions.
1 change: 1 addition & 0 deletions boards/x230-maximized/x230-maximized.config
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CONFIG_LINUX_CONFIG=config/linux-x230-maximized.config
#Additional hardware support
CONFIG_LINUX_USB=y
CONFIG_LINUX_E1000E=y
CONFIG_ANDROID_TETHERING=y

CONFIG_CRYPTSETUP2=y
CONFIG_FLASHROM=y
Expand Down
47 changes: 46 additions & 1 deletion config/linux-x230-maximized.config
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,7 @@ CONFIG_BLK_DEV_RAM_SIZE=65536
#
# CONFIG_BLK_DEV_NVME is not set
# CONFIG_NVME_FC is not set
# CONFIG_NVME_TARGET is not set
# end of NVME Support

#
Expand Down Expand Up @@ -1244,7 +1245,48 @@ CONFIG_E1000E_HWTS=y

# CONFIG_PPP is not set
# CONFIG_SLIP is not set
# CONFIG_USB_NET_DRIVERS is not set
CONFIG_USB_NET_DRIVERS=m
# CONFIG_USB_CATC is not set
# CONFIG_USB_KAWETH is not set
# CONFIG_USB_PEGASUS is not set
# CONFIG_USB_RTL8150 is not set
# CONFIG_USB_RTL8152 is not set
# CONFIG_USB_LAN78XX is not set
CONFIG_USB_USBNET=m
# CONFIG_USB_NET_AX8817X is not set
# CONFIG_USB_NET_AX88179_178A is not set
CONFIG_USB_NET_CDCETHER=m
CONFIG_USB_NET_CDC_EEM=m
# CONFIG_USB_NET_CDC_NCM is not set
# CONFIG_USB_NET_HUAWEI_CDC_NCM is not set
# CONFIG_USB_NET_CDC_MBIM is not set
# CONFIG_USB_NET_DM9601 is not set
# CONFIG_USB_NET_SR9700 is not set
# CONFIG_USB_NET_SR9800 is not set
# CONFIG_USB_NET_SMSC75XX is not set
# CONFIG_USB_NET_SMSC95XX is not set
# CONFIG_USB_NET_GL620A is not set
# CONFIG_USB_NET_NET1080 is not set
# CONFIG_USB_NET_PLUSB is not set
# CONFIG_USB_NET_MCS7830 is not set
CONFIG_USB_NET_RNDIS_HOST=m
CONFIG_USB_NET_CDC_SUBSET=m
# CONFIG_USB_ALI_M5632 is not set
# CONFIG_USB_AN2720 is not set
# CONFIG_USB_BELKIN is not set
# CONFIG_USB_ARMLINUX is not set
# CONFIG_USB_EPSON2888 is not set
# CONFIG_USB_KC2190 is not set
# CONFIG_USB_NET_ZAURUS is not set
# CONFIG_USB_NET_CX82310_ETH is not set
# CONFIG_USB_NET_KALMIA is not set
# CONFIG_USB_NET_QMI_WWAN is not set
# CONFIG_USB_NET_INT51X1 is not set
# CONFIG_USB_IPHETH is not set
# CONFIG_USB_SIERRA_NET is not set
# CONFIG_USB_VL600 is not set
# CONFIG_USB_NET_CH9200 is not set
# CONFIG_USB_NET_AQC111 is not set
# CONFIG_WLAN is not set

#
Expand Down Expand Up @@ -2479,6 +2521,7 @@ CONFIG_NVMEM=y
# CONFIG_SLIMBUS is not set
# CONFIG_INTERCONNECT is not set
# CONFIG_COUNTER is not set
# CONFIG_MOST is not set
# end of Device Drivers

#
Expand All @@ -2501,6 +2544,7 @@ CONFIG_FS_MBCACHE=y
# CONFIG_JFS_FS is not set
# CONFIG_XFS_FS is not set
# CONFIG_GFS2_FS is not set
# CONFIG_OCFS2_FS is not set
# CONFIG_BTRFS_FS is not set
# CONFIG_NILFS2_FS is not set
# CONFIG_F2FS_FS is not set
Expand Down Expand Up @@ -2627,6 +2671,7 @@ CONFIG_NLS_ISO8859_1=y
# CONFIG_NLS_MAC_ROMANIAN is not set
# CONFIG_NLS_MAC_TURKISH is not set
CONFIG_NLS_UTF8=y
# CONFIG_DLM is not set
CONFIG_UNICODE=y
# CONFIG_UNICODE_NORMALIZATION_SELFTEST is not set
# end of File systems
Expand Down
73 changes: 46 additions & 27 deletions initrd/bin/network-init-recovery
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,24 @@ for module in `echo $network_modules`; do
fi
done

if [ -e /sys/class/net/eth0 ]; then
#Tethering over Android 11+ PoC
if [ -e /lib/modules/rndis_host.ko ]; then
#first enable USB controllers
enable_usb
network_modules="mii usbnet cdc_eem cdc_ether rndis_host"

for module in `echo $network_modules`; do
if [ -f /lib/modules/$module.ko ]; then
insmod /lib/modules/$module.ko
fi
done
#other prep needed
fi

if [ -e /sys/class/net/usb0 ]; then
echo "Tethering on..."
dev=usb0
elif [ -e /sys/class/net/eth0 ]; then
#Randomize eth0 MAC address of maximized boards
if echo "$CONFIG_BOARD" | grep -q maximized; then
ifconfig eth0 down
Expand All @@ -28,34 +45,36 @@ if [ -e /sys/class/net/eth0 ]; then
# Set up static IP
if [ ! -z "$CONFIG_BOOT_STATIC_IP" ]; then
ifconfig eth0 $CONFIG_BOOT_STATIC_IP
#Get ip from DHCP
elif [ -e /sbin/udhcpc ];then
if udhcpc -T 1 -q; then
if [ -e /sbin/ntpd ]; then
DNS_SERVER=$(grep nameserver /etc/resolv.conf|awk -F " " {'print $2'})
killall ntpd 2&>1 > /dev/null
if ! ntpd -d -N -n -q -p $DNS_SERVER > /dev/ttyprintk; then
if ! ntpd -d -d -N -n -q -p ntp.pool.org> /dev/ttyprintk; then
echo "NTP sync unsuccessful." > /dev/tty0
fi
fi
dev=eth0
fi

#Get ip from DHCP
if [ -e /sbin/udhcpc ];then
if udhcpc -T 1 -i $dev -q; then
if [ -e /sbin/ntpd ]; then
DNS_SERVER=$(grep nameserver /etc/resolv.conf|awk -F " " {'print $2'})
killall ntpd 2&>1 > /dev/null
if ! ntpd -d -N -n -q -p $DNS_SERVER > /dev/ttyprintk; then
if ! ntpd -d -d -N -n -q -p ntp.pool.org> /dev/ttyprintk; then
echo "NTP sync unsuccessful." > /dev/tty0
#TODO: clean time sync. Not always successful
fi
hwclock -w
echo "" > /dev/tty0
date=`date "+%Y-%m-%d %H:%M:%S %Z"`
echo "Time: $date" > /dev/tty0
fi
fi
fi

ifconfig eth0 > /dev/ttyprintk

if [ -e /bin/dropbear ]; then
# Set up the ssh server, allow root logins and log to stderr
if [ ! -d /etc/dropbear ]; then
mkdir /etc/dropbear
hwclock -w
echo "" > /dev/tty0
date=`date "+%Y-%m-%d %H:%M:%S %Z"`
echo "Time: $date" > /dev/tty0
fi
dropbear -B -R 2>/dev/ttyprintk
fi
fi

if [ -e /bin/dropbear ]; then
# Set up the ssh server, allow root logins and log to stderr
if [ ! -d /etc/dropbear ]; then
mkdir /etc/dropbear
fi
echo "" > /dev/tty0
ifconfig eth0 | head -2 > /dev/tty0
dropbear -B -R 2>/dev/ttyprintk
fi
echo "" > /dev/tty0
ifconfig > /dev/tty0
18 changes: 18 additions & 0 deletions modules/linux
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,24 @@ linux_modules-$(CONFIG_LINUX_USB) += drivers/usb/storage/usb-storage.ko
#USB modules when a USB keyboard is defined in board config
linux_modules-$(CONFIG_USB_KEYBOARD) += drivers/hid/usbhid/usbhid.ko

#USB modules for Android USB Internet Tethering
#Non working https://forums.gentoo.org/viewtopic-t-1095940.html
#linux_modules-$(CONFIG_ANDROID_TETHERING) += drivers/usb/gadget/udc/udc-core.ko
#linux_modules-$(CONFIG_ANDROID_TETHERING) += drivers/usb/gadget/function/usb_f_ecm.ko
#linux_modules-$(CONFIG_ANDROID_TETHERING) += drivers/usb/gadget/function/u_ether.ko
#linux_modules-$(CONFIG_ANDROID_TETHERING) += drivers/usb/gadget/function/usb_f_ecm_subset.ko
#linux_modules-$(CONFIG_ANDROID_TETHERING) += drivers/usb/gadget/function/usb_f_eem.ko
#linux_modules-$(CONFIG_ANDROID_TETHERING) += drivers/usb/gadget/function/usb_f_rndis.ko
#linux_modules-$(CONFIG_ANDROID_TETHERING) += drivers/usb/gadget/legacy/g_ether.ko
#linux_modules-$(CONFIG_ANDROID_TETHERING) += drivers/usb/gadget/libcomposite.ko
#linux_modules-$(CONFIG_ANDROID_TETHERING) += fs/configfs/configfs.ko
#Testing https://wiki.gentoo.org/wiki/Android_USB_tethering general instructions:
linux_modules-$(CONFIG_ANDROID_TETHERING) += drivers/net/usb/cdc_eem.ko
linux_modules-$(CONFIG_ANDROID_TETHERING) += drivers/net/usb/rndis_host.ko
linux_modules-$(CONFIG_ANDROID_TETHERING) += drivers/net/usb/cdc_ether.ko
linux_modules-$(CONFIG_ANDROID_TETHERING) += drivers/net/usb/usbnet.ko
linux_modules-$(CONFIG_ANDROID_TETHERING) += drivers/net/mii.ko

# NVMe driver for winterfell and other servers
linux_modules-$(CONFIG_LINUX_NVME) += drivers/nvme/host/nvme.ko
linux_modules-$(CONFIG_LINUX_NVME) += drivers/nvme/host/nvme-core.ko
Expand Down

0 comments on commit bd228c5

Please sign in to comment.