From 580453d3769ed1457970eecde7af474ca7dba1ed Mon Sep 17 00:00:00 2001 From: Ratchanan Srirattanamet Date: Wed, 21 Sep 2022 19:26:25 +0700 Subject: [PATCH] wwan/device-modem: disabled but not enable-able modem is unavailable If a modem is disabled, and it has no method to enable it, then by no mean it's "available" to NM. --- src/core/devices/wwan/nm-device-modem.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/core/devices/wwan/nm-device-modem.c b/src/core/devices/wwan/nm-device-modem.c index e0209affcd..15256781b4 100644 --- a/src/core/devices/wwan/nm-device-modem.c +++ b/src/core/devices/wwan/nm-device-modem.c @@ -273,6 +273,15 @@ modem_state_cb(NMModem *modem, int new_state_i, int old_state_i, gpointer user_d /* Called when the ModemManager modem enabled state is changed externally * to NetworkManager (eg something using MM's D-Bus API directly). */ + + if (!NM_MODEM_GET_CLASS(priv->modem)->set_mm_enabled) { + /* We cannot re-enable this modem, thus device becomes unavailable. */ + nm_device_state_changed(device, + NM_DEVICE_STATE_UNAVAILABLE, + NM_DEVICE_STATE_REASON_USER_REQUESTED); + return; + } + if (nm_device_is_activating(device) || dev_state == NM_DEVICE_STATE_ACTIVATED) { /* user-initiated action, hence DISCONNECTED not FAILED */ nm_device_state_changed(device, @@ -435,6 +444,13 @@ check_connection_available(NMDevice *device, return FALSE; } + if (!NM_MODEM_GET_CLASS(priv->modem)->set_mm_enabled && state <= NM_MODEM_STATE_DISABLING) { + nm_utils_error_set_literal(error, + NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY, + "modem is disabled and NM cannot enable it"); + return FALSE; + } + if (state == NM_MODEM_STATE_LOCKED) { if (!nm_connection_get_setting_gsm(connection)) { nm_utils_error_set_literal(error, @@ -617,6 +633,9 @@ is_available(NMDevice *device, NMDeviceCheckDevAvailableFlags flags) if (modem_state <= NM_MODEM_STATE_INITIALIZING) return FALSE; + if (!NM_MODEM_GET_CLASS(priv->modem)->set_mm_enabled && modem_state <= NM_MODEM_STATE_DISABLING) + return FALSE; + return TRUE; }