Index: uspace/app/usbinfo/dump.c
===================================================================
--- uspace/app/usbinfo/dump.c	(revision c9d5577cfba2ae0264c71b27709c24b1f5f95541)
+++ uspace/app/usbinfo/dump.c	(revision 466b1205996a4e747a6b1efb924156172bc3d3d6)
@@ -43,4 +43,5 @@
 #include <usb/usb.h>
 #include <usb/descriptor.h>
+#include <usb/debug.h>
 #include <usb/classes/classes.h>
 
@@ -49,40 +50,6 @@
 
 #define INDENT "  "
-#define PRINTLINE(indent, fmt, ...) printf("%s - " fmt, get_indent(indent), __VA_ARGS__)
 #define BYTES_PER_LINE 12
 
-#define BCD_INT(a) (((unsigned int)(a)) / 256)
-#define BCD_FRAC(a) (((unsigned int)(a)) % 256)
-
-#define BCD_FMT "%x.%x"
-#define BCD_ARGS(a) BCD_INT((a)), BCD_FRAC((a))
-
-static void dump_descriptor_by_type(size_t, uint8_t *, size_t);
-
-typedef struct {
-	int descriptor;
-	void (*dump)(size_t indent, uint8_t *descriptor, size_t length);
-} descriptor_dump_t;
-
-static void dump_descriptor_device(size_t, uint8_t *, size_t);
-static void dump_descriptor_configuration(size_t, uint8_t *, size_t);
-static void dump_descriptor_interface(size_t, uint8_t *, size_t);
-static void dump_descriptor_string(size_t, uint8_t *, size_t);
-static void dump_descriptor_endpoint(size_t, uint8_t *, size_t);
-static void dump_descriptor_hid(size_t, uint8_t *, size_t);
-static void dump_descriptor_hub(size_t, uint8_t *, size_t);
-static void dump_descriptor_generic(size_t, uint8_t *, size_t);
-
-static descriptor_dump_t descriptor_dumpers[] = {
-	{ USB_DESCTYPE_DEVICE, dump_descriptor_device },
-	{ USB_DESCTYPE_CONFIGURATION, dump_descriptor_configuration },
-	{ USB_DESCTYPE_STRING, dump_descriptor_string },
-	{ USB_DESCTYPE_INTERFACE, dump_descriptor_interface },
-	{ USB_DESCTYPE_ENDPOINT, dump_descriptor_endpoint },
-	{ USB_DESCTYPE_HID, dump_descriptor_hid },
-	{ USB_DESCTYPE_HUB, dump_descriptor_hub },
-	{ -1, dump_descriptor_generic },
-	{ -1, NULL }
-};
 
 static const char *get_indent(size_t level)
@@ -127,138 +94,9 @@
 }
 
-void dump_descriptor_by_type(size_t indent, uint8_t *d, size_t length)
-{
-	if (length < 2) {
-		return;
-	}
-	int type = d[1];
-	
-	descriptor_dump_t *dumper = descriptor_dumpers;
-	while (dumper->dump != NULL) {
-		if ((dumper->descriptor == type) || (dumper->descriptor < 0)) {
-			dumper->dump(indent, d, length);
-			return;
-		}
-		dumper++;
-	}			
-}
-
 void dump_usb_descriptor(uint8_t *descriptor, size_t size)
 {
-	dump_descriptor_by_type(0, descriptor, size);
+	usb_dump_standard_descriptor(stdout, get_indent(0), "\n",
+	    descriptor, size);
 }
-
-void dump_descriptor_device(size_t indent, uint8_t *descr, size_t size)
-{
-	usb_standard_device_descriptor_t *d
-	    = (usb_standard_device_descriptor_t *) descr;
-	if (size != sizeof(*d)) {
-		return;
-	}
-	
-	PRINTLINE(indent, "bLength = %d\n", d->length);
-	PRINTLINE(indent, "bDescriptorType = 0x%02x\n", d->descriptor_type);
-	PRINTLINE(indent, "bcdUSB = %d (" BCD_FMT ")\n", d->usb_spec_version,
-	    BCD_ARGS(d->usb_spec_version));
-	PRINTLINE(indent, "bDeviceClass = 0x%02x\n", d->device_class);
-	PRINTLINE(indent, "bDeviceSubClass = 0x%02x\n", d->device_subclass);
-	PRINTLINE(indent, "bDeviceProtocol = 0x%02x\n", d->device_protocol);
-	PRINTLINE(indent, "bMaxPacketSize0 = %d\n", d->max_packet_size);
-	PRINTLINE(indent, "idVendor = %d\n", d->vendor_id);
-	PRINTLINE(indent, "idProduct = %d\n", d->product_id);
-	PRINTLINE(indent, "bcdDevice = %d\n", d->device_version);
-	PRINTLINE(indent, "iManufacturer = %d\n", d->str_manufacturer);
-	PRINTLINE(indent, "iProduct = %d\n", d->str_product);
-	PRINTLINE(indent, "iSerialNumber = %d\n", d->str_serial_number);
-	PRINTLINE(indent, "bNumConfigurations = %d\n", d->configuration_count);
-}
-
-void dump_descriptor_configuration(size_t indent, uint8_t *descr, size_t size)
-{
-	usb_standard_configuration_descriptor_t *d
-	    = (usb_standard_configuration_descriptor_t *) descr;
-	if (size != sizeof(*d)) {
-		return;
-	}
-	
-	bool self_powered = d->attributes & 64;
-	bool remote_wakeup = d->attributes & 32;
-	
-	PRINTLINE(indent, "bLength = %d\n", d->length);
-	PRINTLINE(indent, "bDescriptorType = 0x%02x\n", d->descriptor_type);
-	PRINTLINE(indent, "wTotalLength = %d\n", d->total_length);
-	PRINTLINE(indent, "bNumInterfaces = %d\n", d->interface_count);
-	PRINTLINE(indent, "bConfigurationValue = %d\n", d->configuration_number);
-	PRINTLINE(indent, "iConfiguration = %d\n", d->str_configuration);
-	PRINTLINE(indent, "bmAttributes = %d [%s%s%s]\n", d->attributes,
-	    self_powered ? "self-powered" : "",
-	    (self_powered & remote_wakeup) ? ", " : "",
-	    remote_wakeup ? "remote-wakeup" : "");
-	PRINTLINE(indent, "MaxPower = %d (%dmA)\n", d->max_power,
-	    2 * d->max_power);
-}
-
-void dump_descriptor_interface(size_t indent, uint8_t *descr, size_t size)
-{
-	usb_standard_interface_descriptor_t *d
-	    = (usb_standard_interface_descriptor_t *) descr;
-	if (size != sizeof(*d)) {
-		return;
-	}
-	
-	PRINTLINE(indent, "bLength = %d\n", d->length);
-	PRINTLINE(indent, "bDescriptorType = 0x%02x\n", d->descriptor_type);
-	PRINTLINE(indent, "bInterfaceNumber = %d\n", d->interface_number);
-	PRINTLINE(indent, "bAlternateSetting = %d\n", d->alternate_setting);
-	PRINTLINE(indent, "bNumEndpoints = %d\n", d->endpoint_count);
-	PRINTLINE(indent, "bInterfaceClass = %s\n", d->interface_class == 0
-	    ? "reserved (0)" : usb_str_class(d->interface_class));
-	PRINTLINE(indent, "bInterfaceSubClass = %d\n", d->interface_subclass);
-	PRINTLINE(indent, "bInterfaceProtocol = %d\n", d->interface_protocol);
-	PRINTLINE(indent, "iInterface = %d\n", d->str_interface);
-}
-
-void dump_descriptor_string(size_t indent, uint8_t *descr, size_t size)
-{
-	dump_descriptor_generic(indent, descr, size);
-}
-
-void dump_descriptor_endpoint(size_t indent, uint8_t *descr, size_t size)
-{
-	usb_standard_endpoint_descriptor_t *d
-	   = (usb_standard_endpoint_descriptor_t *) descr;
-	if (size != sizeof(*d)) {
-		return;
-	}
-	
-	int endpoint = d->endpoint_address & 15;
-	usb_direction_t direction = d->endpoint_address & 128
-	    ? USB_DIRECTION_IN : USB_DIRECTION_OUT;
-	
-	PRINTLINE(indent, "bLength = %d\n", d->length);
-	PRINTLINE(indent, "bDescriptorType = 0x%02X\n", d->descriptor_type);
-	PRINTLINE(indent, "bEndpointAddress = 0x%02X [%d, %s]\n",
-	    d->endpoint_address, endpoint,
-	    direction == USB_DIRECTION_IN ? "in" : "out");
-	PRINTLINE(indent, "bmAttributes = %d\n", d->attributes);
-	PRINTLINE(indent, "wMaxPacketSize = %d\n", d->max_packet_size);
-	PRINTLINE(indent, "bInterval = %dms\n", d->poll_interval);
-}
-
-void dump_descriptor_hid(size_t indent, uint8_t *descr, size_t size)
-{
-	dump_descriptor_generic(indent, descr, size);
-}
-
-void dump_descriptor_hub(size_t indent, uint8_t *descr, size_t size)
-{
-	dump_descriptor_generic(indent, descr, size);
-}
-
-void dump_descriptor_generic(size_t indent, uint8_t *descr, size_t size)
-{
-	dump_buffer(NULL, indent, descr, size);
-}
-
 
 void dump_match_ids(match_id_list_t *matches)
@@ -297,6 +135,6 @@
 	}
 	printf("%s%s (0x%02X):\n", get_indent(depth), name, type);
-	dump_descriptor_by_type(depth, descriptor, descriptor[0]);
-	
+	usb_dump_standard_descriptor(stdout, get_indent(depth), "\n",
+	    descriptor, descriptor[0]);
 }
 
