X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FModules%2FUSB%2FCore%2Fusb_devinit.c;h=d260f62744de3c186b3d91e4c4f2fc223d7ca4b9;hb=5fad99e7c76b4974a45c6c1880ee63eb2839d324;hp=32076690faf5c937b3fff5996fdd234eb0291dc6;hpb=45c91b880402af13c4b8f934c53780d7cba24aac;p=tpg%2Facess2.git diff --git a/KernelLand/Modules/USB/Core/usb_devinit.c b/KernelLand/Modules/USB/Core/usb_devinit.c index 32076690..d260f627 100644 --- a/KernelLand/Modules/USB/Core/usb_devinit.c +++ b/KernelLand/Modules/USB/Core/usb_devinit.c @@ -6,7 +6,6 @@ * - USB Device Initialisation */ #define DEBUG 1 - #include #include #include @@ -14,6 +13,8 @@ #include "usb_proto.h" #include "usb_lowlevel.h" +#define DUMP_DESCRIPTORS 1 + // === PROTOTYPES === void USB_DeviceConnected(tUSBHub *Hub, int Port); void USB_DeviceDisconnected(tUSBHub *Hub, int Port); @@ -55,22 +56,23 @@ void USB_DeviceConnected(tUSBHub *Hub, int Port) LOG("Getting device descriptor"); // Endpoint 0, Desc Type 1, Index 0 USB_int_ReadDescriptor(dev, 0, 1, 0, sizeof(desc), &desc); - + + #if DUMP_DESCRIPTORS LOG("Device Descriptor = {"); LOG(" .Length = %i", desc.Length); LOG(" .Type = %i", desc.Type); - LOG(" .USBVersion = 0x%04x", desc.USBVersion); + LOG(" .USBVersion = 0x%04x", LittleEndian16(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(" .VendorID = 0x%04x", LittleEndian16(desc.VendorID)); + LOG(" .ProductID = 0x%04x", LittleEndian16(desc.ProductID)); + LOG(" .DeviceID = 0x%04x", LittleEndian16(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(" .NumConfigurations = %i", desc.NumConfigurations); LOG("}"); #if DEBUG @@ -99,6 +101,9 @@ void USB_DeviceConnected(tUSBHub *Hub, int Port) } } #endif + #endif + + memcpy(&dev->DevDesc, &desc, sizeof(desc)); } // TODO: Support alternate configurations @@ -112,6 +117,8 @@ void USB_DeviceConnected(tUSBHub *Hub, int Port) size_t total_length; USB_int_ReadDescriptor(dev, 0, 2, i, sizeof(desc), &desc); + // TODO: Check return length? (Do we get a length?) + #if DUMP_DESCRIPTORS LOG("Configuration Descriptor %i = {", i); LOG(" .Length = %i", desc.Length); LOG(" .Type = %i", desc.Type); @@ -127,6 +134,12 @@ void USB_DeviceConnected(tUSBHub *Hub, int Port) LOG("ConfigurationStr = '%s'", tmp); free(tmp); } + #endif + + if( desc.NumInterfaces == 0 ) { + Log_Notice("USB", "Device does not have any interfaces"); + continue ; + } // TODO: Split here and allow some method of selection @@ -139,10 +152,10 @@ void USB_DeviceConnected(tUSBHub *Hub, int Port) total_length = LittleEndian16(desc.TotalLength); full_buf = malloc( total_length ); USB_int_ReadDescriptor(dev, 0, 2, i, total_length, full_buf); - ptr_ofs += desc.Length; - // TODO: Interfaces + + // Interfaces! for( int j = 0; ptr_ofs < total_length && j < desc.NumInterfaces; j ++ ) { struct sDescriptor_Interface *iface; @@ -167,26 +180,30 @@ void USB_DeviceConnected(tUSBHub *Hub, int Port) continue ; } + #if DUMP_DESCRIPTORS LOG("Interface %i/%i = {", i, j); 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 DEBUG if( iface->InterfaceStr ) { char *tmp = USB_int_GetDeviceString(dev, 0, iface->InterfaceStr); LOG(" .InterfaceStr = %i '%s'", iface->InterfaceStr, tmp); free(tmp); } - #endif LOG("}"); + #endif - dev_if = malloc(sizeof(tUSBInterface) + iface->NumEndpoints*sizeof(dev_if->Endpoints[0])); + dev_if = malloc( + sizeof(tUSBInterface) + + iface->NumEndpoints*sizeof(dev_if->Endpoints[0]) + ); dev_if->Dev = dev; dev_if->Driver = NULL; dev_if->Data = NULL; dev_if->nEndpoints = iface->NumEndpoints; + memcpy(&dev_if->IfaceDesc, iface, sizeof(*iface)); dev->Interfaces[j] = dev_if; // Copy interface data @@ -239,11 +256,11 @@ void USB_DeviceConnected(tUSBHub *Hub, int Port) ); } else { + LOG("Driver '%s' in use", dev_if->Driver->Name); dev_if->Driver->Connected( dev_if, full_buf + iface_base_ofs, ptr_ofs - iface_base_ofs ); - // dev_if->Driver->Connected( dev_if ); } }