3 * Copyright (C) 2012 BMW AG
5 * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps.
7 * Contributions are licensed to the GENIVI Alliance under one or more
8 * Contribution License Agreements.
11 * This Source Code Form is subject to the terms of the
12 * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
13 * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
16 * \author Alexander Wenzel <alexander.aw.wenzel@bmw.de> BMW 2011-2012
18 * \file dlt_daemon_common.c
19 * For further information see http://www.genivi.org/.
23 /*******************************************************************************
25 ** SRC-MODULE: dlt_daemon_common.c **
31 ** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de **
38 ** PLATFORM DEPENDANT [yes/no]: yes **
40 ** TO BE CHANGED BY USER [yes/no]: no **
42 *******************************************************************************/
44 /*******************************************************************************
46 ********************************************************************************
48 ** Initials Name Company **
49 ** -------- ------------------------- ---------------------------------- **
50 ** aw Alexander Wenzel BMW **
51 ** mk Markus Klein Fraunhofer ESK **
52 *******************************************************************************/
54 /*******************************************************************************
55 ** Revision Control History **
56 *******************************************************************************/
59 * $LastChangedRevision: 1670 $
60 * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $
74 #include <sys/types.h> /* send() */
75 #include <sys/socket.h> /* send() */
77 #include "dlt_types.h"
78 #include "dlt_daemon_common.h"
79 #include "dlt_daemon_common_cfg.h"
80 #include "dlt_user_shared.h"
81 #include "dlt_user_shared_cfg.h"
83 static char str[DLT_DAEMON_COMMON_TEXTBUFSIZE];
85 sem_t dlt_daemon_mutex;
87 static int dlt_daemon_cmp_apid(const void *m1, const void *m2)
89 DltDaemonApplication *mi1 = (DltDaemonApplication *) m1;
90 DltDaemonApplication *mi2 = (DltDaemonApplication *) m2;
92 return memcmp(mi1->apid, mi2->apid, DLT_ID_SIZE);
95 static int dlt_daemon_cmp_apid_ctid(const void *m1, const void *m2)
99 DltDaemonContext *mi1 = (DltDaemonContext *) m1;
100 DltDaemonContext *mi2 = (DltDaemonContext *) m2;
102 cmp=memcmp(mi1->apid, mi2->apid, DLT_ID_SIZE);
109 ret=memcmp(mi1->ctid, mi2->ctid, DLT_ID_SIZE);
119 int dlt_daemon_init(DltDaemon *daemon,const char *runtime_directory, int verbose)
121 PRINT_FUNCTION_VERBOSE(verbose);
128 int append_length = 0;
129 daemon->num_contexts = 0;
130 daemon->contexts = 0;
132 daemon->num_applications = 0;
133 daemon->applications = 0;
135 daemon->default_log_level = DLT_DAEMON_INITIAL_LOG_LEVEL ;
136 daemon->default_trace_status = DLT_DAEMON_INITIAL_TRACE_STATUS ;
138 daemon->message_buffer_overflow = DLT_MESSAGE_BUFFER_NO_OVERFLOW;
139 daemon->overflow_counter = 0;
141 daemon->runtime_context_cfg_loaded = 0;
143 daemon->mode = DLT_USER_MODE_EXTERNAL;
145 /* prepare filenames for configuration */
147 append_length = PATH_MAX - sizeof(DLT_RUNTIME_APPLICATION_CFG);
148 if(runtime_directory[0])
149 strncpy(daemon->runtime_application_cfg,runtime_directory,append_length);
151 strcpy(daemon->runtime_application_cfg,DLT_RUNTIME_DEFAULT_DIRECTORY);
152 strcat(daemon->runtime_application_cfg,DLT_RUNTIME_APPLICATION_CFG);
154 append_length = PATH_MAX - sizeof(DLT_RUNTIME_CONTEXT_CFG);
155 if(runtime_directory[0])
156 strncpy(daemon->runtime_context_cfg,runtime_directory,append_length);
158 strcpy(daemon->runtime_context_cfg,DLT_RUNTIME_DEFAULT_DIRECTORY);
159 strcat(daemon->runtime_context_cfg,DLT_RUNTIME_CONTEXT_CFG);
161 append_length = PATH_MAX - sizeof(DLT_RUNTIME_CONFIGURATION);
162 if(runtime_directory[0])
163 strncpy(daemon->runtime_configuration,runtime_directory,append_length);
165 strcpy(daemon->runtime_configuration,DLT_RUNTIME_DEFAULT_DIRECTORY);
166 strcat(daemon->runtime_configuration,DLT_RUNTIME_CONFIGURATION);
168 /* Check for runtime cfg, if it is loadable, load it! */
169 if ((dlt_daemon_applications_load(daemon,daemon->runtime_application_cfg, verbose)==0) &&
170 (dlt_daemon_contexts_load(daemon,daemon->runtime_context_cfg, verbose)==0))
172 daemon->runtime_context_cfg_loaded = 1;
175 /* load configuration if available */
176 dlt_daemon_configuration_load(daemon,daemon->runtime_configuration, verbose);
178 daemon->sendserialheader = 0;
179 daemon->timingpackets = 0;
181 dlt_set_id(daemon->ecuid,"");
183 /* initialize ring buffer for client connection */
184 if (dlt_buffer_init_dynamic(&(daemon->client_ringbuffer), DLT_DAEMON_RINGBUFFER_MIN_SIZE,DLT_DAEMON_RINGBUFFER_MAX_SIZE,DLT_DAEMON_RINGBUFFER_STEP_SIZE)==-1)
192 int dlt_daemon_free(DltDaemon *daemon,int verbose)
194 PRINT_FUNCTION_VERBOSE(verbose);
202 if (dlt_daemon_contexts_clear(daemon, verbose)==-1)
207 /* Free applications */
208 if (dlt_daemon_applications_clear(daemon, verbose)==-1)
213 /* free ringbuffer */
214 dlt_buffer_free_dynamic(&(daemon->client_ringbuffer));
219 int dlt_daemon_applications_invalidate_fd(DltDaemon *daemon,int fd,int verbose)
223 PRINT_FUNCTION_VERBOSE(verbose);
230 for (i=0; i<daemon->num_applications; i++)
232 if (daemon->applications[i].user_handle==fd)
234 daemon->applications[i].user_handle = DLT_FD_INIT;
241 int dlt_daemon_applications_clear(DltDaemon *daemon,int verbose)
245 PRINT_FUNCTION_VERBOSE(verbose);
252 for (i=0; i<daemon->num_applications; i++)
254 if (daemon->applications[i].application_description!=0)
256 free(daemon->applications[i].application_description);
257 daemon->applications[i].application_description = 0;
261 if (daemon->applications)
263 free(daemon->applications);
266 daemon->applications = 0;
267 daemon->num_applications = 0;
272 DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon,char *apid,pid_t pid,char *description, int verbose)
274 DltDaemonApplication *application;
275 DltDaemonApplication *old;
278 char filename[DLT_DAEMON_COMMON_TEXTBUFSIZE];
280 if ((daemon==0) || (apid==0) || (apid[0]=='\0'))
282 return (DltDaemonApplication*) 0;
285 if (daemon->applications == 0)
287 daemon->applications = (DltDaemonApplication*) malloc(sizeof(DltDaemonApplication)*DLT_DAEMON_APPL_ALLOC_SIZE);
288 if (daemon->applications==0)
290 return (DltDaemonApplication*) 0;
296 /* Check if application [apid] is already available */
297 application = dlt_daemon_application_find(daemon, apid, verbose);
300 daemon->num_applications += 1;
302 if (daemon->num_applications!=0)
304 if ((daemon->num_applications%DLT_DAEMON_APPL_ALLOC_SIZE)==0)
306 /* allocate memory in steps of DLT_DAEMON_APPL_ALLOC_SIZE, e.g. 100 */
307 old = daemon->applications;
308 daemon->applications = (DltDaemonApplication*) malloc(sizeof(DltDaemonApplication)*
309 ((daemon->num_applications/DLT_DAEMON_APPL_ALLOC_SIZE)+1)*DLT_DAEMON_APPL_ALLOC_SIZE);
310 if (daemon->applications==0)
312 daemon->applications = old;
313 daemon->num_applications -= 1;
314 return (DltDaemonApplication*) 0;
316 memcpy(daemon->applications,old,sizeof(DltDaemonApplication)*daemon->num_applications);
321 application = &(daemon->applications[daemon->num_applications-1]);
323 dlt_set_id(application->apid,apid);
324 application->pid = 0;
325 application->application_description = 0;
326 application->num_contexts = 0;
327 application->user_handle = DLT_FD_INIT;
333 snprintf(str,DLT_DAEMON_COMMON_TEXTBUFSIZE, "Duplicate registration of AppId: %s\n",apid);
334 dlt_log(LOG_ERR, str);
338 /* Store application description and pid of application */
339 if (application->application_description)
341 free(application->application_description);
342 application->application_description=0;
347 application->application_description = malloc(strlen(description)+1);
348 if (application->application_description)
350 strncpy(application->application_description,description,strlen(description)+1);
351 application->application_description[strlen(description)]='\0';
355 if( application->user_handle != DLT_FD_INIT )
357 if( application->pid != pid )
359 if ( close(application->user_handle) < 0 )
361 snprintf(str,DLT_DAEMON_COMMON_TEXTBUFSIZE, "close() failed to %s, errno=%d (%s)!\n",filename,errno,strerror(errno)); /* errno 2: ENOENT - No such file or directory */
362 dlt_log(LOG_ERR, str);
365 application->user_handle = DLT_FD_INIT;
366 application->pid = 0;
370 /* open user pipe only if it is not yet opened */
371 if (application->user_handle==DLT_FD_INIT && pid!=0)
373 sprintf(filename,"%s/dlt%d",DLT_USER_DIR,pid);
375 dlt_user_handle = open(filename, O_WRONLY|O_NONBLOCK);
376 if ( dlt_user_handle < 0 )
378 snprintf(str,DLT_DAEMON_COMMON_TEXTBUFSIZE, "open() failed to %s, errno=%d (%s)!\n",filename,errno,strerror(errno)); /* errno 2: ENOENT - No such file or directory */
379 dlt_log(LOG_ERR, str);
382 /* check if file file descriptor was already used, and make it invalid if it is reused */
383 /* This prevents sending messages to wrong file descriptor */
384 dlt_daemon_applications_invalidate_fd(daemon,dlt_user_handle,verbose);
385 dlt_daemon_contexts_invalidate_fd(daemon,dlt_user_handle,verbose);
387 application->pid = pid;
388 application->user_handle = dlt_user_handle;
394 qsort(daemon->applications,daemon->num_applications,sizeof(DltDaemonApplication),dlt_daemon_cmp_apid);
396 /* Find new position of application with apid*/
397 application = dlt_daemon_application_find(daemon, apid, verbose);
403 int dlt_daemon_application_del(DltDaemon *daemon, DltDaemonApplication *application, int verbose)
407 PRINT_FUNCTION_VERBOSE(verbose);
409 if ((daemon==0) || (application==0))
414 if (daemon->num_applications>0)
416 /* Check if user handle is open; if yes, close it */
417 if (application->user_handle >= DLT_FD_MINIMUM)
419 close(application->user_handle);
420 application->user_handle=DLT_FD_INIT;
423 /* Free description of application to be deleted */
424 if (application->application_description)
426 free(application->application_description);
427 application->application_description = 0;
430 pos = application-(daemon->applications);
432 /* move all applications above pos to pos */
433 memmove(&(daemon->applications[pos]),&(daemon->applications[pos+1]), sizeof(DltDaemonApplication)*((daemon->num_applications-1)-pos));
435 /* Clear last application */
436 memset(&(daemon->applications[daemon->num_applications-1]),0,sizeof(DltDaemonApplication));
438 daemon->num_applications--;
445 DltDaemonApplication* dlt_daemon_application_find(DltDaemon *daemon,char *apid,int verbose)
447 DltDaemonApplication application;
449 PRINT_FUNCTION_VERBOSE(verbose);
451 if ((daemon==0) || (apid==0) || (apid[0]=='\0') || (daemon->num_applications==0))
453 return (DltDaemonApplication*) 0;
456 /* Check, if apid is smaller than smallest apid or greater than greatest apid */
457 if ((memcmp(apid,daemon->applications[0].apid,DLT_ID_SIZE)<0) ||
458 (memcmp(apid,daemon->applications[daemon->num_applications-1].apid,DLT_ID_SIZE)>0))
460 return (DltDaemonApplication*) 0;
463 dlt_set_id(application.apid,apid);
464 return (DltDaemonApplication*)bsearch(&application,daemon->applications,daemon->num_applications,sizeof(DltDaemonApplication),dlt_daemon_cmp_apid);
467 int dlt_daemon_applications_load(DltDaemon *daemon,const char *filename, int verbose)
471 char buf[DLT_DAEMON_COMMON_TEXTBUFSIZE];
475 PRINT_FUNCTION_VERBOSE(verbose);
477 if ((daemon==0) || (filename==0) || (filename[0]=='\0'))
482 fd=fopen(filename, "r");
492 memset(buf, 0, sizeof(buf));
495 ret=fgets(buf,sizeof(buf),fd);
498 /* fgets always null pointer if the last byte of the file is a new line
499 * We need to check here if there was an error or was it feof.*/
502 snprintf(str,DLT_DAEMON_COMMON_TEXTBUFSIZE, "dlt_daemon_applications_load fgets(buf,sizeof(buf),fd) returned NULL. %s\n",
504 dlt_log(LOG_ERR, str);
514 snprintf(str,DLT_DAEMON_COMMON_TEXTBUFSIZE, "dlt_daemon_applications_load fgets(buf,sizeof(buf),fd) returned NULL. Unknown error.\n");
515 dlt_log(LOG_ERR, str);
521 if (strcmp(buf,"")!=0)
527 /* pb contains now the description */
529 /* pid is unknown at loading time */
530 if (dlt_daemon_application_add(daemon,apid,0,pb,verbose)==0)
542 int dlt_daemon_applications_save(DltDaemon *daemon,const char *filename, int verbose)
547 char apid[DLT_ID_SIZE+1]; /* DLT_ID_SIZE+1, because the 0-termination is required here */
549 PRINT_FUNCTION_VERBOSE(verbose);
551 if ((daemon==0) || (filename==0) || (filename[0]=='\0'))
556 memset(apid,0, sizeof(apid));
558 if ((daemon->applications) && (daemon->num_applications>0))
560 fd=fopen(filename, "w");
563 for (i=0; i<daemon->num_applications; i++)
565 dlt_set_id(apid,daemon->applications[i].apid);
567 if ((daemon->applications[i].application_description) &&
568 (daemon->applications[i].application_description!='\0'))
570 fprintf(fd,"%s:%s:\n",apid, daemon->applications[i].application_description);
574 fprintf(fd,"%s::\n",apid);
584 DltDaemonContext* dlt_daemon_context_add(DltDaemon *daemon,char *apid,char *ctid,int8_t log_level,int8_t trace_status,int log_level_pos, int user_handle,char *description,int verbose)
586 DltDaemonApplication *application;
587 DltDaemonContext *context;
588 DltDaemonContext *old;
591 PRINT_FUNCTION_VERBOSE(verbose);
593 if ((daemon==0) || (apid==0) || (apid[0]=='\0') || (ctid==0) || (ctid[0]=='\0'))
595 return (DltDaemonContext*) 0;
598 if ((log_level<DLT_LOG_DEFAULT) || (log_level>DLT_LOG_VERBOSE))
600 return (DltDaemonContext*) 0;
603 if ((trace_status<DLT_TRACE_STATUS_DEFAULT) || (trace_status>DLT_TRACE_STATUS_ON))
605 return (DltDaemonContext*) 0;
608 if (daemon->contexts == 0)
610 daemon->contexts = (DltDaemonContext*) malloc(sizeof(DltDaemonContext)*DLT_DAEMON_CONTEXT_ALLOC_SIZE);
611 if (daemon->contexts==0)
613 return (DltDaemonContext*) 0;
617 /* Check if application [apid] is available */
618 application = dlt_daemon_application_find(daemon, apid, verbose);
621 return (DltDaemonContext*) 0;
624 /* Check if context [apid, ctid] is already available */
625 context = dlt_daemon_context_find(daemon, apid, ctid, verbose);
628 daemon->num_contexts += 1;
630 if (daemon->num_contexts!=0)
632 if ((daemon->num_contexts%DLT_DAEMON_CONTEXT_ALLOC_SIZE)==0)
634 /* allocate memory for context in steps of DLT_DAEMON_CONTEXT_ALLOC_SIZE, e.g 100 */
635 old = daemon->contexts;
636 daemon->contexts = (DltDaemonContext*) malloc(sizeof(DltDaemonContext)*
637 ((daemon->num_contexts/DLT_DAEMON_CONTEXT_ALLOC_SIZE)+1)*DLT_DAEMON_CONTEXT_ALLOC_SIZE);
638 if (daemon->contexts==0)
640 daemon->contexts = old;
641 daemon->num_contexts -= 1;
642 return (DltDaemonContext*) 0;
644 memcpy(daemon->contexts,old,sizeof(DltDaemonContext)*daemon->num_contexts);
649 context = &(daemon->contexts[daemon->num_contexts-1]);
651 dlt_set_id(context->apid,apid);
652 dlt_set_id(context->ctid,ctid);
653 context->context_description = 0;
655 application->num_contexts++;
659 /* Set context description */
660 if (context->context_description)
662 free(context->context_description);
663 context->context_description=0;
668 context->context_description = malloc(strlen(description)+1);
670 if (context->context_description)
672 strncpy(context->context_description,description,strlen(description)+1);
673 context->context_description[strlen(description)]='\0';
677 /* Store log level and trace status,
678 if this is a new context, or
679 if this is an old context and the runtime cfg was not loaded */
681 if ((new_context==1) ||
682 ((new_context==0) && (daemon->runtime_context_cfg_loaded==0)))
684 context->log_level = log_level;
685 context->trace_status = trace_status;
688 context->log_level_pos = log_level_pos;
689 context->user_handle = user_handle;
694 qsort(daemon->contexts,daemon->num_contexts, sizeof(DltDaemonContext),dlt_daemon_cmp_apid_ctid);
696 /* Find new position of context with apid, ctid */
697 context = dlt_daemon_context_find(daemon, apid, ctid, verbose);
703 int dlt_daemon_context_del(DltDaemon *daemon, DltDaemonContext* context, int verbose)
706 DltDaemonApplication *application;
708 PRINT_FUNCTION_VERBOSE(verbose);
710 if ((daemon==0) || (context==0))
715 if (daemon->num_contexts>0)
717 application = dlt_daemon_application_find(daemon, context->apid, verbose);
719 /* Free description of context to be deleted */
720 if (context->context_description)
722 free(context->context_description);
723 context->context_description = 0;
726 pos = context-(daemon->contexts);
728 /* move all contexts above pos to pos */
729 memmove(&(daemon->contexts[pos]),&(daemon->contexts[pos+1]), sizeof(DltDaemonContext)*((daemon->num_contexts-1)-pos));
731 /* Clear last context */
732 memset(&(daemon->contexts[daemon->num_contexts-1]),0,sizeof(DltDaemonContext));
734 daemon->num_contexts--;
736 /* Check if application [apid] is available */
739 application->num_contexts--;
746 DltDaemonContext* dlt_daemon_context_find(DltDaemon *daemon,char *apid,char *ctid,int verbose)
748 DltDaemonContext context;
750 PRINT_FUNCTION_VERBOSE(verbose);
752 if ((daemon==0) || (apid==0) || (apid[0]=='\0') || (ctid==0) || (ctid[0]=='\0') || (daemon->num_contexts==0))
754 return (DltDaemonContext*) 0;
757 /* Check, if apid is smaller than smallest apid or greater than greatest apid */
758 if ((memcmp(apid,daemon->contexts[0].apid,DLT_ID_SIZE)<0) ||
759 (memcmp(apid,daemon->contexts[daemon->num_contexts-1].apid,DLT_ID_SIZE)>0))
761 return (DltDaemonContext*) 0;
764 dlt_set_id(context.apid,apid);
765 dlt_set_id(context.ctid,ctid);
767 return (DltDaemonContext*)bsearch(&context,daemon->contexts,daemon->num_contexts,sizeof(DltDaemonContext),dlt_daemon_cmp_apid_ctid);
770 int dlt_daemon_contexts_invalidate_fd(DltDaemon *daemon,int fd,int verbose)
774 PRINT_FUNCTION_VERBOSE(verbose);
781 for (i=0; i<daemon->num_contexts; i++)
783 if (daemon->contexts[i].user_handle==fd)
785 daemon->contexts[i].user_handle = DLT_FD_INIT;
792 int dlt_daemon_contexts_clear(DltDaemon *daemon,int verbose)
796 PRINT_FUNCTION_VERBOSE(verbose);
803 for (i=0; i<daemon->num_contexts; i++)
805 if (daemon->contexts[i].context_description!=0)
807 free(daemon->contexts[i].context_description);
808 daemon->contexts[i].context_description = 0;
812 if (daemon->contexts)
814 free(daemon->contexts);
817 daemon->contexts = 0;
819 for (i=0; i<daemon->num_applications; i++)
821 daemon->applications[i].num_contexts = 0;
824 daemon->num_contexts = 0;
829 int dlt_daemon_contexts_load(DltDaemon *daemon,const char *filename, int verbose)
833 char buf[DLT_DAEMON_COMMON_TEXTBUFSIZE];
838 PRINT_FUNCTION_VERBOSE(verbose);
840 if ((daemon==0) || (filename==0) ||( filename[0]=='\0'))
845 fd=fopen(filename, "r");
855 memset(buf, 0, sizeof(buf));
858 ret=fgets(buf,sizeof(buf),fd);
861 /* fgets always returns null pointer if the last byte of the file is a new line.
862 * We need to check here if there was an error or was it feof.*/
865 snprintf(str,DLT_DAEMON_COMMON_TEXTBUFSIZE, "dlt_daemon_contexts_load fgets(buf,sizeof(buf),fd) returned NULL. %s\n",
867 dlt_log(LOG_ERR, str);
877 snprintf(str,DLT_DAEMON_COMMON_TEXTBUFSIZE, "dlt_daemon_contexts_load fgets(buf,sizeof(buf),fd) returned NULL. Unknown error.\n");
878 dlt_log(LOG_ERR, str);
884 if (strcmp(buf,"")!=0)
896 /* pb contains now the description */
898 /* log_level_pos, and user_handle are unknown at loading time */
899 if (dlt_daemon_context_add(daemon,apid,ctid,(int8_t)ll,(int8_t)ts,0,0,pb,verbose)==0)
911 int dlt_daemon_contexts_save(DltDaemon *daemon,const char *filename, int verbose)
916 char apid[DLT_ID_SIZE+1], ctid[DLT_ID_SIZE+1]; /* DLT_ID_SIZE+1, because the 0-termination is required here */
918 PRINT_FUNCTION_VERBOSE(verbose);
920 if ((daemon==0) || (filename==0) ||( filename[0]=='\0'))
925 memset(apid,0, sizeof(apid));
926 memset(ctid,0, sizeof(ctid));
928 if ((daemon->contexts) && (daemon->num_contexts>0))
930 fd=fopen(filename, "w");
933 for (i=0; i<daemon->num_contexts; i++)
935 dlt_set_id(apid,daemon->contexts[i].apid);
936 dlt_set_id(ctid,daemon->contexts[i].ctid);
938 if ((daemon->contexts[i].context_description) &&
939 (daemon->contexts[i].context_description[0]!='\0'))
941 fprintf(fd,"%s:%s:%d:%d:%s:\n",apid,ctid,
942 (int)(daemon->contexts[i].log_level),
943 (int)(daemon->contexts[i].trace_status),
944 daemon->contexts[i].context_description);
948 fprintf(fd,"%s:%s:%d:%d::\n",apid,ctid,
949 (int)(daemon->contexts[i].log_level),
950 (int)(daemon->contexts[i].trace_status));
960 int dlt_daemon_configuration_save(DltDaemon *daemon,const char *filename, int verbose)
964 PRINT_FUNCTION_VERBOSE(verbose);
966 if ((daemon==0) || (filename==0) ||( filename[0]=='\0'))
971 fd=fopen(filename, "w");
974 fprintf(fd,"# 0 = off, 1 = external, 2 = internal, 3 = both\n");
975 fprintf(fd,"LoggingMode = %d\n",daemon->mode);
983 int dlt_daemon_configuration_load(DltDaemon *daemon,const char *filename, int verbose)
991 PRINT_FUNCTION_VERBOSE(verbose);
993 pFile = fopen (filename,"r");
999 /* fetch line from configuration file */
1000 if ( fgets (line , 1024 , pFile) != NULL )
1002 pch = strtok (line," =\r\n");
1008 if(strcmp(pch,"#")==0)
1013 strncpy(token,pch,sizeof(token));
1017 strncpy(value,pch,sizeof(value));
1021 pch = strtok (NULL, " =\r\n");
1024 if(token[0] && value[0])
1026 /* parse arguments here */
1027 if(strcmp(token,"LoggingMode")==0)
1029 daemon->mode = atoi(value);
1030 sprintf(str,"Runtime Option: %s=%d\n",token,daemon->mode);
1031 dlt_log(LOG_INFO, str);
1035 sprintf(str,"Unknown option: %s=%s\n",token,value);
1036 dlt_log(LOG_ERR, str);
1049 sprintf(str,"Cannot open configuration file: %s\n",filename);
1050 dlt_log(LOG_WARNING, str);
1056 int dlt_daemon_user_send_log_level(DltDaemon *daemon,DltDaemonContext *context,int verbose)
1058 DltUserHeader userheader;
1059 DltUserControlMsgLogLevel usercontext;
1062 PRINT_FUNCTION_VERBOSE(verbose);
1064 if ((daemon==0) || (context==0))
1069 if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_LOG_LEVEL)==-1)
1074 usercontext.log_level = ((context->log_level == DLT_LOG_DEFAULT)?daemon->default_log_level:context->log_level);
1075 usercontext.trace_status = ((context->trace_status == DLT_TRACE_STATUS_DEFAULT)?daemon->default_trace_status:context->trace_status);
1077 usercontext.log_level_pos = context->log_level_pos;
1080 ret = dlt_user_log_out2(context->user_handle, &(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgLogLevel));
1082 if (ret!=DLT_RETURN_OK)
1086 /* Close connection */
1087 close(context->user_handle);
1088 context->user_handle=DLT_FD_INIT;
1092 return ((ret==DLT_RETURN_OK)?0:-1);
1095 int dlt_daemon_user_send_log_state(DltDaemon *daemon,DltDaemonApplication *app,int verbose)
1097 DltUserHeader userheader;
1098 DltUserControlMsgLogState logstate;
1101 PRINT_FUNCTION_VERBOSE(verbose);
1103 if ((daemon==0) || (app==0))
1108 if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_LOG_STATE)==-1)
1113 logstate.log_state = daemon->state;
1116 ret = dlt_user_log_out2(app->user_handle, &(userheader), sizeof(DltUserHeader), &(logstate), sizeof(DltUserControlMsgLogState));
1118 if (ret!=DLT_RETURN_OK)
1122 /* Close connection */
1123 close(app->user_handle);
1124 app->user_handle=DLT_FD_INIT;
1128 return ((ret==DLT_RETURN_OK)?0:-1);
1131 int dlt_daemon_control_process_control(int sock, DltDaemon *daemon, DltMessage *msg, int verbose)
1133 uint32_t id,id_tmp=0;
1135 PRINT_FUNCTION_VERBOSE(verbose);
1137 if ((daemon==0) || (msg==0))
1142 if (msg->datasize < (int32_t)sizeof(uint32_t))
1147 id_tmp = *((uint32_t*)(msg->databuffer));
1148 id=DLT_ENDIAN_GET_32(msg->standardheader->htyp ,id_tmp);
1150 if ((id > 0) && (id <= DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW))
1152 /* Control message handling */
1155 case DLT_SERVICE_ID_SET_LOG_LEVEL:
1157 dlt_daemon_control_set_log_level(sock, daemon, msg, verbose);
1160 case DLT_SERVICE_ID_SET_TRACE_STATUS:
1162 dlt_daemon_control_set_trace_status(sock, daemon, msg, verbose);
1165 case DLT_SERVICE_ID_GET_LOG_INFO:
1167 dlt_daemon_control_get_log_info(sock, daemon, msg, verbose);
1170 case DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL:
1172 dlt_daemon_control_get_default_log_level(sock, daemon, verbose);
1175 case DLT_SERVICE_ID_STORE_CONFIG:
1177 if (dlt_daemon_applications_save(daemon, daemon->runtime_application_cfg, verbose)==0)
1179 if (dlt_daemon_contexts_save(daemon, daemon->runtime_context_cfg, verbose)==0)
1181 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_OK, verbose);
1185 /* Delete saved files */
1186 dlt_daemon_control_reset_to_factory_default(daemon, daemon->runtime_application_cfg, daemon->runtime_context_cfg, verbose);
1187 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1192 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1196 case DLT_SERVICE_ID_RESET_TO_FACTORY_DEFAULT:
1198 dlt_daemon_control_reset_to_factory_default(daemon, daemon->runtime_application_cfg, daemon->runtime_context_cfg, verbose);
1199 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_OK, verbose);
1202 case DLT_SERVICE_ID_SET_COM_INTERFACE_STATUS:
1204 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose);
1207 case DLT_SERVICE_ID_SET_COM_INTERFACE_MAX_BANDWIDTH:
1209 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose);
1212 case DLT_SERVICE_ID_SET_VERBOSE_MODE:
1214 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose);
1217 case DLT_SERVICE_ID_SET_MESSAGE_FILTERING:
1219 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose);
1222 case DLT_SERVICE_ID_SET_TIMING_PACKETS:
1224 dlt_daemon_control_set_timing_packets(sock, daemon, msg, verbose);
1227 case DLT_SERVICE_ID_GET_LOCAL_TIME:
1229 /* Send response with valid timestamp (TMSP) field */
1230 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_OK, verbose);
1233 case DLT_SERVICE_ID_USE_ECU_ID:
1235 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose);
1238 case DLT_SERVICE_ID_USE_SESSION_ID:
1240 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose);
1243 case DLT_SERVICE_ID_USE_TIMESTAMP:
1245 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose);
1248 case DLT_SERVICE_ID_USE_EXTENDED_HEADER:
1250 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose);
1253 case DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL:
1255 dlt_daemon_control_set_default_log_level(sock, daemon, msg, verbose);
1258 case DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS:
1260 dlt_daemon_control_set_default_trace_status(sock, daemon, msg, verbose);
1263 case DLT_SERVICE_ID_GET_SOFTWARE_VERSION:
1265 dlt_daemon_control_get_software_version(sock, daemon, verbose);
1268 case DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW:
1270 dlt_daemon_control_message_buffer_overflow(sock, daemon, daemon->overflow_counter,"",verbose);
1275 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose);
1282 /* Injection handling */
1283 dlt_daemon_control_callsw_cinjection(sock, daemon, msg, verbose);
1289 void dlt_daemon_control_callsw_cinjection(int sock, DltDaemon *daemon, DltMessage *msg, int verbose)
1291 char apid[DLT_ID_SIZE],ctid[DLT_ID_SIZE];
1292 uint32_t id=0,id_tmp=0;
1294 DltDaemonContext *context;
1295 int32_t data_length_inject=0;
1296 uint32_t data_length_inject_tmp=0;
1300 DltUserHeader userheader;
1301 DltUserControlMsgInjection usercontext;
1302 uint8_t *userbuffer;
1304 PRINT_FUNCTION_VERBOSE(verbose);
1306 if ((daemon==0) || (msg==0))
1311 datalength = msg->datasize;
1312 ptr = msg->databuffer;
1319 DLT_MSG_READ_VALUE(id_tmp,ptr,datalength,uint32_t); /* Get service id */
1320 id=DLT_ENDIAN_GET_32(msg->standardheader->htyp, id_tmp);
1322 if ((id>=DLT_DAEMON_INJECTION_MIN) && (id<=DLT_DAEMON_INJECTION_MAX))
1324 /* This a a real SW-C injection call */
1325 data_length_inject=0;
1326 data_length_inject_tmp=0;
1328 DLT_MSG_READ_VALUE(data_length_inject_tmp,ptr,datalength,uint32_t); /* Get data length */
1329 data_length_inject=DLT_ENDIAN_GET_32(msg->standardheader->htyp, data_length_inject_tmp);
1331 /* Get context handle for apid, ctid (and seid) */
1332 /* Warning: seid is ignored in this implementation! */
1333 if (DLT_IS_HTYP_UEH(msg->standardheader->htyp))
1335 dlt_set_id(apid, msg->extendedheader->apid);
1336 dlt_set_id(ctid, msg->extendedheader->ctid);
1340 /* No extended header, and therefore no apid and ctid available */
1341 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1345 /* At this point, apid and ctid is available */
1346 context=dlt_daemon_context_find(daemon, apid, ctid, verbose);
1350 // dlt_log(LOG_INFO,"No context found!\n");
1351 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1355 /* Send user message to handle, specified in context */
1356 if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_INJECTION)==-1)
1358 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1362 usercontext.log_level_pos = context->log_level_pos;
1364 if(data_length_inject > msg->databuffersize)
1366 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1370 userbuffer = malloc(data_length_inject);
1374 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1378 usercontext.data_length_inject = data_length_inject;
1379 usercontext.service_id = id;
1381 memcpy(userbuffer,ptr,data_length_inject); /* Copy received injection to send buffer */
1384 DltReturnValue ret =
1385 dlt_user_log_out3(context->user_handle, &(userheader), sizeof(DltUserHeader),
1386 &(usercontext), sizeof(DltUserControlMsgInjection),
1387 userbuffer, data_length_inject);
1388 if (ret != DLT_RETURN_OK)
1390 if (ret == DLT_RETURN_PIPE_ERROR)
1392 /* Close connection */
1393 close(context->user_handle);
1394 context->user_handle=DLT_FD_INIT;
1396 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1400 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_OK, verbose);
1410 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose);
1414 void dlt_daemon_control_set_log_level(int sock, DltDaemon *daemon, DltMessage *msg, int verbose)
1416 PRINT_FUNCTION_VERBOSE(verbose);
1418 char apid[DLT_ID_SIZE],ctid[DLT_ID_SIZE];
1419 DltServiceSetLogLevel *req;
1420 DltDaemonContext *context;
1421 int32_t id=DLT_SERVICE_ID_SET_LOG_LEVEL;
1423 int8_t old_log_level;
1425 if ((daemon==0) || (msg==0))
1430 req = (DltServiceSetLogLevel*) (msg->databuffer);
1432 dlt_set_id(apid, req->apid);
1433 dlt_set_id(ctid, req->ctid);
1435 context=dlt_daemon_context_find(daemon, apid, ctid, verbose);
1440 old_log_level = context->log_level;
1441 context->log_level = req->log_level; /* No endianess conversion necessary*/
1443 if ((context->user_handle >= DLT_FD_MINIMUM) &&
1444 (dlt_daemon_user_send_log_level(daemon, context, verbose)==0))
1446 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_OK, verbose);
1450 //dlt_log(LOG_ERR, "Log level could not be sent!\n");
1451 context->log_level = old_log_level;
1452 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1457 //dlt_log(LOG_ERR, "Context not found!\n");
1458 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1462 void dlt_daemon_control_set_trace_status(int sock, DltDaemon *daemon, DltMessage *msg, int verbose)
1464 PRINT_FUNCTION_VERBOSE(verbose);
1466 char apid[DLT_ID_SIZE],ctid[DLT_ID_SIZE];
1467 DltServiceSetLogLevel *req; /* request uses same struct as set log level */
1468 DltDaemonContext *context;
1469 int32_t id=DLT_SERVICE_ID_SET_TRACE_STATUS;
1471 int8_t old_trace_status;
1473 if ((daemon==0) || (msg==0))
1478 req = (DltServiceSetLogLevel*) (msg->databuffer);
1480 dlt_set_id(apid, req->apid);
1481 dlt_set_id(ctid, req->ctid);
1483 context=dlt_daemon_context_find(daemon, apid, ctid, verbose);
1488 old_trace_status = context->trace_status;
1489 context->trace_status = req->log_level; /* No endianess conversion necessary */
1491 if ((context->user_handle >= DLT_FD_MINIMUM ) &&
1492 (dlt_daemon_user_send_log_level(daemon, context, verbose)==0))
1494 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_OK, verbose);
1498 //dlt_log(LOG_ERR, "Trace Status could not be sent!\n");
1499 context->trace_status = old_trace_status;
1500 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1505 //dlt_log(LOG_ERR, "Context not found!\n");
1506 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1510 void dlt_daemon_control_set_default_log_level(int sock, DltDaemon *daemon, DltMessage *msg, int verbose)
1512 PRINT_FUNCTION_VERBOSE(verbose);
1514 DltServiceSetDefaultLogLevel *req;
1515 int32_t id=DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL;
1517 if ((daemon==0) || (msg==0))
1522 req = (DltServiceSetDefaultLogLevel*) (msg->databuffer);
1524 /* No endianess conversion necessary */
1525 if (/*(req->log_level>=0) &&*/
1526 (req->log_level<=DLT_LOG_VERBOSE))
1528 daemon->default_log_level = req->log_level; /* No endianess conversion necessary */
1530 /* Send Update to all contexts using the default log level */
1531 dlt_daemon_user_send_default_update(daemon, verbose);
1533 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_OK, verbose);
1537 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1541 void dlt_daemon_control_set_default_trace_status(int sock, DltDaemon *daemon, DltMessage *msg, int verbose)
1543 PRINT_FUNCTION_VERBOSE(verbose);
1545 /* Payload of request message */
1546 DltServiceSetDefaultLogLevel *req;
1547 int32_t id=DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS;
1549 if ((daemon==0) || (msg==0))
1554 req = (DltServiceSetDefaultLogLevel*) (msg->databuffer);
1556 /* No endianess conversion necessary */
1557 if ((req->log_level==DLT_TRACE_STATUS_OFF) ||
1558 (req->log_level==DLT_TRACE_STATUS_ON))
1560 daemon->default_trace_status = req->log_level; /* No endianess conversion necessary*/
1562 /* Send Update to all contexts using the default trace status */
1563 dlt_daemon_user_send_default_update(daemon, verbose);
1565 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_OK, verbose);
1569 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1573 void dlt_daemon_control_set_timing_packets(int sock, DltDaemon *daemon, DltMessage *msg, int verbose)
1575 PRINT_FUNCTION_VERBOSE(verbose);
1577 DltServiceSetVerboseMode *req; /* request uses same struct as set verbose mode */
1578 int32_t id=DLT_SERVICE_ID_SET_TIMING_PACKETS;
1580 if ((daemon==0) || (msg==0))
1585 req = (DltServiceSetVerboseMode*) (msg->databuffer);
1586 if ((req->new_status==0) || (req->new_status==1))
1588 daemon->timingpackets = req->new_status;
1590 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_OK, verbose);
1594 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1598 void dlt_daemon_control_get_software_version(int sock, DltDaemon *daemon, int verbose)
1602 DltServiceGetSoftwareVersionResponse *resp;
1604 PRINT_FUNCTION_VERBOSE(verbose);
1611 /* initialise new message */
1612 if (dlt_message_init(&msg,0)==-1)
1614 dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_GET_SOFTWARE_VERSION, DLT_SERVICE_RESPONSE_ERROR, verbose);
1618 /* prepare payload of data */
1619 len = strlen(daemon->ECUVersionString);
1621 msg.datasize = sizeof(DltServiceGetSoftwareVersionResponse) + len;
1622 if (msg.databuffer && (msg.databuffersize < msg.datasize))
1624 free(msg.databuffer);
1627 if (msg.databuffer == 0){
1628 msg.databuffer = (uint8_t *) malloc(msg.datasize);
1629 msg.databuffersize = msg.datasize;
1631 if (msg.databuffer==0)
1633 dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_GET_SOFTWARE_VERSION, DLT_SERVICE_RESPONSE_ERROR, verbose);
1637 resp = (DltServiceGetSoftwareVersionResponse*) msg.databuffer;
1638 resp->service_id = DLT_SERVICE_ID_GET_SOFTWARE_VERSION;
1639 resp->status = DLT_SERVICE_RESPONSE_OK;
1641 memcpy(msg.databuffer+sizeof(DltServiceGetSoftwareVersionResponse),daemon->ECUVersionString,len);
1644 dlt_daemon_control_send_control_message(sock, daemon, &msg,"","", verbose);
1647 dlt_message_free(&msg,0);
1650 void dlt_daemon_control_get_default_log_level(int sock, DltDaemon *daemon, int verbose)
1653 DltServiceGetDefaultLogLevelResponse *resp;
1655 PRINT_FUNCTION_VERBOSE(verbose);
1662 /* initialise new message */
1663 if (dlt_message_init(&msg,0)==-1)
1665 dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL, DLT_SERVICE_RESPONSE_ERROR, verbose);
1669 msg.datasize = sizeof(DltServiceGetDefaultLogLevelResponse);
1670 if (msg.databuffer && (msg.databuffersize<msg.datasize))
1672 free(msg.databuffer);
1675 if (msg.databuffer == 0){
1676 msg.databuffer = (uint8_t *) malloc(msg.datasize);
1677 msg.databuffersize = msg.datasize;
1679 if (msg.databuffer==0)
1681 dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL, DLT_SERVICE_RESPONSE_ERROR, verbose);
1685 resp = (DltServiceGetDefaultLogLevelResponse*) msg.databuffer;
1686 resp->service_id = DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL;
1687 resp->status = DLT_SERVICE_RESPONSE_OK;
1688 resp->log_level = daemon->default_log_level;
1691 dlt_daemon_control_send_control_message(sock,daemon,&msg,"","", verbose);
1694 dlt_message_free(&msg,0);
1697 void dlt_daemon_control_get_log_info(int sock, DltDaemon *daemon, DltMessage *msg, int verbose)
1699 DltServiceGetLogInfoRequest *req;
1701 DltDaemonContext *context=0;
1702 DltDaemonApplication *application=0;
1704 int num_applications=0, num_contexts=0;
1705 uint16_t count_app_ids=0, count_con_ids=0;
1707 #if (DLT_DEBUG_GETLOGINFO==1)
1711 int32_t i,j,offset=0;
1721 PRINT_FUNCTION_VERBOSE(verbose);
1723 if ((daemon==0) || (msg==0))
1728 /* prepare pointer to message request */
1729 req = (DltServiceGetLogInfoRequest*) (msg->databuffer);
1731 /* initialise new message */
1732 if (dlt_message_init(&resp,0)==-1)
1734 dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_GET_LOG_INFO, DLT_SERVICE_RESPONSE_ERROR, verbose);
1739 if ((req->options < 3 ) || (req->options>7))
1741 dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_GET_LOG_INFO, DLT_SERVICE_RESPONSE_ERROR, verbose);
1745 if (req->apid[0]!='\0')
1747 application = dlt_daemon_application_find(daemon, req->apid, verbose);
1750 num_applications = 1;
1751 if (req->ctid[0]!='\0')
1753 context = dlt_daemon_context_find(daemon, req->apid, req->ctid, verbose);
1755 num_contexts = ((context)?1:0);
1759 num_contexts = application->num_contexts;
1764 num_applications = 0;
1770 /* Request all applications and contexts */
1771 num_applications = daemon->num_applications;
1772 num_contexts = daemon->num_contexts;
1775 /* prepare payload of data */
1777 /* Calculate maximum size for a response */
1778 resp.datasize = sizeof(uint32_t) /* SID */ + sizeof(int8_t) /* status*/ + sizeof(ID4) /* DLT_DAEMON_REMO_STRING */;
1780 sizecont = sizeof(uint32_t) /* context_id */;
1782 /* Add additional size for response of Mode 4, 6, 7 */
1783 if ((req->options==4) || (req->options==6) || (req->options==7))
1785 sizecont += sizeof(int8_t); /* log level */
1788 /* Add additional size for response of Mode 5, 6, 7 */
1789 if ((req->options==5) || (req->options==6) || (req->options==7))
1791 sizecont+= sizeof(int8_t); /* trace status */
1794 resp.datasize+= (num_applications * (sizeof(uint32_t) /* app_id */ + sizeof(uint16_t) /* count_con_ids */)) +
1795 (num_contexts * sizecont);
1797 resp.datasize+= sizeof(uint16_t) /* count_app_ids */;
1799 /* Add additional size for response of Mode 7 */
1800 if (req->options==7)
1802 if (req->apid[0]!='\0')
1804 if (req->ctid[0]!='\0')
1806 /* One application, one context */
1807 // context = dlt_daemon_context_find(daemon, req->apid, req->ctid, verbose);
1810 resp.datasize+=sizeof(uint16_t) /* len_context_description */;
1811 if (context->context_description!=0)
1813 resp.datasize+=strlen(context->context_description); /* context_description */
1819 /* One application, all contexts */
1820 if ((daemon->applications) && (application))
1822 /* Calculate start offset within contexts[] */
1824 for (i=0; i<(application-(daemon->applications)); i++)
1826 offset_base+=daemon->applications[i].num_contexts;
1829 /* Iterate over all contexts belonging to this application */
1830 for (j=0;j<application->num_contexts;j++)
1833 context = &(daemon->contexts[offset_base+j]);
1836 resp.datasize+=sizeof(uint16_t) /* len_context_description */;
1837 if (context->context_description!=0)
1839 resp.datasize+=strlen(context->context_description); /* context_description */
1846 /* Space for application description */
1849 resp.datasize+=sizeof(uint16_t) /* len_app_description */;
1850 if (application->application_description!=0)
1852 resp.datasize+=strlen(application->application_description); /* app_description */
1858 /* All applications, all contexts */
1859 for (i=0;i<daemon->num_contexts;i++)
1861 resp.datasize+=sizeof(uint16_t) /* len_context_description */;
1862 if (daemon->contexts[i].context_description!=0)
1864 resp.datasize+=strlen(daemon->contexts[i].context_description); /* context_description */
1868 for (i=0;i<daemon->num_applications;i++)
1870 resp.datasize+=sizeof(uint16_t) /* len_app_description */;
1871 if (daemon->applications[i].application_description!=0)
1873 resp.datasize+=strlen(daemon->applications[i].application_description); /* app_description */
1881 sprintf(str,"Allocate %d bytes for response msg databuffer\n", resp.datasize);
1882 dlt_log(LOG_INFO, str);
1885 /* Allocate buffer for response message */
1886 resp.databuffer = (uint8_t *) malloc(resp.datasize);
1887 resp.databuffersize = resp.datasize;
1889 if (resp.databuffer==0)
1891 dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_GET_LOG_INFO, DLT_SERVICE_RESPONSE_ERROR, verbose);
1894 memset(resp.databuffer,0,resp.datasize);
1895 /* Preparation finished */
1897 /* Prepare response */
1898 sid = DLT_SERVICE_ID_GET_LOG_INFO;
1899 memcpy(resp.databuffer,&sid,sizeof(uint32_t));
1900 offset+=sizeof(uint32_t);
1902 value = (((num_applications!=0)&&(num_contexts!=0))?req->options:8); /* 8 = no matching context found */
1904 memcpy(resp.databuffer+offset,&value,sizeof(int8_t));
1905 offset+=sizeof(int8_t);
1907 count_app_ids = num_applications;
1909 if (count_app_ids!=0)
1911 memcpy(resp.databuffer+offset,&count_app_ids,sizeof(uint16_t));
1912 offset+=sizeof(uint16_t);
1914 #if (DLT_DEBUG_GETLOGINFO==1)
1915 sprintf(str,"#apid: %d \n", count_app_ids);
1916 dlt_log(LOG_DEBUG, str);
1919 for (i=0;i<count_app_ids;i++)
1921 if (req->apid[0]!='\0')
1927 if (daemon->applications)
1929 apid = daemon->applications[i].apid;
1933 /* This should never occur! */
1938 application = dlt_daemon_application_find(daemon, apid, verbose);
1942 /* Calculate start offset within contexts[] */
1944 for (j=0; j<(application-(daemon->applications)); j++)
1946 offset_base+=daemon->applications[j].num_contexts;
1949 dlt_set_id((char*)(resp.databuffer+offset),apid);
1950 offset+=sizeof(ID4);
1952 #if (DLT_DEBUG_GETLOGINFO==1)
1953 dlt_print_id(buf, apid);
1954 sprintf(str,"apid: %s\n",buf);
1955 dlt_log(LOG_DEBUG, str);
1958 if (req->apid[0]!='\0')
1960 count_con_ids = num_contexts;
1964 count_con_ids = application->num_contexts;
1967 memcpy(resp.databuffer+offset,&count_con_ids,sizeof(uint16_t));
1968 offset+=sizeof(uint16_t);
1970 #if (DLT_DEBUG_GETLOGINFO==1)
1971 sprintf(str,"#ctid: %d \n", count_con_ids);
1972 dlt_log(LOG_DEBUG, str);
1975 for (j=0;j<count_con_ids;j++)
1977 #if (DLT_DEBUG_GETLOGINFO==1)
1978 sprintf(str,"j: %d \n",j);
1979 dlt_log(LOG_DEBUG, str);
1981 if (!((count_con_ids==1) && (req->apid[0]!='\0') && (req->ctid[0]!='\0')))
1983 context = &(daemon->contexts[offset_base+j]);
1985 /* else: context was already searched and found
1986 (one application (found) with one context (found))*/
1989 ((req->ctid[0]=='\0') ||
1990 ((req->ctid[0]!='\0') && (memcmp(context->ctid,req->ctid,DLT_ID_SIZE)==0)))
1993 dlt_set_id((char*)(resp.databuffer+offset),context->ctid);
1994 offset+=sizeof(ID4);
1996 #if (DLT_DEBUG_GETLOGINFO==1)
1997 dlt_print_id(buf, context->ctid);
1998 sprintf(str,"ctid: %s \n",buf);
1999 dlt_log(LOG_DEBUG, str);
2003 if ((req->options==4) || (req->options==6) || (req->options==7))
2005 ll=context->log_level;
2006 memcpy(resp.databuffer+offset,&ll,sizeof(int8_t));
2007 offset+=sizeof(int8_t);
2011 if ((req->options==5) || (req->options==6) || (req->options==7))
2013 ts=context->trace_status;
2014 memcpy(resp.databuffer+offset,&ts,sizeof(int8_t));
2015 offset+=sizeof(int8_t);
2019 if (req->options==7)
2021 if (context->context_description)
2023 len = strlen(context->context_description);
2024 memcpy(resp.databuffer+offset,&len,sizeof(uint16_t));
2025 offset+=sizeof(uint16_t);
2026 memcpy(resp.databuffer+offset,context->context_description,strlen(context->context_description));
2027 offset+=strlen(context->context_description);
2032 memcpy(resp.databuffer+offset,&len,sizeof(uint16_t));
2033 offset+=sizeof(uint16_t);
2037 #if (DLT_DEBUG_GETLOGINFO==1)
2038 sprintf(str,"ll=%d ts=%d \n",(int32_t)ll,(int32_t)ts);
2039 dlt_log(LOG_DEBUG, str);
2043 #if (DLT_DEBUG_GETLOGINFO==1)
2044 dlt_log(LOG_DEBUG,"\n");
2049 if (req->options==7)
2051 if (application->application_description)
2053 len = strlen(application->application_description);
2054 memcpy(resp.databuffer+offset,&len,sizeof(uint16_t));
2055 offset+=sizeof(uint16_t);
2056 memcpy(resp.databuffer+offset,application->application_description,strlen(application->application_description));
2057 offset+=strlen(application->application_description);
2062 memcpy(resp.databuffer+offset,&len,sizeof(uint16_t));
2063 offset+=sizeof(uint16_t);
2066 } /* if (application) */
2067 } /* for (i=0;i<count_app_ids;i++) */
2068 } /* if (count_app_ids!=0) */
2070 dlt_set_id((char*)(resp.databuffer+offset),DLT_DAEMON_REMO_STRING);
2073 dlt_daemon_control_send_control_message(sock,daemon,&resp,"","", verbose);
2076 dlt_message_free(&resp,0);
2079 int dlt_daemon_control_message_buffer_overflow(int sock, DltDaemon *daemon, unsigned int overflow_counter,char* apid, int verbose)
2082 DltServiceMessageBufferOverflowResponse *resp;
2084 PRINT_FUNCTION_VERBOSE(verbose);
2091 /* initialise new message */
2092 if (dlt_message_init(&msg,0)==-1)
2094 dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW, DLT_SERVICE_RESPONSE_ERROR, verbose);
2098 /* prepare payload of data */
2099 msg.datasize = sizeof(DltServiceMessageBufferOverflowResponse);
2100 if (msg.databuffer && (msg.databuffersize < msg.datasize))
2102 free(msg.databuffer);
2105 if (msg.databuffer == 0){
2106 msg.databuffer = (uint8_t *) malloc(msg.datasize);
2107 msg.databuffersize = msg.datasize;
2109 if (msg.databuffer==0)
2111 if (sock!=DLT_DAEMON_STORE_TO_BUFFER)
2113 dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW, DLT_SERVICE_RESPONSE_ERROR, verbose);
2118 resp = (DltServiceMessageBufferOverflowResponse*) msg.databuffer;
2119 resp->service_id = DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW;
2120 resp->status = DLT_SERVICE_RESPONSE_OK;
2121 resp->overflow = daemon->message_buffer_overflow;
2122 resp->overflow_counter = overflow_counter;
2125 if(dlt_daemon_control_send_control_message(sock,daemon,&msg,apid,"", verbose))
2127 dlt_message_free(&msg,0);
2132 dlt_message_free(&msg,0);
2137 void dlt_daemon_control_service_response( int sock, DltDaemon *daemon, uint32_t service_id, int8_t status , int verbose)
2140 DltServiceResponse *resp;
2142 PRINT_FUNCTION_VERBOSE(verbose);
2149 /* initialise new message */
2150 if (dlt_message_init(&msg,0)==-1)
2155 /* prepare payload of data */
2156 msg.datasize = sizeof(DltServiceResponse);
2157 if (msg.databuffer && (msg.databuffersize < msg.datasize))
2159 free(msg.databuffer);
2162 if (msg.databuffer == 0){
2163 msg.databuffer = (uint8_t *) malloc(msg.datasize);
2164 msg.databuffersize = msg.datasize;
2166 if (msg.databuffer==0)
2171 resp = (DltServiceResponse*) msg.databuffer;
2172 resp->service_id = service_id;
2173 resp->status = status;
2176 dlt_daemon_control_send_control_message(sock,daemon,&msg,"","", verbose);
2179 dlt_message_free(&msg,0);
2182 int dlt_daemon_control_send_control_message( int sock, DltDaemon *daemon, DltMessage *msg, char* appid, char* ctid, int verbose)
2187 PRINT_FUNCTION_VERBOSE(verbose);
2189 if ((daemon==0) || (msg==0) || (appid==0) || (ctid==0))
2194 /* prepare storage header */
2195 msg->storageheader = (DltStorageHeader*)msg->headerbuffer;
2197 if (dlt_set_storageheader(msg->storageheader,daemon->ecuid)==-1)
2202 /* prepare standard header */
2203 msg->standardheader = (DltStandardHeader*)(msg->headerbuffer + sizeof(DltStorageHeader));
2204 msg->standardheader->htyp = DLT_HTYP_WEID | DLT_HTYP_WTMS | DLT_HTYP_UEH | DLT_HTYP_PROTOCOL_VERSION1 ;
2206 #if (BYTE_ORDER==BIG_ENDIAN)
2207 msg->standardheader->htyp = ( msg->standardheader->htyp | DLT_HTYP_MSBF);
2210 msg->standardheader->mcnt = 0;
2212 /* Set header extra parameters */
2213 dlt_set_id(msg->headerextra.ecu,daemon->ecuid);
2215 //msg->headerextra.seid = 0;
2217 msg->headerextra.tmsp = dlt_uptime();
2219 dlt_message_set_extraparameters(msg, verbose);
2221 /* prepare extended header */
2222 msg->extendedheader = (DltExtendedHeader*)(msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp));
2223 msg->extendedheader->msin = DLT_MSIN_CONTROL_RESPONSE;
2225 msg->extendedheader->noar = 1; /* number of arguments */
2226 if (strcmp(appid,"")==0)
2228 dlt_set_id(msg->extendedheader->apid,DLT_DAEMON_CTRL_APID); /* application id */
2232 dlt_set_id(msg->extendedheader->apid, appid);
2234 if (strcmp(ctid,"")==0)
2236 dlt_set_id(msg->extendedheader->ctid,DLT_DAEMON_CTRL_CTID); /* context id */
2240 dlt_set_id(msg->extendedheader->ctid, ctid);
2243 /* prepare length information */
2244 msg->headersize = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + sizeof(DltExtendedHeader) + DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp);
2246 len=msg->headersize - sizeof(DltStorageHeader) + msg->datasize;
2249 dlt_log(LOG_CRIT,"Huge control message discarded!\n");
2253 msg->standardheader->len = DLT_HTOBE_16(((uint16_t)len));
2255 if (sock!=DLT_DAEMON_STORE_TO_BUFFER)
2260 DLT_DAEMON_SEM_LOCK();
2262 /* Optional: Send serial header, if requested */
2263 if (daemon->sendserialheader)
2265 ret=write(sock,dltSerialHeader,sizeof(dltSerialHeader));
2268 dlt_log(LOG_CRIT,"dlt_daemon_control_send_control_message: write dltSerialHeader failed\n");
2269 DLT_DAEMON_SEM_FREE();
2275 ret=write(sock, msg->headerbuffer+sizeof(DltStorageHeader),msg->headersize-sizeof(DltStorageHeader));
2278 dlt_log(LOG_CRIT,"dlt_daemon_control_send_control_message: write msg->headerbuffer failed\n");
2279 DLT_DAEMON_SEM_FREE();
2282 ret=write(sock, msg->databuffer,msg->datasize);
2285 dlt_log(LOG_CRIT,"dlt_daemon_control_send_control_message: write msg->databuffer failed\n");
2286 DLT_DAEMON_SEM_FREE();
2290 DLT_DAEMON_SEM_FREE();
2294 DLT_DAEMON_SEM_LOCK();
2296 /* Optional: Send serial header, if requested */
2297 if (daemon->sendserialheader)
2299 if (0 > send(sock, dltSerialHeader,sizeof(dltSerialHeader),0))
2300 dlt_log(LOG_WARNING,"dlt_daemon_control_send_control_message: send serialheader failed\n");
2306 if ( 0 > send(sock, msg->headerbuffer+sizeof(DltStorageHeader),msg->headersize-sizeof(DltStorageHeader),0))
2307 dlt_log(LOG_WARNING,"dlt_daemon_control_send_control_message: send DltStorageHeader failed\n");
2309 if ( 0 > send(sock, msg->databuffer,msg->datasize,0))
2310 dlt_log(LOG_WARNING,"dlt_daemon_control_send_control_message: send databuffer failed\n");
2312 DLT_DAEMON_SEM_FREE();
2317 DLT_DAEMON_SEM_LOCK();
2318 /* Store message in history buffer */
2319 if (dlt_buffer_push3(&(daemon->client_ringbuffer),
2320 msg->headerbuffer+sizeof(DltStorageHeader),msg->headersize-sizeof(DltStorageHeader),
2321 msg->databuffer,msg->datasize,
2325 DLT_DAEMON_SEM_FREE();
2326 dlt_log(LOG_ERR,"Storage of message in history buffer failed! Message discarded.\n");
2329 DLT_DAEMON_SEM_FREE();
2334 void dlt_daemon_control_reset_to_factory_default(DltDaemon *daemon,const char *filename, const char *filename1, int verbose)
2338 PRINT_FUNCTION_VERBOSE(verbose);
2340 if ((daemon==0) || (filename==0) || (filename1==0) || (filename[0]=='\0') || (filename1[0]=='\0'))
2345 /* Check for runtime cfg file and delete it, if available */
2346 fd=fopen(filename, "r");
2350 /* Close and delete file */
2355 fd=fopen(filename1, "r");
2359 /* Close and delete file */
2364 daemon->default_log_level = DLT_DAEMON_INITIAL_LOG_LEVEL ;
2365 daemon->default_trace_status = DLT_DAEMON_INITIAL_TRACE_STATUS ;
2367 daemon->message_buffer_overflow = DLT_MESSAGE_BUFFER_NO_OVERFLOW;
2369 /* Reset all other things (log level, trace status, etc.
2370 to default values */
2372 /* Inform user libraries about changed default log level/trace status */
2373 dlt_daemon_user_send_default_update(daemon, verbose);
2376 void dlt_daemon_user_send_default_update(DltDaemon *daemon, int verbose)
2379 DltDaemonContext *context;
2381 PRINT_FUNCTION_VERBOSE(verbose);
2388 for (count=0;count<daemon->num_contexts; count ++)
2390 context = &(daemon->contexts[count]);
2394 if ((context->log_level == DLT_LOG_DEFAULT) ||
2395 (context->trace_status == DLT_TRACE_STATUS_DEFAULT))
2397 if (context->user_handle >= DLT_FD_MINIMUM)
2399 if (dlt_daemon_user_send_log_level(daemon, context, verbose)==-1)
2409 void dlt_daemon_user_send_all_log_state(DltDaemon *daemon, int verbose)
2412 DltDaemonApplication *app;
2414 PRINT_FUNCTION_VERBOSE(verbose);
2421 for (count=0;count<daemon->num_applications; count ++)
2423 app = &(daemon->applications[count]);
2427 if (app->user_handle >= DLT_FD_MINIMUM)
2429 if (dlt_daemon_user_send_log_state(daemon, app, verbose)==-1)
2438 void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, int verbose)
2444 PRINT_FUNCTION_VERBOSE(verbose);
2451 if (sock==DLT_DAEMON_STORE_TO_BUFFER)
2456 /* initialise new message */
2457 if (dlt_message_init(&msg,0)==-1)
2464 /* prepare storage header */
2465 msg.storageheader = (DltStorageHeader*)msg.headerbuffer;
2466 dlt_set_storageheader(msg.storageheader,daemon->ecuid);
2468 /* prepare standard header */
2469 msg.standardheader = (DltStandardHeader*)(msg.headerbuffer + sizeof(DltStorageHeader));
2470 msg.standardheader->htyp = DLT_HTYP_WEID | DLT_HTYP_WTMS | DLT_HTYP_UEH | DLT_HTYP_PROTOCOL_VERSION1 ;
2472 #if (BYTE_ORDER==BIG_ENDIAN)
2473 msg.standardheader->htyp = ( msg.standardheader->htyp | DLT_HTYP_MSBF);
2476 msg.standardheader->mcnt = 0;
2478 /* Set header extra parameters */
2479 dlt_set_id(msg.headerextra.ecu,daemon->ecuid);
2480 msg.headerextra.tmsp = dlt_uptime();
2482 dlt_message_set_extraparameters(&msg, verbose);
2484 /* prepare extended header */
2485 msg.extendedheader = (DltExtendedHeader*)(msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp));
2486 msg.extendedheader->msin = DLT_MSIN_CONTROL_TIME;
2488 msg.extendedheader->noar = 0; /* number of arguments */
2489 dlt_set_id(msg.extendedheader->apid,""); /* application id */
2490 dlt_set_id(msg.extendedheader->ctid,""); /* context id */
2492 /* prepare length information */
2493 msg.headersize = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + sizeof(DltExtendedHeader) + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp);
2495 len=msg.headersize - sizeof(DltStorageHeader) + msg.datasize;
2498 dlt_log(LOG_CRIT,"Huge control message discarded!\n");
2501 dlt_message_free(&msg,0);
2506 msg.standardheader->len = DLT_HTOBE_16(((uint16_t)len));
2511 DLT_DAEMON_SEM_LOCK();
2513 /* Optional: Send serial header, if requested */
2514 if (daemon->sendserialheader)
2516 ret=write(sock,dltSerialHeader,sizeof(dltSerialHeader));
2520 ret=write(sock, msg.headerbuffer+sizeof(DltStorageHeader),msg.headersize-sizeof(DltStorageHeader));
2521 if(msg.datasize > 0)
2523 ret=write(sock, msg.databuffer,msg.datasize);
2525 dlt_log(LOG_CRIT,"dlt_daemon_control_message_time: Failed to write databuffer\n");
2526 dlt_message_free(&msg,0);
2527 DLT_DAEMON_SEM_FREE();
2532 DLT_DAEMON_SEM_FREE();
2536 DLT_DAEMON_SEM_LOCK();
2538 /* Optional: Send serial header, if requested */
2539 if (daemon->sendserialheader)
2541 if ( 0 > send(sock, dltSerialHeader,sizeof(dltSerialHeader),0) )
2542 dlt_log(LOG_ERR,"dlt_daemon_control_message_time: Failed to send dltSerialHeader");
2547 if (0 > send(sock, msg.headerbuffer+sizeof(DltStorageHeader),msg.headersize-sizeof(DltStorageHeader),0))
2548 dlt_log(LOG_ERR,"dlt_daemon_control_message_time: Failed to send DltStorageHeader");
2550 if(msg.datasize > 0)
2552 if (0 > send(sock, msg.databuffer,msg.datasize,0) )
2553 dlt_log(LOG_ERR,"dlt_daemon_control_message_time: Failed to send databuffer");
2556 DLT_DAEMON_SEM_FREE();
2560 dlt_message_free(&msg,0);
2563 int dlt_daemon_control_message_unregister_context(int sock, DltDaemon *daemon, char* apid, char* ctid, char* comid, int verbose)
2566 DltServiceUnregisterContext *resp;
2568 PRINT_FUNCTION_VERBOSE(verbose);
2575 /* initialise new message */
2576 if (dlt_message_init(&msg,0)==-1)
2578 dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW, DLT_SERVICE_RESPONSE_ERROR, verbose);
2582 /* prepare payload of data */
2583 msg.datasize = sizeof(DltServiceUnregisterContext);
2584 if (msg.databuffer && (msg.databuffersize < msg.datasize))
2586 free(msg.databuffer);
2589 if (msg.databuffer == 0){
2590 msg.databuffer = (uint8_t *) malloc(msg.datasize);
2591 msg.databuffersize = msg.datasize;
2593 if (msg.databuffer==0)
2595 if (sock!=DLT_DAEMON_STORE_TO_BUFFER)
2597 dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW, DLT_SERVICE_RESPONSE_ERROR, verbose);
2602 resp = (DltServiceUnregisterContext*) msg.databuffer;
2603 resp->service_id = DLT_SERVICE_ID_UNREGISTER_CONTEXT;
2604 resp->status = DLT_SERVICE_RESPONSE_OK;
2605 dlt_set_id(resp->apid, apid);
2606 dlt_set_id(resp->apid, ctid);
2607 dlt_set_id(resp->comid, comid);
2610 if(dlt_daemon_control_send_control_message(sock,daemon,&msg,"","", verbose))
2612 dlt_message_free(&msg,0);
2617 dlt_message_free(&msg,0);
2622 int dlt_daemon_control_message_connection_info(int sock, DltDaemon *daemon, uint8_t state, char* comid, int verbose)
2625 DltServiceConnectionInfo *resp;
2627 PRINT_FUNCTION_VERBOSE(verbose);
2634 /* initialise new message */
2635 if (dlt_message_init(&msg,0)==-1)
2637 dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW, DLT_SERVICE_RESPONSE_ERROR, verbose);
2641 /* prepare payload of data */
2642 msg.datasize = sizeof(DltServiceConnectionInfo);
2643 if (msg.databuffer && (msg.databuffersize < msg.datasize))
2645 free(msg.databuffer);
2648 if (msg.databuffer == 0){
2649 msg.databuffer = (uint8_t *) malloc(msg.datasize);
2650 msg.databuffersize = msg.datasize;
2652 if (msg.databuffer==0)
2654 if (sock!=DLT_DAEMON_STORE_TO_BUFFER)
2656 dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW, DLT_SERVICE_RESPONSE_ERROR, verbose);
2661 resp = (DltServiceConnectionInfo*) msg.databuffer;
2662 resp->service_id = DLT_SERVICE_ID_CONNECTION_INFO;
2663 resp->status = DLT_SERVICE_RESPONSE_OK;
2664 resp->state = state;
2665 dlt_set_id(resp->comid, comid);
2668 if(dlt_daemon_control_send_control_message(sock,daemon,&msg,"","", verbose))
2670 dlt_message_free(&msg,0);
2675 dlt_message_free(&msg,0);