-/*
- * Dlt- Diagnostic Log and Trace console apps
+/**
* @licence app begin@
+ * Copyright (C) 2012 BMW AG
+ *
+ * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps.
+ *
+ * Contributions are licensed to the GENIVI Alliance under one or more
+ * Contribution License Agreements.
+ *
+ * \copyright
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
+ * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
- * Copyright (C) 2011, BMW AG - Alexander Wenzel <alexander.wenzel@bmw.de>
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
- * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
- * Public License, version 2.1, for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License, version 2.1, along
- * with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
- *
- * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may
- * also be applicable to programs even in cases in which the program is not a library in the technical sense.
- *
- * Linking DLT statically or dynamically with other modules is making a combined work based on DLT. You may
- * license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to
- * license your linked modules under the GNU Lesser General Public License, version 2.1, you
- * may use the program under the following exception.
- *
- * As a special exception, the copyright holders of DLT give you permission to combine DLT
- * with software programs or libraries that are released under any license unless such a combination is not
- * permitted by the license of such a software program or library. You may copy and distribute such a
- * system following the terms of the GNU Lesser General Public License, version 2.1, including this
- * special exception, for DLT and the licenses of the other code concerned.
- *
- * Note that people who make modified versions of DLT are not obligated to grant this special exception
- * for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License,
- * version 2.1, gives permission to release a modified version without this exception; this exception
- * also makes it possible to release a modified version which carries forward this exception.
*
+ * \author Alexander Wenzel <alexander.aw.wenzel@bmw.de> BMW 2011-2012
+ *
+ * \file dlt_common.c
+ * For further information see http://www.genivi.org/.
* @licence end@
*/
#include <stdlib.h> /* for malloc(), free() */
#include <string.h> /* for strlen(), memcmp(), memmove() */
#include <time.h> /* for localtime(), strftime() */
+#include <limits.h> /* for NAME_MAX */
#include "dlt_common.h"
#include "dlt_common_cfg.h"
/* internal logging parameters */
static int logging_mode = 0;
static int logging_level = 6;
-static char logging_filename[256] = "";
+static char logging_filename[NAME_MAX + 1] = "";
static FILE *logging_handle = 0;
char *message_type[] = {"log","app_trace","nw_trace","control","","","",""};
/* apid matches, now check for ctid */
if (ctid==0)
{
- /* check if empty ctid matches */
- if (memcmp(filter->ctid[num],"",DLT_ID_SIZE)==0)
+ /* check if empty ctid matches */
+ //if (memcmp(filter->ctid[num],"",DLT_ID_SIZE)==0)//coverity complains here about Out-of-bounds access.
+ char empty_ctid[DLT_ID_SIZE]="";
+ if (memcmp(filter->ctid[num],empty_ctid,DLT_ID_SIZE)==0)
{
return num;
}
msg->datasize = 0;
msg->databuffer = 0;
+ msg->databuffersize = 0;
msg->storageheader = 0;
msg->standardheader = 0;
if (msg->databuffer)
{
free(msg->databuffer);
+ msg->databuffer = 0;
+ msg->databuffersize = 0;
}
- msg->databuffer = 0;
return 0;
}
/* free last used memory for buffer */
if (msg->databuffer)
{
- free(msg->databuffer);
+ if (msg->datasize>msg->databuffersize){
+ free(msg->databuffer);
+ msg->databuffer=(uint8_t *)malloc(msg->datasize);
+ msg->databuffersize = msg->datasize;
+ }
+ }else{
+ /* get new memory for buffer */
+ msg->databuffer = (uint8_t *)malloc(msg->datasize);
+ msg->databuffersize = msg->datasize;
}
-
- /* get new memory for buffer */
- msg->databuffer = (uint8_t *)malloc(msg->datasize);
if (msg->databuffer == 0)
{
sprintf(str,"Cannot allocate memory for payload buffer of size %d!\n",msg->datasize);
else
{
/* go back to last file position */
- fseek(file->handle,file->file_position,SEEK_SET);
+ if (0 != fseek(file->handle,file->file_position,SEEK_SET))
+ return -1;
}
}
}
/* free last used memory for buffer */
- if (file->msg.databuffer)
+ if (file->msg.databuffer && (file->msg.databuffersize < file->msg.datasize))
{
free(file->msg.databuffer);
+ file->msg.databuffer=0;
}
- /* get new memory for buffer */
- file->msg.databuffer = (uint8_t *)malloc(file->msg.datasize);
+ if (file->msg.databuffer == 0){
+ /* get new memory for buffer */
+ file->msg.databuffer = (uint8_t *)malloc(file->msg.datasize);
+ file->msg.databuffersize = file->msg.datasize;
+ }
if (file->msg.databuffer == 0)
{
file->handle = fopen(filename,"rb");
if (file->handle == 0)
{
- sprintf(str,"File %s cannot be opened!\n",filename);
+ snprintf(str, DLT_COMMON_BUFFER_LENGTH - 1 ,"File %s cannot be opened!\n",filename);
+
dlt_log(LOG_ERR, str);
return -1;
}
- fseek(file->handle,0,SEEK_END);
+ if (0 != fseek(file->handle,0,SEEK_END))
+ {
+ sprintf(str,"dlt_file_open: Seek failed to 0,SEEK_END");
+ dlt_log(LOG_ERR, str);
+ return -1;
+ }
file->file_length = ftell(file->handle);
- fseek(file->handle,0,SEEK_SET);
+
+ if (0 != fseek(file->handle,0,SEEK_SET))
+ {
+ sprintf(str,"dlt_file_open: Seek failed to 0,SEEK_SET");
+ dlt_log(LOG_ERR, str);
+ return -1;
+ }
if (verbose)
{
}
/* set to end of last succesful read message, because of conflicting calls to dlt_file_read and dlt_file_message */
- fseek(file->handle,file->file_position,SEEK_SET);
+ if (0 != fseek(file->handle,file->file_position,SEEK_SET))
+ {
+ sprintf(str,"Seek failed to file_position %ld \n",file->file_position);
+ dlt_log(LOG_ERR, str);
+ return -1;
+ }
/* get file position at start of DLT message */
if (verbose)
if (dlt_file_read_header_extended(file, verbose)<0)
{
/* go back to last position in file */
- fseek(file->handle,file->file_position,SEEK_SET);
+ if (0 != fseek(file->handle,file->file_position,SEEK_SET))
+ {
+ sprintf(str,"Seek to last file pos failed!\n");
+ dlt_log(LOG_ERR, str);
+ }
return-1;
}
if (fseek(file->handle,file->msg.datasize,SEEK_CUR)!=0)
{
/* go back to last position in file */
- fseek(file->handle,file->file_position,SEEK_SET);
sprintf(str,"Seek failed to skip payload data of size %d!\n",file->msg.datasize);
dlt_log(LOG_ERR, str);
+
+ if (0 != fseek(file->handle,file->file_position,SEEK_SET))
+ {
+ sprintf(str,"Seek back also failed!\n");
+ dlt_log(LOG_ERR, str);
+ }
+
return -1;
}
}
/* skip additional header parameters and payload data */
if (fseek(file->handle,file->msg.headersize - sizeof(DltStorageHeader) - sizeof(DltStandardHeader) + file->msg.datasize,SEEK_CUR))
{
- /* go back to last position in file */
- fseek(file->handle,file->file_position,SEEK_SET);
+
sprintf(str,"Seek failed to skip extra header and payload data from file of size %d!\n",
file->msg.headersize - sizeof(DltStorageHeader) - sizeof(DltStandardHeader) + file->msg.datasize);
dlt_log(LOG_ERR, str);
+ /* go back to last position in file */
+ if (fseek(file->handle,file->file_position,SEEK_SET))
+ {
+ sprintf(str,"Seek back also failed!\n");
+ dlt_log(LOG_ERR, str);
+ }
return -1;
}
file->index = ptr;
}
- /* set to end of last succesful read message, because of conflicting calls to dlt_file_read and dlt_file_message */
- fseek(file->handle,file->file_position,SEEK_SET);
+ /* set to end of last successful read message, because of conflicting calls to dlt_file_read and dlt_file_message */
+ if (0 != fseek(file->handle,file->file_position,SEEK_SET))
+ return -1;
/* get file position at start of DLT message */
if (verbose)
if (dlt_file_read_header_raw(file,resync,verbose)<0)
{
/* go back to last position in file */
- fseek(file->handle,file->file_position,SEEK_SET);
+ if (0!= fseek(file->handle,file->file_position,SEEK_SET))
+ {
+ sprintf(str,"dlt_file_read_raw, fseek failed 1\n");
+ dlt_log(LOG_ERR, str);
+ }
return -1;
}
if (dlt_file_read_header_extended(file, verbose)<0)
{
/* go back to last position in file */
- fseek(file->handle,file->file_position,SEEK_SET);
+ if (0 != fseek(file->handle,file->file_position,SEEK_SET))
+ {
+ sprintf(str,"dlt_file_read_raw, fseek failed 2\n");
+ dlt_log(LOG_ERR, str);
+ }
return-1;
}
if (dlt_file_read_data(file,verbose)<0)
{
/* go back to last position in file */
- fseek(file->handle,file->file_position,SEEK_SET);
+ if (0 != fseek(file->handle,file->file_position,SEEK_SET))
+ {
+ sprintf(str,"dlt_file_read_raw, fseek failed 3\n");
+ dlt_log(LOG_ERR, str);
+ }
return-1;
}
void dlt_log_set_filename(const char *filename)
{
- strncpy(logging_filename,filename,sizeof(logging_filename));
+ strncpy(logging_filename,filename,NAME_MAX);
+
}
void dlt_log_init(int mode)
return -1;
}
+ if (size > receiver->bytesRcvd || size <= 0)
+ {
+ receiver->buf = receiver->buf + receiver->bytesRcvd;
+ receiver->bytesRcvd=0;
+ return -1;
+ }
+
receiver->bytesRcvd = receiver->bytesRcvd - size;
receiver->buf = receiver->buf + size;
int dlt_buffer_init_dynamic(DltBuffer *buf, uint32_t min_size, uint32_t max_size,uint32_t step_size)
{
+ //Do not DLT_SEM_LOCK inside here!
char str[256];
DltBufferHead *head;
// clear memory
memset(buf->mem,0,buf->size);
- snprintf(str,sizeof(str),"Buffer: Size %d bytes\n",buf->size);
- dlt_log(LOG_INFO, str);
+ //snprintf(str,sizeof(str),"Buffer: Size %d bytes\n",buf->size);
+ //dlt_log(LOG_INFO, str);
return 0; /* OK */
}
void dlt_buffer_write_block(DltBuffer *buf,int *write, const unsigned char *data,unsigned int size)
{
- if((*write+size) <= buf->size) {
+ if((int)(*write+size) <= buf->size) {
// write one block
memcpy(buf->mem+*write,data,size);
*write += size;
void dlt_buffer_read_block(DltBuffer *buf,int *read,unsigned char *data,unsigned int size)
{
- if((*read+size) <= buf->size) {
+ if((int)(*read+size) <= buf->size) {
// read one block
memcpy(data,buf->mem+*read,size);
*read += size;
free_size = buf->size - write + read;
// check size
- if(free_size < (sizeof(DltBufferBlockHead)+size1+size2+size3)) {
+ if(free_size < (int)(sizeof(DltBufferBlockHead)+size1+size2+size3)) {
// try to increase size if possible
if(dlt_buffer_increase_size(buf)) {
/* increase size is not possible */
used_size = buf->size - read + write;
// first check size
- if(used_size < (sizeof(DltBufferBlockHead))) {
+ if(used_size < (int)(sizeof(DltBufferBlockHead))) {
dlt_log(LOG_ERR,"Buffer: Size check 1 failed\n");
dlt_buffer_reset(buf);
return -1; // ERROR
}
// second check size
- if(used_size < (sizeof(DltBufferBlockHead)+head.size)) {
+ if(used_size < (int)(sizeof(DltBufferBlockHead)+head.size)) {
dlt_log(LOG_ERR,"Buffer: Size check 2 failed\n");
dlt_buffer_reset(buf);
return -1; // ERROR
void dlt_get_version(char *buf)
{
- sprintf(buf,"DLT Package Version: %s %s, Package Revision: %s, build on %s %s\n",
- _DLT_PACKAGE_VERSION, _DLT_PACKAGE_VERSION_STATE, _DLT_PACKAGE_REVISION, __DATE__ , __TIME__ );
+ sprintf(buf,"DLT Package Version: %s %s, Package Revision: %s, build on %s %s\n%s %s %s %s\n",
+ _DLT_PACKAGE_VERSION, _DLT_PACKAGE_VERSION_STATE, _DLT_PACKAGE_REVISION, __DATE__ , __TIME__,_DLT_SYSTEMD_ENABLE,_DLT_SYSTEMD_WATCHDOG_ENABLE,_DLT_TEST_ENABLE,_DLT_SHM_ENABLE );
}
void dlt_get_major_version(char *buf)
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC,&ts)==0)
- {
- return (uint32_t)((((ts.tv_sec*1000000)+(ts.tv_nsec/1000)))/100); // in 0.1 ms = 100 us
+ {
+ return ( (uint32_t)ts.tv_sec*10000 + (uint32_t)ts.tv_nsec/100000 );// in 0.1 ms = 100 us
}
else
{
float64_t value64f=0,value64f_tmp=0;
int64_t value64f_tmp_int64i=0,value64f_tmp_int64i_swaped=0;
- uint32_t quantisation=0, quantisation_tmp=0;
+ uint32_t quantisation_tmp=0;
if (type_info & DLT_TYPE_INFO_STRG)
{
return -1;
sprintf(text+strlen(text),"%d",value8u);
}
- else if (type_info & DLT_TYPE_INFO_SINT || type_info & DLT_TYPE_INFO_UINT)
+ else if ((type_info & DLT_TYPE_INFO_SINT) || (type_info & DLT_TYPE_INFO_UINT))
{
/* signed or unsigned argument received */
if (type_info & DLT_TYPE_INFO_VARI)
}
if (type_info & DLT_TYPE_INFO_FIXP)
{
- quantisation=0;
- quantisation_tmp=0;
+ //compiler warning: variable ‘quantisation_tmp’ set but not used [-Wunused-but-set-variable], but: DLT_MSG_READ_VALUE wants a parameter, "0" does not work
DLT_MSG_READ_VALUE(quantisation_tmp,*ptr,*datalength,uint32_t);
+
if((*datalength)<0)
return -1;
- quantisation=DLT_ENDIAN_GET_32(msg->standardheader->htyp, quantisation_tmp);
-
switch ( type_info & DLT_TYPE_INFO_TYLE)
{
case DLT_TYLE_8BIT: