Skip to content

Commit de798fb

Browse files
committed
Adding in preliminary AES transfer functions -- Trying to save space for more where it can be pruned -- III -- cf. emsec#313
1 parent a0cb74c commit de798fb

10 files changed

+75
-405
lines changed

Doc/DESFireSupportReadme.md

-17
Original file line numberDiff line numberDiff line change
@@ -204,23 +204,6 @@ DF_SETHDR=ATS 0675f7b102
204204
```
205205
Note that the UID for the tag can be set using separate Chameleon terminal commands.
206206

207-
#### DF_PPRINT_PICC -- Visualize tag contents
208-
209-
This lets users pretty print the tag layout in several different ways, and with
210-
a couple of options for verbosity. This helps with visualizing the landscape that
211-
we are programming. The syntax include:
212-
```bash
213-
DF_PPRINT_PICC FullImage
214-
DF_PPRINT_PICC HeaderData
215-
```
216-
217-
#### DF_FWINFO -- Print firmware revision information
218-
219-
Self explanatory and similar to the familiar ``VERSION`` command. Syntax:
220-
```bash
221-
DF_FWINFO
222-
```
223-
224207
#### DF_LOGMODE -- Sets the depth of (LIVE) logging messages printed at runtime
225208

226209
Syntax -- not guaranteeing that all of these are meaningful or distinct just yet:

Firmware/Chameleon-Mini/Application/DESFire/DESFireChameleonTerminal.c

-44
Original file line numberDiff line numberDiff line change
@@ -114,50 +114,6 @@ CommandStatusIdType CommandDESFireSetHeaderProperty(char *OutParam, const char *
114114
}
115115
#endif /* DISABLE_PERMISSIVE_DESFIRE_SETTINGS */
116116

117-
#if 0
118-
CommandStatusIdType CommandDESFireLayoutPPrint(char *OutParam, const char *InParams) {
119-
if (!IsDESFireConfiguration()) {
120-
ExitOnInvalidConfigurationError(OutParam);
121-
}
122-
char pprintListSpecStr[32];
123-
BYTE StatusError = 0x00;
124-
if (!sscanf_P(InParams, PSTR("%31s"), pprintListSpecStr)) {
125-
StatusError = 0x01;
126-
} else {
127-
pprintListSpecStr[31] = '\0';
128-
if (!strcasecmp_P(pprintListSpecStr, PSTR("FullImage"))) {
129-
PrettyPrintPICCImageData((BYTE *) OutParam, TERMINAL_BUFFER_SIZE, 0x01);
130-
} else if (!strcasecmp_P(pprintListSpecStr, PSTR("HeaderData"))) {
131-
PrettyPrintPICCHeaderData((BYTE *) OutParam, TERMINAL_BUFFER_SIZE, 0x01);
132-
} else {
133-
StatusError = 0x01;
134-
}
135-
}
136-
if (StatusError) {
137-
snprintf_P(OutParam, TERMINAL_BUFFER_SIZE,
138-
PSTR("%s <FullImage|HeaderData>"),
139-
DFCOMMAND_LAYOUT_PPRINT);
140-
return COMMAND_ERR_INVALID_USAGE_ID;
141-
}
142-
return COMMAND_INFO_OK_WITH_TEXT_ID;
143-
}
144-
145-
CommandStatusIdType CommandDESFireFirmwareInfo(char *OutParam) {
146-
if (!IsDESFireConfiguration()) {
147-
ExitOnInvalidConfigurationError(OutParam);
148-
}
149-
snprintf_P(OutParam, TERMINAL_BUFFER_SIZE,
150-
PSTR("Chameleon-Mini DESFire enabled firmware built on %s "
151-
"based on %s from \r\n"
152-
"https://github.com/maxieds/ChameleonMini.\r\n"
153-
"Revision: %s\r\n"),
154-
DESFIRE_FIRMWARE_BUILD_TIMESTAMP,
155-
DESFIRE_FIRMWARE_GIT_COMMIT_ID,
156-
DESFIRE_FIRMWARE_REVISION);
157-
return COMMAND_INFO_OK_WITH_TEXT_ID;
158-
}
159-
#endif
160-
161117
CommandStatusIdType CommandDESFireGetLoggingMode(char *OutParam) {
162118
if (!IsDESFireConfiguration()) {
163119
ExitOnInvalidConfigurationError(OutParam);

Firmware/Chameleon-Mini/Application/DESFire/DESFireChameleonTerminal.h

-6
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ CommandStatusIdType CommandDESFireGetHeaderProperty(char *OutParam);
4242
CommandStatusIdType CommandDESFireSetHeaderProperty(char *OutMessage, const char *InParams);
4343
#endif
4444

45-
//#define DFCOMMAND_LAYOUT_PPRINT "DF_PPRINT_PICC"
46-
//CommandStatusIdType CommandDESFireLayoutPPrint(char *OutParam, const char *InParams);
47-
48-
//#define DFCOMMAND_FIRMWARE_INFO "DF_FWINFO"
49-
//CommandStatusIdType CommandDESFireFirmwareInfo(char *OutParam);
50-
5145
#define DFCOMMAND_LOGGING_MODE "DF_LOGMODE"
5246
CommandStatusIdType CommandDESFireGetLoggingMode(char *OutParam);
5347
CommandStatusIdType CommandDESFireSetLoggingMode(char *OutMessage, const char *InParams);

Firmware/Chameleon-Mini/Application/DESFire/DESFireChameleonTerminalInclude.c

-12
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,6 @@ This notice must be retained at the top of all source files where indicated.
3535
.SetFunc = CommandDESFireSetHeaderProperty,
3636
.GetFunc = CommandDESFireGetHeaderProperty
3737
}, {
38-
// .Command = DFCOMMAND_LAYOUT_PPRINT,
39-
// .ExecFunc = NO_FUNCTION,
40-
// .ExecParamFunc = CommandDESFireLayoutPPrint,
41-
// .SetFunc = NO_FUNCTION,
42-
// .GetFunc = NO_FUNCTION
43-
//}, {
44-
// .Command = DFCOMMAND_FIRMWARE_INFO,
45-
// .ExecFunc = CommandDESFireFirmwareInfo,
46-
// .ExecParamFunc = NO_FUNCTION,
47-
// .SetFunc = NO_FUNCTION,
48-
// .GetFunc = NO_FUNCTION
49-
//}, {
5038
.Command = DFCOMMAND_LOGGING_MODE,
5139
.ExecFunc = NO_FUNCTION,
5240
.ExecParamFunc = NO_FUNCTION,

Firmware/Chameleon-Mini/Application/DESFire/DESFireInstructions.c

+62
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,68 @@ This notice must be retained at the top of all source files where indicated.
4545

4646
DesfireSavedCommandStateType DesfireCommandState = { 0 };
4747

48+
/* Helper and batch process functions */
49+
static uint16_t ExitWithStatus(uint8_t *Buffer, uint8_t StatusCode, uint16_t DefaultReturnValue);
50+
uint16_t CmdNotImplemented(uint8_t *Buffer, uint16_t ByteCount);
51+
52+
/* General commands */
53+
static uint16_t EV0CmdFormatPicc(uint8_t *Buffer, uint16_t ByteCount);
54+
static uint16_t DesfireCmdGetCardUID(uint8_t *Buffer, uint16_t ByteCount);
55+
static uint16_t DesfireCmdSetConfiguration(uint8_t *Buffer, uint16_t ByteCount); // ?? Docs ??
56+
static uint16_t DesfireCmdFreeMemory(uint8_t *Buffer, uint16_t ByteCount); // returns free memory on the tag
57+
58+
/* Key management commands */
59+
static uint16_t EV0CmdChangeKey(uint8_t *Buffer, uint16_t ByteCount);
60+
static uint16_t EV0CmdGetKeySettings(uint8_t *Buffer, uint16_t ByteCount);
61+
static uint16_t EV0CmdChangeKeySettings(uint8_t *Buffer, uint16_t ByteCount);
62+
static uint16_t DesfireCmdGetKeyVersion(uint8_t *Buffer, uint16_t ByteCount);
63+
64+
/* Application management commands */
65+
static uint16_t EV0CmdGetApplicationIds1(uint8_t *Buffer, uint16_t ByteCount);
66+
static uint16_t EV0CmdCreateApplication(uint8_t *Buffer, uint16_t ByteCount);
67+
static uint16_t EV0CmdDeleteApplication(uint8_t *Buffer, uint16_t ByteCount);
68+
static uint16_t EV0CmdSelectApplication(uint8_t *Buffer, uint16_t ByteCount);
69+
static uint16_t DesfireCmdGetDFNames(uint8_t *Buffer, uint16_t ByteCount);
70+
71+
/* File management commands */
72+
static uint16_t EV0CmdCreateStandardDataFile(uint8_t *Buffer, uint16_t ByteCount);
73+
static uint16_t EV0CmdCreateBackupDataFile(uint8_t *Buffer, uint16_t ByteCount);
74+
static uint16_t EV0CmdCreateValueFile(uint8_t *Buffer, uint16_t ByteCount);
75+
static uint16_t EV0CmdCreateLinearRecordFile(uint8_t *Buffer, uint16_t ByteCount);
76+
static uint16_t EV0CmdCreateCyclicRecordFile(uint8_t *Buffer, uint16_t ByteCount);
77+
static uint16_t EV0CmdDeleteFile(uint8_t *Buffer, uint16_t ByteCount);
78+
static uint16_t EV0CmdGetFileIds(uint8_t *Buffer, uint16_t ByteCount);
79+
static uint16_t EV0CmdGetFileSettings(uint8_t *Buffer, uint16_t ByteCount);
80+
static uint16_t EV0CmdChangeFileSettings(uint8_t *Buffer, uint16_t ByteCount);
81+
82+
/* Data manipulation commands */
83+
// NOTE: Page 57: Read file functions:
84+
static uint16_t EV0CmdReadData(uint8_t *Buffer, uint16_t ByteCount);
85+
static uint16_t EV0CmdWriteData(uint8_t *Buffer, uint16_t ByteCount);
86+
static uint16_t EV0CmdGetValue(uint8_t *Buffer, uint16_t ByteCount);
87+
static uint16_t EV0CmdCredit(uint8_t *Buffer, uint16_t ByteCount);
88+
static uint16_t EV0CmdDebit(uint8_t *Buffer, uint16_t ByteCount);
89+
static uint16_t EV0CmdLimitedCredit(uint8_t *Buffer, uint16_t ByteCount);
90+
static uint16_t EV0CmdReadRecords(uint8_t *Buffer, uint16_t ByteCount);
91+
static uint16_t EV0CmdWriteRecord(uint8_t *Buffer, uint16_t ByteCount);
92+
static uint16_t EV0CmdClearRecords(uint8_t *Buffer, uint16_t ByteCount);
93+
94+
/* Transaction handling commands */
95+
static uint16_t EV0CmdCommitTransaction(uint8_t *Buffer, uint16_t ByteCount);
96+
static uint16_t EV0CmdAbortTransaction(uint8_t *Buffer, uint16_t ByteCount);
97+
98+
/* ISO7816 command handling */
99+
static uint16_t ISO7816CmdSelect(uint8_t *Buffer, uint16_t ByteCount);
100+
static uint16_t ISO7816CmdSelectEF(uint8_t *Buffer, uint16_t ByteCount);
101+
static uint16_t ISO7816CmdSelectDF(uint8_t *Buffer, uint16_t ByteCount);
102+
static uint16_t ISO7816CmdGetChallenge(uint8_t *Buffer, uint16_t ByteCount);
103+
static uint16_t ISO7816CmdExternalAuthenticate(uint8_t *Buffer, uint16_t ByteCount);
104+
static uint16_t ISO7816CmdInternalAuthenticate(uint8_t *Buffer, uint16_t ByteCount);
105+
static uint16_t ISO7816CmdReadBinary(uint8_t *Buffer, uint16_t ByteCount);
106+
static uint16_t ISO7816CmdUpdateBinary(uint8_t *Buffer, uint16_t ByteCount);
107+
static uint16_t ISO7816CmdReadRecords(uint8_t *Buffer, uint16_t ByteCount);
108+
static uint16_t ISO7816CmdAppendRecord(uint8_t *Buffer, uint16_t ByteCount);
109+
48110
/* NOTE: The order of the structures in this buffer MUST be kept in
49111
* ascending sorted order by the INS code. This property of the
50112
* array has to be maintained as new commands and functions are

Firmware/Chameleon-Mini/Application/DESFire/DESFireInstructions.h

+1-61
Original file line numberDiff line numberDiff line change
@@ -122,81 +122,21 @@ extern const __flash DESFireCommand DESFireCommandSet[];
122122

123123
/* Helper and batch process functions */
124124
uint16_t CallInstructionHandler(uint8_t *Buffer, uint16_t ByteCount);
125-
uint16_t ExitWithStatus(uint8_t *Buffer, uint8_t StatusCode, uint16_t DefaultReturnValue);
126-
uint16_t CmdNotImplemented(uint8_t *Buffer, uint16_t ByteCount);
127125

128126
/*
129127
* The following section implements:
130128
* DESFire EV0 / D40 specific commands
131129
*/
132130

133-
/* General commands */
134131
uint16_t EV0CmdGetVersion1(uint8_t *Buffer, uint16_t ByteCount);
135132
uint16_t EV0CmdGetVersion2(uint8_t *Buffer, uint16_t ByteCount);
136133
uint16_t EV0CmdGetVersion3(uint8_t *Buffer, uint16_t ByteCount);
137-
uint16_t EV0CmdFormatPicc(uint8_t *Buffer, uint16_t ByteCount);
138-
uint16_t DesfireCmdGetCardUID(uint8_t *Buffer, uint16_t ByteCount);
139-
uint16_t DesfireCmdSetConfiguration(uint8_t *Buffer, uint16_t ByteCount); // ?? Docs ??
140-
uint16_t DesfireCmdFreeMemory(uint8_t *Buffer, uint16_t ByteCount); // returns free memory on the tag
141-
142-
/* Key management commands */
143-
uint16_t EV0CmdChangeKey(uint8_t *Buffer, uint16_t ByteCount);
144-
uint16_t EV0CmdGetKeySettings(uint8_t *Buffer, uint16_t ByteCount);
145-
uint16_t EV0CmdChangeKeySettings(uint8_t *Buffer, uint16_t ByteCount);
146-
uint16_t DesfireCmdGetKeyVersion(uint8_t *Buffer, uint16_t ByteCount);
147-
148-
/* Application management commands */
149-
uint16_t EV0CmdGetApplicationIds1(uint8_t *Buffer, uint16_t ByteCount);
150-
uint16_t EV0CmdCreateApplication(uint8_t *Buffer, uint16_t ByteCount);
151-
uint16_t EV0CmdDeleteApplication(uint8_t *Buffer, uint16_t ByteCount);
152-
uint16_t EV0CmdSelectApplication(uint8_t *Buffer, uint16_t ByteCount);
153-
uint16_t DesfireCmdGetDFNames(uint8_t *Buffer, uint16_t ByteCount);
154-
155-
/* File management commands */
156-
uint16_t EV0CmdCreateStandardDataFile(uint8_t *Buffer, uint16_t ByteCount);
157-
uint16_t EV0CmdCreateBackupDataFile(uint8_t *Buffer, uint16_t ByteCount);
158-
uint16_t EV0CmdCreateValueFile(uint8_t *Buffer, uint16_t ByteCount);
159-
uint16_t EV0CmdCreateLinearRecordFile(uint8_t *Buffer, uint16_t ByteCount);
160-
uint16_t EV0CmdCreateCyclicRecordFile(uint8_t *Buffer, uint16_t ByteCount);
161-
uint16_t EV0CmdDeleteFile(uint8_t *Buffer, uint16_t ByteCount);
162-
uint16_t EV0CmdGetFileIds(uint8_t *Buffer, uint16_t ByteCount);
163-
uint16_t EV0CmdGetFileSettings(uint8_t *Buffer, uint16_t ByteCount);
164-
uint16_t EV0CmdChangeFileSettings(uint8_t *Buffer, uint16_t ByteCount);
165-
166-
/* Data manipulation commands */
167-
// NOTE: Page 57: Read file functions:
168-
uint16_t EV0CmdReadData(uint8_t *Buffer, uint16_t ByteCount);
169-
uint16_t EV0CmdWriteData(uint8_t *Buffer, uint16_t ByteCount);
170-
uint16_t EV0CmdGetValue(uint8_t *Buffer, uint16_t ByteCount);
171-
uint16_t EV0CmdCredit(uint8_t *Buffer, uint16_t ByteCount);
172-
uint16_t EV0CmdDebit(uint8_t *Buffer, uint16_t ByteCount);
173-
uint16_t EV0CmdLimitedCredit(uint8_t *Buffer, uint16_t ByteCount);
174-
uint16_t EV0CmdReadRecords(uint8_t *Buffer, uint16_t ByteCount);
175-
uint16_t EV0CmdWriteRecord(uint8_t *Buffer, uint16_t ByteCount);
176-
uint16_t EV0CmdClearRecords(uint8_t *Buffer, uint16_t ByteCount);
177-
178-
/* Transaction handling commands */
179-
uint16_t EV0CmdCommitTransaction(uint8_t *Buffer, uint16_t ByteCount);
180-
uint16_t EV0CmdAbortTransaction(uint8_t *Buffer, uint16_t ByteCount);
181-
182-
/* EV1/EV2 supported commands */
183134
uint16_t EV0CmdAuthenticateLegacy1(uint8_t *Buffer, uint16_t ByteCount);
184135
uint16_t EV0CmdAuthenticateLegacy2(uint8_t *Buffer, uint16_t ByteCount);
136+
185137
uint16_t DesfireCmdAuthenticate3KTDEA1(uint8_t *Buffer, uint16_t ByteCount);
186138
uint16_t DesfireCmdAuthenticate3KTDEA2(uint8_t *Buffer, uint16_t ByteCount);
187139
uint16_t DesfireCmdAuthenticateAES1(uint8_t *Buffer, uint16_t ByteCount);
188140
uint16_t DesfireCmdAuthenticateAES2(uint8_t *Buffer, uint16_t ByteCount);
189141

190-
/* ISO7816 command handling */
191-
uint16_t ISO7816CmdSelect(uint8_t *Buffer, uint16_t ByteCount);
192-
uint16_t ISO7816CmdSelectEF(uint8_t *Buffer, uint16_t ByteCount);
193-
uint16_t ISO7816CmdSelectDF(uint8_t *Buffer, uint16_t ByteCount);
194-
uint16_t ISO7816CmdGetChallenge(uint8_t *Buffer, uint16_t ByteCount);
195-
uint16_t ISO7816CmdExternalAuthenticate(uint8_t *Buffer, uint16_t ByteCount);
196-
uint16_t ISO7816CmdInternalAuthenticate(uint8_t *Buffer, uint16_t ByteCount);
197-
uint16_t ISO7816CmdReadBinary(uint8_t *Buffer, uint16_t ByteCount);
198-
uint16_t ISO7816CmdUpdateBinary(uint8_t *Buffer, uint16_t ByteCount);
199-
uint16_t ISO7816CmdReadRecords(uint8_t *Buffer, uint16_t ByteCount);
200-
uint16_t ISO7816CmdAppendRecord(uint8_t *Buffer, uint16_t ByteCount);
201-
202142
#endif

0 commit comments

Comments
 (0)