Support 4G/5G automatic reconnection using ModemManager

Right now on an ISP-triggered 4G/5G disconnection, ModemManager will not automatically reconnect. It merely reports the disconnection to netifd and that's it. Work is needed to be done to the netifd protocol to tie things up to react to the reported disconnection and reconnect.

Back in November 2022, I raised this issue here:

And @aleksander0m wrote:

The way to solve this, after briefly talking with @jow- about this in IRC would be to have the netifd protocol handler launch a "watcher" process which brings up the connection, and is kept alive and running for as long as the network interface is assumed connected. If MM detects a network-initiated disconnection, the dispatcher script called by MM should kill that watcher process. At that point, netifd (if configured to autoconnect) will then kill the netdev, restart that process and await proto updates.

Anyone up to the task of writing this logic in the netfid modemmanager protocol handler?

And most recently:

Might anyone be willing to carry the torch and progress this matter for the 4G/5G modem users out there?

3 Likes

I consider this approach bloated, far too complicated. Simple script, pinging a well known target, i.g. 8.8.8.8, can do the job for a qmi-interface.

I just ran into this with my LTE Backup connection - I was surprised that OpenWrt does not try to keep the connection alive.

1 Like

May be, offering a bounty might help you here.

A temporary workaround hack is:

root@OpenWrt:~# cat /usr/lib/ModemManager/connection.d/10-report-down-and-reconnect
#!/bin/sh

# Automatically report to netifd that the underlying modem
# is really disconnected and reconnect if interface was up

# require program name and at least 4 arguments
[ $# -lt 4 ] && exit 1

MODEM_PATH="$1"
BEARER_PATH="$2"
INTERFACE="$3"
STATE="$4"

[ "${STATE}" = "disconnected" ] || exit 0

. /usr/share/ModemManager/modemmanager.common
. /lib/netifd/netifd-proto.sh
INCLUDE_ONLY=1 . /lib/netifd/proto/modemmanager.sh

MODEM_STATUS=$(mmcli --modem="${MODEM_PATH}" --output-keyvalue)
[ -n "${MODEM_STATUS}" ] || exit 1

MODEM_DEVICE=$(modemmanager_get_field "${MODEM_STATUS}" "modem.generic.device")
[ -n "${MODEM_DEVICE}" ] || exit 2

CFG=$(mm_get_modem_config "${MODEM_DEVICE}")
[ -n "${CFG}" ] || exit 3

IFUP=$(ifstatus ${CFG} | jsonfilter -e '@.up')

logger -t "modemmanager" "interface ${CFG} (network device ${INTERFACE}) ${STATE}"
proto_init_update $INTERFACE 0
proto_send_update $CFG

[ "${IFUP}" = "true" ] && ifup ${CFG}

exit 0

But @aleksander0m laid out a proposal on what needs to be done to address this properly.

Hi cant find cat /usr/lib/ModemManager/connection.d/10-report-down-and-reconnect ?

I have created an interface with modemmanager protocol

Just edit /usr/lib/ModemManager/connection.d/10-report-down

Also, which OpenWrt version do you have? Frustratingly in 22.03.5 the ModemManager package isn't recent enough to support the dispatcher script.

You need ModemManager version 1.18.8 or later - see:

I have an .ipk for ModemManager 1.18.12 that works for the Zyxel in 22.03.5 if that'd be helpful. You could just upload that using the LuCi interface, but you'd need to trust me.

Openwrt 22.03.5, r20134-5f15225cle
Modemmanager v 1.18.6-2
How to trust ?

Yes you need a more recent ModemManager package. It's very frustrating that only such an old ModemManager version is available for 22.03.5.

https://www.linuxfromscratch.org/blfs/view/svn/general/ModemManager.html

Perhaps this might work:

https://downloads.openwrt.org/releases/packages-23.05/mipsel_24kc/packages/modemmanager_1.20.6-3_mipsel_24kc.ipk

I can install but it have no modem device in the interface
Now i got the 10-report-down file

Probably doesn't work then. Is that after a reboot?

I have an .ipk you could use that I know works in 22.03.5. But you shouldn't trust me or anyone offering an .ipk for you to install willy-nilly. So I'm hoping someone can explain how to get historical builds that will work.

@frollic or anyone else, how can @balle15 obtain an .ipk for a later version of ModemManager than presently available in 22.03.5 that might work in 22.03.5? The 23.05 .ipk doesn't work. I managed to obtain an .ipk this way from a snapshot, and that just happened to work fine.

All of this pain is unfortunate; I hope more attention might be given to mobile broadband support in OpenWrt.

yes but i this nr7101 istn on some secret network,
so i d like to try, if posible

But really for security reasons you should seek to obtain/build a working .ipk yourself.

what version does 23.05-rc2 come with ?

The version in 23.05 is 1.20.6 (so recent enough). But it seems from @balle15's testing that this may not work in 22.03.5.

The version in 22.03 is 18.6, but we need 18.8 or later.

Is there a good way to obtain a later version of a packaged program for a given OpenWrt release or branch when that later version hasn't been pulled in yet? Whilst I am sure it is terrible practice, in the past I just downloaded an .ipk for ModemManager version 1.18.12 from a snapshot that just happened to work.

I raised an issue here: https://github.com/openwrt/packages/issues/19794 back in November last year, and even the ModemManager maintainer has tried chasing it up, but the needed fix hasn't been added to OpenWrt even in master yet.

So for now it's still about just using my hack, but that requires upgrading to a version of ModemManager not yet provided in 22.03.

Protocol: ModemManager
RX: 0 B (0 Pkts.)
TX: 0 B (0 Pkts.)
Error: Modem bearer teardown in progress.

not connecting
appreciate the help

Anything helpful in 'logread'?

Sat Jul 22 20:11:54 2023 daemon.notice netifd: Interface '5G' is setting up now
Sat Jul 22 20:11:54 2023 daemon.notice netifd: 5G (4854): modem available at /org/freedesktop/ModemManager1/Modem/0
Sat Jul 22 20:11:54 2023 daemon.notice netifd: 5G (4854): starting connection with apn 'telia'...
Sat Jul 22 20:11:54 2023 daemon.info [2671]: [modem0] simple connect started...
Sat Jul 22 20:11:54 2023 daemon.info [2671]: [modem0] simple connect state (4/8): wait to get fully enabled
Sat Jul 22 20:11:54 2023 daemon.info [2671]: [modem0] simple connect state (5/8): register
Sat Jul 22 20:12:35 2023 authpriv.info dropbear[4897]: Child connection from 192.168.1.170:60916
Sat Jul 22 20:12:38 2023 authpriv.notice dropbear[4897]: Auth succeeded with blank password for 'root' from 192.168.1.170:60916
Sat Jul 22 20:12:57 2023 daemon.notice netifd: 5G (4854): error: couldn't connect the modem: 'GDBus.Error:org.freedesktop.ModemManager1.Error.MobileEquipment.NetworkTimeout: Network timeout'
Sat Jul 22 20:12:57 2023 daemon.notice netifd: 5G (4914): stopping network
Sat Jul 22 20:12:57 2023 daemon.notice netifd: 5G (4914): couldn't load bearer path: disconnecting anyway