sernum.c 1010 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * fw/sernum.c - ATUSB serial number
  3. *
  4. * Written 2008-2011, 2013 by Werner Almesberger
  5. * Copyright 2008-2011, 2013 Werner Almesberger
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. */
  12. #include <stdbool.h>
  13. #include <stdint.h>
  14. #include "usb.h"
  15. #include "board.h"
  16. #include "sernum.h"
  17. static const uint8_t string_descriptor_0[] = {
  18. 4, /* blength */
  19. USB_DT_STRING, /* bDescriptorType */
  20. LE(USB_LANGID_ENGLISH_US) /* wLANGID[0] */
  21. };
  22. bool sernum_get_descr(uint8_t type, uint8_t index, const uint8_t **reply,
  23. uint8_t *size)
  24. {
  25. if (type != USB_DT_STRING)
  26. return 0;
  27. switch (index) {
  28. case 0:
  29. *reply = string_descriptor_0;
  30. *size = sizeof(string_descriptor_0);
  31. return 1;
  32. case 1:
  33. *reply = board_sernum;
  34. *size = sizeof(board_sernum);
  35. return 1;
  36. default:
  37. return 0;
  38. }
  39. }