Skip to contentSkip to conversation

stk: Introduce BIP command handlers

PATCH In review Philippe Nunes 2 participants 3 messages Mar 22, 2011 – Mar 30, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 3/6 stk: Introduce BIP command handlers

---
 src/stk.c |  307 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 307 insertions(+), 0 deletions(-)
src/stk.c +307 -0
index 68b6240..d224360 100644
@@ -79,6 +79,9 @@ 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;
 };
 
 struct envelope_op {
@@ -2548,6 +2551,285 @@ static gboolean handle_command_launch_browser(const struct stk_command *cmd,
 	return FALSE;
 }
 
+static void confirm_open_channel_cb(enum stk_agent_result result,
+					gboolean confirm,
+					void *user_data)
+{
+	struct ofono_stk *stk = user_data;
+	unsigned char no_cause[] = { 0x00 };
+	struct ofono_error failure = { .type = OFONO_ERROR_TYPE_FAILURE };
+	struct stk_response rsp;
+
+	stk->respond_on_exit = FALSE;
+
+	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 */
+
+	default:
+		memset(&rsp, 0, sizeof(rsp));
+		ADD_ERROR_RESULT(rsp.result, STK_RESULT_TYPE_TERMINAL_BUSY,
+					no_cause);
+
+		if (stk_respond(stk, &rsp, stk_command_cb))
+			stk_command_cb(&failure, stk);
+
+		return;
+	}
+
+	/*
+	 * TODO
+	 * setup the channel
+	 */
+
+	/* For now, return  "Command beyond terminal's capabilities" */
+	send_simple_response(stk, STK_RESULT_TYPE_NOT_CAPABLE);
+}
+
+static gboolean handle_command_open_channel(const struct stk_command *cmd,
+						struct stk_response *rsp,
+						struct ofono_stk *stk)
+{
+	const struct stk_command_open_channel *oc = &cmd->open_channel;
+	char *alpha_id;
+	int err;
+
+	/* Don't ask for user confirmation if AID is a null data object*/
+	if (oc->alpha_id && strlen(oc->alpha_id) == 0) {
+		/*
+		 * TODO
+		 * setup the channel
+		 */
+
+		/* For now, return  "Command beyond terminal's capabilities" */
+		rsp->result.type = STK_RESULT_TYPE_NOT_CAPABLE;
+		return TRUE;
+	}
+
+	alpha_id = dbus_apply_text_attributes(oc->alpha_id ? oc->alpha_id : "",
+							&oc->text_attr);
+	if (alpha_id == NULL) {
+		rsp->result.type = STK_RESULT_TYPE_DATA_NOT_UNDERSTOOD;
+		return TRUE;
+	}
+
+	err = stk_agent_confirm_open_channel(stk->current_agent, alpha_id,
+						&oc->icon_id,
+						confirm_open_channel_cb,
+						stk, NULL, stk->timeout * 1000);
+	g_free(alpha_id);
+
+	if (err < 0) {
+		unsigned char no_cause_result[] = { 0x00 };
+
+		/*
+		 * We most likely got an out of memory error, tell SIM
+		 * to retry
+		 */
+		ADD_ERROR_RESULT(rsp->result, STK_RESULT_TYPE_TERMINAL_BUSY,
+					no_cause_result);
+		return TRUE;
+	}
+
+	stk->respond_on_exit = TRUE;
+	stk->cancel_cmd = stk_request_cancel;
+
+	return FALSE;
+}
+
+static void channel_activity_cb(enum stk_agent_result result, void *user_data)
+{
+	struct ofono_stk *stk = user_data;
+
+	if (result == STK_AGENT_RESULT_TERMINATE) {
+		stk->respond_on_exit = FALSE;
+		send_simple_response(stk, STK_RESULT_TYPE_USER_TERMINATED);
+	}
+}
+
+static gboolean handle_command_close_channel(const struct stk_command *cmd,
+						struct stk_response *rsp,
+						struct ofono_stk *stk)
+{
+	const struct stk_command_close_channel *cc = &cmd->close_channel;
+	char *alpha_id;
+	int err;
+
+	/*
+	 * Don't inform the user about the link closing phase if AID is
+	 * a null data object
+	 * */
+	if (cc->alpha_id && strlen(cc->alpha_id) == 0)
+		goto close;
+
+	alpha_id = dbus_apply_text_attributes(cc->alpha_id ? cc->alpha_id : "",
+							&cc->text_attr);
+	if (alpha_id == NULL) {
+		rsp->result.type = STK_RESULT_TYPE_DATA_NOT_UNDERSTOOD;
+		return TRUE;
+	}
+
+	err = stk_agent_display_channel_activity(stk->current_agent, alpha_id,
+							&cc->icon_id,
+							channel_activity_cb,
+							stk, NULL);
+	g_free(alpha_id);
+
+	if (err < 0) {
+		unsigned char no_cause_result[] = { 0x00 };
+
+		/*
+		 * We most likely got an out of memory error, tell SIM
+		 * to retry
+		 */
+		ADD_ERROR_RESULT(rsp->result, STK_RESULT_TYPE_TERMINAL_BUSY,
+					no_cause_result);
+		return TRUE;
+	}
+
+close:
+	stk->respond_on_exit = TRUE;
+	stk->cancel_cmd = stk_request_cancel;
+	/*
+	 * TODO
+	 * close the channel
+	 * Send the Terminal Response once the PDP context is deactivated
+	 */
+
+	/* For now, return  "Command beyond terminal's capabilities" */
+	rsp->result.type = STK_RESULT_TYPE_NOT_CAPABLE;
+	return TRUE;
+}
+
+static gboolean handle_command_receive_data(const struct stk_command *cmd,
+						struct stk_response *rsp,
+						struct ofono_stk *stk)
+{
+	const struct stk_command_receive_data *rd = &cmd->receive_data;
+	char *alpha_id;
+	int err;
+
+	/*
+	 * Don't inform the user during data transfer
+	 * if AID is a null data object
+	 */
+	if (rd->alpha_id && strlen(rd->alpha_id) == 0)
+		goto receive;
+
+	alpha_id = dbus_apply_text_attributes(rd->alpha_id ? rd->alpha_id : "",
+							&rd->text_attr);
+	if (alpha_id == NULL) {
+		rsp->result.type = STK_RESULT_TYPE_DATA_NOT_UNDERSTOOD;
+		return TRUE;
+	}
+
+	err = stk_agent_display_channel_activity(stk->current_agent, alpha_id,
+							&rd->icon_id,
+							channel_activity_cb,
+							stk, NULL);
+	g_free(alpha_id);
+
+	if (err < 0) {
+		unsigned char no_cause_result[] = { 0x00 };
+
+		/*
+		 * We most likely got an out of memory error, tell SIM
+		 * to retry
+		 */
+		ADD_ERROR_RESULT(rsp->result, STK_RESULT_TYPE_TERMINAL_BUSY,
+					no_cause_result);
+		return TRUE;
+	}
+
+	stk->respond_on_exit = TRUE;
+	stk->cancel_cmd = stk_request_cancel;
+
+receive:
+	/*
+	 * TODO
+	 * return data available in the Rx buffer corresponding to the
+	 * channel identifier
+	 */
+
+	/* For now, return  "Command beyond terminal's capabilities" */
+	rsp->result.type = STK_RESULT_TYPE_NOT_CAPABLE;
+	return TRUE;
+}
+
+static gboolean handle_command_send_data(const struct stk_command *cmd,
+						struct stk_response *rsp,
+						struct ofono_stk *stk)
+{
+	const struct stk_command_send_data *sd = &cmd->send_data;
+	char *alpha_id;
+	int err;
+
+	/*
+	 * Don't inform the user during data transfer
+	 * if AID is a null data object
+	 */
+	if (sd->alpha_id && strlen(sd->alpha_id) == 0)
+		goto send;
+
+	alpha_id = dbus_apply_text_attributes(sd->alpha_id ? sd->alpha_id : "",
+							&sd->text_attr);
+	if (alpha_id == NULL) {
+		rsp->result.type = STK_RESULT_TYPE_DATA_NOT_UNDERSTOOD;
+		return TRUE;
+	}
+
+	err = stk_agent_display_channel_activity(stk->current_agent, alpha_id,
+							&sd->icon_id,
+							channel_activity_cb,
+							stk, NULL);
+	g_free(alpha_id);
+
+	if (err < 0) {
+		unsigned char no_cause_result[] = { 0x00 };
+
+		/*
+		 * We most likely got an out of memory error, tell SIM
+		 * to retry
+		 */
+		ADD_ERROR_RESULT(rsp->result, STK_RESULT_TYPE_TERMINAL_BUSY,
+					no_cause_result);
+		return TRUE;
+	}
+
+	stk->respond_on_exit = TRUE;
+	stk->cancel_cmd = stk_request_cancel;
+
+send:
+	/*
+	 * TODO
+	 * send the data immediately or store the provided data in the Tx buffer
+	 * corresponding to the channel identifier
+	 */
+	/* For now, return  "Command beyond terminal's capabilities"	*/
+	rsp->result.type = STK_RESULT_TYPE_NOT_CAPABLE;
+	return TRUE;
+}
+
+static gboolean handle_command_get_channel_status(const struct stk_command *cmd,
+						struct stk_response *rsp,
+						struct ofono_stk *stk)
+{
+	rsp->result.type = STK_RESULT_TYPE_SUCCESS;
+	rsp->channel_status.channel.id = stk->channel.id;
+	rsp->channel_status.channel.status = stk->channel.status;
+	return TRUE;
+}
+
 static void stk_proactive_command_cancel(struct ofono_stk *stk)
 {
 	if (stk->immediate_response)
@@ -2741,6 +3023,31 @@ void ofono_stk_proactive_command_notify(struct ofono_stk *stk,
 							&rsp, stk);
 		break;
 
+	case STK_COMMAND_TYPE_OPEN_CHANNEL:
+		respond = handle_command_open_channel(stk->pending_cmd,
+							&rsp, stk);
+		break;
+
+	case STK_COMMAND_TYPE_CLOSE_CHANNEL:
+		respond = handle_command_close_channel(stk->pending_cmd,
+							&rsp, stk);
+		break;
+
+	case STK_COMMAND_TYPE_RECEIVE_DATA:
+		respond = handle_command_receive_data(stk->pending_cmd,
+							&rsp, stk);
+		break;
+
+	case STK_COMMAND_TYPE_SEND_DATA:
+		respond = handle_command_send_data(stk->pending_cmd,
+							&rsp, stk);
+		break;
+
+	case STK_COMMAND_TYPE_GET_CHANNEL_STATUS:
+		respond = handle_command_get_channel_status(stk->pending_cmd,
+							&rsp, stk);
+		break;
+
 	default:
 		rsp.result.type = STK_RESULT_TYPE_COMMAND_NOT_UNDERSTOOD;
 		break;
Signature · 1 line
1.7.1
#1 lore raw

Hi Philippe,

I understand that this is a stub but I have some comments just for reference.

Quoted 89 lines · Philippe Nunes

---
 src/stk.c |  307 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 1 files changed, 307 insertions(+), 0 deletions(-)
src/stk.c +70 -0
index 68b6240..d224360 100644
@@ -79,6 +79,9 @@ 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;
  };
 
  struct envelope_op {
@@ -2548,6 +2551,285 @@ static gboolean handle_command_launch_browser(const struct stk_command *cmd,
        return FALSE;
  }
 
+static void confirm_open_channel_cb(enum stk_agent_result result,
+                                       gboolean confirm,
+                                       void *user_data)
+{
+       struct ofono_stk *stk = user_data;
+       unsigned char no_cause[] = { 0x00 };
+       struct ofono_error failure = { .type = OFONO_ERROR_TYPE_FAILURE };
+       struct stk_response rsp;
+
+       stk->respond_on_exit = FALSE;
+
+       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 */
+
+       default:
+               memset(&rsp, 0, sizeof(rsp));
+               ADD_ERROR_RESULT(rsp.result, STK_RESULT_TYPE_TERMINAL_BUSY,
+                                       no_cause);
+
+               if (stk_respond(stk, &rsp, stk_command_cb))
+                       stk_command_cb(&failure, stk);
+
+               return;
+       }
+
+       /*
+        * TODO
+        * setup the channel
+        */
+
+       /* For now, return  "Command beyond terminal's capabilities" */
+       send_simple_response(stk, STK_RESULT_TYPE_NOT_CAPABLE);
+}
+
+static gboolean handle_command_open_channel(const struct stk_command *cmd,
+                                               struct stk_response *rsp,
+                                               struct ofono_stk *stk)
+{
+       const struct stk_command_open_channel *oc = &cmd->open_channel;
+       char *alpha_id;
+       int err;
+
+       /* Don't ask for user confirmation if AID is a null data object*/
+       if (oc->alpha_id && strlen(oc->alpha_id) == 0) {
+               /*
+                * TODO
+                * setup the channel
+                */
+
+               /* For now, return  "Command beyond terminal's capabilities" */
+               rsp->result.type = STK_RESULT_TYPE_NOT_CAPABLE;
+               return TRUE;
+       }
+
+       alpha_id = dbus_apply_text_attributes(oc->alpha_id ? oc->alpha_id : "",
+                                                       &oc->text_attr);

src/stk.c static gboolean handle_command_launch_browser(const struct stk_command *cmd, · line 2630

Quoted 10 lines
src/stk.c +10 -0
+       if (alpha_id == NULL) {
+               rsp->result.type = STK_RESULT_TYPE_DATA_NOT_UNDERSTOOD;
+               return TRUE;
+       }
+
+       err = stk_agent_confirm_open_channel(stk->current_agent, alpha_id,
+                                               &oc->icon_id,
+                                               confirm_open_channel_cb,
+                                               stk, NULL, stk->timeout * 1000);
+       g_free(alpha_id);

What if no AlphaId or Icon are provided? Also why don't we just use stk_alpha_id_set?

Another thing, is that AFAICS this series wants to support only one channel at a time, right? Then we need to check if a channel is already open (non-NULL) and return "busy". In the close/transmit/receive functions we need to make sure that the channel is non NULL and the channel id matches.

Also it looks like the patches are in reverse order because unit tests are added before implementation, and stk.c functions are added before stkagent.c functions.

Quoted 17 lines
src/stk.c +17 -0
+
+       if (err < 0) {
+               unsigned char no_cause_result[] = { 0x00 };
+
+               /*
+                * We most likely got an out of memory error, tell SIM
+                * to retry
+                */
+               ADD_ERROR_RESULT(rsp->result, STK_RESULT_TYPE_TERMINAL_BUSY,
+                                       no_cause_result);
+               return TRUE;
+       }
+
+       stk->respond_on_exit = TRUE;
+       stk->cancel_cmd = stk_request_cancel;
+
+       return FALSE;

src/stk.c static gboolean handle_command_launch_browser(const struct stk_command *cmd, · line 2657

Quoted 10 lines
src/stk.c +10 -0
+}
+
+static void channel_activity_cb(enum stk_agent_result result, void *user_data)
+{
+       struct ofono_stk *stk = user_data;
+
+       if (result == STK_AGENT_RESULT_TERMINATE) {
+               stk->respond_on_exit = FALSE;
+               send_simple_response(stk, STK_RESULT_TYPE_USER_TERMINATED);
+       }

Should we close the channel?

Best regards

#2 lore raw

Hi Andrew,

Quoted 98 lines · Andrzej Zaborowski

Hi Philippe,

I understand that this is a stub but I have some comments just for reference.

Quoted 93 lines · Philippe Nunes
---
  src/stk.c |  307 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1 files changed, 307 insertions(+), 0 deletions(-)
src/stk.c +74 -0
index 68b6240..d224360 100644
@@ -79,6 +79,9 @@ 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;
  };
 
  struct envelope_op {
@@ -2548,6 +2551,285 @@ static gboolean handle_command_launch_browser(const struct stk_command *cmd,
        return FALSE;
  }
 
+static void confirm_open_channel_cb(enum stk_agent_result result,
+                                       gboolean confirm,
+                                       void *user_data)
+{
+       struct ofono_stk *stk = user_data;
+       unsigned char no_cause[] = { 0x00 };
+       struct ofono_error failure = { .type = OFONO_ERROR_TYPE_FAILURE };
+       struct stk_response rsp;
+
+       stk->respond_on_exit = FALSE;
+
+       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 */
+
+       default:
+               memset(&rsp, 0, sizeof(rsp));
+               ADD_ERROR_RESULT(rsp.result, STK_RESULT_TYPE_TERMINAL_BUSY,
+                                       no_cause);
+
+               if (stk_respond(stk,&rsp, stk_command_cb))
+                       stk_command_cb(&failure, stk);
+
+               return;
+       }
+
+       /*
+        * TODO
+        * setup the channel
+        */
+
+       /* For now, return  "Command beyond terminal's capabilities" */
+       send_simple_response(stk, STK_RESULT_TYPE_NOT_CAPABLE);
+}
+
+static gboolean handle_command_open_channel(const struct stk_command *cmd,
+                                               struct stk_response *rsp,
+                                               struct ofono_stk *stk)
+{
+       const struct stk_command_open_channel *oc =&cmd->open_channel;
+       char *alpha_id;
+       int err;
+
+       /* Don't ask for user confirmation if AID is a null data object*/
+       if (oc->alpha_id&&  strlen(oc->alpha_id) == 0) {
+               /*
+                * TODO
+                * setup the channel
+                */
+
+               /* For now, return  "Command beyond terminal's capabilities" */
+               rsp->result.type = STK_RESULT_TYPE_NOT_CAPABLE;
+               return TRUE;
+       }
+
+       alpha_id = dbus_apply_text_attributes(oc->alpha_id ? oc->alpha_id : "",
+&oc->text_attr);
+       if (alpha_id == NULL) {
+               rsp->result.type = STK_RESULT_TYPE_DATA_NOT_UNDERSTOOD;
+               return TRUE;
+       }
Quoted 8 lines

src/stk.c static gboolean handle_command_launch_browser(const struct stk_command *cmd, · line 2630

Quoted 6 lines
src/stk.c +6 -0
+
+       err = stk_agent_confirm_open_channel(stk->current_agent, alpha_id,
+&oc->icon_id,
+                                               confirm_open_channel_cb,
+                                               stk, NULL, stk->timeout * 1000);
+       g_free(alpha_id);

What if no AlphaId or Icon are provided?

As you know, we are treating null data object(len = 0, no value part) and no alpha identifier cases equally. As specified for the case null data object, we are not allowed to provide any information to the user. So we start to setup the channel directly.

Also why don't we just use

Quoted 1 line

stk_alpha_id_set?

For Open channel, we need to get the user confirmation before setting up the channel. So a dedicated method is required.
However, for close/send/receive, the idea is finally to use stk_alpha_id_set. The set of patch introducing the new method "DisplayAction" is precisely preparing this work.

Quoted 6 lines

Another thing, is that AFAICS this series wants to support only one channel at a time, right? Then we need to check if a channel is already open (non-NULL) and return "busy". In the close/transmit/receive functions we need to make sure that the channel is non NULL and the channel id matches.

You're right, the basic checking are missing. For Open channel, we need also to check that the bearer type is supported (for now, we are looking to handle only packet data service bearer).
And I confirm that for now, only one channel is supported at a time.

Quoted 5 lines

Also it looks like the patches are in reverse order because unit tests are added before implementation, and stk.c functions are added before stkagent.c functions.

Yes, I missed to consider that we could apply the patches one by one so I didn't care about the order. I will reorder the patches next time.

Quoted 21 lines
Quoted 21 lines
src/stk.c +21 -0
+
+       if (err<  0) {
+               unsigned char no_cause_result[] = { 0x00 };
+
+               /*
+                * We most likely got an out of memory error, tell SIM
+                * to retry
+                */
+               ADD_ERROR_RESULT(rsp->result, STK_RESULT_TYPE_TERMINAL_BUSY,
+                                       no_cause_result);
+               return TRUE;
+       }
+
+       stk->respond_on_exit = TRUE;
+       stk->cancel_cmd = stk_request_cancel;
+
+       return FALSE;
+}
+
+static void channel_activity_cb(enum stk_agent_result result, void *user_data)
+{
Quoted 8 lines

src/stk.c static gboolean handle_command_launch_browser(const struct stk_command *cmd, · line 2657

Quoted 6 lines
src/stk.c +6 -0
+       struct ofono_stk *stk = user_data;
+
+       if (result == STK_AGENT_RESULT_TERMINATE) {
+               stk->respond_on_exit = FALSE;
+               send_simple_response(stk, STK_RESULT_TYPE_USER_TERMINATED);
+       }

Should we close the channel?

Yes, logically (at least for Receive data/Send Data). The following code could be more relevant:

	if (result == STK_AGENT_RESULT_TERMINATE && stk->pending_cmd) {
			stk->respond_on_exit = FALSE;
			
			stk->cancel_cmd(stk);
			
			send_simple_response(stk,
                             STK_RESULT_TYPE_USER_TERMINATED);
	}	

stk->cancel_cmd should not be set to 'stk_request_cancel' as you see in this patch but it should be set to a generic function like "cancel_channel" implementing the channel closing and cleanup .

In practice, the terminal response to Receive data/Send Data is likely to be already sent before the user decides to end the session. So, in this case, sending the 'Channel status' event should be considered instead of sending a simple response.

Quoted 2 lines

Best regards