+static int ints_enabled = 0;
+static pthread_mutex_t int_wait = PTHREAD_MUTEX_INITIALIZER;
+
+#define NO_WINDRVR 1
+
+#ifdef DEBUG
+#define DPRINTF(format, args...) fprintf(stderr, format, ##args)
+void hexdump(unsigned char *buf, int len) {
+ int i;
+
+ for(i=0; i<len; i++) {
+ fprintf(stderr,"%02x ", buf[i]);
+ if ((i % 16) == 15)
+ fprintf(stderr,"\n");
+ }
+ fprintf(stderr,"\n");
+}
+#else
+#define DPRINTF(format, args...)
+#endif
+
+int usb_deviceinfo(unsigned char *buf) {
+ int i,j,k,l;
+ int len = 0;
+ WDU_CONFIGURATION **pConfigs, **pActiveConfig;
+ WDU_INTERFACE **pActiveInterface;
+
+ if (buf) {
+ struct usb_device_info *udi = (struct usb_device_info*)(buf+len);
+
+ udi->Descriptor.bLength = sizeof(WDU_DEVICE_DESCRIPTOR);
+ udi->Descriptor.bDescriptorType = usbdevice->descriptor.bDescriptorType;
+ udi->Descriptor.bcdUSB = usbdevice->descriptor.bcdUSB;
+ udi->Descriptor.bDeviceClass = usbdevice->descriptor.bDeviceClass;
+ udi->Descriptor.bDeviceSubClass = usbdevice->descriptor.bDeviceSubClass;
+ udi->Descriptor.bDeviceProtocol = usbdevice->descriptor.bDeviceProtocol;
+ udi->Descriptor.bMaxPacketSize0 = usbdevice->descriptor.bMaxPacketSize0;
+ udi->Descriptor.idVendor = usbdevice->descriptor.idVendor;
+ udi->Descriptor.idProduct = usbdevice->descriptor.idProduct;
+ udi->Descriptor.bcdDevice = usbdevice->descriptor.bcdDevice;
+ udi->Descriptor.iManufacturer = usbdevice->descriptor.iManufacturer;
+ udi->Descriptor.iProduct = usbdevice->descriptor.iProduct;
+ udi->Descriptor.iSerialNumber = usbdevice->descriptor.iSerialNumber;
+ udi->Descriptor.bNumConfigurations = usbdevice->descriptor.bNumConfigurations;
+
+ /* TODO: Fix Pipe0! */
+ udi->Pipe0.dwNumber = 0x00;
+ udi->Pipe0.dwMaximumPacketSize = usbdevice->descriptor.bMaxPacketSize0;
+ udi->Pipe0.type = 0;
+ udi->Pipe0.direction = WDU_DIR_IN_OUT;
+ udi->Pipe0.dwInterval = 0;
+
+ pConfigs = &(udi->pConfigs);
+ pActiveConfig = &(udi->pActiveConfig);
+ pActiveInterface = &(udi->pActiveInterface[0]);
+ }
+
+ len = sizeof(struct usb_device_info);
+
+ for (i=0; i<usbdevice->descriptor.bNumConfigurations; i++)
+ {
+ struct usb_config_descriptor *conf_desc = &usbdevice->config[i];
+ WDU_INTERFACE **pInterfaces;
+ WDU_ALTERNATE_SETTING **pAlternateSettings[conf_desc->bNumInterfaces];
+ WDU_ALTERNATE_SETTING **pActiveAltSetting[conf_desc->bNumInterfaces];
+
+ if (buf) {
+ WDU_CONFIGURATION *cfg = (WDU_CONFIGURATION*)(buf+len);
+
+ *pConfigs = cfg;
+ *pActiveConfig = cfg;
+
+ cfg->Descriptor.bLength = conf_desc->bLength;
+ cfg->Descriptor.bDescriptorType = conf_desc->bDescriptorType;
+ cfg->Descriptor.wTotalLength = conf_desc->wTotalLength;
+ cfg->Descriptor.bNumInterfaces = conf_desc->bNumInterfaces;
+ cfg->Descriptor.bConfigurationValue = conf_desc->bConfigurationValue;
+ cfg->Descriptor.iConfiguration = conf_desc->iConfiguration;
+ cfg->Descriptor.bmAttributes = conf_desc->bmAttributes;
+ cfg->Descriptor.MaxPower = conf_desc->MaxPower;
+
+ cfg->dwNumInterfaces = conf_desc->bNumInterfaces;
+
+ pInterfaces = &(cfg->pInterfaces);
+ }
+ len += sizeof(WDU_CONFIGURATION);
+
+ if (buf) {
+ *pInterfaces = (WDU_INTERFACE*)(buf+len);
+ for (j=0; j<conf_desc->bNumInterfaces; j++) {
+ WDU_INTERFACE *iface = (WDU_INTERFACE*)(buf+len);
+
+ pActiveInterface[j] = iface;
+
+ pAlternateSettings[j] = &(iface->pAlternateSettings);
+ iface->dwNumAltSettings = usbdevice->config[i].interface[j].num_altsetting;
+ pActiveAltSetting[j] = &(iface->pActiveAltSetting);
+
+ len += sizeof(WDU_INTERFACE);
+ }
+ } else {
+ len += sizeof(WDU_INTERFACE) * conf_desc->bNumInterfaces;
+ }
+
+ for (j=0; j<conf_desc->bNumInterfaces; j++)
+ {
+ struct usb_interface *interface = &usbdevice->config[i].interface[j];
+
+ if (buf) {
+ *pAlternateSettings[j] = (WDU_ALTERNATE_SETTING*)(buf+len);
+ /* FIXME: */
+ *pActiveAltSetting[j] = (WDU_ALTERNATE_SETTING*)(buf+len);
+ }
+
+ for(k=0; k<interface->num_altsetting; k++)
+ {
+ unsigned char bNumEndpoints = interface->altsetting[k].bNumEndpoints;
+ WDU_ENDPOINT_DESCRIPTOR **pEndpointDescriptors;
+ WDU_PIPE_INFO **pPipes;
+
+ if (buf) {
+ WDU_ALTERNATE_SETTING *altset = (WDU_ALTERNATE_SETTING*)(buf+len);
+
+ altset->Descriptor.bLength = interface->altsetting[k].bLength;
+ altset->Descriptor.bDescriptorType = interface->altsetting[k].bDescriptorType;
+ altset->Descriptor.bInterfaceNumber = interface->altsetting[k].bInterfaceNumber;
+ altset->Descriptor.bAlternateSetting = interface->altsetting[k].bAlternateSetting;
+ altset->Descriptor.bNumEndpoints = interface->altsetting[k].bNumEndpoints;
+ altset->Descriptor.bInterfaceClass = interface->altsetting[k].bInterfaceClass;
+ altset->Descriptor.bInterfaceSubClass = interface->altsetting[k].bInterfaceSubClass;
+ altset->Descriptor.bInterfaceProtocol = interface->altsetting[k].bInterfaceProtocol;
+ altset->Descriptor.iInterface = interface->altsetting[k].iInterface;
+ pEndpointDescriptors = &(altset->pEndpointDescriptors);
+ pPipes = &(altset->pPipes);
+
+ }
+ len +=sizeof(WDU_ALTERNATE_SETTING);
+
+ if (buf) {
+ *pEndpointDescriptors = (WDU_ENDPOINT_DESCRIPTOR*)(buf+len);
+ for (l = 0; l < bNumEndpoints; l++) {
+ WDU_ENDPOINT_DESCRIPTOR *ed = (WDU_ENDPOINT_DESCRIPTOR*)(buf+len);
+
+ ed->bLength = interface->altsetting[k].endpoint[l].bLength;
+ ed->bDescriptorType = interface->altsetting[k].endpoint[l].bDescriptorType;
+ ed->bEndpointAddress = interface->altsetting[k].endpoint[l].bEndpointAddress;
+ ed->bmAttributes = interface->altsetting[k].endpoint[l].bmAttributes;
+ ed->wMaxPacketSize = interface->altsetting[k].endpoint[l].wMaxPacketSize;
+ ed->bInterval = interface->altsetting[k].endpoint[l].bInterval;
+
+ len += sizeof(WDU_ENDPOINT_DESCRIPTOR);
+ }
+
+ *pPipes = (WDU_PIPE_INFO*)(buf+len);
+ for (l = 0; l < bNumEndpoints; l++) {
+ WDU_PIPE_INFO *pi = (WDU_PIPE_INFO*)(buf+len);
+
+ pi->dwNumber = interface->altsetting[k].endpoint[l].bEndpointAddress;
+ pi->dwMaximumPacketSize = WDU_GET_MAX_PACKET_SIZE(interface->altsetting[k].endpoint[l].wMaxPacketSize);
+ pi->type = interface->altsetting[k].endpoint[l].bmAttributes & USB_ENDPOINT_TYPE_MASK;
+ if (pi->type == PIPE_TYPE_CONTROL)
+ pi->direction = WDU_DIR_IN_OUT;
+ else
+ {
+ pi->direction = interface->altsetting[k].endpoint[l].bEndpointAddress & USB_ENDPOINT_DIR_MASK ? WDU_DIR_IN : WDU_DIR_OUT;
+ }
+
+ pi->dwInterval = interface->altsetting[k].endpoint[l].bInterval;
+
+ len += sizeof(WDU_PIPE_INFO);
+ }
+ } else {
+ len +=(sizeof(WDU_ENDPOINT_DESCRIPTOR)+sizeof(WDU_PIPE_INFO))*bNumEndpoints;
+ }
+ }
+ }
+ }
+
+ return len;
+}