gwenhywfar  4.99.8beta
tlv.c
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Sun Jun 13 2004
3  copyright : (C) 2004-2011 by Martin Preuss
4  email : martin@libchipcard.de
5 
6  ***************************************************************************
7  * Please see toplevel file COPYING for license details *
8  ***************************************************************************/
9 
10 
11 #ifdef HAVE_CONFIG_H
12 # include <config.h>
13 #endif
14 
15 #define DISABLE_DEBUGLOG
16 
17 
18 #include "tlv_p.h"
19 #include <gwenhywfar/debug.h>
20 #include <gwenhywfar/inherit.h>
21 #include <gwenhywfar/misc.h>
22 #include <gwenhywfar/text.h>
23 
24 #include <stdlib.h>
25 #include <assert.h>
26 #include <string.h>
27 
28 #define BER_TLV_TAG_FIRST_BYTE_BYTE_FOLLOWS 0b00011111
29 #define BER_TLV_TAG_SECOND_BYTE_BYTE_FOLLOWS 0b10000000
30 #define BER_TLV_TAG_IS_CONSTRUCTED 0b00100000
31 
33 
34 
36  GWEN_TLV *tlv;
37 
40 
41  return tlv;
42 }
43 
44 
45 
46 void GWEN_TLV_free(GWEN_TLV *tlv) {
47  if (tlv) {
48  free(tlv->tagData);
50  GWEN_FREE_OBJECT(tlv);
51  }
52 }
53 
54 
55 
56 GWEN_TLV *GWEN_TLV_create(unsigned int tagType,
57  unsigned int tagMode,
58  const void *p,
59  unsigned int dlen,
60  int isBerTlv) {
61  GWEN_TLV *tlv;
62 
63  /* some checks first */
64  if (tagType>255) {
65  DBG_ERROR(GWEN_LOGDOMAIN, "Tag type too high");
66  abort();
67  }
68  if (isBerTlv) {
69  if (dlen>65535) {
70  DBG_ERROR(GWEN_LOGDOMAIN, "Data too long");
71  abort();
72  }
73  }
74  else {
75  if (dlen>255) {
76  DBG_ERROR(GWEN_LOGDOMAIN, "Data too long");
77  abort();
78  }
79  }
80 
81  /* limits ok, create TLV */
82  tlv=GWEN_TLV_new();
83  tlv->tagType=tagType;
84  tlv->tagMode=tagMode;
85  tlv->isBerTlv=isBerTlv;
86 
87  tlv->tagLength=dlen;
88  if (dlen) {
89  tlv->tagData=malloc(dlen);
90  assert(tlv->tagData);
91  memmove(tlv->tagData, p, dlen);
92  }
93 
94  return tlv;
95 }
96 
97 
98 
99 int GWEN_TLV_IsBerTlv(const GWEN_TLV *tlv) {
100  assert(tlv);
101  return tlv->isBerTlv;
102 }
103 
104 
105 
106 unsigned int GWEN_TLV_GetTagType(const GWEN_TLV *tlv) {
107  assert(tlv);
108  return tlv->tagType;
109 }
110 
111 
112 
113 unsigned int GWEN_TLV_GetTagLength(const GWEN_TLV *tlv) {
114  assert(tlv);
115  return tlv->tagLength;
116 }
117 
118 
119 
120 unsigned int GWEN_TLV_GetTagSize(const GWEN_TLV *tlv) {
121  assert(tlv);
122  return tlv->tagSize;
123 }
124 
125 
126 
127 const void *GWEN_TLV_GetTagData(const GWEN_TLV *tlv) {
128  assert(tlv);
129  return tlv->tagData;
130 }
131 
132 
133 
134 GWEN_TLV *GWEN_TLV_fromBuffer(GWEN_BUFFER *mbuf, int isBerTlv) {
135  const char *p;
136  unsigned int tagMode;
137  unsigned int tagType;
138  unsigned int tagLength;
139  const char *tagData;
140  unsigned int size;
141  unsigned int pos;
142  unsigned int j;
143  GWEN_TLV *tlv;
144  uint32_t startPos;
145 
146  if (!GWEN_Buffer_GetBytesLeft(mbuf)) {
147  DBG_ERROR(GWEN_LOGDOMAIN, "Buffer empty");
148  return 0;
149  }
150 
151  startPos=GWEN_Buffer_GetPos(mbuf);
152 
153  tagMode=tagType=tagLength=0;
154 
156  pos=0;
157  size=GWEN_Buffer_GetBytesLeft(mbuf);
158 
159  /* get tag type */
160  if (size<2) {
161  DBG_ERROR(GWEN_LOGDOMAIN, "Too few bytes for BER-TLV");
162  return 0;
163  }
164  j=(unsigned char)(p[pos]);
165  tagMode=(j & 0xe0);
166  if (isBerTlv) {
167  if ((j & 0x1f)==0x1f) {
168  pos++;
169  if (pos>=size) {
170  DBG_ERROR(GWEN_LOGDOMAIN, "Too few bytes");
171  return 0;
172  }
173  j=(unsigned char)(p[pos]);
174  }
175  else
176  j&=0x1f;
177  }
178  DBG_DEBUG(GWEN_LOGDOMAIN, "Tag type %02x%s", j,
179  isBerTlv?" (BER-TLV)":"");
180  tagType=j;
181 
182  /* get length */
183  pos++;
184  if (pos>=size) {
185  DBG_ERROR(GWEN_LOGDOMAIN, "Too few bytes");
186  return 0;
187  }
188  j=(unsigned char)(p[pos]);
189  if (isBerTlv) {
190  if (j & 0x80) {
191  if (j==0x81) {
192  pos++;
193  if (pos>=size) {
194  DBG_ERROR(GWEN_LOGDOMAIN, "Too few bytes");
195  return 0;
196  }
197  j=(unsigned char)(p[pos]);
198  } /* 0x81 */
199  else if (j==0x82) {
200  if (pos+1>=size) {
201  DBG_ERROR(GWEN_LOGDOMAIN, "Too few bytes");
202  return 0;
203  }
204  pos++;
205  j=((unsigned char)(p[pos]))<<8;
206  pos++;
207  j+=(unsigned char)(p[pos]);
208  } /* 0x82 */
209  else {
210  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected tag length modifier %02x at %d", j, pos);
211  return 0;
212  }
213  } /* if tag length modifier */
214  }
215  else {
216  if (j==255) {
217  if (pos+2>=size) {
218  DBG_ERROR(GWEN_LOGDOMAIN, "Too few bytes");
219  return 0;
220  }
221  pos++;
222  j=((unsigned char)(p[pos]))<<8;
223  pos++;
224  j+=(unsigned char)(p[pos]);
225  }
226  }
227  pos++;
228  tagLength=j;
229  tagData=p+pos;
230  GWEN_Buffer_IncrementPos(mbuf, pos);
231 
232  DBG_DEBUG(GWEN_LOGDOMAIN, "Tag: %02x (%d bytes)", tagType, tagLength);
233  if (pos+j>size) {
234  DBG_ERROR(GWEN_LOGDOMAIN, "Too few bytes");
235  return 0;
236  }
237 
238  tlv=GWEN_TLV_new();
239  assert(tlv);
240  tlv->isBerTlv=isBerTlv;
241  tlv->tagMode=tagMode;
242  tlv->tagType=tagType;
243  tlv->tagLength=tagLength;
244  if (tagLength) {
245  tlv->tagData=(void*)malloc(tagLength);
246  memmove(tlv->tagData, tagData, tagLength);
247  }
248 
249  GWEN_Buffer_IncrementPos(mbuf, tagLength);
250  tlv->tagSize=GWEN_Buffer_GetPos(mbuf)-startPos;
251  return tlv;
252 }
253 
254 
255 
257  assert(tlv);
258  return (tlv->tagMode & 0x20);
259 }
260 
261 
262 
263 unsigned int GWEN_TLV_GetClass(const GWEN_TLV *tlv) {
264  assert(tlv);
265  return (tlv->tagMode & 0xc0);
266 }
267 
268 
269 
271  assert(tlv);
272  return GWEN_TLV_DirectlyToBuffer(tlv->tagType,
273  tlv->tagMode,
274  tlv->tagData,
275  tlv->tagLength,
276  tlv->isBerTlv,
277  mbuf);
278 }
279 
280 
281 
282 int GWEN_TLV_DirectlyToBuffer(unsigned int tagType,
283  unsigned int tagMode,
284  const void *tagData,
285  int tagLength,
286  int isBerTlv,
287  GWEN_BUFFER *mbuf) {
288  if (tagLength==-1)
289  tagLength=strlen(tagData);
290 
291  if (isBerTlv) {
292  unsigned char j;
293 
294  /* write tag type */
295  j=tagMode;
296  if (tagType>=0x1f) {
297  j|=0x1f;
298  GWEN_Buffer_AppendByte(mbuf, j);
299  GWEN_Buffer_AppendByte(mbuf, (unsigned char)tagType);
300  }
301  else {
302  j|=tagType;
303  GWEN_Buffer_AppendByte(mbuf, j);
304  }
305 
306  /* write tag length */
307  if (tagLength>255) {
308  /* two byte size */
309  GWEN_Buffer_AppendByte(mbuf, 0x82);
310  GWEN_Buffer_AppendByte(mbuf, ((tagLength>>8) & 0xff));
311  GWEN_Buffer_AppendByte(mbuf, (tagLength & 0xff));
312  }
313  else if (tagLength>127) {
314  /* one byte size */
315  GWEN_Buffer_AppendByte(mbuf, 0x81);
316  GWEN_Buffer_AppendByte(mbuf, (tagLength & 0xff));
317  }
318  else {
319  GWEN_Buffer_AppendByte(mbuf, (tagLength & 0x7f));
320  }
321 
322  /* write tag data */
323  if (tagLength)
324  GWEN_Buffer_AppendBytes(mbuf, tagData, tagLength);
325  }
326  else {
327  /* write tag type */
328  GWEN_Buffer_AppendByte(mbuf, (unsigned char)tagType);
329 
330  /* write tag length */
331  GWEN_Buffer_AppendByte(mbuf, (tagLength & 0xff));
332 
333  /* write tag data */
334  if (tagLength)
335  GWEN_Buffer_AppendBytes(mbuf, tagData, tagLength);
336  }
337 
338  return 0;
339 }
340 
341 
342 
343 int GWEN_TLV_ReadHeader(GWEN_TLV *tlv, const uint8_t *p, uint32_t size, int isBerTlv) {
344  uint64_t tagMode;
345  uint64_t tagType;
346  uint64_t tagLength;
347  unsigned int pos;
348  uint64_t j;
349 
350  tagMode=tagType=tagLength=0;
351 
352  pos=0;
353 
354  /* get tag type */
355  if (size<2) {
356  DBG_ERROR(GWEN_LOGDOMAIN, "Too few bytes for TLV");
357  return GWEN_ERROR_BAD_DATA;
358  }
359  j=(unsigned char)(p[pos]);
360  tagMode=(j & 0xe0);
361  if (isBerTlv) {
362  if ((j & 0x1f)==0x1f) {
363  pos++;
364  if (pos>=size) {
365  DBG_ERROR(GWEN_LOGDOMAIN, "Too few bytes");
366  return 0;
367  }
368  j=(unsigned char)(p[pos]);
369  }
370  else
371  j&=0x1f;
372  }
373  DBG_DEBUG(GWEN_LOGDOMAIN, "Tag type %02x%s", j,
374  isBerTlv?" (BER-TLV)":"");
375  tagType=j;
376 
377  /* get length */
378  pos++;
379  if (pos>=size) {
380  DBG_ERROR(GWEN_LOGDOMAIN, "Too few bytes");
381  return GWEN_ERROR_BAD_DATA;
382  }
383  j=(unsigned char)(p[pos]);
384  if (isBerTlv) {
385  if (j & 0x80) {
386  if (j==0x81) {
387  pos++;
388  if (pos>=size) {
389  DBG_ERROR(GWEN_LOGDOMAIN, "Too few bytes");
390  return GWEN_ERROR_BAD_DATA;
391  }
392  j=(unsigned char)(p[pos]);
393  } /* 0x81 */
394  else if (j==0x82) {
395  if (pos+1>=size) {
396  DBG_ERROR(GWEN_LOGDOMAIN, "Too few bytes");
397  return GWEN_ERROR_BAD_DATA;
398  }
399  pos++;
400  j=((unsigned char)(p[pos]))<<8;
401  pos++;
402  j+=(unsigned char)(p[pos]);
403  } /* 0x82 */
404  else if (j==0x83) {
405  if (pos+2>=size) {
406  DBG_ERROR(GWEN_LOGDOMAIN, "Too few bytes");
407  return GWEN_ERROR_BAD_DATA;
408  }
409  pos++;
410  j=((unsigned char)(p[pos]))<<16;
411  pos++;
412  j+=((unsigned char)(p[pos]))<<8;
413  pos++;
414  j+=(unsigned char)(p[pos]);
415  } /* 0x83 */
416  else if (j==0x84) {
417  if (pos+3>=size) {
418  DBG_ERROR(GWEN_LOGDOMAIN, "Too few bytes");
419  return GWEN_ERROR_BAD_DATA;
420  }
421  pos++;
422  j=((unsigned char)(p[pos]))<<24;
423  pos++;
424  j+=((unsigned char)(p[pos]))<<16;
425  pos++;
426  j+=((unsigned char)(p[pos]))<<8;
427  pos++;
428  j+=(unsigned char)(p[pos]);
429  } /* 0x84 */
430  else if (j==0x85) {
431  if (pos+4>=size) {
432  DBG_ERROR(GWEN_LOGDOMAIN, "Too few bytes");
433  return GWEN_ERROR_BAD_DATA;
434  }
435  pos++;
436  j=((uint64_t) ((unsigned char)(p[pos])))<<32;
437  pos++;
438  j+=((uint64_t) ((unsigned char)(p[pos])))<<24;
439  pos++;
440  j+=((uint64_t) ((unsigned char)(p[pos])))<<16;
441  pos++;
442  j+=((uint64_t) ((unsigned char)(p[pos])))<<8;
443  pos++;
444  j+=(unsigned char)(p[pos]);
445  } /* 0x85 */
446  else {
447  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected tag length modifier %02x at %d", (int) j, pos);
448  return GWEN_ERROR_BAD_DATA;
449  }
450  } /* if tag length modifier */
451  }
452  else {
453  if (j==255) {
454  if (pos+2>=size) {
455  DBG_ERROR(GWEN_LOGDOMAIN, "Too few bytes");
456  return GWEN_ERROR_BAD_DATA;
457  }
458  pos++;
459  j=((unsigned char)(p[pos]))<<8;
460  pos++;
461  j+=(unsigned char)(p[pos]);
462  }
463  }
464  pos++;
465  tagLength=j;
466 
467  DBG_DEBUG(GWEN_LOGDOMAIN, "Tag: %02x (%d bytes)", tagType, tagLength);
468 
469  tlv->isBerTlv=isBerTlv;
470  tlv->tagMode=tagMode;
471  tlv->tagType=tagType;
472  tlv->tagLength=tagLength;
473 
474  tlv->tagSize=pos+tagLength;
475  return (int) pos;
476 }
477 
478 
479 
480 int GWEN_TLV_WriteHeader(unsigned int tagType,
481  unsigned int tagMode,
482  uint64_t tagLength,
483  int isBerTlv,
484  GWEN_BUFFER *mbuf) {
485  if (isBerTlv) {
486  unsigned char j;
487 
488  /* write tag type */
489  j=tagMode;
490  if (tagType>=0x1f) {
491  j|=0x1f;
492  GWEN_Buffer_AppendByte(mbuf, j);
493  GWEN_Buffer_AppendByte(mbuf, (unsigned char)tagType);
494  }
495  else {
496  j|=tagType;
497  GWEN_Buffer_AppendByte(mbuf, j);
498  }
499 
500  /* write tag length */
501  if (tagLength>0xffffffffLL) {
502  /* five byte size */
503  GWEN_Buffer_AppendByte(mbuf, 0x85);
504  GWEN_Buffer_AppendByte(mbuf, ((tagLength>>32) & 0xff));
505  GWEN_Buffer_AppendByte(mbuf, ((tagLength>>24) & 0xff));
506  GWEN_Buffer_AppendByte(mbuf, ((tagLength>>16) & 0xff));
507  GWEN_Buffer_AppendByte(mbuf, ((tagLength>>8) & 0xff));
508  GWEN_Buffer_AppendByte(mbuf, (tagLength & 0xff));
509  }
510  else if (tagLength>0xffffffL) {
511  /* four byte size */
512  GWEN_Buffer_AppendByte(mbuf, 0x84);
513  GWEN_Buffer_AppendByte(mbuf, ((tagLength>>24) & 0xff));
514  GWEN_Buffer_AppendByte(mbuf, ((tagLength>>16) & 0xff));
515  GWEN_Buffer_AppendByte(mbuf, ((tagLength>>8) & 0xff));
516  GWEN_Buffer_AppendByte(mbuf, (tagLength & 0xff));
517  }
518  else if (tagLength>0xffff) {
519  /* three byte size */
520  GWEN_Buffer_AppendByte(mbuf, 0x83);
521  GWEN_Buffer_AppendByte(mbuf, ((tagLength>>16) & 0xff));
522  GWEN_Buffer_AppendByte(mbuf, ((tagLength>>8) & 0xff));
523  GWEN_Buffer_AppendByte(mbuf, (tagLength & 0xff));
524  }
525  else if (tagLength>0xff) {
526  /* two byte size */
527  GWEN_Buffer_AppendByte(mbuf, 0x82);
528  GWEN_Buffer_AppendByte(mbuf, ((tagLength>>8) & 0xff));
529  GWEN_Buffer_AppendByte(mbuf, (tagLength & 0xff));
530  }
531  else if (tagLength>127) {
532  /* one byte size */
533  GWEN_Buffer_AppendByte(mbuf, 0x81);
534  GWEN_Buffer_AppendByte(mbuf, (tagLength & 0xff));
535  }
536  else {
537  GWEN_Buffer_AppendByte(mbuf, (tagLength & 0x7f));
538  }
539  }
540  else {
541  /* write tag type */
542  GWEN_Buffer_AppendByte(mbuf, (unsigned char)tagType);
543 
544  /* write tag length */
545  GWEN_Buffer_AppendByte(mbuf, (tagLength & 0xff));
546  }
547 
548  return 0;
549 }
550 
551 static void hex2char(char byte, char* character)
552 {
553  uint8_t nibbles[2];
554  int i;
555  nibbles[0]=(byte>>4) &0x0f;
556  nibbles[1]=byte & 0x0f;
557 
558  for ( i = 0 ; i < 2 ; i++ )
559  {
560  switch (nibbles[i])
561  {
562  case 0:
563  character[i]='0';
564  break;
565  case 1:
566  character[i]='1';
567  break;
568  case 2:
569  character[i]='2';
570  break;
571  case 3:
572  character[i]='3';
573  break;
574  case 4:
575  character[i]='4';
576  break;
577  case 5:
578  character[i]='5';
579  break;
580  case 6:
581  character[i]='6';
582  break;
583  case 7:
584  character[i]='7';
585  break;
586  case 8:
587  character[i]='8';
588  break;
589  case 9:
590  character[i]='9';
591  break;
592  case 10:
593  character[i]='A';
594  break;
595  case 11:
596  character[i]='B';
597  break;
598  case 12:
599  character[i]='C';
600  break;
601  case 13:
602  character[i]='D';
603  break;
604  case 14:
605  character[i]='E';
606  break;
607  case 15:
608  character[i]='F';
609  break;
610  }
611  }
612 }
613 
614 int GWEN_TLV_Buffer_To_DB(GWEN_DB_NODE *dbRecord, GWEN_BUFFER *mbuf, int len)
615 {
616  int tlv_len=0;
617  unsigned int tag_len=0;
618  unsigned int data_len;
619  char byte;
620  int isConstructed;
621  int anotherByte;
622  char tag[128];
623  GWEN_DB_NODE *dbTLV;
624 
625 
626  /* get first byte */
627  while (tlv_len < len)
628  {
629 
630  tag_len=0;
631  memset(tag,'\0',128);
632  byte = GWEN_Buffer_ReadByte(mbuf);
633  isConstructed = byte & BER_TLV_TAG_IS_CONSTRUCTED;
634  tlv_len++;
635  hex2char(byte,&tag[tag_len++]);
637  while (anotherByte)
638  {
639  byte = GWEN_Buffer_ReadByte(mbuf);
640  tlv_len++;
641  hex2char(byte,&tag[tag_len++]);
642  anotherByte= byte > 127;
643  }
644  dbTLV=GWEN_DB_Group_new(tag);
645  byte = GWEN_Buffer_ReadByte(mbuf);
646  tlv_len++;
647  if ( byte == 0x81)
648  {
649  data_len=127;
650  byte = GWEN_Buffer_ReadByte(mbuf);
651  tlv_len++;
652  if ( byte == 0x82 )
653  {
654  data_len=255;
655  byte = GWEN_Buffer_ReadByte(mbuf);
656  tlv_len++;
657  data_len+= (uint8_t) byte;
658  }
659  else
660  {
661  data_len+= (uint8_t) byte;
662  }
663 
664  }
665  else
666  {
667  data_len= (uint8_t) byte;
668  }
669  GWEN_DB_SetIntValue(dbTLV,0,"length",data_len);
670  if (isConstructed)
671  {
672  tlv_len+=GWEN_TLV_Buffer_To_DB(dbTLV,mbuf,data_len);
673  }
674 
675 
676  else
677  {
678  char *buffer;
679 
680  buffer=(char*)GWEN_Memory_malloc((data_len*2)+1);
681  assert(buffer);
683  buffer, data_len*2+1);
684  GWEN_DB_SetCharValue(dbTLV,0,"data",buffer);
685  GWEN_DB_SetBinValue(dbTLV,0,"dataBin",GWEN_Buffer_GetPosPointer(mbuf),data_len);
686  GWEN_Memory_dealloc(buffer);
687  GWEN_Buffer_IncrementPos(mbuf,data_len);
688  tlv_len+=data_len;
689 
690  }
691  GWEN_DB_AddGroup(dbRecord,dbTLV);
692  }
693  assert(len==tlv_len);
694  return tlv_len;
695 }
696 
697 
698 
699 
700 
701 
struct GWEN_TLV GWEN_TLV
Definition: tlv.h:19
uint32_t GWEN_Buffer_GetBytesLeft(GWEN_BUFFER *bf)
Definition: buffer.c:577
int GWEN_TLV_IsBerTlv(const GWEN_TLV *tlv)
Definition: tlv.c:99
struct GWEN_DB_NODE GWEN_DB_NODE
Definition: db.h:228
static void hex2char(char byte, char *character)
Definition: tlv.c:551
void GWEN_TLV_free(GWEN_TLV *tlv)
Definition: tlv.c:46
GWEN_TLV * GWEN_TLV_create(unsigned int tagType, unsigned int tagMode, const void *p, unsigned int dlen, int isBerTlv)
Definition: tlv.c:56
#define GWEN_FREE_OBJECT(varname)
Definition: memory.h:92
void GWEN_Memory_dealloc(void *p)
Definition: memory.c:472
int GWEN_TLV_ReadHeader(GWEN_TLV *tlv, const uint8_t *p, uint32_t size, int isBerTlv)
Definition: tlv.c:343
#define GWEN_LOGDOMAIN
Definition: logger.h:35
uint32_t GWEN_Buffer_GetPos(const GWEN_BUFFER *bf)
Definition: buffer.c:239
int GWEN_TLV_DirectlyToBuffer(unsigned int tagType, unsigned int tagMode, const void *tagData, int tagLength, int isBerTlv, GWEN_BUFFER *mbuf)
Definition: tlv.c:282
char * GWEN_Buffer_GetPosPointer(const GWEN_BUFFER *bf)
Definition: buffer.c:588
int GWEN_Buffer_IncrementPos(GWEN_BUFFER *bf, uint32_t i)
Definition: buffer.c:495
unsigned int GWEN_TLV_GetTagType(const GWEN_TLV *tlv)
Definition: tlv.c:106
#define BER_TLV_TAG_FIRST_BYTE_BYTE_FOLLOWS
Definition: tlv.c:28
#define GWEN_ERROR_BAD_DATA
Definition: error.h:121
int GWEN_DB_AddGroup(GWEN_DB_NODE *n, GWEN_DB_NODE *nn)
Definition: db.c:1358
int GWEN_DB_SetBinValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, const void *val, unsigned int valSize)
Definition: db.c:1151
#define GWEN_NEW_OBJECT(typ, varname)
Definition: memory.h:86
#define DBG_DEBUG(dbg_logger, format, args...)
Definition: debug.h:192
unsigned int GWEN_TLV_GetClass(const GWEN_TLV *tlv)
Definition: tlv.c:263
void * GWEN_Memory_malloc(size_t wsize)
Definition: memory.c:385
#define BER_TLV_TAG_IS_CONSTRUCTED
Definition: tlv.c:30
int GWEN_Buffer_AppendByte(GWEN_BUFFER *bf, char c)
Definition: buffer.c:380
GWEN_TLV * GWEN_TLV_new(void)
Definition: tlv.c:35
int GWEN_TLV_IsContructed(const GWEN_TLV *tlv)
Definition: tlv.c:256
const void * GWEN_TLV_GetTagData(const GWEN_TLV *tlv)
Definition: tlv.c:127
unsigned int GWEN_TLV_GetTagSize(const GWEN_TLV *tlv)
Definition: tlv.c:120
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition: buffer.h:41
int GWEN_TLV_WriteHeader(unsigned int tagType, unsigned int tagMode, uint64_t tagLength, int isBerTlv, GWEN_BUFFER *mbuf)
Definition: tlv.c:480
#define DBG_ERROR(dbg_logger, format, args...)
Definition: debug.h:97
char * GWEN_Text_ToHex(const char *src, unsigned l, char *buffer, unsigned int maxsize)
Definition: text.c:622
int GWEN_DB_SetCharValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, const char *val)
Definition: db.c:922
unsigned int GWEN_TLV_GetTagLength(const GWEN_TLV *tlv)
Definition: tlv.c:113
int GWEN_TLV_toBuffer(GWEN_TLV *tlv, GWEN_BUFFER *mbuf)
Definition: tlv.c:270
int GWEN_Buffer_ReadByte(GWEN_BUFFER *bf)
Definition: buffer.c:477
#define GWEN_LIST_INIT(t, element)
Definition: list1.h:465
GWEN_TLV * GWEN_TLV_fromBuffer(GWEN_BUFFER *mbuf, int isBerTlv)
Definition: tlv.c:134
int GWEN_TLV_Buffer_To_DB(GWEN_DB_NODE *dbRecord, GWEN_BUFFER *mbuf, int len)
Definition: tlv.c:614
int GWEN_Buffer_AppendBytes(GWEN_BUFFER *bf, const char *buffer, uint32_t size)
Definition: buffer.c:348
GWEN_DB_NODE * GWEN_DB_Group_new(const char *name)
Definition: db.c:131
int GWEN_DB_SetIntValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, int val)
Definition: db.c:1086
#define GWEN_LIST_FUNCTIONS(t, pr)
Definition: list1.h:366
#define GWEN_LIST_FINI(t, element)
Definition: list1.h:474