Skip to contentSkip to conversation

Add parser for file list objects

PATCH Superseded Yang Gu 4 participants 5 messages Mar 19, 2010 – Mar 23, 2010

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yang Gu

author
#0 lore raw

PATCH 1/1 Add parser for file list objects

---
 src/stkutil.c |   85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/stkutil.h |    6 ++++
 2 files changed, 91 insertions(+), 0 deletions(-)
src/stkutil.c +85 -0
index 940eee2..18f1cdb 100644
@@ -416,6 +416,89 @@ static gboolean parse_dataobj_tone(struct comprehension_tlv_iter *iter,
 	return TRUE;
 }
 
+/* Defined in TS 102.223 Section 8.18 */
+static gboolean parse_dataobj_file_list(struct comprehension_tlv_iter *iter,
+						void *user)
+{
+	GSList **fl = user;
+	const unsigned char *data;
+	unsigned int len;
+	unsigned int i;
+	unsigned int start;
+	struct stk_file *sf;
+	unsigned char last_type = 0x2f;
+
+	if (comprehension_tlv_iter_get_tag(iter) !=
+			STK_DATA_OBJECT_TYPE_FILE_LIST)
+		return FALSE;
+
+	len = comprehension_tlv_iter_get_length(iter);
+	if (len < 5)
+		return FALSE;
+
+	data = comprehension_tlv_iter_get_data(iter);
+
+	for (i = 1; i < len; i += 2) {
+		/* Check the validity of file type.
+		 * According to TS 11.11, each file id contains of two bytes,
+		 * in which the first byte is the type of file. For GSM is:
+		 * 0x3f: master file
+		 * 0x7f: 1st level dedicated file
+		 * 0x5f: 2nd level dedicated file
+		 * 0x2f: elementary file under the master file
+		 * 0x6f: elementary file under 1st level dedicated file
+		 * 0x4f: elementary file under 2nd level dedicated file
+		 */
+		if (data[i] == 0x3f) {
+			if ((last_type != 0x2f) && (last_type != 0x6f) &&
+							(last_type != 0x4f))
+				goto error;
+			start = i;
+		} else if (data[i] == 0x2f) {
+			if (last_type != 0x3f)
+				goto error;
+		} else if (data[i] == 0x6f) {
+			if (last_type != 0x7f)
+				goto error;
+		} else if (data[i] == 0x4f) {
+			if (last_type != 0x5f)
+				goto error;
+		} else if (data[i] == 0x7f) {
+			if (last_type != 0x3f)
+				goto error;
+		} else if (data[i] == 0x5f) {
+			if (last_type != 0x7f)
+				goto error;
+		} else
+			goto error;
+
+		if ((data[i] == 0x2f) || (data[i] == 0x6f) ||
+						(data[i] == 0x4f)) {
+			sf = g_try_new0(struct stk_file, 1);
+			if (sf == NULL)
+				goto error;
+
+			sf->len = i - start;
+			memcpy(sf->file, data + start, i - start);
+			*fl = g_slist_prepend(*fl, sf);
+		}
+
+		last_type = data[i];
+	}
+
+	if ((data[len - 2] != 0x2f) && (data[len - 2] != 0x6f) &&
+						(data[len - 2] != 0x4f))
+		goto error;
+
+	*fl = g_slist_reverse(*fl);
+	return TRUE;
+
+error:
+	g_slist_foreach(*fl, (GFunc)g_free, NULL);
+	g_slist_free(*fl);
+	return FALSE;
+}
+
 /* Defined in TS 102.223 Section 8.31 */
 static gboolean parse_dataobj_icon_id(struct comprehension_tlv_iter *iter,
 					void *user)
@@ -533,6 +616,8 @@ static dataobj_handler handler_for_type(enum stk_data_object_type type)
 		return parse_dataobj_text;
 	case STK_DATA_OBJECT_TYPE_TONE:
 		return parse_dataobj_tone;
+	case STK_DATA_OBJECT_TYPE_FILE_LIST:
+		return parse_dataobj_file_list;
 	case STK_DATA_OBJECT_TYPE_ICON_ID:
 		return parse_dataobj_icon_id;
 	case STK_DATA_OBJECT_TYPE_IMMEDIATE_RESPONSE:
src/stkutil.h +6 -0
index 1d690b5..bafe03c 100644
@@ -345,6 +345,12 @@ struct stk_result {
 	unsigned char *additional;
 };
 
+/* Define the struct of single file in TS102.223 Section 8.18 */
+struct stk_file {
+	unsigned char file[8];
+	unsigned int len;
+};
+
 /*
  * According to 102.223 Section 8.72 the length of text attribute CTLV is 1
  * byte.  This means that the maximum size is 127 according to the rules
Signature · 1 line
1.6.3.3
#1 lore raw

Hi Yang,

Quoted 3 lines
---
 src/stkutil.c |   85

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

src/stkutil.h |

Quoted 66 lines
   6 ++++
 2 files changed, 91 insertions(+), 0 deletions(-)
src/stkutil.c +54 -0
index 940eee2..18f1cdb 100644
@@ -416,6 +416,89 @@ static gboolean parse_dataobj_tone(struct
 comprehension_tlv_iter *iter, return TRUE;
 }
 
+/* Defined in TS 102.223 Section 8.18 */
+static gboolean parse_dataobj_file_list(struct comprehension_tlv_iter
 *iter, +						void *user)
+{
+	GSList **fl = user;
+	const unsigned char *data;
+	unsigned int len;
+	unsigned int i;
+	unsigned int start;
+	struct stk_file *sf;
+	unsigned char last_type = 0x2f;
+
+	if (comprehension_tlv_iter_get_tag(iter) !=
+			STK_DATA_OBJECT_TYPE_FILE_LIST)
+		return FALSE;
+
+	len = comprehension_tlv_iter_get_length(iter);
+	if (len < 5)
+		return FALSE;
+
+	data = comprehension_tlv_iter_get_data(iter);
+
+	for (i = 1; i < len; i += 2) {
+		/* Check the validity of file type.
+		 * According to TS 11.11, each file id contains of two bytes,
+		 * in which the first byte is the type of file. For GSM is:
+		 * 0x3f: master file
+		 * 0x7f: 1st level dedicated file
+		 * 0x5f: 2nd level dedicated file
+		 * 0x2f: elementary file under the master file
+		 * 0x6f: elementary file under 1st level dedicated file
+		 * 0x4f: elementary file under 2nd level dedicated file
+		 */
+		if (data[i] == 0x3f) {
+			if ((last_type != 0x2f) && (last_type != 0x6f) &&
+							(last_type != 0x4f))
+				goto error;
+			start = i;
+		} else if (data[i] == 0x2f) {
+			if (last_type != 0x3f)
+				goto error;
+		} else if (data[i] == 0x6f) {
+			if (last_type != 0x7f)
+				goto error;
+		} else if (data[i] == 0x4f) {
+			if (last_type != 0x5f)
+				goto error;
+		} else if (data[i] == 0x7f) {
+			if (last_type != 0x3f)
+				goto error;
+		} else if (data[i] == 0x5f) {
+			if (last_type != 0x7f)
+				goto error;
+		} else
+			goto error;

src/stkutil.c static gboolean parse_dataobj_tone(struct · line 483

Quoted 10 lines
src/stkutil.c +10 -0
+
+		if ((data[i] == 0x2f) || (data[i] == 0x6f) ||
+						(data[i] == 0x4f)) {
+			sf = g_try_new0(struct stk_file, 1);
+			if (sf == NULL)
+				goto error;
+
+			sf->len = i - start;
+			memcpy(sf->file, data + start, i - start);
+			*fl = g_slist_prepend(*fl, sf);

This looks wrong, you're not including the EF file type byte / 2nd byte in the file contents.

Quoted 35 lines
src/stkutil.c +20 -0
+		}
+
+		last_type = data[i];
+	}
+
+	if ((data[len - 2] != 0x2f) && (data[len - 2] != 0x6f) &&
+						(data[len - 2] != 0x4f))
+		goto error;
+
+	*fl = g_slist_reverse(*fl);
+	return TRUE;
+
+error:
+	g_slist_foreach(*fl, (GFunc)g_free, NULL);
+	g_slist_free(*fl);
+	return FALSE;
+}
+
 /* Defined in TS 102.223 Section 8.31 */
 static gboolean parse_dataobj_icon_id(struct comprehension_tlv_iter *iter,
 					void *user)
@@ -533,6 +616,8 @@ static dataobj_handler handler_for_type(enum
 stk_data_object_type type) return parse_dataobj_text;
 	case STK_DATA_OBJECT_TYPE_TONE:
 		return parse_dataobj_tone;
+	case STK_DATA_OBJECT_TYPE_FILE_LIST:
+		return parse_dataobj_file_list;
 	case STK_DATA_OBJECT_TYPE_ICON_ID:
 		return parse_dataobj_icon_id;
 	case STK_DATA_OBJECT_TYPE_IMMEDIATE_RESPONSE:
src/stkutil.h +0 -0
index 1d690b5..bafe03c 100644

src/stkutil.h struct stk_result { · line 350

Quoted 6 lines
src/stkutil.h +3 -0
@@ -345,6 +345,12 @@ struct stk_result {
 	unsigned char *additional;
 };
 
+/* Define the struct of single file in TS102.223 Section 8.18 */
+struct stk_file {
+	unsigned char file[8];

Please put a comment here why it is 8, preferably quoting or referencing the right right section from the specification.

src/stkutil.h struct stk_result {

Quoted 7 lines
src/stkutil.h +3 -0
+	unsigned int len;
+};
+
 /*
  * According to 102.223 Section 8.72 the length of text attribute CTLV is
 1 * byte.  This means that the maximum size is 127 according to the rules

Regards,
-Denis

#2 lore raw

Hi,
Attached is the patch modified according to the comments. Please review!

Quoted 21 lines

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+		if ((data[i] == 0x2f) || (data[i] == 0x6f) ||
+						(data[i] == 0x4f)) {
+			sf = g_try_new0(struct stk_file, 1);
+			if (sf == NULL)
+				goto error;
+
+			sf->len = i - start;
+			memcpy(sf->file, data + start, i - start);
+			*fl = g_slist_prepend(*fl, sf);

This looks wrong, you're not including the EF file type byte / 2nd byte in the file contents.

Review

Quoted 4 lines
(quoted diff) +3 -0
+/* Define the struct of single file in TS102.223 Section 8.18 */
+struct stk_file {
+	unsigned char file[8];

Please put a comment here why it is 8, preferably quoting or referencing the right right section from the specification.

Quoted 10 lines

Review

Quoted 7 lines
(quoted diff) +3 -0
+	unsigned int len;
+};
+
 /*
  * According to 102.223 Section 8.72 the length of text attribute CTLV is
 1 * byte.  This means that the maximum size is 127 according to the rules

Regards,
-Denis

Regards,
-Yang

From 974a8d894d479a7c58cd6d79f3b073862ff41984 Mon Sep 17 00:00:00 2001
From: Yang Gu <[email protected]>
Date: Tue, 23 Mar 2010 11:12:39 +0800
Subject: [PATCH] Add parser for file list objects

---
 src/stkutil.c |   88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/stkutil.h |   11 +++++++
 2 files changed, 99 insertions(+), 0 deletions(-)
src/stkutil.c +88 -0
index 940eee2..833073b 100644
@@ -416,6 +416,92 @@ static gboolean parse_dataobj_tone(struct comprehension_tlv_iter *iter,
 	return TRUE;
 }
 
+/* Defined in TS 102.223 Section 8.18 */
+static gboolean parse_dataobj_file_list(struct comprehension_tlv_iter *iter,
+						void *user)
+{
+	GSList **fl = user;
+	const unsigned char *data;
+	unsigned int len;
+	unsigned int i;
+	unsigned int start = 0;
+	struct stk_file *sf;
+	unsigned char last_type = 0x2f;
+
+	if (comprehension_tlv_iter_get_tag(iter) !=
+			STK_DATA_OBJECT_TYPE_FILE_LIST)
+		return FALSE;
+
+	len = comprehension_tlv_iter_get_length(iter);
+	if (len < 5)
+		return FALSE;
+
+	data = comprehension_tlv_iter_get_data(iter);
+
+	for (i = 1; i < len; i += 2) {
+		/* Check the validity of file type.
+		 * According to TS 11.11, each file id contains of two bytes,
+		 * in which the first byte is the type of file. For GSM is:
+		 * 0x3f: master file
+		 * 0x7f: 1st level dedicated file
+		 * 0x5f: 2nd level dedicated file
+		 * 0x2f: elementary file under the master file
+		 * 0x6f: elementary file under 1st level dedicated file
+		 * 0x4f: elementary file under 2nd level dedicated file
+		 */
+		if (data[i] == 0x3f) {
+			if ((last_type != 0x2f) && (last_type != 0x6f) &&
+							(last_type != 0x4f))
+				goto error;
+			start = i;
+		} else if (data[i] == 0x2f) {
+			if (last_type != 0x3f)
+				goto error;
+		} else if (data[i] == 0x6f) {
+			if (last_type != 0x7f)
+				goto error;
+		} else if (data[i] == 0x4f) {
+			if (last_type != 0x5f)
+				goto error;
+		} else if (data[i] == 0x7f) {
+			if (last_type != 0x3f)
+				goto error;
+		} else if (data[i] == 0x5f) {
+			if (last_type != 0x7f)
+				goto error;
+		} else
+			goto error;
+
+		if ((data[i] == 0x2f) || (data[i] == 0x6f) ||
+						(data[i] == 0x4f)) {
+			if (i + 1 >= len)
+				goto error;
+
+			sf = g_try_new0(struct stk_file, 1);
+			if (sf == NULL)
+				goto error;
+
+			sf->len = i - start + 2;
+			memcpy(sf->file, data + start, i - start + 2);
+			*fl = g_slist_prepend(*fl, sf);
+		}
+
+		last_type = data[i];
+	}
+
+	if ((data[len - 2] != 0x2f) && (data[len - 2] != 0x6f) &&
+						(data[len - 2] != 0x4f))
+		goto error;
+
+	*fl = g_slist_reverse(*fl);
+	return TRUE;
+
+error:
+	g_slist_foreach(*fl, (GFunc)g_free, NULL);
+	g_slist_free(*fl);
+	return FALSE;
+}
+
 /* Defined in TS 102.223 Section 8.31 */
 static gboolean parse_dataobj_icon_id(struct comprehension_tlv_iter *iter,
 					void *user)
@@ -533,6 +619,8 @@ static dataobj_handler handler_for_type(enum stk_data_object_type type)
 		return parse_dataobj_text;
 	case STK_DATA_OBJECT_TYPE_TONE:
 		return parse_dataobj_tone;
+	case STK_DATA_OBJECT_TYPE_FILE_LIST:
+		return parse_dataobj_file_list;
 	case STK_DATA_OBJECT_TYPE_ICON_ID:
 		return parse_dataobj_icon_id;
 	case STK_DATA_OBJECT_TYPE_IMMEDIATE_RESPONSE:
src/stkutil.h +11 -0
index 1d690b5..93ac854 100644
@@ -345,6 +345,17 @@ struct stk_result {
 	unsigned char *additional;
 };
 
+/* Define the struct of single file in TS102.223 Section 8.18.
+ * According to TS 11.11 Section 6.2, each file id has two bytes, and the
+ * maximum Dedicated File level is 2. So the maximum size of file is 8, which
+ * contains two bytes of Master File, 2 bytes of 1st level Dedicated File,
+ * 2 bytes of 2nd level Dedicated File and 2 bytes of Elementary File.
+ */
+struct stk_file {
+	unsigned char file[8];
+	unsigned int len;
+};
+
 /*
  * According to 102.223 Section 8.72 the length of text attribute CTLV is 1
  * byte.  This means that the maximum size is 127 according to the rules
Signature · 1 line
1.6.3.3
#3 lore raw

Hi Yang,

Quoted 1 line

Attached is the patch modified according to the comments. Please review!

I theory I don't mind patches as attachments, but if you are asking for review I prefer them inline.

So using git send-email (using linux.intel.com works just fine) is a lot better here. Just mark the patch as [PATCH v2] or similar in the subject line and it is easy to track them.

Regards

Marcel

#4 lore raw

Hi,

Quoted 9 lines

-----Original Message-----
From: ofono-bounces(a)ofono.org [mailto:ofono-bounces(a)ofono.org] On Behalf Of Marcel Holtmann
Sent: Tuesday, March 23, 2010 11:49 AM
To: ofono(a)ofono.org
Subject: RE: [PATCH] Add parser for file list objects

Hi Yang,

Quoted 8 lines
Quoted 1 line

Attached is the patch modified according to the comments. Please review!

I theory I don't mind patches as attachments, but if you are asking for review I prefer them inline.

So using git send-email (using linux.intel.com works just fine) is a lot better here. Just mark the patch as [PATCH v2] or similar in the subject line and it is easy to track them.

Sure. I will resend the patch.

Quoted 9 lines

Regards

Marcel

_______________________________________________
ofono mailing list
ofono(a)ofono.org
http://lists.ofono.org/listinfo/ofono

Regards,
-Yang