All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrzej Zaborowski <andrew.zaborowski@intel.com>
To: ofono@ofono.org
Subject: Re: [PATCH v3 2/7] stk: Introduce BIP command handlers
Date: Mon, 16 May 2011 17:54:09 +0200	[thread overview]
Message-ID: <BANLkTin0K_wovwFOsmkO2JUhODC+H=O2yw@mail.gmail.com> (raw)
In-Reply-To: <1305307324-19548-2-git-send-email-philippe.nunes@linux.intel.com>

[-- Attachment #1: Type: text/plain, Size: 11112 bytes --]

Hi Philippe,

On 13 May 2011 19:21, Philippe Nunes <philippe.nunes@linux.intel.com> wrote:
> ---
>  src/stk.c |  425 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 files changed, 424 insertions(+), 1 deletions(-)
>
> diff --git a/src/stk.c b/src/stk.c
> index 8214b65..dec0439 100644
> --- a/src/stk.c
> +++ b/src/stk.c
> @@ -41,6 +41,7 @@
>  #include "smsutil.h"
>  #include "stkutil.h"
>  #include "stkagent.h"
> +#include "gprs.h"
>  #include "util.h"
>
>  static GSList *g_drivers = NULL;
> @@ -79,6 +80,11 @@ struct ofono_stk {
>
>        __ofono_sms_sim_download_cb_t sms_pp_cb;
>        void *sms_pp_userdata;
> +       struct stk_channel channel;
> +       struct stk_channel_data rx_buffer;
> +       struct stk_channel_data tx_buffer;
> +       gboolean link_on_demand;
> +       struct ofono_gprs *gprs;
>  };
>
>  struct envelope_op {
> @@ -104,6 +110,13 @@ static void timers_update(struct ofono_stk *stk);
>                result.additional_len = sizeof(addn_info);      \
>                result.additional = addn_info;                  \
>
> +/*
> + * According the structure and coding of the Terminal response defined in
> + * TS 102 223 section 6.8, the maximum number of bytes possible for the channel
> + * data object is 243
> + */
> +#define CHANNEL_DATA_OBJECT_MAX_LENGTH 243
> +
>  static int stk_respond(struct ofono_stk *stk, struct stk_response *rsp,
>                        ofono_stk_generic_cb_t cb)
>  {
> @@ -474,12 +487,49 @@ static void emit_menu_changed(struct ofono_stk *stk)
>        g_dbus_send_message(conn, signal);
>  }
>
> +static void stk_close_channel(struct ofono_stk *stk)
> +{
> +       /*
> +        * TODO
> +        * Deactivate and remove PDP context
> +        * Send the Terminal Response once the PDP context is deactivated
> +        */
> +
> +       /* Temporary implementation */
> +       g_free(stk->rx_buffer.data.array);
> +       g_free(stk->tx_buffer.data.array);
> +       stk->rx_buffer.data.array = NULL;
> +       stk->tx_buffer.data.array = NULL;
> +
> +       stk->channel.id = 0;
> +       stk->channel.status = STK_CHANNEL_PACKET_DATA_SERVICE_NOT_ACTIVATED;
> +
> +       if (stk->pending_cmd &&
> +                       stk->pending_cmd->type ==
> +                               STK_COMMAND_TYPE_CLOSE_CHANNEL)
> +               send_simple_response(stk, STK_RESULT_TYPE_SUCCESS);
> +       else {
> +               /*
> +                * TODO
> +                * Send Event channel status
> +                */
> +       }
> +}
> +
>  static void user_termination_cb(enum stk_agent_result result, void *user_data)
>  {
>        struct ofono_stk *stk = user_data;
>
> -       if (result == STK_AGENT_RESULT_TERMINATE)
> +       if (result != STK_AGENT_RESULT_TERMINATE)
> +               return;
> +
> +       if (stk->pending_cmd) {
> +               stk->cancel_cmd(stk);
>                send_simple_response(stk, STK_RESULT_TYPE_USER_TERMINATED);
> +       }
> +
> +       if (stk->channel.id)
> +               stk_close_channel(stk);
>  }
>
>  static void stk_alpha_id_set(struct ofono_stk *stk,
> @@ -510,6 +560,143 @@ static void stk_alpha_id_unset(struct ofono_stk *stk)
>        stk_agent_request_cancel(stk->current_agent);
>  }
>
> +
> +static void stk_open_channel(struct ofono_stk *stk)
> +{
> +       const struct stk_command_open_channel *oc;
> +       struct stk_response rsp;
> +       struct ofono_error failure = { .type = OFONO_ERROR_TYPE_FAILURE };
> +
> +       if (stk->pending_cmd == NULL ||
> +               stk->pending_cmd->type != STK_COMMAND_TYPE_OPEN_CHANNEL)
> +               return;
> +
> +       oc = &stk->pending_cmd->open_channel;
> +
> +       memset(&rsp, 0, sizeof(rsp));
> +       rsp.result.type = STK_RESULT_TYPE_SUCCESS;
> +
> +       stk->rx_buffer.data.array = g_try_malloc(oc->buf_size);
> +       if (stk->rx_buffer.data.array == NULL) {
> +               rsp.result.type = STK_RESULT_TYPE_NOT_CAPABLE;
> +               goto out;
> +       }
> +
> +       stk->tx_buffer.data.array = g_try_malloc(oc->buf_size);
> +       if (stk->tx_buffer.data.array == NULL) {
> +               rsp.result.type = STK_RESULT_TYPE_NOT_CAPABLE;
> +               goto out;
> +       }

A minor nitpick: we tend to return one of the temporary error codes
when out of memory.

> +
> +       stk->rx_buffer.data.len = oc->buf_size;
> +       stk->tx_buffer.data.len = oc->buf_size;
> +       stk->link_on_demand = (stk->pending_cmd->qualifier &
> +                               STK_OPEN_CHANNEL_FLAG_IMMEDIATE) ? FALSE : TRUE;
> +
> +       /*
> +        * TODO
> +        * Add a new primary PDP context based on the provided settings
> +        * Send the Terminal Response or wait until the PDP context is activated
> +        * in case of immediate link establishment not in background.
> +        */
> +out:
> +       if (stk_respond(stk, &rsp, stk_command_cb))
> +               stk_command_cb(&failure, stk);
> +}
> +
> +static void stk_send_data(struct ofono_stk *stk,
> +                               struct stk_common_byte_array data,
> +                               unsigned char qualifier)
> +{
> +       struct stk_response rsp;
> +       struct ofono_error failure = { .type = OFONO_ERROR_TYPE_FAILURE };
> +       unsigned int offset;
> +
> +       memset(&rsp, 0, sizeof(rsp));
> +       rsp.result.type = STK_RESULT_TYPE_SUCCESS;
> +
> +       if (data.len > stk->tx_buffer.data.len) {
> +               rsp.result.type = STK_RESULT_TYPE_BIP_ERROR;
> +               goto out;
> +       }
> +
> +       if (qualifier == STK_SEND_DATA_STORE_DATA) {
> +
> +               /*
> +                * check if the requested number of bytes of empty space
> +                * is available
> +                */
> +               if (data.len > stk->tx_buffer.tx_avail) {
> +                       rsp.result.type = STK_RESULT_TYPE_BIP_ERROR;
> +                       goto out;
> +               }
> +
> +               offset = stk->tx_buffer.data.len - stk->tx_buffer.tx_avail;
> +               memcpy(stk->tx_buffer.data.array + offset, data.array,
> +                               data.len);
> +
> +               stk->tx_buffer.tx_avail -= data.len;
> +               rsp.send_data.tx_avail = stk->tx_buffer.tx_avail;
> +               goto out;
> +       }
> +
> +       if (stk->channel.status == STK_CHANNEL_PACKET_DATA_SERVICE_NOT_ACTIVATED
> +                       && stk->link_on_demand == TRUE) {
> +               /*
> +                * TODO
> +                * activate the context, update the channel status
> +                * once the context is activated, send the data immediately
> +                * and flush the tx buffer
> +                */
> +       } else {
> +               /*
> +                * TODO
> +                * send the data immediately, flush the tx buffer
> +                */
> +               stk->tx_buffer.tx_avail = stk->tx_buffer.data.len;
> +               rsp.send_data.tx_avail = stk->tx_buffer.data.len;
> +       }
> +
> +out:
> +       if (stk_respond(stk, &rsp, stk_command_cb))
> +               stk_command_cb(&failure, stk);
> +}
> +
> +static void stk_receive_data(struct ofono_stk *stk, unsigned char data_len)
> +{
> +       struct stk_response rsp;
> +       struct ofono_error failure = { .type = OFONO_ERROR_TYPE_FAILURE };
> +
> +       memset(&rsp, 0, sizeof(rsp));
> +       rsp.result.type = STK_RESULT_TYPE_SUCCESS;
> +
> +       if (stk->rx_buffer.rx_remaining == 0) {
> +               rsp.result.type = STK_RESULT_TYPE_MISSING_INFO;
> +               goto out;
> +       }
> +
> +       if (data_len > stk->rx_buffer.rx_remaining) {
> +               rsp.result.type = STK_RESULT_TYPE_MISSING_INFO;
> +               data_len = stk->rx_buffer.rx_remaining;
> +       }
> +
> +       if (data_len > CHANNEL_DATA_OBJECT_MAX_LENGTH)
> +               data_len = CHANNEL_DATA_OBJECT_MAX_LENGTH;
> +
> +       rsp.receive_data.rx_data.array = stk->rx_buffer.data.array;
> +       rsp.receive_data.rx_data.len = data_len;
> +       stk->rx_buffer.rx_remaining -= data_len;
> +       rsp.receive_data.rx_remaining = stk->rx_buffer.rx_remaining;
> +
> +out:
> +       if (stk_respond(stk, &rsp, stk_command_cb))
> +               stk_command_cb(&failure, stk);
> +
> +       if (rsp.receive_data.rx_data.len && stk->rx_buffer.rx_remaining > 0)
> +               memmove(stk->rx_buffer.data.array, stk->rx_buffer.data.array +
> +                               data_len, stk->rx_buffer.rx_remaining);
> +}
> +
>  static int duration_to_msecs(const struct stk_duration *duration)
>  {
>        int msecs = duration->interval;
> @@ -2589,6 +2776,217 @@ static gboolean handle_command_launch_browser(const struct stk_command *cmd,
>        return FALSE;
>  }
>
> +
> +static void open_channel_cancel(struct ofono_stk *stk)
> +{
> +       /* TODO */
> +}
> +
> +static void confirm_open_channel_cb(enum stk_agent_result result,
> +                                       gboolean confirm,
> +                                       void *user_data)
> +{
> +       struct ofono_stk *stk = user_data;
> +
> +       switch (result) {
> +       case STK_AGENT_RESULT_TERMINATE:
> +               send_simple_response(stk, STK_RESULT_TYPE_USER_TERMINATED);
> +               return;
> +
> +       case STK_AGENT_RESULT_TIMEOUT:
> +               confirm = FALSE;
> +               /* Fall through */
> +
> +       case STK_AGENT_RESULT_OK:
> +               if (confirm)
> +                       break;
> +               /* Fall through */

According to 6.4.27 we should return STK_RESULT_TYPE_USER_REJECT if
the user does not accept the channel setup.

> +
> +       default:
> +               send_simple_response(stk, STK_RESULT_TYPE_TERMINAL_BUSY);
> +               return;
> +       }

I think Jeevaka determined that this needs an additional info field.

Best regards

  reply	other threads:[~2011-05-16 15:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-13 17:21 [PATCH v3 1/7] stk: Clear 'respond_on_exit' flag after sending the terminal response Philippe Nunes
2011-05-13 17:21 ` [PATCH v3 2/7] stk: Introduce BIP command handlers Philippe Nunes
2011-05-16 15:54   ` Andrzej Zaborowski [this message]
2011-05-17  9:55     ` Philippe Nunes
2011-05-13 17:22 ` [PATCH v3 3/7] gprs: Add 'stk' gprs context type Philippe Nunes
2011-05-13 17:22 ` [PATCH v3 4/7] gprs: Add private APIs for adding/activating/removing hidden PDP contexts Philippe Nunes
2011-05-13 17:22 ` [PATCH v3 5/7] stk: Use Gprs private APIs to handle the Open channel/Close Channel Philippe Nunes
2011-05-13 17:22 ` [PATCH v3 6/7] gprs: Add a host route for STK context type Philippe Nunes
2011-05-13 17:22 ` [PATCH v3 7/7] stk: Add support of the Setup event list proactive command Philippe Nunes
2011-05-16 17:00   ` Andrzej Zaborowski

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='BANLkTin0K_wovwFOsmkO2JUhODC+H=O2yw@mail.gmail.com' \
    --to=andrew.zaborowski@intel.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.