wxArrayString OpenOCDDevs::GetInterfaceList()
{
    wxArrayString il;

    int num = GetInterfaceCount();
    for (int i = 0; i < num; i++)
        il.Add(OpenOCDDevList[i].Name);

    return il;
}
int OpenOCDDevs::FindItem(wxString item)
{
    int res = -1;
    int num = GetInterfaceCount();

    for (int i = 0; i < num; i++) {
        if (item == OpenOCDDevList[i].Name)
            res = i;
    }
    return res;
}
OpenOCDIntDev *OpenOCDDevs::GetInterfaceDevice(int item)
{
    if (item < GetInterfaceCount())
        return OpenOCDDevList[item].IntDev;
    return NULL;
}
NTSTATUS AndroidUsbDeviceObject::SelectInterfaces() {
  ASSERT_IRQL_PASSIVE();

  ASSERT(IsDeviceConfigured());
  if (!IsDeviceConfigured())
    return STATUS_INTERNAL_ERROR;

  WDF_USB_DEVICE_SELECT_CONFIG_PARAMS config_params;
  PWDF_USB_INTERFACE_SETTING_PAIR pairs = NULL;
  // TODO: We need to find a way (possibly by looking at each
  // interface descriptor) to get index of the ADB interface in multiinterface
  // configuration.
  UCHAR adb_interface_index = 0;

  if (IsSingleInterfaceDevice()) {
    // Our device has only one interface, so we don't have to bother with
    // multiple interfaces at all.
    GoogleDbgPrint("\n********** Device reports single interface");
    // Select single interface configuration
    WDF_USB_DEVICE_SELECT_CONFIG_PARAMS_INIT_SINGLE_INTERFACE(&config_params);
  } else {
    // Configure multiple interfaces
    ULONG num_interf = GetInterfaceCount();
    GoogleDbgPrint("\n********** Device reports %u interfaces",
             num_interf);

    // Allocate pairs for each interface
    pairs = new(PagedPool, GANDR_POOL_TAG_INTERF_PAIRS)
              WDF_USB_INTERFACE_SETTING_PAIR[num_interf];
    ASSERT(NULL != pairs);
    if (NULL == pairs)
      return STATUS_INSUFFICIENT_RESOURCES;

    adb_interface_index = 1;
    // Initialize each interface pair
    for (UCHAR pair = 0; pair < num_interf; pair++) {
      pairs[pair].SettingIndex = 0;
      pairs[pair].UsbInterface =
        WdfUsbTargetDeviceGetInterface(wdf_target_device(), pair);
      ASSERT(NULL != pairs[pair].UsbInterface);
      if (NULL == pairs[pair].UsbInterface) {
        delete[] pairs;
        return STATUS_INTERNAL_ERROR;
      }
    }

    // Select multiinterface configuration
    WDF_USB_DEVICE_SELECT_CONFIG_PARAMS_INIT_MULTIPLE_INTERFACES(&config_params,
                                                                 (UCHAR)num_interf,
                                                                 pairs);
  }

  NTSTATUS status =
    WdfUsbTargetDeviceSelectConfig(wdf_target_device(),
                                   WDF_NO_OBJECT_ATTRIBUTES,
                                   &config_params);
  if (NULL != pairs)
    delete[] pairs;

  // ASSERT(NT_SUCCESS(status));
  if (!NT_SUCCESS(status))
    return status;

#if DBG
  PrintSelectedConfig(&config_params);
#endif  // DBG

  wdf_usb_interface_ =
    WdfUsbTargetDeviceGetInterface(wdf_target_device(), adb_interface_index);
  ASSERT(NULL != wdf_usb_interface_);
  if (NULL == wdf_usb_interface_)
    return STATUS_INTERNAL_ERROR;

  configured_pipes_num_ = WdfUsbInterfaceGetNumEndpoints(wdf_usb_interface(), 0);
  ASSERT(0 != configured_pipes_num_);

  // Cache selected interface descriptor
  BYTE setting_index =
    WdfUsbInterfaceGetConfiguredSettingIndex(wdf_usb_interface());

  WdfUsbInterfaceGetDescriptor(wdf_usb_interface(),
                               setting_index,
                               &interface_descriptor_);

#if DBG
  PrintInterfaceDescriptor(interface_descriptor());
#endif  // DBG

  // Iterate over pipes, decoding and saving info about bulk r/w pipes for
  // easier and faster addressing later on when they get opened
  for (UCHAR pipe = 0; pipe < configured_pipes_num(); pipe++) {
    WDF_USB_PIPE_INFORMATION pipe_info;
    WDF_USB_PIPE_INFORMATION_INIT(&pipe_info);
    WDFUSBPIPE wdf_pipe_obj =
      WdfUsbInterfaceGetConfiguredPipe(wdf_usb_interface(), pipe, &pipe_info);
    ASSERT(NULL != wdf_pipe_obj);
    if (NULL != wdf_pipe_obj) {
      if ((WdfUsbPipeTypeBulk  == pipe_info.PipeType) &&
          WDF_USB_PIPE_DIRECTION_IN(pipe_info.EndpointAddress)) {
        // This is a bulk read pipe
        ASSERT(!IsBulkReadPipeKnown());
        bulk_read_pipe_index_ = pipe;
      } else {
        ASSERT(!IsBulkWritePipeKnown());
        bulk_write_pipe_index_ = pipe;
      }
    }
#if DBG
    PrintPipeInformation(&pipe_info, pipe);
#endif  // DBG
  }

  // At the end we must have calculated indexes for both,
  // bulk read and write pipes
  ASSERT(!NT_SUCCESS(status) || (IsBulkReadPipeKnown() &&
                                 IsBulkWritePipeKnown()));

  return status;
}