tlv.h
Go to the documentation of this file.
#pragma once
#include <stdint.h>
#include <string.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/byteswap.h>
#include <osmocom/core/bit16gen.h>
#include <osmocom/core/bit32gen.h>
/* Terminology / wording
tag length value (in bits)
V - - 8
LV - 8 N * 8
TLV 8 8 N * 8
TL16V 8 16 N * 8
TLV16 8 8 N * 16
TvLV 8 8/16 N * 8
vTvLV 8/16 8/16 N * 8
T16LV 16 8 N * 8
*/
#define LV_GROSS_LEN(x) (x+1)
#define TLV_GROSS_LEN(x) (x+2)
#define TLV16_GROSS_LEN(x) ((2*x)+2)
#define TL16V_GROSS_LEN(x) (x+3)
#define L16TV_GROSS_LEN(x) (x+3)
#define T16LV_GROSS_LEN(x) (x+3)
#define TVLV_MAX_ONEBYTE 0x7f
enum osmo_tlv_parser_error {
OSMO_TLVP_ERR_OFS_BEYOND_BUFFER = -1,
OSMO_TLVP_ERR_OFS_LEN_BEYOND_BUFFER = -2,
OSMO_TLVP_ERR_UNKNOWN_TLV_TYPE = -3,
OSMO_TLVP_ERR_MAND_IE_MISSING = -50,
OSMO_TLVP_ERR_IE_TOO_SHORT = -51,
};
static inline uint16_t TVLV_GROSS_LEN(uint16_t len)
{
if (len <= TVLV_MAX_ONEBYTE)
return TLV_GROSS_LEN(len);
else
return TL16V_GROSS_LEN(len);
}
static inline uint16_t VTVL_GAN_GROSS_LEN(uint16_t tag, uint16_t len)
{
uint16_t ret = 2;
if (tag > TVLV_MAX_ONEBYTE)
ret++;
if (len > TVLV_MAX_ONEBYTE)
ret++;
return ret;
}
static inline uint16_t VTVLV_GAN_GROSS_LEN(uint16_t tag, uint16_t len)
{
uint16_t ret;
if (len <= TVLV_MAX_ONEBYTE)
ret = TLV_GROSS_LEN(len);
else
ret = TL16V_GROSS_LEN(len);
if (tag > TVLV_MAX_ONEBYTE)
ret += 1;
return ret;
}
/* TLV generation */
static inline uint8_t *lv_put(uint8_t *buf, uint8_t len,
const uint8_t *val)
{
*buf++ = len;
memcpy(buf, val, len);
return buf + len;
}
static inline uint8_t *tlv_put(uint8_t *buf, uint8_t tag, uint8_t len,
const uint8_t *val)
{
*buf++ = tag;
*buf++ = len;
if (len) {
if (val)
memcpy(buf, val, len);
else
memset(buf, 0, len);
}
return buf + len;
}
static inline uint8_t *tl_put(uint8_t *buf, uint8_t tag, uint8_t len)
{
*buf++ = tag;
*buf++ = len;
return buf;
}
static inline uint8_t *tlv16_put(uint8_t *buf, uint8_t tag, uint8_t len,
const uint16_t *val)
{
*buf++ = tag;
*buf++ = len;
memcpy(buf, val, len*2);
return buf + len*2;
}
static inline uint8_t *tl16v_put(uint8_t *buf, uint8_t tag, uint16_t len,
const uint8_t *val)
{
*buf++ = tag;
*buf++ = len >> 8;
*buf++ = len & 0xff;
memcpy(buf, val, len);
return buf + len;
}
static inline uint8_t *tl16_put(uint8_t *buf, uint8_t tag, uint16_t len)
{
*buf++ = tag;
*buf++ = len >> 8;
*buf++ = len & 0xff;
return buf;
}
static inline uint8_t *t16lv_put(uint8_t *buf, uint16_t tag, uint8_t len,
const uint8_t *val)
{
*buf++ = tag >> 8;
*buf++ = tag & 0xff;
*buf++ = len;
memcpy(buf, val, len);
return buf + len;
}
static inline uint8_t *tvlv_put(uint8_t *buf, uint8_t tag, uint16_t len,
const uint8_t *val)
{
uint8_t *ret;
if (len <= TVLV_MAX_ONEBYTE) {
ret = tlv_put(buf, tag, len, val);
buf[1] |= 0x80;
} else
ret = tl16v_put(buf, tag, len, val);
return ret;
}
static inline uint8_t *tvl_put(uint8_t *buf, uint8_t tag, uint16_t len)
{
uint8_t *ret;
if (len <= TVLV_MAX_ONEBYTE) {
ret = tl_put(buf, tag, len);
buf[1] |= 0x80;
} else
ret = tl16_put(buf, tag, len);
return ret;
}
static inline uint8_t *vt_gan_put(uint8_t *buf, uint16_t tag)
{
if (tag > TVLV_MAX_ONEBYTE) {
/* two-byte TAG */
*buf++ = 0x80 | (tag >> 8);
*buf++ = (tag & 0xff);
} else
*buf++ = tag;
return buf;
}
/* put (append) vTvL (GAN) field (tag + length)*/
static inline uint8_t *vtvl_gan_put(uint8_t *buf, uint16_t tag, uint16_t len)
{
uint8_t *ret;
ret = vt_gan_put(buf, tag);
return vt_gan_put(ret, len);
}
/* put (append) vTvLV (GAN) field (tag + length + val) */
static inline uint8_t *vtvlv_gan_put(uint8_t *buf, uint16_t tag, uint16_t len,
const uint8_t *val)
{
uint8_t *ret;
ret = vtvl_gan_put(buf, tag, len );
memcpy(ret, val, len);
ret = buf + len;
return ret;
}
static inline uint8_t *msgb_tlv16_put(struct msgb *msg, uint8_t tag, uint8_t len, const uint16_t *val)
{
uint8_t *buf = msgb_put(msg, TLV16_GROSS_LEN(len));
return tlv16_put(buf, tag, len, val);
}
static inline uint8_t *msgb_tl16v_put(struct msgb *msg, uint8_t tag, uint16_t len,
const uint8_t *val)
{
uint8_t *buf = msgb_put(msg, TL16V_GROSS_LEN(len));
return tl16v_put(buf, tag, len, val);
}
static inline uint8_t *msgb_t16lv_put(struct msgb *msg, uint16_t tag, uint8_t len, const uint8_t *val)
{
uint8_t *buf = msgb_put(msg, T16LV_GROSS_LEN(len));
return t16lv_put(buf, tag, len, val);
}
static inline uint8_t *msgb_tvl_put(struct msgb *msg, uint8_t tag, uint16_t len)
{
uint8_t *buf = msgb_put(msg, TVLV_GROSS_LEN(len));
return tvl_put(buf, tag, len);
}
static inline uint8_t *msgb_tvlv_put(struct msgb *msg, uint8_t tag, uint16_t len,
const uint8_t *val)
{
uint8_t *buf = msgb_put(msg, TVLV_GROSS_LEN(len));
return tvlv_put(buf, tag, len, val);
}
static inline uint8_t *msgb_tvlv_put_16be(struct msgb *msg, uint8_t tag, uint16_t val)
{
uint16_t val_be = osmo_htons(val);
return msgb_tvlv_put(msg, tag, 2, (const uint8_t *)&val_be);
}
static inline uint8_t *msgb_tvlv_put_32be(struct msgb *msg, uint8_t tag, uint32_t val)
{
uint32_t val_be = osmo_htonl(val);
return msgb_tvlv_put(msg, tag, 4, (const uint8_t *)&val_be);
}
static inline uint8_t *msgb_vtvlv_gan_put(struct msgb *msg, uint16_t tag,
uint16_t len, const uint8_t *val)
{
uint8_t *buf = msgb_put(msg, VTVLV_GAN_GROSS_LEN(tag, len));
return vtvlv_gan_put(buf, tag, len, val);
}
static inline uint8_t *msgb_l16tv_put(struct msgb *msg, uint16_t len, uint8_t tag,
const uint8_t *val)
{
uint8_t *buf = msgb_put(msg, L16TV_GROSS_LEN(len));
*buf++ = len >> 8;
*buf++ = len & 0xff;
*buf++ = tag;
memcpy(buf, val, len);
return buf + len;
}
static inline uint8_t *v_put(uint8_t *buf, uint8_t val)
{
*buf++ = val;
return buf;
}
static inline uint8_t *tv_put(uint8_t *buf, uint8_t tag,
uint8_t val)
{
*buf++ = tag;
*buf++ = val;
return buf;
}
static inline uint8_t *tv_fixed_put(uint8_t *buf, uint8_t tag,
unsigned int len, const uint8_t *val)
{
*buf++ = tag;
memcpy(buf, val, len);
return buf + len;
}
static inline uint8_t *tv16_put(uint8_t *buf, uint8_t tag,
uint16_t val)
{
*buf++ = tag;
*buf++ = val >> 8;
*buf++ = val & 0xff;
return buf;
}
static inline uint8_t *msgb_lv_put(struct msgb *msg, uint8_t len, const uint8_t *val)
{
uint8_t *buf = msgb_put(msg, LV_GROSS_LEN(len));
return lv_put(buf, len, val);
}
static inline uint8_t *msgb_tlv_put(struct msgb *msg, uint8_t tag, uint8_t len, const uint8_t *val)
{
uint8_t *buf = msgb_put(msg, TLV_GROSS_LEN(len));
return tlv_put(buf, tag, len, val);
}
static inline uint8_t *msgb_tv_put(struct msgb *msg, uint8_t tag, uint8_t val)
{
uint8_t *buf = msgb_put(msg, 2);
return tv_put(buf, tag, val);
}
static inline uint8_t *msgb_tv_fixed_put(struct msgb *msg, uint8_t tag,
unsigned int len, const uint8_t *val)
{
uint8_t *buf = msgb_put(msg, 1+len);
return tv_fixed_put(buf, tag, len, val);
}
static inline uint8_t *msgb_v_put(struct msgb *msg, uint8_t val)
{
uint8_t *buf = msgb_put(msg, 1);
return v_put(buf, val);
}
static inline uint8_t *msgb_tl_put(struct msgb *msg, uint8_t tag)
{
uint8_t *len = msgb_v_put(msg, tag);
/* reserve space for length, len points to this reserved space already */
msgb_v_put(msg, 0);
return len;
}
static inline uint8_t *msgb_tv16_put(struct msgb *msg, uint8_t tag, uint16_t val)
{
uint8_t *buf = msgb_put(msg, 3);
return tv16_put(buf, tag, val);
}
static inline uint8_t *msgb_tv32_put(struct msgb *msg, uint8_t tag, uint32_t val)
{
uint8_t *buf = msgb_put(msg, 1 + 4);
*buf++ = tag;
osmo_store32be(val, buf);
return msg->tail;
}
static inline uint8_t *msgb_tlv_push(struct msgb *msg, uint8_t tag, uint8_t len, const uint8_t *val)
{
uint8_t *buf = msgb_push(msg, TLV_GROSS_LEN(len));
tlv_put(buf, tag, len, val);
return buf;
}
static inline uint8_t *msgb_tlv1_push(struct msgb *msg, uint8_t tag, uint8_t val)
{
return msgb_tlv_push(msg, tag, 1, &val);
}
static inline uint8_t *msgb_tv_push(struct msgb *msg, uint8_t tag, uint8_t val)
{
uint8_t *buf = msgb_push(msg, 2);
tv_put(buf, tag, val);
return buf;
}
static inline uint8_t *msgb_tv16_push(struct msgb *msg, uint8_t tag, uint16_t val)
{
uint8_t *buf = msgb_push(msg, 3);
tv16_put(buf, tag, val);
return buf;
}
static inline uint8_t *msgb_tvlv_push(struct msgb *msg, uint8_t tag, uint16_t len,
const uint8_t *val)
{
uint8_t *buf = msgb_push(msg, TVLV_GROSS_LEN(len));
tvlv_put(buf, tag, len, val);
return buf;
}
/* push (prepend) a vTvL header to a \ref msgb
*/
static inline uint8_t *msgb_vtvl_gan_push(struct msgb *msg, uint16_t tag,
uint16_t len)
{
uint8_t *buf = msgb_push(msg, VTVL_GAN_GROSS_LEN(tag, len));
vtvl_gan_put(buf, tag, len);
return buf;
}
static inline uint8_t *msgb_vtvlv_gan_push(struct msgb *msg, uint16_t tag,
uint16_t len, const uint8_t *val)
{
uint8_t *buf = msgb_push(msg, VTVLV_GAN_GROSS_LEN(tag, len));
vtvlv_gan_put(buf, tag, len, val);
return buf;
}
/* TLV parsing */
struct tlv_p_entry {
uint16_t len;
const uint8_t *val;
};
enum tlv_type {
TLV_TYPE_NONE,
TLV_TYPE_FIXED,
TLV_TYPE_T,
TLV_TYPE_TV,
TLV_TYPE_TLV,
TLV_TYPE_TL16V,
TLV_TYPE_TvLV,
TLV_TYPE_SINGLE_TV,
TLV_TYPE_vTvLV_GAN,
};
struct tlv_def {
enum tlv_type type;
uint8_t fixed_len;
};
struct tlv_definition {
struct tlv_def def[256];
};
struct tlv_parsed {
struct tlv_p_entry lv[256];
};
extern struct tlv_definition tvlv_att_def;
extern struct tlv_definition vtvlv_gan_att_def;
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);
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);
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);
/* take a master (src) tlv def and fill up all empty slots in 'dst' */
void tlv_def_patch(struct tlv_definition *dst, const struct tlv_definition *src);
int tlv_encode_one(struct msgb *msg, enum tlv_type type, uint8_t tag,
unsigned int len, const uint8_t *val);
int tlv_encode(struct msgb *msg, const struct tlv_definition *def, const struct tlv_parsed *tp);
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);
#define TLVP_PRESENT(x, y) ((x)->lv[y].val)
#define TLVP_LEN(x, y) (x)->lv[y].len
#define TLVP_VAL(x, y) (x)->lv[y].val
#define TLVP_PRES_LEN(tp, tag, min_len) \
(TLVP_PRESENT(tp, tag) && TLVP_LEN(tp, tag) >= min_len)
#define TLVP_GET(_tp, tag) (TLVP_PRESENT(_tp, tag)? &(_tp)->lv[tag] : NULL)
#define TLVP_GET_MINLEN(_tp, tag, min_len) \
(TLVP_PRES_LEN(_tp, tag, min_len)? &(_tp)->lv[tag] : NULL)
#define TLVP_VAL_MINLEN(_tp, tag, min_len) \
(TLVP_PRES_LEN(_tp, tag, min_len)? (_tp)->lv[tag].val : NULL)
static inline uint8_t tlvp_val8(const struct tlv_parsed *tp, uint8_t tag, uint8_t default_val)
{
const uint8_t *res = TLVP_VAL_MINLEN(tp, tag, 1);
if (res)
return res[0];
return default_val;
}
static inline uint16_t tlvp_val16_unal(const struct tlv_parsed *tp, int pos)
{
uint16_t res;
memcpy(&res, TLVP_VAL(tp, pos), sizeof(res));
return res;
}
static inline uint32_t tlvp_val32_unal(const struct tlv_parsed *tp, int pos)
{
uint32_t res;
memcpy(&res, TLVP_VAL(tp, pos), sizeof(res));
return res;
}
static inline uint16_t tlvp_val16be(const struct tlv_parsed *tp, int pos)
{
return osmo_load16be(TLVP_VAL(tp, pos));
}
static inline uint32_t tlvp_val32be(const struct tlv_parsed *tp, int pos)
{
return osmo_load32be(TLVP_VAL(tp, pos));
}
struct tlv_parsed *osmo_tlvp_copy(const struct tlv_parsed *tp_orig, void *ctx);
int osmo_tlvp_merge(struct tlv_parsed *dst, const struct tlv_parsed *src);
int osmo_shift_v_fixed(uint8_t **data, size_t *data_len,
size_t len, uint8_t **value);
int osmo_match_shift_tv_fixed(uint8_t **data, size_t *data_len,
uint8_t tag, size_t len, uint8_t **value);
int osmo_shift_tlv(uint8_t **data, size_t *data_len,
uint8_t *tag, uint8_t **value, size_t *value_len);
int osmo_match_shift_tlv(uint8_t **data, size_t *data_len,
uint8_t tag, uint8_t **value, size_t *value_len);
int osmo_shift_lv(uint8_t **data, size_t *data_len,
uint8_t **value, size_t *value_len);
#define MSG_DEF(name, mand_ies, flags) { name, mand_ies, ARRAY_SIZE(mand_ies), flags }
struct osmo_tlv_prot_msg_def {
const char *name;
const uint8_t *mand_ies;
uint8_t mand_count;
uint32_t flags;
};
struct osmo_tlv_prot_ie_def {
uint16_t min_len;
const char *name;
};
struct osmo_tlv_prot_def {
const char *name;
const struct tlv_definition *tlv_def;
struct osmo_tlv_prot_msg_def msg_def[256];
struct osmo_tlv_prot_ie_def ie_def[256];
const struct value_string *msgt_names;
};
const char *osmo_tlv_prot_msg_name(const struct osmo_tlv_prot_def *pdef, uint8_t msg_type);
const char *osmo_tlv_prot_ie_name(const struct osmo_tlv_prot_def *pdef, uint8_t iei);
int osmo_tlv_prot_validate_tp(const struct osmo_tlv_prot_def *pdef, uint8_t msg_type,
const struct tlv_parsed *tp, int log_subsys, const char *log_pfx);
int osmo_tlv_prot_parse(const struct osmo_tlv_prot_def *pdef,
struct tlv_parsed *dec, unsigned int dec_multiples, uint8_t msg_type,
const uint8_t *buf, unsigned int buf_len, uint8_t lv_tag, uint8_t lv_tag2,
int log_subsys, const char *log_pfx);
static inline uint32_t osmo_tlv_prot_msgt_flags(const struct osmo_tlv_prot_def *pdef, uint8_t msg_type)
{
return pdef->msg_def[msg_type].flags;
}
bit16gen.h
bit32gen.h
byteswap.h
osmo_htons
#define osmo_htons(x)
osmo_htonl
#define osmo_htonl(x)
data
uint8_t data[0]
msgb_push
static unsigned char * msgb_push(struct msgb *msgb, unsigned int len)
msgb_put
static unsigned char * msgb_put(struct msgb *msgb, unsigned int len)
tl_put
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:126
msgb_tv_put
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:374
osmo_shift_v_fixed
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:468
TL16V_GROSS_LEN
#define TL16V_GROSS_LEN(x)
gross length of a TL16V type field
Definition: tlv.h:35
tvl_put
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:193
tl16_put
static uint8_t * tl16_put(uint8_t *buf, uint8_t tag, uint16_t len)
put (append) a TL16 field.
Definition: tlv.h:155
tlvp_val16be
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:629
msgb_lv_put
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:358
msgb_tlv_put
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:366
TLVP_VAL
#define TLVP_VAL(x, y)
Definition: tlv.h:548
msgb_tvlv_put_32be
static uint8_t * msgb_tvlv_put_32be(struct msgb *msg, uint8_t tag, uint32_t val)
put (append) a TvLV field containing a big-endian 16bit value to msgb.
Definition: tlv.h:290
TVLV_MAX_ONEBYTE
#define TVLV_MAX_ONEBYTE
maximum length of TLV of one byte length
Definition: tlv.h:42
vt_gan_put
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:207
tlv_parse_one
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:230
tlv_encode_ordered
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:199
tlv_type
tlv_type
TLV type.
Definition: tlv.h:498
osmo_match_shift_tv_fixed
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:496
TLVP_VAL_MINLEN
#define TLVP_VAL_MINLEN(_tp, tag, min_len)
Like TLVP_VAL(), but enforcing a minimum val length.
Definition: tlv.h:580
vtvlv_gan_att_def
struct tlv_definition vtvlv_gan_att_def
Definition: tlv_parser.c:50
msgb_tlv1_push
static uint8_t * msgb_tlv1_push(struct msgb *msg, uint8_t tag, uint8_t val)
push 1-byte tagged value
Definition: tlv.h:437
vtvl_gan_put
static uint8_t * vtvl_gan_put(uint8_t *buf, uint16_t tag, uint16_t len)
Definition: tlv.h:220
tlv_encode
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:173
tlvp_val16_unal
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:605
tlvp_val32_unal
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:617
LV_GROSS_LEN
#define LV_GROSS_LEN(x)
gross length of a LV type field
Definition: tlv.h:29
VTVLV_GAN_GROSS_LEN
static uint16_t VTVLV_GAN_GROSS_LEN(uint16_t tag, uint16_t len)
gross length of vTvLV (tag+len+val)
Definition: tlv.h:78
osmo_shift_lv
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:602
msgb_tvl_put
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:268
tlv_parse2
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:359
tlvp_val8
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:590
tlvp_val32be
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:639
osmo_tlv_prot_ie_name
const char * osmo_tlv_prot_ie_name(const struct osmo_tlv_prot_def *pdef, uint8_t iei)
get the IE name for given IEI in protocol pdef
Definition: tlv_parser.c:649
osmo_tlv_prot_parse
int osmo_tlv_prot_parse(const struct osmo_tlv_prot_def *pdef, struct tlv_parsed *dec, unsigned int dec_multiples, uint8_t msg_type, const uint8_t *buf, unsigned int buf_len, uint8_t lv_tag, uint8_t lv_tag2, int log_subsys, const char *log_pfx)
Parse + Validate a TLV-encoded message against the protocol definition.
Definition: tlv_parser.c:719
VTVL_GAN_GROSS_LEN
static uint16_t VTVL_GAN_GROSS_LEN(uint16_t tag, uint16_t len)
gross length of vTvL header (tag+len)
Definition: tlv.h:64
TVLV_GROSS_LEN
static uint16_t TVLV_GROSS_LEN(uint16_t len)
gross length of a TVLV type field
Definition: tlv.h:55
msgb_t16lv_put
static uint8_t * msgb_t16lv_put(struct msgb *msg, uint16_t tag, uint8_t len, const uint8_t *val)
Definition: tlv.h:257
tlv_def_patch
void tlv_def_patch(struct tlv_definition *dst, const struct tlv_definition *src)
take a master (src) tlv_definition and fill up all empty slots in 'dst'
Definition: tlv_parser.c:439
tvlv_put
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:175
msgb_tl_put
static uint8_t * msgb_tl_put(struct msgb *msg, uint8_t tag)
put (append) a TL fields to a Message buffers
Definition: tlv.h:399
msgb_vtvlv_gan_put
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:297
msgb_tv16_put
static uint8_t * msgb_tv16_put(struct msgb *msg, uint8_t tag, uint16_t val)
put (append) a TV16 field (network order) to the given msgb
Definition: tlv.h:411
msgb_tv_push
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:444
msgb_vtvl_gan_push
static uint8_t * msgb_vtvl_gan_push(struct msgb *msg, uint16_t tag, uint16_t len)
Definition: tlv.h:472
msgb_tl16v_put
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:250
msgb_tvlv_put
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:275
tv_put
static uint8_t * tv_put(uint8_t *buf, uint8_t tag, uint8_t val)
put (append) a TV field
Definition: tlv.h:325
TLV16_GROSS_LEN
#define TLV16_GROSS_LEN(x)
gross length of a TLV16 type field
Definition: tlv.h:33
L16TV_GROSS_LEN
#define L16TV_GROSS_LEN(x)
gross length of a L16TV type field
Definition: tlv.h:37
msgb_l16tv_put
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:305
msgb_tv32_put
static uint8_t * msgb_tv32_put(struct msgb *msg, uint8_t tag, uint32_t val)
put (append) a TV32 field (network order) to the given msgb
Definition: tlv.h:419
osmo_tlvp_merge
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:105
t16lv_put
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:164
v_put
static uint8_t * v_put(uint8_t *buf, uint8_t val)
put (append) a V field
Definition: tlv.h:318
tlv_parse
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:336
msgb_vtvlv_gan_push
static uint8_t * msgb_vtvlv_gan_push(struct msgb *msg, uint16_t tag, uint16_t len, const uint8_t *val)
Definition: tlv.h:481
osmo_shift_tlv
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:562
tvlv_att_def
struct tlv_definition tvlv_att_def
Definition: tlv_parser.c:49
msgb_tvlv_push
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:462
tlv_put
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:111
lv_put
static uint8_t * lv_put(uint8_t *buf, uint8_t len, const uint8_t *val)
put (append) a LV field
Definition: tlv.h:96
osmo_tlv_prot_validate_tp
int osmo_tlv_prot_validate_tp(const struct osmo_tlv_prot_def *pdef, uint8_t msg_type, const struct tlv_parsed *tp, int log_subsys, const char *log_pfx)
Validate an already TLV-decoded message against the protocol definition.
Definition: tlv_parser.c:667
msgb_tlv_push
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:429
osmo_tlv_parser_error
osmo_tlv_parser_error
error return codes of various TLV parser functions
Definition: tlv.h:45
osmo_match_shift_tlv
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:534
T16LV_GROSS_LEN
#define T16LV_GROSS_LEN(x)
gross length of a T16LV type field
Definition: tlv.h:39
osmo_tlv_prot_msg_name
const char * osmo_tlv_prot_msg_name(const struct osmo_tlv_prot_def *pdef, uint8_t msg_type)
get the message name for given msg_type in protocol pdef
Definition: tlv_parser.c:636
vtvlv_gan_put
static uint8_t * vtvlv_gan_put(uint8_t *buf, uint16_t tag, uint16_t len, const uint8_t *val)
Definition: tlv.h:229
msgb_tlv16_put
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:243
TLV_GROSS_LEN
#define TLV_GROSS_LEN(x)
gross length of a TLV type field
Definition: tlv.h:31
msgb_v_put
static uint8_t * msgb_v_put(struct msgb *msg, uint8_t val)
put (append) a V field to a Message buffers
Definition: tlv.h:391
tlv16_put
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:134
tv_fixed_put
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:334
osmo_tlvp_copy
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:70
tlv_encode_one
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:132
osmo_tlv_prot_msgt_flags
static uint32_t osmo_tlv_prot_msgt_flags(const struct osmo_tlv_prot_def *pdef, uint8_t msg_type)
Definition: tlv.h:702
msgb_tv16_push
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:453
tl16v_put
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:144
tv16_put
static uint8_t * tv16_put(uint8_t *buf, uint8_t tag, uint16_t val)
put (append) a TV16 field
Definition: tlv.h:347
msgb_tv_fixed_put
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:382
msgb_tvlv_put_16be
static uint8_t * msgb_tvlv_put_16be(struct msgb *msg, uint8_t tag, uint16_t val)
put (append) a TvLV field containing a big-endian 16bit value to msgb.
Definition: tlv.h:283
TLV_TYPE_TLV
@ TLV_TYPE_TLV
tag-length-value
Definition: tlv.h:503
TLV_TYPE_TV
@ TLV_TYPE_TV
tag-value (8bit)
Definition: tlv.h:502
TLV_TYPE_FIXED
@ TLV_TYPE_FIXED
fixed-length value-only
Definition: tlv.h:500
TLV_TYPE_TvLV
@ TLV_TYPE_TvLV
tag, variable length, value
Definition: tlv.h:505
TLV_TYPE_NONE
@ TLV_TYPE_NONE
no type
Definition: tlv.h:499
TLV_TYPE_TL16V
@ TLV_TYPE_TL16V
tag, 16 bit length, value
Definition: tlv.h:504
TLV_TYPE_SINGLE_TV
@ TLV_TYPE_SINGLE_TV
tag and value (both 4 bit) in 1 byte
Definition: tlv.h:506
TLV_TYPE_T
@ TLV_TYPE_T
tag-only
Definition: tlv.h:501
TLV_TYPE_vTvLV_GAN
@ TLV_TYPE_vTvLV_GAN
variable-length tag, variable-length length
Definition: tlv.h:507
OSMO_TLVP_ERR_MAND_IE_MISSING
@ OSMO_TLVP_ERR_MAND_IE_MISSING
Definition: tlv.h:50
OSMO_TLVP_ERR_UNKNOWN_TLV_TYPE
@ OSMO_TLVP_ERR_UNKNOWN_TLV_TYPE
Definition: tlv.h:48
OSMO_TLVP_ERR_OFS_BEYOND_BUFFER
@ OSMO_TLVP_ERR_OFS_BEYOND_BUFFER
Definition: tlv.h:46
OSMO_TLVP_ERR_IE_TOO_SHORT
@ OSMO_TLVP_ERR_IE_TOO_SHORT
Definition: tlv.h:51
OSMO_TLVP_ERR_OFS_LEN_BEYOND_BUFFER
@ OSMO_TLVP_ERR_OFS_LEN_BEYOND_BUFFER
Definition: tlv.h:47
msg_type
uint8_t msg_type
Definition: gsm_04_08.h:2
len
uint8_t len
Definition: gsm_04_11.h:0
type
uint8_t type
Definition: gsm_08_08.h:0
msg
uint8_t msg[0]
Definition: gsm_08_08.h:8
iei
uint8_t iei
Definition: gsm_08_58.h:2
res
uint8_t res
msgb.h
msgb
osmo_tlv_prot_def
Osmocom TLV protocol definition.
Definition: tlv.h:678
osmo_tlv_prot_def::ie_def
struct osmo_tlv_prot_ie_def ie_def[256]
definition of IE for each 8-bit tag
Definition: tlv.h:686
osmo_tlv_prot_def::tlv_def
const struct tlv_definition * tlv_def
TLV parser definition (optional)
Definition: tlv.h:682
osmo_tlv_prot_def::msg_def
struct osmo_tlv_prot_msg_def msg_def[256]
definition of each message (8-bit message type)
Definition: tlv.h:684
osmo_tlv_prot_def::msgt_names
const struct value_string * msgt_names
value_string array of message type names (legacy, if not populated in msg_def)
Definition: tlv.h:688
osmo_tlv_prot_def::name
const char * name
human-readable name of protocol
Definition: tlv.h:680
osmo_tlv_prot_ie_def
Definition: tlv.h:670
osmo_tlv_prot_ie_def::name
const char * name
huamn-readable name (optional)
Definition: tlv.h:674
osmo_tlv_prot_ie_def::min_len
uint16_t min_len
minimum length of IE value part, in octets
Definition: tlv.h:672
osmo_tlv_prot_msg_def
Definition: tlv.h:660
osmo_tlv_prot_msg_def::mand_ies
const uint8_t * mand_ies
array of mandatory IEs
Definition: tlv.h:664
osmo_tlv_prot_msg_def::name
const char * name
human-readable name of message type (optional)
Definition: tlv.h:662
osmo_tlv_prot_msg_def::flags
uint32_t flags
user-defined flags (like uplink/downlink/...)
Definition: tlv.h:668
osmo_tlv_prot_msg_def::mand_count
uint8_t mand_count
number of entries in 'mand_ies' above
Definition: tlv.h:666
tlv_def
Definition of a single IE (Information Element)
Definition: tlv.h:511
tlv_def::fixed_len
uint8_t fixed_len
length in case of TLV_TYPE_FIXED
Definition: tlv.h:513
tlv_def::type
enum tlv_type type
TLV type.
Definition: tlv.h:512
tlv_definition
Definition of All 256 IE / TLV.
Definition: tlv.h:517
tlv_definition::def
struct tlv_def def[256]
Definition: tlv.h:518
tlv_p_entry
Entry in a TLV parser array.
Definition: tlv.h:492
tlv_p_entry::len
uint16_t len
length
Definition: tlv.h:493
tlv_p_entry::val
const uint8_t * val
pointer to value
Definition: tlv.h:494
tlv_parsed
result of the TLV parser
Definition: tlv.h:522
tlv_parsed::lv
struct tlv_p_entry lv[256]
Definition: tlv.h:523
value_string