diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-07-15 18:26:11 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-07-30 16:17:41 +0200 |
commit | f84f641af014e12a6f0ecda43bb365ec9456eb16 (patch) | |
tree | df3ec64c777a15dc6b066e921ba8b9be784f0882 | |
parent | a056ed442621469bff57738ef8661ea32556ddbc (diff) |
huawei: limit the number of deferred tasks
The Huawei plugin requires to probe first the USB interface 0; all the other
probing tasks in the remaining ports will get deferred until the interface 0
gets probed. But, some modems (e.g. Huawei ET8282), don't expose the USB
interface 0 as an AT port, so we get an infinite loop as no port ends up being
probed.
In order to fix this, we will limit to a predefined maximum the number of times
a given probing task is deferred, 4 in this case. So, if a given probing task is
deferred for more than 4x3s=12s, probing will get forced.
-rw-r--r-- | plugins/mm-plugin-huawei.c | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/plugins/mm-plugin-huawei.c b/plugins/mm-plugin-huawei.c index fe7ffa0e..1a50e9fb 100644 --- a/plugins/mm-plugin-huawei.c +++ b/plugins/mm-plugin-huawei.c @@ -159,6 +159,9 @@ add_regex (MMAtSerialPort *port, const char *match, gpointer user_data) g_regex_unref (regex); } +#define TAG_DEFER_COUNTS_PREFIX "huawei-defer-counts" +#define MAX_DEFERS 5 + static MMPluginSupportsResult supports_port (MMPluginBase *base, MMModem *existing, @@ -198,8 +201,31 @@ supports_port (MMPluginBase *base, * we need to use the first port that does respond to probing to create the * right type of mode (GSM or CDMA), and then re-check the other interfaces. */ - if (!existing && usbif != 0) - return MM_PLUGIN_SUPPORTS_PORT_DEFER; + if (!existing && usbif != 0) { + gchar *tag; + guint n_deferred; + + /* We need to defer the probing as usbif 0 wasn't probed yet. We need to + * protect against the case of not having usbif 0 as an AT port, and we + * do that by limiting the number of times we defer the probing. */ + + tag = g_strdup_printf ("%s-%s/%s", TAG_DEFER_COUNTS_PREFIX, subsys, name); + /* First time requested will be 0 */ + n_deferred = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (base), tag)); + if (n_deferred < MAX_DEFERS) { + /* Update defer count */ + g_object_set_data (G_OBJECT (base), tag, GUINT_TO_POINTER (n_deferred + 1)); + g_free (tag); + return MM_PLUGIN_SUPPORTS_PORT_DEFER; + } + + mm_dbg ("(%s): no longer waiting for usbif 0, will launch probing in interface (%s/%s)", + mm_plugin_get_name (MM_PLUGIN (base)), subsys, name); + g_free (tag); + + /* Clear tag */ + g_object_set_data (G_OBJECT (base), tag, NULL); + } /* CDMA devices don't have problems with the secondary ports, so after * ensuring we have a device by probing the first port, probe the secondary |