diff options
author | Stefan Tatschner <stefan@rumpelsepp.org> | 2019-11-28 08:03:51 +0100 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2019-11-28 18:27:16 +0000 |
commit | 40eece98f8e6bc9a0a8f0961e43e95f538322aec (patch) | |
tree | 90b5fa36b1e892a1f554d025d5febe33c00da1a5 /epan/dissectors | |
parent | bb7014731cfa39f7742f552f2817461b75ed084f (diff) |
Change struct can_identifier to can_info
The can specific data structure `struct can_identifier` is used as
supplementary data for higher level dissectors. This patch adds more
data to this struct and renames it accordingly to `struct can_info`.
More supplementary data is needed in order to dissect iso15765
correctly, since the header format depends on details on the underlying
CAN protocol (CAN 2.0B vs CAN-FD).
Change-Id: Id068cf38453f98b67a5ec470a22e7013548c5a14
Reviewed-on: https://code.wireshark.org/review/35246
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan/dissectors')
-rw-r--r-- | epan/dissectors/packet-autosar-nm.c | 8 | ||||
-rw-r--r-- | epan/dissectors/packet-caneth.c | 10 | ||||
-rw-r--r-- | epan/dissectors/packet-canopen.c | 16 | ||||
-rw-r--r-- | epan/dissectors/packet-devicenet.c | 50 | ||||
-rw-r--r-- | epan/dissectors/packet-ieee1722.c | 16 | ||||
-rw-r--r-- | epan/dissectors/packet-iso15765.c | 8 | ||||
-rw-r--r-- | epan/dissectors/packet-isobus.c | 38 | ||||
-rw-r--r-- | epan/dissectors/packet-j1939.c | 38 | ||||
-rw-r--r-- | epan/dissectors/packet-obd-ii.c | 10 | ||||
-rw-r--r-- | epan/dissectors/packet-socketcan.c | 90 | ||||
-rw-r--r-- | epan/dissectors/packet-socketcan.h | 6 |
11 files changed, 146 insertions, 144 deletions
diff --git a/epan/dissectors/packet-autosar-nm.c b/epan/dissectors/packet-autosar-nm.c index a3b90fa240..e471089e0c 100644 --- a/epan/dissectors/packet-autosar-nm.c +++ b/epan/dissectors/packet-autosar-nm.c @@ -398,7 +398,7 @@ dissect_autosar_nm(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void const int prev_proto = GPOINTER_TO_INT(wmem_list_frame_data(prev_layer)); if (prev_proto != proto_udp) { - const can_identifier_t *can_id = (can_identifier_t *)data; + const struct can_info *can_info = (struct can_info *)data; const gboolean is_can_frame = (prev_proto == proto_can) || (prev_proto == proto_canfd) || @@ -409,14 +409,14 @@ dissect_autosar_nm(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void return 0; } - DISSECTOR_ASSERT(can_id); + DISSECTOR_ASSERT(can_info); - if (can_id->id & (CAN_ERR_FLAG | CAN_RTR_FLAG)) { + if (can_info->id & (CAN_ERR_FLAG | CAN_RTR_FLAG)) { /* Error and RTR frames are not for us. */ return 0; } - if ((can_id->id & g_autosar_nm_can_id_mask) != (g_autosar_nm_can_id & g_autosar_nm_can_id_mask)) { + if ((can_info->id & g_autosar_nm_can_id_mask) != (g_autosar_nm_can_id & g_autosar_nm_can_id_mask)) { /* Id doesn't match. The frame is not for us. */ return 0; } diff --git a/epan/dissectors/packet-caneth.c b/epan/dissectors/packet-caneth.c index 0b9db3aa0b..773f9e2c44 100644 --- a/epan/dissectors/packet-caneth.c +++ b/epan/dissectors/packet-caneth.c @@ -96,7 +96,7 @@ dissect_caneth_can(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *da gint8 ext_flag; gint8 rtr_flag; tvbuff_t* next_tvb; - struct can_identifier can_id; + struct can_info can_info; ti = proto_tree_add_item(tree, proto_can, tvb, 0, -1, ENC_NA); can_tree = proto_item_add_subtree(ti, ett_caneth_can); @@ -107,14 +107,14 @@ dissect_caneth_can(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *da if (ext_flag) { - can_id.id = raw_can_id & CAN_EFF_MASK; + can_info.id = raw_can_id & CAN_EFF_MASK; } else { - can_id.id = raw_can_id & CAN_SFF_MASK; + can_info.id = raw_can_id & CAN_SFF_MASK; } - can_id.id |= (ext_flag ? CAN_EFF_FLAG : 0) | (rtr_flag ? CAN_RTR_FLAG : 0); + can_info.id |= (ext_flag ? CAN_EFF_FLAG : 0) | (rtr_flag ? CAN_RTR_FLAG : 0); proto_tree_add_item_ret_uint(can_tree, hf_caneth_can_len, tvb, CAN_DLC_OFFSET, 1, ENC_NA, &data_len); proto_tree_add_item(can_tree, hf_caneth_can_extflag, tvb, CAN_EXT_FLAG_OFFSET, 1, ENC_NA); @@ -122,7 +122,7 @@ dissect_caneth_can(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *da next_tvb = tvb_new_subset_length(tvb, CAN_DATA_OFFSET, data_len); - if (!dissector_try_payload_new(can_subdissector_table, next_tvb, pinfo, tree, TRUE, &can_id)) + if (!dissector_try_payload_new(can_subdissector_table, next_tvb, pinfo, tree, TRUE, &can_info)) { call_data_dissector(next_tvb, pinfo, tree); } diff --git a/epan/dissectors/packet-canopen.c b/epan/dissectors/packet-canopen.c index 98170b737d..855371ae42 100644 --- a/epan/dissectors/packet-canopen.c +++ b/epan/dissectors/packet-canopen.c @@ -1067,7 +1067,7 @@ dissect_canopen(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data) guint node_id; guint32 time_stamp_msec; guint32 time_stamp_days; - struct can_identifier can_id; + struct can_info can_info; guint msg_type_id; nstime_t time_stamp; gint can_data_len = tvb_reported_length(tvb); @@ -1081,9 +1081,9 @@ dissect_canopen(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data) proto_tree *canopen_type_tree; DISSECTOR_ASSERT(data); - can_id = *((struct can_identifier*)data); + can_info = *((struct can_info*)data); - if (can_id.id & (CAN_ERR_FLAG | CAN_RTR_FLAG | CAN_EFF_FLAG)) + if (can_info.id & (CAN_ERR_FLAG | CAN_RTR_FLAG | CAN_EFF_FLAG)) { /* Error, RTR and frames with extended ids are not for us. */ return 0; @@ -1092,8 +1092,8 @@ dissect_canopen(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data) col_set_str(pinfo->cinfo, COL_PROTOCOL, "CANopen"); col_clear(pinfo->cinfo, COL_INFO); - node_id = can_id.id & 0x7F; - function_code = (can_id.id >> 7) & 0x0F; + node_id = can_info.id & 0x7F; + function_code = (can_info.id >> 7) & 0x0F; msg_type_id = canopen_detect_msg_type(function_code, node_id); @@ -1120,15 +1120,15 @@ dissect_canopen(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data) canopen_tree = proto_item_add_subtree(ti, ett_canopen); /* add COB-ID with function code and node id */ - cob_ti = proto_tree_add_uint(canopen_tree, hf_canopen_cob_id, tvb, 0, 0, can_id.id); + cob_ti = proto_tree_add_uint(canopen_tree, hf_canopen_cob_id, tvb, 0, 0, can_info.id); canopen_cob_tree = proto_item_add_subtree(cob_ti, ett_canopen_cob); /* add function code */ - ti = proto_tree_add_uint(canopen_cob_tree, hf_canopen_function_code, tvb, 0, 0, can_id.id); + ti = proto_tree_add_uint(canopen_cob_tree, hf_canopen_function_code, tvb, 0, 0, can_info.id); proto_item_set_generated(ti); /* add node id */ - ti = proto_tree_add_uint(canopen_cob_tree, hf_canopen_node_id, tvb, 0, 0, can_id.id); + ti = proto_tree_add_uint(canopen_cob_tree, hf_canopen_node_id, tvb, 0, 0, can_info.id); proto_item_set_generated(ti); /* add CANopen frame type */ diff --git a/epan/dissectors/packet-devicenet.c b/epan/dissectors/packet-devicenet.c index c0232d6499..02fcbba051 100644 --- a/epan/dissectors/packet-devicenet.c +++ b/epan/dissectors/packet-devicenet.c @@ -411,14 +411,14 @@ static int dissect_devicenet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree guint16 message_id; guint32 data_length = tvb_reported_length(tvb); guint8 source_mac; - struct can_identifier can_id; + struct can_info can_info; guint8 service_rr; guint8 *src_address, *dest_address; DISSECTOR_ASSERT(data); - can_id = *((struct can_identifier*)data); + can_info = *((struct can_info*)data); - if (can_id.id & (CAN_ERR_FLAG | CAN_RTR_FLAG | CAN_EFF_FLAG)) + if (can_info.id & (CAN_ERR_FLAG | CAN_RTR_FLAG | CAN_EFF_FLAG)) { /* Error, RTR and frames with extended ids are not for us. */ return 0; @@ -429,26 +429,26 @@ static int dissect_devicenet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree ti = proto_tree_add_item(tree, proto_devicenet, tvb, offset, -1, ENC_NA); devicenet_tree = proto_item_add_subtree(ti, ett_devicenet); - can_tree = proto_tree_add_subtree_format(devicenet_tree, tvb, 0, 0, ett_devicenet_can, NULL, "CAN Identifier: 0x%04x", can_id.id); - can_id_item = proto_tree_add_uint(can_tree, hf_devicenet_can_id, tvb, 0, 0, can_id.id); + can_tree = proto_tree_add_subtree_format(devicenet_tree, tvb, 0, 0, ett_devicenet_can, NULL, "CAN Identifier: 0x%04x", can_info.id); + can_id_item = proto_tree_add_uint(can_tree, hf_devicenet_can_id, tvb, 0, 0, can_info.id); proto_item_set_generated(can_id_item); /* * Message group 1 */ - if ( can_id.id <= MESSAGE_GROUP_1_ID ) + if ( can_info.id <= MESSAGE_GROUP_1_ID ) { - ti = proto_tree_add_uint(can_tree, hf_devicenet_grp_msg1_id, tvb, 0, 0, can_id.id); + ti = proto_tree_add_uint(can_tree, hf_devicenet_grp_msg1_id, tvb, 0, 0, can_info.id); proto_item_set_generated(ti); - ti = proto_tree_add_uint(can_tree, hf_devicenet_src_mac_id, tvb, 0, 0, can_id.id & MESSAGE_GROUP_1_MAC_ID_MASK); + ti = proto_tree_add_uint(can_tree, hf_devicenet_src_mac_id, tvb, 0, 0, can_info.id & MESSAGE_GROUP_1_MAC_ID_MASK); proto_item_set_generated(ti); /* Set source address */ src_address = (guint8*)wmem_alloc(pinfo->pool, 1); - *src_address = (guint8)(can_id.id & MESSAGE_GROUP_1_MAC_ID_MASK); + *src_address = (guint8)(can_info.id & MESSAGE_GROUP_1_MAC_ID_MASK); set_address(&pinfo->src, devicenet_address_type, 1, (const void*)src_address); - message_id = can_id.id & MESSAGE_GROUP_1_MSG_MASK; + message_id = can_info.id & MESSAGE_GROUP_1_MSG_MASK; col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(message_id, devicenet_grp_msg1_vals, "Other Group 1 Message")); proto_tree_add_item(devicenet_tree, hf_devicenet_data, tvb, offset, data_length, ENC_NA); @@ -456,21 +456,21 @@ static int dissect_devicenet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree /* * Message group 2 */ - else if (can_id.id <= MESSAGE_GROUP_2_ID ) + else if (can_info.id <= MESSAGE_GROUP_2_ID ) { - ti = proto_tree_add_uint(can_tree, hf_devicenet_grp_msg2_id, tvb, 0, 0, can_id.id); + ti = proto_tree_add_uint(can_tree, hf_devicenet_grp_msg2_id, tvb, 0, 0, can_info.id); proto_item_set_generated(ti); /* create display subtree for the protocol */ - message_id = can_id.id & MESSAGE_GROUP_2_MSG_MASK; + message_id = can_info.id & MESSAGE_GROUP_2_MSG_MASK; col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(message_id, devicenet_grp_msg2_vals, "Unknown")); - ti = proto_tree_add_uint(can_tree, hf_devicenet_src_mac_id, tvb, 0, 0, (can_id.id & MESSAGE_GROUP_2_MAC_ID_MASK) >> 3); + ti = proto_tree_add_uint(can_tree, hf_devicenet_src_mac_id, tvb, 0, 0, (can_info.id & MESSAGE_GROUP_2_MAC_ID_MASK) >> 3); proto_item_set_generated(ti); /* Set source address */ src_address = (guint8*)wmem_alloc(pinfo->pool, 1); - *src_address = (guint8)((can_id.id & MESSAGE_GROUP_2_MAC_ID_MASK) >> 3); + *src_address = (guint8)((can_info.id & MESSAGE_GROUP_2_MAC_ID_MASK) >> 3); set_address(&pinfo->src, devicenet_address_type, 1, (const void*)src_address); content_tree = proto_tree_add_subtree(devicenet_tree, tvb, offset, -1, ett_devicenet_contents, NULL, "Contents"); @@ -505,21 +505,21 @@ static int dissect_devicenet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree /* * Message group 3 */ - else if (can_id.id <= MESSAGE_GROUP_3_ID ) + else if (can_info.id <= MESSAGE_GROUP_3_ID ) { guint8 byte1; - msg_id_item = proto_tree_add_uint(can_tree, hf_devicenet_grp_msg3_id, tvb, 0, 0, can_id.id); + msg_id_item = proto_tree_add_uint(can_tree, hf_devicenet_grp_msg3_id, tvb, 0, 0, can_info.id); proto_item_set_generated(msg_id_item); - ti = proto_tree_add_uint(can_tree, hf_devicenet_src_mac_id, tvb, 0, 0, can_id.id & MESSAGE_GROUP_3_MAC_ID_MASK); + ti = proto_tree_add_uint(can_tree, hf_devicenet_src_mac_id, tvb, 0, 0, can_info.id & MESSAGE_GROUP_3_MAC_ID_MASK); proto_item_set_generated(ti); /* Set source address */ src_address = (guint8*)wmem_alloc(pinfo->pool, 1); - *src_address = (guint8)(can_id.id & MESSAGE_GROUP_3_MAC_ID_MASK); + *src_address = (guint8)(can_info.id & MESSAGE_GROUP_3_MAC_ID_MASK); set_address(&pinfo->src, devicenet_address_type, 1, (const void*)src_address); - message_id = can_id.id & MESSAGE_GROUP_3_MSG_MASK; + message_id = can_info.id & MESSAGE_GROUP_3_MSG_MASK; col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(message_id, devicenet_grp_msg3_vals, "Unknown")); proto_tree_add_item(devicenet_tree, hf_devicenet_grp_msg3_frag, tvb, offset, 1, ENC_NA); @@ -684,12 +684,12 @@ static int dissect_devicenet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree } } /*Message group 4*/ - else if (can_id.id <= MESSAGE_GROUP_4_ID ) + else if (can_info.id <= MESSAGE_GROUP_4_ID ) { - ti = proto_tree_add_uint(can_tree, hf_devicenet_grp_msg4_id, tvb, 0, 0, can_id.id); + ti = proto_tree_add_uint(can_tree, hf_devicenet_grp_msg4_id, tvb, 0, 0, can_info.id); proto_item_set_generated(ti); - message_id = can_id.id & MESSAGE_GROUP_4_MSG_MASK; + message_id = can_info.id & MESSAGE_GROUP_4_MSG_MASK; col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(message_id, devicenet_grp_msg4_vals, "Reserved Group 4 Message")); switch(message_id) @@ -766,9 +766,9 @@ static int dissect_devicenet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree /*Invalid CAN message*/ else { - col_add_fstr(pinfo->cinfo, COL_INFO, "Invalid CAN Message 0x%06X", can_id.id); + col_add_fstr(pinfo->cinfo, COL_INFO, "Invalid CAN Message 0x%06X", can_info.id); expert_add_info_format(pinfo, can_id_item, &ei_devicenet_invalid_can_id, - "Invalid CAN Message 0x%04X", can_id.id); + "Invalid CAN Message 0x%04X", can_info.id); } return tvb_captured_length(tvb); diff --git a/epan/dissectors/packet-ieee1722.c b/epan/dissectors/packet-ieee1722.c index a07cf2d56f..3cb4fa74e0 100644 --- a/epan/dissectors/packet-ieee1722.c +++ b/epan/dissectors/packet-ieee1722.c @@ -2473,7 +2473,7 @@ static int dissect_1722_acf_can_common(tvbuff_t *tvb, packet_info *pinfo, proto_ proto_tree *tree_can_id; gint can_protocol; const int **can_flags; - can_identifier_t can_id; + struct can_info can_info; tvbuff_t* next_tvb; gint offset = 0; @@ -2597,24 +2597,24 @@ static int dissect_1722_acf_can_common(tvbuff_t *tvb, packet_info *pinfo, proto_ * CAN sub-dissectors expect several flags to be merged into ID that is passed * to dissector_try_payload_new. Add them */ - can_id.id = parsed.id; + can_info.id = parsed.id; if (parsed.is_xtd) { - can_id.id |= CAN_EFF_FLAG; + can_info.id |= CAN_EFF_FLAG; } if (parsed.is_rtr) { - can_id.id |= CAN_RTR_FLAG; + can_info.id |= CAN_RTR_FLAG; } next_tvb = tvb_new_subset_length(tvb, offset, parsed.datalen); if(!can_heuristic_first) { - if (!dissector_try_payload_new(can_subdissector_table, next_tvb, pinfo, tree, TRUE, &can_id)) + if (!dissector_try_payload_new(can_subdissector_table, next_tvb, pinfo, tree, TRUE, &can_info)) { - if(!dissector_try_heuristic(can_heur_subdissector_table, next_tvb, pinfo, tree, &can_heur_dtbl_entry, &can_id)) + if(!dissector_try_heuristic(can_heur_subdissector_table, next_tvb, pinfo, tree, &can_heur_dtbl_entry, &can_info)) { call_data_dissector(next_tvb, pinfo, tree); } @@ -2622,9 +2622,9 @@ static int dissect_1722_acf_can_common(tvbuff_t *tvb, packet_info *pinfo, proto_ } else { - if (!dissector_try_heuristic(can_heur_subdissector_table, next_tvb, pinfo, tree, &can_heur_dtbl_entry, &can_id)) + if (!dissector_try_heuristic(can_heur_subdissector_table, next_tvb, pinfo, tree, &can_heur_dtbl_entry, &can_info)) { - if(!dissector_try_payload_new(can_subdissector_table, next_tvb, pinfo, tree, FALSE, &can_id)) + if(!dissector_try_payload_new(can_subdissector_table, next_tvb, pinfo, tree, FALSE, &can_info)) { call_data_dissector(next_tvb, pinfo, tree); } diff --git a/epan/dissectors/packet-iso15765.c b/epan/dissectors/packet-iso15765.c index ea7cadeedf..711739bf67 100644 --- a/epan/dissectors/packet-iso15765.c +++ b/epan/dissectors/packet-iso15765.c @@ -161,7 +161,7 @@ dissect_iso15765(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data proto_item *message_type_item; tvbuff_t* next_tvb = NULL; guint8 pci, message_type; - can_identifier_t can_id; + struct can_info can_info; iso15765_identifier_t* iso15765_info; guint8 ae = (addressing == NORMAL_ADDRESSING)?0:1; guint8 frag_id_low = 0; @@ -171,9 +171,9 @@ dissect_iso15765(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data gboolean complete = FALSE; DISSECTOR_ASSERT(data); - can_id = *((can_identifier_t*)data); + can_info = *((struct can_info*)data); - if (can_id.id & (CAN_ERR_FLAG | CAN_RTR_FLAG)) + if (can_info.id & (CAN_ERR_FLAG | CAN_RTR_FLAG)) { /* Error and RTR frames are not for us. */ return 0; @@ -186,7 +186,7 @@ dissect_iso15765(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data if (!iso15765_info) { iso15765_info = wmem_new0(wmem_file_scope(), iso15765_identifier_t); - iso15765_info->id = can_id.id; + iso15765_info->id = can_info.id; iso15765_info->last = FALSE; p_add_proto_data(wmem_file_scope(), pinfo, proto_iso15765, 0, iso15765_info); } diff --git a/epan/dissectors/packet-isobus.c b/epan/dissectors/packet-isobus.c index 92092cc70d..1a36fa4b20 100644 --- a/epan/dissectors/packet-isobus.c +++ b/epan/dissectors/packet-isobus.c @@ -298,7 +298,7 @@ dissect_isobus(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data) guint data_page; guint pdu_format; guint pdu_specific; - struct can_identifier can_id; + struct can_info can_info; char str_dst[10]; char str_src[4]; @@ -314,10 +314,10 @@ dissect_isobus(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data) struct address_reassemble_table* address_reassemble_table_item = NULL; DISSECTOR_ASSERT(data); - can_id = *((struct can_identifier*)data); + can_info = *((struct can_info*)data); - if ((can_id.id & (CAN_ERR_FLAG | CAN_RTR_FLAG)) || - !(can_id.id & CAN_EFF_FLAG)) + if ((can_info.id & (CAN_ERR_FLAG | CAN_RTR_FLAG)) || + !(can_info.id & CAN_EFF_FLAG)) { /* Error, RTR and frames with standard ids are not for us. */ return 0; @@ -326,41 +326,41 @@ dissect_isobus(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data) col_set_str(pinfo->cinfo, COL_PROTOCOL, "ISObus"); col_clear(pinfo->cinfo, COL_INFO); - /*priority = (can_id.id >> 26) & 0x07;*/ - /*ext_data_page = (can_id.id >> 25) & 0x01;*/ - data_page = (can_id.id >> 24) & 0x01; - pdu_format = (can_id.id >> 16) & 0xff; - pdu_specific = (can_id.id >> 8) & 0xff; - src_addr = (can_id.id >> 0 ) & 0xff; + /*priority = (can_info.id >> 26) & 0x07;*/ + /*ext_data_page = (can_info.id >> 25) & 0x01;*/ + data_page = (can_info.id >> 24) & 0x01; + pdu_format = (can_info.id >> 16) & 0xff; + pdu_specific = (can_info.id >> 8) & 0xff; + src_addr = (can_info.id >> 0 ) & 0xff; ti = proto_tree_add_item(tree, proto_isobus, tvb, 0, tvb_reported_length(tvb), ENC_NA); isobus_tree = proto_item_add_subtree(ti, ett_isobus); /* add COB-ID with function code and node id */ - can_id_ti = proto_tree_add_uint(isobus_tree, hf_isobus_can_id, tvb, 0, 0, can_id.id); + can_id_ti = proto_tree_add_uint(isobus_tree, hf_isobus_can_id, tvb, 0, 0, can_info.id); isobus_can_id_tree = proto_item_add_subtree(can_id_ti, ett_isobus_can_id); /* add priority */ - ti = proto_tree_add_uint(isobus_can_id_tree, hf_isobus_priority, tvb, 0, 0, can_id.id); + ti = proto_tree_add_uint(isobus_can_id_tree, hf_isobus_priority, tvb, 0, 0, can_info.id); proto_item_set_generated(ti); /* add extended data page */ - ti = proto_tree_add_uint(isobus_can_id_tree, hf_isobus_ext_data_page, tvb, 0, 0, can_id.id); + ti = proto_tree_add_uint(isobus_can_id_tree, hf_isobus_ext_data_page, tvb, 0, 0, can_info.id); proto_item_set_generated(ti); /* add data page */ - ti = proto_tree_add_uint(isobus_can_id_tree, hf_isobus_data_page, tvb, 0, 0, can_id.id); + ti = proto_tree_add_uint(isobus_can_id_tree, hf_isobus_data_page, tvb, 0, 0, can_info.id); proto_item_set_generated(ti); /* add pdu format */ switch(data_page) { case 0: - ti = proto_tree_add_uint(isobus_can_id_tree, hf_isobus_pdu_format_dp0, tvb, 0, 0, can_id.id); + ti = proto_tree_add_uint(isobus_can_id_tree, hf_isobus_pdu_format_dp0, tvb, 0, 0, can_info.id); proto_item_set_generated(ti); break; case 1: - ti = proto_tree_add_uint(isobus_can_id_tree, hf_isobus_pdu_format_dp1, tvb, 0, 0, can_id.id); + ti = proto_tree_add_uint(isobus_can_id_tree, hf_isobus_pdu_format_dp1, tvb, 0, 0, can_info.id); proto_item_set_generated(ti); break; } @@ -368,17 +368,17 @@ dissect_isobus(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data) /* add pdu specific */ if(pdu_format <= 239) { - ti = proto_tree_add_uint(isobus_can_id_tree, hf_isobus_dst_addr, tvb, 0, 0, can_id.id); + ti = proto_tree_add_uint(isobus_can_id_tree, hf_isobus_dst_addr, tvb, 0, 0, can_info.id); proto_item_set_generated(ti); } else { - ti = proto_tree_add_uint(isobus_can_id_tree, hf_isobus_group_extension, tvb, 0, 0, can_id.id); + ti = proto_tree_add_uint(isobus_can_id_tree, hf_isobus_group_extension, tvb, 0, 0, can_info.id); proto_item_set_generated(ti); } /* add source address */ - ti = proto_tree_add_uint(isobus_can_id_tree, hf_isobus_src_addr, tvb, 0, 0, can_id.id); + ti = proto_tree_add_uint(isobus_can_id_tree, hf_isobus_src_addr, tvb, 0, 0, can_info.id); proto_item_set_generated(ti); /* put source address in source field */ diff --git a/epan/dissectors/packet-j1939.c b/epan/dissectors/packet-j1939.c index b7870eb452..3307e06e82 100644 --- a/epan/dissectors/packet-j1939.c +++ b/epan/dissectors/packet-j1939.c @@ -162,16 +162,16 @@ static int dissect_j1939(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, vo proto_tree *j1939_tree, *can_tree, *msg_tree; gint offset = 0; - struct can_identifier can_id; + struct can_info can_info; guint32 data_length = tvb_reported_length(tvb); guint32 pgn; guint8 *src_addr, *dest_addr; DISSECTOR_ASSERT(data); - can_id = *((struct can_identifier*)data); + can_info = *((struct can_info*)data); - if ((can_id.id & CAN_ERR_FLAG) || - !(can_id.id & CAN_EFF_FLAG)) + if ((can_info.id & CAN_ERR_FLAG) || + !(can_info.id & CAN_EFF_FLAG)) { /* Error frames and frames with standards ids are not for us */ return 0; @@ -184,51 +184,51 @@ static int dissect_j1939(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, vo j1939_tree = proto_item_add_subtree(ti, ett_j1939); can_tree = proto_tree_add_subtree_format(j1939_tree, tvb, 0, 0, - ett_j1939_can, NULL, "CAN Identifier: 0x%08x", can_id.id); - can_id_item = proto_tree_add_uint(can_tree, hf_j1939_can_id, tvb, 0, 0, can_id.id); + ett_j1939_can, NULL, "CAN Identifier: 0x%08x", can_info.id); + can_id_item = proto_tree_add_uint(can_tree, hf_j1939_can_id, tvb, 0, 0, can_info.id); proto_item_set_generated(can_id_item); - ti = proto_tree_add_uint(can_tree, hf_j1939_priority, tvb, 0, 0, can_id.id); + ti = proto_tree_add_uint(can_tree, hf_j1939_priority, tvb, 0, 0, can_info.id); proto_item_set_generated(ti); - ti = proto_tree_add_uint(can_tree, hf_j1939_extended_data_page, tvb, 0, 0, can_id.id); + ti = proto_tree_add_uint(can_tree, hf_j1939_extended_data_page, tvb, 0, 0, can_info.id); proto_item_set_generated(ti); - ti = proto_tree_add_uint(can_tree, hf_j1939_data_page, tvb, 0, 0, can_id.id); + ti = proto_tree_add_uint(can_tree, hf_j1939_data_page, tvb, 0, 0, can_info.id); proto_item_set_generated(ti); - ti = proto_tree_add_uint(can_tree, hf_j1939_pdu_format, tvb, 0, 0, can_id.id); + ti = proto_tree_add_uint(can_tree, hf_j1939_pdu_format, tvb, 0, 0, can_info.id); proto_item_set_generated(ti); - ti = proto_tree_add_uint(can_tree, hf_j1939_pdu_specific, tvb, 0, 0, can_id.id); + ti = proto_tree_add_uint(can_tree, hf_j1939_pdu_specific, tvb, 0, 0, can_info.id); proto_item_set_generated(ti); - ti = proto_tree_add_uint(can_tree, hf_j1939_src_addr, tvb, 0, 0, can_id.id); + ti = proto_tree_add_uint(can_tree, hf_j1939_src_addr, tvb, 0, 0, can_info.id); proto_item_set_generated(ti); /* Set source address */ src_addr = (guint8*)wmem_alloc(pinfo->pool, 1); - *src_addr = (guint8)(can_id.id & 0xFF); + *src_addr = (guint8)(can_info.id & 0xFF); set_address(&pinfo->src, j1939_address_type, 1, (const void*)src_addr); - pgn = (can_id.id & 0x3FFFF00) >> 8; + pgn = (can_info.id & 0x3FFFF00) >> 8; /* If PF < 240, PS is destination address, last byte of PGN is cleared */ - if (((can_id.id & 0xFF0000) >> 16) < 240) + if (((can_info.id & 0xFF0000) >> 16) < 240) { pgn &= 0x3FF00; - ti = proto_tree_add_uint(can_tree, hf_j1939_dst_addr, tvb, 0, 0, can_id.id); + ti = proto_tree_add_uint(can_tree, hf_j1939_dst_addr, tvb, 0, 0, can_info.id); proto_item_set_generated(ti); } else { - ti = proto_tree_add_uint(can_tree, hf_j1939_group_extension, tvb, 0, 0, can_id.id); + ti = proto_tree_add_uint(can_tree, hf_j1939_group_extension, tvb, 0, 0, can_info.id); proto_item_set_generated(ti); } /* Fill in "destination" address even if its "broadcast" */ dest_addr = (guint8*)wmem_alloc(pinfo->pool, 1); - *dest_addr = (guint8)((can_id.id & 0xFF00) >> 8); + *dest_addr = (guint8)((can_info.id & 0xFF00) >> 8); set_address(&pinfo->dst, j1939_address_type, 1, (const void*)dest_addr); col_add_fstr(pinfo->cinfo, COL_INFO, "PGN: %-6" PRIu32, pgn); - if (can_id.id & CAN_RTR_FLAG) + if (can_info.id & CAN_RTR_FLAG) { /* RTR frames don't have payload */ col_append_fstr(pinfo->cinfo, COL_INFO, " %s", "(Remote Transmission Request)"); diff --git a/epan/dissectors/packet-obd-ii.c b/epan/dissectors/packet-obd-ii.c index 0e07968ff7..4f0238ad0d 100644 --- a/epan/dissectors/packet-obd-ii.c +++ b/epan/dissectors/packet-obd-ii.c @@ -1278,7 +1278,7 @@ dissect_obdii_response(tvbuff_t *tvb, struct obdii_packet_info *oinfo, proto_tre static int dissect_obdii(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) { - struct can_identifier can_id; + struct can_info can_info; guint32 can_id_only; struct obdii_packet_info oinfo; @@ -1291,11 +1291,11 @@ dissect_obdii(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) gboolean id_is_response; DISSECTOR_ASSERT(data); - can_id = *((struct can_identifier *) data); - can_id_only = can_id.id & CAN_EFF_MASK; + can_info = *((struct can_info *) data); + can_id_only = can_info.id & CAN_EFF_MASK; /* If we're using 29bit extended ID's then use extended ID parameters */ - if (can_id.id & CAN_EFF_FLAG) + if (can_info.id & CAN_EFF_FLAG) { id_is_query = (can_id_only == ODBII_CAN_QUERY_ID_EFF); id_is_response = ((((can_id_only & ~ODBII_CAN_RESPONSE_ID_LOWER_MASK_EFF) ^ ODBII_CAN_RESPONSE_ID_LOWER_MIN_EFF) == 0) || @@ -1309,7 +1309,7 @@ dissect_obdii(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) } /* validate */ - if (can_id.id & (CAN_ERR_FLAG | CAN_RTR_FLAG)) + if (can_info.id & (CAN_ERR_FLAG | CAN_RTR_FLAG)) return 0; if (!(id_is_query || id_is_response)) diff --git a/epan/dissectors/packet-socketcan.c b/epan/dissectors/packet-socketcan.c index f894037afe..8b459360d5 100644 --- a/epan/dissectors/packet-socketcan.c +++ b/epan/dissectors/packet-socketcan.c @@ -28,8 +28,8 @@ void proto_register_socketcan(void); void proto_reg_handoff_socketcan(void); static int hf_can_len = -1; -static int hf_can_ident_ext = -1; -static int hf_can_ident_std = -1; +static int hf_can_infoent_ext = -1; +static int hf_can_infoent_std = -1; static int hf_can_extflag = -1; static int hf_can_rtrflag = -1; static int hf_can_errflag = -1; @@ -168,19 +168,18 @@ dissect_socketcan_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_tree *can_tree; proto_item *ti; guint8 frame_type; - gint frame_len; - struct can_identifier can_id; + struct can_info can_info; const int **can_flags; static const int *can_std_flags[] = { - &hf_can_ident_std, + &hf_can_infoent_std, &hf_can_extflag, &hf_can_rtrflag, &hf_can_errflag, NULL, }; static const int *can_ext_flags[] = { - &hf_can_ident_ext, + &hf_can_infoent_ext, &hf_can_extflag, &hf_can_rtrflag, &hf_can_errflag, @@ -201,25 +200,26 @@ dissect_socketcan_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, NULL, }; - can_id.id = tvb_get_guint32(tvb, 0, encoding); - frame_len = tvb_get_guint8(tvb, CAN_LEN_OFFSET); + can_info.id = tvb_get_guint32(tvb, 0, encoding); + can_info.len = tvb_get_guint8(tvb, CAN_LEN_OFFSET); + can_info.fd = FALSE; /* Error Message Frames are only encapsulated in Classic CAN frames */ - if (can_id.id & CAN_ERR_FLAG) + if (can_info.id & CAN_ERR_FLAG) { frame_type = LINUX_CAN_ERR; can_flags = can_err_flags; } - else if (can_id.id & CAN_EFF_FLAG) + else if (can_info.id & CAN_EFF_FLAG) { frame_type = LINUX_CAN_EXT; - can_id.id &= (CAN_EFF_MASK | CAN_FLAG_MASK); + can_info.id &= (CAN_EFF_MASK | CAN_FLAG_MASK); can_flags = can_ext_flags; } else { frame_type = LINUX_CAN_STD; - can_id.id &= (CAN_SFF_MASK | CAN_FLAG_MASK); + can_info.id &= (CAN_SFF_MASK | CAN_FLAG_MASK); can_flags = can_std_flags; } @@ -231,7 +231,7 @@ dissect_socketcan_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_tree_add_bitmask_list(can_tree, tvb, 0, 4, can_flags, encoding); proto_tree_add_item(can_tree, hf_can_len, tvb, CAN_LEN_OFFSET, 1, ENC_NA); - if (frame_type == LINUX_CAN_ERR && frame_len != CAN_ERR_DLC) + if (frame_type == LINUX_CAN_ERR && can_info.len != CAN_ERR_DLC) { proto_tree_add_expert(tree, pinfo, &ei_can_err_dlc_mismatch, tvb, CAN_LEN_OFFSET, 1); } @@ -252,16 +252,16 @@ dissect_socketcan_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, if (!hfi) continue; - if ((can_id.id & hfi->bitmask & ~CAN_FLAG_MASK) == 0) + if ((can_info.id & hfi->bitmask & ~CAN_FLAG_MASK) == 0) continue; col_append_sep_str(pinfo->cinfo, COL_INFO, sepa, hfi->name); sepa = ", "; } - if (can_id.id & CAN_ERR_LOSTARB) + if (can_info.id & CAN_ERR_LOSTARB) proto_tree_add_item(can_tree, hf_can_err_lostarb_bit_number, tvb, CAN_DATA_OFFSET+0, 1, ENC_NA); - if (can_id.id & CAN_ERR_CTRL) + if (can_info.id & CAN_ERR_CTRL) { static const int *can_err_ctrl_flags[] = { &hf_can_err_ctrl_rx_overflow, @@ -276,7 +276,7 @@ dissect_socketcan_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_tree_add_bitmask_list(can_tree, tvb, CAN_DATA_OFFSET+1, 1, can_err_ctrl_flags, ENC_NA); } - if (can_id.id & CAN_ERR_PROT) + if (can_info.id & CAN_ERR_PROT) { static const int *can_err_prot_error_type_flags[] = { &hf_can_err_prot_error_type_bit, @@ -292,7 +292,7 @@ dissect_socketcan_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_tree_add_bitmask_list(can_tree, tvb, CAN_DATA_OFFSET+2, 1, can_err_prot_error_type_flags, ENC_NA); proto_tree_add_item(can_tree, hf_can_err_prot_error_location, tvb, CAN_DATA_OFFSET+3, 1, ENC_NA); } - if (can_id.id & CAN_ERR_TRX) + if (can_info.id & CAN_ERR_TRX) { proto_tree_add_item(can_tree, hf_can_err_trx_canh, tvb, CAN_DATA_OFFSET+4, 1, ENC_NA); proto_tree_add_item(can_tree, hf_can_err_trx_canl, tvb, CAN_DATA_OFFSET+4, 1, ENC_NA); @@ -304,27 +304,27 @@ dissect_socketcan_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, tvbuff_t *next_tvb; col_add_fstr(pinfo->cinfo, COL_INFO, "%s: 0x%08x ", - val_to_str(frame_type, frame_type_vals, "Unknown (0x%02x)"), (can_id.id & ~CAN_FLAG_MASK)); + val_to_str(frame_type, frame_type_vals, "Unknown (0x%02x)"), (can_info.id & ~CAN_FLAG_MASK)); - if (can_id.id & CAN_RTR_FLAG) + if (can_info.id & CAN_RTR_FLAG) { col_append_str(pinfo->cinfo, COL_INFO, "(Remote Transmission Request)"); } else { - col_append_str(pinfo->cinfo, COL_INFO, tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, CAN_DATA_OFFSET, frame_len, ' ')); + col_append_str(pinfo->cinfo, COL_INFO, tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, CAN_DATA_OFFSET, can_info.len, ' ')); } - next_tvb = tvb_new_subset_length(tvb, CAN_DATA_OFFSET, frame_len); - if (!dissector_try_payload_new(subdissector_table, next_tvb, pinfo, tree, TRUE, &can_id)) + next_tvb = tvb_new_subset_length(tvb, CAN_DATA_OFFSET, can_info.len); + if (!dissector_try_payload_new(subdissector_table, next_tvb, pinfo, tree, TRUE, &can_info)) { call_data_dissector(next_tvb, pinfo, tree); } } - if (tvb_captured_length_remaining(tvb, CAN_DATA_OFFSET+frame_len) > 0) + if (tvb_captured_length_remaining(tvb, CAN_DATA_OFFSET+can_info.len) > 0) { - proto_tree_add_item(can_tree, hf_can_padding, tvb, CAN_DATA_OFFSET+frame_len, -1, ENC_NA); + proto_tree_add_item(can_tree, hf_can_padding, tvb, CAN_DATA_OFFSET+can_info.len, -1, ENC_NA); } return tvb_captured_length(tvb); @@ -359,11 +359,10 @@ dissect_socketcanfd_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_tree *can_tree; proto_item *ti; guint8 frame_type; - gint frame_len; - struct can_identifier can_id; + struct can_info can_info; tvbuff_t* next_tvb; int * can_flags_fd[] = { - &hf_can_ident_ext, + &hf_can_infoent_ext, &hf_can_extflag, NULL, }; @@ -373,27 +372,28 @@ dissect_socketcanfd_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, NULL, }; - can_id.id = tvb_get_guint32(tvb, 0, encoding); - frame_len = tvb_get_guint8(tvb, CAN_LEN_OFFSET); + can_info.id = tvb_get_guint32(tvb, 0, encoding); + can_info.len = tvb_get_guint8(tvb, CAN_LEN_OFFSET); + can_info.fd = TRUE; - if (can_id.id & CAN_EFF_FLAG) + if (can_info.id & CAN_EFF_FLAG) { frame_type = LINUX_CAN_EXT; - can_id.id &= (CAN_EFF_MASK | CAN_FLAG_MASK); + can_info.id &= (CAN_EFF_MASK | CAN_FLAG_MASK); } else { frame_type = LINUX_CAN_STD; - can_id.id &= (CAN_SFF_MASK | CAN_FLAG_MASK); - can_flags_fd[0] = &hf_can_ident_std; + can_info.id &= (CAN_SFF_MASK | CAN_FLAG_MASK); + can_flags_fd[0] = &hf_can_infoent_std; } col_set_str(pinfo->cinfo, COL_PROTOCOL, "CANFD"); col_clear(pinfo->cinfo, COL_INFO); col_add_fstr(pinfo->cinfo, COL_INFO, "%s: 0x%08x %s", - val_to_str(frame_type, frame_type_vals, "Unknown (0x%02x)"), (can_id.id & ~CAN_FLAG_MASK), - tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, CAN_DATA_OFFSET, frame_len, ' ')); + val_to_str(frame_type, frame_type_vals, "Unknown (0x%02x)"), (can_info.id & ~CAN_FLAG_MASK), + tvb_bytes_to_str_punct(wmem_packet_scope(), tvb, CAN_DATA_OFFSET, can_info.len, ' ')); ti = proto_tree_add_item(tree, proto_canfd, tvb, 0, -1, ENC_NA); can_tree = proto_item_add_subtree(ti, ett_can_fd); @@ -404,13 +404,13 @@ dissect_socketcanfd_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_tree_add_bitmask_list(can_tree, tvb, CANFD_FLAG_OFFSET, 1, canfd_flag_fields, ENC_NA); proto_tree_add_item(can_tree, hf_can_reserved, tvb, CANFD_FLAG_OFFSET+1, 2, ENC_NA); - next_tvb = tvb_new_subset_length(tvb, CAN_DATA_OFFSET, frame_len); + next_tvb = tvb_new_subset_length(tvb, CAN_DATA_OFFSET, can_info.len); if(!heuristic_first) { - if (!dissector_try_payload_new(subdissector_table, next_tvb, pinfo, tree, TRUE, &can_id)) + if (!dissector_try_payload_new(subdissector_table, next_tvb, pinfo, tree, TRUE, &can_info)) { - if(!dissector_try_heuristic(heur_subdissector_list, next_tvb, pinfo, tree, &heur_dtbl_entry, &can_id)) + if(!dissector_try_heuristic(heur_subdissector_list, next_tvb, pinfo, tree, &heur_dtbl_entry, &can_info)) { call_data_dissector(next_tvb, pinfo, tree); } @@ -418,18 +418,18 @@ dissect_socketcanfd_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, } else { - if (!dissector_try_heuristic(heur_subdissector_list, next_tvb, pinfo, tree, &heur_dtbl_entry, &can_id)) + if (!dissector_try_heuristic(heur_subdissector_list, next_tvb, pinfo, tree, &heur_dtbl_entry, &can_info)) { - if(!dissector_try_payload_new(subdissector_table, next_tvb, pinfo, tree, FALSE, &can_id)) + if(!dissector_try_payload_new(subdissector_table, next_tvb, pinfo, tree, FALSE, &can_info)) { call_data_dissector(next_tvb, pinfo, tree); } } } - if (tvb_captured_length_remaining(tvb, CAN_DATA_OFFSET+frame_len) > 0) + if (tvb_captured_length_remaining(tvb, CAN_DATA_OFFSET+can_info.len) > 0) { - proto_tree_add_item(can_tree, hf_can_padding, tvb, CAN_DATA_OFFSET+frame_len, -1, ENC_NA); + proto_tree_add_item(can_tree, hf_can_padding, tvb, CAN_DATA_OFFSET+can_info.len, -1, ENC_NA); } return tvb_captured_length(tvb); @@ -448,7 +448,7 @@ proto_register_socketcan(void) { static hf_register_info hf[] = { { - &hf_can_ident_ext, + &hf_can_infoent_ext, { "Identifier", "can.id", FT_UINT32, BASE_HEX, @@ -457,7 +457,7 @@ proto_register_socketcan(void) } }, { - &hf_can_ident_std, + &hf_can_infoent_std, { "Identifier", "can.id", FT_UINT32, BASE_HEX, diff --git a/epan/dissectors/packet-socketcan.h b/epan/dissectors/packet-socketcan.h index e7c9c7bb91..1d56cca3c6 100644 --- a/epan/dissectors/packet-socketcan.h +++ b/epan/dissectors/packet-socketcan.h @@ -11,12 +11,14 @@ #define __PACKET_SOCKETCAN_H__ /* Structure that gets passed between dissectors. */ -struct can_identifier +struct can_info { guint32 id; + guint32 len; + gboolean fd; }; -typedef struct can_identifier can_identifier_t; +typedef struct can_info can_info_t; /* controller area network (CAN) kernel definitions * These masks are usually defined within <linux/can.h> but are not |