All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] stkagent: Implement RequestConfirmation/Key/Digit.
@ 2010-08-04  4:55 Andrzej Zaborowski
  2010-08-04  4:55 ` [PATCH 2/4] stk: Handle the Get Inkey proactive command Andrzej Zaborowski
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Andrzej Zaborowski @ 2010-08-04  4:55 UTC (permalink / raw)
  To: ofono

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

---
 src/stkagent.c |  240 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/stkagent.h |   24 ++++++
 2 files changed, 264 insertions(+), 0 deletions(-)

diff --git a/src/stkagent.c b/src/stkagent.c
index 22ff7c6..6352fb2 100644
--- a/src/stkagent.c
+++ b/src/stkagent.c
@@ -33,6 +33,7 @@
 
 #include "ofono.h"
 
+#include "common.h"
 #include "stkagent.h"
 
 enum allowed_error {
@@ -430,3 +431,242 @@ int stk_agent_display_text(struct stk_agent *agent, const char *text,
 
 	return 0;
 }
+
+static void get_confirmation_cb(DBusPendingCall *call, void *data)
+{
+	struct stk_agent *agent = data;
+	stk_agent_confirmation_cb cb = agent->user_cb;
+	DBusMessage *reply = dbus_pending_call_steal_reply(call);
+	enum stk_agent_result result;
+	gboolean remove_agent;
+	dbus_bool_t confirm;
+
+	if (check_error(agent, reply,
+			ALLOWED_ERROR_GO_BACK | ALLOWED_ERROR_TERMINATE,
+			&result) == -EINVAL) {
+		remove_agent = TRUE;
+		goto error;
+	}
+
+	if (result != STK_AGENT_RESULT_OK) {
+		cb(result, FALSE, agent->user_data);
+		goto done;
+	}
+
+	if (dbus_message_get_args(reply, NULL,
+					DBUS_TYPE_BOOLEAN, &confirm,
+					DBUS_TYPE_INVALID) == FALSE) {
+		ofono_error("Can't parse the reply to GetConfirmation()");
+		remove_agent = TRUE;
+		goto error;
+	}
+
+	cb(result, confirm, agent->user_data);
+
+done:
+	if (result == STK_AGENT_RESULT_TERMINATE && agent->remove_on_terminate)
+		remove_agent = TRUE;
+	else
+		remove_agent = FALSE;
+
+error:
+	stk_agent_request_end(agent);
+	dbus_message_unref(reply);
+
+	if (remove_agent)
+		stk_agent_free(agent);
+}
+
+int stk_agent_request_confirmation(struct stk_agent *agent,
+					const char *text, uint8_t icon_id,
+					stk_agent_confirmation_cb cb,
+					void *user_data,
+					ofono_destroy_func destroy,
+					int timeout)
+{
+	DBusConnection *conn = ofono_dbus_get_connection();
+
+	agent->msg = dbus_message_new_method_call(agent->bus, agent->path,
+							OFONO_SIM_APP_INTERFACE,
+							"RequestConfirmation");
+	if (agent->msg == NULL)
+		return -ENOMEM;
+
+	dbus_message_append_args(agent->msg,
+					DBUS_TYPE_STRING, &text,
+					DBUS_TYPE_BYTE, &icon_id,
+					DBUS_TYPE_INVALID);
+
+	if (dbus_connection_send_with_reply(conn, agent->msg, &agent->call,
+						timeout) == FALSE ||
+			agent->call == NULL)
+		return -EIO;
+
+	agent->user_cb = cb;
+	agent->user_data = user_data;
+	agent->user_destroy = destroy;
+
+	dbus_pending_call_set_notify(agent->call, get_confirmation_cb,
+					agent, NULL);
+
+	return 0;
+}
+
+static void get_digit_cb(DBusPendingCall *call, void *data)
+{
+	struct stk_agent *agent = data;
+	stk_agent_string_cb cb = agent->user_cb;
+	DBusMessage *reply = dbus_pending_call_steal_reply(call);
+	enum stk_agent_result result;
+	gboolean remove_agent;
+	char *digit;
+
+	if (check_error(agent, reply,
+			ALLOWED_ERROR_GO_BACK | ALLOWED_ERROR_TERMINATE,
+			&result) == -EINVAL) {
+		remove_agent = TRUE;
+		goto error;
+	}
+
+	if (result != STK_AGENT_RESULT_OK) {
+		cb(result, NULL, agent->user_data);
+		goto done;
+	}
+
+	if (dbus_message_get_args(reply, NULL,
+					DBUS_TYPE_STRING, &digit,
+					DBUS_TYPE_INVALID) == FALSE ||
+			strlen(digit) != 1 ||
+			!valid_phone_number_format(digit)) {
+		ofono_error("Can't parse the reply to GetDigit()");
+		remove_agent = TRUE;
+		goto error;
+	}
+
+	cb(result, digit, agent->user_data);
+
+done:
+	if (result == STK_AGENT_RESULT_TERMINATE && agent->remove_on_terminate)
+		remove_agent = TRUE;
+	else
+		remove_agent = FALSE;
+
+error:
+	stk_agent_request_end(agent);
+	dbus_message_unref(reply);
+
+	if (remove_agent)
+		stk_agent_free(agent);
+}
+
+int stk_agent_request_digit(struct stk_agent *agent,
+				const char *text, uint8_t icon_id,
+				stk_agent_string_cb cb, void *user_data,
+				ofono_destroy_func destroy, int timeout)
+{
+	DBusConnection *conn = ofono_dbus_get_connection();
+
+	agent->msg = dbus_message_new_method_call(agent->bus, agent->path,
+							OFONO_SIM_APP_INTERFACE,
+							"RequestDigit");
+	if (agent->msg == NULL)
+		return -ENOMEM;
+
+	dbus_message_append_args(agent->msg,
+					DBUS_TYPE_STRING, &text,
+					DBUS_TYPE_BYTE, &icon_id,
+					DBUS_TYPE_INVALID);
+
+	if (dbus_connection_send_with_reply(conn, agent->msg, &agent->call,
+						timeout) == FALSE ||
+			agent->call == NULL)
+		return -EIO;
+
+	agent->user_cb = cb;
+	agent->user_data = user_data;
+	agent->user_destroy = destroy;
+
+	dbus_pending_call_set_notify(agent->call, get_digit_cb,
+					agent, NULL);
+
+	return 0;
+}
+
+static void get_key_cb(DBusPendingCall *call, void *data)
+{
+	struct stk_agent *agent = data;
+	stk_agent_string_cb cb = agent->user_cb;
+	DBusMessage *reply = dbus_pending_call_steal_reply(call);
+	enum stk_agent_result result;
+	gboolean remove_agent;
+	char *key;
+
+	if (check_error(agent, reply,
+			ALLOWED_ERROR_GO_BACK | ALLOWED_ERROR_TERMINATE,
+			&result) == -EINVAL) {
+		remove_agent = TRUE;
+		goto error;
+	}
+
+	if (result != STK_AGENT_RESULT_OK) {
+		cb(result, NULL, agent->user_data);
+		goto done;
+	}
+
+	if (dbus_message_get_args(reply, NULL,
+					DBUS_TYPE_STRING, &key,
+					DBUS_TYPE_INVALID) == FALSE ||
+			g_utf8_strlen(key, 10) != 1) {
+		ofono_error("Can't parse the reply to GetKey()");
+		remove_agent = TRUE;
+		goto error;
+	}
+
+	cb(result, key, agent->user_data);
+
+done:
+	if (result == STK_AGENT_RESULT_TERMINATE && agent->remove_on_terminate)
+		remove_agent = TRUE;
+	else
+		remove_agent = FALSE;
+
+error:
+	stk_agent_request_end(agent);
+	dbus_message_unref(reply);
+
+	if (remove_agent)
+		stk_agent_free(agent);
+}
+
+int stk_agent_request_key(struct stk_agent *agent, const char *text,
+				uint8_t icon_id, ofono_bool_t unicode_charset,
+				stk_agent_string_cb cb, void *user_data,
+				ofono_destroy_func destroy, int timeout)
+{
+	DBusConnection *conn = ofono_dbus_get_connection();
+
+	agent->msg = dbus_message_new_method_call(agent->bus, agent->path,
+							OFONO_SIM_APP_INTERFACE,
+							"RequestKey");
+	if (agent->msg == NULL)
+		return -ENOMEM;
+
+	dbus_message_append_args(agent->msg,
+					DBUS_TYPE_STRING, &text,
+					DBUS_TYPE_BYTE, &icon_id,
+					DBUS_TYPE_INVALID);
+
+	if (dbus_connection_send_with_reply(conn, agent->msg, &agent->call,
+						timeout) == FALSE ||
+			agent->call == NULL)
+		return -EIO;
+
+	agent->user_cb = cb;
+	agent->user_data = user_data;
+	agent->user_destroy = destroy;
+
+	dbus_pending_call_set_notify(agent->call, get_key_cb,
+					agent, NULL);
+
+	return 0;
+}
diff --git a/src/stkagent.h b/src/stkagent.h
index d9e79dc..8b9a931 100644
--- a/src/stkagent.h
+++ b/src/stkagent.h
@@ -50,6 +50,13 @@ typedef void (*stk_agent_display_text_cb)(enum stk_agent_result result,
 typedef void (*stk_agent_selection_cb)(enum stk_agent_result result,
 					uint8_t id, void *user_data);
 
+typedef void (*stk_agent_confirmation_cb)(enum stk_agent_result result,
+						ofono_bool_t confirm,
+						void *user_data);
+
+typedef void (*stk_agent_string_cb)(enum stk_agent_result result,
+					char *string, void *user_data);
+
 struct stk_agent *stk_agent_new(const char *path, const char *sender,
 					ofono_bool_t remove_on_terminate);
 
@@ -76,5 +83,22 @@ int stk_agent_display_text(struct stk_agent *agent, const char *text,
 				void *user_data, ofono_destroy_func destroy,
 				int timeout);
 
+int stk_agent_request_confirmation(struct stk_agent *agent,
+					const char *text, uint8_t icon_id,
+					stk_agent_confirmation_cb cb,
+					void *user_data,
+					ofono_destroy_func destroy,
+					int timeout);
+
+int stk_agent_request_digit(struct stk_agent *agent,
+				const char *text, uint8_t icon_id,
+				stk_agent_string_cb cb, void *user_data,
+				ofono_destroy_func destroy, int timeout);
+
+int stk_agent_request_key(struct stk_agent *agent, const char *text,
+				uint8_t icon_id, ofono_bool_t unicode_charset,
+				stk_agent_string_cb cb, void *user_data,
+				ofono_destroy_func destroy, int timeout);
+
 void append_menu_items_variant(DBusMessageIter *iter,
 				const struct stk_menu_item *items);
-- 
1.7.1.86.g0e460.dirty


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

* [PATCH 2/4] stk: Handle the Get Inkey proactive command.
  2010-08-04  4:55 [PATCH 1/4] stkagent: Implement RequestConfirmation/Key/Digit Andrzej Zaborowski
@ 2010-08-04  4:55 ` Andrzej Zaborowski
  2010-08-04  4:55 ` [PATCH 3/4] stkagent: Implement RequestInput/RequestDigits Andrzej Zaborowski
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Andrzej Zaborowski @ 2010-08-04  4:55 UTC (permalink / raw)
  To: ofono

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

I don't have any card that actually makes use of Get Inkey so it's
not tested on hardware.
---
 src/stk.c |  200 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 200 insertions(+), 0 deletions(-)

diff --git a/src/stk.c b/src/stk.c
index 4146443..9331934 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -32,6 +32,7 @@
 #include <gdbus.h>
 #include <errno.h>
 #include <time.h>
+#include <sys/time.h>
 
 #include "ofono.h"
 
@@ -69,6 +70,7 @@ struct ofono_stk {
 	guint remove_agent_source;
 	struct sms_submit_req *sms_submit_req;
 	char *idle_mode_text;
+	struct timeval get_inkey_start_ts;
 };
 
 struct envelope_op {
@@ -1134,6 +1136,199 @@ static gboolean handle_command_display_text(const struct stk_command *cmd,
 	return stk->immediate_response;
 }
 
+static void set_get_inkey_duration(struct stk_duration *duration,
+					struct timeval *start_ts)
+{
+	struct timeval end_ts;
+	int interval;
+
+	gettimeofday(&end_ts, NULL);
+
+	interval = (end_ts.tv_usec + 1099999 - start_ts->tv_usec) / 100000;
+	interval += (end_ts.tv_sec - start_ts->tv_sec) * 10;
+	interval -= 10;
+
+	switch (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;
+	}
+
+	duration->interval = interval;
+}
+
+static void request_confirmation_cb(enum stk_agent_result result,
+					gboolean confirm,
+					void *user_data)
+{
+	struct ofono_stk *stk = user_data;
+	static struct ofono_error error = { .type = OFONO_ERROR_TYPE_FAILURE };
+	struct stk_command_get_inkey *cmd = &stk->pending_cmd->get_inkey;
+	uint8_t qualifier = stk->pending_cmd->qualifier;
+	struct stk_response rsp;
+
+	switch (result) {
+	case STK_AGENT_RESULT_OK:
+		memset(&rsp, 0, sizeof(rsp));
+
+		rsp.result.type = STK_RESULT_TYPE_SUCCESS;
+		rsp.get_inkey.text.text = confirm ? "" : NULL;
+		rsp.get_inkey.text.yesno = TRUE;
+
+		if (cmd->duration.interval) {
+			rsp.get_inkey.duration.unit = cmd->duration.unit;
+			set_get_inkey_duration(&rsp.get_inkey.duration,
+						&stk->get_inkey_start_ts);
+		}
+
+		if (stk_respond(stk, &rsp, stk_command_cb))
+			stk_command_cb(&error, stk);
+
+		break;
+
+	case STK_AGENT_RESULT_BACK:
+		send_simple_response(stk, STK_RESULT_TYPE_GO_BACK);
+		break;
+
+	case STK_AGENT_RESULT_TIMEOUT:
+		send_simple_response(stk, STK_RESULT_TYPE_NO_RESPONSE);
+		break;
+
+	case STK_AGENT_RESULT_HELP:
+		if ((qualifier & (1 << 7)) == 0) {
+			ofono_error("Help requested but not available");
+
+			send_simple_response(stk,
+					STK_RESULT_TYPE_USER_TERMINATED);
+			break;
+		}
+
+		send_simple_response(stk, STK_RESULT_TYPE_HELP_REQUESTED);
+		break;
+
+	case STK_AGENT_RESULT_TERMINATE:
+	default:
+		send_simple_response(stk, STK_RESULT_TYPE_USER_TERMINATED);
+		break;
+	}
+}
+
+static void request_key_cb(enum stk_agent_result result, char *string,
+				void *user_data)
+{
+	struct ofono_stk *stk = user_data;
+	static struct ofono_error error = { .type = OFONO_ERROR_TYPE_FAILURE };
+	struct stk_command_get_inkey *cmd = &stk->pending_cmd->get_inkey;
+	uint8_t qualifier = stk->pending_cmd->qualifier;
+	struct stk_response rsp;
+
+	switch (result) {
+	case STK_AGENT_RESULT_OK:
+		memset(&rsp, 0, sizeof(rsp));
+
+		rsp.result.type = STK_RESULT_TYPE_SUCCESS;
+		rsp.get_inkey.text.text = string;
+
+		if (cmd->duration.interval) {
+			rsp.get_inkey.duration.unit = cmd->duration.unit;
+			set_get_inkey_duration(&rsp.get_inkey.duration,
+						&stk->get_inkey_start_ts);
+		}
+
+		if (stk_respond(stk, &rsp, stk_command_cb))
+			stk_command_cb(&error, stk);
+
+		break;
+
+	case STK_AGENT_RESULT_BACK:
+		send_simple_response(stk, STK_RESULT_TYPE_GO_BACK);
+		break;
+
+	case STK_AGENT_RESULT_TIMEOUT:
+		send_simple_response(stk, STK_RESULT_TYPE_NO_RESPONSE);
+		break;
+
+	case STK_AGENT_RESULT_HELP:
+		if ((qualifier & (1 << 7)) == 0) {
+			ofono_error("Help requested but not available");
+
+			send_simple_response(stk,
+					STK_RESULT_TYPE_USER_TERMINATED);
+			break;
+		}
+
+		send_simple_response(stk, STK_RESULT_TYPE_HELP_REQUESTED);
+		break;
+
+	case STK_AGENT_RESULT_TERMINATE:
+	default:
+		send_simple_response(stk, STK_RESULT_TYPE_USER_TERMINATED);
+		break;
+	}
+}
+
+static gboolean handle_command_get_inkey(const struct stk_command *cmd,
+						struct stk_response *rsp,
+						struct ofono_stk *stk)
+{
+	int timeout = stk->timeout * 1000;
+	const struct stk_command_get_inkey *gi = &cmd->get_inkey;
+	uint8_t qualifier = stk->pending_cmd->qualifier;
+	gboolean alphabet = (qualifier & (1 << 0)) != 0;
+	gboolean ucs2 = (qualifier & (1 << 1)) != 0;
+	gboolean yesno = (qualifier & (1 << 2)) != 0;
+	/*
+	 * Note: immediate response and help parameter values are not
+	 * provided by current api.
+	 */
+	uint8_t icon_id = 0;
+	int err;
+
+	if (gi->duration.interval) {
+		timeout = gi->duration.interval;
+		switch (gi->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->cancel_cmd = stk_request_cancel;
+
+	if (yesno)
+		err = stk_agent_request_confirmation(stk->current_agent,
+							gi->text, icon_id,
+							request_confirmation_cb,
+							stk, NULL, timeout);
+	else if (alphabet)
+		err = stk_agent_request_key(stk->current_agent, gi->text,
+						icon_id, ucs2, request_key_cb,
+						stk, NULL, timeout);
+	else
+		err = stk_agent_request_digit(stk->current_agent, gi->text,
+						icon_id, request_key_cb,
+						stk, NULL, timeout);
+
+	if (err < 0) {
+		/*
+		 * We most likely got an out of memory error, tell SIM
+		 * to retry
+		 */
+		rsp->result.type = STK_RESULT_TYPE_TERMINAL_BUSY;
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
 static void stk_proactive_command_cancel(struct ofono_stk *stk)
 {
 	if (stk->immediate_response)
@@ -1268,6 +1463,11 @@ void ofono_stk_proactive_command_notify(struct ofono_stk *stk,
 							&rsp, stk);
 		break;
 
+	case STK_COMMAND_TYPE_GET_INKEY:
+		respond = handle_command_get_inkey(stk->pending_cmd,
+							&rsp, stk);
+		break;
+
 	default:
 		rsp.result.type = STK_RESULT_TYPE_COMMAND_NOT_UNDERSTOOD;
 		break;
-- 
1.7.1.86.g0e460.dirty


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

* [PATCH 3/4] stkagent: Implement RequestInput/RequestDigits.
  2010-08-04  4:55 [PATCH 1/4] stkagent: Implement RequestConfirmation/Key/Digit Andrzej Zaborowski
  2010-08-04  4:55 ` [PATCH 2/4] stk: Handle the Get Inkey proactive command Andrzej Zaborowski
@ 2010-08-04  4:55 ` Andrzej Zaborowski
  2010-08-04  4:55 ` [PATCH 4/4] stk: Handle the Get Input proactive command Andrzej Zaborowski
  2010-08-04 20:16 ` [PATCH 1/4] stkagent: Implement RequestConfirmation/Key/Digit Denis Kenzior
  3 siblings, 0 replies; 5+ messages in thread
From: Andrzej Zaborowski @ 2010-08-04  4:55 UTC (permalink / raw)
  To: ofono

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

---
 src/stkagent.c |  179 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/stkagent.h |   13 ++++
 2 files changed, 192 insertions(+), 0 deletions(-)

diff --git a/src/stkagent.c b/src/stkagent.c
index 6352fb2..692b470 100644
--- a/src/stkagent.c
+++ b/src/stkagent.c
@@ -670,3 +670,182 @@ int stk_agent_request_key(struct stk_agent *agent, const char *text,
 
 	return 0;
 }
+
+static void get_digits_cb(DBusPendingCall *call, void *data)
+{
+	struct stk_agent *agent = data;
+	stk_agent_string_cb cb = agent->user_cb;
+	DBusMessage *reply = dbus_pending_call_steal_reply(call);
+	enum stk_agent_result result;
+	gboolean remove_agent;
+	char *string;
+
+	if (check_error(agent, reply,
+			ALLOWED_ERROR_GO_BACK | ALLOWED_ERROR_TERMINATE,
+			&result) == -EINVAL) {
+		remove_agent = TRUE;
+		goto error;
+	}
+
+	if (result != STK_AGENT_RESULT_OK) {
+		cb(result, NULL, agent->user_data);
+		goto done;
+	}
+
+	if (dbus_message_get_args(reply, NULL,
+					DBUS_TYPE_STRING, &string,
+					DBUS_TYPE_INVALID) == FALSE) {
+		ofono_error("Can't parse the reply to GetDigits()");
+		remove_agent = TRUE;
+		goto error;
+	}
+
+	cb(result, string, agent->user_data);
+
+done:
+	if (result == STK_AGENT_RESULT_TERMINATE && agent->remove_on_terminate)
+		remove_agent = TRUE;
+	else
+		remove_agent = FALSE;
+
+error:
+	stk_agent_request_end(agent);
+	dbus_message_unref(reply);
+
+	if (remove_agent)
+		stk_agent_free(agent);
+}
+
+int stk_agent_request_digits(struct stk_agent *agent, const char *text,
+				uint8_t icon_id, const char *default_text,
+				int min, int max, ofono_bool_t hidden,
+				stk_agent_string_cb cb, void *user_data,
+				ofono_destroy_func destroy, int timeout)
+{
+	DBusConnection *conn = ofono_dbus_get_connection();
+	uint8_t min_val = min;
+	uint8_t max_val = max;
+	dbus_bool_t hidden_val = hidden;
+
+	agent->msg = dbus_message_new_method_call(agent->bus, agent->path,
+							OFONO_SIM_APP_INTERFACE,
+							"RequestDigits");
+	if (agent->msg == NULL)
+		return -ENOMEM;
+
+	if (default_text == NULL)
+		default_text = "";
+
+	dbus_message_append_args(agent->msg,
+					DBUS_TYPE_STRING, &text,
+					DBUS_TYPE_BYTE, &icon_id,
+					DBUS_TYPE_STRING, &default_text,
+					DBUS_TYPE_BYTE, &min_val,
+					DBUS_TYPE_BYTE, &max_val,
+					DBUS_TYPE_BOOLEAN, &hidden_val,
+					DBUS_TYPE_INVALID);
+
+	if (dbus_connection_send_with_reply(conn, agent->msg, &agent->call,
+						timeout) == FALSE ||
+			agent->call == NULL)
+		return -EIO;
+
+	agent->user_cb = cb;
+	agent->user_data = user_data;
+	agent->user_destroy = destroy;
+
+	dbus_pending_call_set_notify(agent->call, get_digits_cb,
+					agent, NULL);
+
+	return 0;
+}
+
+static void get_input_cb(DBusPendingCall *call, void *data)
+{
+	struct stk_agent *agent = data;
+	stk_agent_string_cb cb = agent->user_cb;
+	DBusMessage *reply = dbus_pending_call_steal_reply(call);
+	enum stk_agent_result result;
+	gboolean remove_agent;
+	char *string;
+
+	if (check_error(agent, reply,
+			ALLOWED_ERROR_GO_BACK | ALLOWED_ERROR_TERMINATE,
+			&result) == -EINVAL) {
+		remove_agent = TRUE;
+		goto error;
+	}
+
+	if (result != STK_AGENT_RESULT_OK) {
+		cb(result, NULL, agent->user_data);
+		goto done;
+	}
+
+	if (dbus_message_get_args(reply, NULL,
+					DBUS_TYPE_STRING, &string,
+					DBUS_TYPE_INVALID) == FALSE) {
+		ofono_error("Can't parse the reply to GetInput()");
+		remove_agent = TRUE;
+		goto error;
+	}
+
+	cb(result, string, agent->user_data);
+
+done:
+	if (result == STK_AGENT_RESULT_TERMINATE && agent->remove_on_terminate)
+		remove_agent = TRUE;
+	else
+		remove_agent = FALSE;
+
+error:
+	stk_agent_request_end(agent);
+	dbus_message_unref(reply);
+
+	if (remove_agent)
+		stk_agent_free(agent);
+}
+
+int stk_agent_request_input(struct stk_agent *agent, const char *text,
+				uint8_t icon_id, const char *default_text,
+				ofono_bool_t unicode_charset, int min, int max,
+				ofono_bool_t hidden, stk_agent_string_cb cb,
+				void *user_data, ofono_destroy_func destroy,
+				int timeout)
+{
+	DBusConnection *conn = ofono_dbus_get_connection();
+	uint8_t min_val = min;
+	uint8_t max_val = max;
+	dbus_bool_t hidden_val = hidden;
+
+	agent->msg = dbus_message_new_method_call(agent->bus, agent->path,
+							OFONO_SIM_APP_INTERFACE,
+							"RequestInput");
+	if (agent->msg == NULL)
+		return -ENOMEM;
+
+	if (default_text == NULL)
+		default_text = "";
+
+	dbus_message_append_args(agent->msg,
+					DBUS_TYPE_STRING, &text,
+					DBUS_TYPE_BYTE, &icon_id,
+					DBUS_TYPE_STRING, &default_text,
+					DBUS_TYPE_BYTE, &min_val,
+					DBUS_TYPE_BYTE, &max_val,
+					DBUS_TYPE_BOOLEAN, &hidden_val,
+					DBUS_TYPE_INVALID);
+
+	if (dbus_connection_send_with_reply(conn, agent->msg, &agent->call,
+						timeout) == FALSE ||
+			agent->call == NULL)
+		return -EIO;
+
+	agent->user_cb = cb;
+	agent->user_data = user_data;
+	agent->user_destroy = destroy;
+
+	dbus_pending_call_set_notify(agent->call, get_input_cb,
+					agent, NULL);
+
+	return 0;
+}
diff --git a/src/stkagent.h b/src/stkagent.h
index 8b9a931..3faabe7 100644
--- a/src/stkagent.h
+++ b/src/stkagent.h
@@ -100,5 +100,18 @@ int stk_agent_request_key(struct stk_agent *agent, const char *text,
 				stk_agent_string_cb cb, void *user_data,
 				ofono_destroy_func destroy, int timeout);
 
+int stk_agent_request_digits(struct stk_agent *agent, const char *text,
+				uint8_t icon_id, const char *default_text,
+				int min, int max, ofono_bool_t hidden,
+				stk_agent_string_cb cb, void *user_data,
+				ofono_destroy_func destroy, int timeout);
+
+int stk_agent_request_input(struct stk_agent *agent, const char *text,
+				uint8_t icon_id, const char *default_text,
+				ofono_bool_t unicode_charset, int min, int max,
+				ofono_bool_t hidden, stk_agent_string_cb cb,
+				void *user_data, ofono_destroy_func destroy,
+				int timeout);
+
 void append_menu_items_variant(DBusMessageIter *iter,
 				const struct stk_menu_item *items);
-- 
1.7.1.86.g0e460.dirty


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

* [PATCH 4/4] stk: Handle the Get Input proactive command.
  2010-08-04  4:55 [PATCH 1/4] stkagent: Implement RequestConfirmation/Key/Digit Andrzej Zaborowski
  2010-08-04  4:55 ` [PATCH 2/4] stk: Handle the Get Inkey proactive command Andrzej Zaborowski
  2010-08-04  4:55 ` [PATCH 3/4] stkagent: Implement RequestInput/RequestDigits Andrzej Zaborowski
@ 2010-08-04  4:55 ` Andrzej Zaborowski
  2010-08-04 20:16 ` [PATCH 1/4] stkagent: Implement RequestConfirmation/Key/Digit Denis Kenzior
  3 siblings, 0 replies; 5+ messages in thread
From: Andrzej Zaborowski @ 2010-08-04  4:55 UTC (permalink / raw)
  To: ofono

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

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

diff --git a/src/stk.c b/src/stk.c
index 9331934..91a4586 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -1329,6 +1329,97 @@ static gboolean handle_command_get_inkey(const struct stk_command *cmd,
 	return FALSE;
 }
 
+static void request_string_cb(enum stk_agent_result result, char *string,
+				void *user_data)
+{
+	struct ofono_stk *stk = user_data;
+	static struct ofono_error error = { .type = OFONO_ERROR_TYPE_FAILURE };
+	uint8_t qualifier = stk->pending_cmd->qualifier;
+	gboolean packed = (qualifier & (1 << 3)) != 0;
+	struct stk_response rsp;
+
+	switch (result) {
+	case STK_AGENT_RESULT_OK:
+		memset(&rsp, 0, sizeof(rsp));
+
+		rsp.result.type = STK_RESULT_TYPE_SUCCESS;
+		rsp.get_input.text.text = string;
+		rsp.get_input.text.packed = packed;
+
+		if (stk_respond(stk, &rsp, stk_command_cb))
+			stk_command_cb(&error, stk);
+
+		break;
+
+	case STK_AGENT_RESULT_BACK:
+		send_simple_response(stk, STK_RESULT_TYPE_GO_BACK);
+		break;
+
+	case STK_AGENT_RESULT_TIMEOUT:
+		send_simple_response(stk, STK_RESULT_TYPE_NO_RESPONSE);
+		break;
+
+	case STK_AGENT_RESULT_HELP:
+		if ((qualifier & (1 << 7)) == 0) {
+			ofono_error("Help requested but not available");
+
+			send_simple_response(stk,
+					STK_RESULT_TYPE_USER_TERMINATED);
+			break;
+		}
+
+		send_simple_response(stk, STK_RESULT_TYPE_HELP_REQUESTED);
+		break;
+
+	case STK_AGENT_RESULT_TERMINATE:
+	default:
+		send_simple_response(stk, STK_RESULT_TYPE_USER_TERMINATED);
+		break;
+	}
+}
+
+static gboolean handle_command_get_input(const struct stk_command *cmd,
+						struct stk_response *rsp,
+						struct ofono_stk *stk)
+{
+	int timeout = stk->timeout * 1000;
+	const struct stk_command_get_input *gi = &cmd->get_input;
+	uint8_t qualifier = stk->pending_cmd->qualifier;
+	gboolean alphabet = (qualifier & (1 << 0)) != 0;
+	gboolean ucs2 = (qualifier & (1 << 1)) != 0;
+	gboolean hidden = (qualifier & (1 << 2)) != 0;
+	uint8_t icon_id = 0;
+	int err;
+
+	stk->cancel_cmd = stk_request_cancel;
+
+	if (alphabet)
+		err = stk_agent_request_input(stk->current_agent, gi->text,
+						icon_id, gi->default_text, ucs2,
+						gi->resp_len.min,
+						gi->resp_len.max, hidden,
+						request_string_cb,
+						stk, NULL, timeout);
+	else
+		err = stk_agent_request_digits(stk->current_agent, gi->text,
+						icon_id, gi->default_text,
+						gi->resp_len.min,
+						gi->resp_len.max, hidden,
+						request_string_cb,
+						stk, NULL, timeout);
+
+	if (err < 0) {
+		/*
+		 * We most likely got an out of memory error, tell SIM
+		 * to retry
+		 */
+		rsp->result.type = STK_RESULT_TYPE_TERMINAL_BUSY;
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
 static void stk_proactive_command_cancel(struct ofono_stk *stk)
 {
 	if (stk->immediate_response)
@@ -1468,6 +1559,11 @@ void ofono_stk_proactive_command_notify(struct ofono_stk *stk,
 							&rsp, stk);
 		break;
 
+	case STK_COMMAND_TYPE_GET_INPUT:
+		respond = handle_command_get_input(stk->pending_cmd,
+							&rsp, stk);
+		break;
+
 	default:
 		rsp.result.type = STK_RESULT_TYPE_COMMAND_NOT_UNDERSTOOD;
 		break;
-- 
1.7.1.86.g0e460.dirty


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

* Re: [PATCH 1/4] stkagent: Implement RequestConfirmation/Key/Digit.
  2010-08-04  4:55 [PATCH 1/4] stkagent: Implement RequestConfirmation/Key/Digit Andrzej Zaborowski
                   ` (2 preceding siblings ...)
  2010-08-04  4:55 ` [PATCH 4/4] stk: Handle the Get Input proactive command Andrzej Zaborowski
@ 2010-08-04 20:16 ` Denis Kenzior
  3 siblings, 0 replies; 5+ messages in thread
From: Denis Kenzior @ 2010-08-04 20:16 UTC (permalink / raw)
  To: ofono

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

Hi Andrew,

On 08/03/2010 11:55 PM, Andrzej Zaborowski wrote:
> ---
>  src/stkagent.c |  240 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  src/stkagent.h |   24 ++++++
>  2 files changed, 264 insertions(+), 0 deletions(-)
> 

All patches in this series have been applied.  Thanks!

Regards,
-Denis

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

end of thread, other threads:[~2010-08-04 20:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-04  4:55 [PATCH 1/4] stkagent: Implement RequestConfirmation/Key/Digit Andrzej Zaborowski
2010-08-04  4:55 ` [PATCH 2/4] stk: Handle the Get Inkey proactive command Andrzej Zaborowski
2010-08-04  4:55 ` [PATCH 3/4] stkagent: Implement RequestInput/RequestDigits Andrzej Zaborowski
2010-08-04  4:55 ` [PATCH 4/4] stk: Handle the Get Input proactive command Andrzej Zaborowski
2010-08-04 20:16 ` [PATCH 1/4] stkagent: Implement RequestConfirmation/Key/Digit 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.