libosmogsm 0.9.6-23.20170220git32ee5af8.fc42
Osmocom GSM library
Loading...
Searching...
No Matches
GSM L3 compatible TLV parser

Files

file  tlv.h
 
file  tlv_parser.c
 

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...
 

Macros

#define LV_GROSS_LEN(x)
 gross length of a LV type field
 
#define TLV_GROSS_LEN(x)
 gross length of a TLV type field
 
#define TLV16_GROSS_LEN(x)
 gross length of a TLV16 type field
 
#define TL16V_GROSS_LEN(x)
 gross length of a TL16V type field
 
#define L16TV_GROSS_LEN(x)
 gross length of a L16TV type field
 
#define TVLV_MAX_ONEBYTE   0x7f
 maximum length of TLV of one byte length
 
#define TLVP_PRESENT(x, y)
 
#define TLVP_LEN(x, y)
 
#define TLVP_VAL(x, y)
 
#define TLVP_PRES_LEN(tp, tag, min_len)
 

Enumerations

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
 
static uint16_t VTVL_GAN_GROSS_LEN (uint16_t tag, uint16_t len)
 gross length of vTvL header (tag+len)
 
static uint16_t VTVLV_GAN_GROSS_LEN (uint16_t tag, uint16_t len)
 gross length of vTvLV (tag+len+val)
 
static uint8_t * lv_put (uint8_t *buf, uint8_t len, const uint8_t *val)
 put (append) a LV field
 
static uint8_t * tlv_put (uint8_t *buf, uint8_t tag, uint8_t len, const uint8_t *val)
 put (append) a TLV field
 
static uint8_t * tlv16_put (uint8_t *buf, uint8_t tag, uint8_t len, const uint16_t *val)
 put (append) a TLV16 field
 
static uint8_t * tl16v_put (uint8_t *buf, uint8_t tag, uint16_t len, const uint8_t *val)
 put (append) a TL16V field
 
static uint8_t * tvlv_put (uint8_t *buf, uint8_t tag, uint16_t len, const uint8_t *val)
 put (append) a TvLV field
 
static uint8_t * vt_gan_put (uint8_t *buf, uint16_t tag)
 put (append) a variable-length tag or variable-length length *
 
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 msgb
 
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 msgb
 
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 msgb
 
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 msgb
 
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 msgb
 
static uint8_t * v_put (uint8_t *buf, uint8_t val)
 put (append) a V field
 
static uint8_t * tv_put (uint8_t *buf, uint8_t tag, uint8_t val)
 put (append) a TV field
 
static uint8_t * tv_fixed_put (uint8_t *buf, uint8_t tag, unsigned int len, const uint8_t *val)
 put (append) a TVfixed field
 
static uint8_t * tv16_put (uint8_t *buf, uint8_t tag, uint16_t val)
 put (append) a TV16 field
 
static uint8_t * msgb_lv_put (struct msgb *msg, uint8_t len, const uint8_t *val)
 put (append) a LV field to a msgb
 
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 msgb
 
static uint8_t * msgb_tv_put (struct msgb *msg, uint8_t tag, uint8_t val)
 put (append) a TV field to a msgb
 
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 msgb
 
static uint8_t * msgb_v_put (struct msgb *msg, uint8_t val)
 put (append) a V field to a msgb
 
static uint8_t * msgb_tv16_put (struct msgb *msg, uint8_t tag, uint16_t val)
 put (append) a TV16 field to a msgb
 
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 msgb
 
static uint8_t * msgb_tv_push (struct msgb *msg, uint8_t tag, uint8_t val)
 push (prepend) a TV field to a msgb
 
static uint8_t * msgb_tv16_push (struct msgb *msg, uint8_t tag, uint16_t val)
 push (prepend) a TV16 field to a msgb
 
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 msgb
 
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.
 
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.
 
void tlv_def_patch (struct tlv_definition *dst, const struct tlv_definition *src)
 take a master (src) tlvdev and fill up all empty slots in 'dst'
 
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.
 
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.
 
struct tlv_parsedosmo_tlvp_copy (const struct tlv_parsed *tp_orig, void *ctx)
 Copy tlv_parsed using given talloc context.
 
int osmo_tlvp_merge (struct tlv_parsed *dst, const struct tlv_parsed *src)
 Merge all tlv_parsed attributes of 'src' into 'dst'.
 
int osmo_shift_v_fixed (uint8_t **data, size_t *data_len, size_t len, uint8_t **value)
 
int osmo_match_shift_tv_fixed (uint8_t **data, size_t *data_len, uint8_t tag, size_t len, uint8_t **value)
 
int osmo_shift_tlv (uint8_t **data, size_t *data_len, uint8_t *tag, uint8_t **value, size_t *value_len)
 
int osmo_match_shift_tlv (uint8_t **data, size_t *data_len, uint8_t tag, uint8_t **value, size_t *value_len)
 
int osmo_shift_lv (uint8_t **data, size_t *data_len, uint8_t **value, size_t *value_len)
 
int tlv_dump (struct tlv_parsed *dec)
 Dump pasred TLV structure to stdout.
 
static __attribute__ ((constructor))
 

Variables

struct tlv_definition tvlv_att_def
 
struct tlv_definition vtvlv_gan_att_def
 
struct tlv_definition tvlv_att_def
 
struct tlv_definition vtvlv_gan_att_def
 

Detailed Description

Macro Definition Documentation

◆ L16TV_GROSS_LEN

#define L16TV_GROSS_LEN ( x)
Value:
(x+3)

gross length of a L16TV type field

Referenced by msgb_l16tv_put().

◆ LV_GROSS_LEN

#define LV_GROSS_LEN ( x)
Value:
(x+1)

gross length of a LV type field

Referenced by msgb_lv_put().

◆ TL16V_GROSS_LEN

#define TL16V_GROSS_LEN ( x)
Value:
(x+3)

gross length of a TL16V type field

Referenced by msgb_tl16v_put(), TVLV_GROSS_LEN(), and VTVLV_GAN_GROSS_LEN().

◆ TLV16_GROSS_LEN

#define TLV16_GROSS_LEN ( x)
Value:
((2*x)+2)

gross length of a TLV16 type field

Referenced by msgb_tlv16_put().

◆ TLV_GROSS_LEN

#define TLV_GROSS_LEN ( x)
Value:
(x+2)

gross length of a TLV type field

Referenced by msgb_tlv_push(), msgb_tlv_put(), TVLV_GROSS_LEN(), and VTVLV_GAN_GROSS_LEN().

◆ TLVP_LEN

#define TLVP_LEN ( x,
y )
Value:
(x)->lv[y].len

◆ TLVP_PRES_LEN

#define TLVP_PRES_LEN ( tp,
tag,
min_len )
Value:
(TLVP_PRESENT(tp, tag) && TLVP_LEN(tp, tag) >= min_len)

◆ TLVP_PRESENT

#define TLVP_PRESENT ( x,
y )
Value:
((x)->lv[y].val)

◆ TLVP_VAL

#define TLVP_VAL ( x,
y )
Value:
(x)->lv[y].val

Enumeration Type Documentation

◆ tlv_type

enum tlv_type

TLV type.

Enumerator
TLV_TYPE_NONE 

no type

TLV_TYPE_FIXED 

fixed-length value-only

TLV_TYPE_T 

tag-only

TLV_TYPE_TV 

tag-value (8bit)

TLV_TYPE_TLV 

tag-length-value

TLV_TYPE_TL16V 

tag, 16 bit length, value

TLV_TYPE_TvLV 

tag, variable length, value

TLV_TYPE_SINGLE_TV 

tag and value (both 4 bit) in 1 byte

TLV_TYPE_vTvLV_GAN 

variable-length tag, variable-length length

Function Documentation

◆ msgb_lv_put()

static uint8_t * msgb_lv_put ( struct msgb * msg,
uint8_t len,
const uint8_t * val )
inlinestatic

put (append) a LV field to a msgb

Returns
pointer to first byte after newly-put information

References LV_GROSS_LEN, and lv_put().

◆ msgb_tlv_push()

static uint8_t * msgb_tlv_push ( struct msgb * msg,
uint8_t tag,
uint8_t len,
const uint8_t * val )
inlinestatic

push (prepend) a TLV field to a msgb

Returns
pointer to first byte of newly-pushed information

References TLV_GROSS_LEN, and tlv_put().

◆ msgb_tlv_put()

static uint8_t * msgb_tlv_put ( struct msgb * msg,
uint8_t tag,
uint8_t len,
const uint8_t * val )
inlinestatic

put (append) a TLV field to a msgb

Returns
pointer to first byte after newly-put information

References TLV_GROSS_LEN, and tlv_put().

◆ msgb_tv16_push()

static uint8_t * msgb_tv16_push ( struct msgb * msg,
uint8_t tag,
uint16_t val )
inlinestatic

push (prepend) a TV16 field to a msgb

Returns
pointer to first byte of newly-pushed information

References tv16_put().

Referenced by rsl_rll_push_l3().

◆ msgb_tv16_put()

static uint8_t * msgb_tv16_put ( struct msgb * msg,
uint8_t tag,
uint16_t val )
inlinestatic

put (append) a TV16 field to a msgb

Returns
pointer to first byte after newly-put information

References tv16_put().

◆ msgb_tv_fixed_put()

static uint8_t * msgb_tv_fixed_put ( struct msgb * msg,
uint8_t tag,
unsigned int len,
const uint8_t * val )
inlinestatic

put (append) a TVfixed field to a msgb

Returns
pointer to first byte after newly-put information

References tv_fixed_put().

Referenced by abis_nm_fail_evt_vrep().

◆ msgb_tv_push()

static uint8_t * msgb_tv_push ( struct msgb * msg,
uint8_t tag,
uint8_t val )
inlinestatic

push (prepend) a TV field to a msgb

Returns
pointer to first byte of newly-pushed information

References tv_put().

◆ msgb_tv_put()

static uint8_t * msgb_tv_put ( struct msgb * msg,
uint8_t tag,
uint8_t val )
inlinestatic

put (append) a TV field to a msgb

Returns
pointer to first byte after newly-put information

References tv_put().

Referenced by abis_nm_fail_evt_vrep().

◆ msgb_tvlv_push()

static uint8_t * msgb_tvlv_push ( struct msgb * msg,
uint8_t tag,
uint16_t len,
const uint8_t * val )
inlinestatic

push (prepend) a TvLV field to a msgb

Returns
pointer to first byte of newly-pushed information

References TVLV_GROSS_LEN(), and tvlv_put().

◆ msgb_v_put()

static uint8_t * msgb_v_put ( struct msgb * msg,
uint8_t val )
inlinestatic

put (append) a V field to a msgb

Returns
pointer to first byte after newly-put information

References v_put().

◆ osmo_match_shift_tlv()

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

Parameters
datapointer to the pointer to data
data_lenpointer to size_t containing
  • data length
[in]expected_tagthe tag (IEI) that we expect at
  • data
[out]valuepointer to pointer of value part of IE
[out]value_lenpointer to length of
  • value
Returns
length of IE value; negative in case of error

References osmo_shift_tlv().

◆ osmo_match_shift_tv_fixed()

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

Parameters
datapointer to the pointer to data
data_lenpointer to size_t containing
  • data length
[in]tagthe tag (IEI) that we expect at
  • data
[in]lenthe length that we expect the fixed IE to have
[out]valuepointer to pointer of value part of IE
Returns
length of IE value; negative in case of error

◆ osmo_shift_lv()

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

Parameters
datapointer to the pointer to data
data_lenpointer to size_t containing
  • data lengt
[out]valueextracted pointer to value part of TLV
[out]value_lenextracted length of
  • value
Returns
number of bytes subtracted

◆ osmo_shift_tlv()

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

Parameters
datapointer to the pointer to data
data_lenpointer to size_t containing
  • data lengt
[out]tagextract the tag (IEI) at start of
  • data
[out]valueextracted pointer to value part of TLV
[out]value_lenextracted length of
  • value
Returns
number of bytes subtracted

Referenced by osmo_match_shift_tlv().

◆ osmo_shift_v_fixed()

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

Parameters
datapointer to the pointer to data
data_lenpointer to size_t containing
  • data length
[in]lenthe length that we expect the fixed IE to hav
[out]valuepointer to pointer of value part of IE
Returns
length of IE value; negative in case of error

◆ osmo_tlvp_copy()

struct tlv_parsed * osmo_tlvp_copy ( const struct tlv_parsed * tp_orig,
void * ctx )

Copy tlv_parsed using given talloc context.

Parameters
[in]tp_origParsed TLV structure
[in]ctxTalloc context for allocations
Returns
NULL on errors, tlv_parsed pointer otherwise

References tlv_p_entry::len, and tlv_p_entry::val.

◆ osmo_tlvp_merge()

int osmo_tlvp_merge ( struct tlv_parsed * dst,
const struct tlv_parsed * src )

Merge all tlv_parsed attributes of 'src' into 'dst'.

Parameters
[in]dstParsed TLV structure to merge into
[in]srcParsed TLV structure to merge from
Returns
0 on success, negative on error

References tlv_p_entry::len, and tlv_p_entry::val.

◆ tlv_parse()

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.

Parameters
[out]deccaller-allocated pointer to tlv_parsed
[in]defstructure defining the valid TLV tags / configurations
[in]bufthe input data buffer to be parsed
[in]buf_lenlength of the input data buffer
[in]lv_tagan initial LV tag at the start of the buffer
[in]lv_tag2a second initial LV tag following the lv_tag
Returns
number of bytes consumed by the TLV entry / IE parsed

References tlv_p_entry::len, tlv_parse_one(), and tlv_p_entry::val.

◆ tlv_parse_one()

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.

Parameters
[out]o_tagthe tag of the IE that was found
[out]o_lenlength of the IE that was found
[out]o_valpointer to the data of the IE that was found
[in]defstructure defining the valid TLV tags / configurations
[in]bufthe input data buffer to be parsed
[in]buf_lenlength of the input data buffer
Returns
number of bytes consumed by the TLV entry / IE parsed

References tlv_def::fixed_len, TLV_TYPE_FIXED, TLV_TYPE_SINGLE_TV, TLV_TYPE_T, TLV_TYPE_TL16V, TLV_TYPE_TLV, TLV_TYPE_TV, TLV_TYPE_TvLV, TLV_TYPE_vTvLV_GAN, and tlv_def::type.

Referenced by tlv_parse().

◆ tlvp_val16_unal()

static uint16_t tlvp_val16_unal ( const struct tlv_parsed * tp,
int pos )
inlinestatic

Align given TLV element with 16 bit value to an even address.

Parameters
[in]tppointer to tlv_parsed
[in]poselement to return
Returns
aligned 16 bit value

◆ tlvp_val32_unal()

static uint32_t tlvp_val32_unal ( const struct tlv_parsed * tp,
int pos )
inlinestatic

Align given TLV element with 32 bit value to an address that is a multiple of 4.

Parameters
[in]tppointer to tlv_parsed
[in]poselement to return
Returns
aligned 32 bit value

◆ tv16_put()

static uint8_t * tv16_put ( uint8_t * buf,
uint8_t tag,
uint16_t val )
inlinestatic

put (append) a TV16 field

Parameters
[in,out]bufdata buffer
[in]tagTag value
[in]valValue (in host byte order!)

Referenced by msgb_tv16_push(), and msgb_tv16_put().