diff --git a/src/pcsc.hxx b/src/pcsc.hxx index a25bf8a..e21743b 100644 --- a/src/pcsc.hxx +++ b/src/pcsc.hxx @@ -219,7 +219,21 @@ namespace pcsc { //! @c false if last operation was not successful 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 @@ -381,7 +395,8 @@ namespace pcsc { //! @c false if last operation was not successful 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 @@ -389,180 +404,233 @@ namespace pcsc { #ifdef WIN32 std::stringstream ss; switch (_state) { - case SCARD_E_SHARING_VIOLATION: - ss<<"The smart card cannot be accessed because of other" - <<" connections outstanding."; + case ERROR_BROKEN_PIPE: + ss<<"The client attempted a smart card operation in a" + <<" 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; - case SCARD_E_NO_SMARTCARD: - ss<<"The operation requires a Smart Card, but no Smart Card" - <<" is currently in the device."; + case SCARD_E_BAD_SEEK: + ss<<"There was an error trying to set the smart card file" + <<" object pointer."; break; - case SCARD_E_UNKNOWN_CARD: - ss<<"The specified smart card name is not recognized."; + case SCARD_E_CANCELLED: + ss<<"The action was canceled by an SCardCancel request."; break; case SCARD_E_CANT_DISPOSE: - ss<<"The system could not dispose of the media in the" - <<" requested manner."; + ss<<"The system could not dispose of the media in the requested" + <<" manner."; break; - case SCARD_E_PROTO_MISMATCH: - ss<<"The requested protocols are incompatible with the" - <<" protocol currently in use with the smart card."; + case SCARD_E_CARD_UNSUPPORTED: + ss<<"The smart card does not meet minimal requirements for" + <<" support."; break; - case SCARD_E_NOT_READY: - ss<<"The reader or smart card is not ready to accept commands."; + case SCARD_E_CERTIFICATE_UNAVAILABLE: + ss<<"The requested certificate could not be obtained."; break; - case SCARD_E_INVALID_VALUE: - ss<<"One or more of the supplied parameters values could" - <<" not be properly interpreted."; + case SCARD_E_COMM_DATA_LOST: + ss<<"A communications error with the smart card has been detected."; break; - case SCARD_E_SYSTEM_CANCELLED: - ss<<"The action was cancelled by the system, presumably" - <<" to log off or shut down."; + case SCARD_E_DIR_NOT_FOUND: + ss<<"The specified directory does not exist in the smart card."; break; - case SCARD_F_COMM_ERROR: - ss<<"An internal communications error has been detected."; + case SCARD_E_DUPLICATE_READER: + ss<<"The reader driver did not produce a unique reader name."; break; - case SCARD_F_UNKNOWN_ERROR: - ss<<"An internal error has been detected, but the source" - <<" is unknown."; + case SCARD_E_FILE_NOT_FOUND: + ss<<"The specified file does not exist in the smart card."; + 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; 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; 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; - case SCARD_E_READER_UNAVAILABLE: - ss<<"The specified reader is not currently available for use."; + case SCARD_E_NO_ACCESS: + ss<<"Access is denied to this file."; break; - case SCARD_P_SHUTDOWN: - ss<<"The operation has been aborted to allow the server" - <<" application to exit."; + case SCARD_E_NO_DIR: + ss<<"The supplied path does not represent a smart card directory."; break; - case SCARD_E_PCI_TOO_SMALL: - ss<<"The PCI Receive buffer was too small."; + case SCARD_E_NO_FILE: + ss<<"The supplied path does not represent a smart card file."; break; - case SCARD_E_READER_UNSUPPORTED: - ss<<"The reader driver does not meet minimal requirements" - <<" for support."; + case SCARD_E_NO_KEY_CONTAINER: + ss<<"The requested key container does not exist on the smart card."; break; - case SCARD_E_DUPLICATE_READER: - ss<<"The reader driver did not produce a unique reader name."; + case SCARD_E_NO_MEMORY: + ss<<"Not enough memory available to complete this command."; break; - case SCARD_E_CARD_UNSUPPORTED: - ss<<"The smart card does not meet minimal requirements" - <<" for support."; + case SCARD_E_NO_READERS_AVAILABLE: + ss<<"No smart card reader is available."; break; case SCARD_E_NO_SERVICE: - ss<<"The Smart card resource manager is not running."; + ss<<"The smart card resource manager is not running."; break; - case SCARD_E_SERVICE_STOPPED: - ss<<"The Smart card resource manager has shut down."; + case SCARD_E_NO_SMARTCARD: + ss<<"The operation requires a smart card, but no smart card" + <<" is currently in the device."; break; - case SCARD_E_UNEXPECTED: - ss<<"An unexpected card error has occurred."; + case SCARD_E_NO_SUCH_CERTIFICATE: + ss<<"The requested certificate does not exist."; break; - case SCARD_E_ICC_INSTALLATION: - ss<<"No Primary Provider can be found for the smart card."; + case SCARD_E_PCI_TOO_SMALL: + ss<<"The PCI receive buffer was too small."; break; - case SCARD_E_ICC_CREATEORDER: - ss<<"The requested order of object creation is not supported."; + case SCARD_E_PROTO_MISMATCH: + ss<<"The requested protocols are incompatible with the protocol" + <<" currently in use with the smart card."; break; - case SCARD_E_UNSUPPORTED_FEATURE: - ss<<"This smart card does not support the requested feature."; + case SCARD_E_READER_UNAVAILABLE: + ss<<"The specified reader is not currently available for use."; break; - case SCARD_E_DIR_NOT_FOUND: - ss<<"The identified directory does not exist in the smart card."; + case SCARD_E_READER_UNSUPPORTED: + ss<<"The reader driver does not meet minimal requirements for" + <<" support."; break; - case SCARD_E_FILE_NOT_FOUND: - ss<<"The identified file does not exist in the smart card."; + case SCARD_E_SERVER_TOO_BUSY: + ss<<"The Smart card resource manager is too busy to complete this" + <<" operation."; break; - case SCARD_E_NO_DIR: - ss<<"The supplied path does not represent a smart card directory."; + case SCARD_E_SERVICE_STOPPED: + ss<<"The smart card resource manager has shut down."; break; - case SCARD_E_NO_FILE: - ss<<"The supplied path does not represent a smart card file."; + case SCARD_E_SHARING_VIOLATION: + ss<<"The smart card cannot be accessed because of other outstanding" + <<" connections."; break; - case SCARD_E_NO_ACCESS: - ss<<"Access is denied to this file."; + case SCARD_E_SYSTEM_CANCELLED: + ss<<"The action was cancelled by the system, presumably to log" + <<" off or shut down."; break; - case SCARD_E_WRITE_TOO_MANY: - ss<<"The smartcard does not have enough memory to store" - <<" the information."; + case SCARD_E_TIMEOUT: + ss<<"The user-specified time-out value has expired."; break; - case SCARD_E_BAD_SEEK: - ss<<"There was an error trying to set the smart card file" - <<" object pointer."; + case SCARD_E_UNEXPECTED: + ss<<"An unexpected card error has occurred."; break; - case SCARD_E_INVALID_CHV: - ss<<"The supplied PIN is incorrect."; + case SCARD_E_UNKNOWN_CARD: + ss<<"The specified smart card name is not recognized."; + break; + case SCARD_E_UNKNOWN_READER: + ss<<"The specified reader name is not recognized."; break; case SCARD_E_UNKNOWN_RES_MNG: ss<<"An unrecognized error code was returned from a layered" <<" component."; break; - case SCARD_E_NO_SUCH_CERTIFICATE: - ss<<"The requested certificate does not exist."; + case SCARD_E_UNSUPPORTED_FEATURE: + ss<<"This smart card does not support the requested feature."; break; - case SCARD_E_CERTIFICATE_UNAVAILABLE: - ss<<"The requested certificate could not be obtained."; + case SCARD_E_WRITE_TOO_MANY: + ss<<"The smartcard does not have enough memory to store the" + <<" information."; break; - case SCARD_E_NO_READERS_AVAILABLE: - ss<<"Cannot find a smart card reader."; + case SCARD_F_COMM_ERROR: + ss<<"An internal communications error has been detected."; break; - case SCARD_E_COMM_DATA_LOST: - ss<<"A communications error with the smart card has been" - <<" detected. Retry the operation."; + case SCARD_F_INTERNAL_ERROR: + ss<<"An internal consistency check failed."; break; - case SCARD_E_NO_KEY_CONTAINER: - ss<<"The requested key container does not exist on the" - <<" smart card."; + case SCARD_F_UNKNOWN_ERROR: + ss<<"An internal error has been detected, but the source is" + <<" unknown."; break; - case SCARD_E_SERVER_TOO_BUSY: - ss<<"The Smart card resource manager is too busy to complete" - <<" this operation."; + case SCARD_F_WAITED_TOO_LONG: + ss<<"An internal consistency timer has expired."; break; - case SCARD_W_UNSUPPORTED_CARD: - ss<<"The reader cannot communicate with the smart card, due" - <<" to ATR configuration conflicts."; + case SCARD_P_SHUTDOWN: + ss<<"The operation has been aborted to allow the server application" + <<" to exit."; break; - case SCARD_W_UNRESPONSIVE_CARD: - ss<<"The smart card is not responding to a reset."; + case SCARD_S_SUCCESS: + ss<<"No error was encountered."; break; - case SCARD_W_UNPOWERED_CARD: - ss<<"Power has been removed from the smart card, so that" - <<" further communication is not possible."; + case SCARD_W_CANCELLED_BY_USER: + ss<<"The action was cancelled by the user."; break; - case SCARD_W_RESET_CARD: - ss<<"The smart card has been reset, so any shared state" - <<" information is invalid."; + case SCARD_W_CARD_NOT_AUTHENTICATED: + ss<<"No PIN was presented to the smart card."; + 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; case SCARD_W_REMOVED_CARD: - ss<<"The smart card has been removed, so that further" - <<" communication is not possible."; + ss<<"The smart card has been removed, so that further communication" + <<" is not possible."; + break; + case SCARD_W_RESET_CARD: + ss<<"The smart card was reset."; break; case SCARD_W_SECURITY_VIOLATION: ss<<"Access was denied because of a security violation."; break; - case SCARD_W_WRONG_CHV: - ss<<"The card cannot be accessed because the wrong PIN" - <<" was presented."; - break; - case SCARD_W_CHV_BLOCKED: - ss<<"The card cannot be accessed because the maximum" - <<" number of PIN entry attempts has been reached."; + case SCARD_W_UNPOWERED_CARD: + ss<<"Power has been removed from the smart card, so that" + <<" further communication is not possible."; break; - case SCARD_W_EOF: - ss<<"The end of the smart card file has been reached."; + case SCARD_W_UNRESPONSIVE_CARD: + ss<<"The smart card is not responding to a reset."; break; - case SCARD_W_CANCELLED_BY_USER: - ss<<"The action was cancelled by the user."; + case SCARD_W_UNSUPPORTED_CARD: + ss<<"The reader cannot communicate with the smart card," + <<" due to ATR configuration conflicts."; break; - case SCARD_W_CARD_NOT_AUTHENTICATED: - ss<<"No PIN was presented to the smart card."; + case SCARD_W_WRONG_CHV: + ss<<"The card cannot be accessed because the wrong PIN was" + <<" presented."; break; default: - ss<<"Unknown PCSC 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"<>16&0xfff); + ss<<" Code=0x"<