+ // 2. Get device information
+ {
+ struct sDescriptor_Device desc;
+ LOG("Getting device descriptor");
+ // Endpoint 0, Desc Type 1, Index 0
+ USB_int_ReadDescriptor(dev, 0, 1, 0, sizeof(desc), &desc);
+
+ LOG("Device Descriptor = {");
+ LOG(" .Length = %i", desc.Length);
+ LOG(" .Type = %i", desc.Type);
+ LOG(" .USBVersion = 0x%04x", desc.USBVersion);
+ LOG(" .DeviceClass = 0x%02x", desc.DeviceClass);
+ LOG(" .DeviceSubClass = 0x%02x", desc.DeviceSubClass);
+ LOG(" .DeviceProtocol = 0x%02x", desc.DeviceProtocol);
+ LOG(" .MaxPacketSize = 0x%02x", desc.MaxPacketSize);
+ LOG(" .VendorID = 0x%04x", desc.VendorID);
+ LOG(" .ProductID = 0x%04x", desc.ProductID);
+ LOG(" .DeviceID = 0x%04x", desc.DeviceID);
+ LOG(" .ManufacturerStr = Str %i", desc.ManufacturerStr);
+ LOG(" .ProductStr = Str %i", desc.ProductStr);
+ LOG(" .SerialNumberStr = Str %i", desc.SerialNumberStr);
+ LOG(" .NumConfigurations = %i", desc.SerialNumberStr);
+ LOG("}");
+
+ if( desc.ManufacturerStr )
+ {
+ char *tmp = USB_int_GetDeviceString(dev, 0, desc.ManufacturerStr);
+ LOG("ManufacturerStr = '%s'", tmp);
+ free(tmp);
+ }
+ if( desc.ProductStr )
+ {
+ char *tmp = USB_int_GetDeviceString(dev, 0, desc.ProductStr);
+ LOG("ProductStr = '%s'", tmp);
+ free(tmp);
+ }
+ if( desc.SerialNumberStr )
+ {
+ char *tmp = USB_int_GetDeviceString(dev, 0, desc.SerialNumberStr);
+ LOG("SerialNumbertStr = '%s'", tmp);
+ free(tmp);
+ }
+ }
+
+ // 3. Get configurations
+ for( int i = 0; i < 1; i ++ )
+ {
+ struct sDescriptor_Configuration desc;
+ void *full_buf;
+ char *cur_ptr;
+
+ USB_int_ReadDescriptor(dev, 0, 2, i, sizeof(desc), &desc);
+ LOG("Configuration Descriptor %i = {", i);
+ LOG(" .Length = %i", desc.Length);
+ LOG(" .Type = %i", desc.Type);
+ LOG(" .TotalLength = 0x%x", LittleEndian16(desc.TotalLength));
+ LOG(" .NumInterfaces = %i", desc.NumInterfaces);
+ LOG(" .ConfigurationValue = %i", desc.ConfigurationValue);
+ LOG(" .ConfigurationStr = %i", desc.ConfigurationStr);
+ LOG(" .AttributesBmp = 0b%b", desc.AttributesBmp);
+ LOG(" .MaxPower = %i (*2mA)", desc.MaxPower);
+ LOG("}");
+ if( desc.ConfigurationStr ) {
+ char *tmp = USB_int_GetDeviceString(dev, 0, desc.ConfigurationStr);
+ LOG("ConfigurationStr = '%s'", tmp);
+ free(tmp);
+ }
+
+ cur_ptr = full_buf = malloc( LittleEndian16(desc.TotalLength) );
+ USB_int_ReadDescriptor(dev, 0, 2, i, desc.TotalLength, full_buf);
+
+ cur_ptr += desc.Length;
+
+ // TODO: Interfaces
+ for( int j = 0; j < desc.NumInterfaces; j ++ )
+ {
+ struct sDescriptor_Interface *iface;
+ iface = (void*)cur_ptr;
+ // TODO: Sanity check with remaining space
+ cur_ptr += sizeof(*iface);
+
+ LOG("Interface %i/%i = {");
+ LOG(" .InterfaceNum = %i", iface->InterfaceNum);
+ LOG(" .NumEndpoints = %i", iface->NumEndpoints);
+ LOG(" .InterfaceClass = 0x%x", iface->InterfaceClass);
+ LOG(" .InterfaceSubClass = 0x%x", iface->InterfaceSubClass);
+ LOG(" .InterfaceProcol = 0x%x", iface->InterfaceProtocol);
+
+ if( iface->InterfaceStr ) {
+ char *tmp = USB_int_GetDeviceString(dev, 0, iface->InterfaceStr);
+ LOG(" .InterfaceStr = %i '%s'", iface->InterfaceStr, tmp);
+ free(tmp);
+ }
+ LOG("}");
+
+ for( int k = 0; k < iface->NumEndpoints; k ++ )
+ {
+ struct sDescriptor_Endpoint *endpt;
+ endpt = (void*)cur_ptr;
+ // TODO: Sanity check with remaining space
+ cur_ptr += sizeof(*endpt);
+
+
+ }
+ }
+
+ free(full_buf);
+ }
+
+ // Done.
+ LEAVE('-');
+}
+
+void USB_DeviceDisconnected(tUSBHub *Hub, int Port)
+{