Exemple #1
0
        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();
                        LHelper.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 UsbEndpointInfo(byte[] descriptor)
 {
     mUsbEndpointDescriptor = new UsbEndpointDescriptor();
     LHelper.BytesToObject(descriptor, 0, Math.Min(UsbEndpointDescriptor.Size, descriptor[0]), mUsbEndpointDescriptor);
 }
Exemple #3
0
 internal UsbInterfaceInfo(UsbDevice usbDevice, byte[] descriptor)
 {
     mUsbDevice = usbDevice;
     mUsbInterfaceDescriptor = new UsbInterfaceDescriptor();
     LHelper.BytesToObject(descriptor, 0, Math.Min(UsbInterfaceDescriptor.Size, descriptor[0]), mUsbInterfaceDescriptor);
 }