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
18 : * Alexander Wenzel <alexander.aw.wenzel@bmw.de>
19 : * Markus Klein <Markus.Klein@esk.fraunhofer.de>
20 : * Mikko Rapeli <mikko.rapeli@bmw.de>
21 : *
22 : * \copyright Copyright © 2011-2015 BMW AG. \n
23 : * License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
24 : *
25 : * \file dlt_daemon_client.c
26 : */
27 :
28 : #include <netdb.h>
29 : #include <ctype.h>
30 : #include <stdio.h> /* for printf() and fprintf() */
31 : #include <sys/socket.h> /* for socket(), connect(), (), and recv() */
32 : #include <sys/stat.h> /* for stat() */
33 : #include <arpa/inet.h> /* for sockaddr_in and inet_addr() */
34 : #include <stdlib.h> /* for atoi() and exit() */
35 : #include <string.h> /* for memset() */
36 : #include <unistd.h> /* for close() */
37 : #include <signal.h>
38 : #include <syslog.h>
39 : #include <errno.h>
40 : #include <pthread.h>
41 :
42 : #ifdef linux
43 : # include <sys/timerfd.h>
44 : #endif
45 : #include <sys/time.h>
46 : #if defined(linux) && defined(__NR_statx)
47 : # include <linux/stat.h>
48 : #endif
49 :
50 : #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE
51 : # include <systemd/sd-daemon.h>
52 : #endif
53 :
54 : #include "dlt_types.h"
55 : #include "dlt_log.h"
56 : #include "dlt-daemon.h"
57 : #include "dlt-daemon_cfg.h"
58 : #include "dlt_daemon_common_cfg.h"
59 :
60 : #include "dlt_daemon_socket.h"
61 : #include "dlt_daemon_serial.h"
62 :
63 : #include "dlt_daemon_client.h"
64 : #include "dlt_daemon_connection.h"
65 : #include "dlt_daemon_event_handler.h"
66 :
67 : #include "dlt_daemon_offline_logstorage.h"
68 : #include "dlt_gateway.h"
69 : #ifdef UDP_CONNECTION_SUPPORT
70 : # include "dlt_daemon_udp_socket.h"
71 : #endif
72 :
73 : /** Inline function to calculate/set the requested log level or traces status
74 : * with default log level or trace status when "ForceContextLogLevelAndTraceStatus"
75 : * is enabled and set to 1 in dlt.conf file.
76 : *
77 : * @param request_log The requested log level (or) trace status
78 : * @param context_log The default log level (or) trace status
79 : *
80 : * @return The log level if requested log level is lower or equal to ContextLogLevel
81 : */
82 : static inline int8_t getStatus(uint8_t request_log, int context_log)
83 : {
84 0 : return (int8_t)((request_log <= context_log) ? request_log : context_log);
85 : }
86 :
87 : /** @brief Sends up to 2 messages to all the clients.
88 : *
89 : * Runs through the client list and sends the messages to them. If the message
90 : * transfer fails and the connection is a socket connection, the socket is closed.
91 : * Takes and release dlt_daemon_mutex.
92 : *
93 : * @param daemon Daemon structure needed for socket closure.
94 : * @param daemon_local Daemon local structure
95 : * @param data1 The first message to be sent.
96 : * @param size1 The size of the first message.
97 : * @param data2 The second message to be send.
98 : * @param size2 The second message size.
99 : * @param verbose Needed for socket closure.
100 : *
101 : * @return The amount of data transferred.
102 : */
103 0 : static int dlt_daemon_client_send_all_multiple(DltDaemon *daemon,
104 : DltDaemonLocal *daemon_local,
105 : void *data1,
106 : int size1,
107 : void *data2,
108 : int size2,
109 : int verbose)
110 : {
111 : int sent = 0;
112 : nfds_t i = 0;
113 : int ret = 0;
114 : DltConnection *temp = NULL;
115 : int type_mask =
116 : (DLT_CON_MASK_CLIENT_MSG_TCP | DLT_CON_MASK_CLIENT_MSG_SERIAL);
117 :
118 0 : PRINT_FUNCTION_VERBOSE(verbose);
119 :
120 0 : if ((daemon == NULL) || (daemon_local == NULL)) {
121 0 : dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__);
122 0 : return 0;
123 : }
124 :
125 0 : for (i = 0; i < daemon_local->pEvent.nfds; i++)
126 : {
127 : #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE
128 : bool watchdog_triggered = dlt_daemon_trigger_systemd_watchdog_if_necessary(daemon);
129 : if (watchdog_triggered) {
130 : dlt_vlog(LOG_WARNING, "%s notified watchdog, processed %lu/%lu fds already.\n",
131 : __func__, i, daemon_local->pEvent.nfds);
132 : }
133 : #endif
134 0 : temp = dlt_event_handler_find_connection(&(daemon_local->pEvent),
135 0 : daemon_local->pEvent.pfd[i].fd);
136 :
137 0 : if ((temp == NULL) || (temp->receiver == NULL) ||
138 0 : !((1 << temp->type) & type_mask)) {
139 0 : dlt_log(LOG_DEBUG, "The connection not found or the connection type not TCP/Serial.\n");
140 0 : continue;
141 : }
142 :
143 0 : ret = dlt_connection_send_multiple(temp,
144 : data1,
145 : size1,
146 : data2,
147 : size2,
148 : daemon->sendserialheader);
149 :
150 0 : if ((ret != DLT_DAEMON_ERROR_OK) &&
151 0 : (DLT_CONNECTION_CLIENT_MSG_TCP == temp->type)) {
152 0 : dlt_daemon_close_socket(temp->receiver->fd,
153 : daemon,
154 : daemon_local,
155 : verbose);
156 : }
157 :
158 : if (ret != DLT_DAEMON_ERROR_OK)
159 0 : dlt_vlog(LOG_WARNING, "%s: send dlt message failed\n", __func__);
160 : else
161 : /* If sent to at least one client,
162 : * then do not store in ring buffer
163 : */
164 : sent = 1;
165 : } /* for */
166 :
167 : #ifdef DLT_TRACE_LOAD_CTRL_ENABLE
168 : if (sent)
169 : {
170 : const uint32_t serial_header = daemon->sendserialheader ? sizeof(dltSerialHeader) : 0;
171 : daemon->bytes_sent += size1 + size2 + serial_header;
172 : }
173 : #endif
174 :
175 : return sent;
176 : }
177 :
178 : /* TODO: Extract the storage header v2 from buffer */
179 394 : int dlt_daemon_client_send(int sock,
180 : DltDaemon *daemon,
181 : DltDaemonLocal *daemon_local,
182 : void *storage_header,
183 : int storage_header_size,
184 : void *data1,
185 : int size1,
186 : void *data2,
187 : int size2,
188 : int verbose)
189 : {
190 : int sent, ret;
191 : int ret_logstorage = 0;
192 : static int sent_message_overflow_cnt = 0;
193 :
194 394 : if ((daemon == NULL) || (daemon_local == NULL)) {
195 0 : dlt_vlog(LOG_ERR, "%s: Invalid arguments\n", __func__);
196 0 : return DLT_DAEMON_ERROR_UNKNOWN;
197 : }
198 :
199 394 : if ((sock != DLT_DAEMON_SEND_TO_ALL) && (sock != DLT_DAEMON_SEND_FORCE)) {
200 : /* Send message to specific socket */
201 1 : if (isatty(sock)) {
202 0 : if ((ret =
203 0 : dlt_daemon_serial_send(sock, data1, size1, data2, size2,
204 0 : (char)daemon->sendserialheader))) {
205 0 : dlt_vlog(LOG_WARNING, "%s: serial send dlt message failed\n", __func__);
206 0 : return ret;
207 : }
208 : } else {
209 1 : if ((ret =
210 1 : dlt_daemon_socket_send(sock, data1, size1, data2, size2,
211 1 : (char)daemon->sendserialheader))) {
212 0 : dlt_vlog(LOG_WARNING, "%s: socket send dlt message failed\n", __func__);
213 0 : return ret;
214 : }
215 : }
216 :
217 1 : return DLT_DAEMON_ERROR_OK;
218 : }
219 :
220 : /* write message to offline trace */
221 : /* In the SEND_BUFFER state we must skip offline tracing because the offline traces */
222 : /* are going without buffering directly to the offline trace. Thus we have to filter out */
223 : /* the traces that are coming from the buffer. */
224 393 : if ((sock != DLT_DAEMON_SEND_FORCE) && (daemon->state != DLT_DAEMON_STATE_SEND_BUFFER)) {
225 393 : if (((daemon->mode == DLT_USER_MODE_INTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH))
226 0 : && daemon_local->flags.offlineTraceDirectory[0]) {
227 0 : if (dlt_offline_trace_write(&(daemon_local->offlineTrace), storage_header, storage_header_size, data1,
228 : size1, data2, size2)) {
229 : static int error_dlt_offline_trace_write_failed = 0;
230 :
231 0 : if (!error_dlt_offline_trace_write_failed) {
232 0 : dlt_vlog(LOG_ERR, "%s: dlt_offline_trace_write failed!\n", __func__);
233 0 : error_dlt_offline_trace_write_failed = 1;
234 : }
235 :
236 : /*return DLT_DAEMON_ERROR_WRITE_FAILED; */
237 : }
238 : }
239 :
240 : /* write messages to offline logstorage only if there is an extended header set
241 : * this need to be checked because the function is dlt_daemon_client_send is called by
242 : * newly introduced dlt_daemon_log_internal */
243 393 : if (daemon_local->flags.offlineLogstorageMaxDevices > 0)
244 393 : ret_logstorage = dlt_daemon_logstorage_write(daemon,
245 : &daemon_local->flags,
246 : storage_header,
247 : storage_header_size,
248 : data1,
249 : size1,
250 : data2,
251 : size2);
252 : }
253 :
254 : /* send messages to daemon socket */
255 393 : if ((daemon->mode == DLT_USER_MODE_EXTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) {
256 : #ifdef UDP_CONNECTION_SUPPORT
257 : if (daemon_local->UDPConnectionSetup == MULTICAST_CONNECTION_ENABLED) {
258 : /* Forward message to network client if network routing is not disabled */
259 : if (ret_logstorage != 1) {
260 : dlt_daemon_udp_dltmsg_multicast(data1,
261 : size1,
262 : data2,
263 : size2,
264 : verbose);
265 : }
266 : }
267 :
268 : #endif
269 :
270 393 : if ((sock == DLT_DAEMON_SEND_FORCE) || (daemon->state == DLT_DAEMON_STATE_SEND_DIRECT)) {
271 : /* Forward message to network client if network routing is not disabled */
272 0 : if (ret_logstorage != 1) {
273 0 : sent = dlt_daemon_client_send_all_multiple(daemon,
274 : daemon_local,
275 : data1,
276 : size1,
277 : data2,
278 : size2,
279 : verbose);
280 :
281 0 : if ((sock == DLT_DAEMON_SEND_FORCE) && !sent) {
282 : return DLT_DAEMON_ERROR_SEND_FAILED;
283 : }
284 : }
285 : }
286 : }
287 :
288 : /* Message was not sent to client, so store it in client ringbuffer */
289 393 : if ((sock != DLT_DAEMON_SEND_FORCE) &&
290 393 : ((daemon->state == DLT_DAEMON_STATE_BUFFER) || (daemon->state == DLT_DAEMON_STATE_SEND_BUFFER) ||
291 : (daemon->state == DLT_DAEMON_STATE_BUFFER_FULL))) {
292 393 : if (daemon->state != DLT_DAEMON_STATE_BUFFER_FULL) {
293 : /* Store message in history buffer */
294 393 : ret = dlt_buffer_push3(&(daemon->client_ringbuffer), data1, (unsigned int)size1, data2, (unsigned int)size2, 0U, 0U);
295 393 : if (ret < DLT_RETURN_OK) {
296 0 : dlt_daemon_change_state(daemon, DLT_DAEMON_STATE_BUFFER_FULL);
297 : }
298 : }
299 393 : if (daemon->state == DLT_DAEMON_STATE_BUFFER_FULL) {
300 0 : daemon->overflow_counter += 1;
301 0 : if (daemon->overflow_counter == 1)
302 0 : dlt_vlog(LOG_INFO, "%s: Buffer is full! Messages will be discarded.\n", __func__);
303 :
304 0 : return DLT_DAEMON_ERROR_BUFFER_FULL;
305 : }
306 : } else {
307 0 : if ((daemon->overflow_counter > 0) &&
308 0 : (daemon_local->client_connections > 0)) {
309 0 : sent_message_overflow_cnt++;
310 0 : if (sent_message_overflow_cnt >= 2) {
311 0 : sent_message_overflow_cnt--;
312 : }
313 : else {
314 0 : if (dlt_daemon_send_message_overflow(daemon, daemon_local,
315 : verbose) == DLT_DAEMON_ERROR_OK) {
316 0 : dlt_vlog(LOG_WARNING,
317 : "%s: %u messages discarded! Now able to send messages to the client.\n",
318 : __func__,
319 : daemon->overflow_counter);
320 0 : daemon->overflow_counter = 0;
321 0 : sent_message_overflow_cnt--;
322 : }
323 : }
324 : }
325 : }
326 :
327 : return DLT_DAEMON_ERROR_OK;
328 :
329 : }
330 :
331 0 : int dlt_daemon_client_send_v2(int sock,
332 : DltDaemon *daemon,
333 : DltDaemonLocal *daemon_local,
334 : void *storage_header,
335 : int storage_header_size,
336 : void *data1,
337 : int size1,
338 : void *data2,
339 : int size2,
340 : int verbose)
341 : {
342 : int sent, ret;
343 : int ret_logstorage = 0;
344 : static int sent_message_overflow_cnt = 0;
345 :
346 0 : if ((daemon == NULL) || (daemon_local == NULL)) {
347 0 : dlt_vlog(LOG_ERR, "%s: Invalid arguments\n", __func__);
348 0 : return DLT_DAEMON_ERROR_UNKNOWN;
349 : }
350 :
351 0 : if ((sock != DLT_DAEMON_SEND_TO_ALL) && (sock != DLT_DAEMON_SEND_FORCE)) {
352 : /* Send message to specific socket */
353 0 : if (isatty(sock)) {
354 0 : if ((ret =
355 0 : dlt_daemon_serial_send(sock, data1, size1, data2, size2,
356 0 : (char)daemon->sendserialheader))) {
357 0 : dlt_vlog(LOG_WARNING, "%s: serial send dlt message failed\n", __func__);
358 0 : return ret;
359 : }
360 : } else {
361 0 : if ((ret =
362 0 : dlt_daemon_socket_send(sock, data1, size1, data2, size2,
363 0 : (char)daemon->sendserialheader))) {
364 0 : dlt_vlog(LOG_WARNING, "%s: socket send dlt message failed\n", __func__);
365 0 : return ret;
366 : }
367 : }
368 :
369 0 : return DLT_DAEMON_ERROR_OK;
370 : }
371 :
372 : /* write message to offline trace */
373 : /* In the SEND_BUFFER state we must skip offline tracing because the offline traces */
374 : /* are going without buffering directly to the offline trace. Thus we have to filter out */
375 : /* the traces that are coming from the buffer. */
376 0 : if ((sock != DLT_DAEMON_SEND_FORCE) && (daemon->state != DLT_DAEMON_STATE_SEND_BUFFER)) {
377 0 : if (((daemon->mode == DLT_USER_MODE_INTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH))
378 0 : && daemon_local->flags.offlineTraceDirectory[0]) {
379 : /* To update for v2*/
380 0 : if (dlt_offline_trace_write(&(daemon_local->offlineTrace), storage_header, storage_header_size, data1,
381 : size1, data2, size2)) {
382 : static int error_dlt_offline_trace_write_failed = 0;
383 :
384 0 : if (!error_dlt_offline_trace_write_failed) {
385 0 : dlt_vlog(LOG_ERR, "%s: dlt_offline_trace_write failed!\n", __func__);
386 0 : error_dlt_offline_trace_write_failed = 1;
387 : }
388 :
389 : /*return DLT_DAEMON_ERROR_WRITE_FAILED; */
390 : }
391 : }
392 :
393 : /* write messages to offline logstorage only if there is an extended header set
394 : * this need to be checked because the function is dlt_daemon_client_send is called by
395 : * newly introduced dlt_daemon_log_internal */
396 : /* To Update to dlt_daemon_logstorage_write_v2*/
397 0 : if (daemon_local->flags.offlineLogstorageMaxDevices > 0)
398 0 : ret_logstorage = dlt_daemon_logstorage_write(daemon,
399 : &daemon_local->flags,
400 : storage_header,
401 : storage_header_size,
402 : data1,
403 : size1,
404 : data2,
405 : size2);
406 : }
407 :
408 : /* send messages to daemon socket */
409 0 : if ((daemon->mode == DLT_USER_MODE_EXTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) {
410 : #ifdef UDP_CONNECTION_SUPPORT
411 : if (daemon_local->UDPConnectionSetup == MULTICAST_CONNECTION_ENABLED) {
412 : /* Forward message to network client if network routing is not disabled */
413 : if (ret_logstorage != 1) {
414 : dlt_daemon_udp_dltmsg_multicast(data1,
415 : size1,
416 : data2,
417 : size2,
418 : verbose);
419 : }
420 : }
421 :
422 : #endif
423 :
424 0 : if ((sock == DLT_DAEMON_SEND_FORCE) || (daemon->state == DLT_DAEMON_STATE_SEND_DIRECT)) {
425 : /* Forward message to network client if network routing is not disabled */
426 0 : if (ret_logstorage != 1) {
427 0 : sent = dlt_daemon_client_send_all_multiple(daemon,
428 : daemon_local,
429 : data1,
430 : size1,
431 : data2,
432 : size2,
433 : verbose);
434 :
435 0 : if ((sock == DLT_DAEMON_SEND_FORCE) && !sent) {
436 : return DLT_DAEMON_ERROR_SEND_FAILED;
437 : }
438 : }
439 : }
440 : }
441 :
442 : /* Message was not sent to client, so store it in client ringbuffer */
443 0 : if ((sock != DLT_DAEMON_SEND_FORCE) &&
444 0 : ((daemon->state == DLT_DAEMON_STATE_BUFFER) || (daemon->state == DLT_DAEMON_STATE_SEND_BUFFER) ||
445 : (daemon->state == DLT_DAEMON_STATE_BUFFER_FULL))) {
446 0 : if (daemon->state != DLT_DAEMON_STATE_BUFFER_FULL) {
447 : /* Store message in history buffer */
448 0 : ret = dlt_buffer_push3(&(daemon->client_ringbuffer), data1, (unsigned int)size1, data2, (unsigned int)size2, 0, 0);
449 0 : if (ret < DLT_RETURN_OK) {
450 0 : dlt_daemon_change_state(daemon, DLT_DAEMON_STATE_BUFFER_FULL);
451 : }
452 : }
453 0 : if (daemon->state == DLT_DAEMON_STATE_BUFFER_FULL) {
454 0 : daemon->overflow_counter += 1;
455 0 : if (daemon->overflow_counter == 1)
456 0 : dlt_vlog(LOG_INFO, "%s: Buffer is full! Messages will be discarded.\n", __func__);
457 :
458 0 : return DLT_DAEMON_ERROR_BUFFER_FULL;
459 : }
460 : } else {
461 0 : if ((daemon->overflow_counter > 0) &&
462 0 : (daemon_local->client_connections > 0)) {
463 0 : sent_message_overflow_cnt++;
464 0 : if (sent_message_overflow_cnt >= 2) {
465 0 : sent_message_overflow_cnt--;
466 : }
467 : else {
468 0 : if (dlt_daemon_send_message_overflow_v2(daemon, daemon_local,
469 : verbose) == DLT_DAEMON_ERROR_OK) {
470 0 : dlt_vlog(LOG_WARNING,
471 : "%s: %u messages discarded! Now able to send messages to the client.\n",
472 : __func__,
473 : daemon->overflow_counter);
474 0 : daemon->overflow_counter = 0;
475 0 : sent_message_overflow_cnt--;
476 : }
477 : }
478 : }
479 : }
480 :
481 : return DLT_DAEMON_ERROR_OK;
482 :
483 : }
484 :
485 389 : int dlt_daemon_client_send_message_to_all_client(DltDaemon *daemon,
486 : DltDaemonLocal *daemon_local,
487 : int verbose)
488 : {
489 : static char text[DLT_DAEMON_TEXTSIZE];
490 : char * ecu_ptr = NULL;
491 :
492 389 : PRINT_FUNCTION_VERBOSE(verbose);
493 :
494 389 : if ((daemon == NULL) || (daemon_local == NULL)) {
495 0 : dlt_vlog(LOG_ERR, "%s: invalid arguments\n", __func__);
496 0 : return DLT_DAEMON_ERROR_UNKNOWN;
497 : }
498 :
499 : /* set overwrite ecu id */
500 389 : if ((daemon_local->flags.evalue[0]) &&
501 0 : (strncmp(daemon_local->msg.headerextra.ecu,
502 : DLT_DAEMON_ECU_ID, DLT_ID_SIZE) == 0)) {
503 : /* Set header extra parameters */
504 0 : dlt_set_id(daemon_local->msg.headerextra.ecu, daemon->ecuid);
505 :
506 : /*msg.headerextra.seid = 0; */
507 0 : if (dlt_message_set_extraparameters(&(daemon_local->msg), 0)) {
508 0 : dlt_vlog(LOG_WARNING,
509 : "%s: failed to set message extra parameters.\n", __func__);
510 0 : return DLT_DAEMON_ERROR_UNKNOWN;
511 : }
512 :
513 : /* Correct value of timestamp, this was changed by dlt_message_set_extraparameters() */
514 0 : daemon_local->msg.headerextra.tmsp =
515 0 : DLT_BETOH_32(daemon_local->msg.headerextra.tmsp);
516 : }
517 :
518 : /* prepare storage header */
519 389 : if (DLT_IS_HTYP_WEID(daemon_local->msg.standardheader->htyp)) {
520 389 : ecu_ptr = daemon_local->msg.headerextra.ecu;
521 : } else {
522 0 : ecu_ptr = daemon->ecuid;
523 : }
524 :
525 389 : if (dlt_set_storageheader(daemon_local->msg.storageheader, ecu_ptr)) {
526 0 : dlt_vlog(LOG_WARNING,
527 : "%s: failed to set storage header with header type: 0x%x\n",
528 0 : __func__, daemon_local->msg.standardheader->htyp);
529 0 : return DLT_DAEMON_ERROR_UNKNOWN;
530 : }
531 :
532 : /* if no filter set or filter is matching display message */
533 389 : if (daemon_local->flags.xflag) {
534 0 : if (DLT_RETURN_OK !=
535 0 : dlt_message_print_hex(&(daemon_local->msg), text,
536 : DLT_DAEMON_TEXTSIZE, verbose))
537 0 : dlt_log(LOG_WARNING, "dlt_message_print_hex() failed!\n");
538 389 : } else if (daemon_local->flags.aflag) {
539 0 : if (DLT_RETURN_OK !=
540 0 : dlt_message_print_ascii(&(daemon_local->msg), text,
541 : DLT_DAEMON_TEXTSIZE, verbose))
542 0 : dlt_log(LOG_WARNING, "dlt_message_print_ascii() failed!\n");
543 389 : } else if (daemon_local->flags.sflag) {
544 0 : if (DLT_RETURN_OK !=
545 0 : dlt_message_print_header(&(daemon_local->msg), text,
546 : DLT_DAEMON_TEXTSIZE, verbose))
547 0 : dlt_log(LOG_WARNING, "dlt_message_print_header() failed!\n");
548 : }
549 :
550 : /* send message to client or write to log file */
551 389 : return dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local,
552 389 : daemon_local->msg.headerbuffer, sizeof(DltStorageHeader),
553 : daemon_local->msg.headerbuffer + sizeof(DltStorageHeader),
554 389 : (size_t)(daemon_local->msg.headersize - (int32_t)sizeof(DltStorageHeader)),
555 389 : daemon_local->msg.databuffer, (size_t)daemon_local->msg.datasize, verbose);
556 :
557 : }
558 :
559 0 : int dlt_daemon_client_send_message_to_all_client_v2(DltDaemon *daemon,
560 : DltDaemonLocal *daemon_local,
561 : int verbose)
562 : {
563 : static char text[DLT_DAEMON_TEXTSIZE];
564 : char * ecu_ptr = NULL;
565 : uint8_t ecu_len = 0;
566 : uint32_t temp_extended_size = 0;
567 0 : uint8_t *temp_buffer = (uint8_t *)malloc((size_t)daemon_local->msgv2.headersizev2);
568 0 : if (temp_buffer == NULL) {
569 : return DLT_RETURN_ERROR;
570 : }
571 : /* Store headerbuffer in temp buffer BEFORE replacing the original buffer */
572 0 : memcpy(temp_buffer, daemon_local->msgv2.headerbufferv2, (size_t)daemon_local->msgv2.headersizev2);
573 :
574 0 : PRINT_FUNCTION_VERBOSE(verbose);
575 :
576 0 : if ((daemon == NULL) || (daemon_local == NULL)) {
577 0 : dlt_vlog(LOG_ERR, "%s: invalid arguments\n", __func__);
578 0 : return DLT_DAEMON_ERROR_UNKNOWN;
579 : }
580 :
581 0 : temp_extended_size = daemon_local->msgv2.extendedheadersizev2;
582 : /* set overwrite ecu id */
583 0 : if ((daemon_local->flags.evalue[0]) &&
584 0 : (strncmp(daemon_local->msgv2.extendedheaderv2.ecid,
585 0 : DLT_DAEMON_ECU_ID, daemon_local->msgv2.extendedheaderv2.ecidlen) == 0)) {
586 0 : daemon_local->msgv2.extendedheaderv2.ecidlen = daemon->ecuid2len;
587 0 : dlt_set_id_v2(daemon_local->msgv2.extendedheaderv2.ecid, daemon->ecuid2, daemon->ecuid2len);
588 :
589 0 : daemon_local->msgv2.extendedheaderv2.seid = 0;
590 :
591 : /* Get new extended header size and header size, update header buffer*/
592 0 : daemon_local->msgv2.extendedheadersizev2 = dlt_message_get_extendedparameters_size_v2(&(daemon_local->msgv2));
593 : }
594 :
595 : /* Save old storage header size before we recalculate it */
596 0 : uint32_t old_storage_size = daemon_local->msgv2.storageheadersizev2;
597 :
598 : /* prepare storage header */
599 0 : if (DLT_IS_HTYP2_WEID(daemon_local->msgv2.baseheaderv2->htyp2)) {
600 0 : ecu_ptr = daemon_local->msgv2.extendedheaderv2.ecid;
601 0 : ecu_len = daemon_local->msgv2.extendedheaderv2.ecidlen;
602 : } else {
603 0 : ecu_ptr = daemon->ecuid2;
604 0 : ecu_len = daemon->ecuid2len;
605 : }
606 :
607 0 : daemon_local->msgv2.storageheadersizev2 = (uint32_t)(STORAGE_HEADER_V2_FIXED_SIZE + ecu_len);
608 :
609 0 : if (dlt_set_storageheader_v2(&(daemon_local->msgv2.storageheaderv2), ecu_len, ecu_ptr)) {
610 0 : dlt_vlog(LOG_WARNING,
611 : "%s: failed to set storage header with header type: 0x%x\n",
612 0 : __func__, daemon_local->msg.standardheader->htyp);
613 0 : return DLT_DAEMON_ERROR_UNKNOWN;
614 : }
615 :
616 0 : daemon_local->msgv2.headersizev2 = (int32_t)((uint32_t)daemon_local->msgv2.headersizev2 - temp_extended_size +
617 0 : daemon_local->msgv2.extendedheadersizev2 + daemon_local->msgv2.storageheadersizev2);
618 :
619 : /* allocate new header buffer, copy cached header parts into it, then replace the old buffer */
620 0 : uint8_t *new_headerbufferv2 = (uint8_t *)malloc((size_t)daemon_local->msgv2.headersizev2);
621 0 : if (new_headerbufferv2 == NULL) {
622 0 : free(temp_buffer);
623 0 : return DLT_RETURN_ERROR;
624 : }
625 :
626 0 : if (dlt_message_set_storageparameters_v2(&(daemon_local->msgv2), 0) != DLT_RETURN_OK) {
627 0 : free(temp_buffer);
628 0 : free(new_headerbufferv2);
629 0 : return DLT_RETURN_ERROR;
630 : }
631 :
632 : /* Copy base header + base header extra from temp buffer (skip old storage header) */
633 0 : memcpy(new_headerbufferv2 + daemon_local->msgv2.storageheadersizev2,
634 0 : temp_buffer + old_storage_size,
635 0 : (daemon_local->msgv2.baseheadersizev2 + daemon_local->msgv2.baseheaderextrasizev2));
636 :
637 : /* Copy extended header from temp buffer */
638 0 : uint32_t old_extended_offset = old_storage_size + daemon_local->msgv2.baseheadersizev2 + daemon_local->msgv2.baseheaderextrasizev2;
639 0 : uint32_t new_extended_offset = daemon_local->msgv2.storageheadersizev2 + daemon_local->msgv2.baseheadersizev2 + daemon_local->msgv2.baseheaderextrasizev2;
640 0 : memcpy(new_headerbufferv2 + new_extended_offset,
641 0 : temp_buffer + old_extended_offset,
642 : temp_extended_size);
643 :
644 0 : free(temp_buffer);
645 :
646 : /* free the original header buffer and install the new one */
647 0 : free(daemon_local->msgv2.headerbufferv2);
648 0 : daemon_local->msgv2.headerbufferv2 = new_headerbufferv2;
649 :
650 : /* Update baseheaderv2 pointer to point into the new buffer */
651 0 : daemon_local->msgv2.baseheaderv2 = (DltBaseHeaderV2 *)(new_headerbufferv2 + daemon_local->msgv2.storageheadersizev2);
652 :
653 : /* Re-parse extended parameters from the new buffer to update pointers */
654 0 : DltHtyp2ContentType msgcontent = daemon_local->msgv2.baseheaderv2->htyp2 & MSGCONTENT_MASK;
655 0 : if (dlt_message_get_extendedparameters_from_recievedbuffer_v2(&(daemon_local->msgv2),
656 : new_headerbufferv2 + daemon_local->msgv2.storageheadersizev2,
657 : msgcontent) != DLT_RETURN_OK) {
658 0 : dlt_vlog(LOG_WARNING,
659 : "%s: failed to get message extended parameters.\n", __func__);
660 0 : return DLT_DAEMON_ERROR_UNKNOWN;
661 : }
662 :
663 0 : if (dlt_message_set_extendedparameters_v2(&(daemon_local->msgv2))) {
664 0 : dlt_vlog(LOG_WARNING,
665 : "%s: failed to set message extended parameters.\n", __func__);
666 0 : return DLT_DAEMON_ERROR_UNKNOWN;
667 : }
668 :
669 : /* if no filter set or filter is matching display message */
670 0 : if (daemon_local->flags.xflag) {
671 0 : if (DLT_RETURN_OK !=
672 0 : dlt_message_print_hex_v2(&(daemon_local->msgv2), text,
673 : DLT_DAEMON_TEXTSIZE, verbose))
674 0 : dlt_log(LOG_WARNING, "dlt_message_print_hex() failed!\n");
675 0 : } else if (daemon_local->flags.aflag) {
676 0 : if (DLT_RETURN_OK !=
677 0 : dlt_message_print_ascii_v2(&(daemon_local->msgv2), text,
678 : DLT_DAEMON_TEXTSIZE, verbose))
679 0 : dlt_log(LOG_WARNING, "dlt_message_print_ascii() failed!\n");
680 0 : } else if (daemon_local->flags.sflag) {
681 0 : if (DLT_RETURN_OK !=
682 0 : dlt_message_print_header_v2(&(daemon_local->msgv2), text,
683 : DLT_DAEMON_TEXTSIZE, verbose))
684 0 : dlt_log(LOG_WARNING, "dlt_message_print_header() failed!\n");
685 : }
686 :
687 : /* send message to client or write to log file */
688 0 : return dlt_daemon_client_send_v2(DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local,
689 : daemon_local->msgv2.headerbufferv2, (int)daemon_local->msgv2.storageheadersizev2,
690 0 : daemon_local->msgv2.headerbufferv2 + daemon_local->msgv2.storageheadersizev2,
691 0 : (int)(daemon_local->msgv2.headersizev2 - (int32_t)daemon_local->msgv2.storageheadersizev2),
692 0 : daemon_local->msgv2.databuffer, (int) daemon_local->msgv2.datasize, verbose);
693 : }
694 :
695 2 : int dlt_daemon_client_send_control_message(int sock,
696 : DltDaemon *daemon,
697 : DltDaemonLocal *daemon_local,
698 : DltMessage *msg,
699 : char *apid,
700 : char *ctid,
701 : int verbose)
702 : {
703 : int ret;
704 : int32_t len;
705 :
706 2 : PRINT_FUNCTION_VERBOSE(verbose);
707 :
708 2 : if ((daemon == 0) || (msg == 0) || (apid == 0) || (ctid == 0))
709 : return DLT_DAEMON_ERROR_UNKNOWN;
710 :
711 : /* prepare storage header */
712 2 : msg->storageheader = (DltStorageHeader *)msg->headerbuffer;
713 :
714 2 : if (dlt_set_storageheader(msg->storageheader, daemon->ecuid) == DLT_RETURN_ERROR)
715 : return DLT_DAEMON_ERROR_UNKNOWN;
716 :
717 : /* prepare standard header */
718 2 : msg->standardheader = (DltStandardHeader *)(msg->headerbuffer + sizeof(DltStorageHeader));
719 2 : msg->standardheader->htyp = DLT_HTYP_WEID | DLT_HTYP_WTMS | DLT_HTYP_UEH | DLT_HTYP_PROTOCOL_VERSION1;
720 :
721 : #if (BYTE_ORDER == BIG_ENDIAN)
722 : msg->standardheader->htyp = (msg->standardheader->htyp | DLT_HTYP_MSBF);
723 : #endif
724 :
725 2 : msg->standardheader->mcnt = 0;
726 :
727 : /* Set header extra parameters */
728 2 : dlt_set_id(msg->headerextra.ecu, daemon->ecuid);
729 :
730 : /*msg->headerextra.seid = 0; */
731 :
732 2 : msg->headerextra.tmsp = dlt_uptime();
733 :
734 2 : dlt_message_set_extraparameters(msg, verbose);
735 :
736 : /* prepare extended header */
737 2 : msg->extendedheader =
738 2 : (DltExtendedHeader *)(msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) +
739 2 : DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp));
740 2 : msg->extendedheader->msin = DLT_MSIN_CONTROL_RESPONSE;
741 :
742 2 : msg->extendedheader->noar = 1; /* number of arguments */
743 :
744 2 : if (strcmp(apid, "") == 0)
745 2 : dlt_set_id(msg->extendedheader->apid, DLT_DAEMON_CTRL_APID); /* application id */
746 : else
747 0 : dlt_set_id(msg->extendedheader->apid, apid);
748 :
749 2 : if (strcmp(ctid, "") == 0)
750 2 : dlt_set_id(msg->extendedheader->ctid, DLT_DAEMON_CTRL_CTID); /* context id */
751 : else
752 0 : dlt_set_id(msg->extendedheader->ctid, ctid);
753 :
754 : /* prepare length information */
755 2 : msg->headersize = (int32_t)((size_t)sizeof(DltStorageHeader)
756 : + (size_t)sizeof(DltStandardHeader)
757 : + (size_t)sizeof(DltExtendedHeader)
758 2 : + (size_t)DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp));
759 :
760 2 : len = (int32_t)((size_t)msg->headersize
761 : - (size_t)sizeof(DltStorageHeader)
762 2 : + (size_t)msg->datasize);
763 :
764 2 : if (len > UINT16_MAX) {
765 0 : dlt_log(LOG_WARNING, "Huge control message discarded!\n");
766 0 : return DLT_DAEMON_ERROR_UNKNOWN;
767 : }
768 :
769 2 : msg->standardheader->len = DLT_HTOBE_16(((uint16_t)len));
770 :
771 2 : if ((ret =
772 2 : dlt_daemon_client_send(sock, daemon, daemon_local, msg->headerbuffer, sizeof(DltStorageHeader),
773 : msg->headerbuffer + sizeof(DltStorageHeader),
774 : (size_t)(msg->headersize - (int32_t)sizeof(DltStorageHeader)),
775 2 : msg->databuffer, (size_t)msg->datasize, verbose))) {
776 0 : dlt_log(LOG_DEBUG, "dlt_daemon_control_send_control_message: DLT message send to all failed!.\n");
777 0 : return ret;
778 : }
779 :
780 : return DLT_DAEMON_ERROR_OK;
781 : }
782 :
783 0 : int dlt_daemon_client_send_control_message_v2(int sock,
784 : DltDaemon *daemon,
785 : DltDaemonLocal *daemon_local,
786 : DltMessageV2 *msg,
787 : char *apid,
788 : char *ctid,
789 : int verbose)
790 : {
791 : int ret;
792 : int32_t len;
793 : uint8_t appidlen;
794 : uint8_t ctxidlen;
795 : char ecid_buf[DLT_V2_ID_SIZE];
796 : char apid_buf[DLT_V2_ID_SIZE];
797 : char ctid_buf[DLT_V2_ID_SIZE];
798 :
799 0 : PRINT_FUNCTION_VERBOSE(verbose);
800 :
801 0 : if ((daemon == 0) || (msg == 0) || (apid == NULL) || (ctid == NULL))
802 : return DLT_DAEMON_ERROR_UNKNOWN;
803 :
804 : /* prepare storage header */
805 :
806 : if (apid == NULL) {
807 : appidlen = (uint8_t)strlen(DLT_DAEMON_CTRL_APID);
808 : } else {
809 0 : appidlen = (uint8_t)strlen(apid);
810 : }
811 :
812 : if (ctid == NULL) {
813 : ctxidlen = (uint8_t)strlen(DLT_DAEMON_CTRL_CTID);
814 : } else {
815 0 : ctxidlen = (uint8_t)strlen(ctid);
816 : }
817 :
818 0 : msg->storageheadersizev2 = (uint32_t)(STORAGE_HEADER_V2_FIXED_SIZE + (daemon->ecuid2len));
819 0 : msg->baseheadersizev2 = BASE_HEADER_V2_FIXED_SIZE;
820 0 : msg->baseheaderextrasizev2 = (int32_t)dlt_message_get_extraparameters_size_v2(DLT_CONTROL_MSG);
821 0 : msg->extendedheadersizev2 = (uint32_t)((daemon->ecuid2len) + 1 + appidlen + 1 + ctxidlen + 1);
822 :
823 0 : msg->headersizev2 = (int32_t)(msg->storageheadersizev2 + msg->baseheadersizev2 +
824 0 : msg->baseheaderextrasizev2 + msg->extendedheadersizev2);
825 :
826 0 : if (msg->headerbufferv2 != NULL) {
827 0 : free(msg->headerbufferv2);
828 : msg->headerbufferv2 = NULL;
829 : }
830 :
831 0 : msg->headerbufferv2 = (uint8_t*)malloc((size_t)msg->headersizev2);
832 :
833 0 : if (dlt_set_storageheader_v2(&(msg->storageheaderv2), daemon->ecuid2len, daemon->ecuid2) == DLT_RETURN_ERROR)
834 : return DLT_DAEMON_ERROR_UNKNOWN;
835 :
836 0 : if (dlt_message_set_storageparameters_v2(msg, 0) != DLT_RETURN_OK) {
837 : return DLT_RETURN_ERROR;
838 : }
839 :
840 : /* prepare base header */
841 0 : msg->baseheaderv2 = (DltBaseHeaderV2 *)(msg->headerbufferv2 + msg->storageheadersizev2);
842 :
843 : msg->baseheaderv2->htyp2 = DLT_HTYP2_PROTOCOL_VERSION2;
844 : msg->baseheaderv2->htyp2 |= DLT_CONTROL_MSG;
845 : msg->baseheaderv2->htyp2 |= DLT_HTYP2_WEID;
846 0 : msg->baseheaderv2->htyp2 |= DLT_HTYP2_WACID;
847 0 : msg->baseheaderv2->mcnt = 0;
848 :
849 : /* Fill base header conditional parameters */
850 0 : msg->headerextrav2.msin = DLT_MSIN_CONTROL_RESPONSE;
851 0 : msg->headerextrav2.noar = 1; /* number of arguments */
852 0 : memset(msg->headerextrav2.seconds, 0, 5);
853 0 : msg->headerextrav2.nanoseconds = 0;
854 : #if defined (__WIN32__) || defined(_MSC_VER)
855 : time_t t = time(NULL);
856 : if (t==-1) {
857 : uint32_t tcnt = (uint32_t)(GetTickCount()); /* GetTickCount() in 10 ms resolution */
858 : tcnt_seconds = tcnt / 100;
859 : tcnt_ns = (tcnt - (tcnt*100)) * 10000;
860 : msg->headerextrav2.seconds[0]=(tcnt_seconds >> 32) & 0xFF;
861 : msg->headerextrav2.seconds[1]=(tcnt_seconds >> 24) & 0xFF;
862 : msg->headerextrav2.seconds[2]=(tcnt_seconds >> 16) & 0xFF;
863 : msg->headerextrav2.seconds[3]=(tcnt_seconds >> 8) & 0xFF;
864 : msg->headerextrav2.seconds[4]= tcnt_seconds & 0xFF;
865 : if (ts.tv_nsec < 0x3B9ACA00) {
866 : msg->headerextrav2.nanoseconds = tcnt_ns;
867 : }
868 : } else {
869 : msg->headerextrav2.seconds[0]=(t >> 32) & 0xFF;
870 : msg->headerextrav2.seconds[1]=(t >> 24) & 0xFF;
871 : msg->headerextrav2.seconds[2]=(t >> 16) & 0xFF;
872 : msg->headerextrav2.seconds[3]=(t >> 8) & 0xFF;
873 : msg->headerextrav2.seconds[4]= t & 0xFF;
874 : msg->headerextrav2.nanoseconds |= 0x8000;
875 : }
876 : #else
877 : struct timespec ts;
878 0 : if (clock_gettime(CLOCK_REALTIME, &ts) == 0) {
879 0 : msg->headerextrav2.seconds[0]=(uint8_t)((ts.tv_sec >> 32) & 0xFF);
880 0 : msg->headerextrav2.seconds[1]=(uint8_t)((ts.tv_sec >> 24) & 0xFF);
881 0 : msg->headerextrav2.seconds[2]=(uint8_t)((ts.tv_sec >> 16) & 0xFF);
882 0 : msg->headerextrav2.seconds[3]=(uint8_t)((ts.tv_sec >> 8) & 0xFF);
883 0 : msg->headerextrav2.seconds[4]= (uint8_t)(ts.tv_sec & 0xFF);
884 0 : if (ts.tv_nsec < 0x3B9ACA00) {
885 0 : msg->headerextrav2.nanoseconds = (uint32_t) ts.tv_nsec; /* value is long */
886 : }
887 0 : } else if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
888 0 : msg->headerextrav2.seconds[0]=(uint8_t)((ts.tv_sec >> 32) & 0xFF);
889 0 : msg->headerextrav2.seconds[1]=(uint8_t)((ts.tv_sec >> 24) & 0xFF);
890 0 : msg->headerextrav2.seconds[2]=(uint8_t)((ts.tv_sec >> 16) & 0xFF);
891 0 : msg->headerextrav2.seconds[3]=(uint8_t)((ts.tv_sec >> 8) & 0xFF);
892 0 : msg->headerextrav2.seconds[4]= (uint8_t)(ts.tv_sec & 0xFF);
893 0 : if (ts.tv_nsec < 0x3B9ACA00) {
894 0 : msg->headerextrav2.nanoseconds = (uint32_t) ts.tv_nsec; /* value is long */
895 : }
896 0 : msg->headerextrav2.nanoseconds |= 0x8000;
897 : }
898 : #endif
899 :
900 : /* Copy header extra parameters to headerbuffer */
901 0 : if (dlt_message_set_extraparameters_v2(msg, 0) == DLT_RETURN_ERROR) {
902 0 : dlt_message_free_v2(msg, 0);
903 0 : return DLT_RETURN_ERROR;
904 : }
905 :
906 : /* Fill out extended header */
907 0 : if (DLT_IS_HTYP2_WEID(msg->baseheaderv2->htyp2)) {
908 0 : msg->extendedheaderv2.ecidlen = daemon->ecuid2len;
909 0 : if (msg->extendedheaderv2.ecidlen > 0) {
910 0 : dlt_set_id_v2(ecid_buf, daemon->ecuid2, msg->extendedheaderv2.ecidlen);
911 0 : msg->extendedheaderv2.ecid = ecid_buf;
912 : } else {
913 0 : msg->extendedheaderv2.ecid = NULL;
914 : }
915 : }
916 :
917 0 : if (DLT_IS_HTYP2_WACID(msg->baseheaderv2->htyp2)) {
918 0 : msg->extendedheaderv2.apidlen = appidlen;
919 0 : if (msg->extendedheaderv2.apidlen > 0) {
920 : if (apid == NULL) {
921 : dlt_set_id_v2(apid_buf, DLT_DAEMON_CTRL_APID, msg->extendedheaderv2.apidlen);
922 : } else {
923 0 : dlt_set_id_v2(apid_buf, apid, msg->extendedheaderv2.apidlen);
924 : }
925 0 : msg->extendedheaderv2.apid = apid_buf;
926 : } else {
927 0 : msg->extendedheaderv2.apid = NULL;
928 : }
929 :
930 0 : msg->extendedheaderv2.ctidlen = ctxidlen;
931 0 : if (msg->extendedheaderv2.ctidlen > 0) {
932 : if (ctid == NULL) {
933 : dlt_set_id_v2(ctid_buf, DLT_DAEMON_CTRL_CTID, msg->extendedheaderv2.ctidlen);
934 : } else {
935 0 : dlt_set_id_v2(ctid_buf, ctid, msg->extendedheaderv2.ctidlen);
936 : }
937 0 : msg->extendedheaderv2.ctid = ctid_buf;
938 : } else {
939 0 : msg->extendedheaderv2.ctid = NULL;
940 : }
941 : }
942 :
943 0 : if (dlt_message_set_extendedparameters_v2(msg) != DLT_RETURN_OK) {
944 0 : dlt_message_free_v2(msg, 0);
945 0 : return DLT_RETURN_ERROR;
946 : }
947 :
948 0 : len = (int32_t) (msg->headersizev2 - (int32_t)msg->storageheadersizev2 + msg->datasize);
949 :
950 0 : if (len > UINT16_MAX) {
951 0 : dlt_vlog(LOG_ERR,
952 : "%s: Critical: Huge injection message discarded!\n",
953 : __func__);
954 0 : dlt_message_free_v2(msg, 0);
955 0 : return DLT_RETURN_ERROR;
956 : }
957 :
958 0 : msg->baseheaderv2->len = (uint16_t)len;
959 :
960 0 : if ((ret =
961 0 : dlt_daemon_client_send_v2(sock, daemon, daemon_local, msg->headerbufferv2, (int)msg->storageheadersizev2,
962 0 : msg->headerbufferv2 + (int)msg->storageheadersizev2,
963 : (int) (msg->headersizev2 - (int32_t)msg->storageheadersizev2),
964 0 : msg->databuffer, (int) msg->datasize, verbose))) {
965 0 : dlt_log(LOG_DEBUG, "dlt_daemon_control_send_control_message: DLT message send to all failed!.\n");
966 0 : return ret;
967 : }
968 :
969 : return DLT_DAEMON_ERROR_OK;
970 : }
971 :
972 1 : int dlt_daemon_client_process_control(int sock,
973 : DltDaemon *daemon,
974 : DltDaemonLocal *daemon_local,
975 : DltMessage *msg,
976 : int verbose)
977 : {
978 : uint32_t id, id_tmp = 0;
979 : DltStandardHeaderExtra extra;
980 :
981 1 : PRINT_FUNCTION_VERBOSE(verbose);
982 :
983 1 : if ((daemon == NULL) || (daemon_local == NULL) || (msg == NULL))
984 : return -1;
985 :
986 1 : if (msg->datasize < (int32_t)sizeof(uint32_t))
987 : return -1;
988 :
989 1 : extra = msg->headerextra;
990 :
991 : /* TODO: Add length of extra.ecu to dlt_gateway_forward_control_message_v2 */
992 : /* check if the message needs to be forwarded */
993 1 : if (daemon_local->flags.gatewayMode == 1) {
994 0 : if (strncmp(daemon_local->flags.evalue, extra.ecu, DLT_ID_SIZE) != 0)
995 0 : return dlt_gateway_forward_control_message(&daemon_local->pGateway,
996 : daemon_local,
997 : msg,
998 : extra.ecu,
999 : verbose);
1000 : }
1001 :
1002 1 : id_tmp = *((uint32_t *)(msg->databuffer));
1003 1 : id = DLT_ENDIAN_GET_32(msg->standardheader->htyp, id_tmp);
1004 :
1005 1 : if ((id > DLT_SERVICE_ID) && (id < DLT_SERVICE_ID_CALLSW_CINJECTION)) {
1006 : /* Control message handling */
1007 1 : switch (id) {
1008 0 : case DLT_SERVICE_ID_SET_LOG_LEVEL:
1009 : {
1010 0 : dlt_daemon_control_set_log_level(sock, daemon, daemon_local, msg, verbose);
1011 0 : break;
1012 : }
1013 0 : case DLT_SERVICE_ID_SET_TRACE_STATUS:
1014 : {
1015 0 : dlt_daemon_control_set_trace_status(sock, daemon, daemon_local, msg, verbose);
1016 0 : break;
1017 : }
1018 0 : case DLT_SERVICE_ID_GET_LOG_INFO:
1019 : {
1020 0 : dlt_daemon_control_get_log_info(sock, daemon, daemon_local, msg, verbose);
1021 0 : break;
1022 : }
1023 0 : case DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL:
1024 : {
1025 0 : dlt_daemon_control_get_default_log_level(sock, daemon, daemon_local, verbose);
1026 0 : break;
1027 : }
1028 0 : case DLT_SERVICE_ID_STORE_CONFIG:
1029 : {
1030 0 : if (dlt_daemon_applications_save(daemon, daemon->runtime_application_cfg, verbose) == 0) {
1031 0 : if (dlt_daemon_contexts_save(daemon, daemon->runtime_context_cfg, verbose) == 0) {
1032 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK,
1033 : verbose);
1034 : }
1035 : else {
1036 : /* Delete saved files */
1037 0 : dlt_daemon_control_reset_to_factory_default(daemon,
1038 : daemon->runtime_application_cfg,
1039 : daemon->runtime_context_cfg,
1040 : daemon_local->flags.contextLogLevel,
1041 : daemon_local->flags.contextTraceStatus,
1042 : daemon_local->flags.enforceContextLLAndTS,
1043 : verbose);
1044 0 : dlt_daemon_control_service_response(sock,
1045 : daemon,
1046 : daemon_local,
1047 : id,
1048 : DLT_SERVICE_RESPONSE_ERROR,
1049 : verbose);
1050 : }
1051 : }
1052 : else {
1053 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR,
1054 : verbose);
1055 : }
1056 :
1057 : break;
1058 : }
1059 0 : case DLT_SERVICE_ID_RESET_TO_FACTORY_DEFAULT:
1060 : {
1061 0 : dlt_daemon_control_reset_to_factory_default(daemon,
1062 0 : daemon->runtime_application_cfg,
1063 0 : daemon->runtime_context_cfg,
1064 : daemon_local->flags.contextLogLevel,
1065 : daemon_local->flags.contextTraceStatus,
1066 : daemon_local->flags.enforceContextLLAndTS,
1067 : verbose);
1068 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose);
1069 0 : break;
1070 : }
1071 0 : case DLT_SERVICE_ID_SET_COM_INTERFACE_STATUS:
1072 : {
1073 0 : dlt_daemon_control_service_response(sock,
1074 : daemon,
1075 : daemon_local,
1076 : id,
1077 : DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
1078 : verbose);
1079 0 : break;
1080 : }
1081 0 : case DLT_SERVICE_ID_SET_COM_INTERFACE_MAX_BANDWIDTH:
1082 : {
1083 0 : dlt_daemon_control_service_response(sock,
1084 : daemon,
1085 : daemon_local,
1086 : id,
1087 : DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
1088 : verbose);
1089 0 : break;
1090 : }
1091 0 : case DLT_SERVICE_ID_SET_VERBOSE_MODE:
1092 : {
1093 0 : dlt_daemon_control_service_response(sock,
1094 : daemon,
1095 : daemon_local,
1096 : id,
1097 : DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
1098 : verbose);
1099 0 : break;
1100 : }
1101 0 : case DLT_SERVICE_ID_SET_MESSAGE_FILTERING:
1102 : {
1103 0 : dlt_daemon_control_service_response(sock,
1104 : daemon,
1105 : daemon_local,
1106 : id,
1107 : DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
1108 : verbose);
1109 0 : break;
1110 : }
1111 0 : case DLT_SERVICE_ID_SET_TIMING_PACKETS:
1112 : {
1113 0 : dlt_daemon_control_set_timing_packets(sock, daemon, daemon_local, msg, verbose);
1114 0 : break;
1115 : }
1116 0 : case DLT_SERVICE_ID_GET_LOCAL_TIME:
1117 : {
1118 : /* Send response with valid timestamp (TMSP) field */
1119 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose);
1120 0 : break;
1121 : }
1122 0 : case DLT_SERVICE_ID_USE_ECU_ID:
1123 : {
1124 0 : dlt_daemon_control_service_response(sock,
1125 : daemon,
1126 : daemon_local,
1127 : id,
1128 : DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
1129 : verbose);
1130 0 : break;
1131 : }
1132 0 : case DLT_SERVICE_ID_USE_SESSION_ID:
1133 : {
1134 0 : dlt_daemon_control_service_response(sock,
1135 : daemon,
1136 : daemon_local,
1137 : id,
1138 : DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
1139 : verbose);
1140 0 : break;
1141 : }
1142 0 : case DLT_SERVICE_ID_USE_TIMESTAMP:
1143 : {
1144 0 : dlt_daemon_control_service_response(sock,
1145 : daemon,
1146 : daemon_local,
1147 : id,
1148 : DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
1149 : verbose);
1150 0 : break;
1151 : }
1152 0 : case DLT_SERVICE_ID_USE_EXTENDED_HEADER:
1153 : {
1154 0 : dlt_daemon_control_service_response(sock,
1155 : daemon,
1156 : daemon_local,
1157 : id,
1158 : DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
1159 : verbose);
1160 0 : break;
1161 : }
1162 0 : case DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL:
1163 : {
1164 0 : dlt_daemon_control_set_default_log_level(sock, daemon, daemon_local, msg, verbose);
1165 0 : break;
1166 : }
1167 0 : case DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS:
1168 : {
1169 0 : dlt_daemon_control_set_default_trace_status(sock, daemon, daemon_local, msg, verbose);
1170 0 : break;
1171 : }
1172 0 : case DLT_SERVICE_ID_GET_SOFTWARE_VERSION:
1173 : {
1174 0 : dlt_daemon_control_get_software_version(sock, daemon, daemon_local, verbose);
1175 0 : break;
1176 : }
1177 0 : case DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW:
1178 : {
1179 0 : dlt_daemon_control_message_buffer_overflow(sock, daemon, daemon_local, daemon->overflow_counter, "",
1180 : verbose);
1181 0 : break;
1182 : }
1183 1 : case DLT_SERVICE_ID_OFFLINE_LOGSTORAGE:
1184 : {
1185 1 : dlt_daemon_control_service_logstorage(sock, daemon, daemon_local, msg, verbose);
1186 1 : break;
1187 : }
1188 0 : case DLT_SERVICE_ID_PASSIVE_NODE_CONNECT:
1189 : {
1190 0 : dlt_daemon_control_passive_node_connect(sock,
1191 : daemon,
1192 : daemon_local,
1193 : msg,
1194 : verbose);
1195 0 : break;
1196 : }
1197 0 : case DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS:
1198 : {
1199 0 : dlt_daemon_control_passive_node_connect_status(sock,
1200 : daemon,
1201 : daemon_local,
1202 : verbose);
1203 0 : break;
1204 : }
1205 0 : case DLT_SERVICE_ID_SET_ALL_LOG_LEVEL:
1206 : {
1207 0 : dlt_daemon_control_set_all_log_level(sock, daemon, daemon_local, msg, verbose);
1208 0 : break;
1209 : }
1210 0 : case DLT_SERVICE_ID_SET_ALL_TRACE_STATUS:
1211 : {
1212 0 : dlt_daemon_control_set_all_trace_status(sock, daemon, daemon_local, msg, verbose);
1213 0 : break;
1214 : }
1215 0 : default:
1216 : {
1217 0 : dlt_daemon_control_service_response(sock,
1218 : daemon,
1219 : daemon_local,
1220 : id,
1221 : DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
1222 : verbose);
1223 0 : break;
1224 : }
1225 : }
1226 : }
1227 : else {
1228 : /* Injection handling */
1229 0 : dlt_daemon_control_callsw_cinjection(sock, daemon, daemon_local, msg, verbose);
1230 : }
1231 :
1232 : return 0;
1233 : }
1234 :
1235 0 : int dlt_daemon_client_process_control_v2(int sock,
1236 : DltDaemon *daemon,
1237 : DltDaemonLocal *daemon_local,
1238 : DltMessageV2 *msg,
1239 : int verbose)
1240 : {
1241 : uint32_t id, id_tmp = 0;
1242 : DltExtendedHeaderV2 extended;
1243 :
1244 0 : PRINT_FUNCTION_VERBOSE(verbose);
1245 :
1246 0 : if ((daemon == NULL) || (daemon_local == NULL) || (msg == NULL))
1247 : return -1;
1248 :
1249 0 : if (msg->datasize < (int32_t)sizeof(uint32_t))
1250 : return -1;
1251 :
1252 0 : extended = msg->extendedheaderv2;
1253 :
1254 : /* check if the message needs to be forwarded */
1255 0 : if (daemon_local->flags.gatewayMode == 1) {
1256 0 : if (strncmp(daemon_local->flags.evalue, extended.ecid, extended.ecidlen) != 0)
1257 0 : return dlt_gateway_forward_control_message_v2(&daemon_local->pGateway,
1258 : daemon_local,
1259 : msg,
1260 : extended.ecidlen,
1261 : extended.ecid,
1262 : verbose);
1263 : }
1264 :
1265 0 : id_tmp = *((uint32_t *)(msg->databuffer));
1266 : id = DLT_LETOH_32(id_tmp);
1267 :
1268 0 : if ((id > DLT_SERVICE_ID) && (id < DLT_SERVICE_ID_CALLSW_CINJECTION)) {
1269 : /* Control message handling */
1270 0 : switch (id) {
1271 0 : case DLT_SERVICE_ID_SET_LOG_LEVEL:
1272 : {
1273 0 : dlt_daemon_control_set_log_level_v2(sock, daemon, daemon_local, msg, verbose);
1274 0 : break;
1275 : }
1276 0 : case DLT_SERVICE_ID_SET_TRACE_STATUS:
1277 : {
1278 0 : dlt_daemon_control_set_trace_status_v2(sock, daemon, daemon_local, msg, verbose);
1279 0 : break;
1280 : }
1281 0 : case DLT_SERVICE_ID_GET_LOG_INFO:
1282 : {
1283 0 : dlt_daemon_control_get_log_info_v2(sock, daemon, daemon_local, msg, verbose);
1284 0 : break;
1285 : }
1286 0 : case DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL:
1287 : {
1288 0 : dlt_daemon_control_get_default_log_level_v2(sock, daemon, daemon_local, verbose);
1289 0 : break;
1290 : }
1291 0 : case DLT_SERVICE_ID_STORE_CONFIG:
1292 : {
1293 0 : if (dlt_daemon_applications_save_v2(daemon, daemon->runtime_application_cfg, verbose) == 0) {
1294 0 : if (dlt_daemon_contexts_save_v2(daemon, daemon->runtime_context_cfg, verbose) == 0) {
1295 0 : dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK,
1296 : verbose);
1297 : }
1298 : else {
1299 : /* Delete saved files */
1300 0 : dlt_daemon_control_reset_to_factory_default_v2(daemon,
1301 : daemon->runtime_application_cfg,
1302 : daemon->runtime_context_cfg,
1303 : daemon_local->flags.contextLogLevel,
1304 : daemon_local->flags.contextTraceStatus,
1305 : daemon_local->flags.enforceContextLLAndTS,
1306 : verbose);
1307 0 : dlt_daemon_control_service_response_v2(sock,
1308 : daemon,
1309 : daemon_local,
1310 : id,
1311 : DLT_SERVICE_RESPONSE_ERROR,
1312 : verbose);
1313 : }
1314 : }
1315 : else {
1316 0 : dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR,
1317 : verbose);
1318 : }
1319 :
1320 : break;
1321 : }
1322 0 : case DLT_SERVICE_ID_RESET_TO_FACTORY_DEFAULT:
1323 : {
1324 0 : dlt_daemon_control_reset_to_factory_default_v2(daemon,
1325 0 : daemon->runtime_application_cfg,
1326 0 : daemon->runtime_context_cfg,
1327 : daemon_local->flags.contextLogLevel,
1328 : daemon_local->flags.contextTraceStatus,
1329 : daemon_local->flags.enforceContextLLAndTS,
1330 : verbose);
1331 0 : dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose);
1332 0 : break;
1333 : }
1334 0 : case DLT_SERVICE_ID_SET_COM_INTERFACE_STATUS:
1335 : {
1336 0 : dlt_daemon_control_service_response_v2(sock,
1337 : daemon,
1338 : daemon_local,
1339 : id,
1340 : DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
1341 : verbose);
1342 0 : break;
1343 : }
1344 0 : case DLT_SERVICE_ID_SET_COM_INTERFACE_MAX_BANDWIDTH:
1345 : {
1346 0 : dlt_daemon_control_service_response_v2(sock,
1347 : daemon,
1348 : daemon_local,
1349 : id,
1350 : DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
1351 : verbose);
1352 0 : break;
1353 : }
1354 0 : case DLT_SERVICE_ID_SET_VERBOSE_MODE:
1355 : {
1356 0 : dlt_daemon_control_service_response_v2(sock,
1357 : daemon,
1358 : daemon_local,
1359 : id,
1360 : DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
1361 : verbose);
1362 0 : break;
1363 : }
1364 0 : case DLT_SERVICE_ID_SET_MESSAGE_FILTERING:
1365 : {
1366 0 : dlt_daemon_control_service_response_v2(sock,
1367 : daemon,
1368 : daemon_local,
1369 : id,
1370 : DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
1371 : verbose);
1372 0 : break;
1373 : }
1374 0 : case DLT_SERVICE_ID_SET_TIMING_PACKETS:
1375 : {
1376 0 : dlt_daemon_control_set_timing_packets_v2(sock, daemon, daemon_local, msg, verbose);
1377 0 : break;
1378 : }
1379 0 : case DLT_SERVICE_ID_GET_LOCAL_TIME:
1380 : {
1381 : /* Send response with valid timestamp (TMSP) field */
1382 0 : dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose);
1383 0 : break;
1384 : }
1385 0 : case DLT_SERVICE_ID_USE_ECU_ID:
1386 : {
1387 0 : dlt_daemon_control_service_response_v2(sock,
1388 : daemon,
1389 : daemon_local,
1390 : id,
1391 : DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
1392 : verbose);
1393 0 : break;
1394 : }
1395 0 : case DLT_SERVICE_ID_USE_SESSION_ID:
1396 : {
1397 0 : dlt_daemon_control_service_response_v2(sock,
1398 : daemon,
1399 : daemon_local,
1400 : id,
1401 : DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
1402 : verbose);
1403 0 : break;
1404 : }
1405 0 : case DLT_SERVICE_ID_USE_TIMESTAMP:
1406 : {
1407 0 : dlt_daemon_control_service_response_v2(sock,
1408 : daemon,
1409 : daemon_local,
1410 : id,
1411 : DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
1412 : verbose);
1413 0 : break;
1414 : }
1415 0 : case DLT_SERVICE_ID_USE_EXTENDED_HEADER:
1416 : {
1417 0 : dlt_daemon_control_service_response_v2(sock,
1418 : daemon,
1419 : daemon_local,
1420 : id,
1421 : DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
1422 : verbose);
1423 0 : break;
1424 : }
1425 0 : case DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL:
1426 : {
1427 0 : dlt_daemon_control_set_default_log_level_v2(sock, daemon, daemon_local, msg, verbose);
1428 0 : break;
1429 : }
1430 0 : case DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS:
1431 : {
1432 0 : dlt_daemon_control_set_default_trace_status_v2(sock, daemon, daemon_local, msg, verbose);
1433 0 : break;
1434 : }
1435 0 : case DLT_SERVICE_ID_GET_SOFTWARE_VERSION:
1436 : {
1437 0 : dlt_daemon_control_get_software_version_v2(sock, daemon, daemon_local, verbose);
1438 0 : break;
1439 : }
1440 0 : case DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW:
1441 : {
1442 0 : dlt_daemon_control_message_buffer_overflow_v2(sock, daemon, daemon_local, daemon->overflow_counter, "",
1443 : verbose);
1444 0 : break;
1445 : }
1446 0 : case DLT_SERVICE_ID_OFFLINE_LOGSTORAGE:
1447 : {
1448 0 : dlt_daemon_control_service_logstorage_v2(sock, daemon, daemon_local, msg, verbose);
1449 0 : break;
1450 : }
1451 0 : case DLT_SERVICE_ID_PASSIVE_NODE_CONNECT:
1452 : {
1453 0 : dlt_daemon_control_passive_node_connect_v2(sock,
1454 : daemon,
1455 : daemon_local,
1456 : msg,
1457 : verbose);
1458 0 : break;
1459 : }
1460 0 : case DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS:
1461 : {
1462 0 : dlt_daemon_control_passive_node_connect_status_v2(sock,
1463 : daemon,
1464 : daemon_local,
1465 : verbose);
1466 0 : break;
1467 : }
1468 0 : case DLT_SERVICE_ID_SET_ALL_LOG_LEVEL:
1469 : {
1470 0 : dlt_daemon_control_set_all_log_level_v2(sock, daemon, daemon_local, msg, verbose);
1471 0 : break;
1472 : }
1473 0 : case DLT_SERVICE_ID_SET_ALL_TRACE_STATUS:
1474 : {
1475 0 : dlt_daemon_control_set_all_trace_status_v2(sock, daemon, daemon_local, msg, verbose);
1476 0 : break;
1477 : }
1478 0 : default:
1479 : {
1480 0 : dlt_daemon_control_service_response_v2(sock,
1481 : daemon,
1482 : daemon_local,
1483 : id,
1484 : DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
1485 : verbose);
1486 0 : break;
1487 : }
1488 : }
1489 : }
1490 : else {
1491 : /* Injection handling */
1492 0 : dlt_daemon_control_callsw_cinjection_v2(sock, daemon, daemon_local, msg, verbose);
1493 : }
1494 :
1495 : return 0;
1496 : }
1497 :
1498 0 : void dlt_daemon_control_get_software_version(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
1499 : {
1500 : DltMessage msg;
1501 : uint32_t len;
1502 : DltServiceGetSoftwareVersionResponse *resp;
1503 :
1504 0 : PRINT_FUNCTION_VERBOSE(verbose);
1505 :
1506 0 : if (daemon == 0)
1507 0 : return;
1508 :
1509 : /* initialise new message */
1510 0 : if (dlt_message_init(&msg, 0) == DLT_RETURN_ERROR) {
1511 0 : dlt_daemon_control_service_response(sock,
1512 : daemon,
1513 : daemon_local,
1514 : DLT_SERVICE_ID_GET_SOFTWARE_VERSION,
1515 : DLT_SERVICE_RESPONSE_ERROR,
1516 : verbose);
1517 0 : return;
1518 : }
1519 :
1520 : /* prepare payload of data */
1521 0 : len = (uint32_t) strlen(daemon->ECUVersionString);
1522 :
1523 : /* msg.datasize = sizeof(serviceID) + sizeof(status) + sizeof(length) + len */
1524 0 : msg.datasize = (int32_t)((size_t)sizeof(uint32_t) + (size_t)sizeof(uint8_t) + (size_t)sizeof(uint32_t) + (size_t)len);
1525 :
1526 0 : if (msg.databuffer && (msg.databuffersize < msg.datasize)) {
1527 0 : free(msg.databuffer);
1528 0 : msg.databuffer = 0;
1529 : }
1530 :
1531 0 : if (msg.databuffer == 0) {
1532 0 : msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize);
1533 0 : msg.databuffersize = msg.datasize;
1534 : }
1535 :
1536 0 : if (msg.databuffer == 0) {
1537 0 : dlt_daemon_control_service_response(sock,
1538 : daemon,
1539 : daemon_local,
1540 : DLT_SERVICE_ID_GET_SOFTWARE_VERSION,
1541 : DLT_SERVICE_RESPONSE_ERROR,
1542 : verbose);
1543 0 : return;
1544 : }
1545 :
1546 : resp = (DltServiceGetSoftwareVersionResponse *)msg.databuffer;
1547 0 : resp->service_id = DLT_SERVICE_ID_GET_SOFTWARE_VERSION;
1548 0 : resp->status = DLT_SERVICE_RESPONSE_OK;
1549 0 : resp->length = len;
1550 0 : memcpy(msg.databuffer + msg.datasize - len, daemon->ECUVersionString, len);
1551 :
1552 : /* send message */
1553 0 : dlt_daemon_client_send_control_message(sock, daemon, daemon_local, &msg, "", "", verbose);
1554 :
1555 : /* free message */
1556 0 : dlt_message_free(&msg, 0);
1557 : }
1558 :
1559 0 : void dlt_daemon_control_get_software_version_v2(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
1560 : {
1561 : DltMessageV2 msg;
1562 : uint32_t len;
1563 : DltServiceGetSoftwareVersionResponse *resp;
1564 :
1565 0 : PRINT_FUNCTION_VERBOSE(verbose);
1566 :
1567 0 : if (daemon == 0)
1568 0 : return;
1569 :
1570 : /* initialise new message */
1571 0 : if (dlt_message_init_v2(&msg, 0) == DLT_RETURN_ERROR) {
1572 0 : dlt_daemon_control_service_response_v2(sock,
1573 : daemon,
1574 : daemon_local,
1575 : DLT_SERVICE_ID_GET_SOFTWARE_VERSION,
1576 : DLT_SERVICE_RESPONSE_ERROR,
1577 : verbose);
1578 0 : return;
1579 : }
1580 :
1581 : /* prepare payload of data */
1582 0 : len = (uint32_t) strlen(daemon->ECUVersionString);
1583 :
1584 : /* msg.datasize = sizeof(serviceID) + sizeof(status) + sizeof(length) + len */
1585 0 : msg.datasize = (int32_t) (sizeof(uint32_t) + sizeof(uint8_t) + sizeof(uint32_t) + len);
1586 :
1587 0 : if (msg.databuffer && (msg.databuffersize < msg.datasize)) {
1588 0 : free(msg.databuffer);
1589 0 : msg.databuffer = 0;
1590 : }
1591 :
1592 0 : if (msg.databuffer == 0) {
1593 0 : msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize);
1594 0 : msg.databuffersize = msg.datasize;
1595 : }
1596 :
1597 0 : if (msg.databuffer == 0) {
1598 0 : dlt_daemon_control_service_response_v2(sock,
1599 : daemon,
1600 : daemon_local,
1601 : DLT_SERVICE_ID_GET_SOFTWARE_VERSION,
1602 : DLT_SERVICE_RESPONSE_ERROR,
1603 : verbose);
1604 0 : return;
1605 : }
1606 :
1607 : resp = (DltServiceGetSoftwareVersionResponse *)msg.databuffer;
1608 0 : resp->service_id = DLT_SERVICE_ID_GET_SOFTWARE_VERSION;
1609 0 : resp->status = DLT_SERVICE_RESPONSE_OK;
1610 0 : resp->length = len;
1611 0 : memcpy(msg.databuffer + msg.datasize - len, daemon->ECUVersionString, len);
1612 :
1613 : /* send message */
1614 0 : dlt_daemon_client_send_control_message_v2(sock, daemon, daemon_local, &msg, "", "", verbose);
1615 :
1616 : /* free message */
1617 0 : dlt_message_free_v2(&msg, 0);
1618 : }
1619 :
1620 0 : void dlt_daemon_control_get_default_log_level(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
1621 : {
1622 : DltMessage msg;
1623 : DltServiceGetDefaultLogLevelResponse *resp;
1624 :
1625 0 : PRINT_FUNCTION_VERBOSE(verbose);
1626 :
1627 0 : if (daemon == 0)
1628 0 : return;
1629 :
1630 : /* initialise new message */
1631 0 : if (dlt_message_init(&msg, 0) == DLT_RETURN_ERROR) {
1632 0 : dlt_daemon_control_service_response(sock,
1633 : daemon,
1634 : daemon_local,
1635 : DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL,
1636 : DLT_SERVICE_RESPONSE_ERROR,
1637 : verbose);
1638 0 : return;
1639 : }
1640 :
1641 0 : msg.datasize = sizeof(DltServiceGetDefaultLogLevelResponse);
1642 :
1643 0 : if (msg.databuffer && (msg.databuffersize < msg.datasize)) {
1644 0 : free(msg.databuffer);
1645 0 : msg.databuffer = 0;
1646 : }
1647 :
1648 0 : if (msg.databuffer == 0) {
1649 0 : msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize);
1650 0 : msg.databuffersize = msg.datasize;
1651 : }
1652 :
1653 0 : if (msg.databuffer == 0) {
1654 0 : dlt_daemon_control_service_response(sock,
1655 : daemon,
1656 : daemon_local,
1657 : DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL,
1658 : DLT_SERVICE_RESPONSE_ERROR,
1659 : verbose);
1660 0 : return;
1661 : }
1662 :
1663 : resp = (DltServiceGetDefaultLogLevelResponse *)msg.databuffer;
1664 0 : resp->service_id = DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL;
1665 0 : resp->status = DLT_SERVICE_RESPONSE_OK;
1666 0 : resp->log_level = (uint8_t) daemon->default_log_level;
1667 :
1668 : /* send message */
1669 0 : dlt_daemon_client_send_control_message(sock, daemon, daemon_local, &msg, "", "", verbose);
1670 :
1671 : /* free message */
1672 0 : dlt_message_free(&msg, 0);
1673 : }
1674 :
1675 0 : void dlt_daemon_control_get_default_log_level_v2(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
1676 : {
1677 : DltMessageV2 msg;
1678 : DltServiceGetDefaultLogLevelResponse *resp;
1679 :
1680 0 : PRINT_FUNCTION_VERBOSE(verbose);
1681 :
1682 0 : if (daemon == 0)
1683 0 : return;
1684 :
1685 : /* initialise new message */
1686 0 : if (dlt_message_init_v2(&msg, 0) == DLT_RETURN_ERROR) {
1687 0 : dlt_daemon_control_service_response_v2(sock,
1688 : daemon,
1689 : daemon_local,
1690 : DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL,
1691 : DLT_SERVICE_RESPONSE_ERROR,
1692 : verbose);
1693 0 : return;
1694 : }
1695 :
1696 0 : msg.datasize = sizeof(DltServiceGetDefaultLogLevelResponse);
1697 :
1698 0 : if (msg.databuffer && (msg.databuffersize < msg.datasize)) {
1699 0 : free(msg.databuffer);
1700 0 : msg.databuffer = 0;
1701 : }
1702 :
1703 0 : if (msg.databuffer == 0) {
1704 0 : msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize);
1705 0 : msg.databuffersize = msg.datasize;
1706 : }
1707 :
1708 0 : if (msg.databuffer == 0) {
1709 0 : dlt_daemon_control_service_response_v2(sock,
1710 : daemon,
1711 : daemon_local,
1712 : DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL,
1713 : DLT_SERVICE_RESPONSE_ERROR,
1714 : verbose);
1715 0 : return;
1716 : }
1717 :
1718 : resp = (DltServiceGetDefaultLogLevelResponse *)msg.databuffer;
1719 0 : resp->service_id = DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL;
1720 0 : resp->status = DLT_SERVICE_RESPONSE_OK;
1721 0 : resp->log_level = (uint8_t) daemon->default_log_level;
1722 :
1723 : /* send message */
1724 0 : dlt_daemon_client_send_control_message_v2(sock, daemon, daemon_local, &msg, "", "", verbose);
1725 :
1726 : /* free message */
1727 0 : dlt_message_free_v2(&msg, 0);
1728 : }
1729 :
1730 0 : void dlt_daemon_control_get_log_info(int sock,
1731 : DltDaemon *daemon,
1732 : DltDaemonLocal *daemon_local,
1733 : DltMessage *msg,
1734 : int verbose)
1735 : {
1736 : DltServiceGetLogInfoRequest *req;
1737 : DltMessage resp;
1738 : DltDaemonContext *context = 0;
1739 : DltDaemonApplication *application = 0;
1740 :
1741 : int num_applications = 0, num_contexts = 0;
1742 0 : uint16_t count_app_ids = 0, count_con_ids = 0;
1743 :
1744 : #if (DLT_DEBUG_GETLOGINFO == 1)
1745 : char buf[255];
1746 : #endif
1747 :
1748 : int32_t i, j;
1749 : size_t offset = 0;
1750 : char *apid = 0;
1751 : int8_t ll, ts;
1752 : uint16_t len;
1753 : int8_t value;
1754 : size_t sizecont = 0;
1755 : int offset_base;
1756 :
1757 : uint32_t sid;
1758 :
1759 : DltDaemonRegisteredUsers *user_list = NULL;
1760 :
1761 0 : PRINT_FUNCTION_VERBOSE(verbose);
1762 :
1763 0 : if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL))
1764 0 : return;
1765 :
1766 0 : if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceGetLogInfoRequest)) < 0)
1767 : return;
1768 :
1769 0 : user_list = dlt_daemon_find_users_list(daemon, daemon->ecuid, verbose);
1770 :
1771 0 : if (user_list == NULL)
1772 : return;
1773 :
1774 : /* prepare pointer to message request */
1775 0 : req = (DltServiceGetLogInfoRequest *)(msg->databuffer);
1776 :
1777 : /* initialise new message */
1778 0 : if (dlt_message_init(&resp, 0) == DLT_RETURN_ERROR) {
1779 0 : dlt_daemon_control_service_response(sock,
1780 : daemon,
1781 : daemon_local,
1782 : DLT_SERVICE_ID_GET_LOG_INFO,
1783 : DLT_SERVICE_RESPONSE_ERROR,
1784 : verbose);
1785 0 : return;
1786 : }
1787 :
1788 : /* check request */
1789 0 : if ((req->options < 3) || (req->options > 7)) {
1790 0 : dlt_daemon_control_service_response(sock,
1791 : daemon,
1792 : daemon_local,
1793 : DLT_SERVICE_ID_GET_LOG_INFO,
1794 : DLT_SERVICE_RESPONSE_ERROR,
1795 : verbose);
1796 0 : return;
1797 : }
1798 :
1799 0 : if (req->apid[0] != '\0') {
1800 0 : application = dlt_daemon_application_find(daemon,
1801 0 : req->apid,
1802 : daemon->ecuid,
1803 : verbose);
1804 :
1805 0 : if (application) {
1806 : num_applications = 1;
1807 :
1808 0 : if (req->ctid[0] != '\0') {
1809 0 : context = dlt_daemon_context_find(daemon,
1810 : req->apid,
1811 0 : req->ctid,
1812 : daemon->ecuid,
1813 : verbose);
1814 :
1815 0 : num_contexts = ((context) ? 1 : 0);
1816 : }
1817 : else {
1818 0 : num_contexts = application->num_contexts;
1819 : }
1820 : }
1821 : else {
1822 : num_applications = 0;
1823 : num_contexts = 0;
1824 : }
1825 : }
1826 : else {
1827 : /* Request all applications and contexts */
1828 0 : num_applications = user_list->num_applications;
1829 0 : num_contexts = user_list->num_contexts;
1830 : }
1831 :
1832 : /* prepare payload of data */
1833 :
1834 : /* Calculate maximum size for a response */
1835 : resp.datasize = sizeof(uint32_t) /* SID */ + sizeof(int8_t) /* status*/ + sizeof(ID4) /* DLT_DAEMON_REMO_STRING */;
1836 :
1837 : sizecont = sizeof(uint32_t) /* context_id */;
1838 :
1839 : /* Add additional size for response of Mode 4, 6, 7 */
1840 0 : if ((req->options == 4) || (req->options == 6) || (req->options == 7))
1841 : sizecont += sizeof(int8_t); /* log level */
1842 :
1843 : /* Add additional size for response of Mode 5, 6, 7 */
1844 0 : if ((req->options == 5) || (req->options == 6) || (req->options == 7))
1845 0 : sizecont += sizeof(int8_t); /* trace status */
1846 :
1847 0 : resp.datasize += (int32_t)(((size_t) num_applications * (sizeof(uint32_t) + sizeof(uint16_t))) +
1848 0 : ((size_t) num_contexts * sizecont));
1849 :
1850 0 : resp.datasize += (int32_t)sizeof(uint16_t);
1851 :
1852 : /* Add additional size for response of Mode 7 */
1853 0 : if (req->options == 7) {
1854 0 : if (req->apid[0] != '\0') {
1855 0 : if (req->ctid[0] != '\0') {
1856 : /* One application, one context */
1857 : /* context = dlt_daemon_context_find(daemon, req->apid, req->ctid, verbose); */
1858 0 : if (context) {
1859 0 : resp.datasize += (int32_t)sizeof(uint16_t);
1860 :
1861 0 : if (context->context_description != 0)
1862 0 : resp.datasize += (int32_t)strlen(context->context_description);
1863 : }
1864 : }
1865 : else
1866 : /* One application, all contexts */
1867 0 : if ((user_list->applications) && (application)) {
1868 : /* Calculate start offset within contexts[] */
1869 : offset_base = 0;
1870 :
1871 0 : for (i = 0; i < (application - (user_list->applications)); i++)
1872 0 : offset_base += user_list->applications[i].num_contexts;
1873 :
1874 : /* Iterate over all contexts belonging to this application */
1875 0 : for (j = 0; j < application->num_contexts; j++) {
1876 :
1877 0 : context = &(user_list->contexts[offset_base + j]);
1878 :
1879 0 : if (context) {
1880 0 : resp.datasize += (int32_t)sizeof(uint16_t);
1881 :
1882 0 : if (context->context_description != 0)
1883 0 : resp.datasize += (int32_t)strlen(context->context_description);
1884 : }
1885 : }
1886 : }
1887 :
1888 : /* Space for application description */
1889 0 : if (application) {
1890 0 : resp.datasize += (int32_t)sizeof(uint16_t);
1891 :
1892 0 : if (application->application_description != 0)
1893 0 : resp.datasize += (int32_t)strlen(application->application_description);
1894 : }
1895 : }
1896 : else {
1897 : /* All applications, all contexts */
1898 0 : for (i = 0; i < user_list->num_contexts; i++) {
1899 0 : resp.datasize += (int32_t)sizeof(uint16_t);
1900 :
1901 0 : if (user_list->contexts[i].context_description != 0)
1902 0 : resp.datasize +=
1903 0 : (int32_t)strlen(user_list->contexts[i].context_description);
1904 : }
1905 :
1906 0 : for (i = 0; i < user_list->num_applications; i++) {
1907 0 : resp.datasize += (int32_t)sizeof(uint16_t);
1908 :
1909 0 : if (user_list->applications[i].application_description != 0)
1910 0 : resp.datasize += (int32_t)strlen(user_list->applications[i].application_description);
1911 : }
1912 : }
1913 : }
1914 :
1915 0 : if (verbose)
1916 0 : dlt_vlog(LOG_DEBUG,
1917 : "Allocate %u bytes for response msg databuffer\n",
1918 : resp.datasize);
1919 :
1920 : /* Allocate buffer for response message */
1921 0 : resp.databuffer = (uint8_t *)malloc((size_t)resp.datasize);
1922 0 : resp.databuffersize = (size_t)resp.datasize;
1923 :
1924 0 : if (resp.databuffer == 0) {
1925 0 : dlt_daemon_control_service_response(sock,
1926 : daemon,
1927 : daemon_local,
1928 : DLT_SERVICE_ID_GET_LOG_INFO,
1929 : DLT_SERVICE_RESPONSE_ERROR,
1930 : verbose);
1931 0 : return;
1932 : }
1933 :
1934 : memset(resp.databuffer, 0, (size_t)resp.datasize);
1935 : /* Preparation finished */
1936 :
1937 : /* Prepare response */
1938 0 : sid = DLT_SERVICE_ID_GET_LOG_INFO;
1939 : memcpy(resp.databuffer, &sid, sizeof(uint32_t));
1940 : offset += sizeof(uint32_t);
1941 :
1942 0 : value = (int8_t) (((num_applications != 0) && (num_contexts != 0)) ? req->options : 8); /* 8 = no matching context found */
1943 :
1944 0 : memcpy(resp.databuffer + offset, &value, sizeof(int8_t));
1945 : offset += sizeof(int8_t);
1946 :
1947 0 : count_app_ids = (uint16_t) num_applications;
1948 :
1949 0 : if (count_app_ids != 0) {
1950 0 : memcpy(resp.databuffer + offset, &count_app_ids, sizeof(uint16_t));
1951 : offset += sizeof(uint16_t);
1952 :
1953 : #if (DLT_DEBUG_GETLOGINFO == 1)
1954 : dlt_vlog(LOG_DEBUG, "#apid: %d \n", count_app_ids);
1955 : #endif
1956 :
1957 0 : for (i = 0; i < count_app_ids; i++) {
1958 0 : if (req->apid[0] != '\0') {
1959 0 : apid = req->apid;
1960 : }
1961 : else {
1962 0 : if (user_list->applications)
1963 0 : apid = user_list->applications[i].apid;
1964 : else
1965 : /* This should never occur! */
1966 : apid = 0;
1967 : }
1968 :
1969 0 : application = dlt_daemon_application_find(daemon,
1970 : apid,
1971 : daemon->ecuid,
1972 : verbose);
1973 :
1974 0 : if ((user_list->applications) && (application)) {
1975 : /* Calculate start offset within contexts[] */
1976 : offset_base = 0;
1977 :
1978 0 : for (j = 0; j < (application - (user_list->applications)); j++)
1979 0 : offset_base += user_list->applications[j].num_contexts;
1980 :
1981 0 : dlt_set_id((char *)(resp.databuffer + offset), apid);
1982 0 : offset += sizeof(ID4);
1983 :
1984 : #if (DLT_DEBUG_GETLOGINFO == 1)
1985 : dlt_print_id(buf, apid);
1986 : dlt_vlog(LOG_DEBUG, "apid: %s\n", buf);
1987 : #endif
1988 :
1989 0 : if (req->apid[0] != '\0')
1990 0 : count_con_ids = (uint16_t) num_contexts;
1991 : else
1992 0 : count_con_ids = (uint16_t) application->num_contexts;
1993 :
1994 0 : memcpy(resp.databuffer + offset, &count_con_ids, sizeof(uint16_t));
1995 0 : offset += sizeof(uint16_t);
1996 :
1997 : #if (DLT_DEBUG_GETLOGINFO == 1)
1998 : dlt_vlog(LOG_DEBUG, "#ctid: %d \n", count_con_ids);
1999 : #endif
2000 :
2001 0 : for (j = 0; j < count_con_ids; j++) {
2002 : #if (DLT_DEBUG_GETLOGINFO == 1)
2003 : dlt_vlog(LOG_DEBUG, "j: %d \n", j);
2004 : #endif
2005 :
2006 0 : if (!((count_con_ids == 1) && (req->apid[0] != '\0') &&
2007 0 : (req->ctid[0] != '\0')))
2008 0 : context = &(user_list->contexts[offset_base + j]);
2009 :
2010 : /* else: context was already searched and found
2011 : * (one application (found) with one context (found))*/
2012 :
2013 0 : if ((context) &&
2014 0 : ((req->ctid[0] == '\0') || ((req->ctid[0] != '\0') &&
2015 0 : (memcmp(context->ctid, req->ctid, DLT_ID_SIZE) == 0)))
2016 : ) {
2017 0 : dlt_set_id((char *)(resp.databuffer + offset), context->ctid);
2018 0 : offset += sizeof(ID4);
2019 :
2020 : #if (DLT_DEBUG_GETLOGINFO == 1)
2021 : dlt_print_id(buf, context->ctid);
2022 : dlt_vlog(LOG_DEBUG, "ctid: %s \n", buf);
2023 : #endif
2024 :
2025 : /* Mode 4, 6, 7 */
2026 0 : if ((req->options == 4) || (req->options == 6) || (req->options == 7)) {
2027 0 : ll = context->log_level;
2028 0 : memcpy(resp.databuffer + offset, &ll, sizeof(int8_t));
2029 0 : offset += sizeof(int8_t);
2030 : }
2031 :
2032 : /* Mode 5, 6, 7 */
2033 0 : if ((req->options == 5) || (req->options == 6) || (req->options == 7)) {
2034 0 : ts = context->trace_status;
2035 0 : memcpy(resp.databuffer + offset, &ts, sizeof(int8_t));
2036 0 : offset += sizeof(int8_t);
2037 : }
2038 :
2039 : /* Mode 7 */
2040 0 : if (req->options == 7) {
2041 0 : if (context->context_description) {
2042 0 : len = (uint16_t) strlen(context->context_description);
2043 0 : memcpy(resp.databuffer + offset, &len, sizeof(uint16_t));
2044 0 : offset += sizeof(uint16_t);
2045 0 : memcpy(resp.databuffer + offset, context->context_description,
2046 0 : strlen(context->context_description));
2047 0 : offset += strlen(context->context_description);
2048 : }
2049 : else {
2050 0 : len = 0;
2051 0 : memcpy(resp.databuffer + offset, &len, sizeof(uint16_t));
2052 0 : offset += sizeof(uint16_t);
2053 : }
2054 : }
2055 :
2056 : #if (DLT_DEBUG_GETLOGINFO == 1)
2057 : dlt_vlog(LOG_DEBUG, "ll=%d ts=%d \n", (int32_t)ll,
2058 : (int32_t)ts);
2059 : #endif
2060 : }
2061 :
2062 : #if (DLT_DEBUG_GETLOGINFO == 1)
2063 : dlt_log(LOG_DEBUG, "\n");
2064 : #endif
2065 : }
2066 :
2067 : /* Mode 7 */
2068 0 : if (req->options == 7) {
2069 0 : if (application->application_description) {
2070 0 : len = (uint16_t) strlen(application->application_description);
2071 0 : memcpy(resp.databuffer + offset, &len, sizeof(uint16_t));
2072 0 : offset += sizeof(uint16_t);
2073 0 : memcpy(resp.databuffer + offset, application->application_description,
2074 0 : strlen(application->application_description));
2075 0 : offset += strlen(application->application_description);
2076 : }
2077 : else {
2078 0 : len = 0;
2079 0 : memcpy(resp.databuffer + offset, &len, sizeof(uint16_t));
2080 0 : offset += sizeof(uint16_t);
2081 : }
2082 : }
2083 : } /* if (application) */
2084 :
2085 : } /* for (i=0;i<count_app_ids;i++) */
2086 :
2087 : } /* if (count_app_ids!=0) */
2088 :
2089 0 : dlt_set_id((char *)(resp.databuffer + offset), DLT_DAEMON_REMO_STRING);
2090 :
2091 : /* send message */
2092 0 : dlt_daemon_client_send_control_message(sock, daemon, daemon_local, &resp, "", "", verbose);
2093 :
2094 : /* free message */
2095 0 : dlt_message_free(&resp, 0);
2096 : }
2097 :
2098 0 : void dlt_daemon_control_get_log_info_v2(int sock,
2099 : DltDaemon *daemon,
2100 : DltDaemonLocal *daemon_local,
2101 : DltMessageV2 *msg,
2102 : int verbose)
2103 : {
2104 : DltServiceGetLogInfoRequestV2 *req;
2105 : DltMessageV2 resp;
2106 : DltDaemonContext *context = NULL;
2107 0 : DltDaemonApplication *application = (DltDaemonApplication *)malloc(sizeof(DltDaemonApplication));
2108 :
2109 : int num_applications = 0, num_contexts = 0;
2110 0 : uint16_t count_app_ids = 0, count_con_ids = 0;
2111 :
2112 : #if (DLT_DEBUG_GETLOGINFO == 1)
2113 : char buf[255];
2114 : #endif
2115 : size_t offset = 0;
2116 0 : uint8_t apidlen = 0;
2117 : char *apid = 0;
2118 : int8_t ll, ts;
2119 : uint16_t len;
2120 : int8_t value;
2121 : size_t sizecont = 0;
2122 : int offset_base;
2123 :
2124 : uint32_t sid;
2125 :
2126 : DltDaemonRegisteredUsers *user_list = NULL;
2127 :
2128 0 : PRINT_FUNCTION_VERBOSE(verbose);
2129 :
2130 0 : if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL))
2131 0 : return;
2132 :
2133 0 : if (dlt_check_rcv_data_size(msg->datasize, DLT_SERVICE_GET_LOG_INFO_REQUEST_FIXED_SIZE_V2) < 0)
2134 : return;
2135 :
2136 0 : user_list = dlt_daemon_find_users_list_v2(daemon, daemon->ecuid2len, daemon->ecuid2, verbose);
2137 :
2138 0 : if (user_list == NULL)
2139 : return;
2140 :
2141 0 : req = (DltServiceGetLogInfoRequestV2 *)calloc(1, sizeof(DltServiceGetLogInfoRequestV2));
2142 :
2143 0 : if (req == NULL)
2144 : return;
2145 :
2146 : /* prepare pointer to message request */
2147 : int db_offset = 0;
2148 0 : memcpy(&(req->service_id), msg->databuffer + db_offset, sizeof(uint32_t));
2149 : db_offset = db_offset + (int)sizeof(uint32_t);
2150 0 : memcpy(&(req->options), msg->databuffer + db_offset, sizeof(uint8_t));
2151 : db_offset = db_offset + (int)sizeof(uint8_t);
2152 0 : memcpy(&(req->apidlen), msg->databuffer + db_offset, sizeof(uint8_t));
2153 : db_offset = db_offset + (int)sizeof(uint8_t);
2154 0 : dlt_set_id_v2(req->apid, (const char *)(msg->databuffer + db_offset), req->apidlen);
2155 0 : db_offset = db_offset + (int)req->apidlen;
2156 0 : memcpy(&(req->ctidlen), (const char *)(msg->databuffer + db_offset), sizeof(uint8_t));
2157 0 : db_offset = db_offset + (int)sizeof(uint8_t);
2158 0 : dlt_set_id_v2(req->ctid, (const char *)(msg->databuffer + db_offset), req->ctidlen);
2159 0 : db_offset = db_offset + (int)req->ctidlen;
2160 0 : memcpy((req->com), (const char *)(msg->databuffer + db_offset), DLT_ID_SIZE);
2161 :
2162 : /* initialise new message */
2163 0 : if (dlt_message_init_v2(&resp, 0) == DLT_RETURN_ERROR) {
2164 0 : dlt_daemon_control_service_response_v2(sock,
2165 : daemon,
2166 : daemon_local,
2167 : DLT_SERVICE_ID_GET_LOG_INFO,
2168 : DLT_SERVICE_RESPONSE_ERROR,
2169 : verbose);
2170 0 : return;
2171 : }
2172 :
2173 : /* check request */
2174 0 : if ((req->options < 3) || (req->options > 7)) {
2175 0 : dlt_daemon_control_service_response_v2(sock,
2176 : daemon,
2177 : daemon_local,
2178 : DLT_SERVICE_ID_GET_LOG_INFO,
2179 : DLT_SERVICE_RESPONSE_ERROR,
2180 : verbose);
2181 0 : return;
2182 : }
2183 :
2184 0 : if (req->apidlen != 0) {
2185 :
2186 0 : dlt_daemon_application_find_v2(daemon,
2187 : req->apidlen,
2188 : req->apid,
2189 0 : daemon->ecuid2len,
2190 : daemon->ecuid2,
2191 : verbose,
2192 : &application);
2193 :
2194 0 : if (application) {
2195 : num_applications = 1;
2196 0 : if (req->ctidlen != 0) {
2197 0 : context = dlt_daemon_context_find_v2(daemon,
2198 : req->apidlen,
2199 : req->apid,
2200 : req->ctidlen,
2201 : req->ctid,
2202 0 : daemon->ecuid2len,
2203 : daemon->ecuid2,
2204 : verbose);
2205 :
2206 0 : num_contexts = ((context) ? 1 : 0);
2207 : }
2208 : else {
2209 0 : num_contexts = application->num_contexts;
2210 : }
2211 : }
2212 : else {
2213 : num_applications = 0;
2214 : num_contexts = 0;
2215 : }
2216 : }
2217 : else {
2218 : /* Request all applications and contexts */
2219 0 : num_applications = user_list->num_applications;
2220 0 : num_contexts = user_list->num_contexts;
2221 : }
2222 : /* prepare payload of data */
2223 :
2224 : /* Calculate maximum size for a response */
2225 0 : resp.datasize = sizeof(uint32_t) /* SID */ + sizeof(int8_t) /* status*/ + sizeof(ID4) /* DLT_DAEMON_REMO_STRING */;
2226 :
2227 : sizecont = sizeof(uint8_t) /* context_id length */;
2228 :
2229 : /* Add additional size for response of Mode 4, 6, 7 */
2230 0 : if ((req->options == 4) || (req->options == 6) || (req->options == 7))
2231 : sizecont += sizeof(int8_t); /* log level */
2232 :
2233 : /* Add additional size for response of Mode 5, 6, 7 */
2234 0 : if ((req->options == 5) || (req->options == 6) || (req->options == 7))
2235 0 : sizecont += sizeof(int8_t); /* trace status */
2236 :
2237 0 : if ((num_applications == user_list->num_applications) && (num_contexts == user_list->num_contexts)){
2238 0 : for(int i = 0; i<num_applications; i++){
2239 0 : resp.datasize += (int32_t) ((sizeof(uint8_t) /* app_id length */ + user_list->applications[i].apid2len /* app_id */ + sizeof(uint16_t) /* count_con_ids */));
2240 : }
2241 0 : for(int j = 0; j<num_contexts; j++){
2242 0 : resp.datasize += (int32_t) (sizecont + user_list->contexts[j].ctid2len);
2243 : }
2244 0 : }else if (num_applications == 1) {
2245 0 : resp.datasize += (int32_t) ((sizeof(uint8_t) /* app_id length */ + application->apid2len /* app_id */ + sizeof(uint16_t) /* count_con_ids */));
2246 : /* 1 application and 1 context*/
2247 0 : if (num_contexts == 1) {
2248 0 : resp.datasize += (int32_t) (sizecont + context->ctid2len);
2249 0 : }else if (num_contexts == application->num_contexts) {
2250 0 : if ((user_list->applications) && (application)) {
2251 : /* Calculate start offset within contexts[] */
2252 : offset_base = 0;
2253 :
2254 0 : for (int i = 0; i < (application - (user_list->applications)); i++)
2255 0 : offset_base += user_list->applications[i].num_contexts;
2256 :
2257 : /* Iterate over all contexts belonging to this application */
2258 0 : for (int j = 0; j < application->num_contexts; j++) {
2259 0 : context = &(user_list->contexts[offset_base + j]);
2260 :
2261 0 : if (context) {
2262 0 : resp.datasize += (int32_t) (sizecont + context->ctid2len);
2263 : }
2264 : }
2265 : }
2266 : }
2267 : }
2268 0 : resp.datasize += (int32_t) sizeof(uint16_t) /* count_app_ids */;
2269 :
2270 : /* Add additional size for response of Mode 7 */
2271 0 : if (req->options == 7) {
2272 0 : if (req->apidlen != 0) {
2273 0 : if (req->ctidlen != 0) {
2274 : /* One application, one context */
2275 0 : if (context) {
2276 0 : resp.datasize += (int32_t) sizeof(uint16_t) /* len_context_description */;
2277 :
2278 0 : if (context->context_description != 0)
2279 0 : resp.datasize += (int32_t) strlen(context->context_description); /* context_description */
2280 : }
2281 : }
2282 : else
2283 : /* One application, all contexts */
2284 0 : if ((user_list->applications) && (application)) {
2285 : /* Calculate start offset within contexts[] */
2286 : offset_base = 0;
2287 :
2288 0 : for (int i = 0; i < (application - (user_list->applications)); i++)
2289 0 : offset_base += user_list->applications[i].num_contexts;
2290 :
2291 : /* Iterate over all contexts belonging to this application */
2292 0 : for (int j = 0; j < application->num_contexts; j++) {
2293 0 : context = &(user_list->contexts[offset_base + j]);
2294 :
2295 0 : if (context) {
2296 0 : resp.datasize += (int32_t) sizeof(uint16_t) /* len_context_description */;
2297 :
2298 0 : if (context->context_description != 0)
2299 0 : resp.datasize += (int32_t) strlen(context->context_description); /* context_description */
2300 : }
2301 : }
2302 : }
2303 :
2304 : /* Space for application description */
2305 0 : if (application) {
2306 0 : resp.datasize += (int32_t) sizeof(uint16_t) /* len_app_description */;
2307 :
2308 0 : if (application->application_description != 0)
2309 0 : resp.datasize += (int32_t) strlen(application->application_description); /* app_description */
2310 : }
2311 : }
2312 : else {
2313 : /* All applications, all contexts */
2314 0 : for (int i = 0; i < user_list->num_contexts; i++) {
2315 0 : resp.datasize += (int32_t) sizeof(uint16_t) /* len_context_description */;
2316 :
2317 0 : if (user_list->contexts[i].context_description != 0)
2318 0 : resp.datasize +=
2319 0 : (int32_t) strlen(user_list->contexts[i].context_description);
2320 : }
2321 :
2322 0 : for (int i = 0; i < user_list->num_applications; i++) {
2323 0 : resp.datasize += (int32_t) sizeof(uint16_t) /* len_app_description */;
2324 0 : if (user_list->applications[i].application_description != 0)
2325 0 : resp.datasize += (int32_t) strlen(user_list->applications[i].application_description); /* app_description */
2326 : }
2327 : }
2328 : }
2329 :
2330 0 : if (verbose)
2331 0 : dlt_vlog(LOG_DEBUG,
2332 : "Allocate %u bytes for response msg databuffer\n",
2333 : resp.datasize);
2334 :
2335 : /* Allocate buffer for response message */
2336 0 : resp.databuffer = (uint8_t *)malloc((size_t)resp.datasize);
2337 : resp.datasize = resp.datasize;
2338 :
2339 0 : if (resp.databuffer == 0) {
2340 0 : dlt_daemon_control_service_response_v2(sock,
2341 : daemon,
2342 : daemon_local,
2343 : DLT_SERVICE_ID_GET_LOG_INFO,
2344 : DLT_SERVICE_RESPONSE_ERROR,
2345 : verbose);
2346 0 : return;
2347 : }
2348 :
2349 : memset(resp.databuffer, 0, (size_t)resp.datasize);
2350 : /* Preparation finished */
2351 :
2352 : /* Prepare response */
2353 0 : sid = DLT_SERVICE_ID_GET_LOG_INFO;
2354 : memcpy(resp.databuffer, &sid, sizeof(uint32_t));
2355 : offset += sizeof(uint32_t);
2356 :
2357 0 : value = (int8_t) (((num_applications != 0) && (num_contexts != 0)) ? req->options : 8); /* 8 = no matching context found */
2358 :
2359 0 : memcpy(resp.databuffer + offset, &value, sizeof(int8_t));
2360 : offset += sizeof(int8_t);
2361 :
2362 0 : count_app_ids = (uint16_t) num_applications;
2363 :
2364 0 : if (count_app_ids != 0) {
2365 0 : memcpy(resp.databuffer + offset, &count_app_ids, sizeof(uint16_t));
2366 : offset += sizeof(uint16_t);
2367 :
2368 : #if (DLT_DEBUG_GETLOGINFO == 1)
2369 : dlt_vlog(LOG_DEBUG, "#apid: %d \n", count_app_ids);
2370 : #endif
2371 :
2372 0 : for (int i = 0; i < count_app_ids; i++) {
2373 0 : if (req->apidlen != 0) {
2374 : apid = req->apid;
2375 0 : apidlen = req->apidlen;
2376 : }
2377 : else {
2378 0 : if (user_list->applications){
2379 0 : apid = user_list->applications[i].apid2;
2380 0 : apidlen = user_list->applications[i].apid2len;
2381 : }
2382 : else {
2383 : /* This should never occur! */
2384 : apid = NULL;
2385 0 : apidlen = 0;
2386 : }
2387 : }
2388 :
2389 0 : dlt_daemon_application_find_v2(daemon,
2390 : apidlen,
2391 : apid,
2392 0 : daemon->ecuid2len,
2393 : daemon->ecuid2,
2394 : verbose,
2395 : &application);
2396 :
2397 0 : if ((user_list->applications) && (application)) {
2398 : /* Calculate start offset within contexts[] */
2399 : offset_base = 0;
2400 :
2401 0 : for (int j = 0; j < (application - (user_list->applications)); j++)
2402 0 : offset_base += user_list->applications[j].num_contexts;
2403 0 : memcpy(resp.databuffer + offset, &apidlen, 1);
2404 0 : offset += 1;
2405 0 : memcpy(resp.databuffer + offset, apid, apidlen);
2406 0 : offset += apidlen;
2407 :
2408 : #if (DLT_DEBUG_GETLOGINFO == 1)
2409 : dlt_print_id_v2(buf, apid, apidlen);
2410 : if ((buf == NULL) || (apid == NULL) || (apidlen == 0)) {
2411 : dlt_vlog(LOG_ERR, "Failed to memcpy apid\n");
2412 : }
2413 :
2414 : memcpy(buf, apid, apidlen);
2415 : dlt_vlog(LOG_DEBUG, "apid: %s\n", buf);
2416 : #endif
2417 0 : if (req->apidlen != 0)
2418 0 : count_con_ids = (uint16_t) num_contexts;
2419 : else
2420 0 : count_con_ids = (uint16_t) application->num_contexts;
2421 :
2422 0 : memcpy(resp.databuffer + offset, &count_con_ids, sizeof(uint16_t));
2423 0 : offset += sizeof(uint16_t);
2424 :
2425 : #if (DLT_DEBUG_GETLOGINFO == 1)
2426 : dlt_vlog(LOG_DEBUG, "#ctid: %d \n", count_con_ids);
2427 : #endif
2428 :
2429 0 : for (int j = 0; j < count_con_ids; j++) {
2430 : #if (DLT_DEBUG_GETLOGINFO == 1)
2431 : dlt_vlog(LOG_DEBUG, "j: %d \n", j);
2432 : #endif
2433 :
2434 0 : if (!((count_con_ids == 1) && (req->apidlen != 0) &&
2435 : (req->ctidlen != 0)))
2436 0 : context = &(user_list->contexts[offset_base + j]);
2437 :
2438 : /* else: context was already searched and found
2439 : * (one application (found) with one context (found))*/
2440 :
2441 0 : if ((context) &&
2442 0 : ((req->ctidlen == 0) || ((req->ctidlen != 0) &&
2443 0 : (memcmp(context->ctid2, req->ctid, req->ctidlen) == 0)))
2444 : ) {
2445 0 : memcpy(resp.databuffer + offset, &(context->ctid2len), 1);
2446 0 : offset += 1;
2447 0 : memcpy(resp.databuffer + offset, context->ctid2, context->ctid2len);
2448 0 : offset += context->ctid2len;
2449 :
2450 : #if (DLT_DEBUG_GETLOGINFO == 1)
2451 : // dlt_print_id_v2(buf, context->ctid, context->ctid2len);
2452 : //TBD: Enable below check for NULL
2453 : /*
2454 : if ((buf == NULL) || (context->ctid == NULL) || (context->ctid2len == 0)) {
2455 : dlt_vlog(LOG_ERR, "Failed to memcpy ctid\n");
2456 : }
2457 : */
2458 :
2459 : memcpy(buf, context->ctid2, context->ctid2len);
2460 : dlt_vlog(LOG_DEBUG, "ctid: %s \n", buf);
2461 : #endif
2462 :
2463 : /* Mode 4, 6, 7 */
2464 0 : if ((req->options == 4) || (req->options == 6) || (req->options == 7)) {
2465 0 : ll = context->log_level;
2466 0 : memcpy(resp.databuffer + offset, &ll, sizeof(int8_t));
2467 0 : offset += sizeof(int8_t);
2468 : }
2469 :
2470 : /* Mode 5, 6, 7 */
2471 0 : if ((req->options == 5) || (req->options == 6) || (req->options == 7)) {
2472 0 : ts = context->trace_status;
2473 0 : memcpy(resp.databuffer + offset, &ts, sizeof(int8_t));
2474 0 : offset += sizeof(int8_t);
2475 : }
2476 :
2477 : /* Mode 7 */
2478 0 : if (req->options == 7) {
2479 0 : if (context->context_description) {
2480 0 : len = (uint16_t) strlen(context->context_description);
2481 0 : memcpy(resp.databuffer + offset, &len, sizeof(uint16_t));
2482 0 : offset += sizeof(uint16_t);
2483 0 : memcpy(resp.databuffer + offset, context->context_description,
2484 0 : strlen(context->context_description));
2485 0 : offset += strlen(context->context_description);
2486 : }
2487 : else {
2488 0 : len = 0;
2489 0 : memcpy(resp.databuffer + offset, &len, sizeof(uint16_t));
2490 0 : offset += sizeof(uint16_t);
2491 : }
2492 : }
2493 :
2494 : #if (DLT_DEBUG_GETLOGINFO == 1)
2495 : dlt_vlog(LOG_DEBUG, "ll=%d ts=%d \n", (int32_t)ll,
2496 : (int32_t)ts);
2497 : #endif
2498 : }
2499 :
2500 : #if (DLT_DEBUG_GETLOGINFO == 1)
2501 : dlt_log(LOG_DEBUG, "\n");
2502 : #endif
2503 : }
2504 :
2505 : /* Mode 7 */
2506 0 : if (req->options == 7) {
2507 0 : if (application->application_description) {
2508 0 : len = (uint16_t) strlen(application->application_description);
2509 0 : memcpy(resp.databuffer + offset, &len, sizeof(uint16_t));
2510 0 : offset += sizeof(uint16_t);
2511 0 : memcpy(resp.databuffer + offset, application->application_description,
2512 0 : strlen(application->application_description));
2513 0 : offset += strlen(application->application_description);
2514 : }
2515 : else {
2516 0 : len = 0;
2517 0 : memcpy(resp.databuffer + offset, &len, sizeof(uint16_t));
2518 0 : offset += sizeof(uint16_t);
2519 : }
2520 : }
2521 : } /* if (application) */
2522 :
2523 : } /* for (i=0;i<count_app_ids;i++) */
2524 :
2525 : } /* if (count_app_ids!=0) */
2526 :
2527 0 : dlt_set_id((char *)(resp.databuffer + offset), DLT_DAEMON_REMO_STRING);
2528 :
2529 : /* send message */
2530 0 : dlt_daemon_client_send_control_message_v2(sock, daemon, daemon_local, &resp, "", "", verbose);
2531 :
2532 0 : free(req);
2533 :
2534 : /* free message */
2535 0 : dlt_message_free_v2(&resp, 0);
2536 : }
2537 :
2538 0 : int dlt_daemon_control_message_buffer_overflow(int sock,
2539 : DltDaemon *daemon,
2540 : DltDaemonLocal *daemon_local,
2541 : unsigned int overflow_counter,
2542 : char *apid,
2543 : int verbose)
2544 : {
2545 : int ret;
2546 : DltMessage msg;
2547 : DltServiceMessageBufferOverflowResponse *resp;
2548 :
2549 0 : PRINT_FUNCTION_VERBOSE(verbose);
2550 :
2551 0 : if (daemon == 0)
2552 : return DLT_DAEMON_ERROR_UNKNOWN;
2553 :
2554 : /* initialise new message */
2555 0 : if (dlt_message_init(&msg, 0) == DLT_RETURN_ERROR) {
2556 0 : dlt_daemon_control_service_response(sock,
2557 : daemon,
2558 : daemon_local,
2559 : DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW,
2560 : DLT_SERVICE_RESPONSE_ERROR,
2561 : verbose);
2562 0 : return DLT_DAEMON_ERROR_UNKNOWN;
2563 : }
2564 :
2565 : /* prepare payload of data */
2566 0 : msg.datasize = sizeof(DltServiceMessageBufferOverflowResponse);
2567 :
2568 0 : if (msg.databuffer && (msg.databuffersize < msg.datasize)) {
2569 0 : free(msg.databuffer);
2570 0 : msg.databuffer = 0;
2571 : }
2572 :
2573 0 : if (msg.databuffer == 0) {
2574 0 : msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize);
2575 0 : msg.databuffersize = (size_t)msg.datasize;
2576 : }
2577 :
2578 0 : if (msg.databuffer == 0)
2579 : return DLT_DAEMON_ERROR_UNKNOWN;
2580 :
2581 : resp = (DltServiceMessageBufferOverflowResponse *)msg.databuffer;
2582 0 : resp->service_id = DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW;
2583 0 : resp->status = DLT_SERVICE_RESPONSE_OK;
2584 0 : resp->overflow = DLT_MESSAGE_BUFFER_OVERFLOW;
2585 0 : resp->overflow_counter = overflow_counter;
2586 :
2587 : /* send message */
2588 0 : if ((ret = dlt_daemon_client_send_control_message(sock, daemon, daemon_local, &msg, apid, "", verbose))) {
2589 0 : dlt_message_free(&msg, 0);
2590 0 : return ret;
2591 : }
2592 :
2593 : /* free message */
2594 0 : dlt_message_free(&msg, 0);
2595 :
2596 0 : return DLT_DAEMON_ERROR_OK;
2597 : }
2598 :
2599 0 : int dlt_daemon_control_message_buffer_overflow_v2(int sock,
2600 : DltDaemon *daemon,
2601 : DltDaemonLocal *daemon_local,
2602 : unsigned int overflow_counter,
2603 : char *apid,
2604 : int verbose)
2605 : {
2606 : int ret;
2607 : DltMessageV2 msg;
2608 : DltServiceMessageBufferOverflowResponse *resp;
2609 :
2610 0 : PRINT_FUNCTION_VERBOSE(verbose);
2611 :
2612 0 : if (daemon == 0)
2613 : return DLT_DAEMON_ERROR_UNKNOWN;
2614 :
2615 : /* initialise new message */
2616 0 : if (dlt_message_init_v2(&msg, 0) == DLT_RETURN_ERROR) {
2617 0 : dlt_daemon_control_service_response_v2(sock,
2618 : daemon,
2619 : daemon_local,
2620 : DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW,
2621 : DLT_SERVICE_RESPONSE_ERROR,
2622 : verbose);
2623 0 : return DLT_DAEMON_ERROR_UNKNOWN;
2624 : }
2625 :
2626 : /* prepare payload of data */
2627 0 : msg.datasize = sizeof(DltServiceMessageBufferOverflowResponse);
2628 :
2629 0 : if (msg.databuffer && (msg.databuffersize < msg.datasize)) {
2630 0 : free(msg.databuffer);
2631 0 : msg.databuffer = 0;
2632 : }
2633 :
2634 0 : if (msg.databuffer == 0) {
2635 0 : msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize);
2636 0 : msg.databuffersize = (size_t)msg.datasize;
2637 : }
2638 :
2639 0 : if (msg.databuffer == 0)
2640 : return DLT_DAEMON_ERROR_UNKNOWN;
2641 :
2642 : resp = (DltServiceMessageBufferOverflowResponse *)msg.databuffer;
2643 0 : resp->service_id = DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW;
2644 0 : resp->status = DLT_SERVICE_RESPONSE_OK;
2645 0 : resp->overflow = DLT_MESSAGE_BUFFER_OVERFLOW;
2646 0 : resp->overflow_counter = overflow_counter;
2647 :
2648 : /* send message */
2649 0 : if ((ret = dlt_daemon_client_send_control_message_v2(sock, daemon, daemon_local, &msg, apid, "", verbose))) {
2650 0 : dlt_message_free_v2(&msg, 0);
2651 0 : return ret;
2652 : }
2653 :
2654 : /* free message */
2655 0 : dlt_message_free_v2(&msg, 0);
2656 :
2657 0 : return DLT_DAEMON_ERROR_OK;
2658 : }
2659 :
2660 1 : void dlt_daemon_control_service_response(int sock,
2661 : DltDaemon *daemon,
2662 : DltDaemonLocal *daemon_local,
2663 : uint32_t service_id,
2664 : int8_t status,
2665 : int verbose)
2666 : {
2667 : DltMessage msg;
2668 : DltServiceResponse *resp;
2669 :
2670 1 : PRINT_FUNCTION_VERBOSE(verbose);
2671 :
2672 1 : if (daemon == 0)
2673 0 : return;
2674 :
2675 : /* initialise new message */
2676 1 : if (dlt_message_init(&msg, 0) == DLT_RETURN_ERROR)
2677 : return;
2678 :
2679 : /* prepare payload of data */
2680 1 : msg.datasize = sizeof(DltServiceResponse);
2681 :
2682 1 : if (msg.databuffer && (msg.databuffersize < msg.datasize)) {
2683 0 : free(msg.databuffer);
2684 0 : msg.databuffer = 0;
2685 : }
2686 :
2687 1 : if (msg.databuffer == 0) {
2688 1 : msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize);
2689 1 : msg.databuffersize = (size_t)msg.datasize;
2690 : }
2691 :
2692 1 : if (msg.databuffer == 0)
2693 : return;
2694 :
2695 : resp = (DltServiceResponse *)msg.databuffer;
2696 1 : resp->service_id = service_id;
2697 1 : resp->status = (uint8_t) status;
2698 :
2699 : /* send message */
2700 1 : dlt_daemon_client_send_control_message(sock, daemon, daemon_local, &msg, "", "", verbose);
2701 :
2702 : /* free message */
2703 1 : dlt_message_free(&msg, 0);
2704 : }
2705 :
2706 0 : void dlt_daemon_control_service_response_v2(int sock,
2707 : DltDaemon *daemon,
2708 : DltDaemonLocal *daemon_local,
2709 : uint32_t service_id,
2710 : int8_t status,
2711 : int verbose)
2712 : {
2713 : DltMessageV2 msg;
2714 : DltServiceResponse *resp;
2715 :
2716 0 : PRINT_FUNCTION_VERBOSE(verbose);
2717 :
2718 0 : if (daemon == 0)
2719 0 : return;
2720 :
2721 : /* initialise new message */
2722 0 : if (dlt_message_init_v2(&msg, 0) == DLT_RETURN_ERROR)
2723 : return;
2724 :
2725 : /* prepare payload of data */
2726 0 : msg.datasize = sizeof(DltServiceResponse);
2727 :
2728 0 : if (msg.databuffer && (msg.databuffersize < msg.datasize)) {
2729 0 : free(msg.databuffer);
2730 0 : msg.databuffer = 0;
2731 : }
2732 :
2733 0 : if (msg.databuffer == 0) {
2734 0 : msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize);
2735 0 : msg.databuffersize = (size_t)msg.datasize;
2736 : }
2737 :
2738 0 : if (msg.databuffer == 0)
2739 : return;
2740 :
2741 : resp = (DltServiceResponse *)msg.databuffer;
2742 0 : resp->service_id = service_id;
2743 0 : resp->status = (uint8_t) status;
2744 :
2745 : /* send message */
2746 0 : dlt_daemon_client_send_control_message_v2(sock, daemon, daemon_local, &msg, "", "", verbose);
2747 :
2748 : /* free message */
2749 0 : dlt_message_free_v2(&msg, 0);
2750 : }
2751 :
2752 0 : int dlt_daemon_control_message_unregister_context(int sock,
2753 : DltDaemon *daemon,
2754 : DltDaemonLocal *daemon_local,
2755 : char *apid,
2756 : char *ctid,
2757 : char *comid,
2758 : int verbose)
2759 : {
2760 : DltMessage msg;
2761 : DltServiceUnregisterContext *resp;
2762 :
2763 0 : PRINT_FUNCTION_VERBOSE(verbose);
2764 :
2765 0 : if (daemon == 0)
2766 : return -1;
2767 :
2768 : /* initialise new message */
2769 0 : if (dlt_message_init(&msg, 0) == DLT_RETURN_ERROR)
2770 : return -1;
2771 :
2772 : /* prepare payload of data */
2773 0 : msg.datasize = sizeof(DltServiceUnregisterContext);
2774 :
2775 0 : if (msg.databuffer && (msg.databuffersize < msg.datasize)) {
2776 0 : free(msg.databuffer);
2777 0 : msg.databuffer = 0;
2778 : }
2779 :
2780 0 : if (msg.databuffer == 0) {
2781 0 : msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize);
2782 0 : msg.databuffersize = (size_t)msg.datasize;
2783 : }
2784 :
2785 0 : if (msg.databuffer == 0)
2786 : return -1;
2787 :
2788 : resp = (DltServiceUnregisterContext *)msg.databuffer;
2789 0 : resp->service_id = DLT_SERVICE_ID_UNREGISTER_CONTEXT;
2790 0 : resp->status = DLT_SERVICE_RESPONSE_OK;
2791 0 : dlt_set_id(resp->apid, apid);
2792 0 : dlt_set_id(resp->ctid, ctid);
2793 0 : dlt_set_id(resp->comid, comid);
2794 :
2795 : /* send message */
2796 0 : if (dlt_daemon_client_send_control_message(sock, daemon, daemon_local, &msg, "", "", verbose)) {
2797 0 : dlt_message_free(&msg, 0);
2798 0 : return -1;
2799 : }
2800 :
2801 : /* free message */
2802 0 : dlt_message_free(&msg, 0);
2803 :
2804 0 : return 0;
2805 : }
2806 :
2807 0 : int dlt_daemon_control_message_unregister_context_v2(int sock,
2808 : DltDaemon *daemon,
2809 : DltDaemonLocal *daemon_local,
2810 : uint8_t apidlen,
2811 : char *apid,
2812 : uint8_t ctidlen,
2813 : char *ctid,
2814 : char *comid,
2815 : int verbose)
2816 : {
2817 : DltMessageV2 msg;
2818 : DltServiceUnregisterContextV2 resp;
2819 : uint8_t contextSize = 0;
2820 0 : resp.apid = NULL;
2821 0 : resp.ctid = NULL;
2822 : int offset = 0;
2823 :
2824 0 : PRINT_FUNCTION_VERBOSE(verbose);
2825 :
2826 0 : if (daemon == 0)
2827 : return -1;
2828 :
2829 : /* initialise new message */
2830 0 : if (dlt_message_init_v2(&msg, 0) == DLT_RETURN_ERROR)
2831 : return -1;
2832 :
2833 : /* prepare payload of data */
2834 0 : contextSize = (uint8_t)(sizeof(uint32_t) + sizeof(uint8_t) + sizeof(uint8_t) + apidlen + sizeof(uint8_t) + ctidlen + DLT_ID_SIZE);
2835 :
2836 0 : msg.datasize = contextSize;
2837 :
2838 0 : if (msg.databuffer && (msg.databuffersize < msg.datasize)) {
2839 0 : free(msg.databuffer);
2840 0 : msg.databuffer = 0;
2841 : }
2842 :
2843 0 : if (msg.databuffer == 0) {
2844 0 : msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize);
2845 0 : msg.databuffersize = (size_t)msg.datasize;
2846 : }
2847 :
2848 0 : if (msg.databuffer == 0)
2849 : return -1;
2850 :
2851 0 : resp.service_id = DLT_SERVICE_ID_UNREGISTER_CONTEXT;
2852 0 : resp.status = DLT_SERVICE_RESPONSE_OK;
2853 0 : dlt_set_id_v2(resp.apid, apid, resp.apidlen);
2854 0 : dlt_set_id_v2(resp.ctid, ctid, resp.ctidlen);
2855 0 : dlt_set_id(resp.comid, comid);
2856 :
2857 0 : memcpy(msg.databuffer + offset, &(resp.service_id), sizeof(uint32_t));
2858 : offset = offset + (int)sizeof(uint32_t);
2859 0 : memcpy(msg.databuffer + offset, &(resp.status), sizeof(uint8_t));
2860 : offset = offset + (int)sizeof(uint8_t);
2861 0 : memcpy(msg.databuffer + offset, &(resp.apidlen), sizeof(uint8_t));
2862 : offset = offset + (int)sizeof(uint8_t);
2863 0 : memcpy(msg.databuffer + offset, resp.apid, resp.apidlen);
2864 0 : offset = offset + (int)resp.apidlen;
2865 0 : memcpy(msg.databuffer + offset, &(resp.ctidlen), sizeof(uint8_t));
2866 0 : offset = offset + (int)sizeof(uint8_t);
2867 0 : memcpy(msg.databuffer + offset, resp.ctid, resp.ctidlen);
2868 0 : offset = offset + (int)resp.ctidlen;
2869 0 : memcpy(msg.databuffer + offset, resp.comid, DLT_ID_SIZE);
2870 :
2871 : /* send message */
2872 0 : if (dlt_daemon_client_send_control_message_v2(sock, daemon, daemon_local, &msg, "", "", verbose)) {
2873 0 : dlt_message_free_v2(&msg, 0);
2874 0 : return -1;
2875 : }
2876 :
2877 : /* free message */
2878 0 : dlt_message_free_v2(&msg, 0);
2879 :
2880 0 : return 0;
2881 : }
2882 :
2883 1 : int dlt_daemon_control_message_connection_info(int sock,
2884 : DltDaemon *daemon,
2885 : DltDaemonLocal *daemon_local,
2886 : uint8_t state,
2887 : char *comid,
2888 : int verbose)
2889 : {
2890 : DltMessage msg;
2891 : DltServiceConnectionInfo *resp;
2892 :
2893 1 : PRINT_FUNCTION_VERBOSE(verbose);
2894 :
2895 1 : if (daemon == 0)
2896 : return -1;
2897 :
2898 : /* initialise new message */
2899 1 : if (dlt_message_init(&msg, 0) == DLT_RETURN_ERROR)
2900 : return -1;
2901 :
2902 : /* prepare payload of data */
2903 1 : msg.datasize = sizeof(DltServiceConnectionInfo);
2904 :
2905 1 : if (msg.databuffer && (msg.databuffersize < msg.datasize)) {
2906 0 : free(msg.databuffer);
2907 0 : msg.databuffer = 0;
2908 : }
2909 :
2910 1 : if (msg.databuffer == 0) {
2911 1 : msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize);
2912 1 : msg.databuffersize = (size_t)msg.datasize;
2913 : }
2914 :
2915 1 : if (msg.databuffer == 0)
2916 : return -1;
2917 :
2918 : resp = (DltServiceConnectionInfo *)msg.databuffer;
2919 1 : resp->service_id = DLT_SERVICE_ID_CONNECTION_INFO;
2920 1 : resp->status = DLT_SERVICE_RESPONSE_OK;
2921 1 : resp->state = state;
2922 1 : dlt_set_id(resp->comid, comid);
2923 :
2924 : /* send message */
2925 1 : if (dlt_daemon_client_send_control_message(sock, daemon, daemon_local, &msg, "", "", verbose)) {
2926 0 : dlt_message_free(&msg, 0);
2927 0 : return -1;
2928 : }
2929 :
2930 : /* free message */
2931 1 : dlt_message_free(&msg, 0);
2932 :
2933 1 : return 0;
2934 : }
2935 :
2936 0 : int dlt_daemon_control_message_connection_info_v2(int sock,
2937 : DltDaemon *daemon,
2938 : DltDaemonLocal *daemon_local,
2939 : uint8_t state,
2940 : char *comid,
2941 : int verbose)
2942 : {
2943 : DltMessageV2 msg;
2944 : DltServiceConnectionInfo *resp;
2945 :
2946 0 : PRINT_FUNCTION_VERBOSE(verbose);
2947 :
2948 0 : if (daemon == 0)
2949 : return -1;
2950 :
2951 : /* initialise new message */
2952 0 : if (dlt_message_init_v2(&msg, 0) == DLT_RETURN_ERROR)
2953 : return -1;
2954 :
2955 : /* prepare payload of data */
2956 0 : msg.datasize = sizeof(DltServiceConnectionInfo);
2957 :
2958 0 : if (msg.databuffer && (msg.databuffersize < msg.datasize)) {
2959 0 : free(msg.databuffer);
2960 0 : msg.databuffer = 0;
2961 : }
2962 :
2963 0 : if (msg.databuffer == 0) {
2964 0 : msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize);
2965 0 : msg.databuffersize = (size_t)msg.datasize;
2966 : }
2967 :
2968 0 : if (msg.databuffer == 0)
2969 : return -1;
2970 :
2971 : resp = (DltServiceConnectionInfo *)msg.databuffer;
2972 0 : resp->service_id = DLT_SERVICE_ID_CONNECTION_INFO;
2973 0 : resp->status = DLT_SERVICE_RESPONSE_OK;
2974 0 : resp->state = state;
2975 0 : dlt_set_id(resp->comid, comid);
2976 :
2977 : /* send message */
2978 0 : if (dlt_daemon_client_send_control_message_v2(sock, daemon, daemon_local, &msg, "", "", verbose)) {
2979 0 : dlt_message_free_v2(&msg, 0);
2980 0 : return -1;
2981 : }
2982 :
2983 : /* free message */
2984 0 : dlt_message_free_v2(&msg, 0);
2985 :
2986 0 : return 0;
2987 : }
2988 :
2989 0 : int dlt_daemon_control_message_timezone(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
2990 : {
2991 : DltMessage msg;
2992 : DltServiceTimezone *resp;
2993 :
2994 0 : PRINT_FUNCTION_VERBOSE(verbose);
2995 :
2996 0 : if (daemon == 0)
2997 : return -1;
2998 :
2999 : /* initialise new message */
3000 0 : if (dlt_message_init(&msg, 0) == DLT_RETURN_ERROR)
3001 : return -1;
3002 :
3003 : /* prepare payload of data */
3004 0 : msg.datasize = sizeof(DltServiceTimezone);
3005 :
3006 0 : if (msg.databuffer && (msg.databuffersize < msg.datasize)) {
3007 0 : free(msg.databuffer);
3008 0 : msg.databuffer = 0;
3009 : }
3010 :
3011 0 : if (msg.databuffer == 0) {
3012 0 : msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize);
3013 0 : msg.databuffersize = (size_t)msg.datasize;
3014 : }
3015 :
3016 0 : if (msg.databuffer == 0)
3017 : return -1;
3018 :
3019 : resp = (DltServiceTimezone *)msg.databuffer;
3020 0 : resp->service_id = DLT_SERVICE_ID_TIMEZONE;
3021 0 : resp->status = DLT_SERVICE_RESPONSE_OK;
3022 :
3023 0 : time_t t = time(NULL);
3024 : struct tm lt;
3025 0 : tzset();
3026 0 : localtime_r(&t, <);
3027 : #if defined(__USE_BSD) || defined(__USE_GNU) || defined(__APPLE__)
3028 0 : resp->timezone = (int32_t)lt.tm_gmtoff;
3029 : #else
3030 : /* Portable fallback: timezone is the difference in seconds between UTC and local time */
3031 : {
3032 : struct tm gmt;
3033 : gmtime_r(&t, &gmt);
3034 : resp->timezone = (int32_t)difftime(mktime(<), mktime(&gmt));
3035 : }
3036 : #endif
3037 0 : resp->isdst = (uint8_t)lt.tm_isdst;
3038 :
3039 : /* send message */
3040 0 : if (dlt_daemon_client_send_control_message(sock, daemon, daemon_local, &msg, "", "", verbose)) {
3041 0 : dlt_message_free(&msg, 0);
3042 0 : return -1;
3043 : }
3044 :
3045 : /* free message */
3046 0 : dlt_message_free(&msg, 0);
3047 :
3048 0 : return 0;
3049 : }
3050 :
3051 0 : int dlt_daemon_control_message_timezone_v2(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
3052 : {
3053 : DltMessageV2 msg;
3054 : DltServiceTimezone *resp;
3055 :
3056 0 : PRINT_FUNCTION_VERBOSE(verbose);
3057 :
3058 0 : if (daemon == 0)
3059 : return -1;
3060 :
3061 : /* initialise new message */
3062 0 : if (dlt_message_init_v2(&msg, 0) == DLT_RETURN_ERROR)
3063 : return -1;
3064 :
3065 : /* prepare payload of data */
3066 0 : msg.datasize = sizeof(DltServiceTimezone);
3067 :
3068 0 : if (msg.databuffer && (msg.databuffersize < msg.datasize)) {
3069 0 : free(msg.databuffer);
3070 0 : msg.databuffer = 0;
3071 : }
3072 :
3073 0 : if (msg.databuffer == 0) {
3074 0 : msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize);
3075 0 : msg.databuffersize = (size_t)msg.datasize;
3076 : }
3077 :
3078 0 : if (msg.databuffer == 0)
3079 : return -1;
3080 :
3081 : resp = (DltServiceTimezone *)msg.databuffer;
3082 0 : resp->service_id = DLT_SERVICE_ID_TIMEZONE;
3083 0 : resp->status = DLT_SERVICE_RESPONSE_OK;
3084 :
3085 0 : time_t t = time(NULL);
3086 : struct tm lt;
3087 0 : tzset();
3088 0 : localtime_r(&t, <);
3089 : #if !defined(__CYGWIN__)
3090 0 : resp->timezone = (int32_t)lt.tm_gmtoff;
3091 : #endif
3092 0 : resp->isdst = (uint8_t)lt.tm_isdst;
3093 :
3094 : /* send message */
3095 0 : if (dlt_daemon_client_send_control_message_v2(sock, daemon, daemon_local, &msg, "", "", verbose)) {
3096 0 : dlt_message_free_v2(&msg, 0);
3097 0 : return -1;
3098 : }
3099 :
3100 : /* free message */
3101 0 : dlt_message_free_v2(&msg, 0);
3102 :
3103 0 : return 0;
3104 : }
3105 :
3106 0 : int dlt_daemon_control_message_marker(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
3107 : {
3108 : DltMessage msg;
3109 : DltServiceMarker *resp;
3110 :
3111 0 : PRINT_FUNCTION_VERBOSE(verbose);
3112 :
3113 0 : if (daemon == 0)
3114 : return -1;
3115 :
3116 : /* initialise new message */
3117 0 : if (dlt_message_init(&msg, 0) == DLT_RETURN_ERROR)
3118 : return -1;
3119 :
3120 : /* prepare payload of data */
3121 0 : msg.datasize = sizeof(DltServiceMarker);
3122 :
3123 0 : if (msg.databuffer && (msg.databuffersize < msg.datasize)) {
3124 0 : free(msg.databuffer);
3125 0 : msg.databuffer = 0;
3126 : }
3127 :
3128 0 : if (msg.databuffer == 0) {
3129 0 : msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize);
3130 0 : msg.databuffersize = (size_t)msg.datasize;
3131 : }
3132 :
3133 0 : if (msg.databuffer == 0)
3134 : return -1;
3135 :
3136 : resp = (DltServiceMarker *)msg.databuffer;
3137 0 : resp->service_id = DLT_SERVICE_ID_MARKER;
3138 0 : resp->status = DLT_SERVICE_RESPONSE_OK;
3139 :
3140 : /* send message */
3141 0 : if (dlt_daemon_client_send_control_message(sock, daemon, daemon_local, &msg, "", "", verbose)) {
3142 0 : dlt_message_free(&msg, 0);
3143 0 : return -1;
3144 : }
3145 :
3146 : /* free message */
3147 0 : dlt_message_free(&msg, 0);
3148 :
3149 0 : return 0;
3150 : }
3151 :
3152 0 : void dlt_daemon_control_callsw_cinjection(int sock,
3153 : DltDaemon *daemon,
3154 : DltDaemonLocal *daemon_local,
3155 : DltMessage *msg,
3156 : int verbose)
3157 : {
3158 : char apid[DLT_ID_SIZE], ctid[DLT_ID_SIZE];
3159 : uint32_t id = 0, id_tmp = 0;
3160 : uint8_t *ptr;
3161 : DltDaemonContext *context;
3162 : uint32_t data_length_inject = 0;
3163 : uint32_t data_length_inject_tmp = 0;
3164 :
3165 : int32_t datalength;
3166 :
3167 : DltUserHeader userheader;
3168 : DltUserControlMsgInjection usercontext;
3169 : uint8_t *userbuffer;
3170 :
3171 0 : PRINT_FUNCTION_VERBOSE(verbose);
3172 :
3173 0 : if ((daemon == NULL) || (daemon_local == NULL) || (msg == NULL) || (msg->databuffer == NULL))
3174 0 : return;
3175 :
3176 0 : datalength = (int32_t) msg->datasize;
3177 : ptr = msg->databuffer;
3178 :
3179 0 : DLT_MSG_READ_VALUE(id_tmp, ptr, datalength, uint32_t); /* Get service id */
3180 0 : id = DLT_ENDIAN_GET_32(msg->standardheader->htyp, id_tmp);
3181 :
3182 : /* injectionMode is disabled */
3183 0 : if (daemon_local->flags.injectionMode == 0) {
3184 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_PERM_DENIED, verbose);
3185 0 : return;
3186 : }
3187 :
3188 : /* id is always less than DLT_DAEMON_INJECTION_MAX since its type is uinit32_t */
3189 0 : if (id >= DLT_DAEMON_INJECTION_MIN) {
3190 : /* This a a real SW-C injection call */
3191 : data_length_inject = 0;
3192 : data_length_inject_tmp = 0;
3193 :
3194 0 : DLT_MSG_READ_VALUE(data_length_inject_tmp, ptr, datalength, uint32_t); /* Get data length */
3195 0 : data_length_inject = DLT_ENDIAN_GET_32(msg->standardheader->htyp, data_length_inject_tmp);
3196 :
3197 : /* Get context handle for apid, ctid (and seid) */
3198 : /* Warning: seid is ignored in this implementation! */
3199 0 : if (DLT_IS_HTYP_UEH(msg->standardheader->htyp)) {
3200 0 : dlt_set_id(apid, msg->extendedheader->apid);
3201 0 : dlt_set_id(ctid, msg->extendedheader->ctid);
3202 : }
3203 : else {
3204 : /* No extended header, and therefore no apid and ctid available */
3205 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
3206 0 : return;
3207 : }
3208 :
3209 : /* At this point, apid and ctid is available */
3210 0 : context = dlt_daemon_context_find(daemon,
3211 : apid,
3212 : ctid,
3213 0 : daemon->ecuid,
3214 : verbose);
3215 :
3216 0 : if (context == 0) {
3217 : /* dlt_log(LOG_INFO,"No context found!\n"); */
3218 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
3219 0 : return;
3220 : }
3221 :
3222 : /* Send user message to handle, specified in context */
3223 0 : if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_INJECTION) < DLT_RETURN_OK) {
3224 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
3225 0 : return;
3226 : }
3227 :
3228 0 : usercontext.log_level_pos = context->log_level_pos;
3229 :
3230 0 : if (data_length_inject > (uint32_t) msg->databuffersize) {
3231 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
3232 0 : return;
3233 : }
3234 :
3235 0 : userbuffer = malloc(data_length_inject);
3236 :
3237 0 : if (userbuffer == 0) {
3238 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
3239 0 : return;
3240 : }
3241 :
3242 0 : usercontext.data_length_inject = (uint32_t) data_length_inject;
3243 0 : usercontext.service_id = id;
3244 :
3245 : memcpy(userbuffer, ptr, (size_t) data_length_inject); /* Copy received injection to send buffer */
3246 :
3247 : /* write to FIFO */
3248 : DltReturnValue ret =
3249 0 : dlt_user_log_out3_with_timeout(context->user_handle, &(userheader), sizeof(DltUserHeader),
3250 : &(usercontext), sizeof(DltUserControlMsgInjection),
3251 : userbuffer, (size_t) data_length_inject);
3252 :
3253 0 : if (ret < DLT_RETURN_OK) {
3254 0 : if (ret == DLT_RETURN_PIPE_ERROR) {
3255 : /* Close connection */
3256 0 : close(context->user_handle);
3257 0 : context->user_handle = DLT_FD_INIT;
3258 : }
3259 :
3260 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
3261 : }
3262 : else {
3263 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose);
3264 : }
3265 :
3266 0 : free(userbuffer);
3267 : userbuffer = 0;
3268 :
3269 : }
3270 : else {
3271 : /* Invalid ID */
3272 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
3273 : verbose);
3274 : }
3275 : }
3276 :
3277 0 : void dlt_daemon_control_callsw_cinjection_v2(int sock,
3278 : DltDaemon *daemon,
3279 : DltDaemonLocal *daemon_local,
3280 : DltMessageV2 *msg,
3281 : int verbose)
3282 : {
3283 : uint8_t apidlen = 0, ctidlen = 0;
3284 : char *apid = NULL;
3285 : char *ctid = NULL;
3286 : uint32_t id = 0, id_tmp = 0;
3287 : uint8_t *ptr;
3288 : DltDaemonContext *context;
3289 : uint32_t data_length_inject = 0;
3290 : uint32_t data_length_inject_tmp = 0;
3291 :
3292 : int32_t datalength;
3293 :
3294 : DltUserHeader userheader;
3295 : DltUserControlMsgInjection usercontext;
3296 : uint8_t *userbuffer;
3297 :
3298 0 : PRINT_FUNCTION_VERBOSE(verbose);
3299 :
3300 0 : if ((daemon == NULL) || (daemon_local == NULL) || (msg == NULL) || (msg->databuffer == NULL))
3301 0 : return;
3302 :
3303 0 : datalength = (int32_t) msg->datasize;
3304 : ptr = msg->databuffer;
3305 :
3306 0 : DLT_MSG_READ_VALUE(id_tmp, ptr, datalength, uint32_t); /* Get service id */
3307 : // id = DLT_ENDIAN_GET_32(msg->standardheader->htyp, id_tmp);
3308 : //TBD: Review endianness for V2, id extraction
3309 0 : id = DLT_ENDIAN_GET_32(msg->baseheaderv2->htyp2, id_tmp);
3310 :
3311 : /* injectionMode is disabled */
3312 0 : if (daemon_local->flags.injectionMode == 0) {
3313 0 : dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_PERM_DENIED, verbose);
3314 0 : return;
3315 : }
3316 :
3317 : /* id is always less than DLT_DAEMON_INJECTION_MAX since its type is uinit32_t */
3318 0 : if (id >= DLT_DAEMON_INJECTION_MIN) {
3319 : /* This a a real SW-C injection call */
3320 : data_length_inject = 0;
3321 : data_length_inject_tmp = 0;
3322 :
3323 0 : DLT_MSG_READ_VALUE(data_length_inject_tmp, ptr, datalength, uint32_t); /* Get data length */
3324 0 : data_length_inject = DLT_ENDIAN_GET_32(msg->baseheaderv2->htyp2, data_length_inject_tmp);
3325 :
3326 : /* Get context handle for apid, ctid (and seid) */
3327 : /* Warning: seid is ignored in this implementation! */
3328 : //TBD: Review EH(htyp2) vs UEH(htyp)
3329 0 : if (DLT_IS_HTYP2_EH(msg->baseheaderv2->htyp2)) {
3330 : //TBD: Check if apidlen and ctidlen are fetched properly in runtime
3331 0 : apidlen = msg->extendedheaderv2.apidlen;
3332 0 : dlt_set_id_v2(apid, msg->extendedheaderv2.apid, msg->extendedheaderv2.apidlen);
3333 0 : ctidlen = msg->extendedheaderv2.ctidlen;
3334 0 : dlt_set_id_v2(ctid, msg->extendedheaderv2.ctid, msg->extendedheaderv2.ctidlen);
3335 : }
3336 : else {
3337 : /* No extended header, and therefore no apid and ctid available */
3338 0 : dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
3339 0 : return;
3340 : }
3341 :
3342 : /* At this point, apid and ctid is available */
3343 0 : context = dlt_daemon_context_find_v2(daemon,
3344 : apidlen,
3345 : apid,
3346 : ctidlen,
3347 : ctid,
3348 0 : daemon->ecuid2len,
3349 0 : daemon->ecuid2,
3350 : verbose);
3351 :
3352 0 : if (context == 0) {
3353 : /* dlt_log(LOG_INFO,"No context found!\n"); */
3354 0 : dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
3355 0 : return;
3356 : }
3357 :
3358 : /* Send user message to handle, specified in context */
3359 0 : if (dlt_user_set_userheader_v2(&userheader, DLT_USER_MESSAGE_INJECTION) < DLT_RETURN_OK) {
3360 0 : dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
3361 0 : return;
3362 : }
3363 :
3364 0 : usercontext.log_level_pos = context->log_level_pos;
3365 :
3366 0 : if (data_length_inject > (uint32_t) msg->databuffersize) {
3367 0 : dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
3368 0 : return;
3369 : }
3370 :
3371 0 : userbuffer = malloc(data_length_inject);
3372 :
3373 0 : if (userbuffer == 0) {
3374 0 : dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
3375 0 : return;
3376 : }
3377 :
3378 0 : usercontext.data_length_inject = (uint32_t) data_length_inject;
3379 0 : usercontext.service_id = id;
3380 :
3381 : memcpy(userbuffer, ptr, (size_t) data_length_inject); /* Copy received injection to send buffer */
3382 :
3383 : /* write to FIFO */
3384 : DltReturnValue ret =
3385 0 : dlt_user_log_out3_with_timeout(context->user_handle, &(userheader), sizeof(DltUserHeader),
3386 : &(usercontext), sizeof(DltUserControlMsgInjection),
3387 : userbuffer, (size_t) data_length_inject);
3388 :
3389 0 : if (ret < DLT_RETURN_OK) {
3390 0 : if (ret == DLT_RETURN_PIPE_ERROR) {
3391 : /* Close connection */
3392 0 : close(context->user_handle);
3393 0 : context->user_handle = DLT_FD_INIT;
3394 : }
3395 :
3396 0 : dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
3397 : }
3398 : else {
3399 0 : dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose);
3400 : }
3401 :
3402 0 : free(userbuffer);
3403 : userbuffer = 0;
3404 :
3405 : }
3406 : else {
3407 : /* Invalid ID */
3408 0 : dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
3409 : verbose);
3410 : }
3411 : }
3412 :
3413 0 : void dlt_daemon_send_log_level(int sock,
3414 : DltDaemon *daemon,
3415 : DltDaemonLocal *daemon_local,
3416 : DltDaemonContext *context,
3417 : int8_t loglevel,
3418 : int verbose)
3419 : {
3420 0 : PRINT_FUNCTION_VERBOSE(verbose);
3421 :
3422 : int32_t id = DLT_SERVICE_ID_SET_LOG_LEVEL;
3423 : int8_t old_log_level = 0;
3424 :
3425 0 : old_log_level = context->log_level;
3426 0 : context->log_level = loglevel; /* No endianess conversion necessary*/
3427 :
3428 0 : if ((context->user_handle >= DLT_FD_MINIMUM) &&
3429 0 : (dlt_daemon_user_send_log_level(daemon, context, verbose) == 0)) {
3430 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, (uint32_t) id, DLT_SERVICE_RESPONSE_OK, verbose);
3431 : }
3432 : else {
3433 0 : dlt_log(LOG_ERR, "Log level could not be sent!\n");
3434 0 : context->log_level = old_log_level;
3435 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, (uint32_t) id, DLT_SERVICE_RESPONSE_ERROR, verbose);
3436 : }
3437 0 : }
3438 :
3439 0 : void dlt_daemon_send_log_level_v2(int sock,
3440 : DltDaemon *daemon,
3441 : DltDaemonLocal *daemon_local,
3442 : DltDaemonContext *context,
3443 : int8_t loglevel,
3444 : int verbose)
3445 : {
3446 0 : PRINT_FUNCTION_VERBOSE(verbose);
3447 :
3448 : int32_t id = DLT_SERVICE_ID_SET_LOG_LEVEL;
3449 : int8_t old_log_level = 0;
3450 :
3451 0 : old_log_level = context->log_level;
3452 0 : context->log_level = loglevel; /* No endianess conversion necessary*/
3453 :
3454 0 : if ((context->user_handle >= DLT_FD_MINIMUM) &&
3455 0 : (dlt_daemon_user_send_log_level_v2(daemon, context, verbose) == 0)) {
3456 0 : dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, (uint32_t) id, DLT_SERVICE_RESPONSE_OK, verbose);
3457 : }
3458 : else {
3459 0 : dlt_log(LOG_ERR, "Log level could not be sent!\n");
3460 0 : context->log_level = old_log_level;
3461 0 : dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, (uint32_t) id, DLT_SERVICE_RESPONSE_ERROR, verbose);
3462 : }
3463 0 : }
3464 :
3465 0 : void dlt_daemon_find_multiple_context_and_send_log_level(int sock,
3466 : DltDaemon *daemon,
3467 : DltDaemonLocal *daemon_local,
3468 : int8_t app_flag,
3469 : char *str,
3470 : int8_t len,
3471 : int8_t loglevel,
3472 : int verbose)
3473 : {
3474 0 : PRINT_FUNCTION_VERBOSE(verbose);
3475 :
3476 : int count = 0;
3477 : DltDaemonContext *context = NULL;
3478 0 : char src_str[DLT_ID_SIZE + 1] = { 0 };
3479 : int ret = 0;
3480 : DltDaemonRegisteredUsers *user_list = NULL;
3481 :
3482 0 : if (daemon == 0) {
3483 0 : dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__);
3484 0 : return;
3485 : }
3486 :
3487 0 : user_list = dlt_daemon_find_users_list(daemon, daemon->ecuid, verbose);
3488 :
3489 0 : if (user_list == NULL)
3490 : return;
3491 :
3492 0 : for (count = 0; count < user_list->num_contexts; count++) {
3493 0 : context = &(user_list->contexts[count]);
3494 :
3495 0 : if (context) {
3496 0 : if (app_flag == 1)
3497 0 : strncpy(src_str, context->apid, DLT_ID_SIZE);
3498 : else
3499 0 : strncpy(src_str, context->ctid, DLT_ID_SIZE);
3500 :
3501 0 : ret = strncmp(src_str, str, (size_t)len);
3502 :
3503 0 : if (ret == 0)
3504 0 : dlt_daemon_send_log_level(sock, daemon, daemon_local, context, loglevel, verbose);
3505 0 : else if ((ret > 0) && (app_flag == 1))
3506 : break;
3507 : else
3508 0 : continue;
3509 : }
3510 : }
3511 : }
3512 :
3513 0 : void dlt_daemon_find_multiple_context_and_send_log_level_v2(int sock,
3514 : DltDaemon *daemon,
3515 : DltDaemonLocal *daemon_local,
3516 : int8_t app_flag,
3517 : char *str,
3518 : int8_t len,
3519 : int8_t loglevel,
3520 : int verbose)
3521 : {
3522 0 : PRINT_FUNCTION_VERBOSE(verbose);
3523 :
3524 : int count = 0;
3525 : DltDaemonContext *context = NULL;
3526 0 : char src_str[DLT_V2_ID_SIZE] = {0};
3527 : int ret = 0;
3528 : DltDaemonRegisteredUsers *user_list = NULL;
3529 :
3530 0 : if (daemon == 0) {
3531 0 : dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__);
3532 0 : return;
3533 : }
3534 :
3535 0 : user_list = dlt_daemon_find_users_list_v2(daemon, daemon->ecuid2len, daemon->ecuid2, verbose);
3536 :
3537 0 : if (user_list == NULL)
3538 : return;
3539 :
3540 0 : for (count = 0; count < user_list->num_contexts; count++) {
3541 0 : context = &(user_list->contexts[count]);
3542 :
3543 0 : if (context) {
3544 0 : if (app_flag == 1)
3545 0 : dlt_set_id_v2(src_str, context->apid2, context->apid2len);
3546 : else
3547 0 : dlt_set_id_v2(src_str, context->ctid2, context->ctid2len);
3548 :
3549 0 : ret = strncmp(src_str, str, (size_t)len);
3550 :
3551 0 : if (ret == 0)
3552 0 : dlt_daemon_send_log_level_v2(sock, daemon, daemon_local, context, loglevel, verbose);
3553 0 : else if ((ret > 0) && (app_flag == 1))
3554 : break;
3555 : else
3556 0 : continue;
3557 : }
3558 : }
3559 : }
3560 :
3561 :
3562 0 : void dlt_daemon_control_set_log_level(int sock,
3563 : DltDaemon *daemon,
3564 : DltDaemonLocal *daemon_local,
3565 : DltMessage *msg,
3566 : int verbose)
3567 : {
3568 0 : PRINT_FUNCTION_VERBOSE(verbose);
3569 :
3570 0 : char apid[DLT_ID_SIZE + 1] = { 0 };
3571 0 : char ctid[DLT_ID_SIZE + 1] = { 0 };
3572 : DltServiceSetLogLevel *req = NULL;
3573 : DltDaemonContext *context = NULL;
3574 : int8_t apid_length = 0;
3575 : int8_t ctid_length = 0;
3576 :
3577 0 : if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL))
3578 0 : return;
3579 :
3580 0 : if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetLogLevel)) < 0)
3581 : return;
3582 :
3583 0 : req = (DltServiceSetLogLevel *)(msg->databuffer);
3584 :
3585 0 : if (daemon_local->flags.enforceContextLLAndTS)
3586 0 : req->log_level = (uint8_t) getStatus(req->log_level, daemon_local->flags.contextLogLevel);
3587 :
3588 0 : dlt_set_id(apid, req->apid);
3589 0 : dlt_set_id(ctid, req->ctid);
3590 0 : apid_length = (int8_t) strlen(apid);
3591 0 : ctid_length = (int8_t) strlen(ctid);
3592 :
3593 0 : if ((apid_length != 0) && (apid[apid_length - 1] == '*') && (ctid[0] == 0)) { /*apid provided having '*' in it and ctid is null*/
3594 0 : dlt_daemon_find_multiple_context_and_send_log_level(sock,
3595 : daemon,
3596 : daemon_local,
3597 : 1,
3598 : apid,
3599 0 : (int8_t) (apid_length - 1),
3600 0 : (int8_t) req->log_level,
3601 : verbose);
3602 : }
3603 0 : else if ((ctid_length != 0) && (ctid[ctid_length - 1] == '*') && (apid[0] == 0)) /*ctid provided is having '*' in it and apid is null*/
3604 : {
3605 0 : dlt_daemon_find_multiple_context_and_send_log_level(sock,
3606 : daemon,
3607 : daemon_local,
3608 : 0,
3609 : ctid,
3610 0 : (int8_t) (ctid_length - 1),
3611 0 : (int8_t) req->log_level,
3612 : verbose);
3613 : }
3614 0 : else if ((apid_length != 0) && (apid[apid_length - 1] != '*') && (ctid[0] == 0)) /*only app id case*/
3615 : {
3616 0 : dlt_daemon_find_multiple_context_and_send_log_level(sock,
3617 : daemon,
3618 : daemon_local,
3619 : 1,
3620 : apid,
3621 : DLT_ID_SIZE,
3622 0 : (int8_t) req->log_level,
3623 : verbose);
3624 : }
3625 0 : else if ((ctid_length != 0) && (ctid[ctid_length - 1] != '*') && (apid[0] == 0)) /*only context id case*/
3626 : {
3627 0 : dlt_daemon_find_multiple_context_and_send_log_level(sock,
3628 : daemon,
3629 : daemon_local,
3630 : 0,
3631 : ctid,
3632 : DLT_ID_SIZE,
3633 0 : (int8_t) req->log_level,
3634 : verbose);
3635 : }
3636 : else {
3637 0 : context = dlt_daemon_context_find(daemon,
3638 : apid,
3639 : ctid,
3640 0 : daemon->ecuid,
3641 : verbose);
3642 :
3643 : /* Set log level */
3644 0 : if (context != 0) {
3645 0 : dlt_daemon_send_log_level(sock, daemon, daemon_local, context, (int8_t) req->log_level, verbose);
3646 : }
3647 : else {
3648 0 : dlt_vlog(LOG_ERR, "Could not set log level: %d. Context [%.4s:%.4s] not found:", req->log_level, apid,
3649 : ctid);
3650 0 : dlt_daemon_control_service_response(sock,
3651 : daemon,
3652 : daemon_local,
3653 : DLT_SERVICE_ID_SET_LOG_LEVEL,
3654 : DLT_SERVICE_RESPONSE_ERROR,
3655 : verbose);
3656 : }
3657 : }
3658 : }
3659 :
3660 0 : void dlt_daemon_control_set_log_level_v2(int sock,
3661 : DltDaemon *daemon,
3662 : DltDaemonLocal *daemon_local,
3663 : DltMessageV2 *msg,
3664 : int verbose)
3665 : {
3666 0 : PRINT_FUNCTION_VERBOSE(verbose);
3667 : char *apid =NULL;
3668 : char *ctid =NULL;
3669 0 : DltServiceSetLogLevelV2 req = {0};
3670 : DltDaemonContext *context = NULL;
3671 : int8_t apid_length = 0;
3672 : int8_t ctid_length = 0;
3673 : int offset = 0;
3674 :
3675 0 : if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL))
3676 0 : return;
3677 :
3678 0 : if (dlt_check_rcv_data_size(msg->datasize, DLT_SERVICE_SET_LOG_LEVEL_FIXED_SIZE_V2) < 0)
3679 : return;
3680 :
3681 0 : memcpy(&(req.service_id), msg->databuffer + offset, sizeof(uint32_t));
3682 : offset = offset + (int)sizeof(uint32_t);
3683 : memcpy(&(req.apidlen), msg->databuffer + offset, sizeof(uint8_t));
3684 : offset = offset + (int)sizeof(uint8_t);
3685 0 : dlt_set_id_v2(req.apid, (const char *)(msg->databuffer + offset), req.apidlen);
3686 0 : offset = offset + req.apidlen;
3687 0 : memcpy(&(req.ctidlen), msg->databuffer + offset, sizeof(uint8_t));
3688 0 : offset = offset + (int)sizeof(uint8_t);
3689 0 : dlt_set_id_v2(req.ctid, (const char *)(msg->databuffer + offset), req.ctidlen);
3690 0 : offset = offset + req.ctidlen;
3691 0 : memcpy(&(req.log_level), msg->databuffer + offset, sizeof(uint8_t));
3692 0 : offset = offset + (int)sizeof(uint8_t);
3693 0 : memcpy(&(req.com), msg->databuffer + offset, DLT_ID_SIZE);
3694 :
3695 0 : if (daemon_local->flags.enforceContextLLAndTS)
3696 0 : req.log_level = (uint8_t) getStatus(req.log_level, daemon_local->flags.contextLogLevel);
3697 :
3698 0 : apid_length = (int8_t) req.apidlen;
3699 0 : dlt_set_id_v2(apid, req.apid, req.apidlen);
3700 0 : ctid_length = (int8_t) req.ctidlen;
3701 0 : dlt_set_id_v2(ctid, req.ctid, req.ctidlen);
3702 :
3703 0 : if ((apid_length != 0) && (apid[apid_length - 1] == '*') && (ctid == NULL)) { /*apid provided having '*' in it and ctid is null*/
3704 0 : dlt_daemon_find_multiple_context_and_send_log_level_v2(sock,
3705 : daemon,
3706 : daemon_local,
3707 : 1,
3708 : apid,
3709 0 : (int8_t) (apid_length - 1),
3710 0 : (int8_t) req.log_level,
3711 : verbose);
3712 : }
3713 0 : else if ((ctid_length != 0) && (ctid[ctid_length - 1] == '*') && (apid == NULL)) /*ctid provided is having '*' in it and apid is null*/
3714 : {
3715 0 : dlt_daemon_find_multiple_context_and_send_log_level_v2(sock,
3716 : daemon,
3717 : daemon_local,
3718 : 0,
3719 : ctid,
3720 0 : (int8_t) (ctid_length - 1),
3721 0 : (int8_t) req.log_level,
3722 : verbose);
3723 : }
3724 0 : else if ((apid_length != 0) && (apid[apid_length - 1] != '*') && (ctid == NULL)) /*only app id case*/
3725 : {
3726 0 : dlt_daemon_find_multiple_context_and_send_log_level_v2(sock,
3727 : daemon,
3728 : daemon_local,
3729 : 1,
3730 : apid,
3731 : apid_length,
3732 0 : (int8_t) req.log_level,
3733 : verbose);
3734 : }
3735 0 : else if ((ctid_length != 0) && (ctid[ctid_length - 1] != '*') && (apid == NULL)) /*only context id case*/
3736 : {
3737 0 : dlt_daemon_find_multiple_context_and_send_log_level_v2(sock,
3738 : daemon,
3739 : daemon_local,
3740 : 0,
3741 : ctid,
3742 : ctid_length,
3743 0 : (int8_t) req.log_level,
3744 : verbose);
3745 : }
3746 : else {
3747 0 : context = dlt_daemon_context_find_v2(daemon,
3748 : (uint8_t)apid_length,
3749 : apid,
3750 : (uint8_t)ctid_length,
3751 : ctid,
3752 0 : daemon->ecuid2len,
3753 0 : daemon->ecuid2,
3754 : verbose);
3755 :
3756 : /* Set log level */
3757 0 : if (context != 0) {
3758 0 : dlt_daemon_send_log_level_v2(sock, daemon, daemon_local, context, (int8_t) req.log_level, verbose);
3759 : }
3760 : else {
3761 0 : dlt_vlog(LOG_ERR, "Could not set log level: %d. Context [%s:%s] not found:", req.log_level,
3762 : apid ? apid : "<NULL>",
3763 : ctid ? ctid : "<NULL>");
3764 0 : dlt_daemon_control_service_response_v2(sock,
3765 : daemon,
3766 : daemon_local,
3767 : DLT_SERVICE_ID_SET_LOG_LEVEL,
3768 : DLT_SERVICE_RESPONSE_ERROR,
3769 : verbose);
3770 : }
3771 : }
3772 : }
3773 :
3774 0 : void dlt_daemon_send_trace_status(int sock,
3775 : DltDaemon *daemon,
3776 : DltDaemonLocal *daemon_local,
3777 : DltDaemonContext *context,
3778 : int8_t tracestatus,
3779 : int verbose)
3780 : {
3781 0 : PRINT_FUNCTION_VERBOSE(verbose);
3782 :
3783 : int32_t id = DLT_SERVICE_ID_SET_TRACE_STATUS;
3784 : int8_t old_trace_status = 0;
3785 :
3786 0 : old_trace_status = context->trace_status;
3787 0 : context->trace_status = tracestatus; /* No endianess conversion necessary*/
3788 :
3789 0 : if ((context->user_handle >= DLT_FD_MINIMUM) &&
3790 0 : (dlt_daemon_user_send_log_level(daemon, context, verbose) == 0)) {
3791 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, (uint32_t) id, DLT_SERVICE_RESPONSE_OK, verbose);
3792 : }
3793 : else {
3794 0 : dlt_log(LOG_ERR, "Trace status could not be sent!\n");
3795 0 : context->trace_status = old_trace_status;
3796 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, (uint32_t) id, DLT_SERVICE_RESPONSE_ERROR, verbose);
3797 : }
3798 0 : }
3799 :
3800 0 : void dlt_daemon_send_trace_status_v2(int sock,
3801 : DltDaemon *daemon,
3802 : DltDaemonLocal *daemon_local,
3803 : DltDaemonContext *context,
3804 : int8_t tracestatus,
3805 : int verbose)
3806 : {
3807 0 : PRINT_FUNCTION_VERBOSE(verbose);
3808 :
3809 : int32_t id = DLT_SERVICE_ID_SET_TRACE_STATUS;
3810 : int8_t old_trace_status = 0;
3811 :
3812 0 : old_trace_status = context->trace_status;
3813 0 : context->trace_status = tracestatus; /* No endianess conversion necessary*/
3814 :
3815 0 : if ((context->user_handle >= DLT_FD_MINIMUM) &&
3816 0 : (dlt_daemon_user_send_log_level_v2(daemon, context, verbose) == 0)) {
3817 0 : dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, (uint32_t) id, DLT_SERVICE_RESPONSE_OK, verbose);
3818 : }
3819 : else {
3820 0 : dlt_log(LOG_ERR, "Trace status could not be sent!\n");
3821 0 : context->trace_status = old_trace_status;
3822 0 : dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, (uint32_t) id, DLT_SERVICE_RESPONSE_ERROR, verbose);
3823 : }
3824 0 : }
3825 :
3826 0 : void dlt_daemon_find_multiple_context_and_send_trace_status(int sock,
3827 : DltDaemon *daemon,
3828 : DltDaemonLocal *daemon_local,
3829 : int8_t app_flag,
3830 : char *str,
3831 : int8_t len,
3832 : int8_t tracestatus,
3833 : int verbose)
3834 : {
3835 0 : PRINT_FUNCTION_VERBOSE(verbose);
3836 :
3837 : int count = 0;
3838 : DltDaemonContext *context = NULL;
3839 0 : char src_str[DLT_ID_SIZE + 1] = { 0 };
3840 : int ret = 0;
3841 : DltDaemonRegisteredUsers *user_list = NULL;
3842 :
3843 0 : if (daemon == 0) {
3844 0 : dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__);
3845 0 : return;
3846 : }
3847 :
3848 0 : user_list = dlt_daemon_find_users_list(daemon, daemon->ecuid, verbose);
3849 :
3850 0 : if (user_list == NULL)
3851 : return;
3852 :
3853 0 : for (count = 0; count < user_list->num_contexts; count++) {
3854 0 : context = &(user_list->contexts[count]);
3855 :
3856 0 : if (context) {
3857 0 : if (app_flag == 1)
3858 0 : strncpy(src_str, context->apid, DLT_ID_SIZE);
3859 : else
3860 0 : strncpy(src_str, context->ctid, DLT_ID_SIZE);
3861 :
3862 0 : ret = strncmp(src_str, str, (size_t)len);
3863 :
3864 0 : if (ret == 0)
3865 0 : dlt_daemon_send_trace_status(sock, daemon, daemon_local, context, tracestatus, verbose);
3866 0 : else if ((ret > 0) && (app_flag == 1))
3867 : break;
3868 : else
3869 0 : continue;
3870 : }
3871 : }
3872 : }
3873 :
3874 0 : void dlt_daemon_find_multiple_context_and_send_trace_status_v2(int sock,
3875 : DltDaemon *daemon,
3876 : DltDaemonLocal *daemon_local,
3877 : int8_t app_flag,
3878 : char *str,
3879 : int8_t len,
3880 : int8_t tracestatus,
3881 : int verbose)
3882 : {
3883 0 : PRINT_FUNCTION_VERBOSE(verbose);
3884 :
3885 : int count = 0;
3886 : DltDaemonContext *context = NULL;
3887 0 : char src_str[DLT_V2_ID_SIZE] = { 0 };
3888 : int ret = 0;
3889 : DltDaemonRegisteredUsers *user_list = NULL;
3890 :
3891 0 : if (daemon == 0) {
3892 0 : dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__);
3893 0 : return;
3894 : }
3895 :
3896 0 : user_list = dlt_daemon_find_users_list_v2(daemon, daemon->ecuid2len, daemon->ecuid2, verbose);
3897 :
3898 0 : if (user_list == NULL)
3899 : return;
3900 :
3901 0 : for (count = 0; count < user_list->num_contexts; count++) {
3902 0 : context = &(user_list->contexts[count]);
3903 :
3904 0 : if (context) {
3905 0 : if (app_flag == 1)
3906 0 : dlt_set_id_v2(src_str, context->apid2, context->apid2len);
3907 : else
3908 0 : dlt_set_id_v2(src_str, context->ctid2, context->ctid2len);
3909 :
3910 0 : ret = strncmp(src_str, str, (size_t)len);
3911 :
3912 0 : if (ret == 0)
3913 0 : dlt_daemon_send_trace_status_v2(sock, daemon, daemon_local, context, tracestatus, verbose);
3914 0 : else if ((ret > 0) && (app_flag == 1))
3915 : break;
3916 : else
3917 0 : continue;
3918 : }
3919 : }
3920 : }
3921 :
3922 0 : void dlt_daemon_control_set_trace_status(int sock,
3923 : DltDaemon *daemon,
3924 : DltDaemonLocal *daemon_local,
3925 : DltMessage *msg,
3926 : int verbose)
3927 : {
3928 0 : PRINT_FUNCTION_VERBOSE(verbose);
3929 :
3930 0 : char apid[DLT_ID_SIZE + 1] = { 0 };
3931 0 : char ctid[DLT_ID_SIZE + 1] = { 0 };
3932 : DltServiceSetLogLevel *req = NULL;
3933 : DltDaemonContext *context = NULL;
3934 : int8_t apid_length = 0;
3935 : int8_t ctid_length = 0;
3936 :
3937 0 : if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL))
3938 0 : return;
3939 :
3940 0 : if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetLogLevel)) < 0)
3941 : return;
3942 :
3943 0 : req = (DltServiceSetLogLevel *)(msg->databuffer);
3944 :
3945 0 : if (daemon_local->flags.enforceContextLLAndTS)
3946 0 : req->log_level = (uint8_t) getStatus(req->log_level, daemon_local->flags.contextTraceStatus);
3947 :
3948 0 : dlt_set_id(apid, req->apid);
3949 0 : dlt_set_id(ctid, req->ctid);
3950 0 : apid_length = (int8_t) strlen(apid);
3951 0 : ctid_length = (int8_t) strlen(ctid);
3952 :
3953 0 : if ((apid_length != 0) && (apid[apid_length - 1] == '*') && (ctid[0] == 0)) { /*apid provided having '*' in it and ctid is null*/
3954 0 : dlt_daemon_find_multiple_context_and_send_trace_status(sock,
3955 : daemon,
3956 : daemon_local,
3957 : 1,
3958 : apid,
3959 0 : (int8_t) (apid_length - 1),
3960 0 : (int8_t) req->log_level,
3961 : verbose);
3962 : }
3963 0 : else if ((ctid_length != 0) && (ctid[ctid_length - 1] == '*') && (apid[0] == 0)) /*ctid provided is having '*' in it and apid is null*/
3964 :
3965 : {
3966 0 : dlt_daemon_find_multiple_context_and_send_trace_status(sock,
3967 : daemon,
3968 : daemon_local,
3969 : 0,
3970 : ctid,
3971 0 : (int8_t) (ctid_length - 1),
3972 0 : (int8_t) req->log_level,
3973 : verbose);
3974 : }
3975 0 : else if ((apid_length != 0) && (apid[apid_length - 1] != '*') && (ctid[0] == 0)) /*only app id case*/
3976 : {
3977 0 : dlt_daemon_find_multiple_context_and_send_trace_status(sock,
3978 : daemon,
3979 : daemon_local,
3980 : 1,
3981 : apid,
3982 : DLT_ID_SIZE,
3983 0 : (int8_t) req->log_level,
3984 : verbose);
3985 : }
3986 0 : else if ((ctid_length != 0) && (ctid[ctid_length - 1] != '*') && (apid[0] == 0)) /*only context id case*/
3987 : {
3988 0 : dlt_daemon_find_multiple_context_and_send_trace_status(sock,
3989 : daemon,
3990 : daemon_local,
3991 : 0,
3992 : ctid,
3993 : DLT_ID_SIZE,
3994 0 : (int8_t) req->log_level,
3995 : verbose);
3996 : }
3997 : else {
3998 0 : context = dlt_daemon_context_find(daemon, apid, ctid, daemon->ecuid, verbose);
3999 :
4000 : /* Set trace status */
4001 0 : if (context != 0) {
4002 0 : dlt_daemon_send_trace_status(sock, daemon, daemon_local, context, (int8_t) req->log_level, verbose);
4003 : }
4004 : else {
4005 0 : dlt_vlog(LOG_ERR,
4006 : "Could not set trace status: %d. Context [%.4s:%.4s] not found:",
4007 0 : req->log_level,
4008 : apid,
4009 : ctid);
4010 0 : dlt_daemon_control_service_response(sock,
4011 : daemon,
4012 : daemon_local,
4013 : DLT_SERVICE_ID_SET_LOG_LEVEL,
4014 : DLT_SERVICE_RESPONSE_ERROR,
4015 : verbose);
4016 : }
4017 : }
4018 : }
4019 :
4020 0 : void dlt_daemon_control_set_trace_status_v2(int sock,
4021 : DltDaemon *daemon,
4022 : DltDaemonLocal *daemon_local,
4023 : DltMessageV2 *msg,
4024 : int verbose)
4025 : {
4026 0 : PRINT_FUNCTION_VERBOSE(verbose);
4027 :
4028 : char *apid = NULL;
4029 : char *ctid = NULL;
4030 : DltServiceSetLogLevelV2 *req = NULL;
4031 : DltDaemonContext *context = NULL;
4032 : int8_t apid_length = 0;
4033 : int8_t ctid_length = 0;
4034 :
4035 0 : if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL))
4036 : return;
4037 :
4038 : //TBD: Review sizeof(DltServiceSetLogLevelV2)) or fixed size
4039 0 : if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetLogLevelV2)) < 0)
4040 : return;
4041 :
4042 0 : req = (DltServiceSetLogLevelV2 *)(msg->databuffer);
4043 :
4044 0 : if (daemon_local->flags.enforceContextLLAndTS)
4045 0 : req->log_level = (uint8_t) getStatus(req->log_level, daemon_local->flags.contextTraceStatus);
4046 :
4047 0 : apid_length = (int8_t) req->apidlen;
4048 0 : dlt_set_id_v2(apid, req->apid, req->apidlen);
4049 0 : ctid_length = (int8_t) req->ctidlen;
4050 0 : dlt_set_id_v2(ctid, req->ctid, req->ctidlen);
4051 :
4052 : //TBD: Review apid[apid_length - 1] == '*'
4053 0 : if ((apid_length != 0) && (apid[apid_length - 1] == '*') && (ctid == NULL)) { /*apid provided having '*' in it and ctid is null*/
4054 0 : dlt_daemon_find_multiple_context_and_send_trace_status_v2(sock,
4055 : daemon,
4056 : daemon_local,
4057 : 1,
4058 : apid,
4059 0 : (int8_t) (apid_length - 1),
4060 0 : (int8_t) req->log_level,
4061 : verbose);
4062 : }
4063 0 : else if ((ctid_length != 0) && (ctid[ctid_length - 1] == '*') && (apid == NULL)) /*ctid provided is having '*' in it and apid is null*/
4064 :
4065 : {
4066 0 : dlt_daemon_find_multiple_context_and_send_trace_status_v2(sock,
4067 : daemon,
4068 : daemon_local,
4069 : 0,
4070 : ctid,
4071 0 : (int8_t) (ctid_length - 1),
4072 0 : (int8_t) req->log_level,
4073 : verbose);
4074 : }
4075 0 : else if ((apid_length != 0) && (apid[apid_length - 1] != '*') && (ctid == NULL)) /*only app id case*/
4076 : {
4077 0 : dlt_daemon_find_multiple_context_and_send_trace_status_v2(sock,
4078 : daemon,
4079 : daemon_local,
4080 : 1,
4081 : apid,
4082 : apid_length,
4083 0 : (int8_t) req->log_level,
4084 : verbose);
4085 : }
4086 0 : else if ((ctid_length != 0) && (ctid[ctid_length - 1] != '*') && (apid == NULL)) /*only context id case*/
4087 : {
4088 0 : dlt_daemon_find_multiple_context_and_send_trace_status_v2(sock,
4089 : daemon,
4090 : daemon_local,
4091 : 0,
4092 : ctid,
4093 : ctid_length,
4094 0 : (int8_t) req->log_level,
4095 : verbose);
4096 : }
4097 : else {
4098 0 : context = dlt_daemon_context_find_v2(daemon, (uint8_t)apid_length, apid, (uint8_t)ctid_length, ctid, daemon->ecuid2len, daemon->ecuid2, verbose);
4099 :
4100 : /* Set trace status */
4101 0 : if (context != 0) {
4102 0 : dlt_daemon_send_trace_status_v2(sock, daemon, daemon_local, context, (int8_t) req->log_level, verbose);
4103 : }
4104 : else {
4105 0 : dlt_vlog(LOG_ERR,
4106 : "Could not set trace status: %d. Context [%.4s:%.4s] not found:",
4107 0 : req->log_level,
4108 : apid ? apid : "<NULL>",
4109 : ctid ? ctid : "<NULL>");
4110 0 : dlt_daemon_control_service_response_v2(sock,
4111 : daemon,
4112 : daemon_local,
4113 : DLT_SERVICE_ID_SET_LOG_LEVEL,
4114 : DLT_SERVICE_RESPONSE_ERROR,
4115 : verbose);
4116 : }
4117 : }
4118 : }
4119 :
4120 0 : void dlt_daemon_control_set_default_log_level(int sock,
4121 : DltDaemon *daemon,
4122 : DltDaemonLocal *daemon_local,
4123 : DltMessage *msg,
4124 : int verbose)
4125 : {
4126 0 : PRINT_FUNCTION_VERBOSE(verbose);
4127 :
4128 : DltServiceSetDefaultLogLevel *req;
4129 : uint32_t id = DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL;
4130 :
4131 0 : if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL))
4132 : return;
4133 :
4134 0 : if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetDefaultLogLevel)) < 0)
4135 : return;
4136 :
4137 0 : req = (DltServiceSetDefaultLogLevel *)(msg->databuffer);
4138 :
4139 : /* No endianess conversion necessary */
4140 0 : if (/*(req->log_level>=0) &&*/
4141 0 : (req->log_level <= DLT_LOG_VERBOSE)) {
4142 0 : if (daemon_local->flags.enforceContextLLAndTS)
4143 0 : daemon->default_log_level = getStatus(req->log_level, daemon_local->flags.contextLogLevel);
4144 : else
4145 0 : daemon->default_log_level = (int8_t) req->log_level; /* No endianess conversion necessary */
4146 :
4147 : /* Send Update to all contexts using the default log level */
4148 0 : dlt_daemon_user_send_default_update(daemon, verbose);
4149 :
4150 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose);
4151 : }
4152 : else {
4153 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
4154 : }
4155 : }
4156 :
4157 0 : void dlt_daemon_control_set_default_log_level_v2(int sock,
4158 : DltDaemon *daemon,
4159 : DltDaemonLocal *daemon_local,
4160 : DltMessageV2 *msg,
4161 : int verbose)
4162 : {
4163 0 : PRINT_FUNCTION_VERBOSE(verbose);
4164 :
4165 : DltServiceSetDefaultLogLevel *req;
4166 : uint32_t id = DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL;
4167 :
4168 0 : if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL))
4169 : return;
4170 :
4171 0 : if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetDefaultLogLevel)) < 0)
4172 : return;
4173 :
4174 0 : req = (DltServiceSetDefaultLogLevel *)(msg->databuffer);
4175 :
4176 : /* No endianess conversion necessary */
4177 0 : if (/*(req->log_level>=0) &&*/
4178 0 : (req->log_level <= DLT_LOG_VERBOSE)) {
4179 0 : if (daemon_local->flags.enforceContextLLAndTS)
4180 0 : daemon->default_log_level = getStatus(req->log_level, daemon_local->flags.contextLogLevel);
4181 : else
4182 0 : daemon->default_log_level = (int8_t) req->log_level; /* No endianess conversion necessary */
4183 :
4184 : /* Send Update to all contexts using the default log level */
4185 0 : dlt_daemon_user_send_default_update(daemon, verbose);
4186 :
4187 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose);
4188 : }
4189 : else {
4190 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
4191 : }
4192 : }
4193 :
4194 0 : void dlt_daemon_control_set_all_log_level(int sock,
4195 : DltDaemon *daemon,
4196 : DltDaemonLocal *daemon_local,
4197 : DltMessage *msg,
4198 : int verbose)
4199 : {
4200 0 : PRINT_FUNCTION_VERBOSE(verbose);
4201 :
4202 : DltServiceSetDefaultLogLevel *req = NULL;
4203 : uint32_t id = DLT_SERVICE_ID_SET_ALL_LOG_LEVEL;
4204 : int8_t loglevel = 0;
4205 :
4206 0 : if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL)) {
4207 0 : dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__);
4208 0 : return;
4209 : }
4210 :
4211 0 : if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetDefaultLogLevel)) < 0)
4212 : return;
4213 :
4214 0 : req = (DltServiceSetDefaultLogLevel *)(msg->databuffer);
4215 :
4216 : /* No endianess conversion necessary */
4217 0 : if ((req != NULL) && ((req->log_level <= DLT_LOG_VERBOSE) || (req->log_level == (uint8_t)DLT_LOG_DEFAULT))) {
4218 0 : loglevel = (int8_t) req->log_level;
4219 :
4220 : /* Send Update to all contexts using the new log level */
4221 0 : dlt_daemon_user_send_all_log_level_update(
4222 : daemon,
4223 : daemon_local->flags.enforceContextLLAndTS,
4224 0 : (int8_t)daemon_local->flags.contextLogLevel,
4225 : loglevel,
4226 : verbose);
4227 :
4228 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose);
4229 : }
4230 : else {
4231 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
4232 : }
4233 : }
4234 :
4235 0 : void dlt_daemon_control_set_all_log_level_v2(int sock,
4236 : DltDaemon *daemon,
4237 : DltDaemonLocal *daemon_local,
4238 : DltMessageV2 *msg,
4239 : int verbose)
4240 : {
4241 0 : PRINT_FUNCTION_VERBOSE(verbose);
4242 :
4243 : DltServiceSetDefaultLogLevel *req = NULL;
4244 : uint32_t id = DLT_SERVICE_ID_SET_ALL_LOG_LEVEL;
4245 : int8_t loglevel = 0;
4246 :
4247 0 : if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL)) {
4248 0 : dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__);
4249 0 : return;
4250 : }
4251 :
4252 0 : if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetDefaultLogLevel)) < 0)
4253 : return;
4254 :
4255 0 : req = (DltServiceSetDefaultLogLevel *)(msg->databuffer);
4256 :
4257 : /* No endianess conversion necessary */
4258 0 : if ((req != NULL) && ((req->log_level <= DLT_LOG_VERBOSE) || (req->log_level == (uint8_t)DLT_LOG_DEFAULT))) {
4259 0 : loglevel = (int8_t) req->log_level;
4260 :
4261 : /* Send Update to all contexts using the new log level */
4262 0 : dlt_daemon_user_send_all_log_level_update_v2(
4263 : daemon,
4264 : daemon_local->flags.enforceContextLLAndTS,
4265 0 : (int8_t)daemon_local->flags.contextLogLevel,
4266 : loglevel,
4267 : verbose);
4268 :
4269 0 : dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose);
4270 : }
4271 : else {
4272 0 : dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
4273 : }
4274 : }
4275 :
4276 0 : void dlt_daemon_control_set_default_trace_status(int sock,
4277 : DltDaemon *daemon,
4278 : DltDaemonLocal *daemon_local,
4279 : DltMessage *msg,
4280 : int verbose)
4281 : {
4282 0 : PRINT_FUNCTION_VERBOSE(verbose);
4283 :
4284 : /* Payload of request message */
4285 : DltServiceSetDefaultLogLevel *req;
4286 : uint32_t id = DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS;
4287 :
4288 0 : if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL))
4289 : return;
4290 :
4291 0 : if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetDefaultLogLevel)) < 0)
4292 : return;
4293 :
4294 0 : req = (DltServiceSetDefaultLogLevel *)(msg->databuffer);
4295 :
4296 : /* No endianess conversion necessary */
4297 0 : if ((req->log_level == DLT_TRACE_STATUS_OFF) ||
4298 : (req->log_level == DLT_TRACE_STATUS_ON)) {
4299 0 : if (daemon_local->flags.enforceContextLLAndTS)
4300 0 : daemon->default_trace_status = getStatus(req->log_level, daemon_local->flags.contextTraceStatus);
4301 : else
4302 0 : daemon->default_trace_status = (int8_t) req->log_level; /* No endianess conversion necessary*/
4303 :
4304 : /* Send Update to all contexts using the default trace status */
4305 0 : dlt_daemon_user_send_default_update(daemon, verbose);
4306 :
4307 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose);
4308 : }
4309 : else {
4310 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
4311 : }
4312 : }
4313 :
4314 0 : void dlt_daemon_control_set_default_trace_status_v2(int sock,
4315 : DltDaemon *daemon,
4316 : DltDaemonLocal *daemon_local,
4317 : DltMessageV2 *msg,
4318 : int verbose)
4319 : {
4320 0 : PRINT_FUNCTION_VERBOSE(verbose);
4321 :
4322 : /* Payload of request message */
4323 : DltServiceSetDefaultLogLevel *req;
4324 : uint32_t id = DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS;
4325 :
4326 0 : if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL))
4327 : return;
4328 :
4329 0 : if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetDefaultLogLevel)) < 0)
4330 : return;
4331 :
4332 0 : req = (DltServiceSetDefaultLogLevel *)(msg->databuffer);
4333 :
4334 : /* No endianess conversion necessary */
4335 0 : if ((req->log_level == DLT_TRACE_STATUS_OFF) ||
4336 : (req->log_level == DLT_TRACE_STATUS_ON)) {
4337 0 : if (daemon_local->flags.enforceContextLLAndTS)
4338 0 : daemon->default_trace_status = getStatus(req->log_level, daemon_local->flags.contextTraceStatus);
4339 : else
4340 0 : daemon->default_trace_status = (int8_t) req->log_level; /* No endianess conversion necessary*/
4341 :
4342 : /* Send Update to all contexts using the default trace status */
4343 0 : dlt_daemon_user_send_default_update_v2(daemon, verbose);
4344 :
4345 0 : dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose);
4346 : }
4347 : else {
4348 0 : dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
4349 : }
4350 : }
4351 :
4352 0 : void dlt_daemon_control_set_all_trace_status(int sock,
4353 : DltDaemon *daemon,
4354 : DltDaemonLocal *daemon_local,
4355 : DltMessage *msg,
4356 : int verbose)
4357 : {
4358 0 : PRINT_FUNCTION_VERBOSE(verbose);
4359 :
4360 : DltServiceSetDefaultLogLevel *req = NULL;
4361 : uint32_t id = DLT_SERVICE_ID_SET_ALL_TRACE_STATUS;
4362 : int8_t tracestatus = 0;
4363 :
4364 0 : if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL)) {
4365 0 : dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__);
4366 0 : return;
4367 : }
4368 :
4369 0 : if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetDefaultLogLevel)) < 0)
4370 : return;
4371 :
4372 0 : req = (DltServiceSetDefaultLogLevel *)(msg->databuffer);
4373 :
4374 : /* No endianess conversion necessary */
4375 0 : if ((req != NULL) &&
4376 0 : ((req->log_level <= DLT_TRACE_STATUS_ON) || (req->log_level == (uint8_t)DLT_TRACE_STATUS_DEFAULT))) {
4377 0 : if (daemon_local->flags.enforceContextLLAndTS)
4378 0 : tracestatus = getStatus(req->log_level, daemon_local->flags.contextTraceStatus);
4379 : else
4380 0 : tracestatus = (int8_t) req->log_level; /* No endianess conversion necessary */
4381 :
4382 : /* Send Update to all contexts using the new log level */
4383 0 : dlt_daemon_user_send_all_trace_status_update(daemon, tracestatus, verbose);
4384 :
4385 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose);
4386 : }
4387 : else {
4388 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
4389 : }
4390 : }
4391 :
4392 0 : void dlt_daemon_control_set_all_trace_status_v2(int sock,
4393 : DltDaemon *daemon,
4394 : DltDaemonLocal *daemon_local,
4395 : DltMessageV2 *msg,
4396 : int verbose)
4397 : {
4398 0 : PRINT_FUNCTION_VERBOSE(verbose);
4399 :
4400 : DltServiceSetDefaultLogLevel *req = NULL;
4401 : uint32_t id = DLT_SERVICE_ID_SET_ALL_TRACE_STATUS;
4402 : int8_t tracestatus = 0;
4403 :
4404 0 : if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL)) {
4405 0 : dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__);
4406 0 : return;
4407 : }
4408 :
4409 0 : if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetDefaultLogLevel)) < 0)
4410 : return;
4411 :
4412 0 : req = (DltServiceSetDefaultLogLevel *)(msg->databuffer);
4413 :
4414 : /* No endianess conversion necessary */
4415 0 : if ((req != NULL) &&
4416 0 : ((req->log_level <= DLT_TRACE_STATUS_ON) || (req->log_level == (uint8_t)DLT_TRACE_STATUS_DEFAULT))) {
4417 0 : if (daemon_local->flags.enforceContextLLAndTS)
4418 0 : tracestatus = getStatus(req->log_level, daemon_local->flags.contextTraceStatus);
4419 : else
4420 0 : tracestatus = (int8_t) req->log_level; /* No endianess conversion necessary */
4421 :
4422 : /* Send Update to all contexts using the new log level */
4423 0 : dlt_daemon_user_send_all_trace_status_update_v2(daemon, tracestatus, verbose);
4424 :
4425 0 : dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose);
4426 : }
4427 : else {
4428 0 : dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
4429 : }
4430 : }
4431 :
4432 0 : void dlt_daemon_control_set_timing_packets(int sock,
4433 : DltDaemon *daemon,
4434 : DltDaemonLocal *daemon_local,
4435 : DltMessage *msg,
4436 : int verbose)
4437 : {
4438 0 : PRINT_FUNCTION_VERBOSE(verbose);
4439 :
4440 : DltServiceSetVerboseMode *req; /* request uses same struct as set verbose mode */
4441 : uint32_t id = DLT_SERVICE_ID_SET_TIMING_PACKETS;
4442 :
4443 0 : if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL))
4444 : return;
4445 :
4446 0 : if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetVerboseMode)) < 0)
4447 : return;
4448 :
4449 0 : req = (DltServiceSetVerboseMode *)(msg->databuffer);
4450 :
4451 0 : if ((req->new_status == 0) || (req->new_status == 1)) {
4452 0 : daemon->timingpackets = req->new_status;
4453 :
4454 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose);
4455 : }
4456 : else {
4457 0 : dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
4458 : }
4459 : }
4460 :
4461 0 : void dlt_daemon_control_set_timing_packets_v2(int sock,
4462 : DltDaemon *daemon,
4463 : DltDaemonLocal *daemon_local,
4464 : DltMessageV2 *msg,
4465 : int verbose)
4466 : {
4467 0 : PRINT_FUNCTION_VERBOSE(verbose);
4468 :
4469 : DltServiceSetVerboseMode *req; /* request uses same struct as set verbose mode */
4470 : uint32_t id = DLT_SERVICE_ID_SET_TIMING_PACKETS;
4471 :
4472 0 : if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL))
4473 : return;
4474 :
4475 0 : if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceSetVerboseMode)) < 0)
4476 : return;
4477 :
4478 0 : req = (DltServiceSetVerboseMode *)(msg->databuffer);
4479 :
4480 0 : if ((req->new_status == 0) || (req->new_status == 1)) {
4481 0 : daemon->timingpackets = req->new_status;
4482 :
4483 0 : dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose);
4484 : }
4485 : else {
4486 0 : dlt_daemon_control_service_response_v2(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR, verbose);
4487 : }
4488 : }
4489 :
4490 0 : void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
4491 : {
4492 : DltMessage msg;
4493 : int32_t len;
4494 :
4495 0 : PRINT_FUNCTION_VERBOSE(verbose);
4496 :
4497 0 : if (daemon == 0)
4498 0 : return;
4499 :
4500 : /* initialise new message */
4501 0 : if (dlt_message_init(&msg, 0) == DLT_RETURN_ERROR)
4502 : return;
4503 :
4504 : /* send message */
4505 :
4506 : /* prepare storage header */
4507 0 : msg.storageheader = (DltStorageHeader *)msg.headerbuffer;
4508 0 : dlt_set_storageheader(msg.storageheader, daemon->ecuid);
4509 :
4510 : /* prepare standard header */
4511 0 : msg.standardheader = (DltStandardHeader *)(msg.headerbuffer + sizeof(DltStorageHeader));
4512 0 : msg.standardheader->htyp = DLT_HTYP_WEID | DLT_HTYP_WTMS | DLT_HTYP_UEH | DLT_HTYP_PROTOCOL_VERSION1;
4513 :
4514 : #if (BYTE_ORDER == BIG_ENDIAN)
4515 : msg.standardheader->htyp = (msg.standardheader->htyp | DLT_HTYP_MSBF);
4516 : #endif
4517 :
4518 0 : msg.standardheader->mcnt = 0;
4519 :
4520 : /* Set header extra parameters */
4521 0 : dlt_set_id(msg.headerextra.ecu, daemon->ecuid);
4522 0 : msg.headerextra.tmsp = dlt_uptime();
4523 :
4524 0 : dlt_message_set_extraparameters(&msg, verbose);
4525 :
4526 : /* prepare extended header */
4527 0 : msg.extendedheader =
4528 0 : (DltExtendedHeader *)(msg.headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) +
4529 0 : DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp));
4530 0 : msg.extendedheader->msin = DLT_MSIN_CONTROL_TIME;
4531 :
4532 0 : msg.extendedheader->noar = 0; /* number of arguments */
4533 0 : dlt_set_id(msg.extendedheader->apid, ""); /* application id */
4534 0 : dlt_set_id(msg.extendedheader->ctid, ""); /* context id */
4535 :
4536 : /* prepare length information */
4537 0 : msg.headersize = (int32_t)((size_t)sizeof(DltStorageHeader) + (size_t)sizeof(DltStandardHeader) + (size_t)sizeof(DltExtendedHeader) +
4538 0 : (size_t)DLT_STANDARD_HEADER_EXTRA_SIZE(msg.standardheader->htyp));
4539 :
4540 0 : len = (int32_t)((size_t)msg.headersize - (size_t)sizeof(DltStorageHeader) + (size_t)msg.datasize);
4541 :
4542 0 : if (len > UINT16_MAX) {
4543 0 : dlt_log(LOG_WARNING, "Huge control message discarded!\n");
4544 :
4545 : /* free message */
4546 0 : dlt_message_free(&msg, 0);
4547 :
4548 0 : return;
4549 : }
4550 :
4551 0 : msg.standardheader->len = DLT_HTOBE_16(((uint16_t)len));
4552 :
4553 : /* Send message, ignore return value */
4554 0 : dlt_daemon_client_send(sock, daemon, daemon_local, msg.headerbuffer,
4555 : sizeof(DltStorageHeader),
4556 : msg.headerbuffer + sizeof(DltStorageHeader),
4557 : (int) msg.headersize - (int) sizeof(DltStorageHeader),
4558 0 : msg.databuffer, (int) msg.datasize, verbose);
4559 :
4560 : /* free message */
4561 0 : dlt_message_free(&msg, 0);
4562 : }
4563 :
4564 0 : int dlt_daemon_process_one_s_timer(DltDaemon *daemon,
4565 : DltDaemonLocal *daemon_local,
4566 : DltReceiver *receiver,
4567 : int verbose)
4568 : {
4569 0 : uint64_t expir = 0;
4570 : ssize_t res = 0;
4571 :
4572 0 : PRINT_FUNCTION_VERBOSE(verbose);
4573 :
4574 0 : if ((daemon_local == NULL) || (daemon == NULL) || (receiver == NULL)) {
4575 0 : dlt_vlog(LOG_ERR, "%s: invalid parameters", __func__);
4576 0 : return -1;
4577 : }
4578 :
4579 0 : res = read(receiver->fd, &expir, sizeof(expir));
4580 :
4581 0 : if (res < 0) {
4582 0 : dlt_vlog(LOG_WARNING, "%s: Fail to read timer (%s)\n", __func__,
4583 0 : strerror(errno));
4584 : /* Activity received on timer_wd, but unable to read the fd:
4585 : * let's go on sending notification */
4586 : }
4587 :
4588 0 : if ((daemon->state == DLT_DAEMON_STATE_SEND_BUFFER) ||
4589 : (daemon->state == DLT_DAEMON_STATE_BUFFER_FULL)) {
4590 0 : if (dlt_daemon_send_ringbuffer_to_client(daemon,
4591 : daemon_local,
4592 : daemon_local->flags.vflag))
4593 0 : dlt_log(LOG_DEBUG,
4594 : "Can't send contents of ring buffer to clients\n");
4595 : }
4596 :
4597 0 : if ((daemon->timingpackets) &&
4598 0 : (daemon->state == DLT_DAEMON_STATE_SEND_DIRECT))
4599 0 : dlt_daemon_control_message_time(DLT_DAEMON_SEND_TO_ALL,
4600 : daemon,
4601 : daemon_local,
4602 : daemon_local->flags.vflag);
4603 :
4604 0 : dlt_log(LOG_DEBUG, "Timer timingpacket\n");
4605 :
4606 0 : return 0;
4607 : }
4608 :
4609 0 : int dlt_daemon_process_sixty_s_timer(DltDaemon *daemon,
4610 : DltDaemonLocal *daemon_local,
4611 : DltReceiver *receiver,
4612 : int verbose)
4613 : {
4614 0 : uint64_t expir = 0;
4615 : ssize_t res = 0;
4616 :
4617 0 : PRINT_FUNCTION_VERBOSE(verbose);
4618 :
4619 0 : if ((daemon_local == NULL) || (daemon == NULL) || (receiver == NULL)) {
4620 0 : dlt_vlog(LOG_ERR, "%s: invalid parameters", __func__);
4621 0 : return -1;
4622 : }
4623 :
4624 0 : res = read(receiver->fd, &expir, sizeof(expir));
4625 :
4626 0 : if (res < 0) {
4627 0 : dlt_vlog(LOG_WARNING, "%s: Fail to read timer (%s)\n", __func__,
4628 0 : strerror(errno));
4629 : /* Activity received on timer_wd, but unable to read the fd:
4630 : * let's go on sending notification */
4631 : }
4632 :
4633 0 : if (daemon_local->flags.sendECUSoftwareVersion > 0){
4634 0 : if (daemon->daemon_version == DLTProtocolV2) {
4635 0 : dlt_daemon_control_get_software_version_v2(DLT_DAEMON_SEND_TO_ALL,
4636 : daemon,
4637 : daemon_local,
4638 : daemon_local->flags.vflag);
4639 0 : }else if (daemon->daemon_version == DLTProtocolV1) {
4640 0 : dlt_daemon_control_get_software_version(DLT_DAEMON_SEND_TO_ALL,
4641 : daemon,
4642 : daemon_local,
4643 : daemon_local->flags.vflag);
4644 : }else {
4645 0 : dlt_vlog(LOG_ERR, "Unsupported DLT version %u in %s\n", daemon->daemon_version, __func__);
4646 0 : return -1;
4647 : }
4648 : }
4649 :
4650 0 : if (daemon_local->flags.sendTimezone > 0) {
4651 : /* send timezone information */
4652 0 : time_t t = time(NULL);
4653 : struct tm lt;
4654 :
4655 : /*Added memset to avoid compiler warning for near initialization */
4656 : memset((void *)<, 0, sizeof(lt));
4657 0 : tzset();
4658 0 : localtime_r(&t, <);
4659 0 : if (daemon->daemon_version == DLTProtocolV2) {
4660 0 : dlt_daemon_control_message_timezone_v2(DLT_DAEMON_SEND_TO_ALL,
4661 : daemon,
4662 : daemon_local,
4663 : daemon_local->flags.vflag);
4664 0 : }else if (daemon->daemon_version == DLTProtocolV1) {
4665 0 : dlt_daemon_control_message_timezone(DLT_DAEMON_SEND_TO_ALL,
4666 : daemon,
4667 : daemon_local,
4668 : daemon_local->flags.vflag);
4669 : }else {
4670 0 : dlt_vlog(LOG_ERR, "Unsupported DLT version %u in %s\n", daemon->daemon_version, __func__);
4671 0 : return -1;
4672 : }
4673 : }
4674 :
4675 0 : dlt_log(LOG_DEBUG, "Timer ecuversion\n");
4676 :
4677 0 : return 0;
4678 : }
4679 :
4680 : #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE
4681 : int dlt_daemon_process_systemd_timer(DltDaemon *daemon,
4682 : DltDaemonLocal *daemon_local,
4683 : DltReceiver *receiver,
4684 : int verbose)
4685 : {
4686 : uint64_t expir = 0;
4687 : ssize_t res = -1;
4688 :
4689 : PRINT_FUNCTION_VERBOSE(verbose);
4690 :
4691 : if ((daemon_local == NULL) || (daemon == NULL) || (receiver == NULL)) {
4692 : dlt_vlog(LOG_ERR, "%s: invalid parameters", __func__);
4693 : return res;
4694 : }
4695 :
4696 : res = read(receiver->fd, &expir, sizeof(expir));
4697 :
4698 : if (res < 0) {
4699 : dlt_vlog(LOG_WARNING, "Failed to read timer_wd; %s\n", strerror(errno));
4700 : /* Activity received on timer_wd, but unable to read the fd:
4701 : * let's go on sending notification */
4702 : }
4703 :
4704 : #ifdef DLT_SYSTEMD_WATCHDOG_ENFORCE_MSG_RX_ENABLE
4705 : if (!daemon->received_message_since_last_watchdog_interval) {
4706 : dlt_log(LOG_WARNING, "No new messages received since last watchdog timer run\n");
4707 : return 0;
4708 : }
4709 : daemon->received_message_since_last_watchdog_interval = 0;
4710 : #endif
4711 :
4712 : dlt_daemon_trigger_systemd_watchdog_if_necessary(daemon);
4713 :
4714 : dlt_log(LOG_DEBUG, "Timer watchdog\n");
4715 :
4716 : return 0;
4717 : }
4718 : #else
4719 0 : int dlt_daemon_process_systemd_timer(DltDaemon *daemon,
4720 : DltDaemonLocal *daemon_local,
4721 : DltReceiver *receiver,
4722 : int verbose)
4723 : {
4724 : (void)daemon;
4725 : (void)daemon_local;
4726 : (void)receiver;
4727 : (void)verbose;
4728 :
4729 0 : dlt_log(LOG_DEBUG, "Timer watchdog not enabled\n");
4730 :
4731 0 : return -1;
4732 : }
4733 : #endif
4734 :
4735 1 : void dlt_daemon_control_service_logstorage(int sock,
4736 : DltDaemon *daemon,
4737 : DltDaemonLocal *daemon_local,
4738 : DltMessage *msg,
4739 : int verbose)
4740 : {
4741 : DltServiceOfflineLogstorage *req = NULL;
4742 : int ret = 0;
4743 : unsigned int connection_type = 0;
4744 : DltLogStorage *device = NULL;
4745 : int device_index = -1;
4746 : uint32_t i = 0;
4747 :
4748 : int tmp_errno = 0;
4749 :
4750 1 : struct stat daemon_mpoint_st = {0};
4751 : int daemon_st_status = 0;
4752 :
4753 1 : struct stat req_mpoint_st = {0};
4754 : int req_st_status = 0;
4755 :
4756 1 : PRINT_FUNCTION_VERBOSE(verbose);
4757 :
4758 1 : if ((daemon == NULL) || (msg == NULL) || (daemon_local == NULL)) {
4759 0 : dlt_vlog(LOG_ERR,
4760 : "%s: Invalid function parameters\n",
4761 : __func__);
4762 0 : return;
4763 : }
4764 :
4765 1 : if ((daemon_local->flags.offlineLogstorageMaxDevices <= 0) || (msg->databuffer == NULL)) {
4766 0 : dlt_daemon_control_service_response(sock,
4767 : daemon,
4768 : daemon_local,
4769 : DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,
4770 : DLT_SERVICE_RESPONSE_ERROR,
4771 : verbose);
4772 :
4773 0 : dlt_log(LOG_INFO,
4774 : "Logstorage functionality not enabled or MAX device set is 0\n");
4775 0 : return;
4776 : }
4777 :
4778 1 : if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceOfflineLogstorage)) < 0)
4779 : return;
4780 :
4781 1 : req = (DltServiceOfflineLogstorage *)(msg->databuffer);
4782 :
4783 1 : if(req->connection_type != DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES) {
4784 0 : req_st_status = stat(req->mount_point, &req_mpoint_st);
4785 0 : tmp_errno = errno;
4786 0 : if (req_st_status < 0) {
4787 0 : dlt_daemon_control_service_response(sock,
4788 : daemon,
4789 : daemon_local,
4790 : DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,
4791 : DLT_SERVICE_RESPONSE_ERROR,
4792 : verbose);
4793 :
4794 0 : dlt_vlog(LOG_WARNING,
4795 : "%s: Failed to stat requested mount point [%s] with error [%s]\n",
4796 : __func__, req->mount_point, strerror(tmp_errno));
4797 0 : return;
4798 : }
4799 : }
4800 :
4801 2 : for (i = 0; i < (uint32_t) daemon_local->flags.offlineLogstorageMaxDevices; i++) {
4802 1 : connection_type = daemon->storage_handle[i].connection_type;
4803 :
4804 : memset(&daemon_mpoint_st, 0, sizeof(struct stat));
4805 1 : if (strlen(daemon->storage_handle[i].device_mount_point) > 1) {
4806 0 : daemon_st_status = stat(daemon->storage_handle[i].device_mount_point,
4807 : &daemon_mpoint_st);
4808 0 : tmp_errno = errno;
4809 :
4810 0 : if (daemon_st_status < 0) {
4811 0 : dlt_daemon_control_service_response(sock,
4812 : daemon,
4813 : daemon_local,
4814 : DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,
4815 : DLT_SERVICE_RESPONSE_ERROR,
4816 : verbose);
4817 0 : dlt_vlog(LOG_WARNING,
4818 : "%s: Failed to stat daemon mount point [%s] with error [%s]\n",
4819 0 : __func__, daemon->storage_handle[i].device_mount_point,
4820 : strerror(tmp_errno));
4821 0 : return;
4822 : }
4823 :
4824 : /* Check if the requested device path is already used as log storage device */
4825 0 : if (req_mpoint_st.st_dev == daemon_mpoint_st.st_dev &&
4826 0 : req_mpoint_st.st_ino == daemon_mpoint_st.st_ino) {
4827 0 : device_index = (int) i;
4828 0 : break;
4829 : }
4830 : }
4831 :
4832 : /* Get first available device index here */
4833 1 : if ((connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) &&
4834 1 : (device_index == -1))
4835 0 : device_index = (int) i;
4836 : }
4837 :
4838 : /* It might be possible to sync all caches of all devices */
4839 1 : if ((req->connection_type == DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES) &&
4840 1 : (strlen(req->mount_point) == 0)) {
4841 : /* It is expected to receive an empty mount point to sync all Logstorage
4842 : * devices in this case. */
4843 : }
4844 0 : else if (device_index == -1) {
4845 0 : dlt_daemon_control_service_response(sock,
4846 : daemon,
4847 : daemon_local,
4848 : DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,
4849 : DLT_SERVICE_RESPONSE_ERROR,
4850 : verbose);
4851 0 : dlt_log(LOG_WARNING, "MAX devices already in use \n");
4852 0 : return;
4853 : }
4854 :
4855 : /* Check for device connection request from log storage ctrl app */
4856 1 : device = &daemon->storage_handle[device_index];
4857 :
4858 1 : if (req->connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) {
4859 0 : ret = dlt_logstorage_device_connected(device, req->mount_point);
4860 :
4861 0 : if (ret == 1) {
4862 0 : dlt_daemon_control_service_response(sock,
4863 : daemon,
4864 : daemon_local,
4865 : DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,
4866 : DLT_SERVICE_RESPONSE_WARNING,
4867 : verbose);
4868 0 : return;
4869 : }
4870 0 : else if (ret != 0)
4871 : {
4872 0 : dlt_daemon_control_service_response(sock,
4873 : daemon,
4874 : daemon_local,
4875 : DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,
4876 : DLT_SERVICE_RESPONSE_ERROR,
4877 : verbose);
4878 0 : return;
4879 : }
4880 :
4881 0 : dlt_daemon_control_service_response(sock,
4882 : daemon,
4883 : daemon_local,
4884 : DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,
4885 : DLT_SERVICE_RESPONSE_OK,
4886 : verbose);
4887 :
4888 : /* Update maintain logstorage loglevel if necessary */
4889 0 : if (daemon->storage_handle[device_index].maintain_logstorage_loglevel != DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_UNDEF)
4890 : {
4891 0 : daemon->maintain_logstorage_loglevel = daemon->storage_handle[device_index].maintain_logstorage_loglevel;
4892 : }
4893 :
4894 : /* Check if log level of running application needs an update */
4895 0 : dlt_daemon_logstorage_update_application_loglevel(daemon,
4896 : daemon_local,
4897 : device_index,
4898 : verbose);
4899 :
4900 : }
4901 : /* Check for device disconnection request from log storage ctrl app */
4902 1 : else if (req->connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_DISCONNECTED)
4903 : {
4904 : /* Check if log level of running application needs to be reset */
4905 0 : dlt_daemon_logstorage_reset_application_loglevel(
4906 : daemon,
4907 : daemon_local,
4908 : device_index,
4909 : (int) daemon_local->flags.offlineLogstorageMaxDevices,
4910 : verbose);
4911 :
4912 0 : dlt_logstorage_device_disconnected(&(daemon->storage_handle[device_index]),
4913 : DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT);
4914 :
4915 0 : dlt_daemon_control_service_response(sock,
4916 : daemon,
4917 : daemon_local,
4918 : DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,
4919 : DLT_SERVICE_RESPONSE_OK,
4920 : verbose);
4921 :
4922 : }
4923 : /* Check for cache synchronization request from log storage ctrl app */
4924 1 : else if (req->connection_type == DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES)
4925 : {
4926 : ret = 0;
4927 :
4928 1 : if (device_index == -1) { /* sync all Logstorage devices */
4929 :
4930 2 : for (i = 0; i < (uint32_t) daemon_local->flags.offlineLogstorageMaxDevices; i++)
4931 1 : if (daemon->storage_handle[i].connection_type ==
4932 : DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED)
4933 1 : ret = dlt_daemon_logstorage_sync_cache(
4934 : daemon,
4935 : daemon_local,
4936 1 : daemon->storage_handle[i].device_mount_point,
4937 : verbose);
4938 : }
4939 : else {
4940 : /* trigger logstorage to sync caches */
4941 0 : ret = dlt_daemon_logstorage_sync_cache(daemon,
4942 : daemon_local,
4943 0 : req->mount_point,
4944 : verbose);
4945 : }
4946 :
4947 1 : if (ret == 0)
4948 1 : dlt_daemon_control_service_response(sock,
4949 : daemon,
4950 : daemon_local,
4951 : DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,
4952 : DLT_SERVICE_RESPONSE_OK,
4953 : verbose);
4954 : else
4955 0 : dlt_daemon_control_service_response(sock,
4956 : daemon,
4957 : daemon_local,
4958 : DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,
4959 : DLT_SERVICE_RESPONSE_ERROR,
4960 : verbose);
4961 : }
4962 : else {
4963 0 : dlt_daemon_control_service_response(sock,
4964 : daemon,
4965 : daemon_local,
4966 : DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,
4967 : DLT_SERVICE_RESPONSE_ERROR,
4968 : verbose);
4969 : }
4970 : }
4971 :
4972 0 : void dlt_daemon_control_service_logstorage_v2(int sock,
4973 : DltDaemon *daemon,
4974 : DltDaemonLocal *daemon_local,
4975 : DltMessageV2 *msg,
4976 : int verbose)
4977 : {
4978 : DltServiceOfflineLogstorage *req = NULL;
4979 : int ret = 0;
4980 : unsigned int connection_type = 0;
4981 : DltLogStorage *device = NULL;
4982 : int device_index = -1;
4983 : uint32_t i = 0;
4984 :
4985 : int tmp_errno = 0;
4986 :
4987 0 : struct stat daemon_mpoint_st = {0};
4988 : int daemon_st_status = 0;
4989 :
4990 0 : struct stat req_mpoint_st = {0};
4991 : int req_st_status = 0;
4992 :
4993 0 : PRINT_FUNCTION_VERBOSE(verbose);
4994 :
4995 0 : if ((daemon == NULL) || (msg == NULL) || (daemon_local == NULL)) {
4996 0 : dlt_vlog(LOG_ERR,
4997 : "%s: Invalid function parameters\n",
4998 : __func__);
4999 0 : return;
5000 : }
5001 :
5002 0 : if ((daemon_local->flags.offlineLogstorageMaxDevices <= 0) || (msg->databuffer == NULL)) {
5003 0 : dlt_daemon_control_service_response_v2(sock,
5004 : daemon,
5005 : daemon_local,
5006 : DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,
5007 : DLT_SERVICE_RESPONSE_ERROR,
5008 : verbose);
5009 :
5010 0 : dlt_log(LOG_INFO,
5011 : "Logstorage functionality not enabled or MAX device set is 0\n");
5012 0 : return;
5013 : }
5014 :
5015 0 : if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceOfflineLogstorage)) < 0)
5016 : return;
5017 :
5018 0 : req = (DltServiceOfflineLogstorage *)(msg->databuffer);
5019 :
5020 0 : if(req->connection_type != DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES) {
5021 0 : req_st_status = stat(req->mount_point, &req_mpoint_st);
5022 0 : tmp_errno = errno;
5023 0 : if (req_st_status < 0) {
5024 0 : dlt_daemon_control_service_response_v2(sock,
5025 : daemon,
5026 : daemon_local,
5027 : DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,
5028 : DLT_SERVICE_RESPONSE_ERROR,
5029 : verbose);
5030 :
5031 0 : dlt_vlog(LOG_WARNING,
5032 : "%s: Failed to stat requested mount point [%s] with error [%s]\n",
5033 : __func__, req->mount_point, strerror(tmp_errno));
5034 0 : return;
5035 : }
5036 : }
5037 :
5038 0 : for (i = 0; i < (uint32_t) daemon_local->flags.offlineLogstorageMaxDevices; i++) {
5039 0 : connection_type = daemon->storage_handle[i].connection_type;
5040 :
5041 : memset(&daemon_mpoint_st, 0, sizeof(struct stat));
5042 0 : if (strlen(daemon->storage_handle[i].device_mount_point) > 1) {
5043 0 : daemon_st_status = stat(daemon->storage_handle[i].device_mount_point,
5044 : &daemon_mpoint_st);
5045 0 : tmp_errno = errno;
5046 :
5047 0 : if (daemon_st_status < 0) {
5048 0 : dlt_daemon_control_service_response_v2(sock,
5049 : daemon,
5050 : daemon_local,
5051 : DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,
5052 : DLT_SERVICE_RESPONSE_ERROR,
5053 : verbose);
5054 0 : dlt_vlog(LOG_WARNING,
5055 : "%s: Failed to stat daemon mount point [%s] with error [%s]\n",
5056 0 : __func__, daemon->storage_handle[i].device_mount_point,
5057 : strerror(tmp_errno));
5058 0 : return;
5059 : }
5060 :
5061 : /* Check if the requested device path is already used as log storage device */
5062 0 : if (req_mpoint_st.st_dev == daemon_mpoint_st.st_dev &&
5063 0 : req_mpoint_st.st_ino == daemon_mpoint_st.st_ino) {
5064 0 : device_index = (int) i;
5065 0 : break;
5066 : }
5067 : }
5068 :
5069 : /* Get first available device index here */
5070 0 : if ((connection_type != DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) &&
5071 0 : (device_index == -1))
5072 0 : device_index = (int) i;
5073 : }
5074 :
5075 : /* It might be possible to sync all caches of all devices */
5076 0 : if ((req->connection_type == DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES) &&
5077 0 : (strlen(req->mount_point) == 0)) {
5078 : /* It is expected to receive an empty mount point to sync all Logstorage
5079 : * devices in this case. */
5080 : }
5081 0 : else if (device_index == -1) {
5082 0 : dlt_daemon_control_service_response_v2(sock,
5083 : daemon,
5084 : daemon_local,
5085 : DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,
5086 : DLT_SERVICE_RESPONSE_ERROR,
5087 : verbose);
5088 0 : dlt_log(LOG_WARNING, "MAX devices already in use \n");
5089 0 : return;
5090 : }
5091 :
5092 : /* Check for device connection request from log storage ctrl app */
5093 0 : device = &daemon->storage_handle[device_index];
5094 :
5095 0 : if (req->connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED) {
5096 0 : ret = dlt_logstorage_device_connected(device, req->mount_point);
5097 :
5098 0 : if (ret == 1) {
5099 0 : dlt_daemon_control_service_response_v2(sock,
5100 : daemon,
5101 : daemon_local,
5102 : DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,
5103 : DLT_SERVICE_RESPONSE_WARNING,
5104 : verbose);
5105 0 : return;
5106 : }
5107 0 : else if (ret != 0)
5108 : {
5109 0 : dlt_daemon_control_service_response_v2(sock,
5110 : daemon,
5111 : daemon_local,
5112 : DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,
5113 : DLT_SERVICE_RESPONSE_ERROR,
5114 : verbose);
5115 0 : return;
5116 : }
5117 :
5118 0 : dlt_daemon_control_service_response_v2(sock,
5119 : daemon,
5120 : daemon_local,
5121 : DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,
5122 : DLT_SERVICE_RESPONSE_OK,
5123 : verbose);
5124 :
5125 : /* Update maintain logstorage loglevel if necessary */
5126 0 : if (daemon->storage_handle[device_index].maintain_logstorage_loglevel != DLT_MAINTAIN_LOGSTORAGE_LOGLEVEL_UNDEF)
5127 : {
5128 0 : daemon->maintain_logstorage_loglevel = daemon->storage_handle[device_index].maintain_logstorage_loglevel;
5129 : }
5130 :
5131 : /* Check if log level of running application needs an update */
5132 0 : dlt_daemon_logstorage_update_application_loglevel_v2(daemon,
5133 : daemon_local,
5134 : device_index,
5135 : verbose);
5136 :
5137 : }
5138 : /* Check for device disconnection request from log storage ctrl app */
5139 0 : else if (req->connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_DISCONNECTED)
5140 : {
5141 : /* Check if log level of running application needs to be reset */
5142 0 : dlt_daemon_logstorage_reset_application_loglevel(
5143 : daemon,
5144 : daemon_local,
5145 : device_index,
5146 : (int) daemon_local->flags.offlineLogstorageMaxDevices,
5147 : verbose);
5148 :
5149 0 : dlt_logstorage_device_disconnected(&(daemon->storage_handle[device_index]),
5150 : DLT_LOGSTORAGE_SYNC_ON_DEVICE_DISCONNECT);
5151 :
5152 0 : dlt_daemon_control_service_response_v2(sock,
5153 : daemon,
5154 : daemon_local,
5155 : DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,
5156 : DLT_SERVICE_RESPONSE_OK,
5157 : verbose);
5158 :
5159 : }
5160 : /* Check for cache synchronization request from log storage ctrl app */
5161 0 : else if (req->connection_type == DLT_OFFLINE_LOGSTORAGE_SYNC_CACHES)
5162 : {
5163 : ret = 0;
5164 :
5165 0 : if (device_index == -1) { /* sync all Logstorage devices */
5166 :
5167 0 : for (i = 0; i < (uint32_t) daemon_local->flags.offlineLogstorageMaxDevices; i++)
5168 0 : if (daemon->storage_handle[i].connection_type ==
5169 : DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED)
5170 0 : ret = dlt_daemon_logstorage_sync_cache(
5171 : daemon,
5172 : daemon_local,
5173 0 : daemon->storage_handle[i].device_mount_point,
5174 : verbose);
5175 : }
5176 : else {
5177 : /* trigger logstorage to sync caches */
5178 0 : ret = dlt_daemon_logstorage_sync_cache(daemon,
5179 : daemon_local,
5180 0 : req->mount_point,
5181 : verbose);
5182 : }
5183 :
5184 0 : if (ret == 0)
5185 0 : dlt_daemon_control_service_response_v2(sock,
5186 : daemon,
5187 : daemon_local,
5188 : DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,
5189 : DLT_SERVICE_RESPONSE_OK,
5190 : verbose);
5191 : else
5192 0 : dlt_daemon_control_service_response_v2(sock,
5193 : daemon,
5194 : daemon_local,
5195 : DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,
5196 : DLT_SERVICE_RESPONSE_ERROR,
5197 : verbose);
5198 : }
5199 : else {
5200 0 : dlt_daemon_control_service_response_v2(sock,
5201 : daemon,
5202 : daemon_local,
5203 : DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,
5204 : DLT_SERVICE_RESPONSE_ERROR,
5205 : verbose);
5206 : }
5207 : }
5208 :
5209 0 : void dlt_daemon_control_passive_node_connect(int sock,
5210 : DltDaemon *daemon,
5211 : DltDaemonLocal *daemon_local,
5212 : DltMessage *msg,
5213 : int verbose)
5214 : {
5215 0 : PRINT_FUNCTION_VERBOSE(verbose);
5216 :
5217 : DltServicePassiveNodeConnect *req;
5218 : uint32_t id = DLT_SERVICE_ID_PASSIVE_NODE_CONNECT;
5219 :
5220 0 : if ((daemon == NULL) || (daemon_local == NULL) || (msg == NULL) ||
5221 0 : (msg->databuffer == NULL))
5222 : return;
5223 :
5224 : /* return error, if gateway mode not enabled*/
5225 0 : if (daemon_local->flags.gatewayMode == 0) {
5226 0 : dlt_log(LOG_WARNING,
5227 : "Received passive node connection status request, "
5228 : "but GatewayMode is disabled\n");
5229 :
5230 0 : dlt_daemon_control_service_response(
5231 : sock,
5232 : daemon,
5233 : daemon_local,
5234 : DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS,
5235 : DLT_SERVICE_RESPONSE_ERROR,
5236 : verbose);
5237 :
5238 0 : return;
5239 : }
5240 :
5241 0 : if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServicePassiveNodeConnect)) < 0)
5242 : return;
5243 :
5244 0 : req = (DltServicePassiveNodeConnect *)msg->databuffer;
5245 :
5246 0 : if (dlt_gateway_process_on_demand_request(&daemon_local->pGateway,
5247 : daemon_local,
5248 0 : req->node_id,
5249 0 : (int) req->connection_status,
5250 : verbose) < 0)
5251 0 : dlt_daemon_control_service_response(sock,
5252 : daemon,
5253 : daemon_local,
5254 : id,
5255 : DLT_SERVICE_RESPONSE_ERROR,
5256 : verbose);
5257 : else
5258 0 : dlt_daemon_control_service_response(sock,
5259 : daemon,
5260 : daemon_local,
5261 : id,
5262 : DLT_SERVICE_RESPONSE_OK,
5263 : verbose);
5264 : }
5265 :
5266 0 : void dlt_daemon_control_passive_node_connect_v2(int sock,
5267 : DltDaemon *daemon,
5268 : DltDaemonLocal *daemon_local,
5269 : DltMessageV2 *msg,
5270 : int verbose)
5271 : {
5272 0 : PRINT_FUNCTION_VERBOSE(verbose);
5273 :
5274 : //TBD: Review node_id member of DltServicePassiveNodeConnect
5275 : DltServicePassiveNodeConnect *req;
5276 : uint32_t id = DLT_SERVICE_ID_PASSIVE_NODE_CONNECT;
5277 :
5278 0 : if ((daemon == NULL) || (daemon_local == NULL) || (msg == NULL) ||
5279 0 : (msg->databuffer == NULL))
5280 : return;
5281 :
5282 : /* return error, if gateway mode not enabled*/
5283 0 : if (daemon_local->flags.gatewayMode == 0) {
5284 0 : dlt_log(LOG_WARNING,
5285 : "Received passive node connection status request, "
5286 : "but GatewayMode is disabled\n");
5287 :
5288 0 : dlt_daemon_control_service_response_v2(
5289 : sock,
5290 : daemon,
5291 : daemon_local,
5292 : DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS,
5293 : DLT_SERVICE_RESPONSE_ERROR,
5294 : verbose);
5295 :
5296 0 : return;
5297 : }
5298 :
5299 0 : if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServicePassiveNodeConnect)) < 0)
5300 : return;
5301 :
5302 0 : req = (DltServicePassiveNodeConnect *)msg->databuffer;
5303 :
5304 0 : if (dlt_gateway_process_on_demand_request(&daemon_local->pGateway,
5305 : daemon_local,
5306 0 : req->node_id,
5307 0 : (int) req->connection_status,
5308 : verbose) < 0)
5309 0 : dlt_daemon_control_service_response_v2(sock,
5310 : daemon,
5311 : daemon_local,
5312 : id,
5313 : DLT_SERVICE_RESPONSE_ERROR,
5314 : verbose);
5315 : else
5316 0 : dlt_daemon_control_service_response_v2(sock,
5317 : daemon,
5318 : daemon_local,
5319 : id,
5320 : DLT_SERVICE_RESPONSE_OK,
5321 : verbose);
5322 : }
5323 :
5324 0 : void dlt_daemon_control_passive_node_connect_status_v2(int sock,
5325 : DltDaemon *daemon,
5326 : DltDaemonLocal *daemon_local,
5327 : int verbose)
5328 : {
5329 : DltMessageV2 msg;
5330 : DltServicePassiveNodeConnectionInfo *resp;
5331 : DltGatewayConnection *con = NULL;
5332 : unsigned int i = 0;
5333 :
5334 0 : PRINT_FUNCTION_VERBOSE(verbose);
5335 :
5336 0 : if ((daemon == NULL) || (daemon_local == NULL))
5337 0 : return;
5338 :
5339 0 : if (dlt_message_init_v2(&msg, verbose) == -1)
5340 : return;
5341 :
5342 : /* return error, if gateway mode not enabled*/
5343 0 : if (daemon_local->flags.gatewayMode == 0) {
5344 0 : dlt_log(LOG_WARNING,
5345 : "Received passive node connection status request, "
5346 : "but GatewayMode is disabled\n");
5347 :
5348 0 : dlt_daemon_control_service_response_v2(
5349 : sock,
5350 : daemon,
5351 : daemon_local,
5352 : DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS,
5353 : DLT_SERVICE_RESPONSE_ERROR,
5354 : verbose);
5355 :
5356 0 : return;
5357 : }
5358 :
5359 : /* prepare payload of data */
5360 0 : msg.datasize = sizeof(DltServicePassiveNodeConnectionInfo);
5361 :
5362 0 : if (msg.databuffer && (msg.databuffersize < msg.datasize))
5363 0 : msg.databuffer = NULL;
5364 :
5365 0 : if (msg.databuffer == NULL) {
5366 0 : msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize);
5367 :
5368 0 : if (msg.databuffer == NULL) {
5369 0 : dlt_log(LOG_CRIT, "Cannot allocate memory for message response\n");
5370 0 : return;
5371 : }
5372 :
5373 0 : msg.databuffersize = msg.datasize;
5374 : }
5375 :
5376 0 : resp = (DltServicePassiveNodeConnectionInfo *)msg.databuffer;
5377 : memset(resp, 0, (size_t)msg.datasize);
5378 0 : resp->service_id = DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS;
5379 : resp->status = DLT_SERVICE_RESPONSE_OK;
5380 0 : resp->num_connections = (uint32_t) daemon_local->pGateway.num_connections;
5381 :
5382 0 : for (i = 0; i < resp->num_connections; i++) {
5383 0 : if ((i * DLT_ID_SIZE) > DLT_ENTRY_MAX) {
5384 0 : dlt_log(LOG_ERR,
5385 : "Maximal message size reached. Skip further information\n");
5386 0 : break;
5387 : }
5388 :
5389 0 : con = &daemon_local->pGateway.connections[i];
5390 :
5391 0 : resp->connection_status[i] = con->status;
5392 : //TBD: Review node_id[i * con->ecuid2len]
5393 0 : memcpy(&resp->node_id[i * con->ecuid2len], con->ecuid2, con->ecuid2len);
5394 : }
5395 :
5396 0 : dlt_daemon_client_send_control_message_v2(sock,
5397 : daemon,
5398 : daemon_local,
5399 : &msg,
5400 : "",
5401 : "",
5402 : verbose);
5403 : /* free message */
5404 0 : dlt_message_free_v2(&msg, verbose);
5405 : }
5406 :
5407 0 : void dlt_daemon_control_passive_node_connect_status(int sock,
5408 : DltDaemon *daemon,
5409 : DltDaemonLocal *daemon_local,
5410 : int verbose)
5411 : {
5412 : DltMessage msg;
5413 : DltServicePassiveNodeConnectionInfo *resp;
5414 : DltGatewayConnection *con = NULL;
5415 : unsigned int i = 0;
5416 :
5417 0 : PRINT_FUNCTION_VERBOSE(verbose);
5418 :
5419 0 : if ((daemon == NULL) || (daemon_local == NULL))
5420 0 : return;
5421 :
5422 0 : if (dlt_message_init(&msg, verbose) == -1)
5423 : return;
5424 :
5425 : /* return error, if gateway mode not enabled*/
5426 0 : if (daemon_local->flags.gatewayMode == 0) {
5427 0 : dlt_log(LOG_WARNING,
5428 : "Received passive node connection status request, "
5429 : "but GatewayMode is disabled\n");
5430 :
5431 0 : dlt_daemon_control_service_response(
5432 : sock,
5433 : daemon,
5434 : daemon_local,
5435 : DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS,
5436 : DLT_SERVICE_RESPONSE_ERROR,
5437 : verbose);
5438 :
5439 0 : return;
5440 : }
5441 :
5442 : /* prepare payload of data */
5443 0 : msg.datasize = sizeof(DltServicePassiveNodeConnectionInfo);
5444 :
5445 0 : if (msg.databuffer && (msg.databuffersize < msg.datasize))
5446 0 : msg.databuffer = NULL;
5447 :
5448 0 : if (msg.databuffer == NULL) {
5449 0 : msg.databuffer = (uint8_t *)malloc((size_t)msg.datasize);
5450 :
5451 0 : if (msg.databuffer == NULL) {
5452 0 : dlt_log(LOG_CRIT, "Cannot allocate memory for message response\n");
5453 0 : return;
5454 : }
5455 :
5456 0 : msg.databuffersize = msg.datasize;
5457 : }
5458 :
5459 0 : resp = (DltServicePassiveNodeConnectionInfo *)msg.databuffer;
5460 : memset(resp, 0, (size_t)msg.datasize);
5461 0 : resp->service_id = DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS;
5462 : resp->status = DLT_SERVICE_RESPONSE_OK;
5463 0 : resp->num_connections = (uint32_t) daemon_local->pGateway.num_connections;
5464 :
5465 0 : for (i = 0; i < resp->num_connections; i++) {
5466 0 : if ((i * DLT_ID_SIZE) > DLT_ENTRY_MAX) {
5467 0 : dlt_log(LOG_ERR,
5468 : "Maximal message size reached. Skip further information\n");
5469 0 : break;
5470 : }
5471 :
5472 0 : con = &daemon_local->pGateway.connections[i];
5473 :
5474 0 : resp->connection_status[i] = con->status;
5475 0 : memcpy(&resp->node_id[i * DLT_ID_SIZE], con->ecuid, DLT_ID_SIZE);
5476 : }
5477 :
5478 0 : dlt_daemon_client_send_control_message(sock,
5479 : daemon,
5480 : daemon_local,
5481 : &msg,
5482 : "",
5483 : "",
5484 : verbose);
5485 : /* free message */
5486 0 : dlt_message_free(&msg, verbose);
5487 : }
|