DBus Interface to MM and No Modems?

Dan Williams dcbw at redhat.com
Wed Jun 17 07:48:13 PDT 2015


On Wed, 2015-06-17 at 14:23 +0100, John Whitmore wrote:
> On Fri, Jun 12, 2015 at 09:50:32AM -0500, Dan Williams wrote:
> > On Fri, 2015-06-12 at 15:03 +0100, John Whitmore wrote:
> > > I'm going through the DBus documentation and can't seem to find what I'm
> > > looking for. Then perhaps what I'm looking for is not actually valid. 
> > > 
> > > The documentation goes through the creation of a connection but I'm at the
> > > step before that trying to find out how many, if any modems are actually
> > > connected. If there's none then that's fine I have nothing to do but how to
> > > determine that?
> > 
> > ModemManager uses the standard D-Bus "Object manager" interfaces as
> > described here:
> > 
> > http://www.freedesktop.org/software/ModemManager/api/latest/ref-dbus-standard-interfaces-objectmanager.html
> > 
> > which means you can get the list of modems by doing this:
> > 
> > sudo dbus-send --system --print-reply
> > --dest=org.freedesktop.ModemManager1 /org/freedesktop/ModemManager1
> > org.freedesktop.DBus.ObjectManager.GetManagedObjects
> > 
> > and that'll send you back a dict of the all modems managed by MM keyed
> > by object path.  For example:
> > 
> > method return sender=:1.5 -> dest=:1.139 reply_serial=2
> >    array [
> >       dict entry(
> >          object path "/org/freedesktop/ModemManager1/Modem/0"
> >          array [
> >             dict entry(
> >                string "org.freedesktop.ModemManager1.Modem"
> >                array [
> >                   dict entry(
> >                      string "Plugin"
> >                      variant                         string "Sierra"
> >                   )
> >                   dict entry(
> >                      string "PrimaryPort"
> >                      variant                         string "cdc-wdm0"
> >                   )
> >                   dict entry(
> >                      string "State"
> >                      variant                         int32 3
> >                   )
> > 
> > You can either grab the properties out of the dict here, or just use
> > this reply to build up the list of modem objects and query the state
> > later.  In this case, my modem is in state 3 (MM_MODEM_STATE_DISABLED)
> > because that's what the State property of the
> > org.freedesktop.ModemManager1.Modem interface is.  If the modem was
> > already connected, the org.freedesktop.ModemManager1.Modem.State
> > property would be either 10 (CONNECTING) or 11 (CONNECTED).
> > 
> > Here's a python example:
> > 
> > -----
> > import dbus, sys
> > 
> > bus = dbus.SystemBus()
> > proxy = bus.get_object("org.freedesktop.ModemManager1",
> > "/org/freedesktop/ModemManager1")
> > om = dbus.Interface(proxy, "org.freedesktop.DBus.ObjectManager")
> > 
> > states = { 10: "Connecting", 11: "Connected" }
> > 
> > modems = om.GetManagedObjects()
> > for mpath in modems.keys():
> >     modem_state =
> > modems[mpath]['org.freedesktop.ModemManager1.Modem']['State']
> >     try:
> >         state = states[modem_state]
> >     except KeyError:
> >         state = "Not connected"
> >     print "Modem object path: " + mpath + "  (" + state + ")"
> > -----
> > 
> > Let us know if any of this is unclear or if you've got more questions!
> > 
> > Dan
> > 
> > 
> 
> Thanks for all that, and sorry I've been distracted from this for a few
> days. Got back to it and have one good modem I'm working on and one modem I've
> not been able to modeswitch as yet. 
> 
> With the one that is switching I've got the DBus object. I was going to
> attempt to connect with the Simple DBus interface but I'm pulling back a
> SignalStrength of 0 so thought that might be to do with the current
> state. That I'm sure just means that I have to activate the radio on the
> device, so that gets into bearers and the like. So forget the Simple interface
> as I don't want to just connect. I want to enable radios check coverage and
> then connect.

A signal of '0' doesn't mean that you need to get into bearers, you just
need to 'enable' the modem.  ModemManager starts all modems in a
'disabled' state when they are recognized, and they must then be enabled
to become useful.  That basically means opening up the modem's ports,
setting up listeners for unsolicited messages (like SMS receipt, signal
strength indications, access technology change indications, operator
change indications, etc).  This is because it's pretty useless to have
all that stuff turned on and the modem powered up if no program actually
cares about it :)

Bearers only come into play when you want a data connection.

> All that means that I'd really like to use some of the enumerated types that
> the DBus interface defines but struggling to find how to get them and use
> them. So for example in your code you use states of {10: "Connecting", 11:
> "Connected"} How would I use the enumeration:
> 
> http://www.freedesktop.org/software/ModemManager/api/latest/ModemManager-Flags-and-Enumerations.html#MMModemState
> 
> I'm looking into DBus tutorials and they never seem to go over
> enumerations. Just using a bad search term I guess.

The enums are just numbers; so if (in the above example) you see that
the org.freedesktop.ModemManager1.Modem.State property is '10', you look
that up in the ModemManager D-Bus specification linked above and you
know that this property's numbers all map to the MMModemState
enumeration.  If you're not using C (and thus not using libmm-glib) then
you get to create the mapping yourself in your code, if you like.  Or
just use the numbers, but mapping them in your own code would help
readability.

That's essentially what I did in the python code with the 'states' dict.

Dan



More information about the ModemManager-devel mailing list