Open Source Telephony
 help / color / mirror / Atom feed
From: Yang Gu <yang.gu@intel.com>
To: ofono@ofono.org
Subject: [PATCH 4/7] Add parser for imei objects
Date: Fri, 26 Mar 2010 00:07:33 +0800	[thread overview]
Message-ID: <1269533256-29095-4-git-send-email-yang.gu@intel.com> (raw)
In-Reply-To: <1269533256-29095-3-git-send-email-yang.gu@intel.com>

[-- Attachment #1: Type: text/plain, Size: 2128 bytes --]

---
 src/stkutil.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/src/stkutil.c b/src/stkutil.c
index d67c5c4..af1200c 100644
--- a/src/stkutil.c
+++ b/src/stkutil.c
@@ -553,6 +553,47 @@ static gboolean parse_dataobj_location_info(
 	return TRUE;
 }
 
+/* Defined in TS 102.223 Section 8.20.
+ *
+ * According to 3GPP TS 24.008, Section 10.5.1.4, IMEI is composed of
+ * 15 digits and totally 8 bytes are used to represent it.
+ *
+ * Bits 1-3 of first byte represent the type of identity, and they
+ * are 0 1 0 separately for IMEI. Bit 4 of first byte is the odd/even
+ * indication, and it's 1 to indicate IMEI has odd number of digits (15).
+ * The rest bytes are coded using BCD coding.
+ *
+ * For example, if the IMEI is "123456789012345", then it's coded as
+ * "1A 32 54 76 98 10 32 54".
+ */
+static gboolean parse_dataobj_imei(struct comprehension_tlv_iter *iter,
+						void *user)
+{
+	char **imei = user;
+	const unsigned char *data;
+	unsigned int len;
+	static const char digit_lut[] = "0123456789*#abc\0";
+
+	if (comprehension_tlv_iter_get_tag(iter) !=
+			STK_DATA_OBJECT_TYPE_IMEI)
+		return FALSE;
+
+	len = comprehension_tlv_iter_get_length(iter);
+	if (len != 8)
+		return FALSE;
+
+	data = comprehension_tlv_iter_get_data(iter);
+
+	if ((data[0] & 0x0f) != 0x0a)
+		return FALSE;
+
+	*imei = g_try_malloc(16);
+	(*imei)[0] = digit_lut[(data[0] & 0xf0) >> 4];
+	extract_bcd_number(data + 1, 7, *imei + 1);
+
+	return TRUE;
+}
+
 /* Defined in TS 102.223 Section 8.31 */
 static gboolean parse_dataobj_icon_id(struct comprehension_tlv_iter *iter,
 					void *user)
@@ -674,6 +715,8 @@ static dataobj_handler handler_for_type(enum stk_data_object_type type)
 		return parse_dataobj_file_list;
 	case STK_DATA_OBJECT_TYPE_LOCATION_INFO:
 		return parse_dataobj_location_info;
+	case STK_DATA_OBJECT_TYPE_IMEI:
+		return parse_dataobj_imei;
 	case STK_DATA_OBJECT_TYPE_ICON_ID:
 		return parse_dataobj_icon_id;
 	case STK_DATA_OBJECT_TYPE_IMMEDIATE_RESPONSE:
-- 
1.6.3.3


  reply	other threads:[~2010-03-25 16:07 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-25 16:07 [PATCH 1/7] Unify some macro names of ber-tlv and comprehension tlv Yang Gu
2010-03-25 16:07 ` [PATCH 2/7] Make the function to parse mcc and mnc public Yang Gu
2010-03-25 16:07   ` [PATCH 3/7] Add parser for location information objects Yang Gu
2010-03-25 16:07     ` Yang Gu [this message]
2010-03-25 16:07       ` [PATCH 5/7] Add parser for common bool object Yang Gu
2010-03-25 16:07         ` [PATCH 6/7] Use common bool parser to reimplement immediate response object Yang Gu
2010-03-25 16:07           ` [PATCH 7/7] Add parser for help request objects Yang Gu
2010-03-25 16:43             ` Denis Kenzior
2010-03-25 16:43           ` [PATCH 6/7] Use common bool parser to reimplement immediate response object Denis Kenzior
2010-03-25 16:43         ` [PATCH 5/7] Add parser for common bool object Denis Kenzior
2010-03-25 16:42       ` [PATCH 4/7] Add parser for imei objects Denis Kenzior
2010-03-25 16:42     ` [PATCH 3/7] Add parser for location information objects Denis Kenzior
2010-03-25 16:41   ` [PATCH 2/7] Make the function to parse mcc and mnc public Denis Kenzior
2010-03-25 16:41 ` [PATCH 1/7] Unify some macro names of ber-tlv and comprehension tlv Denis Kenzior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1269533256-29095-4-git-send-email-yang.gu@intel.com \
    --to=yang.gu@intel.com \
    --cc=ofono@ofono.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox