blob: ef2bb3462dbc7b0b01a15ef2f53ad9cc44ab0a2f [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
Markus Armbrustera27bd6c2019-08-12 07:23:51 +020013#include "hw/qdev-core.h"
Eduardo Habkostdb1015e2020-09-03 16:43:22 -040014#include "qom/object.h"
Alon Levy36707142010-10-17 11:40:07 +020015
16typedef struct CCIDCardState CCIDCardState;
17typedef struct CCIDCardInfo CCIDCardInfo;
18
Anthony Liguoriba7c0522011-12-04 12:34:10 -060019#define TYPE_CCID_CARD "ccid-card"
Eduardo Habkostdb1015e2020-09-03 16:43:22 -040020typedef struct CCIDCardClass CCIDCardClass;
Eduardo Habkost8110fa12020-08-31 17:07:33 -040021DECLARE_OBJ_CHECKERS(CCIDCardState, CCIDCardClass,
22 CCID_CARD, TYPE_CCID_CARD)
Alon Levy36707142010-10-17 11:40:07 +020023
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 */
Eduardo Habkostdb1015e2020-09-03 16:43:22 -040028struct CCIDCardClass {
Philippe Mathieu-Daudé80ae8652018-01-25 14:14:32 -030029 /*< private >*/
Anthony Liguoriba7c0522011-12-04 12:34:10 -060030 DeviceClass parent_class;
Philippe Mathieu-Daudé80ae8652018-01-25 14:14:32 -030031 /*< public >*/
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);
Mao Zhongyicc847bf2018-01-25 14:14:30 -030036 void (*realize)(CCIDCardState *card, Error **errp);
Markus Armbrusterb69c3c22020-05-05 17:29:24 +020037 void (*unrealize)(CCIDCardState *card);
Eduardo Habkostdb1015e2020-09-03 16:43:22 -040038};
Anthony Liguoriba7c0522011-12-04 12:34:10 -060039
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 */