]>
Commit | Line | Data |
---|---|---|
e6a6d5ab AZ |
1 | /* |
2 | * QEMU Bluetooth HCI USB Transport Layer v1.0 | |
3 | * | |
4 | * Copyright (C) 2007 OpenMoko, Inc. | |
5 | * Copyright (C) 2008 Andrzej Zaborowski <[email protected]> | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or | |
8 | * modify it under the terms of the GNU General Public License as | |
9 | * published by the Free Software Foundation; either version 2 or | |
10 | * (at your option) version 3 of the License. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
fad6cb1a | 17 | * You should have received a copy of the GNU General Public License along |
8167ee88 | 18 | * with this program; if not, see <http://www.gnu.org/licenses/>. |
e6a6d5ab AZ |
19 | */ |
20 | ||
21 | #include "qemu-common.h" | |
22 | #include "usb.h" | |
4696425c | 23 | #include "usb-desc.h" |
e6a6d5ab AZ |
24 | #include "net.h" |
25 | #include "bt.h" | |
26 | ||
27 | struct USBBtState { | |
28 | USBDevice dev; | |
29 | struct HCIInfo *hci; | |
30 | ||
31 | int altsetting; | |
32 | int config; | |
33 | ||
34 | #define CFIFO_LEN_MASK 255 | |
35 | #define DFIFO_LEN_MASK 4095 | |
36 | struct usb_hci_in_fifo_s { | |
37 | uint8_t data[(DFIFO_LEN_MASK + 1) * 2]; | |
38 | struct { | |
39 | uint8_t *data; | |
40 | int len; | |
41 | } fifo[CFIFO_LEN_MASK + 1]; | |
42 | int dstart, dlen, dsize, start, len; | |
43 | } evt, acl, sco; | |
44 | ||
45 | struct usb_hci_out_fifo_s { | |
46 | uint8_t data[4096]; | |
47 | int len; | |
48 | } outcmd, outacl, outsco; | |
49 | }; | |
50 | ||
51 | #define USB_EVT_EP 1 | |
52 | #define USB_ACL_EP 2 | |
53 | #define USB_SCO_EP 3 | |
54 | ||
4696425c GH |
55 | enum { |
56 | STR_MANUFACTURER = 1, | |
57 | STR_SERIALNUMBER, | |
58 | }; | |
e6a6d5ab | 59 | |
4696425c GH |
60 | static const USBDescStrings desc_strings = { |
61 | [STR_MANUFACTURER] = "QEMU " QEMU_VERSION, | |
62 | [STR_SERIALNUMBER] = "1", | |
63 | }; | |
e6a6d5ab | 64 | |
4696425c GH |
65 | static const USBDescIface desc_iface_bluetooth[] = { |
66 | { | |
67 | .bInterfaceNumber = 0, | |
68 | .bNumEndpoints = 3, | |
69 | .bInterfaceClass = 0xe0, /* Wireless */ | |
70 | .bInterfaceSubClass = 0x01, /* Radio Frequency */ | |
71 | .bInterfaceProtocol = 0x01, /* Bluetooth */ | |
72 | .eps = (USBDescEndpoint[]) { | |
73 | { | |
74 | .bEndpointAddress = USB_DIR_IN | USB_EVT_EP, | |
75 | .bmAttributes = USB_ENDPOINT_XFER_INT, | |
76 | .wMaxPacketSize = 0x10, | |
77 | .bInterval = 0x02, | |
78 | }, | |
79 | { | |
80 | .bEndpointAddress = USB_DIR_OUT | USB_ACL_EP, | |
81 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | |
82 | .wMaxPacketSize = 0x40, | |
83 | .bInterval = 0x0a, | |
84 | }, | |
85 | { | |
86 | .bEndpointAddress = USB_DIR_IN | USB_ACL_EP, | |
87 | .bmAttributes = USB_ENDPOINT_XFER_BULK, | |
88 | .wMaxPacketSize = 0x40, | |
89 | .bInterval = 0x0a, | |
90 | }, | |
91 | }, | |
92 | },{ | |
93 | .bInterfaceNumber = 1, | |
94 | .bAlternateSetting = 0, | |
95 | .bNumEndpoints = 2, | |
96 | .bInterfaceClass = 0xe0, /* Wireless */ | |
97 | .bInterfaceSubClass = 0x01, /* Radio Frequency */ | |
98 | .bInterfaceProtocol = 0x01, /* Bluetooth */ | |
99 | .eps = (USBDescEndpoint[]) { | |
100 | { | |
101 | .bEndpointAddress = USB_DIR_OUT | USB_SCO_EP, | |
dd850cf2 | 102 | .bmAttributes = USB_ENDPOINT_XFER_ISOC, |
4696425c GH |
103 | .wMaxPacketSize = 0, |
104 | .bInterval = 0x01, | |
105 | }, | |
106 | { | |
107 | .bEndpointAddress = USB_DIR_IN | USB_SCO_EP, | |
dd850cf2 | 108 | .bmAttributes = USB_ENDPOINT_XFER_ISOC, |
4696425c GH |
109 | .wMaxPacketSize = 0, |
110 | .bInterval = 0x01, | |
111 | }, | |
112 | }, | |
113 | },{ | |
114 | .bInterfaceNumber = 1, | |
115 | .bAlternateSetting = 1, | |
116 | .bNumEndpoints = 2, | |
117 | .bInterfaceClass = 0xe0, /* Wireless */ | |
118 | .bInterfaceSubClass = 0x01, /* Radio Frequency */ | |
119 | .bInterfaceProtocol = 0x01, /* Bluetooth */ | |
120 | .eps = (USBDescEndpoint[]) { | |
121 | { | |
122 | .bEndpointAddress = USB_DIR_OUT | USB_SCO_EP, | |
dd850cf2 | 123 | .bmAttributes = USB_ENDPOINT_XFER_ISOC, |
4696425c GH |
124 | .wMaxPacketSize = 0x09, |
125 | .bInterval = 0x01, | |
126 | }, | |
127 | { | |
128 | .bEndpointAddress = USB_DIR_IN | USB_SCO_EP, | |
dd850cf2 | 129 | .bmAttributes = USB_ENDPOINT_XFER_ISOC, |
4696425c GH |
130 | .wMaxPacketSize = 0x09, |
131 | .bInterval = 0x01, | |
132 | }, | |
133 | }, | |
134 | },{ | |
135 | .bInterfaceNumber = 1, | |
136 | .bAlternateSetting = 2, | |
137 | .bNumEndpoints = 2, | |
138 | .bInterfaceClass = 0xe0, /* Wireless */ | |
139 | .bInterfaceSubClass = 0x01, /* Radio Frequency */ | |
140 | .bInterfaceProtocol = 0x01, /* Bluetooth */ | |
141 | .eps = (USBDescEndpoint[]) { | |
142 | { | |
143 | .bEndpointAddress = USB_DIR_OUT | USB_SCO_EP, | |
dd850cf2 | 144 | .bmAttributes = USB_ENDPOINT_XFER_ISOC, |
4696425c GH |
145 | .wMaxPacketSize = 0x11, |
146 | .bInterval = 0x01, | |
147 | }, | |
148 | { | |
149 | .bEndpointAddress = USB_DIR_IN | USB_SCO_EP, | |
dd850cf2 | 150 | .bmAttributes = USB_ENDPOINT_XFER_ISOC, |
4696425c GH |
151 | .wMaxPacketSize = 0x11, |
152 | .bInterval = 0x01, | |
153 | }, | |
154 | }, | |
155 | },{ | |
156 | .bInterfaceNumber = 1, | |
157 | .bAlternateSetting = 3, | |
158 | .bNumEndpoints = 2, | |
159 | .bInterfaceClass = 0xe0, /* Wireless */ | |
160 | .bInterfaceSubClass = 0x01, /* Radio Frequency */ | |
161 | .bInterfaceProtocol = 0x01, /* Bluetooth */ | |
162 | .eps = (USBDescEndpoint[]) { | |
163 | { | |
164 | .bEndpointAddress = USB_DIR_OUT | USB_SCO_EP, | |
dd850cf2 | 165 | .bmAttributes = USB_ENDPOINT_XFER_ISOC, |
4696425c GH |
166 | .wMaxPacketSize = 0x19, |
167 | .bInterval = 0x01, | |
168 | }, | |
169 | { | |
170 | .bEndpointAddress = USB_DIR_IN | USB_SCO_EP, | |
dd850cf2 | 171 | .bmAttributes = USB_ENDPOINT_XFER_ISOC, |
4696425c GH |
172 | .wMaxPacketSize = 0x19, |
173 | .bInterval = 0x01, | |
174 | }, | |
175 | }, | |
176 | },{ | |
177 | .bInterfaceNumber = 1, | |
178 | .bAlternateSetting = 4, | |
179 | .bNumEndpoints = 2, | |
180 | .bInterfaceClass = 0xe0, /* Wireless */ | |
181 | .bInterfaceSubClass = 0x01, /* Radio Frequency */ | |
182 | .bInterfaceProtocol = 0x01, /* Bluetooth */ | |
183 | .eps = (USBDescEndpoint[]) { | |
184 | { | |
185 | .bEndpointAddress = USB_DIR_OUT | USB_SCO_EP, | |
dd850cf2 | 186 | .bmAttributes = USB_ENDPOINT_XFER_ISOC, |
4696425c GH |
187 | .wMaxPacketSize = 0x21, |
188 | .bInterval = 0x01, | |
189 | }, | |
190 | { | |
191 | .bEndpointAddress = USB_DIR_IN | USB_SCO_EP, | |
dd850cf2 | 192 | .bmAttributes = USB_ENDPOINT_XFER_ISOC, |
4696425c GH |
193 | .wMaxPacketSize = 0x21, |
194 | .bInterval = 0x01, | |
195 | }, | |
196 | }, | |
197 | },{ | |
198 | .bInterfaceNumber = 1, | |
199 | .bAlternateSetting = 5, | |
200 | .bNumEndpoints = 2, | |
201 | .bInterfaceClass = 0xe0, /* Wireless */ | |
202 | .bInterfaceSubClass = 0x01, /* Radio Frequency */ | |
203 | .bInterfaceProtocol = 0x01, /* Bluetooth */ | |
204 | .eps = (USBDescEndpoint[]) { | |
205 | { | |
206 | .bEndpointAddress = USB_DIR_OUT | USB_SCO_EP, | |
dd850cf2 | 207 | .bmAttributes = USB_ENDPOINT_XFER_ISOC, |
4696425c GH |
208 | .wMaxPacketSize = 0x31, |
209 | .bInterval = 0x01, | |
210 | }, | |
211 | { | |
212 | .bEndpointAddress = USB_DIR_IN | USB_SCO_EP, | |
dd850cf2 | 213 | .bmAttributes = USB_ENDPOINT_XFER_ISOC, |
4696425c GH |
214 | .wMaxPacketSize = 0x31, |
215 | .bInterval = 0x01, | |
216 | }, | |
217 | }, | |
218 | } | |
219 | }; | |
e6a6d5ab | 220 | |
4696425c GH |
221 | static const USBDescDevice desc_device_bluetooth = { |
222 | .bcdUSB = 0x0110, | |
223 | .bDeviceClass = 0xe0, /* Wireless */ | |
224 | .bDeviceSubClass = 0x01, /* Radio Frequency */ | |
225 | .bDeviceProtocol = 0x01, /* Bluetooth */ | |
226 | .bMaxPacketSize0 = 64, | |
227 | .bNumConfigurations = 1, | |
228 | .confs = (USBDescConfig[]) { | |
229 | { | |
230 | .bNumInterfaces = 2, | |
231 | .bConfigurationValue = 1, | |
232 | .bmAttributes = 0xc0, | |
233 | .bMaxPower = 0, | |
234 | .nif = ARRAY_SIZE(desc_iface_bluetooth), | |
235 | .ifs = desc_iface_bluetooth, | |
236 | }, | |
237 | }, | |
e6a6d5ab AZ |
238 | }; |
239 | ||
4696425c GH |
240 | static const USBDesc desc_bluetooth = { |
241 | .id = { | |
242 | .idVendor = 0x0a12, | |
243 | .idProduct = 0x0001, | |
244 | .bcdDevice = 0x1958, | |
245 | .iManufacturer = STR_MANUFACTURER, | |
246 | .iProduct = 0, | |
247 | .iSerialNumber = STR_SERIALNUMBER, | |
248 | }, | |
249 | .full = &desc_device_bluetooth, | |
250 | .str = desc_strings, | |
e6a6d5ab AZ |
251 | }; |
252 | ||
253 | static void usb_bt_fifo_reset(struct usb_hci_in_fifo_s *fifo) | |
254 | { | |
255 | fifo->dstart = 0; | |
256 | fifo->dlen = 0; | |
257 | fifo->dsize = DFIFO_LEN_MASK + 1; | |
258 | fifo->start = 0; | |
259 | fifo->len = 0; | |
260 | } | |
261 | ||
262 | static void usb_bt_fifo_enqueue(struct usb_hci_in_fifo_s *fifo, | |
263 | const uint8_t *data, int len) | |
264 | { | |
265 | int off = fifo->dstart + fifo->dlen; | |
266 | uint8_t *buf; | |
267 | ||
268 | fifo->dlen += len; | |
269 | if (off <= DFIFO_LEN_MASK) { | |
270 | if (off + len > DFIFO_LEN_MASK + 1 && | |
271 | (fifo->dsize = off + len) > (DFIFO_LEN_MASK + 1) * 2) { | |
272 | fprintf(stderr, "%s: can't alloc %i bytes\n", __FUNCTION__, len); | |
273 | exit(-1); | |
274 | } | |
275 | buf = fifo->data + off; | |
276 | } else { | |
277 | if (fifo->dlen > fifo->dsize) { | |
278 | fprintf(stderr, "%s: can't alloc %i bytes\n", __FUNCTION__, len); | |
279 | exit(-1); | |
280 | } | |
281 | buf = fifo->data + off - fifo->dsize; | |
282 | } | |
283 | ||
284 | off = (fifo->start + fifo->len ++) & CFIFO_LEN_MASK; | |
285 | fifo->fifo[off].data = memcpy(buf, data, len); | |
286 | fifo->fifo[off].len = len; | |
287 | } | |
288 | ||
289 | static inline int usb_bt_fifo_dequeue(struct usb_hci_in_fifo_s *fifo, | |
290 | USBPacket *p) | |
291 | { | |
292 | int len; | |
293 | ||
294 | if (likely(!fifo->len)) | |
295 | return USB_RET_STALL; | |
296 | ||
4f4321c1 GH |
297 | len = MIN(p->iov.size, fifo->fifo[fifo->start].len); |
298 | usb_packet_copy(p, fifo->fifo[fifo->start].data, len); | |
299 | if (len == p->iov.size) { | |
e6a6d5ab AZ |
300 | fifo->fifo[fifo->start].len -= len; |
301 | fifo->fifo[fifo->start].data += len; | |
302 | } else { | |
303 | fifo->start ++; | |
304 | fifo->start &= CFIFO_LEN_MASK; | |
305 | fifo->len --; | |
306 | } | |
307 | ||
308 | fifo->dstart += len; | |
309 | fifo->dlen -= len; | |
310 | if (fifo->dstart >= fifo->dsize) { | |
311 | fifo->dstart = 0; | |
312 | fifo->dsize = DFIFO_LEN_MASK + 1; | |
313 | } | |
314 | ||
315 | return len; | |
316 | } | |
317 | ||
86178a57 | 318 | static inline void usb_bt_fifo_out_enqueue(struct USBBtState *s, |
e6a6d5ab AZ |
319 | struct usb_hci_out_fifo_s *fifo, |
320 | void (*send)(struct HCIInfo *, const uint8_t *, int), | |
321 | int (*complete)(const uint8_t *, int), | |
4f4321c1 | 322 | USBPacket *p) |
e6a6d5ab | 323 | { |
4f4321c1 GH |
324 | usb_packet_copy(p, fifo->data + fifo->len, p->iov.size); |
325 | fifo->len += p->iov.size; | |
326 | if (complete(fifo->data, fifo->len)) { | |
327 | send(s->hci, fifo->data, fifo->len); | |
328 | fifo->len = 0; | |
e6a6d5ab AZ |
329 | } |
330 | ||
331 | /* TODO: do we need to loop? */ | |
332 | } | |
333 | ||
334 | static int usb_bt_hci_cmd_complete(const uint8_t *data, int len) | |
335 | { | |
336 | len -= HCI_COMMAND_HDR_SIZE; | |
337 | return len >= 0 && | |
338 | len >= ((struct hci_command_hdr *) data)->plen; | |
339 | } | |
340 | ||
341 | static int usb_bt_hci_acl_complete(const uint8_t *data, int len) | |
342 | { | |
343 | len -= HCI_ACL_HDR_SIZE; | |
344 | return len >= 0 && | |
345 | len >= le16_to_cpu(((struct hci_acl_hdr *) data)->dlen); | |
346 | } | |
347 | ||
348 | static int usb_bt_hci_sco_complete(const uint8_t *data, int len) | |
349 | { | |
350 | len -= HCI_SCO_HDR_SIZE; | |
351 | return len >= 0 && | |
352 | len >= ((struct hci_sco_hdr *) data)->dlen; | |
353 | } | |
354 | ||
355 | static void usb_bt_handle_reset(USBDevice *dev) | |
356 | { | |
357 | struct USBBtState *s = (struct USBBtState *) dev->opaque; | |
358 | ||
359 | usb_bt_fifo_reset(&s->evt); | |
360 | usb_bt_fifo_reset(&s->acl); | |
361 | usb_bt_fifo_reset(&s->sco); | |
362 | s->outcmd.len = 0; | |
363 | s->outacl.len = 0; | |
364 | s->outsco.len = 0; | |
365 | s->altsetting = 0; | |
366 | } | |
367 | ||
007fd62f HG |
368 | static int usb_bt_handle_control(USBDevice *dev, USBPacket *p, |
369 | int request, int value, int index, int length, uint8_t *data) | |
e6a6d5ab AZ |
370 | { |
371 | struct USBBtState *s = (struct USBBtState *) dev->opaque; | |
4696425c GH |
372 | int ret; |
373 | ||
007fd62f | 374 | ret = usb_desc_handle_control(dev, p, request, value, index, length, data); |
4696425c | 375 | if (ret >= 0) { |
a980a065 GH |
376 | switch (request) { |
377 | case DeviceRequest | USB_REQ_GET_CONFIGURATION: | |
378 | s->config = 0; | |
379 | break; | |
380 | case DeviceOutRequest | USB_REQ_SET_CONFIGURATION: | |
381 | s->config = 1; | |
382 | usb_bt_fifo_reset(&s->evt); | |
383 | usb_bt_fifo_reset(&s->acl); | |
384 | usb_bt_fifo_reset(&s->sco); | |
385 | break; | |
386 | } | |
4696425c GH |
387 | return ret; |
388 | } | |
e6a6d5ab | 389 | |
4696425c | 390 | ret = 0; |
e6a6d5ab | 391 | switch (request) { |
e6a6d5ab AZ |
392 | case InterfaceRequest | USB_REQ_GET_STATUS: |
393 | case EndpointRequest | USB_REQ_GET_STATUS: | |
ed5a83dd | 394 | data[0] = 0x00; |
e6a6d5ab AZ |
395 | data[1] = 0x00; |
396 | ret = 2; | |
397 | break; | |
e6a6d5ab AZ |
398 | case InterfaceOutRequest | USB_REQ_CLEAR_FEATURE: |
399 | case EndpointOutRequest | USB_REQ_CLEAR_FEATURE: | |
ed5a83dd | 400 | goto fail; |
e6a6d5ab AZ |
401 | case InterfaceOutRequest | USB_REQ_SET_FEATURE: |
402 | case EndpointOutRequest | USB_REQ_SET_FEATURE: | |
ed5a83dd | 403 | goto fail; |
e6a6d5ab | 404 | break; |
e6a6d5ab AZ |
405 | case InterfaceRequest | USB_REQ_GET_INTERFACE: |
406 | if (value != 0 || (index & ~1) || length != 1) | |
407 | goto fail; | |
408 | if (index == 1) | |
409 | data[0] = s->altsetting; | |
410 | else | |
411 | data[0] = 0; | |
412 | ret = 1; | |
413 | break; | |
414 | case InterfaceOutRequest | USB_REQ_SET_INTERFACE: | |
415 | if ((index & ~1) || length != 0 || | |
416 | (index == 1 && (value < 0 || value > 4)) || | |
417 | (index == 0 && value != 0)) { | |
418 | printf("%s: Wrong SET_INTERFACE request (%i, %i)\n", | |
419 | __FUNCTION__, index, value); | |
420 | goto fail; | |
421 | } | |
422 | s->altsetting = value; | |
423 | ret = 0; | |
424 | break; | |
425 | case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_DEVICE) << 8): | |
426 | if (s->config) | |
427 | usb_bt_fifo_out_enqueue(s, &s->outcmd, s->hci->cmd_send, | |
4f4321c1 | 428 | usb_bt_hci_cmd_complete, p); |
e6a6d5ab AZ |
429 | break; |
430 | default: | |
431 | fail: | |
432 | ret = USB_RET_STALL; | |
433 | break; | |
434 | } | |
435 | return ret; | |
436 | } | |
437 | ||
438 | static int usb_bt_handle_data(USBDevice *dev, USBPacket *p) | |
439 | { | |
440 | struct USBBtState *s = (struct USBBtState *) dev->opaque; | |
441 | int ret = 0; | |
442 | ||
443 | if (!s->config) | |
444 | goto fail; | |
445 | ||
446 | switch (p->pid) { | |
447 | case USB_TOKEN_IN: | |
448 | switch (p->devep & 0xf) { | |
449 | case USB_EVT_EP: | |
450 | ret = usb_bt_fifo_dequeue(&s->evt, p); | |
451 | break; | |
452 | ||
453 | case USB_ACL_EP: | |
454 | ret = usb_bt_fifo_dequeue(&s->acl, p); | |
455 | break; | |
456 | ||
457 | case USB_SCO_EP: | |
458 | ret = usb_bt_fifo_dequeue(&s->sco, p); | |
459 | break; | |
460 | ||
461 | default: | |
462 | goto fail; | |
463 | } | |
464 | break; | |
465 | ||
466 | case USB_TOKEN_OUT: | |
467 | switch (p->devep & 0xf) { | |
468 | case USB_ACL_EP: | |
469 | usb_bt_fifo_out_enqueue(s, &s->outacl, s->hci->acl_send, | |
4f4321c1 | 470 | usb_bt_hci_acl_complete, p); |
e6a6d5ab AZ |
471 | break; |
472 | ||
473 | case USB_SCO_EP: | |
474 | usb_bt_fifo_out_enqueue(s, &s->outsco, s->hci->sco_send, | |
4f4321c1 | 475 | usb_bt_hci_sco_complete, p); |
e6a6d5ab AZ |
476 | break; |
477 | ||
478 | default: | |
479 | goto fail; | |
480 | } | |
481 | break; | |
482 | ||
483 | default: | |
484 | fail: | |
485 | ret = USB_RET_STALL; | |
486 | break; | |
487 | } | |
488 | ||
489 | return ret; | |
490 | } | |
491 | ||
492 | static void usb_bt_out_hci_packet_event(void *opaque, | |
493 | const uint8_t *data, int len) | |
494 | { | |
495 | struct USBBtState *s = (struct USBBtState *) opaque; | |
496 | ||
497 | usb_bt_fifo_enqueue(&s->evt, data, len); | |
498 | } | |
499 | ||
500 | static void usb_bt_out_hci_packet_acl(void *opaque, | |
501 | const uint8_t *data, int len) | |
502 | { | |
503 | struct USBBtState *s = (struct USBBtState *) opaque; | |
504 | ||
505 | usb_bt_fifo_enqueue(&s->acl, data, len); | |
506 | } | |
507 | ||
508 | static void usb_bt_handle_destroy(USBDevice *dev) | |
509 | { | |
510 | struct USBBtState *s = (struct USBBtState *) dev->opaque; | |
511 | ||
511d2b14 BS |
512 | s->hci->opaque = NULL; |
513 | s->hci->evt_recv = NULL; | |
514 | s->hci->acl_recv = NULL; | |
e6a6d5ab AZ |
515 | } |
516 | ||
806b6024 GH |
517 | static int usb_bt_initfn(USBDevice *dev) |
518 | { | |
a980a065 | 519 | usb_desc_init(dev); |
806b6024 GH |
520 | return 0; |
521 | } | |
522 | ||
e6a6d5ab AZ |
523 | USBDevice *usb_bt_init(HCIInfo *hci) |
524 | { | |
806b6024 | 525 | USBDevice *dev; |
e6a6d5ab AZ |
526 | struct USBBtState *s; |
527 | ||
2d564691 AZ |
528 | if (!hci) |
529 | return NULL; | |
556cd098 | 530 | dev = usb_create_simple(NULL /* FIXME */, "usb-bt-dongle"); |
806b6024 | 531 | s = DO_UPCAST(struct USBBtState, dev, dev); |
e6a6d5ab | 532 | s->dev.opaque = s; |
e6a6d5ab AZ |
533 | |
534 | s->hci = hci; | |
535 | s->hci->opaque = s; | |
536 | s->hci->evt_recv = usb_bt_out_hci_packet_event; | |
537 | s->hci->acl_recv = usb_bt_out_hci_packet_acl; | |
538 | ||
539 | usb_bt_handle_reset(&s->dev); | |
540 | ||
806b6024 GH |
541 | return dev; |
542 | } | |
543 | ||
2474e505 GH |
544 | static const VMStateDescription vmstate_usb_bt = { |
545 | .name = "usb-bt", | |
546 | .unmigratable = 1, | |
547 | }; | |
548 | ||
806b6024 | 549 | static struct USBDeviceInfo bt_info = { |
06384698 | 550 | .product_desc = "QEMU BT dongle", |
556cd098 | 551 | .qdev.name = "usb-bt-dongle", |
806b6024 | 552 | .qdev.size = sizeof(struct USBBtState), |
2474e505 | 553 | .qdev.vmsd = &vmstate_usb_bt, |
4696425c | 554 | .usb_desc = &desc_bluetooth, |
806b6024 GH |
555 | .init = usb_bt_initfn, |
556 | .handle_packet = usb_generic_handle_packet, | |
557 | .handle_reset = usb_bt_handle_reset, | |
558 | .handle_control = usb_bt_handle_control, | |
559 | .handle_data = usb_bt_handle_data, | |
560 | .handle_destroy = usb_bt_handle_destroy, | |
561 | }; | |
562 | ||
563 | static void usb_bt_register_devices(void) | |
564 | { | |
565 | usb_qdev_register(&bt_info); | |
e6a6d5ab | 566 | } |
806b6024 | 567 | device_init(usb_bt_register_devices) |