From 7d38846bb6c93c78d40483771ca268c39a5d0683 Mon Sep 17 00:00:00 2001 From: Jorijn van der Graaf Date: Tue, 6 Oct 2026 17:54:09 +0200 Subject: [PATCH] ims-pdn-up: do not connect a bearer while the modem is disabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With the modem's radio off (airplane mode) the bring-up waited five minutes for registration and then tried to connect the ims bearer anyway. That attempt fails with no-service and leaves ModemManager's modem state `enabled` while the modem stays in low power; switching the radio back on then no longer brings the modem up, and the phone has no mobile service until the modem is disabled and enabled again (dev phone 2026-10-06: not registered 150 s after the radio came on, against 5 s without the attempt). 0.3.9's bring-up made the same attempts, but it only ran at boot or at a manual restart. Since this series a registered imsd exits when its address leaves the netdev and systemd runs the bring-up again, and an upgrade restarts it: the bring-up now also runs during a radio-off period. A modem still disabled after the registration wait, or disabled when a connect attempt is due, now makes the script exit non-zero without touching the modem; systemd retries after RestartSec. Tested on the dev phone (KPN) with this script: a registered imsd, the radio switched off — imsd exited at its next refresh, the bring-up gave up after the wait with the modem still disabled, and when the radio came back the modem registered in 5 s and imsd registered by itself two minutes later; the same with an upgrade's restart during the radio-off period. The twelve mock scenarios of the bring-up are unchanged. --- AGENTS.md | 9 +++++++++ packaging/ims-pdn-up.sh | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/AGENTS.md b/AGENTS.md index 216170d..2a8715b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -436,6 +436,15 @@ configures the muxed netdev. Idempotent; a non-zero exit fails the unit. - Waits up to 120 s for a modem, then gates the connect attempts on network registration (`IMS_REG_TIMEOUT`, default 300 s): some carriers attach ~2 min after boot. +- Never creates or connects a bearer while the modem is `disabled` — its + radio is off (airplane mode): a modem still disabled after the wait, or + disabled when an attempt is due, makes the script exit non-zero (`modem … + disabled … (radio off): not connecting`) and systemd retries. A bearer + connect on a disabled modem fails with `no-service` and leaves + ModemManager's state `enabled` with the modem in low power; switching the + radio back on then no longer brings it up (dev phone 2026-10-06: not + registered after 150 s, against 5 s without the attempt; a ModemManager + disable/enable recovered it). - Connects by **3GPP profile index** (`IMS_PROFILE_ID`, default: looked up by APN in `qmicli --wds-get-profile-list=3gpp`), not by APN string: a profile-indexed request is exempt from the modem's attach-family forcing diff --git a/packaging/ims-pdn-up.sh b/packaging/ims-pdn-up.sh index a20068e..191c2b5 100644 --- a/packaging/ims-pdn-up.sh +++ b/packaging/ims-pdn-up.sh @@ -39,6 +39,12 @@ bearer_paths() { kv -m "$MODEM" | sed -n 's/^modem\.generic\.bearers\.value\[[0-9]*\] *: *//p' } +# A disabled modem has its radio off (airplane mode): leave it alone. A bearer +# connect on it fails with no-service and leaves ModemManager's state +# `enabled` with the modem still in low power; switching the radio back on +# then no longer brings the modem up (dev phone 2026-10-06). +radio_off() { [ "$(modem_state)" = disabled ]; } + envval() { # $1 = key — for manual runs; under systemd the vars are inherited sed -n "s/^$1=//p" /etc/imsd.env 2>/dev/null | tail -n1 | tr -d '"' } @@ -165,6 +171,10 @@ if [ -z "$BEARER" ]; then [ "$STATE" != "$last" ] && log "waiting for registration (state: ${STATE:-unknown})" last=$STATE if [ "$waited" -ge "$REG_TIMEOUT" ]; then + if [ "$STATE" = disabled ]; then + log "modem still disabled after $REG_TIMEOUT s (radio off): not connecting" + exit 1 + fi log "not registered after $REG_TIMEOUT s — attempting anyway" break fi @@ -193,6 +203,7 @@ n=0 while [ -z "$BEARER" ]; do n=$((n + 1)) [ "$n" -gt 10 ] && { log "bearer connect failed after 10 attempts"; exit 1; } + radio_off && { log "modem disabled (radio off): not connecting"; exit 1; } B=$(find_ims_bearer no) # reuse a stale disconnected ims bearer of this run's shape if [ -z "$B" ]; then if [ -n "$PROFILE_ID" ]; then