From a86c5f7cae7ec9a3398300555a0b644689d946a1 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 19 Sep 2024 06:14:53 +0200 Subject: Merging upstream version 4.4.0. Signed-off-by: Daniel Baumann --- epan/dissectors/packet-adb.c | 246 ++++++++++++++++++++++--------------------- 1 file changed, 124 insertions(+), 122 deletions(-) (limited to 'epan/dissectors/packet-adb.c') diff --git a/epan/dissectors/packet-adb.c b/epan/dissectors/packet-adb.c index 0808990f..b939c5f6 100644 --- a/epan/dissectors/packet-adb.c +++ b/epan/dissectors/packet-adb.c @@ -15,86 +15,88 @@ #include #include #include +#include + #include #include "packet-adb_service.h" #include "packet-usb.h" -static int proto_adb = -1; -static int hf_command = -1; -static int hf_argument_0 = -1; -static int hf_argument_1 = -1; -static int hf_data_length = -1; -static int hf_data_crc32 = -1; -static int hf_magic = -1; -static int hf_local_id = -1; -static int hf_remote_id = -1; -static int hf_version = -1; -static int hf_max_data = -1; -static int hf_zero = -1; -static int hf_sequence = -1; -static int hf_online = -1; -static int hf_auth_type = -1; -static int hf_data = -1; -static int hf_service = -1; -static int hf_data_fragment = -1; -static int hf_command_in_frame = -1; -static int hf_completed_in_frame = -1; -static int hf_service_start_in_frame = -1; -static int hf_close_local_in_frame = -1; -static int hf_close_remote_in_frame = -1; -static int hf_connection_info = -1; - -static gint ett_adb = -1; -static gint ett_adb_arg0 = -1; -static gint ett_adb_arg1 = -1; -static gint ett_adb_crc = -1; -static gint ett_adb_magic = -1; - -static expert_field ei_invalid_magic = EI_INIT; -static expert_field ei_invalid_crc = EI_INIT; -static expert_field ei_invalid_data = EI_INIT; +static int proto_adb; +static int hf_command; +static int hf_argument_0; +static int hf_argument_1; +static int hf_data_length; +static int hf_data_crc32; +static int hf_magic; +static int hf_local_id; +static int hf_remote_id; +static int hf_version; +static int hf_max_data; +static int hf_zero; +static int hf_sequence; +static int hf_online; +static int hf_auth_type; +static int hf_data; +static int hf_service; +static int hf_data_fragment; +static int hf_command_in_frame; +static int hf_completed_in_frame; +static int hf_service_start_in_frame; +static int hf_close_local_in_frame; +static int hf_close_remote_in_frame; +static int hf_connection_info; + +static int ett_adb; +static int ett_adb_arg0; +static int ett_adb_arg1; +static int ett_adb_crc; +static int ett_adb_magic; + +static expert_field ei_invalid_magic; +static expert_field ei_invalid_crc; +static expert_field ei_invalid_data; static dissector_handle_t adb_handle; static dissector_handle_t adb_service_handle; -static gint proto_tcp = -1; -static gint proto_usb = -1; +static int proto_tcp; +static int proto_usb; -static wmem_tree_t *command_info = NULL; -static wmem_tree_t *service_info = NULL; +static wmem_tree_t *command_info; +static wmem_tree_t *service_info; typedef struct service_data_t { - guint32 start_in_frame; + uint32_t start_in_frame; - guint32 close_local_in_frame; - guint32 close_remote_in_frame; + uint32_t close_local_in_frame; + uint32_t close_remote_in_frame; - guint32 local_id; - guint32 remote_id; + uint32_t local_id; + uint32_t remote_id; - const gchar *service; + const char *service; } service_data_t; typedef struct command_data_t { - guint32 command; + uint32_t command; - guint32 command_in_frame; - guint32 response_in_frame; + uint32_t command_in_frame; + uint32_t response_in_frame; - guint32 arg0; - guint32 arg1; + uint32_t arg0; + uint32_t arg1; - guint32 data_length; - guint32 crc32; + uint32_t data_length; + uint32_t crc32; - guint32 completed_in_frame; - guint32 reassemble_data_length; - guint8 *reassemble_data; - guint32 reassemble_error_in_frame; + uint32_t completed_in_frame; + uint32_t reassemble_data_length; + uint8_t *reassemble_data; + uint32_t reassemble_error_in_frame; } command_data_t; -static guint32 max_in_frame = G_MAXUINT32; +static uint32_t max_in_frame = UINT32_MAX; static const value_string command_vals[] = { { 0x434e5953, "Synchronize" }, @@ -139,21 +141,21 @@ void proto_register_adb(void); void proto_reg_handoff_adb(void); static void -save_command(guint32 cmd, guint32 arg0, guint32 arg1, guint32 data_length, - guint32 crc32, service_data_t *service_data, gint proto, void *data, +save_command(uint32_t cmd, uint32_t arg0, uint32_t arg1, uint32_t data_length, + uint32_t crc32, service_data_t *service_data, int proto, void *data, packet_info *pinfo, service_data_t **returned_service_data, command_data_t **returned_command_data) { wmem_tree_key_t key[6]; - guint32 interface_id; - guint32 bus_id; - guint32 device_address; - guint32 side_id; - guint32 frame_number; + uint32_t interface_id; + uint32_t bus_id; + uint32_t device_address; + uint32_t side_id; + uint32_t frame_number; command_data_t *command_data; wmem_tree_t *wmem_tree; - gint direction = P2P_DIR_UNKNOWN; - usb_conv_info_t *usb_conv_info = (usb_conv_info_t *) data; + int direction = P2P_DIR_UNKNOWN; + urb_info_t *urb = (urb_info_t *) data; frame_number = pinfo->num; @@ -163,13 +165,13 @@ save_command(guint32 cmd, guint32 arg0, guint32 arg1, guint32 data_length, interface_id = 0; if (proto == proto_usb) { - usb_conv_info = (usb_conv_info_t *) data; - DISSECTOR_ASSERT(usb_conv_info); + urb = (urb_info_t *) data; + DISSECTOR_ASSERT(urb); - direction = usb_conv_info->direction; + direction = urb->direction; - bus_id = usb_conv_info->bus_id; - device_address = usb_conv_info->device_address; + bus_id = urb->bus_id; + device_address = urb->device_address; key[0].length = 1; key[0].key = &interface_id; @@ -247,7 +249,7 @@ save_command(guint32 cmd, guint32 arg0, guint32 arg1, guint32 data_length, else command_data->completed_in_frame = max_in_frame; command_data->reassemble_data_length = 0; - command_data->reassemble_data = (guint8 *) wmem_alloc(wmem_file_scope(), command_data->data_length); + command_data->reassemble_data = (uint8_t *) wmem_alloc(wmem_file_scope(), command_data->data_length); command_data->reassemble_error_in_frame = 0; key[3].length = 1; @@ -317,7 +319,7 @@ save_command(guint32 cmd, guint32 arg0, guint32 arg1, guint32 data_length, *returned_command_data = command_data; } -static gint +static int dissect_adb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) { proto_item *main_item; @@ -330,24 +332,24 @@ dissect_adb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) proto_item *crc_item; proto_tree *crc_tree = NULL; proto_item *sub_item; - gint offset = 0; - guint32 command; - guint32 arg0; - guint32 arg1; - guint32 data_length = 0; - guint32 crc32 = 0; - usb_conv_info_t *usb_conv_info = NULL; + int offset = 0; + uint32_t command; + uint32_t arg0; + uint32_t arg1; + uint32_t data_length = 0; + uint32_t crc32 = 0; + urb_info_t *urb = NULL; wmem_tree_key_t key[5]; - guint32 interface_id; - guint32 bus_id; - guint32 device_address; - guint32 side_id; - guint32 frame_number; - gboolean is_command = TRUE; - gboolean is_next_fragment = FALSE; - gboolean is_service = FALSE; - gint proto; - gint direction = P2P_DIR_UNKNOWN; + uint32_t interface_id; + uint32_t bus_id; + uint32_t device_address; + uint32_t side_id; + uint32_t frame_number; + bool is_command = true; + bool is_next_fragment = false; + bool is_service = false; + int proto; + int direction = P2P_DIR_UNKNOWN; wmem_tree_t *wmem_tree; command_data_t *command_data = NULL; service_data_t *service_data = NULL; @@ -363,16 +365,16 @@ dissect_adb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) /* XXX: Why? If interface is USB only first try is correct * (and seems strange...), in other cases standard check for * previous protocol is correct */ - proto = (gint) GPOINTER_TO_INT(wmem_list_frame_data(/*wmem_list_frame_prev*/(wmem_list_tail(pinfo->layers)))); + proto = (int) GPOINTER_TO_INT(wmem_list_frame_data(/*wmem_list_frame_prev*/(wmem_list_tail(pinfo->layers)))); if (proto != proto_usb) { - proto = (gint) GPOINTER_TO_INT(wmem_list_frame_data(wmem_list_frame_prev(wmem_list_tail(pinfo->layers)))); + proto = (int) GPOINTER_TO_INT(wmem_list_frame_data(wmem_list_frame_prev(wmem_list_tail(pinfo->layers)))); } if (proto == proto_usb) { - usb_conv_info = (usb_conv_info_t *) data; - DISSECTOR_ASSERT(usb_conv_info); + urb = (urb_info_t *) data; + DISSECTOR_ASSERT(urb); - direction = usb_conv_info->direction; + direction = urb->direction; } else if (proto == proto_tcp) { if (pinfo->destport == ADB_TCP_PORT) direction = P2P_DIR_SENT; @@ -388,8 +390,8 @@ dissect_adb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) interface_id = 0; if (proto == proto_usb) { - bus_id = usb_conv_info->bus_id; - device_address = usb_conv_info->device_address; + bus_id = urb->bus_id; + device_address = urb->device_address; key[0].length = 1; key[0].key = &interface_id; @@ -422,8 +424,8 @@ dissect_adb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) command_data->command_in_frame <= frame_number) { if (command_data->command_in_frame != frame_number) { - is_command = FALSE; - is_next_fragment = TRUE; + is_command = false; + is_next_fragment = true; } data_length = command_data->data_length; @@ -447,7 +449,7 @@ dissect_adb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) if (wmem_tree) { service_data = (service_data_t *) wmem_tree_lookup32_le(wmem_tree, frame_number); if (service_data && command_data->command == A_OPEN) { - is_service = TRUE; + is_service = true; } } } @@ -456,21 +458,21 @@ dissect_adb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) /* Simple heuristics to check if packet is command or data */ if ((command_data && command_data->completed_in_frame <= frame_number) || !command_data) { if (tvb_reported_length(tvb) < 24) { - is_command = FALSE; + is_command = false; } else if (tvb_reported_length(tvb) >= 24) { command = tvb_get_letohl(tvb, offset); if (command != A_SYNC && command != A_CLSE && command != A_WRTE && command != A_AUTH && command != A_CNXN && command != A_OPEN && command != A_OKAY) - is_command = FALSE; + is_command = false; else if (command != (0xFFFFFFFF ^ tvb_get_letohl(tvb, offset + 20))) - is_command = FALSE; + is_command = false; if (is_command) { data_length = tvb_get_letohl(tvb, offset + 12); crc32 = tvb_get_letohl(tvb, offset + 16); } - if (command == A_OPEN) is_service = TRUE; + if (command == A_OPEN) is_service = true; } } @@ -516,7 +518,7 @@ dissect_adb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) proto_tree_add_item(arg0_tree, hf_version, tvb, offset - 8, 4, ENC_LITTLE_ENDIAN); proto_tree_add_item(arg1_tree, hf_max_data, tvb, offset - 4, 4, ENC_LITTLE_ENDIAN); - col_append_fstr(pinfo->cinfo, COL_INFO, "(version=%u.%u.%u, max_data=%u)", tvb_get_guint8(tvb, offset - 5), tvb_get_guint8(tvb, offset - 6), tvb_get_letohs(tvb, offset - 7), tvb_get_letohl(tvb, offset - 4)); + col_append_fstr(pinfo->cinfo, COL_INFO, "(version=%u.%u.%u, max_data=%u)", tvb_get_uint8(tvb, offset - 5), tvb_get_uint8(tvb, offset - 6), tvb_get_letohs(tvb, offset - 7), tvb_get_letohl(tvb, offset - 4)); break; case A_AUTH: proto_tree_add_item(arg0_tree, hf_auth_type, tvb, offset - 8, 4, ENC_LITTLE_ENDIAN); @@ -577,8 +579,8 @@ dissect_adb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) if (!pinfo->fd->visited && command_data) { if (command_data->command_in_frame != frame_number) { - is_command = FALSE; - is_next_fragment = TRUE; + is_command = false; + is_next_fragment = true; } data_length = command_data->data_length; @@ -614,13 +616,13 @@ dissect_adb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) if (tvb_captured_length_remaining(tvb, offset) > 0 && (!is_command || data_length > 0)) { - guint32 crc = 0; - guint32 i_offset; + uint32_t crc = 0; + uint32_t i_offset; /* First pass: store message payload (usually a single packet, but * potentially multiple fragments). */ if (!pinfo->fd->visited && command_data && command_data->reassemble_data_length < command_data->data_length) { - guint chunklen = tvb_captured_length_remaining(tvb, offset); + unsigned chunklen = tvb_captured_length_remaining(tvb, offset); if (chunklen > command_data->data_length - command_data->reassemble_data_length) { chunklen = command_data->data_length - command_data->reassemble_data_length; /* This should never happen, but when it does, then either we @@ -641,7 +643,7 @@ dissect_adb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) proto_tree_add_expert(main_tree, pinfo, &ei_invalid_data, tvb, offset, -1); } - if ((!pinfo->fd->visited && command_data && command_data->reassemble_data_length < command_data->data_length) || data_length > (guint32) tvb_captured_length_remaining(tvb, offset)) { /* need reassemble */ + if ((!pinfo->fd->visited && command_data && command_data->reassemble_data_length < command_data->data_length) || data_length > (uint32_t) tvb_captured_length_remaining(tvb, offset)) { /* need reassemble */ proto_tree_add_item(main_tree, hf_data_fragment, tvb, offset, -1, ENC_NA); col_append_str(pinfo->cinfo, COL_INFO, "Data Fragment"); offset = tvb_captured_length(tvb); @@ -657,12 +659,12 @@ dissect_adb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) adb_service_data.direction = direction; adb_service_data.session_key_length = 3; - adb_service_data.session_key = (guint32 *) wmem_alloc(pinfo->pool, adb_service_data.session_key_length * sizeof(guint32)); + adb_service_data.session_key = (uint32_t *) wmem_alloc(pinfo->pool, adb_service_data.session_key_length * sizeof(uint32_t)); adb_service_data.session_key[0] = interface_id; if (proto == proto_usb) { - adb_service_data.session_key[1] = usb_conv_info->bus_id; - adb_service_data.session_key[2] = usb_conv_info->device_address; + adb_service_data.session_key[1] = urb->bus_id; + adb_service_data.session_key[2] = urb->device_address; } else { /* tcp */ if (direction == P2P_DIR_SENT) { adb_service_data.session_key[1] = pinfo->srcport; @@ -677,7 +679,7 @@ dissect_adb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) } } else { /* full message */ for (i_offset = 0; i_offset < data_length; ++i_offset) - crc += tvb_get_guint8(tvb, offset + i_offset); + crc += tvb_get_uint8(tvb, offset + i_offset); if (crc32 > 0 && crc32 != crc) proto_tree_add_expert(crc_tree, pinfo, &ei_invalid_crc, tvb, offset, -1); @@ -685,12 +687,12 @@ dissect_adb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) if (is_service) { proto_tree_add_item(main_tree, hf_service, tvb, offset, -1, ENC_ASCII | ENC_NA); if (!pinfo->fd->visited && service_data) { - service_data->service = (gchar *) tvb_get_stringz_enc(wmem_file_scope(), tvb, offset, NULL, ENC_ASCII); + service_data->service = (char *) tvb_get_stringz_enc(wmem_file_scope(), tvb, offset, NULL, ENC_ASCII); } col_append_fstr(pinfo->cinfo, COL_INFO, "Service: %s", tvb_get_stringz_enc(pinfo->pool, tvb, offset, NULL, ENC_ASCII)); offset = tvb_captured_length(tvb); } else if (command_data && command_data->command == A_CNXN) { - const guint8 *info; + const uint8_t *info; /* * Format: "::". @@ -714,12 +716,12 @@ dissect_adb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) adb_service_data.direction = direction; adb_service_data.session_key_length = 3; - adb_service_data.session_key = (guint32 *) wmem_alloc(pinfo->pool, adb_service_data.session_key_length * sizeof(guint32)); + adb_service_data.session_key = (uint32_t *) wmem_alloc(pinfo->pool, adb_service_data.session_key_length * sizeof(uint32_t)); adb_service_data.session_key[0] = interface_id; if (proto == proto_usb) { - adb_service_data.session_key[1] = usb_conv_info->bus_id; - adb_service_data.session_key[2] = usb_conv_info->device_address; + adb_service_data.session_key[1] = urb->bus_id; + adb_service_data.session_key[2] = urb->device_address; } else { /* tcp */ if (direction == P2P_DIR_SENT) { adb_service_data.session_key[1] = pinfo->srcport; @@ -735,7 +737,7 @@ dissect_adb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) } else { proto_item *data_item; - gchar *data_str; + char *data_str; data_item = proto_tree_add_item(main_tree, hf_data, tvb, offset, data_length, ENC_NA); data_str = tvb_format_text(pinfo->pool, tvb, offset, data_length); @@ -805,7 +807,7 @@ proto_register_adb(void) }, { &hf_online, { "Online", "adb.online", - FT_BOOLEAN, 32, TFS(&tfs_no_yes), 0x00, + FT_BOOLEAN, BASE_NONE, TFS(&tfs_no_yes), 0x00, NULL, HFILL } }, { &hf_sequence, @@ -875,7 +877,7 @@ proto_register_adb(void) } }; - static gint *ett[] = { + static int *ett[] = { &ett_adb, &ett_adb_arg0, &ett_adb_arg1, -- cgit v1.2.3