All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/14][RESEND] STK patches without agent
@ 2010-07-06 22:38 Andrzej Zaborowski
  2010-07-06 22:38 ` [PATCH 01/14] stk: Utilities for proactive command/envelope handling Andrzej Zaborowski
                   ` (14 more replies)
  0 siblings, 15 replies; 18+ messages in thread
From: Andrzej Zaborowski @ 2010-07-06 22:38 UTC (permalink / raw)
  To: ofono

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

These are some patches I sent before reordered and refactored to
skip stuff related to the Agent API, i.e. related to the UI.

Andrzej Zaborowski (14):
  stk: Utilities for proactive command/envelope handling.
  mbmmodem: End session on *STKEND.
  stk: Handle the More Time proactive command as a nop.
  Add OFONO_ERROR_TYPE_SIM for negative SIM statuses.
  atmodem: Make sim operations return sim error codes.
  stk: Handle ENVELOPEs in a queue, retry on sim busy.
  Add __ofono_sms_submit for other atoms to submit SMs.
  stk: Handle the Send SMS proactive command.
  Add Dbus interface names for STK.
  stk: Handle the Set Up Idle Text proactive command.
  sktutil: Use the Mandatory flag in parse_dataobj.
  stkutil: Timer Value is conditional, not optional.
  stk: Handle the Timer Management proactive command.
  stk: Handle the Poll Interval proactive command.

 drivers/atmodem/sim.c  |   32 ++-
 drivers/atmodem/stk.c  |   20 +-
 drivers/mbmmodem/stk.c |    3 +
 include/dbus.h         |    2 +
 include/stk.h          |    2 +
 include/types.h        |    1 +
 src/ofono.h            |    7 +-
 src/sms.c              |   39 +++
 src/stk.c              |  667 ++++++++++++++++++++++++++++++++++++++++++++++--
 src/stkutil.c          |   12 +-
 10 files changed, 744 insertions(+), 41 deletions(-)


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

* [PATCH 01/14] stk: Utilities for proactive command/envelope handling.
  2010-07-06 22:38 [PATCH 00/14][RESEND] STK patches without agent Andrzej Zaborowski
@ 2010-07-06 22:38 ` Andrzej Zaborowski
  2010-07-06 22:38 ` [PATCH 02/14] mbmmodem: End session on *STKEND Andrzej Zaborowski
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Andrzej Zaborowski @ 2010-07-06 22:38 UTC (permalink / raw)
  To: ofono

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

---
 include/stk.h |    2 +
 src/stk.c     |  173 +++++++++++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 157 insertions(+), 18 deletions(-)

diff --git a/include/stk.h b/include/stk.h
index ad3f6c5..638da9c 100644
--- a/include/stk.h
+++ b/include/stk.h
@@ -65,6 +65,8 @@ void *ofono_stk_get_data(struct ofono_stk *stk);
 void ofono_stk_proactive_command_notify(struct ofono_stk *stk,
 					int length, const unsigned char *pdu);
 
+void ofono_stk_proactive_session_end_notify(struct ofono_stk *stk);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/stk.c b/src/stk.c
index b5c6919..66b0a6b 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -43,48 +43,144 @@ struct ofono_stk {
 	const struct ofono_stk_driver *driver;
 	void *driver_data;
 	struct ofono_atom *atom;
+	struct stk_command *pending_cmd;
+	void (*cancel_cmd)(struct ofono_stk *stk);
+	gboolean cancelled;
 };
 
+static int stk_respond(struct ofono_stk *stk, struct stk_response *rsp,
+			ofono_stk_generic_cb_t cb)
+{
+	const guint8 *tlv;
+	unsigned int tlv_len;
+
+	if (stk->driver->terminal_response == NULL)
+		return -ENOSYS;
+
+	rsp->src = STK_DEVICE_IDENTITY_TYPE_TERMINAL;
+	rsp->dst = STK_DEVICE_IDENTITY_TYPE_UICC;
+	rsp->number = stk->pending_cmd->number;
+	rsp->type = stk->pending_cmd->type;
+	rsp->qualifier = stk->pending_cmd->qualifier;
+
+	tlv = stk_pdu_from_response(rsp, &tlv_len);
+	if (!tlv)
+		return -EINVAL;
+
+	stk_command_free(stk->pending_cmd);
+	stk->pending_cmd = NULL;
+
+	stk->driver->terminal_response(stk, tlv_len, tlv, cb, stk);
+
+	return 0;
+}
+
+static int stk_send_envelope(struct ofono_stk *stk, struct stk_envelope *e,
+				ofono_stk_envelope_cb_t cb)
+{
+	const guint8 *tlv;
+	unsigned int tlv_len;
+
+	if (stk->driver->envelope == NULL)
+		return -ENOSYS;
+
+	e->dst = STK_DEVICE_IDENTITY_TYPE_UICC;
+
+	tlv = stk_pdu_from_envelope(e, &tlv_len);
+	if (!tlv)
+		return -EINVAL;
+
+	stk->driver->envelope(stk, tlv_len, tlv, cb, stk);
+
+	return 0;
+}
+
 static void stk_cbs_download_cb(const struct ofono_error *error,
 				const unsigned char *data, int len, void *user)
 {
 	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." */
+		/*
+		 * "The ME may retry to deliver the same Cell Broadcast
+		 * page."
+		 */
 		return;
 	}
 
+	if (len)
+		ofono_error("CellBroadcast download returned %i bytes of data",
+				len);
+
 	DBG("CellBroadcast download to UICC reported no error");
 }
 
 void __ofono_cbs_sim_download(struct ofono_stk *stk, const struct cbs *msg)
 {
-	const guint8 *tlv;
-	unsigned int tlv_len;
+	struct ofono_error error = { .type = OFONO_ERROR_TYPE_FAILURE };
 	struct stk_envelope e;
+	int err;
 
-	if (stk->driver->envelope == NULL)
-		return;
+	memset(&e, 0, sizeof(e));
 
 	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, msg, sizeof(msg));
 
-	tlv = stk_pdu_from_envelope(&e, &tlv_len);
-	if (!tlv)
+	err = stk_send_envelope(stk, &e, stk_cbs_download_cb);
+	if (err)
+		stk_cbs_download_cb(&error, NULL, -1, stk);
+}
+
+static void stk_command_cb(const struct ofono_error *error, void *data)
+{
+	if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
+		ofono_error("TERMINAL RESPONSE to a UICC command failed");
+		/* "The ME may retry to deliver the same Cell Broadcast
+		 * page." */
 		return;
+	}
+
+	DBG("TERMINAL RESPONSE to a command reported no errors");
+}
+
+static void stk_proactive_command_cancel(struct ofono_stk *stk)
+{
+	if (!stk->pending_cmd)
+		return;
+
+	stk->cancelled = TRUE;
+
+	stk->cancel_cmd(stk);
+
+	if (stk->pending_cmd) {
+		stk_command_free(stk->pending_cmd);
+		stk->pending_cmd = NULL;
+	}
+}
 
-	stk->driver->envelope(stk, tlv_len, tlv, stk_cbs_download_cb, stk);
+void ofono_stk_proactive_session_end_notify(struct ofono_stk *stk)
+{
+	stk_proactive_command_cancel(stk);
 }
 
 void ofono_stk_proactive_command_notify(struct ofono_stk *stk,
 					int length, const unsigned char *pdu)
 {
-	struct stk_command *cmd;
+	struct ofono_error error = { .type = OFONO_ERROR_TYPE_FAILURE };
+	struct stk_response rsp;
 	char *buf;
-	int i;
+	int i, err;
+	gboolean respond = TRUE;
+
+	/*
+	 * Depending on the hardware we may have received a new
+	 * command before we managed to send a TERMINAL RESPONSE to
+	 * the previous one.  3GPP says in the current revision only
+	 * one command can be executing at any time, so assume that
+	 * the previous one is being cancelled and the card just
+	 * expects a response to the new one.
+	 */
+	stk_proactive_command_cancel(stk);
 
 	buf = g_try_malloc(length * 2 + 1);
 	if (!buf)
@@ -93,18 +189,53 @@ void ofono_stk_proactive_command_notify(struct ofono_stk *stk,
 	for (i = 0; i < length; i ++)
 		sprintf(buf + i * 2, "%02hhx", pdu[i]);
 
-	cmd = stk_command_new_from_pdu(pdu, length);
-	if (!cmd) {
+	stk->cancelled = FALSE;
+
+	stk->pending_cmd = stk_command_new_from_pdu(pdu, length);
+	if (!stk->pending_cmd) {
 		ofono_error("Can't parse proactive command: %s", buf);
 
-		/* TODO: return TERMINAL RESPONSE with permanent error */
+		/*
+		 * Nothing we can do, we'd need at least Command Details
+		 * to be able to respond with an error.
+		 */
 		goto done;
 	}
 
-	/* TODO: execute */
-	ofono_info("Proactive command PDU: %s", buf);
+	ofono_debug("Proactive command PDU: %s", buf);
 
-	stk_command_free(cmd);
+	memset(&rsp, 0, sizeof(rsp));
+
+	switch (stk->pending_cmd->status) {
+	case STK_PARSE_RESULT_OK:
+		switch (stk->pending_cmd->type) {
+		default:
+			rsp.result.type =
+				STK_RESULT_TYPE_COMMAND_NOT_UNDERSTOOD;
+			break;
+		}
+
+		if (respond)
+			break;
+		return;
+
+	case STK_PARSE_RESULT_MISSING_VALUE:
+		rsp.result.type = STK_RESULT_TYPE_MINIMUM_NOT_MET;
+		break;
+
+	case STK_PARSE_RESULT_DATA_NOT_UNDERSTOOD:
+		rsp.result.type = STK_RESULT_TYPE_DATA_NOT_UNDERSTOOD;
+		break;
+
+	case STK_PARSE_RESULT_TYPE_NOT_UNDERSTOOD:
+	default:
+		rsp.result.type = STK_RESULT_TYPE_COMMAND_NOT_UNDERSTOOD;
+		break;
+	}
+
+	err = stk_respond(stk, &rsp, stk_command_cb);
+	if (err)
+		stk_command_cb(&error, stk);
 
 done:
 	g_free(buf);
@@ -131,6 +262,12 @@ void ofono_stk_driver_unregister(const struct ofono_stk_driver *d)
 
 static void stk_unregister(struct ofono_atom *atom)
 {
+	struct ofono_stk *stk = __ofono_atom_get_data(atom);
+
+	if (stk->pending_cmd) {
+		stk_command_free(stk->pending_cmd);
+		stk->pending_cmd = NULL;
+	}
 }
 
 static void stk_remove(struct ofono_atom *atom)
-- 
1.7.1.86.g0e460.dirty


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

* [PATCH 02/14] mbmmodem: End session on *STKEND.
  2010-07-06 22:38 [PATCH 00/14][RESEND] STK patches without agent Andrzej Zaborowski
  2010-07-06 22:38 ` [PATCH 01/14] stk: Utilities for proactive command/envelope handling Andrzej Zaborowski
@ 2010-07-06 22:38 ` Andrzej Zaborowski
  2010-07-06 22:38 ` [PATCH 03/14] stk: Handle the More Time proactive command as a nop Andrzej Zaborowski
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Andrzej Zaborowski @ 2010-07-06 22:38 UTC (permalink / raw)
  To: ofono

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

---
 drivers/mbmmodem/stk.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/drivers/mbmmodem/stk.c b/drivers/mbmmodem/stk.c
index 77bd7b5..613b257 100644
--- a/drivers/mbmmodem/stk.c
+++ b/drivers/mbmmodem/stk.c
@@ -179,6 +179,9 @@ static void stkn_notify(GAtResult *result, gpointer user_data)
 
 static void stkend_notify(GAtResult *result, gpointer user_data)
 {
+	struct ofono_stk *stk = user_data;
+
+	ofono_stk_proactive_session_end_notify(stk);
 }
 
 static void mbm_stkc_cb(gboolean ok, GAtResult *result, gpointer user_data)
-- 
1.7.1.86.g0e460.dirty


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

* [PATCH 03/14] stk: Handle the More Time proactive command as a nop.
  2010-07-06 22:38 [PATCH 00/14][RESEND] STK patches without agent Andrzej Zaborowski
  2010-07-06 22:38 ` [PATCH 01/14] stk: Utilities for proactive command/envelope handling Andrzej Zaborowski
  2010-07-06 22:38 ` [PATCH 02/14] mbmmodem: End session on *STKEND Andrzej Zaborowski
@ 2010-07-06 22:38 ` Andrzej Zaborowski
  2010-07-06 22:38 ` [PATCH 04/14] Add OFONO_ERROR_TYPE_SIM for negative SIM statuses Andrzej Zaborowski
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Andrzej Zaborowski @ 2010-07-06 22:38 UTC (permalink / raw)
  To: ofono

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

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

diff --git a/src/stk.c b/src/stk.c
index 66b0a6b..ba66fe2 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -143,6 +143,15 @@ static void stk_command_cb(const struct ofono_error *error, void *data)
 	DBG("TERMINAL RESPONSE to a command reported no errors");
 }
 
+static gboolean handle_command_more_time(const struct stk_command *cmd,
+						struct stk_response *rsp,
+						struct ofono_stk *stk)
+{
+	/* Do nothing */
+
+	return TRUE;
+}
+
 static void stk_proactive_command_cancel(struct ofono_stk *stk)
 {
 	if (!stk->pending_cmd)
@@ -213,6 +222,10 @@ void ofono_stk_proactive_command_notify(struct ofono_stk *stk,
 			rsp.result.type =
 				STK_RESULT_TYPE_COMMAND_NOT_UNDERSTOOD;
 			break;
+		case STK_COMMAND_TYPE_MORE_TIME:
+			respond = handle_command_more_time(stk->pending_cmd,
+								&rsp, stk);
+			break;
 		}
 
 		if (respond)
-- 
1.7.1.86.g0e460.dirty


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

* [PATCH 04/14] Add OFONO_ERROR_TYPE_SIM for negative SIM statuses.
  2010-07-06 22:38 [PATCH 00/14][RESEND] STK patches without agent Andrzej Zaborowski
                   ` (2 preceding siblings ...)
  2010-07-06 22:38 ` [PATCH 03/14] stk: Handle the More Time proactive command as a nop Andrzej Zaborowski
@ 2010-07-06 22:38 ` Andrzej Zaborowski
  2010-07-06 22:39 ` [PATCH 05/14] atmodem: Make sim operations return sim error codes Andrzej Zaborowski
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Andrzej Zaborowski @ 2010-07-06 22:38 UTC (permalink / raw)
  To: ofono

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

Expected value of the .error field is status word 1 and status word 2
in bits 8:15 and 0:7 of the field.
---
 include/types.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/include/types.h b/include/types.h
index 2b154f0..6098cba 100644
--- a/include/types.h
+++ b/include/types.h
@@ -60,6 +60,7 @@ enum ofono_error_type {
 	OFONO_ERROR_TYPE_CME,
 	OFONO_ERROR_TYPE_CMS,
 	OFONO_ERROR_TYPE_CEER,
+	OFONO_ERROR_TYPE_SIM,
 	OFONO_ERROR_TYPE_FAILURE
 };
 
-- 
1.7.1.86.g0e460.dirty


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

* [PATCH 05/14] atmodem: Make sim operations return sim error codes.
  2010-07-06 22:38 [PATCH 00/14][RESEND] STK patches without agent Andrzej Zaborowski
                   ` (3 preceding siblings ...)
  2010-07-06 22:38 ` [PATCH 04/14] Add OFONO_ERROR_TYPE_SIM for negative SIM statuses Andrzej Zaborowski
@ 2010-07-06 22:39 ` Andrzej Zaborowski
  2010-07-06 22:39 ` [PATCH 06/14] stk: Handle ENVELOPEs in a queue, retry on sim busy Andrzej Zaborowski
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Andrzej Zaborowski @ 2010-07-06 22:39 UTC (permalink / raw)
  To: ofono

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

---
 drivers/atmodem/sim.c |   32 +++++++++++++++++++++++++-------
 drivers/atmodem/stk.c |   20 ++++++++++++--------
 2 files changed, 37 insertions(+), 15 deletions(-)

diff --git a/drivers/atmodem/sim.c b/drivers/atmodem/sim.c
index 2b4a8c6..d5d5ff9 100644
--- a/drivers/atmodem/sim.c
+++ b/drivers/atmodem/sim.c
@@ -82,8 +82,15 @@ static void at_crsm_info_cb(gboolean ok, GAtResult *result, gpointer user_data)
 
 	if (!g_at_result_iter_next_hexstring(&iter, &response, &len) ||
 			(sw1 != 0x90 && sw1 != 0x91 && sw1 != 0x92) ||
-			(sw1 == 0x90 && sw2 != 0x00))
-		goto error;
+			(sw1 == 0x90 && sw2 != 0x00)) {
+		memset(&error, 0, sizeof(error));
+
+		error.type = OFONO_ERROR_TYPE_SIM;
+		error.error = (sw1 << 8) | sw2;
+
+		cb(&error, -1, -1, -1, NULL, cbd->data);
+		return;
+	}
 
 	DBG("crsm_info_cb: %02x, %02x, %i", sw1, sw2, len);
 
@@ -165,9 +172,18 @@ static void at_crsm_read_cb(gboolean ok, GAtResult *result,
 	g_at_result_iter_next_number(&iter, &sw1);
 	g_at_result_iter_next_number(&iter, &sw2);
 
-	if (!g_at_result_iter_next_hexstring(&iter, &response, &len) ||
-		(sw1 != 0x90 && sw1 != 0x91 && sw1 != 0x92 && sw1 != 0x9f) ||
-		(sw1 == 0x90 && sw2 != 0x00)) {
+	if ((sw1 != 0x90 && sw1 != 0x91 && sw1 != 0x92 && sw1 != 0x9f) ||
+			(sw1 == 0x90 && sw2 != 0x00)) {
+		memset(&error, 0, sizeof(error));
+
+		error.type = OFONO_ERROR_TYPE_SIM;
+		error.error = (sw1 << 8) | sw2;
+
+		cb(&error, NULL, 0, cbd->data);
+		return;
+	}
+
+	if (!g_at_result_iter_next_hexstring(&iter, &response, &len)) {
 		CALLBACK_WITH_FAILURE(cb, NULL, 0, cbd->data);
 		return;
 	}
@@ -255,8 +271,10 @@ static void at_crsm_update_cb(gboolean ok, GAtResult *result,
 
 	if ((sw1 != 0x90 && sw1 != 0x91 && sw1 != 0x92 && sw1 != 0x9f) ||
 			(sw1 == 0x90 && sw2 != 0x00)) {
-		CALLBACK_WITH_FAILURE(cb, cbd->data);
-		return;
+		memset(&error, 0, sizeof(error));
+
+		error.type = OFONO_ERROR_TYPE_SIM;
+		error.error = (sw1 << 8) | sw2;
 	}
 
 	DBG("crsm_update_cb: %02x, %02x", sw1, sw2);
diff --git a/drivers/atmodem/stk.c b/drivers/atmodem/stk.c
index 8cff4a2..aede668 100644
--- a/drivers/atmodem/stk.c
+++ b/drivers/atmodem/stk.c
@@ -74,11 +74,13 @@ static void at_csim_envelope_cb(gboolean ok, GAtResult *result,
 	if (rlen != len * 2 || len < 2)
 		goto error;
 
-	if (response[len - 2] != 0x90 && response[len - 2] != 0x91)
-		goto error;
+	if ((response[len - 2] != 0x90 && response[len - 2] != 0x91) ||
+			(response[len - 2] == 0x90 && response[len - 1] != 0)) {
+		memset(&error, 0, sizeof(error));
 
-	if (response[len - 2] == 0x90 && response[len - 1] != 0)
-		goto error;
+		error.type = OFONO_ERROR_TYPE_SIM;
+		error.error = (response[len - 2] << 8) | response[len - 1];
+	}
 
 	DBG("csim_envelope_cb: %i", len);
 
@@ -157,11 +159,13 @@ static void at_csim_terminal_response_cb(gboolean ok, GAtResult *result,
 	if (rlen != len * 2 || len < 2)
 		goto error;
 
-	if (response[len - 2] != 0x90 && response[len - 2] != 0x91)
-		goto error;
+	if ((response[len - 2] != 0x90 && response[len - 2] != 0x91) ||
+			(response[len - 2] == 0x90 && response[len - 1] != 0)) {
+		memset(&error, 0, sizeof(error));
 
-	if (response[len - 2] == 0x90 && response[len - 1] != 0)
-		goto error;
+		error.type = OFONO_ERROR_TYPE_SIM;
+		error.error = (response[len - 2] << 8) | response[len - 1];
+	}
 
 	DBG("csim_terminal_response_cb: %i", len);
 
-- 
1.7.1.86.g0e460.dirty


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

* [PATCH 06/14] stk: Handle ENVELOPEs in a queue, retry on sim busy.
  2010-07-06 22:38 [PATCH 00/14][RESEND] STK patches without agent Andrzej Zaborowski
                   ` (4 preceding siblings ...)
  2010-07-06 22:39 ` [PATCH 05/14] atmodem: Make sim operations return sim error codes Andrzej Zaborowski
@ 2010-07-06 22:39 ` Andrzej Zaborowski
  2010-07-06 22:39 ` [PATCH 07/14] Add __ofono_sms_submit for other atoms to submit SMs Andrzej Zaborowski
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Andrzej Zaborowski @ 2010-07-06 22:39 UTC (permalink / raw)
  To: ofono

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

Some envelope types need to be retried when sim reports busy status.
Then envelopes such as Event Download need to be returned in the
order of the event occurences, so need to be handled in a queue.
---
 src/stk.c |   91 +++++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 77 insertions(+), 14 deletions(-)

diff --git a/src/stk.c b/src/stk.c
index ba66fe2..b4b65c1 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -46,8 +46,21 @@ struct ofono_stk {
 	struct stk_command *pending_cmd;
 	void (*cancel_cmd)(struct ofono_stk *stk);
 	gboolean cancelled;
+	GQueue *envelope_q;
 };
 
+struct envelope_op {
+	uint8_t tlv[256];
+	unsigned int tlv_len;
+	int retries;
+	void (*cb)(struct ofono_stk *stk, gboolean ok,
+			const unsigned char *data, int length);
+};
+
+#define ENVELOPE_RETRIES_DEFAULT 5
+
+static void envelope_queue_run(struct ofono_stk *stk);
+
 static int stk_respond(struct ofono_stk *stk, struct stk_response *rsp,
 			ofono_stk_generic_cb_t cb)
 {
@@ -75,35 +88,80 @@ static int stk_respond(struct ofono_stk *stk, struct stk_response *rsp,
 	return 0;
 }
 
+static void envelope_cb(const struct ofono_error *error, const uint8_t *data,
+			int length, void *user_data)
+{
+	struct ofono_stk *stk = user_data;
+	struct envelope_op *op = g_queue_peek_head(stk->envelope_q);
+	gboolean result = TRUE;
+
+	if (op->retries > 0 && error->type == OFONO_ERROR_TYPE_SIM &&
+			error->error == 0x9300) {
+		op->retries--;
+		goto out;
+	}
+
+	if (error->type != OFONO_ERROR_TYPE_NO_ERROR)
+		result = FALSE;
+
+	g_queue_pop_head(stk->envelope_q);
+
+	if (op->cb)
+		op->cb(stk, result, data, length);
+
+	g_free(op);
+
+out:
+	envelope_queue_run(stk);
+}
+
+static void envelope_queue_run(struct ofono_stk *stk)
+{
+	while (g_queue_get_length(stk->envelope_q) > 0) {
+		struct envelope_op *op = g_queue_peek_head(stk->envelope_q);
+
+		stk->driver->envelope(stk, op->tlv_len, op->tlv,
+				envelope_cb, stk);
+	}
+}
+
 static int stk_send_envelope(struct ofono_stk *stk, struct stk_envelope *e,
-				ofono_stk_envelope_cb_t cb)
+				void (*cb)(struct ofono_stk *stk, gboolean ok,
+						const uint8_t *data,
+						int length), int retries)
 {
-	const guint8 *tlv;
+	const uint8_t *tlv;
 	unsigned int tlv_len;
+	struct envelope_op *op;
 
 	if (stk->driver->envelope == NULL)
 		return -ENOSYS;
 
 	e->dst = STK_DEVICE_IDENTITY_TYPE_UICC;
-
 	tlv = stk_pdu_from_envelope(e, &tlv_len);
 	if (!tlv)
 		return -EINVAL;
 
-	stk->driver->envelope(stk, tlv_len, tlv, cb, stk);
+	op = g_new0(struct envelope_op, 1);
+
+	op->cb = cb;
+	op->retries = retries;
+	memcpy(op->tlv, tlv, tlv_len);
+	op->tlv_len = tlv_len;
+
+	g_queue_push_tail(stk->envelope_q, op);
+
+	if (g_queue_get_length(stk->envelope_q) == 1)
+		envelope_queue_run(stk);
 
 	return 0;
 }
 
-static void stk_cbs_download_cb(const struct ofono_error *error,
-				const unsigned char *data, int len, void *user)
+static void stk_cbs_download_cb(struct ofono_stk *stk, gboolean ok,
+				const unsigned char *data, int len)
 {
-	if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
+	if (!ok) {
 		ofono_error("CellBroadcast download to UICC failed");
-		/*
-		 * "The ME may retry to deliver the same Cell Broadcast
-		 * page."
-		 */
 		return;
 	}
 
@@ -116,7 +174,6 @@ static void stk_cbs_download_cb(const struct ofono_error *error,
 
 void __ofono_cbs_sim_download(struct ofono_stk *stk, const struct cbs *msg)
 {
-	struct ofono_error error = { .type = OFONO_ERROR_TYPE_FAILURE };
 	struct stk_envelope e;
 	int err;
 
@@ -126,9 +183,10 @@ void __ofono_cbs_sim_download(struct ofono_stk *stk, const struct cbs *msg)
 	e.src = STK_DEVICE_IDENTITY_TYPE_NETWORK;
 	memcpy(&e.cbs_pp_download.page, msg, sizeof(msg));
 
-	err = stk_send_envelope(stk, &e, stk_cbs_download_cb);
+	err = stk_send_envelope(stk, &e, stk_cbs_download_cb,
+				ENVELOPE_RETRIES_DEFAULT);
 	if (err)
-		stk_cbs_download_cb(&error, NULL, -1, stk);
+		stk_cbs_download_cb(stk, FALSE, NULL, -1);
 }
 
 static void stk_command_cb(const struct ofono_error *error, void *data)
@@ -281,6 +339,9 @@ static void stk_unregister(struct ofono_atom *atom)
 		stk_command_free(stk->pending_cmd);
 		stk->pending_cmd = NULL;
 	}
+
+	g_queue_foreach(stk->envelope_q, (GFunc) g_free, NULL);
+	g_queue_free(stk->envelope_q);
 }
 
 static void stk_remove(struct ofono_atom *atom)
@@ -336,6 +397,8 @@ struct ofono_stk *ofono_stk_create(struct ofono_modem *modem,
 void ofono_stk_register(struct ofono_stk *stk)
 {
 	__ofono_atom_register(stk->atom, stk_unregister);
+
+	stk->envelope_q = g_queue_new();
 }
 
 void ofono_stk_remove(struct ofono_stk *stk)
-- 
1.7.1.86.g0e460.dirty


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

* [PATCH 07/14] Add __ofono_sms_submit for other atoms to submit SMs.
  2010-07-06 22:38 [PATCH 00/14][RESEND] STK patches without agent Andrzej Zaborowski
                   ` (5 preceding siblings ...)
  2010-07-06 22:39 ` [PATCH 06/14] stk: Handle ENVELOPEs in a queue, retry on sim busy Andrzej Zaborowski
@ 2010-07-06 22:39 ` Andrzej Zaborowski
  2010-07-06 22:39 ` [PATCH 08/14] stk: Handle the Send SMS proactive command Andrzej Zaborowski
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Andrzej Zaborowski @ 2010-07-06 22:39 UTC (permalink / raw)
  To: ofono

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

---
 src/ofono.h |    7 ++++++-
 src/sms.c   |   39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletions(-)

diff --git a/src/ofono.h b/src/ofono.h
index e2271e6..94e2715 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -168,12 +168,17 @@ void __ofono_atom_free(struct ofono_atom *atom);
 #include <ofono/cbs.h>
 #include <ofono/devinfo.h>
 #include <ofono/phonebook.h>
-#include <ofono/sms.h>
 #include <ofono/voicecall.h>
 #include <ofono/gprs.h>
 #include <ofono/gprs-context.h>
 #include <ofono/radio-settings.h>
 
+#include <ofono/sms.h>
+
+struct sms;
+void __ofono_sms_submit(struct ofono_sms *sms, const struct sms *msg,
+			ofono_sms_submit_cb_t cb, void *data);
+
 #include <ofono/sim.h>
 #include <ofono/stk.h>
 
diff --git a/src/sms.c b/src/sms.c
index c848007..54c46a5 100644
--- a/src/sms.c
+++ b/src/sms.c
@@ -87,6 +87,8 @@ struct tx_queue_entry {
 	DBusMessage *msg;
 	gboolean status_report;
 	struct sms_address receiver;
+	ofono_sms_submit_cb_t cb;
+	void *data;
 };
 
 static const char *sms_bearer_to_string(int bearer)
@@ -413,6 +415,9 @@ static void tx_finished(const struct ofono_error *error, int mr, void *data)
 	DBG("tx_finished");
 
 	if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
+		if (entry->cb)
+			goto callback;
+
 		entry->retry += 1;
 
 		if (entry->retry != TXQ_MAX_RETRIES) {
@@ -459,6 +464,9 @@ static void tx_finished(const struct ofono_error *error, int mr, void *data)
 		return;
 	}
 
+	if (entry->cb)
+		goto callback;
+
 	entry = g_queue_pop_head(sms->txq);
 	__ofono_dbus_pending_reply(&entry->msg,
 				dbus_message_new_method_return(entry->msg));
@@ -473,6 +481,19 @@ static void tx_finished(const struct ofono_error *error, int mr, void *data)
 		DBG("Scheduling next");
 		sms->tx_source = g_timeout_add(0, tx_next, sms);
 	}
+
+	return;
+
+callback:
+	entry = g_queue_pop_head(sms->txq);
+
+	entry->cb(error, mr, entry->data);
+
+	g_free(entry->pdus);
+	g_free(entry);
+
+	if (g_queue_peek_head(sms->txq))
+		sms->tx_source = g_timeout_add(0, tx_next, sms);
 }
 
 static gboolean tx_next(gpointer user_data)
@@ -1285,3 +1306,21 @@ void *ofono_sms_get_data(struct ofono_sms *sms)
 {
 	return sms->driver_data;
 }
+
+void __ofono_sms_submit(struct ofono_sms *sms, const struct sms *msg,
+			ofono_sms_submit_cb_t cb, void *data)
+{
+	GSList msg_list = {
+		.data = (void *) msg,
+		.next = NULL,
+	};
+	struct tx_queue_entry *entry = create_tx_queue_entry(&msg_list);
+
+	entry->cb = cb;
+	entry->data = data;
+
+	g_queue_push_tail(sms->txq, entry);
+
+	if (g_queue_get_length(sms->txq) == 1)
+		sms->tx_source = g_timeout_add(0, tx_next, sms);
+}
-- 
1.7.1.86.g0e460.dirty


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

* [PATCH 08/14] stk: Handle the Send SMS proactive command.
  2010-07-06 22:38 [PATCH 00/14][RESEND] STK patches without agent Andrzej Zaborowski
                   ` (6 preceding siblings ...)
  2010-07-06 22:39 ` [PATCH 07/14] Add __ofono_sms_submit for other atoms to submit SMs Andrzej Zaborowski
@ 2010-07-06 22:39 ` Andrzej Zaborowski
  2010-07-06 22:39 ` [PATCH 09/14] Add Dbus interface names for STK Andrzej Zaborowski
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Andrzej Zaborowski @ 2010-07-06 22:39 UTC (permalink / raw)
  To: ofono

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

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

diff --git a/src/stk.c b/src/stk.c
index b4b65c1..a57342a 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -34,6 +34,7 @@
 
 #include "ofono.h"
 
+#include "common.h"
 #include "smsutil.h"
 #include "stkutil.h"
 
@@ -47,6 +48,8 @@ struct ofono_stk {
 	void (*cancel_cmd)(struct ofono_stk *stk);
 	gboolean cancelled;
 	GQueue *envelope_q;
+
+	struct sms_submit_req *sms_submit_req;
 };
 
 struct envelope_op {
@@ -57,6 +60,11 @@ struct envelope_op {
 			const unsigned char *data, int length);
 };
 
+struct sms_submit_req {
+	struct ofono_stk *stk;
+	gboolean cancelled;
+};
+
 #define ENVELOPE_RETRIES_DEFAULT 5
 
 static void envelope_queue_run(struct ofono_stk *stk);
@@ -201,6 +209,16 @@ static void stk_command_cb(const struct ofono_error *error, void *data)
 	DBG("TERMINAL RESPONSE to a command reported no errors");
 }
 
+static void stk_alpha_id_set(struct ofono_stk *stk, const char *text)
+{
+	/* TODO */
+}
+
+static void stk_alpha_id_unset(struct ofono_stk *stk)
+{
+	/* TODO */
+}
+
 static gboolean handle_command_more_time(const struct stk_command *cmd,
 						struct stk_response *rsp,
 						struct ofono_stk *stk)
@@ -210,6 +228,88 @@ static gboolean handle_command_more_time(const struct stk_command *cmd,
 	return TRUE;
 }
 
+static void send_sms_cancel(struct ofono_stk *stk)
+{
+	stk->sms_submit_req->cancelled = TRUE;
+
+	if (!stk->pending_cmd->send_sms.alpha_id ||
+			!stk->pending_cmd->send_sms.alpha_id[0])
+		return;
+
+	stk_alpha_id_unset(stk);
+}
+
+static void send_sms_submit_cb(const struct ofono_error *error, int mr,
+				void *data)
+{
+	struct stk_response rsp;
+	struct sms_submit_req *req = data;
+	struct ofono_stk *stk = req->stk;
+	struct ofono_error failure = { .type = OFONO_ERROR_TYPE_FAILURE };
+
+	if (error->type != OFONO_ERROR_TYPE_NO_ERROR)
+		ofono_debug("SMS submission returned errors: %s",
+				telephony_error_to_str(error));
+	else
+		ofono_debug("SMS submission successful");
+
+	if (req->cancelled) {
+		ofono_debug("Received an SMS submitted callback after the "
+				"proactive command was cancelled");
+		goto out;
+	}
+
+	memset(&rsp, 0, sizeof(rsp));
+
+	if (error->type != OFONO_ERROR_TYPE_NO_ERROR)
+		rsp.result.type = STK_RESULT_TYPE_NETWORK_UNAVAILABLE;
+
+	if (stk_respond(stk, &rsp, stk_command_cb))
+		stk_command_cb(&failure, stk);
+
+	if (!stk->pending_cmd->send_sms.alpha_id ||
+			!stk->pending_cmd->send_sms.alpha_id[0])
+		goto out;
+
+	stk_alpha_id_unset(stk);
+
+out:
+	g_free(req);
+}
+
+static gboolean handle_command_send_sms(const struct stk_command *cmd,
+					struct stk_response *rsp,
+					struct ofono_stk *stk)
+{
+	struct ofono_modem *modem = __ofono_atom_get_modem(stk->atom);
+	struct ofono_atom *sms_atom;
+	struct ofono_sms *sms;
+
+	sms_atom = __ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_SMS);
+
+	if (!sms_atom || !__ofono_atom_get_registered(sms_atom)) {
+		rsp->result.type = STK_RESULT_TYPE_NOT_CAPABLE;
+		return TRUE;
+	}
+
+	sms = __ofono_atom_get_data(sms_atom);
+
+	stk->sms_submit_req = g_new0(struct sms_submit_req, 1);
+	stk->sms_submit_req->stk = stk;
+
+	__ofono_sms_submit(sms, &cmd->send_sms.gsm_sms,
+				send_sms_submit_cb, stk->sms_submit_req);
+
+	stk->cancel_cmd = send_sms_cancel;
+
+	if (!cmd->send_sms.alpha_id || !cmd->send_sms.alpha_id[0])
+		return FALSE;
+
+	stk_alpha_id_set(stk, cmd->send_sms.alpha_id);
+
+	return FALSE;
+}
+
 static void stk_proactive_command_cancel(struct ofono_stk *stk)
 {
 	if (!stk->pending_cmd)
@@ -284,6 +384,10 @@ void ofono_stk_proactive_command_notify(struct ofono_stk *stk,
 			respond = handle_command_more_time(stk->pending_cmd,
 								&rsp, stk);
 			break;
+		case STK_COMMAND_TYPE_SEND_SMS:
+			respond = handle_command_send_sms(stk->pending_cmd,
+								&rsp, stk);
+			break;
 		}
 
 		if (respond)
-- 
1.7.1.86.g0e460.dirty


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

* [PATCH 09/14] Add Dbus interface names for STK.
  2010-07-06 22:38 [PATCH 00/14][RESEND] STK patches without agent Andrzej Zaborowski
                   ` (7 preceding siblings ...)
  2010-07-06 22:39 ` [PATCH 08/14] stk: Handle the Send SMS proactive command Andrzej Zaborowski
@ 2010-07-06 22:39 ` Andrzej Zaborowski
  2010-07-06 22:39 ` [PATCH 10/14] stk: Handle the Set Up Idle Text proactive command Andrzej Zaborowski
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Andrzej Zaborowski @ 2010-07-06 22:39 UTC (permalink / raw)
  To: ofono

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

---
 include/dbus.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/include/dbus.h b/include/dbus.h
index d988760..d959754 100644
--- a/include/dbus.h
+++ b/include/dbus.h
@@ -49,6 +49,8 @@ extern "C" {
 #define OFONO_VOICECALL_MANAGER_INTERFACE "org.ofono.VoiceCallManager"
 #define OFONO_DATA_CONNECTION_MANAGER_INTERFACE "org.ofono.DataConnectionManager"
 #define OFONO_DATA_CONTEXT_INTERFACE "org.ofono.PrimaryDataContext"
+#define OFONO_STK_INTERFACE OFONO_SERVICE ".SimToolkit"
+#define OFONO_SIM_APP_INTERFACE OFONO_SERVICE ".SimApplicationAgent"
 
 /* Essentially a{sv} */
 #define OFONO_PROPERTIES_ARRAY_SIGNATURE DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING \
-- 
1.7.1.86.g0e460.dirty


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

* [PATCH 10/14] stk: Handle the Set Up Idle Text proactive command.
  2010-07-06 22:38 [PATCH 00/14][RESEND] STK patches without agent Andrzej Zaborowski
                   ` (8 preceding siblings ...)
  2010-07-06 22:39 ` [PATCH 09/14] Add Dbus interface names for STK Andrzej Zaborowski
@ 2010-07-06 22:39 ` Andrzej Zaborowski
  2010-07-06 22:39 ` [PATCH 11/14] sktutil: Use the Mandatory flag in parse_dataobj Andrzej Zaborowski
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Andrzej Zaborowski @ 2010-07-06 22:39 UTC (permalink / raw)
  To: ofono

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

This adds a SimToolkit dbus interface with just one property
(IdleModeText).
---
 src/stk.c |   98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 98 insertions(+), 0 deletions(-)

diff --git a/src/stk.c b/src/stk.c
index a57342a..940c65d 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -50,6 +50,7 @@ struct ofono_stk {
 	GQueue *envelope_q;
 
 	struct sms_submit_req *sms_submit_req;
+	char *idle_mode_text;
 };
 
 struct envelope_op {
@@ -219,6 +220,45 @@ static void stk_alpha_id_unset(struct ofono_stk *stk)
 	/* TODO */
 }
 
+static DBusMessage *stk_get_properties(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	struct ofono_stk *stk = data;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+	DBusMessageIter dict;
+	const char *idle_mode_text = stk->idle_mode_text ?: "";
+
+	reply = dbus_message_new_method_return(msg);
+	if (!reply)
+		return NULL;
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+					OFONO_PROPERTIES_ARRAY_SIGNATURE,
+					&dict);
+
+	ofono_dbus_dict_append(&dict, "IdleModeText",
+				DBUS_TYPE_STRING, &idle_mode_text);
+
+	dbus_message_iter_close_container(&iter, &dict);
+
+	return reply;
+}
+
+static GDBusMethodTable stk_methods[] = {
+	{ "GetProperties",		"",	"a{sv}",stk_get_properties },
+
+	{ }
+};
+
+static GDBusSignalTable stk_signals[] = {
+	{ "PropertyChanged",	"sv" },
+
+	{ }
+};
+
 static gboolean handle_command_more_time(const struct stk_command *cmd,
 						struct stk_response *rsp,
 						struct ofono_stk *stk)
@@ -310,6 +350,34 @@ static gboolean handle_command_send_sms(const struct stk_command *cmd,
 	return FALSE;
 }
 
+static gboolean handle_command_set_idle_text(const struct stk_command *cmd,
+						struct stk_response *rsp,
+						struct ofono_stk *stk)
+{
+	const char *idle_mode_text;
+	DBusConnection *conn = ofono_dbus_get_connection();
+	const char *path = __ofono_atom_get_path(stk->atom);
+
+	if (stk->idle_mode_text) {
+		g_free(stk->idle_mode_text);
+		stk->idle_mode_text = NULL;
+	}
+
+	if (!cmd->setup_idle_mode_text.text)
+		goto out;
+
+	stk->idle_mode_text = g_strdup(cmd->setup_idle_mode_text.text);
+
+out:
+	idle_mode_text = stk->idle_mode_text ?: "";
+	ofono_dbus_signal_property_changed(conn, path, OFONO_STK_INTERFACE,
+						"IdleModeText",
+						DBUS_TYPE_STRING,
+						&idle_mode_text);
+
+	return TRUE;
+}
+
 static void stk_proactive_command_cancel(struct ofono_stk *stk)
 {
 	if (!stk->pending_cmd)
@@ -388,6 +456,10 @@ void ofono_stk_proactive_command_notify(struct ofono_stk *stk,
 			respond = handle_command_send_sms(stk->pending_cmd,
 								&rsp, stk);
 			break;
+		case STK_COMMAND_TYPE_SETUP_IDLE_MODE_TEXT:
+			respond = handle_command_set_idle_text(stk->pending_cmd,
+								&rsp, stk);
+			break;
 		}
 
 		if (respond)
@@ -438,14 +510,25 @@ void ofono_stk_driver_unregister(const struct ofono_stk_driver *d)
 static void stk_unregister(struct ofono_atom *atom)
 {
 	struct ofono_stk *stk = __ofono_atom_get_data(atom);
+	DBusConnection *conn = ofono_dbus_get_connection();
+	struct ofono_modem *modem = __ofono_atom_get_modem(atom);
+	const char *path = __ofono_atom_get_path(atom);
 
 	if (stk->pending_cmd) {
 		stk_command_free(stk->pending_cmd);
 		stk->pending_cmd = NULL;
 	}
 
+	if (stk->idle_mode_text) {
+		g_free(stk->idle_mode_text);
+		stk->idle_mode_text = NULL;
+	}
+
 	g_queue_foreach(stk->envelope_q, (GFunc) g_free, NULL);
 	g_queue_free(stk->envelope_q);
+
+	ofono_modem_remove_interface(modem, OFONO_STK_INTERFACE);
+	g_dbus_unregister_interface(conn, path, OFONO_STK_INTERFACE);
 }
 
 static void stk_remove(struct ofono_atom *atom)
@@ -500,6 +583,21 @@ struct ofono_stk *ofono_stk_create(struct ofono_modem *modem,
 
 void ofono_stk_register(struct ofono_stk *stk)
 {
+	DBusConnection *conn = ofono_dbus_get_connection();
+	struct ofono_modem *modem = __ofono_atom_get_modem(stk->atom);
+	const char *path = __ofono_atom_get_path(stk->atom);
+
+	if (!g_dbus_register_interface(conn, path, OFONO_STK_INTERFACE,
+					stk_methods, stk_signals, NULL,
+					stk, NULL)) {
+		ofono_error("Could not create %s interface",
+				OFONO_STK_INTERFACE);
+
+		return;
+	}
+
+	ofono_modem_add_interface(modem, OFONO_STK_INTERFACE);
+
 	__ofono_atom_register(stk->atom, stk_unregister);
 
 	stk->envelope_q = g_queue_new();
-- 
1.7.1.86.g0e460.dirty


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

* [PATCH 11/14] sktutil: Use the Mandatory flag in parse_dataobj.
  2010-07-06 22:38 [PATCH 00/14][RESEND] STK patches without agent Andrzej Zaborowski
                   ` (9 preceding siblings ...)
  2010-07-06 22:39 ` [PATCH 10/14] stk: Handle the Set Up Idle Text proactive command Andrzej Zaborowski
@ 2010-07-06 22:39 ` Andrzej Zaborowski
  2010-07-06 22:39 ` [PATCH 12/14] stkutil: Timer Value is conditional, not optional Andrzej Zaborowski
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Andrzej Zaborowski @ 2010-07-06 22:39 UTC (permalink / raw)
  To: ofono

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

We need to look at the Mandatory flag and not at the Minimum flag
when parsing CTLVs.  The Minimum flag is important when encoding CTLVs
because CR bit is set according to it.
---
 src/stkutil.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/stkutil.c b/src/stkutil.c
index e92add3..d2cd126 100644
--- a/src/stkutil.c
+++ b/src/stkutil.c
@@ -2324,8 +2324,8 @@ static enum stk_command_parse_result parse_dataobj(
 			if (comprehension_tlv_iter_get_tag(iter) == entry->type)
 				break;
 
-			/* Can't skip over Minimum objects */
-			if (entry->flags & DATAOBJ_FLAG_MINIMUM) {
+			/* Can't skip over mandatory objects */
+			if (entry->flags & DATAOBJ_FLAG_MANDATORY) {
 				l2 = NULL;
 				break;
 			}
@@ -2352,7 +2352,7 @@ static enum stk_command_parse_result parse_dataobj(
 	for (; l; l = l->next) {
 		struct dataobj_handler_entry *entry = l->data;
 
-		if (entry->flags & DATAOBJ_FLAG_MINIMUM)
+		if (entry->flags & DATAOBJ_FLAG_MANDATORY)
 			minimum_set = FALSE;
 	}
 
-- 
1.7.1.86.g0e460.dirty


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

* [PATCH 12/14] stkutil: Timer Value is conditional, not optional.
  2010-07-06 22:38 [PATCH 00/14][RESEND] STK patches without agent Andrzej Zaborowski
                   ` (10 preceding siblings ...)
  2010-07-06 22:39 ` [PATCH 11/14] sktutil: Use the Mandatory flag in parse_dataobj Andrzej Zaborowski
@ 2010-07-06 22:39 ` Andrzej Zaborowski
  2010-07-06 22:39 ` [PATCH 13/14] stk: Handle the Timer Management proactive command Andrzej Zaborowski
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 18+ messages in thread
From: Andrzej Zaborowski @ 2010-07-06 22:39 UTC (permalink / raw)
  To: ofono

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

Make the parser check that the value is present when necessary,
so that stk.c doesn't have to check this.
---
 src/stkutil.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/src/stkutil.c b/src/stkutil.c
index d2cd126..94ff182 100644
--- a/src/stkutil.c
+++ b/src/stkutil.c
@@ -3000,6 +3000,7 @@ static enum stk_command_parse_result parse_timer_mgmt(
 					struct comprehension_tlv_iter *iter)
 {
 	struct stk_command_timer_mgmt *obj = &command->timer_mgmt;
+	enum stk_data_object_flag value_flags = 0;
 
 	if (command->src != STK_DEVICE_IDENTITY_TYPE_UICC)
 		return STK_PARSE_RESULT_DATA_NOT_UNDERSTOOD;
@@ -3007,10 +3008,13 @@ static enum stk_command_parse_result parse_timer_mgmt(
 	if (command->dst != STK_DEVICE_IDENTITY_TYPE_TERMINAL)
 		return STK_PARSE_RESULT_DATA_NOT_UNDERSTOOD;
 
+	if ((command->qualifier & 3) == 0) /* Start a timer */
+		value_flags = DATAOBJ_FLAG_MANDATORY;
+
 	return parse_dataobj(iter, STK_DATA_OBJECT_TYPE_TIMER_ID,
 				DATAOBJ_FLAG_MANDATORY | DATAOBJ_FLAG_MINIMUM,
 				&obj->timer_id,
-				STK_DATA_OBJECT_TYPE_TIMER_VALUE, 0,
+				STK_DATA_OBJECT_TYPE_TIMER_VALUE, value_flags,
 				&obj->timer_value,
 				STK_DATA_OBJECT_TYPE_INVALID);
 }
-- 
1.7.1.86.g0e460.dirty


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

* [PATCH 13/14] stk: Handle the Timer Management proactive command.
  2010-07-06 22:38 [PATCH 00/14][RESEND] STK patches without agent Andrzej Zaborowski
                   ` (11 preceding siblings ...)
  2010-07-06 22:39 ` [PATCH 12/14] stkutil: Timer Value is conditional, not optional Andrzej Zaborowski
@ 2010-07-06 22:39 ` Andrzej Zaborowski
  2010-07-06 22:39 ` [PATCH 14/14] stk: Handle the Poll Interval " Andrzej Zaborowski
  2010-07-08 19:28 ` [PATCH 00/14][RESEND] STK patches without agent Denis Kenzior
  14 siblings, 0 replies; 18+ messages in thread
From: Andrzej Zaborowski @ 2010-07-06 22:39 UTC (permalink / raw)
  To: ofono

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

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

diff --git a/src/stk.c b/src/stk.c
index 940c65d..6edce2c 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -31,6 +31,7 @@
 #include <glib.h>
 #include <gdbus.h>
 #include <errno.h>
+#include <time.h>
 
 #include "ofono.h"
 
@@ -40,6 +41,11 @@
 
 static GSList *g_drivers = NULL;
 
+struct stk_timer {
+	time_t expiry;
+	time_t start;
+};
+
 struct ofono_stk {
 	const struct ofono_stk_driver *driver;
 	void *driver_data;
@@ -49,6 +55,9 @@ struct ofono_stk {
 	gboolean cancelled;
 	GQueue *envelope_q;
 
+	struct stk_timer timers[8];
+	guint timers_source;
+
 	struct sms_submit_req *sms_submit_req;
 	char *idle_mode_text;
 };
@@ -69,6 +78,7 @@ struct sms_submit_req {
 #define ENVELOPE_RETRIES_DEFAULT 5
 
 static void envelope_queue_run(struct ofono_stk *stk);
+static void timers_update(struct ofono_stk *stk);
 
 static int stk_respond(struct ofono_stk *stk, struct stk_response *rsp,
 			ofono_stk_generic_cb_t cb)
@@ -378,6 +388,152 @@ out:
 	return TRUE;
 }
 
+static void timer_expiration_cb(struct ofono_stk *stk, gboolean ok,
+				const unsigned char *data, int len)
+{
+	if (!ok) {
+		ofono_error("Timer Expiration reporting failed");
+		return;
+	}
+
+	if (len)
+		ofono_error("Timer Expiration returned %i bytes of data",
+				len);
+
+	DBG("Timer Expiration reporting to UICC reported no error");
+}
+
+static gboolean timers_cb(gpointer user_data)
+{
+	struct ofono_stk *stk = user_data;
+
+	stk->timers_source = 0;
+
+	timers_update(stk);
+
+	return FALSE;
+}
+
+static void timer_value_from_seconds(struct stk_timer_value *val, int seconds)
+{
+	val->has_value = TRUE;
+	val->hour = seconds / 3600;
+	seconds -= val->hour * 3600;
+	val->minute = seconds / 60;
+	seconds -= val->minute * 60;
+	val->second = seconds;
+}
+
+static void timers_update(struct ofono_stk *stk)
+{
+	time_t min = 0, now = time(NULL);
+	int i;
+
+	if (stk->timers_source) {
+		g_source_remove(stk->timers_source);
+		stk->timers_source = 0;
+	}
+
+	for (i = 0; i < 8; i++) {
+		if (!stk->timers[i].expiry)
+			continue;
+
+		if (stk->timers[i].expiry <= now) {
+			struct stk_envelope e;
+			int seconds = now - stk->timers[i].start;
+
+			stk->timers[i].expiry = 0;
+
+			memset(&e, 0, sizeof(e));
+
+			e.type = STK_ENVELOPE_TYPE_TIMER_EXPIRATION;
+			e.src = STK_DEVICE_IDENTITY_TYPE_TERMINAL,
+			e.timer_expiration.id = i + 1;
+			timer_value_from_seconds(&e.timer_expiration.value,
+							seconds);
+
+			/*
+			 * TODO: resubmit until success, providing current
+			 * time difference every time we re-send.
+			 */
+			if (stk_send_envelope(stk, &e, timer_expiration_cb, 0))
+				timer_expiration_cb(stk, FALSE, NULL, -1);
+
+			continue;
+		}
+
+		if (stk->timers[i].expiry < now + min || min == 0)
+			min = stk->timers[i].expiry - now;
+	}
+
+	if (min)
+		stk->timers_source = g_timeout_add_seconds(min, timers_cb, stk);
+}
+
+static gboolean handle_command_timer_mgmt(const struct stk_command *cmd,
+						struct stk_response *rsp,
+						struct ofono_stk *stk)
+{
+	int op = cmd->qualifier & 3;
+	time_t seconds, now = time(NULL);
+	struct stk_timer *tmr;
+
+	if (cmd->timer_mgmt.timer_id < 1 || cmd->timer_mgmt.timer_id > 8) {
+		rsp->result.type = STK_RESULT_TYPE_DATA_NOT_UNDERSTOOD;
+		return TRUE;
+	}
+
+	tmr = &stk->timers[cmd->timer_mgmt.timer_id - 1];
+
+	switch (op) {
+	case 0: /* Start */
+		seconds = cmd->timer_mgmt.timer_value.second +
+			cmd->timer_mgmt.timer_value.minute * 60 +
+			cmd->timer_mgmt.timer_value.hour * 3600;
+
+		tmr->expiry = now + seconds;
+		tmr->start = now;
+
+		timers_update(stk);
+		break;
+
+	case 1: /* Deactivate */
+		if (!tmr->expiry) {
+			rsp->result.type = STK_RESULT_TYPE_TIMER_CONFLICT;
+
+			return TRUE;
+		}
+
+		seconds = MAX(0, tmr->expiry - now);
+		tmr->expiry = 0;
+
+		timers_update(stk);
+
+		timer_value_from_seconds(&rsp->timer_mgmt.value, seconds);
+		break;
+
+	case 2: /* Get current value */
+		if (!tmr->expiry) {
+			rsp->result.type = STK_RESULT_TYPE_TIMER_CONFLICT;
+
+			return TRUE;
+		}
+
+		seconds = MAX(0, tmr->expiry - now);
+		timer_value_from_seconds(&rsp->timer_mgmt.value, seconds);
+		break;
+
+	default:
+		rsp->result.type = STK_RESULT_TYPE_DATA_NOT_UNDERSTOOD;
+
+		return TRUE;
+	}
+
+	rsp->timer_mgmt.id = cmd->timer_mgmt.timer_id;
+
+	return TRUE;
+}
+
 static void stk_proactive_command_cancel(struct ofono_stk *stk)
 {
 	if (!stk->pending_cmd)
@@ -460,6 +616,10 @@ void ofono_stk_proactive_command_notify(struct ofono_stk *stk,
 			respond = handle_command_set_idle_text(stk->pending_cmd,
 								&rsp, stk);
 			break;
+		case STK_COMMAND_TYPE_TIMER_MANAGEMENT:
+			respond = handle_command_timer_mgmt(stk->pending_cmd,
+								&rsp, stk);
+			break;
 		}
 
 		if (respond)
@@ -524,6 +684,11 @@ static void stk_unregister(struct ofono_atom *atom)
 		stk->idle_mode_text = NULL;
 	}
 
+	if (stk->timers_source) {
+		g_source_remove(stk->timers_source);
+		stk->timers_source = 0;
+	}
+
 	g_queue_foreach(stk->envelope_q, (GFunc) g_free, NULL);
 	g_queue_free(stk->envelope_q);
 
-- 
1.7.1.86.g0e460.dirty


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

* [PATCH 14/14] stk: Handle the Poll Interval proactive command.
  2010-07-06 22:38 [PATCH 00/14][RESEND] STK patches without agent Andrzej Zaborowski
                   ` (12 preceding siblings ...)
  2010-07-06 22:39 ` [PATCH 13/14] stk: Handle the Timer Management proactive command Andrzej Zaborowski
@ 2010-07-06 22:39 ` Andrzej Zaborowski
  2010-07-08 19:28 ` [PATCH 00/14][RESEND] STK patches without agent Denis Kenzior
  14 siblings, 0 replies; 18+ messages in thread
From: Andrzej Zaborowski @ 2010-07-06 22:39 UTC (permalink / raw)
  To: ofono

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

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

diff --git a/src/stk.c b/src/stk.c
index 6edce2c..e77c723 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -534,6 +534,47 @@ static gboolean handle_command_timer_mgmt(const struct stk_command *cmd,
 	return TRUE;
 }
 
+static gboolean handle_command_poll_interval(const struct stk_command *cmd,
+						struct stk_response *rsp,
+						struct ofono_stk *stk)
+{
+	struct ofono_modem *modem = __ofono_atom_get_modem(stk->atom);
+	int seconds;
+
+	switch (cmd->poll_interval.duration.unit) {
+	case STK_DURATION_TYPE_MINUTES:
+		seconds = cmd->poll_interval.duration.interval * 60;
+		break;
+	case STK_DURATION_TYPE_SECONDS:
+		seconds = cmd->poll_interval.duration.interval;
+		break;
+	case STK_DURATION_TYPE_SECOND_TENTHS:
+		seconds = (4 + cmd->poll_interval.duration.interval) / 10;
+		if (seconds < 1)
+			seconds = 1;
+		break;
+	}
+
+	if (ofono_modem_set_integer(modem, "status-poll-interval", seconds)) {
+		seconds = ofono_modem_get_integer(modem,
+							"status-poll-interval");
+		if (!seconds)
+			seconds = 30;
+	}
+
+	if (seconds > 255) {
+		rsp->poll_interval.max_interval.unit =
+			STK_DURATION_TYPE_MINUTES;
+		rsp->poll_interval.max_interval.interval = seconds / 60;
+	} else {
+		rsp->poll_interval.max_interval.unit =
+			STK_DURATION_TYPE_SECONDS;
+		rsp->poll_interval.max_interval.interval = seconds;
+	}
+
+	return TRUE;
+}
+
 static void stk_proactive_command_cancel(struct ofono_stk *stk)
 {
 	if (!stk->pending_cmd)
@@ -620,6 +661,10 @@ void ofono_stk_proactive_command_notify(struct ofono_stk *stk,
 			respond = handle_command_timer_mgmt(stk->pending_cmd,
 								&rsp, stk);
 			break;
+		case STK_COMMAND_TYPE_POLL_INTERVAL:
+			respond = handle_command_poll_interval(stk->pending_cmd,
+								&rsp, stk);
+			break;
 		}
 
 		if (respond)
-- 
1.7.1.86.g0e460.dirty


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

* Re: [PATCH 00/14][RESEND] STK patches without agent
  2010-07-06 22:38 [PATCH 00/14][RESEND] STK patches without agent Andrzej Zaborowski
                   ` (13 preceding siblings ...)
  2010-07-06 22:39 ` [PATCH 14/14] stk: Handle the Poll Interval " Andrzej Zaborowski
@ 2010-07-08 19:28 ` Denis Kenzior
  2010-07-15 20:37   ` Andrzej Zaborowski
  14 siblings, 1 reply; 18+ messages in thread
From: Denis Kenzior @ 2010-07-08 19:28 UTC (permalink / raw)
  To: ofono

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

Hi Andrew,

On 07/06/2010 05:38 PM, Andrzej Zaborowski wrote:
> These are some patches I sent before reordered and refactored to
> skip stuff related to the Agent API, i.e. related to the UI.
> 
> Andrzej Zaborowski (14):
>   stk: Utilities for proactive command/envelope handling.
>   mbmmodem: End session on *STKEND.
>   stk: Handle the More Time proactive command as a nop.
>   Add OFONO_ERROR_TYPE_SIM for negative SIM statuses.
>   atmodem: Make sim operations return sim error codes.
>   stk: Handle ENVELOPEs in a queue, retry on sim busy.
>   Add __ofono_sms_submit for other atoms to submit SMs.
>   stk: Handle the Send SMS proactive command.
>   Add Dbus interface names for STK.
>   stk: Handle the Set Up Idle Text proactive command.
>   sktutil: Use the Mandatory flag in parse_dataobj.
>   stkutil: Timer Value is conditional, not optional.
>   stk: Handle the Timer Management proactive command.
>   stk: Handle the Poll Interval proactive command.

All patches in this series have been pushed upstream with some
refactoring afterwards.  Please review and make sure I didn't screw
something up.

Regards,
-Denis

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

* Re: [PATCH 00/14][RESEND] STK patches without agent
  2010-07-08 19:28 ` [PATCH 00/14][RESEND] STK patches without agent Denis Kenzior
@ 2010-07-15 20:37   ` Andrzej Zaborowski
  2010-07-15 20:46     ` Denis Kenzior
  0 siblings, 1 reply; 18+ messages in thread
From: Andrzej Zaborowski @ 2010-07-15 20:37 UTC (permalink / raw)
  To: ofono

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

Hi,

On 8 July 2010 21:28, Denis Kenzior <denkenz@gmail.com> wrote:
> On 07/06/2010 05:38 PM, Andrzej Zaborowski wrote:
>> These are some patches I sent before reordered and refactored to
>> skip stuff related to the Agent API, i.e. related to the UI.
>>
>> Andrzej Zaborowski (14):
>>   stk: Utilities for proactive command/envelope handling.
>>   mbmmodem: End session on *STKEND.
>>   stk: Handle the More Time proactive command as a nop.
>>   Add OFONO_ERROR_TYPE_SIM for negative SIM statuses.
>>   atmodem: Make sim operations return sim error codes.
>>   stk: Handle ENVELOPEs in a queue, retry on sim busy.
>>   Add __ofono_sms_submit for other atoms to submit SMs.
>>   stk: Handle the Send SMS proactive command.
>>   Add Dbus interface names for STK.
>>   stk: Handle the Set Up Idle Text proactive command.
>>   sktutil: Use the Mandatory flag in parse_dataobj.
>>   stkutil: Timer Value is conditional, not optional.
>>   stk: Handle the Timer Management proactive command.
>>   stk: Handle the Poll Interval proactive command.
>
> All patches in this series have been pushed upstream with some
> refactoring afterwards.  Please review and make sure I didn't screw
> something up.

Thanks, just a small change to remove the seconds == 0 check for Set
Poll Interval.  Seconds can't be 0 or parsing would fail.  The logic
behind the original code was:

Try to set the modem property to "seconds".
If setting fails, then return the previous value (which is actually
the nearest value we could accept).
If getting previous value fails (function returns 0) then return 30
secs, the default value, which also happens to be the nearest we could
accept.

Best regards

[-- Attachment #2: 0003-stk-Remove-a-unneeded-check.patch --]
[-- Type: application/octet-stream, Size: 663 bytes --]

From c617d567f1c2345fdbce42080531f099a8f964dd Mon Sep 17 00:00:00 2001
From: Andrzej Zaborowski <andrew.zaborowski@intel.com>
Date: Tue, 13 Jul 2010 16:23:35 +0200
Subject: [PATCH] stk: Remove an unneeded check.

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

diff --git a/src/stk.c b/src/stk.c
index bf16169..f3d8247 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -977,9 +977,6 @@ static gboolean handle_command_poll_interval(const struct stk_command *cmd,
 		return TRUE;
 	}
 
-	if (seconds == 0)
-		seconds = 30;
-
 	ofono_modem_set_integer(modem, "status-poll-interval", seconds);
 
 	if (seconds > 255) {
-- 
1.7.1.86.g0e460.dirty


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

* Re: [PATCH 00/14][RESEND] STK patches without agent
  2010-07-15 20:37   ` Andrzej Zaborowski
@ 2010-07-15 20:46     ` Denis Kenzior
  0 siblings, 0 replies; 18+ messages in thread
From: Denis Kenzior @ 2010-07-15 20:46 UTC (permalink / raw)
  To: ofono

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

Hi Andrew,

>> All patches in this series have been pushed upstream with some
>> refactoring afterwards.  Please review and make sure I didn't screw
>> something up.
> 
> Thanks, just a small change to remove the seconds == 0 check for Set
> Poll Interval.  Seconds can't be 0 or parsing would fail.  The logic
> behind the original code was:
> 
> Try to set the modem property to "seconds".
> If setting fails, then return the previous value (which is actually
> the nearest value we could accept).
> If getting previous value fails (function returns 0) then return 30
> secs, the default value, which also happens to be the nearest we could
> accept.
> 

Thanks for catching this.  Patch has been applied.

Regards,
-Denis

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

end of thread, other threads:[~2010-07-15 20:46 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-06 22:38 [PATCH 00/14][RESEND] STK patches without agent Andrzej Zaborowski
2010-07-06 22:38 ` [PATCH 01/14] stk: Utilities for proactive command/envelope handling Andrzej Zaborowski
2010-07-06 22:38 ` [PATCH 02/14] mbmmodem: End session on *STKEND Andrzej Zaborowski
2010-07-06 22:38 ` [PATCH 03/14] stk: Handle the More Time proactive command as a nop Andrzej Zaborowski
2010-07-06 22:38 ` [PATCH 04/14] Add OFONO_ERROR_TYPE_SIM for negative SIM statuses Andrzej Zaborowski
2010-07-06 22:39 ` [PATCH 05/14] atmodem: Make sim operations return sim error codes Andrzej Zaborowski
2010-07-06 22:39 ` [PATCH 06/14] stk: Handle ENVELOPEs in a queue, retry on sim busy Andrzej Zaborowski
2010-07-06 22:39 ` [PATCH 07/14] Add __ofono_sms_submit for other atoms to submit SMs Andrzej Zaborowski
2010-07-06 22:39 ` [PATCH 08/14] stk: Handle the Send SMS proactive command Andrzej Zaborowski
2010-07-06 22:39 ` [PATCH 09/14] Add Dbus interface names for STK Andrzej Zaborowski
2010-07-06 22:39 ` [PATCH 10/14] stk: Handle the Set Up Idle Text proactive command Andrzej Zaborowski
2010-07-06 22:39 ` [PATCH 11/14] sktutil: Use the Mandatory flag in parse_dataobj Andrzej Zaborowski
2010-07-06 22:39 ` [PATCH 12/14] stkutil: Timer Value is conditional, not optional Andrzej Zaborowski
2010-07-06 22:39 ` [PATCH 13/14] stk: Handle the Timer Management proactive command Andrzej Zaborowski
2010-07-06 22:39 ` [PATCH 14/14] stk: Handle the Poll Interval " Andrzej Zaborowski
2010-07-08 19:28 ` [PATCH 00/14][RESEND] STK patches without agent Denis Kenzior
2010-07-15 20:37   ` Andrzej Zaborowski
2010-07-15 20:46     ` Denis Kenzior

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.