2 * Dlt Daemon - Diagnostic Log and Trace
5 * Copyright (C) 2011, BMW AG - Alexander Wenzel <alexander.wenzel@bmw.de>
7 * This program is free software; you can redistribute it and/or modify it under the terms of the
8 * GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
11 * Public License, version 2.1, for more details.
13 * You should have received a copy of the GNU Lesser General Public License, version 2.1, along
14 * with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
16 * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may
17 * also be applicable to programs even in cases in which the program is not a library in the technical sense.
19 * Linking DLT statically or dynamically with other modules is making a combined work based on DLT. You may
20 * license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to
21 * license your linked modules under the GNU Lesser General Public License, version 2.1, you
22 * may use the program under the following exception.
24 * As a special exception, the copyright holders of DLT give you permission to combine DLT
25 * with software programs or libraries that are released under any license unless such a combination is not
26 * permitted by the license of such a software program or library. You may copy and distribute such a
27 * system following the terms of the GNU Lesser General Public License, version 2.1, including this
28 * special exception, for DLT and the licenses of the other code concerned.
30 * Note that people who make modified versions of DLT are not obligated to grant this special exception
31 * for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License,
32 * version 2.1, gives permission to release a modified version without this exception; this exception
33 * also makes it possible to release a modified version which carries forward this exception.
38 /*******************************************************************************
40 ** SRC-MODULE: dlt_daemon_common.c **
46 ** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de **
53 ** PLATFORM DEPENDANT [yes/no]: yes **
55 ** TO BE CHANGED BY USER [yes/no]: no **
57 *******************************************************************************/
59 /*******************************************************************************
61 ********************************************************************************
63 ** Initials Name Company **
64 ** -------- ------------------------- ---------------------------------- **
65 ** aw Alexander Wenzel BMW **
66 ** mk Markus Klein Fraunhofer ESK **
67 *******************************************************************************/
69 /*******************************************************************************
70 ** Revision Control History **
71 *******************************************************************************/
74 * $LastChangedRevision: 1670 $
75 * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $
89 #include <sys/types.h> /* send() */
90 #include <sys/socket.h> /* send() */
92 #include "dlt_types.h"
93 #include "dlt_daemon_common.h"
94 #include "dlt_daemon_common_cfg.h"
95 #include "dlt_user_shared.h"
96 #include "dlt_user_shared_cfg.h"
98 static char str[DLT_DAEMON_TEXTBUFSIZE];
100 sem_t dlt_daemon_mutex;
102 static int dlt_daemon_cmp_apid(const void *m1, const void *m2)
104 DltDaemonApplication *mi1 = (DltDaemonApplication *) m1;
105 DltDaemonApplication *mi2 = (DltDaemonApplication *) m2;
107 return memcmp(mi1->apid, mi2->apid, DLT_ID_SIZE);
110 static int dlt_daemon_cmp_apid_ctid(const void *m1, const void *m2)
114 DltDaemonContext *mi1 = (DltDaemonContext *) m1;
115 DltDaemonContext *mi2 = (DltDaemonContext *) m2;
117 cmp=memcmp(mi1->apid, mi2->apid, DLT_ID_SIZE);
124 ret=memcmp(mi1->ctid, mi2->ctid, DLT_ID_SIZE);
134 int dlt_daemon_init(DltDaemon *daemon,int verbose)
136 PRINT_FUNCTION_VERBOSE(verbose);
143 daemon->num_contexts = 0;
144 daemon->contexts = 0;
146 daemon->num_applications = 0;
147 daemon->applications = 0;
149 daemon->default_log_level = DLT_DAEMON_INITIAL_LOG_LEVEL ;
150 daemon->default_trace_status = DLT_DAEMON_INITIAL_TRACE_STATUS ;
152 daemon->message_buffer_overflow = DLT_MESSAGE_BUFFER_NO_OVERFLOW;
154 daemon->runtime_context_cfg_loaded = 0;
156 /* Check for runtime cfg, if it is loadable, load it! */
157 if ((dlt_daemon_applications_load(daemon,DLT_RUNTIME_APPLICATION_CFG, verbose)==0) &&
158 (dlt_daemon_contexts_load(daemon,DLT_RUNTIME_CONTEXT_CFG, verbose)==0))
160 daemon->runtime_context_cfg_loaded = 1;
163 daemon->sendserialheader = 0;
164 daemon->timingpackets = 0;
166 dlt_set_id(daemon->ecuid,"");
168 /* initialize ring buffer for client connection */
169 if (dlt_ringbuffer_init(&(daemon->client_ringbuffer), DLT_DAEMON_RINGBUFFER_SIZE)==-1)
177 int dlt_daemon_free(DltDaemon *daemon,int verbose)
179 PRINT_FUNCTION_VERBOSE(verbose);
187 if (dlt_daemon_contexts_clear(daemon, verbose)==-1)
192 /* Free applications */
193 if (dlt_daemon_applications_clear(daemon, verbose)==-1)
201 int dlt_daemon_applications_clear(DltDaemon *daemon,int verbose)
205 PRINT_FUNCTION_VERBOSE(verbose);
212 for (i=0; i<daemon->num_applications; i++)
214 if (daemon->applications[i].application_description!=0)
216 free(daemon->applications[i].application_description);
217 daemon->applications[i].application_description = 0;
221 if (daemon->applications)
223 free(daemon->applications);
226 daemon->applications = 0;
227 daemon->num_applications = 0;
232 DltDaemonApplication* dlt_daemon_application_add(DltDaemon *daemon,char *apid,pid_t pid,char *description, int verbose)
234 DltDaemonApplication *application;
235 DltDaemonApplication *old;
238 char filename[DLT_DAEMON_TEXTBUFSIZE];
240 if ((daemon==0) || (apid==0) || (apid[0]=='\0'))
242 return (DltDaemonApplication*) 0;
245 if (daemon->applications == 0)
247 daemon->applications = (DltDaemonApplication*) malloc(sizeof(DltDaemonApplication)*DLT_DAEMON_APPL_ALLOC_SIZE);
248 if (daemon->applications==0)
250 return (DltDaemonApplication*) 0;
256 /* Check if application [apid] is already available */
257 application = dlt_daemon_application_find(daemon, apid, verbose);
260 daemon->num_applications += 1;
262 if (daemon->num_applications!=0)
264 if ((daemon->num_applications%DLT_DAEMON_APPL_ALLOC_SIZE)==0)
266 /* allocate memory in steps of DLT_DAEMON_APPL_ALLOC_SIZE, e.g. 100 */
267 old = daemon->applications;
268 daemon->applications = (DltDaemonApplication*) malloc(sizeof(DltDaemonApplication)*
269 ((daemon->num_applications/DLT_DAEMON_APPL_ALLOC_SIZE)+1)*DLT_DAEMON_APPL_ALLOC_SIZE);
270 if (daemon->applications==0)
272 daemon->applications = old;
273 return (DltDaemonApplication*) 0;
275 memcpy(daemon->applications,old,sizeof(DltDaemonApplication)*daemon->num_applications);
280 application = &(daemon->applications[daemon->num_applications-1]);
282 dlt_set_id(application->apid,apid);
283 application->application_description = 0;
284 application->num_contexts = 0;
289 /* Store application description and pid of application */
290 if (application->application_description)
292 free(application->application_description);
295 application->application_description=0;
299 application->application_description = malloc(strlen(description)+1);
300 if (application->application_description)
302 strncpy(application->application_description,description,strlen(description)+1);
303 application->application_description[strlen(description)]='\0';
307 application->pid = pid;
309 application->user_handle = -1;
313 sprintf(filename,"%s/dlt%d",DLT_USER_DIR,application->pid);
315 dlt_user_handle = open(filename, O_WRONLY|O_NONBLOCK);
316 if (dlt_user_handle <0)
318 sprintf(str,"open() failed to %s, errno=%d (%s)!\n",filename,errno,strerror(errno)); /* errno 2: ENOENT - No such file or directory */
319 dlt_log(LOG_ERR, str);
322 application->user_handle = dlt_user_handle;
328 qsort(daemon->applications,daemon->num_applications,sizeof(DltDaemonApplication),dlt_daemon_cmp_apid);
330 /* Find new position of application with apid*/
331 application = dlt_daemon_application_find(daemon, apid, verbose);
337 int dlt_daemon_application_del(DltDaemon *daemon, DltDaemonApplication *application, int verbose)
341 PRINT_FUNCTION_VERBOSE(verbose);
343 if ((daemon==0) || (application==0))
348 if (daemon->num_applications>0)
350 /* Check if user handle is open; if yes, close it */
351 if (application->user_handle!=-1)
353 close(application->user_handle);
354 application->user_handle=-1;
357 /* Free description of application to be deleted */
358 if (application->application_description)
360 free(application->application_description);
361 application->application_description = 0;
364 pos = application-(daemon->applications);
366 /* move all applications above pos to pos */
367 memmove(&(daemon->applications[pos]),&(daemon->applications[pos+1]), sizeof(DltDaemonApplication)*((daemon->num_applications-1)-pos));
369 /* Clear last application */
370 memset(&(daemon->applications[daemon->num_applications-1]),0,sizeof(DltDaemonApplication));
372 daemon->num_applications--;
379 DltDaemonApplication* dlt_daemon_application_find(DltDaemon *daemon,char *apid,int verbose)
381 DltDaemonApplication application;
383 PRINT_FUNCTION_VERBOSE(verbose);
385 if ((daemon==0) || (apid==0) || (apid[0]=='\0') || (daemon->num_applications==0))
387 return (DltDaemonApplication*) 0;
390 /* Check, if apid is smaller than smallest apid or greater than greatest apid */
391 if ((memcmp(apid,daemon->applications[0].apid,DLT_ID_SIZE)<0) ||
392 (memcmp(apid,daemon->applications[daemon->num_applications-1].apid,DLT_ID_SIZE)>0))
394 return (DltDaemonApplication*) 0;
397 dlt_set_id(application.apid,apid);
398 return (DltDaemonApplication*)bsearch(&application,daemon->applications,daemon->num_applications,sizeof(DltDaemonApplication),dlt_daemon_cmp_apid);
401 int dlt_daemon_applications_load(DltDaemon *daemon,const char *filename, int verbose)
405 char buf[DLT_DAEMON_TEXTBUFSIZE];
409 PRINT_FUNCTION_VERBOSE(verbose);
411 if ((daemon==0) || (filename==0) || (filename[0]=='\0'))
416 fd=fopen(filename, "r");
426 memset(buf, 0, sizeof(buf));
429 ret=fgets(buf,sizeof(buf),fd);
431 if (strcmp(buf,"")!=0)
437 /* pb contains now the description */
439 /* pid is unknown at loading time */
440 if (dlt_daemon_application_add(daemon,apid,0,pb,verbose)==0)
452 int dlt_daemon_applications_save(DltDaemon *daemon,const char *filename, int verbose)
457 char apid[DLT_ID_SIZE+1]; /* DLT_ID_SIZE+1, because the 0-termination is required here */
459 PRINT_FUNCTION_VERBOSE(verbose);
461 if ((daemon==0) || (filename==0) || (filename[0]=='\0'))
466 memset(apid,0, sizeof(apid));
468 if ((daemon->applications) && (daemon->num_applications>0))
470 fd=fopen(filename, "w");
473 for (i=0; i<daemon->num_applications; i++)
475 dlt_set_id(apid,daemon->applications[i].apid);
477 if ((daemon->applications[i].application_description) &&
478 (daemon->applications[i].application_description!='\0'))
480 fprintf(fd,"%s:%s:\n",apid, daemon->applications[i].application_description);
484 fprintf(fd,"%s::\n",apid);
494 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)
496 DltDaemonApplication *application;
497 DltDaemonContext *context;
498 DltDaemonContext *old;
501 PRINT_FUNCTION_VERBOSE(verbose);
503 if ((daemon==0) || (apid==0) || (apid[0]=='\0') || (ctid==0) || (ctid[0]=='\0'))
505 return (DltDaemonContext*) 0;
508 if ((log_level<DLT_LOG_DEFAULT) || (log_level>DLT_LOG_VERBOSE))
510 return (DltDaemonContext*) 0;
513 if ((trace_status<DLT_TRACE_STATUS_DEFAULT) || (trace_status>DLT_TRACE_STATUS_ON))
515 return (DltDaemonContext*) 0;
518 if (daemon->contexts == 0)
520 daemon->contexts = (DltDaemonContext*) malloc(sizeof(DltDaemonContext)*DLT_DAEMON_CONTEXT_ALLOC_SIZE);
521 if (daemon->contexts==0)
523 return (DltDaemonContext*) 0;
527 /* Check if application [apid] is available */
528 application = dlt_daemon_application_find(daemon, apid, verbose);
531 return (DltDaemonContext*) 0;
534 /* Check if context [apid, ctid] is already available */
535 context = dlt_daemon_context_find(daemon, apid, ctid, verbose);
538 daemon->num_contexts += 1;
540 if (daemon->num_contexts!=0)
542 if ((daemon->num_contexts%DLT_DAEMON_CONTEXT_ALLOC_SIZE)==0)
544 /* allocate memory for context in steps of DLT_DAEMON_CONTEXT_ALLOC_SIZE, e.g 100 */
545 old = daemon->contexts;
546 daemon->contexts = (DltDaemonContext*) malloc(sizeof(DltDaemonContext)*
547 ((daemon->num_contexts/DLT_DAEMON_CONTEXT_ALLOC_SIZE)+1)*DLT_DAEMON_CONTEXT_ALLOC_SIZE);
548 if (daemon->contexts==0)
550 daemon->contexts = old;
551 return (DltDaemonContext*) 0;
553 memcpy(daemon->contexts,old,sizeof(DltDaemonContext)*daemon->num_contexts);
558 context = &(daemon->contexts[daemon->num_contexts-1]);
560 dlt_set_id(context->apid,apid);
561 dlt_set_id(context->ctid,ctid);
562 context->context_description = 0;
564 application->num_contexts++;
568 /* Set context description */
569 if (context->context_description)
571 free(context->context_description);
574 context->context_description=0;
578 context->context_description = malloc(strlen(description)+1);
580 if (context->context_description)
582 strncpy(context->context_description,description,strlen(description)+1);
583 context->context_description[strlen(description)]='\0';
587 /* Store log level and trace status,
588 if this is a new context, or
589 if this is an old context and the runtime cfg was not loaded */
591 if ((new_context==1) ||
592 ((new_context==0) && (daemon->runtime_context_cfg_loaded==0)))
594 context->log_level = log_level;
595 context->trace_status = trace_status;
598 context->log_level_pos = log_level_pos;
599 context->user_handle = user_handle;
604 qsort(daemon->contexts,daemon->num_contexts, sizeof(DltDaemonContext),dlt_daemon_cmp_apid_ctid);
606 /* Find new position of context with apid, ctid */
607 context = dlt_daemon_context_find(daemon, apid, ctid, verbose);
613 int dlt_daemon_context_del(DltDaemon *daemon, DltDaemonContext* context, int verbose)
616 DltDaemonApplication *application;
618 PRINT_FUNCTION_VERBOSE(verbose);
620 if ((daemon==0) || (context==0))
625 if (daemon->num_contexts>0)
627 application = dlt_daemon_application_find(daemon, context->apid, verbose);
629 /* Free description of context to be deleted */
630 if (context->context_description)
632 free(context->context_description);
633 context->context_description = 0;
636 pos = context-(daemon->contexts);
638 /* move all contexts above pos to pos */
639 memmove(&(daemon->contexts[pos]),&(daemon->contexts[pos+1]), sizeof(DltDaemonContext)*((daemon->num_contexts-1)-pos));
641 /* Clear last context */
642 memset(&(daemon->contexts[daemon->num_contexts-1]),0,sizeof(DltDaemonContext));
644 daemon->num_contexts--;
646 /* Check if application [apid] is available */
649 application->num_contexts--;
656 DltDaemonContext* dlt_daemon_context_find(DltDaemon *daemon,char *apid,char *ctid,int verbose)
658 DltDaemonContext context;
660 PRINT_FUNCTION_VERBOSE(verbose);
662 if ((daemon==0) || (apid==0) || (apid[0]=='\0') || (ctid==0) || (ctid[0]=='\0') || (daemon->num_contexts==0))
664 return (DltDaemonContext*) 0;
667 /* Check, if apid is smaller than smallest apid or greater than greatest apid */
668 if ((memcmp(apid,daemon->contexts[0].apid,DLT_ID_SIZE)<0) ||
669 (memcmp(apid,daemon->contexts[daemon->num_contexts-1].apid,DLT_ID_SIZE)>0))
671 return (DltDaemonContext*) 0;
674 dlt_set_id(context.apid,apid);
675 dlt_set_id(context.ctid,ctid);
677 return (DltDaemonContext*)bsearch(&context,daemon->contexts,daemon->num_contexts,sizeof(DltDaemonContext),dlt_daemon_cmp_apid_ctid);
680 int dlt_daemon_contexts_clear(DltDaemon *daemon,int verbose)
684 PRINT_FUNCTION_VERBOSE(verbose);
691 for (i=0; i<daemon->num_contexts; i++)
693 if (daemon->contexts[i].context_description!=0)
695 free(daemon->contexts[i].context_description);
696 daemon->contexts[i].context_description = 0;
700 if (daemon->contexts)
702 free(daemon->contexts);
705 daemon->contexts = 0;
707 for (i=0; i<daemon->num_applications; i++)
709 daemon->applications[i].num_contexts = 0;
712 daemon->num_contexts = 0;
717 int dlt_daemon_contexts_load(DltDaemon *daemon,const char *filename, int verbose)
721 char buf[DLT_DAEMON_TEXTBUFSIZE];
726 PRINT_FUNCTION_VERBOSE(verbose);
728 if ((daemon==0) || (filename==0) ||( filename[0]=='\0'))
733 fd=fopen(filename, "r");
743 memset(buf, 0, sizeof(buf));
746 ret=fgets(buf,sizeof(buf),fd);
748 if (strcmp(buf,"")!=0)
760 /* pb contains now the description */
762 /* log_level_pos, and user_handle are unknown at loading time */
763 if (dlt_daemon_context_add(daemon,apid,ctid,(int8_t)ll,(int8_t)ts,0,0,pb,verbose)==0)
775 int dlt_daemon_contexts_save(DltDaemon *daemon,const char *filename, int verbose)
780 char apid[DLT_ID_SIZE+1], ctid[DLT_ID_SIZE+1]; /* DLT_ID_SIZE+1, because the 0-termination is required here */
782 PRINT_FUNCTION_VERBOSE(verbose);
784 if ((daemon==0) || (filename==0) ||( filename[0]=='\0'))
789 memset(apid,0, sizeof(apid));
790 memset(ctid,0, sizeof(ctid));
792 if ((daemon->contexts) && (daemon->num_contexts>0))
794 fd=fopen(filename, "w");
797 for (i=0; i<daemon->num_contexts; i++)
799 dlt_set_id(apid,daemon->contexts[i].apid);
800 dlt_set_id(ctid,daemon->contexts[i].ctid);
802 if ((daemon->contexts[i].context_description) &&
803 (daemon->contexts[i].context_description[0]!='\0'))
805 fprintf(fd,"%s:%s:%d:%d:%s:\n",apid,ctid,
806 (int)(daemon->contexts[i].log_level),
807 (int)(daemon->contexts[i].trace_status),
808 daemon->contexts[i].context_description);
812 fprintf(fd,"%s:%s:%d:%d::\n",apid,ctid,
813 (int)(daemon->contexts[i].log_level),
814 (int)(daemon->contexts[i].trace_status));
824 int dlt_daemon_user_send_log_level(DltDaemon *daemon,DltDaemonContext *context,int verbose)
826 DltUserHeader userheader;
827 DltUserControlMsgLogLevel usercontext;
830 PRINT_FUNCTION_VERBOSE(verbose);
832 if ((daemon==0) || (context==0))
837 if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_LOG_LEVEL)==-1)
842 usercontext.log_level = ((context->log_level == DLT_LOG_DEFAULT)?daemon->default_log_level:context->log_level);
843 usercontext.trace_status = ((context->trace_status == DLT_TRACE_STATUS_DEFAULT)?daemon->default_trace_status:context->trace_status);
845 usercontext.log_level_pos = context->log_level_pos;
848 ret = dlt_user_log_out2(context->user_handle, &(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgLogLevel));
850 if (ret!=DLT_RETURN_OK)
854 /* Close connection */
855 close(context->user_handle);
856 context->user_handle=0;
860 return ((ret==DLT_RETURN_OK)?0:-1);
863 int dlt_daemon_control_process_control(int sock, DltDaemon *daemon, DltMessage *msg, int verbose)
865 uint32_t id,id_tmp=0;
867 PRINT_FUNCTION_VERBOSE(verbose);
869 if ((daemon==0) || (msg==0))
874 if (msg->datasize<sizeof(uint32_t))
879 id_tmp = *((uint32_t*)(msg->databuffer));
880 id=DLT_ENDIAN_GET_32(msg->standardheader->htyp ,id_tmp);
882 if ((id > 0) && (id <= DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW))
884 /* Control message handling */
887 case DLT_SERVICE_ID_SET_LOG_LEVEL:
889 dlt_daemon_control_set_log_level(sock, daemon, msg, verbose);
892 case DLT_SERVICE_ID_SET_TRACE_STATUS:
894 dlt_daemon_control_set_trace_status(sock, daemon, msg, verbose);
897 case DLT_SERVICE_ID_GET_LOG_INFO:
899 dlt_daemon_control_get_log_info(sock, daemon, msg, verbose);
902 case DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL:
904 dlt_daemon_control_get_default_log_level(sock, daemon, verbose);
907 case DLT_SERVICE_ID_STORE_CONFIG:
909 if (dlt_daemon_applications_save(daemon, DLT_RUNTIME_APPLICATION_CFG, verbose)==0)
911 if (dlt_daemon_contexts_save(daemon, DLT_RUNTIME_CONTEXT_CFG, verbose)==0)
913 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_OK, verbose);
917 /* Delete saved files */
918 dlt_daemon_control_reset_to_factory_default(daemon, DLT_RUNTIME_APPLICATION_CFG, DLT_RUNTIME_CONTEXT_CFG, verbose);
919 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
924 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
928 case DLT_SERVICE_ID_RESET_TO_FACTORY_DEFAULT:
930 dlt_daemon_control_reset_to_factory_default(daemon, DLT_RUNTIME_APPLICATION_CFG, DLT_RUNTIME_CONTEXT_CFG, verbose);
931 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_OK, verbose);
934 case DLT_SERVICE_ID_SET_COM_INTERFACE_STATUS:
936 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose);
939 case DLT_SERVICE_ID_SET_COM_INTERFACE_MAX_BANDWIDTH:
941 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose);
944 case DLT_SERVICE_ID_SET_VERBOSE_MODE:
946 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose);
949 case DLT_SERVICE_ID_SET_MESSAGE_FILTERING:
951 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose);
954 case DLT_SERVICE_ID_SET_TIMING_PACKETS:
956 dlt_daemon_control_set_timing_packets(sock, daemon, msg, verbose);
959 case DLT_SERVICE_ID_GET_LOCAL_TIME:
961 /* Send response with valid timestamp (TMSP) field */
962 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_OK, verbose);
965 case DLT_SERVICE_ID_USE_ECU_ID:
967 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose);
970 case DLT_SERVICE_ID_USE_SESSION_ID:
972 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose);
975 case DLT_SERVICE_ID_USE_TIMESTAMP:
977 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose);
980 case DLT_SERVICE_ID_USE_EXTENDED_HEADER:
982 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose);
985 case DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL:
987 dlt_daemon_control_set_default_log_level(sock, daemon, msg, verbose);
990 case DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS:
992 dlt_daemon_control_set_default_trace_status(sock, daemon, msg, verbose);
995 case DLT_SERVICE_ID_GET_SOFTWARE_VERSION:
997 dlt_daemon_control_get_software_version(sock, daemon, verbose);
1000 case DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW:
1002 dlt_daemon_control_message_buffer_overflow(sock, daemon, verbose);
1007 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose);
1014 /* Injection handling */
1015 dlt_daemon_control_callsw_cinjection(sock, daemon, msg, verbose);
1021 void dlt_daemon_control_callsw_cinjection(int sock, DltDaemon *daemon, DltMessage *msg, int verbose)
1023 char apid[DLT_ID_SIZE],ctid[DLT_ID_SIZE];
1024 uint32_t id=0,id_tmp=0;
1026 DltDaemonContext *context;
1027 uint32_t data_length_inject=0,data_length_inject_tmp=0;
1031 DltUserHeader userheader;
1032 DltUserControlMsgInjection usercontext;
1033 uint8_t *userbuffer;
1035 PRINT_FUNCTION_VERBOSE(verbose);
1037 if ((daemon==0) || (msg==0))
1042 datalength = msg->datasize;
1043 ptr = msg->databuffer;
1050 DLT_MSG_READ_VALUE(id_tmp,ptr,datalength,uint32_t); /* Get service id */
1051 id=DLT_ENDIAN_GET_32(msg->standardheader->htyp, id_tmp);
1053 if ((id>=DLT_DAEMON_INJECTION_MIN) && (id<=DLT_DAEMON_INJECTION_MAX))
1055 /* This a a real SW-C injection call */
1056 data_length_inject=0;
1057 data_length_inject_tmp=0;
1059 DLT_MSG_READ_VALUE(data_length_inject_tmp,ptr,datalength,uint32_t); /* Get data length */
1060 data_length_inject=DLT_ENDIAN_GET_32(msg->standardheader->htyp, data_length_inject_tmp);
1062 /* Get context handle for apid, ctid (and seid) */
1063 /* Warning: seid is ignored in this implementation! */
1064 if (DLT_IS_HTYP_UEH(msg->standardheader->htyp))
1066 dlt_set_id(apid, msg->extendedheader->apid);
1067 dlt_set_id(ctid, msg->extendedheader->ctid);
1071 /* No extended header, and therefore no apid and ctid available */
1072 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1076 /* At this point, apid and ctid is available */
1077 context=dlt_daemon_context_find(daemon, apid, ctid, verbose);
1081 // dlt_log(LOG_INFO,"No context found!\n");
1082 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1086 /* Send user message to handle, specified in context */
1087 if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_INJECTION)==-1)
1089 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1093 usercontext.log_level_pos = context->log_level_pos;
1095 userbuffer = malloc(data_length_inject);
1099 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1103 usercontext.data_length_inject = data_length_inject;
1104 usercontext.service_id = id;
1106 memcpy(userbuffer,ptr,data_length_inject); /* Copy received injection to send buffer */
1109 if (dlt_user_log_out3(context->user_handle, &(userheader), sizeof(DltUserHeader),
1110 &(usercontext), sizeof(DltUserControlMsgInjection),
1111 userbuffer, data_length_inject)!=DLT_RETURN_OK)
1115 /* Close connection */
1116 close(context->user_handle);
1117 context->user_handle=0;
1119 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1123 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_OK, verbose);
1133 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose);
1137 void dlt_daemon_control_set_log_level(int sock, DltDaemon *daemon, DltMessage *msg, int verbose)
1139 PRINT_FUNCTION_VERBOSE(verbose);
1141 char apid[DLT_ID_SIZE],ctid[DLT_ID_SIZE];
1142 DltServiceSetLogLevel *req;
1143 DltDaemonContext *context;
1144 int32_t id=DLT_SERVICE_ID_SET_LOG_LEVEL;
1146 int8_t old_log_level;
1148 if ((daemon==0) || (msg==0))
1153 req = (DltServiceSetLogLevel*) (msg->databuffer);
1155 dlt_set_id(apid, req->apid);
1156 dlt_set_id(ctid, req->ctid);
1158 context=dlt_daemon_context_find(daemon, apid, ctid, verbose);
1163 old_log_level = context->log_level;
1164 context->log_level = req->log_level; /* No endianess conversion necessary*/
1166 if ((context->user_handle!=0) &&
1167 (dlt_daemon_user_send_log_level(daemon, context, verbose)==0))
1169 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_OK, verbose);
1173 //dlt_log(LOG_ERR, "Log level could not be sent!\n");
1174 context->log_level = old_log_level;
1175 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1180 //dlt_log(LOG_ERR, "Context not found!\n");
1181 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1185 void dlt_daemon_control_set_trace_status(int sock, DltDaemon *daemon, DltMessage *msg, int verbose)
1187 PRINT_FUNCTION_VERBOSE(verbose);
1189 char apid[DLT_ID_SIZE],ctid[DLT_ID_SIZE];
1190 DltServiceSetLogLevel *req; /* request uses same struct as set log level */
1191 DltDaemonContext *context;
1192 int32_t id=DLT_SERVICE_ID_SET_TRACE_STATUS;
1194 int8_t old_trace_status;
1196 if ((daemon==0) || (msg==0))
1201 req = (DltServiceSetLogLevel*) (msg->databuffer);
1203 dlt_set_id(apid, req->apid);
1204 dlt_set_id(ctid, req->ctid);
1206 context=dlt_daemon_context_find(daemon, apid, ctid, verbose);
1211 old_trace_status = context->trace_status;
1212 context->trace_status = req->log_level; /* No endianess conversion necessary */
1214 if ((context->user_handle!=0) &&
1215 (dlt_daemon_user_send_log_level(daemon, context, verbose)==0))
1217 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_OK, verbose);
1221 //dlt_log(LOG_ERR, "Trace Status could not be sent!\n");
1222 context->trace_status = old_trace_status;
1223 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1228 //dlt_log(LOG_ERR, "Context not found!\n");
1229 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1233 void dlt_daemon_control_set_default_log_level(int sock, DltDaemon *daemon, DltMessage *msg, int verbose)
1235 PRINT_FUNCTION_VERBOSE(verbose);
1237 DltServiceSetDefaultLogLevel *req;
1238 int32_t id=DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL;
1240 if ((daemon==0) || (msg==0))
1245 req = (DltServiceSetDefaultLogLevel*) (msg->databuffer);
1247 /* No endianess conversion necessary */
1248 if ((req->log_level>=0) &&
1249 (req->log_level<=DLT_LOG_VERBOSE))
1251 daemon->default_log_level = req->log_level; /* No endianess conversion necessary */
1253 /* Send Update to all contexts using the default log level */
1254 dlt_daemon_user_send_default_update(daemon, verbose);
1256 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_OK, verbose);
1260 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1264 void dlt_daemon_control_set_default_trace_status(int sock, DltDaemon *daemon, DltMessage *msg, int verbose)
1266 PRINT_FUNCTION_VERBOSE(verbose);
1268 /* Payload of request message */
1269 DltServiceSetDefaultLogLevel *req;
1270 int32_t id=DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS;
1272 if ((daemon==0) || (msg==0))
1277 req = (DltServiceSetDefaultLogLevel*) (msg->databuffer);
1279 /* No endianess conversion necessary */
1280 if ((req->log_level==DLT_TRACE_STATUS_OFF) ||
1281 (req->log_level==DLT_TRACE_STATUS_ON))
1283 daemon->default_trace_status = req->log_level; /* No endianess conversion necessary*/
1285 /* Send Update to all contexts using the default trace status */
1286 dlt_daemon_user_send_default_update(daemon, verbose);
1288 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_OK, verbose);
1292 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1296 void dlt_daemon_control_set_timing_packets(int sock, DltDaemon *daemon, DltMessage *msg, int verbose)
1298 PRINT_FUNCTION_VERBOSE(verbose);
1300 DltServiceSetVerboseMode *req; /* request uses same struct as set verbose mode */
1301 int32_t id=DLT_SERVICE_ID_SET_TIMING_PACKETS;
1303 if ((daemon==0) || (msg==0))
1308 req = (DltServiceSetVerboseMode*) (msg->databuffer);
1309 if ((req->new_status==0) || (req->new_status==1))
1311 daemon->timingpackets = req->new_status;
1313 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_OK, verbose);
1317 dlt_daemon_control_service_response(sock, daemon, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
1321 void dlt_daemon_control_get_software_version(int sock, DltDaemon *daemon, int verbose)
1323 char version[DLT_DAEMON_TEXTBUFSIZE];
1326 DltServiceGetSoftwareVersionResponse *resp;
1328 PRINT_FUNCTION_VERBOSE(verbose);
1335 /* initialise new message */
1336 if (dlt_message_init(&msg,0)==-1)
1338 dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_GET_SOFTWARE_VERSION, DLT_SERVICE_RESPONSE_ERROR, verbose);
1342 /* prepare payload of data */
1343 dlt_get_version(version);
1344 len = strlen(version);
1346 msg.datasize = sizeof(DltServiceGetSoftwareVersionResponse) + len;
1349 free(msg.databuffer);
1351 msg.databuffer = (uint8_t *) malloc(msg.datasize);
1352 if (msg.databuffer==0)
1354 dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_GET_SOFTWARE_VERSION, DLT_SERVICE_RESPONSE_ERROR, verbose);
1358 resp = (DltServiceGetSoftwareVersionResponse*) msg.databuffer;
1359 resp->service_id = DLT_SERVICE_ID_GET_SOFTWARE_VERSION;
1360 resp->status = DLT_SERVICE_RESPONSE_OK;
1362 memcpy(msg.databuffer+sizeof(DltServiceGetSoftwareVersionResponse),version,len);
1365 dlt_daemon_control_send_control_message(sock, daemon, &msg,"","", verbose);
1368 dlt_message_free(&msg,0);
1371 void dlt_daemon_control_get_default_log_level(int sock, DltDaemon *daemon, int verbose)
1374 DltServiceGetDefaultLogLevelResponse *resp;
1376 PRINT_FUNCTION_VERBOSE(verbose);
1383 /* initialise new message */
1384 if (dlt_message_init(&msg,0)==-1)
1386 dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL, DLT_SERVICE_RESPONSE_ERROR, verbose);
1390 msg.datasize = sizeof(DltServiceGetDefaultLogLevelResponse);
1393 free(msg.databuffer);
1395 msg.databuffer = (uint8_t *) malloc(msg.datasize);
1396 if (msg.databuffer==0)
1398 dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL, DLT_SERVICE_RESPONSE_ERROR, verbose);
1402 resp = (DltServiceGetDefaultLogLevelResponse*) msg.databuffer;
1403 resp->service_id = DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL;
1404 resp->status = DLT_SERVICE_RESPONSE_OK;
1405 resp->log_level = daemon->default_log_level;
1408 dlt_daemon_control_send_control_message(sock,daemon,&msg,"","", verbose);
1411 dlt_message_free(&msg,0);
1414 void dlt_daemon_control_get_log_info(int sock, DltDaemon *daemon, DltMessage *msg, int verbose)
1416 DltServiceGetLogInfoRequest *req;
1418 DltDaemonContext *context=0;
1419 DltDaemonApplication *application=0;
1421 int num_applications=0, num_contexts=0;
1422 uint16_t count_app_ids=0, count_con_ids=0;
1424 #if (DLT_DEBUG_GETLOGINFO==1)
1428 int32_t i,j,offset=0;
1438 PRINT_FUNCTION_VERBOSE(verbose);
1440 if ((daemon==0) || (msg==0))
1445 /* prepare pointer to message request */
1446 req = (DltServiceGetLogInfoRequest*) (msg->databuffer);
1448 /* initialise new message */
1449 if (dlt_message_init(&resp,0)==-1)
1451 dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_GET_LOG_INFO, DLT_SERVICE_RESPONSE_ERROR, verbose);
1456 if ((req->options < 3 ) || (req->options>7))
1458 dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_GET_LOG_INFO, DLT_SERVICE_RESPONSE_ERROR, verbose);
1462 if (req->apid[0]!='\0')
1464 application = dlt_daemon_application_find(daemon, req->apid, verbose);
1467 num_applications = 1;
1468 if (req->ctid[0]!='\0')
1470 context = dlt_daemon_context_find(daemon, req->apid, req->ctid, verbose);
1472 num_contexts = ((context)?1:0);
1476 num_contexts = application->num_contexts;
1481 num_applications = 0;
1487 /* Request all applications and contexts */
1488 num_applications = daemon->num_applications;
1489 num_contexts = daemon->num_contexts;
1492 /* prepare payload of data */
1494 /* Calculate maximum size for a response */
1495 resp.datasize = sizeof(uint32_t) /* SID */ + sizeof(int8_t) /* status*/ + sizeof(ID4) /* DLT_DAEMON_REMO_STRING */;
1497 sizecont = sizeof(uint32_t) /* context_id */;
1499 /* Add additional size for response of Mode 4, 6, 7 */
1500 if ((req->options==4) || (req->options==6) || (req->options==7))
1502 sizecont += sizeof(int8_t); /* log level */
1505 /* Add additional size for response of Mode 5, 6, 7 */
1506 if ((req->options==5) || (req->options==6) || (req->options==7))
1508 sizecont+= sizeof(int8_t); /* trace status */
1511 resp.datasize+= (num_applications * (sizeof(uint32_t) /* app_id */ + sizeof(uint16_t) /* count_con_ids */)) +
1512 (num_contexts * sizecont);
1514 resp.datasize+= sizeof(uint16_t) /* count_app_ids */;
1516 /* Add additional size for response of Mode 7 */
1517 if (req->options==7)
1519 if (req->apid[0]!='\0')
1521 if (req->ctid[0]!='\0')
1523 /* One application, one context */
1524 // context = dlt_daemon_context_find(daemon, req->apid, req->ctid, verbose);
1527 resp.datasize+=sizeof(uint16_t) /* len_context_description */;
1528 if (context->context_description!=0)
1530 resp.datasize+=strlen(context->context_description); /* context_description */
1536 /* One application, all contexts */
1537 if ((daemon->applications) && (application))
1539 /* Calculate start offset within contexts[] */
1541 for (i=0; i<(application-(daemon->applications)); i++)
1543 offset_base+=daemon->applications[i].num_contexts;
1546 /* Iterate over all contexts belonging to this application */
1547 for (j=0;j<application->num_contexts;j++)
1550 context = &(daemon->contexts[offset_base+j]);
1553 resp.datasize+=sizeof(uint16_t) /* len_context_description */;
1554 if (context->context_description!=0)
1556 resp.datasize+=strlen(context->context_description); /* context_description */
1563 /* Space for application description */
1566 resp.datasize+=sizeof(uint16_t) /* len_app_description */;
1567 if (application->application_description!=0)
1569 resp.datasize+=strlen(application->application_description); /* app_description */
1575 /* All applications, all contexts */
1576 for (i=0;i<daemon->num_contexts;i++)
1578 resp.datasize+=sizeof(uint16_t) /* len_context_description */;
1579 if (daemon->contexts[i].context_description!=0)
1581 resp.datasize+=strlen(daemon->contexts[i].context_description); /* context_description */
1585 for (i=0;i<daemon->num_applications;i++)
1587 resp.datasize+=sizeof(uint16_t) /* len_app_description */;
1588 if (daemon->applications[i].application_description!=0)
1590 resp.datasize+=strlen(daemon->applications[i].application_description); /* app_description */
1598 sprintf(str,"Allocate %d bytes for response msg databuffer\n", resp.datasize);
1599 dlt_log(LOG_INFO, str);
1602 /* Allocate buffer for response message */
1603 resp.databuffer = (uint8_t *) malloc(resp.datasize);
1604 if (resp.databuffer==0)
1606 dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_GET_LOG_INFO, DLT_SERVICE_RESPONSE_ERROR, verbose);
1609 memset(resp.databuffer,0,resp.datasize);
1610 /* Preparation finished */
1612 /* Prepare response */
1613 sid = DLT_SERVICE_ID_GET_LOG_INFO;
1614 memcpy(resp.databuffer,&sid,sizeof(uint32_t));
1615 offset+=sizeof(uint32_t);
1617 value = (((num_applications!=0)&&(num_contexts!=0))?req->options:8); /* 8 = no matching context found */
1619 memcpy(resp.databuffer+offset,&value,sizeof(int8_t));
1620 offset+=sizeof(int8_t);
1622 count_app_ids = num_applications;
1624 if (count_app_ids!=0)
1626 memcpy(resp.databuffer+offset,&count_app_ids,sizeof(uint16_t));
1627 offset+=sizeof(uint16_t);
1629 #if (DLT_DEBUG_GETLOGINFO==1)
1630 sprintf(str,"#apid: %d \n", count_app_ids);
1631 dlt_log(LOG_DEBUG, str);
1634 for (i=0;i<count_app_ids;i++)
1636 if (req->apid[0]!='\0')
1642 if (daemon->applications)
1644 apid = daemon->applications[i].apid;
1648 /* This should never occur! */
1653 application = dlt_daemon_application_find(daemon, apid, verbose);
1657 /* Calculate start offset within contexts[] */
1659 for (j=0; j<(application-(daemon->applications)); j++)
1661 offset_base+=daemon->applications[j].num_contexts;
1664 dlt_set_id((char*)(resp.databuffer+offset),apid);
1665 offset+=sizeof(ID4);
1667 #if (DLT_DEBUG_GETLOGINFO==1)
1668 dlt_print_id(buf, apid);
1669 sprintf(str,"apid: %s\n",buf);
1670 dlt_log(LOG_DEBUG, str);
1673 if (req->apid[0]!='\0')
1675 count_con_ids = num_contexts;
1679 count_con_ids = application->num_contexts;
1682 memcpy(resp.databuffer+offset,&count_con_ids,sizeof(uint16_t));
1683 offset+=sizeof(uint16_t);
1685 #if (DLT_DEBUG_GETLOGINFO==1)
1686 sprintf(str,"#ctid: %d \n", count_con_ids);
1687 dlt_log(LOG_DEBUG, str);
1690 for (j=0;j<count_con_ids;j++)
1692 #if (DLT_DEBUG_GETLOGINFO==1)
1693 sprintf(str,"j: %d \n",j);
1694 dlt_log(LOG_DEBUG, str);
1696 if (!((count_con_ids==1) && (req->apid[0]!='\0') && (req->ctid[0]!='\0')))
1698 context = &(daemon->contexts[offset_base+j]);
1700 /* else: context was already searched and found
1701 (one application (found) with one context (found))*/
1704 ((req->ctid[0]=='\0') ||
1705 ((req->ctid[0]!='\0') && (memcmp(context->ctid,req->ctid,DLT_ID_SIZE)==0)))
1708 dlt_set_id((char*)(resp.databuffer+offset),context->ctid);
1709 offset+=sizeof(ID4);
1711 #if (DLT_DEBUG_GETLOGINFO==1)
1712 dlt_print_id(buf, context->ctid);
1713 sprintf(str,"ctid: %s \n",buf);
1714 dlt_log(LOG_DEBUG, str);
1718 if ((req->options==4) || (req->options==6) || (req->options==7))
1720 ll=context->log_level;
1721 memcpy(resp.databuffer+offset,&ll,sizeof(int8_t));
1722 offset+=sizeof(int8_t);
1726 if ((req->options==5) || (req->options==6) || (req->options==7))
1728 ts=context->trace_status;
1729 memcpy(resp.databuffer+offset,&ts,sizeof(int8_t));
1730 offset+=sizeof(int8_t);
1734 if (req->options==7)
1736 if (context->context_description)
1738 len = strlen(context->context_description);
1739 memcpy(resp.databuffer+offset,&len,sizeof(uint16_t));
1740 offset+=sizeof(uint16_t);
1741 memcpy(resp.databuffer+offset,context->context_description,strlen(context->context_description));
1742 offset+=strlen(context->context_description);
1747 memcpy(resp.databuffer+offset,&len,sizeof(uint16_t));
1748 offset+=sizeof(uint16_t);
1752 #if (DLT_DEBUG_GETLOGINFO==1)
1753 sprintf(str,"ll=%d ts=%d \n",(int32_t)ll,(int32_t)ts);
1754 dlt_log(LOG_DEBUG, str);
1758 #if (DLT_DEBUG_GETLOGINFO==1)
1759 dlt_log(LOG_DEBUG,"\n");
1764 if (req->options==7)
1766 if (application->application_description)
1768 len = strlen(application->application_description);
1769 memcpy(resp.databuffer+offset,&len,sizeof(uint16_t));
1770 offset+=sizeof(uint16_t);
1771 memcpy(resp.databuffer+offset,application->application_description,strlen(application->application_description));
1772 offset+=strlen(application->application_description);
1777 memcpy(resp.databuffer+offset,&len,sizeof(uint16_t));
1778 offset+=sizeof(uint16_t);
1781 } /* if (application) */
1782 } /* for (i=0;i<count_app_ids;i++) */
1783 } /* if (count_app_ids!=0) */
1785 dlt_set_id((char*)(resp.databuffer+offset),DLT_DAEMON_REMO_STRING);
1788 dlt_daemon_control_send_control_message(sock,daemon,&resp,"","", verbose);
1791 dlt_message_free(&resp,0);
1794 void dlt_daemon_control_message_buffer_overflow(int sock, DltDaemon *daemon, int verbose)
1797 DltServiceMessageBufferOverflowResponse *resp;
1799 PRINT_FUNCTION_VERBOSE(verbose);
1806 /* initialise new message */
1807 if (dlt_message_init(&msg,0)==-1)
1809 dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW, DLT_SERVICE_RESPONSE_ERROR, verbose);
1813 /* prepare payload of data */
1814 msg.datasize = sizeof(DltServiceMessageBufferOverflowResponse);
1817 free(msg.databuffer);
1819 msg.databuffer = (uint8_t *) malloc(msg.datasize);
1820 if (msg.databuffer==0)
1822 if (sock!=DLT_DAEMON_STORE_TO_BUFFER)
1824 dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW, DLT_SERVICE_RESPONSE_ERROR, verbose);
1829 resp = (DltServiceMessageBufferOverflowResponse*) msg.databuffer;
1830 resp->service_id = DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW;
1831 resp->status = DLT_SERVICE_RESPONSE_OK;
1832 resp->overflow = daemon->message_buffer_overflow;
1835 dlt_daemon_control_send_control_message(sock,daemon,&msg,"","", verbose);
1838 dlt_message_free(&msg,0);
1841 void dlt_daemon_control_service_response( int sock, DltDaemon *daemon, uint32_t service_id, int8_t status , int verbose)
1844 DltServiceResponse *resp;
1846 PRINT_FUNCTION_VERBOSE(verbose);
1853 /* initialise new message */
1854 if (dlt_message_init(&msg,0)==-1)
1859 /* prepare payload of data */
1860 msg.datasize = sizeof(DltServiceResponse);
1863 free(msg.databuffer);
1865 msg.databuffer = (uint8_t *) malloc(msg.datasize);
1866 if (msg.databuffer==0)
1871 resp = (DltServiceResponse*) msg.databuffer;
1872 resp->service_id = service_id;
1873 resp->status = status;
1876 dlt_daemon_control_send_control_message(sock,daemon,&msg,"","", verbose);
1879 dlt_message_free(&msg,0);
1882 void dlt_daemon_control_send_control_message( int sock, DltDaemon *daemon, DltMessage *msg, char* appid, char* ctid, int verbose)
1887 PRINT_FUNCTION_VERBOSE(verbose);
1889 if ((daemon==0) || (msg==0) || (appid==0) || (ctid==0))
1894 /* prepare storage header */
1895 msg->storageheader = (DltStorageHeader*)msg->headerbuffer;
1897 if (dlt_set_storageheader(msg->storageheader,daemon->ecuid)==-1)
1902 /* prepare standard header */
1903 msg->standardheader = (DltStandardHeader*)(msg->headerbuffer + sizeof(DltStorageHeader));
1904 msg->standardheader->htyp = DLT_HTYP_WEID | DLT_HTYP_WTMS | DLT_HTYP_UEH | DLT_HTYP_PROTOCOL_VERSION1 ;
1906 #if (BYTE_ORDER==BIG_ENDIAN)
1907 msg->standardheader->htyp = ( msg->standardheader->htyp | DLT_HTYP_MSBF);
1910 msg->standardheader->mcnt = 0;
1912 /* Set header extra parameters */
1913 dlt_set_id(msg->headerextra.ecu,daemon->ecuid);
1915 //msg->headerextra.seid = 0;
1917 msg->headerextra.tmsp = dlt_uptime();
1919 dlt_message_set_extraparameters(msg, verbose);
1921 /* prepare extended header */
1922 msg->extendedheader = (DltExtendedHeader*)(msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp));
1923 msg->extendedheader->msin = DLT_MSIN_CONTROL_RESPONSE;
1925 msg->extendedheader->noar = 1; /* number of arguments */
1926 if (strcmp(appid,"")==0)
1928 dlt_set_id(msg->extendedheader->apid,DLT_DAEMON_CTRL_APID); /* application id */
1932 dlt_set_id(msg->extendedheader->apid, appid);
1934 if (strcmp(ctid,"")==0)
1936 dlt_set_id(msg->extendedheader->ctid,DLT_DAEMON_CTRL_CTID); /* context id */
1940 dlt_set_id(msg->extendedheader->ctid, ctid);
1943 /* prepare length information */
1944 msg->headersize = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + sizeof(DltExtendedHeader) + DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp);
1946 len=msg->headersize - sizeof(DltStorageHeader) + msg->datasize;
1949 dlt_log(LOG_CRIT,"Huge control message discarded!\n");
1953 msg->standardheader->len = DLT_HTOBE_16(((uint16_t)len));
1955 if (sock!=DLT_DAEMON_STORE_TO_BUFFER)
1960 DLT_DAEMON_SEM_LOCK();
1962 /* Optional: Send serial header, if requested */
1963 if (daemon->sendserialheader)
1965 ret=write(sock,dltSerialHeader,sizeof(dltSerialHeader));
1969 ret=write(sock, msg->headerbuffer+sizeof(DltStorageHeader),msg->headersize-sizeof(DltStorageHeader));
1970 ret=write(sock, msg->databuffer,msg->datasize);
1972 DLT_DAEMON_SEM_FREE();
1976 DLT_DAEMON_SEM_LOCK();
1978 /* Optional: Send serial header, if requested */
1979 if (daemon->sendserialheader)
1981 send(sock, dltSerialHeader,sizeof(dltSerialHeader),0);
1985 send(sock, msg->headerbuffer+sizeof(DltStorageHeader),msg->headersize-sizeof(DltStorageHeader),0);
1986 send(sock, msg->databuffer,msg->datasize,0);
1988 DLT_DAEMON_SEM_FREE();
1993 /* Store message in history buffer */
1994 if (dlt_ringbuffer_put3(&(daemon->client_ringbuffer),
1995 msg->headerbuffer+sizeof(DltStorageHeader),msg->headersize-sizeof(DltStorageHeader),
1996 msg->databuffer,msg->datasize,
2000 dlt_log(LOG_ERR,"Storage of message in history buffer failed! Message discarded.\n");
2006 void dlt_daemon_control_reset_to_factory_default(DltDaemon *daemon,const char *filename, const char *filename1, int verbose)
2010 PRINT_FUNCTION_VERBOSE(verbose);
2012 if ((daemon==0) || (filename==0) || (filename1==0) || (filename[0]=='\0') || (filename1[0]=='\0'))
2017 /* Check for runtime cfg file and delete it, if available */
2018 fd=fopen(filename, "r");
2022 /* Close and delete file */
2027 fd=fopen(filename1, "r");
2031 /* Close and delete file */
2036 daemon->default_log_level = DLT_DAEMON_INITIAL_LOG_LEVEL ;
2037 daemon->default_trace_status = DLT_DAEMON_INITIAL_TRACE_STATUS ;
2039 daemon->message_buffer_overflow = DLT_MESSAGE_BUFFER_NO_OVERFLOW;
2041 /* Reset all other things (log level, trace status, etc.
2042 to default values */
2044 /* Inform user libraries about changed default log level/trace status */
2045 dlt_daemon_user_send_default_update(daemon, verbose);
2048 void dlt_daemon_user_send_default_update(DltDaemon *daemon, int verbose)
2051 DltDaemonContext *context;
2053 PRINT_FUNCTION_VERBOSE(verbose);
2060 for (count=0;count<daemon->num_contexts; count ++)
2062 context = &(daemon->contexts[count]);
2066 if ((context->log_level == DLT_LOG_DEFAULT) ||
2067 (context->trace_status == DLT_TRACE_STATUS_DEFAULT))
2069 if (context->user_handle!=0)
2071 if (dlt_daemon_user_send_log_level(daemon, context, verbose)==-1)
2081 void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, int verbose)
2087 PRINT_FUNCTION_VERBOSE(verbose);
2094 if (sock==DLT_DAEMON_STORE_TO_BUFFER)
2099 /* initialise new message */
2100 if (dlt_message_init(&msg,0)==-1)
2105 /* prepare payload of data */
2109 free(msg.databuffer);
2115 /* prepare storage header */
2116 msg.storageheader = (DltStorageHeader*)msg.headerbuffer;
2117 dlt_set_storageheader(msg.storageheader,daemon->ecuid);
2119 /* prepare standard header */
2120 msg.standardheader = (DltStandardHeader*)(msg.headerbuffer + sizeof(DltStorageHeader));
2121 msg.standardheader->htyp = DLT_HTYP_WEID | DLT_HTYP_WTMS | DLT_HTYP_UEH | DLT_HTYP_PROTOCOL_VERSION1 ;
2123 #if (BYTE_ORDER==BIG_ENDIAN)
2124 msg.standardheader->htyp = ( msg.standardheader->htyp | DLT_HTYP_MSBF);
2127 msg.standardheader->mcnt = 0;
2129 /* Set header extra parameters */
2130 dlt_set_id(msg.headerextra.ecu,daemon->ecuid);
2131 msg.headerextra.tmsp = dlt_uptime();
2133 dlt_message_set_extraparameters(&msg, verbose);
2135 /* prepare extended header */
2136 msg.extendedheader = (DltExtendedHeader*)(msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp));
2137 msg.extendedheader->msin = DLT_MSIN_CONTROL_TIME;
2139 msg.extendedheader->noar = 0; /* number of arguments */
2140 dlt_set_id(msg.extendedheader->apid,""); /* application id */
2141 dlt_set_id(msg.extendedheader->ctid,""); /* context id */
2143 /* prepare length information */
2144 msg.headersize = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + sizeof(DltExtendedHeader) + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp);
2146 len=msg.headersize - sizeof(DltStorageHeader) + msg.datasize;
2149 dlt_log(LOG_CRIT,"Huge control message discarded!\n");
2152 dlt_message_free(&msg,0);
2157 msg.standardheader->len = DLT_HTOBE_16(((uint16_t)len));
2162 DLT_DAEMON_SEM_LOCK();
2164 /* Optional: Send serial header, if requested */
2165 if (daemon->sendserialheader)
2167 ret=write(sock,dltSerialHeader,sizeof(dltSerialHeader));
2171 ret=write(sock, msg.headerbuffer+sizeof(DltStorageHeader),msg.headersize-sizeof(DltStorageHeader));
2172 ret=write(sock, msg.databuffer,msg.datasize);
2174 DLT_DAEMON_SEM_FREE();
2178 DLT_DAEMON_SEM_LOCK();
2180 /* Optional: Send serial header, if requested */
2181 if (daemon->sendserialheader)
2183 send(sock, dltSerialHeader,sizeof(dltSerialHeader),0);
2187 send(sock, msg.headerbuffer+sizeof(DltStorageHeader),msg.headersize-sizeof(DltStorageHeader),0);
2188 send(sock, msg.databuffer,msg.datasize,0);
2190 DLT_DAEMON_SEM_FREE();
2194 dlt_message_free(&msg,0);