open5gs/lib/core/include/core_tlv_msg.h

149 lines
3.3 KiB
C
Raw Normal View History

2017-03-12 13:52:14 +00:00
#ifndef __TLV_MSG_H__
#define __TLV_MSG_H__
2017-03-11 13:25:58 +00:00
2017-03-12 14:07:17 +00:00
#include "core_tlv.h"
2017-03-11 13:25:58 +00:00
#include "core_pkbuf.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
2017-03-12 14:07:17 +00:00
#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]
2017-03-11 13:25:58 +00:00
#define TLV_MAX_CHILD_DESC 128
2017-03-11 13:25:58 +00:00
typedef enum {
2017-03-12 13:52:14 +00:00
TLV_UINT8,
TLV_UINT16,
TLV_UINT24,
TLV_UINT32,
TLV_INT8,
TLV_INT16,
TLV_INT24,
TLV_INT32,
TLV_FIXED_STR,
TLV_VAR_STR,
TLV_NULL,
TLV_MORE,
TLV_COMPOUND,
TLV_MESSAGE,
2017-03-12 14:20:33 +00:00
} tlv_type_e;
2017-03-11 13:25:58 +00:00
2017-03-12 13:59:45 +00:00
typedef struct _tlv_desc_t {
2017-03-12 14:20:33 +00:00
tlv_type_e ctype;
c_int8_t *name;
2017-03-11 13:25:58 +00:00
c_uint16_t type;
c_uint16_t length;
2017-03-13 02:32:21 +00:00
c_uint8_t instance;
2017-03-11 13:25:58 +00:00
c_uint16_t vsize;
void *child_descs[TLV_MAX_CHILD_DESC];
2017-03-12 13:59:45 +00:00
} tlv_desc_t;
2017-03-11 13:25:58 +00:00
2017-03-13 04:02:42 +00:00
extern tlv_desc_t tlv_desc_more1;
extern tlv_desc_t tlv_desc_more2;
extern tlv_desc_t tlv_desc_more3;
extern tlv_desc_t tlv_desc_more4;
extern tlv_desc_t tlv_desc_more5;
extern tlv_desc_t tlv_desc_more6;
extern tlv_desc_t tlv_desc_more7;
extern tlv_desc_t tlv_desc_more8;
2017-03-12 14:07:17 +00:00
2017-03-15 12:20:26 +00:00
typedef c_uint64_t tlv_presence_t;
2017-03-12 14:07:17 +00:00
2017-03-11 13:25:58 +00:00
/* 8-bit Unsigned integer */
2017-03-12 13:59:45 +00:00
typedef struct _tlv_uint8_t {
2017-03-15 12:20:26 +00:00
tlv_presence_t presence;
c_uint8_t u8;
2017-03-12 13:59:45 +00:00
} tlv_uint8_t;
2017-03-11 13:25:58 +00:00
/* 16-bit Unsigned integer */
2017-03-12 13:59:45 +00:00
typedef struct _tlv_uint16_t {
2017-03-15 12:20:26 +00:00
tlv_presence_t presence;
c_uint16_t u16;
2017-03-12 13:59:45 +00:00
} tlv_uint16_t;
2017-03-11 13:25:58 +00:00
/* 24-bit Unsigned integer */
2017-03-12 13:59:45 +00:00
typedef struct _tlv_uint24_t {
2017-03-15 12:20:26 +00:00
tlv_presence_t presence;
c_uint32_t u24; /* Only 3 bytes valid */
2017-03-12 13:59:45 +00:00
} tlv_uint24_t;
2017-03-11 13:25:58 +00:00
/* 32-bit Unsigned integer */
2017-03-12 13:59:45 +00:00
typedef struct _tlv_uint32_t {
2017-03-15 12:20:26 +00:00
tlv_presence_t presence;
c_uint32_t u32;
2017-03-12 13:59:45 +00:00
} tlv_uint32_t;
2017-03-11 13:25:58 +00:00
/* 8-bit Signed integer */
2017-03-12 13:59:45 +00:00
typedef struct _tlv_int8_t {
2017-03-15 12:20:26 +00:00
tlv_presence_t presence;
c_int8_t i8;
2017-03-12 13:59:45 +00:00
} tlv_int8_t;
2017-03-11 13:25:58 +00:00
/* 16-bit Signed integer */
2017-03-12 13:59:45 +00:00
typedef struct _tlv_int16t {
2017-03-15 12:20:26 +00:00
tlv_presence_t presence;
c_int16_t i16;
2017-03-12 13:59:45 +00:00
} tlv_int16_t;
2017-03-11 13:25:58 +00:00
/* 24-bit Signed integer */
2017-03-12 13:59:45 +00:00
typedef struct _tlv_int24_t {
2017-03-15 12:20:26 +00:00
tlv_presence_t presence;
c_int32_t i24; /* Only 3 bytes valid */
2017-03-12 13:59:45 +00:00
} tlv_int24_t;
2017-03-11 13:25:58 +00:00
/* 32-bit Signed integer */
2017-03-12 13:59:45 +00:00
typedef struct _tlv_int32_t {
2017-03-15 12:20:26 +00:00
tlv_presence_t presence;
c_int32_t i32;
2017-03-12 13:59:45 +00:00
} tlv_int32_t;
2017-03-11 13:25:58 +00:00
/* Octets */
#define TLV_CLEAR_DATA(__dATA) \
do { \
d_assert((__dATA), , "Null param"); \
if ((__dATA)->data) \
{ \
CORE_FREE((__dATA)->data); \
(__dATA)->data = NULL; \
(__dATA)->len = 0; \
(__dATA)->presence = 0; \
} \
} while(0)
#define TLV_STORE_DATA(__dST, __sRC) \
do { \
d_assert((__sRC),, "Null param") \
d_assert((__sRC)->data,, "Null param") \
d_assert((__dST),, "Null param") \
TLV_CLEAR_DATA(__dST); \
(__dST)->presence = (__sRC)->presence; \
(__dST)->len = (__sRC)->len; \
(__dST)->data = core_calloc((__dST)->len, sizeof(c_uint8_t)); \
memcpy((__dST)->data, (__sRC)->data, (__dST)->len); \
} while(0)
2017-03-13 06:21:33 +00:00
typedef struct _tlv_octet_t {
2017-03-15 12:20:26 +00:00
tlv_presence_t presence;
2017-03-25 03:10:08 +00:00
void *data;
2017-03-15 12:20:26 +00:00
c_uint32_t len;
2017-03-13 06:21:33 +00:00
} tlv_octet_t;
2017-03-11 13:25:58 +00:00
/* No value */
2017-03-12 13:59:45 +00:00
typedef struct _tlv_null {
2017-03-15 12:20:26 +00:00
tlv_presence_t presence;
2017-03-12 13:59:45 +00:00
} tlv_null_t;
2017-03-11 13:25:58 +00:00
2017-03-12 13:59:45 +00:00
CORE_DECLARE(status_t) tlv_build_msg(
2017-03-12 14:25:56 +00:00
pkbuf_t **pkbuf, tlv_desc_t *desc, void *msg, int mode);
2017-03-11 13:25:58 +00:00
2017-03-12 13:59:45 +00:00
CORE_DECLARE(status_t) tlv_parse_msg(
2017-03-12 14:25:56 +00:00
void *msg, tlv_desc_t *desc, pkbuf_t *pkbuf, int mode);
2017-03-11 13:25:58 +00:00
#ifdef __cplusplus
}
#endif /* __cplusplus */
2017-03-12 13:52:14 +00:00
#endif /* __TLV_MSG_H__ */