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>
This commit is contained in:
Aleksander Morgado
2012-09-19 07:35:23 +02:00
parent d2353e01ff
commit a6faae3260
3 changed files with 31 additions and 3 deletions

View File

@@ -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;
}

View File

@@ -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)
{

View File

@@ -44,6 +44,7 @@
(MM_MODEM_CAPABILITY_GSM_UMTS | \
MM_MODEM_CAPABILITY_3GPP_LTE)
gchar *mm_strip_quotes (gchar *str);
const gchar *mm_strip_tag (const gchar *str,
const gchar *cmd);