]> git.zerfleddert.de Git - proxmark3-svn/blame - client/cmdlfcotag.c
CHG: 'lf cotag demod' - now finds FC/CN Thanks to @marshmellow42
[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
a330987d 11
4653da43 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}
a330987d 27
28// COTAG demod should be able to use GraphBuffer,
29// when data load samples
5f5b83b7 30int CmdCOTAGDemod(const char *Cmd) {
a330987d 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;
5f5b83b7 58}
4653da43 59
5f5b83b7 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
64int CmdCOTAGRead(const char *Cmd) {
65
66 if (Cmd[0] == 'h' || Cmd[0] == 'H') return usage_lf_cotag_read();
67
a330987d 68 uint32_t rawsignal = 1;
5f5b83b7 69 sscanf(Cmd, "%u", &rawsignal);
507afbf3 70
5f5b83b7 71 UsbCommand c = {CMD_COTAG, {rawsignal, 0, 0}};
4653da43 72 clearCommandBuffer();
73 SendCommand(&c);
5f5b83b7 74 if ( !WaitForResponseTimeout(CMD_ACK, NULL, 7000) ) {
bdf387c7 75 PrintAndLog("command execution time out");
a330987d 76 return -1;
b828a4e1 77 }
5f5b83b7 78
79 switch ( rawsignal ){
80 case 0:
81 case 2: {
82 CmdPlot("");
83 CmdGrid("384");
84 getSamples("", true); break;
85 }
86 case 1: {
a330987d 87 GetFromBigBuf(DemodBuffer, COTAG_BITS, 0);
88 DemodBufferLen = COTAG_BITS;
5f5b83b7 89 UsbCommand response;
a330987d 90 if ( !WaitForResponseTimeout(CMD_ACK, &response, 1000) ) {
91 PrintAndLog("timeout while waiting for reply.");
92 return -1;
5f5b83b7 93 }
a330987d 94 return CmdCOTAGDemod("");
5f5b83b7 95 }
96 }
b828a4e1 97 return 0;
4653da43 98}
99
100static command_t CommandTable[] = {
101 {"help", CmdHelp, 1, "This help"},
5f5b83b7 102 {"demod", CmdCOTAGDemod, 1, "Tries to decode a COTAG signal"},
103 {"read", CmdCOTAGRead, 0, "Attempt to read and extract tag data"},
4653da43 104 {NULL, NULL, 0, NULL}
105};
106
107int CmdLFCOTAG(const char *Cmd) {
108 clearCommandBuffer();
109 CmdsParse(CommandTable, Cmd);
110 return 0;
111}
112
113int CmdHelp(const char *Cmd) {
114 CmdsHelp(CommandTable);
115 return 0;
116}
Impressum, Datenschutz