UsbDevice.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /** @file
  2. Copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. **/
  5. #ifndef __USB_DEVICE_PROTOCOL_H__
  6. #define __USB_DEVICE_PROTOCOL_H__
  7. #include <IndustryStandard/Usb.h>
  8. extern EFI_GUID gUsbDeviceProtocolGuid;
  9. /*
  10. * Note: This Protocol is just the bare minimum for Android Fastboot. It
  11. * only makes sense for devices that only do Bulk Transfers and only have one
  12. * endpoint.
  13. */
  14. /*
  15. Callback to be called when data is received.
  16. Buffer is callee-allocated and it's the caller's responsibility to free it with
  17. FreePool.
  18. @param[in] Size Size in bytes of data.
  19. @param[in] Buffer Pointer to data.
  20. */
  21. typedef
  22. VOID
  23. (*USB_DEVICE_RX_CALLBACK) (
  24. IN UINTN Size,
  25. IN VOID *Buffer
  26. );
  27. /*
  28. Callback to be called when the host asks for data by sending an IN token
  29. (excluding during the data stage of a control transfer).
  30. When this function is called, data previously buffered by calling Send() has
  31. been sent.
  32. @param[in]Endpoint Endpoint index, as specified in endpoint descriptors, of
  33. the endpoint the IN token was sent to.
  34. */
  35. typedef
  36. VOID
  37. (*USB_DEVICE_TX_CALLBACK) (
  38. IN UINT8 EndpointIndex
  39. );
  40. /*
  41. Put data in the Tx buffer to be sent on the next IN token.
  42. Don't call this function again until the TxCallback has been called.
  43. @param[in]Endpoint Endpoint index, as specified in endpoint descriptors, of
  44. the endpoint to send the data from.
  45. @param[in]Size Size in bytes of data.
  46. @param[in]Buffer Pointer to data.
  47. @retval EFI_SUCCESS The data was queued successfully.
  48. @retval EFI_INVALID_PARAMETER There was an error sending the data.
  49. */
  50. typedef
  51. EFI_STATUS
  52. (*USB_DEVICE_SEND) (
  53. IN UINT8 EndpointIndex,
  54. IN UINTN Size,
  55. IN CONST VOID *Buffer
  56. );
  57. /*
  58. Restart the USB peripheral controller and respond to enumeration.
  59. @param[in] DeviceDescriptor pointer to device descriptor
  60. @param[in] Descriptors Array of pointers to buffers, where
  61. Descriptors[n] contains the response to a
  62. GET_DESCRIPTOR request for configuration n. From
  63. USB Spec section 9.4.3:
  64. "The first interface descriptor follows the
  65. configuration descriptor. The endpoint
  66. descriptors for the first interface follow the
  67. first interface descriptor. If there are
  68. additional interfaces, their interface
  69. descriptor and endpoint descriptors follow the
  70. first interface’s endpoint descriptors".
  71. The size of each buffer is the TotalLength
  72. member of the Configuration Descriptor.
  73. The size of the array is
  74. DeviceDescriptor->NumConfigurations.
  75. @param[in]RxCallback See USB_DEVICE_RX_CALLBACK
  76. @param[in]TxCallback See USB_DEVICE_TX_CALLBACK
  77. */
  78. typedef
  79. EFI_STATUS
  80. (*USB_DEVICE_START) (
  81. IN USB_DEVICE_DESCRIPTOR *DeviceDescriptor,
  82. IN VOID **Descriptors,
  83. IN USB_DEVICE_RX_CALLBACK RxCallback,
  84. IN USB_DEVICE_TX_CALLBACK TxCallback
  85. );
  86. struct _USB_DEVICE_PROTOCOL {
  87. USB_DEVICE_START Start;
  88. USB_DEVICE_SEND Send;
  89. };
  90. typedef struct _USB_DEVICE_PROTOCOL USB_DEVICE_PROTOCOL;
  91. #endif //ifndef __USB_DEVICE_PROTOCOL_H__