1 /* $Id: ifdwrapper.c,v 1.1 2003/06/19 22:40:53 rees Exp $ */
2
3 /*
4 copyright 2003
5 the regents of the university of michigan
6 all rights reserved
7
8 permission is granted to use, copy, create derivative works
9 and redistribute this software and such derivative works
10 for any purpose, so long as the name of the university of
11 michigan is not used in any advertising or publicity
12 pertaining to the use or distribution of this software
13 without specific, written prior authorization. if the
14 above copyright notice or any other identification of the
15 university of michigan is included in any copy of any
16 portion of this software, then the disclaimer below must
17 also be included.
18
19 this software is provided as is, without representation
20 from the university of michigan as to its fitness for any
21 purpose, and without warranty by the university of
22 michigan of any kind, either express or implied, including
23 without limitation the implied warranties of
24 merchantability and fitness for a particular purpose. the
25 regents of the university of michigan shall not be liable
26 for any damages, including special, indirect, incidental, or
27 consequential damages, with respect to any claim arising
28 out of or in connection with the use of the software, even
29 if it has been or is hereafter advised of the possibility of
30 such damages.
31 */
32
33 /* ifdwrapper by Hans-Joerg Hoexer <Hans-Joerg.Hoexer@yerbouti.franken.de> */
34
35 #include <sys/types.h>
36 #include <stdlib.h>
37 #include <unistd.h>
38 #include <stdio.h>
39
40 #include "sectok.h"
41 #include "ifdhandler.h"
42 #include "ifdwrapper.h"
43
44 unsigned long
IFDOpenIFD(readerInfo * reader)45 IFDOpenIFD(readerInfo *reader)
46 {
47 unsigned long ret;
48 void *func;
49
50 unsigned long (*IO_create_channel)(unsigned long);
51 unsigned long (*IFDH_create_channel)(unsigned long, unsigned long);
52
53 func = reader->open;
54 if (reader->version == IFDH_VERSION_1_0) {
55 IO_create_channel = (unsigned long (*)(unsigned long)) func;
56 ret = (*IO_create_channel)(reader->channelID);
57 } else {
58 IFDH_create_channel = (unsigned long (*)(unsigned long,
59 unsigned long)) func;
60 ret = (*IFDH_create_channel)(reader->lun, reader->channelID);
61 }
62
63 return ret;
64 }
65
66 unsigned long
IFDCloseIFD(readerInfo * reader)67 IFDCloseIFD(readerInfo *reader)
68 {
69 unsigned long ret;
70 void *func;
71
72 unsigned long (*IO_close_channel)();
73 unsigned long (*IFDH_close_channel)(unsigned long);
74
75 func = reader->close;
76 if (reader->version == IFDH_VERSION_1_0) {
77 IO_close_channel = (unsigned long (*)()) func;
78 ret = (*IO_close_channel)();
79 } else {
80 IFDH_close_channel = (unsigned long (*)(unsigned long)) func;
81 ret = (*IFDH_close_channel)(reader->lun);
82 }
83
84 return ret;
85 }
86
87 unsigned long
IFDPowerICC(readerInfo * reader,unsigned long action,unsigned char * atr,unsigned long * atrlength)88 IFDPowerICC(readerInfo *reader, unsigned long action,
89 unsigned char *atr, unsigned long *atrlength)
90 {
91 unsigned long ret;
92 void *func;
93 unsigned char dummy_atr[MAX_ATR_SIZE];
94 unsigned long dummy_atrlength;
95 unsigned char *patr;
96 unsigned long *patrlength;
97
98 unsigned long (*IFD_power_icc)(unsigned long);
99 unsigned long (*IFDH_power_icc)(unsigned long, unsigned long,
100 unsigned char *, unsigned long *);
101
102 func = reader->power;
103 if (reader->version == IFDH_VERSION_1_0) {
104 IFD_power_icc = (unsigned long (*)(unsigned long)) func;
105 ret = (*IFD_power_icc)(action);
106 } else {
107 if (atr != NULL) {
108 patr = atr;
109 } else {
110 patr = dummy_atr;
111 }
112 if (atrlength != NULL) {
113 patrlength = atrlength;
114 } else {
115 patrlength = &dummy_atrlength;
116 }
117
118 IFDH_power_icc = (unsigned long (*)(unsigned long, unsigned long,
119 unsigned char *, unsigned long*)) func;
120 ret = (*IFDH_power_icc)(reader->lun, action, patr, patrlength);
121 }
122
123 return ret;
124 }
125
126 unsigned long
IFDTransmit(readerInfo * reader,SCARD_IO_HEADER txpci,unsigned char * txbuffer,unsigned long txlength,unsigned char * rxbuffer,unsigned long * rxlength,SCARD_IO_HEADER * rxpci)127 IFDTransmit(readerInfo *reader, SCARD_IO_HEADER txpci,
128 unsigned char *txbuffer, unsigned long txlength,
129 unsigned char *rxbuffer, unsigned long *rxlength,
130 SCARD_IO_HEADER *rxpci)
131 {
132 unsigned long ret;
133 void *func;
134
135 unsigned long (*IFD_transmit_to_icc)(SCARD_IO_HEADER, unsigned char *,
136 unsigned long, unsigned char *, unsigned long *,
137 SCARD_IO_HEADER *);
138 unsigned long (*IFDH_transmit_to_icc)(unsigned long, SCARD_IO_HEADER,
139 unsigned char *, unsigned long, unsigned char *,
140 unsigned long *, SCARD_IO_HEADER *);
141
142 func = reader->data;
143 if (reader->version == IFDH_VERSION_1_0) {
144 IFD_transmit_to_icc = (unsigned long (*)(SCARD_IO_HEADER,
145 unsigned char *, unsigned long,
146 unsigned char *, unsigned long *,
147 SCARD_IO_HEADER *)) func;
148 ret = (*IFD_transmit_to_icc)(txpci, txbuffer, txlength,
149 rxbuffer, rxlength, rxpci);
150 } else {
151 IFDH_transmit_to_icc = (unsigned long (*)(unsigned long,
152 SCARD_IO_HEADER, unsigned char *,
153 unsigned long, unsigned char *,
154 unsigned long *, SCARD_IO_HEADER *))
155 func;
156 ret = (*IFDH_transmit_to_icc)(reader->lun, txpci, txbuffer,
157 txlength, rxbuffer, rxlength, rxpci);
158 }
159
160 return ret;
161 }
162
163 unsigned long
IFDSetCapabilities(readerInfo * reader,unsigned long tag,unsigned long length,unsigned char * value)164 IFDSetCapabilities(readerInfo *reader, unsigned long tag, unsigned long length,
165 unsigned char *value)
166 {
167 unsigned long ret;
168 void *func;
169
170 unsigned long (*IFD_set_capabilities)(unsigned long, unsigned char *);
171 unsigned long (*IFDH_set_capabilities)(unsigned long, unsigned long,
172 unsigned long, unsigned char*);
173
174 func = reader->setcapa;
175 if (reader->version == IFDH_VERSION_1_0) {
176 IFD_set_capabilities = (unsigned long (*)(unsigned long,
177 unsigned char *)) func;
178 ret = (*IFD_set_capabilities)(tag, value);
179 } else {
180 IFDH_set_capabilities = (unsigned long (*)(unsigned long,
181 unsigned long, unsigned long,
182 unsigned char *)) func;
183 ret = (*IFDH_set_capabilities)(reader->lun, tag, length, value);
184 }
185
186 return ret;
187 }
188
189 unsigned long
IFDGetCapabilities(readerInfo * reader,unsigned long tag,unsigned long * length,unsigned char * value)190 IFDGetCapabilities(readerInfo *reader, unsigned long tag, unsigned long *length,
191 unsigned char *value)
192 {
193 unsigned long ret;
194 void *func;
195
196 unsigned long (*IFD_get_capabilities)(unsigned long, unsigned char *);
197 unsigned long (*IFDH_get_capabilities)(unsigned long, unsigned long,
198 unsigned long *, unsigned char *);
199
200 func = reader->getcapa;
201 if (reader->version == IFDH_VERSION_1_0) {
202 IFD_get_capabilities = (unsigned long (*)(unsigned long,
203 unsigned char *)) func;
204 ret = (*IFD_get_capabilities)(tag, value);
205 } else {
206 IFDH_get_capabilities = (unsigned long (*)(unsigned long,
207 unsigned long, unsigned long *,
208 unsigned char *)) func;
209 ret = (*IFDH_get_capabilities)(reader->lun, tag, length, value);
210 }
211
212 return ret;
213 }
214
215 unsigned long
IFDPresent(readerInfo * reader)216 IFDPresent(readerInfo *reader)
217 {
218 unsigned long ret;
219 void *func;
220
221 unsigned long (*IFD_icc_present)();
222 unsigned long (*IFDH_icc_presence)(unsigned long);
223
224 func = reader->cardpresent;
225 if (reader->version == IFDH_VERSION_1_0) {
226 IFD_icc_present = (unsigned long (*)()) func;
227 ret = (*IFD_icc_present)();
228 } else {
229 IFDH_icc_presence = (unsigned long (*)(unsigned long)) func;
230 ret = (*IFDH_icc_presence)(reader->lun);
231 }
232
233 return ret;
234 }
235