usb_desc.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * usb_desc.c
  3. *
  4. * Copyright (C) 2019 Sylvain Munaut
  5. * All rights reserved.
  6. *
  7. * LGPL v3+, see LICENSE.lgpl3
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 3 of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public License
  20. * along with this program; if not, write to the Free Software Foundation,
  21. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. */
  23. #include <stdint.h>
  24. #include "usb_desc_data.h"
  25. #define NULL ((void*)0)
  26. #define num_elem(a) (sizeof(a) / sizeof(a[0]))
  27. const void *
  28. usb_get_device_desc(int *len)
  29. {
  30. *len = Devices[0][0];
  31. return Devices[0];
  32. }
  33. const void *
  34. usb_get_config_desc(int *len, int idx)
  35. {
  36. if (idx < num_elem(Configurations)) {
  37. *len = Configurations[idx][2] + (Configurations[idx][3] << 8);
  38. return Configurations[idx];
  39. } else {
  40. *len = 0;
  41. return NULL;
  42. }
  43. }
  44. const void *
  45. usb_get_string_desc(int *len, int idx)
  46. {
  47. if (idx <= 0) {
  48. *len = StringZeros[0][0];
  49. return StringZeros[0];
  50. } else if ((idx-1) < num_elem(Strings)) {
  51. *len = Strings[idx-1][0];
  52. return Strings[idx-1];
  53. } else {
  54. *len = 0;
  55. return NULL;
  56. }
  57. }