Skip to content

Commit

Permalink
Merge pull request #190 from ca1e/master
Browse files Browse the repository at this point in the history
Add UIDMODE command
  • Loading branch information
iceman1001 authored Jan 23, 2021
2 parents 9f958e9 + fd70f10 commit 18007ef
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 3 deletions.
10 changes: 9 additions & 1 deletion Firmware/ChameleonMini/Application/MifareClassic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -785,6 +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);
Expand Down
2 changes: 1 addition & 1 deletion Firmware/ChameleonMini/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,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
Expand Down
4 changes: 4 additions & 0 deletions Firmware/ChameleonMini/Memory/Memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,7 @@ bool AppCardMemoryClear(void) {
bool AppWorkingMemoryClear(void) {
return AppWorkingMemoryClearForSetting(GlobalSettings.ActiveSetting);
}

bool AppMemoryUidMode(void) {
return GlobalSettings.UidMode;
}
2 changes: 2 additions & 0 deletions Firmware/ChameleonMini/Memory/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,6 @@ bool AppCardMemoryClear(void);
bool AppWorkingMemoryClearForSetting(uint8_t SettingNumber);
bool AppWorkingMemoryClear(void);

bool AppMemoryUidMode(void);

#endif /* _MEM_MEMORY_H_ */
6 changes: 6 additions & 0 deletions Firmware/ChameleonMini/Settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -82,3 +83,8 @@ bool SettingsSetActiveByName(const char* Setting) {
return false;
}
}

void SettingsSetUidMode(bool isActive) {
GlobalSettings.UidMode = isActive;
SettingsSave();
}
3 changes: 3 additions & 0 deletions Firmware/ChameleonMini/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ typedef struct {
uint8_t ActiveSetting;
SettingsEntryType* ActiveSettingPtr;
SettingsEntryType Settings[SETTINGS_COUNT];
bool UidMode;
} SettingsType;

extern SettingsType GlobalSettings;
Expand All @@ -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_ */
8 changes: 8 additions & 0 deletions Firmware/ChameleonMini/Terminal/CommandLine.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 19 additions & 0 deletions Firmware/ChameleonMini/Terminal/Commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,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++) {
Expand Down
8 changes: 7 additions & 1 deletion Firmware/ChameleonMini/Terminal/Commands.h
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -196,6 +196,12 @@ CommandStatusIdType CommandGetUltralightPassword(char* OutParam);
CommandStatusIdType CommandGetDetection(char* OutParam);
#endif

#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);

Expand Down

0 comments on commit 18007ef

Please sign in to comment.