LCOV - code coverage report
Current view: top level - shared - dlt_user_shared.c (source / functions) Coverage Total Hit
Test: dlt_final_coverage.info Lines: 84.1 % 63 53
Test Date: 2026-02-03 07:35:37 Functions: 87.5 % 8 7

            Line data    Source code
       1              : /*
       2              :  * SPDX license identifier: MPL-2.0
       3              :  *
       4              :  * Copyright (C) 2011-2015, BMW AG
       5              :  *
       6              :  * This file is part of COVESA Project DLT - Diagnostic Log and Trace.
       7              :  *
       8              :  * This Source Code Form is subject to the terms of the
       9              :  * Mozilla Public License (MPL), v. 2.0.
      10              :  * If a copy of the MPL was not distributed with this file,
      11              :  * You can obtain one at http://mozilla.org/MPL/2.0/.
      12              :  *
      13              :  * For further information see http://www.covesa.org/.
      14              :  */
      15              : 
      16              : /*!
      17              :  * \author Alexander Wenzel <alexander.aw.wenzel@bmw.de>
      18              :  *
      19              :  * \copyright Copyright © 2011-2015 BMW AG. \n
      20              :  * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
      21              :  *
      22              :  * \file dlt_user_shared.c
      23              :  */
      24              : 
      25              : 
      26              : /*******************************************************************************
      27              : **                                                                            **
      28              : **  SRC-MODULE: dlt_user_shared.c                                             **
      29              : **                                                                            **
      30              : **  TARGET    : linux                                                         **
      31              : **                                                                            **
      32              : **  PROJECT   : DLT                                                           **
      33              : **                                                                            **
      34              : **  AUTHOR    : Alexander Wenzel Alexander.AW.Wenzel@bmw.de                   **
      35              : **              Markus Klein                                                  **
      36              : **                                                                            **
      37              : **  PURPOSE   :                                                               **
      38              : **                                                                            **
      39              : **  REMARKS   :                                                               **
      40              : **                                                                            **
      41              : **  PLATFORM DEPENDANT [yes/no]: yes                                          **
      42              : **                                                                            **
      43              : **  TO BE CHANGED BY USER [yes/no]: no                                        **
      44              : **                                                                            **
      45              : *******************************************************************************/
      46              : 
      47              : /*******************************************************************************
      48              : **                      Author Identity                                       **
      49              : ********************************************************************************
      50              : **                                                                            **
      51              : ** Initials     Name                       Company                            **
      52              : ** --------     -------------------------  ---------------------------------- **
      53              : **  aw          Alexander Wenzel           BMW                                **
      54              : **  mk          Markus Klein               Fraunhofer ESK                     **
      55              : *******************************************************************************/
      56              : 
      57              : /*******************************************************************************
      58              : **                      Revision Control History                              **
      59              : *******************************************************************************/
      60              : 
      61              : /*
      62              :  * $LastChangedRevision: 1670 $
      63              :  * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $
      64              :  * $LastChangedBy$
      65              :  * Initials    Date         Comment
      66              :  * aw          13.01.2010   initial
      67              :  */
      68              : 
      69              : #include <sys/stat.h>
      70              : #include <fcntl.h>
      71              : #include <errno.h>
      72              : #include <poll.h>
      73              : 
      74              : #include <sys/uio.h> /* writev() */
      75              : 
      76              : #include "dlt_user_shared.h"
      77              : #include "dlt_user_shared_cfg.h"
      78              : 
      79         6761 : DltReturnValue dlt_user_set_userheader(DltUserHeader *userheader, uint32_t mtype)
      80              : {
      81         6761 :     if (userheader == 0)
      82              :         return DLT_RETURN_ERROR;
      83              : 
      84         6761 :     if (mtype <= 0)
      85              :         return DLT_RETURN_ERROR;
      86              : 
      87         6761 :     userheader->pattern[0] = 'D';
      88         6761 :     userheader->pattern[1] = 'U';
      89         6761 :     userheader->pattern[2] = 'H';
      90         6761 :     userheader->pattern[3] = 1;
      91         6761 :     userheader->message = mtype;
      92              : 
      93         6761 :     return DLT_RETURN_OK;
      94              : }
      95              : 
      96          142 : DltReturnValue dlt_user_set_userheader_v2(DltUserHeader *userheader, uint32_t mtype)
      97              : {
      98          142 :     if (userheader == 0)
      99              :         return DLT_RETURN_ERROR;
     100              : 
     101          142 :     if (mtype <= 0)
     102              :         return DLT_RETURN_ERROR;
     103              : 
     104          142 :     userheader->pattern[0] = 'D';
     105          142 :     userheader->pattern[1] = 'U';
     106          142 :     userheader->pattern[2] = 'H';
     107          142 :     userheader->pattern[3] = 2;
     108          142 :     userheader->message = mtype;
     109              : 
     110          142 :     return DLT_RETURN_OK;
     111              : }
     112              : 
     113         1214 : int dlt_user_check_userheader(DltUserHeader *userheader)
     114              : {
     115         1214 :     if (userheader == 0)
     116              :         return -1;
     117              : 
     118         2428 :     return (userheader->pattern[0] == 'D') &&
     119         1214 :            (userheader->pattern[1] == 'U') &&
     120         2428 :            (userheader->pattern[2] == 'H') &&
     121         1214 :            ((userheader->pattern[3] == 1) || (userheader->pattern[3] == 2));
     122              : }
     123              : 
     124          144 : int dlt_get_version_from_userheader(DltUserHeader *userheader){
     125          144 :     if (userheader == 0)
     126              :         return -1;
     127              :     
     128          144 :     int version = userheader->pattern[3];
     129              :     
     130          144 :     return version;
     131              : }
     132              : 
     133          443 : DltReturnValue dlt_user_log_out2(int handle, void *ptr1, size_t len1, void *ptr2, size_t len2)
     134              : {
     135              :     struct iovec iov[2];
     136              :     uint32_t bytes_written;
     137              : 
     138          443 :     if (handle < 0)
     139              :         /* Invalid handle */
     140              :         return DLT_RETURN_ERROR;
     141              : 
     142          384 :     iov[0].iov_base = ptr1;
     143          384 :     iov[0].iov_len = len1;
     144          384 :     iov[1].iov_base = ptr2;
     145          384 :     iov[1].iov_len = len2;
     146              : 
     147          384 :     bytes_written = (uint32_t) writev(handle, iov, 2);
     148              : 
     149          384 :     if (bytes_written != (len1 + len2))
     150              :         return DLT_RETURN_ERROR;
     151              : 
     152              :     return DLT_RETURN_OK;
     153              : }
     154              : 
     155            4 : DltReturnValue dlt_user_log_out2_with_timeout(int handle, void *ptr1, size_t len1, void *ptr2, size_t len2)
     156              : {
     157            4 :     if (handle < 0)
     158              :         /* Invalid handle */
     159              :         return DLT_RETURN_ERROR;
     160              : 
     161              :     struct pollfd pfd;
     162            4 :     pfd.fd = handle;
     163            4 :     pfd.events = POLLOUT;
     164              : 
     165            4 :     if (poll(&pfd, 1, DLT_WRITEV_TIMEOUT_MS) < 0) {
     166              :         return DLT_RETURN_ERROR;
     167              :     }
     168              : 
     169            4 :     if (pfd.revents & POLLOUT) {
     170            4 :         return dlt_user_log_out2(handle, ptr1, len1, ptr2, len2);
     171              :     } else {
     172              :         return DLT_RETURN_ERROR;
     173              :     }
     174              : }
     175              : 
     176         6456 : DltReturnValue dlt_user_log_out3(int handle, void *ptr1, size_t len1, void *ptr2, size_t len2, void *ptr3, size_t len3)
     177              : {
     178              :     struct iovec iov[3];
     179              :     uint32_t bytes_written;
     180              : 
     181         6456 :     if (handle < 0)
     182              :         /* Invalid handle */
     183              :         return DLT_RETURN_ERROR;
     184              : 
     185         6375 :     iov[0].iov_base = ptr1;
     186         6375 :     iov[0].iov_len = len1;
     187         6375 :     iov[1].iov_base = ptr2;
     188         6375 :     iov[1].iov_len = len2;
     189         6375 :     iov[2].iov_base = ptr3;
     190         6375 :     iov[2].iov_len = len3;
     191              : 
     192         6375 :     bytes_written = (uint32_t) writev(handle, iov, 3);
     193              : 
     194         6375 :     if (bytes_written != (len1 + len2 + len3)) {
     195            0 :         switch (errno) {
     196              :         case ETIMEDOUT:
     197              :         {
     198              :             return DLT_RETURN_PIPE_ERROR;     /* ETIMEDOUT - connect timeout */
     199              :             break;
     200              :         }
     201              :         case EBADF:
     202              :         {
     203              :             return DLT_RETURN_PIPE_ERROR;     /* EBADF - handle not open */
     204              :             break;
     205              :         }
     206              :         case EPIPE:
     207              :         {
     208              :             return DLT_RETURN_PIPE_ERROR;     /* EPIPE - pipe error */
     209              :             break;
     210              :         }
     211            0 :         case EAGAIN:
     212              :         {
     213            0 :             return DLT_RETURN_PIPE_FULL;     /* EAGAIN - data could not be written */
     214              :             break;
     215              :         }
     216              :         default:
     217              :         {
     218              :             break;
     219              :         }
     220              :         }
     221              : 
     222              :         return DLT_RETURN_ERROR;
     223              :     }
     224              : 
     225              :     return DLT_RETURN_OK;
     226              : }
     227              : 
     228            0 : DltReturnValue dlt_user_log_out3_with_timeout(int handle, void *ptr1, size_t len1, void *ptr2, size_t len2, void *ptr3, size_t len3)
     229              : {
     230            0 :     if (handle < 0)
     231              :         /* Invalid handle */
     232              :         return DLT_RETURN_ERROR;
     233              : 
     234              :     struct pollfd pfd;
     235            0 :     pfd.fd = handle;
     236            0 :     pfd.events = POLLOUT;
     237              : 
     238            0 :     if (poll(&pfd, 1, DLT_WRITEV_TIMEOUT_MS) < 0) {
     239              :         return DLT_RETURN_ERROR;
     240              :     }
     241              : 
     242            0 :     if (pfd.revents & POLLOUT) {
     243            0 :         return dlt_user_log_out3(handle, ptr1, len1, ptr2, len2, ptr3, len3);
     244              :     } else {
     245              :         return DLT_RETURN_ERROR;
     246              :     }
     247              : }
        

Generated by: LCOV version 2.0-1