STK patches without agent
cover STK patches without agent
These are some patches I sent before reordered and refactored to skip stuff related to the Agent API, i.e. related to the UI.
Andrzej Zaborowski (14):
stk: Utilities for proactive command/envelope handling.
mbmmodem: End session on *STKEND.
stk: Handle the More Time proactive command as a nop. Add OFONO_ERROR_TYPE_SIM for negative SIM statuses.
atmodem: Make sim operations return sim error codes.
stk: Handle ENVELOPEs in a queue, retry on sim busy. Add __ofono_sms_submit for other atoms to submit SMs.
stk: Handle the Send SMS proactive command. Add Dbus interface names for STK.
stk: Handle the Set Up Idle Text proactive command.
sktutil: Use the Mandatory flag in parse_dataobj.
stkutil: Timer Value is conditional, not optional.
stk: Handle the Timer Management proactive command.
stk: Handle the Poll Interval proactive command.
drivers/atmodem/sim.c | 32 ++- drivers/atmodem/stk.c | 20 +- drivers/mbmmodem/stk.c | 3 + include/dbus.h | 2 + include/stk.h | 2 + include/types.h | 1 + src/ofono.h | 7 +- src/sms.c | 39 +++ src/stk.c | 667 ++++++++++++++++++++++++++++++++++++++++++++++-- src/stkutil.c | 12 +- 10 files changed, 744 insertions(+), 41 deletions(-)
PATCH 1/14 stk: Utilities for proactive command/envelope handling.
--- include/stk.h | 2 + src/stk.c | 173 +++++++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 157 insertions(+), 18 deletions(-)
include/stk.h +2 -0
@@ -65,6 +65,8 @@ void *ofono_stk_get_data(struct ofono_stk *stk);void ofono_stk_proactive_command_notify (struct ofono_stk *stk,int length,const unsigned char *pdu); +void ofono_stk_proactive_session_end_notify (struct ofono_stk *stk); + #ifdef __cplusplus }#endif
src/stk.c +155 -18
227 lines not on this page · raw message
Signature · 1 line
1.7.1.86.g0e460.dirty
PATCH 2/14 mbmmodem: End session on *STKEND.
In reply to Andrzej Zaborowski--- drivers/mbmmodem/stk.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/mbmmodem/stk.c +3 -0
@@ -179,6 +179,9 @@ static void stkn_notify(GAtResult *result, gpointer user_data)static void stkend_notify (GAtResult *result,gpointer user_data) { +struct ofono_stk *stk = user_data; + +ofono_stk_proactive_session_end_notify (stk); }static void mbm_stkc_cb (gboolean ok,GAtResult *result,gpointer user_data)
Signature · 1 line
1.7.1.86.g0e460.dirty
PATCH 3/14 stk: Handle the More Time proactive command as a nop.
In reply to Andrzej Zaborowski--- src/stk.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-)
src/stk.c +13 -0
@@ -143,6 +143,15 @@ static void stk_command_cb(const struct ofono_error *error, void *data)DBG ("TERMINAL RESPONSE to a command reported no errors" ); } +static gboolean handle_command_more_time (const struct stk_command *cmd, +struct stk_response *rsp, +struct ofono_stk *stk) +{ +/* Do nothing */ + +return TRUE; +} +static void stk_proactive_command_cancel (struct ofono_stk *stk) {if (!stk->pending_cmd)
@@ -213,6 +222,10 @@ void ofono_stk_proactive_command_notify(struct ofono_stk *stk, rsp.result.type =STK_RESULT_TYPE_COMMAND_NOT_UNDERSTOOD ;break ; +case STK_COMMAND_TYPE_MORE_TIME : + respond =handle_command_more_time (stk->pending_cmd, + &rsp, stk); +break ; }if (respond)
Signature · 1 line
1.7.1.86.g0e460.dirty
PATCH 4/14 Add OFONO_ERROR_TYPE_SIM for negative SIM statuses.
In reply to Andrzej ZaborowskiExpected value of the .error field is status word 1 and status word 2 in bits 8:15 and 0:7 of the field.
--- include/types.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
include/types.h +1 -0
@@ -60,6 +60,7 @@ enum ofono_error_type {OFONO_ERROR_TYPE_CME ,OFONO_ERROR_TYPE_CMS ,OFONO_ERROR_TYPE_CEER , +OFONO_ERROR_TYPE_SIM , OFONO_ERROR_TYPE_FAILURE };
Signature · 1 line
1.7.1.86.g0e460.dirty
PATCH 5/14 atmodem: Make sim operations return sim error codes.
In reply to Andrzej Zaborowski--- drivers/atmodem/sim.c | 32 +++++++++++++++++++++++++------- drivers/atmodem/stk.c | 20 ++++++++++++-------- 2 files changed, 37 insertions(+), 15 deletions(-)
drivers/atmodem/sim.c +25 -7
@@ -82,8 +82,15 @@ static void at_crsm_info_cb(gboolean ok, GAtResult *result, gpointer user_data)if (!g_at_result_iter_next_hexstring (&iter, &response, &len) || (sw1 !=0x90 && sw1 !=0x91 && sw1 !=0x92 ) || - (sw1 ==0x90 && sw2 !=0x00 )) - goto error; + (sw1 ==0x90 && sw2 !=0x00 )) { +memset (&error,0 ,sizeof (error)); + + error.type =OFONO_ERROR_TYPE_SIM ; + error.error = (sw1 <<8 ) | sw2; + +cb (&error,-1 ,-1 ,-1 ,NULL , cbd->data); +return ; + }DBG ("crsm_info_cb: %02x, %02x, %i" , sw1, sw2, len);
@@ -165,9 +172,18 @@ static void at_crsm_read_cb(gboolean ok, GAtResult *result,g_at_result_iter_next_number (&iter, &sw1);g_at_result_iter_next_number (&iter, &sw2); -if (!g_at_result_iter_next_hexstring (&iter, &response, &len) || - (sw1 !=0x90 && sw1 !=0x91 && sw1 !=0x92 && sw1 !=0x9f ) || - (sw1 ==0x90 && sw2 !=0x00 )) { +if ((sw1 !=0x90 && sw1 !=0x91 && sw1 !=0x92 && sw1 !=0x9f ) || + (sw1 ==0x90 && sw2 !=0x00 )) { +memset (&error,0 ,sizeof (error)); + + error.type =OFONO_ERROR_TYPE_SIM ; + error.error = (sw1 <<8 ) | sw2; + +cb (&error,NULL ,0 , cbd->data); +return ; + } + +if (!g_at_result_iter_next_hexstring (&iter, &response, &len)) {CALLBACK_WITH_FAILURE (cb,NULL ,0 , cbd->data);return ; }
@@ -255,8 +271,10 @@ static void at_crsm_update_cb(gboolean ok, GAtResult *result,if ((sw1 !=0x90 && sw1 !=0x91 && sw1 !=0x92 && sw1 !=0x9f ) || (sw1 ==0x90 && sw2 !=0x00 )) { -CALLBACK_WITH_FAILURE (cb, cbd->data); -return ; +memset (&error,0 ,sizeof (error)); + + error.type =OFONO_ERROR_TYPE_SIM ; + error.error = (sw1 <<8 ) | sw2; }DBG ("crsm_update_cb: %02x, %02x" , sw1, sw2);
drivers/atmodem/stk.c +12 -8
@@ -74,11 +74,13 @@ static void at_csim_envelope_cb(gboolean ok, GAtResult *result,if (rlen != len *2 || len <2 ) goto error; -if (response[len -2 ] !=0x90 && response[len -2 ] !=0x91 ) - goto error; +if ((response[len -2 ] !=0x90 && response[len -2 ] !=0x91 ) || + (response[len -2 ] ==0x90 && response[len -1 ] !=0 )) { +memset (&error,0 ,sizeof (error)); -if (response[len -2 ] ==0x90 && response[len -1 ] !=0 ) - goto error; + error.type =OFONO_ERROR_TYPE_SIM ; + error.error = (response[len -2 ] <<8 ) | response[len -1 ]; + }DBG ("csim_envelope_cb: %i" , len);
@@ -157,11 +159,13 @@ static void at_csim_terminal_response_cb(gboolean ok, GAtResult *result,if (rlen != len *2 || len <2 ) goto error; -if (response[len -2 ] !=0x90 && response[len -2 ] !=0x91 ) - goto error; +if ((response[len -2 ] !=0x90 && response[len -2 ] !=0x91 ) || + (response[len -2 ] ==0x90 && response[len -1 ] !=0 )) { +memset (&error,0 ,sizeof (error)); -if (response[len -2 ] ==0x90 && response[len -1 ] !=0 ) - goto error; + error.type =OFONO_ERROR_TYPE_SIM ; + error.error = (response[len -2 ] <<8 ) | response[len -1 ]; + }DBG ("csim_terminal_response_cb: %i" , len);
Signature · 1 line
1.7.1.86.g0e460.dirty
PATCH 6/14 stk: Handle ENVELOPEs in a queue, retry on sim busy.
In reply to Andrzej ZaborowskiSome envelope types need to be retried when sim reports busy status. Then envelopes such as Event Download need to be returned in the order of the event occurences, so need to be handled in a queue.
--- src/stk.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 77 insertions(+), 14 deletions(-)
src/stk.c +77 -14
@@ -46,8 +46,21 @@ struct ofono_stk {struct stk_command *pending_cmd;void (*cancel_cmd)(struct ofono_stk *stk);gboolean cancelled; +GQueue *envelope_q; }; +struct envelope_op { +uint8_t tlv[256 ]; +unsigned int tlv_len; +int retries; +void (*cb)(struct ofono_stk *stk,gboolean ok, +const unsigned char *data,int length); +}; + +#define ENVELOPE_RETRIES_DEFAULT 5 + +static void envelope_queue_run (struct ofono_stk *stk); +static int stk_respond (struct ofono_stk *stk,struct stk_response *rsp,ofono_stk_generic_cb_t cb) {
@@ -75,35 +88,80 @@ static int stk_respond(struct ofono_stk *stk, struct stk_response *rsp,return 0 ; } +static void envelope_cb (const struct ofono_error *error,const uint8_t *data, +int length,void *user_data) +{ +struct ofono_stk *stk = user_data; +struct envelope_op *op =g_queue_peek_head (stk->envelope_q); +gboolean result = TRUE; + +if (op->retries >0 && error->type ==OFONO_ERROR_TYPE_SIM && + error->error ==0x9300 ) { + op->retries--; + goto out; + } + +if (error->type !=OFONO_ERROR_TYPE_NO_ERROR ) + result = FALSE; + +g_queue_pop_head (stk->envelope_q); + +if (op->cb) + op->cb (stk, result, data, length); + +g_free (op); + +out: +envelope_queue_run (stk); +} + +static void envelope_queue_run (struct ofono_stk *stk) +{ +while (g_queue_get_length (stk->envelope_q) >0 ) { +struct envelope_op *op =g_queue_peek_head (stk->envelope_q); + + stk->driver->envelope (stk, op->tlv_len, op->tlv, + envelope_cb, stk); + } +} +static int stk_send_envelope (struct ofono_stk *stk,struct stk_envelope *e, -ofono_stk_envelope_cb_t cb) +void (*cb)(struct ofono_stk *stk,gboolean ok, +const uint8_t *data, +int length),int retries) { -const guint8 *tlv; +const uint8_t *tlv;unsigned int tlv_len; +struct envelope_op *op;if (stk->driver->envelope ==NULL )return -ENOSYS ; e->dst =STK_DEVICE_IDENTITY_TYPE_UICC ; - tlv =stk_pdu_from_envelope (e, &tlv_len);if (!tlv)return -EINVAL ; - stk->driver->envelope (stk, tlv_len, tlv, cb, stk); + op = g_new0(struct envelope_op, 1); + + op->cb = cb; + op->retries = retries; +memcpy (op->tlv, tlv, tlv_len); + op->tlv_len = tlv_len; + +g_queue_push_tail (stk->envelope_q, op); + +if (g_queue_get_length (stk->envelope_q) ==1 ) +envelope_queue_run (stk);return 0 ; } -static void stk_cbs_download_cb (const struct ofono_error *error, -const unsigned char *data,int len,void *user) +static void stk_cbs_download_cb (struct ofono_stk *stk,gboolean ok, +const unsigned char *data,int len) { -if (error->type !=OFONO_ERROR_TYPE_NO_ERROR ) { +if (!ok) {ofono_error ("CellBroadcast download to UICC failed" ); -/* -* "The ME may retry to deliver the same Cell Broadcast -* page." -*/ return ; }
@@ -116,7 +174,6 @@ static void stk_cbs_download_cb(const struct ofono_error *error,void __ofono_cbs_sim_download (struct ofono_stk *stk,const struct cbs *msg) { -struct ofono_error error = { .type =OFONO_ERROR_TYPE_FAILURE };struct stk_envelope e;int err;
@@ -126,9 +183,10 @@ void __ofono_cbs_sim_download(struct ofono_stk *stk, const struct cbs *msg) e.src =STK_DEVICE_IDENTITY_TYPE_NETWORK ;memcpy (&e.cbs_pp_download.page, msg,sizeof (msg)); - err =stk_send_envelope (stk, &e, stk_cbs_download_cb); + err =stk_send_envelope (stk, &e, stk_cbs_download_cb, +ENVELOPE_RETRIES_DEFAULT );if (err) -stk_cbs_download_cb (&error,NULL ,-1 , stk); +stk_cbs_download_cb (stk, FALSE,NULL ,-1 ); }static void stk_command_cb (const struct ofono_error *error,void *data)
@@ -281,6 +339,9 @@ static void stk_unregister(struct ofono_atom *atom)stk_command_free (stk->pending_cmd); stk->pending_cmd =NULL ; } + +g_queue_foreach (stk->envelope_q, (GFunc ) g_free,NULL ); +g_queue_free (stk->envelope_q); }static void stk_remove (struct ofono_atom *atom)
@@ -336,6 +397,8 @@ struct ofono_stk *ofono_stk_create(struct ofono_modem *modem,void ofono_stk_register (struct ofono_stk *stk) {__ofono_atom_register (stk->atom, stk_unregister); + + stk->envelope_q =g_queue_new (); }void ofono_stk_remove (struct ofono_stk *stk)
Signature · 1 line
1.7.1.86.g0e460.dirty
PATCH 7/14 Add __ofono_sms_submit for other atoms to submit SMs.
In reply to Andrzej Zaborowski--- src/ofono.h | 7 ++++++- src/sms.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletions(-)
src/ofono.h +6 -1
@@ -168,12 +168,17 @@ void __ofono_atom_free(struct ofono_atom *atom);#include <ofono/cbs.h> #include <ofono/devinfo.h> #include <ofono/phonebook.h> -#include <ofono/sms.h> #include <ofono/voicecall.h> #include <ofono/gprs.h> #include <ofono/gprs-context.h> #include <ofono/radio-settings.h> +#include <ofono/sms.h> + +struct sms ; +void __ofono_sms_submit (struct ofono_sms *sms,const struct sms *msg, +ofono_sms_submit_cb_t cb,void *data); +#include <ofono/sim.h> #include <ofono/stk.h>
src/sms.c +39 -0
@@ -87,6 +87,8 @@ struct tx_queue_entry {DBusMessage *msg;gboolean status_report;struct sms_address receiver; +ofono_sms_submit_cb_t cb; +void *data; };static const char *sms_bearer_to_string (int bearer)
@@ -413,6 +415,9 @@ static void tx_finished(const struct ofono_error *error, int mr, void *data)DBG ("tx_finished" );if (error->type !=OFONO_ERROR_TYPE_NO_ERROR ) { +if (entry->cb) + goto callback; + entry->retry +=1 ;if (entry->retry !=TXQ_MAX_RETRIES ) {
@@ -459,6 +464,9 @@ static void tx_finished(const struct ofono_error *error, int mr, void *data)return ; } +if (entry->cb) + goto callback; + entry =g_queue_pop_head (sms->txq);__ofono_dbus_pending_reply (&entry->msg,dbus_message_new_method_return (entry->msg));
@@ -473,6 +481,19 @@ static void tx_finished(const struct ofono_error *error, int mr, void *data)DBG ("Scheduling next" ); sms->tx_source =g_timeout_add (0 , tx_next, sms); } + +return ; + +callback: + entry =g_queue_pop_head (sms->txq); + + entry->cb (error, mr, entry->data); + +g_free (entry->pdus); +g_free (entry); + +if (g_queue_peek_head (sms->txq)) + sms->tx_source =g_timeout_add (0 , tx_next, sms); }static gboolean tx_next (gpointer user_data)
@@ -1285,3 +1306,21 @@ void *ofono_sms_get_data(struct ofono_sms *sms) {return sms->driver_data; } + +void __ofono_sms_submit (struct ofono_sms *sms,const struct sms *msg, +ofono_sms_submit_cb_t cb,void *data) +{ +GSList msg_list = { + .data = (void *) msg, + .next =NULL , + }; +struct tx_queue_entry *entry =create_tx_queue_entry (&msg_list); + + entry->cb = cb; + entry->data = data; + +g_queue_push_tail (sms->txq, entry); + +if (g_queue_get_length (sms->txq) ==1 ) + sms->tx_source =g_timeout_add (0 , tx_next, sms); +}
Signature · 1 line
1.7.1.86.g0e460.dirty
PATCH 8/14 stk: Handle the Send SMS proactive command.
In reply to Andrzej Zaborowski--- src/stk.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 104 insertions(+), 0 deletions(-)
src/stk.c +104 -0
@@ -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 5static 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)
Signature · 1 line
1.7.1.86.g0e460.dirty
PATCH 9/14 Add Dbus interface names for STK.
In reply to Andrzej Zaborowski--- include/dbus.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
include/dbus.h +2 -0
@@ -49,6 +49,8 @@ extern "C" {#define OFONO_VOICECALL_MANAGER_INTERFACE "org.ofono.VoiceCallManager"#define OFONO_DATA_CONNECTION_MANAGER_INTERFACE "org.ofono.DataConnectionManager"#define OFONO_DATA_CONTEXT_INTERFACE "org.ofono.PrimaryDataContext" +#define OFONO_STK_INTERFACE OFONO_SERVICE ".SimToolkit" +#define OFONO_SIM_APP_INTERFACE OFONO_SERVICE ".SimApplicationAgent"/* Essentially a{sv} */ #define OFONO_PROPERTIES_ARRAY_SIGNATURE DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING \
Signature · 1 line
1.7.1.86.g0e460.dirty
PATCH 10/14 stk: Handle the Set Up Idle Text proactive command.
In reply to Andrzej ZaborowskiThis adds a SimToolkit dbus interface with just one property (IdleModeText).
--- src/stk.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 98 insertions(+), 0 deletions(-)
src/stk.c +98 -0
@@ -50,6 +50,7 @@ struct ofono_stk {GQueue *envelope_q;struct sms_submit_req *sms_submit_req; +char *idle_mode_text; };struct envelope_op {
@@ -219,6 +220,45 @@ static void stk_alpha_id_unset(struct ofono_stk *stk)/* TODO */ } +static DBusMessage *stk_get_properties (DBusConnection *conn, +DBusMessage *msg,void *data) +{ +struct ofono_stk *stk = data; +DBusMessage *reply; +DBusMessageIter iter; +DBusMessageIter dict; +const char *idle_mode_text = stk->idle_mode_text ?:"" ; + + reply =dbus_message_new_method_return (msg); +if (!reply) +return NULL ; + +dbus_message_iter_init_append (reply, &iter); + +dbus_message_iter_open_container (&iter,DBUS_TYPE_ARRAY , +OFONO_PROPERTIES_ARRAY_SIGNATURE , + &dict); + +ofono_dbus_dict_append (&dict,"IdleModeText" , +DBUS_TYPE_STRING , &idle_mode_text); + +dbus_message_iter_close_container (&iter, &dict); + +return reply; +} + +static GDBusMethodTable stk_methods[] = { + {"GetProperties" ,"" ,"a{sv}" ,stk_get_properties }, + + { } +}; + +static GDBusSignalTable stk_signals[] = { + {"PropertyChanged" ,"sv" }, + + { } +}; +static gboolean handle_command_more_time (const struct stk_command *cmd,struct stk_response *rsp,struct ofono_stk *stk)
@@ -310,6 +350,34 @@ static gboolean handle_command_send_sms(const struct stk_command *cmd,return FALSE; } +static gboolean handle_command_set_idle_text (const struct stk_command *cmd, +struct stk_response *rsp, +struct ofono_stk *stk) +{ +const char *idle_mode_text; +DBusConnection *conn =ofono_dbus_get_connection (); +const char *path =__ofono_atom_get_path (stk->atom); + +if (stk->idle_mode_text) { +g_free (stk->idle_mode_text); + stk->idle_mode_text =NULL ; + } + +if (!cmd->setup_idle_mode_text.text) + goto out; + + stk->idle_mode_text =g_strdup (cmd->setup_idle_mode_text.text); + +out: + idle_mode_text = stk->idle_mode_text ?:"" ; +ofono_dbus_signal_property_changed (conn, path,OFONO_STK_INTERFACE , +"IdleModeText" , +DBUS_TYPE_STRING , + &idle_mode_text); + +return TRUE; +} +static void stk_proactive_command_cancel (struct ofono_stk *stk) {if (!stk->pending_cmd)
@@ -388,6 +456,10 @@ void ofono_stk_proactive_command_notify(struct ofono_stk *stk, respond =handle_command_send_sms (stk->pending_cmd, &rsp, stk);break ; +case STK_COMMAND_TYPE_SETUP_IDLE_MODE_TEXT : + respond =handle_command_set_idle_text (stk->pending_cmd, + &rsp, stk); +break ; }if (respond)
@@ -438,14 +510,25 @@ void ofono_stk_driver_unregister(const struct ofono_stk_driver *d)static void stk_unregister (struct ofono_atom *atom) {struct ofono_stk *stk =__ofono_atom_get_data (atom); +DBusConnection *conn =ofono_dbus_get_connection (); +struct ofono_modem *modem =__ofono_atom_get_modem (atom); +const char *path =__ofono_atom_get_path (atom);if (stk->pending_cmd) {stk_command_free (stk->pending_cmd); stk->pending_cmd =NULL ; } +if (stk->idle_mode_text) { +g_free (stk->idle_mode_text); + stk->idle_mode_text =NULL ; + } +g_queue_foreach (stk->envelope_q, (GFunc ) g_free,NULL );g_queue_free (stk->envelope_q); + +ofono_modem_remove_interface (modem,OFONO_STK_INTERFACE ); +g_dbus_unregister_interface (conn, path,OFONO_STK_INTERFACE ); }static void stk_remove (struct ofono_atom *atom)
@@ -500,6 +583,21 @@ struct ofono_stk *ofono_stk_create(struct ofono_modem *modem,void ofono_stk_register (struct ofono_stk *stk) { +DBusConnection *conn =ofono_dbus_get_connection (); +struct ofono_modem *modem =__ofono_atom_get_modem (stk->atom); +const char *path =__ofono_atom_get_path (stk->atom); + +if (!g_dbus_register_interface (conn, path,OFONO_STK_INTERFACE , + stk_methods, stk_signals,NULL , + stk,NULL )) { +ofono_error ("Could not create %s interface" , +OFONO_STK_INTERFACE ); + +return ; + } + +ofono_modem_add_interface (modem,OFONO_STK_INTERFACE ); +__ofono_atom_register (stk->atom, stk_unregister); stk->envelope_q =g_queue_new ();
Signature · 1 line
1.7.1.86.g0e460.dirty
PATCH 11/14 sktutil: Use the Mandatory flag in parse_dataobj.
In reply to Andrzej ZaborowskiWe need to look at the Mandatory flag and not at the Minimum flag when parsing CTLVs. The Minimum flag is important when encoding CTLVs because CR bit is set according to it.
--- src/stkutil.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
src/stkutil.c +3 -3
@@ -2324,8 +2324,8 @@ static enum stk_command_parse_result parse_dataobj(if (comprehension_tlv_iter_get_tag (iter) == entry->type)break ; -/* Can't skip over Minimum objects */ -if (entry->flags &DATAOBJ_FLAG_MINIMUM ) { +/* Can't skip over mandatory objects */ +if (entry->flags &DATAOBJ_FLAG_MANDATORY ) { l2 =NULL ;break ; }
@@ -2352,7 +2352,7 @@ static enum stk_command_parse_result parse_dataobj(for (; l; l = l->next) {struct dataobj_handler_entry *entry = l->data; -if (entry->flags &DATAOBJ_FLAG_MINIMUM ) +if (entry->flags &DATAOBJ_FLAG_MANDATORY ) minimum_set = FALSE; }
Signature · 1 line
1.7.1.86.g0e460.dirty
PATCH 12/14 stkutil: Timer Value is conditional, not optional.
In reply to Andrzej ZaborowskiMake the parser check that the value is present when necessary, so that stk.c doesn't have to check this.
--- src/stkutil.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
src/stkutil.c +5 -1
@@ -3000,6 +3000,7 @@ static enum stk_command_parse_result parse_timer_mgmt( struct comprehension_tlv_iter *iter) {struct stk_command_timer_mgmt *obj = &command->timer_mgmt; +enum stk_data_object_flag value_flags =0 ;if (command->src !=STK_DEVICE_IDENTITY_TYPE_UICC )return STK_PARSE_RESULT_DATA_NOT_UNDERSTOOD ;
@@ -3007,10 +3008,13 @@ static enum stk_command_parse_result parse_timer_mgmt(if (command->dst !=STK_DEVICE_IDENTITY_TYPE_TERMINAL )return STK_PARSE_RESULT_DATA_NOT_UNDERSTOOD ; +if ((command->qualifier &3 ) ==0 )/* Start a timer */ + value_flags =DATAOBJ_FLAG_MANDATORY ; +return parse_dataobj (iter,STK_DATA_OBJECT_TYPE_TIMER_ID ,DATAOBJ_FLAG_MANDATORY |DATAOBJ_FLAG_MINIMUM , &obj->timer_id, -STK_DATA_OBJECT_TYPE_TIMER_VALUE ,0 , +STK_DATA_OBJECT_TYPE_TIMER_VALUE , value_flags, &obj->timer_value,STK_DATA_OBJECT_TYPE_INVALID ); }
Signature · 1 line
1.7.1.86.g0e460.dirty
PATCH 13/14 stk: Handle the Timer Management proactive command.
In reply to Andrzej Zaborowski--- src/stk.c | 165 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 165 insertions(+), 0 deletions(-)
src/stk.c +165 -0
@@ -31,6 +31,7 @@#include <glib.h> #include <gdbus.h> #include <errno.h> +#include <time.h> #include "ofono.h"
@@ -40,6 +41,11 @@static GSList *g_drivers =NULL ; +struct stk_timer { +time_t expiry; +time_t start; +}; +struct ofono_stk {const struct ofono_stk_driver *driver;void *driver_data;
@@ -49,6 +55,9 @@ struct ofono_stk {gboolean cancelled;GQueue *envelope_q; +struct stk_timer timers[8 ]; +guint timers_source; +struct sms_submit_req *sms_submit_req;char *idle_mode_text; };
@@ -69,6 +78,7 @@ struct sms_submit_req {#define ENVELOPE_RETRIES_DEFAULT 5static void envelope_queue_run (struct ofono_stk *stk); +static void timers_update (struct ofono_stk *stk);static int stk_respond (struct ofono_stk *stk,struct stk_response *rsp,ofono_stk_generic_cb_t cb)
@@ -378,6 +388,152 @@ out:return TRUE; } +static void timer_expiration_cb (struct ofono_stk *stk,gboolean ok, +const unsigned char *data,int len) +{ +if (!ok) { +ofono_error ("Timer Expiration reporting failed" ); +return ; + } + +if (len) +ofono_error ("Timer Expiration returned %i bytes of data" , + len); + +DBG ("Timer Expiration reporting to UICC reported no error" ); +} + +static gboolean timers_cb (gpointer user_data) +{ +struct ofono_stk *stk = user_data; + + stk->timers_source =0 ; + +timers_update (stk); + +return FALSE; +} + +static void timer_value_from_seconds (struct stk_timer_value *val,int seconds) +{ + val->has_value = TRUE; + val->hour = seconds /3600 ; + seconds -= val->hour *3600 ; + val->minute = seconds /60 ; + seconds -= val->minute *60 ; + val->second = seconds; +} + +static void timers_update (struct ofono_stk *stk) +{ +time_t min =0 , now =time (NULL ); +int i; + +if (stk->timers_source) { +g_source_remove (stk->timers_source); + stk->timers_source =0 ; + } + +for (i =0 ; i <8 ; i++) { +if (!stk->timers[i].expiry) +continue ; + +if (stk->timers[i].expiry <= now) { +struct stk_envelope e; +int seconds = now - stk->timers[i].start; + + stk->timers[i].expiry =0 ; + +memset (&e,0 ,sizeof (e)); + + e.type =STK_ENVELOPE_TYPE_TIMER_EXPIRATION ; + e.src =STK_DEVICE_IDENTITY_TYPE_TERMINAL , + e.timer_expiration.id = i +1 ; +timer_value_from_seconds (&e.timer_expiration.value, + seconds); + +/* +* TODO: resubmit until success, providing current +* time difference every time we re-send. +*/ +if (stk_send_envelope (stk, &e, timer_expiration_cb,0 )) +timer_expiration_cb (stk, FALSE,NULL ,-1 ); + +continue ; + } + +if (stk->timers[i].expiry < now + min || min ==0 ) + min = stk->timers[i].expiry - now; + } + +if (min) + stk->timers_source =g_timeout_add_seconds (min, timers_cb, stk); +} + +static gboolean handle_command_timer_mgmt (const struct stk_command *cmd, +struct stk_response *rsp, +struct ofono_stk *stk) +{ +int op = cmd->qualifier &3 ; +time_t seconds, now =time (NULL ); +struct stk_timer *tmr; + +if (cmd->timer_mgmt.timer_id <1 || cmd->timer_mgmt.timer_id >8 ) { + rsp->result.type =STK_RESULT_TYPE_DATA_NOT_UNDERSTOOD ; +return TRUE; + } + + tmr = &stk->timers[cmd->timer_mgmt.timer_id -1 ]; + +switch (op) { +case 0 :/* Start */ + seconds = cmd->timer_mgmt.timer_value.second + + cmd->timer_mgmt.timer_value.minute *60 + + cmd->timer_mgmt.timer_value.hour *3600 ; + + tmr->expiry = now + seconds; + tmr->start = now; + +timers_update (stk); +break ; + +case 1 :/* Deactivate */ +if (!tmr->expiry) { + rsp->result.type =STK_RESULT_TYPE_TIMER_CONFLICT ; + +return TRUE; + } + + seconds =MAX (0 , tmr->expiry - now); + tmr->expiry =0 ; + +timers_update (stk); + +timer_value_from_seconds (&rsp->timer_mgmt.value, seconds); +break ; + +case 2 :/* Get current value */ +if (!tmr->expiry) { + rsp->result.type =STK_RESULT_TYPE_TIMER_CONFLICT ; + +return TRUE; + } + + seconds =MAX (0 , tmr->expiry - now); +timer_value_from_seconds (&rsp->timer_mgmt.value, seconds); +break ; + +default : + rsp->result.type =STK_RESULT_TYPE_DATA_NOT_UNDERSTOOD ; + +return TRUE; + } + + rsp->timer_mgmt.id = cmd->timer_mgmt.timer_id; + +return TRUE; +} +static void stk_proactive_command_cancel (struct ofono_stk *stk) {if (!stk->pending_cmd)
@@ -460,6 +616,10 @@ void ofono_stk_proactive_command_notify(struct ofono_stk *stk, respond =handle_command_set_idle_text (stk->pending_cmd, &rsp, stk);break ; +case STK_COMMAND_TYPE_TIMER_MANAGEMENT : + respond =handle_command_timer_mgmt (stk->pending_cmd, + &rsp, stk); +break ; }if (respond)
@@ -524,6 +684,11 @@ static void stk_unregister(struct ofono_atom *atom) stk->idle_mode_text =NULL ; } +if (stk->timers_source) { +g_source_remove (stk->timers_source); + stk->timers_source =0 ; + } +g_queue_foreach (stk->envelope_q, (GFunc ) g_free,NULL );g_queue_free (stk->envelope_q);
Signature · 1 line
1.7.1.86.g0e460.dirty
PATCH 14/14 stk: Handle the Poll Interval proactive command.
In reply to Andrzej Zaborowski--- src/stk.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 45 insertions(+), 0 deletions(-)
src/stk.c +45 -0
@@ -534,6 +534,47 @@ static gboolean handle_command_timer_mgmt(const struct stk_command *cmd,return TRUE; } +static gboolean handle_command_poll_interval (const struct stk_command *cmd, +struct stk_response *rsp, +struct ofono_stk *stk) +{ +struct ofono_modem *modem =__ofono_atom_get_modem (stk->atom); +int seconds; + +switch (cmd->poll_interval.duration.unit) { +case STK_DURATION_TYPE_MINUTES : + seconds = cmd->poll_interval.duration.interval *60 ; +break ; +case STK_DURATION_TYPE_SECONDS : + seconds = cmd->poll_interval.duration.interval; +break ; +case STK_DURATION_TYPE_SECOND_TENTHS : + seconds = (4 + cmd->poll_interval.duration.interval) /10 ; +if (seconds <1 ) + seconds =1 ; +break ; + } + +if (ofono_modem_set_integer (modem,"status-poll-interval" , seconds)) { + seconds =ofono_modem_get_integer (modem, +"status-poll-interval" ); +if (!seconds) + seconds =30 ; + } + +if (seconds >255 ) { + rsp->poll_interval.max_interval.unit = +STK_DURATION_TYPE_MINUTES ; + rsp->poll_interval.max_interval.interval = seconds /60 ; + }else { + rsp->poll_interval.max_interval.unit = +STK_DURATION_TYPE_SECONDS ; + rsp->poll_interval.max_interval.interval = seconds; + } + +return TRUE; +} +static void stk_proactive_command_cancel (struct ofono_stk *stk) {if (!stk->pending_cmd)
@@ -620,6 +661,10 @@ void ofono_stk_proactive_command_notify(struct ofono_stk *stk, respond =handle_command_timer_mgmt (stk->pending_cmd, &rsp, stk);break ; +case STK_COMMAND_TYPE_POLL_INTERVAL : + respond =handle_command_poll_interval (stk->pending_cmd, + &rsp, stk); +break ; }if (respond)
Signature · 1 line
1.7.1.86.g0e460.dirty
Hi Andrew,
Quoted 18 lines · Andrzej Zaborowski
These are some patches I sent before reordered and refactored to skip stuff related to the Agent API, i.e. related to the UI.
Andrzej Zaborowski (14):
stk: Utilities for proactive command/envelope handling.
mbmmodem: End session on *STKEND.
stk: Handle the More Time proactive command as a nop. AddOFONO_ERROR_TYPE_SIMfor negative SIM statuses.
atmodem: Make sim operations return sim error codes.
stk: Handle ENVELOPEs in a queue, retry on sim busy. Add__ofono_sms_submitfor other atoms to submit SMs.
stk: Handle the Send SMS proactive command. Add Dbus interface names for STK.
stk: Handle the Set Up Idle Text proactive command.
sktutil: Use the Mandatory flag inparse_dataobj.
stkutil: Timer Value is conditional, not optional.
stk: Handle the Timer Management proactive command.
stk: Handle the Poll Interval proactive command.
All patches in this series have been pushed upstream with some refactoring afterwards. Please review and make sure I didn't screw something up.
Regards,
-Denis
Hi,
Quoted 20 lines · Denis Kenzior
Quoted 18 lines · Andrzej Zaborowski
These are some patches I sent before reordered and refactored to skip stuff related to the Agent API, i.e. related to the UI.
Andrzej Zaborowski (14):
stk: Utilities for proactive command/envelope handling.
mbmmodem: End session on *STKEND.
stk: Handle the More Time proactive command as a nop. AddOFONO_ERROR_TYPE_SIMfor negative SIM statuses.
atmodem: Make sim operations return sim error codes.
stk: Handle ENVELOPEs in a queue, retry on sim busy. Add__ofono_sms_submitfor other atoms to submit SMs.
stk: Handle the Send SMS proactive command. Add Dbus interface names for STK.
stk: Handle the Set Up Idle Text proactive command.
sktutil: Use the Mandatory flag inparse_dataobj.
stkutil: Timer Value is conditional, not optional.
stk: Handle the Timer Management proactive command.
stk: Handle the Poll Interval proactive command.
Quoted 3 lines
All patches in this series have been pushed upstream with some refactoring afterwards. Please review and make sure I didn't screw something up.
Thanks, just a small change to remove the seconds == 0 check for Set Poll Interval. Seconds can't be 0 or parsing would fail. The logic behind the original code was:
Try to set the modem property to "seconds".
If setting fails, then return the previous value (which is actually the nearest value we could accept).
If getting previous value fails (function returns 0) then return 30 secs, the default value, which also happens to be the nearest we could accept.
Best regards
From c617d567f1c2345fdbce42080531f099a8f964dd Mon Sep 17 00:00:00 2001
From: Andrzej Zaborowski <[email protected]>
Date: Tue, 13 Jul 2010 16:23:35 +0200
Subject: [PATCH] stk: Remove an unneeded check.
--- src/stk.c | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-)
src/stk.c +0 -3
@@ -977,9 +977,6 @@ static gboolean handle_command_poll_interval(const struct stk_command *cmd,return TRUE; } -if (seconds ==0 ) - seconds =30 ; -ofono_modem_set_integer (modem,"status-poll-interval" , seconds);if (seconds >255 ) {
Signature · 1 line
1.7.1.86.g0e460.dirty
Hi Andrew,
Quoted 8 lines
Quoted 3 lines
All patches in this series have been pushed upstream with some refactoring afterwards. Please review and make sure I didn't screw something up.
Thanks, just a small change to remove the seconds == 0 check for Set Poll Interval. Seconds can't be 0 or parsing would fail. The logic behind the original code was:
Quoted 7 lines
Try to set the modem property to "seconds".
If setting fails, then return the previous value (which is actually the nearest value we could accept).
If getting previous value fails (function returns 0) then return 30 secs, the default value, which also happens to be the nearest we could accept.
Thanks for catching this. Patch has been applied.
Regards,
-Denis