Skip to content

Commit b873261

Browse files
committed
More progress towards PM3 compatible auth
1 parent bccf579 commit b873261

File tree

6 files changed

+86
-64
lines changed

6 files changed

+86
-64
lines changed

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

+6-7
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,16 @@ bool Iso7816FileSelected = false;
3434
uint8_t Iso7816FileOffset = 0;
3535
uint8_t Iso7816EfIdNumber = ISO7816_EF_NOT_SPECIFIED;
3636

37-
bool IsWrappedISO7816CommandType(uint8_t *Buffer, uint16_t ByteCount) {
38-
if (ByteCount <= ISO7816_PROLOGUE_SIZE + ISO14443A_CRCA_SIZE + 2) {
39-
return ISO7816_WRAPPED_CMD_TYPE_NONE;
40-
} else if (!ISO14443ACheckCRCA(&Buffer[0], ByteCount - 2)) {
41-
return ISO7816_WRAPPED_CMD_TYPE_NONE;
42-
} else if (ByteCount >= 6 && Buffer[3] == ByteCount - 6) {
37+
Iso7816WrappedCommandType_t IsWrappedISO7816CommandType(uint8_t *Buffer, uint16_t ByteCount) {
38+
if (ByteCount >= 6 && Buffer[3] == ByteCount - 6) {
4339
return ISO7816_WRAPPED_CMD_TYPE_PM3RAW;
40+
} else if (ByteCount <= ISO7816_PROLOGUE_SIZE + ISO14443A_CRCA_SIZE + 2) {
41+
return ISO7816_WRAPPED_CMD_TYPE_NONE;
4442
} else if (!Iso7816CLA(Buffer[2])) {
4543
return ISO7816_WRAPPED_CMD_TYPE_NONE;
44+
} else {
45+
return ISO7816_WRAPPED_CMD_TYPE_STANDARD;
4646
}
47-
return ISO7816_WRAPPED_CMD_TYPE_STANDARD;
4847
}
4948

5049
uint16_t SetIso7816WrappedParametersType(uint8_t *Buffer, uint16_t ByteCount) {

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ extern uint8_t Iso7816FileOffset;
8484
extern uint8_t Iso7816EfIdNumber;
8585

8686
typedef enum {
87-
ISO7816_WRAPPED_CMD_TYPE_NONE = 0,
88-
ISO7816_WRAPPED_CMD_TYPE_STANDARD,
89-
ISO7816_WRAPPED_CMD_TYPE_PM3RAW,
87+
ISO7816_WRAPPED_CMD_TYPE_NONE = 0,
88+
ISO7816_WRAPPED_CMD_TYPE_STANDARD = 1,
89+
ISO7816_WRAPPED_CMD_TYPE_PM3RAW = 2,
9090
/* Others ??? */
9191
} Iso7816WrappedCommandType_t;
9292

93-
bool IsWrappedISO7816CommandType(uint8_t *Buffer, uint16_t ByteCount);
93+
Iso7816WrappedCommandType_t IsWrappedISO7816CommandType(uint8_t *Buffer, uint16_t ByteCount);
9494
uint16_t SetIso7816WrappedParametersType(uint8_t *Buffer, uint16_t ByteCount);
9595

9696
#endif

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

+39-29
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ uint16_t CallInstructionHandler(uint8_t *Buffer, uint16_t ByteCount) {
326326
while (curInsUpper >= curInsLower) {
327327
curInsIndex = curInsLower + (curInsUpper + 1 - curInsLower) / 2;
328328
dfCmd = DESFireCommandSet[curInsIndex];
329-
if (dfCmd.insCode == insCode) {
329+
if (dfCmd.insCode == insCode) {
330330
if (dfCmd.insFunc == NULL) {
331331
return CmdNotImplemented(Buffer, ByteCount);
332332
}
@@ -1713,6 +1713,7 @@ uint16_t DesfireCmdAuthenticate3KTDEA1(uint8_t *Buffer, uint16_t ByteCount) {
17131713

17141714
BYTE KeyId, Status;
17151715
BYTE keySize;
1716+
BYTE CryptoChallengeResponseBytesSize;
17161717
BYTE *Key;
17171718

17181719
/* Validate command length */
@@ -1728,10 +1729,10 @@ uint16_t DesfireCmdAuthenticate3KTDEA1(uint8_t *Buffer, uint16_t ByteCount) {
17281729
* in the event of an error.
17291730
*/
17301731
KeyId = Buffer[1];
1731-
if (!Authenticated || !AuthenticatedWithPICCMasterKey) {
1732+
if (!AuthenticatedWithPICCMasterKey && KeyId != DESFIRE_MASTER_KEY_ID) {
17321733
Buffer[0] = STATUS_PERMISSION_DENIED;
17331734
return DESFIRE_STATUS_RESPONSE_SIZE;
1734-
} else if (AuthenticatedWithKey != KeyId) {
1735+
} else if ((Authenticated || AuthenticatedWithPICCMasterKey) && AuthenticatedWithKey != KeyId) {
17351736
Buffer[0] = STATUS_NO_SUCH_KEY;
17361737
return DESFIRE_STATUS_RESPONSE_SIZE;
17371738
} else {
@@ -1750,21 +1751,28 @@ uint16_t DesfireCmdAuthenticate3KTDEA1(uint8_t *Buffer, uint16_t ByteCount) {
17501751
return DESFIRE_STATUS_RESPONSE_SIZE;
17511752
}
17521753

1753-
keySize = GetDefaultCryptoMethodKeySize(CRYPTO_TYPE_3K3DES);
1754+
/* Update state */
17541755
Key = SessionKey;
1755-
1756-
/* Indicate that we are in AES key authentication land */
17571756
DesfireCommandState.KeyId = KeyId;
1758-
DesfireCommandState.CryptoMethodType = CRYPTO_TYPE_3K3DES;
1759-
DesfireCommandState.ActiveCommMode = GetCryptoMethodCommSettings(CRYPTO_TYPE_3K3DES);
1757+
if (!AuthenticatedWithPICCMasterKey) {
1758+
keySize = GetDefaultCryptoMethodKeySize(CRYPTO_TYPE_DES);
1759+
DesfireCommandState.CryptoMethodType = CRYPTO_TYPE_DES;
1760+
DesfireCommandState.ActiveCommMode = GetCryptoMethodCommSettings(CRYPTO_TYPE_DES);
1761+
1762+
} else {
1763+
keySize = GetDefaultCryptoMethodKeySize(CRYPTO_TYPE_3K3DES);
1764+
DesfireCommandState.CryptoMethodType = CRYPTO_TYPE_3K3DES;
1765+
DesfireCommandState.ActiveCommMode = GetCryptoMethodCommSettings(CRYPTO_TYPE_3K3DES);
1766+
}
1767+
CryptoChallengeResponseBytesSize = keySize;
17601768

17611769
/* Fetch the key */
17621770
ReadAppKey(SelectedApp.Slot, KeyId, Key, keySize);
17631771
LogEntry(LOG_APP_AUTH_KEY, (const void *) Key, keySize);
17641772

17651773
/* Generate the nonce B (RndB / Challenge response) */
17661774
if (LocalTestingMode == 0) {
1767-
RandomGetBuffer(DesfireCommandState.RndB, CRYPTO_CHALLENGE_RESPONSE_BYTES);
1775+
RandomGetBuffer(DesfireCommandState.RndB, CryptoChallengeResponseBytesSize);
17681776
} else {
17691777
/* Fixed nonce for testing */
17701778
DesfireCommandState.RndB[0] = 0xCA;
@@ -1784,10 +1792,10 @@ uint16_t DesfireCmdAuthenticate3KTDEA1(uint8_t *Buffer, uint16_t ByteCount) {
17841792
DesfireCommandState.RndB[14] = 0x22;
17851793
DesfireCommandState.RndB[15] = 0x33;
17861794
}
1787-
LogEntry(LOG_APP_NONCE_B, DesfireCommandState.RndB, CRYPTO_CHALLENGE_RESPONSE_BYTES);
1795+
LogEntry(LOG_APP_NONCE_B, DesfireCommandState.RndB, CryptoChallengeResponseBytesSize);
17881796

17891797
/* Encrypt RndB with the selected key and transfer it back to the PCD */
1790-
Encrypt3DESBuffer(CRYPTO_CHALLENGE_RESPONSE_BYTES, DesfireCommandState.RndB,
1798+
Encrypt3DESBuffer(CryptoChallengeResponseBytesSize, DesfireCommandState.RndB,
17911799
&Buffer[1], NULL, Key);
17921800

17931801
/* Scrub the key */
@@ -1796,54 +1804,57 @@ uint16_t DesfireCmdAuthenticate3KTDEA1(uint8_t *Buffer, uint16_t ByteCount) {
17961804
/* Done */
17971805
DesfireState = DESFIRE_ISO_AUTHENTICATE2;
17981806
Buffer[0] = STATUS_ADDITIONAL_FRAME;
1799-
return DESFIRE_STATUS_RESPONSE_SIZE + CRYPTO_CHALLENGE_RESPONSE_BYTES;
1807+
return DESFIRE_STATUS_RESPONSE_SIZE + CryptoChallengeResponseBytesSize;
18001808

18011809
}
18021810

18031811
uint16_t DesfireCmdAuthenticate3KTDEA2(uint8_t *Buffer, uint16_t ByteCount) {
18041812
BYTE KeyId;
18051813
BYTE cryptoKeyType, keySize;
1814+
BYTE CryptoChallengeResponseBytesSize;
18061815
BYTE *Key;
18071816

1817+
cryptoKeyType = DesfireCommandState.CryptoMethodType;
1818+
keySize = GetDefaultCryptoMethodKeySize(cryptoKeyType);
1819+
CryptoChallengeResponseBytesSize = keySize;
1820+
18081821
/* Set status for the next incoming command on error */
18091822
DesfireState = DESFIRE_IDLE;
18101823
/* Validate command length */
1811-
if (ByteCount != 2 * CRYPTO_CHALLENGE_RESPONSE_BYTES + 1) {
1824+
if (ByteCount != 2 * CryptoChallengeResponseBytesSize + 1) {
18121825
Buffer[0] = STATUS_LENGTH_ERROR;
18131826
return DESFIRE_STATUS_RESPONSE_SIZE;
18141827
}
18151828

18161829
/* Reset parameters for authentication from the first exchange */
18171830
KeyId = DesfireCommandState.KeyId;
1818-
cryptoKeyType = DesfireCommandState.CryptoMethodType;
1819-
keySize = GetDefaultCryptoMethodKeySize(CRYPTO_TYPE_3K3DES);
18201831
Key = SessionKey;
18211832
ReadAppKey(SelectedApp.Slot, KeyId, Key, keySize);
18221833

18231834
/* Decrypt the challenge sent back to get RndA and a shifted RndB */
1824-
BYTE challengeRndAB[2 * CRYPTO_CHALLENGE_RESPONSE_BYTES];
1825-
BYTE challengeRndA[CRYPTO_CHALLENGE_RESPONSE_BYTES];
1826-
BYTE challengeRndB[CRYPTO_CHALLENGE_RESPONSE_BYTES];
1827-
Decrypt3DESBuffer(2 * CRYPTO_CHALLENGE_RESPONSE_BYTES, challengeRndAB,
1835+
BYTE challengeRndAB[2 * CryptoChallengeResponseBytesSize];
1836+
BYTE challengeRndA[CryptoChallengeResponseBytesSize];
1837+
BYTE challengeRndB[CryptoChallengeResponseBytesSize];
1838+
Decrypt3DESBuffer(2 * CryptoChallengeResponseBytesSize, challengeRndAB,
18281839
&Buffer[1], NULL, Key);
1829-
RotateArrayRight(challengeRndAB + CRYPTO_CHALLENGE_RESPONSE_BYTES, challengeRndB,
1830-
CRYPTO_CHALLENGE_RESPONSE_BYTES);
1831-
memcpy(challengeRndA, challengeRndAB, CRYPTO_CHALLENGE_RESPONSE_BYTES);
1840+
RotateArrayRight(challengeRndAB + CryptoChallengeResponseBytesSize, challengeRndB,
1841+
CryptoChallengeResponseBytesSize);
1842+
memcpy(challengeRndA, challengeRndAB, CryptoChallengeResponseBytesSize);
18321843

18331844
/* Check that the returned RndB matches what we sent in the previous round */
1834-
if (memcmp(DesfireCommandState.RndB, challengeRndB, CRYPTO_CHALLENGE_RESPONSE_BYTES)) {
1835-
LogEntry(LOG_ERR_DESFIRE_GENERIC_ERROR, (const void *) challengeRndB, CRYPTO_CHALLENGE_RESPONSE_BYTES);
1845+
if (memcmp(DesfireCommandState.RndB, challengeRndB, CryptoChallengeResponseBytesSize)) {
1846+
LogEntry(LOG_ERR_DESFIRE_GENERIC_ERROR, (const void *) challengeRndB, CryptoChallengeResponseBytesSize);
18361847
Buffer[0] = STATUS_AUTHENTICATION_ERROR;
18371848
return DESFIRE_STATUS_RESPONSE_SIZE;
18381849
}
18391850

18401851
/* Encrypt and send back the once rotated RndA buffer to the PCD */
1841-
RotateArrayLeft(challengeRndA, challengeRndAB, CRYPTO_CHALLENGE_RESPONSE_BYTES);
1842-
Encrypt3DESBuffer(CRYPTO_CHALLENGE_RESPONSE_BYTES, challengeRndAB,
1852+
RotateArrayLeft(challengeRndA, challengeRndAB, CryptoChallengeResponseBytesSize);
1853+
Encrypt3DESBuffer(CryptoChallengeResponseBytesSize, challengeRndAB,
18431854
&Buffer[1], NULL, Key);
18441855

18451856
/* Create the session key based on the previous exchange */
1846-
generateSessionKey(SessionKey, challengeRndA, challengeRndB, CRYPTO_TYPE_3K3DES);
1857+
generateSessionKey(SessionKey, challengeRndA, challengeRndB, cryptoKeyType);
18471858

18481859
/* Now that we have auth'ed with the legacy command, a ChangeKey command will
18491860
* allow for subsequent authentication with the ISO or AES routines
@@ -1855,7 +1866,7 @@ uint16_t DesfireCmdAuthenticate3KTDEA2(uint8_t *Buffer, uint16_t ByteCount) {
18551866

18561867
/* Return the status on success */
18571868
Buffer[0] = STATUS_OPERATION_OK;
1858-
return DESFIRE_STATUS_RESPONSE_SIZE + CRYPTO_CHALLENGE_RESPONSE_BYTES;
1869+
return DESFIRE_STATUS_RESPONSE_SIZE + CryptoChallengeResponseBytesSize;
18591870

18601871
}
18611872

@@ -1990,7 +2001,6 @@ uint16_t DesfireCmdAuthenticateAES2(uint8_t *Buffer, uint16_t ByteCount) {
19902001
if (memcmp(DesfireCommandState.RndB, challengeRndB, CRYPTO_CHALLENGE_RESPONSE_BYTES)) {
19912002
memcpy(challengeRndAB, DesfireCommandState.RndB, CRYPTO_CHALLENGE_RESPONSE_BYTES);
19922003
memcpy(challengeRndAB + CRYPTO_CHALLENGE_RESPONSE_BYTES, challengeRndB, CRYPTO_CHALLENGE_RESPONSE_BYTES);
1993-
LogEntry(LOG_APP_NONCE_B, challengeRndAB, 2 * CRYPTO_CHALLENGE_RESPONSE_BYTES);
19942004
Buffer[0] = STATUS_AUTHENTICATION_ERROR;
19952005
return DESFIRE_STATUS_RESPONSE_SIZE;
19962006
}

Firmware/Chameleon-Mini/Application/ISO14443-3A.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ bool ISO14443ASelectDesfire(void *Buffer, uint16_t *BitCount, uint8_t *UidCL, ui
2020

2121
switch (NVB) {
2222
case 0x00:
23-
case ISO14443A_CMD_HLTA:
23+
case ISO14443A_CMD_HLTA:
2424
case ISO14443A_NVB_AC_START:
2525
/* Start of anticollision procedure.
2626
* Send whole UID CLn + BCC */

Firmware/Chameleon-Mini/Application/MifareDESFire.c

+28-16
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ static bool AnticolNoResp = false;
5757
/* Dispatching routines */
5858
void MifareDesfireReset(void) {
5959
AnticolNoResp = false;
60+
//DesfireState = DESFIRE_IDLE;
6061
}
6162

6263
static void MifareDesfireAppInitLocal(uint8_t StorageSize, uint8_t Version, bool FormatPICC) {
@@ -178,9 +179,9 @@ uint16_t MifareDesfireProcess(uint8_t *Buffer, uint16_t BitCount) {
178179
if (BitCount == 0) {
179180
LogEntry(LOG_INFO_DESFIRE_INCOMING_DATA, Buffer, ByteCount);
180181
return ISO14443A_APP_NO_RESPONSE;
181-
} else if ((ByteCount >= 8 && DesfireCLA(Buffer[0]) && Buffer[2] == 0x00 &&
182-
Buffer[3] == 0x00 && (Buffer[4] == ByteCount - 6 || Buffer[4] == ByteCount - 8)) ||
183-
Iso7816CLA(DesfireCmdCLA)) {
182+
} else if (((ByteCount >= 8 && Buffer[4] == ByteCount - 8) || (ByteCount >= 5 && Buffer[4] == ByteCount - 5)) &&
183+
DesfireCLA(Buffer[0]) && Buffer[2] == 0x00 &&
184+
Buffer[3] == 0x00 || Iso7816CLA(DesfireCmdCLA)) {
184185
/* Wrapped native command structure or ISO7816: */
185186
if (Iso7816CLA(DesfireCmdCLA)) {
186187
uint16_t iso7816ParamsStatus = SetIso7816WrappedParametersType(Buffer, ByteCount);
@@ -193,10 +194,12 @@ uint16_t MifareDesfireProcess(uint8_t *Buffer, uint16_t BitCount) {
193194
}
194195
ByteCount = Buffer[4];
195196
Buffer[0] = Buffer[1];
196-
memmove(&Buffer[1], &Buffer[5], ByteCount);
197+
if (ByteCount > 0) {
198+
memmove(&Buffer[1], &Buffer[5], ByteCount);
199+
}
197200
/* Process the command */
198201
ByteCount = MifareDesfireProcessCommand(Buffer, ByteCount + 1);
199-
if ((ByteCount != 0 && !Iso7816CLA(DesfireCmdCLA)) || (ByteCount == 1)) {
202+
if ((ByteCount != 0 && !Iso7816CLA(DesfireCmdCLA))) {
200203
/* Re-wrap into padded APDU form */
201204
Buffer[ByteCount] = Buffer[0];
202205
memmove(&Buffer[0], &Buffer[1], ByteCount - 1);
@@ -205,7 +208,6 @@ uint16_t MifareDesfireProcess(uint8_t *Buffer, uint16_t BitCount) {
205208
} else {
206209
/* Re-wrap into ISO 7816-4 -- Done below by prepending the prologue back to the buffer */
207210
}
208-
LogEntry(LOG_INFO_DESFIRE_OUTGOING_DATA, Buffer, ByteCount);
209211
return ByteCount * BITS_PER_BYTE;
210212
} else {
211213
/* ISO/IEC 14443-4 PDUs: No extra work */
@@ -217,43 +219,53 @@ uint16_t MifareDesfireProcess(uint8_t *Buffer, uint16_t BitCount) {
217219
uint16_t MifareDesfireAppProcess(uint8_t *Buffer, uint16_t BitCount) {
218220
uint16_t ByteCount = (BitCount + BITS_PER_BYTE - 1) / BITS_PER_BYTE;
219221
uint16_t ReturnedBytes = 0;
222+
LogEntry(LOG_INFO_DESFIRE_INCOMING_DATA, Buffer, ByteCount);
220223
if (ByteCount >= 8 && DesfireCLA(Buffer[0]) && Buffer[2] == 0x00 &&
221224
Buffer[3] == 0x00 && Buffer[4] == ByteCount - 8) {
222225
DesfireCmdCLA = Buffer[0];
223226
uint16_t IncomingByteCount = (BitCount + BITS_PER_BYTE - 1) / BITS_PER_BYTE;
224227
uint16_t UnwrappedBitCount = DesfirePreprocessAPDU(ActiveCommMode, Buffer, IncomingByteCount) * BITS_PER_BYTE;
225228
uint16_t ProcessedBitCount = MifareDesfireProcess(Buffer, UnwrappedBitCount);
226229
uint16_t ProcessedByteCount = (ProcessedBitCount + BITS_PER_BYTE - 1) / BITS_PER_BYTE;
227-
return ISO14443AStoreLastDataFrameAndReturn(Buffer,
228-
DesfirePostprocessAPDU(ActiveCommMode, Buffer, ProcessedByteCount) * BITS_PER_BYTE);
229-
} else if ((Iso7816CmdType = IsWrappedISO7816CommandType(Buffer, ByteCount)) && Iso7816CmdType != ISO7816_WRAPPED_CMD_TYPE_NONE) {
230-
DesfireCmdCLA = (Iso7816CmdType == ISO7816_WRAPPED_CMD_TYPE_STANDARD) ? Buffer[2] : DESFIRE_ISO7816_CLA;
230+
ProcessedByteCount = DesfirePostprocessAPDU(ActiveCommMode, Buffer, ProcessedByteCount);
231+
LogEntry(LOG_INFO_DESFIRE_OUTGOING_DATA, Buffer, ProcessedByteCount);
232+
return ISO14443AStoreLastDataFrameAndReturn(Buffer, ProcessedByteCount * BITS_PER_BYTE);
233+
}
234+
Iso7816CmdType = IsWrappedISO7816CommandType(Buffer, ByteCount);
235+
if (Iso7816CmdType != ISO7816_WRAPPED_CMD_TYPE_NONE) {
236+
DesfireCmdCLA = (Iso7816CmdType == ISO7816_WRAPPED_CMD_TYPE_STANDARD) ? Buffer[2] : DESFIRE_NATIVE_CLA;
231237
uint8_t ISO7816PrologueBytes[2];
232238
memcpy(&ISO7816PrologueBytes[0], Buffer, 2);
233239
if (Iso7816CmdType == ISO7816_WRAPPED_CMD_TYPE_STANDARD) {
234240
memmove(&Buffer[0], &Buffer[2], ByteCount - 2);
235241
ByteCount = ByteCount - 2;
236242
} else if (Iso7816CmdType == ISO7816_WRAPPED_CMD_TYPE_PM3RAW) {
237-
/* Something like the following (for PM3 raw ISO auth):
238-
* 0a 00 1a 00 CRC1 CRC2 -- first two are prologue -- last two are checksum
243+
/* Something like the following (for PM3 raw ISO auth):
244+
* 0a 00 1a 00 CRC1 CRC2 -- first two are prologue -- last two are checksum
239245
*/
240246
Buffer[0] = DesfireCmdCLA;
241247
Buffer[1] = Buffer[2];
242248
memmove(&Buffer[5], &Buffer[3], ByteCount - 3);
243249
Buffer[2] = 0x00;
244250
Buffer[3] = 0x00;
245251
Buffer[4] = ByteCount - 5;
246-
ByteCount = ByteCount + 3;
247252
}
248253
uint16_t IncomingByteCount = DesfirePreprocessAPDU(ActiveCommMode, Buffer, ByteCount);
249-
uint16_t UnwrappedBitCount = (IncomingByteCount - 2) * BITS_PER_BYTE;
254+
uint16_t UnwrappedBitCount = IncomingByteCount * BITS_PER_BYTE;
250255
uint16_t ProcessedBitCount = MifareDesfireProcess(Buffer, UnwrappedBitCount);
251256
uint16_t ProcessedByteCount = (ProcessedBitCount + BITS_PER_BYTE - 1) / BITS_PER_BYTE;
257+
/* Undo the leading 0x91 and shift for the PM3 raw wrapped commands: */
258+
if (Iso7816CmdType != ISO7816_WRAPPED_CMD_TYPE_NONE) {
259+
memmove(&Buffer[1], &Buffer[0], ProcessedByteCount);
260+
Buffer[0] = Buffer[ProcessedByteCount];
261+
--ProcessedByteCount;
262+
}
252263
/* Append the same ISO7816 prologue bytes to the response: */
253264
memmove(&Buffer[2], &Buffer[0], ProcessedByteCount);
254265
memcpy(&Buffer[0], &ISO7816PrologueBytes[0], 2);
255-
ProcessedBitCount = DesfirePostprocessAPDU(ActiveCommMode, Buffer, ProcessedByteCount + 2) * BITS_PER_BYTE;
256-
return ISO14443AStoreLastDataFrameAndReturn(Buffer, ProcessedBitCount);
266+
ProcessedByteCount = DesfirePostprocessAPDU(ActiveCommMode, Buffer, ProcessedByteCount + 2);
267+
LogEntry(LOG_INFO_DESFIRE_OUTGOING_DATA, Buffer, ProcessedByteCount);
268+
return ISO14443AStoreLastDataFrameAndReturn(Buffer, ProcessedByteCount * BITS_PER_BYTE);
257269
} else if ((ReturnedBytes = CallInstructionHandler(Buffer, ByteCount)) != ISO14443A_APP_NO_RESPONSE) {
258270
/* This case should handle non-wrappped native commands. No pre/postprocessing afterwards: */
259271
LogEntry(LOG_INFO_DESFIRE_OUTGOING_DATA, Buffer, ReturnedBytes);

Firmware/Chameleon-Mini/Makefile

+8-7
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ SETTINGS += -DENABLE_EEPROM_SETTINGS
9696

9797
#Set a default logging mode for debugging with the DESFire
9898
#emulation code:
99-
#SETTINGS += -DDESFIRE_DEFAULT_LOGGING_MODE=DEBUGGING
100-
SETTINGS += -DDESFIRE_DEFAULT_LOGGING_MODE=OFF
99+
SETTINGS += -DDESFIRE_DEFAULT_LOGGING_MODE=DEBUGGING
100+
#SETTINGS += -DDESFIRE_DEFAULT_LOGGING_MODE=OFF
101101

102102
#Set a default testing mode setting (0 = OFF, non-NULL = ON):
103-
SETTINGS += -DDESFIRE_DEFAULT_TESTING_MODE=0
104-
#SETTINGS += -DDESFIRE_DEFAULT_TESTING_MODE=1
103+
#SETTINGS += -DDESFIRE_DEFAULT_TESTING_MODE=0
104+
SETTINGS += -DDESFIRE_DEFAULT_TESTING_MODE=1
105105

106106
#Feature: Use randomized UIDs that mask the actual secret UID until
107107
#the tag has been issued a successful authentication sequence:
@@ -173,7 +173,8 @@ SRC += Terminal/Terminal.c Terminal/Commands.c Terminal/XModem.c Termina
173173
SRC += Codec/Codec.c Codec/ISO14443-2A.c Codec/Reader14443-2A.c Codec/SniffISO14443-2A.c Codec/Reader14443-ISR.S
174174
SRC += Application/MifareUltralight.c Application/MifareClassic.c Application/ISO14443-3A.c \
175175
Application/Crypto1.c Application/Reader14443A.c Application/Sniff14443A.c \
176-
Application/CryptoTDEA-HWAccelerated.S Application/CryptoTDEA.c Application/CryptoAES128.c Application/CryptoCMAC.c \
176+
Application/CryptoTDEA-HWAccelerated.S Application/CryptoTDEA.c \
177+
Application/CryptoAES128.c Application/CryptoCMAC.c \
177178
Tests/CryptoTests.c Tests/ChameleonTerminal.c
178179
SRC += Application/NTAG215.c
179180
SRC += Codec/ISO15693.c
@@ -302,8 +303,8 @@ local-clean:
302303
@mkdir $(OBJDIR)
303304

304305
git-add-dev:
305-
@git add Makefile ./*.{c,h} ./*/*.{c,h} ./*/*/*.{c,h}
306-
@cd ../../Software/DESFireLibNFCTesting && \
306+
@make style && git add Makefile ./*.{c,h} ./*/*.{c,h} ./*/*/*.{c,h}
307+
@cd ../../Software/DESFireLibNFCTesting && make style && \
307308
git add Makefile LocalInclude/*.h Source/*.c SampleOutputDumps/*.dump
308309

309310
## Defining custom targets for the DESFire build (normal/user mode) and

0 commit comments

Comments
 (0)