Bug in SCardTransmit parameter
This commit is contained in:
		| @@ -1,6 +1,6 @@ | |||||||
| //g++ -I ../svn -I /usr/include/PCSC test.cpp -lpcsclite -ggdb3 | //g++ -I ../svn -I /usr/include/PCSC test.cpp -lpcsclite -ggdb3 | ||||||
| #include "pcscpp/pcsc.hxx" | #include "pcscpp/pcsc.hxx" | ||||||
| #include "pcscpp/cardos.hxx" | //#include "pcscpp/cardos.hxx" | ||||||
| #include <iostream> | #include <iostream> | ||||||
|  |  | ||||||
| int main(int, char const*const*const argv) try { | int main(int, char const*const*const argv) try { | ||||||
|   | |||||||
							
								
								
									
										34
									
								
								src/pcsc.hxx
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								src/pcsc.hxx
									
									
									
									
									
								
							| @@ -10,8 +10,10 @@ | |||||||
| #ifndef PCSC_HXX | #ifndef PCSC_HXX | ||||||
| #define PCSC_HXX | #define PCSC_HXX | ||||||
|  |  | ||||||
|  | #include <string> | ||||||
|  |  | ||||||
| #ifdef WIN32 | #ifdef WIN32 | ||||||
|   #include "WinSCard.h" |   #include <WinSCard.h> | ||||||
|   #ifndef MAX_ATR_SIZE |   #ifndef MAX_ATR_SIZE | ||||||
|     #define MAX_ATR_SIZE 33 |     #define MAX_ATR_SIZE 33 | ||||||
|   #endif |   #endif | ||||||
| @@ -41,7 +43,6 @@ namespace pcsc { | |||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #include <boost/shared_ptr.hpp> | #include <boost/shared_ptr.hpp> | ||||||
| #include <string> |  | ||||||
| #include <vector> | #include <vector> | ||||||
| #include <map> | #include <map> | ||||||
| #include <memory> | #include <memory> | ||||||
| @@ -69,8 +70,8 @@ namespace pcsc { | |||||||
|   std::string hex(const std::string& data) { |   std::string hex(const std::string& data) { | ||||||
|     std::stringstream res; |     std::stringstream res; | ||||||
|     for (std::string::const_iterator it(data.begin()); it!=data.end(); ++it) |     for (std::string::const_iterator it(data.begin()); it!=data.end(); ++it) | ||||||
|       res<<"(0x"<<std::hex<<std::setfill('0')<<std::setw(2) |       res<<std::hex<<std::setfill('0')<<std::setw(2) | ||||||
|          <<(unsigned int)(unsigned char)*it<<')'; |          <<(unsigned int)(unsigned char)*it; | ||||||
|     return res.str(); |     return res.str(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -189,7 +190,7 @@ namespace pcsc { | |||||||
|  |  | ||||||
|           //! Disconnects connection. |           //! Disconnects connection. | ||||||
|           ~Reader() { |           ~Reader() { | ||||||
|             _state = SCardDisconnect(_id, SCARD_LEAVE_CARD); |             _state = SCardDisconnect(_id, SCARD_RESET_CARD); | ||||||
|             if (!std::uncaught_exception()) |             if (!std::uncaught_exception()) | ||||||
|               _connection.check("disconnect smartcard"); |               _connection.check("disconnect smartcard"); | ||||||
|           } |           } | ||||||
| @@ -210,9 +211,11 @@ namespace pcsc { | |||||||
|             DWORD len(1024); // arbitrary |             DWORD len(1024); // arbitrary | ||||||
|             unsigned char buff[len]; |             unsigned char buff[len]; | ||||||
|             SCARD_IO_REQUEST rPci; |             SCARD_IO_REQUEST rPci; | ||||||
|             check(SCardTransmit(_id, pci(), |             rPci.dwProtocol  = pci()->dwProtocol; | ||||||
|  |             rPci.cbPciLength = sizeof(rPci); | ||||||
|  |             check(SCardTransmit(_id, &rPci, | ||||||
|                                 (unsigned char*)in.c_str(), in.size(), |                                 (unsigned char*)in.c_str(), in.size(), | ||||||
|                                 &rPci, buff, &len), |                                 0, buff, &len), | ||||||
|                   "smartcard transmit message "+hex(in)); |                   "smartcard transmit message "+hex(in)); | ||||||
|             return std::string((char*)buff, len); |             return std::string((char*)buff, len); | ||||||
|           } |           } | ||||||
| @@ -232,8 +235,8 @@ namespace pcsc { | |||||||
|             //          11 - Error |             //          11 - Error | ||||||
|             // So everything with Sev=00 is successful |             // So everything with Sev=00 is successful | ||||||
|             // theoretically even with Sev=01, but that's still rejected |             // theoretically even with Sev=01, but that's still rejected | ||||||
|             return (_state>>30&3)==0; |             //return (_state>>30&3)==0; | ||||||
|             //RETURN _STATE==SCARD_S_SUCCESS; |             return _state==SCARD_S_SUCCESS; | ||||||
|           } |           } | ||||||
|            |            | ||||||
|           //...........................................................variables |           //...........................................................variables | ||||||
| @@ -282,11 +285,12 @@ namespace pcsc { | |||||||
|           friend class Connection; |           friend class Connection; | ||||||
|            |            | ||||||
|           //! Establishes a connection to the given named cardreader |           //! Establishes a connection to the given named cardreader | ||||||
|           Reader(const std::string& nm, Connection& c): |           Reader(const std::string& nm, Connection& c, | ||||||
|  |                  DWORD mode=SCARD_SHARE_SHARED, | ||||||
|  |                  DWORD protocol=SCARD_PROTOCOL_T1): | ||||||
|               name(nm), _connection(c) { |               name(nm), _connection(c) { | ||||||
|             check(SCardConnect(_connection._id, strconv(name).c_str(), |             check(SCardConnect(_connection._id, strconv(name).c_str(), | ||||||
|                                SCARD_SHARE_SHARED, |                                mode, protocol, | ||||||
|                                SCARD_PROTOCOL_T0|SCARD_PROTOCOL_T1, |  | ||||||
|                                &_id, &_protocol), |                                &_id, &_protocol), | ||||||
|                   "connect smartcard \""+name+"\""); |                   "connect smartcard \""+name+"\""); | ||||||
|           } |           } | ||||||
| @@ -347,7 +351,7 @@ namespace pcsc { | |||||||
|             - @c true:  class throws exceptions in case of an error |             - @c true:  class throws exceptions in case of an error | ||||||
|             - @c false: no exceptions, check your instance after each |             - @c false: no exceptions, check your instance after each | ||||||
|                         operation */ |                         operation */ | ||||||
|       Connection(Scope s=SYSTEM, bool exceptions=true): |       Connection(Scope s=USER, bool exceptions=true): | ||||||
|           _exc(exceptions), _id(0), |           _exc(exceptions), _id(0), | ||||||
|           _state(SCardEstablishContext(s, 0, 0, &_id)) { |           _state(SCardEstablishContext(s, 0, 0, &_id)) { | ||||||
|         check("establish smartcard context"); |         check("establish smartcard context"); | ||||||
| @@ -395,8 +399,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>>30&3)==0; |         //return (_state>>30&3)==0; | ||||||
|         //return _state==SCARD_S_SUCCESS; |         return _state==SCARD_S_SUCCESS; | ||||||
|       } |       } | ||||||
|  |  | ||||||
|       //! Get the describing text of the last error |       //! Get the describing text of the last error | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user