Open Source Telephony
 help / color / mirror / Atom feed
From: Yang Gu <yang.gu@intel.com>
To: ofono@ofono.org
Subject: [PATCH 03/27] stkutil: Add setup menu proactive command parser
Date: Thu, 13 May 2010 18:48:20 +0800	[thread overview]
Message-ID: <1273747724-28019-3-git-send-email-yang.gu@intel.com> (raw)
In-Reply-To: <1273747724-28019-1-git-send-email-yang.gu@intel.com>

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

---
 src/simutil.c |   12 +++++
 src/simutil.h |    3 +
 src/stkutil.c |  138 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 src/stkutil.h |   11 +++++
 4 files changed, 160 insertions(+), 4 deletions(-)

diff --git a/src/simutil.c b/src/simutil.c
index 941c551..b98c011 100644
--- a/src/simutil.c
+++ b/src/simutil.c
@@ -307,6 +307,18 @@ const unsigned char *comprehension_tlv_iter_get_data(
 	return iter->data;
 }
 
+void comprehension_tlv_iter_copy(struct comprehension_tlv_iter *from,
+					struct comprehension_tlv_iter *to)
+{
+	to->max = from->max;
+	to->pos = from->pos;
+	to->pdu = from->pdu;
+	to->tag = from->tag;
+	to->cr = from->cr;
+	to->len = from->len;
+	to->data = from->data;
+}
+
 void ber_tlv_iter_init(struct ber_tlv_iter *iter, const unsigned char *pdu,
 			unsigned int len)
 {
diff --git a/src/simutil.h b/src/simutil.h
index 7590cca..45b6847 100644
--- a/src/simutil.h
+++ b/src/simutil.h
@@ -132,6 +132,9 @@ unsigned int comprehension_tlv_iter_get_length(
 const unsigned char *comprehension_tlv_iter_get_data(
 					struct comprehension_tlv_iter *iter);
 
+void comprehension_tlv_iter_copy(struct comprehension_tlv_iter *from,
+					struct comprehension_tlv_iter *to);
+
 void ber_tlv_iter_init(struct ber_tlv_iter *iter, const unsigned char *pdu,
 			unsigned int len);
 /*
diff --git a/src/stkutil.c b/src/stkutil.c
index 46f4796..1698321 100644
--- a/src/stkutil.c
+++ b/src/stkutil.c
@@ -281,8 +281,8 @@ static gboolean parse_dataobj_alpha_id(struct comprehension_tlv_iter *iter,
 	char *utf8;
 
 	len = comprehension_tlv_iter_get_length(iter);
-	if (len < 1)
-		return FALSE;
+	if (len == 0)
+		return TRUE;
 
 	data = comprehension_tlv_iter_get_data(iter);
 	utf8 = sim_string_to_utf8(data, len);
@@ -373,7 +373,11 @@ static gboolean parse_dataobj_item(struct comprehension_tlv_iter *iter,
 	char *utf8;
 
 	len = comprehension_tlv_iter_get_length(iter);
-	if (len < 2)
+
+	if (len == 0)
+		return TRUE;
+
+	if (len == 1)
 		return FALSE;
 
 	data = comprehension_tlv_iter_get_data(iter);
@@ -2022,7 +2026,6 @@ static gboolean parse_dataobj(struct comprehension_tlv_iter *iter,
 		entries = g_slist_prepend(entries, entry);
 	}
 
-
 	if (comprehension_tlv_iter_next(iter) != TRUE)
 		goto out;
 
@@ -2039,6 +2042,10 @@ static gboolean parse_dataobj(struct comprehension_tlv_iter *iter,
 		if (comprehension_tlv_iter_get_tag(iter) == entry->type) {
 			if (handler(iter, entry->data))
 				entry->parsed = TRUE;
+
+			if (l->next == NULL)
+				break;
+
 			if (comprehension_tlv_iter_next(iter) == FALSE)
 				break;
 		}
@@ -2255,6 +2262,126 @@ static gboolean parse_poll_interval(struct stk_command *command,
 	return TRUE;
 }
 
+static void destroy_stk_item(struct stk_item *item)
+{
+	g_free(item->text);
+	g_free(item);
+}
+
+static void destroy_setup_menu(struct stk_command *command)
+{
+	g_free(command->setup_menu.alpha_id);
+	g_slist_foreach(command->setup_menu.items,
+				(GFunc)destroy_stk_item, NULL);
+	g_slist_free(command->setup_menu.items);
+}
+
+static gboolean parse_list(struct comprehension_tlv_iter *iter,
+		enum stk_data_object_type type,	int flags, GSList **list)
+{
+	struct comprehension_tlv_iter iter_old;
+	void *dataobj;
+	gboolean has_obj = FALSE;
+	dataobj_handler handler = handler_for_type(type);
+	gboolean ret;
+
+	if ((type != STK_DATA_OBJECT_TYPE_ITEM) && (type !=
+			STK_DATA_OBJECT_TYPE_PROVISIONING_FILE_REFERENCE))
+		return FALSE;
+
+	comprehension_tlv_iter_copy(iter, &iter_old);
+
+	while (comprehension_tlv_iter_next(iter)) {
+		if (comprehension_tlv_iter_get_tag(iter) != type)
+			break;
+
+		comprehension_tlv_iter_copy(iter, &iter_old);
+
+		if (type == STK_DATA_OBJECT_TYPE_ITEM)
+			dataobj = g_try_new0(struct stk_item, 1);
+		else
+			dataobj = g_try_new0(struct stk_file, 1);
+
+		if (!dataobj)
+			goto out;
+
+		ret = handler(iter, dataobj);
+		has_obj |= ret;
+
+		if (type == STK_DATA_OBJECT_TYPE_ITEM) {
+			struct stk_item *item = dataobj;
+
+			/* either return is FALSE or item is empty */
+			if (item->id == 0)
+				g_free(dataobj);
+			else
+				*list = g_slist_prepend(*list, dataobj);
+		} else
+			*list = g_slist_prepend(*list, dataobj);
+	}
+
+	comprehension_tlv_iter_copy(&iter_old, iter);
+out:
+	if ((flags & DATAOBJ_FLAG_MANDATORY) && !has_obj)
+		return FALSE;
+
+	*list = g_slist_reverse(*list);
+
+	return TRUE;
+}
+
+static gboolean parse_setup_menu(struct stk_command *command,
+					struct comprehension_tlv_iter *iter)
+{
+	struct stk_command_setup_menu *obj = &command->setup_menu;
+	gboolean ret;
+
+	if (command->src != STK_DEVICE_IDENTITY_TYPE_UICC)
+		goto error;
+
+	if (command->dst != STK_DEVICE_IDENTITY_TYPE_TERMINAL)
+		goto error;
+
+	ret = parse_dataobj(iter,
+			STK_DATA_OBJECT_TYPE_ALPHA_ID,
+			DATAOBJ_FLAG_MANDATORY | DATAOBJ_FLAG_MINIMUM,
+			&obj->alpha_id,
+			STK_DATA_OBJECT_TYPE_INVALID);
+
+	if (ret == FALSE)
+		goto error;
+
+	ret = parse_list(iter, STK_DATA_OBJECT_TYPE_ITEM,
+				DATAOBJ_FLAG_MANDATORY, &obj->items);
+
+	if (ret == FALSE)
+		goto error;
+
+	ret = parse_dataobj(iter,
+			STK_DATA_OBJECT_TYPE_ITEMS_NEXT_ACTION_INDICATOR, 0,
+			&obj->next_act,
+			STK_DATA_OBJECT_TYPE_ICON_ID, 0,
+			&obj->icon_id,
+			STK_DATA_OBJECT_TYPE_ITEM_ICON_ID_LIST, 0,
+			&obj->item_icon_id_list,
+			STK_DATA_OBJECT_TYPE_TEXT_ATTRIBUTE, 0,
+			&obj->text_attr,
+			STK_DATA_OBJECT_TYPE_ITEM_TEXT_ATTRIBUTE_LIST, 0,
+			&obj->item_text_attr_list,
+			STK_DATA_OBJECT_TYPE_INVALID);
+
+	if (ret == FALSE)
+		goto error;
+
+	command->destructor = destroy_setup_menu;
+
+	return TRUE;
+
+error:
+	destroy_setup_menu(command);
+	return FALSE;
+}
+
 static void destroy_send_sms(struct stk_command *command)
 {
 	g_free(command->send_sms.alpha_id);
@@ -2386,6 +2513,9 @@ struct stk_command *stk_command_new_from_pdu(const unsigned char *pdu,
 	case STK_COMMAND_TYPE_POLL_INTERVAL:
 		ok = parse_poll_interval(command, &iter);
 		break;
+	case STK_COMMAND_TYPE_SETUP_MENU:
+		ok = parse_setup_menu(command, &iter);
+		break;
 	case STK_COMMAND_TYPE_SEND_SMS:
 		ok = parse_send_sms(command, &iter);
 		break;
diff --git a/src/stkutil.h b/src/stkutil.h
index 02451b4..e22292b 100644
--- a/src/stkutil.h
+++ b/src/stkutil.h
@@ -828,6 +828,16 @@ struct stk_command_poll_interval {
 	struct stk_duration duration;
 };
 
+struct stk_command_setup_menu {
+	char *alpha_id;
+	GSList *items;
+	struct stk_items_next_action_indicator next_act;
+	struct stk_icon_id icon_id;
+	struct stk_item_icon_id_list item_icon_id_list;
+	struct stk_text_attribute text_attr;
+	struct stk_item_text_attribute_list item_text_attr_list;
+};
+
 struct stk_command_send_sms {
 	char *alpha_id;
 	struct stk_address address;
@@ -852,6 +862,7 @@ struct stk_command {
 		struct stk_command_play_tone play_tone;
 		struct stk_command_send_sms send_sms;
 		struct stk_command_poll_interval poll_interval;
+		struct stk_command_setup_menu setup_menu;
 	};
 
 	void (*destructor)(struct stk_command *command);
-- 
1.7.0.4


  parent reply	other threads:[~2010-05-13 10:48 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-13 10:48 [PATCH 01/27] stk: Add poll interval proactive command parser Yang Gu
2010-05-13 10:48 ` [PATCH 02/27] test-stkutil: Add test for poll interval parser Yang Gu
2010-05-13 10:48 ` Yang Gu [this message]
2010-05-13 10:48 ` [PATCH 04/27] test-stkutil: Add test for setup menu parser Yang Gu
2010-05-13 10:48 ` [PATCH 05/27] stkutil: Add select item proactive command parser Yang Gu
2010-05-13 10:48 ` [PATCH 06/27] test-stkutil: Add test for select item parser Yang Gu
2010-05-13 10:48 ` [PATCH 07/27] test-stkutil: Use dedicated functions to check Yang Gu
2010-05-13 10:48 ` [PATCH 08/27] test-stkutil: Refactor test for send sms parser Yang Gu
2010-05-13 10:48 ` [PATCH 09/27] stk: Adjust the sequence of dataobj Yang Gu
2010-05-13 10:48 ` [PATCH 10/27] stkutil: Add setup call proactive command parser Yang Gu
2010-05-13 10:48 ` [PATCH 11/27] test-stkutil: Add unit test for setup call parser Yang Gu
2010-05-13 10:48 ` [PATCH 12/27] stkutil: Add refresh proactive command parser Yang Gu
2010-05-13 10:48 ` [PATCH 13/27] test-stkutil: Add test for refresh parser Yang Gu
2010-05-13 10:48 ` [PATCH 14/27] stkutil: Add polling off proactive command parser Yang Gu
2010-05-13 10:48 ` [PATCH 15/27] test-stkutil: Add test for polling off parser Yang Gu
2010-05-13 10:48 ` [PATCH 16/27] stkutil: Add provide local info command parser Yang Gu
2010-05-13 10:48 ` [PATCH 17/27] test-stk: Add test for provide local info parser Yang Gu
2010-05-13 10:48 ` [PATCH 18/27] stkutil: Add event list command parser Yang Gu
2010-05-13 10:48 ` [PATCH 19/27] test-stkutil: Add test for event list parser Yang Gu
2010-05-13 10:48 ` [PATCH 20/27] stkutil: Add perform card apdu command parser Yang Gu
2010-05-13 10:48 ` [PATCH 21/27] test-stk: Add test for perform card apdu parser Yang Gu
2010-05-13 10:48 ` [PATCH 22/27] stkutil: Add power off card command parser Yang Gu
2010-05-13 10:48 ` [PATCH 23/27] stkutil: Add power on " Yang Gu
2010-05-13 10:48 ` [PATCH 24/27] stkutil: Add get reader status " Yang Gu
2010-05-13 10:48 ` [PATCH 25/27] test-stk: Add test for get reader status parser Yang Gu
2010-05-13 10:48 ` [PATCH 26/27] stkutil: Add timer management command parser Yang Gu
2010-05-13 10:48 ` [PATCH 27/27] test-stk: Add test for timer management parser Yang Gu
2010-05-13 20:37 ` [PATCH 01/27] stk: Add poll interval proactive command parser Denis Kenzior
2010-05-14  8:37   ` Gu, Yang

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=1273747724-28019-3-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