Files
open5gs/lib/core/include/core_tlv.h
2017-02-02 20:34:37 +09:00

109 lines
3.1 KiB
C

#ifndef __CORE_TLV_H__
#define __CORE_TLV_H__
#include "core.h"
#include "core_pool.h"
#ifdef __cplusplus
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 NUM_OF_TLV_NODE 100
/* tlv_t struncture */
typedef struct _tlv_t
{
/* for tlv management */
struct _tlv_t* head;
struct _tlv_t* tail; /* this is used only for head tlv_t */
struct _tlv_t* next;
struct _tlv_t* parent;
struct _tlv_t* embedded;
/* tlv basic element */
c_uint32_t type;
c_uint32_t length;
void* value;
/* can be needed in encoding tlv_t*/
c_uint8_t buff_allocated;
c_uint32_t buff_len;
c_uint8_t* buff_ptr;
c_uint8_t* buff;
} tlv_t;
#define tlv_type(pTlv) pTlv->type
#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);
CORE_DECLARE(void) tlv_free_all(tlv_t *rootTlv);
CORE_DECLARE(status_t) tlv_init(void);
CORE_DECLARE(status_t) tlv_final(void);
/* tlv_t encoding functions */
CORE_DECLARE(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);
CORE_DECLARE(tlv_t*) tlv_add(
tlv_t *headTlv, c_uint32_t type, c_uint32_t length, c_uint8_t *value);
CORE_DECLARE(tlv_t*) tlv_create_buff_enabled_tlv(
c_uint8_t *buff, c_uint32_t buff_len,
c_uint32_t type, c_uint32_t length, c_uint8_t *value);
CORE_DECLARE(tlv_t*) tlv_embed(
tlv_t *parent_tlv, c_uint32_t type, c_uint32_t length, c_uint8_t *value);
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);
CORE_DECLARE(c_uint32_t) tlv_pool_avail(void);
CORE_DECLARE(c_uint32_t) tlv_calc_length(tlv_t *p_tlv, c_uint8_t mode);
CORE_DECLARE(c_uint32_t) tlv_calc_count(tlv_t *p_tlv);
CORE_DECLARE(c_uint8_t) tlv_value_8(tlv_t *tlv);
CORE_DECLARE(c_uint16_t) tlv_value_16(tlv_t *tlv);
CORE_DECLARE(c_uint32_t) tlv_value_32(tlv_t *tlv);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* !__CORE_TLV_H__ */