12 static int CmdHelp(const char *Cmd
);
14 static uint16_t Iso15693Crc(uint8_t *v
, int n
)
20 for (i
= 0; i
< n
; i
++) {
21 reg
= reg
^ ((uint32_t)v
[i
]);
22 for (j
= 0; j
< 8; j
++) {
24 reg
= (reg
>> 1) ^ 0x8408;
31 return (uint16_t)~reg
;
34 int CmdHF15Demod(const char *Cmd
)
36 // The sampling rate is 106.353 ksps/s, for T = 18.8 us
39 // 1) Unmodulated time of 56.64us
40 // 2) 24 pulses of 423.75khz
41 // 3) logic '1' (unmodulated for 18.88us followed by 8 pulses of 423.75khz)
43 static const int FrameSOF
[] = {
44 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
45 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
46 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
47 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
53 static const int Logic0
[] = {
59 static const int Logic1
[] = {
67 // 1) logic '0' (8 pulses of 423.75khz followed by unmodulated for 18.88us)
68 // 2) 24 pulses of 423.75khz
69 // 3) Unmodulated time of 56.64us
71 static const int FrameEOF
[] = {
76 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
77 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
78 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
79 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
87 if (GraphTraceLen
< 1000) return 0;
89 // First, correlate for SOF
90 for (i
= 0; i
< 100; i
++) {
92 for (j
= 0; j
< arraylen(FrameSOF
); j
+= skip
) {
93 corr
+= FrameSOF
[j
] * GraphBuffer
[i
+ (j
/ skip
)];
100 PrintAndLog("SOF at %d, correlation %d", maxPos
,
101 max
/ (arraylen(FrameSOF
) / skip
));
103 i
= maxPos
+ arraylen(FrameSOF
) / skip
;
106 memset(outBuf
, 0, sizeof(outBuf
));
109 int corr0
= 0, corr1
= 0, corrEOF
= 0;
110 for (j
= 0; j
< arraylen(Logic0
); j
+= skip
) {
111 corr0
+= Logic0
[j
] * GraphBuffer
[i
+ (j
/ skip
)];
113 for (j
= 0; j
< arraylen(Logic1
); j
+= skip
) {
114 corr1
+= Logic1
[j
] * GraphBuffer
[i
+ (j
/ skip
)];
116 for (j
= 0; j
< arraylen(FrameEOF
); j
+= skip
) {
117 corrEOF
+= FrameEOF
[j
] * GraphBuffer
[i
+ (j
/ skip
)];
119 // Even things out by the length of the target waveform.
123 if (corrEOF
> corr1
&& corrEOF
> corr0
) {
124 PrintAndLog("EOF at %d", i
);
126 } else if (corr1
> corr0
) {
127 i
+= arraylen(Logic1
) / skip
;
130 i
+= arraylen(Logic0
) / skip
;
137 if ((i
+ (int)arraylen(FrameEOF
)) >= GraphTraceLen
) {
138 PrintAndLog("ran off end!");
143 PrintAndLog("error, uneven octet! (discard extra bits!)");
144 PrintAndLog(" mask=%02x", mask
);
146 PrintAndLog("%d octets", k
);
148 for (i
= 0; i
< k
; i
++) {
149 PrintAndLog("# %2d: %02x ", i
, outBuf
[i
]);
151 PrintAndLog("CRC=%04x", Iso15693Crc(outBuf
, k
- 2));
155 int CmdHF15Read(const char *Cmd
)
157 UsbCommand c
= {CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_15693
};
162 int CmdHF15Reader(const char *Cmd
)
164 UsbCommand c
= {CMD_READER_ISO_15693
, {strtol(Cmd
, NULL
, 0), 0, 0}};
169 int CmdHF15Sim(const char *Cmd
)
171 UsbCommand c
= {CMD_SIMTAG_ISO_15693
, {strtol(Cmd
, NULL
, 0), 0, 0}};
176 static command_t CommandTable
[] =
178 {"help", CmdHelp
, 1, "This help"},
179 {"demod", CmdHF15Demod
, 1, "Demodulate ISO15693 from tag"},
180 {"read", CmdHF15Read
, 0, "Read HF tag (ISO 15693)"},
181 {"reader", CmdHF15Reader
, 0, "Act like an ISO15693 reader"},
182 {"sim", CmdHF15Sim
, 0, "Fake an ISO15693 tag"},
183 {NULL
, NULL
, 0, NULL
}
186 int CmdHF15(const char *Cmd
)
188 CmdsParse(CommandTable
, Cmd
);
192 int CmdHelp(const char *Cmd
)
194 CmdsHelp(CommandTable
);