helloSystem / ISO

helloSystem Live and installation ISO
https://github.com/helloSystem/
BSD 3-Clause "New" or "Revised" License
805 stars 59 forks source link

Make mobile phone (e.g., Android) USB tethering "just work" #436

Closed louies0623 closed 1 year ago

louies0623 commented 1 year ago

When the mobile phone is connected to the computer with usb tethering, it does not working the computer to connect to the network.

probonopd commented 1 year ago

Can you please provide specifics: Android/iOS version? Do you see anything related to it when you type dmesg?

louies0623 commented 1 year ago

Galaxy A70, android 11, No

probonopd commented 1 year ago

Please check

https://docs.freebsd.org/en/books/handbook/advanced-networking/#network-usb-tethering

probonopd commented 1 year ago

I wonder whether we should set all of

if_urndis_load="YES"
if_cdce_load="YES"
if_ipheth_load="YES"

by default...

louies0623 commented 1 year ago

Haven't work.

probonopd commented 1 year ago

Here is a Hardware Probe of someone who is using an Android phone connected via USB and using dhclient ue0:

https://bsd-hardware.info/?probe=8ae819f673

Note the SOV41 RNDIS Communications Control RNDIS Ethernet Data.

https://www.freebsd.org/cgi/man.cgi?query=urndis&sektion=4

So it seems we have at least some support for Android USB tethered phones.

probonopd commented 1 year ago

Tried this, it works for me with an Android phone

Note that this works not only for using cellular but also for using the Android device to access WLAN, which might come handy in situations where the WLAN hardware on your device is not supported by FreeBSD yet.

probonopd commented 1 year ago

Now the question is, how can we automate all of this so that no commands need to be typed in by the user?

For all kernel modules that are not essential for mounting the root device use kld_list, because

kld_list (str) A list of kernel modules to load right after the local disks are mounted. Loading modules at this point in the boot process is much faster than doing it via /boot/loader.conf for those modules not necessary for mounting local disk.

probonopd commented 1 year ago

Inspecting what udev does when a tethering device is attached with sudo service devd stop && sudo devd -d 2>&1 | grep Executing, then switing on tethering on the Android device shows:

Executing '/etc/pccard_ether $'ue0' start'
Executing '/usr/libexec/hyperv/hyperv_vfattach $'ue0' 0'

So what is missing is sudo service dhclient quietstart ue0. To change that, create /usr/local/etc/devd/android_tethering.conf with the following content (tested):

# DHCP for USB Ethernet devices, e.g., Android phones with USB Tethering
notify 100 {
        match "system"          "ETHERNET";
        match "subsystem"       "(ue)[0-9]+";
        match "type"            "IFATTACH";
        action "/usr/sbin/service dhclient quietstart $subsystem";
};

For iOS devices it may be more complicated, as it may be necessary to run usbmuxd(1) (from comms/usbmuxd): https://man.freebsd.org/cgi/man.cgi?query=if_ipheth&sektion=4.