Commit Graph
159 Commits
Author SHA1 Message Date
Dan Williams ee75d23f00 modem-helpers: handle no space after "+CESQ:"
See https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/merge_requests/1277
for more details.

Signed-off-by: Dan Williams <dan@ioncontrol.co>
2025-09-11 08:24:42 -05:00
Guido Günther 04229ca146 modem-helpers: Don't leak in tests
Signed-off-by: Guido Günther <agx@sigxcpu.org>
2025-06-14 16:10:05 -05:00
Dan Williams 56fe8e7d31 modem-helpers: add utility function to split DTMF runs
Split into groups of non-pause characters and single pause characters
by themselves and return as an array of strings.

Signed-off-by: Dan Williams <dan@ioncontrol.co>
2025-05-30 08:02:47 -05:00
Dan Williams 757df26b29 broadband-modem,modem-helpers: move +CPIN response parsing to modem helpers
Unit test it better, plus remove code duplication in various plugins.

Signed-off-by: Dan Williams <dan@ioncontrol.co>
2025-05-23 08:31:04 -05:00
Dan Williams 5888949fa3 modem-helpers: handle spaces in +CPMS query response
Fixes: https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/990

Signed-off-by: Dan Williams <dan@ioncontrol.co>
2025-05-20 09:56:49 -05:00
Daniele Palmas b0589932d7 broadband-modem: support +CGEREP values different than 2
Signed-off-by: Daniele Palmas <dnlplm@gmail.com>
2025-05-19 08:59:00 -05:00
Kirill Buksha e5c4cbc79a tests,modem-helpers: add cases for multidigit "stat" value in CREG response
Signed-off-by: Kirill Buksha <kirbuk200@gmail.com>
2025-05-14 13:21:01 +02:00
Dan Williams d4c0bbc839 modem-helpers: add IPv6 support to +CGCONTRDP parsing
Add some test responses from the Quectel EG915Q and some other Quectel devices.
Then try to parse those responses.

Signed-off-by: Dan Williams <dan@ioncontrol.co>
2025-05-08 20:37:09 -05:00
Dan Williams 9e205f4784 modem-helpers: fix checking of CDMA/EVDO access technology
Missing ! for strncmp() meant the test was backwards and would
erroneously report 1xRTT and EVDOr0 when those access technologies
were not in use.

Signed-off-by: Dan Williams <dan@ioncontrol.co>
2025-04-12 23:37:00 -05:00
Guido Günther d8135be6e2 modem-helpers: Add helpers to parse channel lists
`CSCB` has the form

```
CSCB: [0|1],"<channel-list>","<data-coding-scheme>"
```

If the first parameter is `0` this specifies the accepted types if `1`
it specifies rejected.

So far seen in the wild were CSCB strings with accepted types only and a
coding scheme of "" so this is what we handle for the moment.

Signed-off-by: Guido Günther <agx@sigxcpu.org>
2025-03-28 20:53:52 +00:00
Michal Mazur a030eaef76 sim: add common helpers to parse operator name and mnc length 2024-09-25 12:08:40 +00:00
Dan Williams 478e9645ca tests: test mm_split_string_groups()
Signed-off-by: Dan Williams <dan@ioncontrol.co>
2024-09-10 19:03:31 -05:00
Aleksander Morgado 07f1f58642 modem-helpers: rework AT string quote operation and add unit tests
Rework the AT string quote operation to build the output with the
GString helper, instead of manually calculating how many bytes we'll
need in the output. It just makes it clearer.
2024-03-12 10:15:59 +00:00
Petr Krasnoshchekov 277d785735 modem-helpers: improve CGDCONT read response parsing
SIM A7600E-H sends only 3 parameters in CGDCONT read response (+CGDCONT: 1,"IP","nate.sktelecom.com").
The parsing regex requeres 4 parameters, so the response is not matched.
In addition fourth parameter is not used by parsing code.
2023-12-01 12:49:45 +00:00
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
Aleksander Morgado 51a333cd9a test-modem-helpers: add EOL to strings matched with G_REGEX_NEWLINE_CRLF
Looks like pcre2 (used since glib 2.73.2) requires EOLs to match if
G_REGEX_NEWLINE_CRLF is explicitly used. The tests are updated
accordingly, because the modem responses will anyway have the EOLs
as well.

See https://gitlab.gnome.org/GNOME/glib/-/issues/2729#note_1544130

Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/601
2022-09-02 17:23:56 +02:00
Aleksander Morgado 598d99b5bd test,modem-helpers: add test for the EM9191 COPS=? response
Including 5GNR network reporting (act=12)

https://forum.sierrawireless.com/t/5g-network-scan-with-the-em9191-operation-not-allowed/26374/9
2022-03-16 11:04:06 +00:00
Aleksander Morgado 2c8cfb4768 modem-helpers: improve and fix COPS=? numeric fields parsing
The numeric fields in the +COPS=? response were relying on a very weak
parsing logic, assuming that they were single-digit numeric values and
not using the common string to integer conversion utilities.

This commit improves the conversion from the 3GPP/ETSI defined network
availability and access technology values to the MM defined ones,
providing enum-based matches even if the numeric values are the same.

The commit also fixes the parsing of access technology values > 10,
required to report 5G related values.
2022-03-16 11:04:06 +00: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
Dylan Van Assche 92ad38432c mm-modem-helpers: only parse calls in voice mode
Calls in a CLCC response in data-only or fax-only mode
do not count as actuall calls.
2021-09-08 07:59:16 +00:00
Teijo Kinnunen 0610267fa8 test,modem-helpers: add test case of AT+CPOL? response parsing 2021-08-02 12:42:13 +03:00
Aleksander Morgado 4cf12bb8bc helpers: skip g_warning() in mm_3gpp_parse_ws46_test_response()
Use mm_obj_warn() instead.
2021-06-16 11:59:51 +02:00
Teijo Kinnunen 14c4f27ae4 modem-helpers: add 3 digit MNC output to mm_3gpp_parse_operator_id()
MNC digit count information is lost on conversion to integers. Make it
possible for the caller to get this information through a separate
boolean.
2021-05-17 12:46:52 +03:00
Aleksander Morgado 62cbf7fa86 modem-helpers: new profile list helpers
The new helpers allow converting a PDP context list returned from the
+CGDCONT? parser to a list of 3GPP profile objects.

The new mm_3gpp_profile_list_find_best() method is equivalent to the
mm_3gpp_select_best_cid() one, but using profile objects as
input/output instead of specific settings.

The unit tests that were testing mm_3gpp_select_best_cid() are also
converted to use mm_3gpp_profile_list_find_best().
2021-04-29 10:13:22 +00:00
Aleksander Morgado 16df1e17e6 helpers: rework normalize_operator() to use str_to_utf8()
Instead of blindly assuming that we can take whatever string given as
valid UTF-8, we'll always attempt to convert from the current modem
charset into UTF-8. Before we were doing this for hex-encoded UCS2,
but not for example for GSM-7.

And due to the now applied GSM-7 conversion, the mf627a/mf627b +COPS
parsing unit tests are updated accordingly, because when converting
from an input string that contains byte 0x40 ('@' in UTF-8) as if it
were GSM-7, the 0x40 is taken as character '¡', encoded as 0xc2,0xa1
in UTF-8).
2021-02-23 11:35:11 +00:00
Eric Caruso 1800983b6c mm-modem-helpers: add low_nybble_first argument to mm_bcd_to_string
All BCD-encoded strings used by MM currently have the low nybble
of each byte come before the high nybble, but some strings (such
as the EID string returned by QMI Get Slot Status) are meant to
be read in order with the high nybble before the low one. As such,
extend mm_bcd_to_string to decode both.
2020-10-16 11:22:37 -07:00
Aleksander Morgado 426f69d64b tests,modem-helpers: regex number is index of an array, so starts at 0 2020-04-09 12:38:50 +00:00
Aleksander Morgado 8aec9e3889 test,modem-helpers: use MMModem3gppRegistrationState values in tests 2020-04-09 12:38:50 +00:00
Aleksander Morgado c78da3de7e broadband-modem: run +C5GREG state checks
The generic CREG parser is improved to also allow parsing +C5GREG
responses and URCs.
2020-04-09 12:38:50 +00:00
Aleksander Morgado 040eb3880c helpers: use generic number parsing methods in CREG parser
This fixes the s8500 wave unit test, which was incorrectly parsing the
Act field reported as 'B' as "GSM" (strtol(B)=0)

Also, given that the generic parsing methods are able to parse numbers
from quoted strings, this change allows us to remove the Thuraya
specific CREG matching that just took into consideration quoted
strings. The Thuraya unit tests are also fixed up to provide proper
testing of the logic.
2020-04-09 12:38:50 +00:00
Aleksander Morgado 40b36a25ca test,modem-helpers: remove obsolete comments in u-blox CREG tests
We already support "SMS only" registration state.
2020-04-09 12:38:50 +00:00
Aleksander Morgado e956bac47b log: common logging method definition for all testers and helpers 2020-04-08 17:53:42 +02:00
Aleksander Morgado 7004f97093 modem-helpers: make cpms test parser return error on failure 2020-04-08 16:35:09 +02:00
Aleksander Morgado 105cb31e8c modem-helpers: port ccwa service query parser to use object logging 2020-04-08 16:35:09 +02:00
Aleksander Morgado ecd766796a modem-helpers: port cesq response parser to use object logging 2020-04-08 16:35:09 +02:00
Aleksander Morgado ef1a570afe modem-helpers: port creg response parser to use object logging 2020-04-08 16:35:09 +02:00
Aleksander Morgado 39dd4c166d modem-helpers: port clcc list parser to use object logging 2020-04-08 16:35:09 +02:00
Aleksander Morgado 78cad902ef modem-helpers: remove unused supported capabilities filter 2020-04-08 16:35:09 +02:00
Aleksander Morgado 5b1b33a894 modem-helpers: port cmer test parser to use object logging 2020-04-08 16:35:09 +02:00
Aleksander Morgado 740827bde1 modem-helpers: parse cgdcont test parser to use object logging 2020-04-08 16:35:09 +02:00
Aleksander Morgado f76489cd81 modem-helpers: port cid selection helper to use object logging 2020-04-08 16:35:09 +02:00
Aleksander Morgado 2b23ef3fa6 modem-helpers: port cops test parser to use object logging 2020-04-08 16:35:09 +02:00
Aleksander Morgado fb61243b7d modem-helpers: port ifc test parser to use object logging 2020-04-08 16:35:09 +02:00
Aleksander Morgado 0f708daf0b modem-helpers: port supported modes filtering to use object logging 2020-04-08 16:35:09 +02:00
Aleksander Morgado fd1464cff0 modem-helpers: port device identifier to use object logging and autoptr 2020-04-08 16:35:09 +02:00
Aleksander Morgado 9bcadea172 log: new object logging support
So that we can provide the specific object id in every log associated
to a given object.
2020-04-08 16:35:08 +02:00
Aleksander Morgado 9ad6e1f633 test-modem-helpers: fix warnings with -Wswitch-enum
test-modem-helpers.c: In function ‘test_cgev_indication’:
  test-modem-helpers.c:2165:9: error: enumeration value ‘MM_3GPP_CGEV_UNKNOWN’ not handled in switch [-Werror=switch-enum]
   2165 |         switch (type) {
        |         ^~~~~~
  cc1: all warnings being treated as errors
2020-01-31 14:52:49 +01:00
Aleksander Morgado a27c957dc5 test-modem-helpers: fix warnings with -Wsign-compare
test-modem-helpers.c: In function ‘test_creg_match’:
  test-modem-helpers.c:1127:19: error: comparison of integer expressions of different signedness: ‘int’ and ‘guint’ {aka ‘unsigned int’} [-Werror=sign-compare]
   1127 |     for (i = 0; i < array->len; i++) {
        |                   ^
2020-01-31 14:52:49 +01:00
Aleksander Morgado 6dcbda1c80 test-modem-helpers: fix warnings with -Wdiscarded-qualifiers
test-modem-helpers.c: In function ‘test_cmgl_response_generic’:
  test-modem-helpers.c:294:20: error: initialization discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
    294 |             .pdu = "07914306073011F00405812261F700003130916191314095C27"
        |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ...
2020-01-31 14:52:49 +01:00
Aleksander Morgado 1722915f5e broadband-modem: +COPS=? response may give strings in UCS2
If the charset selected via CSCS is UCS2, the modem may decide to
return all the strings in the +COPS=? response in UCS2:

    <debug> (ttyACM0): --> 'AT+COPS=?<CR>'
    <debug> (ttyACM0): <-- '<CR><LF>+COPS: (2,"004D006F007600690073007400610072","004D006F007600690073007400610072","00320031003400300037",7)
    <debug> Found network '00320031003400300037' ('004D006F007600690073007400610072','004D006F007600690073007400610072'); availability: current, access tech: lte
2020-01-06 20:17:08 +00:00