quirks.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * USB quirk handling
  3. *
  4. * Copyright (c) 2012 Red Hat, Inc.
  5. *
  6. * Red Hat Authors:
  7. * Hans de Goede <hdegoede@redhat.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. */
  14. #include "quirks.h"
  15. #include "hw/usb.h"
  16. static bool usb_id_match(const struct usb_device_id *ids,
  17. uint16_t vendor_id, uint16_t product_id,
  18. uint8_t interface_class, uint8_t interface_subclass,
  19. uint8_t interface_protocol) {
  20. int i;
  21. for (i = 0; ids[i].vendor_id != -1; i++) {
  22. if (ids[i].vendor_id == vendor_id &&
  23. ids[i].product_id == product_id &&
  24. (ids[i].interface_class == -1 ||
  25. (ids[i].interface_class == interface_class &&
  26. ids[i].interface_subclass == interface_subclass &&
  27. ids[i].interface_protocol == interface_protocol))) {
  28. return true;
  29. }
  30. }
  31. return false;
  32. }
  33. int usb_get_quirks(uint16_t vendor_id, uint16_t product_id,
  34. uint8_t interface_class, uint8_t interface_subclass,
  35. uint8_t interface_protocol)
  36. {
  37. int quirks = 0;
  38. if (usb_id_match(usbredir_raw_serial_ids, vendor_id, product_id,
  39. interface_class, interface_subclass, interface_protocol)) {
  40. quirks |= USB_QUIRK_BUFFER_BULK_IN;
  41. }
  42. if (usb_id_match(usbredir_ftdi_serial_ids, vendor_id, product_id,
  43. interface_class, interface_subclass, interface_protocol)) {
  44. quirks |= USB_QUIRK_BUFFER_BULK_IN | USB_QUIRK_IS_FTDI;
  45. }
  46. return quirks;
  47. }