7 #include <osmocom/core/msgb.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,
165 ret = vtvl_gan_put(buf, tag, 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)
201 return vtvlv_gan_put(buf, tag, len, 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,
344 static inline uint8_t *msgb_vtvl_gan_push(
struct msgb *msg, uint16_t tag,
348 vtvl_gan_put(buf, tag, len);
353 static inline uint8_t *msgb_vtvlv_gan_push(
struct msgb *msg, uint16_t tag,
354 uint16_t len,
const uint8_t *val)
357 vtvlv_gan_put(buf, tag, len, 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
421 memcpy(&res, TLVP_VAL(tp, pos),
sizeof(res));
433 memcpy(&res, TLVP_VAL(tp, pos),
sizeof(res));