/[pcsclite]/trunk/Drivers/ccid/src/commands.c
ViewVC logotype

Contents of /trunk/Drivers/ccid/src/commands.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1983 - (show annotations) (download)
Mon Mar 27 14:38:35 2006 UTC (7 years, 2 months ago) by rousseau
File MIME type: text/plain
File size: 36230 byte(s)
SecurePINModify(): separate the validation test in three different tests
and add a debug message for each test
1 /*
2 commands.c: Commands sent to the card
3 Copyright (C) 2003-2004 Ludovic Rousseau
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20 /*
21 * $Id$
22 */
23
24 #include <string.h>
25 #include <stdlib.h>
26 #include <pcsclite.h>
27 #include <ifdhandler.h>
28 #include <reader.h>
29
30 #include "commands.h"
31 #include "openct/proto-t1.h"
32 #include "ccid.h"
33 #include "defs.h"
34 #include "ccid_ifdhandler.h"
35 #include "config.h"
36 #include "debug.h"
37
38 /* All the pinpad readers I used are more or less bogus
39 * I use code to change the user command and make the firmware happy */
40 #define BOGUS_PINPAD_FIRMWARE
41
42 #define max( a, b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )
43 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
44
45 /* internal functions */
46 static RESPONSECODE CmdXfrBlockTPDU_T0(unsigned int reader_index,
47 unsigned int tx_length, unsigned char tx_buffer[], unsigned int *rx_length,
48 unsigned char rx_buffer[]);
49
50 static RESPONSECODE CmdXfrBlockCHAR_T0(unsigned int reader_index, unsigned int
51 tx_length, unsigned char tx_buffer[], unsigned int *rx_length, unsigned
52 char rx_buffer[]);
53
54 static RESPONSECODE CmdXfrBlockTPDU_T1(unsigned int reader_index,
55 unsigned int tx_length, unsigned char tx_buffer[], unsigned int *rx_length,
56 unsigned char rx_buffer[]);
57
58 static void i2dw(int value, unsigned char *buffer);
59
60
61 /*****************************************************************************
62 *
63 * CmdPowerOn
64 *
65 ****************************************************************************/
66 RESPONSECODE CmdPowerOn(unsigned int reader_index, unsigned int * nlength,
67 unsigned char buffer[], int voltage)
68 {
69 unsigned char cmd[10];
70 status_t res;
71 int length, count = 1;
72 unsigned int atr_len;
73 RESPONSECODE return_value = IFD_SUCCESS;
74 _ccid_descriptor *ccid_descriptor = get_ccid_descriptor(reader_index);
75
76 /* store length of buffer[] */
77 length = *nlength;
78
79 if (ccid_descriptor->dwFeatures & CCID_CLASS_AUTO_VOLTAGE)
80 voltage = 0; /* automatic voltage selection */
81
82 again:
83 cmd[0] = 0x62; /* IccPowerOn */
84 cmd[1] = cmd[2] = cmd[3] = cmd[4] = 0; /* dwLength */
85 cmd[5] = ccid_descriptor->bCurrentSlotIndex; /* slot number */
86 cmd[6] = (*ccid_descriptor->pbSeq)++;
87 cmd[7] = voltage;
88 cmd[8] = cmd[9] = 0; /* RFU */
89
90 res = WritePort(reader_index, sizeof(cmd), cmd);
91 if (res != STATUS_SUCCESS)
92 return IFD_COMMUNICATION_ERROR;
93
94 /* reset available buffer size */
95 /* needed if we go back after a switch to ISO mode */
96 *nlength = length;
97
98 res = ReadPort(reader_index, nlength, buffer);
99 if (res != STATUS_SUCCESS)
100 return IFD_COMMUNICATION_ERROR;
101
102 if (buffer[STATUS_OFFSET] & CCID_COMMAND_FAILED)
103 {
104 ccid_error(buffer[ERROR_OFFSET], __FILE__, __LINE__, __FUNCTION__); /* bError */
105
106 if (0xBB == buffer[ERROR_OFFSET] && /* Protocol error in EMV mode */
107 ((GEMPC433 == ccid_descriptor->readerID)
108 || (CHERRYXX33 == ccid_descriptor->readerID)))
109 {
110 unsigned char cmd[] = {0x1F, 0x01};
111 unsigned char res[1];
112 unsigned int res_length = sizeof(res);
113
114 if ((return_value = CmdEscape(reader_index, cmd, sizeof(cmd), res,
115 &res_length)) != IFD_SUCCESS)
116 return return_value;
117
118 /* avoid looping if we can't switch mode */
119 if (count--)
120 goto again;
121 else
122 DEBUG_CRITICAL("Can't set reader in ISO mode");
123 }
124
125 /* continue with 3 volts and 5 volts */
126 if (voltage > 1)
127 {
128 char *voltage_code[] = { "auto", "5V", "3V", "1.8V" };
129
130 DEBUG_INFO3("Power up with %s failed. Try with %s.",
131 voltage_code[voltage], voltage_code[voltage-1]);
132 voltage--;
133 goto again;
134 }
135
136 return IFD_COMMUNICATION_ERROR;
137 }
138
139 /* extract the ATR */
140 atr_len = dw2i(buffer, 1); /* ATR length */
141 if (atr_len > *nlength)
142 atr_len = *nlength;
143 else
144 *nlength = atr_len;
145
146 memmove(buffer, buffer+10, atr_len);
147
148 return return_value;
149 } /* CmdPowerOn */
150
151
152 /*****************************************************************************
153 *
154 * SecurePINVerify
155 *
156 ****************************************************************************/
157 RESPONSECODE SecurePINVerify(unsigned int reader_index,
158 unsigned char TxBuffer[], unsigned int TxLength,
159 unsigned char RxBuffer[], unsigned int *RxLength)
160 {
161 unsigned char cmd[11+14+CMD_BUF_SIZE];
162 unsigned int a, b;
163 _ccid_descriptor *ccid_descriptor = get_ccid_descriptor(reader_index);
164 int old_read_timeout;
165 RESPONSECODE ret;
166
167 cmd[0] = 0x69; /* Secure */
168 cmd[5] = ccid_descriptor->bCurrentSlotIndex; /* slot number */
169 cmd[6] = (*ccid_descriptor->pbSeq)++;
170 cmd[7] = 0; /* bBWI */
171 cmd[8] = 0; /* wLevelParameter */
172 cmd[9] = 0;
173 cmd[10] = 0; /* bPINOperation: PIN Verification */
174
175 /* 19 is the size of the PCSCv2 PIN verify structure
176 * The equivalent CCID structure is only 14-bytes long */
177 if (TxLength > 19+CMD_BUF_SIZE) /* command too large? */
178 {
179 DEBUG_INFO3("Command too long: %d > %d", TxLength, 19+CMD_BUF_SIZE);
180 *RxLength = 0;
181 return IFD_NOT_SUPPORTED;
182 }
183
184 if (TxLength < 19+4 /* 4 = APDU size */) /* command too short? */
185 {
186 DEBUG_INFO3("Command too short: %d < %d", TxLength, 19+4);
187 *RxLength = 0;
188 return IFD_NOT_SUPPORTED;
189 }
190
191 if (dw2i(TxBuffer, 15) + 19 != TxLength) /* ulDataLength field coherency */
192 {
193 DEBUG_INFO3("Wrong lengths: %d %d", TxBuffer[15] + 19, TxLength);
194 *RxLength = 0;
195 return IFD_NOT_SUPPORTED;
196 }
197
198 #ifdef BOGUS_PINPAD_FIRMWARE
199 /* bug circumvention for the GemPC Pinpad */
200 if (GEMPCPINPAD == ccid_descriptor->readerID)
201 {
202 /* the firmware reject the cases: 00h No string and FFh default
203 * CCID message. The only value supported is 01h (display 1 message) */
204 if (0x01 != TxBuffer[8])
205 {
206 DEBUG_INFO2("Correct bNumberMessage for GemPC Pinpad (was %d)",
207 TxBuffer[8]);
208 TxBuffer[8] = 0x01;
209 }
210 }
211 #endif
212
213 /* T=1 Protocol Management for a TPDU reader */
214 if ((SCARD_PROTOCOL_T1 == ccid_descriptor->cardProtocol)
215 && (CCID_CLASS_TPDU == (ccid_descriptor->dwFeatures & CCID_CLASS_EXCHANGE_MASK)))
216 {
217 ct_buf_t sbuf;
218 unsigned char sdata[T1_BUFFER_SIZE];
219
220 /* Initialize send buffer with the APDU */
221 ct_buf_set(&sbuf,
222 (void *)(TxBuffer + offsetof(PIN_VERIFY_STRUCTURE, abData)),
223 TxLength - offsetof(PIN_VERIFY_STRUCTURE, abData));
224
225 /* Create T=1 block */
226 ret = t1_build(&((get_ccid_slot(reader_index))->t1),
227 sdata, 0, T1_I_BLOCK, &sbuf, NULL);
228
229 /* Increment the sequence numbers */
230 get_ccid_slot(reader_index)->t1.ns ^= 1;
231 get_ccid_slot(reader_index)->t1.nr ^= 1;
232
233 /* Copy the generated T=1 block prologue into the teoprologue
234 * of the CCID command */
235 memcpy(TxBuffer + offsetof(PIN_VERIFY_STRUCTURE, bTeoPrologue),
236 sdata, 3);
237 }
238
239 /* Build a CCID block from a PC/SC V2.1.2 Part 10 block */
240 for (a = 11, b = 0; b < TxLength; b++)
241 {
242 if (1 == b) /* bTimeOut2 field */
243 /* Ignore the second timeout as there's nothing we can do with
244 * it currently */
245 continue;
246
247 if ((b >= 15) && (b <= 18)) /* ulDataLength field (4 bytes) */
248 /* the ulDataLength field is not present in the CCID frame
249 * so do not copy */
250 continue;
251
252 /* copy the CCID block 'verbatim' */
253 cmd[a] = TxBuffer[b];
254 a++;
255 }
256
257 /* SPR532 and Case 1 APDU */
258 if ((SPR532 == ccid_descriptor->readerID) && (TxBuffer[15] == 4))
259 {
260 RESPONSECODE return_value;
261 unsigned char cmd[] = { 0x80, 0x02, 0x00 };
262 unsigned char res[1];
263 unsigned int res_length = sizeof(res);
264
265 /* the SPR532 will append the PIN code without any padding */
266 return_value = CmdEscape(reader_index, cmd, sizeof(cmd), res,
267 &res_length);
268 if (return_value != IFD_SUCCESS)
269 {
270 ccid_error(res[ERROR_OFFSET], __FILE__, __LINE__, __FUNCTION__);
271 return return_value;
272 }
273 }
274
275 i2dw(a - 10, cmd + 1); /* CCID message length */
276
277 old_read_timeout = ccid_descriptor -> readTimeout;
278 ccid_descriptor -> readTimeout = max(30, TxBuffer[0]); /* at least 30 seconds */
279
280 if (WritePort(reader_index, a, cmd) != STATUS_SUCCESS)
281 {
282 *RxLength = 0;
283 return IFD_COMMUNICATION_ERROR;
284 }
285
286 ret = CCID_Receive(reader_index, RxLength, RxBuffer);
287
288 /* T=1 Protocol Management for a TPDU reader */
289 if ((IFD_SUCCESS == ret)
290 && (SCARD_PROTOCOL_T1 == ccid_descriptor->cardProtocol)
291 && (CCID_CLASS_TPDU == (ccid_descriptor->dwFeatures & CCID_CLASS_EXCHANGE_MASK)))
292 {
293 /* timeout and cancel cases are faked by CCID_Receive() */
294 if (2 == *RxLength)
295 {
296 /* Decrement the sequence numbers since no TPDU was sent */
297 get_ccid_slot(reader_index)->t1.ns ^= 1;
298 get_ccid_slot(reader_index)->t1.nr ^= 1;
299 }
300 else
301 {
302 /* get only the T=1 data */
303 /* FIXME: manage T=1 error blocks */
304 memmove(RxBuffer, RxBuffer+3, *RxLength -4);
305 *RxLength -= 4; /* remove NAD, PCB, LEN and CRC */
306 }
307 }
308
309 ccid_descriptor -> readTimeout = old_read_timeout;
310 return ret;
311 } /* SecurePINVerify */
312
313
314 /*****************************************************************************
315 *
316 * SecurePINModify
317 *
318 ****************************************************************************/
319 RESPONSECODE SecurePINModify(unsigned int reader_index,
320 unsigned char TxBuffer[], unsigned int TxLength,
321 unsigned char RxBuffer[], unsigned int *RxLength)
322 {
323 unsigned char cmd[11+19+CMD_BUF_SIZE];
324 unsigned int a, b;
325 _ccid_descriptor *ccid_descriptor = get_ccid_descriptor(reader_index);
326 int old_read_timeout;
327 RESPONSECODE ret;
328
329 cmd[0] = 0x69; /* Secure */
330 cmd[5] = ccid_descriptor->bCurrentSlotIndex; /* slot number */
331 cmd[6] = (*ccid_descriptor->pbSeq)++;
332 cmd[7] = 0; /* bBWI */
333 cmd[8] = 0; /* wLevelParameter */
334 cmd[9] = 0;
335 cmd[10] = 1; /* bPINOperation: PIN Modification */
336
337 /* 24 is the size of the PCSC PIN modify structure
338 * The equivalent CCID structure is only 18 or 19-bytes long */
339 if (TxLength > 24+CMD_BUF_SIZE) /* command too large? */
340 {
341 DEBUG_INFO3("Command too long: %d > %d", TxLength, 24+CMD_BUF_SIZE);
342 *RxLength = 0;
343 return IFD_NOT_SUPPORTED;
344 }
345
346 if (TxLength < 24+4 /* 4 = APDU size */) /* command too short? */
347 {
348 DEBUG_INFO3("Command too short: %d < %d", TxLength, 24+4);
349 *RxLength = 0;
350 return IFD_NOT_SUPPORTED;
351 }
352
353 if (dw2i(TxBuffer, 20) + 24 != TxLength) /* ulDataLength field coherency */
354 {
355 DEBUG_INFO3("Wrong lengths: %d %d", dw2i(TxBuffer, 20) + 24, TxLength);
356 *RxLength = 0;
357 return IFD_NOT_SUPPORTED;
358 }
359
360 /* Make sure in the beginning if bNumberMessage is valid or not */
361 if (TxBuffer[11] > 3)
362 {
363 DEBUG_INFO2("Wrong bNumberMessage: %d", TxBuffer[11]);
364 *RxLength = 0;
365 return IFD_NOT_SUPPORTED;
366 }
367
368 #ifdef BOGUS_PINPAD_FIRMWARE
369 /* some firmwares are buggy so we try to "correct" the frame */
370 /*
371 * SPR 532 and Cherry ST 2000C has no display but requires _all_
372 * bMsgIndex fields with bNumberMessage set to 0.
373 */
374 if ((SPR532 == ccid_descriptor->readerID)
375 || (CHERRYST2000 == ccid_descriptor->readerID))
376 {
377 TxBuffer[11] = 0x03; /* set bNumberMessages to 3 so that
378 all bMsgIndex123 are filled */
379 TxBuffer[14] = TxBuffer[15] = TxBuffer[16] = 0; /* bMsgIndex123 */
380 }
381
382 /* the bug is a bit different than for the Cherry ST 2000C
383 * with bNumberMessages < 3 the command seems to be accepted
384 * and the card sends 6B 80 */
385 if (CHERRYXX44 == ccid_descriptor->readerID)
386 {
387 TxBuffer[11] = 0x03; /* set bNumberMessages to 3 so that
388 all bMsgIndex123 are filled */
389 }
390
391 /* bug circumvention for the GemPC Pinpad */
392 if (GEMPCPINPAD == ccid_descriptor->readerID)
393 {
394 /* The reader does not support, and actively reject, "max size reached"
395 * and "timeout occured" validation conditions */
396 if (0x02 != TxBuffer[10])
397 {
398 DEBUG_INFO2("Correct bEntryValidationCondition for GemPC Pinpad (was %d)",
399 TxBuffer[10]);
400 TxBuffer[10] = 0x02; /* validation key pressed */
401 }
402
403 /* the reader does not support any other value than 3 for the number
404 * of messages */
405 if (0x03 != TxBuffer[11])
406 {
407 DEBUG_INFO2("Correct bNumberMessages for GemPC Pinpad (was %d)",
408 TxBuffer[11]);
409 TxBuffer[11] = 0x03; /* 3 messages */
410 }
411 }
412 #endif
413
414 /* T=1 Protocol Management for a TPDU reader */
415 if ((SCARD_PROTOCOL_T1 == ccid_descriptor->cardProtocol)
416 && (CCID_CLASS_TPDU == (ccid_descriptor->dwFeatures & CCID_CLASS_EXCHANGE_MASK)))
417 {
418 ct_buf_t sbuf;
419 unsigned char sdata[T1_BUFFER_SIZE];
420
421 /* Initialize send buffer with the APDU */
422 ct_buf_set(&sbuf,
423 (void *)(TxBuffer + offsetof(PIN_MODIFY_STRUCTURE, abData)),
424 TxLength - offsetof(PIN_MODIFY_STRUCTURE, abData));
425
426 /* Create T=1 block */
427 ret = t1_build(&((get_ccid_slot(reader_index))->t1),
428 sdata, 0, T1_I_BLOCK, &sbuf, NULL);
429
430 /* Increment the sequence numbers */
431 get_ccid_slot(reader_index)->t1.ns ^= 1;
432 get_ccid_slot(reader_index)->t1.nr ^= 1;
433
434 /* Copy the generated T=1 block prologue into the teoprologue
435 * of the CCID command */
436 memcpy(TxBuffer + offsetof(PIN_MODIFY_STRUCTURE, bTeoPrologue),
437 sdata, 3);
438 }
439
440 /* Build a CCID block from a PC/SC V2.1.2 Part 10 block */
441
442 /* Do adjustments as needed - CCID spec is not exact with some
443 * details in the format of the structure, per-reader adaptions
444 * might be needed.
445 */
446 for (a = 11, b = 0; b < TxLength; b++)
447 {
448 if (1 == b) /* bTimeOut2 */
449 /* Ignore the second timeout as there's nothing we can do with it
450 * currently */
451 continue;
452
453 if (15 == b) /* bMsgIndex2 */
454 {
455 /* in CCID the bMsgIndex2 is present only if bNumberMessage != 0 */
456 if (0 == TxBuffer[11])
457 continue;
458 }
459
460 if (16 == b) /* bMsgIndex3 */
461 {
462 /* in CCID the bMsgIndex3 is present only if bNumberMessage == 3 */
463 if (TxBuffer[11] < 3)
464 continue;
465 }
466
467 if ((b >= 20) && (b <= 23)) /* ulDataLength field (4 bytes) */
468 /* the ulDataLength field is not present in the CCID frame
469 * so do not copy */
470 continue;
471
472 /* copy to the CCID block 'verbatim' */
473 cmd[a] = TxBuffer[b];
474 a++;
475 }
476
477 #ifdef BOGUS_PINPAD_FIRMWARE
478 if ((SPR532 == ccid_descriptor->readerID)
479 || (CHERRYST2000 == ccid_descriptor->readerID))
480 {
481 cmd[21] = 0x00; /* set bNumberMessages to 0 */
482 }
483 #endif
484
485 /* We know the size of the CCID message now */
486 i2dw(a - 10, cmd + 1); /* command length (includes bPINOperation) */
487
488 old_read_timeout = ccid_descriptor -> readTimeout;
489 ccid_descriptor -> readTimeout = max(30, TxBuffer[0]); /* at least 30 seconds */
490
491 if (WritePort(reader_index, a, cmd) != STATUS_SUCCESS)
492 {
493 *RxLength = 0;
494 return IFD_COMMUNICATION_ERROR;
495 }
496
497 ret = CCID_Receive(reader_index, RxLength, RxBuffer);
498
499 /* T=1 Protocol Management for a TPDU reader */
500 if ((IFD_SUCCESS == ret)
501 && (SCARD_PROTOCOL_T1 == ccid_descriptor->cardProtocol)
502 && (CCID_CLASS_TPDU == (ccid_descriptor->dwFeatures & CCID_CLASS_EXCHANGE_MASK)))
503 {
504 /* timeout and cancel cases are faked by CCID_Receive() */
505 if (2 == *RxLength)
506 {
507 /* Decrement the sequence numbers since no TPDU was sent */
508 get_ccid_slot(reader_index)->t1.ns ^= 1;
509 get_ccid_slot(reader_index)->t1.nr ^= 1;
510 }
511 else
512 {
513 /* get only the T=1 data */
514 /* FIXME: manage T=1 error blocks */
515 memmove(RxBuffer, RxBuffer+3, *RxLength -4);
516 *RxLength -= 4; /* remove NAD, PCB, LEN and CRC */
517 }
518 }
519
520 ccid_descriptor -> readTimeout = old_read_timeout;
521 return ret;
522 } /* SecurePINModify */
523
524
525 /*****************************************************************************
526 *
527 * Escape
528 *
529 ****************************************************************************/
530 RESPONSECODE CmdEscape(unsigned int reader_index,
531 const unsigned char TxBuffer[], unsigned int TxLength,
532 unsigned char RxBuffer[], unsigned int *RxLength)
533 {
534 unsigned char *cmd_in, *cmd_out;
535 status_t res;
536 unsigned int length_in, length_out;
537 RESPONSECODE return_value = IFD_SUCCESS;
538 _ccid_descriptor *ccid_descriptor = get_ccid_descriptor(reader_index);
539
540 again:
541 /* allocate buffers */
542 length_in = 10 + TxLength;
543 if (NULL == (cmd_in = malloc(length_in)))
544 return IFD_COMMUNICATION_ERROR;
545
546 length_out = 10 + *RxLength;
547 if (NULL == (cmd_out = malloc(length_out)))
548 {
549 free(cmd_in);
550 return IFD_COMMUNICATION_ERROR;
551 }
552
553 cmd_in[0] = 0x6B; /* PC_to_RDR_Escape */
554 i2dw(length_in - 10, cmd_in+1); /* dwLength */
555 cmd_in[5] = ccid_descriptor->bCurrentSlotIndex; /* slot number */
556 cmd_in[6] = (*ccid_descriptor->pbSeq)++;
557 cmd_in[7] = cmd_in[8] = cmd_in[9] = 0; /* RFU */
558
559 /* copy the command */
560 memcpy(&cmd_in[10], TxBuffer, TxLength);
561
562 res = WritePort(reader_index, length_in, cmd_in);
563 free(cmd_in);
564 if (res != STATUS_SUCCESS)
565 {
566 free(cmd_out);
567 return IFD_COMMUNICATION_ERROR;
568 }
569
570 res = ReadPort(reader_index, &length_out, cmd_out);
571
572 /* replay the command if NAK
573 * This (generally) happens only for the first command sent to the reader
574 * with the serial protocol so it is not really needed for all the other
575 * ReadPort() calls */
576 if (STATUS_COMM_NAK == res)
577 {
578 free(cmd_out);
579 goto again;
580 }
581
582 if (res != STATUS_SUCCESS)
583 {
584 free(cmd_out);
585 return IFD_COMMUNICATION_ERROR;
586 }
587
588 if (cmd_out[STATUS_OFFSET] & CCID_COMMAND_FAILED)
589 {
590 ccid_error(cmd_out[ERROR_OFFSET], __FILE__, __LINE__, __FUNCTION__); /* bError */
591 return_value = IFD_COMMUNICATION_ERROR;
592 }
593
594 /* copy the response */
595 length_out = dw2i(cmd_out, 1);
596 if (length_out > *RxLength)
597 length_out = *RxLength;
598 *RxLength = length_out;
599 memcpy(RxBuffer, &cmd_out[10], length_out);
600
601 free(cmd_out);
602
603 return return_value;
604 } /* Escape */
605
606
607 /*****************************************************************************
608 *
609 * CmdPowerOff
610 *
611 ****************************************************************************/
612 RESPONSECODE CmdPowerOff(unsigned int reader_index)
613 {
614 unsigned char cmd[10];
615 status_t res;
616 unsigned int length;
617 RESPONSECODE return_value = IFD_SUCCESS;
618 _ccid_descriptor *ccid_descriptor = get_ccid_descriptor(reader_index);
619
620 cmd[0] = 0x63; /* IccPowerOff */
621 cmd[1] = cmd[2] = cmd[3] = cmd[4] = 0; /* dwLength */
622 cmd[5] = ccid_descriptor->bCurrentSlotIndex; /* slot number */
623 cmd[6] = (*ccid_descriptor->pbSeq)++;
624 cmd[7] = cmd[8] = cmd[9] = 0; /* RFU */
625
626 res = WritePort(reader_index, sizeof(cmd), cmd);
627 if (res != STATUS_SUCCESS)
628 return IFD_COMMUNICATION_ERROR;
629
630 length = sizeof(cmd);
631 res = ReadPort(reader_index, &length, cmd);
632 if (res != STATUS_SUCCESS)
633 return IFD_COMMUNICATION_ERROR;
634
635 if (cmd[STATUS_OFFSET] & CCID_COMMAND_FAILED)
636 {
637 ccid_error(cmd[ERROR_OFFSET], __FILE__, __LINE__, __FUNCTION__); /* bError */
638 return_value = IFD_COMMUNICATION_ERROR;
639 }
640
641 return return_value;
642 } /* CmdPowerOff */
643
644
645 /*****************************************************************************
646 *
647 * CmdGetSlotStatus
648 *
649 ****************************************************************************/
650 RESPONSECODE CmdGetSlotStatus(unsigned int reader_index, unsigned char buffer[])
651 {
652 unsigned char cmd[10];
653 status_t res;
654 unsigned int length;
655 RESPONSECODE return_value = IFD_SUCCESS;
656 _ccid_descriptor *ccid_descriptor = get_ccid_descriptor(reader_index);
657
658 cmd[0] = 0x65; /* GetSlotStatus */
659 cmd[1] = cmd[2] = cmd[3] = cmd[4] = 0; /* dwLength */
660 cmd[5] = ccid_descriptor->bCurrentSlotIndex; /* slot number */
661 cmd[6] = (*ccid_descriptor->pbSeq)++;
662 cmd[7] = cmd[8] = cmd[9] = 0; /* RFU */
663
664 res = WritePort(reader_index, sizeof(cmd), cmd);
665 if (res != STATUS_SUCCESS)
666 return IFD_COMMUNICATION_ERROR;
667
668 length = SIZE_GET_SLOT_STATUS;
669 res = ReadPort(reader_index, &length, buffer);
670 if (res != STATUS_SUCCESS)
671 return IFD_COMMUNICATION_ERROR;
672
673 if (buffer[STATUS_OFFSET] & CCID_COMMAND_FAILED)
674 {
675 ccid_error(buffer[ERROR_OFFSET], __FILE__, __LINE__, __FUNCTION__); /* bError */
676
677 /* card absent or mute is not an communication error */
678 if (buffer[ERROR_OFFSET] != 0xFE)
679 return_value = IFD_COMMUNICATION_ERROR;
680 }
681
682 return return_value;
683 } /* CmdGetSlotStatus */
684
685
686 /*****************************************************************************
687 *
688 * CmdXfrBlock
689 *
690 ****************************************************************************/
691 RESPONSECODE CmdXfrBlock(unsigned int reader_index, unsigned int tx_length,
692 unsigned char tx_buffer[], unsigned int *rx_length,
693 unsigned char rx_buffer[], int protocol)
694 {
695 RESPONSECODE return_value = IFD_SUCCESS;
696 _ccid_descriptor *ccid_descriptor = get_ccid_descriptor(reader_index);
697
698 /* command length too big for CCID reader? */
699 if (tx_length > ccid_descriptor->dwMaxCCIDMessageLength)
700 {
701 DEBUG_CRITICAL3("Command too long (%d bytes) for max: %d bytes",
702 tx_length, ccid_descriptor->dwMaxCCIDMessageLength);
703 return_value = IFD_COMMUNICATION_ERROR;
704 goto clean_up_and_return;
705 }
706
707 /* command length too big for CCID driver? */
708 if (tx_length > CMD_BUF_SIZE)
709 {
710 DEBUG_CRITICAL3("Command too long (%d bytes) for max: %d bytes",
711 tx_length, CMD_BUF_SIZE);
712 return_value = IFD_COMMUNICATION_ERROR;
713 goto clean_up_and_return;
714 }
715
716 /* APDU or TPDU? */
717 switch (ccid_descriptor->dwFeatures & CCID_CLASS_EXCHANGE_MASK)
718 {
719 case CCID_CLASS_TPDU:
720 if (protocol == T_0)
721 return_value = CmdXfrBlockTPDU_T0(reader_index,
722 tx_length, tx_buffer, rx_length, rx_buffer);
723 else
724 if (protocol == T_1)
725 return_value = CmdXfrBlockTPDU_T1(reader_index, tx_length,
726 tx_buffer, rx_length, rx_buffer);
727 else
728 return_value = IFD_PROTOCOL_NOT_SUPPORTED;
729 break;
730
731 case CCID_CLASS_SHORT_APDU:
732 case CCID_CLASS_EXTENDED_APDU:
733 /* We only support extended APDU if the reader can support the
734 * command length. See test above */
735 return_value = CmdXfrBlockTPDU_T0(reader_index,
736 tx_length, tx_buffer, rx_length, rx_buffer);
737 break;
738
739 case CCID_CLASS_CHARACTER:
740 if (protocol == T_0)
741 return_value = CmdXfrBlockCHAR_T0(reader_index, tx_length,
742 tx_buffer, rx_length, rx_buffer);
743 else
744 if (protocol == T_1)
745 return_value = CmdXfrBlockTPDU_T1(reader_index, tx_length,
746 tx_buffer, rx_length, rx_buffer);
747 else
748 return_value = IFD_PROTOCOL_NOT_SUPPORTED;
749 break;
750
751 default:
752 *rx_length = 0;
753 return_value = IFD_COMMUNICATION_ERROR;
754 }
755
756 clean_up_and_return:
757 return return_value;
758 } /* CmdXfrBlock */
759
760
761 /*****************************************************************************
762 *
763 * CCID_Transmit
764 *
765 ****************************************************************************/
766 RESPONSECODE CCID_Transmit(unsigned int reader_index, unsigned int tx_length,
767 const unsigned char tx_buffer[], unsigned short rx_length, unsigned char bBWI)
768 {
769 unsigned char cmd[10+CMD_BUF_SIZE]; /* CCID + APDU buffer */
770 _ccid_descriptor *ccid_descriptor = get_ccid_descriptor(reader_index);
771
772 cmd[0] = 0x6F; /* XfrBlock */
773 i2dw(tx_length, cmd+1); /* APDU length */
774 cmd[5] = ccid_descriptor->bCurrentSlotIndex; /* slot number */
775 cmd[6] = (*ccid_descriptor->pbSeq)++;
776 cmd[7] = bBWI; /* extend block waiting timeout */
777 cmd[8] = rx_length & 0xFF; /* Expected length, in character mode only */
778 cmd[9] = (rx_length >> 8) & 0xFF;
779
780 /* check that the command is not too large */
781 if (tx_length > CMD_BUF_SIZE)
782 return IFD_NOT_SUPPORTED;
783
784 memcpy(cmd+10, tx_buffer, tx_length);
785
786 if (WritePort(reader_index, 10+tx_length, cmd) != STATUS_SUCCESS)
787 return IFD_COMMUNICATION_ERROR;
788
789 return IFD_SUCCESS;
790 } /* CCID_Transmit */
791
792
793 /*****************************************************************************
794 *
795 * CCID_Receive
796 *
797 ****************************************************************************/
798 RESPONSECODE CCID_Receive(unsigned int reader_index, unsigned int *rx_length,
799 unsigned char rx_buffer[])
800 {
801 unsigned char cmd[10+CMD_BUF_SIZE]; /* CCID + APDU buffer */
802 unsigned int length;
803
804 time_request:
805 length = sizeof(cmd);
806 if (ReadPort(reader_index, &length, cmd) != STATUS_SUCCESS)
807 {
808 *rx_length = 0;
809 return IFD_COMMUNICATION_ERROR;
810 }
811
812 if (cmd[STATUS_OFFSET] & CCID_COMMAND_FAILED)
813 {
814 ccid_error(cmd[ERROR_OFFSET], __FILE__, __LINE__, __FUNCTION__); /* bError */
815 switch (cmd[ERROR_OFFSET])
816 {
817 case 0xEF: /* cancel */
818 if (*rx_length < 2)
819 return IFD_COMMUNICATION_ERROR;
820 rx_buffer[0]= 0x64;
821 rx_buffer[1]= 0x01;
822 *rx_length = 2;
823 return IFD_SUCCESS;
824
825 case 0xF0: /* timeout */
826 if (*rx_length < 2)
827 return IFD_COMMUNICATION_ERROR;
828 rx_buffer[0]= 0x64;
829 rx_buffer[1]= 0x00;
830 *rx_length = 2;
831 return IFD_SUCCESS;
832
833 case 0xFD: /* Parity error during exchange */
834 *rx_length = 0; /* nothing received */
835 return IFD_PARITY_ERROR;
836
837 default:
838 *rx_length = 0; /* nothing received */
839 return IFD_COMMUNICATION_ERROR;
840 }
841 }
842
843 if (cmd[STATUS_OFFSET] & CCID_TIME_EXTENSION)
844 {
845 DEBUG_COMM2("Time extension requested: 0x%02X", cmd[ERROR_OFFSET]);
846 goto time_request;
847 }
848
849 length = dw2i(cmd, 1);
850 if (length < *rx_length)
851 *rx_length = length;
852 else
853 length = *rx_length;
854 memcpy(rx_buffer, cmd+10, length);
855
856 return IFD_SUCCESS;
857 } /* CCID_Receive */
858
859
860 /*****************************************************************************
861 *
862 * CmdXfrBlockTPDU_T0
863 *
864 ****************************************************************************/
865 static RESPONSECODE CmdXfrBlockTPDU_T0(unsigned int reader_index,
866 unsigned int tx_length, unsigned char tx_buffer[], unsigned int *rx_length,
867 unsigned char rx_buffer[])
868 {
869 RESPONSECODE return_value = IFD_SUCCESS;
870
871 DEBUG_COMM2("T=0: %d bytes", tx_length);
872
873 return_value = CCID_Transmit(reader_index, tx_length, tx_buffer, 0, 0);
874 if (return_value != IFD_SUCCESS)
875 return return_value;
876
877 return CCID_Receive(reader_index, rx_length, rx_buffer);
878 } /* CmdXfrBlockTPDU_T0 */
879
880
881 /*****************************************************************************
882 *
883 * T0CmdParsing
884 *
885 ****************************************************************************/
886 static RESPONSECODE T0CmdParsing(unsigned char *cmd, unsigned int cmd_len,
887 unsigned int *exp_len)
888 {
889 *exp_len = 0;
890
891 /* Ref: 7816-4 Annex A */
892 switch (cmd_len)
893 {
894 case 4: /* Case 1 */
895 *exp_len = 2; /* SW1 and SW2 only */
896 break;
897
898 case 5: /* Case 2 */
899 if (cmd[4] != 0)
900 *exp_len = cmd[4] + 2;
901 else
902 *exp_len = 256 + 2;
903 break;
904
905 default: /* Case 3 */
906 if (cmd_len > 5 && cmd_len == (unsigned int)(cmd[4] + 5))
907 *exp_len = 2; /* SW1 and SW2 only */
908 else
909 return IFD_COMMUNICATION_ERROR; /* situation not supported */
910 break;
911 }
912
913 return IFD_SUCCESS;
914 } /* T0CmdParsing */
915
916
917 /*****************************************************************************
918 *
919 * T0ProcACK
920 *
921 ****************************************************************************/
922 static RESPONSECODE T0ProcACK(unsigned int reader_index,
923 unsigned char **snd_buf, unsigned int *snd_len,
924 unsigned char **rcv_buf, unsigned int *rcv_len,
925 unsigned char **in_buf, unsigned int *in_len,
926 unsigned int proc_len, int is_rcv)
927 {
928 RESPONSECODE return_value;
929 unsigned int remain_len;
930 unsigned char tmp_buf[512];
931 unsigned int ret_len;
932
933 DEBUG_COMM2("Enter, is_rcv = %d", is_rcv);
934
935 if (is_rcv == 1)
936 { /* Receiving mode */
937 if (*in_len > 0)
938 { /* There are still available data in our buffer */
939 if (*in_len >= proc_len)
940 {
941 /* We only need to get the data from our buffer */
942 memcpy(*rcv_buf, *in_buf, proc_len);
943 *rcv_buf += proc_len;
944 *in_buf += proc_len;
945 *rcv_len += proc_len;
946 *in_len -= proc_len;
947
948 return IFD_SUCCESS;
949 }
950 else
951 {
952 /* Move all data in the input buffer to the reply buffer */
953 remain_len = proc_len - *in_len;
954 memcpy(*rcv_buf, *in_buf, *in_len);
955 *rcv_buf += *in_len;
956 *in_buf += *in_len;
957 *rcv_len += *in_len;
958 *in_len = 0;
959 }
960 }
961 else
962 /* There is no data in our tmp_buf,
963 * we have to read all data we needed */
964 remain_len = proc_len;
965
966 /* Read the expected data from the smartcard */
967 if (*in_len != 0)
968 {
969 DEBUG_CRITICAL("*in_len != 0");
970 return IFD_COMMUNICATION_ERROR;
971 }
972
973 memset(tmp_buf, 0, sizeof(tmp_buf));
974
975 ret_len = remain_len;
976 return_value = CCID_Transmit(reader_index, 0, *snd_buf, ret_len, 0);
977 if (return_value != IFD_SUCCESS)
978 return return_value;
979
980 return_value = CCID_Receive(reader_index, &ret_len, tmp_buf);
981 if (return_value != IFD_SUCCESS)
982 return return_value;
983
984 memcpy(*rcv_buf, tmp_buf, remain_len);
985 *rcv_buf += remain_len, *rcv_len += remain_len;
986
987 /* If ret_len != remain_len, our logic is erroneous */
988 if (ret_len != remain_len)
989 {
990 DEBUG_CRITICAL("ret_len != remain_len");
991 return IFD_COMMUNICATION_ERROR;
992 }
993 }
994 else
995 { /* Sending mode */
996
997 return_value = CCID_Transmit(reader_index, proc_len, *snd_buf, 1, 0);
998 if (return_value != IFD_SUCCESS)
999 return return_value;
1000
1001 *snd_len -= proc_len;
1002 *snd_buf += proc_len;
1003 }
1004
1005 DEBUG_COMM("Exit");
1006
1007 return IFD_SUCCESS;
1008 } /* T0ProcACK */
1009
1010
1011 /*****************************************************************************
1012 *
1013 * T0ProcSW1
1014 *
1015 ****************************************************************************/
1016 static RESPONSECODE T0ProcSW1(unsigned int reader_index,
1017 unsigned char *rcv_buf, unsigned int *rcv_len,
1018 unsigned char *in_buf, unsigned int in_len)
1019 {
1020 RESPONSECODE return_value = IFD_SUCCESS;
1021 UCHAR tmp_buf[512];
1022 unsigned char *rcv_buf_tmp = rcv_buf;
1023 const unsigned int rcv_len_tmp = *rcv_len;
1024 unsigned char sw1, sw2;
1025
1026 /* store the SW1 */
1027 sw1 = *rcv_buf = *in_buf;
1028 rcv_buf++;
1029 in_buf++;
1030 in_len--;
1031 (*rcv_len)++;
1032
1033 /* store the SW2 */
1034 if (0 == in_len)
1035 {
1036 return_value = CCID_Transmit(reader_index, 0, rcv_buf, 1, 0);
1037 if (return_value != IFD_SUCCESS)
1038 return return_value;
1039
1040 in_len = 1;
1041
1042 return_value = CCID_Receive(reader_index, &in_len, tmp_buf);
1043 if (return_value != IFD_SUCCESS)
1044 return return_value;
1045
1046 in_buf = tmp_buf;
1047 }
1048 sw2 = *rcv_buf = *in_buf;
1049 rcv_buf++;
1050 in_buf++;
1051 in_len--;
1052 (*rcv_len)++;
1053
1054 if (return_value != IFD_SUCCESS)
1055 {
1056 rcv_buf_tmp[0] = rcv_buf_tmp[1] = 0;
1057 *rcv_len = rcv_len_tmp;
1058 }
1059
1060 DEBUG_COMM3("Exit: SW=%02X %02X", sw1, sw2);
1061
1062 return return_value;
1063 } /* T0ProcSW1 */
1064
1065
1066 /*****************************************************************************
1067 *
1068 * CmdXfrBlockCHAR_T0
1069 *
1070 ****************************************************************************/
1071 static RESPONSECODE CmdXfrBlockCHAR_T0(unsigned int reader_index,
1072 unsigned int snd_len, unsigned char snd_buf[], unsigned int *rcv_len,
1073 unsigned char rcv_buf[])
1074 {
1075 int is_rcv;
1076 unsigned char cmd[5];
1077 unsigned char tmp_buf[512];
1078 unsigned int exp_len, in_len;
1079 unsigned char ins, *in_buf;
1080 RESPONSECODE return_value = IFD_SUCCESS;
1081
1082 DEBUG_COMM2("T=0: %d bytes", snd_len);
1083
1084 in_buf = tmp_buf;
1085 in_len = 0;
1086 *rcv_len = 0;
1087
1088 return_value = T0CmdParsing(snd_buf, snd_len, &exp_len);
1089 if (return_value != IFD_SUCCESS)
1090 {
1091 DEBUG_CRITICAL("T0CmdParsing failed");
1092 return IFD_COMMUNICATION_ERROR;
1093 }
1094
1095 if (snd_len == 5 || snd_len == 4)
1096 is_rcv = 1;
1097 else
1098 is_rcv = 0;
1099
1100 /* Command to send to the smart card (must be 5 bytes, from 7816 p.15) */
1101 memset(cmd, 0, sizeof(cmd));
1102 if (snd_len == 4)
1103 {
1104 memcpy(cmd, snd_buf, 4);
1105 snd_buf += 4;
1106 snd_len -= 4;
1107 }
1108 else
1109 {
1110 memcpy(cmd, snd_buf, 5);
1111 snd_buf += 5;
1112 snd_len -= 5;
1113 }
1114
1115 /* Make sure this is a valid command by checking the INS field */
1116 ins = cmd[1];
1117 if ((ins & 0xF0) == 0x60 || /* 7816-3 8.3.2 */
1118 (ins & 0xF0) == 0x90)
1119 {
1120 DEBUG_CRITICAL2("fatal: INS (0x%02X) = 0x6X or 0x9X", ins);
1121 return IFD_COMMUNICATION_ERROR;
1122 }
1123
1124 return_value = CCID_Transmit(reader_index, 5, cmd, 1, 0);
1125 if (return_value != IFD_SUCCESS)
1126 return return_value;
1127
1128 while (1)
1129 {
1130 if (in_len == 0)
1131 {
1132 in_len = 1;
1133 return_value = CCID_Receive(reader_index, &in_len, tmp_buf);
1134 if (return_value != IFD_SUCCESS)
1135 {
1136 DEBUG_CRITICAL("CCID_Receive failed");
1137 return return_value;
1138 }
1139 in_buf = tmp_buf;
1140 }
1141 if (in_len == 0)
1142 {
1143 /* Suppose we should be able to get data.
1144 * If not, error. Set the time-out error */
1145 DEBUG_CRITICAL("error: in_len = 0");
1146 return IFD_RESPONSE_TIMEOUT;
1147 }
1148
1149 /* Start to process the procedure bytes */
1150 if (*in_buf == 0x60)
1151 {
1152 in_len = 0;
1153 return_value = CCID_Transmit(reader_index, 0, cmd, 1, 0);
1154
1155 if (return_value != IFD_SUCCESS)
1156 return return_value;
1157
1158 continue;
1159 }
1160 else if (*in_buf == ins || *in_buf == (ins ^ 0x01))
1161 {
1162 /* ACK => To transfer all remaining data bytes */
1163 in_buf++, in_len--;
1164 if (is_rcv)
1165 return_value = T0ProcACK(reader_index, &snd_buf, &snd_len,
1166 &rcv_buf, rcv_len, &in_buf, &in_len, exp_len - *rcv_len, 1);
1167 else
1168 return_value = T0ProcACK(reader_index, &snd_buf, &snd_len,
1169 &rcv_buf, rcv_len, &in_buf, &in_len, snd_len, 0);
1170
1171 if (*rcv_len == exp_len)
1172 return return_value;
1173
1174 continue;
1175 }
1176 else if (*in_buf == (ins ^ 0xFF) || *in_buf == (ins ^ 0xFE))
1177 {
1178 /* ACK => To transfer 1 remaining bytes */
1179 in_buf++, in_len--;
1180 return_value = T0ProcACK(reader_index, &snd_buf, &snd_len,
1181 &rcv_buf, rcv_len, &in_buf, &in_len, 1, is_rcv);
1182
1183 if (return_value != IFD_SUCCESS)
1184 return return_value;
1185
1186 continue;
1187 }
1188 else if ((*in_buf & 0xF0) == 0x60 || (*in_buf & 0xF0) == 0x90)
1189 /* SW1 */
1190 return T0ProcSW1(reader_index, rcv_buf, rcv_len, in_buf, in_len);
1191
1192 /* Error, unrecognized situation found */
1193 DEBUG_CRITICAL2("Unrecognized Procedure byte (0x%02X) found!", *in_buf);
1194 return return_value;
1195 }
1196
1197 return return_value;
1198 } /* CmdXfrBlockCHAR_T0 */
1199
1200
1201 /*****************************************************************************
1202 *
1203 * CmdXfrBlockTPDU_T1
1204 *
1205 ****************************************************************************/
1206 static RESPONSECODE CmdXfrBlockTPDU_T1(unsigned int reader_index,
1207 unsigned int tx_length, unsigned char tx_buffer[], unsigned int *rx_length,
1208 unsigned char rx_buffer[])
1209 {
1210 RESPONSECODE return_value = IFD_SUCCESS;
1211 int ret;
1212
1213 DEBUG_COMM2("T=1: %d bytes", tx_length);
1214
1215 ret = t1_transceive(&((get_ccid_slot(reader_index)) -> t1), 0,
1216 tx_buffer, tx_length, rx_buffer, *rx_length);
1217
1218 if (ret < 0)
1219 {
1220 *rx_length = 0;
1221 return_value = IFD_COMMUNICATION_ERROR;
1222 }
1223 else
1224 *rx_length = ret;
1225
1226 return return_value;
1227 } /* CmdXfrBlockTPDU_T1 */
1228
1229
1230 /*****************************************************************************
1231 *
1232 * SetParameters
1233 *
1234 ****************************************************************************/
1235 RESPONSECODE SetParameters(unsigned int reader_index, char protocol,
1236 unsigned int length, unsigned char buffer[])
1237 {
1238 unsigned char cmd[10+CMD_BUF_SIZE]; /* CCID + APDU buffer */
1239 _ccid_descriptor *ccid_descriptor = get_ccid_descriptor(reader_index);
1240
1241 DEBUG_COMM2("length: %d bytes", length);
1242
1243 cmd[0] = 0x61; /* SetParameters */
1244 i2dw(length, cmd+1); /* APDU length */
1245 cmd[5] = ccid_descriptor->bCurrentSlotIndex; /* slot number */
1246 cmd[6] = (*ccid_descriptor->pbSeq)++;
1247 cmd[7] = protocol; /* bProtocolNum */
1248 cmd[8] = cmd[9] = 0; /* RFU */
1249
1250 /* check that the command is not too large */
1251 if (length > CMD_BUF_SIZE)
1252 return IFD_NOT_SUPPORTED;
1253
1254 memcpy(cmd+10, buffer, length);
1255
1256 if (WritePort(reader_index, 10+length, cmd) != STATUS_SUCCESS)
1257 return IFD_COMMUNICATION_ERROR;
1258
1259 length = sizeof(cmd);
1260 if (ReadPort(reader_index, &length, cmd) != STATUS_SUCCESS)
1261 return IFD_COMMUNICATION_ERROR;
1262
1263 if (cmd[STATUS_OFFSET] & CCID_COMMAND_FAILED)
1264 {
1265 ccid_error(cmd[ERROR_OFFSET], __FILE__, __LINE__, __FUNCTION__); /* bError */
1266 if (0x00 == cmd[ERROR_OFFSET]) /* command not supported */
1267 return IFD_NOT_SUPPORTED;
1268 else
1269 return IFD_COMMUNICATION_ERROR;
1270 }
1271
1272 return IFD_SUCCESS;
1273 } /* SetParameters */
1274
1275
1276 /*****************************************************************************
1277 *
1278 * isCharLevel
1279 *
1280 ****************************************************************************/
1281 int isCharLevel(int reader_index)
1282 {
1283 return CCID_CLASS_CHARACTER == (get_ccid_descriptor(reader_index)->dwFeatures & CCID_CLASS_EXCHANGE_MASK);
1284 } /* isCharLevel */
1285
1286
1287 /*****************************************************************************
1288 *
1289 * i2dw
1290 *
1291 ****************************************************************************/
1292 static void i2dw(int value, unsigned char buffer[])
1293 {
1294 buffer[0] = value & 0xFF;
1295 buffer[1] = (value >> 8) & 0xFF;
1296 buffer[2] = (value >> 16) & 0xFF;
1297 buffer[3] = (value >> 24) & 0xFF;
1298 } /* i2dw */
1299

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.5