From f7d4643cc551841815f621bfc86b7b1ece46be54 Mon Sep 17 00:00:00 2001 From: Andrzej Zaborowski Date: Tue, 15 Feb 2011 08:58:59 +0100 Subject: [PATCH] stk: Partially handle Refresh command Only the four "NAA initialisation" modes are handled at the moment. --- src/stk.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/stk.c b/src/stk.c index 199e02b1..bc46b2ff 100644 --- a/src/stk.c +++ b/src/stk.c @@ -1973,10 +1973,22 @@ static gboolean handle_command_send_ussd(const struct stk_command *cmd, return FALSE; } +static void free_idle_mode_text(struct ofono_stk *stk) +{ + g_free(stk->idle_mode_text); + stk->idle_mode_text = NULL; + + memset(&stk->idle_mode_icon, 0, sizeof(stk->idle_mode_icon)); +} + static gboolean handle_command_refresh(const struct stk_command *cmd, struct stk_response *rsp, struct ofono_stk *stk) { + struct ofono_error failure = { .type = OFONO_ERROR_TYPE_FAILURE }; + struct ofono_sim *sim = NULL; + struct ofono_atom *sim_atom; + int err; GSList *l; DBG(""); @@ -2030,6 +2042,59 @@ static gboolean handle_command_refresh(const struct stk_command *cmd, cmd->refresh.icon_id.qualifier); DBG("Alpha ID: %s", cmd->refresh.alpha_id); + sim_atom = __ofono_modem_find_atom(__ofono_atom_get_modem(stk->atom), + OFONO_ATOM_TYPE_SIM); + if (sim_atom) + sim = __ofono_atom_get_data(sim_atom); + + if (sim == NULL) { + rsp->result.type = STK_RESULT_TYPE_NOT_CAPABLE; + return TRUE; + } + + if (cmd->qualifier < 4) { + int qualifier = stk->pending_cmd->qualifier; + GSList *file_list = stk->pending_cmd->refresh.file_list; + + /* Don't free the list yet */ + stk->pending_cmd->refresh.file_list = NULL; + + /* + * Queue the TERMINAL RESPONSE before triggering potential + * file accesses. + */ + err = stk_respond(stk, rsp, stk_command_cb); + if (err) + stk_command_cb(&failure, stk); + + /* TODO: use the alphaId / icon */ + /* TODO: if AID is supplied, check its value */ + /* TODO: possibly check if a D-bus call is pending or + * an STK session ongoing. */ + + /* TODO: free some elements of the atom state */ + + switch (qualifier) { + case 0: + free_idle_mode_text(stk); + __ofono_sim_refresh(sim, file_list, TRUE, TRUE); + break; + case 1: + __ofono_sim_refresh(sim, file_list, FALSE, FALSE); + break; + case 2: + case 3: + free_idle_mode_text(stk); + __ofono_sim_refresh(sim, file_list, FALSE, TRUE); + break; + } + + g_slist_foreach(file_list, (GFunc) g_free, NULL); + g_slist_free(file_list); + + return FALSE; + } + rsp->result.type = STK_RESULT_TYPE_NOT_CAPABLE; return TRUE; }