pcsc-lite  1.8.11
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 Changes to this license can be made only by the copyright author with
26 explicit written consent.
27 
28 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
29 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
30 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
31 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
32 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
33 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
37 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  *
39  * $Id: error.c 6851 2014-02-14 15:43:32Z rousseau $
40  */
41 
47 #include <stdio.h>
48 #include <sys/types.h>
49 
50 #include "config.h"
51 #include "misc.h"
52 #include "pcsclite.h"
53 #include "strlcpycat.h"
54 
55 #ifdef NO_LOG
56 PCSC_API char* pcsc_stringify_error(const long pcscError)
57 {
58  static char strError[] = "0x12345678";
59 
60  snprintf(strError, sizeof(strError), "0x%08lX", pcscError);
61 
62  return strError;
63 }
64 #else
65 
82 PCSC_API char* pcsc_stringify_error(const LONG pcscError)
83 {
84  static char strError[75];
85 
86  switch (pcscError)
87  {
88  case SCARD_S_SUCCESS:
89  (void)strlcpy(strError, "Command successful.", sizeof(strError));
90  break;
92  (void)strlcpy(strError, "Internal error.", sizeof(strError));
93  break;
94  case SCARD_E_CANCELLED:
95  (void)strlcpy(strError, "Command cancelled.", sizeof(strError));
96  break;
98  (void)strlcpy(strError, "Invalid handle.", sizeof(strError));
99  break;
101  (void)strlcpy(strError, "Invalid parameter given.", sizeof(strError));
102  break;
104  (void)strlcpy(strError, "Invalid target given.", sizeof(strError));
105  break;
106  case SCARD_E_NO_MEMORY:
107  (void)strlcpy(strError, "Not enough memory.", sizeof(strError));
108  break;
110  (void)strlcpy(strError, "Waited too long.", sizeof(strError));
111  break;
113  (void)strlcpy(strError, "Insufficient buffer.", sizeof(strError));
114  break;
116  (void)strlcpy(strError, "Unknown reader specified.", sizeof(strError));
117  break;
118  case SCARD_E_TIMEOUT:
119  (void)strlcpy(strError, "Command timeout.", sizeof(strError));
120  break;
122  (void)strlcpy(strError, "Sharing violation.", sizeof(strError));
123  break;
125  (void)strlcpy(strError, "No smart card inserted.", sizeof(strError));
126  break;
128  (void)strlcpy(strError, "Unknown card.", sizeof(strError));
129  break;
131  (void)strlcpy(strError, "Cannot dispose handle.", sizeof(strError));
132  break;
134  (void)strlcpy(strError, "Card protocol mismatch.", sizeof(strError));
135  break;
136  case SCARD_E_NOT_READY:
137  (void)strlcpy(strError, "Subsystem not ready.", sizeof(strError));
138  break;
140  (void)strlcpy(strError, "Invalid value given.", sizeof(strError));
141  break;
143  (void)strlcpy(strError, "System cancelled.", sizeof(strError));
144  break;
145  case SCARD_F_COMM_ERROR:
146  (void)strlcpy(strError, "RPC transport error.", sizeof(strError));
147  break;
149  (void)strlcpy(strError, "Unknown error.", sizeof(strError));
150  break;
151  case SCARD_E_INVALID_ATR:
152  (void)strlcpy(strError, "Invalid ATR.", sizeof(strError));
153  break;
155  (void)strlcpy(strError, "Transaction failed.", sizeof(strError));
156  break;
158  (void)strlcpy(strError, "Reader is unavailable.", sizeof(strError));
159  break;
160  /* case SCARD_P_SHUTDOWN: */
162  (void)strlcpy(strError, "PCI struct too small.", sizeof(strError));
163  break;
165  (void)strlcpy(strError, "Reader is unsupported.", sizeof(strError));
166  break;
168  (void)strlcpy(strError, "Reader already exists.", sizeof(strError));
169  break;
171  (void)strlcpy(strError, "Card is unsupported.", sizeof(strError));
172  break;
173  case SCARD_E_NO_SERVICE:
174  (void)strlcpy(strError, "Service not available.", sizeof(strError));
175  break;
177  (void)strlcpy(strError, "Service was stopped.", sizeof(strError));
178  break;
179  /* case SCARD_E_UNEXPECTED: */
180  /* case SCARD_E_ICC_CREATEORDER: */
181  /* case SCARD_E_UNSUPPORTED_FEATURE: */
182  /* case SCARD_E_DIR_NOT_FOUND: */
183  /* case SCARD_E_NO_DIR: */
184  /* case SCARD_E_NO_FILE: */
185  /* case SCARD_E_NO_ACCESS: */
186  /* case SCARD_E_WRITE_TOO_MANY: */
187  /* case SCARD_E_BAD_SEEK: */
188  /* case SCARD_E_INVALID_CHV: */
189  /* case SCARD_E_UNKNOWN_RES_MNG: */
190  /* case SCARD_E_NO_SUCH_CERTIFICATE: */
191  /* case SCARD_E_CERTIFICATE_UNAVAILABLE: */
193  (void)strlcpy(strError, "Cannot find a smart card reader.", sizeof(strError));
194  break;
195  /* case SCARD_E_COMM_DATA_LOST: */
196  /* case SCARD_E_NO_KEY_CONTAINER: */
197  /* case SCARD_E_SERVER_TOO_BUSY: */
199  (void)strlcpy(strError, "Card is not supported.", sizeof(strError));
200  break;
202  (void)strlcpy(strError, "Card is unresponsive.", sizeof(strError));
203  break;
205  (void)strlcpy(strError, "Card is unpowered.", sizeof(strError));
206  break;
207  case SCARD_W_RESET_CARD:
208  (void)strlcpy(strError, "Card was reset.", sizeof(strError));
209  break;
211  (void)strlcpy(strError, "Card was removed.", sizeof(strError));
212  break;
213  /* case SCARD_W_SECURITY_VIOLATION: */
214  /* case SCARD_W_WRONG_CHV: */
215  /* case SCARD_W_CHV_BLOCKED: */
216  /* case SCARD_W_EOF: */
217  /* case SCARD_W_CANCELLED_BY_USER: */
218  /* case SCARD_W_CARD_NOT_AUTHENTICATED: */
219 
221  (void)strlcpy(strError, "Feature not supported.", sizeof(strError));
222  break;
223  default:
224  (void)snprintf(strError, sizeof(strError)-1, "Unknown error: 0x%08lX",
225  pcscError);
226  };
227 
228  /* add a null byte */
229  strError[sizeof(strError)-1] = '\0';
230 
231  return strError;
232 }
233 #endif
234 
#define SCARD_E_CARD_UNSUPPORTED
The smart card does not meet minimal requirements for support.
Definition: pcsclite.h:134
#define SCARD_E_CANCELLED
The action was cancelled by an SCardCancel request.
Definition: pcsclite.h:108
#define SCARD_E_READER_UNSUPPORTED
The reader driver does not meet minimal requirements for support.
Definition: pcsclite.h:132
#define SCARD_E_PROTO_MISMATCH
The requested protocols are incompatible with the protocol currently in use with the smart card...
Definition: pcsclite.h:121
#define SCARD_E_READER_UNAVAILABLE
The specified reader is not currently available for use.
Definition: pcsclite.h:129
#define SCARD_E_CANT_DISPOSE
The system could not dispose of the media in the requested manner.
Definition: pcsclite.h:120
#define SCARD_E_DUPLICATE_READER
The reader driver did not produce a unique reader name.
Definition: pcsclite.h:133
PCSC_API 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_F_COMM_ERROR
An internal communications error has been detected.
Definition: pcsclite.h:125
#define SCARD_E_INVALID_PARAMETER
One or more of the supplied parameters could not be properly interpreted.
Definition: pcsclite.h:110
#define SCARD_E_NOT_TRANSACTED
An attempt was made to end a non-existent transaction.
Definition: pcsclite.h:128
#define SCARD_E_NO_SERVICE
The Smart card resource manager is not running.
Definition: pcsclite.h:135
#define SCARD_E_SERVICE_STOPPED
The Smart card resource manager has shut down.
Definition: pcsclite.h:136
#define SCARD_E_NO_READERS_AVAILABLE
Cannot find a smart card reader.
Definition: pcsclite.h:153
#define SCARD_E_UNKNOWN_CARD
The specified smart card name is not recognized.
Definition: pcsclite.h:119
#define SCARD_F_WAITED_TOO_LONG
An internal consistency timer has expired.
Definition: pcsclite.h:113
#define SCARD_F_UNKNOWN_ERROR
An internal error has been detected, but the source is unknown.
Definition: pcsclite.h:126
#define SCARD_E_INVALID_HANDLE
The supplied handle was invalid.
Definition: pcsclite.h:109
#define SCARD_W_UNRESPONSIVE_CARD
The smart card is not responding to a reset.
Definition: pcsclite.h:159
#define SCARD_E_INVALID_VALUE
One or more of the supplied parameters values could not be properly interpreted.
Definition: pcsclite.h:123
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:158
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:162
#define SCARD_E_UNSUPPORTED_FEATURE
This smart card does not support the requested feature.
Definition: pcsclite.h:138
#define SCARD_W_RESET_CARD
The smart card has been reset, so any shared state information is invalid.
Definition: pcsclite.h:161
#define SCARD_E_SHARING_VIOLATION
The smart card cannot be accessed because of other connections outstanding.
Definition: pcsclite.h:117
#define SCARD_W_UNPOWERED_CARD
Power has been removed from the smart card, so that further communication is not possible.
Definition: pcsclite.h:160
#define SCARD_E_SYSTEM_CANCELLED
The action was cancelled by the system, presumably to log off or shut down.
Definition: pcsclite.h:124
#define SCARD_E_NO_SMARTCARD
The operation requires a Smart Card, but no Smart Card is currently in the device.
Definition: pcsclite.h:118
#define SCARD_E_NO_MEMORY
Not enough memory available to complete this command.
Definition: pcsclite.h:112
#define SCARD_E_INSUFFICIENT_BUFFER
The data buffer to receive returned data is too small for the returned data.
Definition: pcsclite.h:114
#define SCARD_E_INVALID_TARGET
Registry startup information is missing or invalid.
Definition: pcsclite.h:111
#define SCARD_E_PCI_TOO_SMALL
The PCI Receive buffer was too small.
Definition: pcsclite.h:131
#define SCARD_E_INVALID_ATR
An ATR obtained from the registry is not a valid ATR string.
Definition: pcsclite.h:127
#define SCARD_E_UNKNOWN_READER
The specified reader name is not recognized.
Definition: pcsclite.h:115
#define SCARD_E_NOT_READY
The reader or smart card is not ready to accept commands.
Definition: pcsclite.h:122
#define SCARD_S_SUCCESS
error codes from http://msdn.microsoft.com/en-us/library/aa924526.aspx
Definition: pcsclite.h:106
#define SCARD_E_TIMEOUT
The user-specified timeout value has expired.
Definition: pcsclite.h:116
#define SCARD_F_INTERNAL_ERROR
An internal consistency check failed.
Definition: pcsclite.h:107