blob: d0fcdc0d738143e34f0fd63064e55f99f2f1b2a9 [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 {
Harald Weltee6ac4162019-05-16 11:18:00 +020062 /* msgb ownership in below functions is transferred, i.e. whoever
63 * provides the callback function must make sure to msgb_free() them
64 * once transmission on IN or INT EP has completed. */
Harald Welte8d186ad2019-05-15 19:40:29 +020065 int (*send_in)(struct ccid_instance *ci, struct msgb *msg);
Harald Weltea7da5042019-05-16 11:08:35 +020066 int (*send_int)(struct ccid_instance *ci, struct msgb *msg);
Harald Welte8d186ad2019-05-15 19:40:29 +020067};
68
69/* An instance of CCID (i.e. a card reader device) */
70struct ccid_instance {
71 /* slots within the reader */
72 struct ccid_slot slot[NR_SLOTS];
73 /* set of function pointers implementing specific operations */
Harald Weltebcbc1972019-05-15 21:57:32 +020074 const struct ccid_ops *ops;
Harald Welte8d186ad2019-05-15 19:40:29 +020075 const char *name;
Harald Weltebcbc1972019-05-15 21:57:32 +020076 /* user-supplied opaque data */
77 void *priv;
Harald Welte8d186ad2019-05-15 19:40:29 +020078};
79
Harald Weltebcbc1972019-05-15 21:57:32 +020080void ccid_instance_init(struct ccid_instance *ci, const struct ccid_ops *ops, const char *name,
81 void *priv);
Harald Welte8d186ad2019-05-15 19:40:29 +020082int ccid_handle_out(struct ccid_instance *ci, struct msgb *msg);