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 10 #ifndef CCID_H 11 #define CCID_H 12 13 #include "hw/qdev.h" 14 15 typedef struct CCIDCardState CCIDCardState; 16 typedef struct CCIDCardInfo CCIDCardInfo; 17 18 #define TYPE_CCID_CARD "ccid-card" 19 #define CCID_CARD(obj) \ 20 OBJECT_CHECK(CCIDCardState, (obj), TYPE_CCID_CARD) 21 #define CCID_CARD_CLASS(klass) \ 22 OBJECT_CLASS_CHECK(CCIDCardClass, (klass), TYPE_CCID_CARD) 23 #define CCID_CARD_GET_CLASS(obj) \ 24 OBJECT_GET_CLASS(CCIDCardClass, (obj), TYPE_CCID_CARD) 25 26 /* 27 * callbacks to be used by the CCID device (hw/usb-ccid.c) to call 28 * into the smartcard device (hw/ccid-card-*.c) 29 */ 30 typedef struct CCIDCardClass { 31 /*< private >*/ 32 DeviceClass parent_class; 33 /*< public >*/ 34 const uint8_t *(*get_atr)(CCIDCardState *card, uint32_t *len); 35 void (*apdu_from_guest)(CCIDCardState *card, 36 const uint8_t *apdu, 37 uint32_t len); 38 void (*realize)(CCIDCardState *card, Error **errp); 39 void (*unrealize)(CCIDCardState *card, Error **errp); 40 } CCIDCardClass; 41 42 /* 43 * state of the CCID Card device (i.e. hw/ccid-card-*.c) 44 */ 45 struct CCIDCardState { 46 DeviceState qdev; 47 uint32_t slot; /* For future use with multiple slot reader. */ 48 }; 49 50 /* 51 * API for smartcard calling the CCID device (used by hw/ccid-card-*.c) 52 */ 53 void ccid_card_send_apdu_to_guest(CCIDCardState *card, 54 uint8_t *apdu, 55 uint32_t len); 56 void ccid_card_card_removed(CCIDCardState *card); 57 void ccid_card_card_inserted(CCIDCardState *card); 58 void ccid_card_card_error(CCIDCardState *card, uint64_t error); 59 60 /* 61 * support guest visible insertion/removal of ccid devices based on actual 62 * devices connected/removed. Called by card implementation (passthru, local) 63 */ 64 int ccid_card_ccid_attach(CCIDCardState *card); 65 void ccid_card_ccid_detach(CCIDCardState *card); 66 67 #endif /* CCID_H */ 68