gwenhywfar 5.14.1
tlv.c File Reference
#include "tlv_p.h"
#include <gwenhywfar/debug.h>
#include <gwenhywfar/inherit.h>
#include <gwenhywfar/misc.h>
#include <gwenhywfar/text.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
Include dependency graph for tlv.c:

Go to the source code of this file.

Macros

#define BER_TLV_TAG_FIRST_BYTE_BYTE_FOLLOWS   0b00011111
#define BER_TLV_TAG_IS_CONSTRUCTED   0b00100000
#define BER_TLV_TAG_SECOND_BYTE_BYTE_FOLLOWS   0b10000000
#define DISABLE_DEBUGLOG

Functions

int GWEN_TLV_Buffer_To_DB (GWEN_DB_NODE *dbRecord, GWEN_BUFFER *mbuf, int len)
GWEN_TLVGWEN_TLV_create (unsigned int tagType, unsigned int tagMode, const void *p, unsigned int dlen, int isBerTlv)
int GWEN_TLV_DirectlyToBuffer (unsigned int tagType, unsigned int tagMode, const void *tagData, int tagLength, int isBerTlv, GWEN_BUFFER *mbuf)
void GWEN_TLV_free (GWEN_TLV *tlv)
GWEN_TLVGWEN_TLV_fromBuffer (GWEN_BUFFER *mbuf, int isBerTlv)
unsigned int GWEN_TLV_GetClass (const GWEN_TLV *tlv)
const void * GWEN_TLV_GetTagData (const GWEN_TLV *tlv)
unsigned int GWEN_TLV_GetTagLength (const GWEN_TLV *tlv)
unsigned int GWEN_TLV_GetTagSize (const GWEN_TLV *tlv)
unsigned int GWEN_TLV_GetTagType (const GWEN_TLV *tlv)
int GWEN_TLV_IsBerTlv (const GWEN_TLV *tlv)
int GWEN_TLV_IsContructed (const GWEN_TLV *tlv)
GWEN_TLVGWEN_TLV_new (void)
uint32_t GWEN_TLV_ParseLength (GWEN_BUFFER *mbuf, uint32_t *tag_len_len)
int GWEN_TLV_ReadHeader (GWEN_TLV *tlv, const uint8_t *p, uint32_t size, int isBerTlv)
int GWEN_TLV_toBuffer (GWEN_TLV *tlv, GWEN_BUFFER *mbuf)
int GWEN_TLV_WriteHeader (unsigned int tagType, unsigned int tagMode, uint64_t tagLength, int isBerTlv, GWEN_BUFFER *mbuf)
static void hex2char (char byte, char *character)

Macro Definition Documentation

◆ BER_TLV_TAG_FIRST_BYTE_BYTE_FOLLOWS

#define BER_TLV_TAG_FIRST_BYTE_BYTE_FOLLOWS   0b00011111

Definition at line 28 of file tlv.c.

Referenced by GWEN_TLV_Buffer_To_DB(), and GWEN_TLV_ParseLength().

◆ BER_TLV_TAG_IS_CONSTRUCTED

#define BER_TLV_TAG_IS_CONSTRUCTED   0b00100000

Definition at line 30 of file tlv.c.

Referenced by GWEN_TLV_Buffer_To_DB().

◆ BER_TLV_TAG_SECOND_BYTE_BYTE_FOLLOWS

#define BER_TLV_TAG_SECOND_BYTE_BYTE_FOLLOWS   0b10000000

Definition at line 29 of file tlv.c.

◆ DISABLE_DEBUGLOG

#define DISABLE_DEBUGLOG

Definition at line 15 of file tlv.c.

Function Documentation

◆ GWEN_TLV_Buffer_To_DB()

int GWEN_TLV_Buffer_To_DB ( GWEN_DB_NODE * dbRecord,
GWEN_BUFFER * mbuf,
int len )

Directly parses a BER-TLV structure do a DB.

Returns
number of bytes parsed
Parameters
dbRecordGWEN_DB database with the parsed TLV structure
mbufbuffer holding the TLV data
lenlength of the data in the buffer

Definition at line 629 of file tlv.c.

References BER_TLV_TAG_FIRST_BYTE_BYTE_FOLLOWS, BER_TLV_TAG_IS_CONSTRUCTED, GWEN_Buffer_GetPosPointer(), GWEN_Buffer_IncrementPos(), GWEN_Buffer_ReadByte(), GWEN_DB_AddGroup(), GWEN_DB_Group_new(), GWEN_DB_SetBinValue(), GWEN_DB_SetCharValue(), GWEN_DB_SetIntValue(), GWEN_Memory_dealloc(), GWEN_Memory_malloc(), GWEN_Text_ToHex(), GWEN_TLV_Buffer_To_DB(), and hex2char().

Referenced by GWEN_TLV_Buffer_To_DB().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_TLV_create()

GWEN_TLV * GWEN_TLV_create ( unsigned int tagType,
unsigned int tagMode,
const void * p,
unsigned int dlen,
int isBerTlv )

Definition at line 58 of file tlv.c.

References DBG_ERROR, GWEN_LOGDOMAIN, and GWEN_TLV_new().

Here is the call graph for this function:

◆ GWEN_TLV_DirectlyToBuffer()

int GWEN_TLV_DirectlyToBuffer ( unsigned int tagType,
unsigned int tagMode,
const void * tagData,
int tagLength,
int isBerTlv,
GWEN_BUFFER * mbuf )

Definition at line 294 of file tlv.c.

References GWEN_Buffer_AppendByte(), and GWEN_Buffer_AppendBytes().

Referenced by GWEN_Sar_AddAndDigestFileLink(), GWEN_Sar_AddFile(), GWEN_Sar_FileHeaderToTlv(), GWEN_Sar_Sign(), and GWEN_TLV_toBuffer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_TLV_free()

void GWEN_TLV_free ( GWEN_TLV * tlv)

Definition at line 47 of file tlv.c.

References GWEN_FREE_OBJECT, and GWEN_LIST_FINI.

Referenced by GWEN_Sar_ScanFile().

Here is the caller graph for this function:

◆ GWEN_TLV_fromBuffer()

GWEN_TLV * GWEN_TLV_fromBuffer ( GWEN_BUFFER * mbuf,
int isBerTlv )

Definition at line 142 of file tlv.c.

References DBG_DEBUG, DBG_ERROR, GWEN_Buffer_GetBytesLeft(), GWEN_Buffer_GetPos(), GWEN_Buffer_GetPosPointer(), GWEN_Buffer_IncrementPos(), GWEN_LOGDOMAIN, and GWEN_TLV_new().

Referenced by GWEN_Sar_TlvToFileHeader().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_TLV_GetClass()

unsigned int GWEN_TLV_GetClass ( const GWEN_TLV * tlv)

Definition at line 273 of file tlv.c.

◆ GWEN_TLV_GetTagData()

const void * GWEN_TLV_GetTagData ( const GWEN_TLV * tlv)

Definition at line 134 of file tlv.c.

Referenced by GWEN_Sar_TlvToFileHeader().

Here is the caller graph for this function:

◆ GWEN_TLV_GetTagLength()

unsigned int GWEN_TLV_GetTagLength ( const GWEN_TLV * tlv)

Definition at line 118 of file tlv.c.

Referenced by GWEN_Sar_ScanFile(), and GWEN_Sar_TlvToFileHeader().

Here is the caller graph for this function:

◆ GWEN_TLV_GetTagSize()

unsigned int GWEN_TLV_GetTagSize ( const GWEN_TLV * tlv)

Definition at line 126 of file tlv.c.

Referenced by GWEN_Sar_ScanFile().

Here is the caller graph for this function:

◆ GWEN_TLV_GetTagType()

unsigned int GWEN_TLV_GetTagType ( const GWEN_TLV * tlv)

Definition at line 110 of file tlv.c.

Referenced by GWEN_Sar_ScanFile(), and GWEN_Sar_TlvToFileHeader().

Here is the caller graph for this function:

◆ GWEN_TLV_IsBerTlv()

int GWEN_TLV_IsBerTlv ( const GWEN_TLV * tlv)

Definition at line 102 of file tlv.c.

◆ GWEN_TLV_IsContructed()

int GWEN_TLV_IsContructed ( const GWEN_TLV * tlv)

Definition at line 265 of file tlv.c.

◆ GWEN_TLV_new()

GWEN_TLV * GWEN_TLV_new ( void )

Definition at line 35 of file tlv.c.

References GWEN_LIST_INIT, GWEN_NEW_OBJECT, and GWEN_TLV_new().

Referenced by GWEN_Sar_ScanFile(), GWEN_TLV_create(), GWEN_TLV_fromBuffer(), and GWEN_TLV_new().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_TLV_ParseLength()

uint32_t GWEN_TLV_ParseLength ( GWEN_BUFFER * mbuf,
uint32_t * tag_len_len )

Parses length of a BER-TLV structure.

Returns
number of bytes including the tag itself
Parameters
mbufbuffer holding the TLV data
tag_len_lennumber of bytes used for tag identifier octets and length octets

Definition at line 699 of file tlv.c.

References BER_TLV_TAG_FIRST_BYTE_BYTE_FOLLOWS, DBG_INFO, GWEN_Buffer_ReadByte(), and GWEN_LOGDOMAIN.

Here is the call graph for this function:

◆ GWEN_TLV_ReadHeader()

int GWEN_TLV_ReadHeader ( GWEN_TLV * tlv,
const uint8_t * p,
uint32_t size,
int isBerTlv )

Reads a TLV header from a buffer (tag and length) and returns the number of bytes used by the header.

Returns
number of bytes used to specify tag and length (i.e. TLV size without the data part)
Parameters
tlvTLV to read the header into
ppointer to a buffer containing at least the header
sizesiez of the buffer pointed to by p
isBerTlvif !=0 then the TLV is supposed to be a BER-TLV object

Definition at line 356 of file tlv.c.

References DBG_DEBUG, DBG_ERROR, GWEN_ERROR_BAD_DATA, and GWEN_LOGDOMAIN.

Referenced by GWEN_Sar_ScanFile().

Here is the caller graph for this function:

◆ GWEN_TLV_toBuffer()

int GWEN_TLV_toBuffer ( GWEN_TLV * tlv,
GWEN_BUFFER * mbuf )

Definition at line 281 of file tlv.c.

References GWEN_TLV_DirectlyToBuffer().

Here is the call graph for this function:

◆ GWEN_TLV_WriteHeader()

int GWEN_TLV_WriteHeader ( unsigned int tagType,
unsigned int tagMode,
uint64_t tagLength,
int isBerTlv,
GWEN_BUFFER * mbuf )

Directly writes a TLV header (tag and length) to the given buffer.

Returns
0 if ok, error code otherwise
Parameters
tagTypetag id
tagModebits 5, 6 and 7 of the first TLV byte (bits 6/7: class, bit 5: constructed)
tagLengthlength of the data part introduced by the TLV header
isBerTlvif !=0 then the TLV is supposed to be a BER-TLV object
mbufbuffer to receive the TLV header

Definition at line 494 of file tlv.c.

References GWEN_Buffer_AppendByte().

Referenced by GWEN_Sar_AddAndDigestFileReg(), and GWEN_Sar_AddFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hex2char()

void hex2char ( char byte,
char * character )
static

Definition at line 566 of file tlv.c.

Referenced by GWEN_TLV_Buffer_To_DB().

Here is the caller graph for this function: