From cafb34ee93d8e194577e76d03ebb3a5c9176e466 Mon Sep 17 00:00:00 2001 From: ca1e Date: Tue, 19 Jan 2021 23:13:44 +0800 Subject: [PATCH 1/2] Add UIDMODE Command --- .../ChameleonMini/Application/MifareClassic.c | 7 ++++++- Firmware/ChameleonMini/Makefile | 2 +- Firmware/ChameleonMini/Memory/Memory.c | 4 ++++ Firmware/ChameleonMini/Memory/Memory.h | 2 ++ Firmware/ChameleonMini/Settings.c | 6 ++++++ Firmware/ChameleonMini/Settings.h | 3 +++ Firmware/ChameleonMini/Terminal/CommandLine.c | 8 ++++++++ Firmware/ChameleonMini/Terminal/Commands.c | 19 +++++++++++++++++++ Firmware/ChameleonMini/Terminal/Commands.h | 11 ++++++++++- 9 files changed, 59 insertions(+), 3 deletions(-) diff --git a/Firmware/ChameleonMini/Application/MifareClassic.c b/Firmware/ChameleonMini/Application/MifareClassic.c index b0085ce..eeab753 100644 --- a/Firmware/ChameleonMini/Application/MifareClassic.c +++ b/Firmware/ChameleonMini/Application/MifareClassic.c @@ -664,7 +664,7 @@ uint16_t MifareClassicAppProcess(uint8_t* Buffer, uint16_t BitCount) { isFromHaltChain = (State == STATE_HALT); isCascadeStepOnePassed = false; #ifdef SUPPORT_MF_CLASSIC_MAGIC_MODE - if (Buffer[0] == MFCLASSIC_CMD_CHINESE_UNLOCK) { + if (Buffer[0] == MFCLASSIC_CMD_CHINESE_UNLOCK && AppMemoryUidMode()) { State = STATE_CHINESE_IDLE; Buffer[0] = MFCLASSIC_ACK_VALUE; retSize = MFCLASSIC_ACK_NAK_FRAME_SIZE; @@ -785,6 +785,11 @@ uint16_t MifareClassicAppProcess(uint8_t* Buffer, uint16_t BitCount) { break; /* End of state READY */ case STATE_ACTIVE: + if (Buffer[0] == MFCLASSIC_CMD_CHINESE_UNLOCK && AppMemoryUidMode()) { + State = STATE_CHINESE_IDLE; + Buffer[0] = MFCLASSIC_ACK_VALUE; + retSize = MFCLASSIC_ACK_NAK_FRAME_SIZE; + } if ( (Buffer[0] == MFCLASSIC_CMD_AUTH_A) || (Buffer[0] == MFCLASSIC_CMD_AUTH_B) ) { if (ISO14443ACheckCRCA(Buffer, MFCLASSIC_CMD_AUTH_FRAME_SIZE)) { mfcHandleAuthenticationRequest(false, Buffer, &retSize); diff --git a/Firmware/ChameleonMini/Makefile b/Firmware/ChameleonMini/Makefile index 9a66016..8db2dfb 100644 --- a/Firmware/ChameleonMini/Makefile +++ b/Firmware/ChameleonMini/Makefile @@ -25,7 +25,7 @@ SETTINGS += -DCONFIG_MF_CLASSIC_DETECTION_SUPPORT #SETTINGS += -DCONFIG_MF_CLASSIC_LOG_SUPPORT #Support magic mode on mifare classic configuration -#SETTINGS += -DSUPPORT_MF_CLASSIC_MAGIC_MODE +SETTINGS += -DSUPPORT_MF_CLASSIC_MAGIC_MODE #Support activating firmware upgrade mode through command-line SETTINGS += -DSUPPORT_FIRMWARE_UPGRADE diff --git a/Firmware/ChameleonMini/Memory/Memory.c b/Firmware/ChameleonMini/Memory/Memory.c index b49503e..908b3f3 100644 --- a/Firmware/ChameleonMini/Memory/Memory.c +++ b/Firmware/ChameleonMini/Memory/Memory.c @@ -270,3 +270,7 @@ bool AppCardMemoryClear(void) { bool AppWorkingMemoryClear(void) { return AppWorkingMemoryClearForSetting(GlobalSettings.ActiveSetting); } + +bool AppMemoryUidMode(void) { + return GlobalSettings.UidMode; +} diff --git a/Firmware/ChameleonMini/Memory/Memory.h b/Firmware/ChameleonMini/Memory/Memory.h index 0ba7da0..0b0af14 100644 --- a/Firmware/ChameleonMini/Memory/Memory.h +++ b/Firmware/ChameleonMini/Memory/Memory.h @@ -88,4 +88,6 @@ bool AppCardMemoryClear(void); bool AppWorkingMemoryClearForSetting(uint8_t SettingNumber); bool AppWorkingMemoryClear(void); +bool AppMemoryUidMode(void); + #endif /* _MEM_MEMORY_H_ */ diff --git a/Firmware/ChameleonMini/Settings.c b/Firmware/ChameleonMini/Settings.c index 1939c8d..5f073f6 100644 --- a/Firmware/ChameleonMini/Settings.c +++ b/Firmware/ChameleonMini/Settings.c @@ -14,6 +14,7 @@ SettingsType GlobalSettings; SettingsType EEMEM StoredSettings = { .ActiveSetting = DEFAULT_SETTING, .ActiveSettingPtr = &GlobalSettings.Settings[DEFAULT_SETTING], + .UidMode = 0, .Settings = { [SETTINGS_FIRST ... SETTINGS_LAST] = { .Configuration = DEFAULT_CONFIGURATION, @@ -82,3 +83,8 @@ bool SettingsSetActiveByName(const char* Setting) { return false; } } + +void SettingsSetUidMode(bool isActive) { + GlobalSettings.UidMode = isActive; + SettingsSave(); +} diff --git a/Firmware/ChameleonMini/Settings.h b/Firmware/ChameleonMini/Settings.h index 490d859..0193098 100644 --- a/Firmware/ChameleonMini/Settings.h +++ b/Firmware/ChameleonMini/Settings.h @@ -35,6 +35,7 @@ typedef struct { uint8_t ActiveSetting; SettingsEntryType* ActiveSettingPtr; SettingsEntryType Settings[SETTINGS_COUNT]; + bool UidMode; } SettingsType; extern SettingsType GlobalSettings; @@ -49,4 +50,6 @@ uint8_t SettingsGetActiveById(void); void SettingsGetActiveByName(char* SettingOut, uint16_t BufferSize); bool SettingsSetActiveByName(const char* Setting); +void SettingsSetUidMode(bool isActive); + #endif /* SETTINGS_H_ */ diff --git a/Firmware/ChameleonMini/Terminal/CommandLine.c b/Firmware/ChameleonMini/Terminal/CommandLine.c index 2078ebc..0b7d8c5 100644 --- a/Firmware/ChameleonMini/Terminal/CommandLine.c +++ b/Firmware/ChameleonMini/Terminal/CommandLine.c @@ -330,6 +330,14 @@ const PROGMEM CommandEntryType CommandTable[] = { .SetFunc = NO_FUNCTION, .GetFunc = CommandGetDetection, }, +#endif +#ifdef SUPPORT_MF_CLASSIC_MAGIC_MODE + { + .Command = COMMAND_UIDMOD, + .ExecFunc = NO_FUNCTION, + .SetFunc = CommandSetUidMode, + .GetFunc = CommandGetUidMode, + }, #endif { .Command = COMMAND_CLEARALL, diff --git a/Firmware/ChameleonMini/Terminal/Commands.c b/Firmware/ChameleonMini/Terminal/Commands.c index b23e2da..8688dc7 100644 --- a/Firmware/ChameleonMini/Terminal/Commands.c +++ b/Firmware/ChameleonMini/Terminal/Commands.c @@ -429,6 +429,25 @@ CommandStatusIdType CommandGetDetection(char* OutParam) { } #endif +#ifdef SUPPORT_MF_CLASSIC_MAGIC_MODE +CommandStatusIdType CommandGetUidMode(char* OutParam) { + snprintf_P(OutParam, TERMINAL_BUFFER_SIZE, PSTR("%u"), GlobalSettings.UidMode); + return COMMAND_INFO_OK_WITH_TEXT_ID; +} +CommandStatusIdType CommandSetUidMode(char* OutMessage, const char* InParam) { + if (InParam[1] == '\0') { + if (InParam[0] == COMMAND_CHAR_TRUE) { + SettingsSetUidMode(true); + return COMMAND_INFO_OK_ID; + } else if (InParam[0] == COMMAND_CHAR_FALSE) { + SettingsSetUidMode(false); + return COMMAND_INFO_OK_ID; + } + } + return COMMAND_ERR_INVALID_PARAM_ID; +} +#endif + CommandStatusIdType CommandExecClearAll(char* OutMessage) { MemoryClearAll(); for(uint8_t i = SETTINGS_FIRST; i <= SETTINGS_LAST; i++) { diff --git a/Firmware/ChameleonMini/Terminal/Commands.h b/Firmware/ChameleonMini/Terminal/Commands.h index b39285f..6c917d1 100644 --- a/Firmware/ChameleonMini/Terminal/Commands.h +++ b/Firmware/ChameleonMini/Terminal/Commands.h @@ -1,4 +1,4 @@ -/* Copyright 2013 Timo Kasper, Simon KŸppers, David Oswald ("ORIGINAL +/* Copyright 2013 Timo Kasper, Simon KŸppers, David Oswald ("ORIGINAL * AUTHORS"). All rights reserved. * * DEFINITIONS: @@ -196,6 +196,15 @@ CommandStatusIdType CommandGetUltralightPassword(char* OutParam); CommandStatusIdType CommandGetDetection(char* OutParam); #endif +#define COMMAND_CLONE "CLONE" +CommandStatusIdType CommandExecClone(char *OutMessage); + +#ifdef SUPPORT_MF_CLASSIC_MAGIC_MODE +#define COMMAND_UIDMOD "UIDMODE" +CommandStatusIdType CommandGetUidMode(char* OutParam); +CommandStatusIdType CommandSetUidMode(char* OutMessage, const char* InParam); +#endif + #define COMMAND_CLEARALL "CLEARALL" CommandStatusIdType CommandExecClearAll(char* OutMessage); From fd70f103f23f2cd372ea95e740c69befb42e4942 Mon Sep 17 00:00:00 2001 From: ca1e Date: Sat, 23 Jan 2021 11:36:00 +0800 Subject: [PATCH 2/2] clean up --- Firmware/ChameleonMini/Application/MifareClassic.c | 3 +++ Firmware/ChameleonMini/Terminal/Commands.h | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Firmware/ChameleonMini/Application/MifareClassic.c b/Firmware/ChameleonMini/Application/MifareClassic.c index eeab753..d18dc13 100644 --- a/Firmware/ChameleonMini/Application/MifareClassic.c +++ b/Firmware/ChameleonMini/Application/MifareClassic.c @@ -785,11 +785,14 @@ uint16_t MifareClassicAppProcess(uint8_t* Buffer, uint16_t BitCount) { break; /* End of state READY */ case STATE_ACTIVE: +#ifdef SUPPORT_MF_CLASSIC_MAGIC_MODE if (Buffer[0] == MFCLASSIC_CMD_CHINESE_UNLOCK && AppMemoryUidMode()) { State = STATE_CHINESE_IDLE; Buffer[0] = MFCLASSIC_ACK_VALUE; retSize = MFCLASSIC_ACK_NAK_FRAME_SIZE; + break; } +#endif if ( (Buffer[0] == MFCLASSIC_CMD_AUTH_A) || (Buffer[0] == MFCLASSIC_CMD_AUTH_B) ) { if (ISO14443ACheckCRCA(Buffer, MFCLASSIC_CMD_AUTH_FRAME_SIZE)) { mfcHandleAuthenticationRequest(false, Buffer, &retSize); diff --git a/Firmware/ChameleonMini/Terminal/Commands.h b/Firmware/ChameleonMini/Terminal/Commands.h index 6c917d1..3a62b46 100644 --- a/Firmware/ChameleonMini/Terminal/Commands.h +++ b/Firmware/ChameleonMini/Terminal/Commands.h @@ -196,9 +196,6 @@ CommandStatusIdType CommandGetUltralightPassword(char* OutParam); CommandStatusIdType CommandGetDetection(char* OutParam); #endif -#define COMMAND_CLONE "CLONE" -CommandStatusIdType CommandExecClone(char *OutMessage); - #ifdef SUPPORT_MF_CLASSIC_MAGIC_MODE #define COMMAND_UIDMOD "UIDMODE" CommandStatusIdType CommandGetUidMode(char* OutParam);