diff options
Diffstat (limited to 'epan/dissectors/packet-signal-pdu.c')
-rw-r--r-- | epan/dissectors/packet-signal-pdu.c | 1802 |
1 files changed, 1467 insertions, 335 deletions
diff --git a/epan/dissectors/packet-signal-pdu.c b/epan/dissectors/packet-signal-pdu.c index 8230c7603d..28a25ee48f 100644 --- a/epan/dissectors/packet-signal-pdu.c +++ b/epan/dissectors/packet-signal-pdu.c @@ -1,8 +1,8 @@ /* packet-signal-pdu.c * Signal PDU dissector. * By Dr. Lars Voelker <lars.voelker@technica-engineering.de> - * Copyright 2020-2021 Dr. Lars Voelker - * + * Copyright 2020-2023 Dr. Lars Voelker + * * Wireshark - Network traffic analyzer * By Gerald Combs <gerald@wireshark.org> * Copyright 1998 Gerald Combs @@ -18,23 +18,25 @@ */ #include <config.h> + #include <epan/packet.h> #include <epan/prefs.h> #include <epan/expert.h> #include <epan/to_str.h> #include <epan/uat.h> -#include "wsutil/sign_ext.h" +#include <epan/proto_data.h> -#include <packet-someip.h> -#include <packet-socketcan.h> -#include <packet-flexray.h> -#include <packet-pdu-transport.h> -#include <packet-lin.h> +#include <wsutil/sign_ext.h> -void proto_reg_handoff_signal_pdu_can(void); -void proto_reg_handoff_signal_pdu_lin(void); -void proto_reg_handoff_signal_pdu_someip(void); -void proto_reg_handoff_signal_pdu_pdu_transport(void); +#include "packet-someip.h" +#include "packet-socketcan.h" +#include "packet-flexray.h" +#include "packet-pdu-transport.h" +#include "packet-lin.h" +#include "packet-autosar-ipdu-multiplexer.h" +#include "packet-dlt.h" +#include "packet-uds.h" +#include "packet-isobus.h" /* * Dissector for CAN, FlexRay, and other message payloads. @@ -62,27 +64,35 @@ void proto_reg_handoff_signal_pdu_pdu_transport(void); #define DATAFILE_SPDU_FLEXRAY_MAPPING "Signal_PDU_Binding_FlexRay" #define DATAFILE_SPDU_LIN_MAPPING "Signal_PDU_Binding_LIN" #define DATAFILE_SPDU_PDU_TRANSPORT_MAPPING "Signal_PDU_Binding_PDU_Transport" +#define DATAFILE_SPDU_IPDUM_MAPPING "Signal_PDU_Binding_AUTOSAR_IPduM" +#define DATAFILE_SPDU_DLT_MAPPING "Signal_PDU_Binding_DLT" +#define DATAFILE_SPDU_UDS_MAPPING "Signal_PDU_Binding_UDS" +#define DATAFILE_SPDU_ISOBUS_MAPPING "Signal_PDU_Binding_ISOBUS" /* ID wireshark identifies the dissector by */ -static int proto_signal_pdu = -1; +static int proto_signal_pdu; static dissector_handle_t signal_pdu_handle_someip = NULL; static dissector_handle_t signal_pdu_handle_can = NULL; static dissector_handle_t signal_pdu_handle_flexray = NULL; static dissector_handle_t signal_pdu_handle_lin = NULL; static dissector_handle_t signal_pdu_handle_pdu_transport = NULL; +static dissector_handle_t signal_pdu_handle_ipdum = NULL; +static dissector_handle_t signal_pdu_handle_isobus = NULL; -static int hf_payload_unparsed = -1; +static int hf_pdu_name; +static int hf_payload_unparsed; -static gint ett_spdu_payload = -1; -static gint ett_spdu_signal = -1; -static gboolean spdu_derserializer_activated = FALSE; -static gboolean spdu_derserializer_show_hidden = FALSE; -static gboolean spdu_derserializer_hide_raw_values = TRUE; +static gint ett_spdu_payload; +static gint ett_spdu_signal; +static gboolean spdu_deserializer_activated = TRUE; +static gboolean spdu_deserializer_show_hidden = FALSE; +static gboolean spdu_deserializer_hide_raw_values = TRUE; /*** expert info items ***/ -static expert_field ef_spdu_payload_truncated = EI_INIT; -static expert_field ef_spdu_config_error = EI_INIT; +static expert_field ei_spdu_payload_truncated; +static expert_field ei_spdu_config_error; +static expert_field ei_spdu_unaligned_data; /*** Data Structure for UAT based config ***/ static GHashTable *data_spdu_messages = NULL; @@ -95,9 +105,30 @@ static GHashTable *data_spdu_can_mappings = NULL; static GHashTable *data_spdu_flexray_mappings = NULL; static GHashTable *data_spdu_lin_mappings = NULL; static GHashTable *data_spdu_pdu_transport_mappings = NULL; +static GHashTable *data_spdu_ipdum_mappings = NULL; +static GHashTable *data_spdu_dlt_mappings = NULL; +static GHashTable *data_spdu_uds_mappings = NULL; +static GHashTable *data_spdu_isobus_mappings = NULL; + +static hf_register_info *dynamic_hf_base_raw = NULL; +static hf_register_info *dynamic_hf_agg_sum = NULL; +static hf_register_info *dynamic_hf_agg_avg = NULL; +static hf_register_info *dynamic_hf_agg_int = NULL; +static guint dynamic_hf_number_of_entries = 0; +static guint dynamic_hf_base_raw_number = 0; +static guint dynamic_hf_agg_sum_number = 0; +static guint dynamic_hf_agg_avg_number = 0; +static guint dynamic_hf_agg_int_number = 0; + +#define HF_TYPE_BASE 0 +#define HF_TYPE_RAW 1 +#define HF_TYPE_AGG_SUM 2 +#define HF_TYPE_AGG_AVG 3 +#define HF_TYPE_AGG_INT 4 +#define HF_TYPE_NONE 0xffff + +#define HF_TYPE_COUNT_BASE_RAW_TABLE 2 -static hf_register_info *dynamic_hf = NULL; -static guint dynamic_hf_size = 0; /*********************************************** ********* Preferences / Configuration ********* @@ -108,11 +139,20 @@ typedef struct _generic_one_id_string { gchar *name; } generic_one_id_string_t; +typedef enum _spdu_data_type { + SPDU_DATA_TYPE_NONE, + SPDU_DATA_TYPE_UINT, + SPDU_DATA_TYPE_INT, + SPDU_DATA_TYPE_FLOAT, + SPDU_DATA_TYPE_STRING, + SPDU_DATA_TYPE_STRINGZ, + SPDU_DATA_TYPE_UINT_STRING, +} spdu_dt_t; typedef struct _spdu_signal_item { guint32 pos; gchar *name; - gchar *data_type; + spdu_dt_t data_type; gboolean big_endian; guint32 bitlength_base_type; guint32 bitlength_encoded_type; @@ -122,14 +162,23 @@ typedef struct _spdu_signal_item { gboolean multiplexer; gint multiplex_value_only; gboolean hidden; + guint encoding; + + gboolean aggregate_sum; + gboolean aggregate_avg; + gboolean aggregate_int; gint *hf_id_effective; gint *hf_id_raw; + gint *hf_id_agg_sum; + gint *hf_id_agg_avg; + gint *hf_id_agg_int; } spdu_signal_item_t; typedef struct _spdu_signal_list { guint32 id; guint32 num_of_items; + gboolean aggregation; spdu_signal_item_t *items; } spdu_signal_list_t; @@ -150,6 +199,9 @@ typedef struct _spdu_signal_list_uat { gboolean multiplexer; gint multiplex_value_only; gboolean hidden; + gboolean aggregate_sum; + gboolean aggregate_avg; + gboolean aggregate_int; } spdu_signal_list_uat_t; @@ -241,6 +293,39 @@ typedef struct _spdu_pdu_transport_mapping { typedef spdu_pdu_transport_mapping_t spdu_pdu_transport_mapping_uat_t; +typedef struct _spdu_ipdum_mapping { + guint32 pdu_id; + guint32 message_id; +} spdu_ipdum_mapping_t; +typedef spdu_ipdum_mapping_t spdu_ipdum_mapping_uat_t; + + +typedef struct _spdu_dlt_mapping { + gchar *ecu_id; + guint32 dlt_message_id; + guint32 message_id; +} spdu_dlt_mapping_t; +typedef spdu_dlt_mapping_t spdu_dlt_mapping_uat_t; + + +typedef struct _spdu_uds_mapping { + guint32 uds_address; + guint32 service; + gboolean reply; + guint32 id; + guint32 message_id; +} spdu_uds_mapping_t; +typedef spdu_uds_mapping_t spdu_uds_mapping_uat_t; + + +typedef struct _spdu_isobus_mapping { + guint32 pgn; + guint32 bus_id; + guint32 message_id; +} spdu_isobus_mapping_t; +typedef spdu_isobus_mapping_t spdu_isobus_mapping_uat_t; + + static generic_one_id_string_t *spdu_message_ident = NULL; static guint spdu_message_ident_num = 0; @@ -265,11 +350,23 @@ static guint spdu_lin_mapping_num = 0; static spdu_pdu_transport_mapping_t *spdu_pdu_transport_mapping = NULL; static guint spdu_pdu_transport_mapping_num = 0; +static spdu_ipdum_mapping_t *spdu_ipdum_mapping = NULL; +static guint spdu_ipdum_mapping_num = 0; + +static spdu_dlt_mapping_t *spdu_dlt_mapping = NULL; +static guint spdu_dlt_mapping_num = 0; + +static spdu_uds_mapping_t *spdu_uds_mapping = NULL; +static guint spdu_uds_mapping_num = 0; + +static spdu_isobus_mapping_t *spdu_isobus_mapping = NULL; +static guint spdu_isobus_mapping_num = 0; + void proto_register_signal_pdu(void); void proto_reg_handoff_signal_pdu(void); -void -proto_reg_handoff_signal_pdu_can(void) { +static void +register_signal_pdu_can(void) { if (signal_pdu_handle_can == NULL) { return; } @@ -283,19 +380,21 @@ proto_reg_handoff_signal_pdu_can(void) { GList *tmp; for (tmp = keys; tmp != NULL; tmp = tmp->next) { - gint32 *id = ((gint32*)tmp->data); + gint32 id = (*(gint32 *)tmp->data); - *id &= CAN_EFF_MASK; - dissector_add_uint("can.extended_id", *id, signal_pdu_handle_can); - if (*id <= CAN_SFF_MASK) { - dissector_add_uint("can.id", *id, signal_pdu_handle_can); + if ((id & CAN_EFF_FLAG) == CAN_EFF_FLAG) { + dissector_add_uint("can.extended_id", id & CAN_EFF_MASK, signal_pdu_handle_can); + } else { + dissector_add_uint("can.id", id & CAN_SFF_MASK, signal_pdu_handle_can); } } + + g_list_free(keys); } } -void -proto_reg_handoff_signal_pdu_lin(void) { +static void +register_signal_pdu_lin(void) { if (signal_pdu_handle_lin == NULL) { return; } @@ -308,15 +407,17 @@ proto_reg_handoff_signal_pdu_lin(void) { GList *tmp; for (tmp = keys; tmp != NULL; tmp = tmp->next) { - gint32 *id = (gint32*)tmp->data; + gint32 *id = (gint32 *)tmp->data; /* we register the combination of bus and frame id */ dissector_add_uint("lin.frame_id", *id, signal_pdu_handle_lin); } + + g_list_free(keys); } } -void -proto_reg_handoff_signal_pdu_someip(void) { +static void +register_signal_pdu_someip(void) { if (signal_pdu_handle_someip == NULL) { return; } @@ -329,15 +430,17 @@ proto_reg_handoff_signal_pdu_someip(void) { GList *tmp; for (tmp = keys; tmp != NULL; tmp = tmp->next) { - gint64 *id = (gint64*)tmp->data; + gint64 *id = (gint64 *)tmp->data; guint32 message_id = (guint32)((guint64)(*id)) & 0xffffffff; dissector_add_uint("someip.messageid", message_id, signal_pdu_handle_someip); } + + g_list_free(keys); } } -void -proto_reg_handoff_signal_pdu_pdu_transport(void) { +static void +register_signal_pdu_pdu_transport(void) { if (signal_pdu_handle_pdu_transport == NULL) { return; } @@ -350,9 +453,55 @@ proto_reg_handoff_signal_pdu_pdu_transport(void) { GList *tmp; for (tmp = keys; tmp != NULL; tmp = tmp->next) { - gint64 *id = (gint64*)tmp->data; + gint64 *id = (gint64 *)tmp->data; dissector_add_uint("pdu_transport.id", ((guint32)((guint64)(*id)) & 0xffffffff), signal_pdu_handle_pdu_transport); } + + g_list_free(keys); + } +} + +static void +register_signal_pdu_ipdum(void) { + if (signal_pdu_handle_ipdum == NULL) { + return; + } + + dissector_delete_all("ipdum.pdu.id", signal_pdu_handle_ipdum); + + /* IPduM: loop over all messages IDs in HT */ + if (data_spdu_ipdum_mappings != NULL) { + GList *keys = g_hash_table_get_keys(data_spdu_ipdum_mappings); + + GList *tmp; + for (tmp = keys; tmp != NULL; tmp = tmp->next) { + gint64 *id = (gint64 *)tmp->data; + dissector_add_uint("ipdum.pdu.id", ((guint32)((guint64)(*id)) & 0xffffffff), signal_pdu_handle_ipdum); + } + + g_list_free(keys); + } +} + +static void +register_signal_pdu_isobus(void) { + if (signal_pdu_handle_isobus == NULL) { + return; + } + + dissector_delete_all("isobus.pgn", signal_pdu_handle_isobus); + + /* ISOBUS: loop over all messages IDs in HT */ + if (data_spdu_isobus_mappings != NULL) { + GList *keys = g_hash_table_get_keys(data_spdu_isobus_mappings); + + GList *tmp; + for (tmp = keys; tmp != NULL; tmp = tmp->next) { + gint64 *id = (gint64 *)tmp->data; + dissector_add_uint("isobus.pgn", ((guint32)((guint64)(*id)) & 0xffffffff), signal_pdu_handle_isobus); + } + + g_list_free(keys); } } @@ -370,7 +519,7 @@ spdu_payload_free_generic_data(gpointer data _U_) { /* ID -> Name */ static void * copy_generic_one_id_string_cb(void *n, const void *o, size_t size _U_) { - generic_one_id_string_t *new_rec = (generic_one_id_string_t *)n; + generic_one_id_string_t *new_rec = (generic_one_id_string_t *)n; const generic_one_id_string_t *old_rec = (const generic_one_id_string_t *)o; if (old_rec->name == NULL) { @@ -383,12 +532,12 @@ copy_generic_one_id_string_cb(void *n, const void *o, size_t size _U_) { return new_rec; } -static gboolean +static bool update_generic_one_identifier_32bit(void *r, char **err) { generic_one_id_string_t *rec = (generic_one_id_string_t *)r; if (rec->id > 0xffffffff) { - *err = g_strdup_printf("We currently only support 32 bit identifiers (ID: %i Name: %s)", rec->id, rec->name); + *err = ws_strdup_printf("We currently only support 32 bit identifiers (ID: %i Name: %s)", rec->id, rec->name); return FALSE; } @@ -400,11 +549,11 @@ update_generic_one_identifier_32bit(void *r, char **err) { guchar c = proto_check_field_name(rec->name); if (c) { if (c == '.') { - *err = g_strdup_printf("Name contains illegal chars '.' (ID: 0x%08x)", rec->id); + *err = ws_strdup_printf("Name contains illegal chars '.' (ID: 0x%08x)", rec->id); } else if (g_ascii_isprint(c)) { - *err = g_strdup_printf("Name contains illegal chars '%c' (ID: 0x%08x)", c, rec->id); + *err = ws_strdup_printf("Name contains illegal chars '%c' (ID: 0x%08x)", c, rec->id); } else { - *err = g_strdup_printf("Name contains invalid byte \\%03o (ID: 0x%08x)", c, rec->id); + *err = ws_strdup_printf("Name contains invalid byte \\%03o (ID: 0x%08x)", c, rec->id); } return FALSE; } @@ -434,14 +583,14 @@ post_update_one_id_string_template_cb(generic_one_id_string_t *data, guint data_ /*** Signal PDU Messages ***/ -UAT_HEX_CB_DEF (spdu_message_ident, id, generic_one_id_string_t) -UAT_CSTRING_CB_DEF (spdu_message_ident, name, generic_one_id_string_t) +UAT_HEX_CB_DEF(spdu_message_ident, id, generic_one_id_string_t) +UAT_CSTRING_CB_DEF(spdu_message_ident, name, generic_one_id_string_t) static void post_update_spdu_message_cb(void) { /* destroy old hash table, if it exists */ if (data_spdu_messages) { - g_hash_table_destroy (data_spdu_messages); + g_hash_table_destroy(data_spdu_messages); data_spdu_messages = NULL; } @@ -450,7 +599,7 @@ post_update_spdu_message_cb(void) { post_update_one_id_string_template_cb(spdu_message_ident, spdu_message_ident_num, data_spdu_messages); } -static char* +static char * get_message_name(guint32 id) { guint32 tmp = id; @@ -477,11 +626,14 @@ UAT_CSTRING_CB_DEF(spdu_signal_list, offset, spdu_signal_list_uat_t) UAT_BOOL_CB_DEF(spdu_signal_list, multiplexer, spdu_signal_list_uat_t) UAT_SIGNED_DEC_CB_DEF(spdu_signal_list, multiplex_value_only, spdu_signal_list_uat_t) UAT_BOOL_CB_DEF(spdu_signal_list, hidden, spdu_signal_list_uat_t) +UAT_BOOL_CB_DEF(spdu_signal_list, aggregate_sum, spdu_signal_list_uat_t) +UAT_BOOL_CB_DEF(spdu_signal_list, aggregate_avg, spdu_signal_list_uat_t) +UAT_BOOL_CB_DEF(spdu_signal_list, aggregate_int, spdu_signal_list_uat_t) static void * copy_spdu_signal_list_cb(void *n, const void *o, size_t size _U_) { - spdu_signal_list_uat_t *new_rec = (spdu_signal_list_uat_t *)n; - const spdu_signal_list_uat_t *old_rec = (const spdu_signal_list_uat_t *)o; + spdu_signal_list_uat_t *new_rec = (spdu_signal_list_uat_t *)n; + const spdu_signal_list_uat_t *old_rec = (const spdu_signal_list_uat_t *)o; new_rec->id = old_rec->id; new_rec->num_of_params = old_rec->num_of_params; @@ -522,78 +674,168 @@ copy_spdu_signal_list_cb(void *n, const void *o, size_t size _U_) { new_rec->multiplex_value_only = old_rec->multiplex_value_only; new_rec->hidden = old_rec->hidden; + new_rec->aggregate_sum = old_rec->aggregate_sum; + new_rec->aggregate_avg = old_rec->aggregate_avg; + new_rec->aggregate_int = old_rec->aggregate_int; return new_rec; } -static gboolean +static bool update_spdu_signal_list(void *r, char **err) { gchar *tmp; guchar c; - gdouble d; + gdouble scaler; + gdouble offset; spdu_signal_list_uat_t *rec = (spdu_signal_list_uat_t *)r; + offset = g_ascii_strtod(rec->offset, &tmp); + if (!(offset == offset)) { + *err = ws_strdup_printf("Offset not a double!"); + return FALSE; + } + + scaler = g_ascii_strtod(rec->scaler, &tmp); + if (!(scaler == scaler)) { + *err = ws_strdup_printf("Scaler not a double!"); + return FALSE; + } + if (rec->pos >= 0xffff) { - *err = g_strdup_printf("Position too big"); + *err = ws_strdup_printf("Position too big"); return FALSE; } if (rec->num_of_params >= 0xffff) { - *err = g_strdup_printf("Number of Parameters too big"); + *err = ws_strdup_printf("Number of Parameters too big"); return FALSE; } if (rec->pos >= rec->num_of_params) { - *err = g_strdup_printf("Position >= Number of Parameters"); + *err = ws_strdup_printf("Position %u >= Number of Parameters %u (ID: 0x%x)", rec->pos, rec->num_of_params, rec->id); return FALSE; } if (rec->name == NULL || rec->name[0] == 0) { - *err = g_strdup_printf("Name cannot be empty"); + *err = ws_strdup_printf("Name cannot be empty"); return FALSE; } if (rec->filter_string == NULL || rec->filter_string[0] == 0) { - *err = g_strdup_printf("Filter String cannot be empty"); + *err = ws_strdup_printf("Filter String cannot be empty"); return FALSE; } c = proto_check_field_name(rec->filter_string); if (c) { if (c == '.') { - *err = g_strdup_printf("Filter String contains illegal chars '.' (ID: 0x%08x)", rec->id); + *err = ws_strdup_printf("Filter String contains illegal chars '.' (ID: 0x%08x)", rec->id); } else if (g_ascii_isprint(c)) { - *err = g_strdup_printf("Filter String contains illegal chars '%c' (ID: 0x%08x)", c, rec->id); + *err = ws_strdup_printf("Filter String contains illegal chars '%c' (ID: 0x%08x)", c, rec->id); } else { - *err = g_strdup_printf("Filter String contains invalid byte \\%03o (ID: 0x%08x)", c, rec->id); + *err = ws_strdup_printf("Filter String contains invalid byte \\%03o (ID: 0x%08x)", c, rec->id); } return FALSE; } - if (g_strcmp0(rec->data_type, "uint") != 0 && g_strcmp0(rec->data_type, "int") != 0) { - *err = g_strdup_printf("Currently only uint and int supported!"); + if (g_strcmp0(rec->data_type, "uint") != 0 && + g_strcmp0(rec->data_type, "int") != 0 && + g_strcmp0(rec->data_type, "float") != 0 && + g_strcmp0(rec->data_type, "string") != 0 && + g_strcmp0(rec->data_type, "stringz") != 0 && + g_strcmp0(rec->data_type, "uint_string") != 0 && + g_strcmp0(rec->data_type, "utf_string") != 0 && + g_strcmp0(rec->data_type, "utf_stringz") != 0 && + g_strcmp0(rec->data_type, "utf_uint_string") != 0) { + *err = ws_strdup_printf("Currently the only supported data types are uint, int, float, string, stringz, uint_string, utf_string, utf_stringz, and utf_uint_string (ID: 0x%08x)", rec->id); return FALSE; } - if (g_strcmp0(rec->data_type, "int") == 0 && (rec->bitlength_base_type != rec->bitlength_encoded_type)) { - *err = g_strdup_printf("signed ints (int) only support in non-shortened length"); - return FALSE; + /* uint */ + if (g_strcmp0(rec->data_type, "uint") == 0) { + if ((rec->bitlength_base_type != 8) && (rec->bitlength_base_type != 16) && (rec->bitlength_base_type != 32) && (rec->bitlength_base_type != 64)) { + *err = ws_strdup_printf("Data type uint is only supported as 8, 16, 32, or 64 bit base type (ID: 0x%08x)", rec->id); + return FALSE; + } } - if (g_strcmp0(rec->data_type, "int") == 0 && (rec->bitlength_encoded_type != 8) && (rec->bitlength_encoded_type != 16) && (rec->bitlength_encoded_type != 32) && (rec->bitlength_encoded_type != 64)) { - *err = g_strdup_printf("signed ints (int) are only supported in 8, 16, 32, or 64 bit."); - return FALSE; + /* int */ + if (g_strcmp0(rec->data_type, "int") == 0) { + if (rec->bitlength_base_type != rec->bitlength_encoded_type) { + *err = ws_strdup_printf("Data type int is only supported in non-shortened length (ID: 0x%08x)", rec->id); + return FALSE; + } + + if ((rec->bitlength_encoded_type != 8) && (rec->bitlength_encoded_type != 16) && (rec->bitlength_encoded_type != 32) && (rec->bitlength_encoded_type != 64)) { + *err = ws_strdup_printf("Data type int is only supported in 8, 16, 32, or 64 bit (ID: 0x%08x)", rec->id); + return FALSE; + } } - d = g_ascii_strtod(rec->offset, &tmp); - if (!(d == d)) { - *err = g_strdup_printf("Offset not a double!"); - return FALSE; + /* float */ + if (g_strcmp0(rec->data_type, "float") == 0) { + if (rec->bitlength_base_type != rec->bitlength_encoded_type) { + *err = ws_strdup_printf("Data type float is only supported in non-shortened length (ID: 0x%08x)", rec->id); + return FALSE; + } + + if ((rec->bitlength_encoded_type != 32) && (rec->bitlength_encoded_type != 64)) { + *err = ws_strdup_printf("Data type float is only supported in 32 or 64 bit (ID: 0x%08x)", rec->id); + return FALSE; + } + + if ((scaler != 1.0) || (offset != 0.0)) { + *err = ws_strdup_printf("Data type float currently does not support scaling and offset (ID: 0x%08x)", rec->id); + return FALSE; + } + + if (rec->multiplexer == TRUE) { + *err = ws_strdup_printf("Data type float currently cannot be used as multiplexer (ID: 0x%08x)", rec->id); + return FALSE; + } + } + + /* string, stringz, uint_string, utf_string, utf_stringz, utf_uint_string */ + if (g_strcmp0(rec->data_type, "string") == 0 || g_strcmp0(rec->data_type, "stringz") == 0 || g_strcmp0(rec->data_type, "uint_string") == 0 || + g_strcmp0(rec->data_type, "utf_string") == 0 || g_strcmp0(rec->data_type, "utf_stringz") == 0 || g_strcmp0(rec->data_type, "utf_uint_string") == 0) { + if ((scaler != 1.0) || (offset != 0.0)) { + *err = ws_strdup_printf("Data types string, stringz, uint_string, utf_string, utf_stringz, and utf_uint_string currently do not support scaling and offset (ID: 0x%08x)", rec->id); + return FALSE; + } + + if (rec->multiplexer == TRUE) { + *err = ws_strdup_printf("Data types string, stringz, uint_string, utf_string, utf_stringz, and utf_uint_string currently cannot be used as multiplexer (ID: 0x%08x)", rec->id); + return FALSE; + } + + if ((g_strcmp0(rec->data_type, "string") == 0 || g_strcmp0(rec->data_type, "stringz") == 0 || g_strcmp0(rec->data_type, "uint_string") == 0) && + rec->bitlength_base_type != 8) { + *err = ws_strdup_printf("Data types string, stringz, and uint_string only support 8 bit Bitlength base type since they are ASCII-based (ID: 0x%08x)", rec->id); + return FALSE; + } + + if ((g_strcmp0(rec->data_type, "utf_string") == 0 || g_strcmp0(rec->data_type, "utf_stringz") == 0 || g_strcmp0(rec->data_type, "utf_uint_string") == 0) && + rec->bitlength_base_type != 8 && rec->bitlength_base_type != 16) { + *err = ws_strdup_printf("Data types utf_string, utf_stringz, and utf_uint_string only support Bitlength base type with 8 bit (UTF-8) or 16 bit (UTF-16) (ID: 0x%08x)", rec->id); + return FALSE; + } + + if ((g_strcmp0(rec->data_type, "stringz") == 0 || g_strcmp0(rec->data_type, "utf_stringz") == 0 ) && + (rec->bitlength_encoded_type != 0)) { + *err = ws_strdup_printf("Data types stringz and utf_stringz only support Bitlength encoded with 0 bit since the length is determined by zero-termination (ID: 0x%08x)", rec->id); + return FALSE; + } + + if ((g_strcmp0(rec->data_type, "uint_string") == 0 || g_strcmp0(rec->data_type, "utf_uint_string") == 0) && + (rec->bitlength_encoded_type != 8) && (rec->bitlength_encoded_type != 16) && (rec->bitlength_encoded_type != 32) && (rec->bitlength_encoded_type != 64)) { + *err = ws_strdup_printf("Data types uint_string and utf_uint_string only support Bitlength encoded with 8, 16, 32, or 64 bit since that defines the length of the length field (ID: 0x%08x)", rec->id); + return FALSE; + } } - d = g_ascii_strtod(rec->scaler, &tmp); - if (!(d == d)) { - *err = g_strdup_printf("Scaler not a double!"); + if (g_strcmp0(rec->data_type, "uint") != 0 && g_strcmp0(rec->data_type, "int") != 0 && g_strcmp0(rec->data_type, "float") != 0 && + (rec->aggregate_sum || rec->aggregate_avg || rec->aggregate_int)) { + *err = ws_strdup_printf("Aggregation is only allowed for uint, int, and float (ID: 0x%08x)", rec->id); return FALSE; } @@ -601,7 +843,7 @@ update_spdu_signal_list(void *r, char **err) { } static void -free_spdu_signal_list_cb(void*r) { +free_spdu_signal_list_cb(void *r) { spdu_signal_list_uat_t *rec = (spdu_signal_list_uat_t *)r; if (rec->name) { g_free(rec->name); @@ -611,41 +853,69 @@ free_spdu_signal_list_cb(void*r) { g_free(rec->filter_string); rec->filter_string = NULL; } + if (rec->data_type) { + g_free(rec->data_type); + rec->data_type = NULL; + } + if (rec->scaler) { + g_free(rec->scaler); + rec->scaler = NULL; + } + if (rec->offset) { + g_free(rec->offset); + rec->offset = NULL; + } } static void -deregister_user_data(void) -{ - if (dynamic_hf) { +deregister_user_data_hfarray(hf_register_info **hf_array, guint *number_of_entries) { + if (hf_array == NULL || number_of_entries == NULL) { + return; + } + + guint dynamic_hf_size = *number_of_entries; + hf_register_info *dynamic_hf = *hf_array; + + if (dynamic_hf != NULL) { /* Unregister all fields */ for (guint i = 0; i < dynamic_hf_size; i++) { - proto_deregister_field(proto_signal_pdu, *(dynamic_hf[i].p_id)); - g_free(dynamic_hf[i].p_id); - dynamic_hf[i].p_id = NULL; + if (dynamic_hf[i].p_id != NULL) { + if (*(dynamic_hf[i].p_id) != -1) { + proto_deregister_field(proto_signal_pdu, *(dynamic_hf[i].p_id)); + } + g_free(dynamic_hf[i].p_id); + dynamic_hf[i].p_id = NULL; - /* workaround since the proto.c proto_free_field_strings seems to crash us... */ - dynamic_hf[i].hfinfo.strings = NULL; + /* workaround since the proto.c proto_free_field_strings would double free this... */ + dynamic_hf[i].hfinfo.strings = NULL; + } } proto_add_deregistered_data(dynamic_hf); - dynamic_hf = NULL; - dynamic_hf_size = 0; + *hf_array = NULL; + *number_of_entries = 0; } } -static spdu_signal_value_name_t* get_signal_value_name_config(guint32 id, guint16 pos); +static void +deregister_user_data(void) +{ + deregister_user_data_hfarray(&dynamic_hf_base_raw, &dynamic_hf_base_raw_number); + deregister_user_data_hfarray(&dynamic_hf_agg_sum, &dynamic_hf_agg_sum_number); + deregister_user_data_hfarray(&dynamic_hf_agg_avg, &dynamic_hf_agg_avg_number); + deregister_user_data_hfarray(&dynamic_hf_agg_int, &dynamic_hf_agg_int_number); + dynamic_hf_number_of_entries = 0; +} + +static spdu_signal_value_name_t *get_signal_value_name_config(guint32 id, guint16 pos); static gint* -create_hf_entry(guint i, guint32 id, guint32 pos, gchar *name, gchar *filter_string, gchar *data_type, gboolean scale_or_offset, gboolean raw) { +create_hf_entry(hf_register_info *dynamic_hf, guint i, guint32 id, guint32 pos, gchar *name, gchar *filter_string, spdu_dt_t data_type, gboolean scale_or_offset, guint32 hf_type) { val64_string *vs = NULL; gint *hf_id = g_new(gint, 1); *hf_id = -1; - if (i >= dynamic_hf_size) { - return NULL; - } - spdu_signal_value_name_t *sig_val = get_signal_value_name_config(id, pos); if (sig_val != NULL) { vs = sig_val->vs; @@ -654,30 +924,84 @@ create_hf_entry(guint i, guint32 id, guint32 pos, gchar *name, gchar *filter_str dynamic_hf[i].p_id = hf_id; dynamic_hf[i].hfinfo.bitmask = 0x0; - if (raw) { - dynamic_hf[i].hfinfo.name = g_strdup_printf("%s_raw", name); - dynamic_hf[i].hfinfo.abbrev = g_strdup_printf("%s.%s_raw", SPDU_NAME_FILTER, filter_string); - } else { - dynamic_hf[i].hfinfo.name = g_strdup(name); - dynamic_hf[i].hfinfo.abbrev = g_strdup_printf("%s.%s", SPDU_NAME_FILTER, filter_string); + switch (hf_type) { + case HF_TYPE_RAW: + dynamic_hf[i].hfinfo.name = ws_strdup_printf("%s_raw", name); + dynamic_hf[i].hfinfo.abbrev = ws_strdup_printf("%s.%s_raw", SPDU_NAME_FILTER, filter_string); + break; + + case HF_TYPE_AGG_SUM: + dynamic_hf[i].hfinfo.name = ws_strdup_printf("%s_sum", name); + dynamic_hf[i].hfinfo.abbrev = ws_strdup_printf("%s.%s_sum", SPDU_NAME_FILTER, filter_string); + break; + + case HF_TYPE_AGG_AVG: + dynamic_hf[i].hfinfo.name = ws_strdup_printf("%s_avg", name); + dynamic_hf[i].hfinfo.abbrev = ws_strdup_printf("%s.%s_avg", SPDU_NAME_FILTER, filter_string); + break; + + case HF_TYPE_AGG_INT: + dynamic_hf[i].hfinfo.name = ws_strdup_printf("%s_int", name); + dynamic_hf[i].hfinfo.abbrev = ws_strdup_printf("%s.%s_int", SPDU_NAME_FILTER, filter_string); + break; + + case HF_TYPE_BASE: + dynamic_hf[i].hfinfo.name = ws_strdup(name); + dynamic_hf[i].hfinfo.abbrev = ws_strdup_printf("%s.%s", SPDU_NAME_FILTER, filter_string); + break; + + case HF_TYPE_NONE: + default: + /* we bail out but have set hf_id to -1 before */ + dynamic_hf[i].hfinfo.name = ws_strdup_printf("%s_none", name); + dynamic_hf[i].hfinfo.abbrev = ws_strdup_printf("%s.%s_none", SPDU_NAME_FILTER, filter_string); + return hf_id; } dynamic_hf[i].hfinfo.bitmask = 0; dynamic_hf[i].hfinfo.blurb = NULL; - if (scale_or_offset && !raw) { + if ((scale_or_offset && hf_type == HF_TYPE_BASE) || hf_type == HF_TYPE_AGG_SUM || hf_type == HF_TYPE_AGG_AVG || hf_type == HF_TYPE_AGG_INT) { dynamic_hf[i].hfinfo.display = BASE_NONE; dynamic_hf[i].hfinfo.type = FT_DOUBLE; } else { - if (g_strcmp0(data_type, "uint") == 0) { + switch (data_type) { + case SPDU_DATA_TYPE_UINT: dynamic_hf[i].hfinfo.display = BASE_DEC; dynamic_hf[i].hfinfo.type = FT_UINT64; - } else if (g_strcmp0(data_type, "int") == 0) { + break; + + case SPDU_DATA_TYPE_INT: dynamic_hf[i].hfinfo.display = BASE_DEC; dynamic_hf[i].hfinfo.type = FT_INT64; + break; + + case SPDU_DATA_TYPE_FLOAT: + dynamic_hf[i].hfinfo.display = BASE_NONE; + dynamic_hf[i].hfinfo.type = FT_DOUBLE; + break; + + case SPDU_DATA_TYPE_STRING: + dynamic_hf[i].hfinfo.display = BASE_NONE; + dynamic_hf[i].hfinfo.type = FT_STRING; + break; + + case SPDU_DATA_TYPE_STRINGZ: + dynamic_hf[i].hfinfo.display = BASE_NONE; + dynamic_hf[i].hfinfo.type = FT_STRINGZ; + break; + + case SPDU_DATA_TYPE_UINT_STRING: + dynamic_hf[i].hfinfo.display = BASE_NONE; + dynamic_hf[i].hfinfo.type = FT_UINT_STRING; + break; + + case SPDU_DATA_TYPE_NONE: + /* do nothing */ + break; } } - if (raw && vs != NULL) { + if (hf_type == HF_TYPE_RAW && vs != NULL) { dynamic_hf[i].hfinfo.strings = VALS64(vs); dynamic_hf[i].hfinfo.display |= BASE_VAL64_STRING | BASE_SPECIAL_VALS; } else { @@ -696,9 +1020,19 @@ post_update_spdu_signal_list_read_in_data(spdu_signal_list_uat_t *data, guint da } if (data_num) { - /* lets create 2 hf_ids per entry (1x effective, 1x raw) */ - dynamic_hf = g_new0(hf_register_info, 2 * data_num); - dynamic_hf_size = 2 * data_num; + dynamic_hf_number_of_entries = data_num; + /* lets create the dynamic_hf array (base + raw) */ + dynamic_hf_base_raw = g_new0(hf_register_info, 2 * dynamic_hf_number_of_entries); + dynamic_hf_base_raw_number = 2 * dynamic_hf_number_of_entries; + + /* lets create the other dynamic_hf arrays */ + dynamic_hf_agg_sum = g_new0(hf_register_info, dynamic_hf_number_of_entries); + dynamic_hf_agg_sum_number = 0; + dynamic_hf_agg_avg = g_new0(hf_register_info, dynamic_hf_number_of_entries); + dynamic_hf_agg_avg_number = 0; + dynamic_hf_agg_int = g_new0(hf_register_info, dynamic_hf_number_of_entries); + dynamic_hf_agg_int_number = 0; + guint i = 0; for (i = 0; i < data_num; i++) { @@ -733,7 +1067,41 @@ post_update_spdu_signal_list_read_in_data(spdu_signal_list_uat_t *data, guint da /* we do not care if we overwrite param */ item->name = g_strdup(data[i].name); item->pos = data[i].pos; - item->data_type = g_strdup(data[i].data_type); + + item->encoding = ENC_ASCII; + if (g_strcmp0("utf_string", data[i].data_type) == 0 || + g_strcmp0("utf_stringz", data[i].data_type) == 0 || + g_strcmp0("utf_uint_string", data[i].data_type) == 0) { + switch (data[i].bitlength_base_type) { + case 8: + item->encoding = ENC_UTF_8; + break; + case 16: + item->encoding = ENC_UTF_16; + break; + default: + /* this should never happen, since it is validated in the update callback */ + item->encoding = ENC_ASCII; + break; + } + } + + if (g_strcmp0("uint", data[i].data_type) == 0) { + item->data_type = SPDU_DATA_TYPE_UINT; + } else if (g_strcmp0("int", data[i].data_type) == 0) { + item->data_type = SPDU_DATA_TYPE_INT; + } else if (g_strcmp0("float", data[i].data_type) == 0) { + item->data_type = SPDU_DATA_TYPE_FLOAT; + } else if (g_strcmp0("string", data[i].data_type) == 0 || g_strcmp0("utf_string", data[i].data_type) == 0) { + item->data_type = SPDU_DATA_TYPE_STRING; + } else if (g_strcmp0("stringz", data[i].data_type) == 0 || g_strcmp0("utf_stringz", data[i].data_type) == 0) { + item->data_type = SPDU_DATA_TYPE_STRINGZ; + } else if (g_strcmp0("uint_string", data[i].data_type) == 0 || g_strcmp0("utf_uint_string", data[i].data_type) == 0) { + item->data_type = SPDU_DATA_TYPE_UINT_STRING; + } else { + item->data_type = SPDU_DATA_TYPE_NONE; + } + item->big_endian = data[i].big_endian; item->bitlength_base_type = data[i].bitlength_base_type; item->bitlength_encoded_type = data[i].bitlength_encoded_type; @@ -743,12 +1111,40 @@ post_update_spdu_signal_list_read_in_data(spdu_signal_list_uat_t *data, guint da item->multiplexer = data[i].multiplexer; item->multiplex_value_only = data[i].multiplex_value_only; item->hidden = data[i].hidden; - item->hf_id_effective = create_hf_entry(2 * i, data[i].id, data[i].pos, data[i].name, data[i].filter_string, data[i].data_type, item->scale_or_offset, FALSE); - item->hf_id_raw = create_hf_entry(2 * i + 1, data[i].id, data[i].pos, data[i].name, data[i].filter_string, data[i].data_type, item->scale_or_offset, TRUE); + + item->aggregate_sum = data[i].aggregate_sum; + item->aggregate_avg = data[i].aggregate_avg; + item->aggregate_int = data[i].aggregate_int; + + /* if one signal needs aggregation, the messages needs to know */ + list->aggregation |= item->aggregate_sum | item->aggregate_avg | item->aggregate_int; + + item->hf_id_effective = create_hf_entry(dynamic_hf_base_raw, HF_TYPE_COUNT_BASE_RAW_TABLE * i + HF_TYPE_BASE, data[i].id, data[i].pos, data[i].name, data[i].filter_string, item->data_type, item->scale_or_offset, HF_TYPE_BASE); + item->hf_id_raw = create_hf_entry(dynamic_hf_base_raw, HF_TYPE_COUNT_BASE_RAW_TABLE * i + HF_TYPE_RAW, data[i].id, data[i].pos, data[i].name, data[i].filter_string, item->data_type, item->scale_or_offset, HF_TYPE_RAW); + if (data[i].aggregate_sum) { + item->hf_id_agg_sum = create_hf_entry(dynamic_hf_agg_sum, dynamic_hf_agg_sum_number++, data[i].id, data[i].pos, data[i].name, data[i].filter_string, item->data_type, item->scale_or_offset, HF_TYPE_AGG_SUM); + } + if (data[i].aggregate_avg) { + item->hf_id_agg_avg = create_hf_entry(dynamic_hf_agg_avg, dynamic_hf_agg_avg_number++, data[i].id, data[i].pos, data[i].name, data[i].filter_string, item->data_type, item->scale_or_offset, HF_TYPE_AGG_AVG); + } + if (data[i].aggregate_int) { + item->hf_id_agg_int = create_hf_entry(dynamic_hf_agg_int, dynamic_hf_agg_int_number++, data[i].id, data[i].pos, data[i].name, data[i].filter_string, item->data_type, item->scale_or_offset, HF_TYPE_AGG_INT); + } } } - proto_register_field_array(proto_signal_pdu, dynamic_hf, dynamic_hf_size); + if (dynamic_hf_base_raw_number) { + proto_register_field_array(proto_signal_pdu, dynamic_hf_base_raw, dynamic_hf_base_raw_number); + } + if (dynamic_hf_agg_sum_number) { + proto_register_field_array(proto_signal_pdu, dynamic_hf_agg_sum, dynamic_hf_agg_sum_number); + } + if (dynamic_hf_agg_avg_number) { + proto_register_field_array(proto_signal_pdu, dynamic_hf_agg_avg, dynamic_hf_agg_avg_number); + } + if (dynamic_hf_agg_int_number) { + proto_register_field_array(proto_signal_pdu, dynamic_hf_agg_int, dynamic_hf_agg_int_number); + } } } @@ -772,18 +1168,14 @@ reset_spdu_signal_list(void) deregister_user_data(); } -static spdu_signal_list_t* +static spdu_signal_list_t * get_parameter_config(guint64 id) { if (data_spdu_signal_list == NULL) { return NULL; } - gint64 *key = wmem_new(wmem_epan_scope(), gint64); - *key = id; - spdu_signal_list_t *tmp = (spdu_signal_list_t*)g_hash_table_lookup(data_spdu_signal_list, key); - wmem_free(wmem_epan_scope(), key); - - return tmp; + gint64 key = (gint64)id; + return (spdu_signal_list_t *)g_hash_table_lookup(data_spdu_signal_list, &key); } /* UAT: Value Names */ @@ -815,22 +1207,22 @@ copy_spdu_signal_value_name_cb(void *n, const void *o, size_t size _U_) { return new_rec; } -static gboolean +static bool update_spdu_signal_value_name(void *r, char **err) { spdu_signal_value_name_uat_t *rec = (spdu_signal_value_name_uat_t *)r; if (rec->value_name == NULL || rec->value_name[0] == 0) { - *err = g_strdup_printf("Value Name cannot be empty"); + *err = ws_strdup_printf("Value Name cannot be empty"); return FALSE; } if (rec->value_end < rec->value_start) { - *err = g_strdup_printf("Value Range is defined backwards (end < start)!"); + *err = ws_strdup_printf("Value Range is defined backwards (end < start)!"); return FALSE; } if (rec->pos >= 0xffff) { - *err = g_strdup_printf("Position too big"); + *err = ws_strdup_printf("Position too big"); return FALSE; } @@ -838,7 +1230,7 @@ update_spdu_signal_value_name(void *r, char **err) { } static void -free_spdu_signal_value_name_cb(void*r) { +free_spdu_signal_value_name_cb(void *r) { spdu_signal_value_name_uat_t *rec = (spdu_signal_value_name_uat_t *)r; if (rec->value_name) { g_free(rec->value_name); @@ -919,18 +1311,14 @@ post_update_spdu_signal_value_names_cb(void) { post_update_spdu_signal_value_names_read_in_data(spdu_signal_value_names, spdu_parameter_value_names_num, data_spdu_signal_value_names); } -static spdu_signal_value_name_t* +static spdu_signal_value_name_t * get_signal_value_name_config(guint32 id, guint16 pos) { if (data_spdu_signal_list == NULL) { return NULL; } - gint64 *key = wmem_new(wmem_epan_scope(), gint64); - *key = (guint64)id | (guint64)pos << 32; - spdu_signal_value_name_t *tmp = (spdu_signal_value_name_t*)g_hash_table_lookup(data_spdu_signal_value_names, key); - wmem_free(wmem_epan_scope(), key); - - return tmp; + gint64 key = (guint64)id | (guint64)pos << 32; + return (spdu_signal_value_name_t *)g_hash_table_lookup(data_spdu_signal_value_names, &key); } /* UAT: SOME/IP Mapping */ @@ -947,7 +1335,7 @@ spdu_someip_key(guint16 service_id, guint16 method_id, guint8 major_version, gui static void * copy_spdu_someip_mapping_cb(void *n, const void *o, size_t size _U_) { - spdu_someip_mapping_uat_t *new_rec = (spdu_someip_mapping_uat_t *)n; + spdu_someip_mapping_uat_t *new_rec = (spdu_someip_mapping_uat_t *)n; const spdu_someip_mapping_uat_t *old_rec = (const spdu_someip_mapping_uat_t *)o; new_rec->service_id = old_rec->service_id; @@ -959,30 +1347,30 @@ copy_spdu_someip_mapping_cb(void *n, const void *o, size_t size _U_) { return new_rec; } -static gboolean +static bool update_spdu_someip_mapping(void *r, char **err) { spdu_someip_mapping_uat_t *rec = (spdu_someip_mapping_uat_t *)r; if (rec->service_id > 0xffff) { - *err = g_strdup_printf("We currently only support 16 bit SOME/IP Service IDs (Service-ID: %x Method-ID: %x MsgType: %x Version: %i)", + *err = ws_strdup_printf("We currently only support 16 bit SOME/IP Service IDs (Service-ID: %x Method-ID: %x MsgType: %x Version: %i)", rec->service_id, rec->method_id, rec->message_type, rec->major_version); return FALSE; } if (rec->method_id > 0xffff) { - *err = g_strdup_printf("We currently only support 16 bit SOME/IP Method IDs (Service-ID: %x Method-ID: %x MsgType: %x Version: %i)", - rec->service_id, rec->method_id, rec->message_type, rec->major_version); + *err = ws_strdup_printf("We currently only support 16 bit SOME/IP Method IDs (Service-ID: %x Method-ID: %x MsgType: %x Version: %i)", + rec->service_id, rec->method_id, rec->message_type, rec->major_version); return FALSE; } if (rec->major_version > 0xff) { - *err = g_strdup_printf("We currently only support 8 bit SOME/IP major versions (Service-ID: %x Method-ID: %x MsgType: %x Version: %i)", - rec->service_id, rec->method_id, rec->message_type, rec->major_version); + *err = ws_strdup_printf("We currently only support 8 bit SOME/IP major versions (Service-ID: %x Method-ID: %x MsgType: %x Version: %i)", + rec->service_id, rec->method_id, rec->message_type, rec->major_version); } if (rec->message_type > 0xff) { - *err = g_strdup_printf("We currently only support 8 bit SOME/IP message types (Service-ID: %x Method-ID: %x MsgType: %x Version: %i)", - rec->service_id, rec->method_id, rec->message_type, rec->major_version); + *err = ws_strdup_printf("We currently only support 8 bit SOME/IP message types (Service-ID: %x Method-ID: %x MsgType: %x Version: %i)", + rec->service_id, rec->method_id, rec->message_type, rec->major_version); } return TRUE; @@ -1017,21 +1405,17 @@ post_update_spdu_someip_mapping_cb(void) { } /* we need to make sure we register again */ - proto_reg_handoff_signal_pdu_someip(); + register_signal_pdu_someip(); } -static spdu_someip_mapping_t* +static spdu_someip_mapping_t * get_someip_mapping(guint16 service_id, guint16 method_id, guint8 major_version, guint8 message_type) { if (data_spdu_someip_mappings == NULL) { return NULL; } - gint64 *key = wmem_new(wmem_epan_scope(), gint64); - *key = spdu_someip_key(service_id, method_id, major_version, message_type); - spdu_someip_mapping_t *tmp = (spdu_someip_mapping_t*)g_hash_table_lookup(data_spdu_someip_mappings, key); - wmem_free(wmem_epan_scope(), key); - - return tmp; + gint64 key = spdu_someip_key(service_id, method_id, major_version, message_type); + return (spdu_someip_mapping_t *)g_hash_table_lookup(data_spdu_someip_mappings, &key); } /* UAT: CAN Mapping */ @@ -1041,7 +1425,7 @@ UAT_HEX_CB_DEF(spdu_can_mapping, message_id, spdu_can_mapping_uat_t) static void * copy_spdu_can_mapping_cb(void *n, const void *o, size_t size _U_) { - spdu_can_mapping_uat_t *new_rec = (spdu_can_mapping_uat_t *)n; + spdu_can_mapping_uat_t *new_rec = (spdu_can_mapping_uat_t *)n; const spdu_can_mapping_uat_t *old_rec = (const spdu_can_mapping_uat_t *)o; new_rec->can_id = old_rec->can_id; @@ -1051,6 +1435,23 @@ copy_spdu_can_mapping_cb(void *n, const void *o, size_t size _U_) { return new_rec; } +static bool +update_spdu_can_mapping(void *r, char **err) { + spdu_can_mapping_uat_t *rec = (spdu_can_mapping_uat_t *)r; + + if ((rec->can_id & (CAN_RTR_FLAG | CAN_ERR_FLAG)) != 0) { + *err = g_strdup_printf("We currently do not support CAN IDs with RTR or Error Flag set (CAN_ID: 0x%x)", rec->can_id); + return FALSE; + } + + if ((rec->can_id & CAN_EFF_FLAG) == 0 && rec->can_id > CAN_SFF_MASK) { + *err = g_strdup_printf("Standard CAN ID (EFF flag not set) cannot be bigger than 0x7ff (CAN_ID: 0x%x)", rec->can_id); + return FALSE; + } + + return TRUE; +} + static void post_update_spdu_can_mapping_cb(void) { /* destroy old hash table, if it exists */ @@ -1078,27 +1479,24 @@ post_update_spdu_can_mapping_cb(void) { } /* we need to make sure we register again */ - proto_reg_handoff_signal_pdu_can(); + register_signal_pdu_can(); } -static spdu_can_mapping_t* +static spdu_can_mapping_t * get_can_mapping(guint32 id, guint16 bus_id) { if (data_spdu_can_mappings == NULL) { return NULL; } - gint64 *key = wmem_new(wmem_epan_scope(), gint64); - *key = id & CAN_EFF_MASK; - *key |= ((gint64)bus_id << 32); - spdu_can_mapping_t *tmp = (spdu_can_mapping_t*)g_hash_table_lookup(data_spdu_can_mappings, key); + /* key is Bus ID, EFF Flag, CAN-ID*/ + gint64 key = ((gint64)id & (CAN_EFF_MASK | CAN_EFF_FLAG)) | ((gint64)bus_id << 32); + spdu_can_mapping_t *tmp = (spdu_can_mapping_t *)g_hash_table_lookup(data_spdu_can_mappings, &key); if (tmp == NULL) { /* try again without Bus ID set */ - *key = id & CAN_EFF_MASK; - tmp = (spdu_can_mapping_t*)g_hash_table_lookup(data_spdu_can_mappings, key); + key = id & (CAN_EFF_MASK | CAN_EFF_FLAG); + tmp = (spdu_can_mapping_t *)g_hash_table_lookup(data_spdu_can_mappings, &key); } - wmem_free(wmem_epan_scope(), key); - return tmp; } @@ -1111,7 +1509,7 @@ UAT_HEX_CB_DEF(spdu_flexray_mapping, message_id, spdu_flexray_mapping_uat_t) static void * copy_spdu_flexray_mapping_cb(void *n, const void *o, size_t size _U_) { - spdu_flexray_mapping_uat_t *new_rec = (spdu_flexray_mapping_uat_t *)n; + spdu_flexray_mapping_uat_t *new_rec = (spdu_flexray_mapping_uat_t *)n; const spdu_flexray_mapping_uat_t *old_rec = (const spdu_flexray_mapping_uat_t *)o; new_rec->channel = old_rec->channel; @@ -1122,17 +1520,17 @@ copy_spdu_flexray_mapping_cb(void *n, const void *o, size_t size _U_) { return new_rec; } -static gboolean +static bool update_spdu_flexray_mapping(void *r, char **err) { spdu_flexray_mapping_uat_t *rec = (spdu_flexray_mapping_uat_t *)r; if (rec->cycle > 0xff) { - *err = g_strdup_printf("We currently only support 8 bit Cycles (Cycle: %i Frame ID: %i)", rec->cycle, rec->flexray_id); + *err = ws_strdup_printf("We currently only support 8 bit Cycles (Cycle: %i Frame ID: %i)", rec->cycle, rec->flexray_id); return FALSE; } if (rec->flexray_id > 0xffff) { - *err = g_strdup_printf("We currently only support 16 bit Frame IDs (Cycle: %i Frame ID: %i)", rec->cycle, rec->flexray_id); + *err = ws_strdup_printf("We currently only support 16 bit Frame IDs (Cycle: %i Frame ID: %i)", rec->cycle, rec->flexray_id); return FALSE; } @@ -1159,27 +1557,22 @@ post_update_spdu_flexray_mapping_cb(void) { for (i = 0; i < spdu_flexray_mapping_num; i++) { gint64 *key = wmem_new(wmem_epan_scope(), gint64); *key = spdu_flexray_mapping[i].flexray_id & 0xffff; - *key |= (spdu_flexray_mapping[i].cycle & 0xff) << 16; - *key |= (spdu_flexray_mapping[i].channel & 0xff) << 24; + *key |= (gint64)(spdu_flexray_mapping[i].cycle & 0xff) << 16; + *key |= (gint64)(spdu_flexray_mapping[i].channel & 0xff) << 24; g_hash_table_insert(data_spdu_flexray_mappings, key, &spdu_flexray_mapping[i]); } } } -static spdu_flexray_mapping_t* +static spdu_flexray_mapping_t * get_flexray_mapping(guint8 channel, guint8 cycle, guint16 flexray_id) { if (data_spdu_flexray_mappings == NULL) { return NULL; } - gint64 *key = wmem_new(wmem_epan_scope(), gint64); - *key = (channel << 24) | (cycle << 16) | flexray_id; - - spdu_flexray_mapping_t *tmp = (spdu_flexray_mapping_t*)g_hash_table_lookup(data_spdu_flexray_mappings, key); - wmem_free(wmem_epan_scope(), key); - - return tmp; + gint64 key = ((gint64)channel << 24) | ((gint64)cycle << 16) | (gint64)flexray_id; + return (spdu_flexray_mapping_t *)g_hash_table_lookup(data_spdu_flexray_mappings, &key); } @@ -1190,8 +1583,8 @@ UAT_HEX_CB_DEF(spdu_lin_mapping, message_id, spdu_lin_mapping_uat_t) static void * copy_spdu_lin_mapping_cb(void *n, const void *o, size_t size _U_) { - spdu_lin_mapping_uat_t *new_rec = (spdu_lin_mapping_uat_t*)n; - const spdu_lin_mapping_uat_t *old_rec = (const spdu_lin_mapping_uat_t*)o; + spdu_lin_mapping_uat_t *new_rec = (spdu_lin_mapping_uat_t *)n; + const spdu_lin_mapping_uat_t *old_rec = (const spdu_lin_mapping_uat_t *)o; new_rec->frame_id = old_rec->frame_id; new_rec->bus_id = old_rec->bus_id; @@ -1200,17 +1593,17 @@ copy_spdu_lin_mapping_cb(void *n, const void *o, size_t size _U_) { return new_rec; } -static gboolean +static bool update_spdu_lin_mapping(void *r, char **err) { spdu_lin_mapping_uat_t *rec = (spdu_lin_mapping_uat_t *)r; if (rec->frame_id > LIN_ID_MASK) { - *err = g_strdup_printf("LIN Frame IDs are only uint with 6 bits (ID: %i)", rec->frame_id); + *err = ws_strdup_printf("LIN Frame IDs are only uint with 6 bits (ID: %i)", rec->frame_id); return FALSE; } if (rec->bus_id > 0xffff) { - *err = g_strdup_printf("LIN Bus IDs are only uint with 16 bits (ID: 0x%x, Bus ID: 0x%x)", rec->frame_id, rec->bus_id); + *err = ws_strdup_printf("LIN Bus IDs are only uint with 16 bits (ID: 0x%x, Bus ID: 0x%x)", rec->frame_id, rec->bus_id); return FALSE; } @@ -1236,7 +1629,7 @@ post_update_spdu_lin_mapping_cb(void) { guint i; for (i = 0; i < spdu_lin_mapping_num; i++) { gint *key = wmem_new(wmem_epan_scope(), gint); - *key = (spdu_lin_mapping[i].frame_id)&LIN_ID_MASK; + *key = (spdu_lin_mapping[i].frame_id) & LIN_ID_MASK; *key |= ((spdu_lin_mapping[i].bus_id) & 0xffff) << 16; g_hash_table_insert(data_spdu_lin_mappings, key, &spdu_lin_mapping[i]); @@ -1244,29 +1637,25 @@ post_update_spdu_lin_mapping_cb(void) { } /* we need to make sure we register again */ - proto_reg_handoff_signal_pdu_lin(); + register_signal_pdu_lin(); } -static spdu_lin_mapping_t* +static spdu_lin_mapping_t * get_lin_mapping(lin_info_t *lininfo) { if (data_spdu_lin_mappings == NULL) { return NULL; } - gint32 *key = wmem_new(wmem_epan_scope(), gint32); - *key = (lininfo->id)&LIN_ID_MASK; - *key |= ((lininfo->bus_id) & 0xffff) << 16; + gint32 key = ((lininfo->id) & LIN_ID_MASK) | (((lininfo->bus_id) & 0xffff) << 16); - spdu_lin_mapping_uat_t *tmp = (spdu_lin_mapping_uat_t*)g_hash_table_lookup(data_spdu_lin_mappings, key); + spdu_lin_mapping_uat_t *tmp = (spdu_lin_mapping_uat_t *)g_hash_table_lookup(data_spdu_lin_mappings, &key); if (tmp == NULL) { /* try again without Bus ID set */ - *key = (lininfo->id) & LIN_ID_MASK; - tmp = (spdu_lin_mapping_uat_t*)g_hash_table_lookup(data_spdu_lin_mappings, key); + key = (lininfo->id) & LIN_ID_MASK; + tmp = (spdu_lin_mapping_uat_t *)g_hash_table_lookup(data_spdu_lin_mappings, &key); } - wmem_free(wmem_epan_scope(), key); - return tmp; } @@ -1276,8 +1665,8 @@ UAT_HEX_CB_DEF(spdu_pdu_transport_mapping, message_id, spdu_pdu_transport_mappin static void * copy_spdu_pdu_transport_mapping_cb(void *n, const void *o, size_t size _U_) { - spdu_pdu_transport_mapping_uat_t *new_rec = (spdu_pdu_transport_mapping_uat_t*)n; - const spdu_pdu_transport_mapping_uat_t *old_rec = (const spdu_pdu_transport_mapping_uat_t*)o; + spdu_pdu_transport_mapping_uat_t *new_rec = (spdu_pdu_transport_mapping_uat_t *)n; + const spdu_pdu_transport_mapping_uat_t *old_rec = (const spdu_pdu_transport_mapping_uat_t *)o; new_rec->pdu_id = old_rec->pdu_id; new_rec->message_id = old_rec->message_id; @@ -1285,12 +1674,12 @@ copy_spdu_pdu_transport_mapping_cb(void *n, const void *o, size_t size _U_) { return new_rec; } -static gboolean +static bool update_spdu_pdu_transport_mapping(void *r, char **err) { spdu_pdu_transport_mapping_uat_t *rec = (spdu_pdu_transport_mapping_uat_t *)r; if (rec->pdu_id > 0xffffffff) { - *err = g_strdup_printf("PDU-Transport IDs are only uint32 (ID: %i)", rec->pdu_id); + *err = ws_strdup_printf("PDU-Transport IDs are only uint32 (ID: %i)", rec->pdu_id); return FALSE; } @@ -1323,24 +1712,340 @@ post_update_spdu_pdu_transport_mapping_cb(void) { } /* we need to make sure we register again */ - proto_reg_handoff_signal_pdu_pdu_transport(); + register_signal_pdu_pdu_transport(); } -static spdu_pdu_transport_mapping_t* +static spdu_pdu_transport_mapping_t * get_pdu_transport_mapping(guint32 pdu_transport_id) { if (data_spdu_pdu_transport_mappings == NULL) { return NULL; } + gint64 key = pdu_transport_id; + return (spdu_pdu_transport_mapping_uat_t *)g_hash_table_lookup(data_spdu_pdu_transport_mappings, &key); +} + +/* UAT: IPduM Mapping */ +UAT_HEX_CB_DEF(spdu_ipdum_mapping, pdu_id, spdu_ipdum_mapping_uat_t) +UAT_HEX_CB_DEF(spdu_ipdum_mapping, message_id, spdu_ipdum_mapping_uat_t) + +static void * +copy_spdu_ipdum_mapping_cb(void *n, const void *o, size_t size _U_) { + spdu_ipdum_mapping_uat_t *new_rec = (spdu_ipdum_mapping_uat_t *)n; + const spdu_ipdum_mapping_uat_t *old_rec = (const spdu_ipdum_mapping_uat_t *)o; + + new_rec->pdu_id = old_rec->pdu_id; + new_rec->message_id = old_rec->message_id; + + return new_rec; +} + +static bool +update_spdu_ipdum_mapping(void *r, char **err) { + spdu_ipdum_mapping_uat_t *rec = (spdu_ipdum_mapping_uat_t *)r; + + if (rec->pdu_id > 0xffffffff) { + *err = ws_strdup_printf("IPduM IDs are only uint32 (ID: %i)", rec->pdu_id); + return FALSE; + } + + return TRUE; +} + +static void +post_update_spdu_ipdum_mapping_cb(void) { + /* destroy old hash table, if it exists */ + if (data_spdu_ipdum_mappings) { + g_hash_table_destroy(data_spdu_ipdum_mappings); + data_spdu_ipdum_mappings = NULL; + } + + /* we don't need to free the data as long as we don't alloc it first */ + data_spdu_ipdum_mappings = g_hash_table_new_full(g_int64_hash, g_int64_equal, &spdu_payload_free_key, NULL); + + if (data_spdu_ipdum_mappings == NULL || spdu_ipdum_mapping == NULL) { + return; + } + + if (spdu_ipdum_mapping_num > 0) { + guint i; + for (i = 0; i < spdu_ipdum_mapping_num; i++) { + gint64 *key = wmem_new(wmem_epan_scope(), gint64); + *key = spdu_ipdum_mapping[i].pdu_id; + + g_hash_table_insert(data_spdu_ipdum_mappings, key, &spdu_ipdum_mapping[i]); + } + } + + /* we need to make sure we register again */ + register_signal_pdu_ipdum(); +} + +static spdu_ipdum_mapping_uat_t * +get_ipdum_mapping(guint32 pdu_id) { + if (data_spdu_ipdum_mappings == NULL) { + return NULL; + } + + gint64 key = pdu_id; + return (spdu_ipdum_mapping_uat_t *)g_hash_table_lookup(data_spdu_ipdum_mappings, &key); +} + +/* UAT: DLT Mapping */ +UAT_CSTRING_CB_DEF(spdu_dlt_mapping, ecu_id, spdu_dlt_mapping_uat_t) +UAT_HEX_CB_DEF(spdu_dlt_mapping, dlt_message_id, spdu_dlt_mapping_uat_t) +UAT_HEX_CB_DEF(spdu_dlt_mapping, message_id, spdu_dlt_mapping_uat_t) + +static void * +copy_spdu_dlt_mapping_cb(void *n, const void *o, size_t size _U_) { + spdu_dlt_mapping_uat_t *new_rec = (spdu_dlt_mapping_uat_t *)n; + const spdu_dlt_mapping_uat_t *old_rec = (const spdu_dlt_mapping_uat_t *)o; + + if (old_rec->ecu_id) { + new_rec->ecu_id = g_strdup(old_rec->ecu_id); + } else { + new_rec->ecu_id = NULL; + } + + new_rec->dlt_message_id = old_rec->dlt_message_id; + new_rec->message_id = old_rec->message_id; + + return new_rec; +} + +static bool +update_spdu_dlt_mapping(void *r, char **err) { + spdu_dlt_mapping_uat_t *rec = (spdu_dlt_mapping_uat_t *)r; + + if (rec->ecu_id != NULL && strlen(rec->ecu_id) > 4) { + *err = ws_strdup_printf("ECU ID can only be up to 4 characters long!"); + return FALSE; + } + + return TRUE; +} + +static void +post_update_spdu_dlt_mapping_cb(void) { + /* destroy old hash table, if it exists */ + if (data_spdu_dlt_mappings) { + g_hash_table_destroy(data_spdu_dlt_mappings); + data_spdu_dlt_mappings = NULL; + } + + /* we don't need to free the data as long as we don't alloc it first */ + data_spdu_dlt_mappings = g_hash_table_new_full(g_int64_hash, g_int64_equal, &spdu_payload_free_key, NULL); + + if (data_spdu_dlt_mappings == NULL || spdu_dlt_mapping == NULL) { + return; + } + + if (spdu_dlt_mapping_num > 0) { + guint i; + for (i = 0; i < spdu_dlt_mapping_num; i++) { + gint64 *key = wmem_new(wmem_epan_scope(), gint64); + *key = spdu_dlt_mapping[i].dlt_message_id; + *key |= (gint64)(dlt_ecu_id_to_gint32(spdu_dlt_mapping[i].ecu_id)) << 32; + + g_hash_table_insert(data_spdu_dlt_mappings, key, &spdu_dlt_mapping[i]); + } + } +} + +static spdu_dlt_mapping_uat_t * +get_dlt_mapping(guint32 pdu_id, const gchar *ecu_id) { + if (data_spdu_dlt_mappings == NULL) { + return NULL; + } + + gint64 key = pdu_id; + key |= (gint64)dlt_ecu_id_to_gint32(ecu_id) << 32; + + return (spdu_dlt_mapping_uat_t *)g_hash_table_lookup(data_spdu_dlt_mappings, &key); +} + +/* UAT: UDS Mapping */ +UAT_HEX_CB_DEF(spdu_uds_mapping, uds_address, spdu_uds_mapping_uat_t) +UAT_HEX_CB_DEF(spdu_uds_mapping, service, spdu_uds_mapping_uat_t) +UAT_BOOL_CB_DEF(spdu_uds_mapping, reply, spdu_uds_mapping_uat_t) +UAT_HEX_CB_DEF(spdu_uds_mapping, id, spdu_uds_mapping_uat_t) +UAT_HEX_CB_DEF(spdu_uds_mapping, message_id, spdu_uds_mapping_uat_t) + +static void * +copy_spdu_uds_mapping_cb(void *n, const void *o, size_t size _U_) { + spdu_uds_mapping_uat_t *new_rec = (spdu_uds_mapping_uat_t *)n; + const spdu_uds_mapping_uat_t *old_rec = (const spdu_uds_mapping_uat_t *)o; + + new_rec->uds_address = old_rec->uds_address; + new_rec->service = old_rec->service; + new_rec->reply = old_rec->reply; + new_rec->id = old_rec->id; + new_rec->message_id = old_rec->message_id; + + return new_rec; +} + +static bool +update_spdu_uds_mapping(void *r, char **err) { + spdu_uds_mapping_uat_t *rec = (spdu_uds_mapping_uat_t *)r; + + if (rec->id > 0xffff) { + *err = g_strdup_printf("UDS IDs are only uint16!"); + return FALSE; + } + + if (rec->service > 0xff) { + *err = g_strdup_printf("UDS Services are only uint8!"); + return FALSE; + } + + return TRUE; +} + +static void +post_update_spdu_uds_mapping_cb(void) { + /* destroy old hash table, if it exists */ + if (data_spdu_uds_mappings) { + g_hash_table_destroy(data_spdu_uds_mappings); + data_spdu_uds_mappings = NULL; + } + + /* we don't need to free the data as long as we don't alloc it first */ + data_spdu_uds_mappings = g_hash_table_new_full(g_int64_hash, g_int64_equal, &spdu_payload_free_key, NULL); + + if (data_spdu_uds_mappings == NULL || spdu_uds_mapping == NULL) { + return; + } + + if (spdu_uds_mapping_num > 0) { + guint i; + guint32 sid; + for (i = 0; i < spdu_uds_mapping_num; i++) { + gint64 *key = wmem_new(wmem_epan_scope(), gint64); + if (spdu_uds_mapping[i].reply) { + sid = (0xff & spdu_uds_mapping[i].service) | UDS_REPLY_MASK; + } else { + sid = (0xff & spdu_uds_mapping[i].service); + } + + *key = (guint64)(spdu_uds_mapping[i].uds_address) | ((guint64)(0xffff & spdu_uds_mapping[i].id) << 32) | ((guint64)sid << 48); + g_hash_table_insert(data_spdu_uds_mappings, key, &spdu_uds_mapping[i]); + + /* Adding with 0xffffffff (ANY) as address too */ + key = wmem_new(wmem_epan_scope(), gint64); + *key = (guint64)(0xffffffff) | ((guint64)(0xffff & spdu_uds_mapping[i].id) << 32) | ((guint64)sid << 48); + g_hash_table_insert(data_spdu_uds_mappings, key, &spdu_uds_mapping[i]); + } + } +} + +static spdu_uds_mapping_uat_t * +get_uds_mapping(uds_info_t *uds_info) { + guint32 sid; + + DISSECTOR_ASSERT(uds_info); + if (data_spdu_uds_mappings == NULL) { + return NULL; + } + gint64 *key = wmem_new(wmem_epan_scope(), gint64); - *key = pdu_transport_id; + if (uds_info->reply) { + sid = (0xff & uds_info->service) | UDS_REPLY_MASK; + } else { + sid = (0xff & uds_info->service); + } + *key = (guint64)(uds_info->uds_address) | ((guint64)(0xffff & uds_info->id) << 32) | ((guint64)sid << 48); + + spdu_uds_mapping_uat_t *tmp = (spdu_uds_mapping_uat_t *)g_hash_table_lookup(data_spdu_uds_mappings, key); + + /* if we cannot find it for the Address, lets look at MAXUINT32 */ + if (tmp == NULL) { + *key = (guint64)(G_MAXUINT32) | ((guint64)(0xffff & uds_info->id) << 32) | ((guint64)sid << 48); + + tmp = (spdu_uds_mapping_uat_t *)g_hash_table_lookup(data_spdu_uds_mappings, key); + } - spdu_pdu_transport_mapping_uat_t *tmp = (spdu_pdu_transport_mapping_uat_t*)g_hash_table_lookup(data_spdu_pdu_transport_mappings, key); wmem_free(wmem_epan_scope(), key); return tmp; } +/* UAT: ISOBUS Mapping */ +UAT_HEX_CB_DEF(spdu_isobus_mapping, pgn, spdu_isobus_mapping_uat_t) +UAT_HEX_CB_DEF(spdu_isobus_mapping, bus_id, spdu_isobus_mapping_uat_t) +UAT_HEX_CB_DEF(spdu_isobus_mapping, message_id, spdu_isobus_mapping_uat_t) + +static void * +copy_spdu_isobus_mapping_cb(void *n, const void *o, size_t size _U_) { + spdu_isobus_mapping_uat_t *new_rec = (spdu_isobus_mapping_uat_t *)n; + const spdu_isobus_mapping_uat_t *old_rec = (const spdu_isobus_mapping_uat_t *)o; + + new_rec->pgn = old_rec->pgn; + new_rec->bus_id = old_rec->bus_id; + new_rec->message_id = old_rec->message_id; + + return new_rec; +} + +static bool +update_spdu_isobus_mapping(void *r, char **err) { + spdu_isobus_mapping_uat_t *rec = (spdu_isobus_mapping_uat_t *)r; + + if (rec->pgn > 0x03ffff) { + *err = g_strdup_printf("PGN %u > %u!", rec->pgn, 0x03ffff); + return FALSE; + } + + return TRUE; +} + +static void +post_update_spdu_isobus_mapping_cb(void) { + /* destroy old hash table, if it exists */ + if (data_spdu_isobus_mappings) { + g_hash_table_destroy(data_spdu_isobus_mappings); + data_spdu_isobus_mappings = NULL; + } + + /* we don't need to free the data as long as we don't alloc it first */ + data_spdu_isobus_mappings = g_hash_table_new_full(g_int64_hash, g_int64_equal, &spdu_payload_free_key, NULL); + + if (data_spdu_isobus_mappings == NULL || spdu_isobus_mapping == NULL) { + return; + } + + if (spdu_isobus_mapping_num > 0) { + guint i; + for (i = 0; i < spdu_isobus_mapping_num; i++) { + gint64 *key = wmem_new(wmem_epan_scope(), gint64); + *key = spdu_isobus_mapping[i].pgn; + *key |= ((gint64)(spdu_isobus_mapping[i].bus_id & 0xffff)) << 32; + + g_hash_table_insert(data_spdu_isobus_mappings, key, &spdu_isobus_mapping[i]); + } + } + + /* we need to make sure we register again */ + register_signal_pdu_isobus(); +} + +static spdu_isobus_mapping_uat_t * +get_isobus_mapping(guint32 pgn, guint16 bus_id) { + if (data_spdu_isobus_mappings == NULL) { + return NULL; + } + + /* key is PGN */ + gint64 key = ((gint64)pgn) | ((gint64)bus_id << 32); + spdu_isobus_mapping_t *tmp = (spdu_isobus_mapping_t *)g_hash_table_lookup(data_spdu_isobus_mappings, &key); + if (tmp == NULL) { + /* try again without Bus ID set */ + key = (gint64)pgn; + tmp = (spdu_isobus_mapping_t *)g_hash_table_lookup(data_spdu_isobus_mappings, &key); + } + + return tmp; +} /************************************** ******** Expert Infos ******** @@ -1348,16 +2053,98 @@ get_pdu_transport_mapping(guint32 pdu_transport_id) { static void expert_spdu_payload_truncated(proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, gint offset, gint length) { - proto_tree_add_expert(tree, pinfo, &ef_spdu_payload_truncated, tvb, offset, length); + proto_tree_add_expert(tree, pinfo, &ei_spdu_payload_truncated, tvb, offset, length); col_append_str(pinfo->cinfo, COL_INFO, " [Signal PDU: Truncated payload!]"); } static void expert_spdu_config_error(proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, gint offset, gint length) { - proto_tree_add_expert(tree, pinfo, &ef_spdu_config_error, tvb, offset, length); + proto_tree_add_expert(tree, pinfo, &ei_spdu_config_error, tvb, offset, length); col_append_str(pinfo->cinfo, COL_INFO, " [Signal PDU: Config Error!]"); } +static void +expert_spdu_unaligned_data(proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, gint offset, gint length) { + proto_tree_add_expert(tree, pinfo, &ei_spdu_unaligned_data, tvb, offset, length); + col_append_str(pinfo->cinfo, COL_INFO, " [Signal PDU: Unaligned Data!]"); +} + + +/************************************** + ******** Aggregation Feature ******** + **************************************/ + +typedef struct _spdu_frame_data { + gdouble sum; + guint32 count; + gdouble avg; + gdouble sum_time_value_products; +} spdu_frame_data_t; + +typedef struct _spdu_aggregation { + gdouble sum; + guint32 count; + nstime_t start_time; + + nstime_t last_time; + gdouble last_value; + gdouble sum_time_value_products; +} spdu_aggregation_t; + +static wmem_map_t *spdu_aggregation_data = NULL; + +static spdu_aggregation_t * +get_or_create_aggregation_data(packet_info *pinfo, gint hf_id_effective) { + DISSECTOR_ASSERT(spdu_aggregation_data != NULL); + DISSECTOR_ASSERT(hf_id_effective > 0); + + spdu_aggregation_t *data = (spdu_aggregation_t *)wmem_map_lookup(spdu_aggregation_data, GINT_TO_POINTER(hf_id_effective)); + + if (data == NULL) + { + data = wmem_new0(wmem_file_scope(), spdu_aggregation_t); + data->sum = 0; + data->count = 0; + data->start_time = pinfo->abs_ts; + data->last_time = pinfo->abs_ts; + data->sum_time_value_products = 0.0; + wmem_map_insert(spdu_aggregation_data, GINT_TO_POINTER(hf_id_effective), data); + } + + return data; +} + + +/************************************** + ******** Dissector Helpers ******** + **************************************/ + +/* There is similar code in tvbuff.c ... */ + +static gdouble +spdu_ieee_double_from_64bits(guint64 value) { + union { + gdouble d; + guint64 w; + } ieee_fp_union; + + ieee_fp_union.w = value; + + return ieee_fp_union.d; +} + +static gfloat +spdu_ieee_float_from_32bits(guint32 value) { + union { + gfloat d; + guint32 w; + } ieee_fp_union; + + ieee_fp_union.w = value; + + return ieee_fp_union.d; +} + /************************************** ******** Signal PDU Dissector ******** @@ -1421,6 +2208,9 @@ dissect_shifted_and_shortened_uint(tvbuff_t *tvb, gint offset, gint offset_bits, static int dissect_spdu_payload_signal(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset, gint offset_bits, spdu_signal_item_t *item, spdu_signal_value_name_t *value_name_config, gint *multiplexer) { + DISSECTOR_ASSERT(item != NULL); + DISSECTOR_ASSERT(item->hf_id_effective != NULL); + proto_item *ti = NULL; proto_tree *subtree = NULL; @@ -1431,22 +2221,23 @@ dissect_spdu_payload_signal(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint offset_end = (gint)((8 * offset + offset_bits + item->bitlength_encoded_type) / 8); gint offset_end_bits = (gint)((8 * offset + offset_bits + item->bitlength_encoded_type) % 8); + gint string_length = 0; gint signal_length = offset_end - offset; if (offset_end_bits != 0) { signal_length++; } - if (tvb_captured_length_remaining(tvb, offset) < signal_length) { - expert_spdu_payload_truncated(tree, pinfo, tvb, offset, tvb_captured_length_remaining(tvb, offset)); - return -1; - } - if (item->multiplex_value_only != -1 && item->multiplex_value_only != *multiplexer) { /* multiplexer set and we are in the wrong multiplex */ return 0; } - if (!spdu_derserializer_show_hidden && item->hidden) { + if (tvb_captured_length_remaining(tvb, offset) < signal_length) { + expert_spdu_payload_truncated(tree, pinfo, tvb, offset, tvb_captured_length_remaining(tvb, offset)); + return -1; + } + + if (!spdu_deserializer_show_hidden && item->hidden) { return (gint)item->bitlength_encoded_type; } @@ -1468,8 +2259,14 @@ dissect_spdu_payload_signal(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint64 value_guint64 = dissect_shifted_and_shortened_uint(tvb, offset, offset_bits, offset_end, offset_end_bits, item->big_endian); - if (g_strcmp0("uint", item->data_type) == 0) { - gdouble value_gdouble = (gdouble)value_guint64; + /* we need to reset this because it is reused */ + ti = NULL; + + gdouble value_gdouble = 0.0; + + switch (item->data_type) { + case SPDU_DATA_TYPE_UINT: { + value_gdouble = (gdouble)value_guint64; if (item->multiplexer) { *multiplexer = (gint)value_guint64; @@ -1493,17 +2290,20 @@ dissect_spdu_payload_signal(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, ti = proto_tree_add_uint64(tree, hf_id_effective, tvb, offset, signal_length, value_guint64); } if (value_name != NULL) { - proto_item_append_text(ti, " [raw: 0x%" G_GINT64_MODIFIER "x: %s]", value_guint64, value_name); + proto_item_append_text(ti, " [raw: 0x%" PRIx64 ": %s]", value_guint64, value_name); } else { - proto_item_append_text(ti, " [raw: 0x%" G_GINT64_MODIFIER "x]", value_guint64); + proto_item_append_text(ti, " [raw: 0x%" PRIx64 "]", value_guint64); } subtree = proto_item_add_subtree(ti, ett_spdu_signal); ti = proto_tree_add_uint64(subtree, hf_id_raw, tvb, offset, signal_length, value_guint64); - proto_item_append_text(ti, " (0x%" G_GINT64_MODIFIER "x)", value_guint64); - } else if (g_strcmp0("int", item->data_type) == 0) { + proto_item_append_text(ti, " (0x%" PRIx64 ")", value_guint64); + } + break; + + case SPDU_DATA_TYPE_INT: { gint64 value_gint64 = ws_sign_ext64(value_guint64, (gint)item->bitlength_encoded_type); - gdouble value_gdouble = (gdouble)value_gint64; + value_gdouble = (gdouble)value_gint64; if (item->multiplexer) { *multiplexer = (gint)value_gint64; @@ -1517,22 +2317,134 @@ dissect_spdu_payload_signal(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, ti = proto_tree_add_int64(tree, hf_id_effective, tvb, offset, signal_length, value_gint64); } if (value_name != NULL) { - proto_item_append_text(ti, " [raw: %" G_GINT64_MODIFIER "x: %s]", value_gint64, value_name); + proto_item_append_text(ti, " [raw: %" PRIx64 ": %s]", value_gint64, value_name); } else { - proto_item_append_text(ti, " [raw: %" G_GINT64_MODIFIER "x]", value_gint64); + proto_item_append_text(ti, " [raw: %" PRIx64 "]", value_gint64); } subtree = proto_item_add_subtree(ti, ett_spdu_signal); ti = proto_tree_add_int64(subtree, hf_id_raw, tvb, offset, signal_length, value_gint64); - proto_item_append_text(ti, " (0x%" G_GINT64_MODIFIER "x)", value_gint64); + proto_item_append_text(ti, " (0x%" PRIx64 ")", value_gint64); + } + break; + + case SPDU_DATA_TYPE_FLOAT: { + value_gdouble = 0.0; + + switch (item->bitlength_base_type) { + case 64: + value_gdouble = spdu_ieee_double_from_64bits(value_guint64); + break; + case 32: + value_gdouble = (gdouble)spdu_ieee_float_from_32bits((guint32)value_guint64); + break; + default: + /* not supported and cannot occur since the config is checked! */ + break; + } + + /* scaler, offset, multiplexer not allowed by config checks */ + + ti = proto_tree_add_double(tree, hf_id_effective, tvb, offset, signal_length, value_gdouble); + + if (value_name != NULL) { + proto_item_append_text(ti, " [raw: 0x%" PRIx64 ": %s]", value_guint64, value_name); + } else { + proto_item_append_text(ti, " [raw: 0x%" PRIx64 "]", value_guint64); + } + + subtree = proto_item_add_subtree(ti, ett_spdu_signal); + ti = proto_tree_add_double(subtree, hf_id_raw, tvb, offset, signal_length, value_gdouble); + proto_item_append_text(ti, " [raw: 0x%" PRIx64 "]", value_guint64); + } + break; + + case SPDU_DATA_TYPE_STRING: + if (offset_bits != 0) { + expert_spdu_unaligned_data(tree, pinfo, tvb, offset, 0); + } + + proto_tree_add_item(tree, hf_id_effective, tvb, offset, signal_length, item->encoding); + break; + + case SPDU_DATA_TYPE_STRINGZ: + if (offset_bits != 0) { + expert_spdu_unaligned_data(tree, pinfo, tvb, offset, 0); + } + proto_tree_add_item_ret_length(tree, hf_id_effective, tvb, offset, -1, item->encoding, &string_length); + string_length *= 8; + break; + + case SPDU_DATA_TYPE_UINT_STRING: + if (offset_bits != 0) { + expert_spdu_unaligned_data(tree, pinfo, tvb, offset, 0); + } + + if (item->big_endian) { + proto_tree_add_item_ret_length(tree, hf_id_effective, tvb, offset, signal_length, item->encoding | ENC_BIG_ENDIAN, &string_length); + } else { + proto_tree_add_item_ret_length(tree, hf_id_effective, tvb, offset, signal_length, item->encoding | ENC_LITTLE_ENDIAN, &string_length); + } + string_length = string_length * 8 - (gint)item->bitlength_encoded_type; + break; + + case SPDU_DATA_TYPE_NONE: + /* do nothing */ + break; } /* hide raw value per default, if effective value is present */ - if (spdu_derserializer_hide_raw_values) { + if (spdu_deserializer_hide_raw_values) { proto_item_set_hidden(ti); } - return (gint)item->bitlength_encoded_type; + /* Value passed in with value_gdouble, tree via subtree. */ + if (item->aggregate_sum || item->aggregate_avg || item->aggregate_int) { + gint hf_id_eff = *(item->hf_id_effective); + spdu_aggregation_t *agg_data = get_or_create_aggregation_data(pinfo, hf_id_eff); + spdu_frame_data_t *spdu_frame_data = (spdu_frame_data_t *)p_get_proto_data(wmem_file_scope(), pinfo, proto_signal_pdu, (guint32)hf_id_eff); + + if (!PINFO_FD_VISITED(pinfo)) { + nstime_t delta; + + agg_data->sum += value_gdouble; + agg_data->count++; + + nstime_delta(&delta, &(pinfo->abs_ts), &(agg_data->last_time)); + gdouble delta_s = nstime_to_sec(&delta); + + if (delta_s > 0.0) { + agg_data->sum_time_value_products += delta_s * agg_data->last_value; + agg_data->last_time = pinfo->abs_ts; + } + agg_data->last_value = value_gdouble; + + if (!spdu_frame_data) { + spdu_frame_data = wmem_new0(wmem_file_scope(), spdu_frame_data_t); + p_add_proto_data(wmem_file_scope(), pinfo, proto_signal_pdu, (guint32)hf_id_eff, spdu_frame_data); + } + + spdu_frame_data->sum = agg_data->sum; + spdu_frame_data->count = agg_data->count; + spdu_frame_data->avg = agg_data->sum / agg_data->count; + spdu_frame_data->sum_time_value_products = agg_data->sum_time_value_products; + } + + /* if frame data was not created on first pass, we cannot calculate it now */ + if (spdu_frame_data != NULL) { + if (item->aggregate_sum) { + proto_tree_add_double(subtree, *(item->hf_id_agg_sum), tvb, offset, signal_length, spdu_frame_data->sum); + } + if (item->aggregate_avg) { + proto_tree_add_double(subtree, *(item->hf_id_agg_avg), tvb, offset, signal_length, spdu_frame_data->avg); + } + if (item->aggregate_int && (spdu_frame_data->sum_time_value_products == spdu_frame_data->sum_time_value_products)) { + proto_tree_add_double(subtree, *(item->hf_id_agg_int), tvb, offset, signal_length, spdu_frame_data->sum_time_value_products); + } + } + } + + return (gint)item->bitlength_encoded_type + string_length; } static int @@ -1553,6 +2465,9 @@ dissect_spdu_payload(tvbuff_t *tvb, packet_info *pinfo, proto_tree *root_tree, g col_append_fstr(pinfo->cinfo, COL_INFO, " (PDU: %s)", name); col_set_str(pinfo->cinfo, COL_PROTOCOL, SPDU_NAME); } + ti = proto_tree_add_string(tree, hf_pdu_name, tvb, offset, -1, name); + proto_item_set_generated(ti); + proto_item_set_hidden(ti); } spdu_signal_list_t *paramlist = get_parameter_config(id); @@ -1562,13 +2477,20 @@ dissect_spdu_payload(tvbuff_t *tvb, packet_info *pinfo, proto_tree *root_tree, g return 0; } - if (root_tree == NULL && !proto_field_is_referenced(root_tree, proto_signal_pdu)) { - /* we only receive subtvbs with nothing behind us */ + if (!spdu_deserializer_activated) { + /* we only receive a tvb with nothing behind us */ + proto_tree_add_text_internal(tree, tvb, 0, tvb_captured_length(tvb), "Dissection of payload is disabled. It can be enabled via protocol preferences."); return tvb_captured_length(tvb); } - if (paramlist == NULL || !spdu_derserializer_activated) { - /* we only receive subtvbs with nothing behind us */ + if (tvb_captured_length(tvb) > 0 && paramlist == NULL) { + /* we only receive a tvb with nothing behind us */ + proto_tree_add_text_internal(tree, tvb, 0, tvb_captured_length(tvb), "Payload of PDU is not configured. See protocol preferences."); + return tvb_captured_length(tvb); + } + + if (root_tree == NULL && !proto_field_is_referenced(root_tree, proto_signal_pdu) && !paramlist->aggregation) { + /* we only receive a tvb with nothing behind us */ return tvb_captured_length(tvb); } @@ -1586,15 +2508,19 @@ dissect_spdu_payload(tvbuff_t *tvb, packet_info *pinfo, proto_tree *root_tree, g } if (bits_parsed != -1 && length > offset + 1) { - proto_tree_add_item(tree, hf_payload_unparsed, tvb, offset + 1, length - (offset + 1), ENC_NA); + if (offset_bits == 0) { + proto_tree_add_item(tree, hf_payload_unparsed, tvb, offset, length - offset, ENC_NA); + } else { + proto_tree_add_item(tree, hf_payload_unparsed, tvb, offset + 1, length - (offset + 1), ENC_NA); + } } - return length - (offset + 1); + return offset; } static int dissect_spdu_message_someip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) { - someip_info_t *someip_info = (someip_info_t*)data; + someip_info_t *someip_info = (someip_info_t *)data; DISSECTOR_ASSERT(someip_info); @@ -1632,7 +2558,7 @@ dissect_spdu_message_can_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tre static int dissect_spdu_message_flexray(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) { - struct flexray_info *flexray_data = (struct flexray_info*)data; + struct flexray_info *flexray_data = (struct flexray_info *)data; DISSECTOR_ASSERT(flexray_data); spdu_flexray_mapping_t *flexray_mapping = get_flexray_mapping(flexray_data->ch, flexray_data->cc, flexray_data->id); @@ -1666,7 +2592,7 @@ dissect_spdu_message_lin(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, vo static int dissect_spdu_message_pdu_transport(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) { - pdu_transport_info_t *pdu_info = (pdu_transport_info_t*)data; + pdu_transport_info_t *pdu_info = (pdu_transport_info_t *)data; DISSECTOR_ASSERT(pdu_info); spdu_pdu_transport_mapping_t *pdu_transport_mapping = get_pdu_transport_mapping(pdu_info->id); @@ -1678,6 +2604,60 @@ dissect_spdu_message_pdu_transport(tvbuff_t *tvb, packet_info *pinfo, proto_tree return dissect_spdu_payload(tvb, pinfo, tree, pdu_transport_mapping->message_id, FALSE); } +static int +dissect_spdu_message_ipdum(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) { + autosar_ipdu_multiplexer_info_t *pdu_info = (autosar_ipdu_multiplexer_info_t *)data; + DISSECTOR_ASSERT(pdu_info); + + spdu_ipdum_mapping_uat_t *ipdum_mapping = get_ipdum_mapping(pdu_info->pdu_id); + + if (ipdum_mapping == NULL) { + return 0; + } + + return dissect_spdu_payload(tvb, pinfo, tree, ipdum_mapping->message_id, TRUE); +} + +static int +dissect_spdu_message_dlt_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) { + dlt_info_t *pdu_info = (dlt_info_t *)data; + DISSECTOR_ASSERT(pdu_info); + + spdu_dlt_mapping_uat_t *dlt_mapping = get_dlt_mapping(pdu_info->message_id, pdu_info->ecu_id); + + if (dlt_mapping == NULL) { + return 0; + } + + return dissect_spdu_payload(tvb, pinfo, tree, dlt_mapping->message_id, TRUE); +} + +static gboolean +dissect_spdu_message_uds_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) { + uds_info_t *uds_info = (uds_info_t *)data; + DISSECTOR_ASSERT(uds_info); + + spdu_uds_mapping_t *uds_mapping = get_uds_mapping(uds_info); + if (uds_mapping == NULL) { + return FALSE; + } + + return dissect_spdu_payload(tvb, pinfo, tree, uds_mapping->message_id, FALSE) != 0; +} + +static int +dissect_spdu_message_isobus(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) { + isobus_info_t *isobus_info = (isobus_info_t *)data; + DISSECTOR_ASSERT(isobus_info); + + spdu_isobus_mapping_t *isobus_mapping = get_isobus_mapping(isobus_info->pgn, isobus_info->bus_id); + + if (isobus_mapping == NULL) { + return 0; + } + + return dissect_spdu_payload(tvb, pinfo, tree, isobus_mapping->message_id, TRUE); +} /************************************** ******** Register Dissector ******** @@ -1689,22 +2669,28 @@ proto_register_signal_pdu(void) { expert_module_t *expert_module_lpdu; /* UAT for naming */ - uat_t *spdu_messages_uat; + uat_t *spdu_messages_uat; /* the UATs for parsing the message*/ - uat_t *spdu_signal_list_uat; - uat_t *spdu_parameter_value_names_uat; + uat_t *spdu_signal_list_uat; + uat_t *spdu_parameter_value_names_uat; /* UATs for mapping different incoming payloads to messages*/ - uat_t *spdu_someip_mapping_uat; - uat_t *spdu_can_mapping_uat; - uat_t *spdu_flexray_mapping_uat; - uat_t *spdu_lin_mapping_uat; - uat_t *spdu_pdu_transport_mapping_uat; - + uat_t *spdu_someip_mapping_uat; + uat_t *spdu_can_mapping_uat; + uat_t *spdu_flexray_mapping_uat; + uat_t *spdu_lin_mapping_uat; + uat_t *spdu_pdu_transport_mapping_uat; + uat_t *spdu_ipdum_mapping_uat; + uat_t *spdu_dlt_mapping_uat; + uat_t *spdu_uds_mapping_uat; + uat_t *spdu_isobus_mapping_uat; /* data fields */ static hf_register_info hf[] = { + { &hf_pdu_name, + { "Signal PDU Name", "signal_pdu.name", + FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }}, { &hf_payload_unparsed, { "Unparsed Payload", "signal_pdu.payload.unparsed", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }}, @@ -1729,15 +2715,18 @@ proto_register_signal_pdu(void) { UAT_FLD_DEC(spdu_signal_list, pos, "Signal Position", "Position of signal (16bit dec, starting with 0)"), UAT_FLD_CSTRING(spdu_signal_list, name, "Signal Name", "Name of signal (string)"), UAT_FLD_CSTRING(spdu_signal_list, filter_string, "Filter String", "Unique filter string that will be prepended with signal_pdu. (string)"), - UAT_FLD_CSTRING(spdu_signal_list, data_type, "Data Type", "Data type (string), [uint|int]"), + UAT_FLD_CSTRING(spdu_signal_list, data_type, "Data Type", "Data type (string), [uint|int|float|string|stringz|uint_string|utf8_string|utf8_stringz|utf8_uint_string]"), UAT_FLD_BOOL(spdu_signal_list, big_endian, "Big Endian?", "Big Endian encoded [FALSE|TRUE]"), - UAT_FLD_DEC(spdu_signal_list, bitlength_base_type, "Bitlength base type", "Bitlength base type (uint32 dec)"), - UAT_FLD_DEC(spdu_signal_list, bitlength_encoded_type, "Bitlength enc. type", "Bitlength encoded type (uint32 dec)"), + UAT_FLD_DEC(spdu_signal_list, bitlength_base_type, "Bitlength base type", "Bitlength base type (uint32 dec). The length of the original type or the length of a single character."), + UAT_FLD_DEC(spdu_signal_list, bitlength_encoded_type, "Bitlength enc. type", "Bitlength encoded type (uint32 dec). The shortened length of uints or the total length of string/utf8_string or the length of the uint_string/utf8_uint_string length field."), UAT_FLD_CSTRING(spdu_signal_list, scaler, "Scaler", "Raw value is multiplied by this Scaler, e.g. 1.0 (double)"), UAT_FLD_CSTRING(spdu_signal_list, offset, "Offset", "Scaled raw value is shifted by this Offset, e.g. 1.0 (double)"), UAT_FLD_BOOL(spdu_signal_list, multiplexer, "Multiplexer?", "Is this used as multiplexer? [FALSE|TRUE]"), UAT_FLD_SIGNED_DEC(spdu_signal_list, multiplex_value_only, "Multiplexer value", "The multiplexer value for which this is relevant (-1 all)"), UAT_FLD_BOOL(spdu_signal_list, hidden, "Hidden?", "Should this field be hidden in the dissection? [FALSE|TRUE]"), + UAT_FLD_BOOL(spdu_signal_list, aggregate_sum, "Calc Sum?", "Should this field be aggregated using sum function? [FALSE|TRUE]"), + UAT_FLD_BOOL(spdu_signal_list, aggregate_avg, "Calc Avg?", "Should this field be aggregated using average function? [FALSE|TRUE]"), + UAT_FLD_BOOL(spdu_signal_list, aggregate_int, "Calc Int?", "Should this field be aggregated using integrate function (sum of time value product)? [FALSE|TRUE]"), UAT_END_FIELDS }; @@ -1761,7 +2750,7 @@ proto_register_signal_pdu(void) { }; static uat_field_t spdu_can_mapping_uat_fields[] = { - UAT_FLD_HEX(spdu_can_mapping, can_id, "CAN ID", "CAN ID (32bit hex without leading 0x)"), + UAT_FLD_HEX(spdu_can_mapping, can_id, "CAN ID", "CAN ID (32bit hex without leading 0x, highest bit 1 for extended, 0 for standard ID)"), UAT_FLD_HEX(spdu_can_mapping, bus_id, "Bus ID", "Bus ID on which frame was recorded with 0=any (16bit hex without leading 0x)"), UAT_FLD_HEX(spdu_can_mapping, message_id, "Signal PDU ID", "ID of the Signal PDU (32bit hex without leading 0x)"), UAT_END_FIELDS @@ -1788,11 +2777,42 @@ proto_register_signal_pdu(void) { UAT_END_FIELDS }; + static uat_field_t spdu_ipdum_mapping_uat_fields[] = { + UAT_FLD_HEX(spdu_ipdum_mapping, pdu_id, "PDU ID", "PDU ID (32bit hex without leading 0x)"), + UAT_FLD_HEX(spdu_ipdum_mapping, message_id, "Signal PDU ID", "ID of the Signal PDU (32bit hex without leading 0x)"), + UAT_END_FIELDS + }; + + static uat_field_t spdu_dlt_mapping_uat_fields[] = { + UAT_FLD_CSTRING(spdu_dlt_mapping, ecu_id, "ECU ID", "ECU ID (4 ASCII chars only!)"), + UAT_FLD_HEX(spdu_dlt_mapping, dlt_message_id, "DLT Message ID", "Message ID (32bit hex without leading 0x)"), + UAT_FLD_HEX(spdu_dlt_mapping, message_id, "Signal PDU ID", "ID of the Signal PDU (32bit hex without leading 0x)"), + UAT_END_FIELDS + }; + + static uat_field_t spdu_uds_mapping_uat_fields[] = { + UAT_FLD_HEX(spdu_uds_mapping, uds_address, "ECU Address", "ECU Address (32bit hex without leading 0x, 0xffffffff means any)"), + UAT_FLD_HEX(spdu_uds_mapping, service, "UDS Service", "UDS Service (8bit hex without leading 0x)"), + UAT_FLD_BOOL(spdu_uds_mapping, reply, "Reply", "Reply [FALSE|TRUE]"), + UAT_FLD_HEX(spdu_uds_mapping, id, "ID", "ID (16bit hex without leading 0x)"), + UAT_FLD_HEX(spdu_uds_mapping, message_id, "Signal PDU ID", "ID of the Signal PDU (32bit hex without leading 0x)"), + UAT_END_FIELDS + }; + + static uat_field_t spdu_isobus_mapping_uat_fields[] = { + UAT_FLD_HEX(spdu_isobus_mapping, pgn, "PGN", "PGN (18bit hex without leading 0x)"), + UAT_FLD_HEX(spdu_isobus_mapping, bus_id, "Bus ID", "Bus ID on which frame was recorded with 0=any (16bit hex without leading 0x)"), + UAT_FLD_HEX(spdu_isobus_mapping, message_id, "Signal PDU ID", "ID of the Signal PDU (32bit hex without leading 0x)"), + UAT_END_FIELDS + }; + static ei_register_info ei[] = { - { &ef_spdu_payload_truncated, {"signal_pdu.payload.expert_truncated", + { &ei_spdu_payload_truncated, {"signal_pdu.payload.expert_truncated", PI_MALFORMED, PI_ERROR, "Signal PDU: Truncated payload!", EXPFILL} }, - { &ef_spdu_config_error, {"signal_pdu.payload.config_error", + { &ei_spdu_config_error, {"signal_pdu.payload.config_error", PI_MALFORMED, PI_ERROR, "Signal PDU: Config Error (missing filter, filter duplicate, ...)!", EXPFILL} }, + { &ei_spdu_unaligned_data, {"signal_pdu.payload.unaligned_data", + PI_MALFORMED, PI_ERROR, "Signal PDU: Unaligned data! Strings etc. need to be aligned to bytes!", EXPFILL} }, }; /* Register ETTs */ @@ -1808,19 +2828,19 @@ proto_register_signal_pdu(void) { /* UATs */ spdu_messages_uat = uat_new("Signal PDU Messages", - sizeof(generic_one_id_string_t), /* record size */ - DATAFILE_SPDU_MESSAGES, /* filename */ - TRUE, /* from profile */ - (void**) &spdu_message_ident, /* data_ptr */ - &spdu_message_ident_num, /* numitems_ptr */ - UAT_AFFECTS_DISSECTION, /* but not fields */ - NULL, /* help */ - copy_generic_one_id_string_cb, /* copy callback */ - update_generic_one_identifier_32bit, /* update callback */ - free_generic_one_id_string_cb, /* free callback */ - post_update_spdu_message_cb, /* post update callback */ - NULL, /* reset callback */ - spdu_messages_uat_fields /* UAT field definitions */ + sizeof(generic_one_id_string_t), /* record size */ + DATAFILE_SPDU_MESSAGES, /* filename */ + TRUE, /* from profile */ + (void **)&spdu_message_ident, /* data_ptr */ + &spdu_message_ident_num, /* numitems_ptr */ + UAT_AFFECTS_DISSECTION, /* but not fields */ + NULL, /* help */ + copy_generic_one_id_string_cb, /* copy callback */ + update_generic_one_identifier_32bit, /* update callback */ + free_generic_one_id_string_cb, /* free callback */ + post_update_spdu_message_cb, /* post update callback */ + NULL, /* reset callback */ + spdu_messages_uat_fields /* UAT field definitions */ ); prefs_register_uat_preference(spdu_module, "_spdu_signal_pdus", "Signal PDUs", @@ -1832,70 +2852,82 @@ proto_register_signal_pdu(void) { prefs_register_bool_preference(spdu_module, "payload_dissector_activated", "Dissect Payload", "Should the payload dissector be active?", - &spdu_derserializer_activated); + &spdu_deserializer_activated); prefs_register_bool_preference(spdu_module, "payload_dissector_show_hidden", "Show hidden entries", "Should the payload dissector show entries marked as hidden in the configuration?", - &spdu_derserializer_show_hidden); + &spdu_deserializer_show_hidden); prefs_register_bool_preference(spdu_module, "payload_dissector_hide_raw_values", "Hide raw values", "Should the payload dissector hide raw values?", - &spdu_derserializer_hide_raw_values); + &spdu_deserializer_hide_raw_values); spdu_parameter_value_names_uat = uat_new("Signal Value Names", - sizeof(spdu_signal_value_name_uat_t), DATAFILE_SPDU_VALUE_NAMES, TRUE, - (void**)&spdu_signal_value_names, - &spdu_parameter_value_names_num, - UAT_AFFECTS_DISSECTION, - NULL, /* help */ - copy_spdu_signal_value_name_cb, - update_spdu_signal_value_name, - free_spdu_signal_value_name_cb, - post_update_spdu_signal_value_names_cb, - NULL, /* reset */ - spdu_parameter_value_name_uat_fields + sizeof(spdu_signal_value_name_uat_t), /* record size */ + DATAFILE_SPDU_VALUE_NAMES, /* filename */ + TRUE, /* from profile */ + (void **)&spdu_signal_value_names, /* data_ptr */ + &spdu_parameter_value_names_num, /* numitems_ptr */ + UAT_AFFECTS_DISSECTION, /* but not fields */ + NULL, /* help */ + copy_spdu_signal_value_name_cb, /* copy callback */ + update_spdu_signal_value_name, /* update callback */ + free_spdu_signal_value_name_cb, /* free callback */ + post_update_spdu_signal_value_names_cb, /* post update callback */ + NULL, /* reset callback */ + spdu_parameter_value_name_uat_fields /* UAT field definitions */ ); /* value names must be for signals since we need this data for the later */ prefs_register_uat_preference(spdu_module, "_spdu_parameter_value_names", "Value Names", "A table to define names of signal values", spdu_parameter_value_names_uat); + spdu_signal_list_uat = uat_new("Signal PDU Signal List", - sizeof(spdu_signal_list_uat_t), DATAFILE_SPDU_SIGNALS, TRUE, - (void**)&spdu_signal_list, - &spdu_signal_list_num, - UAT_AFFECTS_DISSECTION|UAT_AFFECTS_FIELDS, - NULL, /* help */ - copy_spdu_signal_list_cb, - update_spdu_signal_list, - free_spdu_signal_list_cb, - post_update_spdu_signal_list_cb, - reset_spdu_signal_list, - spdu_signal_list_uat_fields + sizeof(spdu_signal_list_uat_t), /* record size */ + DATAFILE_SPDU_SIGNALS, /* filename */ + TRUE, /* from profile */ + (void **)&spdu_signal_list, /* data_ptr */ + &spdu_signal_list_num, /* numitems_ptr */ + UAT_AFFECTS_DISSECTION | UAT_AFFECTS_FIELDS, + NULL, /* help */ + copy_spdu_signal_list_cb, /* copy callback */ + update_spdu_signal_list, /* update callback */ + free_spdu_signal_list_cb, /* free callback */ + post_update_spdu_signal_list_cb, /* post update callback */ + reset_spdu_signal_list, /* reset callback */ + spdu_signal_list_uat_fields /* UAT field definitions */ ); + static const char *spdu_signal_list_uat_defaults_[] = { + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + "FALSE", "FALSE", "FALSE" }; + uat_set_default_values(spdu_signal_list_uat, spdu_signal_list_uat_defaults_); prefs_register_uat_preference(spdu_module, "_spdu_signal_list", "Signal List", "A table to define names of signals", spdu_signal_list_uat); + prefs_register_static_text_preference(spdu_module, "empty2", "", NULL); prefs_register_static_text_preference(spdu_module, "map", "Protocol Mappings:", NULL); spdu_someip_mapping_uat = uat_new("SOME/IP", - sizeof(spdu_someip_mapping_uat_t), DATAFILE_SPDU_SOMEIP_MAPPING, TRUE, - (void**)&spdu_someip_mapping, - &spdu_someip_mapping_num, - UAT_AFFECTS_DISSECTION, - NULL, /* help */ - copy_spdu_someip_mapping_cb, - update_spdu_someip_mapping, - NULL, - post_update_spdu_someip_mapping_cb, - NULL, /* reset */ - spdu_someip_mapping_uat_fields + sizeof(spdu_someip_mapping_uat_t), /* record size */ + DATAFILE_SPDU_SOMEIP_MAPPING, /* filename */ + TRUE, /* from profile */ + (void **)&spdu_someip_mapping, /* data_ptr */ + &spdu_someip_mapping_num, /* numitems_ptr */ + UAT_AFFECTS_DISSECTION, /* but not fields */ + NULL, /* help */ + copy_spdu_someip_mapping_cb, /* copy callback */ + update_spdu_someip_mapping, /* update callback */ + NULL, /* free callback */ + post_update_spdu_someip_mapping_cb, /* post update callback */ + NULL, /* reset callback */ + spdu_someip_mapping_uat_fields /* UAT field definitions */ ); prefs_register_uat_preference(spdu_module, "_spdu_someip_mapping", "SOME/IP Mappings", @@ -1903,17 +2935,19 @@ proto_register_signal_pdu(void) { spdu_can_mapping_uat = uat_new("CAN", - sizeof(spdu_can_mapping_uat_t), DATAFILE_SPDU_CAN_MAPPING, TRUE, - (void**)&spdu_can_mapping, - &spdu_can_mapping_num, - UAT_AFFECTS_DISSECTION, - NULL, /* help */ - copy_spdu_can_mapping_cb, - NULL, - NULL, - post_update_spdu_can_mapping_cb, - NULL, /* reset */ - spdu_can_mapping_uat_fields + sizeof(spdu_can_mapping_uat_t), /* record size */ + DATAFILE_SPDU_CAN_MAPPING, /* filename */ + TRUE, /* from profile */ + (void **)&spdu_can_mapping, /* data_ptr */ + &spdu_can_mapping_num, /* numitems_ptr */ + UAT_AFFECTS_DISSECTION, /* but not fields */ + NULL, /* help */ + copy_spdu_can_mapping_cb, /* copy callback */ + update_spdu_can_mapping, /* update callback */ + NULL, /* free callback */ + post_update_spdu_can_mapping_cb, /* post update callback */ + NULL, /* reset callback */ + spdu_can_mapping_uat_fields /* UAT field definitions */ ); prefs_register_uat_preference(spdu_module, "_spdu_can_mapping", "CAN Mappings", @@ -1921,17 +2955,19 @@ proto_register_signal_pdu(void) { spdu_flexray_mapping_uat = uat_new("FlexRay", - sizeof(spdu_flexray_mapping_uat_t), DATAFILE_SPDU_FLEXRAY_MAPPING, TRUE, - (void**)&spdu_flexray_mapping, - &spdu_flexray_mapping_num, - UAT_AFFECTS_DISSECTION, - NULL, /* help */ - copy_spdu_flexray_mapping_cb, - update_spdu_flexray_mapping, - NULL, - post_update_spdu_flexray_mapping_cb, - NULL, /* reset */ - spdu_flexray_mapping_uat_fields + sizeof(spdu_flexray_mapping_uat_t), /* record size */ + DATAFILE_SPDU_FLEXRAY_MAPPING, /* filename */ + TRUE, /* from profile */ + (void **)&spdu_flexray_mapping, /* data_ptr */ + &spdu_flexray_mapping_num, /* numitems_ptr */ + UAT_AFFECTS_DISSECTION, /* but not fields */ + NULL, /* help */ + copy_spdu_flexray_mapping_cb, /* copy callback */ + update_spdu_flexray_mapping, /* update callback */ + NULL, /* free callback */ + post_update_spdu_flexray_mapping_cb, /* post update callback */ + NULL, /* reset callback */ + spdu_flexray_mapping_uat_fields /* UAT field definitions */ ); prefs_register_uat_preference(spdu_module, "_spdu_flexray_mapping", "FlexRay Mappings", @@ -1939,17 +2975,19 @@ proto_register_signal_pdu(void) { spdu_lin_mapping_uat = uat_new("LIN", - sizeof(spdu_lin_mapping_uat_t), DATAFILE_SPDU_LIN_MAPPING, TRUE, - (void**)&spdu_lin_mapping, - &spdu_lin_mapping_num, - UAT_AFFECTS_DISSECTION, - NULL, /* help */ - copy_spdu_lin_mapping_cb, - update_spdu_lin_mapping, - NULL, - post_update_spdu_lin_mapping_cb, - NULL, /* reset */ - spdu_lin_mapping_uat_fields + sizeof(spdu_lin_mapping_uat_t), /* record size */ + DATAFILE_SPDU_LIN_MAPPING, /* filename */ + TRUE, /* from profile */ + (void **)&spdu_lin_mapping, /* data_ptr */ + &spdu_lin_mapping_num, /* numitems_ptr */ + UAT_AFFECTS_DISSECTION, /* but not fields */ + NULL, /* help */ + copy_spdu_lin_mapping_cb, /* copy callback */ + update_spdu_lin_mapping, /* update callback */ + NULL, /* free callback */ + post_update_spdu_lin_mapping_cb, /* post update callback */ + NULL, /* reset callback */ + spdu_lin_mapping_uat_fields /* UAT field definitions */ ); prefs_register_uat_preference(spdu_module, "_spdu_lin_mapping", "LIN Mappings", @@ -1957,21 +2995,107 @@ proto_register_signal_pdu(void) { spdu_pdu_transport_mapping_uat = uat_new("PDU Transport", - sizeof(spdu_pdu_transport_mapping_uat_t), DATAFILE_SPDU_PDU_TRANSPORT_MAPPING, TRUE, - (void**)&spdu_pdu_transport_mapping, - &spdu_pdu_transport_mapping_num, - UAT_AFFECTS_DISSECTION, - NULL, /* help */ - copy_spdu_pdu_transport_mapping_cb, - update_spdu_pdu_transport_mapping, - NULL, - post_update_spdu_pdu_transport_mapping_cb, - NULL, /* reset */ - spdu_pdu_transport_mapping_uat_fields + sizeof(spdu_pdu_transport_mapping_uat_t), /* record size */ + DATAFILE_SPDU_PDU_TRANSPORT_MAPPING, /* filename */ + TRUE, /* from profile */ + (void **)&spdu_pdu_transport_mapping, /* data_ptr */ + &spdu_pdu_transport_mapping_num, /* numitems_ptr */ + UAT_AFFECTS_DISSECTION, /* but not fields */ + NULL, /* help */ + copy_spdu_pdu_transport_mapping_cb, /* copy callback */ + update_spdu_pdu_transport_mapping, /* update callback */ + NULL, /* free callback */ + post_update_spdu_pdu_transport_mapping_cb, /* post update callback */ + NULL, /* reset callback */ + spdu_pdu_transport_mapping_uat_fields /* UAT field definitions */ ); prefs_register_uat_preference(spdu_module, "_spdu_pdu_transport_mapping", "PDU Transport Mappings", "A table to map PDU Transport payloads to Signal PDUs", spdu_pdu_transport_mapping_uat); + + + spdu_ipdum_mapping_uat = uat_new("AUTOSAR I-PduM", + sizeof(spdu_ipdum_mapping_uat_t), /* record size */ + DATAFILE_SPDU_IPDUM_MAPPING, /* filename */ + TRUE, /* from profile */ + (void **)&spdu_ipdum_mapping, /* data_ptr */ + &spdu_ipdum_mapping_num, /* numitems_ptr */ + UAT_AFFECTS_DISSECTION, /* but not fields */ + NULL, /* help */ + copy_spdu_ipdum_mapping_cb, /* copy callback */ + update_spdu_ipdum_mapping, /* update callback */ + NULL, /* free callback */ + post_update_spdu_ipdum_mapping_cb, /* post update callback */ + NULL, /* reset callback */ + spdu_ipdum_mapping_uat_fields /* UAT field definitions */ + ); + + prefs_register_uat_preference(spdu_module, "_spdu_ipdum_mapping", "IPduM Mappings", + "A table to map AUTOSAR I-PduM PDUs to Signal PDUs", spdu_ipdum_mapping_uat); + + + spdu_dlt_mapping_uat = uat_new("DLT", + sizeof(spdu_dlt_mapping_uat_t), /* record size */ + DATAFILE_SPDU_DLT_MAPPING, /* filename */ + TRUE, /* from profile */ + (void **)&spdu_dlt_mapping, /* data_ptr */ + &spdu_dlt_mapping_num, /* numitems_ptr */ + UAT_AFFECTS_DISSECTION, /* but not fields */ + NULL, /* help */ + copy_spdu_dlt_mapping_cb, /* copy callback */ + update_spdu_dlt_mapping, /* update callback */ + NULL, /* free callback */ + post_update_spdu_dlt_mapping_cb, /* post update callback */ + NULL, /* reset callback */ + spdu_dlt_mapping_uat_fields /* UAT field definitions */ + ); + + prefs_register_uat_preference(spdu_module, "_spdu_dlt_mapping", "DLT Mappings", + "A table to map DLT non-verbose Payloads to Signal PDUs", spdu_dlt_mapping_uat); + + + spdu_uds_mapping_uat = uat_new("UDS", + sizeof(spdu_uds_mapping_uat_t), /* record size */ + DATAFILE_SPDU_UDS_MAPPING, /* filename */ + TRUE, /* from profile */ + (void **)&spdu_uds_mapping, /* data_ptr */ + &spdu_uds_mapping_num, /* numitems_ptr */ + UAT_AFFECTS_DISSECTION, /* but not fields */ + NULL, /* help */ + copy_spdu_uds_mapping_cb, /* copy callback */ + update_spdu_uds_mapping, /* update callback */ + NULL, /* free callback */ + post_update_spdu_uds_mapping_cb, /* post update callback */ + NULL, /* reset callback */ + spdu_uds_mapping_uat_fields /* UAT field definitions */ + ); + + prefs_register_uat_preference(spdu_module, "_spdu_uds_mapping", "UDS Mappings", + "A table to map UDS payloads to Signal PDUs", spdu_uds_mapping_uat); + + + spdu_isobus_mapping_uat = uat_new("ISOBUS", + sizeof(spdu_isobus_mapping_uat_t), /* record size */ + DATAFILE_SPDU_ISOBUS_MAPPING, /* filename */ + TRUE, /* from profile */ + (void **)&spdu_isobus_mapping, /* data_ptr */ + &spdu_isobus_mapping_num, /* numitems_ptr */ + UAT_AFFECTS_DISSECTION, /* but not fields */ + NULL, /* help */ + copy_spdu_isobus_mapping_cb, /* copy callback */ + update_spdu_isobus_mapping, /* update callback */ + NULL, /* free callback */ + post_update_spdu_isobus_mapping_cb, /* post update callback */ + NULL, /* reset callback */ + spdu_isobus_mapping_uat_fields /* UAT field definitions */ + ); + + prefs_register_uat_preference(spdu_module, "_spdu_isobus_mapping", "ISOBUS Mappings", + "A table to map ISOBUS payloads to Signal PDUs", spdu_isobus_mapping_uat); + + + /* Aggregation Feature */ + spdu_aggregation_data = wmem_map_new_autoreset(wmem_epan_scope(), wmem_file_scope(), g_direct_hash, g_direct_equal); } void @@ -1983,16 +3107,24 @@ proto_reg_handoff_signal_pdu(void) { signal_pdu_handle_can = register_dissector("signal_pdu_over_can", dissect_spdu_message_can, proto_signal_pdu); dissector_add_for_decode_as("can.subdissector", signal_pdu_handle_can); - heur_dissector_add("can", dissect_spdu_message_can_heur, "Signal-PDU-Heuristic", "signal_pdu_can_heur", proto_signal_pdu, HEURISTIC_ENABLE); + heur_dissector_add("can", dissect_spdu_message_can_heur, "Signal PDU over CAN", "signal_pdu_can_heur", proto_signal_pdu, HEURISTIC_ENABLE); signal_pdu_handle_flexray = register_dissector("signal_pdu_over_flexray", dissect_spdu_message_flexray, proto_signal_pdu); dissector_add_for_decode_as("flexray.subdissector", signal_pdu_handle_flexray); - heur_dissector_add("flexray", dissect_spdu_message_flexray_heur, "Signal-PDU-Heuristic", "signal_pdu_flexray_heur", proto_signal_pdu, HEURISTIC_ENABLE); + heur_dissector_add("flexray", dissect_spdu_message_flexray_heur, "Signal PDU over FlexRay", "signal_pdu_flexray_heur", proto_signal_pdu, HEURISTIC_ENABLE); signal_pdu_handle_lin = register_dissector("signal_pdu_over_lin", dissect_spdu_message_lin, proto_signal_pdu); signal_pdu_handle_pdu_transport = register_dissector("signal_pdu_over_pdu_transport", dissect_spdu_message_pdu_transport, proto_signal_pdu); + signal_pdu_handle_ipdum = register_dissector("signal_pdu_over_IPduM", dissect_spdu_message_ipdum, proto_signal_pdu); + + heur_dissector_add("dlt", dissect_spdu_message_dlt_heur, "Signal PDU over DLT", "signal_pdu_dlt_heur", proto_signal_pdu, HEURISTIC_ENABLE); + + heur_dissector_add("uds", dissect_spdu_message_uds_heur, "Signal PDU over UDS", "signal_pdu_uds_heur", proto_signal_pdu, HEURISTIC_ENABLE); + + signal_pdu_handle_isobus = register_dissector("signal_pdu_over_ISOBUS", dissect_spdu_message_isobus, proto_signal_pdu); + initialized = TRUE; } } |