automotive-dlt
dlt-control.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 
28 /*******************************************************************************
29 ** **
30 ** SRC-MODULE: dlt-control.cpp **
31 ** **
32 ** TARGET : linux **
33 ** **
34 ** PROJECT : DLT **
35 ** **
36 ** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de **
37 ** **
38 ** PURPOSE : **
39 ** **
40 ** REMARKS : **
41 ** **
42 ** PLATFORM DEPENDANT [yes/no]: yes **
43 ** **
44 ** TO BE CHANGED BY USER [yes/no]: no **
45 ** **
46 *******************************************************************************/
47 
48 /*******************************************************************************
49 ** Author Identity **
50 ********************************************************************************
51 ** **
52 ** Initials Name Company **
53 ** -------- ------------------------- ---------------------------------- **
54 ** aw Alexander Wenzel BMW **
55 *******************************************************************************/
56 
57 #include <ctype.h> /* for isprint() */
58 #include <stdlib.h> /* for atoi() */
59 #include <sys/stat.h> /* for S_IRUSR, S_IWUSR, S_IRGRP, S_IROTH */
60 #include <fcntl.h> /* for open() */
61 #include <sys/uio.h> /* for writev() */
62 #include <string.h> /* for open() */
63 
64 #include "dlt_client.h"
65 #include "dlt_user.h"
66 #include "dlt-control-common.h"
67 
68 #define DLT_RECEIVE_TEXTBUFSIZE 10024 /* Size of buffer for text output */
69 
70 
71 #define DLT_GLOGINFO_APID_NUM_MAX 150
72 #define DLT_GLOGINFO_DATA_MAX 800
73 #define DLT_GET_LOG_INFO_HEADER 18 /*Get log info header size in response text */
74 #define DLT_INVALID_LOG_LEVEL 0xF
75 /* Option of GET_LOG_INFO */
76 #define DLT_SERVICE_GET_LOG_INFO_OPT7 7 /* get Apid, ApDescription, Ctid, CtDescription, loglevel, tracestatus */
77 
78 typedef struct
79 {
80  char apid[DLT_ID_SIZE + 1];
81  char ctid[DLT_ID_SIZE + 1];
82  char *apid_desc;
83  char *ctid_desc;
84  int log_level;
86  int disp;
88 
89 typedef struct
90 {
92  int count;
93 } DltLoginfo;
94 
95 
96 typedef struct
97 {
98  uint32_t service_id;
99 } PACKED DltServiceGetDefaultLogLevel;
100 
103 
104 /* Function prototypes */
105 int dlt_receive_message_callback(DltMessage *message, void *data);
106 
107 typedef struct {
108  int vflag;
109  int yflag;
110  char *evalue;
111 
112  char *avalue;
113  char *cvalue;
114  int svalue;
115  char *mvalue;
116  char *xvalue;
117  int tvalue;
118  int lvalue;
119  int rvalue;
120  int dvalue;
121  int fvalue;
122  int ivalue;
123  int oflag;
124  int gflag;
125  int jvalue;
126  int bvalue;
127  char ecuid[4];
131 
132 
133 void hexAsciiToBinary (const char *ptr,uint8_t *binary,int *size)
134 {
135 
136  char ch = *ptr;
137  int pos = 0;
138  binary[pos] = 0;
139  int first = 1;
140  int found;
141 
142  for(;;)
143  {
144 
145  if(ch == 0)
146  {
147  *size = pos;
148  return;
149  }
150 
151 
152  found = 0;
153  if (ch >= '0' && ch <= '9')
154  {
155  binary[pos] = (binary[pos] << 4) + (ch - '0');
156  found = 1;
157  }
158  else if (ch >= 'A' && ch <= 'F')
159  {
160  binary[pos] = (binary[pos] << 4) + (ch - 'A' + 10);
161  found = 1;
162  }
163  else if (ch >= 'a' && ch <= 'f')
164  {
165  binary[pos] = (binary[pos] << 4) + (ch - 'a' + 10);
166  found = 1;
167  }
168  if(found)
169  {
170  if(first)
171  first = 0;
172  else
173  {
174  first = 1;
175  pos++;
176  if(pos>=*size)
177  return;
178  binary[pos]=0;
179  }
180  }
181 
182  ch = *(++ptr);
183  }
184 
185 }
186 
190 void usage()
191 {
192  char version[255];
193 
194  dlt_get_version(version,255);
195 
196  printf("Usage: dlt-control [options] hostname/serial_device_name\n");
197  printf("Send control message to DLT daemon.\n");
198  printf("%s \n", version);
199  printf("Options:\n");
200  printf(" -v Verbose mode\n");
201  printf(" -h Usage\n");
202  printf(" -y Serial device mode\n");
203  printf(" -b baudrate Serial device baudrate (Default: 115200)\n");
204  printf(" -e ecuid Set ECU ID (Default: RECV)\n");
205  printf("\n");
206  printf(" -a id Control message application id\n");
207  printf(" -c id Control message context id\n");
208  printf(" -s id Control message injection service id\n");
209  printf(" -m message Control message injection in ASCII\n");
210  printf(" -x message Control message injection in Hex e.g. 'ad 01 24 ef'\n");
211  printf(" -t milliseconds Timeout to terminate application (Default:1000)'\n");
212  printf(" -l loglevel Set the log level (0=off - 6=verbose default= -1)\n");
213  printf(" supported options:\n");
214  printf(" -l level -a appid -c ctid\n");
215  printf(" -l level -a abc* (set level for all ctxts of apps name starts with abc)\n");
216  printf(" -l level -a appid (set level for all ctxts of this app)\n");
217  printf(" -l level -c xyz* (set level for all ctxts whose name starts with xyz)\n");
218  printf(" -l level -c ctxid (set level for the particular ctxt)\n");
219  printf(" -l level (set level for all the registered contexts)\n");
220  printf(" -r tracestatus Set the trace status (0=off - 1=on,255=default)\n");
221  printf(" -d loglevel Set the default log level (0=off - 5=verbose)\n");
222  printf(" -f tracestatus Set the default trace status (0=off - 1=on)\n");
223  printf(" -i enable Enable timing packets (0=off - 1=on)\n");
224  printf(" -o Store configuration\n");
225  printf(" -g Reset to factory default\n");
226  printf(" -j Get log info\n");
227  printf(" -u unix port\n");
228 }
233 {
234  char apid[DLT_ID_SIZE+1] = {0};
235  int cnt;
236 
238 
239  /* send control message*/
240  if (0 != dlt_client_get_log_info(&g_dltclient))
241  {
242  fprintf(stderr, "ERROR: Could not get log info\n");
243  return;
244  }
245 
246  for (cnt = 0; cnt < g_get_loginfo.count; cnt++)
247  {
248  if (strncmp(apid, g_get_loginfo.info[cnt].apid, DLT_ID_SIZE) != 0)
249  {
250  printf("APID:%4s ", g_get_loginfo.info[cnt].apid);
251  apid[DLT_ID_SIZE] = 0;
252  dlt_set_id(apid, g_get_loginfo.info[cnt].apid);
253 
254  if (g_get_loginfo.info[cnt].apid_desc != 0)
255  {
256  printf("%s\n", g_get_loginfo.info[cnt].apid_desc);
257  }
258  else
259  {
260  printf("\n");
261  }
262  }
263 
264  if (strncmp(apid, g_get_loginfo.info[cnt].apid, DLT_ID_SIZE) == 0)
265  {
266  printf("%4s %2d %2d %s\n", g_get_loginfo.info[cnt].ctid, g_get_loginfo.info[cnt].log_level,
267  g_get_loginfo.info[cnt].trace_status, g_get_loginfo.info[cnt].ctid_desc);
268  }
269  }
271 }
272 
276 int main(int argc, char* argv[])
277 {
278  DltReceiveData dltdata;
279  int c;
280  int index;
281  char *endptr = NULL;
282 
283  /* Initialize dltdata */
284  dltdata.vflag = 0;
285  dltdata.yflag = 0;
286  dltdata.evalue = 0;
287  dltdata.bvalue = 0;
288 
289  dltdata.avalue = 0;
290  dltdata.cvalue = 0;
291  dltdata.svalue = 0;
292  dltdata.mvalue = 0;
293  dltdata.xvalue = 0;
294  dltdata.tvalue = 1000;
295  dltdata.lvalue = DLT_INVALID_LOG_LEVEL;
296  dltdata.rvalue = -1;
297  dltdata.dvalue = -1;
298  dltdata.fvalue = -1;
299  dltdata.ivalue = -1;
300  dltdata.oflag = -1;
301  dltdata.gflag = -1;
302  dltdata.jvalue = 0;
303  /* Fetch command line arguments */
304  opterr = 0;
305 
306  while ((c = getopt (argc, argv, "vhye:b:a:c:s:m:x:t:l:r:d:f:i:ogju")) != -1)
307  switch (c)
308  {
309  case 'v':
310  {
311  dltdata.vflag = 1;
312  break;
313  }
314  case 'h':
315  {
316  usage();
317  return -1;
318  }
319  case 'y':
320  {
321  dltdata.yflag = DLT_CLIENT_MODE_SERIAL;
322  break;
323  }
324  case 'e':
325  {
326  dltdata.evalue = optarg;
327  break;
328  }
329  case 'b':
330  {
331  dltdata.bvalue = atoi(optarg);
332  break;
333  }
334 
335  case 'a':
336  {
337  dltdata.avalue = optarg;
338  if (strlen(dltdata.avalue) > DLT_ID_SIZE)
339  {
340  fprintf (stderr, "Invalid appid\n");
341  return -1;
342  }
343  break;
344  }
345  case 'c':
346  {
347  dltdata.cvalue = optarg;
348  if (strlen(dltdata.cvalue) > DLT_ID_SIZE)
349  {
350  fprintf (stderr, "Invalid context id\n");
351  return -1;
352  }
353  break;
354  }
355  case 's':
356  {
357  dltdata.svalue = atoi(optarg);
358  break;
359  }
360  case 'm':
361  {
362  dltdata.mvalue = optarg;
363  break;
364  }
365  case 'x':
366  {
367  dltdata.xvalue = optarg;
368  break;
369  }
370  case 't':
371  {
372  dltdata.tvalue = atoi(optarg);;
373  break;
374  }
375  case 'l':
376  {
377  dltdata.lvalue = strtol(optarg, &endptr, 10);
378  if ((dltdata.lvalue < DLT_LOG_DEFAULT) || (dltdata.lvalue > DLT_LOG_VERBOSE))
379  {
380  fprintf (stderr, "invalid log level, supported log level 0-6\n");
381  return -1;
382  }
383  break;
384  }
385  case 'r':
386  {
387  dltdata.rvalue = atoi(optarg);;
388  break;
389  }
390  case 'd':
391  {
392  dltdata.dvalue = atoi(optarg);;
393  break;
394  }
395  case 'f':
396  {
397  dltdata.fvalue = atoi(optarg);;
398  break;
399  }
400  case 'i':
401  {
402  dltdata.ivalue = atoi(optarg);;
403  break;
404  }
405  case 'o':
406  {
407  dltdata.oflag = 1;
408  break;
409  }
410  case 'g':
411  {
412  dltdata.gflag = 1;
413  break;
414  }
415  case 'j':
416  {
417  dltdata.jvalue = 1;
418  break;
419  }
420  case 'u':
421  {
422  dltdata.yflag = DLT_CLIENT_MODE_UNIX;
423  break;
424  }
425  case '?':
426  {
427  if (optopt == 'o' || optopt == 'f')
428  {
429  fprintf (stderr, "Option -%c requires an argument.\n", optopt);
430  }
431  else if (isprint (optopt))
432  {
433  fprintf (stderr, "Unknown option `-%c'.\n", optopt);
434  }
435  else
436  {
437  fprintf (stderr, "Unknown option character `\\x%x'.\n",optopt);
438  }
439  /* unknown or wrong option used, show usage information and terminate */
440  usage();
441  return -1;
442  }
443  default:
444  {
445  abort ();
446  return -1;//for parasoft
447  }
448  }
449 
450  /* Initialize DLT Client */
451  dlt_client_init(&g_dltclient, dltdata.vflag);
452 
453  /* Register callback to be called when message was received */
455 
456  /* Setup DLT Client structure */
457  if (dltdata.yflag == DLT_CLIENT_MODE_SERIAL)
458  {
459  g_dltclient.mode = DLT_CLIENT_MODE_SERIAL;
460  }
461  else if (dltdata.yflag == DLT_CLIENT_MODE_UNIX)
462  {
463  g_dltclient.mode = DLT_CLIENT_MODE_UNIX;
464  g_dltclient.socketPath = NULL;
465  dlt_parse_config_param("ControlSocketPath", &g_dltclient.socketPath);
466  }
467  else
468  {
469  g_dltclient.mode = DLT_CLIENT_MODE_TCP;
470  }
471 
472  if (g_dltclient.mode==DLT_CLIENT_MODE_TCP)
473  {
474  for (index = optind; index < argc; index++)
475  {
476  if(dlt_client_set_server_ip(&g_dltclient, argv[index]) == -1)
477  {
478  pr_error("set server ip didn't succeed\n");
479  return -1;
480  }
481  }
482  if (g_dltclient.servIP == 0)
483  {
484  /* no hostname selected, show usage and terminate */
485  fprintf(stderr,"ERROR: No hostname selected\n");
486  usage();
487  dlt_client_cleanup(&g_dltclient,dltdata.vflag);
488  return -1;
489  }
490  }
491  else if (g_dltclient.mode == DLT_CLIENT_MODE_SERIAL)
492  {
493  for (index = optind; index < argc; index++)
494  {
495  if(dlt_client_set_serial_device(&g_dltclient, argv[index]) == -1)
496  {
497  pr_error("set serial device didn't succeed\n");
498  return -1;
499  }
500  }
501  if (g_dltclient.serialDevice == 0)
502  {
503  /* no serial device name selected, show usage and terminate */
504  fprintf(stderr,"ERROR: No serial device name specified\n");
505  usage();
506  return -1;
507  }
508 
509  dlt_client_setbaudrate(&g_dltclient,dltdata.bvalue);
510  }
511 
512  /* initialise structure to use DLT file */
513  dlt_file_init(&(dltdata.file),dltdata.vflag);
514 
515  /* first parse filter file if filter parameter is used */
516  dlt_filter_init(&(dltdata.filter),dltdata.vflag);
517 
518  if (dltdata.evalue)
519  {
520  dlt_set_id(dltdata.ecuid,dltdata.evalue);
521  dlt_set_id(g_dltclient.ecuid,dltdata.evalue);
522  }
523  else
524  {
525  dltdata.evalue = NULL;
526  if (dlt_parse_config_param("ECUId", &dltdata.evalue) == 0)
527  {
528  dlt_set_id(dltdata.ecuid,dltdata.evalue);
529  dlt_set_id(g_dltclient.ecuid,dltdata.evalue);
530  free (dltdata.evalue);
531  }
532  else
533  {
534  fprintf(stderr, "ERROR: Failed to read ECUId from dlt.conf \n");
535  }
536  }
537 
538  /* Connect to TCP socket or open serial device */
539  if (dlt_client_connect(&g_dltclient, dltdata.vflag) != DLT_RETURN_ERROR)
540  {
541  /* send injection message */
542  if(dltdata.mvalue && dltdata.avalue && dltdata.cvalue)
543  {
544  /* ASCII */
545  printf("Send injection message:\n");
546  printf("AppId: %s\n",dltdata.avalue);
547  printf("ConId: %s\n",dltdata.cvalue);
548  printf("ServiceId: %d\n",dltdata.svalue);
549  printf("Message: %s\n",dltdata.mvalue);
550  /* send control message in ascii */
551  if (dlt_client_send_inject_msg(&g_dltclient,
552  dltdata.avalue,
553  dltdata.cvalue,
554  dltdata.svalue,
555  (uint8_t*)dltdata.mvalue,
556  strlen(dltdata.mvalue)) != DLT_RETURN_OK)
557  {
558  fprintf(stderr, "ERROR: Could not send inject message\n");
559  }
560  }
561  else if(dltdata.xvalue && dltdata.avalue && dltdata.cvalue)
562  {
563  /* Hex */
564  uint8_t buffer[1024];
565  int size = 1024;
566  printf("Send injection message:\n");
567  printf("AppId: %s\n",dltdata.avalue);
568  printf("ConId: %s\n",dltdata.cvalue);
569  printf("ServiceId: %d\n",dltdata.svalue);
570  printf("Message: %s\n",dltdata.xvalue);
571  hexAsciiToBinary(dltdata.xvalue,buffer,&size);
572  printf("Size: %d\n",size);
573  /* send control message in hex */
574  if (dlt_client_send_inject_msg(&g_dltclient,
575  dltdata.avalue,
576  dltdata.cvalue,
577  dltdata.svalue,
578  buffer,size) != DLT_RETURN_OK)
579  {
580  fprintf(stderr, "ERROR: Could not send inject message\n");
581  }
582  }
583  else if (dltdata.lvalue != DLT_INVALID_LOG_LEVEL) /*&& dltdata.avalue && dltdata.cvalue)*/
584  {
585  if ((dltdata.avalue == 0) && (dltdata.cvalue == 0))
586  {
587  if (dltdata.vflag)
588  {
589  printf("Set all log level:\n");
590  printf("Loglevel: %d\n", dltdata.lvalue);
591  }
592  if (0 != dlt_client_send_all_log_level(&g_dltclient,
593  dltdata.lvalue))
594  {
595  fprintf(stderr, "ERROR: Could not send log level\n");
596  }
597  }
598  else
599  {
600  /* log level */
601  if (dltdata.vflag)
602  {
603  printf("Set log level:\n");
604  printf("AppId: %s\n", dltdata.avalue);
605  printf("ConId: %s\n", dltdata.cvalue);
606  printf("Loglevel: %d\n", dltdata.lvalue);
607  }
608  /* send control message*/
609  if (0 != dlt_client_send_log_level(&g_dltclient,
610  dltdata.avalue,
611  dltdata.cvalue,
612  dltdata.lvalue))
613  {
614  fprintf(stderr, "ERROR: Could not send log level\n");
615  }
616  }
617  }
618  else if(dltdata.rvalue!=-1 && dltdata.avalue && dltdata.cvalue)
619  {
620  /* trace status */
621  printf("Set trace status:\n");
622  printf("AppId: %s\n",dltdata.avalue);
623  printf("ConId: %s\n",dltdata.cvalue);
624  printf("TraceStatus: %d\n",dltdata.rvalue);
625  /* send control message in*/
626  if (dlt_client_send_trace_status(&g_dltclient,
627  dltdata.avalue,
628  dltdata.cvalue,
629  dltdata.rvalue) != DLT_RETURN_OK)
630  {
631  fprintf(stderr, "ERROR: Could not send trace status\n");
632  }
633  }
634  else if(dltdata.dvalue!=-1)
635  {
636  /* default log level */
637  printf("Set default log level:\n");
638  printf("Loglevel: %d\n",dltdata.dvalue);
639  /* send control message in*/
640  if (dlt_client_send_default_log_level(&g_dltclient, dltdata.dvalue) != DLT_RETURN_OK)
641  {
642  fprintf (stderr, "ERROR: Could not send default log level\n");
643  }
644  }
645  else if(dltdata.rvalue!=-1)
646  {
647  /* default trace status */
648  printf("Set default trace status:\n");
649  printf("TraceStatus: %d\n",dltdata.rvalue);
650  /* send control message in*/
651  if (dlt_client_send_default_trace_status(&g_dltclient, dltdata.rvalue) != DLT_RETURN_OK)
652  {
653  fprintf (stderr, "ERROR: Could not send default trace status\n");
654  }
655  }
656  else if(dltdata.ivalue!=-1)
657  {
658  /* timing pakets */
659  printf("Set timing pakets:\n");
660  printf("Timing packets: %d\n",dltdata.ivalue);
661  /* send control message in*/
662  if (dlt_client_send_timing_pakets(&g_dltclient, dltdata.ivalue) != DLT_RETURN_OK)
663  {
664  fprintf (stderr, "ERROR: Could not send timing packets\n");
665  }
666  }
667  else if(dltdata.oflag!=-1)
668  {
669  /* default trace status */
670  printf("Store config\n");
671  /* send control message in*/
672  if (dlt_client_send_store_config(&g_dltclient) != DLT_RETURN_OK)
673  {
674  fprintf (stderr, "ERROR: Could not send store config\n");
675  }
676  }
677  else if(dltdata.gflag!=-1)
678  {
679  /* reset to factory default */
680  printf("Reset to factory default\n");
681  /* send control message in*/
683  {
684  fprintf (stderr, "ERROR: Could send reset to factory default\n");
685  }
686  }
687  else if (dltdata.jvalue == 1)
688  {
689  /* get log info */
690  printf("Get log info:\n");
692  }
693  /* Dlt Client Main Loop */
694  //dlt_client_main_loop(&dltclient, &dltdata, dltdata.vflag);
695 
696  /* Wait timeout */
697  usleep(dltdata.tvalue*1000);
698 
699  /* Dlt Client Cleanup */
700  dlt_client_cleanup(&g_dltclient,dltdata.vflag);
701  }
702 
703  if (g_dltclient.socketPath != NULL)
704  free(g_dltclient.socketPath);
705 
706  dlt_file_free(&(dltdata.file),dltdata.vflag);
707 
708  dlt_filter_free(&(dltdata.filter),dltdata.vflag);
709 
710  return 0;
711 }
712 
713 void dlt_getloginfo_conv_ascii_to_id(char *rp, int *rp_count, char *wp, int len)
714 {
715  char number16[6]={0};
716  char *endptr;
717  int count;
718 
719  if ((rp == NULL) || (rp_count == NULL) || (wp == NULL))
720  {
721  return;
722  }
723  /* ------------------------------------------------------
724  from: [72 65 6d 6f ] -> to: [0x72,0x65,0x6d,0x6f,0x00]
725  ------------------------------------------------------ */
726  number16[0] = '+';
727  number16[1] = '0';
728  number16[2] = 'x';
729  for (count = 0; count < (len - 1); count++)
730  {
731  number16[3] = *(rp + *rp_count + 0);
732  number16[4] = *(rp + *rp_count + 1);
733  *(wp + count) = strtol(number16, &endptr, 16);
734  *rp_count += 3;
735  }
736  *(wp + count) = 0;
737  return;
738 }
739 
740 uint16_t dlt_getloginfo_conv_ascii_to_uint16_t(char *rp, int *rp_count)
741 {
742  char num_work[8];
743  char *endptr;
744 
745  if ((rp == NULL) || (rp_count == NULL))
746  {
747  return -1;
748  }
749  /* ------------------------------------------------------
750  from: [89 13 ] -> to: ['+0x'1389\0] -> to num
751  ------------------------------------------------------ */
752  num_work[0] = '+';
753  num_work[1] = '0';
754  num_work[2] = 'x';
755  num_work[3] = *(rp + *rp_count + 3);
756  num_work[4] = *(rp + *rp_count + 4);
757  num_work[5] = *(rp + *rp_count + 0);
758  num_work[6] = *(rp + *rp_count + 1);
759  num_work[7] = 0;
760  *rp_count += 6;
761 
762  return strtol(num_work, &endptr, 16);
763 }
764 int16_t dlt_getloginfo_conv_ascii_to_int16_t(char *rp, int *rp_count)
765 {
766  char num_work[6];
767  char *endptr;
768 
769  if ((rp == NULL) || (rp_count == NULL))
770  {
771  return -1;
772  }
773  /* ------------------------------------------------------
774  from: [89 ] -> to: ['0x'89\0] -> to num
775  ------------------------------------------------------ */
776  num_work[0] = '0';
777  num_work[1] = 'x';
778  num_work[2] = *(rp + *rp_count + 0);
779  num_work[3] = *(rp + *rp_count + 1);
780  num_work[4] = 0;
781  *rp_count += 3;
782 
783  return (signed char)strtol(num_work, &endptr, 16);
784 }
785 
787 {
788  int cnt;
789 
790  g_get_loginfo.count = 0;
791  for (cnt = 0; cnt < DLT_GLOGINFO_DATA_MAX; cnt++)
792  {
793  g_get_loginfo.info[cnt].apid_desc = NULL;
794  g_get_loginfo.info[cnt].ctid_desc = NULL;
795  }
796 }
797 
799 {
800  int cnt;
801 
802  for (cnt = 0; cnt < DLT_GLOGINFO_DATA_MAX; cnt++)
803  {
804  if (g_get_loginfo.info[cnt].apid_desc != 0)
805  {
806  free(g_get_loginfo.info[cnt].apid_desc);
807  }
808  if (g_get_loginfo.info[cnt].ctid_desc != 0)
809  {
810  free(g_get_loginfo.info[cnt].ctid_desc);
811  }
812  }
813 }
814 
818 int dlt_set_loginfo_parse_service_id(char *resp_text, int *service_id, int *service_opt, char *cb_result)
819 {
820  int ret;
821  char get_log_info_tag[13];
822  char service_opt_str[3];
823 
824  if ((resp_text == NULL) || (service_id == NULL) || (service_opt == NULL) || (cb_result == NULL))
825  {
826  return -1;
827  }
828  /* ascii type, syntax is 'get_log_info, ..' */
829  /* check target id */
830  strncpy(get_log_info_tag, "get_log_info", strlen("get_log_info"));
831  ret = memcmp((void *)resp_text, (void *)get_log_info_tag, sizeof(get_log_info_tag)-1);
832  if (ret == 0)
833  {
834  *service_id = DLT_SERVICE_ID_GET_LOG_INFO;
835  *cb_result = 0;
836  /* reading the response mode from the resp_text. eg. option 7*/
837  service_opt_str[0] = *(resp_text+14);
838  service_opt_str[1] = *(resp_text+15);
839  service_opt_str[2] = 0;
840  *service_opt = atoi( service_opt_str );
841  }
842 
843  return ret;
844 }
845 
850 int dlt_getloginfo_make_loginfo(char *resp_text, int service_opt)
851 {
852  char *rp;
853  int rp_count;
854  int loginfo_count;
855  uint16_t reg_apid_count;
856  uint16_t reg_ctid_count;
857  uint16_t reg_apid_num;
858  uint16_t reg_ctid_num;
859  uint16_t reg_apid_dsc_len;
860  uint16_t reg_ctid_dsc_len;
861  char reg_apid[DLT_ID_SIZE+1];
862  char reg_ctid[DLT_ID_SIZE+1];
863  char *reg_apid_dsc;
864  char *reg_ctid_dsc;
865 
866  if (resp_text == NULL)
867  {
868  return -1;
869  }
870  /* ------------------------------------------------------
871  get_log_info data structure(all data is ascii)
872 
873  get_log_info, aa, bb bb cc cc cc cc dd dd ee ee ee ee ff gg hh hh ii ii ii .. ..
874  ~~ ~~~~~ ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~
875  cc cc cc cc dd dd ee ee ee ee ff gg hh hh ii ii ii .. ..
876  jj jj kk kk kk .. ..
877  ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~
878  aa : get mode (fix value at 0x07)
879  bb bb : list num of apid (little endian)
880  cc cc cc cc: apid
881  dd dd : list num of ctid (little endian)
882  ee ee ee ee: ctid
883  ff : log level
884  gg : trase status
885  hh hh : description length of ctid
886  ii ii .. : description text of ctid
887  jj jj : description length of apid
888  kk kk .. : description text of apid
889  ------------------------------------------------------ */
890 
891  /* create all target convert list */
892 
893  /* rp set header */
894  rp = (resp_text + DLT_GET_LOG_INFO_HEADER);
895  rp_count = 0;
896  /* get reg_apid_num */
897  reg_apid_num = dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count);
898  loginfo_count = g_get_loginfo.count;
899 
900  if (reg_apid_num > DLT_GLOGINFO_APID_NUM_MAX)
901  {
902  fprintf(stderr, "GET_LOG_INFO ERROR: APID MAX Over\n");
903  g_get_loginfo.count = 0;
904  return -1;
905  }
906 
907  /* search for target apid */
908  for (reg_apid_count = 0; reg_apid_count < reg_apid_num; reg_apid_count++)
909  {
910  /* get reg_apid */
911  dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, reg_apid, DLT_ID_SIZE+1);
912 
913  /* get reg_ctid_num of current reg_apid */
914  reg_ctid_num = dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count);
915  if (loginfo_count + reg_ctid_num > DLT_GLOGINFO_DATA_MAX)
916  {
917  fprintf(stderr, "GET_LOG_INFO ERROR: LOG DATA MAX Over\n");
918  g_get_loginfo.count = 0;
919  return -1;
920  }
921  for (reg_ctid_count = 0; reg_ctid_count < reg_ctid_num; reg_ctid_count++)
922  {
923  /* get reg_ctid */
924  dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, reg_ctid, DLT_ID_SIZE+1);
925 
926  g_get_loginfo.info[ loginfo_count ].apid[DLT_ID_SIZE] = 0;
927  dlt_set_id(g_get_loginfo.info[ loginfo_count ].apid, reg_apid);
928  g_get_loginfo.info[ loginfo_count ].ctid[DLT_ID_SIZE] = 0;
929  dlt_set_id(g_get_loginfo.info[ loginfo_count ].ctid, reg_ctid);
930  g_get_loginfo.info[ loginfo_count ].log_level = dlt_getloginfo_conv_ascii_to_int16_t(rp, &rp_count);
931  g_get_loginfo.info[ loginfo_count ].trace_status = dlt_getloginfo_conv_ascii_to_int16_t(rp, &rp_count);
932 
933  /* Description Information */
934  if (service_opt == DLT_SERVICE_GET_LOG_INFO_OPT7)
935  {
936  reg_ctid_dsc_len = dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count);
937  reg_ctid_dsc = (char *)malloc(sizeof(char) * reg_ctid_dsc_len + 1);
938  if (reg_ctid_dsc == 0)
939  {
940  fprintf(stderr, "malloc failed for ctxt desc\n");
941  return -1;
942  }
943  dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, reg_ctid_dsc, reg_ctid_dsc_len+1);
944  g_get_loginfo.info[ loginfo_count ].ctid_desc = reg_ctid_dsc;
945  }
946  loginfo_count++;
947  }
948  /* Description Information */
949  if (service_opt == DLT_SERVICE_GET_LOG_INFO_OPT7)
950  {
951  reg_apid_dsc_len = dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count);
952  reg_apid_dsc = (char *)malloc(sizeof(char) * reg_apid_dsc_len + 1);
953  if (reg_apid_dsc == 0)
954  {
955  fprintf(stderr, "malloc failed for apid desc\n");
956  return -1;
957  }
958  dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, reg_apid_dsc, reg_apid_dsc_len+1);
959  g_get_loginfo.info[ loginfo_count - reg_ctid_num ].apid_desc = reg_apid_dsc;
960  }
961  }
962  g_get_loginfo.count = loginfo_count;
963 
964  return 0;
965 }
966 
968 {
969  static char resp_text[DLT_RECEIVE_TEXTBUFSIZE];
970  int ret;
971  int service_id;
972  int service_opt;
973  char cb_result;
974 
975  /* parameter check */
976  if (message == NULL)
977  {
978  return -1;
979  }
980  /* to avoid warning */
981  data = data;
982 
983  /* prepare storage header */
984  if (DLT_IS_HTYP_WEID(message->standardheader->htyp))
985  {
986  dlt_set_storageheader(message->storageheader, message->headerextra.ecu);
987  }
988  else
989  {
990  dlt_set_storageheader(message->storageheader, "LCTL");
991  }
992 
993  /* get response data */
994  ret = dlt_message_header(message, resp_text, DLT_RECEIVE_TEXTBUFSIZE, 0);
995  if (ret < 0)
996  {
997  fprintf(stderr, "GET_LOG_INFO message_header result failed..\n");
998  dlt_client_cleanup(&g_dltclient, 0);
999  return -1;
1000  }
1001 
1002  ret = dlt_message_payload(message, resp_text, DLT_RECEIVE_TEXTBUFSIZE, DLT_OUTPUT_ASCII, 0);
1003  if (ret < 0)
1004  {
1005  fprintf(stderr, "GET_LOG_INFO message_payload result failed..\n");
1006  dlt_client_cleanup(&g_dltclient, 0);
1007  return -1;
1008  }
1009 
1010  /* check service id */
1011  ret = dlt_set_loginfo_parse_service_id(resp_text, &service_id, &service_opt, &cb_result);
1012  if ((ret == 0) && (service_id == DLT_SERVICE_ID_GET_LOG_INFO ))
1013  {
1014  ret = dlt_getloginfo_make_loginfo(resp_text, service_opt);
1015 
1016  if (ret != 0)
1017  {
1018  fprintf(stderr, "GET_LOG_INFO result failed..\n");
1019  }
1020  dlt_client_cleanup(&g_dltclient, 0);
1021  }
1022 
1023  return ret;
1024 }
void hexAsciiToBinary(const char *ptr, uint8_t *binary, int *size)
Definition: dlt-control.c:133
int dlt_receive_message_callback(DltMessage *message, void *data)
Definition: dlt-control.c:967
DltReturnValue dlt_client_send_timing_pakets(DltClient *client, uint8_t timingPakets)
Definition: dlt_client.c:768
#define DLT_ID_SIZE
Definition: dlt_common.h:204
DltReturnValue dlt_client_send_all_log_level(DltClient *client, uint8_t LogLevel)
Definition: dlt_client.c:708
DltStorageHeader * storageheader
Definition: dlt_common.h:432
char ecuid[4]
Definition: dlt_client.h:97
void dlt_set_id(char *id, const char *text)
Definition: dlt_common.c:324
void dlt_client_register_message_callback(int(*registerd_callback)(DltMessage *message, void *data))
Definition: dlt_client.c:105
int dlt_parse_config_param(char *config_id, char **config_data)
int dlt_client_set_server_ip(DltClient *client, char *ipaddr)
Definition: dlt_client.c:839
#define DLT_GET_LOG_INFO_HEADER
Definition: dlt-control.c:73
void usage()
Definition: dlt-control.c:190
uint32_t service_id
Definition: dlt-control.c:98
int main(int argc, char *argv[])
Definition: dlt-control.c:276
#define DLT_SERVICE_ID_GET_LOG_INFO
Definition: dlt_protocol.h:178
#define DLT_GLOGINFO_APID_NUM_MAX
Definition: dlt-control.c:71
int dlt_client_get_log_info(DltClient *client)
Definition: dlt_client.c:603
DltReturnValue dlt_client_setbaudrate(DltClient *client, int baudrate)
Definition: dlt_client.c:827
DltReturnValue dlt_filter_init(DltFilter *filter, int verbose)
Definition: dlt_common.c:390
int dlt_set_loginfo_parse_service_id(char *resp_text, int *service_id, int *service_opt, char *cb_result)
Definition: dlt-control.c:818
char ctid[DLT_ID_SIZE+1]
Definition: dlt-control.c:81
int dlt_client_set_serial_device(DltClient *client, char *serial_device)
Definition: dlt_client.c:850
int dlt_getloginfo_make_loginfo(char *resp_text, int service_opt)
Definition: dlt-control.c:850
#define DLT_RECEIVE_TEXTBUFSIZE
Definition: dlt-control.c:68
DltClient g_dltclient
Definition: dlt-control.c:101
static char * service_id[]
Definition: dlt_common.c:85
static char data[kDataSize]
Definition: city-test.cc:40
DltReturnValue dlt_set_storageheader(DltStorageHeader *storageheader, const char *ecu)
Definition: dlt_common.c:2315
DltReturnValue dlt_client_send_reset_to_factory_default(DltClient *client)
Definition: dlt_client.c:812
DltReturnValue dlt_client_init(DltClient *client, int verbose)
Definition: dlt_client.c:133
DltReturnValue dlt_filter_free(DltFilter *filter, int verbose)
Definition: dlt_common.c:404
DltReturnValue dlt_client_cleanup(DltClient *client, int verbose)
Definition: dlt_client.c:301
unsigned char buffer[BUFFER_SIZE]
Buffer for dlt file transfer. The size is defined by BUFFER_SIZE.
DltReturnValue dlt_client_connect(DltClient *client, int verbose)
Definition: dlt_client.c:168
void dlt_getloginfo_free(void)
Definition: dlt-control.c:798
#define pr_error(fmt,...)
#define DLT_IS_HTYP_WEID(htyp)
Definition: dlt_protocol.h:91
DltStandardHeaderExtra headerextra
Definition: dlt_common.h:434
DltReturnValue dlt_file_init(DltFile *file, int verbose)
Definition: dlt_common.c:1305
DltReturnValue dlt_message_payload(DltMessage *msg, char *text, int textlength, int type, int verbose)
Definition: dlt_common.c:891
void dlt_getloginfo_conv_ascii_to_id(char *rp, int *rp_count, char *wp, int len)
Definition: dlt-control.c:713
#define DLT_INVALID_LOG_LEVEL
Definition: dlt-control.c:74
DltReturnValue dlt_client_send_inject_msg(DltClient *client, char *apid, char *ctid, uint32_t serviceID, uint8_t *buffer, uint32_t size)
Definition: dlt_client.c:539
DltLoginfo g_get_loginfo
Definition: dlt-control.c:102
DltReturnValue dlt_file_free(DltFile *file, int verbose)
Definition: dlt_common.c:1942
DltFilter filter
Definition: dlt-control.c:129
uint16_t dlt_getloginfo_conv_ascii_to_uint16_t(char *rp, int *rp_count)
Definition: dlt-control.c:740
DltStandardHeader * standardheader
Definition: dlt_common.h:433
DltReturnValue dlt_client_send_log_level(DltClient *client, char *apid, char *ctid, uint8_t logLevel)
Definition: dlt_client.c:571
void dlt_get_version(char *buf, size_t size)
Definition: dlt_common.c:3239
DltReturnValue dlt_message_header(DltMessage *msg, char *text, int textlength, int verbose)
Definition: dlt_common.c:710
DltReturnValue dlt_client_send_default_log_level(DltClient *client, uint8_t defaultLogLevel)
Definition: dlt_client.c:678
char * servIP
Definition: dlt_client.h:93
#define DLT_OUTPUT_ASCII
Definition: dlt_common.h:271
DltLoginfoDetail info[DLT_GLOGINFO_DATA_MAX]
Definition: dlt-control.c:91
char * socketPath
Definition: dlt_client.h:96
DltReturnValue dlt_client_send_trace_status(DltClient *client, char *apid, char *ctid, uint8_t traceStatus)
Definition: dlt_client.c:646
char * serialDevice
Definition: dlt_client.h:95
char apid[DLT_ID_SIZE+1]
Definition: dlt-control.c:80
void dlt_getloginfo_init(void)
Definition: dlt-control.c:786
DltReturnValue dlt_client_send_default_trace_status(DltClient *client, uint8_t defaultTraceStatus)
Definition: dlt_client.c:738
DltClientMode mode
Definition: dlt_client.h:99
#define DLT_SERVICE_GET_LOG_INFO_OPT7
Definition: dlt-control.c:76
void dlt_process_get_log_info(void)
Definition: dlt-control.c:232
#define DLT_GLOGINFO_DATA_MAX
Definition: dlt-control.c:72
#define NULL
Definition: dlt_common.h:232
int16_t dlt_getloginfo_conv_ascii_to_int16_t(char *rp, int *rp_count)
Definition: dlt-control.c:764
DltReturnValue dlt_client_send_store_config(DltClient *client)
Definition: dlt_client.c:797