From 56d927b8148da4fac42aa2c8dec8287dcd7a57c9 Mon Sep 17 00:00:00 2001 From: Andrzej Zaborowski Date: Wed, 7 Jul 2010 00:39:03 +0200 Subject: [PATCH] stk: Handle the Send SMS proactive command. --- src/stk.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) 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) -- 2.7.4