You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #ifndef _IPXE_CDC_H
  2. #define _IPXE_CDC_H
  3. /** @file
  4. *
  5. * USB Communications Device Class (CDC)
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <ipxe/usb.h>
  10. /** Class code for communications devices */
  11. #define USB_CLASS_CDC 2
  12. /** Send encapsulated command */
  13. #define CDC_SEND_ENCAPSULATED_COMMAND \
  14. ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \
  15. USB_REQUEST_TYPE ( 0x00 ) )
  16. /** Get encapsulated response */
  17. #define CDC_GET_ENCAPSULATED_RESPONSE \
  18. ( USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \
  19. USB_REQUEST_TYPE ( 0x01 ) )
  20. /** Union functional descriptor */
  21. struct cdc_union_descriptor {
  22. /** Descriptor header */
  23. struct usb_descriptor_header header;
  24. /** Descriptor subtype */
  25. uint8_t subtype;
  26. /** Interfaces (variable-length) */
  27. uint8_t interface[1];
  28. } __attribute__ (( packed ));
  29. /** Union functional descriptor subtype */
  30. #define CDC_SUBTYPE_UNION 6
  31. /** Ethernet descriptor subtype */
  32. #define CDC_SUBTYPE_ETHERNET 15
  33. /** Response available */
  34. #define CDC_RESPONSE_AVAILABLE \
  35. ( USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \
  36. USB_REQUEST_TYPE ( 0x01 ) )
  37. /** Network connection notification */
  38. #define CDC_NETWORK_CONNECTION \
  39. ( USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \
  40. USB_REQUEST_TYPE ( 0x00 ) )
  41. /** Connection speed change notification */
  42. #define CDC_CONNECTION_SPEED_CHANGE \
  43. ( USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \
  44. USB_REQUEST_TYPE ( 0x2a ) )
  45. /** Connection speed change notification */
  46. struct cdc_connection_speed_change {
  47. /** Downlink bit rate, in bits per second */
  48. uint32_t down;
  49. /** Uplink bit rate, in bits per second */
  50. uint32_t up;
  51. } __attribute__ (( packed ));
  52. extern struct cdc_union_descriptor *
  53. cdc_union_descriptor ( struct usb_configuration_descriptor *config,
  54. struct usb_interface_descriptor *interface );
  55. /**
  56. * Send encapsulated command
  57. *
  58. * @v usb USB device
  59. * @v interface Interface number
  60. * @v data Command
  61. * @v len Length of command
  62. * @ret rc Return status code
  63. */
  64. static inline __attribute__ (( always_inline )) int
  65. cdc_send_encapsulated_command ( struct usb_device *usb, unsigned int interface,
  66. void *data, size_t len ) {
  67. return usb_control ( usb, CDC_SEND_ENCAPSULATED_COMMAND, 0, interface,
  68. data, len );
  69. }
  70. /**
  71. * Get encapsulated response
  72. *
  73. * @v usb USB device
  74. * @v interface Interface number
  75. * @v data Response buffer
  76. * @v len Length of response buffer
  77. * @ret rc Return status code
  78. */
  79. static inline __attribute__ (( always_inline )) int
  80. cdc_get_encapsulated_response ( struct usb_device *usb, unsigned int interface,
  81. void *data, size_t len ) {
  82. return usb_control ( usb, CDC_GET_ENCAPSULATED_RESPONSE, 0, interface,
  83. data, len );
  84. }
  85. #endif /* _IPXE_CDC_H */