Commit Graph

41 Commits

Author SHA1 Message Date
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
3e037dc158 plugins: AT/QCDM/GPS port type hints only applicable to TTY ports
There are modems out there, that reuse the same vid:pid for multiple
USB layouts, so there may be port type hints that are not really
applicable in all layouts.

E.g. the EM7565 in MBIM layout uses interface #0 for the MBIM port,
while in QMI layout it uses interface #0 for the QCDM port (which is
what the port type hint included in MM states). With these rules, if
we don't bind the port type hint to TTY ports only, we would be
wrongly flagging the MBIM port as possible QCDM port:

    <debug> [plugin/sierra] probes required for port cdc-wdm0: 'mbim'
    <debug> [cdc-wdm0/probe] no AT/QMI/MBIM probing in possible QCDM port
    <debug> [cdc-wdm0/probe] port is not AT-capable
    <debug> [cdc-wdm0/probe] port is not QMI-capable
    <debug> [cdc-wdm0/probe] port is not MBIM-capable
    <debug> [cdc-wdm0/probe] port probing finished: no more probings needed

Avoid this, by making sure all port type hints are added exclusively
to TTY ports. It's not a perfect solution, but it's enough for the
known cases.
2021-07-13 10:56:11 +02:00
Aleksander Morgado
5d176a1e61 base-modem: explicitly say if NET or TTY data ports are supported
A modem that creates exclusively bearer objects that work with NET
ports (e.g. all QMI or MBIM modems) must not add any TTY port in the
list of data ports.

A modem that creates exclusively bearer objects that work with TTY
ports (e.g. the generic modem) must not add any NET port in the
list of data ports.

A modem that may use both TTY and NET ports should add all in the list
of data ports.

Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/324
Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/329
2021-03-04 18:03:28 +01:00
Aleksander Morgado
8722215f7e plugins: use logging module name as plugin name 2020-04-08 17:53:42 +02:00
Aleksander Morgado
63955ce52d mtk: port to use object logging 2020-04-08 16:35:09 +02:00
Aleksander Morgado
accd1a5841 base-modem: define new helper MMBaseModemAtCommandAlloc
It has the same exact format as MMBaseModemAtCommand, but its contents
are assumed heap allocated.

The only real purpose of this type is to allow defining static
constant MMBaseModemAtCommand variables without warnings when using
-Wdiscarded-qualifiers.
2020-01-31 15:18:35 +01:00
Aleksander Morgado
f3acdcaa1b mtk: fix warnings with -Wdiscarded-qualifiers
mtk/mm-broadband-modem-mtk.c:727:6: error: initialization discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
    727 |     {"+ECSQ=2", 5, FALSE, NULL},
        |      ^~~~~~~~~
  mtk/mm-broadband-modem-mtk.c:733:6: error: initialization discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
    733 |     {"+ECSQ=0", 5, FALSE, NULL},
        |      ^~~~~~~~~
2020-01-31 15:18:35 +01:00
Aleksander Morgado
bbeabb495e helpers: new macro to CLAMP high threshold only
Useful when clamping a unsigned integer with low threshold set to 0,
which would give us compiler warnings with -Wtype-limits when using
CLAMP(), e.g.:

  via/mm-broadband-modem-via.c: In function ‘handle_evdo_quality_change’:
  /usr/include/glib-2.0/glib/gmacros.h:811:63: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
    811 | #define CLAMP(x, low, high)  (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
        |                                                               ^
  via/mm-broadband-modem-via.c:284:19: note: in expansion of macro ‘CLAMP’
    284 |         quality = CLAMP (quality, 0, 100);
        |                   ^~~~~
2020-01-31 15:18:35 +01:00
Khem Raj
2b18af89b4 Do not pass null string to %s printf formatted string
Here the string is already decided to be NULL and passing
a null pointer to %s will not work

Fixes
error: '%s' directive argument is null

Signed-off-by: Khem Raj <raj.khem@gmail.com>
2018-12-18 23:30:10 -08:00
Ben Chan
7de6b6f2e1 core: remove unnecessary NULL checks for g_match_info_free()
g_match_info_free() already check if the given pointer is NULL and does
nothing on a NULL pointer.
2018-10-18 13:17:36 +02:00
Aleksander Morgado
548b7f8847 base-modem: load AT port type hints when adding port
We keep the pflags input in mm_base_modem_grab_port() so that plugins
can use other methods to gather port type hints (e.g. querying with AT
commands as in Huawei/Telit or looking at sysfs properties as in HSO).

For standard udev tag port type hints, it will be the base modem
looking them up.

Note that there is no longer any need to ignore non-flagged ports for
those modems that require primary/secondary flags. They will be
implicitly ignored when mm_base_modem_organize_ports() decides which
ports to use, as the flagged ones are preferred over the non-flagged
ones.
2018-08-10 04:19:13 +00:00
Aleksander Morgado
6b0424cfac plugins: consolidate ID_MM_PORT_TYPE_AT_* flag names
We define 3 common udev tag ids to be used by all plugins:

 * ID_MM_PORT_TYPE_AT_PRIMARY: the primary modem port. It will be used
   for AT control and also as PPP if there is no other port flagged
   explicitly to do PPP.

 * ID_MM_PORT_TYPE_AT_SECONDARY: the secondary modem port. It will be
   used when/if the primary port gets connected to do PPP.

 * ID_MM_PORT_TYPE_PPP: the port to be used to do PPP only. This tag
   makes sense only when the primary port shouldn't be used for PPP,
   i.e. when there is a port dedicated to do PPP and one port
   dedicated for control.
2018-08-10 04:19:13 +00:00
Aleksander Morgado
c07382a486 udev: add tags also on bind action
When a new USB device is hotplugged, e.g. a USB<->RS232 converter that
exposes a single ttyUSB0, these udev events happen:

  add  /devices/pci0000:00/0000:00:14.0/usb2/2-1 (usb/usb-device)
  add  /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0 (usb/usb-interface)
  add  /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/ttyUSB0 (usb-serial)
  add  /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/ttyUSB0/tty/ttyUSB0 (tty)
  bind /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/ttyUSB0 (usb-serial)
  bind /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0 (usb/usb-interface)
  bind /devices/pci0000:00/0000:00:14.0/usb2/2-1 (usb/usb-device)

Our udev rules in MM only added tags in the 'add' events, and it looks
like the only ones 'persistent' after this sequence are those of the
last event happening on the specific path.

This meant that all TTY subsystem rules (e.g. ID_MM_CANDIDATE) would
be stored for later check (e.g. if ModemManager is started after these
rules have been applied), which was ok. "udevadm info -p ..." would
show these tags correctly always.

But this also meant that the 'bind' udev event happening for the USB
device didn't get any of our device-specific tags, and so we would be
missing them (e.g. ID_MM_DEVICE_MANUAL_SCAN_ONLY) if MM is started
after the last event has happened. "udevadm info -p ..." would
not show these tags.

Modify all our rules to also run at the 'bind' events.

See, for context:
  https://github.com/systemd/systemd/issues/8221
2018-06-02 16:54:37 +02:00
Ben Chan
fea6835592 mtk: port disable_unsolicited_events to use GTask 2017-09-28 10:39:25 +02:00
Ben Chan
fe58e5f498 mtk: port enable_unsolicited_events to use GTask 2017-09-28 10:39:25 +02:00
Ben Chan
bfac21fbb8 mtk: port modem_3gpp_{setup,cleanup}_unsolicited_events to use GTask 2017-09-28 10:39:25 +02:00
Ben Chan
42bde89bae mtk: port modem_after_sim_unlock to use GTask 2017-09-28 10:39:25 +02:00
Ben Chan
3b2873148c mtk: port set_current_modes to use GTask 2017-09-28 10:39:25 +02:00
Ben Chan
996612f8db mtk: port load_supported_modes to use GTask 2017-09-28 10:39:25 +02:00
Ben Chan
2991ae0e86 mtk: port load_unlock_retries to use GTask 2017-09-28 10:39:25 +02:00
Aleksander Morgado
e2246da507 mtk: fix async completion in 3gpp event handlers setting 2017-07-17 10:20:17 +02:00
Aleksander Morgado
2eb55d3224 plugins: use G_N_ELEMENTS when iterating ports array 2017-05-30 17:28:23 +02:00
Ben Chan
254f2e3412 plugins: 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:18 +02:00
Aleksander Morgado
ae9ede926a core: use the kernel device object in the port object and the plugin interface
The mm_base_modem_grab_port() now receives a MMKernelDevice directly from the
plugin, which is then stored in the MMPort corresponding to the port.

This means that we have direct access to e.g. all properties set by udev rules
everywhere, and we don't need additional GUdevClient objects (e.g. like the one
used in the Huawei plugin to detect NDISDUP support during runtime).

For virtual ports (e.g. generated during unit tests), we have a new 'generic'
kernel device object which just provides the values from the kernel device
properties given during its creation.
2016-09-29 15:43:05 +02: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
c7d8ac622a udev: fix tagging per interface number
Commit 7ff57f9808 introduced a change to try to
use ATTRS{bInterfaceNumber} as a common way to match by interface number, but
this logic is broken because all the rules that we use to match by interface
number (attribute in the interface device) also require matching by idVendor
and idProduct (attributes in the physdev device), and udev rules forbid matches
from more than one parent device at a time.

We could use ATTR{bInterfaceNumber} (instead of ATTRS) to tag the actual USB
interface device, but that would require a change in all the plugins to look for
the tag not in the TTY device, but in its parent.

So, recover the original behavior, where a hidden property is created containing
the first bInterfaceNumber found in the list of parent devices, and then run
the matches against idVendor and idProduct only if the hidden property is found
with the expected value.
2016-09-18 15:43:30 +02:00
Aleksander Morgado
aa0e108107 udev: fix SUBSYSTEMS and ATTRS{idVendor} checks
Rules with a single condition where a parent property is checked with != don't
work properly. E.g.:
  SUBSYSTEMS!="usb", GOTO="end"
or:
  ATTRS{idVendor}!="abcd", GOTO="end"

Instead, we can mix both those previous parent rules and match them:
  SUBSYSTEMS=="usb",ATTRS{idVendor}=="abcd", GOTO="next"
  GOTO="end"
  LABEL="next"
  # Apply rules here
  LABEL="end"

In this case both SUBSYSTEMS and ATTRS conditions apply to the parent usb_device
(idVendor attribute is only available in the usb_device), so they apply to all
ports of the same device.
2016-09-18 14:08:20 +02:00
Aleksander Morgado
764bfbce9d mtk,udev: single 'usb' subsystems check 2016-08-06 12:57:44 +02:00
Aleksander Morgado
7ff57f9808 udev: replace ENV{.MM_USBIFNUM} conditions with ATTRS{bInterfaceNumber} 2016-08-06 10:41:52 +02:00
Ting-Yuan Huang
969189d42c plugin-manager: protect mm_plugin_{major,minor}_version
This patch makes declarations bind to definitions within the same module
to prevent the potential ambiguity if referenced directly.

AddressSanitizer think they violated one definition rule, although
those symbols are accessed by address through their modules and do
not depend on the order of the libararies loaded.
2016-05-28 13:59:54 +02:00
Lubomir Rintel
ff8f030d24 mtk: add D-Link DWM-156 A3 2016-05-04 09:49:43 -05:00
Aleksander Morgado
ffde429843 core: use G_SOURCE_REMOVE and G_SOURCE_CONTINUE in GSourceFuncs 2015-12-02 17:07:39 +01:00
Ben Chan
4669611412 broadband-modem,plugins: fix GMatchInfo leaks 2014-08-12 09:45:50 +02:00
Aleksander Morgado
7c347aa3ec port: store parent sysfs path in each MMPort 2014-06-23 18:12:27 +02:00
Aleksander Morgado
6f235b9948 ports: rename 'MMAtSerialPort' to 'MMPortSerialAt' 2014-02-13 13:40:01 +01:00
Aleksander Morgado
48585c250b udev: apply udev rules upon 'move' events as well
Otherwise, we may end up losing the tags we expect if the device gets a 'move'
event just after the initial 'add'.
2014-01-26 19:33:45 +01:00
Aleksander Morgado
c65c01703b mtk: fix GOTO tag in udev rules 2013-10-28 17:51:02 +01:00
Dan Williams
0755beff07 mtk: update udev rules to always match both VID/PID together
See commit c79d266e62.

    If the rules to tag specific USB interface numbers only apply on the PID, we'll
    end up seeing that if the port has a parent with another PID, and that other
    PID also has a rule, port will get tagged multiple times.
2013-09-16 11:54:16 -05:00
Dan Williams
872bd3e837 mtk: add D-Link DWM-156 udev rules
For HW version A5 and possibly later, which are based on MediaTek
chipsets instead of Qualcomm ones.
2013-09-16 11:54:16 -05:00
Quentin.Li
c22eca999b mtk: add plugin for various MediaTek devices
Signed-off-by: Quentin.Li <snowmanli88@gmail.com>
2013-09-16 11:53:58 -05:00