stkutil: Add Get Inkey response builder.
PATCH 6/27 stkutil: Add Get Inkey response builder.
--- src/stkutil.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/stkutil.h | 16 ++++++++++ 2 files changed, 103 insertions(+), 1 deletions(-)
src/stkutil.c +86 -1
@@ -36,7 +36,8 @@enum stk_data_object_flag {DATAOBJ_FLAG_MANDATORY =1 , -DATAOBJ_FLAG_MINIMUM =2 +DATAOBJ_FLAG_MINIMUM =2 , +DATAOBJ_FLAG_CR =4 };struct stk_file_iter {
@@ -3046,6 +3047,23 @@ static inline gboolean stk_tlv_append_bytes(struct stk_tlv_builder *iter,return TRUE; } +/* Described in TS 102.223 Section 8.8 */ +static gboolean build_dataobj_duration (struct stk_tlv_builder *tlv, +const void *data,gboolean cr) +{ +const struct stk_duration *duration = data; + +if (duration->interval ==0x00 ) +return TRUE; + +return stk_tlv_open_container (tlv, cr, +STK_DATA_OBJECT_TYPE_DURATION , FALSE) && +stk_tlv_append_byte (tlv, duration->unit) && +stk_tlv_append_byte (tlv, duration->interval) && +stk_tlv_close_container (tlv); +} + +/* Described in TS 102.223 Section 8.12 */ static gboolean build_dataobj_result (struct stk_tlv_builder *tlv,const void *data,gboolean cr) {
@@ -3060,6 +3078,65 @@ static gboolean build_dataobj_result(struct stk_tlv_builder *tlv,stk_tlv_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) +{ +const struct stk_answer_text *text = data; + +if (!text->text && !text->yesno) +return TRUE; + +if (stk_tlv_open_container (tlv, cr,STK_DATA_OBJECT_TYPE_TEXT , + TRUE) != TRUE) +return FALSE; + +if (text->yesno == TRUE) { +/* Section 6.8.5: +* When the terminal issues [...] command qualifier set +* to "Yes/No", it shall supply the value "01" when the +* answer is "positive" and the value '00' when the +* answer is "negative" in the text string data object. +*/ +if (stk_tlv_append_byte (tlv,0x04 ) != TRUE) +return FALSE; +if (stk_tlv_append_byte (tlv, text->text ?0x01 :0x00 ) != TRUE) +return FALSE; + }else if (text->packed) { +if (stk_tlv_append_text (tlv,0x00 , text->text) != TRUE) +return FALSE; + }else { +if (stk_tlv_append_text (tlv,-1 , text->text) != TRUE) +return FALSE; + } + +return stk_tlv_close_container (tlv); +} + +static gboolean build_dataobj (struct stk_tlv_builder *tlv,gboolean + (*builder_func)(struct stk_tlv_builder *, +const void *,gboolean ), ...) +{ +va_list args; + +va_start (args, builder_func); + +while (builder_func) { + unsigned int flags = va_arg(args, enum stk_data_object_flag); + const void *data = va_arg(args, const void *); +gboolean cr = (flags &DATAOBJ_FLAG_CR ) ? TRUE : FALSE; + +if (builder_func (tlv, data, cr) != TRUE) +return FALSE; + + builder_func = va_arg(args, gboolean (*)( + struct stk_tlv_builder *, + const void *, gboolean)); + } + +return TRUE; +} +unsigned int stk_pdu_from_response (const struct stk_response *response,unsigned char *pdu,unsigned int size) {
@@ -3106,6 +3184,14 @@ unsigned int stk_pdu_from_response(const struct stk_response *response,switch (response->type) {case STK_COMMAND_TYPE_DISPLAY_TEXT :break ; +case STK_COMMAND_TYPE_GET_INKEY : + ok =build_dataobj (&builder, + build_dataobj_text,DATAOBJ_FLAG_CR , + &response->get_inkey.text, + build_dataobj_duration,0 , + &response->get_inkey.duration, +NULL ); +break ;default :return 0 ; };
src/stkutil.h +16 -0
@@ -995,6 +995,21 @@ struct stk_command {struct stk_response_generic { }; +struct stk_answer_text { +char *text; +ofono_bool_t packed; +ofono_bool_t yesno; +/* If a "Yes/No" answer was requested in a GET INKEY command, +* .yesno must be TRUE and text should be non-NULL to indicate +* a Yes response or NULL to indicate a No response. +*/ +}; + +struct stk_response_get_inkey { +struct stk_answer_text text; +struct stk_duration duration; +}; +struct stk_response {unsigned char number;unsigned char type;
@@ -1005,6 +1020,7 @@ struct stk_response {union {struct stk_response_generic display_text; +struct stk_response_get_inkey get_inkey; };void (*destructor)(struct stk_response *response);
Signature · 1 line
1.7.1.86.g0e460.dirty