Commit Graph

44 Commits

Author SHA1 Message Date
Ben Chan
8ad785925a core: use g_list_copy_deep for deep copying a GList 2017-06-23 22:32:07 +02:00
Ben Chan
27e4c74c60 core: reset GList pointers to NULL when necessary
When calling g_list_free_full() to free a GList in dispose(), it is
necessary to reset the GList pointer to NULL as dispose() may be called
more than once.
2017-03-29 10:22:37 +02:00
Ben Chan
9823d9d6f6 core: remove explicit GDestroyNotify cast on g_free / g_object_unref
g_free and g_object_unref are in form of  `void (*)(gpointer)`, which
matches the GDestroyNotify signature. An explicit GDestroyNotify cast on
g_free and g_object_unref is thus not needed.
2017-03-29 10:22:05 +02:00
Ben Chan
73bfe94643 device: add null check on `self->priv->modem' in clear_modem
clear_modem() can be invoked from set_property() and dispose(), where
`self->priv->modem' may be NULL. This patch adds a null check on the
modem object to make sure we don't run g_object_run_dispose() on a null
modem object.
2017-03-03 21:37:18 +01:00
Aleksander Morgado
1d41685f48 device: disconnect signal handlers when modem object removed
Don't rely on the automatic disconnection of the signal as the last
reference of the modem object may outlive the device object.

Also, setup a common clear_modem() function to dispose the internal
reference of the modem object, which will take care of the signal
disconnection when required.

https://lists.freedesktop.org/archives/modemmanager-devel/2017-February/003907.html
2017-02-13 20:31:20 +01:00
Carlo Lobrano
9a92034cd3 device: fixed crash in SIM hot swap when removing the SIM
mm_device_create_modem needs a valid object_manager instance to create the new
modem, while the one provided before was cleared out by a call to
mm_device_remove_modem few lines before.

Since the newly created modem refers to the same HW device, we can use
the same object_manager also.

https://bugs.freedesktop.org/show_bug.cgi?id=99160
2016-12-20 16:15:37 +01:00
Aleksander Morgado
aa4577dfb9 core: new kernel device object instead of an explicit GUdevDevice
Instead of relying constantly on GUdevDevice objects reported by GUdev, we now
use a new generic object (MMKernelDevice) for which we provide an initial GUdev
based backend.
2016-09-29 15:43:05 +02:00
Aleksander Morgado
1f813c4e96 core: allow identifying devices by a user-provided 'uid'
All ports of the same modem reported by the kernel will all be associated with
a common 'uid' (unique id), which uniquely identifies the physical device. This
logic was already in place, what we do now is avoid calling it  the 'sysfs
path' of the physical device, because we may not want to use that to identify
a device.

This logic now also enables the possibility of "naming" the modems in a unique
way by setting the "ID_MM_PHYSDEV_UID" property in the "usb_device" that owns
all the ports.

E.g. a custom device has 4 modems in 4 different USB ports. The device path of
each USB device will always be the same, so the naming rules could go like this:

    $ vim /usr/lib/udev/rules.d/78-mm-naming.rules

    ACTION!="add|change|move", GOTO="mm_naming_rules_end"
    DEVPATH=="/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.5/4-1.5.1", ENV{ID_MM_PHYSDEV_UID}="USB-MODEM-1"
    DEVPATH=="/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.5/4-1.5.2", ENV{ID_MM_PHYSDEV_UID}="USB-MODEM-2"
    DEVPATH=="/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.5/4-1.5.3", ENV{ID_MM_PHYSDEV_UID}="USB-MODEM-3"
    DEVPATH=="/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.5/4-1.5.4", ENV{ID_MM_PHYSDEV_UID}="USB-MODEM-4"
    LABEL="mm_naming_rules_end"

Each of the modems found will have a unique UID retrieved from the previous list
of rules. Then, "mmcli" has also been updated to allow using the UID instead of
the modem DBus path or index, e.g.:

    $ sudo mmcli -m USB-MODEM-1
    /org/freedesktop/ModemManager1/Modem/0 (device id '988d83252c0598f670c2d69d5f41e077204a92fd')
      -------------------------
      Hardware |   manufacturer: 'ZTE CORPORATION'
               |          model: 'MF637'
               |       revision: 'BD_W7P673A3F3V1.0.0B04'
               |      supported: 'gsm-umts'
               |        current: 'gsm-umts'
               |   equipment id: '356516027657837'
      -------------------------
      System   |         device: 'USB-MODEM-1'
               |        drivers: 'option'
               |         plugin: 'ZTE'
               |   primary port: 'ttyUSB5'
               |          ports: 'ttyUSB5 (at)'
    ...

    $ sudo mmcli -m USB-MODEM-1 --enable
    ...
2016-09-29 15:41:21 +02:00
Aleksander Morgado
048667ffc2 core: minor coding style changes 2016-08-10 09:49:40 +02:00
Carlo Lobrano
60f4f9e57d modem: support SIM hot swap
BaseModem
  added reprobe property.

MMDevice
  added logic to recreate the modem if it is set invalid and "to reprobe"

MMBroadbandModem
 * added initialization step for SIM hot swap:
    1. keep dedicated ports open to listen to modem's unsolicited
    2. dedicated error management in case of initialization failure due to SIM missing
 * added function to be called in order to act upon SIM insertion/removal:
    1. close dedicated ports
    2. set the modem to be reprobed
    3. disable modem
 * added SIM HOT SWAP boolean property

MMIfaceModem
 * added initialization step for SIM hot swap, if supported by the plugin
 * dedicated error management in case of initialization failure due to SIM missing
2016-08-10 09:39:27 +02:00
Aleksander Morgado
f9e4e6b8f1 device: ignored ports are also owned by the device, so include them in lookup 2016-08-06 13:02:19 +02:00
Aleksander Morgado
55408e8b94 device: port probe may be in the ignored list 2016-03-27 21:53:03 +02:00
Aleksander Morgado
dc38332224 plugin: avoid segfault when port driver is unknown
Based on a patch from Bastiaan Jacques <bastiaan@bjacques.org>

https://bugzilla.redhat.com/show_bug.cgi?id=1177799
https://bugs.freedesktop.org/show_bug.cgi?id=88864
2015-01-29 12:23:31 +01:00
Lubomir Rintel
b8cd5ae838 device: Keep track of devices as they are move across sysfs
For certain devices the name changes with their status. Notably, RFCOMM
devices move from /devices/virtual/ to underneath the HCI that is used
for the connection as the session is estabilished, and return back when
it's torn down.
2014-11-01 20:07:30 +01:00
Ben Chan
37b0402ee5 core: minor coding style fixes 2014-05-20 09:32:29 +02:00
Dan Williams
42ad7b758a manager: make Bluetooth rfcomm ports work again
At some point rfcomm serial ports stopped having parents in sysfs,
so checks to get the physical device fail because the rfcomm port
is /sys/devices/virtual/rfcommX and has no parents.  So we have
to fall back on checking the interface name.
2014-02-13 15:18:16 -06:00
Aleksander Morgado
9641d27518 device: allow creating 'virtual' devices 2014-02-13 13:41:33 +01:00
Aleksander Morgado
b7fa48dd22 device: new 'hotplugged' property 2014-02-13 13:41:31 +01:00
Ben Chan
82a0787906 device: check for NULL driver in add_port_driver
This patch fixes a crash in MMDevice::add_port_driver() due to
g_str_equal() dereferencing a NULL driver returned by
mm_device_utils_get_port_driver().

Bug reported on https://code.google.com/p/chromium/issues/detail?id=241823
2013-05-19 20:27:54 +02:00
Aleksander Morgado
f8e7f2ebe1 device: look for vendor/product ID on the grandparent for MBIM devices 2013-04-17 15:23:24 +02:00
Ben Chan
be8c8a99bb device: handle NULL returned by g_udev_device_get_driver() gracefully
This patch fixes a crash in mm_device_grab_port() when doing a string
comparison on a NULL returned by g_udev_device_get_driver().

Thread 0 *CRASHED* ( SIGSEGV @ 0x00000000 )

0x76b760b4   [libc-2.15.so]               - strcmp.c:38                      strcmp
0x76c66a7d   [libglib-2.0.so.0.3200.4]    - ghash.c:1704                     g_str_equal
0x76ee0e5d   [ModemManager]               - mm-device.c:147                  mm_device_grab_port
0x76edf9d9   [ModemManager]               - mm-manager.c:313                 device_added
0x76e95b2d   [libgudev-1.0.so.0.1.0]      - extras/gudev/gudevmarshal.c:84   g_udev_marshal_VOID__STRING_OBJECT
0x76d1fb2b   [libgobject-2.0.so.0.3200.4] - gclosure.c:777                   g_closure_invoke
0x76d2b88b   [libgobject-2.0.so.0.3200.4] - gsignal.c:3551                   signal_emit_unlocked_R
0x76d313c5   [libgobject-2.0.so.0.3200.4] - gsignal.c:3300                   g_signal_emit_valist
0x76d31569   [libgobject-2.0.so.0.3200.4] - gsignal.c:3356                   g_signal_emit
0x76e93bdd   [libgudev-1.0.so.0.1.0]      - extras/gudev/gudevclient.c:105   monitor_event
0x76c9beb7   [libglib-2.0.so.0.3200.4]    - giounix.c:166                    g_io_unix_dispatch
0x76c714c1   [libglib-2.0.so.0.3200.4]    - gmain.c:2539                     g_main_context_dispatch
0x76c71745   [libglib-2.0.so.0.3200.4]    - gmain.c:3146                     g_main_context_iterate
0x76c71a59   [libglib-2.0.so.0.3200.4]    - gmain.c:3340                     g_main_loop_run
0x76ede8ed   [ModemManager]               - main.c:142                       main
0x76b35f79   [libc-2.15.so]               - libc-start.c:226                 __libc_start_main
0x76edea49   [ModemManager]               + 0x00014a49
0x76eb4eab   [ld-2.15.so]                 + 0x0000aeab
2013-04-10 15:04:36 -05:00
Dan Williams
2bbe2f8327 device: read PCI VID/PID
Nozomi devices are old Option NV CardBus devices with the ttys (nozX)
hanging directly off the PCI device.  We need to read the vendor and
product IDs off them too.  It appears that udev screws up the ID_MODEL_ID
field (at least on F17, its set to the device path and not the PCI ID)
so just skip looking at the TTY itself and read the PCI parent, where
we're 100% sure to find the PCI IDs we want.
2013-03-28 20:06:53 +01:00
Ben Chan
e75dba639f core: add 'hotplugged' flag to indicate if modem is newly plugged in
This patch adds a 'hotplugged' flag to MMBaseModem to indicate if a
modem is newly plugged in. A plugin can use this information to
determine if, for example, the modem needs to be soft reset using the
ATZ command.

Dan Williams <dcbw@redhat.com> contributed the idea of implementation.
2013-01-18 11:27:51 +01:00
Aleksander Morgado
731812fe34 plugin: avoid QMI-managed net ports when compiling without QMI support 2012-12-27 13:51:28 +01:00
Aleksander Morgado
c5f3198a9f device: only export modem if it is available 2012-10-22 12:27:55 +02:00
Aleksander Morgado
c250fa3797 libmm-glib: remove the `libmm-common.h' header
Both the ModemManager daemon and the mmcli will now include `libmm-glib.h' only.

We also handle two new special `_LIBMM_INSIDE_MM' and `LIBMM_INSIDE_MMCLI'
symbols, which if included before the `libmm-glib.h' library allow us to:

 * Don't include the libmm-glib high level API in the ModemManager daemon, as
   the object names would clash with those in the core.

 * Define some of the methods of helper objects to be included only if compiling
   ModemManager daemon or the mmcli.
2012-10-04 10:17:12 +02:00
Aleksander Morgado
c4b5293669 device: if failed to get VID/PID in first port, try the next one
Don't rely only in the first grabbed port to get VID/PID. Some modems, e.g.
Huawei E367, won't report a proper VID in the cdc-wdm port, which is the first
one probed.
2012-09-19 10:18:44 +02:00
Aleksander Morgado
a66f971a7c libmm-common: added common utils from core
Moved the utils to play with binary to hex strings into libmm-common.
2012-09-14 07:05:26 +02:00
Aleksander Morgado
494a70a8ff core: handle the 'usb'->'usbmisc' subsystem rename in the kernel
We'll try to cope with getting devices being reported in either 'usb' or
'usbmisc', trying to avoid the need of checking kernel version during runtime.
2012-08-29 17:26:46 +02:00
Aleksander Morgado
306b4eb509 core: allow grabbing QMI ports 2012-08-29 17:14:47 +02:00
Aleksander Morgado
0436b3e457 api,introspection: report list of drivers, not just one
Different ports of the same modem may get handled by different drivers. We
therefore need to provide a list of drivers (new `Modem.Drivers' property with
signature 'as') instead of just one (removed `Modem.Driver' property with
signature 's').

$ sudo mmcli -m 0 | grep drivers
           |        drivers: 'qcserial, qmi_wwan'
2012-08-24 13:34:51 +02:00
Aleksander Morgado
f6415a71b6 device: keep all unsupported ports in a separate list
Ports being marked as unsupported should not be passed to the plugin specific
create_modem() or grab_port() methods.
2012-08-06 20:07:50 +02:00
Aleksander Morgado
b8cc7c66ec device: don't create devices with 0 ports
If for any reason we're requested to create a device with 0 ports, just return
error.
2012-08-06 20:07:22 +02:00
Aleksander Morgado
ff8a962d99 port-probe: let us peek the `MMDevice' owning the probe from the probe itself 2012-08-06 20:06:47 +02:00
Aleksander Morgado
bfc3cb27e1 device,plugin: let the MMPlugin' API know about MMDevice' 2012-08-06 20:06:46 +02:00
Aleksander Morgado
4a85707b09 port-probe: no need to keep neither physdev path nor driver 2012-08-06 20:06:46 +02:00
Aleksander Morgado
9d14e4e8e9 device: get vendor/product IDs
And don't do it in MMPlugin.
2012-08-06 20:06:45 +02:00
Aleksander Morgado
74dd724669 plugin: simplify interface by passing around the device and/or port objects 2012-08-06 20:06:45 +02:00
Aleksander Morgado
b791e87b23 device: keep a list of port probes instead of just ports 2012-08-06 20:06:45 +02:00
Aleksander Morgado
66ec5cd724 device: signal grabbed/released ports 2012-08-06 20:06:44 +02:00
Aleksander Morgado
72ffa7a1e5 device: load driver being used when first port grabbed 2012-08-06 20:06:44 +02:00
Aleksander Morgado
7b7f5b9dcb device: keep sysfs path around for logging 2012-08-06 20:06:44 +02:00
Aleksander Morgado
0aff871b04 device: split `MMDevice' creation and plugin setting
We want to be able to create the MMDevice way before we have decided which
plugin to use.
2012-08-06 20:06:44 +02:00
Aleksander Morgado
815693661c core: compile all ports before creating the modem object
Before this, we only exported the modem to DBus when all ports were organized,
in order to make sure that we select as primary port the one we really want and
not the first AT port grabbed. Given that to get all the ports organized we also
needed to wait to get all the ports grabbed, we can now also defer the creation
of the modem object until all the ports get grabbed. This allows us to create
different types of objects based on the ports available (e.g. we can now create
QMI-supported modem objects if we see a QMI port around).
2012-08-06 20:06:44 +02:00