| 1 | /* |
|---|
| 2 | * Core functions of the IFD handler library |
|---|
| 3 | * |
|---|
| 4 | * Copyright (C) 2003, Olaf Kirch <okir@suse.de> |
|---|
| 5 | */ |
|---|
| 6 | |
|---|
| 7 | #ifndef IFD_INTERNAL_H |
|---|
| 8 | #define IFD_INTERNAL_H |
|---|
| 9 | |
|---|
| 10 | #ifdef HAVE_CONFIG_H |
|---|
| 11 | #include <config.h> |
|---|
| 12 | #endif |
|---|
| 13 | #ifdef HAVE_SYS_TIME_H |
|---|
| 14 | #include <sys/time.h> |
|---|
| 15 | #endif |
|---|
| 16 | #include <openct/types.h> |
|---|
| 17 | #include <openct/ifd.h> |
|---|
| 18 | #include <openct/device.h> |
|---|
| 19 | #include <openct/driver.h> |
|---|
| 20 | #include <openct/conf.h> |
|---|
| 21 | #include <openct/logging.h> |
|---|
| 22 | #include <openct/error.h> |
|---|
| 23 | #include <openct/buffer.h> |
|---|
| 24 | |
|---|
| 25 | struct ifd_device { |
|---|
| 26 | char *name; |
|---|
| 27 | int type; |
|---|
| 28 | long timeout; |
|---|
| 29 | |
|---|
| 30 | unsigned int hotplug:1; |
|---|
| 31 | |
|---|
| 32 | int fd; |
|---|
| 33 | void *dev; /* use instead of fd, if no fd available for implementation */ |
|---|
| 34 | |
|---|
| 35 | ifd_device_params_t settings; |
|---|
| 36 | struct ifd_device_ops *ops; |
|---|
| 37 | |
|---|
| 38 | void *user_data; |
|---|
| 39 | |
|---|
| 40 | /* per-device data may follow */ |
|---|
| 41 | |
|---|
| 42 | unsigned int etu; /* XXX: unnecessary? */ |
|---|
| 43 | }; |
|---|
| 44 | |
|---|
| 45 | struct ifd_device_ops { |
|---|
| 46 | /* Reset device */ |
|---|
| 47 | int (*reset) (ifd_device_t *); |
|---|
| 48 | |
|---|
| 49 | int (*set_params) (ifd_device_t *, const ifd_device_params_t *); |
|---|
| 50 | int (*get_params) (ifd_device_t *, ifd_device_params_t *); |
|---|
| 51 | |
|---|
| 52 | /* Flush any pending input */ |
|---|
| 53 | void (*flush) (ifd_device_t *); |
|---|
| 54 | void (*send_break) (ifd_device_t *, unsigned int); |
|---|
| 55 | |
|---|
| 56 | /* |
|---|
| 57 | * Send/receive data. Some devices such as USB will support |
|---|
| 58 | * the transceive command, others such as serial devices will |
|---|
| 59 | * need to use send/recv |
|---|
| 60 | */ |
|---|
| 61 | int (*transceive) (ifd_device_t *, |
|---|
| 62 | const void *, size_t, void *, size_t, long); |
|---|
| 63 | int (*send) (ifd_device_t *, const unsigned char *, size_t); |
|---|
| 64 | int (*recv) (ifd_device_t *, unsigned char *, size_t, long); |
|---|
| 65 | int (*control) (ifd_device_t *, void *, size_t); |
|---|
| 66 | |
|---|
| 67 | void (*close) (ifd_device_t *); |
|---|
| 68 | |
|---|
| 69 | int (*get_eventfd) (ifd_device_t *, short *events); |
|---|
| 70 | |
|---|
| 71 | /* Poll for device presence. This function is called |
|---|
| 72 | * prior to the poll call (with revents == 0), in this |
|---|
| 73 | * case poll_presence is supposed to set up the poll |
|---|
| 74 | * structure. |
|---|
| 75 | * Then, it is called after poll() returns - in this case |
|---|
| 76 | * it should check the contents of pollfd to find out |
|---|
| 77 | * whether the device got removed. |
|---|
| 78 | * |
|---|
| 79 | * This is pretty much tailored for USB support, so |
|---|
| 80 | * the addition of PCMCIA devices may cause this |
|---|
| 81 | * to change. |
|---|
| 82 | */ |
|---|
| 83 | int (*poll_presence) (ifd_device_t *, struct pollfd *); |
|---|
| 84 | }; |
|---|
| 85 | |
|---|
| 86 | struct ifd_protocol_ops { |
|---|
| 87 | int id; |
|---|
| 88 | const char *name; |
|---|
| 89 | size_t size; |
|---|
| 90 | int (*init) (ifd_protocol_t *); |
|---|
| 91 | void (*release) (ifd_protocol_t *); |
|---|
| 92 | int (*set_param) (ifd_protocol_t *, int, long); |
|---|
| 93 | int (*get_param) (ifd_protocol_t *, int, long *); |
|---|
| 94 | int (*resynchronize) (ifd_protocol_t *, int dad); |
|---|
| 95 | int (*transceive) (ifd_protocol_t *, int dad, |
|---|
| 96 | const void *, size_t, void *, size_t); |
|---|
| 97 | int (*sync_read) (ifd_protocol_t *, int, |
|---|
| 98 | unsigned short, unsigned char *, size_t); |
|---|
| 99 | int (*sync_write) (ifd_protocol_t *, int, |
|---|
| 100 | unsigned short, const unsigned char *, size_t); |
|---|
| 101 | }; |
|---|
| 102 | |
|---|
| 103 | struct ifd_protocol { |
|---|
| 104 | ifd_reader_t *reader; |
|---|
| 105 | unsigned int dad; |
|---|
| 106 | struct ifd_protocol_ops *ops; |
|---|
| 107 | }; |
|---|
| 108 | |
|---|
| 109 | extern struct ifd_protocol_ops ifd_protocol_t1; |
|---|
| 110 | extern struct ifd_protocol_ops ifd_protocol_t0; |
|---|
| 111 | extern struct ifd_protocol_ops ifd_protocol_gbp; |
|---|
| 112 | extern struct ifd_protocol_ops ifd_protocol_trans; |
|---|
| 113 | extern struct ifd_protocol_ops ifd_protocol_i2c_short; |
|---|
| 114 | extern struct ifd_protocol_ops ifd_protocol_i2c_long; |
|---|
| 115 | extern struct ifd_protocol_ops ifd_protocol_2wire; |
|---|
| 116 | extern struct ifd_protocol_ops ifd_protocol_3wire; |
|---|
| 117 | extern struct ifd_protocol_ops ifd_protocol_eurochip; |
|---|
| 118 | extern struct ifd_protocol_ops ifd_protocol_esc; |
|---|
| 119 | |
|---|
| 120 | extern void ifd_acr30u_register(void); |
|---|
| 121 | extern void ifd_cardman_register(void); |
|---|
| 122 | extern void ifd_ccid_register(void); |
|---|
| 123 | extern void ifd_cm4000_register(void); |
|---|
| 124 | extern void ifd_egate_register(void); |
|---|
| 125 | extern void ifd_epass3k_register(void); |
|---|
| 126 | extern void ifd_etoken_register(void); |
|---|
| 127 | extern void ifd_etoken64_register(void); |
|---|
| 128 | extern void ifd_eutron_register(void); |
|---|
| 129 | extern void ifd_gempc_register(void); |
|---|
| 130 | extern void ifd_ikey2k_register(void); |
|---|
| 131 | extern void ifd_ikey3k_register(void); |
|---|
| 132 | extern void ifd_kaan_register(void); |
|---|
| 133 | extern void ifd_pertosmart_ac1030_register(void); |
|---|
| 134 | extern void ifd_pertosmart_ac1038_register(void); |
|---|
| 135 | extern void ifd_smartboard_register(void); |
|---|
| 136 | extern void ifd_smph_register(void); |
|---|
| 137 | extern void ifd_starkey_register(void); |
|---|
| 138 | extern void ifd_towitoko_register(void); |
|---|
| 139 | /* extern void ifd_wbeiuu_register(void); driver not working yet */ |
|---|
| 140 | extern void ifd_cyberjack_register(void); |
|---|
| 141 | extern void ifd_rutoken_register(void); |
|---|
| 142 | |
|---|
| 143 | /* reader.c */ |
|---|
| 144 | extern int ifd_error(ifd_reader_t *); |
|---|
| 145 | extern int ifd_event(ifd_reader_t *); |
|---|
| 146 | extern int ifd_send_command(ifd_protocol_t *, const void *, size_t); |
|---|
| 147 | extern int ifd_recv_response(ifd_protocol_t *, void *, size_t, long); |
|---|
| 148 | |
|---|
| 149 | /* driver.c */ |
|---|
| 150 | extern unsigned int ifd_drivers_list(const char **, size_t); |
|---|
| 151 | |
|---|
| 152 | /* device.c */ |
|---|
| 153 | extern ifd_device_t *ifd_open_pcmcia_block(const char *); |
|---|
| 154 | extern ifd_device_t *ifd_open_pcmcia(const char *); |
|---|
| 155 | extern ifd_device_t *ifd_open_psaux(const char *); |
|---|
| 156 | extern ifd_device_t *ifd_open_remote(const char *); |
|---|
| 157 | extern ifd_device_t *ifd_open_serial(const char *); |
|---|
| 158 | extern ifd_device_t *ifd_open_usb(const char *); |
|---|
| 159 | extern ifd_device_t *ifd_device_new(const char *, |
|---|
| 160 | struct ifd_device_ops *, size_t); |
|---|
| 161 | extern void ifd_device_free(ifd_device_t *); |
|---|
| 162 | |
|---|
| 163 | /* checksum.c */ |
|---|
| 164 | extern unsigned int csum_lrc_compute(const uint8_t *, size_t, unsigned char *); |
|---|
| 165 | extern unsigned int csum_crc_compute(const uint8_t *, size_t, unsigned char *); |
|---|
| 166 | |
|---|
| 167 | /* Internal system dependent device functions */ |
|---|
| 168 | extern int ifd_sysdep_usb_poll_presence(ifd_device_t *, struct pollfd *); |
|---|
| 169 | extern int ifd_sysdep_usb_get_eventfd(ifd_device_t *, short *events); |
|---|
| 170 | extern int ifd_sysdep_usb_control(ifd_device_t *, |
|---|
| 171 | unsigned int, |
|---|
| 172 | unsigned int, |
|---|
| 173 | unsigned int, |
|---|
| 174 | unsigned int, void *, size_t, long); |
|---|
| 175 | extern int ifd_sysdep_usb_bulk(ifd_device_t *, int, void *, size_t, long); |
|---|
| 176 | extern int ifd_sysdep_usb_set_configuration(ifd_device_t *, int); |
|---|
| 177 | extern int ifd_sysdep_usb_set_interface(ifd_device_t *, int, int); |
|---|
| 178 | extern int ifd_sysdep_usb_claim_interface(ifd_device_t *, int); |
|---|
| 179 | extern int ifd_sysdep_usb_release_interface(ifd_device_t *, int); |
|---|
| 180 | extern int ifd_sysdep_usb_begin_capture(ifd_device_t *, int, int, size_t, |
|---|
| 181 | ifd_usb_capture_t **); |
|---|
| 182 | extern int ifd_sysdep_usb_capture_event(ifd_device_t *, ifd_usb_capture_t *, |
|---|
| 183 | void *, size_t); |
|---|
| 184 | extern int ifd_sysdep_usb_capture(ifd_device_t *, ifd_usb_capture_t *, void *, |
|---|
| 185 | size_t, long); |
|---|
| 186 | extern int ifd_sysdep_usb_end_capture(ifd_device_t *, ifd_usb_capture_t * cap); |
|---|
| 187 | extern int ifd_sysdep_usb_open(const char *device); |
|---|
| 188 | extern int ifd_sysdep_usb_reset(ifd_device_t *); |
|---|
| 189 | |
|---|
| 190 | /* module.c */ |
|---|
| 191 | extern int ifd_load_module(const char *, const char *); |
|---|
| 192 | |
|---|
| 193 | /* utils.c */ |
|---|
| 194 | extern void ifd_revert_bits(unsigned char *, size_t); |
|---|
| 195 | extern unsigned int ifd_count_bits(unsigned int); |
|---|
| 196 | extern long ifd_time_elapsed(struct timeval *); |
|---|
| 197 | #ifndef HAVE_DAEMON |
|---|
| 198 | extern int daemon(int, int); |
|---|
| 199 | #endif |
|---|
| 200 | |
|---|
| 201 | /* protocol.c */ |
|---|
| 202 | extern int ifd_protocol_register(struct ifd_protocol_ops *); |
|---|
| 203 | extern int ifd_sync_detect_icc(ifd_reader_t *, int, void *, size_t); |
|---|
| 204 | extern unsigned int ifd_protocols_list(const char **, unsigned int); |
|---|
| 205 | |
|---|
| 206 | /* proto-t1.c */ |
|---|
| 207 | extern int t1_negotiate_ifsd(ifd_protocol_t *, unsigned int, int); |
|---|
| 208 | |
|---|
| 209 | #endif /* IFD_INTERNAL_H */ |
|---|