---
src/stk.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 135 insertions(+), 1 deletions(-)
diff --git a/src/stk.c b/src/stk.c
index 3fda2af..b469467 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -434,8 +434,12 @@ static void default_agent_notify(gpointer user_data)
{
struct ofono_stk *stk = user_data;
- if (stk->current_agent == stk->default_agent && stk->respond_on_exit)
+ if (stk->current_agent == stk->default_agent && stk->respond_on_exit) {
+ if (stk->pending_cmd)
+ stk->cancel_cmd(stk);
+
send_simple_response(stk, STK_RESULT_TYPE_USER_TERMINATED);
+ }
stk->default_agent = NULL;
stk->current_agent = stk->session_agent;
@@ -449,6 +453,9 @@ static void session_agent_notify(gpointer user_data)
DBG("Session Agent removed");
if (stk->current_agent == stk->session_agent && stk->respond_on_exit) {
+ if (stk->pending_cmd)
+ stk->cancel_cmd(stk);
+
DBG("Sending Terminate response for session agent");
send_simple_response(stk, STK_RESULT_TYPE_USER_TERMINATED);
}
@@ -1590,6 +1597,128 @@ static gboolean handle_command_set_up_call(const struct
stk_command *cmd,
return FALSE;
}
+static void send_dtmf_cancel(struct ofono_stk *stk)
+{
+ struct ofono_voicecall *vc;
+ struct ofono_atom *vc_atom;
+
+ stk->respond_on_exit = FALSE;
+
+ if (stk->pending_cmd->send_dtmf.alpha_id &&
+ stk->pending_cmd->send_dtmf.alpha_id[0])
+ stk_alpha_id_unset(stk);
+
+ vc_atom = __ofono_modem_find_atom(__ofono_atom_get_modem(stk->atom),
+ OFONO_ATOM_TYPE_VOICECALL);
+ if (!vc_atom)
+ return;
+
+ vc = __ofono_atom_get_data(vc_atom);
+ if (vc)
+ __ofono_voicecall_tone_cancel(vc);
+}
+
+static void dtmf_sent_cb(int err, void *user_data)
+{
+ struct ofono_stk *stk = user_data;
+
+ stk->respond_on_exit = FALSE;
+
+ if (stk->pending_cmd->send_dtmf.alpha_id &&
+ stk->pending_cmd->send_dtmf.alpha_id[0])
+ stk_alpha_id_unset(stk);
+
+ if (err == -ENOENT) {
+ struct stk_response rsp;
+ static unsigned char not_in_speech_call_result[] = { 0x07 };
+ static struct ofono_error error =
+ { .type = OFONO_ERROR_TYPE_FAILURE };
+
+ memset(&rsp, 0, sizeof(rsp));
+
+ rsp.result.type = STK_RESULT_TYPE_TERMINAL_BUSY;
+ rsp.result.additional_len = sizeof(not_in_speech_call_result);
+ rsp.result.additional = not_in_speech_call_result;
+
+ if (stk_respond(stk, &rsp, stk_command_cb))
+ stk_command_cb(&error, stk);
+
+ return;
+ }
+
+ if (err == -EINVAL) {
+ send_simple_response(stk, STK_RESULT_TYPE_DATA_NOT_UNDERSTOOD);
+ return;
+ }
+
+ if (err == 0)
+ send_simple_response(stk, STK_RESULT_TYPE_SUCCESS);
+ else
+ send_simple_response(stk, STK_RESULT_TYPE_NOT_CAPABLE);
+}
+
+static gboolean handle_command_send_dtmf(const struct stk_command *cmd,
+ struct stk_response *rsp,
+ struct ofono_stk *stk)
+{
+ static unsigned char not_in_speech_call_result[] = { 0x07 };
+ struct ofono_voicecall *vc = NULL;
+ struct ofono_atom *vc_atom;
+ int err;
+
+ vc_atom = __ofono_modem_find_atom(__ofono_atom_get_modem(stk->atom),
+ OFONO_ATOM_TYPE_VOICECALL);
+ if (vc_atom)
+ vc = __ofono_atom_get_data(vc_atom);
+
+ if (!vc) {
+ rsp->result.type = STK_RESULT_TYPE_NOT_CAPABLE;
+ return TRUE;
+ }
+
+ err = __ofono_voicecall_send_tone(vc, cmd->send_dtmf.dtmf,
+ dtmf_sent_cb, stk);
+
+ if (err == -EBUSY) {
+ rsp->result.type = STK_RESULT_TYPE_TERMINAL_BUSY;
+ return TRUE;
+ }
+
+ if (err == -ENOSYS) {
+ rsp->result.type = STK_RESULT_TYPE_NOT_CAPABLE;
+ return TRUE;
+ }
+
+ if (err == -ENOENT) {
+ rsp->result.type = STK_RESULT_TYPE_TERMINAL_BUSY;
+ rsp->result.additional_len = sizeof(not_in_speech_call_result);
+ rsp->result.additional = not_in_speech_call_result;
+ return TRUE;
+ }
+
+ 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;
+ }
+
+ if (cmd->send_dtmf.alpha_id && cmd->send_dtmf.alpha_id[0])
+ stk_alpha_id_set(stk, cmd->send_dtmf.alpha_id);
+
+ /*
+ * Note that we don't strictly require an agent to be connected,
+ * but to comply with 6.4.24 we need to send a End Session when
+ * the user decides so.
+ */
+ stk->respond_on_exit = TRUE;
+ stk->cancel_cmd = send_dtmf_cancel;
+
+ return FALSE;
+}
+
static void stk_proactive_command_cancel(struct ofono_stk *stk)
{
if (stk->immediate_response)
@@ -1741,6 +1870,11 @@ void ofono_stk_proactive_command_notify(struct ofono_stk
*stk,
&rsp, stk);
break;
+ case STK_COMMAND_TYPE_SEND_DTMF:
+ respond = handle_command_send_dtmf(stk->pending_cmd,
+ &rsp, stk);
+ break;
+
default:
rsp.result.type = STK_RESULT_TYPE_COMMAND_NOT_UNDERSTOOD;
break;
--
1.7.1.86.g0e460.dirty
_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono