blob: cc93319f7ec025bfd4ce94d272b51b822181ed5c [file] [log] [blame]
Harald Welte3aa901d2018-08-13 18:32:36 +02001#pragma once
2
3#include <osmocom/core/linuxlist.h>
4
5struct card_reader_slot;
6
7struct card_reader_driver_ops {
8 /* probe system for card readers */
9 void (*probe)(void *ctx);
10 /* open a given slot, attempt to reset/start the card */
11 int (*open_slot)(struct card_reader_slot *slot);
12 /* close a given slot, power down the card */
13 void (*close_slot)(struct card_reader_slot *slot);
14 /* transceive an APDU */
15 int (*transceive_apdu)(struct card_reader_slot *slot);
16};
17
18struct card_reader_driver {
19 /* global list of drivers */
20 struct llist_head list;
21 /* name of the driver */
22 char *name;
23 const struct card_reader_driver_ops *ops;
24};
25
26struct card_reader {
27 /* global list of card readers */
28 struct llist_head list;
29 /* name of this reader */
30 char *name;
31 /* driver providing access to this reader */
32 const struct card_reader_driver *drv;
33 void *drv_handle;
34 /* list of card slots for this reader */
35 struct llist_head slots;
36};
37
38enum card_slot_state {
39 CARD_SLOT_OFF,
40 CARD_SLOT_OPEN,
41};
42
43struct card_reader_slot {
44 /* links to card_reader.slots */
45 struct llist_head list;
46 /* back-pointer to reader serving this slot */
47 struct card_reader *reader;
48 /* slot number */
49 unsigned int num;
50 /* state in which the slot is */
51 enum card_slot_state state;
52};
53
54
55struct card_reader *card_reader_alloc(void *ctx, const char *name,
56 const struct card_reader_driver *drv, void *drv_handle);
57struct card_reader_slot *card_reader_slot_alloc(struct card_reader *cr, unsigned int slot_num);
58
59void card_reader_driver_register(struct card_reader_driver *drv);
60void card_readers_probe(void *ctx);