-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 = 3;
- 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);