2014-06-16 08:13:40 +00:00
|
|
|
#pragma once
|
2010-02-20 19:34:29 +00:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2011-03-22 15:36:13 +00:00
|
|
|
#include <osmocom/core/msgb.h>
|
2010-02-20 19:34:29 +00:00
|
|
|
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \defgroup tlv GSM L3 compatible TLV parser
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
/*! \file tlv.h */
|
|
|
|
|
2010-02-20 19:34:29 +00:00
|
|
|
/* 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
|
2012-07-13 23:50:33 +00:00
|
|
|
vTvLV 8/16 8/16 N * 8
|
2010-02-20 19:34:29 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \brief gross length of a LV type field */
|
2010-02-20 19:34:29 +00:00
|
|
|
#define LV_GROSS_LEN(x) (x+1)
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \brief gross length of a TLV type field */
|
2010-02-20 19:34:29 +00:00
|
|
|
#define TLV_GROSS_LEN(x) (x+2)
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \brief gross length of a TLV16 type field */
|
2010-02-20 19:34:29 +00:00
|
|
|
#define TLV16_GROSS_LEN(x) ((2*x)+2)
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \brief gross length of a TL16V type field */
|
2010-02-20 19:34:29 +00:00
|
|
|
#define TL16V_GROSS_LEN(x) (x+3)
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \brief gross length of a L16TV type field */
|
2010-02-20 19:34:29 +00:00
|
|
|
#define L16TV_GROSS_LEN(x) (x+3)
|
|
|
|
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \brief maximum length of TLV of one byte length */
|
2010-02-20 19:34:29 +00:00
|
|
|
#define TVLV_MAX_ONEBYTE 0x7f
|
|
|
|
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \brief gross length of a TVLV type field */
|
2010-02-20 19:34:29 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-07-13 23:50:33 +00:00
|
|
|
/*! \brief gross length of vTvL header (tag+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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief gross length of vTvLV (tag+len+val) */
|
|
|
|
static inline uint16_t VTVLV_GAN_GROSS_LEN(uint16_t tag, uint16_t len)
|
|
|
|
{
|
|
|
|
uint16_t ret;
|
|
|
|
|
|
|
|
if (len <= TVLV_MAX_ONEBYTE)
|
|
|
|
return TLV_GROSS_LEN(len);
|
|
|
|
else
|
|
|
|
return TL16V_GROSS_LEN(len);
|
|
|
|
|
|
|
|
if (tag > TVLV_MAX_ONEBYTE)
|
|
|
|
ret += 1;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-02-20 19:34:29 +00:00
|
|
|
/* TLV generation */
|
|
|
|
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \brief put (append) a LV field */
|
2010-02-20 19:34:29 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \brief put (append) a TLV field */
|
2010-02-20 19:34:29 +00:00
|
|
|
static inline uint8_t *tlv_put(uint8_t *buf, uint8_t tag, uint8_t len,
|
|
|
|
const uint8_t *val)
|
|
|
|
{
|
|
|
|
*buf++ = tag;
|
|
|
|
*buf++ = len;
|
|
|
|
memcpy(buf, val, len);
|
|
|
|
return buf + len;
|
|
|
|
}
|
|
|
|
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \brief put (append) a TLV16 field */
|
2010-02-20 19:34:29 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \brief put (append) a TL16V field */
|
2010-02-20 19:34:29 +00:00
|
|
|
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*2;
|
|
|
|
}
|
|
|
|
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \brief put (append) a TvLV field */
|
2010-02-20 19:34:29 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-07-13 23:50:33 +00:00
|
|
|
/*! \brief put (append) a variable-length tag or variable-length length * */
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* \brief 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* \brief 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;
|
|
|
|
}
|
|
|
|
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \brief put (append) a TLV16 field to \ref msgb */
|
2010-02-20 19:34:29 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \brief put (append) a TL16V field to \ref msgb */
|
2010-02-20 19:34:29 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \brief put (append) a TvLV field to \ref msgb */
|
2010-02-20 19:34:29 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-07-13 23:50:33 +00:00
|
|
|
/*! \brief put (append) a vTvLV field to \ref msgb */
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \brief put (append) a L16TV field to \ref msgb */
|
2010-02-20 19:34:29 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \brief put (append) a V field */
|
2010-02-20 19:34:29 +00:00
|
|
|
static inline uint8_t *v_put(uint8_t *buf, uint8_t val)
|
|
|
|
{
|
|
|
|
*buf++ = val;
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \brief put (append) a TV field */
|
2010-02-20 19:34:29 +00:00
|
|
|
static inline uint8_t *tv_put(uint8_t *buf, uint8_t tag,
|
|
|
|
uint8_t val)
|
|
|
|
{
|
|
|
|
*buf++ = tag;
|
|
|
|
*buf++ = val;
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \brief put (append) a TVfixed field */
|
2011-03-05 13:32:50 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \brief put (append) a TV16 field
|
|
|
|
* \param[in,out] buf data buffer
|
|
|
|
* \param[in] tag Tag value
|
|
|
|
* \param[in] val Value (in host byte order!)
|
|
|
|
*/
|
2010-02-20 19:34:29 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-01-22 22:03:38 +00:00
|
|
|
/*! \brief put (append) a LV field to a \ref msgb
|
|
|
|
* \returns pointer to first byte after newly-put information */
|
2010-02-20 19:34:29 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-01-22 22:03:38 +00:00
|
|
|
/*! \brief put (append) a TLV field to a \ref msgb
|
|
|
|
* \returns pointer to first byte after newly-put information */
|
2010-02-20 19:34:29 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-01-22 22:03:38 +00:00
|
|
|
/*! \brief put (append) a TV field to a \ref msgb
|
|
|
|
* \returns pointer to first byte after newly-put information */
|
2010-02-20 19:34:29 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-01-22 22:03:38 +00:00
|
|
|
/*! \brief put (append) a TVfixed field to a \ref msgb
|
|
|
|
* \returns pointer to first byte after newly-put information */
|
2011-03-05 13:32:50 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-01-22 22:03:38 +00:00
|
|
|
/*! \brief put (append) a V field to a \ref msgb
|
|
|
|
* \returns pointer to first byte after newly-put information */
|
2010-02-20 19:34:29 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-01-22 22:03:38 +00:00
|
|
|
/*! \brief put (append) a TV16 field to a \ref msgb
|
|
|
|
* \returns pointer to first byte after newly-put information */
|
2010-02-20 19:34:29 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-01-22 22:03:38 +00:00
|
|
|
/*! \brief push (prepend) a TLV field to a \ref msgb
|
|
|
|
* \returns pointer to first byte of newly-pushed information */
|
2010-02-20 19:34:29 +00:00
|
|
|
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));
|
2012-01-22 22:03:38 +00:00
|
|
|
tlv_put(buf, tag, len, val);
|
|
|
|
return buf;
|
2010-02-20 19:34:29 +00:00
|
|
|
}
|
|
|
|
|
2012-01-22 22:03:38 +00:00
|
|
|
/*! \brief push (prepend) a TV field to a \ref msgb
|
|
|
|
* \returns pointer to first byte of newly-pushed information */
|
2010-02-20 19:34:29 +00:00
|
|
|
static inline uint8_t *msgb_tv_push(struct msgb *msg, uint8_t tag, uint8_t val)
|
|
|
|
{
|
|
|
|
uint8_t *buf = msgb_push(msg, 2);
|
2012-01-22 22:03:38 +00:00
|
|
|
tv_put(buf, tag, val);
|
|
|
|
return buf;
|
2010-02-20 19:34:29 +00:00
|
|
|
}
|
|
|
|
|
2012-01-22 22:03:38 +00:00
|
|
|
/*! \brief push (prepend) a TV16 field to a \ref msgb
|
|
|
|
* \returns pointer to first byte of newly-pushed information */
|
2010-02-20 19:34:29 +00:00
|
|
|
static inline uint8_t *msgb_tv16_push(struct msgb *msg, uint8_t tag, uint16_t val)
|
|
|
|
{
|
|
|
|
uint8_t *buf = msgb_push(msg, 3);
|
2012-01-22 22:03:38 +00:00
|
|
|
tv16_put(buf, tag, val);
|
|
|
|
return buf;
|
2010-02-20 19:34:29 +00:00
|
|
|
}
|
|
|
|
|
2012-01-22 22:03:38 +00:00
|
|
|
/*! \brief push (prepend) a TvLV field to a \ref msgb
|
|
|
|
* \returns pointer to first byte of newly-pushed information */
|
2010-02-21 18:03:41 +00:00
|
|
|
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));
|
2012-01-22 22:03:38 +00:00
|
|
|
tvlv_put(buf, tag, len, val);
|
|
|
|
return buf;
|
2010-02-21 18:03:41 +00:00
|
|
|
}
|
|
|
|
|
2012-07-13 23:50:33 +00:00
|
|
|
/* \brief 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;
|
|
|
|
}
|
|
|
|
|
2010-02-20 19:34:29 +00:00
|
|
|
/* TLV parsing */
|
|
|
|
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \brief Entry in a TLV parser array */
|
2010-02-20 19:34:29 +00:00
|
|
|
struct tlv_p_entry {
|
2011-08-17 15:50:55 +00:00
|
|
|
uint16_t len; /*!< \brief length */
|
|
|
|
const uint8_t *val; /*!< \brief pointer to value */
|
2010-02-20 19:34:29 +00:00
|
|
|
};
|
|
|
|
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \brief TLV type */
|
2010-02-20 19:34:29 +00:00
|
|
|
enum tlv_type {
|
2011-08-17 15:50:55 +00:00
|
|
|
TLV_TYPE_NONE, /*!< \brief no type */
|
|
|
|
TLV_TYPE_FIXED, /*!< \brief fixed-length value-only */
|
|
|
|
TLV_TYPE_T, /*!< \brief tag-only */
|
|
|
|
TLV_TYPE_TV, /*!< \brief tag-value (8bit) */
|
|
|
|
TLV_TYPE_TLV, /*!< \brief tag-length-value */
|
|
|
|
TLV_TYPE_TL16V, /*!< \brief tag, 16 bit length, value */
|
|
|
|
TLV_TYPE_TvLV, /*!< \brief tag, variable length, value */
|
2012-07-13 23:50:33 +00:00
|
|
|
TLV_TYPE_SINGLE_TV, /*!< \brief tag and value (both 4 bit) in 1 byte */
|
|
|
|
TLV_TYPE_vTvLV_GAN, /*!< \brief variable-length tag, variable-length length */
|
2010-02-20 19:34:29 +00:00
|
|
|
};
|
|
|
|
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \brief Definition of a single IE (Information Element) */
|
2010-02-20 19:34:29 +00:00
|
|
|
struct tlv_def {
|
2011-08-17 15:50:55 +00:00
|
|
|
enum tlv_type type; /*!< \brief TLV type */
|
|
|
|
uint8_t fixed_len; /*!< \brief length in case of \ref TLV_TYPE_FIXED */
|
2010-02-20 19:34:29 +00:00
|
|
|
};
|
|
|
|
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \brief Definition of All 256 IE / TLV */
|
2010-02-20 19:34:29 +00:00
|
|
|
struct tlv_definition {
|
2011-07-16 13:42:46 +00:00
|
|
|
struct tlv_def def[256];
|
2010-02-20 19:34:29 +00:00
|
|
|
};
|
|
|
|
|
2011-08-17 15:50:55 +00:00
|
|
|
/*! \brief result of the TLV parser */
|
2010-02-20 19:34:29 +00:00
|
|
|
struct tlv_parsed {
|
2011-07-16 13:42:46 +00:00
|
|
|
struct tlv_p_entry lv[256];
|
2010-02-20 19:34:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern struct tlv_definition tvlv_att_def;
|
2012-07-13 23:50:33 +00:00
|
|
|
extern struct tlv_definition vtvlv_gan_att_def;
|
2010-02-20 19:34:29 +00:00
|
|
|
|
|
|
|
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);
|
2015-12-21 10:20:14 +00:00
|
|
|
/* take a master (src) tlv def and fill up all empty slots in 'dst' */
|
2010-02-20 19:34:29 +00:00
|
|
|
void tlv_def_patch(struct tlv_definition *dst, const struct tlv_definition *src);
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
2014-08-18 13:31:04 +00:00
|
|
|
#define TLVP_PRES_LEN(tp, tag, min_len) \
|
|
|
|
(TLVP_PRESENT(tp, tag) && TLVP_LEN(tp, tag) >= min_len)
|
|
|
|
|
2012-11-06 11:02:59 +00:00
|
|
|
/*! \brief Align given TLV element with 16 bit value to an even address
|
|
|
|
* \param[in] tp pointer to \ref tlv_parsed
|
|
|
|
* \param[in] pos element to return
|
|
|
|
* \returns aligned 16 bit value
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Align given TLV element with 32 bit value to an address that is a multiple of 4
|
|
|
|
* \param[in] tp pointer to \ref tlv_parsed
|
|
|
|
* \param[in] pos element to return
|
|
|
|
* \returns aligned 32 bit value
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-01-02 13:10:30 +00:00
|
|
|
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);
|
2016-04-25 13:19:35 +00:00
|
|
|
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);
|
|
|
|
|
2012-04-18 19:53:23 +00:00
|
|
|
/*! @} */
|