DoIP/UDS: Allow mixing with OBD-II

This patch allows users to dissect UDS and OBD-II messages on the same
ISO15765 or DoIP connection without changing manually changing the
config.
This commit is contained in:
Dr. Lars Völker 2023-01-12 19:16:33 +01:00 committed by AndersBroman
parent 9baefc3d5d
commit 566292435f
3 changed files with 63 additions and 4 deletions

View File

@ -1362,7 +1362,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)
dissect_obdii_iso15765(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
{
iso15765_info_t iso15765_info;
guint32 can_id_only;
@ -1456,10 +1456,53 @@ dissect_obdii(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
return tvb_captured_length(tvb);
}
static int
dissect_obdii_uds(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
{
struct obdii_packet_info oinfo;
proto_tree *obdii_tree;
proto_item *ti;
guint8 data_bytes;
guint8 mode;
gboolean response;
data_bytes = tvb_reported_length(tvb);
mode = tvb_get_guint8(tvb, OBDII_MODE_POS);
response = (mode & 0x40) == 0x40;
mode = mode & 0xbf;
col_set_str(pinfo->cinfo, COL_PROTOCOL, "OBD-II");
col_clear(pinfo->cinfo, COL_INFO);
ti = proto_tree_add_item(tree, proto_obdii, tvb, 0, -1, ENC_NA);
obdii_tree = proto_item_add_subtree(ti, ett_obdii);
proto_tree_add_uint(obdii_tree, hf_obdii_mode, tvb, OBDII_MODE_POS, 1, mode);
memset(&oinfo, 0, sizeof(oinfo));
oinfo.pinfo = pinfo;
oinfo.can_id = 0;
oinfo.data_bytes = data_bytes;
oinfo.mode = mode;
if (!response) {
return dissect_obdii_query(tvb, &oinfo, obdii_tree);
} else {
return dissect_obdii_response(tvb, &oinfo, obdii_tree);
}
/* never here */
DISSECTOR_ASSERT_NOT_REACHED();
return tvb_captured_length(tvb);
}
static int
dissect_obdii_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
{
return dissect_obdii(tvb, pinfo, tree, data) != 0;
return dissect_obdii_iso15765(tvb, pinfo, tree, data) != 0;
}
void
@ -1712,10 +1755,11 @@ proto_reg_handoff_obdii(void)
{
dissector_handle_t obdii_handle;
obdii_handle = create_dissector_handle(dissect_obdii, proto_obdii);
obdii_handle = create_dissector_handle(dissect_obdii_iso15765, proto_obdii);
dissector_add_for_decode_as("iso15765.subdissector", obdii_handle);
register_dissector("obd-ii-uds", dissect_obdii_uds, proto_obdii);
/* heuristics default off since these standardized IDs might be reused outside automotive systems */
heur_dissector_add("can", dissect_obdii_heur, "OBD-II Heuristic", "obd-ii_can_heur", proto_obdii, HEURISTIC_DISABLE);
}

View File

@ -603,12 +603,15 @@ static dissector_handle_t uds_handle;
static dissector_handle_t uds_handle_doip;
static dissector_handle_t uds_handle_iso10681;
static dissector_handle_t uds_handle_iso15765;
static dissector_handle_t obd_ii_handle;
/*** Subdissectors ***/
static heur_dissector_list_t heur_subdissector_list;
static heur_dtbl_entry_t *heur_dtbl_entry;
/*** Configuration ***/
static gboolean uds_dissect_small_sids_with_obd_ii = TRUE;
typedef struct _address_string {
guint address;
gchar *name;
@ -1006,6 +1009,11 @@ dissect_uds_internal(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint3
sid = tvb_get_guint8(tvb, UDS_SID_OFFSET);
service = sid & UDS_SID_MASK;
if (service < UDS_SERVICES_MIN && uds_dissect_small_sids_with_obd_ii && (obd_ii_handle != NULL)) {
return call_dissector(obd_ii_handle, tvb_new_subset_length_caplen(tvb, UDS_SID_OFFSET, -1, -1), pinfo, tree);
}
service_name = val_to_str(service, uds_services, "Unknown (0x%02x)");
col_add_fstr(pinfo->cinfo, COL_INFO, "%-7s %-36s", (sid & UDS_REPLY_MASK)? "Reply": "Request", service_name);
@ -1940,6 +1948,11 @@ proto_register_uds(void)
prefs_register_uat_preference(uds_module, "_uds_address_list", "UDS Address List",
"A table to define names of UDS Addresses", uds_address_uat);
prefs_register_bool_preference(uds_module, "dissect_small_sids_with_obd_ii",
"Dissect Service Identifiers smaller 0x10 with OBD II Dissector?",
"Dissect Service Identifiers smaller 0x10 with OBD II Dissector?",
&uds_dissect_small_sids_with_obd_ii);
heur_subdissector_list = register_heur_dissector_list("uds", proto_uds);
}
@ -1948,6 +1961,7 @@ proto_reg_handoff_uds(void)
{
dissector_add_for_decode_as("iso10681.subdissector", uds_handle_iso10681);
dissector_add_for_decode_as("iso15765.subdissector", uds_handle_iso15765);
obd_ii_handle = find_dissector("obd-ii-uds");
}
/*

View File

@ -16,6 +16,7 @@
#define UDS_SID_MASK 0xBF
#define UDS_REPLY_MASK 0x40
#define UDS_SERVICES_MIN 0x10
#define UDS_SERVICES_DSC 0x10
#define UDS_SERVICES_ER 0x11
#define UDS_SERVICES_CDTCI 0x14