# HG changeset patch # User Ivo Smits # Date 1381618108 -7200 # Node ID 2b24666cd75922a9a051d80e41e561334ca24f58 # Parent 3424fa5a12c98b904c3000ff3c793690181206d6 Fixed errors in Windows USB enumeration and LibUsbDotNet configuration descriptor code diff -r 3424fa5a12c9 -r 2b24666cd759 USBLib/Communication/LibUsbDotNet.cs --- a/USBLib/Communication/LibUsbDotNet.cs Sat Oct 12 16:35:24 2013 +0200 +++ b/USBLib/Communication/LibUsbDotNet.cs Sun Oct 13 00:48:28 2013 +0200 @@ -108,16 +108,24 @@ public IList Configs { get { List rtnConfigs = new List(); - byte[] cfgBuffer = new byte[UsbConstants.MAX_CONFIG_SIZE]; int iConfigs = Info.Descriptor.ConfigurationCount; for (int iConfig = 0; iConfig < iConfigs; iConfig++) { int iBytesTransmitted; + byte[] cfgBuffer = new byte[9]; if (!GetDescriptor((byte)UsbDescriptorType.Configuration, (byte)iConfig, 0, cfgBuffer, cfgBuffer.Length, out iBytesTransmitted)) throw new Exception("Could not read configuration descriptor"); if (iBytesTransmitted < UsbConfigDescriptor.Size || cfgBuffer[1] != (byte)UsbDescriptorType.Configuration) throw new Exception("GetDeviceConfigs: USB config descriptor is invalid."); UsbConfigDescriptor configDescriptor = new UsbConfigDescriptor(); Helper.BytesToObject(cfgBuffer, 0, Math.Min(UsbConfigDescriptor.Size, cfgBuffer[0]), configDescriptor); + if (configDescriptor.TotalLength > cfgBuffer.Length) { + cfgBuffer = new Byte[configDescriptor.TotalLength]; + if (!GetDescriptor((byte)UsbDescriptorType.Configuration, (byte)iConfig, 0, cfgBuffer, cfgBuffer.Length, out iBytesTransmitted)) + throw new Exception("Could not read configuration descriptor"); + if (iBytesTransmitted < UsbConfigDescriptor.Size || cfgBuffer[1] != (byte)UsbDescriptorType.Configuration) + throw new Exception("GetDeviceConfigs: USB config descriptor is invalid."); + Helper.BytesToObject(cfgBuffer, 0, Math.Min(UsbConfigDescriptor.Size, cfgBuffer[0]), configDescriptor); + } if (configDescriptor.TotalLength != iBytesTransmitted) throw new Exception("GetDeviceConfigs: USB config descriptor length doesn't match the length received."); List rawDescriptorList = new List(); int iRawLengthPosition = configDescriptor.Length; diff -r 3424fa5a12c9 -r 2b24666cd759 USBLib/Windows/USB/UsbDevice.cs --- a/USBLib/Windows/USB/UsbDevice.cs Sat Oct 12 16:35:24 2013 +0200 +++ b/USBLib/Windows/USB/UsbDevice.cs Sun Oct 13 00:48:28 2013 +0200 @@ -142,6 +142,7 @@ } isHostController = false; DeviceNode parent = node.GetParent(); + if (parent == null) return null; Boolean isHostControllerA; UsbDevice usbdev = GetUsbDevice(parent, out isHostControllerA); if (isHostControllerA) return usbdev;