]> cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlfcotag.c
CHG: minor fixes in setting arrays and error messages.
[proxmark3-svn] / client / cmdlfcotag.c
1 //-----------------------------------------------------------------------------
2 // Authored by Iceman
3 //
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
6 // the license.
7 //-----------------------------------------------------------------------------
8 // Low frequency COTAG commands
9 //-----------------------------------------------------------------------------
10 #include "cmdlfcotag.h" // COTAG function declarations
11
12 static int CmdHelp(const char *Cmd);
13
14 int usage_lf_cotag_read(void){
15 PrintAndLog("Usage: lf COTAG read [h] <signaldata>");
16 PrintAndLog("Options:");
17 PrintAndLog(" h : This help");
18 PrintAndLog(" <0|1|2> : 0 - HIGH/LOW signal; maxlength bigbuff");
19 PrintAndLog(" : 1 - translation of HI/LO into bytes with manchester 0,1");
20 PrintAndLog(" : 2 - raw signal; maxlength bigbuff");
21 PrintAndLog("");
22 PrintAndLog("Sample:");
23 PrintAndLog(" lf cotag read 0");
24 PrintAndLog(" lf cotag read 1");
25 return 0;
26 }
27 int CmdCOTAGDemod(const char *Cmd) {
28 return 0;
29 }
30
31 // When reading a COTAG.
32 // 0 = HIGH/LOW signal - maxlength bigbuff
33 // 1 = translation for HI/LO into bytes with manchester 0,1 - length 300
34 // 2 = raw signal - maxlength bigbuff
35 int CmdCOTAGRead(const char *Cmd) {
36
37 if (Cmd[0] == 'h' || Cmd[0] == 'H') return usage_lf_cotag_read();
38
39 uint8_t bits[320] = {0};
40 uint32_t rawsignal = 0;
41 sscanf(Cmd, "%u", &rawsignal);
42
43 UsbCommand c = {CMD_COTAG, {rawsignal, 0, 0}};
44 clearCommandBuffer();
45 SendCommand(&c);
46 if ( !WaitForResponseTimeout(CMD_ACK, NULL, 7000) ) {
47 PrintAndLog("command execution time out");
48 return 1;
49 }
50
51 switch ( rawsignal ){
52 case 0:
53 case 2: {
54 CmdPlot("");
55 CmdGrid("384");
56 getSamples("", true); break;
57 }
58 case 1: {
59 GetFromBigBuf(bits, sizeof(bits), 0);
60 UsbCommand response;
61 if ( !WaitForResponseTimeout(CMD_ACK, &response, 500) ) {
62 if (g_debugMode) PrintAndLog("timeout while waiting for reply.");
63 return 1;
64 }
65
66 size_t size = sizeof(bits);
67 int err = manrawdecode(bits, &size, 1);
68 if (err){
69 if (g_debugMode) PrintAndLog("DEBUG: Error - COTAG too many errors: %d", err);
70 return 0;
71 }
72 PrintAndLog("%s", sprint_bin(bits, size));
73 setDemodBuf(bits, size, 0);
74
75 // CmdCOTAGDemod();
76 break;
77 }
78 }
79 return 0;
80 }
81
82 static command_t CommandTable[] = {
83 {"help", CmdHelp, 1, "This help"},
84 {"demod", CmdCOTAGDemod, 1, "Tries to decode a COTAG signal"},
85 {"read", CmdCOTAGRead, 0, "Attempt to read and extract tag data"},
86 {NULL, NULL, 0, NULL}
87 };
88
89 int CmdLFCOTAG(const char *Cmd) {
90 clearCommandBuffer();
91 CmdsParse(CommandTable, Cmd);
92 return 0;
93 }
94
95 int CmdHelp(const char *Cmd) {
96 CmdsHelp(CommandTable);
97 return 0;
98 }
Impressum, Datenschutz