]>
Commit | Line | Data |
---|---|---|
69354a83 HG |
1 | /* |
2 | * USB redirector usb-guest | |
3 | * | |
cb897117 | 4 | * Copyright (c) 2011-2012 Red Hat, Inc. |
69354a83 HG |
5 | * |
6 | * Red Hat Authors: | |
7 | * Hans de Goede <hdegoede@redhat.com> | |
8 | * | |
9 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
10 | * of this software and associated documentation files (the "Software"), to deal | |
11 | * in the Software without restriction, including without limitation the rights | |
12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
13 | * copies of the Software, and to permit persons to whom the Software is | |
14 | * furnished to do so, subject to the following conditions: | |
15 | * | |
16 | * The above copyright notice and this permission notice shall be included in | |
17 | * all copies or substantial portions of the Software. | |
18 | * | |
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
22 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
25 | * THE SOFTWARE. | |
26 | */ | |
27 | ||
28 | #include "qemu-common.h" | |
29 | #include "qemu-timer.h" | |
30 | #include "monitor.h" | |
31 | #include "sysemu.h" | |
32 | ||
33 | #include <dirent.h> | |
34 | #include <sys/ioctl.h> | |
35 | #include <signal.h> | |
36 | #include <usbredirparser.h> | |
6af16589 | 37 | #include <usbredirfilter.h> |
69354a83 HG |
38 | |
39 | #include "hw/usb.h" | |
40 | ||
41 | #define MAX_ENDPOINTS 32 | |
1510168e | 42 | #define NO_INTERFACE_INFO 255 /* Valid interface_count always <= 32 */ |
69354a83 HG |
43 | #define EP2I(ep_address) (((ep_address & 0x80) >> 3) | (ep_address & 0x0f)) |
44 | #define I2EP(i) (((i & 0x10) << 3) | (i & 0x0f)) | |
45 | ||
de550a6a | 46 | typedef struct Cancelled Cancelled; |
69354a83 HG |
47 | typedef struct USBRedirDevice USBRedirDevice; |
48 | ||
49 | /* Struct to hold buffered packets (iso or int input packets) */ | |
50 | struct buf_packet { | |
51 | uint8_t *data; | |
52 | int len; | |
53 | int status; | |
54 | QTAILQ_ENTRY(buf_packet)next; | |
55 | }; | |
56 | ||
57 | struct endp_data { | |
58 | uint8_t type; | |
59 | uint8_t interval; | |
60 | uint8_t interface; /* bInterfaceNumber this ep belongs to */ | |
61 | uint8_t iso_started; | |
62 | uint8_t iso_error; /* For reporting iso errors to the HC */ | |
63 | uint8_t interrupt_started; | |
64 | uint8_t interrupt_error; | |
e1537884 | 65 | uint8_t bufpq_prefilled; |
81fd7b74 | 66 | uint8_t bufpq_dropping_packets; |
69354a83 | 67 | QTAILQ_HEAD(, buf_packet) bufpq; |
e1537884 | 68 | int bufpq_size; |
e8a7dd29 | 69 | int bufpq_target_size; |
69354a83 HG |
70 | }; |
71 | ||
72 | struct USBRedirDevice { | |
73 | USBDevice dev; | |
74 | /* Properties */ | |
75 | CharDriverState *cs; | |
76 | uint8_t debug; | |
6af16589 | 77 | char *filter_str; |
65bb3a5c | 78 | int32_t bootindex; |
69354a83 HG |
79 | /* Data passed from chardev the fd_read cb to the usbredirparser read cb */ |
80 | const uint8_t *read_buf; | |
81 | int read_buf_size; | |
ed9873bf HG |
82 | /* For async handling of close */ |
83 | QEMUBH *chardev_close_bh; | |
69354a83 HG |
84 | /* To delay the usb attach in case of quick chardev close + open */ |
85 | QEMUTimer *attach_timer; | |
86 | int64_t next_attach_time; | |
87 | struct usbredirparser *parser; | |
88 | struct endp_data endpoint[MAX_ENDPOINTS]; | |
de550a6a | 89 | QTAILQ_HEAD(, Cancelled) cancelled; |
6af16589 HG |
90 | /* Data for device filtering */ |
91 | struct usb_redir_device_connect_header device_info; | |
92 | struct usb_redir_interface_info_header interface_info; | |
93 | struct usbredirfilter_rule *filter_rules; | |
94 | int filter_rules_count; | |
69354a83 HG |
95 | }; |
96 | ||
de550a6a HG |
97 | struct Cancelled { |
98 | uint64_t id; | |
99 | QTAILQ_ENTRY(Cancelled)next; | |
69354a83 HG |
100 | }; |
101 | ||
097a66ef | 102 | static void usbredir_hello(void *priv, struct usb_redir_hello_header *h); |
69354a83 HG |
103 | static void usbredir_device_connect(void *priv, |
104 | struct usb_redir_device_connect_header *device_connect); | |
105 | static void usbredir_device_disconnect(void *priv); | |
106 | static void usbredir_interface_info(void *priv, | |
107 | struct usb_redir_interface_info_header *interface_info); | |
108 | static void usbredir_ep_info(void *priv, | |
109 | struct usb_redir_ep_info_header *ep_info); | |
be4a8928 | 110 | static void usbredir_configuration_status(void *priv, uint64_t id, |
69354a83 | 111 | struct usb_redir_configuration_status_header *configuration_status); |
be4a8928 | 112 | static void usbredir_alt_setting_status(void *priv, uint64_t id, |
69354a83 | 113 | struct usb_redir_alt_setting_status_header *alt_setting_status); |
be4a8928 | 114 | static void usbredir_iso_stream_status(void *priv, uint64_t id, |
69354a83 | 115 | struct usb_redir_iso_stream_status_header *iso_stream_status); |
be4a8928 | 116 | static void usbredir_interrupt_receiving_status(void *priv, uint64_t id, |
69354a83 HG |
117 | struct usb_redir_interrupt_receiving_status_header |
118 | *interrupt_receiving_status); | |
be4a8928 | 119 | static void usbredir_bulk_streams_status(void *priv, uint64_t id, |
69354a83 | 120 | struct usb_redir_bulk_streams_status_header *bulk_streams_status); |
be4a8928 | 121 | static void usbredir_control_packet(void *priv, uint64_t id, |
69354a83 HG |
122 | struct usb_redir_control_packet_header *control_packet, |
123 | uint8_t *data, int data_len); | |
be4a8928 | 124 | static void usbredir_bulk_packet(void *priv, uint64_t id, |
69354a83 HG |
125 | struct usb_redir_bulk_packet_header *bulk_packet, |
126 | uint8_t *data, int data_len); | |
be4a8928 | 127 | static void usbredir_iso_packet(void *priv, uint64_t id, |
69354a83 HG |
128 | struct usb_redir_iso_packet_header *iso_packet, |
129 | uint8_t *data, int data_len); | |
be4a8928 | 130 | static void usbredir_interrupt_packet(void *priv, uint64_t id, |
69354a83 HG |
131 | struct usb_redir_interrupt_packet_header *interrupt_header, |
132 | uint8_t *data, int data_len); | |
133 | ||
134 | static int usbredir_handle_status(USBRedirDevice *dev, | |
135 | int status, int actual_len); | |
136 | ||
69354a83 HG |
137 | /* |
138 | * Logging stuff | |
139 | */ | |
140 | ||
141 | #define ERROR(...) \ | |
142 | do { \ | |
143 | if (dev->debug >= usbredirparser_error) { \ | |
144 | error_report("usb-redir error: " __VA_ARGS__); \ | |
145 | } \ | |
146 | } while (0) | |
147 | #define WARNING(...) \ | |
148 | do { \ | |
149 | if (dev->debug >= usbredirparser_warning) { \ | |
150 | error_report("usb-redir warning: " __VA_ARGS__); \ | |
151 | } \ | |
152 | } while (0) | |
153 | #define INFO(...) \ | |
154 | do { \ | |
155 | if (dev->debug >= usbredirparser_info) { \ | |
156 | error_report("usb-redir: " __VA_ARGS__); \ | |
157 | } \ | |
158 | } while (0) | |
159 | #define DPRINTF(...) \ | |
160 | do { \ | |
161 | if (dev->debug >= usbredirparser_debug) { \ | |
162 | error_report("usb-redir: " __VA_ARGS__); \ | |
163 | } \ | |
164 | } while (0) | |
165 | #define DPRINTF2(...) \ | |
166 | do { \ | |
167 | if (dev->debug >= usbredirparser_debug_data) { \ | |
168 | error_report("usb-redir: " __VA_ARGS__); \ | |
169 | } \ | |
170 | } while (0) | |
171 | ||
172 | static void usbredir_log(void *priv, int level, const char *msg) | |
173 | { | |
174 | USBRedirDevice *dev = priv; | |
175 | ||
176 | if (dev->debug < level) { | |
177 | return; | |
178 | } | |
179 | ||
be62a2eb | 180 | error_report("%s", msg); |
69354a83 HG |
181 | } |
182 | ||
183 | static void usbredir_log_data(USBRedirDevice *dev, const char *desc, | |
184 | const uint8_t *data, int len) | |
185 | { | |
186 | int i, j, n; | |
187 | ||
188 | if (dev->debug < usbredirparser_debug_data) { | |
189 | return; | |
190 | } | |
191 | ||
192 | for (i = 0; i < len; i += j) { | |
193 | char buf[128]; | |
194 | ||
195 | n = sprintf(buf, "%s", desc); | |
196 | for (j = 0; j < 8 && i + j < len; j++) { | |
197 | n += sprintf(buf + n, " %02X", data[i + j]); | |
198 | } | |
be62a2eb | 199 | error_report("%s", buf); |
69354a83 HG |
200 | } |
201 | } | |
202 | ||
203 | /* | |
204 | * usbredirparser io functions | |
205 | */ | |
206 | ||
207 | static int usbredir_read(void *priv, uint8_t *data, int count) | |
208 | { | |
209 | USBRedirDevice *dev = priv; | |
210 | ||
211 | if (dev->read_buf_size < count) { | |
212 | count = dev->read_buf_size; | |
213 | } | |
214 | ||
215 | memcpy(data, dev->read_buf, count); | |
216 | ||
217 | dev->read_buf_size -= count; | |
218 | if (dev->read_buf_size) { | |
219 | dev->read_buf += count; | |
220 | } else { | |
221 | dev->read_buf = NULL; | |
222 | } | |
223 | ||
224 | return count; | |
225 | } | |
226 | ||
227 | static int usbredir_write(void *priv, uint8_t *data, int count) | |
228 | { | |
229 | USBRedirDevice *dev = priv; | |
230 | ||
c1b71a1d HG |
231 | if (!dev->cs->opened) { |
232 | return 0; | |
233 | } | |
234 | ||
2cc6e0a1 | 235 | return qemu_chr_fe_write(dev->cs, data, count); |
69354a83 HG |
236 | } |
237 | ||
238 | /* | |
de550a6a | 239 | * Cancelled and buffered packets helpers |
69354a83 HG |
240 | */ |
241 | ||
de550a6a | 242 | static void usbredir_cancel_packet(USBDevice *udev, USBPacket *p) |
69354a83 | 243 | { |
de550a6a HG |
244 | USBRedirDevice *dev = DO_UPCAST(USBRedirDevice, dev, udev); |
245 | Cancelled *c; | |
69354a83 | 246 | |
de550a6a | 247 | DPRINTF("cancel packet id %"PRIu64"\n", p->id); |
69354a83 | 248 | |
de550a6a HG |
249 | c = g_malloc0(sizeof(Cancelled)); |
250 | c->id = p->id; | |
251 | QTAILQ_INSERT_TAIL(&dev->cancelled, c, next); | |
252 | ||
253 | usbredirparser_send_cancel_data_packet(dev->parser, p->id); | |
254 | usbredirparser_do_write(dev->parser); | |
69354a83 HG |
255 | } |
256 | ||
de550a6a | 257 | static int usbredir_is_cancelled(USBRedirDevice *dev, uint64_t id) |
69354a83 | 258 | { |
de550a6a HG |
259 | Cancelled *c; |
260 | ||
261 | if (!dev->dev.attached) { | |
262 | return 1; /* Treat everything as cancelled after a disconnect */ | |
263 | } | |
69354a83 | 264 | |
de550a6a HG |
265 | QTAILQ_FOREACH(c, &dev->cancelled, next) { |
266 | if (c->id == id) { | |
267 | QTAILQ_REMOVE(&dev->cancelled, c, next); | |
268 | g_free(c); | |
269 | return 1; | |
69354a83 HG |
270 | } |
271 | } | |
de550a6a | 272 | return 0; |
69354a83 HG |
273 | } |
274 | ||
de550a6a HG |
275 | static USBPacket *usbredir_find_packet_by_id(USBRedirDevice *dev, |
276 | uint8_t ep, uint64_t id) | |
69354a83 | 277 | { |
de550a6a | 278 | USBPacket *p; |
69354a83 | 279 | |
de550a6a HG |
280 | if (usbredir_is_cancelled(dev, id)) { |
281 | return NULL; | |
282 | } | |
69354a83 | 283 | |
de550a6a HG |
284 | p = usb_ep_find_packet_by_id(&dev->dev, |
285 | (ep & USB_DIR_IN) ? USB_TOKEN_IN : USB_TOKEN_OUT, | |
286 | ep & 0x0f, id); | |
287 | if (p == NULL) { | |
288 | ERROR("could not find packet with id %"PRIu64"\n", id); | |
69354a83 | 289 | } |
de550a6a | 290 | return p; |
69354a83 HG |
291 | } |
292 | ||
81fd7b74 | 293 | static void bufp_alloc(USBRedirDevice *dev, |
69354a83 HG |
294 | uint8_t *data, int len, int status, uint8_t ep) |
295 | { | |
81fd7b74 HG |
296 | struct buf_packet *bufp; |
297 | ||
298 | if (!dev->endpoint[EP2I(ep)].bufpq_dropping_packets && | |
299 | dev->endpoint[EP2I(ep)].bufpq_size > | |
300 | 2 * dev->endpoint[EP2I(ep)].bufpq_target_size) { | |
301 | DPRINTF("bufpq overflow, dropping packets ep %02X\n", ep); | |
302 | dev->endpoint[EP2I(ep)].bufpq_dropping_packets = 1; | |
303 | } | |
304 | /* Since we're interupting the stream anyways, drop enough packets to get | |
305 | back to our target buffer size */ | |
306 | if (dev->endpoint[EP2I(ep)].bufpq_dropping_packets) { | |
307 | if (dev->endpoint[EP2I(ep)].bufpq_size > | |
308 | dev->endpoint[EP2I(ep)].bufpq_target_size) { | |
309 | free(data); | |
310 | return; | |
311 | } | |
312 | dev->endpoint[EP2I(ep)].bufpq_dropping_packets = 0; | |
313 | } | |
314 | ||
315 | bufp = g_malloc(sizeof(struct buf_packet)); | |
69354a83 HG |
316 | bufp->data = data; |
317 | bufp->len = len; | |
318 | bufp->status = status; | |
319 | QTAILQ_INSERT_TAIL(&dev->endpoint[EP2I(ep)].bufpq, bufp, next); | |
e1537884 | 320 | dev->endpoint[EP2I(ep)].bufpq_size++; |
69354a83 HG |
321 | } |
322 | ||
323 | static void bufp_free(USBRedirDevice *dev, struct buf_packet *bufp, | |
324 | uint8_t ep) | |
325 | { | |
326 | QTAILQ_REMOVE(&dev->endpoint[EP2I(ep)].bufpq, bufp, next); | |
e1537884 | 327 | dev->endpoint[EP2I(ep)].bufpq_size--; |
69354a83 | 328 | free(bufp->data); |
7267c094 | 329 | g_free(bufp); |
69354a83 HG |
330 | } |
331 | ||
332 | static void usbredir_free_bufpq(USBRedirDevice *dev, uint8_t ep) | |
333 | { | |
334 | struct buf_packet *buf, *buf_next; | |
335 | ||
336 | QTAILQ_FOREACH_SAFE(buf, &dev->endpoint[EP2I(ep)].bufpq, next, buf_next) { | |
337 | bufp_free(dev, buf, ep); | |
338 | } | |
339 | } | |
340 | ||
341 | /* | |
342 | * USBDevice callbacks | |
343 | */ | |
344 | ||
345 | static void usbredir_handle_reset(USBDevice *udev) | |
346 | { | |
347 | USBRedirDevice *dev = DO_UPCAST(USBRedirDevice, dev, udev); | |
348 | ||
349 | DPRINTF("reset device\n"); | |
350 | usbredirparser_send_reset(dev->parser); | |
351 | usbredirparser_do_write(dev->parser); | |
352 | } | |
353 | ||
354 | static int usbredir_handle_iso_data(USBRedirDevice *dev, USBPacket *p, | |
355 | uint8_t ep) | |
356 | { | |
357 | int status, len; | |
69354a83 HG |
358 | if (!dev->endpoint[EP2I(ep)].iso_started && |
359 | !dev->endpoint[EP2I(ep)].iso_error) { | |
360 | struct usb_redir_start_iso_stream_header start_iso = { | |
361 | .endpoint = ep, | |
69354a83 | 362 | }; |
e8a7dd29 HG |
363 | int pkts_per_sec; |
364 | ||
365 | if (dev->dev.speed == USB_SPEED_HIGH) { | |
366 | pkts_per_sec = 8000 / dev->endpoint[EP2I(ep)].interval; | |
367 | } else { | |
368 | pkts_per_sec = 1000 / dev->endpoint[EP2I(ep)].interval; | |
369 | } | |
370 | /* Testing has shown that we need circa 60 ms buffer */ | |
371 | dev->endpoint[EP2I(ep)].bufpq_target_size = (pkts_per_sec * 60) / 1000; | |
372 | ||
373 | /* Aim for approx 100 interrupts / second on the client to | |
374 | balance latency and interrupt load */ | |
375 | start_iso.pkts_per_urb = pkts_per_sec / 100; | |
376 | if (start_iso.pkts_per_urb < 1) { | |
377 | start_iso.pkts_per_urb = 1; | |
378 | } else if (start_iso.pkts_per_urb > 32) { | |
379 | start_iso.pkts_per_urb = 32; | |
380 | } | |
381 | ||
382 | start_iso.no_urbs = (dev->endpoint[EP2I(ep)].bufpq_target_size + | |
383 | start_iso.pkts_per_urb - 1) / | |
384 | start_iso.pkts_per_urb; | |
385 | /* Output endpoints pre-fill only 1/2 of the packets, keeping the rest | |
386 | as overflow buffer. Also see the usbredir protocol documentation */ | |
387 | if (!(ep & USB_DIR_IN)) { | |
388 | start_iso.no_urbs *= 2; | |
389 | } | |
390 | if (start_iso.no_urbs > 16) { | |
391 | start_iso.no_urbs = 16; | |
392 | } | |
393 | ||
69354a83 HG |
394 | /* No id, we look at the ep when receiving a status back */ |
395 | usbredirparser_send_start_iso_stream(dev->parser, 0, &start_iso); | |
396 | usbredirparser_do_write(dev->parser); | |
32213543 HG |
397 | DPRINTF("iso stream started pkts/sec %d pkts/urb %d urbs %d ep %02X\n", |
398 | pkts_per_sec, start_iso.pkts_per_urb, start_iso.no_urbs, ep); | |
69354a83 | 399 | dev->endpoint[EP2I(ep)].iso_started = 1; |
e1537884 | 400 | dev->endpoint[EP2I(ep)].bufpq_prefilled = 0; |
81fd7b74 | 401 | dev->endpoint[EP2I(ep)].bufpq_dropping_packets = 0; |
69354a83 HG |
402 | } |
403 | ||
404 | if (ep & USB_DIR_IN) { | |
405 | struct buf_packet *isop; | |
406 | ||
e1537884 HG |
407 | if (dev->endpoint[EP2I(ep)].iso_started && |
408 | !dev->endpoint[EP2I(ep)].bufpq_prefilled) { | |
409 | if (dev->endpoint[EP2I(ep)].bufpq_size < | |
410 | dev->endpoint[EP2I(ep)].bufpq_target_size) { | |
411 | return usbredir_handle_status(dev, 0, 0); | |
412 | } | |
413 | dev->endpoint[EP2I(ep)].bufpq_prefilled = 1; | |
414 | } | |
415 | ||
69354a83 HG |
416 | isop = QTAILQ_FIRST(&dev->endpoint[EP2I(ep)].bufpq); |
417 | if (isop == NULL) { | |
32213543 HG |
418 | DPRINTF("iso-token-in ep %02X, no isop, iso_error: %d\n", |
419 | ep, dev->endpoint[EP2I(ep)].iso_error); | |
e1537884 HG |
420 | /* Re-fill the buffer */ |
421 | dev->endpoint[EP2I(ep)].bufpq_prefilled = 0; | |
69354a83 HG |
422 | /* Check iso_error for stream errors, otherwise its an underrun */ |
423 | status = dev->endpoint[EP2I(ep)].iso_error; | |
424 | dev->endpoint[EP2I(ep)].iso_error = 0; | |
d61000a8 | 425 | return status ? USB_RET_IOERROR : 0; |
69354a83 | 426 | } |
32213543 HG |
427 | DPRINTF2("iso-token-in ep %02X status %d len %d queue-size: %d\n", ep, |
428 | isop->status, isop->len, dev->endpoint[EP2I(ep)].bufpq_size); | |
69354a83 HG |
429 | |
430 | status = isop->status; | |
431 | if (status != usb_redir_success) { | |
432 | bufp_free(dev, isop, ep); | |
d61000a8 | 433 | return USB_RET_IOERROR; |
69354a83 HG |
434 | } |
435 | ||
436 | len = isop->len; | |
4f4321c1 | 437 | if (len > p->iov.size) { |
32213543 HG |
438 | ERROR("received iso data is larger then packet ep %02X (%d > %d)\n", |
439 | ep, len, (int)p->iov.size); | |
69354a83 | 440 | bufp_free(dev, isop, ep); |
4d819a9b | 441 | return USB_RET_BABBLE; |
69354a83 | 442 | } |
4f4321c1 | 443 | usb_packet_copy(p, isop->data, len); |
69354a83 HG |
444 | bufp_free(dev, isop, ep); |
445 | return len; | |
446 | } else { | |
447 | /* If the stream was not started because of a pending error don't | |
448 | send the packet to the usb-host */ | |
449 | if (dev->endpoint[EP2I(ep)].iso_started) { | |
450 | struct usb_redir_iso_packet_header iso_packet = { | |
451 | .endpoint = ep, | |
4f4321c1 | 452 | .length = p->iov.size |
69354a83 | 453 | }; |
4f4321c1 | 454 | uint8_t buf[p->iov.size]; |
69354a83 | 455 | /* No id, we look at the ep when receiving a status back */ |
4f4321c1 | 456 | usb_packet_copy(p, buf, p->iov.size); |
69354a83 | 457 | usbredirparser_send_iso_packet(dev->parser, 0, &iso_packet, |
4f4321c1 | 458 | buf, p->iov.size); |
69354a83 HG |
459 | usbredirparser_do_write(dev->parser); |
460 | } | |
461 | status = dev->endpoint[EP2I(ep)].iso_error; | |
462 | dev->endpoint[EP2I(ep)].iso_error = 0; | |
4f4321c1 GH |
463 | DPRINTF2("iso-token-out ep %02X status %d len %zd\n", ep, status, |
464 | p->iov.size); | |
465 | return usbredir_handle_status(dev, status, p->iov.size); | |
69354a83 HG |
466 | } |
467 | } | |
468 | ||
469 | static void usbredir_stop_iso_stream(USBRedirDevice *dev, uint8_t ep) | |
470 | { | |
471 | struct usb_redir_stop_iso_stream_header stop_iso_stream = { | |
472 | .endpoint = ep | |
473 | }; | |
474 | if (dev->endpoint[EP2I(ep)].iso_started) { | |
475 | usbredirparser_send_stop_iso_stream(dev->parser, 0, &stop_iso_stream); | |
476 | DPRINTF("iso stream stopped ep %02X\n", ep); | |
477 | dev->endpoint[EP2I(ep)].iso_started = 0; | |
478 | } | |
2bd836e5 | 479 | dev->endpoint[EP2I(ep)].iso_error = 0; |
69354a83 HG |
480 | usbredir_free_bufpq(dev, ep); |
481 | } | |
482 | ||
483 | static int usbredir_handle_bulk_data(USBRedirDevice *dev, USBPacket *p, | |
484 | uint8_t ep) | |
485 | { | |
69354a83 HG |
486 | struct usb_redir_bulk_packet_header bulk_packet; |
487 | ||
de550a6a | 488 | DPRINTF("bulk-out ep %02X len %zd id %"PRIu64"\n", ep, p->iov.size, p->id); |
69354a83 HG |
489 | |
490 | bulk_packet.endpoint = ep; | |
4f4321c1 | 491 | bulk_packet.length = p->iov.size; |
69354a83 | 492 | bulk_packet.stream_id = 0; |
69354a83 HG |
493 | |
494 | if (ep & USB_DIR_IN) { | |
de550a6a | 495 | usbredirparser_send_bulk_packet(dev->parser, p->id, |
69354a83 HG |
496 | &bulk_packet, NULL, 0); |
497 | } else { | |
4f4321c1 GH |
498 | uint8_t buf[p->iov.size]; |
499 | usb_packet_copy(p, buf, p->iov.size); | |
500 | usbredir_log_data(dev, "bulk data out:", buf, p->iov.size); | |
de550a6a | 501 | usbredirparser_send_bulk_packet(dev->parser, p->id, |
4f4321c1 | 502 | &bulk_packet, buf, p->iov.size); |
69354a83 HG |
503 | } |
504 | usbredirparser_do_write(dev->parser); | |
505 | return USB_RET_ASYNC; | |
506 | } | |
507 | ||
508 | static int usbredir_handle_interrupt_data(USBRedirDevice *dev, | |
509 | USBPacket *p, uint8_t ep) | |
510 | { | |
511 | if (ep & USB_DIR_IN) { | |
512 | /* Input interrupt endpoint, buffered packet input */ | |
513 | struct buf_packet *intp; | |
514 | int status, len; | |
515 | ||
516 | if (!dev->endpoint[EP2I(ep)].interrupt_started && | |
517 | !dev->endpoint[EP2I(ep)].interrupt_error) { | |
518 | struct usb_redir_start_interrupt_receiving_header start_int = { | |
519 | .endpoint = ep, | |
520 | }; | |
521 | /* No id, we look at the ep when receiving a status back */ | |
522 | usbredirparser_send_start_interrupt_receiving(dev->parser, 0, | |
523 | &start_int); | |
524 | usbredirparser_do_write(dev->parser); | |
525 | DPRINTF("interrupt recv started ep %02X\n", ep); | |
526 | dev->endpoint[EP2I(ep)].interrupt_started = 1; | |
81fd7b74 HG |
527 | /* We don't really want to drop interrupt packets ever, but |
528 | having some upper limit to how much we buffer is good. */ | |
529 | dev->endpoint[EP2I(ep)].bufpq_target_size = 1000; | |
530 | dev->endpoint[EP2I(ep)].bufpq_dropping_packets = 0; | |
69354a83 HG |
531 | } |
532 | ||
533 | intp = QTAILQ_FIRST(&dev->endpoint[EP2I(ep)].bufpq); | |
534 | if (intp == NULL) { | |
535 | DPRINTF2("interrupt-token-in ep %02X, no intp\n", ep); | |
536 | /* Check interrupt_error for stream errors */ | |
537 | status = dev->endpoint[EP2I(ep)].interrupt_error; | |
538 | dev->endpoint[EP2I(ep)].interrupt_error = 0; | |
e6472210 HG |
539 | if (status) { |
540 | return usbredir_handle_status(dev, status, 0); | |
541 | } | |
542 | return USB_RET_NAK; | |
69354a83 HG |
543 | } |
544 | DPRINTF("interrupt-token-in ep %02X status %d len %d\n", ep, | |
545 | intp->status, intp->len); | |
546 | ||
547 | status = intp->status; | |
548 | if (status != usb_redir_success) { | |
549 | bufp_free(dev, intp, ep); | |
550 | return usbredir_handle_status(dev, status, 0); | |
551 | } | |
552 | ||
553 | len = intp->len; | |
4f4321c1 | 554 | if (len > p->iov.size) { |
69354a83 HG |
555 | ERROR("received int data is larger then packet ep %02X\n", ep); |
556 | bufp_free(dev, intp, ep); | |
4d819a9b | 557 | return USB_RET_BABBLE; |
69354a83 | 558 | } |
4f4321c1 | 559 | usb_packet_copy(p, intp->data, len); |
69354a83 HG |
560 | bufp_free(dev, intp, ep); |
561 | return len; | |
562 | } else { | |
563 | /* Output interrupt endpoint, normal async operation */ | |
69354a83 | 564 | struct usb_redir_interrupt_packet_header interrupt_packet; |
4f4321c1 | 565 | uint8_t buf[p->iov.size]; |
69354a83 | 566 | |
de550a6a HG |
567 | DPRINTF("interrupt-out ep %02X len %zd id %"PRIu64"\n", ep, |
568 | p->iov.size, p->id); | |
69354a83 HG |
569 | |
570 | interrupt_packet.endpoint = ep; | |
4f4321c1 | 571 | interrupt_packet.length = p->iov.size; |
69354a83 | 572 | |
4f4321c1 GH |
573 | usb_packet_copy(p, buf, p->iov.size); |
574 | usbredir_log_data(dev, "interrupt data out:", buf, p->iov.size); | |
de550a6a | 575 | usbredirparser_send_interrupt_packet(dev->parser, p->id, |
4f4321c1 | 576 | &interrupt_packet, buf, p->iov.size); |
69354a83 HG |
577 | usbredirparser_do_write(dev->parser); |
578 | return USB_RET_ASYNC; | |
579 | } | |
580 | } | |
581 | ||
582 | static void usbredir_stop_interrupt_receiving(USBRedirDevice *dev, | |
583 | uint8_t ep) | |
584 | { | |
585 | struct usb_redir_stop_interrupt_receiving_header stop_interrupt_recv = { | |
586 | .endpoint = ep | |
587 | }; | |
588 | if (dev->endpoint[EP2I(ep)].interrupt_started) { | |
589 | usbredirparser_send_stop_interrupt_receiving(dev->parser, 0, | |
590 | &stop_interrupt_recv); | |
591 | DPRINTF("interrupt recv stopped ep %02X\n", ep); | |
592 | dev->endpoint[EP2I(ep)].interrupt_started = 0; | |
593 | } | |
2bd836e5 | 594 | dev->endpoint[EP2I(ep)].interrupt_error = 0; |
69354a83 HG |
595 | usbredir_free_bufpq(dev, ep); |
596 | } | |
597 | ||
598 | static int usbredir_handle_data(USBDevice *udev, USBPacket *p) | |
599 | { | |
600 | USBRedirDevice *dev = DO_UPCAST(USBRedirDevice, dev, udev); | |
601 | uint8_t ep; | |
602 | ||
079d0b7f | 603 | ep = p->ep->nr; |
69354a83 HG |
604 | if (p->pid == USB_TOKEN_IN) { |
605 | ep |= USB_DIR_IN; | |
606 | } | |
607 | ||
608 | switch (dev->endpoint[EP2I(ep)].type) { | |
609 | case USB_ENDPOINT_XFER_CONTROL: | |
610 | ERROR("handle_data called for control transfer on ep %02X\n", ep); | |
611 | return USB_RET_NAK; | |
612 | case USB_ENDPOINT_XFER_ISOC: | |
613 | return usbredir_handle_iso_data(dev, p, ep); | |
614 | case USB_ENDPOINT_XFER_BULK: | |
3a93113a | 615 | return usbredir_handle_bulk_data(dev, p, ep); |
69354a83 | 616 | case USB_ENDPOINT_XFER_INT: |
3a93113a | 617 | return usbredir_handle_interrupt_data(dev, p, ep); |
69354a83 HG |
618 | default: |
619 | ERROR("handle_data ep %02X has unknown type %d\n", ep, | |
620 | dev->endpoint[EP2I(ep)].type); | |
621 | return USB_RET_NAK; | |
622 | } | |
623 | } | |
624 | ||
625 | static int usbredir_set_config(USBRedirDevice *dev, USBPacket *p, | |
626 | int config) | |
627 | { | |
628 | struct usb_redir_set_configuration_header set_config; | |
69354a83 HG |
629 | int i; |
630 | ||
de550a6a | 631 | DPRINTF("set config %d id %"PRIu64"\n", config, p->id); |
69354a83 HG |
632 | |
633 | for (i = 0; i < MAX_ENDPOINTS; i++) { | |
634 | switch (dev->endpoint[i].type) { | |
635 | case USB_ENDPOINT_XFER_ISOC: | |
636 | usbredir_stop_iso_stream(dev, I2EP(i)); | |
637 | break; | |
638 | case USB_ENDPOINT_XFER_INT: | |
639 | if (i & 0x10) { | |
640 | usbredir_stop_interrupt_receiving(dev, I2EP(i)); | |
641 | } | |
642 | break; | |
643 | } | |
644 | usbredir_free_bufpq(dev, I2EP(i)); | |
645 | } | |
646 | ||
647 | set_config.configuration = config; | |
de550a6a | 648 | usbredirparser_send_set_configuration(dev->parser, p->id, &set_config); |
69354a83 HG |
649 | usbredirparser_do_write(dev->parser); |
650 | return USB_RET_ASYNC; | |
651 | } | |
652 | ||
653 | static int usbredir_get_config(USBRedirDevice *dev, USBPacket *p) | |
654 | { | |
de550a6a | 655 | DPRINTF("get config id %"PRIu64"\n", p->id); |
69354a83 | 656 | |
de550a6a | 657 | usbredirparser_send_get_configuration(dev->parser, p->id); |
69354a83 HG |
658 | usbredirparser_do_write(dev->parser); |
659 | return USB_RET_ASYNC; | |
660 | } | |
661 | ||
662 | static int usbredir_set_interface(USBRedirDevice *dev, USBPacket *p, | |
663 | int interface, int alt) | |
664 | { | |
665 | struct usb_redir_set_alt_setting_header set_alt; | |
69354a83 HG |
666 | int i; |
667 | ||
de550a6a | 668 | DPRINTF("set interface %d alt %d id %"PRIu64"\n", interface, alt, p->id); |
69354a83 HG |
669 | |
670 | for (i = 0; i < MAX_ENDPOINTS; i++) { | |
671 | if (dev->endpoint[i].interface == interface) { | |
672 | switch (dev->endpoint[i].type) { | |
673 | case USB_ENDPOINT_XFER_ISOC: | |
674 | usbredir_stop_iso_stream(dev, I2EP(i)); | |
675 | break; | |
676 | case USB_ENDPOINT_XFER_INT: | |
677 | if (i & 0x10) { | |
678 | usbredir_stop_interrupt_receiving(dev, I2EP(i)); | |
679 | } | |
680 | break; | |
681 | } | |
682 | usbredir_free_bufpq(dev, I2EP(i)); | |
683 | } | |
684 | } | |
685 | ||
686 | set_alt.interface = interface; | |
687 | set_alt.alt = alt; | |
de550a6a | 688 | usbredirparser_send_set_alt_setting(dev->parser, p->id, &set_alt); |
69354a83 HG |
689 | usbredirparser_do_write(dev->parser); |
690 | return USB_RET_ASYNC; | |
691 | } | |
692 | ||
693 | static int usbredir_get_interface(USBRedirDevice *dev, USBPacket *p, | |
694 | int interface) | |
695 | { | |
696 | struct usb_redir_get_alt_setting_header get_alt; | |
69354a83 | 697 | |
de550a6a | 698 | DPRINTF("get interface %d id %"PRIu64"\n", interface, p->id); |
69354a83 HG |
699 | |
700 | get_alt.interface = interface; | |
de550a6a | 701 | usbredirparser_send_get_alt_setting(dev->parser, p->id, &get_alt); |
69354a83 HG |
702 | usbredirparser_do_write(dev->parser); |
703 | return USB_RET_ASYNC; | |
704 | } | |
705 | ||
706 | static int usbredir_handle_control(USBDevice *udev, USBPacket *p, | |
707 | int request, int value, int index, int length, uint8_t *data) | |
708 | { | |
709 | USBRedirDevice *dev = DO_UPCAST(USBRedirDevice, dev, udev); | |
710 | struct usb_redir_control_packet_header control_packet; | |
69354a83 HG |
711 | |
712 | /* Special cases for certain standard device requests */ | |
713 | switch (request) { | |
714 | case DeviceOutRequest | USB_REQ_SET_ADDRESS: | |
715 | DPRINTF("set address %d\n", value); | |
716 | dev->dev.addr = value; | |
717 | return 0; | |
718 | case DeviceOutRequest | USB_REQ_SET_CONFIGURATION: | |
719 | return usbredir_set_config(dev, p, value & 0xff); | |
720 | case DeviceRequest | USB_REQ_GET_CONFIGURATION: | |
721 | return usbredir_get_config(dev, p); | |
722 | case InterfaceOutRequest | USB_REQ_SET_INTERFACE: | |
723 | return usbredir_set_interface(dev, p, index, value); | |
724 | case InterfaceRequest | USB_REQ_GET_INTERFACE: | |
725 | return usbredir_get_interface(dev, p, index); | |
726 | } | |
727 | ||
de550a6a HG |
728 | /* Normal ctrl requests, note request is (bRequestType << 8) | bRequest */ |
729 | DPRINTF( | |
730 | "ctrl-out type 0x%x req 0x%x val 0x%x index %d len %d id %"PRIu64"\n", | |
731 | request >> 8, request & 0xff, value, index, length, p->id); | |
69354a83 HG |
732 | |
733 | control_packet.request = request & 0xFF; | |
734 | control_packet.requesttype = request >> 8; | |
735 | control_packet.endpoint = control_packet.requesttype & USB_DIR_IN; | |
736 | control_packet.value = value; | |
737 | control_packet.index = index; | |
738 | control_packet.length = length; | |
69354a83 HG |
739 | |
740 | if (control_packet.requesttype & USB_DIR_IN) { | |
de550a6a | 741 | usbredirparser_send_control_packet(dev->parser, p->id, |
69354a83 HG |
742 | &control_packet, NULL, 0); |
743 | } else { | |
744 | usbredir_log_data(dev, "ctrl data out:", data, length); | |
de550a6a | 745 | usbredirparser_send_control_packet(dev->parser, p->id, |
69354a83 HG |
746 | &control_packet, data, length); |
747 | } | |
748 | usbredirparser_do_write(dev->parser); | |
749 | return USB_RET_ASYNC; | |
750 | } | |
751 | ||
752 | /* | |
753 | * Close events can be triggered by usbredirparser_do_write which gets called | |
754 | * from within the USBDevice data / control packet callbacks and doing a | |
755 | * usb_detach from within these callbacks is not a good idea. | |
756 | * | |
ed9873bf | 757 | * So we use a bh handler to take care of close events. |
69354a83 | 758 | */ |
ed9873bf | 759 | static void usbredir_chardev_close_bh(void *opaque) |
69354a83 HG |
760 | { |
761 | USBRedirDevice *dev = opaque; | |
762 | ||
763 | usbredir_device_disconnect(dev); | |
764 | ||
765 | if (dev->parser) { | |
766 | usbredirparser_destroy(dev->parser); | |
767 | dev->parser = NULL; | |
768 | } | |
ed9873bf | 769 | } |
69354a83 | 770 | |
ed9873bf HG |
771 | static void usbredir_chardev_open(USBRedirDevice *dev) |
772 | { | |
773 | uint32_t caps[USB_REDIR_CAPS_SIZE] = { 0, }; | |
774 | char version[32]; | |
6af16589 | 775 | |
ed9873bf HG |
776 | /* Make sure any pending closes are handled (no-op if none pending) */ |
777 | usbredir_chardev_close_bh(dev); | |
778 | qemu_bh_cancel(dev->chardev_close_bh); | |
779 | ||
780 | strcpy(version, "qemu usb-redir guest "); | |
781 | pstrcat(version, sizeof(version), qemu_get_version()); | |
782 | ||
783 | dev->parser = qemu_oom_check(usbredirparser_create()); | |
784 | dev->parser->priv = dev; | |
785 | dev->parser->log_func = usbredir_log; | |
786 | dev->parser->read_func = usbredir_read; | |
787 | dev->parser->write_func = usbredir_write; | |
788 | dev->parser->hello_func = usbredir_hello; | |
789 | dev->parser->device_connect_func = usbredir_device_connect; | |
790 | dev->parser->device_disconnect_func = usbredir_device_disconnect; | |
791 | dev->parser->interface_info_func = usbredir_interface_info; | |
792 | dev->parser->ep_info_func = usbredir_ep_info; | |
793 | dev->parser->configuration_status_func = usbredir_configuration_status; | |
794 | dev->parser->alt_setting_status_func = usbredir_alt_setting_status; | |
795 | dev->parser->iso_stream_status_func = usbredir_iso_stream_status; | |
796 | dev->parser->interrupt_receiving_status_func = | |
797 | usbredir_interrupt_receiving_status; | |
798 | dev->parser->bulk_streams_status_func = usbredir_bulk_streams_status; | |
799 | dev->parser->control_packet_func = usbredir_control_packet; | |
800 | dev->parser->bulk_packet_func = usbredir_bulk_packet; | |
801 | dev->parser->iso_packet_func = usbredir_iso_packet; | |
802 | dev->parser->interrupt_packet_func = usbredir_interrupt_packet; | |
803 | dev->read_buf = NULL; | |
804 | dev->read_buf_size = 0; | |
805 | ||
806 | usbredirparser_caps_set_cap(caps, usb_redir_cap_connect_device_version); | |
807 | usbredirparser_caps_set_cap(caps, usb_redir_cap_filter); | |
be4a8928 | 808 | usbredirparser_caps_set_cap(caps, usb_redir_cap_64bits_ids); |
ed9873bf HG |
809 | usbredirparser_init(dev->parser, version, caps, USB_REDIR_CAPS_SIZE, 0); |
810 | usbredirparser_do_write(dev->parser); | |
69354a83 HG |
811 | } |
812 | ||
813 | static void usbredir_do_attach(void *opaque) | |
814 | { | |
815 | USBRedirDevice *dev = opaque; | |
816 | ||
714f9db0 HG |
817 | if (usb_device_attach(&dev->dev) != 0) { |
818 | usbredir_device_disconnect(dev); | |
819 | if (usbredirparser_peer_has_cap(dev->parser, usb_redir_cap_filter)) { | |
820 | usbredirparser_send_filter_reject(dev->parser); | |
821 | usbredirparser_do_write(dev->parser); | |
822 | } | |
823 | } | |
69354a83 HG |
824 | } |
825 | ||
826 | /* | |
827 | * chardev callbacks | |
828 | */ | |
829 | ||
830 | static int usbredir_chardev_can_read(void *opaque) | |
831 | { | |
832 | USBRedirDevice *dev = opaque; | |
833 | ||
ed9873bf HG |
834 | if (!dev->parser) { |
835 | WARNING("chardev_can_read called on non open chardev!\n"); | |
69354a83 HG |
836 | return 0; |
837 | } | |
ed9873bf HG |
838 | |
839 | /* usbredir_parser_do_read will consume *all* data we give it */ | |
840 | return 1024 * 1024; | |
69354a83 HG |
841 | } |
842 | ||
843 | static void usbredir_chardev_read(void *opaque, const uint8_t *buf, int size) | |
844 | { | |
845 | USBRedirDevice *dev = opaque; | |
846 | ||
847 | /* No recursion allowed! */ | |
848 | assert(dev->read_buf == NULL); | |
849 | ||
850 | dev->read_buf = buf; | |
851 | dev->read_buf_size = size; | |
852 | ||
853 | usbredirparser_do_read(dev->parser); | |
854 | /* Send any acks, etc. which may be queued now */ | |
855 | usbredirparser_do_write(dev->parser); | |
856 | } | |
857 | ||
858 | static void usbredir_chardev_event(void *opaque, int event) | |
859 | { | |
860 | USBRedirDevice *dev = opaque; | |
861 | ||
862 | switch (event) { | |
863 | case CHR_EVENT_OPENED: | |
ed9873bf HG |
864 | usbredir_chardev_open(dev); |
865 | break; | |
69354a83 | 866 | case CHR_EVENT_CLOSED: |
ed9873bf | 867 | qemu_bh_schedule(dev->chardev_close_bh); |
69354a83 HG |
868 | break; |
869 | } | |
870 | } | |
871 | ||
872 | /* | |
873 | * init + destroy | |
874 | */ | |
875 | ||
876 | static int usbredir_initfn(USBDevice *udev) | |
877 | { | |
878 | USBRedirDevice *dev = DO_UPCAST(USBRedirDevice, dev, udev); | |
879 | int i; | |
880 | ||
881 | if (dev->cs == NULL) { | |
882 | qerror_report(QERR_MISSING_PARAMETER, "chardev"); | |
883 | return -1; | |
884 | } | |
885 | ||
6af16589 HG |
886 | if (dev->filter_str) { |
887 | i = usbredirfilter_string_to_rules(dev->filter_str, ":", "|", | |
888 | &dev->filter_rules, | |
889 | &dev->filter_rules_count); | |
890 | if (i) { | |
891 | qerror_report(QERR_INVALID_PARAMETER_VALUE, "filter", | |
892 | "a usb device filter string"); | |
893 | return -1; | |
894 | } | |
895 | } | |
896 | ||
ed9873bf | 897 | dev->chardev_close_bh = qemu_bh_new(usbredir_chardev_close_bh, dev); |
69354a83 HG |
898 | dev->attach_timer = qemu_new_timer_ms(vm_clock, usbredir_do_attach, dev); |
899 | ||
de550a6a | 900 | QTAILQ_INIT(&dev->cancelled); |
69354a83 HG |
901 | for (i = 0; i < MAX_ENDPOINTS; i++) { |
902 | QTAILQ_INIT(&dev->endpoint[i].bufpq); | |
903 | } | |
904 | ||
905 | /* We'll do the attach once we receive the speed from the usb-host */ | |
906 | udev->auto_attach = 0; | |
907 | ||
65f9d986 HG |
908 | /* Let the backend know we are ready */ |
909 | qemu_chr_fe_open(dev->cs); | |
69354a83 HG |
910 | qemu_chr_add_handlers(dev->cs, usbredir_chardev_can_read, |
911 | usbredir_chardev_read, usbredir_chardev_event, dev); | |
912 | ||
65bb3a5c | 913 | add_boot_device_path(dev->bootindex, &udev->qdev, NULL); |
69354a83 HG |
914 | return 0; |
915 | } | |
916 | ||
917 | static void usbredir_cleanup_device_queues(USBRedirDevice *dev) | |
918 | { | |
de550a6a | 919 | Cancelled *c, *next_c; |
69354a83 HG |
920 | int i; |
921 | ||
de550a6a HG |
922 | QTAILQ_FOREACH_SAFE(c, &dev->cancelled, next, next_c) { |
923 | QTAILQ_REMOVE(&dev->cancelled, c, next); | |
924 | g_free(c); | |
69354a83 HG |
925 | } |
926 | for (i = 0; i < MAX_ENDPOINTS; i++) { | |
927 | usbredir_free_bufpq(dev, I2EP(i)); | |
928 | } | |
929 | } | |
930 | ||
931 | static void usbredir_handle_destroy(USBDevice *udev) | |
932 | { | |
933 | USBRedirDevice *dev = DO_UPCAST(USBRedirDevice, dev, udev); | |
934 | ||
65f9d986 | 935 | qemu_chr_fe_close(dev->cs); |
70f24fb6 | 936 | qemu_chr_delete(dev->cs); |
69354a83 | 937 | /* Note must be done after qemu_chr_close, as that causes a close event */ |
ed9873bf | 938 | qemu_bh_delete(dev->chardev_close_bh); |
69354a83 HG |
939 | |
940 | qemu_del_timer(dev->attach_timer); | |
941 | qemu_free_timer(dev->attach_timer); | |
942 | ||
943 | usbredir_cleanup_device_queues(dev); | |
944 | ||
945 | if (dev->parser) { | |
946 | usbredirparser_destroy(dev->parser); | |
947 | } | |
6af16589 HG |
948 | |
949 | free(dev->filter_rules); | |
950 | } | |
951 | ||
952 | static int usbredir_check_filter(USBRedirDevice *dev) | |
953 | { | |
1510168e | 954 | if (dev->interface_info.interface_count == NO_INTERFACE_INFO) { |
6af16589 | 955 | ERROR("No interface info for device\n"); |
5b3bd682 | 956 | goto error; |
6af16589 HG |
957 | } |
958 | ||
959 | if (dev->filter_rules) { | |
960 | if (!usbredirparser_peer_has_cap(dev->parser, | |
961 | usb_redir_cap_connect_device_version)) { | |
962 | ERROR("Device filter specified and peer does not have the " | |
963 | "connect_device_version capability\n"); | |
5b3bd682 | 964 | goto error; |
6af16589 HG |
965 | } |
966 | ||
967 | if (usbredirfilter_check( | |
968 | dev->filter_rules, | |
969 | dev->filter_rules_count, | |
970 | dev->device_info.device_class, | |
971 | dev->device_info.device_subclass, | |
972 | dev->device_info.device_protocol, | |
973 | dev->interface_info.interface_class, | |
974 | dev->interface_info.interface_subclass, | |
975 | dev->interface_info.interface_protocol, | |
976 | dev->interface_info.interface_count, | |
977 | dev->device_info.vendor_id, | |
978 | dev->device_info.product_id, | |
979 | dev->device_info.device_version_bcd, | |
980 | 0) != 0) { | |
5b3bd682 | 981 | goto error; |
6af16589 HG |
982 | } |
983 | } | |
984 | ||
985 | return 0; | |
5b3bd682 HG |
986 | |
987 | error: | |
988 | usbredir_device_disconnect(dev); | |
097a66ef HG |
989 | if (usbredirparser_peer_has_cap(dev->parser, usb_redir_cap_filter)) { |
990 | usbredirparser_send_filter_reject(dev->parser); | |
991 | usbredirparser_do_write(dev->parser); | |
992 | } | |
5b3bd682 | 993 | return -1; |
69354a83 HG |
994 | } |
995 | ||
996 | /* | |
997 | * usbredirparser packet complete callbacks | |
998 | */ | |
999 | ||
1000 | static int usbredir_handle_status(USBRedirDevice *dev, | |
1001 | int status, int actual_len) | |
1002 | { | |
1003 | switch (status) { | |
1004 | case usb_redir_success: | |
1005 | return actual_len; | |
1006 | case usb_redir_stall: | |
1007 | return USB_RET_STALL; | |
1008 | case usb_redir_cancelled: | |
18113340 HG |
1009 | /* |
1010 | * When the usbredir-host unredirects a device, it will report a status | |
1011 | * of cancelled for all pending packets, followed by a disconnect msg. | |
1012 | */ | |
1013 | return USB_RET_IOERROR; | |
69354a83 | 1014 | case usb_redir_inval: |
d61000a8 | 1015 | WARNING("got invalid param error from usb-host?\n"); |
18113340 | 1016 | return USB_RET_IOERROR; |
adae502c HG |
1017 | case usb_redir_babble: |
1018 | return USB_RET_BABBLE; | |
69354a83 HG |
1019 | case usb_redir_ioerror: |
1020 | case usb_redir_timeout: | |
1021 | default: | |
d61000a8 | 1022 | return USB_RET_IOERROR; |
69354a83 HG |
1023 | } |
1024 | } | |
1025 | ||
097a66ef HG |
1026 | static void usbredir_hello(void *priv, struct usb_redir_hello_header *h) |
1027 | { | |
1028 | USBRedirDevice *dev = priv; | |
1029 | ||
1030 | /* Try to send the filter info now that we've the usb-host's caps */ | |
1031 | if (usbredirparser_peer_has_cap(dev->parser, usb_redir_cap_filter) && | |
1032 | dev->filter_rules) { | |
1033 | usbredirparser_send_filter_filter(dev->parser, dev->filter_rules, | |
1034 | dev->filter_rules_count); | |
1035 | usbredirparser_do_write(dev->parser); | |
1036 | } | |
1037 | } | |
1038 | ||
69354a83 HG |
1039 | static void usbredir_device_connect(void *priv, |
1040 | struct usb_redir_device_connect_header *device_connect) | |
1041 | { | |
1042 | USBRedirDevice *dev = priv; | |
6af16589 | 1043 | const char *speed; |
69354a83 | 1044 | |
99f08100 HG |
1045 | if (qemu_timer_pending(dev->attach_timer) || dev->dev.attached) { |
1046 | ERROR("Received device connect while already connected\n"); | |
1047 | return; | |
1048 | } | |
1049 | ||
69354a83 HG |
1050 | switch (device_connect->speed) { |
1051 | case usb_redir_speed_low: | |
6af16589 | 1052 | speed = "low speed"; |
69354a83 HG |
1053 | dev->dev.speed = USB_SPEED_LOW; |
1054 | break; | |
1055 | case usb_redir_speed_full: | |
6af16589 | 1056 | speed = "full speed"; |
69354a83 HG |
1057 | dev->dev.speed = USB_SPEED_FULL; |
1058 | break; | |
1059 | case usb_redir_speed_high: | |
6af16589 | 1060 | speed = "high speed"; |
69354a83 HG |
1061 | dev->dev.speed = USB_SPEED_HIGH; |
1062 | break; | |
1063 | case usb_redir_speed_super: | |
6af16589 | 1064 | speed = "super speed"; |
69354a83 HG |
1065 | dev->dev.speed = USB_SPEED_SUPER; |
1066 | break; | |
1067 | default: | |
6af16589 | 1068 | speed = "unknown speed"; |
69354a83 HG |
1069 | dev->dev.speed = USB_SPEED_FULL; |
1070 | } | |
6af16589 HG |
1071 | |
1072 | if (usbredirparser_peer_has_cap(dev->parser, | |
1073 | usb_redir_cap_connect_device_version)) { | |
1074 | INFO("attaching %s device %04x:%04x version %d.%d class %02x\n", | |
1075 | speed, device_connect->vendor_id, device_connect->product_id, | |
52234bc0 HG |
1076 | ((device_connect->device_version_bcd & 0xf000) >> 12) * 10 + |
1077 | ((device_connect->device_version_bcd & 0x0f00) >> 8), | |
1078 | ((device_connect->device_version_bcd & 0x00f0) >> 4) * 10 + | |
1079 | ((device_connect->device_version_bcd & 0x000f) >> 0), | |
6af16589 HG |
1080 | device_connect->device_class); |
1081 | } else { | |
1082 | INFO("attaching %s device %04x:%04x class %02x\n", speed, | |
1083 | device_connect->vendor_id, device_connect->product_id, | |
1084 | device_connect->device_class); | |
1085 | } | |
1086 | ||
69354a83 | 1087 | dev->dev.speedmask = (1 << dev->dev.speed); |
6af16589 HG |
1088 | dev->device_info = *device_connect; |
1089 | ||
1090 | if (usbredir_check_filter(dev)) { | |
1091 | WARNING("Device %04x:%04x rejected by device filter, not attaching\n", | |
1092 | device_connect->vendor_id, device_connect->product_id); | |
1093 | return; | |
1094 | } | |
1095 | ||
69354a83 HG |
1096 | qemu_mod_timer(dev->attach_timer, dev->next_attach_time); |
1097 | } | |
1098 | ||
1099 | static void usbredir_device_disconnect(void *priv) | |
1100 | { | |
1101 | USBRedirDevice *dev = priv; | |
99f08100 | 1102 | int i; |
69354a83 HG |
1103 | |
1104 | /* Stop any pending attaches */ | |
1105 | qemu_del_timer(dev->attach_timer); | |
1106 | ||
1107 | if (dev->dev.attached) { | |
1108 | usb_device_detach(&dev->dev); | |
69354a83 HG |
1109 | /* |
1110 | * Delay next usb device attach to give the guest a chance to see | |
1111 | * see the detach / attach in case of quick close / open succession | |
1112 | */ | |
1113 | dev->next_attach_time = qemu_get_clock_ms(vm_clock) + 200; | |
1114 | } | |
99f08100 HG |
1115 | |
1116 | /* Reset state so that the next dev connected starts with a clean slate */ | |
1117 | usbredir_cleanup_device_queues(dev); | |
1118 | memset(dev->endpoint, 0, sizeof(dev->endpoint)); | |
1119 | for (i = 0; i < MAX_ENDPOINTS; i++) { | |
1120 | QTAILQ_INIT(&dev->endpoint[i].bufpq); | |
1121 | } | |
0454b611 | 1122 | usb_ep_init(&dev->dev); |
1510168e | 1123 | dev->interface_info.interface_count = NO_INTERFACE_INFO; |
a0625c56 HG |
1124 | dev->dev.addr = 0; |
1125 | dev->dev.speed = 0; | |
69354a83 HG |
1126 | } |
1127 | ||
1128 | static void usbredir_interface_info(void *priv, | |
1129 | struct usb_redir_interface_info_header *interface_info) | |
1130 | { | |
6af16589 HG |
1131 | USBRedirDevice *dev = priv; |
1132 | ||
1133 | dev->interface_info = *interface_info; | |
1134 | ||
1135 | /* | |
1136 | * If we receive interface info after the device has already been | |
1137 | * connected (ie on a set_config), re-check the filter. | |
1138 | */ | |
1139 | if (qemu_timer_pending(dev->attach_timer) || dev->dev.attached) { | |
1140 | if (usbredir_check_filter(dev)) { | |
1141 | ERROR("Device no longer matches filter after interface info " | |
1142 | "change, disconnecting!\n"); | |
6af16589 HG |
1143 | } |
1144 | } | |
69354a83 HG |
1145 | } |
1146 | ||
1147 | static void usbredir_ep_info(void *priv, | |
1148 | struct usb_redir_ep_info_header *ep_info) | |
1149 | { | |
1150 | USBRedirDevice *dev = priv; | |
0454b611 | 1151 | struct USBEndpoint *usb_ep; |
69354a83 HG |
1152 | int i; |
1153 | ||
1154 | for (i = 0; i < MAX_ENDPOINTS; i++) { | |
1155 | dev->endpoint[i].type = ep_info->type[i]; | |
1156 | dev->endpoint[i].interval = ep_info->interval[i]; | |
1157 | dev->endpoint[i].interface = ep_info->interface[i]; | |
e8a7dd29 HG |
1158 | switch (dev->endpoint[i].type) { |
1159 | case usb_redir_type_invalid: | |
1160 | break; | |
1161 | case usb_redir_type_iso: | |
1162 | case usb_redir_type_interrupt: | |
1163 | if (dev->endpoint[i].interval == 0) { | |
1164 | ERROR("Received 0 interval for isoc or irq endpoint\n"); | |
1165 | usbredir_device_disconnect(dev); | |
1166 | } | |
1167 | /* Fall through */ | |
1168 | case usb_redir_type_control: | |
1169 | case usb_redir_type_bulk: | |
69354a83 HG |
1170 | DPRINTF("ep: %02X type: %d interface: %d\n", I2EP(i), |
1171 | dev->endpoint[i].type, dev->endpoint[i].interface); | |
e8a7dd29 HG |
1172 | break; |
1173 | default: | |
1174 | ERROR("Received invalid endpoint type\n"); | |
1175 | usbredir_device_disconnect(dev); | |
0454b611 | 1176 | return; |
69354a83 | 1177 | } |
0454b611 HG |
1178 | usb_ep = usb_ep_get(&dev->dev, |
1179 | (i & 0x10) ? USB_TOKEN_IN : USB_TOKEN_OUT, | |
1180 | i & 0x0f); | |
1181 | usb_ep->type = dev->endpoint[i].type; | |
1182 | usb_ep->ifnum = dev->endpoint[i].interface; | |
69354a83 HG |
1183 | } |
1184 | } | |
1185 | ||
be4a8928 | 1186 | static void usbredir_configuration_status(void *priv, uint64_t id, |
69354a83 HG |
1187 | struct usb_redir_configuration_status_header *config_status) |
1188 | { | |
1189 | USBRedirDevice *dev = priv; | |
de550a6a | 1190 | USBPacket *p; |
69354a83 HG |
1191 | int len = 0; |
1192 | ||
be4a8928 HG |
1193 | DPRINTF("set config status %d config %d id %"PRIu64"\n", |
1194 | config_status->status, config_status->configuration, id); | |
69354a83 | 1195 | |
de550a6a HG |
1196 | p = usbredir_find_packet_by_id(dev, 0, id); |
1197 | if (p) { | |
cb897117 | 1198 | if (dev->dev.setup_buf[0] & USB_DIR_IN) { |
69354a83 HG |
1199 | dev->dev.data_buf[0] = config_status->configuration; |
1200 | len = 1; | |
1201 | } | |
de550a6a HG |
1202 | p->result = usbredir_handle_status(dev, config_status->status, len); |
1203 | usb_generic_async_ctrl_complete(&dev->dev, p); | |
69354a83 | 1204 | } |
69354a83 HG |
1205 | } |
1206 | ||
be4a8928 | 1207 | static void usbredir_alt_setting_status(void *priv, uint64_t id, |
69354a83 HG |
1208 | struct usb_redir_alt_setting_status_header *alt_setting_status) |
1209 | { | |
1210 | USBRedirDevice *dev = priv; | |
de550a6a | 1211 | USBPacket *p; |
69354a83 HG |
1212 | int len = 0; |
1213 | ||
be4a8928 HG |
1214 | DPRINTF("alt status %d intf %d alt %d id: %"PRIu64"\n", |
1215 | alt_setting_status->status, alt_setting_status->interface, | |
69354a83 HG |
1216 | alt_setting_status->alt, id); |
1217 | ||
de550a6a HG |
1218 | p = usbredir_find_packet_by_id(dev, 0, id); |
1219 | if (p) { | |
cb897117 | 1220 | if (dev->dev.setup_buf[0] & USB_DIR_IN) { |
69354a83 HG |
1221 | dev->dev.data_buf[0] = alt_setting_status->alt; |
1222 | len = 1; | |
1223 | } | |
de550a6a | 1224 | p->result = |
69354a83 | 1225 | usbredir_handle_status(dev, alt_setting_status->status, len); |
de550a6a | 1226 | usb_generic_async_ctrl_complete(&dev->dev, p); |
69354a83 | 1227 | } |
69354a83 HG |
1228 | } |
1229 | ||
be4a8928 | 1230 | static void usbredir_iso_stream_status(void *priv, uint64_t id, |
69354a83 HG |
1231 | struct usb_redir_iso_stream_status_header *iso_stream_status) |
1232 | { | |
1233 | USBRedirDevice *dev = priv; | |
1234 | uint8_t ep = iso_stream_status->endpoint; | |
1235 | ||
be4a8928 | 1236 | DPRINTF("iso status %d ep %02X id %"PRIu64"\n", iso_stream_status->status, |
69354a83 HG |
1237 | ep, id); |
1238 | ||
2bd836e5 | 1239 | if (!dev->dev.attached || !dev->endpoint[EP2I(ep)].iso_started) { |
99f08100 HG |
1240 | return; |
1241 | } | |
1242 | ||
69354a83 HG |
1243 | dev->endpoint[EP2I(ep)].iso_error = iso_stream_status->status; |
1244 | if (iso_stream_status->status == usb_redir_stall) { | |
1245 | DPRINTF("iso stream stopped by peer ep %02X\n", ep); | |
1246 | dev->endpoint[EP2I(ep)].iso_started = 0; | |
1247 | } | |
1248 | } | |
1249 | ||
be4a8928 | 1250 | static void usbredir_interrupt_receiving_status(void *priv, uint64_t id, |
69354a83 HG |
1251 | struct usb_redir_interrupt_receiving_status_header |
1252 | *interrupt_receiving_status) | |
1253 | { | |
1254 | USBRedirDevice *dev = priv; | |
1255 | uint8_t ep = interrupt_receiving_status->endpoint; | |
1256 | ||
be4a8928 | 1257 | DPRINTF("interrupt recv status %d ep %02X id %"PRIu64"\n", |
69354a83 HG |
1258 | interrupt_receiving_status->status, ep, id); |
1259 | ||
2bd836e5 | 1260 | if (!dev->dev.attached || !dev->endpoint[EP2I(ep)].interrupt_started) { |
99f08100 HG |
1261 | return; |
1262 | } | |
1263 | ||
69354a83 HG |
1264 | dev->endpoint[EP2I(ep)].interrupt_error = |
1265 | interrupt_receiving_status->status; | |
1266 | if (interrupt_receiving_status->status == usb_redir_stall) { | |
1267 | DPRINTF("interrupt receiving stopped by peer ep %02X\n", ep); | |
1268 | dev->endpoint[EP2I(ep)].interrupt_started = 0; | |
1269 | } | |
1270 | } | |
1271 | ||
be4a8928 | 1272 | static void usbredir_bulk_streams_status(void *priv, uint64_t id, |
69354a83 HG |
1273 | struct usb_redir_bulk_streams_status_header *bulk_streams_status) |
1274 | { | |
1275 | } | |
1276 | ||
be4a8928 | 1277 | static void usbredir_control_packet(void *priv, uint64_t id, |
69354a83 HG |
1278 | struct usb_redir_control_packet_header *control_packet, |
1279 | uint8_t *data, int data_len) | |
1280 | { | |
1281 | USBRedirDevice *dev = priv; | |
de550a6a | 1282 | USBPacket *p; |
69354a83 | 1283 | int len = control_packet->length; |
69354a83 | 1284 | |
be4a8928 | 1285 | DPRINTF("ctrl-in status %d len %d id %"PRIu64"\n", control_packet->status, |
69354a83 HG |
1286 | len, id); |
1287 | ||
de550a6a HG |
1288 | p = usbredir_find_packet_by_id(dev, 0, id); |
1289 | if (p) { | |
69354a83 HG |
1290 | len = usbredir_handle_status(dev, control_packet->status, len); |
1291 | if (len > 0) { | |
1292 | usbredir_log_data(dev, "ctrl data in:", data, data_len); | |
1293 | if (data_len <= sizeof(dev->dev.data_buf)) { | |
1294 | memcpy(dev->dev.data_buf, data, data_len); | |
1295 | } else { | |
1296 | ERROR("ctrl buffer too small (%d > %zu)\n", | |
1297 | data_len, sizeof(dev->dev.data_buf)); | |
1298 | len = USB_RET_STALL; | |
1299 | } | |
1300 | } | |
de550a6a HG |
1301 | p->result = len; |
1302 | usb_generic_async_ctrl_complete(&dev->dev, p); | |
69354a83 | 1303 | } |
69354a83 HG |
1304 | free(data); |
1305 | } | |
1306 | ||
be4a8928 | 1307 | static void usbredir_bulk_packet(void *priv, uint64_t id, |
69354a83 HG |
1308 | struct usb_redir_bulk_packet_header *bulk_packet, |
1309 | uint8_t *data, int data_len) | |
1310 | { | |
1311 | USBRedirDevice *dev = priv; | |
1312 | uint8_t ep = bulk_packet->endpoint; | |
1313 | int len = bulk_packet->length; | |
de550a6a | 1314 | USBPacket *p; |
69354a83 | 1315 | |
be4a8928 HG |
1316 | DPRINTF("bulk-in status %d ep %02X len %d id %"PRIu64"\n", |
1317 | bulk_packet->status, ep, len, id); | |
69354a83 | 1318 | |
de550a6a HG |
1319 | p = usbredir_find_packet_by_id(dev, ep, id); |
1320 | if (p) { | |
69354a83 HG |
1321 | len = usbredir_handle_status(dev, bulk_packet->status, len); |
1322 | if (len > 0) { | |
1323 | usbredir_log_data(dev, "bulk data in:", data, data_len); | |
de550a6a HG |
1324 | if (data_len <= p->iov.size) { |
1325 | usb_packet_copy(p, data, data_len); | |
69354a83 | 1326 | } else { |
2979a361 HG |
1327 | ERROR("bulk got more data then requested (%d > %zd)\n", |
1328 | data_len, p->iov.size); | |
1329 | len = USB_RET_BABBLE; | |
69354a83 HG |
1330 | } |
1331 | } | |
de550a6a HG |
1332 | p->result = len; |
1333 | usb_packet_complete(&dev->dev, p); | |
69354a83 | 1334 | } |
69354a83 HG |
1335 | free(data); |
1336 | } | |
1337 | ||
be4a8928 | 1338 | static void usbredir_iso_packet(void *priv, uint64_t id, |
69354a83 HG |
1339 | struct usb_redir_iso_packet_header *iso_packet, |
1340 | uint8_t *data, int data_len) | |
1341 | { | |
1342 | USBRedirDevice *dev = priv; | |
1343 | uint8_t ep = iso_packet->endpoint; | |
1344 | ||
be4a8928 HG |
1345 | DPRINTF2("iso-in status %d ep %02X len %d id %"PRIu64"\n", |
1346 | iso_packet->status, ep, data_len, id); | |
69354a83 HG |
1347 | |
1348 | if (dev->endpoint[EP2I(ep)].type != USB_ENDPOINT_XFER_ISOC) { | |
1349 | ERROR("received iso packet for non iso endpoint %02X\n", ep); | |
1350 | free(data); | |
1351 | return; | |
1352 | } | |
1353 | ||
1354 | if (dev->endpoint[EP2I(ep)].iso_started == 0) { | |
1355 | DPRINTF("received iso packet for non started stream ep %02X\n", ep); | |
1356 | free(data); | |
1357 | return; | |
1358 | } | |
1359 | ||
1360 | /* bufp_alloc also adds the packet to the ep queue */ | |
1361 | bufp_alloc(dev, data, data_len, iso_packet->status, ep); | |
1362 | } | |
1363 | ||
be4a8928 | 1364 | static void usbredir_interrupt_packet(void *priv, uint64_t id, |
69354a83 HG |
1365 | struct usb_redir_interrupt_packet_header *interrupt_packet, |
1366 | uint8_t *data, int data_len) | |
1367 | { | |
1368 | USBRedirDevice *dev = priv; | |
1369 | uint8_t ep = interrupt_packet->endpoint; | |
1370 | ||
be4a8928 | 1371 | DPRINTF("interrupt-in status %d ep %02X len %d id %"PRIu64"\n", |
69354a83 HG |
1372 | interrupt_packet->status, ep, data_len, id); |
1373 | ||
1374 | if (dev->endpoint[EP2I(ep)].type != USB_ENDPOINT_XFER_INT) { | |
1375 | ERROR("received int packet for non interrupt endpoint %02X\n", ep); | |
1376 | free(data); | |
1377 | return; | |
1378 | } | |
1379 | ||
1380 | if (ep & USB_DIR_IN) { | |
1381 | if (dev->endpoint[EP2I(ep)].interrupt_started == 0) { | |
1382 | DPRINTF("received int packet while not started ep %02X\n", ep); | |
1383 | free(data); | |
1384 | return; | |
1385 | } | |
1386 | ||
1387 | /* bufp_alloc also adds the packet to the ep queue */ | |
1388 | bufp_alloc(dev, data, data_len, interrupt_packet->status, ep); | |
1389 | } else { | |
1390 | int len = interrupt_packet->length; | |
1391 | ||
de550a6a HG |
1392 | USBPacket *p = usbredir_find_packet_by_id(dev, ep, id); |
1393 | if (p) { | |
1394 | p->result = usbredir_handle_status(dev, | |
69354a83 | 1395 | interrupt_packet->status, len); |
de550a6a | 1396 | usb_packet_complete(&dev->dev, p); |
69354a83 | 1397 | } |
69354a83 HG |
1398 | } |
1399 | } | |
1400 | ||
3bc36349 AL |
1401 | static Property usbredir_properties[] = { |
1402 | DEFINE_PROP_CHR("chardev", USBRedirDevice, cs), | |
1403 | DEFINE_PROP_UINT8("debug", USBRedirDevice, debug, 0), | |
6af16589 | 1404 | DEFINE_PROP_STRING("filter", USBRedirDevice, filter_str), |
65bb3a5c | 1405 | DEFINE_PROP_INT32("bootindex", USBRedirDevice, bootindex, -1), |
3bc36349 AL |
1406 | DEFINE_PROP_END_OF_LIST(), |
1407 | }; | |
1408 | ||
62aed765 AL |
1409 | static void usbredir_class_initfn(ObjectClass *klass, void *data) |
1410 | { | |
1411 | USBDeviceClass *uc = USB_DEVICE_CLASS(klass); | |
3bc36349 | 1412 | DeviceClass *dc = DEVICE_CLASS(klass); |
62aed765 AL |
1413 | |
1414 | uc->init = usbredir_initfn; | |
1415 | uc->product_desc = "USB Redirection Device"; | |
1416 | uc->handle_destroy = usbredir_handle_destroy; | |
62aed765 AL |
1417 | uc->cancel_packet = usbredir_cancel_packet; |
1418 | uc->handle_reset = usbredir_handle_reset; | |
1419 | uc->handle_data = usbredir_handle_data; | |
1420 | uc->handle_control = usbredir_handle_control; | |
3bc36349 | 1421 | dc->props = usbredir_properties; |
62aed765 AL |
1422 | } |
1423 | ||
3bc36349 AL |
1424 | static TypeInfo usbredir_dev_info = { |
1425 | .name = "usb-redir", | |
1426 | .parent = TYPE_USB_DEVICE, | |
1427 | .instance_size = sizeof(USBRedirDevice), | |
1428 | .class_init = usbredir_class_initfn, | |
69354a83 HG |
1429 | }; |
1430 | ||
83f7d43a | 1431 | static void usbredir_register_types(void) |
69354a83 | 1432 | { |
3bc36349 | 1433 | type_register_static(&usbredir_dev_info); |
69354a83 | 1434 | } |
83f7d43a AF |
1435 | |
1436 | type_init(usbredir_register_types) |