ModemManager (and latest udev) in OpenWRT

So I wanted to have ModemManager in OpenWRT to handle my mobile broadband connections.

OpenWRT has its own built-in support to handle mobile broadband modems of different types, mainly for AT-controlled modems, but also for QMI-controlled modems through libqmi and qmicli (now available in upstream OpenWRT). But hell, why not package ModemManager for that work, and provide a unified single DBus API to control any kind of mobile broadband modem in the same way?

ModemManager itself isn’t a very complex daemon, so it doesn’t have many dependencies, just: glib/gio, dbus, udev/gudev and libqmi. In the world of OpenWRT, though, none of these are blessed dependencies, as they have a lightweight replacement for everything: libubox (instead of glib), ubus (instead of dbus) and hotplug2 (instead of udev). These replacements target minimal embedded systems, and are perfectly integrated into OpenWRT and provide the building blocks of other core software like the netifd network interface daemon.

Still, having ModemManager available as a OpenWRT package seems like a good idea if you’re not very constrained by the hardware you’re going to use. If you are building a system which should support multiple broadband modems from different vendors, or just building a base system for one specific modem model but leaving the door open to change the model in the future, ModemManager seems a good choice.

 

systemd’s udev in OpenWRT

Since April 2012, udev sources are now integrated within the systemd source code. And that means that udev packages in OpenWRT would need to get updated in order to get built from that new repository. systemd provides some hints on what would be the best way of creating a minimal systemd build which can be used to gather just the udev-specific libraries and binaries. The easiest way involves compiling the whole systemd package with all optional features disabled, and that would get us not only systemd (which we won’t need), but also udevd and libudev. Easy, yes, but then we have some issues in the environment that we would need to handle…

In OpenWRT, the udev package is available in the trunk repository, where only the core OpenWRT packages are given. But in order to get the new udev compiled out of systemd we end up needing additional dependencies (dbus, libcap) which are only available in the packages repository. Moreover, if you also want to compile the glib-based gudev library, glib is also needed, which is also only available in the packages repository. And you cannot require a package from trunk to depend on a package from packages, so… ended up creating a new systemd-udev package within the packages repository.

As I was targeting the uClibc toolchain, I also ended up requiring some additional patches both in uClibc (e.g. to enable utmpx) and systemd to get the thing properly compiled. The patches applied in the systemd sources are just to handle missing features in uClibc (execvpe, secure_getenv…). Whenever uClibc includes those, we’ll be able to remove those patches.

 

ModemManager in OpenWRT

I prepared an easy setup of ModemManager packaging in OpenWRT, where all possible plugins get compiled. It wouldn’t have been difficult to allow selecting via configuration which plugins to get compiled, but didn’t want to spend time on that.

I sent the patches to the OpenWRT mailing list already, but if you want to give it a quick try, you can just clone the Lanedo OpenWRT repositories (trunk and packages) from gitorious.org:

$> git clone git://gitorious.org/lanedo/openwrt.git
$> git clone git://gitorious.org/lanedo/openwrt-packages.git

You’ll want both ‘modemmanager-support‘ branches in those git repositories.

ModemManager will be available under the ‘Network’ section in the OpenWRT build configuration; but only after explicitly selecting the following kernel modules (all under Kernel Modules/USB support):

  • kmod-usb-net
  • kmod-usb-serial
  • kmod-usb-acm

Once all above are enabled, ModemManager can be selected, and it will itself pull all its other required dependencies (systemd-udev, glib, dbus, libqmi…).

 

No LuCI? No connection manager?

Well, not yet :). If you want to use ModemManager you still need to have your own connection manager software to manage the connectivity. ModemManager will get your mobile broadband modem connected, but you still need to either call pppd or setup the wwan interface yourself (depending on the data port type). This is really not a big deal; and you can just setup a shell script using the provided mmcli command line interface to talk to ModemManager.

Posted on February 14, 2013, in FreeDesktop Planet, Packaging, Planets and tagged , , , . Bookmark the permalink. 24 Comments.

  1. Hi, Aleksander !
    Thanks for libqmi first of all! 🙂
    I’ve tried to compile ModemManager Edition from your git branches. And I’ve got the same mistacke twice:

     make[7]: Leaving directory `/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt/build_dir/target-mipsel_r2_uClibc-0.9.33.2/modemmanager-2013-02-13/docs'
    make[6]: Leaving directory `/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt/build_dir/target-mipsel_r2_uClibc-0.9.33.2/modemmanager-2013-02-13/docs'
    make[5]: *** [all-recursive] Error 1
    make[5]: Leaving directory `/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt/build_dir/target-mipsel_r2_uClibc-0.9.33.2/modemmanager-2013-02-13'
    make[4]: *** [all] Error 2
    make[4]: Leaving directory `/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt/build_dir/target-mipsel_r2_uClibc-0.9.33.2/modemmanager-2013-02-13'
    make[3]: *** [/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt/build_dir/target-mipsel_r2_uClibc-0.9.33.2/modemmanager-2013-02-13/.built] Error 2
    make[3]: Leaving directory `/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt/lanedo-openwrt-packages/net/modemmanager'
    make[2]: *** [package/feeds/packages/modemmanager/compile] Error 2
    make[2]: Leaving directory `/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt'
    make[1]: *** [/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt/staging_dir/target-mipsel_r2_uClibc-0.9.33.2/stamp/.package_compile] Error 2
    make[1]: Leaving directory `/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt'
    make: *** [world] Ошибка 2 
    ruslan@debian:~/OpenWRT_Lan-ModemManager/lanedo-openwrt$ 
    

    what could be the problem? What system do you use for compilation? I use Debian GNU/Linux 6.0.3 (squeeze)
    Thanks
    Ruslan

  2. I’m using Fedora 18. Can you try to compile with “make V=s”?

  3. Of course, yes, but here is the same result ( I’ve renew system to Debian 6.0.6):

    make[6]: Leaving directory `/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt/build_dir/target-mipsel_r2_uClibc-0.9.33.2/modemmanager-2013-02-13/docs/reference'
    Making all in man
    make[6]: Entering directory `/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt/build_dir/target-mipsel_r2_uClibc-0.9.33.2/modemmanager-2013-02-13/docs/man'
    make[6]: Nothing to be done for `all'.
    make[6]: Leaving directory `/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt/build_dir/target-mipsel_r2_uClibc-0.9.33.2/modemmanager-2013-02-13/docs/man'
    make[6]: Entering directory `/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt/build_dir/target-mipsel_r2_uClibc-0.9.33.2/modemmanager-2013-02-13/docs'
    make[6]: Nothing to be done for `all-am'.
    make[6]: Leaving directory `/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt/build_dir/target-mipsel_r2_uClibc-0.9.33.2/modemmanager-2013-02-13/docs'
    make[5]: Leaving directory `/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt/build_dir/target-mipsel_r2_uClibc-0.9.33.2/modemmanager-2013-02-13/docs'
    make[4]: *** [all-recursive] Error 1
    make[4]: Leaving directory `/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt/build_dir/target-mipsel_r2_uClibc-0.9.33.2/modemmanager-2013-02-13'
    make[3]: *** [all] Error 2
    make[3]: Leaving directory `/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt/build_dir/target-mipsel_r2_uClibc-0.9.33.2/modemmanager-2013-02-13'
    make[2]: *** [/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt/build_dir/target-mipsel_r2_uClibc-0.9.33.2/modemmanager-2013-02-13/.built] Error 2
    make[2]: Leaving directory `/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt/lanedo-openwrt-packages/net/modemmanager'
    make[1]: *** [package/feeds/packages/modemmanager/compile] Error 2
    make[1]: Leaving directory `/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt'
    make: *** [package/modemmanager/compile] Ошибка 2
    ruslan@debian:~/OpenWRT_Lan-ModemManager/lanedo-openwrt$ 
    

    I’ve Fedora on my desktop, I’ll try to renew it to 18 and compile.

    Thanks

  4. Well, I’ve tried to compile under Fedora 18 & get the same mistacke. IMHO the problem is here:
    [/code]
    OpenWrt-libtool: link: ( cd “.libs” && rm -f “mm-test-pppd-plugin.la” && ln -s “../mm-test-pppd-plugin.la” “mm-test-pppd-plugin.la” )
    mipsel-openwrt-linux-uclibc-gcc -DHAVE_CONFIG_H -I. -I.. -I/usr/include/gudev-1.0 -I/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt/staging_dir/target-mipsel_r2_uClibc-0.9.33.2/usr/include/glib-2.0 -I/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt/staging_dir/target-mipsel_r2_uClibc-0.9.33.2/usr/lib/glib-2.0/include -I/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt/staging_dir/target-mipsel_r2_uClibc-0.9.33.2/usr/include -I/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt/staging_dir/target-mipsel_r2_uClibc-0.9.33.2/include -I/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt/staging_dir/toolchain-mipsel_r2_gcc-4.6-linaro_uClibc-0.9.33.2/usr/include -I/home/ruslan/OpenWRT_Lan-ModemManager/lanedo-openwrt/staging_dir/toolchain-mipsel_r2_gcc-4.6-linaro_uClibc-0.9.33.2/include -Wall -Werror -std=gnu89 -Os -pipe -mips32r2 -mtune=mips32r2 -fno-caller-saves -mno-branch-likely -fhonour-copts -Wno-error=unused-but-set-variable -msoft-float -Wmissing-declarations -Wmissing-prototypes -Wdeclaration-after-statement -Wno-unused-parameter -Wno-sign-compare -fno-strict-aliasing -Wno-deprecated-declarations -Wno-unused-but-set-variable -MT lsudev-lsudev.o -MD -MP -MF .deps/lsudev-lsudev.Tpo -c -o lsudev-lsudev.o `test -f ‘lsudev.c’ || echo ‘./’`lsudev.c
    [b]lsudev.c:20:25: fatal error: gudev/gudev.h: No such file or directory[/b]
    compilation terminated.
    make[5]: *** [lsudev-lsudev.o] Error 1
    [/code] 😦

    IMHO needs to check Makefile of [b]system-udev [/b]

  5. Yes! I’ve compiled it. The problem was in /system-udev/Makefile
    Here is my patch

    http://pastebin.com/XiXrVECb

  6. Great!

  7. Well. Next problem 😦

    root@OpenWrt:~# mmcli -m 0 --simple-connect="apn=yota.ru"
    error: couldn't find the ModemManager process in the bus
    

    Modem E392 is connected, driver qmi_wwan is in place.
    Full log of ps and /sys/kernel/debug/usb/devices here:

    http://pastebin.com/ecTCMwXd

  8. You need to run udevd, dbus and only then ModemManager.

  9. Something misteriously 🙂

    root@OpenWrt:~# udevd
    bind failed: No such file or directory
    error binding udev control socket
    error binding udev control socket
    root@OpenWrt:~# dbus
    -ash: dbus: not found
    

    Here ls :
    http://pastebin.com/V7qHV3W3
    Could you show your .config file?

  10. I guess you’ll need to see how to enable udevd and dbus in your installation…

  11. Right you are! I’ll do 🙂

    Anyway the firmware is rather big in result. IMHO glib2 is heavy lib for embedded systems. For example its impossible to install something like this one to 4 Mb flash router:( Is it difficult to unbind libqmi and modemmanager from glib2? And possible?

  12. Nothing in life is impossible 🙂 But you wouldn’t want to do that, it would be redoing it from scratch. If you’re targeting a 4MB flash image, you may really skip all these, truth be told…

  13. My target is 8Mb. It was just question “by the way” 🙂 And one more… would you plan to port libmbim to openwrt?

  14. Whenever libmbim is ready, sure, why not 🙂

  15. It’s not ready yet, isn’ it? Hm… I’ve tried to compile it for OpenWRT, but got mistackes. Under Fedora 18 it was O.K., but just after installing glib2-devel 🙂

  16. libmbim is currently just an initial effort, it’s not really fully usable yet… help welcome 🙂

  17. Hello, Aleksander!
    I’ve tried to compile libmbim for OpenWRT, (I know cdc-mbim will bee just in kernel_3.8, I’ve find patches of Bjorn Mork :), but got this mistacke:

    checking for LIBMBIM_GLIB... yes
    checking for MBIMCLI... yes
    configure: creating ./config.status
    config.status: error: cannot find input file: `Makefile.in'
    make[2]: *** [/home/ruslan/OpenWRT_Lanedo_MM/lanedo-openwrt/build_dir/target-mipsel_r2_uClibc-0.9.33.2/libmbim-0.0.1/.configured_] Error 1
    make[2]: Leaving directory `/home/ruslan/OpenWRT_Lanedo_MM/lanedo-openwrt/custom-feed/libmbim'
    make[1]: *** [package/feeds/custom/libmbim/compile] Error 2
    make[1]: Leaving directory `/home/ruslan/OpenWRT_Lanedo_MM/lanedo-openwrt'
    make: *** [package/libmbim/compile] Ошибка 2
    [ruslan@localhost lanedo-openwrt]$ 
    

    So, I’ve reconfigured the package, and it was compiled successfully

    Makefile is here:
    http://pastebin.com/5KkN2rdM

    Perhaps, you could change your Makefile for OpenWRT tools?

  18. Ruslan :

    Perhaps, you could change your Makefile for OpenWRT tools?

    Not sure what you mean with that; do you want me to suggest libmbim to OpenWRT already?

  19. Oh, no! 🙂 Not now at least. I’ve just wanted to talk, that I faced to problem while compiling this package. And temporary solved it by reconfiguring. But it’s not so good 🙂 Anyway, I’ve compiled it for OpenWRT and ported cdc-mbim driver to kernel 3.6.11. I think it’s enough for tests. But if you find time, try to compile libmbim for OpenWRT and see what’s wrong. 🙂 Thanks for your job and efforts!

  20. Thanks for the work! It’s working quite well. To fix the udev startup issue, you have to create the /run directory. Initially ModemManager refused to start as the file in /etc/dbus-1/system.d/org.freedesktop.ModemManager.conf was missing.

    Also the compilation depends on some host tools which were not defined (as in brought into the OpenWrt build and installed into $(STAGING_DIR)/host) so I had to install them myself. Namely libintl and gtk-doc… the latter could be avoided by not compiling docs and patching the config script to not check for the tools.

    All in all my jffs2 rootfs image was 5.4 megs which really isn’t that bad. Devices with <8MB are pretty rare nowadays and having full-featured modem support is pretty sweet.

    My only gripe is that my firmware "feels dirty" because it is running duplicate softwares. Hotplug2 and udev, ubus and dbus, etc… I understand why OpenWrt uses that software but it seems like trying to trim down udev and dbus would have been a better effort than rewriting from scratch. NIH syndrome for sure.

  21. Glad you made it work!

  22. I downloaded your openwrt and openwrt-packages repo and have modemmanager and systemd-udev compiling fine. my problem is after I run udev and dbus, modemmanager comes back with a name_lost_cb(): Could not acquire the ‘org.freedesktop.ModemManager1’ service name. I created a conf into /etc/dbus-1/system.d/ with no luck has anyone got this working perfectly?

    Great work BTW!

  23. I am trying to make the libmbim-1.8.0, getting error: ../../src/libmbim-glib/.libs/libmbim-glib.so: file not recognized: File format not recognized, I need some help here guys. Thank you so much. Ben

  1. Pingback: ModemManager in OpenWRT (take #2) | SIGQUIT

Leave a comment