/* * @licence app begin@ * SPDX license identifier: MPL-2.0 * * Copyright (C) 2011-2015, BMW AG * * This file is part of GENIVI Project DLT - Diagnostic Log and Trace. * * This Source Code Form is subject to the terms of the * Mozilla Public License (MPL), 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/. * * For further information see http://www.genivi.org/. * @licence end@ */ /*! * \author Alexander Wenzel * * \copyright Copyright © 2011-2015 BMW AG. \n * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/. * * \file dlt_common.h */ /******************************************************************************* ** ** ** SRC-MODULE: dlt_common.h ** ** ** ** TARGET : linux ** ** ** ** PROJECT : DLT ** ** ** ** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de ** ** Markus Klein ** ** ** ** PURPOSE : ** ** ** ** REMARKS : ** ** ** ** PLATFORM DEPENDANT [yes/no]: yes ** ** ** ** TO BE CHANGED BY USER [yes/no]: no ** ** ** *******************************************************************************/ /******************************************************************************* ** Author Identity ** ******************************************************************************** ** ** ** Initials Name Company ** ** -------- ------------------------- ---------------------------------- ** ** aw Alexander Wenzel BMW ** ** mk Markus Klein Fraunhofer ESK ** *******************************************************************************/ /******************************************************************************* ** Revision Control History ** *******************************************************************************/ /* * $LastChangedRevision: 1670 $ * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $ * $LastChangedBy$ Initials Date Comment aw 13.01.2010 initial */ #ifndef DLT_COMMON_H #define DLT_COMMON_H /** \defgroup commonapi DLT Common API \addtogroup commonapi \{ */ #include #ifdef __linux__ #include #else #include #endif #if !defined(_MSC_VER) #include #include #endif #if !defined (__WIN32__) && !defined(_MSC_VER) #include #endif #include "dlt_types.h" #include "dlt_protocol.h" #if !defined (PACKED) #define PACKED __attribute__((aligned(1),packed)) #endif #if defined (__MSDOS__) || defined (_MSC_VER) /* set instead /Zp8 flag in Visual C++ configuration */ #undef PACKED #define PACKED #endif /* * Macros to swap the byte order. */ #define DLT_SWAP_64(value) ((((uint64_t)DLT_SWAP_32((value)&0xffffffffull))<<32) | (DLT_SWAP_32((value)>>32))) #define DLT_SWAP_16(value) ((((value) >> 8)&0xff) | (((value) << 8)&0xff00)) #define DLT_SWAP_32(value) ((((value) >> 24)&0xff) | (((value) << 8)&0xff0000) | (((value) >> 8)&0xff00) | (((value) << 24)&0xff000000)) /* Set Big Endian and Little Endian to a initial value, if not defined */ #if !defined __USE_BSD #ifndef LITTLE_ENDIAN #define LITTLE_ENDIAN 1234 #endif #ifndef BIG_ENDIAN #define BIG_ENDIAN 4321 #endif #endif /* __USE_BSD */ /* If byte order is not defined, default to little endian */ #if !defined __USE_BSD #ifndef BYTE_ORDER #define BYTE_ORDER LITTLE_ENDIAN #endif #endif /* __USE_BSD */ /* Check for byte-order */ #if (BYTE_ORDER==BIG_ENDIAN) /* #warning "Big Endian Architecture!" */ #define DLT_HTOBE_16(x) ((x)) #define DLT_HTOLE_16(x) DLT_SWAP_16((x)) #define DLT_BETOH_16(x) ((x)) #define DLT_LETOH_16(x) DLT_SWAP_16((x)) #define DLT_HTOBE_32(x) ((x)) #define DLT_HTOLE_32(x) DLT_SWAP_32((x)) #define DLT_BETOH_32(x) ((x)) #define DLT_LETOH_32(x) DLT_SWAP_32((x)) #define DLT_HTOBE_64(x) ((x)) #define DLT_HTOLE_64(x) DLT_SWAP_64((x)) #define DLT_BETOH_64(x) ((x)) #define DLT_LETOH_64(x) DLT_SWAP_64((x)) #else /* #warning "Litte Endian Architecture!" */ #define DLT_HTOBE_16(x) DLT_SWAP_16((x)) #define DLT_HTOLE_16(x) ((x)) #define DLT_BETOH_16(x) DLT_SWAP_16((x)) #define DLT_LETOH_16(x) ((x)) #define DLT_HTOBE_32(x) DLT_SWAP_32((x)) #define DLT_HTOLE_32(x) ((x)) #define DLT_BETOH_32(x) DLT_SWAP_32((x)) #define DLT_LETOH_32(x) ((x)) #define DLT_HTOBE_64(x) DLT_SWAP_64((x)) #define DLT_HTOLE_64(x) ((x)) #define DLT_BETOH_64(x) DLT_SWAP_64((x)) #define DLT_LETOH_64(x) ((x)) #endif #define DLT_ENDIAN_GET_16(htyp,x) ((((htyp) & DLT_HTYP_MSBF)>0)?DLT_BETOH_16(x):DLT_LETOH_16(x)) #define DLT_ENDIAN_GET_32(htyp,x) ((((htyp) & DLT_HTYP_MSBF)>0)?DLT_BETOH_32(x):DLT_LETOH_32(x)) #define DLT_ENDIAN_GET_64(htyp,x) ((((htyp) & DLT_HTYP_MSBF)>0)?DLT_BETOH_64(x):DLT_LETOH_64(x)) #if defined (__WIN32__) || defined (_MSC_VER) #define LOG_EMERG 0 #define LOG_ALERT 1 #define LOG_CRIT 2 #define LOG_ERR 3 #define LOG_WARNING 4 #define LOG_NOTICE 5 #define LOG_INFO 6 #define LOG_DEBUG 7 #define LOG_PID 0x01 #define LOG_DAEMON (3<<3) #endif enum { DLT_LOG_TO_CONSOLE=0, DLT_LOG_TO_SYSLOG=1, DLT_LOG_TO_FILE=2, DLT_LOG_DROPPED=3 }; /** * The standard TCP Port used for DLT daemon, can be overwritten via -p when starting dlt-daemon */ #define DLT_DAEMON_TCP_PORT 3490 /* Initial value for file descriptor */ #define DLT_FD_INIT -1 /* Minimum value for a file descriptor except the POSIX Standards: stdin=0, stdout=1, stderr=2 */ #define DLT_FD_MINIMUM 3 /** * The size of a DLT ID */ #define DLT_ID_SIZE 4 #define DLT_SIZE_WEID DLT_ID_SIZE #define DLT_SIZE_WSID (sizeof(uint32_t)) #define DLT_SIZE_WTMS (sizeof(uint32_t)) /** * Definitions for GET_LOG_INFO */ #define DLT_GET_LOG_INFO_HEADER 18 /*Get log info header size in response text */ #define GET_LOG_INFO_LENGTH 13 #define SERVICE_OPT_LENGTH 3 /* checks if received size is big enough for expected data */ #define DLT_CHECK_RCV_DATA_SIZE(received, required) \ ({ \ int _ret = DLT_RETURN_OK; \ if (((int)received - (int)required) < 0) { \ dlt_vlog(LOG_WARNING, "%s: Received data not complete\n", __func__); \ _ret = DLT_RETURN_ERROR; \ } \ _ret; \ }) /** * Get the size of extra header parameters, depends on htyp. */ #define DLT_STANDARD_HEADER_EXTRA_SIZE(htyp) ( (DLT_IS_HTYP_WEID(htyp) ? DLT_SIZE_WEID : 0) + (DLT_IS_HTYP_WSID(htyp) ? DLT_SIZE_WSID : 0) + (DLT_IS_HTYP_WTMS(htyp) ? DLT_SIZE_WTMS : 0) ) #if defined (__MSDOS__) || defined (_MSC_VER) #define __func__ __FUNCTION__ #endif #define PRINT_FUNCTION_VERBOSE(_verbose) \ { \ static char _strbuf[255]; \ \ if(_verbose) \ { \ snprintf(_strbuf, 255, "%s()\n",__func__); \ dlt_log(LOG_INFO, _strbuf); \ } \ } #ifndef NULL #define NULL (char*)0 #endif #define DLT_MSG_IS_CONTROL(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \ (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL)) #define DLT_MSG_IS_CONTROL_REQUEST(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \ (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL) && \ (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_CONTROL_REQUEST)) #define DLT_MSG_IS_CONTROL_RESPONSE(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \ (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL) && \ (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_CONTROL_RESPONSE)) #define DLT_MSG_IS_CONTROL_TIME(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \ (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL) && \ (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_CONTROL_TIME)) #define DLT_MSG_IS_NW_TRACE(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \ (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_NW_TRACE)) #define DLT_MSG_IS_TRACE_MOST(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \ (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_NW_TRACE) && \ (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_NW_TRACE_MOST)) #define DLT_MSG_IS_NONVERBOSE(MSG) (!(DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) || \ ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && (!(DLT_IS_MSIN_VERB((MSG)->extendedheader->msin))))) /* * Definitions of DLT message buffer overflow */ #define DLT_MESSAGE_BUFFER_NO_OVERFLOW 0x00 /**< Buffer overflow has not occured */ #define DLT_MESSAGE_BUFFER_OVERFLOW 0x01 /**< Buffer overflow has occured */ /* * Definition of DLT output variants */ #define DLT_OUTPUT_HEX 1 #define DLT_OUTPUT_ASCII 2 #define DLT_OUTPUT_MIXED_FOR_PLAIN 3 #define DLT_OUTPUT_MIXED_FOR_HTML 4 #define DLT_OUTPUT_ASCII_LIMITED 5 #define DLT_FILTER_MAX 30 /**< Maximum number of filters */ #define DLT_MSG_READ_VALUE(dst,src,length,type) \ { \ if((length<0) || ((length)<((int32_t)sizeof(type)))) \ { length = -1; } \ else \ { dst = *((type*)src);src+=sizeof(type);length-=sizeof(type); } \ } #define DLT_MSG_READ_ID(dst,src,length) \ { \ if((length<0) || ((length) on the console */ int dlt_mkdir_recursive(const char *dir); #endif #ifdef __cplusplus } #endif /** \} */ #endif /* DLT_COMMON_H */