wwan: expose the network id on the D-Bus

This is going to be useful for UIs to find out which network is the
device actually registered with.
This commit is contained in:
Lubomir Rintel
2019-05-06 17:15:31 +02:00
parent f18b09b3f6
commit bba4a37a59
7 changed files with 106 additions and 1 deletions

View File

@@ -39,6 +39,16 @@
-->
<property name="DeviceId" type="s" access="read" />
<!--
OperatorCode:
The MCC and MNC (concatenated) of the network the modem is connected to.
Blank if disconnected or not a 3GPP modem.
Since: 1.20
-->
<property name="OperatorCode" type="s" access="read" />
<!--
PropertiesChanged:
@properties: A dictionary mapping property names to variant boxed values

View File

@@ -15,6 +15,7 @@ global:
nm_modem_get_iid;
nm_modem_get_path;
nm_modem_get_ip_ifindex;
nm_modem_get_operator_code;
nm_modem_get_secrets;
nm_modem_get_state;
nm_modem_get_type;

View File

@@ -36,11 +36,12 @@ _LOG_DECLARE_SELF(NMDeviceModem);
/*****************************************************************************/
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
NM_GOBJECT_PROPERTIES_DEFINE (NMDeviceModem,
PROP_MODEM,
PROP_CAPABILITIES,
PROP_CURRENT_CAPABILITIES,
PROP_DEVICE_ID,
PROP_OPERATOR_CODE,
);
typedef struct {
@@ -49,6 +50,7 @@ typedef struct {
NMDeviceModemCapabilities current_caps;
gboolean rf_enabled;
char *device_id;
char *operator_code;
} NMDeviceModemPrivate;
struct _NMDeviceModem {
@@ -309,6 +311,20 @@ ip_ifindex_changed_cb (NMModem *modem, GParamSpec *pspec, gpointer user_data)
nm_device_sysctl_ip_conf_set (device, AF_INET6, "disable_ipv6", "1");
}
static void
operator_code_changed_cb (NMModem *modem, GParamSpec *pspec, gpointer user_data)
{
NMDeviceModem *self = NM_DEVICE_MODEM (user_data);
NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (self);
const char *operator_code = nm_modem_get_operator_code (modem);
if (g_strcmp0 (priv->operator_code, operator_code) != 0) {
g_free (priv->operator_code);
priv->operator_code = g_strdup (operator_code);
_notify (self, PROP_OPERATOR_CODE);
}
}
static void
ids_changed_cb (NMModem *modem, GParamSpec *pspec, gpointer user_data)
{
@@ -694,6 +710,7 @@ set_modem (NMDeviceModem *self, NMModem *modem)
g_signal_connect (modem, "notify::" NM_MODEM_DEVICE_ID, G_CALLBACK (ids_changed_cb), self);
g_signal_connect (modem, "notify::" NM_MODEM_SIM_ID, G_CALLBACK (ids_changed_cb), self);
g_signal_connect (modem, "notify::" NM_MODEM_SIM_OPERATOR_ID, G_CALLBACK (ids_changed_cb), self);
g_signal_connect (modem, "notify::" NM_MODEM_OPERATOR_CODE, G_CALLBACK (operator_code_changed_cb), self);
}
static guint32
@@ -727,6 +744,9 @@ get_property (GObject *object, guint prop_id,
case PROP_DEVICE_ID:
g_value_set_string (value, priv->device_id);
break;
case PROP_OPERATOR_CODE:
g_value_set_string (value, priv->operator_code);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -803,6 +823,7 @@ dispose (GObject *object)
}
g_clear_pointer (&priv->device_id, g_free);
g_clear_pointer (&priv->operator_code, g_free);
G_OBJECT_CLASS (nm_device_modem_parent_class)->dispose (object);
}
@@ -817,6 +838,7 @@ static const NMDBusInterfaceInfoExtended interface_info_device_modem = {
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("ModemCapabilities", "u", NM_DEVICE_MODEM_CAPABILITIES),
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE_L ("CurrentCapabilities", "u", NM_DEVICE_MODEM_CURRENT_CAPABILITIES),
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE ("DeviceId", "s", NM_DEVICE_MODEM_DEVICE_ID),
NM_DEFINE_DBUS_PROPERTY_INFO_EXTENDED_READABLE ("OperatorCode", "s", NM_DEVICE_MODEM_OPERATOR_CODE),
),
),
.legacy_property_changed = TRUE,
@@ -880,5 +902,10 @@ nm_device_modem_class_init (NMDeviceModemClass *klass)
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_OPERATOR_CODE] =
g_param_spec_string (NM_DEVICE_MODEM_OPERATOR_CODE, "", "",
NULL,
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
}

View File

@@ -35,6 +35,7 @@
#define NM_DEVICE_MODEM_CAPABILITIES "modem-capabilities"
#define NM_DEVICE_MODEM_CURRENT_CAPABILITIES "current-capabilities"
#define NM_DEVICE_MODEM_DEVICE_ID "device-id"
#define NM_DEVICE_MODEM_OPERATOR_CODE "operator-code"
typedef struct _NMDeviceModem NMDeviceModem;
typedef struct _NMDeviceModemClass NMDeviceModemClass;

View File

@@ -79,6 +79,7 @@ typedef struct {
MMObject *modem_object;
/* Per-interface objects */
MMModem *modem_iface;
MMModem3gpp *modem_3gpp_iface;
MMModemSimple *simple_iface;
MMSim *sim_iface;
@@ -1338,6 +1339,15 @@ supported_ip_families_changed (MMModem *modem, GParamSpec *pspec, gpointer user_
NULL);
}
static void
operator_code_changed (MMModem3gpp *modem_3gpp, GParamSpec *pspec, gpointer user_data)
{
NMModemBroadband *self = NM_MODEM_BROADBAND (user_data);
g_return_if_fail (modem_3gpp == self->_priv.modem_3gpp_iface);
_nm_modem_set_operator_code (NM_MODEM (self), mm_modem_3gpp_get_operator_code (modem_3gpp));
}
/*****************************************************************************/
static void
@@ -1371,6 +1381,7 @@ set_property (GObject *object,
/* construct-only */
self->_priv.modem_object = g_value_dup_object (value);
self->_priv.modem_iface = mm_object_get_modem (self->_priv.modem_object);
self->_priv.modem_3gpp_iface = mm_object_get_modem_3gpp (self->_priv.modem_object);
g_assert (self->_priv.modem_iface != NULL);
g_signal_connect (self->_priv.modem_iface,
"state-changed",
@@ -1386,6 +1397,13 @@ set_property (GObject *object,
G_CALLBACK (supported_ip_families_changed),
self);
if (self->_priv.modem_3gpp_iface) {
g_signal_connect (self->_priv.modem_3gpp_iface,
"notify::operator-code",
G_CALLBACK (operator_code_changed),
self);
}
/* Note: don't grab the Simple iface here; the Modem interface is the
* only one assumed to be always valid and available */
break;
@@ -1407,7 +1425,9 @@ nm_modem_broadband_new (GObject *object, GError **error)
{
MMObject *modem_object;
MMModem *modem_iface;
MMModem3gpp *modem_3gpp_iface;
const char *const*drivers;
const char *operator_code = NULL;
gs_free char *driver = NULL;
g_return_val_if_fail (MM_IS_OBJECT (object), NULL);
@@ -1423,6 +1443,10 @@ nm_modem_broadband_new (GObject *object, GError **error)
if (drivers)
driver = g_strjoinv (", ", (char **) drivers);
modem_3gpp_iface = mm_object_peek_modem_3gpp (modem_object);
if (modem_3gpp_iface)
operator_code = mm_modem_3gpp_get_operator_code (modem_3gpp_iface);
return g_object_new (NM_TYPE_MODEM_BROADBAND,
NM_MODEM_PATH, mm_object_get_path (modem_object),
NM_MODEM_UID, mm_modem_get_primary_port (modem_iface),
@@ -1432,6 +1456,7 @@ nm_modem_broadband_new (GObject *object, GError **error)
NM_MODEM_DEVICE_ID, mm_modem_get_device_identifier (modem_iface),
NM_MODEM_BROADBAND_MODEM, modem_object,
NM_MODEM_DRIVER, driver,
NM_MODEM_OPERATOR_CODE, operator_code,
NULL);
}
@@ -1454,6 +1479,11 @@ dispose (GObject *object)
g_clear_object (&self->_priv.modem_iface);
}
if (self->_priv.modem_3gpp_iface) {
g_signal_handlers_disconnect_by_data (self->_priv.modem_3gpp_iface, self);
g_clear_object (&self->_priv.modem_3gpp_iface);
}
g_clear_object (&self->_priv.simple_iface);
g_clear_object (&self->_priv.sim_iface);
g_clear_object (&self->_priv.modem_object);

View File

@@ -52,6 +52,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMModem,
PROP_SIM_ID,
PROP_IP_TYPES,
PROP_SIM_OPERATOR_ID,
PROP_OPERATOR_CODE,
);
enum {
@@ -90,6 +91,7 @@ typedef struct _NMModemPrivate {
char *sim_id;
NMModemIPType ip_types;
char *sim_operator_id;
char *operator_code;
NMPPPManager *ppp_manager;
@@ -436,6 +438,12 @@ nm_modem_get_sim_operator_id (NMModem *self)
return NM_MODEM_GET_PRIVATE (self)->sim_operator_id;
}
const char *
nm_modem_get_operator_code (NMModem *self)
{
return NM_MODEM_GET_PRIVATE (self)->operator_code;
}
/*****************************************************************************/
/* IP method PPP */
@@ -1577,6 +1585,18 @@ nm_modem_get_capabilities (NMModem *self,
/*****************************************************************************/
void
_nm_modem_set_operator_code (NMModem *self, const char *operator_code)
{
NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (self);
if (g_strcmp0 (priv->operator_code, operator_code) != 0) {
g_free (priv->operator_code);
priv->operator_code = g_strdup (operator_code);
_notify (self, PROP_OPERATOR_CODE);
}
}
static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
@@ -1615,6 +1635,9 @@ get_property (GObject *object, guint prop_id,
case PROP_SIM_OPERATOR_ID:
g_value_set_string (value, priv->sim_operator_id);
break;
case PROP_OPERATOR_CODE:
g_value_set_string (value, priv->operator_code);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -1667,6 +1690,9 @@ set_property (GObject *object, guint prop_id,
if (s && s[0])
priv->sim_operator_id = g_strdup (s);
break;
case PROP_OPERATOR_CODE:
_nm_modem_set_operator_code (NM_MODEM (object), g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -1728,6 +1754,7 @@ finalize (GObject *object)
g_free (priv->device_id);
g_free (priv->sim_id);
g_free (priv->sim_operator_id);
g_free (priv->operator_code);
G_OBJECT_CLASS (nm_modem_parent_class)->finalize (object);
}
@@ -1811,6 +1838,11 @@ nm_modem_class_init (NMModemClass *klass)
G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS);
obj_properties[PROP_OPERATOR_CODE] =
g_param_spec_string (NM_MODEM_OPERATOR_CODE, "", "",
NULL,
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
signals[PPP_STATS] =

View File

@@ -43,6 +43,7 @@
#define NM_MODEM_SIM_ID "sim-id"
#define NM_MODEM_IP_TYPES "ip-types" /* Supported IP types */
#define NM_MODEM_SIM_OPERATOR_ID "sim-operator-id"
#define NM_MODEM_OPERATOR_CODE "operator-code"
/* Signals */
#define NM_MODEM_PPP_STATS "ppp-stats"
@@ -175,6 +176,7 @@ const char *nm_modem_get_device_id (NMModem *modem);
const char *nm_modem_get_sim_id (NMModem *modem);
const char *nm_modem_get_sim_operator_id (NMModem *modem);
gboolean nm_modem_get_iid (NMModem *modem, NMUtilsIPv6IfaceId *out_iid);
const char *nm_modem_get_operator_code (NMModem *modem);
gboolean nm_modem_set_data_port (NMModem *self,
NMPlatform *platform,
@@ -286,4 +288,6 @@ const char *nm_modem_ip_type_to_string (NMModemIPType ip_type);
guint32 nm_modem_get_configured_mtu (NMDevice *self, NMDeviceMtuSource *out_source);
void _nm_modem_set_operator_code (NMModem *self, const char *operator_code);
#endif /* __NETWORKMANAGER_MODEM_H__ */