Commit Graph
173 Commits
Author SHA1 Message Date
Aleksander Morgado 32aa8333c6 helpers,tests: update ICCID related unit tests
Fix the test for invalid characters, because now I allow hex chars in
the account number.

And add new tests with real China Mobile ICCIDs that contain hex chars
in the account number.
2018-09-12 17:17:36 +00:00
Aleksander Morgado 0282123287 helpers: allow 19-digit reported ICCIDs
The mm_3gpp_parse_iccid() method does validation of the ICCID string
and was originally implemented to handle +CRSM reported values. The
implementation was looking for 20-digit strings, even for 19-digit
ICCIDs (those finished with a trailing 'F').

We now extend the logic to also validate ICCID strings reported as
19-digit values directly, and when that happens we won't allow
swapping of the digits (a +CRSM specific requirement) or trailing 'F'
characters (as that is only required when reporting 19-digit ICCIDs
with 20-digit strings).

This change allows us to e.g. use the u-blox specific AT+CCID command
and validate the returned ICCID with the same helper method, which
currently fails:

  (ttyACM2): --> 'AT+CCID<CR>'
  (ttyACM2): <-- '<CR><LF>+CCID: 8934077700015848638<CR><LF><CR><LF>OK<CR><LF>'
  couldn't load SIM identifier: 'Invalid ICCID response size (was 19, expected 20)'
2018-09-12 17:17:36 +00:00
Ben Chan 1b3b2e26a7 test,modem-helpers: remove unnecessary NULL check for g_free()
g_free() handles a NULL pointer properly, so there is no need to have a
NULL check before calling g_free().
2018-08-29 08:35:46 +02:00
Aleksander Morgado e17d5a51a2 broadband-bearer: allow matching empty APN when looking for PDP CID
The PDP contexts that are found with an empty APN configured are right
now used as placeholders that can be overwritten with the user
provided APN if no direct match is found.

We want to keep that logic in place, but for the case where we do get
an empty APN requested by the user, we need to perform the full
context match, so that the first PDP context matching the empty APN is
used.

Right now we're overwriting with the empty APN again the last PDP
context found with an empty APN, which doesn't make much sense:

    Apr 27 08:15:21 ModemManager[4251]: <debug> Found '3' PDP contexts
    Apr 27 08:15:21 ModemManager[4251]: <debug>   PDP context [cid=1] [type='ipv4'] [apn='']
    Apr 27 08:15:21 ModemManager[4251]: <debug>   PDP context [cid=2] [type='ipv4'] [apn='broadband']
    Apr 27 08:15:21 ModemManager[4251]: <debug>   PDP context [cid=15] [type='ipv4'] [apn='']
    Apr 27 08:15:21 ModemManager[4251]: <debug> Found PDP context with CID 1 and no APN
    Apr 27 08:15:21 ModemManager[4251]: <debug> Found PDP context with CID 15 and no APN
    Apr 27 08:15:21 ModemManager[4251]: <debug> (ttyUSB3) device open count is 3 (open)
    Apr 27 08:15:21 ModemManager[4251]: <debug> (ttyUSB3) device open count is 2 (close)
    Apr 27 08:15:21 ModemManager[4251]: <debug> (ttyUSB3): --> 'AT+CGDCONT=15,"IP",""<CR>'
    Apr 27 08:15:21 ModemManager[4251]: <debug> (ttyUSB3): <-- '<CR><LF>OK<CR><LF>'
2018-04-30 18:25:49 +02:00
Colin Helliwell 8f26848ef0 helpers: move generic load_unlock_retries from Telit plugin
As a precursor to a generic load_unlock_retries method, move the
CSIM Response parser from the Telit plugin into the core code.
2018-01-01 18:37:10 +01:00
Aleksander Morgado b252ab668f build,tests: make sure tests are rebuilt if helper libs are updated 2017-09-28 23:13:12 +02:00
Aleksander Morgado 5a01e54066 charsets: simplify check to see if conversion to charset possible
Instead of having a method that returns the expected length after the
conversion and the amount of input UTF-8 characters that couldn't be
converted to the given charset, simplify the logic and just define a
method that returns a boolean specifying whether the conversion is
possible or not.

Also, include unit tests.
2017-08-16 16:27:42 +02:00
Aleksander Morgado 1f2bb64028 charsets: ensure all methods are prefixed with 'mm_' 2017-08-16 16:08:15 +02:00
Aleksander Morgado 06fef77cc0 charsets,test: refactor unit tests
These tests don't need fixtures, so use the simpler g_test_add_func()
methods to add tests associated to a test path.
2017-08-16 16:08:15 +02:00
Aleksander Morgado dec53d6ef6 modem-helpers: allow unquoted strings in +CCLK responses
Also:
  * define the leading '+' as a escaped value
  * allow any number of spaces between '+CCLK' and the string value.
2017-08-09 21:59:31 +02:00
Aleksander Morgado 4db3ccf2af helpers: +CNUM parser doesn't return any error 2017-07-19 11:21:27 +02:00
Ben Chan 94a289a1b3 modem-helpers: minor coding style fixes 2017-07-14 10:59:46 +02:00
Daniele Palmas 5820666495 helpers: extend +WS46=? response parser to support ranges
Telit LTE modems could reply to +WS46=? with:

+WS46: (12,22,25,28-31)

This patch extends +WS46=? response parser to support ranges.
2017-06-16 15:48:18 +02:00
Aleksander Morgado 024c7a1a8f broadband-modem: query +CMER format before enabling/disabling
Don't blindly try '+CMER=3,0,0,1' to enable and '+CMER=0' to disable
Mobile Equipment Event Reporting. We now query the device for the
supported formats and use that info to build commands that will work.
2017-05-29 14:58:25 +02:00
Aleksander Morgado e753911a4e helpers: new 'AT+CMER=?' parser 2017-05-29 14:56:54 +02:00
Aleksander Morgado 973c7d0970 helpers: new parser for AT+IFC=?
Instead of having the parser return separate list of supported flow
controls for TE and TA, we simplify it by only returning those
settings that apply to both TE and TA.

This logic isn't perfect either, though, as some settings (e.g. '3' in
TE in some modems, specifying a different XON/XOFF behavior) may not
have a corresponding setting in the other end.

The most common cases we care about (i.e. standard XON/XOFF, RTS/CTS)
should be properly reported with this logic.
2017-04-18 18:08:57 +02:00
Aleksander Morgado fba49d8d00 broadband-modem: normalize also operator code
The operator code (MCCMNC) may also be given encoded in the current
charset (e.g. UCS2).

Based on a patch from Colin Helliwell <colin.helliwell@ln-systems.com>
2017-04-02 10:06:13 +02:00
Aleksander Morgado f824602bdd modem-helpers: if operator not in UCS2, see if already valid UTF-8
The method doing the operator name normalization takes as input the
current configured modem charset. If this is UCS2, we will now just
assume this is a hint: the string may or may not come in hex/UCS2.

This logic makes the custom operator name loading in Huawei unneeded,
if the modem is configured in UCS2, we still properly process operator
names coming in plain ASCII.
2017-04-02 10:06:07 +02:00
Aleksander Morgado 1600911439 broadband-modem,helpers: implement AT+WS46=? response parser
We want a parser that returns the full list of combinations found.
2017-03-24 21:28:34 +01:00
Ben Chan 31655bb5a5 glib: remove invocations of g_type_init()
g_type_init() has been deprecated (and also marked with the attribute
'deprecated') since glib 2.36 as the type system is automatically
initialized. Since the minimum version of glib required by ModemManager
is 2.36, calling g_type_init() isn't necessarily in the ModemManager
code.
2017-02-03 10:05:14 +01:00
Aleksander Morgado 51e3d3d837 modem-helpers: improve +CCLK parsing
Added support for 4-digit format years (i.e. YYYY), and also made the
timezone information optional, as per +CSDF in 3GPP TS 27.007.

https://bugs.freedesktop.org/show_bug.cgi?id=95319
2016-11-18 10:25:07 +01:00
Aleksander Morgado 5a9f093839 modem-helpers: implement less strict APN comparison
u-blox modems will append a string showing the MCC and MNC info to the access
point name listed in AT+CGDCONT? responses. We will try to detect when that
happens, and we just accept the match.

The logic doesn't just look for a string prefix; it also looks for the special
MCC + MNC suffix, which is much more restrictive, to try to avoid false
positives.
2016-10-12 13:24:09 +02:00
Aleksander Morgado 7ab3d3e727 modem-helpers: new helper to parse +CESQ response into MMSignal objects 2016-10-12 13:24:08 +02:00
Aleksander Morgado df6f6d1f37 modem-helpers: new +CESQ response parser 2016-10-12 13:24:08 +02:00
Aleksander Morgado fe460b2f54 3gpp: update registration state enumeration with CSFB related states
Introduce "sms only" and "CSFB not preferred" home/roaming states to be reported
for the CS context, while already registered on LTE.

Based on 3GPP TS 27.007 v13.5.0.
2016-10-12 13:24:08 +02:00
Aleksander Morgado aca6bb1c02 modem-helpers: new +CFUN? response parser 2016-10-12 11:29:52 +02:00
Aleksander Morgado 3a886d848d modem-helpers: new uint list parser, including interval support 2016-10-12 11:29:52 +02:00
Aleksander Morgado 61fbab286c modem-helpers: new CGACT? response parser 2016-10-12 11:29:52 +02:00
Aleksander Morgado 467b3c57f0 modem-helpers: new COPS? response parser
Split into two different actions the actual COPS? response parsing and the
operator name normalization process.

Also, allow parsing not only the operator string, but also the format, mode
and the optional access technology value.
2016-10-12 11:29:52 +02:00
Aleksander Morgado 654f718b06 modem-helpers: new +CGCONTRDP=N response parser 2016-10-12 11:29:52 +02:00
Aleksander Morgado 58c955f5f2 core: allow building and running without udev
Instead of relying on the udev daemon and GUDev to manage the devices reported
by the kernel, we can now run ModemManager relying solely on the kernel events
reported via the new ReportKernelEvent() API. Therefore, the '--no-auto-scan'
option is implicit for the ModemManager daemon when udev is disabled in the
build.

Additionally, a new custom implementation of the kernel device object is
provided, which uses sysfs to load the properties and attributes required in
each kernel device, instead of using a GUdevDevice.

The udev rule files are kept in place, and a simple custom parser is provided
which preloads all rules in memory once and then applies them to the different
kernel objects reported via ReportKernelEvent(), e.g. to set port type hints.
A simple unit test setup is prepared to validate the udev rules during the
`check' Makefile target.
2016-09-29 15:43:05 +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 7fb366c41a core: use MM-specific logging methods always instead of the generic GLib ones 2016-08-15 13:14:47 +02:00
Aleksander Morgado 3b8361eb06 build,core: update build rules
We try to combine in common envvars the compiler and linker flags shared by the
different components, and where possible, also re-using the implicit AM_CFLAGS
and AM_LDFLAGS variables that automake provides, and which apply to all objects
being built in the same Makefile.am.

The internal libmodem-helpers.la library is also renamed to libhelpers.la
2016-03-15 19:15:25 +01:00
Dan Williams 0a9cbf65ea modem-helpers: fix handling split PDP context ID reporting in CGDCONT=? response
Cinterion PHS8-US devices send split PDP context ID like "(1-17,101-112)" and
that caused the modem-helpers to choke.
2016-03-15 10:34:28 -05:00
Carlo Lobrano be317e8b80 broadband-modem: fix +CPMS empty parameter support
* Add new async virtual method init_current_storages to
  MMIfaceModemMessaging
* Add logic of init_current_storages to MMBroadbandModem
* Add step "INIT_CURRENT_STORAGES" in MMIfaceModemMessaging
  initialization in order to load and store current SMS
  storages for mem1 and mem2.
* Add usage of current sms storage value for mem1 in place
  of an empty string parameter when the command AT+CPMS
  is used.

https://bugs.freedesktop.org/show_bug.cgi?id=93135
2016-03-09 14:43:08 +01:00
Thomas Sailer 95876c6f57 helpers: move +CRSM parsing to mm_3gpp_parse_crsm_response
Also added test cases.

Signed-off-by: Thomas Sailer <t.sailer@alumni.ethz.ch>
2016-02-13 14:27:51 +01:00
Thomas Sailer a33615d6cb helpers: allow optional quotes in +CREG: <stat>,"<lac>","<ci>"
GSM 07.07 CREG=2 unsolicited pattern.

Added testcase for Thuraya XT.

Signed-off-by: Thomas Sailer <t.sailer@alumni.ethz.ch>
2016-02-13 14:24:54 +01:00
Thomas Sailer 4442173dcf modem-helpers: allow optional whitespace in +CGDCONT response
Add testcase for Thuraya XT.

Signed-off-by: Thomas Sailer <t.sailer@alumni.ethz.ch>
2016-02-11 15:34:25 +01:00
Aleksander Morgado 508a37a891 modem-helpers: fix parsing CPMS=? responses without groups
The CPMS test parser was expecting 3 groups (parenthesis enclosed lists) of
memory IDs, e.g.:

   +CPMS: ("SM","ME"),("SM","ME"),("SM","ME")

But some modems like the Huawei MU609 may just report single elements, not
groups, e.g.:

   +CPMS: "SM","SM","SM"

This patch avoids using g_strsplit() to split the groups, as that is unaware
of the possible replies without groups. Instead, a new helper method is
implemented which does the group/item split itself, considering also the
possibility of a reply with mixed groups and non-groups, like e.g.:

   +CPMS: ("SM","ME"),"SM","SM"

Additionally, we also now support the case where the groups are empty, e.g.:

   +CPMS: (),(),()

https://bugs.freedesktop.org/show_bug.cgi?id=92243
2015-12-02 22:34:37 +01:00
Aleksander Morgado 585320e0b4 tests: plug memleak in +CMGR response parser 2015-09-22 09:34:22 +02:00
Nick Stevens eaf65ed98d core: process SMS +CGMR response with regex
Variability in the response style from certain modems causes the parsing
of the +CGMR response to fail. For example, the Telit HE910 inserts an
empty string ("") in the second field of the response, causing the
sscanf implementation to fail.

This patch converts the parsing of the CGMR response to a regex that
allows for more flexibility and robustness, and adds unit tests around
the parsing call.

Signed-off-by: Nick Stevens <Nick.Stevens@digi.com>
2015-09-22 09:24:18 +02:00
Jason Simmons 3ad64c8f5a broadband-modem: default implementation of the network time interface
Add a default implementation that queries the real-time clock using the
AT+CCLK? command.  Also set AT+CTZU=1 in case a modem requires it.
2015-03-23 11:31:32 +01:00
Jakub Sitnicki 7552030ef9 build: add code coverage support
Build all targets, except for CLI tools (mmcli, uml290), with special
flags needed for collecting code coverage information when the build has
been configured with --enable-code-coverage.

Three new targets are available in the top build directory:

 - `check-code-coverage' runs the test suite and generates a code
   coverage report,

 - `code-coverage-capture' generates a code coverage report from already
   collected data, which can come in handy when one wants to see code
   paths touched by a particular test,

 - `code-coverage-clean' removes the collected coverage data and the
   generated reports.
2015-01-11 19:32:43 +01:00
Aleksander Morgado f2fa7a7fbf qcdm: don't retry probing if QCDM unescaping fails
But keep the retries when the frame marker isn't found.

https://bugzilla.gnome.org/show_bug.cgi?id=708861
2014-10-15 18:29:18 +02:00
Aleksander Morgado e0f3716d26 modem-helpers: don't return any result if an error happens when parsing CPMS=?
We shouldn't rely on the caller to cleanup intermediate results when returning
an error.
2014-06-27 09:20:40 +02:00
Ben Chan 7c389511d8 tests: fix more memory leaks 2014-06-03 10:51:51 +02:00
Ben Chan 6e7bae9dc5 tests: fix memory leaks
This patch fixes memory leaks in unit tests detected by LeakSanitizer.
2014-05-30 13:31:41 +02:00
Ben Chan 37b0402ee5 core: minor coding style fixes 2014-05-20 09:32:29 +02:00
Aleksander Morgado a2f4fbe373 port-serial-qcdm: commands are never cached
The QCDM port commands are never cached, so remove the option from the command()
method. Will also simplify command caching afterwards as it will be an AT-only
thing.
2014-02-13 13:40:44 +01:00