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