blob: 68ec98afb17af23c4282478a04fc80bb2e1e6fef [file] [log] [blame]
Harald Welte8d186ad2019-05-15 19:40:29 +02001#pragma once
2#include <stdbool.h>
3#include <stdint.h>
4
Harald Weltee73a1df2019-05-15 22:27:02 +02005enum {
6 DCCID,
7 DUSB,
8};
Harald Welte8d186ad2019-05-15 19:40:29 +02009
10#define NR_SLOTS 8
11
12#define LOGPCI(ci, lvl, fmt, args ...) LOGP(DCCID, lvl, "%s: " fmt, (ci)->name, ## args)
13#define LOGPCS(cs, lvl, fmt, args ...) \
Harald Weltee73a1df2019-05-15 22:27:02 +020014 LOGP(DCCID, lvl, "%s(%u): " fmt, (cs)->ci->name, (cs)->slot_nr, ## args)
Harald Welte8d186ad2019-05-15 19:40:29 +020015
16struct msgb;
17
18struct ccid_pars_decoded {
19 /* global for T0/T1 */
20 uint8_t fi;
21 uint8_t di;
22 enum ccid_clock_stop clock_stop;
23 bool inverse_convention;
24
25 struct {
26 uint8_t guard_time_etu;
27 uint8_t waiting_integer;
28 } t0;
29
30 struct {
31 enum ccid_t1_csum_type csum_type;
32 uint8_t guard_time_t1;
33 uint8_t bwi;
34 uint8_t cwi;
35 uint8_t ifsc;
36 uint8_t nad;
37 } t1;
38};
39
40struct ccid_slot {
41 /* back-pointer to the ccid_instance */
42 struct ccid_instance *ci;
43 /* number of this slot (0 = first) */
44 uint8_t slot_nr;
45 /* is there an ICC physically present (card detect)? */
46 bool icc_present;
47 /* was there an ICC present during the last NotifSlotStatus?
48 * should be set to zero every USB resume and setConfig != 0 */
49 bool icc_present_last;
50 /* is the ICC physically powered? */
51 bool icc_powered;
52 /* is the ICC currently in reset? */
53 bool icc_in_reset;
54 /* is this slot currently busy with processing a CCID command? */
55 bool cmd_busy;
56 /* decided CCID parameters */
57 struct ccid_pars_decoded pars;
58};
59
60/* CCID operations */
61struct ccid_ops {
62 int (*send_in)(struct ccid_instance *ci, struct msgb *msg);
63};
64
65/* An instance of CCID (i.e. a card reader device) */
66struct ccid_instance {
67 /* slots within the reader */
68 struct ccid_slot slot[NR_SLOTS];
69 /* set of function pointers implementing specific operations */
Harald Weltebcbc1972019-05-15 21:57:32 +020070 const struct ccid_ops *ops;
Harald Welte8d186ad2019-05-15 19:40:29 +020071 const char *name;
Harald Weltebcbc1972019-05-15 21:57:32 +020072 /* user-supplied opaque data */
73 void *priv;
Harald Welte8d186ad2019-05-15 19:40:29 +020074};
75
Harald Weltebcbc1972019-05-15 21:57:32 +020076void ccid_instance_init(struct ccid_instance *ci, const struct ccid_ops *ops, const char *name,
77 void *priv);
Harald Welte8d186ad2019-05-15 19:40:29 +020078int ccid_handle_out(struct ccid_instance *ci, struct msgb *msg);