diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2013-02-22 18:58:06 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2013-02-22 19:43:49 +0100 |
commit | b1bb8e30b4fd835649b5790895fcd519f1809141 (patch) | |
tree | 256c59922b255d6f451c58318ffee0be87fcefef | |
parent | ca49af0c5d4b649950ef3ed038e70f58a37050f3 (diff) | |
download | ModemManager-b1bb8e30b4fd835649b5790895fcd519f1809141.tar.gz |
broadband-modem: don't assume the returned string is always hex-encoded
-rw-r--r-- | libmm-glib/mm-common-helpers.c | 25 | ||||
-rw-r--r-- | libmm-glib/mm-common-helpers.h | 1 | ||||
-rw-r--r-- | src/mm-broadband-modem.c | 7 |
3 files changed, 32 insertions, 1 deletions
diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c index 3f100b681..4694be8d5 100644 --- a/libmm-glib/mm-common-helpers.c +++ b/libmm-glib/mm-common-helpers.c @@ -929,6 +929,31 @@ mm_utils_hexstr2bin (const gchar *hex, gsize *out_len) /* End from hostap */ +gboolean +mm_utils_ishexstr (const gchar *hex) +{ + gsize len; + gsize i; + + /* Length not multiple of 2? */ + len = strlen (hex); + if (len % 2 != 0) + return FALSE; + + for (i = 0; i < len; i++) { + /* Non-hex char? */ + if (hex[i] >= '0' && hex[i] <= '9') + continue; + if (hex[i] >= 'a' && hex[i] <= 'f') + continue; + if (hex[i] >= 'A' && hex[i] <= 'F') + continue; + return FALSE; + } + + return TRUE; +} + gchar * mm_utils_bin2hexstr (const guint8 *bin, gsize len) { diff --git a/libmm-glib/mm-common-helpers.h b/libmm-glib/mm-common-helpers.h index 6155b5875..d23fc73e3 100644 --- a/libmm-glib/mm-common-helpers.h +++ b/libmm-glib/mm-common-helpers.h @@ -99,6 +99,7 @@ const gchar *mm_sms_delivery_state_get_string_extended (guint delivery_state); gint mm_utils_hex2byte (const gchar *hex); gchar *mm_utils_hexstr2bin (const gchar *hex, gsize *out_len); gchar *mm_utils_bin2hexstr (const guint8 *bin, gsize len); +gboolean mm_utils_ishexstr (const gchar *hex); gboolean mm_utils_check_for_single_value (guint32 value); diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index ab26b345d..a3f5ba47d 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -4373,8 +4373,13 @@ decode_ussd_response (MMBroadbandModem *self, if (p) *p = '\0'; - decoded = mm_iface_modem_3gpp_ussd_decode (MM_IFACE_MODEM_3GPP_USSD (self), str, error); + /* If reply doesn't seem to be hex; just return itself... */ + if (!mm_utils_ishexstr (str)) + decoded = g_strdup (str); + else + decoded = mm_iface_modem_3gpp_ussd_decode (MM_IFACE_MODEM_3GPP_USSD (self), str, error); g_strfreev (items); + return decoded; } |