9206d3b0 |
1 | #ifndef __TLV_H |
2 | #define __TLV_H |
3 | |
4 | #include <stdint.h> |
9206d3b0 |
5 | #include <string.h> |
e04f23fa |
6 | #include <stddef.h> |
9206d3b0 |
7 | |
8 | //structure buffer definitions |
9 | #define TAG_LENGTH 2 |
10 | #define VALUE_LENGTH 1024 |
11 | |
12 | //masks |
13 | //if TLV_TAG_NUMBER_MASK bits are set, refer to the next byte for the tag number |
14 | //otherwise its located in bits 1-5 |
15 | #define TLV_TAG_NUMBER_MASK 0x1f |
16 | //if TLV_DATA_MASK set then its a 'constructed data object' |
17 | //otherwise a 'primitive data object' |
18 | #define TLV_DATA_MASK 0x20 |
19 | #define TLV_TAG_MASK 0x80 |
20 | #define TLV_LENGTH_MASK 0x80 |
21 | |
22 | //tlv tag structure, tag can be max of 2 bytes, length up to 65535 and value 1024 bytes long |
23 | typedef struct { |
24 | uint8_t tag[TAG_LENGTH]; |
25 | uint16_t fieldlength; |
26 | uint16_t valuelength; |
27 | uint8_t value[VALUE_LENGTH]; |
28 | }tlvtag; |
29 | |
30 | //decode a BER TLV |
31 | extern int decode_ber_tlv_item(uint8_t* data, tlvtag* returnedtag); |
32 | extern int encode_ber_tlv_item(uint8_t* tag, uint8_t taglen, uint8_t*data, uint32_t datalen, uint8_t* outputtag, uint32_t* outputtaglen); |
33 | #endif //__TLV_H |