Gerd Hoffmann | 37fb59d | 2010-11-17 11:03:53 +0100 | [diff] [blame] | 1 | #ifndef QEMU_HW_USB_DESC_H |
| 2 | #define QEMU_HW_USB_DESC_H |
| 3 | |
| 4 | #include <inttypes.h> |
| 5 | |
| 6 | struct USBDescID { |
| 7 | uint16_t idVendor; |
| 8 | uint16_t idProduct; |
| 9 | uint16_t bcdDevice; |
| 10 | uint8_t iManufacturer; |
| 11 | uint8_t iProduct; |
| 12 | uint8_t iSerialNumber; |
| 13 | }; |
| 14 | |
| 15 | struct USBDescDevice { |
| 16 | uint16_t bcdUSB; |
| 17 | uint8_t bDeviceClass; |
| 18 | uint8_t bDeviceSubClass; |
| 19 | uint8_t bDeviceProtocol; |
| 20 | uint8_t bMaxPacketSize0; |
| 21 | uint8_t bNumConfigurations; |
| 22 | |
| 23 | const USBDescConfig *confs; |
| 24 | }; |
| 25 | |
| 26 | struct USBDescConfig { |
| 27 | uint8_t bNumInterfaces; |
| 28 | uint8_t bConfigurationValue; |
| 29 | uint8_t iConfiguration; |
| 30 | uint8_t bmAttributes; |
| 31 | uint8_t bMaxPower; |
| 32 | |
| 33 | uint8_t nif; |
| 34 | const USBDescIface *ifs; |
| 35 | }; |
| 36 | |
| 37 | struct USBDescIface { |
| 38 | uint8_t bInterfaceNumber; |
| 39 | uint8_t bAlternateSetting; |
| 40 | uint8_t bNumEndpoints; |
| 41 | uint8_t bInterfaceClass; |
| 42 | uint8_t bInterfaceSubClass; |
| 43 | uint8_t bInterfaceProtocol; |
| 44 | uint8_t iInterface; |
| 45 | |
| 46 | uint8_t ndesc; |
| 47 | USBDescOther *descs; |
| 48 | USBDescEndpoint *eps; |
| 49 | }; |
| 50 | |
| 51 | struct USBDescEndpoint { |
| 52 | uint8_t bEndpointAddress; |
| 53 | uint8_t bmAttributes; |
| 54 | uint16_t wMaxPacketSize; |
| 55 | uint8_t bInterval; |
| 56 | }; |
| 57 | |
| 58 | struct USBDescOther { |
| 59 | uint8_t length; |
| 60 | uint8_t *data; |
| 61 | }; |
| 62 | |
| 63 | typedef const char *USBDescStrings[256]; |
| 64 | |
| 65 | struct USBDesc { |
| 66 | USBDescID id; |
| 67 | const USBDescDevice *full; |
| 68 | const USBDescDevice *high; |
| 69 | const char* const *str; |
| 70 | }; |
| 71 | |
| 72 | /* generate usb packages from structs */ |
| 73 | int usb_desc_device(const USBDescID *id, const USBDescDevice *dev, |
| 74 | uint8_t *dest, size_t len); |
Gerd Hoffmann | 25620cb | 2010-12-08 17:35:22 +0100 | [diff] [blame] | 75 | int usb_desc_device_qualifier(const USBDescDevice *dev, |
| 76 | uint8_t *dest, size_t len); |
Gerd Hoffmann | 37fb59d | 2010-11-17 11:03:53 +0100 | [diff] [blame] | 77 | int usb_desc_config(const USBDescConfig *conf, uint8_t *dest, size_t len); |
| 78 | int usb_desc_iface(const USBDescIface *iface, uint8_t *dest, size_t len); |
| 79 | int usb_desc_endpoint(const USBDescEndpoint *ep, uint8_t *dest, size_t len); |
| 80 | int usb_desc_other(const USBDescOther *desc, uint8_t *dest, size_t len); |
Gerd Hoffmann | 37fb59d | 2010-11-17 11:03:53 +0100 | [diff] [blame] | 81 | |
| 82 | /* control message emulation helpers */ |
Gerd Hoffmann | a980a06 | 2010-11-26 20:20:41 +0100 | [diff] [blame] | 83 | void usb_desc_init(USBDevice *dev); |
Gerd Hoffmann | 32d4191 | 2010-12-03 18:07:20 +0100 | [diff] [blame] | 84 | void usb_desc_attach(USBDevice *dev); |
Gerd Hoffmann | 132a3f5 | 2010-11-26 12:25:32 +0100 | [diff] [blame] | 85 | void usb_desc_set_string(USBDevice *dev, uint8_t index, const char *str); |
| 86 | const char *usb_desc_get_string(USBDevice *dev, uint8_t index); |
| 87 | int usb_desc_string(USBDevice *dev, int index, uint8_t *dest, size_t len); |
Gerd Hoffmann | 37fb59d | 2010-11-17 11:03:53 +0100 | [diff] [blame] | 88 | int usb_desc_get_descriptor(USBDevice *dev, int value, uint8_t *dest, size_t len); |
| 89 | int usb_desc_handle_control(USBDevice *dev, int request, int value, |
| 90 | int index, int length, uint8_t *data); |
| 91 | |
| 92 | #endif /* QEMU_HW_USB_DESC_H */ |