usb.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2008 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef GRUB_USB_H
  19. #define GRUB_USB_H 1
  20. #include <grub/usbdesc.h>
  21. #include <grub/usbtrans.h>
  22. typedef struct grub_usb_device *grub_usb_device_t;
  23. typedef struct grub_usb_controller *grub_usb_controller_t;
  24. typedef struct grub_usb_controller_dev *grub_usb_controller_dev_t;
  25. typedef enum
  26. {
  27. GRUB_USB_ERR_NONE,
  28. GRUB_USB_ERR_INTERNAL,
  29. GRUB_USB_ERR_STALL,
  30. GRUB_USB_ERR_DATA,
  31. GRUB_USB_ERR_NAK,
  32. GRUB_USB_ERR_BABBLE,
  33. GRUB_USB_ERR_TIMEOUT,
  34. GRUB_USB_ERR_BITSTUFF
  35. } grub_usb_err_t;
  36. typedef enum
  37. {
  38. GRUB_USB_SPEED_NONE,
  39. GRUB_USB_SPEED_LOW,
  40. GRUB_USB_SPEED_FULL,
  41. GRUB_USB_SPEED_HIGH
  42. } grub_usb_speed_t;
  43. /* Call HOOK with each device, until HOOK returns non-zero. */
  44. int grub_usb_iterate (int (*hook) (grub_usb_device_t dev, void *closure),
  45. void *closure);
  46. grub_usb_err_t grub_usb_device_initialize (grub_usb_device_t dev);
  47. grub_usb_err_t grub_usb_get_descriptor (grub_usb_device_t dev,
  48. grub_uint8_t type, grub_uint8_t index,
  49. grub_size_t size, char *data);
  50. struct grub_usb_desc_endp *
  51. grub_usb_get_endpdescriptor (grub_usb_device_t usbdev, int addr);
  52. grub_usb_err_t grub_usb_clear_halt (grub_usb_device_t dev, int endpoint);
  53. grub_usb_err_t grub_usb_set_configuration (grub_usb_device_t dev,
  54. int configuration);
  55. void grub_usb_controller_dev_register (grub_usb_controller_dev_t usb);
  56. void grub_usb_controller_dev_unregister (grub_usb_controller_dev_t usb);
  57. int grub_usb_controller_iterate (int (*hook) (grub_usb_controller_t dev,
  58. void *closure),
  59. void *closure);
  60. grub_usb_err_t grub_usb_control_msg (grub_usb_device_t dev, grub_uint8_t reqtype,
  61. grub_uint8_t request, grub_uint16_t value,
  62. grub_uint16_t index, grub_size_t size,
  63. char *data);
  64. grub_usb_err_t
  65. grub_usb_bulk_read (grub_usb_device_t dev,
  66. int endpoint, grub_size_t size, char *data);
  67. grub_usb_err_t
  68. grub_usb_bulk_write (grub_usb_device_t dev,
  69. int endpoint, grub_size_t size, char *data);
  70. grub_usb_err_t
  71. grub_usb_root_hub (grub_usb_controller_t controller);
  72. /* XXX: All handled by libusb for now. */
  73. struct grub_usb_controller_dev
  74. {
  75. /* The device name. */
  76. const char *name;
  77. int (*iterate) (int (*hook) (grub_usb_controller_t dev, void *closure),
  78. void *closure);
  79. grub_usb_err_t (*transfer) (grub_usb_controller_t dev,
  80. grub_usb_transfer_t transfer);
  81. int (*hubports) (grub_usb_controller_t dev);
  82. grub_err_t (*portstatus) (grub_usb_controller_t dev, unsigned int port,
  83. unsigned int enable);
  84. grub_usb_speed_t (*detect_dev) (grub_usb_controller_t dev, int port);
  85. /* The next host controller. */
  86. struct grub_usb_controller_dev *next;
  87. };
  88. struct grub_usb_controller
  89. {
  90. /* The underlying USB Host Controller device. */
  91. grub_usb_controller_dev_t dev;
  92. /* Data used by the USB Host Controller Driver. */
  93. void *data;
  94. };
  95. struct grub_usb_interface
  96. {
  97. struct grub_usb_desc_if *descif;
  98. struct grub_usb_desc_endp *descendp;
  99. };
  100. struct grub_usb_configuration
  101. {
  102. /* Configuration descriptors . */
  103. struct grub_usb_desc_config *descconf;
  104. /* Interfaces associated to this configuration. */
  105. struct grub_usb_interface interf[32];
  106. };
  107. struct grub_usb_device
  108. {
  109. /* The device descriptor of this device. */
  110. struct grub_usb_desc_device descdev;
  111. /* The controller the device is connected to. */
  112. struct grub_usb_controller controller;
  113. /* Device configurations (after opening the device). */
  114. struct grub_usb_configuration config[8];
  115. /* Device address. */
  116. int addr;
  117. /* Device speed. */
  118. grub_usb_speed_t speed;
  119. /* All descriptors are read if this is set to 1. */
  120. int initialized;
  121. /* Data toggle values (used for bulk transfers only). */
  122. int toggle[16];
  123. /* Device-specific data. */
  124. void *data;
  125. };
  126. typedef enum
  127. {
  128. GRUB_USB_CLASS_NOTHERE,
  129. GRUB_USB_CLASS_AUDIO,
  130. GRUB_USB_CLASS_COMMUNICATION,
  131. GRUB_USB_CLASS_HID,
  132. GRUB_USB_CLASS_XXX,
  133. GRUB_USB_CLASS_PHYSICAL,
  134. GRUB_USB_CLASS_IMAGE,
  135. GRUB_USB_CLASS_PRINTER,
  136. GRUB_USB_CLASS_MASS_STORAGE,
  137. GRUB_USB_CLASS_HUB,
  138. GRUB_USB_CLASS_DATA_INTERFACE,
  139. GRUB_USB_CLASS_SMART_CARD,
  140. GRUB_USB_CLASS_CONTENT_SECURITY,
  141. GRUB_USB_CLASS_VIDEO
  142. } grub_usb_classes_t;
  143. typedef enum
  144. {
  145. GRUB_USBMS_SUBCLASS_BULK = 0x06
  146. } grub_usbms_subclass_t;
  147. typedef enum
  148. {
  149. GRUB_USBMS_PROTOCOL_BULK = 0x50
  150. } grub_usbms_protocol_t;
  151. static inline struct grub_usb_desc_if *
  152. grub_usb_get_config_interface (struct grub_usb_desc_config *config)
  153. {
  154. struct grub_usb_desc_if *interf;
  155. interf = (struct grub_usb_desc_if *) (sizeof (*config) + (char *) config);
  156. return interf;
  157. }
  158. #endif /* GRUB_USB_H */