blob: 6adc745a6d1f250ccb85ca4a178572f2897177a2 [file] [log] [blame]
Alon Levy36707142010-10-17 11:40:07 +02001/*
2 * CCID Passthru Card Device emulation
3 *
4 * Copyright (c) 2011 Red Hat.
5 * Written by Alon Levy.
6 *
Matthew Fernandez8e31bf32011-06-26 12:21:35 +10007 * This code is licensed under the GNU LGPL, version 2 or later.
Alon Levy36707142010-10-17 11:40:07 +02008 */
9
10#ifndef CCID_H
11#define CCID_H
12
13#include "qdev.h"
14
15typedef struct CCIDCardState CCIDCardState;
16typedef struct CCIDCardInfo CCIDCardInfo;
17
Anthony Liguoriba7c0522011-12-04 12:34:10 -060018#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)
Alon Levy36707142010-10-17 11:40:07 +020025
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 */
Anthony Liguoriba7c0522011-12-04 12:34:10 -060030typedef struct CCIDCardClass {
31 DeviceClass parent_class;
Alon Levy36707142010-10-17 11:40:07 +020032 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 int (*exitfn)(CCIDCardState *card);
37 int (*initfn)(CCIDCardState *card);
Anthony Liguoriba7c0522011-12-04 12:34:10 -060038} CCIDCardClass;
39
40/*
41 * state of the CCID Card device (i.e. hw/ccid-card-*.c)
42 */
43struct CCIDCardState {
44 DeviceState qdev;
45 uint32_t slot; /* For future use with multiple slot reader. */
Alon Levy36707142010-10-17 11:40:07 +020046};
47
48/*
49 * API for smartcard calling the CCID device (used by hw/ccid-card-*.c)
50 */
51void ccid_card_send_apdu_to_guest(CCIDCardState *card,
52 uint8_t *apdu,
53 uint32_t len);
54void ccid_card_card_removed(CCIDCardState *card);
55void ccid_card_card_inserted(CCIDCardState *card);
56void ccid_card_card_error(CCIDCardState *card, uint64_t error);
Alon Levy36707142010-10-17 11:40:07 +020057
58/*
59 * support guest visible insertion/removal of ccid devices based on actual
60 * devices connected/removed. Called by card implementation (passthru, local)
61 */
62int ccid_card_ccid_attach(CCIDCardState *card);
63void ccid_card_ccid_detach(CCIDCardState *card);
64
65#endif /* CCID_H */