diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-09-19 07:35:23 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-09-19 07:42:47 +0200 |
commit | a6faae32608833f3d26d57bc6bace4f2a9add8bd (patch) | |
tree | 4dc6bb0e66272ebc9f2e993132105dc1e61ec4d3 /src | |
parent | d2353e01ff4b786da4542f7fd6f4f4e76081f450 (diff) |
broadband-modem: skip +CGMM: prefix when loading device model
Some devices, e.g. ZTE MF820D, seem to prefix the `AT+CGMM?' response with the
`+CGMM:' string, resulting in the following model string being loaded:
model: '+CGMM: "MF820D"'
Avoid this by:
1) Removing the expected prefixes.
2) Unquoting the resulting string.
Reported by: Marius Kotsbak <marius.kotsbak@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/mm-broadband-modem.c | 12 | ||||
-rw-r--r-- | src/mm-modem-helpers.c | 17 | ||||
-rw-r--r-- | src/mm-modem-helpers.h | 5 |
3 files changed, 31 insertions, 3 deletions
diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 77650490..4a2fdb8e 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -634,13 +634,23 @@ modem_load_model_finish (MMIfaceModem *self, GError **error) { GVariant *result; + const gchar *p; gchar *model; result = mm_base_modem_at_sequence_finish (MM_BASE_MODEM (self), res, NULL, error); if (!result) return NULL; - model = g_strstrip (g_variant_dup_string (result, NULL)); + p = g_variant_get_string (result, NULL); + + /* Some devices (e.g. ZTE MF820D) seem to include the command prefix */ + p = mm_strip_tag (p, "+CGMM:"); + p = mm_strip_tag (p, "+GMM:"); + model = g_strdup (p); + + /* Stripping quotes modifies string in place */ + model = mm_strip_quotes (model); + mm_dbg ("loaded model: %s", model); return model; } diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 60d7459b..db0bfbdf 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -32,6 +32,23 @@ /*****************************************************************************/ +gchar * +mm_strip_quotes (gchar *str) +{ + gsize len; + + if (!str) + return NULL; + + len = strlen (str); + if ((len >= 2) && (str[0] == '"') && (str[len - 1] == '"')) { + str[0] = ' '; + str[len - 1] = ' '; + } + + return g_strstrip (str); +} + const gchar * mm_strip_tag (const gchar *str, const gchar *cmd) { diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h index 95b15ebc..b8573aa5 100644 --- a/src/mm-modem-helpers.h +++ b/src/mm-modem-helpers.h @@ -44,8 +44,9 @@ (MM_MODEM_CAPABILITY_GSM_UMTS | \ MM_MODEM_CAPABILITY_3GPP_LTE) -const gchar *mm_strip_tag (const gchar *str, - const gchar *cmd); +gchar *mm_strip_quotes (gchar *str); +const gchar *mm_strip_tag (const gchar *str, + const gchar *cmd); guint mm_count_bits_set (gulong number); |