X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FModules%2FUSB%2FCore%2Fusb_devinit.c;h=fb44bb04387ecdb5667baf72a19ca684342a54f9;hb=53c786d33db4627ae764299a62b1769eaed137c5;hp=4b18b30a582c7e5c9e1b0c220a4082d00122f795;hpb=1ba64c63a4a3a8ce27155f9463f0442ea7f7dc89;p=tpg%2Facess2.git diff --git a/KernelLand/Modules/USB/Core/usb_devinit.c b/KernelLand/Modules/USB/Core/usb_devinit.c index 4b18b30a..fb44bb04 100644 --- a/KernelLand/Modules/USB/Core/usb_devinit.c +++ b/KernelLand/Modules/USB/Core/usb_devinit.c @@ -5,8 +5,7 @@ * usb_devinit.c * - USB Device Initialisation */ -#define DEBUG 0 - +#define DEBUG 1 #include #include #include @@ -14,6 +13,8 @@ #include "usb_proto.h" #include "usb_lowlevel.h" +#define DUMP_DESCRIPTORS 0 + // === PROTOTYPES === void USB_DeviceConnected(tUSBHub *Hub, int Port); void USB_DeviceDisconnected(tUSBHub *Hub, int Port); @@ -55,7 +56,8 @@ 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); @@ -72,25 +74,34 @@ void USB_DeviceConnected(tUSBHub *Hub, int Port) LOG(" .SerialNumberStr = Str %i", desc.SerialNumberStr); LOG(" .NumConfigurations = %i", desc.SerialNumberStr); LOG("}"); - + + #if DEBUG if( desc.ManufacturerStr ) { char *tmp = USB_int_GetDeviceString(dev, 0, desc.ManufacturerStr); - LOG("ManufacturerStr = '%s'", tmp); - free(tmp); + if( tmp ) { + 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( tmp ) { + LOG("ProductStr = '%s'", tmp); + free(tmp); + } } if( desc.SerialNumberStr ) { char *tmp = USB_int_GetDeviceString(dev, 0, desc.SerialNumberStr); - LOG("SerialNumbertStr = '%s'", tmp); - free(tmp); + if( tmp ) { + LOG("SerialNumbertStr = '%s'", tmp); + free(tmp); + } } + #endif + #endif } // TODO: Support alternate configurations @@ -104,6 +115,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); @@ -119,6 +132,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 @@ -142,6 +161,10 @@ void USB_DeviceConnected(tUSBHub *Hub, int Port) size_t iface_base_ofs; iface = (void*)(full_buf + ptr_ofs); + if( iface->Length == 0 ) { + Log_Warning("USB", "Bad USB descriptor (length = 0)"); + break ; + } ptr_ofs += iface->Length; if( ptr_ofs > total_length ) { // Sanity fail @@ -155,6 +178,7 @@ 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); @@ -167,6 +191,7 @@ void USB_DeviceConnected(tUSBHub *Hub, int Port) free(tmp); } LOG("}"); + #endif dev_if = malloc(sizeof(tUSBInterface) + iface->NumEndpoints*sizeof(dev_if->Endpoints[0])); dev_if->Dev = dev; @@ -225,11 +250,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 ); } }