From fabab906a37731237483a342e68732efd5c5ca2c Mon Sep 17 00:00:00 2001 From: Muhammad Asif Date: Mon, 22 Dec 2025 02:15:32 +0500 Subject: [PATCH] devices: wwan: add support for changing capabilities of modem after initialization Signed-off-by: Muhammad Asif --- src/core/devices/wwan/nm-device-modem.c | 18 ++++++++++++++++++ src/core/devices/wwan/nm-modem.c | 21 +++++++++++++++++++++ src/core/devices/wwan/nm-modem.h | 21 +++++++++++++-------- 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/src/core/devices/wwan/nm-device-modem.c b/src/core/devices/wwan/nm-device-modem.c index a8a48ce6ab..ba77ca5067 100644 --- a/src/core/devices/wwan/nm-device-modem.c +++ b/src/core/devices/wwan/nm-device-modem.c @@ -327,6 +327,23 @@ modem_state_cb(NMModem *modem, int new_state_i, int old_state_i, gpointer user_d NM_DEVICE_STATE_REASON_MODEM_FAILED); } +static void +caps_changed_cb(NMModem *modem, guint modem_caps, guint current_caps, gpointer user_data) +{ + NMDeviceModem *self = NM_DEVICE_MODEM(user_data); + NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE(self); + + if (priv->caps != modem_caps) { + priv->caps = modem_caps; + _notify(self, PROP_CAPABILITIES); + } + + if (priv->current_caps != current_caps) { + priv->current_caps = current_caps; + _notify(self, PROP_CURRENT_CAPABILITIES); + } +} + static void modem_removed_cb(NMModem *modem, gpointer user_data) { @@ -677,6 +694,7 @@ set_modem(NMDeviceModem *self, NMModem *modem) g_signal_connect(modem, NM_MODEM_AUTH_REQUESTED, G_CALLBACK(modem_auth_requested), self); g_signal_connect(modem, NM_MODEM_AUTH_RESULT, G_CALLBACK(modem_auth_result), self); g_signal_connect(modem, NM_MODEM_STATE_CHANGED, G_CALLBACK(modem_state_cb), self); + g_signal_connect(modem, NM_MODEM_CAPABILITIES_CHANGED, G_CALLBACK(caps_changed_cb), self); g_signal_connect(modem, NM_MODEM_REMOVED, G_CALLBACK(modem_removed_cb), self); g_signal_connect(modem, diff --git a/src/core/devices/wwan/nm-modem.c b/src/core/devices/wwan/nm-modem.c index 0862167223..a9c25f8607 100644 --- a/src/core/devices/wwan/nm-modem.c +++ b/src/core/devices/wwan/nm-modem.c @@ -51,6 +51,7 @@ enum { AUTH_RESULT, REMOVED, STATE_CHANGED, + CAPABILITIES_CHANGED, LAST_SIGNAL, }; @@ -338,6 +339,14 @@ nm_modem_set_state(NMModem *self, NMModemState new_state, const char *reason) } } +void +nm_modem_set_capabilities(NMModem *self, + NMDeviceModemCapabilities modem_caps, + NMDeviceModemCapabilities current_caps) +{ + g_signal_emit(self, signals[CAPABILITIES_CHANGED], 0, (guint) modem_caps, (guint) current_caps); +} + void nm_modem_set_prev_state(NMModem *self, const char *reason) { @@ -2004,4 +2013,16 @@ nm_modem_class_init(NMModemClass *klass) 2, G_TYPE_INT, G_TYPE_INT); + + signals[CAPABILITIES_CHANGED] = g_signal_new(NM_MODEM_CAPABILITIES_CHANGED, + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_FIRST, + 0, + NULL, + NULL, + NULL, + G_TYPE_NONE, + 2, + G_TYPE_UINT, + G_TYPE_UINT); } diff --git a/src/core/devices/wwan/nm-modem.h b/src/core/devices/wwan/nm-modem.h index 6900036099..1b79d67d61 100644 --- a/src/core/devices/wwan/nm-modem.h +++ b/src/core/devices/wwan/nm-modem.h @@ -33,14 +33,15 @@ #define NM_MODEM_DEVICE_UID "device-uid" /* Signals */ -#define NM_MODEM_PPP_STATS "ppp-stats" -#define NM_MODEM_PPP_FAILED "ppp-failed" -#define NM_MODEM_PREPARE_RESULT "prepare-result" -#define NM_MODEM_NEW_CONFIG "new-config" -#define NM_MODEM_AUTH_REQUESTED "auth-requested" -#define NM_MODEM_AUTH_RESULT "auth-result" -#define NM_MODEM_REMOVED "removed" -#define NM_MODEM_STATE_CHANGED "state-changed" +#define NM_MODEM_PPP_STATS "ppp-stats" +#define NM_MODEM_PPP_FAILED "ppp-failed" +#define NM_MODEM_PREPARE_RESULT "prepare-result" +#define NM_MODEM_NEW_CONFIG "new-config" +#define NM_MODEM_AUTH_REQUESTED "auth-requested" +#define NM_MODEM_AUTH_RESULT "auth-result" +#define NM_MODEM_REMOVED "removed" +#define NM_MODEM_STATE_CHANGED "state-changed" +#define NM_MODEM_CAPABILITIES_CHANGED "capabilities-changed" typedef enum { NM_MODEM_IP_METHOD_UNKNOWN = 0, @@ -215,6 +216,10 @@ void nm_modem_set_state(NMModem *self, NMModemState new_state, const cha void nm_modem_set_prev_state(NMModem *self, const char *reason); const char *nm_modem_state_to_string(NMModemState state); +void nm_modem_set_capabilities(NMModem *self, + NMDeviceModemCapabilities modem_caps, + NMDeviceModemCapabilities current_caps); + NMModemIPType nm_modem_get_supported_ip_types(NMModem *self); /* For the modem-manager only */