3 * Copyright (C) 2012-2014 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/.
17 * Alexander Wenzel <alexander.aw.wenzel@bmw.de>
18 * Markus Klein <Markus.Klein@esk.fraunhofer.de>
19 * Mikko Rapeli <mikko.rapeli@bmw.de>
22 * For further information see http://www.genivi.org/.
26 #include <stdlib.h> /* for getenv(), free(), atexit() */
27 #include <string.h> /* for strcmp(), strncmp(), strlen(), memset(), memcpy() */
28 #include <signal.h> /* for signal(), SIGPIPE, SIG_IGN */
30 #if !defined (__WIN32__)
31 #include <syslog.h> /* for LOG_... */
32 #include <semaphore.h>
33 #include <pthread.h> /* POSIX Threads */
43 #include <sys/uio.h> /* writev() */
47 #include <sys/prctl.h>
50 #include <sys/types.h> /* needed for getpid() */
55 #include "dlt_user_shared.h"
56 #include "dlt_user_shared_cfg.h"
57 #include "dlt_user_cfg.h"
59 static DltUser dlt_user;
60 static int dlt_user_initialised = 0;
61 static int dlt_user_freeing = 0;
63 static char str[DLT_USER_BUFFER_LENGTH];
65 static sem_t dlt_mutex;
66 static pthread_t dlt_receiverthread_handle;
67 static pthread_attr_t dlt_receiverthread_attr;
69 /* Segmented Network Trace */
70 #define DLT_MAX_TRACE_SEGMENT_SIZE 1024
71 #define DLT_MESSAGE_QUEUE_NAME "/dlt_message_queue"
72 #define DLT_DELAYED_RESEND_INDICATOR_PATTERN 0xFFFF
74 /* Mutex to wait on while message queue is not initialized */
75 pthread_mutex_t mq_mutex;
76 pthread_cond_t mq_init_condition;
78 /* Structure to pass data to segmented thread */
82 DltNetworkTraceType nw_trace_type;
89 /* Function prototypes for internally used functions */
90 static void dlt_user_receiverthread_function(void *ptr);
91 static void dlt_user_atexit_handler(void);
92 static int dlt_user_log_init(DltContext *handle, DltContextData *log);
93 static DltReturnValue dlt_user_log_send_log(DltContextData *log, int mtype);
94 static int dlt_user_log_send_register_application(void);
95 static int dlt_user_log_send_unregister_application(void);
96 static int dlt_user_log_send_register_context(DltContextData *log);
97 static int dlt_user_log_send_unregister_context(DltContextData *log);
98 static int dlt_send_app_ll_ts_limit(const char *appid, DltLogLevelType loglevel, DltTraceStatusType tracestatus);
99 static int dlt_user_log_send_log_mode(DltUserLogMode mode);
100 static int dlt_user_print_msg(DltMessage *msg, DltContextData *log);
101 static int dlt_user_log_check_user_message(void);
102 static void dlt_user_log_reattach_to_daemon(void);
103 static int dlt_user_log_send_overflow(void);
104 static void dlt_user_trace_network_segmented_thread(void *unused);
105 static void dlt_user_trace_network_segmented_thread_segmenter(s_segmented_data *data);
106 static int dlt_user_queue_resend(void);
108 int dlt_user_check_library_version(const char *user_major_version,const char *user_minor_version){
110 char str[DLT_USER_BUFFER_LENGTH];
111 char lib_major_version[DLT_USER_MAX_LIB_VERSION_LENGTH];
112 char lib_minor_version[DLT_USER_MAX_LIB_VERSION_LENGTH];
114 dlt_get_major_version( lib_major_version,DLT_USER_MAX_LIB_VERSION_LENGTH);
115 dlt_get_minor_version( lib_minor_version,DLT_USER_MAX_LIB_VERSION_LENGTH);
117 if( (strcmp(lib_major_version,user_major_version)!=0) || (strcmp(lib_minor_version,user_minor_version)!=0))
119 snprintf(str,DLT_USER_BUFFER_LENGTH,"DLT Library version check failed! Installed DLT library version is %s.%s - Application using DLT library version %s.%s\n",lib_major_version,lib_minor_version,user_major_version,user_minor_version);
120 dlt_log(LOG_WARNING, str);
128 char filename[DLT_USER_MAX_FILENAME_LENGTH];
131 // process is exiting. Do not allocate new resources.
132 if (dlt_user_freeing != 0)
134 // return negative value, to stop the current log
138 // WARNING: multithread unsafe !
139 // Another thread will check that dlt_user_initialised != 0, but the lib is not initialised !
140 dlt_user_initialised = 1;
142 /* Initialize common part of dlt_init()/dlt_init_file() */
143 if (dlt_init_common()==-1)
145 dlt_user_initialised = 0;
149 /* check environment variables */
152 dlt_user.dlt_is_file = 0;
153 dlt_user.overflow = 0;
154 dlt_user.overflow_counter = 0;
155 #ifdef DLT_SHM_ENABLE
156 memset(&(dlt_user.dlt_shm),0,sizeof(DltShm));
159 /* create dlt pipes directory */
160 ret=mkdir(DLT_USER_DIR, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH | S_ISVTX );
161 if (ret==-1 && errno != EEXIST)
163 snprintf(str,DLT_USER_BUFFER_LENGTH,"FIFO user dir %s cannot be created!\n", DLT_USER_DIR);
164 dlt_log(LOG_ERR, str);
168 /* if dlt pipes directory is created by the application also chmod the directory */
171 // S_ISGID cannot be set by mkdir, let's reassign right bits
172 ret=chmod(DLT_USER_DIR, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH | S_ISGID | S_ISVTX );
175 snprintf(str,DLT_USER_BUFFER_LENGTH,"FIFO user dir %s cannot be chmoded!\n", DLT_USER_DIR);
176 dlt_log(LOG_ERR, str);
181 /* create and open DLT user FIFO */
182 snprintf(filename,DLT_USER_MAX_FILENAME_LENGTH,"%s/dlt%d",DLT_USER_DIR,getpid());
184 /* Try to delete existing pipe, ignore result of unlink */
187 ret=mkfifo(filename, S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP );
190 snprintf(str,DLT_USER_BUFFER_LENGTH,"Loging disabled, FIFO user %s cannot be created!\n",filename);
191 dlt_log(LOG_WARNING, str);
192 /* return 0; */ /* removed to prevent error, when FIFO already exists */
195 // S_IWGRP cannot be set by mkfifo (???), let's reassign right bits
196 ret=chmod(filename, S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP );
199 snprintf(str,DLT_USER_BUFFER_LENGTH,"FIFO user %s cannot be chmoded!\n", DLT_USER_DIR);
200 dlt_log(LOG_ERR, str);
204 dlt_user.dlt_user_handle = open(filename, O_RDWR | O_CLOEXEC);
205 if (dlt_user.dlt_user_handle == DLT_FD_INIT)
207 snprintf(str,DLT_USER_BUFFER_LENGTH,"Loging disabled, FIFO user %s cannot be opened!\n",filename);
208 dlt_log(LOG_WARNING, str);
213 /* open DLT output FIFO */
214 dlt_user.dlt_log_handle = open(DLT_USER_FIFO, O_WRONLY | O_NONBLOCK | O_CLOEXEC );
215 if (dlt_user.dlt_log_handle==-1)
217 snprintf(str,DLT_USER_BUFFER_LENGTH,"Loging disabled, FIFO %s cannot be opened with open()!\n",DLT_USER_FIFO);
218 dlt_log(LOG_WARNING, str);
223 #ifdef DLT_SHM_ENABLE
224 /* init shared memory */
225 if (dlt_shm_init_client(&(dlt_user.dlt_shm),DLT_SHM_KEY) < 0)
227 snprintf(str,DLT_USER_BUFFER_LENGTH,"Loging disabled, Shared memory %d cannot be created!\n",DLT_SHM_KEY);
228 dlt_log(LOG_WARNING, str);
235 if (dlt_receiver_init(&(dlt_user.receiver),dlt_user.dlt_user_handle, DLT_USER_RCVBUF_MAX_SIZE)==-1)
237 dlt_user_initialised = 0;
241 /* Start receiver thread */
242 if (pthread_create(&(dlt_receiverthread_handle),
244 (void *) &dlt_user_receiverthread_function,
247 if (pthread_attr_destroy(&dlt_receiverthread_attr)!=0)
249 dlt_log(LOG_WARNING, "Can't destroy thread attributes!\n");
252 dlt_log(LOG_CRIT, "Can't create receiver thread!\n");
253 dlt_user_initialised = 0;
257 if (pthread_attr_destroy(&dlt_receiverthread_attr)!=0)
259 dlt_log(LOG_WARNING, "Can't destroy thread attributes!\n");
262 /* These will be lazy initialized only when needed */
263 dlt_user.dlt_segmented_queue_read_handle = -1;
264 dlt_user.dlt_segmented_queue_write_handle = -1;
266 /* Wait mutext for segmented thread */
267 pthread_mutex_init(&mq_mutex, NULL);
268 pthread_cond_init(&mq_init_condition, NULL);
270 /* Start the segmented thread */
271 if(pthread_create(&(dlt_user.dlt_segmented_nwt_handle), NULL,
272 (void *)dlt_user_trace_network_segmented_thread, NULL))
274 dlt_log(LOG_CRIT, "Can't start segmented thread!\n");
281 int dlt_init_file(const char *name)
283 dlt_user_initialised = 1;
285 /* Initialize common part of dlt_init()/dlt_init_file() */
286 if (dlt_init_common()==-1)
288 dlt_user_initialised = 0;
292 dlt_user.dlt_is_file = 1;
294 /* open DLT output file */
295 dlt_user.dlt_log_handle = open(name,O_WRONLY|O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); /* mode: wb */
296 if (dlt_user.dlt_log_handle == -1)
298 snprintf(str,DLT_USER_BUFFER_LENGTH,"Log file %s cannot be opened!\n",name);
299 dlt_log(LOG_ERR, str);
306 int dlt_init_message_queue(void)
308 pthread_mutex_lock(&mq_mutex);
309 if(dlt_user.dlt_segmented_queue_read_handle >= 0 &&
310 dlt_user.dlt_segmented_queue_write_handle >= 0)
312 // Already intialized
313 pthread_mutex_unlock(&mq_mutex);
317 /* Generate per process name for queue */
318 char queue_name[NAME_MAX];
319 snprintf(queue_name,NAME_MAX, "%s.%d", DLT_MESSAGE_QUEUE_NAME, getpid());
321 /* Maximum queue size is 10, limit to size of pointers */
322 struct mq_attr mqatr;
324 mqatr.mq_maxmsg = 10;
325 mqatr.mq_msgsize = sizeof(s_segmented_data *);
326 mqatr.mq_curmsgs = 0;
329 * Create the message queue. It must be newly created
330 * if old one was left by a crashing process.
332 dlt_user.dlt_segmented_queue_read_handle = mq_open(queue_name, O_CREAT| O_RDONLY | O_EXCL,
333 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, &mqatr);
334 if(dlt_user.dlt_segmented_queue_read_handle < 0)
338 dlt_log(LOG_WARNING, "Old message queue exists, trying to delete.\n");
339 if(mq_unlink(queue_name) < 0)
342 snprintf(str,255,"Could not delete existing message queue!: %s \n",strerror(errno));
343 dlt_log(LOG_CRIT, str);
347 dlt_user.dlt_segmented_queue_read_handle = mq_open(queue_name, O_CREAT| O_RDONLY | O_EXCL,
348 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, &mqatr);
351 if(dlt_user.dlt_segmented_queue_read_handle < 0)
354 snprintf(str,255,"Can't create message queue read handle!: %s \n",strerror(errno));
355 dlt_log(LOG_CRIT, str);
356 pthread_mutex_unlock(&mq_mutex);
361 dlt_user.dlt_segmented_queue_write_handle = mq_open(queue_name, O_WRONLY|O_NONBLOCK);
362 if(dlt_user.dlt_segmented_queue_write_handle < 0)
366 snprintf(str,255,"Can't open message queue write handle!: %s \n",strerror(errno));
367 dlt_log(LOG_CRIT, str);
368 pthread_mutex_unlock(&mq_mutex);
372 pthread_cond_signal(&mq_init_condition);
373 pthread_mutex_unlock(&mq_mutex);
377 int dlt_init_common(void)
379 char *env_local_print;
381 /* Binary semaphore for threads */
382 if (sem_init(&dlt_mutex, 0, 1)==-1)
384 dlt_user_initialised = 0;
388 /* set to unknown state of connected client */
389 dlt_user.log_state = -1;
391 dlt_user.dlt_log_handle=-1;
392 dlt_user.dlt_user_handle=DLT_FD_INIT;
394 dlt_set_id(dlt_user.ecuID,DLT_USER_DEFAULT_ECU_ID);
395 dlt_set_id(dlt_user.appID,"");
397 dlt_user.application_description = 0;
399 /* Verbose mode is enabled by default */
400 dlt_user.verbose_mode = 1;
402 /* Use extended header for non verbose is enabled by default */
403 dlt_user.use_extende_header_for_non_verbose = DLT_USER_USE_EXTENDED_HEADER_FOR_NONVERBOSE;
405 /* WIth session id is enabled by default */
406 dlt_user.with_session_id = DLT_USER_WITH_SESSION_ID;
408 /* With timestamp is enabled by default */
409 dlt_user.with_timestamp= DLT_USER_WITH_TIMESTAMP;
411 /* With timestamp is enabled by default */
412 dlt_user.with_ecu_id= DLT_USER_WITH_ECU_ID;
414 /* Local print is disabled by default */
415 dlt_user.enable_local_print = 0;
417 dlt_user.local_print_mode = DLT_PM_UNSET;
419 env_local_print = getenv(DLT_USER_ENV_LOCAL_PRINT_MODE);
422 if (strcmp(env_local_print,"AUTOMATIC")==0)
424 dlt_user.local_print_mode = DLT_PM_AUTOMATIC;
426 else if (strcmp(env_local_print,"FORCE_ON")==0)
428 dlt_user.local_print_mode = DLT_PM_FORCE_ON;
430 else if (strcmp(env_local_print,"FORCE_OFF")==0)
432 dlt_user.local_print_mode = DLT_PM_FORCE_OFF;
436 /* Initialize LogLevel/TraceStatus field */
438 dlt_user.dlt_ll_ts = 0;
439 dlt_user.dlt_ll_ts_max_num_entries = 0;
440 dlt_user.dlt_ll_ts_num_entries = 0;
442 if (dlt_buffer_init_dynamic(&(dlt_user.startup_buffer), DLT_USER_RINGBUFFER_MIN_SIZE, DLT_USER_RINGBUFFER_MAX_SIZE, DLT_USER_RINGBUFFER_STEP_SIZE)==-1)
444 dlt_user_initialised = 0;
450 signal(SIGPIPE,SIG_IGN); /* ignore pipe signals */
452 atexit(dlt_user_atexit_handler);
454 #ifdef DLT_TEST_ENABLE
455 dlt_user.corrupt_user_header = 0;
456 dlt_user.corrupt_message_size = 0;
457 dlt_user.corrupt_message_size_size = 0;
463 void dlt_user_atexit_handler(void)
465 if (dlt_user_initialised==0)
467 dlt_log(LOG_WARNING, "dlt_user_atexit_handler dlt_user_initialised==0\n");
473 /* Try to resend potential log messages in the user buffer */
474 int count = dlt_user_atexit_blow_out_user_buffer();
478 snprintf(tmp,256,"Lost log messages in user buffer when exiting: %i\n",count);
479 dlt_log(LOG_ERR, tmp);
482 /* Unregister app (this also unregisters all contexts in daemon) */
483 /* Ignore return value */
484 dlt_unregister_app();
487 /* Ignore return value */
491 int dlt_user_atexit_blow_out_user_buffer(void){
495 uint32_t exitTime = dlt_uptime() + DLT_USER_ATEXIT_RESEND_BUFFER_EXIT_TIMEOUT;
497 while(dlt_uptime() < exitTime ){
499 ret = dlt_user_log_resend_buffer();
506 usleep(DLT_USER_ATEXIT_RESEND_BUFFER_SLEEP);
510 count = dlt_buffer_get_message_count(&(dlt_user.startup_buffer));
519 char filename[DLT_USER_MAX_FILENAME_LENGTH];
521 if( dlt_user_freeing != 0 )
522 // resources are already being freed. Do nothing and return.
525 // library is freeing its resources. Avoid to allocate it in dlt_init()
526 dlt_user_freeing = 1;
528 if (dlt_user_initialised==0)
530 dlt_user_freeing = 0;
533 dlt_user_initialised = 0;
535 if (dlt_receiverthread_handle)
537 /* Ignore return value */
538 pthread_cancel(dlt_receiverthread_handle);
541 if (dlt_user.dlt_segmented_nwt_handle)
543 pthread_cancel(dlt_user.dlt_segmented_nwt_handle);
546 if (dlt_user.dlt_user_handle!=DLT_FD_INIT)
548 snprintf(filename,DLT_USER_MAX_FILENAME_LENGTH,"%s/dlt%d",DLT_USER_DIR,getpid());
550 close(dlt_user.dlt_user_handle);
551 dlt_user.dlt_user_handle=DLT_FD_INIT;
556 #ifdef DLT_SHM_ENABLE
557 /* free shared memory */
558 dlt_shm_free_client(&dlt_user.dlt_shm);
561 if (dlt_user.dlt_log_handle!=-1)
563 /* close log file/output fifo to daemon */
564 close(dlt_user.dlt_log_handle);
565 dlt_user.dlt_log_handle = -1;
568 /* Ignore return value */
570 dlt_receiver_free(&(dlt_user.receiver));
573 /* Ignore return value */
575 dlt_buffer_free_dynamic(&(dlt_user.startup_buffer));
579 if (dlt_user.dlt_ll_ts)
581 for (i=0;i<dlt_user.dlt_ll_ts_max_num_entries;i++)
583 if (dlt_user.dlt_ll_ts[i].injection_table!=0)
585 free(dlt_user.dlt_ll_ts[i].injection_table);
586 dlt_user.dlt_ll_ts[i].injection_table = 0;
588 dlt_user.dlt_ll_ts[i].nrcallbacks = 0;
591 free(dlt_user.dlt_ll_ts);
592 dlt_user.dlt_ll_ts = 0;
593 dlt_user.dlt_ll_ts_max_num_entries = 0;
594 dlt_user.dlt_ll_ts_num_entries = 0;
598 char queue_name[NAME_MAX];
599 snprintf(queue_name,NAME_MAX, "%s.%d", DLT_MESSAGE_QUEUE_NAME, getpid());
602 * Ignore errors from these, to not to spam user if dlt_free
603 * is accidentally called multiple times.
605 mq_close(dlt_user.dlt_segmented_queue_write_handle);
606 mq_close(dlt_user.dlt_segmented_queue_read_handle);
607 mq_unlink(queue_name);
609 // allow the user app to do dlt_init() again.
610 // The flag is unset only to keep almost the same behaviour as before, on EntryNav
611 // This should be removed for other projects (see documentation of dlt_free()
612 dlt_user_freeing = 0;
617 int dlt_check_library_version(const char * user_major_version,const char * user_minor_version)
619 return dlt_user_check_library_version(user_major_version, user_minor_version);
622 int dlt_register_app(const char *appid, const char * description)
626 if (dlt_user_initialised==0)
634 if ((appid==0) || (appid[0]=='\0'))
639 /* check if application already registered */
640 /* if yes do not register again */
643 if(appid[0]==dlt_user.appID[0])
648 if(appid[0]==dlt_user.appID[0] &&
649 appid[1]==dlt_user.appID[1])
654 if(appid[0]==dlt_user.appID[0] &&
655 appid[1]==dlt_user.appID[1] &&
656 appid[2]==dlt_user.appID[2])
661 if(appid[0]==dlt_user.appID[0] &&
662 appid[1]==dlt_user.appID[1] &&
663 appid[2]==dlt_user.appID[2] &&
664 appid[3]==dlt_user.appID[3])
670 /* Store locally application id and application description */
671 dlt_set_id(dlt_user.appID, appid);
673 if (dlt_user.application_description!=0)
675 free(dlt_user.application_description);
678 dlt_user.application_description = 0;
682 size_t desc_len = strlen(description);
683 dlt_user.application_description= malloc(desc_len+1);
684 if (dlt_user.application_description){
685 strncpy(dlt_user.application_description, description, desc_len);
686 dlt_user.application_description[desc_len]='\0';
697 ret = dlt_user_log_send_register_application();
701 int dlt_register_context(DltContext *handle, const char *contextid, const char * description)
703 if (dlt_user_initialised==0)
713 if (dlt_user.appID[0]=='\0')
715 dlt_log(LOG_ERR, "no application registered!\n");
721 if ((contextid==0) || (contextid[0]=='\0'))
729 return dlt_register_context_ll_ts(handle, contextid, description, DLT_USER_LOG_LEVEL_NOT_SET, DLT_USER_TRACE_STATUS_NOT_SET);
732 int dlt_register_context_ll_ts(DltContext *handle, const char *contextid, const char * description, int loglevel, int tracestatus)
737 if (dlt_user_initialised==0)
747 if (dlt_user.appID[0]=='\0')
749 dlt_log(LOG_ERR, "no application registered!\n");
757 if ((contextid==0) || (contextid[0]=='\0'))
762 if ((loglevel<DLT_USER_LOG_LEVEL_NOT_SET) || (loglevel>DLT_LOG_VERBOSE) || (loglevel==DLT_LOG_DEFAULT))
767 if ((tracestatus<DLT_USER_TRACE_STATUS_NOT_SET) || (tracestatus>DLT_TRACE_STATUS_ON) || (tracestatus==DLT_TRACE_STATUS_DEFAULT))
772 if (dlt_user_log_init(handle, &log)==-1)
777 /* Reset message counter */
780 /* Store context id in log level/trace status field */
782 /* Check if already registered, else register context */
785 /* Check of double context registration removed */
786 /* Double registration is already checked by daemon */
788 /* Allocate or expand context array */
789 if (dlt_user.dlt_ll_ts == 0)
791 dlt_user.dlt_ll_ts = (dlt_ll_ts_type*) malloc(sizeof(dlt_ll_ts_type)*DLT_USER_CONTEXT_ALLOC_SIZE);
792 if (dlt_user.dlt_ll_ts==0)
798 dlt_user.dlt_ll_ts_max_num_entries = DLT_USER_CONTEXT_ALLOC_SIZE;
800 /* Initialize new entries */
801 for (i=0;i<dlt_user.dlt_ll_ts_max_num_entries;i++)
803 dlt_set_id(dlt_user.dlt_ll_ts[i].contextID,"");
805 /* At startup, logging and tracing is locally enabled */
806 /* the correct log level/status is set after received from daemon */
807 dlt_user.dlt_ll_ts[i].log_level = DLT_USER_INITIAL_LOG_LEVEL;
808 dlt_user.dlt_ll_ts[i].trace_status = DLT_USER_INITIAL_TRACE_STATUS;
810 dlt_user.dlt_ll_ts[i].log_level_ptr = 0;
811 dlt_user.dlt_ll_ts[i].trace_status_ptr = 0;
813 dlt_user.dlt_ll_ts[i].context_description = 0;
815 dlt_user.dlt_ll_ts[i].injection_table = 0;
816 dlt_user.dlt_ll_ts[i].nrcallbacks = 0;
821 if ((dlt_user.dlt_ll_ts_num_entries%DLT_USER_CONTEXT_ALLOC_SIZE)==0)
823 /* allocate memory in steps of DLT_USER_CONTEXT_ALLOC_SIZE, e.g. 500 */
824 dlt_ll_ts_type *old_ll_ts;
825 uint32_t old_max_entries;
827 old_ll_ts = dlt_user.dlt_ll_ts;
828 old_max_entries = dlt_user.dlt_ll_ts_max_num_entries;
830 dlt_user.dlt_ll_ts_max_num_entries = ((dlt_user.dlt_ll_ts_num_entries/DLT_USER_CONTEXT_ALLOC_SIZE)+1)*DLT_USER_CONTEXT_ALLOC_SIZE;
831 dlt_user.dlt_ll_ts = (dlt_ll_ts_type*) malloc(sizeof(dlt_ll_ts_type)*
832 dlt_user.dlt_ll_ts_max_num_entries);
833 if (dlt_user.dlt_ll_ts==0)
835 dlt_user.dlt_ll_ts = old_ll_ts;
836 dlt_user.dlt_ll_ts_max_num_entries = old_max_entries;
841 memcpy(dlt_user.dlt_ll_ts,old_ll_ts,sizeof(dlt_ll_ts_type)*dlt_user.dlt_ll_ts_num_entries);
844 /* Initialize new entries */
845 for (i=dlt_user.dlt_ll_ts_num_entries;i<dlt_user.dlt_ll_ts_max_num_entries;i++)
847 dlt_set_id(dlt_user.dlt_ll_ts[i].contextID,"");
849 /* At startup, logging and tracing is locally enabled */
850 /* the correct log level/status is set after received from daemon */
851 dlt_user.dlt_ll_ts[i].log_level = DLT_USER_INITIAL_LOG_LEVEL;
852 dlt_user.dlt_ll_ts[i].trace_status = DLT_USER_INITIAL_TRACE_STATUS;
854 dlt_user.dlt_ll_ts[i].log_level_ptr = 0;
855 dlt_user.dlt_ll_ts[i].trace_status_ptr = 0;
857 dlt_user.dlt_ll_ts[i].context_description = 0;
859 dlt_user.dlt_ll_ts[i].injection_table = 0;
860 dlt_user.dlt_ll_ts[i].nrcallbacks = 0;
865 /* Store locally context id and context description */
866 dlt_set_id(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].contextID, contextid);
868 if (dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description!=0)
870 free(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description);
873 dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description = 0;
877 size_t desc_len = strlen(description);
878 dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description = malloc(desc_len+1);
879 if(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description == 0)
885 strncpy(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description, description, desc_len);
886 dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description[desc_len]='\0';
889 if(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr == 0)
891 dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr = malloc(sizeof(int8_t));
892 if(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr == 0)
898 if(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr == 0)
900 dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr = malloc(sizeof(int8_t));
901 if(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr == 0)
908 if (loglevel!=DLT_USER_LOG_LEVEL_NOT_SET)
910 dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level = loglevel;
913 if (tracestatus!=DLT_USER_TRACE_STATUS_NOT_SET)
915 dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status = tracestatus;
918 /* Prepare transfer struct */
919 //dlt_set_id(log->appID, dlt_user.appID);
920 dlt_set_id(handle->contextID, contextid);
921 handle->log_level_pos = dlt_user.dlt_ll_ts_num_entries;
923 handle->log_level_ptr = dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr;
924 handle->trace_status_ptr = dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr;
926 log.context_description = dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].context_description;
928 *(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level_ptr) = dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].log_level;
929 *(dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status_ptr) = dlt_user.dlt_ll_ts[dlt_user.dlt_ll_ts_num_entries].trace_status = tracestatus;
931 if (loglevel!=DLT_USER_LOG_LEVEL_NOT_SET)
933 log.log_level = loglevel;
937 log.log_level = DLT_USER_LOG_LEVEL_NOT_SET;
940 if (tracestatus!=DLT_USER_TRACE_STATUS_NOT_SET)
942 log.trace_status = tracestatus;
946 log.trace_status = DLT_USER_TRACE_STATUS_NOT_SET;
949 dlt_user.dlt_ll_ts_num_entries++;
953 return dlt_user_log_send_register_context(&log);
956 int dlt_unregister_app(void)
960 if (dlt_user_initialised==0)
965 /* Inform daemon to unregister application and all of its contexts */
966 ret = dlt_user_log_send_unregister_application();
970 /* Clear and free local stored application information */
971 dlt_set_id(dlt_user.appID, "");
973 if (dlt_user.application_description!=0)
975 free(dlt_user.application_description);
978 dlt_user.application_description = 0;
985 int dlt_unregister_context(DltContext *handle)
990 if (dlt_user_initialised==0)
995 if (dlt_user_log_init(handle, &log) == -1)
1002 handle->log_level_ptr = 0;
1003 handle->trace_status_ptr = 0;
1005 if (dlt_user.dlt_ll_ts)
1007 /* Clear and free local stored context information */
1008 dlt_set_id(dlt_user.dlt_ll_ts[handle->log_level_pos].contextID, "");
1010 dlt_user.dlt_ll_ts[handle->log_level_pos].log_level = DLT_USER_INITIAL_LOG_LEVEL;
1011 dlt_user.dlt_ll_ts[handle->log_level_pos].trace_status = DLT_USER_INITIAL_TRACE_STATUS;
1013 if (dlt_user.dlt_ll_ts[handle->log_level_pos].context_description!=0)
1015 free(dlt_user.dlt_ll_ts[handle->log_level_pos].context_description);
1018 if (dlt_user.dlt_ll_ts[handle->log_level_pos].log_level_ptr!=0)
1020 free(dlt_user.dlt_ll_ts[handle->log_level_pos].log_level_ptr);
1021 dlt_user.dlt_ll_ts[handle->log_level_pos].log_level_ptr = 0;
1024 if (dlt_user.dlt_ll_ts[handle->log_level_pos].trace_status_ptr!=0)
1026 free(dlt_user.dlt_ll_ts[handle->log_level_pos].trace_status_ptr);
1027 dlt_user.dlt_ll_ts[handle->log_level_pos].trace_status_ptr = 0;
1030 dlt_user.dlt_ll_ts[handle->log_level_pos].context_description = 0;
1032 if (dlt_user.dlt_ll_ts[handle->log_level_pos].injection_table)
1034 free(dlt_user.dlt_ll_ts[handle->log_level_pos].injection_table);
1035 dlt_user.dlt_ll_ts[handle->log_level_pos].injection_table = 0;
1038 dlt_user.dlt_ll_ts[handle->log_level_pos].nrcallbacks = 0;
1043 /* Inform daemon to unregister context */
1044 ret = dlt_user_log_send_unregister_context(&log);
1049 int dlt_set_application_ll_ts_limit(DltLogLevelType loglevel, DltTraceStatusType tracestatus)
1054 if (dlt_user_initialised==0)
1062 /* Removed because of DltLogLevelType and DltTraceStatusType
1064 if ((loglevel<DLT_LOG_DEFAULT) || (loglevel>DLT_LOG_VERBOSE))
1069 if ((tracestatus<DLT_TRACE_STATUS_DEFAULT) || (tracestatus>DLT_TRACE_STATUS_ON))
1074 if (dlt_user.dlt_ll_ts==0)
1082 if (dlt_user.dlt_ll_ts==0)
1088 /* Update local structures */
1089 for (i=0; i<dlt_user.dlt_ll_ts_num_entries;i++)
1091 dlt_user.dlt_ll_ts[i].log_level = loglevel;
1092 dlt_user.dlt_ll_ts[i].trace_status = tracestatus;
1093 if(dlt_user.dlt_ll_ts[i].log_level_ptr)
1094 *(dlt_user.dlt_ll_ts[i].log_level_ptr) = loglevel;
1095 if(dlt_user.dlt_ll_ts[i].trace_status_ptr)
1096 *(dlt_user.dlt_ll_ts[i].trace_status_ptr) = tracestatus;
1101 /* Inform DLT server about update */
1102 ret = dlt_send_app_ll_ts_limit(dlt_user.appID, loglevel, tracestatus);
1107 int dlt_get_log_state()
1109 return dlt_user.log_state;
1112 int dlt_set_log_mode(DltUserLogMode mode)
1114 if (dlt_user_initialised==0)
1122 return dlt_user_log_send_log_mode(mode);
1125 int dlt_forward_msg(void *msgdata,size_t size)
1127 DltUserHeader userheader;
1130 if ((msgdata==0) || (size==0))
1135 if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_LOG)==-1)
1137 /* Type of internal user message; same value for Trace messages */
1141 if (dlt_user.dlt_is_file)
1144 ret = dlt_user_log_out2(dlt_user.dlt_log_handle, msgdata, size, 0, 0);
1145 return ((ret==DLT_RETURN_OK)?0:-1);
1149 /* Reattach to daemon if neccesary */
1150 dlt_user_log_reattach_to_daemon();
1152 if (dlt_user.overflow_counter)
1154 if (dlt_user_log_send_overflow()==0)
1156 snprintf(str,DLT_USER_BUFFER_LENGTH,"Buffer full! %u messages discarded!\n",dlt_user.overflow_counter);
1157 dlt_log(LOG_ERR, str);
1158 dlt_user.overflow_counter=0; }
1162 ret = dlt_user_log_out3(dlt_user.dlt_log_handle,
1163 &(userheader), sizeof(DltUserHeader),
1164 msgdata, size, 0, 0);
1166 /* store message in ringbuffer, if an error has occured */
1167 if (ret!=DLT_RETURN_OK)
1171 if (dlt_buffer_push3(&(dlt_user.startup_buffer),
1172 (unsigned char *)&(userheader), sizeof(DltUserHeader),
1173 msgdata, size, 0, 0)==-1)
1175 if(dlt_user.overflow_counter==0)
1177 dlt_log(LOG_ERR,"Buffer full! First message discarded!\n");
1179 ret = DLT_RETURN_BUFFER_FULL;
1184 if(dlt_user_queue_resend() < 0 && dlt_user.dlt_log_handle >= 0)
1186 ;//dlt_log(LOG_WARNING, "dlt_forward_msg: Failed to queue resending.\n");
1192 case DLT_RETURN_BUFFER_FULL:
1195 dlt_user.overflow_counter += 1;
1198 case DLT_RETURN_PIPE_FULL:
1200 /* data could not be written */
1203 case DLT_RETURN_PIPE_ERROR:
1205 /* handle not open or pipe error */
1206 close(dlt_user.dlt_log_handle);
1207 dlt_user.dlt_log_handle = -1;
1211 case DLT_RETURN_ERROR:
1213 /* other error condition */
1222 /* This case should not occur */
1231 /* ********************************************************************************************* */
1233 inline int dlt_user_log_write_start(DltContext *handle, DltContextData *log,DltLogLevelType loglevel)
1235 return dlt_user_log_write_start_id(handle,log,loglevel,DLT_USER_DEFAULT_MSGID);
1238 int dlt_user_log_write_start_id(DltContext *handle, DltContextData *log,DltLogLevelType loglevel, uint32_t messageid)
1240 if(dlt_user_initialised==0)
1252 if (dlt_user_log_init(handle, log)==-1)
1257 if (dlt_user.dlt_ll_ts==0)
1262 if (handle->log_level_ptr && (loglevel<=(int)*(handle->log_level_ptr) ) && (loglevel!=0))
1265 log->log_level = loglevel;
1267 /* In non-verbose mode, insert message id */
1268 if (dlt_user.verbose_mode==0)
1270 if ((sizeof(uint32_t))>DLT_USER_BUF_MAX_SIZE)
1274 /* Write message id */
1275 memcpy(log->buffer,&(messageid),sizeof(uint32_t));
1276 log->size = sizeof(uint32_t);
1278 /* as the message id is part of each message in non-verbose mode,
1279 it doesn't increment the argument counter in extended header (if used) */
1288 int dlt_user_log_write_finish(DltContextData *log)
1295 return dlt_user_log_send_log(log, DLT_TYPE_LOG) < 0 ? -1 : 0;
1298 int dlt_user_log_write_raw(DltContextData *log,void *data,uint16_t length)
1308 if ((log->size+length+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
1313 if (dlt_user.verbose_mode)
1315 if ((log->size+length+sizeof(uint32_t)+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
1320 /* Transmit type information */
1321 type_info = DLT_TYPE_INFO_RAWD;
1323 memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t));
1324 log->size += sizeof(uint32_t);
1328 /* First transmit length of raw data, then the raw data itself */
1329 arg_size = (uint16_t)length;
1331 memcpy((log->buffer)+log->size,&(arg_size),sizeof(uint16_t));
1332 log->size += sizeof(uint16_t);
1334 memcpy((log->buffer)+log->size,data,arg_size);
1335 log->size += arg_size;
1342 int dlt_user_log_write_float32(DltContextData *log, float32_t data)
1351 if (sizeof(float32_t)!=4)
1356 if ((log->size+sizeof(float32_t))>DLT_USER_BUF_MAX_SIZE)
1361 if (dlt_user.verbose_mode)
1363 if ((log->size+sizeof(uint32_t)+sizeof(float32_t))>DLT_USER_BUF_MAX_SIZE)
1368 type_info = DLT_TYPE_INFO_FLOA | DLT_TYLE_32BIT;
1370 memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t));
1371 log->size += sizeof(uint32_t);
1374 memcpy((log->buffer)+log->size,&data, sizeof(float32_t));
1375 log->size += sizeof(float32_t);
1382 int dlt_user_log_write_float64(DltContextData *log, float64_t data)
1391 if (sizeof(float64_t)!=8)
1396 if ((log->size+sizeof(float64_t))>DLT_USER_BUF_MAX_SIZE)
1401 if (dlt_user.verbose_mode)
1403 if ((log->size+sizeof(uint32_t)+sizeof(float64_t))>DLT_USER_BUF_MAX_SIZE)
1408 type_info = DLT_TYPE_INFO_FLOA | DLT_TYLE_64BIT;
1410 memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t));
1411 log->size += sizeof(uint32_t);
1414 memcpy((log->buffer)+log->size,&data, sizeof(float64_t));
1415 log->size += sizeof(float64_t);
1422 int dlt_user_log_write_uint( DltContextData *log, unsigned int data)
1429 switch (sizeof(unsigned int))
1433 return dlt_user_log_write_uint8(log, (uint8_t)data);
1438 return dlt_user_log_write_uint16(log, (uint16_t)data);
1443 return dlt_user_log_write_uint32(log, (uint32_t)data);
1448 return dlt_user_log_write_uint64(log, (uint64_t)data);
1461 int dlt_user_log_write_uint8(DltContextData *log, uint8_t data)
1470 if ((log->size+sizeof(uint8_t))>DLT_USER_BUF_MAX_SIZE)
1475 if (dlt_user.verbose_mode)
1477 if ((log->size+sizeof(uint32_t)+sizeof(uint8_t))>DLT_USER_BUF_MAX_SIZE)
1482 type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_8BIT;
1484 memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t));
1485 log->size += sizeof(uint32_t);
1488 memcpy((log->buffer)+log->size,&data,sizeof(uint8_t));
1489 log->size += sizeof(uint8_t);
1496 int dlt_user_log_write_uint16(DltContextData *log, uint16_t data)
1505 if ((log->size+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
1510 if (dlt_user.verbose_mode)
1512 if ((log->size+sizeof(uint32_t)+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
1517 type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_16BIT;
1519 memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t));
1520 log->size += sizeof(uint32_t);
1523 memcpy((log->buffer)+log->size,&data,sizeof(uint16_t));
1524 log->size += sizeof(uint16_t);
1531 int dlt_user_log_write_uint32(DltContextData *log, uint32_t data)
1540 if ((log->size+sizeof(uint32_t))>DLT_USER_BUF_MAX_SIZE)
1545 if (dlt_user.verbose_mode)
1547 if ((log->size+sizeof(uint32_t)+sizeof(uint32_t))>DLT_USER_BUF_MAX_SIZE)
1552 type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_32BIT;
1554 memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t));
1555 log->size += sizeof(uint32_t);
1558 memcpy((log->buffer)+log->size,&data, sizeof(uint32_t));
1559 log->size += sizeof(uint32_t);
1566 int dlt_user_log_write_uint64(DltContextData *log, uint64_t data)
1575 if ((log->size+sizeof(uint64_t))>DLT_USER_BUF_MAX_SIZE)
1580 if (dlt_user.verbose_mode)
1582 if ((log->size+sizeof(uint32_t)+sizeof(uint64_t))>DLT_USER_BUF_MAX_SIZE)
1587 type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_64BIT;
1589 memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t));
1590 log->size +=sizeof(uint32_t);
1593 memcpy((log->buffer)+log->size,&data,sizeof(uint64_t));
1594 log->size += sizeof(uint64_t);
1601 int dlt_user_log_write_int(DltContextData *log, int data)
1608 switch (sizeof(int))
1612 return dlt_user_log_write_int8(log, (int8_t)data);
1617 return dlt_user_log_write_int16(log, (int16_t)data);
1622 return dlt_user_log_write_int32(log, (int32_t)data);
1627 return dlt_user_log_write_int64(log, (int64_t)data);
1640 int dlt_user_log_write_int8(DltContextData *log, int8_t data)
1649 if ((log->size+sizeof(int8_t))>DLT_USER_BUF_MAX_SIZE)
1654 if (dlt_user.verbose_mode)
1656 if ((log->size+sizeof(uint32_t)+sizeof(int8_t))>DLT_USER_BUF_MAX_SIZE)
1661 type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_8BIT;
1663 memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t));
1664 log->size += sizeof(uint32_t);
1667 memcpy((log->buffer)+log->size,&data,sizeof(int8_t));
1668 log->size += sizeof(int8_t);
1675 int dlt_user_log_write_int16(DltContextData *log, int16_t data)
1684 if ((log->size+sizeof(int16_t))>DLT_USER_BUF_MAX_SIZE)
1689 if (dlt_user.verbose_mode)
1691 if ((log->size+sizeof(uint32_t)+sizeof(int16_t))>DLT_USER_BUF_MAX_SIZE)
1696 type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_16BIT;
1698 memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t));
1699 log->size += sizeof(uint32_t);
1702 memcpy((log->buffer)+log->size,&data,sizeof(int16_t));
1703 log->size += sizeof(int16_t);
1710 int dlt_user_log_write_int32(DltContextData *log, int32_t data)
1719 if ((log->size+sizeof(int32_t))>DLT_USER_BUF_MAX_SIZE)
1724 if (dlt_user.verbose_mode)
1726 if ((log->size+sizeof(uint32_t)+sizeof(int32_t))>DLT_USER_BUF_MAX_SIZE)
1731 type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_32BIT;
1733 memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t));
1734 log->size += sizeof(uint32_t);
1737 memcpy((log->buffer)+log->size,&data, sizeof(int32_t));
1738 log->size += sizeof(int32_t);
1745 int dlt_user_log_write_int64(DltContextData *log, int64_t data)
1754 if ((log->size+sizeof(int64_t))>DLT_USER_BUF_MAX_SIZE)
1759 if (dlt_user.verbose_mode)
1761 if ((log->size+sizeof(uint32_t)+sizeof(int64_t))>DLT_USER_BUF_MAX_SIZE)
1766 type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_64BIT;
1768 memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t));
1769 log->size += sizeof(uint32_t);
1772 memcpy((log->buffer)+log->size,&data,sizeof(int64_t));
1773 log->size += sizeof(int64_t);
1780 int dlt_user_log_write_bool(DltContextData *log, uint8_t data)
1789 if ((log->size+sizeof(uint8_t))>DLT_USER_BUF_MAX_SIZE)
1794 if (dlt_user.verbose_mode)
1796 if ((log->size+sizeof(uint32_t)+sizeof(uint8_t))>DLT_USER_BUF_MAX_SIZE)
1801 type_info = DLT_TYPE_INFO_BOOL;
1803 memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t));
1804 log->size += sizeof(uint32_t);
1807 memcpy((log->buffer)+log->size,&data,sizeof(uint8_t));
1808 log->size += sizeof(uint8_t);
1815 int dlt_user_log_write_string(DltContextData *log, const char *text)
1820 if ((log==0) || (text==0))
1825 if ((log->size+(strlen(text)+1)+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
1830 if (dlt_user.verbose_mode)
1832 if ((log->size+(strlen(text)+1)+sizeof(uint32_t)+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
1837 type_info = DLT_TYPE_INFO_STRG | DLT_SCOD_ASCII;
1839 memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t));
1840 log->size += sizeof(uint32_t);
1843 arg_size = strlen(text) + 1;
1845 memcpy((log->buffer)+log->size,&(arg_size),sizeof(uint16_t));
1846 log->size += sizeof(uint16_t);
1848 memcpy((log->buffer)+log->size,text,arg_size);
1849 log->size += arg_size;
1856 int dlt_user_log_write_utf8_string(DltContextData *log, const char *text)
1861 if ((log==0) || (text==0))
1866 arg_size = strlen(text)+1;
1868 if ((log->size+arg_size+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
1873 if (dlt_user.verbose_mode)
1875 if ((log->size+arg_size+sizeof(uint32_t)+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
1880 type_info = DLT_TYPE_INFO_STRG | DLT_SCOD_UTF8;
1882 memcpy((log->buffer)+log->size,&(type_info),sizeof(uint32_t));
1883 log->size += sizeof(uint32_t);
1886 arg_size = strlen(text) + 1;
1888 memcpy((log->buffer)+log->size,&(arg_size),sizeof(uint16_t));
1889 log->size += sizeof(uint16_t);
1891 memcpy((log->buffer)+log->size,text,arg_size);
1892 log->size += arg_size;
1899 int dlt_register_injection_callback(DltContext *handle, uint32_t service_id,
1900 int (*dlt_injection_callback)(uint32_t service_id, void *data, uint32_t length))
1906 DltUserInjectionCallback *old;
1913 if (dlt_user_log_init(handle, &log)==-1)
1918 if (service_id<DLT_USER_INJECTION_MIN)
1922 /* This function doesn't make sense storing to local file is choosen;
1923 so terminate this function */
1924 if (dlt_user.dlt_is_file)
1931 if (dlt_user.dlt_ll_ts==0)
1937 /* Insert callback in corresponding table */
1938 i=handle->log_level_pos;
1940 /* Insert each service_id only once */
1941 for (k=0;k<dlt_user.dlt_ll_ts[i].nrcallbacks;k++)
1943 if ((dlt_user.dlt_ll_ts[i].injection_table) &&
1944 (dlt_user.dlt_ll_ts[i].injection_table[k].service_id == service_id))
1957 j=dlt_user.dlt_ll_ts[i].nrcallbacks;
1959 /* Allocate or expand injection table */
1960 if (dlt_user.dlt_ll_ts[i].injection_table == 0)
1962 dlt_user.dlt_ll_ts[i].injection_table = (DltUserInjectionCallback*) malloc(sizeof(DltUserInjectionCallback));
1963 if(dlt_user.dlt_ll_ts[i].injection_table == 0)
1971 old = dlt_user.dlt_ll_ts[i].injection_table;
1972 dlt_user.dlt_ll_ts[i].injection_table = (DltUserInjectionCallback*) malloc(sizeof(DltUserInjectionCallback)*(j+1));
1973 if(dlt_user.dlt_ll_ts[i].injection_table == 0)
1975 dlt_user.dlt_ll_ts[i].injection_table = old;
1979 memcpy(dlt_user.dlt_ll_ts[i].injection_table,old,sizeof(DltUserInjectionCallback)*j);
1983 dlt_user.dlt_ll_ts[i].nrcallbacks++;
1986 /* Store service_id and corresponding function pointer for callback function */
1987 dlt_user.dlt_ll_ts[i].injection_table[j].service_id = service_id;
1988 dlt_user.dlt_ll_ts[i].injection_table[j].injection_callback = dlt_injection_callback;
2001 int total_size, used_size;
2002 dlt_user_check_buffer(&total_size, &used_size);
2004 if((total_size - used_size) < (total_size/2))
2012 * Send the start of a segment chain.
2013 * Returns -1 on failure
2015 int dlt_user_trace_network_segmented_start(uint16_t *id, DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len)
2026 if (dlt_user_log_init(handle, &log)==-1)
2032 if (dlt_user.dlt_ll_ts==0)
2037 if (handle->trace_status_ptr && *(handle->trace_status_ptr)==DLT_TRACE_STATUS_ON)
2041 log.trace_status = nw_trace_type;
2044 gettimeofday(&tv, NULL);
2047 /* Write identifier */
2048 if(dlt_user_log_write_string(&log, "NWST") < 0)
2053 /* Write stream handle */
2054 if(dlt_user_log_write_uint16(&log, *id) < 0)
2060 if(dlt_user_log_write_raw(&log, header, header_len) < 0)
2065 /* Write size of payload */
2066 if(dlt_user_log_write_uint16(&log, payload_len) < 0)
2071 /* Write expected segment count */
2072 uint16_t segment_count = payload_len/DLT_MAX_TRACE_SEGMENT_SIZE+1;
2074 /* If segments align perfectly with segment size, avoid sending empty segment */
2075 if((payload_len % DLT_MAX_TRACE_SEGMENT_SIZE) == 0)
2080 if(dlt_user_log_write_uint16(&log, segment_count) < 0)
2085 /* Write length of one segment */
2086 if(dlt_user_log_write_uint16(&log, DLT_MAX_TRACE_SEGMENT_SIZE) < 0)
2092 return dlt_user_log_send_log(&log, DLT_TYPE_NW_TRACE);
2097 int dlt_user_trace_network_segmented_segment(uint16_t id, DltContext *handle, DltNetworkTraceType nw_trace_type, int sequence, uint16_t payload_len, void *payload)
2099 while(check_buffer() < 0)
2101 usleep(1000*50); // Wait 50ms
2102 dlt_user_log_resend_buffer();
2112 if (dlt_user_log_init(handle, &log)==-1)
2117 if (dlt_user.dlt_ll_ts==0)
2122 if (handle->trace_status_ptr && *(handle->trace_status_ptr)==DLT_TRACE_STATUS_ON)
2126 log.trace_status = nw_trace_type;
2129 /* Write identifier */
2130 if(dlt_user_log_write_string(&log, "NWCH") < 0)
2135 /* Write stream handle */
2136 if(dlt_user_log_write_uint16(&log, id) < 0)
2141 /* Write segment sequence number */
2142 if(dlt_user_log_write_uint16(&log, sequence) < 0)
2148 if(dlt_user_log_write_raw(&log, payload, payload_len) < 0)
2154 return dlt_user_log_send_log(&log, DLT_TYPE_NW_TRACE);
2157 /* Allow other threads to log between chunks */
2162 int dlt_user_trace_network_segmented_end(uint16_t id, DltContext *handle, DltNetworkTraceType nw_trace_type)
2171 if (dlt_user_log_init(handle, &log)==-1)
2178 if (dlt_user.dlt_ll_ts==0)
2183 if (handle->trace_status_ptr && *(handle->trace_status_ptr)==DLT_TRACE_STATUS_ON)
2187 log.trace_status = nw_trace_type;
2190 /* Write identifier */
2191 if(dlt_user_log_write_string(&log, "NWEN") < 0)
2196 /* Write stream handle */
2197 if(dlt_user_log_write_uint(&log, id) < 0)
2203 return dlt_user_log_send_log(&log, DLT_TYPE_NW_TRACE);
2209 void dlt_user_trace_network_segmented_thread(void *unused)
2211 /* Unused on purpose. */
2214 prctl(PR_SET_NAME, "dlt_segmented", 0, 0, 0);
2217 s_segmented_data *data;
2221 // Wait until message queue is initialized
2222 pthread_mutex_lock(&mq_mutex);
2223 if(dlt_user.dlt_segmented_queue_read_handle < 0)
2225 pthread_cond_wait(&mq_init_condition, &mq_mutex);
2227 pthread_mutex_unlock(&mq_mutex);
2229 ssize_t read = mq_receive(dlt_user.dlt_segmented_queue_read_handle, (char *)&data,
2230 sizeof(s_segmented_data * ), NULL);
2232 if(read != sizeof(s_segmented_data *))
2236 snprintf(str,254,"NWTSegmented: Error while reading queue: %s \n",strerror(errno));
2237 dlt_log(LOG_CRIT, str);
2241 /* Indicator just to try to flush the buffer */
2242 if(data->payload_len == DLT_DELAYED_RESEND_INDICATOR_PATTERN)
2244 // Sleep 100ms, to allow other process to read FIFO
2246 if(dlt_user_log_resend_buffer() < 0)
2248 // Requeue if still not empty
2249 if ( dlt_user_queue_resend() < 0 )
2251 //dlt_log(LOG_WARNING, "Failed to queue resending in dlt_user_trace_network_segmented_thread.\n");
2258 dlt_user_trace_network_segmented_thread_segmenter(data);
2260 /* Send the end message */
2261 DltReturnValue err = dlt_user_trace_network_segmented_end(data->id, data->handle, data->nw_trace_type);
2262 if(err == DLT_RETURN_BUFFER_FULL || err == DLT_RETURN_ERROR)
2264 dlt_log(LOG_ERR,"NWTSegmented: Could not send end segment.\n");
2267 /* Free resources */
2269 free(data->payload);
2274 void dlt_user_trace_network_segmented_thread_segmenter(s_segmented_data *data)
2276 /* Segment the data and send the chunks */
2278 uint16_t offset = 0;
2279 uint16_t sequence = 0;
2283 if(offset + DLT_MAX_TRACE_SEGMENT_SIZE > data->payload_len)
2285 len = data->payload_len - offset;
2289 len = DLT_MAX_TRACE_SEGMENT_SIZE;
2291 /* If payload size aligns perfectly with segment size, avoid sending empty segment */
2297 ptr = data->payload + offset;
2298 DltReturnValue err = dlt_user_trace_network_segmented_segment(data->id, data->handle, data->nw_trace_type, sequence++, len, ptr);
2299 if(err == DLT_RETURN_BUFFER_FULL || err == DLT_RETURN_ERROR)
2301 dlt_log(LOG_ERR,"NWTSegmented: Could not send segment. Aborting.\n");
2305 }while(ptr < data->payload + data->payload_len);
2309 int dlt_user_trace_network_segmented(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload)
2311 /* Send as normal trace if possible */
2312 if(header_len+payload_len+sizeof(uint16_t) < DLT_USER_BUF_MAX_SIZE) {
2313 return dlt_user_trace_network(handle, nw_trace_type, header_len, header, payload_len, payload);
2316 /* Allocate Memory */
2317 s_segmented_data *thread_data = malloc(sizeof(s_segmented_data));
2318 if(thread_data == NULL)
2322 thread_data->header = malloc(header_len);
2323 if(thread_data->header == NULL)
2328 thread_data->payload = malloc(payload_len);
2329 if(thread_data->payload == NULL)
2331 free(thread_data->header);
2337 thread_data->handle = handle;
2338 thread_data->nw_trace_type = nw_trace_type;
2339 thread_data->header_len = header_len;
2340 memcpy(thread_data->header, header, header_len);
2341 thread_data->payload_len = payload_len;
2342 memcpy(thread_data->payload, payload, payload_len);
2344 /* Send start message */
2345 DltReturnValue err = dlt_user_trace_network_segmented_start(&(thread_data->id),
2346 thread_data->handle, thread_data->nw_trace_type,
2347 thread_data->header_len, thread_data->header,
2348 thread_data->payload_len);
2349 if(err == DLT_RETURN_BUFFER_FULL || err == DLT_RETURN_ERROR)
2351 dlt_log(LOG_ERR,"NWTSegmented: Could not send start segment. Aborting.\n");
2352 free(thread_data->header);
2353 free(thread_data->payload);
2358 /* Open queue if it is not open */
2359 if(dlt_init_message_queue() < 0)
2361 dlt_log(LOG_ERR, "NWTSegmented: Could not open queue.\n");
2362 free(thread_data->header);
2363 free(thread_data->payload);
2370 if(mq_send(dlt_user.dlt_segmented_queue_write_handle,
2371 (char *)&thread_data, sizeof(s_segmented_data *), 1) < 0)
2375 dlt_log(LOG_ERR, "NWTSegmented: Queue full. Message discarded.\n");
2377 free(thread_data->header);
2378 free(thread_data->payload);
2381 snprintf(str,255,"NWTSegmented: Could not write into queue: %s \n",strerror(errno));
2382 dlt_log(LOG_CRIT, str);
2386 //thread_data will be freed by the receiver function
2387 //coverity[leaked_storage]
2391 int dlt_user_trace_network(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload)
2393 return dlt_user_trace_network_truncated(handle, nw_trace_type, header_len, header, payload_len, payload, 1);
2396 int dlt_user_trace_network_truncated(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload, int allow_truncate)
2400 if (dlt_user_initialised==0)
2408 if (dlt_user_log_init(handle, &log)==-1)
2418 /* Commented out because of DltNetworkTraceType:
2420 if ((nw_trace_type<=0) || (nw_trace_type>0x15))
2427 if (dlt_user.dlt_ll_ts==0)
2432 if (handle->trace_status_ptr && *(handle->trace_status_ptr)==DLT_TRACE_STATUS_ON)
2436 log.trace_status = nw_trace_type;
2444 /* If truncation is allowed, check if we must do it */
2445 if(allow_truncate > 0 && (header_len+payload_len+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
2447 /* Identify as truncated */
2448 if(dlt_user_log_write_string(&log, "NWTR") < 0)
2453 /* Write header and its length */
2454 if (dlt_user_log_write_raw(&log, header, header_len) < 0)
2459 /* Write original size of payload */
2460 if(dlt_user_log_write_uint16(&log, payload_len) < 0)
2466 * Calculate maximum avaialble space in sending buffer after headers.
2469 int truncated_payload_len = DLT_USER_BUF_MAX_SIZE -
2470 log.size - sizeof(uint16_t) - sizeof(uint32_t);
2472 /* Write truncated payload */
2473 if (dlt_user_log_write_raw(&log, payload, truncated_payload_len) < 0)
2478 else /* Truncation not allowed or data short enough */
2480 /* Write header and its length */
2481 if (dlt_user_log_write_raw(&log, header, header_len)==-1)
2491 /* Write payload and its length */
2492 if (dlt_user_log_write_raw(&log, payload, payload_len)==-1)
2499 return dlt_user_log_send_log(&log, DLT_TYPE_NW_TRACE);
2505 int dlt_log_string(DltContext *handle,DltLogLevelType loglevel, const char *text)
2509 if (dlt_user.verbose_mode==0)
2514 if ((handle==0) || (text==0))
2519 if (dlt_user_log_write_start(handle,&log,loglevel)>0)
2521 if (dlt_user_log_write_string(&log,text)==-1)
2525 if (dlt_user_log_write_finish(&log)==-1)
2534 int dlt_log_string_int(DltContext *handle,DltLogLevelType loglevel, const char *text, int data)
2538 if (dlt_user.verbose_mode==0)
2543 if ((handle==0) || (text==0))
2548 if (dlt_user_log_write_start(handle,&log,loglevel)>0)
2550 if (dlt_user_log_write_string(&log,text)==-1)
2554 if (dlt_user_log_write_int(&log,data)==-1)
2558 if (dlt_user_log_write_finish(&log)==-1)
2567 int dlt_log_string_uint(DltContext *handle,DltLogLevelType loglevel, const char *text, unsigned int data)
2571 if (dlt_user.verbose_mode==0)
2576 if ((handle==0) || (text==0))
2581 if (dlt_user_log_write_start(handle,&log,loglevel)>0)
2583 if (dlt_user_log_write_string(&log,text)==-1)
2587 if (dlt_user_log_write_uint(&log,data)==-1)
2591 if (dlt_user_log_write_finish(&log)==-1)
2600 int dlt_log_int(DltContext *handle,DltLogLevelType loglevel, int data)
2604 if (dlt_user.verbose_mode==0)
2614 if (dlt_user_log_write_start(handle,&log,loglevel)>0)
2616 if (dlt_user_log_write_int(&log,data)==-1)
2620 if (dlt_user_log_write_finish(&log)==-1)
2629 int dlt_log_uint(DltContext *handle,DltLogLevelType loglevel, unsigned int data)
2633 if (dlt_user.verbose_mode==0)
2643 if (dlt_user_log_write_start(handle,&log,loglevel)>0)
2645 if (dlt_user_log_write_uint(&log,data)==-1)
2649 if (dlt_user_log_write_finish(&log)==-1)
2658 int dlt_log_raw(DltContext *handle,DltLogLevelType loglevel, void *data,uint16_t length)
2662 if (dlt_user.verbose_mode==0)
2672 if (dlt_user_log_write_start(handle,&log,loglevel)>0)
2674 if (dlt_user_log_write_raw(&log,data,length)==-1)
2678 if (dlt_user_log_write_finish(&log)==-1)
2687 int dlt_verbose_mode(void)
2689 if (dlt_user_initialised==0)
2697 /* Switch to verbose mode */
2698 dlt_user.verbose_mode = 1;
2703 int dlt_nonverbose_mode(void)
2705 if (dlt_user_initialised==0)
2713 /* Switch to non-verbose mode */
2714 dlt_user.verbose_mode = 0;
2719 int dlt_use_extended_header_for_non_verbose(int8_t use_extende_header_for_non_verbose)
2721 if (dlt_user_initialised==0)
2729 /* Set use_extende_header_for_non_verbose */
2730 dlt_user.use_extende_header_for_non_verbose = use_extende_header_for_non_verbose;
2735 int dlt_with_session_id(int8_t with_session_id)
2737 if (dlt_user_initialised==0)
2745 /* Set use_extende_header_for_non_verbose */
2746 dlt_user.with_session_id = with_session_id;
2751 int dlt_with_timestamp(int8_t with_timestamp)
2753 if (dlt_user_initialised==0)
2761 /* Set with_timestamp */
2762 dlt_user.with_timestamp = with_timestamp;
2767 int dlt_with_ecu_id(int8_t with_ecu_id)
2769 if (dlt_user_initialised==0)
2777 /* Set with_timestamp */
2778 dlt_user.with_ecu_id = with_ecu_id;
2783 int dlt_enable_local_print(void)
2785 if (dlt_user_initialised==0)
2793 dlt_user.enable_local_print = 1;
2798 int dlt_disable_local_print(void)
2800 if (dlt_user_initialised==0)
2808 dlt_user.enable_local_print = 0;
2813 void dlt_user_receiverthread_function(__attribute__((unused)) void *ptr)
2816 prctl(PR_SET_NAME, "dlt_receiver", 0, 0, 0);
2820 /* Check for new messages from DLT daemon */
2821 if (dlt_user_log_check_user_message()==-1)
2823 /* Critical error */
2824 dlt_log(LOG_CRIT,"Receiver thread encountered error condition\n");
2827 usleep(DLT_USER_RECEIVE_DELAY); /* delay */
2831 /* Private functions of user library */
2833 int dlt_user_log_init(DltContext *handle, DltContextData *log)
2835 if (dlt_user_initialised==0)
2843 log->handle = handle;
2848 int dlt_user_queue_resend(void)
2850 static unsigned char dlt_user_queue_resend_error_counter = 0;
2852 if(dlt_user.dlt_log_handle < 0)
2854 // Fail silenty. FIFO is not open yet
2858 * Ask segmented thread to try emptying the buffer soon.
2859 * This will be freed in dlt_user_trace_network_segmented_thread
2861 s_segmented_data *resend_data = malloc(sizeof(s_segmented_data));
2863 if (NULL == resend_data)
2868 resend_data->payload_len = DLT_DELAYED_RESEND_INDICATOR_PATTERN;
2872 /* Open queue if it is not open */
2873 if(dlt_init_message_queue() < 0)
2875 if(!dlt_user_queue_resend_error_counter)
2877 // log error only when problem occurred first time
2878 dlt_log(LOG_ERR, "NWTSegmented: Could not open queue.\n");
2880 dlt_user_queue_resend_error_counter = 1;
2885 if(mq_send(dlt_user.dlt_segmented_queue_write_handle, (char *)&resend_data, sizeof(s_segmented_data *), 1) < 0)
2887 if(!dlt_user_queue_resend_error_counter)
2889 // log error only when problem occurred first time
2891 snprintf(str,254,"Could not request resending.: %s \n",strerror(errno));
2892 dlt_log(LOG_CRIT, str);
2894 dlt_user_queue_resend_error_counter = 1;
2899 dlt_user_queue_resend_error_counter = 0;
2901 //thread_data will be freed by the receiver function
2902 //coverity[leaked_storage]
2906 DltReturnValue dlt_user_log_send_log(DltContextData *log, int mtype)
2909 DltUserHeader userheader;
2912 DltReturnValue ret = DLT_RETURN_OK;
2916 return DLT_RETURN_ERROR;
2921 return DLT_RETURN_ERROR;
2924 if (dlt_user.appID[0]=='\0')
2926 return DLT_RETURN_ERROR;
2929 if (log->handle->contextID[0]=='\0')
2931 return DLT_RETURN_ERROR;
2934 if ((mtype<DLT_TYPE_LOG) || (mtype>DLT_TYPE_CONTROL))
2936 return DLT_RETURN_ERROR;
2939 /* also for Trace messages */
2940 #ifdef DLT_SHM_ENABLE
2941 if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_LOG_SHM)==-1)
2943 if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_LOG)==-1)
2946 return DLT_RETURN_ERROR;
2949 if (dlt_message_init(&msg,0)==-1)
2951 return DLT_RETURN_ERROR;
2954 msg.storageheader = (DltStorageHeader*)msg.headerbuffer;
2956 if (dlt_set_storageheader(msg.storageheader,dlt_user.ecuID)==-1)
2958 return DLT_RETURN_ERROR;
2961 msg.standardheader = (DltStandardHeader*)(msg.headerbuffer + sizeof(DltStorageHeader));
2962 msg.standardheader->htyp = DLT_HTYP_PROTOCOL_VERSION1 ;
2965 if(dlt_user.with_ecu_id)
2967 msg.standardheader->htyp |= DLT_HTYP_WEID;
2970 /* send timestamp */
2971 if(dlt_user.with_timestamp)
2973 msg.standardheader->htyp |= DLT_HTYP_WTMS;
2976 /* send session id */
2977 if(dlt_user.with_session_id)
2979 msg.standardheader->htyp |= DLT_HTYP_WSID;
2980 msg.headerextra.seid = getpid();
2983 if (dlt_user.verbose_mode)
2985 /* In verbose mode, send extended header */
2986 msg.standardheader->htyp = (msg.standardheader->htyp | DLT_HTYP_UEH );
2990 /* In non-verbose, send extended header if desired */
2991 if(dlt_user.use_extende_header_for_non_verbose)
2992 msg.standardheader->htyp = (msg.standardheader->htyp | DLT_HTYP_UEH );
2995 #if (BYTE_ORDER==BIG_ENDIAN)
2996 msg.standardheader->htyp = (msg.standardheader->htyp | DLT_HTYP_MSBF);
2999 msg.standardheader->mcnt = log->handle->mcnt++;
3001 /* Set header extra parameters */
3002 dlt_set_id(msg.headerextra.ecu,dlt_user.ecuID);
3003 //msg.headerextra.seid = 0;
3004 msg.headerextra.tmsp = dlt_uptime();
3006 if (dlt_message_set_extraparameters(&msg,0)==-1)
3008 return DLT_RETURN_ERROR;
3011 /* Fill out extended header, if extended header should be provided */
3012 if (DLT_IS_HTYP_UEH(msg.standardheader->htyp))
3014 /* with extended header */
3015 msg.extendedheader = (DltExtendedHeader*)(msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp) );
3021 msg.extendedheader->msin = (DLT_TYPE_LOG << DLT_MSIN_MSTP_SHIFT) | ((log->log_level << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN) ; /* messsage info */
3024 case DLT_TYPE_NW_TRACE:
3026 msg.extendedheader->msin = (DLT_TYPE_NW_TRACE << DLT_MSIN_MSTP_SHIFT) | ((log->trace_status << DLT_MSIN_MTIN_SHIFT) & DLT_MSIN_MTIN) ; /* messsage info */
3031 /* This case should not occur */
3032 return DLT_RETURN_ERROR;
3037 /* If in verbose mode, set flag in header for verbose mode */
3038 if (dlt_user.verbose_mode)
3040 msg.extendedheader->msin |= DLT_MSIN_VERB;
3043 msg.extendedheader->noar = log->args_num; /* number of arguments */
3044 dlt_set_id(msg.extendedheader->apid,dlt_user.appID); /* application id */
3045 dlt_set_id(msg.extendedheader->ctid,log->handle->contextID); /* context id */
3047 msg.headersize = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + sizeof(DltExtendedHeader) + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp);
3051 /* without extended header */
3052 msg.headersize = sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp);
3055 len=msg.headersize - sizeof(DltStorageHeader) +log->size;
3058 dlt_log(LOG_CRIT,"Huge message discarded!\n");
3059 return DLT_RETURN_ERROR;
3062 msg.standardheader->len = DLT_HTOBE_16(len);
3064 /* print to std out, if enabled */
3065 if ((dlt_user.local_print_mode != DLT_PM_FORCE_OFF) &&
3066 (dlt_user.local_print_mode != DLT_PM_AUTOMATIC))
3068 if ((dlt_user.enable_local_print) || (dlt_user.local_print_mode == DLT_PM_FORCE_ON))
3070 if (dlt_user_print_msg(&msg, log)==-1)
3072 return DLT_RETURN_ERROR;
3077 if (dlt_user.dlt_is_file)
3080 ret=dlt_user_log_out2(dlt_user.dlt_log_handle, msg.headerbuffer, msg.headersize, log->buffer, log->size);
3085 /* Reattach to daemon if neccesary */
3086 dlt_user_log_reattach_to_daemon();
3088 if (dlt_user.overflow_counter)
3090 if (dlt_user_log_send_overflow()==0)
3092 snprintf(str,DLT_USER_BUFFER_LENGTH,"%u messages discarded!\n",dlt_user.overflow_counter);
3093 dlt_log(LOG_ERR, str);
3094 dlt_user.overflow_counter=0;
3098 /* try to resent old data first */
3099 ret = DLT_RETURN_OK;
3100 if(dlt_user.dlt_log_handle!=-1)
3101 ret = dlt_user_log_resend_buffer();
3102 if(ret==DLT_RETURN_OK)
3104 /* resend ok or nothing to resent */
3105 #ifdef DLT_SHM_ENABLE
3106 if(dlt_user.dlt_log_handle!=-1)
3107 dlt_shm_push(&dlt_user.dlt_shm,msg.headerbuffer+sizeof(DltStorageHeader), msg.headersize-sizeof(DltStorageHeader),
3108 log->buffer, log->size,0,0);
3111 ret = dlt_user_log_out3(dlt_user.dlt_log_handle,
3112 &(userheader), sizeof(DltUserHeader),
3117 #ifdef DLT_TEST_ENABLE
3118 if(dlt_user.corrupt_user_header) {
3119 userheader.pattern[0]=0xff;
3120 userheader.pattern[1]=0xff;
3121 userheader.pattern[2]=0xff;
3122 userheader.pattern[3]=0xff;
3124 if(dlt_user.corrupt_message_size) {
3125 msg.standardheader->len = DLT_HTOBE_16(dlt_user.corrupt_message_size_size);
3128 ret = dlt_user_log_out3(dlt_user.dlt_log_handle,
3129 &(userheader), sizeof(DltUserHeader),
3130 msg.headerbuffer+sizeof(DltStorageHeader), msg.headersize-sizeof(DltStorageHeader),
3131 log->buffer, log->size);
3135 /* store message in ringbuffer, if an error has occured */
3136 if (ret!=DLT_RETURN_OK)
3140 if (dlt_buffer_push3(&(dlt_user.startup_buffer),
3141 (unsigned char *)&(userheader), sizeof(DltUserHeader),
3142 msg.headerbuffer+sizeof(DltStorageHeader), msg.headersize-sizeof(DltStorageHeader),
3143 log->buffer, log->size)==-1)
3145 if(dlt_user.overflow_counter==0)
3148 dlt_log(LOG_ERR,"Buffer full! Messages will be discarded.\n");
3150 ret = DLT_RETURN_BUFFER_FULL;
3155 // Fail silenty if FIFO is not open
3156 if(dlt_user_queue_resend() < 0 && dlt_user.dlt_log_handle >= 0)
3158 ;//dlt_log(LOG_WARNING, "dlt_user_log_send_log: Failed to queue resending.\n");
3164 case DLT_RETURN_BUFFER_FULL:
3167 dlt_user.overflow_counter += 1;
3168 return DLT_RETURN_BUFFER_FULL;
3170 case DLT_RETURN_PIPE_FULL:
3172 /* data could not be written */
3173 return DLT_RETURN_PIPE_FULL;
3175 case DLT_RETURN_PIPE_ERROR:
3177 /* handle not open or pipe error */
3178 close(dlt_user.dlt_log_handle);
3179 dlt_user.dlt_log_handle = -1;
3181 #ifdef DLT_SHM_ENABLE
3182 /* free shared memory */
3183 dlt_shm_free_client(&dlt_user.dlt_shm);
3186 if (dlt_user.local_print_mode == DLT_PM_AUTOMATIC)
3188 dlt_user_print_msg(&msg, log);
3191 return DLT_RETURN_PIPE_ERROR;
3193 case DLT_RETURN_ERROR:
3195 /* other error condition */
3196 return DLT_RETURN_ERROR;
3200 return DLT_RETURN_OK;
3204 /* This case should never occur. */
3205 return DLT_RETURN_ERROR;
3210 return DLT_RETURN_OK;
3213 int dlt_user_log_send_register_application(void)
3215 DltUserHeader userheader;
3216 DltUserControlMsgRegisterApplication usercontext;
3220 if (dlt_user.appID[0]=='\0')
3225 /* set userheader */
3226 if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_REGISTER_APPLICATION)==-1)
3231 /* set usercontext */
3232 dlt_set_id(usercontext.apid,dlt_user.appID); /* application id */
3233 usercontext.pid = getpid();
3235 if (dlt_user.application_description!=0)
3237 usercontext.description_length = strlen(dlt_user.application_description);
3241 usercontext.description_length = 0;
3244 if (dlt_user.dlt_is_file)
3250 ret=dlt_user_log_out3(dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgRegisterApplication),dlt_user.application_description,usercontext.description_length);
3252 /* store message in ringbuffer, if an error has occured */
3253 if (ret!=DLT_RETURN_OK)
3257 if (dlt_buffer_push3(&(dlt_user.startup_buffer),
3258 (unsigned char *)&(userheader), sizeof(DltUserHeader),
3259 (const unsigned char*)&(usercontext), sizeof(DltUserControlMsgRegisterApplication),
3260 (const unsigned char*)dlt_user.application_description, usercontext.description_length)==-1)
3262 dlt_log(LOG_ERR,"Storing message to history buffer failed! Message discarded.\n");
3269 if(dlt_user_queue_resend() < 0 && dlt_user.dlt_log_handle >= 0)
3271 ;//dlt_log(LOG_WARNING, "dlt_user_log_send_register_application: Failed to queue resending.\n");
3278 int dlt_user_log_send_unregister_application(void)
3280 DltUserHeader userheader;
3281 DltUserControlMsgUnregisterApplication usercontext;
3285 if (dlt_user.appID[0]=='\0')
3290 /* set userheader */
3291 if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_UNREGISTER_APPLICATION)==-1)
3296 /* set usercontext */
3297 dlt_set_id(usercontext.apid,dlt_user.appID); /* application id */
3298 usercontext.pid = getpid();
3300 if (dlt_user.dlt_is_file)
3306 ret=dlt_user_log_out2(dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgUnregisterApplication));
3307 return ((ret==DLT_RETURN_OK)?0:-1);
3310 int dlt_user_log_send_register_context(DltContextData *log)
3312 DltUserHeader userheader;
3313 DltUserControlMsgRegisterContext usercontext;
3326 if ((dlt_user.appID[0]=='\0') || (log->handle->contextID=='\0'))
3331 /* set userheader */
3332 if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_REGISTER_CONTEXT)==-1)
3337 /* set usercontext */
3338 dlt_set_id(usercontext.apid,dlt_user.appID); /* application id */
3339 dlt_set_id(usercontext.ctid,log->handle->contextID); /* context id */
3340 usercontext.log_level_pos = log->handle->log_level_pos;
3341 usercontext.pid = getpid();
3343 usercontext.log_level = (int8_t)log->log_level;
3344 usercontext.trace_status = (int8_t)log->trace_status;
3346 if (log->context_description!=0)
3348 usercontext.description_length = strlen(log->context_description);
3352 usercontext.description_length = 0;
3355 if (dlt_user.dlt_is_file)
3361 ret=dlt_user_log_out3(dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgRegisterContext),log->context_description,usercontext.description_length);
3363 /* store message in ringbuffer, if an error has occured */
3364 if (ret!=DLT_RETURN_OK)
3368 if (dlt_buffer_push3(&(dlt_user.startup_buffer),
3369 (unsigned char *)&(userheader), sizeof(DltUserHeader),
3370 (const unsigned char*)&(usercontext), sizeof(DltUserControlMsgRegisterContext),
3371 (const unsigned char*)log->context_description, usercontext.description_length)==-1)
3373 dlt_log(LOG_ERR,"Storing message to history buffer failed! Message discarded.\n");
3380 if(dlt_user_queue_resend() < 0 && dlt_user.dlt_log_handle >= 0)
3382 ;//dlt_log(LOG_WARNING, "dlt_user_log_send_register_context: Failed to queue resending.\n");
3390 int dlt_user_log_send_unregister_context(DltContextData *log)
3392 DltUserHeader userheader;
3393 DltUserControlMsgUnregisterContext usercontext;
3406 if ((dlt_user.appID[0]=='\0') || (log->handle->contextID=='\0'))
3411 /* set userheader */
3412 if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_UNREGISTER_CONTEXT)==-1)
3417 /* set usercontext */
3418 dlt_set_id(usercontext.apid,dlt_user.appID); /* application id */
3419 dlt_set_id(usercontext.ctid,log->handle->contextID); /* context id */
3420 usercontext.pid = getpid();
3422 if (dlt_user.dlt_is_file)
3428 ret=dlt_user_log_out2(dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgUnregisterContext));
3429 return ((ret==DLT_RETURN_OK)?0:-1);
3432 int dlt_send_app_ll_ts_limit(const char *appid, DltLogLevelType loglevel, DltTraceStatusType tracestatus)
3434 DltUserHeader userheader;
3435 DltUserControlMsgAppLogLevelTraceStatus usercontext;
3438 if ((appid==0) || (appid[0]=='\0'))
3443 /* Removed because of DltLogLevelType and DltTraceStatusType
3445 if ((loglevel<DLT_LOG_DEFAULT) || (loglevel>DLT_LOG_VERBOSE))
3450 if ((tracestatus<DLT_TRACE_STATUS_DEFAULT) || (tracestatus>DLT_TRACE_STATUS_ON))
3457 /* set userheader */
3458 if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_APP_LL_TS)==-1)
3463 /* set usercontext */
3464 dlt_set_id(usercontext.apid,appid); /* application id */
3465 usercontext.log_level = loglevel;
3466 usercontext.trace_status = tracestatus;
3468 if (dlt_user.dlt_is_file)
3474 ret=dlt_user_log_out2(dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), &(usercontext), sizeof(DltUserControlMsgAppLogLevelTraceStatus));
3475 return ((ret==DLT_RETURN_OK)?0:-1);
3478 int dlt_user_log_send_log_mode(DltUserLogMode mode)
3480 DltUserHeader userheader;
3481 DltUserControlMsgLogMode logmode;
3485 /* set userheader */
3486 if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_LOG_MODE)==-1)
3492 logmode.log_mode = (unsigned char) mode;
3494 if (dlt_user.dlt_is_file)
3500 ret=dlt_user_log_out2(dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader), &(logmode), sizeof(DltUserControlMsgLogMode));
3501 return ((ret==DLT_RETURN_OK)?0:-1);
3504 int dlt_user_print_msg(DltMessage *msg, DltContextData *log)
3506 uint8_t *databuffer_tmp;
3507 int32_t datasize_tmp;
3508 int32_t databuffersize_tmp;
3509 static char text[DLT_USER_TEXT_LENGTH];
3511 if ((msg==0) || (log==0))
3516 /* Save variables before print */
3517 databuffer_tmp = msg->databuffer;
3518 datasize_tmp = msg->datasize;
3519 databuffersize_tmp = msg->databuffersize;
3521 /* Act like a receiver, convert header back to host format */
3522 msg->standardheader->len = DLT_BETOH_16(msg->standardheader->len);
3523 dlt_message_get_extraparameters(msg,0);
3525 msg->databuffer = log->buffer;
3526 msg->datasize = log->size;
3527 msg->databuffersize = log->size;
3529 /* Print message as ASCII */
3530 if (dlt_message_print_ascii(msg,text,DLT_USER_TEXT_LENGTH,0)==-1)
3535 /* Restore variables and set len to BE*/
3536 msg->databuffer = databuffer_tmp;
3537 msg->databuffersize = databuffersize_tmp;
3538 msg->datasize = datasize_tmp;
3540 msg->standardheader->len = DLT_HTOBE_16(msg->standardheader->len);
3545 int dlt_user_log_check_user_message(void)
3552 DltUserHeader *userheader;
3553 DltReceiver *receiver = &(dlt_user.receiver);
3555 DltUserControlMsgLogLevel *usercontextll;
3556 DltUserControlMsgInjection *usercontextinj;
3557 DltUserControlMsgLogState *userlogstate;
3558 unsigned char *userbuffer;
3560 /* For delayed calling of injection callback, to avoid deadlock */
3561 DltUserInjectionCallback delayed_injection_callback;
3562 unsigned char *delayed_inject_buffer = 0;
3563 uint32_t delayed_inject_data_length = 0;
3565 /* Ensure that callback is null before searching for it */
3566 delayed_injection_callback.injection_callback = 0;
3567 delayed_injection_callback.service_id = 0;
3569 if (dlt_user.dlt_user_handle!=DLT_FD_INIT)
3573 if (dlt_receiver_receive_fd(receiver)<=0)
3575 /* No new message available */
3579 /* look through buffer as long as data is in there */
3582 if (receiver->bytesRcvd < (int32_t)sizeof(DltUserHeader))
3587 /* resync if necessary */
3591 userheader = (DltUserHeader*) (receiver->buf+offset);
3593 /* Check for user header pattern */
3594 if (dlt_user_check_userheader(userheader))
3601 while ((int32_t)(sizeof(DltUserHeader)+offset)<=receiver->bytesRcvd);
3603 /* Check for user header pattern */
3604 if (dlt_user_check_userheader(userheader)<0 ||
3605 dlt_user_check_userheader(userheader)==0)
3610 /* Set new start offset */
3613 receiver->buf+=offset;
3614 receiver->bytesRcvd-=offset;
3617 switch (userheader->message)
3619 case DLT_USER_MESSAGE_LOG_LEVEL:
3621 if (receiver->bytesRcvd < (int32_t)(sizeof(DltUserHeader)+sizeof(DltUserControlMsgLogLevel)))
3627 usercontextll = (DltUserControlMsgLogLevel*) (receiver->buf+sizeof(DltUserHeader));
3629 /* Update log level and trace status */
3630 if (usercontextll!=0)
3634 if ((usercontextll->log_level_pos >= 0) && (usercontextll->log_level_pos < (int32_t)dlt_user.dlt_ll_ts_num_entries))
3636 // printf("Store ll, ts\n");
3637 if (dlt_user.dlt_ll_ts)
3639 dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level = usercontextll->log_level;
3640 dlt_user.dlt_ll_ts[usercontextll->log_level_pos].trace_status = usercontextll->trace_status;
3641 if(dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level_ptr)
3642 *(dlt_user.dlt_ll_ts[usercontextll->log_level_pos].log_level_ptr) = usercontextll->log_level;
3643 if(dlt_user.dlt_ll_ts[usercontextll->log_level_pos].trace_status_ptr)
3644 *(dlt_user.dlt_ll_ts[usercontextll->log_level_pos].trace_status_ptr) = usercontextll->trace_status;
3651 /* keep not read data in buffer */
3652 if (dlt_receiver_remove(receiver,sizeof(DltUserHeader)+sizeof(DltUserControlMsgLogLevel))==-1)
3658 case DLT_USER_MESSAGE_INJECTION:
3660 /* At least, user header, user context, and service id and data_length of injected message is available */
3661 if (receiver->bytesRcvd < (int32_t)(sizeof(DltUserHeader)+sizeof(DltUserControlMsgInjection)))
3667 usercontextinj = (DltUserControlMsgInjection*) (receiver->buf+sizeof(DltUserHeader));
3668 userbuffer = (unsigned char*) (receiver->buf+sizeof(DltUserHeader)+sizeof(DltUserControlMsgInjection));
3673 if (receiver->bytesRcvd < (int32_t)(sizeof(DltUserHeader)+sizeof(DltUserControlMsgInjection)+usercontextinj->data_length_inject))
3681 if ((usercontextinj->data_length_inject>0) && (dlt_user.dlt_ll_ts))
3683 /* Check if injection callback is registered for this context */
3684 for (i=0; i<dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].nrcallbacks;i++)
3686 if ((dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].injection_table) &&
3687 (dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].injection_table[i].service_id == usercontextinj->service_id))
3689 /* Prepare delayed injection callback call */
3690 if (dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].injection_table[i].injection_callback!=0)
3692 delayed_injection_callback.injection_callback = dlt_user.dlt_ll_ts[usercontextinj->log_level_pos].injection_table[i].injection_callback;
3693 delayed_injection_callback.service_id = usercontextinj->service_id;
3694 delayed_inject_data_length = usercontextinj->data_length_inject;
3695 delayed_inject_buffer = malloc(delayed_inject_data_length);
3696 if(delayed_inject_buffer != 0) {
3697 memcpy(delayed_inject_buffer, userbuffer, delayed_inject_data_length);
3708 /* Delayed injection callback call */
3709 if(delayed_inject_buffer != 0 && delayed_injection_callback.injection_callback != 0) {
3710 delayed_injection_callback.injection_callback(delayed_injection_callback.service_id, delayed_inject_buffer, delayed_inject_data_length);
3711 delayed_injection_callback.injection_callback = 0;
3712 free(delayed_inject_buffer);
3713 delayed_inject_buffer = NULL;
3717 /* keep not read data in buffer */
3718 if (dlt_receiver_remove(receiver,(sizeof(DltUserHeader)+sizeof(DltUserControlMsgInjection)+usercontextinj->data_length_inject))==-1)
3725 case DLT_USER_MESSAGE_LOG_STATE:
3727 /* At least, user header, user context, and service id and data_length of injected message is available */
3728 if (receiver->bytesRcvd < (int32_t)(sizeof(DltUserHeader)+sizeof(DltUserControlMsgLogState)))
3734 userlogstate = (DltUserControlMsgLogState*) (receiver->buf+sizeof(DltUserHeader));
3735 dlt_user.log_state = userlogstate->log_state;
3737 /* keep not read data in buffer */
3738 if (dlt_receiver_remove(receiver,(sizeof(DltUserHeader)+sizeof(DltUserControlMsgLogState)))==-1)
3746 dlt_log(LOG_ERR,"Invalid user message type received!\n");
3748 dlt_receiver_remove(receiver,sizeof(DltUserHeader));
3749 /* In next invocation of while loop, a resync will be triggered if additional data was received */
3762 if (dlt_receiver_move_to_begin(receiver)==-1)
3766 } /* while receive */
3769 return DLT_RETURN_OK;
3772 int dlt_user_log_resend_buffer(void)
3778 /* Send content of ringbuffer */
3780 count = dlt_buffer_get_message_count(&(dlt_user.startup_buffer));
3783 for (num=0;num<count;num++)
3787 size = dlt_buffer_copy(&(dlt_user.startup_buffer),dlt_user.resend_buffer,sizeof(dlt_user.resend_buffer));
3791 #ifdef DLT_SHM_ENABLE
3792 dlt_shm_push(&dlt_user.dlt_shm,dlt_user.resend_buffer+sizeof(DltUserHeader),size-sizeof(DltUserHeader),0,0,0,0);
3795 ret = dlt_user_log_out3(dlt_user.dlt_log_handle, dlt_user.resend_buffer,sizeof(DltUserHeader),0,0,0,0);
3798 ret = dlt_user_log_out3(dlt_user.dlt_log_handle, dlt_user.resend_buffer,size,0,0,0,0);
3801 /* in case of error, keep message in ringbuffer */
3802 if (ret==DLT_RETURN_OK)
3804 dlt_buffer_remove(&(dlt_user.startup_buffer));
3808 /* keep message in ringbuffer */
3819 void dlt_user_log_reattach_to_daemon(void)
3821 uint32_t num,reregistered=0;
3824 DltContextData log_new;
3826 if (dlt_user.dlt_log_handle<0)
3828 dlt_user.dlt_log_handle=-1;
3830 /* try to open pipe to dlt daemon */
3831 dlt_user.dlt_log_handle = open(DLT_USER_FIFO, O_WRONLY | O_NONBLOCK);
3832 if (dlt_user.dlt_log_handle > 0)
3834 if (dlt_user_log_init(&handle,&log_new)==-1)
3839 #ifdef DLT_SHM_ENABLE
3840 /* init shared memory */
3841 if (dlt_shm_init_client(&dlt_user.dlt_shm,DLT_SHM_KEY) < 0)
3843 snprintf(str,DLT_USER_BUFFER_LENGTH,"Loging disabled, Shared memory %d cannot be created!\n",DLT_SHM_KEY);
3844 dlt_log(LOG_WARNING, str);
3849 dlt_log(LOG_NOTICE, "Logging re-enabled!\n");
3851 /* Re-register application */
3852 if (dlt_user_log_send_register_application()==-1)
3859 /* Re-register all stored contexts */
3860 for (num=0; num<dlt_user.dlt_ll_ts_num_entries; num++)
3862 /* Re-register stored context */
3863 if ((dlt_user.appID[0]!='\0') && (dlt_user.dlt_ll_ts) && (dlt_user.dlt_ll_ts[num].contextID[0]!='\0'))
3865 //dlt_set_id(log_new.appID, dlt_user.appID);
3866 dlt_set_id(handle.contextID, dlt_user.dlt_ll_ts[num].contextID);
3867 handle.log_level_pos = num;
3868 log_new.context_description = dlt_user.dlt_ll_ts[num].context_description;
3870 // Release the mutex for sending context registration:
3871 // function dlt_user_log_send_register_context() can take the mutex to write to the DLT buffer. => dead lock
3874 log_new.log_level = DLT_USER_LOG_LEVEL_NOT_SET;
3875 log_new.trace_status = DLT_USER_TRACE_STATUS_NOT_SET;
3877 if (dlt_user_log_send_register_context(&log_new)==-1)
3884 // Lock again the mutex
3885 // it is necessary in the for(;;) test, in order to have coherent dlt_user data all over the critical section.
3893 if (reregistered==1)
3895 dlt_user_log_resend_buffer();
3901 int dlt_user_log_send_overflow(void)
3903 DltUserHeader userheader;
3904 DltUserControlMsgBufferOverflow userpayload;
3907 /* set userheader */
3908 if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_OVERFLOW)==-1)
3913 if (dlt_user.dlt_is_file)
3918 /* set user message parameters */
3919 userpayload.overflow_counter = dlt_user.overflow_counter;
3920 dlt_set_id(userpayload.apid,dlt_user.appID);
3923 ret=dlt_user_log_out2(dlt_user.dlt_log_handle, &(userheader), sizeof(DltUserHeader),
3924 &(userpayload), sizeof(DltUserControlMsgBufferOverflow));
3925 return ((ret==DLT_RETURN_OK)?0:-1);
3928 int dlt_user_check_buffer(int *total_size, int *used_size)
3930 #ifdef DLT_SHM_ENABLE
3931 *total_size = dlt_shm_get_total_size(&(dlt_user.dlt_shm));
3932 *used_size = dlt_shm_get_used_size(&(dlt_user.dlt_shm));
3934 *total_size = dlt_buffer_get_total_size(&(dlt_user.startup_buffer));
3935 *used_size = dlt_buffer_get_used_size(&(dlt_user.startup_buffer));
3941 #ifdef DLT_TEST_ENABLE
3942 void dlt_user_test_corrupt_user_header(int enable)
3944 dlt_user.corrupt_user_header = enable;
3946 void dlt_user_test_corrupt_message_size(int enable,int16_t size)
3948 dlt_user.corrupt_message_size = enable;
3949 dlt_user.corrupt_message_size_size = size;