]> git.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlfcotag.c
CHG: 'lf cotag demod' - now finds FC/CN Thanks to @marshmellow42
[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
28 // COTAG demod should be able to use GraphBuffer,
29 // when data load samples
30 int CmdCOTAGDemod(const char *Cmd) {
31
32 uint8_t bits[COTAG_BITS] = {0};
33 size_t bitlen = COTAG_BITS;
34 memcpy(bits, DemodBuffer, COTAG_BITS);
35
36 int err = manrawdecode(bits, &bitlen, 1);
37 if (err){
38 if (g_debugMode) PrintAndLog("DEBUG: Error - COTAG too many errors: %d", err);
39 return -1;
40 }
41
42 setDemodBuf(bits, bitlen, 0);
43
44 //got a good demod
45 uint16_t cn = bytebits_to_byteLSBF(bits+1, 16);
46 uint32_t fc = bytebits_to_byteLSBF(bits+1+16, 8);
47
48 /*
49 fc 161: 1010 0001 -> LSB 1000 0101
50 cn 33593 1000 0011 0011 1001 -> LSB 1001 1100 1100 0001
51 cccc cccc cccc cccc ffffffff
52 0 1001 1100 1100 0001 1000 0101 0000 0000 100001010000000001111011100000011010000010000000000000000000000000000000000000000000000000000000100111001100000110000101000
53 1001 1100 1100 0001 10000101
54 */
55 //PrintAndLog("COTAG Found: FC %u, CN: %u Raw: %08X%08X%08X", fc, cn); //, raw1 ,raw2, raw3);
56 PrintAndLog("COTAG Found: FC %u, CN: %u", fc, cn);
57 return 1;
58 }
59
60 // When reading a COTAG.
61 // 0 = HIGH/LOW signal - maxlength bigbuff
62 // 1 = translation for HI/LO into bytes with manchester 0,1 - length 300
63 // 2 = raw signal - maxlength bigbuff
64 int CmdCOTAGRead(const char *Cmd) {
65
66 if (Cmd[0] == 'h' || Cmd[0] == 'H') return usage_lf_cotag_read();
67
68 uint32_t rawsignal = 1;
69 sscanf(Cmd, "%u", &rawsignal);
70
71 UsbCommand c = {CMD_COTAG, {rawsignal, 0, 0}};
72 clearCommandBuffer();
73 SendCommand(&c);
74 if ( !WaitForResponseTimeout(CMD_ACK, NULL, 7000) ) {
75 PrintAndLog("command execution time out");
76 return -1;
77 }
78
79 switch ( rawsignal ){
80 case 0:
81 case 2: {
82 CmdPlot("");
83 CmdGrid("384");
84 getSamples("", true); break;
85 }
86 case 1: {
87 GetFromBigBuf(DemodBuffer, COTAG_BITS, 0);
88 DemodBufferLen = COTAG_BITS;
89 UsbCommand response;
90 if ( !WaitForResponseTimeout(CMD_ACK, &response, 1000) ) {
91 PrintAndLog("timeout while waiting for reply.");
92 return -1;
93 }
94 return CmdCOTAGDemod("");
95 }
96 }
97 return 0;
98 }
99
100 static command_t CommandTable[] = {
101 {"help", CmdHelp, 1, "This help"},
102 {"demod", CmdCOTAGDemod, 1, "Tries to decode a COTAG signal"},
103 {"read", CmdCOTAGRead, 0, "Attempt to read and extract tag data"},
104 {NULL, NULL, 0, NULL}
105 };
106
107 int CmdLFCOTAG(const char *Cmd) {
108 clearCommandBuffer();
109 CmdsParse(CommandTable, Cmd);
110 return 0;
111 }
112
113 int CmdHelp(const char *Cmd) {
114 CmdsHelp(CommandTable);
115 return 0;
116 }
Impressum, Datenschutz