pcsc-lite  1.8.14
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$
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 "string.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  const char *msg = NULL;
83 
84  switch (pcscError)
85  {
86  case SCARD_S_SUCCESS:
87  msg = "Command successful.";
88  break;
90  msg = "Internal error.";
91  break;
92  case SCARD_E_CANCELLED:
93  msg = "Command cancelled.";
94  break;
96  msg = "Invalid handle.";
97  break;
99  msg = "Invalid parameter given.";
100  break;
102  msg = "Invalid target given.";
103  break;
104  case SCARD_E_NO_MEMORY:
105  msg = "Not enough memory.";
106  break;
108  msg = "Waited too long.";
109  break;
111  msg = "Insufficient buffer.";
112  break;
114  msg = "Unknown reader specified.";
115  break;
116  case SCARD_E_TIMEOUT:
117  msg = "Command timeout.";
118  break;
120  msg = "Sharing violation.";
121  break;
123  msg = "No smart card inserted.";
124  break;
126  msg = "Unknown card.";
127  break;
129  msg = "Cannot dispose handle.";
130  break;
132  msg = "Card protocol mismatch.";
133  break;
134  case SCARD_E_NOT_READY:
135  msg = "Subsystem not ready.";
136  break;
138  msg = "Invalid value given.";
139  break;
141  msg = "System cancelled.";
142  break;
143  case SCARD_F_COMM_ERROR:
144  msg = "RPC transport error.";
145  break;
147  msg = "Unknown error.";
148  break;
149  case SCARD_E_INVALID_ATR:
150  msg = "Invalid ATR.";
151  break;
153  msg = "Transaction failed.";
154  break;
156  msg = "Reader is unavailable.";
157  break;
158  /* case SCARD_P_SHUTDOWN: */
160  msg = "PCI struct too small.";
161  break;
163  msg = "Reader is unsupported.";
164  break;
166  msg = "Reader already exists.";
167  break;
169  msg = "Card is unsupported.";
170  break;
171  case SCARD_E_NO_SERVICE:
172  msg = "Service not available.";
173  break;
175  msg = "Service was stopped.";
176  break;
177  /* case SCARD_E_UNEXPECTED: */
178  /* case SCARD_E_ICC_CREATEORDER: */
179  /* case SCARD_E_UNSUPPORTED_FEATURE: */
180  /* case SCARD_E_DIR_NOT_FOUND: */
181  /* case SCARD_E_NO_DIR: */
182  /* case SCARD_E_NO_FILE: */
183  /* case SCARD_E_NO_ACCESS: */
184  /* case SCARD_E_WRITE_TOO_MANY: */
185  /* case SCARD_E_BAD_SEEK: */
186  /* case SCARD_E_INVALID_CHV: */
187  /* case SCARD_E_UNKNOWN_RES_MNG: */
188  /* case SCARD_E_NO_SUCH_CERTIFICATE: */
189  /* case SCARD_E_CERTIFICATE_UNAVAILABLE: */
191  msg = "Cannot find a smart card reader.";
192  break;
193  /* case SCARD_E_COMM_DATA_LOST: */
194  /* case SCARD_E_NO_KEY_CONTAINER: */
195  /* case SCARD_E_SERVER_TOO_BUSY: */
197  msg = "Card is not supported.";
198  break;
200  msg = "Card is unresponsive.";
201  break;
203  msg = "Card is unpowered.";
204  break;
205  case SCARD_W_RESET_CARD:
206  msg = "Card was reset.";
207  break;
209  msg = "Card was removed.";
210  break;
211  /* case SCARD_W_SECURITY_VIOLATION: */
212  /* case SCARD_W_WRONG_CHV: */
213  /* case SCARD_W_CHV_BLOCKED: */
214  /* case SCARD_W_EOF: */
215  /* case SCARD_W_CANCELLED_BY_USER: */
216  /* case SCARD_W_CARD_NOT_AUTHENTICATED: */
217 
219  msg = "Feature not supported.";
220  break;
221  default:
222  (void)snprintf(strError, sizeof(strError)-1, "Unknown error: 0x%08lX",
223  pcscError);
224  };
225 
226  if (msg)
227  (void)strncpy(strError, msg, sizeof(strError));
228  else
229  (void)snprintf(strError, sizeof(strError)-1, "Unknown error: 0x%08lX",
230  pcscError);
231 
232  /* add a null byte */
233  strError[sizeof(strError)-1] = '\0';
234 
235  return strError;
236 }
237 #endif
238 
#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
#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