usbdebug_late.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2000,2001,2002,2003,2004,2005,2007,2008,2009,2010,2013 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <grub/serial.h>
  19. #include <grub/types.h>
  20. #include <grub/dl.h>
  21. #include <grub/misc.h>
  22. #include <grub/mm.h>
  23. #include <grub/usb.h>
  24. #include <grub/usbserial.h>
  25. #include <grub/i18n.h>
  26. GRUB_MOD_LICENSE ("GPLv3+");
  27. /* Fetch a key. */
  28. static int
  29. usbdebug_late_hw_fetch (struct grub_serial_port *port)
  30. {
  31. return grub_usbserial_fetch (port, 0);
  32. }
  33. /* Put a character. */
  34. static void
  35. usbdebug_late_hw_put (struct grub_serial_port *port, const int c)
  36. {
  37. char cc = c;
  38. grub_usb_bulk_write (port->usbdev, port->out_endp, 1, &cc);
  39. }
  40. static grub_err_t
  41. usbdebug_late_hw_configure (struct grub_serial_port *port __attribute__ ((unused)),
  42. struct grub_serial_config *config __attribute__ ((unused)))
  43. {
  44. return GRUB_ERR_NONE;
  45. }
  46. static struct grub_serial_driver grub_usbdebug_late_driver =
  47. {
  48. .configure = usbdebug_late_hw_configure,
  49. .fetch = usbdebug_late_hw_fetch,
  50. .put = usbdebug_late_hw_put,
  51. .fini = grub_usbserial_fini
  52. };
  53. static int
  54. grub_usbdebug_late_attach (grub_usb_device_t usbdev, int configno, int interfno)
  55. {
  56. grub_usb_err_t err;
  57. struct grub_usb_desc_debug debugdesc;
  58. err = grub_usb_get_descriptor (usbdev, GRUB_USB_DESCRIPTOR_DEBUG, configno,
  59. sizeof (debugdesc), (char *) &debugdesc);
  60. if (err)
  61. return 0;
  62. return grub_usbserial_attach (usbdev, configno, interfno,
  63. &grub_usbdebug_late_driver,
  64. debugdesc.in_endp, debugdesc.out_endp);
  65. }
  66. static struct grub_usb_attach_desc attach_hook =
  67. {
  68. .class = 0xff,
  69. .hook = grub_usbdebug_late_attach
  70. };
  71. GRUB_MOD_INIT(usbserial_usbdebug_late)
  72. {
  73. grub_usb_register_attach_hook_class (&attach_hook);
  74. }
  75. GRUB_MOD_FINI(usbserial_usbdebug_late)
  76. {
  77. grub_serial_unregister_driver (&grub_usbdebug_late_driver);
  78. grub_usb_unregister_attach_hook_class (&attach_hook);
  79. }