win: even more error details when unknown

master
Marc Wäckerlin 16 years ago
parent f6a72ef0fa
commit d1c5ed8dd8
  1. 304
      src/pcsc.hxx

@ -219,7 +219,21 @@ namespace pcsc {
//! @c false if last operation was not successful //! @c false if last operation was not successful
operator bool() const { operator bool() const {
return _state==SCARD_S_SUCCESS; // Values are 32 bit values layed out as follows:
// 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
// ---+-+-+-----------------------+-------------------------------
// Sev|C|R| Facility | Code
// ---+-+-+-----------------------+-------------------------------
// where Sev - is the severity code
// 00 - Success
// 01 - Informational
// 10 - Warning
// 11 - Error
// So everything with Sev=00 is successful
// theoretically even with Sev=01, but that's still rejected
return (_state>>30&3)==0;
//RETURN _STATE==SCARD_S_SUCCESS;
} }
//...........................................................variables //...........................................................variables
@ -381,7 +395,8 @@ namespace pcsc {
//! @c false if last operation was not successful //! @c false if last operation was not successful
operator bool() const { operator bool() const {
return _state==SCARD_S_SUCCESS; return (_state>>30&3)==0;
//return _state==SCARD_S_SUCCESS;
} }
//! Get the describing text of the last error //! Get the describing text of the last error
@ -389,180 +404,233 @@ namespace pcsc {
#ifdef WIN32 #ifdef WIN32
std::stringstream ss; std::stringstream ss;
switch (_state) { switch (_state) {
case SCARD_E_SHARING_VIOLATION: case ERROR_BROKEN_PIPE:
ss<<"The smart card cannot be accessed because of other" ss<<"The client attempted a smart card operation in a"
<<" connections outstanding."; <<" remote session, such as a client session running"
<<" on a terminal server, and the operating system in"
<<" use does not support smart card redirection.";
break; break;
case SCARD_E_NO_SMARTCARD: case SCARD_E_BAD_SEEK:
ss<<"The operation requires a Smart Card, but no Smart Card" ss<<"There was an error trying to set the smart card file"
<<" is currently in the device."; <<" object pointer.";
break; break;
case SCARD_E_UNKNOWN_CARD: case SCARD_E_CANCELLED:
ss<<"The specified smart card name is not recognized."; ss<<"The action was canceled by an SCardCancel request.";
break; break;
case SCARD_E_CANT_DISPOSE: case SCARD_E_CANT_DISPOSE:
ss<<"The system could not dispose of the media in the" ss<<"The system could not dispose of the media in the requested"
<<" requested manner."; <<" manner.";
break; break;
case SCARD_E_PROTO_MISMATCH: case SCARD_E_CARD_UNSUPPORTED:
ss<<"The requested protocols are incompatible with the" ss<<"The smart card does not meet minimal requirements for"
<<" protocol currently in use with the smart card."; <<" support.";
break; break;
case SCARD_E_NOT_READY: case SCARD_E_CERTIFICATE_UNAVAILABLE:
ss<<"The reader or smart card is not ready to accept commands."; ss<<"The requested certificate could not be obtained.";
break; break;
case SCARD_E_INVALID_VALUE: case SCARD_E_COMM_DATA_LOST:
ss<<"One or more of the supplied parameters values could" ss<<"A communications error with the smart card has been detected.";
<<" not be properly interpreted.";
break; break;
case SCARD_E_SYSTEM_CANCELLED: case SCARD_E_DIR_NOT_FOUND:
ss<<"The action was cancelled by the system, presumably" ss<<"The specified directory does not exist in the smart card.";
<<" to log off or shut down.";
break; break;
case SCARD_F_COMM_ERROR: case SCARD_E_DUPLICATE_READER:
ss<<"An internal communications error has been detected."; ss<<"The reader driver did not produce a unique reader name.";
break; break;
case SCARD_F_UNKNOWN_ERROR: case SCARD_E_FILE_NOT_FOUND:
ss<<"An internal error has been detected, but the source" ss<<"The specified file does not exist in the smart card.";
<<" is unknown."; break;
case SCARD_E_ICC_CREATEORDER:
ss<<"The requested order of object creation is not supported.";
break;
case SCARD_E_ICC_INSTALLATION:
ss<<"No primary provider can be found for the smart card.";
break;
case SCARD_E_INSUFFICIENT_BUFFER:
ss<<"The data buffer for returned data is too small for the"
<<" returned data.";
break; break;
case SCARD_E_INVALID_ATR: case SCARD_E_INVALID_ATR:
ss<<"An ATR obtained from the registry is not a valid ATR string."; ss<<"An ATR string obtained from the registry is not a valid"
<<" ATR string.";
break;
case SCARD_E_INVALID_CHV:
ss<<"The supplied PIN is incorrect.";
break;
case SCARD_E_INVALID_HANDLE:
ss<<"The supplied handle was not valid.";
break;
case SCARD_E_INVALID_PARAMETER:
ss<<"One or more of the supplied parameters could not be properly"
<<" interpreted.";
break;
case SCARD_E_INVALID_TARGET:
ss<<"Registry startup information is missing or not valid.";
break;
case SCARD_E_INVALID_VALUE:
ss<<"One or more of the supplied parameters values could not"
<<" be properly interpreted.";
break;
case SCARD_E_NOT_READY:
ss<<"The reader or smart card is not ready to accept commands.";
break; break;
case SCARD_E_NOT_TRANSACTED: case SCARD_E_NOT_TRANSACTED:
ss<<"An attempt was made to end a non-existent transaction."; ss<<"An attempt was made to end a nonexistent transaction.";
break; break;
case SCARD_E_READER_UNAVAILABLE: case SCARD_E_NO_ACCESS:
ss<<"The specified reader is not currently available for use."; ss<<"Access is denied to this file.";
break; break;
case SCARD_P_SHUTDOWN: case SCARD_E_NO_DIR:
ss<<"The operation has been aborted to allow the server" ss<<"The supplied path does not represent a smart card directory.";
<<" application to exit.";
break; break;
case SCARD_E_PCI_TOO_SMALL: case SCARD_E_NO_FILE:
ss<<"The PCI Receive buffer was too small."; ss<<"The supplied path does not represent a smart card file.";
break; break;
case SCARD_E_READER_UNSUPPORTED: case SCARD_E_NO_KEY_CONTAINER:
ss<<"The reader driver does not meet minimal requirements" ss<<"The requested key container does not exist on the smart card.";
<<" for support.";
break; break;
case SCARD_E_DUPLICATE_READER: case SCARD_E_NO_MEMORY:
ss<<"The reader driver did not produce a unique reader name."; ss<<"Not enough memory available to complete this command.";
break; break;
case SCARD_E_CARD_UNSUPPORTED: case SCARD_E_NO_READERS_AVAILABLE:
ss<<"The smart card does not meet minimal requirements" ss<<"No smart card reader is available.";
<<" for support.";
break; break;
case SCARD_E_NO_SERVICE: case SCARD_E_NO_SERVICE:
ss<<"The Smart card resource manager is not running."; ss<<"The smart card resource manager is not running.";
break; break;
case SCARD_E_SERVICE_STOPPED: case SCARD_E_NO_SMARTCARD:
ss<<"The Smart card resource manager has shut down."; ss<<"The operation requires a smart card, but no smart card"
<<" is currently in the device.";
break; break;
case SCARD_E_UNEXPECTED: case SCARD_E_NO_SUCH_CERTIFICATE:
ss<<"An unexpected card error has occurred."; ss<<"The requested certificate does not exist.";
break; break;
case SCARD_E_ICC_INSTALLATION: case SCARD_E_PCI_TOO_SMALL:
ss<<"No Primary Provider can be found for the smart card."; ss<<"The PCI receive buffer was too small.";
break; break;
case SCARD_E_ICC_CREATEORDER: case SCARD_E_PROTO_MISMATCH:
ss<<"The requested order of object creation is not supported."; ss<<"The requested protocols are incompatible with the protocol"
<<" currently in use with the smart card.";
break; break;
case SCARD_E_UNSUPPORTED_FEATURE: case SCARD_E_READER_UNAVAILABLE:
ss<<"This smart card does not support the requested feature."; ss<<"The specified reader is not currently available for use.";
break; break;
case SCARD_E_DIR_NOT_FOUND: case SCARD_E_READER_UNSUPPORTED:
ss<<"The identified directory does not exist in the smart card."; ss<<"The reader driver does not meet minimal requirements for"
<<" support.";
break; break;
case SCARD_E_FILE_NOT_FOUND: case SCARD_E_SERVER_TOO_BUSY:
ss<<"The identified file does not exist in the smart card."; ss<<"The Smart card resource manager is too busy to complete this"
<<" operation.";
break; break;
case SCARD_E_NO_DIR: case SCARD_E_SERVICE_STOPPED:
ss<<"The supplied path does not represent a smart card directory."; ss<<"The smart card resource manager has shut down.";
break; break;
case SCARD_E_NO_FILE: case SCARD_E_SHARING_VIOLATION:
ss<<"The supplied path does not represent a smart card file."; ss<<"The smart card cannot be accessed because of other outstanding"
<<" connections.";
break; break;
case SCARD_E_NO_ACCESS: case SCARD_E_SYSTEM_CANCELLED:
ss<<"Access is denied to this file."; ss<<"The action was cancelled by the system, presumably to log"
<<" off or shut down.";
break; break;
case SCARD_E_WRITE_TOO_MANY: case SCARD_E_TIMEOUT:
ss<<"The smartcard does not have enough memory to store" ss<<"The user-specified time-out value has expired.";
<<" the information.";
break; break;
case SCARD_E_BAD_SEEK: case SCARD_E_UNEXPECTED:
ss<<"There was an error trying to set the smart card file" ss<<"An unexpected card error has occurred.";
<<" object pointer.";
break; break;
case SCARD_E_INVALID_CHV: case SCARD_E_UNKNOWN_CARD:
ss<<"The supplied PIN is incorrect."; ss<<"The specified smart card name is not recognized.";
break;
case SCARD_E_UNKNOWN_READER:
ss<<"The specified reader name is not recognized.";
break; break;
case SCARD_E_UNKNOWN_RES_MNG: case SCARD_E_UNKNOWN_RES_MNG:
ss<<"An unrecognized error code was returned from a layered" ss<<"An unrecognized error code was returned from a layered"
<<" component."; <<" component.";
break; break;
case SCARD_E_NO_SUCH_CERTIFICATE: case SCARD_E_UNSUPPORTED_FEATURE:
ss<<"The requested certificate does not exist."; ss<<"This smart card does not support the requested feature.";
break; break;
case SCARD_E_CERTIFICATE_UNAVAILABLE: case SCARD_E_WRITE_TOO_MANY:
ss<<"The requested certificate could not be obtained."; ss<<"The smartcard does not have enough memory to store the"
<<" information.";
break; break;
case SCARD_E_NO_READERS_AVAILABLE: case SCARD_F_COMM_ERROR:
ss<<"Cannot find a smart card reader."; ss<<"An internal communications error has been detected.";
break; break;
case SCARD_E_COMM_DATA_LOST: case SCARD_F_INTERNAL_ERROR:
ss<<"A communications error with the smart card has been" ss<<"An internal consistency check failed.";
<<" detected. Retry the operation.";
break; break;
case SCARD_E_NO_KEY_CONTAINER: case SCARD_F_UNKNOWN_ERROR:
ss<<"The requested key container does not exist on the" ss<<"An internal error has been detected, but the source is"
<<" smart card."; <<" unknown.";
break; break;
case SCARD_E_SERVER_TOO_BUSY: case SCARD_F_WAITED_TOO_LONG:
ss<<"The Smart card resource manager is too busy to complete" ss<<"An internal consistency timer has expired.";
<<" this operation.";
break; break;
case SCARD_W_UNSUPPORTED_CARD: case SCARD_P_SHUTDOWN:
ss<<"The reader cannot communicate with the smart card, due" ss<<"The operation has been aborted to allow the server application"
<<" to ATR configuration conflicts."; <<" to exit.";
break; break;
case SCARD_W_UNRESPONSIVE_CARD: case SCARD_S_SUCCESS:
ss<<"The smart card is not responding to a reset."; ss<<"No error was encountered.";
break; break;
case SCARD_W_UNPOWERED_CARD: case SCARD_W_CANCELLED_BY_USER:
ss<<"Power has been removed from the smart card, so that" ss<<"The action was cancelled by the user.";
<<" further communication is not possible.";
break; break;
case SCARD_W_RESET_CARD: case SCARD_W_CARD_NOT_AUTHENTICATED:
ss<<"The smart card has been reset, so any shared state" ss<<"No PIN was presented to the smart card.";
<<" information is invalid."; break;
case SCARD_W_CHV_BLOCKED:
ss<<"The card cannot be accessed because the maximum number"
<<" of PIN entry attempts has been reached.";
break;
case SCARD_W_EOF:
ss<<"The end of the smart card file has been reached.";
break; break;
case SCARD_W_REMOVED_CARD: case SCARD_W_REMOVED_CARD:
ss<<"The smart card has been removed, so that further" ss<<"The smart card has been removed, so that further communication"
<<" communication is not possible."; <<" is not possible.";
break;
case SCARD_W_RESET_CARD:
ss<<"The smart card was reset.";
break; break;
case SCARD_W_SECURITY_VIOLATION: case SCARD_W_SECURITY_VIOLATION:
ss<<"Access was denied because of a security violation."; ss<<"Access was denied because of a security violation.";
break; break;
case SCARD_W_WRONG_CHV: case SCARD_W_UNPOWERED_CARD:
ss<<"The card cannot be accessed because the wrong PIN" ss<<"Power has been removed from the smart card, so that"
<<" was presented."; <<" further communication is not possible.";
break;
case SCARD_W_CHV_BLOCKED:
ss<<"The card cannot be accessed because the maximum"
<<" number of PIN entry attempts has been reached.";
break; break;
case SCARD_W_EOF: case SCARD_W_UNRESPONSIVE_CARD:
ss<<"The end of the smart card file has been reached."; ss<<"The smart card is not responding to a reset.";
break; break;
case SCARD_W_CANCELLED_BY_USER: case SCARD_W_UNSUPPORTED_CARD:
ss<<"The action was cancelled by the user."; ss<<"The reader cannot communicate with the smart card,"
<<" due to ATR configuration conflicts.";
break; break;
case SCARD_W_CARD_NOT_AUTHENTICATED: case SCARD_W_WRONG_CHV:
ss<<"No PIN was presented to the smart card."; ss<<"The card cannot be accessed because the wrong PIN was"
<<" presented.";
break; break;
default: default:
ss<<"Unknown PCSC state: "<<std::hex<<_state; ss<<"unknown PCSC state=0x"
<<std::hex<<std::setfill('0')<<std::setw(8)<<_state;
switch (_state>>30) {
case 0: ss<<" means SUCCESS"; break;
case 1: ss<<" means INFORMATIONAL"; break;
case 2: ss<<" means WARNING"; break;
case 3: ss<<" means ERROR"; break;
default: ss<<" illegal value";
}
ss<<" C="<<(_state>>29&1);
ss<<" R="<<(_state>>28&1);
ss<<" Facility=0x"<<std::hex<<std::setfill('0')<<std::setw(3)
<<(_state>>16&0xfff);
ss<<" Code=0x"<<std::hex<<std::setfill('0')<<std::setw(4)
<<(_state&0xffff);
} }
return ss.str(); return ss.str();
#else #else
@ -585,12 +653,12 @@ namespace pcsc {
/*! @throw access_error if it is instanciated for exceptions and /*! @throw access_error if it is instanciated for exceptions and
an error occured in the last command. */ an error occured in the last command. */
bool check(const std::string& context="") { bool check(const std::string& context="") {
if (_exc&&_state!=SCARD_S_SUCCESS) if (_exc&&!*this)
if (context.size()) if (context.size())
throw access_error(context+": "+error()); throw access_error(context+": "+error());
else else
throw access_error(error()); throw access_error(error());
return _state==SCARD_S_SUCCESS; return *this;
} }
//! Splits a buffer with 0 separators into a vector of strings. //! Splits a buffer with 0 separators into a vector of strings.

Loading…
Cancel
Save