automotive-dlt
dlt_common.c
Go to the documentation of this file.
1 /*
2  * @licence app begin@
3  * SPDX license identifier: MPL-2.0
4  *
5  * Copyright (C) 2011-2015, BMW AG
6  *
7  * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
8  *
9  * This Source Code Form is subject to the terms of the
10  * Mozilla Public License (MPL), v. 2.0.
11  * If a copy of the MPL was not distributed with this file,
12  * You can obtain one at http://mozilla.org/MPL/2.0/.
13  *
14  * For further information see http://www.genivi.org/.
15  * @licence end@
16  */
17 
30 #include <stdio.h>
31 #include <stdlib.h> /* for malloc(), free() */
32 #include <string.h> /* for strlen(), memcmp(), memmove() */
33 #include <time.h> /* for localtime(), strftime() */
34 #include <limits.h> /* for NAME_MAX */
35 #include <inttypes.h> /* for PRI formatting macro */
36 #include <stdarg.h>
37 
38 #include <errno.h>
39 #include <sys/stat.h> /* for mkdir() */
40 
41 #include "dlt_user_shared.h"
42 #include "dlt_common.h"
43 #include "dlt_common_cfg.h"
44 
45 #include "dlt_version.h"
46 
47 #if defined (__WIN32__) || defined (_MSC_VER)
48 #include <winsock2.h> /* for socket(), connect(), send(), and recv() */
49 #else
50 #include <sys/socket.h> /* for socket(), connect(), send(), and recv() */
51 #include <syslog.h>
52 #include <time.h> /* for clock_gettime() */
53 #endif
54 
55 #if defined (_MSC_VER)
56 #include <io.h>
57 #else
58 #include <unistd.h> /* for read(), close() */
59 #include <sys/time.h> /* for gettimeofday() */
60 #endif
61 
62 #if defined (__MSDOS__) || defined (_MSC_VER)
63 #pragma warning(disable : 4996) /* Switch off C4996 warnings */
64 #include <windows.h>
65 #include <winbase.h>
66 #endif
67 
69 
70 const char dltSerialHeader[DLT_ID_SIZE] = { 'D','L','S',1 };
71 char dltSerialHeaderChar[DLT_ID_SIZE] = { 'D','L','S',1 };
72 char dltFifoBaseDir[PATH_MAX + 1] = "/tmp";
73 
74 /* internal logging parameters */
76 static int logging_level = LOG_INFO;
77 static char logging_filename[NAME_MAX + 1] = "";
78 static FILE *logging_handle = NULL;
79 
80 char *message_type[] = {"log","app_trace","nw_trace","control","","","",""};
81 char *log_info[] = {"","fatal","error","warn","info","debug","verbose","","","","","","","","",""};
82 char *trace_type[] = {"","variable","func_in","func_out","state","vfb","","","","","","","","","",""};
83 char *nw_trace_type[] = {"","ipc","can","flexray","most","vfb","","","","","","","","","",""};
84 char *control_type[] = {"","request","response","time","","","","","","","","","","","",""};
85 static char *service_id[] = {"","set_log_level","set_trace_status","get_log_info","get_default_log_level","store_config","reset_to_factory_default",
86  "set_com_interface_status","set_com_interface_max_bandwidth","set_verbose_mode","set_message_filtering","set_timing_packets",
87  "get_local_time","use_ecu_id","use_session_id","use_timestamp","use_extended_header","set_default_log_level","set_default_trace_status",
88  "get_software_version","message_buffer_overflow"
89  };
90 static char *return_type[] = {"ok","not_supported","error","","","","","","no_matching_context_id"};
91 
92 /* internal function definitions */
93 int dlt_buffer_get(DltBuffer *buf,unsigned char *data, int max_size,int delete);
94 int dlt_buffer_reset(DltBuffer *buf);
97 void dlt_buffer_write_block(DltBuffer *buf,int *write, const unsigned char *data,unsigned int size);
98 void dlt_buffer_read_block(DltBuffer *buf,int *read,unsigned char *data,unsigned int size);
99 
100 void dlt_print_hex(uint8_t *ptr,int size)
101 {
102  int num;
103 
104  if (ptr == NULL)
105  {
106  return;
107  }
108 
109  for (num=0;num<size;num++)
110  {
111  if (num>0)
112  {
113  printf(" ");
114  }
115 
116  printf("%.2x",((uint8_t*)ptr)[num]);
117  }
118 }
119 
120 DltReturnValue dlt_print_hex_string(char *text, int textlength, uint8_t *ptr, int size)
121 {
122  int num;
123 
124  if ((ptr == NULL) || (text == NULL) || (textlength <= 0) || (size < 0))
125  {
127  }
128 
129  /* Length 3: AB_ , A is first digit of hex number, B is second digit of hex number, _ is space */
130  if (textlength<(size*3))
131  {
132  char str[255];
133  snprintf(str, 254, "String does not fit hex data (available=%d, required=%d) !\n", textlength, size*3);
134  dlt_log(LOG_WARNING, str);
135  return DLT_RETURN_ERROR;
136  }
137 
138  for (num=0; num<size; num++)
139  {
140  if (num>0)
141  {
142  snprintf(text,2," ");
143  text++;
144  }
145 
146  snprintf(text,3,"%.2x",((uint8_t*)ptr)[num]);
147  text+=2; /* 2 chars */
148  }
149 
150  return DLT_RETURN_OK;
151 }
152 
153 DltReturnValue dlt_print_mixed_string(char *text, int textlength ,uint8_t *ptr, int size, int html)
154 {
155  int required_size = 0;
156  int lines, rest, i;
157 
158  if ((ptr == NULL) || (text == NULL) || (textlength <= 0) || (size < 0))
159  {
161  }
162 
163  /* Check maximum required size and do a length check */
164  if (html == 0)
165  {
167  ((size/DLT_COMMON_HEX_CHARS) + 1);
168  /* Example: (8 chars line number + (2*16 chars + 15 spaces) + space + 16 ascii chars + CR) *
169  ((size/16) lines + extra line for the rest) */
170  }
171  else
172  {
174  ((size/DLT_COMMON_HEX_CHARS) + 1);
175  /* Example: (8 chars line number + (2*16 chars + 15 spaces) + space + 16 ascii chars + 4 [HTML CR: <BR>]) *
176  ((size/16) lines + extra line for the rest) */
177  }
178 
179  if (textlength<required_size)
180  {
181  snprintf(str,DLT_COMMON_BUFFER_LENGTH, "String does not fit mixed data (available=%d, required=%d) !\n", textlength, required_size);
182  dlt_log(LOG_WARNING, str);
183  return DLT_RETURN_ERROR;
184  }
185 
186  /* print full lines */
187  for (lines=0; lines< (size / DLT_COMMON_HEX_CHARS); lines++)
188  {
189  int ret = 0;
190  /* Line number */
191  ret = snprintf(text,DLT_COMMON_HEX_LINELEN+1,"%.6x: ",lines * DLT_COMMON_HEX_CHARS);
192  if ((ret < 0 ) || (ret >= (DLT_COMMON_HEX_LINELEN + 1)))
193  dlt_log(LOG_WARNING, "line was truncated\n");
194  text+=DLT_COMMON_HEX_LINELEN; /* 'XXXXXX: ' */
195 
196  /* Hex-Output */
197  /* It is not required to decrement textlength, as it was already checked, that
198  there is enough space for the complete output */
199  dlt_print_hex_string(text,textlength,(uint8_t*)(ptr+(lines*DLT_COMMON_HEX_CHARS)),DLT_COMMON_HEX_CHARS);
200  text+=((2*DLT_COMMON_HEX_CHARS)+(DLT_COMMON_HEX_CHARS-1)); /* 32 characters + 15 spaces */
201 
202  snprintf(text,2," ");
203  text+=DLT_COMMON_CHARLEN;
204 
205  /* Char-Output */
206  /* It is not required to decrement textlength, as it was already checked, that
207  there is enough space for the complete output */
208  dlt_print_char_string(&text,textlength,(uint8_t*)(ptr+(lines*DLT_COMMON_HEX_CHARS)),DLT_COMMON_HEX_CHARS);
209 
210  if (html==0)
211  {
212  snprintf(text,2,"\n");
213  text+=DLT_COMMON_CHARLEN;
214  }
215  else
216  {
217  snprintf(text,5,"<BR>");
218  text+=(4*DLT_COMMON_CHARLEN);
219  }
220  }
221 
222  /* print partial line */
223  rest = size % DLT_COMMON_HEX_CHARS;
224 
225  if (rest>0)
226  {
227  /* Line number */
228  int ret = 0;
229  ret = snprintf(text,9,"%.6x: ", (size / DLT_COMMON_HEX_CHARS) * DLT_COMMON_HEX_CHARS);
230  if ((ret < 0) || (ret >= 9))
231  {
232  dlt_log(LOG_WARNING, "line number was truncated");
233  }
234  text+=DLT_COMMON_HEX_LINELEN; /* 'XXXXXX: ' */
235 
236  /* Hex-Output */
237  /* It is not required to decrement textlength, as it was already checked, that
238  there is enough space for the complete output */
239  dlt_print_hex_string(text,textlength,(uint8_t*)(ptr+ ((size / DLT_COMMON_HEX_CHARS) * DLT_COMMON_HEX_CHARS)),rest);
240  text+=2*rest+(rest-1);
241 
242  for (i=0;i<(DLT_COMMON_HEX_CHARS-rest);i++)
243  {
244  snprintf(text,4," xx");
245  text+=(3*DLT_COMMON_CHARLEN);
246  }
247 
248  snprintf(text,2," ");
249  text+=DLT_COMMON_CHARLEN;
250 
251  /* Char-Output */
252  /* It is not required to decrement textlength, as it was already checked, that
253  there is enough space for the complete output */
254  dlt_print_char_string(&text,textlength,(uint8_t*)(ptr+ ((size / DLT_COMMON_HEX_CHARS) * DLT_COMMON_HEX_CHARS)),rest);
255  }
256 
257  return DLT_RETURN_OK;
258 }
259 
260 DltReturnValue dlt_print_char_string(char **text, int textlength, uint8_t *ptr, int size)
261 {
262  int num;
263 
264  if ((text == NULL) || (ptr == NULL) || (*text == NULL) || (textlength <= 0) || (size < 0))
265  {
267  }
268 
269  if (textlength < size)
270  {
271  char str[255];
272  snprintf(str, 254, "String does not fit character data (available=%d, required=%d) !\n", textlength, size);
273  dlt_log(LOG_WARNING, str);
275  }
276 
277  for (num=0; num<size; num++)
278  {
279  if ( (((char*)ptr)[num]<DLT_COMMON_ASCII_CHAR_SPACE) || (((char*)ptr)[num]>DLT_COMMON_ASCII_CHAR_TILDE) )
280  {
281  snprintf(*text,2,".");
282  }
283  else
284  {
285  /* replace < with . */
286  if (((char*)ptr)[num]!=DLT_COMMON_ASCII_CHAR_LT)
287  {
288  snprintf(*text,2,"%c",((char *)ptr)[num]);
289  }
290  else
291  {
292  snprintf(*text,2,".");
293  }
294  }
295  (*text)++;
296  }
297 
298  return DLT_RETURN_OK;
299 }
300 
301 void dlt_print_id(char *text, const char *id)
302 {
303  // check nullpointer
304  if(text == NULL || id == NULL)
305  return;
306 
307  int i, len;
308 
309  /* Initialize text */
310  for (i=0; i<DLT_ID_SIZE; i++)
311  {
312  text[i]='-';
313  }
314 
315  text[DLT_ID_SIZE] = 0;
316 
317  len = ((strlen(id)<=DLT_ID_SIZE)?strlen(id):DLT_ID_SIZE);
318 
319  /* Check id*/
320  for (i=0; i<len; i++)
321  text[i] = id[i];
322 }
323 
324 void dlt_set_id(char *id, const char *text)
325 {
326  // check nullpointer
327  if(id == NULL || text == NULL)
328  return;
329 
330  id[0] = 0;
331  id[1] = 0;
332  id[2] = 0;
333  id[3] = 0;
334 
335  if (text[0]!=0)
336  {
337  id[0] = text[0];
338  }
339  else
340  {
341  return;
342  }
343 
344  if (text[1]!=0)
345  {
346  id[1] = text[1];
347  }
348  else
349  {
350  return;
351  }
352 
353  if (text[2]!=0)
354  {
355  id[2] = text[2];
356  }
357  else
358  {
359  return;
360  }
361 
362  if (text[3]!=0)
363  {
364  id[3] = text[3];
365  }
366  else
367  {
368  return;
369  }
370 }
371 
372 void dlt_clean_string(char *text, int length)
373 {
374  int num;
375 
376  if (text == NULL)
377  {
378  return;
379  }
380 
381  for (num=0;num<length;num++)
382  {
383  if (text[num]=='\r' || text[num]=='\n')
384  {
385  text[num] = ' ';
386  }
387  }
388 }
389 
391 {
392  PRINT_FUNCTION_VERBOSE(verbose);
393 
394  if (filter == NULL)
395  {
397  }
398 
399  filter->counter = 0;
400 
401  return DLT_RETURN_OK;
402 }
403 
405 {
406  PRINT_FUNCTION_VERBOSE(verbose);
407 
408  if (filter == NULL)
409  {
411  }
412 
413  return DLT_RETURN_OK;
414 }
415 
416 DltReturnValue dlt_filter_load(DltFilter *filter, const char *filename, int verbose)
417 {
418  if (filter == NULL || filename == NULL)
419  {
421  }
422 
423  FILE *handle;
424  char str1[DLT_COMMON_BUFFER_LENGTH];
425  char apid[DLT_ID_SIZE],ctid[DLT_ID_SIZE];
426 
427  PRINT_FUNCTION_VERBOSE(verbose);
428 
429  handle = fopen(filename,"r");
430  if (handle == NULL)
431  {
432  snprintf(str, DLT_COMMON_BUFFER_LENGTH, "Filter file %s cannot be opened!\n", filename);
433  dlt_log(LOG_WARNING, str);
434  return DLT_RETURN_ERROR;
435  }
436 
437  /* Reset filters */
438  filter->counter=0;
439 
440  while (!feof(handle))
441  {
442  str1[0]=0;
443  if (fscanf(handle,"%s",str1)!=1)
444  {
445  break;
446  }
447  if (str1[0]==0)
448  {
449  break;
450  }
451  printf(" %s",str1);
452  if (strcmp(str1,"----")==0)
453  {
454  dlt_set_id(apid,"");
455  }
456  else
457  {
458  dlt_set_id(apid,str1);
459  }
460 
461  str1[0]=0;
462  if (fscanf(handle,"%s",str1)!=1)
463  {
464  break;
465  }
466  if (str1[0]==0)
467  {
468  break;
469  }
470  printf(" %s\r\n",str1);
471  if (strcmp(str1,"----")==0)
472  {
473  dlt_set_id(ctid,"");
474  }
475  else
476  {
477  dlt_set_id(ctid,str1);
478  }
479 
480  if (filter->counter<DLT_FILTER_MAX)
481  {
482  dlt_filter_add(filter,apid,ctid,verbose);
483  }
484  else
485  {
486  snprintf(str,DLT_COMMON_BUFFER_LENGTH, "Maximum number (%d) of allowed filters reached, ignoring rest of filters!\n", DLT_FILTER_MAX);
487  dlt_log(LOG_WARNING, str);
488  }
489  }
490 
491  fclose(handle);
492 
493  return DLT_RETURN_OK;
494 }
495 
496 DltReturnValue dlt_filter_save(DltFilter *filter, const char *filename, int verbose)
497 {
498  if (filter == NULL || filename == NULL)
499  {
501  }
502 
503  FILE *handle;
504  int num;
505  char buf[DLT_COMMON_BUFFER_LENGTH];
506 
507  PRINT_FUNCTION_VERBOSE(verbose);
508 
509  handle = fopen(filename,"w");
510  if (handle == NULL)
511  {
512  snprintf(str,DLT_COMMON_BUFFER_LENGTH,"Filter file %s cannot be opened!\n",filename);
513  dlt_log(LOG_WARNING, str);
514  return DLT_RETURN_ERROR;
515  }
516 
517  for (num=0;num<filter->counter;num++)
518  {
519  if (filter->apid[num][0]==0)
520  {
521  fprintf(handle,"---- ");
522  }
523  else
524  {
525  dlt_print_id(buf,filter->apid[num]);
526  fprintf(handle,"%s ",buf);
527  }
528  if (filter->ctid[num][0]==0)
529  {
530  fprintf(handle,"---- ");
531  }
532  else
533  {
534  dlt_print_id(buf,filter->ctid[num]);
535  fprintf(handle,"%s ",buf);
536  }
537  }
538 
539  fclose(handle);
540 
541  return DLT_RETURN_OK;
542 }
543 
544 int dlt_filter_find(DltFilter *filter, const char *apid, const char *ctid, int verbose)
545 {
546  int num;
547 
548  PRINT_FUNCTION_VERBOSE(verbose);
549 
550  if ((filter == NULL) || (apid == NULL))
551  {
552  return -1;
553  }
554 
555  for (num=0; num<filter->counter; num++)
556  {
557  if (memcmp(filter->apid[num],apid,DLT_ID_SIZE)==0)
558  {
559  /* apid matches, now check for ctid */
560  if (ctid == NULL)
561  {
562  /* check if empty ctid matches */
563  //if (memcmp(filter->ctid[num],"",DLT_ID_SIZE)==0)//coverity complains here about Out-of-bounds access.
564  char empty_ctid[DLT_ID_SIZE]="";
565  if (memcmp(filter->ctid[num],empty_ctid,DLT_ID_SIZE)==0)
566  {
567  return num;
568  }
569  }
570  else
571  {
572  if (memcmp(filter->ctid[num],ctid,DLT_ID_SIZE)==0)
573  {
574  return num;
575  }
576  }
577  }
578  }
579 
580  return -1; /* Not found */
581 }
582 
583 DltReturnValue dlt_filter_add(DltFilter *filter,const char *apid, const char *ctid, int verbose)
584 {
585  PRINT_FUNCTION_VERBOSE(verbose);
586 
587  if ((filter == NULL) || (apid == NULL))
588  {
590  }
591 
592  if (filter->counter >= DLT_FILTER_MAX)
593  {
594  sprintf(str, "Maximum number (%d) of allowed filters reached, ignoring filter!\n", DLT_FILTER_MAX);
595  dlt_log(LOG_WARNING, str);
596  return DLT_RETURN_ERROR;
597  }
598 
599  /* add each filter (apid, ctid) only once to filter array */
600  if (dlt_filter_find(filter,apid,ctid,verbose)<0)
601  {
602  /* filter not found, so add it to filter array */
603  if (filter->counter<DLT_FILTER_MAX)
604  {
605  dlt_set_id(filter->apid[filter->counter],apid);
606  dlt_set_id(filter->ctid[filter->counter],(ctid?ctid:""));
607 
608  filter->counter++;
609 
610  return DLT_RETURN_OK;
611  }
612  }
613 
614  return DLT_RETURN_ERROR;
615 }
616 
617 DltReturnValue dlt_filter_delete(DltFilter *filter,const char *apid,const char *ctid, int verbose)
618 {
619  int j,k;
620  int found=0;
621 
622  PRINT_FUNCTION_VERBOSE(verbose);
623 
624  if ((filter == NULL) || (apid == NULL) || (ctid == NULL))
625  {
627  }
628 
629  if (filter->counter>0)
630  {
631  /* Get first occurence of apid and ctid in filter array */
632  for (j=0; j<filter->counter; j++)
633  {
634  if ((memcmp(filter->apid[j],apid,DLT_ID_SIZE)==0) &&
635  (memcmp(filter->ctid[j],ctid,DLT_ID_SIZE)==0)
636  )
637 
638  {
639  found=1;
640  break;
641  }
642  }
643 
644  if (found)
645  {
646  /* j is index */
647  /* Copy from j+1 til end to j til end-1 */
648 
649  dlt_set_id(filter->apid[j],"");
650  dlt_set_id(filter->ctid[j],"");
651 
652  for (k=j; k<(filter->counter-1); k++)
653  {
654  dlt_set_id(filter->apid[k],filter->apid[k+1]);
655  dlt_set_id(filter->ctid[k],filter->ctid[k+1]);
656  }
657 
658  filter->counter--;
659  return DLT_RETURN_OK;
660  }
661  }
662 
663  return DLT_RETURN_ERROR;
664 }
665 
667 {
668  PRINT_FUNCTION_VERBOSE(verbose);
669 
670  if (msg == NULL)
671  {
673  }
674 
675  /* initalise structure parameters */
676  msg->headersize = 0;
677  msg->datasize = 0;
678 
679  msg->databuffer = NULL;
680  msg->databuffersize = 0;
681 
682  msg->storageheader = NULL;
683  msg->standardheader = NULL;
684  msg->extendedheader = NULL;
685 
686  msg->found_serialheader = 0;
687 
688  return DLT_RETURN_OK;
689 }
690 
692 {
693  PRINT_FUNCTION_VERBOSE(verbose);
694 
695  if (msg == NULL)
696  {
698  }
699  /* delete databuffer if exists */
700  if (msg->databuffer)
701  {
702  free(msg->databuffer);
703  msg->databuffer = NULL;
704  msg->databuffersize = 0;
705  }
706 
707  return DLT_RETURN_OK;
708 }
709 
710 DltReturnValue dlt_message_header(DltMessage *msg, char *text, int textlength, int verbose)
711 {
712  return dlt_message_header_flags(msg, text, textlength, DLT_HEADER_SHOW_ALL, verbose);
713 }
714 
715 DltReturnValue dlt_message_header_flags(DltMessage *msg, char *text, int textlength, int flags, int verbose)
716 {
717  struct tm * timeinfo;
719 
720  PRINT_FUNCTION_VERBOSE(verbose);
721 
722  if ((msg == NULL) || (text == NULL) || (textlength <= 0))
723  {
725  }
726 
727  if ((flags<DLT_HEADER_SHOW_NONE) || (flags>DLT_HEADER_SHOW_ALL))
728  {
730  }
731 
732  text[0] = 0;
733 
734  if ((flags & DLT_HEADER_SHOW_TIME) == DLT_HEADER_SHOW_TIME)
735  {
736  /* print received time */
737  time_t tt = msg->storageheader->seconds;
738  timeinfo = localtime (&tt);
739 
740  if (timeinfo != NULL)
741  {
742  strftime (buffer,sizeof(buffer),"%Y/%m/%d %H:%M:%S",timeinfo);
743  snprintf(text,textlength,"%s.%.6d ",buffer,msg->storageheader->microseconds);
744  }
745  }
746 
747  if ((flags & DLT_HEADER_SHOW_TMSTP) == DLT_HEADER_SHOW_TMSTP)
748  {
749  /* print timestamp if available */
750  if ( DLT_IS_HTYP_WTMS(msg->standardheader->htyp) )
751  {
752  snprintf(text+strlen(text),textlength-strlen(text),"%10u ",msg->headerextra.tmsp);
753  }
754  else
755  {
756  snprintf(text+strlen(text),textlength-strlen(text),"---------- ");
757  }
758  }
759 
760  if ((flags & DLT_HEADER_SHOW_MSGCNT) == DLT_HEADER_SHOW_MSGCNT)
761  {
762  /* print message counter */
763  snprintf(text+strlen(text),textlength-strlen(text),"%.3d ",msg->standardheader->mcnt);
764  }
765 
766  if ((flags & DLT_HEADER_SHOW_ECUID) == DLT_HEADER_SHOW_ECUID)
767  {
768  /* print ecu id, use header extra if available, else storage header value */
769  if ( DLT_IS_HTYP_WEID(msg->standardheader->htyp) )
770  {
771  dlt_print_id(text+strlen(text),msg->headerextra.ecu);
772  }
773  else
774  {
775  dlt_print_id(text+strlen(text),msg->storageheader->ecu);
776  }
777  }
778 
779  /* print app id and context id if extended header available, else '----' */#
780  if ((flags & DLT_HEADER_SHOW_APID) == DLT_HEADER_SHOW_APID)
781  {
782  snprintf(text+strlen(text),textlength-strlen(text)," ");
783  if ((DLT_IS_HTYP_UEH(msg->standardheader->htyp)) && (msg->extendedheader->apid[0]!=0))
784  {
785  dlt_print_id(text+strlen(text),msg->extendedheader->apid);
786  }
787  else
788  {
789  snprintf(text+strlen(text),textlength-strlen(text),"----");
790  }
791 
792  snprintf(text+strlen(text),textlength-strlen(text)," ");
793  }
794 
795  if ((flags & DLT_HEADER_SHOW_CTID) == DLT_HEADER_SHOW_CTID)
796  {
797  if ((DLT_IS_HTYP_UEH(msg->standardheader->htyp)) && (msg->extendedheader->ctid[0]!=0))
798  {
799  dlt_print_id(text+strlen(text),msg->extendedheader->ctid);
800  }
801  else
802  {
803  snprintf(text+strlen(text),textlength-strlen(text),"----");
804  }
805 
806  snprintf(text+strlen(text),textlength-strlen(text)," ");
807  }
808 
809  /* print info about message type and length */
810  if (DLT_IS_HTYP_UEH(msg->standardheader->htyp))
811  {
812  if ((flags & DLT_HEADER_SHOW_MSGTYPE) == DLT_HEADER_SHOW_MSGTYPE)
813  {
814  snprintf(text+strlen(text),textlength-strlen(text),"%s",message_type[DLT_GET_MSIN_MSTP(msg->extendedheader->msin)]);
815  snprintf(text+strlen(text),textlength-strlen(text)," ");
816  }
817 
818  if ((flags & DLT_HEADER_SHOW_MSGSUBTYPE) == DLT_HEADER_SHOW_MSGSUBTYPE)
819  {
820  if ((DLT_GET_MSIN_MSTP(msg->extendedheader->msin))==DLT_TYPE_LOG)
821  {
822  snprintf(text+strlen(text),textlength-strlen(text),"%s",log_info[DLT_GET_MSIN_MTIN(msg->extendedheader->msin)]);
823  }
824 
826  {
827  snprintf(text+strlen(text),textlength-strlen(text),"%s",trace_type[DLT_GET_MSIN_MTIN(msg->extendedheader->msin)]);
828  }
829 
831  {
832  snprintf(text+strlen(text),textlength-strlen(text),"%s",nw_trace_type[DLT_GET_MSIN_MTIN(msg->extendedheader->msin)]);
833  }
834 
836  {
837  snprintf(text+strlen(text),textlength-strlen(text),"%s",control_type[DLT_GET_MSIN_MTIN(msg->extendedheader->msin)]);
838  }
839 
840  snprintf(text+strlen(text),textlength-strlen(text)," ");
841  }
842 
843  if ((flags & DLT_HEADER_SHOW_VNVSTATUS) == DLT_HEADER_SHOW_VNVSTATUS)
844  {
845  /* print verbose status pf message */
846  if (DLT_IS_MSIN_VERB(msg->extendedheader->msin))
847  {
848  snprintf(text+strlen(text),textlength-strlen(text),"V");
849  }
850  else
851  {
852  snprintf(text+strlen(text),textlength-strlen(text),"N");
853  }
854 
855  snprintf(text+strlen(text),textlength-strlen(text)," ");
856  }
857 
858  if ((flags & DLT_HEADER_SHOW_NOARG) == DLT_HEADER_SHOW_NOARG)
859  {
860  /* print number of arguments */
861  snprintf(text+strlen(text),textlength-strlen(text),"%d", msg->extendedheader->noar);
862  }
863 
864  }
865  else
866  {
867  if ((flags & DLT_HEADER_SHOW_MSGTYPE) == DLT_HEADER_SHOW_MSGTYPE)
868  {
869  snprintf(text+strlen(text),textlength-strlen(text),"--- ");
870  }
871 
872  if ((flags & DLT_HEADER_SHOW_MSGSUBTYPE) == DLT_HEADER_SHOW_MSGSUBTYPE)
873  {
874  snprintf(text+strlen(text),textlength-strlen(text),"--- ");
875  }
876 
877  if ((flags & DLT_HEADER_SHOW_VNVSTATUS) == DLT_HEADER_SHOW_VNVSTATUS)
878  {
879  snprintf(text+strlen(text),textlength-strlen(text),"N ");
880  }
881 
882  if ((flags & DLT_HEADER_SHOW_NOARG) == DLT_HEADER_SHOW_NOARG)
883  {
884  snprintf(text+strlen(text),textlength-strlen(text),"-");
885  }
886  }
887 
888  return DLT_RETURN_OK;
889 }
890 
891 DltReturnValue dlt_message_payload(DltMessage *msg, char *text, int textlength, int type, int verbose)
892 {
893  uint32_t id=0, id_tmp=0;
894  uint8_t retval=0;
895 
896  uint8_t *ptr;
897  int32_t datalength;
898 
899  /* Pointer to ptr and datalength */
900  uint8_t **pptr;
901  int32_t *pdatalength;
902 
903  int ret=0;
904 
905  int num;
906  uint32_t type_info=0,type_info_tmp=0;
907 
908  PRINT_FUNCTION_VERBOSE(verbose);
909 
910  if ((msg == NULL) || (text == NULL))
911  {
913  }
914 
915  if (textlength <= 0)
916  {
917  dlt_log(LOG_WARNING, "String does not fit binary data!\n");
919  }
920 
921  /* start with empty string */
922  text[0] = 0;
923 
924  /* print payload only as hex */
925  if (type==DLT_OUTPUT_HEX)
926  {
927  return dlt_print_hex_string(text, textlength, msg->databuffer, msg->datasize);
928  }
929 
930  /* print payload as mixed */
931  if (type==DLT_OUTPUT_MIXED_FOR_PLAIN)
932  {
933  return dlt_print_mixed_string(text, textlength, msg->databuffer, msg->datasize,0);
934  }
935 
936  if (type==DLT_OUTPUT_MIXED_FOR_HTML)
937  {
938  return dlt_print_mixed_string(text, textlength, msg->databuffer, msg->datasize,1);
939  }
940 
941  ptr = msg->databuffer;
942  datalength = msg->datasize;
943 
944  /* Pointer to ptr and datalength */
945  pptr = &ptr;
946  pdatalength = &datalength;
947 
948  /* non-verbose mode */
949 
950  /* print payload as hex */
951  if (DLT_MSG_IS_NONVERBOSE(msg))
952  {
953 
954  DLT_MSG_READ_VALUE(id_tmp,ptr,datalength,uint32_t);
955  id=DLT_ENDIAN_GET_32(msg->standardheader->htyp, id_tmp);
956 
957  if (textlength<((datalength*3)+20))
958  {
959  char str[255];
960  snprintf(str, 254, "String does not fit binary data (available=%d, required=%d) !\n", textlength, (datalength*3)+20);
961  dlt_log(LOG_WARNING, str);
962  return DLT_RETURN_ERROR;
963  }
964 
965  /* process message id / service id */
966  if (DLT_MSG_IS_CONTROL(msg))
967  {
968  if (id > 0 && id < DLT_SERVICE_ID_LAST_ENTRY)
969  {
970  snprintf(text+strlen(text),textlength-strlen(text),"%s",service_id[id]); /* service id */
971  }
972  else
973  {
974  if (!(DLT_MSG_IS_CONTROL_TIME(msg)))
975  {
976  snprintf(text+strlen(text),textlength-strlen(text),"service(%u)",id); /* service id */
977  }
978  }
979 
980  if (datalength>0)
981  {
982  snprintf(text+strlen(text),textlength-strlen(text),", ");
983  }
984  }
985  else
986  {
987  snprintf(text+strlen(text),textlength-strlen(text),"%u, ",id); /* message id */
988  }
989 
990  /* process return value */
992  {
993  if (datalength>0)
994  {
995  DLT_MSG_READ_VALUE(retval,ptr,datalength,uint8_t); /* No endian conversion necessary */
996  if ( (retval<3) || (retval==8))
997  {
998  snprintf(text+strlen(text),textlength-strlen(text),"%s",return_type[retval]);
999  }
1000  else
1001  {
1002  snprintf(text+strlen(text),textlength-strlen(text),"%.2x",retval);
1003  }
1004 
1005  if (datalength>=1)
1006  {
1007  snprintf(text+strlen(text),textlength-strlen(text),", ");
1008  }
1009  }
1010  }
1011 
1012  if (type==DLT_OUTPUT_ASCII_LIMITED)
1013  {
1014  ret=dlt_print_hex_string(text+strlen(text),textlength-strlen(text),ptr,
1016  if ((datalength>DLT_COMMON_ASCII_LIMIT_MAX_CHARS) &&
1017  ((textlength-strlen(text))>4))
1018  {
1019  snprintf(text+strlen(text),textlength-strlen(text)," ...");
1020  }
1021  }
1022  else
1023  {
1024  ret=dlt_print_hex_string(text+strlen(text),textlength-strlen(text),ptr,datalength);
1025  }
1026 
1027  return ret;
1028  }
1029 
1030  /* At this point, it is ensured that a extended header is available */
1031 
1032  /* verbose mode */
1033  type_info=0;
1034  type_info_tmp=0;
1035 
1036  for (num=0;num<(int)(msg->extendedheader->noar);num++)
1037  {
1038  if (num!=0)
1039  {
1040  snprintf(text+strlen(text),textlength-strlen(text)," ");
1041  }
1042 
1043  /* first read the type info of the argument */
1044  DLT_MSG_READ_VALUE(type_info_tmp,ptr,datalength,uint32_t);
1045  type_info=DLT_ENDIAN_GET_32(msg->standardheader->htyp, type_info_tmp);
1046 
1047  /* print out argument */
1048  if (dlt_message_argument_print(msg, type_info, pptr, pdatalength, text, textlength, -1, 0) == DLT_RETURN_ERROR)
1049  {
1050  return DLT_RETURN_ERROR;
1051  }
1052  }
1053 
1054  return DLT_RETURN_OK;
1055 }
1056 
1058 {
1059  /* check the filters if message is used */
1060  int num;
1061  DltReturnValue found = DLT_RETURN_OK;
1062 
1063  PRINT_FUNCTION_VERBOSE(verbose);
1064 
1065  if ((msg == NULL) || (filter == NULL))
1066  {
1068  }
1069 
1070  if ((filter->counter==0) || (!(DLT_IS_HTYP_UEH(msg->standardheader->htyp))))
1071  {
1072  /* no filter is set, or no extended header is available, so do as filter is matching */
1073  return DLT_RETURN_TRUE;
1074  }
1075 
1076  for (num=0 ;num<filter->counter; num++)
1077  {
1078  /* check each filter if it matches */
1079  if ((DLT_IS_HTYP_UEH(msg->standardheader->htyp)) &&
1080  (filter->apid[num][0]==0 || memcmp(filter->apid[num],msg->extendedheader->apid,DLT_ID_SIZE)==0) &&
1081  (filter->ctid[num][0]==0 || memcmp(filter->ctid[num],msg->extendedheader->ctid,DLT_ID_SIZE)==0) )
1082  {
1083  found = DLT_RETURN_TRUE;
1084  break;
1085  }
1086  }
1087 
1088  return found;
1089 }
1090 
1091 int dlt_message_read(DltMessage *msg, uint8_t *buffer, unsigned int length, int resync, int verbose)
1092 {
1093  int extra_size = 0;
1094 
1095  PRINT_FUNCTION_VERBOSE(verbose);
1096 
1097  if ((msg == NULL) || (buffer == NULL) || (length <= 0))
1098  {
1100  }
1101 
1102  /* initialize resync_offset */
1103  msg->resync_offset=0;
1104 
1105  /* check if message contains serial header, smaller than standard header */
1106  if (length<sizeof(dltSerialHeader))
1107  {
1108  /* dlt_log(LOG_ERR, "Length smaller than serial header!\n"); */
1109  return DLT_MESSAGE_ERROR_SIZE;
1110  }
1111 
1112  if (memcmp(buffer, dltSerialHeader, sizeof(dltSerialHeader)) == 0)
1113  {
1114  /* serial header found */
1115  msg->found_serialheader = 1;
1116  buffer += sizeof(dltSerialHeader);
1117  length -= sizeof(dltSerialHeader);
1118  }
1119  else
1120  {
1121  /* serial header not found */
1122  msg->found_serialheader = 0;
1123  if (resync)
1124  {
1125  /* resync if necessary */
1126  msg->resync_offset=0;
1127 
1128  do
1129  {
1130  if (memcmp(buffer+msg->resync_offset, dltSerialHeader, sizeof(dltSerialHeader)) == 0)
1131  {
1132  /* serial header found */
1133  msg->found_serialheader = 1;
1134  buffer += sizeof(dltSerialHeader);
1135  length -= sizeof(dltSerialHeader);
1136  break;
1137  }
1138 
1139  msg->resync_offset++;
1140  }
1141  while ((sizeof(dltSerialHeader)+msg->resync_offset)<=length);
1142 
1143  /* Set new start offset */
1144  if (msg->resync_offset>0)
1145  {
1146  /* Resyncing connection */
1147  buffer+=msg->resync_offset;
1148  length-=msg->resync_offset;
1149  }
1150  }
1151  }
1152 
1153  /* check that standard header fits buffer */
1154  if (length<sizeof(DltStandardHeader))
1155  {
1156  /* dlt_log(LOG_ERR, "Length smaller than standard header!\n"); */
1157  return DLT_MESSAGE_ERROR_SIZE;
1158  }
1159  memcpy(msg->headerbuffer+sizeof(DltStorageHeader), buffer, sizeof(DltStandardHeader));
1160 
1161  /* set ptrs to structures */
1162  msg->storageheader = (DltStorageHeader*) msg->headerbuffer;
1163  msg->standardheader = (DltStandardHeader*) (msg->headerbuffer + sizeof(DltStorageHeader));
1164 
1165  /* calculate complete size of headers */
1166  extra_size = DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp)+(DLT_IS_HTYP_UEH(msg->standardheader->htyp) ? sizeof(DltExtendedHeader) : 0);
1167  msg->headersize = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + extra_size;
1168  msg->datasize = DLT_BETOH_16(msg->standardheader->len) - (msg->headersize - sizeof(DltStorageHeader));
1169 
1170  if (verbose)
1171  {
1172  snprintf(str,DLT_COMMON_BUFFER_LENGTH, "BufferLength=%d, HeaderSize=%d, DataSize=%d\n", length, msg->headersize, msg->datasize);
1173  dlt_log(LOG_DEBUG, str);
1174  }
1175 
1176  /* check data size */
1177  if (msg->datasize < 0)
1178  {
1179  snprintf(str,DLT_COMMON_BUFFER_LENGTH, "Plausibility check failed. Complete message size too short (%d)!\n",msg->datasize);
1180  dlt_log(LOG_WARNING, str);
1182  }
1183 
1184  /* load standard header extra parameters and Extended header if used */
1185  if (extra_size>0)
1186  {
1187  if (length < (msg->headersize - sizeof(DltStorageHeader)))
1188  {
1189  return DLT_MESSAGE_ERROR_SIZE;
1190  }
1191 
1192  memcpy(msg->headerbuffer+sizeof(DltStorageHeader)+sizeof(DltStandardHeader),buffer+sizeof(DltStandardHeader),extra_size);
1193 
1194  /* set extended header ptr and get standard header extra parameters */
1195  if (DLT_IS_HTYP_UEH(msg->standardheader->htyp))
1196  {
1197  msg->extendedheader = (DltExtendedHeader*) (msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) +
1199  }
1200  else
1201  {
1202  msg->extendedheader = NULL;
1203  }
1204 
1205  dlt_message_get_extraparameters(msg,verbose);
1206  }
1207 
1208  /* check if payload fits length */
1209  if (length < (msg->headersize - sizeof(DltStorageHeader) + msg->datasize))
1210  {
1211  /* dlt_log(LOG_ERR,"length does not fit!\n"); */
1212  return DLT_MESSAGE_ERROR_SIZE;
1213  }
1214 
1215  /* free last used memory for buffer */
1216  if (msg->databuffer)
1217  {
1218  if (msg->datasize>msg->databuffersize){
1219  free(msg->databuffer);
1220  msg->databuffer=(uint8_t *)malloc(msg->datasize);
1221  msg->databuffersize = msg->datasize;
1222  }
1223  }else{
1224  /* get new memory for buffer */
1225  msg->databuffer = (uint8_t *)malloc(msg->datasize);
1226  msg->databuffersize = msg->datasize;
1227  }
1228  if (msg->databuffer == NULL)
1229  {
1230  snprintf(str,DLT_COMMON_BUFFER_LENGTH,"Cannot allocate memory for payload buffer of size %d!\n",msg->datasize);
1231  dlt_log(LOG_WARNING, str);
1233  }
1234 
1235  /* load payload data from buffer */
1236  memcpy(msg->databuffer,buffer+(msg->headersize-sizeof(DltStorageHeader)),msg->datasize);
1237 
1238  return DLT_MESSAGE_ERROR_OK;
1239 }
1240 
1242 {
1243  PRINT_FUNCTION_VERBOSE(verbose);
1244 
1245  if (msg == NULL)
1246  {
1248  }
1249 
1250  if (DLT_IS_HTYP_WEID(msg->standardheader->htyp))
1251  {
1252  memcpy(msg->headerextra.ecu,msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader),DLT_ID_SIZE);
1253  }
1254 
1255  if (DLT_IS_HTYP_WSID(msg->standardheader->htyp))
1256  {
1257  memcpy(&(msg->headerextra.seid),msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader)
1259  msg->headerextra.seid = DLT_BETOH_32(msg->headerextra.seid);
1260  }
1261 
1262  if (DLT_IS_HTYP_WTMS(msg->standardheader->htyp))
1263  {
1264  memcpy(&(msg->headerextra.tmsp),msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader)
1265  + (DLT_IS_HTYP_WEID(msg->standardheader->htyp) ? DLT_SIZE_WEID : 0)
1267  msg->headerextra.tmsp = DLT_BETOH_32(msg->headerextra.tmsp);
1268  }
1269 
1270  return DLT_RETURN_OK;
1271 }
1272 
1274 {
1275  PRINT_FUNCTION_VERBOSE(verbose);
1276 
1277  if (msg == NULL)
1278  {
1280  }
1281 
1282  if (DLT_IS_HTYP_WEID(msg->standardheader->htyp))
1283  {
1284  memcpy(msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader),msg->headerextra.ecu,DLT_ID_SIZE);
1285  }
1286 
1287  if (DLT_IS_HTYP_WSID(msg->standardheader->htyp))
1288  {
1289  msg->headerextra.seid = DLT_HTOBE_32(msg->headerextra.seid);
1290  memcpy(msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader)
1291  + (DLT_IS_HTYP_WEID(msg->standardheader->htyp) ? DLT_SIZE_WEID : 0), &(msg->headerextra.seid),DLT_SIZE_WSID);
1292  }
1293 
1294  if (DLT_IS_HTYP_WTMS(msg->standardheader->htyp))
1295  {
1296  msg->headerextra.tmsp = DLT_HTOBE_32(msg->headerextra.tmsp);
1297  memcpy(msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader)
1298  + (DLT_IS_HTYP_WEID(msg->standardheader->htyp) ? DLT_SIZE_WEID : 0)
1299  + (DLT_IS_HTYP_WSID(msg->standardheader->htyp) ? DLT_SIZE_WSID : 0), &(msg->headerextra.tmsp),DLT_SIZE_WTMS);
1300  }
1301 
1302  return DLT_RETURN_OK;
1303 }
1304 
1306 {
1307  PRINT_FUNCTION_VERBOSE(verbose);
1308 
1309  if (file == NULL)
1310  {
1312  }
1313 
1314  /* initalise structure parameters */
1315  file->handle = NULL;
1316  file->counter = 0;
1317  file->counter_total = 0;
1318  file->index = NULL;
1319 
1320  file->filter = NULL;
1321  file->filter_counter = 0;
1322  file->file_position = 0;
1323 
1324  file->position = 0;
1325 
1326  file->error_messages = 0;
1327 
1328  return dlt_message_init(&(file->msg),verbose);
1329 }
1330 
1332 {
1333  PRINT_FUNCTION_VERBOSE(verbose);
1334 
1335  if (file == NULL)
1336  {
1338  }
1339 
1340  /* set filter */
1341  file->filter = filter;
1342 
1343  return DLT_RETURN_OK;
1344 }
1345 
1347 {
1348  PRINT_FUNCTION_VERBOSE(verbose);
1349 
1350  if (file == NULL)
1351  {
1353  }
1354 
1355  /* load header from file */
1356  if (fread(file->msg.headerbuffer, sizeof(DltStorageHeader)+sizeof(DltStandardHeader), 1, file->handle)!=1)
1357  {
1358  if (!feof(file->handle))
1359  {
1360  dlt_log(LOG_WARNING, "Cannot read header from file!\n");
1361  }
1362  return DLT_RETURN_ERROR;
1363  }
1364 
1365  /* set ptrs to structures */
1366  file->msg.storageheader = (DltStorageHeader*) file->msg.headerbuffer;
1367  file->msg.standardheader = (DltStandardHeader*) (file->msg.headerbuffer + sizeof(DltStorageHeader));
1368 
1369  /* check id of storage header */
1371  {
1372  dlt_log(LOG_WARNING, "DLT storage header pattern not found!\n");
1373  return DLT_RETURN_ERROR;
1374  }
1375 
1376  /* calculate complete size of headers */
1377  file->msg.headersize = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) +
1378  DLT_STANDARD_HEADER_EXTRA_SIZE(file->msg.standardheader->htyp) + (DLT_IS_HTYP_UEH(file->msg.standardheader->htyp) ? sizeof(DltExtendedHeader) : 0);
1379  file->msg.datasize = DLT_BETOH_16(file->msg.standardheader->len) + sizeof(DltStorageHeader) - file->msg.headersize;
1380  if (verbose)
1381  {
1382  snprintf(str,DLT_COMMON_BUFFER_LENGTH,"HeaderSize=%d, DataSize=%d\n",file->msg.headersize, file->msg.datasize);
1383  dlt_log(LOG_DEBUG, str);
1384  }
1385 
1386  /* check data size */
1387  if (file->msg.datasize < 0)
1388  {
1389  snprintf(str,DLT_COMMON_BUFFER_LENGTH,"Plausibility check failed. Complete message size too short! (%d)\n", file->msg.datasize);
1390  dlt_log(LOG_WARNING, str);
1391  return DLT_RETURN_ERROR;
1392  }
1393 
1394  return DLT_RETURN_OK;
1395 }
1396 
1397 DltReturnValue dlt_file_read_header_raw(DltFile *file, int resync, int verbose)
1398 {
1399  char dltSerialHeaderBuffer[DLT_ID_SIZE];
1400 
1401  PRINT_FUNCTION_VERBOSE(verbose);
1402 
1403  if (file == NULL)
1404  {
1406  }
1407 
1408  /* check if serial header exists, ignore if found */
1409  if (fread(dltSerialHeaderBuffer,sizeof(dltSerialHeaderBuffer),1,file->handle)!=1)
1410  {
1411  /* cannot read serial header, not enough data available in file */
1412  if (!feof(file->handle))
1413  {
1414  dlt_log(LOG_WARNING, "Cannot read header from file!\n");
1415  }
1416  return DLT_RETURN_ERROR;
1417  }
1418  if (memcmp(dltSerialHeaderBuffer,dltSerialHeader,sizeof(dltSerialHeader)) == 0)
1419  {
1420  /* serial header found */
1421  /* nothing to do continue reading */
1422 
1423  }
1424  else
1425  {
1426  /* serial header not found */
1427  if(resync)
1428  {
1429  /* increase error counter */
1430  file->error_messages++;
1431 
1432  /* resync to serial header */
1433  do
1434  {
1435  memmove(dltSerialHeaderBuffer,dltSerialHeaderBuffer+1,sizeof(dltSerialHeader)-1);
1436  if (fread(dltSerialHeaderBuffer+3,1,1,file->handle)!=1)
1437  {
1438  /* cannot read any data, perhaps end of file reached */
1439  return DLT_RETURN_ERROR;
1440  }
1441  if (memcmp(dltSerialHeaderBuffer,dltSerialHeader,sizeof(dltSerialHeader)) == 0)
1442  {
1443  /* serial header synchronised */
1444  break;
1445  }
1446  } while(1);
1447  }
1448  else
1449  {
1450  /* go back to last file position */
1451  if (0 != fseek(file->handle,file->file_position,SEEK_SET))
1452  return DLT_RETURN_ERROR;
1453  }
1454  }
1455 
1456  /* load header from file */
1457  if (fread(file->msg.headerbuffer+sizeof(DltStorageHeader),sizeof(DltStandardHeader),1,file->handle)!=1)
1458  {
1459  if (!feof(file->handle))
1460  {
1461  dlt_log(LOG_WARNING, "Cannot read header from file!\n");
1462  }
1463  return DLT_RETURN_ERROR;
1464  }
1465 
1466  /* set ptrs to structures */
1467  file->msg.storageheader = (DltStorageHeader*) file->msg.headerbuffer; // this points now to a empty storage header (filled with '0')
1468  file->msg.standardheader = (DltStandardHeader*) (file->msg.headerbuffer + sizeof(DltStorageHeader));
1469 
1470  /* Skip storage header field, fill this field with '0' */
1471  memset(file->msg.storageheader, 0, sizeof(DltStorageHeader));
1472 
1473  /* Set storage header */
1475 
1476  /* no check for storage header id*/
1477 
1478  /* calculate complete size of headers */
1479  file->msg.headersize = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) +
1480  DLT_STANDARD_HEADER_EXTRA_SIZE(file->msg.standardheader->htyp) + (DLT_IS_HTYP_UEH(file->msg.standardheader->htyp) ? sizeof(DltExtendedHeader) : 0);
1481  file->msg.datasize = DLT_BETOH_16(file->msg.standardheader->len) + sizeof(DltStorageHeader) - file->msg.headersize;
1482  if (verbose)
1483  {
1484  snprintf(str,DLT_COMMON_BUFFER_LENGTH,"HeaderSize=%d, DataSize=%d\n",file->msg.headersize, file->msg.datasize);
1485  dlt_log(LOG_DEBUG, str);
1486  }
1487 
1488  /* check data size */
1489  if (file->msg.datasize < 0)
1490  {
1491  snprintf(str,DLT_COMMON_BUFFER_LENGTH,"Plausibility check failed. Complete message size too short! (%d)\n", file->msg.datasize);
1492  dlt_log(LOG_WARNING, str);
1493  return DLT_RETURN_ERROR;
1494  }
1495 
1496  return DLT_RETURN_OK;
1497 }
1498 
1500 {
1501  PRINT_FUNCTION_VERBOSE(verbose);
1502 
1503  if (file == NULL)
1504  {
1506  }
1507 
1508  /* load standard header extra parameters if used */
1510  {
1511  if (fread(file->msg.headerbuffer+sizeof(DltStorageHeader)+sizeof(DltStandardHeader),
1513  1,file->handle)!=1)
1514  {
1515  dlt_log(LOG_WARNING, "Cannot read standard header extra parameters from file!\n");
1516  return DLT_RETURN_ERROR;
1517  }
1518 
1519  dlt_message_get_extraparameters(&(file->msg),verbose);
1520  }
1521 
1522  /* load Extended header if used */
1523  if (DLT_IS_HTYP_UEH(file->msg.standardheader->htyp)==0)
1524  {
1525  /* there is nothing to be loaded */
1526  return DLT_RETURN_OK;
1527  }
1528 
1529  if (fread(file->msg.headerbuffer+sizeof(DltStorageHeader)+sizeof(DltStandardHeader)+DLT_STANDARD_HEADER_EXTRA_SIZE(file->msg.standardheader->htyp),
1530  (DLT_IS_HTYP_UEH(file->msg.standardheader->htyp) ? sizeof(DltExtendedHeader) : 0),
1531  1,file->handle)!=1)
1532  {
1533  dlt_log(LOG_WARNING, "Cannot read extended header from file!\n");
1534  return DLT_RETURN_ERROR;
1535  }
1536 
1537  /* set extended header ptr */
1538  if (DLT_IS_HTYP_UEH(file->msg.standardheader->htyp))
1539  {
1540  file->msg.extendedheader = (DltExtendedHeader*) (file->msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) +
1542  }
1543  else
1544  {
1545  file->msg.extendedheader = NULL;
1546  }
1547 
1548  return DLT_RETURN_OK;
1549 }
1550 
1552 {
1553  PRINT_FUNCTION_VERBOSE(verbose);
1554 
1555  if (file == NULL)
1556  {
1558  }
1559 
1560  /* free last used memory for buffer */
1561  if (file->msg.databuffer && (file->msg.databuffersize < file->msg.datasize))
1562  {
1563  free(file->msg.databuffer);
1564  file->msg.databuffer = NULL;
1565  }
1566 
1567  if (file->msg.databuffer == NULL){
1568  /* get new memory for buffer */
1569  file->msg.databuffer = (uint8_t *)malloc(file->msg.datasize);
1570  file->msg.databuffersize = file->msg.datasize;
1571  }
1572 
1573  if (file->msg.databuffer == NULL)
1574  {
1575  snprintf(str,DLT_COMMON_BUFFER_LENGTH,"Cannot allocate memory for payload buffer of size %d!\n",file->msg.datasize);
1576  dlt_log(LOG_WARNING, str);
1577  return DLT_RETURN_ERROR;
1578  }
1579 
1580  /* load payload data from file */
1581  if (fread(file->msg.databuffer,file->msg.datasize,1,file->handle)!=1)
1582  {
1583  if (file->msg.datasize!=0)
1584  {
1585  snprintf(str,DLT_COMMON_BUFFER_LENGTH,"Cannot read payload data from file of size %d!\n",file->msg.datasize);
1586  dlt_log(LOG_WARNING, str);
1587  return DLT_RETURN_ERROR;
1588  }
1589  }
1590 
1591  return DLT_RETURN_OK;
1592 }
1593 
1594 DltReturnValue dlt_file_open(DltFile *file,const char *filename,int verbose)
1595 {
1596  PRINT_FUNCTION_VERBOSE(verbose);
1597 
1598  if(file == NULL || filename == NULL)
1600 
1601  /* reset counters */
1602  file->counter = 0;
1603  file->counter_total = 0;
1604  file->position = 0;
1605  file->file_position = 0;
1606  file->file_length = 0;
1607  file->error_messages = 0;
1608 
1609  if (file->handle)
1610  {
1611  fclose(file->handle);
1612  }
1613 
1614  /* open dlt file */
1615  file->handle = fopen(filename,"rb");
1616  if (file->handle == NULL)
1617  {
1618  snprintf(str, DLT_COMMON_BUFFER_LENGTH - 1 ,"File %s cannot be opened!\n", filename);
1619  dlt_log(LOG_WARNING, str);
1620  return DLT_RETURN_ERROR;
1621  }
1622 
1623  if (0 != fseek(file->handle, 0, SEEK_END))
1624  {
1625  snprintf(str, DLT_COMMON_BUFFER_LENGTH, "dlt_file_open: Seek failed to 0,SEEK_END");
1626  dlt_log(LOG_WARNING, str);
1627  return DLT_RETURN_ERROR;
1628  }
1629  file->file_length = ftell(file->handle);
1630 
1631  if (0 != fseek(file->handle,0,SEEK_SET))
1632  {
1633  snprintf(str,DLT_COMMON_BUFFER_LENGTH,"dlt_file_open: Seek failed to 0,SEEK_SET");
1634  dlt_log(LOG_WARNING, str);
1635  return DLT_RETURN_ERROR;
1636  }
1637 
1638  if (verbose)
1639  {
1640  /* print file length */
1641  snprintf(str,DLT_COMMON_BUFFER_LENGTH,"File is %lu bytes long\n",file->file_length);
1642  dlt_log(LOG_DEBUG, str);
1643  }
1644  return DLT_RETURN_OK;
1645 }
1646 
1648 {
1649  long *ptr;
1650  int found = DLT_RETURN_OK;
1651 
1652  if (verbose)
1653  {
1654  snprintf(str,DLT_COMMON_BUFFER_LENGTH,"%s: Message %d:\n",__func__, file->counter_total);
1655  dlt_log(LOG_DEBUG, str);
1656  }
1657 
1658  if (file == NULL)
1659  {
1661  }
1662 
1663  /* allocate new memory for index if number of messages exceeds a multiple of DLT_COMMON_INDEX_ALLOC (e.g.: 1000) */
1664  if (file->counter % DLT_COMMON_INDEX_ALLOC == 0)
1665  {
1666  ptr = (long *) malloc(((file->counter/DLT_COMMON_INDEX_ALLOC) + 1) * DLT_COMMON_INDEX_ALLOC * sizeof(long));
1667 
1668  if (ptr == NULL)
1669  {
1670  return DLT_RETURN_ERROR;
1671  }
1672 
1673  if (file->index)
1674  {
1675  memcpy(ptr,file->index,file->counter * sizeof(long));
1676  free(file->index);
1677  }
1678  file->index = ptr;
1679  }
1680 
1681  /* set to end of last succesful read message, because of conflicting calls to dlt_file_read and dlt_file_message */
1682  if (0 != fseek(file->handle,file->file_position,SEEK_SET))
1683  {
1684  snprintf(str,DLT_COMMON_BUFFER_LENGTH,"Seek failed to file_position %ld \n",file->file_position);
1685  dlt_log(LOG_WARNING, str);
1686  return DLT_RETURN_ERROR;
1687  }
1688 
1689  /* get file position at start of DLT message */
1690  if (verbose)
1691  {
1692  snprintf(str,DLT_COMMON_BUFFER_LENGTH,"Position in file: %ld\n",file->file_position);
1693  dlt_log(LOG_INFO, str);
1694  }
1695 
1696  /* read header */
1697  if (dlt_file_read_header(file,verbose) < DLT_RETURN_OK)
1698  {
1699  /* go back to last position in file */
1700  fseek(file->handle,file->file_position,SEEK_SET);
1701  return DLT_RETURN_ERROR;
1702  }
1703 
1704  if (file->filter)
1705  {
1706  /* read the extended header if filter is enabled and extended header exists */
1707  if (dlt_file_read_header_extended(file, verbose) < DLT_RETURN_OK)
1708  {
1709  /* go back to last position in file */
1710  if (0 != fseek(file->handle,file->file_position,SEEK_SET))
1711  {
1712  snprintf(str,DLT_COMMON_BUFFER_LENGTH,"Seek to last file pos failed!\n");
1713  dlt_log(LOG_WARNING, str);
1714  }
1715  return DLT_RETURN_ERROR;
1716  }
1717 
1718  /* check the filters if message is used */
1719  if (dlt_message_filter_check(&(file->msg),file->filter,verbose) == DLT_RETURN_TRUE)
1720  {
1721  /* filter matched, consequently store current message */
1722  /* store index pointer to message position in DLT file */
1723  file->index[file->counter] = file->file_position;
1724  file->counter++;
1725  file->position = file->counter - 1;
1726 
1727  found = DLT_RETURN_TRUE;
1728  }
1729 
1730  /* skip payload data */
1731  if (fseek(file->handle,file->msg.datasize,SEEK_CUR)!=0)
1732  {
1733  /* go back to last position in file */
1734  snprintf(str,DLT_COMMON_BUFFER_LENGTH,"Seek failed to skip payload data of size %d!\n",file->msg.datasize);
1735  dlt_log(LOG_WARNING, str);
1736 
1737  if (0 != fseek(file->handle,file->file_position,SEEK_SET))
1738  {
1739  snprintf(str,DLT_COMMON_BUFFER_LENGTH,"Seek back also failed!\n");
1740  dlt_log(LOG_WARNING, str);
1741  }
1742 
1743  return DLT_RETURN_ERROR;
1744  }
1745  }
1746  else
1747  {
1748  /* filter is disabled */
1749  /* skip additional header parameters and payload data */
1750  if (fseek(file->handle,file->msg.headersize - sizeof(DltStorageHeader) - sizeof(DltStandardHeader) + file->msg.datasize,SEEK_CUR))
1751  {
1752 
1753  snprintf(str,DLT_COMMON_BUFFER_LENGTH,"Seek failed to skip extra header and payload data from file of size %d!\n",
1754  file->msg.headersize - (int32_t)sizeof(DltStorageHeader) - (int32_t)sizeof(DltStandardHeader) + file->msg.datasize);
1755  dlt_log(LOG_WARNING, str);
1756  /* go back to last position in file */
1757  if (fseek(file->handle,file->file_position,SEEK_SET))
1758  {
1759  snprintf(str,DLT_COMMON_BUFFER_LENGTH,"Seek back also failed!\n");
1760  dlt_log(LOG_WARNING, str);
1761  }
1762  return DLT_RETURN_ERROR;
1763  }
1764 
1765  /* store index pointer to message position in DLT file */
1766  file->index[file->counter] = file->file_position;
1767  file->counter++;
1768  file->position = file->counter - 1;
1769 
1770  found = DLT_RETURN_TRUE;
1771  }
1772 
1773  /* increase total message counter */
1774  file->counter_total++;
1775 
1776  /* store position to next message */
1777  file->file_position = ftell(file->handle);
1778 
1779  return found;
1780 }
1781 
1782 DltReturnValue dlt_file_read_raw(DltFile *file, int resync, int verbose)
1783 {
1784  int found = DLT_RETURN_OK;
1785  long *ptr;
1786 
1787  if (verbose)
1788  {
1789  snprintf(str, DLT_COMMON_BUFFER_LENGTH, "%s: Message %d:\n", __func__, file->counter_total);
1790  dlt_log(LOG_DEBUG, str);
1791  }
1792 
1793  if (file == NULL)
1795 
1796  /* allocate new memory for index if number of messages exceeds a multiple of DLT_COMMON_INDEX_ALLOC (e.g.: 1000) */
1797  if (file->counter % DLT_COMMON_INDEX_ALLOC == 0)
1798  {
1799  ptr = (long *) malloc(((file->counter/DLT_COMMON_INDEX_ALLOC) + 1) * DLT_COMMON_INDEX_ALLOC * sizeof(long));
1800 
1801  if (ptr == NULL)
1802  {
1803  return DLT_RETURN_ERROR;
1804  }
1805 
1806  if (file->index)
1807  {
1808  memcpy(ptr,file->index,file->counter * sizeof(long));
1809  free(file->index);
1810  }
1811  file->index = ptr;
1812  }
1813 
1814  /* set to end of last successful read message, because of conflicting calls to dlt_file_read and dlt_file_message */
1815  if (0 != fseek(file->handle,file->file_position,SEEK_SET))
1816  return DLT_RETURN_ERROR;
1817 
1818  /* get file position at start of DLT message */
1819  if (verbose)
1820  {
1821  snprintf(str,DLT_COMMON_BUFFER_LENGTH,"Position in file: %ld\n",file->file_position);
1822  dlt_log(LOG_DEBUG, str);
1823  }
1824 
1825  /* read header */
1826  if (dlt_file_read_header_raw(file,resync,verbose) < DLT_RETURN_OK)
1827  {
1828  /* go back to last position in file */
1829  if (0!= fseek(file->handle,file->file_position,SEEK_SET))
1830  {
1831  snprintf(str,DLT_COMMON_BUFFER_LENGTH,"dlt_file_read_raw, fseek failed 1\n");
1832  dlt_log(LOG_WARNING, str);
1833  }
1834  return DLT_RETURN_ERROR;
1835  }
1836 
1837  /* read the extended header if filter is enabled and extended header exists */
1838  if (dlt_file_read_header_extended(file, verbose) < DLT_RETURN_OK)
1839  {
1840  /* go back to last position in file */
1841  if (0 != fseek(file->handle,file->file_position,SEEK_SET))
1842  {
1843  snprintf(str,DLT_COMMON_BUFFER_LENGTH,"dlt_file_read_raw, fseek failed 2\n");
1844  dlt_log(LOG_WARNING, str);
1845  }
1846  return DLT_RETURN_ERROR;
1847  }
1848 
1849  if (dlt_file_read_data(file,verbose) < DLT_RETURN_OK)
1850  {
1851  /* go back to last position in file */
1852  if (0 != fseek(file->handle,file->file_position,SEEK_SET))
1853  {
1854  snprintf(str,DLT_COMMON_BUFFER_LENGTH,"dlt_file_read_raw, fseek failed 3\n");
1855  dlt_log(LOG_WARNING, str);
1856  }
1857  return DLT_RETURN_ERROR;
1858  }
1859 
1860  /* store index pointer to message position in DLT file */
1861  file->index[file->counter] = file->file_position;
1862  file->counter++;
1863  file->position = file->counter - 1;
1864 
1865  found = DLT_RETURN_TRUE;
1866 
1867  /* increase total message counter */
1868  file->counter_total++;
1869 
1870  /* store position to next message */
1871  file->file_position = ftell(file->handle);
1872 
1873  return found;
1874 }
1875 
1877 {
1878  PRINT_FUNCTION_VERBOSE(verbose);
1879 
1880  if (file == NULL)
1881  {
1883  }
1884 
1885  if (file->handle)
1886  {
1887  fclose(file->handle);
1888  }
1889 
1890  file->handle = NULL;
1891 
1892  return DLT_RETURN_OK;
1893 }
1894 
1895 DltReturnValue dlt_file_message(DltFile *file, int index, int verbose)
1896 {
1897  PRINT_FUNCTION_VERBOSE(verbose);
1898 
1899  if (file == NULL)
1900  {
1902  }
1903 
1904  /* check if message is in range */
1905  if (index >= file->counter)
1906  {
1907  snprintf(str,DLT_COMMON_BUFFER_LENGTH, "Message %d out of range!\r\n", index);
1908  dlt_log(LOG_WARNING, str);
1910  }
1911 
1912  /* seek to position in file */
1913  if (fseek(file->handle,file->index[index],SEEK_SET)!=0)
1914  {
1915  snprintf(str,DLT_COMMON_BUFFER_LENGTH,"Seek to message %d to position %ld failed!\r\n",index,file->index[index]);
1916  dlt_log(LOG_WARNING, str);
1917  return DLT_RETURN_ERROR;
1918  }
1919 
1920  /* read all header and payload */
1921  if (dlt_file_read_header(file,verbose) < DLT_RETURN_OK)
1922  {
1923  return DLT_RETURN_ERROR;
1924  }
1925 
1926  if (dlt_file_read_header_extended(file,verbose) < DLT_RETURN_OK)
1927  {
1928  return DLT_RETURN_ERROR;
1929  }
1930 
1931  if (dlt_file_read_data(file,verbose) < DLT_RETURN_OK)
1932  {
1933  return DLT_RETURN_ERROR;
1934  }
1935 
1936  /* set current position in file */
1937  file->position = index;
1938 
1939  return DLT_RETURN_OK;
1940 }
1941 
1943 {
1944  PRINT_FUNCTION_VERBOSE(verbose);
1945 
1946  if (file == NULL)
1947  {
1949  }
1950 
1951  /* delete index lost if exists */
1952  if (file->index)
1953  {
1954  free(file->index);
1955  }
1956  file->index = NULL;
1957 
1958  /* close file */
1959  if (file->handle)
1960  {
1961  fclose(file->handle);
1962  }
1963  file->handle = NULL;
1964 
1965  return dlt_message_free(&(file->msg),verbose);
1966 }
1967 
1968 void dlt_log_set_level(int level)
1969 {
1970  if(level < 0 || level > LOG_DEBUG)
1971  {
1972  if(logging_level < LOG_WARNING)
1973  logging_level = LOG_WARNING;
1974 
1975  dlt_vlog(LOG_WARNING, "Wrong parameter for level: %d\n", level);
1976  }
1977  else
1978  logging_level = level;
1979 }
1980 
1981 void dlt_log_set_filename(const char *filename)
1982 {
1983  // check nullpointer
1984  if(filename == NULL)
1985  {
1986  dlt_log(LOG_WARNING, "Wrong parameter: filename is NULL\n");
1987  return;
1988  }
1989 
1990  strncpy(logging_filename, filename, NAME_MAX);
1991  logging_filename[NAME_MAX]=0;
1992 }
1993 
1994 void dlt_log_set_fifo_basedir(const char * env_pipe_dir)
1995 {
1996  strncpy(dltFifoBaseDir, env_pipe_dir, PATH_MAX);
1997  dltFifoBaseDir[PATH_MAX] = 0;
1998 }
1999 
2000 void dlt_log_init(int mode)
2001 {
2002  if(mode < DLT_LOG_TO_CONSOLE || mode > DLT_LOG_DROPPED)
2003  {
2004  dlt_vlog(LOG_WARNING, "Wrong parameter for mode: %d\n", mode);
2005  return;
2006  }
2007 
2008  logging_mode = mode;
2009 
2011  {
2012  /* internal logging to file */
2013  logging_handle = fopen(logging_filename,"w");
2014  if (logging_handle == NULL)
2015  {
2016  printf("Internal log file %s cannot be opened!\n", logging_filename);
2017  return;
2018  }
2019  }
2020 }
2021 
2022 void dlt_log_free(void)
2023 {
2024  if(logging_mode == DLT_LOG_TO_FILE) {
2025  fclose(logging_handle);
2026  }
2027 }
2028 
2029 DltReturnValue dlt_log(int prio, char *s)
2030 {
2031  static const char asSeverity[LOG_DEBUG+2][11] = {"EMERGENCY", "ALERT ", "CRITICAL ", "ERROR ", "WARNING ", "NOTICE ", "INFO ", "DEBUG ", " "};
2032  static const char sFormatString[] = "[%5d.%06d]~DLT~%5d~%s~%s";
2033  struct timespec sTimeSpec;
2034 
2035  if (s == NULL)
2036  {
2038  }
2039  if(logging_level<prio)
2040  {
2041  return DLT_RETURN_OK;
2042  }
2043  if ((prio < 0) || (prio > LOG_DEBUG))
2044  {
2045  prio = LOG_DEBUG + 1;
2046  }
2047 
2048  clock_gettime(CLOCK_MONOTONIC, &sTimeSpec);
2049  switch(logging_mode)
2050  {
2051  case DLT_LOG_TO_CONSOLE:
2052  /* log to stdout */
2053  printf(sFormatString, (unsigned int)sTimeSpec.tv_sec, (unsigned int)(sTimeSpec.tv_nsec/1000), getpid(), asSeverity[prio], s);
2054  break;
2055  case DLT_LOG_TO_SYSLOG:
2056  /* log to syslog */
2057 #if !defined (__WIN32__) && !defined(_MSC_VER)
2058  openlog("DLT",LOG_PID,LOG_DAEMON);
2059  syslog(prio, sFormatString, (unsigned int)sTimeSpec.tv_sec, (unsigned int)(sTimeSpec.tv_nsec/1000), getpid(), asSeverity[prio], s);
2060  closelog();
2061 #endif
2062  break;
2063  case DLT_LOG_TO_FILE:
2064  /* log to file */
2065  if(logging_handle) {
2066  fprintf(logging_handle,sFormatString, (unsigned int)sTimeSpec.tv_sec, (unsigned int)(sTimeSpec.tv_nsec/1000), getpid(), asSeverity[prio], s);
2067  fflush(logging_handle);
2068  }
2069  break;
2070  case DLT_LOG_DROPPED:
2071  default:
2072  break;
2073  }
2074 
2075  return DLT_RETURN_OK;
2076 }
2077 
2078 DltReturnValue dlt_vlog(int prio, const char *format, ...)
2079 {
2080  char outputString[2048] = { 0 }; /* TODO: what is a reasonable string length here? */
2081 
2082  va_list args;
2083 
2084  if (format == NULL)
2086 
2087  if (logging_level < prio)
2088  return DLT_RETURN_OK;
2089 
2090  va_start(args, format);
2091  vsnprintf(outputString, 2047, format, args);
2092  va_end(args);
2093 
2094  dlt_log(prio, outputString);
2095 
2096  return DLT_RETURN_OK;
2097 }
2098 
2099 DltReturnValue dlt_vnlog(int prio, size_t size, const char *format, ...)
2100 {
2101  char *outputString = NULL;
2102 
2103  va_list args;
2104 
2105  if (format == NULL)
2107 
2108  if (logging_level < prio || size == 0)
2109  return DLT_RETURN_OK;
2110 
2111  if ( (outputString = (char*) calloc(size + 1, sizeof(char))) == NULL )
2112  return DLT_RETURN_ERROR;
2113 
2114  va_start(args, format);
2115  vsnprintf(outputString, size, format, args);
2116  va_end(args);
2117 
2118  dlt_log(prio, outputString);
2119 
2120  free(outputString);
2121  outputString = NULL;
2122 
2123  return DLT_RETURN_OK;
2124 }
2125 
2126 DltReturnValue dlt_receiver_init(DltReceiver *receiver, int fd, int buffersize)
2127 {
2128  if (receiver == NULL)
2129  {
2131  }
2132 
2133  receiver->lastBytesRcvd = 0;
2134  receiver->bytesRcvd = 0;
2135  receiver->totalBytesRcvd = 0;
2136  receiver->buffersize = buffersize;
2137  receiver->fd = fd;
2138  receiver->buffer = (char*)malloc(receiver->buffersize);
2139 
2140  if (receiver->buffer == NULL)
2141  {
2142  receiver->buf = NULL;
2143  return DLT_RETURN_ERROR;
2144  }
2145  else
2146  {
2147  receiver->buf = receiver->buffer;
2148  }
2149 
2150  return DLT_RETURN_OK;
2151 }
2152 
2154 {
2155 
2156  if (receiver == NULL)
2157  {
2159  }
2160 
2161  if (receiver->buffer)
2162  {
2163  free(receiver->buffer);
2164  }
2165 
2166  receiver->buffer = NULL;
2167  receiver->buf = NULL;
2168 
2169  return DLT_RETURN_OK;
2170 }
2171 
2172 #ifndef QT_VIEWER
2174 {
2175  if (receiver == NULL)
2176  {
2177  return -1;
2178  }
2179 
2180  if (receiver->buffer == NULL)
2181  {
2182  return -1;
2183  }
2184 
2185  receiver->buf = (char *)receiver->buffer;
2186  receiver->lastBytesRcvd = receiver->bytesRcvd;
2187 
2188  /* wait for data from socket */
2189  if ((receiver->bytesRcvd = recv(receiver->fd, receiver->buf + receiver->lastBytesRcvd, receiver->buffersize - receiver->lastBytesRcvd , 0)) <= 0)
2190  {
2191  receiver->bytesRcvd = 0;
2192 
2193  return receiver->bytesRcvd;
2194  } /* if */
2195 
2196  receiver->totalBytesRcvd += receiver->bytesRcvd;
2197  receiver->bytesRcvd += receiver->lastBytesRcvd;
2198 
2199  return receiver->bytesRcvd;
2200 }
2201 #endif
2202 
2204 {
2205  if (receiver == NULL)
2206  {
2207  return -1;
2208  }
2209 
2210  if (receiver->buffer == NULL)
2211  {
2212  return -1;
2213  }
2214 
2215  receiver->buf = (char *)receiver->buffer;
2216  receiver->lastBytesRcvd = receiver->bytesRcvd;
2217 
2218  /* wait for data from fd */
2219  if ((receiver->bytesRcvd = read(receiver->fd, receiver->buf + receiver->lastBytesRcvd, receiver->buffersize - receiver->lastBytesRcvd)) <= 0)
2220  {
2221  receiver->bytesRcvd = 0;
2222 
2223  return receiver->bytesRcvd;
2224  } /* if */
2225 
2226  receiver->totalBytesRcvd += receiver->bytesRcvd;
2227  receiver->bytesRcvd += receiver->lastBytesRcvd;
2228 
2229  return receiver->bytesRcvd;
2230 }
2231 
2233 {
2234  if (receiver == NULL)
2235  {
2237  }
2238 
2239  if (receiver->buf == NULL)
2240  {
2241  return DLT_RETURN_ERROR;
2242  }
2243 
2244  if (size > receiver->bytesRcvd || size <= 0)
2245  {
2246  receiver->buf = receiver->buf + receiver->bytesRcvd;
2247  receiver->bytesRcvd = 0;
2249  }
2250 
2251  receiver->bytesRcvd = receiver->bytesRcvd - size;
2252  receiver->buf = receiver->buf + size;
2253 
2254  return DLT_RETURN_OK;
2255 }
2256 
2258 {
2259  if (receiver == NULL)
2260  {
2262  }
2263 
2264  if ((receiver->buffer == NULL) || (receiver->buf == NULL))
2265  {
2266  return DLT_RETURN_ERROR;
2267  }
2268 
2269  if ((receiver->buffer!=receiver->buf) && (receiver->bytesRcvd!=0))
2270  {
2271  memmove(receiver->buffer,receiver->buf,receiver->bytesRcvd);
2272  }
2273 
2274  return DLT_RETURN_OK;
2275 }
2276 
2278  void *dest,
2279  unsigned int to_get,
2280  unsigned int flags)
2281 {
2282  unsigned int min_size = to_get;
2283  void *src = NULL;
2284 
2285  if (flags & DLT_RCV_SKIP_HEADER) {
2286  min_size += sizeof(DltUserHeader);
2287  }
2288 
2289  if (!receiver ||
2290  (receiver->bytesRcvd < (int32_t)min_size) ||
2291  !receiver->buf ||
2292  !dest) {
2294  }
2295 
2296  src = (void *)receiver->buf;
2297 
2298  if (flags & DLT_RCV_SKIP_HEADER) {
2299  src += sizeof(DltUserHeader);
2300  }
2301 
2302  memcpy(dest, src, to_get);
2303 
2304  if (flags & DLT_RCV_REMOVE) {
2305  if (dlt_receiver_remove(receiver, min_size) != DLT_RETURN_OK)
2306  {
2307  dlt_log(LOG_WARNING,"Can't remove bytes from receiver\n");
2308  return DLT_RETURN_ERROR;
2309  }
2310  }
2311 
2312  return to_get;
2313 }
2314 
2315 DltReturnValue dlt_set_storageheader(DltStorageHeader *storageheader, const char *ecu)
2316 {
2317 
2318 #if !defined(_MSC_VER)
2319  struct timeval tv;
2320 #endif
2321 
2322  if (storageheader == NULL || ecu == NULL)
2323  {
2325  }
2326 
2327  /* get time of day */
2328 #if defined(_MSC_VER)
2329  time(&(storageheader->seconds));
2330 #else
2331  gettimeofday(&tv, NULL);
2332 #endif
2333 
2334  /* prepare storage header */
2335  storageheader->pattern[0] = 'D';
2336  storageheader->pattern[1] = 'L';
2337  storageheader->pattern[2] = 'T';
2338  storageheader->pattern[3] = 0x01;
2339 
2340  dlt_set_id(storageheader->ecu,ecu);
2341 
2342  /* Set current time */
2343 #if defined(_MSC_VER)
2344  storageheader->microseconds = 0;
2345 #else
2346  storageheader->seconds = (time_t)tv.tv_sec; /* value is long */
2347  storageheader->microseconds = (int32_t)tv.tv_usec; /* value is long */
2348 #endif
2349 
2350  return DLT_RETURN_OK;
2351 }
2352 
2353 DltReturnValue dlt_check_storageheader(DltStorageHeader *storageheader)
2354 {
2355  if (storageheader == NULL)
2357 
2358  return ((storageheader->pattern[0] == 'D') &&
2359  (storageheader->pattern[1] == 'L') &&
2360  (storageheader->pattern[2] == 'T') &&
2361  (storageheader->pattern[3] == 1))
2363 }
2364 
2365 
2366 
2367 
2368 
2369 
2370 
2371 
2372 
2373 
2374 
2375 
2376 DltReturnValue dlt_buffer_init_static_server(DltBuffer *buf, const unsigned char *ptr, uint32_t size)
2377 {
2378  if(buf == NULL || ptr == NULL)
2380 
2381  char str[256];
2382  DltBufferHead *head;
2383 
2384  // Init parameters
2385  buf->shm = (unsigned char *)ptr;
2386  buf->min_size = size;
2387  buf->max_size = size;
2388  buf->step_size = 0;
2389 
2390  // Init pointers
2391  head = (DltBufferHead*)buf->shm;
2392  head->read = 0;
2393  head->write = 0;
2394  head->count = 0;
2395  buf->mem = (unsigned char *)(buf->shm + sizeof(DltBufferHead));
2396  buf->size = buf->min_size - sizeof(DltBufferHead);
2397 
2398  // clear memory
2399  memset(buf->mem, 0, buf->size);
2400 
2401  snprintf(str,sizeof(str),"Buffer: Size %d\n",buf->size);
2402  dlt_log(LOG_DEBUG, str);
2403 
2404  return DLT_RETURN_OK; /* OK */
2405 }
2406 
2407 DltReturnValue dlt_buffer_init_static_client(DltBuffer *buf, const unsigned char *ptr, uint32_t size)
2408 {
2409  if(buf == NULL || ptr == NULL)
2411 
2412  char str[256];
2413 
2414  // Init parameters
2415  buf->shm = (unsigned char *)ptr;
2416  buf->min_size = size;
2417  buf->max_size = size;
2418  buf->step_size = 0;
2419 
2420  // Init pointers
2421  buf->mem = (unsigned char *)(buf->shm + sizeof(DltBufferHead));
2422  buf->size = buf->min_size - sizeof(DltBufferHead);
2423 
2424  snprintf(str,sizeof(str),"Buffer: Size %d\n",buf->size);
2425  dlt_log(LOG_DEBUG, str);
2426 
2427  return DLT_RETURN_OK; /* OK */
2428 }
2429 
2430 DltReturnValue dlt_buffer_init_dynamic(DltBuffer *buf, uint32_t min_size, uint32_t max_size,uint32_t step_size)
2431 {
2432  //Do not DLT_SEM_LOCK inside here!
2433  char str[256];
2434  DltBufferHead *head;
2435 
2436  // catch null pointer
2437  if(buf == NULL)
2439  // catch 0 logical errors
2440  if(min_size == 0 || max_size == 0 || step_size == 0)
2442 
2443  if(min_size > max_size)
2445 
2446  if(step_size > max_size)
2448 
2449  // Init parameters
2450  buf->min_size = min_size;
2451  buf->max_size = max_size;
2452  buf->step_size = step_size;
2453 
2454  // allocat memory
2455  buf->shm = malloc(buf->min_size);
2456  if(buf->shm == NULL) {
2457  snprintf(str,sizeof(str),"Buffer: Cannot allocate %d bytes\n",buf->min_size);
2458  dlt_log(LOG_EMERG, str);
2459  return DLT_RETURN_ERROR;
2460  }
2461 
2462  // Init pointers
2463  head = (DltBufferHead*)buf->shm;
2464  head->read = 0;
2465  head->write = 0;
2466  head->count = 0;
2467  buf->mem = (unsigned char *)(buf->shm + sizeof(DltBufferHead));
2468  buf->size = buf->min_size - sizeof(DltBufferHead);
2469 
2470  // clear memory
2471  memset(buf->mem,0,buf->size);
2472 
2473  //snprintf(str,sizeof(str),"Buffer: Size %d bytes\n",buf->size);
2474  //dlt_log(LOG_INFO, str);
2475 
2476  return DLT_RETURN_OK; /* OK */
2477 }
2478 
2480 {
2481  // catch null pointer
2482  if(buf == NULL)
2484 
2485  if(buf->mem == NULL) {
2486  // buffer not initialized
2487  dlt_log(LOG_WARNING,"Buffer: Buffer not initialized\n");
2488  return DLT_RETURN_ERROR; /* ERROR */
2489  }
2490 
2491  return DLT_RETURN_OK;
2492 }
2493 
2495 {
2496  // catch null pointer
2497  if(buf == NULL)
2499 
2500  if(buf->shm == NULL) {
2501  // buffer not initialized
2502  dlt_log(LOG_WARNING,"Buffer: Buffer not initialized\n");
2503  return DLT_RETURN_ERROR; /* ERROR */
2504  }
2505 
2506  free(buf->shm);
2507  buf->shm = NULL;
2508  buf->mem = NULL;
2509 
2510  return DLT_RETURN_OK;
2511 }
2512 
2513 void dlt_buffer_write_block(DltBuffer *buf, int *write, const unsigned char *data, unsigned int size)
2514 {
2515  // catch null pointer
2516  if(buf != NULL && write != NULL && data != NULL) {
2517  if((int)(*write+size) <= buf->size) {
2518  // write one block
2519  memcpy(buf->mem+*write,data,size);
2520  *write += size;
2521  }
2522  else {
2523  // write two blocks
2524  memcpy(buf->mem+*write, data, buf->size-*write);
2525  memcpy(buf->mem, data+buf->size-*write, size-buf->size+*write);
2526  *write += size-buf->size;
2527  }
2528  }
2529  else
2530  {
2531  dlt_log(LOG_WARNING, "Wrong parameter: Null pointer\n");
2532  }
2533 }
2534 
2535 void dlt_buffer_read_block(DltBuffer *buf, int *read, unsigned char *data, unsigned int size)
2536 {
2537  // catch nullpointer
2538  if(buf != NULL && read != NULL && data != NULL) {
2539  if((int)(*read+size) <= buf->size) {
2540  // read one block
2541  memcpy(data,buf->mem+*read,size);
2542  *read += size;
2543  }
2544  else {
2545  // read two blocks
2546  memcpy(data, buf->mem+*read, buf->size-*read);
2547  memcpy(data+buf->size-*read, buf->mem, size-buf->size+*read);
2548  *read += size-buf->size;
2549  }
2550  }
2551  else
2552  {
2553  dlt_log(LOG_WARNING, "Wrong parameter: Null pointer\n");
2554  }
2555 }
2556 
2558 {
2559  // catch null pointer
2560  if(buf == NULL) {
2561  return -1;
2562  }
2563 
2564  DltBufferHead *head,*new_head;
2565  unsigned char *new_ptr;
2566 
2567  /* check size */
2568  if(buf->step_size==0) {
2569  /* cannot increase size */
2570  return -1;
2571  }
2572 
2573  /* check size */
2574  if((buf->size + sizeof(DltBufferHead) + buf->step_size) > buf->max_size) {
2575  /* max size reached, do not increase */
2576  return -1;
2577  }
2578 
2579  /* allocate new buffer */
2580  new_ptr = malloc(buf->size + sizeof(DltBufferHead) + buf->step_size);
2581  if(new_ptr == NULL) {
2582  snprintf(str,sizeof(str),"Buffer: Cannot increase size because allocate %d bytes failed\n",buf->min_size);
2583  dlt_log(LOG_WARNING, str);
2584  return -1;
2585  }
2586 
2587  /* copy data */
2588  head = (DltBufferHead*)buf->shm;
2589  new_head = (DltBufferHead*)new_ptr;
2590  if(head->read < head->write) {
2591  memcpy(new_ptr+sizeof(DltBufferHead) , buf->mem+head->read , head->write-head->read);
2592  new_head->read = 0;
2593  new_head->write = head->write-head->read;
2594  new_head->count = head->count;
2595  }
2596  else {
2597  memcpy(new_ptr+sizeof(DltBufferHead) , buf->mem+head->read , buf->size-head->read);
2598  memcpy(new_ptr+sizeof(DltBufferHead)+buf->size-head->read , buf->mem , head->write);
2599  new_head->read = 0;
2600  new_head->write = buf->size-head->read+head->write;
2601  new_head->count = head->count;
2602  }
2603 
2604  /* free old data */
2605  free(buf->shm);
2606 
2607  /* update data */
2608  buf->shm = new_ptr;
2609  buf->mem = new_ptr+sizeof(DltBufferHead);
2610  buf->size += buf->step_size;
2611 
2612  snprintf(str,sizeof(str), "Buffer: Size increased to %d bytes\n", buf->size+(int32_t)sizeof(DltBufferHead));
2613  dlt_log(LOG_DEBUG, str);
2614 
2615  return 0; // OK
2616 }
2617 
2619 {
2620  unsigned char *new_ptr;
2621 
2622  // catch null pointer
2623  if(buf == NULL)
2624  {
2625  dlt_log(LOG_WARNING, "Wrong parameter: Null pointer\n");
2626  return -1;
2627  }
2628 
2629  if((buf->size + sizeof(DltBufferHead)) == buf->min_size)
2630  {
2631  /* already minimized */
2632  return 0;
2633  }
2634 
2635  /* allocate new buffer */
2636  new_ptr = malloc(buf->min_size);
2637  if(new_ptr == NULL) {
2638  snprintf(str,sizeof(str),"Buffer: Cannot set to min size of %d bytes\n",buf->min_size);
2639  dlt_log(LOG_WARNING, str);
2640  return -1;
2641  }
2642 
2643  /* free old data */
2644  free(buf->shm);
2645 
2646  /* update data */
2647  buf->shm = new_ptr;
2648  buf->mem = new_ptr+sizeof(DltBufferHead);
2649  buf->size = buf->min_size - sizeof(DltBufferHead);
2650 
2651  /* reset pointers and counters */
2652  ((int*)(buf->shm))[0] = 0; // pointer to write memory
2653  ((int*)(buf->shm))[1] = 0; // pointer to read memory
2654  ((int*)(buf->shm))[2] = 0; // number of packets
2655 
2656  // clear memory
2657  memset(buf->mem, 0, buf->size);
2658 
2659  dlt_log(LOG_DEBUG,"Buffer: Buffer minimized.\n");
2660 
2661  return 0; /* OK */
2662 }
2663 
2665 {
2666  // catch null pointer
2667  if(buf == NULL)
2668  {
2669  dlt_log(LOG_WARNING, "Wrong parameter: Null pointer\n");
2670  return -1;
2671  }
2672 
2673  dlt_log(LOG_WARNING, "Buffer: Buffer reset triggered.\n");
2674 
2675  /* reset pointers and counters */
2676  ((int*)(buf->shm))[0] = 0; // pointer to write memory
2677  ((int*)(buf->shm))[1] = 0; // pointer to read memory
2678  ((int*)(buf->shm))[2] = 0; // number of packets
2679 
2680  // clear memory
2681  memset(buf->mem,0,buf->size);
2682 
2683  return 0; /* OK */
2684 }
2685 
2686 DltReturnValue dlt_buffer_push(DltBuffer *buf,const unsigned char *data,unsigned int size)
2687 {
2688  return dlt_buffer_push3(buf, data, size, 0, 0, 0, 0);
2689 }
2690 
2691 int dlt_buffer_push3(DltBuffer *buf, const unsigned char *data1, unsigned int size1, const unsigned char *data2, unsigned int size2, const unsigned char *data3, unsigned int size3)
2692 {
2693  int free_size;
2694  int write, read, count;
2695  DltBufferBlockHead head;
2696 
2697  // catch null pointer
2698  if (buf == NULL)
2699  return DLT_RETURN_ERROR;
2700 
2701  if (buf->shm == NULL)
2702  {
2703  // buffer not initialised
2704  dlt_log(LOG_ERR, "Buffer: Buffer not initialised\n");
2705  return DLT_RETURN_ERROR; /* ERROR */
2706  }
2707 
2708  // get current write pointer
2709  write = ((int*) (buf->shm))[0];
2710  read = ((int*) (buf->shm))[1];
2711  count = ((int*) (buf->shm))[2];
2712 
2713  // check pointers
2714  if ((read > buf->size) || (write > buf->size))
2715  {
2716  dlt_log(LOG_ERR, "Buffer: Pointer out of range\n");
2717  dlt_buffer_reset(buf);
2718  return DLT_RETURN_ERROR; // ERROR
2719  }
2720 
2721  // calculate free size
2722  if (read > write)
2723  free_size = read - write;
2724  else if (count && (write == read))
2725  free_size = 0;
2726  else
2727  free_size = buf->size - write + read;
2728 
2729  // check size
2730  if (free_size < (int) (sizeof(DltBufferBlockHead) + size1 + size2 + size3))
2731  {
2732  // try to increase size if possible
2733  if (dlt_buffer_increase_size(buf))
2734  {
2735  /* increase size is not possible */
2736  //dlt_log(LOG_ERR,"Buffer: Buffer is full\n");
2737  return DLT_RETURN_ERROR; // ERROR
2738  }
2739 
2740  // update pointers
2741  write = ((int*) (buf->shm))[0];
2742  read = ((int*) (buf->shm))[1];
2743  }
2744 
2745  // set header
2746  strncpy(head.head, DLT_BUFFER_HEAD, 3);
2747  head.head[3] = 0;
2748  head.status = 2;
2749  head.size = size1 + size2 + size3;
2750 
2751  // write data
2752  dlt_buffer_write_block(buf, &write, (unsigned char*) &head, sizeof(DltBufferBlockHead));
2753  if (size1)
2754  dlt_buffer_write_block(buf, &write, data1, size1);
2755  if (size2)
2756  dlt_buffer_write_block(buf, &write, data2, size2);
2757  if (size3)
2758  dlt_buffer_write_block(buf, &write, data3, size3);
2759 
2760  // update global shm pointers
2761  ((int*) (buf->shm))[0] = write; // set new write pointer
2762  ((int*) (buf->shm))[2] += 1; // increase counter
2763 
2764  return DLT_RETURN_OK; // OK
2765 
2766 }
2767 
2768 int dlt_buffer_get(DltBuffer *buf, unsigned char *data, int max_size, int delete)
2769 {
2770  int used_size;
2771  int write, read, count;
2772  char head_compare[] = DLT_BUFFER_HEAD;
2773  DltBufferBlockHead head;
2774 
2775  // catch null pointer
2776  if(buf == NULL)
2777  return -1;
2778 
2779  if(buf->shm == NULL) {
2780  // shm not initialised
2781  dlt_log(LOG_ERR,"Buffer: SHM not initialised\n");
2782  return -1; /* ERROR */
2783  }
2784 
2785  // get current write pointer
2786  write = ((int*)(buf->shm))[0];
2787  read = ((int*)(buf->shm))[1];
2788  count = ((int*)(buf->shm))[2];
2789 
2790  // check pointers
2791  if((read>buf->size) || (write>buf->size) || (count<0))
2792  {
2793  dlt_log(LOG_ERR,"Buffer: Pointer out of range\n");
2794  dlt_buffer_reset(buf);
2795  return -1; // ERROR
2796  }
2797 
2798  // check if data is in there
2799  if(count==0) {
2800  if(write!=read)
2801  {
2802  dlt_log(LOG_ERR,"Buffer: SHM should be empty, but is not\n");
2803  dlt_buffer_reset(buf);
2804  }
2805  return -1; // ERROR
2806  }
2807 
2808  // calculate used size
2809  if(write>read)
2810  used_size = write - read;
2811  else
2812  used_size = buf->size - read + write;
2813 
2814  // first check size
2815  if(used_size < (int)(sizeof(DltBufferBlockHead))) {
2816  dlt_log(LOG_ERR,"Buffer: Size check 1 failed\n");
2817  dlt_buffer_reset(buf);
2818  return -1; // ERROR
2819  }
2820 
2821  // read header
2822  dlt_buffer_read_block(buf,&read,(unsigned char*)&head,sizeof(DltBufferBlockHead));
2823 
2824  // check header
2825  if(memcmp((unsigned char*)(head.head),head_compare,sizeof(head_compare))!=0)
2826  {
2827  dlt_log(LOG_ERR,"Buffer: Header head check failed\n");
2828  dlt_buffer_reset(buf);
2829  return -1; // ERROR
2830  }
2831  if(head.status != 2)
2832  {
2833  dlt_log(LOG_ERR,"Buffer: Header status check failed\n");
2834  dlt_buffer_reset(buf);
2835  return -1; // ERROR
2836  }
2837 
2838  // second check size
2839  if(used_size < (int)(sizeof(DltBufferBlockHead)+head.size)) {
2840  dlt_log(LOG_ERR,"Buffer: Size check 2 failed\n");
2841  dlt_buffer_reset(buf);
2842  return -1; // ERROR
2843  }
2844 
2845  // third check size
2846  if(max_size && (head.size > max_size)) {
2847  dlt_log(LOG_ERR,"Buffer: Size check 3 failed\n");
2848  // nothing to do but data does not fit provided buffer
2849  }
2850 
2851  if(data != NULL && max_size)
2852  {
2853  // read data
2854  dlt_buffer_read_block(buf,&read,data,head.size);
2855 
2856  if(delete)
2857  {
2858  // update buffer pointers
2859  ((int*)(buf->shm))[1] = read; // set new read pointer
2860  }
2861  }
2862  else
2863  {
2864  if(delete) {
2865  if( (read+head.size) <= buf->size)
2866  ((int*)(buf->shm))[1] = read+head.size; // set new read pointer
2867  else
2868  ((int*)(buf->shm))[1] = read+head.size-buf->size; // set new read pointer
2869  }
2870  }
2871  if(delete) {
2872  ((int*)(buf->shm))[2] -= 1; // decrease counter
2873 
2874  if(((int*)(buf->shm))[2] == 0)
2875  {
2876  // try to minimize size
2878  }
2879  }
2880 
2881  return head.size; // OK
2882 }
2883 
2884 int dlt_buffer_pull(DltBuffer *buf,unsigned char *data, int max_size)
2885 {
2886  return dlt_buffer_get(buf,data,max_size,1);
2887 }
2888 
2889 int dlt_buffer_copy(DltBuffer *buf,unsigned char *data, int max_size)
2890 {
2891  return dlt_buffer_get(buf,data,max_size,0);
2892 }
2893 
2895 {
2896  return dlt_buffer_get(buf,0,0,1);
2897 }
2898 
2900 {
2901  // check nullpointer
2902  if(buf == NULL)
2903  return;
2904 
2905  char str[256];
2906 
2907  snprintf(str,sizeof(str),"Buffer: Available size: %d\n",buf->size);
2908  dlt_log(LOG_DEBUG, str);
2909  snprintf(str,sizeof(str),"Buffer: Buffer full start address: %lX\n",(unsigned long)buf->shm);
2910  dlt_log(LOG_DEBUG, str);
2911  snprintf(str,sizeof(str),"Buffer: Buffer start address: %lX\n",(unsigned long)buf->mem);
2912  dlt_log(LOG_DEBUG, str);
2913 
2914 }
2915 
2917 {
2918  int write, read, count;
2919  char str[256];
2920 
2921  // check nullpointer
2922  if(buf == NULL) {
2923  dlt_log(LOG_WARNING, "Wrong parameter: Null pointer\n");
2924  return;
2925  }
2926 
2927  /* check if buffer available */
2928  if(buf->shm == NULL)
2929  return;
2930 
2931  write = ((int*)(buf->shm))[0];
2932  read = ((int*)(buf->shm))[1];
2933  count = ((int*)(buf->shm))[2];
2934 
2935  snprintf(str,sizeof(str),"Buffer: Write: %d\n",write);
2936  dlt_log(LOG_DEBUG, str);
2937  snprintf(str,sizeof(str),"Buffer: Read: %d\n",read);
2938  dlt_log(LOG_DEBUG, str);
2939  snprintf(str,sizeof(str),"Buffer: Count: %d\n",count);
2940  dlt_log(LOG_DEBUG, str);
2941 }
2942 
2944 {
2945  // catch null pointer
2946  if(buf == NULL)
2947  return -1;
2948 
2949  return buf->max_size;
2950 }
2951 
2953 {
2954  int write, read, count;
2955 
2956  // catch null pointer
2957  if(buf == NULL)
2958  return -1;
2959 
2960  /* check if buffer available */
2961  if(buf->shm == NULL)
2962  return 0;
2963 
2964  write = ((int*)(buf->shm))[0];
2965  read = ((int*)(buf->shm))[1];
2966  count = ((int*)(buf->shm))[2];
2967 
2968  if(count == 0)
2969  return 0;
2970 
2971  if(write>read)
2972  return (write - read);
2973 
2974  return (buf->size - read + write);
2975 }
2976 
2978 {
2979  // catch null pointer
2980  if(buf == NULL)
2981  return -1;
2982 
2983  /* check if buffer available */
2984  if(buf->shm == NULL)
2985  return 0;
2986 
2987  return ((int*)(buf->shm))[2];
2988 }
2989 
2990 #if !defined (__WIN32__)
2991 
2992 DltReturnValue dlt_setup_serial(int fd, speed_t speed)
2993 {
2994 #if !defined (__WIN32__) && !defined(_MSC_VER)
2995  struct termios config;
2996 
2997  if (isatty(fd)==0)
2998  {
2999  return DLT_RETURN_ERROR;
3000  }
3001 
3002  if (tcgetattr(fd, &config) < 0)
3003  {
3004  return DLT_RETURN_ERROR;
3005  }
3006 
3007  /* Input flags - Turn off input processing
3008  convert break to null byte, no CR to NL translation,
3009  no NL to CR translation, don't mark parity errors or breaks
3010  no input parity check, don't strip high bit off,
3011  no XON/XOFF software flow control
3012  */
3013  config.c_iflag &= ~(IGNBRK | BRKINT | ICRNL |
3014  INLCR | PARMRK | INPCK | ISTRIP | IXON);
3015 
3016  /* Output flags - Turn off output processing
3017  no CR to NL translation, no NL to CR-NL translation,
3018  no NL to CR translation, no column 0 CR suppression,
3019  no Ctrl-D suppression, no fill characters, no case mapping,
3020  no local output processing
3021 
3022  config.c_oflag &= ~(OCRNL | ONLCR | ONLRET |
3023  ONOCR | ONOEOT| OFILL | OLCUC | OPOST);
3024  */
3025  config.c_oflag = 0;
3026 
3027  /* No line processing:
3028  echo off, echo newline off, canonical mode off,
3029  extended input processing off, signal chars off
3030  */
3031  config.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN | ISIG);
3032 
3033  /* Turn off character processing
3034  clear current char size mask, no parity checking,
3035  no output processing, force 8 bit input
3036  */
3037  config.c_cflag &= ~(CSIZE | PARENB);
3038  config.c_cflag |= CS8;
3039 
3040  /* One input byte is enough to return from read()
3041  Inter-character timer off
3042  */
3043  config.c_cc[VMIN] = 1;
3044  config.c_cc[VTIME] = 0;
3045 
3046  /* Communication speed (simple version, using the predefined
3047  constants)
3048  */
3049  if (cfsetispeed(&config, speed) < 0 || cfsetospeed(&config, speed) < 0)
3050  {
3051  return DLT_RETURN_ERROR;
3052  }
3053 
3054  /* Finally, apply the configuration
3055  */
3056  if (tcsetattr(fd, TCSAFLUSH, &config) < 0)
3057  {
3058  return DLT_RETURN_ERROR;
3059  }
3060 
3061  return DLT_RETURN_OK;
3062 #else
3063  return DLT_RETURN_ERROR;
3064 #endif
3065 }
3066 
3067 speed_t dlt_convert_serial_speed(int baudrate)
3068 {
3069 #if !defined (__WIN32__) && !defined(_MSC_VER) && !defined(__CYGWIN__)
3070  speed_t ret;
3071 
3072  switch (baudrate)
3073  {
3074  case 50:
3075  {
3076  ret = B50;
3077  break;
3078  }
3079  case 75:
3080  {
3081  ret = B75;
3082  break;
3083  }
3084  case 110:
3085  {
3086  ret = B110;
3087  break;
3088  }
3089  case 134:
3090  {
3091  ret = B134;
3092  break;
3093  }
3094  case 150:
3095  {
3096  ret = B150;
3097  break;
3098  }
3099  case 200:
3100  {
3101  ret = B200;
3102  break;
3103  }
3104  case 300:
3105  {
3106  ret = B300;
3107  break;
3108  }
3109  case 600:
3110  {
3111  ret = B600;
3112  break;
3113  }
3114  case 1200:
3115  {
3116  ret = B1200;
3117  break;
3118  }
3119  case 1800:
3120  {
3121  ret = B1800;
3122  break;
3123  }
3124  case 2400:
3125  {
3126  ret = B2400;
3127  break;
3128  }
3129  case 4800:
3130  {
3131  ret = B4800;
3132  break;
3133  }
3134  case 9600:
3135  {
3136  ret = B9600;
3137  break;
3138  }
3139  case 19200:
3140  {
3141  ret = B19200;
3142  break;
3143  }
3144  case 38400:
3145  {
3146  ret = B38400;
3147  break;
3148  }
3149  case 57600:
3150  {
3151  ret = B57600;
3152  break;
3153  }
3154  case 115200:
3155  {
3156  ret = B115200;
3157  break;
3158  }
3159  case 230400:
3160  {
3161  ret = B230400;
3162  break;
3163  }
3164  case 460800:
3165  {
3166  ret = B460800;
3167  break;
3168  }
3169  case 500000:
3170  {
3171  ret = B500000;
3172  break;
3173  }
3174  case 576000:
3175  {
3176  ret = B576000;
3177  break;
3178  }
3179  case 921600:
3180  {
3181  ret = B921600;
3182  break;
3183  }
3184  case 1000000:
3185  {
3186  ret = B1000000;
3187  break;
3188  }
3189  case 1152000:
3190  {
3191  ret = B1152000;
3192  break;
3193  }
3194  case 1500000:
3195  {
3196  ret = B1500000;
3197  break;
3198  }
3199  case 2000000:
3200  {
3201  ret = B2000000;
3202  break;
3203  }
3204  case 2500000:
3205  {
3206  ret = B2500000;
3207  break;
3208  }
3209  case 3000000:
3210  {
3211  ret = B3000000;
3212  break;
3213  }
3214  case 3500000:
3215  {
3216  ret = B3500000;
3217  break;
3218  }
3219  case 4000000:
3220  {
3221  ret = B4000000;
3222  break;
3223  }
3224  default:
3225  {
3226  ret = B115200;
3227  break;
3228  }
3229  }
3230 
3231  return ret;
3232 #else
3233  return 0;
3234 #endif
3235 }
3236 
3237 #endif
3238 
3239 void dlt_get_version(char *buf, size_t size)
3240 {
3241  if(buf == NULL && size > 0)
3242  {
3243  dlt_log(LOG_WARNING, "Wrong parameter: Null pointer\n");
3244  return;
3245  }
3246 
3247  snprintf(buf,size,"DLT Package Version: %s %s, Package Revision: %s, build on %s %s\n%s %s %s %s\n",
3249 }
3250 
3251 void dlt_get_major_version(char *buf, size_t size)
3252 {
3253  if (buf == NULL && size > 0)
3254  {
3255  dlt_log(LOG_WARNING, "Wrong parameter: Null pointer\n");
3256  return;
3257  }
3258 
3259  snprintf(buf, size, "%s", _DLT_PACKAGE_MAJOR_VERSION);
3260 }
3261 
3262 void dlt_get_minor_version(char *buf, size_t size)
3263 {
3264  if (buf == NULL && size > 0)
3265  {
3266  dlt_log(LOG_WARNING, "Wrong parameter: Null pointer\n");
3267  return;
3268  }
3269 
3270  snprintf(buf, size, "%s", _DLT_PACKAGE_MINOR_VERSION);
3271 }
3272 
3273 
3274 uint32_t dlt_uptime(void)
3275 {
3276 
3277 #if defined (__WIN32__) || defined(_MSC_VER)
3278 
3279  return (uint32_t)(GetTickCount()*10); /* GetTickCount() return DWORD */
3280 
3281 #else
3282  struct timespec ts;
3283 
3284  if (clock_gettime(CLOCK_MONOTONIC,&ts)==0)
3285  {
3286  return ( (uint32_t)ts.tv_sec*10000 + (uint32_t)ts.tv_nsec/100000 );// in 0.1 ms = 100 us
3287  }
3288  else
3289  {
3290  return 0;
3291  }
3292 
3293 #endif
3294 
3295 }
3296 
3297 DltReturnValue dlt_message_print_header(DltMessage *message, char *text, uint32_t size, int verbose)
3298 {
3299  if ((message == NULL) || (text == NULL))
3300  {
3302  }
3303 
3304  dlt_message_header(message, text, size, verbose);
3305  printf("%s\n",text);
3306 
3307  return DLT_RETURN_OK;
3308 }
3309 
3310 DltReturnValue dlt_message_print_hex(DltMessage *message, char *text, uint32_t size, int verbose)
3311 {
3312  if ((message == NULL) || (text == NULL))
3313  {
3315  }
3316 
3317  dlt_message_header(message,text,size,verbose);
3318  printf("%s ",text);
3319  dlt_message_payload(message,text,size,DLT_OUTPUT_HEX,verbose);
3320  printf("[%s]\n",text);
3321 
3322  return DLT_RETURN_OK;
3323 }
3324 
3325 DltReturnValue dlt_message_print_ascii(DltMessage *message, char *text, uint32_t size, int verbose)
3326 {
3327  if ((message == NULL) || (text == NULL))
3328  {
3330  }
3331 
3332  dlt_message_header(message,text,size,verbose);
3333  printf("%s ",text);
3334  dlt_message_payload(message,text,size,DLT_OUTPUT_ASCII,verbose);
3335  printf("[%s]\n",text);
3336 
3337  return DLT_RETURN_OK;
3338 }
3339 
3340 DltReturnValue dlt_message_print_mixed_plain(DltMessage *message, char *text, uint32_t size, int verbose)
3341 {
3342  if ((message == NULL) || (text == NULL))
3343  {
3345  }
3346 
3347  dlt_message_header(message,text,size,verbose);
3348  printf("%s \n",text);
3349  dlt_message_payload(message,text,size,DLT_OUTPUT_MIXED_FOR_PLAIN,verbose);
3350  printf("[%s]\n",text);
3351 
3352  return DLT_RETURN_OK;
3353 }
3354 
3355 DltReturnValue dlt_message_print_mixed_html(DltMessage *message, char *text, uint32_t size, int verbose)
3356 {
3357  if ((message == NULL) || (text == NULL))
3358  {
3360  }
3361 
3362  dlt_message_header(message,text,size,verbose);
3363  printf("%s \n",text);
3364  dlt_message_payload(message,text,size,DLT_OUTPUT_MIXED_FOR_HTML,verbose);
3365  printf("[%s]\n",text);
3366 
3367  return DLT_RETURN_OK;
3368 }
3369 
3370 DltReturnValue dlt_message_argument_print(DltMessage *msg,uint32_t type_info,uint8_t **ptr,int32_t *datalength,char *text,int textlength,int byteLength,int __attribute__((unused)) verbose)
3371 {
3372  // check null pointers
3373  if(msg == NULL || ptr == NULL || datalength == NULL || text == NULL)
3375 
3376  int16_t length=0,length_tmp=0; /* the macro can set this variable to -1 */
3377  uint16_t length2=0,length2_tmp=0,length3=0,length3_tmp=0;
3378 
3379  uint8_t value8u=0;
3380  uint16_t value16u=0,value16u_tmp=0;
3381  uint32_t value32u=0,value32u_tmp=0;
3382  uint64_t value64u=0,value64u_tmp=0;
3383 
3384  int8_t value8i=0;
3385  int16_t value16i=0,value16i_tmp=0;
3386  int32_t value32i=0,value32i_tmp=0;
3387  int64_t value64i=0,value64i_tmp=0;
3388 
3389  float32_t value32f=0,value32f_tmp=0;
3390  int32_t value32f_tmp_int32i=0,value32f_tmp_int32i_swaped=0;
3391  float64_t value64f=0,value64f_tmp=0;
3392  int64_t value64f_tmp_int64i=0,value64f_tmp_int64i_swaped=0;
3393 
3394  uint32_t quantisation_tmp = 0;
3395 
3396  /* apparently this makes no sense but needs to be done to prevent compiler warning.
3397  * This variable is only written by DLT_MSG_READ_VALUE macro in if (type_info & DLT_TYPE_INFO_FIXP)
3398  * case but never read anywhere */
3399  quantisation_tmp += quantisation_tmp;
3400 
3401  if ( (type_info & DLT_TYPE_INFO_STRG) && (((type_info & DLT_TYPE_INFO_SCOD) == DLT_SCOD_ASCII) || ((type_info & DLT_TYPE_INFO_SCOD) == DLT_SCOD_UTF8)) )
3402  {
3403  /* string type or utf8-encoded string type */
3404  if (byteLength<0)
3405  {
3406  DLT_MSG_READ_VALUE(length_tmp,*ptr,*datalength,uint16_t);
3407  if((*datalength)<0)
3408  return DLT_RETURN_ERROR;
3409  length=DLT_ENDIAN_GET_16(msg->standardheader->htyp, length_tmp);
3410  }
3411  else
3412  {
3413  length=(int16_t)byteLength;
3414  }
3415 
3416  if (type_info & DLT_TYPE_INFO_VARI)
3417  {
3418  DLT_MSG_READ_VALUE(length2_tmp,*ptr,*datalength,uint16_t);
3419  if((*datalength)<0)
3420  return DLT_RETURN_ERROR;
3421  length2=DLT_ENDIAN_GET_16(msg->standardheader->htyp, length2_tmp);
3422  if((*datalength)<length2)
3423  return DLT_RETURN_ERROR;
3424  *ptr += length2;
3425  *datalength-=length2;
3426  }
3427 
3428  DLT_MSG_READ_STRING((text+strlen(text)),*ptr,*datalength,length);
3429  if((*datalength)<0)
3430  return DLT_RETURN_ERROR;
3431 
3432  }
3433  else if (type_info & DLT_TYPE_INFO_BOOL)
3434  {
3435  /* Boolean type */
3436  if (type_info & DLT_TYPE_INFO_VARI)
3437  {
3438  DLT_MSG_READ_VALUE(length2_tmp,*ptr,*datalength,uint16_t);
3439  if((*datalength)<0)
3440  return DLT_RETURN_ERROR;
3441  length2=DLT_ENDIAN_GET_16(msg->standardheader->htyp, length2_tmp);
3442  if((*datalength)<length2)
3443  return DLT_RETURN_ERROR;
3444  *ptr += length2;
3445  *datalength-=length2;
3446  }
3447  value8u=0;
3448  DLT_MSG_READ_VALUE(value8u,*ptr,*datalength,uint8_t); /* No endian conversion necessary */
3449  if((*datalength)<0)
3450  return DLT_RETURN_ERROR;
3451  snprintf(text+strlen(text),textlength-strlen(text),"%d",value8u);
3452  }
3453  else if ((type_info & DLT_TYPE_INFO_UINT) && (DLT_SCOD_BIN == (type_info & DLT_TYPE_INFO_SCOD)))
3454  {
3455  if (DLT_TYLE_8BIT == (type_info & DLT_TYPE_INFO_TYLE))
3456  {
3457  DLT_MSG_READ_VALUE(value8u,*ptr,*datalength,uint8_t); /* No endian conversion necessary */
3458  if((*datalength)<0)
3459  return DLT_RETURN_ERROR;
3460  char binary[10] = {'\0'}; // e.g.: "0b1100 0010"
3461  int i;
3462  for (i = (1 << 7); i > 0; i >>= 1)
3463  {
3464  if ((1<<3) == i)
3465  strcat(binary, " ");
3466  strcat(binary, (i == (value8u & i)) ? "1" : "0");
3467  }
3468 
3469  snprintf(text+strlen(text),textlength-strlen(text),"0b%s",binary);
3470  }
3471  if (DLT_TYLE_16BIT == (type_info & DLT_TYPE_INFO_TYLE))
3472  {
3473  DLT_MSG_READ_VALUE(value16u,*ptr,*datalength,uint16_t);
3474  if((*datalength)<0)
3475  return DLT_RETURN_ERROR;
3476  char binary[20] = {'\0'}; // e.g.: "0b1100 0010 0011 0110"
3477  int i;
3478  for (i = (1 << 15); i > 0; i >>= 1)
3479  {
3480  if (((1<<3) == i) || ((1<<7) == i) || ((1<<11) == i))
3481  strcat(binary, " ");
3482  strcat(binary, (i == (value16u & i)) ? "1" : "0");
3483  }
3484 
3485  snprintf(text+strlen(text),textlength-strlen(text),"0b%s",binary);
3486  }
3487  }
3488  else if ((type_info & DLT_TYPE_INFO_UINT) && (DLT_SCOD_HEX == (type_info & DLT_TYPE_INFO_SCOD)))
3489  {
3490  if (DLT_TYLE_8BIT == (type_info & DLT_TYPE_INFO_TYLE))
3491  {
3492  DLT_MSG_READ_VALUE(value8u,*ptr,*datalength,uint8_t); /* No endian conversion necessary */
3493  if((*datalength)<0)
3494  return DLT_RETURN_ERROR;
3495  snprintf(text+strlen(text),textlength-strlen(text),"0x%02x",value8u);
3496  }
3497  if (DLT_TYLE_16BIT == (type_info & DLT_TYPE_INFO_TYLE))
3498  {
3499  DLT_MSG_READ_VALUE(value16u,*ptr,*datalength,uint16_t);
3500  if((*datalength)<0)
3501  return DLT_RETURN_ERROR;
3502  snprintf(text+strlen(text),textlength-strlen(text),"0x%04x",value16u);
3503  }
3504  if (DLT_TYLE_32BIT == (type_info & DLT_TYPE_INFO_TYLE))
3505  {
3506  DLT_MSG_READ_VALUE(value32u,*ptr,*datalength,uint32_t);
3507  if((*datalength)<0)
3508  return DLT_RETURN_ERROR;
3509  snprintf(text+strlen(text),textlength-strlen(text),"0x%08x",value32u);
3510  }
3511  if (DLT_TYLE_64BIT == (type_info & DLT_TYPE_INFO_TYLE))
3512  {
3513  *ptr += 4;
3514  DLT_MSG_READ_VALUE(value32u,*ptr,*datalength,uint32_t);
3515  if((*datalength)<0)
3516  return DLT_RETURN_ERROR;
3517  snprintf(text+strlen(text),textlength-strlen(text),"0x%08x",value32u);
3518  *ptr -= 8;
3519  DLT_MSG_READ_VALUE(value32u,*ptr,*datalength,uint32_t);
3520  if((*datalength)<0)
3521  return DLT_RETURN_ERROR;
3522  snprintf(text+strlen(text),textlength-strlen(text),"%08x",value32u);
3523  *ptr += 4;
3524  }
3525  }
3526  else if ((type_info & DLT_TYPE_INFO_SINT) || (type_info & DLT_TYPE_INFO_UINT))
3527  {
3528  /* signed or unsigned argument received */
3529  if (type_info & DLT_TYPE_INFO_VARI)
3530  {
3531  DLT_MSG_READ_VALUE(length2_tmp,*ptr,*datalength,uint16_t);
3532  if((*datalength)<0)
3533  return DLT_RETURN_ERROR;
3534  length2=DLT_ENDIAN_GET_16(msg->standardheader->htyp, length2_tmp);
3535  DLT_MSG_READ_VALUE(length3_tmp,*ptr,*datalength,uint16_t);
3536  if((*datalength)<0)
3537  return DLT_RETURN_ERROR;
3538  length3=DLT_ENDIAN_GET_16(msg->standardheader->htyp, length3_tmp);
3539  if((*datalength)<length2)
3540  return DLT_RETURN_ERROR;
3541  *ptr += length2;
3542  *datalength-=length2;
3543  if((*datalength)<length3)
3544  return DLT_RETURN_ERROR;
3545  *ptr += length3;
3546  *datalength-=length3;
3547  }
3548  if (type_info & DLT_TYPE_INFO_FIXP)
3549  {
3550  DLT_MSG_READ_VALUE(quantisation_tmp, *ptr, *datalength, uint32_t);
3551 
3552  if((*datalength)<0)
3553  return DLT_RETURN_ERROR;
3554 
3555  switch ( type_info & DLT_TYPE_INFO_TYLE)
3556  {
3557  case DLT_TYLE_8BIT:
3558  case DLT_TYLE_16BIT:
3559  case DLT_TYLE_32BIT:
3560  {
3561  if((*datalength)<4)
3562  return DLT_RETURN_ERROR;
3563  *ptr += 4;
3564  *datalength-=4;
3565  break;
3566  }
3567  case DLT_TYLE_64BIT:
3568  {
3569  if((*datalength)<8)
3570  return DLT_RETURN_ERROR;
3571  *ptr += 8;
3572  *datalength-=8;
3573  break;
3574  }
3575  case DLT_TYLE_128BIT:
3576  {
3577  if((*datalength)<16)
3578  return DLT_RETURN_ERROR;
3579  *ptr += 16;
3580  *datalength-=16;
3581  break;
3582  }
3583  default:
3584  {
3585  return DLT_RETURN_ERROR;
3586  }
3587  }
3588  }
3589  switch (type_info & DLT_TYPE_INFO_TYLE)
3590  {
3591  case DLT_TYLE_8BIT:
3592  {
3593  if (type_info & DLT_TYPE_INFO_SINT)
3594  {
3595  value8i=0;
3596  DLT_MSG_READ_VALUE(value8i,*ptr,*datalength,int8_t); /* No endian conversion necessary */
3597  if((*datalength)<0)
3598  return DLT_RETURN_ERROR;
3599  snprintf(text+strlen(text),textlength-strlen(text),"%d",value8i);
3600  }
3601  else
3602  {
3603  value8u=0;
3604  DLT_MSG_READ_VALUE(value8u,*ptr,*datalength,uint8_t); /* No endian conversion necessary */
3605  if((*datalength)<0)
3606  return DLT_RETURN_ERROR;
3607  snprintf(text+strlen(text),textlength-strlen(text),"%d",value8u);
3608  }
3609  break;
3610  }
3611  case DLT_TYLE_16BIT:
3612  {
3613  if (type_info & DLT_TYPE_INFO_SINT)
3614  {
3615  value16i=0;
3616  value16i_tmp=0;
3617  DLT_MSG_READ_VALUE(value16i_tmp,*ptr,*datalength,int16_t);
3618  if((*datalength)<0)
3619  return DLT_RETURN_ERROR;
3620  value16i=DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16i_tmp);
3621  snprintf(text+strlen(text),textlength-strlen(text),"%hd",value16i);
3622  }
3623  else
3624  {
3625  value16u=0;
3626  value16u_tmp=0;
3627  DLT_MSG_READ_VALUE(value16u_tmp,*ptr,*datalength,uint16_t);
3628  if((*datalength)<0)
3629  return DLT_RETURN_ERROR;
3630  value16u=DLT_ENDIAN_GET_16(msg->standardheader->htyp, value16u_tmp);
3631  snprintf(text+strlen(text),textlength-strlen(text),"%hu",value16u);
3632  }
3633  break;
3634  }
3635  case DLT_TYLE_32BIT:
3636  {
3637  if (type_info & DLT_TYPE_INFO_SINT)
3638  {
3639  value32i=0;
3640  value32i_tmp=0;
3641  DLT_MSG_READ_VALUE(value32i_tmp,*ptr,*datalength,int32_t);
3642  if((*datalength)<0)
3643  return DLT_RETURN_ERROR;
3644  value32i=DLT_ENDIAN_GET_32(msg->standardheader->htyp, (uint32_t)value32i_tmp);
3645  snprintf(text+strlen(text),textlength-strlen(text),"%d",value32i);
3646  }
3647  else
3648  {
3649  value32u=0;
3650  value32u_tmp=0;
3651  DLT_MSG_READ_VALUE(value32u_tmp,*ptr,*datalength,uint32_t);
3652  if((*datalength)<0)
3653  return DLT_RETURN_ERROR;
3654  value32u=DLT_ENDIAN_GET_32(msg->standardheader->htyp, value32u_tmp);
3655  snprintf(text+strlen(text),textlength-strlen(text),"%u",value32u);
3656  }
3657  break;
3658  }
3659  case DLT_TYLE_64BIT:
3660  {
3661  if (type_info & DLT_TYPE_INFO_SINT)
3662  {
3663  value64i=0;
3664  value64i_tmp=0;
3665  DLT_MSG_READ_VALUE(value64i_tmp,*ptr,*datalength,int64_t);
3666  if((*datalength)<0)
3667  return DLT_RETURN_ERROR;
3668  value64i=DLT_ENDIAN_GET_64(msg->standardheader->htyp, (uint64_t)value64i_tmp);
3669  #if defined (__WIN32__) && !defined(_MSC_VER)
3670  snprintf(text+strlen(text),textlength-strlen(text),"%I64d",value64i);
3671  #else
3672  snprintf(text+strlen(text),textlength-strlen(text),"%"PRId64, value64i);
3673  #endif
3674  }
3675  else
3676  {
3677  value64u=0;
3678  value64u_tmp=0;
3679  DLT_MSG_READ_VALUE(value64u_tmp,*ptr,*datalength,uint64_t);
3680  if((*datalength)<0)
3681  return DLT_RETURN_ERROR;
3682  value64u=DLT_ENDIAN_GET_64(msg->standardheader->htyp, value64u_tmp);
3683  #if defined (__WIN32__) && !defined(_MSC_VER)
3684  snprintf(text+strlen(text),textlength-strlen(text),"%I64u",value64u);
3685  #else
3686  snprintf(text+strlen(text),textlength-strlen(text),"%"PRId64,value64u);
3687  #endif
3688  }
3689  break;
3690  }
3691  case DLT_TYLE_128BIT:
3692  {
3693  if (*datalength>=16)
3694  dlt_print_hex_string(text+strlen(text),textlength,*ptr,16);
3695  if((*datalength)<16)
3696  return DLT_RETURN_ERROR;
3697  *ptr += 16;
3698  *datalength-=16;
3699  break;
3700  }
3701  default:
3702  {
3703  return DLT_RETURN_ERROR;
3704  }
3705  }
3706  }
3707  else if (type_info & DLT_TYPE_INFO_FLOA)
3708  {
3709  /* float data argument */
3710  if (type_info & DLT_TYPE_INFO_VARI)
3711  {
3712  DLT_MSG_READ_VALUE(length2_tmp,*ptr,*datalength,uint16_t);
3713  if((*datalength)<0)
3714  return DLT_RETURN_ERROR;
3715  length2=DLT_ENDIAN_GET_16(msg->standardheader->htyp, length2_tmp);
3716  DLT_MSG_READ_VALUE(length3_tmp,*ptr,*datalength,uint16_t);
3717  if((*datalength)<0)
3718  return DLT_RETURN_ERROR;
3719  length3=DLT_ENDIAN_GET_16(msg->standardheader->htyp, length3_tmp);
3720  if((*datalength)<length2)
3721  return DLT_RETURN_ERROR;
3722  *ptr += length2;
3723  *datalength-=length2;
3724  if((*datalength)<length3)
3725  return DLT_RETURN_ERROR;
3726  *ptr += length3;
3727  *datalength-=length3;
3728  }
3729  switch ( type_info & DLT_TYPE_INFO_TYLE)
3730  {
3731  case DLT_TYLE_8BIT:
3732  {
3733  if (*datalength>=1)
3734  dlt_print_hex_string(text+strlen(text),textlength,*ptr,1);
3735  if((*datalength)<1)
3736  return DLT_RETURN_ERROR;
3737  *ptr += 1;
3738  *datalength-=1;
3739  break;
3740  }
3741  case DLT_TYLE_16BIT:
3742  {
3743  if (*datalength>=2)
3744  dlt_print_hex_string(text+strlen(text),textlength,*ptr,2);
3745  if((*datalength)<2)
3746  return DLT_RETURN_ERROR;
3747  *ptr += 2;
3748  *datalength-=2;
3749  break;
3750  }
3751  case DLT_TYLE_32BIT:
3752  {
3753  if (sizeof(float32_t)==4)
3754  {
3755  value32f=0;
3756  value32f_tmp=0;
3757  value32f_tmp_int32i=0;
3758  value32f_tmp_int32i_swaped=0;
3759  DLT_MSG_READ_VALUE(value32f_tmp,*ptr,*datalength,float32_t);
3760  if((*datalength)<0)
3761  return DLT_RETURN_ERROR;
3762  memcpy(&value32f_tmp_int32i,&value32f_tmp,sizeof(float32_t));
3763  value32f_tmp_int32i_swaped=DLT_ENDIAN_GET_32(msg->standardheader->htyp, (uint32_t)value32f_tmp_int32i);
3764  memcpy(&value32f,&value32f_tmp_int32i_swaped,sizeof(float32_t));
3765  snprintf(text+strlen(text),textlength-strlen(text),"%g",value32f);
3766  }
3767  else
3768  {
3769  dlt_log(LOG_ERR, "Invalid size of float32_t\n");
3770  return DLT_RETURN_ERROR;
3771  }
3772  break;
3773  }
3774  case DLT_TYLE_64BIT:
3775  {
3776  if (sizeof(float64_t)==8)
3777  {
3778  value64f=0;
3779  value64f_tmp=0;
3780  value64f_tmp_int64i=0;
3781  value64f_tmp_int64i_swaped=0;
3782  DLT_MSG_READ_VALUE(value64f_tmp,*ptr,*datalength,float64_t);
3783  if((*datalength)<0)
3784  return DLT_RETURN_ERROR;
3785  memcpy(&value64f_tmp_int64i,&value64f_tmp,sizeof(float64_t));
3786  value64f_tmp_int64i_swaped=DLT_ENDIAN_GET_64(msg->standardheader->htyp, (uint64_t)value64f_tmp_int64i);
3787  memcpy(&value64f,&value64f_tmp_int64i_swaped,sizeof(float64_t));
3788 #ifdef __arm__
3789  snprintf(text+strlen(text),textlength-strlen(text),"ILLEGAL");
3790 #else
3791  snprintf(text+strlen(text),textlength-strlen(text),"%g",value64f);
3792 #endif
3793  }
3794  else
3795  {
3796  dlt_log(LOG_ERR, "Invalid size of float64_t\n");
3797  return DLT_RETURN_ERROR;
3798  }
3799  break;
3800  }
3801  case DLT_TYLE_128BIT:
3802  {
3803  if (*datalength>=16)
3804  dlt_print_hex_string(text+strlen(text),textlength,*ptr,16);
3805  if((*datalength)<16)
3806  return DLT_RETURN_ERROR;
3807  *ptr += 16;
3808  *datalength-=16;
3809  break;
3810  }
3811  default:
3812  {
3813  return DLT_RETURN_ERROR;
3814  }
3815  }
3816 
3817  }
3818  else if (type_info & DLT_TYPE_INFO_RAWD)
3819  {
3820  /* raw data argument */
3821  DLT_MSG_READ_VALUE(length_tmp,*ptr,*datalength,uint16_t);
3822  if((*datalength)<0)
3823  return DLT_RETURN_ERROR;
3824  length=DLT_ENDIAN_GET_16(msg->standardheader->htyp, length_tmp);
3825  if (type_info & DLT_TYPE_INFO_VARI)
3826  {
3827  DLT_MSG_READ_VALUE(length2_tmp,*ptr,*datalength,uint16_t);
3828  if((*datalength)<0)
3829  return DLT_RETURN_ERROR;
3830  length2=DLT_ENDIAN_GET_16(msg->standardheader->htyp, length2_tmp);
3831  if((*datalength)<length2)
3832  return DLT_RETURN_ERROR;
3833  *ptr += length2;
3834  *datalength-=length2;
3835  }
3836  if((*datalength)<length)
3837  return DLT_RETURN_ERROR;
3838  dlt_print_hex_string(text+strlen(text),textlength,*ptr,length);
3839  *ptr+=length;
3840  *datalength-=length;
3841  }
3842  else if (type_info & DLT_TYPE_INFO_TRAI)
3843  {
3844  /* trace info argument */
3845  DLT_MSG_READ_VALUE(length_tmp,*ptr,*datalength,uint16_t);
3846  if((*datalength)<0)
3847  return DLT_RETURN_ERROR;
3848  length=DLT_ENDIAN_GET_16(msg->standardheader->htyp, length_tmp);
3849  DLT_MSG_READ_STRING((text+strlen(text)),*ptr,*datalength,length);
3850  if((*datalength)<0)
3851  return DLT_RETURN_ERROR;
3852  }
3853  else
3854  {
3855  return DLT_RETURN_ERROR;
3856  }
3857 
3858  if (*datalength<0)
3859  {
3860  dlt_log(LOG_ERR, "Payload of DLT message corrupted\n");
3861  return DLT_RETURN_ERROR;
3862  }
3863 
3864  return DLT_RETURN_OK;
3865 }
3866 
3868 {
3869  char* env_log_filename = getenv("DLT_LOG_FILENAME");
3870 
3871  if( env_log_filename != NULL )
3872  {
3873  dlt_log_set_filename(env_log_filename);
3874  }
3875 
3876  char* env_log_level_str = getenv("DLT_LOG_LEVEL");
3877 
3878  if( env_log_level_str != NULL )
3879  {
3880  int level = 0;
3881  if( sscanf(env_log_level_str, "%d", &level) )
3882  {
3883  dlt_log_set_level(level);
3884  }
3885  }
3886 
3887  char* env_log_mode = getenv("DLT_LOG_MODE");
3888 
3889  if( env_log_mode != NULL )
3890  {
3891  int mode = 0;
3892  if( sscanf(env_log_mode, "%d", &mode) )
3893  {
3894  dlt_log_init(mode);
3895  }
3896  }
3897 
3898  char* env_pipe_dir = getenv("DLT_PIPE_DIR");
3899  if( env_pipe_dir != NULL )
3900  {
3901  dlt_log_set_fifo_basedir(env_pipe_dir);
3902  }
3903 }
3904 
3905 int dlt_mkdir_recursive(const char *dir)
3906 {
3907  int ret = 0;
3908  char tmp[PATH_MAX+1];
3909  char *p = NULL;
3910  char *end = NULL;
3911  size_t len;
3912 
3913  strncpy(tmp, dir, PATH_MAX);
3914  len = strlen(tmp);
3915  if(tmp[len - 1] == '/')
3916  {
3917  tmp[len - 1] = 0;
3918  }
3919  end = tmp + len;
3920 
3921  for(p = tmp + 1; ((*p) && (ret == 0)) || ((ret == -1 && errno == EEXIST) && (p != end)); p++)
3922  {
3923  if(*p == '/')
3924  {
3925  *p = 0;
3926  ret = mkdir(tmp, S_IRWXU);
3927  *p = '/';
3928  }
3929  }
3930 
3931  if (ret == 0 || (ret == -1 && errno == EEXIST))
3932  {
3933  ret = mkdir(tmp, S_IRWXU);
3934  }
3935 
3936  if (ret == -1 && errno == EEXIST)
3937  {
3938  ret = 0;
3939  }
3940 
3941  return ret;
3942 }
int32_t datasize
Definition: dlt_common.h:423
static char str[DLT_COMMON_BUFFER_LENGTH]
Definition: dlt_common.c:68
#define DLT_HEADER_SHOW_TIME
Definition: dlt_common.h:312
static char logging_filename[NAME_MAX+1]
Definition: dlt_common.c:77
DltReturnValue dlt_file_open(DltFile *file, const char *filename, int verbose)
Definition: dlt_common.c:1594
#define DLT_MESSAGE_ERROR_UNKNOWN
Definition: dlt_common.h:711
int dlt_message_read(DltMessage *msg, uint8_t *buffer, unsigned int length, int resync, int verbose)
Definition: dlt_common.c:1091
#define DLT_RCV_SKIP_HEADER
Definition: dlt_common.h:326
DltReturnValue dlt_file_read_data(DltFile *file, int verbose)
Definition: dlt_common.c:1551
DltReturnValue dlt_buffer_push(DltBuffer *buf, const unsigned char *data, unsigned int size)
Definition: dlt_common.c:2686
int dlt_receiver_receive_socket(DltReceiver *receiver)
Definition: dlt_common.c:2173
DltReturnValue dlt_file_read_header(DltFile *file, int verbose)
Definition: dlt_common.c:1346
#define DLT_SCOD_UTF8
Definition: dlt_protocol.h:169
#define PRINT_FUNCTION_VERBOSE(_verbose)
Definition: dlt_common.h:220
DltReturnValue dlt_buffer_init_dynamic(DltBuffer *buf, uint32_t min_size, uint32_t max_size, uint32_t step_size)
Definition: dlt_common.c:2430
#define DLT_ENDIAN_GET_32(htyp, x)
Definition: dlt_common.h:165
#define DLT_ID_SIZE
Definition: dlt_common.h:204
int8_t found_serialheader
Definition: dlt_common.h:416
DltReturnValue dlt_message_print_header(DltMessage *message, char *text, uint32_t size, int verbose)
Definition: dlt_common.c:3297
#define DLT_TYPE_INFO_SINT
Definition: dlt_protocol.h:150
DltStorageHeader * storageheader
Definition: dlt_common.h:432
uint32_t dlt_buffer_get_total_size(DltBuffer *buf)
Definition: dlt_common.c:2943
DltReturnValue
Definition: dlt_types.h:86
DltReturnValue dlt_filter_save(DltFilter *filter, const char *filename, int verbose)
Definition: dlt_common.c:496
void dlt_check_envvar()
Definition: dlt_common.c:3867
DltReturnValue dlt_file_message(DltFile *file, int index, int verbose)
Definition: dlt_common.c:1895
int32_t buffersize
Definition: dlt_common.h:680
#define DLT_TYLE_32BIT
Definition: dlt_protocol.h:164
#define DLT_COMMON_DUMMY_ECUID
void dlt_get_minor_version(char *buf, size_t size)
Definition: dlt_common.c:3262
char * control_type[]
Definition: dlt_common.c:84
#define DLT_COMMON_ASCII_LIMIT_MAX_CHARS
void dlt_set_id(char *id, const char *text)
Definition: dlt_common.c:324
int dlt_buffer_reset(DltBuffer *buf)
Definition: dlt_common.c:2664
void dlt_buffer_info(DltBuffer *buf)
Definition: dlt_common.c:2899
DltReturnValue dlt_file_set_filter(DltFile *file, DltFilter *filter, int verbose)
Definition: dlt_common.c:1331
#define DLT_COMMON_ASCII_CHAR_LT
DltReturnValue dlt_message_argument_print(DltMessage *msg, uint32_t type_info, uint8_t **ptr, int32_t *datalength, char *text, int textlength, int byteLength, int __attribute__((unused)) verbose)
Definition: dlt_common.c:3370
#define DLT_GET_MSIN_MTIN(msin)
Definition: dlt_protocol.h:109
#define DLT_BETOH_32(x)
Definition: dlt_common.h:155
int dlt_receiver_check_and_get(DltReceiver *receiver, void *dest, unsigned int to_get, unsigned int flags)
Definition: dlt_common.c:2277
DltReturnValue dlt_buffer_free_static(DltBuffer *buf)
Definition: dlt_common.c:2479
#define _DLT_PACKAGE_VERSION_STATE
Definition: dlt_version.h:22
DltReturnValue dlt_file_read_raw(DltFile *file, int resync, int verbose)
Definition: dlt_common.c:1782
DltReturnValue dlt_file_read_header_raw(DltFile *file, int resync, int verbose)
Definition: dlt_common.c:1397
static char * return_type[]
Definition: dlt_common.c:90
#define DLT_HEADER_SHOW_VNVSTATUS
Definition: dlt_common.h:320
#define DLT_ENDIAN_GET_64(htyp, x)
Definition: dlt_common.h:166
int counter
Definition: dlt_common.h:635
DltReturnValue dlt_filter_delete(DltFilter *filter, const char *apid, const char *ctid, int verbose)
Definition: dlt_common.c:617
void dlt_log_free(void)
Definition: dlt_common.c:2022
char * message_type[]
Definition: dlt_common.c:80
#define DLT_HEADER_SHOW_ECUID
Definition: dlt_common.h:315
#define DLT_MESSAGE_ERROR_OK
Definition: dlt_common.h:710
#define DLT_STANDARD_HEADER_EXTRA_SIZE(htyp)
Definition: dlt_common.h:213
DltReturnValue dlt_buffer_free_dynamic(DltBuffer *buf)
Definition: dlt_common.c:2494
DltReturnValue dlt_print_mixed_string(char *text, int textlength, uint8_t *ptr, int size, int html)
Definition: dlt_common.c:153
void dlt_clean_string(char *text, int length)
Definition: dlt_common.c:372
DltReturnValue dlt_file_read_header_extended(DltFile *file, int verbose)
Definition: dlt_common.c:1499
DltReturnValue dlt_receiver_remove(DltReceiver *receiver, int size)
Definition: dlt_common.c:2232
unsigned char status
Definition: dlt_common.h:706
DltReturnValue dlt_message_filter_check(DltMessage *msg, DltFilter *filter, int verbose)
Definition: dlt_common.c:1057
char * buf
Definition: dlt_common.h:678
#define _DLT_PACKAGE_VERSION
Definition: dlt_version.h:23
#define _DLT_PACKAGE_MAJOR_VERSION
Definition: dlt_version.h:24
#define DLT_MSG_READ_VALUE(dst, src, length, type)
Definition: dlt_common.h:278
DltReturnValue dlt_log(int prio, char *s)
Definition: dlt_common.c:2029
DltReturnValue dlt_file_read(DltFile *file, int verbose)
Definition: dlt_common.c:1647
#define DLT_GET_MSIN_MSTP(msin)
Definition: dlt_protocol.h:108
DltReturnValue dlt_buffer_init_static_server(DltBuffer *buf, const unsigned char *ptr, uint32_t size)
Definition: dlt_common.c:2376
int dlt_receiver_receive_fd(DltReceiver *receiver)
Definition: dlt_common.c:2203
DltReturnValue dlt_print_hex_string(char *text, int textlength, uint8_t *ptr, int size)
Definition: dlt_common.c:120
#define DLT_TYPE_APP_TRACE
Definition: dlt_protocol.h:115
DltReturnValue dlt_filter_init(DltFilter *filter, int verbose)
Definition: dlt_common.c:390
DltFilter * filter
Definition: dlt_common.h:659
#define DLT_RCV_REMOVE
Definition: dlt_common.h:327
DltReturnValue dlt_message_init(DltMessage *msg, int verbose)
Definition: dlt_common.c:666
unsigned char * mem
Definition: dlt_common.h:687
int32_t bytesRcvd
Definition: dlt_common.h:675
#define DLT_HEADER_SHOW_TMSTP
Definition: dlt_common.h:313
double float64_t
Definition: dlt_types.h:179
DltReturnValue dlt_receiver_move_to_begin(DltReceiver *receiver)
Definition: dlt_common.c:2257
int32_t filter_counter
Definition: dlt_common.h:660
DltExtendedHeader * extendedheader
Definition: dlt_common.h:435
static int logging_mode
Definition: dlt_common.c:75
#define DLT_OUTPUT_ASCII_LIMITED
Definition: dlt_common.h:274
DltReturnValue dlt_message_print_ascii(DltMessage *message, char *text, uint32_t size, int verbose)
Definition: dlt_common.c:3325
#define DLT_IS_MSIN_VERB(msin)
Definition: dlt_protocol.h:107
#define DLT_ENDIAN_GET_16(htyp, x)
Definition: dlt_common.h:164
#define DLT_HEADER_SHOW_CTID
Definition: dlt_common.h:317
DltReturnValue dlt_print_char_string(char **text, int textlength, uint8_t *ptr, int size)
Definition: dlt_common.c:260
DltReturnValue dlt_buffer_init_static_client(DltBuffer *buf, const unsigned char *ptr, uint32_t size)
Definition: dlt_common.c:2407
#define DLT_TYLE_16BIT
Definition: dlt_protocol.h:163
int dlt_buffer_copy(DltBuffer *buf, unsigned char *data, int max_size)
Definition: dlt_common.c:2889
#define DLT_OUTPUT_MIXED_FOR_HTML
Definition: dlt_common.h:273
static char * service_id[]
Definition: dlt_common.c:85
int dlt_buffer_get_used_size(DltBuffer *buf)
Definition: dlt_common.c:2952
void dlt_buffer_write_block(DltBuffer *buf, int *write, const unsigned char *data, unsigned int size)
Definition: dlt_common.c:2513
DltReturnValue dlt_message_set_extraparameters(DltMessage *msg, int verbose)
Definition: dlt_common.c:1273
#define DLT_HEADER_SHOW_MSGCNT
Definition: dlt_common.h:314
static char data[kDataSize]
Definition: city-test.cc:40
#define DLT_MESSAGE_ERROR_CONTENT
Definition: dlt_common.h:713
char * nw_trace_type[]
Definition: dlt_common.c:83
DltReturnValue dlt_set_storageheader(DltStorageHeader *storageheader, const char *ecu)
Definition: dlt_common.c:2315
int32_t databuffersize
Definition: dlt_common.h:429
char * buffer
Definition: dlt_common.h:677
static int logging_level
Definition: dlt_common.c:76
DltReturnValue dlt_receiver_init(DltReceiver *receiver, int fd, int buffersize)
Definition: dlt_common.c:2126
#define _DLT_SYSTEMD_ENABLE
Definition: dlt_version.h:32
#define _DLT_TEST_ENABLE
Definition: dlt_version.h:44
#define DLT_SIZE_WEID
Definition: dlt_common.h:206
#define DLT_TYLE_128BIT
Definition: dlt_protocol.h:166
#define DLT_IS_HTYP_UEH(htyp)
Definition: dlt_protocol.h:89
#define DLT_MSG_IS_NONVERBOSE(MSG)
Definition: dlt_common.h:257
DltReturnValue dlt_filter_free(DltFilter *filter, int verbose)
Definition: dlt_common.c:404
int32_t position
Definition: dlt_common.h:651
int dlt_filter_find(DltFilter *filter, const char *apid, const char *ctid, int verbose)
Definition: dlt_common.c:544
#define DLT_COMMON_HEX_LINELEN
unsigned char * shm
Definition: dlt_common.h:685
#define DLT_TYPE_NW_TRACE
Definition: dlt_protocol.h:116
#define DLT_HTOBE_32(x)
Definition: dlt_common.h:153
int dlt_mkdir_recursive(const char *dir)
Definition: dlt_common.c:3905
unsigned char buffer[BUFFER_SIZE]
Buffer for dlt file transfer. The size is defined by BUFFER_SIZE.
#define DLT_BETOH_16(x)
Definition: dlt_common.h:150
uint32_t dlt_uptime(void)
Definition: dlt_common.c:3274
int dlt_buffer_minimize_size(DltBuffer *buf)
Definition: dlt_common.c:2618
FILE * handle
Definition: dlt_common.h:645
int32_t counter_total
Definition: dlt_common.h:650
#define _DLT_SYSTEMD_WATCHDOG_ENABLE
Definition: dlt_version.h:38
uint32_t max_size
Definition: dlt_common.h:690
void dlt_log_set_filename(const char *filename)
Definition: dlt_common.c:1981
DltReturnValue dlt_filter_load(DltFilter *filter, const char *filename, int verbose)
Definition: dlt_common.c:416
char * trace_type[]
Definition: dlt_common.c:82
int32_t headersize
Definition: dlt_common.h:422
void dlt_buffer_status(DltBuffer *buf)
Definition: dlt_common.c:2916
const char dltSerialHeader[DLT_ID_SIZE]
Definition: dlt_common.c:70
#define DLT_HEADER_SHOW_MSGSUBTYPE
Definition: dlt_common.h:319
void dlt_buffer_read_block(DltBuffer *buf, int *read, unsigned char *data, unsigned int size)
Definition: dlt_common.c:2535
#define DLT_TYPE_INFO_FLOA
Definition: dlt_protocol.h:152
#define DLT_COMMON_CHARLEN
uint8_t headerbuffer[sizeof(DltStorageHeader)+sizeof(DltStandardHeader)+sizeof(DltStandardHeaderExtra)+sizeof(DltExtendedHeader)]
Definition: dlt_common.h:427
long * index
Definition: dlt_common.h:646
#define DLT_HEADER_SHOW_MSGTYPE
Definition: dlt_common.h:318
#define _DLT_PACKAGE_MINOR_VERSION
Definition: dlt_version.h:25
#define DLT_IS_HTYP_WEID(htyp)
Definition: dlt_protocol.h:91
int dlt_buffer_remove(DltBuffer *buf)
Definition: dlt_common.c:2894
int32_t error_messages
Definition: dlt_common.h:656
#define DLT_TYPE_INFO_STRG
Definition: dlt_protocol.h:154
int dlt_buffer_get_message_count(DltBuffer *buf)
Definition: dlt_common.c:2977
DltStandardHeaderExtra headerextra
Definition: dlt_common.h:434
char apid[DLT_FILTER_MAX][DLT_ID_SIZE]
Definition: dlt_common.h:633
DltMessage msg
Definition: dlt_common.h:663
DltReturnValue dlt_filter_add(DltFilter *filter, const char *apid, const char *ctid, int verbose)
Definition: dlt_common.c:583
DltReturnValue dlt_file_init(DltFile *file, int verbose)
Definition: dlt_common.c:1305
#define DLT_HEADER_SHOW_NONE
Definition: dlt_common.h:311
#define DLT_MSG_IS_CONTROL_RESPONSE(MSG)
Definition: dlt_common.h:242
#define DLT_TYPE_LOG
Definition: dlt_protocol.h:114
#define DLT_IS_HTYP_WSID(htyp)
Definition: dlt_protocol.h:92
#define DLT_COMMON_ASCII_CHAR_TILDE
DltReturnValue dlt_message_payload(DltMessage *msg, char *text, int textlength, int type, int verbose)
Definition: dlt_common.c:891
char ctid[DLT_FILTER_MAX][DLT_ID_SIZE]
Definition: dlt_common.h:634
DltReturnValue dlt_message_print_mixed_html(DltMessage *message, char *text, uint32_t size, int verbose)
Definition: dlt_common.c:3355
#define DLT_SCOD_BIN
Definition: dlt_protocol.h:171
#define _DLT_PACKAGE_REVISION
Definition: dlt_version.h:27
void dlt_print_id(char *text, const char *id)
Definition: dlt_common.c:301
#define DLT_MSG_IS_CONTROL(MSG)
Definition: dlt_common.h:235
#define DLT_MSG_IS_CONTROL_TIME(MSG)
Definition: dlt_common.h:246
#define DLT_SCOD_ASCII
Definition: dlt_protocol.h:168
#define DLT_TYPE_CONTROL
Definition: dlt_protocol.h:117
DltReturnValue dlt_check_storageheader(DltStorageHeader *storageheader)
Definition: dlt_common.c:2353
int32_t resync_offset
Definition: dlt_common.h:419
char dltFifoBaseDir[PATH_MAX+1]
Definition: dlt_common.c:72
#define DLT_SIZE_WSID
Definition: dlt_common.h:207
DltReturnValue dlt_file_free(DltFile *file, int verbose)
Definition: dlt_common.c:1942
DltReturnValue dlt_setup_serial(int fd, speed_t speed)
Definition: dlt_common.c:2992
static FILE * logging_handle
Definition: dlt_common.c:78
DltReturnValue dlt_vnlog(int prio, size_t size, const char *format,...)
Definition: dlt_common.c:2099
DltStandardHeader * standardheader
Definition: dlt_common.h:433
DltReturnValue dlt_message_free(DltMessage *msg, int verbose)
Definition: dlt_common.c:691
#define DLT_HEADER_SHOW_NOARG
Definition: dlt_common.h:321
speed_t dlt_convert_serial_speed(int baudrate)
Definition: dlt_common.c:3067
char dltSerialHeaderChar[DLT_ID_SIZE]
Definition: dlt_common.c:71
int dlt_buffer_increase_size(DltBuffer *buf)
Definition: dlt_common.c:2557
#define DLT_TYPE_INFO_BOOL
Definition: dlt_protocol.h:149
void dlt_print_hex(uint8_t *ptr, int size)
Definition: dlt_common.c:100
int32_t counter
Definition: dlt_common.h:649
#define DLT_OUTPUT_MIXED_FOR_PLAIN
Definition: dlt_common.h:272
#define DLT_COMMON_BUFFER_LENGTH
#define DLT_TYPE_INFO_FIXP
Definition: dlt_protocol.h:157
int32_t lastBytesRcvd
Definition: dlt_common.h:674
#define DLT_HEADER_SHOW_APID
Definition: dlt_common.h:316
#define DLT_TYPE_INFO_RAWD
Definition: dlt_protocol.h:155
int dlt_buffer_push3(DltBuffer *buf, const unsigned char *data1, unsigned int size1, const unsigned char *data2, unsigned int size2, const unsigned char *data3, unsigned int size3)
Definition: dlt_common.c:2691
void dlt_get_version(char *buf, size_t size)
Definition: dlt_common.c:3239
#define _DLT_SHM_ENABLE
Definition: dlt_version.h:50
void dlt_log_set_level(int level)
Definition: dlt_common.c:1968
int dlt_buffer_get(DltBuffer *buf, unsigned char *data, int max_size, int delete)
Definition: dlt_common.c:2768
long file_length
Definition: dlt_common.h:652
DltReturnValue dlt_message_header(DltMessage *msg, char *text, int textlength, int verbose)
Definition: dlt_common.c:710
#define DLT_SIZE_WTMS
Definition: dlt_common.h:208
#define DLT_TYPE_INFO_VARI
Definition: dlt_protocol.h:156
#define DLT_TYPE_INFO_UINT
Definition: dlt_protocol.h:151
int dlt_buffer_pull(DltBuffer *buf, unsigned char *data, int max_size)
Definition: dlt_common.c:2884
#define DLT_MESSAGE_ERROR_SIZE
Definition: dlt_common.h:712
#define DLT_TYPE_INFO_TRAI
Definition: dlt_protocol.h:158
char * log_info[]
Definition: dlt_common.c:81
DltReturnValue dlt_message_print_hex(DltMessage *message, char *text, uint32_t size, int verbose)
Definition: dlt_common.c:3310
#define DLT_OUTPUT_ASCII
Definition: dlt_common.h:271
#define DLT_SCOD_HEX
Definition: dlt_protocol.h:170
uint8_t * databuffer
Definition: dlt_common.h:428
#define DLT_TYPE_INFO_TYLE
Definition: dlt_protocol.h:148
#define DLT_FILTER_MAX
Definition: dlt_common.h:276
long file_position
Definition: dlt_common.h:653
#define DLT_IS_HTYP_WTMS(htyp)
Definition: dlt_protocol.h:93
DltReturnValue dlt_message_get_extraparameters(DltMessage *msg, int verbose)
Definition: dlt_common.c:1241
DltReturnValue dlt_file_close(DltFile *file, int verbose)
Definition: dlt_common.c:1876
#define DLT_OUTPUT_HEX
Definition: dlt_common.h:270
#define DLT_SERVICE_ID_LAST_ENTRY
Definition: dlt_protocol.h:196
DltReturnValue dlt_vlog(int prio, const char *format,...)
Definition: dlt_common.c:2078
DltReturnValue dlt_message_header_flags(DltMessage *msg, char *text, int textlength, int flags, int verbose)
Definition: dlt_common.c:715
#define DLT_BUFFER_HEAD
Definition: dlt_common.h:701
void dlt_get_major_version(char *buf, size_t size)
Definition: dlt_common.c:3251
#define DLT_COMMON_HEX_CHARS
#define DLT_TYLE_8BIT
Definition: dlt_protocol.h:162
#define DLT_HEADER_SHOW_ALL
Definition: dlt_common.h:322
#define DLT_COMMON_ASCII_CHAR_SPACE
int32_t totalBytesRcvd
Definition: dlt_common.h:676
void dlt_log_set_fifo_basedir(const char *env_pipe_dir)
Definition: dlt_common.c:1994
uint32_t min_size
Definition: dlt_common.h:689
#define DLT_COMMON_INDEX_ALLOC
#define DLT_TYLE_64BIT
Definition: dlt_protocol.h:165
float float32_t
Definition: dlt_types.h:178
uint32_t step_size
Definition: dlt_common.h:691
DltReturnValue dlt_message_print_mixed_plain(DltMessage *message, char *text, uint32_t size, int verbose)
Definition: dlt_common.c:3340
void dlt_log_init(int mode)
Definition: dlt_common.c:2000
#define NULL
Definition: dlt_common.h:232
#define DLT_TYPE_INFO_SCOD
Definition: dlt_protocol.h:160
#define DLT_MSG_READ_STRING(dst, src, maxlength, length)
Definition: dlt_common.h:294
DltReturnValue dlt_receiver_free(DltReceiver *receiver)
Definition: dlt_common.c:2153