iPXE
cdc.h
Go to the documentation of this file.
00001 #ifndef _IPXE_CDC_H
00002 #define _IPXE_CDC_H
00003 
00004 /** @file
00005  *
00006  * USB Communications Device Class (CDC)
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 #include <ipxe/usb.h>
00013 
00014 /** Class code for communications devices */
00015 #define USB_CLASS_CDC 2
00016 
00017 /** Send encapsulated command */
00018 #define CDC_SEND_ENCAPSULATED_COMMAND                                   \
00019         ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE |          \
00020           USB_REQUEST_TYPE ( 0x00 ) )
00021 
00022 /** Get encapsulated response */
00023 #define CDC_GET_ENCAPSULATED_RESPONSE                                   \
00024         ( USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE |           \
00025           USB_REQUEST_TYPE ( 0x01 ) )
00026 
00027 /** Union functional descriptor */
00028 struct cdc_union_descriptor {
00029         /** Descriptor header */
00030         struct usb_descriptor_header header;
00031         /** Descriptor subtype */
00032         uint8_t subtype;
00033         /** Interfaces (variable-length) */
00034         uint8_t interface[1];
00035 } __attribute__ (( packed ));
00036 
00037 /** Union functional descriptor subtype */
00038 #define CDC_SUBTYPE_UNION 6
00039 
00040 /** Ethernet descriptor subtype */
00041 #define CDC_SUBTYPE_ETHERNET 15
00042 
00043 /** Response available */
00044 #define CDC_RESPONSE_AVAILABLE                                          \
00045         ( USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE |           \
00046           USB_REQUEST_TYPE ( 0x01 ) )
00047 
00048 /** Network connection notification */
00049 #define CDC_NETWORK_CONNECTION                                          \
00050         ( USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE |           \
00051           USB_REQUEST_TYPE ( 0x00 ) )
00052 
00053 /** Connection speed change notification */
00054 #define CDC_CONNECTION_SPEED_CHANGE                                     \
00055         ( USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE |           \
00056           USB_REQUEST_TYPE ( 0x2a ) )
00057 
00058 /** Connection speed change notification */
00059 struct cdc_connection_speed_change {
00060         /** Downlink bit rate, in bits per second */
00061         uint32_t down;
00062         /** Uplink bit rate, in bits per second */
00063         uint32_t up;
00064 } __attribute__ (( packed ));
00065 
00066 extern struct cdc_union_descriptor *
00067 cdc_union_descriptor ( struct usb_configuration_descriptor *config,
00068                        struct usb_interface_descriptor *interface );
00069 
00070 /**
00071  * Send encapsulated command
00072  *
00073  * @v usb               USB device
00074  * @v interface         Interface number
00075  * @v data              Command
00076  * @v len               Length of command
00077  * @ret rc              Return status code
00078  */
00079 static inline __attribute__ (( always_inline )) int
00080 cdc_send_encapsulated_command ( struct usb_device *usb, unsigned int interface,
00081                                 void *data, size_t len ) {
00082 
00083         return usb_control ( usb, CDC_SEND_ENCAPSULATED_COMMAND, 0, interface,
00084                              data, len );
00085 }
00086 
00087 /**
00088 * Get encapsulated response
00089 *
00090 * @v usb                USB device
00091 * @v interface          Interface number
00092 * @v data               Response buffer
00093 * @v len                Length of response buffer
00094 * @ret rc               Return status code
00095 */
00096 static inline __attribute__ (( always_inline )) int
00097 cdc_get_encapsulated_response ( struct usb_device *usb, unsigned int interface,
00098                                 void *data, size_t len ) {
00099 
00100         return usb_control ( usb, CDC_GET_ENCAPSULATED_RESPONSE, 0, interface,
00101                              data, len );
00102 }
00103 
00104 #endif /* _IPXE_CDC_H */