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