1 //-----------------------------------------------------------------------------
2 // Artyom Gnatyuk, 2020
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
7 //-----------------------------------------------------------------------------
8 // LF emul - Very simple mode. Simulate only predefined in low[] IDs
9 // Short click - select next slot and start simulation
10 //-----------------------------------------------------------------------------
11 #include "standalone.h"
12 #include "proxmark3_arm.h"
14 #include "fpgaloader.h"
21 #include "commonutil.h"
23 #define MAX_IND 16 // 4 LEDs - 2^4 combinations
24 #define LF_CLOCK 64 // for 125kHz
26 // low & high - array for storage IDs. Its length must be equal.
27 // Predefined IDs must be stored in low[].
28 static uint64_t low
[] = {0x565A1140BE, 0x365A398149, 0x5555555555, 0xFFFFFFFFFF};
29 static uint8_t slots_count
;
33 DbpString(" LF EM4100 simulator standalone mode");
36 static uint64_t rev_quads(uint64_t bits
) {
38 for (int i
= 0; i
< 16; i
++) {
39 result
+= ((bits
>> (60 - 4 * i
)) & 0xf) << (4 * i
);
44 static void fill_buff(uint8_t bit
) {
45 uint8_t *bba
= BigBuf_get_addr();
46 memset(bba
+ buflen
, bit
, LF_CLOCK
/ 2);
47 buflen
+= (LF_CLOCK
/ 2);
48 memset(bba
+ buflen
, bit
^ 1, LF_CLOCK
/ 2);
49 buflen
+= (LF_CLOCK
/ 2);
52 static void construct_EM410x_emul(uint64_t id
) {
55 int binary
[4] = {0, 0, 0, 0};
56 int parity
[4] = {0, 0, 0, 0};
59 for (i
= 0; i
< 9; i
++)
62 for (i
= 0; i
< 10; i
++) {
63 for (j
= 3; j
>= 0; j
--, id
/= 2)
66 for (j
= 0; j
< 4; j
++)
69 fill_buff(binary
[0] ^ binary
[1] ^ binary
[2] ^ binary
[3]);
70 for (j
= 0; j
< 4; j
++)
71 parity
[j
] ^= binary
[j
];
74 for (j
= 0; j
< 4; j
++)
80 static void LED_Slot(int i
) {
82 if (slots_count
> 4) {
83 LED(i
% MAX_IND
, 0); //binary indication for slots_count > 4
85 LED(1 << i
, 0); //simple indication for slots_count <=4
91 FpgaDownloadAndGo(FPGA_BITSTREAM_LF
);
92 Dbprintf("[=] >> LF EM4100 simulator started <<");
94 int selected
= 0; //selected slot after start
95 slots_count
= ARRAYLEN(low
);
98 if (data_available()) break;
103 construct_EM410x_emul(rev_quads(low
[selected
]));
104 SimulateTagLowFrequency(buflen
, 0, true);
105 selected
= (selected
+ 1) % slots_count
;