From 2550cb20a9741378c747233ddea8e7a7daa5c198 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Tue, 15 Jan 2013 16:05:11 +0100 Subject: [PATCH] huawei: only retry DHCP? check on specific errors We don't want to retry DHCP? on every possible GError reported; specially if the error is about the port being forced to get closed when the modem gets unplugged or the like. So just retry on very specific errors reported. The main cause for retry is really when the modem replies the following: --> AT^DHCP? <-- ERROR Which in our case gets translated to a 'unknown' mobile equipment error. We'll also consider any kind of mobile equipment error, as the modems may reply a CME ERROR instead. --- plugins/huawei/mm-broadband-bearer-huawei.c | 25 ++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/plugins/huawei/mm-broadband-bearer-huawei.c b/plugins/huawei/mm-broadband-bearer-huawei.c index 75176dbe..67a98243 100644 --- a/plugins/huawei/mm-broadband-bearer-huawei.c +++ b/plugins/huawei/mm-broadband-bearer-huawei.c @@ -115,6 +115,7 @@ connect_dhcp_check_ready (MMBaseModem *modem, MMBroadbandBearerHuawei *self) { Connect3gppContext *ctx; + GError *error = NULL; ctx = self->priv->connect_pending; g_assert (ctx != NULL); @@ -122,11 +123,25 @@ connect_dhcp_check_ready (MMBaseModem *modem, /* Balance refcount */ g_object_unref (self); - if (!mm_base_modem_at_command_full_finish (modem, res, NULL)) { - /* Setup timeout to retry the same step */ - g_timeout_add_seconds (1, - (GSourceFunc)connect_retry_dhcp_check_cb, - g_object_ref (self)); + if (!mm_base_modem_at_command_full_finish (modem, res, &error)) { + /* Only retry the DHCP check if we get a mobile equipment error, or if + * the command timed out. */ + if (error->domain == MM_MOBILE_EQUIPMENT_ERROR || + g_error_matches (error, + MM_SERIAL_ERROR, + MM_SERIAL_ERROR_RESPONSE_TIMEOUT)) { + g_error_free (error); + /* Setup timeout to retry the same step */ + g_timeout_add_seconds (1, + (GSourceFunc)connect_retry_dhcp_check_cb, + g_object_ref (self)); + return; + } + + /* Fatal error happened; e.g. modem unplugged */ + self->priv->connect_pending = NULL; + g_simple_async_result_take_error (ctx->result, error); + connect_3gpp_context_complete_and_free (ctx); return; }