From: Denis Kenzior <denkenz@gmail.com>
To: ofono@ofono.org
Subject: Re: [PATCH 5/9] stk: Handle ENVELOPEs in a queue, retry on sim busy.
Date: Thu, 01 Jul 2010 14:57:47 -0500 [thread overview]
Message-ID: <4C2CF33B.90908@gmail.com> (raw)
In-Reply-To: <1277806448-5322-5-git-send-email-andrew.zaborowski@intel.com>
[-- Attachment #1: Type: text/plain, Size: 5640 bytes --]
Hi Andrew,
> +
> + gboolean envelope_q_busy;
In my opinion we can get rid of this variable. The SMS tx_queue does
almost the same thing without requiring such a variable.
> + GQueue *envelope_q;
> +};
> +
> +struct envelope_op {
> + struct stk_envelope e;
> + int retries;
> + void (*cb)(struct ofono_stk *stk, gboolean ok,
> + const unsigned char *data, int length);
Is the callback really needed? What can we intelligently do besides
printing an error to the log?
> };
>
> +#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,
> void (*cb)(const struct ofono_error *error,
> struct ofono_stk *stk))
> @@ -72,37 +86,87 @@ static int stk_respond(struct ofono_stk *stk, struct stk_response *rsp,
> return 0;
> }
>
> -static int stk_send_envelope(struct ofono_stk *stk, struct stk_envelope *e,
> - void (*cb)(const struct ofono_error *error,
> - const unsigned char *data,
> - int length,
> - struct ofono_stk *stk))
> +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;
> +
> + stk->envelope_q_busy = FALSE;
> +
> + if (op->retries > 0 && error->type == OFONO_ERROR_TYPE_SIM &&
> + error->error == 0x9300) {
> + op->retries--;
> + goto out;
You might really want to use an increasing retry timeout here.
> + }
> +
> + 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)
> {
> const guint8 *tlv;
> unsigned int tlv_len;
>
> - e->dst = STK_DEVICE_IDENTITY_TYPE_UICC;
> + while (stk->envelope_q_busy == FALSE &&
> + g_queue_get_length(stk->envelope_q) > 0) {
> + struct envelope_op *op = g_queue_peek_head(stk->envelope_q);
> +
> + tlv = stk_pdu_from_envelope(&op->e, &tlv_len);
Do you think it is efficient for us to re-encode the envelope every time
the queue is retried? What about encoding once during send (and
erroring out right away if that fails) and then simply storing the PDU?
Might make the code a bit simpler too.
> + if (!tlv) {
> + g_queue_pop_head(stk->envelope_q);
> +
> + op->cb(stk, FALSE, NULL, -1);
> + g_free(op);
> +
> + continue;
> + }
> +
> + stk->envelope_q_busy = TRUE;
> + stk->driver->envelope(stk, tlv_len, tlv, envelope_cb, stk);
> + }
> +}
> +
> +static int stk_send_envelope(struct ofono_stk *stk, struct stk_envelope *e,
> + void (*cb)(struct ofono_stk *stk, gboolean ok,
> + const uint8_t *data,
> + int length), int retries)
> +{
> + struct envelope_op *op;
>
> if (stk->driver->envelope == NULL)
> return -ENOSYS;
>
> - tlv = stk_pdu_from_envelope(e, &tlv_len);
> - if (!tlv)
> - return -EINVAL;
> + op = g_new0(struct envelope_op, 1);
> +
> + memcpy(&op->e, e, sizeof(op->e));
> + op->e.dst = STK_DEVICE_IDENTITY_TYPE_UICC;
> + op->cb = cb;
> + op->retries = retries;
> +
> + g_queue_push_tail(stk->envelope_q, op);
> +
> + envelope_queue_run(stk);
>
> - stk->driver->envelope(stk, tlv_len, tlv,
> - (ofono_stk_envelope_cb_t) cb, stk);
> return 0;
> }
>
> -static void stk_cbs_download_cb(const struct ofono_error *error,
> - const unsigned char *data, int len,
> - struct ofono_stk *stk)
> +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;
> }
>
> @@ -115,7 +179,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;
>
> @@ -125,9 +188,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,
> @@ -254,6 +318,10 @@ 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);
> +
> + g_queue_foreach(stk->envelope_q, (GFunc) g_free, NULL);
> + g_queue_free(stk->envelope_q);
> }
>
> static void stk_remove(struct ofono_atom *atom)
> @@ -309,6 +377,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)
Regards,
-Denis
next prev parent reply other threads:[~2010-07-01 19:57 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-29 10:14 [PATCH 1/9] stk: Utilities for proactive command/envelope handling Andrzej Zaborowski
2010-06-29 10:14 ` [PATCH 2/9] mbmmodem: Cancel running command on *STKEND Andrzej Zaborowski
2010-06-29 10:14 ` [PATCH 3/9] stk: Handle the More Time command as a nop Andrzej Zaborowski
2010-06-29 10:14 ` [PATCH 4/9] Make sim operations return sim error codes to core Andrzej Zaborowski
2010-07-01 19:16 ` Denis Kenzior
2010-06-29 10:14 ` [PATCH 5/9] stk: Handle ENVELOPEs in a queue, retry on sim busy Andrzej Zaborowski
2010-07-01 19:57 ` Denis Kenzior [this message]
2010-07-02 1:32 ` Andrzej Zaborowski
2010-07-02 2:28 ` Denis Kenzior
2010-07-02 19:15 ` Andrzej Zaborowski
2010-06-29 10:14 ` [PATCH 6/9] Add SimToolkit and SimApplicationAgent interfaces Andrzej Zaborowski
2010-07-02 17:21 ` Denis Kenzior
2010-07-02 19:55 ` Andrzej Zaborowski
2010-07-02 20:20 ` Denis Kenzior
2010-07-02 23:40 ` Andrzej Zaborowski
2010-07-03 0:23 ` Andrzej Zaborowski
2010-07-03 18:24 ` Denis Kenzior
2010-06-29 10:14 ` [PATCH 7/9] stk: Add menu related utilities Andrzej Zaborowski
2010-06-29 10:14 ` [PATCH 8/9] stk: Handle Select Item and Set Up Menu commands Andrzej Zaborowski
2010-06-29 10:14 ` [PATCH 9/9] stk: Handle the Display Text command Andrzej Zaborowski
2010-07-01 19:10 ` [PATCH 1/9] stk: Utilities for proactive command/envelope handling Denis Kenzior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4C2CF33B.90908@gmail.com \
--to=denkenz@gmail.com \
--cc=ofono@ofono.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.