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:
@@ -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;
|
||||
}
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user