LibLogicalAccess  2.5.0
An Open Source RFID Library
Loading...
Searching...
No Matches
desfireiso7816commands.hpp
Go to the documentation of this file.
1
7#ifndef LOGICALACCESS_DESFIREISO7816CARDPROVIDER_HPP
8#define LOGICALACCESS_DESFIREISO7816CARDPROVIDER_HPP
9
15#include <logicalaccess/plugins/readers/iso7816/lla_readers_iso7816_api.hpp>
16#include <string>
17#include <vector>
18#include <iostream>
20
21namespace logicalaccess
22{
23#define DESFIRE_CLEAR_DATA_LENGTH_CHUNK 32
24#define CMD_DESFIREISO7816 "DESFireISO7816"
25
29class LLA_READERS_ISO7816_API DESFireISO7816Commands : public DESFireCommands
30{
31 public:
36
37 explicit DESFireISO7816Commands(std::string);
38
43
48 void setChip(std::shared_ptr<Chip> chip) override;
49
53 void erase() override;
54
59 void selectApplication(unsigned int aid) override;
60
67 void createApplication(unsigned int aid, DESFireKeySettings settings,
68 unsigned char maxNbKeys) override;
69
74 void deleteApplication(unsigned int aid) override;
75
80 std::vector<unsigned int> getApplicationIDs() override;
81
87 void changeKey(unsigned char keyno, std::shared_ptr<DESFireKey> key) override;
88
94 void getKeySettings(DESFireKeySettings &settings, unsigned char &maxNbKeys) override;
95
100 virtual uint8_t getKeyVersion(uint8_t keyno);
101
106 void changeKeySettings(DESFireKeySettings settings) override;
107
113 ByteVector getFileIDs() override;
114
120 FileSetting getFileSettings(unsigned char fileno) override;
121
129 void changeFileSettings(unsigned char fileno, EncryptionMode comSettings,
130 const DESFireAccessRights &accessRights, bool plain) override;
131
139 void createStdDataFile(unsigned char fileno, EncryptionMode comSettings,
140 const DESFireAccessRights &accessRights,
141 unsigned int fileSize) override;
142
150 void createBackupFile(unsigned char fileno, EncryptionMode comSettings,
151 const DESFireAccessRights &accessRights,
152 unsigned int fileSize) override;
153
164 void createValueFile(unsigned char fileno, EncryptionMode comSettings,
165 const DESFireAccessRights &accessRights, int32_t lowerLimit,
166 int32_t upperLimit, int32_t value,
167 bool limitedCreditEnabled) override;
168
177 void createLinearRecordFile(unsigned char fileno, EncryptionMode comSettings,
178 const DESFireAccessRights &accessRights,
179 unsigned int fileSize,
180 unsigned int maxNumberOfRecords) override;
181
190 void createCyclicRecordFile(unsigned char fileno, EncryptionMode comSettings,
191 const DESFireAccessRights &accessRights,
192 unsigned int fileSize,
193 unsigned int maxNumberOfRecords) override;
194
199 void deleteFile(unsigned char fileno) override;
200
209 ByteVector readData(unsigned char fileno, unsigned int offset, unsigned int length,
210 EncryptionMode mode) override;
211
219 void writeData(unsigned char fileno, unsigned int offset, const ByteVector &data,
220 EncryptionMode mode) override;
221
229 int32_t getValue(unsigned char fileno, EncryptionMode mode) override;
230
237 void credit(unsigned char fileno, unsigned int value, EncryptionMode mode) override;
238
245 void debit(unsigned char fileno, unsigned int value, EncryptionMode mode) override;
246
254 void limitedCredit(unsigned char fileno, int32_t value,
255 EncryptionMode mode) override;
256
265 void writeRecord(unsigned char fileno, unsigned int offset, const ByteVector &data,
266 EncryptionMode mode) override;
267
277 ByteVector readRecords(unsigned char fileno, unsigned int offset, unsigned int length,
278 EncryptionMode mode) override;
279
284 void clearRecordFile(unsigned char fileno) override;
285
289 void commitTransaction() override;
290
294 void abortTransaction() override;
295
300 void authenticate(unsigned char keyno = 0) override;
301
307 void authenticate(unsigned char keyno, std::shared_ptr<DESFireKey> key) override;
308
313 DESFireCardVersion getVersion() override;
314
319 std::shared_ptr<ISO7816ReaderCardAdapter> getISO7816ReaderCardAdapter() const
320 {
321 return std::dynamic_pointer_cast<ISO7816ReaderCardAdapter>(
322 getReaderCardAdapter());
323 }
324
329 void setSAMChip(std::shared_ptr<SAMChip> t)
330 {
331 d_SAM_chip = t;
332 }
333
337 std::shared_ptr<SAMChip> getSAMChip() const
338 {
339 return d_SAM_chip;
340 }
341
345 void getKeyFromSAM(std::shared_ptr<DESFireKey> key, ByteVector diversify) const;
346
347 ByteVector sam_authenticate_p1(std::shared_ptr<DESFireKey> key, ByteVector rndb,
348 ByteVector diversify) const;
349
350 void sam_authenticate_p2(unsigned char keyno, ByteVector rndap) const;
351
352 protected:
353 ByteVector getKeyInformations(std::shared_ptr<DESFireKey> key, uint8_t keyno) const;
354
355 ByteVector getChangeKeySAMCryptogram(unsigned char keyno,
356 std::shared_ptr<DESFireKey> key) const;
357
358 ByteVector getChangeKeyIKSCryptogram(unsigned char keyno,
359 std::shared_ptr<DESFireKey> key) const;
360
369 virtual ByteVector handleReadData(unsigned char err, const ByteVector &firstMsg,
370 unsigned int length, EncryptionMode mode);
371
379 virtual void handleWriteData(unsigned char cmd, const ByteVector &parameters,
380 const ByteVector &data, EncryptionMode mode);
381
388 virtual ISO7816Response transmit(unsigned char cmd, unsigned char lc);
389
398 virtual ISO7816Response transmit(unsigned char cmd,
399 const ByteVector &data = ByteVector(),
400 unsigned char lc = 0, bool forceLc = false);
401
402 bool checkChangeKeySAMKeyStorage(unsigned char keyno,
403 std::shared_ptr<DESFireKey> oldkey,
404 std::shared_ptr<DESFireKey> key);
405
409 std::shared_ptr<SAMChip> d_SAM_chip;
410};
411}
412
413#endif /* LOGICALACCESS_DESFIREISO7816COMMANDS_HPP */
The DESFire commands class.
Definition: desfirecommands.hpp:130
The DESFire base commands class.
Definition: desfireiso7816commands.hpp:30
std::shared_ptr< SAMChip > d_SAM_chip
The SAMChip used for the SAM Commands.
Definition: desfireiso7816commands.hpp:409
void setSAMChip(std::shared_ptr< SAMChip > t)
Set the SAM Chip.
Definition: desfireiso7816commands.hpp:329
std::shared_ptr< SAMChip > getSAMChip() const
get the SAM Chip.
Definition: desfireiso7816commands.hpp:337
std::shared_ptr< ISO7816ReaderCardAdapter > getISO7816ReaderCardAdapter() const
Get the ISO7816 reader/card adapter.
Definition: desfireiso7816commands.hpp:319
A ISO7816 response message.
Definition: iso7816response.hpp:21
DESFire commands.
DESFireCrypto.
Default ISO7816 reader/card adapter.
std::vector< uint8_t > ByteVector
Definition: lla_fwd.hpp:80
Definition: asn1.hpp:9
EncryptionMode
The file communication mode (or encryption mode)
Definition: desfirelocation.hpp:18
DESFireKeySettings
The key settings.
Definition: desfirecommands.hpp:69
SAM chip.
SAM key storage description.
Access rights on DESFire file.
Definition: desfirecommands.hpp:106
Card information about software and hardware version.
Definition: desfirecommands.hpp:212
Describe file setting.
Definition: desfirecommands.hpp:191