diff USBLib/Communication/LibUsbDotNet.cs @ 61:2b24666cd759

Fixed errors in Windows USB enumeration and LibUsbDotNet configuration descriptor code
author Ivo Smits <Ivo@UCIS.nl>
date Sun, 13 Oct 2013 00:48:28 +0200
parents 3424fa5a12c9
children abe0d55a2201
line wrap: on
line diff
--- 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<UsbConfigInfo> Configs {
 			get {
 				List<UsbConfigInfo> rtnConfigs = new List<UsbConfigInfo>();
-				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<byte[]> rawDescriptorList = new List<byte[]>();
 					int iRawLengthPosition = configDescriptor.Length;