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