55 #include <linux/poll.h>
57 #include <linux/usbdevice_fs.h>
65 #define ALLOW_SERIAL_NUMBER
67 static const char format_topo[] =
69 "\nT: Bus=%2.2d Lev=%2.2d Prnt=%2.2d Port=%2.2d Cnt=%2.2d Dev#=%3d Spd=%-4s MxCh=%2d\n";
71 static const char format_string_manufacturer[] =
73 "S: Manufacturer=%.100s\n";
75 static const char format_string_product[] =
77 "S: Product=%.100s\n";
79 #ifdef ALLOW_SERIAL_NUMBER
80 static const char format_string_serialnumber[] =
82 "S: SerialNumber=%.100s\n";
85 static const char format_bandwidth[] =
87 "B: Alloc=%3d/%3d us (%2d%%), #Int=%3d, #Iso=%3d\n";
89 static const char format_device1[] =
91 "D: Ver=%2x.%02x Cls=%02x(%-5s) Sub=%02x Prot=%02x MxPS=%2d #Cfgs=%3d\n";
93 static const char format_device2[] =
95 "P: Vendor=%04x ProdID=%04x Rev=%2x.%02x\n";
97 static const char format_config[] =
99 "C:%c #Ifs=%2d Cfg#=%2d Atr=%02x MxPwr=%3dmA\n";
101 static const char format_iad[] =
103 "A: FirstIf#=%2d IfCount=%2d Cls=%02x(%-5s) Sub=%02x Prot=%02x\n";
105 static const char format_iface[] =
107 "I:%c If#=%2d Alt=%2d #EPs=%2d Cls=%02x(%-5s) Sub=%02x Prot=%02x Driver=%s\n";
109 static const char format_endpt[] =
111 "E: Ad=%02x(%c) Atr=%02x(%-4s) MxPS=%4d Ivl=%d%cs\n";
128 static struct device_connect_event {
141 static const struct class_info clas_info[] = {
171 static const char *class_decode(
const int class)
175 for (ix = 0; clas_info[ix].
class != -1; ix++)
176 if (clas_info[ix].
class ==
class)
181 static char *usb_dump_endpoint_descriptor(
int speed,
char *
start,
char *
end,
190 dir = usb_endpoint_dir_in(desc) ?
'I' :
'O';
193 switch (usb_endpoint_maxp(desc) & (0x03 << 11)) {
195 bandwidth = 2;
break;
197 bandwidth = 3;
break;
202 switch (usb_endpoint_type(desc)) {
243 (usb_endpoint_maxp(desc) & 0x07ff) *
249 static char *usb_dump_interface_descriptor(
char *start,
char *end,
250 const struct usb_interface_cache *intfc,
260 desc = &intfc->altsetting[setno].desc;
262 driver_name = (iface->dev.driver
263 ? iface->dev.driver->name
265 active = (desc == &iface->cur_altsetting->desc);
267 start +=
sprintf(start, format_iface,
280 static char *usb_dump_interface(
int speed,
char *start,
char *end,
281 const struct usb_interface_cache *intfc,
284 const struct usb_host_interface *desc = &intfc->altsetting[setno];
287 start = usb_dump_interface_descriptor(start, end, intfc, iface, setno);
288 for (i = 0; i < desc->desc.bNumEndpoints; i++) {
291 start = usb_dump_endpoint_descriptor(speed,
292 start, end, &desc->endpoint[i].desc);
297 static char *usb_dump_iad_descriptor(
char *start,
char *end,
302 start +=
sprintf(start, format_iad,
317 static char *usb_dump_config_descriptor(
char *start,
char *end,
323 start +=
sprintf(start, format_config,
333 static char *usb_dump_config(
int speed,
char *start,
char *end,
334 const struct usb_host_config *
config,
int active)
337 struct usb_interface_cache *intfc;
344 return start +
sprintf(start,
"(null Cfg. desc.)\n");
345 start = usb_dump_config_descriptor(start, end, &config->desc, active);
346 for (i = 0; i < USB_MAXIADS; i++) {
347 if (config->intf_assoc[i] ==
NULL)
349 start = usb_dump_iad_descriptor(start, end,
350 config->intf_assoc[i]);
352 for (i = 0; i < config->desc.bNumInterfaces; i++) {
353 intfc = config->intf_cache[
i];
354 interface = config->interface[i];
355 for (j = 0; j < intfc->num_altsetting; j++) {
358 start = usb_dump_interface(speed,
359 start, end, intfc, interface, j);
368 static char *usb_dump_device_descriptor(
char *start,
char *end,
376 start +=
sprintf(start, format_device1,
377 bcdUSB >> 8, bcdUSB & 0xff,
386 start +=
sprintf(start, format_device2,
389 bcdDevice >> 8, bcdDevice & 0xff);
396 static char *usb_dump_device_strings(
char *start,
char *end,
397 struct usb_device *
dev)
401 if (dev->manufacturer)
402 start +=
sprintf(start, format_string_manufacturer,
407 start +=
sprintf(start, format_string_product, dev->product);
410 #ifdef ALLOW_SERIAL_NUMBER
412 start +=
sprintf(start, format_string_serialnumber,
419 static char *usb_dump_desc(
char *start,
char *end,
struct usb_device *dev)
426 start = usb_dump_device_descriptor(start, end, &dev->descriptor);
431 start = usb_dump_device_strings(start, end, dev);
433 for (i = 0; i < dev->descriptor.bNumConfigurations; i++) {
436 start = usb_dump_config(dev->speed,
437 start, end, dev->config + i,
439 (dev->config + i) == dev->actconfig);
447 static char *usb_dump_hub_descriptor(
char *start,
char *end,
451 unsigned char *
ptr = (
unsigned char *)desc;
455 start +=
sprintf(start,
"Interface:");
456 while (leng && start <= end) {
457 start +=
sprintf(start,
" %02x", *ptr);
464 static char *usb_dump_string(
char *start,
char *end,
465 const struct usb_device *dev,
char *
id,
int index)
469 start +=
sprintf(start,
"Interface:");
470 if (index <= dev->maxstring && dev->stringindex &&
471 dev->stringindex[index])
472 start +=
sprintf(start,
"%s: %.100s ",
id,
473 dev->stringindex[index]);
490 struct usb_device *usbdev,
struct usb_bus *
bus,
495 int parent_devnum = 0;
496 char *pages_start, *data_end, *speed;
499 struct usb_device *childdev =
NULL;
505 if (level > MAX_TOPO_LEVEL)
513 if (usbdev->parent && usbdev->parent->devnum != -1)
514 parent_devnum = usbdev->parent->devnum;
519 switch (usbdev->speed) {
521 speed =
"1.5";
break;
527 speed =
"480";
break;
529 speed =
"5000";
break;
533 data_end = pages_start +
sprintf(pages_start, format_topo,
534 bus->busnum, level, parent_devnum,
535 index, count, usbdev->devnum,
536 speed, usbdev->maxchild);
552 max = FRAME_TIME_MAX_USECS_ALLOC;
558 data_end +=
sprintf(data_end, format_bandwidth,
559 bus->bandwidth_allocated, max,
560 (100 * bus->bandwidth_allocated + max / 2)
562 bus->bandwidth_int_reqs,
563 bus->bandwidth_isoc_reqs);
566 data_end = usb_dump_desc(data_end, pages_start + (2 *
PAGE_SIZE) - 256,
569 if (data_end > (pages_start + (2 *
PAGE_SIZE) - 256))
570 data_end +=
sprintf(data_end,
"(truncated)\n");
572 length = data_end - pages_start;
574 if (length > *skip_bytes) {
575 length -= *skip_bytes;
576 if (length > *nbytes)
578 if (
copy_to_user(*buffer, pages_start + *skip_bytes, length)) {
593 usb_hub_for_each_child(usbdev, chix, childdev) {
595 usb_lock_device(childdev);
596 ret = usb_device_dump(buffer, nbytes, skip_bytes,
597 file_offset, childdev, bus,
598 level + 1, chix - 1, ++cnt);
599 usb_unlock_device(childdev);
601 return total_written;
602 total_written +=
ret;
605 return total_written;
609 size_t nbytes, loff_t *ppos)
613 loff_t skip_bytes = *ppos;
626 if (!bus_to_hcd(bus)->rh_registered)
628 usb_lock_device(bus->root_hub);
629 ret = usb_device_dump(&buf, &nbytes, &skip_bytes, ppos,
630 bus->root_hub, bus, 0, 0, 0);
631 usb_unlock_device(bus->root_hub);
636 total_written +=
ret;
639 return total_written;
643 static unsigned int usb_device_poll(
struct file *file,
646 unsigned int event_count;
648 poll_wait(file, &device_event.wait, wait);
659 static loff_t usb_device_lseek(
struct file *file, loff_t
offset,
int orig)
663 mutex_lock(&file->f_dentry->d_inode->i_mutex);
684 .llseek = usb_device_lseek,
685 .read = usb_device_read,
686 .poll = usb_device_poll,