diff options
author | Eric Caruso <ejcaruso@chromium.org> | 2020-10-16 11:22:37 -0700 |
---|---|---|
committer | Eric Caruso <ejcaruso@chromium.org> | 2020-10-16 11:22:37 -0700 |
commit | 1800983b6c77b495a97eb4335541561456abfed5 (patch) | |
tree | 9882f6130f9ef91ec298eba2d1243e6a9d1ae668 /src/mm-modem-helpers.c | |
parent | f013e94ff89680d1acd7dba12ff4a6a0fa7b58bf (diff) |
mm-modem-helpers: add low_nybble_first argument to mm_bcd_to_string
All BCD-encoded strings used by MM currently have the low nybble
of each byte come before the high nybble, but some strings (such
as the EID string returned by QMI Get Slot Status) are meant to
be read in order with the high nybble before the low one. As such,
extend mm_bcd_to_string to decode both.
Diffstat (limited to 'src/mm-modem-helpers.c')
-rw-r--r-- | src/mm-modem-helpers.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index d080e010..3ee12aaa 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -473,7 +473,7 @@ mm_filter_supported_modes (const GArray *all, static const gchar bcd_chars[] = "0123456789\0\0\0\0\0\0"; gchar * -mm_bcd_to_string (const guint8 *bcd, gsize bcd_len) +mm_bcd_to_string (const guint8 *bcd, gsize bcd_len, gboolean low_nybble_first) { GString *str; gsize i; @@ -482,8 +482,11 @@ mm_bcd_to_string (const guint8 *bcd, gsize bcd_len) str = g_string_sized_new (bcd_len * 2 + 1); for (i = 0 ; i < bcd_len; i++) { - str = g_string_append_c (str, bcd_chars[bcd[i] & 0xF]); + if (low_nybble_first) + str = g_string_append_c (str, bcd_chars[bcd[i] & 0xF]); str = g_string_append_c (str, bcd_chars[(bcd[i] >> 4) & 0xF]); + if (!low_nybble_first) + str = g_string_append_c (str, bcd_chars[bcd[i] & 0xF]); } return g_string_free (str, FALSE); } @@ -4301,7 +4304,7 @@ mm_3gpp_parse_emergency_numbers (const char *raw, GError **error) for (i = 0; i < max_items; i++) { gchar *number; - number = mm_bcd_to_string (&bin[i*3], 3); + number = mm_bcd_to_string (&bin[i*3], 3, TRUE /* low_nybble_first */); if (number && number[0]) g_ptr_array_add (out, number); else |