linux-user: stack_base is now mandatory on all targets
[qemu.git] / hw / usb-desc.h
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 /* grouped interfaces */
34 uint8_t nif_groups;
35 const USBDescIfaceAssoc *if_groups;
36
37 /* "normal" interfaces */
38 uint8_t nif;
39 const USBDescIface *ifs;
40 };
41
42 /* conceptually an Interface Association Descriptor, and releated interfaces */
43 struct USBDescIfaceAssoc {
44 uint8_t bFirstInterface;
45 uint8_t bInterfaceCount;
46 uint8_t bFunctionClass;
47 uint8_t bFunctionSubClass;
48 uint8_t bFunctionProtocol;
49 uint8_t iFunction;
50
51 uint8_t nif;
52 const USBDescIface *ifs;
53 };
54
55 struct USBDescIface {
56 uint8_t bInterfaceNumber;
57 uint8_t bAlternateSetting;
58 uint8_t bNumEndpoints;
59 uint8_t bInterfaceClass;
60 uint8_t bInterfaceSubClass;
61 uint8_t bInterfaceProtocol;
62 uint8_t iInterface;
63
64 uint8_t ndesc;
65 USBDescOther *descs;
66 USBDescEndpoint *eps;
67 };
68
69 struct USBDescEndpoint {
70 uint8_t bEndpointAddress;
71 uint8_t bmAttributes;
72 uint16_t wMaxPacketSize;
73 uint8_t bInterval;
74 uint8_t bRefresh;
75 uint8_t bSynchAddress;
76
77 uint8_t is_audio; /* has bRefresh + bSynchAddress */
78 uint8_t *extra;
79 };
80
81 struct USBDescOther {
82 uint8_t length;
83 const uint8_t *data;
84 };
85
86 typedef const char *USBDescStrings[256];
87
88 struct USBDesc {
89 USBDescID id;
90 const USBDescDevice *full;
91 const USBDescDevice *high;
92 const char* const *str;
93 };
94
95 /* generate usb packages from structs */
96 int usb_desc_device(const USBDescID *id, const USBDescDevice *dev,
97 uint8_t *dest, size_t len);
98 int usb_desc_device_qualifier(const USBDescDevice *dev,
99 uint8_t *dest, size_t len);
100 int usb_desc_config(const USBDescConfig *conf, uint8_t *dest, size_t len);
101 int usb_desc_iface_group(const USBDescIfaceAssoc *iad, uint8_t *dest,
102 size_t len);
103 int usb_desc_iface(const USBDescIface *iface, uint8_t *dest, size_t len);
104 int usb_desc_endpoint(const USBDescEndpoint *ep, uint8_t *dest, size_t len);
105 int usb_desc_other(const USBDescOther *desc, uint8_t *dest, size_t len);
106
107 /* control message emulation helpers */
108 void usb_desc_init(USBDevice *dev);
109 void usb_desc_attach(USBDevice *dev);
110 void usb_desc_set_string(USBDevice *dev, uint8_t index, const char *str);
111 const char *usb_desc_get_string(USBDevice *dev, uint8_t index);
112 int usb_desc_string(USBDevice *dev, int index, uint8_t *dest, size_t len);
113 int usb_desc_get_descriptor(USBDevice *dev, int value, uint8_t *dest, size_t len);
114 int usb_desc_handle_control(USBDevice *dev, USBPacket *p,
115 int request, int value, int index, int length, uint8_t *data);
116
117 #endif /* QEMU_HW_USB_DESC_H */