00001
00002
00003
00004
00005
00006
00007 #ifndef OPENCT_IFD_H
00008 #define OPENCT_IFD_H
00009
00010 #ifdef __cplusplus
00011 extern "C" {
00012 #endif
00013
00014 #include <sys/types.h>
00015 #include <openct/openct.h>
00016 #include <openct/apdu.h>
00017
00018 typedef struct ifd_device ifd_device_t;
00019 typedef union ifd_device_params ifd_device_params_t;
00020
00021 enum {
00022 IFD_PROTOCOL_DEFAULT = -1,
00023 IFD_PROTOCOL_T0 = 0,
00024 IFD_PROTOCOL_T1,
00025 IFD_PROTOCOL_2WIRE = 16,
00026 IFD_PROTOCOL_3WIRE,
00027 IFD_PROTOCOL_I2C_SHORT,
00028 IFD_PROTOCOL_I2C_LONG,
00029 IFD_PROTOCOL_TLP,
00030 IFD_PROTOCOL_GBP,
00031 IFD_PROTOCOL_EUROCHIP,
00032 IFD_PROTOCOL_TRANSPARENT = 128
00033 };
00034
00035 typedef struct ifd_protocol ifd_protocol_t;
00036
00037 typedef struct ifd_driver {
00038 const char * name;
00039 struct ifd_driver_ops * ops;
00040 } ifd_driver_t;
00041
00042 #define IFD_MAX_ATR_LEN 64
00043 typedef struct ifd_slot {
00044 unsigned int handle;
00045
00046 int status;
00047 time_t next_update;
00048
00049 unsigned char dad;
00050 unsigned int atr_len;
00051 unsigned char atr[IFD_MAX_ATR_LEN];
00052
00053 ifd_protocol_t * proto;
00054 void * reader_data;
00055 } ifd_slot_t;
00056
00057 typedef struct ifd_reader {
00058 unsigned int num;
00059 unsigned int handle;
00060
00061 const char * name;
00062 unsigned int flags;
00063 unsigned int nslots;
00064 ifd_slot_t slot[OPENCT_MAX_SLOTS];
00065
00066 const ifd_driver_t * driver;
00067 ifd_device_t * device;
00068 ct_info_t * status;
00069
00070
00071 void * driver_data;
00072 } ifd_reader_t;
00073
00074 #define IFD_READER_ACTIVE 0x0001
00075 #define IFD_READER_HOTPLUG 0x0002
00076 #define IFD_READER_DISPLAY 0x0100
00077 #define IFD_READER_KEYPAD 0x0200
00078
00079 enum {
00080 IFD_PROTOCOL_RECV_TIMEOUT = 0x0000,
00081 IFD_PROTOCOL_BLOCK_ORIENTED,
00082
00083
00084 __IFD_PROTOCOL_T0_PARAM_BASE = IFD_PROTOCOL_T0 << 16,
00085
00086
00087 __IFD_PROTOCOL_T1_PARAM_BASE = IFD_PROTOCOL_T1 << 16,
00088 IFD_PROTOCOL_T1_BLOCKSIZE,
00089 IFD_PROTOCOL_T1_CHECKSUM_CRC,
00090 IFD_PROTOCOL_T1_CHECKSUM_LRC,
00091 IFD_PROTOCOL_T1_IFSC,
00092 IFD_PROTOCOL_T1_IFSD,
00093 IFD_PROTOCOL_T1_STATE,
00094 IFD_PROTOCOL_T1_MORE
00095 };
00096
00097 enum {
00098 IFD_DAD_HOST = 0,
00099 IFD_DAD_IFD,
00100 IFD_DAD_ICC1,
00101 IFD_DAD_ICC2
00102 };
00103
00104
00105 extern int ifd_init(void);
00106
00107 extern ifd_reader_t * ifd_open(const char *driver_name,
00108 const char *device_name);
00109 extern void ifd_close(ifd_reader_t *);
00110 extern int ifd_reader_count(void);
00111 extern int ifd_attach(ifd_reader_t *);
00112 extern void ifd_detach(ifd_reader_t *);
00113 extern ifd_reader_t * ifd_reader_by_handle(unsigned int handle);
00114 extern ifd_reader_t * ifd_reader_by_index(unsigned int index);
00115
00116 extern int ifd_spawn_handler(const char *, const char *, int);
00117 extern int ifd_scan_usb(void);
00118
00119 extern int ifd_activate(ifd_reader_t *);
00120 extern int ifd_deactivate(ifd_reader_t *);
00121 extern int ifd_output(ifd_reader_t *, const char *);
00122
00123 extern int ifd_atr_complete(const unsigned char *, size_t);
00124
00125 extern int ifd_set_protocol(ifd_reader_t *reader,
00126 unsigned int slot,
00127 int id);
00128 extern int ifd_card_command(ifd_reader_t *reader,
00129 unsigned int slot,
00130 const void *sbuf, size_t slen,
00131 void *rbuf, size_t rlen);
00132 extern int ifd_card_status(ifd_reader_t *reader,
00133 unsigned int slot,
00134 int *status);
00135 extern int ifd_card_reset(ifd_reader_t *reader,
00136 unsigned int slot,
00137 void *atr_buf,
00138 size_t atr_len);
00139 extern int ifd_card_request(ifd_reader_t *reader,
00140 unsigned int slot,
00141 time_t timeout,
00142 const char *message,
00143 void *atr_buf,
00144 size_t atr_len);
00145 extern int ifd_card_eject(ifd_reader_t *reader,
00146 unsigned int slot,
00147 time_t timeout,
00148 const char *message);
00149 extern int ifd_card_perform_verify(ifd_reader_t *reader,
00150 unsigned int slot,
00151 time_t timeout,
00152 const char *message,
00153 const unsigned char *data, size_t data_len,
00154 unsigned char *resp, size_t resp_len);
00155 extern int ifd_card_read_memory(ifd_reader_t *,
00156 unsigned int, unsigned short,
00157 unsigned char *, size_t);
00158 extern int ifd_card_write_memory(ifd_reader_t *,
00159 unsigned int, unsigned short,
00160 const unsigned char *, size_t);
00161
00162 extern ifd_protocol_t * ifd_protocol_new(int id,
00163 ifd_reader_t *reader,
00164 unsigned int dad);
00165 extern int ifd_protocol_set_parameter(ifd_protocol_t *p,
00166 int type,
00167 long value);
00168 extern int ifd_protocol_get_parameter(ifd_protocol_t *p,
00169 int type,
00170 long *value);
00171 extern int ifd_protocol_read_memory(ifd_protocol_t *,
00172 int, unsigned short,
00173 unsigned char *, size_t);
00174 extern int ifd_protocol_write_memory(ifd_protocol_t *,
00175 int, unsigned short,
00176 const unsigned char *, size_t);
00177 extern void ifd_protocol_free(ifd_protocol_t *);
00178
00179
00180 #ifdef __GNUC__
00181 #define ifd_debug(level, fmt, args...) \
00182 do { \
00183 if ((level) <= ct_config.debug) \
00184 ct_debug("%s: " fmt, __FUNCTION__ , ##args); \
00185 } while (0)
00186 #else
00187 extern void ifd_debug(int level, const char *fmt, ...);
00188 #endif
00189
00190 #ifdef __cplusplus
00191 }
00192 #endif
00193
00194 #endif