summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2009-07-10 19:07:23 -0500
committerDenis Kenzior <denkenz@gmail.com>2009-07-14 15:45:05 -0500
commit80f43ff849d60e5f23b1794ff0f84b093755c1a2 (patch)
treecbc2ad4c52eb7c1543705bb813c38bb8d994c496 /src
parentf6aa6e473cbd5539de9d820d84fb30133cd14002 (diff)
downloadofono-80f43ff849d60e5f23b1794ff0f84b093755c1a2.tar.bz2
Move function to simutil.c
Diffstat (limited to 'src')
-rw-r--r--src/sim.c43
-rw-r--r--src/simutil.c54
-rw-r--r--src/simutil.h2
3 files changed, 56 insertions, 43 deletions
diff --git a/src/sim.c b/src/sim.c
index 09a03c0f..d8bce300 100644
--- a/src/sim.c
+++ b/src/sim.c
@@ -208,49 +208,6 @@ static GDBusMethodTable sim_manager_methods[] = {
static GDBusSignalTable sim_manager_signals[] = { { } };
-static char *network_name_parse(const unsigned char *buffer, int length)
-{
- unsigned char *endp;
- unsigned char dcs;
- int i;
-
- if (length < 1)
- return NULL;
-
- dcs = *buffer ++;
- length --;
-
- /* 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:
- endp = memchr(buffer, 0xff, length);
- if (endp)
- length = endp - buffer;
- return convert_gsm_to_utf8(buffer, length,
- NULL, NULL, 0xff);
- case 0x10:
- 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;
-}
-
static void sim_spn_read_cb(const struct ofono_error *error,
const unsigned char *sdata, int length, void *data)
{
diff --git a/src/simutil.c b/src/simutil.c
index e4fbd9b7..003dd5d8 100644
--- a/src/simutil.c
+++ b/src/simutil.c
@@ -23,9 +23,12 @@
#include <config.h>
#endif
+#include <string.h>
+
#include <glib.h>
#include "simutil.h"
+#include "util.h"
/* Parse ASN.1 Basic Encoding Rules TLVs per ISO/IEC 7816 */
const guint8 *ber_tlv_find_by_tag(const guint8 *pdu, guint8 in_tag,
@@ -64,3 +67,54 @@ const guint8 *ber_tlv_find_by_tag(const guint8 *pdu, guint8 in_tag,
return NULL;
}
+
+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;
+
+ if (length < 1)
+ return NULL;
+
+ dcs = *buffer ++;
+ length --;
+
+ /* "The MS should add the letters for the Country's Initials and a
+ * separator (e.g. a space)" */
+ if (is_bit_set(dcs, 4))
+ ci = TRUE;
+
+ 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);
+ break;
+ case 0x10:
+ 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;
+
+ ret = g_convert(buffer, length, "UTF-8//TRANSLIT", "UCS-2BE",
+ NULL, NULL, NULL);
+ break;
+ }
+
+ if (add_ci)
+ *add_ci = ci;
+
+ return ret;
+}
diff --git a/src/simutil.h b/src/simutil.h
index d41db144..673bafc7 100644
--- a/src/simutil.h
+++ b/src/simutil.h
@@ -32,3 +32,5 @@ enum sim_fileid {
const guint8 *ber_tlv_find_by_tag(const guint8 *pdu, guint8 in_tag,
int in_len, int *out_len);
+char *sim_network_name_parse(const unsigned char *buffer, int length,
+ gboolean *add_ci);