3 * By Dr. Lars Voelker <lars.voelker@technica-engineering.de>
4 * Copyright 2022-2022 Dr. Lars Voelker
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
12 * This dissector allows to parse DLT files.
16 * Sources for specification:
17 * https://www.autosar.org/fileadmin/standards/classic/21-11/AUTOSAR_SWS_DiagnosticLogAndTrace.pdf
18 * https://www.autosar.org/fileadmin/standards/foundation/1-3/AUTOSAR_PRS_LogAndTraceProtocol.pdf
19 * https://github.com/COVESA/dlt-viewer
24 #include <epan/packet.h>
25 #include <wsutil/array.h>
29 static int hf_dlt_file_magic
;
30 static int hf_dlt_file_tstamp_s
;
31 static int hf_dlt_file_tstamp_us
;
32 static int hf_dlt_file_ecuid
;
34 static int hf_dlt_file_header_type
;
35 static int hf_dlt_file_message_counter
;
36 static int hf_dlt_file_length
;
37 static int hf_dlt_file_data
;
40 static int ett_dlt_item
;
42 void proto_register_file_dlt(void);
43 void proto_reg_handoff_file_dlt(void);
45 #define MAGIC_NUMBER_SIZE 4
46 static const uint8_t dlt_file_magic
[MAGIC_NUMBER_SIZE
] = { 'D', 'L', 'T', 0x01 };
49 dissect_dlt(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
) {
50 volatile int offset
= 0;
52 proto_tree
*item_tree
;
57 if (tvb_captured_length(tvb
) < 16 || tvb_memeql(tvb
, 0, dlt_file_magic
, MAGIC_NUMBER_SIZE
) != 0) {
58 /* does not start with DLT\x1, so this is not DLT it seems */
62 ti
= proto_tree_add_item(tree
, proto_dlt
, tvb
, offset
, -1, ENC_NA
);
63 dlt_tree
= proto_item_add_subtree(ti
, ett_dlt
);
65 int tvb_length
= tvb_captured_length(tvb
);
67 while (offset
+ 20 <= tvb_length
) {
68 item_tree
= proto_tree_add_subtree_format(dlt_tree
, tvb
, offset
, -1, ett_dlt_item
, &ti_item
, "DLT Log Line");
69 proto_tree_add_item(item_tree
, hf_dlt_file_magic
, tvb
, offset
, 4, ENC_ASCII
| ENC_NA
);
72 uint32_t tstamp_s
= 0;
73 proto_tree_add_item_ret_uint(item_tree
, hf_dlt_file_tstamp_s
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
, &tstamp_s
);
76 uint32_t tstamp_us
= 0;
77 proto_tree_add_item_ret_uint(item_tree
, hf_dlt_file_tstamp_us
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
, &tstamp_us
);
81 proto_tree_add_item_ret_string(item_tree
, hf_dlt_file_ecuid
, tvb
, offset
, 4, ENC_ASCII
| ENC_NA
, pinfo
->pool
, &ecuid
);
84 proto_tree_add_item(item_tree
, hf_dlt_file_header_type
, tvb
, offset
, 1, ENC_NA
);
88 proto_tree_add_item_ret_uint(item_tree
, hf_dlt_file_message_counter
, tvb
, offset
, 1, ENC_NA
, &counter
);
91 proto_tree_add_item_ret_uint(item_tree
, hf_dlt_file_length
, tvb
, offset
, 2, ENC_BIG_ENDIAN
, &len
);
94 proto_tree_add_item(item_tree
, hf_dlt_file_data
, tvb
, offset
, len
- 4, ENC_NA
);
97 proto_item_set_end(ti_item
, tvb
, offset
);
98 proto_item_append_text(ti_item
, " %3u %u.%06u ECU:%s Len:%u", counter
, tstamp_s
, tstamp_us
, ecuid
, len
);
105 dissect_dlt_heur(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data
) {
106 return dissect_dlt(tvb
, pinfo
, tree
, data
) > 0;
110 proto_register_file_dlt(void) {
111 static hf_register_info hf
[] = {
112 { &hf_dlt_file_magic
,
113 { "Magic", "file-dlt.magic", FT_STRING
, BASE_NONE
, NULL
, 0x00, NULL
, HFILL
}},
114 { &hf_dlt_file_tstamp_s
,
115 { "Timestamp s", "file-dlt.timestamp_s", FT_UINT32
, BASE_DEC
, NULL
, 0x00, NULL
, HFILL
}},
116 { &hf_dlt_file_tstamp_us
,
117 { "Timestamp us", "file-dlt.timestamp_us", FT_UINT32
, BASE_DEC
, NULL
, 0x00, NULL
, HFILL
}},
118 { &hf_dlt_file_ecuid
,
119 { "ECU ID", "file-dlt.ecu_id", FT_STRING
, BASE_NONE
, NULL
, 0x00, NULL
, HFILL
}},
121 { &hf_dlt_file_header_type
,
122 { "Header Type", "file-dlt.header_type", FT_UINT8
, BASE_HEX
, NULL
, 0x00, NULL
, HFILL
}},
123 { &hf_dlt_file_message_counter
,
124 { "Message Counter", "file-dlt.msg_counter", FT_UINT8
, BASE_DEC
, NULL
, 0x00, NULL
, HFILL
}},
125 { &hf_dlt_file_length
,
126 { "Length", "file-dlt.length", FT_UINT16
, BASE_DEC
, NULL
, 0x00, NULL
, HFILL
}},
128 { "Data", "file-dlt.data", FT_BYTES
, BASE_NONE
, NULL
, 0x00, NULL
, HFILL
}},
131 static int *ett
[] = {
136 proto_dlt
= proto_register_protocol("DLT File Format", "File-DLT", "file-dlt");
137 proto_register_field_array(proto_dlt
, hf
, array_length(hf
));
138 proto_register_subtree_array(ett
, array_length(ett
));
140 register_dissector("file-dlt", dissect_dlt
, proto_dlt
);
144 proto_reg_handoff_file_dlt(void) {
145 heur_dissector_add("wtap_file", dissect_dlt_heur
, "DLT File", "dlt_wtap", proto_dlt
, HEURISTIC_ENABLE
);
149 * Editor modelines - https://www.wireshark.org/tools/modelines.html
154 * indent-tabs-mode: nil
157 * vi: set shiftwidth=4 tabstop=8 expandtab:
158 * :indentSize=4:tabSize=8:noTabs=true: