ccid.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * CCID Passthru Card Device emulation
  3. *
  4. * Copyright (c) 2011 Red Hat.
  5. * Written by Alon Levy.
  6. *
  7. * This code is licensed under the GNU LGPL, version 2 or later.
  8. */
  9. #ifndef CCID_H
  10. #define CCID_H
  11. #include "hw/qdev-core.h"
  12. typedef struct CCIDCardState CCIDCardState;
  13. typedef struct CCIDCardInfo CCIDCardInfo;
  14. #define TYPE_CCID_CARD "ccid-card"
  15. #define CCID_CARD(obj) \
  16. OBJECT_CHECK(CCIDCardState, (obj), TYPE_CCID_CARD)
  17. #define CCID_CARD_CLASS(klass) \
  18. OBJECT_CLASS_CHECK(CCIDCardClass, (klass), TYPE_CCID_CARD)
  19. #define CCID_CARD_GET_CLASS(obj) \
  20. OBJECT_GET_CLASS(CCIDCardClass, (obj), TYPE_CCID_CARD)
  21. /*
  22. * callbacks to be used by the CCID device (hw/usb-ccid.c) to call
  23. * into the smartcard device (hw/ccid-card-*.c)
  24. */
  25. typedef struct CCIDCardClass {
  26. /*< private >*/
  27. DeviceClass parent_class;
  28. /*< public >*/
  29. const uint8_t *(*get_atr)(CCIDCardState *card, uint32_t *len);
  30. void (*apdu_from_guest)(CCIDCardState *card,
  31. const uint8_t *apdu,
  32. uint32_t len);
  33. void (*realize)(CCIDCardState *card, Error **errp);
  34. void (*unrealize)(CCIDCardState *card, Error **errp);
  35. } CCIDCardClass;
  36. /*
  37. * state of the CCID Card device (i.e. hw/ccid-card-*.c)
  38. */
  39. struct CCIDCardState {
  40. DeviceState qdev;
  41. uint32_t slot; /* For future use with multiple slot reader. */
  42. };
  43. /*
  44. * API for smartcard calling the CCID device (used by hw/ccid-card-*.c)
  45. */
  46. void ccid_card_send_apdu_to_guest(CCIDCardState *card,
  47. uint8_t *apdu,
  48. uint32_t len);
  49. void ccid_card_card_removed(CCIDCardState *card);
  50. void ccid_card_card_inserted(CCIDCardState *card);
  51. void ccid_card_card_error(CCIDCardState *card, uint64_t error);
  52. /*
  53. * support guest visible insertion/removal of ccid devices based on actual
  54. * devices connected/removed. Called by card implementation (passthru, local)
  55. */
  56. int ccid_card_ccid_attach(CCIDCardState *card);
  57. void ccid_card_ccid_detach(CCIDCardState *card);
  58. #endif /* CCID_H */