Browse Source

getAttribute; apdu class

master
Robin Thoni 9 years ago
parent
commit
f01842a81b

+ 1
- 1
src/CMakeLists.txt View File

13
   DataAccess/ScReader.cpp
13
   DataAccess/ScReader.cpp
14
   include/ScReader.h
14
   include/ScReader.h
15
   include/ScReader.hxx)
15
   include/ScReader.hxx)
16
-add_library(pcsc_cpptools SHARED ${SOURCE_FILES} include/ScHex.h DBO/ScHex.cpp)
16
+add_library(pcsc_cpptools SHARED ${SOURCE_FILES} include/ScHex.h DBO/ScHex.cpp include/ScApduCommand.h DBO/ScApduCommand.cpp)
17
 target_link_libraries(pcsc_cpptools pcsclite)
17
 target_link_libraries(pcsc_cpptools pcsclite)

+ 5
- 0
src/DBO/ScApduCommand.cpp View File

1
+//
2
+// Created by robin on 6/30/15.
3
+//
4
+
5
+#include "ScApduCommand.h"

+ 31
- 0
src/DataAccess/ScReader.cpp View File

5
 #include <winscard.h>
5
 #include <winscard.h>
6
 #include <vector>
6
 #include <vector>
7
 #include <string.h>
7
 #include <string.h>
8
+#include <reader.h>
8
 #include "ScReader.h"
9
 #include "ScReader.h"
9
 
10
 
10
 thread_local LPSCARDCONTEXT ScReader::_context = nullptr;
11
 thread_local LPSCARDCONTEXT ScReader::_context = nullptr;
98
 {
99
 {
99
     return _lastResult;
100
     return _lastResult;
100
 }
101
 }
102
+
103
+std::string ScReader::getAttribute(DWORD attr)
104
+{
105
+    DWORD len = SCARD_AUTOALLOCATE;
106
+    BYTE* data = nullptr;
107
+    _lastResult = SCardGetAttrib(*_card, attr, (BYTE*)&data, &len);
108
+    if (_lastResult == SCARD_S_SUCCESS)
109
+        return std::string((char*)data, len);
110
+    return std::string();
111
+}
112
+
113
+std::string ScReader::getAtr()
114
+{
115
+    return getAttribute(SCARD_ATTR_ATR_STRING);
116
+}
117
+
118
+std::string ScReader::getResultString(const LONG& error)
119
+{
120
+    return pcsc_stringify_error(error);
121
+}
122
+
123
+std::string ScReader::getLastStaticResultString()
124
+{
125
+    return getResultString(_lastStaticResult);
126
+}
127
+
128
+std::string ScReader::getLastResultString()
129
+{
130
+    return getResultString(_lastResult);
131
+}

+ 29
- 0
src/include/ScApduCommand.h View File

1
+//
2
+// Created by robin on 6/30/15.
3
+//
4
+
5
+#ifndef PCSC_CPPTOOLS_SCADPUCOMMAND_H
6
+# define PCSC_CPPTOOLS_SCADPUCOMMAND_H
7
+
8
+# include <string>
9
+
10
+class ScApduCommand
11
+{
12
+
13
+private:
14
+    char _cla;
15
+
16
+    char _ins;
17
+
18
+    char _p1;
19
+
20
+    char _p2;
21
+
22
+    char _lc;
23
+
24
+    std::string _data;
25
+
26
+    char _le;
27
+};
28
+
29
+#endif //PCSC_CPPTOOLS_SCADPUCOMMAND_H

+ 10
- 0
src/include/ScReader.h View File

23
 
23
 
24
     static LONG getLastStaticResult();
24
     static LONG getLastStaticResult();
25
 
25
 
26
+    static std::string getLastStaticResultString();
27
+
28
+    static std::string getResultString(const LONG& result);
29
+
26
     LONG getLastResult();
30
     LONG getLastResult();
27
 
31
 
32
+    std::string getLastResultString();
33
+
28
     static bool establishContext();
34
     static bool establishContext();
29
 
35
 
30
     static bool freeContext();
36
     static bool freeContext();
38
 
44
 
39
     inline const std::string getName() const;
45
     inline const std::string getName() const;
40
 
46
 
47
+    std::string getAttribute(DWORD attr);
48
+
49
+    std::string getAtr();
50
+
41
 private:
51
 private:
42
     std::string _name;
52
     std::string _name;
43
 
53
 

+ 2
- 0
tests/test_pcsc_cpp_tools.cpp View File

44
     }
44
     }
45
     auto reader = readers[0];
45
     auto reader = readers[0];
46
     ASSERT_TRUE(reader->connect());
46
     ASSERT_TRUE(reader->connect());
47
+    std::cout << "ATR: " << ScHex::byteArrayToString(reader->getAtr())
48
+        << " Result: " << reader->getLastResultString() << std::endl;
47
     auto res = reader->transmit(ScBasicCommand("94 A4 00 00 02 20 00 00"));
49
     auto res = reader->transmit(ScBasicCommand("94 A4 00 00 02 20 00 00"));
48
     ASSERT_NE(nullptr, res->getData().data());
50
     ASSERT_NE(nullptr, res->getData().data());
49
     auto resp = ScHex::byteArrayToString(res->getData());
51
     auto resp = ScHex::byteArrayToString(res->getData());

Loading…
Cancel
Save