cdc-wdm support now added in AOSP Hikey

Recently I was trying to use my QMI and MBIM based modems in AOSP, with no luck: no cdc-wdm device was available in /dev/ after modem plugging, apparently without any kernel error.

First guess was lack of cdc-wdm device driver in my kernel build, but, after checking, that was not the issue, since the network interfaces of the modem were properly created. So what?

cdc-wdm supported in AOSP Hikey

Where is cdc-wdm ?

Nowadays in common Linux distributions the device nodes management is taken care by udev, which collects kernel events and use them according to a set of rules for doing its job (for a more detailed description of what udev is and does see Wikipedia article).

But Android does not use udev, so chances are that there’s something missing in Android hotplug device manager, namely init.

init code can be found in system/core/init: a nice explanation of how init behaves in regard to device management can be found in the initial comments at ueventd.cpp.

Starting from this file and following the logic flow, we can see that the device events are managed by function HandleDeviceEvent in devices.cpp. The part of this function related to the usb subsystem considers only
the devices found inside /sys/class/usb and all the rest is discarded: we found the cause of the problem.

Due to this change in the kernel, cdc-wdm devices are placed inside /sys/class/usbmisc, so they are not considered by init.

My first try to fix this was to hardcode the usbmisc subsystem in HandleDeviceEvent: this worked properly, but there is a better solution, as was instructed by the the init maintainer, since it is possible to dinamically add subsystem through the ueventd.rc files.

The discussion eventually led to this change that adds cdc-wdm (and other devices under misc) support in Hikey.

Note that the change needs also a fix on init related to the susbsystem name parsing and another change that makes the subsystems list to be analyzed before doing usb subsystem logic: you can find them here.

Why only Hikey?

Hikey is a development board so it is the perfect target for this kind of modems, while it is basically useless in all the other “fixed” devices available in AOSP (e.g. Nexus).

Note that the cdc-wdm device is useful when the modem is integrated through USB and uses the kernel driver: this is common for systems that need cellular features, but are not strictly phones. SoCs that have the application processor and radio together usually have different kind of devices, see for example system/core/rootdir/ueventd.rc:

/dev/smd0                 0640   radio      radio
/dev/qmi                  0640   radio      radio
/dev/qmi0                 0640   radio      radio
/dev/qmi1                 0640   radio      radio
/dev/qmi2                 0640   radio      radio