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