/* This function returns the USB transfer status, and put the high level command execution result in Result. The CBI contains three phases: Command, Data, and Status. This is Status phase. */
EFI_STATUS UsbCbiGetStatus(IN USB_CBI_PROTOCOL *UsbCbi, IN UINT32 Timeout, OUT USB_CBI_STATUS *Result)
/* This function returns the USB transfer status, and put the high level command execution result in Result. The CBI contains three phases: Command, Data, and Status. This is Status phase. */
EFI_STATUS UsbCbiGetStatus(IN USB_CBI_PROTOCOL *UsbCbi, IN UINT32 Timeout, OUT USB_CBI_STATUS *Result)
{
  UINTN       Len;
  UINT8       Endpoint;
  EFI_STATUS  Status;
  UINT32      TransStatus;
  INTN        Retry;
  Endpoint = UsbCbi->InterruptEndpoint->EndpointAddress;
  Status   = EFI_SUCCESS;
  Timeout  = Timeout / USB_MASS_1_MILLISECOND;
  for (Retry = 0; Retry < USB_CBI_MAX_RETRY; Retry++) {
    TransStatus = 0;
    Len         = sizeof (USB_CBI_STATUS);
    Status = UsbCbi->UsbIo->UsbSyncInterruptTransfer (
                              UsbCbi->UsbIo,
                              Endpoint,
                              Result,
                              &Len,
                              Timeout,
                              &TransStatus
                              );
    if (EFI_ERROR (Status) && (TransStatus == EFI_USB_ERR_NAK)) {
      continue;
    }
    break;
  }
  return Status;
}