usbmon: Report device address assigned to USB device
Subsystems (2)
PATCH 1/1 usbmon: Report device address assigned to USB device
Make USB device addresses match while sniffing USB communication with usbmon and hardware USB sniffer (OpenVizsla) at the same time. On xHCI root hubs the address is assigned by hardware and can be different than devnum.
--- Documentation/usb/usbmon.rst | 2 +- drivers/usb/mon/mon_bin.c | 6 +++--- drivers/usb/mon/mon_text.c | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-)
Documentation/usb/usbmon.rst +1 -1
@@ -220,7 +220,7 @@ the following structure (its name is made up, so that we can refer to it):: unsigned char type; /* 8: Same as text; extensible. */ unsigned char xfer_type; /* ISO (0), Intr, Control, Bulk (3) */ unsigned char epnum; /* Endpoint number and transfer direction */ - unsigned char devnum; /* Device address */ + unsigned char devaddr; /* Device address */ u16 busnum; /* 12: Bus number */ char flag_setup; /* 14: Same as text */ char flag_data; /* 15: Same as text; Binary zero is OK. */
drivers/usb/mon/mon_bin.c +3 -3
@@ -91,7 +91,7 @@ struct mon_bin_hdr {unsigned char type;/* Same as in text API; extensible. */ unsigned char xfer_type;/* ISO, Intr, Control, Bulk */ unsigned char epnum;/* Endpoint number and transfer direction */ -unsigned char devnum;/* Device address */ +unsigned char devaddr;/* Device address */ unsigned short busnum;/* Bus number */ char flag_setup;char flag_data;
@@ -567,7 +567,7 @@ static void mon_bin_event(struct mon_reader_bin *rp, struct urb *urb, ep->type = ev_type; ep->xfer_type = xfer_to_pipe[usb_endpoint_type (epd)]; ep->epnum = dir |usb_endpoint_num (epd); - ep->devnum = urb->dev->devnum; + ep->devaddr = urb->dev->devaddr; ep->busnum = urb->dev->bus->busnum; ep->id = (unsigned long ) urb; ep->ts_sec = ts.tv_sec;
@@ -655,7 +655,7 @@ static void mon_bin_error(void *data, struct urb *urb, int error) ep->xfer_type = xfer_to_pipe[usb_endpoint_type (&urb->ep->desc)]; ep->epnum =usb_urb_dir_in (urb) ?USB_DIR_IN :0 ; ep->epnum |=usb_endpoint_num (&urb->ep->desc); - ep->devnum = urb->dev->devnum; + ep->devaddr = urb->dev->devaddr; ep->busnum = urb->dev->bus->busnum; ep->id = (unsigned long ) urb; ep->ts_sec = ts.tv_sec;
drivers/usb/mon/mon_text.c +5 -5
@@ -59,7 +59,7 @@ struct mon_event_text {unsigned long id;/* From pointer, most of the time */ unsigned int tstamp;int busnum; -char devnum; +char devaddr;char epnum;char is_in;char xfertype;
@@ -210,7 +210,7 @@ static void mon_text_event(struct mon_reader_text *rp, struct urb *urb, ep->type = ev_type; ep->id = (unsigned long ) urb; ep->busnum = urb->dev->bus->busnum; - ep->devnum = urb->dev->devnum; + ep->devaddr = urb->dev->devaddr; ep->epnum =usb_endpoint_num (&urb->ep->desc); ep->xfertype =usb_endpoint_type (&urb->ep->desc); ep->is_in =usb_urb_dir_in (urb);
@@ -282,7 +282,7 @@ static void mon_text_error(void *data, struct urb *urb, int error) ep->type ='E' ; ep->id = (unsigned long ) urb; ep->busnum = urb->dev->bus->busnum; - ep->devnum = urb->dev->devnum; + ep->devaddr = urb->dev->devaddr; ep->epnum =usb_endpoint_num (&urb->ep->desc); ep->xfertype =usb_endpoint_type (&urb->ep->desc); ep->is_in =usb_urb_dir_in (urb);
@@ -523,7 +523,7 @@ static void mon_text_read_head_t(struct mon_reader_text *rp, p->cnt +=snprintf (p->pbuf + p->cnt, p->limit - p->cnt,"%lx %u %c %c%c:%03u:%02u" , ep->id, ep->tstamp, ep->type, - utype, udir, ep->devnum, ep->epnum); + utype, udir, ep->devaddr, ep->epnum); } static void mon_text_read_head_u(struct mon_reader_text *rp,
@@ -541,7 +541,7 @@ static void mon_text_read_head_u(struct mon_reader_text *rp, p->cnt +=snprintf (p->pbuf + p->cnt, p->limit - p->cnt,"%lx %u %c %c%c:%d:%03u:%u" , ep->id, ep->tstamp, ep->type, - utype, udir, ep->busnum, ep->devnum, ep->epnum); + utype, udir, ep->busnum, ep->devaddr, ep->epnum); } static void mon_text_read_statset(struct mon_reader_text *rp,
Signature · 1 line
2.24.1
Review
Quoted 7 lines · On Mon, 6 Jan 2020 10:37:17 +0100 Tomasz Moń <[email protected]> wrote:
Make USB device addresses match while sniffing USB communication with usbmon and hardware USB sniffer (OpenVizsla) at the same time. On xHCI root hubs the address is assigned by hardware and can be different than devnum.
(quoted diff) +1
-1- unsigned char devnum; /* Device address */ + unsigned char devaddr; /* Device address */
I think it's fine, the name of the field is not exported by a header anyway, so there's no impact.
-- Pete
Greg Kroah-Hartman
maintainerQuoted 4 lines · Tomasz Moń
Make USB device addresses match while sniffing USB communication with usbmon and hardware USB sniffer (OpenVizsla) at the same time. On xHCI root hubs the address is assigned by hardware and can be different than devnum.
This breaks the userspace abi for matching up the devnum with the number that is listed by the kernel to userspace, making it really hard to match things up for xhci devices now :(
I understand the need to look at this data, but you can't do it in a way that will change things like this.
thanks,
greg k-h
Quoted 6 lines · On Wed, 8 Jan 2020 16:55:13 +0100 Greg Kroah-Hartman…
Quoted 4 lines · Tomasz Moń
Make USB device addresses match while sniffing USB communication with usbmon and hardware USB sniffer (OpenVizsla) at the same time. On xHCI root hubs the address is assigned by hardware and can be different than devnum.
Quoted 6 lines
This breaks the userspace abi for matching up the devnum with the number that is listed by the kernel to userspace, making it really hard to match things up for xhci devices now :(
I understand the need to look at this data, but you can't do it in a way that will change things like this.
This sounds reasonable, although perhaps unfortunate. I acked Tomasz's patch because I thought that XHCI is new, and thus it's no big deal if its results are different.
Of course I rushed to examine the packet structure, but yes, there's no space in the header, not without some trickery. For example, the upper 8 bits of the ID are probably the same for all packets, so it may be stuffed in there. Or, it might be possible to create an extra header and attach it at the end of ISO descriptors.
Alan's suggestion of leaving the physical address in /sys appeals the most to me, honestly. One thing though, libpcap will need to rifle through /sys and then store that address, so its serialization has to be changed no matter what. Unfortunately, I'm wholly ignorant as to what syntax it uses and how extensible it is.
-- Pete
Quoted 26 lines · Pete Zaitcev
Quoted 6 lines · On Wed, 8 Jan 2020 16:55:13 +0100 Greg Kroah-Hartman…
Quoted 4 lines · Tomasz Moń
Make USB device addresses match while sniffing USB communication with usbmon and hardware USB sniffer (OpenVizsla) at the same time. On xHCI root hubs the address is assigned by hardware and can be different than devnum.
Quoted 6 lines
This breaks the userspace abi for matching up the devnum with the number that is listed by the kernel to userspace, making it really hard to match things up for xhci devices now :(
I understand the need to look at this data, but you can't do it in a way that will change things like this.
This sounds reasonable, although perhaps unfortunate. I acked Tomasz's patch because I thought that XHCI is new, and thus it's no big deal if its results are different.
Of course I rushed to examine the packet structure, but yes, there's no space in the header, not without some trickery. For example, the upper 8 bits of the ID are probably the same for all packets, so it may be stuffed in there. Or, it might be possible to create an extra header and attach it at the end of ISO descriptors.
Quoted 5 lines
Alan's suggestion of leaving the physical address in /sys appeals the most to me, honestly. One thing though, libpcap will need to rifle through /sys and then store that address, so its serialization has to be changed no matter what. Unfortunately, I'm wholly ignorant as to what syntax it uses and how extensible it is.
Alternatively, libpcap can ignore the issue and just display the device numbers, as it does now. A separate program or the user could convert the number to a physical address, if necessary, using the information in sysfs.
Alan Stern
Quoted 10 lines · On Mon, 13 Jan 2020 10:05:42 -0500 (EST) Alan Stern…
Quoted 5 lines
Alan's suggestion of leaving the physical address in /sys appeals the most to me, honestly. One thing though, libpcap will need to rifle through /sys and then store that address, so its serialization has to be changed no matter what. Unfortunately, I'm wholly ignorant as to what syntax it uses and how extensible it is.
Alternatively, libpcap can ignore the issue and just display the device numbers, as it does now. A separate program or the user could convert the number to a physical address, if necessary, using the information in sysfs.
I thoght that people sometimes saved the traces and replayed them on other machines, which obviously have their own /sys or even run Windows or iOS.
-- Pete