Initial commit
[platform/upstream/ccid.git] / src / ccid.c
1 /*
2     ccid.c: CCID common code
3     Copyright (C) 2003-2010   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 License
16         along with this library; if not, write to the Free Software Foundation,
17         Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include <config.h>
21
22 #ifdef HAVE_STDIO_H
23 #include <stdio.h>
24 #endif
25 #ifdef HAVE_STDLIB_H
26 #include <stdlib.h>
27 #endif
28 #ifdef HAVE_STRING_H
29 #include <string.h>
30 #endif
31 #ifdef HAVE_UNISTD_H
32 #include <unistd.h>
33 #endif
34
35 #include <pcsclite.h>
36 #include <ifdhandler.h>
37
38 #include "debug.h"
39 #include "ccid.h"
40 #include "defs.h"
41 #include "ccid_ifdhandler.h"
42 #include "commands.h"
43 #include "utils.h"
44
45 #ifdef __APPLE__
46 #include <CoreFoundation/CoreFoundation.h>
47 #endif
48
49 /*****************************************************************************
50  *
51  *                                      ccid_open_hack_pre
52  *
53  ****************************************************************************/
54 int ccid_open_hack_pre(unsigned int reader_index)
55 {
56         _ccid_descriptor *ccid_descriptor = get_ccid_descriptor(reader_index);
57
58         switch (ccid_descriptor->readerID)
59         {
60                 case MYSMARTPAD:
61                         ccid_descriptor->dwMaxIFSD = 254;
62                         break;
63
64                 case CL1356D:
65                         /* the firmware needs some time to initialize */
66                         (void)sleep(1);
67                         ccid_descriptor->readTimeout = 60*1000; /* 60 seconds */
68                         break;
69
70 #ifdef ENABLE_ZLP
71                 case GEMPCTWIN:
72                 case GEMPCKEY:
73                 case DELLSCRK:
74                         /* Only the chipset with firmware version 2.00 is "bogus"
75                          * The reader may send packets of 0 bytes when the reader is
76                          * connected to a USB 3 port */
77                         if (0x0200 == ccid_descriptor->IFD_bcdDevice)
78                         {
79                                 ccid_descriptor->zlp = TRUE;
80                                 DEBUG_INFO1("ZLP fixup");
81                         }
82                         break;
83 #endif
84
85                 case OZ776:
86                 case OZ776_7772:
87                         ccid_descriptor->dwMaxDataRate = 9600;
88                         break;
89
90                 case ElatecTWN4_CCID_CDC:
91                 case ElatecTWN4_CCID:
92                         /* Use a timeout of 1000 ms instead of 100 ms in
93                          * CmdGetSlotStatus() used by CreateChannelByNameOrChannel()
94                          * The reader answers after up to 1 s if no tag is present */
95                         ccid_descriptor->readTimeout = DEFAULT_COM_READ_TIMEOUT * 10;
96                         break;
97
98                 case SCM_SCL011:
99                 case IDENTIV_uTrust3700F:
100                 case IDENTIV_uTrust3701F:
101                 case IDENTIV_uTrust4701F:
102                         /* The SCM SCL011 reader needs 350 ms to answer */
103                         ccid_descriptor->readTimeout = DEFAULT_COM_READ_TIMEOUT * 4;
104                         break;
105         }
106
107         /* CCID */
108         if ((PROTOCOL_CCID == ccid_descriptor->bInterfaceProtocol)
109                 && (3 == ccid_descriptor -> bNumEndpoints))
110         {
111 #ifndef TWIN_SERIAL
112                 /* just wait for 100ms in case a notification is in the pipe */
113                 (void)InterruptRead(reader_index, 100);
114 #endif
115         }
116
117         /* ICCD type A */
118         if (PROTOCOL_ICCD_A == ccid_descriptor->bInterfaceProtocol)
119         {
120                 unsigned char tmp[MAX_ATR_SIZE];
121                 unsigned int n = sizeof(tmp);
122
123                 DEBUG_COMM("ICCD type A");
124                 (void)CmdPowerOff(reader_index);
125                 (void)CmdPowerOn(reader_index, &n, tmp, VOLTAGE_AUTO);
126                 (void)CmdPowerOff(reader_index);
127         }
128
129         /* ICCD type B */
130         if (PROTOCOL_ICCD_B == ccid_descriptor->bInterfaceProtocol)
131         {
132                 unsigned char tmp[MAX_ATR_SIZE];
133                 unsigned int n = sizeof(tmp);
134
135                 DEBUG_COMM("ICCD type B");
136                 if (CCID_CLASS_SHORT_APDU ==
137                         (ccid_descriptor->dwFeatures & CCID_CLASS_EXCHANGE_MASK))
138                 {
139                         /* use the extended APDU comm alogorithm */
140                         ccid_descriptor->dwFeatures &= ~CCID_CLASS_EXCHANGE_MASK;
141                         ccid_descriptor->dwFeatures |= CCID_CLASS_EXTENDED_APDU;
142                 }
143
144                 (void)CmdPowerOff(reader_index);
145                 (void)CmdPowerOn(reader_index, &n, tmp, VOLTAGE_AUTO);
146                 (void)CmdPowerOff(reader_index);
147         }
148
149         return 0;
150 } /* ccid_open_hack_pre */
151
152 #ifndef NO_LOG
153 /*****************************************************************************
154  *
155  *                                      dump_gemalto_firmware_features
156  *
157  ****************************************************************************/
158 static void dump_gemalto_firmware_features(struct GEMALTO_FIRMWARE_FEATURES *gff)
159 {
160         DEBUG_INFO2("Dumping Gemalto firmware features (%zd bytes):",
161                 sizeof(struct GEMALTO_FIRMWARE_FEATURES));
162
163 #define YESNO(x) (x) ? "yes" : "no"
164
165         DEBUG_INFO2(" bLogicalLCDLineNumber: %d", gff->bLogicalLCDLineNumber);
166         DEBUG_INFO2(" bLogicalLCDRowNumber: %d", gff->bLogicalLCDRowNumber);
167         DEBUG_INFO2(" bLcdInfo: 0x%02X", gff->bLcdInfo);
168         DEBUG_INFO2(" bEntryValidationCondition: 0x%02X",
169                 gff->bEntryValidationCondition);
170
171         DEBUG_INFO1(" Reader supports PC/SCv2 features:");
172         DEBUG_INFO2("  VerifyPinStart: %s", YESNO(gff->VerifyPinStart));
173         DEBUG_INFO2("  VerifyPinFinish: %s", YESNO(gff->VerifyPinFinish));
174         DEBUG_INFO2("  ModifyPinStart: %s", YESNO(gff->ModifyPinStart));
175         DEBUG_INFO2("  ModifyPinFinish: %s", YESNO(gff->ModifyPinFinish));
176         DEBUG_INFO2("  GetKeyPressed: %s", YESNO(gff->GetKeyPressed));
177         DEBUG_INFO2("  VerifyPinDirect: %s", YESNO(gff->VerifyPinDirect));
178         DEBUG_INFO2("  ModifyPinDirect: %s", YESNO(gff->ModifyPinDirect));
179         DEBUG_INFO2("  Abort: %s", YESNO(gff->Abort));
180         DEBUG_INFO2("  GetKey: %s", YESNO(gff->GetKey));
181         DEBUG_INFO2("  WriteDisplay: %s", YESNO(gff->WriteDisplay));
182         DEBUG_INFO2("  SetSpeMessage: %s", YESNO(gff->SetSpeMessage));
183         DEBUG_INFO2("  bTimeOut2: %s", YESNO(gff->bTimeOut2));
184         DEBUG_INFO2("  bPPDUSupportOverXferBlock: %s",
185                 YESNO(gff->bPPDUSupportOverXferBlock));
186         DEBUG_INFO2("  bPPDUSupportOverEscape: %s",
187                 YESNO(gff->bPPDUSupportOverEscape));
188
189         DEBUG_INFO2(" bListSupportedLanguages: %s",
190                 YESNO(gff->bListSupportedLanguages));
191         DEBUG_INFO2(" bNumberMessageFix: %s", YESNO(gff->bNumberMessageFix));
192
193         DEBUG_INFO2(" VersionNumber: 0x%02X", gff->VersionNumber);
194         DEBUG_INFO2(" MinimumPINSize: %d", gff->MinimumPINSize);
195         DEBUG_INFO2(" MaximumPINSize: %d", gff->MaximumPINSize);
196         DEBUG_INFO2(" Firewall: %s", YESNO(gff->Firewall));
197         if (gff->Firewall && gff->FirewalledCommand_SW1
198                 && gff->FirewalledCommand_SW2)
199         {
200                 DEBUG_INFO2("  FirewalledCommand_SW1: 0x%02X",
201                         gff->FirewalledCommand_SW1);
202                 DEBUG_INFO2("  FirewalledCommand_SW2: 0x%02X",
203                         gff->FirewalledCommand_SW2);
204         }
205
206 } /* dump_gemalto_firmware_features */
207 #endif
208
209 /*****************************************************************************
210  *
211  *                                      set_gemalto_firmware_features
212  *
213  ****************************************************************************/
214 static void set_gemalto_firmware_features(unsigned int reader_index)
215 {
216         _ccid_descriptor *ccid_descriptor = get_ccid_descriptor(reader_index);
217         struct GEMALTO_FIRMWARE_FEATURES *gf_features;
218
219         gf_features = malloc(sizeof(struct GEMALTO_FIRMWARE_FEATURES));
220         if (gf_features)
221         {
222                 unsigned char cmd[] = { 0x6A }; /* GET_FIRMWARE_FEATURES command id */
223                 unsigned int len_features = sizeof *gf_features;
224                 RESPONSECODE ret;
225
226                 ret = CmdEscapeCheck(reader_index, cmd, sizeof cmd,
227                         (unsigned char*)gf_features, &len_features, 0, TRUE);
228                 if ((IFD_SUCCESS == ret) &&
229                     (len_features == sizeof *gf_features))
230                 {
231                         /* Command is supported if it succeeds at CCID level */
232                         /* and returned size matches our expectation */
233                         ccid_descriptor->gemalto_firmware_features = gf_features;
234 #ifndef NO_LOG
235                         dump_gemalto_firmware_features(gf_features);
236 #endif
237                 }
238                 else
239                 {
240                         /* Command is not supported, let's free allocated memory */
241                         free(gf_features);
242                         DEBUG_INFO3("GET_FIRMWARE_FEATURES failed: " DWORD_D ", len=%d",
243                                 ret, len_features);
244                 }
245         }
246 } /* set_gemalto_firmware_features */
247
248 /*****************************************************************************
249  *
250  *                                      ccid_open_hack_post
251  *
252  ****************************************************************************/
253 int ccid_open_hack_post(unsigned int reader_index)
254 {
255         _ccid_descriptor *ccid_descriptor = get_ccid_descriptor(reader_index);
256         RESPONSECODE return_value = IFD_SUCCESS;
257
258         switch (ccid_descriptor->readerID)
259         {
260                 case GEMPCKEY:
261                 case GEMPCTWIN:
262                         /* Reader announces TPDU but can do APDU (EMV in fact) */
263                         if (DriverOptions & DRIVER_OPTION_GEMPC_TWIN_KEY_APDU)
264                         {
265                                 unsigned char cmd[] = { 0x1F, 0x02 };
266                                 unsigned char res[10];
267                                 unsigned int length_res = sizeof(res);
268
269                                 if (CmdEscape(reader_index, cmd, sizeof(cmd), res, &length_res, 0) == IFD_SUCCESS)
270                                 {
271                                         ccid_descriptor->dwFeatures &= ~CCID_CLASS_EXCHANGE_MASK;
272                                         ccid_descriptor->dwFeatures |= CCID_CLASS_SHORT_APDU;
273                                 }
274                         }
275                         break;
276
277                 case VEGAALPHA:
278                 case GEMPCPINPAD:
279                         /* load the l10n strings in the pinpad memory */
280                         {
281 #define L10N_HEADER_SIZE 5
282 #define L10N_STRING_MAX_SIZE 16
283 #define L10N_NB_STRING 10
284
285                                 unsigned char cmd[L10N_HEADER_SIZE + L10N_NB_STRING * L10N_STRING_MAX_SIZE];
286                                 unsigned char res[20];
287                                 unsigned int length_res = sizeof(res);
288                                 int offset, i, j;
289
290                                 const char *fr[] = {
291                                         "Entrer PIN",
292                                         "Nouveau PIN",
293                                         "Confirmer PIN",
294                                         "PIN correct",
295                                         "PIN Incorrect !",
296                                         "Delai depasse",
297                                         "* essai restant",
298                                         "Inserer carte",
299                                         "Erreur carte",
300                                         "PIN bloque" };
301
302                                 const char *de[] = {
303                                         "PIN eingeben",
304                                         "Neue PIN",
305                                         "PIN bestatigen",
306                                         "PIN korrect",
307                                         "Falsche PIN !",
308                                         "Zeit abgelaufen",
309                                         "* Versuche ubrig",
310                                         "Karte einstecken",
311                                         "Fehler Karte",
312                                         "PIN blockiert" };
313
314                                 const char *es[] = {
315                                         "Introducir PIN",
316                                         "Nuevo PIN",
317                                         "Confirmar PIN",
318                                         "PIN OK",
319                                         "PIN Incorrecto !",
320                                         "Tiempo Agotado",
321                                         "* ensayos quedan",
322                                         "Introducir Tarj.",
323                                         "Error en Tarjeta",
324                                         "PIN bloqueado" };
325
326                                 const char *it[] = {
327                                         "Inserire PIN",
328                                         "Nuovo PIN",
329                                         "Confermare PIN",
330                                         "PIN Corretto",
331                                         "PIN Errato !",
332                                         "Tempo scaduto",
333                                         "* prove rimaste",
334                                         "Inserire Carta",
335                                         "Errore Carta",
336                                         "PIN ostruito"};
337
338                                 const char *pt[] = {
339                                         "Insira PIN",
340                                         "Novo PIN",
341                                         "Conf. novo PIN",
342                                         "PIN OK",
343                                         "PIN falhou!",
344                                         "Tempo expirou",
345                                         "* tentiv. restam",
346                                         "Introduza cartao",
347                                         "Erro cartao",
348                                         "PIN bloqueado" };
349
350                                 const char *nl[] = {
351                                         "Inbrengen code",
352                                         "Nieuwe code",
353                                         "Bevestig code",
354                                         "Code aanvaard",
355                                         "Foute code",
356                                         "Time out",
357                                         "* Nog Pogingen",
358                                         "Kaart inbrengen",
359                                         "Kaart fout",
360                                         "Kaart blok" };
361
362                                 const char *tr[] = {
363                                         "PIN Giriniz",
364                                         "Yeni PIN",
365                                         "PIN Onayala",
366                                         "PIN OK",
367                                         "Yanlis PIN",
368                                         "Zaman Asimi",
369                                         "* deneme kaldi",
370                                         "Karti Takiniz",
371                                         "Kart Hatasi",
372                                         "Kart Kilitli" };
373
374                                 const char *en[] = {
375                                         "Enter PIN",
376                                         "New PIN",
377                                         "Confirm PIN",
378                                         "PIN OK",
379                                         "Incorrect PIN!",
380                                         "Time Out",
381                                         "* retries left",
382                                         "Insert Card",
383                                         "Card Error",
384                                         "PIN blocked" };
385
386                                 const char *lang;
387                                 const char **l10n;
388
389 #ifdef __APPLE__
390                                 CFArrayRef cfa;
391                                 CFStringRef slang;
392
393                                 /* Get the complete ordered list */
394                                 cfa = CFLocaleCopyPreferredLanguages();
395
396                                 /* Use the first/preferred language
397                                  * As the driver is run as root we get the language
398                                  * selected during install */
399                                 slang = CFArrayGetValueAtIndex(cfa, 0);
400
401                                 /* CFString -> C string */
402                                 lang = CFStringGetCStringPtr(slang, kCFStringEncodingMacRoman);
403 #else
404                                 /* The other Unixes just use the LANG env variable */
405                                 lang = getenv("LANG");
406 #endif
407                                 DEBUG_COMM2("Using lang: %s", lang);
408                                 if (NULL == lang)
409                                         l10n = en;
410                                 else
411                                 {
412                                         if (0 == strncmp(lang, "fr", 2))
413                                                 l10n = fr;
414                                         else if (0 == strncmp(lang, "de", 2))
415                                                 l10n = de;
416                                         else if (0 == strncmp(lang, "es", 2))
417                                                 l10n = es;
418                                         else if (0 == strncmp(lang, "it", 2))
419                                                 l10n = it;
420                                         else if (0 == strncmp(lang, "pt", 2))
421                                                 l10n = pt;
422                                         else if (0 == strncmp(lang, "nl", 2))
423                                                 l10n = nl;
424                                         else if (0 == strncmp(lang, "tr", 2))
425                                                 l10n = tr;
426                                         else
427                                                 l10n = en;
428                                 }
429
430 #ifdef __APPLE__
431                                 /* Release the allocated array */
432                                 CFRelease(cfa);
433 #endif
434                                 offset = 0;
435                                 cmd[offset++] = 0xB2;   /* load strings */
436                                 cmd[offset++] = 0xA0;   /* address of the memory */
437                                 cmd[offset++] = 0x00;   /* address of the first byte */
438                                 cmd[offset++] = 0x4D;   /* magic value */
439                                 cmd[offset++] = 0x4C;   /* magic value */
440
441                                 /* for each string */
442                                 for (i=0; i<L10N_NB_STRING; i++)
443                                 {
444                                         /* copy the string */
445                                         for (j=0; l10n[i][j]; j++)
446                                                 cmd[offset++] = l10n[i][j];
447
448                                         /* pad with " " */
449                                         for (; j<L10N_STRING_MAX_SIZE; j++)
450                                                 cmd[offset++] = ' ';
451                                 }
452
453                                 (void)sleep(1);
454                                 if (IFD_SUCCESS == CmdEscape(reader_index, cmd, sizeof(cmd), res, &length_res, DEFAULT_COM_READ_TIMEOUT))
455                                 {
456                                         DEBUG_COMM("l10n string loaded successfully");
457                                 }
458                                 else
459                                 {
460                                         DEBUG_COMM("Failed to load l10n strings");
461                                         return_value = IFD_COMMUNICATION_ERROR;
462                                 }
463
464                                 if (DriverOptions & DRIVER_OPTION_DISABLE_PIN_RETRIES)
465                                 {
466                                         /* disable VERIFY from reader */
467                                         const unsigned char cmd2[] = {0xb5, 0x00};
468                                         length_res = sizeof(res);
469                                         if (IFD_SUCCESS == CmdEscape(reader_index, cmd2, sizeof(cmd2), res, &length_res, DEFAULT_COM_READ_TIMEOUT))
470                                         {
471                                                 DEBUG_COMM("Disable SPE retry counter successful");
472                                         }
473                                         else
474                                         {
475                                                 DEBUG_CRITICAL("Failed to disable SPE retry counter");
476                                         }
477                                 }
478                         }
479                         break;
480
481                 case HPSMARTCARDKEYBOARD:
482                 case HP_CCIDSMARTCARDKEYBOARD:
483                 case FUJITSUSMARTKEYB:
484                 case CHICONYHPSKYLABKEYBOARD:
485                         /* the Secure Pin Entry is bogus so disable it
486                          * https://web.archive.org/web/20120320001756/http://martinpaljak.net/2011/03/19/insecure-hp-usb-smart-card-keyboard/
487                          *
488                          * The problem is that the PIN code entered using the Secure
489                          * Pin Entry function is also sent to the host.
490                          */
491
492                 case C3PO_LTC31_v2:
493                         ccid_descriptor->bPINSupport = 0;
494                         break;
495
496                 case HID_AVIATOR:      /* OMNIKEY Generic */
497                 case HID_OMNIKEY_3X21: /* OMNIKEY 3121 or 3021 or 1021 */
498                 case HID_OMNIKEY_6121: /* OMNIKEY 6121 */
499                 case CHERRY_XX44:      /* Cherry Smart Terminal xx44 */
500                 case FUJITSU_D323:     /* Fujitsu Smartcard Reader D323 */
501                         /* The chip advertises pinpad but actually doesn't have one */
502                         ccid_descriptor->bPINSupport = 0;
503                         /* Firmware uses chaining */
504                         ccid_descriptor->dwFeatures &= ~CCID_CLASS_EXCHANGE_MASK;
505                         ccid_descriptor->dwFeatures |= CCID_CLASS_EXTENDED_APDU;
506                         break;
507
508 #if 0
509                 /* SCM SCR331-DI contactless */
510                 case SCR331DI:
511                 /* SCM SCR331-DI-NTTCOM contactless */
512                 case SCR331DINTTCOM:
513                 /* SCM SDI010 contactless */
514                 case SDI010:
515                         /* the contactless reader is in the second slot */
516                         if (ccid_descriptor->bCurrentSlotIndex > 0)
517                         {
518                                 unsigned char cmd1[] = { 0x00 };
519                                 /*  command: 00 ??
520                                  * response: 06 10 03 03 00 00 00 01 FE FF FF FE 01 ?? */
521                                 unsigned char cmd2[] = { 0x02 };
522                                 /*  command: 02 ??
523                                  * response: 00 ?? */
524
525                                 unsigned char res[20];
526                                 unsigned int length_res = sizeof(res);
527
528                                 if ((IFD_SUCCESS == CmdEscape(reader_index, cmd1, sizeof(cmd1), res, &length_res, 0))
529                                         && (IFD_SUCCESS == CmdEscape(reader_index, cmd2, sizeof(cmd2), res, &length_res, 0)))
530                                 {
531                                         DEBUG_COMM("SCM SCR331-DI contactless detected");
532                                 }
533                                 else
534                                 {
535                                         DEBUG_COMM("SCM SCR331-DI contactless init failed");
536                                 }
537
538                                 /* hack since the contactless reader do not share dwFeatures */
539                                 ccid_descriptor->dwFeatures &= ~CCID_CLASS_EXCHANGE_MASK;
540                                 ccid_descriptor->dwFeatures |= CCID_CLASS_SHORT_APDU;
541
542                                 ccid_descriptor->dwFeatures |= CCID_CLASS_AUTO_IFSD;
543                         }
544                         break;
545 #endif
546                 case CHERRY_KC1000SC:
547                         if ((0x0100 == ccid_descriptor->IFD_bcdDevice)
548                                 && (ccid_descriptor->dwFeatures & CCID_CLASS_EXCHANGE_MASK) == CCID_CLASS_SHORT_APDU)
549                         {
550                                 /* firmware 1.00 is bogus
551                                  * With a T=1 card and case 2 APDU (data from card to
552                                  * host) the maximum size returned by the reader is 128
553                                  * byes. The reader is then using chaining as with
554                                  * extended APDU.
555                                  */
556                                 ccid_descriptor->dwFeatures &= ~CCID_CLASS_EXCHANGE_MASK;
557                                 ccid_descriptor->dwFeatures |= CCID_CLASS_EXTENDED_APDU;
558                         }
559                         break;
560
561                 case ElatecTWN4_CCID_CDC:
562                 case ElatecTWN4_CCID:
563                 case SCM_SCL011:
564                         /* restore default timeout (modified in ccid_open_hack_pre()) */
565                         ccid_descriptor->readTimeout = DEFAULT_COM_READ_TIMEOUT;
566                         break;
567         }
568
569         /* Gemalto readers may report additional information */
570         if (GET_VENDOR(ccid_descriptor->readerID) == VENDOR_GEMALTO)
571                 set_gemalto_firmware_features(reader_index);
572
573         return return_value;
574 } /* ccid_open_hack_post */
575
576 /*****************************************************************************
577  *
578  *                                      ccid_error
579  *
580  ****************************************************************************/
581 void ccid_error(int log_level, int error, const char *file, int line,
582         const char *function)
583 {
584 #ifndef NO_LOG
585         const char *text;
586         char var_text[30];
587
588         switch (error)
589         {
590                 case 0x00:
591                         text = "Command not supported or not allowed";
592                         break;
593
594                 case 0x01:
595                         text = "Wrong command length";
596                         break;
597
598                 case 0x05:
599                         text = "Invalid slot number";
600                         break;
601
602                 case 0xA2:
603                         text = "Card short-circuiting. Card powered off";
604                         break;
605
606                 case 0xA3:
607                         text = "ATR too long (> 33)";
608                         break;
609
610                 case 0xAB:
611                         text = "No data exchanged";
612                         break;
613
614                 case 0xB0:
615                         text = "Reader in EMV mode and T=1 message too long";
616                         break;
617
618                 case 0xBB:
619                         text = "Protocol error in EMV mode";
620                         break;
621
622                 case 0xBD:
623                         text = "Card error during T=1 exchange";
624                         break;
625
626                 case 0xBE:
627                         text = "Wrong APDU command length";
628                         break;
629
630                 case 0xE0:
631                         text = "Slot busy";
632                         break;
633
634                 case 0xEF:
635                         text = "PIN cancelled";
636                         break;
637
638                 case 0xF0:
639                         text = "PIN timeout";
640                         break;
641
642                 case 0xF2:
643                         text = "Busy with autosequence";
644                         break;
645
646                 case 0xF3:
647                         text = "Deactivated protocol";
648                         break;
649
650                 case 0xF4:
651                         text = "Procedure byte conflict";
652                         break;
653
654                 case 0xF5:
655                         text = "Class not supported";
656                         break;
657
658                 case 0xF6:
659                         text = "Protocol not supported";
660                         break;
661
662                 case 0xF7:
663                         text = "Invalid ATR checksum byte (TCK)";
664                         break;
665
666                 case 0xF8:
667                         text = "Invalid ATR first byte";
668                         break;
669
670                 case 0xFB:
671                         text = "Hardware error";
672                         break;
673
674                 case 0xFC:
675                         text = "Overrun error";
676                         break;
677
678                 case 0xFD:
679                         text = "Parity error during exchange";
680                         break;
681
682                 case 0xFE:
683                         text = "Card absent or mute";
684                         break;
685
686                 case 0xFF:
687                         text = "Activity aborted by Host";
688                         break;
689
690                 default:
691                         if ((error >= 1) && (error <= 127))
692                                 (void)snprintf(var_text, sizeof(var_text), "error on byte %d",
693                                         error);
694                         else
695                                 (void)snprintf(var_text, sizeof(var_text),
696                                         "Unknown CCID error: 0x%02X", error);
697
698                         text = var_text;
699                         break;
700         }
701 #ifdef USE_OS_LOG
702         (log_level);
703         os_log_error(OS_LOG_DEFAULT, "%s:%d:%s %s", file, line, function, text);
704 #else
705         log_msg(log_level, "%s:%d:%s %s", file, line, function, text);
706 #endif
707 #endif
708
709 } /* ccid_error */
710