HF_Legic: remove global variable and cleanup

As requested by @iceman1001:
* removed global variable
* updated according to make style
* added entry in CHANGELOG.md
This commit is contained in:
Uli Heilmeier 2020-03-30 10:22:45 +02:00
commit db02a1f306
4 changed files with 45 additions and 48 deletions

View file

@ -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... 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] ## [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) - 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 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) - Fix 'hf mfdes info' - now detects DESFire light and work properly Wrapped commands :+1: (@iceman1001)

View file

@ -29,21 +29,21 @@ void ModInfo(void) {
// A, B, C = Reading // A, B, C = Reading
// A, D = Simulating // A, D = Simulating
void RunMod(){ void RunMod() {
StandAloneMode(); StandAloneMode();
FpgaDownloadAndGo(FPGA_BITSTREAM_HF); FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
Dbprintf(">> HF Legic Prime Read/Simulate Started <<"); Dbprintf(">> HF Legic Prime Read/Simulate Started <<");
int read_success; int read_success;
for(;;){ for (;;) {
WDT_HIT(); WDT_HIT();
//exit from hf_legic, send usbcommand //exit from hf_legic, send usbcommand
if(data_available()) break; if (data_available()) break;
//Was our button held down or pressed? //Was our button held down or pressed?
int button_pressed = BUTTON_HELD(280); int button_pressed = BUTTON_HELD(280);
if(button_pressed != BUTTON_HOLD) continue; if (button_pressed != BUTTON_HOLD) continue;
LED_A_OFF(); LED_A_OFF();
LED_B_OFF(); LED_B_OFF();
@ -56,24 +56,23 @@ void RunMod(){
DbpString("[=] start recording"); DbpString("[=] start recording");
//search for legic card until reading successfull or button pressed //search for legic card until reading successfull or button pressed
do{ do {
LED_C_ON(); LED_C_ON();
SpinDelay(1000); SpinDelay(1000);
// We don't care if we read a MIM256, MIM512 or MIM1024 // We don't care if we read a MIM256, MIM512 or MIM1024
// we just read 1024 bytes // we just read 1024 bytes
LegicRfReader(0, 1024, 0x55); read_success = LegicRfReader(0, 1024, 0x55);
read_success = check_success(); } while (read_success == 0 && !BUTTON_PRESS());
}while(read_success == 0 && !BUTTON_PRESS());
//simulate if read successfully //simulate if read successfully
if(read_success == 1){ if (read_success == 1) {
LED_A_OFF(); LED_A_OFF();
LED_B_OFF(); LED_B_OFF();
LED_C_OFF(); LED_C_OFF();
LED_D_ON(); LED_D_ON();
// The read data is migrated to a MIM1024 card // The read data is migrated to a MIM1024 card
LegicRfSimulate(2); LegicRfSimulate(2);
}else{ } else {
LEDsoff(); LEDsoff();
WAIT_BUTTON_RELEASED(); WAIT_BUTTON_RELEASED();
} }

View file

@ -28,7 +28,6 @@
static uint8_t *legic_mem; /* card memory, used for read, write */ static uint8_t *legic_mem; /* card memory, used for read, write */
static legic_card_select_t card;/* metadata of currently selected card */ static legic_card_select_t card;/* metadata of currently selected card */
static crc_t legic_crc; static crc_t legic_crc;
int read_success = 0;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Frame timing and pseudorandom number generator // Frame timing and pseudorandom number generator
@ -442,10 +441,10 @@ OUT:
StopTicks(); 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 // configure ARM and FPGA
init_reader(false); init_reader(false);
read_success = 0;
// establish shared secret and detect card type // establish shared secret and detect card type
uint8_t card_type = setup_phase(iv); uint8_t card_type = setup_phase(iv);
@ -475,6 +474,7 @@ void LegicRfReader(uint16_t offset, uint16_t len, uint8_t iv) {
OUT: OUT:
switch_off(); switch_off();
StopTicks(); StopTicks();
return read_success;
} }
void LegicRfWriter(uint16_t offset, uint16_t len, uint8_t iv, uint8_t *data) { void LegicRfWriter(uint16_t offset, uint16_t len, uint8_t iv, uint8_t *data) {
@ -515,5 +515,3 @@ OUT:
switch_off(); switch_off();
StopTicks(); StopTicks();
} }
int check_success(void){return read_success;}

View file

@ -15,7 +15,6 @@
#include "common.h" #include "common.h"
void LegicRfInfo(void); 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); void LegicRfWriter(uint16_t offset, uint16_t len, uint8_t iv, uint8_t *data);
int check_success(void);
#endif /* __LEGICRF_H */ #endif /* __LEGICRF_H */