summaryrefslogtreecommitdiffstats
path: root/src/sim.c
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2009-07-09 11:42:04 -0500
committerDenis Kenzior <denkenz@gmail.com>2009-07-14 15:45:03 -0500
commit2de9ad258bb51a6d93e4fc7743557b69a34a1ef2 (patch)
treed4b954e5875fdf7a806805306ecc874918964e50 /src/sim.c
parent98a4308b307cefd3b6daa60195d4e8d91ec7c709 (diff)
downloadofono-2de9ad258bb51a6d93e4fc7743557b69a34a1ef2.tar.bz2
Cleanup network_name_parse
Diffstat (limited to 'src/sim.c')
-rw-r--r--src/sim.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/sim.c b/src/sim.c
index 719013cb..beba0fcf 100644
--- a/src/sim.c
+++ b/src/sim.c
@@ -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;