Harald Welte | cab5d15 | 2019-05-16 13:31:16 +0200 | [diff] [blame^] | 1 | /* Simulated CCID card slot. This is used in absence of a real hardware back-end |
| 2 | * in order to test the CCID firmware codebase in a virtual environment */ |
| 3 | |
| 4 | #include "ccid_device.h" |
| 5 | |
| 6 | static const struct ccid_pars_decoded slotsim_def_pars = { |
| 7 | .fi = 0, |
| 8 | .di = 0, |
| 9 | .clock_stop = CCID_CLOCK_STOP_NOTALLOWED, |
| 10 | .inverse_convention = false, |
| 11 | .t0 = { |
| 12 | .guard_time_etu = 0, |
| 13 | .waiting_integer = 0, |
| 14 | }, |
| 15 | /* FIXME: T=1 */ |
| 16 | }; |
| 17 | |
| 18 | static void slotsim_pre_proc_cb(struct ccid_slot *cs, struct msgb *msg) |
| 19 | { |
| 20 | /* do nothing; real hardware would update the slot related state here */ |
| 21 | } |
| 22 | |
| 23 | static void slotsim_set_power(struct ccid_slot *cs, bool enable) |
| 24 | { |
| 25 | if (enable) { |
| 26 | cs->icc_powered = true; |
| 27 | /* FIXME: What to do about ATR? */ |
| 28 | } else { |
| 29 | cs->icc_powered = false; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | static void slotsim_set_clock(struct ccid_slot *cs, enum ccid_clock_command cmd) |
| 34 | { |
| 35 | /* FIXME */ |
| 36 | switch (cmd) { |
| 37 | case CCID_CLOCK_CMD_STOP: |
| 38 | break; |
| 39 | case CCID_CLOCK_CMD_RESTART: |
| 40 | break; |
| 41 | default: |
| 42 | OSMO_ASSERT(0); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | static int slotsim_set_params(struct ccid_slot *cs, enum ccid_protocol_num proto, |
| 47 | const struct ccid_pars_decoded *pars_dec) |
| 48 | { |
| 49 | /* we always acknowledge all parameters */ |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | static int slotsim_set_rate_and_clock(struct ccid_slot *cs, uint32_t freq_hz, uint32_t rate_bps) |
| 54 | { |
| 55 | /* we always acknowledge all rates/clocks */ |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | static int slotsim_init(struct ccid_slot *cs) |
| 60 | { |
| 61 | cs->default_pars = &slotsim_def_pars; |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | const struct ccid_slot_ops slotsim_slot_ops = { |
| 66 | .init = slotsim_init, |
| 67 | .pre_proc_cb = slotsim_pre_proc_cb, |
| 68 | .set_power = slotsim_set_power, |
| 69 | .set_clock = slotsim_set_clock, |
| 70 | .set_params = slotsim_set_params, |
| 71 | .set_rate_and_clock = slotsim_set_rate_and_clock, |
| 72 | }; |