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