Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-socketcan.c
blobc8939ed64ab2372b4bed4d6493fd8ba387cf6af7
1 /* packet-socketcan.c
2 * Routines for disassembly of packets from SocketCAN
3 * Felix Obenhuber <felix@obenhuber.de>
5 * Added support for the DeviceNet Dissector
6 * Hans-Joergen Gunnarsson <hag@hms.se>
7 * Copyright 2013
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1998 Gerald Combs
13 * SPDX-License-Identifier: GPL-2.0-or-later
16 #include "config.h"
18 #include <epan/packet.h>
19 #include <epan/prefs.h>
20 #include <epan/expert.h>
21 #include <epan/decode_as.h>
22 #include <epan/uat.h>
23 #include <wiretap/wtap.h>
25 #include "packet-sll.h"
26 #include "packet-socketcan.h"
28 void proto_register_socketcan(void);
29 void proto_reg_handoff_socketcan(void);
31 static int hf_can_len;
32 static int hf_can_infoent_ext;
33 static int hf_can_infoent_std;
34 static int hf_can_extflag;
35 static int hf_can_rtrflag;
36 static int hf_can_errflag;
37 static int hf_can_reserved;
38 static int hf_can_len8dlc;
39 static int hf_can_padding;
41 static int hf_can_err_tx_timeout;
42 static int hf_can_err_lostarb;
43 static int hf_can_err_ctrl;
44 static int hf_can_err_prot;
45 static int hf_can_err_trx;
46 static int hf_can_err_ack;
47 static int hf_can_err_busoff;
48 static int hf_can_err_buserror;
49 static int hf_can_err_restarted;
50 static int hf_can_err_reserved;
52 static int hf_can_err_lostarb_bit_number;
54 static int hf_can_err_ctrl_rx_overflow;
55 static int hf_can_err_ctrl_tx_overflow;
56 static int hf_can_err_ctrl_rx_warning;
57 static int hf_can_err_ctrl_tx_warning;
58 static int hf_can_err_ctrl_rx_passive;
59 static int hf_can_err_ctrl_tx_passive;
60 static int hf_can_err_ctrl_active;
62 static int hf_can_err_prot_error_type_bit;
63 static int hf_can_err_prot_error_type_form;
64 static int hf_can_err_prot_error_type_stuff;
65 static int hf_can_err_prot_error_type_bit0;
66 static int hf_can_err_prot_error_type_bit1;
67 static int hf_can_err_prot_error_type_overload;
68 static int hf_can_err_prot_error_type_active;
69 static int hf_can_err_prot_error_type_tx;
71 static int hf_can_err_prot_error_location;
73 static int hf_can_err_trx_canh;
74 static int hf_can_err_trx_canl;
76 static int hf_can_err_ctrl_specific;
78 static int hf_canxl_priority;
79 static int hf_canxl_vcid;
80 static int hf_canxl_secflag;
81 static int hf_canxl_xlflag;
82 static int hf_canxl_sdu_type;
83 static int hf_canxl_len;
84 static int hf_canxl_acceptance_field;
86 static expert_field ei_can_err_dlc_mismatch;
88 static int hf_canfd_brsflag;
89 static int hf_canfd_esiflag;
90 static int hf_canfd_fdflag;
92 static int ett_can;
93 static int ett_can_fd;
94 static int ett_can_xl;
96 static int proto_can;
97 static int proto_canfd;
98 static int proto_canxl;
100 static bool byte_swap;
101 static bool heuristic_first;
103 static heur_dissector_list_t heur_subdissector_list;
104 static heur_dtbl_entry_t *heur_dtbl_entry;
106 #define LINUX_CAN_STD 0
107 #define LINUX_CAN_EXT 1
108 #define LINUX_CAN_ERR 2
110 #define CAN_LEN_OFFSET 4
111 #define CAN_DATA_OFFSET 8
113 #define CANFD_FLAG_OFFSET 5
115 #define CANXL_FLAGS_OFFSET CAN_LEN_OFFSET
116 #define CANXL_LEN_OFFSET 6
117 #define CANXL_DATA_OFFSET 12
119 static dissector_table_t can_id_dissector_table;
120 static dissector_table_t can_extended_id_dissector_table;
121 static dissector_table_t subdissector_table;
122 static dissector_table_t canxl_sdu_type_dissector_table;
123 static dissector_handle_t socketcan_classic_handle;
124 static dissector_handle_t socketcan_fd_handle;
125 static dissector_handle_t socketcan_xl_handle;
126 static dissector_handle_t socketcan_bigendian_handle;
129 static const value_string can_err_prot_error_location_vals[] = {
130 { 0x00, "unspecified" },
131 { 0x02, "ID bits 28 - 21 (SFF: 10 - 3)" },
132 { 0x03, "start of frame" },
133 { 0x04, "substitute RTR (SFF: RTR)" },
134 { 0x05, "identifier extension" },
135 { 0x06, "ID bits 20 - 18 (SFF: 2 - 0)" },
136 { 0x07, "ID bits 17-13" },
137 { 0x08, "CRC sequence" },
138 { 0x09, "reserved bit 0" },
139 { 0x0A, "data section" },
140 { 0x0B, "data length code" },
141 { 0x0C, "RTR" },
142 { 0x0D, "reserved bit 1" },
143 { 0x0E, "ID bits 4-0" },
144 { 0x0F, "ID bits 12-5" },
145 { 0x12, "intermission" },
146 { 0x18, "CRC delimiter" },
147 { 0x19, "ACK slot" },
148 { 0x1A, "end of frame" },
149 { 0x1B, "ACK delimiter" },
150 { 0, NULL }
153 static const value_string can_err_trx_canh_vals[] = {
154 { 0x00, "unspecified" },
155 { 0x04, "no wire" },
156 { 0x05, "short to BAT" },
157 { 0x06, "short to VCC" },
158 { 0x07, "short to GND" },
159 { 0, NULL }
162 static const value_string can_err_trx_canl_vals[] = {
163 { 0x00, "unspecified" },
164 { 0x04, "no wire" },
165 { 0x05, "short to BAT" },
166 { 0x06, "short to VCC" },
167 { 0x07, "short to GND" },
168 { 0x08, "short to CANH" },
169 { 0, NULL }
172 static const value_string canxl_sdu_type_vals[] = {
173 { 0x00, "Reserved" },
174 { CANXL_SDU_TYPE_CONTENT_BASED_ADDRESSING, "Content-based Addressing" },
175 { 0x02, "Reserved for future use" },
176 { CANXL_SDU_TYPE_CAN_CC_CAN_FD, "CAN CC/CAN FD" },
177 { CANXL_SDU_TYPE_IEEE_802_3, "IEEE 802.3 (MAC frame)" },
178 { CANXL_SDU_TYPE_IEEE_802_3_EXTENDED, "IEEE 802.3 (MAC frame) extended" },
179 { CANXL_SDU_TYPE_CAN_CC, "CAN CC" },
180 { CANXL_SDU_TYPE_CAN_FD, "CAN FD" },
181 { CANXL_SDU_TYPE_CIA_611_2, "CiA 611-2 (Multi-PDU)" },
182 { CANXL_SDU_TYPE_AUTOSAR_MPDU, "AUTOSAR Multi-PDU" },
183 { CANXL_SDU_TYPE_CIA_613_2, "CiA 613-2 (CANsec key agreement protocol" },
184 { 0xFF, "Reserved" },
185 { 0, NULL }
188 /********* UATs *********/
190 /* Interface Config UAT */
191 typedef struct _interface_config {
192 unsigned interface_id;
193 char *interface_name;
194 unsigned bus_id;
195 } interface_config_t;
197 #define DATAFILE_CAN_INTERFACE_MAPPING "CAN_interface_mapping"
199 static GHashTable *data_can_interfaces_by_id;
200 static GHashTable *data_can_interfaces_by_name;
201 static interface_config_t *interface_configs;
202 static unsigned interface_config_num;
204 UAT_HEX_CB_DEF(interface_configs, interface_id, interface_config_t)
205 UAT_CSTRING_CB_DEF(interface_configs, interface_name, interface_config_t)
206 UAT_HEX_CB_DEF(interface_configs, bus_id, interface_config_t)
208 static void *
209 copy_interface_config_cb(void *n, const void *o, size_t size _U_) {
210 interface_config_t *new_rec = (interface_config_t *)n;
211 const interface_config_t *old_rec = (const interface_config_t *)o;
213 new_rec->interface_id = old_rec->interface_id;
214 new_rec->interface_name = g_strdup(old_rec->interface_name);
215 new_rec->bus_id = old_rec->bus_id;
216 return new_rec;
219 static bool
220 update_interface_config(void *r, char **err) {
221 interface_config_t *rec = (interface_config_t *)r;
223 if (rec->interface_id > 0xffffffff) {
224 *err = ws_strdup_printf("We currently only support 32 bit identifiers (ID: %i Name: %s)",
225 rec->interface_id, rec->interface_name);
226 return false;
229 if (rec->bus_id > 0xffff) {
230 *err = ws_strdup_printf("We currently only support 16 bit bus identifiers (ID: %i Name: %s Bus-ID: %i)",
231 rec->interface_id, rec->interface_name, rec->bus_id);
232 return false;
235 return true;
238 static void
239 free_interface_config_cb(void *r) {
240 interface_config_t *rec = (interface_config_t *)r;
242 /* freeing result of g_strdup */
243 g_free(rec->interface_name);
244 rec->interface_name = NULL;
247 static interface_config_t *
248 ht_lookup_interface_config_by_id(unsigned int identifier) {
249 interface_config_t *tmp = NULL;
250 unsigned int *id = NULL;
252 if (interface_configs == NULL) {
253 return NULL;
256 id = wmem_new(wmem_epan_scope(), unsigned int);
257 *id = (unsigned int)identifier;
258 tmp = (interface_config_t *)g_hash_table_lookup(data_can_interfaces_by_id, id);
259 wmem_free(wmem_epan_scope(), id);
261 return tmp;
264 static interface_config_t *
265 ht_lookup_interface_config_by_name(const char *name) {
266 interface_config_t *tmp = NULL;
267 char *key = NULL;
269 if (interface_configs == NULL) {
270 return NULL;
273 key = wmem_strdup(wmem_epan_scope(), name);
274 tmp = (interface_config_t *)g_hash_table_lookup(data_can_interfaces_by_name, key);
275 wmem_free(wmem_epan_scope(), key);
277 return tmp;
280 static void
281 can_free_key(void *key) {
282 wmem_free(wmem_epan_scope(), key);
285 static void
286 post_update_can_interfaces_cb(void) {
287 unsigned i;
288 int *key_id = NULL;
289 char *key_name = NULL;
291 /* destroy old hash tables, if they exist */
292 if (data_can_interfaces_by_id) {
293 g_hash_table_destroy(data_can_interfaces_by_id);
294 data_can_interfaces_by_id = NULL;
296 if (data_can_interfaces_by_name) {
297 g_hash_table_destroy(data_can_interfaces_by_name);
298 data_can_interfaces_by_name = NULL;
301 /* create new hash table */
302 data_can_interfaces_by_id = g_hash_table_new_full(g_int_hash, g_int_equal, &can_free_key, NULL);
303 data_can_interfaces_by_name = g_hash_table_new_full(g_str_hash, g_str_equal, &can_free_key, NULL);
305 if (data_can_interfaces_by_id == NULL || data_can_interfaces_by_name == NULL || interface_configs == NULL || interface_config_num == 0) {
306 return;
309 for (i = 0; i < interface_config_num; i++) {
310 if (interface_configs[i].interface_id != 0xfffffff) {
311 key_id = wmem_new(wmem_epan_scope(), int);
312 *key_id = interface_configs[i].interface_id;
313 g_hash_table_insert(data_can_interfaces_by_id, key_id, &interface_configs[i]);
316 if (interface_configs[i].interface_name != NULL && interface_configs[i].interface_name[0] != 0) {
317 key_name = wmem_strdup(wmem_epan_scope(), interface_configs[i].interface_name);
318 g_hash_table_insert(data_can_interfaces_by_name, key_name, &interface_configs[i]);
323 /* We match based on the config in the following order:
324 * - interface_name matches and interface_id matches
325 * - interface_name matches and interface_id = 0xffffffff
326 * - interface_name = "" and interface_id matches
328 static unsigned
329 get_bus_id(packet_info *pinfo) {
330 if (!(pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID)) {
331 return 0;
334 uint32_t interface_id = pinfo->rec->rec_header.packet_header.interface_id;
335 unsigned section_number = pinfo->rec->presence_flags & WTAP_HAS_SECTION_NUMBER ? pinfo->rec->section_number : 0;
336 const char *interface_name = epan_get_interface_name(pinfo->epan, interface_id, section_number);
337 interface_config_t *tmp = NULL;
339 if (interface_name != NULL && interface_name[0] != 0) {
340 tmp = ht_lookup_interface_config_by_name(interface_name);
342 if (tmp != NULL && (tmp->interface_id == 0xffffffff || tmp->interface_id == interface_id)) {
343 /* name + id match or name match and id = any */
344 return tmp->bus_id;
347 tmp = ht_lookup_interface_config_by_id(interface_id);
349 if (tmp != NULL && (tmp->interface_name == NULL || tmp->interface_name[0] == 0)) {
350 /* id matches and name is any */
351 return tmp->bus_id;
355 /* we found nothing */
356 return 0;
359 /* Senders and Receivers UAT */
360 typedef struct _sender_receiver_config {
361 unsigned bus_id;
362 unsigned can_id;
363 char *sender_name;
364 char *receiver_name;
365 } sender_receiver_config_t;
367 #define DATAFILE_CAN_SENDER_RECEIVER "CAN_senders_receivers"
369 static GHashTable *data_sender_receiver;
370 static sender_receiver_config_t *sender_receiver_configs;
371 static unsigned sender_receiver_config_num;
373 UAT_HEX_CB_DEF(sender_receiver_configs, bus_id, sender_receiver_config_t)
374 UAT_HEX_CB_DEF(sender_receiver_configs, can_id, sender_receiver_config_t)
375 UAT_CSTRING_CB_DEF(sender_receiver_configs, sender_name, sender_receiver_config_t)
376 UAT_CSTRING_CB_DEF(sender_receiver_configs, receiver_name, sender_receiver_config_t)
378 static void *
379 copy_sender_receiver_config_cb(void *n, const void *o, size_t size _U_) {
380 sender_receiver_config_t *new_rec = (sender_receiver_config_t *)n;
381 const sender_receiver_config_t *old_rec = (const sender_receiver_config_t *)o;
383 new_rec->bus_id = old_rec->bus_id;
384 new_rec->can_id = old_rec->can_id;
385 new_rec->sender_name = g_strdup(old_rec->sender_name);
386 new_rec->receiver_name = g_strdup(old_rec->receiver_name);
387 return new_rec;
390 static bool
391 update_sender_receiver_config(void *r, char **err) {
392 sender_receiver_config_t *rec = (sender_receiver_config_t *)r;
394 if (rec->bus_id > 0xffff) {
395 *err = ws_strdup_printf("We currently only support 16 bit bus identifiers (Bus ID: %i CAN ID: %i)", rec->bus_id, rec->can_id);
396 return false;
399 return true;
402 static void
403 free_sender_receiver_config_cb(void *r) {
404 sender_receiver_config_t *rec = (sender_receiver_config_t *)r;
406 /* freeing result of g_strdup */
407 g_free(rec->sender_name);
408 rec->sender_name = NULL;
409 g_free(rec->receiver_name);
410 rec->receiver_name = NULL;
413 static uint64_t
414 sender_receiver_key(uint16_t bus_id, uint32_t can_id) {
415 return ((uint64_t)bus_id << 32) | can_id;
418 static sender_receiver_config_t *
419 ht_lookup_sender_receiver_config(uint16_t bus_id, uint32_t can_id) {
420 sender_receiver_config_t *tmp = NULL;
421 uint64_t key = 0;
423 if (sender_receiver_configs == NULL) {
424 return NULL;
427 key = sender_receiver_key(bus_id, can_id);
428 tmp = (sender_receiver_config_t *)g_hash_table_lookup(data_sender_receiver, &key);
430 if (tmp == NULL) {
431 key = sender_receiver_key(0, can_id);
432 tmp = (sender_receiver_config_t *)g_hash_table_lookup(data_sender_receiver, &key);
435 return tmp;
438 static void
439 sender_receiver_free_key(void *key) {
440 wmem_free(wmem_epan_scope(), key);
443 static void
444 post_update_sender_receiver_cb(void) {
445 unsigned i;
446 uint64_t *key_id = NULL;
448 /* destroy old hash table, if it exist */
449 if (data_sender_receiver) {
450 g_hash_table_destroy(data_sender_receiver);
451 data_sender_receiver = NULL;
454 /* create new hash table */
455 data_sender_receiver = g_hash_table_new_full(g_int64_hash, g_int64_equal, &sender_receiver_free_key, NULL);
457 if (data_sender_receiver == NULL || sender_receiver_configs == NULL || sender_receiver_config_num == 0) {
458 return;
461 for (i = 0; i < sender_receiver_config_num; i++) {
462 key_id = wmem_new(wmem_epan_scope(), uint64_t);
463 *key_id = sender_receiver_key(sender_receiver_configs[i].bus_id, sender_receiver_configs[i].can_id);
464 g_hash_table_insert(data_sender_receiver, key_id, &sender_receiver_configs[i]);
468 bool
469 socketcan_set_source_and_destination_columns(packet_info *pinfo, can_info_t *caninfo) {
470 sender_receiver_config_t *tmp = ht_lookup_sender_receiver_config(caninfo->bus_id, caninfo->id);
472 if (tmp != NULL) {
473 /* remove all addresses to support CAN as payload (e.g., TECMP) */
474 clear_address(&pinfo->net_src);
475 clear_address(&pinfo->dl_src);
476 clear_address(&pinfo->src);
477 clear_address(&pinfo->net_dst);
478 clear_address(&pinfo->dl_dst);
479 clear_address(&pinfo->dst);
481 col_add_str(pinfo->cinfo, COL_DEF_SRC, tmp->sender_name);
482 col_add_str(pinfo->cinfo, COL_DEF_DST, tmp->receiver_name);
483 return true;
485 return false;
488 bool
489 socketcan_call_subdissectors(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, struct can_info *can_info, const bool use_heuristics_first) {
490 dissector_table_t effective_can_id_dissector_table = (can_info->id & CAN_EFF_FLAG) ? can_extended_id_dissector_table : can_id_dissector_table;
491 uint32_t effective_can_id = (can_info->id & CAN_EFF_FLAG) ? can_info->id & CAN_EFF_MASK : can_info->id & CAN_SFF_MASK;
493 if (!dissector_try_uint_with_data(effective_can_id_dissector_table, effective_can_id, tvb, pinfo, tree, true, can_info)) {
494 if (!use_heuristics_first) {
495 if (!dissector_try_payload_with_data(subdissector_table, tvb, pinfo, tree, true, can_info)) {
496 if (!dissector_try_heuristic(heur_subdissector_list, tvb, pinfo, tree, &heur_dtbl_entry, can_info)) {
497 return false;
500 } else {
501 if (!dissector_try_heuristic(heur_subdissector_list, tvb, pinfo, tree, &heur_dtbl_entry, can_info)) {
502 if (!dissector_try_payload_with_data(subdissector_table, tvb, pinfo, tree, false, can_info)) {
503 return false;
509 return true;
513 * Either:
515 * 1) a given SocketCAN frame is known to contain a classic CAN
516 * packet based on information outside the SocketCAN header;
518 * 2) a given SocketCAN frame is known to contain a CAN FD
519 * packet based on information outside the SocketCAN header;
521 * 3) a given SocketCAN frame is known to contain a CAN XL
522 * packet based on information outside the SocketCAN header;
524 * 4) we don't know whether the given SocketCAN frame is a
525 * classic CAN packet, a CAN FD packet, or a CAN XL packet,
526 * and will have to check the CANXL_XLF bit in the "Frame Length"
527 * field and the CANFD_FDF bit in the "FD flags" field of the
528 * SocketCAN header to determine that.
530 typedef enum {
531 PACKET_TYPE_CAN,
532 PACKET_TYPE_CAN_FD,
533 PACKET_TYPE_CAN_XL,
534 PACKET_TYPE_UNKNOWN
535 } can_packet_type_t;
537 static int
538 dissect_socketcan_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, unsigned encoding, unsigned xl_encoding, can_packet_type_t can_packet_type) {
539 proto_tree *can_tree;
540 proto_item *ti;
541 uint8_t frame_type;
542 can_info_t can_info;
543 int * const *can_flags_id;
545 static int * const can_std_flags_id[] = {
546 &hf_can_infoent_std,
547 &hf_can_extflag,
548 &hf_can_rtrflag,
549 &hf_can_errflag,
550 NULL,
552 static int * const can_ext_flags_id[] = {
553 &hf_can_infoent_ext,
554 &hf_can_extflag,
555 &hf_can_rtrflag,
556 &hf_can_errflag,
557 NULL,
559 static int * const canfd_std_flags_id[] = {
560 &hf_can_infoent_std,
561 &hf_can_extflag,
562 NULL,
564 static int * const canfd_ext_flags_id[] = {
565 &hf_can_infoent_ext,
566 &hf_can_extflag,
567 NULL,
569 static int * const canfd_flag_fields[] = {
570 &hf_canfd_brsflag,
571 &hf_canfd_esiflag,
572 &hf_canfd_fdflag,
573 NULL,
575 static int * const can_err_flags[] = {
576 &hf_can_errflag,
577 &hf_can_err_tx_timeout,
578 &hf_can_err_lostarb,
579 &hf_can_err_ctrl,
580 &hf_can_err_prot,
581 &hf_can_err_trx,
582 &hf_can_err_ack,
583 &hf_can_err_busoff,
584 &hf_can_err_buserror,
585 &hf_can_err_restarted,
586 &hf_can_err_reserved,
587 NULL,
589 static int * const canxl_prio_vcid_fields[] = {
590 &hf_canxl_priority,
591 &hf_canxl_vcid,
592 NULL,
594 static int * const canxl_flag_fields[] = {
595 &hf_canxl_secflag,
596 &hf_canxl_xlflag,
597 NULL,
600 /* determine CAN packet type */
601 if (can_packet_type == PACKET_TYPE_UNKNOWN) {
602 uint8_t canfd_flags;
603 uint8_t canxl_flags;
606 * Check whether the frame has the CANXL_XLF flag set in what
607 * is in the location of the frame length field of a CAN classic
608 * or CAN FD frame; if so, then it's a CAN XL frame (and that
609 * field is the flags field of that frame).
611 canfd_flags = tvb_get_uint8(tvb, CANFD_FLAG_OFFSET);
612 canxl_flags = tvb_get_uint8(tvb, CANXL_FLAGS_OFFSET);
614 if (canxl_flags & CANXL_XLF) {
615 /* CAN XL: check for min/max data length */
616 if ((tvb_reported_length(tvb) >= 13) && (tvb_reported_length(tvb) <= 2060))
617 can_packet_type = PACKET_TYPE_CAN_XL;
618 } else {
619 /* CAN CC/FD */
620 if ((tvb_reported_length(tvb) == 72) || (canfd_flags & CANFD_FDF)) {
621 /* CAN FD: check for min/max data length */
622 if ((tvb_reported_length(tvb) >= 8) && (tvb_reported_length(tvb) <= 72))
623 can_packet_type = PACKET_TYPE_CAN_FD;
624 } else if ((tvb_reported_length(tvb) >= 8) && (tvb_reported_length(tvb) <= 16))
625 can_packet_type = PACKET_TYPE_CAN;
629 can_info.bus_id = get_bus_id(pinfo);
631 if (can_packet_type == PACKET_TYPE_CAN_XL) {
632 can_info.fd = CAN_TYPE_CAN_XL;
633 col_set_str(pinfo->cinfo, COL_PROTOCOL, "CANXL");
634 col_clear(pinfo->cinfo, COL_INFO);
636 can_info.id = 0; /* XXX - is there an "ID" for XL frames? */
638 ti = proto_tree_add_item(tree, proto_can, tvb, 0, -1, ENC_NA);
639 proto_item_set_hidden(ti);
640 ti = proto_tree_add_item(tree, proto_canxl, tvb, 0, -1, ENC_NA);
641 can_tree = proto_item_add_subtree(ti, ett_can_xl);
643 uint32_t proto_vcid;
646 * The priority/VCID field is big-endian in LINKTYPE_CAN_SOCKETCAN
647 * captures, for historical reasons. It's host-endian in
648 * Linux cooked captures. This means we use the non-XL encoding.
650 proto_tree_add_bitmask_list(can_tree, tvb, 0, 4, canxl_prio_vcid_fields, encoding);
651 proto_vcid = tvb_get_uint32(tvb, 0, encoding);
652 col_add_fstr(pinfo->cinfo, COL_INFO, "Priority: %u (0x%03x), VCID: %u (0x%02X)", proto_vcid & 0x7FF, proto_vcid & 0x7FF, (proto_vcid >> 16) & 0xFF, (proto_vcid >> 16) & 0xFF);
653 proto_item_append_text(can_tree, ", Priority: %u (0x%03x), VCID: %u (0x%02X)", proto_vcid & 0x7FF, proto_vcid & 0x7FF, (proto_vcid >> 16) & 0xFF, (proto_vcid >> 16) & 0xFF);
654 proto_tree_add_bitmask_list(can_tree, tvb, 4, 1, canxl_flag_fields, xl_encoding);
656 socketcan_set_source_and_destination_columns(pinfo, &can_info);
658 uint32_t sdu_type;
661 * These fields are, if multi-byte, little-endian in
662 * LINKTYPE_CAN_SOCKETCAN captures, so use xl_encoding.
664 proto_tree_add_item_ret_uint(can_tree, hf_canxl_sdu_type, tvb, 5, 1, ENC_NA, &sdu_type);
665 proto_tree_add_item_ret_uint(can_tree, hf_canxl_len, tvb, CANXL_LEN_OFFSET, 2, xl_encoding, &can_info.len);
666 col_append_fstr(pinfo->cinfo, COL_INFO, ", Length: %u", can_info.len);
667 proto_item_append_text(can_tree, ", Length: %u", can_info.len);
668 proto_tree_add_item(can_tree, hf_canxl_acceptance_field, tvb, CANXL_LEN_OFFSET+2, 4, xl_encoding);
670 tvbuff_t *next_tvb;
672 next_tvb = tvb_new_subset_length(tvb, CANXL_DATA_OFFSET, can_info.len);
674 if (!dissector_try_uint_with_data(canxl_sdu_type_dissector_table, sdu_type, next_tvb, pinfo, tree, true, &can_info)) {
675 call_data_dissector(next_tvb, pinfo, tree);
678 if (tvb_captured_length_remaining(tvb, CANXL_DATA_OFFSET+can_info.len) > 0) {
679 proto_tree_add_item(can_tree, hf_can_padding, tvb, CANXL_DATA_OFFSET+can_info.len, -1, ENC_NA);
681 } else {
682 if (can_packet_type == PACKET_TYPE_CAN_FD) {
683 can_info.fd = CAN_TYPE_CAN_FD;
684 col_set_str(pinfo->cinfo, COL_PROTOCOL, "CANFD");
685 } else {
686 can_info.fd = CAN_TYPE_CAN_CLASSIC;
687 col_set_str(pinfo->cinfo, COL_PROTOCOL, "CAN");
689 col_clear(pinfo->cinfo, COL_INFO);
691 ti = proto_tree_add_item(tree, proto_can, tvb, 0, -1, ENC_NA);
692 if (can_packet_type == PACKET_TYPE_CAN_FD) {
693 proto_item_set_hidden(ti);
694 ti = proto_tree_add_item(tree, proto_canfd, tvb, 0, -1, ENC_NA);
696 can_tree = proto_item_add_subtree(ti, (can_packet_type == PACKET_TYPE_CAN_FD) ? ett_can_fd : ett_can);
698 /* Get the ID and flags field */
699 can_info.id = tvb_get_uint32(tvb, 0, encoding);
701 /* Error Message Frames are only encapsulated in Classic CAN frames */
702 if (can_packet_type == PACKET_TYPE_CAN && (can_info.id & CAN_ERR_FLAG)) {
703 frame_type = LINUX_CAN_ERR;
704 can_flags_id = can_err_flags;
705 } else if (can_info.id & CAN_EFF_FLAG) {
706 frame_type = LINUX_CAN_EXT;
707 can_info.id &= (CAN_EFF_MASK | CAN_FLAG_MASK);
708 can_flags_id = (can_packet_type == PACKET_TYPE_CAN_FD) ? canfd_ext_flags_id : can_ext_flags_id;
709 } else {
710 frame_type = LINUX_CAN_STD;
711 can_info.id &= (CAN_SFF_MASK | CAN_FLAG_MASK);
712 can_flags_id = (can_packet_type == PACKET_TYPE_CAN_FD) ? canfd_std_flags_id : can_std_flags_id;
715 socketcan_set_source_and_destination_columns(pinfo, &can_info);
717 proto_tree_add_bitmask_list(can_tree, tvb, 0, 4, can_flags_id, encoding);
718 if (can_info.id & CAN_EFF_FLAG) {
719 col_add_fstr(pinfo->cinfo, COL_INFO, "Ext. ID: %u (0x%08x)", can_info.id & CAN_EFF_MASK, can_info.id & CAN_EFF_MASK);
720 proto_item_append_text(can_tree, ", Ext. ID: %u (0x%08x)", can_info.id & CAN_EFF_MASK, can_info.id & CAN_EFF_MASK);
721 } else {
722 col_add_fstr(pinfo->cinfo, COL_INFO, "ID: %u (0x%03x)", can_info.id & CAN_SFF_MASK, can_info.id & CAN_SFF_MASK);
723 proto_item_append_text(can_tree, ", ID: %u (0x%03x)", can_info.id & CAN_SFF_MASK, can_info.id & CAN_SFF_MASK);
725 proto_tree_add_item_ret_uint(can_tree, hf_can_len, tvb, CAN_LEN_OFFSET, 1, ENC_NA, &can_info.len);
726 col_append_fstr(pinfo->cinfo, COL_INFO, ", Length: %u", can_info.len);
727 proto_item_append_text(can_tree, ", Length: %u", can_info.len);
729 if (frame_type == LINUX_CAN_ERR && can_info.len != CAN_ERR_DLC) {
730 proto_tree_add_expert(tree, pinfo, &ei_can_err_dlc_mismatch, tvb, CAN_LEN_OFFSET, 1);
733 if (can_packet_type == PACKET_TYPE_CAN_FD) {
734 proto_tree_add_bitmask_list(can_tree, tvb, CANFD_FLAG_OFFSET, 1, canfd_flag_fields, ENC_NA);
735 proto_tree_add_item(can_tree, hf_can_reserved, tvb, CANFD_FLAG_OFFSET+1, 2, ENC_NA);
736 } else {
737 proto_tree_add_item(can_tree, hf_can_reserved, tvb, CANFD_FLAG_OFFSET, 2, ENC_NA);
738 proto_tree_add_item(can_tree, hf_can_len8dlc, tvb, CANFD_FLAG_OFFSET+2, 1, ENC_NA);
741 if (frame_type == LINUX_CAN_ERR) {
742 int * const *flag;
743 const char *sepa = ": ";
745 col_set_str(pinfo->cinfo, COL_INFO, "ERR");
747 for (flag = can_err_flags; *flag; flag++) {
748 header_field_info *hfi;
750 hfi = proto_registrar_get_nth(**flag);
751 if (!hfi)
752 continue;
754 if ((can_info.id & hfi->bitmask & ~CAN_FLAG_MASK) == 0)
755 continue;
757 col_append_sep_str(pinfo->cinfo, COL_INFO, sepa, hfi->name);
758 sepa = ", ";
761 if (can_info.id & CAN_ERR_LOSTARB) {
762 proto_tree_add_item(can_tree, hf_can_err_lostarb_bit_number, tvb, CAN_DATA_OFFSET + 0, 1, ENC_NA);
765 if (can_info.id & CAN_ERR_CTRL) {
766 static int * const can_err_ctrl_flags[] = {
767 &hf_can_err_ctrl_rx_overflow,
768 &hf_can_err_ctrl_tx_overflow,
769 &hf_can_err_ctrl_rx_warning,
770 &hf_can_err_ctrl_tx_warning,
771 &hf_can_err_ctrl_rx_passive,
772 &hf_can_err_ctrl_tx_passive,
773 &hf_can_err_ctrl_active,
774 NULL,
777 proto_tree_add_bitmask_list(can_tree, tvb, CAN_DATA_OFFSET+1, 1, can_err_ctrl_flags, ENC_NA);
780 if (can_info.id & CAN_ERR_PROT) {
781 static int * const can_err_prot_error_type_flags[] = {
782 &hf_can_err_prot_error_type_bit,
783 &hf_can_err_prot_error_type_form,
784 &hf_can_err_prot_error_type_stuff,
785 &hf_can_err_prot_error_type_bit0,
786 &hf_can_err_prot_error_type_bit1,
787 &hf_can_err_prot_error_type_overload,
788 &hf_can_err_prot_error_type_active,
789 &hf_can_err_prot_error_type_tx,
790 NULL
792 proto_tree_add_bitmask_list(can_tree, tvb, CAN_DATA_OFFSET+2, 1, can_err_prot_error_type_flags, ENC_NA);
793 proto_tree_add_item(can_tree, hf_can_err_prot_error_location, tvb, CAN_DATA_OFFSET+3, 1, ENC_NA);
796 if (can_info.id & CAN_ERR_TRX) {
797 proto_tree_add_item(can_tree, hf_can_err_trx_canh, tvb, CAN_DATA_OFFSET+4, 1, ENC_NA);
798 proto_tree_add_item(can_tree, hf_can_err_trx_canl, tvb, CAN_DATA_OFFSET+4, 1, ENC_NA);
801 proto_tree_add_item(can_tree, hf_can_err_ctrl_specific, tvb, CAN_DATA_OFFSET+5, 3, ENC_NA);
802 } else {
803 tvbuff_t *next_tvb;
805 if (can_info.id & CAN_RTR_FLAG) {
806 col_append_str(pinfo->cinfo, COL_INFO, "(Remote Transmission Request)");
809 next_tvb = tvb_new_subset_length(tvb, CAN_DATA_OFFSET, can_info.len);
811 if (!socketcan_call_subdissectors(next_tvb, pinfo, tree, &can_info, heuristic_first)) {
812 call_data_dissector(next_tvb, pinfo, tree);
816 if (tvb_captured_length_remaining(tvb, CAN_DATA_OFFSET+can_info.len) > 0) {
817 proto_tree_add_item(can_tree, hf_can_padding, tvb, CAN_DATA_OFFSET+can_info.len, -1, ENC_NA);
821 return tvb_captured_length(tvb);
824 static int
825 dissect_socketcan_bigendian(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) {
826 return dissect_socketcan_common(tvb, pinfo, tree,
827 byte_swap ? ENC_LITTLE_ENDIAN : ENC_BIG_ENDIAN,
828 ENC_LITTLE_ENDIAN,
829 PACKET_TYPE_UNKNOWN);
832 static int
833 dissect_socketcan_classic(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) {
834 return dissect_socketcan_common(tvb, pinfo, tree,
835 byte_swap ? ENC_ANTI_HOST_ENDIAN : ENC_HOST_ENDIAN,
836 ENC_HOST_ENDIAN, /* Not used, as this is CAN classic, not CAN XL */
837 PACKET_TYPE_CAN);
840 static int
841 dissect_socketcan_fd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) {
842 return dissect_socketcan_common(tvb, pinfo, tree,
843 byte_swap ? ENC_ANTI_HOST_ENDIAN : ENC_HOST_ENDIAN,
844 ENC_HOST_ENDIAN, /* Not used, as this is CAN FD, not CAN XL */
845 PACKET_TYPE_CAN_FD);
848 static int
849 dissect_socketcan_xl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) {
850 return dissect_socketcan_common(tvb, pinfo, tree,
851 byte_swap ? ENC_ANTI_HOST_ENDIAN : ENC_HOST_ENDIAN,
852 ENC_HOST_ENDIAN,
853 PACKET_TYPE_CAN_XL);
856 void
857 proto_register_socketcan(void) {
858 static hf_register_info hf[] = {
859 { &hf_can_infoent_ext, {
860 "ID", "can.id", FT_UINT32, BASE_DEC_HEX, NULL, CAN_EFF_MASK, NULL, HFILL } },
861 { &hf_can_infoent_std, {
862 "ID", "can.id", FT_UINT32, BASE_DEC_HEX, NULL, CAN_SFF_MASK, NULL, HFILL } },
863 { &hf_can_extflag, {
864 "Extended Flag", "can.flags.xtd", FT_BOOLEAN, 32, NULL, CAN_EFF_FLAG, NULL, HFILL } },
865 { &hf_can_rtrflag, {
866 "Remote Transmission Request Flag", "can.flags.rtr", FT_BOOLEAN, 32, NULL, CAN_RTR_FLAG, NULL, HFILL } },
867 { &hf_can_errflag, {
868 "Error Message Flag", "can.flags.err", FT_BOOLEAN, 32, NULL, CAN_ERR_FLAG, NULL, HFILL } },
869 { &hf_can_len, {
870 "Frame-Length", "can.len", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL } },
871 { &hf_can_len8dlc, {
872 "Len 8 DLC", "can.len8dlc", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL } },
873 { &hf_can_reserved, {
874 "Reserved", "can.reserved", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },
875 { &hf_can_padding, {
876 "Padding", "can.padding", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },
877 { &hf_canfd_brsflag, {
878 "Bit Rate Setting", "canfd.flags.brs", FT_BOOLEAN, 8, NULL, CANFD_BRS, NULL, HFILL } },
879 { &hf_canfd_esiflag, {
880 "Error State Indicator", "canfd.flags.esi", FT_BOOLEAN, 8, NULL, CANFD_ESI, NULL, HFILL } },
881 { &hf_canfd_fdflag, {
882 "FD Frame", "canfd.flags.fdf", FT_BOOLEAN, 8, NULL, CANFD_FDF, NULL, HFILL } },
883 { &hf_can_err_tx_timeout, {
884 "Transmit timeout", "can.err.tx_timeout", FT_BOOLEAN, 32, NULL, CAN_ERR_TX_TIMEOUT, NULL, HFILL } },
885 { &hf_can_err_lostarb, {
886 "Lost arbitration", "can.err.lostarb", FT_BOOLEAN, 32, NULL, CAN_ERR_LOSTARB, NULL, HFILL } },
887 { &hf_can_err_ctrl, {
888 "Controller problems", "can.err.ctrl", FT_BOOLEAN, 32, NULL, CAN_ERR_CTRL, NULL, HFILL } },
889 { &hf_can_err_prot, {
890 "Protocol violation", "can.err.prot", FT_BOOLEAN, 32, NULL, CAN_ERR_PROT, NULL, HFILL } },
891 { &hf_can_err_trx, {
892 "Transceiver status", "can.err.trx", FT_BOOLEAN, 32, NULL, CAN_ERR_TRX, NULL, HFILL } },
893 { &hf_can_err_ack, {
894 "No acknowledgment", "can.err.ack", FT_BOOLEAN, 32, NULL, CAN_ERR_ACK, NULL, HFILL } },
895 { &hf_can_err_busoff, {
896 "Bus off", "can.err.busoff", FT_BOOLEAN, 32, NULL, CAN_ERR_BUSOFF, NULL, HFILL } },
897 { &hf_can_err_buserror, {
898 "Bus error", "can.err.buserror", FT_BOOLEAN, 32, NULL, CAN_ERR_BUSERROR, NULL, HFILL } },
899 { &hf_can_err_restarted, {
900 "Controller restarted", "can.err.restarted", FT_BOOLEAN, 32, NULL, CAN_ERR_RESTARTED, NULL, HFILL } },
901 { &hf_can_err_reserved, {
902 "Reserved", "can.err.reserved", FT_UINT32, BASE_HEX, NULL, CAN_ERR_RESERVED, NULL, HFILL } },
903 { &hf_can_err_lostarb_bit_number, {
904 "Lost arbitration in bit number", "can.err.lostarb.bitnum", FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL } },
905 { &hf_can_err_ctrl_rx_overflow, {
906 "RX buffer overflow", "can.err.ctrl.rx_overflow", FT_BOOLEAN, 8, NULL, 0x01, NULL, HFILL } },
907 { &hf_can_err_ctrl_tx_overflow, {
908 "TX buffer overflow", "can.err.ctrl.tx_overflow", FT_BOOLEAN, 8, NULL, 0x02, NULL, HFILL } },
909 { &hf_can_err_ctrl_rx_warning, {
910 "Reached warning level for RX errors", "can.err.ctrl.rx_warning", FT_BOOLEAN, 8, NULL, 0x04, NULL, HFILL } },
911 { &hf_can_err_ctrl_tx_warning, {
912 "Reached warning level for TX errors", "can.err.ctrl.tx_warning", FT_BOOLEAN, 8, NULL, 0x08, NULL, HFILL } },
913 { &hf_can_err_ctrl_rx_passive, {
914 "Reached error passive status RX", "can.err.ctrl.rx_passive", FT_BOOLEAN, 8, NULL, 0x10, NULL, HFILL } },
915 { &hf_can_err_ctrl_tx_passive, {
916 "Reached error passive status TX", "can.err.ctrl.tx_passive", FT_BOOLEAN, 8, NULL, 0x20, NULL, HFILL } },
917 { &hf_can_err_ctrl_active, {
918 "Recovered to error active state", "can.err.ctrl.active", FT_BOOLEAN, 8, NULL, 0x40, NULL, HFILL } },
919 { &hf_can_err_prot_error_type_bit, {
920 "Single bit error", "can.err.prot.type.bit", FT_BOOLEAN, 8, NULL, CAN_ERR_PROT_BIT, NULL, HFILL } },
921 { &hf_can_err_prot_error_type_form, {
922 "Frame format error", "can.err.prot.type.form", FT_BOOLEAN, 8, NULL, CAN_ERR_PROT_FORM, NULL, HFILL } },
923 { &hf_can_err_prot_error_type_stuff, {
924 "Bit stuffing error", "can.err.prot.type.stuff", FT_BOOLEAN, 8, NULL, CAN_ERR_PROT_STUFF, NULL, HFILL } },
925 { &hf_can_err_prot_error_type_bit0, {
926 "Unable to send dominant bit", "can.err.prot.type.bit0", FT_BOOLEAN, 8, NULL, CAN_ERR_PROT_BIT0, NULL, HFILL } },
927 { &hf_can_err_prot_error_type_bit1, {
928 "Unable to send recessive bit", "can.err.prot.type.bit1", FT_BOOLEAN, 8, NULL, CAN_ERR_PROT_BIT1, NULL, HFILL } },
929 { &hf_can_err_prot_error_type_overload, {
930 "Bus overload", "can.err.prot.type.overload", FT_BOOLEAN, 8, NULL, CAN_ERR_PROT_OVERLOAD, NULL, HFILL } },
931 { &hf_can_err_prot_error_type_active, {
932 "Active error announcement", "can.err.prot.type.active", FT_BOOLEAN, 8, NULL, CAN_ERR_PROT_ACTIVE, NULL, HFILL } },
933 { &hf_can_err_prot_error_type_tx, {
934 "Error occurred on transmission", "can.err.prot.type.tx", FT_BOOLEAN, 8, NULL, CAN_ERR_PROT_TX, NULL, HFILL } },
935 { &hf_can_err_prot_error_location, {
936 "Protocol error location", "can.err.prot.location", FT_UINT8, BASE_DEC, VALS(can_err_prot_error_location_vals), 0, NULL, HFILL } },
937 { &hf_can_err_trx_canh, {
938 "Transceiver CANH status", "can.err.trx.canh", FT_UINT8, BASE_DEC, VALS(can_err_trx_canh_vals), 0x0F, NULL, HFILL } },
939 { &hf_can_err_trx_canl, {
940 "Transceiver CANL status", "can.err.trx.canl", FT_UINT8, BASE_DEC, VALS(can_err_trx_canl_vals), 0xF0, NULL, HFILL } },
941 { &hf_can_err_ctrl_specific, {
942 "Controller specific data", "can.err.ctrl_specific", FT_BYTES, SEP_SPACE, NULL, 0, NULL, HFILL } },
943 { &hf_canxl_priority, {
944 "Priority", "canxl.priority", FT_UINT32, BASE_DEC, NULL, 0x0000FFFF, NULL, HFILL } },
945 { &hf_canxl_vcid, {
946 "VCID", "canxl.vcid", FT_UINT32, BASE_DEC, NULL, 0x00FF0000, NULL, HFILL } },
947 { &hf_canxl_secflag, {
948 "Simple Extended Context", "canxl.flags.sec", FT_BOOLEAN, 8, NULL, CANXL_SEC, NULL, HFILL } },
949 { &hf_canxl_xlflag, {
950 "XL Frame", "canxl.flags.xl", FT_BOOLEAN, 8, NULL, CANXL_XLF, NULL, HFILL } },
951 { &hf_canxl_sdu_type, {
952 "SDU type", "canxl.sdu_type", FT_UINT8, BASE_HEX, VALS(canxl_sdu_type_vals), 0, NULL, HFILL } },
953 { &hf_canxl_len, {
954 "Frame-Length", "canxl.len", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
955 { &hf_canxl_acceptance_field, {
956 "Acceptance field", "canxl.acceptance_field", FT_UINT32, BASE_DEC_HEX, NULL, 0, NULL, HFILL } },
959 uat_t *can_interface_uat = NULL;
960 uat_t *sender_receiver_uat = NULL;
962 /* Setup protocol subtree array */
963 static int *ett[] = {
964 &ett_can,
965 &ett_can_fd,
966 &ett_can_xl
969 static ei_register_info ei[] = {
970 { &ei_can_err_dlc_mismatch, {
971 "can.err.dlc_mismatch", PI_MALFORMED, PI_ERROR, "ERROR: DLC mismatch", EXPFILL } }
974 module_t *can_module;
976 proto_can = proto_register_protocol("Controller Area Network", "CAN", "can");
979 * "can-hostendian" is a legacy name (there never was, in any libpcap
980 * release, a SocketCAN LINKTYPE_ value for a host-endian CAN ID
981 * and flags field); we need to keep it around in case some candump
982 * or Busmaster capture that was saved as a pcap or pcapng file,
983 * as those use a linktype of LINKTYPE_WIRESHARK_UPPER_PDU with
984 * "can-hostendian" as the dissector name.
986 * "can-bigendian" is also a legacy name (fpr CAN XL frames, the
987 * fields in the header are in *little-endian* order); we keep it
988 * around for the same reason. It's used for the dissector for
989 * LINKTYPE_CAN_SOCKETCAN.
991 socketcan_classic_handle = register_dissector("can-hostendian", dissect_socketcan_classic, proto_can);
992 socketcan_bigendian_handle = register_dissector("can-bigendian", dissect_socketcan_bigendian, proto_can);
994 proto_canfd = proto_register_protocol("Controller Area Network FD", "CANFD", "canfd");
995 socketcan_fd_handle = register_dissector("canfd", dissect_socketcan_fd, proto_canfd);
997 proto_canxl = proto_register_protocol("Controller Area Network XL", "CANXL", "canxl");
998 socketcan_xl_handle = register_dissector("canxl", dissect_socketcan_xl, proto_canxl);
1000 proto_register_field_array(proto_can, hf, array_length(hf));
1001 proto_register_subtree_array(ett, array_length(ett));
1003 expert_register_field_array(expert_register_protocol(proto_can), ei, array_length(ei));
1005 can_module = prefs_register_protocol(proto_can, NULL);
1007 prefs_register_obsolete_preference(can_module, "protocol");
1009 prefs_register_bool_preference(can_module, "byte_swap", "Byte-swap the CAN ID/flags field",
1010 "Whether the CAN ID/flags field should be byte-swapped in CAN classic and CAN FD packets",
1011 &byte_swap);
1013 prefs_register_bool_preference(can_module, "try_heuristic_first", "Try heuristic sub-dissectors first",
1014 "Try to decode a packet using an heuristic sub-dissector before using a sub-dissector registered to \"decode as\"",
1015 &heuristic_first);
1017 can_id_dissector_table = register_dissector_table("can.id", "CAN ID", proto_can, FT_UINT32, BASE_DEC);
1019 can_extended_id_dissector_table = register_dissector_table("can.extended_id", "CAN Extended ID", proto_can, FT_UINT32, BASE_DEC);
1021 subdissector_table = register_decode_as_next_proto(proto_can, "can.subdissector", "CAN next level dissector", NULL);
1023 canxl_sdu_type_dissector_table = register_dissector_table("canxl.sdu_type", "CAN XL SDU type", proto_canxl, FT_UINT8, BASE_HEX);
1025 heur_subdissector_list = register_heur_dissector_list_with_description("can", "CAN heuristic", proto_can);
1027 static uat_field_t can_interface_mapping_uat_fields[] = {
1028 UAT_FLD_HEX(interface_configs, interface_id, "Interface ID", "ID of the Interface with 0xffffffff = any (hex uint32 without leading 0x)"),
1029 UAT_FLD_CSTRING(interface_configs, interface_name, "Interface Name", "Name of the Interface, empty = any (string)"),
1030 UAT_FLD_HEX(interface_configs, bus_id, "Bus ID", "Bus ID of the Interface (hex uint16 without leading 0x)"),
1031 UAT_END_FIELDS
1034 can_interface_uat = uat_new("CAN Interface Mapping",
1035 sizeof(interface_config_t), /* record size */
1036 DATAFILE_CAN_INTERFACE_MAPPING, /* filename */
1037 true, /* from profile */
1038 (void**)&interface_configs, /* data_ptr */
1039 &interface_config_num, /* numitems_ptr */
1040 UAT_AFFECTS_DISSECTION, /* but not fields */
1041 NULL, /* help */
1042 copy_interface_config_cb, /* copy callback */
1043 update_interface_config, /* update callback */
1044 free_interface_config_cb, /* free callback */
1045 post_update_can_interfaces_cb, /* post update callback */
1046 NULL, /* reset callback */
1047 can_interface_mapping_uat_fields /* UAT field definitions */
1050 prefs_register_uat_preference(can_module, "_can_interface_mapping", "Interface Mapping",
1051 "A table to define the mapping between interface and Bus ID.", can_interface_uat);
1053 static uat_field_t sender_receiver_mapping_uat_fields[] = {
1054 UAT_FLD_HEX(sender_receiver_configs, bus_id, "Bus ID", "Bus ID of the Interface with 0 meaning any (hex uint16 without leading 0x)."),
1055 UAT_FLD_HEX(sender_receiver_configs, can_id, "CAN ID", "ID of the CAN Message (hex uint32 without leading 0x)"),
1056 UAT_FLD_CSTRING(sender_receiver_configs, sender_name, "Sender Name", "Name of Sender(s)"),
1057 UAT_FLD_CSTRING(sender_receiver_configs, receiver_name, "Receiver Name", "Name of Receiver(s)"),
1058 UAT_END_FIELDS
1061 sender_receiver_uat = uat_new("Sender Receiver Config",
1062 sizeof(sender_receiver_config_t), /* record size */
1063 DATAFILE_CAN_SENDER_RECEIVER, /* filename */
1064 true, /* from profile */
1065 (void**)&sender_receiver_configs, /* data_ptr */
1066 &sender_receiver_config_num, /* numitems_ptr */
1067 UAT_AFFECTS_DISSECTION, /* but not fields */
1068 NULL, /* help */
1069 copy_sender_receiver_config_cb, /* copy callback */
1070 update_sender_receiver_config, /* update callback */
1071 free_sender_receiver_config_cb, /* free callback */
1072 post_update_sender_receiver_cb, /* post update callback */
1073 NULL, /* reset callback */
1074 sender_receiver_mapping_uat_fields /* UAT field definitions */
1077 prefs_register_uat_preference(can_module, "_sender_receiver_config", "Sender Receiver Config",
1078 "A table to define the mapping between Bus ID and CAN ID to Sender and Receiver.", sender_receiver_uat);
1081 void
1082 proto_reg_handoff_socketcan(void) {
1083 dissector_add_uint("wtap_encap", WTAP_ENCAP_SOCKETCAN, socketcan_bigendian_handle);
1085 dissector_add_uint("sll.ltype", LINUX_SLL_P_CAN, socketcan_classic_handle);
1086 dissector_add_uint("sll.ltype", LINUX_SLL_P_CANFD, socketcan_fd_handle);
1087 dissector_add_uint("sll.ltype", LINUX_SLL_P_CANXL, socketcan_xl_handle);
1091 * Editor modelines - https://www.wireshark.org/tools/modelines.html
1093 * Local variables:
1094 * c-basic-offset: 4
1095 * tab-width: 8
1096 * indent-tabs-mode: nil
1097 * End:
1099 * vi: set shiftwidth=4 tabstop=8 expandtab:
1100 * :indentSize=4:tabSize=8:noTabs=true: