29#define LV_GROSS_LEN(x) (x+1)
31#define TLV_GROSS_LEN(x) (x+2)
33#define TLV16_GROSS_LEN(x) ((2*x)+2)
35#define TL16V_GROSS_LEN(x) (x+3)
37#define L16TV_GROSS_LEN(x) (x+3)
39#define T16LV_GROSS_LEN(x) (x+3)
42#define TVLV_MAX_ONEBYTE 0x7f
96static inline uint8_t *
lv_put(uint8_t *buf, uint8_t
len,
100 memcpy(buf, val,
len);
111static inline uint8_t *
tlv_put(uint8_t *buf, uint8_t tag, uint8_t
len,
118 memcpy(buf, val,
len);
126static inline uint8_t *
tl_put(uint8_t *buf, uint8_t tag, uint8_t
len)
134static inline uint8_t *
tlv16_put(uint8_t *buf, uint8_t tag, uint8_t
len,
139 memcpy(buf, val,
len*2);
144static inline uint8_t *
tl16v_put(uint8_t *buf, uint8_t tag, uint16_t
len,
150 memcpy(buf, val,
len);
155static inline uint8_t *
tl16_put(uint8_t *buf, uint8_t tag, uint16_t
len)
164static inline uint8_t *
t16lv_put(uint8_t *buf, uint16_t tag, uint8_t
len,
170 memcpy(buf, val,
len);
175static inline uint8_t *
tvlv_put(uint8_t *buf, uint8_t tag, uint16_t
len,
193static inline uint8_t *
tvl_put(uint8_t *buf, uint8_t tag, uint16_t
len)
211 *buf++ = 0x80 | (tag >> 8);
212 *buf++ = (tag & 0xff);
236 memcpy(ret, val,
len);
298 uint16_t
len,
const uint8_t *val)
313 memcpy(buf, val,
len);
318static inline uint8_t *
v_put(uint8_t *buf, uint8_t val)
325static inline uint8_t *
tv_put(uint8_t *buf, uint8_t tag,
335 unsigned int len,
const uint8_t *val)
338 memcpy(buf, val,
len);
347static inline uint8_t *
tv16_put(uint8_t *buf, uint8_t tag,
377 return tv_put(buf, tag, val);
383 unsigned int len,
const uint8_t *val)
394 return v_put(buf, val);
423 osmo_store32be(val, buf);
466 osmo_store32be(val, buf);
492 uint16_t
len,
const uint8_t *val)
539int tlv_parse_one(uint8_t *o_tag, uint16_t *o_len,
const uint8_t **o_val,
541 const uint8_t *buf,
int buf_len);
543 const uint8_t *buf,
int buf_len, uint8_t lv_tag, uint8_t lv_tag2);
546 uint8_t lv_tag, uint8_t lv_tag2);
551 unsigned int len,
const uint8_t *val);
554 const uint8_t *tag_order,
unsigned int tag_order_len);
556#define TLVP_PRESENT(x, y) (!!((x)->lv[y].val))
557#define TLVP_LEN(x, y) (x)->lv[y].len
558#define TLVP_VAL(x, y) (x)->lv[y].val
560#define TLVP_PRES_LEN(tp, tag, min_len) \
561 (TLVP_PRESENT(tp, tag) && TLVP_LEN(tp, tag) >= min_len)
573#define TLVP_GET(_tp, tag) (TLVP_PRESENT(_tp, tag)? &(_tp)->lv[tag] : NULL)
581#define TLVP_GET_MINLEN(_tp, tag, min_len) \
582 (TLVP_PRES_LEN(_tp, tag, min_len)? &(_tp)->lv[tag] : NULL)
590#define TLVP_VAL_MINLEN(_tp, tag, min_len) \
591 (TLVP_PRES_LEN(_tp, tag, min_len)? (_tp)->lv[tag].val : NULL)
641 return osmo_load16be(
TLVP_VAL(tp, pos));
651 return osmo_load32be(
TLVP_VAL(tp, pos));
658 size_t len, uint8_t **value);
660 uint8_t tag,
size_t len, uint8_t **value);
662 uint8_t *tag, uint8_t **value,
size_t *value_len);
664 uint8_t tag, uint8_t **value,
size_t *value_len);
666 uint8_t **value,
size_t *value_len);
668#define MSG_DEF(name, mand_ies, flags) { name, mand_ies, ARRAY_SIZE(mand_ies), flags }
705 const struct tlv_parsed *tp,
int log_subsys,
const char *log_pfx);
709 const uint8_t *buf,
unsigned int buf_len, uint8_t lv_tag, uint8_t lv_tag2,
710 int log_subsys,
const char *log_pfx);
static unsigned char * msgb_put(struct msgb *msgb, unsigned int len)
static unsigned char * msgb_push(struct msgb *msgb, unsigned int len)
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
Definition: tlv.h:472
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.
Definition: tlv_parser.c:478
static uint8_t * vtvl_gan_put(uint8_t *buf, uint16_t tag, uint16_t len)
Definition: tlv.h:220
#define TL16V_GROSS_LEN(x)
gross length of a TL16V type field
Definition: tlv.h:35
static uint16_t tlvp_val16be(const struct tlv_parsed *tp, int pos)
Retrieve (possibly unaligned) TLV element and convert to host byte order.
Definition: tlv.h:639
#define TLVP_VAL(x, y)
Definition: tlv.h:558
static uint8_t * tlv16_put(uint8_t *buf, uint8_t tag, uint8_t len, const uint16_t *val)
put (append) a TLV16 field
Definition: tlv.h:134
#define TVLV_MAX_ONEBYTE
maximum length of TLV of one byte length
Definition: tlv.h:42
static uint8_t * tv_fixed_put(uint8_t *buf, uint8_t tag, unsigned int len, const uint8_t *val)
put (append) a TVfixed field
Definition: tlv.h:334
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.
Definition: tlv_parser.c:234
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.
Definition: tlv_parser.c:199
tlv_type
TLV type.
Definition: tlv.h:508
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.
Definition: tlv_parser.c:506
static uint8_t * lv_put(uint8_t *buf, uint8_t len, const uint8_t *val)
put (append) a LV field
Definition: tlv.h:96
#define TLVP_VAL_MINLEN(_tp, tag, min_len)
Like TLVP_VAL(), but enforcing a minimum val length.
Definition: tlv.h:590
struct tlv_definition vtvlv_gan_att_def
Definition: tlv_parser.c:50
static uint8_t * tv_put(uint8_t *buf, uint8_t tag, uint8_t val)
put (append) a TV field
Definition: tlv.h:325
static uint8_t * vtvlv_gan_put(uint8_t *buf, uint16_t tag, uint16_t len, const uint8_t *val)
Definition: tlv.h:229
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.
Definition: tlv_parser.c:173
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
Definition: tlv.h:297
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
Definition: tlv.h:382
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.
Definition: tlv.h:615
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.
Definition: tlv.h:627
#define LV_GROSS_LEN(x)
gross length of a LV type field
Definition: tlv.h:29
static uint16_t VTVLV_GAN_GROSS_LEN(uint16_t tag, uint16_t len)
gross length of vTvLV (tag+len+val)
Definition: tlv.h:78
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.
Definition: tlv_parser.c:612
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.
Definition: tlv_parser.c:369
static uint8_t tlvp_val8(const struct tlv_parsed *tp, uint8_t tag, uint8_t default_val)
Obtain 1-byte TLV element.
Definition: tlv.h:600
static uint32_t tlvp_val32be(const struct tlv_parsed *tp, int pos)
Retrieve (possibly unaligned) TLV element and convert to host byte order.
Definition: tlv.h:649
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
Definition: tlv_parser.c:659
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
Definition: tlv.h:358
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.
Definition: tlv_parser.c:729
static uint16_t VTVL_GAN_GROSS_LEN(uint16_t tag, uint16_t len)
gross length of vTvL header (tag+len)
Definition: tlv.h:64
static uint8_t * t16lv_put(uint8_t *buf, uint16_t tag, uint8_t len, const uint8_t *val)
put (append) a TL16V field
Definition: tlv.h:164
static uint16_t TVLV_GROSS_LEN(uint16_t len)
gross length of a TVLV type field
Definition: tlv.h:55
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'
Definition: tlv_parser.c:449
static uint8_t * msgb_tv_put(struct msgb *msg, uint8_t tag, uint8_t val)
put (append) a TV field to a Message buffers
Definition: tlv.h:374
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.
Definition: tlv.h:111
static uint8_t * msgb_v_put(struct msgb *msg, uint8_t val)
put (append) a V field to a Message buffers
Definition: tlv.h:391
static uint8_t * tl16v_put(uint8_t *buf, uint8_t tag, uint16_t len, const uint8_t *val)
put (append) a TL16V field
Definition: tlv.h:144
static uint8_t * msgb_vtvl_gan_push(struct msgb *msg, uint16_t tag, uint16_t len)
Definition: tlv.h:482
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
Definition: tlv.h:243
#define TLV16_GROSS_LEN(x)
gross length of a TLV16 type field
Definition: tlv.h:33
#define L16TV_GROSS_LEN(x)
gross length of a L16TV type field
Definition: tlv.h:37
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).
Definition: tlv.h:126
static uint8_t * msgb_tlv1_push(struct msgb *msg, uint8_t tag, uint8_t val)
push 1-byte tagged value
Definition: tlv.h:437
int osmo_tlvp_merge(struct tlv_parsed *dst, const struct tlv_parsed *src)
Merge all tlv_parsed attributes of 'src' into 'dst'.
Definition: tlv_parser.c:105
static uint8_t * msgb_vtvlv_gan_push(struct msgb *msg, uint16_t tag, uint16_t len, const uint8_t *val)
Definition: tlv.h:491
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.
Definition: tlv_parser.c:346
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.
Definition: tlv.h:268
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.
Definition: tlv_parser.c:572
struct tlv_definition tvlv_att_def
Definition: tlv_parser.c:49
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
Definition: tlv.h:411
static uint8_t * tl16_put(uint8_t *buf, uint8_t tag, uint16_t len)
put (append) a TL16 field.
Definition: tlv.h:155
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
Definition: tlv.h:366
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.
Definition: tlv.h:290
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
Definition: tlv.h:419
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.
Definition: tlv_parser.c:677
static uint8_t * msgb_tv32_push(struct msgb *msg, uint8_t tag, uint32_t val)
push (prepend) a TV32 field to a Message buffers
Definition: tlv.h:462
static uint8_t * msgb_tv_push(struct msgb *msg, uint8_t tag, uint8_t val)
push (prepend) a TV field to a Message buffers
Definition: tlv.h:444
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
Definition: tlv.h:429
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.
Definition: tlv.h:283
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
Definition: tlv.h:305
osmo_tlv_parser_error
error return codes of various TLV parser functions
Definition: tlv.h:45
int osmo_match_shift_tlv(uint8_t **data, size_t *data_len, uint8_t tag, uint8_t **value, size_t *value_len)
Verify TLV header and advance data / subtract length.
Definition: tlv_parser.c:544
#define T16LV_GROSS_LEN(x)
gross length of a T16LV type field
Definition: tlv.h:39
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
Definition: tlv_parser.c:646
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 ...
Definition: tlv.h:193
static uint8_t * tv16_put(uint8_t *buf, uint8_t tag, uint16_t val)
put (append) a TV16 field
Definition: tlv.h:347
static uint8_t * v_put(uint8_t *buf, uint8_t val)
put (append) a V field
Definition: tlv.h:318
#define TLV_GROSS_LEN(x)
gross length of a TLV type field
Definition: tlv.h:31
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
Definition: tlv.h:275
struct tlv_parsed * osmo_tlvp_copy(const struct tlv_parsed *tp_orig, void *ctx)
Copy tlv_parsed using given talloc context.
Definition: tlv_parser.c:70
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.
Definition: tlv_parser.c:132
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
Definition: tlv.h:250
static uint8_t * vt_gan_put(uint8_t *buf, uint16_t tag)
put (append) a variable-length tag or variable-length length *
Definition: tlv.h:207
static uint8_t * tvlv_put(uint8_t *buf, uint8_t tag, uint16_t len, const uint8_t *val)
put (append) a TvLV field
Definition: tlv.h:175
static uint32_t osmo_tlv_prot_msgt_flags(const struct osmo_tlv_prot_def *pdef, uint8_t msg_type)
Definition: tlv.h:712
static uint8_t * msgb_t16lv_put(struct msgb *msg, uint16_t tag, uint8_t len, const uint8_t *val)
Definition: tlv.h:257
static uint8_t * msgb_tv16_push(struct msgb *msg, uint8_t tag, uint16_t val)
push (prepend) a TV16 field to a Message buffers
Definition: tlv.h:453
static uint8_t * msgb_tl_put(struct msgb *msg, uint8_t tag)
put (append) a TL fields to a Message buffers
Definition: tlv.h:399
@ TLV_TYPE_TLV
tag-length-value
Definition: tlv.h:513
@ TLV_TYPE_TV
tag-value (8bit)
Definition: tlv.h:512
@ TLV_TYPE_FIXED
fixed-length value-only
Definition: tlv.h:510
@ TLV_TYPE_TvLV
tag, variable length, value
Definition: tlv.h:515
@ TLV_TYPE_NONE
no type
Definition: tlv.h:509
@ TLV_TYPE_TL16V
tag, 16 bit length, value
Definition: tlv.h:514
@ TLV_TYPE_SINGLE_TV
tag and value (both 4 bit) in 1 byte
Definition: tlv.h:516
@ TLV_TYPE_T
tag-only
Definition: tlv.h:511
@ TLV_TYPE_vTvLV_GAN
variable-length tag, variable-length length
Definition: tlv.h:517
@ OSMO_TLVP_ERR_MAND_IE_MISSING
Definition: tlv.h:50
@ OSMO_TLVP_ERR_UNKNOWN_TLV_TYPE
Definition: tlv.h:48
@ OSMO_TLVP_ERR_OFS_BEYOND_BUFFER
Definition: tlv.h:46
@ OSMO_TLVP_ERR_IE_TOO_SHORT
Definition: tlv.h:51
@ OSMO_TLVP_ERR_OFS_LEN_BEYOND_BUFFER
Definition: tlv.h:47
uint8_t msg_type
Definition: gsm_04_08.h:2
uint8_t type
Definition: gsm_04_08_gprs.h:7
uint8_t len
Definition: gsm_04_11.h:0
uint8_t msg[0]
Definition: gsm_08_08.h:8
uint8_t iei
Definition: gsm_08_58.h:2
Osmocom TLV protocol definition.
Definition: tlv.h:688
struct osmo_tlv_prot_ie_def ie_def[256]
definition of IE for each 8-bit tag
Definition: tlv.h:696
const struct tlv_definition * tlv_def
TLV parser definition (optional)
Definition: tlv.h:692
struct osmo_tlv_prot_msg_def msg_def[256]
definition of each message (8-bit message type)
Definition: tlv.h:694
const struct value_string * msgt_names
value_string array of message type names (legacy, if not populated in msg_def)
Definition: tlv.h:698
const char * name
human-readable name of protocol
Definition: tlv.h:690
const char * name
huamn-readable name (optional)
Definition: tlv.h:684
uint16_t min_len
minimum length of IE value part, in octets
Definition: tlv.h:682
const uint8_t * mand_ies
array of mandatory IEs
Definition: tlv.h:674
const char * name
human-readable name of message type (optional)
Definition: tlv.h:672
uint32_t flags
user-defined flags (like uplink/downlink/...)
Definition: tlv.h:678
uint8_t mand_count
number of entries in 'mand_ies' above
Definition: tlv.h:676
Definition of a single IE (Information Element)
Definition: tlv.h:521
uint8_t fixed_len
length in case of TLV_TYPE_FIXED
Definition: tlv.h:523
enum tlv_type type
TLV type.
Definition: tlv.h:522
Definition of All 256 IE / TLV.
Definition: tlv.h:527
struct tlv_def def[256]
Definition: tlv.h:528
Entry in a TLV parser array.
Definition: tlv.h:502
uint16_t len
length
Definition: tlv.h:503
const uint8_t * val
pointer to value
Definition: tlv.h:504
result of the TLV parser
Definition: tlv.h:532
struct tlv_p_entry lv[256]
Definition: tlv.h:533