Browse Source

refactor classic {1,4}K support

develop
Robin Thoni 7 years ago
parent
commit
beb395f2d4
27 changed files with 480 additions and 349 deletions
  1. 23
    13
      cli/cli/MainClass.cpp
  2. 7
    6
      cli/cli/MainClass.h
  3. 10
    10
      libnfc_cpptools/CMakeLists.txt
  4. 4
    4
      libnfc_cpptools/inc/libnfc_cpptools/FreeFareClassicAccessBits.h
  5. 6
    6
      libnfc_cpptools/inc/libnfc_cpptools/FreeFareClassicSector.h
  6. 2
    24
      libnfc_cpptools/inc/libnfc_cpptools/FreeFareTag.h
  7. 61
    0
      libnfc_cpptools/inc/libnfc_cpptools/FreeFareTagClassic.h
  8. 2
    2
      libnfc_cpptools/inc/libnfc_cpptools/LibNfcContext.h
  9. 2
    1
      libnfc_cpptools/inc/libnfc_cpptools/Result.h
  10. 8
    1
      libnfc_cpptools/src/freefare/FreeFareDevice.cpp
  11. 8
    1
      libnfc_cpptools/src/freefare/FreeFareDeviceInternal.cpp
  12. 1
    1
      libnfc_cpptools/src/freefare/FreeFareDeviceInternal.h
  13. 0
    53
      libnfc_cpptools/src/freefare/FreeFareTagInternal.h
  14. 30
    30
      libnfc_cpptools/src/freefare/Tags/Classic/FreeFareClassicAccessBits.cpp
  15. 17
    17
      libnfc_cpptools/src/freefare/Tags/Classic/FreeFareClassicSector.cpp
  16. 34
    108
      libnfc_cpptools/src/freefare/Tags/Classic/FreeFareTagClassic.cpp
  17. 10
    35
      libnfc_cpptools/src/freefare/Tags/Classic/FreeFareTagClassicInternal.cpp
  18. 37
    0
      libnfc_cpptools/src/freefare/Tags/Classic/FreeFareTagClassicInternal.h
  19. 98
    0
      libnfc_cpptools/src/freefare/Tags/FreeFareTag.cpp
  20. 42
    0
      libnfc_cpptools/src/freefare/Tags/FreeFareTagInternal.cpp
  21. 41
    0
      libnfc_cpptools/src/freefare/Tags/FreeFareTagInternal.h
  22. 3
    3
      libnfc_cpptools/src/libnfc/LibNfcContext.cpp
  23. 8
    8
      libnfc_cpptools/src/libnfc/LibNfcContextInternal.cpp
  24. 3
    3
      libnfc_cpptools/src/libnfc/LibNfcContextInternal.h
  25. 1
    1
      libnfc_cpptools/src/libnfc/NfcDeviceInternal.cpp
  26. 4
    4
      libnfc_cpptools/src/libnfc/NfcDeviceInternal.h
  27. 18
    18
      tests/test-main.cpp

+ 23
- 13
cli/cli/MainClass.cpp View File

3
 //
3
 //
4
 
4
 
5
 #include <iostream>
5
 #include <iostream>
6
+#include <algorithm>
6
 #include <sysexits.h>
7
 #include <sysexits.h>
8
+#include <unistd.h>
7
 #include <iomanip>
9
 #include <iomanip>
8
 #include <fstream>
10
 #include <fstream>
9
 #include <libnfc_cpptools/StringUtils.h>
11
 #include <libnfc_cpptools/StringUtils.h>
10
 #include <libnfc_cpptools/FreeFareDevice.h>
12
 #include <libnfc_cpptools/FreeFareDevice.h>
11
 #include <libnfc_cpptools/Result.h>
13
 #include <libnfc_cpptools/Result.h>
12
 #include <libnfc_cpptools/LibNfcContext.h>
14
 #include <libnfc_cpptools/LibNfcContext.h>
15
+#include <libnfc_cpptools/FreeFareTagClassic.h>
13
 #include "CommandLineParser.h"
16
 #include "CommandLineParser.h"
14
 #include "MainClass.h"
17
 #include "MainClass.h"
15
 
18
 
22
 #define EX_MAP_KEYS_ERROR 15
25
 #define EX_MAP_KEYS_ERROR 15
23
 #define EX_READ_ERROR 16
26
 #define EX_READ_ERROR 16
24
 #define EX_WRITE_ERROR 17
27
 #define EX_WRITE_ERROR 17
28
+#define EX_NFC_TAG_NOT_SUPPORTED 18
25
 
29
 
26
 MainClass::MainClass(int argc, char *argv[])
30
 MainClass::MainClass(int argc, char *argv[])
27
     : _argc(argc)
31
     : _argc(argc)
212
                             }
216
                             }
213
                         }
217
                         }
214
                         else {
218
                         else {
215
-                            auto tag = getTag(tagUid, tags);
216
-                            if (tag == 0) {
219
+                            auto genericTag = getTag(tagUid, tags);
220
+                            if (genericTag == nullptr) {
217
                                 std::cerr << "Tag not found" << std::endl;
221
                                 std::cerr << "Tag not found" << std::endl;
218
                                 res = EX_NFC_TAG_NOT_FOUND;
222
                                 res = EX_NFC_TAG_NOT_FOUND;
219
                             }
223
                             }
220
-                            else {
224
+                            else if (genericTag->getType() == LibNfc::FreeFare::FreeFareTag::MIFARE_CLASSIC_1K
225
+                                    || genericTag->getType() == LibNfc::FreeFare::FreeFareTag::MIFARE_CLASSIC_4K) {
226
+                                auto tag = std::static_pointer_cast<LibNfc::FreeFare::FreeFareTagClassic>(genericTag);
221
                                 if (action == Read) {
227
                                 if (action == Read) {
222
                                     res = read(tag, keys);
228
                                     res = read(tag, keys);
223
                                 }
229
                                 }
228
                                     res = write(tag, keys, inputData);
234
                                     res = write(tag, keys, inputData);
229
                                 }
235
                                 }
230
                             }
236
                             }
237
+                            else {
238
+                                std::cerr << "Tag not supported" << std::endl;
239
+                                res = EX_NFC_TAG_NOT_SUPPORTED;
240
+                            }
231
                         }
241
                         }
232
                     }
242
                     }
233
                     device->close();
243
                     device->close();
246
     return res;
256
     return res;
247
 }
257
 }
248
 
258
 
249
-int MainClass::mapKeys(std::shared_ptr<LibNfc::FreeFare::FreeFareTag> tag, std::vector<std::string> keys)
259
+int MainClass::mapKeys(std::shared_ptr<LibNfc::FreeFare::FreeFareTagClassic> tag, std::vector<std::string> keys)
250
 {
260
 {
251
     auto mappedKeysResult = tag->mapKeys(keys, printPercentMapKeys);
261
     auto mappedKeysResult = tag->mapKeys(keys, printPercentMapKeys);
252
     if (!mappedKeysResult) {
262
     if (!mappedKeysResult) {
268
     return EX_OK;
278
     return EX_OK;
269
 }
279
 }
270
 
280
 
271
-int MainClass::read(std::shared_ptr<LibNfc::FreeFare::FreeFareTag> tag, std::vector<std::string> keys)
281
+int MainClass::read(std::shared_ptr<LibNfc::FreeFare::FreeFareTagClassic> tag, std::vector<std::string> keys)
272
 {
282
 {
273
     auto readResult = tag->read(keys, printPercentMapKeys, printPercentDump);
283
     auto readResult = tag->read(keys, printPercentMapKeys, printPercentDump);
274
     if (!readResult) {
284
     if (!readResult) {
280
     return EX_OK;
290
     return EX_OK;
281
 }
291
 }
282
 
292
 
283
-int MainClass::write(std::shared_ptr<LibNfc::FreeFare::FreeFareTag> tag, std::vector<std::string> keys, const std::string &data)
293
+int MainClass::write(std::shared_ptr<LibNfc::FreeFare::FreeFareTagClassic> tag, std::vector<std::string> keys, const std::string &data)
284
 {
294
 {
285
     auto writeResult = tag->write(keys, data, false, printPercentMapKeys, printPercentWrite);
295
     auto writeResult = tag->write(keys, data, false, printPercentMapKeys, printPercentWrite);
286
     if (!writeResult) {
296
     if (!writeResult) {
287
         writeResult.print();
297
         writeResult.print();
288
         return EX_WRITE_ERROR;
298
         return EX_WRITE_ERROR;
289
     }
299
     }
290
-//    std::vector<LibNfc::FreeFare::FreeFareSector> sectors;
300
+//    std::vector<LibNfc::FreeFare::FreeFareClassicSector> sectors;
291
 //    std::string d = LibNfc::Utils::StringUtils::ensureSize(data, 1024);
301
 //    std::string d = LibNfc::Utils::StringUtils::ensureSize(data, 1024);
292
 //    for (int i = 0; i < 16; ++i) {
302
 //    for (int i = 0; i < 16; ++i) {
293
-//        LibNfc::FreeFare::FreeFareSector LibNfc::FreeFare::FreeFareSector(d.substr(i * 64, 64));
294
-//        sectors.push_back(LibNfc::FreeFare::FreeFareSector);
303
+//        LibNfc::FreeFare::FreeFareClassicSector LibNfc::FreeFare::FreeFareClassicSector(d.substr(i * 64, 64));
304
+//        sectors.push_back(LibNfc::FreeFare::FreeFareClassicSector);
295
 //    }
305
 //    }
296
 //    printSectors(sectors);
306
 //    printSectors(sectors);
297
     return EX_OK;
307
     return EX_OK;
298
 }
308
 }
299
 
309
 
300
-void MainClass::printSectors(const std::vector<LibNfc::FreeFare::FreeFareSector> &sectors)
310
+void MainClass::printSectors(const std::vector<LibNfc::FreeFare::FreeFareClassicSector> &sectors)
301
 {
311
 {
302
     for(int s = 0; s < sectors.size(); ++s) {
312
     for(int s = 0; s < sectors.size(); ++s) {
303
         cout() << "+Sector: " << s << std::endl;
313
         cout() << "+Sector: " << s << std::endl;
313
         cout() << "+Trailer key A: " << (sector.hasKeyA() ? LibNfc::Utils::StringUtils::rawToHuman(sector.getKeyA()) : std::string(12, '-'))
323
         cout() << "+Trailer key A: " << (sector.hasKeyA() ? LibNfc::Utils::StringUtils::rawToHuman(sector.getKeyA()) : std::string(12, '-'))
314
         << "\t AC bits: " << (sector.hasAccessBits() ? LibNfc::Utils::StringUtils::rawToHuman(sector.getAccessBits()) : std::string(8, '-'))
324
         << "\t AC bits: " << (sector.hasAccessBits() ? LibNfc::Utils::StringUtils::rawToHuman(sector.getAccessBits()) : std::string(8, '-'))
315
         << "\t key B: " << (sector.hasKeyB() ? LibNfc::Utils::StringUtils::rawToHuman(sector.getKeyB()) : std::string(12, '-')) << std::endl;
325
         << "\t key B: " << (sector.hasKeyB() ? LibNfc::Utils::StringUtils::rawToHuman(sector.getKeyB()) : std::string(12, '-')) << std::endl;
316
-        LibNfc::FreeFare::FreeFareAccessBits accessBitsDbo = sector.getAccessBitsDbo();
326
+        LibNfc::FreeFare::FreeFareClassicAccessBits accessBitsDbo = sector.getAccessBitsDbo();
317
         for (int b = 0; b < 3; ++b) {
327
         for (int b = 0; b < 3; ++b) {
318
             cout() << "+Block: " << b << " ";
328
             cout() << "+Block: " << b << " ";
319
             printBlockAccessBits(accessBitsDbo, b);
329
             printBlockAccessBits(accessBitsDbo, b);
323
     }
333
     }
324
 }
334
 }
325
 
335
 
326
-void MainClass::printBlockAccessBits(const LibNfc::FreeFare::FreeFareAccessBits &accessBits, int block)
336
+void MainClass::printBlockAccessBits(const LibNfc::FreeFare::FreeFareClassicAccessBits &accessBits, int block)
327
 {
337
 {
328
     cout() << "read: " << (accessBits.canKeyAReadBlock(block) ? "A" : " ") << (accessBits.canKeyBReadBlock(block) ? "B" : " ");
338
     cout() << "read: " << (accessBits.canKeyAReadBlock(block) ? "A" : " ") << (accessBits.canKeyBReadBlock(block) ? "B" : " ");
329
     cout() << "\t write: " << (accessBits.canKeyAWriteBlock(block) ? "A" : " ") << (accessBits.canKeyBWriteBlock(block) ? "B" : " ");
339
     cout() << "\t write: " << (accessBits.canKeyAWriteBlock(block) ? "A" : " ") << (accessBits.canKeyBWriteBlock(block) ? "B" : " ");
331
     cout() << "\t decrement: " << (accessBits.canKeyADecrementBlock(block) ? "A" : " ") << (accessBits.canKeyBDecrementBlock(block) ? "B" : " ") << std::endl;
341
     cout() << "\t decrement: " << (accessBits.canKeyADecrementBlock(block) ? "A" : " ") << (accessBits.canKeyBDecrementBlock(block) ? "B" : " ") << std::endl;
332
 }
342
 }
333
 
343
 
334
-void MainClass::printTrailerAccessBits(const LibNfc::FreeFare::FreeFareAccessBits &accessBits)
344
+void MainClass::printTrailerAccessBits(const LibNfc::FreeFare::FreeFareClassicAccessBits &accessBits)
335
 {
345
 {
336
     cout() << "key A read: " << (accessBits.canKeyAReadKeyATrailer() ? "A" : " ") << (accessBits.canKeyBReadKeyATrailer() ? "B" : " ");
346
     cout() << "key A read: " << (accessBits.canKeyAReadKeyATrailer() ? "A" : " ") << (accessBits.canKeyBReadKeyATrailer() ? "B" : " ");
337
     cout() << "\t key A write: " << (accessBits.canKeyAWriteKeyATrailer() ? "A" : " ") << (accessBits.canKeyBWriteKeyATrailer() ? "B" : " ");
347
     cout() << "\t key A write: " << (accessBits.canKeyAWriteKeyATrailer() ? "A" : " ") << (accessBits.canKeyBWriteKeyATrailer() ? "B" : " ");

+ 7
- 6
cli/cli/MainClass.h View File

7
 
7
 
8
 #include <memory>
8
 #include <memory>
9
 #include <libnfc_cpptools/FreeFareTag.h>
9
 #include <libnfc_cpptools/FreeFareTag.h>
10
+#include <libnfc_cpptools/FreeFareTagClassic.h>
10
 #include <libnfc_cpptools/NfcDevice.h>
11
 #include <libnfc_cpptools/NfcDevice.h>
11
 
12
 
12
 class MainClass {
13
 class MainClass {
27
 
28
 
28
     std::shared_ptr<LibNfc::FreeFare::FreeFareTag> getTag(const std::string& tagUid, std::vector<std::shared_ptr<LibNfc::FreeFare::FreeFareTag>> tags);
29
     std::shared_ptr<LibNfc::FreeFare::FreeFareTag> getTag(const std::string& tagUid, std::vector<std::shared_ptr<LibNfc::FreeFare::FreeFareTag>> tags);
29
 
30
 
30
-    int mapKeys(std::shared_ptr<LibNfc::FreeFare::FreeFareTag> tag, std::vector<std::string> keys);
31
+    int mapKeys(std::shared_ptr<LibNfc::FreeFare::FreeFareTagClassic> tag, std::vector<std::string> keys);
31
 
32
 
32
-    int read(std::shared_ptr<LibNfc::FreeFare::FreeFareTag> tag, std::vector<std::string> keys);
33
+    int read(std::shared_ptr<LibNfc::FreeFare::FreeFareTagClassic> tag, std::vector<std::string> keys);
33
 
34
 
34
-    int write(std::shared_ptr<LibNfc::FreeFare::FreeFareTag> tag, std::vector<std::string> keys, const std::string& data);
35
+    int write(std::shared_ptr<LibNfc::FreeFare::FreeFareTagClassic> tag, std::vector<std::string> keys, const std::string& data);
35
 
36
 
36
     LibNfc::Utils::Result<std::vector<std::string>> readFile(const std::string& filePath);
37
     LibNfc::Utils::Result<std::vector<std::string>> readFile(const std::string& filePath);
37
 
38
 
38
     LibNfc::Utils::Result<std::vector<std::string>> readStream(std::istream& stream);
39
     LibNfc::Utils::Result<std::vector<std::string>> readStream(std::istream& stream);
39
 
40
 
40
-    void printSectors(const std::vector<LibNfc::FreeFare::FreeFareSector>& sectors);
41
+    void printSectors(const std::vector<LibNfc::FreeFare::FreeFareClassicSector>& sectors);
41
 
42
 
42
-    void printBlockAccessBits(const LibNfc::FreeFare::FreeFareAccessBits& accessBits, int block);
43
+    void printBlockAccessBits(const LibNfc::FreeFare::FreeFareClassicAccessBits& accessBits, int block);
43
 
44
 
44
-    void printTrailerAccessBits(const LibNfc::FreeFare::FreeFareAccessBits& accessBits);
45
+    void printTrailerAccessBits(const LibNfc::FreeFare::FreeFareClassicAccessBits& accessBits);
45
 
46
 
46
     void printVersion();
47
     void printVersion();
47
 
48
 

+ 10
- 10
libnfc_cpptools/CMakeLists.txt View File

7
 
7
 
8
 set(SOURCE_FILES
8
 set(SOURCE_FILES
9
         inc/libnfc_cpptools/Result.h
9
         inc/libnfc_cpptools/Result.h
10
-        src/libnfc/LibNfcInternal.cpp
11
-        src/libnfc/LibNfcInternal.h
10
+        src/libnfc/LibNfcContextInternal.cpp
11
+        src/libnfc/LibNfcContextInternal.h
12
         src/libnfc/NfcDeviceInternal.cpp
12
         src/libnfc/NfcDeviceInternal.cpp
13
         src/libnfc/NfcDeviceInternal.h
13
         src/libnfc/NfcDeviceInternal.h
14
         src/freefare/FreeFareDeviceInternal.cpp
14
         src/freefare/FreeFareDeviceInternal.cpp
15
         src/freefare/FreeFareDeviceInternal.h
15
         src/freefare/FreeFareDeviceInternal.h
16
-        src/freefare/FreeFareTagInternal.cpp
17
-        src/freefare/FreeFareTagInternal.h
16
+        src/freefare/Tags/FreeFareTagInternal.cpp
17
+        src/freefare/Tags/FreeFareTagInternal.h
18
         src/utils/StringUtils.cpp
18
         src/utils/StringUtils.cpp
19
         inc/libnfc_cpptools/StringUtils.h
19
         inc/libnfc_cpptools/StringUtils.h
20
-        src/freefare/FreeFareAccessBits.cpp
21
-        inc/libnfc_cpptools/FreeFareAccessBits.h
20
+        src/freefare/Tags/Classic/FreeFareClassicAccessBits.cpp
21
+        inc/libnfc_cpptools/FreeFareClassicAccessBits.h
22
         src/libnfc/LibNfcContext.cpp
22
         src/libnfc/LibNfcContext.cpp
23
         inc/libnfc_cpptools/LibNfcContext.h
23
         inc/libnfc_cpptools/LibNfcContext.h
24
         src/libnfc/NfcDevice.cpp
24
         src/libnfc/NfcDevice.cpp
25
         inc/libnfc_cpptools/NfcDevice.h
25
         inc/libnfc_cpptools/NfcDevice.h
26
         src/freefare/FreeFareDevice.cpp
26
         src/freefare/FreeFareDevice.cpp
27
         inc/libnfc_cpptools/FreeFareDevice.h
27
         inc/libnfc_cpptools/FreeFareDevice.h
28
-        src/freefare/FreeFareTag.cpp
28
+        src/freefare/Tags/FreeFareTag.cpp
29
         inc/libnfc_cpptools/FreeFareTag.h
29
         inc/libnfc_cpptools/FreeFareTag.h
30
-        src/freefare/FreeFareSector.cpp
31
-        inc/libnfc_cpptools/FreeFareSector.h
30
+        src/freefare/Tags/Classic/FreeFareClassicSector.cpp
31
+        inc/libnfc_cpptools/FreeFareClassicSector.h
32
         src/utils/ArrayUtils.cpp
32
         src/utils/ArrayUtils.cpp
33
         inc/libnfc_cpptools/ArrayUtils.h
33
         inc/libnfc_cpptools/ArrayUtils.h
34
-        )
34
+        src/freefare/Tags/Classic/FreeFareTagClassicInternal.cpp src/freefare/Tags/Classic/FreeFareTagClassicInternal.h src/freefare/Tags/Classic/FreeFareTagClassic.cpp inc/libnfc_cpptools/FreeFareTagClassic.h)
35
 
35
 
36
 add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})
36
 add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})
37
 target_link_libraries(${PROJECT_NAME}
37
 target_link_libraries(${PROJECT_NAME}

libnfc_cpptools/inc/libnfc_cpptools/FreeFareAccessBits.h → libnfc_cpptools/inc/libnfc_cpptools/FreeFareClassicAccessBits.h View File

13
 namespace FreeFare
13
 namespace FreeFare
14
 {
14
 {
15
 
15
 
16
-class FreeFareAccessBits
16
+class FreeFareClassicAccessBits
17
 {
17
 {
18
 public:
18
 public:
19
 
19
 
20
     static const char nonInvertedBitPosition[4][4];
20
     static const char nonInvertedBitPosition[4][4];
21
     static const char invertedBitPosition[4][4];
21
     static const char invertedBitPosition[4][4];
22
 
22
 
23
-    FreeFareAccessBits();
24
-    explicit FreeFareAccessBits(const std::string& bits);
25
-    ~FreeFareAccessBits() = default;
23
+    FreeFareClassicAccessBits();
24
+    explicit FreeFareClassicAccessBits(const std::string& bits);
25
+    ~FreeFareClassicAccessBits() = default;
26
 
26
 
27
     char getUserData() const;
27
     char getUserData() const;
28
     void setUserData(const char& data);
28
     void setUserData(const char& data);

libnfc_cpptools/inc/libnfc_cpptools/FreeFareSector.h → libnfc_cpptools/inc/libnfc_cpptools/FreeFareClassicSector.h View File

8
 
8
 
9
 #include <string>
9
 #include <string>
10
 #include <libnfc_cpptools/Result.h>
10
 #include <libnfc_cpptools/Result.h>
11
-#include <libnfc_cpptools/FreeFareAccessBits.h>
11
+#include <libnfc_cpptools/FreeFareClassicAccessBits.h>
12
 
12
 
13
 namespace LibNfc
13
 namespace LibNfc
14
 {
14
 {
15
 namespace FreeFare
15
 namespace FreeFare
16
 {
16
 {
17
 
17
 
18
-class FreeFareSector
18
+class FreeFareClassicSector
19
 {
19
 {
20
 public:
20
 public:
21
-    explicit FreeFareSector(const std::string& data = "");
22
-    ~FreeFareSector() = default;
21
+    explicit FreeFareClassicSector(const std::string& data = "");
22
+    ~FreeFareClassicSector() = default;
23
 
23
 
24
     const std::string& getBlock(int block) const;
24
     const std::string& getBlock(int block) const;
25
 
25
 
29
 
29
 
30
     std::string getAccessBits() const;
30
     std::string getAccessBits() const;
31
 
31
 
32
-    FreeFareAccessBits getAccessBitsDbo() const;
32
+    FreeFareClassicAccessBits getAccessBitsDbo() const;
33
 
33
 
34
     void setBlock(int block, const std::string& data);
34
     void setBlock(int block, const std::string& data);
35
 
35
 
39
 
39
 
40
     void setAccessBits(const std::string& accessBits);
40
     void setAccessBits(const std::string& accessBits);
41
 
41
 
42
-    void setAccessBits(const FreeFareAccessBits& accessBits);
42
+    void setAccessBits(const FreeFareClassicAccessBits& accessBits);
43
 
43
 
44
     bool hasBlock(int block) const;
44
     bool hasBlock(int block) const;
45
 
45
 

+ 2
- 24
libnfc_cpptools/inc/libnfc_cpptools/FreeFareTag.h View File

6
 #define LIBNFC_CPPTOOLS_FREEFARETAGBUSINESS_H
6
 #define LIBNFC_CPPTOOLS_FREEFARETAGBUSINESS_H
7
 
7
 
8
 
8
 
9
-#include <boost/shared_ptr.hpp>
10
-#include <libnfc_cpptools/FreeFareSector.h>
9
+#include <memory>
10
+#include <libnfc_cpptools/FreeFareClassicSector.h>
11
 
11
 
12
 namespace LibNfc
12
 namespace LibNfc
13
 {
13
 {
37
     explicit FreeFareTag(std::shared_ptr<FreeFareTagInternal> tag);
37
     explicit FreeFareTag(std::shared_ptr<FreeFareTagInternal> tag);
38
     ~FreeFareTag() = default;
38
     ~FreeFareTag() = default;
39
 
39
 
40
-    LibNfc::Utils::ResultBool authenticate(int sector, const std::string& key, int keyType);
41
-
42
-    LibNfc::Utils::Result<MappedKeys> mapKeys(const std::vector<std::string>& keys, std::function<void(int, int)> cb = nullptr);
43
-
44
-    LibNfc::Utils::ResultString readBlock(int sector, int block, const std::string& key, int keyType);
45
-
46
-    LibNfc::Utils::Result<FreeFareSector> readSector(int sector, const std::string& key, int keyType);
47
-
48
-    LibNfc::Utils::Result<std::vector<FreeFareSector>> read(const MappedKeys& keys, std::function<void(int, int)> cb = nullptr);
49
-
50
-    LibNfc::Utils::Result<std::vector<FreeFareSector>> read(const std::vector<std::string>& keys, std::function<void(int, int)> mapCb = nullptr,
51
-                                        std::function<void(int, int)> readCb = nullptr);
52
-
53
-    LibNfc::Utils::ResultBool writeBlock(int sector, int block, const std::string& key, int keyType, const std::string& data);
54
-
55
-    LibNfc::Utils::ResultBool writeSector(int sector, const std::string& key, int keyType, const std::string& data);
56
-
57
-    LibNfc::Utils::ResultBool write(const MappedKeys& keys, const std::string& data, bool writeSector0, std::function<void(int, int)> cb = nullptr);
58
-
59
-    LibNfc::Utils::ResultBool write(const std::vector<std::string>& keys, const std::string& data, bool writeSector0,
60
-                     std::function<void(int, int)> mapCb = nullptr, std::function<void(int, int)> writeCb = nullptr);
61
-
62
     const std::string& getUid() const;
40
     const std::string& getUid() const;
63
 
41
 
64
     FreeFareTagType getType() const;
42
     FreeFareTagType getType() const;

+ 61
- 0
libnfc_cpptools/inc/libnfc_cpptools/FreeFareTagClassic.h View File

1
+//
2
+// Created by robin on 10/8/17.
3
+//
4
+
5
+#ifndef NFC_CPPTOOLS_FREEFARETAGCLASSIC_H
6
+#define NFC_CPPTOOLS_FREEFARETAGCLASSIC_H
7
+
8
+#include "FreeFareTag.h"
9
+
10
+namespace LibNfc
11
+{
12
+namespace FreeFare
13
+{
14
+
15
+class FreeFareTagClassicInternal;
16
+
17
+class FreeFareTagClassic : public FreeFareTag
18
+{
19
+public:
20
+    explicit FreeFareTagClassic(std::shared_ptr<FreeFareTagClassicInternal> tag);
21
+
22
+    LibNfc::Utils::ResultBool authenticate(int sector, const std::string& key, int keyType);
23
+
24
+    LibNfc::Utils::Result<MappedKeys> mapKeys(const std::vector<std::string>& keys,
25
+                                              std::function<void(int, int)> cb = nullptr);
26
+
27
+    LibNfc::Utils::ResultString readBlock(int sector, int block, const std::string& key, int keyType);
28
+
29
+    LibNfc::Utils::Result<FreeFareClassicSector> readSector(int sector, const std::string& key, int keyType);
30
+
31
+    LibNfc::Utils::Result<std::vector<FreeFareClassicSector>> read(const MappedKeys& keys,
32
+                                                            std::function<void(int, int)> cb = nullptr);
33
+
34
+    LibNfc::Utils::Result<std::vector<FreeFareClassicSector>> read(const std::vector<std::string>& keys,
35
+                                                            std::function<void(int, int)> mapCb = nullptr,
36
+                                                            std::function<void(int, int)> readCb = nullptr);
37
+
38
+    LibNfc::Utils::ResultBool writeBlock(int sector,
39
+                                         int block,
40
+                                         const std::string& key,
41
+                                         int keyType,
42
+                                         const std::string& data);
43
+
44
+    LibNfc::Utils::ResultBool writeSector(int sector, const std::string& key, int keyType, const std::string& data);
45
+
46
+    LibNfc::Utils::ResultBool write(const MappedKeys& keys,
47
+                                    const std::string& data,
48
+                                    bool writeSector0,
49
+                                    std::function<void(int, int)> cb = nullptr);
50
+
51
+    LibNfc::Utils::ResultBool write(const std::vector<std::string>& keys,
52
+                                    const std::string& data,
53
+                                    bool writeSector0,
54
+                                    std::function<void(int, int)> mapCb = nullptr,
55
+                                    std::function<void(int, int)> writeCb = nullptr);
56
+};
57
+
58
+}; // FreeFare
59
+}; // LibNfc
60
+
61
+#endif //NFC_CPPTOOLS_FREEFARETAGCLASSIC_H

+ 2
- 2
libnfc_cpptools/inc/libnfc_cpptools/LibNfcContext.h View File

14
 namespace Core
14
 namespace Core
15
 {
15
 {
16
 
16
 
17
-class LibNfcInternal;
17
+class LibNfcContextInternal;
18
 
18
 
19
 class LibNfcContext
19
 class LibNfcContext
20
 {
20
 {
35
     static std::string getLibNfcCppToolsVersion();
35
     static std::string getLibNfcCppToolsVersion();
36
 
36
 
37
 protected:
37
 protected:
38
-    std::shared_ptr<LibNfcInternal> _libNfc;
38
+    std::shared_ptr<LibNfcContextInternal> _libNfc;
39
 };
39
 };
40
 
40
 
41
 }; // Core
41
 }; // Core

+ 2
- 1
libnfc_cpptools/inc/libnfc_cpptools/Result.h View File

19
 template <class T> class Result
19
 template <class T> class Result
20
 {
20
 {
21
 public:
21
 public:
22
-    Result();
23
     Result(const Result<T>& other);
22
     Result(const Result<T>& other);
24
 
23
 
25
     static const Result<T> ok(const T& data);
24
     static const Result<T> ok(const T& data);
40
     const Result<T>& print() const;
39
     const Result<T>& print() const;
41
 
40
 
42
 private:
41
 private:
42
+    Result();
43
+
43
     T _data;
44
     T _data;
44
 
45
 
45
     std::string _error;
46
     std::string _error;

+ 8
- 1
libnfc_cpptools/src/freefare/FreeFareDevice.cpp View File

2
 // Created by robin on 7/22/16.
2
 // Created by robin on 7/22/16.
3
 //
3
 //
4
 
4
 
5
+#include <libnfc_cpptools/FreeFareTagClassic.h>
5
 #include "libnfc_cpptools/FreeFareDevice.h"
6
 #include "libnfc_cpptools/FreeFareDevice.h"
6
 #include "FreeFareDeviceInternal.h"
7
 #include "FreeFareDeviceInternal.h"
8
+#include "Tags/Classic/FreeFareTagClassicInternal.h"
7
 
9
 
8
 namespace LibNfc
10
 namespace LibNfc
9
 {
11
 {
28
     auto tags = tagsResult.getData();
30
     auto tags = tagsResult.getData();
29
     std::vector<std::shared_ptr<FreeFareTag>> tagsBusiness;
31
     std::vector<std::shared_ptr<FreeFareTag>> tagsBusiness;
30
     for (auto tag : tags) {
32
     for (auto tag : tags) {
31
-        tagsBusiness.push_back(std::make_shared<FreeFareTag>(tag));
33
+        if (tag->getType() == MIFARE_CLASSIC_1K || tag->getType() == MIFARE_CLASSIC_4K) {
34
+            tagsBusiness.push_back(std::make_shared<FreeFareTagClassic>(std::dynamic_pointer_cast<FreeFareTagClassicInternal>(tag)));
35
+        }
36
+        else {
37
+            tagsBusiness.push_back(std::make_shared<FreeFareTag>(tag));
38
+        }
32
     }
39
     }
33
     return LibNfc::Utils::Result<std::vector<std::shared_ptr<FreeFareTag>>>::ok(tagsBusiness);
40
     return LibNfc::Utils::Result<std::vector<std::shared_ptr<FreeFareTag>>>::ok(tagsBusiness);
34
 }
41
 }

+ 8
- 1
libnfc_cpptools/src/freefare/FreeFareDeviceInternal.cpp View File

2
 // Created by robin on 6/19/16.
2
 // Created by robin on 6/19/16.
3
 //
3
 //
4
 
4
 
5
+#include <Tags/Classic/FreeFareTagClassicInternal.h>
5
 #include "FreeFareDeviceInternal.h"
6
 #include "FreeFareDeviceInternal.h"
6
 
7
 
7
 namespace LibNfc
8
 namespace LibNfc
22
     }
23
     }
23
     std::vector<std::shared_ptr<FreeFareTagInternal>> tagList;
24
     std::vector<std::shared_ptr<FreeFareTagInternal>> tagList;
24
     for (size_t i = 0; tags[i] != 0; ++i) {
25
     for (size_t i = 0; tags[i] != 0; ++i) {
25
-        tagList.push_back(std::make_shared<FreeFareTagInternal>(tags[i]));
26
+        auto type = freefare_get_tag_type(tags[i]);
27
+        if (type == MIFARE_CLASSIC_1K || type == MIFARE_CLASSIC_4K) {
28
+            tagList.push_back(std::make_shared<FreeFareTagClassicInternal>(tags[i]));
29
+        }
30
+        else {
31
+            tagList.push_back(std::make_shared<FreeFareTagInternal>(tags[i]));
32
+        }
26
     }
33
     }
27
     return LibNfc::Utils::Result<std::vector<std::shared_ptr<FreeFareTagInternal>>>::ok(tagList);
34
     return LibNfc::Utils::Result<std::vector<std::shared_ptr<FreeFareTagInternal>>>::ok(tagList);
28
 }
35
 }

+ 1
- 1
libnfc_cpptools/src/freefare/FreeFareDeviceInternal.h View File

8
 
8
 
9
 #include <freefare.h>
9
 #include <freefare.h>
10
 #include "NfcDeviceInternal.h"
10
 #include "NfcDeviceInternal.h"
11
-#include "FreeFareTagInternal.h"
11
+#include "Tags/FreeFareTagInternal.h"
12
 
12
 
13
 namespace LibNfc
13
 namespace LibNfc
14
 {
14
 {

+ 0
- 53
libnfc_cpptools/src/freefare/FreeFareTagInternal.h View File

1
-//
2
-// Created by robin on 6/19/16.
3
-//
4
-
5
-#ifndef LIBNFC_CPPTOOLS_FREEFARETAG_H
6
-#define LIBNFC_CPPTOOLS_FREEFARETAG_H
7
-
8
-#include <freefare.h>
9
-#include <string>
10
-#include "libnfc_cpptools/Result.h"
11
-
12
-namespace LibNfc
13
-{
14
-namespace FreeFare
15
-{
16
-
17
-class FreeFareTagInternal
18
-{
19
-public:
20
-
21
-    explicit FreeFareTagInternal(FreefareTag tag);
22
-    ~FreeFareTagInternal();
23
-
24
-    LibNfc::Utils::ResultBool authenticate(int sector, std::string key, int keyType);
25
-
26
-    LibNfc::Utils::ResultString readBlock(int sector, int block, std::string key, int keyType);
27
-
28
-    LibNfc::Utils::ResultBool writeBlock(int sector, int block, std::string key, int keyType, const std::string& data);
29
-
30
-    int getFirstBlock(int sector) const;
31
-
32
-    int getLastBlock(int sector) const;
33
-
34
-    int getSectorBlockCount(int sector);
35
-
36
-    const freefare_tag * getTag() const;
37
-
38
-    freefare_tag_type getType() const;
39
-
40
-    const std::string & getUid() const;
41
-
42
-private:
43
-    FreefareTag _tag;
44
-
45
-    freefare_tag_type _type;
46
-
47
-    std::string _uid;
48
-};
49
-
50
-}; // FreeFare
51
-}; // LibNfc
52
-
53
-#endif //LIBNFC_CPPTOOLS_FREEFARETAG_H

libnfc_cpptools/src/freefare/FreeFareAccessBits.cpp → libnfc_cpptools/src/freefare/Tags/Classic/FreeFareClassicAccessBits.cpp View File

4
 
4
 
5
 #include <cstring>
5
 #include <cstring>
6
 #include <iostream>
6
 #include <iostream>
7
-#include "libnfc_cpptools/FreeFareAccessBits.h"
7
+#include "libnfc_cpptools/FreeFareClassicAccessBits.h"
8
 #include "libnfc_cpptools/StringUtils.h"
8
 #include "libnfc_cpptools/StringUtils.h"
9
 #include "libnfc_cpptools/ArrayUtils.h"
9
 #include "libnfc_cpptools/ArrayUtils.h"
10
 
10
 
13
 namespace FreeFare
13
 namespace FreeFare
14
 {
14
 {
15
 
15
 
16
-const char FreeFareAccessBits::nonInvertedBitPosition[4][4] = {
16
+const char FreeFareClassicAccessBits::nonInvertedBitPosition[4][4] = {
17
         {0,  0,  0,  0 },
17
         {0,  0,  0,  0 },
18
         {11, 10, 9,  8 },
18
         {11, 10, 9,  8 },
19
         {23, 22, 21, 20},
19
         {23, 22, 21, 20},
20
         {19, 18, 17, 16}};
20
         {19, 18, 17, 16}};
21
 
21
 
22
-const char FreeFareAccessBits::invertedBitPosition[4][4] = {
22
+const char FreeFareClassicAccessBits::invertedBitPosition[4][4] = {
23
         {0,  0,  0,  0 },
23
         {0,  0,  0,  0 },
24
         {7,  6,  5,  4 },
24
         {7,  6,  5,  4 },
25
         {3,  2,  1,  0},
25
         {3,  2,  1,  0},
26
         {15, 14, 13, 12}};
26
         {15, 14, 13, 12}};
27
 
27
 
28
-FreeFareAccessBits::FreeFareAccessBits()
28
+FreeFareClassicAccessBits::FreeFareClassicAccessBits()
29
     : _bits("\xff\x0f\00\x00", 4)
29
     : _bits("\xff\x0f\00\x00", 4)
30
 {
30
 {
31
 }
31
 }
32
 
32
 
33
-FreeFareAccessBits::FreeFareAccessBits(const std::string &bits)
33
+FreeFareClassicAccessBits::FreeFareClassicAccessBits(const std::string &bits)
34
     : _bits(LibNfc::Utils::StringUtils::ensureSize(bits, 4))
34
     : _bits(LibNfc::Utils::StringUtils::ensureSize(bits, 4))
35
 {
35
 {
36
 }
36
 }
37
 
37
 
38
-char FreeFareAccessBits::getUserData() const
38
+char FreeFareClassicAccessBits::getUserData() const
39
 {
39
 {
40
     return _bits[_bits.length() - 1];
40
     return _bits[_bits.length() - 1];
41
 }
41
 }
42
 
42
 
43
-void FreeFareAccessBits::setUserData(const char &data)
43
+void FreeFareClassicAccessBits::setUserData(const char &data)
44
 {
44
 {
45
     _bits[_bits.length() - 1] = data;
45
     _bits[_bits.length() - 1] = data;
46
 }
46
 }
47
 
47
 
48
-void FreeFareAccessBits::setBit(int i, int j, const bool& value)
48
+void FreeFareClassicAccessBits::setBit(int i, int j, const bool& value)
49
 {
49
 {
50
     char buf[_bits.length()];
50
     char buf[_bits.length()];
51
     memcpy(buf, _bits.c_str(), _bits.length());
51
     memcpy(buf, _bits.c_str(), _bits.length());
56
     _bits = std::string(buf, _bits.length());
56
     _bits = std::string(buf, _bits.length());
57
 }
57
 }
58
 
58
 
59
-bool FreeFareAccessBits::getBit(int i, int j) const
59
+bool FreeFareClassicAccessBits::getBit(int i, int j) const
60
 {
60
 {
61
     const char* buf = _bits.c_str();
61
     const char* buf = _bits.c_str();
62
     return LibNfc::Utils::ArrayUtils::getArrayBit(buf, nonInvertedBitPosition[i][j]) && !LibNfc::Utils::ArrayUtils::getArrayBit(buf, invertedBitPosition[i][j]);
62
     return LibNfc::Utils::ArrayUtils::getArrayBit(buf, nonInvertedBitPosition[i][j]) && !LibNfc::Utils::ArrayUtils::getArrayBit(buf, invertedBitPosition[i][j]);
63
 }
63
 }
64
 
64
 
65
-std::string FreeFareAccessBits::getBits() const
65
+std::string FreeFareClassicAccessBits::getBits() const
66
 {
66
 {
67
     return _bits;
67
     return _bits;
68
 }
68
 }
69
 
69
 
70
-bool FreeFareAccessBits::canKeyAReadBlock(int block) const
70
+bool FreeFareClassicAccessBits::canKeyAReadBlock(int block) const
71
 {
71
 {
72
     bool c1 = getBit(1, block);
72
     bool c1 = getBit(1, block);
73
     bool c2 = getBit(2, block);
73
     bool c2 = getBit(2, block);
75
     return !c3 || (!c1 && !c2 && c3);
75
     return !c3 || (!c1 && !c2 && c3);
76
 }
76
 }
77
 
77
 
78
-bool FreeFareAccessBits::canKeyBReadBlock(int block) const
78
+bool FreeFareClassicAccessBits::canKeyBReadBlock(int block) const
79
 {
79
 {
80
     bool c1 = getBit(1, block);
80
     bool c1 = getBit(1, block);
81
     bool c2 = getBit(2, block);
81
     bool c2 = getBit(2, block);
83
     return !c1 || !c2 || !c3;
83
     return !c1 || !c2 || !c3;
84
 }
84
 }
85
 
85
 
86
-bool FreeFareAccessBits::canKeyAWriteBlock(int block) const
86
+bool FreeFareClassicAccessBits::canKeyAWriteBlock(int block) const
87
 {
87
 {
88
     bool c1 = getBit(1, block);
88
     bool c1 = getBit(1, block);
89
     bool c2 = getBit(2, block);
89
     bool c2 = getBit(2, block);
91
     return !c1 && !c2 && !c3;
91
     return !c1 && !c2 && !c3;
92
 }
92
 }
93
 
93
 
94
-bool FreeFareAccessBits::canKeyBWriteBlock(int block) const
94
+bool FreeFareClassicAccessBits::canKeyBWriteBlock(int block) const
95
 {
95
 {
96
     bool c1 = getBit(1, block);
96
     bool c1 = getBit(1, block);
97
     bool c2 = getBit(2, block);
97
     bool c2 = getBit(2, block);
99
     return (!c2 && !c3) || (c1 && !c3) || (!c1 && c2 && c3);
99
     return (!c2 && !c3) || (c1 && !c3) || (!c1 && c2 && c3);
100
 }
100
 }
101
 
101
 
102
-bool FreeFareAccessBits::canKeyAIncrementBlock(int block) const
102
+bool FreeFareClassicAccessBits::canKeyAIncrementBlock(int block) const
103
 {
103
 {
104
     bool c1 = getBit(1, block);
104
     bool c1 = getBit(1, block);
105
     bool c2 = getBit(2, block);
105
     bool c2 = getBit(2, block);
107
     return !c1 && !c2 && !c3;
107
     return !c1 && !c2 && !c3;
108
 }
108
 }
109
 
109
 
110
-bool FreeFareAccessBits::canKeyBIncrementBlock(int block) const
110
+bool FreeFareClassicAccessBits::canKeyBIncrementBlock(int block) const
111
 {
111
 {
112
     bool c1 = getBit(1, block);
112
     bool c1 = getBit(1, block);
113
     bool c2 = getBit(2, block);
113
     bool c2 = getBit(2, block);
115
     return (!c1 && !c2 && !c3) || (c1 && c2 && !c3);
115
     return (!c1 && !c2 && !c3) || (c1 && c2 && !c3);
116
 }
116
 }
117
 
117
 
118
-bool FreeFareAccessBits::canKeyADecrementBlock(int block) const
118
+bool FreeFareClassicAccessBits::canKeyADecrementBlock(int block) const
119
 {
119
 {
120
     bool c1 = getBit(1, block);
120
     bool c1 = getBit(1, block);
121
     bool c2 = getBit(2, block);
121
     bool c2 = getBit(2, block);
123
     return (!c1 && !c2) || (c1 && c2 && !c3);
123
     return (!c1 && !c2) || (c1 && c2 && !c3);
124
 }
124
 }
125
 
125
 
126
-bool FreeFareAccessBits::canKeyBDecrementBlock(int block) const
126
+bool FreeFareClassicAccessBits::canKeyBDecrementBlock(int block) const
127
 {
127
 {
128
     bool c1 = getBit(1, block);
128
     bool c1 = getBit(1, block);
129
     bool c2 = getBit(2, block);
129
     bool c2 = getBit(2, block);
131
     return (!c1 && !c2) || (c1 && c2 && !c3);
131
     return (!c1 && !c2) || (c1 && c2 && !c3);
132
 }
132
 }
133
 
133
 
134
-bool FreeFareAccessBits::canKeyAReadKeyATrailer() const
134
+bool FreeFareClassicAccessBits::canKeyAReadKeyATrailer() const
135
 {
135
 {
136
     return false;
136
     return false;
137
 }
137
 }
138
 
138
 
139
-bool FreeFareAccessBits::canKeyBReadKeyATrailer() const
139
+bool FreeFareClassicAccessBits::canKeyBReadKeyATrailer() const
140
 {
140
 {
141
     return false;
141
     return false;
142
 }
142
 }
143
 
143
 
144
-bool FreeFareAccessBits::canKeyAWriteKeyATrailer() const
144
+bool FreeFareClassicAccessBits::canKeyAWriteKeyATrailer() const
145
 {
145
 {
146
     bool c1 = getBit(1, 3);
146
     bool c1 = getBit(1, 3);
147
     bool c2 = getBit(2, 3);
147
     bool c2 = getBit(2, 3);
148
     return !c1 && !c2;
148
     return !c1 && !c2;
149
 }
149
 }
150
 
150
 
151
-bool FreeFareAccessBits::canKeyBWriteKeyATrailer() const
151
+bool FreeFareClassicAccessBits::canKeyBWriteKeyATrailer() const
152
 {
152
 {
153
     bool c1 = getBit(1, 3);
153
     bool c1 = getBit(1, 3);
154
     bool c2 = getBit(2, 3);
154
     bool c2 = getBit(2, 3);
156
     return (!c1 && c2 && c3) || (c1 && !c2 && !c3);
156
     return (!c1 && c2 && c3) || (c1 && !c2 && !c3);
157
 }
157
 }
158
 
158
 
159
-bool FreeFareAccessBits::canKeyAReadAccessBitsTrailer() const
159
+bool FreeFareClassicAccessBits::canKeyAReadAccessBitsTrailer() const
160
 {
160
 {
161
     return true;
161
     return true;
162
 }
162
 }
163
 
163
 
164
-bool FreeFareAccessBits::canKeyBReadAccessBitsTrailer() const
164
+bool FreeFareClassicAccessBits::canKeyBReadAccessBitsTrailer() const
165
 {
165
 {
166
     bool c1 = getBit(1, 3);
166
     bool c1 = getBit(1, 3);
167
     bool c2 = getBit(2, 3);
167
     bool c2 = getBit(2, 3);
169
     return c1 || (c2 && c3);
169
     return c1 || (c2 && c3);
170
 }
170
 }
171
 
171
 
172
-bool FreeFareAccessBits::canKeyAWriteAccessBitsTrailer() const
172
+bool FreeFareClassicAccessBits::canKeyAWriteAccessBitsTrailer() const
173
 {
173
 {
174
     bool c1 = getBit(1, 3);
174
     bool c1 = getBit(1, 3);
175
     bool c2 = getBit(2, 3);
175
     bool c2 = getBit(2, 3);
177
     return !c1 && !c2 && c3;
177
     return !c1 && !c2 && c3;
178
 }
178
 }
179
 
179
 
180
-bool FreeFareAccessBits::canKeyBWriteAccessBitsTrailer() const
180
+bool FreeFareClassicAccessBits::canKeyBWriteAccessBitsTrailer() const
181
 {
181
 {
182
     bool c1 = getBit(1, 3);
182
     bool c1 = getBit(1, 3);
183
     bool c2 = getBit(2, 3);
183
     bool c2 = getBit(2, 3);
185
     return (!c1 && c2 && c3) || (c1 && !c2 && c3);
185
     return (!c1 && c2 && c3) || (c1 && !c2 && c3);
186
 }
186
 }
187
 
187
 
188
-bool FreeFareAccessBits::canKeyAReadKeyBTrailer() const
188
+bool FreeFareClassicAccessBits::canKeyAReadKeyBTrailer() const
189
 {
189
 {
190
     bool c1 = getBit(1, 3);
190
     bool c1 = getBit(1, 3);
191
     bool c2 = getBit(2, 3);
191
     bool c2 = getBit(2, 3);
193
     return (!c1 && !c2) || (!c1 && !c3);
193
     return (!c1 && !c2) || (!c1 && !c3);
194
 }
194
 }
195
 
195
 
196
-bool FreeFareAccessBits::canKeyBReadKeyBTrailer() const
196
+bool FreeFareClassicAccessBits::canKeyBReadKeyBTrailer() const
197
 {
197
 {
198
     return false;
198
     return false;
199
 }
199
 }
200
 
200
 
201
-bool FreeFareAccessBits::canKeyAWriteKeyBTrailer() const
201
+bool FreeFareClassicAccessBits::canKeyAWriteKeyBTrailer() const
202
 {
202
 {
203
     bool c1 = getBit(1, 3);
203
     bool c1 = getBit(1, 3);
204
     bool c2 = getBit(2, 3);
204
     bool c2 = getBit(2, 3);
205
     return !c1 && !c2;
205
     return !c1 && !c2;
206
 }
206
 }
207
 
207
 
208
-bool FreeFareAccessBits::canKeyBWriteKeyBTrailer() const
208
+bool FreeFareClassicAccessBits::canKeyBWriteKeyBTrailer() const
209
 {
209
 {
210
     bool c1 = getBit(1, 3);
210
     bool c1 = getBit(1, 3);
211
     bool c2 = getBit(2, 3);
211
     bool c2 = getBit(2, 3);

libnfc_cpptools/src/freefare/FreeFareSector.cpp → libnfc_cpptools/src/freefare/Tags/Classic/FreeFareClassicSector.cpp View File

3
 //
3
 //
4
 
4
 
5
 #include "libnfc_cpptools/StringUtils.h"
5
 #include "libnfc_cpptools/StringUtils.h"
6
-#include "libnfc_cpptools/FreeFareSector.h"
6
+#include "libnfc_cpptools/FreeFareClassicSector.h"
7
 
7
 
8
 namespace LibNfc
8
 namespace LibNfc
9
 {
9
 {
10
 namespace FreeFare
10
 namespace FreeFare
11
 {
11
 {
12
 
12
 
13
-FreeFareSector::FreeFareSector(const std::string &data)
13
+FreeFareClassicSector::FreeFareClassicSector(const std::string &data)
14
 {
14
 {
15
     std::string d = LibNfc::Utils::StringUtils::ensureSize(data, 64);
15
     std::string d = LibNfc::Utils::StringUtils::ensureSize(data, 64);
16
     for (unsigned int i = 0; i < 4; ++i) {
16
     for (unsigned int i = 0; i < 4; ++i) {
19
     }
19
     }
20
 }
20
 }
21
 
21
 
22
-const std::string &FreeFareSector::getBlock(int block) const
22
+const std::string &FreeFareClassicSector::getBlock(int block) const
23
 {
23
 {
24
     return _blocks[block];
24
     return _blocks[block];
25
 }
25
 }
26
 
26
 
27
-std::string FreeFareSector::getKeyA() const
27
+std::string FreeFareClassicSector::getKeyA() const
28
 {
28
 {
29
     return _blocks[3].substr(0, 6);
29
     return _blocks[3].substr(0, 6);
30
 }
30
 }
31
 
31
 
32
-std::string FreeFareSector::getKeyB() const
32
+std::string FreeFareClassicSector::getKeyB() const
33
 {
33
 {
34
     return _blocks[3].substr(10, 6);
34
     return _blocks[3].substr(10, 6);
35
 }
35
 }
36
 
36
 
37
-std::string FreeFareSector::getAccessBits() const
37
+std::string FreeFareClassicSector::getAccessBits() const
38
 {
38
 {
39
     return _blocks[3].substr(6, 4);
39
     return _blocks[3].substr(6, 4);
40
 }
40
 }
41
 
41
 
42
-FreeFareAccessBits FreeFareSector::getAccessBitsDbo() const
42
+FreeFareClassicAccessBits FreeFareClassicSector::getAccessBitsDbo() const
43
 {
43
 {
44
-    return FreeFareAccessBits(getAccessBits());
44
+    return FreeFareClassicAccessBits(getAccessBits());
45
 }
45
 }
46
 
46
 
47
-void FreeFareSector::setBlock(int block, const std::string &data)
47
+void FreeFareClassicSector::setBlock(int block, const std::string &data)
48
 {
48
 {
49
     std::string d = LibNfc::Utils::StringUtils::ensureSize(data, 16);
49
     std::string d = LibNfc::Utils::StringUtils::ensureSize(data, 16);
50
     if (block == 3) {
50
     if (block == 3) {
58
     }
58
     }
59
 }
59
 }
60
 
60
 
61
-void FreeFareSector::setKeyA(const std::string &key)
61
+void FreeFareClassicSector::setKeyA(const std::string &key)
62
 {
62
 {
63
     std::string k = LibNfc::Utils::StringUtils::ensureSize(key, 6);
63
     std::string k = LibNfc::Utils::StringUtils::ensureSize(key, 6);
64
     for (int i = 0; i < k.size(); ++i) {
64
     for (int i = 0; i < k.size(); ++i) {
67
     _hasKeyA = !key.empty();
67
     _hasKeyA = !key.empty();
68
 }
68
 }
69
 
69
 
70
-void FreeFareSector::setKeyB(const std::string &key)
70
+void FreeFareClassicSector::setKeyB(const std::string &key)
71
 {
71
 {
72
     std::string k = LibNfc::Utils::StringUtils::ensureSize(key, 6);
72
     std::string k = LibNfc::Utils::StringUtils::ensureSize(key, 6);
73
     for (int i = 0; i < k.size(); ++i) {
73
     for (int i = 0; i < k.size(); ++i) {
76
     _hasKeyB = !key.empty();
76
     _hasKeyB = !key.empty();
77
 }
77
 }
78
 
78
 
79
-void FreeFareSector::setAccessBits(const std::string &accessBits)
79
+void FreeFareClassicSector::setAccessBits(const std::string &accessBits)
80
 {
80
 {
81
     std::string a = LibNfc::Utils::StringUtils::ensureSize(accessBits, 4);
81
     std::string a = LibNfc::Utils::StringUtils::ensureSize(accessBits, 4);
82
     for (int i = 0; i < a.size(); ++i) {
82
     for (int i = 0; i < a.size(); ++i) {
85
     _hasAccessBits = !accessBits.empty();
85
     _hasAccessBits = !accessBits.empty();
86
 }
86
 }
87
 
87
 
88
-void FreeFareSector::setAccessBits(const FreeFareAccessBits &accessBits)
88
+void FreeFareClassicSector::setAccessBits(const FreeFareClassicAccessBits &accessBits)
89
 {
89
 {
90
     setAccessBits(accessBits.getBits());
90
     setAccessBits(accessBits.getBits());
91
 }
91
 }
92
 
92
 
93
-bool FreeFareSector::hasBlock(int block) const
93
+bool FreeFareClassicSector::hasBlock(int block) const
94
 {
94
 {
95
     if (block == 3) {
95
     if (block == 3) {
96
         return _hasKeyA && _hasKeyB && _hasAccessBits;
96
         return _hasKeyA && _hasKeyB && _hasAccessBits;
98
     return _haveBlocks[block];
98
     return _haveBlocks[block];
99
 }
99
 }
100
 
100
 
101
-bool FreeFareSector::hasKeyA() const
101
+bool FreeFareClassicSector::hasKeyA() const
102
 {
102
 {
103
     return _hasKeyA;
103
     return _hasKeyA;
104
 }
104
 }
105
 
105
 
106
-bool FreeFareSector::hasKeyB() const
106
+bool FreeFareClassicSector::hasKeyB() const
107
 {
107
 {
108
     return _hasKeyB;
108
     return _hasKeyB;
109
 }
109
 }
110
 
110
 
111
-bool FreeFareSector::hasAccessBits() const
111
+bool FreeFareClassicSector::hasAccessBits() const
112
 {
112
 {
113
     return _hasAccessBits;
113
     return _hasAccessBits;
114
 }
114
 }

libnfc_cpptools/src/freefare/FreeFareTag.cpp → libnfc_cpptools/src/freefare/Tags/Classic/FreeFareTagClassic.cpp View File

1
 //
1
 //
2
-// Created by robin on 7/22/16.
2
+// Created by robin on 10/8/17.
3
 //
3
 //
4
 
4
 
5
-#include "libnfc_cpptools/FreeFareTag.h"
6
-#include "libnfc_cpptools/StringUtils.h"
7
-#include "FreeFareTagInternal.h"
5
+#include <libnfc_cpptools/StringUtils.h>
6
+#include "libnfc_cpptools/FreeFareTagClassic.h"
7
+#include "FreeFareTagClassicInternal.h"
8
 
8
 
9
 namespace LibNfc
9
 namespace LibNfc
10
 {
10
 {
11
 namespace FreeFare
11
 namespace FreeFare
12
 {
12
 {
13
 
13
 
14
-std::string FreeFareTag::getTagTypeString(FreeFareTag::FreeFareTagType type)
14
+FreeFareTagClassic::FreeFareTagClassic(std::shared_ptr<FreeFareTagClassicInternal> tag)
15
+        : FreeFareTag(tag)
15
 {
16
 {
16
-    if (type == FreeFareTagType::FELICA)
17
-    {
18
-        return "FELICA";
19
-    }
20
-    if (type == FreeFareTagType::MIFARE_MINI)
21
-    {
22
-        return "MIFARE_MINI";
23
-    }
24
-    if (type == FreeFareTagType::MIFARE_CLASSIC_1K)
25
-    {
26
-        return "MIFARE_CLASSIC_1K";
27
-    }
28
-    if (type == FreeFareTagType::MIFARE_CLASSIC_4K)
29
-    {
30
-        return "MIFARE_CLASSIC_4K";
31
-    }
32
-    if (type == FreeFareTagType::MIFARE_DESFIRE)
33
-    {
34
-        return "MIFARE_DESFIRE";
35
-    }
36
-    if (type == FreeFareTagType::MIFARE_ULTRALIGHT)
37
-    {
38
-        return "MIFARE_ULTRALIGHT";
39
-    }
40
-    if (type == FreeFareTagType::MIFARE_ULTRALIGHT_C)
41
-    {
42
-        return "MIFARE_ULTRALIGHT_C";
43
-    }
44
-    return "UNKNOWN";
45
 }
17
 }
46
 
18
 
47
-FreeFareTag::FreeFareTag(std::shared_ptr<FreeFareTagInternal> tag)
48
-    : _tag(tag)
19
+LibNfc::Utils::ResultBool FreeFareTagClassic::authenticate(int sector, const std::string& key, int keyType)
49
 {
20
 {
21
+    return std::static_pointer_cast<FreeFareTagClassicInternal>(_tag)->authenticate(sector, key, keyType);
50
 }
22
 }
51
 
23
 
52
-LibNfc::Utils::ResultBool FreeFareTag::authenticate(int sector, const std::string& key, int keyType)
53
-{
54
-    return _tag->authenticate(sector, key, keyType);
55
-}
56
-
57
-LibNfc::Utils::Result<MappedKeys> FreeFareTag::mapKeys(const std::vector<std::string>& keys, std::function<void(int, int)> cb)
24
+LibNfc::Utils::Result<MappedKeys> FreeFareTagClassic::mapKeys(const std::vector<std::string>& keys, std::function<void(int, int)> cb)
58
 {
25
 {
59
     MappedKeys mappedKeys;
26
     MappedKeys mappedKeys;
60
     unsigned long done = 0;
27
     unsigned long done = 0;
86
     return LibNfc::Utils::Result<MappedKeys>::ok(mappedKeys);
53
     return LibNfc::Utils::Result<MappedKeys>::ok(mappedKeys);
87
 }
54
 }
88
 
55
 
89
-LibNfc::Utils::ResultString FreeFareTag::readBlock(int sector, int block, const std::string& key, int keyType)
56
+LibNfc::Utils::ResultString FreeFareTagClassic::readBlock(int sector, int block, const std::string& key, int keyType)
90
 {
57
 {
91
-    return _tag->readBlock(sector, block, key, keyType);
58
+    return std::static_pointer_cast<FreeFareTagClassicInternal>(_tag)->readBlock(sector, block, key, keyType);
92
 }
59
 }
93
 
60
 
94
-LibNfc::Utils::Result<FreeFareSector> FreeFareTag::readSector(int sector, const std::string& key, int keyType)
61
+LibNfc::Utils::Result<FreeFareClassicSector> FreeFareTagClassic::readSector(int sector, const std::string& key, int keyType)
95
 {
62
 {
96
     std::string res;
63
     std::string res;
97
-    int lastBlock = _tag->getSectorBlockCount(sector);
64
+    int lastBlock = std::static_pointer_cast<FreeFareTagClassicInternal>(_tag)->getSectorBlockCount(sector);
98
     for (int i = 0; i < lastBlock; ++i) {
65
     for (int i = 0; i < lastBlock; ++i) {
99
         auto data = readBlock(sector, i, key, keyType);
66
         auto data = readBlock(sector, i, key, keyType);
100
         if (data) {
67
         if (data) {
101
             res += data.getData();
68
             res += data.getData();
102
         }
69
         }
103
         else {
70
         else {
104
-            return LibNfc::Utils::Result<FreeFareSector>::error(data);
71
+            return LibNfc::Utils::Result<FreeFareClassicSector>::error(data);
105
         }
72
         }
106
     }
73
     }
107
-    return LibNfc::Utils::Result<FreeFareSector>::ok(FreeFareSector(res));
74
+    return LibNfc::Utils::Result<FreeFareClassicSector>::ok(FreeFareClassicSector(res));
108
 }
75
 }
109
 
76
 
110
-LibNfc::Utils::Result<std::vector<FreeFareSector>> FreeFareTag::read(const MappedKeys& keys, std::function<void(int, int)> cb)
77
+LibNfc::Utils::Result<std::vector<FreeFareClassicSector>> FreeFareTagClassic::read(const MappedKeys& keys, std::function<void(int, int)> cb)
111
 {
78
 {
112
     if (keys.size() != 16) {
79
     if (keys.size() != 16) {
113
-        return LibNfc::Utils::Result<std::vector<FreeFareSector>>::error("Must have 16 sectors keys");
80
+        return LibNfc::Utils::Result<std::vector<FreeFareClassicSector>>::error("Must have 16 sectors keys");
114
     }
81
     }
115
     int done = 0;
82
     int done = 0;
116
     int total = 4 * keys.size();
83
     int total = 4 * keys.size();
117
-    std::vector<FreeFareSector> sectors;
84
+    std::vector<FreeFareClassicSector> sectors;
118
     for (int s = 0; s < keys.size(); ++s) {
85
     for (int s = 0; s < keys.size(); ++s) {
119
         auto sectorKey = keys[s];
86
         auto sectorKey = keys[s];
120
-        FreeFareSector sector;
87
+        FreeFareClassicSector sector;
121
         bool keyA = false;
88
         bool keyA = false;
122
         bool keyB = false;
89
         bool keyB = false;
123
         for (int b = 0; b < 3; ++b) {
90
         for (int b = 0; b < 3; ++b) {
165
         }
132
         }
166
 
133
 
167
         sector.setBlock(b, dataA);
134
         sector.setBlock(b, dataA);
168
-        FreeFareAccessBits accessBitsDboA = sector.getAccessBitsDbo();
135
+        FreeFareClassicAccessBits accessBitsDboA = sector.getAccessBitsDbo();
169
         sector.setBlock(b, dataB);
136
         sector.setBlock(b, dataB);
170
-        FreeFareAccessBits accessBitsDboB = sector.getAccessBitsDbo();
137
+        FreeFareClassicAccessBits accessBitsDboB = sector.getAccessBitsDbo();
171
         sector.setKeyA(keyA ? sectorKey.first : "");
138
         sector.setKeyA(keyA ? sectorKey.first : "");
172
         sector.setKeyB(keyB ? sectorKey.second : "");
139
         sector.setKeyB(keyB ? sectorKey.second : "");
173
 
140
 
186
         cb(total, total);
153
         cb(total, total);
187
     }
154
     }
188
 
155
 
189
-    return LibNfc::Utils::Result<std::vector<FreeFareSector>>::ok(sectors);
156
+    return LibNfc::Utils::Result<std::vector<FreeFareClassicSector>>::ok(sectors);
190
 }
157
 }
191
 
158
 
192
-LibNfc::Utils::Result<std::vector<FreeFareSector>> FreeFareTag::read(const std::vector<std::string>& keys,
159
+LibNfc::Utils::Result<std::vector<FreeFareClassicSector>> FreeFareTagClassic::read(const std::vector<std::string>& keys,
193
                                                                      std::function<void(int, int)> mapCb,
160
                                                                      std::function<void(int, int)> mapCb,
194
                                                                      std::function<void(int, int)> readCb)
161
                                                                      std::function<void(int, int)> readCb)
195
 {
162
 {
196
     auto mappedKeysResult = mapKeys(keys, mapCb);
163
     auto mappedKeysResult = mapKeys(keys, mapCb);
197
     if (!mappedKeysResult) {
164
     if (!mappedKeysResult) {
198
-        return LibNfc::Utils::Result<std::vector<FreeFareSector>>::error(mappedKeysResult);
165
+        return LibNfc::Utils::Result<std::vector<FreeFareClassicSector>>::error(mappedKeysResult);
199
     }
166
     }
200
     return read(mappedKeysResult.getData(), readCb);
167
     return read(mappedKeysResult.getData(), readCb);
201
 }
168
 }
202
 
169
 
203
-LibNfc::Utils::ResultBool FreeFareTag::writeBlock(int sector, int block, const std::string& key, int keyType, const std::string& data)
170
+LibNfc::Utils::ResultBool FreeFareTagClassic::writeBlock(int sector, int block, const std::string& key, int keyType, const std::string& data)
204
 {
171
 {
205
-    return _tag->writeBlock(sector, block, key, keyType, LibNfc::Utils::StringUtils::ensureSize(data, 16));
172
+    return std::static_pointer_cast<FreeFareTagClassicInternal>(_tag)->writeBlock(sector, block, key, keyType, LibNfc::Utils::StringUtils::ensureSize(data, 16));
206
 }
173
 }
207
 
174
 
208
-LibNfc::Utils::ResultBool FreeFareTag::writeSector(int sector, const std::string& key, int keyType, const std::string& data)
175
+LibNfc::Utils::ResultBool FreeFareTagClassic::writeSector(int sector, const std::string& key, int keyType, const std::string& data)
209
 {
176
 {
210
     std::string d = LibNfc::Utils::StringUtils::ensureSize(data, 64);
177
     std::string d = LibNfc::Utils::StringUtils::ensureSize(data, 64);
211
     std::string errors;
178
     std::string errors;
222
     return LibNfc::Utils::ResultBool::error(errors);
189
     return LibNfc::Utils::ResultBool::error(errors);
223
 }
190
 }
224
 
191
 
225
-LibNfc::Utils::ResultBool FreeFareTag::write(const MappedKeys& keys, const std::string& data, bool writeSector0, std::function<void(int, int)> cb)
192
+LibNfc::Utils::ResultBool FreeFareTagClassic::write(const MappedKeys& keys,
193
+                                             const std::string& data,
194
+                                             bool writeSector0,
195
+                                             std::function<void(int, int)> cb)
226
 {
196
 {
227
     if (keys.size() != 16) {
197
     if (keys.size() != 16) {
228
         return LibNfc::Utils::ResultBool::error("Must have 16 sectors keys");
198
         return LibNfc::Utils::ResultBool::error("Must have 16 sectors keys");
278
     return LibNfc::Utils::ResultBool::error(errors);
248
     return LibNfc::Utils::ResultBool::error(errors);
279
 }
249
 }
280
 
250
 
281
-LibNfc::Utils::ResultBool FreeFareTag::write(const std::vector<std::string>& keys, const std::string& data, bool writeSector0,
282
-                                      std::function<void(int, int)> mapCb, std::function<void(int, int)> writeCb)
251
+LibNfc::Utils::ResultBool FreeFareTagClassic::write(const std::vector<std::string>& keys, const std::string& data, bool writeSector0,
252
+                                             std::function<void(int, int)> mapCb, std::function<void(int, int)> writeCb)
283
 {
253
 {
284
     auto mappedKeysResult = mapKeys(keys, mapCb);
254
     auto mappedKeysResult = mapKeys(keys, mapCb);
285
     if (!mappedKeysResult) {
255
     if (!mappedKeysResult) {
288
     return write(mappedKeysResult.getData(), data, writeSector0, writeCb);
258
     return write(mappedKeysResult.getData(), data, writeSector0, writeCb);
289
 }
259
 }
290
 
260
 
291
-const std::string &FreeFareTag::getUid() const
292
-{
293
-    return _tag->getUid();
294
-}
295
-
296
-FreeFareTag::FreeFareTagType FreeFareTag::getType() const
297
-{
298
-    auto type = _tag->getType();
299
-    if (type == freefare_tag_type::FELICA)
300
-    {
301
-        return FreeFareTagType::FELICA;
302
-    }
303
-    if (type == freefare_tag_type::MIFARE_MINI)
304
-    {
305
-        return FreeFareTagType::MIFARE_MINI;
306
-    }
307
-    if (type == freefare_tag_type::MIFARE_CLASSIC_1K)
308
-    {
309
-        return FreeFareTagType::MIFARE_CLASSIC_1K;
310
-    }
311
-    if (type == freefare_tag_type::MIFARE_CLASSIC_4K)
312
-    {
313
-        return FreeFareTagType::MIFARE_CLASSIC_4K;
314
-    }
315
-    if (type == freefare_tag_type::MIFARE_DESFIRE)
316
-    {
317
-        return FreeFareTagType::MIFARE_DESFIRE;
318
-    }
319
-    if (type == freefare_tag_type::MIFARE_ULTRALIGHT)
320
-    {
321
-        return FreeFareTagType::MIFARE_ULTRALIGHT;
322
-    }
323
-    if (type == freefare_tag_type::MIFARE_ULTRALIGHT_C)
324
-    {
325
-        return FreeFareTagType::MIFARE_ULTRALIGHT_C;
326
-    }
327
-    return FreeFareTagType::UNKNOWN;
328
-}
329
-
330
-std::shared_ptr<FreeFareTagInternal> FreeFareTag::getTag() const
331
-{
332
-    return _tag;
333
-}
334
-
335
 }; // FreeFare
261
 }; // FreeFare
336
-}; // LibNfc
262
+}; // LibNfc

libnfc_cpptools/src/freefare/FreeFareTagInternal.cpp → libnfc_cpptools/src/freefare/Tags/Classic/FreeFareTagClassicInternal.cpp View File

1
 //
1
 //
2
-// Created by robin on 6/19/16.
2
+// Created by robin on 10/8/17.
3
 //
3
 //
4
 
4
 
5
-#include <sstream>
6
-#include <map>
7
-#include "FreeFareTagInternal.h"
5
+#include "FreeFareTagClassicInternal.h"
8
 
6
 
9
 namespace LibNfc
7
 namespace LibNfc
10
 {
8
 {
11
 namespace FreeFare
9
 namespace FreeFare
12
 {
10
 {
13
 
11
 
14
-FreeFareTagInternal::FreeFareTagInternal(FreefareTag tag)
15
-    : _tag(tag)
12
+FreeFareTagClassicInternal::FreeFareTagClassicInternal(FreefareTag tag)
13
+        : FreeFareTagInternal(tag)
16
 {
14
 {
17
-    _type = freefare_get_tag_type(tag);
18
-    _uid = freefare_get_tag_uid(tag);
19
 }
15
 }
20
 
16
 
21
-FreeFareTagInternal::~FreeFareTagInternal()
22
-{
23
-    freefare_free_tag(_tag);
24
-}
25
-
26
-LibNfc::Utils::ResultBool FreeFareTagInternal::authenticate(int sector, std::string key, int keyType)
17
+LibNfc::Utils::ResultBool FreeFareTagClassicInternal::authenticate(int sector, std::string key, int keyType)
27
 {
18
 {
28
 
19
 
29
     if (mifare_classic_connect(_tag) != 0) {
20
     if (mifare_classic_connect(_tag) != 0) {
38
     return LibNfc::Utils::ResultBool::ok(true);
29
     return LibNfc::Utils::ResultBool::ok(true);
39
 }
30
 }
40
 
31
 
41
-LibNfc::Utils::ResultString FreeFareTagInternal::readBlock(int sector, int block, std::string key, int keyType)
32
+LibNfc::Utils::ResultString FreeFareTagClassicInternal::readBlock(int sector, int block, std::string key, int keyType)
42
 {
33
 {
43
     if (mifare_classic_connect(_tag) != 0) {
34
     if (mifare_classic_connect(_tag) != 0) {
44
         return LibNfc::Utils::ResultString::error("Failed to connect to MIFARE tag");
35
         return LibNfc::Utils::ResultString::error("Failed to connect to MIFARE tag");
57
     return LibNfc::Utils::ResultString::ok(std::string((const char*)data, sizeof(data)));
48
     return LibNfc::Utils::ResultString::ok(std::string((const char*)data, sizeof(data)));
58
 }
49
 }
59
 
50
 
60
-LibNfc::Utils::ResultBool FreeFareTagInternal::writeBlock(int sector, int block, std::string key, int keyType, const std::string &data)
51
+LibNfc::Utils::ResultBool FreeFareTagClassicInternal::writeBlock(int sector, int block, std::string key, int keyType, const std::string &data)
61
 {
52
 {
62
     if (mifare_classic_connect(_tag) != 0) {
53
     if (mifare_classic_connect(_tag) != 0) {
63
         return LibNfc::Utils::ResultBool::error("Failed to connect to MIFARE tag");
54
         return LibNfc::Utils::ResultBool::error("Failed to connect to MIFARE tag");
75
     return LibNfc::Utils::ResultBool::ok(true);
66
     return LibNfc::Utils::ResultBool::ok(true);
76
 }
67
 }
77
 
68
 
78
-const freefare_tag *FreeFareTagInternal::getTag() const
79
-{
80
-    return _tag;
81
-}
82
-
83
-int FreeFareTagInternal::getFirstBlock(int sector) const
69
+int FreeFareTagClassicInternal::getFirstBlock(int sector) const
84
 {
70
 {
85
     return mifare_classic_sector_first_block(sector);
71
     return mifare_classic_sector_first_block(sector);
86
 }
72
 }
87
 
73
 
88
-int FreeFareTagInternal::getLastBlock(int sector) const
74
+int FreeFareTagClassicInternal::getLastBlock(int sector) const
89
 {
75
 {
90
     return mifare_classic_sector_last_block(sector);
76
     return mifare_classic_sector_last_block(sector);
91
 }
77
 }
92
 
78
 
93
-int FreeFareTagInternal::getSectorBlockCount(int sector)
79
+int FreeFareTagClassicInternal::getSectorBlockCount(int sector)
94
 {
80
 {
95
     return mifare_classic_sector_block_count(sector);
81
     return mifare_classic_sector_block_count(sector);
96
 }
82
 }
97
-
98
-freefare_tag_type FreeFareTagInternal::getType() const
99
-{
100
-    return _type;
101
-}
102
-
103
-const std::string &FreeFareTagInternal::getUid() const
104
-{
105
-    return _uid;
106
-}
107
-
108
 }; // FreeFare
83
 }; // FreeFare
109
 }; // LibNfc
84
 }; // LibNfc

+ 37
- 0
libnfc_cpptools/src/freefare/Tags/Classic/FreeFareTagClassicInternal.h View File

1
+//
2
+// Created by robin on 10/8/17.
3
+//
4
+
5
+#ifndef NFC_CPPTOOLS_FREEFARETAGCLASSICINTERNAL_H
6
+#define NFC_CPPTOOLS_FREEFARETAGCLASSICINTERNAL_H
7
+
8
+#include "Tags/FreeFareTagInternal.h"
9
+
10
+namespace LibNfc
11
+{
12
+namespace FreeFare
13
+{
14
+
15
+class FreeFareTagClassicInternal : public FreeFareTagInternal
16
+{
17
+public:
18
+    explicit FreeFareTagClassicInternal(FreefareTag tag);
19
+    ~FreeFareTagClassicInternal() override = default;
20
+
21
+    LibNfc::Utils::ResultBool authenticate(int sector, std::string key, int keyType);
22
+
23
+    LibNfc::Utils::ResultString readBlock(int sector, int block, std::string key, int keyType);
24
+
25
+    LibNfc::Utils::ResultBool writeBlock(int sector, int block, std::string key, int keyType, const std::string& data);
26
+
27
+    int getFirstBlock(int sector) const;
28
+
29
+    int getLastBlock(int sector) const;
30
+
31
+    int getSectorBlockCount(int sector);
32
+};
33
+
34
+}; // FreeFare
35
+}; // LibNfc
36
+
37
+#endif //NFC_CPPTOOLS_FREEFARETAGCLASSICINTERNAL_H

+ 98
- 0
libnfc_cpptools/src/freefare/Tags/FreeFareTag.cpp View File

1
+//
2
+// Created by robin on 7/22/16.
3
+//
4
+
5
+#include "libnfc_cpptools/FreeFareTag.h"
6
+#include "libnfc_cpptools/StringUtils.h"
7
+#include "FreeFareTagInternal.h"
8
+
9
+namespace LibNfc
10
+{
11
+namespace FreeFare
12
+{
13
+
14
+std::string FreeFareTag::getTagTypeString(FreeFareTag::FreeFareTagType type)
15
+{
16
+    if (type == FreeFareTagType::FELICA)
17
+    {
18
+        return "FELICA";
19
+    }
20
+    if (type == FreeFareTagType::MIFARE_MINI)
21
+    {
22
+        return "MIFARE_MINI";
23
+    }
24
+    if (type == FreeFareTagType::MIFARE_CLASSIC_1K)
25
+    {
26
+        return "MIFARE_CLASSIC_1K";
27
+    }
28
+    if (type == FreeFareTagType::MIFARE_CLASSIC_4K)
29
+    {
30
+        return "MIFARE_CLASSIC_4K";
31
+    }
32
+    if (type == FreeFareTagType::MIFARE_DESFIRE)
33
+    {
34
+        return "MIFARE_DESFIRE";
35
+    }
36
+    if (type == FreeFareTagType::MIFARE_ULTRALIGHT)
37
+    {
38
+        return "MIFARE_ULTRALIGHT";
39
+    }
40
+    if (type == FreeFareTagType::MIFARE_ULTRALIGHT_C)
41
+    {
42
+        return "MIFARE_ULTRALIGHT_C";
43
+    }
44
+    return "UNKNOWN";
45
+}
46
+
47
+FreeFareTag::FreeFareTag(std::shared_ptr<FreeFareTagInternal> tag)
48
+    : _tag(tag)
49
+{
50
+}
51
+
52
+
53
+const std::string &FreeFareTag::getUid() const
54
+{
55
+    return _tag->getUid();
56
+}
57
+
58
+FreeFareTag::FreeFareTagType FreeFareTag::getType() const
59
+{
60
+    auto type = _tag->getType();
61
+    if (type == freefare_tag_type::FELICA)
62
+    {
63
+        return FreeFareTagType::FELICA;
64
+    }
65
+    if (type == freefare_tag_type::MIFARE_MINI)
66
+    {
67
+        return FreeFareTagType::MIFARE_MINI;
68
+    }
69
+    if (type == freefare_tag_type::MIFARE_CLASSIC_1K)
70
+    {
71
+        return FreeFareTagType::MIFARE_CLASSIC_1K;
72
+    }
73
+    if (type == freefare_tag_type::MIFARE_CLASSIC_4K)
74
+    {
75
+        return FreeFareTagType::MIFARE_CLASSIC_4K;
76
+    }
77
+    if (type == freefare_tag_type::MIFARE_DESFIRE)
78
+    {
79
+        return FreeFareTagType::MIFARE_DESFIRE;
80
+    }
81
+    if (type == freefare_tag_type::MIFARE_ULTRALIGHT)
82
+    {
83
+        return FreeFareTagType::MIFARE_ULTRALIGHT;
84
+    }
85
+    if (type == freefare_tag_type::MIFARE_ULTRALIGHT_C)
86
+    {
87
+        return FreeFareTagType::MIFARE_ULTRALIGHT_C;
88
+    }
89
+    return FreeFareTagType::UNKNOWN;
90
+}
91
+
92
+std::shared_ptr<FreeFareTagInternal> FreeFareTag::getTag() const
93
+{
94
+    return _tag;
95
+}
96
+
97
+}; // FreeFare
98
+}; // LibNfc

+ 42
- 0
libnfc_cpptools/src/freefare/Tags/FreeFareTagInternal.cpp View File

1
+//
2
+// Created by robin on 6/19/16.
3
+//
4
+
5
+#include <sstream>
6
+#include <map>
7
+#include "FreeFareTagInternal.h"
8
+
9
+namespace LibNfc
10
+{
11
+namespace FreeFare
12
+{
13
+
14
+FreeFareTagInternal::FreeFareTagInternal(FreefareTag tag)
15
+    : _tag(tag)
16
+    , _type(freefare_get_tag_type(tag))
17
+    , _uid(freefare_get_tag_uid(tag))
18
+{
19
+}
20
+
21
+FreeFareTagInternal::~FreeFareTagInternal()
22
+{
23
+    freefare_free_tag(_tag);
24
+}
25
+
26
+const freefare_tag *FreeFareTagInternal::getTag() const
27
+{
28
+    return _tag;
29
+}
30
+
31
+freefare_tag_type FreeFareTagInternal::getType() const
32
+{
33
+    return _type;
34
+}
35
+
36
+const std::string &FreeFareTagInternal::getUid() const
37
+{
38
+    return _uid;
39
+}
40
+
41
+}; // FreeFare
42
+}; // LibNfc

+ 41
- 0
libnfc_cpptools/src/freefare/Tags/FreeFareTagInternal.h View File

1
+//
2
+// Created by robin on 6/19/16.
3
+//
4
+
5
+#ifndef LIBNFC_CPPTOOLS_FREEFARETAG_H
6
+#define LIBNFC_CPPTOOLS_FREEFARETAG_H
7
+
8
+#include <freefare.h>
9
+#include <string>
10
+#include "libnfc_cpptools/Result.h"
11
+
12
+namespace LibNfc
13
+{
14
+namespace FreeFare
15
+{
16
+
17
+class FreeFareTagInternal
18
+{
19
+public:
20
+
21
+    explicit FreeFareTagInternal(FreefareTag tag);
22
+    virtual ~FreeFareTagInternal();
23
+
24
+    const freefare_tag * getTag() const;
25
+
26
+    freefare_tag_type getType() const;
27
+
28
+    const std::string & getUid() const;
29
+
30
+protected:
31
+    const FreefareTag _tag;
32
+
33
+    const freefare_tag_type _type;
34
+
35
+    const std::string _uid;
36
+};
37
+
38
+}; // FreeFare
39
+}; // LibNfc
40
+
41
+#endif //LIBNFC_CPPTOOLS_FREEFARETAG_H

+ 3
- 3
libnfc_cpptools/src/libnfc/LibNfcContext.cpp View File

4
 
4
 
5
 #include <algorithm>
5
 #include <algorithm>
6
 #include "libnfc_cpptools/LibNfcContext.h"
6
 #include "libnfc_cpptools/LibNfcContext.h"
7
-#include "LibNfcInternal.h"
7
+#include "LibNfcContextInternal.h"
8
 
8
 
9
 #define Q(x) #x
9
 #define Q(x) #x
10
 #define QUOTE(x) Q(x)
10
 #define QUOTE(x) Q(x)
24
 
24
 
25
 LibNfcContext::LibNfcContext()
25
 LibNfcContext::LibNfcContext()
26
 {
26
 {
27
-    _libNfc = std::make_shared<LibNfcInternal>();
27
+    _libNfc = std::make_shared<LibNfcContextInternal>();
28
 }
28
 }
29
 
29
 
30
 LibNfcContext::~LibNfcContext()
30
 LibNfcContext::~LibNfcContext()
42
 
42
 
43
 std::string LibNfcContext::getLibNfcVersion()
43
 std::string LibNfcContext::getLibNfcVersion()
44
 {
44
 {
45
-    return LibNfcInternal::getVersion();
45
+    return LibNfcContextInternal::getVersion();
46
 }
46
 }
47
 
47
 
48
 void LibNfcContext::clean()
48
 void LibNfcContext::clean()

libnfc_cpptools/src/libnfc/LibNfcInternal.cpp → libnfc_cpptools/src/libnfc/LibNfcContextInternal.cpp View File

3
 //
3
 //
4
 
4
 
5
 #include <boost/shared_ptr.hpp>
5
 #include <boost/shared_ptr.hpp>
6
-#include "LibNfcInternal.h"
6
+#include "LibNfcContextInternal.h"
7
 
7
 
8
 namespace LibNfc
8
 namespace LibNfc
9
 {
9
 {
10
 namespace Core
10
 namespace Core
11
 {
11
 {
12
 
12
 
13
-LibNfcInternal::LibNfcInternal()
13
+LibNfcContextInternal::LibNfcContextInternal()
14
     : _context(0)
14
     : _context(0)
15
 {
15
 {
16
 }
16
 }
17
 
17
 
18
-LibNfcInternal::~LibNfcInternal()
18
+LibNfcContextInternal::~LibNfcContextInternal()
19
 {
19
 {
20
     clean();
20
     clean();
21
 }
21
 }
22
 
22
 
23
-LibNfc::Utils::ResultBool LibNfcInternal::init()
23
+LibNfc::Utils::ResultBool LibNfcContextInternal::init()
24
 {
24
 {
25
     nfc_init(&_context);
25
     nfc_init(&_context);
26
     if (!_context) {
26
     if (!_context) {
29
     return LibNfc::Utils::ResultBool::ok(true);
29
     return LibNfc::Utils::ResultBool::ok(true);
30
 }
30
 }
31
 
31
 
32
-std::string LibNfcInternal::getVersion()
32
+std::string LibNfcContextInternal::getVersion()
33
 {
33
 {
34
     return nfc_version();
34
     return nfc_version();
35
 }
35
 }
36
 
36
 
37
-void LibNfcInternal::clean()
37
+void LibNfcContextInternal::clean()
38
 {
38
 {
39
     nfc_exit(_context);
39
     nfc_exit(_context);
40
     _context = 0;
40
     _context = 0;
41
 }
41
 }
42
 
42
 
43
-LibNfc::Utils::Result<std::vector<std::shared_ptr<NfcDeviceInternal>>> LibNfcInternal::getDevices() const
43
+LibNfc::Utils::Result<std::vector<std::shared_ptr<NfcDeviceInternal>>> LibNfcContextInternal::getDevices() const
44
 {
44
 {
45
     nfc_connstring devices[16];
45
     nfc_connstring devices[16];
46
     ::memset((char*)devices, 0, sizeof(devices));
46
     ::memset((char*)devices, 0, sizeof(devices));
55
     return LibNfc::Utils::Result<std::vector<std::shared_ptr<NfcDeviceInternal>>>::ok(devicesList);
55
     return LibNfc::Utils::Result<std::vector<std::shared_ptr<NfcDeviceInternal>>>::ok(devicesList);
56
 }
56
 }
57
 
57
 
58
-nfc_context *LibNfcInternal::getContext() const
58
+nfc_context *LibNfcContextInternal::getContext() const
59
 {
59
 {
60
     return _context;
60
     return _context;
61
 }
61
 }

libnfc_cpptools/src/libnfc/LibNfcInternal.h → libnfc_cpptools/src/libnfc/LibNfcContextInternal.h View File

17
 
17
 
18
 class NfcDeviceInternal;
18
 class NfcDeviceInternal;
19
 
19
 
20
-class LibNfcInternal
20
+class LibNfcContextInternal
21
 {
21
 {
22
 public:
22
 public:
23
-    LibNfcInternal();
24
-    virtual ~LibNfcInternal();
23
+    LibNfcContextInternal();
24
+    virtual ~LibNfcContextInternal();
25
 
25
 
26
     LibNfc::Utils::ResultBool init();
26
     LibNfc::Utils::ResultBool init();
27
 
27
 

+ 1
- 1
libnfc_cpptools/src/libnfc/NfcDeviceInternal.cpp View File

9
 namespace Core
9
 namespace Core
10
 {
10
 {
11
 
11
 
12
-NfcDeviceInternal::NfcDeviceInternal(const LibNfcInternal* libNfc, const std::string& str)
12
+NfcDeviceInternal::NfcDeviceInternal(const LibNfcContextInternal* libNfc, const std::string& str)
13
     : _connStr(str)
13
     : _connStr(str)
14
     , _device(nullptr)
14
     , _device(nullptr)
15
     , _libNfc(libNfc)
15
     , _libNfc(libNfc)

+ 4
- 4
libnfc_cpptools/src/libnfc/NfcDeviceInternal.h View File

9
 #include <string>
9
 #include <string>
10
 #include <nfc/nfc-types.h>
10
 #include <nfc/nfc-types.h>
11
 #include "libnfc_cpptools/Result.h"
11
 #include "libnfc_cpptools/Result.h"
12
-#include "LibNfcInternal.h"
12
+#include "LibNfcContextInternal.h"
13
 
13
 
14
 namespace LibNfc
14
 namespace LibNfc
15
 {
15
 {
16
 namespace Core
16
 namespace Core
17
 {
17
 {
18
 
18
 
19
-class LibNfcInternal;
19
+class LibNfcContextInternal;
20
 
20
 
21
 class NfcDeviceInternal
21
 class NfcDeviceInternal
22
 {
22
 {
23
 public:
23
 public:
24
-    NfcDeviceInternal(const LibNfcInternal* libNfc, const std::string& connStr);
24
+    NfcDeviceInternal(const LibNfcContextInternal* libNfc, const std::string& connStr);
25
     ~NfcDeviceInternal();
25
     ~NfcDeviceInternal();
26
 
26
 
27
     LibNfc::Utils::ResultBool open();
27
     LibNfc::Utils::ResultBool open();
37
 
37
 
38
     nfc_device* _device;
38
     nfc_device* _device;
39
 
39
 
40
-    const LibNfcInternal* _libNfc;
40
+    const LibNfcContextInternal* _libNfc;
41
 };
41
 };
42
 
42
 
43
 }; // Core
43
 }; // Core

+ 18
- 18
tests/test-main.cpp View File

4
 #include <libnfc_cpptools/LibNfcContext.h>
4
 #include <libnfc_cpptools/LibNfcContext.h>
5
 #include <libnfc_cpptools/StringUtils.h>
5
 #include <libnfc_cpptools/StringUtils.h>
6
 #include <libnfc_cpptools/ArrayUtils.h>
6
 #include <libnfc_cpptools/ArrayUtils.h>
7
-#include <libnfc_cpptools/FreeFareAccessBits.h>
7
+#include <libnfc_cpptools/FreeFareClassicAccessBits.h>
8
 
8
 
9
 TEST(StringUtils, rawToHumanChar)
9
 TEST(StringUtils, rawToHumanChar)
10
 {
10
 {
179
 TEST(AccessBitsDbo, getBit)
179
 TEST(AccessBitsDbo, getBit)
180
 {
180
 {
181
   const unsigned char buf[4] = {0x05, 0xa3, 0xcf, 0x00};
181
   const unsigned char buf[4] = {0x05, 0xa3, 0xcf, 0x00};
182
-  LibNfc::FreeFare::FreeFareAccessBits dbo((const char*)buf);
182
+  LibNfc::FreeFare::FreeFareClassicAccessBits dbo((const char*)buf);
183
 
183
 
184
   ASSERT_FALSE(dbo.getBit(1, 0));
184
   ASSERT_FALSE(dbo.getBit(1, 0));
185
   ASSERT_TRUE(dbo.getBit(2, 0));
185
   ASSERT_TRUE(dbo.getBit(2, 0));
201
 TEST(AccessBitsDbo, canKeyDoThisOnThisBlock1)
201
 TEST(AccessBitsDbo, canKeyDoThisOnThisBlock1)
202
 {
202
 {
203
   const unsigned char buf[4] = {0xff, 0x0f, 0x00, 0x00};
203
   const unsigned char buf[4] = {0xff, 0x0f, 0x00, 0x00};
204
-    LibNfc::FreeFare::FreeFareAccessBits dbo((const char*)buf);
204
+    LibNfc::FreeFare::FreeFareClassicAccessBits dbo((const char*)buf);
205
 
205
 
206
   ASSERT_TRUE(dbo.canKeyAReadBlock(0));
206
   ASSERT_TRUE(dbo.canKeyAReadBlock(0));
207
   ASSERT_TRUE(dbo.canKeyBReadBlock(0));
207
   ASSERT_TRUE(dbo.canKeyBReadBlock(0));
219
 TEST(AccessBitsDbo, canKeyDoThisOnThisBlock2)
219
 TEST(AccessBitsDbo, canKeyDoThisOnThisBlock2)
220
 {
220
 {
221
   const unsigned char buf[4] = {0xef, 0x0f, 0x01, 0x00};
221
   const unsigned char buf[4] = {0xef, 0x0f, 0x01, 0x00};
222
-    LibNfc::FreeFare::FreeFareAccessBits dbo((const char*)buf);
222
+    LibNfc::FreeFare::FreeFareClassicAccessBits dbo((const char*)buf);
223
 
223
 
224
   ASSERT_TRUE(dbo.canKeyAReadBlock(0));
224
   ASSERT_TRUE(dbo.canKeyAReadBlock(0));
225
   ASSERT_TRUE(dbo.canKeyBReadBlock(0));
225
   ASSERT_TRUE(dbo.canKeyBReadBlock(0));
237
 TEST(AccessBitsDbo, canKeyDoThisOnThisBlock3)
237
 TEST(AccessBitsDbo, canKeyDoThisOnThisBlock3)
238
 {
238
 {
239
   const unsigned char buf[4] = {0xfe, 0x1f, 0x00, 0x00};
239
   const unsigned char buf[4] = {0xfe, 0x1f, 0x00, 0x00};
240
-    LibNfc::FreeFare::FreeFareAccessBits dbo((const char*)buf);
240
+    LibNfc::FreeFare::FreeFareClassicAccessBits dbo((const char*)buf);
241
 
241
 
242
   ASSERT_TRUE(dbo.canKeyAReadBlock(0));
242
   ASSERT_TRUE(dbo.canKeyAReadBlock(0));
243
   ASSERT_TRUE(dbo.canKeyBReadBlock(0));
243
   ASSERT_TRUE(dbo.canKeyBReadBlock(0));
255
 TEST(AccessBitsDbo, canKeyDoThisOnThisBlock4)
255
 TEST(AccessBitsDbo, canKeyDoThisOnThisBlock4)
256
 {
256
 {
257
   const unsigned char buf[4] = {0xee, 0x1f, 0x01, 0x00};
257
   const unsigned char buf[4] = {0xee, 0x1f, 0x01, 0x00};
258
-    LibNfc::FreeFare::FreeFareAccessBits dbo((const char*)buf);
258
+    LibNfc::FreeFare::FreeFareClassicAccessBits dbo((const char*)buf);
259
 
259
 
260
   ASSERT_TRUE(dbo.canKeyAReadBlock(0));
260
   ASSERT_TRUE(dbo.canKeyAReadBlock(0));
261
   ASSERT_TRUE(dbo.canKeyBReadBlock(0));
261
   ASSERT_TRUE(dbo.canKeyBReadBlock(0));
273
 TEST(AccessBitsDbo, canKeyDoThisOnThisBlock5)
273
 TEST(AccessBitsDbo, canKeyDoThisOnThisBlock5)
274
 {
274
 {
275
   const unsigned char buf[4] = {0xff, 0x0e, 0x10, 0x00};
275
   const unsigned char buf[4] = {0xff, 0x0e, 0x10, 0x00};
276
-    LibNfc::FreeFare::FreeFareAccessBits dbo((const char*)buf);
276
+    LibNfc::FreeFare::FreeFareClassicAccessBits dbo((const char*)buf);
277
 
277
 
278
   ASSERT_TRUE(dbo.canKeyAReadBlock(0));
278
   ASSERT_TRUE(dbo.canKeyAReadBlock(0));
279
   ASSERT_TRUE(dbo.canKeyBReadBlock(0));
279
   ASSERT_TRUE(dbo.canKeyBReadBlock(0));
291
 TEST(AccessBitsDbo, canKeyDoThisOnThisBlock6)
291
 TEST(AccessBitsDbo, canKeyDoThisOnThisBlock6)
292
 {
292
 {
293
   const unsigned char buf[4] = {0xef, 0x0e, 0x11, 0x00};
293
   const unsigned char buf[4] = {0xef, 0x0e, 0x11, 0x00};
294
-    LibNfc::FreeFare::FreeFareAccessBits dbo((const char*)buf);
294
+    LibNfc::FreeFare::FreeFareClassicAccessBits dbo((const char*)buf);
295
 
295
 
296
   ASSERT_FALSE(dbo.canKeyAReadBlock(0));
296
   ASSERT_FALSE(dbo.canKeyAReadBlock(0));
297
   ASSERT_TRUE(dbo.canKeyBReadBlock(0));
297
   ASSERT_TRUE(dbo.canKeyBReadBlock(0));
309
 TEST(AccessBitsDbo, canKeyDoThisOnThisBlock7)
309
 TEST(AccessBitsDbo, canKeyDoThisOnThisBlock7)
310
 {
310
 {
311
   const unsigned char buf[4] = {0xfe, 0x1e, 0x10, 0x00};
311
   const unsigned char buf[4] = {0xfe, 0x1e, 0x10, 0x00};
312
-    LibNfc::FreeFare::FreeFareAccessBits dbo((const char*)buf);
312
+    LibNfc::FreeFare::FreeFareClassicAccessBits dbo((const char*)buf);
313
 
313
 
314
   ASSERT_FALSE(dbo.canKeyAReadBlock(0));
314
   ASSERT_FALSE(dbo.canKeyAReadBlock(0));
315
   ASSERT_TRUE(dbo.canKeyBReadBlock(0));
315
   ASSERT_TRUE(dbo.canKeyBReadBlock(0));
327
 TEST(AccessBitsDbo, canKeyDoThisOnThisBlock8)
327
 TEST(AccessBitsDbo, canKeyDoThisOnThisBlock8)
328
 {
328
 {
329
   const unsigned char buf[4] = {0xee, 0x1e, 0x11, 0x00};
329
   const unsigned char buf[4] = {0xee, 0x1e, 0x11, 0x00};
330
-    LibNfc::FreeFare::FreeFareAccessBits dbo((const char*)buf);
330
+    LibNfc::FreeFare::FreeFareClassicAccessBits dbo((const char*)buf);
331
 
331
 
332
   ASSERT_FALSE(dbo.canKeyAReadBlock(0));
332
   ASSERT_FALSE(dbo.canKeyAReadBlock(0));
333
   ASSERT_FALSE(dbo.canKeyBReadBlock(0));
333
   ASSERT_FALSE(dbo.canKeyBReadBlock(0));
345
 TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer1)
345
 TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer1)
346
 {
346
 {
347
   const unsigned char buf[4] = {0xff, 0x0f, 0x00, 0x00};
347
   const unsigned char buf[4] = {0xff, 0x0f, 0x00, 0x00};
348
-    LibNfc::FreeFare::FreeFareAccessBits dbo((const char*)buf);
348
+    LibNfc::FreeFare::FreeFareClassicAccessBits dbo((const char*)buf);
349
 
349
 
350
   ASSERT_FALSE(dbo.canKeyAReadKeyATrailer());
350
   ASSERT_FALSE(dbo.canKeyAReadKeyATrailer());
351
   ASSERT_FALSE(dbo.canKeyBReadKeyATrailer());
351
   ASSERT_FALSE(dbo.canKeyBReadKeyATrailer());
369
 TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer2)
369
 TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer2)
370
 {
370
 {
371
   const unsigned char buf[4] = {0x7f, 0x0f, 0x08, 0x00};
371
   const unsigned char buf[4] = {0x7f, 0x0f, 0x08, 0x00};
372
-    LibNfc::FreeFare::FreeFareAccessBits dbo((const char*)buf);
372
+    LibNfc::FreeFare::FreeFareClassicAccessBits dbo((const char*)buf);
373
 
373
 
374
   ASSERT_FALSE(dbo.canKeyAReadKeyATrailer());
374
   ASSERT_FALSE(dbo.canKeyAReadKeyATrailer());
375
   ASSERT_FALSE(dbo.canKeyBReadKeyATrailer());
375
   ASSERT_FALSE(dbo.canKeyBReadKeyATrailer());
393
 TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer3)
393
 TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer3)
394
 {
394
 {
395
   const unsigned char buf[4] = {0xf7, 0x8f, 0x00, 0x00};
395
   const unsigned char buf[4] = {0xf7, 0x8f, 0x00, 0x00};
396
-    LibNfc::FreeFare::FreeFareAccessBits dbo((const char*)buf);
396
+    LibNfc::FreeFare::FreeFareClassicAccessBits dbo((const char*)buf);
397
 
397
 
398
   ASSERT_FALSE(dbo.canKeyAReadKeyATrailer());
398
   ASSERT_FALSE(dbo.canKeyAReadKeyATrailer());
399
   ASSERT_FALSE(dbo.canKeyBReadKeyATrailer());
399
   ASSERT_FALSE(dbo.canKeyBReadKeyATrailer());
417
 TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer4)
417
 TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer4)
418
 {
418
 {
419
   const unsigned char buf[4] = {0x77, 0x8f, 0x08, 0x00};
419
   const unsigned char buf[4] = {0x77, 0x8f, 0x08, 0x00};
420
-    LibNfc::FreeFare::FreeFareAccessBits dbo((const char*)buf);
420
+    LibNfc::FreeFare::FreeFareClassicAccessBits dbo((const char*)buf);
421
 
421
 
422
   ASSERT_FALSE(dbo.canKeyAReadKeyATrailer());
422
   ASSERT_FALSE(dbo.canKeyAReadKeyATrailer());
423
   ASSERT_FALSE(dbo.canKeyBReadKeyATrailer());
423
   ASSERT_FALSE(dbo.canKeyBReadKeyATrailer());
441
 TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer5)
441
 TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer5)
442
 {
442
 {
443
   const unsigned char buf[4] = {0xff, 0x07, 0x80, 0x00};
443
   const unsigned char buf[4] = {0xff, 0x07, 0x80, 0x00};
444
-    LibNfc::FreeFare::FreeFareAccessBits dbo((const char*)buf);
444
+    LibNfc::FreeFare::FreeFareClassicAccessBits dbo((const char*)buf);
445
 
445
 
446
   ASSERT_FALSE(dbo.canKeyAReadKeyATrailer());
446
   ASSERT_FALSE(dbo.canKeyAReadKeyATrailer());
447
   ASSERT_FALSE(dbo.canKeyBReadKeyATrailer());
447
   ASSERT_FALSE(dbo.canKeyBReadKeyATrailer());
465
 TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer6)
465
 TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer6)
466
 {
466
 {
467
   const unsigned char buf[4] = {0x7f, 0x07, 0x88, 0x00};
467
   const unsigned char buf[4] = {0x7f, 0x07, 0x88, 0x00};
468
-    LibNfc::FreeFare::FreeFareAccessBits dbo((const char*)buf);
468
+    LibNfc::FreeFare::FreeFareClassicAccessBits dbo((const char*)buf);
469
 
469
 
470
   ASSERT_FALSE(dbo.canKeyAReadKeyATrailer());
470
   ASSERT_FALSE(dbo.canKeyAReadKeyATrailer());
471
   ASSERT_FALSE(dbo.canKeyBReadKeyATrailer());
471
   ASSERT_FALSE(dbo.canKeyBReadKeyATrailer());
489
 TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer7)
489
 TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer7)
490
 {
490
 {
491
   const unsigned char buf[4] = {0xf7, 0x87, 0x80, 0x00};
491
   const unsigned char buf[4] = {0xf7, 0x87, 0x80, 0x00};
492
-    LibNfc::FreeFare::FreeFareAccessBits dbo((const char*)buf);
492
+    LibNfc::FreeFare::FreeFareClassicAccessBits dbo((const char*)buf);
493
 
493
 
494
   ASSERT_FALSE(dbo.canKeyAReadKeyATrailer());
494
   ASSERT_FALSE(dbo.canKeyAReadKeyATrailer());
495
   ASSERT_FALSE(dbo.canKeyBReadKeyATrailer());
495
   ASSERT_FALSE(dbo.canKeyBReadKeyATrailer());
513
 TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer8)
513
 TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer8)
514
 {
514
 {
515
   const unsigned char buf[4] = {0x77, 0x87, 0x88, 0x00};
515
   const unsigned char buf[4] = {0x77, 0x87, 0x88, 0x00};
516
-    LibNfc::FreeFare::FreeFareAccessBits dbo((const char*)buf);
516
+    LibNfc::FreeFare::FreeFareClassicAccessBits dbo((const char*)buf);
517
 
517
 
518
   ASSERT_FALSE(dbo.canKeyAReadKeyATrailer());
518
   ASSERT_FALSE(dbo.canKeyAReadKeyATrailer());
519
   ASSERT_FALSE(dbo.canKeyBReadKeyATrailer());
519
   ASSERT_FALSE(dbo.canKeyBReadKeyATrailer());

Loading…
Cancel
Save