Commit Graph

56 Commits

Author SHA1 Message Date
Daniele Palmas
15b031ce6d bearer-mbim: enable multiplex support for wwan devices 2022-08-11 09:48:38 +02:00
Daniele Palmas
654c5f5014 base-modem: add subsystem vendor ID property
Subsystem vendor ID can be used for identifying PCI modems,
so expose the property.
2022-05-24 09:22:06 +02:00
Aleksander Morgado
25a1b28fbf core: strict return type in g_object_ref()
This is now a requirement when using glib 2.56.
2021-04-30 11:05:42 +00:00
Aleksander Morgado
897e48709d base-modem: allow grabbing link ports after modem is created
We will grab the ports and make them available through find_ports() or
peek_port() or get_port().

The link ports are not 'organized' so they won't be available in
e.g. get_data_ports(), which is fine, because we don't want to mix
them with the real data ports exposed by the device.

Link port additions and removals are also notified via signals in the
modem object, so that explicit wait for specific ports can be done.
2021-03-10 12:58:12 +01:00
Aleksander Morgado
f3f05f397a device: avoid trying to remove source multiple times
ModemManager[115879]: <debug> [1613341789.760031] [modem3] completely disposed

   (ModemManager:115879): GLib-CRITICAL **: 23:29:49.760: Source ID 2379 was not found when attempting to remove it

   Thread 1 "ModemManager" received signal SIGTRAP, Trace/breakpoint trap.
   0x00007ffff774b343 in g_logv () from /usr/lib/libglib-2.0.so.0
   (gdb)
   (gdb) bt
   #0  0x00007ffff774b343 in g_logv () at /usr/lib/libglib-2.0.so.0
   #1  0x00007ffff774b5c0 in g_log () at /usr/lib/libglib-2.0.so.0
   #2  0x00007ffff7741c9e in g_source_remove () at /usr/lib/libglib-2.0.so.0
   #3  0x00005555555aad02 in dispose (object=0x555555831260) at mm-device.c:802
   #4  0x00007ffff7843755 in g_object_unref () at /usr/lib/libgobject-2.0.so.0
   #5  0x00005555555a5107 in glib_autoptr_clear_MMDevice (_ptr=0x555555831260) at mm-device.h:63
   #6  0x00005555555a5125 in glib_autoptr_cleanup_MMDevice (_ptr=0x7fffffffe090) at mm-device.h:63
   #7  0x00005555555a59ab in device_removed (self=0x555555769220, subsystem=0x55555577dc50 "tty", name=0x555555869a40 "ttyUSB3") at mm-base-manager.c:237
   #8  0x00005555555a620d in handle_uevent (self=0x555555769220, action=0x5555558987b0 "remove", device=0x555555893840) at mm-base-manager.c:445
   #9  0x00007ffff7381acd in  () at /usr/lib/libffi.so.7
   #10 0x00007ffff738103a in  () at /usr/lib/libffi.so.7
   #11 0x00007ffff783c8fe in g_cclosure_marshal_generic () at /usr/lib/libgobject-2.0.so.0
   #12 0x00007ffff7837072 in g_closure_invoke () at /usr/lib/libgobject-2.0.so.0
   #13 0x00007ffff785fa85 in  () at /usr/lib/libgobject-2.0.so.0
   #14 0x00007ffff78535dd in g_signal_emit_valist () at /usr/lib/libgobject-2.0.so.0
   #15 0x00007ffff7853b40 in g_signal_emit () at /usr/lib/libgobject-2.0.so.0
   #16 0x00007ffff7e792aa in  () at /usr/lib/libgudev-1.0.so.0
   #17 0x00007ffff7742b84 in g_main_context_dispatch () at /usr/lib/libglib-2.0.so.0
   #18 0x00007ffff7796c21 in  () at /usr/lib/libglib-2.0.so.0
   #19 0x00007ffff77420d3 in g_main_loop_run () at /usr/lib/libglib-2.0.so.0
   #20 0x00005555555a1df4 in main (argc=2, argv=0x7fffffffea88) at main.c:213
2021-02-14 23:34:36 +01:00
Pavan Holla
38f6704fa1 base-sim: Reprobe modem if lock status cannot be read after sending puk
If the lock status cannot be read during a puk unblock attempt, reprobe
the modem. It is likely that the SIM was permanently blocked if the lock
status cannot be read.
2020-11-26 08:53:14 +00:00
Aleksander Morgado
c3bc515b8a base-manager: never create kernel device objects for remove events
There is no point in creating a new kernel device object just to
process a remove event; instead, do any matching with existing
kernel device objects by subsystem and name, which is what the generic
backend already did anyway.

This avoids unnecessary lookup of information in sysfs during removal
events, because the port is anyway already gone when we try to look
those up.
2020-11-19 17:01:55 +00:00
Aleksander Morgado
2b1201af3c device: port to use object logging 2020-04-08 16:35:09 +02:00
Aleksander Morgado
9e50dda400 base-modem: set dbus id as soon as object is created 2020-04-08 16:35:08 +02:00
Aleksander Morgado
fbc1e3f89e device: don't reprobe if device is gone
When a QMI/MBIM device is unplugged, we first get the notification
from the proxy that the communication is broken, and then we get the
kernel event reporting that the cdc-wdm port is gone.

If we reprobe the device as soon as the proxy notifies us that the
communication is broken, we would end up trying to reprobe the cdc-wdm
port when it's already gone, and we end up trying to create a modem
object when we shouldn't:

   <debug> [1577963152.429386] (ttyUSB0) unexpected port hangup!
   <debug> [1577963152.429506] (ttyUSB0) forced to close port
   <debug> [1577963152.429546] (ttyUSB0) device open count is 0 (close)
   <debug> [1577963152.429582] (ttyUSB0) closing serial port...
   <debug> [1577963152.429653] (ttyUSB0) serial port closed
   <debug> [1577963152.430340] (ttyUSB2) unexpected port hangup!
   <debug> [1577963152.430391] (ttyUSB2) forced to close port
   <debug> [1577963152.430418] (ttyUSB2) device open count is 0 (close)
   <debug> [1577963152.430451] (ttyUSB2) closing serial port...
   <debug> [1577963152.430517] (ttyUSB2) serial port closed
   <info>  [1577963152.436932] (tty/ttyUSB0): released by device '/sys/devices/pci0000:00/0000:00:14.0/usb2/2-3'
   <info>  [1577963152.439176] (tty/ttyUSB1): released by device '/sys/devices/pci0000:00/0000:00:14.0/usb2/2-3'
   <info>  [1577963152.440409] (tty/ttyUSB2): released by device '/sys/devices/pci0000:00/0000:00:14.0/usb2/2-3'
   <info>  [1577963152.447977] (net/wwan1): released by device '/sys/devices/pci0000:00/0000:00:14.0/usb2/2-3'
   Cannot read from istream: connection broken
   <info>  [1577963152.458878] Connection to qmi-proxy for /dev/cdc-wdm1 lost, reprobing
   <debug> [1577963152.459144] [device /sys/devices/pci0000:00/0000:00:14.0/usb2/2-3] unexported modem from path '/org/freedesktop/ModemManager1/Modem/1'
   <debug> [1577963152.460151] (ttyUSB1) forced to close port
   <info>  [1577963152.460182] [device /sys/devices/pci0000:00/0000:00:14.0/usb2/2-3] creating modem with plugin 'Sierra' and '1' ports
   <debug> [1577963152.460199] QMI-powered Sierra modem found...
   <debug> [1577963152.460382] (cdc-wdm1) type 'qmi' claimed by /sys/devices/pci0000:00/0000:00:14.0/usb2/2-3
   <debug> [1577963152.460417] Modem (Sierra) '/sys/devices/pci0000:00/0000:00:14.0/usb2/2-3' completely disposed
   <warn>  [1577963152.460431] Could not recreate modem for device '/sys/devices/pci0000:00/0000:00:14.0/usb2/2-3': Failed to find a net port in the QMI modem
   <debug> [1577963152.460526] Modem (Sierra) '/sys/devices/pci0000:00/0000:00:14.0/usb2/2-3' completely disposed
   <info>  [1577963152.460627] (usbmisc/cdc-wdm1): released by device '/sys/devices/pci0000:00/0000:00:14.0/usb2/2-3'
   <debug> [1577963152.460666] Removing empty device '/sys/devices/pci0000:00/0000:00:14.0/usb2/2-3'

Fix this by delaying the reprobing attempt some time, and make sure we
cancel the reprobing if the device detects that all ports are gone.
2020-01-06 20:46:06 +00:00
Aleksander Morgado
941879b43a device: keep reference to object manager server
Instead of having the reference to the object manager server only
while the modem is exported, just keep a reference for as long as the
device object exists. This will make it easier to handle reprobing
logic.
2020-01-06 20:46:06 +00:00
Aleksander Morgado
2212d3e054 api,manager: new InhibitDevice() method
This new method allows users of the ModemManager API to take full
control of a given device.

Unlike other operations in the API, the inhibition is maintained as
long as the caller exists in the bus, or until the same caller
uninhibits the device.

https://gitlab.freedesktop.org/mobile-broadband/ModemManager/issues/98
2019-01-03 21:05:58 +01:00
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