add USBNET Support in Kernel and OpenSSH access (Feature #627)


Added by Tom King about 3 years ago. Updated about 3 years ago.


Status:In Progress Start date:09/20/2014
Priority:Normal Due date:
Assignee:S. Lockwood-Childs % Done:

0%

Category:System Services
Target version:Later

Description

Add USBNET support as a USB Gadget, make OpenSSH default

IP: 192.168.7.3
NM: 255.255.255.0
GW 192.168.7.3

Add Settings app section for OpenSSH Password.


History

Updated by Tom King about 3 years ago

Instead of Settings App support just use the terminal to set Password.

I think we should still support a default IP.

T

Updated by S. Lockwood-Childs about 3 years ago

In android kernels, g_android usb gadget driver includes rndis ethernet among available functions. Not that rndis is a good usbnet (it is the worst usbnet for Linux hosts, being a secret spec owned by Microsoft), but at least it is already available. Just need android-gadget-setup to turn on rndis as well as adb.

I looked into letting connman manage the rndis connection instead of blacklisting it per the current /etc/connman/main.conf but that didn't turn out so well -- connman didn't want to bring rndis0 up as just a local net, instead interfered with a previously connected wireless connection. Leaving the blacklist and adding a new script and systemd unit to configure rndis seems best.

Since g_android is built in rather than a module (confirmed on my touchpad, and linux-lg-mako/defconfig also shows CONFIG_USB_G_ANDROID=y) the rndis MAC address is either
  • randomly generated on every boot
  • assigned to a fixed by hardcoding a MAC address into the boot parameters
Having to set the MAC from boot parameters is not appealing, but having the MAC change on every boot will trick some hosts into thinking there are a million different usbnet adapters. Thus rndis0 configure script should try to make the MAC address sticky, so each LuneOS device gets a unique but unchanging MAC:
  • on initial boot, create config file with randomly chosen MAC
  • on subsequent boots, use 'ip set link' to switch back to stored MAC

Updated by S. Lockwood-Childs about 3 years ago

Where do we want to put a usbnet configure script + systemd unit? Is there an existing package where it would sensibly fit in?

Updated by Simon Busch about 3 years ago

The primary configuration point for this should be the devmode service (see https://github.com/webOS-ports/org.webosports.service.devmode). It should support the following options:

- set password for default ssh username
- set device IP address

Look at the options Sailfish OS gives you for the developer mode: http://blog.hardcodes.de/images/93.jpg

On the lower levels the gadget is configured on the Android side through the property system. Look at https://github.com/webOS-ports/android_device_lge_mako/blob/wop-11.0/init.mako.usb.rc and https://android.googlesource.com/platform/system/core/+/master/rootdir/init.usb.rc for available options.

To set one of the options use

$ getprop sys.usb.config
$ setprop sys.usb.config adb,mtp

To this property over ls2 we have the android property service (see https://github.com/webOS-ports/android-property-service) which is currently missing support for setting a property.

When the devmode is disabled we need to also disable the rndis mode. Sadly we can't do the same here as we do for adb right (just disable the adbd service) and have to remove it completely from the gadget configuration to prevent a usbnet interface appear on the user PC side.

For devices where the android property system isn't available we can abstract this later through the devmode service in some way but lets concentrate on what we currently have.

For the IP configuration of the rndis0 interface we should be able to use connman for that. If I remember well we have to place a specific file in /var/lib/connman with the configuration for the interface. Furthermore we need to run a tiny dhcp server on the interface so client PCs can easily obtain an IP address for the usbnet interface.

For the MAC address that sounds good but we need to integrate it somehow with the things above as the rdnis interface might go away when we change the gadget configuration.

Updated by S. Lockwood-Childs about 3 years ago

Simon Busch wrote:

For the IP configuration of the rndis0 interface we should be able to use connman for that. If I remember well we have to place a specific file in /var/lib/connman with the configuration for the interface. Furthermore we need to run a tiny dhcp server on the interface so client PCs can easily obtain an IP address for the usbnet interface.

Actually, connman does not support that use-case yet

# hand-edited config
cat /etc/connman/main.conf
[General]
DefaultAutoConnectTechnologies=ethernet,wifi,cellular,gadget
PreferredTechnologies=ethernet,wifi,cellular,gadget
NetworkInterfaceBlacklist = p2p,usb,rmnet,ifb # don't blacklist rndis

systemctl restart connman.service

connmanctl tether gadget on
Error enabling gadget tethering: Not supported

SERVICE=$(connmanctl services | grep -o "gadget_.*")
connmanctl config $SERVICE --ipv4 manual 192.168.7.3 255.255.255.0 
connmanctl config $SERVICE --autoconnect yes
Error gadget_1e9ad079f6a5_usb: Invalid service

connman doesn't want to use rndis0 for tethering (which is what it calls running a little dhcp server on the interface) and it doesn't want to autoconnect it, so the interface just stays down unless I manually connect it... where "connect" command seems to mean pick as the primary internet connection in connman-speak, so my wireless goes down at that point.

Unless someone else manages to get connman to cooperate better, I'm assuming we need to leave usb gadget blacklisted by connman and configure it with a separate mechanism. For dhcp setting, I'd use busybox udhcpd because that's already installed and this use-case is suitably dirt-simple.

Updated by Tom King about 3 years ago

  • Status changed from New to In Progress

Updated by Simon Busch about 3 years ago

Please ignore my former comment about using the android property system for this. We should not do that and instead extend the android-gadget-setup script. Jolla did that similar for Sailfish (see https://github.com/mer-hybris/hybris-boot/blob/hybris-10.1/init-script#L168). Btw that is the point where we should name our device a "LuneOS" device.

To get the default android property configuration unset we need to revert https://github.com/webOS-ports/android_system_core/commit/c9931bcc58dd3073c923afa9d39387487c7164e1 and make sure the android-gagdet-setup script is started independent of adbd. A separate package for this would be an option.

I will look into the connman configuration for the gadget as I know that was possible some time ago.

Updated by S. Lockwood-Childs about 3 years ago

Excellent -- design-wise it seems cleaner to have configuration stay on the Linux side as much as possible, using the android LXC only where clearly warranted (e.g. touchscreen driver).

I see devmode service is currently using files as flags for enable/disable of options. I'd like to switch that to a config file under /etc, so that it will be nicely extensible for those upcoming usbnet options for devmode. The config file would be written only by devmode service, but also read by systemd jobs configuring usbnet and adb, which would get run at bootup to apply the saved state as well as being called by devmode to apply new settings after a change.

Configs in /etc/palm are a mixture of .conf and .json... would INI-style .conf file be the right format to use for a new devmode config?

Updated by Simon Busch about 3 years ago

We have to place the conf file in /var as /etc isn't possible for a read-write file once we go over to have a read-only rootfs.

Also available in: Atom PDF