1.1 --- a/test.c Mon Mar 04 19:27:25 2013 +0000
1.2 +++ b/test.c Mon Mar 04 22:26:19 2013 +0000
1.3 @@ -599,6 +599,10 @@
1.4 }
1.5 }
1.6
1.7 +/**
1.8 + * Get a descriptor from the device having the given type, value and index.
1.9 + * The descriptor buffer is static and must be copied if it is to be preserved.
1.10 + */
1.11 uint8_t *max_get_descriptor(max_device *device, uint8_t type, uint8_t value, uint8_t index)
1.12 {
1.13 static uint8_t data[64];
1.14 @@ -620,7 +624,10 @@
1.15 if (len >= usb_descriptor_size(type))
1.16 return data;
1.17 else
1.18 + {
1.19 + printf("Expected %d but received %d.\n", usb_descriptor_size(type), len);
1.20 return NULL;
1.21 + }
1.22 }
1.23
1.24 /**
1.25 @@ -707,6 +714,70 @@
1.26 }
1.27 }
1.28
1.29 +void usb_show_configuration(uint8_t *data)
1.30 +{
1.31 + struct usb_config_descriptor *conf = (struct usb_config_descriptor *) data;
1.32 + uint8_t *current, *last, total = le16toh(conf->wTotalLength);
1.33 + struct usb_descriptor_header *desc;
1.34 + struct usb_interface_descriptor *intf;
1.35 + struct usb_endpoint_descriptor *endp;
1.36 +
1.37 + if (data == NULL)
1.38 + return;
1.39 +
1.40 + printf("bLength: %d\n", conf->bLength);
1.41 + printf("bDescriptorType: %d\n", conf->bDescriptorType);
1.42 + printf("wTotalLength: %d\n", total);
1.43 + printf("bNumInterfaces: %d\n", conf->bNumInterfaces);
1.44 + printf("bConfigurationValue: %d\n", conf->bConfigurationValue);
1.45 + printf("iConfiguration: %d\n", conf->iConfiguration);
1.46 + printf("bmAttributes: %x\n", conf->bmAttributes);
1.47 + printf("MaxPower: %d\n", conf->MaxPower);
1.48 +
1.49 + current = ((uint8_t *) conf) + conf->bLength;
1.50 + last = ((uint8_t *) conf) + total;
1.51 +
1.52 + while (current < last)
1.53 + {
1.54 + desc = (struct usb_descriptor_header *) current;
1.55 + printf("bLength: %d\n", desc->bLength);
1.56 + printf("bDescriptorType: %d\n", desc->bDescriptorType);
1.57 +
1.58 + switch (desc->bDescriptorType)
1.59 + {
1.60 + case USB_DT_INTERFACE:
1.61 + intf = (struct usb_interface_descriptor *) current;
1.62 + printf("bInterfaceNumber: %d\n", intf->bInterfaceNumber);
1.63 + printf("bAlternateSetting: %d\n", intf->bAlternateSetting);
1.64 + printf("bNumEndpoints: %d\n", intf->bNumEndpoints);
1.65 + printf("bInterfaceClass: %x\n", intf->bInterfaceClass);
1.66 + printf("bInterfaceSubClass: %x\n", intf->bInterfaceSubClass);
1.67 + printf("bInterfaceProtocol: %x\n", intf->bInterfaceProtocol);
1.68 + printf("iInterface: %d\n", intf->iInterface);
1.69 + break;
1.70 +
1.71 + case USB_DT_ENDPOINT:
1.72 + endp = (struct usb_endpoint_descriptor *) current;
1.73 + printf("bEndpointAddress: %d\n", endp->bEndpointAddress);
1.74 + printf("bmAttributes: %x\n", endp->bmAttributes);
1.75 + printf("wMaxPacketSize: %d\n", le16toh(endp->wMaxPacketSize));
1.76 + printf("bInterval: %d\n", endp->bInterval);
1.77 + break;
1.78 +
1.79 + default:
1.80 + break;
1.81 + }
1.82 +
1.83 + if (desc->bLength)
1.84 + current += desc->bLength;
1.85 + else
1.86 + {
1.87 + printf("END (zero length record)\n");
1.88 + break;
1.89 + }
1.90 + }
1.91 +}
1.92 +
1.93 /**
1.94 * Handle termination of the process.
1.95 */
1.96 @@ -883,6 +954,7 @@
1.97 max_set_address(&device);
1.98 devstate = MAX_DEVSTATE_READY;
1.99 usb_show_languages(max_get_descriptor(&device, USB_DT_STRING, 0, 0));
1.100 + usb_show_configuration(max_get_descriptor(&device, USB_DT_CONFIG, 0, 0));
1.101 printf("READY\n");
1.102 }
1.103