public GetDescriptor ( byte descriptorType, byte index, short langId, |
||
descriptorType | byte | The descriptor type ID to retrieve; this is usually one of the |
index | byte | Descriptor index. |
langId | short | Descriptor language id. |
buffer | Memory to store the returned descriptor in. | |
bufferLength | int | Length of the buffer parameter in bytes. |
transferLength | int | The number of bytes transferred to buffer upon success. |
return | bool |
internal static List <UsbConfigInfo> GetDeviceConfigs(UsbDevice usbDevice) { List <UsbConfigInfo> rtnConfigs = new List <UsbConfigInfo>(); byte[] cfgBuffer = new byte[UsbConstants.MAX_CONFIG_SIZE]; int iConfigs = usbDevice.Info.Descriptor.ConfigurationCount; for (int iConfig = 0; iConfig < iConfigs; iConfig++) { int iBytesTransmitted; bool bSuccess = usbDevice.GetDescriptor((byte)DescriptorType.Configuration, 0, 0, cfgBuffer, cfgBuffer.Length, out iBytesTransmitted); if (bSuccess) { if (iBytesTransmitted >= UsbConfigDescriptor.Size && cfgBuffer[1] == (byte)DescriptorType.Configuration) { UsbConfigDescriptor configDescriptor = new UsbConfigDescriptor(); Helper.BytesToObject(cfgBuffer, 0, Math.Min(UsbConfigDescriptor.Size, cfgBuffer[0]), configDescriptor); if (configDescriptor.TotalLength == iBytesTransmitted) { List <byte[]> rawDescriptorList = new List <byte[]>(); int iRawLengthPosition = configDescriptor.Length; while (iRawLengthPosition < configDescriptor.TotalLength) { byte[] rawDescriptor = new byte[cfgBuffer[iRawLengthPosition]]; if (iRawLengthPosition + rawDescriptor.Length > iBytesTransmitted) { throw new UsbException(usbDevice, "Descriptor length is out of range."); } Array.Copy(cfgBuffer, iRawLengthPosition, rawDescriptor, 0, rawDescriptor.Length); rawDescriptorList.Add(rawDescriptor); iRawLengthPosition += rawDescriptor.Length; } rtnConfigs.Add(new UsbConfigInfo(usbDevice, configDescriptor, ref rawDescriptorList)); } else { UsbError.Error(ErrorCode.InvalidConfig, 0, "GetDeviceConfigs: USB config descriptor length doesn't match the length received.", usbDevice); } } else { UsbError.Error(ErrorCode.InvalidConfig, 0, "GetDeviceConfigs: USB config descriptor is invalid.", usbDevice); } } else { UsbError.Error(ErrorCode.InvalidConfig, 0, "GetDeviceConfigs", usbDevice); } } return(rtnConfigs); }
internal static List<UsbConfigInfo> GetDeviceConfigs(UsbDevice usbDevice) { List<UsbConfigInfo> rtnConfigs = new List<UsbConfigInfo>(); byte[] cfgBuffer = new byte[UsbConstants.MAX_CONFIG_SIZE]; int iConfigs = usbDevice.Info.Descriptor.ConfigurationCount; for (int iConfig = 0; iConfig < iConfigs; iConfig++) { int iBytesTransmitted; bool bSuccess = usbDevice.GetDescriptor((byte) DescriptorType.Configuration, 0, 0, cfgBuffer, cfgBuffer.Length, out iBytesTransmitted); if (bSuccess) { if (iBytesTransmitted >= UsbConfigDescriptor.Size && cfgBuffer[1] == (byte) DescriptorType.Configuration) { UsbConfigDescriptor configDescriptor = new UsbConfigDescriptor(); Helper.BytesToObject(cfgBuffer, 0, Math.Min(UsbConfigDescriptor.Size, cfgBuffer[0]), configDescriptor); if (configDescriptor.TotalLength == iBytesTransmitted) { List<byte[]> rawDescriptorList = new List<byte[]>(); int iRawLengthPosition = configDescriptor.Length; while (iRawLengthPosition < configDescriptor.TotalLength) { byte[] rawDescriptor = new byte[cfgBuffer[iRawLengthPosition]]; if (iRawLengthPosition + rawDescriptor.Length > iBytesTransmitted) throw new UsbException(usbDevice, "Descriptor length is out of range."); Array.Copy(cfgBuffer, iRawLengthPosition, rawDescriptor, 0, rawDescriptor.Length); rawDescriptorList.Add(rawDescriptor); iRawLengthPosition += rawDescriptor.Length; } rtnConfigs.Add(new UsbConfigInfo(usbDevice, configDescriptor, ref rawDescriptorList)); } else UsbError.Error(ErrorCode.InvalidConfig, 0, "GetDeviceConfigs: USB config descriptor length doesn't match the length received.", usbDevice); } else UsbError.Error(ErrorCode.InvalidConfig, 0, "GetDeviceConfigs: USB config descriptor is invalid.", usbDevice); } else UsbError.Error(ErrorCode.InvalidConfig, 0, "GetDeviceConfigs", usbDevice); } return rtnConfigs; }