canokey.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * CanoKey QEMU device header.
  3. *
  4. * Copyright (c) 2021-2022 Canokeys.org <contact@canokeys.org>
  5. * Written by Hongren (Zenithal) Zheng <i@zenithal.me>
  6. *
  7. * This code is licensed under the GPL v2 or later.
  8. */
  9. #ifndef CANOKEY_H
  10. #define CANOKEY_H
  11. #include "hw/qdev-core.h"
  12. #define TYPE_CANOKEY "canokey"
  13. #define CANOKEY(obj) \
  14. OBJECT_CHECK(CanoKeyState, (obj), TYPE_CANOKEY)
  15. /*
  16. * State of Canokey (i.e. hw/canokey.c)
  17. */
  18. /* CTRL INTR BULK */
  19. #define CANOKEY_EP_NUM 3
  20. /* BULK/INTR IN can be up to 1352 bytes, e.g. get key info */
  21. #define CANOKEY_EP_IN_BUFFER_SIZE 2048
  22. typedef enum {
  23. CANOKEY_EP_IN_WAIT,
  24. CANOKEY_EP_IN_READY,
  25. CANOKEY_EP_IN_STALL
  26. } CanoKeyEPState;
  27. typedef struct CanoKeyState {
  28. USBDevice dev;
  29. /* IN packets from canokey device loop */
  30. uint8_t ep_in[CANOKEY_EP_NUM][CANOKEY_EP_IN_BUFFER_SIZE];
  31. /*
  32. * See canokey_emu_transmit
  33. *
  34. * For large INTR IN, receive multiple data from canokey device loop
  35. * in this case ep_in_size would increase with every call
  36. */
  37. uint32_t ep_in_size[CANOKEY_EP_NUM];
  38. /*
  39. * Used in canokey_handle_data
  40. * for IN larger than p->iov.size, we would do multiple handle_data()
  41. *
  42. * The difference between ep_in_pos and ep_in_size:
  43. * We first increase ep_in_size to fill ep_in buffer in device_loop,
  44. * then use ep_in_pos to submit data from ep_in buffer in handle_data
  45. */
  46. uint32_t ep_in_pos[CANOKEY_EP_NUM];
  47. CanoKeyEPState ep_in_state[CANOKEY_EP_NUM];
  48. /* OUT pointer to canokey recv buffer */
  49. uint8_t *ep_out[CANOKEY_EP_NUM];
  50. uint32_t ep_out_size[CANOKEY_EP_NUM];
  51. /* Properties */
  52. char *file; /* canokey-file */
  53. } CanoKeyState;
  54. #endif /* CANOKEY_H */