Current-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: QUick question about USB interfaces
On Wed, Oct 31, 2012 at 12:47:18PM -0500, Dave Burgess wrote:
>
> Using ugen0.04 was my first thought, but that didn't help. I tried all
> of the ugen0.xx ports, just to see what would happen.
>
FWIW the below code will tell you what all the endpoints on a ugen
device are. Unfortunately this will only work if the device is grabbed
by ugen, if another driver gets the device you cannot query it. Though,
IMHO, we should be able to, it can be useful sometimes and would allow
us to implement something like the linux lsusb command. Apologies for
the lack of error checking and so forth, this was a quick hack I threw
together when poking at a USB device...
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <dev/usb/usb.h>
main(int argc, char **argv)
{
struct usb_config_desc desc;
int fd, i, j;
struct usb_interface_desc int_desc;
struct usb_endpoint_desc end_desc;
fd = open(argv[1], O_RDONLY, 0);
if (fd < 0) {
printf("open failed %d\n", errno);
exit(0);
}
desc.ucd_config_index = USB_CURRENT_CONFIG_INDEX;
if (ioctl(fd, USB_GET_CONFIG_DESC, &desc) < 0) {
printf("ioctl failed, %d\n", errno);
exit(0);
}
printf("length: %d\n", desc.ucd_desc.bLength);
printf("descriptor type: %d\n", desc.ucd_desc.bDescriptorType);
printf("total length: %d\n", desc.ucd_desc.wTotalLength);
printf("num interface: %d\n", desc.ucd_desc.bNumInterface);
printf("config value: %d\n", desc.ucd_desc.bConfigurationValue);
printf("configuration: %d\n", desc.ucd_desc.iConfiguration);
printf("Attributes: (0x%x) ", desc.ucd_desc.bmAttributes);
/* if ((desc.ucd_desc.bmAttributes & UC_BUS_POWERED) == UC_BUS_POWERED)
printf("Bus powered ");*/
if ((desc.ucd_desc.bmAttributes & UC_SELF_POWERED) == UC_SELF_POWERED)
printf("Self powered ");
if ((desc.ucd_desc.bmAttributes & UC_REMOTE_WAKEUP)
== UC_REMOTE_WAKEUP)
printf("Remote Wakeup ");
printf("\n");
printf("max power: %d mA\n",
desc.ucd_desc.bMaxPower * UC_POWER_FACTOR);
int_desc.uid_config_index = USB_CURRENT_CONFIG_INDEX;
int_desc.uid_alt_index = USB_CURRENT_ALT_INDEX;
end_desc.ued_config_index = USB_CURRENT_CONFIG_INDEX;
end_desc.ued_alt_index = USB_CURRENT_ALT_INDEX;
for (i = 0; i <= desc.ucd_desc.bNumInterface - 1; i++) {
printf("\nInterface %d:\n", i);
int_desc.uid_interface_index = i;
if (ioctl(fd, USB_GET_INTERFACE_DESC, &int_desc) < 0) {
printf("ioctl failed, %d\n", errno);
exit(0);
}
printf(" Length: %d\n", int_desc.uid_desc.bLength);
printf(" Descriptor Type: %d\n",
int_desc.uid_desc.bDescriptorType);
printf(" Interface No: %d\n",
int_desc.uid_desc.bInterfaceNumber);
printf(" Alt Setting: %d\n",
int_desc.uid_desc.bAlternateSetting);
printf(" Num Endpoints: %d\n",
int_desc.uid_desc.bNumEndpoints);
printf(" Interface Class: %d\n",
int_desc.uid_desc.bInterfaceClass);
printf(" Interface SubClass: %d\n",
int_desc.uid_desc.bInterfaceSubClass);
printf(" Interface Protocol: %d\n",
int_desc.uid_desc.bInterfaceProtocol);
printf(" Interface: %d\n", int_desc.uid_desc.iInterface);
end_desc.ued_interface_index = i;
for (j = 0; j < int_desc.uid_desc.bNumEndpoints; j++) {
printf(" Endpoint %d:\n", j);
end_desc.ued_endpoint_index = j;
if (ioctl(fd, USB_GET_ENDPOINT_DESC, &end_desc) < 0) {
printf("ioctl failed, %d\n", errno);
exit(0);
}
printf(" Length: %d\n", end_desc.ued_desc.bLength);
printf(" Length: %d\n",
end_desc.ued_desc.bDescriptorType);
printf(" Length: (0x%x) %d ",
end_desc.ued_desc.bEndpointAddress,
UE_GET_ADDR(end_desc.ued_desc.bEndpointAddress));
if (UE_GET_DIR(end_desc.ued_desc.bEndpointAddress)
== UE_DIR_OUT)
printf("(out)\n");
else
printf("(in)\n");
printf(" Attributes: (0x%x) ",
end_desc.ued_desc.bmAttributes);
switch
(UE_GET_XFERTYPE(end_desc.ued_desc.bmAttributes)) {
case UE_CONTROL:
printf("control ");
break;
case UE_ISOCHRONOUS:
printf("isochronous ");
break;
case UE_BULK:
printf("bulk ");
break;
case UE_INTERRUPT:
printf("interrupt ");
break;
}
switch
(UE_GET_ISO_TYPE(end_desc.ued_desc.bmAttributes)) {
case UE_ISO_ASYNC:
printf("async");
break;
case UE_ISO_ADAPT:
printf("adapt");
break;
case UE_ISO_SYNC:
printf("sync");
break;
}
printf("\n");
printf(" Max Packet Size: %d\n",
end_desc.ued_desc.wMaxPacketSize);
printf(" Interval: %d\n",
end_desc.ued_desc.bInterval);
}
}
}
--
Brett Lymn
"Warning:
The information contained in this email and any attached files is
confidential to BAE Systems Australia. If you are not the intended
recipient, any use, disclosure or copying of this email or any
attachments is expressly prohibited. If you have received this email
in error, please notify us immediately. VIRUS: Every care has been
taken to ensure this email and its attachments are virus free,
however, any loss or damage incurred in using this email is not the
sender's responsibility. It is your responsibility to ensure virus
checks are completed before installing any data sent in this email to
your computer."
Home |
Main Index |
Thread Index |
Old Index