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_client.c
23 : */
24 :
25 : /*******************************************************************************
26 : ** **
27 : ** SRC-MODULE: dlt_client.c **
28 : ** **
29 : ** TARGET : linux **
30 : ** **
31 : ** PROJECT : DLT **
32 : ** **
33 : ** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de **
34 : ** Markus Klein **
35 : ** **
36 : ** PURPOSE : **
37 : ** **
38 : ** REMARKS : **
39 : ** **
40 : ** PLATFORM DEPENDANT [yes/no]: yes **
41 : ** **
42 : ** TO BE CHANGED BY USER [yes/no]: no **
43 : ** **
44 : *******************************************************************************/
45 :
46 : /*******************************************************************************
47 : ** Author Identity **
48 : ********************************************************************************
49 : ** **
50 : ** Initials Name Company **
51 : ** -------- ------------------------- ---------------------------------- **
52 : ** aw Alexander Wenzel BMW **
53 : ** mk Markus Klein Fraunhofer ESK **
54 : *******************************************************************************/
55 :
56 : /*******************************************************************************
57 : ** Revision Control History **
58 : *******************************************************************************/
59 :
60 : /*
61 : * $LastChangedRevision$
62 : * $LastChangedDate$
63 : * $LastChangedBy$
64 : * Initials Date Comment
65 : * aw 12.07.2010 initial
66 : */
67 :
68 : #include <stdio.h>
69 :
70 : #if defined(__WIN32__) || defined(_MSC_VER)
71 : #pragma warning(disable : 4996) /* Switch off C4996 warnings */
72 : #include <winsock2.h> /* for socket(), connect(), send(), and recv() */
73 : #else
74 : #include <sys/socket.h> /* for socket(), connect(), send(), and recv() */
75 :
76 : #pragma GCC diagnostic ignored "-Wconversion"
77 : #include <arpa/inet.h> /* for sockaddr_in and inet_addr() */
78 : #pragma GCC diagnostic push
79 : #pragma GCC diagnostic pop
80 :
81 : #include <netdb.h>
82 : #include <sys/stat.h>
83 : #include <sys/un.h>
84 : #endif
85 :
86 : #if defined(_MSC_VER)
87 : #include <io.h>
88 : #else
89 : #include <unistd.h>
90 : #include <syslog.h>
91 : #endif
92 :
93 : #include <fcntl.h>
94 :
95 : #include <stdlib.h> /* for malloc(), free() */
96 : #include <string.h> /* for strlen(), memcmp(), memmove() */
97 : #include <errno.h>
98 : #include <limits.h>
99 : #include <poll.h>
100 :
101 : #include "dlt_types.h"
102 : #include "dlt_log.h"
103 : #include "dlt_client.h"
104 : #include "dlt_client_cfg.h"
105 :
106 : // DLTv2 - DLT Version flag for multiplexing v1 and v2 messages
107 : uint8_t dlt_client_dlt_version = DLTProtocolV1;
108 :
109 : static int (*message_callback_function)(DltMessage* message, void* data) = NULL;
110 : static int (*message_callback_function_v2)(DltMessageV2* message, void* data) = NULL;
111 : static bool (*fetch_next_message_callback_function)(void* data) = NULL;
112 :
113 2 : void dlt_client_register_message_callback(int (*registerd_callback)(DltMessage* message, void* data))
114 : {
115 2 : message_callback_function = registerd_callback;
116 2 : }
117 :
118 0 : void dlt_client_register_message_callback_v2(int (*registerd_callback)(DltMessageV2* message, void* data))
119 : {
120 0 : message_callback_function_v2 = registerd_callback;
121 0 : }
122 :
123 0 : void dlt_client_register_fetch_next_message_callback(bool (*registerd_callback)(void* data))
124 : {
125 0 : fetch_next_message_callback_function = registerd_callback;
126 0 : }
127 :
128 6 : DltReturnValue dlt_client_init_port(DltClient* client, int port, int verbose)
129 : {
130 6 : if (verbose && (port != DLT_DAEMON_TCP_PORT))
131 1 : dlt_vlog(LOG_INFO, "%s: Init dlt client struct with port %d\n", __func__, port);
132 :
133 6 : if (client == NULL)
134 : return DLT_RETURN_ERROR;
135 :
136 6 : client->sock = -1;
137 6 : client->servIP = NULL;
138 6 : client->serialDevice = NULL;
139 6 : client->baudrate = DLT_CLIENT_INITIAL_BAUDRATE;
140 6 : client->port = (uint16_t)port;
141 6 : client->socketPath = NULL;
142 6 : client->mode = DLT_CLIENT_MODE_TCP;
143 6 : client->receiver.buffer = NULL;
144 6 : client->receiver.buf = NULL;
145 6 : client->receiver.backup_buf = NULL;
146 6 : client->hostip = NULL;
147 :
148 6 : return DLT_RETURN_OK;
149 : }
150 :
151 2 : DltReturnValue dlt_client_init(DltClient* client, int verbose)
152 : {
153 : char* env_daemon_port;
154 : int tmp_port;
155 2 : client->ecuid2 = NULL;
156 : /* the port may be specified by an environment variable, defaults to DLT_DAEMON_TCP_PORT */
157 : unsigned short servPort = DLT_DAEMON_TCP_PORT;
158 :
159 : /* the port may be specified by an environment variable */
160 2 : env_daemon_port = getenv(DLT_CLIENT_ENV_DAEMON_TCP_PORT);
161 :
162 2 : if (env_daemon_port != NULL) {
163 : tmp_port = atoi(env_daemon_port);
164 :
165 0 : if ((tmp_port < IPPORT_RESERVED) || ((unsigned)tmp_port > USHRT_MAX)) {
166 0 : dlt_vlog(LOG_ERR, "%s: Specified port is out of possible range: %d.\n", __func__, tmp_port);
167 0 : return DLT_RETURN_ERROR;
168 : } else {
169 0 : servPort = (unsigned short)tmp_port;
170 : }
171 : }
172 :
173 2 : if (verbose)
174 0 : dlt_vlog(LOG_INFO, "%s: Init dlt client struct with default port: %hu.\n", __func__, servPort);
175 2 : return dlt_client_init_port(client, servPort, verbose);
176 : }
177 :
178 7 : DltReturnValue dlt_client_connect(DltClient* client, int verbose)
179 : {
180 7 : const int yes = 1;
181 7 : char portnumbuffer[33] = {0};
182 : struct addrinfo hints, *servinfo, *p;
183 : struct sockaddr_un addr;
184 : int rv;
185 : struct ip_mreq mreq;
186 : DltReceiverType receiver_type = DLT_RECEIVE_FD;
187 :
188 : struct pollfd pfds[1];
189 : int ret;
190 : int n;
191 7 : socklen_t m = sizeof(n);
192 : int connect_errno = 0;
193 :
194 : memset(&hints, 0, sizeof(hints));
195 7 : hints.ai_socktype = SOCK_STREAM;
196 :
197 7 : if (client == 0)
198 : return DLT_RETURN_ERROR;
199 :
200 7 : switch (client->mode) {
201 6 : case DLT_CLIENT_MODE_TCP:
202 6 : snprintf(portnumbuffer, 32, "%d", client->port);
203 :
204 6 : if ((rv = getaddrinfo(client->servIP, portnumbuffer, &hints, &servinfo)) != 0) {
205 0 : dlt_vlog(LOG_ERR, "%s: getaddrinfo: %s\n", __func__, gai_strerror(rv));
206 3 : return DLT_RETURN_ERROR;
207 : }
208 :
209 10 : for (p = servinfo; p != NULL; p = p->ai_next) {
210 7 : if ((client->sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) < 0) {
211 0 : dlt_vlog(LOG_WARNING, "%s: socket() failed! %s\n", __func__, strerror(errno));
212 0 : continue;
213 : }
214 :
215 : /* Set socket to Non-blocking mode */
216 7 : if (fcntl(client->sock, F_SETFL, fcntl(client->sock, F_GETFL, 0) | O_NONBLOCK) < 0) {
217 0 : dlt_vlog(LOG_WARNING, "%s: Socket cannot be changed to NON BLOCK: %s\n", __func__, strerror(errno));
218 0 : close(client->sock);
219 0 : continue;
220 : }
221 :
222 7 : if (connect(client->sock, p->ai_addr, p->ai_addrlen) < 0) {
223 7 : if (errno == EINPROGRESS) {
224 7 : pfds[0].fd = client->sock;
225 7 : pfds[0].events = POLLOUT;
226 : ret = poll(pfds, 1, 500);
227 7 : if (ret < 0) {
228 0 : dlt_vlog(LOG_ERR, "%s: Failed to poll with err [%s]\n", __func__, strerror(errno));
229 0 : close(client->sock);
230 0 : continue;
231 7 : } else if (
232 7 : (pfds[0].revents & POLLOUT)
233 7 : && getsockopt(client->sock, SOL_SOCKET, SO_ERROR, (void*)&n, &m) == 0) {
234 7 : if (n == 0) {
235 3 : dlt_vlog(LOG_DEBUG, "%s: Already connect\n", __func__);
236 3 : if (fcntl(client->sock, F_SETFL, fcntl(client->sock, F_GETFL, 0) & ~O_NONBLOCK) < 0) {
237 0 : dlt_vlog(
238 : LOG_WARNING, "%s: Socket cannot be changed to BLOCK with err [%s]\n", __func__,
239 : strerror(errno));
240 0 : close(client->sock);
241 0 : continue;
242 : }
243 : } else {
244 : connect_errno = n;
245 4 : close(client->sock);
246 4 : continue;
247 : }
248 : } else {
249 0 : connect_errno = errno;
250 0 : close(client->sock);
251 0 : continue;
252 : }
253 : } else {
254 : connect_errno = errno;
255 0 : close(client->sock);
256 0 : continue;
257 : }
258 : }
259 :
260 : break;
261 : }
262 :
263 6 : freeaddrinfo(servinfo);
264 :
265 6 : if (p == NULL) {
266 3 : dlt_vlog(LOG_ERR, "%s: ERROR: failed to connect! %s\n", __func__, strerror(connect_errno));
267 3 : return DLT_RETURN_ERROR;
268 : }
269 :
270 3 : if (verbose) {
271 1 : dlt_vlog(LOG_INFO, "%s: Connected to DLT daemon (%s)\n", __func__, client->servIP);
272 : }
273 :
274 : receiver_type = DLT_RECEIVE_SOCKET;
275 :
276 4 : break;
277 0 : case DLT_CLIENT_MODE_SERIAL:
278 : /* open serial connection */
279 0 : client->sock = open(client->serialDevice, O_RDWR);
280 :
281 0 : if (client->sock < 0) {
282 0 : dlt_vlog(LOG_ERR, "%s: ERROR: Failed to open device %s\n", __func__, client->serialDevice);
283 0 : return DLT_RETURN_ERROR;
284 : }
285 :
286 0 : if (isatty(client->sock)) {
287 : #if !defined(__WIN32__)
288 :
289 0 : if (dlt_setup_serial(client->sock, client->baudrate) < DLT_RETURN_OK) {
290 0 : dlt_vlog(
291 : LOG_ERR, "%s: ERROR: Failed to configure serial device %s (%s) \n", __func__, client->serialDevice,
292 0 : strerror(errno));
293 0 : return DLT_RETURN_ERROR;
294 : }
295 :
296 : #else
297 : return DLT_RETURN_ERROR;
298 : #endif
299 : } else {
300 0 : if (verbose)
301 0 : dlt_vlog(
302 : LOG_ERR, "%s: ERROR: Device is not a serial device, device = %s (%s) \n", __func__,
303 0 : client->serialDevice, strerror(errno));
304 :
305 0 : return DLT_RETURN_ERROR;
306 : }
307 :
308 0 : if (verbose)
309 0 : dlt_vlog(LOG_INFO, "%s: Connected to %s\n", __func__, client->serialDevice);
310 :
311 : receiver_type = DLT_RECEIVE_FD;
312 :
313 : break;
314 1 : case DLT_CLIENT_MODE_UNIX:
315 :
316 1 : if ((client->sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
317 0 : dlt_vlog(LOG_ERR, "%s: ERROR: (unix) socket error: %s\n", __func__, strerror(errno));
318 :
319 0 : return DLT_RETURN_ERROR;
320 : }
321 :
322 : memset(&addr, 0, sizeof(addr));
323 1 : addr.sun_family = AF_UNIX;
324 1 : strncpy(addr.sun_path, client->socketPath, sizeof(addr.sun_path) - 1);
325 :
326 1 : if (connect(client->sock, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
327 0 : dlt_vlog(LOG_ERR, "%s: ERROR: (unix) connect error: %s\n", __func__, strerror(errno));
328 :
329 0 : return DLT_RETURN_ERROR;
330 : }
331 :
332 1 : if (client->sock < 0) {
333 0 : dlt_vlog(LOG_ERR, "%s: ERROR: Failed to open device %s\n", __func__, client->socketPath);
334 :
335 0 : return DLT_RETURN_ERROR;
336 : }
337 :
338 : receiver_type = DLT_RECEIVE_SOCKET;
339 :
340 : break;
341 0 : case DLT_CLIENT_MODE_UDP_MULTICAST:
342 :
343 0 : if ((client->sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
344 0 : dlt_vlog(LOG_ERR, "%s: ERROR: socket error: %s\n", __func__, strerror(errno));
345 :
346 0 : return DLT_RETURN_ERROR;
347 : }
348 :
349 : /* allow multiple sockets to use the same PORT number */
350 0 : if (setsockopt(client->sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0) {
351 0 : dlt_vlog(LOG_ERR, "%s: ERROR: Reusing address failed: %s\n", __func__, strerror(errno));
352 :
353 0 : return DLT_RETURN_ERROR;
354 : }
355 :
356 0 : memset(&client->receiver.addr, 0, sizeof(client->receiver.addr));
357 0 : client->receiver.addr.sin_family = AF_INET;
358 : client->receiver.addr.sin_addr.s_addr = htonl(INADDR_ANY);
359 0 : client->receiver.addr.sin_port = htons(client->port);
360 :
361 : /* bind to receive address */
362 0 : if (bind(client->sock, (struct sockaddr*)&client->receiver.addr, sizeof(client->receiver.addr)) < 0) {
363 0 : dlt_vlog(LOG_ERR, "%s: ERROR: bind failed: %s\n", __func__, strerror(errno));
364 :
365 0 : return DLT_RETURN_ERROR;
366 : }
367 :
368 0 : mreq.imr_interface.s_addr = htonl(INADDR_ANY);
369 0 : if (client->hostip) {
370 0 : mreq.imr_interface.s_addr = inet_addr(client->hostip);
371 : }
372 0 : if (client->servIP == NULL) {
373 0 : dlt_vlog(LOG_ERR, "%s: ERROR: server address not set\n", __func__);
374 :
375 0 : return DLT_RETURN_ERROR;
376 : }
377 :
378 0 : char delimiter[] = ",";
379 0 : char* servIP = strtok(client->servIP, delimiter);
380 :
381 0 : while (servIP != NULL) {
382 0 : mreq.imr_multiaddr.s_addr = inet_addr(servIP);
383 0 : if (mreq.imr_multiaddr.s_addr == (in_addr_t)-1) {
384 0 : dlt_vlog(LOG_ERR, "%s: ERROR: server address not not valid %s\n", __func__, servIP);
385 :
386 0 : return DLT_RETURN_ERROR;
387 : }
388 :
389 0 : if (setsockopt(client->sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*)&mreq, sizeof(mreq)) < 0) {
390 0 : dlt_vlog(LOG_ERR, "%s: ERROR: setsockopt add membership failed: %s\n", __func__, strerror(errno));
391 :
392 0 : return DLT_RETURN_ERROR;
393 : }
394 0 : servIP = strtok(NULL, delimiter);
395 : }
396 : receiver_type = DLT_RECEIVE_UDP_SOCKET;
397 :
398 : break;
399 0 : default:
400 0 : dlt_vlog(LOG_ERR, "%s: ERROR: Mode not supported: %d\n", __func__, client->mode);
401 :
402 0 : return DLT_RETURN_ERROR;
403 : }
404 :
405 4 : if (dlt_receiver_init(&(client->receiver), client->sock, receiver_type, DLT_RECEIVE_BUFSIZE) != DLT_RETURN_OK) {
406 0 : dlt_vlog(LOG_ERR, "%s: ERROR initializing receiver\n", __func__);
407 0 : return DLT_RETURN_ERROR;
408 : }
409 :
410 : return DLT_RETURN_OK;
411 : }
412 :
413 3 : DltReturnValue dlt_client_cleanup(DltClient* client, int verbose)
414 : {
415 : int ret = DLT_RETURN_OK;
416 :
417 3 : if (verbose)
418 0 : dlt_vlog(LOG_INFO, "%s: Cleanup dlt client\n", __func__);
419 :
420 3 : if (client == NULL)
421 : return DLT_RETURN_WRONG_PARAMETER;
422 :
423 3 : if (client->sock != -1)
424 3 : close(client->sock);
425 :
426 3 : if (dlt_receiver_free(&(client->receiver)) != DLT_RETURN_OK) {
427 0 : dlt_vlog(LOG_WARNING, "%s: Failed to free receiver\n", __func__);
428 : ret = DLT_RETURN_ERROR;
429 : }
430 :
431 3 : if (client->serialDevice) {
432 0 : free(client->serialDevice);
433 0 : client->serialDevice = NULL;
434 : }
435 :
436 3 : if (client->servIP) {
437 2 : free(client->servIP);
438 2 : client->servIP = NULL;
439 : }
440 :
441 3 : if (client->socketPath) {
442 1 : free(client->socketPath);
443 1 : client->socketPath = NULL;
444 : }
445 :
446 3 : if (client->hostip) {
447 0 : free(client->hostip);
448 0 : client->hostip = NULL;
449 : }
450 :
451 3 : if (client->ecuid2 != NULL) {
452 0 : free(client->ecuid2);
453 0 : client->ecuid2 = NULL;
454 : }
455 : return ret;
456 : }
457 :
458 2 : DltReturnValue dlt_client_main_loop(DltClient* client, void* data, int verbose)
459 : {
460 : DltMessage msg;
461 : int ret;
462 :
463 2 : if (client == 0)
464 : return DLT_RETURN_ERROR;
465 :
466 2 : if (dlt_message_init(&msg, verbose) == DLT_RETURN_ERROR)
467 : return DLT_RETURN_ERROR;
468 :
469 : bool fetch_next_message = true;
470 365 : while (fetch_next_message) {
471 : /* wait for data from socket or serial connection */
472 365 : ret = dlt_receiver_receive(&(client->receiver));
473 :
474 365 : if (ret <= 0) {
475 : /* No more data to be received */
476 2 : if (dlt_message_free(&msg, verbose) == DLT_RETURN_ERROR)
477 : return DLT_RETURN_ERROR;
478 :
479 : return DLT_RETURN_TRUE;
480 : }
481 :
482 549 : while (dlt_message_read(
483 549 : &msg, (unsigned char*)(client->receiver.buf), (unsigned int)client->receiver.bytesRcvd,
484 : client->resync_serial_header, verbose)
485 549 : == DLT_MESSAGE_ERROR_OK) {
486 : /* Call callback function */
487 186 : if (message_callback_function)
488 186 : (*message_callback_function)(&msg, data);
489 :
490 186 : int total_size = (int)((size_t)msg.headersize + (size_t)msg.datasize - sizeof(DltStorageHeader));
491 :
492 186 : if (msg.found_serialheader) {
493 : total_size += (int)sizeof(dltSerialHeader);
494 : }
495 :
496 186 : if (dlt_receiver_remove(&(client->receiver), total_size) == DLT_RETURN_ERROR) {
497 : /* Return value ignored */
498 0 : dlt_message_free(&msg, verbose);
499 0 : return DLT_RETURN_ERROR;
500 : }
501 : }
502 :
503 363 : if (dlt_receiver_move_to_begin(&(client->receiver)) == DLT_RETURN_ERROR) {
504 : /* Return value ignored */
505 0 : dlt_message_free(&msg, verbose);
506 0 : return DLT_RETURN_ERROR;
507 : }
508 363 : if (fetch_next_message_callback_function)
509 0 : fetch_next_message = (*fetch_next_message_callback_function)(data);
510 : }
511 :
512 0 : if (dlt_message_free(&msg, verbose) == DLT_RETURN_ERROR)
513 : return DLT_RETURN_ERROR;
514 :
515 : return DLT_RETURN_OK;
516 : }
517 :
518 0 : DltReturnValue dlt_client_main_loop_v2(DltClient* client, void* data, int verbose)
519 : {
520 : DltMessageV2 msg;
521 : int ret;
522 0 : if (client == 0)
523 : return DLT_RETURN_ERROR;
524 0 : if (dlt_message_init_v2(&msg, verbose) == DLT_RETURN_ERROR)
525 : return DLT_RETURN_ERROR;
526 :
527 : bool fetch_next_message = true;
528 0 : while (fetch_next_message) {
529 : /* wait for data from socket or serial connection */
530 0 : ret = dlt_receiver_receive(&(client->receiver));
531 :
532 0 : if (ret <= 0) {
533 : /* No more data to be received */
534 0 : if (dlt_message_free_v2(&msg, verbose) == DLT_RETURN_ERROR)
535 : return DLT_RETURN_ERROR;
536 :
537 : return DLT_RETURN_TRUE;
538 : }
539 :
540 0 : while (dlt_message_read_v2(
541 0 : &msg, (unsigned char*)(client->receiver.buf), (unsigned int)client->receiver.bytesRcvd,
542 : client->resync_serial_header, verbose)
543 0 : == DLT_MESSAGE_ERROR_OK) {
544 : /* Call callback function */
545 0 : if (message_callback_function_v2) {
546 0 : (*message_callback_function_v2)(&msg, data);
547 : }
548 :
549 0 : if (msg.found_serialheader) {
550 0 : int64_t temp_remove_size = (int64_t)msg.headersizev2 + (int64_t)msg.datasize
551 0 : - (int64_t)msg.storageheadersizev2 + (int64_t)sizeof(dltSerialHeader);
552 0 : if (temp_remove_size < 0 || temp_remove_size > UINT32_MAX) {
553 0 : dlt_message_free_v2(&msg, verbose);
554 0 : return DLT_RETURN_ERROR;
555 : }
556 : uint32_t remove_size = (uint32_t)temp_remove_size;
557 0 : if (dlt_receiver_remove(&(client->receiver), (int)remove_size) == DLT_RETURN_ERROR) {
558 : /* Return value ignored */
559 0 : dlt_message_free_v2(&msg, verbose);
560 0 : return DLT_RETURN_ERROR;
561 : }
562 0 : } else if (
563 0 : dlt_receiver_remove(
564 : &(client->receiver),
565 0 : (int)((uint32_t)msg.headersizev2 + (uint32_t)msg.datasize - msg.storageheadersizev2))
566 : == DLT_RETURN_ERROR) {
567 : /* Return value ignored */
568 0 : dlt_message_free_v2(&msg, verbose);
569 0 : return DLT_RETURN_ERROR;
570 : }
571 0 : dlt_message_free_v2(&msg, verbose);
572 : }
573 :
574 0 : if (dlt_receiver_move_to_begin(&(client->receiver)) == DLT_RETURN_ERROR) {
575 : /* Return value ignored */
576 0 : dlt_message_free_v2(&msg, verbose);
577 0 : return DLT_RETURN_ERROR;
578 : }
579 0 : if (fetch_next_message_callback_function)
580 0 : fetch_next_message = (*fetch_next_message_callback_function)(data);
581 : }
582 :
583 0 : if (dlt_message_free_v2(&msg, verbose) == DLT_RETURN_ERROR)
584 : return DLT_RETURN_ERROR;
585 :
586 : return DLT_RETURN_OK;
587 : }
588 :
589 1 : DltReturnValue dlt_client_send_message_to_socket(DltClient* client, DltMessage* msg)
590 : {
591 : int ret = 0;
592 :
593 1 : if ((client == NULL) || (client->sock < 0) || (msg == NULL) || (msg->databuffer == NULL)) {
594 0 : dlt_log(LOG_ERR, "Invalid parameters\n");
595 0 : return DLT_RETURN_ERROR;
596 : }
597 :
598 1 : if (client->send_serial_header) {
599 0 : ret = (int)send(client->sock, (const char*)dltSerialHeader, sizeof(dltSerialHeader), 0);
600 0 : if (ret < 0) {
601 0 : dlt_vlog(LOG_ERR, "Sending serial header failed: %s\n", strerror(errno));
602 0 : return DLT_RETURN_ERROR;
603 : }
604 : }
605 :
606 2 : ret = (int)send(
607 : client->sock, (const char*)(msg->headerbuffer + sizeof(DltStorageHeader)),
608 1 : (size_t)((int32_t)msg->headersize - (int32_t)sizeof(DltStorageHeader)), 0);
609 1 : if (ret < 0) {
610 0 : dlt_vlog(LOG_ERR, "Sending message header failed: %s\n", strerror(errno));
611 0 : return DLT_RETURN_ERROR;
612 : }
613 :
614 1 : ret = (int)send(client->sock, (const char*)msg->databuffer, (size_t)msg->datasize, 0);
615 1 : if (ret < 0) {
616 0 : dlt_vlog(LOG_ERR, "Sending message failed: %s\n", strerror(errno));
617 0 : return DLT_RETURN_ERROR;
618 : }
619 :
620 : return DLT_RETURN_OK;
621 : }
622 :
623 0 : DltReturnValue dlt_client_send_message_to_socket_v2(DltClient* client, DltMessageV2* msg)
624 : {
625 : int ret = 0;
626 :
627 0 : if ((client == NULL) || (client->sock < 0) || (msg == NULL) || (msg->databuffer == NULL)) {
628 0 : dlt_log(LOG_ERR, "Invalid parameters\n");
629 0 : return DLT_RETURN_ERROR;
630 : }
631 :
632 0 : if (client->send_serial_header) {
633 0 : ret = send(client->sock, (const char*)dltSerialHeader, sizeof(dltSerialHeader), 0);
634 0 : if (ret < 0) {
635 0 : dlt_vlog(LOG_ERR, "Sending serial header failed: %s\n", strerror(errno));
636 0 : return DLT_RETURN_ERROR;
637 : }
638 : }
639 :
640 0 : ret = send(
641 0 : client->sock, (const char*)(msg->headerbufferv2 + msg->storageheadersizev2),
642 0 : (uint32_t)msg->headersizev2 - msg->storageheadersizev2, 0);
643 0 : if (ret < 0) {
644 0 : dlt_vlog(LOG_ERR, "Sending message header failed: %s\n", strerror(errno));
645 0 : return DLT_RETURN_ERROR;
646 : }
647 :
648 0 : ret = send(client->sock, (const char*)msg->databuffer, (size_t)msg->datasize, 0);
649 0 : if (ret < 0) {
650 0 : dlt_vlog(LOG_ERR, "Sending message failed: %s\n", strerror(errno));
651 0 : return DLT_RETURN_ERROR;
652 : }
653 :
654 : return DLT_RETURN_OK;
655 : }
656 :
657 8 : DltReturnValue dlt_client_send_ctrl_msg(DltClient* client, char* apid, char* ctid, uint8_t* payload, uint32_t size)
658 : {
659 : DltMessage msg;
660 : int ret;
661 :
662 : int32_t len;
663 : uint32_t id_tmp;
664 : uint32_t id;
665 :
666 8 : if ((client == 0) || (client->sock < 0) || (apid == 0) || (ctid == 0))
667 : return DLT_RETURN_ERROR;
668 :
669 : /* initialise new message */
670 8 : if (dlt_message_init(&msg, 0) == DLT_RETURN_ERROR)
671 : return DLT_RETURN_ERROR;
672 :
673 : /* prepare payload of data */
674 8 : msg.datasize = (int32_t)size;
675 :
676 8 : if (msg.databuffer && (msg.databuffersize < msg.datasize)) {
677 0 : free(msg.databuffer);
678 0 : msg.databuffer = 0;
679 : }
680 :
681 8 : if (msg.databuffer == 0) {
682 8 : msg.databuffer = (uint8_t*)malloc((size_t)msg.datasize);
683 8 : msg.databuffersize = msg.datasize;
684 : }
685 :
686 8 : if (msg.databuffer == 0) {
687 0 : dlt_message_free(&msg, 0);
688 0 : return DLT_RETURN_ERROR;
689 : }
690 :
691 : /* copy data */
692 8 : memcpy(msg.databuffer, payload, size);
693 :
694 : /* prepare storage header */
695 8 : msg.storageheader = (DltStorageHeader*)msg.headerbuffer;
696 :
697 8 : if (dlt_set_storageheader(msg.storageheader, "") == DLT_RETURN_ERROR) {
698 0 : dlt_message_free(&msg, 0);
699 0 : return DLT_RETURN_ERROR;
700 : }
701 :
702 : /* prepare standard header */
703 8 : msg.standardheader = (DltStandardHeader*)(msg.headerbuffer + sizeof(DltStorageHeader));
704 8 : msg.standardheader->htyp = DLT_HTYP_WEID | DLT_HTYP_WTMS | DLT_HTYP_UEH | DLT_HTYP_PROTOCOL_VERSION1;
705 :
706 : #if (BYTE_ORDER == BIG_ENDIAN)
707 : msg.standardheader->htyp = (msg.standardheader->htyp | DLT_HTYP_MSBF);
708 : #endif
709 :
710 8 : msg.standardheader->mcnt = 0;
711 :
712 : /* Set header extra parameters */
713 8 : dlt_set_id(msg.headerextra.ecu, client->ecuid);
714 : /*msg.headerextra.seid = 0; */
715 8 : msg.headerextra.tmsp = dlt_uptime();
716 :
717 : /* Copy header extra parameters to headerbuffer */
718 8 : if (dlt_message_set_extraparameters(&msg, 0) == DLT_RETURN_ERROR) {
719 0 : dlt_message_free(&msg, 0);
720 0 : return DLT_RETURN_ERROR;
721 : }
722 :
723 : /* prepare extended header */
724 8 : msg.extendedheader = (DltExtendedHeader*)(msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader)
725 8 : + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp));
726 :
727 8 : msg.extendedheader->msin = DLT_MSIN_CONTROL_REQUEST;
728 :
729 8 : msg.extendedheader->noar = 1; /* number of arguments */
730 :
731 15 : dlt_set_id(msg.extendedheader->apid, (apid[0] == '\0') ? DLT_CLIENT_DUMMY_APP_ID : apid);
732 15 : dlt_set_id(msg.extendedheader->ctid, (ctid[0] == '\0') ? DLT_CLIENT_DUMMY_CON_ID : ctid);
733 :
734 : /* prepare length information */
735 8 : msg.headersize = (int32_t)(sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + sizeof(DltExtendedHeader)
736 8 : + DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp));
737 :
738 8 : len = (int32_t)((size_t)msg.headersize - sizeof(DltStorageHeader) + (size_t)msg.datasize);
739 :
740 :
741 8 : if (len > UINT16_MAX) {
742 0 : dlt_vlog(LOG_ERR, "%s: Critical: Huge injection message discarded!\n", __func__);
743 :
744 0 : dlt_message_free(&msg, 0);
745 :
746 0 : return DLT_RETURN_ERROR;
747 : }
748 :
749 8 : msg.standardheader->len = (uint16_t)DLT_HTOBE_16((uint16_t)len);
750 :
751 : /* Send data (without storage header) */
752 8 : if ((client->mode == DLT_CLIENT_MODE_TCP) || (client->mode == DLT_CLIENT_MODE_SERIAL)) {
753 : /* via FileDescriptor */
754 8 : if (client->send_serial_header) {
755 0 : ret = write(client->sock, dltSerialHeader, sizeof(dltSerialHeader));
756 0 : if (ret < 0) {
757 0 : dlt_log(LOG_ERR, "Sending message failed\n");
758 0 : dlt_message_free(&msg, 0);
759 0 : return DLT_RETURN_ERROR;
760 : }
761 : }
762 :
763 16 : ret = (int)write(
764 : client->sock, msg.headerbuffer + sizeof(DltStorageHeader),
765 8 : (size_t)((int32_t)msg.headersize - (int32_t)sizeof(DltStorageHeader)));
766 :
767 8 : if (0 > ret) {
768 0 : dlt_vlog(LOG_ERR, "%s: Sending message failed\n", __func__);
769 0 : dlt_message_free(&msg, 0);
770 0 : return DLT_RETURN_ERROR;
771 : }
772 :
773 8 : ret = (int)write(client->sock, msg.databuffer, (size_t)msg.datasize);
774 :
775 8 : if (0 > ret) {
776 0 : dlt_vlog(LOG_ERR, "%s: Sending message failed\n", __func__);
777 0 : dlt_message_free(&msg, 0);
778 0 : return DLT_RETURN_ERROR;
779 : }
780 :
781 8 : id_tmp = *((uint32_t*)(msg.databuffer));
782 8 : id = DLT_ENDIAN_GET_32(msg.standardheader->htyp, id_tmp);
783 :
784 8 : dlt_vlog(LOG_INFO, "%s: Control message forwarded : %s\n", __func__, dlt_get_service_name(id));
785 : } else {
786 : /* via Socket */
787 0 : if (dlt_client_send_message_to_socket(client, &msg) == DLT_RETURN_ERROR) {
788 0 : dlt_log(LOG_ERR, "Sending message to socket failed\n");
789 0 : dlt_message_free(&msg, 0);
790 0 : return DLT_RETURN_ERROR;
791 : }
792 : }
793 :
794 : /* free message */
795 8 : if (dlt_message_free(&msg, 0) == DLT_RETURN_ERROR)
796 : return DLT_RETURN_ERROR;
797 :
798 : return DLT_RETURN_OK;
799 : }
800 :
801 0 : DltReturnValue dlt_client_send_ctrl_msg_v2(DltClient* client, char* apid, char* ctid, uint8_t* payload, uint32_t size)
802 : {
803 : DltMessageV2 msg;
804 : int ret;
805 : int32_t len;
806 : uint32_t id_tmp;
807 : uint32_t id;
808 : uint8_t appidlen;
809 : uint8_t ctxidlen;
810 : char ecid_buf[DLT_V2_ID_SIZE];
811 : char apid_buf[DLT_V2_ID_SIZE];
812 : char ctid_buf[DLT_V2_ID_SIZE];
813 :
814 0 : if ((client == 0) || (client->sock < 0) || (apid == NULL) || (ctid == NULL))
815 : return DLT_RETURN_ERROR;
816 :
817 : /* initialise new message */
818 0 : if (dlt_message_init_v2(&msg, 0) == DLT_RETURN_ERROR)
819 : return DLT_RETURN_ERROR;
820 :
821 : /* prepare payload of data */
822 0 : msg.datasize = (int32_t)size;
823 :
824 0 : if (msg.databuffer && (msg.databuffersize < msg.datasize)) {
825 0 : free(msg.databuffer);
826 0 : msg.databuffer = 0;
827 : }
828 :
829 0 : if (msg.databuffer == 0) {
830 0 : msg.databuffer = (uint8_t*)malloc((size_t)msg.datasize);
831 0 : msg.databuffersize = msg.datasize;
832 : }
833 :
834 0 : if (msg.databuffer == 0) {
835 0 : dlt_message_free_v2(&msg, 0);
836 0 : return DLT_RETURN_ERROR;
837 : }
838 :
839 : /* copy data */
840 0 : memcpy(msg.databuffer, payload, size);
841 :
842 0 : if (strcmp(apid, "") == 0) {
843 : appidlen = strlen(DLT_CLIENT_DUMMY_APP_ID);
844 : } else {
845 0 : appidlen = strlen(apid);
846 : }
847 :
848 0 : if (strcmp(ctid, "") == 0) {
849 : ctxidlen = strlen(DLT_CLIENT_DUMMY_CON_ID);
850 : } else {
851 0 : ctxidlen = strlen(ctid);
852 : }
853 :
854 0 : msg.storageheadersizev2 = STORAGE_HEADER_V2_FIXED_SIZE;
855 0 : msg.baseheadersizev2 = BASE_HEADER_V2_FIXED_SIZE;
856 0 : msg.baseheaderextrasizev2 = (int32_t)dlt_message_get_extraparameters_size_v2(DLT_CONTROL_MSG);
857 0 : msg.extendedheadersizev2 = (uint32_t)(client->ecuid2len) + 1 + appidlen + 1 + ctxidlen + 1;
858 :
859 0 : msg.headersizev2 = (int32_t)(msg.storageheadersizev2 + msg.baseheadersizev2 + msg.baseheaderextrasizev2
860 0 : + msg.extendedheadersizev2);
861 :
862 0 : if (msg.headerbufferv2 != NULL) {
863 0 : free(msg.headerbufferv2);
864 : msg.headerbufferv2 = NULL;
865 : }
866 :
867 0 : msg.headerbufferv2 = (uint8_t*)malloc((size_t)msg.headersizev2);
868 :
869 0 : if (dlt_set_storageheader_v2(&(msg.storageheaderv2), 0, NULL) == DLT_RETURN_ERROR) {
870 0 : dlt_message_free_v2(&msg, 0);
871 0 : return DLT_RETURN_ERROR;
872 : }
873 :
874 0 : if (dlt_message_set_storageparameters_v2(&msg, 0) != DLT_RETURN_OK) {
875 0 : dlt_message_free_v2(&msg, 0);
876 0 : return DLT_RETURN_ERROR;
877 : }
878 :
879 : /* prepare base header */
880 0 : msg.baseheaderv2 = (DltBaseHeaderV2*)(msg.headerbufferv2 + msg.storageheadersizev2);
881 :
882 : msg.baseheaderv2->htyp2 = DLT_HTYP2_PROTOCOL_VERSION2;
883 : msg.baseheaderv2->htyp2 |= DLT_CONTROL_MSG;
884 : msg.baseheaderv2->htyp2 |= DLT_HTYP2_WEID;
885 0 : msg.baseheaderv2->htyp2 |= DLT_HTYP2_WACID;
886 0 : msg.baseheaderv2->mcnt = 0;
887 :
888 : /* Fill base header conditional parameters */
889 0 : msg.headerextrav2.msin = DLT_MSIN_CONTROL_REQUEST;
890 0 : msg.headerextrav2.noar = 1; /* number of arguments */
891 : memset(msg.headerextrav2.seconds, 0, 5);
892 0 : msg.headerextrav2.nanoseconds = 0;
893 : #if defined(__WIN32__) || defined(_MSC_VER)
894 : time_t t = time(NULL);
895 : if (t == -1) {
896 : uint32_t tcnt = (uint32_t)(GetTickCount()); /* GetTickCount() in 10 ms resolution */
897 : tcnt_seconds = tcnt / 100;
898 : tcnt_ns = (tcnt - (tcnt * 100)) * 10000;
899 : msg.headerextrav2.seconds[0] = (tcnt_seconds >> 32) & 0xFF;
900 : msg.headerextrav2.seconds[1] = (tcnt_seconds >> 24) & 0xFF;
901 : msg.headerextrav2.seconds[2] = (tcnt_seconds >> 16) & 0xFF;
902 : msg.headerextrav2.seconds[3] = (tcnt_seconds >> 8) & 0xFF;
903 : msg.headerextrav2.seconds[4] = tcnt_seconds & 0xFF;
904 : if (ts.tv_nsec < 0x3B9ACA00) {
905 : msg.headerextrav2.nanoseconds = tcnt_ns;
906 : }
907 : } else {
908 : msg.headerextrav2.seconds[0] = (t >> 32) & 0xFF;
909 : msg.headerextrav2.seconds[1] = (t >> 24) & 0xFF;
910 : msg.headerextrav2.seconds[2] = (t >> 16) & 0xFF;
911 : msg.headerextrav2.seconds[3] = (t >> 8) & 0xFF;
912 : msg.headerextrav2.seconds[4] = t & 0xFF;
913 : msg.headerextrav2.nanoseconds |= 0x80000000;
914 : }
915 : #else
916 : struct timespec ts;
917 0 : if (clock_gettime(CLOCK_REALTIME, &ts) == 0) {
918 0 : msg.headerextrav2.seconds[0] = ((uint64_t)ts.tv_sec >> 32) & 0xFF;
919 0 : msg.headerextrav2.seconds[1] = (ts.tv_sec >> 24) & 0xFF;
920 0 : msg.headerextrav2.seconds[2] = (ts.tv_sec >> 16) & 0xFF;
921 0 : msg.headerextrav2.seconds[3] = (ts.tv_sec >> 8) & 0xFF;
922 0 : msg.headerextrav2.seconds[4] = ts.tv_sec & 0xFF;
923 0 : if (ts.tv_nsec < 0x3B9ACA00) {
924 0 : msg.headerextrav2.nanoseconds = (uint32_t)ts.tv_nsec; /* value is long */
925 : }
926 0 : } else if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
927 0 : msg.headerextrav2.seconds[0] = ((uint64_t)ts.tv_sec >> 32) & 0xFF;
928 0 : msg.headerextrav2.seconds[1] = (ts.tv_sec >> 24) & 0xFF;
929 0 : msg.headerextrav2.seconds[2] = (ts.tv_sec >> 16) & 0xFF;
930 0 : msg.headerextrav2.seconds[3] = (ts.tv_sec >> 8) & 0xFF;
931 0 : msg.headerextrav2.seconds[4] = ts.tv_sec & 0xFF;
932 0 : if (ts.tv_nsec < 0x3B9ACA00) {
933 0 : msg.headerextrav2.nanoseconds = (uint32_t)ts.tv_nsec; /* value is long */
934 : }
935 0 : msg.headerextrav2.nanoseconds |= 0x80000000;
936 : }
937 : #endif
938 :
939 : /* Copy header extra parameters to headerbuffer */
940 0 : if (dlt_message_set_extraparameters_v2(&msg, 0) == DLT_RETURN_ERROR) {
941 0 : dlt_message_free_v2(&msg, 0);
942 0 : return DLT_RETURN_ERROR;
943 : }
944 :
945 : /* Fill out extended header */
946 0 : if (DLT_IS_HTYP2_WEID(msg.baseheaderv2->htyp2)) {
947 0 : msg.extendedheaderv2.ecidlen = client->ecuid2len;
948 0 : if (msg.extendedheaderv2.ecidlen > 0) {
949 0 : dlt_set_id_v2(ecid_buf, client->ecuid2, msg.extendedheaderv2.ecidlen);
950 0 : msg.extendedheaderv2.ecid = ecid_buf;
951 : } else {
952 0 : msg.extendedheaderv2.ecid = NULL;
953 : }
954 : }
955 :
956 0 : if (DLT_IS_HTYP2_WACID(msg.baseheaderv2->htyp2)) {
957 0 : msg.extendedheaderv2.apidlen = appidlen;
958 0 : if (msg.extendedheaderv2.apidlen > 0) {
959 0 : if (strcmp(apid, "") == 0) {
960 0 : dlt_set_id_v2(apid_buf, DLT_CLIENT_DUMMY_APP_ID, msg.extendedheaderv2.apidlen);
961 : } else {
962 0 : dlt_set_id_v2(apid_buf, apid, msg.extendedheaderv2.apidlen);
963 : }
964 0 : msg.extendedheaderv2.apid = apid_buf;
965 : } else {
966 0 : msg.extendedheaderv2.apid = NULL;
967 : }
968 0 : msg.extendedheaderv2.apidlen = appidlen;
969 0 : msg.extendedheaderv2.ctidlen = ctxidlen;
970 0 : if (msg.extendedheaderv2.ctidlen > 0) {
971 0 : if (strcmp(ctid, "") == 0) {
972 0 : dlt_set_id_v2(ctid_buf, DLT_CLIENT_DUMMY_CON_ID, msg.extendedheaderv2.ctidlen);
973 : } else {
974 0 : dlt_set_id_v2(ctid_buf, ctid, msg.extendedheaderv2.ctidlen);
975 : }
976 0 : msg.extendedheaderv2.ctid = ctid_buf;
977 : } else {
978 0 : msg.extendedheaderv2.ctid = NULL;
979 : }
980 : }
981 :
982 0 : if (dlt_message_set_extendedparameters_v2(&msg) != DLT_RETURN_OK) {
983 0 : dlt_message_free_v2(&msg, 0);
984 0 : return DLT_RETURN_ERROR;
985 : }
986 :
987 0 : len = msg.headersizev2 - (int32_t)msg.storageheadersizev2 + msg.datasize;
988 :
989 0 : if (len > UINT16_MAX) {
990 0 : dlt_vlog(LOG_ERR, "%s: Critical: Huge injection message discarded!\n", __func__);
991 0 : dlt_message_free_v2(&msg, 0);
992 0 : return DLT_RETURN_ERROR;
993 : }
994 0 : msg.baseheaderv2->len = DLT_HTOBE_16((uint16_t)len);
995 :
996 : /* Send data (without storage header) */
997 0 : if ((client->mode == DLT_CLIENT_MODE_TCP) || (client->mode == DLT_CLIENT_MODE_SERIAL)) {
998 : /* via FileDescriptor */
999 0 : if (client->send_serial_header) {
1000 0 : ret = write(client->sock, dltSerialHeader, sizeof(dltSerialHeader));
1001 0 : if (ret < 0) {
1002 0 : dlt_log(LOG_ERR, "Sending message failed\n");
1003 0 : dlt_message_free_v2(&msg, 0);
1004 0 : return DLT_RETURN_ERROR;
1005 : }
1006 : }
1007 0 : ret = (int)write(
1008 0 : client->sock, msg.headerbufferv2 + msg.storageheadersizev2,
1009 0 : (uint32_t)msg.headersizev2 - msg.storageheadersizev2);
1010 :
1011 0 : if (0 > ret) {
1012 0 : dlt_vlog(LOG_ERR, "%s: Sending message failed\n", __func__);
1013 0 : dlt_message_free_v2(&msg, 0);
1014 0 : return DLT_RETURN_ERROR;
1015 : }
1016 :
1017 0 : ret = (int)write(client->sock, msg.databuffer, (uint32_t)msg.datasize);
1018 :
1019 0 : if (0 > ret) {
1020 0 : dlt_vlog(LOG_ERR, "%s: Sending message failed\n", __func__);
1021 0 : dlt_message_free_v2(&msg, 0);
1022 0 : return DLT_RETURN_ERROR;
1023 : }
1024 :
1025 0 : id_tmp = *((uint32_t*)(msg.databuffer));
1026 : id = DLT_LETOH_32(id_tmp);
1027 :
1028 0 : dlt_vlog(LOG_INFO, "%s: Control message forwarded : %s\n", __func__, dlt_get_service_name(id));
1029 : } else {
1030 : /* via Socket */
1031 0 : if (dlt_client_send_message_to_socket_v2(client, &msg) == DLT_RETURN_ERROR) {
1032 0 : dlt_log(LOG_ERR, "Sending message to socket failed\n");
1033 0 : dlt_message_free_v2(&msg, 0);
1034 0 : return DLT_RETURN_ERROR;
1035 : }
1036 : }
1037 :
1038 : /* free message */
1039 0 : if (dlt_message_free_v2(&msg, 0) == DLT_RETURN_ERROR)
1040 : return DLT_RETURN_ERROR;
1041 :
1042 :
1043 : return DLT_RETURN_OK;
1044 : }
1045 :
1046 0 : DltReturnValue dlt_client_send_inject_msg(
1047 : DltClient* client, char* apid, char* ctid, uint32_t serviceID, uint8_t* buffer, uint32_t size)
1048 : {
1049 : uint8_t* payload;
1050 : int offset;
1051 :
1052 0 : payload = (uint8_t*)malloc(sizeof(uint32_t) + sizeof(uint32_t) + size);
1053 :
1054 0 : if (payload == 0)
1055 : return DLT_RETURN_ERROR;
1056 :
1057 : offset = 0;
1058 : memcpy(payload, &serviceID, sizeof(serviceID));
1059 : offset += (int)sizeof(uint32_t);
1060 0 : memcpy(payload + offset, &size, sizeof(size));
1061 : offset += (int)sizeof(uint32_t);
1062 0 : memcpy(payload + offset, buffer, size);
1063 :
1064 : /* free message */
1065 0 : if (dlt_client_send_ctrl_msg(client, apid, ctid, payload, (uint32_t)(sizeof(uint32_t) + sizeof(uint32_t) + size))
1066 : == DLT_RETURN_ERROR) {
1067 0 : free(payload);
1068 0 : return DLT_RETURN_ERROR;
1069 : }
1070 :
1071 0 : free(payload);
1072 :
1073 0 : return DLT_RETURN_OK;
1074 : }
1075 :
1076 0 : DltReturnValue dlt_client_send_inject_msg_v2(
1077 : DltClient* client, char* apid, char* ctid, uint32_t serviceID, uint8_t* buffer, uint32_t size)
1078 : {
1079 : uint8_t* payload;
1080 : int offset;
1081 :
1082 0 : payload = (uint8_t*)malloc(sizeof(uint32_t) + sizeof(uint32_t) + size);
1083 :
1084 0 : if (payload == 0)
1085 : return DLT_RETURN_ERROR;
1086 :
1087 : offset = 0;
1088 : memcpy(payload, &serviceID, sizeof(serviceID));
1089 : offset += (int)sizeof(uint32_t);
1090 0 : memcpy(payload + offset, &size, sizeof(size));
1091 : offset += (int)sizeof(uint32_t);
1092 0 : memcpy(payload + offset, buffer, size);
1093 :
1094 : /* free message */
1095 0 : if (dlt_client_send_ctrl_msg_v2(client, apid, ctid, payload, (uint32_t)(sizeof(uint32_t) + sizeof(uint32_t) + size))
1096 : == DLT_RETURN_ERROR) {
1097 0 : free(payload);
1098 0 : return DLT_RETURN_ERROR;
1099 : }
1100 :
1101 0 : free(payload);
1102 :
1103 0 : return DLT_RETURN_OK;
1104 : }
1105 :
1106 1 : DltReturnValue dlt_client_send_log_level(DltClient* client, char* apid, char* ctid, uint8_t logLevel)
1107 : {
1108 : DltServiceSetLogLevel* req;
1109 : int ret = DLT_RETURN_ERROR;
1110 :
1111 1 : if (client == NULL)
1112 : return ret;
1113 :
1114 1 : req = calloc(1, sizeof(DltServiceSetLogLevel));
1115 :
1116 1 : if (req == NULL)
1117 : return ret;
1118 :
1119 1 : req->service_id = DLT_SERVICE_ID_SET_LOG_LEVEL;
1120 1 : dlt_set_id(req->apid, apid);
1121 1 : dlt_set_id(req->ctid, ctid);
1122 1 : req->log_level = logLevel;
1123 1 : dlt_set_id(req->com, "remo");
1124 :
1125 : /* free message */
1126 1 : ret = dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*)req, sizeof(DltServiceSetLogLevel));
1127 :
1128 :
1129 1 : free(req);
1130 :
1131 1 : return ret;
1132 : }
1133 :
1134 0 : DltReturnValue dlt_client_send_log_level_v2(DltClient* client, char* apid, char* ctid, uint8_t logLevel)
1135 : {
1136 : DltServiceSetLogLevelV2 req;
1137 : int ret = DLT_RETURN_ERROR;
1138 : uint8_t* buffer;
1139 : uint16_t buffersize;
1140 : uint16_t offset = 0;
1141 :
1142 0 : if (client == NULL)
1143 : return ret;
1144 :
1145 0 : req.service_id = DLT_SERVICE_ID_SET_LOG_LEVEL;
1146 0 : req.apidlen = strlen(apid);
1147 0 : req.apid = apid;
1148 0 : req.ctidlen = strlen(ctid);
1149 0 : req.ctid = ctid;
1150 0 : req.log_level = logLevel;
1151 0 : dlt_set_id(req.com, "remo");
1152 :
1153 0 : buffersize = DLT_SERVICE_SET_LOG_LEVEL_FIXED_SIZE_V2 + req.apidlen + req.ctidlen;
1154 :
1155 0 : buffer = (uint8_t*)malloc(buffersize);
1156 0 : if (buffer == NULL)
1157 : return ret;
1158 :
1159 : memcpy(buffer + offset, &(req.service_id), 4);
1160 : offset = offset + 4;
1161 0 : memcpy(buffer + offset, &(req.apidlen), 1);
1162 : offset = offset + 1;
1163 0 : memcpy(buffer + offset, req.apid, req.apidlen);
1164 0 : offset = offset + req.apidlen;
1165 0 : memcpy(buffer + offset, &(req.ctidlen), 1);
1166 0 : offset = offset + 1;
1167 0 : memcpy(buffer + offset, req.ctid, req.ctidlen);
1168 0 : offset = offset + req.ctidlen;
1169 0 : memcpy(buffer + offset, &(req.log_level), 1);
1170 0 : offset = offset + 1;
1171 0 : memcpy(buffer + offset, req.com, 4);
1172 :
1173 0 : ret = dlt_client_send_ctrl_msg_v2(client, "APP", "CON", (uint8_t*)buffer, buffersize);
1174 :
1175 :
1176 0 : free(buffer);
1177 :
1178 0 : return ret;
1179 : }
1180 :
1181 3 : DltReturnValue dlt_client_get_log_info(DltClient* client)
1182 : {
1183 : DltServiceGetLogInfoRequest* req;
1184 : int ret = DLT_RETURN_ERROR;
1185 :
1186 3 : if (client == NULL)
1187 : return ret;
1188 :
1189 3 : req = (DltServiceGetLogInfoRequest*)malloc(sizeof(DltServiceGetLogInfoRequest));
1190 :
1191 3 : if (req == NULL)
1192 : return ret;
1193 :
1194 3 : req->service_id = DLT_SERVICE_ID_GET_LOG_INFO;
1195 3 : req->options = 7;
1196 3 : dlt_set_id(req->apid, "");
1197 3 : dlt_set_id(req->ctid, "");
1198 3 : dlt_set_id(req->com, "remo");
1199 :
1200 : /* send control message to daemon*/
1201 3 : ret = dlt_client_send_ctrl_msg(client, "", "", (uint8_t*)req, sizeof(DltServiceGetLogInfoRequest));
1202 :
1203 3 : free(req);
1204 :
1205 3 : return ret;
1206 : }
1207 :
1208 0 : int dlt_client_get_log_info_v2(DltClient* client)
1209 : {
1210 : DltServiceGetLogInfoRequestV2 req;
1211 : int ret = DLT_RETURN_ERROR;
1212 : uint8_t* buffer;
1213 : uint16_t buffersize;
1214 : uint16_t offset = 0;
1215 :
1216 0 : if (client == NULL)
1217 : return ret;
1218 :
1219 0 : req.service_id = DLT_SERVICE_ID_GET_LOG_INFO;
1220 0 : req.options = 7;
1221 0 : req.apidlen = 0;
1222 0 : req.apid = NULL;
1223 0 : req.ctidlen = 0;
1224 0 : req.ctid = NULL;
1225 0 : dlt_set_id(req.com, "remo");
1226 :
1227 0 : buffersize = DLT_SERVICE_GET_LOG_INFO_REQUEST_FIXED_SIZE_V2 + req.apidlen + req.ctidlen;
1228 :
1229 0 : buffer = (uint8_t*)malloc(buffersize);
1230 0 : if (buffer == NULL)
1231 : return ret;
1232 :
1233 : memcpy(buffer + offset, &(req.service_id), 4);
1234 : offset = offset + 4;
1235 0 : memcpy(buffer + offset, &(req.options), 1);
1236 : offset = offset + 1;
1237 0 : memcpy(buffer + offset, &(req.apidlen), 1);
1238 : offset = offset + 1;
1239 : // Since App Id is null, not copying it into buffer
1240 0 : memcpy(buffer + offset, &(req.ctidlen), 1);
1241 : offset = offset + 1;
1242 : // Since Context Id is null, not copying it into buffer
1243 0 : memcpy(buffer + offset, req.com, 4);
1244 :
1245 : /* send control message to daemon*/
1246 0 : ret = dlt_client_send_ctrl_msg_v2(client, "", "", (uint8_t*)buffer, buffersize);
1247 :
1248 0 : free(buffer);
1249 :
1250 0 : return ret;
1251 : }
1252 :
1253 1 : DltReturnValue dlt_client_get_default_log_level(DltClient* client)
1254 : {
1255 : DltServiceGetDefaultLogLevelRequest* req;
1256 : int ret = DLT_RETURN_ERROR;
1257 :
1258 1 : if (client == NULL)
1259 : return ret;
1260 :
1261 1 : req = (DltServiceGetDefaultLogLevelRequest*)malloc(sizeof(DltServiceGetDefaultLogLevelRequest));
1262 :
1263 1 : if (req == NULL)
1264 : return ret;
1265 :
1266 1 : req->service_id = DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL;
1267 :
1268 : /* send control message to daemon*/
1269 1 : ret = dlt_client_send_ctrl_msg(client, "", "", (uint8_t*)req, sizeof(DltServiceGetDefaultLogLevelRequest));
1270 :
1271 1 : free(req);
1272 :
1273 1 : return ret;
1274 : }
1275 :
1276 0 : DltReturnValue dlt_client_get_default_log_level_v2(DltClient* client)
1277 : {
1278 : DltServiceGetDefaultLogLevelRequest* req;
1279 : int ret = DLT_RETURN_ERROR;
1280 :
1281 0 : if (client == NULL)
1282 : return ret;
1283 :
1284 0 : req = (DltServiceGetDefaultLogLevelRequest*)malloc(sizeof(DltServiceGetDefaultLogLevelRequest));
1285 :
1286 0 : if (req == NULL)
1287 : return ret;
1288 :
1289 0 : req->service_id = DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL;
1290 :
1291 : /* send control message to daemon*/
1292 0 : ret = dlt_client_send_ctrl_msg_v2(client, "", "", (uint8_t*)req, sizeof(DltServiceGetDefaultLogLevelRequest));
1293 :
1294 0 : free(req);
1295 :
1296 0 : return ret;
1297 : }
1298 :
1299 3 : DltReturnValue dlt_client_get_software_version(DltClient* client)
1300 : {
1301 : DltServiceGetSoftwareVersion* req;
1302 : int ret = DLT_RETURN_ERROR;
1303 :
1304 3 : if (client == NULL)
1305 : return ret;
1306 :
1307 3 : req = (DltServiceGetSoftwareVersion*)malloc(sizeof(DltServiceGetSoftwareVersion));
1308 :
1309 3 : req->service_id = DLT_SERVICE_ID_GET_SOFTWARE_VERSION;
1310 :
1311 : /* send control message to daemon*/
1312 3 : ret = dlt_client_send_ctrl_msg(client, "", "", (uint8_t*)req, sizeof(DltServiceGetSoftwareVersion));
1313 :
1314 3 : free(req);
1315 :
1316 3 : return ret;
1317 : }
1318 :
1319 0 : int dlt_client_get_software_version_v2(DltClient* client)
1320 : {
1321 : DltServiceGetSoftwareVersion* req;
1322 : int ret = DLT_RETURN_ERROR;
1323 :
1324 0 : if (client == NULL)
1325 : return ret;
1326 :
1327 0 : req = (DltServiceGetSoftwareVersion*)malloc(sizeof(DltServiceGetSoftwareVersion));
1328 :
1329 0 : req->service_id = DLT_SERVICE_ID_GET_SOFTWARE_VERSION;
1330 :
1331 : /* send control message to daemon*/
1332 0 : ret = dlt_client_send_ctrl_msg_v2(client, "", "", (uint8_t*)req, sizeof(DltServiceGetSoftwareVersion));
1333 :
1334 0 : free(req);
1335 :
1336 0 : return ret;
1337 : }
1338 :
1339 0 : DltReturnValue dlt_client_send_trace_status(DltClient* client, char* apid, char* ctid, uint8_t traceStatus)
1340 : {
1341 : DltServiceSetLogLevel* req;
1342 :
1343 0 : req = calloc(1, sizeof(DltServiceSetLogLevel));
1344 :
1345 0 : if (req == 0)
1346 : return DLT_RETURN_ERROR;
1347 :
1348 0 : req->service_id = DLT_SERVICE_ID_SET_TRACE_STATUS;
1349 0 : dlt_set_id(req->apid, apid);
1350 0 : dlt_set_id(req->ctid, ctid);
1351 0 : req->log_level = traceStatus;
1352 0 : dlt_set_id(req->com, "remo");
1353 :
1354 : /* free message */
1355 0 : if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*)req, sizeof(DltServiceSetLogLevel))
1356 : == DLT_RETURN_ERROR) {
1357 0 : free(req);
1358 0 : return DLT_RETURN_ERROR;
1359 : }
1360 :
1361 0 : free(req);
1362 :
1363 0 : return DLT_RETURN_OK;
1364 : }
1365 :
1366 0 : DltReturnValue dlt_client_send_trace_status_v2(DltClient* client, char* apid, char* ctid, uint8_t traceStatus)
1367 : {
1368 : DltServiceSetLogLevelV2 req;
1369 : int ret = DLT_RETURN_ERROR;
1370 : uint8_t* buffer;
1371 : uint16_t buffersize;
1372 : uint16_t offset = 0;
1373 :
1374 0 : if (client == NULL)
1375 : return ret;
1376 :
1377 0 : req.service_id = DLT_SERVICE_ID_SET_TRACE_STATUS;
1378 0 : req.apidlen = strlen(apid);
1379 0 : req.apid = apid;
1380 0 : req.ctidlen = strlen(ctid);
1381 0 : req.ctid = ctid;
1382 0 : req.log_level = traceStatus;
1383 0 : dlt_set_id(req.com, "remo");
1384 :
1385 0 : buffersize = DLT_SERVICE_SET_LOG_LEVEL_FIXED_SIZE_V2 + req.apidlen + req.ctidlen;
1386 :
1387 0 : buffer = (uint8_t*)malloc(buffersize);
1388 0 : if (buffer == NULL)
1389 : return ret;
1390 :
1391 : memcpy(buffer + offset, &(req.service_id), 4);
1392 : offset = offset + 4;
1393 0 : memcpy(buffer + offset, &(req.apidlen), 1);
1394 : offset = offset + 1;
1395 0 : memcpy(buffer + offset, req.apid, req.apidlen);
1396 0 : offset = offset + req.apidlen;
1397 0 : memcpy(buffer + offset, &(req.ctidlen), 1);
1398 0 : offset = offset + 1;
1399 0 : memcpy(buffer + offset, req.ctid, req.ctidlen);
1400 0 : offset = offset + req.ctidlen;
1401 0 : memcpy(buffer + offset, &(req.log_level), 1);
1402 : offset = offset + 1;
1403 : memcpy(buffer, req.com, 4);
1404 :
1405 : /* free message */
1406 0 : ret = dlt_client_send_ctrl_msg_v2(client, "APP", "CON", (uint8_t*)buffer, buffersize);
1407 :
1408 :
1409 0 : free(buffer);
1410 :
1411 0 : return ret;
1412 : }
1413 :
1414 0 : DltReturnValue dlt_client_send_default_log_level(DltClient* client, uint8_t defaultLogLevel)
1415 : {
1416 : DltServiceSetDefaultLogLevel* req;
1417 :
1418 0 : req = calloc(1, sizeof(DltServiceSetDefaultLogLevel));
1419 :
1420 0 : if (req == 0)
1421 : return DLT_RETURN_ERROR;
1422 :
1423 0 : req->service_id = DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL;
1424 0 : req->log_level = defaultLogLevel;
1425 0 : dlt_set_id(req->com, "remo");
1426 :
1427 : /* free message */
1428 0 : if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*)req, sizeof(DltServiceSetDefaultLogLevel))
1429 : == DLT_RETURN_ERROR) {
1430 0 : free(req);
1431 0 : return DLT_RETURN_ERROR;
1432 : }
1433 :
1434 0 : free(req);
1435 :
1436 0 : return DLT_RETURN_OK;
1437 : }
1438 :
1439 0 : DltReturnValue dlt_client_send_default_log_level_v2(DltClient* client, uint8_t defaultLogLevel)
1440 : {
1441 : DltServiceSetDefaultLogLevel* req;
1442 :
1443 0 : req = calloc(1, sizeof(DltServiceSetDefaultLogLevel));
1444 :
1445 0 : if (req == 0)
1446 : return DLT_RETURN_ERROR;
1447 :
1448 0 : req->service_id = DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL;
1449 0 : req->log_level = defaultLogLevel;
1450 0 : dlt_set_id(req->com, "remo");
1451 :
1452 : /* free message */
1453 0 : if (dlt_client_send_ctrl_msg_v2(client, "APP", "CON", (uint8_t*)req, sizeof(DltServiceSetDefaultLogLevel))
1454 : == DLT_RETURN_ERROR) {
1455 0 : free(req);
1456 0 : return DLT_RETURN_ERROR;
1457 : }
1458 :
1459 0 : free(req);
1460 :
1461 0 : return DLT_RETURN_OK;
1462 : }
1463 :
1464 0 : DltReturnValue dlt_client_send_all_log_level(DltClient* client, uint8_t LogLevel)
1465 : {
1466 : DltServiceSetDefaultLogLevel* req;
1467 :
1468 0 : req = calloc(1, sizeof(DltServiceSetDefaultLogLevel));
1469 :
1470 0 : if (req == 0)
1471 : return DLT_RETURN_ERROR;
1472 :
1473 0 : req->service_id = DLT_SERVICE_ID_SET_ALL_LOG_LEVEL;
1474 0 : req->log_level = LogLevel;
1475 0 : dlt_set_id(req->com, "remo");
1476 :
1477 : /* free message */
1478 0 : if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*)req, sizeof(DltServiceSetDefaultLogLevel)) == -1) {
1479 0 : free(req);
1480 0 : return DLT_RETURN_ERROR;
1481 : }
1482 :
1483 0 : free(req);
1484 :
1485 0 : return DLT_RETURN_OK;
1486 : }
1487 :
1488 0 : DltReturnValue dlt_client_send_all_log_level_v2(DltClient* client, uint8_t LogLevel)
1489 : {
1490 : DltServiceSetDefaultLogLevel* req;
1491 :
1492 0 : req = calloc(1, sizeof(DltServiceSetDefaultLogLevel));
1493 :
1494 0 : if (req == 0)
1495 : return DLT_RETURN_ERROR;
1496 :
1497 0 : req->service_id = DLT_SERVICE_ID_SET_ALL_LOG_LEVEL;
1498 0 : req->log_level = LogLevel;
1499 0 : dlt_set_id(req->com, "remo");
1500 :
1501 : /* free message */
1502 0 : if (dlt_client_send_ctrl_msg_v2(client, "APP", "CON", (uint8_t*)req, sizeof(DltServiceSetDefaultLogLevel)) == -1) {
1503 0 : free(req);
1504 0 : return DLT_RETURN_ERROR;
1505 : }
1506 :
1507 0 : free(req);
1508 :
1509 0 : return DLT_RETURN_OK;
1510 : }
1511 :
1512 0 : DltReturnValue dlt_client_send_default_trace_status(DltClient* client, uint8_t defaultTraceStatus)
1513 : {
1514 : DltServiceSetDefaultLogLevel* req;
1515 :
1516 0 : req = calloc(1, sizeof(DltServiceSetDefaultLogLevel));
1517 :
1518 0 : if (req == 0)
1519 : return DLT_RETURN_ERROR;
1520 :
1521 0 : req->service_id = DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS;
1522 0 : req->log_level = defaultTraceStatus;
1523 0 : dlt_set_id(req->com, "remo");
1524 :
1525 : /* free message */
1526 0 : if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*)req, sizeof(DltServiceSetDefaultLogLevel))
1527 : == DLT_RETURN_ERROR) {
1528 0 : free(req);
1529 0 : return DLT_RETURN_ERROR;
1530 : }
1531 :
1532 0 : free(req);
1533 :
1534 0 : return DLT_RETURN_OK;
1535 : }
1536 :
1537 0 : DltReturnValue dlt_client_send_default_trace_status_v2(DltClient* client, uint8_t defaultTraceStatus)
1538 : {
1539 : DltServiceSetDefaultLogLevel* req;
1540 :
1541 0 : req = calloc(1, sizeof(DltServiceSetDefaultLogLevel));
1542 :
1543 0 : if (req == 0)
1544 : return DLT_RETURN_ERROR;
1545 :
1546 0 : req->service_id = DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS;
1547 0 : req->log_level = defaultTraceStatus;
1548 0 : dlt_set_id(req->com, "remo");
1549 :
1550 : /* free message */
1551 0 : if (dlt_client_send_ctrl_msg_v2(client, "APP", "CON", (uint8_t*)req, sizeof(DltServiceSetDefaultLogLevel))
1552 : == DLT_RETURN_ERROR) {
1553 0 : free(req);
1554 0 : return DLT_RETURN_ERROR;
1555 : }
1556 :
1557 0 : free(req);
1558 :
1559 0 : return DLT_RETURN_OK;
1560 : }
1561 :
1562 0 : DltReturnValue dlt_client_send_all_trace_status(DltClient* client, uint8_t traceStatus)
1563 : {
1564 : DltServiceSetDefaultLogLevel* req;
1565 :
1566 0 : if (client == NULL) {
1567 0 : dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__);
1568 0 : return DLT_RETURN_ERROR;
1569 : }
1570 :
1571 0 : req = calloc(1, sizeof(DltServiceSetDefaultLogLevel));
1572 :
1573 0 : if (req == 0) {
1574 0 : dlt_vlog(LOG_ERR, "%s: Could not allocate memory %zu\n", __func__, sizeof(DltServiceSetDefaultLogLevel));
1575 0 : return DLT_RETURN_ERROR;
1576 : }
1577 :
1578 0 : req->service_id = DLT_SERVICE_ID_SET_ALL_TRACE_STATUS;
1579 0 : req->log_level = traceStatus;
1580 0 : dlt_set_id(req->com, "remo");
1581 :
1582 : /* free message */
1583 0 : if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*)req, sizeof(DltServiceSetDefaultLogLevel)) == -1) {
1584 0 : free(req);
1585 : ;
1586 0 : return DLT_RETURN_ERROR;
1587 : }
1588 :
1589 0 : free(req);
1590 :
1591 0 : return DLT_RETURN_OK;
1592 : }
1593 :
1594 0 : DltReturnValue dlt_client_send_all_trace_status_v2(DltClient* client, uint8_t traceStatus)
1595 : {
1596 : DltServiceSetDefaultLogLevel* req;
1597 :
1598 0 : if (client == NULL) {
1599 0 : dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__);
1600 0 : return DLT_RETURN_ERROR;
1601 : }
1602 :
1603 0 : req = calloc(1, sizeof(DltServiceSetDefaultLogLevel));
1604 :
1605 0 : if (req == 0) {
1606 0 : dlt_vlog(LOG_ERR, "%s: Could not allocate memory %zu\n", __func__, sizeof(DltServiceSetDefaultLogLevel));
1607 0 : return DLT_RETURN_ERROR;
1608 : }
1609 :
1610 0 : req->service_id = DLT_SERVICE_ID_SET_ALL_TRACE_STATUS;
1611 0 : req->log_level = traceStatus;
1612 0 : dlt_set_id(req->com, "remo");
1613 :
1614 : /* free message */
1615 0 : if (dlt_client_send_ctrl_msg_v2(client, "APP", "CON", (uint8_t*)req, sizeof(DltServiceSetDefaultLogLevel)) == -1) {
1616 0 : free(req);
1617 : ;
1618 0 : return DLT_RETURN_ERROR;
1619 : }
1620 :
1621 0 : free(req);
1622 :
1623 0 : return DLT_RETURN_OK;
1624 : }
1625 :
1626 0 : DltReturnValue dlt_client_send_timing_pakets(DltClient* client, uint8_t timingPakets)
1627 : {
1628 : DltServiceSetVerboseMode* req;
1629 :
1630 0 : req = calloc(1, sizeof(DltServiceSetVerboseMode));
1631 :
1632 0 : if (req == 0)
1633 : return DLT_RETURN_ERROR;
1634 :
1635 0 : req->service_id = DLT_SERVICE_ID_SET_TIMING_PACKETS;
1636 0 : req->new_status = timingPakets;
1637 :
1638 : /* free message */
1639 0 : if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*)req, sizeof(DltServiceSetVerboseMode))
1640 : == DLT_RETURN_ERROR) {
1641 0 : free(req);
1642 0 : return DLT_RETURN_ERROR;
1643 : }
1644 :
1645 0 : free(req);
1646 :
1647 0 : return DLT_RETURN_OK;
1648 : }
1649 :
1650 0 : DltReturnValue dlt_client_send_timing_pakets_v2(DltClient* client, uint8_t timingPakets)
1651 : {
1652 : DltServiceSetVerboseMode* req;
1653 :
1654 0 : req = calloc(1, sizeof(DltServiceSetVerboseMode));
1655 :
1656 0 : if (req == 0)
1657 : return DLT_RETURN_ERROR;
1658 :
1659 0 : req->service_id = DLT_SERVICE_ID_SET_TIMING_PACKETS;
1660 0 : req->new_status = timingPakets;
1661 :
1662 : /* free message */
1663 0 : if (dlt_client_send_ctrl_msg_v2(client, "APP", "CON", (uint8_t*)req, sizeof(DltServiceSetVerboseMode))
1664 : == DLT_RETURN_ERROR) {
1665 0 : free(req);
1666 0 : return DLT_RETURN_ERROR;
1667 : }
1668 :
1669 0 : free(req);
1670 :
1671 0 : return DLT_RETURN_OK;
1672 : }
1673 :
1674 0 : DltReturnValue dlt_client_send_store_config(DltClient* client)
1675 : {
1676 : uint32_t service_id;
1677 :
1678 0 : service_id = DLT_SERVICE_ID_STORE_CONFIG;
1679 :
1680 : /* free message */
1681 0 : if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*)&service_id, sizeof(uint32_t)) == DLT_RETURN_ERROR)
1682 0 : return DLT_RETURN_ERROR;
1683 :
1684 : return DLT_RETURN_OK;
1685 : }
1686 :
1687 0 : DltReturnValue dlt_client_send_store_config_v2(DltClient* client)
1688 : {
1689 : uint32_t service_id;
1690 :
1691 0 : service_id = DLT_SERVICE_ID_STORE_CONFIG;
1692 :
1693 : /* free message */
1694 0 : if (dlt_client_send_ctrl_msg_v2(client, "APP", "CON", (uint8_t*)&service_id, sizeof(uint32_t)) == DLT_RETURN_ERROR)
1695 0 : return DLT_RETURN_ERROR;
1696 :
1697 : return DLT_RETURN_OK;
1698 : }
1699 :
1700 0 : DltReturnValue dlt_client_send_reset_to_factory_default(DltClient* client)
1701 : {
1702 : uint32_t service_id;
1703 :
1704 0 : service_id = DLT_SERVICE_ID_RESET_TO_FACTORY_DEFAULT;
1705 :
1706 : /* free message */
1707 0 : if (dlt_client_send_ctrl_msg(client, "APP", "CON", (uint8_t*)&service_id, sizeof(uint32_t)) == DLT_RETURN_ERROR)
1708 0 : return DLT_RETURN_ERROR;
1709 :
1710 : return DLT_RETURN_OK;
1711 : }
1712 :
1713 0 : DltReturnValue dlt_client_send_reset_to_factory_default_v2(DltClient* client)
1714 : {
1715 : uint32_t service_id;
1716 :
1717 0 : service_id = DLT_SERVICE_ID_RESET_TO_FACTORY_DEFAULT;
1718 :
1719 : /* free message */
1720 0 : if (dlt_client_send_ctrl_msg_v2(client, "APP", "CON", (uint8_t*)&service_id, sizeof(uint32_t)) == DLT_RETURN_ERROR)
1721 0 : return DLT_RETURN_ERROR;
1722 :
1723 : return DLT_RETURN_OK;
1724 : }
1725 :
1726 0 : DltReturnValue dlt_client_setbaudrate(DltClient* client, int baudrate)
1727 : {
1728 0 : if (client == 0)
1729 : return DLT_RETURN_ERROR;
1730 :
1731 0 : client->baudrate = dlt_convert_serial_speed(baudrate);
1732 :
1733 0 : return DLT_RETURN_OK;
1734 : }
1735 :
1736 0 : DltReturnValue dlt_client_set_mode(DltClient* client, DltClientMode mode)
1737 : {
1738 0 : if (client == 0)
1739 : return DLT_RETURN_ERROR;
1740 :
1741 0 : client->mode = mode;
1742 0 : return DLT_RETURN_OK;
1743 : }
1744 :
1745 5 : int dlt_client_set_server_ip(DltClient* client, char* ipaddr)
1746 : {
1747 5 : client->servIP = strdup(ipaddr);
1748 :
1749 5 : if (client->servIP == NULL) {
1750 0 : dlt_vlog(LOG_ERR, "%s: ERROR: failed to duplicate server IP\n", __func__);
1751 0 : return DLT_RETURN_ERROR;
1752 : }
1753 :
1754 : return DLT_RETURN_OK;
1755 : }
1756 :
1757 0 : int dlt_client_set_host_if_address(DltClient* client, char* hostip)
1758 : {
1759 0 : client->hostip = strdup(hostip);
1760 :
1761 0 : if (client->hostip == NULL) {
1762 0 : dlt_vlog(LOG_ERR, "%s: ERROR: failed to duplicate UDP interface address\n", __func__);
1763 0 : return DLT_RETURN_ERROR;
1764 : }
1765 :
1766 : return DLT_RETURN_OK;
1767 : }
1768 :
1769 0 : int dlt_client_set_serial_device(DltClient* client, char* serial_device)
1770 : {
1771 0 : client->serialDevice = strdup(serial_device);
1772 :
1773 0 : if (client->serialDevice == NULL) {
1774 0 : dlt_vlog(LOG_ERR, "%s: ERROR: failed to duplicate serial device\n", __func__);
1775 0 : return DLT_RETURN_ERROR;
1776 : }
1777 :
1778 : return DLT_RETURN_OK;
1779 : }
1780 :
1781 0 : int dlt_client_set_socket_path(DltClient* client, char* socket_path)
1782 : {
1783 0 : client->socketPath = strdup(socket_path);
1784 :
1785 0 : if (client->socketPath == NULL) {
1786 0 : dlt_vlog(LOG_ERR, "%s: ERROR: failed to duplicate socket path\n", __func__);
1787 0 : return DLT_RETURN_ERROR;
1788 : }
1789 :
1790 : return DLT_RETURN_OK;
1791 : }
1792 : /**
1793 : * free allocation when calloc failed get log info
1794 : *
1795 : * @param resp DltServiceGetLogInfoResponse
1796 : * @param count_app_ids number of app_ids which needs to be freed
1797 : */
1798 0 : DLT_STATIC void dlt_client_free_calloc_failed_get_log_info(DltServiceGetLogInfoResponse* resp, int count_app_ids)
1799 : {
1800 : AppIDsType* app = NULL;
1801 : ContextIDsInfoType* con = NULL;
1802 : int i = 0;
1803 : int j = 0;
1804 :
1805 0 : for (i = 0; i < count_app_ids; i++) {
1806 0 : app = &(resp->log_info_type.app_ids[i]);
1807 :
1808 0 : for (j = 0; j < app->count_context_ids; j++) {
1809 0 : con = &(app->context_id_info[j]);
1810 :
1811 0 : free(con->context_description);
1812 0 : con->context_description = NULL;
1813 : }
1814 :
1815 0 : free(app->app_description);
1816 0 : app->app_description = NULL;
1817 :
1818 0 : free(app->context_id_info);
1819 0 : app->context_id_info = NULL;
1820 : }
1821 :
1822 0 : free(resp->log_info_type.app_ids);
1823 0 : resp->log_info_type.app_ids = NULL;
1824 0 : resp->log_info_type.count_app_ids = 0;
1825 :
1826 0 : return;
1827 : }
1828 :
1829 : /**
1830 : * free allocation when calloc failed get log info v2
1831 : *
1832 : * @param resp DltServiceGetLogInfoResponse
1833 : * @param count_app_ids number of app_ids which needs to be freed
1834 : */
1835 0 : DLT_STATIC void dlt_client_free_calloc_failed_get_log_info_v2(DltServiceGetLogInfoResponse* resp, int count_app_ids)
1836 : {
1837 : AppIDsType* app = NULL;
1838 : ContextIDsInfoType* con = NULL;
1839 : int i = 0;
1840 : int j = 0;
1841 :
1842 0 : for (i = 0; i < count_app_ids; i++) {
1843 0 : app = &(resp->log_info_type.app_ids[i]);
1844 :
1845 0 : for (j = 0; j < app->count_context_ids; j++) {
1846 0 : con = &(app->context_id_info[j]);
1847 0 : free(con->context_id2);
1848 0 : free(con->context_description);
1849 0 : con->context_id2 = NULL;
1850 0 : con->context_description = NULL;
1851 : }
1852 :
1853 0 : free(app->app_id2);
1854 0 : free(app->app_description);
1855 0 : app->app_id2 = NULL;
1856 0 : app->app_description = NULL;
1857 :
1858 0 : free(app->context_id_info);
1859 0 : app->context_id_info = NULL;
1860 : }
1861 :
1862 0 : free(resp->log_info_type.app_ids);
1863 0 : resp->log_info_type.app_ids = NULL;
1864 0 : resp->log_info_type.count_app_ids = 0;
1865 :
1866 0 : return;
1867 : }
1868 :
1869 2 : DltReturnValue dlt_client_parse_get_log_info_resp_text(DltServiceGetLogInfoResponse* resp, char* resp_text)
1870 : {
1871 : AppIDsType* app = NULL;
1872 : ContextIDsInfoType* con = NULL;
1873 : int i = 0;
1874 : int j = 0;
1875 : char* rp = NULL;
1876 2 : int rp_count = 0;
1877 :
1878 2 : if ((resp == NULL) || (resp_text == NULL))
1879 : return DLT_RETURN_WRONG_PARAMETER;
1880 :
1881 : /* ------------------------------------------------------
1882 : * get_log_info data structure(all data is ascii)
1883 : *
1884 : * get_log_info, aa, bb bb cc cc cc cc dd dd ee ee ee ee ff gg hh hh ii ii ii .. ..
1885 : * ~~ ~~~~~ ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~
1886 : * cc cc cc cc dd dd ee ee ee ee ff gg hh hh ii ii ii .. ..
1887 : * jj jj kk kk kk .. ..
1888 : * ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~
1889 : * aa : get mode (fix value at 0x07)
1890 : * bb bb : list num of apid (little endian)
1891 : * cc cc cc cc: apid
1892 : * dd dd : list num of ctid (little endian)
1893 : * ee ee ee ee: ctid
1894 : * ff : log level
1895 : * gg : trace status
1896 : * hh hh : description length of ctid
1897 : * ii ii .. : description text of ctid
1898 : * jj jj : description length of apid
1899 : * kk kk .. : description text of apid
1900 : * ------------------------------------------------------ */
1901 :
1902 2 : rp = resp_text + DLT_GET_LOG_INFO_HEADER;
1903 : rp_count = 0;
1904 :
1905 : /* check if status is acceptable */
1906 2 : if ((resp->status < GET_LOG_INFO_STATUS_MIN) || (resp->status > GET_LOG_INFO_STATUS_MAX)) {
1907 0 : if (resp->status == GET_LOG_INFO_STATUS_NO_MATCHING_CTX)
1908 0 : dlt_vlog(LOG_WARNING, "%s: The status(%d) is invalid: NO matching Context IDs\n", __func__, resp->status);
1909 0 : else if (resp->status == GET_LOG_INFO_STATUS_RESP_DATA_OVERFLOW)
1910 0 : dlt_vlog(LOG_WARNING, "%s: The status(%d) is invalid: Response data over flow\n", __func__, resp->status);
1911 : else
1912 0 : dlt_vlog(LOG_WARNING, "%s: The status(%d) is invalid\n", __func__, resp->status);
1913 :
1914 0 : return DLT_RETURN_ERROR;
1915 : }
1916 :
1917 : /* count_app_ids */
1918 2 : resp->log_info_type.count_app_ids = (uint16_t)dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count);
1919 :
1920 2 : resp->log_info_type.app_ids = (AppIDsType*)calloc(resp->log_info_type.count_app_ids, sizeof(AppIDsType));
1921 :
1922 2 : if (resp->log_info_type.app_ids == NULL) {
1923 0 : dlt_vlog(LOG_ERR, "%s: calloc failed for app_ids\n", __func__);
1924 0 : dlt_client_free_calloc_failed_get_log_info(resp, 0);
1925 0 : return DLT_RETURN_ERROR;
1926 : }
1927 :
1928 5 : for (i = 0; i < resp->log_info_type.count_app_ids; i++) {
1929 3 : app = &(resp->log_info_type.app_ids[i]);
1930 : /* get app id */
1931 3 : dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, app->app_id, DLT_ID_SIZE);
1932 :
1933 : /* count_con_ids */
1934 3 : app->count_context_ids = (uint16_t)dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count);
1935 :
1936 3 : app->context_id_info = (ContextIDsInfoType*)calloc(app->count_context_ids, sizeof(ContextIDsInfoType));
1937 :
1938 3 : if (app->context_id_info == NULL) {
1939 0 : dlt_vlog(LOG_ERR, "%s: calloc failed for context_id_info\n", __func__);
1940 0 : dlt_client_free_calloc_failed_get_log_info(resp, i);
1941 0 : return DLT_RETURN_ERROR;
1942 : }
1943 :
1944 9 : for (j = 0; j < app->count_context_ids; j++) {
1945 6 : con = &(app->context_id_info[j]);
1946 : /* get con id */
1947 6 : dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, con->context_id, DLT_ID_SIZE);
1948 :
1949 : /* log_level */
1950 6 : if ((resp->status == 4) || (resp->status == 6) || (resp->status == 7))
1951 6 : con->log_level = dlt_getloginfo_conv_ascii_to_int16_t(rp, &rp_count);
1952 :
1953 : /* trace status */
1954 6 : if ((resp->status == 5) || (resp->status == 6) || (resp->status == 7))
1955 6 : con->trace_status = dlt_getloginfo_conv_ascii_to_int16_t(rp, &rp_count);
1956 :
1957 : /* context desc */
1958 6 : if (resp->status == 7) {
1959 6 : con->len_context_description = (uint16_t)dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count);
1960 6 : con->context_description = (char*)calloc((size_t)(con->len_context_description + 1), sizeof(char));
1961 :
1962 6 : if (con->context_description == NULL) {
1963 0 : dlt_vlog(LOG_ERR, "%s: calloc failed for context description\n", __func__);
1964 0 : dlt_client_free_calloc_failed_get_log_info(resp, i);
1965 0 : return DLT_RETURN_ERROR;
1966 : }
1967 :
1968 6 : dlt_getloginfo_conv_ascii_to_string(
1969 : rp, &rp_count, con->context_description, con->len_context_description);
1970 : }
1971 : }
1972 :
1973 : /* application desc */
1974 3 : if (resp->status == 7) {
1975 3 : app->len_app_description = (uint16_t)dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count);
1976 3 : app->app_description = (char*)calloc((size_t)(app->len_app_description + 1), sizeof(char));
1977 :
1978 3 : if (app->app_description == NULL) {
1979 0 : dlt_vlog(LOG_ERR, "%s: calloc failed for application description\n", __func__);
1980 0 : dlt_client_free_calloc_failed_get_log_info(resp, i);
1981 0 : return DLT_RETURN_ERROR;
1982 : }
1983 :
1984 3 : dlt_getloginfo_conv_ascii_to_string(rp, &rp_count, app->app_description, app->len_app_description);
1985 : }
1986 : }
1987 :
1988 : return DLT_RETURN_OK;
1989 : }
1990 :
1991 0 : DltReturnValue dlt_client_parse_get_log_info_resp_text_v2(DltServiceGetLogInfoResponse* resp, char* resp_text)
1992 : {
1993 : AppIDsType* app = NULL;
1994 : ContextIDsInfoType* con = NULL;
1995 : int i = 0;
1996 : int j = 0;
1997 : char* rp = NULL;
1998 0 : int rp_count = 0;
1999 :
2000 0 : if ((resp == NULL) || (resp_text == NULL))
2001 : return DLT_RETURN_WRONG_PARAMETER;
2002 :
2003 : /* ------------------------------------------------------
2004 : * get_log_info data structure(all data is ascii)
2005 : *
2006 : * get_log_info, aa, bb bb cc1 cc cc cc.... dd dd ee1 ee ee ee.... ff gg hh hh ii ii ii .. ..
2007 : * ~~ ~~~~~ ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~
2008 : * cc1 cc cc cc.... dd dd ee1 ee ee ee.... ff gg hh hh ii ii ii .. ..
2009 : * jj jj kk kk kk .. ..
2010 : * ~~~~~~~~~~~ ~~~~~ ~~~~~~~~~~~~~~
2011 : * aa : get mode (fix value at 0x07)
2012 : * bb bb : list num of apid (little endian)
2013 : * cc1 : length of apid
2014 : * cc cc cc cc: apid
2015 : * dd dd : list num of ctid (little endian)
2016 : * ee1 : length of ctid
2017 : * ee ee ee ee: ctid
2018 : * ff : log level
2019 : * gg : trace status
2020 : * hh hh : description length of ctid
2021 : * ii ii .. : description text of ctid
2022 : * jj jj : description length of apid
2023 : * kk kk .. : description text of apid
2024 : * ------------------------------------------------------ */
2025 :
2026 0 : rp = resp_text + DLT_GET_LOG_INFO_HEADER;
2027 : rp_count = 0;
2028 :
2029 : /* check if status is acceptable */
2030 0 : if ((resp->status < GET_LOG_INFO_STATUS_MIN) || (resp->status > GET_LOG_INFO_STATUS_MAX)) {
2031 0 : if (resp->status == GET_LOG_INFO_STATUS_NO_MATCHING_CTX)
2032 0 : dlt_vlog(LOG_WARNING, "%s: The status(%d) is invalid: NO matching Context IDs\n", __func__, resp->status);
2033 0 : else if (resp->status == GET_LOG_INFO_STATUS_RESP_DATA_OVERFLOW)
2034 0 : dlt_vlog(LOG_WARNING, "%s: The status(%d) is invalid: Response data over flow\n", __func__, resp->status);
2035 : else
2036 0 : dlt_vlog(LOG_WARNING, "%s: The status(%d) is invalid\n", __func__, resp->status);
2037 :
2038 0 : return DLT_RETURN_ERROR;
2039 : }
2040 :
2041 : /* count_app_ids */
2042 0 : uint16_t ret = dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count);
2043 0 : resp->log_info_type.count_app_ids = ret;
2044 :
2045 0 : resp->log_info_type.app_ids = (AppIDsType*)calloc(resp->log_info_type.count_app_ids, sizeof(AppIDsType));
2046 :
2047 0 : if (resp->log_info_type.app_ids == NULL) {
2048 0 : dlt_vlog(LOG_ERR, "%s: calloc failed for app_ids\n", __func__);
2049 0 : dlt_client_free_calloc_failed_get_log_info_v2(resp, 0);
2050 0 : return DLT_RETURN_ERROR;
2051 : }
2052 :
2053 0 : for (i = 0; i < resp->log_info_type.count_app_ids; i++) {
2054 0 : app = &(resp->log_info_type.app_ids[i]);
2055 0 : app->app_id2len = dlt_getloginfo_conv_ascii_to_uint8_t(rp, &rp_count);
2056 :
2057 0 : app->app_id2 = (char*)calloc((size_t)(app->app_id2len + 1), sizeof(char));
2058 :
2059 0 : if (app->app_id2 == NULL) {
2060 0 : dlt_vlog(LOG_ERR, "%s: calloc failed for App Id\n", __func__);
2061 0 : dlt_client_free_calloc_failed_get_log_info_v2(resp, i);
2062 0 : return DLT_RETURN_ERROR;
2063 : }
2064 : /* get app id */
2065 0 : dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, app->app_id2, app->app_id2len);
2066 :
2067 : /* count_con_ids */
2068 0 : ret = dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count);
2069 0 : app->count_context_ids = ret;
2070 0 : app->context_id_info = (ContextIDsInfoType*)calloc(app->count_context_ids, sizeof(ContextIDsInfoType));
2071 :
2072 0 : if (app->context_id_info == NULL) {
2073 0 : dlt_vlog(LOG_ERR, "%s: calloc failed for context_id_info\n", __func__);
2074 0 : dlt_client_free_calloc_failed_get_log_info_v2(resp, i);
2075 0 : return DLT_RETURN_ERROR;
2076 : }
2077 :
2078 0 : for (j = 0; j < app->count_context_ids; j++) {
2079 0 : con = &(app->context_id_info[j]);
2080 0 : con->context_id2len = dlt_getloginfo_conv_ascii_to_uint8_t(rp, &rp_count);
2081 0 : con->context_id2 = (char*)calloc((size_t)(con->context_id2len + 1), sizeof(char));
2082 :
2083 0 : if (con->context_id2 == NULL) {
2084 0 : dlt_vlog(LOG_ERR, "%s: calloc failed for Context Id\n", __func__);
2085 0 : dlt_client_free_calloc_failed_get_log_info_v2(resp, i);
2086 0 : return DLT_RETURN_ERROR;
2087 : }
2088 : /* get con id */
2089 0 : dlt_getloginfo_conv_ascii_to_id(rp, &rp_count, con->context_id2, con->context_id2len);
2090 :
2091 : /* log_level */
2092 0 : if ((resp->status == 4) || (resp->status == 6) || (resp->status == 7))
2093 0 : con->log_level = dlt_getloginfo_conv_ascii_to_int16_t(rp, &rp_count);
2094 :
2095 : /* trace status */
2096 0 : if ((resp->status == 5) || (resp->status == 6) || (resp->status == 7))
2097 0 : con->trace_status = dlt_getloginfo_conv_ascii_to_int16_t(rp, &rp_count);
2098 :
2099 : /* context desc */
2100 0 : if (resp->status == 7) {
2101 0 : con->len_context_description = (uint16_t)dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count);
2102 0 : con->context_description = (char*)calloc((size_t)(con->len_context_description + 1), sizeof(char));
2103 :
2104 0 : if (con->context_description == NULL) {
2105 0 : dlt_vlog(LOG_ERR, "%s: calloc failed for context description\n", __func__);
2106 0 : dlt_client_free_calloc_failed_get_log_info_v2(resp, i);
2107 0 : return DLT_RETURN_ERROR;
2108 : }
2109 :
2110 0 : dlt_getloginfo_conv_ascii_to_string(
2111 : rp, &rp_count, con->context_description, con->len_context_description);
2112 : }
2113 : }
2114 :
2115 : /* application desc */
2116 0 : if (resp->status == 7) {
2117 0 : app->len_app_description = (uint16_t)dlt_getloginfo_conv_ascii_to_uint16_t(rp, &rp_count);
2118 0 : app->app_description = (char*)calloc((size_t)(app->len_app_description + 1), sizeof(char));
2119 :
2120 0 : if (app->app_description == NULL) {
2121 0 : dlt_vlog(LOG_ERR, "%s: calloc failed for application description\n", __func__);
2122 0 : dlt_client_free_calloc_failed_get_log_info_v2(resp, i);
2123 0 : return DLT_RETURN_ERROR;
2124 : }
2125 :
2126 0 : dlt_getloginfo_conv_ascii_to_string(rp, &rp_count, app->app_description, app->len_app_description);
2127 : }
2128 : }
2129 :
2130 : return DLT_RETURN_OK;
2131 : }
2132 :
2133 2 : int dlt_client_cleanup_get_log_info(DltServiceGetLogInfoResponse* resp)
2134 : {
2135 : AppIDsType app;
2136 : int i = 0;
2137 : int j = 0;
2138 :
2139 2 : if (resp == NULL)
2140 : return DLT_RETURN_OK;
2141 :
2142 5 : for (i = 0; i < resp->log_info_type.count_app_ids; i++) {
2143 3 : app = resp->log_info_type.app_ids[i];
2144 :
2145 9 : for (j = 0; j < app.count_context_ids; j++) {
2146 6 : free(app.context_id_info[j].context_description);
2147 6 : app.context_id_info[j].context_description = NULL;
2148 : }
2149 :
2150 3 : free(app.context_id_info);
2151 : app.context_id_info = NULL;
2152 3 : free(app.app_description);
2153 : app.app_description = NULL;
2154 : }
2155 :
2156 2 : free(resp->log_info_type.app_ids);
2157 : resp->log_info_type.app_ids = NULL;
2158 :
2159 2 : free(resp);
2160 : resp = NULL;
2161 :
2162 2 : return DLT_RETURN_OK;
2163 : }
2164 :
2165 0 : int dlt_client_cleanup_get_log_info_v2(DltServiceGetLogInfoResponse* resp)
2166 : {
2167 : AppIDsType app;
2168 : int i = 0;
2169 : int j = 0;
2170 :
2171 0 : if (resp == NULL)
2172 : return DLT_RETURN_OK;
2173 :
2174 0 : for (i = 0; i < resp->log_info_type.count_app_ids; i++) {
2175 0 : app = resp->log_info_type.app_ids[i];
2176 :
2177 0 : for (j = 0; j < app.count_context_ids; j++) {
2178 0 : free(app.context_id_info[j].context_id2);
2179 0 : app.context_id_info[j].context_id2 = NULL;
2180 0 : free(app.context_id_info[j].context_description);
2181 0 : app.context_id_info[j].context_description = NULL;
2182 : }
2183 :
2184 0 : free(app.context_id_info);
2185 : app.context_id_info = NULL;
2186 0 : free(app.app_id2);
2187 : app.app_id2 = NULL;
2188 0 : free(app.app_description);
2189 : app.app_description = NULL;
2190 : }
2191 :
2192 0 : free(resp->log_info_type.app_ids);
2193 : resp->log_info_type.app_ids = NULL;
2194 :
2195 0 : free(resp);
2196 : resp = NULL;
2197 :
2198 0 : return DLT_RETURN_OK;
2199 : }
|