6#include <osmocom/core/msgb.h>
27#define LV_GROSS_LEN(x) (x+1)
29#define TLV_GROSS_LEN(x) (x+2)
31#define TLV16_GROSS_LEN(x) ((2*x)+2)
33#define TL16V_GROSS_LEN(x) (x+3)
35#define L16TV_GROSS_LEN(x) (x+3)
38#define TVLV_MAX_ONEBYTE 0x7f
82static inline uint8_t *
lv_put(uint8_t *buf, uint8_t len,
86 memcpy(buf, val, len);
91static inline uint8_t *
tlv_put(uint8_t *buf, uint8_t tag, uint8_t len,
96 memcpy(buf, val, len);
101static inline uint8_t *
tlv16_put(uint8_t *buf, uint8_t tag, uint8_t len,
106 memcpy(buf, val, len*2);
111static inline uint8_t *
tl16v_put(uint8_t *buf, uint8_t tag, uint16_t len,
117 memcpy(buf, val, len);
122static inline uint8_t *
tvlv_put(uint8_t *buf, uint8_t tag, uint16_t len,
128 ret =
tlv_put(buf, tag, len, val);
141 *buf++ = 0x80 | (tag >> 8);
142 *buf++ = (tag & 0xff);
150static inline uint8_t *vtvl_gan_put(uint8_t *buf, uint16_t tag, uint16_t len)
159static inline uint8_t *vtvlv_gan_put(uint8_t *buf, uint16_t tag, uint16_t len,
164 ret = vtvl_gan_put(buf, tag, len );
166 memcpy(ret, val, len);
173static inline uint8_t *
msgb_tlv16_put(
struct msgb *msg, uint8_t tag, uint8_t len,
const uint16_t *val)
180static inline uint8_t *
msgb_tl16v_put(
struct msgb *msg, uint8_t tag, uint16_t len,
188static inline uint8_t *
msgb_tvlv_put(
struct msgb *msg, uint8_t tag, uint16_t len,
192 return tvlv_put(buf, tag, len, val);
197 uint16_t len,
const uint8_t *val)
200 return vtvlv_gan_put(buf, tag, len, val);
204static inline uint8_t *
msgb_l16tv_put(
struct msgb *msg, uint16_t len, uint8_t tag,
212 memcpy(buf, val, len);
217static inline uint8_t *
v_put(uint8_t *buf, uint8_t val)
224static inline uint8_t *
tv_put(uint8_t *buf, uint8_t tag,
234 unsigned int len,
const uint8_t *val)
237 memcpy(buf, val, len);
246static inline uint8_t *
tv16_put(uint8_t *buf, uint8_t tag,
257static inline uint8_t *
msgb_lv_put(
struct msgb *msg, uint8_t len,
const uint8_t *val)
260 return lv_put(buf, len, val);
265static inline uint8_t *
msgb_tlv_put(
struct msgb *msg, uint8_t tag, uint8_t len,
const uint8_t *val)
268 return tlv_put(buf, tag, len, val);
273static inline uint8_t *
msgb_tv_put(
struct msgb *msg, uint8_t tag, uint8_t val)
275 uint8_t *buf = msgb_put(msg, 2);
276 return tv_put(buf, tag, val);
282 unsigned int len,
const uint8_t *val)
284 uint8_t *buf = msgb_put(msg, 1+len);
290static inline uint8_t *
msgb_v_put(
struct msgb *msg, uint8_t val)
292 uint8_t *buf = msgb_put(msg, 1);
293 return v_put(buf, val);
298static inline uint8_t *
msgb_tv16_put(
struct msgb *msg, uint8_t tag, uint16_t val)
300 uint8_t *buf = msgb_put(msg, 3);
306static inline uint8_t *
msgb_tlv_push(
struct msgb *msg, uint8_t tag, uint8_t len,
const uint8_t *val)
315static inline uint8_t *
msgb_tv_push(
struct msgb *msg, uint8_t tag, uint8_t val)
317 uint8_t *buf = msgb_push(msg, 2);
324static inline uint8_t *
msgb_tv16_push(
struct msgb *msg, uint8_t tag, uint16_t val)
326 uint8_t *buf = msgb_push(msg, 3);
333static inline uint8_t *
msgb_tvlv_push(
struct msgb *msg, uint8_t tag, uint16_t len,
343static inline uint8_t *msgb_vtvl_gan_push(
struct msgb *msg, uint16_t tag,
347 vtvl_gan_put(buf, tag, len);
352static inline uint8_t *msgb_vtvlv_gan_push(
struct msgb *msg, uint16_t tag,
353 uint16_t len,
const uint8_t *val)
356 vtvlv_gan_put(buf, tag, len, val);
400int tlv_parse_one(uint8_t *o_tag, uint16_t *o_len,
const uint8_t **o_val,
402 const uint8_t *buf,
int buf_len);
404 const uint8_t *buf,
int buf_len, uint8_t lv_tag, uint8_t lv_tag2);
408#define TLVP_PRESENT(x, y) ((x)->lv[y].val)
409#define TLVP_LEN(x, y) (x)->lv[y].len
410#define TLVP_VAL(x, y) (x)->lv[y].val
412#define TLVP_PRES_LEN(tp, tag, min_len) \
413 (TLVP_PRESENT(tp, tag) && TLVP_LEN(tp, tag) >= min_len)
423 memcpy(&res, TLVP_VAL(tp, pos),
sizeof(res));
435 memcpy(&res, TLVP_VAL(tp, pos),
sizeof(res));
442 size_t len, uint8_t **value);
444 uint8_t tag,
size_t len, uint8_t **value);
446 uint8_t *tag, uint8_t **value,
size_t *value_len);
448 uint8_t tag, uint8_t **value,
size_t *value_len);
450 uint8_t **value,
size_t *value_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 msgb
Definition tlv.h:333
int osmo_shift_v_fixed(uint8_t **data, size_t *data_len, size_t len, uint8_t **value)
Definition tlv_parser.c:295
#define TL16V_GROSS_LEN(x)
gross length of a TL16V type field
Definition tlv.h:33
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:101
#define TVLV_MAX_ONEBYTE
maximum length of TLV of one byte length
Definition tlv.h:38
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:233
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:115
tlv_type
TLV type.
Definition tlv.h:369
int osmo_match_shift_tv_fixed(uint8_t **data, size_t *data_len, uint8_t tag, size_t len, uint8_t **value)
Definition tlv_parser.c:323
static uint8_t * lv_put(uint8_t *buf, uint8_t len, const uint8_t *val)
put (append) a LV field
Definition tlv.h:82
static uint8_t * tv_put(uint8_t *buf, uint8_t tag, uint8_t val)
put (append) a TV field
Definition tlv.h:224
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
Definition tlv.h:196
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
Definition tlv.h:281
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:420
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:432
#define LV_GROSS_LEN(x)
gross length of a LV type field
Definition tlv.h:27
static uint16_t VTVLV_GAN_GROSS_LEN(uint16_t tag, uint16_t len)
gross length of vTvLV (tag+len+val)
Definition tlv.h:64
int osmo_shift_lv(uint8_t **data, size_t *data_len, uint8_t **value, size_t *value_len)
Definition tlv_parser.c:429
int osmo_match_shift_tlv(uint8_t **data, size_t *data_len, uint8_t tag, uint8_t **value, size_t *value_len)
Definition tlv_parser.c:361
static uint8_t * msgb_lv_put(struct msgb *msg, uint8_t len, const uint8_t *val)
put (append) a LV field to a msgb
Definition tlv.h:257
static uint16_t VTVL_GAN_GROSS_LEN(uint16_t tag, uint16_t len)
gross length of vTvL header (tag+len)
Definition tlv.h:50
static uint16_t TVLV_GROSS_LEN(uint16_t len)
gross length of a TVLV type field
Definition tlv.h:41
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'
Definition tlv_parser.c:266
static uint8_t * msgb_tv_put(struct msgb *msg, uint8_t tag, uint8_t val)
put (append) a TV field to a msgb
Definition tlv.h:273
static uint8_t * tlv_put(uint8_t *buf, uint8_t tag, uint8_t len, const uint8_t *val)
put (append) a TLV field
Definition tlv.h:91
static uint8_t * msgb_v_put(struct msgb *msg, uint8_t val)
put (append) a V field to a msgb
Definition tlv.h:290
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:111
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
Definition tlv.h:173
#define TLV16_GROSS_LEN(x)
gross length of a TLV16 type field
Definition tlv.h:31
#define L16TV_GROSS_LEN(x)
gross length of a L16TV type field
Definition tlv.h:35
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:87
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:215
int osmo_shift_tlv(uint8_t **data, size_t *data_len, uint8_t *tag, uint8_t **value, size_t *value_len)
Definition tlv_parser.c:389
static uint8_t * msgb_tv16_put(struct msgb *msg, uint8_t tag, uint16_t val)
put (append) a TV16 field to a msgb
Definition tlv.h:298
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
Definition tlv.h:265
static uint8_t * msgb_tv_push(struct msgb *msg, uint8_t tag, uint8_t val)
push (prepend) a TV field to a msgb
Definition tlv.h:315
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
Definition tlv.h:306
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
Definition tlv.h:204
static uint8_t * tv16_put(uint8_t *buf, uint8_t tag, uint16_t val)
put (append) a TV16 field
Definition tlv.h:246
static uint8_t * v_put(uint8_t *buf, uint8_t val)
put (append) a V field
Definition tlv.h:217
#define TLV_GROSS_LEN(x)
gross length of a TLV type field
Definition tlv.h:29
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
Definition tlv.h:188
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:52
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
Definition tlv.h:180
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:137
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:122
static uint8_t * msgb_tv16_push(struct msgb *msg, uint8_t tag, uint16_t val)
push (prepend) a TV16 field to a msgb
Definition tlv.h:324
@ TLV_TYPE_TLV
tag-length-value
Definition tlv.h:374
@ TLV_TYPE_TV
tag-value (8bit)
Definition tlv.h:373
@ TLV_TYPE_FIXED
fixed-length value-only
Definition tlv.h:371
@ TLV_TYPE_TvLV
tag, variable length, value
Definition tlv.h:376
@ TLV_TYPE_NONE
no type
Definition tlv.h:370
@ TLV_TYPE_TL16V
tag, 16 bit length, value
Definition tlv.h:375
@ TLV_TYPE_SINGLE_TV
tag and value (both 4 bit) in 1 byte
Definition tlv.h:377
@ TLV_TYPE_T
tag-only
Definition tlv.h:372
@ TLV_TYPE_vTvLV_GAN
variable-length tag, variable-length length
Definition tlv.h:378
Definition of a single IE (Information Element)
Definition tlv.h:382
uint8_t fixed_len
length in case of TLV_TYPE_FIXED
Definition tlv.h:384
enum tlv_type type
TLV type.
Definition tlv.h:383
Definition of All 256 IE / TLV.
Definition tlv.h:388
Entry in a TLV parser array.
Definition tlv.h:363
uint16_t len
length
Definition tlv.h:364
const uint8_t * val
pointer to value
Definition tlv.h:365
result of the TLV parser
Definition tlv.h:393