6 #include <osmocom/core/msgb.h>
7 #include <osmocom/core/bit16gen.h>
8 #include <osmocom/core/bit32gen.h>
28 #define LV_GROSS_LEN(x) (x+1)
30 #define TLV_GROSS_LEN(x) (x+2)
32 #define TLV16_GROSS_LEN(x) ((2*x)+2)
34 #define TL16V_GROSS_LEN(x) (x+3)
36 #define L16TV_GROSS_LEN(x) (x+3)
39 #define TVLV_MAX_ONEBYTE 0x7f
83 static inline uint8_t *
lv_put(uint8_t *buf, uint8_t len,
87 memcpy(buf, val, len);
92 static inline uint8_t *
tlv_put(uint8_t *buf, uint8_t tag, uint8_t len,
97 memcpy(buf, val, len);
102 static inline uint8_t *
tlv16_put(uint8_t *buf, uint8_t tag, uint8_t len,
107 memcpy(buf, val, len*2);
112 static inline uint8_t *
tl16v_put(uint8_t *buf, uint8_t tag, uint16_t len,
118 memcpy(buf, val, len);
123 static inline uint8_t *
tvlv_put(uint8_t *buf, uint8_t tag, uint16_t len,
129 ret =
tlv_put(buf, tag, len, val);
138 static inline uint8_t *
vt_gan_put(uint8_t *buf, uint16_t tag)
142 *buf++ = 0x80 | (tag >> 8);
143 *buf++ = (tag & 0xff);
151 static inline uint8_t *
vtvl_gan_put(uint8_t *buf, uint16_t tag, uint16_t len)
160 static inline uint8_t *
vtvlv_gan_put(uint8_t *buf, uint16_t tag, uint16_t len,
167 memcpy(ret, val, len);
174 static inline uint8_t *
msgb_tlv16_put(
struct msgb *msg, uint8_t tag, uint8_t len,
const uint16_t *val)
181 static inline uint8_t *
msgb_tl16v_put(
struct msgb *msg, uint8_t tag, uint16_t len,
189 static inline uint8_t *
msgb_tvlv_put(
struct msgb *msg, uint8_t tag, uint16_t len,
193 return tvlv_put(buf, tag, len, val);
198 uint16_t len,
const uint8_t *val)
205 static inline uint8_t *
msgb_l16tv_put(
struct msgb *msg, uint16_t len, uint8_t tag,
213 memcpy(buf, val, len);
218 static inline uint8_t *
v_put(uint8_t *buf, uint8_t val)
225 static inline uint8_t *
tv_put(uint8_t *buf, uint8_t tag,
235 unsigned int len,
const uint8_t *val)
238 memcpy(buf, val, len);
247 static inline uint8_t *
tv16_put(uint8_t *buf, uint8_t tag,
258 static inline uint8_t *
msgb_lv_put(
struct msgb *msg, uint8_t len,
const uint8_t *val)
261 return lv_put(buf, len, val);
266 static inline uint8_t *
msgb_tlv_put(
struct msgb *msg, uint8_t tag, uint8_t len,
const uint8_t *val)
269 return tlv_put(buf, tag, len, val);
274 static inline uint8_t *
msgb_tv_put(
struct msgb *msg, uint8_t tag, uint8_t val)
276 uint8_t *buf = msgb_put(msg, 2);
277 return tv_put(buf, tag, val);
283 unsigned int len,
const uint8_t *val)
285 uint8_t *buf = msgb_put(msg, 1+len);
291 static inline uint8_t *
msgb_v_put(
struct msgb *msg, uint8_t val)
293 uint8_t *buf = msgb_put(msg, 1);
294 return v_put(buf, val);
299 static inline uint8_t *
msgb_tv16_put(
struct msgb *msg, uint8_t tag, uint16_t val)
301 uint8_t *buf = msgb_put(msg, 3);
307 static inline uint8_t *
msgb_tlv_push(
struct msgb *msg, uint8_t tag, uint8_t len,
const uint8_t *val)
316 static inline uint8_t *
msgb_tv_push(
struct msgb *msg, uint8_t tag, uint8_t val)
318 uint8_t *buf = msgb_push(msg, 2);
325 static inline uint8_t *
msgb_tv16_push(
struct msgb *msg, uint8_t tag, uint16_t val)
327 uint8_t *buf = msgb_push(msg, 3);
334 static inline uint8_t *
msgb_tvlv_push(
struct msgb *msg, uint8_t tag, uint16_t len,
354 uint16_t len,
const uint8_t *val)
401 int tlv_parse_one(uint8_t *o_tag, uint16_t *o_len,
const uint8_t **o_val,
403 const uint8_t *buf,
int buf_len);
405 const uint8_t *buf,
int buf_len, uint8_t lv_tag, uint8_t lv_tag2);
409 #define TLVP_PRESENT(x, y) ((x)->lv[y].val)
410 #define TLVP_LEN(x, y) (x)->lv[y].len
411 #define TLVP_VAL(x, y) (x)->lv[y].val
413 #define TLVP_PRES_LEN(tp, tag, min_len) \
414 (TLVP_PRESENT(tp, tag) && TLVP_LEN(tp, tag) >= min_len)
424 memcpy(&res,
TLVP_VAL(tp, pos),
sizeof(res));
436 memcpy(&res,
TLVP_VAL(tp, pos),
sizeof(res));
447 return osmo_load16be(
TLVP_VAL(tp, pos));
457 return osmo_load32be(
TLVP_VAL(tp, pos));
464 size_t len, uint8_t **value);
466 uint8_t tag,
size_t len, uint8_t **value);
468 uint8_t *tag, uint8_t **value,
size_t *value_len);
470 uint8_t tag, uint8_t **value,
size_t *value_len);
472 uint8_t **value,
size_t *value_len);
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:316
static uint16_t VTVLV_GAN_GROSS_LEN(uint16_t tag, uint16_t len)
gross length of vTvLV (tag+len+val)
Definition: tlv.h:65
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:445
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:325
static uint8_t * tv_put(uint8_t *buf, uint8_t tag, uint8_t val)
put (append) a TV field
Definition: tlv.h:225
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:205
uint16_t len
length
Definition: tlv.h:365
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:311
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:174
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:274
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:129
struct tlv_definition tvlv_att_def
Definition: tlv_parser.c:45
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:334
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:455
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:339
static uint16_t TVLV_GROSS_LEN(uint16_t len)
gross length of a TVLV type field
Definition: tlv.h:42
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:138
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:123
static uint8_t * lv_put(uint8_t *buf, uint8_t len, const uint8_t *val)
put (append) a LV field
Definition: tlv.h:83
static uint8_t * msgb_vtvl_gan_push(struct msgb *msg, uint16_t tag, uint16_t len)
Definition: tlv.h:344
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:405
Entry in a TLV parser array.
Definition: tlv.h:364
#define TLV_GROSS_LEN(x)
gross length of a TLV type field
Definition: tlv.h:30
struct tlv_p_entry lv[256]
Definition: tlv.h:395
tag-value (8bit)
Definition: tlv.h:374
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:234
#define TL16V_GROSS_LEN(x)
gross length of a TL16V type field
Definition: tlv.h:34
no type
Definition: tlv.h:371
#define TVLV_MAX_ONEBYTE
maximum length of TLV of one byte length
Definition: tlv.h:39
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:197
static uint16_t VTVL_GAN_GROSS_LEN(uint16_t tag, uint16_t len)
gross length of vTvL header (tag+len)
Definition: tlv.h:51
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:299
#define TLV16_GROSS_LEN(x)
gross length of a TLV16 type field
Definition: tlv.h:32
Definition of a single IE (Information Element)
Definition: tlv.h:383
#define L16TV_GROSS_LEN(x)
gross length of a L16TV type field
Definition: tlv.h:36
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:112
struct tlv_def def[256]
Definition: tlv.h:390
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:266
enum tlv_type type
TLV type.
Definition: tlv.h:384
static uint8_t * tv16_put(uint8_t *buf, uint8_t tag, uint16_t val)
put (append) a TV16 field
Definition: tlv.h:247
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:421
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:102
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:445
tag-length-value
Definition: tlv.h:375
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:282
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:377
static uint8_t * vtvl_gan_put(uint8_t *buf, uint16_t tag, uint16_t len)
Definition: tlv.h:151
tlv_type
TLV type.
Definition: tlv.h:370
static uint8_t * v_put(uint8_t *buf, uint8_t val)
put (append) a V field
Definition: tlv.h:218
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:181
variable-length tag, variable-length length
Definition: tlv.h:379
tag, 16 bit length, value
Definition: tlv.h:376
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:66
result of the TLV parser
Definition: tlv.h:394
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:92
uint8_t fixed_len
length in case of TLV_TYPE_FIXED
Definition: tlv.h:385
fixed-length value-only
Definition: tlv.h:372
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:282
static uint8_t * msgb_vtvlv_gan_push(struct msgb *msg, uint16_t tag, uint16_t len, const uint8_t *val)
Definition: tlv.h:353
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:433
Definition of All 256 IE / TLV.
Definition: tlv.h:389
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:101
static uint8_t * msgb_v_put(struct msgb *msg, uint8_t val)
put (append) a V field to a msgb
Definition: tlv.h:291
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:229
#define LV_GROSS_LEN(x)
gross length of a LV type field
Definition: tlv.h:28
tag-only
Definition: tlv.h:373
tag, variable length, value
Definition: tlv.h:377
const uint8_t * val
pointer to value
Definition: tlv.h:366
#define TLVP_VAL(x, y)
Definition: tlv.h:411
static uint8_t * vtvlv_gan_put(uint8_t *buf, uint16_t tag, uint16_t len, const uint8_t *val)
Definition: tlv.h:160
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:307
struct tlv_definition vtvlv_gan_att_def
Definition: tlv_parser.c:46
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:258
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:189
tag and value (both 4 bit) in 1 byte
Definition: tlv.h:378