diff --git a/CHANGELOG.md b/CHANGELOG.md index 6192b8068..3032b04fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] + - Added `HF_LEGIC` standalone mode to read and simulate a Legic prime tag (@Pizza_4u) - Added keri MS decode/encode and update 'lf keri clone' to support MS fc/cid cloning. (@mwalker33) - Fix 'hf mfdes enum' - now actually manages to enumerate files under all AID's. :smiley: (@iceman1001) - Fix 'hf mfdes info' - now detects DESFire light and work properly Wrapped commands :+1: (@iceman1001) diff --git a/armsrc/Standalone/Makefile.hal b/armsrc/Standalone/Makefile.hal index 5c2352aaf..bd018e15b 100644 --- a/armsrc/Standalone/Makefile.hal +++ b/armsrc/Standalone/Makefile.hal @@ -50,7 +50,7 @@ define KNOWN_STANDALONE_DEFINITIONS endef STANDALONE_MODES := LF_SAMYRUN LF_ICERUN LF_PROXBRUTE LF_HIDBRUTE LF_ICEHID LF_EM4100EMUL LF_EM4100RWC -STANDALONE_MODES += HF_YOUNG HF_MATTYRUN HF_COLIN HF_BOG HF_14ASNIFF +STANDALONE_MODES += HF_YOUNG HF_MATTYRUN HF_COLIN HF_BOG HF_14ASNIFF HF_LEGIC STANDALONE_MODES_REQ_SMARTCARD := STANDALONE_MODES_REQ_FLASH := HF_COLIN HF_BOG HF_14ASNIFF LF_ICEHID ifneq ($(filter $(STANDALONE),$(STANDALONE_MODES)),) diff --git a/armsrc/Standalone/Makefile.inc b/armsrc/Standalone/Makefile.inc index e5a3304a8..4b480ad3a 100644 --- a/armsrc/Standalone/Makefile.inc +++ b/armsrc/Standalone/Makefile.inc @@ -48,4 +48,8 @@ endif # WITH_STANDALONE_LF_EM4100RWC ifneq (,$(findstring WITH_STANDALONE_LF_EM4100RWC,$(APP_CFLAGS))) SRC_STANDALONE = lf_em4100rwc.c -endif \ No newline at end of file +endif +# WITH_STANDALONE_HF_LEGIC +ifneq (,$(findstring WITH_STANDALONE_HF_LEGIC,$(APP_CFLAGS))) + SRC_STANDALONE = hf_legic.c +endif diff --git a/armsrc/Standalone/hf_legic.c b/armsrc/Standalone/hf_legic.c new file mode 100644 index 000000000..1e7aa7114 --- /dev/null +++ b/armsrc/Standalone/hf_legic.c @@ -0,0 +1,80 @@ +//----------------------------------------------------------------------------- +// Stefanie Hofmann, 2020 +// Uli Heilmeier, 2020 +// +// This code is licensed to you under the terms of the GNU GPL, version 2 or, +// at your option, any later version. See the LICENSE.txt file for the text of +// the license. +//----------------------------------------------------------------------------- +// main code for Legic Prime read/sim +//----------------------------------------------------------------------------- +#include "standalone.h" +#include "proxmark3_arm.h" +#include "appmain.h" +#include "fpgaloader.h" +#include "util.h" +#include "dbprint.h" +#include "ticks.h" + +#include "legicrf.h" +#include "legicrfsim.h" + +void ModInfo(void) { + DbpString(" HF Legic Prime standalone "); +} + +// Searching for Legic card until found and read. +// Simulating recorded Legic Prime card. +// C = Searching +// A, B, C = Reading +// A, D = Simulating + +void RunMod() { + StandAloneMode(); + FpgaDownloadAndGo(FPGA_BITSTREAM_HF); + Dbprintf(">> HF Legic Prime Read/Simulate Started <<"); + + int read_success; + for (;;) { + WDT_HIT(); + + //exit from hf_legic, send usbcommand + if (data_available()) break; + + //Was our button held down or pressed? + int button_pressed = BUTTON_HELD(280); + if (button_pressed != BUTTON_HOLD) continue; + + LED_A_OFF(); + LED_B_OFF(); + LED_C_ON(); + LED_D_OFF(); + + WAIT_BUTTON_RELEASED(); + + //record + DbpString("[=] start recording"); + + //search for legic card until reading successfull or button pressed + do { + LED_C_ON(); + SpinDelay(1000); + // We don't care if we read a MIM256, MIM512 or MIM1024 + // we just read 1024 bytes + read_success = LegicRfReader(0, 1024, 0x55); + } while (read_success == 0 && !BUTTON_PRESS()); + + //simulate if read successfully + if (read_success == 1) { + LED_A_OFF(); + LED_B_OFF(); + LED_C_OFF(); + LED_D_ON(); + // The read data is migrated to a MIM1024 card + LegicRfSimulate(2); + } else { + LEDsoff(); + WAIT_BUTTON_RELEASED(); + } + } +} diff --git a/armsrc/legicrf.c b/armsrc/legicrf.c index 0665705b6..313b38fc5 100644 --- a/armsrc/legicrf.c +++ b/armsrc/legicrf.c @@ -441,7 +441,8 @@ OUT: StopTicks(); } -void LegicRfReader(uint16_t offset, uint16_t len, uint8_t iv) { +int LegicRfReader(uint16_t offset, uint16_t len, uint8_t iv) { + int read_success = 0; // configure ARM and FPGA init_reader(false); @@ -467,11 +468,13 @@ void LegicRfReader(uint16_t offset, uint16_t len, uint8_t iv) { } // OK + read_success = 1; reply_old(CMD_ACK, 1, len, 0, legic_mem, len); OUT: switch_off(); StopTicks(); + return read_success; } void LegicRfWriter(uint16_t offset, uint16_t len, uint8_t iv, uint8_t *data) { diff --git a/armsrc/legicrf.h b/armsrc/legicrf.h index 47a7f89d6..6e59f4ca7 100644 --- a/armsrc/legicrf.h +++ b/armsrc/legicrf.h @@ -15,7 +15,6 @@ #include "common.h" void LegicRfInfo(void); -void LegicRfReader(uint16_t offset, uint16_t len, uint8_t iv); +int LegicRfReader(uint16_t offset, uint16_t len, uint8_t iv); void LegicRfWriter(uint16_t offset, uint16_t len, uint8_t iv, uint8_t *data); - #endif /* __LEGICRF_H */