root / hw / usb-bt.c @ bf38c1a0
History | View | Annotate | Download (20.3 kB)
1 | e6a6d5ab | balrog | /*
|
---|---|---|---|
2 | e6a6d5ab | balrog | * QEMU Bluetooth HCI USB Transport Layer v1.0
|
3 | e6a6d5ab | balrog | *
|
4 | e6a6d5ab | balrog | * Copyright (C) 2007 OpenMoko, Inc.
|
5 | e6a6d5ab | balrog | * Copyright (C) 2008 Andrzej Zaborowski <balrog@zabor.org>
|
6 | e6a6d5ab | balrog | *
|
7 | e6a6d5ab | balrog | * This program is free software; you can redistribute it and/or
|
8 | e6a6d5ab | balrog | * modify it under the terms of the GNU General Public License as
|
9 | e6a6d5ab | balrog | * published by the Free Software Foundation; either version 2 or
|
10 | e6a6d5ab | balrog | * (at your option) version 3 of the License.
|
11 | e6a6d5ab | balrog | *
|
12 | e6a6d5ab | balrog | * This program is distributed in the hope that it will be useful,
|
13 | e6a6d5ab | balrog | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 | e6a6d5ab | balrog | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 | e6a6d5ab | balrog | * GNU General Public License for more details.
|
16 | e6a6d5ab | balrog | *
|
17 | fad6cb1a | aurel32 | * You should have received a copy of the GNU General Public License along
|
18 | fad6cb1a | aurel32 | * with this program; if not, write to the Free Software Foundation, Inc.,
|
19 | fad6cb1a | aurel32 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
20 | e6a6d5ab | balrog | */
|
21 | e6a6d5ab | balrog | |
22 | e6a6d5ab | balrog | #include "qemu-common.h" |
23 | e6a6d5ab | balrog | #include "usb.h" |
24 | e6a6d5ab | balrog | #include "net.h" |
25 | e6a6d5ab | balrog | #include "bt.h" |
26 | e6a6d5ab | balrog | |
27 | e6a6d5ab | balrog | struct USBBtState {
|
28 | e6a6d5ab | balrog | USBDevice dev; |
29 | e6a6d5ab | balrog | struct HCIInfo *hci;
|
30 | e6a6d5ab | balrog | |
31 | e6a6d5ab | balrog | int altsetting;
|
32 | e6a6d5ab | balrog | int config;
|
33 | e6a6d5ab | balrog | |
34 | e6a6d5ab | balrog | #define CFIFO_LEN_MASK 255 |
35 | e6a6d5ab | balrog | #define DFIFO_LEN_MASK 4095 |
36 | e6a6d5ab | balrog | struct usb_hci_in_fifo_s {
|
37 | e6a6d5ab | balrog | uint8_t data[(DFIFO_LEN_MASK + 1) * 2]; |
38 | e6a6d5ab | balrog | struct {
|
39 | e6a6d5ab | balrog | uint8_t *data; |
40 | e6a6d5ab | balrog | int len;
|
41 | e6a6d5ab | balrog | } fifo[CFIFO_LEN_MASK + 1];
|
42 | e6a6d5ab | balrog | int dstart, dlen, dsize, start, len;
|
43 | e6a6d5ab | balrog | } evt, acl, sco; |
44 | e6a6d5ab | balrog | |
45 | e6a6d5ab | balrog | struct usb_hci_out_fifo_s {
|
46 | e6a6d5ab | balrog | uint8_t data[4096];
|
47 | e6a6d5ab | balrog | int len;
|
48 | e6a6d5ab | balrog | } outcmd, outacl, outsco; |
49 | e6a6d5ab | balrog | }; |
50 | e6a6d5ab | balrog | |
51 | e6a6d5ab | balrog | #define USB_EVT_EP 1 |
52 | e6a6d5ab | balrog | #define USB_ACL_EP 2 |
53 | e6a6d5ab | balrog | #define USB_SCO_EP 3 |
54 | e6a6d5ab | balrog | |
55 | e6a6d5ab | balrog | static const uint8_t qemu_bt_dev_descriptor[] = { |
56 | e6a6d5ab | balrog | 0x12, /* u8 bLength; */ |
57 | e6a6d5ab | balrog | USB_DT_DEVICE, /* u8 bDescriptorType; Device */
|
58 | e6a6d5ab | balrog | 0x10, 0x01, /* u16 bcdUSB; v1.10 */ |
59 | e6a6d5ab | balrog | |
60 | e6a6d5ab | balrog | 0xe0, /* u8 bDeviceClass; Wireless */ |
61 | e6a6d5ab | balrog | 0x01, /* u8 bDeviceSubClass; Radio Frequency */ |
62 | e6a6d5ab | balrog | 0x01, /* u8 bDeviceProtocol; Bluetooth */ |
63 | e6a6d5ab | balrog | 0x40, /* u8 bMaxPacketSize0; 64 Bytes */ |
64 | e6a6d5ab | balrog | |
65 | e6a6d5ab | balrog | 0x12, 0x0a, /* u16 idVendor; */ |
66 | e6a6d5ab | balrog | 0x01, 0x00, /* u16 idProduct; Bluetooth Dongle (HCI mode) */ |
67 | e6a6d5ab | balrog | 0x58, 0x19, /* u16 bcdDevice; (some devices have 0x48, 0x02) */ |
68 | e6a6d5ab | balrog | |
69 | e6a6d5ab | balrog | 0x00, /* u8 iManufacturer; */ |
70 | e6a6d5ab | balrog | 0x00, /* u8 iProduct; */ |
71 | e6a6d5ab | balrog | 0x00, /* u8 iSerialNumber; */ |
72 | e6a6d5ab | balrog | 0x01, /* u8 bNumConfigurations; */ |
73 | e6a6d5ab | balrog | }; |
74 | e6a6d5ab | balrog | |
75 | e6a6d5ab | balrog | static const uint8_t qemu_bt_config_descriptor[] = { |
76 | e6a6d5ab | balrog | /* one configuration */
|
77 | e6a6d5ab | balrog | 0x09, /* u8 bLength; */ |
78 | e6a6d5ab | balrog | USB_DT_CONFIG, /* u8 bDescriptorType; */
|
79 | e6a6d5ab | balrog | 0xb1, 0x00, /* u16 wTotalLength; */ |
80 | e6a6d5ab | balrog | 0x02, /* u8 bNumInterfaces; (2) */ |
81 | e6a6d5ab | balrog | 0x01, /* u8 bConfigurationValue; */ |
82 | e6a6d5ab | balrog | 0x00, /* u8 iConfiguration; */ |
83 | e6a6d5ab | balrog | 0xc0, /* u8 bmAttributes; |
84 | e6a6d5ab | balrog | Bit 7: must be set,
|
85 | e6a6d5ab | balrog | 6: Self-powered,
|
86 | e6a6d5ab | balrog | 5: Remote wakeup,
|
87 | e6a6d5ab | balrog | 4..0: resvd */
|
88 | e6a6d5ab | balrog | 0x00, /* u8 MaxPower; */ |
89 | e6a6d5ab | balrog | |
90 | e6a6d5ab | balrog | /* USB 1.1:
|
91 | e6a6d5ab | balrog | * USB 2.0, single TT organization (mandatory):
|
92 | e6a6d5ab | balrog | * one interface, protocol 0
|
93 | e6a6d5ab | balrog | *
|
94 | e6a6d5ab | balrog | * USB 2.0, multiple TT organization (optional):
|
95 | e6a6d5ab | balrog | * two interfaces, protocols 1 (like single TT)
|
96 | e6a6d5ab | balrog | * and 2 (multiple TT mode) ... config is
|
97 | e6a6d5ab | balrog | * sometimes settable
|
98 | e6a6d5ab | balrog | * NOT IMPLEMENTED
|
99 | e6a6d5ab | balrog | */
|
100 | e6a6d5ab | balrog | |
101 | e6a6d5ab | balrog | /* interface one */
|
102 | e6a6d5ab | balrog | 0x09, /* u8 if_bLength; */ |
103 | e6a6d5ab | balrog | USB_DT_INTERFACE, /* u8 if_bDescriptorType; */
|
104 | e6a6d5ab | balrog | 0x00, /* u8 if_bInterfaceNumber; */ |
105 | e6a6d5ab | balrog | 0x00, /* u8 if_bAlternateSetting; */ |
106 | e6a6d5ab | balrog | 0x03, /* u8 if_bNumEndpoints; */ |
107 | e6a6d5ab | balrog | 0xe0, /* u8 if_bInterfaceClass; Wireless */ |
108 | e6a6d5ab | balrog | 0x01, /* u8 if_bInterfaceSubClass; Radio Frequency */ |
109 | e6a6d5ab | balrog | 0x01, /* u8 if_bInterfaceProtocol; Bluetooth */ |
110 | e6a6d5ab | balrog | 0x00, /* u8 if_iInterface; */ |
111 | e6a6d5ab | balrog | |
112 | e6a6d5ab | balrog | /* endpoint one */
|
113 | e6a6d5ab | balrog | 0x07, /* u8 ep_bLength; */ |
114 | e6a6d5ab | balrog | USB_DT_ENDPOINT, /* u8 ep_bDescriptorType; */
|
115 | e6a6d5ab | balrog | USB_DIR_IN | USB_EVT_EP, /* u8 ep_bEndpointAddress; */
|
116 | e6a6d5ab | balrog | 0x03, /* u8 ep_bmAttributes; Interrupt */ |
117 | e6a6d5ab | balrog | 0x10, 0x00, /* u16 ep_wMaxPacketSize; */ |
118 | e6a6d5ab | balrog | 0x02, /* u8 ep_bInterval; */ |
119 | e6a6d5ab | balrog | |
120 | e6a6d5ab | balrog | /* endpoint two */
|
121 | e6a6d5ab | balrog | 0x07, /* u8 ep_bLength; */ |
122 | e6a6d5ab | balrog | USB_DT_ENDPOINT, /* u8 ep_bDescriptorType; */
|
123 | e6a6d5ab | balrog | USB_DIR_OUT | USB_ACL_EP, /* u8 ep_bEndpointAddress; */
|
124 | e6a6d5ab | balrog | 0x02, /* u8 ep_bmAttributes; Bulk */ |
125 | e6a6d5ab | balrog | 0x40, 0x00, /* u16 ep_wMaxPacketSize; */ |
126 | e6a6d5ab | balrog | 0x0a, /* u8 ep_bInterval; (255ms -- usb 2.0 spec) */ |
127 | e6a6d5ab | balrog | |
128 | e6a6d5ab | balrog | /* endpoint three */
|
129 | e6a6d5ab | balrog | 0x07, /* u8 ep_bLength; */ |
130 | e6a6d5ab | balrog | USB_DT_ENDPOINT, /* u8 ep_bDescriptorType; */
|
131 | e6a6d5ab | balrog | USB_DIR_IN | USB_ACL_EP, /* u8 ep_bEndpointAddress; */
|
132 | e6a6d5ab | balrog | 0x02, /* u8 ep_bmAttributes; Bulk */ |
133 | e6a6d5ab | balrog | 0x40, 0x00, /* u16 ep_wMaxPacketSize; */ |
134 | e6a6d5ab | balrog | 0x0a, /* u8 ep_bInterval; (255ms -- usb 2.0 spec) */ |
135 | e6a6d5ab | balrog | |
136 | e6a6d5ab | balrog | /* interface two setting one */
|
137 | e6a6d5ab | balrog | 0x09, /* u8 if_bLength; */ |
138 | e6a6d5ab | balrog | USB_DT_INTERFACE, /* u8 if_bDescriptorType; */
|
139 | e6a6d5ab | balrog | 0x01, /* u8 if_bInterfaceNumber; */ |
140 | e6a6d5ab | balrog | 0x00, /* u8 if_bAlternateSetting; */ |
141 | e6a6d5ab | balrog | 0x02, /* u8 if_bNumEndpoints; */ |
142 | e6a6d5ab | balrog | 0xe0, /* u8 if_bInterfaceClass; Wireless */ |
143 | e6a6d5ab | balrog | 0x01, /* u8 if_bInterfaceSubClass; Radio Frequency */ |
144 | e6a6d5ab | balrog | 0x01, /* u8 if_bInterfaceProtocol; Bluetooth */ |
145 | e6a6d5ab | balrog | 0x00, /* u8 if_iInterface; */ |
146 | e6a6d5ab | balrog | |
147 | e6a6d5ab | balrog | /* endpoint one */
|
148 | e6a6d5ab | balrog | 0x07, /* u8 ep_bLength; */ |
149 | e6a6d5ab | balrog | USB_DT_ENDPOINT, /* u8 ep_bDescriptorType; */
|
150 | e6a6d5ab | balrog | USB_DIR_OUT | USB_SCO_EP, /* u8 ep_bEndpointAddress; */
|
151 | e6a6d5ab | balrog | 0x01, /* u8 ep_bmAttributes; Isochronous */ |
152 | e6a6d5ab | balrog | 0x00, 0x00, /* u16 ep_wMaxPacketSize; */ |
153 | e6a6d5ab | balrog | 0x01, /* u8 ep_bInterval; (255ms -- usb 2.0 spec) */ |
154 | e6a6d5ab | balrog | |
155 | e6a6d5ab | balrog | /* endpoint two */
|
156 | e6a6d5ab | balrog | 0x07, /* u8 ep_bLength; */ |
157 | e6a6d5ab | balrog | USB_DT_ENDPOINT, /* u8 ep_bDescriptorType; */
|
158 | e6a6d5ab | balrog | USB_DIR_IN | USB_SCO_EP, /* u8 ep_bEndpointAddress; */
|
159 | e6a6d5ab | balrog | 0x01, /* u8 ep_bmAttributes; Isochronous */ |
160 | e6a6d5ab | balrog | 0x00, 0x00, /* u16 ep_wMaxPacketSize; */ |
161 | e6a6d5ab | balrog | 0x01, /* u8 ep_bInterval; (255ms -- usb 2.0 spec) */ |
162 | e6a6d5ab | balrog | |
163 | e6a6d5ab | balrog | /* interface two setting two */
|
164 | e6a6d5ab | balrog | 0x09, /* u8 if_bLength; */ |
165 | e6a6d5ab | balrog | USB_DT_INTERFACE, /* u8 if_bDescriptorType; */
|
166 | e6a6d5ab | balrog | 0x01, /* u8 if_bInterfaceNumber; */ |
167 | e6a6d5ab | balrog | 0x01, /* u8 if_bAlternateSetting; */ |
168 | e6a6d5ab | balrog | 0x02, /* u8 if_bNumEndpoints; */ |
169 | e6a6d5ab | balrog | 0xe0, /* u8 if_bInterfaceClass; Wireless */ |
170 | e6a6d5ab | balrog | 0x01, /* u8 if_bInterfaceSubClass; Radio Frequency */ |
171 | e6a6d5ab | balrog | 0x01, /* u8 if_bInterfaceProtocol; Bluetooth */ |
172 | e6a6d5ab | balrog | 0x00, /* u8 if_iInterface; */ |
173 | e6a6d5ab | balrog | |
174 | e6a6d5ab | balrog | /* endpoint one */
|
175 | e6a6d5ab | balrog | 0x07, /* u8 ep_bLength; */ |
176 | e6a6d5ab | balrog | USB_DT_ENDPOINT, /* u8 ep_bDescriptorType; */
|
177 | e6a6d5ab | balrog | USB_DIR_OUT | USB_SCO_EP, /* u8 ep_bEndpointAddress; */
|
178 | e6a6d5ab | balrog | 0x01, /* u8 ep_bmAttributes; Isochronous */ |
179 | e6a6d5ab | balrog | 0x09, 0x00, /* u16 ep_wMaxPacketSize; */ |
180 | e6a6d5ab | balrog | 0x01, /* u8 ep_bInterval; (255ms -- usb 2.0 spec) */ |
181 | e6a6d5ab | balrog | |
182 | e6a6d5ab | balrog | /* endpoint two */
|
183 | e6a6d5ab | balrog | 0x07, /* u8 ep_bLength; */ |
184 | e6a6d5ab | balrog | USB_DT_ENDPOINT, /* u8 ep_bDescriptorType; */
|
185 | e6a6d5ab | balrog | USB_DIR_IN | USB_SCO_EP, /* u8 ep_bEndpointAddress; */
|
186 | e6a6d5ab | balrog | 0x01, /* u8 ep_bmAttributes; Isochronous */ |
187 | e6a6d5ab | balrog | 0x09, 0x00, /* u16 ep_wMaxPacketSize; */ |
188 | e6a6d5ab | balrog | 0x01, /* u8 ep_bInterval; (255ms -- usb 2.0 spec) */ |
189 | e6a6d5ab | balrog | |
190 | e6a6d5ab | balrog | /* interface two setting three */
|
191 | e6a6d5ab | balrog | 0x09, /* u8 if_bLength; */ |
192 | e6a6d5ab | balrog | USB_DT_INTERFACE, /* u8 if_bDescriptorType; */
|
193 | e6a6d5ab | balrog | 0x01, /* u8 if_bInterfaceNumber; */ |
194 | e6a6d5ab | balrog | 0x02, /* u8 if_bAlternateSetting; */ |
195 | e6a6d5ab | balrog | 0x02, /* u8 if_bNumEndpoints; */ |
196 | e6a6d5ab | balrog | 0xe0, /* u8 if_bInterfaceClass; Wireless */ |
197 | e6a6d5ab | balrog | 0x01, /* u8 if_bInterfaceSubClass; Radio Frequency */ |
198 | e6a6d5ab | balrog | 0x01, /* u8 if_bInterfaceProtocol; Bluetooth */ |
199 | e6a6d5ab | balrog | 0x00, /* u8 if_iInterface; */ |
200 | e6a6d5ab | balrog | |
201 | e6a6d5ab | balrog | /* endpoint one */
|
202 | e6a6d5ab | balrog | 0x07, /* u8 ep_bLength; */ |
203 | e6a6d5ab | balrog | USB_DT_ENDPOINT, /* u8 ep_bDescriptorType; */
|
204 | e6a6d5ab | balrog | USB_DIR_OUT | USB_SCO_EP, /* u8 ep_bEndpointAddress; */
|
205 | e6a6d5ab | balrog | 0x01, /* u8 ep_bmAttributes; Isochronous */ |
206 | e6a6d5ab | balrog | 0x11, 0x00, /* u16 ep_wMaxPacketSize; */ |
207 | e6a6d5ab | balrog | 0x01, /* u8 ep_bInterval; (255ms -- usb 2.0 spec) */ |
208 | e6a6d5ab | balrog | |
209 | e6a6d5ab | balrog | /* endpoint two */
|
210 | e6a6d5ab | balrog | 0x07, /* u8 ep_bLength; */ |
211 | e6a6d5ab | balrog | USB_DT_ENDPOINT, /* u8 ep_bDescriptorType; */
|
212 | e6a6d5ab | balrog | USB_DIR_IN | USB_SCO_EP, /* u8 ep_bEndpointAddress; */
|
213 | e6a6d5ab | balrog | 0x01, /* u8 ep_bmAttributes; Isochronous */ |
214 | e6a6d5ab | balrog | 0x11, 0x00, /* u16 ep_wMaxPacketSize; */ |
215 | e6a6d5ab | balrog | 0x01, /* u8 ep_bInterval; (255ms -- usb 2.0 spec) */ |
216 | e6a6d5ab | balrog | |
217 | e6a6d5ab | balrog | /* interface two setting four */
|
218 | e6a6d5ab | balrog | 0x09, /* u8 if_bLength; */ |
219 | e6a6d5ab | balrog | USB_DT_INTERFACE, /* u8 if_bDescriptorType; */
|
220 | e6a6d5ab | balrog | 0x01, /* u8 if_bInterfaceNumber; */ |
221 | e6a6d5ab | balrog | 0x03, /* u8 if_bAlternateSetting; */ |
222 | e6a6d5ab | balrog | 0x02, /* u8 if_bNumEndpoints; */ |
223 | e6a6d5ab | balrog | 0xe0, /* u8 if_bInterfaceClass; Wireless */ |
224 | e6a6d5ab | balrog | 0x01, /* u8 if_bInterfaceSubClass; Radio Frequency */ |
225 | e6a6d5ab | balrog | 0x01, /* u8 if_bInterfaceProtocol; Bluetooth */ |
226 | e6a6d5ab | balrog | 0x00, /* u8 if_iInterface; */ |
227 | e6a6d5ab | balrog | |
228 | e6a6d5ab | balrog | /* endpoint one */
|
229 | e6a6d5ab | balrog | 0x07, /* u8 ep_bLength; */ |
230 | e6a6d5ab | balrog | USB_DT_ENDPOINT, /* u8 ep_bDescriptorType; */
|
231 | e6a6d5ab | balrog | USB_DIR_OUT | USB_SCO_EP, /* u8 ep_bEndpointAddress; */
|
232 | e6a6d5ab | balrog | 0x01, /* u8 ep_bmAttributes; Isochronous */ |
233 | e6a6d5ab | balrog | 0x19, 0x00, /* u16 ep_wMaxPacketSize; */ |
234 | e6a6d5ab | balrog | 0x01, /* u8 ep_bInterval; (255ms -- usb 2.0 spec) */ |
235 | e6a6d5ab | balrog | |
236 | e6a6d5ab | balrog | /* endpoint two */
|
237 | e6a6d5ab | balrog | 0x07, /* u8 ep_bLength; */ |
238 | e6a6d5ab | balrog | USB_DT_ENDPOINT, /* u8 ep_bDescriptorType; */
|
239 | e6a6d5ab | balrog | USB_DIR_IN | USB_SCO_EP, /* u8 ep_bEndpointAddress; */
|
240 | e6a6d5ab | balrog | 0x01, /* u8 ep_bmAttributes; Isochronous */ |
241 | e6a6d5ab | balrog | 0x19, 0x00, /* u16 ep_wMaxPacketSize; */ |
242 | e6a6d5ab | balrog | 0x01, /* u8 ep_bInterval; (255ms -- usb 2.0 spec) */ |
243 | e6a6d5ab | balrog | |
244 | e6a6d5ab | balrog | /* interface two setting five */
|
245 | e6a6d5ab | balrog | 0x09, /* u8 if_bLength; */ |
246 | e6a6d5ab | balrog | USB_DT_INTERFACE, /* u8 if_bDescriptorType; */
|
247 | e6a6d5ab | balrog | 0x01, /* u8 if_bInterfaceNumber; */ |
248 | e6a6d5ab | balrog | 0x04, /* u8 if_bAlternateSetting; */ |
249 | e6a6d5ab | balrog | 0x02, /* u8 if_bNumEndpoints; */ |
250 | e6a6d5ab | balrog | 0xe0, /* u8 if_bInterfaceClass; Wireless */ |
251 | e6a6d5ab | balrog | 0x01, /* u8 if_bInterfaceSubClass; Radio Frequency */ |
252 | e6a6d5ab | balrog | 0x01, /* u8 if_bInterfaceProtocol; Bluetooth */ |
253 | e6a6d5ab | balrog | 0x00, /* u8 if_iInterface; */ |
254 | e6a6d5ab | balrog | |
255 | e6a6d5ab | balrog | /* endpoint one */
|
256 | e6a6d5ab | balrog | 0x07, /* u8 ep_bLength; */ |
257 | e6a6d5ab | balrog | USB_DT_ENDPOINT, /* u8 ep_bDescriptorType; */
|
258 | e6a6d5ab | balrog | USB_DIR_OUT | USB_SCO_EP, /* u8 ep_bEndpointAddress; */
|
259 | e6a6d5ab | balrog | 0x01, /* u8 ep_bmAttributes; Isochronous */ |
260 | e6a6d5ab | balrog | 0x21, 0x00, /* u16 ep_wMaxPacketSize; */ |
261 | e6a6d5ab | balrog | 0x01, /* u8 ep_bInterval; (255ms -- usb 2.0 spec) */ |
262 | e6a6d5ab | balrog | |
263 | e6a6d5ab | balrog | /* endpoint two */
|
264 | e6a6d5ab | balrog | 0x07, /* u8 ep_bLength; */ |
265 | e6a6d5ab | balrog | USB_DT_ENDPOINT, /* u8 ep_bDescriptorType; */
|
266 | e6a6d5ab | balrog | USB_DIR_IN | USB_SCO_EP, /* u8 ep_bEndpointAddress; */
|
267 | e6a6d5ab | balrog | 0x01, /* u8 ep_bmAttributes; Isochronous */ |
268 | e6a6d5ab | balrog | 0x21, 0x00, /* u16 ep_wMaxPacketSize; */ |
269 | e6a6d5ab | balrog | 0x01, /* u8 ep_bInterval; (255ms -- usb 2.0 spec) */ |
270 | e6a6d5ab | balrog | |
271 | e6a6d5ab | balrog | /* interface two setting six */
|
272 | e6a6d5ab | balrog | 0x09, /* u8 if_bLength; */ |
273 | e6a6d5ab | balrog | USB_DT_INTERFACE, /* u8 if_bDescriptorType; */
|
274 | e6a6d5ab | balrog | 0x01, /* u8 if_bInterfaceNumber; */ |
275 | e6a6d5ab | balrog | 0x05, /* u8 if_bAlternateSetting; */ |
276 | e6a6d5ab | balrog | 0x02, /* u8 if_bNumEndpoints; */ |
277 | e6a6d5ab | balrog | 0xe0, /* u8 if_bInterfaceClass; Wireless */ |
278 | e6a6d5ab | balrog | 0x01, /* u8 if_bInterfaceSubClass; Radio Frequency */ |
279 | e6a6d5ab | balrog | 0x01, /* u8 if_bInterfaceProtocol; Bluetooth */ |
280 | e6a6d5ab | balrog | 0x00, /* u8 if_iInterface; */ |
281 | e6a6d5ab | balrog | |
282 | e6a6d5ab | balrog | /* endpoint one */
|
283 | e6a6d5ab | balrog | 0x07, /* u8 ep_bLength; */ |
284 | e6a6d5ab | balrog | USB_DT_ENDPOINT, /* u8 ep_bDescriptorType; */
|
285 | e6a6d5ab | balrog | USB_DIR_OUT | USB_SCO_EP, /* u8 ep_bEndpointAddress; */
|
286 | e6a6d5ab | balrog | 0x01, /* u8 ep_bmAttributes; Isochronous */ |
287 | e6a6d5ab | balrog | 0x31, 0x00, /* u16 ep_wMaxPacketSize; */ |
288 | e6a6d5ab | balrog | 0x01, /* u8 ep_bInterval; (255ms -- usb 2.0 spec) */ |
289 | e6a6d5ab | balrog | |
290 | e6a6d5ab | balrog | /* endpoint two */
|
291 | e6a6d5ab | balrog | 0x07, /* u8 ep_bLength; */ |
292 | e6a6d5ab | balrog | USB_DT_ENDPOINT, /* u8 ep_bDescriptorType; */
|
293 | e6a6d5ab | balrog | USB_DIR_IN | USB_SCO_EP, /* u8 ep_bEndpointAddress; */
|
294 | e6a6d5ab | balrog | 0x01, /* u8 ep_bmAttributes; Isochronous */ |
295 | e6a6d5ab | balrog | 0x31, 0x00, /* u16 ep_wMaxPacketSize; */ |
296 | e6a6d5ab | balrog | 0x01, /* u8 ep_bInterval; (255ms -- usb 2.0 spec) */ |
297 | e6a6d5ab | balrog | |
298 | e6a6d5ab | balrog | /* If implemented, the DFU interface descriptor goes here with no
|
299 | e6a6d5ab | balrog | * endpoints or alternative settings. */
|
300 | e6a6d5ab | balrog | }; |
301 | e6a6d5ab | balrog | |
302 | e6a6d5ab | balrog | static void usb_bt_fifo_reset(struct usb_hci_in_fifo_s *fifo) |
303 | e6a6d5ab | balrog | { |
304 | e6a6d5ab | balrog | fifo->dstart = 0;
|
305 | e6a6d5ab | balrog | fifo->dlen = 0;
|
306 | e6a6d5ab | balrog | fifo->dsize = DFIFO_LEN_MASK + 1;
|
307 | e6a6d5ab | balrog | fifo->start = 0;
|
308 | e6a6d5ab | balrog | fifo->len = 0;
|
309 | e6a6d5ab | balrog | } |
310 | e6a6d5ab | balrog | |
311 | e6a6d5ab | balrog | static void usb_bt_fifo_enqueue(struct usb_hci_in_fifo_s *fifo, |
312 | e6a6d5ab | balrog | const uint8_t *data, int len) |
313 | e6a6d5ab | balrog | { |
314 | e6a6d5ab | balrog | int off = fifo->dstart + fifo->dlen;
|
315 | e6a6d5ab | balrog | uint8_t *buf; |
316 | e6a6d5ab | balrog | |
317 | e6a6d5ab | balrog | fifo->dlen += len; |
318 | e6a6d5ab | balrog | if (off <= DFIFO_LEN_MASK) {
|
319 | e6a6d5ab | balrog | if (off + len > DFIFO_LEN_MASK + 1 && |
320 | e6a6d5ab | balrog | (fifo->dsize = off + len) > (DFIFO_LEN_MASK + 1) * 2) { |
321 | e6a6d5ab | balrog | fprintf(stderr, "%s: can't alloc %i bytes\n", __FUNCTION__, len);
|
322 | e6a6d5ab | balrog | exit(-1);
|
323 | e6a6d5ab | balrog | } |
324 | e6a6d5ab | balrog | buf = fifo->data + off; |
325 | e6a6d5ab | balrog | } else {
|
326 | e6a6d5ab | balrog | if (fifo->dlen > fifo->dsize) {
|
327 | e6a6d5ab | balrog | fprintf(stderr, "%s: can't alloc %i bytes\n", __FUNCTION__, len);
|
328 | e6a6d5ab | balrog | exit(-1);
|
329 | e6a6d5ab | balrog | } |
330 | e6a6d5ab | balrog | buf = fifo->data + off - fifo->dsize; |
331 | e6a6d5ab | balrog | } |
332 | e6a6d5ab | balrog | |
333 | e6a6d5ab | balrog | off = (fifo->start + fifo->len ++) & CFIFO_LEN_MASK; |
334 | e6a6d5ab | balrog | fifo->fifo[off].data = memcpy(buf, data, len); |
335 | e6a6d5ab | balrog | fifo->fifo[off].len = len; |
336 | e6a6d5ab | balrog | } |
337 | e6a6d5ab | balrog | |
338 | e6a6d5ab | balrog | static inline int usb_bt_fifo_dequeue(struct usb_hci_in_fifo_s *fifo, |
339 | e6a6d5ab | balrog | USBPacket *p) |
340 | e6a6d5ab | balrog | { |
341 | e6a6d5ab | balrog | int len;
|
342 | e6a6d5ab | balrog | |
343 | e6a6d5ab | balrog | if (likely(!fifo->len))
|
344 | e6a6d5ab | balrog | return USB_RET_STALL;
|
345 | e6a6d5ab | balrog | |
346 | e6a6d5ab | balrog | len = MIN(p->len, fifo->fifo[fifo->start].len); |
347 | e6a6d5ab | balrog | memcpy(p->data, fifo->fifo[fifo->start].data, len); |
348 | e6a6d5ab | balrog | if (len == p->len) {
|
349 | e6a6d5ab | balrog | fifo->fifo[fifo->start].len -= len; |
350 | e6a6d5ab | balrog | fifo->fifo[fifo->start].data += len; |
351 | e6a6d5ab | balrog | } else {
|
352 | e6a6d5ab | balrog | fifo->start ++; |
353 | e6a6d5ab | balrog | fifo->start &= CFIFO_LEN_MASK; |
354 | e6a6d5ab | balrog | fifo->len --; |
355 | e6a6d5ab | balrog | } |
356 | e6a6d5ab | balrog | |
357 | e6a6d5ab | balrog | fifo->dstart += len; |
358 | e6a6d5ab | balrog | fifo->dlen -= len; |
359 | e6a6d5ab | balrog | if (fifo->dstart >= fifo->dsize) {
|
360 | e6a6d5ab | balrog | fifo->dstart = 0;
|
361 | e6a6d5ab | balrog | fifo->dsize = DFIFO_LEN_MASK + 1;
|
362 | e6a6d5ab | balrog | } |
363 | e6a6d5ab | balrog | |
364 | e6a6d5ab | balrog | return len;
|
365 | e6a6d5ab | balrog | } |
366 | e6a6d5ab | balrog | |
367 | e6a6d5ab | balrog | static void inline usb_bt_fifo_out_enqueue(struct USBBtState *s, |
368 | e6a6d5ab | balrog | struct usb_hci_out_fifo_s *fifo,
|
369 | e6a6d5ab | balrog | void (*send)(struct HCIInfo *, const uint8_t *, int), |
370 | e6a6d5ab | balrog | int (*complete)(const uint8_t *, int), |
371 | e6a6d5ab | balrog | const uint8_t *data, int len) |
372 | e6a6d5ab | balrog | { |
373 | e6a6d5ab | balrog | if (fifo->len) {
|
374 | e6a6d5ab | balrog | memcpy(fifo->data + fifo->len, data, len); |
375 | e6a6d5ab | balrog | fifo->len += len; |
376 | e6a6d5ab | balrog | if (complete(fifo->data, fifo->len)) {
|
377 | e6a6d5ab | balrog | send(s->hci, fifo->data, fifo->len); |
378 | e6a6d5ab | balrog | fifo->len = 0;
|
379 | e6a6d5ab | balrog | } |
380 | e6a6d5ab | balrog | } else if (complete(data, len)) |
381 | e6a6d5ab | balrog | send(s->hci, data, len); |
382 | e6a6d5ab | balrog | else {
|
383 | e6a6d5ab | balrog | memcpy(fifo->data, data, len); |
384 | e6a6d5ab | balrog | fifo->len = len; |
385 | e6a6d5ab | balrog | } |
386 | e6a6d5ab | balrog | |
387 | e6a6d5ab | balrog | /* TODO: do we need to loop? */
|
388 | e6a6d5ab | balrog | } |
389 | e6a6d5ab | balrog | |
390 | e6a6d5ab | balrog | static int usb_bt_hci_cmd_complete(const uint8_t *data, int len) |
391 | e6a6d5ab | balrog | { |
392 | e6a6d5ab | balrog | len -= HCI_COMMAND_HDR_SIZE; |
393 | e6a6d5ab | balrog | return len >= 0 && |
394 | e6a6d5ab | balrog | len >= ((struct hci_command_hdr *) data)->plen;
|
395 | e6a6d5ab | balrog | } |
396 | e6a6d5ab | balrog | |
397 | e6a6d5ab | balrog | static int usb_bt_hci_acl_complete(const uint8_t *data, int len) |
398 | e6a6d5ab | balrog | { |
399 | e6a6d5ab | balrog | len -= HCI_ACL_HDR_SIZE; |
400 | e6a6d5ab | balrog | return len >= 0 && |
401 | e6a6d5ab | balrog | len >= le16_to_cpu(((struct hci_acl_hdr *) data)->dlen);
|
402 | e6a6d5ab | balrog | } |
403 | e6a6d5ab | balrog | |
404 | e6a6d5ab | balrog | static int usb_bt_hci_sco_complete(const uint8_t *data, int len) |
405 | e6a6d5ab | balrog | { |
406 | e6a6d5ab | balrog | len -= HCI_SCO_HDR_SIZE; |
407 | e6a6d5ab | balrog | return len >= 0 && |
408 | e6a6d5ab | balrog | len >= ((struct hci_sco_hdr *) data)->dlen;
|
409 | e6a6d5ab | balrog | } |
410 | e6a6d5ab | balrog | |
411 | e6a6d5ab | balrog | static void usb_bt_handle_reset(USBDevice *dev) |
412 | e6a6d5ab | balrog | { |
413 | e6a6d5ab | balrog | struct USBBtState *s = (struct USBBtState *) dev->opaque; |
414 | e6a6d5ab | balrog | |
415 | e6a6d5ab | balrog | usb_bt_fifo_reset(&s->evt); |
416 | e6a6d5ab | balrog | usb_bt_fifo_reset(&s->acl); |
417 | e6a6d5ab | balrog | usb_bt_fifo_reset(&s->sco); |
418 | e6a6d5ab | balrog | s->outcmd.len = 0;
|
419 | e6a6d5ab | balrog | s->outacl.len = 0;
|
420 | e6a6d5ab | balrog | s->outsco.len = 0;
|
421 | e6a6d5ab | balrog | s->altsetting = 0;
|
422 | e6a6d5ab | balrog | } |
423 | e6a6d5ab | balrog | |
424 | e6a6d5ab | balrog | static int usb_bt_handle_control(USBDevice *dev, int request, int value, |
425 | e6a6d5ab | balrog | int index, int length, uint8_t *data) |
426 | e6a6d5ab | balrog | { |
427 | e6a6d5ab | balrog | struct USBBtState *s = (struct USBBtState *) dev->opaque; |
428 | e6a6d5ab | balrog | int ret = 0; |
429 | e6a6d5ab | balrog | |
430 | e6a6d5ab | balrog | switch (request) {
|
431 | e6a6d5ab | balrog | case DeviceRequest | USB_REQ_GET_STATUS:
|
432 | e6a6d5ab | balrog | case InterfaceRequest | USB_REQ_GET_STATUS:
|
433 | e6a6d5ab | balrog | case EndpointRequest | USB_REQ_GET_STATUS:
|
434 | e6a6d5ab | balrog | data[0] = (1 << USB_DEVICE_SELF_POWERED) | |
435 | e6a6d5ab | balrog | (dev->remote_wakeup << USB_DEVICE_REMOTE_WAKEUP); |
436 | e6a6d5ab | balrog | data[1] = 0x00; |
437 | e6a6d5ab | balrog | ret = 2;
|
438 | e6a6d5ab | balrog | break;
|
439 | e6a6d5ab | balrog | case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
|
440 | e6a6d5ab | balrog | case InterfaceOutRequest | USB_REQ_CLEAR_FEATURE:
|
441 | e6a6d5ab | balrog | case EndpointOutRequest | USB_REQ_CLEAR_FEATURE:
|
442 | e6a6d5ab | balrog | if (value == USB_DEVICE_REMOTE_WAKEUP) {
|
443 | e6a6d5ab | balrog | dev->remote_wakeup = 0;
|
444 | e6a6d5ab | balrog | } else {
|
445 | e6a6d5ab | balrog | goto fail;
|
446 | e6a6d5ab | balrog | } |
447 | e6a6d5ab | balrog | ret = 0;
|
448 | e6a6d5ab | balrog | break;
|
449 | e6a6d5ab | balrog | case DeviceOutRequest | USB_REQ_SET_FEATURE:
|
450 | e6a6d5ab | balrog | case InterfaceOutRequest | USB_REQ_SET_FEATURE:
|
451 | e6a6d5ab | balrog | case EndpointOutRequest | USB_REQ_SET_FEATURE:
|
452 | e6a6d5ab | balrog | if (value == USB_DEVICE_REMOTE_WAKEUP) {
|
453 | e6a6d5ab | balrog | dev->remote_wakeup = 1;
|
454 | e6a6d5ab | balrog | } else {
|
455 | e6a6d5ab | balrog | goto fail;
|
456 | e6a6d5ab | balrog | } |
457 | e6a6d5ab | balrog | ret = 0;
|
458 | e6a6d5ab | balrog | break;
|
459 | e6a6d5ab | balrog | case DeviceOutRequest | USB_REQ_SET_ADDRESS:
|
460 | e6a6d5ab | balrog | dev->addr = value; |
461 | e6a6d5ab | balrog | ret = 0;
|
462 | e6a6d5ab | balrog | break;
|
463 | e6a6d5ab | balrog | case DeviceRequest | USB_REQ_GET_DESCRIPTOR:
|
464 | e6a6d5ab | balrog | switch (value >> 8) { |
465 | e6a6d5ab | balrog | case USB_DT_DEVICE:
|
466 | e6a6d5ab | balrog | ret = sizeof(qemu_bt_dev_descriptor);
|
467 | e6a6d5ab | balrog | memcpy(data, qemu_bt_dev_descriptor, ret); |
468 | e6a6d5ab | balrog | break;
|
469 | e6a6d5ab | balrog | case USB_DT_CONFIG:
|
470 | e6a6d5ab | balrog | ret = sizeof(qemu_bt_config_descriptor);
|
471 | e6a6d5ab | balrog | memcpy(data, qemu_bt_config_descriptor, ret); |
472 | e6a6d5ab | balrog | break;
|
473 | e6a6d5ab | balrog | case USB_DT_STRING:
|
474 | e6a6d5ab | balrog | switch(value & 0xff) { |
475 | e6a6d5ab | balrog | case 0: |
476 | e6a6d5ab | balrog | /* language ids */
|
477 | e6a6d5ab | balrog | data[0] = 4; |
478 | e6a6d5ab | balrog | data[1] = 3; |
479 | e6a6d5ab | balrog | data[2] = 0x09; |
480 | e6a6d5ab | balrog | data[3] = 0x04; |
481 | e6a6d5ab | balrog | ret = 4;
|
482 | e6a6d5ab | balrog | break;
|
483 | e6a6d5ab | balrog | default:
|
484 | e6a6d5ab | balrog | goto fail;
|
485 | e6a6d5ab | balrog | } |
486 | e6a6d5ab | balrog | break;
|
487 | e6a6d5ab | balrog | default:
|
488 | e6a6d5ab | balrog | goto fail;
|
489 | e6a6d5ab | balrog | } |
490 | e6a6d5ab | balrog | break;
|
491 | e6a6d5ab | balrog | case DeviceRequest | USB_REQ_GET_CONFIGURATION:
|
492 | e6a6d5ab | balrog | data[0] = qemu_bt_config_descriptor[0x5]; |
493 | e6a6d5ab | balrog | ret = 1;
|
494 | e6a6d5ab | balrog | s->config = 0;
|
495 | e6a6d5ab | balrog | break;
|
496 | e6a6d5ab | balrog | case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:
|
497 | e6a6d5ab | balrog | ret = 0;
|
498 | e6a6d5ab | balrog | if (value != qemu_bt_config_descriptor[0x5] && value != 0) { |
499 | e6a6d5ab | balrog | printf("%s: Wrong SET_CONFIGURATION request (%i)\n",
|
500 | e6a6d5ab | balrog | __FUNCTION__, value); |
501 | e6a6d5ab | balrog | goto fail;
|
502 | e6a6d5ab | balrog | } |
503 | e6a6d5ab | balrog | s->config = 1;
|
504 | e6a6d5ab | balrog | usb_bt_fifo_reset(&s->evt); |
505 | e6a6d5ab | balrog | usb_bt_fifo_reset(&s->acl); |
506 | e6a6d5ab | balrog | usb_bt_fifo_reset(&s->sco); |
507 | e6a6d5ab | balrog | break;
|
508 | e6a6d5ab | balrog | case InterfaceRequest | USB_REQ_GET_INTERFACE:
|
509 | e6a6d5ab | balrog | if (value != 0 || (index & ~1) || length != 1) |
510 | e6a6d5ab | balrog | goto fail;
|
511 | e6a6d5ab | balrog | if (index == 1) |
512 | e6a6d5ab | balrog | data[0] = s->altsetting;
|
513 | e6a6d5ab | balrog | else
|
514 | e6a6d5ab | balrog | data[0] = 0; |
515 | e6a6d5ab | balrog | ret = 1;
|
516 | e6a6d5ab | balrog | break;
|
517 | e6a6d5ab | balrog | case InterfaceOutRequest | USB_REQ_SET_INTERFACE:
|
518 | e6a6d5ab | balrog | if ((index & ~1) || length != 0 || |
519 | e6a6d5ab | balrog | (index == 1 && (value < 0 || value > 4)) || |
520 | e6a6d5ab | balrog | (index == 0 && value != 0)) { |
521 | e6a6d5ab | balrog | printf("%s: Wrong SET_INTERFACE request (%i, %i)\n",
|
522 | e6a6d5ab | balrog | __FUNCTION__, index, value); |
523 | e6a6d5ab | balrog | goto fail;
|
524 | e6a6d5ab | balrog | } |
525 | e6a6d5ab | balrog | s->altsetting = value; |
526 | e6a6d5ab | balrog | ret = 0;
|
527 | e6a6d5ab | balrog | break;
|
528 | e6a6d5ab | balrog | case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_DEVICE) << 8): |
529 | e6a6d5ab | balrog | if (s->config)
|
530 | e6a6d5ab | balrog | usb_bt_fifo_out_enqueue(s, &s->outcmd, s->hci->cmd_send, |
531 | e6a6d5ab | balrog | usb_bt_hci_cmd_complete, data, length); |
532 | e6a6d5ab | balrog | break;
|
533 | e6a6d5ab | balrog | default:
|
534 | e6a6d5ab | balrog | fail:
|
535 | e6a6d5ab | balrog | ret = USB_RET_STALL; |
536 | e6a6d5ab | balrog | break;
|
537 | e6a6d5ab | balrog | } |
538 | e6a6d5ab | balrog | return ret;
|
539 | e6a6d5ab | balrog | } |
540 | e6a6d5ab | balrog | |
541 | e6a6d5ab | balrog | static int usb_bt_handle_data(USBDevice *dev, USBPacket *p) |
542 | e6a6d5ab | balrog | { |
543 | e6a6d5ab | balrog | struct USBBtState *s = (struct USBBtState *) dev->opaque; |
544 | e6a6d5ab | balrog | int ret = 0; |
545 | e6a6d5ab | balrog | |
546 | e6a6d5ab | balrog | if (!s->config)
|
547 | e6a6d5ab | balrog | goto fail;
|
548 | e6a6d5ab | balrog | |
549 | e6a6d5ab | balrog | switch (p->pid) {
|
550 | e6a6d5ab | balrog | case USB_TOKEN_IN:
|
551 | e6a6d5ab | balrog | switch (p->devep & 0xf) { |
552 | e6a6d5ab | balrog | case USB_EVT_EP:
|
553 | e6a6d5ab | balrog | ret = usb_bt_fifo_dequeue(&s->evt, p); |
554 | e6a6d5ab | balrog | break;
|
555 | e6a6d5ab | balrog | |
556 | e6a6d5ab | balrog | case USB_ACL_EP:
|
557 | e6a6d5ab | balrog | ret = usb_bt_fifo_dequeue(&s->acl, p); |
558 | e6a6d5ab | balrog | break;
|
559 | e6a6d5ab | balrog | |
560 | e6a6d5ab | balrog | case USB_SCO_EP:
|
561 | e6a6d5ab | balrog | ret = usb_bt_fifo_dequeue(&s->sco, p); |
562 | e6a6d5ab | balrog | break;
|
563 | e6a6d5ab | balrog | |
564 | e6a6d5ab | balrog | default:
|
565 | e6a6d5ab | balrog | goto fail;
|
566 | e6a6d5ab | balrog | } |
567 | e6a6d5ab | balrog | break;
|
568 | e6a6d5ab | balrog | |
569 | e6a6d5ab | balrog | case USB_TOKEN_OUT:
|
570 | e6a6d5ab | balrog | switch (p->devep & 0xf) { |
571 | e6a6d5ab | balrog | case USB_ACL_EP:
|
572 | e6a6d5ab | balrog | usb_bt_fifo_out_enqueue(s, &s->outacl, s->hci->acl_send, |
573 | e6a6d5ab | balrog | usb_bt_hci_acl_complete, p->data, p->len); |
574 | e6a6d5ab | balrog | break;
|
575 | e6a6d5ab | balrog | |
576 | e6a6d5ab | balrog | case USB_SCO_EP:
|
577 | e6a6d5ab | balrog | usb_bt_fifo_out_enqueue(s, &s->outsco, s->hci->sco_send, |
578 | e6a6d5ab | balrog | usb_bt_hci_sco_complete, p->data, p->len); |
579 | e6a6d5ab | balrog | break;
|
580 | e6a6d5ab | balrog | |
581 | e6a6d5ab | balrog | default:
|
582 | e6a6d5ab | balrog | goto fail;
|
583 | e6a6d5ab | balrog | } |
584 | e6a6d5ab | balrog | break;
|
585 | e6a6d5ab | balrog | |
586 | e6a6d5ab | balrog | default:
|
587 | e6a6d5ab | balrog | fail:
|
588 | e6a6d5ab | balrog | ret = USB_RET_STALL; |
589 | e6a6d5ab | balrog | break;
|
590 | e6a6d5ab | balrog | } |
591 | e6a6d5ab | balrog | |
592 | e6a6d5ab | balrog | return ret;
|
593 | e6a6d5ab | balrog | } |
594 | e6a6d5ab | balrog | |
595 | e6a6d5ab | balrog | static void usb_bt_out_hci_packet_event(void *opaque, |
596 | e6a6d5ab | balrog | const uint8_t *data, int len) |
597 | e6a6d5ab | balrog | { |
598 | e6a6d5ab | balrog | struct USBBtState *s = (struct USBBtState *) opaque; |
599 | e6a6d5ab | balrog | |
600 | e6a6d5ab | balrog | usb_bt_fifo_enqueue(&s->evt, data, len); |
601 | e6a6d5ab | balrog | } |
602 | e6a6d5ab | balrog | |
603 | e6a6d5ab | balrog | static void usb_bt_out_hci_packet_acl(void *opaque, |
604 | e6a6d5ab | balrog | const uint8_t *data, int len) |
605 | e6a6d5ab | balrog | { |
606 | e6a6d5ab | balrog | struct USBBtState *s = (struct USBBtState *) opaque; |
607 | e6a6d5ab | balrog | |
608 | e6a6d5ab | balrog | usb_bt_fifo_enqueue(&s->acl, data, len); |
609 | e6a6d5ab | balrog | } |
610 | e6a6d5ab | balrog | |
611 | e6a6d5ab | balrog | static void usb_bt_handle_destroy(USBDevice *dev) |
612 | e6a6d5ab | balrog | { |
613 | e6a6d5ab | balrog | struct USBBtState *s = (struct USBBtState *) dev->opaque; |
614 | e6a6d5ab | balrog | |
615 | e6a6d5ab | balrog | s->hci->opaque = 0;
|
616 | e6a6d5ab | balrog | s->hci->evt_recv = 0;
|
617 | e6a6d5ab | balrog | s->hci->acl_recv = 0;
|
618 | e6a6d5ab | balrog | qemu_free(s); |
619 | e6a6d5ab | balrog | } |
620 | e6a6d5ab | balrog | |
621 | e6a6d5ab | balrog | USBDevice *usb_bt_init(HCIInfo *hci) |
622 | e6a6d5ab | balrog | { |
623 | e6a6d5ab | balrog | struct USBBtState *s;
|
624 | e6a6d5ab | balrog | |
625 | 2d564691 | balrog | if (!hci)
|
626 | 2d564691 | balrog | return NULL; |
627 | e6a6d5ab | balrog | s = qemu_mallocz(sizeof(struct USBBtState)); |
628 | e6a6d5ab | balrog | if (!s)
|
629 | e6a6d5ab | balrog | return NULL; |
630 | e6a6d5ab | balrog | s->dev.opaque = s; |
631 | e6a6d5ab | balrog | s->dev.speed = USB_SPEED_HIGH; |
632 | e6a6d5ab | balrog | s->dev.handle_packet = usb_generic_handle_packet; |
633 | e6a6d5ab | balrog | pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU BT dongle"); |
634 | e6a6d5ab | balrog | |
635 | e6a6d5ab | balrog | s->dev.handle_reset = usb_bt_handle_reset; |
636 | e6a6d5ab | balrog | s->dev.handle_control = usb_bt_handle_control; |
637 | e6a6d5ab | balrog | s->dev.handle_data = usb_bt_handle_data; |
638 | e6a6d5ab | balrog | s->dev.handle_destroy = usb_bt_handle_destroy; |
639 | e6a6d5ab | balrog | |
640 | e6a6d5ab | balrog | s->hci = hci; |
641 | e6a6d5ab | balrog | s->hci->opaque = s; |
642 | e6a6d5ab | balrog | s->hci->evt_recv = usb_bt_out_hci_packet_event; |
643 | e6a6d5ab | balrog | s->hci->acl_recv = usb_bt_out_hci_packet_acl; |
644 | e6a6d5ab | balrog | |
645 | e6a6d5ab | balrog | usb_bt_handle_reset(&s->dev); |
646 | e6a6d5ab | balrog | |
647 | e6a6d5ab | balrog | return &s->dev;
|
648 | e6a6d5ab | balrog | } |