forked from COVESA/dlt-daemon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdlt_daemon_client.c
More file actions
2805 lines (2340 loc) · 106 KB
/
dlt_daemon_client.c
File metadata and controls
2805 lines (2340 loc) · 106 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* SPDX license identifier: MPL-2.0
*
* Copyright (C) 2011-2015, BMW AG
*
* This file is part of COVESA Project DLT - Diagnostic Log and Trace.
*
* This Source Code Form is subject to the terms of the
* Mozilla Public License (MPL), v. 2.0.
* If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* For further information see http://www.covesa.org/.
*/
/*!
* \author
* Alexander Wenzel <alexander.aw.wenzel@bmw.de>
* Markus Klein <Markus.Klein@esk.fraunhofer.de>
* Mikko Rapeli <mikko.rapeli@bmw.de>
*
* \copyright Copyright © 2011-2015 BMW AG. \n
* License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.
*
* \file dlt_daemon_client.c
*/
#include <netdb.h>
#include <ctype.h>
#include <stdio.h> /* for printf() and fprintf() */
#include <sys/socket.h> /* for socket(), connect(), (), and recv() */
#include <sys/stat.h> /* for stat() */
#include <arpa/inet.h> /* for sockaddr_in and inet_addr() */
#include <stdlib.h> /* for atoi() and exit() */
#include <string.h> /* for memset() */
#include <unistd.h> /* for close() */
#include <signal.h>
#include <syslog.h>
#include <errno.h>
#include <pthread.h>
#ifdef linux
# include <sys/timerfd.h>
#endif
#include <sys/time.h>
#if defined(linux) && defined(__NR_statx)
# include <linux/stat.h>
#endif
#ifdef DLT_SYSTEMD_WATCHDOG_ENABLE
# include <systemd/sd-daemon.h>
#endif
#include "dlt_types.h"
#include "dlt_log.h"
#include "dlt-daemon.h"
#include "dlt-daemon_cfg.h"
#include "dlt_daemon_common_cfg.h"
#include "dlt_daemon_socket.h"
#include "dlt_daemon_serial.h"
#include "dlt_daemon_client.h"
#include "dlt_daemon_connection.h"
#include "dlt_daemon_event_handler.h"
#include "dlt_daemon_offline_logstorage.h"
#include "dlt_gateway.h"
/** Inline function to calculate/set the requested log level or traces status
* with default log level or trace status when "ForceContextLogLevelAndTraceStatus"
* is enabled and set to 1 in dlt.conf file.
*
* @param request_log The requested log level (or) trace status
* @param context_log The default log level (or) trace status
*
* @return The log level if requested log level is lower or equal to ContextLogLevel
*/
static inline int8_t getStatus(uint8_t request_log, int context_log)
{
return (request_log <= context_log) ? request_log : context_log;
}
#ifdef UDP_CONNECTION_SUPPORT
# include "dlt_daemon_udp_socket.h"
#endif
/** @brief Sends up to 2 messages to all the clients.
*
* Runs through the client list and sends the messages to them. If the message
* transfer fails and the connection is a socket connection, the socket is closed.
* Takes and release dlt_daemon_mutex.
*
* @param daemon Daemon structure needed for socket closure.
* @param daemon_local Daemon local structure
* @param data1 The first message to be sent.
* @param size1 The size of the first message.
* @param data2 The second message to be send.
* @param size2 The second message size.
* @param verbose Needed for socket closure.
*
* @return The amount of data transferred.
*/
static int dlt_daemon_client_send_all_multiple(DltDaemon *daemon,
DltDaemonLocal *daemon_local,
void *data1,
int size1,
void *data2,
int size2,
int verbose)
{
int sent = 0;
nfds_t i = 0;
int ret = 0;
DltConnection *temp = NULL;
int type_mask =
(DLT_CON_MASK_CLIENT_MSG_TCP | DLT_CON_MASK_CLIENT_MSG_SERIAL);
PRINT_FUNCTION_VERBOSE(verbose);
if ((daemon == NULL) || (daemon_local == NULL)) {
dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__);
return 0;
}
for (i = 0; i < daemon_local->pEvent.nfds; i++)
{
#ifdef DLT_SYSTEMD_WATCHDOG_ENABLE
bool watchdog_triggered = dlt_daemon_trigger_systemd_watchdog_if_necessary(daemon);
if (watchdog_triggered) {
dlt_vlog(LOG_WARNING, "%s notified watchdog, processed %lu/%lu fds already.\n",
__func__, i, daemon_local->pEvent.nfds);
}
#endif
temp = dlt_event_handler_find_connection(&(daemon_local->pEvent),
daemon_local->pEvent.pfd[i].fd);
if ((temp == NULL) || (temp->receiver == NULL) ||
!((1 << temp->type) & type_mask)) {
dlt_log(LOG_DEBUG, "The connection not found or the connection type not TCP/Serial.\n");
continue;
}
ret = dlt_connection_send_multiple(temp,
data1,
size1,
data2,
size2,
daemon->sendserialheader);
if ((ret != DLT_DAEMON_ERROR_OK) &&
(DLT_CONNECTION_CLIENT_MSG_TCP == temp->type)) {
dlt_daemon_close_socket(temp->receiver->fd,
daemon,
daemon_local,
verbose);
}
if (ret != DLT_DAEMON_ERROR_OK)
dlt_vlog(LOG_WARNING, "%s: send dlt message failed\n", __func__);
else
/* If sent to at least one client,
* then do not store in ring buffer
*/
sent = 1;
} /* for */
#ifdef DLT_TRACE_LOAD_CTRL_ENABLE
if (sent)
{
const uint32_t serial_header = daemon->sendserialheader ? sizeof(dltSerialHeader) : 0;
daemon->bytes_sent += size1 + size2 + serial_header;
}
#endif
return sent;
}
int dlt_daemon_client_send(int sock,
DltDaemon *daemon,
DltDaemonLocal *daemon_local,
void *storage_header,
int storage_header_size,
void *data1,
int size1,
void *data2,
int size2,
int verbose)
{
int sent, ret;
int ret_logstorage = 0;
static int sent_message_overflow_cnt = 0;
if ((daemon == NULL) || (daemon_local == NULL)) {
dlt_vlog(LOG_ERR, "%s: Invalid arguments\n", __func__);
return DLT_DAEMON_ERROR_UNKNOWN;
}
if ((sock != DLT_DAEMON_SEND_TO_ALL) && (sock != DLT_DAEMON_SEND_FORCE)) {
/* Send message to specific socket */
if (isatty(sock)) {
if ((ret =
dlt_daemon_serial_send(sock, data1, size1, data2, size2,
daemon->sendserialheader))) {
dlt_vlog(LOG_WARNING, "%s: serial send dlt message failed\n", __func__);
return ret;
}
} else {
if ((ret =
dlt_daemon_socket_send(sock, data1, size1, data2, size2,
daemon->sendserialheader))) {
dlt_vlog(LOG_WARNING, "%s: socket send dlt message failed\n", __func__);
return ret;
}
}
return DLT_DAEMON_ERROR_OK;
}
/* write message to offline trace */
/* In the SEND_BUFFER state we must skip offline tracing because the offline traces */
/* are going without buffering directly to the offline trace. Thus we have to filter out */
/* the traces that are coming from the buffer. */
if ((sock != DLT_DAEMON_SEND_FORCE) && (daemon->state != DLT_DAEMON_STATE_SEND_BUFFER)) {
if (((daemon->mode == DLT_USER_MODE_INTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH))
&& daemon_local->flags.offlineTraceDirectory[0]) {
if (dlt_offline_trace_write(&(daemon_local->offlineTrace), storage_header, storage_header_size, data1,
size1, data2, size2)) {
static int error_dlt_offline_trace_write_failed = 0;
if (!error_dlt_offline_trace_write_failed) {
dlt_vlog(LOG_ERR, "%s: dlt_offline_trace_write failed!\n", __func__);
error_dlt_offline_trace_write_failed = 1;
}
/*return DLT_DAEMON_ERROR_WRITE_FAILED; */
}
}
/* write messages to offline logstorage only if there is an extended header set
* this need to be checked because the function is dlt_daemon_client_send is called by
* newly introduced dlt_daemon_log_internal */
if (daemon_local->flags.offlineLogstorageMaxDevices > 0)
ret_logstorage = dlt_daemon_logstorage_write(daemon,
&daemon_local->flags,
storage_header,
storage_header_size,
data1,
size1,
data2,
size2);
}
/* send messages to daemon socket */
if ((daemon->mode == DLT_USER_MODE_EXTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) {
#ifdef UDP_CONNECTION_SUPPORT
if (daemon_local->UDPConnectionSetup == MULTICAST_CONNECTION_ENABLED) {
/* Forward message to network client if network routing is not disabled */
if (ret_logstorage != 1) {
dlt_daemon_udp_dltmsg_multicast(data1,
size1,
data2,
size2,
verbose);
}
}
#endif
if ((sock == DLT_DAEMON_SEND_FORCE) || (daemon->state == DLT_DAEMON_STATE_SEND_DIRECT)) {
/* Forward message to network client if network routing is not disabled */
if (ret_logstorage != 1) {
sent = dlt_daemon_client_send_all_multiple(daemon,
daemon_local,
data1,
size1,
data2,
size2,
verbose);
if ((sock == DLT_DAEMON_SEND_FORCE) && !sent) {
return DLT_DAEMON_ERROR_SEND_FAILED;
}
}
}
}
/* Message was not sent to client, so store it in client ringbuffer */
if ((sock != DLT_DAEMON_SEND_FORCE) &&
((daemon->state == DLT_DAEMON_STATE_BUFFER) || (daemon->state == DLT_DAEMON_STATE_SEND_BUFFER) ||
(daemon->state == DLT_DAEMON_STATE_BUFFER_FULL))) {
if (daemon->state != DLT_DAEMON_STATE_BUFFER_FULL) {
/* Store message in history buffer */
ret = dlt_buffer_push3(&(daemon->client_ringbuffer), data1, size1, data2, size2, 0, 0);
if (ret < DLT_RETURN_OK) {
dlt_daemon_change_state(daemon, DLT_DAEMON_STATE_BUFFER_FULL);
}
}
if (daemon->state == DLT_DAEMON_STATE_BUFFER_FULL) {
daemon->overflow_counter += 1;
if (daemon->overflow_counter == 1)
dlt_vlog(LOG_INFO, "%s: Buffer is full! Messages will be discarded.\n", __func__);
return DLT_DAEMON_ERROR_BUFFER_FULL;
}
} else {
if ((daemon->overflow_counter > 0) &&
(daemon_local->client_connections > 0)) {
sent_message_overflow_cnt++;
if (sent_message_overflow_cnt >= 2) {
sent_message_overflow_cnt--;
}
else {
if (dlt_daemon_send_message_overflow(daemon, daemon_local,
verbose) == DLT_DAEMON_ERROR_OK) {
dlt_vlog(LOG_WARNING,
"%s: %u messages discarded! Now able to send messages to the client.\n",
__func__,
daemon->overflow_counter);
daemon->overflow_counter = 0;
sent_message_overflow_cnt--;
}
}
}
}
return DLT_DAEMON_ERROR_OK;
}
int dlt_daemon_client_send_message_to_all_client(DltDaemon *daemon,
DltDaemonLocal *daemon_local,
int verbose)
{
static char text[DLT_DAEMON_TEXTSIZE];
char * ecu_ptr = NULL;
PRINT_FUNCTION_VERBOSE(verbose);
if ((daemon == NULL) || (daemon_local == NULL)) {
dlt_vlog(LOG_ERR, "%s: invalid arguments\n", __func__);
return DLT_DAEMON_ERROR_UNKNOWN;
}
/* set overwrite ecu id */
if ((daemon_local->flags.evalue[0]) &&
(strncmp(daemon_local->msg.headerextra.ecu,
DLT_DAEMON_ECU_ID, DLT_ID_SIZE) == 0)) {
/* Set header extra parameters */
dlt_set_id(daemon_local->msg.headerextra.ecu, daemon->ecuid);
/*msg.headerextra.seid = 0; */
if (dlt_message_set_extraparameters(&(daemon_local->msg), 0)) {
dlt_vlog(LOG_WARNING,
"%s: failed to set message extra parameters.\n", __func__);
return DLT_DAEMON_ERROR_UNKNOWN;
}
/* Correct value of timestamp, this was changed by dlt_message_set_extraparameters() */
daemon_local->msg.headerextra.tmsp =
DLT_BETOH_32(daemon_local->msg.headerextra.tmsp);
}
/* prepare storage header */
if (DLT_IS_HTYP_WEID(daemon_local->msg.standardheader->htyp)) {
ecu_ptr = daemon_local->msg.headerextra.ecu;
} else {
ecu_ptr = daemon->ecuid;
}
if (dlt_set_storageheader(daemon_local->msg.storageheader, ecu_ptr)) {
dlt_vlog(LOG_WARNING,
"%s: failed to set storage header with header type: 0x%x\n",
__func__, daemon_local->msg.standardheader->htyp);
return DLT_DAEMON_ERROR_UNKNOWN;
}
/* if no filter set or filter is matching display message */
if (daemon_local->flags.xflag) {
if (DLT_RETURN_OK !=
dlt_message_print_hex(&(daemon_local->msg), text,
DLT_DAEMON_TEXTSIZE, verbose))
dlt_log(LOG_WARNING, "dlt_message_print_hex() failed!\n");
} else if (daemon_local->flags.aflag) {
if (DLT_RETURN_OK !=
dlt_message_print_ascii(&(daemon_local->msg), text,
DLT_DAEMON_TEXTSIZE, verbose))
dlt_log(LOG_WARNING, "dlt_message_print_ascii() failed!\n");
} else if (daemon_local->flags.sflag) {
if (DLT_RETURN_OK !=
dlt_message_print_header(&(daemon_local->msg), text,
DLT_DAEMON_TEXTSIZE, verbose))
dlt_log(LOG_WARNING, "dlt_message_print_header() failed!\n");
}
/* send message to client or write to log file */
return dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL, daemon, daemon_local,
daemon_local->msg.headerbuffer, sizeof(DltStorageHeader),
daemon_local->msg.headerbuffer + sizeof(DltStorageHeader),
(int) (daemon_local->msg.headersize - sizeof(DltStorageHeader)),
daemon_local->msg.databuffer, (int) daemon_local->msg.datasize, verbose);
}
int dlt_daemon_client_send_control_message(int sock,
DltDaemon *daemon,
DltDaemonLocal *daemon_local,
DltMessage *msg,
char *apid,
char *ctid,
int verbose)
{
int ret;
int32_t len;
PRINT_FUNCTION_VERBOSE(verbose);
if ((daemon == 0) || (msg == 0) || (apid == 0) || (ctid == 0))
return DLT_DAEMON_ERROR_UNKNOWN;
/* prepare storage header */
msg->storageheader = (DltStorageHeader *)msg->headerbuffer;
if (dlt_set_storageheader(msg->storageheader, daemon->ecuid) == DLT_RETURN_ERROR)
return DLT_DAEMON_ERROR_UNKNOWN;
/* prepare standard header */
msg->standardheader = (DltStandardHeader *)(msg->headerbuffer + sizeof(DltStorageHeader));
msg->standardheader->htyp = DLT_HTYP_WEID | DLT_HTYP_WTMS | DLT_HTYP_UEH | DLT_HTYP_PROTOCOL_VERSION1;
#if (BYTE_ORDER == BIG_ENDIAN)
msg->standardheader->htyp = (msg->standardheader->htyp | DLT_HTYP_MSBF);
#endif
msg->standardheader->mcnt = 0;
/* Set header extra parameters */
dlt_set_id(msg->headerextra.ecu, daemon->ecuid);
/*msg->headerextra.seid = 0; */
msg->headerextra.tmsp = dlt_uptime();
dlt_message_set_extraparameters(msg, verbose);
/* prepare extended header */
msg->extendedheader =
(DltExtendedHeader *)(msg->headerbuffer + sizeof(DltStorageHeader) + sizeof(DltStandardHeader) +
DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp));
msg->extendedheader->msin = DLT_MSIN_CONTROL_RESPONSE;
msg->extendedheader->noar = 1; /* number of arguments */
if (strcmp(apid, "") == 0)
dlt_set_id(msg->extendedheader->apid, DLT_DAEMON_CTRL_APID); /* application id */
else
dlt_set_id(msg->extendedheader->apid, apid);
if (strcmp(ctid, "") == 0)
dlt_set_id(msg->extendedheader->ctid, DLT_DAEMON_CTRL_CTID); /* context id */
else
dlt_set_id(msg->extendedheader->ctid, ctid);
/* prepare length information */
msg->headersize = (uint32_t) (sizeof(DltStorageHeader) + sizeof(DltStandardHeader) + sizeof(DltExtendedHeader) +
DLT_STANDARD_HEADER_EXTRA_SIZE(msg->standardheader->htyp));
len = (int32_t) (msg->headersize - sizeof(DltStorageHeader) + msg->datasize);
if (len > UINT16_MAX) {
dlt_log(LOG_WARNING, "Huge control message discarded!\n");
return DLT_DAEMON_ERROR_UNKNOWN;
}
msg->standardheader->len = DLT_HTOBE_16(((uint16_t)len));
if ((ret =
dlt_daemon_client_send(sock, daemon, daemon_local, msg->headerbuffer, sizeof(DltStorageHeader),
msg->headerbuffer + sizeof(DltStorageHeader),
(int) (msg->headersize - sizeof(DltStorageHeader)),
msg->databuffer, (int) msg->datasize, verbose))) {
dlt_log(LOG_DEBUG, "dlt_daemon_control_send_control_message: DLT message send to all failed!.\n");
return ret;
}
return DLT_DAEMON_ERROR_OK;
}
int dlt_daemon_client_process_control(int sock,
DltDaemon *daemon,
DltDaemonLocal *daemon_local,
DltMessage *msg,
int verbose)
{
uint32_t id, id_tmp = 0;
DltStandardHeaderExtra extra;
PRINT_FUNCTION_VERBOSE(verbose);
if ((daemon == NULL) || (daemon_local == NULL) || (msg == NULL))
return -1;
if (msg->datasize < (int32_t)sizeof(uint32_t))
return -1;
extra = msg->headerextra;
/* check if the message needs to be forwarded */
if (daemon_local->flags.gatewayMode == 1) {
if (strncmp(daemon_local->flags.evalue, extra.ecu, DLT_ID_SIZE) != 0)
return dlt_gateway_forward_control_message(&daemon_local->pGateway,
daemon_local,
msg,
extra.ecu,
verbose);
}
id_tmp = *((uint32_t *)(msg->databuffer));
id = DLT_ENDIAN_GET_32(msg->standardheader->htyp, id_tmp);
if ((id > DLT_SERVICE_ID) && (id < DLT_SERVICE_ID_CALLSW_CINJECTION)) {
/* Control message handling */
switch (id) {
case DLT_SERVICE_ID_SET_LOG_LEVEL:
{
dlt_daemon_control_set_log_level(sock, daemon, daemon_local, msg, verbose);
break;
}
case DLT_SERVICE_ID_SET_TRACE_STATUS:
{
dlt_daemon_control_set_trace_status(sock, daemon, daemon_local, msg, verbose);
break;
}
case DLT_SERVICE_ID_GET_LOG_INFO:
{
dlt_daemon_control_get_log_info(sock, daemon, daemon_local, msg, verbose);
break;
}
case DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL:
{
dlt_daemon_control_get_default_log_level(sock, daemon, daemon_local, verbose);
break;
}
case DLT_SERVICE_ID_STORE_CONFIG:
{
if (dlt_daemon_applications_save(daemon, daemon->runtime_application_cfg, verbose) == 0) {
if (dlt_daemon_contexts_save(daemon, daemon->runtime_context_cfg, verbose) == 0) {
dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK,
verbose);
}
else {
/* Delete saved files */
dlt_daemon_control_reset_to_factory_default(daemon,
daemon->runtime_application_cfg,
daemon->runtime_context_cfg,
daemon_local->flags.contextLogLevel,
daemon_local->flags.contextTraceStatus,
daemon_local->flags.enforceContextLLAndTS,
verbose);
dlt_daemon_control_service_response(sock,
daemon,
daemon_local,
id,
DLT_SERVICE_RESPONSE_ERROR,
verbose);
}
}
else {
dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_ERROR,
verbose);
}
break;
}
case DLT_SERVICE_ID_RESET_TO_FACTORY_DEFAULT:
{
dlt_daemon_control_reset_to_factory_default(daemon,
daemon->runtime_application_cfg,
daemon->runtime_context_cfg,
daemon_local->flags.contextLogLevel,
daemon_local->flags.contextTraceStatus,
daemon_local->flags.enforceContextLLAndTS,
verbose);
dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose);
break;
}
case DLT_SERVICE_ID_SET_COM_INTERFACE_STATUS:
{
dlt_daemon_control_service_response(sock,
daemon,
daemon_local,
id,
DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
verbose);
break;
}
case DLT_SERVICE_ID_SET_COM_INTERFACE_MAX_BANDWIDTH:
{
dlt_daemon_control_service_response(sock,
daemon,
daemon_local,
id,
DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
verbose);
break;
}
case DLT_SERVICE_ID_SET_VERBOSE_MODE:
{
dlt_daemon_control_service_response(sock,
daemon,
daemon_local,
id,
DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
verbose);
break;
}
case DLT_SERVICE_ID_SET_MESSAGE_FILTERING:
{
dlt_daemon_control_service_response(sock,
daemon,
daemon_local,
id,
DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
verbose);
break;
}
case DLT_SERVICE_ID_SET_TIMING_PACKETS:
{
dlt_daemon_control_set_timing_packets(sock, daemon, daemon_local, msg, verbose);
break;
}
case DLT_SERVICE_ID_GET_LOCAL_TIME:
{
/* Send response with valid timestamp (TMSP) field */
dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_OK, verbose);
break;
}
case DLT_SERVICE_ID_USE_ECU_ID:
{
dlt_daemon_control_service_response(sock,
daemon,
daemon_local,
id,
DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
verbose);
break;
}
case DLT_SERVICE_ID_USE_SESSION_ID:
{
dlt_daemon_control_service_response(sock,
daemon,
daemon_local,
id,
DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
verbose);
break;
}
case DLT_SERVICE_ID_USE_TIMESTAMP:
{
dlt_daemon_control_service_response(sock,
daemon,
daemon_local,
id,
DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
verbose);
break;
}
case DLT_SERVICE_ID_USE_EXTENDED_HEADER:
{
dlt_daemon_control_service_response(sock,
daemon,
daemon_local,
id,
DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
verbose);
break;
}
case DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL:
{
dlt_daemon_control_set_default_log_level(sock, daemon, daemon_local, msg, verbose);
break;
}
case DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS:
{
dlt_daemon_control_set_default_trace_status(sock, daemon, daemon_local, msg, verbose);
break;
}
case DLT_SERVICE_ID_GET_SOFTWARE_VERSION:
{
dlt_daemon_control_get_software_version(sock, daemon, daemon_local, verbose);
break;
}
case DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW:
{
dlt_daemon_control_message_buffer_overflow(sock, daemon, daemon_local, daemon->overflow_counter, "",
verbose);
break;
}
case DLT_SERVICE_ID_OFFLINE_LOGSTORAGE:
{
dlt_daemon_control_service_logstorage(sock, daemon, daemon_local, msg, verbose);
break;
}
case DLT_SERVICE_ID_PASSIVE_NODE_CONNECT:
{
dlt_daemon_control_passive_node_connect(sock,
daemon,
daemon_local,
msg,
verbose);
break;
}
case DLT_SERVICE_ID_PASSIVE_NODE_CONNECTION_STATUS:
{
dlt_daemon_control_passive_node_connect_status(sock,
daemon,
daemon_local,
verbose);
break;
}
case DLT_SERVICE_ID_SET_ALL_LOG_LEVEL:
{
dlt_daemon_control_set_all_log_level(sock, daemon, daemon_local, msg, verbose);
break;
}
case DLT_SERVICE_ID_SET_ALL_TRACE_STATUS:
{
dlt_daemon_control_set_all_trace_status(sock, daemon, daemon_local, msg, verbose);
break;
}
default:
{
dlt_daemon_control_service_response(sock,
daemon,
daemon_local,
id,
DLT_SERVICE_RESPONSE_NOT_SUPPORTED,
verbose);
break;
}
}
}
else {
/* Injection handling */
dlt_daemon_control_callsw_cinjection(sock, daemon, daemon_local, msg, verbose);
}
return 0;
}
void dlt_daemon_control_get_software_version(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
{
DltMessage msg;
uint32_t len;
DltServiceGetSoftwareVersionResponse *resp;
PRINT_FUNCTION_VERBOSE(verbose);
if (daemon == 0)
return;
/* initialise new message */
if (dlt_message_init(&msg, 0) == DLT_RETURN_ERROR) {
dlt_daemon_control_service_response(sock,
daemon,
daemon_local,
DLT_SERVICE_ID_GET_SOFTWARE_VERSION,
DLT_SERVICE_RESPONSE_ERROR,
verbose);
return;
}
/* prepare payload of data */
len = (uint32_t) strlen(daemon->ECUVersionString);
/* msg.datasize = sizeof(serviceID) + sizeof(status) + sizeof(length) + len */
msg.datasize = (uint32_t) (sizeof(uint32_t) + sizeof(uint8_t) + sizeof(uint32_t) + len);
if (msg.databuffer && (msg.databuffersize < msg.datasize)) {
free(msg.databuffer);
msg.databuffer = 0;
}
if (msg.databuffer == 0) {
msg.databuffer = (uint8_t *)malloc(msg.datasize);
msg.databuffersize = msg.datasize;
}
if (msg.databuffer == 0) {
dlt_daemon_control_service_response(sock,
daemon,
daemon_local,
DLT_SERVICE_ID_GET_SOFTWARE_VERSION,
DLT_SERVICE_RESPONSE_ERROR,
verbose);
return;
}
resp = (DltServiceGetSoftwareVersionResponse *)msg.databuffer;
resp->service_id = DLT_SERVICE_ID_GET_SOFTWARE_VERSION;
resp->status = DLT_SERVICE_RESPONSE_OK;
resp->length = len;
memcpy(msg.databuffer + msg.datasize - len, daemon->ECUVersionString, len);
/* send message */
dlt_daemon_client_send_control_message(sock, daemon, daemon_local, &msg, "", "", verbose);
/* free message */
dlt_message_free(&msg, 0);
}
void dlt_daemon_control_get_default_log_level(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
{
DltMessage msg;
DltServiceGetDefaultLogLevelResponse *resp;
PRINT_FUNCTION_VERBOSE(verbose);
if (daemon == 0)
return;
/* initialise new message */
if (dlt_message_init(&msg, 0) == DLT_RETURN_ERROR) {
dlt_daemon_control_service_response(sock,
daemon,
daemon_local,
DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL,
DLT_SERVICE_RESPONSE_ERROR,
verbose);
return;
}
msg.datasize = sizeof(DltServiceGetDefaultLogLevelResponse);
if (msg.databuffer && (msg.databuffersize < msg.datasize)) {
free(msg.databuffer);
msg.databuffer = 0;
}
if (msg.databuffer == 0) {
msg.databuffer = (uint8_t *)malloc(msg.datasize);
msg.databuffersize = msg.datasize;
}
if (msg.databuffer == 0) {
dlt_daemon_control_service_response(sock,
daemon,
daemon_local,
DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL,
DLT_SERVICE_RESPONSE_ERROR,
verbose);
return;
}
resp = (DltServiceGetDefaultLogLevelResponse *)msg.databuffer;
resp->service_id = DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL;
resp->status = DLT_SERVICE_RESPONSE_OK;
resp->log_level = (uint8_t) daemon->default_log_level;
/* send message */
dlt_daemon_client_send_control_message(sock, daemon, daemon_local, &msg, "", "", verbose);
/* free message */
dlt_message_free(&msg, 0);
}
void dlt_daemon_control_get_log_info(int sock,
DltDaemon *daemon,
DltDaemonLocal *daemon_local,
DltMessage *msg,
int verbose)
{
DltServiceGetLogInfoRequest *req;
DltMessage resp;
DltDaemonContext *context = 0;
DltDaemonApplication *application = 0;
int num_applications = 0, num_contexts = 0;
uint16_t count_app_ids = 0, count_con_ids = 0;
#if (DLT_DEBUG_GETLOGINFO == 1)
char buf[255];
#endif
int32_t i, j;
size_t offset = 0;
char *apid = 0;
int8_t ll, ts;
uint16_t len;
int8_t value;
size_t sizecont = 0;
int offset_base;
uint32_t sid;
DltDaemonRegisteredUsers *user_list = NULL;
PRINT_FUNCTION_VERBOSE(verbose);
if ((daemon == NULL) || (msg == NULL) || (msg->databuffer == NULL))
return;
if (dlt_check_rcv_data_size(msg->datasize, sizeof(DltServiceGetLogInfoRequest)) < 0)
return;
user_list = dlt_daemon_find_users_list(daemon, daemon->ecuid, verbose);
if (user_list == NULL)
return;
/* prepare pointer to message request */
req = (DltServiceGetLogInfoRequest *)(msg->databuffer);
/* initialise new message */
if (dlt_message_init(&resp, 0) == DLT_RETURN_ERROR) {
dlt_daemon_control_service_response(sock,
daemon,
daemon_local,
DLT_SERVICE_ID_GET_LOG_INFO,
DLT_SERVICE_RESPONSE_ERROR,
verbose);
return;
}
/* check request */
if ((req->options < 3) || (req->options > 7)) {
dlt_daemon_control_service_response(sock,
daemon,
daemon_local,
DLT_SERVICE_ID_GET_LOG_INFO,
DLT_SERVICE_RESPONSE_ERROR,
verbose);
return;
}
if (req->apid[0] != '\0') {
application = dlt_daemon_application_find(daemon,
req->apid,
daemon->ecuid,
verbose);
if (application) {
num_applications = 1;
if (req->ctid[0] != '\0') {
context = dlt_daemon_context_find(daemon,
req->apid,
req->ctid,
daemon->ecuid,
verbose);
num_contexts = ((context) ? 1 : 0);
}
else {
num_contexts = application->num_contexts;
}
}
else {
num_applications = 0;
num_contexts = 0;
}
}
else {
/* Request all applications and contexts */
num_applications = user_list->num_applications;
num_contexts = user_list->num_contexts;
}
/* prepare payload of data */
/* Calculate maximum size for a response */
resp.datasize = sizeof(uint32_t) /* SID */ + sizeof(int8_t) /* status*/ + sizeof(ID4) /* DLT_DAEMON_REMO_STRING */;
sizecont = sizeof(uint32_t) /* context_id */;
/* Add additional size for response of Mode 4, 6, 7 */
if ((req->options == 4) || (req->options == 6) || (req->options == 7))
sizecont += sizeof(int8_t); /* log level */
/* Add additional size for response of Mode 5, 6, 7 */
if ((req->options == 5) || (req->options == 6) || (req->options == 7))
sizecont += sizeof(int8_t); /* trace status */
resp.datasize += (uint32_t) (((uint32_t) num_applications * (sizeof(uint32_t) /* app_id */ + sizeof(uint16_t) /* count_con_ids */)) +
((size_t) num_contexts * sizecont));
resp.datasize += (uint32_t) sizeof(uint16_t) /* count_app_ids */;
/* Add additional size for response of Mode 7 */
if (req->options == 7) {
if (req->apid[0] != '\0') {
if (req->ctid[0] != '\0') {
/* One application, one context */
/* context = dlt_daemon_context_find(daemon, req->apid, req->ctid, verbose); */
if (context) {
resp.datasize += (uint32_t) sizeof(uint16_t) /* len_context_description */;
if (context->context_description != 0)
resp.datasize += (uint32_t) strlen(context->context_description); /* context_description */
}