]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlfpyramid.c
c1c237299f8f98b256e84c72a92283a1ab135af1
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 "cmdlfpyramid.h"
12 static int CmdHelp(const char *Cmd
);
14 int usage_lf_pyramid_clone(void){
15 PrintAndLog("clone a Farepointe/Pyramid tag to a T55x7 tag.");
16 PrintAndLog("Per pyramid format, the facility-code is 8-bit and the card number is 16-bit. Larger values are truncated.");
18 PrintAndLog("Usage: lf pyramid clone <Facility-Code> <Card-Number>");
19 PrintAndLog("Options :");
20 PrintAndLog(" <Facility-Code> : 8-bit value facility code");
21 PrintAndLog(" <Card Number> : 16-bit value card number");
23 PrintAndLog("Sample : lf pyramid clone 123 11223");
27 int usage_lf_pyramid_sim(void) {
28 PrintAndLog("Enables simulation of Farepointe/Pyramid card with specified card number.");
29 PrintAndLog("Simulation runs until the button is pressed or another USB command is issued.");
30 PrintAndLog("Per pyramid format, the facility-code is 8-bit and the card number is 16-bit. Larger values are truncated.");
32 PrintAndLog("Usage: lf pyramid sim <Card-Number>");
33 PrintAndLog("Options :");
34 PrintAndLog(" <Facility-Code> : 8-bit value facility code");
35 PrintAndLog(" <Card Number> : 16-bit value card number");
37 PrintAndLog("Sample : lf pyramid sim 123 11223");
42 int GetWiegandFromPyramid(const char *id
, uint32_t *fc
, uint32_t *cn
) {
46 int GetPyramidBits(uint32_t fc
, uint32_t cn
, uint8_t *pyramidBits
) {
49 memset(pre
, 0x00, sizeof(pre
));
53 // Get 26 wiegand from FacilityCode, CardNumber
55 num_to_bytebits(fc
, 8, wiegand
);
56 num_to_bytebits(cn
, 16, wiegand
+8);
58 // add wiegand parity bits (dest, source, len)
59 wiegand_add_parity(pre
+71, wiegand
, 26);
61 // add paritybits (bitsource, dest, sourcelen, paritylen, parityType (odd, even,)
62 addParity(pre
+8, pyramidBits
+8, 112, 8, 1);
66 for (uint8_t i
= 0; i
< 13; i
++)
67 csBuff
[i
] = bytebits_to_byte(pyramidBits
+ 16 + (i
*8), 8);
69 uint32_t crc
= CRC8Maxim(csBuff
, 13);
70 num_to_bytebits(crc
, 8, pyramidBits
+120);
75 33278 - 1000000111111110
77 000101010101010101010101082602
80 int CmdPyramidRead(const char *Cmd
) {
83 // get samples silently
84 getSamples("30000",false);
85 // demod and output Pyramid ID
86 return CmdFSKdemodPyramid("");
89 int CmdPyramidClone(const char *Cmd
) {
91 char cmdp
= param_getchar(Cmd
, 0);
92 if (strlen(Cmd
) == 0 || cmdp
== 'h' || cmdp
== 'H') return usage_lf_pyramid_clone();
94 uint32_t facilitycode
=0, cardnumber
=0, fc
= 0, cn
= 0;
98 memset(bs
, 0x00, sizeof(bits
));
100 //Pyramid - compat mode, FSK2a, data rate 50, 4 data blocks
101 uint32_t blocks
[5] = {T55x7_MODULATION_FSK2a
| T55x7_BITRATE_RF_50
| 4<<T55x7_MAXBLOCK_SHIFT
, 0, 0, 0, 0};
103 // if (param_getchar(Cmd, 3) == 'Q' || param_getchar(Cmd, 3) == 'q')
104 // blocks[0] = T5555_MODULATION_FSK2 | 50<<T5555_BITRATE_SHIFT | 4<<T5555_MAXBLOCK_SHIFT;
106 if (sscanf(Cmd
, "%u %u", &fc
, &cn
) != 2) return usage_lf_pyramid_clone();
108 facilitycode
= (fc
& 0x000000FF);
109 cardnumber
= (cn
& 0x0000FFFF);
111 // get wiegand from printed number.
112 //GetWiegandFromPyramid(Cmd, &facilitycode, &cardnumber);
114 if ( !GetPyramidBits(facilitycode
, cardnumber
, bs
)) {
115 PrintAndLog("Error with tag bitstream generation.");
119 blocks
[1] = bytebits_to_byte(bs
,32);
120 blocks
[2] = bytebits_to_byte(bs
+32,32);
121 blocks
[3] = bytebits_to_byte(bs
+64,32);
122 blocks
[4] = bytebits_to_byte(bs
+96,32);
124 PrintAndLog("Preparing to clone Farepointe/Pyramid to T55x7 with Facility Code: %u, Card Number: %u", facilitycode
, cardnumber
);
125 PrintAndLog("Blk | Data ");
126 PrintAndLog("----+------------");
127 for ( uint8_t i
=0; i
<5; ++i
)
128 PrintAndLog(" %d | %08x",i
, blocks
[i
]);
131 UsbCommand c
= {CMD_T55XX_WRITE_BLOCK
, {0,0,0}};
133 for ( uint8_t i
=0; i
<5; ++i
) {
134 c
.arg
[0] = blocks
[i
];
136 clearCommandBuffer();
138 if (!WaitForResponseTimeout(CMD_ACK
, &resp
, 1000)){
139 PrintAndLog("Error occurred, device did not respond during write operation.");
146 int CmdPyramidSim(const char *Cmd
) {
148 // uint64_t rawID = 0;
149 // uint8_t clk = 50, encoding = 1, separator = 0, invert = 0;
151 char cmdp
= param_getchar(Cmd
, 0);
152 if (strlen(Cmd
) == 0 || cmdp
== 'h' || cmdp
== 'H') return usage_lf_pyramid_sim();
154 // id = param_get32ex(Cmd, 0, 0, 16);
155 // if (id == 0) return usage_lf_pyramid_sim();
157 //rawID = getPyramidBits(id);
159 // uint16_t arg1, arg2;
161 // arg1 = clk << 8 | encoding;
162 // arg2 = invert << 8 | separator;
164 // PrintAndLog("Simulating - ID: %08X, Raw: %08X%08X",id,(uint32_t)(rawID >> 32),(uint32_t) (rawID & 0xFFFFFFFF));
166 // UsbCommand c = {CMD_FSK_SIM_TAG, {arg1, arg2, size}};
167 // num_to_bytebits(rawID, size, c.d.asBytes);
168 // clearCommandBuffer();
173 static command_t CommandTable
[] = {
174 {"help", CmdHelp
, 1, "This help"},
175 {"read", CmdPyramidRead
, 0, "Attempt to read and extract tag data"},
176 {"clone", CmdPyramidClone
, 0, "<Facility-Code> <Card Number> clone pyramid tag"},
177 {"sim", CmdPyramidSim
, 0, "<Facility-Code> <Card Number> simulate pyramid tag"},
178 {NULL
, NULL
, 0, NULL
}
181 int CmdLFPyramid(const char *Cmd
) {
182 clearCommandBuffer();
183 CmdsParse(CommandTable
, Cmd
);
187 int CmdHelp(const char *Cmd
) {
188 CmdsHelp(CommandTable
);