BALTECH SDK wrapper functions reference
desfire.h
Go to the documentation of this file.
1 
12 #ifndef __BRP_BALTECH_SDK_CMDS_DESFIRE_H__
13 #define __BRP_BALTECH_SDK_CMDS_DESFIRE_H__
14 #include "../typedefs.h"
18 #define BRP_Desfire_ErrIso14NoTag BRP_ERR_STATUS(0x1B00, 0x01)
19 
24 #define BRP_Desfire_ErrBreak BRP_ERR_STATUS(0x1B00, 0x03)
25 
28 #define BRP_Desfire_ErrIso14Hf BRP_ERR_STATUS(0x1B00, 0x04)
29 
32 #define BRP_Desfire_ErrIso14CardInvalid BRP_ERR_STATUS(0x1B00, 0x05)
33 
36 #define BRP_Desfire_ErrReaderChipCommunication BRP_ERR_STATUS(0x1B00, 0x06)
37 
40 #define BRP_Desfire_ErrIso14ApduCmd BRP_ERR_STATUS(0x1B00, 0x07)
41 
44 #define BRP_Desfire_ErrIso14InvalidResponse BRP_ERR_STATUS(0x1B00, 0x08)
45 
48 #define BRP_Desfire_ErrPcdAuthentication BRP_ERR_STATUS(0x1B00, 0x09)
49 
52 #define BRP_Desfire_ErrIntegrity BRP_ERR_STATUS(0x1B00, 0x0A)
53 
56 #define BRP_Desfire_ErrPcdKey BRP_ERR_STATUS(0x1B00, 0x0B)
57 
60 #define BRP_Desfire_ErrNoChanges BRP_ERR_STATUS(0x1B00, 0x0C)
61 
64 #define BRP_Desfire_ErrPcdParam BRP_ERR_STATUS(0x1B00, 0x0D)
65 
68 #define BRP_Desfire_VcsAndProxCheckError BRP_ERR_STATUS(0x1B00, 0x0F)
69 
72 #define BRP_Desfire_ErrFirmwareNotSupported BRP_ERR_STATUS(0x1B00, 0x10)
73 
76 #define BRP_Desfire_ErrSamCommunication BRP_ERR_STATUS(0x1B00, 0x11)
77 
80 #define BRP_Desfire_ErrSamUnlock BRP_ERR_STATUS(0x1B00, 0x12)
81 
86 #define BRP_Desfire_ErrHardwareNotSupported BRP_ERR_STATUS(0x1B00, 0x13)
87 
90 #define BRP_Desfire_ErrIllegalCmdLegacy BRP_ERR_STATUS(0x1B00, 0x1C)
91 
94 #define BRP_Desfire_ErrLength BRP_ERR_STATUS(0x1B00, 0x20)
95 
98 #define BRP_Desfire_ErrPermissionDenied BRP_ERR_STATUS(0x1B00, 0x21)
99 
102 #define BRP_Desfire_ErrParameter BRP_ERR_STATUS(0x1B00, 0x22)
103 
106 #define BRP_Desfire_ErrAppNotFound BRP_ERR_STATUS(0x1B00, 0x23)
107 
110 #define BRP_Desfire_ErrAppIntegrity BRP_ERR_STATUS(0x1B00, 0x24)
111 
114 #define BRP_Desfire_ErrAuthentication BRP_ERR_STATUS(0x1B00, 0x25)
115 
118 #define BRP_Desfire_ErrBoundary BRP_ERR_STATUS(0x1B00, 0x27)
119 
122 #define BRP_Desfire_ErrPiccIntegrity BRP_ERR_STATUS(0x1B00, 0x28)
123 
126 #define BRP_Desfire_ErrCommandAborted BRP_ERR_STATUS(0x1B00, 0x29)
127 
130 #define BRP_Desfire_ErrPiccDisabled BRP_ERR_STATUS(0x1B00, 0x2A)
131 
134 #define BRP_Desfire_ErrCount BRP_ERR_STATUS(0x1B00, 0x2B)
135 
138 #define BRP_Desfire_ErrDuplicate BRP_ERR_STATUS(0x1B00, 0x2C)
139 
142 #define BRP_Desfire_ErrEeprom BRP_ERR_STATUS(0x1B00, 0x2D)
143 
146 #define BRP_Desfire_ErrFileNotFound BRP_ERR_STATUS(0x1B00, 0x2E)
147 
150 #define BRP_Desfire_ErrFileIntegrity BRP_ERR_STATUS(0x1B00, 0x2F)
151 
154 #define BRP_Desfire_ErrNoSuchKey BRP_ERR_STATUS(0x1B00, 0x30)
155 
158 #define BRP_Desfire_ErrOutOfMemory BRP_ERR_STATUS(0x1B00, 0x32)
159 
162 #define BRP_Desfire_ErrIllegalCmd BRP_ERR_STATUS(0x1B00, 0x33)
163 
166 #define BRP_Desfire_ErrCmdOverflow BRP_ERR_STATUS(0x1B00, 0x34)
167 typedef struct {
169  unsigned Cmd;
171  size_t Header_len;
173  size_t Param_len;
175  unsigned ResponseLen;
177  size_t* Resp_len;
200 #ifdef BRP_SUPPORT_LEGACY_METHODS
201 brp_errcode brp_Desfire_ExecCommand(brp_protocol protocol, unsigned Cmd, brp_buf Header, size_t Header_len, brp_buf Param, size_t Param_len, brp_Desfire_ExecCommand_CryptoMode CryptoMode, unsigned ResponseLen, brp_buf* Resp, size_t* Resp_len, brp_mempool *mempool);
202 #else
204 #endif
205 typedef struct {
208  unsigned DesKeynr;
209  unsigned KeyId;
215  unsigned KeyExtIdx;
234 #ifdef BRP_SUPPORT_LEGACY_METHODS
235 brp_errcode brp_Desfire_Authenticate(brp_protocol protocol, brp_Desfire_Authenticate_SecureMessaging SecureMessaging, unsigned DesKeynr, unsigned KeyId, bool KeyHasDivData, brp_Desfire_Authenticate_KeyDivMode KeyDivMode, bool KeyHasExtIdx, brp_buf KeyDivData, size_t KeyDivData_len, unsigned KeyExtIdx);
236 #else
238 #endif
239 typedef struct {
242  unsigned DesKeyNr;
245  size_t Key_len;
262 #ifdef BRP_SUPPORT_LEGACY_METHODS
263 brp_errcode brp_Desfire_AuthExtKey(brp_protocol protocol, brp_Desfire_AuthExtKey_SecureMessaging SecureMessaging, unsigned DesKeyNr, brp_Desfire_AuthExtKey_CryptoMode CryptoMode, brp_buf Key, size_t Key_len);
264 #else
266 #endif
267 typedef struct {
269  unsigned AppId;
278 #ifdef BRP_SUPPORT_LEGACY_METHODS
279 brp_errcode brp_Desfire_SelectApplication(brp_protocol protocol, unsigned AppId);
280 #else
282 #endif
283 typedef struct {
285  unsigned FileId;
286  unsigned Adr;
287  unsigned Len;
290  size_t* Data_len;
306 #ifdef BRP_SUPPORT_LEGACY_METHODS
307 brp_errcode brp_Desfire_ReadData(brp_protocol protocol, unsigned FileId, unsigned Adr, unsigned Len, brp_Desfire_ReadData_Mode Mode, brp_buf* Data, size_t* Data_len, brp_mempool *mempool);
308 #else
310 #endif
311 typedef struct {
313  unsigned FileId;
314  unsigned Adr;
316  size_t Data_len;
330 #ifdef BRP_SUPPORT_LEGACY_METHODS
331 brp_errcode brp_Desfire_WriteData(brp_protocol protocol, unsigned FileId, unsigned Adr, brp_buf Data, size_t Data_len, brp_Desfire_WriteData_Mode Mode);
332 #else
334 #endif
335 typedef struct {
338  bool IsKeySet;
339  bool IsAesKey;
340  bool IsVersion;
342  unsigned KeyNo;
343  unsigned KeyVersion;
345  size_t NewKey_len;
347  size_t OldKey_len;
348  unsigned KeySet;
374 #ifdef BRP_SUPPORT_LEGACY_METHODS
375 brp_errcode brp_Desfire_ChangeExtKey(brp_protocol protocol, brp_Desfire_ChangeExtKey_MasterKeyType MasterKeyType, bool IsKeySet, bool IsAesKey, bool IsVersion, bool IsChangeKey, unsigned KeyNo, unsigned KeyVersion, brp_buf NewKey, size_t NewKey_len, brp_buf OldKey, size_t OldKey_len, unsigned KeySet);
376 #else
378 #endif
379 typedef struct {
381  bool IsKeySet;
384  unsigned KeyNr;
388  unsigned NewKeyIdx;
392  unsigned CurKeyIdx;
397  unsigned NewKeyExtIdx;
398  unsigned CurKeyExtIdx;
399  unsigned KeySet;
426 #ifdef BRP_SUPPORT_LEGACY_METHODS
427 brp_errcode brp_Desfire_ChangeKey(brp_protocol protocol, bool IsKeySet, bool IsMasterKey, bool IsChangeKey, unsigned KeyNr, brp_Desfire_ChangeKey_NewKeyDivMode NewKeyDivMode, bool NewKeyHasDivData, bool NewKeyHasExtIdx, unsigned NewKeyIdx, brp_Desfire_ChangeKey_CurKeyDivMode CurKeyDivMode, bool CurKeyHasDivData, bool CurKeyHasExtIdx, unsigned CurKeyIdx, brp_buf NewKeyDivData, size_t NewKeyDivData_len, brp_buf CurKeyDivData, size_t CurKeyDivData_len, unsigned NewKeyExtIdx, unsigned CurKeyExtIdx, unsigned KeySet);
428 #else
430 #endif
431 typedef struct {
442 #ifdef BRP_SUPPORT_LEGACY_METHODS
444 #else
446 #endif
447 typedef struct {
458 #ifdef BRP_SUPPORT_LEGACY_METHODS
460 #else
462 #endif
463 typedef struct {
465  unsigned AppId;
486 #ifdef BRP_SUPPORT_LEGACY_METHODS
487 brp_errcode brp_Desfire_CreateDam(brp_protocol protocol, unsigned AppId, brp_buf AppParams, size_t AppParams_len, brp_buf EncryptedDefaultDamKey, size_t EncryptedDefaultDamKey_len, brp_buf DamMacKey, size_t DamMacKey_len);
488 #else
490 #endif
491 typedef struct {
494  size_t* Signature_len;
506 #ifdef BRP_SUPPORT_LEGACY_METHODS
507 brp_errcode brp_Desfire_GetOriginalitySignature(brp_protocol protocol, brp_buf* Signature, size_t* Signature_len, brp_mempool *mempool);
508 #else
510 #endif
511 typedef struct {
515  unsigned DiversifyMacKey;
519  size_t IID_len;
520  unsigned EncKeyIdx;
521  unsigned MacKeyIdx;
523  size_t DivData_len;
525  size_t EncKey_len;
527  size_t MacKey_len;
528  unsigned* FciType;
530  size_t* Fci_len;
558 #ifdef BRP_SUPPORT_LEGACY_METHODS
559 brp_errcode brp_Desfire_VirtualCardSelect(brp_protocol protocol, bool ForceVcsAuthentication, bool UseExtVcSelectKeys, unsigned DiversifyMacKey, bool DiversifyEncKey, bool UseVcSelectKeys, brp_buf IID, size_t IID_len, unsigned EncKeyIdx, unsigned MacKeyIdx, brp_buf DivData, size_t DivData_len, brp_buf EncKey, size_t EncKey_len, brp_buf MacKey, size_t MacKey_len, unsigned* FciType, brp_buf* Fci, size_t* Fci_len, brp_mempool *mempool);
560 #else
562 #endif
563 typedef struct {
565  unsigned M;
569  unsigned ProxKeyIdx;
571  size_t DivData_len;
573  size_t ProxKey_len;
590 #ifdef BRP_SUPPORT_LEGACY_METHODS
591 brp_errcode brp_Desfire_ProxCheck(brp_protocol protocol, unsigned M, bool UseExtProxKey, bool DiversifyProxKey, bool UseProxKey, unsigned ProxKeyIdx, brp_buf DivData, size_t DivData_len, brp_buf ProxKey, size_t ProxKey_len);
592 #else
594 #endif
595 typedef struct {
598  size_t* AppNr_len;
610 #ifdef BRP_SUPPORT_LEGACY_METHODS
612 #else
614 #endif
615 #endif
616 
brp_Desfire_WriteData_Mode
Communication settings linked to the file.
Definition: typedefs.h:748
brp_protocol protocol
Definition: desfire.h:240
brp_errcode brp_Desfire_VirtualCardSelect(brp_Desfire_VirtualCardSelect_t params)
This command selects a virtual card.
brp_errcode brp_Desfire_ResetAuthentication(brp_Desfire_ResetAuthentication_t params)
This command resets the reader's authentication state until the next call of the brp_Desfire_Authenti...
brp_protocol protocol
Definition: desfire.h:596
brp_Desfire_ChangeExtKey_MasterKeyType MasterKeyType
Definition: desfire.h:337
brp_Desfire_Authenticate_KeyDivMode
Specifies diversification algorithm.
Definition: typedefs.h:668
unsigned int brp_errcode
This type is used library-wide for passing error codes in the return value of functions.
Definition: errorcodes.h:23
brp_Desfire_WriteData_Mode Mode
Definition: desfire.h:317
brp_errcode brp_Desfire_ChangeExtKey(brp_Desfire_ChangeExtKey_t params)
This command allows to change any key stored on the card.
brp_Desfire_SetFraming_CommMode
Defines 14443-4 communication mode to DESFire card.
Definition: typedefs.h:820
brp_errcode brp_Desfire_GetOriginalitySignature(brp_Desfire_GetOriginalitySignature_t params)
This command returns the NXP originality signature of a desfire card.
struct brp_protocol_t * brp_protocol
This is a generic handle of a protocol.
Definition: protocol.h:34
brp_mempool * mempool
Definition: desfire.h:178
brp_protocol protocol
Definition: desfire.h:564
Definition: typedefs.h:834
brp_protocol protocol
Definition: desfire.h:206
brp_Desfire_AuthExtKey_CryptoMode
Sets the encryption algorithm.
Definition: typedefs.h:708
brp_Desfire_ChangeExtKey_MasterKeyType
These bits must only be set if the card's Master Key is changed.
Definition: typedefs.h:766
struct brp_mempool_object_t * brp_mempool
mempool handle.
Definition: mempool.h:29
brp_Desfire_ChangeKey_NewKeyDivMode
Specifies diversification algorithm.
Definition: typedefs.h:784
brp_protocol protocol
Definition: desfire.h:380
brp_protocol protocol
Definition: desfire.h:432
brp_protocol protocol
Definition: desfire.h:284
brp_Desfire_SetFraming_CommMode CommMode
Definition: desfire.h:433
brp_errcode brp_Desfire_SelectApplication(brp_Desfire_SelectApplication_t params)
Selects an application of the DESFire card.
size_t EncryptedDefaultDamKey_len
Definition: desfire.h:469
brp_protocol protocol
Definition: desfire.h:336
brp_Desfire_ReadData_Mode
Communication settings linked to the file.
Definition: typedefs.h:730
brp_errcode brp_Desfire_SetFraming(brp_Desfire_SetFraming_t params)
This command switches the DESFire communication protocol mode to use (std, iso_wrapping).
brp_protocol protocol
Definition: desfire.h:464
brp_Desfire_ChangeKey_NewKeyDivMode NewKeyDivMode
Definition: desfire.h:385
brp_protocol protocol
Definition: desfire.h:168
brp_buf EncryptedDefaultDamKey
Definition: desfire.h:468
brp_errcode brp_Desfire_ExecCommand(brp_Desfire_ExecCommand_t params)
Generic command to communicate to a DESFire card.
brp_Desfire_AuthExtKey_CryptoMode CryptoMode
Definition: desfire.h:243
brp_mempool * mempool
Definition: desfire.h:599
brp_Desfire_AuthExtKey_SecureMessaging
Sets the secure messaging mode.
Definition: typedefs.h:690
brp_mempool * mempool
Definition: desfire.h:291
brp_Desfire_GetDfNames_AppNr_Entry ** AppNr
Definition: desfire.h:597
brp_errcode brp_Desfire_ChangeKey(brp_Desfire_ChangeKey_t params)
Modifies a DESFire card key defined in the SAM or crypto memory.
brp_Desfire_Authenticate_KeyDivMode KeyDivMode
Definition: desfire.h:211
brp_Desfire_ChangeKey_CurKeyDivMode CurKeyDivMode
Definition: desfire.h:389
brp_errcode brp_Desfire_WriteData(brp_Desfire_WriteData_t params)
Writes data to a Standard or a Backup data file.
brp_protocol protocol
Definition: desfire.h:312
brp_Desfire_Authenticate_SecureMessaging SecureMessaging
Definition: desfire.h:207
brp_Desfire_ExecCommand_CryptoMode CryptoMode
Definition: desfire.h:174
brp_errcode brp_Desfire_Authenticate(brp_Desfire_Authenticate_t params)
This command authenticates a card with the reader.
brp_Desfire_ChangeKey_CurKeyDivMode
Specifies diversification algorithm.
Definition: typedefs.h:802
unsigned char * brp_buf
represents a pointer to a protocol data buffer.
Definition: common.h:61
brp_Desfire_ExecCommand_CryptoMode
Type of encryption.
Definition: typedefs.h:632
brp_Desfire_ReadData_Mode Mode
Definition: desfire.h:288
brp_errcode brp_Desfire_ProxCheck(brp_Desfire_ProxCheck_t params)
This command executes a proximity check of the card.
brp_Desfire_AuthExtKey_SecureMessaging SecureMessaging
Definition: desfire.h:241
brp_errcode brp_Desfire_GetDfNames(brp_Desfire_GetDfNames_t params)
This command returns the application identifiers together with file IDs and (optionally) DF names of ...
brp_Desfire_Authenticate_SecureMessaging
Sets the secure messaging mode.
Definition: typedefs.h:650
brp_errcode brp_Desfire_AuthExtKey(brp_Desfire_AuthExtKey_t params)
This command authenticates a card with the reader, similarly to the brp_Desfire_Authenticate() comman...
brp_errcode brp_Desfire_ReadData(brp_Desfire_ReadData_t params)
Reads data from a Standard or Backup data file.
brp_errcode brp_Desfire_CreateDam(brp_Desfire_CreateDam_t params)
This command creates a delegated application.