stkutil: Add SMS-PP Data Download envelope builder
PATCH 1/11 stkutil: Add SMS-PP Data Download envelope builder
Note that the sms_tpdu member could be of type struct sms_deliver, but the users may more often have access to the raw tpdu so there's no point decoding and reencoding it.
--- src/stkutil.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/stkutil.h | 21 +++++++++++++ 2 files changed, 114 insertions(+), 0 deletions(-)
src/stkutil.c +93 -0
@@ -3128,6 +3128,20 @@ static gboolean stk_tlv_builder_init(struct stk_tlv_builder *iter,return comprehension_tlv_builder_init (&iter->ctlv, pdu, size); } +static gboolean stk_tlv_builder_recurse (struct stk_tlv_builder *iter, +struct ber_tlv_builder *btlv, +unsigned char tag) +{ + iter->value =NULL ; + iter->len =0 ; + +if (ber_tlv_builder_next (btlv, tag >>6 , (tag >>5 ) &1 , + tag &0x1f ) != TRUE) +return FALSE; + +return ber_tlv_builder_recurse_comprehension (btlv, &iter->ctlv); +} + static gboolean stk_tlv_builder_open_container(struct stk_tlv_builder *iter, gboolean cr, unsigned char shorttag,
@@ -3308,6 +3322,23 @@ static inline gboolean stk_tlv_builder_append_bytes(struct stk_tlv_builder *iterreturn TRUE; } +/* Described in TS 102.223 Section 8.1 */ +static gboolean build_dataobj_address (struct stk_tlv_builder *tlv, +const void *data,gboolean cr) +{ +const struct stk_address *addr = data; +unsigned char tag =STK_DATA_OBJECT_TYPE_ADDRESS ; +unsigned int len = (strlen (addr->number) +1 ) /2 ; +unsigned char number[len]; + +sim_encode_bcd_number (addr->number, number); + +return stk_tlv_builder_open_container (tlv, cr, tag, FALSE) && +stk_tlv_builder_append_byte (tlv, addr->ton_npi) && +stk_tlv_builder_append_bytes (tlv, number, len) && +stk_tlv_builder_close_container (tlv); +} +/* Described in TS 102.223 Section 8.6 */ static gboolean build_dataobj_item_id (struct stk_tlv_builder *tlv,const void *data,gboolean cr)
@@ -3360,6 +3391,18 @@ static gboolean build_dataobj_result(struct stk_tlv_builder *tlv,return stk_tlv_builder_close_container (tlv); } +/* Described in TS 131.111 Section 8.13 */ +static gboolean build_dataobj_gsm_sms_tpdu (struct stk_tlv_builder *tlv, +const void *data,gboolean cr) +{ +const struct stk_common_byte_array *tpdu = data; +unsigned char tag =STK_DATA_OBJECT_TYPE_GSM_SMS_TPDU ; + +return stk_tlv_builder_open_container (tlv, cr, tag, TRUE) && +stk_tlv_builder_append_bytes (tlv, tpdu->array, tpdu->len) && +stk_tlv_builder_close_container (tlv); +} +/* Defined in TS 102.223 Section 8.15 */ static gboolean build_dataobj_text (struct stk_tlv_builder *tlv,const void *data,gboolean cr)
@@ -4099,3 +4142,53 @@ unsigned int stk_pdu_from_response(const struct stk_response *response,return stk_tlv_builder_get_length (&builder); } + +ofono_bool_t stk_pdu_from_envelope (const struct stk_envelope *envelope, +unsigned char *pdu,unsigned int size, +unsigned char **out_pdu, +unsigned int *out_size) +{ +struct ber_tlv_builder btlv; +struct stk_tlv_builder builder; +gboolean ok = TRUE; +unsigned char tag; + +if (ber_tlv_builder_init (&btlv, pdu, size) != TRUE) +return FALSE; + +if (stk_tlv_builder_recurse (&builder, &btlv, envelope->type) != TRUE) +return FALSE; + + tag =STK_DATA_OBJECT_TYPE_DEVICE_IDENTITIES ; +if (stk_tlv_builder_open_container (&builder, TRUE, tag, FALSE) == FALSE) +return FALSE; + +if (stk_tlv_builder_append_byte (&builder, envelope->src) == FALSE) +return FALSE; + +if (stk_tlv_builder_append_byte (&builder, envelope->dst) == FALSE) +return FALSE; + +if (stk_tlv_builder_close_container (&builder) == FALSE) +return FALSE; + +switch (envelope->type) { +case STK_ENVELOPE_TYPE_SMS_PP_DOWNLOAD : + ok =build_dataobj (&builder, + build_dataobj_address,0 , + &envelope->sms_pp_download.address, + build_dataobj_gsm_sms_tpdu, +DATAOBJ_FLAG_CR , + &envelope->sms_pp_download.sms_tpdu, +NULL ); +break ; +default : +return FALSE; + }; + +if (ok != TRUE) +return ok; + +ber_tlv_builder_optimize (&btlv, out_pdu, out_size); +return TRUE; +}
src/stkutil.h +21 -0
@@ -1172,6 +1172,21 @@ struct stk_response {void (*destructor)(struct stk_response *response); }; +/* ENVELOPEs defined in TS 102.223 Section 7 */ +struct stk_envelope_sms_pp_download { +struct stk_address address; +struct stk_common_byte_array sms_tpdu; +}; + +struct stk_envelope { +enum stk_envelope_type type; +enum stk_device_identity_type src; +enum stk_device_identity_type dst; +union { +struct stk_envelope_sms_pp_download sms_pp_download; + }; +}; +struct stk_command *stk_command_new_from_pdu (const unsigned char *pdu,unsigned int len);void stk_command_free (struct stk_command *command);
@@ -1179,3 +1194,9 @@ void stk_command_free(struct stk_command *command);/* Returns # of bytes written or zero on error */ unsigned int stk_pdu_from_response (const struct stk_response *response,unsigned char *pdu,unsigned int size); + +/* Returns TRUE on success */ +ofono_bool_t stk_pdu_from_envelope (const struct stk_envelope *envelope, +unsigned char *pdu,unsigned int size, +unsigned char **out_pdu, +unsigned int *out_size);
Signature · 1 line
1.7.1.86.g0e460.dirty
PATCH 2/11 test-stkutil: Tests for SMS-PP Data Download envelope builder
--- unit/test-stkutil.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 158 insertions(+), 0 deletions(-)
unit/test-stkutil.c +158 -0
@@ -17838,6 +17838,154 @@ static const struct terminal_response_test launch_browser_response_data_411b = { }, }; +struct envelope_test { +const unsigned char *pdu; +unsigned int pdu_len; +struct stk_envelope envelope; +}; + +static void test_envelope_encoding (gconstpointer data) +{ +const struct envelope_test *test = data; +unsigned char buf[512 ], *pdu; +unsigned int len; + +g_assert (stk_pdu_from_envelope (&test->envelope, + buf,sizeof (buf), &pdu, &len) == TRUE); + +g_assert (len == test->pdu_len); +g_assert (memcmp (pdu, test->pdu, len) ==0 ); +} + +static const unsigned char sms_pp_data_download_161[] = { +0xd1 ,0x2d ,0x82 ,0x02 ,0x83 ,0x81 ,0x06 ,0x09 , +0x91 ,0x11 ,0x22 ,0x33 ,0x44 ,0x55 ,0x66 ,0x77 , +0xf8 ,0x8b ,0x1c ,0x04 ,0x04 ,0x91 ,0x21 ,0x43 , +0x7f ,0x16 ,0x89 ,0x10 ,0x10 ,0x00 ,0x00 ,0x00 , +0x00 ,0x0d ,0x53 ,0x68 ,0x6f ,0x72 ,0x74 ,0x20 , +0x4d ,0x65 ,0x73 ,0x73 ,0x61 ,0x67 ,0x65 , +}; + +static const struct envelope_test sms_pp_data_download_data_161 = { + .pdu = sms_pp_data_download_161, + .pdu_len =sizeof (sms_pp_data_download_161), + .envelope = { + .type =STK_ENVELOPE_TYPE_SMS_PP_DOWNLOAD , + .src =STK_DEVICE_IDENTITY_TYPE_NETWORK , + .dst =STK_DEVICE_IDENTITY_TYPE_UICC , + { .sms_pp_download = { + .address = { + .ton_npi =0x91 ,/* Intl, ISDN */ + .number ="112233445566778" , + }, + .sms_tpdu = { + .array = (unsigned char [28 ]) { +0x04 ,0x04 ,0x91 ,0x21 ,0x43 ,0x7f , +0x16 ,0x89 ,0x10 ,0x10 ,0x00 ,0x00 , +0x00 ,0x00 ,0x0d ,0x53 ,0x68 ,0x6f , +0x72 ,0x74 ,0x20 ,0x4d ,0x65 ,0x73 , +0x73 ,0x61 ,0x67 ,0x65 , + }, + .len =28 , + }, +/* Corresponds to (struct sms_deliver) { +* .oaddr = { +* .number_type = +* SMS_NUMBER_TYPE_INTERNATIONAL, +* .numbering_plan = +* SMS_NUMBERING_PLAN_ISDN, +* .address = "1234", +* }, +* .pid = SMS_PID_TYPE_USIM_DOWNLOAD, +* .dcs = 0x16, // General, uncompr, Class 2, 8-bit +* .scts = { +* .year = 98, +* .month = 0, +* .day = 0, +* }, +* .udl = 13, +* .ud = "Short Message", +* } +*/ + }}, + }, +}; + +static const unsigned char sms_pp_data_download_162[] = { +0xd1 ,0x2d ,0x82 ,0x02 ,0x83 ,0x81 ,0x06 ,0x09 , +0x91 ,0x11 ,0x22 ,0x33 ,0x44 ,0x55 ,0x66 ,0x77 , +0xf8 ,0x8b ,0x1c ,0x04 ,0x04 ,0x91 ,0x21 ,0x43 , +0x7f ,0xf6 ,0x89 ,0x10 ,0x10 ,0x00 ,0x00 ,0x00 , +0x00 ,0x0d ,0x53 ,0x68 ,0x6f ,0x72 ,0x74 ,0x20 , +0x4d ,0x65 ,0x73 ,0x73 ,0x61 ,0x67 ,0x65 , +}; + +static const struct envelope_test sms_pp_data_download_data_162 = { + .pdu = sms_pp_data_download_162, + .pdu_len =sizeof (sms_pp_data_download_162), + .envelope = { + .type =STK_ENVELOPE_TYPE_SMS_PP_DOWNLOAD , + .src =STK_DEVICE_IDENTITY_TYPE_NETWORK , + .dst =STK_DEVICE_IDENTITY_TYPE_UICC , + { .sms_pp_download = { + .address = { + .ton_npi =0x91 ,/* Intl, ISDN */ + .number ="112233445566778" , + }, + .sms_tpdu = { + .array = (unsigned char [28 ]) { +0x04 ,0x04 ,0x91 ,0x21 ,0x43 ,0x7f , +0xf6 ,0x89 ,0x10 ,0x10 ,0x00 ,0x00 , +0x00 ,0x00 ,0x0d ,0x53 ,0x68 ,0x6f , +0x72 ,0x74 ,0x20 ,0x4d ,0x65 ,0x73 , +0x73 ,0x61 ,0x67 ,0x65 , + }, + .len =28 , + }, + }}, + }, +}; + +static const unsigned char sms_pp_data_download_182[] = { +0xd1 ,0x3e ,0x82 ,0x02 ,0x83 ,0x81 ,0x06 ,0x09 , +0x91 ,0x11 ,0x22 ,0x33 ,0x44 ,0x55 ,0x66 ,0x77 , +0xf8 ,0x8b ,0x2d ,0x44 ,0x04 ,0x91 ,0x21 ,0x43 , +0x7f ,0xf6 ,0x89 ,0x10 ,0x10 ,0x00 ,0x00 ,0x00 , +0x00 ,0x1e ,0x02 ,0x70 ,0x00 ,0x00 ,0x19 ,0x00 , +0x0d ,0x00 ,0x00 ,0x00 ,0x00 ,0xbf ,0xff ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x01 ,0x00 ,0xdc ,0xdc , +0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc , +}; + +static const struct envelope_test sms_pp_data_download_data_182 = { + .pdu = sms_pp_data_download_182, + .pdu_len =sizeof (sms_pp_data_download_182), + .envelope = { + .type =STK_ENVELOPE_TYPE_SMS_PP_DOWNLOAD , + .src =STK_DEVICE_IDENTITY_TYPE_NETWORK , + .dst =STK_DEVICE_IDENTITY_TYPE_UICC , + { .sms_pp_download = { + .address = { + .ton_npi =0x91 ,/* Intl, ISDN */ + .number ="112233445566778" , + }, + .sms_tpdu = { + .array = (unsigned char [45 ]) { +0x44 ,0x04 ,0x91 ,0x21 ,0x43 ,0x7f , +0xf6 ,0x89 ,0x10 ,0x10 ,0x00 ,0x00 , +0x00 ,0x00 ,0x1e ,0x02 ,0x70 ,0x00 , +0x00 ,0x19 ,0x00 ,0x0d ,0x00 ,0x00 , +0x00 ,0x00 ,0xbf ,0xff ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x01 ,0x00 ,0xdc , +0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc , +0xdc ,0xdc ,0xdc , + }, + .len =45 , + }, + }}, + }, +}; +int main (int argc,char **argv) {g_test_init (&argc, &argv,NULL );
@@ -19499,5 +19647,15 @@ int main(int argc, char **argv) &launch_browser_response_data_411b, 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); +g_test_add_data_func ("/teststk/SMS-PP data download 1.6.2" , + &sms_pp_data_download_data_162, + test_envelope_encoding); +g_test_add_data_func ("/teststk/SMS-PP data download 1.8.2" , + &sms_pp_data_download_data_182, + test_envelope_encoding); +return g_test_run (); }
Signature · 1 line
1.7.1.86.g0e460.dirty
PATCH 3/11 stkutil: Add CBS-PP Data Download envelope builder
In reply to Andrzej Zaborowski--- src/stkutil.c | 18 ++++++++++++++++++ src/stkutil.h | 5 +++++ 2 files changed, 23 insertions(+), 0 deletions(-)
src/stkutil.c +18 -0
@@ -3339,6 +3339,17 @@ static gboolean build_dataobj_address(struct stk_tlv_builder *tlv,stk_tlv_builder_close_container (tlv); } +/* Described in TS 131.111 Section 8.5 */ +static gboolean build_dataobj_cbs_page (struct stk_tlv_builder *tlv, +const void *data,gboolean cr) +{ +unsigned char tag =STK_DATA_OBJECT_TYPE_CBS_PAGE ; + +return stk_tlv_builder_open_container (tlv, cr, tag, TRUE) && +stk_tlv_builder_append_bytes (tlv, data,88 ) && +stk_tlv_builder_close_container (tlv); +} +/* Described in TS 102.223 Section 8.6 */ static gboolean build_dataobj_item_id (struct stk_tlv_builder *tlv,const void *data,gboolean cr)
@@ -4182,6 +4193,13 @@ ofono_bool_t stk_pdu_from_envelope(const struct stk_envelope *envelope, &envelope->sms_pp_download.sms_tpdu, NULL);break ; +case STK_ENVELOPE_TYPE_CBS_PP_DOWNLOAD : + ok =build_dataobj (&builder, + build_dataobj_cbs_page, +DATAOBJ_FLAG_CR , + envelope->cbs_pp_download.page, +NULL ); +break ;default :return FALSE; };
src/stkutil.h +5 -0
@@ -1178,12 +1178,17 @@ struct stk_envelope_sms_pp_download {struct stk_common_byte_array sms_tpdu; }; +struct stk_envelope_cbs_pp_download { +unsigned char page[88 ]; +}; +struct stk_envelope {enum stk_envelope_type type;enum stk_device_identity_type src;enum stk_device_identity_type dst;union {struct stk_envelope_sms_pp_download sms_pp_download; +struct stk_envelope_cbs_pp_download cbs_pp_download; }; };
Signature · 1 line
1.7.1.86.g0e460.dirty
PATCH 4/11 stk: Use envelope encoding utility from stkutil.c
In reply to Andrzej Zaborowski--- src/stk.c | 28 +++++++++++++++++----------- 1 files changed, 17 insertions(+), 11 deletions(-)
src/stk.c +17 -11
@@ -49,6 +49,8 @@ static void stk_cbs_download_cb(const struct ofono_error *error, {if (error->type !=OFONO_ERROR_TYPE_NO_ERROR ) {ofono_error ("CellBroadcast download to UICC failed" ); +/* "The ME may retry to deliver the same Cell Broadcast +* page." */ return ; }
@@ -58,23 +60,27 @@ static void stk_cbs_download_cb(const struct ofono_error *error,void __ofono_cbs_sim_download (struct ofono_stk *stk,const guint8 *pdu,int pdu_len) { -guint8 tlv[pdu_len +8 ]; +guint8 buf[512 ], *tlv; +struct stk_envelope e; +unsigned int tlv_len; + +if (pdu_len !=88 ) { +ofono_error ("Bad CellBroadcast page length" ); +return ; + }if (stk->driver->envelope ==NULL )return ; - tlv[0 ] =STK_ENVELOPE_TYPE_CBS_PP_DOWNLOAD ; - tlv[1 ] =6 + pdu_len; - tlv[2 ] =0x80 |STK_DATA_OBJECT_TYPE_DEVICE_IDENTITIES ; - tlv[3 ] =0x02 ;/* Device Identities length */ - tlv[4 ] =STK_DEVICE_IDENTITY_TYPE_NETWORK ; - tlv[5 ] =STK_DEVICE_IDENTITY_TYPE_UICC ; - tlv[6 ] =0x80 |STK_DATA_OBJECT_TYPE_CBS_PAGE ; - tlv[7 ] = pdu_len; + e.type =STK_ENVELOPE_TYPE_CBS_PP_DOWNLOAD ; + e.src =STK_DEVICE_IDENTITY_TYPE_NETWORK ; + e.dst =STK_DEVICE_IDENTITY_TYPE_UICC ; +memcpy (e.cbs_pp_download.page, pdu, pdu_len); -memcpy (tlv +8 , pdu, pdu_len); +if (stk_pdu_from_envelope (&e, buf,sizeof (buf), &tlv, &tlv_len) != TRUE) +return ; - stk->driver->envelope (stk, pdu_len +8 , tlv, stk_cbs_download_cb, stk); + stk->driver->envelope (stk, tlv_len, tlv, stk_cbs_download_cb, stk); } void ofono_stk_proactive_command_notify(struct ofono_stk *stk,
Signature · 1 line
1.7.1.86.g0e460.dirty
PATCH 5/11 test-stkutil: Tests for CBS-PP Data Download envelope builder
In reply to Andrzej Zaborowski--- unit/test-stkutil.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 85 insertions(+), 0 deletions(-)
unit/test-stkutil.c +85 -0
@@ -17986,6 +17986,86 @@ static const struct envelope_test sms_pp_data_download_data_182 = { }, }; +static const unsigned char cbs_pp_data_download_11[] = { +0xd2 ,0x5e ,0x82 ,0x02 ,0x83 ,0x81 ,0x8c ,0x58 , +0xc0 ,0x11 ,0x10 ,0x01 ,0x01 ,0x11 ,0xc3 ,0x32 , +0x9b ,0x0d ,0x12 ,0xca ,0xdf ,0x61 ,0xf2 ,0x38 , +0x3c ,0xa7 ,0x83 ,0x40 ,0x20 ,0x10 ,0x08 ,0x04 , +0x02 ,0x81 ,0x40 ,0x20 ,0x10 ,0x08 ,0x04 ,0x02 , +0x81 ,0x40 ,0x20 ,0x10 ,0x08 ,0x04 ,0x02 ,0x81 , +0x40 ,0x20 ,0x10 ,0x08 ,0x04 ,0x02 ,0x81 ,0x40 , +0x20 ,0x10 ,0x08 ,0x04 ,0x02 ,0x81 ,0x40 ,0x20 , +0x10 ,0x08 ,0x04 ,0x02 ,0x81 ,0x40 ,0x20 ,0x10 , +0x08 ,0x04 ,0x02 ,0x81 ,0x40 ,0x20 ,0x10 ,0x08 , +0x04 ,0x02 ,0x81 ,0x40 ,0x20 ,0x10 ,0x08 ,0x04 , +0x02 ,0x81 ,0x40 ,0x20 ,0x10 ,0x08 ,0x04 ,0x02 , +}; + +static const struct envelope_test cbs_pp_data_download_data_11 = { + .pdu = cbs_pp_data_download_11, + .pdu_len =sizeof (cbs_pp_data_download_11), + .envelope = { + .type =STK_ENVELOPE_TYPE_CBS_PP_DOWNLOAD , + .src =STK_DEVICE_IDENTITY_TYPE_NETWORK , + .dst =STK_DEVICE_IDENTITY_TYPE_UICC , + { .cbs_pp_download = { + .page = { +0xc0 ,0x11 ,0x10 ,0x01 ,0x01 ,0x11 ,0xc3 ,0x32 , +0x9b ,0x0d ,0x12 ,0xca ,0xdf ,0x61 ,0xf2 ,0x38 , +0x3c ,0xa7 ,0x83 ,0x40 ,0x20 ,0x10 ,0x08 ,0x04 , +0x02 ,0x81 ,0x40 ,0x20 ,0x10 ,0x08 ,0x04 ,0x02 , +0x81 ,0x40 ,0x20 ,0x10 ,0x08 ,0x04 ,0x02 ,0x81 , +0x40 ,0x20 ,0x10 ,0x08 ,0x04 ,0x02 ,0x81 ,0x40 , +0x20 ,0x10 ,0x08 ,0x04 ,0x02 ,0x81 ,0x40 ,0x20 , +0x10 ,0x08 ,0x04 ,0x02 ,0x81 ,0x40 ,0x20 ,0x10 , +0x08 ,0x04 ,0x02 ,0x81 ,0x40 ,0x20 ,0x10 ,0x08 , +0x04 ,0x02 ,0x81 ,0x40 ,0x20 ,0x10 ,0x08 ,0x04 , +0x02 ,0x81 ,0x40 ,0x20 ,0x10 ,0x08 ,0x04 ,0x02 , + }, + }}, + }, +}; + +static const unsigned char cbs_pp_data_download_17[] = { +0xd2 ,0x5e ,0x82 ,0x02 ,0x83 ,0x81 ,0x8c ,0x58 , +0xc0 ,0x11 ,0x10 ,0x01 ,0x96 ,0x11 ,0x02 ,0x70 , +0x00 ,0x00 ,0x4d ,0x00 ,0x0d ,0x00 ,0x00 ,0x00 , +0x00 ,0xbf ,0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x01 ,0x00 ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc , +0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc , +0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc , +0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc , +0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc , +0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc , +0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc , +0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc , +}; + +static const struct envelope_test cbs_pp_data_download_data_17 = { + .pdu = cbs_pp_data_download_17, + .pdu_len =sizeof (cbs_pp_data_download_17), + .envelope = { + .type =STK_ENVELOPE_TYPE_CBS_PP_DOWNLOAD , + .src =STK_DEVICE_IDENTITY_TYPE_NETWORK , + .dst =STK_DEVICE_IDENTITY_TYPE_UICC , + { .cbs_pp_download = { + .page = { +0xc0 ,0x11 ,0x10 ,0x01 ,0x96 ,0x11 ,0x02 ,0x70 , +0x00 ,0x00 ,0x4d ,0x00 ,0x0d ,0x00 ,0x00 ,0x00 , +0x00 ,0xbf ,0xff ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x01 ,0x00 ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc , +0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc , +0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc , +0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc , +0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc , +0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc , +0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc , +0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc ,0xdc , + }, + }}, + }, +}; +int main (int argc,char **argv) {g_test_init (&argc, &argv,NULL );
@@ -19657,5 +19737,10 @@ int main(int argc, char **argv) &sms_pp_data_download_data_182, test_envelope_encoding); +g_test_add_data_func ("/teststk/CBS-PP data download 1.1" , + &cbs_pp_data_download_data_11, test_envelope_encoding); +g_test_add_data_func ("/teststk/CBS-PP data download 1.7" , + &cbs_pp_data_download_data_17, test_envelope_encoding); +return g_test_run (); }
Signature · 1 line
1.7.1.86.g0e460.dirty
PATCH 6/11 stkutil: Add the Menu Selection envelope builder
In reply to Andrzej Zaborowski--- src/stkutil.c | 22 ++++++++++++++++++++++ src/stkutil.h | 6 ++++++ 2 files changed, 28 insertions(+), 0 deletions(-)
src/stkutil.c +22 -0
@@ -3528,6 +3528,20 @@ static gboolean build_dataobj_imei(struct stk_tlv_builder *tlv,stk_tlv_builder_close_container (tlv); } +/* Described in TS 102.223 Section 8.21 */ +static gboolean build_dataobj_help_request (struct stk_tlv_builder *tlv, +const void *data,gboolean cr) +{ +const gboolean *help = data; +unsigned char tag =STK_DATA_OBJECT_TYPE_HELP_REQUEST ; + +if (*help != TRUE) +return TRUE; + +return stk_tlv_builder_open_container (tlv, cr, tag, FALSE) && +stk_tlv_builder_close_container (tlv); +} +/* Described in TS 102.223 Section 8.22 */ static gboolean build_dataobj_network_measurement_results( struct stk_tlv_builder *tlv,
@@ -4200,6 +4214,14 @@ ofono_bool_t stk_pdu_from_envelope(const struct stk_envelope *envelope, envelope->cbs_pp_download.page, NULL);break ; +case STK_ENVELOPE_TYPE_MENU_SELECTION : + ok =build_dataobj (&builder, + build_dataobj_item_id,DATAOBJ_FLAG_CR , + &envelope->menu_selection.item_id, + build_dataobj_help_request,0 , + &envelope->menu_selection.help_request, +NULL ); +break ;default :return FALSE; };
src/stkutil.h +6 -0
@@ -1182,6 +1182,11 @@ struct stk_envelope_cbs_pp_download {unsigned char page[88 ]; }; +struct stk_envelope_menu_selection { +unsigned char item_id; +gboolean help_request; +}; +struct stk_envelope {enum stk_envelope_type type;enum stk_device_identity_type src;
@@ -1189,6 +1194,7 @@ struct stk_envelope {union {struct stk_envelope_sms_pp_download sms_pp_download;struct stk_envelope_cbs_pp_download cbs_pp_download; +struct stk_envelope_menu_selection menu_selection; }; };
Signature · 1 line
1.7.1.86.g0e460.dirty
PATCH 7/11 test-stkutil: Tests for the Menu Selection envelope builder
In reply to Andrzej Zaborowski--- unit/test-stkutil.c | 162 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 162 insertions(+), 0 deletions(-)
unit/test-stkutil.c +162 -0
@@ -18066,6 +18066,151 @@ static const struct envelope_test cbs_pp_data_download_data_17 = { }, }; +static const unsigned char menu_selection_111[] = { +0xd3 ,0x07 ,0x82 ,0x02 ,0x01 ,0x81 ,0x90 ,0x01 , +0x02 , +}; + +static const struct envelope_test menu_selection_data_111 = { + .pdu = menu_selection_111, + .pdu_len =sizeof (menu_selection_111), + .envelope = { + .type =STK_ENVELOPE_TYPE_MENU_SELECTION , + .src =STK_DEVICE_IDENTITY_TYPE_KEYPAD , + .dst =STK_DEVICE_IDENTITY_TYPE_UICC , + { .menu_selection = { + .item_id =0x2 , + }}, + }, +}; + +static const unsigned char menu_selection_112[] = { +0xd3 ,0x07 ,0x82 ,0x02 ,0x01 ,0x81 ,0x90 ,0x01 , +0x12 , +}; + +static const struct envelope_test menu_selection_data_112 = { + .pdu = menu_selection_112, + .pdu_len =sizeof (menu_selection_112), + .envelope = { + .type =STK_ENVELOPE_TYPE_MENU_SELECTION , + .src =STK_DEVICE_IDENTITY_TYPE_KEYPAD , + .dst =STK_DEVICE_IDENTITY_TYPE_UICC , + { .menu_selection = { + .item_id =0x12 , + }}, + }, +}; + +static const unsigned char menu_selection_121[] = { +0xd3 ,0x07 ,0x82 ,0x02 ,0x01 ,0x81 ,0x90 ,0x01 , +0x3d , +}; + +static const struct envelope_test menu_selection_data_121 = { + .pdu = menu_selection_121, + .pdu_len =sizeof (menu_selection_121), + .envelope = { + .type =STK_ENVELOPE_TYPE_MENU_SELECTION , + .src =STK_DEVICE_IDENTITY_TYPE_KEYPAD , + .dst =STK_DEVICE_IDENTITY_TYPE_UICC , + { .menu_selection = { + .item_id =0x3d , + }}, + }, +}; + +static const unsigned char menu_selection_122[] = { +0xd3 ,0x07 ,0x82 ,0x02 ,0x01 ,0x81 ,0x90 ,0x01 , +0xfb , +}; + +static const struct envelope_test menu_selection_data_122 = { + .pdu = menu_selection_122, + .pdu_len =sizeof (menu_selection_122), + .envelope = { + .type =STK_ENVELOPE_TYPE_MENU_SELECTION , + .src =STK_DEVICE_IDENTITY_TYPE_KEYPAD , + .dst =STK_DEVICE_IDENTITY_TYPE_UICC , + { .menu_selection = { + .item_id =0xfb , + }}, + }, +}; + +static const unsigned char menu_selection_123[] = { +0xd3 ,0x07 ,0x82 ,0x02 ,0x01 ,0x81 ,0x90 ,0x01 , +0x01 , +}; + +static const struct envelope_test menu_selection_data_123 = { + .pdu = menu_selection_123, + .pdu_len =sizeof (menu_selection_123), + .envelope = { + .type =STK_ENVELOPE_TYPE_MENU_SELECTION , + .src =STK_DEVICE_IDENTITY_TYPE_KEYPAD , + .dst =STK_DEVICE_IDENTITY_TYPE_UICC , + { .menu_selection = { + .item_id =0x1 , + }}, + }, +}; + +static const unsigned char menu_selection_211[] = { +0xd3 ,0x09 ,0x82 ,0x02 ,0x01 ,0x81 ,0x90 ,0x01 , +0x02 ,0x15 ,0x00 , +}; + +static const struct envelope_test menu_selection_data_211 = { + .pdu = menu_selection_211, + .pdu_len =sizeof (menu_selection_211), + .envelope = { + .type =STK_ENVELOPE_TYPE_MENU_SELECTION , + .src =STK_DEVICE_IDENTITY_TYPE_KEYPAD , + .dst =STK_DEVICE_IDENTITY_TYPE_UICC , + { .menu_selection = { + .item_id =0x2 , + .help_request = TRUE, + }}, + }, +}; + +static const unsigned char menu_selection_612[] = { +0xd3 ,0x07 ,0x82 ,0x02 ,0x01 ,0x81 ,0x90 ,0x01 , +0x05 , +}; + +static const struct envelope_test menu_selection_data_612 = { + .pdu = menu_selection_612, + .pdu_len =sizeof (menu_selection_612), + .envelope = { + .type =STK_ENVELOPE_TYPE_MENU_SELECTION , + .src =STK_DEVICE_IDENTITY_TYPE_KEYPAD , + .dst =STK_DEVICE_IDENTITY_TYPE_UICC , + { .menu_selection = { + .item_id =0x5 , + }}, + }, +}; + +static const unsigned char menu_selection_641[] = { +0xd3 ,0x07 ,0x82 ,0x02 ,0x01 ,0x81 ,0x90 ,0x01 , +0x08 , +}; + +static const struct envelope_test menu_selection_data_641 = { + .pdu = menu_selection_641, + .pdu_len =sizeof (menu_selection_641), + .envelope = { + .type =STK_ENVELOPE_TYPE_MENU_SELECTION , + .src =STK_DEVICE_IDENTITY_TYPE_KEYPAD , + .dst =STK_DEVICE_IDENTITY_TYPE_UICC , + { .menu_selection = { + .item_id =0x8 , + }}, + }, +}; +int main (int argc,char **argv) {g_test_init (&argc, &argv,NULL );
@@ -19742,5 +19887,22 @@ int main(int argc, char **argv)g_test_add_data_func ("/teststk/CBS-PP data download 1.7" , &cbs_pp_data_download_data_17, test_envelope_encoding); +g_test_add_data_func ("/teststk/Menu Selection 1.1.1" , + &menu_selection_data_111, test_envelope_encoding); +g_test_add_data_func ("/teststk/Menu Selection 1.1.2" , + &menu_selection_data_112, test_envelope_encoding); +g_test_add_data_func ("/teststk/Menu Selection 1.2.1" , + &menu_selection_data_121, test_envelope_encoding); +g_test_add_data_func ("/teststk/Menu Selection 1.2.2" , + &menu_selection_data_122, test_envelope_encoding); +g_test_add_data_func ("/teststk/Menu Selection 1.2.3" , + &menu_selection_data_123, test_envelope_encoding); +g_test_add_data_func ("/teststk/Menu Selection 2.1.1" , + &menu_selection_data_211, test_envelope_encoding); +g_test_add_data_func ("/teststk/Menu Selection 6.1.2" , + &menu_selection_data_612, test_envelope_encoding); +g_test_add_data_func ("/teststk/Menu Selection 6.4.1" , + &menu_selection_data_641, test_envelope_encoding); +return g_test_run (); }
Signature · 1 line
1.7.1.86.g0e460.dirty
PATCH 8/11 Add a buffer size parameter to convert_utf8_to_gsm
In reply to Andrzej ZaborowskiThis is needed when encoding a string into gsm that needs to fit a in a given number of bytes. Just taking the first N bytes of the resulting string may leave you with byte 1 of a two-byte character at the end of the buffer. As far as I can tell there's no easier way to avoid that.
--- src/util.c | 6 +++++- src/util.h | 1 + unit/test-util.c | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-)
src/util.c +5 -1
@@ -645,6 +645,7 @@ char *convert_gsm_to_utf8(const unsigned char *text, long len,unsigned char *convert_utf8_to_gsm_with_lang (const char *text,long len,long *items_read,long *items_written,unsigned char terminator, +long max_size,enum gsm_dialect locking_lang,enum gsm_dialect single_lang) {
@@ -688,6 +689,9 @@ unsigned char *convert_utf8_to_gsm_with_lang(const char *text, long len,else res_len +=1 ; +if (max_size !=-1 && res_len > max_size) +break ; + in =g_utf8_next_char (in); nchars +=1 ; }
@@ -739,7 +743,7 @@ unsigned char *convert_utf8_to_gsm(const char *text, long len, {return convert_utf8_to_gsm_with_lang (text, len, items_read, items_written, - terminator, + terminator,-1 ,GSM_DIALECT_DEFAULT ,GSM_DIALECT_DEFAULT ); }
src/util.h +1 -0
@@ -40,6 +40,7 @@ unsigned char *convert_utf8_to_gsm(const char *text, long len, long *items_read,unsigned char *convert_utf8_to_gsm_with_lang (const char *text,long len,long *items_read,long *items_written,unsigned char terminator, +long max_size,enum gsm_dialect locking_shift_lang,enum gsm_dialect single_shift_lang);
unit/test-util.c +2 -1
@@ -468,7 +468,8 @@ static void test_valid_turkish()g_assert (nwritten ==UTF8_LENGTH (verify[0 ])); - back =convert_utf8_to_gsm_with_lang (res,-1 , &nread, &nwritten,0 ,1 ,1 ); + back =convert_utf8_to_gsm_with_lang (res,-1 , &nread, + &nwritten,0 ,-1 ,1 ,1 );g_assert (back);
Signature · 1 line
1.7.1.86.g0e460.dirty
Re: [PATCH 08/11] Add a buffer size parameter to convert_utf8_to_gsm
Hi Andrew,
Quoted 5 lines
This is needed when encoding a string into gsm that needs to fit a in a given number of bytes. Just taking the first N bytes of the resulting string may leave you with byte 1 of a two-byte character at the end of the buffer. As far as I can tell there's no easier way to avoid that.
In gsm it is actually pretty easy, the escape character for two-byte sequence is always 0x1b, so chopping a string up could be done quite easily.
src/util.h unsigned char *convert_utf8_to_gsm(const char *text, long len, long *items_read, · line 45
Quoted 5 lines
unsigned char *convert_utf8_to_gsm_with_lang(const char *text, long len, long
*items_read, long*items_written, unsigned char terminator,src/util.h +1
-0+long max_size, enum gsm_dialect locking_shift_lang, enum gsm_dialect single_shift_lang);
If there's still need for this, I'd prefer we reuse long *items_written as an in/out argument for the max size or add another function entirely, adding yet another int argument is getting a bit ridiculous.
Regards,
-Denis
PATCH 9/11 Add a "sim string" encoding utility.
In reply to Andrzej ZaborowskiUse it in sim_adn_build to support UCS2 encoded strings if GSM7 is not possible, and to avoid storing half of a double byte character at the end of the alpha identifier field.
--- src/simutil.c | 25 ++++++++++--------------- src/util.c | 43 +++++++++++++++++++++++++++++++++++++++++++ src/util.h | 3 +++ 3 files changed, 56 insertions(+), 15 deletions(-)
src/simutil.c +10 -15
@@ -1232,29 +1232,24 @@ void sim_adn_build(unsigned char *data, int length, const char *identifier) {int number_len =strlen (ph->number); -unsigned char *gsm_identifier =NULL ; -long gsm_bytes; -long alpha_length; +unsigned char *alpha =NULL ; +int alpha_written =0 ; +int alpha_length; alpha_length = length -14 ;/* Alpha-Identifier field */ if (alpha_length >0 ) { -memset (data,0xff , alpha_length); -if (identifier) - gsm_identifier =convert_utf8_to_gsm (identifier, --1 ,NULL , &gsm_bytes,0 ); - -if (gsm_identifier) { -memcpy (data, gsm_identifier, -MIN (gsm_bytes, alpha_length)); -g_free (gsm_identifier); + alpha =utf8_to_sim_string (identifier, alpha_length, + &alpha_written); +if (alpha) { +memcpy (data, alpha, alpha_written); +g_free (alpha); } -/* TODO: figure out when the identifier needs to -* be encoded in UCS2 and do this. -*/ +memset (data + alpha_written,0xff , + alpha_length - alpha_written); data += alpha_length; }
src/util.c +43 -0
46 lines not on this page · raw message
src/util.h +3 -0
@@ -78,3 +78,6 @@ unsigned char *pack_7bit(const unsigned char *in, long len, int byte_offset, long *items_written, unsigned char terminator);char *sim_string_to_utf8 (const unsigned char *buffer,int length); + +unsigned char *utf8_to_sim_string (const char *utf, +int max_length,int *out_length);
Signature · 1 line
1.7.1.86.g0e460.dirty
PATCH 10/11 stkutil: Add the Call Control envelope builder
In reply to Andrzej Zaborowski--- src/stkutil.c | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/stkutil.h | 31 ++++++++++ 2 files changed, 204 insertions(+), 2 deletions(-)
src/stkutil.c +173 -2
@@ -321,8 +321,6 @@ static gboolean parse_dataobj_subaddress(struct comprehension_tlv_iter *iter,unsigned int len; len =comprehension_tlv_iter_get_length (iter); -if (len <1 ) -return FALSE;if (len >sizeof (subaddr->subaddr))return FALSE;
@@ -331,6 +329,8 @@ static gboolean parse_dataobj_subaddress(struct comprehension_tlv_iter *iter, subaddr->len = len;memcpy (subaddr->subaddr, data, len); + subaddr->has_subaddr = TRUE; +return TRUE; }
@@ -3331,6 +3331,9 @@ static gboolean build_dataobj_address(struct stk_tlv_builder *tlv,unsigned int len = (strlen (addr->number) +1 ) /2 ;unsigned char number[len]; +if (addr->number ==NULL ) +return TRUE; +sim_encode_bcd_number (addr->number, number); return stk_tlv_builder_open_container(tlv, cr, tag, FALSE) &&
@@ -3339,6 +3342,61 @@ static gboolean build_dataobj_address(struct stk_tlv_builder *tlv,stk_tlv_builder_close_container (tlv); } +/* Described in TS 102.223 Section 8.2 */ +static gboolean build_dataobj_alpha_id (struct stk_tlv_builder *tlv, +const void *data,gboolean cr) +{ +unsigned char tag =STK_DATA_OBJECT_TYPE_ALPHA_ID ; +int len; +unsigned char *string; + +if (data ==NULL ) +return TRUE; + +if (strlen (data) ==0 ) +return stk_tlv_builder_open_container (tlv, cr, tag, FALSE) && +stk_tlv_builder_close_container (tlv); + + string =utf8_to_sim_string (data,-1 , &len); +if (string ==NULL ) +return FALSE; + +return stk_tlv_builder_open_container (tlv, cr, tag, TRUE) && +stk_tlv_builder_append_bytes (tlv, string, len) && +stk_tlv_builder_close_container (tlv); +} + +/* Described in TS 102.223 Section 8.3 */ +static gboolean build_dataobj_subaddress (struct stk_tlv_builder *tlv, +const void *data,gboolean cr) +{ +const struct stk_subaddress *sa = data; +unsigned char tag =STK_DATA_OBJECT_TYPE_SUBADDRESS ; + +if (sa->has_subaddr != TRUE) +return FALSE; + +return stk_tlv_builder_open_container (tlv, cr, tag, FALSE) && +stk_tlv_builder_append_bytes (tlv, sa->subaddr, sa->len) && +stk_tlv_builder_close_container (tlv); +} + +/* Described in TS 131.111 Section 8.4 */ +static gboolean build_dataobj_ccp (struct stk_tlv_builder *tlv, +const void *data,gboolean cr) +{ +const struct stk_ccp *ccp = data; +unsigned char tag =STK_DATA_OBJECT_TYPE_CCP ; + +if (ccp->len ==0 ) +return TRUE; + +return stk_tlv_builder_open_container (tlv, cr, tag, FALSE) && +stk_tlv_builder_append_byte (tlv, ccp->len) && +stk_tlv_builder_append_bytes (tlv, ccp->ccp, ccp->len) && +stk_tlv_builder_close_container (tlv); +} +/* Described in TS 131.111 Section 8.5 */ static gboolean build_dataobj_cbs_page (struct stk_tlv_builder *tlv,const void *data,gboolean cr)
@@ -3414,6 +3472,26 @@ static gboolean build_dataobj_gsm_sms_tpdu(struct stk_tlv_builder *tlv,stk_tlv_builder_close_container (tlv); } +/* Described in TS 131.111 Section 8.14 */ +static gboolean build_dataobj_ss_string (struct stk_tlv_builder *tlv, +const void *data,gboolean cr) +{ +const struct stk_address *addr = data; +unsigned char tag =STK_DATA_OBJECT_TYPE_SS_STRING ; +unsigned int len = (strlen (addr->number) +1 ) /2 ; +unsigned char number[len]; + +if (addr->number ==NULL ) +return TRUE; + +sim_encode_bcd_number (addr->number, number); + +return stk_tlv_builder_open_container (tlv, cr, tag, FALSE) && +stk_tlv_builder_append_byte (tlv, addr->ton_npi) && +stk_tlv_builder_append_bytes (tlv, number, len) && +stk_tlv_builder_close_container (tlv); +} +/* Defined in TS 102.223 Section 8.15 */ static gboolean build_dataobj_text (struct stk_tlv_builder *tlv,const void *data,gboolean cr)
@@ -3451,6 +3529,22 @@ static gboolean build_dataobj_text(struct stk_tlv_builder *tlv,return stk_tlv_builder_close_container (tlv); } +/* Described in TS 131.111 Section 8.17 */ +static gboolean build_dataobj_ussd_string (struct stk_tlv_builder *tlv, +const void *data,gboolean cr) +{ +const struct stk_ussd_string *ussd = data; +unsigned char tag =STK_DATA_OBJECT_TYPE_USSD_STRING ; + +if (ussd->string ==NULL ) +return TRUE; + +return stk_tlv_builder_open_container (tlv, cr, tag, FALSE) && +stk_tlv_builder_append_byte (tlv, ussd->dcs) && +stk_tlv_builder_append_bytes (tlv, ussd->string, ussd->len) && +stk_tlv_builder_close_container (tlv); +} +/* Described in TS 102.223 Section 8.19 */ static gboolean build_dataobj_location_info (struct stk_tlv_builder *tlv,const void *data,gboolean cr)
@@ -3698,6 +3792,19 @@ static gboolean build_dataobj_at_response(struct stk_tlv_builder *tlv,stk_tlv_builder_close_container (tlv); } +/* Described in TS 131.111 Section 8.42 */ +static gboolean build_dataobj_bc_repeat (struct stk_tlv_builder *tlv, +const void *data,gboolean cr) +{ +unsigned char tag =STK_DATA_OBJECT_TYPE_BC_REPEAT_INDICATOR ; +const struct stk_bc_repeat *bcr = data; + +return bcr->has_bc_repeat != TRUE || + (stk_tlv_builder_open_container (tlv, cr, tag, TRUE) && +stk_tlv_builder_append_byte (tlv, bcr->value) && +stk_tlv_builder_close_container (tlv)); +} +/* Described in TS 102.223 Section 8.45 */ static gboolean build_dataobj_language (struct stk_tlv_builder *tlv,const void *data,gboolean cr)
@@ -3773,6 +3880,23 @@ static gboolean build_dataobj_esn(struct stk_tlv_builder *tlv,stk_tlv_builder_close_container (tlv); } +/* Described in TS 131.111 Section 8.72, 3GPP 24.008 Section 9.5.7 */ +static gboolean build_dataobj_pdp_context_params (struct stk_tlv_builder *tlv, +const void *data,gboolean cr) +{ +const struct stk_common_byte_array *params = data; +unsigned char tag =STK_DATA_OBJECT_TYPE_PDP_ACTIVATION_PARAMETER ; + +if (params->len <1 ) +return TRUE; +if (params->len >0x7f ) +return FALSE; + +return stk_tlv_builder_open_container (tlv, cr, tag, FALSE) && +stk_tlv_builder_append_bytes (tlv, params->array, params->len) && +stk_tlv_builder_close_container (tlv); +} +/* Described in TS 102.223 Section 8.74 * * See format note in parse_dataobj_imeisv.
@@ -3861,6 +3985,23 @@ static gboolean build_dataobj_broadcast_network_information(stk_tlv_builder_close_container (tlv); } +/* Described in TS 131.111 Section 8.98, 3GPP 24.301 Section 6.5.1 */ +static gboolean build_dataobj_eps_pdn_conn_params (struct stk_tlv_builder *tlv, +const void *data,gboolean cr) +{ +const struct stk_common_byte_array *params = data; +unsigned char tag =STK_DATA_OBJECT_TYPE_EPS_PDN_CONN_ACTIVATION_REQ ; + +if (params->len <1 ) +return TRUE; +if (params->len >0x7f ) +return FALSE; + +return stk_tlv_builder_open_container (tlv, cr, tag, FALSE) && +stk_tlv_builder_append_bytes (tlv, params->array, params->len) && +stk_tlv_builder_close_container (tlv); +} +static gboolean build_dataobj (struct stk_tlv_builder *tlv,dataobj_writer builder_func, ...) {
@@ -4222,6 +4363,36 @@ ofono_bool_t stk_pdu_from_envelope(const struct stk_envelope *envelope, &envelope->menu_selection.help_request, NULL);break ; +case STK_ENVELOPE_TYPE_CALL_CONTROL : + ok =build_dataobj (&builder, + build_dataobj_address,DATAOBJ_FLAG_CR , + &envelope->call_control.address, + build_dataobj_ss_string, +DATAOBJ_FLAG_CR , + &envelope->call_control.ss_string, + build_dataobj_ussd_string, +DATAOBJ_FLAG_CR , + &envelope->call_control.ussd_string, + build_dataobj_pdp_context_params, +DATAOBJ_FLAG_CR , + &envelope->call_control.pdp_ctx_params, + build_dataobj_eps_pdn_conn_params, +DATAOBJ_FLAG_CR , + &envelope->call_control.eps_pdn_params, + build_dataobj_ccp,0 , + &envelope->call_control.ccp1, + build_dataobj_subaddress,0 , + &envelope->call_control.subaddress, + build_dataobj_location_info,0 , + &envelope->call_control.location, + build_dataobj_ccp,0 , + &envelope->call_control.ccp2, + build_dataobj_alpha_id,0 , + envelope->call_control.alpha_id, + build_dataobj_bc_repeat,0 , + &envelope->call_control.bc_repeat, +NULL ); +break ;default :return FALSE; };
src/stkutil.h +31 -0
@@ -178,6 +178,7 @@ enum stk_data_object_type {STK_DATA_OBJECT_TYPE_PLMN_LIST =0x79 ,STK_DATA_OBJECT_TYPE_BROADCAST_NETWORK_INFO =0x7A ,STK_DATA_OBJECT_TYPE_ACTIVATE_DESCRIPTOR =0x7B , + STK_DATA_OBJECT_TYPE_EPS_PDN_CONN_ACTIVATION_REQ = 0x7C, }; enum stk_device_identity_type {
@@ -474,6 +475,7 @@ struct stk_address {* bytes." */ struct stk_subaddress { +gboolean has_subaddr;unsigned char len;unsigned char subaddr[23 ]; };
@@ -1187,6 +1189,34 @@ struct stk_envelope_menu_selection {gboolean help_request; }; +/* Used both in the ENVELOPE message to UICC and response from UICC */ +struct stk_envelope_call_control { +/* Exactly one of the following 5 fields must be present */ +struct stk_address address; +struct stk_address ss_string; +struct stk_ussd_string { +unsigned char dcs; +const unsigned char *string; +int len; + } ussd_string; +struct stk_common_byte_array pdp_ctx_params; +struct stk_common_byte_array eps_pdn_params; +/* At least one of the following two fields must be present in a +* response indicating modification of the call. +* In an EVELOPE message, only allowed for a call setup. */ +struct stk_ccp ccp1; +struct stk_subaddress subaddress; +struct stk_location_info location; +/* Only allowed when ccp1 is present */ +struct stk_ccp ccp2; +char *alpha_id; +/* Only allowed when both ccp1 and ccp2 are present */ +struct stk_bc_repeat { +gboolean has_bc_repeat; +unsigned char value; + } bc_repeat; +}; +struct stk_envelope {enum stk_envelope_type type;enum stk_device_identity_type src;
@@ -1195,6 +1225,7 @@ struct stk_envelope {struct stk_envelope_sms_pp_download sms_pp_download;struct stk_envelope_cbs_pp_download cbs_pp_download;struct stk_envelope_menu_selection menu_selection; +struct stk_envelope_call_control call_control; }; };
Signature · 1 line
1.7.1.86.g0e460.dirty
Re: [PATCH 10/11] stkutil: Add the Call Control envelope builder
Quoted 4 lines · Andrzej Zaborowski
---
src/stkutil.c | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-src/stkutil.h| 31 ++++++++++2 files changed, 204 insertions(+), 2 deletions(-)
Please ignore this patch and the following one, I will resend with some corrections later.
Thanks,
Andrew
PATCH 11/11 test-stkutil: Tests for Call Control envelope builder
In reply to Andrzej Zaborowski--- unit/test-stkutil.c | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 137 insertions(+), 0 deletions(-)
unit/test-stkutil.c +137 -0
@@ -18211,6 +18211,143 @@ static const struct envelope_test menu_selection_data_641 = { }, }; +static const unsigned char call_control_111a[] = { +0xd4 ,0x21 ,0x82 ,0x02 ,0x82 ,0x81 ,0x86 ,0x0b , +0x91 ,0x10 ,0x32 ,0x54 ,0x76 ,0x98 ,0x10 ,0x32 , +0x54 ,0x76 ,0x98 ,0x07 ,0x07 ,0x06 ,0x60 ,0x04 , +0x02 ,0x00 ,0x05 ,0x81 ,0x13 ,0x07 ,0x00 ,0xf1 , +0x10 ,0x00 ,0x01 ,0x00 ,0x01 ,0x00 ,0x01 , +}; + +static const struct envelope_test call_control_data_111a = { + .pdu = call_control_111a, + .pdu_len =sizeof (call_control_111a), + .envelope = { + .type =STK_ENVELOPE_TYPE_CALL_CONTROL , + .src =STK_DEVICE_IDENTITY_TYPE_TERMINAL , + .dst =STK_DEVICE_IDENTITY_TYPE_UICC , + { .call_control = { + .address = { + .ton_npi =0x91 ,/* Intl, ISDN */ + .number ="01234567890123456789" , + }, + .ccp1 = { + .ccp = { +0x60 ,0x04 ,0x02 ,0x00 ,0x05 ,0x81 , + }, + .len =6 , + }, + .location = { + .mcc ="00" , + .mnc ="011" , + .lac_tac =0x0001 , + .has_ci = TRUE, + .ci =0x0001 , + .has_ext_ci = TRUE, + .ext_ci =0x0001 , + }, + }}, + }, +}; + +static const unsigned char call_control_111b[] = { +0xd4 ,0x23 ,0x82 ,0x02 ,0x82 ,0x81 ,0x86 ,0x0b , +0x91 ,0x10 ,0x32 ,0x54 ,0x76 ,0x98 ,0x10 ,0x32 , +0x54 ,0x76 ,0x98 ,0x07 ,0x07 ,0x06 ,0x60 ,0x04 , +0x02 ,0x00 ,0x05 ,0x81 ,0x13 ,0x07 ,0x00 ,0x11 , +0x10 ,0x00 ,0x01 ,0x00 ,0x01 , +}; + +static const struct envelope_test call_control_data_111b = { + .pdu = call_control_111b, + .pdu_len =sizeof (call_control_111b), + .envelope = { + .type =STK_ENVELOPE_TYPE_CALL_CONTROL , + .src =STK_DEVICE_IDENTITY_TYPE_TERMINAL , + .dst =STK_DEVICE_IDENTITY_TYPE_UICC , + { .call_control = { + .address = { + .ton_npi =0x91 ,/* Intl, ISDN */ + .number ="01234567890123456789" , + }, + .ccp1 = { + .ccp = { +0x60 ,0x04 ,0x02 ,0x00 ,0x05 ,0x81 , + }, + .len =6 , + }, + .location = { + .mcc ="001" , + .mnc ="011" , + .lac_tac =0x0001 , + .has_ci = TRUE, + .ci =0x0001 , + }, + }}, + }, +}; + +static const unsigned char call_control_131a[] = { +0xd4 ,0x18 ,0x02 ,0x02 ,0x82 ,0x81 ,0x06 ,0x07 , +0x91 ,0x10 ,0x32 ,0x04 ,0x21 ,0x43 ,0x65 ,0x13 , +0x09 ,0x00 ,0xf1 ,0x10 ,0x00 ,0x01 ,0x00 ,0x01 , +0x00 ,0x01 , +}; + +static const struct envelope_test call_control_data_131a = { + .pdu = call_control_131a, + .pdu_len =sizeof (call_control_131a), + .envelope = { + .type =STK_ENVELOPE_TYPE_CALL_CONTROL , + .src =STK_DEVICE_IDENTITY_TYPE_TERMINAL , + .dst =STK_DEVICE_IDENTITY_TYPE_UICC , + { .call_control = { + .address = { + .ton_npi =0x91 ,/* Intl, ISDN */ + .number ="012340123456" , + }, + .location = { + .mcc ="00" , + .mnc ="011" , + .lac_tac =0x0001 , + .has_ci = TRUE, + .ci =0x0001 , + .has_ext_ci = TRUE, + .ext_ci =0x0001 , + }, + }}, + }, +}; + +static const unsigned char call_control_131b[] = { +0xd4 ,0x16 ,0x02 ,0x02 ,0x82 ,0x81 ,0x06 ,0x07 , +0x91 ,0x10 ,0x32 ,0x04 ,0x21 ,0x43 ,0x65 ,0x13 , +0x07 ,0x00 ,0x11 ,0x10 ,0x00 ,0x01 ,0x00 ,0x01 , +}; + +static const struct envelope_test call_control_data_131b = { + .pdu = call_control_131b, + .pdu_len =sizeof (call_control_131b), + .envelope = { + .type =STK_ENVELOPE_TYPE_CALL_CONTROL , + .src =STK_DEVICE_IDENTITY_TYPE_TERMINAL , + .dst =STK_DEVICE_IDENTITY_TYPE_UICC , + { .call_control = { + .address = { + .ton_npi =0x91 ,/* Intl, ISDN */ + .number ="012340123456" , + }, + .location = { + .mcc ="001" , + .mnc ="011" , + .lac_tac =0x0001 , + .has_ci = TRUE, + .ci =0x0001 , + }, + }}, + }, +}; +int main (int argc,char **argv) {g_test_init (&argc, &argv,NULL );
Signature · 1 line
1.7.1.86.g0e460.dirty
Hi Andrew,
Quoted 3 lines
Note that the
sms_tpdumember could be of type structsms_deliver, but the users may more often have access to the raw tpdu so there's no point decoding and reencoding it.
Overall patch looks fine, but using a raw pdu is not preferable. Couple of reasons:
- When SMS is delivered, it is delivered in tpdu form, e.g. sc_address + deliver pdu. To obtain the sc_address, we need to decode the deliver tpdu anyway.
- Before we know this is an SMS-PP download, we must check the dcs / pid. In order to check those, we must again decode the tpdu.
- SMS sc_address can actually be non-numeric. In that case the SMS-PP download should simply be dropped.
- Consistency with Send SMS proactive command.
src/stkutil.h void stk_command_free(struct stk_command *command); · line 1202
Quoted 7 lines
src/stkutil.h +6
-0+ +/* Returns TRUE on success */ +ofono_bool_t stk_pdu_from_envelope (const struct stk_envelope *envelope, +unsigned char *pdu,unsigned int size, +unsigned char **out_pdu, +unsigned int *out_size);
This part just looks ugly. Can't we hide the details of char buf[512] somewhere inside stk_pdu_from_envelope? Or perhaps make **out_pdu and *out_size in/out arguments instead of just out.
Regards,
-Denis
Hi Denis,
Quoted 9 lines · Denis Kenzior
Hi Andrew,
Quoted 3 lines
Note that the
sms_tpdumember could be of type structsms_deliver, but the users may more often have access to the raw tpdu so there's no point decoding and reencoding it.Overall patch looks fine, but using a raw pdu is not preferable. Couple of reasons:
Quoted 7 lines
- When SMS is delivered, it is delivered in tpdu form, e.g.
sc_address+ deliver pdu. To obtain thesc_address, we need to decode the deliver tpdu anyway.
- Before we know this is an SMS-PP download, we must check the dcs / pid. In order to check those, we must again decode the tpdu.
- SMSsc_addresscan actually be non-numeric. In that case the SMS-PP download should simply be dropped.
This means we have to decode the PDU, but re-encoding it is still an overhead having access to the TPDU.
Quoted 1 line
- Consistency with Send SMS proactive command.
Ok, makes sense.
Quoted 11 lines
src/stkutil.h void stk_command_free(struct stk_command *command); · line 1202
Quoted 8 lines
src/stkutil.h +6
-0+ +/* Returns TRUE on success */ +ofono_bool_t stk_pdu_from_envelope (const struct stk_envelope *envelope, + unsigned char *pdu, unsigned int size, + unsigned char **out_pdu, + unsigned int *out_size);This part just looks ugly. Can't we hide the details of char buf[512] somewhere inside
stk_pdu_from_envelope?
By that do you mean using a static buffer? I'll send a patch for that. I prefer a static buffer for the PDUs but thought you had argued against it :)
Regards
Hi Andrew,
Quoted 10 lines
Quoted 7 lines
- When SMS is delivered, it is delivered in tpdu form, e.g.
sc_address+ deliver pdu. To obtain thesc_address, we need to decode the deliver tpdu anyway.
- Before we know this is an SMS-PP download, we must check the dcs / pid. In order to check those, we must again decode the tpdu.
- SMSsc_addresscan actually be non-numeric. In that case the SMS-PP download should simply be dropped.This means we have to decode the PDU, but re-encoding it is still an overhead having access to the TPDU.
Fair enough, I don't really feel strongly either way. However, encoding is quite fast and we have to re-encode the sc_address in a different format anyway because of the weird sc_addr encoding rules.
Quoted 4 lines
Quoted 2 lines
- Consistency with Send SMS proactive command.
Ok, makes sense.
One thing that comes to mind is that we might have to modify sms_encode() with the capability to skip encoding the sc_address field. Otherwise our pdu will have some extra crap in the beginning.
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines
src/stkutil.h +4
-0+ +/* Returns TRUE on success */ +ofono_bool_t stk_pdu_from_envelope (const struct stk_envelope *envelope, + unsigned char *pdu, unsigned intsize, + unsigned char **out_pdu,
+ unsigned int*out_size);This part just looks ugly. Can't we hide the details of char buf[512] somewhere inside
stk_pdu_from_envelope?
Quoted 3 lines
By that do you mean using a static buffer? I'll send a patch for that. I prefer a static buffer for the PDUs but thought you had argued against it :)
Don't recall :) I think in this case it is ok, or you can always make the function re-entrant safe by making the buf argument in/out.
e.g.
char buf[512];
char *out = buf;
func(foo, bar, &out);
Regards,
-Denis
Quoted 8 lines · Denis Kenzior
Quoted 8 lines
Quoted 7 lines
- When SMS is delivered, it is delivered in tpdu form, e.g.
sc_address+ deliver pdu. To obtain thesc_address, we need to decode the deliver tpdu anyway.
- Before we know this is an SMS-PP download, we must check the dcs / pid. In order to check those, we must again decode the tpdu.
- SMSsc_addresscan actually be non-numeric. In that case the SMS-PP download should simply be dropped.
Quoted 6 lines
Quoted 2 lines
This means we have to decode the PDU, but re-encoding it is still an overhead having access to the TPDU.
Fair enough, I don't really feel strongly either way. However, encoding is quite fast and we have to re-encode the
sc_addressin a different format anyway because of the weirdsc_addrencoding rules.
I'll send a new patch using struct sms_deliver (this way api enforces the correct type of pdu is supplied).
Quoted 28 lines
Quoted 5 lines
Quoted 3 lines
- Consistency with Send SMS proactive command.
Ok, makes sense.
One thing that comes to mind is that we might have to modify
sms_encode()with the capability to skip encoding thesc_addressfield. Otherwise our pdu will have some extra crap in the beginning.Quoted 11 lines
Quoted 10 lines
Quoted 7 lines
src/stkutil.h +4
-0+ +/* Returns TRUE on success */ +ofono_bool_t stk_pdu_from_envelope (const struct stk_envelope *envelope, + unsigned char *pdu, unsigned intsize, + unsigned char **out_pdu,
+ unsigned int*out_size);This part just looks ugly. Can't we hide the details of char buf[512] somewhere inside
stk_pdu_from_envelope?Quoted 3 lines
By that do you mean using a static buffer? I'll send a patch for that. I prefer a static buffer for the PDUs but thought you had argued against it :)
Don't recall :) I think in this case it is ok, or you can always make the function re-entrant safe by making the buf argument in/out.
Quoted 6 lines
e.g.
char buf[512];
char *out = buf;
func(foo, bar, &out);
The nice thing about static buffer is the users don't have to worry about how many bytes to reserve. It would also allow dropping 90% of the length checks which are then only defensive coding.
Regards,
Andrew