]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlfguard.c
1 //-----------------------------------------------------------------------------
3 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
4 // at your option, any later version. See the LICENSE.txt file for the text of
6 //-----------------------------------------------------------------------------
7 // Low frequency Farpoint / Pyramid tag commands
8 //-----------------------------------------------------------------------------
11 #include "cmdlfguard.h"
12 static int CmdHelp(const char *Cmd
);
14 int usage_lf_guard_clone(void){
15 PrintAndLog("clone a Guardall tag to a T55x7 tag.");
16 PrintAndLog("The facility-code is 8-bit and the card number is 16-bit. Larger values are truncated. ");
17 PrintAndLog("Currently work only on 26bit");
19 PrintAndLog("Usage: lf guard clone <Facility-Code> <Card-Number>");
20 PrintAndLog("Options :");
21 PrintAndLog(" <Facility-Code> : 8-bit value facility code");
22 PrintAndLog(" <Card Number> : 16-bit value card number");
24 PrintAndLog("Sample : lf guard clone 123 11223");
28 int usage_lf_guard_sim(void) {
29 PrintAndLog("Enables simulation of Guardall card with specified card number.");
30 PrintAndLog("Simulation runs until the button is pressed or another USB command is issued.");
31 PrintAndLog("The facility-code is 8-bit and the card number is 16-bit. Larger values are truncated.");
32 PrintAndLog("Currently work only on 26bit");
34 PrintAndLog("Usage: lf guard sim <Card-Number>");
35 PrintAndLog("Options :");
36 PrintAndLog(" <Facility-Code> : 8-bit value facility code");
37 PrintAndLog(" <Card Number> : 16-bit value card number");
39 PrintAndLog("Sample : lf guard sim 123 11223");
45 int GetGuardBits(uint32_t fc
, uint32_t cn
, uint8_t *guardBits
) {
47 // Intializes random number generator
49 srand((unsigned) time(&t
));
52 memset(pre
, 0x00, sizeof(pre
));
65 uint8_t xorKey
= rand() % 0xFF;
66 num_to_bytebits(xorKey
, 8, pre
+index
);
70 // len | hex | bin wiegand pos fc/cn
71 // 26 | 1A | 0001 1010
72 num_to_bytebits(26, 8, pre
+index
);
73 // 36 | 24 | 0010 0100
74 //num_to_bytebits(36, 8, pre+index);
75 // 40 | 28 | 0010 1000
76 //num_to_bytebits(40, 8, pre+index);
84 // Get 26 wiegand from FacilityCode, CardNumber
86 memset(wiegand
, 0x00, sizeof(wiegand
));
87 num_to_bytebits(fc
, 8, wiegand
);
88 num_to_bytebits(cn
, 16, wiegand
+8);
90 // add wiegand parity bits (dest, source, len)
91 wiegand_add_parity(pre
+index
, wiegand
, 24);
93 uint8_t tmp
= 0, i
= 0;
94 for (i
= 2; i
< 12; ++i
) {
96 // tmp = xorKey ^ bytebits_to_byte(pre + (i*8), 8);
99 // num_to_bytebits(tmp, 8, pre + (i*8) );
102 // add spacer bit 0 every 5
108 memcpy(guardBits
, pre
, sizeof(pre
));
110 printf(" | %s\n", sprint_bin(guardBits
, 96) );
114 int CmdGuardRead(const char *Cmd
) {
116 getSamples("30000",false);
117 return CmdG_Prox_II_Demod("");
120 int CmdGuardClone(const char *Cmd
) {
122 char cmdp
= param_getchar(Cmd
, 0);
123 if (strlen(Cmd
) == 0 || cmdp
== 'h' || cmdp
== 'H') return usage_lf_guard_clone();
125 uint32_t facilitycode
=0, cardnumber
=0, fc
= 0, cn
= 0;
128 memset(bs
, 0x00, sizeof(bs
));
130 //GuardProxII - compat mode, ASK/Biphase, data rate 64, 3 data blocks
131 uint32_t blocks
[5] = {T55x7_MODULATION_BIPHASE
| T55x7_BITRATE_RF_64
| 3<<T55x7_MAXBLOCK_SHIFT
, 0, 0, 0, 0};
133 // if (param_getchar(Cmd, 3) == 'Q' || param_getchar(Cmd, 3) == 'q')
134 // blocks[0] = T5555_MODULATION_FSK2 | 50<<T5555_BITRATE_SHIFT | 4<<T5555_MAXBLOCK_SHIFT;
136 if (sscanf(Cmd
, "%u %u", &fc
, &cn
) != 2) return usage_lf_guard_clone();
138 facilitycode
= (fc
& 0x000000FF);
139 cardnumber
= (cn
& 0x0000FFFF);
141 if ( !GetGuardBits(facilitycode
, cardnumber
, bs
)) {
142 PrintAndLog("Error with tag bitstream generation.");
146 blocks
[1] = bytebits_to_byte(bs
,32);
147 blocks
[2] = bytebits_to_byte(bs
+32,32);
148 blocks
[3] = bytebits_to_byte(bs
+64,32);
150 PrintAndLog("Preparing to clone Guardall to T55x7 with Facility Code: %u, Card Number: %u", facilitycode
, cardnumber
);
151 PrintAndLog("Blk | Data ");
152 PrintAndLog("----+------------");
153 for ( i
= 0; i
<4; ++i
)
154 PrintAndLog(" %02d | %08x", i
, blocks
[i
]);
157 // UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}};
159 // for ( i = 0; i<5; ++i ) {
160 // c.arg[0] = blocks[i];
162 // clearCommandBuffer();
164 // if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)){
165 // PrintAndLog("Error occurred, device did not respond during write operation.");
172 int CmdGuardSim(const char *Cmd
) {
174 char cmdp
= param_getchar(Cmd
, 0);
175 if (strlen(Cmd
) == 0 || cmdp
== 'h' || cmdp
== 'H') return usage_lf_guard_sim();
177 uint32_t facilitycode
= 0, cardnumber
= 0, fc
= 0, cn
= 0;
180 size_t size
= sizeof(bs
);
181 memset(bs
, 0x00, size
);
183 // Pyramid uses: ASK Biphase, clk: 32, invert: 0
185 arg1
= (10 << 8) + 8;
188 if (sscanf(Cmd
, "%u %u", &fc
, &cn
) != 2) return usage_lf_guard_sim();
190 facilitycode
= (fc
& 0x000000FF);
191 cardnumber
= (cn
& 0x0000FFFF);
193 if ( !GetGuardBits(facilitycode
, cardnumber
, bs
)) {
194 PrintAndLog("Error with tag bitstream generation.");
198 PrintAndLog("Simulating Guardall - Facility Code: %u, CardNumber: %u", facilitycode
, cardnumber
);
200 UsbCommand c
= {CMD_ASK_SIM_TAG
, {arg1
, arg2
, size
}};
201 memcpy(c
.d
.asBytes
, bs
, size
);
202 clearCommandBuffer();
207 static command_t CommandTable
[] = {
208 {"help", CmdHelp
, 1, "This help"},
209 {"read", CmdGuardRead
, 0, "Attempt to read and extract tag data"},
210 // {"clone", CmdGuardClone, 0, "<Facility-Code> <Card Number> clone Guardall tag"},
211 // {"sim", CmdGuardSim, 0, "<Facility-Code> <Card Number> simulate Guardall tag"},
212 {NULL
, NULL
, 0, NULL
}
215 int CmdLFGuard(const char *Cmd
) {
216 clearCommandBuffer();
217 CmdsParse(CommandTable
, Cmd
);
221 int CmdHelp(const char *Cmd
) {
222 CmdsHelp(CommandTable
);