Commit Graph
6 Commits
Author SHA1 Message Date
Dominique Martinet 5e12f3fab5 tests: modem-helpers: test parsing multiple creg
The test_creg_match helper would only parse the first match, but actual
code e.g. parse_unsolicited() in src/mm-port-serial-at.c iterates over
all matches:
this updates the test to loop similarily to what is done in real code.

There were two tests assuming only the first match gets matched, so
their result were updated, and a third test was added matching the URC
received from a SIM7672 modem (including unrelated CNSMOD message)

Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
2026-09-08 18:52:03 +02:00
Dominique Martinet 04c9797456 modem-helpers: fix multiple C*REG events in single URC
When receiving a message from modem containing multiple CREG events that
have different format, the parsing happens in the order CREG regexes are
registered, and not in the order the modem sent the events.

That means that when receiving the following URC:
<CR><LF>+CEREG:  2<CR><LF><CR><LF>+CNSMOD: 8<CR><LF><CR><LF>+CEREG: 1,AAAA,01234567,7<CR><LF>
we'd incorrectly parse the `CEREG: 1` before `CEREG: 2`, and remember
the state as searching (2) instead of home (1), which can cause trouble
connecting because of waiting for state to go home which would never
happen again.

This fixes that problem by merging all the regexes together, so the
parsing should properly process the events in matching order in
parse_unsolicited()

Unfortunately changing the regex like this means that
mm_3gpp_parse_creg_response() match info handling also needs to be
reworked: matches number are increased for each regex, so we can
reliably know which regex was matched based on match count.
This is actually cleaner than the old approach that just guessed if nth
field with "item_is_lac_not_stat()", but requires careful testing.

This was validated checking that tests fail if any of the indices is
changed by iterating over them all and running the test:
grep -n 'n_matches -' src/mm-modem-helpers.c | sed -e 's/:.*//' \
	| while read lineno; do
		echo $lineno
		git show HEAD:src/mm-modem-helpers.c \
			| awk -v l=$lineno '{ if (NR == l) {
					print $1,$2,$3,$4,$5 - 1,";"
				} else {
					print
			}}' > src/mm-modem-helpers.c
		ninja -C build src/tests/test-modem-helpers || break
		build/src/tests/test-modem-helpers && break
	done

A test case was added to make this work, as the Samsung Wave S8500
sample 'act' doesn't seem to actually be a technology value?

(case 36/42 could actually be merged but were kept separate on purpose
for easier maintenance/testing)

Fixes: #1087
Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
2026-09-08 18:51:58 +02:00
Dominique Martinet 0780526594 base-bearer: set dbus disconnect_request on ignored disconnection
When we get a disconnect event that we wanted to ignore, set the
DisconnectRequest property instead so clients on dbus can act on it.

Also upgrade the logs from dbg to msg (info) as there would be otherwise
no message indicating the disconnect request if it is not acted on.

This was checked with dbus-monitor:
```
$ dbus-monitor  --system "type='signal',sender='org.freedesktop.ModemManager1'"
signal time=1747362238.227804 sender=:1.73798 -> destination=(null destination) serial=741 path=/org/freedesktop/ModemManager1/Bearer/0; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.freedesktop.ModemManager1.Bearer"
   array [
      dict entry(
         string "DisconnectRequest"
         variant             boolean true
      )
   ]
   array [
   ]
```

Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
2025-05-16 22:06:24 +09:00
Dominique Martinet dea8f27464 api,bearer: new 'DisconnectRequest' property
To report that the bearer has been killed from the modem side and
the connection should be terminated.

Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
2025-05-16 22:06:24 +09:00
Dominique Martinet 2d29832f89 dispatcher-connection: add new 'disconnect-request' event
When bearer gets an event that should trigger a disconnection but we
cannot disconnect (for example because we're waiting for pppd to close),
we now trigger a new 'disconnect-request' event instead

This was tested with the following hook:
```
$ cat /etc/ModemManager/connection.d/handle-disconnect-request.sh
#!/bin/sh

if [ "$4" != disconnect-request ]; then
	exit 0
fi

iface=$(mmcli -b "$2" -K | awk '/bearer.status.interface/ { print $3 }')

if pkill -f "pppd\>.*\<$iface\>"; then
	logger -t mm-disconnect-request "Killed $iface pppd"
else
	logger -t mm-disconnect-request "No pppd found for $iface"
fi
```

Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
2025-05-16 22:06:10 +09:00
Dominique Martinet f3aaa113e0 dispatcher-connection: replace 'connected' boolean with a new enum
The next commit will introduce a new dispatcher event.
This commit should not change anything user-facing

Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
2025-05-16 15:34:02 +09:00