OpenCT  0.6.20
ifd.h
1 /*
2  * Core functions of the IFD handler library
3  *
4  * Copyright (C) 2003, Olaf Kirch <okir@suse.de>
5  */
6 
7 #ifndef OPENCT_IFD_H
8 #define OPENCT_IFD_H
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 #include <sys/types.h>
15 #include <openct/openct.h>
16 #include <openct/apdu.h>
17 
18 typedef struct ifd_device ifd_device_t;
20 
21 enum {
22  IFD_PROTOCOL_DEFAULT = -1,
23  IFD_PROTOCOL_T0 = 0,
24  IFD_PROTOCOL_T1,
25  IFD_PROTOCOL_2WIRE = 16,
26  IFD_PROTOCOL_3WIRE,
27  IFD_PROTOCOL_I2C_SHORT,
28  IFD_PROTOCOL_I2C_LONG,
29  IFD_PROTOCOL_TLP, /* older Gemplus protocol */
30  IFD_PROTOCOL_GBP, /* Gemplus block protocol */
31  IFD_PROTOCOL_EUROCHIP, /* Eurochip Countercard */
32  IFD_PROTOCOL_TCL, /* ISO 14443-4 T=CL */
33  IFD_PROTOCOL_ESCAPE, /* Virtual 'escape' protocol */
34  IFD_PROTOCOL_TRANSPARENT = 128
35 };
36 
37 typedef struct ifd_protocol ifd_protocol_t;
38 
39 typedef struct ifd_driver {
40  const char * name;
41  struct ifd_driver_ops * ops;
42 } ifd_driver_t;
43 
44 #define IFD_MAX_ATR_LEN 64
45 typedef struct ifd_slot {
46  unsigned int handle;
47 
48  int status;
49  time_t next_update;
50 
51  unsigned char dad; /* address when using T=1 */
52  unsigned int atr_len;
53  unsigned char atr[IFD_MAX_ATR_LEN];
54 
55  ifd_protocol_t * proto;
56  void * reader_data;
57 } ifd_slot_t;
58 
59 typedef struct ifd_reader {
60  unsigned int num;
61  unsigned int handle;
62 
63  const char * name;
64  unsigned int flags;
65  unsigned int nslots;
66  ifd_slot_t slot[OPENCT_MAX_SLOTS];
67 
68  const ifd_driver_t * driver;
69  ifd_device_t * device;
70  ct_info_t * status;
71 
72  /* In case the IFD needs to keep state */
73  void * driver_data;
74 } ifd_reader_t;
75 
76 #define IFD_READER_ACTIVE 0x0001
77 #define IFD_READER_HOTPLUG 0x0002
78 #define IFD_READER_DISPLAY 0x0100
79 #define IFD_READER_KEYPAD 0x0200
80 
81 enum {
82  IFD_PROTOCOL_RECV_TIMEOUT = 0x0000,
83  IFD_PROTOCOL_BLOCK_ORIENTED,
84 
85  /* T=0 specific parameters */
86  __IFD_PROTOCOL_T0_PARAM_BASE = IFD_PROTOCOL_T0 << 16,
87 
88  /* T=1 specific parameters */
89  __IFD_PROTOCOL_T1_PARAM_BASE = IFD_PROTOCOL_T1 << 16,
90  IFD_PROTOCOL_T1_BLOCKSIZE,
91  IFD_PROTOCOL_T1_CHECKSUM_CRC,
92  IFD_PROTOCOL_T1_CHECKSUM_LRC,
93  IFD_PROTOCOL_T1_IFSC,
94  IFD_PROTOCOL_T1_IFSD,
95  IFD_PROTOCOL_T1_STATE,
96  IFD_PROTOCOL_T1_MORE
97 };
98 
99 enum {
100  IFD_DAD_HOST = 0,
101  IFD_DAD_IFD,
102  IFD_DAD_ICC1,
103  IFD_DAD_ICC2
104 };
105 
106 
107 extern int ifd_init(void);
108 
109 extern ifd_reader_t * ifd_open(const char *driver_name,
110  const char *device_name);
111 extern void ifd_close(ifd_reader_t *);
112 extern int ifd_reader_count(void);
113 extern int ifd_attach(ifd_reader_t *);
114 extern void ifd_detach(ifd_reader_t *);
115 extern ifd_reader_t * ifd_reader_by_handle(unsigned int handle);
116 extern ifd_reader_t * ifd_reader_by_index(unsigned int index);
117 
118 extern int ifd_spawn_handler(const char *, const char *, int);
119 extern int ifd_scan_usb(void);
120 
121 extern int ifd_activate(ifd_reader_t *);
122 extern int ifd_deactivate(ifd_reader_t *);
123 extern int ifd_output(ifd_reader_t *, const char *);
124 
125 extern int ifd_atr_complete(const unsigned char *, size_t);
126 
127 extern int ifd_set_protocol(ifd_reader_t *reader,
128  unsigned int slot,
129  int id);
130 extern int ifd_card_command(ifd_reader_t *reader,
131  unsigned int slot,
132  const void *sbuf, size_t slen,
133  void *rbuf, size_t rlen);
134 extern int ifd_card_status(ifd_reader_t *reader,
135  unsigned int slot,
136  int *status);
137 extern int ifd_card_reset(ifd_reader_t *reader,
138  unsigned int slot,
139  void *atr_buf,
140  size_t atr_len);
141 extern int ifd_card_request(ifd_reader_t *reader,
142  unsigned int slot,
143  time_t timeout,
144  const char *message,
145  void *atr_buf,
146  size_t atr_len);
147 extern int ifd_card_eject(ifd_reader_t *reader,
148  unsigned int slot,
149  time_t timeout,
150  const char *message);
151 extern int ifd_card_perform_verify(ifd_reader_t *reader,
152  unsigned int slot,
153  time_t timeout,
154  const char *message,
155  const unsigned char *data, size_t data_len,
156  unsigned char *resp, size_t resp_len);
157 extern int ifd_card_read_memory(ifd_reader_t *,
158  unsigned int, unsigned short,
159  unsigned char *, size_t);
160 extern int ifd_card_write_memory(ifd_reader_t *,
161  unsigned int, unsigned short,
162  const unsigned char *, size_t);
163 
164 extern ifd_protocol_t * ifd_protocol_new(int id,
165  ifd_reader_t *reader,
166  unsigned int dad);
167 extern int ifd_protocol_set_parameter(ifd_protocol_t *p,
168  int type,
169  long value);
170 extern int ifd_protocol_get_parameter(ifd_protocol_t *p,
171  int type,
172  long *value);
173 extern int ifd_protocol_read_memory(ifd_protocol_t *,
174  int, unsigned short,
175  unsigned char *, size_t);
176 extern int ifd_protocol_write_memory(ifd_protocol_t *,
177  int, unsigned short,
178  const unsigned char *, size_t);
179 extern void ifd_protocol_free(ifd_protocol_t *);
180 extern int ifd_before_command(ifd_reader_t *);
181 extern int ifd_after_command(ifd_reader_t *);
182 extern int ifd_get_eventfd(ifd_reader_t *, short *);
183 extern void ifd_poll(ifd_reader_t *);
184 extern int id_event(ifd_reader_t *);
185 
186 /* Debugging macro */
187 #ifdef __GNUC__
188 #define ifd_debug(level, fmt, args...) \
189  do { \
190  if ((level) <= ct_config.debug) \
191  ct_debug("%s: " fmt, __FUNCTION__ , ##args); \
192  } while (0)
193 #else
194 extern void ifd_debug(int level, const char *fmt, ...);
195 #endif
196 
197 #ifdef __cplusplus
198 }
199 #endif
200 
201 #endif /* OPENCT_IFD_H */
ct_info
Definition: openct.h:20
ifd_device_params
Definition: device.h:28
ifd_reader
Definition: ifd.h:59
ifd_driver
Definition: ifd.h:39
ifd_driver_ops
Driver operations.
Definition: driver.h:20
ifd_slot
Definition: ifd.h:45

libp11, Copyright (C) 2005 Olaf Kirch <okir@lst.de>OpenSC-Project.org Logo