Harald Welte | 8d186ad | 2019-05-15 19:40:29 +0200 | [diff] [blame] | 1 | #pragma once |
| 2 | #include <stdbool.h> |
| 3 | #include <stdint.h> |
| 4 | |
Harald Welte | e73a1df | 2019-05-15 22:27:02 +0200 | [diff] [blame^] | 5 | enum { |
| 6 | DCCID, |
| 7 | DUSB, |
| 8 | }; |
Harald Welte | 8d186ad | 2019-05-15 19:40:29 +0200 | [diff] [blame] | 9 | |
| 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 Welte | e73a1df | 2019-05-15 22:27:02 +0200 | [diff] [blame^] | 14 | LOGP(DCCID, lvl, "%s(%u): " fmt, (cs)->ci->name, (cs)->slot_nr, ## args) |
Harald Welte | 8d186ad | 2019-05-15 19:40:29 +0200 | [diff] [blame] | 15 | |
| 16 | struct msgb; |
| 17 | |
| 18 | struct 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 | |
| 40 | struct 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 */ |
| 61 | struct 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) */ |
| 66 | struct ccid_instance { |
| 67 | /* slots within the reader */ |
| 68 | struct ccid_slot slot[NR_SLOTS]; |
| 69 | /* set of function pointers implementing specific operations */ |
Harald Welte | bcbc197 | 2019-05-15 21:57:32 +0200 | [diff] [blame] | 70 | const struct ccid_ops *ops; |
Harald Welte | 8d186ad | 2019-05-15 19:40:29 +0200 | [diff] [blame] | 71 | const char *name; |
Harald Welte | bcbc197 | 2019-05-15 21:57:32 +0200 | [diff] [blame] | 72 | /* user-supplied opaque data */ |
| 73 | void *priv; |
Harald Welte | 8d186ad | 2019-05-15 19:40:29 +0200 | [diff] [blame] | 74 | }; |
| 75 | |
Harald Welte | bcbc197 | 2019-05-15 21:57:32 +0200 | [diff] [blame] | 76 | void ccid_instance_init(struct ccid_instance *ci, const struct ccid_ops *ops, const char *name, |
| 77 | void *priv); |
Harald Welte | 8d186ad | 2019-05-15 19:40:29 +0200 | [diff] [blame] | 78 | int ccid_handle_out(struct ccid_instance *ci, struct msgb *msg); |