pcsc-lite  1.8.20
error.c
Go to the documentation of this file.
1 /*
2  * MUSCLE SmartCard Development ( http://pcsclite.alioth.debian.org/pcsclite.html )
3  *
4  * Copyright (C) 1999-2002
5  * David Corcoran <corcoran@musclecard.com>
6  * Copyright (C) 2006-2009
7  * Ludovic Rousseau <ludovic.rousseau@free.fr>
8  *
9  * This file is dual licenced:
10  * - BSD-like, see the COPYING file
11  * - GNU Lesser General Licence 2.1 or (at your option) any later version.
12  *
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions
15 are met:
16 
17 1. Redistributions of source code must retain the above copyright
18  notice, this list of conditions and the following disclaimer.
19 2. Redistributions in binary form must reproduce the above copyright
20  notice, this list of conditions and the following disclaimer in the
21  documentation and/or other materials provided with the distribution.
22 3. The name of the author may not be used to endorse or promote products
23  derived from this software without specific prior written permission.
24 
25 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  */
36 
42 #include <stdio.h>
43 #include <sys/types.h>
44 
45 #include "config.h"
46 #include "misc.h"
47 #include "pcsclite.h"
48 #include "string.h"
49 
50 #ifdef NO_LOG
51 PCSC_API char* pcsc_stringify_error(const LONG pcscError)
52 {
53  static char strError[] = "0x12345678";
54 
55  snprintf(strError, sizeof(strError), "0x%08lX", pcscError);
56 
57  return strError;
58 }
59 #else
60 
77 PCSC_API char* pcsc_stringify_error(const LONG pcscError)
78 {
79  static char strError[75];
80  const char *msg = NULL;
81 
82  switch (pcscError)
83  {
84  case SCARD_S_SUCCESS:
85  msg = "Command successful.";
86  break;
88  msg = "Internal error.";
89  break;
90  case SCARD_E_CANCELLED:
91  msg = "Command cancelled.";
92  break;
94  msg = "Invalid handle.";
95  break;
97  msg = "Invalid parameter given.";
98  break;
100  msg = "Invalid target given.";
101  break;
102  case SCARD_E_NO_MEMORY:
103  msg = "Not enough memory.";
104  break;
106  msg = "Waited too long.";
107  break;
109  msg = "Insufficient buffer.";
110  break;
112  msg = "Unknown reader specified.";
113  break;
114  case SCARD_E_TIMEOUT:
115  msg = "Command timeout.";
116  break;
118  msg = "Sharing violation.";
119  break;
121  msg = "No smart card inserted.";
122  break;
124  msg = "Unknown card.";
125  break;
127  msg = "Cannot dispose handle.";
128  break;
130  msg = "Card protocol mismatch.";
131  break;
132  case SCARD_E_NOT_READY:
133  msg = "Subsystem not ready.";
134  break;
136  msg = "Invalid value given.";
137  break;
139  msg = "System cancelled.";
140  break;
141  case SCARD_F_COMM_ERROR:
142  msg = "RPC transport error.";
143  break;
145  msg = "Unknown error.";
146  break;
147  case SCARD_E_INVALID_ATR:
148  msg = "Invalid ATR.";
149  break;
151  msg = "Transaction failed.";
152  break;
154  msg = "Reader is unavailable.";
155  break;
156  /* case SCARD_P_SHUTDOWN: */
158  msg = "PCI struct too small.";
159  break;
161  msg = "Reader is unsupported.";
162  break;
164  msg = "Reader already exists.";
165  break;
167  msg = "Card is unsupported.";
168  break;
169  case SCARD_E_NO_SERVICE:
170  msg = "Service not available.";
171  break;
173  msg = "Service was stopped.";
174  break;
175  /* case SCARD_E_UNEXPECTED: */
176  /* case SCARD_E_ICC_CREATEORDER: */
177  /* case SCARD_E_UNSUPPORTED_FEATURE: */
178  /* case SCARD_E_DIR_NOT_FOUND: */
179  /* case SCARD_E_NO_DIR: */
180  /* case SCARD_E_NO_FILE: */
181  /* case SCARD_E_NO_ACCESS: */
182  /* case SCARD_E_WRITE_TOO_MANY: */
183  /* case SCARD_E_BAD_SEEK: */
184  /* case SCARD_E_INVALID_CHV: */
185  /* case SCARD_E_UNKNOWN_RES_MNG: */
186  /* case SCARD_E_NO_SUCH_CERTIFICATE: */
187  /* case SCARD_E_CERTIFICATE_UNAVAILABLE: */
189  msg = "Cannot find a smart card reader.";
190  break;
191  /* case SCARD_E_COMM_DATA_LOST: */
192  /* case SCARD_E_NO_KEY_CONTAINER: */
193  /* case SCARD_E_SERVER_TOO_BUSY: */
195  msg = "Card is not supported.";
196  break;
198  msg = "Card is unresponsive.";
199  break;
201  msg = "Card is unpowered.";
202  break;
203  case SCARD_W_RESET_CARD:
204  msg = "Card was reset.";
205  break;
207  msg = "Card was removed.";
208  break;
209  /* case SCARD_W_SECURITY_VIOLATION: */
210  /* case SCARD_W_WRONG_CHV: */
211  /* case SCARD_W_CHV_BLOCKED: */
212  /* case SCARD_W_EOF: */
213  /* case SCARD_W_CANCELLED_BY_USER: */
214  /* case SCARD_W_CARD_NOT_AUTHENTICATED: */
215 
217  msg = "Feature not supported.";
218  break;
219  default:
220  (void)snprintf(strError, sizeof(strError)-1, "Unknown error: 0x%08lX",
221  pcscError);
222  };
223 
224  if (msg)
225  (void)strncpy(strError, msg, sizeof(strError));
226  else
227  (void)snprintf(strError, sizeof(strError)-1, "Unknown error: 0x%08lX",
228  pcscError);
229 
230  /* add a null byte */
231  strError[sizeof(strError)-1] = '\0';
232 
233  return strError;
234 }
235 #endif
236 
#define SCARD_E_INVALID_VALUE
One or more of the supplied parameters values could not be properly interpreted.
Definition: pcsclite.h:141
#define SCARD_S_SUCCESS
No error was encountered.
Definition: pcsclite.h:107
#define SCARD_E_SYSTEM_CANCELLED
The action was cancelled by the system, presumably to log off or shut down.
Definition: pcsclite.h:143
#define SCARD_E_CARD_UNSUPPORTED
The smart card does not meet minimal requirements for support.
Definition: pcsclite.h:163
#define SCARD_E_TIMEOUT
The user-specified timeout value has expired.
Definition: pcsclite.h:127
#define SCARD_E_NO_SERVICE
The Smart card resource manager is not running.
Definition: pcsclite.h:165
#define SCARD_E_INVALID_TARGET
Registry startup information is missing or invalid.
Definition: pcsclite.h:117
#define SCARD_E_INVALID_PARAMETER
One or more of the supplied parameters could not be properly interpreted.
Definition: pcsclite.h:115
PCSC_API char * pcsc_stringify_error(const LONG pcscError)
Returns a human readable text for the given PC/SC error code.
Definition: error.c:77
#define SCARD_E_NO_READERS_AVAILABLE
Cannot find a smart card reader.
Definition: pcsclite.h:201
#define SCARD_E_INVALID_ATR
An ATR obtained from the registry is not a valid ATR string.
Definition: pcsclite.h:149
#define SCARD_E_NO_SMARTCARD
The operation requires a Smart Card, but no Smart Card is currently in the device.
Definition: pcsclite.h:131
#define SCARD_W_UNRESPONSIVE_CARD
The smart card is not responding to a reset.
Definition: pcsclite.h:212
#define SCARD_E_READER_UNSUPPORTED
The reader driver does not meet minimal requirements for support.
Definition: pcsclite.h:159
#define SCARD_E_NOT_TRANSACTED
An attempt was made to end a non-existent transaction.
Definition: pcsclite.h:151
#define SCARD_E_NOT_READY
The reader or smart card is not ready to accept commands.
Definition: pcsclite.h:139
#define SCARD_E_PROTO_MISMATCH
The requested protocols are incompatible with the protocol currently in use with the smart card...
Definition: pcsclite.h:137
#define SCARD_F_UNKNOWN_ERROR
An internal error has been detected, but the source is unknown.
Definition: pcsclite.h:147
#define SCARD_W_UNSUPPORTED_CARD
The reader cannot communicate with the card, due to ATR string configuration conflicts.
Definition: pcsclite.h:210
#define SCARD_E_NO_MEMORY
Not enough memory available to complete this command.
Definition: pcsclite.h:119
#define SCARD_E_READER_UNAVAILABLE
The specified reader is not currently available for use.
Definition: pcsclite.h:153
#define SCARD_E_PCI_TOO_SMALL
The PCI Receive buffer was too small.
Definition: pcsclite.h:157
#define SCARD_E_UNKNOWN_CARD
The specified smart card name is not recognized.
Definition: pcsclite.h:133
#define SCARD_W_RESET_CARD
The smart card has been reset, so any shared state information is invalid.
Definition: pcsclite.h:216
This keeps a list of defines for pcsc-lite.
#define SCARD_F_COMM_ERROR
An internal communications error has been detected.
Definition: pcsclite.h:145
#define SCARD_W_REMOVED_CARD
The smart card has been removed, so further communication is not possible.
Definition: pcsclite.h:218
#define SCARD_E_INSUFFICIENT_BUFFER
The data buffer to receive returned data is too small for the returned data.
Definition: pcsclite.h:123
#define SCARD_E_CANCELLED
The action was cancelled by an SCardCancel request.
Definition: pcsclite.h:111
#define SCARD_E_DUPLICATE_READER
The reader driver did not produce a unique reader name.
Definition: pcsclite.h:161
#define SCARD_E_CANT_DISPOSE
The system could not dispose of the media in the requested manner.
Definition: pcsclite.h:135
#define SCARD_E_SHARING_VIOLATION
The smart card cannot be accessed because of other connections outstanding.
Definition: pcsclite.h:129
#define SCARD_E_UNKNOWN_READER
The specified reader name is not recognized.
Definition: pcsclite.h:125
#define SCARD_F_INTERNAL_ERROR
An internal consistency check failed.
Definition: pcsclite.h:109
#define SCARD_E_UNSUPPORTED_FEATURE
This smart card does not support the requested feature.
Definition: pcsclite.h:171
#define SCARD_E_SERVICE_STOPPED
The Smart card resource manager has shut down.
Definition: pcsclite.h:167
#define SCARD_E_INVALID_HANDLE
The supplied handle was invalid.
Definition: pcsclite.h:113
#define SCARD_F_WAITED_TOO_LONG
An internal consistency timer has expired.
Definition: pcsclite.h:121
#define SCARD_W_UNPOWERED_CARD
Power has been removed from the smart card, so that further communication is not possible.
Definition: pcsclite.h:214