xref: /openbmc/qemu/hw/usb/ccid.h (revision ad1a706f)
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 CCIDCardInfo CCIDCardInfo;
17 
18 #define TYPE_CCID_CARD "ccid-card"
19 OBJECT_DECLARE_TYPE(CCIDCardState, CCIDCardClass, CCID_CARD)
20 
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 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);
35 };
36 
37 /*
38  * state of the CCID Card device (i.e. hw/ccid-card-*.c)
39  */
40 struct CCIDCardState {
41     DeviceState qdev;
42     uint32_t    slot; /* For future use with multiple slot reader. */
43 };
44 
45 /*
46  * API for smartcard calling the CCID device (used by hw/ccid-card-*.c)
47  */
48 void ccid_card_send_apdu_to_guest(CCIDCardState *card,
49                                   uint8_t *apdu,
50                                   uint32_t len);
51 void ccid_card_card_removed(CCIDCardState *card);
52 void ccid_card_card_inserted(CCIDCardState *card);
53 void ccid_card_card_error(CCIDCardState *card, uint64_t error);
54 
55 /*
56  * support guest visible insertion/removal of ccid devices based on actual
57  * devices connected/removed. Called by card implementation (passthru, local)
58  */
59 int ccid_card_ccid_attach(CCIDCardState *card);
60 void ccid_card_ccid_detach(CCIDCardState *card);
61 
62 #endif /* CCID_H */
63