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