00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00021 #include <stdio.h>
00022 #include <sys/types.h>
00023
00024 #include "config.h"
00025 #include "misc.h"
00026 #include "pcsclite.h"
00027 #include "strlcpycat.h"
00028
00029 #ifdef NO_LOG
00030 PCSC_API char* pcsc_stringify_error(const long pcscError)
00031 {
00032 static char strError[] = "0x12345678";
00033
00034 snprintf(strError, sizeof(strError), "0x%08lX", pcscError);
00035
00036 return strError;
00037 }
00038 #else
00039
00057 PCSC_API char* pcsc_stringify_error(const long pcscError)
00058 {
00059 static char strError[75];
00060
00061 switch (pcscError)
00062 {
00063 case SCARD_S_SUCCESS:
00064 (void)strlcpy(strError, "Command successful.", sizeof(strError));
00065 break;
00066 case SCARD_F_INTERNAL_ERROR:
00067 (void)strlcpy(strError, "Internal error.", sizeof(strError));
00068 break;
00069 case SCARD_E_CANCELLED:
00070 (void)strlcpy(strError, "Command cancelled.", sizeof(strError));
00071 break;
00072 case SCARD_E_INVALID_HANDLE:
00073 (void)strlcpy(strError, "Invalid handle.", sizeof(strError));
00074 break;
00075 case SCARD_E_INVALID_PARAMETER:
00076 (void)strlcpy(strError, "Invalid parameter given.", sizeof(strError));
00077 break;
00078 case SCARD_E_INVALID_TARGET:
00079 (void)strlcpy(strError, "Invalid target given.", sizeof(strError));
00080 break;
00081 case SCARD_E_NO_MEMORY:
00082 (void)strlcpy(strError, "Not enough memory.", sizeof(strError));
00083 break;
00084 case SCARD_F_WAITED_TOO_LONG:
00085 (void)strlcpy(strError, "Waited too long.", sizeof(strError));
00086 break;
00087 case SCARD_E_INSUFFICIENT_BUFFER:
00088 (void)strlcpy(strError, "Insufficient buffer.", sizeof(strError));
00089 break;
00090 case SCARD_E_UNKNOWN_READER:
00091 (void)strlcpy(strError, "Unknown reader specified.", sizeof(strError));
00092 break;
00093 case SCARD_E_TIMEOUT:
00094 (void)strlcpy(strError, "Command timeout.", sizeof(strError));
00095 break;
00096 case SCARD_E_SHARING_VIOLATION:
00097 (void)strlcpy(strError, "Sharing violation.", sizeof(strError));
00098 break;
00099 case SCARD_E_NO_SMARTCARD:
00100 (void)strlcpy(strError, "No smart card inserted.", sizeof(strError));
00101 break;
00102 case SCARD_E_UNKNOWN_CARD:
00103 (void)strlcpy(strError, "Unknown card.", sizeof(strError));
00104 break;
00105 case SCARD_E_CANT_DISPOSE:
00106 (void)strlcpy(strError, "Cannot dispose handle.", sizeof(strError));
00107 break;
00108 case SCARD_E_PROTO_MISMATCH:
00109 (void)strlcpy(strError, "Card protocol mismatch.", sizeof(strError));
00110 break;
00111 case SCARD_E_NOT_READY:
00112 (void)strlcpy(strError, "Subsystem not ready.", sizeof(strError));
00113 break;
00114 case SCARD_E_INVALID_VALUE:
00115 (void)strlcpy(strError, "Invalid value given.", sizeof(strError));
00116 break;
00117 case SCARD_E_SYSTEM_CANCELLED:
00118 (void)strlcpy(strError, "System cancelled.", sizeof(strError));
00119 break;
00120 case SCARD_F_COMM_ERROR:
00121 (void)strlcpy(strError, "RPC transport error.", sizeof(strError));
00122 break;
00123 case SCARD_F_UNKNOWN_ERROR:
00124 (void)strlcpy(strError, "Unknown error.", sizeof(strError));
00125 break;
00126 case SCARD_E_INVALID_ATR:
00127 (void)strlcpy(strError, "Invalid ATR.", sizeof(strError));
00128 break;
00129 case SCARD_E_NOT_TRANSACTED:
00130 (void)strlcpy(strError, "Transaction failed.", sizeof(strError));
00131 break;
00132 case SCARD_E_READER_UNAVAILABLE:
00133 (void)strlcpy(strError, "Reader is unavailable.", sizeof(strError));
00134 break;
00135
00136 case SCARD_E_PCI_TOO_SMALL:
00137 (void)strlcpy(strError, "PCI struct too small.", sizeof(strError));
00138 break;
00139 case SCARD_E_READER_UNSUPPORTED:
00140 (void)strlcpy(strError, "Reader is unsupported.", sizeof(strError));
00141 break;
00142 case SCARD_E_DUPLICATE_READER:
00143 (void)strlcpy(strError, "Reader already exists.", sizeof(strError));
00144 break;
00145 case SCARD_E_CARD_UNSUPPORTED:
00146 (void)strlcpy(strError, "Card is unsupported.", sizeof(strError));
00147 break;
00148 case SCARD_E_NO_SERVICE:
00149 (void)strlcpy(strError, "Service not available.", sizeof(strError));
00150 break;
00151 case SCARD_E_SERVICE_STOPPED:
00152 (void)strlcpy(strError, "Service was stopped.", sizeof(strError));
00153 break;
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 case SCARD_E_NO_READERS_AVAILABLE:
00168 (void)strlcpy(strError, "Cannot find a smart card reader.", sizeof(strError));
00169 break;
00170
00171
00172
00173 case SCARD_W_UNSUPPORTED_CARD:
00174 (void)strlcpy(strError, "Card is not supported.", sizeof(strError));
00175 break;
00176 case SCARD_W_UNRESPONSIVE_CARD:
00177 (void)strlcpy(strError, "Card is unresponsive.", sizeof(strError));
00178 break;
00179 case SCARD_W_UNPOWERED_CARD:
00180 (void)strlcpy(strError, "Card is unpowered.", sizeof(strError));
00181 break;
00182 case SCARD_W_RESET_CARD:
00183 (void)strlcpy(strError, "Card was reset.", sizeof(strError));
00184 break;
00185 case SCARD_W_REMOVED_CARD:
00186 (void)strlcpy(strError, "Card was removed.", sizeof(strError));
00187 break;
00188
00189
00190
00191
00192
00193
00194
00195 case SCARD_E_UNSUPPORTED_FEATURE:
00196 (void)strlcpy(strError, "Feature not supported.", sizeof(strError));
00197 break;
00198 default:
00199 (void)snprintf(strError, sizeof(strError)-1, "Unknown error: 0x%08lX",
00200 pcscError);
00201 };
00202
00203
00204 strError[sizeof(strError)-1] = '\0';
00205
00206 return strError;
00207 }
00208 #endif
00209