mirror of git://git.sysmocom.de/ofono
stkutil: Use static buf in stk_pdu_from_response
This commit is contained in:
parent
1d8bb1bab6
commit
ef408ae1a6
|
@ -3980,14 +3980,15 @@ static gboolean build_local_info(struct stk_tlv_builder *builder,
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int stk_pdu_from_response(const struct stk_response *response,
|
const unsigned char *stk_pdu_from_response(const struct stk_response *response,
|
||||||
unsigned char *pdu, unsigned int size)
|
unsigned int *out_length)
|
||||||
{
|
{
|
||||||
struct stk_tlv_builder builder;
|
struct stk_tlv_builder builder;
|
||||||
gboolean ok = TRUE;
|
gboolean ok = TRUE;
|
||||||
unsigned char tag;
|
unsigned char tag;
|
||||||
|
static unsigned char pdu[512];
|
||||||
|
|
||||||
stk_tlv_builder_init(&builder, pdu, size);
|
stk_tlv_builder_init(&builder, pdu, sizeof(pdu));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Encode command details, they come in order with
|
* Encode command details, they come in order with
|
||||||
|
@ -3996,19 +3997,19 @@ unsigned int stk_pdu_from_response(const struct stk_response *response,
|
||||||
*/
|
*/
|
||||||
tag = STK_DATA_OBJECT_TYPE_COMMAND_DETAILS;
|
tag = STK_DATA_OBJECT_TYPE_COMMAND_DETAILS;
|
||||||
if (stk_tlv_builder_open_container(&builder, TRUE, tag, FALSE) == FALSE)
|
if (stk_tlv_builder_open_container(&builder, TRUE, tag, FALSE) == FALSE)
|
||||||
return 0;
|
return NULL;
|
||||||
|
|
||||||
if (stk_tlv_builder_append_byte(&builder, response->number) == FALSE)
|
if (stk_tlv_builder_append_byte(&builder, response->number) == FALSE)
|
||||||
return 0;
|
return NULL;
|
||||||
|
|
||||||
if (stk_tlv_builder_append_byte(&builder, response->type) == FALSE)
|
if (stk_tlv_builder_append_byte(&builder, response->type) == FALSE)
|
||||||
return 0;
|
return NULL;
|
||||||
|
|
||||||
if (stk_tlv_builder_append_byte(&builder, response->qualifier) == FALSE)
|
if (stk_tlv_builder_append_byte(&builder, response->qualifier) == FALSE)
|
||||||
return 0;
|
return NULL;
|
||||||
|
|
||||||
if (stk_tlv_builder_close_container(&builder) == FALSE)
|
if (stk_tlv_builder_close_container(&builder) == FALSE)
|
||||||
return 0;
|
return NULL;
|
||||||
|
|
||||||
/* TS 102 223 section 6.8 states:
|
/* TS 102 223 section 6.8 states:
|
||||||
* "For all COMPREHENSION-TLV objects with Min = N, the terminal
|
* "For all COMPREHENSION-TLV objects with Min = N, the terminal
|
||||||
|
@ -4022,19 +4023,19 @@ unsigned int stk_pdu_from_response(const struct stk_response *response,
|
||||||
*/
|
*/
|
||||||
tag = STK_DATA_OBJECT_TYPE_DEVICE_IDENTITIES;
|
tag = STK_DATA_OBJECT_TYPE_DEVICE_IDENTITIES;
|
||||||
if (stk_tlv_builder_open_container(&builder, TRUE, tag, FALSE) == FALSE)
|
if (stk_tlv_builder_open_container(&builder, TRUE, tag, FALSE) == FALSE)
|
||||||
return 0;
|
return NULL;
|
||||||
|
|
||||||
if (stk_tlv_builder_append_byte(&builder, response->src) == FALSE)
|
if (stk_tlv_builder_append_byte(&builder, response->src) == FALSE)
|
||||||
return 0;
|
return NULL;
|
||||||
|
|
||||||
if (stk_tlv_builder_append_byte(&builder, response->dst) == FALSE)
|
if (stk_tlv_builder_append_byte(&builder, response->dst) == FALSE)
|
||||||
return 0;
|
return NULL;
|
||||||
|
|
||||||
if (stk_tlv_builder_close_container(&builder) == FALSE)
|
if (stk_tlv_builder_close_container(&builder) == FALSE)
|
||||||
return 0;
|
return NULL;
|
||||||
|
|
||||||
if (build_dataobj_result(&builder, &response->result, TRUE) != TRUE)
|
if (build_dataobj_result(&builder, &response->result, TRUE) != TRUE)
|
||||||
return 0;
|
return NULL;
|
||||||
|
|
||||||
switch (response->type) {
|
switch (response->type) {
|
||||||
case STK_COMMAND_TYPE_DISPLAY_TEXT:
|
case STK_COMMAND_TYPE_DISPLAY_TEXT:
|
||||||
|
@ -4105,11 +4106,14 @@ unsigned int stk_pdu_from_response(const struct stk_response *response,
|
||||||
case STK_COMMAND_TYPE_LAUNCH_BROWSER:
|
case STK_COMMAND_TYPE_LAUNCH_BROWSER:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return 0;
|
return NULL;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (ok != TRUE)
|
if (ok != TRUE)
|
||||||
return 0;
|
return NULL;
|
||||||
|
|
||||||
return stk_tlv_builder_get_length(&builder);
|
if (out_length)
|
||||||
|
*out_length = stk_tlv_builder_get_length(&builder);
|
||||||
|
|
||||||
|
return pdu;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1176,6 +1176,5 @@ struct stk_command *stk_command_new_from_pdu(const unsigned char *pdu,
|
||||||
unsigned int len);
|
unsigned int len);
|
||||||
void stk_command_free(struct stk_command *command);
|
void stk_command_free(struct stk_command *command);
|
||||||
|
|
||||||
/* Returns # of bytes written or zero on error */
|
const unsigned char *stk_pdu_from_response(const struct stk_response *response,
|
||||||
unsigned int stk_pdu_from_response(const struct stk_response *response,
|
unsigned int *out_length);
|
||||||
unsigned char *pdu, unsigned int size);
|
|
||||||
|
|
|
@ -13949,13 +13949,18 @@ struct terminal_response_test {
|
||||||
static void test_terminal_response_encoding(gconstpointer data)
|
static void test_terminal_response_encoding(gconstpointer data)
|
||||||
{
|
{
|
||||||
const struct terminal_response_test *test = data;
|
const struct terminal_response_test *test = data;
|
||||||
unsigned char buf[512];
|
const unsigned char *pdu;
|
||||||
unsigned int len;
|
unsigned int pdu_len;
|
||||||
|
|
||||||
len = stk_pdu_from_response(&test->response, buf, sizeof(buf));
|
pdu = stk_pdu_from_response(&test->response, &pdu_len);
|
||||||
|
|
||||||
g_assert(len == test->pdu_len);
|
if (test->pdu)
|
||||||
g_assert(memcmp(buf, test->pdu, len) == 0);
|
g_assert(pdu);
|
||||||
|
else
|
||||||
|
g_assert(pdu == NULL);
|
||||||
|
|
||||||
|
g_assert(pdu_len == test->pdu_len);
|
||||||
|
g_assert(memcmp(pdu, test->pdu, pdu_len) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const unsigned char display_text_response_111[] = {
|
static const unsigned char display_text_response_111[] = {
|
||||||
|
|
Loading…
Reference in New Issue