Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mifare DESFire tag emulation support #287

Merged
merged 10 commits into from
Oct 19, 2020
Prev Previous commit
Next Next commit
Updating the Makefile and relevant source code that has to change to …
…support disabling common config targets
  • Loading branch information
maxieds committed Oct 17, 2020
commit 6f77cad6b065749c880f590ced84ba68e13aaf59
1 change: 1 addition & 0 deletions Firmware/Chameleon-Mini/Application/ISO14443-3A.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#define ISO14443A_ATQA_FRAME_SIZE (2 * 8) /* Bit */
#define ISO14443A_SAK_FRAME_SIZE (3 * 8) /* Bit */
#define ISO14443A_HLTA_FRAME_SIZE (2 * 8) /* Bit */

#define ISO14443A_UID0_RANDOM 0x08
#define ISO14443A_UID0_CT 0x88
Expand Down
4 changes: 4 additions & 0 deletions Firmware/Chameleon-Mini/Application/ISO15693-A.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef CONFIG_ISO15693_SNIFF_SUPPORT

#include "ISO15693-A.h"
#include "../Common.h"
#include <util/crc16.h>
Expand Down Expand Up @@ -158,3 +160,5 @@ bool ISO15693AntiColl(uint8_t *FrameBuf, uint16_t FrameBytes, CurrentFrame *Fram

return true;
}

#endif /* CONFIG_ISO15693_SNIFF_SUPPORT */
7 changes: 7 additions & 0 deletions Firmware/Chameleon-Mini/Application/MifareClassic.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
* Author: skuser
*/

#if defined(CONFIG_MF_CLASSIC_1K_SUPPORT) || \
defined(CONFIG_MF_CLASSIC_1K_7B_SUPPORT) || \
defined(CONFIG_MF_CLASSIC_4K_SUPPORT) || \
defined(CONFIG_MF_CLASSIC_4K_7B_SUPPORT)

#include "MifareClassic.h"

#include "ISO14443-3A.h"
Expand Down Expand Up @@ -1072,3 +1077,5 @@ void MifareClassicSetUid(ConfigurationUidType Uid) {
MemoryWriteBlock(&BCC, MEM_UID_BCC1_ADDRESS, ISO14443A_CL_BCC_SIZE);
}
}

#endif
3 changes: 3 additions & 0 deletions Firmware/Chameleon-Mini/Application/MifareUltralight.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Author: skuser
*/

#ifdef CONFIG_MF_ULTRALIGHT_SUPPORT

#include "MifareUltralight.h"
#include "ISO14443-3A.h"
#include "../Codec/ISO14443-2A.h"
Expand Down Expand Up @@ -673,3 +675,4 @@ void MifareUltralightSetUid(ConfigurationUidType Uid) {
MemoryWriteBlock(&BCC2, UID_BCC2_ADDRESS, ISO14443A_CL_BCC_SIZE);
}

#endif /* CONFIG_MF_ULTRALIGHT_SUPPORT */
5 changes: 5 additions & 0 deletions Firmware/Chameleon-Mini/Application/Reader14443A.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#if defined(CONFIG_ISO14443A_READER_SUPPORT) || \
defined(CONFIG_ISO14443A_SNIFF_SUPPORT)

#include "Reader14443A.h"
#include "LEDHook.h"
#include "Application.h"
Expand Down Expand Up @@ -907,3 +910,5 @@ uint16_t ISO14443_CRCA(uint8_t *Buffer, uint8_t ByteCount) {
}
return crc;
}

#endif
5 changes: 5 additions & 0 deletions Firmware/Chameleon-Mini/Application/Sniff14443A.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
// Currently only support Autocalibrate
//

#ifdef CONFIG_ISO14443A_SNIFF_SUPPORT

#include <stdbool.h>
#include <LED.h>
#include "Sniff14443A.h"
#include "Codec/SniffISO14443-2A.h"

extern bool checkParityBits(uint8_t *Buffer, uint16_t BitCount);

Sniff14443Command Sniff14443CurrentCommand = Sniff14443_Do_Nothing;
Expand Down Expand Up @@ -172,3 +175,5 @@ uint16_t Sniff14443AAppProcess(uint8_t *Buffer, uint16_t BitCount) {
}
return 0;
}

#endif /* CONFIG_ISO14443A_SNIFF_SUPPORT */
60 changes: 42 additions & 18 deletions Firmware/Chameleon-Mini/Configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,60 @@
#include "Map.h"
#include "AntennaLevel.h"

#ifdef CONFIG_MF_DESFIRE_SUPPORT
#include "Application/MifareDESFire.h"
#endif

/* Map IDs to text */
static const MapEntryType PROGMEM ConfigurationMap[] = {
{ .Id = CONFIG_NONE, .Text = "NONE" },
{ .Id = CONFIG_NONE, .Text = "NONE" },
#ifdef CONFIG_MF_ULTRALIGHT_SUPPORT
{ .Id = CONFIG_MF_ULTRALIGHT, .Text = "MF_ULTRALIGHT" },
{ .Id = CONFIG_MF_ULTRALIGHT_EV1_80B, .Text = "MF_ULTRALIGHT_EV1_80B" },
{ .Id = CONFIG_MF_ULTRALIGHT_EV1_164B, .Text = "MF_ULTRALIGHT_EV1_164B" },
{.Id = CONFIG_MF_ULTRALIGHT_C, .Text = "MF_ULTRALIGHT_C"},
{ .Id = CONFIG_MF_ULTRALIGHT, .Text = "MF_ULTRALIGHT" },
{ .Id = CONFIG_MF_ULTRALIGHT_EV1_80B, .Text = "MF_ULTRALIGHT_EV1_80B" },
{ .Id = CONFIG_MF_ULTRALIGHT_EV1_164B, .Text = "MF_ULTRALIGHT_EV1_164B" },
{ .Id = CONFIG_MF_ULTRALIGHT_C, .Text = "MF_ULTRALIGHT_C"},
#endif
#ifdef CONFIG_MF_CLASSIC_MINI_4B_SUPPORT
{ .Id = CONFIG_MF_CLASSIC_MINI_4B, .Text = "MF_CLASSIC_MINI_4B" },
{ .Id = CONFIG_MF_CLASSIC_MINI_4B, .Text = "MF_CLASSIC_MINI_4B" },
#endif
#ifdef CONFIG_MF_CLASSIC_1K_SUPPORT
{ .Id = CONFIG_MF_CLASSIC_1K, .Text = "MF_CLASSIC_1K" },
{ .Id = CONFIG_MF_CLASSIC_1K, .Text = "MF_CLASSIC_1K" },
#endif
#ifdef CONFIG_MF_CLASSIC_1K_7B_SUPPORT
{ .Id = CONFIG_MF_CLASSIC_1K_7B, .Text = "MF_CLASSIC_1K_7B" },
{ .Id = CONFIG_MF_CLASSIC_1K_7B, .Text = "MF_CLASSIC_1K_7B" },
#endif
#ifdef CONFIG_MF_CLASSIC_4K_SUPPORT
{ .Id = CONFIG_MF_CLASSIC_4K, .Text = "MF_CLASSIC_4K" },
{ .Id = CONFIG_MF_CLASSIC_4K, .Text = "MF_CLASSIC_4K" },
#endif
#ifdef CONFIG_MF_CLASSIC_4K_7B_SUPPORT
{ .Id = CONFIG_MF_CLASSIC_4K_7B, .Text = "MF_CLASSIC_4K_7B" },
{ .Id = CONFIG_MF_CLASSIC_4K_7B, .Text = "MF_CLASSIC_4K_7B" },
#endif
#ifdef CONFIG_ISO14443A_SNIFF_SUPPORT
{ .Id = CONFIG_ISO14443A_SNIFF, .Text = "ISO14443A_SNIFF" },
{ .Id = CONFIG_ISO14443A_SNIFF, .Text = "ISO14443A_SNIFF" },
#endif
#ifdef CONFIG_ISO14443A_READER_SUPPORT
{ .Id = CONFIG_ISO14443A_READER, .Text = "ISO14443A_READER" },
{ .Id = CONFIG_ISO14443A_READER, .Text = "ISO14443A_READER" },
#endif
#ifdef CONFIG_NTAG215_SUPPORT
{ .Id = CONFIG_NTAG215, .Text = "NTAG215" },
{ .Id = CONFIG_NTAG215, .Text = "NTAG215" },
#endif
#ifdef CONFIG_VICINITY_SUPPORT
{ .Id = CONFIG_VICINITY, .Text = "VICINITY" },
{ .Id = CONFIG_VICINITY, .Text = "VICINITY" },
#endif
#ifdef CONFIG_ISO15693_SNIFF_SUPPORT
{ .Id = CONFIG_ISO15693_SNIFF, .Text = "ISO15693_SNIFF" },
{ .Id = CONFIG_ISO15693_SNIFF, .Text = "ISO15693_SNIFF" },
#endif
#ifdef CONFIG_SL2S2002_SUPPORT
{ .Id = CONFIG_SL2S2002, .Text = "SL2S2002" },
{ .Id = CONFIG_SL2S2002, .Text = "SL2S2002" },
#endif
#ifdef CONFIG_TITAGITSTANDARD_SUPPORT
{ .Id = CONFIG_TITAGITSTANDARD, .Text = "TITAGITSTANDARD" },
{ .Id = CONFIG_TITAGITSTANDARD, .Text = "TITAGITSTANDARD" },
#endif
#ifdef CONFIG_EM4233_SUPPORT
{ .Id = CONFIG_EM4233, .Text = "EM4233" },
{ .Id = CONFIG_EM4233, .Text = "EM4233" },
#endif
#ifdef CONFIG_MF_DESFIRE_SUPPORT
{ .Id = CONFIG_MF_DESFIRE, .Text = "MF_DESFIRE" },
#endif
};

Expand Down Expand Up @@ -393,6 +400,23 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = {
.ReadOnly = false,
},
#endif
#ifdef CONFIG_MF_DESFIRE_SUPPORT
[CONFIG_MF_DESFIRE] = {
.CodecInitFunc = ISO14443ACodecInit,
.CodecDeInitFunc =ISO14443ACodecDeInit,
.CodecTaskFunc = ISO14443ACodecTask,
.ApplicationInitFunc = MifareDesfireEV0AppInit,
.ApplicationResetFunc = MifareDesfireAppReset,
.ApplicationTaskFunc = MifareDesfireAppTask,
.ApplicationTickFunc = MifareDesfireAppTick,
.ApplicationProcessFunc = MifareDesfireAppProcess,
.ApplicationGetUidFunc = MifareDesfireGetUid,
.ApplicationSetUidFunc = MifareDesfireSetUid,
.UidSize = ISO14443A_UID_SIZE_DOUBLE,
.MemorySize = MIFARE_CLASSIC_4K_MEM_SIZE,
.ReadOnly = false
},
#endif
};

ConfigurationType ActiveConfiguration;
Expand Down
3 changes: 3 additions & 0 deletions Firmware/Chameleon-Mini/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ typedef enum {
#endif
#ifdef CONFIG_EM4233_SUPPORT
CONFIG_EM4233,
#endif
#ifdef CONFIG_MF_DESFIRE_SUPPORT
CONFIG_MF_DESFIRE,
#endif
/* This HAS to be the last element */
CONFIG_COUNT
Expand Down
4 changes: 2 additions & 2 deletions Firmware/Chameleon-Mini/LUFAConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
// #define USE_RAM_DESCRIPTORS
#define USE_FLASH_DESCRIPTORS
// #define USE_EEPROM_DESCRIPTORS
// #define NO_INTERNAL_SERIAL
#undef NO_INTERNAL_SERIAL
#define NO_INTERNAL_SERIAL
//#undef NO_INTERNAL_SERIAL
#define FIXED_CONTROL_ENDPOINT_SIZE 8
// #define DEVICE_STATE_AS_GPIOR {Insert Value Here}
#define FIXED_NUM_CONFIGURATIONS 1
Expand Down
63 changes: 32 additions & 31 deletions Firmware/Chameleon-Mini/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,46 @@ extern uint16_t LogMemLeft;
/** Enum for log entry type. \note Every entry type has a specific integer value, which can be found in the source code. */
typedef enum {
/* Generic */
LOG_INFO_GENERIC = 0x10, ///< Unspecific log entry.
LOG_INFO_CONFIG_SET = 0x11, ///< Configuration change.
LOG_INFO_SETTING_SET = 0x12, ///< Setting change.
LOG_INFO_UID_SET = 0x13, ///< UID change.
LOG_INFO_RESET_APP = 0x20, ///< Application reset.
LOG_INFO_GENERIC = 0x10, ///< Unspecific log entry.
LOG_INFO_CONFIG_SET = 0x11, ///< Configuration change.
LOG_INFO_SETTING_SET = 0x12, ///< Setting change.
LOG_INFO_UID_SET = 0x13, ///< UID change.
LOG_INFO_RESET_APP = 0x20, ///< Application reset.

/* Codec */
LOG_INFO_CODEC_RX_DATA = 0x40, ///< Currently active codec received data.
LOG_INFO_CODEC_TX_DATA = 0x41, ///< Currently active codec sent data.
LOG_INFO_CODEC_RX_DATA_W_PARITY = 0x42, ///< Currently active codec received data.
LOG_INFO_CODEC_TX_DATA_W_PARITY = 0x43, ///< Currently active codec sent data.

LOG_INFO_CODEC_RX_DATA = 0x40, ///< Currently active codec received data.
LOG_INFO_CODEC_TX_DATA = 0x41, ///< Currently active codec sent data.
LOG_INFO_CODEC_RX_DATA_W_PARITY = 0x42, ///< Currently active codec received data.
LOG_INFO_CODEC_TX_DATA_W_PARITY = 0x43, ///< Currently active codec sent data.
LOG_INFO_CODEC_SNI_READER_DATA = 0x44, //< Sniffing codec receive data from reader
LOG_INFO_CODEC_SNI_READER_DATA_W_PARITY = 0x45, //< Sniffing codec receive data from reader

LOG_INFO_CODEC_SNI_CARD_DATA = 0x46, //< Sniffing codec receive data from card
LOG_INFO_CODEC_SNI_CARD_DATA_W_PARITY = 0x47, //< Sniffing codec receive data from card



/* App */
LOG_INFO_APP_CMD_READ = 0x80, ///< Application processed read command.
LOG_INFO_APP_CMD_WRITE = 0x81, ///< Application processed write command.
LOG_INFO_APP_CMD_INC = 0x84, ///< Application processed increment command.
LOG_INFO_APP_CMD_DEC = 0x85, ///< Application processed decrement command.
LOG_INFO_APP_CMD_TRANSFER = 0x86, ///< Application processed transfer command.
LOG_INFO_APP_CMD_RESTORE = 0x87, ///< Application processed restore command.
LOG_INFO_APP_CMD_AUTH = 0x90, ///< Application processed authentication command.
LOG_INFO_APP_CMD_HALT = 0x91, ///< Application processed halt command.
LOG_INFO_APP_CMD_UNKNOWN = 0x92, ///< Application processed an unknown command.
LOG_INFO_APP_AUTHING = 0xA0, ///< Application is in `authing` state.
LOG_INFO_APP_AUTHED = 0xA1, ///< Application is in `auth` state.
LOG_ERR_APP_AUTH_FAIL = 0xC0, ///< Application authentication failed.
LOG_ERR_APP_CHECKSUM_FAIL = 0xC1, ///< Application had a checksum fail.
LOG_ERR_APP_NOT_AUTHED = 0xC2, ///< Application is not authenticated.

LOG_INFO_SYSTEM_BOOT = 0xFF, ///< Chameleon boots

LOG_EMPTY = 0x00 ///< Empty Log Entry. This is not followed by a length byte nor the two systick bytes nor any data.
LOG_INFO_APP_CMD_READ = 0x80, ///< Application processed read command.
LOG_INFO_APP_CMD_WRITE = 0x81, ///< Application processed write command.
LOG_INFO_APP_CMD_INC = 0x84, ///< Application processed increment command.
LOG_INFO_APP_CMD_DEC = 0x85, ///< Application processed decrement command.
LOG_INFO_APP_CMD_TRANSFER = 0x86, ///< Application processed transfer command.
LOG_INFO_APP_CMD_RESTORE = 0x87, ///< Application processed restore command.
LOG_INFO_APP_CMD_AUTH = 0x90, ///< Application processed authentication command.
LOG_INFO_APP_CMD_HALT = 0x91, ///< Application processed halt command.
LOG_INFO_APP_CMD_UNKNOWN = 0x92, ///< Application processed an unknown command.
LOG_INFO_APP_AUTHING = 0xA0, ///< Application is in `authing` state.
LOG_INFO_APP_AUTHED = 0xA1, ///< Application is in `auth` state.
LOG_ERR_APP_AUTH_FAIL = 0xC0, ///< Application authentication failed.
LOG_ERR_APP_CHECKSUM_FAIL = 0xC1, ///< Application had a checksum fail.
LOG_ERR_APP_NOT_AUTHED = 0xC2, ///< Application is not authenticated.

/* DESFire emulation and development related logging messages (0xEx): */
#ifdef CONFIG_MF_DESFIRE_SUPPORT
#include "Application/DESFire/DESFireLoggingCodesInclude.c"
#endif

LOG_INFO_SYSTEM_BOOT = 0xFF, ///< Chameleon boots
LOG_EMPTY = 0x00 ///< Empty Log Entry. This is not followed by a length byte
///< nor the two systick bytes nor any data.
} LogEntryEnum;

typedef enum {
Expand Down
Loading