pcsc-lite 2.3.0
error.c
Go to the documentation of this file.
1/*
2 * MUSCLE SmartCard Development ( https://pcsclite.apdu.fr/ )
3 *
4 * Copyright (C) 1999-2002
5 * David Corcoran <corcoran@musclecard.com>
6 * Copyright (C) 2006-2024
7 * Ludovic Rousseau <ludovic.rousseau@free.fr>
8 *
9 * This file is dual licensed:
10 * - BSD-like, see the COPYING file
11 * - GNU Lesser General Licence 2.1 or (at your option) any later version.
12 *
13Redistribution and use in source and binary forms, with or without
14modification, are permitted provided that the following conditions
15are met:
16
171. Redistributions of source code must retain the above copyright
18 notice, this list of conditions and the following disclaimer.
192. 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.
223. 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
25THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34THIS 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
51PCSC_API const 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
82PCSC_API const char* pcsc_stringify_error(const LONG pcscError)
83{
84 /* Use a Thread-local storage so that the returned buffer
85 * is thread safe */
86 static __thread char strError[75];
87 const char *msg = NULL;
88
89 switch (pcscError)
90 {
91 case SCARD_S_SUCCESS:
92 msg = "Command successful.";
93 break;
95 msg = "Internal error.";
96 break;
98 msg = "Command cancelled.";
99 break;
101 msg = "Invalid handle.";
102 break;
104 msg = "Invalid parameter given.";
105 break;
107 msg = "Invalid target given.";
108 break;
110 msg = "Not enough memory.";
111 break;
113 msg = "Waited too long.";
114 break;
116 msg = "Insufficient buffer.";
117 break;
119 msg = "Unknown reader specified.";
120 break;
121 case SCARD_E_TIMEOUT:
122 msg = "Command timeout.";
123 break;
125 msg = "Sharing violation.";
126 break;
128 msg = "No smart card inserted.";
129 break;
131 msg = "Unknown card.";
132 break;
134 msg = "Cannot dispose handle.";
135 break;
137 msg = "Card protocol mismatch.";
138 break;
140 msg = "Subsystem not ready.";
141 break;
143 msg = "Invalid value given.";
144 break;
146 msg = "System cancelled.";
147 break;
149 msg = "RPC transport error.";
150 break;
152 msg = "Unknown error.";
153 break;
155 msg = "Invalid ATR.";
156 break;
158 msg = "Transaction failed.";
159 break;
161 msg = "Reader is unavailable.";
162 break;
163 /* case SCARD_P_SHUTDOWN: */
165 msg = "PCI struct too small.";
166 break;
168 msg = "Reader is unsupported.";
169 break;
171 msg = "Reader already exists.";
172 break;
174 msg = "Card is unsupported.";
175 break;
177 msg = "Service not available.";
178 break;
180 msg = "Service was stopped.";
181 break;
182 /* case SCARD_E_UNEXPECTED: */
183 /* case SCARD_E_ICC_CREATEORDER: */
184 /* case SCARD_E_UNSUPPORTED_FEATURE: */
185 /* case SCARD_E_DIR_NOT_FOUND: */
186 /* case SCARD_E_NO_DIR: */
187 /* case SCARD_E_NO_FILE: */
188 /* case SCARD_E_NO_ACCESS: */
189 /* case SCARD_E_WRITE_TOO_MANY: */
190 /* case SCARD_E_BAD_SEEK: */
191 /* case SCARD_E_INVALID_CHV: */
192 /* case SCARD_E_UNKNOWN_RES_MSG: */
193 /* case SCARD_E_NO_SUCH_CERTIFICATE: */
194 /* case SCARD_E_CERTIFICATE_UNAVAILABLE: */
196 msg = "Cannot find a smart card reader.";
197 break;
198 /* case SCARD_E_COMM_DATA_LOST: */
199 /* case SCARD_E_NO_KEY_CONTAINER: */
200 /* case SCARD_E_SERVER_TOO_BUSY: */
202 msg = "Card is not supported.";
203 break;
205 msg = "Card is unresponsive.";
206 break;
208 msg = "Card is unpowered.";
209 break;
211 msg = "Card was reset.";
212 break;
214 msg = "Card was removed.";
215 break;
217 msg = "Access denied.";
218 break;
219 /* case SCARD_W_WRONG_CHV: */
220 /* case SCARD_W_CHV_BLOCKED: */
221 /* case SCARD_W_EOF: */
222 /* case SCARD_W_CANCELLED_BY_USER: */
223 /* case SCARD_W_CARD_NOT_AUTHENTICATED: */
224
226 msg = "Feature not supported.";
227 break;
228 default:
229 (void)snprintf(strError, sizeof(strError)-1, "Unknown error: 0x%08lX",
230 pcscError);
231 };
232
233 if (msg)
234 (void)strncpy(strError, msg, sizeof(strError));
235 else
236 (void)snprintf(strError, sizeof(strError)-1, "Unknown error: 0x%08lX",
237 pcscError);
238
239 /* add a null byte */
240 strError[sizeof(strError)-1] = '\0';
241
242 return strError;
243}
244#endif
245
PCSC_API const char * pcsc_stringify_error(const LONG pcscError)
Returns a human readable text for the given PC/SC error code.
Definition error.c:82
#define SCARD_E_INVALID_HANDLE
The supplied handle was invalid.
Definition pcsclite.h:113
#define SCARD_F_INTERNAL_ERROR
An internal consistency check failed.
Definition pcsclite.h:109
#define SCARD_E_READER_UNSUPPORTED
The reader driver does not meet minimal requirements for support.
Definition pcsclite.h:159
#define SCARD_W_SECURITY_VIOLATION
Access was denied because of a security violation.
Definition pcsclite.h:222
#define SCARD_E_CARD_UNSUPPORTED
The smart card does not meet minimal requirements for support.
Definition pcsclite.h:163
#define SCARD_E_UNKNOWN_READER
The specified reader name is not recognized.
Definition pcsclite.h:125
#define SCARD_W_RESET_CARD
The smart card has been reset, so any shared state information is invalid.
Definition pcsclite.h:217
#define SCARD_E_SERVICE_STOPPED
The Smart card resource manager has shut down.
Definition pcsclite.h:167
#define SCARD_F_UNKNOWN_ERROR
An internal error has been detected, but the source is unknown.
Definition pcsclite.h:147
#define SCARD_W_UNRESPONSIVE_CARD
The smart card is not responding to a reset.
Definition pcsclite.h:213
#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_E_INVALID_TARGET
Registry startup information is missing or invalid.
Definition pcsclite.h:117
#define SCARD_E_PCI_TOO_SMALL
The PCI Receive buffer was too small.
Definition pcsclite.h:157
#define SCARD_E_INVALID_PARAMETER
One or more of the supplied parameters could not be properly interpreted.
Definition pcsclite.h:115
#define SCARD_E_CANCELLED
The action was cancelled by an SCardCancel request.
Definition pcsclite.h:111
#define SCARD_S_SUCCESS
No error was encountered.
Definition pcsclite.h:107
#define SCARD_E_CANT_DISPOSE
The system could not dispose of the media in the requested manner.
Definition pcsclite.h:135
#define SCARD_E_NO_MEMORY
Not enough memory available to complete this command.
Definition pcsclite.h:119
#define SCARD_E_NO_READERS_AVAILABLE
Cannot find a smart card reader.
Definition pcsclite.h:202
#define SCARD_E_SHARING_VIOLATION
The smart card cannot be accessed because of other connections outstanding.
Definition pcsclite.h:129
#define SCARD_E_DUPLICATE_READER
The reader driver did not produce a unique reader name.
Definition pcsclite.h:161
#define SCARD_F_COMM_ERROR
An internal communications error has been detected.
Definition pcsclite.h:145
#define SCARD_E_INVALID_VALUE
One or more of the supplied parameters values could not be properly interpreted.
Definition pcsclite.h:141
#define SCARD_E_TIMEOUT
The user-specified timeout value has expired.
Definition pcsclite.h:127
#define SCARD_F_WAITED_TOO_LONG
An internal consistency timer has expired.
Definition pcsclite.h:121
#define SCARD_W_REMOVED_CARD
The smart card has been removed, so further communication is not possible.
Definition pcsclite.h:219
#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_NOT_READY
The reader or smart card is not ready to accept commands.
Definition pcsclite.h:139
#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_E_NOT_TRANSACTED
An attempt was made to end a non-existent transaction.
Definition pcsclite.h:151
#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_SERVICE
The Smart card resource manager is not running.
Definition pcsclite.h:165
#define SCARD_E_READER_UNAVAILABLE
The specified reader is not currently available for use.
Definition pcsclite.h:153
#define SCARD_W_UNPOWERED_CARD
Power has been removed from the smart card, so that further communication is not possible.
Definition pcsclite.h:215
#define SCARD_W_UNSUPPORTED_CARD
The reader cannot communicate with the card, due to ATR string configuration conflicts.
Definition pcsclite.h:211
#define SCARD_E_UNKNOWN_CARD
The specified smart card name is not recognized.
Definition pcsclite.h:133
#define SCARD_E_UNSUPPORTED_FEATURE
This smart card does not support the requested feature.
Definition pcsclite.h:171
#define SCARD_E_SYSTEM_CANCELLED
The action was cancelled by the system, presumably to log off or shut down.
Definition pcsclite.h:143
This keeps a list of defines for pcsc-lite.