]> git.zerfleddert.de Git - proxmark3-svn/blame - client/cmdlfcotag.c
CHG: minor fixes in setting arrays and error messages.
[proxmark3-svn] / client / cmdlfcotag.c
CommitLineData
4653da43 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
12static int CmdHelp(const char *Cmd);
13
5f5b83b7 14int 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}
27int CmdCOTAGDemod(const char *Cmd) {
28 return 0;
29}
4653da43 30
5f5b83b7 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
35int 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);
507afbf3 42
5f5b83b7 43 UsbCommand c = {CMD_COTAG, {rawsignal, 0, 0}};
4653da43 44 clearCommandBuffer();
45 SendCommand(&c);
5f5b83b7 46 if ( !WaitForResponseTimeout(CMD_ACK, NULL, 7000) ) {
bdf387c7 47 PrintAndLog("command execution time out");
5f5b83b7 48 return 1;
b828a4e1 49 }
5f5b83b7 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) ) {
96b516e1 62 if (g_debugMode) PrintAndLog("timeout while waiting for reply.");
63 return 1;
5f5b83b7 64 }
65
66 size_t size = sizeof(bits);
67 int err = manrawdecode(bits, &size, 1);
68 if (err){
96b516e1 69 if (g_debugMode) PrintAndLog("DEBUG: Error - COTAG too many errors: %d", err);
5f5b83b7 70 return 0;
71 }
72 PrintAndLog("%s", sprint_bin(bits, size));
96b516e1 73 setDemodBuf(bits, size, 0);
5f5b83b7 74
75 // CmdCOTAGDemod();
76 break;
77 }
78 }
b828a4e1 79 return 0;
4653da43 80}
81
82static command_t CommandTable[] = {
83 {"help", CmdHelp, 1, "This help"},
5f5b83b7 84 {"demod", CmdCOTAGDemod, 1, "Tries to decode a COTAG signal"},
85 {"read", CmdCOTAGRead, 0, "Attempt to read and extract tag data"},
4653da43 86 {NULL, NULL, 0, NULL}
87};
88
89int CmdLFCOTAG(const char *Cmd) {
90 clearCommandBuffer();
91 CmdsParse(CommandTable, Cmd);
92 return 0;
93}
94
95int CmdHelp(const char *Cmd) {
96 CmdsHelp(CommandTable);
97 return 0;
98}
Impressum, Datenschutz