# HG changeset patch # User Paul Boddie # Date 1362435979 0 # Node ID 5580bf1e6c9e2e832fcdfdeff0b24711eff8c86e # Parent a11494bd42ccad4c669f237a80c86a9f8113f91d Added configuration listing support. diff -r a11494bd42cc -r 5580bf1e6c9e test.c --- a/test.c Mon Mar 04 19:27:25 2013 +0000 +++ b/test.c Mon Mar 04 22:26:19 2013 +0000 @@ -599,6 +599,10 @@ } } +/** + * Get a descriptor from the device having the given type, value and index. + * The descriptor buffer is static and must be copied if it is to be preserved. + */ uint8_t *max_get_descriptor(max_device *device, uint8_t type, uint8_t value, uint8_t index) { static uint8_t data[64]; @@ -620,7 +624,10 @@ if (len >= usb_descriptor_size(type)) return data; else + { + printf("Expected %d but received %d.\n", usb_descriptor_size(type), len); return NULL; + } } /** @@ -707,6 +714,70 @@ } } +void usb_show_configuration(uint8_t *data) +{ + struct usb_config_descriptor *conf = (struct usb_config_descriptor *) data; + uint8_t *current, *last, total = le16toh(conf->wTotalLength); + struct usb_descriptor_header *desc; + struct usb_interface_descriptor *intf; + struct usb_endpoint_descriptor *endp; + + if (data == NULL) + return; + + printf("bLength: %d\n", conf->bLength); + printf("bDescriptorType: %d\n", conf->bDescriptorType); + printf("wTotalLength: %d\n", total); + printf("bNumInterfaces: %d\n", conf->bNumInterfaces); + printf("bConfigurationValue: %d\n", conf->bConfigurationValue); + printf("iConfiguration: %d\n", conf->iConfiguration); + printf("bmAttributes: %x\n", conf->bmAttributes); + printf("MaxPower: %d\n", conf->MaxPower); + + current = ((uint8_t *) conf) + conf->bLength; + last = ((uint8_t *) conf) + total; + + while (current < last) + { + desc = (struct usb_descriptor_header *) current; + printf("bLength: %d\n", desc->bLength); + printf("bDescriptorType: %d\n", desc->bDescriptorType); + + switch (desc->bDescriptorType) + { + case USB_DT_INTERFACE: + intf = (struct usb_interface_descriptor *) current; + printf("bInterfaceNumber: %d\n", intf->bInterfaceNumber); + printf("bAlternateSetting: %d\n", intf->bAlternateSetting); + printf("bNumEndpoints: %d\n", intf->bNumEndpoints); + printf("bInterfaceClass: %x\n", intf->bInterfaceClass); + printf("bInterfaceSubClass: %x\n", intf->bInterfaceSubClass); + printf("bInterfaceProtocol: %x\n", intf->bInterfaceProtocol); + printf("iInterface: %d\n", intf->iInterface); + break; + + case USB_DT_ENDPOINT: + endp = (struct usb_endpoint_descriptor *) current; + printf("bEndpointAddress: %d\n", endp->bEndpointAddress); + printf("bmAttributes: %x\n", endp->bmAttributes); + printf("wMaxPacketSize: %d\n", le16toh(endp->wMaxPacketSize)); + printf("bInterval: %d\n", endp->bInterval); + break; + + default: + break; + } + + if (desc->bLength) + current += desc->bLength; + else + { + printf("END (zero length record)\n"); + break; + } + } +} + /** * Handle termination of the process. */ @@ -883,6 +954,7 @@ max_set_address(&device); devstate = MAX_DEVSTATE_READY; usb_show_languages(max_get_descriptor(&device, USB_DT_STRING, 0, 0)); + usb_show_configuration(max_get_descriptor(&device, USB_DT_CONFIG, 0, 0)); printf("READY\n"); }