Chameleon-Mini
MifareDESFire.h
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * MifareDesfire.h
24  * MIFARE DESFire frontend
25  *
26  * Created on: 14.10.2016
27  * Author: dev_zzo
28  */
29 
30 #ifndef MIFAREDESFIRE_H_
31 #define MIFAREDESFIRE_H_
32 
33 #include "Application.h"
34 #include "DESFire/DESFireFirmwareSettings.h"
35 #include "DESFire/DESFirePICCHeaderLayout.h"
36 #include "DESFire/DESFireISO14443Support.h"
37 #include "DESFire/DESFireISO7816Support.h"
38 #include "DESFire/DESFireInstructions.h"
39 
40 /* The core functions used outside of this implementation
41  * to describe the DESFire emulation to the Chameleon firmware:
42  */
43 void ResetLocalStructureData(void);
44 void MifareDesfireReset(void);
45 void MifareDesfireEV0AppInit(void);
46 void MifareDesfire2kEV1AppInit(void);
47 void MifareDesfire4kEV1AppInit(void);
48 void MifareDesfire8kEV1AppInit(void);
49 void MifareDesfireAppReset(void);
50 void MifareDesfireAppTick(void);
51 void MifareDesfireAppTask(void);
52 
53 uint16_t MifareDesfireProcessCommand(uint8_t *Buffer, uint16_t ByteCount);
54 uint16_t MifareDesfireProcess(uint8_t *Buffer, uint16_t ByteCount);
55 uint16_t MifareDesfireAppProcess(uint8_t *Buffer, uint16_t BitCount);
56 
57 void MifareDesfireGetUid(ConfigurationUidType Uid);
58 void MifareDesfireSetUid(ConfigurationUidType Uid);
59 
60 /* Helper function definitions since we need them
61  * elsewhere in the backend, and so we do not need to
62  * declare them as static in the source.
63  */
64 #define DesfireCLA(cmdCode) \
65  ((cmdCode == DESFIRE_NATIVE_CLA) || Iso7816CLA(cmdCode))
66 
67 typedef enum DESFIRE_FIRMWARE_ENUM_PACKING {
68  DESFIRE_HALT,
69  DESFIRE_IDLE,
70  DESFIRE_IDLE2,
71  DESFIRE_GET_VERSION2,
72  DESFIRE_GET_VERSION3,
73  DESFIRE_GET_APPLICATION_IDS2,
74  DESFIRE_LEGACY_AUTHENTICATE,
75  DESFIRE_LEGACY_AUTHENTICATE2,
76  DESFIRE_ISO_AUTHENTICATE,
77  DESFIRE_ISO_AUTHENTICATE2,
78  DESFIRE_AES_AUTHENTICATE,
79  DESFIRE_AES_AUTHENTICATE2,
80  DESFIRE_READ_DATA_FILE,
81  DESFIRE_WRITE_DATA_FILE,
82 } DesfireStateType;
83 
84 extern DesfireStateType DesfireState;
85 extern DesfireStateType DesfirePreviousState;
86 extern bool DesfireFromHalt;
87 extern BYTE DesfireCmdCLA;
88 
89 #endif /* MIFAREDESFIRE_H_ */