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