diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-19 04:14:33 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-19 04:14:33 +0000 |
commit | 9f153fbfec0fb9c9ce38e749a7c6f4a5e115d4e9 (patch) | |
tree | 2784370cda9bbf2da9114d70f05399c0b229d28c /epan/dissectors/packet-lin.c | |
parent | Adding debian version 4.2.6-1. (diff) | |
download | wireshark-9f153fbfec0fb9c9ce38e749a7c6f4a5e115d4e9.tar.xz wireshark-9f153fbfec0fb9c9ce38e749a7c6f4a5e115d4e9.zip |
Merging upstream version 4.4.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'epan/dissectors/packet-lin.c')
-rw-r--r-- | epan/dissectors/packet-lin.c | 162 |
1 files changed, 85 insertions, 77 deletions
diff --git a/epan/dissectors/packet-lin.c b/epan/dissectors/packet-lin.c index aeda9872..3ffb1b50 100644 --- a/epan/dissectors/packet-lin.c +++ b/epan/dissectors/packet-lin.c @@ -35,32 +35,32 @@ static heur_dissector_list_t heur_subdissector_list; static heur_dtbl_entry_t *heur_dtbl_entry; -static int proto_lin = -1; +static int proto_lin; static dissector_handle_t lin_handle; /* header field */ -static int hf_lin_msg_format_rev = -1; -static int hf_lin_reserved1 = -1; -static int hf_lin_payload_length = -1; -static int hf_lin_message_type = -1; -static int hf_lin_checksum_type = -1; -static int hf_lin_pid = -1; -static int hf_lin_id = -1; -static int hf_lin_parity = -1; -static int hf_lin_checksum = -1; -static int hf_lin_err_errors = -1; -static int hf_lin_err_no_slave_response = -1; -static int hf_lin_err_framing = -1; -static int hf_lin_err_parity = -1; -static int hf_lin_err_checksum = -1; -static int hf_lin_err_invalidid = -1; -static int hf_lin_err_overflow = -1; -static int hf_lin_event_id = -1; - -static gint ett_lin = -1; -static gint ett_lin_pid = -1; -static gint ett_errors = -1; +static int hf_lin_msg_format_rev; +static int hf_lin_reserved1; +static int hf_lin_payload_length; +static int hf_lin_message_type; +static int hf_lin_checksum_type; +static int hf_lin_pid; +static int hf_lin_id; +static int hf_lin_parity; +static int hf_lin_checksum; +static int hf_lin_err_errors; +static int hf_lin_err_no_slave_response; +static int hf_lin_err_framing; +static int hf_lin_err_parity; +static int hf_lin_err_checksum; +static int hf_lin_err_invalidid; +static int hf_lin_err_overflow; +static int hf_lin_event_id; + +static int ett_lin; +static int ett_lin_pid; +static int ett_errors; static int * const error_fields[] = { &hf_lin_err_overflow, @@ -114,17 +114,17 @@ void proto_register_lin(void); /* Interface Config UAT */ typedef struct _interface_config { - guint interface_id; - gchar *interface_name; - guint bus_id; + unsigned interface_id; + char *interface_name; + unsigned bus_id; } interface_config_t; #define DATAFILE_LIN_INTERFACE_MAPPING "LIN_interface_mapping" -static GHashTable *data_lin_interfaces_by_id = NULL; -static GHashTable *data_lin_interfaces_by_name = NULL; -static interface_config_t* interface_configs = NULL; -static guint interface_config_num = 0; +static GHashTable *data_lin_interfaces_by_id; +static GHashTable *data_lin_interfaces_by_name; +static interface_config_t* interface_configs; +static unsigned interface_config_num; UAT_HEX_CB_DEF(interface_configs, interface_id, interface_config_t) UAT_CSTRING_CB_DEF(interface_configs, interface_name, interface_config_t) @@ -148,16 +148,16 @@ update_interface_config(void *r, char **err) { if (rec->interface_id > 0xffffffff) { *err = ws_strdup_printf("We currently only support 32 bit identifiers (ID: 0x%x Name: %s)", rec->interface_id, rec->interface_name); - return FALSE; + return false; } if (rec->bus_id > 0xffff) { *err = ws_strdup_printf("We currently only support 16 bit bus identifiers (ID: 0x%x Name: %s Bus-ID: 0x%x)", rec->interface_id, rec->interface_name, rec->bus_id); - return FALSE; + return false; } - return TRUE; + return true; } static void @@ -186,9 +186,9 @@ ht_lookup_interface_config_by_id(unsigned int identifier) { } static interface_config_t * -ht_lookup_interface_config_by_name(const gchar *name) { +ht_lookup_interface_config_by_name(const char *name) { interface_config_t *tmp = NULL; - gchar *key = NULL; + char *key = NULL; if (interface_configs == NULL) { return NULL; @@ -202,15 +202,15 @@ ht_lookup_interface_config_by_name(const gchar *name) { } static void -lin_free_key(gpointer key) { +lin_free_key(void *key) { wmem_free(wmem_epan_scope(), key); } static void post_update_lin_interfaces_cb(void) { - guint i; + unsigned i; int *key_id = NULL; - gchar *key_name = NULL; + char *key_name = NULL; /* destroy old hash tables, if they exist */ if (data_lin_interfaces_by_id) { @@ -250,16 +250,17 @@ post_update_lin_interfaces_cb(void) { * - interface_name = "" and interface_id matches */ -static guint +static unsigned get_bus_id(packet_info *pinfo) { - guint32 interface_id = pinfo->rec->rec_header.packet_header.interface_id; - const char *interface_name = epan_get_interface_name(pinfo->epan, interface_id); - interface_config_t *tmp = NULL; - if (!(pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID)) { return 0; } + uint32_t interface_id = pinfo->rec->rec_header.packet_header.interface_id; + unsigned section_number = pinfo->rec->presence_flags & WTAP_HAS_SECTION_NUMBER ? pinfo->rec->section_number : 0; + const char *interface_name = epan_get_interface_name(pinfo->epan, interface_id, section_number); + interface_config_t *tmp = NULL; + if (interface_name != NULL && interface_name[0] != 0) { tmp = ht_lookup_interface_config_by_name(interface_name); @@ -282,17 +283,17 @@ get_bus_id(packet_info *pinfo) { /* Senders and Receivers UAT */ typedef struct _sender_receiver_config { - guint bus_id; - guint lin_id; - gchar *sender_name; - gchar *receiver_name; + unsigned bus_id; + unsigned lin_id; + char *sender_name; + char *receiver_name; } sender_receiver_config_t; #define DATAFILE_LIN_SENDER_RECEIVER "LIN_senders_receivers" -static GHashTable *data_sender_receiver = NULL; -static sender_receiver_config_t* sender_receiver_configs = NULL; -static guint sender_receiver_config_num = 0; +static GHashTable *data_sender_receiver; +static sender_receiver_config_t* sender_receiver_configs; +static unsigned sender_receiver_config_num; UAT_HEX_CB_DEF(sender_receiver_configs, bus_id, sender_receiver_config_t) UAT_HEX_CB_DEF(sender_receiver_configs, lin_id, sender_receiver_config_t) @@ -317,15 +318,15 @@ update_sender_receiver_config(void *r, char **err) { if (rec->lin_id > 0x3f) { *err = ws_strdup_printf("LIN IDs need to be between 0x00 and 0x3f (Bus ID: %i LIN ID: %i)", rec->bus_id, rec->lin_id); - return FALSE; + return false; } if (rec->bus_id > 0xffff) { *err = ws_strdup_printf("We currently only support 16 bit bus identifiers (Bus ID: %i LIN ID: %i)", rec->bus_id, rec->lin_id); - return FALSE; + return false; } - return TRUE; + return true; } static void @@ -338,15 +339,15 @@ free_sender_receiver_config_cb(void *r) { rec->receiver_name = NULL; } -static guint64 -sender_receiver_key(guint16 bus_id, guint32 lin_id) { - return ((guint64)bus_id << 32) | lin_id; +static uint64_t +sender_receiver_key(uint16_t bus_id, uint32_t lin_id) { + return ((uint64_t)bus_id << 32) | lin_id; } static sender_receiver_config_t * -ht_lookup_sender_receiver_config(guint16 bus_id, guint32 lin_id) { +ht_lookup_sender_receiver_config(uint16_t bus_id, uint32_t lin_id) { sender_receiver_config_t *tmp = NULL; - guint64 key = 0; + uint64_t key = 0; if (sender_receiver_configs == NULL) { return NULL; @@ -364,14 +365,14 @@ ht_lookup_sender_receiver_config(guint16 bus_id, guint32 lin_id) { } static void -sender_receiver_free_key(gpointer key) { +sender_receiver_free_key(void *key) { wmem_free(wmem_epan_scope(), key); } static void post_update_sender_receiver_cb(void) { - guint i; - guint64 *key_id = NULL; + unsigned i; + uint64_t *key_id = NULL; /* destroy old hash table, if it exist */ if (data_sender_receiver) { @@ -387,13 +388,13 @@ post_update_sender_receiver_cb(void) { } for (i = 0; i < sender_receiver_config_num; i++) { - key_id = wmem_new(wmem_epan_scope(), guint64); + key_id = wmem_new(wmem_epan_scope(), uint64_t); *key_id = sender_receiver_key(sender_receiver_configs[i].bus_id, sender_receiver_configs[i].lin_id); g_hash_table_insert(data_sender_receiver, key_id, &sender_receiver_configs[i]); } } -gboolean +bool lin_set_source_and_destination_columns(packet_info* pinfo, lin_info_t *lininfo) { sender_receiver_config_t *tmp = ht_lookup_sender_receiver_config(lininfo->bus_id, lininfo->id); @@ -406,8 +407,8 @@ lin_set_source_and_destination_columns(packet_info* pinfo, lin_info_t *lininfo) clear_address(&pinfo->dl_dst); clear_address(&pinfo->dst); - col_add_fstr(pinfo->cinfo, COL_DEF_SRC, "%s", tmp->sender_name); - col_add_fstr(pinfo->cinfo, COL_DEF_DST, "%s", tmp->receiver_name); + col_add_str(pinfo->cinfo, COL_DEF_SRC, tmp->sender_name); + col_add_str(pinfo->cinfo, COL_DEF_DST, tmp->receiver_name); return true; } return false; @@ -421,9 +422,10 @@ dissect_lin(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) proto_tree *lin_id_tree; tvbuff_t *next_tvb; - guint payload_length; - guint msg_type; + unsigned payload_length; + unsigned msg_type; lin_info_t lininfo; + uint64_t errors; col_set_str(pinfo->cinfo, COL_PROTOCOL, LIN_NAME); col_clear(pinfo->cinfo, COL_INFO); @@ -447,17 +449,23 @@ dissect_lin(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) proto_tree_add_item(lin_tree, hf_lin_checksum, tvb, 6, 1, ENC_BIG_ENDIAN); - lininfo.bus_id = (guint16)get_bus_id(pinfo); + lininfo.bus_id = (uint16_t)get_bus_id(pinfo); lininfo.len = 0; lin_set_source_and_destination_columns(pinfo, &lininfo); } - proto_tree_add_bitmask(lin_tree, tvb, 7, hf_lin_err_errors, ett_errors, error_fields, ENC_BIG_ENDIAN); + proto_tree_add_bitmask_ret_uint64(lin_tree, tvb, 7, hf_lin_err_errors, ett_errors, error_fields, ENC_BIG_ENDIAN, &errors); col_add_fstr(pinfo->cinfo, COL_INFO, "LIN %s", val_to_str(msg_type, lin_msg_type_names, "(0x%02x)")); + if (errors != 0) { + col_append_str(pinfo->cinfo, COL_INFO, " - ERR"); + proto_item_set_end(ti_root, tvb, 8); + return 8; + } + switch (msg_type) { case LIN_MSG_TYPE_EVENT: { - guint event_id; + unsigned event_id; proto_tree_add_item_ret_uint(lin_tree, hf_lin_event_id, tvb, 8, 4, ENC_BIG_ENDIAN, &event_id); col_append_fstr(pinfo->cinfo, COL_INFO, ": %s", val_to_str(event_id, lin_event_type_names, "0x%08x")); proto_item_set_end(ti_root, tvb, 12); @@ -469,11 +477,11 @@ dissect_lin(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) if (payload_length > 0) { next_tvb = tvb_new_subset_length(tvb, 8, payload_length); proto_item_set_end(ti_root, tvb, 8 + payload_length); - lininfo.len = (guint16)payload_length; + lininfo.len = (uint16_t)payload_length; - guint32 bus_frame_id = lininfo.id | (lininfo.bus_id << 16); - if (!dissector_try_uint_new(subdissector_table, bus_frame_id, next_tvb, pinfo, tree, TRUE, &lininfo)) { - if (!dissector_try_uint_new(subdissector_table, lininfo.id, next_tvb, pinfo, tree, TRUE, &lininfo)) { + uint32_t bus_frame_id = lininfo.id | (lininfo.bus_id << 16); + if (!dissector_try_uint_new(subdissector_table, bus_frame_id, next_tvb, pinfo, tree, true, &lininfo)) { + if (!dissector_try_uint_new(subdissector_table, lininfo.id, next_tvb, pinfo, tree, true, &lininfo)) { if (!dissector_try_heuristic(heur_subdissector_list, next_tvb, pinfo, tree, &heur_dtbl_entry, &lininfo)) { call_data_dissector(next_tvb, pinfo, tree); } @@ -555,7 +563,7 @@ proto_register_lin(void) { FT_UINT32, BASE_HEX_DEC, VALS(lin_event_type_names), 0x00, NULL, HFILL }}, }; - static gint *ett[] = { + static int *ett[] = { &ett_lin, &ett_lin_pid, &ett_errors, @@ -571,7 +579,7 @@ proto_register_lin(void) { /* the lin.frame_id subdissector table carries the bus id in the higher 16 bits */ subdissector_table = register_dissector_table("lin.frame_id", "LIN Frame ID", proto_lin, FT_UINT8, BASE_HEX); - heur_subdissector_list = register_heur_dissector_list(LIN_NAME_FILTER, proto_lin); + heur_subdissector_list = register_heur_dissector_list_with_description(LIN_NAME_FILTER, "LIN Message data fallback", proto_lin); static uat_field_t lin_interface_mapping_uat_fields[] = { UAT_FLD_HEX(interface_configs, interface_id, "Interface ID", "ID of the Interface with 0xffffffff = any (hex uint32 without leading 0x)"), @@ -583,7 +591,7 @@ proto_register_lin(void) { lin_interface_uat = uat_new("LIN Interface Mapping", sizeof(interface_config_t), /* record size */ DATAFILE_LIN_INTERFACE_MAPPING, /* filename */ - TRUE, /* from profile */ + true, /* from profile */ (void**)&interface_configs, /* data_ptr */ &interface_config_num, /* numitems_ptr */ UAT_AFFECTS_DISSECTION, /* but not fields */ @@ -610,7 +618,7 @@ proto_register_lin(void) { sender_receiver_uat = uat_new("Sender Receiver Config", sizeof(sender_receiver_config_t), /* record size */ DATAFILE_LIN_SENDER_RECEIVER, /* filename */ - TRUE, /* from profile */ + true, /* from profile */ (void**)&sender_receiver_configs, /* data_ptr */ &sender_receiver_config_num, /* numitems_ptr */ UAT_AFFECTS_DISSECTION, /* but not fields */ |