libosmogsm
1.4.0
Osmocom GSM library
|
Go to the documentation of this file.
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)
38 #define T16LV_GROSS_LEN(x) (x+3)
41 #define TVLV_MAX_ONEBYTE 0x7f
85 static inline uint8_t *
lv_put(uint8_t *buf, uint8_t
len,
89 memcpy(buf, val,
len);
100 static inline uint8_t *
tlv_put(uint8_t *buf, uint8_t tag, uint8_t
len,
107 memcpy(buf, val,
len);
115 static inline uint8_t *
tl_put(uint8_t *buf, uint8_t tag, uint8_t
len)
123 static inline uint8_t *
tlv16_put(uint8_t *buf, uint8_t tag, uint8_t
len,
128 memcpy(buf, val,
len*2);
133 static inline uint8_t *
tl16v_put(uint8_t *buf, uint8_t tag, uint16_t
len,
139 memcpy(buf, val,
len);
144 static inline uint8_t *
tl16_put(uint8_t *buf, uint8_t tag, uint16_t
len)
153 static inline uint8_t *
t16lv_put(uint8_t *buf, uint16_t tag, uint8_t
len,
159 memcpy(buf, val,
len);
160 return buf +
len + 2;
164 static inline uint8_t *
tvlv_put(uint8_t *buf, uint8_t tag, uint16_t
len,
182 static inline uint8_t *
tvl_put(uint8_t *buf, uint8_t tag, uint16_t
len)
196 static inline uint8_t *
vt_gan_put(uint8_t *buf, uint16_t tag)
200 *buf++ = 0x80 | (tag >> 8);
201 *buf++ = (tag & 0xff);
225 memcpy(ret, val,
len);
273 uint16_t
len,
const uint8_t *val)
288 memcpy(buf, val,
len);
293 static inline uint8_t *
v_put(uint8_t *buf, uint8_t val)
300 static inline uint8_t *
tv_put(uint8_t *buf, uint8_t tag,
310 unsigned int len,
const uint8_t *val)
313 memcpy(buf, val,
len);
322 static inline uint8_t *
tv16_put(uint8_t *buf, uint8_t tag,
352 return tv_put(buf, tag, val);
358 unsigned int len,
const uint8_t *val)
369 return v_put(buf, val);
447 uint16_t
len,
const uint8_t *val)
494 int tlv_parse_one(uint8_t *o_tag, uint16_t *o_len,
const uint8_t **o_val,
496 const uint8_t *buf,
int buf_len);
498 const uint8_t *buf,
int buf_len, uint8_t lv_tag, uint8_t lv_tag2);
501 uint8_t lv_tag, uint8_t lv_tag2);
506 unsigned int len,
const uint8_t *val);
509 const uint8_t *tag_order,
unsigned int tag_order_len);
511 #define TLVP_PRESENT(x, y) ((x)->lv[y].val)
512 #define TLVP_LEN(x, y) (x)->lv[y].len
513 #define TLVP_VAL(x, y) (x)->lv[y].val
515 #define TLVP_PRES_LEN(tp, tag, min_len) \
516 (TLVP_PRESENT(tp, tag) && TLVP_LEN(tp, tag) >= min_len)
528 #define TLVP_GET(_tp, tag) (TLVP_PRESENT(_tp, tag)? &(_tp)->lv[tag] : NULL)
536 #define TLVP_GET_MINLEN(_tp, tag, min_len) \
537 (TLVP_PRES_LEN(_tp, tag, min_len)? &(_tp)->lv[tag] : NULL)
545 #define TLVP_VAL_MINLEN(_tp, tag, min_len) \
546 (TLVP_PRES_LEN(_tp, tag, min_len)? (_tp)->lv[tag].val : NULL)
596 return osmo_load16be(
TLVP_VAL(tp, pos));
606 return osmo_load32be(
TLVP_VAL(tp, pos));
613 size_t len, uint8_t **value);
615 uint8_t tag,
size_t len, uint8_t **value);
617 uint8_t *tag, uint8_t **value,
size_t *value_len);
619 uint8_t tag, uint8_t **value,
size_t *value_len);
621 uint8_t **value,
size_t *value_len);
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:229
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:280
uint8_t len
Definition: gsm_04_11.h:0
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:594
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:69
const uint8_t * val
pointer to value
Definition: tlv.h:459
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:104
static unsigned char * msgb_put(struct msgb *msgb, unsigned int len)
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:437
#define TLV16_GROSS_LEN(x)
gross length of a TLV16 type field
Definition: tlv.h:32
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:334
struct tlv_definition tvlv_att_def
Definition: tlv_parser.c:48
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:560
uint8_t msg[0]
Definition: gsm_08_08.h:8
@ TLV_TYPE_FIXED
fixed-length value-only
Definition: tlv.h:465
uint16_t len
length
Definition: tlv.h:458
static uint8_t * msgb_v_put(struct msgb *msg, uint8_t val)
put (append) a V field to a Message buffers
Definition: tlv.h:366
static uint8_t * msgb_tv16_put(struct msgb *msg, uint8_t tag, uint16_t val)
put (append) a TV16 field to a Message buffers
Definition: tlv.h:386
#define LV_GROSS_LEN(x)
gross length of a LV type field
Definition: tlv.h:28
@ TLV_TYPE_T
tag-only
Definition: tlv.h:466
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:357
static uint8_t * msgb_vtvl_gan_push(struct msgb *msg, uint16_t tag, uint16_t len)
Definition: tlv.h:437
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:196
static uint16_t VTVLV_GAN_GROSS_LEN(uint16_t tag, uint16_t len)
gross length of vTvLV (tag+len+val)
Definition: tlv.h:67
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:418
#define TL16V_GROSS_LEN(x)
gross length of a TL16V type field
Definition: tlv.h:34
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:115
uint8_t type
Definition: gsm_08_08.h:0
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:555
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:333
Entry in a TLV parser array.
Definition: tlv.h:457
struct tlv_p_entry lv[256]
Definition: tlv.h:488
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:604
@ TLV_TYPE_TLV
tag-length-value
Definition: tlv.h:468
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:257
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:172
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:309
static uint16_t TVLV_GROSS_LEN(uint16_t len)
gross length of a TVLV type field
Definition: tlv.h:44
@ TLV_TYPE_TvLV
tag, variable length, value
Definition: tlv.h:470
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:570
Definition of All 256 IE / TLV.
Definition: tlv.h:482
static unsigned char * msgb_push(struct msgb *msgb, unsigned int len)
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:153
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:100
enum tlv_type type
TLV type.
Definition: tlv.h:477
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:272
static uint8_t * v_put(uint8_t *buf, uint8_t val)
put (append) a V field
Definition: tlv.h:293
Definition of a single IE (Information Element)
Definition: tlv.h:476
static uint16_t VTVL_GAN_GROSS_LEN(uint16_t tag, uint16_t len)
gross length of vTvL header (tag+len)
Definition: tlv.h:53
tlv_type
TLV type.
Definition: tlv.h:463
@ TLV_TYPE_TL16V
tag, 16 bit length, value
Definition: tlv.h:469
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:232
#define L16TV_GROSS_LEN(x)
gross length of a L16TV type field
Definition: tlv.h:36
struct tlv_def def[256]
Definition: tlv.h:483
#define TVLV_MAX_ONEBYTE
maximum length of TLV of one byte length
Definition: tlv.h:41
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:582
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:494
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:341
@ TLV_TYPE_SINGLE_TV
tag and value (both 4 bit) in 1 byte
Definition: tlv.h:471
static uint8_t * vtvl_gan_put(uint8_t *buf, uint16_t tag, uint16_t len)
Definition: tlv.h:209
static uint8_t * msgb_vtvlv_gan_push(struct msgb *msg, uint16_t tag, uint16_t len, const uint8_t *val)
Definition: tlv.h:446
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:239
uint8_t fixed_len
length in case of TLV_TYPE_FIXED
Definition: tlv.h:478
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:394
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:133
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:123
#define TLVP_VAL_MINLEN(_tp, tag, min_len)
Like TLVP_VAL(), but enforcing a minimum val length.
Definition: tlv.h:545
static uint8_t * tv16_put(uint8_t *buf, uint8_t tag, uint16_t val)
put (append) a TV16 field
Definition: tlv.h:322
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:182
@ TLV_TYPE_NONE
no type
Definition: tlv.h:464
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:466
struct tlv_definition vtvlv_gan_att_def
Definition: tlv_parser.c:49
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:198
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:264
static uint8_t * msgb_tlv1_push(struct msgb *msg, uint8_t tag, uint8_t val)
push 1-byte tagged value
Definition: tlv.h:402
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:409
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:131
#define T16LV_GROSS_LEN(x)
gross length of a T16LV type field
Definition: tlv.h:38
static uint8_t * msgb_tl_put(struct msgb *msg, uint8_t tag)
put (append) a TL fields to a Message buffers
Definition: tlv.h:374
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:532
static uint8_t * lv_put(uint8_t *buf, uint8_t len, const uint8_t *val)
put (append) a LV field
Definition: tlv.h:85
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:600
static uint8_t * tv_put(uint8_t *buf, uint8_t tag, uint8_t val)
put (append) a TV field
Definition: tlv.h:300
static uint8_t * tl16_put(uint8_t *buf, uint8_t tag, uint16_t len)
put (append) a TL16 field.
Definition: tlv.h:144
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:357
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:164
static uint8_t * vtvlv_gan_put(uint8_t *buf, uint16_t tag, uint16_t len, const uint8_t *val)
Definition: tlv.h:218
static uint8_t * msgb_t16lv_put(struct msgb *msg, uint16_t tag, uint8_t len, const uint8_t *val)
Definition: tlv.h:246
result of the TLV parser
Definition: tlv.h:487
#define TLV_GROSS_LEN(x)
gross length of a TLV type field
Definition: tlv.h:30
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:349
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:427
@ TLV_TYPE_vTvLV_GAN
variable-length tag, variable-length length
Definition: tlv.h:472
@ TLV_TYPE_TV
tag-value (8bit)
Definition: tlv.h:467
#define TLVP_VAL(x, y)
Definition: tlv.h:513