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 */
67 } QEMU_PACKED USBDescriptor
;
73 uint8_t iManufacturer
;
75 uint8_t iSerialNumber
;
78 struct USBDescDevice
{
81 uint8_t bDeviceSubClass
;
82 uint8_t bDeviceProtocol
;
83 uint8_t bMaxPacketSize0
;
84 uint8_t bNumConfigurations
;
86 const USBDescConfig
*confs
;
89 struct USBDescConfig
{
90 uint8_t bNumInterfaces
;
91 uint8_t bConfigurationValue
;
92 uint8_t iConfiguration
;
96 /* grouped interfaces */
98 const USBDescIfaceAssoc
*if_groups
;
100 /* "normal" interfaces */
102 const USBDescIface
*ifs
;
105 /* conceptually an Interface Association Descriptor, and releated interfaces */
106 struct USBDescIfaceAssoc
{
107 uint8_t bFirstInterface
;
108 uint8_t bInterfaceCount
;
109 uint8_t bFunctionClass
;
110 uint8_t bFunctionSubClass
;
111 uint8_t bFunctionProtocol
;
115 const USBDescIface
*ifs
;
118 struct USBDescIface
{
119 uint8_t bInterfaceNumber
;
120 uint8_t bAlternateSetting
;
121 uint8_t bNumEndpoints
;
122 uint8_t bInterfaceClass
;
123 uint8_t bInterfaceSubClass
;
124 uint8_t bInterfaceProtocol
;
129 USBDescEndpoint
*eps
;
132 struct USBDescEndpoint
{
133 uint8_t bEndpointAddress
;
134 uint8_t bmAttributes
;
135 uint16_t wMaxPacketSize
;
138 uint8_t bSynchAddress
;
140 uint8_t is_audio
; /* has bRefresh + bSynchAddress */
144 struct USBDescOther
{
149 typedef const char *USBDescStrings
[256];
153 const USBDescDevice
*full
;
154 const USBDescDevice
*high
;
155 const char* const *str
;
158 /* generate usb packages from structs */
159 int usb_desc_device(const USBDescID
*id
, const USBDescDevice
*dev
,
160 uint8_t *dest
, size_t len
);
161 int usb_desc_device_qualifier(const USBDescDevice
*dev
,
162 uint8_t *dest
, size_t len
);
163 int usb_desc_config(const USBDescConfig
*conf
, uint8_t *dest
, size_t len
);
164 int usb_desc_iface_group(const USBDescIfaceAssoc
*iad
, uint8_t *dest
,
166 int usb_desc_iface(const USBDescIface
*iface
, uint8_t *dest
, size_t len
);
167 int usb_desc_endpoint(const USBDescEndpoint
*ep
, uint8_t *dest
, size_t len
);
168 int usb_desc_other(const USBDescOther
*desc
, uint8_t *dest
, size_t len
);
170 /* control message emulation helpers */
171 void usb_desc_init(USBDevice
*dev
);
172 void usb_desc_attach(USBDevice
*dev
);
173 void usb_desc_set_string(USBDevice
*dev
, uint8_t index
, const char *str
);
174 void usb_desc_create_serial(USBDevice
*dev
);
175 const char *usb_desc_get_string(USBDevice
*dev
, uint8_t index
);
176 int usb_desc_string(USBDevice
*dev
, int index
, uint8_t *dest
, size_t len
);
177 int usb_desc_get_descriptor(USBDevice
*dev
, int value
, uint8_t *dest
, size_t len
);
178 int usb_desc_handle_control(USBDevice
*dev
, USBPacket
*p
,
179 int request
, int value
, int index
, int length
, uint8_t *data
);
181 #endif /* QEMU_HW_USB_DESC_H */