f5ed4d12 |
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 AWID26 commands |
8 | //----------------------------------------------------------------------------- |
9 | |
10 | #include <stdio.h> |
11 | #include <string.h> |
12 | #include <inttypes.h> |
1b492a97 |
13 | #include <stdbool.h> |
f5ed4d12 |
14 | #include "proxmark3.h" |
15 | #include "ui.h" |
3bc3598e |
16 | //#include "graph.h" |
f5ed4d12 |
17 | #include "cmdmain.h" |
18 | #include "cmdparser.h" |
3bc3598e |
19 | //#include "cmddata.h" |
f5ed4d12 |
20 | #include "cmdlf.h" |
21 | #include "cmdlfawid26.h" |
22 | #include "util.h" |
3bc3598e |
23 | //#include "data.h" |
f5ed4d12 |
24 | |
25 | |
26 | static int CmdHelp(const char *Cmd); |
27 | |
28 | int CmdClone(const char *Cmd) |
29 | { |
30 | char cmdp = param_getchar(Cmd, 0); |
31 | |
32 | if (strlen(Cmd) < 1 || cmdp == 'h' || cmdp == 'H') { |
3bc3598e |
33 | PrintAndLog("Usage: lf awid26 clone <facility> <id>"); |
f5ed4d12 |
34 | PrintAndLog(" [], "); |
35 | PrintAndLog(""); |
3bc3598e |
36 | PrintAndLog(" sample: lf awid26 clone 15 2233"); |
f5ed4d12 |
37 | return 0; |
38 | } |
39 | |
40 | //sscanf(Cmd, "%d %d", &facilitycode, &cardno); |
41 | |
42 | // char block0 = "00107060"; |
43 | // char block1 = "00107060"; |
44 | // char block2 = "00107060"; |
45 | // char block3 = "00107060"; |
46 | |
1b492a97 |
47 | unsigned char buf[10] = {0x00}; |
48 | unsigned char *resp = buf; |
f5ed4d12 |
49 | |
50 | |
1b492a97 |
51 | awid26_hex_to_uid(resp, ""); |
f5ed4d12 |
52 | // PrintAndLog("Writing block %d with data %08X", Block, Data); |
53 | return 0; |
54 | } |
55 | |
3bc3598e |
56 | |
57 | // convert 96 bit AWID FSK data to 8 digit BCD UID |
1b492a97 |
58 | bool awid26_hex_to_uid(unsigned char *response, char *awid26) |
3bc3598e |
59 | { |
0452ec6c |
60 | //uint8_t i, tmp[96], tmp1[7]; |
61 | //uint8_t tmp[96] = {0x00}; |
62 | //int site; |
63 | //int id; |
3bc3598e |
64 | |
0452ec6c |
65 | //if(!hextobinarray(tmp, awid26)) |
1b492a97 |
66 | return false; |
3bc3598e |
67 | |
68 | // // data is in blocks of 4 bits - every 4th bit is parity, except the first |
69 | // // block which is all zeros |
70 | // for(i= 0 ; i < 4 ; ++i) |
71 | // if(tmp[i] != 0x00) |
72 | // return false; |
73 | |
74 | // // discard 1st block |
75 | // memcpy(tmp, tmp + 4, 92); |
76 | |
77 | // // check and strip parity on the rest |
78 | // for(i= 1 ; i < 23 ; ++i) |
1b492a97 |
79 | // if(tmp[(i * 4) - 1] != GetParity(tmp + (i - 1) * 4, ODD, 3)) |
3bc3598e |
80 | // return false; |
81 | // else |
82 | // memcpy((tmp + (i - 1) * 3), tmp + (i - 1) * 4, 3); |
83 | |
84 | // // discard the rest of the header - 1 more 3 bit block |
85 | // memcpy(tmp, tmp + 3, 66); |
86 | |
87 | // // next 8 bits is data length - should be 26: 0x1A |
88 | // binarraytohex(tmp1, tmp, 8); |
89 | // if(strcmp(tmp1, "1A") != 0) |
90 | // return false; |
91 | // memcpy(tmp, tmp +8, 58); |
92 | |
93 | // // standard wiegand parity check - even for 1st 12 bits, odd for 2nd 12 |
1b492a97 |
94 | // if(tmp[0] != GetParity(tmp + 1, EVEN, 12)) |
3bc3598e |
95 | // return false; |
1b492a97 |
96 | // if(tmp[25] != GetParity(tmp + 13, ODD, 12)) |
3bc3598e |
97 | // return false; |
98 | |
99 | // // convert to hex, ignoring parity bits |
100 | // if(!binarraytohex(tmp1, tmp + 1, 24)) |
101 | // return false; |
102 | |
103 | // // convert hex to site/id |
104 | // sscanf(tmp1,"%2X%4X", &site, &id); |
105 | |
106 | // // final output 8 byte BCD |
107 | // sprintf(response,"%03d%05d", site, id); |
108 | |
109 | return true; |
110 | } |
111 | |
112 | // convert null-terminated BCD UID (8 digits) to 96 bit awid26 encoded binary array |
113 | bool bcd_to_awid26_bin(unsigned char *awid26, unsigned char *bcd) |
114 | { |
115 | // char i, p, tmp1[8], tmp2[26]; |
116 | // int tmpint; |
117 | |
118 | // if(strlen(bcd) != 8) |
119 | // return false; |
120 | |
121 | // // convert BCD site code to HEX |
122 | // sscanf(bcd, "%03d", &tmpint); |
123 | // sprintf(tmp2, "%02x", tmpint); |
124 | // memcpy(tmp1, tmp2, 2); |
125 | |
126 | // // convert BCD ID to HEX |
127 | // sscanf(bcd + 3, "%05d", &tmpint);; |
128 | // sprintf(tmp2, "%04x", tmpint); |
129 | |
130 | // // copy with trailing NULL |
131 | // memcpy(tmp1 + 2, tmp2, 5); |
132 | |
133 | // // convert full HEX to binary, leaving room for parity prefix |
134 | // hextobinarray(tmp2 + 1, tmp1); |
135 | |
136 | // wiegand_add_parity(tmp2, tmp2 + 1, 24); |
137 | |
138 | // memset(awid26, '\x0', 96); |
139 | |
140 | // // magic 18 bit awid26 header (we will overwrite the last two bits) |
141 | // hextobinarray(awid26, "011D8"); |
142 | |
143 | // // copy to target leaving space for parity bits |
144 | // for(i= 0, p= 18 ; i < 26 ; ++i, ++p) |
145 | // { |
146 | // // skip target bit if this is a parity location |
147 | // if(!((p + 1) % 4)) |
148 | // p += 1; |
149 | // awid26[p]= tmp2[i]; |
150 | // } |
151 | |
152 | // // add parity bits |
153 | // for(i= 1 ; i < 24 ; ++i) |
1b492a97 |
154 | // awid26[((i + 1) * 4) - 1]= GetParity(&awid26[i * 4], ODD, 3); |
3bc3598e |
155 | |
156 | return false; |
157 | } |
158 | |
f5ed4d12 |
159 | // int CmdReadTrace(const char *Cmd) |
160 | // { |
161 | |
162 | // uint8_t bits[LF_BITSSTREAM_LEN] = {0x00}; |
163 | // uint8_t * bitstream = bits; |
164 | |
165 | // uint8_t si = 5; |
166 | // uint32_t bl0 = PackBits(si, 32, bitstream); |
167 | // uint32_t bl1 = PackBits(si+32, 32, bitstream); |
168 | |
169 | // uint32_t acl = PackBits(si, 8, bitstream); si += 8; |
170 | // uint32_t mfc = PackBits(si, 8, bitstream); si += 8; |
171 | // uint32_t cid = PackBits(si, 5, bitstream); si += 5; |
172 | // uint32_t icr = PackBits(si, 3, bitstream); si += 3; |
173 | // uint32_t year = PackBits(si, 4, bitstream); si += 4; |
174 | // uint32_t quarter = PackBits(si, 2, bitstream); si += 2; |
175 | // uint32_t lotid = PackBits(si, 12, bitstream); si += 12; |
176 | // uint32_t wafer = PackBits(si, 5, bitstream); si += 5; |
177 | // uint32_t dw = PackBits(si, 15, bitstream); |
178 | |
179 | // PrintAndLog(""); |
180 | // PrintAndLog("-- T55xx Trace Information ----------------------------------"); |
181 | // PrintAndLog("-------------------------------------------------------------"); |
182 | // PrintAndLog(" ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", acl, acl); |
183 | // PrintAndLog(" MFC Manufacturer ID (ISO/IEC 7816-6) : 0x%02X (%d)", mfc, mfc); |
184 | // PrintAndLog(" CID : 0x%02X (%d)", cid, cid); |
185 | // PrintAndLog(" ICR IC Revision : %d",icr ); |
186 | |
187 | |
188 | // return 0; |
189 | // } |
190 | |
191 | static command_t CommandTable[] = |
192 | { |
3bc3598e |
193 | {"help", CmdHelp, 1, "This help"}, |
194 | {"clone", CmdClone, 1, "<facility> <id> -- clone AWID26 to t55xx tag"}, |
f5ed4d12 |
195 | {NULL, NULL, 0, NULL} |
196 | }; |
197 | |
198 | int CmdLFAWID26(const char *Cmd) |
199 | { |
200 | CmdsParse(CommandTable, Cmd); |
201 | return 0; |
202 | } |
203 | |
204 | int CmdHelp(const char *Cmd) |
205 | { |
206 | CmdsHelp(CommandTable); |
207 | return 0; |
208 | } |