Kaynağa Gözat

refactor classic {1,4}K support

develop
Robin Thoni 6 yıl önce
ebeveyn
işleme
beb395f2d4
27 değiştirilmiş dosya ile 480 ekleme ve 349 silme
  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 Dosyayı Görüntüle

@@ -3,13 +3,16 @@
3 3
 //
4 4
 
5 5
 #include <iostream>
6
+#include <algorithm>
6 7
 #include <sysexits.h>
8
+#include <unistd.h>
7 9
 #include <iomanip>
8 10
 #include <fstream>
9 11
 #include <libnfc_cpptools/StringUtils.h>
10 12
 #include <libnfc_cpptools/FreeFareDevice.h>
11 13
 #include <libnfc_cpptools/Result.h>
12 14
 #include <libnfc_cpptools/LibNfcContext.h>
15
+#include <libnfc_cpptools/FreeFareTagClassic.h>
13 16
 #include "CommandLineParser.h"
14 17
 #include "MainClass.h"
15 18
 
@@ -22,6 +25,7 @@
22 25
 #define EX_MAP_KEYS_ERROR 15
23 26
 #define EX_READ_ERROR 16
24 27
 #define EX_WRITE_ERROR 17
28
+#define EX_NFC_TAG_NOT_SUPPORTED 18
25 29
 
26 30
 MainClass::MainClass(int argc, char *argv[])
27 31
     : _argc(argc)
@@ -212,12 +216,14 @@ int MainClass::main()
212 216
                             }
213 217
                         }
214 218
                         else {
215
-                            auto tag = getTag(tagUid, tags);
216
-                            if (tag == 0) {
219
+                            auto genericTag = getTag(tagUid, tags);
220
+                            if (genericTag == nullptr) {
217 221
                                 std::cerr << "Tag not found" << std::endl;
218 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 227
                                 if (action == Read) {
222 228
                                     res = read(tag, keys);
223 229
                                 }
@@ -228,6 +234,10 @@ int MainClass::main()
228 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 243
                     device->close();
@@ -246,7 +256,7 @@ int MainClass::main()
246 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 261
     auto mappedKeysResult = tag->mapKeys(keys, printPercentMapKeys);
252 262
     if (!mappedKeysResult) {
@@ -268,7 +278,7 @@ int MainClass::mapKeys(std::shared_ptr<LibNfc::FreeFare::FreeFareTag> tag, std::
268 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 283
     auto readResult = tag->read(keys, printPercentMapKeys, printPercentDump);
274 284
     if (!readResult) {
@@ -280,24 +290,24 @@ int MainClass::read(std::shared_ptr<LibNfc::FreeFare::FreeFareTag> tag, std::vec
280 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 295
     auto writeResult = tag->write(keys, data, false, printPercentMapKeys, printPercentWrite);
286 296
     if (!writeResult) {
287 297
         writeResult.print();
288 298
         return EX_WRITE_ERROR;
289 299
     }
290
-//    std::vector<LibNfc::FreeFare::FreeFareSector> sectors;
300
+//    std::vector<LibNfc::FreeFare::FreeFareClassicSector> sectors;
291 301
 //    std::string d = LibNfc::Utils::StringUtils::ensureSize(data, 1024);
292 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 306
 //    printSectors(sectors);
297 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 312
     for(int s = 0; s < sectors.size(); ++s) {
303 313
         cout() << "+Sector: " << s << std::endl;
@@ -313,7 +323,7 @@ void MainClass::printSectors(const std::vector<LibNfc::FreeFare::FreeFareSector>
313 323
         cout() << "+Trailer key A: " << (sector.hasKeyA() ? LibNfc::Utils::StringUtils::rawToHuman(sector.getKeyA()) : std::string(12, '-'))
314 324
         << "\t AC bits: " << (sector.hasAccessBits() ? LibNfc::Utils::StringUtils::rawToHuman(sector.getAccessBits()) : std::string(8, '-'))
315 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 327
         for (int b = 0; b < 3; ++b) {
318 328
             cout() << "+Block: " << b << " ";
319 329
             printBlockAccessBits(accessBitsDbo, b);
@@ -323,7 +333,7 @@ void MainClass::printSectors(const std::vector<LibNfc::FreeFare::FreeFareSector>
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 338
     cout() << "read: " << (accessBits.canKeyAReadBlock(block) ? "A" : " ") << (accessBits.canKeyBReadBlock(block) ? "B" : " ");
329 339
     cout() << "\t write: " << (accessBits.canKeyAWriteBlock(block) ? "A" : " ") << (accessBits.canKeyBWriteBlock(block) ? "B" : " ");
@@ -331,7 +341,7 @@ void MainClass::printBlockAccessBits(const LibNfc::FreeFare::FreeFareAccessBits
331 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 346
     cout() << "key A read: " << (accessBits.canKeyAReadKeyATrailer() ? "A" : " ") << (accessBits.canKeyBReadKeyATrailer() ? "B" : " ");
337 347
     cout() << "\t key A write: " << (accessBits.canKeyAWriteKeyATrailer() ? "A" : " ") << (accessBits.canKeyBWriteKeyATrailer() ? "B" : " ");

+ 7
- 6
cli/cli/MainClass.h Dosyayı Görüntüle

@@ -7,6 +7,7 @@
7 7
 
8 8
 #include <memory>
9 9
 #include <libnfc_cpptools/FreeFareTag.h>
10
+#include <libnfc_cpptools/FreeFareTagClassic.h>
10 11
 #include <libnfc_cpptools/NfcDevice.h>
11 12
 
12 13
 class MainClass {
@@ -27,21 +28,21 @@ public:
27 28
 
28 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 37
     LibNfc::Utils::Result<std::vector<std::string>> readFile(const std::string& filePath);
37 38
 
38 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 47
     void printVersion();
47 48
 

+ 10
- 10
libnfc_cpptools/CMakeLists.txt Dosyayı Görüntüle

@@ -7,31 +7,31 @@ include_directories(
7 7
 
8 8
 set(SOURCE_FILES
9 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 12
         src/libnfc/NfcDeviceInternal.cpp
13 13
         src/libnfc/NfcDeviceInternal.h
14 14
         src/freefare/FreeFareDeviceInternal.cpp
15 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 18
         src/utils/StringUtils.cpp
19 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 22
         src/libnfc/LibNfcContext.cpp
23 23
         inc/libnfc_cpptools/LibNfcContext.h
24 24
         src/libnfc/NfcDevice.cpp
25 25
         inc/libnfc_cpptools/NfcDevice.h
26 26
         src/freefare/FreeFareDevice.cpp
27 27
         inc/libnfc_cpptools/FreeFareDevice.h
28
-        src/freefare/FreeFareTag.cpp
28
+        src/freefare/Tags/FreeFareTag.cpp
29 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 32
         src/utils/ArrayUtils.cpp
33 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 36
 add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES})
37 37
 target_link_libraries(${PROJECT_NAME}

libnfc_cpptools/inc/libnfc_cpptools/FreeFareAccessBits.h → libnfc_cpptools/inc/libnfc_cpptools/FreeFareClassicAccessBits.h Dosyayı Görüntüle

@@ -13,16 +13,16 @@ namespace LibNfc
13 13
 namespace FreeFare
14 14
 {
15 15
 
16
-class FreeFareAccessBits
16
+class FreeFareClassicAccessBits
17 17
 {
18 18
 public:
19 19
 
20 20
     static const char nonInvertedBitPosition[4][4];
21 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 27
     char getUserData() const;
28 28
     void setUserData(const char& data);

libnfc_cpptools/inc/libnfc_cpptools/FreeFareSector.h → libnfc_cpptools/inc/libnfc_cpptools/FreeFareClassicSector.h Dosyayı Görüntüle

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

+ 2
- 24
libnfc_cpptools/inc/libnfc_cpptools/FreeFareTag.h Dosyayı Görüntüle

@@ -6,8 +6,8 @@
6 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 12
 namespace LibNfc
13 13
 {
@@ -37,28 +37,6 @@ public:
37 37
     explicit FreeFareTag(std::shared_ptr<FreeFareTagInternal> tag);
38 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 40
     const std::string& getUid() const;
63 41
 
64 42
     FreeFareTagType getType() const;

+ 61
- 0
libnfc_cpptools/inc/libnfc_cpptools/FreeFareTagClassic.h Dosyayı Görüntüle

@@ -0,0 +1,61 @@
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 Dosyayı Görüntüle

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

+ 2
- 1
libnfc_cpptools/inc/libnfc_cpptools/Result.h Dosyayı Görüntüle

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

+ 8
- 1
libnfc_cpptools/src/freefare/FreeFareDevice.cpp Dosyayı Görüntüle

@@ -2,8 +2,10 @@
2 2
 // Created by robin on 7/22/16.
3 3
 //
4 4
 
5
+#include <libnfc_cpptools/FreeFareTagClassic.h>
5 6
 #include "libnfc_cpptools/FreeFareDevice.h"
6 7
 #include "FreeFareDeviceInternal.h"
8
+#include "Tags/Classic/FreeFareTagClassicInternal.h"
7 9
 
8 10
 namespace LibNfc
9 11
 {
@@ -28,7 +30,12 @@ LibNfc::Utils::Result<std::vector<std::shared_ptr<FreeFareTag>>> FreeFareDevice:
28 30
     auto tags = tagsResult.getData();
29 31
     std::vector<std::shared_ptr<FreeFareTag>> tagsBusiness;
30 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 40
     return LibNfc::Utils::Result<std::vector<std::shared_ptr<FreeFareTag>>>::ok(tagsBusiness);
34 41
 }

+ 8
- 1
libnfc_cpptools/src/freefare/FreeFareDeviceInternal.cpp Dosyayı Görüntüle

@@ -2,6 +2,7 @@
2 2
 // Created by robin on 6/19/16.
3 3
 //
4 4
 
5
+#include <Tags/Classic/FreeFareTagClassicInternal.h>
5 6
 #include "FreeFareDeviceInternal.h"
6 7
 
7 8
 namespace LibNfc
@@ -22,7 +23,13 @@ LibNfc::Utils::Result<std::vector<std::shared_ptr<FreeFareTagInternal>>> FreeFar
22 23
     }
23 24
     std::vector<std::shared_ptr<FreeFareTagInternal>> tagList;
24 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 34
     return LibNfc::Utils::Result<std::vector<std::shared_ptr<FreeFareTagInternal>>>::ok(tagList);
28 35
 }

+ 1
- 1
libnfc_cpptools/src/freefare/FreeFareDeviceInternal.h Dosyayı Görüntüle

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

+ 0
- 53
libnfc_cpptools/src/freefare/FreeFareTagInternal.h Dosyayı Görüntüle

@@ -1,53 +0,0 @@
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 Dosyayı Görüntüle

@@ -4,7 +4,7 @@
4 4
 
5 5
 #include <cstring>
6 6
 #include <iostream>
7
-#include "libnfc_cpptools/FreeFareAccessBits.h"
7
+#include "libnfc_cpptools/FreeFareClassicAccessBits.h"
8 8
 #include "libnfc_cpptools/StringUtils.h"
9 9
 #include "libnfc_cpptools/ArrayUtils.h"
10 10
 
@@ -13,39 +13,39 @@ namespace LibNfc
13 13
 namespace FreeFare
14 14
 {
15 15
 
16
-const char FreeFareAccessBits::nonInvertedBitPosition[4][4] = {
16
+const char FreeFareClassicAccessBits::nonInvertedBitPosition[4][4] = {
17 17
         {0,  0,  0,  0 },
18 18
         {11, 10, 9,  8 },
19 19
         {23, 22, 21, 20},
20 20
         {19, 18, 17, 16}};
21 21
 
22
-const char FreeFareAccessBits::invertedBitPosition[4][4] = {
22
+const char FreeFareClassicAccessBits::invertedBitPosition[4][4] = {
23 23
         {0,  0,  0,  0 },
24 24
         {7,  6,  5,  4 },
25 25
         {3,  2,  1,  0},
26 26
         {15, 14, 13, 12}};
27 27
 
28
-FreeFareAccessBits::FreeFareAccessBits()
28
+FreeFareClassicAccessBits::FreeFareClassicAccessBits()
29 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 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 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 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 50
     char buf[_bits.length()];
51 51
     memcpy(buf, _bits.c_str(), _bits.length());
@@ -56,18 +56,18 @@ void FreeFareAccessBits::setBit(int i, int j, const bool& value)
56 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 61
     const char* buf = _bits.c_str();
62 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 67
     return _bits;
68 68
 }
69 69
 
70
-bool FreeFareAccessBits::canKeyAReadBlock(int block) const
70
+bool FreeFareClassicAccessBits::canKeyAReadBlock(int block) const
71 71
 {
72 72
     bool c1 = getBit(1, block);
73 73
     bool c2 = getBit(2, block);
@@ -75,7 +75,7 @@ bool FreeFareAccessBits::canKeyAReadBlock(int block) const
75 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 80
     bool c1 = getBit(1, block);
81 81
     bool c2 = getBit(2, block);
@@ -83,7 +83,7 @@ bool FreeFareAccessBits::canKeyBReadBlock(int block) const
83 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 88
     bool c1 = getBit(1, block);
89 89
     bool c2 = getBit(2, block);
@@ -91,7 +91,7 @@ bool FreeFareAccessBits::canKeyAWriteBlock(int block) const
91 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 96
     bool c1 = getBit(1, block);
97 97
     bool c2 = getBit(2, block);
@@ -99,7 +99,7 @@ bool FreeFareAccessBits::canKeyBWriteBlock(int block) const
99 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 104
     bool c1 = getBit(1, block);
105 105
     bool c2 = getBit(2, block);
@@ -107,7 +107,7 @@ bool FreeFareAccessBits::canKeyAIncrementBlock(int block) const
107 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 112
     bool c1 = getBit(1, block);
113 113
     bool c2 = getBit(2, block);
@@ -115,7 +115,7 @@ bool FreeFareAccessBits::canKeyBIncrementBlock(int block) const
115 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 120
     bool c1 = getBit(1, block);
121 121
     bool c2 = getBit(2, block);
@@ -123,7 +123,7 @@ bool FreeFareAccessBits::canKeyADecrementBlock(int block) const
123 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 128
     bool c1 = getBit(1, block);
129 129
     bool c2 = getBit(2, block);
@@ -131,24 +131,24 @@ bool FreeFareAccessBits::canKeyBDecrementBlock(int block) const
131 131
     return (!c1 && !c2) || (c1 && c2 && !c3);
132 132
 }
133 133
 
134
-bool FreeFareAccessBits::canKeyAReadKeyATrailer() const
134
+bool FreeFareClassicAccessBits::canKeyAReadKeyATrailer() const
135 135
 {
136 136
     return false;
137 137
 }
138 138
 
139
-bool FreeFareAccessBits::canKeyBReadKeyATrailer() const
139
+bool FreeFareClassicAccessBits::canKeyBReadKeyATrailer() const
140 140
 {
141 141
     return false;
142 142
 }
143 143
 
144
-bool FreeFareAccessBits::canKeyAWriteKeyATrailer() const
144
+bool FreeFareClassicAccessBits::canKeyAWriteKeyATrailer() const
145 145
 {
146 146
     bool c1 = getBit(1, 3);
147 147
     bool c2 = getBit(2, 3);
148 148
     return !c1 && !c2;
149 149
 }
150 150
 
151
-bool FreeFareAccessBits::canKeyBWriteKeyATrailer() const
151
+bool FreeFareClassicAccessBits::canKeyBWriteKeyATrailer() const
152 152
 {
153 153
     bool c1 = getBit(1, 3);
154 154
     bool c2 = getBit(2, 3);
@@ -156,12 +156,12 @@ bool FreeFareAccessBits::canKeyBWriteKeyATrailer() const
156 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 161
     return true;
162 162
 }
163 163
 
164
-bool FreeFareAccessBits::canKeyBReadAccessBitsTrailer() const
164
+bool FreeFareClassicAccessBits::canKeyBReadAccessBitsTrailer() const
165 165
 {
166 166
     bool c1 = getBit(1, 3);
167 167
     bool c2 = getBit(2, 3);
@@ -169,7 +169,7 @@ bool FreeFareAccessBits::canKeyBReadAccessBitsTrailer() const
169 169
     return c1 || (c2 && c3);
170 170
 }
171 171
 
172
-bool FreeFareAccessBits::canKeyAWriteAccessBitsTrailer() const
172
+bool FreeFareClassicAccessBits::canKeyAWriteAccessBitsTrailer() const
173 173
 {
174 174
     bool c1 = getBit(1, 3);
175 175
     bool c2 = getBit(2, 3);
@@ -177,7 +177,7 @@ bool FreeFareAccessBits::canKeyAWriteAccessBitsTrailer() const
177 177
     return !c1 && !c2 && c3;
178 178
 }
179 179
 
180
-bool FreeFareAccessBits::canKeyBWriteAccessBitsTrailer() const
180
+bool FreeFareClassicAccessBits::canKeyBWriteAccessBitsTrailer() const
181 181
 {
182 182
     bool c1 = getBit(1, 3);
183 183
     bool c2 = getBit(2, 3);
@@ -185,7 +185,7 @@ bool FreeFareAccessBits::canKeyBWriteAccessBitsTrailer() const
185 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 190
     bool c1 = getBit(1, 3);
191 191
     bool c2 = getBit(2, 3);
@@ -193,19 +193,19 @@ bool FreeFareAccessBits::canKeyAReadKeyBTrailer() const
193 193
     return (!c1 && !c2) || (!c1 && !c3);
194 194
 }
195 195
 
196
-bool FreeFareAccessBits::canKeyBReadKeyBTrailer() const
196
+bool FreeFareClassicAccessBits::canKeyBReadKeyBTrailer() const
197 197
 {
198 198
     return false;
199 199
 }
200 200
 
201
-bool FreeFareAccessBits::canKeyAWriteKeyBTrailer() const
201
+bool FreeFareClassicAccessBits::canKeyAWriteKeyBTrailer() const
202 202
 {
203 203
     bool c1 = getBit(1, 3);
204 204
     bool c2 = getBit(2, 3);
205 205
     return !c1 && !c2;
206 206
 }
207 207
 
208
-bool FreeFareAccessBits::canKeyBWriteKeyBTrailer() const
208
+bool FreeFareClassicAccessBits::canKeyBWriteKeyBTrailer() const
209 209
 {
210 210
     bool c1 = getBit(1, 3);
211 211
     bool c2 = getBit(2, 3);

libnfc_cpptools/src/freefare/FreeFareSector.cpp → libnfc_cpptools/src/freefare/Tags/Classic/FreeFareClassicSector.cpp Dosyayı Görüntüle

@@ -3,14 +3,14 @@
3 3
 //
4 4
 
5 5
 #include "libnfc_cpptools/StringUtils.h"
6
-#include "libnfc_cpptools/FreeFareSector.h"
6
+#include "libnfc_cpptools/FreeFareClassicSector.h"
7 7
 
8 8
 namespace LibNfc
9 9
 {
10 10
 namespace FreeFare
11 11
 {
12 12
 
13
-FreeFareSector::FreeFareSector(const std::string &data)
13
+FreeFareClassicSector::FreeFareClassicSector(const std::string &data)
14 14
 {
15 15
     std::string d = LibNfc::Utils::StringUtils::ensureSize(data, 64);
16 16
     for (unsigned int i = 0; i < 4; ++i) {
@@ -19,32 +19,32 @@ FreeFareSector::FreeFareSector(const std::string &data)
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 24
     return _blocks[block];
25 25
 }
26 26
 
27
-std::string FreeFareSector::getKeyA() const
27
+std::string FreeFareClassicSector::getKeyA() const
28 28
 {
29 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 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 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 49
     std::string d = LibNfc::Utils::StringUtils::ensureSize(data, 16);
50 50
     if (block == 3) {
@@ -58,7 +58,7 @@ void FreeFareSector::setBlock(int block, const std::string &data)
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 63
     std::string k = LibNfc::Utils::StringUtils::ensureSize(key, 6);
64 64
     for (int i = 0; i < k.size(); ++i) {
@@ -67,7 +67,7 @@ void FreeFareSector::setKeyA(const std::string &key)
67 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 72
     std::string k = LibNfc::Utils::StringUtils::ensureSize(key, 6);
73 73
     for (int i = 0; i < k.size(); ++i) {
@@ -76,7 +76,7 @@ void FreeFareSector::setKeyB(const std::string &key)
76 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 81
     std::string a = LibNfc::Utils::StringUtils::ensureSize(accessBits, 4);
82 82
     for (int i = 0; i < a.size(); ++i) {
@@ -85,12 +85,12 @@ void FreeFareSector::setAccessBits(const std::string &accessBits)
85 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 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 95
     if (block == 3) {
96 96
         return _hasKeyA && _hasKeyB && _hasAccessBits;
@@ -98,17 +98,17 @@ bool FreeFareSector::hasBlock(int block) const
98 98
     return _haveBlocks[block];
99 99
 }
100 100
 
101
-bool FreeFareSector::hasKeyA() const
101
+bool FreeFareClassicSector::hasKeyA() const
102 102
 {
103 103
     return _hasKeyA;
104 104
 }
105 105
 
106
-bool FreeFareSector::hasKeyB() const
106
+bool FreeFareClassicSector::hasKeyB() const
107 107
 {
108 108
     return _hasKeyB;
109 109
 }
110 110
 
111
-bool FreeFareSector::hasAccessBits() const
111
+bool FreeFareClassicSector::hasAccessBits() const
112 112
 {
113 113
     return _hasAccessBits;
114 114
 }

libnfc_cpptools/src/freefare/FreeFareTag.cpp → libnfc_cpptools/src/freefare/Tags/Classic/FreeFareTagClassic.cpp Dosyayı Görüntüle

@@ -1,60 +1,27 @@
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 9
 namespace LibNfc
10 10
 {
11 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 26
     MappedKeys mappedKeys;
60 27
     unsigned long done = 0;
@@ -86,38 +53,38 @@ LibNfc::Utils::Result<MappedKeys> FreeFareTag::mapKeys(const std::vector<std::st
86 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 63
     std::string res;
97
-    int lastBlock = _tag->getSectorBlockCount(sector);
64
+    int lastBlock = std::static_pointer_cast<FreeFareTagClassicInternal>(_tag)->getSectorBlockCount(sector);
98 65
     for (int i = 0; i < lastBlock; ++i) {
99 66
         auto data = readBlock(sector, i, key, keyType);
100 67
         if (data) {
101 68
             res += data.getData();
102 69
         }
103 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 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 82
     int done = 0;
116 83
     int total = 4 * keys.size();
117
-    std::vector<FreeFareSector> sectors;
84
+    std::vector<FreeFareClassicSector> sectors;
118 85
     for (int s = 0; s < keys.size(); ++s) {
119 86
         auto sectorKey = keys[s];
120
-        FreeFareSector sector;
87
+        FreeFareClassicSector sector;
121 88
         bool keyA = false;
122 89
         bool keyB = false;
123 90
         for (int b = 0; b < 3; ++b) {
@@ -165,9 +132,9 @@ LibNfc::Utils::Result<std::vector<FreeFareSector>> FreeFareTag::read(const Mappe
165 132
         }
166 133
 
167 134
         sector.setBlock(b, dataA);
168
-        FreeFareAccessBits accessBitsDboA = sector.getAccessBitsDbo();
135
+        FreeFareClassicAccessBits accessBitsDboA = sector.getAccessBitsDbo();
169 136
         sector.setBlock(b, dataB);
170
-        FreeFareAccessBits accessBitsDboB = sector.getAccessBitsDbo();
137
+        FreeFareClassicAccessBits accessBitsDboB = sector.getAccessBitsDbo();
171 138
         sector.setKeyA(keyA ? sectorKey.first : "");
172 139
         sector.setKeyB(keyB ? sectorKey.second : "");
173 140
 
@@ -186,26 +153,26 @@ LibNfc::Utils::Result<std::vector<FreeFareSector>> FreeFareTag::read(const Mappe
186 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 160
                                                                      std::function<void(int, int)> mapCb,
194 161
                                                                      std::function<void(int, int)> readCb)
195 162
 {
196 163
     auto mappedKeysResult = mapKeys(keys, mapCb);
197 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 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 177
     std::string d = LibNfc::Utils::StringUtils::ensureSize(data, 64);
211 178
     std::string errors;
@@ -222,7 +189,10 @@ LibNfc::Utils::ResultBool FreeFareTag::writeSector(int sector, const std::string
222 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 197
     if (keys.size() != 16) {
228 198
         return LibNfc::Utils::ResultBool::error("Must have 16 sectors keys");
@@ -278,8 +248,8 @@ LibNfc::Utils::ResultBool FreeFareTag::write(const MappedKeys& keys, const std::
278 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 254
     auto mappedKeysResult = mapKeys(keys, mapCb);
285 255
     if (!mappedKeysResult) {
@@ -288,49 +258,5 @@ LibNfc::Utils::ResultBool FreeFareTag::write(const std::vector<std::string>& key
288 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 261
 }; // FreeFare
336
-}; // LibNfc
262
+}; // LibNfc

libnfc_cpptools/src/freefare/FreeFareTagInternal.cpp → libnfc_cpptools/src/freefare/Tags/Classic/FreeFareTagClassicInternal.cpp Dosyayı Görüntüle

@@ -1,29 +1,20 @@
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 7
 namespace LibNfc
10 8
 {
11 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 20
     if (mifare_classic_connect(_tag) != 0) {
@@ -38,7 +29,7 @@ LibNfc::Utils::ResultBool FreeFareTagInternal::authenticate(int sector, std::str
38 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 34
     if (mifare_classic_connect(_tag) != 0) {
44 35
         return LibNfc::Utils::ResultString::error("Failed to connect to MIFARE tag");
@@ -57,7 +48,7 @@ LibNfc::Utils::ResultString FreeFareTagInternal::readBlock(int sector, int block
57 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 53
     if (mifare_classic_connect(_tag) != 0) {
63 54
         return LibNfc::Utils::ResultBool::error("Failed to connect to MIFARE tag");
@@ -75,35 +66,19 @@ LibNfc::Utils::ResultBool FreeFareTagInternal::writeBlock(int sector, int block,
75 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 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 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 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 83
 }; // FreeFare
109 84
 }; // LibNfc

+ 37
- 0
libnfc_cpptools/src/freefare/Tags/Classic/FreeFareTagClassicInternal.h Dosyayı Görüntüle

@@ -0,0 +1,37 @@
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 Dosyayı Görüntüle

@@ -0,0 +1,98 @@
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 Dosyayı Görüntüle

@@ -0,0 +1,42 @@
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 Dosyayı Görüntüle

@@ -0,0 +1,41 @@
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 Dosyayı Görüntüle

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

libnfc_cpptools/src/libnfc/LibNfcInternal.cpp → libnfc_cpptools/src/libnfc/LibNfcContextInternal.cpp Dosyayı Görüntüle

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

libnfc_cpptools/src/libnfc/LibNfcInternal.h → libnfc_cpptools/src/libnfc/LibNfcContextInternal.h Dosyayı Görüntüle

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

+ 1
- 1
libnfc_cpptools/src/libnfc/NfcDeviceInternal.cpp Dosyayı Görüntüle

@@ -9,7 +9,7 @@ namespace LibNfc
9 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 13
     : _connStr(str)
14 14
     , _device(nullptr)
15 15
     , _libNfc(libNfc)

+ 4
- 4
libnfc_cpptools/src/libnfc/NfcDeviceInternal.h Dosyayı Görüntüle

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

+ 18
- 18
tests/test-main.cpp Dosyayı Görüntüle

@@ -4,7 +4,7 @@
4 4
 #include <libnfc_cpptools/LibNfcContext.h>
5 5
 #include <libnfc_cpptools/StringUtils.h>
6 6
 #include <libnfc_cpptools/ArrayUtils.h>
7
-#include <libnfc_cpptools/FreeFareAccessBits.h>
7
+#include <libnfc_cpptools/FreeFareClassicAccessBits.h>
8 8
 
9 9
 TEST(StringUtils, rawToHumanChar)
10 10
 {
@@ -179,7 +179,7 @@ TEST(ArrayUtils, getArrayBitMultiple)
179 179
 TEST(AccessBitsDbo, getBit)
180 180
 {
181 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 184
   ASSERT_FALSE(dbo.getBit(1, 0));
185 185
   ASSERT_TRUE(dbo.getBit(2, 0));
@@ -201,7 +201,7 @@ TEST(AccessBitsDbo, getBit)
201 201
 TEST(AccessBitsDbo, canKeyDoThisOnThisBlock1)
202 202
 {
203 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 206
   ASSERT_TRUE(dbo.canKeyAReadBlock(0));
207 207
   ASSERT_TRUE(dbo.canKeyBReadBlock(0));
@@ -219,7 +219,7 @@ TEST(AccessBitsDbo, canKeyDoThisOnThisBlock1)
219 219
 TEST(AccessBitsDbo, canKeyDoThisOnThisBlock2)
220 220
 {
221 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 224
   ASSERT_TRUE(dbo.canKeyAReadBlock(0));
225 225
   ASSERT_TRUE(dbo.canKeyBReadBlock(0));
@@ -237,7 +237,7 @@ TEST(AccessBitsDbo, canKeyDoThisOnThisBlock2)
237 237
 TEST(AccessBitsDbo, canKeyDoThisOnThisBlock3)
238 238
 {
239 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 242
   ASSERT_TRUE(dbo.canKeyAReadBlock(0));
243 243
   ASSERT_TRUE(dbo.canKeyBReadBlock(0));
@@ -255,7 +255,7 @@ TEST(AccessBitsDbo, canKeyDoThisOnThisBlock3)
255 255
 TEST(AccessBitsDbo, canKeyDoThisOnThisBlock4)
256 256
 {
257 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 260
   ASSERT_TRUE(dbo.canKeyAReadBlock(0));
261 261
   ASSERT_TRUE(dbo.canKeyBReadBlock(0));
@@ -273,7 +273,7 @@ TEST(AccessBitsDbo, canKeyDoThisOnThisBlock4)
273 273
 TEST(AccessBitsDbo, canKeyDoThisOnThisBlock5)
274 274
 {
275 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 278
   ASSERT_TRUE(dbo.canKeyAReadBlock(0));
279 279
   ASSERT_TRUE(dbo.canKeyBReadBlock(0));
@@ -291,7 +291,7 @@ TEST(AccessBitsDbo, canKeyDoThisOnThisBlock5)
291 291
 TEST(AccessBitsDbo, canKeyDoThisOnThisBlock6)
292 292
 {
293 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 296
   ASSERT_FALSE(dbo.canKeyAReadBlock(0));
297 297
   ASSERT_TRUE(dbo.canKeyBReadBlock(0));
@@ -309,7 +309,7 @@ TEST(AccessBitsDbo, canKeyDoThisOnThisBlock6)
309 309
 TEST(AccessBitsDbo, canKeyDoThisOnThisBlock7)
310 310
 {
311 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 314
   ASSERT_FALSE(dbo.canKeyAReadBlock(0));
315 315
   ASSERT_TRUE(dbo.canKeyBReadBlock(0));
@@ -327,7 +327,7 @@ TEST(AccessBitsDbo, canKeyDoThisOnThisBlock7)
327 327
 TEST(AccessBitsDbo, canKeyDoThisOnThisBlock8)
328 328
 {
329 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 332
   ASSERT_FALSE(dbo.canKeyAReadBlock(0));
333 333
   ASSERT_FALSE(dbo.canKeyBReadBlock(0));
@@ -345,7 +345,7 @@ TEST(AccessBitsDbo, canKeyDoThisOnThisBlock8)
345 345
 TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer1)
346 346
 {
347 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 350
   ASSERT_FALSE(dbo.canKeyAReadKeyATrailer());
351 351
   ASSERT_FALSE(dbo.canKeyBReadKeyATrailer());
@@ -369,7 +369,7 @@ TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer1)
369 369
 TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer2)
370 370
 {
371 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 374
   ASSERT_FALSE(dbo.canKeyAReadKeyATrailer());
375 375
   ASSERT_FALSE(dbo.canKeyBReadKeyATrailer());
@@ -393,7 +393,7 @@ TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer2)
393 393
 TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer3)
394 394
 {
395 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 398
   ASSERT_FALSE(dbo.canKeyAReadKeyATrailer());
399 399
   ASSERT_FALSE(dbo.canKeyBReadKeyATrailer());
@@ -417,7 +417,7 @@ TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer3)
417 417
 TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer4)
418 418
 {
419 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 422
   ASSERT_FALSE(dbo.canKeyAReadKeyATrailer());
423 423
   ASSERT_FALSE(dbo.canKeyBReadKeyATrailer());
@@ -441,7 +441,7 @@ TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer4)
441 441
 TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer5)
442 442
 {
443 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 446
   ASSERT_FALSE(dbo.canKeyAReadKeyATrailer());
447 447
   ASSERT_FALSE(dbo.canKeyBReadKeyATrailer());
@@ -465,7 +465,7 @@ TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer5)
465 465
 TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer6)
466 466
 {
467 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 470
   ASSERT_FALSE(dbo.canKeyAReadKeyATrailer());
471 471
   ASSERT_FALSE(dbo.canKeyBReadKeyATrailer());
@@ -489,7 +489,7 @@ TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer6)
489 489
 TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer7)
490 490
 {
491 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 494
   ASSERT_FALSE(dbo.canKeyAReadKeyATrailer());
495 495
   ASSERT_FALSE(dbo.canKeyBReadKeyATrailer());
@@ -513,7 +513,7 @@ TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer7)
513 513
 TEST(AccessBitsDbo, canKeyDoThisOnThisTrailer8)
514 514
 {
515 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 518
   ASSERT_FALSE(dbo.canKeyAReadKeyATrailer());
519 519
   ASSERT_FALSE(dbo.canKeyBReadKeyATrailer());

Loading…
İptal
Kaydet