]> cvs.zerfleddert.de Git - proxmark3-svn/blame - client/cmdlfhid.c
USB CDC patch by jonor to enable working under kernel 2.6.27
[proxmark3-svn] / client / cmdlfhid.c
CommitLineData
a553f267 1//-----------------------------------------------------------------------------
2// Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
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 HID commands
9//-----------------------------------------------------------------------------
10
7fe9b0b7 11#include <stdio.h>
54a942b0 12#include <string.h>
28fdb04f 13//#include "proxusb.h"
902cb3c0 14#include "proxmark3.h"
7fe9b0b7 15#include "ui.h"
16#include "graph.h"
17#include "cmdparser.h"
18#include "cmdlfhid.h"
19
20static int CmdHelp(const char *Cmd);
21
22int CmdHIDDemod(const char *Cmd)
23{
24 if (GraphTraceLen < 4800) {
25 PrintAndLog("too short; need at least 4800 samples");
26 return 0;
27 }
28
29 GraphTraceLen = 4800;
30 for (int i = 0; i < GraphTraceLen; ++i) {
31 if (GraphBuffer[i] < 0) {
32 GraphBuffer[i] = 0;
33 } else {
34 GraphBuffer[i] = 1;
35 }
36 }
37 RepaintGraphWindow();
38 return 0;
39}
40
41int CmdHIDDemodFSK(const char *Cmd)
42{
43 UsbCommand c={CMD_HID_DEMOD_FSK};
44 SendCommand(&c);
45 return 0;
46}
47
48int CmdHIDSim(const char *Cmd)
38b20f75 49{
50 unsigned int hi = 0, lo = 0;
51 int n = 0, i = 0;
52
53 while (sscanf(&Cmd[i++], "%1x", &n ) == 1) {
54 hi = (hi << 4) | (lo >> 28);
55 lo = (lo << 4) | (n & 0xf);
56 }
57
58 PrintAndLog("Emulating tag with ID %x%16x", hi, lo);
59
60 UsbCommand c = {CMD_HID_SIM_TAG, {hi, lo, 0}};
61 SendCommand(&c);
62 return 0;
63}
64
65int CmdHIDClone(const char *Cmd)
7fe9b0b7 66{
54a942b0 67 unsigned int hi2 = 0, hi = 0, lo = 0;
035303ac 68 int n = 0, i = 0;
54a942b0 69 UsbCommand c;
7fe9b0b7 70
54a942b0 71 if (strchr(Cmd,'l') != 0) {
38b20f75 72 while (sscanf(&Cmd[i++], "%1x", &n ) == 1) {
54a942b0 73 hi2 = (hi2 << 4) | (hi >> 28);
74 hi = (hi << 4) | (lo >> 28);
75 lo = (lo << 4) | (n & 0xf);
76 }
38b20f75 77
54a942b0 78 PrintAndLog("Cloning tag with long ID %x%08x%08x", hi2, hi, lo);
38b20f75 79
54a942b0 80 c.d.asBytes[0] = 1;
38b20f75 81 }
82 else {
83 while (sscanf(&Cmd[i++], "%1x", &n ) == 1) {
54a942b0 84 hi = (hi << 4) | (lo >> 28);
85 lo = (lo << 4) | (n & 0xf);
86 }
38b20f75 87
54a942b0 88 PrintAndLog("Cloning tag with ID %x%08x", hi, lo);
38b20f75 89
54a942b0 90 hi2 = 0;
91 c.d.asBytes[0] = 0;
7fe9b0b7 92 }
38b20f75 93
94 c.cmd = CMD_HID_CLONE_TAG;
d16d20b1 95 c.arg[0] = hi2;
96 c.arg[1] = hi;
97 c.arg[2] = lo;
ec09b62d 98
ec09b62d 99 SendCommand(&c);
100 return 0;
101}
102
7fe9b0b7 103static command_t CommandTable[] =
104{
105 {"help", CmdHelp, 1, "This help"},
106 {"demod", CmdHIDDemod, 1, "Demodulate HID Prox Card II (not optimal)"},
54a942b0 107 {"fskdemod", CmdHIDDemodFSK, 1, "Realtime HID FSK demodulator"},
108 {"sim", CmdHIDSim, 1, "<ID> -- HID tag simulator"},
109 {"clone", CmdHIDClone, 1, "<ID> ['l'] -- Clone HID to T55x7 (tag must be in antenna)(option 'l' for 84bit ID)"},
7fe9b0b7 110 {NULL, NULL, 0, NULL}
111};
112
113int CmdLFHID(const char *Cmd)
114{
115 CmdsParse(CommandTable, Cmd);
116 return 0;
117}
118
119int CmdHelp(const char *Cmd)
120{
121 CmdsHelp(CommandTable);
122 return 0;
123}
Impressum, Datenschutz