[PATCH 0/2] Extend Phonesim to support BIP commands
by Philippe Nunes
Philippe Nunes (2):
qsimcommand: Add properties and TLV builders to support BIP commands
simapplication: Add a new SIM applet dedicated to BIP commands
src/qsimcommand.cpp | 201 ++++++++++++++++++++++++++++++++++++++++++++++--
src/qsimcommand.h | 34 ++++++++
src/simapplication.cpp | 161 ++++++++++++++++++++++++++++++++++++++
src/simapplication.h | 2 +
4 files changed, 391 insertions(+), 7 deletions(-)
11 years, 5 months
[PATCH 6/6] test-stk-menu: Add support for BIP commands
by Philippe Nunes
---
test/test-stk-menu | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/test/test-stk-menu b/test/test-stk-menu
index 639fe77..85b9a0b 100755
--- a/test/test-stk-menu
+++ b/test/test-stk-menu
@@ -170,6 +170,18 @@ class StkAgent(dbus.service.Object):
return False
@dbus.service.method("org.ofono.SimToolkitAgent",
+ in_signature="sy", out_signature="b")
+ def ConfirmOpenChannel(self, info, icon):
+ print "Open channel confirmation: (%s)" % (info)
+ print "Icon: (%d)" % (icon)
+ key = raw_input("Enter Confirmation (y, n):")
+
+ if key == 'y':
+ return True
+ else:
+ return False
+
+ @dbus.service.method("org.ofono.SimToolkitAgent",
in_signature="", out_signature="")
def Cancel(self):
print "Cancel"
@@ -198,6 +210,16 @@ class StkAgent(dbus.service.Object):
print "Text: %s" % (text)
print "Icon: %d" % (icon)
+ @dbus.service.method("org.ofono.SimToolkitAgent",
+ in_signature="sy", out_signature="")
+ def DisplayChannelActivity(self, text, icon):
+ print "Channel activity (%s)" % (text)
+ print "Icon: (%d)" % (icon)
+ key = raw_input("Press 't' to terminate the session ")
+
+ if key == 't':
+ raise EndSession("User wishes to terminate session")
+
def property_changed(name, value):
print "SimToolKit property: %s changed to '%s'" % (name, value)
--
1.7.1
11 years, 5 months
[PATCH 4/6] stkagent: Add new methods to support the BIP commands
by Philippe Nunes
---
src/stkagent.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/stkagent.h | 17 +++++++
2 files changed, 146 insertions(+), 0 deletions(-)
diff --git a/src/stkagent.c b/src/stkagent.c
index 2395182..bae788c 100644
--- a/src/stkagent.c
+++ b/src/stkagent.c
@@ -1081,3 +1081,132 @@ int stk_agent_confirm_launch_browser(struct stk_agent *agent, const char *text,
return 0;
}
+
+static void confirm_open_channel_cb(DBusPendingCall *call, void *data)
+{
+ struct stk_agent *agent = data;
+ stk_agent_confirmation_cb cb = agent->user_cb;
+ DBusMessage *reply = dbus_pending_call_steal_reply(call);
+ enum stk_agent_result result;
+ gboolean remove_agent;
+ dbus_bool_t confirm;
+
+ if (check_error(agent, reply,
+ ALLOWED_ERROR_TERMINATE, &result) == -EINVAL) {
+ remove_agent = TRUE;
+ goto error;
+ }
+
+ if (result != STK_AGENT_RESULT_OK) {
+ cb(result, FALSE, agent->user_data);
+ goto done;
+ }
+
+ if (dbus_message_get_args(reply, NULL,
+ DBUS_TYPE_BOOLEAN, &confirm,
+ DBUS_TYPE_INVALID) == FALSE) {
+ ofono_error("Can't parse the reply to ConfirmOpenChannel()");
+ remove_agent = TRUE;
+ goto error;
+ }
+
+ cb(result, confirm, agent->user_data);
+
+ CALLBACK_END();
+}
+
+int stk_agent_confirm_open_channel(struct stk_agent *agent, const char *text,
+ const struct stk_icon_id *icon,
+ stk_agent_confirmation_cb cb,
+ void *user_data,
+ ofono_destroy_func destroy, int timeout)
+{
+ DBusConnection *conn = ofono_dbus_get_connection();
+
+ agent->msg = dbus_message_new_method_call(agent->bus, agent->path,
+ OFONO_SIM_APP_INTERFACE,
+ "ConfirmOpenChannel");
+ if (agent->msg == NULL)
+ return -ENOMEM;
+
+ dbus_message_append_args(agent->msg,
+ DBUS_TYPE_STRING, &text,
+ DBUS_TYPE_BYTE, &icon->id,
+ DBUS_TYPE_INVALID);
+
+ if (dbus_connection_send_with_reply(conn, agent->msg, &agent->call,
+ timeout) == FALSE ||
+ agent->call == NULL)
+ return -EIO;
+
+ agent->user_cb = cb;
+ agent->user_data = user_data;
+ agent->user_destroy = destroy;
+
+ dbus_pending_call_set_notify(agent->call, confirm_open_channel_cb,
+ agent, NULL);
+
+ return 0;
+}
+
+static void channel_activity_cb(DBusPendingCall *call, void *data)
+{
+ struct stk_agent *agent = data;
+ stk_agent_channel_activity_cb cb = agent->user_cb;
+ DBusMessage *reply = dbus_pending_call_steal_reply(call);
+ enum stk_agent_result result;
+ gboolean remove_agent;
+
+ if (check_error(agent, reply,
+ ALLOWED_ERROR_TERMINATE, &result) == -EINVAL) {
+ remove_agent = TRUE;
+ goto error;
+ }
+
+ if (dbus_message_get_args(reply, NULL, DBUS_TYPE_INVALID) == FALSE) {
+ ofono_error("Can't parse the reply to DisplayChannelActivity()"
+ );
+ remove_agent = TRUE;
+ goto error;
+ }
+
+ cb(result, agent->user_data);
+ goto done;
+
+ CALLBACK_END();
+}
+
+int stk_agent_display_channel_activity(struct stk_agent *agent,
+ const char *text,
+ const struct stk_icon_id *icon,
+ stk_agent_channel_activity_cb cb,
+ void *user_data,
+ ofono_destroy_func destroy)
+{
+ DBusConnection *conn = ofono_dbus_get_connection();
+
+ agent->msg = dbus_message_new_method_call(agent->bus, agent->path,
+ OFONO_SIM_APP_INTERFACE,
+ "DisplayChannelActivity");
+ if (agent->msg == NULL)
+ return -ENOMEM;
+
+ dbus_message_append_args(agent->msg,
+ DBUS_TYPE_STRING, &text,
+ DBUS_TYPE_BYTE, &icon->id,
+ DBUS_TYPE_INVALID);
+
+ if (dbus_connection_send_with_reply(conn, agent->msg, &agent->call,
+ 0) == FALSE ||
+ agent->call == NULL)
+ return -EIO;
+
+ agent->user_cb = cb;
+ agent->user_data = user_data;
+ agent->user_destroy = destroy;
+
+ dbus_pending_call_set_notify(agent->call, channel_activity_cb,
+ agent, NULL);
+
+ return 0;
+}
diff --git a/src/stkagent.h b/src/stkagent.h
index 1f0c4fa..610c728 100644
--- a/src/stkagent.h
+++ b/src/stkagent.h
@@ -60,6 +60,9 @@ typedef void (*stk_agent_string_cb)(enum stk_agent_result result,
typedef void (*stk_agent_tone_cb)(enum stk_agent_result result,
void *user_data);
+typedef void (*stk_agent_channel_activity_cb)(enum stk_agent_result result,
+ void *user_data);
+
struct stk_agent *stk_agent_new(const char *path, const char *sender,
ofono_bool_t remove_on_terminate);
@@ -147,3 +150,17 @@ int stk_agent_confirm_launch_browser(struct stk_agent *agent, const char *text,
void *user_data,
ofono_destroy_func destroy,
int timeout);
+
+int stk_agent_confirm_open_channel(struct stk_agent *agent, const char *text,
+ const struct stk_icon_id *icon,
+ stk_agent_confirmation_cb cb,
+ void *user_data,
+ ofono_destroy_func destroy,
+ int timeout);
+
+int stk_agent_display_channel_activity(struct stk_agent *agent,
+ const char *text,
+ const struct stk_icon_id *icon,
+ stk_agent_channel_activity_cb cb,
+ void *user_data,
+ ofono_destroy_func destroy);
--
1.7.1
11 years, 5 months
[PATCH 1/6] test-stkutil: Add unit tests for BIP commands
by Philippe Nunes
---
unit/test-stkutil.c | 1201 ++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 1184 insertions(+), 17 deletions(-)
diff --git a/unit/test-stkutil.c b/unit/test-stkutil.c
index aa62aac..99c2112 100644
--- a/unit/test-stkutil.c
+++ b/unit/test-stkutil.c
@@ -470,6 +470,65 @@ static void check_provisioning_file_references(GSList *command,
g_assert(test[i].len == 0);
}
+/* Defined in TS 102.223 Section 8.52 */
+static void check_bearer_desc(const struct stk_bearer_description *command,
+ const struct stk_bearer_description *test)
+{
+ g_assert(command->type == test->type);
+
+ if (test->type == STK_BEARER_TYPE_GPRS_UTRAN) {
+
+ check_common_byte(command->parameters.gprs.precedence,
+ test->parameters.gprs.precedence);
+ check_common_byte(command->parameters.gprs.delay,
+ test->parameters.gprs.delay);
+ check_common_byte(command->parameters.gprs.reliability,
+ test->parameters.gprs.reliability);
+ check_common_byte(command->parameters.gprs.peak,
+ test->parameters.gprs.peak);
+ check_common_byte(command->parameters.gprs.mean,
+ test->parameters.gprs.mean);
+ check_common_byte(command->parameters.gprs.pdp_type,
+ test->parameters.gprs.pdp_type);
+ return;
+ } else {
+ g_assert(command->parameters.other.len ==
+ test->parameters.other.len);
+ g_assert(g_mem_equal(command->parameters.other.pars,
+ test->parameters.other.pars,
+ test->parameters.other.len));
+ }
+}
+
+/* Defined in TS 102.223 Section 8.53 */
+static inline void check_channel_data(
+ const struct stk_common_byte_array *command,
+ const struct stk_common_byte_array *test)
+{
+ check_common_byte_array(command, test);
+}
+
+/* Defined in TS 102.223 Section 8.58 */
+static inline void check_other_address(
+ const struct stk_other_address *command,
+ const struct stk_other_address *test)
+{
+ check_common_byte(command->type, test->type);
+
+ if (test->type == STK_ADDRESS_IPV4)
+ g_assert(command->addr.ipv4 == test->addr.ipv4);
+ else
+ g_assert(g_mem_equal(command->addr.ipv6, test->addr.ipv6, 16));
+}
+
+/* Defined in TS 102.223 Section 8.59 */
+static void check_uicc_te_interface(const struct stk_uicc_te_interface *command,
+ const struct stk_uicc_te_interface *test)
+{
+ check_common_byte(command->protocol, test->protocol);
+ g_assert(command->port == test->port);
+}
+
/* Defined in TS 102.223 Section 8.60 */
static inline void check_aid(const struct stk_aid *command,
const struct stk_aid *test)
@@ -477,6 +536,15 @@ static inline void check_aid(const struct stk_aid *command,
g_assert(g_mem_equal(command->aid, test->aid, test->len));
}
+/* Defined in TS 102.223 Section 8.70 */
+static inline void check_network_access_name(
+ const struct stk_network_access_name *command,
+ const struct stk_network_access_name *test)
+{
+ g_assert(command->len == test->len);
+ g_assert(g_mem_equal(command->name, test->name, test->len));
+}
+
/* Defined in TS 102.223 Section 8.71 */
static inline void check_cdma_sms_tpdu(
const struct stk_common_byte_array *command,
@@ -16913,6 +16981,662 @@ static void test_launch_browser(gconstpointer data)
stk_command_free(command);
}
+struct open_channel_test {
+ const unsigned char *pdu;
+ unsigned int pdu_len;
+ unsigned char qualifier;
+ char *alpha_id;
+ struct stk_icon_id icon_id;
+ struct stk_bearer_description bearer_desc;
+ unsigned short buf_size;
+ struct stk_network_access_name network_name;
+ struct stk_other_address local_addr;
+ char *text_usr;
+ char *text_passwd;
+ struct stk_uicc_te_interface uti;
+ struct stk_other_address data_dest_addr;
+ struct stk_text_attribute text_attr;
+ struct stk_frame_id frame_id;
+};
+
+static unsigned char open_channel_211[] = { 0xD0, 0x36, 0x81, 0x03, 0x01, 0x40,
+ 0x01, 0x82, 0x02, 0x81, 0x82,
+ 0x35, 0x07, 0x02, 0x03, 0x04,
+ 0x03, 0x04, 0x1F, 0x02, 0x39,
+ 0x02, 0x05, 0x78, 0x0D, 0x08,
+ 0xF4, 0x55, 0x73, 0x65, 0x72,
+ 0x4C, 0x6F, 0x67, 0x0D, 0x08,
+ 0xF4, 0x55, 0x73, 0x65, 0x72,
+ 0x50, 0x77, 0x64, 0x3C, 0x03,
+ 0x01, 0xAD, 0x9C, 0x3E, 0x05,
+ 0x21, 0x01, 0x01, 0x01, 0x01 };
+
+static unsigned char open_channel_221[] = { 0xD0, 0x42, 0x81, 0x03, 0x01, 0x40,
+ 0x01, 0x82, 0x02, 0x81, 0x82,
+ 0x35, 0x07, 0x02, 0x03, 0x04,
+ 0x03, 0x04, 0x1F, 0x02, 0x39,
+ 0x02, 0x05, 0x78, 0x47, 0x0A,
+ 0x06, 0x54, 0x65, 0x73, 0x74,
+ 0x47, 0x70, 0x02, 0x72, 0x73,
+ 0x0D, 0x08, 0xF4, 0x55, 0x73,
+ 0x65, 0x72, 0x4C, 0x6F, 0x67,
+ 0x0D, 0x08, 0xF4, 0x55, 0x73,
+ 0x65, 0x72, 0x50, 0x77, 0x64,
+ 0x3C, 0x03, 0x01, 0xAD, 0x9C,
+ 0x3E, 0x05, 0x21, 0x01, 0x01,
+ 0x01, 0x01 };
+
+static unsigned char open_channel_231[] = { 0xD0, 0x4B, 0x81, 0x03, 0x01, 0x40,
+ 0x01, 0x82, 0x02, 0x81, 0x82,
+ 0x05, 0x07, 0x4F, 0x70, 0x65,
+ 0x6E, 0x20, 0x49, 0x44, 0x35,
+ 0x07, 0x02, 0x03, 0x04, 0x03,
+ 0x04, 0x1F, 0x02, 0x39, 0x02,
+ 0x05, 0x78, 0x47, 0x0A, 0x06,
+ 0x54, 0x65, 0x73, 0x74, 0x47,
+ 0x70, 0x02, 0x72, 0x73, 0x0D,
+ 0x08, 0xF4, 0x55, 0x73, 0x65,
+ 0x72, 0x4C, 0x6F, 0x67, 0x0D,
+ 0x08, 0xF4, 0x55, 0x73, 0x65,
+ 0x72, 0x50, 0x77, 0x64, 0x3C,
+ 0x03, 0x01, 0xAD, 0x9C, 0x3E,
+ 0x05, 0x21, 0x01, 0x01, 0x01,
+ 0x01 };
+
+static unsigned char open_channel_241[] = { 0xD0, 0x44, 0x81, 0x03, 0x01, 0x40,
+ 0x01, 0x82, 0x02, 0x81, 0x82,
+ 0x05, 0x00, 0x35, 0x07, 0x02,
+ 0x03, 0x04, 0x03, 0x04, 0x1F,
+ 0x02, 0x39, 0x02, 0x05, 0x78,
+ 0x47, 0x0A, 0x06, 0x54, 0x65,
+ 0x73, 0x74, 0x47, 0x70, 0x02,
+ 0x72, 0x73, 0x0D, 0x08, 0xF4,
+ 0x55, 0x73, 0x65, 0x72, 0x4C,
+ 0x6F, 0x67, 0x0D, 0x08, 0xF4,
+ 0x55, 0x73, 0x65, 0x72, 0x50,
+ 0x77, 0x64, 0x3C, 0x03, 0x01,
+ 0xAD, 0x9C, 0x3E, 0x05, 0x21,
+ 0x01, 0x01, 0x01, 0x01 };
+
+static unsigned char open_channel_511[] = { 0xD0, 0x53, 0x81, 0x03, 0x01, 0x40,
+ 0x01, 0x82, 0x02, 0x81, 0x82,
+ 0x05, 0x09, 0x4F, 0x70, 0x65,
+ 0x6E, 0x20, 0x49, 0x44, 0x20,
+ 0x31, 0x35, 0x07, 0x02, 0x03,
+ 0x04, 0x03, 0x04, 0x1F, 0x02,
+ 0x39, 0x02, 0x05, 0x78, 0x47,
+ 0x0A, 0x06, 0x54, 0x65, 0x73,
+ 0x74, 0x47, 0x70, 0x02, 0x72,
+ 0x73, 0x0D, 0x08, 0xF4, 0x55,
+ 0x73, 0x65, 0x72, 0x4C, 0x6F,
+ 0x67, 0x0D, 0x08, 0xF4, 0x55,
+ 0x73, 0x65, 0x72, 0x50, 0x77,
+ 0x64, 0x3C, 0x03, 0x01, 0xAD,
+ 0x9C, 0x3E, 0x05, 0x21, 0x01,
+ 0x01, 0x01, 0x01, 0xD0, 0x04,
+ 0x00, 0x09, 0x00, 0xB4 };
+
+static struct open_channel_test open_channel_data_211 = {
+ /*
+ * OPEN CHANNEL, immediate link establishment, GPRS, no local address
+ * no alpha identifier, no network access name
+ */
+ .pdu = open_channel_211,
+ .pdu_len = sizeof(open_channel_211),
+ .qualifier = STK_OPEN_CHANNEL_IMMEDIATE,
+ .bearer_desc = {
+ .type = STK_BEARER_TYPE_GPRS_UTRAN,
+ .parameters = {
+ .gprs = {
+ .precedence = 3,
+ .delay = 4,
+ .reliability = 3,
+ .peak = 4,
+ .mean = 31,
+ .pdp_type = 2,
+ },
+ },
+ },
+ .buf_size = 1400,
+ .text_usr = "UserLog",
+ .text_passwd = "UserPwd",
+ .uti = {
+ .protocol = STK_TRANSPORT_PROTOCOL_UDP_CLIENT_REMOTE,
+ .port = 44444,
+ },
+ .data_dest_addr = {
+ .type = STK_ADDRESS_IPV4,
+ .addr = {
+ .ipv4 = 0x01010101,
+ },
+ },
+};
+
+static struct open_channel_test open_channel_data_221 = {
+ /*
+ * OPEN CHANNEL, immediate link establishment GPRS,
+ * no alpha identifier, with network access name
+ */
+ .pdu = open_channel_221,
+ .pdu_len = sizeof(open_channel_221),
+ .qualifier = STK_OPEN_CHANNEL_IMMEDIATE,
+ .bearer_desc = {
+ .type = STK_BEARER_TYPE_GPRS_UTRAN,
+ .parameters = {
+ .gprs = {
+ .precedence = 3,
+ .delay = 4,
+ .reliability = 3,
+ .peak = 4,
+ .mean = 31,
+ .pdp_type = 2,
+ },
+ },
+ },
+ .buf_size = 1400,
+ .network_name = {
+ .len = 9,
+ .name = "TestGp.rs",
+ },
+ .text_usr = "UserLog",
+ .text_passwd = "UserPwd",
+ .uti = {
+ .protocol = STK_TRANSPORT_PROTOCOL_UDP_CLIENT_REMOTE,
+ .port = 44444,
+ },
+ .data_dest_addr = {
+ .type = STK_ADDRESS_IPV4,
+ .addr = {
+ .ipv4 = 0x01010101,
+ },
+ },
+};
+
+static struct open_channel_test open_channel_data_231 = {
+ /*
+ * OPEN CHANNEL, immediate link establishment, GPRS
+ * with alpha identifier
+ */
+ .pdu = open_channel_231,
+ .pdu_len = sizeof(open_channel_231),
+ .qualifier = STK_OPEN_CHANNEL_IMMEDIATE,
+ .alpha_id = "Open ID",
+ .bearer_desc = {
+ .type = STK_BEARER_TYPE_GPRS_UTRAN,
+ .parameters = {
+ .gprs = {
+ .precedence = 3,
+ .delay = 4,
+ .reliability = 3,
+ .peak = 4,
+ .mean = 31,
+ .pdp_type = 2,
+ },
+ },
+ },
+ .buf_size = 1400,
+ .network_name = {
+ .len = 9,
+ .name = "TestGp.rs",
+ },
+ .text_usr = "UserLog",
+ .text_passwd = "UserPwd",
+ .uti = {
+ .protocol = STK_TRANSPORT_PROTOCOL_UDP_CLIENT_REMOTE,
+ .port = 44444,
+ },
+ .data_dest_addr = {
+ .type = STK_ADDRESS_IPV4,
+ .addr = {
+ .ipv4 = 0x01010101,
+ },
+ },
+};
+
+static struct open_channel_test open_channel_data_241 = {
+ /*
+ * OPEN CHANNEL, immediate link establishment, GPRS,
+ * with null alpha identifier
+ */
+ .pdu = open_channel_241,
+ .pdu_len = sizeof(open_channel_241),
+ .qualifier = STK_OPEN_CHANNEL_IMMEDIATE,
+ .alpha_id = "",
+ .bearer_desc = {
+ .type = STK_BEARER_TYPE_GPRS_UTRAN,
+ .parameters = {
+ .gprs = {
+ .precedence = 3,
+ .delay = 4,
+ .reliability = 3,
+ .peak = 4,
+ .mean = 31,
+ .pdp_type = 2,
+ },
+ },
+ },
+ .buf_size = 1400,
+ .network_name = {
+ .len = 9,
+ .name = "TestGp.rs",
+ },
+ .text_usr = "UserLog",
+ .text_passwd = "UserPwd",
+ .uti = {
+ .protocol = STK_TRANSPORT_PROTOCOL_UDP_CLIENT_REMOTE,
+ .port = 44444,
+ },
+ .data_dest_addr = {
+ .type = STK_ADDRESS_IPV4,
+ .addr = {
+ .ipv4 = 0x01010101,
+ },
+ },
+};
+
+static struct open_channel_test open_channel_data_511 = {
+ /*
+ * OPEN CHANNEL, immediate link establishment, GPRS
+ * Text Attribute – Left Alignment
+ */
+ .pdu = open_channel_511,
+ .pdu_len = sizeof(open_channel_511),
+ .qualifier = STK_OPEN_CHANNEL_IMMEDIATE,
+ .alpha_id = "Open ID 1",
+ .bearer_desc = {
+ .type = STK_BEARER_TYPE_GPRS_UTRAN,
+ .parameters = {
+ .gprs = {
+ .precedence = 3,
+ .delay = 4,
+ .reliability = 3,
+ .peak = 4,
+ .mean = 31,
+ .pdp_type = 2,
+ },
+ },
+ },
+ .buf_size = 1400,
+ .network_name = {
+ .len = 9,
+ .name = "TestGp.rs",
+ },
+ .text_usr = "UserLog",
+ .text_passwd = "UserPwd",
+ .uti = {
+ .protocol = STK_TRANSPORT_PROTOCOL_UDP_CLIENT_REMOTE,
+ .port = 44444,
+ },
+ .data_dest_addr = {
+ .type = STK_ADDRESS_IPV4,
+ .addr = {
+ .ipv4 = 0x01010101,
+ },
+ },
+ .text_attr = {
+ .len = 4,
+ .attributes = { 0x00, 0x09, 0x00, 0xB4 }
+ },
+};
+
+static void test_open_channel(gconstpointer data)
+{
+ const struct open_channel_test *test = data;
+ struct stk_command *command;
+
+ command = stk_command_new_from_pdu(test->pdu, test->pdu_len);
+
+ g_assert(command);
+ g_assert(command->status == STK_PARSE_RESULT_OK);
+
+ g_assert(command->number == 1);
+ g_assert(command->type == STK_COMMAND_TYPE_OPEN_CHANNEL);
+ g_assert(command->qualifier == test->qualifier);
+
+ g_assert(command->src == STK_DEVICE_IDENTITY_TYPE_UICC);
+ g_assert(command->dst == STK_DEVICE_IDENTITY_TYPE_TERMINAL);
+
+ check_alpha_id(command->open_channel.alpha_id, test->alpha_id);
+ check_icon_id(&command->open_channel.icon_id, &test->icon_id);
+ check_bearer_desc(&command->open_channel.bearer_desc,
+ &test->bearer_desc);
+ g_assert(command->open_channel.buf_size == test->buf_size);
+ check_network_access_name(&command->open_channel.network_name,
+ &test->network_name);
+ check_other_address(&command->open_channel.local_addr,
+ &test->local_addr);
+ check_text(command->open_channel.text_usr, test->text_usr);
+ check_text(command->open_channel.text_passwd, test->text_passwd);
+ check_uicc_te_interface(&command->open_channel.uti, &test->uti);
+ check_other_address(&command->open_channel.data_dest_addr,
+ &test->data_dest_addr);
+ check_text_attr(&command->open_channel.text_attr, &test->text_attr);
+ check_frame_id(&command->open_channel.frame_id, &test->frame_id);
+
+ stk_command_free(command);
+}
+
+struct close_channel_test {
+ const unsigned char *pdu;
+ unsigned int pdu_len;
+ unsigned char qualifier;
+ enum stk_device_identity_type dst;
+ char *alpha_id;
+ struct stk_icon_id icon_id;
+ struct stk_text_attribute text_attr;
+ struct stk_frame_id frame_id;
+};
+
+static unsigned char close_channel_111[] = { 0xD0, 0x09, 0x81, 0x03, 0x01, 0x41,
+ 0x00, 0x82, 0x02, 0x81, 0x21 };
+
+static struct close_channel_test close_channel_data_111 = {
+ .pdu = close_channel_111,
+ .pdu_len = sizeof(close_channel_111),
+ .qualifier = 0x00,
+ .dst = STK_DEVICE_IDENTITY_TYPE_CHANNEL_1,
+};
+
+static unsigned char close_channel_211[] = { 0xD0, 0x1B, 0x81, 0x03, 0x01, 0x41,
+ 0x00, 0x82, 0x02, 0x81, 0x21,
+ 0x85, 0x0A, 0x43, 0x6C, 0x6F,
+ 0x73, 0x65, 0x20, 0x49, 0x44,
+ 0x20, 0x31, 0xD0, 0x04, 0x00,
+ 0x0A, 0x00, 0xB4,
+ };
+
+static struct close_channel_test close_channel_data_211 = {
+ .pdu = close_channel_211,
+ .pdu_len = sizeof(close_channel_211),
+ .qualifier = 0x00,
+ .dst = STK_DEVICE_IDENTITY_TYPE_CHANNEL_1,
+ .alpha_id = "Close ID 1",
+ .text_attr = {
+ .len = 4,
+ .attributes = { 0x00, 0x0A, 0x00, 0xB4 }
+ },
+};
+
+static void test_close_channel(gconstpointer data)
+{
+ const struct close_channel_test *test = data;
+ struct stk_command *command;
+
+ command = stk_command_new_from_pdu(test->pdu, test->pdu_len);
+
+ g_assert(command);
+ g_assert(command->status == STK_PARSE_RESULT_OK);
+
+ g_assert(command->number == 1);
+ g_assert(command->type == STK_COMMAND_TYPE_CLOSE_CHANNEL);
+ g_assert(command->qualifier == test->qualifier);
+
+ g_assert(command->src == STK_DEVICE_IDENTITY_TYPE_UICC);
+ g_assert(command->dst == test->dst);
+
+ check_alpha_id(command->close_channel.alpha_id, test->alpha_id);
+ check_icon_id(&command->close_channel.icon_id, &test->icon_id);
+ check_text_attr(&command->close_channel.text_attr, &test->text_attr);
+ check_frame_id(&command->close_channel.frame_id, &test->frame_id);
+
+ stk_command_free(command);
+}
+
+struct receive_data_test {
+ const unsigned char *pdu;
+ unsigned int pdu_len;
+ unsigned char qualifier;
+ enum stk_device_identity_type dst;
+ char *alpha_id;
+ struct stk_icon_id icon_id;
+ unsigned char data_len;
+ struct stk_text_attribute text_attr;
+ struct stk_frame_id frame_id;
+};
+
+static unsigned char receive_data_111[] = { 0xD0, 0x0C, 0x81, 0x03, 0x01, 0x42,
+ 0x00, 0x82, 0x02, 0x81, 0x21,
+ 0xB7, 0x01, 0xC8 };
+
+static struct receive_data_test receive_data_data_111 = {
+ .pdu = receive_data_111,
+ .pdu_len = sizeof(receive_data_111),
+ .qualifier = 0x00,
+ .dst = STK_DEVICE_IDENTITY_TYPE_CHANNEL_1,
+ .data_len = 200,
+};
+
+static unsigned char receive_data_211[] = { 0xD0, 0x22, 0x81, 0x03, 0x01, 0x42,
+ 0x00, 0x82, 0x02, 0x81, 0x21,
+ 0x85, 0x0E, 0x52, 0x65, 0x63,
+ 0x65, 0x69, 0x76, 0x65, 0x20,
+ 0x44, 0x61, 0x74, 0x61, 0x20,
+ 0x31, 0xB7, 0x01, 0xC8, 0xD0,
+ 0x04, 0x00, 0x0E, 0x00, 0xB4 };
+
+static struct receive_data_test receive_data_data_211 = {
+ .pdu = receive_data_211,
+ .pdu_len = sizeof(receive_data_211),
+ .qualifier = 0x00,
+ .dst = STK_DEVICE_IDENTITY_TYPE_CHANNEL_1,
+ .data_len = 200,
+ .alpha_id = "Receive Data 1",
+ .text_attr = {
+ .len = 4,
+ .attributes = { 0x00, 0x0E, 0x00, 0xB4 }
+ },
+};
+
+
+static void test_receive_data(gconstpointer data)
+{
+ const struct receive_data_test *test = data;
+ struct stk_command *command;
+
+ command = stk_command_new_from_pdu(test->pdu, test->pdu_len);
+
+ g_assert(command);
+ g_assert(command->status == STK_PARSE_RESULT_OK);
+
+ g_assert(command->number == 1);
+ g_assert(command->type == STK_COMMAND_TYPE_RECEIVE_DATA);
+ g_assert(command->qualifier == test->qualifier);
+
+ g_assert(command->src == STK_DEVICE_IDENTITY_TYPE_UICC);
+ g_assert(command->dst == test->dst);
+
+ check_alpha_id(command->receive_data.alpha_id, test->alpha_id);
+ check_icon_id(&command->receive_data.icon_id, &test->icon_id);
+ check_common_byte(command->receive_data.data_len, test->data_len);
+ check_text_attr(&command->receive_data.text_attr, &test->text_attr);
+ check_frame_id(&command->receive_data.frame_id, &test->frame_id);
+
+ stk_command_free(command);
+}
+
+struct send_data_test {
+ const unsigned char *pdu;
+ unsigned int pdu_len;
+ unsigned char qualifier;
+ enum stk_device_identity_type dst;
+ char *alpha_id;
+ struct stk_icon_id icon_id;
+ struct stk_common_byte_array tx_data;
+ struct stk_text_attribute text_attr;
+ struct stk_frame_id frame_id;
+};
+
+static unsigned char send_data_111[] = { 0xD0, 0x13, 0x81, 0x03, 0x01, 0x43,
+ 0x01, 0x82, 0x02, 0x81, 0x21,
+ 0xB6, 0x08, 0x00, 0x01, 0x02,
+ 0x03, 0x04, 0x05, 0x06, 0x07 };
+
+static struct send_data_test send_data_data_111 = {
+ .pdu = send_data_111,
+ .pdu_len = sizeof(send_data_111),
+ .qualifier = STK_SEND_DATA_IMMEDIATELY,
+ .dst = STK_DEVICE_IDENTITY_TYPE_CHANNEL_1,
+ .tx_data = {
+ .array = (unsigned char[8]) {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
+ },
+ .len = 8,
+ },
+};
+
+static unsigned char send_data_121[] = {
+ 0xD0, 0x81, 0xD4, 0x81, 0x03, 0x01, 0x43, 0x00,
+ 0x82, 0x02, 0x81, 0x21, 0xB6, 0x81, 0xC8, 0x00,
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+ 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
+ 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
+ 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
+ 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
+ 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
+ 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
+ 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40,
+ 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
+ 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
+ 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
+ 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60,
+ 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
+ 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
+ 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
+ 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80,
+ 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88,
+ 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90,
+ 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
+ 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, 0xa0,
+ 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8,
+ 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0,
+ 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8,
+ 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, 0xc0,
+ 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7 };
+
+static struct send_data_test send_data_data_121 = {
+ .pdu = send_data_121,
+ .pdu_len = sizeof(send_data_121),
+ .qualifier = STK_SEND_DATA_STORE_DATA,
+ .dst = STK_DEVICE_IDENTITY_TYPE_CHANNEL_1,
+ .tx_data = {
+ .array = (unsigned char[200]) {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+ 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
+ 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
+ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
+ 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
+ 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
+ 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
+ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
+ 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
+ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
+ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
+ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
+ 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
+ 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
+ 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
+ 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
+ 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
+ },
+ .len = 200,
+ },
+};
+static unsigned char send_data_211[] = {
+ 0xD0, 0x26, 0x81, 0x03, 0x01, 0x43, 0x01, 0x82,
+ 0x02, 0x81, 0x21, 0x85, 0x0B, 0x53, 0x65, 0x6E,
+ 0x64, 0x20, 0x44, 0x61, 0x74, 0x61, 0x20, 0x31,
+ 0xB6, 0x08, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
+ 0x06, 0x07, 0xD0, 0x04, 0x00, 0x0B, 0x00, 0xB4,
+ };
+
+static struct send_data_test send_data_data_211 = {
+ .pdu = send_data_211,
+ .pdu_len = sizeof(send_data_211),
+ .qualifier = STK_SEND_DATA_IMMEDIATELY,
+ .dst = STK_DEVICE_IDENTITY_TYPE_CHANNEL_1,
+ .alpha_id = "Send Data 1",
+ .tx_data = {
+ .array = (unsigned char[8]) {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
+ },
+ .len = 8,
+ },
+ .text_attr = {
+ .len = 4,
+ .attributes = { 0x00, 0x0B, 0x00, 0xB4 }
+ },
+};
+
+static void test_send_data(gconstpointer data)
+{
+ const struct send_data_test *test = data;
+ struct stk_command *command;
+
+ command = stk_command_new_from_pdu(test->pdu, test->pdu_len);
+
+ g_assert(command);
+ g_assert(command->status == STK_PARSE_RESULT_OK);
+
+ g_assert(command->number == 1);
+ g_assert(command->type == STK_COMMAND_TYPE_SEND_DATA);
+ g_assert(command->qualifier == test->qualifier);
+
+ g_assert(command->src == STK_DEVICE_IDENTITY_TYPE_UICC);
+ g_assert(command->dst == test->dst);
+
+ check_alpha_id(command->send_data.alpha_id, test->alpha_id);
+ check_icon_id(&command->send_data.icon_id, &test->icon_id);
+ check_channel_data(&command->send_data.tx_data, &test->tx_data);
+ check_text_attr(&command->send_data.text_attr, &test->text_attr);
+ check_frame_id(&command->send_data.frame_id, &test->frame_id);
+
+ stk_command_free(command);
+}
+
+struct get_channel_status_test {
+ const unsigned char *pdu;
+ unsigned int pdu_len;
+ unsigned char qualifier;
+};
+
+static unsigned char get_channel_status_111[] = { 0xD0, 0x09, 0x81, 0x03, 0x01,
+ 0x44, 0x00, 0x82, 0x02,
+ 0x81, 0x82 };
+
+static struct get_channel_status_test get_channel_status_data_111 = {
+ .pdu = get_channel_status_111,
+ .pdu_len = sizeof(get_channel_status_111),
+ .qualifier = 0x00,
+};
+
+static void test_get_channel_status(gconstpointer data)
+{
+ const struct get_channel_status_test *test = data;
+ struct stk_command *command;
+
+ command = stk_command_new_from_pdu(test->pdu, test->pdu_len);
+
+ g_assert(command);
+ g_assert(command->status == STK_PARSE_RESULT_OK);
+
+ g_assert(command->number == 1);
+ g_assert(command->type == STK_COMMAND_TYPE_GET_CHANNEL_STATUS);
+ g_assert(command->qualifier == test->qualifier);
+
+ g_assert(command->src == STK_DEVICE_IDENTITY_TYPE_UICC);
+ g_assert(command->dst == STK_DEVICE_IDENTITY_TYPE_TERMINAL);
+
+ stk_command_free(command);
+}
+
struct terminal_response_test {
const unsigned char *pdu;
unsigned int pdu_len;
@@ -20884,6 +21608,366 @@ static const struct terminal_response_test launch_browser_response_data_411b = {
},
};
+static const unsigned char open_channel_response_211[] = {
+ 0x81, 0x03, 0x01, 0x40, 0x01, 0x82, 0x02, 0x82, 0x81, 0x83,
+ 0x01, 0x00, 0x38, 0x02, 0x81, 0x00, 0x35, 0x07, 0x02, 0x03,
+ 0x04, 0x03, 0x04, 0x1F, 0x02, 0x39, 0x02, 0x05, 0x78,
+};
+
+static const struct terminal_response_test open_channel_response_data_211 = {
+ .pdu = open_channel_response_211,
+ .pdu_len = sizeof(open_channel_response_211),
+ .response = {
+ .number = 1,
+ .type = STK_COMMAND_TYPE_OPEN_CHANNEL,
+ .qualifier = STK_OPEN_CHANNEL_IMMEDIATE,
+ .src = STK_DEVICE_IDENTITY_TYPE_TERMINAL,
+ .dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+ .result = {
+ .type = STK_RESULT_TYPE_SUCCESS,
+ },
+ { .open_channel = {
+ .channel = {
+ .id = 1,
+ .status = STK_CHANNEL_PACKET_DATA_SERVICE_ACTIVATED,
+ },
+ .bearer_desc = {
+ .type = STK_BEARER_TYPE_GPRS_UTRAN,
+ { .gprs = {
+ .precedence = 3,
+ .delay = 4,
+ .reliability = 3,
+ .peak = 4,
+ .mean = 31,
+ .pdp_type = 2,
+ } },
+ },
+ .buf_size = 1400,
+ } },
+ },
+};
+
+static const unsigned char open_channel_response_271[] = {
+ 0x81, 0x03, 0x01, 0x40, 0x01, 0x82, 0x02, 0x82, 0x81, 0x83,
+ 0x01, 0x22, 0x35, 0x07, 0x02, 0x03, 0x04, 0x03, 0x04, 0x1F,
+ 0x02, 0x39, 0x02, 0x05, 0x78,
+};
+
+static const struct terminal_response_test open_channel_response_data_271 = {
+ .pdu = open_channel_response_271,
+ .pdu_len = sizeof(open_channel_response_271),
+ .response = {
+ .number = 1,
+ .type = STK_COMMAND_TYPE_OPEN_CHANNEL,
+ .qualifier = STK_OPEN_CHANNEL_IMMEDIATE,
+ .src = STK_DEVICE_IDENTITY_TYPE_TERMINAL,
+ .dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+ .result = {
+ .type = STK_RESULT_TYPE_USER_REJECT,
+ },
+ { .open_channel = {
+ .bearer_desc = {
+ .type = STK_BEARER_TYPE_GPRS_UTRAN,
+ { .gprs = {
+ .precedence = 3,
+ .delay = 4,
+ .reliability = 3,
+ .peak = 4,
+ .mean = 31,
+ .pdp_type = 2,
+ } },
+ },
+ .buf_size = 1400,
+ } },
+ },
+};
+
+static const unsigned char close_channel_response_121[] = {
+ 0x81, 0x03, 0x01, 0x41, 0x00, 0x82, 0x02, 0x82, 0x81, 0x83,
+ 0x02, 0x3A, 0x03,
+};
+
+static const struct terminal_response_test close_channel_response_data_121 = {
+ .pdu = close_channel_response_121,
+ .pdu_len = sizeof(close_channel_response_121),
+ .response = {
+ .number = 1,
+ .type = STK_COMMAND_TYPE_CLOSE_CHANNEL,
+ .qualifier = 0x00,
+ .src = STK_DEVICE_IDENTITY_TYPE_TERMINAL,
+ .dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+ .result = {
+ .type = STK_RESULT_TYPE_BIP_ERROR,
+ .additional_len = 1, /* Channel identifier not valid */
+ .additional = (unsigned char[1]) { 0x03 },
+ },
+ },
+};
+
+static const unsigned char close_channel_response_131[] = {
+ 0x81, 0x03, 0x01, 0x41, 0x00, 0x82, 0x02, 0x82, 0x81, 0x83,
+ 0x02, 0x3A, 0x02,
+};
+
+static const struct terminal_response_test close_channel_response_data_131 = {
+ .pdu = close_channel_response_131,
+ .pdu_len = sizeof(close_channel_response_131),
+ .response = {
+ .number = 1,
+ .type = STK_COMMAND_TYPE_CLOSE_CHANNEL,
+ .qualifier = 0x00,
+ .src = STK_DEVICE_IDENTITY_TYPE_TERMINAL,
+ .dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+ .result = {
+ .type = STK_RESULT_TYPE_BIP_ERROR,
+ .additional_len = 1, /* Channel already closed */
+ .additional = (unsigned char[1]) { 0x02 },
+ },
+ },
+};
+
+static const unsigned char receive_data_response_111[] = {
+ 0x81, 0x03, 0x01, 0x42, 0x00, 0x82, 0x02, 0x82, 0x81, 0x83,
+ 0x01, 0x00, 0xB6, 0x81, 0xC8, 0xc8, 0xc9, 0xca, 0xcb, 0xcc,
+ 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6,
+ 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0,
+ 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
+ 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4,
+ 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe,
+ 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+ 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
+ 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c,
+ 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26,
+ 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
+ 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a,
+ 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44,
+ 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e,
+ 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
+ 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62,
+ 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c,
+ 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76,
+ 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x80,
+ 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a,
+ 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0xB7, 0x01, 0xFF,
+};
+
+static const struct terminal_response_test receive_data_response_data_111 = {
+ .pdu = receive_data_response_111,
+ .pdu_len = sizeof(receive_data_response_111),
+ .response = {
+ .number = 1,
+ .type = STK_COMMAND_TYPE_RECEIVE_DATA,
+ .qualifier = 0x00,
+ .src = STK_DEVICE_IDENTITY_TYPE_TERMINAL,
+ .dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+ .result = {
+ .type = STK_RESULT_TYPE_SUCCESS,
+ },
+ { .receive_data = {
+ .rx_data = {
+ .array = (unsigned char[200]) {
+ 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd,
+ 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3,
+ 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9,
+ 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
+ 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5,
+ 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb,
+ 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1,
+ 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
+ 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd,
+ 0xfe, 0xff, 0x00, 0x01, 0x02, 0x03,
+ 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
+ 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
+ 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
+ 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21,
+ 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+ 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
+ 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33,
+ 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
+ 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45,
+ 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,
+ 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51,
+ 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
+ 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d,
+ 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63,
+ 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
+ 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
+ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75,
+ 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b,
+ 0x7c, 0x7d, 0x7e, 0x7f, 0x80, 0x81,
+ 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d,
+ 0x8e, 0x8f,
+ },
+ .len = 200,
+ },
+ .data_left_length = 0xFF,
+ } },
+ },
+};
+
+static const unsigned char send_data_response_111[] = {
+ 0x81, 0x03, 0x01, 0x43, 0x01, 0x82, 0x02, 0x82, 0x81, 0x83,
+ 0x01, 0x00, 0xB7, 0x01, 0xFF,
+};
+
+static const struct terminal_response_test send_data_response_data_111 = {
+ .pdu = send_data_response_111,
+ .pdu_len = sizeof(send_data_response_111),
+ .response = {
+ .number = 1,
+ .type = STK_COMMAND_TYPE_SEND_DATA,
+ .qualifier = STK_SEND_DATA_IMMEDIATELY,
+ .src = STK_DEVICE_IDENTITY_TYPE_TERMINAL,
+ .dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+ .result = {
+ .type = STK_RESULT_TYPE_SUCCESS,
+ },
+ { .send_data = {
+ /* More than 255 bytes of space available */
+ .empty_data_length = 0xFF,
+ } },
+ },
+};
+
+static const unsigned char send_data_response_121[] = {
+ 0x81, 0x03, 0x01, 0x43, 0x00, 0x82, 0x02, 0x82, 0x81, 0x83,
+ 0x01, 0x00, 0xB7, 0x01, 0xFF,
+};
+
+static const struct terminal_response_test send_data_response_data_121 = {
+ .pdu = send_data_response_121,
+ .pdu_len = sizeof(send_data_response_121),
+ .response = {
+ .number = 1,
+ .type = STK_COMMAND_TYPE_SEND_DATA,
+ .qualifier = STK_SEND_DATA_STORE_DATA,
+ .src = STK_DEVICE_IDENTITY_TYPE_TERMINAL,
+ .dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+ .result = {
+ .type = STK_RESULT_TYPE_SUCCESS,
+ },
+ { .send_data = {
+ /* More than 255 bytes of space available */
+ .empty_data_length = 0xFF,
+ } },
+ },
+};
+
+static const unsigned char send_data_response_151[] = {
+ 0x81, 0x03, 0x01, 0x43, 0x01, 0x82, 0x02, 0x82, 0x81, 0x83,
+ 0x02, 0x3A, 0x03,
+};
+
+static const struct terminal_response_test send_data_response_data_151 = {
+ .pdu = send_data_response_151,
+ .pdu_len = sizeof(send_data_response_151),
+ .response = {
+ .number = 1,
+ .type = STK_COMMAND_TYPE_SEND_DATA,
+ .qualifier = STK_SEND_DATA_IMMEDIATELY,
+ .src = STK_DEVICE_IDENTITY_TYPE_TERMINAL,
+ .dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+ .result = {
+ .type = STK_RESULT_TYPE_BIP_ERROR,
+ .additional_len = 1, /* Channel identifier not valid */
+ .additional = (unsigned char[1]) { 0x03 },
+ },
+ },
+};
+
+static const unsigned char get_channel_status_response_111[] = {
+ 0x81, 0x03, 0x01, 0x44, 0x00, 0x82, 0x02, 0x82, 0x81, 0x83,
+ 0x01, 0x00, 0xB8, 0x02, 0x00, 0x00,
+};
+
+static const struct terminal_response_test
+ get_channel_status_response_data_111 = {
+ .pdu = get_channel_status_response_111,
+ .pdu_len = sizeof(get_channel_status_response_111),
+ .response = {
+ .number = 1,
+ .type = STK_COMMAND_TYPE_GET_CHANNEL_STATUS,
+ .qualifier = 0x00,
+ .src = STK_DEVICE_IDENTITY_TYPE_TERMINAL,
+ .dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+ .result = {
+ .type = STK_RESULT_TYPE_SUCCESS,
+ },
+ { .channel_status = {
+ /*
+ * No Channel available, link not established or
+ * PDP context not activated
+ */
+ .channel = {
+ .id = 0,
+ .status =
+ STK_CHANNEL_PACKET_DATA_SERVICE_NOT_ACTIVATED,
+ }
+ } },
+ },
+};
+
+static const unsigned char get_channel_status_response_121[] = {
+ 0x81, 0x03, 0x01, 0x44, 0x00, 0x82, 0x02, 0x82, 0x81, 0x83,
+ 0x01, 0x00, 0xB8, 0x02, 0x81, 0x00,
+};
+
+static const struct terminal_response_test
+ get_channel_status_response_data_121 = {
+ .pdu = get_channel_status_response_121,
+ .pdu_len = sizeof(get_channel_status_response_121),
+ .response = {
+ .number = 1,
+ .type = STK_COMMAND_TYPE_GET_CHANNEL_STATUS,
+ .qualifier = 0x00,
+ .src = STK_DEVICE_IDENTITY_TYPE_TERMINAL,
+ .dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+ .result = {
+ .type = STK_RESULT_TYPE_SUCCESS,
+ },
+ { .channel_status = {
+ /* Channel 1 open, link established or PDP context activated */
+ .channel = {
+ .id = 1,
+ .status =
+ STK_CHANNEL_PACKET_DATA_SERVICE_ACTIVATED,
+ },
+ } },
+ },
+};
+
+static const unsigned char get_channel_status_response_131[] = {
+ 0x81, 0x03, 0x01, 0x44, 0x00, 0x82, 0x02, 0x82, 0x81, 0x83,
+ 0x01, 0x00, 0xB8, 0x02, 0x01, 0x05,
+};
+
+static const struct terminal_response_test
+ get_channel_status_response_data_131 = {
+ .pdu = get_channel_status_response_131,
+ .pdu_len = sizeof(get_channel_status_response_131),
+ .response = {
+ .number = 1,
+ .type = STK_COMMAND_TYPE_GET_CHANNEL_STATUS,
+ .qualifier = 0x00,
+ .src = STK_DEVICE_IDENTITY_TYPE_TERMINAL,
+ .dst = STK_DEVICE_IDENTITY_TYPE_UICC,
+ .result = {
+ .type = STK_RESULT_TYPE_SUCCESS,
+ },
+ { .channel_status = {
+ /* Channel 1, link dropped */
+ .channel = {
+ .id = 1,
+ .status = STK_CHANNEL_LINK_DROPPED,
+ },
+ } },
+
+ },
+};
+
struct envelope_test {
const unsigned char *pdu;
unsigned int pdu_len;
@@ -22428,16 +23512,20 @@ static const struct envelope_test event_download_data_available_data_111 = {
.type = STK_EVENT_TYPE_DATA_AVAILABLE,
{ .data_available = {
/* Channel 1 open, Link established */
- .channel_status = { 0x81, 0x00 },
+ .channel = {
+ .id = 1,
+ .status =
+ STK_CHANNEL_PACKET_DATA_SERVICE_ACTIVATED,
+ },
.channel_data_len = 255,
- }},
- }},
+ } },
+ } },
},
};
static const unsigned char event_download_data_available_211[] = {
0xd6, 0x0e, 0x99, 0x01, 0x09, 0x82, 0x02, 0x82,
- 0x81, 0xb8, 0x02, 0x81, 0x01, 0xb7, 0x01, 0xff,
+ 0x81, 0xb8, 0x02, 0x81, 0x00, 0xb7, 0x01, 0xff,
};
static const struct envelope_test event_download_data_available_data_211 = {
@@ -22451,10 +23539,14 @@ static const struct envelope_test event_download_data_available_data_211 = {
.type = STK_EVENT_TYPE_DATA_AVAILABLE,
{ .data_available = {
/* Channel 1 open, Link established */
- .channel_status = { 0x81, 0x01 },
+ .channel = {
+ .id = 1,
+ .status =
+ STK_CHANNEL_PACKET_DATA_SERVICE_ACTIVATED,
+ },
.channel_data_len = 255,
- }},
- }},
+ } },
+ } },
},
};
@@ -22474,9 +23566,12 @@ static const struct envelope_test event_download_channel_status_data_131 = {
.type = STK_EVENT_TYPE_CHANNEL_STATUS,
{ .channel_status = {
/* Channel 1, Link dropped */
- .status = { 0x01, 0x05 },
- }},
- }},
+ .channel = {
+ .id = 1,
+ .status = STK_CHANNEL_LINK_DROPPED,
+ },
+ } },
+ } },
},
};
@@ -22500,15 +23595,18 @@ static const struct envelope_test event_download_channel_status_data_211 = {
.type = STK_EVENT_TYPE_CHANNEL_STATUS,
{ .channel_status = {
/* Channel 1, TCP in LISTEN state */
- .status = { 0x41, 0x00 },
- }},
- }},
+ .channel = {
+ .id = 1,
+ .status = STK_CHANNEL_TCP_IN_LISTEN_STATE,
+ },
+ } },
+ } },
},
};
static const unsigned char event_download_channel_status_221[] = {
0xd6, 0x0b, 0x99, 0x01, 0x0a, 0x82, 0x02, 0x82,
- 0x81, 0xb8, 0x02, 0x81, 0x01,
+ 0x81, 0xb8, 0x02, 0x81, 0x00,
/*
* Byte 10 changed to 0xb8 (Comprehension Required should be
* set according to TS 102 223 7.5.11.2)
@@ -22526,9 +23624,13 @@ static const struct envelope_test event_download_channel_status_data_221 = {
.type = STK_EVENT_TYPE_CHANNEL_STATUS,
{ .channel_status = {
/* Channel 1 open, TCP Link established */
- .status = { 0x81, 0x01 },
- }},
- }},
+ .channel = {
+ .id = 1,
+ .status =
+ STK_CHANNEL_PACKET_DATA_SERVICE_ACTIVATED,
+ },
+ } },
+ } },
},
};
@@ -24790,6 +25892,71 @@ int main(int argc, char **argv)
&launch_browser_response_data_411b,
test_terminal_response_encoding);
+
+ g_test_add_data_func("/teststk/Open channel 2.1.1",
+ &open_channel_data_211, test_open_channel);
+ g_test_add_data_func("/teststk/Open channel 2.2.1",
+ &open_channel_data_221, test_open_channel);
+ g_test_add_data_func("/teststk/Open channel 2.3.1",
+ &open_channel_data_231, test_open_channel);
+ g_test_add_data_func("/teststk/Open channel 2.4.1",
+ &open_channel_data_241, test_open_channel);
+ g_test_add_data_func("/teststk/Open channel 5.1.1",
+ &open_channel_data_511, test_open_channel);
+ g_test_add_data_func("/teststk/Open channel response 2.1.1",
+ &open_channel_response_data_211,
+ test_terminal_response_encoding);
+ g_test_add_data_func("/teststk/Open channel response 2.7.1",
+ &open_channel_response_data_271,
+ test_terminal_response_encoding);
+
+ g_test_add_data_func("/teststk/Close channel 1.1.1",
+ &close_channel_data_111, test_close_channel);
+ g_test_add_data_func("/teststk/Close channel 2.1.1",
+ &close_channel_data_211, test_close_channel);
+ g_test_add_data_func("/teststk/Close channel response 1.2.1",
+ &close_channel_response_data_121,
+ test_terminal_response_encoding);
+ g_test_add_data_func("/teststk/Close channel response 1.3.1",
+ &close_channel_response_data_131,
+ test_terminal_response_encoding);
+
+ g_test_add_data_func("/teststk/Receive data 1.1.1",
+ &receive_data_data_111, test_receive_data);
+ g_test_add_data_func("/teststk/Receive data 2.1.1",
+ &receive_data_data_211, test_receive_data);
+ g_test_add_data_func("/teststk/Receive data response 1.1.1",
+ &receive_data_response_data_111,
+ test_terminal_response_encoding);
+
+ g_test_add_data_func("/teststk/Send data 1.1.1",
+ &send_data_data_111, test_send_data);
+ g_test_add_data_func("/teststk/Send data 1.2.1",
+ &send_data_data_121, test_send_data);
+ g_test_add_data_func("/teststk/Send data 2.1.1",
+ &send_data_data_211, test_send_data);
+ g_test_add_data_func("/teststk/Send data response 1.1.1",
+ &send_data_response_data_111,
+ test_terminal_response_encoding);
+ g_test_add_data_func("/teststk/Send data response 1.2.1",
+ &send_data_response_data_121,
+ test_terminal_response_encoding);
+ g_test_add_data_func("/teststk/Send data response 1.5.1",
+ &send_data_response_data_151,
+ test_terminal_response_encoding);
+
+ g_test_add_data_func("/teststk/Get Channel status 1.1.1",
+ &get_channel_status_data_111, test_get_channel_status);
+ g_test_add_data_func("/teststk/Get Channel status response 1.1.1",
+ &get_channel_status_response_data_111,
+ test_terminal_response_encoding);
+ g_test_add_data_func("/teststk/Get Channel status response 1.2.1",
+ &get_channel_status_response_data_121,
+ test_terminal_response_encoding);
+ g_test_add_data_func("/teststk/Get Channel status response 1.3.1",
+ &get_channel_status_response_data_131,
+ test_terminal_response_encoding);
+
g_test_add_data_func("/teststk/SMS-PP data download 1.6.1",
&sms_pp_data_download_data_161,
test_envelope_encoding);
--
1.7.1
11 years, 5 months
[PATCH 0/6] Introduction of BIP commands (STK classe 'e')
by Philippe Nunes
The following set of patches introduces the preliminary support of the BIP commands:
- Open channel
- Close channel
- Receive data
- Send data
- Get channel status
Next step is precisely the channel setup (through a connman plugin) and the Rx/Tx data buffer management.
Philippe Nunes (6):
test-stkutil: Add unit tests for BIP commands
stk-api.txt: Describe new d-bus APIs related to BIP commands.
stk: Introduce BIP command handlers
stkagent: Add new methods to support the BIP commands
stkutil: Complete the TLV parsing/builder to support BIP commands
test-stk-menu: Add support for BIP commands
doc/stk-api.txt | 27 ++-
src/stk.c | 307 +++++++++++++
src/stkagent.c | 129 ++++++
src/stkagent.h | 17 +
src/stkutil.c | 300 ++++++++++++-
src/stkutil.h | 141 ++++++-
test/test-stk-menu | 22 +
unit/test-stkutil.c | 1201 ++++++++++++++++++++++++++++++++++++++++++++++++++-
8 files changed, 2087 insertions(+), 57 deletions(-)
11 years, 5 months
[PATCH 6/6] emulator: add ppp_suspend() CB and register it
by Guillaume Zajac
---
src/emulator.c | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/src/emulator.c b/src/emulator.c
index c84f0a9..c1ceb36 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -99,6 +99,15 @@ static void ppp_disconnect(GAtPPPDisconnectReason reason, gpointer user_data)
g_at_server_resume(em->server);
}
+static void ppp_suspend(gpointer user_data)
+{
+ struct ofono_emulator *em = user_data;
+
+ DBG("");
+
+ g_at_server_resume(em->server);
+}
+
static gboolean setup_ppp(gpointer user_data)
{
struct ofono_emulator *em = user_data;
@@ -126,6 +135,7 @@ static gboolean setup_ppp(gpointer user_data)
g_at_ppp_set_connect_function(em->ppp, ppp_connect, em);
g_at_ppp_set_disconnect_function(em->ppp, ppp_disconnect, em);
+ g_at_ppp_set_suspend_function(em->ppp, ppp_suspend, em);
return FALSE;
}
--
1.7.1
11 years, 5 months
[PATCH 5/6] gatppp: add g_at_ppp_set_suspend_function() definition
by Guillaume Zajac
---
gatchat/gatppp.c | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/gatchat/gatppp.c b/gatchat/gatppp.c
index 993b5ea..9df6b8e 100644
--- a/gatchat/gatppp.c
+++ b/gatchat/gatppp.c
@@ -467,6 +467,14 @@ void g_at_ppp_set_debug(GAtPPP *ppp, GAtDebugFunc func, gpointer user_data)
ppp->debug_data = user_data;
}
+void g_at_ppp_set_suspend_function(GAtPPP *ppp, GAtSuspendFunc func, gpointer user_data)
+{
+ if (ppp == NULL)
+ return;
+
+ g_at_hdlc_set_suspend_function(ppp->hdlc, func, user_data);
+}
+
void g_at_ppp_shutdown(GAtPPP *ppp)
{
if (ppp->phase == PPP_PHASE_DEAD || ppp->phase == PPP_PHASE_TERMINATION)
--
1.7.1
11 years, 5 months
[PATCH 4/6] gatppp: add g_at_ppp_set_suspend_function() prototype
by Guillaume Zajac
---
gatchat/gatppp.h | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/gatchat/gatppp.h b/gatchat/gatppp.h
index fb5de4c..7835d1f 100644
--- a/gatchat/gatppp.h
+++ b/gatchat/gatppp.h
@@ -61,6 +61,8 @@ void g_at_ppp_set_connect_function(GAtPPP *ppp, GAtPPPConnectFunc callback,
void g_at_ppp_set_disconnect_function(GAtPPP *ppp, GAtPPPDisconnectFunc func,
gpointer user_data);
void g_at_ppp_set_debug(GAtPPP *ppp, GAtDebugFunc func, gpointer user_data);
+void g_at_ppp_set_suspend_function(GAtPPP *ppp, GAtSuspendFunc func,
+ gpointer user_data);
void g_at_ppp_shutdown(GAtPPP *ppp);
void g_at_ppp_ref(GAtPPP *ppp);
void g_at_ppp_unref(GAtPPP *ppp);
--
1.7.1
11 years, 5 months
[PATCH 3/6] gathdlc: add mechansim to detect '+++' escape sequence
by Guillaume Zajac
---
gatchat/gathdlc.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 114 insertions(+), 0 deletions(-)
diff --git a/gatchat/gathdlc.c b/gatchat/gathdlc.c
index 7c45454..21e4533 100644
--- a/gatchat/gathdlc.c
+++ b/gatchat/gathdlc.c
@@ -50,6 +50,13 @@
#define HDLC_FCS(fcs, c) crc_ccitt_byte(fcs, c)
+/* Amount of fiftieths of second to detect '+++'.
+ * Range is 0 to 0xff.
+ */
+#define ESC_TIME 0x32
+
+#define GUARD_TIMEOUTS 1000 /* Pause time before and after '+++' sequence */
+
struct _GAtHDLC {
gint ref_count;
GAtIO *io;
@@ -68,6 +75,12 @@ struct _GAtHDLC {
gboolean in_read_handler;
gboolean destroyed;
gboolean no_carrier_detect;
+ GAtSuspendFunc suspend_func;
+ gpointer suspend_data;
+ guint cmpt;
+ guint suspend_timeout;
+ guint pause_timeout;
+ gboolean paused;
};
static void hdlc_record(int fd, gboolean in, guint8 *data, guint16 length)
@@ -130,6 +143,47 @@ guint32 g_at_hdlc_get_recv_accm(GAtHDLC *hdlc)
return hdlc->recv_accm;
}
+void g_at_hdlc_set_suspend_function(GAtHDLC *hdlc, GAtSuspendFunc func,
+ gpointer user_data)
+{
+ if (hdlc == NULL)
+ return;
+
+ hdlc->suspend_func = func;
+ hdlc->suspend_data = user_data;
+}
+
+static gboolean paused_timeout_cb(gpointer user_data)
+{
+ GAtHDLC *hdlc = user_data;
+
+ hdlc->paused = TRUE;
+
+ return FALSE;
+}
+
+static gboolean susp_timeout_cb(gpointer user_data)
+{
+ GAtHDLC *hdlc = user_data;
+
+ hdlc->cmpt = 0;
+
+ return FALSE;
+}
+
+static gboolean hdlc_suspend(gpointer user_data)
+{
+ GAtHDLC *hdlc = user_data;
+
+ g_at_io_set_write_handler(hdlc->io, NULL, NULL);
+ g_at_io_set_read_handler(hdlc->io, NULL, NULL);
+
+ if (hdlc->suspend_func)
+ hdlc->suspend_func(hdlc->suspend_data);
+
+ return FALSE;
+}
+
static void new_bytes(struct ring_buffer *rbuf, gpointer user_data)
{
GAtHDLC *hdlc = user_data;
@@ -142,6 +196,13 @@ static void new_bytes(struct ring_buffer *rbuf, gpointer user_data)
hdlc->in_read_handler = TRUE;
+ /*
+ * We delete the the paused_timeout_cb or hdlc_suspend as soons as
+ * we read a data.
+ */
+ if (hdlc->pause_timeout > 0)
+ g_source_remove(hdlc->pause_timeout);
+
while (pos < len) {
/*
* We try to detect NO CARRIER conditions here. We
@@ -153,6 +214,21 @@ static void new_bytes(struct ring_buffer *rbuf, gpointer user_data)
hdlc->decode_offset == 0 && *buf == '\r')
break;
+ /*
+ * If there was no character for 1 second we try to detect
+ * the '+' character to suspend data call if 3 '+' are
+ * detected in less than 20 * ESC_TIME milliseconds.
+ */
+ if (*buf == '+' && hdlc->paused) {
+ if (hdlc->cmpt == 0)
+ hdlc->suspend_timeout = g_timeout_add (20 * ESC_TIME,
+ susp_timeout_cb, hdlc);
+ hdlc->cmpt++;
+ } else {
+ hdlc->cmpt = 0;
+ hdlc->paused = FALSE;
+ }
+
if (hdlc->decode_escape == TRUE) {
unsigned char val = *buf ^ HDLC_TRANS;
@@ -190,6 +266,9 @@ static void new_bytes(struct ring_buffer *rbuf, gpointer user_data)
}
}
+ if (hdlc->cmpt == 3)
+ goto suspend;
+
out:
ring_buffer_drain(rbuf, pos);
@@ -197,6 +276,37 @@ out:
if (hdlc->destroyed)
g_free(hdlc);
+
+ /*
+ * If there were no data pause for GUARD_TIMEOUTS ms,
+ * we try again to check it.
+ */
+ if (!hdlc->paused)
+ hdlc->pause_timeout = g_timeout_add (GUARD_TIMEOUTS,
+ paused_timeout_cb,
+ hdlc);
+
+ return;
+
+suspend:
+ /*
+ * If the suspend timeout still exists,
+ * delete it.
+ */
+ if (hdlc->suspend_timeout > 0)
+ g_source_remove(hdlc->suspend_timeout);
+
+ /*
+ * Restart the counter and reset the ring buffer.
+ */
+ hdlc->cmpt = 0;
+ ring_buffer_reset(rbuf);
+
+ /*
+ * Wait for another pause of GUARD_TIMEOUTS ms before returning to command mode.
+ */
+ hdlc->paused = FALSE;
+ hdlc->pause_timeout = g_timeout_add (GUARD_TIMEOUTS, hdlc_suspend, hdlc);
}
GAtHDLC *g_at_hdlc_new_from_io(GAtIO *io)
@@ -245,6 +355,10 @@ GAtHDLC *g_at_hdlc_new_from_io(GAtIO *io)
hdlc->io = g_at_io_ref(io);
g_at_io_set_read_handler(hdlc->io, new_bytes, hdlc);
+ hdlc->cmpt = 0;
+
+ hdlc->paused = FALSE;
+
return hdlc;
error:
--
1.7.1
11 years, 5 months
[PATCH 2/6] gathdlc: add g_at_hdlc_set_suspend_function() prototype
by Guillaume Zajac
---
gatchat/gathdlc.h | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/gatchat/gathdlc.h b/gatchat/gathdlc.h
index 95c389e..158f27f 100644
--- a/gatchat/gathdlc.h
+++ b/gatchat/gathdlc.h
@@ -57,6 +57,9 @@ GAtIO *g_at_hdlc_get_io(GAtHDLC *hdlc);
void g_at_hdlc_set_no_carrier_detect(GAtHDLC *hdlc, gboolean detect);
+void g_at_hdlc_set_suspend_function(GAtHDLC *hdlc, GAtSuspendFunc func,
+ gpointer user_data);
+
#ifdef __cplusplus
}
#endif
--
1.7.1
11 years, 5 months