libosmogsm 1.13.1.1-afb4 Osmocom GSM library

Data Structures | Macros | Enumerations | Functions | Variables
tlv.h File Reference
TLV parser
`#include <stdint.h>`
`#include <string.h>`
`#include <osmocom/core/msgb.h>`
`#include <osmocom/core/byteswap.h>`
`#include <osmocom/core/bit16gen.h>`
`#include <osmocom/core/bit32gen.h>`

Go to the source code of this file.

## Data Structures
struct | tlv_p_entry
| Entry in a TLV parser array. More...
struct | tlv_def
| Definition of a single IE (Information Element) More...
struct | tlv_definition
| Definition of All 256 IE / TLV. More...
struct | tlv_parsed
| result of the TLV parser More...
struct | osmo_tlv_prot_msg_def
struct | osmo_tlv_prot_ie_def
struct | osmo_tlv_prot_def
| Osmocom TLV protocol definition. More...

## Macros
#define | LV_GROSS_LEN(x) (x+1)
| gross length of a LV type field More...
#define | TLV_GROSS_LEN(x) (x+2)
| gross length of a TLV type field More...
#define | TLV16_GROSS_LEN(x) ((2*x)+2)
| gross length of a TLV16 type field More...
#define | TL16V_GROSS_LEN(x) (x+3)
| gross length of a TL16V type field More...
#define | L16TV_GROSS_LEN(x) (x+3)
| gross length of a L16TV type field More...
#define | T16LV_GROSS_LEN(x) (x+3)
| gross length of a T16LV type field More...
#define | TVLV_MAX_ONEBYTE 0x7f
| maximum length of TLV of one byte length More...
#define | TLVP_PRESENT(x, y) (!!((x)->lv[y].val))
#define | TLVP_LEN(x, y) (x)->lv[y].len
#define | TLVP_VAL(x, y) (x)->lv[y].val
#define | TLVP_PRES_LEN(tp, tag, min_len) (TLVP_PRESENT(tp, tag) && TLVP_LEN(tp, tag) >= min_len)
#define | TLVP_GET(_tp, tag) (TLVP_PRESENT(_tp, tag)? &(_tp)->lv[tag] : NULL)
| Return pointer to a TLV element if it is present. More...
#define | TLVP_GET_MINLEN(_tp, tag, min_len) (TLVP_PRES_LEN(_tp, tag, min_len)? &(_tp)->lv[tag] : NULL)
| Like TLVP_GET(), but enforcing a minimum val length. More...
#define | TLVP_VAL_MINLEN(_tp, tag, min_len) (TLVP_PRES_LEN(_tp, tag, min_len)? (_tp)->lv[tag].val : NULL)
| Like TLVP_VAL(), but enforcing a minimum val length. More...
#define | MSG_DEF(name, mand_ies, flags) { name, mand_ies, ARRAY_SIZE(mand_ies), flags }

## Enumerations
enum | osmo_tlv_parser_error { OSMO_TLVP_ERR_OFS_BEYOND_BUFFER = -1 , OSMO_TLVP_ERR_OFS_LEN_BEYOND_BUFFER = -2 , OSMO_TLVP_ERR_UNKNOWN_TLV_TYPE = -3 , OSMO_TLVP_ERR_MAND_IE_MISSING = -50 , OSMO_TLVP_ERR_IE_TOO_SHORT = -51 }
| error return codes of various TLV parser functions More...
enum | tlv_type { TLV_TYPE_NONE , TLV_TYPE_FIXED , TLV_TYPE_T , TLV_TYPE_TV , TLV_TYPE_TLV , TLV_TYPE_TL16V , TLV_TYPE_TvLV , TLV_TYPE_SINGLE_TV , TLV_TYPE_vTvLV_GAN }
| TLV type. More...

## Functions
static uint16_t | TVLV_GROSS_LEN (uint16_t len)
| gross length of a TVLV type field More...
static uint16_t | VTVL_GAN_GROSS_LEN (uint16_t tag, uint16_t len)
| gross length of vTvL header (tag+len) More...
static uint16_t | VTVLV_GAN_GROSS_LEN (uint16_t tag, uint16_t len)
| gross length of vTvLV (tag+len+val) More...
static uint8_t * | lv_put (uint8_t *buf, uint8_t len, const uint8_t *val)
| put (append) a LV field More...
static uint8_t * | tlv_put (uint8_t *buf, uint8_t tag, uint8_t len, const uint8_t *val)
| Append a TLV field, a Tag-Length-Value field. More...
static uint8_t * | tl_put (uint8_t *buf, uint8_t tag, uint8_t len)
| put (append) a TL field (a TLV field but omitting the value part). More...
static uint8_t * | tlv16_put (uint8_t *buf, uint8_t tag, uint8_t len, const uint16_t *val)
| put (append) a TLV16 field More...
static uint8_t * | tl16v_put (uint8_t *buf, uint8_t tag, uint16_t len, const uint8_t *val)
| put (append) a TL16V field More...
static uint8_t * | tl16_put (uint8_t *buf, uint8_t tag, uint16_t len)
| put (append) a TL16 field. More...
static uint8_t * | t16lv_put (uint8_t *buf, uint16_t tag, uint8_t len, const uint8_t *val)
| put (append) a TL16V field More...
static uint8_t * | tvlv_put (uint8_t *buf, uint8_t tag, uint16_t len, const uint8_t *val)
| put (append) a TvLV field More...
static uint8_t * | tvl_put (uint8_t *buf, uint8_t tag, uint16_t len)
| put (append) a TvL field (a TvLV with variable-size length, where the value part's length is already known, but will be put() later). More...
static uint8_t * | vt_gan_put (uint8_t *buf, uint16_t tag)
| put (append) a variable-length tag or variable-length length * More...
static uint8_t * | vtvl_gan_put (uint8_t *buf, uint16_t tag, uint16_t len)
static uint8_t * | vtvlv_gan_put (uint8_t *buf, uint16_t tag, uint16_t len, const uint8_t *val)
static uint8_t * | msgb_tlv16_put (struct msgb *msg, uint8_t tag, uint8_t len, const uint16_t *val)
| put (append) a TLV16 field to Message buffers More...
static uint8_t * | msgb_tl16v_put (struct msgb *msg, uint8_t tag, uint16_t len, const uint8_t *val)
| put (append) a TL16V field to Message buffers More...
static uint8_t * | msgb_t16lv_put (struct msgb *msg, uint16_t tag, uint8_t len, const uint8_t *val)
static uint8_t * | msgb_tvl_put (struct msgb *msg, uint8_t tag, uint16_t len)
| put (append) a TvL field to Message buffers, i.e. More...
static uint8_t * | msgb_tvlv_put (struct msgb *msg, uint8_t tag, uint16_t len, const uint8_t *val)
| put (append) a TvLV field to Message buffers More...
static uint8_t * | msgb_tvlv_put_16be (struct msgb *msg, uint8_t tag, uint16_t val)
| put (append) a TvLV field containing a big-endian 16bit value to msgb. More...
static uint8_t * | msgb_tvlv_put_32be (struct msgb *msg, uint8_t tag, uint32_t val)
| put (append) a TvLV field containing a big-endian 16bit value to msgb. More...
static uint8_t * | msgb_vtvlv_gan_put (struct msgb *msg, uint16_t tag, uint16_t len, const uint8_t *val)
| put (append) a vTvLV field to Message buffers More...
static uint8_t * | msgb_l16tv_put (struct msgb *msg, uint16_t len, uint8_t tag, const uint8_t *val)
| put (append) a L16TV field to Message buffers More...
static uint8_t * | v_put (uint8_t *buf, uint8_t val)
| put (append) a V field More...
static uint8_t * | tv_put (uint8_t *buf, uint8_t tag, uint8_t val)
| put (append) a TV field More...
static uint8_t * | tv_fixed_put (uint8_t *buf, uint8_t tag, unsigned int len, const uint8_t *val)
| put (append) a TVfixed field More...
static uint8_t * | tv16_put (uint8_t *buf, uint8_t tag, uint16_t val)
| put (append) a TV16 field More...
static uint8_t * | msgb_lv_put (struct msgb *msg, uint8_t len, const uint8_t *val)
| put (append) a LV field to a Message buffers More...
static uint8_t * | msgb_tlv_put (struct msgb *msg, uint8_t tag, uint8_t len, const uint8_t *val)
| put (append) a TLV field to a Message buffers More...
static uint8_t * | msgb_tv_put (struct msgb *msg, uint8_t tag, uint8_t val)
| put (append) a TV field to a Message buffers More...
static uint8_t * | msgb_tv_fixed_put (struct msgb *msg, uint8_t tag, unsigned int len, const uint8_t *val)
| put (append) a TVfixed field to a Message buffers More...
static uint8_t * | msgb_v_put (struct msgb *msg, uint8_t val)
| put (append) a V field to a Message buffers More...
static uint8_t * | msgb_tl_put (struct msgb *msg, uint8_t tag)
| put (append) a TL fields to a Message buffers More...
static uint8_t * | msgb_tv16_put (struct msgb *msg, uint8_t tag, uint16_t val)
| put (append) a TV16 field (network order) to the given msgb More...
static uint8_t * | msgb_tv32_put (struct msgb *msg, uint8_t tag, uint32_t val)
| put (append) a TV32 field (network order) to the given msgb More...
static uint8_t * | msgb_tlv_push (struct msgb *msg, uint8_t tag, uint8_t len, const uint8_t *val)
| push (prepend) a TLV field to a Message buffers More...
static uint8_t * | msgb_tlv1_push (struct msgb *msg, uint8_t tag, uint8_t val)
| push 1-byte tagged value More...
static uint8_t * | msgb_tv_push (struct msgb *msg, uint8_t tag, uint8_t val)
| push (prepend) a TV field to a Message buffers More...
static uint8_t * | msgb_tv16_push (struct msgb *msg, uint8_t tag, uint16_t val)
| push (prepend) a TV16 field to a Message buffers More...
static uint8_t * | msgb_tv32_push (struct msgb *msg, uint8_t tag, uint32_t val)
| push (prepend) a TV32 field to a Message buffers More...
static uint8_t * | msgb_tvlv_push (struct msgb *msg, uint8_t tag, uint16_t len, const uint8_t *val)
| push (prepend) a TvLV field to a Message buffers More...
static uint8_t * | msgb_vtvl_gan_push (struct msgb *msg, uint16_t tag, uint16_t len)
static uint8_t * | msgb_vtvlv_gan_push (struct msgb *msg, uint16_t tag, uint16_t len, const uint8_t *val)
int | tlv_parse_one (uint8_t *o_tag, uint16_t *o_len, const uint8_t **o_val, const struct tlv_definition *def, const uint8_t *buf, int buf_len)
| Parse a single TLV encoded IE. More...
int | tlv_parse (struct tlv_parsed *dec, const struct tlv_definition *def, const uint8_t *buf, int buf_len, uint8_t lv_tag, uint8_t lv_tag2)
| Parse an entire buffer of TLV encoded Information Elements. More...
int | tlv_parse2 (struct tlv_parsed *dec, int dec_multiples, const struct tlv_definition *def, const uint8_t *buf, int buf_len, uint8_t lv_tag, uint8_t lv_tag2)
| Like tlv_parse(), but capable of decoding multiple occurences of the same IE. More...
void | tlv_def_patch (struct tlv_definition *dst, const struct tlv_definition *src)
| take a master (src) tlv_definition and fill up all empty slots in 'dst' More...
int | tlv_encode_one (struct msgb *msg, enum tlv_type type, uint8_t tag, unsigned int len, const uint8_t *val)
| Encode a single TLV into given message buffer. More...
int | tlv_encode (struct msgb *msg, const struct tlv_definition *def, const struct tlv_parsed *tp)
| Encode a set of decoded TLVs according to a given definition into a message buffer. More...
int | tlv_encode_ordered (struct msgb *msg, const struct tlv_definition *def, const struct tlv_parsed *tp, const uint8_t *tag_order, unsigned int tag_order_len)
| Encode a set of decoded TLVs according to a given definition and IE order into a message buffer. More...
static uint8_t | tlvp_val8 (const struct tlv_parsed *tp, uint8_t tag, uint8_t default_val)
| Obtain 1-byte TLV element. More...
static uint16_t | tlvp_val16_unal (const struct tlv_parsed *tp, int pos)
| Align given TLV element with 16 bit value to an even address. More...
static uint32_t | tlvp_val32_unal (const struct tlv_parsed *tp, int pos)
| Align given TLV element with 32 bit value to an address that is a multiple of 4. More...
static uint16_t | tlvp_val16be (const struct tlv_parsed *tp, int pos)
| Retrieve (possibly unaligned) TLV element and convert to host byte order. More...
static uint32_t | tlvp_val32be (const struct tlv_parsed *tp, int pos)
| Retrieve (possibly unaligned) TLV element and convert to host byte order. More...
struct tlv_parsed * | osmo_tlvp_copy (const struct tlv_parsed *tp_orig, void *ctx)
| Copy tlv_parsed using given talloc context. More...
int | osmo_tlvp_merge (struct tlv_parsed *dst, const struct tlv_parsed *src)
| Merge all tlv_parsed attributes of 'src' into 'dst'. More...
int | osmo_shift_v_fixed (uint8_t **data, size_t *data_len, size_t len, uint8_t **value)
| Advance the data pointer, subtract length and assign value pointer. More...
int | osmo_match_shift_tv_fixed (uint8_t **data, size_t *data_len, uint8_t tag, size_t len, uint8_t **value)
| Match tag, check length and assign value pointer. More...
int | osmo_shift_tlv (uint8_t **data, size_t *data_len, uint8_t *tag, uint8_t **value, size_t *value_len)
| Extract TLV and advance data pointer + subtract length. More...
int | osmo_match_shift_tlv (uint8_t **data, size_t *data_len, uint8_t expected_tag, uint8_t **value, size_t *value_len)
| Verify TLV header and advance data / subtract length. More...
int | osmo_shift_lv (uint8_t **data, size_t *data_len, uint8_t **value, size_t *value_len)
| Extract LV and advance data pointer + subtract length. More...
const char * | osmo_tlv_prot_msg_name (const struct osmo_tlv_prot_def *pdef, uint8_t msg_type)
| get the message name for given msg_type in protocol pdef More...
const char * | osmo_tlv_prot_ie_name (const struct osmo_tlv_prot_def *pdef, uint8_t iei)
| get the IE name for given IEI in protocol pdef More...
int | osmo_tlv_prot_validate_tp (const struct osmo_tlv_prot_def *pdef, uint8_t msg_type, const struct tlv_parsed *tp, int log_subsys, const char *log_pfx)
| Validate an already TLV-decoded message against the protocol definition. More...
int | osmo_tlv_prot_parse (const struct osmo_tlv_prot_def *pdef, struct tlv_parsed *dec, unsigned int dec_multiples, uint8_t msg_type, const uint8_t *buf, unsigned int buf_len, uint8_t lv_tag, uint8_t lv_tag2, int log_subsys, const char *log_pfx)
| Parse + Validate a TLV-encoded message against the protocol definition. More...
static uint32_t | osmo_tlv_prot_msgt_flags (const struct osmo_tlv_prot_def *pdef, uint8_t msg_type)

## Variables
struct tlv_definition | tvlv_att_def
struct tlv_definition | vtvlv_gan_att_def