diff --git a/lib/gtp/asn_msg.h b/lib/core/include/core_tlv_msg.h similarity index 95% rename from lib/gtp/asn_msg.h rename to lib/core/include/core_tlv_msg.h index aacc1a4d52..d3d7f1efe3 100644 --- a/lib/gtp/asn_msg.h +++ b/lib/core/include/core_tlv_msg.h @@ -1,18 +1,19 @@ #ifndef __TLV_MSG_H__ #define __TLV_MSG_H__ +#include "core_tlv.h" #include "core_pkbuf.h" -#define TLV_HEADER_LEN 12 -#define TLV_VARIABLE 0 - #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ -typedef struct _tlv_header_t { - c_uint64_t set_ind; -} tlv_header_t; +#define TLV_MAX_HEADROOM 16 + +#define TLV_VARIABLE_LEN 0 + +#define TLV_MAX_MORE 8 +#define TLV_1_OR_MORE(__v) __v[TLV_MAX_MORE] #define VALUE_SET(__m, __value) \ __m.v = __value; __m.h.set_ind = 1 @@ -69,6 +70,12 @@ typedef struct _tlv_desc_t { void *child_descs[]; } tlv_desc_t; +extern tlv_desc_t tlv_desc_more; + +typedef struct _tlv_header_t { + c_uint64_t set_ind; +} tlv_header_t; + /* 8-bit Unsigned integer */ typedef struct _tlv_uint8_t { tlv_header_t h; @@ -129,11 +136,6 @@ typedef struct _tlv_null { tlv_header_t h; } tlv_null_t; -#define TLV_MORE 8 -#define TLV_1_OR_MORE(__v) __v[TLV_MORE] - -extern tlv_desc_t tlv_desc_more; - CORE_DECLARE(status_t) tlv_build_msg( pkbuf_t **msg, tlv_desc_t *msg_desc, void *asn); diff --git a/lib/core/src/Makefile.am b/lib/core/src/Makefile.am index 8f136e46be..f0f66a9c7a 100644 --- a/lib/core/src/Makefile.am +++ b/lib/core/src/Makefile.am @@ -16,10 +16,11 @@ libcore_la_SOURCES = \ ../include/core_rwlock.h ../include/core_semaphore.h ../include/core_sha1.h \ ../include/core_sha1_hmac.h ../include/core_sha2.h ../include/core_sha2_hmac.h \ ../include/core_signal.h ../include/core_thread.h ../include/core_time.h \ - ../include/core_timer.h ../include/core_tlv.h ../include/core_version.h + ../include/core_timer.h ../include/core_tlv.h ../include/core_tlv_msg.h \ + ../include/core_version.h nodist_libcore_la_SOURCES = \ - debug.c fsm.c msgq.c ringbuf.c timer.c tlv.c \ + debug.c fsm.c msgq.c ringbuf.c timer.c tlv.c tlv_msg.c \ aes.c aes_cmac.c sha1.c sha1_hmac.c sha2.c sha2_hmac.c misc.c libcore_la_DEPENDENCIES = \ diff --git a/lib/gtp/asn_msg.c b/lib/core/src/tlv_msg.c similarity index 99% rename from lib/gtp/asn_msg.c rename to lib/core/src/tlv_msg.c index 5582e1da94..64b228ad4f 100644 --- a/lib/gtp/asn_msg.c +++ b/lib/core/src/tlv_msg.c @@ -1,8 +1,7 @@ #define TRACE_MODULE _tlv_msg -#include "core_debug.h" -#include "core_tlv.h" -#include "asn_msg.h" +#include "core_debug.h" +#include "core_tlv_msg.h" tlv_desc_t tlv_desc_more = { @@ -258,7 +257,7 @@ status_t tlv_build_msg(pkbuf_t **msg, tlv_desc_t *msg_desc, void *asn) "Can't build TLV message"); length = tlv_calc_length(root, TLV_MODE_T1_L2_I1); - *msg = pkbuf_alloc(TLV_HEADER_LEN, length); + *msg = pkbuf_alloc(TLV_MAX_HEADROOM, length); d_assert(*msg, tlv_free_all(root); return CORE_ENOMEM, "pkbuf_alloc() failed"); (*msg)->len = length; diff --git a/lib/gtp/Makefile.am b/lib/gtp/Makefile.am index 75ca8f4b1e..3515e171ac 100644 --- a/lib/gtp/Makefile.am +++ b/lib/gtp/Makefile.am @@ -3,10 +3,10 @@ noinst_LTLIBRARIES = libgtp.la libgtp_la_SOURCES = \ - asn_msg.h asn_tlv_desc.h + gtpv2c_tlv.h nodist_libgtp_la_SOURCES = \ - asn_msg.c asn_tlv_desc.c + gtpv2c_tlv.c AM_CPPFLAGS = \ -I$(top_srcdir)/lib/core/include \ diff --git a/lib/gtp/asn_tlv_desc.c b/lib/gtp/gtpv2c_tlv.c similarity index 97% rename from lib/gtp/asn_tlv_desc.c rename to lib/gtp/gtpv2c_tlv.c index 6ec70d5152..73b8e4bdb3 100644 --- a/lib/gtp/asn_tlv_desc.c +++ b/lib/gtp/gtpv2c_tlv.c @@ -1,4 +1,4 @@ -#include "asn_tlv_desc.h" +#include "gtpv2c_tlv.h" tlv_desc_t tlv_desc_authorization_policy_support = { diff --git a/lib/gtp/asn_tlv_desc.h b/lib/gtp/gtpv2c_tlv.h similarity index 81% rename from lib/gtp/asn_tlv_desc.h rename to lib/gtp/gtpv2c_tlv.h index 899392e064..9d299e1fcb 100644 --- a/lib/gtp/asn_tlv_desc.h +++ b/lib/gtp/gtpv2c_tlv.h @@ -1,7 +1,7 @@ -#ifndef __TLV_TLV_DESC_H__ -#define __TLV_TLV_DESC_H__ +#ifndef __GTPV2C_TLV_H__ +#define __GTPV2C_TLV_H__ -#include "asn_msg.h" +#include "core_tlv_msg.h" #ifdef __cplusplus extern "C" { @@ -13,7 +13,7 @@ typedef tlv_uint8_t tlv_authorization_policy_support_t; extern tlv_desc_t tlv_desc_authorization_policy_support; #define TLV_MS_SECURITY_HISTORY_TYPE 108 -#define TLV_MS_SECURITY_HISTORY_LEN TLV_VARIABLE +#define TLV_MS_SECURITY_HISTORY_LEN TLV_VARIABLE_LEN typedef struct _tlv_ms_security_history_t { tlv_header_t h; tlv_authorization_policy_support_t authorization_policy_support; @@ -21,7 +21,7 @@ typedef struct _tlv_ms_security_history_t { extern tlv_desc_t tlv_desc_ms_security_history; #define TLV_MS_INFO_TYPE 103 -#define TLV_MS_INFO_LEN TLV_VARIABLE +#define TLV_MS_INFO_LEN TLV_VARIABLE_LEN typedef struct _tlv_ms_info_t { tlv_header_t h; tlv_ms_security_history_t ms_security_history; @@ -29,12 +29,12 @@ typedef struct _tlv_ms_info_t { extern tlv_desc_t tlv_desc_ms_info; #define TLV_BS_ID_TYPE 25 -#define TLV_BS_ID_LEN TLV_VARIABLE +#define TLV_BS_ID_LEN TLV_VARIABLE_LEN typedef tlv_octets_t tlv_bs_id_t; extern tlv_desc_t tlv_desc_bs_id; #define TLV_BS_INFO_TYPE 26 -#define TLV_BS_INFO_LEN TLV_VARIABLE +#define TLV_BS_INFO_LEN TLV_VARIABLE_LEN typedef struct _tlv_bs_info_t { tlv_header_t h; tlv_bs_id_t bs_id; @@ -52,4 +52,4 @@ extern tlv_desc_t tlv_desc_msg_ms_preattachment_req; } #endif /* __cplusplus */ -#endif /* __TLV_TLV_DESC_H__ */ +#endif /* __GTPV2C_TLV_H__ */ diff --git a/test/gtp_message_test.c b/test/gtp_message_test.c index 10bc2fa89f..ae6a71022e 100644 --- a/test/gtp_message_test.c +++ b/test/gtp_message_test.c @@ -3,8 +3,7 @@ #include "core_debug.h" #include "testutil.h" -#include "asn_msg.h" -#include "asn_tlv_desc.h" +#include "gtpv2c_tlv.h" static void gtp_message_test1(abts_case *tc, void *data) {