diff options
Diffstat (limited to 'src/devices/wwan/nm-modem-broadband.c')
-rw-r--r-- | src/devices/wwan/nm-modem-broadband.c | 349 |
1 files changed, 182 insertions, 167 deletions
diff --git a/src/devices/wwan/nm-modem-broadband.c b/src/devices/wwan/nm-modem-broadband.c index e3681c01ff..f5f12a03df 100644 --- a/src/devices/wwan/nm-modem-broadband.c +++ b/src/devices/wwan/nm-modem-broadband.c @@ -20,27 +20,39 @@ #include "nm-default.h" +#include "nm-modem-broadband.h" + #include <string.h> #include <arpa/inet.h> #include <libmm-glib.h> -#include "nm-modem-broadband.h" #include "nm-core-internal.h" #include "NetworkManagerUtils.h" #include "nm-device-private.h" #include "nm-platform.h" +#include "nm-ip4-config.h" +#include "nm-ip6-config.h" #define NM_MODEM_BROADBAND_MODEM "modem" -G_DEFINE_TYPE (NMModemBroadband, nm_modem_broadband, NM_TYPE_MODEM) +#define MODEM_CAPS_3GPP(caps) (caps & (MM_MODEM_CAPABILITY_GSM_UMTS | \ + MM_MODEM_CAPABILITY_LTE | \ + MM_MODEM_CAPABILITY_LTE_ADVANCED)) + +#define MODEM_CAPS_3GPP2(caps) (caps & (MM_MODEM_CAPABILITY_CDMA_EVDO)) + +/* Maximum time to keep the DBus call waiting for a connection result */ +#define MODEM_CONNECT_TIMEOUT_SECS 120 + +/*****************************************************************************/ typedef enum { - CONNECT_STEP_FIRST, - CONNECT_STEP_WAIT_FOR_SIM, - CONNECT_STEP_UNLOCK, - CONNECT_STEP_WAIT_FOR_READY, - CONNECT_STEP_CONNECT, - CONNECT_STEP_LAST + CONNECT_STEP_FIRST, + CONNECT_STEP_WAIT_FOR_SIM, + CONNECT_STEP_UNLOCK, + CONNECT_STEP_WAIT_FOR_READY, + CONNECT_STEP_CONNECT, + CONNECT_STEP_LAST, } ConnectStep; typedef struct { @@ -57,7 +69,13 @@ typedef struct { GError *first_error; } ConnectContext; -struct _NMModemBroadbandPrivate { +/*****************************************************************************/ + +NM_GOBJECT_PROPERTIES_DEFINE_BASE ( + PROP_MODEM, +); + +typedef struct { /* The modem object from dbus */ MMObject *modem_object; /* Per-interface objects */ @@ -73,21 +91,20 @@ struct _NMModemBroadbandPrivate { MMBearerIpConfig *ipv6_config; guint32 pin_tries; -}; +} NMModemBroadbandPrivate; -enum { - PROP_0, - PROP_MODEM, +struct _NMModemBroadband { + NMModem parent; + NMModemBroadbandPrivate _priv; }; -#define MODEM_CAPS_3GPP(caps) (caps & (MM_MODEM_CAPABILITY_GSM_UMTS | \ - MM_MODEM_CAPABILITY_LTE | \ - MM_MODEM_CAPABILITY_LTE_ADVANCED)) +struct _NMModemBroadbandClass { + NMModemClass parent; +}; -#define MODEM_CAPS_3GPP2(caps) (caps & (MM_MODEM_CAPABILITY_CDMA_EVDO)) +G_DEFINE_TYPE (NMModemBroadband, nm_modem_broadband, NM_TYPE_MODEM) -/* Maximum time to keep the DBus call waiting for a connection result */ -#define MODEM_CONNECT_TIMEOUT_SECS 120 +#define NM_MODEM_BROADBAND_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMModemBroadband, NM_IS_MODEM_BROADBAND) /*****************************************************************************/ @@ -172,7 +189,7 @@ get_capabilities (NMModem *_self, /* For now, we don't care about the capability combinations, just merge all * combinations in a single mask */ - if (mm_modem_get_supported_capabilities (self->priv->modem_iface, &supported, &n_supported)) { + if (mm_modem_get_supported_capabilities (self->_priv.modem_iface, &supported, &n_supported)) { guint i; for (i = 0; i < n_supported; i++) @@ -182,7 +199,7 @@ get_capabilities (NMModem *_self, } *modem_caps = (NMDeviceModemCapabilities) all_supported; - *current_caps = (NMDeviceModemCapabilities) mm_modem_get_current_capabilities (self->priv->modem_iface); + *current_caps = (NMDeviceModemCapabilities) mm_modem_get_current_capabilities (self->_priv.modem_iface); } static gboolean @@ -193,7 +210,7 @@ owns_port (NMModem *_self, const char *iface) guint n_ports = 0, i; gboolean owns = FALSE; - mm_modem_peek_ports (self->priv->modem_iface, &ports, &n_ports); + mm_modem_peek_ports (self->_priv.modem_iface, &ports, &n_ports); for (i = 0; i < n_ports && !owns; i++) owns = (g_strcmp0 (iface, ports[i].name) == 0); return owns; @@ -206,7 +223,7 @@ ask_for_pin (NMModemBroadband *self) { guint32 tries; - tries = self->priv->pin_tries++; + tries = self->_priv.pin_tries++; nm_modem_get_secrets (NM_MODEM (self), NM_SETTING_GSM_SETTING_NAME, tries ? TRUE : FALSE, @@ -312,8 +329,8 @@ create_gsm_connect_properties (NMConnection *connection) static void connect_context_clear (NMModemBroadband *self) { - if (self->priv->ctx) { - ConnectContext *ctx = self->priv->ctx; + if (self->_priv.ctx) { + ConnectContext *ctx = self->_priv.ctx; g_clear_error (&ctx->first_error); g_clear_pointer (&ctx->ip_types, (GDestroyNotify) g_array_unref); @@ -322,7 +339,7 @@ connect_context_clear (NMModemBroadband *self) g_clear_object (&ctx->connect_properties); g_clear_object (&ctx->self); g_slice_free (ConnectContext, ctx); - self->priv->ctx = NULL; + self->_priv.ctx = NULL; } } @@ -333,20 +350,20 @@ connect_ready (MMModemSimple *simple_iface, GAsyncResult *res, NMModemBroadband *self) { - ConnectContext *ctx = self->priv->ctx; + ConnectContext *ctx = self->_priv.ctx; GError *error = NULL; NMModemIPMethod ip4_method = NM_MODEM_IP_METHOD_UNKNOWN; NMModemIPMethod ip6_method = NM_MODEM_IP_METHOD_UNKNOWN; - self->priv->bearer = mm_modem_simple_connect_finish (simple_iface, res, &error); + self->_priv.bearer = mm_modem_simple_connect_finish (simple_iface, res, &error); if (!ctx) return; - if (!self->priv->bearer) { + if (!self->_priv.bearer) { if (g_error_matches (error, MM_MOBILE_EQUIPMENT_ERROR, MM_MOBILE_EQUIPMENT_ERROR_SIM_PIN) || (g_error_matches (error, MM_CORE_ERROR, MM_CORE_ERROR_UNAUTHORIZED) && - mm_modem_get_unlock_required (self->priv->modem_iface) == MM_MODEM_LOCK_SIM_PIN)) { + mm_modem_get_unlock_required (self->_priv.modem_iface) == MM_MODEM_LOCK_SIM_PIN)) { g_error_free (error); /* Request PIN */ @@ -379,13 +396,13 @@ connect_ready (MMModemSimple *simple_iface, } /* Grab IP configurations */ - self->priv->ipv4_config = mm_bearer_get_ipv4_config (self->priv->bearer); - if (self->priv->ipv4_config) - ip4_method = get_bearer_ip_method (self->priv->ipv4_config); + self->_priv.ipv4_config = mm_bearer_get_ipv4_config (self->_priv.bearer); + if (self->_priv.ipv4_config) + ip4_method = get_bearer_ip_method (self->_priv.ipv4_config); - self->priv->ipv6_config = mm_bearer_get_ipv6_config (self->priv->bearer); - if (self->priv->ipv6_config) - ip6_method = get_bearer_ip_method (self->priv->ipv6_config); + self->_priv.ipv6_config = mm_bearer_get_ipv6_config (self->_priv.bearer); + if (self->_priv.ipv6_config) + ip6_method = get_bearer_ip_method (self->_priv.ipv6_config); if (ip4_method == NM_MODEM_IP_METHOD_UNKNOWN && ip6_method == NM_MODEM_IP_METHOD_UNKNOWN) { @@ -396,10 +413,10 @@ connect_ready (MMModemSimple *simple_iface, } g_object_set (self, - NM_MODEM_DATA_PORT, mm_bearer_get_interface (self->priv->bearer), + NM_MODEM_DATA_PORT, mm_bearer_get_interface (self->_priv.bearer), NM_MODEM_IP4_METHOD, ip4_method, NM_MODEM_IP6_METHOD, ip6_method, - NM_MODEM_IP_TIMEOUT, mm_bearer_get_ip_timeout (self->priv->bearer), + NM_MODEM_IP_TIMEOUT, mm_bearer_get_ip_timeout (self->_priv.bearer), NULL); ctx->step++; @@ -416,13 +433,13 @@ send_pin_ready (MMSim *sim, GAsyncResult *result, NMModemBroadband *self) if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) return; - if (!self->priv->ctx || self->priv->ctx->step != CONNECT_STEP_UNLOCK) + if (!self->_priv.ctx || self->_priv.ctx->step != CONNECT_STEP_UNLOCK) g_return_if_reached (); if (error) { if (g_error_matches (error, MM_MOBILE_EQUIPMENT_ERROR, MM_MOBILE_EQUIPMENT_ERROR_SIM_PIN) || (g_error_matches (error, MM_CORE_ERROR, MM_CORE_ERROR_UNAUTHORIZED) && - mm_modem_get_unlock_required (self->priv->modem_iface) == MM_MODEM_LOCK_SIM_PIN)) { + mm_modem_get_unlock_required (self->_priv.modem_iface) == MM_MODEM_LOCK_SIM_PIN)) { ask_for_pin (self); } else { g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, FALSE, translate_mm_error (self, error)); @@ -430,14 +447,14 @@ send_pin_ready (MMSim *sim, GAsyncResult *result, NMModemBroadband *self) return; } - self->priv->ctx->step++; + self->_priv.ctx->step++; connect_context_step (self); } static void connect_context_step (NMModemBroadband *self) { - ConnectContext *ctx = self->priv->ctx; + ConnectContext *ctx = self->_priv.ctx; switch (ctx->step) { case CONNECT_STEP_FIRST: @@ -445,7 +462,7 @@ connect_context_step (NMModemBroadband *self) /* fall through */ case CONNECT_STEP_WAIT_FOR_SIM: - if (MODEM_CAPS_3GPP (ctx->caps) && !self->priv->sim_iface) { + if (MODEM_CAPS_3GPP (ctx->caps) && !self->_priv.sim_iface) { /* Have to wait for the SIM to show up */ break; } @@ -454,13 +471,13 @@ connect_context_step (NMModemBroadband *self) case CONNECT_STEP_UNLOCK: if ( MODEM_CAPS_3GPP (ctx->caps) - && mm_modem_get_unlock_required (self->priv->modem_iface) == MM_MODEM_LOCK_SIM_PIN) { + && mm_modem_get_unlock_required (self->_priv.modem_iface) == MM_MODEM_LOCK_SIM_PIN) { NMSettingGsm *s_gsm = nm_connection_get_setting_gsm (ctx->connection); const char *pin = nm_setting_gsm_get_pin (s_gsm); /* If we have a PIN already, send it. If we don't, get it. */ if (pin) { - mm_sim_send_pin (self->priv->sim_iface, + mm_sim_send_pin (self->_priv.sim_iface, pin, ctx->cancellable, (GAsyncReadyCallback) send_pin_ready, @@ -476,7 +493,7 @@ connect_context_step (NMModemBroadband *self) case CONNECT_STEP_WAIT_FOR_READY: { GError *error = NULL; - if (mm_modem_get_state (self->priv->modem_iface) <= MM_MODEM_STATE_LOCKED) + if (mm_modem_get_state (self->_priv.modem_iface) <= MM_MODEM_STATE_LOCKED) break; /* Create core connect properties based on the modem capabilities */ @@ -532,7 +549,7 @@ connect_context_step (NMModemBroadband *self) nm_modem_ip_type_to_string (current), ctx->ip_type_tries + 1); - mm_modem_simple_connect (self->priv->simple_iface, + mm_modem_simple_connect (self->_priv.simple_iface, ctx->connect_properties, NULL, (GAsyncReadyCallback) connect_ready, @@ -544,7 +561,7 @@ connect_context_step (NMModemBroadband *self) /* fall through */ case CONNECT_STEP_LAST: - if (self->priv->ipv4_config || self->priv->ipv6_config) { + if (self->_priv.ipv4_config || self->_priv.ipv6_config) { g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, TRUE, NM_DEVICE_STATE_REASON_NONE); } else { /* If we have a saved error from a previous attempt, use it */ @@ -571,9 +588,9 @@ act_stage1_prepare (NMModem *_self, NMModemBroadband *self = NM_MODEM_BROADBAND (_self); /* Make sure we can get the Simple interface from the modem */ - if (!self->priv->simple_iface) { - self->priv->simple_iface = mm_object_get_modem_simple (self->priv->modem_object); - if (!self->priv->simple_iface) { + if (!self->_priv.simple_iface) { + self->_priv.simple_iface = mm_object_get_modem_simple (self->_priv.modem_object); + if (!self->_priv.simple_iface) { _LOGW ("cannot access the Simple mobile broadband modem interface"); *reason = NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED; return NM_ACT_STAGE_RETURN_FAILURE; @@ -583,12 +600,12 @@ act_stage1_prepare (NMModem *_self, connect_context_clear (self); /* Allocate new context for this connect stage attempt */ - self->priv->ctx = g_slice_new0 (ConnectContext); - self->priv->ctx->caps = mm_modem_get_current_capabilities (self->priv->modem_iface); - self->priv->ctx->cancellable = g_cancellable_new (); - self->priv->ctx->connection = g_object_ref (connection); + self->_priv.ctx = g_slice_new0 (ConnectContext); + self->_priv.ctx->caps = mm_modem_get_current_capabilities (self->_priv.modem_iface); + self->_priv.ctx->cancellable = g_cancellable_new (); + self->_priv.ctx->connection = g_object_ref (connection); - g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (self->priv->simple_iface), MODEM_CONNECT_TIMEOUT_SECS * 1000); + g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (self->_priv.simple_iface), MODEM_CONNECT_TIMEOUT_SECS * 1000); connect_context_step (self); return NM_ACT_STAGE_RETURN_POSTPONE; @@ -603,7 +620,7 @@ check_connection_compatible (NMModem *_self, NMConnection *connection) MMModemCapability modem_caps; NMSettingConnection *s_con; - modem_caps = mm_modem_get_current_capabilities (self->priv->modem_iface); + modem_caps = mm_modem_get_current_capabilities (self->_priv.modem_iface); s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); @@ -650,7 +667,7 @@ complete_connection (NMModem *_self, MMModemCapability modem_caps; NMSettingPpp *s_ppp; - modem_caps = mm_modem_get_current_capabilities (self->priv->modem_iface); + modem_caps = mm_modem_get_current_capabilities (self->_priv.modem_iface); /* PPP settings common to 3GPP and 3GPP2 */ s_ppp = nm_connection_get_setting_ppp (connection); @@ -827,12 +844,12 @@ set_mm_enabled (NMModem *_self, NMModemBroadband *self = NM_MODEM_BROADBAND (_self); if (enabled) { - mm_modem_enable (self->priv->modem_iface, + mm_modem_enable (self->_priv.modem_iface, NULL, /* cancellable */ (GAsyncReadyCallback)modem_enable_ready, g_object_ref (self)); } else { - mm_modem_disable (self->priv->modem_iface, + mm_modem_disable (self->_priv.modem_iface, NULL, /* cancellable */ (GAsyncReadyCallback)modem_disable_ready, g_object_ref (self)); @@ -871,13 +888,13 @@ static_stage3_ip4_done (NMModemBroadband *self) const gchar **dns; guint i; - g_assert (self->priv->ipv4_config); - g_assert (self->priv->bearer); + g_assert (self->_priv.ipv4_config); + g_assert (self->_priv.bearer); _LOGI ("IPv4 static configuration:"); /* Fully fail if invalid IP address retrieved */ - address_string = mm_bearer_ip_config_get_address (self->priv->ipv4_config); + address_string = mm_bearer_ip_config_get_address (self->_priv.ipv4_config); if (!ip4_string_to_num (address_string, &address_network)) { error = g_error_new (NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION, @@ -888,17 +905,17 @@ static_stage3_ip4_done (NMModemBroadband *self) } /* Missing gateway not a hard failure */ - gw_string = mm_bearer_ip_config_get_gateway (self->priv->ipv4_config); + gw_string = mm_bearer_ip_config_get_gateway (self->_priv.ipv4_config); ip4_string_to_num (gw_string, &gw); - data_port = mm_bearer_get_interface (self->priv->bearer); + data_port = mm_bearer_get_interface (self->_priv.bearer); g_assert (data_port); config = nm_ip4_config_new (nm_platform_link_get_ifindex (NM_PLATFORM_GET, data_port)); memset (&address, 0, sizeof (address)); address.address = address_network; address.peer_address = address_network; - address.plen = mm_bearer_ip_config_get_prefix (self->priv->ipv4_config); + address.plen = mm_bearer_ip_config_get_prefix (self->_priv.ipv4_config); address.addr_source = NM_IP_CONFIG_SOURCE_WWAN; if (address.plen <= 32) nm_ip4_config_add_address (config, &address); @@ -911,7 +928,7 @@ static_stage3_ip4_done (NMModemBroadband *self) } /* DNS servers */ - dns = mm_bearer_ip_config_get_dns (self->priv->ipv4_config); + dns = mm_bearer_ip_config_get_dns (self->_priv.ipv4_config); for (i = 0; dns && dns[i]; i++) { if ( ip4_string_to_num (dns[i], &address_network) && address_network > 0) { @@ -955,13 +972,13 @@ stage3_ip6_done (NMModemBroadband *self) const gchar **dns; guint i; - g_assert (self->priv->ipv6_config); + g_assert (self->_priv.ipv6_config); memset (&address, 0, sizeof (address)); - ip_method = get_bearer_ip_method (self->priv->ipv6_config); + ip_method = get_bearer_ip_method (self->_priv.ipv6_config); - address_string = mm_bearer_ip_config_get_address (self->priv->ipv6_config); + address_string = mm_bearer_ip_config_get_address (self->_priv.ipv6_config); if (!address_string) { /* DHCP/SLAAC is allowed to skip addresses; other methods require it */ if (ip_method != NM_MODEM_IP_METHOD_AUTO) { @@ -985,17 +1002,17 @@ stage3_ip6_done (NMModemBroadband *self) _LOGI ("IPv6 base configuration:"); - data_port = mm_bearer_get_interface (self->priv->bearer); + data_port = mm_bearer_get_interface (self->_priv.bearer); g_assert (data_port); config = nm_ip6_config_new (nm_platform_link_get_ifindex (NM_PLATFORM_GET, data_port)); - address.plen = mm_bearer_ip_config_get_prefix (self->priv->ipv6_config); + address.plen = mm_bearer_ip_config_get_prefix (self->_priv.ipv6_config); if (address.plen <= 128) nm_ip6_config_add_address (config, &address); _LOGI (" address %s/%d", address_string, address.plen); - address_string = mm_bearer_ip_config_get_gateway (self->priv->ipv6_config); + address_string = mm_bearer_ip_config_get_gateway (self->_priv.ipv6_config); if (address_string) { if (!inet_pton (AF_INET6, address_string, (void *) &(address.address))) { error = g_error_new (NM_DEVICE_ERROR, @@ -1017,7 +1034,7 @@ stage3_ip6_done (NMModemBroadband *self) } /* DNS servers */ - dns = mm_bearer_ip_config_get_dns (self->priv->ipv6_config); + dns = mm_bearer_ip_config_get_dns (self->_priv.ipv6_config); for (i = 0; dns[i]; i++) { struct in6_addr addr; @@ -1125,14 +1142,14 @@ disconnect (NMModem *modem, } /* If no simple iface, we're done */ - if (!ctx->self->priv->simple_iface) { + if (!ctx->self->_priv.simple_iface) { disconnect_context_complete (ctx); return; } _LOGD ("notifying ModemManager about the modem disconnection"); ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL; - mm_modem_simple_disconnect (ctx->self->priv->simple_iface, + mm_modem_simple_disconnect (ctx->self->_priv.simple_iface, NULL, /* bearer path; if NULL given ALL get disconnected */ cancellable, (GAsyncReadyCallback) simple_disconnect_ready, @@ -1149,11 +1166,11 @@ deactivate_cleanup (NMModem *_self, NMDevice *device) /* TODO: cancel SimpleConnect() if any */ /* Cleanup IPv4 addresses and routes */ - g_clear_object (&self->priv->ipv4_config); - g_clear_object (&self->priv->ipv6_config); - g_clear_object (&self->priv->bearer); + g_clear_object (&self->_priv.ipv4_config); + g_clear_object (&self->_priv.ipv6_config); + g_clear_object (&self->_priv.bearer); - self->priv->pin_tries = 0; + self->_priv.pin_tries = 0; /* Chain up parent's */ NM_MODEM_CLASS (nm_modem_broadband_parent_class)->deactivate_cleanup (_self, device); @@ -1202,7 +1219,7 @@ modem_state_changed (MMModem *modem, mm_state_to_nm (new_state), mm_modem_state_change_reason_get_string (reason)); - if (self->priv->ctx && self->priv->ctx->step == CONNECT_STEP_WAIT_FOR_READY) + if (self->_priv.ctx && self->_priv.ctx->step == CONNECT_STEP_WAIT_FOR_READY) connect_context_step (self); } @@ -1223,40 +1240,6 @@ mm_ip_family_to_nm (MMBearerIpFamily family) return nm_type; } -NMModem * -nm_modem_broadband_new (GObject *object, GError **error) -{ - NMModem *modem; - MMObject *modem_object; - MMModem *modem_iface; - gchar *drivers; - - g_return_val_if_fail (MM_IS_OBJECT (object), NULL); - modem_object = MM_OBJECT (object); - - /* Ensure we have the 'Modem' interface and the primary port at least */ - modem_iface = mm_object_peek_modem (modem_object); - g_return_val_if_fail (!!modem_iface, NULL); - g_return_val_if_fail (!!mm_modem_get_primary_port (modem_iface), NULL); - - /* Build a single string with all drivers listed */ - drivers = g_strjoinv (", ", (gchar **)mm_modem_get_drivers (modem_iface)); - - modem = 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), - NM_MODEM_CONTROL_PORT, mm_modem_get_primary_port (modem_iface), - NM_MODEM_DATA_PORT, NULL, /* We don't know it until bearer created */ - NM_MODEM_IP_TYPES, mm_ip_family_to_nm (mm_modem_get_supported_ip_families (modem_iface)), - NM_MODEM_STATE, mm_state_to_nm (mm_modem_get_state (modem_iface)), - NM_MODEM_DEVICE_ID, mm_modem_get_device_identifier (modem_iface), - NM_MODEM_BROADBAND_MODEM, modem_object, - NM_MODEM_DRIVER, drivers, - NULL); - g_free (drivers); - return modem; -} - static void get_sim_ready (MMModem *modem, GAsyncResult *res, @@ -1267,20 +1250,20 @@ get_sim_ready (MMModem *modem, new_sim = mm_modem_get_sim_finish (modem, res, &error); - if (new_sim != self->priv->sim_iface) { - g_clear_object (&self->priv->sim_iface); - self->priv->sim_iface = new_sim; + if (new_sim != self->_priv.sim_iface) { + g_clear_object (&self->_priv.sim_iface); + self->_priv.sim_iface = new_sim; } else g_clear_object (&new_sim); - if (self->priv->sim_iface) { + if (self->_priv.sim_iface) { g_object_set (G_OBJECT (self), - NM_MODEM_SIM_ID, mm_sim_get_identifier (self->priv->sim_iface), - NM_MODEM_SIM_OPERATOR_ID, mm_sim_get_operator_identifier (self->priv->sim_iface), + NM_MODEM_SIM_ID, mm_sim_get_identifier (self->_priv.sim_iface), + NM_MODEM_SIM_OPERATOR_ID, mm_sim_get_operator_identifier (self->_priv.sim_iface), NULL); /* If we're waiting for the SIM during a connect, proceed with the connect */ - if (self->priv->ctx && self->priv->ctx->step == CONNECT_STEP_WAIT_FOR_SIM) + if (self->_priv.ctx && self->_priv.ctx->step == CONNECT_STEP_WAIT_FOR_SIM) connect_context_step (self); } else { _NMLOG (g_error_matches (error, MM_CORE_ERROR, MM_CORE_ERROR_NOT_FOUND) @@ -1297,10 +1280,10 @@ sim_changed (MMModem *modem, GParamSpec *pspec, gpointer user_data) { NMModemBroadband *self = NM_MODEM_BROADBAND (user_data); - g_return_if_fail (modem == self->priv->modem_iface); + g_return_if_fail (modem == self->_priv.modem_iface); - if (mm_modem_get_sim_path (self->priv->modem_iface)) { - mm_modem_get_sim (self->priv->modem_iface, + if (mm_modem_get_sim_path (self->_priv.modem_iface)) { + mm_modem_get_sim (self->_priv.modem_iface, NULL, /* cancellable */ (GAsyncReadyCallback) get_sim_ready, g_object_ref (self)); @@ -1316,7 +1299,7 @@ supported_ip_families_changed (MMModem *modem, GParamSpec *pspec, gpointer user_ { NMModemBroadband *self = NM_MODEM_BROADBAND (user_data); - g_return_if_fail (modem == self->priv->modem_iface); + g_return_if_fail (modem == self->_priv.modem_iface); g_object_set (G_OBJECT (self), NM_MODEM_IP_TYPES, @@ -1324,12 +1307,24 @@ supported_ip_families_changed (MMModem *modem, GParamSpec *pspec, gpointer user_ NULL); } +/*****************************************************************************/ + static void -nm_modem_broadband_init (NMModemBroadband *self) +get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) { - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - NM_TYPE_MODEM_BROADBAND, - NMModemBroadbandPrivate); + NMModemBroadband *self = NM_MODEM_BROADBAND (object); + + switch (prop_id) { + case PROP_MODEM: + g_value_set_object (value, self->_priv.modem_object); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } static void @@ -1343,19 +1338,19 @@ set_property (GObject *object, switch (prop_id) { case PROP_MODEM: /* construct-only */ - self->priv->modem_object = g_value_dup_object (value); - self->priv->modem_iface = mm_object_get_modem (self->priv->modem_object); - g_assert (self->priv->modem_iface != NULL); - g_signal_connect (self->priv->modem_iface, + self->_priv.modem_object = g_value_dup_object (value); + self->_priv.modem_iface = mm_object_get_modem (self->_priv.modem_object); + g_assert (self->_priv.modem_iface != NULL); + g_signal_connect (self->_priv.modem_iface, "state-changed", G_CALLBACK (modem_state_changed), self); - g_signal_connect (self->priv->modem_iface, + g_signal_connect (self->_priv.modem_iface, "notify::sim", G_CALLBACK (sim_changed), self); - sim_changed (self->priv->modem_iface, NULL, self); - g_signal_connect (self->priv->modem_iface, + sim_changed (self->_priv.modem_iface, NULL, self); + g_signal_connect (self->_priv.modem_iface, "notify::supported-ip-families", G_CALLBACK (supported_ip_families_changed), self); @@ -1369,22 +1364,45 @@ set_property (GObject *object, } } +/*****************************************************************************/ + static void -get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) +nm_modem_broadband_init (NMModemBroadband *self) { - NMModemBroadband *self = NM_MODEM_BROADBAND (object); +} - switch (prop_id) { - case PROP_MODEM: - g_value_set_object (value, self->priv->modem_object); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } +NMModem * +nm_modem_broadband_new (GObject *object, GError **error) +{ + NMModem *modem; + MMObject *modem_object; + MMModem *modem_iface; + gchar *drivers; + + g_return_val_if_fail (MM_IS_OBJECT (object), NULL); + modem_object = MM_OBJECT (object); + + /* Ensure we have the 'Modem' interface and the primary port at least */ + modem_iface = mm_object_peek_modem (modem_object); + g_return_val_if_fail (!!modem_iface, NULL); + g_return_val_if_fail (!!mm_modem_get_primary_port (modem_iface), NULL); + + /* Build a single string with all drivers listed */ + drivers = g_strjoinv (", ", (gchar **)mm_modem_get_drivers (modem_iface)); + + modem = 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), + NM_MODEM_CONTROL_PORT, mm_modem_get_primary_port (modem_iface), + NM_MODEM_DATA_PORT, NULL, /* We don't know it until bearer created */ + NM_MODEM_IP_TYPES, mm_ip_family_to_nm (mm_modem_get_supported_ip_families (modem_iface)), + NM_MODEM_STATE, mm_state_to_nm (mm_modem_get_state (modem_iface)), + NM_MODEM_DEVICE_ID, mm_modem_get_device_identifier (modem_iface), + NM_MODEM_BROADBAND_MODEM, modem_object, + NM_MODEM_DRIVER, drivers, + NULL); + g_free (drivers); + return modem; } static void @@ -1393,13 +1411,13 @@ dispose (GObject *object) NMModemBroadband *self = NM_MODEM_BROADBAND (object); connect_context_clear (self); - g_clear_object (&self->priv->ipv4_config); - g_clear_object (&self->priv->ipv6_config); - g_clear_object (&self->priv->bearer); - g_clear_object (&self->priv->modem_iface); - g_clear_object (&self->priv->simple_iface); - g_clear_object (&self->priv->sim_iface); - g_clear_object (&self->priv->modem_object); + g_clear_object (&self->_priv.ipv4_config); + g_clear_object (&self->_priv.ipv6_config); + g_clear_object (&self->_priv.bearer); + g_clear_object (&self->_priv.modem_iface); + g_clear_object (&self->_priv.simple_iface); + g_clear_object (&self->_priv.sim_iface); + g_clear_object (&self->_priv.modem_object); G_OBJECT_CLASS (nm_modem_broadband_parent_class)->dispose (object); } @@ -1410,9 +1428,6 @@ nm_modem_broadband_class_init (NMModemBroadbandClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); NMModemClass *modem_class = NM_MODEM_CLASS (klass); - g_type_class_add_private (object_class, sizeof (NMModemBroadbandPrivate)); - - /* Virtual methods */ object_class->dispose = dispose; object_class->get_property = get_property; object_class->set_property = set_property; @@ -1430,11 +1445,11 @@ nm_modem_broadband_class_init (NMModemBroadbandClass *klass) modem_class->act_stage1_prepare = act_stage1_prepare; modem_class->owns_port = owns_port; - /* Properties */ - g_object_class_install_property - (object_class, PROP_MODEM, - g_param_spec_object (NM_MODEM_BROADBAND_MODEM, "", "", - MM_GDBUS_TYPE_OBJECT, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); + obj_properties[PROP_MODEM] = + g_param_spec_object (NM_MODEM_BROADBAND_MODEM, "", "", + MM_GDBUS_TYPE_OBJECT, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS); + + g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties); } |