]> git.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlfpyramid.c
ADD: added some pyramid commands. //not finished.
[proxmark3-svn] / client / cmdlfpyramid.c
1 //-----------------------------------------------------------------------------
2 //
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
5 // the license.
6 //-----------------------------------------------------------------------------
7 // Low frequency Farpoint / Pyramid tag commands
8 //-----------------------------------------------------------------------------
9 #include <string.h>
10 #include <inttypes.h>
11 #include "cmdlfpyramid.h"
12 static int CmdHelp(const char *Cmd);
13
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.");
17 PrintAndLog("");
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");
22 PrintAndLog("");
23 PrintAndLog("Sample : lf pyramid clone 123 11223");
24 return 0;
25 }
26
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.");
31 PrintAndLog("");
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");
36 PrintAndLog("");
37 PrintAndLog("Sample : lf pyramid sim 123 11223");
38 return 0;
39 }
40
41 // calc checksum
42 int GetWiegandFromPyramid(const char *id, uint32_t *fc, uint32_t *cn) {
43 return 0;
44 }
45
46 int GetPyramidBits(uint32_t fc, uint32_t cn, uint8_t *pyramidBits) {
47
48 uint8_t pre[128];
49 memset(pre, 0x00, sizeof(pre));
50
51 // add preamble
52 pyramidBits[7]=1;
53 num_to_bytebits(26, 8, pre);
54
55 // get wiegand
56 uint8_t wiegand[24];
57 num_to_bytebits(fc, 8, wiegand);
58 num_to_bytebits(cn, 16, wiegand+8);
59
60 // add wiegand parity bits
61 wiegand_add_parity(pre+8, wiegand, 24);
62
63 // add paritybits
64 addParity(pre, pyramidBits+8, 66, 4, 1);
65
66 // add checksum
67 // this is wrong.
68 uint32_t crc = CRC8Maxim(wiegand, 13);
69 num_to_bytebits(crc, 8, pre+120);
70
71 return 1;
72 }
73
74 int CmdPyramidRead(const char *Cmd) {
75 // read lf silently
76 CmdLFRead("s");
77 // get samples silently
78 getSamples("30000",false);
79 // demod and output Pyramid ID
80 return CmdFSKdemodPyramid("");
81 }
82
83 int CmdPyramidClone(const char *Cmd) {
84
85 char cmdp = param_getchar(Cmd, 0);
86 if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_pyramid_clone();
87
88 uint32_t facilitycode=0, cardnumber=0;
89 uint8_t bits[128];
90 uint8_t *bs = bits;
91 memset(bs,0,sizeof(bits));
92 //Pyramid - compat mode, FSK2a, data rate 50, 4 data blocks
93 uint32_t blocks[5] = {T55x7_MODULATION_FSK2a | T55x7_BITRATE_RF_50 | 4<<T55x7_MAXBLOCK_SHIFT, 0, 0, 0, 0};
94
95 // if (param_getchar(Cmd, 3) == 'Q' || param_getchar(Cmd, 3) == 'q')
96 // blocks[0] = T5555_MODULATION_FSK2 | 50<<T5555_BITRATE_SHIFT | 4<<T5555_MAXBLOCK_SHIFT;
97
98 // get wiegand from printed number.
99 GetWiegandFromPyramid(Cmd, &facilitycode, &cardnumber);
100
101 if ((facilitycode & 0xFF) != facilitycode) {
102 facilitycode &= 0xFF;
103 PrintAndLog("Facility Code Truncated to 8-bits (Pyramid): %u", facilitycode);
104 }
105
106 if ((cardnumber & 0xFFFF) != cardnumber) {
107 cardnumber &= 0xFFFF;
108 PrintAndLog("Card Number Truncated to 16-bits (Pyramid): %u", cardnumber);
109 }
110
111 if ( !GetPyramidBits(facilitycode, cardnumber, bs)) {
112 PrintAndLog("Error with tag bitstream generation.");
113 return 1;
114 }
115
116 blocks[1] = bytebits_to_byte(bs,32);
117 blocks[2] = bytebits_to_byte(bs+32,32);
118 blocks[3] = bytebits_to_byte(bs+64,32);
119 blocks[4] = bytebits_to_byte(bs+96,32);
120
121 PrintAndLog("Preparing to clone Farepointe/Pyramid to T55x7 with Facility Code: %u, Card Number: %u", facilitycode, cardnumber);
122 PrintAndLog("Blk | Data ");
123 PrintAndLog("----+------------");
124 for ( uint8_t i=0; i<5; ++i )
125 PrintAndLog(" %02d | 0x%08x",i , blocks[i]);
126
127 UsbCommand resp;
128 //UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}};
129
130 for ( uint8_t i=0; i<5; ++i ) {
131 //c.arg[0] = blocks[i];
132 //c.arg[1] = i;
133 clearCommandBuffer();
134 // SendCommand(&c);
135 if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)){
136 PrintAndLog("Error occurred, device did not respond during write operation.");
137 return -1;
138 }
139 }
140 return 0;
141 }
142
143 int CmdPyramidSim(const char *Cmd) {
144 // uint32_t id = 0;
145 // uint64_t rawID = 0;
146 // uint8_t clk = 50, encoding = 1, separator = 0, invert = 0;
147
148 char cmdp = param_getchar(Cmd, 0);
149 if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_pyramid_sim();
150
151 // id = param_get32ex(Cmd, 0, 0, 16);
152 // if (id == 0) return usage_lf_pyramid_sim();
153
154 //rawID = getPyramidBits(id);
155
156 // uint16_t arg1, arg2;
157 // size_t size = 64;
158 // arg1 = clk << 8 | encoding;
159 // arg2 = invert << 8 | separator;
160
161 // PrintAndLog("Simulating - ID: %08X, Raw: %08X%08X",id,(uint32_t)(rawID >> 32),(uint32_t) (rawID & 0xFFFFFFFF));
162
163 // UsbCommand c = {CMD_FSK_SIM_TAG, {arg1, arg2, size}};
164 // num_to_bytebits(rawID, size, c.d.asBytes);
165 // clearCommandBuffer();
166 // SendCommand(&c);
167 return 0;
168 }
169
170 static command_t CommandTable[] = {
171 {"help", CmdHelp, 1, "This help"},
172 {"read", CmdPyramidRead, 0, "Attempt to read and extract tag data"},
173 {"clone", CmdPyramidClone, 0, "<Facility-Code> <Card Number> clone pyramid tag"},
174 {"sim", CmdPyramidSim, 0, "<Facility-Code> <Card Number> simulate pyramid tag"},
175 {NULL, NULL, 0, NULL}
176 };
177
178 int CmdLFPyramid(const char *Cmd) {
179 clearCommandBuffer();
180 CmdsParse(CommandTable, Cmd);
181 return 0;
182 }
183
184 int CmdHelp(const char *Cmd) {
185 CmdsHelp(CommandTable);
186 return 0;
187 }
Impressum, Datenschutz