]>
git.zerfleddert.de Git - proxmark3-svn/blob - client/cmdlfcotag.c
f10516a61053c3e7974308cf2b7ac68dba99ad8e
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);
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);
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
60 PrintAndLog("COTAG Found: FC %u, CN: %u Raw: %08X%08X%08X%08X", fc
, cn
, raw1
,raw2
, raw3
, raw4
);
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
68 int CmdCOTAGRead(const char *Cmd
) {
70 if (Cmd
[0] == 'h' || Cmd
[0] == 'H') return usage_lf_cotag_read();
72 uint32_t rawsignal
= 1;
73 sscanf(Cmd
, "%u", &rawsignal
);
75 UsbCommand c
= {CMD_COTAG
, {rawsignal
, 0, 0}};
78 if ( !WaitForResponseTimeout(CMD_ACK
, NULL
, 7000) ) {
79 PrintAndLog("command execution time out");
88 getSamples("", true); break;
91 GetFromBigBuf(DemodBuffer
, COTAG_BITS
, 0);
92 DemodBufferLen
= COTAG_BITS
;
94 if ( !WaitForResponseTimeout(CMD_ACK
, &response
, 1000) ) {
95 PrintAndLog("timeout while waiting for reply.");
98 return CmdCOTAGDemod("");
104 static 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
}
111 int CmdLFCOTAG(const char *Cmd
) {
112 clearCommandBuffer();
113 CmdsParse(CommandTable
, Cmd
);
117 int CmdHelp(const char *Cmd
) {
118 CmdsHelp(CommandTable
);