libosmogsm  1.3.1
Osmocom GSM library
tlv.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stdint.h>
4 #include <string.h>
5 
6 #include <osmocom/core/msgb.h>
9 
14 /* Terminology / wording
15  tag length value (in bits)
16 
17  V - - 8
18  LV - 8 N * 8
19  TLV 8 8 N * 8
20  TL16V 8 16 N * 8
21  TLV16 8 8 N * 16
22  TvLV 8 8/16 N * 8
23  vTvLV 8/16 8/16 N * 8
24  T16LV 16 8 N * 8
25 */
26 
28 #define LV_GROSS_LEN(x) (x+1)
29 
30 #define TLV_GROSS_LEN(x) (x+2)
31 
32 #define TLV16_GROSS_LEN(x) ((2*x)+2)
33 
34 #define TL16V_GROSS_LEN(x) (x+3)
35 
36 #define L16TV_GROSS_LEN(x) (x+3)
37 
38 #define T16LV_GROSS_LEN(x) (x+3)
39 
41 #define TVLV_MAX_ONEBYTE 0x7f
42 
44 static inline uint16_t TVLV_GROSS_LEN(uint16_t len)
45 {
46  if (len <= TVLV_MAX_ONEBYTE)
47  return TLV_GROSS_LEN(len);
48  else
49  return TL16V_GROSS_LEN(len);
50 }
51 
53 static inline uint16_t VTVL_GAN_GROSS_LEN(uint16_t tag, uint16_t len)
54 {
55  uint16_t ret = 2;
56 
57  if (tag > TVLV_MAX_ONEBYTE)
58  ret++;
59 
60  if (len > TVLV_MAX_ONEBYTE)
61  ret++;
62 
63  return ret;
64 }
65 
67 static inline uint16_t VTVLV_GAN_GROSS_LEN(uint16_t tag, uint16_t len)
68 {
69  uint16_t ret;
70 
71  if (len <= TVLV_MAX_ONEBYTE)
72  ret = TLV_GROSS_LEN(len);
73  else
74  ret = TL16V_GROSS_LEN(len);
75 
76  if (tag > TVLV_MAX_ONEBYTE)
77  ret += 1;
78 
79  return ret;
80 }
81 
82 /* TLV generation */
83 
85 static inline uint8_t *lv_put(uint8_t *buf, uint8_t len,
86  const uint8_t *val)
87 {
88  *buf++ = len;
89  memcpy(buf, val, len);
90  return buf + len;
91 }
92 
100 static inline uint8_t *tlv_put(uint8_t *buf, uint8_t tag, uint8_t len,
101  const uint8_t *val)
102 {
103  *buf++ = tag;
104  *buf++ = len;
105  if (len) {
106  if (val)
107  memcpy(buf, val, len);
108  else
109  memset(buf, 0, len);
110  }
111  return buf + len;
112 }
113 
115 static inline uint8_t *tlv16_put(uint8_t *buf, uint8_t tag, uint8_t len,
116  const uint16_t *val)
117 {
118  *buf++ = tag;
119  *buf++ = len;
120  memcpy(buf, val, len*2);
121  return buf + len*2;
122 }
123 
125 static inline uint8_t *tl16v_put(uint8_t *buf, uint8_t tag, uint16_t len,
126  const uint8_t *val)
127 {
128  *buf++ = tag;
129  *buf++ = len >> 8;
130  *buf++ = len & 0xff;
131  memcpy(buf, val, len);
132  return buf + len*2;
133 }
134 
136 static inline uint8_t *t16lv_put(uint8_t *buf, uint16_t tag, uint8_t len,
137  const uint8_t *val)
138 {
139  *buf++ = tag >> 8;
140  *buf++ = tag & 0xff;
141  *buf++ = len;
142  memcpy(buf, val, len);
143  return buf + len + 2;
144 }
145 
147 static inline uint8_t *tvlv_put(uint8_t *buf, uint8_t tag, uint16_t len,
148  const uint8_t *val)
149 {
150  uint8_t *ret;
151 
152  if (len <= TVLV_MAX_ONEBYTE) {
153  ret = tlv_put(buf, tag, len, val);
154  buf[1] |= 0x80;
155  } else
156  ret = tl16v_put(buf, tag, len, val);
157 
158  return ret;
159 }
160 
162 static inline uint8_t *vt_gan_put(uint8_t *buf, uint16_t tag)
163 {
164  if (tag > TVLV_MAX_ONEBYTE) {
165  /* two-byte TAG */
166  *buf++ = 0x80 | (tag >> 8);
167  *buf++ = (tag & 0xff);
168  } else
169  *buf++ = tag;
170 
171  return buf;
172 }
173 
174 /* put (append) vTvL (GAN) field (tag + length)*/
175 static inline uint8_t *vtvl_gan_put(uint8_t *buf, uint16_t tag, uint16_t len)
176 {
177  uint8_t *ret;
178 
179  ret = vt_gan_put(buf, tag);
180  return vt_gan_put(ret, len);
181 }
182 
183 /* put (append) vTvLV (GAN) field (tag + length + val) */
184 static inline uint8_t *vtvlv_gan_put(uint8_t *buf, uint16_t tag, uint16_t len,
185  const uint8_t *val)
186 {
187  uint8_t *ret;
188 
189  ret = vtvl_gan_put(buf, tag, len );
190 
191  memcpy(ret, val, len);
192  ret = buf + len;
193 
194  return ret;
195 }
196 
198 static inline uint8_t *msgb_tlv16_put(struct msgb *msg, uint8_t tag, uint8_t len, const uint16_t *val)
199 {
200  uint8_t *buf = msgb_put(msg, TLV16_GROSS_LEN(len));
201  return tlv16_put(buf, tag, len, val);
202 }
203 
205 static inline uint8_t *msgb_tl16v_put(struct msgb *msg, uint8_t tag, uint16_t len,
206  const uint8_t *val)
207 {
208  uint8_t *buf = msgb_put(msg, TL16V_GROSS_LEN(len));
209  return tl16v_put(buf, tag, len, val);
210 }
211 
212 static inline uint8_t *msgb_t16lv_put(struct msgb *msg, uint16_t tag, uint8_t len, const uint8_t *val)
213 {
214  uint8_t *buf = msgb_put(msg, T16LV_GROSS_LEN(len));
215  return t16lv_put(buf, tag, len, val);
216 }
217 
219 static inline uint8_t *msgb_tvlv_put(struct msgb *msg, uint8_t tag, uint16_t len,
220  const uint8_t *val)
221 {
222  uint8_t *buf = msgb_put(msg, TVLV_GROSS_LEN(len));
223  return tvlv_put(buf, tag, len, val);
224 }
225 
227 static inline uint8_t *msgb_vtvlv_gan_put(struct msgb *msg, uint16_t tag,
228  uint16_t len, const uint8_t *val)
229 {
230  uint8_t *buf = msgb_put(msg, VTVLV_GAN_GROSS_LEN(tag, len));
231  return vtvlv_gan_put(buf, tag, len, val);
232 }
233 
235 static inline uint8_t *msgb_l16tv_put(struct msgb *msg, uint16_t len, uint8_t tag,
236  const uint8_t *val)
237 {
238  uint8_t *buf = msgb_put(msg, L16TV_GROSS_LEN(len));
239 
240  *buf++ = len >> 8;
241  *buf++ = len & 0xff;
242  *buf++ = tag;
243  memcpy(buf, val, len);
244  return buf + len;
245 }
246 
248 static inline uint8_t *v_put(uint8_t *buf, uint8_t val)
249 {
250  *buf++ = val;
251  return buf;
252 }
253 
255 static inline uint8_t *tv_put(uint8_t *buf, uint8_t tag,
256  uint8_t val)
257 {
258  *buf++ = tag;
259  *buf++ = val;
260  return buf;
261 }
262 
264 static inline uint8_t *tv_fixed_put(uint8_t *buf, uint8_t tag,
265  unsigned int len, const uint8_t *val)
266 {
267  *buf++ = tag;
268  memcpy(buf, val, len);
269  return buf + len;
270 }
271 
277 static inline uint8_t *tv16_put(uint8_t *buf, uint8_t tag,
278  uint16_t val)
279 {
280  *buf++ = tag;
281  *buf++ = val >> 8;
282  *buf++ = val & 0xff;
283  return buf;
284 }
285 
288 static inline uint8_t *msgb_lv_put(struct msgb *msg, uint8_t len, const uint8_t *val)
289 {
290  uint8_t *buf = msgb_put(msg, LV_GROSS_LEN(len));
291  return lv_put(buf, len, val);
292 }
293 
296 static inline uint8_t *msgb_tlv_put(struct msgb *msg, uint8_t tag, uint8_t len, const uint8_t *val)
297 {
298  uint8_t *buf = msgb_put(msg, TLV_GROSS_LEN(len));
299  return tlv_put(buf, tag, len, val);
300 }
301 
304 static inline uint8_t *msgb_tv_put(struct msgb *msg, uint8_t tag, uint8_t val)
305 {
306  uint8_t *buf = msgb_put(msg, 2);
307  return tv_put(buf, tag, val);
308 }
309 
312 static inline uint8_t *msgb_tv_fixed_put(struct msgb *msg, uint8_t tag,
313  unsigned int len, const uint8_t *val)
314 {
315  uint8_t *buf = msgb_put(msg, 1+len);
316  return tv_fixed_put(buf, tag, len, val);
317 }
318 
321 static inline uint8_t *msgb_v_put(struct msgb *msg, uint8_t val)
322 {
323  uint8_t *buf = msgb_put(msg, 1);
324  return v_put(buf, val);
325 }
326 
329 static inline uint8_t *msgb_tl_put(struct msgb *msg, uint8_t tag)
330 {
331  uint8_t *len = msgb_v_put(msg, tag);
332 
333  /* reserve space for length, len points to this reserved space already */
334  msgb_v_put(msg, 0);
335 
336  return len;
337 }
338 
341 static inline uint8_t *msgb_tv16_put(struct msgb *msg, uint8_t tag, uint16_t val)
342 {
343  uint8_t *buf = msgb_put(msg, 3);
344  return tv16_put(buf, tag, val);
345 }
346 
349 static inline uint8_t *msgb_tlv_push(struct msgb *msg, uint8_t tag, uint8_t len, const uint8_t *val)
350 {
351  uint8_t *buf = msgb_push(msg, TLV_GROSS_LEN(len));
352  tlv_put(buf, tag, len, val);
353  return buf;
354 }
355 
357 static inline uint8_t *msgb_tlv1_push(struct msgb *msg, uint8_t tag, uint8_t val)
358 {
359  return msgb_tlv_push(msg, tag, 1, &val);
360 }
361 
364 static inline uint8_t *msgb_tv_push(struct msgb *msg, uint8_t tag, uint8_t val)
365 {
366  uint8_t *buf = msgb_push(msg, 2);
367  tv_put(buf, tag, val);
368  return buf;
369 }
370 
373 static inline uint8_t *msgb_tv16_push(struct msgb *msg, uint8_t tag, uint16_t val)
374 {
375  uint8_t *buf = msgb_push(msg, 3);
376  tv16_put(buf, tag, val);
377  return buf;
378 }
379 
382 static inline uint8_t *msgb_tvlv_push(struct msgb *msg, uint8_t tag, uint16_t len,
383  const uint8_t *val)
384 {
385  uint8_t *buf = msgb_push(msg, TVLV_GROSS_LEN(len));
386  tvlv_put(buf, tag, len, val);
387  return buf;
388 }
389 
390 /* push (prepend) a vTvL header to a \ref msgb
391  */
392 static inline uint8_t *msgb_vtvl_gan_push(struct msgb *msg, uint16_t tag,
393  uint16_t len)
394 {
395  uint8_t *buf = msgb_push(msg, VTVL_GAN_GROSS_LEN(tag, len));
396  vtvl_gan_put(buf, tag, len);
397  return buf;
398 }
399 
400 
401 static inline uint8_t *msgb_vtvlv_gan_push(struct msgb *msg, uint16_t tag,
402  uint16_t len, const uint8_t *val)
403 {
404  uint8_t *buf = msgb_push(msg, VTVLV_GAN_GROSS_LEN(tag, len));
405  vtvlv_gan_put(buf, tag, len, val);
406  return buf;
407 }
408 
409 /* TLV parsing */
410 
412 struct tlv_p_entry {
413  uint16_t len;
414  const uint8_t *val;
415 };
416 
418 enum tlv_type {
428 };
429 
431 struct tlv_def {
432  enum tlv_type type;
433  uint8_t fixed_len;
434 };
435 
438  struct tlv_def def[256];
439 };
440 
442 struct tlv_parsed {
443  struct tlv_p_entry lv[256];
444 };
445 
446 extern struct tlv_definition tvlv_att_def;
447 extern struct tlv_definition vtvlv_gan_att_def;
448 
449 int tlv_parse_one(uint8_t *o_tag, uint16_t *o_len, const uint8_t **o_val,
450  const struct tlv_definition *def,
451  const uint8_t *buf, int buf_len);
452 int tlv_parse(struct tlv_parsed *dec, const struct tlv_definition *def,
453  const uint8_t *buf, int buf_len, uint8_t lv_tag, uint8_t lv_tag2);
454 int tlv_parse2(struct tlv_parsed *dec, int dec_multiples,
455  const struct tlv_definition *def, const uint8_t *buf, int buf_len,
456  uint8_t lv_tag, uint8_t lv_tag2);
457 /* take a master (src) tlv def and fill up all empty slots in 'dst' */
458 void tlv_def_patch(struct tlv_definition *dst, const struct tlv_definition *src);
459 
460 int tlv_encode_one(struct msgb *msg, enum tlv_type type, uint8_t tag,
461  unsigned int len, const uint8_t *val);
462 int tlv_encode(struct msgb *msg, const struct tlv_definition *def, const struct tlv_parsed *tp);
463 int tlv_encode_ordered(struct msgb *msg, const struct tlv_definition *def, const struct tlv_parsed *tp,
464  const uint8_t *tag_order, unsigned int tag_order_len);
465 
466 #define TLVP_PRESENT(x, y) ((x)->lv[y].val)
467 #define TLVP_LEN(x, y) (x)->lv[y].len
468 #define TLVP_VAL(x, y) (x)->lv[y].val
469 
470 #define TLVP_PRES_LEN(tp, tag, min_len) \
471  (TLVP_PRESENT(tp, tag) && TLVP_LEN(tp, tag) >= min_len)
472 
483 #define TLVP_GET(_tp, tag) (TLVP_PRESENT(_tp, tag)? &(_tp)->lv[tag] : NULL)
484 
491 #define TLVP_GET_MINLEN(_tp, tag, min_len) \
492  (TLVP_PRES_LEN(_tp, tag, min_len)? &(_tp)->lv[tag] : NULL)
493 
500 #define TLVP_VAL_MINLEN(_tp, tag, min_len) \
501  (TLVP_PRES_LEN(_tp, tag, min_len)? (_tp)->lv[tag].val : NULL)
502 
503 
510 static inline uint8_t tlvp_val8(const struct tlv_parsed *tp, uint8_t tag, uint8_t default_val)
511 {
512  const uint8_t *res = TLVP_VAL_MINLEN(tp, tag, 1);
513 
514  if (res)
515  return res[0];
516 
517  return default_val;
518 }
519 
525 static inline uint16_t tlvp_val16_unal(const struct tlv_parsed *tp, int pos)
526 {
527  uint16_t res;
528  memcpy(&res, TLVP_VAL(tp, pos), sizeof(res));
529  return res;
530 }
531 
537 static inline uint32_t tlvp_val32_unal(const struct tlv_parsed *tp, int pos)
538 {
539  uint32_t res;
540  memcpy(&res, TLVP_VAL(tp, pos), sizeof(res));
541  return res;
542 }
543 
549 static inline uint16_t tlvp_val16be(const struct tlv_parsed *tp, int pos)
550 {
551  return osmo_load16be(TLVP_VAL(tp, pos));
552 }
553 
559 static inline uint32_t tlvp_val32be(const struct tlv_parsed *tp, int pos)
560 {
561  return osmo_load32be(TLVP_VAL(tp, pos));
562 }
563 
564 
565 struct tlv_parsed *osmo_tlvp_copy(const struct tlv_parsed *tp_orig, void *ctx);
566 int osmo_tlvp_merge(struct tlv_parsed *dst, const struct tlv_parsed *src);
567 int osmo_shift_v_fixed(uint8_t **data, size_t *data_len,
568  size_t len, uint8_t **value);
569 int osmo_match_shift_tv_fixed(uint8_t **data, size_t *data_len,
570  uint8_t tag, size_t len, uint8_t **value);
571 int osmo_shift_tlv(uint8_t **data, size_t *data_len,
572  uint8_t *tag, uint8_t **value, size_t *value_len);
573 int osmo_match_shift_tlv(uint8_t **data, size_t *data_len,
574  uint8_t tag, uint8_t **value, size_t *value_len);
575 int osmo_shift_lv(uint8_t **data, size_t *data_len,
576  uint8_t **value, size_t *value_len);
577 
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:364
static unsigned char * msgb_put(struct msgb *msgb, unsigned int len)
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 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:549
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:373
uint8_t type
Definition: gsm_08_08.h:469
static uint8_t * tv_put(uint8_t *buf, uint8_t tag, uint8_t val)
put (append) a TV field
Definition: tlv.h:255
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:235
uint16_t len
length
Definition: tlv.h:413
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
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:510
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:198
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:304
static uint8_t * msgb_tlv1_push(struct msgb *msg, uint8_t tag, uint8_t val)
push 1-byte tagged value
Definition: tlv.h:357
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
struct tlv_definition tvlv_att_def
Definition: tlv_parser.c:48
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:382
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:559
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 uint16_t TVLV_GROSS_LEN(uint16_t len)
gross length of a TVLV type field
Definition: tlv.h:44
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:162
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:147
static uint8_t * lv_put(uint8_t *buf, uint8_t len, const uint8_t *val)
put (append) a LV field
Definition: tlv.h:85
static uint8_t * msgb_vtvl_gan_push(struct msgb *msg, uint16_t tag, uint16_t len)
Definition: tlv.h:392
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
Entry in a TLV parser array.
Definition: tlv.h:412
#define TLV_GROSS_LEN(x)
gross length of a TLV type field
Definition: tlv.h:30
tag-value (8bit)
Definition: tlv.h:422
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:264
#define TL16V_GROSS_LEN(x)
gross length of a TL16V type field
Definition: tlv.h:34
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
no type
Definition: tlv.h:419
#define TVLV_MAX_ONEBYTE
maximum length of TLV of one byte length
Definition: tlv.h:41
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:227
static uint16_t VTVL_GAN_GROSS_LEN(uint16_t tag, uint16_t len)
gross length of vTvL header (tag+len)
Definition: tlv.h:53
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:341
#define TLV16_GROSS_LEN(x)
gross length of a TLV16 type field
Definition: tlv.h:32
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
Definition of a single IE (Information Element)
Definition: tlv.h:431
uint8_t data[0]
#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:125
static unsigned char * msgb_push(struct msgb *msgb, unsigned int len)
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:296
static uint8_t * tv16_put(uint8_t *buf, uint8_t tag, uint16_t val)
put (append) a TV16 field
Definition: tlv.h:277
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:525
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:115
uint8_t res
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
tag-length-value
Definition: tlv.h:423
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:312
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 * vtvl_gan_put(uint8_t *buf, uint16_t tag, uint16_t len)
Definition: tlv.h:175
uint8_t len
Definition: gsm_04_11.h:465
tlv_type
TLV type.
Definition: tlv.h:418
static uint8_t * v_put(uint8_t *buf, uint8_t val)
put (append) a V field
Definition: tlv.h:248
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:205
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
variable-length tag, variable-length length
Definition: tlv.h:427
tag, 16 bit length, value
Definition: tlv.h:424
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
#define T16LV_GROSS_LEN(x)
gross length of a T16LV type field
Definition: tlv.h:38
result of the TLV parser
Definition: tlv.h:442
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:136
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
uint8_t fixed_len
length in case of TLV_TYPE_FIXED
Definition: tlv.h:433
fixed-length value-only
Definition: tlv.h:420
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 &#39;dst&#39;
Definition: tlv_parser.c:437
static uint8_t * msgb_vtvlv_gan_push(struct msgb *msg, uint16_t tag, uint16_t len, const uint8_t *val)
Definition: tlv.h:401
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:537
Definition of All 256 IE / TLV.
Definition: tlv.h:437
int osmo_tlvp_merge(struct tlv_parsed *dst, const struct tlv_parsed *src)
Merge all tlv_parsed attributes of &#39;src&#39; into &#39;dst&#39;.
Definition: tlv_parser.c:104
static uint8_t * msgb_tl_put(struct msgb *msg, uint8_t tag)
put (append) a TL fields to a Message buffers
Definition: tlv.h:329
static uint8_t * msgb_v_put(struct msgb *msg, uint8_t val)
put (append) a V field to a Message buffers
Definition: tlv.h:321
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
#define LV_GROSS_LEN(x)
gross length of a LV type field
Definition: tlv.h:28
tag-only
Definition: tlv.h:421
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
tag, variable length, value
Definition: tlv.h:425
const uint8_t * val
pointer to value
Definition: tlv.h:414
#define TLVP_VAL(x, y)
Definition: tlv.h:468
#define TLVP_VAL_MINLEN(_tp, tag, min_len)
Like TLVP_VAL(), but enforcing a minimum val length.
Definition: tlv.h:500
static uint8_t * vtvlv_gan_put(uint8_t *buf, uint16_t tag, uint16_t len, const uint8_t *val)
Definition: tlv.h:184
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:349
struct tlv_definition vtvlv_gan_att_def
Definition: tlv_parser.c:49
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:288
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:219
tag and value (both 4 bit) in 1 byte
Definition: tlv.h:426
static uint8_t * msgb_t16lv_put(struct msgb *msg, uint16_t tag, uint8_t len, const uint8_t *val)
Definition: tlv.h:212