1 #ifndef QEMU_HW_USB_DESC_H
2 #define QEMU_HW_USB_DESC_H
6 /* binary representation */
7 typedef struct USBDescriptor
{
9 uint8_t bDescriptorType
;
15 uint8_t bDeviceSubClass
;
16 uint8_t bDeviceProtocol
;
17 uint8_t bMaxPacketSize0
;
24 uint8_t iManufacturer
;
26 uint8_t iSerialNumber
;
27 uint8_t bNumConfigurations
;
33 uint8_t bDeviceSubClass
;
34 uint8_t bDeviceProtocol
;
35 uint8_t bMaxPacketSize0
;
36 uint8_t bNumConfigurations
;
40 uint8_t wTotalLength_lo
;
41 uint8_t wTotalLength_hi
;
42 uint8_t bNumInterfaces
;
43 uint8_t bConfigurationValue
;
44 uint8_t iConfiguration
;
49 uint8_t bInterfaceNumber
;
50 uint8_t bAlternateSetting
;
51 uint8_t bNumEndpoints
;
52 uint8_t bInterfaceClass
;
53 uint8_t bInterfaceSubClass
;
54 uint8_t bInterfaceProtocol
;
58 uint8_t bEndpointAddress
;
60 uint8_t wMaxPacketSize_lo
;
61 uint8_t wMaxPacketSize_hi
;
63 uint8_t bRefresh
; /* only audio ep */
64 uint8_t bSynchAddress
; /* only audio ep */
69 uint8_t wBytesPerInterval_lo
;
70 uint8_t wBytesPerInterval_hi
;
73 uint8_t wTotalLength_lo
;
74 uint8_t wTotalLength_hi
;
75 uint8_t bNumDeviceCaps
;
78 uint8_t bDevCapabilityType
;
81 uint8_t bmAttributes_1
;
82 uint8_t bmAttributes_2
;
83 uint8_t bmAttributes_3
;
84 uint8_t bmAttributes_4
;
88 uint8_t wSpeedsSupported_lo
;
89 uint8_t wSpeedsSupported_hi
;
90 uint8_t bFunctionalitySupport
;
91 uint8_t bU1DevExitLat
;
92 uint8_t wU2DevExitLat_lo
;
93 uint8_t wU2DevExitLat_hi
;
98 } QEMU_PACKED USBDescriptor
;
104 uint8_t iManufacturer
;
106 uint8_t iSerialNumber
;
109 struct USBDescDevice
{
111 uint8_t bDeviceClass
;
112 uint8_t bDeviceSubClass
;
113 uint8_t bDeviceProtocol
;
114 uint8_t bMaxPacketSize0
;
115 uint8_t bNumConfigurations
;
117 const USBDescConfig
*confs
;
120 struct USBDescConfig
{
121 uint8_t bNumInterfaces
;
122 uint8_t bConfigurationValue
;
123 uint8_t iConfiguration
;
124 uint8_t bmAttributes
;
127 /* grouped interfaces */
129 const USBDescIfaceAssoc
*if_groups
;
131 /* "normal" interfaces */
133 const USBDescIface
*ifs
;
136 /* conceptually an Interface Association Descriptor, and releated interfaces */
137 struct USBDescIfaceAssoc
{
138 uint8_t bFirstInterface
;
139 uint8_t bInterfaceCount
;
140 uint8_t bFunctionClass
;
141 uint8_t bFunctionSubClass
;
142 uint8_t bFunctionProtocol
;
146 const USBDescIface
*ifs
;
149 struct USBDescIface
{
150 uint8_t bInterfaceNumber
;
151 uint8_t bAlternateSetting
;
152 uint8_t bNumEndpoints
;
153 uint8_t bInterfaceClass
;
154 uint8_t bInterfaceSubClass
;
155 uint8_t bInterfaceProtocol
;
160 USBDescEndpoint
*eps
;
163 struct USBDescEndpoint
{
164 uint8_t bEndpointAddress
;
165 uint8_t bmAttributes
;
166 uint16_t wMaxPacketSize
;
169 uint8_t bSynchAddress
;
171 uint8_t is_audio
; /* has bRefresh + bSynchAddress */
174 /* superspeed endpoint companion */
176 uint8_t bmAttributes_super
;
177 uint16_t wBytesPerInterval
;
180 struct USBDescOther
{
185 typedef const char *USBDescStrings
[256];
189 const USBDescDevice
*full
;
190 const USBDescDevice
*high
;
191 const USBDescDevice
*super
;
192 const char* const *str
;
195 #define USB_DESC_FLAG_SUPER (1 << 1)
197 /* generate usb packages from structs */
198 int usb_desc_device(const USBDescID
*id
, const USBDescDevice
*dev
,
199 uint8_t *dest
, size_t len
);
200 int usb_desc_device_qualifier(const USBDescDevice
*dev
,
201 uint8_t *dest
, size_t len
);
202 int usb_desc_config(const USBDescConfig
*conf
, int flags
,
203 uint8_t *dest
, size_t len
);
204 int usb_desc_iface_group(const USBDescIfaceAssoc
*iad
, int flags
,
205 uint8_t *dest
, size_t len
);
206 int usb_desc_iface(const USBDescIface
*iface
, int flags
,
207 uint8_t *dest
, size_t len
);
208 int usb_desc_endpoint(const USBDescEndpoint
*ep
, int flags
,
209 uint8_t *dest
, size_t len
);
210 int usb_desc_other(const USBDescOther
*desc
, uint8_t *dest
, size_t len
);
212 /* control message emulation helpers */
213 void usb_desc_init(USBDevice
*dev
);
214 void usb_desc_attach(USBDevice
*dev
);
215 void usb_desc_set_string(USBDevice
*dev
, uint8_t index
, const char *str
);
216 void usb_desc_create_serial(USBDevice
*dev
);
217 const char *usb_desc_get_string(USBDevice
*dev
, uint8_t index
);
218 int usb_desc_string(USBDevice
*dev
, int index
, uint8_t *dest
, size_t len
);
219 int usb_desc_get_descriptor(USBDevice
*dev
, int value
, uint8_t *dest
, size_t len
);
220 int usb_desc_handle_control(USBDevice
*dev
, USBPacket
*p
,
221 int request
, int value
, int index
, int length
, uint8_t *data
);
223 #endif /* QEMU_HW_USB_DESC_H */