]>
git.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlfcotag.c
3c1c3caa0553c64322b71c66c9fad2d4f6edb728
1 //-----------------------------------------------------------------------------
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
7 //-----------------------------------------------------------------------------
8 // Low frequency COTAG commands
9 //-----------------------------------------------------------------------------
10 #include "cmdlfcotag.h" // COTAG function declarations
12 static int CmdHelp(const char *Cmd
);
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");
22 PrintAndLog("Sample:");
23 PrintAndLog(" lf cotag read 0");
24 PrintAndLog(" lf cotag read 1");
28 // COTAG demod should be able to use GraphBuffer,
29 // when data load samples
30 int CmdCOTAGDemod(const char *Cmd
) {
32 uint8_t bits
[COTAG_BITS
] = {0};
33 size_t bitlen
= COTAG_BITS
;
34 memcpy(bits
, DemodBuffer
, COTAG_BITS
);
36 int err
= manrawdecode(bits
, &bitlen
, 1);
38 if (g_debugMode
) PrintAndLog("DEBUG: Error - COTAG too many errors: %d", err
);
42 setDemodBuf(bits
, bitlen
, 0);
45 uint16_t cn
= bytebits_to_byteLSBF(bits
+1, 16);
46 uint32_t fc
= bytebits_to_byteLSBF(bits
+1+16, 8);
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
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
);
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
) {
66 if (Cmd
[0] == 'h' || Cmd
[0] == 'H') return usage_lf_cotag_read();
68 uint32_t rawsignal
= 1;
69 sscanf(Cmd
, "%u", &rawsignal
);
71 UsbCommand c
= {CMD_COTAG
, {rawsignal
, 0, 0}};
74 if ( !WaitForResponseTimeout(CMD_ACK
, NULL
, 7000) ) {
75 PrintAndLog("command execution time out");
84 getSamples("", true); break;
87 GetFromBigBuf(DemodBuffer
, COTAG_BITS
, 0);
88 DemodBufferLen
= COTAG_BITS
;
90 if ( !WaitForResponseTimeout(CMD_ACK
, &response
, 1000) ) {
91 PrintAndLog("timeout while waiting for reply.");
94 return CmdCOTAGDemod("");
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
}
107 int CmdLFCOTAG(const char *Cmd
) {
108 clearCommandBuffer();
109 CmdsParse(CommandTable
, Cmd
);
113 int CmdHelp(const char *Cmd
) {
114 CmdsHelp(CommandTable
);