All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 01/11] stkutil: Add SMS-PP Data Download envelope builder
@ 2010-05-31 12:47 Andrzej Zaborowski
  2010-05-31 12:47 ` [PATCH 02/11] test-stkutil: Tests for " Andrzej Zaborowski
                   ` (10 more replies)
  0 siblings, 11 replies; 17+ messages in thread
From: Andrzej Zaborowski @ 2010-05-31 12:47 UTC (permalink / raw)
  To: ofono

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

Note that the sms_tpdu member could be of type struct sms_deliver, but the
users may more often have access to the raw tpdu so there's no point
decoding and reencoding it.
---
 src/stkutil.c |   93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/stkutil.h |   21 +++++++++++++
 2 files changed, 114 insertions(+), 0 deletions(-)

diff --git a/src/stkutil.c b/src/stkutil.c
index 7bbd1c9..a29abfe 100644
--- a/src/stkutil.c
+++ b/src/stkutil.c
@@ -3128,6 +3128,20 @@ static gboolean stk_tlv_builder_init(struct stk_tlv_builder *iter,
 	return comprehension_tlv_builder_init(&iter->ctlv, pdu, size);
 }
 
+static gboolean stk_tlv_builder_recurse(struct stk_tlv_builder *iter,
+					struct ber_tlv_builder *btlv,
+					unsigned char tag)
+{
+	iter->value = NULL;
+	iter->len = 0;
+
+	if (ber_tlv_builder_next(btlv, tag >> 6, (tag >> 5) & 1,
+					tag & 0x1f) != TRUE)
+		return FALSE;
+
+	return ber_tlv_builder_recurse_comprehension(btlv, &iter->ctlv);
+}
+
 static gboolean stk_tlv_builder_open_container(struct stk_tlv_builder *iter,
 						gboolean cr,
 						unsigned char shorttag,
@@ -3308,6 +3322,23 @@ static inline gboolean stk_tlv_builder_append_bytes(struct stk_tlv_builder *iter
 	return TRUE;
 }
 
+/* Described in TS 102.223 Section 8.1 */
+static gboolean build_dataobj_address(struct stk_tlv_builder *tlv,
+					const void *data, gboolean cr)
+{
+	const struct stk_address *addr = data;
+	unsigned char tag = STK_DATA_OBJECT_TYPE_ADDRESS;
+	unsigned int len = (strlen(addr->number) + 1) / 2;
+	unsigned char number[len];
+
+	sim_encode_bcd_number(addr->number, number);
+
+	return stk_tlv_builder_open_container(tlv, cr, tag, FALSE) &&
+		stk_tlv_builder_append_byte(tlv, addr->ton_npi) &&
+		stk_tlv_builder_append_bytes(tlv, number, len) &&
+		stk_tlv_builder_close_container(tlv);
+}
+
 /* Described in TS 102.223 Section 8.6 */
 static gboolean build_dataobj_item_id(struct stk_tlv_builder *tlv,
 					const void *data, gboolean cr)
@@ -3360,6 +3391,18 @@ static gboolean build_dataobj_result(struct stk_tlv_builder *tlv,
 	return stk_tlv_builder_close_container(tlv);
 }
 
+/* Described in TS 131.111 Section 8.13 */
+static gboolean build_dataobj_gsm_sms_tpdu(struct stk_tlv_builder *tlv,
+						const void *data, gboolean cr)
+{
+	const struct stk_common_byte_array *tpdu = data;
+	unsigned char tag = STK_DATA_OBJECT_TYPE_GSM_SMS_TPDU;
+
+	return stk_tlv_builder_open_container(tlv, cr, tag, TRUE) &&
+		stk_tlv_builder_append_bytes(tlv, tpdu->array, tpdu->len) &&
+		stk_tlv_builder_close_container(tlv);
+}
+
 /* Defined in TS 102.223 Section 8.15 */
 static gboolean build_dataobj_text(struct stk_tlv_builder *tlv,
 					const void *data, gboolean cr)
@@ -4099,3 +4142,53 @@ unsigned int stk_pdu_from_response(const struct stk_response *response,
 
 	return stk_tlv_builder_get_length(&builder);
 }
+
+ofono_bool_t stk_pdu_from_envelope(const struct stk_envelope *envelope,
+					unsigned char *pdu, unsigned int size,
+					unsigned char **out_pdu,
+					unsigned int *out_size)
+{
+	struct ber_tlv_builder btlv;
+	struct stk_tlv_builder builder;
+	gboolean ok = TRUE;
+	unsigned char tag;
+
+	if (ber_tlv_builder_init(&btlv, pdu, size) != TRUE)
+		return FALSE;
+
+	if (stk_tlv_builder_recurse(&builder, &btlv, envelope->type) != TRUE)
+		return FALSE;
+
+	tag = STK_DATA_OBJECT_TYPE_DEVICE_IDENTITIES;
+	if (stk_tlv_builder_open_container(&builder, TRUE, tag, FALSE) == FALSE)
+		return FALSE;
+
+	if (stk_tlv_builder_append_byte(&builder, envelope->src) == FALSE)
+		return FALSE;
+
+	if (stk_tlv_builder_append_byte(&builder, envelope->dst) == FALSE)
+		return FALSE;
+
+	if (stk_tlv_builder_close_container(&builder) == FALSE)
+		return FALSE;
+
+	switch (envelope->type) {
+	case STK_ENVELOPE_TYPE_SMS_PP_DOWNLOAD:
+		ok = build_dataobj(&builder,
+					build_dataobj_address, 0,
+					&envelope->sms_pp_download.address,
+					build_dataobj_gsm_sms_tpdu,
+					DATAOBJ_FLAG_CR,
+					&envelope->sms_pp_download.sms_tpdu,
+					NULL);
+		break;
+	default:
+		return FALSE;
+	};
+
+	if (ok != TRUE)
+		return ok;
+
+	ber_tlv_builder_optimize(&btlv, out_pdu, out_size);
+	return TRUE;
+}
diff --git a/src/stkutil.h b/src/stkutil.h
index cc5801c..8f4ae36 100644
--- a/src/stkutil.h
+++ b/src/stkutil.h
@@ -1172,6 +1172,21 @@ struct stk_response {
 	void (*destructor)(struct stk_response *response);
 };
 
+/* ENVELOPEs defined in TS 102.223 Section 7 */
+struct stk_envelope_sms_pp_download {
+	struct stk_address address;
+	struct stk_common_byte_array sms_tpdu;
+};
+
+struct stk_envelope {
+	enum stk_envelope_type type;
+	enum stk_device_identity_type src;
+	enum stk_device_identity_type dst;
+	union {
+		struct stk_envelope_sms_pp_download sms_pp_download;
+	};
+};
+
 struct stk_command *stk_command_new_from_pdu(const unsigned char *pdu,
 						unsigned int len);
 void stk_command_free(struct stk_command *command);
@@ -1179,3 +1194,9 @@ void stk_command_free(struct stk_command *command);
 /* Returns # of bytes written or zero on error */
 unsigned int stk_pdu_from_response(const struct stk_response *response,
 					unsigned char *pdu, unsigned int size);
+
+/* Returns TRUE on success */
+ofono_bool_t stk_pdu_from_envelope(const struct stk_envelope *envelope,
+					unsigned char *pdu, unsigned int size,
+					unsigned char **out_pdu,
+					unsigned int *out_size);
-- 
1.7.1.86.g0e460.dirty


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 02/11] test-stkutil: Tests for SMS-PP Data Download envelope builder
  2010-05-31 12:47 [PATCH 01/11] stkutil: Add SMS-PP Data Download envelope builder Andrzej Zaborowski
@ 2010-05-31 12:47 ` Andrzej Zaborowski
  2010-05-31 12:47 ` [PATCH 03/11] stkutil: Add CBS-PP " Andrzej Zaborowski
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Andrzej Zaborowski @ 2010-05-31 12:47 UTC (permalink / raw)
  To: ofono

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

---
 unit/test-stkutil.c |  158 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 158 insertions(+), 0 deletions(-)

diff --git a/unit/test-stkutil.c b/unit/test-stkutil.c
index 06d40a3..681043a 100644
--- a/unit/test-stkutil.c
+++ b/unit/test-stkutil.c
@@ -17838,6 +17838,154 @@ static const struct terminal_response_test launch_browser_response_data_411b = {
 	},
 };
 
+struct envelope_test {
+	const unsigned char *pdu;
+	unsigned int pdu_len;
+	struct stk_envelope envelope;
+};
+
+static void test_envelope_encoding(gconstpointer data)
+{
+	const struct envelope_test *test = data;
+	unsigned char buf[512], *pdu;
+	unsigned int len;
+
+	g_assert(stk_pdu_from_envelope(&test->envelope,
+					buf, sizeof(buf), &pdu, &len) == TRUE);
+
+	g_assert(len == test->pdu_len);
+	g_assert(memcmp(pdu, test->pdu, len) == 0);
+}
+
+static const unsigned char sms_pp_data_download_161[] = {
+	0xd1, 0x2d, 0x82, 0x02, 0x83, 0x81, 0x06, 0x09,
+	0x91, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
+	0xf8, 0x8b, 0x1c, 0x04, 0x04, 0x91, 0x21, 0x43,
+	0x7f, 0x16, 0x89, 0x10, 0x10, 0x00, 0x00, 0x00,
+	0x00, 0x0d, 0x53, 0x68, 0x6f, 0x72, 0x74, 0x20,
+	0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
+};
+
+static const struct envelope_test sms_pp_data_download_data_161 = {
+	.pdu = sms_pp_data_download_161,
+	.pdu_len = sizeof(sms_pp_data_download_161),
+	.envelope = {
+		.type = STK_ENVELOPE_TYPE_SMS_PP_DOWNLOAD,
+		.src = STK_DEVICE_IDENTITY_TYPE_NETWORK,
+		.dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+		{ .sms_pp_download = {
+			.address = {
+				.ton_npi = 0x91, /* Intl, ISDN */
+				.number = "112233445566778",
+			},
+			.sms_tpdu = {
+				.array = (unsigned char[28]) {
+					0x04, 0x04, 0x91, 0x21, 0x43, 0x7f,
+					0x16, 0x89, 0x10, 0x10, 0x00, 0x00,
+					0x00, 0x00, 0x0d, 0x53, 0x68, 0x6f,
+					0x72, 0x74, 0x20, 0x4d, 0x65, 0x73,
+					0x73, 0x61, 0x67, 0x65,
+				},
+				.len = 28,
+			},
+			/* Corresponds to (struct sms_deliver) {
+			 *	.oaddr = {
+			 *		.number_type =
+			 *			SMS_NUMBER_TYPE_INTERNATIONAL,
+			 *		.numbering_plan =
+			 *			SMS_NUMBERING_PLAN_ISDN,
+			 *		.address = "1234",
+			 *	},
+			 *	.pid = SMS_PID_TYPE_USIM_DOWNLOAD,
+			 *	.dcs = 0x16, // General, uncompr, Class 2, 8-bit
+			 *	.scts = {
+			 *		.year = 98,
+			 *		.month = 0,
+			 *		.day = 0,
+			 *	},
+			 *	.udl = 13,
+			 *	.ud = "Short Message",
+			 * }
+			 */
+		}},
+	},
+};
+
+static const unsigned char sms_pp_data_download_162[] = {
+	0xd1, 0x2d, 0x82, 0x02, 0x83, 0x81, 0x06, 0x09,
+	0x91, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
+	0xf8, 0x8b, 0x1c, 0x04, 0x04, 0x91, 0x21, 0x43,
+	0x7f, 0xf6, 0x89, 0x10, 0x10, 0x00, 0x00, 0x00,
+	0x00, 0x0d, 0x53, 0x68, 0x6f, 0x72, 0x74, 0x20,
+	0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
+};
+
+static const struct envelope_test sms_pp_data_download_data_162 = {
+	.pdu = sms_pp_data_download_162,
+	.pdu_len = sizeof(sms_pp_data_download_162),
+	.envelope = {
+		.type = STK_ENVELOPE_TYPE_SMS_PP_DOWNLOAD,
+		.src = STK_DEVICE_IDENTITY_TYPE_NETWORK,
+		.dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+		{ .sms_pp_download = {
+			.address = {
+				.ton_npi = 0x91, /* Intl, ISDN */
+				.number = "112233445566778",
+			},
+			.sms_tpdu = {
+				.array = (unsigned char[28]) {
+					0x04, 0x04, 0x91, 0x21, 0x43, 0x7f,
+					0xf6, 0x89, 0x10, 0x10, 0x00, 0x00,
+					0x00, 0x00, 0x0d, 0x53, 0x68, 0x6f,
+					0x72, 0x74, 0x20, 0x4d, 0x65, 0x73,
+					0x73, 0x61, 0x67, 0x65,
+				},
+				.len = 28,
+			},
+		}},
+	},
+};
+
+static const unsigned char sms_pp_data_download_182[] = {
+	0xd1, 0x3e, 0x82, 0x02, 0x83, 0x81, 0x06, 0x09,
+	0x91, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
+	0xf8, 0x8b, 0x2d, 0x44, 0x04, 0x91, 0x21, 0x43,
+	0x7f, 0xf6, 0x89, 0x10, 0x10, 0x00, 0x00, 0x00,
+	0x00, 0x1e, 0x02, 0x70, 0x00, 0x00, 0x19, 0x00,
+	0x0d, 0x00, 0x00, 0x00, 0x00, 0xbf, 0xff, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0xdc, 0xdc,
+	0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc,
+};
+
+static const struct envelope_test sms_pp_data_download_data_182 = {
+	.pdu = sms_pp_data_download_182,
+	.pdu_len = sizeof(sms_pp_data_download_182),
+	.envelope = {
+		.type = STK_ENVELOPE_TYPE_SMS_PP_DOWNLOAD,
+		.src = STK_DEVICE_IDENTITY_TYPE_NETWORK,
+		.dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+		{ .sms_pp_download = {
+			.address = {
+				.ton_npi = 0x91, /* Intl, ISDN */
+				.number = "112233445566778",
+			},
+			.sms_tpdu = {
+				.array = (unsigned char[45]) {
+					0x44, 0x04, 0x91, 0x21, 0x43, 0x7f,
+					0xf6, 0x89, 0x10, 0x10, 0x00, 0x00,
+					0x00, 0x00, 0x1e, 0x02, 0x70, 0x00,
+					0x00, 0x19, 0x00, 0x0d, 0x00, 0x00,
+					0x00, 0x00, 0xbf, 0xff, 0x00, 0x00,
+					0x00, 0x00, 0x00, 0x01, 0x00, 0xdc,
+					0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc,
+					0xdc, 0xdc, 0xdc,
+				},
+				.len = 45,
+			},
+		}},
+	},
+};
+
 int main(int argc, char **argv)
 {
 	g_test_init(&argc, &argv, NULL);
@@ -19499,5 +19647,15 @@ int main(int argc, char **argv)
 			&launch_browser_response_data_411b,
 			test_terminal_response_encoding);
 
+	g_test_add_data_func("/teststk/SMS-PP data download 1.6.1",
+			&sms_pp_data_download_data_161,
+			test_envelope_encoding);
+	g_test_add_data_func("/teststk/SMS-PP data download 1.6.2",
+			&sms_pp_data_download_data_162,
+			test_envelope_encoding);
+	g_test_add_data_func("/teststk/SMS-PP data download 1.8.2",
+			&sms_pp_data_download_data_182,
+			test_envelope_encoding);
+
 	return g_test_run();
 }
-- 
1.7.1.86.g0e460.dirty


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 03/11] stkutil: Add CBS-PP Data Download envelope builder
  2010-05-31 12:47 [PATCH 01/11] stkutil: Add SMS-PP Data Download envelope builder Andrzej Zaborowski
  2010-05-31 12:47 ` [PATCH 02/11] test-stkutil: Tests for " Andrzej Zaborowski
@ 2010-05-31 12:47 ` Andrzej Zaborowski
  2010-05-31 12:47 ` [PATCH 04/11] stk: Use envelope encoding utility from stkutil.c Andrzej Zaborowski
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Andrzej Zaborowski @ 2010-05-31 12:47 UTC (permalink / raw)
  To: ofono

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

---
 src/stkutil.c |   18 ++++++++++++++++++
 src/stkutil.h |    5 +++++
 2 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/src/stkutil.c b/src/stkutil.c
index a29abfe..755fefd 100644
--- a/src/stkutil.c
+++ b/src/stkutil.c
@@ -3339,6 +3339,17 @@ static gboolean build_dataobj_address(struct stk_tlv_builder *tlv,
 		stk_tlv_builder_close_container(tlv);
 }
 
+/* Described in TS 131.111 Section 8.5 */
+static gboolean build_dataobj_cbs_page(struct stk_tlv_builder *tlv,
+					const void *data, gboolean cr)
+{
+	unsigned char tag = STK_DATA_OBJECT_TYPE_CBS_PAGE;
+
+	return stk_tlv_builder_open_container(tlv, cr, tag, TRUE) &&
+		stk_tlv_builder_append_bytes(tlv, data, 88) &&
+		stk_tlv_builder_close_container(tlv);
+}
+
 /* Described in TS 102.223 Section 8.6 */
 static gboolean build_dataobj_item_id(struct stk_tlv_builder *tlv,
 					const void *data, gboolean cr)
@@ -4182,6 +4193,13 @@ ofono_bool_t stk_pdu_from_envelope(const struct stk_envelope *envelope,
 					&envelope->sms_pp_download.sms_tpdu,
 					NULL);
 		break;
+	case STK_ENVELOPE_TYPE_CBS_PP_DOWNLOAD:
+		ok = build_dataobj(&builder,
+					build_dataobj_cbs_page,
+					DATAOBJ_FLAG_CR,
+					envelope->cbs_pp_download.page,
+					NULL);
+		break;
 	default:
 		return FALSE;
 	};
diff --git a/src/stkutil.h b/src/stkutil.h
index 8f4ae36..8eb6c54 100644
--- a/src/stkutil.h
+++ b/src/stkutil.h
@@ -1178,12 +1178,17 @@ struct stk_envelope_sms_pp_download {
 	struct stk_common_byte_array sms_tpdu;
 };
 
+struct stk_envelope_cbs_pp_download {
+	unsigned char page[88];
+};
+
 struct stk_envelope {
 	enum stk_envelope_type type;
 	enum stk_device_identity_type src;
 	enum stk_device_identity_type dst;
 	union {
 		struct stk_envelope_sms_pp_download sms_pp_download;
+		struct stk_envelope_cbs_pp_download cbs_pp_download;
 	};
 };
 
-- 
1.7.1.86.g0e460.dirty


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 04/11] stk: Use envelope encoding utility from stkutil.c
  2010-05-31 12:47 [PATCH 01/11] stkutil: Add SMS-PP Data Download envelope builder Andrzej Zaborowski
  2010-05-31 12:47 ` [PATCH 02/11] test-stkutil: Tests for " Andrzej Zaborowski
  2010-05-31 12:47 ` [PATCH 03/11] stkutil: Add CBS-PP " Andrzej Zaborowski
@ 2010-05-31 12:47 ` Andrzej Zaborowski
  2010-05-31 12:47 ` [PATCH 05/11] test-stkutil: Tests for CBS-PP Data Download envelope builder Andrzej Zaborowski
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Andrzej Zaborowski @ 2010-05-31 12:47 UTC (permalink / raw)
  To: ofono

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

---
 src/stk.c |   28 +++++++++++++++++-----------
 1 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/src/stk.c b/src/stk.c
index 8573d2c..143d9f3 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -49,6 +49,8 @@ static void stk_cbs_download_cb(const struct ofono_error *error,
 {
 	if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
 		ofono_error("CellBroadcast download to UICC failed");
+		/* "The ME may retry to deliver the same Cell Broadcast
+		 * page." */
 		return;
 	}
 
@@ -58,23 +60,27 @@ static void stk_cbs_download_cb(const struct ofono_error *error,
 void __ofono_cbs_sim_download(struct ofono_stk *stk,
 				const guint8 *pdu, int pdu_len)
 {
-	guint8 tlv[pdu_len + 8];
+	guint8 buf[512], *tlv;
+	struct stk_envelope e;
+	unsigned int tlv_len;
+
+	if (pdu_len != 88) {
+		ofono_error("Bad CellBroadcast page length");
+		return;
+	}
 
 	if (stk->driver->envelope == NULL)
 		return;
 
-	tlv[0] = STK_ENVELOPE_TYPE_CBS_PP_DOWNLOAD;
-	tlv[1] = 6 + pdu_len;
-	tlv[2] = 0x80 | STK_DATA_OBJECT_TYPE_DEVICE_IDENTITIES;
-	tlv[3] = 0x02; /* Device Identities length */
-	tlv[4] = STK_DEVICE_IDENTITY_TYPE_NETWORK;
-	tlv[5] = STK_DEVICE_IDENTITY_TYPE_UICC;
-	tlv[6] = 0x80 | STK_DATA_OBJECT_TYPE_CBS_PAGE;
-	tlv[7] = pdu_len;
+	e.type = STK_ENVELOPE_TYPE_CBS_PP_DOWNLOAD;
+	e.src = STK_DEVICE_IDENTITY_TYPE_NETWORK;
+	e.dst = STK_DEVICE_IDENTITY_TYPE_UICC;
+	memcpy(e.cbs_pp_download.page, pdu, pdu_len);
 
-	memcpy(tlv + 8, pdu, pdu_len);
+	if (stk_pdu_from_envelope(&e, buf, sizeof(buf), &tlv, &tlv_len) != TRUE)
+		return;
 
-	stk->driver->envelope(stk, pdu_len + 8, tlv, stk_cbs_download_cb, stk);
+	stk->driver->envelope(stk, tlv_len, tlv, stk_cbs_download_cb, stk);
 }
 
 void ofono_stk_proactive_command_notify(struct ofono_stk *stk,
-- 
1.7.1.86.g0e460.dirty


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 05/11] test-stkutil: Tests for CBS-PP Data Download envelope builder
  2010-05-31 12:47 [PATCH 01/11] stkutil: Add SMS-PP Data Download envelope builder Andrzej Zaborowski
                   ` (2 preceding siblings ...)
  2010-05-31 12:47 ` [PATCH 04/11] stk: Use envelope encoding utility from stkutil.c Andrzej Zaborowski
@ 2010-05-31 12:47 ` Andrzej Zaborowski
  2010-05-31 12:47 ` [PATCH 06/11] stkutil: Add the Menu Selection " Andrzej Zaborowski
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Andrzej Zaborowski @ 2010-05-31 12:47 UTC (permalink / raw)
  To: ofono

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

---
 unit/test-stkutil.c |   85 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 85 insertions(+), 0 deletions(-)

diff --git a/unit/test-stkutil.c b/unit/test-stkutil.c
index 681043a..5410334 100644
--- a/unit/test-stkutil.c
+++ b/unit/test-stkutil.c
@@ -17986,6 +17986,86 @@ static const struct envelope_test sms_pp_data_download_data_182 = {
 	},
 };
 
+static const unsigned char cbs_pp_data_download_11[] = {
+	0xd2, 0x5e, 0x82, 0x02, 0x83, 0x81, 0x8c, 0x58,
+	0xc0, 0x11, 0x10, 0x01, 0x01, 0x11, 0xc3, 0x32,
+	0x9b, 0x0d, 0x12, 0xca, 0xdf, 0x61, 0xf2, 0x38,
+	0x3c, 0xa7, 0x83, 0x40, 0x20, 0x10, 0x08, 0x04,
+	0x02, 0x81, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02,
+	0x81, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x81,
+	0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x81, 0x40,
+	0x20, 0x10, 0x08, 0x04, 0x02, 0x81, 0x40, 0x20,
+	0x10, 0x08, 0x04, 0x02, 0x81, 0x40, 0x20, 0x10,
+	0x08, 0x04, 0x02, 0x81, 0x40, 0x20, 0x10, 0x08,
+	0x04, 0x02, 0x81, 0x40, 0x20, 0x10, 0x08, 0x04,
+	0x02, 0x81, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02,
+};
+
+static const struct envelope_test cbs_pp_data_download_data_11 = {
+	.pdu = cbs_pp_data_download_11,
+	.pdu_len = sizeof(cbs_pp_data_download_11),
+	.envelope = {
+		.type = STK_ENVELOPE_TYPE_CBS_PP_DOWNLOAD,
+		.src = STK_DEVICE_IDENTITY_TYPE_NETWORK,
+		.dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+		{ .cbs_pp_download = {
+			.page = {
+				0xc0, 0x11, 0x10, 0x01, 0x01, 0x11, 0xc3, 0x32,
+				0x9b, 0x0d, 0x12, 0xca, 0xdf, 0x61, 0xf2, 0x38,
+				0x3c, 0xa7, 0x83, 0x40, 0x20, 0x10, 0x08, 0x04,
+				0x02, 0x81, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02,
+				0x81, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x81,
+				0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x81, 0x40,
+				0x20, 0x10, 0x08, 0x04, 0x02, 0x81, 0x40, 0x20,
+				0x10, 0x08, 0x04, 0x02, 0x81, 0x40, 0x20, 0x10,
+				0x08, 0x04, 0x02, 0x81, 0x40, 0x20, 0x10, 0x08,
+				0x04, 0x02, 0x81, 0x40, 0x20, 0x10, 0x08, 0x04,
+				0x02, 0x81, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02,
+			},
+		}},
+	},
+};
+
+static const unsigned char cbs_pp_data_download_17[] = {
+	0xd2, 0x5e, 0x82, 0x02, 0x83, 0x81, 0x8c, 0x58,
+	0xc0, 0x11, 0x10, 0x01, 0x96, 0x11, 0x02, 0x70,
+	0x00, 0x00, 0x4d, 0x00, 0x0d, 0x00, 0x00, 0x00,
+	0x00, 0xbf, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x01, 0x00, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc,
+	0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc,
+	0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc,
+	0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc,
+	0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc,
+	0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc,
+	0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc,
+	0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc,
+};
+
+static const struct envelope_test cbs_pp_data_download_data_17 = {
+	.pdu = cbs_pp_data_download_17,
+	.pdu_len = sizeof(cbs_pp_data_download_17),
+	.envelope = {
+		.type = STK_ENVELOPE_TYPE_CBS_PP_DOWNLOAD,
+		.src = STK_DEVICE_IDENTITY_TYPE_NETWORK,
+		.dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+		{ .cbs_pp_download = {
+			.page = {
+				0xc0, 0x11, 0x10, 0x01, 0x96, 0x11, 0x02, 0x70,
+				0x00, 0x00, 0x4d, 0x00, 0x0d, 0x00, 0x00, 0x00,
+				0x00, 0xbf, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
+				0x01, 0x00, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc,
+				0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc,
+				0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc,
+				0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc,
+				0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc,
+				0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc,
+				0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc,
+				0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc, 0xdc,
+			},
+		}},
+	},
+};
+
 int main(int argc, char **argv)
 {
 	g_test_init(&argc, &argv, NULL);
@@ -19657,5 +19737,10 @@ int main(int argc, char **argv)
 			&sms_pp_data_download_data_182,
 			test_envelope_encoding);
 
+	g_test_add_data_func("/teststk/CBS-PP data download 1.1",
+			&cbs_pp_data_download_data_11, test_envelope_encoding);
+	g_test_add_data_func("/teststk/CBS-PP data download 1.7",
+			&cbs_pp_data_download_data_17, test_envelope_encoding);
+
 	return g_test_run();
 }
-- 
1.7.1.86.g0e460.dirty


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 06/11] stkutil: Add the Menu Selection envelope builder
  2010-05-31 12:47 [PATCH 01/11] stkutil: Add SMS-PP Data Download envelope builder Andrzej Zaborowski
                   ` (3 preceding siblings ...)
  2010-05-31 12:47 ` [PATCH 05/11] test-stkutil: Tests for CBS-PP Data Download envelope builder Andrzej Zaborowski
@ 2010-05-31 12:47 ` Andrzej Zaborowski
  2010-05-31 12:47 ` [PATCH 07/11] test-stkutil: Tests for " Andrzej Zaborowski
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Andrzej Zaborowski @ 2010-05-31 12:47 UTC (permalink / raw)
  To: ofono

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

---
 src/stkutil.c |   22 ++++++++++++++++++++++
 src/stkutil.h |    6 ++++++
 2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/src/stkutil.c b/src/stkutil.c
index 755fefd..e5ea65a 100644
--- a/src/stkutil.c
+++ b/src/stkutil.c
@@ -3528,6 +3528,20 @@ static gboolean build_dataobj_imei(struct stk_tlv_builder *tlv,
 		stk_tlv_builder_close_container(tlv);
 }
 
+/* Described in TS 102.223 Section 8.21 */
+static gboolean build_dataobj_help_request(struct stk_tlv_builder *tlv,
+						const void *data, gboolean cr)
+{
+	const gboolean *help = data;
+	unsigned char tag = STK_DATA_OBJECT_TYPE_HELP_REQUEST;
+
+	if (*help != TRUE)
+		return TRUE;
+
+	return stk_tlv_builder_open_container(tlv, cr, tag, FALSE) &&
+		stk_tlv_builder_close_container(tlv);
+}
+
 /* Described in TS 102.223 Section 8.22 */
 static gboolean build_dataobj_network_measurement_results(
 						struct stk_tlv_builder *tlv,
@@ -4200,6 +4214,14 @@ ofono_bool_t stk_pdu_from_envelope(const struct stk_envelope *envelope,
 					envelope->cbs_pp_download.page,
 					NULL);
 		break;
+	case STK_ENVELOPE_TYPE_MENU_SELECTION:
+		ok = build_dataobj(&builder,
+					build_dataobj_item_id, DATAOBJ_FLAG_CR,
+					&envelope->menu_selection.item_id,
+					build_dataobj_help_request, 0,
+					&envelope->menu_selection.help_request,
+					NULL);
+		break;
 	default:
 		return FALSE;
 	};
diff --git a/src/stkutil.h b/src/stkutil.h
index 8eb6c54..0e00b7e 100644
--- a/src/stkutil.h
+++ b/src/stkutil.h
@@ -1182,6 +1182,11 @@ struct stk_envelope_cbs_pp_download {
 	unsigned char page[88];
 };
 
+struct stk_envelope_menu_selection {
+	unsigned char item_id;
+	gboolean help_request;
+};
+
 struct stk_envelope {
 	enum stk_envelope_type type;
 	enum stk_device_identity_type src;
@@ -1189,6 +1194,7 @@ struct stk_envelope {
 	union {
 		struct stk_envelope_sms_pp_download sms_pp_download;
 		struct stk_envelope_cbs_pp_download cbs_pp_download;
+		struct stk_envelope_menu_selection menu_selection;
 	};
 };
 
-- 
1.7.1.86.g0e460.dirty


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 07/11] test-stkutil: Tests for the Menu Selection envelope builder
  2010-05-31 12:47 [PATCH 01/11] stkutil: Add SMS-PP Data Download envelope builder Andrzej Zaborowski
                   ` (4 preceding siblings ...)
  2010-05-31 12:47 ` [PATCH 06/11] stkutil: Add the Menu Selection " Andrzej Zaborowski
@ 2010-05-31 12:47 ` Andrzej Zaborowski
  2010-05-31 12:47 ` [PATCH 08/11] Add a buffer size parameter to convert_utf8_to_gsm Andrzej Zaborowski
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Andrzej Zaborowski @ 2010-05-31 12:47 UTC (permalink / raw)
  To: ofono

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

---
 unit/test-stkutil.c |  162 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 162 insertions(+), 0 deletions(-)

diff --git a/unit/test-stkutil.c b/unit/test-stkutil.c
index 5410334..4a822ef 100644
--- a/unit/test-stkutil.c
+++ b/unit/test-stkutil.c
@@ -18066,6 +18066,151 @@ static const struct envelope_test cbs_pp_data_download_data_17 = {
 	},
 };
 
+static const unsigned char menu_selection_111[] = {
+	0xd3, 0x07, 0x82, 0x02, 0x01, 0x81, 0x90, 0x01,
+	0x02,
+};
+
+static const struct envelope_test menu_selection_data_111 = {
+	.pdu = menu_selection_111,
+	.pdu_len = sizeof(menu_selection_111),
+	.envelope = {
+		.type = STK_ENVELOPE_TYPE_MENU_SELECTION,
+		.src = STK_DEVICE_IDENTITY_TYPE_KEYPAD,
+		.dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+		{ .menu_selection = {
+			.item_id = 0x2,
+		}},
+	},
+};
+
+static const unsigned char menu_selection_112[] = {
+	0xd3, 0x07, 0x82, 0x02, 0x01, 0x81, 0x90, 0x01,
+	0x12,
+};
+
+static const struct envelope_test menu_selection_data_112 = {
+	.pdu = menu_selection_112,
+	.pdu_len = sizeof(menu_selection_112),
+	.envelope = {
+		.type = STK_ENVELOPE_TYPE_MENU_SELECTION,
+		.src = STK_DEVICE_IDENTITY_TYPE_KEYPAD,
+		.dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+		{ .menu_selection = {
+			.item_id = 0x12,
+		}},
+	},
+};
+
+static const unsigned char menu_selection_121[] = {
+	0xd3, 0x07, 0x82, 0x02, 0x01, 0x81, 0x90, 0x01,
+	0x3d,
+};
+
+static const struct envelope_test menu_selection_data_121 = {
+	.pdu = menu_selection_121,
+	.pdu_len = sizeof(menu_selection_121),
+	.envelope = {
+		.type = STK_ENVELOPE_TYPE_MENU_SELECTION,
+		.src = STK_DEVICE_IDENTITY_TYPE_KEYPAD,
+		.dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+		{ .menu_selection = {
+			.item_id = 0x3d,
+		}},
+	},
+};
+
+static const unsigned char menu_selection_122[] = {
+	0xd3, 0x07, 0x82, 0x02, 0x01, 0x81, 0x90, 0x01,
+	0xfb,
+};
+
+static const struct envelope_test menu_selection_data_122 = {
+	.pdu = menu_selection_122,
+	.pdu_len = sizeof(menu_selection_122),
+	.envelope = {
+		.type = STK_ENVELOPE_TYPE_MENU_SELECTION,
+		.src = STK_DEVICE_IDENTITY_TYPE_KEYPAD,
+		.dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+		{ .menu_selection = {
+			.item_id = 0xfb,
+		}},
+	},
+};
+
+static const unsigned char menu_selection_123[] = {
+	0xd3, 0x07, 0x82, 0x02, 0x01, 0x81, 0x90, 0x01,
+	0x01,
+};
+
+static const struct envelope_test menu_selection_data_123 = {
+	.pdu = menu_selection_123,
+	.pdu_len = sizeof(menu_selection_123),
+	.envelope = {
+		.type = STK_ENVELOPE_TYPE_MENU_SELECTION,
+		.src = STK_DEVICE_IDENTITY_TYPE_KEYPAD,
+		.dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+		{ .menu_selection = {
+			.item_id = 0x1,
+		}},
+	},
+};
+
+static const unsigned char menu_selection_211[] = {
+	0xd3, 0x09, 0x82, 0x02, 0x01, 0x81, 0x90, 0x01,
+	0x02, 0x15, 0x00,
+};
+
+static const struct envelope_test menu_selection_data_211 = {
+	.pdu = menu_selection_211,
+	.pdu_len = sizeof(menu_selection_211),
+	.envelope = {
+		.type = STK_ENVELOPE_TYPE_MENU_SELECTION,
+		.src = STK_DEVICE_IDENTITY_TYPE_KEYPAD,
+		.dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+		{ .menu_selection = {
+			.item_id = 0x2,
+			.help_request = TRUE,
+		}},
+	},
+};
+
+static const unsigned char menu_selection_612[] = {
+	0xd3, 0x07, 0x82, 0x02, 0x01, 0x81, 0x90, 0x01,
+	0x05,
+};
+
+static const struct envelope_test menu_selection_data_612 = {
+	.pdu = menu_selection_612,
+	.pdu_len = sizeof(menu_selection_612),
+	.envelope = {
+		.type = STK_ENVELOPE_TYPE_MENU_SELECTION,
+		.src = STK_DEVICE_IDENTITY_TYPE_KEYPAD,
+		.dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+		{ .menu_selection = {
+			.item_id = 0x5,
+		}},
+	},
+};
+
+static const unsigned char menu_selection_641[] = {
+	0xd3, 0x07, 0x82, 0x02, 0x01, 0x81, 0x90, 0x01,
+	0x08,
+};
+
+static const struct envelope_test menu_selection_data_641 = {
+	.pdu = menu_selection_641,
+	.pdu_len = sizeof(menu_selection_641),
+	.envelope = {
+		.type = STK_ENVELOPE_TYPE_MENU_SELECTION,
+		.src = STK_DEVICE_IDENTITY_TYPE_KEYPAD,
+		.dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+		{ .menu_selection = {
+			.item_id = 0x8,
+		}},
+	},
+};
+
 int main(int argc, char **argv)
 {
 	g_test_init(&argc, &argv, NULL);
@@ -19742,5 +19887,22 @@ int main(int argc, char **argv)
 	g_test_add_data_func("/teststk/CBS-PP data download 1.7",
 			&cbs_pp_data_download_data_17, test_envelope_encoding);
 
+	g_test_add_data_func("/teststk/Menu Selection 1.1.1",
+			&menu_selection_data_111, test_envelope_encoding);
+	g_test_add_data_func("/teststk/Menu Selection 1.1.2",
+			&menu_selection_data_112, test_envelope_encoding);
+	g_test_add_data_func("/teststk/Menu Selection 1.2.1",
+			&menu_selection_data_121, test_envelope_encoding);
+	g_test_add_data_func("/teststk/Menu Selection 1.2.2",
+			&menu_selection_data_122, test_envelope_encoding);
+	g_test_add_data_func("/teststk/Menu Selection 1.2.3",
+			&menu_selection_data_123, test_envelope_encoding);
+	g_test_add_data_func("/teststk/Menu Selection 2.1.1",
+			&menu_selection_data_211, test_envelope_encoding);
+	g_test_add_data_func("/teststk/Menu Selection 6.1.2",
+			&menu_selection_data_612, test_envelope_encoding);
+	g_test_add_data_func("/teststk/Menu Selection 6.4.1",
+			&menu_selection_data_641, test_envelope_encoding);
+
 	return g_test_run();
 }
-- 
1.7.1.86.g0e460.dirty


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 08/11] Add a buffer size parameter to convert_utf8_to_gsm
  2010-05-31 12:47 [PATCH 01/11] stkutil: Add SMS-PP Data Download envelope builder Andrzej Zaborowski
                   ` (5 preceding siblings ...)
  2010-05-31 12:47 ` [PATCH 07/11] test-stkutil: Tests for " Andrzej Zaborowski
@ 2010-05-31 12:47 ` Andrzej Zaborowski
  2010-06-01 23:50   ` Denis Kenzior
  2010-05-31 12:47 ` [PATCH 09/11] Add a "sim string" encoding utility Andrzej Zaborowski
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 17+ messages in thread
From: Andrzej Zaborowski @ 2010-05-31 12:47 UTC (permalink / raw)
  To: ofono

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

This is needed when encoding a string into gsm that needs to fit a
in a given number of bytes.  Just taking the first N bytes of the
resulting string may leave you with byte 1 of a two-byte character at
the end of the buffer.  As far as I can tell there's no easier way to
avoid that.
---
 src/util.c       |    6 +++++-
 src/util.h       |    1 +
 unit/test-util.c |    3 ++-
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/util.c b/src/util.c
index e5ce7b3..7c27301 100644
--- a/src/util.c
+++ b/src/util.c
@@ -645,6 +645,7 @@ char *convert_gsm_to_utf8(const unsigned char *text, long len,
 unsigned char *convert_utf8_to_gsm_with_lang(const char *text, long len,
 					long *items_read, long *items_written,
 					unsigned char terminator,
+					long max_size,
 					enum gsm_dialect locking_lang,
 					enum gsm_dialect single_lang)
 {
@@ -688,6 +689,9 @@ unsigned char *convert_utf8_to_gsm_with_lang(const char *text, long len,
 		else
 			res_len += 1;
 
+		if (max_size != -1 && res_len > max_size)
+			break;
+
 		in = g_utf8_next_char(in);
 		nchars += 1;
 	}
@@ -739,7 +743,7 @@ unsigned char *convert_utf8_to_gsm(const char *text, long len,
 {
 	return convert_utf8_to_gsm_with_lang(text, len, items_read,
 						items_written,
-						terminator,
+						terminator, -1,
 						GSM_DIALECT_DEFAULT,
 						GSM_DIALECT_DEFAULT);
 }
diff --git a/src/util.h b/src/util.h
index 2835b76..d1b6b18 100644
--- a/src/util.h
+++ b/src/util.h
@@ -40,6 +40,7 @@ unsigned char *convert_utf8_to_gsm(const char *text, long len, long *items_read,
 
 unsigned char *convert_utf8_to_gsm_with_lang(const char *text, long len, long *items_read,
 				long *items_written, unsigned char terminator,
+				long max_size,
 				enum gsm_dialect locking_shift_lang,
 				enum gsm_dialect single_shift_lang);
 
diff --git a/unit/test-util.c b/unit/test-util.c
index de62848..30f4157 100644
--- a/unit/test-util.c
+++ b/unit/test-util.c
@@ -468,7 +468,8 @@ static void test_valid_turkish()
 
 		g_assert(nwritten == UTF8_LENGTH(verify[0]));
 
-		back = convert_utf8_to_gsm_with_lang(res, -1, &nread, &nwritten, 0, 1, 1);
+		back = convert_utf8_to_gsm_with_lang(res, -1, &nread,
+							&nwritten, 0, -1, 1, 1);
 
 		g_assert(back);
 
-- 
1.7.1.86.g0e460.dirty


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 09/11] Add a "sim string" encoding utility.
  2010-05-31 12:47 [PATCH 01/11] stkutil: Add SMS-PP Data Download envelope builder Andrzej Zaborowski
                   ` (6 preceding siblings ...)
  2010-05-31 12:47 ` [PATCH 08/11] Add a buffer size parameter to convert_utf8_to_gsm Andrzej Zaborowski
@ 2010-05-31 12:47 ` Andrzej Zaborowski
  2010-05-31 12:47 ` [PATCH 10/11] stkutil: Add the Call Control envelope builder Andrzej Zaborowski
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 17+ messages in thread
From: Andrzej Zaborowski @ 2010-05-31 12:47 UTC (permalink / raw)
  To: ofono

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

Use it in sim_adn_build to support UCS2 encoded strings if GSM7 is not
possible, and to avoid storing half of a double byte character at the
end of the alpha identifier field.
---
 src/simutil.c |   25 ++++++++++---------------
 src/util.c    |   43 +++++++++++++++++++++++++++++++++++++++++++
 src/util.h    |    3 +++
 3 files changed, 56 insertions(+), 15 deletions(-)

diff --git a/src/simutil.c b/src/simutil.c
index f980bf6..7291729 100644
--- a/src/simutil.c
+++ b/src/simutil.c
@@ -1232,29 +1232,24 @@ void sim_adn_build(unsigned char *data, int length,
 			const char *identifier)
 {
 	int number_len = strlen(ph->number);
-	unsigned char *gsm_identifier = NULL;
-	long gsm_bytes;
-	long alpha_length;
+	unsigned char *alpha = NULL;
+	int alpha_written = 0;
+	int alpha_length;
 
 	alpha_length = length - 14;
 
 	/* Alpha-Identifier field */
 	if (alpha_length > 0) {
-		memset(data, 0xff, alpha_length);
-
 		if (identifier)
-			gsm_identifier = convert_utf8_to_gsm(identifier,
-					-1, NULL, &gsm_bytes, 0);
-
-		if (gsm_identifier) {
-			memcpy(data, gsm_identifier,
-				MIN(gsm_bytes, alpha_length));
-			g_free(gsm_identifier);
+			alpha = utf8_to_sim_string(identifier, alpha_length,
+							&alpha_written);
+		if (alpha) {
+			memcpy(data, alpha, alpha_written);
+			g_free(alpha);
 		}
 
-		/* TODO: figure out when the identifier needs to
-		 * be encoded in UCS2 and do this.
-		 */
+		memset(data + alpha_written, 0xff,
+				alpha_length - alpha_written);
 		data += alpha_length;
 	}
 
diff --git a/src/util.c b/src/util.c
index 7c27301..4c8c2d7 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1219,3 +1219,46 @@ char *sim_string_to_utf8(const unsigned char *buffer, int length)
 
 	return utf8;
 }
+
+unsigned char *utf8_to_sim_string(const char *utf,
+					int max_length, int *out_length)
+{
+	unsigned char *result;
+	unsigned char *ucs2;
+	long gsm_bytes;
+	gsize converted;
+
+	result = convert_utf8_to_gsm_with_lang(utf, -1, NULL, &gsm_bytes,
+						0, max_length,
+						GSM_DIALECT_DEFAULT,
+						GSM_DIALECT_DEFAULT);
+	if (result) {
+		*out_length = gsm_bytes;
+		return result;
+	}
+
+	/* NOTE: UCS2 formats with an offset are never used */
+
+	ucs2 = (guint8 *) g_convert(utf, -1, "UCS-2BE//TRANSLIT", "UTF-8",
+					NULL, &converted, NULL);
+
+	if (!ucs2)
+		return NULL;
+
+	if (max_length != -1 && (int) converted + 1 > max_length)
+		converted = (max_length - 1) & ~1;
+
+	result = g_try_malloc(converted + 1);
+	if (!result) {
+		g_free(ucs2);
+		return NULL;
+	}
+
+	*out_length = converted + 1;
+
+	result[0] = 0x80;
+	memcpy(&result[1], ucs2, converted);
+	g_free(ucs2);
+
+	return result;
+}
diff --git a/src/util.h b/src/util.h
index d1b6b18..43c73b5 100644
--- a/src/util.h
+++ b/src/util.h
@@ -78,3 +78,6 @@ unsigned char *pack_7bit(const unsigned char *in, long len, int byte_offset,
 				long *items_written, unsigned char terminator);
 
 char *sim_string_to_utf8(const unsigned char *buffer, int length);
+
+unsigned char *utf8_to_sim_string(const char *utf,
+					int max_length, int *out_length);
-- 
1.7.1.86.g0e460.dirty


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 10/11] stkutil: Add the Call Control envelope builder
  2010-05-31 12:47 [PATCH 01/11] stkutil: Add SMS-PP Data Download envelope builder Andrzej Zaborowski
                   ` (7 preceding siblings ...)
  2010-05-31 12:47 ` [PATCH 09/11] Add a "sim string" encoding utility Andrzej Zaborowski
@ 2010-05-31 12:47 ` Andrzej Zaborowski
  2010-06-01 22:28   ` Andrzej Zaborowski
  2010-05-31 12:47 ` [PATCH 11/11] test-stkutil: Tests for " Andrzej Zaborowski
  2010-06-01 23:50 ` [PATCH 01/11] stkutil: Add SMS-PP Data Download " Denis Kenzior
  10 siblings, 1 reply; 17+ messages in thread
From: Andrzej Zaborowski @ 2010-05-31 12:47 UTC (permalink / raw)
  To: ofono

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

---
 src/stkutil.c |  175 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/stkutil.h |   31 ++++++++++
 2 files changed, 204 insertions(+), 2 deletions(-)

diff --git a/src/stkutil.c b/src/stkutil.c
index e5ea65a..b4466c7 100644
--- a/src/stkutil.c
+++ b/src/stkutil.c
@@ -321,8 +321,6 @@ static gboolean parse_dataobj_subaddress(struct comprehension_tlv_iter *iter,
 	unsigned int len;
 
 	len = comprehension_tlv_iter_get_length(iter);
-	if (len < 1)
-		return FALSE;
 
 	if (len > sizeof(subaddr->subaddr))
 		return FALSE;
@@ -331,6 +329,8 @@ static gboolean parse_dataobj_subaddress(struct comprehension_tlv_iter *iter,
 	subaddr->len = len;
 	memcpy(subaddr->subaddr, data, len);
 
+	subaddr->has_subaddr = TRUE;
+
 	return TRUE;
 }
 
@@ -3331,6 +3331,9 @@ static gboolean build_dataobj_address(struct stk_tlv_builder *tlv,
 	unsigned int len = (strlen(addr->number) + 1) / 2;
 	unsigned char number[len];
 
+	if (addr->number == NULL)
+		return TRUE;
+
 	sim_encode_bcd_number(addr->number, number);
 
 	return stk_tlv_builder_open_container(tlv, cr, tag, FALSE) &&
@@ -3339,6 +3342,61 @@ static gboolean build_dataobj_address(struct stk_tlv_builder *tlv,
 		stk_tlv_builder_close_container(tlv);
 }
 
+/* Described in TS 102.223 Section 8.2 */
+static gboolean build_dataobj_alpha_id(struct stk_tlv_builder *tlv,
+					const void *data, gboolean cr)
+{
+	unsigned char tag = STK_DATA_OBJECT_TYPE_ALPHA_ID;
+	int len;
+	unsigned char *string;
+
+	if (data == NULL)
+		return TRUE;
+
+	if (strlen(data) == 0)
+		return stk_tlv_builder_open_container(tlv, cr, tag, FALSE) &&
+			stk_tlv_builder_close_container(tlv);
+
+	string = utf8_to_sim_string(data, -1, &len);
+	if (string == NULL)
+		return FALSE;
+
+	return stk_tlv_builder_open_container(tlv, cr, tag, TRUE) &&
+		stk_tlv_builder_append_bytes(tlv, string, len) &&
+		stk_tlv_builder_close_container(tlv);
+}
+
+/* Described in TS 102.223 Section 8.3 */
+static gboolean build_dataobj_subaddress(struct stk_tlv_builder *tlv,
+						const void *data, gboolean cr)
+{
+	const struct stk_subaddress *sa = data;
+	unsigned char tag = STK_DATA_OBJECT_TYPE_SUBADDRESS;
+
+	if (sa->has_subaddr != TRUE)
+		return FALSE;
+
+	return stk_tlv_builder_open_container(tlv, cr, tag, FALSE) &&
+		stk_tlv_builder_append_bytes(tlv, sa->subaddr, sa->len) &&
+		stk_tlv_builder_close_container(tlv);
+}
+
+/* Described in TS 131.111 Section 8.4 */
+static gboolean build_dataobj_ccp(struct stk_tlv_builder *tlv,
+					const void *data, gboolean cr)
+{
+	const struct stk_ccp *ccp = data;
+	unsigned char tag = STK_DATA_OBJECT_TYPE_CCP;
+
+	if (ccp->len == 0)
+		return TRUE;
+
+	return stk_tlv_builder_open_container(tlv, cr, tag, FALSE) &&
+		stk_tlv_builder_append_byte(tlv, ccp->len) &&
+		stk_tlv_builder_append_bytes(tlv, ccp->ccp, ccp->len) &&
+		stk_tlv_builder_close_container(tlv);
+}
+
 /* Described in TS 131.111 Section 8.5 */
 static gboolean build_dataobj_cbs_page(struct stk_tlv_builder *tlv,
 					const void *data, gboolean cr)
@@ -3414,6 +3472,26 @@ static gboolean build_dataobj_gsm_sms_tpdu(struct stk_tlv_builder *tlv,
 		stk_tlv_builder_close_container(tlv);
 }
 
+/* Described in TS 131.111 Section 8.14 */
+static gboolean build_dataobj_ss_string(struct stk_tlv_builder *tlv,
+					const void *data, gboolean cr)
+{
+	const struct stk_address *addr = data;
+	unsigned char tag = STK_DATA_OBJECT_TYPE_SS_STRING;
+	unsigned int len = (strlen(addr->number) + 1) / 2;
+	unsigned char number[len];
+
+	if (addr->number == NULL)
+		return TRUE;
+
+	sim_encode_bcd_number(addr->number, number);
+
+	return stk_tlv_builder_open_container(tlv, cr, tag, FALSE) &&
+		stk_tlv_builder_append_byte(tlv, addr->ton_npi) &&
+		stk_tlv_builder_append_bytes(tlv, number, len) &&
+		stk_tlv_builder_close_container(tlv);
+}
+
 /* Defined in TS 102.223 Section 8.15 */
 static gboolean build_dataobj_text(struct stk_tlv_builder *tlv,
 					const void *data, gboolean cr)
@@ -3451,6 +3529,22 @@ static gboolean build_dataobj_text(struct stk_tlv_builder *tlv,
 	return stk_tlv_builder_close_container(tlv);
 }
 
+/* Described in TS 131.111 Section 8.17 */
+static gboolean build_dataobj_ussd_string(struct stk_tlv_builder *tlv,
+					const void *data, gboolean cr)
+{
+	const struct stk_ussd_string *ussd = data;
+	unsigned char tag = STK_DATA_OBJECT_TYPE_USSD_STRING;
+
+	if (ussd->string == NULL)
+		return TRUE;
+
+	return stk_tlv_builder_open_container(tlv, cr, tag, FALSE) &&
+		stk_tlv_builder_append_byte(tlv, ussd->dcs) &&
+		stk_tlv_builder_append_bytes(tlv, ussd->string, ussd->len) &&
+		stk_tlv_builder_close_container(tlv);
+}
+
 /* Described in TS 102.223 Section 8.19 */
 static gboolean build_dataobj_location_info(struct stk_tlv_builder *tlv,
 						const void *data, gboolean cr)
@@ -3698,6 +3792,19 @@ static gboolean build_dataobj_at_response(struct stk_tlv_builder *tlv,
 		stk_tlv_builder_close_container(tlv);
 }
 
+/* Described in TS 131.111 Section 8.42 */
+static gboolean build_dataobj_bc_repeat(struct stk_tlv_builder *tlv,
+						const void *data, gboolean cr)
+{
+	unsigned char tag = STK_DATA_OBJECT_TYPE_BC_REPEAT_INDICATOR;
+	const struct stk_bc_repeat *bcr = data;
+
+	return bcr->has_bc_repeat != TRUE ||
+		(stk_tlv_builder_open_container(tlv, cr, tag, TRUE) &&
+		 stk_tlv_builder_append_byte(tlv, bcr->value) &&
+		 stk_tlv_builder_close_container(tlv));
+}
+
 /* Described in TS 102.223 Section 8.45 */
 static gboolean build_dataobj_language(struct stk_tlv_builder *tlv,
 					const void *data, gboolean cr)
@@ -3773,6 +3880,23 @@ static gboolean build_dataobj_esn(struct stk_tlv_builder *tlv,
 		stk_tlv_builder_close_container(tlv);
 }
 
+/* Described in TS 131.111 Section 8.72, 3GPP 24.008 Section 9.5.7 */
+static gboolean build_dataobj_pdp_context_params(struct stk_tlv_builder *tlv,
+						const void *data, gboolean cr)
+{
+	const struct stk_common_byte_array *params = data;
+	unsigned char tag = STK_DATA_OBJECT_TYPE_PDP_ACTIVATION_PARAMETER;
+
+	if (params->len < 1)
+		return TRUE;
+	if (params->len > 0x7f)
+		return FALSE;
+
+	return stk_tlv_builder_open_container(tlv, cr, tag, FALSE) &&
+		stk_tlv_builder_append_bytes(tlv, params->array, params->len) &&
+		stk_tlv_builder_close_container(tlv);
+}
+
 /* Described in TS 102.223 Section 8.74
  *
  * See format note in parse_dataobj_imeisv.
@@ -3861,6 +3985,23 @@ static gboolean build_dataobj_broadcast_network_information(
 		stk_tlv_builder_close_container(tlv);
 }
 
+/* Described in TS 131.111 Section 8.98, 3GPP 24.301 Section 6.5.1 */
+static gboolean build_dataobj_eps_pdn_conn_params(struct stk_tlv_builder *tlv,
+						const void *data, gboolean cr)
+{
+	const struct stk_common_byte_array *params = data;
+	unsigned char tag = STK_DATA_OBJECT_TYPE_EPS_PDN_CONN_ACTIVATION_REQ;
+
+	if (params->len < 1)
+		return TRUE;
+	if (params->len > 0x7f)
+		return FALSE;
+
+	return stk_tlv_builder_open_container(tlv, cr, tag, FALSE) &&
+		stk_tlv_builder_append_bytes(tlv, params->array, params->len) &&
+		stk_tlv_builder_close_container(tlv);
+}
+
 static gboolean build_dataobj(struct stk_tlv_builder *tlv,
 				dataobj_writer builder_func, ...)
 {
@@ -4222,6 +4363,36 @@ ofono_bool_t stk_pdu_from_envelope(const struct stk_envelope *envelope,
 					&envelope->menu_selection.help_request,
 					NULL);
 		break;
+	case STK_ENVELOPE_TYPE_CALL_CONTROL:
+		ok = build_dataobj(&builder,
+					build_dataobj_address, DATAOBJ_FLAG_CR,
+					&envelope->call_control.address,
+					build_dataobj_ss_string,
+					DATAOBJ_FLAG_CR,
+					&envelope->call_control.ss_string,
+					build_dataobj_ussd_string,
+					DATAOBJ_FLAG_CR,
+					&envelope->call_control.ussd_string,
+					build_dataobj_pdp_context_params,
+					DATAOBJ_FLAG_CR,
+					&envelope->call_control.pdp_ctx_params,
+					build_dataobj_eps_pdn_conn_params,
+					DATAOBJ_FLAG_CR,
+					&envelope->call_control.eps_pdn_params,
+					build_dataobj_ccp, 0,
+					&envelope->call_control.ccp1,
+					build_dataobj_subaddress, 0,
+					&envelope->call_control.subaddress,
+					build_dataobj_location_info, 0,
+					&envelope->call_control.location,
+					build_dataobj_ccp, 0,
+					&envelope->call_control.ccp2,
+					build_dataobj_alpha_id, 0,
+					envelope->call_control.alpha_id,
+					build_dataobj_bc_repeat, 0,
+					&envelope->call_control.bc_repeat,
+					NULL);
+		break;
 	default:
 		return FALSE;
 	};
diff --git a/src/stkutil.h b/src/stkutil.h
index 0e00b7e..382f7ff 100644
--- a/src/stkutil.h
+++ b/src/stkutil.h
@@ -178,6 +178,7 @@ enum stk_data_object_type {
 	STK_DATA_OBJECT_TYPE_PLMN_LIST =			0x79,
 	STK_DATA_OBJECT_TYPE_BROADCAST_NETWORK_INFO =		0x7A,
 	STK_DATA_OBJECT_TYPE_ACTIVATE_DESCRIPTOR =		0x7B,
+	STK_DATA_OBJECT_TYPE_EPS_PDN_CONN_ACTIVATION_REQ =	0x7C,
 };
 
 enum stk_device_identity_type {
@@ -474,6 +475,7 @@ struct stk_address {
  * bytes."
  */
 struct stk_subaddress {
+	gboolean has_subaddr;
 	unsigned char len;
 	unsigned char subaddr[23];
 };
@@ -1187,6 +1189,34 @@ struct stk_envelope_menu_selection {
 	gboolean help_request;
 };
 
+/* Used both in the ENVELOPE message to UICC and response from UICC */
+struct stk_envelope_call_control {
+	/* Exactly one of the following 5 fields must be present */
+	struct stk_address address;
+	struct stk_address ss_string;
+	struct stk_ussd_string {
+		unsigned char dcs;
+		const unsigned char *string;
+		int len;
+	} ussd_string;
+	struct stk_common_byte_array pdp_ctx_params;
+	struct stk_common_byte_array eps_pdn_params;
+	/* At least one of the following two fields must be present in a
+	 * response indicating modification of the call.
+	 * In an EVELOPE message, only allowed for a call setup. */
+	struct stk_ccp ccp1;
+	struct stk_subaddress subaddress;
+	struct stk_location_info location;
+	/* Only allowed when ccp1 is present */
+	struct stk_ccp ccp2;
+	char *alpha_id;
+	/* Only allowed when both ccp1 and ccp2 are present */
+	struct stk_bc_repeat {
+		gboolean has_bc_repeat;
+		unsigned char value;
+	} bc_repeat;
+};
+
 struct stk_envelope {
 	enum stk_envelope_type type;
 	enum stk_device_identity_type src;
@@ -1195,6 +1225,7 @@ struct stk_envelope {
 		struct stk_envelope_sms_pp_download sms_pp_download;
 		struct stk_envelope_cbs_pp_download cbs_pp_download;
 		struct stk_envelope_menu_selection menu_selection;
+		struct stk_envelope_call_control call_control;
 	};
 };
 
-- 
1.7.1.86.g0e460.dirty


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 11/11] test-stkutil: Tests for Call Control envelope builder
  2010-05-31 12:47 [PATCH 01/11] stkutil: Add SMS-PP Data Download envelope builder Andrzej Zaborowski
                   ` (8 preceding siblings ...)
  2010-05-31 12:47 ` [PATCH 10/11] stkutil: Add the Call Control envelope builder Andrzej Zaborowski
@ 2010-05-31 12:47 ` Andrzej Zaborowski
  2010-06-01 23:50 ` [PATCH 01/11] stkutil: Add SMS-PP Data Download " Denis Kenzior
  10 siblings, 0 replies; 17+ messages in thread
From: Andrzej Zaborowski @ 2010-05-31 12:47 UTC (permalink / raw)
  To: ofono

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

---
 unit/test-stkutil.c |  137 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 137 insertions(+), 0 deletions(-)

diff --git a/unit/test-stkutil.c b/unit/test-stkutil.c
index 4a822ef..e2157b5 100644
--- a/unit/test-stkutil.c
+++ b/unit/test-stkutil.c
@@ -18211,6 +18211,143 @@ static const struct envelope_test menu_selection_data_641 = {
 	},
 };
 
+static const unsigned char call_control_111a[] = {
+	0xd4, 0x21, 0x82, 0x02, 0x82, 0x81, 0x86, 0x0b,
+	0x91, 0x10, 0x32, 0x54, 0x76, 0x98, 0x10, 0x32,
+	0x54, 0x76, 0x98, 0x07, 0x07, 0x06, 0x60, 0x04,
+	0x02, 0x00, 0x05, 0x81, 0x13, 0x07, 0x00, 0xf1,
+	0x10, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01,
+};
+
+static const struct envelope_test call_control_data_111a = {
+	.pdu = call_control_111a,
+	.pdu_len = sizeof(call_control_111a),
+	.envelope = {
+		.type = STK_ENVELOPE_TYPE_CALL_CONTROL,
+		.src = STK_DEVICE_IDENTITY_TYPE_TERMINAL,
+		.dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+		{ .call_control = {
+			.address = {
+				.ton_npi = 0x91, /* Intl, ISDN */
+				.number = "01234567890123456789",
+			},
+			.ccp1 = {
+				.ccp = {
+					0x60, 0x04, 0x02, 0x00, 0x05, 0x81,
+				},
+				.len = 6,
+			},
+			.location = {
+				.mcc = "00",
+				.mnc = "011",
+				.lac_tac = 0x0001,
+				.has_ci = TRUE,
+				.ci = 0x0001,
+				.has_ext_ci = TRUE,
+				.ext_ci = 0x0001,
+			},
+		}},
+	},
+};
+
+static const unsigned char call_control_111b[] = {
+	0xd4, 0x23, 0x82, 0x02, 0x82, 0x81, 0x86, 0x0b,
+	0x91, 0x10, 0x32, 0x54, 0x76, 0x98, 0x10, 0x32,
+	0x54, 0x76, 0x98, 0x07, 0x07, 0x06, 0x60, 0x04,
+	0x02, 0x00, 0x05, 0x81, 0x13, 0x07, 0x00, 0x11,
+	0x10, 0x00, 0x01, 0x00, 0x01,
+};
+
+static const struct envelope_test call_control_data_111b = {
+	.pdu = call_control_111b,
+	.pdu_len = sizeof(call_control_111b),
+	.envelope = {
+		.type = STK_ENVELOPE_TYPE_CALL_CONTROL,
+		.src = STK_DEVICE_IDENTITY_TYPE_TERMINAL,
+		.dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+		{ .call_control = {
+			.address = {
+				.ton_npi = 0x91, /* Intl, ISDN */
+				.number = "01234567890123456789",
+			},
+			.ccp1 = {
+				.ccp = {
+					0x60, 0x04, 0x02, 0x00, 0x05, 0x81,
+				},
+				.len = 6,
+			},
+			.location = {
+				.mcc = "001",
+				.mnc = "011",
+				.lac_tac = 0x0001,
+				.has_ci = TRUE,
+				.ci = 0x0001,
+			},
+		}},
+	},
+};
+
+static const unsigned char call_control_131a[] = {
+	0xd4, 0x18, 0x02, 0x02, 0x82, 0x81, 0x06, 0x07,
+	0x91, 0x10, 0x32, 0x04, 0x21, 0x43, 0x65, 0x13,
+	0x09, 0x00, 0xf1, 0x10, 0x00, 0x01, 0x00, 0x01,
+	0x00, 0x01,
+};
+
+static const struct envelope_test call_control_data_131a = {
+	.pdu = call_control_131a,
+	.pdu_len = sizeof(call_control_131a),
+	.envelope = {
+		.type = STK_ENVELOPE_TYPE_CALL_CONTROL,
+		.src = STK_DEVICE_IDENTITY_TYPE_TERMINAL,
+		.dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+		{ .call_control = {
+			.address = {
+				.ton_npi = 0x91, /* Intl, ISDN */
+				.number = "012340123456",
+			},
+			.location = {
+				.mcc = "00",
+				.mnc = "011",
+				.lac_tac = 0x0001,
+				.has_ci = TRUE,
+				.ci = 0x0001,
+				.has_ext_ci = TRUE,
+				.ext_ci = 0x0001,
+			},
+		}},
+	},
+};
+
+static const unsigned char call_control_131b[] = {
+	0xd4, 0x16, 0x02, 0x02, 0x82, 0x81, 0x06, 0x07,
+	0x91, 0x10, 0x32, 0x04, 0x21, 0x43, 0x65, 0x13,
+	0x07, 0x00, 0x11, 0x10, 0x00, 0x01, 0x00, 0x01,
+};
+
+static const struct envelope_test call_control_data_131b = {
+	.pdu = call_control_131b,
+	.pdu_len = sizeof(call_control_131b),
+	.envelope = {
+		.type = STK_ENVELOPE_TYPE_CALL_CONTROL,
+		.src = STK_DEVICE_IDENTITY_TYPE_TERMINAL,
+		.dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+		{ .call_control = {
+			.address = {
+				.ton_npi = 0x91, /* Intl, ISDN */
+				.number = "012340123456",
+			},
+			.location = {
+				.mcc = "001",
+				.mnc = "011",
+				.lac_tac = 0x0001,
+				.has_ci = TRUE,
+				.ci = 0x0001,
+			},
+		}},
+	},
+};
+
 int main(int argc, char **argv)
 {
 	g_test_init(&argc, &argv, NULL);
-- 
1.7.1.86.g0e460.dirty


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 10/11] stkutil: Add the Call Control envelope builder
  2010-05-31 12:47 ` [PATCH 10/11] stkutil: Add the Call Control envelope builder Andrzej Zaborowski
@ 2010-06-01 22:28   ` Andrzej Zaborowski
  0 siblings, 0 replies; 17+ messages in thread
From: Andrzej Zaborowski @ 2010-06-01 22:28 UTC (permalink / raw)
  To: ofono

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

On 31 May 2010 14:47, Andrzej Zaborowski <andrew.zaborowski@intel.com> wrote:
> ---
>  src/stkutil.c |  175 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  src/stkutil.h |   31 ++++++++++
>  2 files changed, 204 insertions(+), 2 deletions(-)

Please ignore this patch and the following one, I will resend with
some corrections later.

Thanks,
Andrew

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 08/11] Add a buffer size parameter to convert_utf8_to_gsm
  2010-05-31 12:47 ` [PATCH 08/11] Add a buffer size parameter to convert_utf8_to_gsm Andrzej Zaborowski
@ 2010-06-01 23:50   ` Denis Kenzior
  0 siblings, 0 replies; 17+ messages in thread
From: Denis Kenzior @ 2010-06-01 23:50 UTC (permalink / raw)
  To: ofono

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

Hi Andrew,

> This is needed when encoding a string into gsm that needs to fit a
> in a given number of bytes.  Just taking the first N bytes of the
> resulting string may leave you with byte 1 of a two-byte character at
> the end of the buffer.  As far as I can tell there's no easier way to
> avoid that.

In gsm it is actually pretty easy, the escape character for two-byte sequence 
is always 0x1b, so chopping a string up could be done quite easily.

>  unsigned char *convert_utf8_to_gsm_with_lang(const char *text, long len,
>  long *items_read, long *items_written, unsigned char terminator,
> +				long max_size,
>  				enum gsm_dialect locking_shift_lang,
>  				enum gsm_dialect single_shift_lang);

If there's still need for this, I'd prefer we reuse long *items_written as an 
in/out argument for the max size or add another function entirely, adding yet 
another int argument is getting a bit ridiculous.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 01/11] stkutil: Add SMS-PP Data Download envelope builder
  2010-05-31 12:47 [PATCH 01/11] stkutil: Add SMS-PP Data Download envelope builder Andrzej Zaborowski
                   ` (9 preceding siblings ...)
  2010-05-31 12:47 ` [PATCH 11/11] test-stkutil: Tests for " Andrzej Zaborowski
@ 2010-06-01 23:50 ` Denis Kenzior
  2010-06-03  9:53   ` Andrzej Zaborowski
  10 siblings, 1 reply; 17+ messages in thread
From: Denis Kenzior @ 2010-06-01 23:50 UTC (permalink / raw)
  To: ofono

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

Hi Andrew,

> Note that the sms_tpdu member could be of type struct sms_deliver, but the
> users may more often have access to the raw tpdu so there's no point
> decoding and reencoding it.

Overall patch looks fine, but using a raw pdu is not preferable.  Couple of 
reasons:

- When SMS is delivered, it is delivered in tpdu form, e.g. sc_address + 
deliver pdu.  To obtain the sc_address, we need to decode the deliver tpdu 
anyway.
- Before we know this is an SMS-PP download, we must check the dcs / pid.  In 
order to check those, we must again decode the tpdu.
- SMS sc_address can actually be non-numeric.  In that case the SMS-PP 
download should simply be dropped.
- Consistency with Send SMS proactive command.

> +
> +/* Returns TRUE on success */
> +ofono_bool_t stk_pdu_from_envelope(const struct stk_envelope *envelope,
> +					unsigned char *pdu, unsigned int size,
> +					unsigned char **out_pdu,
> +					unsigned int *out_size);
> 

This part just looks ugly.  Can't we hide the details of char buf[512] 
somewhere inside stk_pdu_from_envelope?  Or perhaps make **out_pdu and 
*out_size in/out arguments instead of just out.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 01/11] stkutil: Add SMS-PP Data Download envelope builder
  2010-06-01 23:50 ` [PATCH 01/11] stkutil: Add SMS-PP Data Download " Denis Kenzior
@ 2010-06-03  9:53   ` Andrzej Zaborowski
  2010-06-03 15:32     ` Denis Kenzior
  0 siblings, 1 reply; 17+ messages in thread
From: Andrzej Zaborowski @ 2010-06-03  9:53 UTC (permalink / raw)
  To: ofono

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

Hi Denis,

On 2 June 2010 01:50, Denis Kenzior <denkenz@gmail.com> wrote:
> Hi Andrew,
>
>> Note that the sms_tpdu member could be of type struct sms_deliver, but the
>> users may more often have access to the raw tpdu so there's no point
>> decoding and reencoding it.
>
> Overall patch looks fine, but using a raw pdu is not preferable.  Couple of
> reasons:
>
> - When SMS is delivered, it is delivered in tpdu form, e.g. sc_address +
> deliver pdu.  To obtain the sc_address, we need to decode the deliver tpdu
> anyway.
> - Before we know this is an SMS-PP download, we must check the dcs / pid.  In
> order to check those, we must again decode the tpdu.
> - SMS sc_address can actually be non-numeric.  In that case the SMS-PP
> download should simply be dropped.

This means we have to decode the PDU, but re-encoding it is still an
overhead having access to the TPDU.

> - Consistency with Send SMS proactive command.

Ok, makes sense.

>
>> +
>> +/* Returns TRUE on success */
>> +ofono_bool_t stk_pdu_from_envelope(const struct stk_envelope *envelope,
>> +                                     unsigned char *pdu, unsigned int size,
>> +                                     unsigned char **out_pdu,
>> +                                     unsigned int *out_size);
>>
>
> This part just looks ugly.  Can't we hide the details of char buf[512]
> somewhere inside stk_pdu_from_envelope?

By that do you mean using a static buffer?  I'll send a patch for
that.  I prefer a static buffer for the PDUs but thought you had
argued against it :)

Regards

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 01/11] stkutil: Add SMS-PP Data Download envelope builder
  2010-06-03  9:53   ` Andrzej Zaborowski
@ 2010-06-03 15:32     ` Denis Kenzior
  2010-06-07 13:25       ` Andrzej Zaborowski
  0 siblings, 1 reply; 17+ messages in thread
From: Denis Kenzior @ 2010-06-03 15:32 UTC (permalink / raw)
  To: ofono

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

Hi Andrew,

> > - When SMS is delivered, it is delivered in tpdu form, e.g. sc_address +
> > deliver pdu.  To obtain the sc_address, we need to decode the deliver
> > tpdu anyway.
> > - Before we know this is an SMS-PP download, we must check the dcs / pid.
> >  In order to check those, we must again decode the tpdu.
> > - SMS sc_address can actually be non-numeric.  In that case the SMS-PP
> > download should simply be dropped.
> 
> This means we have to decode the PDU, but re-encoding it is still an
> overhead having access to the TPDU.

Fair enough, I don't really feel strongly either way.  However, encoding is 
quite fast and we have to re-encode the sc_address in a different format anyway 
because of the weird sc_addr encoding rules.

> 
> > - Consistency with Send SMS proactive command.
> 
> Ok, makes sense.

One thing that comes to mind is that we might have to modify sms_encode() with 
the capability to skip encoding the sc_address field.  Otherwise our pdu will 
have some extra crap in the beginning.

> 
> >> +
> >> +/* Returns TRUE on success */
> >> +ofono_bool_t stk_pdu_from_envelope(const struct stk_envelope *envelope,
> >> +                                     unsigned char *pdu, unsigned int
> >> size, +                                     unsigned char **out_pdu,
> >> +                                     unsigned int *out_size);
> >
> > This part just looks ugly.  Can't we hide the details of char buf[512]
> > somewhere inside stk_pdu_from_envelope?
> 
> By that do you mean using a static buffer?  I'll send a patch for
> that.  I prefer a static buffer for the PDUs but thought you had
> argued against it :)

Don't recall :)  I think in this case it is ok, or you can always make the 
function re-entrant safe by making the buf argument in/out.

e.g.

char buf[512];
char *out = buf;

func(foo, bar, &out);

Regards,
-Denis

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 01/11] stkutil: Add SMS-PP Data Download envelope builder
  2010-06-03 15:32     ` Denis Kenzior
@ 2010-06-07 13:25       ` Andrzej Zaborowski
  0 siblings, 0 replies; 17+ messages in thread
From: Andrzej Zaborowski @ 2010-06-07 13:25 UTC (permalink / raw)
  To: ofono

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

On 3 June 2010 17:32, Denis Kenzior <denkenz@gmail.com> wrote:
>> > - When SMS is delivered, it is delivered in tpdu form, e.g. sc_address +
>> > deliver pdu.  To obtain the sc_address, we need to decode the deliver
>> > tpdu anyway.
>> > - Before we know this is an SMS-PP download, we must check the dcs / pid.
>> >  In order to check those, we must again decode the tpdu.
>> > - SMS sc_address can actually be non-numeric.  In that case the SMS-PP
>> > download should simply be dropped.
>>
>> This means we have to decode the PDU, but re-encoding it is still an
>> overhead having access to the TPDU.
>
> Fair enough, I don't really feel strongly either way.  However, encoding is
> quite fast and we have to re-encode the sc_address in a different format anyway
> because of the weird sc_addr encoding rules.

I'll send a new patch using struct sms_deliver (this way api enforces
the correct type of pdu is supplied).

>
>>
>> > - Consistency with Send SMS proactive command.
>>
>> Ok, makes sense.
>
> One thing that comes to mind is that we might have to modify sms_encode() with
> the capability to skip encoding the sc_address field.  Otherwise our pdu will
> have some extra crap in the beginning.
>
>>
>> >> +
>> >> +/* Returns TRUE on success */
>> >> +ofono_bool_t stk_pdu_from_envelope(const struct stk_envelope *envelope,
>> >> +                                     unsigned char *pdu, unsigned int
>> >> size, +                                     unsigned char **out_pdu,
>> >> +                                     unsigned int *out_size);
>> >
>> > This part just looks ugly.  Can't we hide the details of char buf[512]
>> > somewhere inside stk_pdu_from_envelope?
>>
>> By that do you mean using a static buffer?  I'll send a patch for
>> that.  I prefer a static buffer for the PDUs but thought you had
>> argued against it :)
>
> Don't recall :)  I think in this case it is ok, or you can always make the
> function re-entrant safe by making the buf argument in/out.
>
> e.g.
>
> char buf[512];
> char *out = buf;
>
> func(foo, bar, &out);

The nice thing about static buffer is the users don't have to worry
about how many bytes to reserve.  It would also allow dropping 90% of
the length checks which are then only defensive coding.

Regards,
Andrew

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2010-06-07 13:25 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-31 12:47 [PATCH 01/11] stkutil: Add SMS-PP Data Download envelope builder Andrzej Zaborowski
2010-05-31 12:47 ` [PATCH 02/11] test-stkutil: Tests for " Andrzej Zaborowski
2010-05-31 12:47 ` [PATCH 03/11] stkutil: Add CBS-PP " Andrzej Zaborowski
2010-05-31 12:47 ` [PATCH 04/11] stk: Use envelope encoding utility from stkutil.c Andrzej Zaborowski
2010-05-31 12:47 ` [PATCH 05/11] test-stkutil: Tests for CBS-PP Data Download envelope builder Andrzej Zaborowski
2010-05-31 12:47 ` [PATCH 06/11] stkutil: Add the Menu Selection " Andrzej Zaborowski
2010-05-31 12:47 ` [PATCH 07/11] test-stkutil: Tests for " Andrzej Zaborowski
2010-05-31 12:47 ` [PATCH 08/11] Add a buffer size parameter to convert_utf8_to_gsm Andrzej Zaborowski
2010-06-01 23:50   ` Denis Kenzior
2010-05-31 12:47 ` [PATCH 09/11] Add a "sim string" encoding utility Andrzej Zaborowski
2010-05-31 12:47 ` [PATCH 10/11] stkutil: Add the Call Control envelope builder Andrzej Zaborowski
2010-06-01 22:28   ` Andrzej Zaborowski
2010-05-31 12:47 ` [PATCH 11/11] test-stkutil: Tests for " Andrzej Zaborowski
2010-06-01 23:50 ` [PATCH 01/11] stkutil: Add SMS-PP Data Download " Denis Kenzior
2010-06-03  9:53   ` Andrzej Zaborowski
2010-06-03 15:32     ` Denis Kenzior
2010-06-07 13:25       ` Andrzej Zaborowski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.