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

diff --git a/src/stk.c b/src/stk.c
index 6fbdbe4..fd5113b 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -1485,6 +1485,111 @@ static gboolean handle_command_get_inkey(const struct 
stk_command *cmd,
        return FALSE;
 }
 
+static void request_get_text_send(struct ofono_stk *stk, DBusMessage *call)
+{
+       struct stk_command_get_input *cmd = &stk->pending_cmd->get_input;
+       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 hidden = (qualifier & (1 << 2)) != 0;
+       dbus_bool_t help = (qualifier & (1 << 7)) != 0;
+       const char *charset =
+               !alphabet ? "digit" :
+                (ucs2 ? "any" : "gsm");
+       const char *default_text = cmd->default_text ? cmd->default_text : "";
+
+       dbus_message_set_member(call, "GetText");
+
+       dbus_message_append_args(call,
+                                       DBUS_TYPE_STRING, &cmd->text,
+                                       DBUS_TYPE_STRING, &default_text,
+                                       DBUS_TYPE_STRING, &charset,
+                                       DBUS_TYPE_BYTE, &cmd->resp_len.min,
+                                       DBUS_TYPE_BYTE, &cmd->resp_len.max,
+                                       DBUS_TYPE_BOOLEAN, &help,
+                                       DBUS_TYPE_BOOLEAN, &hidden,
+                                       DBUS_TYPE_INVALID);
+}
+
+static void request_get_text_cb(struct ofono_stk *stk,
+                               enum stk_agent_result result,
+                               DBusMessage *reply)
+{
+       uint8_t qualifier = stk->pending_cmd->qualifier;
+       dbus_bool_t packed = (qualifier & (1 << 3)) != 0;
+       dbus_bool_t help = (qualifier & (1 << 7)) != 0;
+       enum stk_result_type type = STK_RESULT_TYPE_SUCCESS;
+       struct stk_response rsp;
+       struct ofono_error error = { .type = OFONO_ERROR_TYPE_FAILURE };
+       char *text;
+
+       switch (result) {
+       case STK_AGENT_RESULT_OK:
+               break;
+
+       case STK_AGENT_RESULT_HELP:
+               if (!help) {
+                       type = STK_RESULT_TYPE_USER_TERMINATED;
+                       ofono_error("Help requested but not available");
+
+                       goto send;
+               }
+
+               type = STK_RESULT_TYPE_HELP_REQUESTED;
+               goto send;
+
+       case STK_AGENT_RESULT_BACK:
+               type = STK_RESULT_TYPE_GO_BACK;
+               goto send;
+
+       case STK_AGENT_RESULT_TIMEOUT:
+               type = STK_RESULT_TYPE_NO_RESPONSE;
+               goto send;
+
+       case STK_AGENT_RESULT_TERMINATE:
+       default:
+               type = STK_RESULT_TYPE_USER_TERMINATED;
+               goto send;
+
+       case STK_AGENT_RESULT_CANCEL:
+               return;
+       }
+
+       if (dbus_message_get_args(reply, NULL,
+                                       DBUS_TYPE_STRING, &text,
+                                       DBUS_TYPE_INVALID) == FALSE) {
+               type = STK_RESULT_TYPE_USER_TERMINATED;
+               ofono_error("Reply not understood");
+
+               goto send;
+       }
+
+send:
+       memset(&rsp, 0, sizeof(rsp));
+       rsp.result.type = type;
+
+       if (type == STK_RESULT_TYPE_SUCCESS) {
+               rsp.get_input.text.text = text;
+               rsp.get_input.text.packed = packed;
+               rsp.get_input.text.yesno = FALSE;
+       }
+
+       if (stk_respond(stk, &rsp, stk_command_cb))
+               stk_command_cb(&error, stk);
+}
+
+static gboolean handle_command_get_input(const struct stk_command *cmd,
+                                               struct stk_response *rsp,
+                                               struct ofono_stk *stk)
+{
+       app_agent_request_start(stk,
+                               request_get_text_send, request_get_text_cb, 0);
+
+       stk->cancel_cmd = app_agent_request_cancel;
+
+       return FALSE;
+}
+
 static void stk_proactive_command_cancel(struct ofono_stk *stk)
 {
        if (!stk->pending_cmd)
@@ -1606,6 +1711,10 @@ void ofono_stk_proactive_command_notify(struct ofono_stk 
*stk,
                        respond = handle_command_get_inkey(stk->pending_cmd,
                                                                &rsp, stk);
                        break;
+               case STK_COMMAND_TYPE_GET_INPUT:
+                       respond = handle_command_get_input(stk->pending_cmd,
+                                                               &rsp, stk);
+                       break;
                }
 
                if (respond)
-- 
1.7.1.86.g0e460.dirty

_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono

Reply via email to