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
82 static inline uint8_t *
lv_put(uint8_t *buf, uint8_t len,
86 memcpy(buf, val, len);
91 static inline uint8_t *
tlv_put(uint8_t *buf, uint8_t tag, uint8_t len,
96 memcpy(buf, val, len);
101 static inline uint8_t *
tlv16_put(uint8_t *buf, uint8_t tag, uint8_t len,
106 memcpy(buf, val, len*2);
111 static inline uint8_t *
tl16v_put(uint8_t *buf, uint8_t tag, uint16_t len,
117 memcpy(buf, val, len);
122 static inline uint8_t *
tvlv_put(uint8_t *buf, uint8_t tag, uint16_t len,
128 ret =
tlv_put(buf, tag, len, val);
137 static inline uint8_t *
vt_gan_put(uint8_t *buf, uint16_t tag)
141 *buf++ = 0x80 | (tag >> 8);
142 *buf++ = (tag & 0xff);
150 static inline uint8_t *vtvl_gan_put(uint8_t *buf, uint16_t tag, uint16_t len)
159 static 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);
173 static inline uint8_t *
msgb_tlv16_put(
struct msgb *msg, uint8_t tag, uint8_t len,
const uint16_t *val)
180 static inline uint8_t *
msgb_tl16v_put(
struct msgb *msg, uint8_t tag, uint16_t len,
188 static 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);
204 static inline uint8_t *
msgb_l16tv_put(
struct msgb *msg, uint16_t len, uint8_t tag,
212 memcpy(buf, val, len);
217 static inline uint8_t *
v_put(uint8_t *buf, uint8_t val)
224 static inline uint8_t *
tv_put(uint8_t *buf, uint8_t tag,
234 unsigned int len,
const uint8_t *val)
237 memcpy(buf, val, len);
246 static inline uint8_t *
tv16_put(uint8_t *buf, uint8_t tag,
257 static inline uint8_t *
msgb_lv_put(
struct msgb *msg, uint8_t len,
const uint8_t *val)
260 return lv_put(buf, len, val);
265 static 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);
273 static 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);
290 static 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);
298 static inline uint8_t *
msgb_tv16_put(
struct msgb *msg, uint8_t tag, uint16_t val)
300 uint8_t *buf = msgb_put(msg, 3);
306 static inline uint8_t *
msgb_tlv_push(
struct msgb *msg, uint8_t tag, uint8_t len,
const uint8_t *val)
315 static inline uint8_t *
msgb_tv_push(
struct msgb *msg, uint8_t tag, uint8_t val)
317 uint8_t *buf = msgb_push(msg, 2);
324 static inline uint8_t *
msgb_tv16_push(
struct msgb *msg, uint8_t tag, uint16_t val)
326 uint8_t *buf = msgb_push(msg, 3);
333 static inline uint8_t *
msgb_tvlv_push(
struct msgb *msg, uint8_t tag, uint16_t len,
343 static inline uint8_t *msgb_vtvl_gan_push(
struct msgb *msg, uint16_t tag,
347 vtvl_gan_put(buf, tag, len);
352 static 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);
400 int 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));