diff --git a/docs/TELEPHONY-APPS-PLAN.md b/docs/TELEPHONY-APPS-PLAN.md index 1e4011606..d5a67a99b 100644 --- a/docs/TELEPHONY-APPS-PLAN.md +++ b/docs/TELEPHONY-APPS-PLAN.md @@ -163,13 +163,29 @@ Today `omamobile-sit-data` puts `rmnet0` behind Wi-Fi with metric 700, and Netwo | Need | How | Ready? | | --- | --- | --- | -| WAP push (the MMS notification) arrives as a binary SMS | sitd passes the PDU's user data through; the bridge exports an `Sms` with `Data` set and `Text` empty, which mmsd-tng picks up | No: the codec keeps the bytes but nothing passes them on (T0, T3) | -| An APN that carries MMS | mmsd-tng's `MMS_APN` must match the connected bearer's APN. mmsd-tng supports no separate MMS bearer ("limitations of Modem Manager", its README), so the carrier must allow MMS on the internet APN. Many US carriers do; check ours (Q8) | Our config has one APN (`[network] apn`) | +| WAP push (the MMS notification) arrives as a binary SMS | sitd passes the PDU's user data through; the bridge exports an `Sms` with `Data` set and `Text` empty, which mmsd-tng picks up; on a phone without mmsd-tng installed the bridge exports the placeholder text instead, so Messages shows that a message came | Yes for the 9a's stack (#697): sitd keeps each part's WAP port and delivers a joined push as data; the bridge exports it with `Data` | +| An APN that carries MMS | mmsd-tng's `MMS_APN` must match the connected bearer's APN. mmsd-tng supports no separate MMS bearer ("limitations of Modem Manager", its README), so the carrier must allow MMS on the internet APN. Many US carriers do; check ours (Q8) | On the palmtop's carrier the MMS APN is the internet APN. A second bearer on it took the IMS bearer down (2026-11-02), so sitd sets up none | | Fetch from the MMSC over mobile data, even with Wi-Fi up | mmsd-tng binds HTTP to the bearer's interface (`SO_BINDTODEVICE`, `src/service.c:3720-3732`) and resolves through that interface's DNS (c-ares or systemd-resolved with the ifindex). Needs `CarrierMMSC`, `CarrierMMSProxy`, or `http://mms.invalid` to look them up in mobile-broadband-provider-info | **Depends on M4.3:** rmnet0 is configured IPv4 only (MODEM-CLIENT §1.3). If the carrier's bearer is IPv6-only (common on T-Mobile's network [I]), MMS needs IPv6 on rmnet0 first. The packet processor (MODEM-PLAN 6.3) is built but untested on hardware; the legacy buffers carry data meanwhile | | Sending MMS | mmsd-tng posts the M-Send.req to the MMSC the same way | as above | -| Storage and UI | mmsd-tng stores messages and serves `org.ofono.mms` on the session bus; Chatty and our app are its clients | install `mmsd-tng` (T3) | +| Storage and UI | mmsd-tng stores messages and serves `org.ofono.mms` on the session bus; Chatty and our app are its clients | `packages/mmsd-tng` (2.6.4, #697), not enabled; Messages' side is in the omatel apps (T3) | | Group MMS | MMS with several recipients; mmsd-tng handles the PDUs | with the above | +**The bearer for mmsd-tng (#697):** sitd reports the internet bearer's device (the one omamobile-sit-data found and kept: a candidate still being probed isn't reported), address and DNS in its private status, and the bridge publishes them on the bearer (`Interface`, `Ip4Config`). mmsd-tng binds to that device and resolves the MMSC through those servers, so MMS goes over cellular with Wi-Fi up, without touching the system's routes or DNS. + +**Received on 2026-11-03** (the palmtop, the daily kernel `7.3.0-rc6-omamobile-tegu-s2mpg15-m1-g991042e2eff3-dirty`, this stack): one picture from the owner's iPhone. The WAP push arrived as a binary SMS during a call, sitd stored it, the bridge exported it with the internet bearer's device and DNS, and mmsd-tng, started afterwards, fetched the 708 KB message over `rmnet0` with Wi-Fi up (state `received`, a PNG inside). It logged one complaint, an IP config without a method, fixed in the bridge since. Messages doesn't show it yet (T3 in the apps). + +**Attended runbook, receive first (9a; steps 1 to 4 passed on 2026-11-03):** + +| Step / risk | Commands or action | Expect / pass | Stop condition | Rollback | +| --- | --- | --- | --- | --- | +| 1. Read-only / none | `uname -r`; `pacman -Q omamobile-modem-sit omamobile-mmd mmsd-tng`; `omamobile-sit status`; `busctl --system get-property org.freedesktop.ModemManager1 org.freedesktop.ModemManager1.Bearer Interface Ip4Config` | Registered with data; the bearer's Interface is the found device and Ip4Config has an address and DNS | No address or DNS, no data | None | +| 2. Settings / low | As the session user, `~/.mms/modemmanager/mms` (mode 0600) from `/usr/share/mmsd-tng/mms.example`: the carrier's MMSC, the APN (the internet APN), the proxy or `NULL`, the palmtop's number; `ForceCAres=true` | A private file, nothing started | Credentials or an IPv6-only MMS bearer needed | Remove the file | +| 3. Daemon / low | `systemctl --user start mmsd-tng.service` (never `-d`) | `org.ofono.mms` on the session bus | Startup errors | `systemctl --user stop mmsd-tng.service` | +| 4. Receive / medium | The owner sends one small picture to the palmtop, Wi-Fi up | One WAP push, one downloaded message in mmsd-tng's store, calls and texts unchanged | A download or routing failure, a second WAP consumer | Stop the daemon; keep its store | +| 5. Send / medium (after the apps' T3 changes) | One small picture from Messages to the owner | One copy received | An uncertain send: don't press Send again | Stop the daemon | + +Never publish the MMSC, the APN, numbers, message URLs, WAP bytes or attachments, or mmsd-tng's debug output. + **What our data path still lacks for MMS** (MODEM-PLAN 6.3 and MODEM-CLIENT §1.3): M4.3 passing on the phone, IPv6 on `rmnet0` (or proof that the carrier gives IPv4), and the bearer exported as a Bearer object. Throughput isn't an issue for MMS (messages are a few hundred kB), so the packet processor isn't a prerequisite. ### 1.8 Requirements against MODEM-PLAN diff --git a/packages/mmsd-tng/0001-use-configured-number-with-empty-own-numbers.patch b/packages/mmsd-tng/0001-use-configured-number-with-empty-own-numbers.patch new file mode 100644 index 000000000..ec66b5c36 --- /dev/null +++ b/packages/mmsd-tng/0001-use-configured-number-with-empty-own-numbers.patch @@ -0,0 +1,16 @@ +From: W4HO <87742609+W4HO-ham@users.noreply.github.com> +Subject: [PATCH] MMS: apply the configured number when OwnNumbers is empty + +--- a/plugins/modemmanager.c ++++ b/plugins/modemmanager.c +@@ -1761,6 +1761,10 @@ + } + } + ++ /* An empty OwnNumbers array never enters the loop above. */ ++ if (!modem->modem_number_known && modem->modem_number) ++ mms_service_set_own_number (modem->service, modem->modem_number); ++ + gdbus_modem = MM_GDBUS_MODEM (modem->modem); + + modem->modem_state_watch_id = g_signal_connect (gdbus_modem, diff --git a/packages/mmsd-tng/0002-close-socket-on-interface-bind-failure.patch b/packages/mmsd-tng/0002-close-socket-on-interface-bind-failure.patch new file mode 100644 index 000000000..25532cb99 --- /dev/null +++ b/packages/mmsd-tng/0002-close-socket-on-interface-bind-failure.patch @@ -0,0 +1,17 @@ +From: W4HO <87742609+W4HO-ham@users.noreply.github.com> +Subject: [PATCH] MMS: fail closed if the bearer interface cannot be bound + +--- a/src/service.c ++++ b/src/service.c +@@ -3735,7 +3735,10 @@ + if (return_code == 0) + DBG ("Socket is bound to %s", request->service->interface); + else +- DBG ("Socket could not be bound! Error: %d", return_code); ++ { ++ g_warning ("MMS interface binding failed; closing socket"); ++ g_socket_close (msg_socket, NULL); ++ } + + g_signal_handler_disconnect (msg, + request->soupmessage_network_event_signal_id); diff --git a/packages/mmsd-tng/0003-link-modern-libphonenumber-dependencies.patch b/packages/mmsd-tng/0003-link-modern-libphonenumber-dependencies.patch new file mode 100644 index 000000000..181f41e38 --- /dev/null +++ b/packages/mmsd-tng/0003-link-modern-libphonenumber-dependencies.patch @@ -0,0 +1,25 @@ +From: W4HO <87742609+W4HO-ham@users.noreply.github.com> +Subject: [PATCH] build: link dependencies used by modern libphonenumber headers + +--- a/meson.build ++++ b/meson.build +@@ -119,6 +119,8 @@ + dependency('libsoup-3.0'), + dependency('libcares', version : '>=1.18.1'), + cc.find_library('dl'), ++ dependency('protobuf'), ++ dependency('absl_absl_check'), + cc.find_library('phonenumber', required: true) + ] + +--- a/unit/meson.build ++++ b/unit/meson.build +@@ -3,6 +3,8 @@ + dependency('mm-glib', version : '>=1.14'), + dependency('libcares', version : '>1.17'), + cc.find_library('dl'), ++ dependency('protobuf'), ++ dependency('absl_absl_check'), + cc.find_library('phonenumber', required: true) + ] + diff --git a/packages/mmsd-tng/0004-accept-international-own-number-with-redacted-IMSI.patch b/packages/mmsd-tng/0004-accept-international-own-number-with-redacted-IMSI.patch new file mode 100644 index 000000000..c00183f3b --- /dev/null +++ b/packages/mmsd-tng/0004-accept-international-own-number-with-redacted-IMSI.patch @@ -0,0 +1,42 @@ +From: W4HO <87742609+W4HO-ham@users.noreply.github.com> +Subject: [PATCH] MMS: accept an international own number with a redacted IMSI + +--- a/src/service.c ++++ b/src/service.c +@@ -3159,6 +3159,10 @@ + g_warning ("mms_service_set_own_number(): Number is NULL!"); + return FALSE; + } ++ /* A redacted IMSI supplies no region. An international own number ++ * can still be parsed without guessing a country for national numbers. */ ++ if (service->country_code == NULL && own_number[0] == '+') ++ service->country_code = g_strdup ("ZZ"); + if (service->country_code == NULL) + { + g_warning ("Country Code is NULL!"); +--- a/unit/test-phone-utils.c ++++ b/unit/test-phone-utils.c +@@ -113,6 +113,15 @@ + g_assert_cmpstr (output, ==, carrer_vvm_test3); + } + ++static void ++international_number_without_imsi (void) ++{ ++ g_autofree char *number = phone_utils_format_number_e164 ("+12025550123", "ZZ", FALSE); ++ g_autofree char *national = phone_utils_format_number_e164 ("2025550123", "ZZ", FALSE); ++ g_assert_cmpstr (number, ==, "+12025550123"); ++ g_assert_null (national); ++} ++ + int + main (int argc, + char **argv) +@@ -123,5 +132,7 @@ + NULL, test_number_decode); + + ++ g_test_add_func ("/mmsutil/international-number-without-imsi", ++ international_number_without_imsi); + return g_test_run (); + } diff --git a/packages/mmsd-tng/PKGBUILD b/packages/mmsd-tng/PKGBUILD new file mode 100644 index 000000000..22674210f --- /dev/null +++ b/packages/mmsd-tng/PKGBUILD @@ -0,0 +1,49 @@ +# SPDX-License-Identifier: MIT +# Maintainer: W4HO <87742609+W4HO-ham@users.noreply.github.com> +pkgname=mmsd-tng +pkgver=2.6.4 +pkgrel=1 +pkgdesc="MMS daemon using ModemManager, with an opt-in user service" +arch=(aarch64) +url="https://gitlab.com/kop316/mmsd" +license=('GPL-2.0-only') +depends=(c-ares mobile-broadband-provider-info 'libmm-glib>=1.24' libsoup3 libphonenumber glib2 glibc gcc-libs protobuf abseil-cpp) +makedepends=(meson ninja pkgconf) +provides=(mmsd) +conflicts=(mmsd mmsd-tng-git) +options=('!lto') +source=("$pkgname-$pkgver.tar.gz::$url/-/archive/$pkgver/mmsd-$pkgver.tar.gz" + '0001-use-configured-number-with-empty-own-numbers.patch' + '0002-close-socket-on-interface-bind-failure.patch' + '0003-link-modern-libphonenumber-dependencies.patch' + '0004-accept-international-own-number-with-redacted-IMSI.patch') +sha256sums=('5772d4d1830664404d8f6ed96d9c35f6e7a53c60b1ac5571cd2a6183c7e633ed' + '2bddbd5812356656162920a8cf145a69a529f6e33a2109633de6b508aee99d8e' + '4c0a0997edfb936c50807459c51b97b55be6a404faf51bbcf7c993faf5041add' + '9875223ed387fc778d05e1624237fc94732822a09f9e847c52ce8be26a427008' + '6f1aedf09714b94415a608e591aefaa72e7539823b580ac493ce19022a5c7896') + +prepare() { + cd "mmsd-$pkgver" + patch -Np1 -i "$srcdir/0001-use-configured-number-with-empty-own-numbers.patch" + patch -Np1 -i "$srcdir/0002-close-socket-on-interface-bind-failure.patch" + patch -Np1 -i "$srcdir/0003-link-modern-libphonenumber-dependencies.patch" + patch -Np1 -i "$srcdir/0004-accept-international-own-number-with-redacted-IMSI.patch" +} + +build() { + arch-meson "mmsd-$pkgver" build -Dbuild-mmsctl=false + meson compile -C build +} + +check() { + meson test -C build --print-errorlogs + "$startdir/test/all" +} + +package() { + DESTDIR="$pkgdir" meson install -C build + install -Dm644 "$startdir/systemd/mmsd-tng.service" "$pkgdir/usr/lib/systemd/user/mmsd-tng.service" + install -Dm644 "$startdir/config/mms.example" "$pkgdir/usr/share/mmsd-tng/mms.example" + install -Dm644 "$startdir/README.md" "$pkgdir/usr/share/doc/mmsd-tng/README.md" +} diff --git a/packages/mmsd-tng/README.md b/packages/mmsd-tng/README.md new file mode 100644 index 000000000..b5468f1a9 --- /dev/null +++ b/packages/mmsd-tng/README.md @@ -0,0 +1,53 @@ + +# mmsd-tng + +An opt-in, per-user MMS daemon using ModemManager's D-Bus API. It never +starts the modem or sitd. This package alone does not enable picture +messages in Messages: omatel-agent and omamessages need their T3 changes +in their own repositories. See `docs/TELEPHONY-APPS-PLAN.md` section 1.7. + +Neither Arch nor Arch Linux ARM packages mmsd-tng (checked 2026-11-03), so +this recipe builds upstream's 2.6.4 tag with the AUR recipe's runtime +dependencies and a checked source checksum. + +Sources: [AUR recipe](https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=mmsd-tng-git), +[upstream 2.6.4](https://gitlab.com/kop316/mmsd/-/tree/2.6.4), +[Arch Linux ARM package indexes](https://de3.mirror.archlinuxarm.org/aarch64/extra/). +Upstream is GPL-2.0; its LGPL components retain their notices. Patches use +the corresponding upstream file's license. + +The patches, and what drops each at a later version bump: + +- `0001` uses the configured own number when ModemManager's OwnNumbers is + empty. Offered upstream as + [mmsd!133](https://gitlab.com/kop316/mmsd/-/merge_requests/133). +- `0002` closes the HTTP socket when it can't be bound to the interface. + Offered upstream as + [mmsd!134](https://gitlab.com/kop316/mmsd/-/merge_requests/134). +- `0003` links protobuf and Abseil, which current libphonenumber headers + need. Not offered upstream yet. +- `0004` parses an international own number without a region taken from the + IMSI. Not offered upstream yet. + +mmsd-tng fetches MMS over a connected bearer whose APN is its `MMS_APN`, +bound to that bearer's device and resolving through the DNS in its +`Ip4Config`. On the 9a that's the internet bearer, where the carrier's MMS +APN is the internet APN: omamobile-mmd gives it the device sitd's data +network found and the carrier's DNS (see docs/TELEPHONY-APPS-PLAN.md 1.7). +Nothing is set up just for MMS, and the system's routes and DNS aren't +touched. A carrier with a separate MMS APN isn't supported yet. + +Owner configuration, before the first start: copy +`/usr/share/mmsd-tng/mms.example` to `~/.mms/modemmanager/mms` (mode 0600) +as the same session user as omatel-agent, and replace ``, `` (the +internet APN) and ``. Keep `ForceCAres=true` so DNS goes to the +bearer's servers. Set the MMS proxy to the carrier's `host:port`, or `NULL` +when there's none. Then `systemctl --user start mmsd-tng.service`. + +No unit is enabled or D-Bus activated by this package. No carrier settings +are shipped. Do not enable upstream debug logging on the phone: it can +print numbers, message URLs, settings and message content. Never publish +its journal, settings, message store, WAP bytes or attachments. + +IPv4 only for now (including an IPv4v6 bearer's IPv4 address and DNS); +IPv6-only MMS, modem suspend and carrier acceptance need attended runs. diff --git a/packages/mmsd-tng/config/mms.example b/packages/mmsd-tng/config/mms.example new file mode 100644 index 000000000..e7a22ed6a --- /dev/null +++ b/packages/mmsd-tng/config/mms.example @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: MIT +# Copy to ~/.mms/modemmanager/mms with mode 0600, before starting mmsd-tng. +# Replace placeholders privately. The APN is the internet APN ([network] apn). +[Modem Manager] +CarrierMMSC= +MMS_APN= +# NULL means no proxy. Otherwise use the carrier's host:port, without a URL scheme. +CarrierMMSProxy=NULL +# Fill in your own phone number; omamobile-mmd deliberately exports no OwnNumbers. +ModemNumber= +AutoProcessOnConnection=true +AutoProcessSMSWAP=true + +[Settings] +# Use only the bearer's DNS and interface, without changing system DNS. +ForceCAres=true diff --git a/packages/mmsd-tng/systemd/mmsd-tng.service b/packages/mmsd-tng/systemd/mmsd-tng.service new file mode 100644 index 000000000..9e52fd558 --- /dev/null +++ b/packages/mmsd-tng/systemd/mmsd-tng.service @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: MIT +[Unit] +Description=MMS transport for the current user +After=dbus.service + +[Service] +ExecStart=/usr/bin/mmsdtng +Restart=no +UMask=0077 + +[Install] +WantedBy=default.target diff --git a/packages/mmsd-tng/test/all b/packages/mmsd-tng/test/all new file mode 100755 index 000000000..fe6cd60d3 --- /dev/null +++ b/packages/mmsd-tng/test/all @@ -0,0 +1,27 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +set -euo pipefail +cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." +bash -n PKGBUILD +python3 - <<'PY' +import configparser +import hashlib +from pathlib import Path +import re +text = Path('PKGBUILD').read_text() +assert 'arch=(aarch64)' in text +assert 'meson test -C build --print-errorlogs' in text +assert 'arch-meson "mmsd-$pkgver" build' in text +assert 'SKIP' not in text +for path in Path('.').glob('*.patch'): + assert hashlib.sha256(path.read_bytes()).hexdigest() in text, path +unit = Path('systemd/mmsd-tng.service').read_text() +assert 'ExecStart=/usr/bin/mmsdtng\n' in unit and 'Restart=no' in unit +assert not re.search(r'^(Requires|Wants|BindsTo|ExecStartPre|ExecStartPost)=', unit, re.M) +config = configparser.ConfigParser(interpolation=None) +config.read('config/mms.example') +assert config['Modem Manager']['CarrierMMSC'] == '' +assert config['Modem Manager']['MMS_APN'] == '' +assert config['Settings'].getboolean('ForceCAres') +print('ok - pinned source, patches, aarch64 recipe and opt-in configuration') +PY diff --git a/packages/omamobile-mmd/PKGBUILD b/packages/omamobile-mmd/PKGBUILD index faba84561..c1f3cf099 100644 --- a/packages/omamobile-mmd/PKGBUILD +++ b/packages/omamobile-mmd/PKGBUILD @@ -7,7 +7,10 @@ pkgdesc="Omarchy Mobile ModemManager-compatible bridge: org.freedesktop.ModemMan arch=(aarch64) url="https://github.com/derekross/omarchy-mobile" license=(MIT) -depends=(python python-gobject glib2 dbus polkit 'omamobile-modem-sit>=0.3.0') +# modem-sit from the version that reports the internet bearer's device, +# address and DNS in its status: with an older one the bearer's Interface +# would stay empty for good. +depends=(python python-gobject glib2 dbus polkit 'omamobile-modem-sit>=0.3.37') checkdepends=(dbus) # It owns ModemManager's bus name and ships its bus policy and polkit # actions. Nothing in Arch or Arch Linux ARM hard-depends on modemmanager diff --git a/packages/omamobile-mmd/lib/bridge.py b/packages/omamobile-mmd/lib/bridge.py index b02e80f3a..7e0ca7d52 100644 --- a/packages/omamobile-mmd/lib/bridge.py +++ b/packages/omamobile-mmd/lib/bridge.py @@ -22,6 +22,7 @@ """ import hashlib import itertools +from pathlib import Path import re import uuid @@ -43,6 +44,12 @@ DEVICE = '/sys/devices/platform/cpif' LIVE = (mm.CALL_DIALING, mm.CALL_RINGING_OUT, mm.CALL_RINGING_IN, mm.CALL_ACTIVE, mm.CALL_HELD, mm.CALL_WAITING) +# A WAP push (an MMS notification) goes to clients as binary data only where +# something can fetch the message: mmsd-tng, by its binary. Elsewhere the +# owner at least learns that a message came. +MMS_DAEMON = Path('/usr/bin/mmsdtng') +NO_MMS_TEXT = 'Received a multimedia or binary message that this phone cannot display yet.' + NOT_YET = { 'data': 'Mobile data through ModemManager (T3); omamobile-sit-data owns rmnet0 for now', 'pin': 'SIM PIN entry (T8); take the PIN lock off in another phone', @@ -103,6 +110,9 @@ def is_emergency(number, d): return re.sub(r'[\s().-]', '', number) in d['emergency_numbers'] +# MM_BEARER_IP_METHOD_UNKNOWN: a bearer IP config with nothing in it. +NO_IP_CONFIG = {'method': GLib.Variant('u', 0)} + class Bridge: def __init__(self, exporter, link, settings): self.x = exporter @@ -189,7 +199,8 @@ def update_modem(self, d): if d['data'] and not self.bearer: self.create_bearer(d) if self.bearer: - self.x.set(self.bearer, mm.BEARER, Connected=d['data']) + self.x.set(self.bearer, mm.BEARER, Connected=d['data'], Interface=self.internet_interface(), + Ip4Config=self.internet_ipv4(d), Ip6Config=NO_IP_CONFIG) for name in d['interfaces']: if not self.x.has(self.modem, name): self.x.add_interface(self.modem, name, self.interface_props(name, d)) @@ -285,11 +296,32 @@ def sim_dynamic(self, d): OperatorIdentifier=d['plmn'] if d['home'] else '', OperatorName=d['operator_name'] if d['home'] else '') + def internet_interface(self): + # The device omamobile-sit-data found carrying the internet bearer, + # which isn't always rmnet; empty until sitd reports it, as + # MM leaves a bearer's interface empty before it has one (a guess + # such as rmnet0 can be another bearer's device for a while). + return ((self.status or {}).get('internet') or {}).get('interface') or '' + + def internet_ipv4(self, d): + # The address and the carrier's DNS, as MM gives them: mmsd-tng + # resolves the MMSC through these where MMS goes over this bearer. + net = (self.status or {}).get('internet') or {} + if not d['data'] or not net.get('address'): + # libmm-glib rejects an IP config without a method (mmsd-tng + # logged "method not given"): unknown, as MM reports no config. + return NO_IP_CONFIG + return {'method': GLib.Variant('u', 2), 'address': GLib.Variant('s', net['address']), + 'prefix': GLib.Variant('u', 32), + **{'dns' + str(i): GLib.Variant('s', value) for i, value in enumerate(net.get('dns', [])[:3], 1)}} + def create_bearer(self, d): self.bearer = self.path('Bearer') apn, ip_type = self.apn_settings() self.x.add(self.bearer, {mm.BEARER: dict( - Interface='rmnet0', Connected=d['data'], IpTimeout=20, BearerType=mm.BEARER_DEFAULT, + Interface=self.internet_interface(), Connected=d['data'], Ip4Config=self.internet_ipv4(d), + Ip6Config=NO_IP_CONFIG, + IpTimeout=20, BearerType=mm.BEARER_DEFAULT, ProfileId=-1, Properties={'apn': GLib.Variant('s', apn), 'ip-type': GLib.Variant('u', IP_TYPES.get(ip_type, mm.IP_V4V6))})}, self.handle_bearer) @@ -452,9 +484,14 @@ def fetched(self, result, error): if sid not in wanted or sid in self.sitd_sms: continue data = bytes.fromhex(message.get('data') or '') + text = message.get('text', '') + if data and not text and not MMS_DAEMON.exists(): + # Nothing on this phone takes a WAP push: Messages would show + # nothing at all, so it gets the placeholder as a text. + text, data = NO_MMS_TEXT, b'' path = self.new_message(dict( sid=sid, State=mm.SMS_RECEIVED, PduType=mm.PDU_DELIVER, Number=message.get('number', ''), - Text=message.get('text', ''), Data=data, Timestamp=message.get('timestamp', ''), + Text=text, Data=data, Timestamp=message.get('timestamp', ''), Storage=mm.STORAGE_ME), received) print(f'SMS {path} received{" (binary data: a WAP push)" if data else ""}', flush=True) if any(i not in self.sitd_sms for i in self.status.get('sms', {}).get('received', [])): diff --git a/packages/omamobile-mmd/lib/main.py b/packages/omamobile-mmd/lib/main.py index 170348afe..c11a857a9 100644 --- a/packages/omamobile-mmd/lib/main.py +++ b/packages/omamobile-mmd/lib/main.py @@ -7,7 +7,7 @@ see a modem. It never talks to the modem itself: sitd stays the only owner of the SIT channel, and nothing here starts the modem or sitd. - omamobile-mmd [--socket PATH] [--sit-config PATH] [--no-polkit] + omamobile-mmd [--socket PATH] [--sit-config PATH] [--mms-daemon PATH] [--no-polkit] --no-polkit skips the polkit checks (offline tests on a private bus only; the shipped unit keeps them). DBUS_SYSTEM_BUS_ADDRESS picks another bus. @@ -15,11 +15,13 @@ import argparse import configparser import os +from pathlib import Path import signal import sys from gi.repository import Gio, GLib +import bridge as bridge_module import mm_api from bridge import Bridge from exporter import Exporter @@ -50,8 +52,11 @@ def main(argv=None): parser = argparse.ArgumentParser(description="ModemManager's D-Bus API in front of omamobile-sitd") parser.add_argument('--socket', default=os.path.join(RUN, 'socket'), help="omamobile-sitd's socket") parser.add_argument('--sit-config', default=SIT_CONFIG, help="omamobile-sitd's settings (the APN)") + parser.add_argument('--mms-daemon', default=str(bridge_module.MMS_DAEMON), + help='the MMS daemon whose presence makes a WAP push binary data (tests)') parser.add_argument('--no-polkit', action='store_true', help='skip polkit (offline tests only)') args = parser.parse_args(argv) + bridge_module.MMS_DAEMON = Path(args.mms_daemon) loop = GLib.MainLoop() state = dict(bridge=None, link=None, code=0) diff --git a/packages/omamobile-mmd/test/env.py b/packages/omamobile-mmd/test/env.py index 20506a623..07953cc59 100644 --- a/packages/omamobile-mmd/test/env.py +++ b/packages/omamobile-mmd/test/env.py @@ -213,6 +213,9 @@ def __init__(self, bus, socket_path, directory, *args): f.write('[network]\napn = internet.example\nip_type = ipv4v6\n') with open(self.log, 'w') as log: polkit = [] if '--polkit' in args else ['--no-polkit'] + # As on a phone with mmsd-tng installed, unless a test says otherwise. + if '--mms-daemon' not in args: + polkit += ['--mms-daemon', sys.executable] self.proc = subprocess.Popen( [sys.executable, BIN, '--socket', socket_path, *polkit, '--sit-config', os.path.join(directory, 'sit.conf'), *[a for a in args if a != '--polkit']], diff --git a/packages/omamobile-mmd/test/test_bridge.py b/packages/omamobile-mmd/test/test_bridge.py index 23d5917f1..5f2d4f543 100644 --- a/packages/omamobile-mmd/test/test_bridge.py +++ b/packages/omamobile-mmd/test/test_bridge.py @@ -228,8 +228,12 @@ def test_registration_states_and_signals(self): bearers = self.modem('Bearers') self.assertEqual(len(bearers), 1) bearer = self.client.props(bearers[0], mm.BEARER) + # No device until sitd reports one: never a guessed rmnet0. self.assertEqual((bearer['Interface'], bearer['Connected'], bearer['Properties']['apn']), - ('rmnet0', True, 'internet.example')) + ('', True, 'internet.example')) + self.sitd.status['internet'] = dict(interface='rmnet1') + self.sitd.push() + wait_until(lambda: self.client.props(bearers[0], mm.BEARER)['Interface'] == 'rmnet1', 5, 'the bearer device') changes = [s for s in self.client.named('PropertiesChanged') if s[0] == MODEM0 and s[3][0] == mm.MODEM] self.assertTrue(any('State' in s[3][1] for s in changes)) self.assertEqual(self.sitd.actions(), []) @@ -725,6 +729,24 @@ def test_introspection(self): ''' +class NoMmsDaemon(BridgeTests): + """A phone without mmsd-tng: nothing would take a WAP push, so it goes + to Messages as the placeholder text.""" + status = staticmethod(registered_status) + mmd_args = ('--mms-daemon', '/nonexistent/mmsdtng') + + def test_mms_notification_is_a_placeholder_text(self): + wap = bytes.fromhex('0106226170706c69636174696f6e2f766e642e7761702e6d6d732d6d65737361676500') + b'x' + messages = [dict(id='sit:b', number=SENDER, text='', timestamp='2026-09-29T12:35:00+00:00', + data=wap.hex(), state='received')] + self.sitd.handlers.update(**{'sms-list': lambda r: messages, 'sms-delete': lambda r: {}}) + self.sitd.status['sms'] = dict(received=['sit:b']) + self.push() + wait_until(lambda: len(self.client.named('Added')) == 1, 5, 'WAP push') + push = self.client.props(self.modem('Messages', mm.MESSAGING)[0], mm.SMS) + self.assertEqual((push['Text'], bytes(push['Data'])), (bridge.NO_MMS_TEXT, b'')) + + class Polkit(BridgeTests): """The shipped behaviour: methods with an action go through polkit for a caller that isn't root (the test's own uid here). A fake authority on @@ -771,5 +793,26 @@ def test_denied_and_allowed(self): self.assertEqual(self.sitd.actions(), [], 'nothing reached sitd without authorisation') +class InternetBearer(BridgeTests): + """The internet bearer's device, address and DNS from sitd, which + mmsd-tng fetches MMS through where the MMS APN is the internet APN.""" + status = staticmethod(lambda: registered_status(data=True)) + + def before_mmd(self): + self.sitd.status['internet'] = dict(interface='rmnet5', address='192.0.2.7', + dns=['192.0.2.53', '192.0.2.54']) + + def test_the_found_device_address_and_dns(self): + bearer = self.client.call(MODEM0, mm.MODEM, 'ListBearers')[0][0] + self.assertEqual(self.client.prop(bearer, mm.BEARER, 'Interface'), 'rmnet5') + self.assertEqual(self.client.prop(bearer, mm.BEARER, 'Ip4Config'), + dict(method=2, address='192.0.2.7', prefix=32, dns1='192.0.2.53', dns2='192.0.2.54')) + self.sitd.status['modem']['data'] = False + self.push() + wait_until(lambda: not self.client.prop(bearer, mm.BEARER, 'Connected'), 5, 'bearer down') + self.assertEqual(self.client.prop(bearer, mm.BEARER, 'Ip4Config'), dict(method=0)) + self.assertEqual(self.client.prop(bearer, mm.BEARER, 'Ip6Config'), dict(method=0)) + + if __name__ == '__main__': unittest.main() diff --git a/packages/omamobile-modem-sit/lib/data_network.py b/packages/omamobile-modem-sit/lib/data_network.py index be7b4fd35..9b90c41a6 100644 --- a/packages/omamobile-modem-sit/lib/data_network.py +++ b/packages/omamobile-modem-sit/lib/data_network.py @@ -40,6 +40,10 @@ RESOLVER = Path('/etc/resolv.conf') INTERFACE = paths.RUN / 'data-interface' +# Written only once a candidate has answered and is kept: what the phone +# service reports as the internet bearer's device. data-interface names a +# candidate from before its probe, so that a killed run can be cleaned up. +KEPT = paths.RUN / 'data-interface-kept' # rmnet0-rmnet7 are tried; CPIF creates 30, a phone uses a handful. CANDIDATES = 8 @@ -200,6 +204,7 @@ def put_back(dev, address=None): def clear_stale(): """A device recorded by a run that ended without its cleanup (killed, or stopped before 0.3.12 while probing): put it back before anything else.""" + KEPT.unlink(missing_ok=True) try: dev = INTERFACE.read_text().strip() except OSError: @@ -217,7 +222,9 @@ def find_device(address, cid, probe=None, stopped=lambda: False): keeps its address and route. Every other one is put back as it was, also when a step fails or the service is stopped in the middle (the record in data-interface is written before the device is touched, so a run that is - killed outright is cleaned up by the next start).""" + killed outright is cleaned up by the next start). data-interface-kept is + written only for the one that answered: a device that is merely being + tried is never reported as the bearer's.""" probe = probe or answers for dev in candidates(cid): if stopped(): @@ -243,6 +250,7 @@ def find_device(address, cid, probe=None, stopped=lambda: False): INTERFACE.unlink(missing_ok=True) if kept: print('Bearer CID', cid, 'carried by', dev, flush=True) + KEPT.write_text(dev + '\n') return dev if stopped(): raise InterruptedError('Stopped while looking for the bearer device') @@ -330,6 +338,8 @@ def watch(): # Stopped while probing: find_device has put the candidate back. pass finally: + # The status stops naming the device before its configuration goes. + KEPT.unlink(missing_ok=True) if resolver: resolver.restore() if dev: diff --git a/packages/omamobile-modem-sit/lib/service.py b/packages/omamobile-modem-sit/lib/service.py index cacfc0508..7d91b3b20 100644 --- a/packages/omamobile-modem-sit/lib/service.py +++ b/packages/omamobile-modem-sit/lib/service.py @@ -46,6 +46,7 @@ from calls import call_status, dial_payload, ring import data_call from data_call import paths as bearer_paths +from data_network import configuration as internet_addresses from ims import REGISTRATION, record_registration from inbox import persist_sms from sit import Sit, ModemError @@ -92,6 +93,26 @@ def signal_percent(rsrp): SUBSCRIBERS = 8 +def internet_config(): + """The internet bearer's device, address and the carrier's DNS, for the + bridge's copy of the bearer (MMS goes over it where the MMS APN is the + internet APN). The device is the one omamobile-sit-data found carrying + it and kept (data-interface-kept, written after its probe answered; a + candidate still being probed is not it); none recorded means the data + network isn't up yet. It goes in the + status for authorised clients only, not in state.json; the bridge then + publishes it in the bearer's Ip4Config, which, as ModemManager's, any + client on the system bus can read.""" + try: + address, dns = internet_addresses(bearer_paths(data_call.INTERNET_CID)[1].read_bytes()) + interface = (paths.RUN / 'data-interface-kept').read_text().strip() + except (OSError, ValueError): + return {} + if not interface: + return {} + return dict(interface=interface, address=address, dns=dns) + + class UnconfirmedRelease(RuntimeError): """Fatal call ownership failure; never turn this into a socket reply.""" @@ -163,6 +184,11 @@ def database(path): for table in ('received', 'parts'): if 'data' not in {c[1] for c in db.execute(f'PRAGMA table_info({table})')}: db.execute(f"ALTER TABLE {table} ADD COLUMN data TEXT NOT NULL DEFAULT ''") + if 'port' not in {c[1] for c in db.execute('PRAGMA table_info(parts)')}: + db.execute('ALTER TABLE parts ADD COLUMN port INTEGER') + # Before this migration, only recognised WAP fragments had Data. + # Preserve a first fragment received before upgrading the daemon. + db.execute("UPDATE parts SET port=2948 WHERE data<>''") # A request interrupted by a process restart must never be retried blindly. db.execute("UPDATE outgoing SET state='unknown', error='Delivery uncertain after service restart; check with the recipient' WHERE state='sending'") db.commit() @@ -330,17 +356,22 @@ def ingest(self, path): return concat = sms.pop('concat') data = sms.pop('data').hex() - sms.pop('port') + port = sms.pop('port') if concat: ref, total, seq = concat - self.db.execute('INSERT OR IGNORE INTO parts(id,sender,reference,total,seq,text,timestamp,received,data) VALUES (?,?,?,?,?,?,?,?,?)', - (key, sms['number'], ref, total, seq, sms['text'], sms['timestamp'], time.time(), data)) + self.db.execute('INSERT OR IGNORE INTO parts(id,sender,reference,total,seq,text,timestamp,received,data,port) VALUES (?,?,?,?,?,?,?,?,?,?)', + (key, sms['number'], ref, total, seq, sms['text'], sms['timestamp'], time.time(), data, port)) parts = self.db.execute('SELECT * FROM parts WHERE sender=? AND reference=? AND total=? AND received>? ORDER BY received', (sms['number'], ref, total, time.time()-86400)).fetchall() by_seq = {p['seq']: p for p in parts} if len(by_seq) == total: sms['text'] = ''.join(by_seq[i]['text'] for i in range(1, total+1)) data = ''.join(by_seq[i]['data'] for i in range(1, total+1)) + # Only the first fragment of a WAP push carries the port. + ports = {p['port'] for p in by_seq.values() if p['port'] is not None} + if data and ports != {2948}: + data = '' + sms['text'] = 'Received an unsupported binary message.' sms['timestamp'] = by_seq[1]['timestamp'] self.db.execute('INSERT OR IGNORE INTO received(id,number,text,timestamp,data) VALUES (?,?,?,?,?)', (key, sms['number'], sms['text'], sms['timestamp'], data)) @@ -579,6 +610,7 @@ def status(self, *, public=False): return dict(modem=modem, calls=calls, sms=dict(unread=unread), updated=int(time.time())) received = [r[0] for r in self.db.execute('SELECT id FROM received WHERE consumed=0 ORDER BY rowid')] return dict(modem=modem, calls=calls, sms=dict(received=['sit:' + i for i in received]), + internet=internet_config() if data else {}, audio=dict(available=True, running=self.audio is not None, mute=self.muted, speaker=getattr(self.audio, 'tegu', False) is True, speaker_available=False, error=self.audio_error)) diff --git a/packages/omamobile-modem-sit/lib/sms_codec.py b/packages/omamobile-modem-sit/lib/sms_codec.py index 054d97dcc..effab0141 100644 --- a/packages/omamobile-modem-sit/lib/sms_codec.py +++ b/packages/omamobile-modem-sit/lib/sms_codec.py @@ -125,7 +125,7 @@ def bcd(x): return (x&15)*10+(x>>4) elif alphabet==2: if length>len(data) or lengthlen(data) or length