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