diff options
Diffstat (limited to 'src/mm-modem-helpers.c')
-rw-r--r-- | src/mm-modem-helpers.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 99d91ed9..2058fe5c 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -5329,6 +5329,56 @@ mm_sim_parse_cpol_test_response (const gchar *response, return TRUE; } +gchar * +mm_sim_convert_spn_to_utf8 (const guint8 *bin, + gsize binlen, + GError **error) +{ + g_autoptr(GByteArray) bin_array = NULL; + + /* Remove the FF filler at the end */ + while (binlen > 1 && bin[binlen - 1] == 0xff) + binlen--; + if (binlen <= 1) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "SIM returned empty response"); + return NULL; + } + + /* Setup as bytearray. + * First byte is metadata; remainder is GSM-7 unpacked into octets; convert to UTF8 */ + bin_array = g_byte_array_sized_new (binlen - 1); + g_byte_array_append (bin_array, bin + 1, binlen - 1); + + return mm_modem_charset_bytearray_to_utf8 (bin_array, MM_MODEM_CHARSET_GSM, FALSE, error); +} + +guint +mm_sim_validate_mnc_length (const guint8 *bin, + gsize binlen, + GError **error) +{ + guint mnc_len; + + if (binlen < 4) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "SIM returned too short response of length %lu (should be 4)", + binlen); + return 0; + } + + /* MNC length is byte 4 of this SIM file */ + mnc_len = bin[3]; + if (mnc_len != 2 && mnc_len != 3) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "SIM returned invalid MNC length %u (should be either 2 or 3)", + mnc_len); + return 0; + } + + return mnc_len; +} + #define EID_BYTE_LENGTH 16 gchar * |