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

CLONE_MFU: command and button action #239

Merged
merged 1 commit into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions Firmware/Chameleon-Mini/Application/Reader14443A.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ uint16_t Reader14443AAppProcess(uint8_t *Buffer, uint16_t BitCount) {
return rVal;
}

case Reader14443_Clone_MF_Ultralight:
case Reader14443_Read_MF_Ultralight: {
static uint8_t MFURead_CurrentAdress = 0;
static uint8_t MFUContents[64];
Expand Down Expand Up @@ -717,18 +718,28 @@ uint16_t Reader14443AAppProcess(uint8_t *Buffer, uint16_t BitCount) {
if (MFURead_CurrentAdress == 16) {
Selected = false;
MFURead_CurrentAdress = 0;
Reader14443CurrentCommand = Reader14443_Do_Nothing;

char tmpBuf[135]; // 135 = 128 hex digits + 3 * \r\n + \0
BufferToHexString(tmpBuf, 135, MFUContents, 16);
snprintf(tmpBuf + 32, 135 - 32, "\r\n");
BufferToHexString(tmpBuf + 32 + 2, 135 - 32 - 2, MFUContents + 16, 16);
snprintf(tmpBuf + 32 + 2 + 32, 135 - 32 - 2 - 32, "\r\n");
BufferToHexString(tmpBuf + 32 + 2 + 32 + 2, 135 - 32 - 2 - 32 - 2, MFUContents + 32, 16);
snprintf(tmpBuf + 32 + 2 + 32 + 2 + 32, 135 - 32 - 2 - 32 - 2 - 32, "\r\n");
BufferToHexString(tmpBuf + 32 + 2 + 32 + 2 + 32 + 2, 135 - 32 - 2 - 32 - 2 - 32 - 2, MFUContents + 48, 16);
CodecReaderFieldStop();
CommandLinePendingTaskFinished(COMMAND_INFO_OK_WITH_TEXT_ID, tmpBuf);

if (Reader14443CurrentCommand == Reader14443_Read_MF_Ultralight) { // dump
Reader14443CurrentCommand = Reader14443_Do_Nothing;
char tmpBuf[135]; // 135 = 128 hex digits + 3 * \r\n + \0
BufferToHexString(tmpBuf, 135, MFUContents, 16);
snprintf(tmpBuf + 32, 135 - 32, "\r\n");
BufferToHexString(tmpBuf + 32 + 2, 135 - 32 - 2, MFUContents + 16, 16);
snprintf(tmpBuf + 32 + 2 + 32, 135 - 32 - 2 - 32, "\r\n");
BufferToHexString(tmpBuf + 32 + 2 + 32 + 2, 135 - 32 - 2 - 32 - 2, MFUContents + 32, 16);
snprintf(tmpBuf + 32 + 2 + 32 + 2 + 32, 135 - 32 - 2 - 32 - 2 - 32, "\r\n");
BufferToHexString(tmpBuf + 32 + 2 + 32 + 2 + 32 + 2, 135 - 32 - 2 - 32 - 2 - 32 - 2, MFUContents + 48, 16);
CodecReaderFieldStop();
CommandLinePendingTaskFinished(COMMAND_INFO_OK_WITH_TEXT_ID, tmpBuf);
} else { // clone
Reader14443CurrentCommand = Reader14443_Do_Nothing;
CodecReaderFieldStop();
MemoryUploadBlock(&MFUContents, 0, 64);
CommandLinePendingTaskFinished(COMMAND_INFO_OK_WITH_TEXT_ID, "Card Cloned to Slot");
ConfigurationSetById(CONFIG_MF_ULTRALIGHT);
MemoryStore();
SettingsSave();
}
return 0;
}
Buffer[0] = 0x30; // MiFare Ultralight read command
Expand Down
3 changes: 2 additions & 1 deletion Firmware/Chameleon-Mini/Application/Reader14443A.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ typedef enum {
Reader14443_Autocalibrate,
Reader14443_Read_MF_Ultralight,
Reader14443_Identify,
Reader14443_Identify_Clone
Reader14443_Identify_Clone,
Reader14443_Clone_MF_Ultralight
} Reader14443Command;


Expand Down
5 changes: 5 additions & 0 deletions Firmware/Chameleon-Mini/Button.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ static const MapEntryType PROGMEM ButtonActionMap[] = {
{ .Id = BUTTON_ACTION_TOGGLE_FIELD, .Text = "TOGGLE_FIELD" },
{ .Id = BUTTON_ACTION_STORE_LOG, .Text = "STORE_LOG" },
{ .Id = BUTTON_ACTION_CLONE, .Text = "CLONE" },
{ .Id = BUTTON_ACTION_CLONE_MFU, .Text = "CLONE_MFU" },
};

static void ExecuteButtonAction(ButtonActionEnum ButtonAction) {
Expand Down Expand Up @@ -178,6 +179,10 @@ static void ExecuteButtonAction(ButtonActionEnum ButtonAction) {
CommandExecute("CLONE");
break;
}
case BUTTON_ACTION_CLONE_MFU: {
CommandExecute("CLONE_MFU");
break;
}

default:
break;
Expand Down
1 change: 1 addition & 0 deletions Firmware/Chameleon-Mini/Button.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ typedef enum {
BUTTON_ACTION_TOGGLE_FIELD,
BUTTON_ACTION_STORE_LOG,
BUTTON_ACTION_CLONE,
BUTTON_ACTION_CLONE_MFU,

/* This has to be last element */
BUTTON_ACTION_COUNT
Expand Down
7 changes: 7 additions & 0 deletions Firmware/Chameleon-Mini/Terminal/CommandLine.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,13 @@ const PROGMEM CommandEntryType CommandTable[] = {
.SetFunc = NO_FUNCTION,
.GetFunc = NO_FUNCTION
},
{
.Command = COMMAND_CLONE_MFU,
.ExecFunc = CommandExecCloneMFU,
.ExecParamFunc = NO_FUNCTION,
.SetFunc = NO_FUNCTION,
.GetFunc = NO_FUNCTION
},
{
.Command = COMMAND_IDENTIFY_CARD,
.ExecFunc = CommandExecIdentifyCard,
Expand Down
11 changes: 11 additions & 0 deletions Firmware/Chameleon-Mini/Terminal/Commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,17 @@ CommandStatusIdType CommandExecDumpMFU(char *OutMessage) {
return TIMEOUT_COMMAND;
}

CommandStatusIdType CommandExecCloneMFU(char *OutMessage) {
ConfigurationSetById(CONFIG_ISO14443A_READER);
ApplicationReset();

Reader14443CurrentCommand = Reader14443_Clone_MF_Ultralight;
Reader14443AAppInit();
Reader14443ACodecStart();
CommandLinePendingTaskTimeout = &Reader14443AAppTimeout;
return TIMEOUT_COMMAND;
}

CommandStatusIdType CommandExecGetUid(char *OutMessage) { // this function is for reading the uid in reader mode
if (GlobalSettings.ActiveSettingPtr->Configuration != CONFIG_ISO14443A_READER)
return COMMAND_ERR_INVALID_USAGE_ID;
Expand Down
3 changes: 3 additions & 0 deletions Firmware/Chameleon-Mini/Terminal/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ CommandStatusIdType CommandExecGetUid(char *OutMessage);
#define COMMAND_DUMP_MFU "DUMP_MFU"
CommandStatusIdType CommandExecDumpMFU(char *OutMessage);

#define COMMAND_CLONE_MFU "CLONE_MFU"
CommandStatusIdType CommandExecCloneMFU(char *OutMessage);

#define COMMAND_IDENTIFY_CARD "IDENTIFY"
CommandStatusIdType CommandExecIdentifyCard(char *OutMessage);

Expand Down