diff options
-rw-r--r-- | src/sim.c | 26 |
1 files changed, 19 insertions, 7 deletions
@@ -236,7 +236,8 @@ static GDBusSignalTable sim_manager_signals[] = { { } }; static char *network_name_parse(const unsigned char *buffer, int length) { unsigned char *endp; - unsigned int dcs; + unsigned char dcs; + int i; if (length < 1) return NULL; @@ -244,10 +245,10 @@ static char *network_name_parse(const unsigned char *buffer, int length) dcs = *buffer ++; length --; - if (dcs & (1 << 3)) { - /* TODO: "The MS should add the letters for the Country's - * Initials and a separator (e.g. a space)" */ - } + /* TODO: "The MS should add the letters for the Country's + * Initials and a separator (e.g. a space)" */ + if (is_bit_set(dcs, 4)) + ofono_error("Network Name DCS implies country initials"); switch (dcs & (7 << 4)) { case 0x00: @@ -257,8 +258,19 @@ static char *network_name_parse(const unsigned char *buffer, int length) return convert_gsm_to_utf8(buffer, length, NULL, NULL, 0xff); case 0x10: - return convert_ucs2_to_utf8(buffer, length, - NULL, NULL, 0xffff); + if ((length % 2) == 1) { + if (buffer[length - 1] != 0xff) + return NULL; + + length = length - 1; + } + + for (i = 0; i < length; i += 2) + if (buffer[i] == 0xff && buffer[i + 1] == 0xff) + break; + + return g_convert(buffer, length, "UTF-8//TRANSLIT", "UCS-2BE", + NULL, NULL, NULL); } return NULL; |