LibLogicalAccess  2.5.0
An Open Source RFID Library
Loading...
Searching...
No Matches
mifareplussl1commands.hpp
Go to the documentation of this file.
1
7#ifndef LOGICALACCESS_MIFAREPLUSSL1COMMANDS_HPP
8#define LOGICALACCESS_MIFAREPLUSSL1COMMANDS_HPP
9
12#include <logicalaccess/plugins/cards/mifareplus/lla_cards_mifareplus_api.hpp>
13
14namespace logicalaccess
15{
16#define CMD_MIFAREPLUSSL1 "MifarePlusSL1"
17
18class MifarePlusChip;
19
28class LLA_CARDS_MIFAREPLUS_API MifarePlusSL1Commands : public MifareCommands
29{
30 public:
33 {
34 }
35
36 explicit MifarePlusSL1Commands(std::string ct)
37 : MifareCommands(ct)
38 {
39 }
40
50 virtual bool AESAuthenticate(std::shared_ptr<AES128Key> key, uint16_t keyslot);
51
52 virtual bool AESAuthenticateSL1(std::shared_ptr<AES128Key> key);
53
58 virtual bool switchLevel2(std::shared_ptr<AES128Key> key);
59
63 virtual bool switchLevel3(std::shared_ptr<AES128Key> key);
64
65
66 ByteVector readBinary(unsigned char blockno, size_t len) override;
67
68 void updateBinary(unsigned char blockno, const ByteVector &buf) override;
69
70 bool loadKey(unsigned char keyno, MifareKeyType keytype,
71 std::shared_ptr<MifareKey> key, bool vol) override;
72
73 void loadKey(std::shared_ptr<Location> location, MifareKeyType keytype,
74 std::shared_ptr<MifareKey> key) override;
75
76 void authenticate(unsigned char blockno, unsigned char keyno,
77 MifareKeyType keytype) override;
78
79 void authenticate(unsigned char blockno, std::shared_ptr<KeyStorage> key_storage,
80 MifareKeyType keytype) override;
81
82 void increment(uint8_t blockno, uint32_t value) override;
83
84 void decrement(uint8_t blockno, uint32_t value) override;
85};
86
96template <typename MifareSL1Impl, typename MifareClassicImpl>
98{
99 public:
101 {
102 }
103
104 void fixup()
105 {
106 classic_impl.setChip(getChip());
107 classic_impl.setReaderCardAdapter(getReaderCardAdapter());
108
109 sl1_impl_.setChip(getChip());
110 sl1_impl_.setReaderCardAdapter(getReaderCardAdapter());
111 }
112
113 bool AESAuthenticateSL1(std::shared_ptr<AES128Key> key) override
114 {
115 fixup();
116 return sl1_impl_.AESAuthenticateSL1(key);
117 }
118
119 void authenticate(unsigned char blockno, unsigned char keyno,
120 MifareKeyType keytype) override
121 {
122 fixup();
123 classic_impl.authenticate(blockno, keyno, keytype);
124 }
125
126 ByteVector readBinary(unsigned char blockno, size_t len) override
127 {
128 fixup();
129 return classic_impl.readBinary(blockno, len);
130 }
131
132 void updateBinary(unsigned char blockno, const ByteVector &buf) override
133 {
134 fixup();
135 classic_impl.updateBinary(blockno, buf);
136 }
137
138 bool loadKey(unsigned char keyno, MifareKeyType keytype,
139 std::shared_ptr<MifareKey> key, bool vol) override
140 {
141 fixup();
142 return classic_impl.loadKey(keyno, keytype, key, vol);
143 }
144
145 void loadKey(std::shared_ptr<Location> location, MifareKeyType keytype,
146 std::shared_ptr<MifareKey> key) override
147 {
148 fixup();
149 classic_impl.loadKey(location, keytype, key);
150 }
151
152 void authenticate(unsigned char blockno, std::shared_ptr<KeyStorage> key_storage,
153 MifareKeyType keytype) override
154 {
155 fixup();
156 classic_impl.authenticate(blockno, key_storage, keytype);
157 }
158
159 void increment(uint8_t blockno, uint32_t value) override
160 {
161 fixup();
162 classic_impl.increment(blockno, value);
163 }
164
165 void decrement(uint8_t blockno, uint32_t value) override
166 {
167 fixup();
168 classic_impl.decrement(blockno, value);
169 }
170
171 MifareSL1Impl sl1_impl_;
172 MifareClassicImpl classic_impl;
173};
174}
175
176#endif /* LOGICALACCESS_MIFAREPLUSSL1COMMANDS_HPP */
AES128 key.
std::shared_ptr< ReaderCardAdapter > getReaderCardAdapter() const override
Get the reader/card adapter.
Definition: commands.hpp:52
std::shared_ptr< Chip > getChip() const override
Get the chip.
Definition: commands.hpp:34
The Mifare commands class.
Definition: mifarecommands.hpp:24
Definition: mifareplussl1commands.hpp:29
MifarePlusSL1Commands()
Definition: mifareplussl1commands.hpp:31
MifarePlusSL1Commands(std::string ct)
Definition: mifareplussl1commands.hpp:36
Definition: mifareplussl1commands.hpp:98
void authenticate(unsigned char blockno, unsigned char keyno, MifareKeyType keytype) override
Authenticate a block, given a key number.
Definition: mifareplussl1commands.hpp:119
void increment(uint8_t blockno, uint32_t value) override
Definition: mifareplussl1commands.hpp:159
void loadKey(std::shared_ptr< Location > location, MifareKeyType keytype, std::shared_ptr< MifareKey > key) override
Load a key on a given location.
Definition: mifareplussl1commands.hpp:145
MifareSL1Impl sl1_impl_
Definition: mifareplussl1commands.hpp:171
bool loadKey(unsigned char keyno, MifareKeyType keytype, std::shared_ptr< MifareKey > key, bool vol) override
Load a key to the reader.
Definition: mifareplussl1commands.hpp:138
void decrement(uint8_t blockno, uint32_t value) override
Definition: mifareplussl1commands.hpp:165
void updateBinary(unsigned char blockno, const ByteVector &buf) override
Write bytes to the card.
Definition: mifareplussl1commands.hpp:132
void authenticate(unsigned char blockno, std::shared_ptr< KeyStorage > key_storage, MifareKeyType keytype) override
Authenticate a block, given a key number.
Definition: mifareplussl1commands.hpp:152
MifarePlusSL1Policy()
Definition: mifareplussl1commands.hpp:100
void fixup()
Definition: mifareplussl1commands.hpp:104
MifareClassicImpl classic_impl
Definition: mifareplussl1commands.hpp:172
ByteVector readBinary(unsigned char blockno, size_t len) override
Read bytes from the card.
Definition: mifareplussl1commands.hpp:126
bool AESAuthenticateSL1(std::shared_ptr< AES128Key > key) override
Definition: mifareplussl1commands.hpp:113
std::vector< uint8_t > ByteVector
Definition: lla_fwd.hpp:80
Mifare commands.
#define CMD_MIFAREPLUSSL1
Definition: mifareplussl1commands.hpp:16
Definition: asn1.hpp:9
MifareKeyType
Mifare Key Type.
Definition: mifareaccessinfo.hpp:18