]>
Commit | Line | Data |
---|---|---|
a553f267 | 1 | //----------------------------------------------------------------------------- |
2 | // Copyright (C) 2010 iZsh <izsh at fail0verflow.com> | |
4f131b53 | 3 | // Merlok - 2017 |
a553f267 | 4 | // |
5 | // This code is licensed to you under the terms of the GNU GPL, version 2 or, | |
6 | // at your option, any later version. See the LICENSE.txt file for the text of | |
7 | // the license. | |
8 | //----------------------------------------------------------------------------- | |
9 | // High frequency commands | |
10 | //----------------------------------------------------------------------------- | |
11 | ||
ad939de5 | 12 | #include "cmdhf.h" |
13 | ||
fc52fbd4 | 14 | #include <math.h> |
0d2624a0 | 15 | #include "usb_cmd.h" |
ad939de5 | 16 | #include "comms.h" |
7fe9b0b7 | 17 | #include "ui.h" |
18 | #include "cmdparser.h" | |
fc52fbd4 | 19 | #include "cliparser/cliparser.h" |
7fe9b0b7 | 20 | #include "cmdhf14a.h" |
21 | #include "cmdhf14b.h" | |
22 | #include "cmdhf15.h" | |
5acd09bd | 23 | #include "cmdhfepa.h" |
7fe9b0b7 | 24 | #include "cmdhflegic.h" |
cee5a30d | 25 | #include "cmdhficlass.h" |
9ca155ba | 26 | #include "cmdhfmf.h" |
dc3e2acf | 27 | #include "cmdhfmfp.h" |
5ee70129 | 28 | #include "cmdhfmfu.h" |
05ddb52c | 29 | #include "cmdhftopaz.h" |
4f131b53 | 30 | #include "cmdhflist.h" |
39cc1c87 | 31 | #include "cmdhffido.h" |
fc52fbd4 | 32 | #include "cmddata.h" |
33 | #include "graph.h" | |
34 | #include "fpga.h" | |
7fe9b0b7 | 35 | |
36 | static int CmdHelp(const char *Cmd); | |
37 | ||
38 | int CmdHFTune(const char *Cmd) | |
39 | { | |
40 | UsbCommand c={CMD_MEASURE_ANTENNA_TUNING_HF}; | |
41 | SendCommand(&c); | |
42 | return 0; | |
43 | } | |
4c3de57a | 44 | |
8ceb6b03 | 45 | int CmdHFSearch(const char *Cmd){ |
46 | int ans = 0; | |
6ce0e538 | 47 | PrintAndLog(""); |
fe842bed | 48 | ans = CmdHF14AInfo("s"); |
6ce0e538 | 49 | if (ans > 0) { |
50 | PrintAndLog("\nValid ISO14443A Tag Found - Quiting Search\n"); | |
51 | return ans; | |
ff4fdb32 | 52 | } |
aa53efc3 | 53 | ans = HFiClassReader("", false, false); |
ff4fdb32 | 54 | if (ans) { |
aa53efc3 | 55 | PrintAndLog("\nValid iClass Tag (or PicoPass Tag) Found - Quiting Search\n"); |
ff4fdb32 | 56 | return ans; |
57 | } | |
979c7655 | 58 | ans = HF15Reader("", false); |
6ce0e538 | 59 | if (ans) { |
979c7655 | 60 | PrintAndLog("\nValid ISO15693 Tag Found - Quiting Search\n"); |
6ce0e538 | 61 | return ans; |
62 | } | |
979c7655 | 63 | //14b is longest test currently (and rarest chip type) ... put last |
64 | ans = HF14BInfo(false); | |
6ce0e538 | 65 | if (ans) { |
979c7655 | 66 | PrintAndLog("\nValid ISO14443B Tag Found - Quiting Search\n"); |
6ce0e538 | 67 | return ans; |
68 | } | |
ff4fdb32 | 69 | PrintAndLog("\nno known/supported 13.56 MHz tags found\n"); |
8ceb6b03 | 70 | return 0; |
71 | } | |
7fe9b0b7 | 72 | |
0472d76d | 73 | int CmdHFSnoop(const char *Cmd) |
74 | { | |
75 | char * pEnd; | |
76 | UsbCommand c = {CMD_HF_SNIFFER, {strtol(Cmd, &pEnd,0),strtol(pEnd, &pEnd,0),0}}; | |
77 | SendCommand(&c); | |
78 | return 0; | |
79 | } | |
80 | ||
fc52fbd4 | 81 | |
82 | // static void InterpolateShannon(int *source, size_t source_len, int *dest, size_t dest_len) | |
83 | // { | |
84 | // int *buf = (int*)malloc(source_len * sizeof(int)); | |
85 | // memcpy(buf, source, source_len * sizeof(int)); | |
86 | // for (int i = 0; i < source_len; i++) { | |
87 | // buf[i] += 128; | |
88 | // } | |
89 | // for (int i = 0; i < dest_len; i++) { | |
90 | // float value = 0.0; | |
91 | // for (int j = 0; j < source_len; j++) { | |
92 | // if (i * source_len == j * dest_len) { // sin(0) / 0 = 1 | |
93 | // value += (float)buf[j]; | |
94 | // } else { | |
95 | // value += (float)buf[j] * sin(((float)i*source_len/dest_len-j)*3.1415) / (((float)i*source_len/dest_len-j)*3.1415); | |
96 | // } | |
97 | // } | |
98 | // dest[i] = value - 128; | |
99 | // } | |
100 | // free(buf); | |
101 | // } | |
102 | ||
103 | ||
104 | static int CmdHFPlot(const char *Cmd) | |
105 | { | |
106 | CLIParserInit("hf plot", | |
107 | "Plots HF signal after RF signal path and A/D conversion.", | |
108 | "This can be used after any hf command and will show the last few milliseconds of the HF signal.\n" | |
109 | "Note: If the last hf command terminated because of a timeout you will most probably see nothing.\n"); | |
110 | void* argtable[] = { | |
111 | arg_param_begin, | |
112 | arg_param_end | |
113 | }; | |
114 | CLIExecWithReturn(Cmd, argtable, true); | |
115 | ||
116 | uint8_t buf[FPGA_TRACE_SIZE]; | |
117 | ||
118 | if (GetFromFpgaRAM(buf, FPGA_TRACE_SIZE)) { | |
119 | for (size_t i = 0; i < FPGA_TRACE_SIZE; i++) { | |
120 | GraphBuffer[i] = (int)buf[i] - 128; | |
121 | } | |
122 | GraphTraceLen = FPGA_TRACE_SIZE; | |
123 | // InterpolateShannon(GraphBuffer, FPGA_TRACE_SIZE, GraphBuffer, FPGA_TRACE_SIZE*8/7); | |
124 | // GraphTraceLen = FPGA_TRACE_SIZE*8/7; | |
125 | ShowGraphWindow(); | |
126 | RepaintGraphWindow(); | |
127 | } | |
128 | return 0; | |
129 | } | |
130 | ||
131 | ||
132 | static command_t CommandTable[] = | |
7fe9b0b7 | 133 | { |
fc52fbd4 | 134 | {"help", CmdHelp, 1, "This help"}, |
135 | {"14a", CmdHF14A, 0, "{ ISO14443A RFIDs... }"}, | |
136 | {"14b", CmdHF14B, 0, "{ ISO14443B RFIDs... }"}, | |
137 | {"15", CmdHF15, 1, "{ ISO15693 RFIDs... }"}, | |
138 | {"epa", CmdHFEPA, 0, "{ German Identification Card... }"}, | |
139 | {"legic", CmdHFLegic, 0, "{ LEGIC RFIDs... }"}, | |
140 | {"iclass", CmdHFiClass, 1, "{ ICLASS RFIDs... }"}, | |
141 | {"mf", CmdHFMF, 1, "{ MIFARE RFIDs... }"}, | |
142 | {"mfu", CmdHFMFUltra, 1, "{ MIFARE Ultralight RFIDs... }"}, | |
143 | {"mfp", CmdHFMFP, 0, "{ MIFARE Plus RFIDs... }"}, | |
144 | {"topaz", CmdHFTopaz, 0, "{ TOPAZ (NFC Type 1) RFIDs... }"}, | |
145 | {"fido", CmdHFFido, 0, "{ FIDO and FIDO2 authenticators... }"}, | |
146 | {"tune", CmdHFTune, 0, "Continuously measure HF antenna tuning"}, | |
147 | {"list", CmdHFList, 1, "List protocol data in trace buffer"}, | |
148 | {"plot", CmdHFPlot, 0, "Plot signal"}, | |
149 | {"search", CmdHFSearch, 0, "Search for known HF tags [preliminary]"}, | |
b2fe0e77 | 150 | {"snoop", CmdHFSnoop, 0, "<samples to skip (10000)> <triggers to skip (1)> Generic HF Snoop"}, |
fc52fbd4 | 151 | {NULL, NULL, 0, NULL} |
7fe9b0b7 | 152 | }; |
153 | ||
154 | int CmdHF(const char *Cmd) | |
155 | { | |
156 | CmdsParse(CommandTable, Cmd); | |
fc52fbd4 | 157 | return 0; |
7fe9b0b7 | 158 | } |
159 | ||
160 | int CmdHelp(const char *Cmd) | |
161 | { | |
162 | CmdsHelp(CommandTable); | |
163 | return 0; | |
164 | } |