pcsc-lite  1.8.8
error.c
Go to the documentation of this file.
1 /*
2  * MUSCLE SmartCard Development ( http://www.linuxnet.com )
3  *
4  * Copyright (C) 1999-2002
5  * David Corcoran <corcoran@linuxnet.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  * $Id: error.c 5964 2011-09-24 09:22:24Z rousseau $
14  */
15 
21 #include <stdio.h>
22 #include <sys/types.h>
23 
24 #include "config.h"
25 #include "misc.h"
26 #include "pcsclite.h"
27 #include "strlcpycat.h"
28 
29 #ifdef NO_LOG
30 PCSC_API char* pcsc_stringify_error(const long pcscError)
31 {
32  static char strError[] = "0x12345678";
33 
34  snprintf(strError, sizeof(strError), "0x%08lX", pcscError);
35 
36  return strError;
37 }
38 #else
39 
56 PCSC_API char* pcsc_stringify_error(const LONG pcscError)
57 {
58  static char strError[75];
59 
60  switch (pcscError)
61  {
62  case SCARD_S_SUCCESS:
63  (void)strlcpy(strError, "Command successful.", sizeof(strError));
64  break;
66  (void)strlcpy(strError, "Internal error.", sizeof(strError));
67  break;
68  case SCARD_E_CANCELLED:
69  (void)strlcpy(strError, "Command cancelled.", sizeof(strError));
70  break;
72  (void)strlcpy(strError, "Invalid handle.", sizeof(strError));
73  break;
75  (void)strlcpy(strError, "Invalid parameter given.", sizeof(strError));
76  break;
78  (void)strlcpy(strError, "Invalid target given.", sizeof(strError));
79  break;
80  case SCARD_E_NO_MEMORY:
81  (void)strlcpy(strError, "Not enough memory.", sizeof(strError));
82  break;
84  (void)strlcpy(strError, "Waited too long.", sizeof(strError));
85  break;
87  (void)strlcpy(strError, "Insufficient buffer.", sizeof(strError));
88  break;
90  (void)strlcpy(strError, "Unknown reader specified.", sizeof(strError));
91  break;
92  case SCARD_E_TIMEOUT:
93  (void)strlcpy(strError, "Command timeout.", sizeof(strError));
94  break;
96  (void)strlcpy(strError, "Sharing violation.", sizeof(strError));
97  break;
99  (void)strlcpy(strError, "No smart card inserted.", sizeof(strError));
100  break;
102  (void)strlcpy(strError, "Unknown card.", sizeof(strError));
103  break;
105  (void)strlcpy(strError, "Cannot dispose handle.", sizeof(strError));
106  break;
108  (void)strlcpy(strError, "Card protocol mismatch.", sizeof(strError));
109  break;
110  case SCARD_E_NOT_READY:
111  (void)strlcpy(strError, "Subsystem not ready.", sizeof(strError));
112  break;
114  (void)strlcpy(strError, "Invalid value given.", sizeof(strError));
115  break;
117  (void)strlcpy(strError, "System cancelled.", sizeof(strError));
118  break;
119  case SCARD_F_COMM_ERROR:
120  (void)strlcpy(strError, "RPC transport error.", sizeof(strError));
121  break;
123  (void)strlcpy(strError, "Unknown error.", sizeof(strError));
124  break;
125  case SCARD_E_INVALID_ATR:
126  (void)strlcpy(strError, "Invalid ATR.", sizeof(strError));
127  break;
129  (void)strlcpy(strError, "Transaction failed.", sizeof(strError));
130  break;
132  (void)strlcpy(strError, "Reader is unavailable.", sizeof(strError));
133  break;
134  /* case SCARD_P_SHUTDOWN: */
136  (void)strlcpy(strError, "PCI struct too small.", sizeof(strError));
137  break;
139  (void)strlcpy(strError, "Reader is unsupported.", sizeof(strError));
140  break;
142  (void)strlcpy(strError, "Reader already exists.", sizeof(strError));
143  break;
145  (void)strlcpy(strError, "Card is unsupported.", sizeof(strError));
146  break;
147  case SCARD_E_NO_SERVICE:
148  (void)strlcpy(strError, "Service not available.", sizeof(strError));
149  break;
151  (void)strlcpy(strError, "Service was stopped.", sizeof(strError));
152  break;
153  /* case SCARD_E_UNEXPECTED: */
154  /* case SCARD_E_ICC_CREATEORDER: */
155  /* case SCARD_E_UNSUPPORTED_FEATURE: */
156  /* case SCARD_E_DIR_NOT_FOUND: */
157  /* case SCARD_E_NO_DIR: */
158  /* case SCARD_E_NO_FILE: */
159  /* case SCARD_E_NO_ACCESS: */
160  /* case SCARD_E_WRITE_TOO_MANY: */
161  /* case SCARD_E_BAD_SEEK: */
162  /* case SCARD_E_INVALID_CHV: */
163  /* case SCARD_E_UNKNOWN_RES_MNG: */
164  /* case SCARD_E_NO_SUCH_CERTIFICATE: */
165  /* case SCARD_E_CERTIFICATE_UNAVAILABLE: */
167  (void)strlcpy(strError, "Cannot find a smart card reader.", sizeof(strError));
168  break;
169  /* case SCARD_E_COMM_DATA_LOST: */
170  /* case SCARD_E_NO_KEY_CONTAINER: */
171  /* case SCARD_E_SERVER_TOO_BUSY: */
173  (void)strlcpy(strError, "Card is not supported.", sizeof(strError));
174  break;
176  (void)strlcpy(strError, "Card is unresponsive.", sizeof(strError));
177  break;
179  (void)strlcpy(strError, "Card is unpowered.", sizeof(strError));
180  break;
181  case SCARD_W_RESET_CARD:
182  (void)strlcpy(strError, "Card was reset.", sizeof(strError));
183  break;
185  (void)strlcpy(strError, "Card was removed.", sizeof(strError));
186  break;
187  /* case SCARD_W_SECURITY_VIOLATION: */
188  /* case SCARD_W_WRONG_CHV: */
189  /* case SCARD_W_CHV_BLOCKED: */
190  /* case SCARD_W_EOF: */
191  /* case SCARD_W_CANCELLED_BY_USER: */
192  /* case SCARD_W_CARD_NOT_AUTHENTICATED: */
193 
195  (void)strlcpy(strError, "Feature not supported.", sizeof(strError));
196  break;
197  default:
198  (void)snprintf(strError, sizeof(strError)-1, "Unknown error: 0x%08lX",
199  pcscError);
200  };
201 
202  /* add a null byte */
203  strError[sizeof(strError)-1] = '\0';
204 
205  return strError;
206 }
207 #endif
208 
#define SCARD_E_CARD_UNSUPPORTED
The smart card does not meet minimal requirements for support.
Definition: pcsclite.h:108
#define SCARD_E_CANCELLED
The action was cancelled by an SCardCancel request.
Definition: pcsclite.h:82
#define SCARD_E_READER_UNSUPPORTED
The reader driver does not meet minimal requirements for support.
Definition: pcsclite.h:106
#define SCARD_E_PROTO_MISMATCH
The requested protocols are incompatible with the protocol currently in use with the smart card...
Definition: pcsclite.h:95
#define SCARD_E_READER_UNAVAILABLE
The specified reader is not currently available for use.
Definition: pcsclite.h:103
#define SCARD_E_CANT_DISPOSE
The system could not dispose of the media in the requested manner.
Definition: pcsclite.h:94
#define SCARD_E_DUPLICATE_READER
The reader driver did not produce a unique reader name.
Definition: pcsclite.h:107
PCSC_API char * pcsc_stringify_error(const LONG pcscError)
Returns a human readable text for the given PC/SC error code.
Definition: error.c:56
#define SCARD_F_COMM_ERROR
An internal communications error has been detected.
Definition: pcsclite.h:99
#define SCARD_E_INVALID_PARAMETER
One or more of the supplied parameters could not be properly interpreted.
Definition: pcsclite.h:84
#define SCARD_E_NOT_TRANSACTED
An attempt was made to end a non-existent transaction.
Definition: pcsclite.h:102
#define SCARD_E_NO_SERVICE
The Smart card resource manager is not running.
Definition: pcsclite.h:109
#define SCARD_E_SERVICE_STOPPED
The Smart card resource manager has shut down.
Definition: pcsclite.h:110
#define SCARD_E_NO_READERS_AVAILABLE
Cannot find a smart card reader.
Definition: pcsclite.h:127
#define SCARD_E_UNKNOWN_CARD
The specified smart card name is not recognized.
Definition: pcsclite.h:93
#define SCARD_F_WAITED_TOO_LONG
An internal consistency timer has expired.
Definition: pcsclite.h:87
#define SCARD_F_UNKNOWN_ERROR
An internal error has been detected, but the source is unknown.
Definition: pcsclite.h:100
#define SCARD_E_INVALID_HANDLE
The supplied handle was invalid.
Definition: pcsclite.h:83
#define SCARD_W_UNRESPONSIVE_CARD
The smart card is not responding to a reset.
Definition: pcsclite.h:133
#define SCARD_E_INVALID_VALUE
One or more of the supplied parameters values could not be properly interpreted.
Definition: pcsclite.h:97
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:132
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:136
#define SCARD_E_UNSUPPORTED_FEATURE
This smart card does not support the requested feature.
Definition: pcsclite.h:112
#define SCARD_W_RESET_CARD
The smart card has been reset, so any shared state information is invalid.
Definition: pcsclite.h:135
#define SCARD_E_SHARING_VIOLATION
The smart card cannot be accessed because of other connections outstanding.
Definition: pcsclite.h:91
#define SCARD_W_UNPOWERED_CARD
Power has been removed from the smart card, so that further communication is not possible.
Definition: pcsclite.h:134
#define SCARD_E_SYSTEM_CANCELLED
The action was cancelled by the system, presumably to log off or shut down.
Definition: pcsclite.h:98
#define SCARD_E_NO_SMARTCARD
The operation requires a Smart Card, but no Smart Card is currently in the device.
Definition: pcsclite.h:92
#define SCARD_E_NO_MEMORY
Not enough memory available to complete this command.
Definition: pcsclite.h:86
#define SCARD_E_INSUFFICIENT_BUFFER
The data buffer to receive returned data is too small for the returned data.
Definition: pcsclite.h:88
#define SCARD_E_INVALID_TARGET
Registry startup information is missing or invalid.
Definition: pcsclite.h:85
#define SCARD_E_PCI_TOO_SMALL
The PCI Receive buffer was too small.
Definition: pcsclite.h:105
#define SCARD_E_INVALID_ATR
An ATR obtained from the registry is not a valid ATR string.
Definition: pcsclite.h:101
#define SCARD_E_UNKNOWN_READER
The specified reader name is not recognized.
Definition: pcsclite.h:89
#define SCARD_E_NOT_READY
The reader or smart card is not ready to accept commands.
Definition: pcsclite.h:96
#define SCARD_S_SUCCESS
error codes from http://msdn.microsoft.com/en-us/library/aa924526.aspx
Definition: pcsclite.h:80
#define SCARD_E_TIMEOUT
The user-specified timeout value has expired.
Definition: pcsclite.h:90
#define SCARD_F_INTERNAL_ERROR
An internal consistency check failed.
Definition: pcsclite.h:81