pcsc-lite  1.8.13
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  * $Id: error.c 7004 2014-10-02 09:26:36Z rousseau $
37  */
38 
44 #include <stdio.h>
45 #include <sys/types.h>
46 
47 #include "config.h"
48 #include "misc.h"
49 #include "pcsclite.h"
50 #include "strlcpycat.h"
51 
52 #ifdef NO_LOG
53 PCSC_API char* pcsc_stringify_error(const long pcscError)
54 {
55  static char strError[] = "0x12345678";
56 
57  snprintf(strError, sizeof(strError), "0x%08lX", pcscError);
58 
59  return strError;
60 }
61 #else
62 
79 PCSC_API char* pcsc_stringify_error(const LONG pcscError)
80 {
81  static char strError[75];
82 
83  switch (pcscError)
84  {
85  case SCARD_S_SUCCESS:
86  (void)strlcpy(strError, "Command successful.", sizeof(strError));
87  break;
89  (void)strlcpy(strError, "Internal error.", sizeof(strError));
90  break;
91  case SCARD_E_CANCELLED:
92  (void)strlcpy(strError, "Command cancelled.", sizeof(strError));
93  break;
95  (void)strlcpy(strError, "Invalid handle.", sizeof(strError));
96  break;
98  (void)strlcpy(strError, "Invalid parameter given.", sizeof(strError));
99  break;
101  (void)strlcpy(strError, "Invalid target given.", sizeof(strError));
102  break;
103  case SCARD_E_NO_MEMORY:
104  (void)strlcpy(strError, "Not enough memory.", sizeof(strError));
105  break;
107  (void)strlcpy(strError, "Waited too long.", sizeof(strError));
108  break;
110  (void)strlcpy(strError, "Insufficient buffer.", sizeof(strError));
111  break;
113  (void)strlcpy(strError, "Unknown reader specified.", sizeof(strError));
114  break;
115  case SCARD_E_TIMEOUT:
116  (void)strlcpy(strError, "Command timeout.", sizeof(strError));
117  break;
119  (void)strlcpy(strError, "Sharing violation.", sizeof(strError));
120  break;
122  (void)strlcpy(strError, "No smart card inserted.", sizeof(strError));
123  break;
125  (void)strlcpy(strError, "Unknown card.", sizeof(strError));
126  break;
128  (void)strlcpy(strError, "Cannot dispose handle.", sizeof(strError));
129  break;
131  (void)strlcpy(strError, "Card protocol mismatch.", sizeof(strError));
132  break;
133  case SCARD_E_NOT_READY:
134  (void)strlcpy(strError, "Subsystem not ready.", sizeof(strError));
135  break;
137  (void)strlcpy(strError, "Invalid value given.", sizeof(strError));
138  break;
140  (void)strlcpy(strError, "System cancelled.", sizeof(strError));
141  break;
142  case SCARD_F_COMM_ERROR:
143  (void)strlcpy(strError, "RPC transport error.", sizeof(strError));
144  break;
146  (void)strlcpy(strError, "Unknown error.", sizeof(strError));
147  break;
148  case SCARD_E_INVALID_ATR:
149  (void)strlcpy(strError, "Invalid ATR.", sizeof(strError));
150  break;
152  (void)strlcpy(strError, "Transaction failed.", sizeof(strError));
153  break;
155  (void)strlcpy(strError, "Reader is unavailable.", sizeof(strError));
156  break;
157  /* case SCARD_P_SHUTDOWN: */
159  (void)strlcpy(strError, "PCI struct too small.", sizeof(strError));
160  break;
162  (void)strlcpy(strError, "Reader is unsupported.", sizeof(strError));
163  break;
165  (void)strlcpy(strError, "Reader already exists.", sizeof(strError));
166  break;
168  (void)strlcpy(strError, "Card is unsupported.", sizeof(strError));
169  break;
170  case SCARD_E_NO_SERVICE:
171  (void)strlcpy(strError, "Service not available.", sizeof(strError));
172  break;
174  (void)strlcpy(strError, "Service was stopped.", sizeof(strError));
175  break;
176  /* case SCARD_E_UNEXPECTED: */
177  /* case SCARD_E_ICC_CREATEORDER: */
178  /* case SCARD_E_UNSUPPORTED_FEATURE: */
179  /* case SCARD_E_DIR_NOT_FOUND: */
180  /* case SCARD_E_NO_DIR: */
181  /* case SCARD_E_NO_FILE: */
182  /* case SCARD_E_NO_ACCESS: */
183  /* case SCARD_E_WRITE_TOO_MANY: */
184  /* case SCARD_E_BAD_SEEK: */
185  /* case SCARD_E_INVALID_CHV: */
186  /* case SCARD_E_UNKNOWN_RES_MNG: */
187  /* case SCARD_E_NO_SUCH_CERTIFICATE: */
188  /* case SCARD_E_CERTIFICATE_UNAVAILABLE: */
190  (void)strlcpy(strError, "Cannot find a smart card reader.", sizeof(strError));
191  break;
192  /* case SCARD_E_COMM_DATA_LOST: */
193  /* case SCARD_E_NO_KEY_CONTAINER: */
194  /* case SCARD_E_SERVER_TOO_BUSY: */
196  (void)strlcpy(strError, "Card is not supported.", sizeof(strError));
197  break;
199  (void)strlcpy(strError, "Card is unresponsive.", sizeof(strError));
200  break;
202  (void)strlcpy(strError, "Card is unpowered.", sizeof(strError));
203  break;
204  case SCARD_W_RESET_CARD:
205  (void)strlcpy(strError, "Card was reset.", sizeof(strError));
206  break;
208  (void)strlcpy(strError, "Card was removed.", sizeof(strError));
209  break;
210  /* case SCARD_W_SECURITY_VIOLATION: */
211  /* case SCARD_W_WRONG_CHV: */
212  /* case SCARD_W_CHV_BLOCKED: */
213  /* case SCARD_W_EOF: */
214  /* case SCARD_W_CANCELLED_BY_USER: */
215  /* case SCARD_W_CARD_NOT_AUTHENTICATED: */
216 
218  (void)strlcpy(strError, "Feature not supported.", sizeof(strError));
219  break;
220  default:
221  (void)snprintf(strError, sizeof(strError)-1, "Unknown error: 0x%08lX",
222  pcscError);
223  };
224 
225  /* add a null byte */
226  strError[sizeof(strError)-1] = '\0';
227 
228  return strError;
229 }
230 #endif
231 
#define SCARD_E_CARD_UNSUPPORTED
The smart card does not meet minimal requirements for support.
Definition: pcsclite.h:131
#define SCARD_E_CANCELLED
The action was cancelled by an SCardCancel request.
Definition: pcsclite.h:105
#define SCARD_E_READER_UNSUPPORTED
The reader driver does not meet minimal requirements for support.
Definition: pcsclite.h:129
#define SCARD_E_PROTO_MISMATCH
The requested protocols are incompatible with the protocol currently in use with the smart card...
Definition: pcsclite.h:118
#define SCARD_E_READER_UNAVAILABLE
The specified reader is not currently available for use.
Definition: pcsclite.h:126
#define SCARD_E_CANT_DISPOSE
The system could not dispose of the media in the requested manner.
Definition: pcsclite.h:117
#define SCARD_E_DUPLICATE_READER
The reader driver did not produce a unique reader name.
Definition: pcsclite.h:130
PCSC_API char * pcsc_stringify_error(const LONG pcscError)
Returns a human readable text for the given PC/SC error code.
Definition: error.c:79
#define SCARD_F_COMM_ERROR
An internal communications error has been detected.
Definition: pcsclite.h:122
#define SCARD_E_INVALID_PARAMETER
One or more of the supplied parameters could not be properly interpreted.
Definition: pcsclite.h:107
#define SCARD_E_NOT_TRANSACTED
An attempt was made to end a non-existent transaction.
Definition: pcsclite.h:125
#define SCARD_E_NO_SERVICE
The Smart card resource manager is not running.
Definition: pcsclite.h:132
#define SCARD_E_SERVICE_STOPPED
The Smart card resource manager has shut down.
Definition: pcsclite.h:133
#define SCARD_E_NO_READERS_AVAILABLE
Cannot find a smart card reader.
Definition: pcsclite.h:150
#define SCARD_E_UNKNOWN_CARD
The specified smart card name is not recognized.
Definition: pcsclite.h:116
#define SCARD_F_WAITED_TOO_LONG
An internal consistency timer has expired.
Definition: pcsclite.h:110
#define SCARD_F_UNKNOWN_ERROR
An internal error has been detected, but the source is unknown.
Definition: pcsclite.h:123
#define SCARD_E_INVALID_HANDLE
The supplied handle was invalid.
Definition: pcsclite.h:106
#define SCARD_W_UNRESPONSIVE_CARD
The smart card is not responding to a reset.
Definition: pcsclite.h:156
#define SCARD_E_INVALID_VALUE
One or more of the supplied parameters values could not be properly interpreted.
Definition: pcsclite.h:120
prototypes of strlcpy()/strlcat() imported from OpenBSD
#define SCARD_W_UNSUPPORTED_CARD
The reader cannot communicate with the card, due to ATR string configuration conflicts.
Definition: pcsclite.h:155
This keeps a list of defines for pcsc-lite.
#define SCARD_W_REMOVED_CARD
The smart card has been removed, so further communication is not possible.
Definition: pcsclite.h:159
#define SCARD_E_UNSUPPORTED_FEATURE
This smart card does not support the requested feature.
Definition: pcsclite.h:135
#define SCARD_W_RESET_CARD
The smart card has been reset, so any shared state information is invalid.
Definition: pcsclite.h:158
#define SCARD_E_SHARING_VIOLATION
The smart card cannot be accessed because of other connections outstanding.
Definition: pcsclite.h:114
#define SCARD_W_UNPOWERED_CARD
Power has been removed from the smart card, so that further communication is not possible.
Definition: pcsclite.h:157
#define SCARD_E_SYSTEM_CANCELLED
The action was cancelled by the system, presumably to log off or shut down.
Definition: pcsclite.h:121
#define SCARD_E_NO_SMARTCARD
The operation requires a Smart Card, but no Smart Card is currently in the device.
Definition: pcsclite.h:115
#define SCARD_E_NO_MEMORY
Not enough memory available to complete this command.
Definition: pcsclite.h:109
#define SCARD_E_INSUFFICIENT_BUFFER
The data buffer to receive returned data is too small for the returned data.
Definition: pcsclite.h:111
#define SCARD_E_INVALID_TARGET
Registry startup information is missing or invalid.
Definition: pcsclite.h:108
#define SCARD_E_PCI_TOO_SMALL
The PCI Receive buffer was too small.
Definition: pcsclite.h:128
#define SCARD_E_INVALID_ATR
An ATR obtained from the registry is not a valid ATR string.
Definition: pcsclite.h:124
#define SCARD_E_UNKNOWN_READER
The specified reader name is not recognized.
Definition: pcsclite.h:112
#define SCARD_E_NOT_READY
The reader or smart card is not ready to accept commands.
Definition: pcsclite.h:119
#define SCARD_S_SUCCESS
error codes from http://msdn.microsoft.com/en-us/library/aa924526.aspx
Definition: pcsclite.h:103
#define SCARD_E_TIMEOUT
The user-specified timeout value has expired.
Definition: pcsclite.h:113
#define SCARD_F_INTERNAL_ERROR
An internal consistency check failed.
Definition: pcsclite.h:104