Skip to content

Commit

Permalink
Factorize MF_CLASSIC versions Makefile flags
Browse files Browse the repository at this point in the history
  • Loading branch information
ShinHub committed Nov 17, 2019
1 parent 52a7c15 commit dfe1e42
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 95 deletions.
13 changes: 6 additions & 7 deletions Firmware/ChameleonMini/Application/MifareClassic.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
*
*/

#if defined(CONFIG_MF_CLASSIC_SUPPORT) || defined(CONFIG_MF_CLASSIC_DETECTION_SUPPORT) \
|| defined(CONFIG_MF_CLASSIC_BRUTE_SUPPORT) || defined(SUPPORT_MF_CLASSIC_MAGIC_MODE) \
|| defined(CONFIG_MF_CLASSIC_LOG_SUPPORT)

#include "MifareClassic.h"
#include "ISO14443-3A.h"
#include "Crypto1.h"
Expand Down Expand Up @@ -334,11 +338,9 @@ void MifareClassicAppInit4K(void) {
(ActiveConfiguration.UidSize == MFCLASSIC_UID_7B_SIZE) );
}

#ifdef CONFIG_MF_CLASSIC_MINI_SUPPORT
void MifareClassicAppInitMini(void) {
MifareClassicAppInit(MFCLASSIC_MINI_ATQA_VALUE, MFCLASSIC_MINI_SAK_VALUE, false);
}
#endif

#ifdef CONFIG_MF_CLASSIC_DETECTION_SUPPORT
void MifareClassicAppDetectionInit(void) {
Expand Down Expand Up @@ -505,11 +507,6 @@ void MifareClassicAppReset(void) {
State = STATE_IDLE;
}

void MifareClassicAppTask(void) {

}


/* Handle a MFCLASSIC_CMD_HALT during main process, as can be raised in many states.
* Sets State, response buffer and response size. Returns if valid HALT. */
bool mfcHandleHaltCommand(uint8_t * Buffer, uint16_t * RetValue) {
Expand Down Expand Up @@ -1028,3 +1025,5 @@ void MifareClassicGetSak(uint8_t * Sak) {
void MifareClassicSetSak(uint8_t Sak) {
CardSAKValue = Sak;
}

#endif /* Compilation support */
16 changes: 7 additions & 9 deletions Firmware/ChameleonMini/Application/MifareClassic.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
*
*/

#if defined(CONFIG_MF_CLASSIC_SUPPORT) || defined(CONFIG_MF_CLASSIC_DETECTION_SUPPORT) \
|| defined(CONFIG_MF_CLASSIC_BRUTE_SUPPORT) || defined(SUPPORT_MF_CLASSIC_MAGIC_MODE) \
|| defined(CONFIG_MF_CLASSIC_LOG_SUPPORT)

#ifndef MIFARECLASSIC_H_
#define MIFARECLASSIC_H_

Expand All @@ -17,9 +21,7 @@
#define MFCLASSIC_UID_7B_SIZE ISO14443A_UID_SIZE_DOUBLE
#define MFCLASSIC_1K_MEM_SIZE 1024
#define MFCLASSIC_4K_MEM_SIZE 4096
#ifdef CONFIG_MF_CLASSIC_MINI_SUPPORT
#define MFCLASSIC_MINI_MEM_SIZE 320
#endif

#define MFCLASSIC_1K_ATQA_VALUE 0x0004
#define MFCLASSIC_1K_7B_ATQA_VALUE 0x0044
Expand All @@ -28,10 +30,8 @@
#define MFCLASSIC_7B_ATQA_MASK 0x40
#define MFCLASSIC_1K_SAK_VALUE 0x08
#define MFCLASSIC_4K_SAK_VALUE 0x18
#ifdef CONFIG_MF_CLASSIC_MINI_SUPPORT
#define MFCLASSIC_MINI_ATQA_VALUE MFCLASSIC_1K_ATQA_VALUE
#define MFCLASSIC_MINI_SAK_VALUE 0x09
#endif
#define MFCLASSIC_SAK_CL1_VALUE ISO14443A_SAK_INCOMPLETE

#define MFCLASSIC_MEM_S0B0_ADDRESS 0x00
Expand Down Expand Up @@ -214,8 +214,8 @@ C1 C2 C3 read write increment decrement,

void MifareClassicAppInit1K(void);
void MifareClassicAppInit4K(void);
void MifareClassicAppInitMini(void);
void MifareClassicAppReset(void);
void MifareClassicAppTask(void);

uint16_t MifareClassicAppProcess(uint8_t* Buffer, uint16_t BitCount);

Expand All @@ -228,10 +228,6 @@ void MifareClassicSetAtqa(uint16_t Atqa);
void MifareClassicGetSak(uint8_t * Sak);
void MifareClassicSetSak(uint8_t Sak);

#ifdef CONFIG_MF_CLASSIC_MINI_SUPPORT
void MifareClassicAppInitMini(void);
#endif

#ifdef CONFIG_MF_CLASSIC_DETECTION_SUPPORT
void MifareClassicAppDetectionInit(void);
#endif
Expand All @@ -249,3 +245,5 @@ void MifareClassicAppLogToggle(void);
#endif

#endif /* MIFARECLASSIC_H_ */

#endif /* Compilation support */
6 changes: 2 additions & 4 deletions Firmware/ChameleonMini/ChameleonMini.cproj
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@
<Value>DEFAULT_BUTTON_ACTION=BUTTON_ACTION_CYCLE_SETTINGS</Value>
<Value>DEFAULT_BUTTON_LONG_ACTION=BUTTON_ACTION_CYCLE_SETTINGS</Value>
<Value>CONFIG_MF_ULTRALIGHT_SUPPORT</Value>
<Value>CONFIG_MF_CLASSIC_1K_SUPPORT</Value>
<Value>CONFIG_MF_CLASSIC_4K_SUPPORT</Value>
<Value>CONFIG_MF_CLASSIC_SUPPORT</Value>
<Value>CONFIG_MF_CLASSIC_DETECTION_SUPPORT</Value>
<Value>SUPPORT_FIRMWARE_UPGRADE</Value>
</ListValues>
Expand Down Expand Up @@ -281,8 +280,7 @@
<Value>DEFAULT_BUTTON_ACTION=BUTTON_ACTION_CYCLE_SETTINGS</Value>
<Value>DEFAULT_BUTTON_LONG_ACTION=BUTTON_ACTION_CYCLE_SETTINGS</Value>
<Value>CONFIG_MF_ULTRALIGHT_SUPPORT</Value>
<Value>CONFIG_MF_CLASSIC_1K_SUPPORT</Value>
<Value>CONFIG_MF_CLASSIC_4K_SUPPORT</Value>
<Value>CONFIG_MF_CLASSIC_SUPPORT</Value>
<Value>CONFIG_MF_CLASSIC_DETECTION_SUPPORT</Value>
<Value>SUPPORT_FIRMWARE_UPGRADE</Value>
</ListValues>
Expand Down
30 changes: 7 additions & 23 deletions Firmware/ChameleonMini/Configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,11 @@ static const MapEntryType ConfigurationMap[] PROGMEM = {
{ .Id = CONFIG_MF_ULTRALIGHT_EV1_80B, .Text = "MF_ULTRALIGHT_EV1_80B" },
{ .Id = CONFIG_MF_ULTRALIGHT_EV1_164B, .Text = "MF_ULTRALIGHT_EV1_164B" },
#endif
#ifdef CONFIG_MF_CLASSIC_1K_SUPPORT
#ifdef CONFIG_MF_CLASSIC_SUPPORT
{ .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" },
#endif
#ifdef CONFIG_MF_CLASSIC_4K_SUPPORT
{ .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" },
#endif
#ifdef CONFIG_MF_CLASSIC_MINI_SUPPORT
{ .Id = CONFIG_MF_CLASSIC_MINI, .Text = "MF_CLASSIC_MINI" },
#endif
#ifdef CONFIG_MF_CLASSIC_DETECTION_SUPPORT
Expand Down Expand Up @@ -147,13 +139,13 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = {
.ReadOnly = false
},
#endif
#ifdef CONFIG_MF_CLASSIC_1K_SUPPORT
#ifdef CONFIG_MF_CLASSIC_SUPPORT
[CONFIG_MF_CLASSIC_1K] = {
.CodecInitFunc = ISO14443ACodecInit,
.CodecTaskFunc = ISO14443ACodecTask,
.ApplicationInitFunc = MifareClassicAppInit1K,
.ApplicationResetFunc = MifareClassicAppReset,
.ApplicationTaskFunc = MifareClassicAppTask,
.ApplicationTaskFunc = ApplicationTaskDummy,
.ApplicationTickFunc = ApplicationTickDummy,
.ApplicationButtonFunc = ApplicationButtonFuncDummy,
.ApplicationProcessFunc = MifareClassicAppProcess,
Expand All @@ -168,14 +160,12 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = {
.WorkingMemorySize = MEMORY_NO_MEMORY,
.ReadOnly = false
},
#endif
#ifdef CONFIG_MF_CLASSIC_1K_7B_SUPPORT
[CONFIG_MF_CLASSIC_1K_7B] = {
.CodecInitFunc = ISO14443ACodecInit,
.CodecTaskFunc = ISO14443ACodecTask,
.ApplicationInitFunc = MifareClassicAppInit1K,
.ApplicationResetFunc = MifareClassicAppReset,
.ApplicationTaskFunc = MifareClassicAppTask,
.ApplicationTaskFunc = ApplicationTaskDummy,
.ApplicationTickFunc = ApplicationTickDummy,
.ApplicationButtonFunc = ApplicationButtonFuncDummy,
.ApplicationProcessFunc = MifareClassicAppProcess,
Expand All @@ -190,14 +180,12 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = {
.WorkingMemorySize = MEMORY_NO_MEMORY,
.ReadOnly = false
},
#endif
#ifdef CONFIG_MF_CLASSIC_4K_SUPPORT
[CONFIG_MF_CLASSIC_4K] = {
.CodecInitFunc = ISO14443ACodecInit,
.CodecTaskFunc = ISO14443ACodecTask,
.ApplicationInitFunc = MifareClassicAppInit4K,
.ApplicationResetFunc = MifareClassicAppReset,
.ApplicationTaskFunc = MifareClassicAppTask,
.ApplicationTaskFunc = ApplicationTaskDummy,
.ApplicationTickFunc = ApplicationTickDummy,
.ApplicationButtonFunc = ApplicationButtonFuncDummy,
.ApplicationProcessFunc = MifareClassicAppProcess,
Expand All @@ -212,14 +200,12 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = {
.WorkingMemorySize = MEMORY_NO_MEMORY,
.ReadOnly = false
},
#endif
#ifdef CONFIG_MF_CLASSIC_4K_7B_SUPPORT
[CONFIG_MF_CLASSIC_4K_7B] = {
.CodecInitFunc = ISO14443ACodecInit,
.CodecTaskFunc = ISO14443ACodecTask,
.ApplicationInitFunc = MifareClassicAppInit4K,
.ApplicationResetFunc = MifareClassicAppReset,
.ApplicationTaskFunc = MifareClassicAppTask,
.ApplicationTaskFunc = ApplicationTaskDummy,
.ApplicationTickFunc = ApplicationTickDummy,
.ApplicationButtonFunc = ApplicationButtonFuncDummy,
.ApplicationProcessFunc = MifareClassicAppProcess,
Expand All @@ -234,14 +220,12 @@ static const PROGMEM ConfigurationType ConfigurationTable[] = {
.WorkingMemorySize = MEMORY_NO_MEMORY,
.ReadOnly = false
},
#endif
#ifdef CONFIG_MF_CLASSIC_MINI_SUPPORT
[CONFIG_MF_CLASSIC_MINI] = {
.CodecInitFunc = ISO14443ACodecInit,
.CodecTaskFunc = ISO14443ACodecTask,
.ApplicationInitFunc = MifareClassicAppInitMini,
.ApplicationResetFunc = MifareClassicAppReset,
.ApplicationTaskFunc = MifareClassicAppTask,
.ApplicationTaskFunc = ApplicationTaskDummy,
.ApplicationTickFunc = ApplicationTickDummy,
.ApplicationButtonFunc = ApplicationButtonFuncDummy,
.ApplicationProcessFunc = MifareClassicAppProcess,
Expand Down
10 changes: 1 addition & 9 deletions Firmware/ChameleonMini/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,11 @@ typedef enum {
CONFIG_MF_ULTRALIGHT_EV1_80B,
CONFIG_MF_ULTRALIGHT_EV1_164B,
#endif
#ifdef CONFIG_MF_CLASSIC_1K_SUPPORT
#ifdef CONFIG_MF_CLASSIC_SUPPORT
CONFIG_MF_CLASSIC_1K,
#endif
#ifdef CONFIG_MF_CLASSIC_1K_7B_SUPPORT
CONFIG_MF_CLASSIC_1K_7B,
#endif
#ifdef CONFIG_MF_CLASSIC_4K_SUPPORT
CONFIG_MF_CLASSIC_4K,
#endif
#ifdef CONFIG_MF_CLASSIC_4K_7B_SUPPORT
CONFIG_MF_CLASSIC_4K_7B,
#endif
#ifdef CONFIG_MF_CLASSIC_MINI_SUPPORT
CONFIG_MF_CLASSIC_MINI,
#endif
#ifdef CONFIG_MF_CLASSIC_DETECTION_SUPPORT
Expand Down
45 changes: 3 additions & 42 deletions Firmware/ChameleonMini/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,69 +16,30 @@ PYTHON_BIN = /usr/bin/env python3
CRYPTO_TOOL = ../../Software/Tools/crypt_operations.py

#Supported configurations
SETTINGS += -DCONFIG_MF_CLASSIC_1K_SUPPORT
SETTINGS += -DCONFIG_MF_CLASSIC_1K_7B_SUPPORT
SETTINGS += -DCONFIG_MF_CLASSIC_4K_SUPPORT
SETTINGS += -DCONFIG_MF_CLASSIC_4K_7B_SUPPORT
SETTINGS += -DCONFIG_MF_CLASSIC_MINI_SUPPORT
SETTINGS += -DCONFIG_MF_CLASSIC_SUPPORT
SETTINGS += -DCONFIG_MF_ULTRALIGHT_SUPPORT
#SETTINGS += -DCONFIG_ISO14443A_SNIFF_SUPPORT
#SETTINGS += -DCONFIG_ISO14443A_READER_SUPPORT
SETTINGS += -DCONFIG_MF_CLASSIC_DETECTION_SUPPORT
SETTINGS += -DCONFIG_MF_CLASSIC_BRUTE_SUPPORT
SETTINGS += -DCONFIG_MF_CLASSIC_LOG_SUPPORT

#Support magic mode on mifare classic configuration
#SETTINGS += -DSUPPORT_MF_CLASSIC_MAGIC_MODE

#Don't touch manufacturer byte with BUTTON_ACTION_UID_LEFT_(DE/IN)CREMENT
#SETTINGS += -DSUPPORT_UID7_FIX_MANUFACTURER_BYTE

#Support activating firmware upgrade mode through command-line
SETTINGS += -DSUPPORT_FIRMWARE_UPGRADE

#Enable the MEMORYTEST and/or MEMORYINFO commands to help with memory management debug
#SETTINGS += -DCONFIG_DEBUG_MEMORYTEST_COMMAND
#SETTINGS += -DCONFIG_DEBUG_MEMORYINFO_COMMAND
SETTINGS += -DCONFIG_DEBUG_MEMORYTEST_COMMAND
SETTINGS += -DCONFIG_DEBUG_MEMORYINFO_COMMAND

#Default configuration
SETTINGS += -DDEFAULT_CONFIGURATION=CONFIG_NONE
#SETTINGS += -DDEFAULT_CONFIGURATION=CONFIG_MF_CLASSIC_1K
#SETTINGS += -DDEFAULT_CONFIGURATION=CONFIG_MF_CLASSIC_4K
#SETTINGS += -DDEFAULT_CONFIGURATION=CONFIG_MF_ULTRALIGHT
#SETTINGS += -DDEFAULT_CONFIGURATION=CONFIG_ISO14443A_READER

#Default button actions
#SETTINGS += -DDEFAULT_BUTTON_ACTION=BUTTON_ACTION_NONE
#SETTINGS += -DDEFAULT_BUTTON_ACTION=BUTTON_ACTION_UID_RANDOM
#SETTINGS += -DDEFAULT_BUTTON_ACTION=BUTTON_ACTION_UID_LEFT_INCREMENT
#SETTINGS += -DDEFAULT_BUTTON_ACTION=BUTTON_ACTION_UID_RIGHT_INCREMENT
#SETTINGS += -DDEFAULT_BUTTON_ACTION=BUTTON_ACTION_UID_LEFT_DECREMENT
#SETTINGS += -DDEFAULT_BUTTON_ACTION=BUTTON_ACTION_UID_RIGHT_DECREMENT
SETTINGS += -DDEFAULT_BUTTON_ACTION=BUTTON_ACTION_CYCLE_SETTINGS
#SETTINGS += -DDEFAULT_BUTTON_ACTION=BUTTON_ACTION_STORE_MEM

#Default long button action
SETTINGS += -DDEFAULT_BUTTON_LONG_ACTION=BUTTON_ACTION_NONE

#Define if button action setting should be independent of active setting
#SETTINGS += -DBUTTON_SETTING_GLOBAL

#Default LED functions
#SETTINGS += -DDEFAULT_RED_LED_ACTION=LED_SETTING_CHANGE
#SETTINGS += -DDEFAULT_GREEN_LED_ACTION=LED_POWERED

#Define if LED function setting should be independent of active setting
#SETTINGS += -DLED_SETTING_GLOBAL

#Default logging mode
#SETTINGS += -DDEFAULT_LOG_MODE=LOG_MODE_OFF
#SETTINGS += -DDEFAULT_LOG_MODE=LOG_MODE_MEMORY
#SETTINGS += -DDEFAULT_LOG_MODE=LOG_MODE_TERMINAL

#Define if log settings should be global
#SETTINGS += -DLOG_SETTING_GLOBAL

#Default setting
SETTINGS += -DDEFAULT_SETTING=0

Expand Down
2 changes: 1 addition & 1 deletion Firmware/ChameleonMini/Memory/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define MEMORY_NO_MEMORY 0x00
#define MEMORY_ALL_MEMORY 0xFFFFFFFF
#define MEMORY_NO_ADDR 0
#ifdef CONFIG_MF_CLASSIC_4K_SUPPORT
#ifdef CONFIG_MF_CLASSIC_SUPPORT
#define MEMORY_MIN_BYTES_PER_APP MFCLASSIC_4K_MEM_SIZE
#else
#define MEMORY_MIN_BYTES_PER_APP 512
Expand Down

0 comments on commit dfe1e42

Please sign in to comment.