Index: qemu-0.13.0/usb-linux.c
===================================================================
--- qemu-0.13.0.orig/usb-linux.c	2011-03-26 20:51:22.174555938 +0100
+++ qemu-0.13.0/usb-linux.c	2011-03-26 20:51:31.139503443 +0100
@@ -38,6 +38,7 @@
 #include <dirent.h>
 #include <sys/ioctl.h>
 #include <signal.h>
+#include <sys/time.h>
 
 #include <linux/usbdevice_fs.h>
 #include <linux/version.h>
@@ -66,7 +67,7 @@ typedef int USBScanFunc(void *opaque, in
                         int vendor_id, int product_id,
                         const char *product_name, int speed);
 
-//#define DEBUG
+#define DEBUG
 
 #ifdef DEBUG
 #define DPRINTF printf
@@ -152,6 +153,69 @@ static int usb_host_close(USBHostDevice
 static int parse_filter(const char *spec, struct USBAutoFilter *f);
 static void usb_host_auto_check(void *unused);
 
+static unsigned int get_vendor_id(USBHostDevice *dev)
+{
+	return *((uint16_t *)&dev->descr[8]); /* is CPU-endian */
+}
+
+static unsigned int get_device_id(USBHostDevice *dev)
+{
+	return *((uint16_t *)&dev->descr[10]); /* is CPU-endian */
+}
+
+static unsigned int msec_timestamp(void)
+{
+	struct timeval tv;
+	unsigned long long msec;
+
+	gettimeofday(&tv, NULL);
+	msec = tv.tv_sec * 1000;
+	msec += tv.tv_usec / 1000;
+
+	return (unsigned int)msec;
+}
+
+static char toAscii(char c)
+{
+	if (c >= 32 && c <= 126)
+		return c;
+	return '.';
+}
+
+static void dump(USBHostDevice *dev, const char *prefix, unsigned int ep, char *buf, size_t size)
+{
+	size_t i;
+	char ascii[17] = { 0, };
+	char tmp[2] = { 0, };
+
+	printf("[%010d] %04X:%04X   EP%02X    %s    len=%u\n",
+		msec_timestamp(),
+		get_vendor_id(dev), get_device_id(dev),
+		ep, prefix, (unsigned int)size);
+
+	for (i = 0; i < size; i++) {
+		if (i % 16 == 0) {
+			if (i != 0) {
+				printf("  |%s|\n", ascii);
+				ascii[0] = '\0';
+			}
+			printf("[%04X]: ", (unsigned int)i);
+		}
+		if (i % 2 == 0)
+			printf(" %02X", buf[i] & 0xFF);
+		else
+			printf("%02X", buf[i] & 0xFF);
+		tmp[0] = toAscii(buf[i]);
+		strcat(ascii, tmp);
+	}
+	if (ascii[0] != '\0') {
+		for ( ; i % 16; i++)
+			printf((i % 2 == 0) ? "   " : "  ");
+		printf("  |%s|", ascii);
+	}
+	puts("\n");
+}
+
 static int is_isoc(USBHostDevice *s, int ep)
 {
     return s->endp_table[ep - 1].type == USBDEVFS_URB_TYPE_ISO;
@@ -251,7 +315,12 @@ static void async_complete(void *opaque)
             case 0:
                 p->len = aurb->urb.actual_length;
                 if (aurb->urb.type == USBDEVFS_URB_TYPE_CONTROL) {
+                    if (((char *)aurb->urb.buffer)[0] & 0x80)
+                        dump(s, "Control IN", 0, aurb->urb.buffer, aurb->urb.buffer_length);
                     async_complete_ctrl(s, p);
+                } else {
+                    if (p->pid == USB_TOKEN_IN)
+                        dump(s, "Bulk IN", aurb->urb.endpoint, aurb->urb.buffer, aurb->urb.buffer_length);
                 }
                 break;
 
@@ -461,6 +530,8 @@ static int usb_host_handle_data(USBHostD
 
     urb->usercontext = s;
 
+    if (p->pid != USB_TOKEN_IN)
+        dump(s, "Bulk OUT", urb->endpoint, urb->buffer, urb->buffer_length);
     ret = ioctl(s->fd, USBDEVFS_SUBMITURB, urb);
 
     DPRINTF("husb: data submit. ep 0x%x len %u aurb %p\n",
@@ -554,15 +625,18 @@ static int usb_host_handle_control(USBHo
     if (s->ctrl.req.bRequestType == 0) {
         switch (s->ctrl.req.bRequest) {
         case USB_REQ_SET_ADDRESS:
+            printf("USB SET_ADDRESS %u\n", value);
             return usb_host_set_address(s, value);
 
         case USB_REQ_SET_CONFIGURATION:
+            printf("USB SET_CONFIGURATION %u\n", value & 0xFF);
             return usb_host_set_config(s, value & 0xff);
         }
     }
 
     if (s->ctrl.req.bRequestType == 1 &&
                   s->ctrl.req.bRequest == USB_REQ_SET_INTERFACE) {
+        printf("USB SET_INTERFACE %u %u\n", index, value);
         return usb_host_set_interface(s, index, value);
     }
 
@@ -595,6 +669,8 @@ static int usb_host_handle_control(USBHo
 
     urb->usercontext = s;
 
+    if (!(((char *)urb->buffer)[0] & 0x80))
+        dump(s, "Control OUT", 0, urb->buffer, urb->buffer_length);
     ret = ioctl(s->fd, USBDEVFS_SUBMITURB, urb);
 
     DPRINTF("husb: submit ctrl. len %u aurb %p\n", urb->buffer_length, aurb);
