All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/6] stk: Handle the Get Inkey proactive command.
@ 2010-06-30 15:24 Andrzej Zaborowski
  2010-06-30 15:24 ` [PATCH 2/6] stk: Handle the Get Input " Andrzej Zaborowski
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Andrzej Zaborowski @ 2010-06-30 15:24 UTC (permalink / raw)
  To: ofono

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

The SimApplication agent method signature is:
string/Back/Terminate/Help GetKey(string message, string charset,
		bool help_available, bool single_key)

	charset is one of:
		"yesno" - response needs to be "yes" or "no"
		"digit" - one of 0-9, *, #, +
		"gsm" - only characters from the GSM SMS charset
		"any"
	single_key indicates that only characters from the device's
	key faces are allowed (e.g. no "+" allowed if device only
	has a basic keypad), and that the key should be returned
	without being shown on screen or waiting for any kind of
	user confirmation.

These patches apply on top of the previous series.
---
 src/stk.c |  160 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 159 insertions(+), 1 deletions(-)

diff --git a/src/stk.c b/src/stk.c
index ff47649..a2649b1 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -31,6 +31,7 @@
 #include <glib.h>
 #include <gdbus.h>
 #include <errno.h>
+#include <sys/time.h>
 
 #include "ofono.h"
 
@@ -64,6 +65,7 @@ enum stk_agent_state {
 	STK_AGENT_MAIN_MENU,
 	STK_AGENT_SELECT_ITEM,
 	STK_AGENT_DISPLAY_TEXT,
+	STK_AGENT_GET_KEY,
 };
 
 struct ofono_stk {
@@ -83,6 +85,7 @@ struct ofono_stk {
 
 	struct stk_menu *main_menu;
 	struct stk_menu *select_item_menu;
+	struct timeval get_inkey_start_ts;
 
 	gboolean envelope_q_busy;
 	GQueue *envelope_q;
@@ -100,6 +103,7 @@ struct envelope_op {
 #define OFONO_NAVIGATION_PREFIX OFONO_SERVICE ".Navigation."
 #define OFONO_NAVIGATION_GOBACK OFONO_NAVIGATION_PREFIX "Back"
 #define OFONO_NAVIGATION_TERMINATED OFONO_NAVIGATION_PREFIX "Terminated"
+#define OFONO_NAVIGATION_GETHELP OFONO_NAVIGATION_PREFIX "Help"
 
 static void envelope_queue_run(struct ofono_stk *stk);
 static void display_idle(struct ofono_stk *stk);
@@ -1041,7 +1045,6 @@ out:
 	display_idle(stk);
 }
 
-
 static gboolean handle_command_display_text(const struct stk_command *cmd,
 						struct stk_response *rsp,
 						struct ofono_stk *stk)
@@ -1067,6 +1070,157 @@ static gboolean handle_command_display_text(const struct stk_command *cmd,
 	return cmd->display_text.immediate_response;
 }
 
+static void request_get_key_send(struct ofono_stk *stk, DBusMessage *call)
+{
+	struct stk_command_get_inkey *cmd = &stk->pending_cmd->get_inkey;
+	uint8_t qualifier = stk->pending_cmd->qualifier;
+	dbus_bool_t alphabet = (qualifier & (1 << 0)) != 0;
+	dbus_bool_t ucs2 = (qualifier & (1 << 1)) != 0;
+	dbus_bool_t yesno = (qualifier & (1 << 2)) != 0;
+	dbus_bool_t immediate = (qualifier & (1 << 3)) != 0;
+	dbus_bool_t help = (qualifier & (1 << 7)) != 0;
+	const char *charset =
+		yesno ? "yesno" :
+		(!alphabet ? "digit" :
+		 (ucs2 ? "any" : "gsm"));
+
+	dbus_message_set_member(call, "GetKey");
+
+	dbus_message_append_args(call,
+					DBUS_TYPE_STRING, &cmd->text,
+					DBUS_TYPE_STRING, &charset,
+					DBUS_TYPE_BOOLEAN, &help,
+					DBUS_TYPE_BOOLEAN, &immediate,
+					DBUS_TYPE_INVALID);
+}
+
+static void request_get_key_cb(struct ofono_stk *stk, DBusMessage *reply)
+{
+	struct stk_command_get_inkey *cmd = &stk->pending_cmd->get_inkey;
+	uint8_t qualifier = stk->pending_cmd->qualifier;
+	dbus_bool_t yesno = (qualifier & (1 << 2)) != 0;
+	dbus_bool_t help = (qualifier & (1 << 7)) != 0;
+	DBusError err;
+	enum stk_result_type type = STK_RESULT_TYPE_SUCCESS;
+	struct stk_response rsp;
+	struct ofono_error error = { .type = OFONO_ERROR_TYPE_FAILURE };
+	char *key;
+
+	if (!reply) {
+		if (stk->cmd_timeout) {
+			app_agent_request_cancel(stk);
+
+			display_idle(stk);
+			return;
+		}
+
+		type = STK_RESULT_TYPE_NO_RESPONSE;
+
+		goto send;
+	}
+
+	dbus_error_init(&err);
+	if (dbus_set_error_from_message(&err, reply)) {
+		if (g_str_equal(err.name, OFONO_NAVIGATION_TERMINATED))
+			type = STK_RESULT_TYPE_USER_TERMINATED;
+		else if (g_str_equal(err.name, OFONO_NAVIGATION_GOBACK))
+			type = STK_RESULT_TYPE_GO_BACK;
+		else if (g_str_equal(err.name, OFONO_NAVIGATION_GETHELP) &&
+				help)
+			type = STK_RESULT_TYPE_HELP_REQUESTED;
+		else {
+			type = STK_RESULT_TYPE_USER_TERMINATED;
+
+			ofono_error("Unknown reply %s", err.name);
+		}
+
+		dbus_error_free(&err);
+		goto send;
+	}
+
+	if (dbus_message_get_args(reply, NULL,
+					DBUS_TYPE_STRING, &key,
+					DBUS_TYPE_INVALID) == FALSE) {
+		type = STK_RESULT_TYPE_USER_TERMINATED;
+
+		ofono_error("Reply not understood");
+		goto send;
+	}
+
+	if (yesno && strcasecmp(key, "yes") && strcasecmp(key, "no")) {
+		type = STK_RESULT_TYPE_USER_TERMINATED;
+
+		ofono_error("Yes/No reply not understood");
+		goto send;
+	} else if (yesno && strcasecmp(key, "yes"))
+		key = NULL; /* NULL indicates No, non-NULL indicates Yes */
+
+send:
+	memset(&rsp, 0, sizeof(rsp));
+	rsp.result.type = type;
+
+	if (type == STK_RESULT_TYPE_SUCCESS) {
+		rsp.get_inkey.text.text = key;
+		rsp.get_inkey.text.packed = FALSE;
+		rsp.get_inkey.text.yesno = yesno;
+	}
+
+	if (cmd->duration.interval) {
+		struct timeval end_ts;
+		int interval;
+
+		gettimeofday(&end_ts, NULL);
+
+		interval = (end_ts.tv_usec + 1099999 -
+				stk->get_inkey_start_ts.tv_usec) / 100000;
+		interval += (end_ts.tv_sec -
+				stk->get_inkey_start_ts.tv_sec) * 10;
+		interval -= 10;
+
+		switch (cmd->duration.unit) {
+		case STK_DURATION_TYPE_MINUTES:
+			interval = (interval + 59) / 60;
+		case STK_DURATION_TYPE_SECONDS:
+			interval = (interval + 9) / 10;
+		case STK_DURATION_TYPE_SECOND_TENTHS:
+			break;
+		}
+
+		rsp.get_inkey.duration.unit = cmd->duration.unit;
+		rsp.get_inkey.duration.interval = interval;
+	}
+
+	if (stk_respond(stk, &rsp, display_command_cb))
+		display_command_cb(&error, stk);
+}
+
+static gboolean handle_command_get_inkey(const struct stk_command *cmd,
+						struct stk_response *rsp,
+						struct ofono_stk *stk)
+{
+	int timeout = 0;
+
+	if (cmd->get_inkey.duration.interval) {
+		timeout = cmd->get_inkey.duration.interval;
+		switch (cmd->get_inkey.duration.unit) {
+		case STK_DURATION_TYPE_MINUTES:
+			timeout *= 60;
+		case STK_DURATION_TYPE_SECONDS:
+			timeout *= 10;
+		case STK_DURATION_TYPE_SECOND_TENTHS:
+			timeout *= 100;
+		}
+	}
+
+	gettimeofday(&stk->get_inkey_start_ts, NULL);
+
+	stk->custom_timeout = timeout;
+	app_agent_request_start(stk, request_get_key_send, request_get_key_cb,
+				STK_AGENT_GET_KEY);
+
+	return FALSE;
+}
+
 void ofono_stk_proactive_command_cancel(struct ofono_stk *stk)
 {
 	if (!stk->pending_cmd)
@@ -1140,6 +1294,10 @@ void ofono_stk_proactive_command_notify(struct ofono_stk *stk,
 		case STK_COMMAND_TYPE_DISPLAY_TEXT:
 			respond = handle_command_display_text(stk->pending_cmd,
 								&rsp, stk);
+			break;
+		case STK_COMMAND_TYPE_GET_INKEY:
+			respond = handle_command_get_inkey(stk->pending_cmd,
+								&rsp, stk);
 		}
 
 		if (respond)
-- 
1.7.1.86.g0e460.dirty


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

end of thread, other threads:[~2010-07-02 19:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-30 15:24 [PATCH 1/6] stk: Handle the Get Inkey proactive command Andrzej Zaborowski
2010-06-30 15:24 ` [PATCH 2/6] stk: Handle the Get Input " Andrzej Zaborowski
2010-06-30 15:24 ` [PATCH 3/6][RfC] stkutil: Move scaddr field to gsm_sms in stk_command_send_sms Andrzej Zaborowski
2010-07-02 19:52   ` Denis Kenzior
2010-06-30 15:24 ` [PATCH 4/6] test-stkutil: Fix always true condition Andrzej Zaborowski
2010-07-02 19:52   ` Denis Kenzior
2010-06-30 15:24 ` [PATCH 5/6] stk: Separate Dbus request cancelling from command cancelling Andrzej Zaborowski
2010-06-30 15:24 ` [PATCH 6/6][RfC] Implement the Send SMS proactive command 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.