aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Moń <desowin@gmail.com>2019-07-21 12:49:07 +0200
committerAnders Broman <a.broman58@gmail.com>2019-08-04 05:33:39 +0000
commit4c9a01213373a29873fe327553bf282e167cf5d3 (patch)
tree7da0305997c45258f7d6d3c2ed243a78d82b1708
parenta4c95bcddf8474d36950f1d1b26e64b431bec5c3 (diff)
USBLL: Minimal destination address handling
Currently only following packets have the address fields populated: * SETUP * OUT * IN * PING * SPLIT Although only some packets have the fields populated, this already makes trace analysis significantly easier. Ping-Bug: 15908 Change-Id: I5a5c0e210cb1ceb8e8a747349c4da33ac84ec4c9 Reviewed-on: https://code.wireshark.org/review/34039 Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r--epan/dissectors/packet-usb.c2
-rw-r--r--epan/dissectors/packet-usb.h4
-rw-r--r--epan/dissectors/packet-usbll.c30
3 files changed, 34 insertions, 2 deletions
diff --git a/epan/dissectors/packet-usb.c b/epan/dissectors/packet-usb.c
index 38a4256470..fe2551b899 100644
--- a/epan/dissectors/packet-usb.c
+++ b/epan/dissectors/packet-usb.c
@@ -4077,7 +4077,7 @@ dissect_darwin_buffer_packet_header(tvbuff_t *tvb, packet_info *pinfo, proto_tre
}
/* Set the usb_address_t fields based on the direction of the urb */
-static void
+void
usb_set_addr(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, guint16 bus_id, guint16 device_address,
int endpoint, gboolean req)
{
diff --git a/epan/dissectors/packet-usb.h b/epan/dissectors/packet-usb.h
index a652c4adb9..79ef0ab16e 100644
--- a/epan/dissectors/packet-usb.h
+++ b/epan/dissectors/packet-usb.h
@@ -275,6 +275,10 @@ dissect_usb_unknown_descriptor(packet_info *pinfo _U_, proto_tree *parent_tree,
int
dissect_urb_transfer_flags(tvbuff_t *tvb, int offset, proto_tree* tree, int hf, int endian);
+void
+usb_set_addr(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, guint16 bus_id, guint16 device_address,
+ int endpoint, gboolean req);
+
struct mausb_header;
void
diff --git a/epan/dissectors/packet-usbll.c b/epan/dissectors/packet-usbll.c
index 8ff29d8ff7..b05f97547e 100644
--- a/epan/dissectors/packet-usbll.c
+++ b/epan/dissectors/packet-usbll.c
@@ -18,6 +18,7 @@
#include <epan/expert.h>
#include <epan/crc16-tvb.h>
#include <wsutil/crc5.h>
+#include "packet-usb.h"
static int proto_usbll = -1;
@@ -126,6 +127,13 @@ static const value_string usb_endpoint_type_vals[] = {
{0, NULL}
};
+#define TOKEN_BITS_GET_ADDRESS(bits) (bits & 0x007F)
+#define TOKEN_BITS_GET_ENDPOINT(bits) ((bits & 0x0780) >> 7)
+
+#define SPLIT_BITS_GET_HUB_ADDRESS(bits) (bits & 0x007F)
+#define SPLIT_BITS_GET_ENDPOINT_TYPE(bits) ((bits & 0x060000) >> 17)
+#define SPLIT_BIT_START_COMPLETE 0x0080
+
static int
dissect_usbll_packet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* data _U_)
{
@@ -134,6 +142,13 @@ dissect_usbll_packet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree,
gint offset = 0;
guint32 pid;
const gchar *str;
+ /* USB address has bus id as when capturing at URB level there are usually multiple root hubs
+ * to select from. Until someone has specific need to connect multiple hardware sniffers at
+ * the same time and analyze that in Wireshark, this code simply sets the bus id to 0.
+ */
+ const guint16 bus_id = 0;
+ guint16 device_address;
+ int endpoint;
tree = proto_tree_add_subtree(parent_tree, tvb, offset, -1, ett_usbll, &item, "USB Packet");
@@ -167,6 +182,10 @@ dissect_usbll_packet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree,
};
address_bits = tvb_get_letohs(tvb, offset);
+ device_address = TOKEN_BITS_GET_ADDRESS(address_bits);
+ endpoint = TOKEN_BITS_GET_ENDPOINT(address_bits);
+ usb_set_addr(tree, tvb, pinfo, bus_id, device_address, endpoint, TRUE);
+
proto_tree_add_bitmask_list_value(tree, tvb, offset, 2, address_fields, address_bits);
proto_tree_add_checksum(tree, tvb, offset,
hf_usbll_crc5, hf_usbll_crc5_status, &ei_wrong_crc5, pinfo,
@@ -202,6 +221,8 @@ dissect_usbll_packet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree,
case USB_PID_TOKEN_SOF:
{
guint32 frame;
+
+ /* TODO: How to mark that it is sent by host to all devices on the bus? */
proto_tree_add_item_ret_uint(tree, hf_usbll_sof_framenum, tvb, offset, 2, ENC_LITTLE_ENDIAN, &frame);
proto_tree_add_checksum(tree, tvb, offset,
hf_usbll_crc5, hf_usbll_crc5_status, &ei_wrong_crc5, pinfo,
@@ -232,7 +253,14 @@ dissect_usbll_packet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree,
NULL
};
- if (((tmp & 0x060000) >> 17) == USB_EP_TYPE_ISOCHRONOUS)
+ device_address = SPLIT_BITS_GET_HUB_ADDRESS(tmp);
+ /* There is no endpoint information in the packet, show it as endpoint 0 */
+ endpoint = 0;
+ usb_set_addr(tree, tvb, pinfo, bus_id, device_address, endpoint, TRUE);
+
+ col_append_str(pinfo->cinfo, COL_INFO, (tmp & SPLIT_BIT_START_COMPLETE) ? " Complete" : " Start");
+
+ if (SPLIT_BITS_GET_ENDPOINT_TYPE(tmp) == USB_EP_TYPE_ISOCHRONOUS)
{
proto_tree_add_bitmask_list(tree, tvb, offset, 3, split_iso_fields, ENC_LITTLE_ENDIAN);
}