LibLogicalAccess  2.5.0
An Open Source RFID Library
Loading...
Searching...
No Matches
mifarecommands.hpp
Go to the documentation of this file.
1
7#ifndef LOGICALACCESS_MIFARECOMMANDS_HPP
8#define LOGICALACCESS_MIFARECOMMANDS_HPP
9
13
14namespace logicalaccess
15{
16#define CMD_MIFARE "Mifare"
17
18class MifareChip;
19
23class LLA_CARDS_MIFARE_API MifareCommands : public Commands
24{
25 public:
28 {
29 }
30
31 explicit MifareCommands(std::string ct)
32 : Commands(ct)
33 {
34 }
35
36 virtual ByteVector readSector(int sector, int start_block,
37 std::shared_ptr<MifareKey> keyA,
38 std::shared_ptr<MifareKey> keyB,
40 bool readtrailer = false) final;
41
42 virtual void
43 writeSector(int sector, int start_block, const ByteVector &buf,
44 std::shared_ptr<MifareKey> keyA, std::shared_ptr<MifareKey> keyB,
45 const MifareAccessInfo::SectorAccessBits &sab,
46 unsigned char userbyte = 0x00,
47 MifareAccessInfo::SectorAccessBits *newsab = nullptr,
48 std::shared_ptr<MifareKey> newkeyA = std::shared_ptr<MifareKey>(),
49 std::shared_ptr<MifareKey> newkeyB = std::shared_ptr<MifareKey>()) final;
50
51 virtual ByteVector readSectors(int start_sector, int stop_sector, int start_block,
52 std::shared_ptr<MifareKey> keyA,
53 std::shared_ptr<MifareKey> keyB,
54 const MifareAccessInfo::SectorAccessBits &sab) final;
55
56 virtual void writeSectors(
57 int start_sector, int stop_sector, int start_block, const ByteVector &buf,
58 std::shared_ptr<MifareKey> keyA, std::shared_ptr<MifareKey> keyB,
59 const MifareAccessInfo::SectorAccessBits &sab, unsigned char userbyte = 0x00,
60 MifareAccessInfo::SectorAccessBits *newsab = nullptr,
61 std::shared_ptr<MifareKey> newkeyA = std::shared_ptr<MifareKey>(),
62 std::shared_ptr<MifareKey> newkeyB = std::shared_ptr<MifareKey>()) final;
63
70 unsigned int getSectorFromMAD(long aid, std::shared_ptr<MifareKey> madKeyA);
71
79 void setSectorToMAD(long aid, unsigned int sector, std::shared_ptr<MifareKey> madKeyA,
80 std::shared_ptr<MifareKey> madKeyB);
81
88 static unsigned char calculateMADCrc(const unsigned char *madbuf, size_t madbuflen);
89
96 static unsigned int findReferencedSector(long aid, unsigned char *madbuf,
97 size_t madbuflen);
98
104 void authenticate(std::shared_ptr<Location> location, std::shared_ptr<AccessInfo> ai,
105 bool write = false);
106
107 void changeKeys(MifareKeyType keytype, std::shared_ptr<MifareKey> key,
108 std::shared_ptr<MifareKey> newkeyA,
109 std::shared_ptr<MifareKey> newkeyB, unsigned int sector,
110 MifareAccessInfo::SectorAccessBits *newsab,
111 unsigned char userbyte = 0x00);
112
113 void changeKeys(std::shared_ptr<MifareKey> newkeyA,
114 std::shared_ptr<MifareKey> newkeyB, unsigned int sector,
115 MifareAccessInfo::SectorAccessBits *newsab,
116 unsigned char userbyte = 0x00);
117
118 static MifareKeyType getKeyType(const MifareAccessInfo::SectorAccessBits &sab,
119 int sector, int block, bool write);
120
129 void authenticate(MifareKeyType keyType, std::shared_ptr<MifareKey> key, int sector,
130 int block, bool write);
131
138 virtual ByteVector readBinary(unsigned char blockno, size_t len) = 0;
139
147 virtual void updateBinary(unsigned char blockno, const ByteVector &buf) = 0;
148
157 virtual bool loadKey(unsigned char keyno, MifareKeyType keytype,
158 std::shared_ptr<MifareKey> key, bool vol = false) = 0;
159
166 virtual void loadKey(std::shared_ptr<Location> location, MifareKeyType keytype,
167 std::shared_ptr<MifareKey> key) = 0;
168
175 virtual void authenticate(unsigned char blockno, unsigned char keyno,
176 MifareKeyType keytype) = 0;
177
184 virtual void authenticate(unsigned char blockno,
185 std::shared_ptr<KeyStorage> key_storage,
186 MifareKeyType keytype) = 0;
187
196 virtual void increment(uint8_t blockno, uint32_t value) = 0;
197
206 virtual void decrement(uint8_t blockno, uint32_t value) = 0;
207
213 bool writeValueBlock(uint8_t blockno, int32_t value, uint8_t backup_blockno);
214
220 bool readValueBlock(uint8_t blockno, int32_t &value, uint8_t &backup_block);
221
227 static unsigned char getNbBlocks(int sector);
228
234 static unsigned char getSectorStartBlock(int sector);
235
236 protected:
237 std::shared_ptr<MifareChip> getMifareChip() const;
238};
239}
240
241#endif
LLA_CARDS_MIFARE_API void getMifareChip(std::shared_ptr< logicalaccess::Chip > *chip)
Definition: libraryentry.cpp:30
A Access informations. Describe key used of authentication and access rights for a specific or a grou...
Definition: accessinfo.hpp:22
The base commands class for all card commands.
Definition: commands.hpp:21
A Key storage base class. The key storage specify where the key is stored in memory....
Definition: keystorage.hpp:31
A location informations.
Definition: location.hpp:19
A Mifare access informations.
Definition: mifareaccessinfo.hpp:26
The Mifare base chip class.
Definition: mifarechip.hpp:25
The Mifare commands class.
Definition: mifarecommands.hpp:24
MifareCommands()
Definition: mifarecommands.hpp:26
MifareCommands(std::string ct)
Definition: mifarecommands.hpp:31
A Mifare Key class.
Definition: mifarekey.hpp:24
Commands.
std::vector< uint8_t > ByteVector
Definition: lla_fwd.hpp:80
Location.
MifareAccessInfo.
#define CMD_MIFARE
Definition: mifarecommands.hpp:16
Definition: asn1.hpp:9
MifareKeyType
Mifare Key Type.
Definition: mifareaccessinfo.hpp:18
Definition: urirecord.hpp:30
Sector access bits structure.
Definition: mifareaccessinfo.hpp:177