automotive-dlt
dlt_client.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 
27 /*******************************************************************************
28 ** **
29 ** SRC-MODULE: dlt_client.c **
30 ** **
31 ** TARGET : linux **
32 ** **
33 ** PROJECT : DLT **
34 ** **
35 ** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de **
36 ** Markus Klein **
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 ** mk Markus Klein Fraunhofer ESK **
56 *******************************************************************************/
57 
58 /*******************************************************************************
59 ** Revision Control History **
60 *******************************************************************************/
61 
62 /*
63  * $LastChangedRevision$
64  * $LastChangedDate$
65  * $LastChangedBy$
66  Initials Date Comment
67  aw 12.07.2010 initial
68  */
69 
70 #include <stdio.h>
71 
72 #if defined (__WIN32__) || defined (_MSC_VER)
73 #pragma warning(disable : 4996) /* Switch off C4996 warnings */
74 #include <winsock2.h> /* for socket(), connect(), send(), and recv() */
75 #else
76 #include <sys/socket.h> /* for socket(), connect(), send(), and recv() */
77 #include <arpa/inet.h> /* for sockaddr_in and inet_addr() */
78 #include <netdb.h>
79 #include <sys/stat.h>
80 #include <sys/un.h>
81 #endif
82 
83 #if defined(_MSC_VER)
84 #include <io.h>
85 #else
86 #include <unistd.h>
87 #include <syslog.h>
88 #endif
89 
90 #include <fcntl.h>
91 
92 #include <stdlib.h> /* for malloc(), free() */
93 #include <string.h> /* for strlen(), memcmp(), memmove() */
94 #include <errno.h>
95 #include <limits.h>
96 
97 #include "dlt_types.h"
98 #include "dlt_client.h"
99 #include "dlt_client_cfg.h"
100 
101 static int (*message_callback_function) (DltMessage *message, void *data) = NULL;
102 
104 
105 void dlt_client_register_message_callback(int (*registerd_callback) (DltMessage *message, void *data)){
106  message_callback_function = registerd_callback;
107 }
108 
110 {
111  if (verbose && port != DLT_DAEMON_TCP_PORT)
112  {
113  dlt_vlog(LOG_INFO, "Init dlt client struct with port %d\n", port);
114  }
115 
116  if (client == NULL)
117  {
118  return DLT_RETURN_ERROR;
119  }
120 
121  client->sock=-1;
122  client->servIP=0;
123  client->serialDevice=0;
125  client->port = port;
126  client->socketPath = 0;
127  client->mode=DLT_CLIENT_MODE_TCP;
128  client->receiver.buffer=0;
129 
130  return DLT_RETURN_OK;
131 }
132 
134 {
135  char *env_daemon_port;
136  int tmp_port;
137  /* the port may be specified by an environment variable, defaults to DLT_DAEMON_TCP_PORT */
138  unsigned short servPort = DLT_DAEMON_TCP_PORT;
139 
140  /* the port may be specified by an environment variable */
141  env_daemon_port = getenv(DLT_CLIENT_ENV_DAEMON_TCP_PORT);
142  if (env_daemon_port != NULL)
143  {
144  tmp_port = atoi(env_daemon_port);
145  if ((tmp_port < IPPORT_RESERVED) || (tmp_port > USHRT_MAX))
146  {
147  dlt_vlog(LOG_ERR,
148  "Specified port is out of possible range: %d.\n",
149  tmp_port);
150  return DLT_RETURN_ERROR;
151  }
152  else
153  {
154  servPort = tmp_port;
155  }
156  }
157 
158  if (verbose)
159  {
160  dlt_vlog(LOG_INFO,
161  "Init dlt client struct with default port: %hu.\n",
162  servPort);
163  }
164 
165  return dlt_client_init_port(client, servPort, verbose);
166 }
167 
169 {
170  char portnumbuffer[33];
171  struct addrinfo hints, *servinfo, *p;
172  struct sockaddr_un addr;
173  int rv;
174  memset(&hints, 0, sizeof(hints));
175  hints.ai_socktype = SOCK_STREAM;
176 
177  if (client==0)
178  {
179  return DLT_RETURN_ERROR;
180  }
181 
182  switch (client->mode)
183  {
184  case DLT_CLIENT_MODE_TCP:
185  snprintf(portnumbuffer, 32, "%d", client->port);
186  if ((rv = getaddrinfo(client->servIP, portnumbuffer, &hints, &servinfo)) != 0) {
187  fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
188  return DLT_RETURN_ERROR;
189  }
190 
191  for(p = servinfo; p != NULL; p = p->ai_next) {
192  if ((client->sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) < 0) {
193  snprintf(str, DLT_CLIENT_TEXTBUFSIZE,
194  "socket() failed! %s\n",
195  strerror(errno));
196  dlt_log(LOG_WARNING, str);
197  continue;
198  }
199  if (connect(client->sock, p->ai_addr, p->ai_addrlen) < 0) {
200  snprintf(str, DLT_CLIENT_TEXTBUFSIZE,
201  "connect() failed! %s\n",
202  strerror(errno));
203  close(client->sock);
204  dlt_log(LOG_WARNING, str);
205  continue;
206  }
207 
208  break;
209  }
210 
211  freeaddrinfo(servinfo);
212 
213  if (p == NULL) {
214  dlt_log(LOG_ERR, "ERROR: failed to connect.\n");
215  return DLT_RETURN_ERROR;
216  }
217 
218  if (verbose)
219  {
220  printf("Connected to DLT daemon (%s)\n",client->servIP);
221  }
222  break;
224  /* open serial connection */
225  client->sock=open(client->serialDevice,O_RDWR);
226  if (client->sock<0)
227  {
228  fprintf(stderr,"ERROR: Failed to open device %s\n", client->serialDevice);
229  return DLT_RETURN_ERROR;
230  }
231 
232  if (isatty(client->sock))
233  {
234  #if !defined (__WIN32__)
235  if (dlt_setup_serial(client->sock,client->baudrate) < DLT_RETURN_OK)
236  {
237  fprintf(stderr,"ERROR: Failed to configure serial device %s (%s) \n", client->serialDevice, strerror(errno));
238  return DLT_RETURN_ERROR;
239  }
240  #else
241  return DLT_RETURN_ERROR;
242  #endif
243  }
244  else
245  {
246  if (verbose)
247  {
248  fprintf(stderr,"ERROR: Device is not a serial device, device = %s (%s) \n", client->serialDevice, strerror(errno));
249  }
250  return DLT_RETURN_ERROR;
251  }
252 
253  if (verbose)
254  {
255  printf("Connected to %s\n", client->serialDevice);
256  }
257  break;
259  if ((client->sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
260  {
261  fprintf(stderr, "ERROR: (unix) socket error: %s\n", strerror(errno));
262  return DLT_RETURN_ERROR;
263  }
264 
265  memset(&addr, 0, sizeof(addr));
266  addr.sun_family = AF_UNIX;
267  memcpy(addr.sun_path, client->socketPath, sizeof(addr.sun_path)-1);
268 
269  if (connect(client->sock,
270  (struct sockaddr_un *)&addr,
271  sizeof(addr)) == -1)
272  {
273  fprintf(stderr, "ERROR: (unix) connect error: %s\n", strerror(errno));
274  return DLT_RETURN_ERROR;
275  }
276 
277  if (client->sock < 0)
278  {
279  fprintf(stderr,"ERROR: Failed to open device %s\n",
280  client->socketPath);
281  return DLT_RETURN_ERROR;
282  }
283  break;
284  default:
285  if (verbose)
286  {
287  fprintf(stderr, "ERROR: Mode not supported: %d\n", client->mode);
288  }
289  return DLT_RETURN_ERROR;
290  }
291 
293  {
294  fprintf(stderr, "ERROR initializing receiver\n");
295  return DLT_RETURN_ERROR;
296  }
297 
298  return DLT_RETURN_OK;
299 }
300 
302 {
303  if (verbose)
304  {
305  printf("Cleanup dlt client\n");
306  }
307 
308  if (client==0)
309  {
310  return DLT_RETURN_ERROR;
311  }
312 
313  if (client->sock!=-1)
314  {
315  close(client->sock);
316  }
317 
318  if (dlt_receiver_free(&(client->receiver)) == DLT_RETURN_ERROR)
319  {
320  return DLT_RETURN_ERROR;
321  }
322 
323  return DLT_RETURN_OK;
324 }
325 
327 {
328  DltMessage msg;
329  int ret;
330 
331  if (client==0)
332  {
333  return DLT_RETURN_ERROR;
334  }
335 
336  if (dlt_message_init(&msg,verbose) == DLT_RETURN_ERROR)
337  {
338  return DLT_RETURN_ERROR;
339  }
340 
341  while (1)
342  {
343  if (client->mode==0)
344  {
345  /* wait for data from socket */
346  ret = dlt_receiver_receive_socket(&(client->receiver));
347  }
348  else
349  {
350  /* wait for data from serial connection */
351  ret = dlt_receiver_receive_fd(&(client->receiver));
352  }
353 
354  if (ret<=0)
355  {
356  /* No more data to be received */
357  if (dlt_message_free(&msg,verbose) == DLT_RETURN_ERROR)
358  {
359  return DLT_RETURN_ERROR;
360  }
361 
362  return DLT_RETURN_TRUE;
363  }
364 
365  while (dlt_message_read(&msg,(unsigned char*)(client->receiver.buf),client->receiver.bytesRcvd,0,verbose) == DLT_MESSAGE_ERROR_OK)
366  {
367  /* Call callback function */
369  {
370  (*message_callback_function)(&msg,data);
371  }
372 
373  if (msg.found_serialheader)
374  {
375  if (dlt_receiver_remove(&(client->receiver),msg.headersize+msg.datasize-sizeof(DltStorageHeader)+sizeof(dltSerialHeader)) == DLT_RETURN_ERROR)
376  {
377  /* Return value ignored */
378  dlt_message_free(&msg,verbose);
379  return DLT_RETURN_ERROR;
380  }
381  }
382  else
383  {
384  if (dlt_receiver_remove(&(client->receiver),msg.headersize+msg.datasize-sizeof(DltStorageHeader)) == DLT_RETURN_ERROR)
385  {
386  /* Return value ignored */
387  dlt_message_free(&msg,verbose);
388  return DLT_RETURN_ERROR;
389  }
390  }
391  }
392 
394  {
395  /* Return value ignored */
396  dlt_message_free(&msg,verbose);
397  return DLT_RETURN_ERROR;
398  }
399  }
400 
401  if (dlt_message_free(&msg,verbose) == DLT_RETURN_ERROR)
402  {
403  return DLT_RETURN_ERROR;
404  }
405 
406  return DLT_RETURN_OK;
407 }
408 
409 DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *ctid, uint8_t *payload, uint32_t size)
410 {
411  DltMessage msg;
412  int ret;
413 
414  int32_t len;
415 
416  if ((client==0) || (client->sock<0) || (apid==0) || (ctid==0))
417  {
418  return DLT_RETURN_ERROR;
419  }
420 
421  /* initialise new message */
422  if (dlt_message_init(&msg,0) == DLT_RETURN_ERROR)
423  {
424  return DLT_RETURN_ERROR;
425  }
426 
427  /* prepare payload of data */
428  msg.datasize = size;
429  if (msg.databuffer && (msg.databuffersize < msg.datasize))
430  {
431  free(msg.databuffer);
432  msg.databuffer=0;
433  }
434  if (msg.databuffer == 0){
435  msg.databuffer = (uint8_t *) malloc(msg.datasize);
436  msg.databuffersize = msg.datasize;
437  }
438  if(msg.databuffer == 0)
439  {
440  dlt_message_free(&msg,0);
441  return DLT_RETURN_ERROR;
442  }
443 
444  /* copy data */
445  memcpy(msg.databuffer,payload,size);
446 
447  /* prepare storage header */
448  msg.storageheader = (DltStorageHeader*)msg.headerbuffer;
449 
451  {
452  dlt_message_free(&msg,0);
453  return DLT_RETURN_ERROR;
454  }
455 
456  /* prepare standard header */
457  msg.standardheader = (DltStandardHeader*)(msg.headerbuffer + sizeof(DltStorageHeader));
459 
460  #if (BYTE_ORDER==BIG_ENDIAN)
461  msg.standardheader->htyp = (msg.standardheader->htyp | DLT_HTYP_MSBF);
462  #endif
463 
464  msg.standardheader->mcnt = 0;
465 
466  /* Set header extra parameters */
467  dlt_set_id(msg.headerextra.ecu,client->ecuid);
468  //msg.headerextra.seid = 0;
469  msg.headerextra.tmsp = dlt_uptime();
470 
471  /* Copy header extra parameters to headerbuffer */
473  {
474  dlt_message_free(&msg,0);
475  return DLT_RETURN_ERROR;
476  }
477 
478  /* prepare extended header */
479  msg.extendedheader = (DltExtendedHeader*)(msg.headerbuffer +
480  sizeof(DltStorageHeader) +
481  sizeof(DltStandardHeader) +
483 
485 
486  msg.extendedheader->noar = 1; /* number of arguments */
487 
488  dlt_set_id(msg.extendedheader->apid,(apid[0]=='\0')?DLT_CLIENT_DUMMY_APP_ID:apid);
489  dlt_set_id(msg.extendedheader->ctid,(ctid[0]=='\0')?DLT_CLIENT_DUMMY_CON_ID:ctid);
490 
491  /* prepare length information */
492  msg.headersize = sizeof(DltStorageHeader) +
493  sizeof(DltStandardHeader) +
494  sizeof(DltExtendedHeader) +
496 
497  len=msg.headersize - sizeof(DltStorageHeader) + msg.datasize;
498  if (len>UINT16_MAX)
499  {
500  fprintf(stderr,"Critical: Huge injection message discarded!\n");
501  dlt_message_free(&msg,0);
502 
503  return DLT_RETURN_ERROR;
504  }
505 
506  msg.standardheader->len = DLT_HTOBE_16(len);
507 
508  /* Send data (without storage header) */
509  if ((client->mode == DLT_CLIENT_MODE_TCP) || (client->mode == DLT_CLIENT_MODE_SERIAL))
510  {
511  /* via FileDescriptor */
512  ret=write(client->sock, msg.headerbuffer+sizeof(DltStorageHeader),msg.headersize-sizeof(DltStorageHeader));
513  if (0 > ret){
514  dlt_message_free(&msg,0);
515  return DLT_RETURN_ERROR;
516  }
517  ret=write(client->sock, msg.databuffer,msg.datasize);
518  if (0 > ret){
519  dlt_message_free(&msg,0);
520  return DLT_RETURN_ERROR;
521  }
522  }
523  else
524  {
525  /* via Socket */
526  send(client->sock, (const char *)(msg.headerbuffer+sizeof(DltStorageHeader)),msg.headersize-sizeof(DltStorageHeader),0);
527  send(client->sock, (const char *)msg.databuffer,msg.datasize,0);
528  }
529 
530  /* free message */
531  if (dlt_message_free(&msg,0) == DLT_RETURN_ERROR)
532  {
533  return DLT_RETURN_ERROR;
534  }
535 
536  return DLT_RETURN_OK;
537 }
538 
539 DltReturnValue dlt_client_send_inject_msg(DltClient *client, char *apid, char *ctid, uint32_t serviceID, uint8_t *buffer, uint32_t size)
540 {
541  uint8_t *payload;
542  int offset;
543 
544  payload = (uint8_t *) malloc(sizeof(uint32_t) + sizeof(uint32_t) + size);
545 
546  if(payload==0)
547  {
548  return DLT_RETURN_ERROR;
549  }
550 
551  offset = 0;
552  memcpy(payload , &serviceID,sizeof(serviceID));
553  offset+=sizeof(uint32_t);
554  memcpy(payload+offset, &size, sizeof(size));
555  offset+=sizeof(uint32_t);
556  memcpy(payload+offset, buffer, size);
557 
558  /* free message */
559  if (dlt_client_send_ctrl_msg(client,apid,ctid,payload,sizeof(uint32_t) + sizeof(uint32_t) + size) == DLT_RETURN_ERROR)
560  {
561  free(payload);
562  return DLT_RETURN_ERROR;
563  }
564 
565  free(payload);
566 
567  return DLT_RETURN_OK;
568 
569 }
570 
571 DltReturnValue dlt_client_send_log_level(DltClient *client, char *apid, char *ctid, uint8_t logLevel)
572 {
573  DltServiceSetLogLevel *req;
574  uint8_t *payload;
575 
576  payload = (uint8_t *) malloc(sizeof(DltServiceSetLogLevel));
577 
578  if(payload==0)
579  {
580  return DLT_RETURN_ERROR;
581  }
582 
583  req = (DltServiceSetLogLevel *) payload;
584 
585  req->service_id = DLT_SERVICE_ID_SET_LOG_LEVEL;
586  dlt_set_id(req->apid,apid);
587  dlt_set_id(req->ctid,ctid);
588  req->log_level=logLevel;
589  dlt_set_id(req->com,"remo");
590 
591  /* free message */
592  if (dlt_client_send_ctrl_msg(client,"APP","CON",payload,sizeof(DltServiceSetLogLevel)) == DLT_RETURN_ERROR)
593  {
594  free(payload);
595  return DLT_RETURN_ERROR;
596  }
597 
598  free(payload);
599 
600  return DLT_RETURN_OK;
601 }
602 
604 {
605  DltServiceGetLogInfoRequest *req;
606  uint8_t *payload;
607  int ret_main_loop = 0;
608  int ret = -1;
609 
610  if (client == NULL)
611  {
612  return ret;
613  }
614  payload = (uint8_t *) malloc(sizeof(DltServiceGetLogInfoRequest));
615 
616  if (payload == 0)
617  {
618  return ret;
619  }
620 
621  req = (DltServiceGetLogInfoRequest *) payload;
622 
623  req->service_id = DLT_SERVICE_ID_GET_LOG_INFO;
624  req->options = 7;
625  dlt_set_id(req->apid, "");
626  dlt_set_id(req->ctid, "");
627  dlt_set_id(req->com, "remo");
628 
629  /* send control message to daemon*/
630  ret = dlt_client_send_ctrl_msg(client, "", "", payload, sizeof(DltServiceGetLogInfoRequest));
631  free(payload);
632  if (ret == -1)
633  {
634  return -1;
635  }
636 
637  ret_main_loop = dlt_client_main_loop(client, NULL, 0);
638  if (ret_main_loop == 1)
639  {
640  printf("DLT-daemon's response is invalid.\n");
641  }
642 
643  return 0;
644 }
645 
646 DltReturnValue dlt_client_send_trace_status(DltClient *client, char *apid, char *ctid, uint8_t traceStatus)
647 {
648  DltServiceSetLogLevel *req;
649  uint8_t *payload;
650 
651  payload = (uint8_t *) malloc(sizeof(DltServiceSetLogLevel));
652 
653  if(payload==0)
654  {
655  return DLT_RETURN_ERROR;
656  }
657 
658  req = (DltServiceSetLogLevel *) payload;
659 
660  req->service_id = DLT_SERVICE_ID_SET_TRACE_STATUS;
661  dlt_set_id(req->apid,apid);
662  dlt_set_id(req->ctid,ctid);
663  req->log_level=traceStatus;
664  dlt_set_id(req->com,"remo");
665 
666  /* free message */
667  if (dlt_client_send_ctrl_msg(client,"APP","CON",payload,sizeof(DltServiceSetLogLevel)) == DLT_RETURN_ERROR)
668  {
669  free(payload);
670  return DLT_RETURN_ERROR;
671  }
672 
673  free(payload);
674 
675  return DLT_RETURN_OK;
676 }
677 
679 {
680  DltServiceSetDefaultLogLevel *req;
681  uint8_t *payload;
682 
683  payload = (uint8_t *) malloc(sizeof(DltServiceSetDefaultLogLevel));
684 
685  if(payload==0)
686  {
687  return DLT_RETURN_ERROR;
688  }
689 
690  req = (DltServiceSetDefaultLogLevel *) payload;
691 
692  req->service_id = DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL;
693  req->log_level=defaultLogLevel;
694  dlt_set_id(req->com,"remo");
695 
696  /* free message */
697  if (dlt_client_send_ctrl_msg(client,"APP","CON",payload,sizeof(DltServiceSetDefaultLogLevel)) == DLT_RETURN_ERROR)
698  {
699  free(payload);
700  return DLT_RETURN_ERROR;
701  }
702 
703  free(payload);
704 
705  return DLT_RETURN_OK;
706 }
707 
709 {
710  DltServiceSetDefaultLogLevel *req;
711  uint8_t *payload;
712 
713  payload = (uint8_t *) malloc(sizeof(DltServiceSetDefaultLogLevel));
714 
715  if (payload == 0)
716  {
717  return DLT_RETURN_ERROR;
718  }
719 
720  req = (DltServiceSetDefaultLogLevel *) payload;
721 
722  req->service_id = DLT_SERVICE_ID_SET_ALL_LOG_LEVEL;
723  req->log_level = LogLevel;
724  dlt_set_id(req->com, "remo");
725 
726  /* free message */
727  if (dlt_client_send_ctrl_msg(client, "APP", "CON", payload, sizeof(DltServiceSetDefaultLogLevel)) == -1)
728  {
729  free(payload);
730  return DLT_RETURN_ERROR;
731  }
732 
733  free(payload);
734 
735  return DLT_RETURN_OK;
736 }
737 
739 {
740  DltServiceSetDefaultLogLevel *req;
741  uint8_t *payload;
742 
743  payload = (uint8_t *) malloc(sizeof(DltServiceSetDefaultLogLevel));
744 
745  if(payload==0)
746  {
747  return DLT_RETURN_ERROR;
748  }
749 
750  req = (DltServiceSetDefaultLogLevel *) payload;
751 
752  req->service_id = DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS;
753  req->log_level=defaultTraceStatus;
754  dlt_set_id(req->com,"remo");
755 
756  /* free message */
757  if (dlt_client_send_ctrl_msg(client,"APP","CON",payload,sizeof(DltServiceSetDefaultLogLevel)) == DLT_RETURN_ERROR)
758  {
759  free(payload);
760  return DLT_RETURN_ERROR;
761  }
762 
763  free(payload);
764 
765  return DLT_RETURN_OK;
766 }
767 
769 {
770  DltServiceSetVerboseMode *req;
771  uint8_t *payload;
772 
773  payload = (uint8_t *) malloc(sizeof(DltServiceSetVerboseMode));
774 
775  if(payload==0)
776  {
777  return DLT_RETURN_ERROR;
778  }
779 
780  req = (DltServiceSetVerboseMode *) payload;
781 
782  req->service_id = DLT_SERVICE_ID_SET_TIMING_PACKETS;
783  req->new_status=timingPakets;
784 
785  /* free message */
786  if (dlt_client_send_ctrl_msg(client,"APP","CON",payload,sizeof(DltServiceSetVerboseMode)) == DLT_RETURN_ERROR)
787  {
788  free(payload);
789  return DLT_RETURN_ERROR;
790  }
791 
792  free(payload);
793 
794  return DLT_RETURN_OK;
795 }
796 
798 {
799  uint32_t service_id;
800 
801  service_id = DLT_SERVICE_ID_STORE_CONFIG;
802 
803  /* free message */
804  if (dlt_client_send_ctrl_msg(client,"APP","CON",(uint8_t*)&service_id,sizeof(uint32_t)) == DLT_RETURN_ERROR)
805  {
806  return DLT_RETURN_ERROR;
807  }
808 
809  return DLT_RETURN_OK;
810 }
811 
813 {
814  uint32_t service_id;
815 
817 
818  /* free message */
819  if (dlt_client_send_ctrl_msg(client,"APP","CON",(uint8_t*)&service_id,sizeof(uint32_t)) == DLT_RETURN_ERROR)
820  {
821  return DLT_RETURN_ERROR;
822  }
823 
824  return DLT_RETURN_OK;
825 }
826 
828 {
829  if (client==0)
830  {
831  return DLT_RETURN_ERROR;
832  }
833 
834  client->baudrate = dlt_convert_serial_speed(baudrate);
835 
836  return DLT_RETURN_OK;
837 }
838 
840 {
841  client->servIP = strdup(ipaddr);
842  if (client->servIP == NULL)
843  {
844  dlt_log(LOG_ERR, "ERROR: failed to duplicate server IP\n");
845  return DLT_RETURN_ERROR;
846  }
847  return DLT_RETURN_OK;
848 }
849 
851 {
852  client->serialDevice = strdup(serial_device);
853  if (client->serialDevice == NULL)
854  {
855  dlt_log(LOG_ERR, "ERROR: failed to duplicate serial device\n");
856  return DLT_RETURN_ERROR;
857  }
858  return DLT_RETURN_OK;
859 }
860 
862 {
863  client->socketPath = strdup(socket_path);
864  if (client->socketPath == NULL)
865  {
866  dlt_log(LOG_ERR, "ERROR: failed to duplicate socket path\n");
867  return DLT_RETURN_ERROR;
868  }
869  return DLT_RETURN_OK;
870 }
int32_t datasize
Definition: dlt_common.h:423
int dlt_message_read(DltMessage *msg, uint8_t *buffer, unsigned int length, int resync, int verbose)
Definition: dlt_common.c:1091
#define DLT_HTYP_UEH
Definition: dlt_protocol.h:82
DltReturnValue dlt_client_send_timing_pakets(DltClient *client, uint8_t timingPakets)
Definition: dlt_client.c:768
int dlt_receiver_receive_socket(DltReceiver *receiver)
Definition: dlt_common.c:2173
int sock
Definition: dlt_client.h:92
int8_t found_serialheader
Definition: dlt_common.h:416
DltReturnValue dlt_client_send_all_log_level(DltClient *client, uint8_t LogLevel)
Definition: dlt_client.c:708
#define DLT_HTOBE_16(x)
Definition: dlt_common.h:148
#define DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL
Definition: dlt_protocol.h:192
DltStorageHeader * storageheader
Definition: dlt_common.h:432
#define DLT_CLIENT_TEXTBUFSIZE
DltReturnValue
Definition: dlt_types.h:86
#define DLT_MSIN_CONTROL_REQUEST
Definition: dlt_protocol.h:141
char ecuid[4]
Definition: dlt_client.h:97
#define DLT_HTYP_PROTOCOL_VERSION1
Definition: dlt_protocol.h:95
void dlt_set_id(char *id, const char *text)
Definition: dlt_common.c:324
DltReturnValue dlt_client_send_ctrl_msg(DltClient *client, char *apid, char *ctid, uint8_t *payload, uint32_t size)
Definition: dlt_client.c:409
void dlt_client_register_message_callback(int(*registerd_callback)(DltMessage *message, void *data))
Definition: dlt_client.c:105
#define DLT_HTYP_WEID
Definition: dlt_protocol.h:84
DltReturnValue dlt_client_main_loop(DltClient *client, void *data, int verbose)
Definition: dlt_client.c:326
int dlt_client_set_server_ip(DltClient *client, char *ipaddr)
Definition: dlt_client.c:839
#define DLT_SERVICE_ID_SET_TRACE_STATUS
Definition: dlt_protocol.h:177
#define DLT_CLIENT_ENV_DAEMON_TCP_PORT
DltReturnValue dlt_client_init_port(DltClient *client, int port, int verbose)
Definition: dlt_client.c:109
#define DLT_MESSAGE_ERROR_OK
Definition: dlt_common.h:710
#define DLT_STANDARD_HEADER_EXTRA_SIZE(htyp)
Definition: dlt_common.h:213
static DltClient client
DltReturnValue dlt_receiver_remove(DltReceiver *receiver, int size)
Definition: dlt_common.c:2232
char * buf
Definition: dlt_common.h:678
#define DLT_SERVICE_ID_SET_LOG_LEVEL
Definition: dlt_protocol.h:176
#define DLT_SERVICE_ID_GET_LOG_INFO
Definition: dlt_protocol.h:178
DltReturnValue dlt_log(int prio, char *s)
Definition: dlt_common.c:2029
int dlt_client_get_log_info(DltClient *client)
Definition: dlt_client.c:603
int dlt_receiver_receive_fd(DltReceiver *receiver)
Definition: dlt_common.c:2203
DltReturnValue dlt_client_setbaudrate(DltClient *client, int baudrate)
Definition: dlt_client.c:827
#define DLT_SERVICE_ID_STORE_CONFIG
Definition: dlt_protocol.h:180
DltReturnValue dlt_message_init(DltMessage *msg, int verbose)
Definition: dlt_common.c:666
#define DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS
Definition: dlt_protocol.h:193
#define DLT_HTYP_MSBF
Definition: dlt_protocol.h:83
int32_t bytesRcvd
Definition: dlt_common.h:675
DltReturnValue dlt_receiver_move_to_begin(DltReceiver *receiver)
Definition: dlt_common.c:2257
DltExtendedHeader * extendedheader
Definition: dlt_common.h:435
int dlt_client_set_serial_device(DltClient *client, char *serial_device)
Definition: dlt_client.c:850
DltReceiver receiver
Definition: dlt_client.h:91
static char * service_id[]
Definition: dlt_common.c:85
DltReturnValue dlt_message_set_extraparameters(DltMessage *msg, int verbose)
Definition: dlt_common.c:1273
static char data[kDataSize]
Definition: city-test.cc:40
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
DltReturnValue dlt_receiver_init(DltReceiver *receiver, int fd, int buffersize)
Definition: dlt_common.c:2126
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
#define DLT_HTYP_WTMS
Definition: dlt_protocol.h:86
int dlt_client_set_socket_path(DltClient *client, char *socket_path)
Definition: dlt_client.c:861
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.
#define DLT_CLIENT_DUMMY_CON_ID
uint32_t dlt_uptime(void)
Definition: dlt_common.c:3274
DltReturnValue dlt_client_connect(DltClient *client, int verbose)
Definition: dlt_client.c:168
#define DLT_SERVICE_ID_RESET_TO_FACTORY_DEFAULT
Definition: dlt_protocol.h:181
int32_t headersize
Definition: dlt_common.h:422
const char dltSerialHeader[DLT_ID_SIZE]
Definition: dlt_common.c:70
#define DLT_CLIENT_RCVBUFSIZE
#define DLT_CLIENT_INITIAL_BAUDRATE
uint8_t headerbuffer[sizeof(DltStorageHeader)+sizeof(DltStandardHeader)+sizeof(DltStandardHeaderExtra)+sizeof(DltExtendedHeader)]
Definition: dlt_common.h:427
DltStandardHeaderExtra headerextra
Definition: dlt_common.h:434
static char str[DLT_CLIENT_TEXTBUFSIZE]
Definition: dlt_client.c:103
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
DltReturnValue dlt_setup_serial(int fd, speed_t speed)
Definition: dlt_common.c:2992
DltStandardHeader * standardheader
Definition: dlt_common.h:433
DltReturnValue dlt_message_free(DltMessage *msg, int verbose)
Definition: dlt_common.c:691
speed_t dlt_convert_serial_speed(int baudrate)
Definition: dlt_common.c:3067
#define DLT_SERVICE_ID_SET_ALL_LOG_LEVEL
Definition: dlt_protocol.h:204
speed_t baudrate
Definition: dlt_client.h:98
DltReturnValue dlt_client_send_log_level(DltClient *client, char *apid, char *ctid, uint8_t logLevel)
Definition: dlt_client.c:571
#define DLT_CLIENT_DUMMY_APP_ID
DltReturnValue dlt_client_send_default_log_level(DltClient *client, uint8_t defaultLogLevel)
Definition: dlt_client.c:678
char * servIP
Definition: dlt_client.h:93
uint8_t * databuffer
Definition: dlt_common.h:428
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
#define DLT_DAEMON_TCP_PORT
Definition: dlt_common.h:192
char * serialDevice
Definition: dlt_client.h:95
#define DLT_SERVICE_ID_SET_TIMING_PACKETS
Definition: dlt_protocol.h:186
int port
Definition: dlt_client.h:94
DltReturnValue dlt_vlog(int prio, const char *format,...)
Definition: dlt_common.c:2078
static int(* message_callback_function)(DltMessage *message, void *data)
Definition: dlt_client.c:101
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 NULL
Definition: dlt_common.h:232
DltReturnValue dlt_client_send_store_config(DltClient *client)
Definition: dlt_client.c:797
DltReturnValue dlt_receiver_free(DltReceiver *receiver)
Definition: dlt_common.c:2153