-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
xcpdissect.c
1688 lines (1612 loc) · 53.3 KB
/
xcpdissect.c
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: (GPL-2.0-only OR BSD-3-Clause) */
/*
* xcpdump.c - dump and explain ASAM MC-1 XCP protocol CAN frames
*
* Copyright (c) 2021 Christoph Schueler
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Volkswagen nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* Alternatively, provided that this notice is retained in full, this
* software may be distributed under the terms of the GNU General
* Public License ("GPL") version 2, in which case the provisions of the
* GPL apply INSTEAD OF those given above.
*
* The provided data structures and external interfaces from this code
* are not restricted to be used by modules with a GPL compatible license.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* Send feedback to <[email protected]>
*
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <linux/can.h>
#include "xcp.h"
/*
*
* Local Function-like Macros.
*
*/
/*
* Get n-th byte from CAN frame.
*
* Note: By convention, this function-like macro requires a variable called `msg` of type `XcpMessage`.
*/
#define MSG_BYTE(n) (msg->frame->data[(n)])
#define MSG_FRAME_LEN() (msg->frame->len)
#define MSG_BOOL(idx, mask) ((MSG_BYTE((idx)) & (mask)) ? "TRUE" : "FALSE")
#define MSG_WORD(idx) (XCP_MAKEWORD(MSG_BYTE((idx) + 1), MSG_BYTE((idx))))
#define MSG_DWORD(idx) (XCP_MAKEDWORD( \
XCP_MAKEWORD(MSG_BYTE((idx) + 3), MSG_BYTE((idx) + 2)), \
XCP_MAKEWORD(MSG_BYTE((idx) + 1), MSG_BYTE((idx))) \
))
#if !defined(XCP_LOBYTE)
#define XCP_LOBYTE(w) ((uint8_t)((w) & (uint8_t)0xff)) /**< Get the low-byte from a word. */
#endif
#if !defined(XCP_HIBYTE)
#define XCP_HIBYTE(w) ((uint8_t)(((w) & (uint16_t)0xff00) >> 8)) /**< Get the high-byte from a word. */
#endif
#if !defined(XCP_LOWORD)
#define XCP_LOWORD(w) ((uint16_t)((w) & (uint16_t)0xffff)) /**< Get the low-word from a double-word. */
#endif
#if !defined(XCP_HIWORD)
#define XCP_HIWORD(w) ((uint16_t)(((w) & (uint32_t)0xffff0000) >> 16)) /**< Get the high-word from a doubleword. */
#endif
#if !defined(XCP_MAKEWORD)
#define XCP_MAKEWORD(h, l) ((((uint16_t)((h) & ((uint8_t)0xff))) << (uint16_t)8) | ((uint16_t)((l) & ((uint8_t)0xff)))) /**< Make word from high and low bytes. */
#endif
#if !defined(XCP_MAKEDWORD)
#define XCP_MAKEDWORD(h, l) ((((uint32_t)((h) & ((uint16_t)0xffffu))) << (uint32_t)16) | ((uint32_t)((l) & ((uint16_t)0xffffu)))) /**< Make double-word from high and low words. */
#endif
/*
*
* Local Types.
*
*/
typedef struct tagGetSegmentInfoRequestType {
uint8_t mode;
uint8_t segmentInfo;
uint8_t mappingIndex;
} GetSegmentInfoRequestType;
/*
*
* Local Variables.
*
*/
static GetSegmentInfoRequestType getSegmentInfoRequest;
static uint8_t get_sector_info_mode;
static bool include_dtos = FALSE;
static CanIdType CanIds;
/*
* To dissect positive responses we need to know what was requested.
*/
static uint8_t service_request = 0;
/*
*
* Local Functions.
*
*/
static void hexdump_xcp_message(XcpMessage const * const msg, uint16_t offset);
#if 0
static void hexdump(uint8_t * data, size_t size);
#endif
static void print_xcp_request(XcpMessage const * const msg);
static void print_xcp_response(XcpMessage const * const msg);
static void print_xcp_positive_response(XcpMessage const * const msg);
static uint16_t print_requested_service(XcpMessage const * const msg);
static void print_resources(uint8_t res, uint8_t variant);
static void print_comm_mode_basic(uint8_t mode);
static void print_current_session_status(uint8_t status);
static void print_set_cal_page_mode(uint8_t mode);
static void print_checksum_method(uint8_t meth);
static void print_get_pag_processor_info(uint8_t properties);
static void print_get_page_info(uint8_t properties);
static void print_segment_mode(uint8_t mode);
static void print_daq_list_mode(uint8_t mode);
static void print_daq_properties(uint8_t properties);
static void print_daq_key_byte(uint8_t key);
static void print_daq_timestamp_mode(uint8_t mode);
static void print_daq_get_list_mode(uint8_t mode);
static void print_daq_event_properties(uint8_t properties);
static void print_event_channel_time_unit(uint8_t unit);
static void print_daq_list_properties(uint8_t properties);
static void print_pgm_comm_mode(uint8_t mode);
static void print_pgm_properties(uint8_t properties);
static void print_event(XcpMessage const * const msg);
void setIdentifiers(CanIdType const * const ids)
{
memcpy(&CanIds, ids, sizeof(CanIdType));
}
#if 0
/*
* Plain HexDumper
*
*/
static void hexdump(uint8_t * data, size_t size)
{
for (int i = 0; i < size; i++) {
printf("0x%02x ", data[i]);
}
}
#endif
/*
* Main entry point of this module.
*
* Just differentiate between requests and responses.
*
*/
void print_xcp_message(XcpMessage const * const msg, bool dtos)
{
include_dtos = dtos;
if (msg->frame->can_id == CanIds.src) {
print_xcp_request(msg);
} else if (msg->frame->can_id == CanIds.dst) {
print_xcp_response(msg);
} else {
hexdump_xcp_message(msg, 0);
}
}
/*
* Print message content as HEX bytes.
*
*/
static void hexdump_xcp_message(XcpMessage const * const msg, uint16_t offset)
{
unsigned idx;
if ((msg->frame->len - offset) == 0) {
return;
}
printf("[ ");
for (idx = offset; idx < msg->frame->len; ++idx) {
printf("%02X ", MSG_BYTE(idx));
}
printf("]");
}
static void print_xcp_request(XcpMessage const * const msg)
{
uint16_t idx;
service_request = MSG_BYTE(0);
idx = print_requested_service(msg);
hexdump_xcp_message(msg, idx);
printf(")");
}
static void print_xcp_response(XcpMessage const * const msg)
{
uint8_t code = MSG_BYTE(0);
uint16_t idx;
printf("<- ");
switch (code) {
case 0xff: /* Positive Response */
printf("OK");
print_xcp_positive_response(msg);
break;
case 0xfe: /* Error */
idx = 2;
printf("ERROR(");
switch (MSG_BYTE(1)) {
case ERR_CMD_SYNCH:
printf("CMD_SYNCH");
break;
case ERR_CMD_BUSY:
printf("CMD_BUSY");
break;
case ERR_DAQ_ACTIVE:
printf("DAQ_ACTIVE");
break;
case ERR_PGM_ACTIVE:
printf("PGM_ACTIVE");
break;
case ERR_CMD_UNKNOWN:
printf("CMD_UNKNOWN");
break;
case ERR_CMD_SYNTAX:
printf("CMD_SYNTAX");
break;
case ERR_OUT_OF_RANGE:
printf("OUT_OF_RANGE");
break;
case ERR_WRITE_PROTECTED:
printf("WRITE_PROTECTED");
break;
case ERR_ACCESS_DENIED:
printf("ACCESS_DENIED");
break;
case ERR_ACCESS_LOCKED:
printf("ACCESS_LOCKED");
break;
case ERR_PAGE_NOT_VALID:
printf("PAGE_NOT_VALID");
break;
case ERR_MODE_NOT_VALID:
printf("MODE_NOT_VALID");
break;
case ERR_SEGMENT_NOT_VALID:
printf("SEGMENT_NOT_VALID");
break;
case ERR_SEQUENCE:
printf("SEQUENCE");
break;
case ERR_DAQ_CONFIG:
printf("DAQ_CONFIG");
break;
case ERR_MEMORY_OVERFLOW:
printf("MEMORY_OVERFLOW");
break;
case ERR_GENERIC:
printf("GENERIC");
break;
case ERR_VERIFY:
printf("VERIFY");
break;
case ERR_RESOURCE_TEMPORARY_NOT_ACCESSIBLE:
printf("RESOURCE_TEMPORARY_NOT_ACCESSIBLE");
break;
case ERR_SUCCESS:
printf("SUCCESS");
break;
default:
idx = 1;
break;
}
hexdump_xcp_message(msg, idx);
printf(")");
break;
case 0xfd: /* Event */
print_event(msg);
break;
case 0xfc: /* Service Request */
printf("SERVICE REQ");
/* TODO: service_request-request-code @pos #1 */
hexdump_xcp_message(msg, 1);
break;
default:
printf("DTO(pid = %u, ", code); /* we assume absolute ODT number in case of CAN. */
hexdump_xcp_message(msg, 1);
printf(")");
break;
}
service_request = 0;
}
static void print_event(XcpMessage const * const msg)
{
uint8_t event_id = MSG_BYTE(1);
uint16_t idx = 2;
uint8_t event_type = MSG_BYTE(2);
uint16_t event_channel = MSG_WORD(4);
uint16_t session_id = MSG_WORD(2);
uint32_t timestamp = MSG_DWORD(4);
printf("EVENT(id = ");
switch (event_id) {
case XCP_EV_RESUME_MODE:
printf("EV_RESUME_MODE, sessionConfigurationId = %u, timestamp = %u", session_id, timestamp);
idx = 8;
break;
case XCP_EV_CLEAR_DAQ:
printf("EV_CLEAR_DAQ");
break;
case XCP_EV_STORE_DAQ:
printf("EV_STORE_DAQ");
break;
case XCP_EV_STORE_CAL:
printf("EV_STORE_CAL");
break;
case XCP_EV_CMD_PENDING:
printf("EV_CMD_PENDING");
break;
case XCP_EV_DAQ_OVERLOAD:
printf("EV_DAQ_OVERLOAD");
break;
case XCP_EV_SESSION_TERMINATED:
printf("EV_SESSION_TERMINATED");
break;
case XCP_EV_TIME_SYNC:
printf("EV_TIME_SYNC, timestamp = %u", timestamp);
break;
case XCP_EV_STIM_TIMEOUT:
printf("EV_STIM_TIMEOUT, eventType = %s, eventChannel =%u",
event_type == 0 ? "EVENT_CHANNEL_NUMBER" : (event_type == 1 ? "DAQ LIST NUMBER" : "INVALID"),
event_channel
);
idx = 6;
break;
case XCP_EV_SLEEP:
printf("EV_SLEEP");
break;
case XCP_EV_WAKE_UP:
printf("EV_WAKE_UP");
break;
case XCP_EV_USER:
printf("EV_USER");
break;
case XCP_EV_TRANSPORT:
printf("EV_TRANSPORT");
break;
default:
printf("0x%0x ", event_id);
break;
}
hexdump_xcp_message(msg, idx);
printf(")");
}
static uint16_t print_requested_service(XcpMessage const * const msg)
{
uint16_t idx = 1;
uint8_t service = MSG_BYTE(0);
//static uint32_t counter = 0;
//printf("\t\tRequ: %u [%u]\n", service_request,counter );
//counter++;
printf("-> ");
switch (service) {
case CONNECT:
printf("CONNECT(mode = ");
if (MSG_BYTE(1) == 0x00) {
printf("NORMAL");
} else if (MSG_BYTE(1) == 0x01) {
printf("USER_DEFINED");
}
idx = 2;
break;
case DISCONNECT:
printf("DISCONNECT(");
break;
case GET_STATUS:
printf("GET_STATUS(");
break;
case SYNCH:
printf("SYNCH(");
break;
case GET_COMM_MODE_INFO:
printf("GET_COMM_MODE_INFO(");
break;
case GET_ID:
printf("GET_ID(");
printf("requestedIdentificationType = %u", MSG_BYTE(1));
idx = 2;
break;
case SET_REQUEST:
printf("SET_REQUEST(");
printf("mode = {");
printf("clearDaqReq = %s", MSG_BOOL(1, XCP_CLEAR_DAQ_REQ));
printf(", storeDaqReqResume = %s", MSG_BOOL(1, XCP_STORE_DAQ_REQ_RESUME));
printf(", storeDaqReqNoResume = %s", MSG_BOOL(1, XCP_STORE_DAQ_REQ_NO_RESUME));
printf(", storeCalReq = %s", MSG_BOOL(1, XCP_STORE_CAL_REQ));
printf("}");
printf(", sessionConfigurationId = %u", MSG_WORD(2));
idx = 3;
break;
case GET_SEED:
printf("GET_SEED(");
printf("mode = \"%s\"", (MSG_BYTE(1) == 0) ? "first part of seed" : "remaining part of seed");
printf(", \"%s\"", (MSG_BYTE(2) == 0) ? "Resource" : "Dont care");
idx = 3;
break;
case UNLOCK:
printf("UNLOCK(");
printf("length = %u, key: ", MSG_BYTE(1));
idx = 2;
break;
case SET_MTA:
printf("SET_MTA(");
printf("address = 0x%08x", MSG_DWORD(4));
printf(", addressExtension = 0x%02x", MSG_BYTE(3));
idx = 8;
break;
case UPLOAD:
printf("UPLOAD(");
printf("numberOfDataElements = %u", MSG_BYTE(1));
idx = 2;
break;
case SHORT_UPLOAD:
printf("SHORT_UPLOAD(");
printf("numberOfDataElements = %u", MSG_BYTE(1));
printf("address = 0x%08x", MSG_DWORD(4));
printf(", addressExtension = 0x%02x", MSG_BYTE(3));
idx = 8;
break;
case BUILD_CHECKSUM:
printf("BUILD_CHECKSUM(");
printf("blockSize = 0x%08x ", MSG_DWORD(4));
idx = 8;
break;
case TRANSPORT_LAYER_CMD:
printf("TRANSPORT_LAYER_CMD(");
printf("subCommandCode = %u", MSG_BYTE(1));
printf("parameters: ");
hexdump_xcp_message(msg, 2);
idx = 8;
case USER_CMD:
printf("USER_CMD(");
printf("subCommandCode = %u", MSG_BYTE(1));
printf("parameters: ");
hexdump_xcp_message(msg, 2);
idx = 8;
case DOWNLOAD:
printf("DOWNLOAD(");
printf("numberOfDataElements = %u", MSG_BYTE(1));
printf(", elements: ");
hexdump_xcp_message(msg, 2);
idx = 8;
break;
case DOWNLOAD_NEXT:
printf("DOWNLOAD_NEXT(");
printf("numberOfDataElements = %u", MSG_BYTE(1));
printf(", elements: ");
hexdump_xcp_message(msg, 2);
idx = 8;
break;
case DOWNLOAD_MAX:
printf("DOWNLOAD_MAX(");
printf("elements: ");
hexdump_xcp_message(msg, 1);
idx = 8;
break;
case SHORT_DOWNLOAD:
printf("SHORT_DOWNLOAD(");
printf("numberOfDataElements = %u", MSG_BYTE(1));
printf(", address = 0x%08x", MSG_DWORD(4));
printf(", addressExtension = 0x%02x", MSG_BYTE(3));
if (MSG_FRAME_LEN()) {
printf("elements: ");
hexdump_xcp_message(msg, 8); /* In case of CAN-FD */
}
idx = 8;
break;
case MODIFY_BITS:
printf("MODIFY_BITS(");
printf("shiftValue = %u", MSG_BYTE(1));
printf(", andMask = 0x%04x", MSG_WORD(2));
printf(", xorMask = 0x%04x", MSG_WORD(4));
idx = 6;
break;
case SET_CAL_PAGE:
printf("SET_CAL_PAGE(");
print_set_cal_page_mode(MSG_BYTE(1));
printf(", logicalDataSegmentNumber = %u", MSG_BYTE(2));
printf(", logicalDataPageNumber = %u", MSG_BYTE(3));
idx = 4;
break;
case GET_CAL_PAGE:
printf("GET_CAL_PAGE(");
printf(", logicalDataPageNumber = %u", MSG_BYTE(3));
idx = 4;
break;
case GET_PAG_PROCESSOR_INFO:
printf("GET_PAG_PROCESSOR_INFO(");
break;
case GET_SEGMENT_INFO:
printf("GET_SEGMENT_INFO(");
getSegmentInfoRequest.mode = MSG_BYTE(1);
printf("mode = ");
if (getSegmentInfoRequest.mode == 0) {
printf("0 [\"get basic address info for this SEGMENT\"]");
} else if (getSegmentInfoRequest.mode == 1) {
printf("1 [\"get standard info for this SEGMENT\"]");
} else if (getSegmentInfoRequest.mode == 2) {
printf("2 [\"get address mapping info for this SEGMENT\"]");
} else {
printf("%u [\"*** INVALID ***\"]", getSegmentInfoRequest.mode);
}
printf(", segmentNumber = %u", MSG_BYTE(2));
getSegmentInfoRequest.segmentInfo = MSG_BYTE(3);
if (getSegmentInfoRequest.mode == 0) {
printf(", segmentInfo = \"%s\"", (getSegmentInfoRequest.segmentInfo == 0) ? "address" : "length");
} else if (getSegmentInfoRequest.mode == 2) {
printf(", segmentInfo = \"%s\"", (getSegmentInfoRequest.segmentInfo == 0) ? "sourceAddress" :
(getSegmentInfoRequest.segmentInfo == 1) ? "destinationAddress" : "lengthAddress"
);
}
if (getSegmentInfoRequest.mode == 2) {
printf(", mappingIndex = %u [\"identifier for address mapping range that MAPPING_INFO belongs to\"]", MSG_BYTE(4));
}
idx = 5;
break;
case GET_PAGE_INFO:
printf("GET_PAGE_INFO(");
printf("segmentNumber = %u", MSG_BYTE(2));
printf(", pageNumber = %u", MSG_BYTE(3));
break;
case SET_SEGMENT_MODE:
printf("SET_SEGMENT_MODE(");
print_segment_mode(MSG_BYTE(1));
printf(", segmentNumber = %u", MSG_BYTE(2));
break;
case GET_SEGMENT_MODE:
printf("GET_SEGMENT_MODE(");
printf(", segmentNumber = %u", MSG_BYTE(2));
break;
case COPY_CAL_PAGE:
printf("COPY_CAL_PAGE(");
printf("logicalDataSegmentNumberSource= %u", MSG_BYTE(1));
printf(", logicalDataPageNumberSource = %u", MSG_BYTE(2));
printf(", logicalDataSegmentNumberDestination = %u", MSG_BYTE(3));
printf(", logicalDataPageNumberDestination = %u", MSG_BYTE(4));
break;
case CLEAR_DAQ_LIST:
printf("CLEAR_DAQ_LIST(");
printf("daqListNumber = %u", MSG_WORD(2));
break;
case SET_DAQ_PTR:
printf("SET_DAQ_PTR(");
printf("daqListNumber = %u", MSG_WORD(2));
printf(", odtNumber = %u", MSG_BYTE(4));
printf(", odtEntryNumber = %u", MSG_BYTE(5));
break;
case WRITE_DAQ:
printf("WRITE_DAQ(");
printf("bitOffset = %u", MSG_BYTE(1));
printf(", sizeofElement = %u", MSG_BYTE(2));
printf(", addressExtension = %u", MSG_BYTE(3));
printf(", adddress = 0x%08x", MSG_DWORD(4));
break;
case SET_DAQ_LIST_MODE:
printf("SET_DAQ_LIST_MODE(");
print_daq_list_mode(MSG_BYTE(1));
printf(" , daqListNumber = %u", MSG_WORD(2));
printf(" , eventChannelNumber = %u", MSG_WORD(4));
printf(" , transmissionRatePrescaler = %u", MSG_WORD(6));
printf(" , daqListPriority = %u", MSG_BYTE(7));
break;
case GET_DAQ_LIST_MODE:
printf("GET_DAQ_LIST_MODE(");
printf("daqListNumber = %u", MSG_WORD(2));
idx = 4;
break;
case START_STOP_DAQ_LIST:
printf("START_STOP_DAQ_LIST(");
printf("mode = ");
switch (MSG_BYTE(1)) {
case 0:
printf("STOP");
break;
case 1:
printf("START");
break;
case 2:
printf("SELECT");
break;
default:
break;
}
printf(", daqListNumber = %u", MSG_WORD(2));
break;
case START_STOP_SYNCH:
printf("START_STOP_SYNCH(");
printf("mode = ");
switch (MSG_BYTE(1)) {
case 0:
printf("STOP_ALL");
break;
case 1:
printf("START_SELECTED");
break;
case 2:
printf("STOP_SELECTED");
break;
default:
break;
}
break;
case GET_DAQ_CLOCK:
printf("GET_DAQ_CLOCK(");
break;
case READ_DAQ:
printf("READ_DAQ(");
break;
case GET_DAQ_PROCESSOR_INFO:
printf("GET_DAQ_PROCESSOR_INFO(");
break;
case GET_DAQ_RESOLUTION_INFO:
printf("GET_DAQ_RESOLUTION_INFO(");
break;
case GET_DAQ_LIST_INFO:
printf("GET_DAQ_LIST_INFO(");
printf("daqListNumber = %u", MSG_WORD(2));
idx = 4;
break;
case GET_DAQ_EVENT_INFO:
printf("GET_DAQ_EVENT_INFO(");
printf("eventChannelNumber = %u", MSG_WORD(2));
idx = 4;
break;
case FREE_DAQ:
printf("FREE_DAQ(");
break;
case ALLOC_DAQ:
printf("ALLOC_DAQ(");
printf("daqCount = %u", MSG_WORD(2));
idx = 4;
break;
case ALLOC_ODT:
printf("ALLOC_ODT(");
printf("daqListNumber = %u", MSG_WORD(2));
printf(", odtCount = %u", MSG_WORD(4));
idx = 6;
break;
case ALLOC_ODT_ENTRY:
printf("ALLOC_ODT_ENTRY(");
printf("daqListNumber = %u", MSG_WORD(2));
printf(", odtNumber = %u", MSG_BYTE(4));
printf(", odtEntriesCount = %u", MSG_BYTE(5));
idx = 7;
break;
case PROGRAM_START:
printf("PROGRAM_START(");
break;
case PROGRAM_CLEAR:
printf("PROGRAM_CLEAR(");
printf("accessMode = ");
switch (MSG_BYTE(1)) {
case 0:
printf("ABSOLUTE");
break;
case 1:
printf("FUNCTIONAL");
break;
default:
printf("\"INVALID\"");
break;
}
printf(", clearRange = %u", MSG_DWORD(4));
break;
case PROGRAM:
printf("PROGRAM(");
printf("numberOfDataElements = %u", MSG_BYTE(1));
printf(", elements: ");
hexdump_xcp_message(msg, 2);
idx = 8;
break;
case PROGRAM_RESET:
printf("PROGRAM_RESET(");
break;
case GET_PGM_PROCESSOR_INFO:
printf("GET_PGM_PROCESSOR_INFO(");
break;
case GET_SECTOR_INFO:
printf("GET_SECTOR_INFO(");
printf("mode = ");
get_sector_info_mode = MSG_BYTE(1);
switch (MSG_BYTE(1)) {
case 0:
printf("\"get start address for this SECTOR\"");
break;
case 1:
printf("\"get length of this SECTOR[bytes]\"");
break;
case 2:
printf("\"get name length of this SECTOR\"");
break;
default:
break;
}
printf(", sectorNumber = %u", MSG_BYTE(2));
break;
case PROGRAM_PREPARE:
printf("PROGRAM_PREPARE(");
printf("Codesize[AG] = %u", MSG_WORD(2));
break;
case PROGRAM_FORMAT:
printf("PROGRAM_FORMAT(");
printf("compressionMethod = %u", MSG_BYTE(1));
printf(", encryptionMethod = %u", MSG_BYTE(2));
printf(", programmingMethod = %u", MSG_BYTE(3));
printf(", accessMethod = %u", MSG_BYTE(4));
break;
case PROGRAM_NEXT:
printf("PROGRAM_NEXT(");
printf("numberOfDataElements = %u", MSG_BYTE(1));
printf(", elements: ");
hexdump_xcp_message(msg, 2);
idx = 8;
break;
case PROGRAM_MAX:
printf("PROGRAM_MAX(");
printf("elements: ");
hexdump_xcp_message(msg, 1);
idx = 8;
break;
case PROGRAM_VERIFY:
printf("PROGRAM_VERIFY(");
printf("verificationMode = \"");
if (MSG_BYTE(1) == 0) {
printf("request to start internal routine");
} else if (MSG_BYTE(1) == 1) {
printf("sending Verification Value");
}
printf("\"");
printf(", verificationType = %u", MSG_WORD(2));
printf(", verificationValue = %u", MSG_DWORD(4));
break;
case WRITE_DAQ_MULTIPLE:
printf("WRITE_DAQ_MULTIPLE(");
printf("elements = [");
for (uint8_t idx = 0; idx < MSG_BYTE(1); ++idx) {
printf("{");
printf("bitOffset = %u", MSG_BYTE((idx * 8) + 2));
printf(", sizeofElement = %u", MSG_BYTE((idx * 8) + 3));
printf(", adddress = 0x%08x", MSG_DWORD((idx * 8) + 4));
printf(", addressExtension = %u", MSG_BYTE((idx * 8) + 8));
printf("}, ");
}
printf("]");
break;
case TIME_CORRELATION_PROPERTIES:
printf("TIME_CORRELATION_PROPERTIES(");
break;
case DTO_CTR_PROPERTIES:
printf("DTO_CTR_PROPERTIES(");
break;
#if 0
case 0xC002:
printf("GET_DAQ_PACKED_MODE(");
break;
case 0xC001:
printf("SET_DAQ_PACKED_MODE(");
break;
case 0xC000:
printf("GET_VERSION(");
break;
#endif
default:
break;
}
return idx;
}
static void print_xcp_positive_response(XcpMessage const * const msg)
{
switch (service_request) {
case CONNECT:
printf("(");
print_resources(MSG_BYTE(1), 0);
printf(", ");
print_comm_mode_basic(MSG_BYTE(2));
printf(", maxCto = %d", MSG_BYTE(3));
printf(", maxDto = %d", XCP_MAKEWORD(MSG_BYTE(5), MSG_BYTE(4)));
printf(", protocolLayerVersion = %d.%d", MSG_BYTE(6), MSG_BYTE(7));
printf(")");
break;
case GET_STATUS:
printf("(");
print_current_session_status(MSG_BYTE(1));
printf(", ");
print_resources(MSG_BYTE(2), 1);
printf(", ");
printf("sessionConfigurationId = %d", XCP_MAKEWORD(MSG_BYTE(5), MSG_BYTE(4)));
printf(")");
break;
case GET_COMM_MODE_INFO:
printf("(");
printf("commModeOptional = {");
printf("masterBlockMode = %s", MSG_BOOL(2, XCP_MASTER_BLOCK_MODE));
printf(", interleavedMode = %s", MSG_BOOL(2, XCP_INTERLEAVED_MODE));
printf("}");
printf(", maxBs = %u", MSG_BYTE(4));
printf(", minSt = %u", MSG_BYTE(5));
printf(", queueSize = %u", MSG_BYTE(6));
printf(", XCPDriverVersion = %u.%u", (MSG_BYTE(7) & 0xf0) >> 8, MSG_BYTE(7) & 0x0f);
printf(")");
break;
case GET_ID:
printf("(");
printf("mode = {");
printf("compressedEncrypted = %s", MSG_BOOL(1, XCP_COMPRESSED_ENCRYPTED));
printf(", transferMode = %s", MSG_BOOL(1, XCP_TRANSFER_MODE));
printf("}");
printf(", length = %u", XCP_MAKEDWORD(
XCP_MAKEWORD(MSG_BYTE(7), MSG_BYTE(6)),
XCP_MAKEWORD(MSG_BYTE(5), MSG_BYTE(4))
));
if (MSG_FRAME_LEN()) {
hexdump_xcp_message(msg, 8); /* In case of CAN-FD */
}
printf(")");
break;
case GET_SEED:
printf("(");
printf("length = %u", MSG_BYTE(1));
printf(", seed: ");
hexdump_xcp_message(msg, 2);
printf(")");
break;
case UNLOCK:
printf("(");
print_resources(MSG_BYTE(1), 1);
printf(")");
break;
case UPLOAD:
printf("(");
printf("elements: ");
hexdump_xcp_message(msg, 1);
printf(")");
break;
case BUILD_CHECKSUM:
printf("(");
print_checksum_method(MSG_BYTE(1));
printf(", checksum = 0x%08x", MSG_DWORD(4));
printf(")");
break;
case TRANSPORT_LAYER_CMD:
printf("(");
hexdump_xcp_message(msg, 1);
printf(")");
break;
case GET_PAG_PROCESSOR_INFO:
printf("(");
printf("maxSegment = %u, ", MSG_BYTE(1));
print_get_pag_processor_info(MSG_BYTE(2));
printf(")");
case GET_SEGMENT_INFO:
printf("(");
if (getSegmentInfoRequest.mode == 0) {
if (getSegmentInfoRequest.segmentInfo == 0) {
printf("address = 0x%08x", MSG_DWORD(4));
} else if (getSegmentInfoRequest.segmentInfo == 1) {
printf("length = %u", MSG_DWORD(4));
}
} else if (getSegmentInfoRequest.mode == 1) {
printf("maxPages = %u", MSG_BYTE(1));
printf(", addressExtension = %u", MSG_BYTE(2));
printf(", maxMapping = %u", MSG_BYTE(3));
printf(", compressionMethod = %u", MSG_BYTE(4));
printf(", encryptionMethod = %u", MSG_BYTE(5));
} else if (getSegmentInfoRequest.mode == 2) {
if (getSegmentInfoRequest.segmentInfo == 0) {
printf(", sourceAddress = 0x%08x", MSG_DWORD(4));
} else if (getSegmentInfoRequest.segmentInfo == 1) {
printf(", destinationAddress = 0x%08x", MSG_DWORD(4));
} else if (getSegmentInfoRequest.segmentInfo == 2) {
printf(", length = %u", MSG_DWORD(4));
}
}
printf(")");
case GET_PAGE_INFO:
printf("(");
print_get_page_info(MSG_BYTE(1));
printf(", initSegment = %u", MSG_BYTE(2));
printf(")");
case GET_SEGMENT_MODE:
printf("(");
print_segment_mode(MSG_BYTE(2));
printf(")");
break;
case START_STOP_DAQ_LIST:
printf("(");
printf("firstPID = %u", MSG_BYTE(1));
printf(")");
break;
case GET_DAQ_CLOCK:
printf("(");
printf("timestamp = %u", MSG_WORD(4));
printf(")");
break;
case GET_DAQ_PROCESSOR_INFO:
printf("(");
print_daq_properties(MSG_BYTE(1));
printf(", minDaq = %u", MSG_BYTE(6));
printf(", maxDaq = %u", MSG_WORD(2));
printf(", maxEventChannel = %u", MSG_WORD(4));
printf(", ");
print_daq_key_byte(MSG_BYTE(7));
printf(")");
break;
case GET_DAQ_RESOLUTION_INFO:
printf("(");
printf("granularityOdtEntrySizeDaq = %u", MSG_BYTE(1));
printf(", maxOdtEntrySizeDaq = %u", MSG_BYTE(2));
printf(", granularityOdtEntrySizeStim = %u", MSG_BYTE(3));
printf(", maxOdtEntrySizeStim = %u", MSG_BYTE(4));
printf(", ");
print_daq_timestamp_mode(MSG_BYTE(5));
printf(", timestampTicks = %u", MSG_BYTE(6));
printf(")");
break;
case GET_DAQ_LIST_MODE:
printf("(");
print_daq_get_list_mode(MSG_BYTE(1));
printf(", currentEventChannelNumber = %u", MSG_WORD(4));
printf(", currentPrescaler = %u", MSG_BYTE(6));
printf(", currentDaqListPriority = %u", MSG_BYTE(7));
printf(")");
break;
case GET_DAQ_EVENT_INFO:
printf("(");
print_daq_event_properties(MSG_BYTE(1));
printf(", maxDaqList = %u", MSG_BYTE(2));
printf(", channelNameLength = %u", MSG_BYTE(3));
printf(", channelTimeCycle = ");
if (MSG_BYTE(4) == 0) {
printf("\"not cyclic\"");
printf(", channelTimeUnit = \"N/A\"");
} else {
printf("%u", MSG_BYTE(4));
}
if (MSG_BYTE(4) != 0) {
printf(", ");
print_event_channel_time_unit(MSG_BYTE(5));
}
printf(", channelPriority = %u", MSG_BYTE(6));
printf(")");
break;
case GET_DAQ_LIST_INFO:
printf("(");
print_daq_list_properties(MSG_BYTE(1));