simutil: Fix EF_PNN access
authorAlfonso Sanchez-Beato <alfonso.sanchez-beato@canonical.com>
Fri, 14 Mar 2014 16:23:43 +0000 (17:23 +0100)
committerDenis Kenzior <denkenz@gmail.com>
Fri, 14 Mar 2014 17:24:26 +0000 (12:24 -0500)
EF_PNN was not being read properly (see TS 24.008, section 10.5.3.5a,
for network names format), which affected the displayed PLMN name for
some MVNOs. Some modems already read the file and return the right
string: these do not show the problem.

src/simutil.c

index 90d7f8d2834db281aa5de8a73b5a94d8e51d0905..a7745ae2601cfd5f836d6b0ca426249ed9a65146 100644 (file)
@@ -767,12 +767,14 @@ static char *sim_network_name_parse(const unsigned char *buffer, int length,
                                        gboolean *add_ci)
 {
        char *ret = NULL;
-       unsigned char *endp;
        unsigned char dcs;
        int i;
        gboolean ci = FALSE;
+       unsigned char *unpacked_buf;
+       long num_char, written;
+       int spare_bits;
 
-       if (length < 1)
+       if (length < 2)
                return NULL;
 
        dcs = *buffer++;
@@ -787,11 +789,18 @@ static char *sim_network_name_parse(const unsigned char *buffer, int length,
 
        switch (dcs & (7 << 4)) {
        case 0x00:
-               endp = memchr(buffer, 0xff, length);
-               if (endp)
-                       length = endp - buffer;
-               ret = convert_gsm_to_utf8(buffer, length,
-                               NULL, NULL, 0xff);
+               spare_bits = dcs & 0x07;
+               num_char = (length * 8 - spare_bits) / 7;
+
+               unpacked_buf = unpack_7bit(buffer, length, 0, FALSE,
+                                               num_char, &written, 0);
+               if (unpacked_buf == NULL)
+                       break;
+
+               ret = convert_gsm_to_utf8(unpacked_buf, written, NULL, NULL, 0);
+
+               g_free(unpacked_buf);
+
                break;
        case 0x10:
                if ((length % 2) == 1) {