internal UsbConfigDescriptor(LibUsbConfigDescriptor descriptor)
 {
     Attributes = descriptor.bmAttributes;
     ConfigID = descriptor.bConfigurationValue;
     DescriptorType = descriptor.bDescriptorType;
     InterfaceCount = descriptor.bNumInterfaces;
     Length = descriptor.bLength;
     MaxPower = descriptor.MaxPower;
     StringIndex = descriptor.iConfiguration;
     TotalLength = (short) descriptor.wTotalLength;
 }
        internal UsbConfigInfo(LibUsbDevice usbDevice, LibUsbConfigDescriptor configDescriptor)
        {
            mUsbDevice = usbDevice;

            mUsbConfigDescriptor = new UsbConfigDescriptor(configDescriptor);

            List<LibUsbInterface> monoUSBInterfaces = configDescriptor.InterfaceList;
            foreach (LibUsbInterface usbInterface in monoUSBInterfaces)
            {
                List<LibUsbAltInterfaceDescriptor> monoUSBAltInterfaces = usbInterface.AltInterfaceList;
                foreach (LibUsbAltInterfaceDescriptor monoUSBAltInterface in monoUSBAltInterfaces)
                {
                    UsbInterfaceInfo usbInterfaceInfo = new UsbInterfaceInfo(mUsbDevice, monoUSBAltInterface);
                    mInterfaceList.Add(usbInterfaceInfo);
                }
            }
        }
        private static ErrorCode GetConfigs(LibUsbDevice usbDevice, out List<UsbConfigInfo> configInfoListRtn)
        {
            configInfoListRtn = new List<UsbConfigInfo>();
            UsbError usbError = null;
            List<LibUsbConfigDescriptor> configList = new List<LibUsbConfigDescriptor>();
            int iConfigs = usbDevice.Info.Descriptor.ConfigurationCount;

            for (int iConfig = 0; iConfig < iConfigs; iConfig++)
            {
                LibUsbConfigHandle nextConfigHandle;
                int ret = LibUsbApi.GetConfigDescriptor(usbDevice.mMonoUSBProfile.ProfileHandle, (byte) iConfig, out nextConfigHandle);
                Debug.Print("GetConfigDescriptor:{0}", ret);
                if (ret != 0 || nextConfigHandle.IsInvalid)
                {
                    usbError = UsbError.Error(ErrorCode.MonoApiError,
                                              ret,
                                              String.Format("GetConfigDescriptor Failed at index:{0}", iConfig),
                                              usbDevice);
                    return usbError.ErrorCode;
                }
                try
                {
                    LibUsbConfigDescriptor nextConfig = new LibUsbConfigDescriptor();
                    Marshal.PtrToStructure(nextConfigHandle.DangerousGetHandle(), nextConfig);

                    UsbConfigInfo nextConfigInfo = new UsbConfigInfo(usbDevice, nextConfig);
                    configInfoListRtn.Add(nextConfigInfo);
                }
                catch (Exception ex)
                {
                    UsbError.Error(ErrorCode.InvalidConfig, Marshal.GetLastWin32Error(), ex.ToString(), usbDevice);
                }
                finally
                {
                    if (!nextConfigHandle.IsInvalid)
                        nextConfigHandle.Close();
                }
            }

            return ErrorCode.Success;
        }