Skip to content

Commit

Permalink
Merge pull request RfidResearchGroup#2409 from ghiki/master
Browse files Browse the repository at this point in the history
Update lf_em4100emul.c
  • Loading branch information
iceman1001 authored Jun 23, 2024
2 parents 8cb344e + a8ac0f3 commit 81fd620
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions armsrc/Standalone/lf_em4100emul.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,48 +41,48 @@ void ModInfo(void) {
DbpString(" LF EM4100 simulator standalone mode");
}

static uint64_t rev_quads(uint64_t bits) {
static uint64_t em4100emul_rev_quads(uint64_t bits) {
uint64_t result = 0;
for (int i = 0; i < 16; i++) {
result += ((bits >> (60 - 4 * i)) & 0xf) << (4 * i);
}
return result >> 24;
}

static void fill_buff(uint8_t bit) {
static void em4100emul_fill_buff(uint8_t bit) {
uint8_t *bba = BigBuf_get_addr();
memset(bba + em4100emul_buflen, bit, LF_CLOCK / 2);
em4100emul_buflen += (LF_CLOCK / 2);
memset(bba + em4100emul_buflen, bit ^ 1, LF_CLOCK / 2);
em4100emul_buflen += (LF_CLOCK / 2);
}

static void construct_EM410x_emul(uint64_t id) {
static void em4100emul_construct_EM410x_emul(uint64_t id) {

int i, j;
int binary[4] = {0, 0, 0, 0};
int parity[4] = {0, 0, 0, 0};
em4100emul_buflen = 0;

for (i = 0; i < 9; i++)
fill_buff(1);
em4100emul_fill_buff(1);

for (i = 0; i < 10; i++) {
for (j = 3; j >= 0; j--, id /= 2)
binary[j] = id % 2;

for (j = 0; j < 4; j++)
fill_buff(binary[j]);
em4100emul_fill_buff(binary[j]);

fill_buff(binary[0] ^ binary[1] ^ binary[2] ^ binary[3]);
em4100emul_fill_buff(binary[0] ^ binary[1] ^ binary[2] ^ binary[3]);
for (j = 0; j < 4; j++)
parity[j] ^= binary[j];
}

for (j = 0; j < 4; j++)
fill_buff(parity[j]);
em4100emul_fill_buff(parity[j]);

fill_buff(0);
em4100emul_fill_buff(0);
}

static void LED_Slot(int i) {
Expand All @@ -108,8 +108,18 @@ void RunMod(void) {
SpinDelay(100);
SpinUp(100);
LED_Slot(selected);
construct_EM410x_emul(rev_quads(em4100emul_low[selected]));
Dbprintf("Emulating 0x%010llX", em4100emul_low[selected]);
em4100emul_construct_EM410x_emul(em4100emul_rev_quads(em4100emul_low[selected]));
SimulateTagLowFrequency(em4100emul_buflen, 0, true);

//Exit! Button hold break
int button_pressed = BUTTON_HELD(500);
if (button_pressed == BUTTON_HOLD) {
Dbprintf("Button hold, Break!");
LEDsoff();
Dbprintf("[=] >> LF EM4100 simulator stopped due to button hold <<");
return; // RunMod end
}
selected = (selected + 1) % em4100emul_slots_count;
}
}

0 comments on commit 81fd620

Please sign in to comment.