diff --git a/lib/core/include/core_tlv_msg.h b/lib/core/include/core_tlv_msg.h index 314e0aae5..821cd85b7 100644 --- a/lib/core/include/core_tlv_msg.h +++ b/lib/core/include/core_tlv_msg.h @@ -66,6 +66,7 @@ typedef struct _tlv_desc_t { tlv_type_e ctype; c_uint16_t type; c_uint16_t length; + c_uint8_t instance; c_uint16_t vsize; void *child_descs[]; } tlv_desc_t; diff --git a/lib/core/src/tlv_msg.c b/lib/core/src/tlv_msg.c index d891b2b73..1017eaf31 100644 --- a/lib/core/src/tlv_msg.c +++ b/lib/core/src/tlv_msg.c @@ -5,7 +5,7 @@ tlv_desc_t tlv_desc_more = { - TLV_MORE, 0, TLV_MORE, 0, { NULL } + TLV_MORE, 0, TLV_MAX_MORE, 0, 0, { NULL } }; static tlv_t* _tlv_add_leaf( @@ -21,9 +21,11 @@ static tlv_t* _tlv_add_leaf( d_trace(1, "V_1B:%02x", v->v); if (parent_tlv) - tlv = tlv_embed(parent_tlv, desc->type, 1, 0, (c_uint8_t*)&v->v); + tlv = tlv_embed(parent_tlv, + desc->type, 1, desc->instance, (c_uint8_t*)&v->v); else - tlv = tlv_add(tlv, desc->type, 1, 0, (c_uint8_t*)&v->v); + tlv = tlv_add(tlv, + desc->type, 1, desc->instance, (c_uint8_t*)&v->v); d_assert(tlv, return NULL, "Can't add TLV"); break; } @@ -36,9 +38,11 @@ static tlv_t* _tlv_add_leaf( v->v = htons(v->v); if (parent_tlv) - tlv = tlv_embed(parent_tlv, desc->type, 2, 0, (c_uint8_t*)&v->v); + tlv = tlv_embed(parent_tlv, + desc->type, 2, desc->instance, (c_uint8_t*)&v->v); else - tlv = tlv_add(tlv, desc->type, 2, 0, (c_uint8_t*)&v->v); + tlv = tlv_add(tlv, + desc->type, 2, desc->instance, (c_uint8_t*)&v->v); d_assert(tlv, return NULL, "Can't add TLV"); break; } @@ -53,9 +57,11 @@ static tlv_t* _tlv_add_leaf( v->v = htonl(v->v); if (parent_tlv) - tlv = tlv_embed(parent_tlv, desc->type, 3, 0, (c_uint8_t*)&v->v); + tlv = tlv_embed(parent_tlv, + desc->type, 3, desc->instance, (c_uint8_t*)&v->v); else - tlv = tlv_add(tlv, desc->type, 3, 0, (c_uint8_t*)&v->v); + tlv = tlv_add(tlv, + desc->type, 3, desc->instance, (c_uint8_t*)&v->v); d_assert(tlv, return NULL, "Can't add TLV"); break; } @@ -83,9 +89,11 @@ static tlv_t* _tlv_add_leaf( d_trace_hex(1, v->v, v->l); if (parent_tlv) - tlv = tlv_embed(parent_tlv, desc->type, desc->length, 0, v->v); + tlv = tlv_embed(parent_tlv, + desc->type, desc->length, desc->instance, v->v); else - tlv = tlv_add(tlv, desc->type, desc->length, 0, v->v); + tlv = tlv_add(tlv, + desc->type, desc->length, desc->instance, v->v); d_assert(tlv, return NULL, "Can't add TLV"); break; } @@ -99,9 +107,11 @@ static tlv_t* _tlv_add_leaf( d_trace_hex(1, v->v, v->l); if (parent_tlv) - tlv = tlv_embed(parent_tlv, desc->type, v->l, 0, v->v); + tlv = tlv_embed(parent_tlv, + desc->type, v->l, desc->instance, v->v); else - tlv = tlv_add(tlv, desc->type, v->l, 0, v->v); + tlv = tlv_add(tlv, + desc->type, v->l, desc->instance, v->v); d_assert(tlv, return NULL, "Can't add TLV"); break; } @@ -110,9 +120,11 @@ static tlv_t* _tlv_add_leaf( d_trace(1, "V_NULL" ); if (parent_tlv) - tlv = tlv_embed(parent_tlv, desc->type, 0, 0, NULL); + tlv = tlv_embed(parent_tlv, + desc->type, 0, desc->instance, NULL); else - tlv = tlv_add(tlv, desc->type, 0, 0, NULL); + tlv = tlv_add(tlv, + desc->type, 0, desc->instance, NULL); d_assert(tlv, return NULL, "Can't add TLV"); break; } @@ -162,13 +174,15 @@ static c_uint32_t _tlv_add_compound(tlv_t **root, tlv_t *parent_tlv, if (desc->ctype == TLV_COMPOUND) { - d_trace(1, "\nBUILD %sC#%d T:%d (vsz=%d) off:%p ", - indent, i, desc->type, desc->vsize, p + offset); + d_trace(1, "\nBUILD %sC#%d T:%d I:%d (vsz=%d) off:%p ", + indent, i, desc->type, desc->instance, desc->vsize, + p + offset); if (parent_tlv) - tlv = tlv_embed(parent_tlv, desc->type, 0, 0, NULL); + tlv = tlv_embed(parent_tlv, + desc->type, 0, desc->instance, NULL); else - tlv = tlv_add(tlv, desc->type, 0, 0, NULL); + tlv = tlv_add(tlv, desc->type, 0, desc->instance, NULL); r = _tlv_add_compound(&emb_tlv, tlv, desc, p + offset + sizeof(tlv_header_t), depth + 1); @@ -178,8 +192,9 @@ static c_uint32_t _tlv_add_compound(tlv_t **root, tlv_t *parent_tlv, } else { - d_trace(1, "\nBUILD %sL#%d T:%d L:%d (cls:%d vsz:%d) off:%p ", - indent, i, desc->type, desc->length, + d_trace(1, "\nBUILD %sL#%d T:%d L:%d I:%d " + "(cls:%d vsz:%d) off:%p ", + indent, i, desc->type, desc->length, desc->instance, desc->ctype, desc->vsize, p + offset); tlv = _tlv_add_leaf(parent_tlv, tlv, desc, p + offset); @@ -203,13 +218,15 @@ static c_uint32_t _tlv_add_compound(tlv_t **root, tlv_t *parent_tlv, { if (desc->ctype == TLV_COMPOUND) { - d_trace(1, "\nBUILD %sC#%d T:%d (vsz=%d) off:%p ", - indent, i, desc->type, desc->vsize, p + offset); + d_trace(1, "\nBUILD %sC#%d T:%d I:%d (vsz=%d) off:%p ", + indent, i, desc->type, desc->instance, + desc->vsize, p + offset); if (parent_tlv) - tlv = tlv_embed(parent_tlv, desc->type, 0, 0, NULL); + tlv = tlv_embed(parent_tlv, + desc->type, 0, desc->instance, NULL); else - tlv = tlv_add(tlv, desc->type, 0, 0, NULL); + tlv = tlv_add(tlv, desc->type, 0, desc->instance, NULL); r = _tlv_add_compound(&emb_tlv, tlv, desc, p + offset + sizeof(tlv_header_t), depth + 1); @@ -219,8 +236,9 @@ static c_uint32_t _tlv_add_compound(tlv_t **root, tlv_t *parent_tlv, } else { - d_trace(1, "\nBUILD %sL#%d T:%d L:%d (cls:%d vsz:%d) off:%p ", - indent, i, desc->type, desc->length, + d_trace(1, "\nBUILD %sL#%d T:%d L:%d I:%d " + "(cls:%d vsz:%d) off:%p ", + indent, i, desc->type, desc->length, desc->instance, desc->ctype, desc->vsize, p + offset); tlv = _tlv_add_leaf(parent_tlv, tlv, desc, p + offset); @@ -287,7 +305,7 @@ static tlv_desc_t* _tlv_find_desc(c_uint8_t *desc_index, { d_trace(5, "%d, ", desc->type); - if (desc->type == tlv->type) + if (desc->type == tlv->type && desc->instance == tlv->instance) { *desc_index = i; *tlv_offset = offset; @@ -491,8 +509,9 @@ static status_t _tlv_parse_compound(void *msg, tlv_desc_t *parent_desc, return CORE_ERROR; } - d_trace(1, "\nPARSE %sC#%d T:%d (vsz=%d) off:%p ", - indent, i++, desc->type, desc->vsize, p + offset); + d_trace(1, "\nPARSE %sC#%d T:%d I:%d (vsz=%d) off:%p ", + indent, i++, desc->type, desc->instance, + desc->vsize, p + offset); offset += sizeof(tlv_header_t); @@ -508,8 +527,9 @@ static status_t _tlv_parse_compound(void *msg, tlv_desc_t *parent_desc, } else { - d_trace(1, "\nPARSE %sL#%d T:%d L:%d (cls:%d vsz:%d) off:%p ", - indent, i++, desc->type, desc->length, + d_trace(1, "\nPARSE %sL#%d T:%d L:%d I:%d " + "(cls:%d vsz:%d) off:%p ", + indent, i++, desc->type, desc->length, desc->instance, desc->ctype, desc->vsize, p + offset); rv = _tlv_parse_leaf(p + offset, desc, tlv); diff --git a/lib/gtp/gtpv2c_tlv.c b/lib/gtp/gtpv2c_tlv.c index 73b8e4bdb..1c155f728 100644 --- a/lib/gtp/gtpv2c_tlv.c +++ b/lib/gtp/gtpv2c_tlv.c @@ -5,6 +5,7 @@ tlv_desc_t tlv_desc_authorization_policy_support = TLV_UINT8, TLV_AUTHORIZATION_POLICY_SUPPORT_TYPE, TLV_AUTHORIZATION_POLICY_SUPPORT_LEN, + 0, sizeof(tlv_authorization_policy_support_t), { NULL } }; @@ -14,6 +15,7 @@ tlv_desc_t tlv_desc_ms_security_history = TLV_COMPOUND, TLV_MS_SECURITY_HISTORY_TYPE, TLV_MS_SECURITY_HISTORY_LEN, + 0, sizeof(tlv_ms_security_history_t), { &tlv_desc_authorization_policy_support, @@ -26,6 +28,7 @@ tlv_desc_t tlv_desc_ms_info = TLV_COMPOUND, TLV_MS_INFO_TYPE, TLV_MS_INFO_LEN, + 0, sizeof(tlv_ms_info_t), { &tlv_desc_ms_security_history, @@ -38,6 +41,7 @@ tlv_desc_t tlv_desc_bs_id = TLV_VAR_STR, TLV_BS_ID_TYPE, TLV_BS_ID_LEN, + 0, sizeof(tlv_bs_id_t), { NULL } }; @@ -47,6 +51,7 @@ tlv_desc_t tlv_desc_bs_info = TLV_COMPOUND, TLV_BS_INFO_TYPE, TLV_BS_INFO_LEN, + 0, sizeof(tlv_bs_info_t), { &tlv_desc_bs_id, @@ -55,7 +60,7 @@ tlv_desc_t tlv_desc_bs_info = }; tlv_desc_t tlv_desc_msg_ms_preattachment_req = { - TLV_MESSAGE, 0, 0, 0, { + TLV_MESSAGE, 0, 0, 0, 0, { &tlv_desc_ms_info, &tlv_desc_bs_info, NULL, diff --git a/test/gtp_message_test.c b/test/gtp_message_test.c index c331b2dd9..e56d3cc56 100644 --- a/test/gtp_message_test.c +++ b/test/gtp_message_test.c @@ -11,14 +11,14 @@ static void gtp_message_test1(abts_case *tc, void *data) tlv_msg_ms_preattachment_req reqv2; pkbuf_t *req = NULL; -#if 0 +#if 1 c_uint8_t *buf; c_uint32_t buflen; #endif { extern int _tlv_msg; - _tlv_msg = 0; + _tlv_msg = 1; } /* Initialize message value structure */ memset(&reqv, 0, sizeof(tlv_msg_ms_preattachment_req)); @@ -35,7 +35,7 @@ static void gtp_message_test1(abts_case *tc, void *data) tlv_build_msg(&req, &tlv_desc_msg_ms_preattachment_req, &reqv, TLV_MODE_T1_L2_I1); -#if 0 +#if 1 d_print_hex(req->payload, req->len); #endif @@ -49,13 +49,13 @@ static void gtp_message_test1(abts_case *tc, void *data) if (COMPD_ISSET(reqv2.ms_info)) if (COMPD_ISSET(reqv2.ms_info.ms_security_history)) if (VALUE_ISSET(reqv2.ms_info.ms_security_history.authorization_policy_support)) -#if 0 +#if 1 d_print("%02x", VALUE_GET(reqv2.ms_info.ms_security_history.authorization_policy_support)); #else ; #endif -#if 0 +#if 1 if (COMPD_ISSET(reqv2.bs_info)) if (OCTET_ISSET(reqv2.bs_info.bs_id)) {