TLV library updated

This commit is contained in:
Sukchan Lee 2017-03-11 14:31:49 +09:00
parent ff3ebab8ba
commit b998837e17
3 changed files with 293 additions and 392 deletions

View File

@ -9,21 +9,9 @@ extern "C" {
#endif /* __cplusplus */
/* UTIS project specific parameters */
#define UPDU_IE_TYPE_1_CODE 0x01
#define UPDU_IE_TYPE_2_CODE 0x02
#define UPDU_IE_TYPE_3_CODE 0x00
#define UPDU_IE_TYPE_1_MAX_SIZE 0x40
#define UPDU_IE_TYPE_2_MAX_SIZE 0x4000
#define UPDU_IE_TYPE_3_MAX_SIZE 0x40000000
#define TLV_MODE_UTIS 2
#define TLV_MODE_WIFI 3
#define TLV_MODE_WMX_R4_R6 4
#define TLV_MODE_WMX_R1 5
#define TLV_MODE_T8_L8 1
#define TLV_MODE_T8_L16 2
#define TLV_MODE_T16_L16 3
#define NUM_OF_TLV_NODE 100
@ -56,12 +44,6 @@ typedef struct _tlv_t
#define tlv_length(pTlv) pTlv->length
#define tlv_value(pTlv) pTlv->value
#define tlv_wmx_r4_r6_type(pTlv) (pTlv->type & 0x7FFF)
#define tlv_wmx_r4_r6_tc(pTlv) (pTlv->type & 0x8000)
#define tlv_wmx_r4_r6_set_tc(pTlv) (pTlv->type | 0x8000)
#define tlv_wmx_r4_r6_clr_tc(pTlv) (pTlv->type & 0x7FFF)
/* tlv_t pool related functions */
CORE_DECLARE(tlv_t*) tlv_get(void);
CORE_DECLARE(void) tlv_free(tlv_t *pTlv);
@ -84,13 +66,11 @@ CORE_DECLARE(tlv_t*) tlv_embed(
CORE_DECLARE(c_uint32_t) tlv_render(
tlv_t *rootTlv, c_uint8_t *blk, c_uint32_t length, c_uint8_t mode);
/* tlv_t parsing functions */
CORE_DECLARE(tlv_t*) tlv_parse_tlv_block(c_uint32_t length,
c_uint8_t *blk, c_uint8_t mode);
CORE_DECLARE(tlv_t*) tlv_parse_embedded_tlv_block(tlv_t* pTlv, c_uint8_t mode);
/* tlv operation-related function */
CORE_DECLARE(tlv_t*) tlv_find(tlv_t* pTlv, c_uint32_t type);
CORE_DECLARE(tlv_t*) tlv_find_root(tlv_t* pTlv);

View File

@ -100,15 +100,19 @@ c_uint32_t tlv_calc_length(tlv_t *p_tlv, c_uint8_t mode)
while(tmp_tlv)
{
/* this is length for type field */
if(mode == TLV_MODE_WMX_R4_R6)
switch(mode)
{
length += 2;
case TLV_MODE_T8_L8:
case TLV_MODE_T8_L16:
length += 1;
break;
case TLV_MODE_T16_L16:
length += 2;
break;
default:
d_assert(0, return 0, "Invalid mode(%d)", mode);
break;
}
else
{
length += 1;
}
/* this is length for type field */
if(tmp_tlv->embedded != NULL)
@ -116,28 +120,19 @@ c_uint32_t tlv_calc_length(tlv_t *p_tlv, c_uint8_t mode)
tmp_tlv->length = tlv_calc_length(tmp_tlv->embedded, mode);
}
if(mode == TLV_MODE_WMX_R4_R6)
switch(mode)
{
length += 2;
}
else if(mode == TLV_MODE_UTIS)
{
if(tmp_tlv->length < UPDU_IE_TYPE_1_MAX_SIZE)
case TLV_MODE_T8_L8:
length += 1;
else if(tmp_tlv->length < UPDU_IE_TYPE_2_MAX_SIZE)
break;
case TLV_MODE_T8_L16:
case TLV_MODE_T16_L16:
length += 2;
else if(tmp_tlv->length < UPDU_IE_TYPE_3_MAX_SIZE)
length += 4;
else
{
/* Error : Invalid IE length field */
}
break;
default:
d_assert(0, return 0, "Invalid mode(%d)", mode);
break;
}
else
{
length += 1;
}
/* this is length for value field */
length += tmp_tlv->length;
@ -167,98 +162,7 @@ c_uint32_t tlv_calc_count(tlv_t *p_tlv)
return count;
}
c_uint32_t _tlv_get_length_utis(c_uint8_t **pos)
{
c_uint8_t *blk = *pos;
c_uint32_t length = 0;
switch(*blk >> 6)
{
case UPDU_IE_TYPE_1_CODE:
length = *blk & 0x3F;
*pos += 1;
break;
case UPDU_IE_TYPE_2_CODE:
length = ((*blk & 0x3F) << 8) + *(blk + 1);
*pos += 2;
break;
case UPDU_IE_TYPE_3_CODE:
length = ((*blk & 0x3F) << 24) +
(*(blk + 1) << 16) + (*(blk + 2) << 8) + *(blk + 3);
*pos += 4;
break;
default:
/* Error : Invalid IE length field */
return CORE_ERROR;
break;
}
return length;
}
c_uint8_t* _tlv_put_length_utis(c_uint32_t length, c_uint8_t *pos)
{
if(length < UPDU_IE_TYPE_1_MAX_SIZE)
{
*(pos++) = (UPDU_IE_TYPE_1_CODE << 6) | length;
}
else if(length < UPDU_IE_TYPE_2_MAX_SIZE)
{
*(pos++) = (UPDU_IE_TYPE_2_CODE << 6) | (length >> 8);
*(pos++) = length & 0xFF;
}
else if(length < UPDU_IE_TYPE_3_MAX_SIZE)
{
*(pos++) = (length >> 24) & 0xFF;
*(pos++) = (length >> 16) & 0xFF;
*(pos++) = (length >> 8) & 0xFF;
*(pos++) = length & 0xFF;
}
else
{
d_assert(FALSE, return NULL, "invalid tlv length\n");
}
return pos;
}
c_uint32_t _tlv_get_length_wifi(c_uint8_t **pos)
{
c_uint8_t *blk = *pos;
c_uint32_t length = 0;
if(*blk & 0x80)
{
d_error("TLV for wifi is not implemented in case of (length > 127)");
}
else
{
length = *blk;
*pos += 1;
}
return length;
}
c_uint8_t* _tlv_put_length_wifi(c_uint32_t length, c_uint8_t *pos)
{
if(length < 128)
{
*(pos++) = length;
}
else
{
d_error("TLV for wifi is not implemented in case of (length > 127)");
}
return pos;
}
c_uint32_t _tlv_get_length_wmx_r4_r6(c_uint8_t **pos)
c_uint32_t _tlv_get_length16(c_uint8_t **pos)
{
c_uint8_t *blk = *pos;
c_uint32_t length = 0;
@ -269,7 +173,7 @@ c_uint32_t _tlv_get_length_wmx_r4_r6(c_uint8_t **pos)
return length;
}
c_uint8_t* _tlv_put_length_wmx_r4_r6(c_uint32_t length, c_uint8_t *pos)
c_uint8_t* _tlv_put_length16(c_uint32_t length, c_uint8_t *pos)
{
*(pos++) = (length >> 8) & 0xFF;
*(pos++) = length & 0xFF;
@ -277,188 +181,91 @@ c_uint8_t* _tlv_put_length_wmx_r4_r6(c_uint32_t length, c_uint8_t *pos)
return pos;
}
/* Not Implemented for WMX_R1*/
c_uint32_t _tlv_get_length_wmx_r1(c_uint8_t **pos)
c_uint32_t _tlv_get_length8(c_uint8_t **pos)
{
c_uint8_t *blk = *pos;
c_uint32_t length = 0;
if(*blk & 0x80)
{
d_error("TLV is not implemented in case of (length > 127)");
}
else
{
length = *blk;
*pos += 1;
}
length = *blk;
*pos += 1;
return length;
}
c_uint8_t* _tlv_put_length_wmx_r1(c_uint32_t length, c_uint8_t *pos)
c_uint8_t* _tlv_put_length8(c_uint32_t length, c_uint8_t *pos)
{
if(length < 128)
{
*(pos++) = length;
}
else
{
d_error("TLV is not implemented in case of (length > 127)");
}
*(pos++) = length;
return pos;
}
c_uint32_t _tlv_get_length_common(c_uint8_t **pos)
{
c_uint8_t *blk = *pos;
c_uint32_t length = 0;
if(*blk & 0x80)
{
d_error("TLV is not implemented in case of (length > 127)");
}
else
{
length = *blk;
*pos += 1;
}
return length;
}
c_uint8_t* _tlv_put_length_common(c_uint32_t length, c_uint8_t *pos)
{
if(length < 128)
{
*(pos++) = length;
}
else
{
d_error("TLV is not implemented in case of (length > 127)");
}
return pos;
}
c_uint8_t* _tlv_put_length(c_uint32_t length, c_uint8_t *pos, c_uint8_t mode)
{
if(mode == TLV_MODE_UTIS)
switch(mode)
{
pos = _tlv_put_length_utis(length, pos);
}
else if(mode == TLV_MODE_WIFI)
{
pos = _tlv_put_length_wifi(length, pos);
}
else if(mode == TLV_MODE_WMX_R4_R6)
{
pos = _tlv_put_length_wmx_r4_r6(length, pos);
}
else if(mode == TLV_MODE_WMX_R1)
{
pos = _tlv_put_length_wmx_r1(length, pos);
}
else
{
pos = _tlv_put_length_common(length, pos);
case TLV_MODE_T8_L8:
pos = _tlv_put_length8(length, pos);
break;
case TLV_MODE_T8_L16:
case TLV_MODE_T16_L16:
pos = _tlv_put_length16(length, pos);
break;
default:
d_assert(0, return 0, "Invalid mode(%d)", mode);
break;
}
return pos;
}
c_uint8_t* _tlv_get_element(tlv_t *p_tlv, c_uint8_t *tlvBlock, c_uint8_t mode)
{
c_uint8_t *pos = tlvBlock;
if(mode == TLV_MODE_WMX_R4_R6)
switch(mode)
{
p_tlv->type = *(pos++) << 8;
p_tlv->type += *(pos++);
}
else
{
p_tlv->type = *(pos++);
}
if(mode == TLV_MODE_UTIS)
{
p_tlv->length = _tlv_get_length_utis(&pos);
}
else if(mode == TLV_MODE_WIFI)
{
p_tlv->length = _tlv_get_length_wifi(&pos);
}
else if(mode == TLV_MODE_WMX_R4_R6)
{
p_tlv->length = _tlv_get_length_wmx_r4_r6(&pos);
}
else if(mode == TLV_MODE_WMX_R1)
{
p_tlv->length = _tlv_get_length_wmx_r1(&pos);
}
else
{
p_tlv->length = _tlv_get_length_common(&pos);
case TLV_MODE_T8_L8:
p_tlv->type = *(pos++);
p_tlv->length = _tlv_get_length8(&pos);
break;
case TLV_MODE_T8_L16:
p_tlv->type = *(pos++);
p_tlv->length = _tlv_get_length16(&pos);
break;
case TLV_MODE_T16_L16:
p_tlv->type = *(pos++) << 8;
p_tlv->type += *(pos++);
p_tlv->length = _tlv_get_length16(&pos);
break;
default:
d_assert(0, return 0, "Invalid mode(%d)", mode);
break;
}
p_tlv->value = pos;
return (pos + tlv_length(p_tlv));
}
c_uint8_t* _tlv_put_type(c_uint32_t type, c_uint8_t *pos, c_uint8_t mode)
{
if(mode == TLV_MODE_WMX_R4_R6)
switch(mode)
{
*(pos++) = (type >> 8) & 0xFF;
*(pos++) = type & 0xFF;
}
else
{
*(pos++) = type & 0xFF;
case TLV_MODE_T8_L8:
case TLV_MODE_T8_L16:
*(pos++) = type & 0xFF;
break;
case TLV_MODE_T16_L16:
*(pos++) = (type >> 8) & 0xFF;
*(pos++) = type & 0xFF;
break;
default:
d_assert(0, return 0, "Invalid mode(%d)", mode);
break;
}
return pos;
}
c_uint8_t* _tlv_get_type(tlv_t *p_tlv, c_uint8_t *tlvBlock, c_uint8_t mode)
{
c_uint8_t *pos = tlvBlock;
p_tlv->type = *(pos++);
if(mode == TLV_MODE_UTIS)
{
p_tlv->length = _tlv_get_length_utis(&pos);
}
else if(mode == TLV_MODE_WIFI)
{
p_tlv->length = _tlv_get_length_wifi(&pos);
}
else if(mode == TLV_MODE_WMX_R4_R6)
{
p_tlv->length = _tlv_get_length_wmx_r4_r6(&pos);
}
else if(mode == TLV_MODE_WMX_R1)
{
p_tlv->length = _tlv_get_length_wmx_r1(&pos);
}
else
{
p_tlv->length = _tlv_get_length_common(&pos);
}
p_tlv->value = pos;
return (pos + tlv_length(p_tlv));
}
/* tlv_t encoding functions */
c_uint8_t *tlv_write_to_buff(
c_uint8_t *blk, c_uint32_t type, c_uint32_t length,
c_uint8_t *value, c_uint8_t mode)
@ -497,7 +304,6 @@ tlv_t * tlv_find_root(tlv_t* p_tlv)
return head_tlv;
}
tlv_t * tlv_add(
tlv_t *head_tlv, c_uint32_t type, c_uint32_t length, c_uint8_t *value)
{
@ -564,8 +370,6 @@ tlv_t * tlv_create_buff_enabled_tlv(
return new_tlv;
}
tlv_t * tlv_embed(
tlv_t *parent_tlv, c_uint32_t type, c_uint32_t length, c_uint8_t *value)
{
@ -607,7 +411,6 @@ tlv_t * tlv_embed(
return new_tlv;
}
c_uint32_t tlv_render(
tlv_t *root_tlv, c_uint8_t *blk, c_uint32_t length, c_uint8_t mode)
{
@ -650,9 +453,7 @@ c_uint32_t tlv_render(
return (pos - blk);
}
/* tlv_t parsing functions */
tlv_t * tlv_parse_tlv_block(c_uint32_t length, c_uint8_t *blk, c_uint8_t mode)
{
c_uint8_t* pos = blk;
@ -699,10 +500,7 @@ tlv_t * tlv_parse_embedded_tlv_block(tlv_t* p_tlv, c_uint8_t mode)
return p_tlv->embedded;
}
/* tlv operation-related function */
tlv_t * tlv_find(tlv_t* p_tlv, c_uint32_t type)
{
tlv_t *tmp_tlv = p_tlv, *embed_tlv = NULL;

View File

@ -24,7 +24,7 @@ c_uint8_t test_tlv_value[TLV_VALUE_ARRAY_SIZE];
test_tlv_eliment tlv_eliment[] ={
{1, TLV_0_LEN, 0, 0x0a},
{100, TLV_1_LEN, 0, 0x0b},
{50, TLV_1_LEN, 0, 0x0b},
{255, TLV_2_LEN, 0, 0x0c},
{254, TLV_3_LEN, 0, 0x0d},
{5, TLV_4_LEN, 0, 0x0e},
@ -59,7 +59,7 @@ void tlv_test_set_tlv_value(void)
return;
}
void tlv_test_check_embed_tlv_test(abts_case *tc, tlv_t *root_tlv)
void tlv_test_check_embed_tlv_test(abts_case *tc, tlv_t *root_tlv, int mode)
{
c_uint32_t m;
c_uint32_t parent_block_len;
@ -72,69 +72,102 @@ void tlv_test_check_embed_tlv_test(abts_case *tc, tlv_t *root_tlv)
memset(parent_block, 0x00, sizeof(parent_block));
parent_block_len = tlv_render(root_tlv, parent_block,
sizeof(parent_block), TLV_MODE_WMX_R4_R6);
ABTS_INT_EQUAL(tc, parent_block_len, 332);
sizeof(parent_block), mode);
tlv_free_all(root_tlv);
ABTS_INT_EQUAL(tc, tlv_pool_avail(), NUM_OF_TLV_NODE);
pos = parent_block;
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[0].type >> 8);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[0].type & 0xFF);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[0].length >> 8);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[0].length & 0xFF);
for(m = 0; m < tlv_eliment[0].length; m++)
switch(mode)
{
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[0].val_char);
case TLV_MODE_T16_L16:
{
ABTS_INT_EQUAL(tc, 332, parent_block_len);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[0].type >> 8);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[0].type & 0xFF);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[0].length >> 8);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[0].length & 0xFF);
for(m = 0; m < tlv_eliment[0].length; m++)
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[0].val_char);
ABTS_INT_EQUAL(tc, *(pos++), EMBED_TLV_TYPE >> 8);
ABTS_INT_EQUAL(tc, *(pos++), EMBED_TLV_TYPE & 0xFF);
ABTS_INT_EQUAL(tc, *(pos++), (308 >> 8));
ABTS_INT_EQUAL(tc, *(pos++), 308 & 0xFF);
/* embedded tlv_t */
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[2].type >> 8);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[2].type & 0xFF);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[2].length >> 8);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[2].length & 0xFF);
for(m = 0; m < tlv_eliment[2].length; m++)
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[2].val_char);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[3].type >> 8);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[3].type & 0xFF);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[3].length >> 8);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[3].length & 0xFF);
for(m = 0; m < tlv_eliment[3].length; m++)
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[3].val_char);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[4].type >> 8);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[4].type & 0xFF);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[4].length >> 8);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[4].length & 0xFF);
for(m = 0; m < tlv_eliment[4].length; m++)
ABTS_INT_EQUAL(tc, *(pos++), 0x0e);
break;
}
case TLV_MODE_T8_L16:
{
ABTS_INT_EQUAL(tc, 327, parent_block_len);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[0].type & 0xFF);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[0].length >> 8);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[0].length & 0xFF);
for(m = 0; m < tlv_eliment[0].length; m++)
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[0].val_char);
ABTS_INT_EQUAL(tc, *(pos++), EMBED_TLV_TYPE & 0xFF);
ABTS_INT_EQUAL(tc, *(pos++), (306 >> 8));
ABTS_INT_EQUAL(tc, *(pos++), 306 & 0xFF);
/* embedded tlv_t */
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[2].type & 0xFF);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[2].length >> 8);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[2].length & 0xFF);
for(m = 0; m < tlv_eliment[2].length; m++)
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[2].val_char);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[3].type & 0xFF);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[3].length >> 8);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[3].length & 0xFF);
for(m = 0; m < tlv_eliment[3].length; m++)
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[3].val_char);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[4].type & 0xFF);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[4].length >> 8);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[4].length & 0xFF);
for(m = 0; m < tlv_eliment[4].length; m++)
ABTS_INT_EQUAL(tc, *(pos++), 0x0e);
break;
}
default:
{
ABTS_TRUE(tc, 0);
break;
}
}
ABTS_INT_EQUAL(tc, *(pos++), EMBED_TLV_TYPE >> 8);
ABTS_INT_EQUAL(tc, *(pos++), EMBED_TLV_TYPE & 0xFF);
ABTS_INT_EQUAL(tc, *(pos++), (308 >> 8));
ABTS_INT_EQUAL(tc, *(pos++), 308 & 0xFF);
/* embedded tlv_t */
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[2].type >> 8);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[2].type & 0xFF);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[2].length >> 8);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[2].length & 0xFF);
for(m = 0; m < tlv_eliment[2].length; m++)
{
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[2].val_char);
}
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[3].type >> 8);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[3].type & 0xFF);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[3].length >> 8);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[3].length & 0xFF);
for(m = 0; m < tlv_eliment[3].length; m++)
{
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[3].val_char);
}
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[4].type >> 8);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[4].type & 0xFF);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[4].length >> 8);
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[4].length & 0xFF);
for(m = 0; m < tlv_eliment[4].length; m++)
{
ABTS_INT_EQUAL(tc, *(pos++), 0x0e);
}
parsed_tlv = tlv_parse_tlv_block(parent_block_len,
parent_block, TLV_MODE_WMX_R4_R6);
parent_block, mode);
ABTS_PTR_NOTNULL(tc, parsed_tlv);
pTlv = parsed_tlv;
@ -146,7 +179,18 @@ void tlv_test_check_embed_tlv_test(abts_case *tc, tlv_t *root_tlv)
pTlv = pTlv->next;
ABTS_INT_EQUAL(tc, pTlv->type, 20);
ABTS_INT_EQUAL(tc, pTlv->length, 308);
switch(mode)
{
case TLV_MODE_T16_L16:
ABTS_INT_EQUAL(tc, pTlv->length, 308);
break;
case TLV_MODE_T8_L16:
ABTS_INT_EQUAL(tc, pTlv->length, 306);
break;
default:
ABTS_TRUE(tc, 0);
break;
}
pTlv = pTlv->next;
ABTS_INT_EQUAL(tc, pTlv->type, tlv_eliment[4].type);
@ -154,18 +198,16 @@ void tlv_test_check_embed_tlv_test(abts_case *tc, tlv_t *root_tlv)
result = memcmp(pTlv->value, tlv_eliment[4].value, tlv_eliment[4].length);
ABTS_INT_EQUAL(tc, result, 0);
pTlv = pTlv->next;
ABTS_PTR_NULL(tc, pTlv);
parent_tlv = tlv_find(parsed_tlv,20);
ABTS_PTR_NOTNULL(tc, parent_tlv);
tlv_parse_embedded_tlv_block(parent_tlv, TLV_MODE_WMX_R4_R6);
tlv_parse_embedded_tlv_block(parent_tlv, mode);
embed_tlv = parent_tlv->embedded;
ABTS_PTR_NOTNULL(tc, embed_tlv);
ABTS_INT_EQUAL(tc, embed_tlv->type, tlv_eliment[2].type);
ABTS_INT_EQUAL(tc, embed_tlv->length, tlv_eliment[2].length);
for(m = 0; m < tlv_eliment[2].length; m++)
@ -207,6 +249,7 @@ static void tlv_test_1(abts_case *tc, void *data)
tlv_t *root_tlv = NULL, *parsed_tlv = NULL, *pTlv;
c_uint8_t parent_block[4000];
c_uint8_t *pos = NULL;
int mode = (int)data;
tlv_test_set_tlv_value();
@ -222,9 +265,23 @@ static void tlv_test_1(abts_case *tc, void *data)
memset(parent_block, 0x00, sizeof(parent_block));
parent_block_len = tlv_render(root_tlv, parent_block,
sizeof(parent_block), TLV_MODE_WMX_R4_R6);
sizeof(parent_block), mode);
ABTS_INT_EQUAL(tc, parent_block_len, 346);
switch(mode)
{
case TLV_MODE_T16_L16:
ABTS_INT_EQUAL(tc, 346, parent_block_len);
break;
case TLV_MODE_T8_L16:
ABTS_INT_EQUAL(tc, 342, parent_block_len);
break;
case TLV_MODE_T8_L8:
ABTS_INT_EQUAL(tc, 338, parent_block_len);
break;
default:
ABTS_TRUE(tc, 0);
break;
}
tlv_free_all(root_tlv);
ABTS_INT_EQUAL(tc, tlv_pool_avail(), NUM_OF_TLV_NODE);
@ -233,23 +290,34 @@ static void tlv_test_1(abts_case *tc, void *data)
for(idx = 0; idx < 4; idx++)
{
ABTS_INT_EQUAL(tc, *(pos++), (tlv_eliment[idx].type >> 8));
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[idx].type & 0xFF);
ABTS_INT_EQUAL(tc, *(pos++), (tlv_eliment[idx].length >> 8));
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[idx].length & 0xFF);
switch(mode)
{
case TLV_MODE_T16_L16:
ABTS_INT_EQUAL(tc, (tlv_eliment[idx].type >> 8), *(pos++));
ABTS_INT_EQUAL(tc, tlv_eliment[idx].type & 0xFF, *(pos++));
ABTS_INT_EQUAL(tc, (tlv_eliment[idx].length >> 8), *(pos++));
ABTS_INT_EQUAL(tc, tlv_eliment[idx].length & 0xFF, *(pos++));
break;
case TLV_MODE_T8_L16:
ABTS_INT_EQUAL(tc, tlv_eliment[idx].type & 0xFF, *(pos++));
ABTS_INT_EQUAL(tc, (tlv_eliment[idx].length >> 8), *(pos++));
ABTS_INT_EQUAL(tc, tlv_eliment[idx].length & 0xFF, *(pos++));
break;
case TLV_MODE_T8_L8:
ABTS_INT_EQUAL(tc, tlv_eliment[idx].type & 0xFF, *(pos++));
ABTS_INT_EQUAL(tc, tlv_eliment[idx].length & 0xFF, *(pos++));
break;
default:
ABTS_TRUE(tc, 0);
break;
}
for(m = 0; m < tlv_eliment[idx].length; m++)
{
ABTS_INT_EQUAL(tc, *(pos++), tlv_eliment[idx].val_char);
}
ABTS_INT_EQUAL(tc, tlv_eliment[idx].val_char, *(pos++));
}
parsed_tlv = tlv_parse_tlv_block(parent_block_len,parent_block,
TLV_MODE_WMX_R4_R6);
parsed_tlv = tlv_parse_tlv_block(parent_block_len,parent_block, mode);
ABTS_PTR_NOTNULL(tc, parsed_tlv);
pTlv = parsed_tlv;
@ -282,7 +350,6 @@ static void tlv_test_1(abts_case *tc, void *data)
return;
}
/* embedded tlv_t test : first, make embedded tlv block for embeded tlv
and then make whole tlv block using embedded tlv block previously made*/
static void tlv_test_2(abts_case *tc, void *data)
@ -291,6 +358,7 @@ static void tlv_test_2(abts_case *tc, void *data)
tlv_t *root_tlv = NULL;
tlv_t *embed_tlv = NULL;
c_uint8_t embed_block[1000];;
int mode = (int)data;
tlv_test_set_tlv_value();
@ -301,8 +369,19 @@ static void tlv_test_2(abts_case *tc, void *data)
tlv_eliment[3].length, tlv_eliment[3].value);
embed_block_len = tlv_render(embed_tlv, embed_block,
sizeof(embed_block), TLV_MODE_WMX_R4_R6);
ABTS_INT_EQUAL(tc, embed_block_len, 308);
sizeof(embed_block), mode);
switch(mode)
{
case TLV_MODE_T16_L16:
ABTS_INT_EQUAL(tc, embed_block_len, 308);
break;
case TLV_MODE_T8_L16:
ABTS_INT_EQUAL(tc, embed_block_len, 306);
break;
default:
ABTS_TRUE(tc, 0);
break;
}
tlv_free_all(embed_tlv);
ABTS_INT_EQUAL(tc, tlv_pool_avail(), NUM_OF_TLV_NODE);
@ -314,7 +393,7 @@ static void tlv_test_2(abts_case *tc, void *data)
tlv_add(root_tlv,tlv_eliment[4].type,
tlv_eliment[4].length, tlv_eliment[4].value);
tlv_test_check_embed_tlv_test(tc, root_tlv);
tlv_test_check_embed_tlv_test(tc, root_tlv, mode);
return;
}
@ -326,6 +405,7 @@ static void tlv_test_2(abts_case *tc, void *data)
static void tlv_test_3(abts_case *tc, void *data)
{
tlv_t *root_tlv = NULL, *parent_tlv = NULL;
int mode = (int)data;
tlv_test_set_tlv_value();
@ -341,7 +421,7 @@ static void tlv_test_3(abts_case *tc, void *data)
tlv_embed(parent_tlv,tlv_eliment[3].type,
tlv_eliment[3].length, tlv_eliment[3].value);
tlv_test_check_embed_tlv_test(tc, root_tlv);
tlv_test_check_embed_tlv_test(tc, root_tlv, mode);
return;
}
@ -356,6 +436,7 @@ static void tlv_test_4(abts_case *tc, void *data)
{
tlv_t *root_tlv = NULL, *parent_tlv = NULL;
c_uint8_t tlv_buff[2000];
int mode = (int)data;
tlv_test_set_tlv_value();
@ -373,7 +454,7 @@ static void tlv_test_4(abts_case *tc, void *data)
memset(tlv_eliment[2].value, 0x00, tlv_eliment[2].length);
memset(tlv_eliment[3].value, 0xf0, tlv_eliment[3].length);
tlv_test_check_embed_tlv_test(tc, root_tlv);
tlv_test_check_embed_tlv_test(tc, root_tlv, mode);
return;
}
@ -387,6 +468,7 @@ static void tlv_test_5(abts_case *tc, void *data)
c_uint8_t *pos = NULL;
c_uint16_t c_16 = 0x1122;
c_uint32_t c_32 = 0x11223344;
int mode = (int)data;
/* tlv encoding for test */
c_16 = htons(c_16);
@ -396,30 +478,64 @@ static void tlv_test_5(abts_case *tc, void *data)
memset(parent_block, 0x00, sizeof(parent_block));
parent_block_len = tlv_render(root_tlv, parent_block,
sizeof(parent_block), TLV_MODE_WMX_R4_R6);
sizeof(parent_block), mode);
tlv_free_all(root_tlv);
ABTS_INT_EQUAL(tc, tlv_pool_avail(), NUM_OF_TLV_NODE);
pos = parent_block;
ABTS_INT_EQUAL(tc, *(pos++), 0);
ABTS_INT_EQUAL(tc, *(pos++), 10);
ABTS_INT_EQUAL(tc, *(pos++), 0);
ABTS_INT_EQUAL(tc, *(pos++), 2);
ABTS_INT_EQUAL(tc, *(pos++), 0x11);
ABTS_INT_EQUAL(tc, *(pos++), 0x22);
ABTS_INT_EQUAL(tc, *(pos++), 0);
ABTS_INT_EQUAL(tc, *(pos++), 20);
ABTS_INT_EQUAL(tc, *(pos++), 0);
ABTS_INT_EQUAL(tc, *(pos++), 4);
ABTS_INT_EQUAL(tc, *(pos++), 0x11);
ABTS_INT_EQUAL(tc, *(pos++), 0x22);
ABTS_INT_EQUAL(tc, *(pos++), 0x33);
ABTS_INT_EQUAL(tc, *(pos++), 0x44);
switch(mode)
{
case TLV_MODE_T16_L16:
ABTS_INT_EQUAL(tc, *(pos++), 0);
ABTS_INT_EQUAL(tc, *(pos++), 10);
ABTS_INT_EQUAL(tc, *(pos++), 0);
ABTS_INT_EQUAL(tc, *(pos++), 2);
ABTS_INT_EQUAL(tc, *(pos++), 0x11);
ABTS_INT_EQUAL(tc, *(pos++), 0x22);
ABTS_INT_EQUAL(tc, *(pos++), 0);
ABTS_INT_EQUAL(tc, *(pos++), 20);
ABTS_INT_EQUAL(tc, *(pos++), 0);
ABTS_INT_EQUAL(tc, *(pos++), 4);
ABTS_INT_EQUAL(tc, *(pos++), 0x11);
ABTS_INT_EQUAL(tc, *(pos++), 0x22);
ABTS_INT_EQUAL(tc, *(pos++), 0x33);
ABTS_INT_EQUAL(tc, *(pos++), 0x44);
break;
case TLV_MODE_T8_L16:
ABTS_INT_EQUAL(tc, *(pos++), 10);
ABTS_INT_EQUAL(tc, *(pos++), 0);
ABTS_INT_EQUAL(tc, *(pos++), 2);
ABTS_INT_EQUAL(tc, *(pos++), 0x11);
ABTS_INT_EQUAL(tc, *(pos++), 0x22);
ABTS_INT_EQUAL(tc, *(pos++), 20);
ABTS_INT_EQUAL(tc, *(pos++), 0);
ABTS_INT_EQUAL(tc, *(pos++), 4);
ABTS_INT_EQUAL(tc, *(pos++), 0x11);
ABTS_INT_EQUAL(tc, *(pos++), 0x22);
ABTS_INT_EQUAL(tc, *(pos++), 0x33);
ABTS_INT_EQUAL(tc, *(pos++), 0x44);
break;
case TLV_MODE_T8_L8:
ABTS_INT_EQUAL(tc, *(pos++), 10);
ABTS_INT_EQUAL(tc, *(pos++), 2);
ABTS_INT_EQUAL(tc, *(pos++), 0x11);
ABTS_INT_EQUAL(tc, *(pos++), 0x22);
ABTS_INT_EQUAL(tc, *(pos++), 20);
ABTS_INT_EQUAL(tc, *(pos++), 4);
ABTS_INT_EQUAL(tc, *(pos++), 0x11);
ABTS_INT_EQUAL(tc, *(pos++), 0x22);
ABTS_INT_EQUAL(tc, *(pos++), 0x33);
ABTS_INT_EQUAL(tc, *(pos++), 0x44);
break;
default:
ABTS_TRUE(tc, 0);
break;
}
p_tlv = parsed_tlv = tlv_parse_tlv_block(parent_block_len,parent_block,
TLV_MODE_WMX_R4_R6);
mode);
ABTS_INT_EQUAL(tc, tlv_value_16(p_tlv), 0x1122);
p_tlv = parsed_tlv->next;
ABTS_INT_EQUAL(tc, tlv_value_32(p_tlv), 0x11223344);
@ -435,11 +551,18 @@ abts_suite *testtlv(abts_suite *suite)
{
suite = ADD_SUITE(suite)
abts_run_test(suite, tlv_test_1, NULL);
abts_run_test(suite, tlv_test_2, NULL);
abts_run_test(suite, tlv_test_3, NULL);
abts_run_test(suite, tlv_test_4, NULL);
abts_run_test(suite, tlv_test_5, NULL);
abts_run_test(suite, tlv_test_1, (void*)TLV_MODE_T16_L16);
abts_run_test(suite, tlv_test_2, (void*)TLV_MODE_T16_L16);
abts_run_test(suite, tlv_test_3, (void*)TLV_MODE_T16_L16);
abts_run_test(suite, tlv_test_4, (void*)TLV_MODE_T16_L16);
abts_run_test(suite, tlv_test_5, (void*)TLV_MODE_T16_L16);
abts_run_test(suite, tlv_test_1, (void*)TLV_MODE_T8_L8);
abts_run_test(suite, tlv_test_5, (void*)TLV_MODE_T8_L8);
abts_run_test(suite, tlv_test_1, (void*)TLV_MODE_T8_L16);
abts_run_test(suite, tlv_test_2, (void*)TLV_MODE_T8_L16);
abts_run_test(suite, tlv_test_3, (void*)TLV_MODE_T8_L16);
abts_run_test(suite, tlv_test_4, (void*)TLV_MODE_T8_L16);
abts_run_test(suite, tlv_test_5, (void*)TLV_MODE_T8_L16);
return suite;
}