protocol.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (c) 2020 Actions Corporation.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief USB Host Storage class driver header file
  9. *
  10. * Header file for USB Host Storage class driver
  11. */
  12. #ifndef __USB_HOST_STORAGE_PROTOCOL_H__
  13. #define __USB_HOST_STORAGE_PROTOCOL_H__
  14. /* Bulk-only Command Block Wrapper (CBW) */
  15. struct bulk_cb_wrap {
  16. u32_t Signature;
  17. u32_t Tag;
  18. u32_t DataLength;
  19. u8_t Flags;
  20. u8_t LUN;
  21. u8_t CBLength;
  22. u8_t CB[16];
  23. } __packed;
  24. #define US_BULK_CB_WRAP_LEN 31
  25. #define US_BULK_CB_SIGN 0x43425355 /*spells out USBC */
  26. #define US_BULK_FLAG_IN (1 << 7)
  27. #define US_BULK_FLAG_OUT 0
  28. /* Bulk-only Command Status Wrapper (CSW) */
  29. struct bulk_cs_wrap {
  30. u32_t Signature;
  31. u32_t Tag;
  32. u32_t DataResidue;
  33. u8_t Status;
  34. } __packed;
  35. /* For Read Capacity Command */
  36. typedef struct {
  37. u32_t lba;
  38. u32_t blksz;
  39. } read_cap_data_t;
  40. #define US_BULK_CS_WRAP_LEN 13
  41. #define US_BULK_CS_SIGN 0x53425355 /* spells out 'USBS' */
  42. #define US_BULK_STAT_OK 0
  43. #define US_BULK_STAT_FAIL 1
  44. #define US_BULK_STAT_PHASE 2
  45. /* SCSI Commands */
  46. #define TEST_UNIT_READY 0x00
  47. #define REQUEST_SENSE 0x03
  48. #define FORMAT_UNIT 0x04
  49. #define INQUIRY 0x12
  50. #define MODE_SELECT6 0x15
  51. #define MODE_SENSE6 0x1A
  52. #define START_STOP_UNIT 0x1B
  53. #define MEDIA_REMOVAL 0x1E
  54. #define READ_FORMAT_CAPACITIES 0x23
  55. #define READ_CAPACITY 0x25
  56. #define READ10 0x28
  57. #define WRITE10 0x2A
  58. #define VERIFY10 0x2F
  59. #define READ12 0xA8
  60. #define WRITE12 0xAA
  61. #define MODE_SELECT10 0x55
  62. #define MODE_SENSE10 0x5A
  63. #define MODE_SENSE6 0x1A
  64. /* bulk-only class specific requests */
  65. #define US_BULK_RESET_REQUEST 0xff
  66. #define US_BULK_GET_MAX_LUN 0xfe
  67. #define INQUIRY_LENGTH 0x24
  68. #define REQUEST_SENSE_LENGTH 0x12
  69. #define READ_CAPACITY_LENGTH 0x08
  70. #define MODE_SENSE_LENGTH 0x04
  71. /* Peripheral Device Type */
  72. #define DIRECT_ACCESS_DEVICE 0x00
  73. /* usb storage bulk transfer return codes, in order of severity */
  74. #define USB_STOR_XFER_GOOD 0 /* good transfer */
  75. #define USB_STOR_XFER_SHORT 1 /* transferred less than expected */
  76. #define USB_STOR_XFER_STALLED 2 /* endpoint stalled */
  77. #define USB_STOR_XFER_LONG 3 /* device tried to send too much */
  78. #define USB_STOR_XFER_ERROR 4 /* transfer died in the middle */
  79. #define USB_STOR_XFER_FAILED 5 /* Transport good, command failed */
  80. #define USB_STOR_XFER_NODEV 6 /* device disconnected */
  81. #endif /* __USB_HOST_STORAGE_PROTOCOL_H__ */