Commit Graph

311 Commits

Author SHA1 Message Date
Aleksander Morgado
74fc5baca2 core: port GRegex/GMatchInfo to use autoptr()
The behavior of GRegex changed in 2.73.2 once it was ported from pcre1
to pcre2. In some cases it was made more strict, which is fine, in
other cases it exposed some change in how it behaves on certain
matches that is not extremely clear whether it's ok or not.

See https://gitlab.gnome.org/GNOME/glib/-/issues/2729
See https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/601
See https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/621

Either way, one thing that was assumed was that initializing all
GRegex/GMatchInfo variables to NULL and making sure they're NULL
before they're initialized by glib (especially the GMatchInfo) was a
good and safer approach.

So, whenever possible, g_autoptr() is used to cleanup the allocated
GMatchInfo/GRegex variables, and otherwise, g_clear_pointer() is used
to ensure that no free/unref is attempted unless the given variable is
not NULL, and also so that the variable is reseted to NULL after being
disposed.
2022-09-05 17:33:11 +00:00
Daniele Palmas
473c41dc63 plugins: add MM_PLUGIN_REQUIRED_QCDM to plugins requiring QCDM
The new QCDM port probing and grabbing mechanism implements a new
property for detecting the plugins which require the QCDM port to
be probed and grabbed.

Add the property to the affected plugins.
2022-06-19 13:40:48 +00:00
Rukun Mao
3da84c2079 suspend: add suspend/resume support with powerd on ChromeOS
ModemManager handles suspend and resume signals sent from powerd

Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/547
2022-06-09 08:32:13 +00: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
4207ee61b7 huawei: disable +CPOL based features in Huawei E226
Issue and bugfix suggestion by Alex Leopoldo Villacís Lasso.

Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/552
2022-04-15 15:23:53 +02:00
Carlo Lobrano
ac243f9467 sms: prevent crash if date is out of range
g_date_time_new, and g_date_time_new_utc return NULL if inputs are out
of range, and currently mm_new_iso8601_time passes the GDateTime created
by those two functions to date_time_format_iso8601 without checking for
NULL values, causing a g_date_time_format_iso8601 crash if PDU data is
corrupted with wrong date.

To prevent this, mm_new_iso8601_time now can return NULL and set a new
GError if GDateTime created by g_date_time_new is NULL.

Fixes #546
2022-04-08 15:41:49 +02:00
Frederic Martinsons
9d82d30978 cli, plugins: factorize usage of iso8601 datetime format
Signed-off-by: Frederic Martinsons <frederic.martinsons@sigfox.com>

Includes updates by Aleksander Morgado to fix coding style issues.
2021-10-22 13:48:20 +02:00
Aleksander Morgado
c4130dcf83 huawei: disable CPOL based features in the R215
Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/411
2021-07-31 23:12:55 +02:00
Aleksander Morgado
13d82c1de2 huawei: ignore ^LWURC URCs
Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/412
2021-07-31 23:12:55 +02:00
Aleksander Morgado
e4d4bbbb72 huawei: plug memleak when processing GETPORTMODE hints
==99766== 96 (24 direct, 72 indirect) bytes in 1 blocks are definitely lost in loss record 3,791 of 4,243
   ==99766==    at 0x483E7C5: malloc (vg_replace_malloc.c:380)
   ==99766==    by 0x50DCAC9: g_malloc (gmem.c:106)
   ==99766==    by 0x50F46D6: g_slice_alloc (gslice.c:1069)
   ==99766==    by 0x50CE9F2: g_list_insert_sorted_real (glist.c:1109)
   ==99766==    by 0x753DE92: ???
   ==99766==    by 0x753E6D4: ???
   ==99766==    by 0x753E897: ???
   ==99766==    by 0x1F059D: mm_plugin_create_modem (mm-plugin.c:922)
   ==99766==    by 0x166693: mm_device_create_modem (mm-device.c:481)
   ==99766==    by 0x161547: device_support_check_ready (mm-base-manager.c:219)
   ==99766==    by 0x4F03533: g_task_return_now (gtask.c:1219)
   ==99766==    by 0x4F07078: UnknownInlinedFun (gtask.c:1289)
   ==99766==    by 0x4F07078: g_task_return (gtask.c:1245)
2021-07-27 00:10:02 +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
6fae479bd7 plugins: ignore reload_connection_status() where not supported
Some of the AT-based connection methods don't have any way to query
connection status, or we don't have a proper implementation for those
yet. Ignore the reload operation in all those.
2021-05-26 13:14:52 +00:00
Aleksander Morgado
43db860c44 base-bearer: report connection error on network initiated disconnections
By default, fallback to "unknown" mobile equipment error when the
modem gets disconnected by the network and we don't have any way to
know a more detailed reason.
2021-05-23 01:22:07 +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
851a708442 modem-helpers: ip family normalization doesn't need log_object 2021-04-01 11:24:42 +02:00
Aleksander Morgado
2c27a7aadc base-bearer: remove default IP family property
There is no point in providing a configurable default IP family in the
bearer object, because we can always assume IPv4 as being the only
default expected.

Simplify the logic and also provide a new method to get the normalize
the IP family, using IPv4 as default always.
2021-03-31 23:46:31 +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
381e2f382b base-modem: separate method to lookup exact port by name
There's no point in returning a list of all ports with a given name,
just provide a lookup method that returns the single port with the
given name.
2021-02-25 14:13:03 +01:00
Aleksander Morgado
1b35d74c15 kernel-device: add get_interface_number() method
We already have methods to query for interface specific attributes
like class/subclass/protocol, so add a new one for the interface
number, and make sure we use ATTRS{bInterfaceNumber} to load it
always, instead of assuming the ID_USB_INTERFACE_NUM property is set.
2021-02-24 20:47:57 +01:00
Aleksander Morgado
033e174e44 charsets: make charset_gsm_unpacked_to_utf8() private
Use the generic mm_modem_charset_bytearray_to_utf8() instead.
2021-02-23 11:35:11 +00:00
Aleksander Morgado
75b37e16b1 charsets: make charset_utf8_to_unpacked_gsm() private
Use the generic mm_modem_charset_bytearray_from_utf8() instead.
2021-02-23 11:35:11 +00:00
Aleksander Morgado
bc449cbe87 charsets: make translit optional in utf8_to_unpacked_gsm()
If the conversion is not fully compatible, the user of the method
needs to request transliteration enabled explicitly in order to avoid
returning errors in this method.
2021-02-23 11:35:11 +00:00
Aleksander Morgado
5ce97abd73 charsets: make translit optional in gsm_unpacked_to_utf8()
Until now, this method would automatically apply transliteration;
i.e. replacing characters with '?' when no direct translation was
available.

We can attempt to do that transliteration on strings that are not
critical, e.g. the operator name reported by the network. But we
should not do that on other types of strings, e.g. on SMS contents
that may really have additional purposes than just being
human-readable.

This commit makes the transliteration option to be explicitly
requested by the caller.
2021-02-23 11:35:11 +00:00
Aleksander Morgado
34de613dea libmm-glib,common-helpers: make hexstr2bin() return a guint8 array
It makes much more sense than returning a gchar array, as gchar is
signed.
2021-02-23 11:35:11 +00:00
Aleksander Morgado
a211981d4a libmm-glib,common-helpers: make hexstr2bin() accept input string length
Optionally given explicitly, and -1 can be used to assume it's
NUL-terminated.
2021-02-23 11:35:11 +00:00
Aleksander Morgado
657cabcfce libmm-glib,common-helpers: make hexstr2bin() return a GError
This util method checks whether the input string is a valid hex
string, so make sure we return a GError on failure.
2021-02-23 11:35:11 +00:00
Thomas Dendale
92c86e2b1b huawei: add GPS port type hints for Huawei ME906e 2020-11-25 21:14:19 +01:00
Aleksander Morgado
5d150ed23e core,plugins: consolidate connection/disconnection timeout values
Each different plugin or protocol had a different connection attempt
value. E.g. QMI and MBIM both used 60s max for the connection attempt,
while the u-blox plugin had up to 180s for ECM based connection
setups.

This commit consolidates all plugins and protocols to use the same
timeout values for commands that may take long to respond, e.g. a
connection atempt under low signal quality conditions.

A value of 180s for the connection attempt steps and 120s for a
disconnection attempt step is considered. Note, though, that in some
cases (like a IPv4v6 setup attempt using QMI) we may have more than
one such long step, so this doesn't mean that a connection attempt
will always take less than 180s.

Users of the connection/disconnection APIs should be able to handle
the case where the attempt times out in their side (e.g. with a lower
DBus request timeout), and which would not mean the actual request
they did really failed. E.g. a connection attempt with a DBus timeout
of 30s may fail in the user with a timeout error, but the attempt
would still go on for as much as the plugin/protocol needs.

Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/270
2020-11-14 09:41:43 +00:00
Aleksander Morgado
950abbf8ee core: stop monitoring the 'usb' subsystem
Back in Linux < 3.6 days, the cdc-wdm ports exposed by the QMI driver
were flagged as owned by the 'usb' subsystem. That changed in 3.6 when
the subsystem was renamed to 'usbmisc':

  https://mail.gnome.org/archives/networkmanager-list/2012-June/msg00125.html

This patch removes all monitoring of the 'usb' subsystem completely,
which is anyway a valid subsystem but for which we shouldn't need any
special handling. Right now, with newer kernels, we were using that
monitoring exclusively to get notified of full USB device remove
events, which is really not required as we already process the port
removals one by one.

We simplify the logic everywhere that attempted to match either the
'usb' or 'usbmisc' subsystems, and we no longer require the explicit
checks for the port name being named 'cdc-wdm[0-9]*' in the code, as
that is already taken care of by the ID_MM_CANDIDATE udev tag rule.
2020-11-13 08:57:06 +00:00
Aleksander Morgado
f052e914c8 port: rename subsystem from 'usb' to 'usbmisc'
Back in Linux < 3.6 days, the cdc-wdm ports exposed by the QMI driver
were flagged as owned by the 'usb' subsystem. That changed in 3.6 when
the subsystem was renamed to 'usbmisc':

  https://mail.gnome.org/archives/networkmanager-list/2012-June/msg00125.html

So, rename the port subsystem type enumn to 'usbmisc'.
2020-11-09 18:41:57 +01:00
Aleksander Morgado
30f0824ea1 huawei: apply GETPORTMODE hints to serial ports in order
The numbers associated to each port mode given by the AT^GETPORTMODE
response are not USB interface numbers, they are 'port numbers'.
Moreover, these numbers may start either at 0 or at 1, depending on
the firmware.

The only reasonable way to parse this response is to just gather the
order of all the port modes reported, and apply the modes to each
serial port found in the system in the same order.

Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/239
2020-11-04 11:15:19 +00:00
Aleksander Morgado
4fdf28bb56 huawei: new ^GETPORTMODE response parser 2020-11-04 11:15:19 +00:00
Aleksander Morgado
b2621b4336 huawei: plugin already processes generic tags
So don't re-process them in the generic modem when grabbing the port.
2020-11-04 11:15:18 +00:00
Aleksander Morgado
824ad11356 huawei: don't apply multiple port type hints methods
We will use one single method to apply port type hints, not a mix of
them:
  * If AT^GETPORTMODE is supported, prefer its hints over any other
    method.
  * Otherwise, try to guess hints from USB interface descriptions.
  * And if none of the plugin-specific hints are supported, we'll
    default to applying generic port type hints from udev tags.

Once the hints have been applied by one of the methods above, the
fallback hint sequences are run:
  * Flag the first cdc-wdm port as primary if no other port has been
    flagged as primary.
  * Flag the USB interface 0 as PPP if no other port type hint has
    been set in any other port.

The logic applying all these procedures has been refactored so that we
have separate functions for each, which is much easier to read and
follow, even if it requires multiple iterations over the port probe
list.

Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/238
2020-11-04 11:15:18 +00:00
Aleksander Morgado
86a183778b api,sim: new 'Active' property
In preparation for the multi-SIM setup, we need a way to tell whether
a given SIM card is active or not in the system.

On systems with one single SIM slot, the available SIM card will
always be active.

On Multi-SIM Single-Standby setups we may have multiple SIM slots with
multiple SIM cards, but only one of them will be active at any given
time.

On Multi-SIM Multi-Standby setups we may have multiple SIM slots with
multiple SIM cards that may be active at the same time. E.g. the QMI
protocol allows up to 5 different active SIM cards (primary,
secondary, tertiary...).
2020-08-28 14:59:06 +00:00
Giacinto Cifelli
4d58278d7f changed default authentication algorithm to CHAP
CHAP is almost universal nowadays, and so it is a better default
than PAP

Not changed for uBlox, that prefers an error if not specified,
and for Huawei, which uses NONE with user/pwd and has 2 CHAP choices
2020-07-24 16:34:40 +02:00
Walter Hagstrom
88923ffe39 iface-modem-signal: added 5G signal information
Extended the ModemManager Signal interface to include 5G signal
information for RSRP, RSRQ and SINR via libqmi.  Also extended mmci
to print 5G signal info.
2020-07-04 05:50:41 +02:00
Aleksander Morgado
70b7218b7b huawei: only flag GPS source as enabled if it was successful 2020-06-29 08:53:00 +00:00
Aleksander Morgado
41ba7d667a huawei: simplify GPS stop logic
The NMEA data port is closed right before stopping the engine.
2020-06-29 08:53:00 +00:00
Aleksander Morgado
aa4851ed03 huawei: port GPS enabling to use AT sequence 2020-06-29 08:53:00 +00:00
Aleksander Morgado
bbfc10d7c5 huawei: minor refactor in GPS enabling/disabling logic 2020-06-29 08:53:00 +00:00
Aleksander Morgado
4b37b7d3cf base-modem,at: response processors return a more specific enum
Instead of using the FALSE return of the method to indicate either a
fatal error (if result_error was set) or the continuation request (if
result_error wasn't set), provide a enum that has explicit states for
all three possible values (failure, success or continue).
2020-06-28 15:07:34 +02:00
Aleksander Morgado
d8b70602c5 huawei: ignore NDISDUP disconnection errors
Running NDISDUP=1,0 on an already disconnected bearer/context will
report ERROR, so we can really ignore the result of the command,
because we're anyway going to get the correct bearer/context status
later on with the NDISSTATQRY checks.
2020-06-01 16:17:29 +00:00
Aleksander Morgado
472fb96bbe huawei: don't delay reporting network initiated disconnects
When a network-initiated event is received telling us that a
bearer/context is disconnected, we should handle and process it right
away, without thinking on whether there is going to be a
user-requested disconnect afterwards or not.

This effectively reverts the changes introduced in commit
21a5aaf4fe, which looks like was done to
handle synchronization issues with upper layers (e.g. with
NetworkManager or Shill).

Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/205
2020-06-01 16:17:29 +00:00
Louis-Alexis Eyraud
3b35bbd47b huawei: fix memory leak when parsing HCSQ response
Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/220
2020-05-29 15:47:54 +02:00
Aleksander Morgado
29a68c94b9 huawei: ignore ^CCALLSTATE URCs for now
We will want to support these to avoid needing to have CLCC call
polling, but for now, just ignore them so that they don't interfere
with the call management.

For context, see:
https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/216
2020-05-22 10:58:29 +02:00
Aleksander Morgado
a2b0cee935 huawei,helpers: fix warnings with -Wcast-align
huawei/mm-modem-helpers-huawei.c: In function 'match_info_to_ip4_addr':
  huawei/mm-modem-helpers-huawei.c:193:39: error: cast increases required alignment of target type [-Werror=cast-align]
       *out_addr = GUINT32_SWAP_LE_BE (*((guint32 *) bin));
                                         ^
  /usr/include/glib-2.0/glib/gtypes.h:184:77: note: in definition of macro 'GUINT32_SWAP_LE_BE'
   #    define GUINT32_SWAP_LE_BE(val) ((guint32) __builtin_bswap32 ((gint32) (val)))
                                                                               ^~~
2020-05-19 13:44:23 +02:00
Aleksander Morgado
bd2e6f5df4 huawei: avoid cast-align errors
We can safely cast the data in a GArray to gpointer first, and then
to the pointer type we require.

  huawei/mm-broadband-modem-huawei.c: In function 'set_current_bands':
  huawei/mm-broadband-modem-huawei.c:916:50: error: cast increases required alignment of target type [-Werror=cast-align]
       bands_string = mm_common_build_bands_string ((MMModemBand *)bands_array->data,
                                                    ^
2020-05-19 13:44:23 +02:00
Aleksander Morgado
6b36fe9f19 huawei: NDISDUP based devices may use plain TTYs for control
So don't warn if no associated cdc-wdm port is found.
2020-05-15 14:12:12 +02:00
Murithi Borona
479d8e723c huawei: updated HCSQ regex to match unquoted response 2020-04-28 15:09:49 +02:00