diff options
author | Dan Williams <dcbw@redhat.com> | 2012-02-07 23:00:23 -0600 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2012-02-07 23:18:40 -0600 |
commit | 0ab87a6423da823358b2c3e6a0a81816b133c5f1 (patch) | |
tree | d8597b41952e4f03d0b079b9177861e240c2a0a1 | |
parent | 59ce2e974fcc7aae9e03bf24ff3bb4f1a46fb52b (diff) | |
download | NetworkManager-0ab87a6423da823358b2c3e6a0a81816b133c5f1.tar.gz |
modem: delay connect a bit after sending the PIN
Modems take a bit of time, and ModemManager may not quite be
ready for immediate connect after sending the PIN since the
modem isn't enabled. The specific issue was that MM is still
closing serial ports, so if we try to enable too soon we'll
get an error about serial ports being closed.
-rw-r--r-- | src/modem-manager/nm-modem-gsm.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/modem-manager/nm-modem-gsm.c b/src/modem-manager/nm-modem-gsm.c index 9764937cf5..c50ca7b453 100644 --- a/src/modem-manager/nm-modem-gsm.c +++ b/src/modem-manager/nm-modem-gsm.c @@ -65,6 +65,8 @@ typedef struct { GHashTable *connect_properties; guint32 pin_tries; + + guint enable_delay_id; } NMModemGsmPrivate; @@ -244,32 +246,39 @@ do_connect (NMModemGsm *self) static void stage1_enable_done (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data); -static void +/* do_enable() is used as a GSourceFunc, hence the gboolean return */ +static gboolean do_enable (NMModemGsm *self) { DBusGProxy *proxy; - g_return_if_fail (self != NULL); - g_return_if_fail (NM_IS_MODEM_GSM (self)); + 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_get_proxy (NM_MODEM (self), MM_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 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; go back and try the enable again */ - do_enable (self); + /* 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, @@ -532,6 +541,9 @@ real_deactivate_quickly (NMModem *modem, NMDevice *device) 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_quickly (modem, device); } @@ -551,6 +563,8 @@ dispose (GObject *object) if (priv->connect_properties) g_hash_table_destroy (priv->connect_properties); + if (priv->enable_delay_id) + g_source_remove (priv->enable_delay_id); G_OBJECT_CLASS (nm_modem_gsm_parent_class)->dispose (object); } |