static void stage1_prepare_done (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data) { NMModemGsm *self = NM_MODEM_GSM (user_data); NMModemGsmPrivate *priv = NM_MODEM_GSM_GET_PRIVATE (self); GError *error = NULL; priv->call = NULL; if (priv->connect_properties) { g_hash_table_destroy (priv->connect_properties); priv->connect_properties = NULL; } if (dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID)) g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, TRUE, NM_DEVICE_STATE_REASON_NONE); else { if (dbus_g_error_has_name (error, MM_MODEM_ERROR_SIM_PIN)) ask_for_pin (self, FALSE); else if (dbus_g_error_has_name (error, MM_MODEM_ERROR_SIM_WRONG)) ask_for_pin (self, TRUE); else { nm_log_warn (LOGD_MB, "GSM connection failed: (%d) %s", error ? error->code : -1, error && error->message ? error->message : "(unknown)"); g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, FALSE, translate_mm_error (error)); } g_error_free (error); } }
static NMActStageReturn act_stage1_prepare (NMModem *modem, NMActRequest *req, GPtrArray **out_hints, const char **out_setting_name, NMDeviceStateReason *reason) { NMModemGsm *self = NM_MODEM_GSM (modem); NMModemGsmPrivate *priv = NM_MODEM_GSM_GET_PRIVATE (self); NMConnection *connection; connection = nm_act_request_get_connection (req); g_assert (connection); *out_setting_name = nm_connection_need_secrets (connection, out_hints); if (!*out_setting_name) { gboolean enabled = nm_modem_get_mm_enabled (modem); if (priv->connect_properties) g_hash_table_destroy (priv->connect_properties); priv->connect_properties = create_connect_properties (connection); if (enabled) do_connect (self); else do_enable (self); } else { /* NMModem will handle requesting secrets... */ } return NM_ACT_STAGE_RETURN_POSTPONE; }
static void stage1_pin_done (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data) { NMModemGsm *self = NM_MODEM_GSM (user_data); NMModemGsmPrivate *priv = NM_MODEM_GSM_GET_PRIVATE (self); NMDeviceStateReason reason; GError *error = NULL; if (dbus_g_proxy_end_call (proxy, call_id, &error, G_TYPE_INVALID)) { /* Success; try to enable the modem again. Wait a few seconds to ensure * that ModemManager is ready for the enable right after the unlock. */ if (priv->enable_delay_id == 0) priv->enable_delay_id = g_timeout_add_seconds (4, (GSourceFunc) do_enable, self); } else { nm_log_warn (LOGD_MB, "GSM PIN unlock failed: (%d) %s", error ? error->code : -1, error && error->message ? error->message : "(unknown)"); /* try to translate the error reason */ reason = translate_mm_error (error); if (reason == NM_DEVICE_STATE_REASON_UNKNOWN) reason = NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED; g_signal_emit_by_name (self, NM_MODEM_PREPARE_RESULT, FALSE, reason); g_error_free (error); } }
static void dispose (GObject *object) { NMModemGsm *self = NM_MODEM_GSM (object); NMModemGsmPrivate *priv = NM_MODEM_GSM_GET_PRIVATE (self); if (priv->connect_properties) g_hash_table_destroy (priv->connect_properties); G_OBJECT_CLASS (nm_modem_gsm_parent_class)->dispose (object); }
static void do_connect (NMModemGsm *self) { NMModemGsmPrivate *priv = NM_MODEM_GSM_GET_PRIVATE (self); DBusGProxy *proxy; proxy = nm_modem_generic_get_proxy (NM_MODEM_GENERIC (self), MM_OLD_DBUS_INTERFACE_MODEM_SIMPLE); priv->call = dbus_g_proxy_begin_call_with_timeout (proxy, "Connect", stage1_prepare_done, self, NULL, 120000, DBUS_TYPE_G_MAP_OF_VARIANT, priv->connect_properties, G_TYPE_INVALID); }
/* do_enable() is used as a GSourceFunc, hence the gboolean return */ static gboolean do_enable (NMModemGsm *self) { DBusGProxy *proxy; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (NM_IS_MODEM_GSM (self), FALSE); NM_MODEM_GSM_GET_PRIVATE (self)->enable_delay_id = 0; proxy = nm_modem_generic_get_proxy (NM_MODEM_GENERIC (self), MM_OLD_DBUS_INTERFACE_MODEM); dbus_g_proxy_begin_call_with_timeout (proxy, "Enable", stage1_enable_done, self, NULL, 20000, G_TYPE_BOOLEAN, TRUE, G_TYPE_INVALID); return FALSE; }
static void real_deactivate (NMModem *modem, NMDevice *device) { NMModemGsmPrivate *priv = NM_MODEM_GSM_GET_PRIVATE (modem); if (priv->call) { DBusGProxy *proxy; proxy = nm_modem_get_proxy (modem, MM_DBUS_INTERFACE_MODEM_SIMPLE); dbus_g_proxy_cancel_call (proxy, priv->call); priv->call = NULL; } priv->pin_tries = 0; NM_MODEM_CLASS (nm_modem_gsm_parent_class)->deactivate (modem, device); }
static void ask_for_pin (NMModemGsm *self, gboolean always_ask) { NMModemGsmPrivate *priv; guint32 tries = 0; g_return_if_fail (self != NULL); g_return_if_fail (NM_IS_MODEM_GSM (self)); priv = NM_MODEM_GSM_GET_PRIVATE (self); if (!always_ask) tries = priv->pin_tries++; nm_modem_get_secrets (NM_MODEM (self), NM_SETTING_GSM_SETTING_NAME, (tries || always_ask) ? TRUE : FALSE, NM_SETTING_GSM_PIN); }
static void deactivate (NMModem *modem, NMDevice *device) { NMModemGsmPrivate *priv = NM_MODEM_GSM_GET_PRIVATE (modem); if (priv->call) { DBusGProxy *proxy; proxy = nm_modem_generic_get_proxy (NM_MODEM_GENERIC (modem), MM_OLD_DBUS_INTERFACE_MODEM_SIMPLE); dbus_g_proxy_cancel_call (proxy, priv->call); priv->call = NULL; } priv->pin_tries = 0; if (priv->enable_delay_id) g_source_remove (priv->enable_delay_id); NM_MODEM_CLASS (nm_modem_gsm_parent_class)->deactivate (modem, device); }
static void handle_enable_pin_required (NMModemGsm *self) { NMModemGsmPrivate *priv = NM_MODEM_GSM_GET_PRIVATE (self); const char *pin = NULL; GValue *value; DBusGProxy *proxy; /* See if we have a PIN already */ value = g_hash_table_lookup (priv->connect_properties, "pin"); if (value && G_VALUE_HOLDS_STRING (value)) pin = g_value_get_string (value); /* If we do, send it */ if (pin) { proxy = nm_modem_generic_get_proxy (NM_MODEM_GENERIC (self), MM_OLD_DBUS_INTERFACE_MODEM_GSM_CARD); dbus_g_proxy_begin_call_with_timeout (proxy, "SendPin", stage1_pin_done, self, NULL, 10000, G_TYPE_STRING, pin, G_TYPE_INVALID); } else ask_for_pin (self, FALSE); }