Files
proxmark3/client/src/cmdhf.c
T

628 lines
23 KiB
C
Raw Permalink Normal View History

//-----------------------------------------------------------------------------
2022-01-07 01:58:03 +01:00
// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
//
2022-01-07 01:58:03 +01:00
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// See LICENSE.txt for the text of the license.
//-----------------------------------------------------------------------------
// High frequency commands
//-----------------------------------------------------------------------------
#include "cmdhf.h"
2019-08-08 16:57:33 +02:00
2020-01-12 16:45:24 +01:00
#include <ctype.h> // tolower
#include "cmdparser.h" // command_t
2020-12-21 02:06:43 +01:00
#include "cliparser.h" // parse
2020-01-12 16:45:24 +01:00
#include "comms.h" // clearCommandBuffer
2020-01-12 17:13:02 +01:00
#include "lfdemod.h" // computeSignalProperties
2019-08-08 16:57:33 +02:00
#include "cmdhf14a.h" // ISO14443-A
#include "cmdhf14b.h" // ISO14443-B
#include "cmdhf15.h" // ISO15693
2024-02-01 10:05:04 +01:00
#include "cmdhfcipurse.h" // CIPURSE transport cards
#include "cmdhfcryptorf.h" // CryptoRF
#include "cmdhfepa.h" // German Identification Card
2020-12-06 03:22:20 +03:00
#include "cmdhfemrtd.h" // eMRTD
2024-02-01 10:05:04 +01:00
#include "cmdhffelica.h" // ISO18092 / FeliCa
#include "cmdhffido.h" // FIDO authenticators
#include "cmdhffudan.h" // Fudan cards
#include "cmdhfgallagher.h" // Gallagher DESFire cards
2019-08-08 16:57:33 +02:00
#include "cmdhficlass.h" // ICLASS
2024-02-01 10:05:04 +01:00
#include "cmdhfict.h" // ICT MFC / DESfire cards
2021-02-11 22:08:51 +01:00
#include "cmdhfjooki.h" // MFU based Jooki
2024-02-01 10:05:04 +01:00
#include "cmdhfksx6924.h" // KS X 6924
#include "cmdhflegic.h" // LEGIC
#include "cmdhflto.h" // LTO-CM
2019-08-08 16:57:33 +02:00
#include "cmdhfmf.h" // CLASSIC
#include "cmdhfmfu.h" // ULTRALIGHT/NTAG etc
#include "cmdhfmfp.h" // Mifare Plus
#include "cmdhfmfdes.h" // DESFIRE
#include "cmdhfntag424.h" // NTAG 424 DNA
2021-05-20 10:07:04 +02:00
#include "cmdhfseos.h" // SEOS
2021-05-30 14:55:58 +02:00
#include "cmdhfst25ta.h" // ST25TA
#include "cmdhftesla.h" // Tesla
#include "cmdhftexkom.h" // Texkom
2024-02-01 10:05:04 +01:00
#include "cmdhfthinfilm.h" // Thinfilm
#include "cmdhftopaz.h" // TOPAZ
#include "cmdhfvas.h" // Value added services
#include "cmdhfwaveshare.h" // Waveshare
#include "cmdhfxerox.h" // Xerox
2019-08-08 16:57:33 +02:00
#include "cmdtrace.h" // trace list
#include "ui.h"
2020-05-03 00:33:28 +02:00
#include "proxgui.h"
2020-01-12 16:45:24 +01:00
#include "cmddata.h"
#include "graph.h"
2020-04-19 13:00:35 +02:00
#include "fpga.h"
static int CmdHelp(const char *Cmd);
int CmdHFSearch(const char *Cmd) {
2020-12-21 02:40:04 +01:00
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf search",
"Will try to find a HF read out of the unknown tag.\n"
"Continues to search for all different HF protocols.",
2020-12-24 10:55:36 +01:00
"hf search"
2020-12-23 19:51:10 +01:00
);
2020-12-21 02:40:04 +01:00
void *argtable[] = {
arg_param_begin,
arg_lit0("v", "verbose", "verbose output"),
2020-12-21 02:40:04 +01:00
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
bool verbose = arg_get_lit(ctx, 1);
2020-12-24 10:55:36 +01:00
CLIParserFree(ctx);
2020-04-16 09:01:14 +02:00
int res = PM3_ESOFT;
2024-01-04 12:49:47 +01:00
uint8_t success[20] = {0};
2019-10-17 21:58:57 +02:00
PROMPT_CLEARLINE;
2020-06-26 23:31:32 +02:00
PrintAndLogEx(INPLACE, " Searching for ThinFilm tag...");
if (IfPm3NfcBarcode()) {
if (infoThinFilm(false) == PM3_SUCCESS) {
PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Thinfilm tag") " found\n");
2024-01-04 12:49:47 +01:00
success[THINFILM] = true;
res = PM3_SUCCESS;
}
}
2019-09-09 13:15:55 +02:00
PROMPT_CLEARLINE;
PrintAndLogEx(INPLACE, " Searching for Topaz tag...");
if (IfPm3Iso14443a()) {
if (readTopazUid(false, false) == PM3_SUCCESS) {
PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Topaz tag") " found\n");
success[TOPAZ] = true;
res = PM3_SUCCESS;
}
}
PROMPT_CLEARLINE;
2020-06-26 23:31:32 +02:00
PrintAndLogEx(INPLACE, " Searching for LTO-CM tag...");
if (IfPm3Iso14443a()) {
if (reader_lto(false, false) == PM3_SUCCESS) {
PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("LTO-CM tag") " found\n");
2024-01-04 12:49:47 +01:00
success[LTO] = true;
res = PM3_SUCCESS;
}
}
2019-10-17 21:58:57 +02:00
PROMPT_CLEARLINE;
2020-06-26 23:31:32 +02:00
PrintAndLogEx(INPLACE, " Searching for ISO14443-A tag...");
if (IfPm3Iso14443a()) {
2021-06-23 14:50:02 +03:00
int sel_state = infoHF14A(false, false, false);
if (sel_state > 0) {
2021-04-16 00:00:02 +02:00
PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("ISO 14443-A tag") " found\n");
2024-01-04 12:49:47 +01:00
success[ISO_14443A] = true;
res = PM3_SUCCESS;
2021-06-17 13:44:14 +03:00
2021-06-23 14:50:02 +03:00
if (sel_state == 1)
infoHF14A4Applications(verbose);
}
2019-03-09 23:35:06 +01:00
}
2019-10-21 13:46:23 +02:00
/*
// ICT
2024-02-01 10:05:04 +01:00
if (IfPm3Iso14443a()) {
2024-02-03 16:05:58 +01:00
int sel_state = infoHF14A(false, false, false);
2024-02-01 10:05:04 +01:00
if (sel_state > 0) {
PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("ISO 14443-A tag") " found\n");
success[ISO_14443A] = true;
res = PM3_SUCCESS;
if (sel_state == 1)
infoHF14A4Applications(verbose);
}
}
*/
2024-02-01 10:05:04 +01:00
2019-10-17 21:58:57 +02:00
PROMPT_CLEARLINE;
2020-06-26 23:31:32 +02:00
PrintAndLogEx(INPLACE, " Searching for LEGIC tag...");
if (IfPm3Legicrf()) {
if (readLegicUid(false, false) == PM3_SUCCESS) {
PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("LEGIC Prime tag") " found\n");
2024-01-04 12:49:47 +01:00
success[LEGIC] = true;
res = PM3_SUCCESS;
}
2019-03-09 23:35:06 +01:00
}
2019-09-09 13:15:55 +02:00
2022-07-08 00:19:26 +03:00
// texkom
2022-07-07 22:45:15 +02:00
PROMPT_CLEARLINE;
PrintAndLogEx(INPLACE, " Searching for TEXKOM tag...");
2022-07-07 22:45:15 +02:00
if (read_texkom_uid(false, false) == PM3_SUCCESS) {
PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("TEXKOM tag") " found\n");
2024-01-04 12:49:47 +01:00
success[PROTO_TEXKOM] = true;
2022-07-07 22:45:15 +02:00
res = PM3_SUCCESS;
}
// xerox
PROMPT_CLEARLINE;
PrintAndLogEx(INPLACE, " Searching for Fuji/Xerox tag...");
if (IfPm3Iso14443b()) {
if (read_xerox_uid(false, false) == PM3_SUCCESS) {
PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("Fuji/Xerox tag") " found\n");
2024-01-04 12:49:47 +01:00
success[PROTO_XEROX] = true;
res = PM3_SUCCESS;
}
}
2019-09-09 13:15:55 +02:00
// 14b is the longest test
PROMPT_CLEARLINE;
PrintAndLogEx(INPLACE, " Searching for ISO14443-B tag...");
if (IfPm3Iso14443b()) {
if (readHF14B(false, false, false) == PM3_SUCCESS) {
PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("ISO 14443-B tag") " found\n");
2024-01-04 12:49:47 +01:00
success[ISO_14443B] = true;
res = PM3_SUCCESS;
}
}
// OBS! This triggers a swap to FPGA_BITSTREAM_HF_15 == 1.5sec delay
PROMPT_CLEARLINE;
PrintAndLogEx(INPLACE, " Searching for ISO15693 tag...");
if (IfPm3Iso15693()) {
2024-02-17 14:20:52 +01:00
if (readHF15Uid(false, true)) {
PrintAndLogEx(SUCCESS, "Valid " _GREEN_("ISO 15693 tag") " found\n");
2024-01-04 12:49:47 +01:00
success[ISO_15693] = true;
res = PM3_SUCCESS;
}
}
PROMPT_CLEARLINE;
PrintAndLogEx(INPLACE, " Searching for iCLASS / PicoPass tag...");
if (IfPm3Iclass()) {
if (read_iclass_csn(false, false, false) == PM3_SUCCESS) {
PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("iCLASS tag / PicoPass tag") " found\n");
2024-01-04 12:49:47 +01:00
success[ICLASS] = true;
res = PM3_SUCCESS;
}
}
// OBS! This triggers a swap to FPGA_BITSTREAM_HF_FELICA == 1.5sec delay
PROMPT_CLEARLINE;
PrintAndLogEx(INPLACE, " Searching for FeliCa tag...");
if (IfPm3Felica()) {
if (read_felica_uid(false, false) == PM3_SUCCESS) {
PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("ISO 18092 / FeliCa tag") " found\n");
2024-01-04 12:49:47 +01:00
success[FELICA] = true;
res = PM3_SUCCESS;
}
}
/*
2021-03-27 13:23:01 +01:00
PROMPT_CLEARLINE;
2021-04-14 08:15:30 +02:00
PrintAndLogEx(INPLACE, " Searching for CryptoRF tag...");
if (IfPm3Iso14443b()) {
if (readHFCryptoRF(false, false) == PM3_SUCCESS) {
PrintAndLogEx(SUCCESS, "\nValid " _GREEN_("CryptoRF tag") " found\n");
2024-01-04 13:13:54 +01:00
success[CRYPTORF] = true;
2021-03-27 13:23:01 +01:00
res = PM3_SUCCESS;
}
2021-03-27 13:23:01 +01:00
}
*/
2017-10-10 14:59:58 +02:00
2019-12-14 12:56:19 +01:00
PROMPT_CLEARLINE;
if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, _RED_("No known/supported 13.56 MHz tags found"));
res = PM3_ESOFT;
2024-01-04 12:49:47 +01:00
} else {
// no need to print 14A hints, since it will print itself
if (success[THINFILM]) {
PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf thinfilm`") " commands\n");
}
if (success[LTO]) {
PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf lto`") " commands\n");
}
if (success[LEGIC]) {
PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf legic`") " commands\n");
}
if (success[TOPAZ]) {
PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf topaz`") " commands\n");
}
if (success[PROTO_TEXKOM]) {
PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf texkom`") " commands\n");
}
if (success[PROTO_XEROX]) {
PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf xerox`") " commands\n");
}
if (success[ISO_14443B]) {
PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf 14b`") " commands\n");
}
if (success[ISO_15693]) {
PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf 15`") " commands\n");
}
if (success[ICLASS]) {
PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf iclass`") " commands\n");
}
if (success[FELICA]) {
PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf felica`") " commands\n");
}
if (success[PROTO_CRYPTORF]) {
PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf cryptorf`") " commands\n");
}
}
2020-08-28 19:24:10 +02:00
2020-12-21 20:50:47 +01:00
DropField();
return res;
}
int CmdHFTune(const char *Cmd) {
2020-12-21 02:06:43 +01:00
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf tune",
"Continuously measure HF antenna tuning.\n"
2023-12-06 22:16:53 +01:00
"Press pm3 button or <Enter> to interrupt.",
2020-12-21 02:06:43 +01:00
"hf tune\n"
2020-12-21 12:55:36 +01:00
"hf tune --mix"
2020-12-21 02:06:43 +01:00
);
void *argtable[] = {
arg_param_begin,
arg_u64_0("n", "iter", "<dec>", "number of iterations (default: 0=infinite)"),
arg_lit0(NULL, "bar", "bar style"),
arg_lit0(NULL, "mix", "mixed style"),
arg_lit0(NULL, "value", "values style"),
arg_lit0("v", "verbose", "verbose output"),
2020-12-21 02:06:43 +01:00
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
uint32_t iter = arg_get_u32_def(ctx, 1, 0);
bool is_bar = arg_get_lit(ctx, 2);
bool is_mix = arg_get_lit(ctx, 3);
bool is_value = arg_get_lit(ctx, 4);
bool verbose = arg_get_lit(ctx, 5);
2020-12-21 02:06:43 +01:00
CLIParserFree(ctx);
if ((is_bar + is_mix + is_value) > 1) {
PrintAndLogEx(ERR, "Select only one output style");
return PM3_EINVARG;
}
2021-08-21 20:31:05 +02:00
barMode_t style = g_session.bar_mode;
2020-12-21 02:06:43 +01:00
if (is_bar)
style = STYLE_BAR;
if (is_mix)
style = STYLE_MIXED;
if (is_value)
style = STYLE_VALUE;
2023-12-06 22:16:53 +01:00
PrintAndLogEx(INFO, "Measuring HF antenna");
PrintAndLogEx(INFO, "Press " _GREEN_("pm3 button") " or " _GREEN_("<Enter>") " to exit");
2019-05-03 08:40:21 +02:00
PacketResponseNG resp;
clearCommandBuffer();
2020-02-24 09:44:48 +01:00
2019-05-14 08:25:26 +02:00
uint8_t mode[] = {1};
SendCommandNG(CMD_MEASURE_ANTENNA_TUNING_HF, mode, sizeof(mode));
if (WaitForResponseTimeout(CMD_MEASURE_ANTENNA_TUNING_HF, &resp, 1000) == false) {
2019-05-14 08:25:26 +02:00
PrintAndLogEx(WARNING, "Timeout while waiting for Proxmark HF initialization, aborting");
2019-05-03 08:40:21 +02:00
return PM3_ETIMEOUT;
}
2020-02-24 09:44:48 +01:00
2019-05-14 08:25:26 +02:00
mode[0] = 2;
2020-12-21 02:06:43 +01:00
2024-01-18 23:43:16 +08:00
uint32_t v_max = 0xFFFF;
uint32_t v_min = 0xFFFF;
uint64_t v_sum = 0;
uint64_t v_count = 0;
2020-12-21 02:06:43 +01:00
bool first = true;
2024-01-18 23:43:16 +08:00
print_progress(0, v_max, style);
2020-12-21 02:06:43 +01:00
2019-05-14 08:25:26 +02:00
// loop forever (till button pressed) if iter = 0 (default)
2022-02-27 14:22:38 +01:00
for (uint32_t i = 0; iter == 0 || i < iter; i++) {
2020-02-24 09:44:48 +01:00
if (kbd_enter_pressed()) {
2019-05-14 08:40:16 +02:00
break;
}
2020-02-24 09:44:48 +01:00
2019-05-14 08:25:26 +02:00
SendCommandNG(CMD_MEASURE_ANTENNA_TUNING_HF, mode, sizeof(mode));
if (WaitForResponseTimeout(CMD_MEASURE_ANTENNA_TUNING_HF, &resp, 1000) == false) {
2020-02-24 09:44:48 +01:00
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(WARNING, "Timeout while waiting for Proxmark HF measure, aborting");
2020-12-21 02:06:43 +01:00
break;
}
2020-02-24 09:44:48 +01:00
if ((resp.status == PM3_EOPABORTED) || (resp.length != sizeof(uint16_t))) {
2020-12-21 02:06:43 +01:00
PrintAndLogEx(NORMAL, "");
break;
2020-02-24 09:44:48 +01:00
}
2019-08-07 12:58:25 +02:00
uint16_t volt = resp.data.asDwords[0] & 0xFFFF;
2020-12-21 02:06:43 +01:00
if (first) {
2024-01-18 23:43:16 +08:00
v_max = volt;
v_min = volt;
2020-12-21 02:06:43 +01:00
first = false;
}
2024-01-18 23:43:16 +08:00
v_max = (volt > v_max) ? volt : v_max;
if (verbose) {
2024-01-18 23:43:16 +08:00
v_min = (volt < v_min) ? volt : v_min;
v_sum += volt;
v_count++;
2020-12-21 02:06:43 +01:00
}
2024-01-18 23:43:16 +08:00
print_progress(volt, v_max, style);
}
2019-05-14 08:25:26 +02:00
mode[0] = 3;
2020-02-24 09:44:48 +01:00
2019-05-14 08:25:26 +02:00
SendCommandNG(CMD_MEASURE_ANTENNA_TUNING_HF, mode, sizeof(mode));
if (WaitForResponseTimeout(CMD_MEASURE_ANTENNA_TUNING_HF, &resp, 1000) == false) {
2019-05-14 08:25:26 +02:00
PrintAndLogEx(WARNING, "Timeout while waiting for Proxmark HF shutdown, aborting");
return PM3_ETIMEOUT;
}
2020-12-21 02:06:43 +01:00
PrintAndLogEx(NORMAL, "\x1b%c[2K\r", 30);
if (verbose) {
PrintAndLogEx(INFO, "Min....... %u mV", v_min);
PrintAndLogEx(INFO, "Max....... %u mV", v_max);
PrintAndLogEx(INFO, "Average... %.3lf mV", v_sum / (double)v_count);
2024-01-18 23:43:16 +08:00
}
PrintAndLogEx(INFO, "Done!");
2019-05-03 08:40:21 +02:00
return PM3_SUCCESS;
}
2022-07-09 17:27:04 +03:00
typedef enum {
HF_SNOOP_SKIP_NONE = 0x00,
2022-07-25 08:00:30 +02:00
HF_SNOOP_SKIP_DROP = 0x01,
2022-07-09 17:27:04 +03:00
HF_SNOOP_SKIP_MAX = 0x02,
HF_SNOOP_SKIP_MIN = 0x03,
HF_SNOOP_SKIP_AVG = 0x04
} HFSnoopSkipMode;
const CLIParserOption HFSnoopSkipModeOpts[] = {
{HF_SNOOP_SKIP_NONE, "none"},
{HF_SNOOP_SKIP_DROP, "drop"},
{HF_SNOOP_SKIP_MAX, "min"},
{HF_SNOOP_SKIP_MIN, "max"},
{HF_SNOOP_SKIP_AVG, "avg"},
{0, NULL},
};
2020-06-19 18:34:47 +02:00
// Collects pars of u8,
// uses 16bit transfers from FPGA for speed
// Takes all available bigbuff memory
// data sample to download? Not sure what we can do with the data.
2019-03-11 14:55:02 +01:00
int CmdHFSniff(const char *Cmd) {
2020-12-21 02:06:43 +01:00
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf sniff",
2020-12-21 02:40:04 +01:00
"The high frequency sniffer will assign all available memory on device for sniffed data.\n"
2020-12-21 02:06:43 +01:00
"Use `data samples` to download from device and `data plot` to visualize it.\n"
"Press button to quit the sniffing.",
"hf sniff\n"
"hf sniff --sp 1000 --st 0 -> skip 1000 pairs, skip 0 triggers"
2020-12-23 19:51:10 +01:00
);
2020-12-21 02:06:43 +01:00
void *argtable[] = {
arg_param_begin,
2022-07-09 17:27:04 +03:00
arg_u64_0(NULL, "sp", "<dec>", "skip sample pairs"),
arg_u64_0(NULL, "st", "<dec>", "skip number of triggers"),
arg_str0(NULL, "smode", "[none|drop|min|max|avg]", "Skip mode. It switches on the function that applies to several samples before they saved to memory"),
arg_int0(NULL, "sratio", "<dec, ms>", "Skip ratio. It applied the function above to (ratio * 2) samples. For ratio = 1 it 2 samples."),
2020-12-21 02:06:43 +01:00
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
struct {
uint32_t samplesToSkip;
uint32_t triggersToSkip;
2022-07-09 17:27:04 +03:00
uint8_t skipMode;
uint8_t skipRatio;
} PACKED params;
2020-12-21 02:06:43 +01:00
params.samplesToSkip = arg_get_u32_def(ctx, 1, 0);
params.triggersToSkip = arg_get_u32_def(ctx, 2, 0);
2022-07-18 22:17:53 +02:00
2022-07-09 17:27:04 +03:00
int smode = 0;
2022-07-18 22:17:53 +02:00
if (CLIGetOptionList(arg_get_str(ctx, 3), HFSnoopSkipModeOpts, &smode)) {
CLIParserFree(ctx);
2022-07-09 17:27:04 +03:00
return PM3_EINVARG;
2022-07-18 22:17:53 +02:00
}
2022-07-09 17:27:04 +03:00
2022-07-18 22:17:53 +02:00
params.skipMode = smode;
2022-07-09 17:27:04 +03:00
params.skipRatio = arg_get_int_def(ctx, 4, 0);
2022-07-18 22:17:53 +02:00
2020-12-21 02:06:43 +01:00
CLIParserFree(ctx);
2022-07-18 22:17:53 +02:00
if (params.skipMode != HF_SNOOP_SKIP_NONE) {
2022-07-25 08:00:30 +02:00
PrintAndLogEx(INFO, "Skip mode. Function: %s, each: %d sample",
CLIGetOptionListStr(HFSnoopSkipModeOpts, params.skipMode),
params.skipRatio * 2
);
2022-07-18 22:17:53 +02:00
}
2022-07-09 17:34:26 +03:00
2019-03-09 23:35:06 +01:00
clearCommandBuffer();
2020-06-19 18:34:47 +02:00
SendCommandNG(CMD_HF_SNIFF, (uint8_t *)&params, sizeof(params));
for (;;) {
if (kbd_enter_pressed()) {
SendCommandNG(CMD_BREAK_LOOP, NULL, 0);
PrintAndLogEx(INFO, "User aborted");
break;
}
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_HF_SNIFF, &resp, 1000)) {
if (resp.status == PM3_EOPABORTED) {
PrintAndLogEx(INFO, "Button pressed, user aborted");
break;
}
2022-07-18 22:17:53 +02:00
if (resp.status == PM3_SUCCESS) {
struct r {
uint16_t len;
} PACKED;
struct r *retval = (struct r *)resp.data.asBytes;
2020-08-13 12:25:04 +02:00
PrintAndLogEx(INFO, "HF sniff (%u samples)", retval->len);
PrintAndLogEx(HINT, "Use `" _YELLOW_("data hpf") "` to remove offset");
PrintAndLogEx(HINT, "Use `" _YELLOW_("data plot") "` to view");
PrintAndLogEx(HINT, "Use `" _YELLOW_("data save") "` to save");
2020-06-19 18:34:47 +02:00
2020-08-13 12:25:04 +02:00
// download bigbuf_malloc:d.
// it reserve memory from the higher end.
2020-08-13 12:25:04 +02:00
// At the moment, sniff takes all free memory in bigbuff. If this changes,
// we can't start from beginning idx 0 but from that hi-to-start-of-allocated.
uint32_t start = g_pm3_capabilities.bigbuf_size - retval->len;
int res = getSamplesEx(start, start, false, true);
if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, "failed to download samples to client");
return res;
}
break;
}
}
}
PrintAndLogEx(INFO, "Done!");
2019-08-03 23:36:55 +02:00
return PM3_SUCCESS;
}
int handle_hf_plot(bool show_plot) {
2020-11-02 01:46:47 +01:00
2022-07-17 19:29:47 +02:00
uint8_t buf[FPGA_TRACE_SIZE] = {0};
2020-01-12 16:45:24 +01:00
2023-07-24 00:53:35 +02:00
PacketResponseNG resp;
if (GetFromDevice(FPGA_MEM, buf, FPGA_TRACE_SIZE, 0, NULL, 0, &resp, 4000, true) == false) {
2020-01-12 16:45:24 +01:00
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
return PM3_ETIMEOUT;
}
for (size_t i = 0; i < FPGA_TRACE_SIZE; i++) {
2021-08-21 17:39:17 +02:00
g_GraphBuffer[i] = ((int)buf[i]) - 128;
2020-01-12 16:45:24 +01:00
}
g_GraphTraceLen = FPGA_TRACE_SIZE;
2020-01-12 17:13:02 +01:00
if (show_plot) {
ShowGraphWindow();
}
2020-01-12 17:13:02 +01:00
// remove signal offset
CmdHpf("");
setClockGrid(0, 0);
g_DemodBufferLen = 0;
2020-01-12 16:45:24 +01:00
RepaintGraphWindow();
2020-01-12 17:28:12 +01:00
return PM3_SUCCESS;
2020-01-12 16:45:24 +01:00
}
2020-10-24 11:56:47 +02:00
int CmdHFPlot(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf plot",
"Plots HF signal after RF signal path and A/D conversion.",
"This can be used after any hf command and will show the last few milliseconds of the HF signal.\n"
"Note: If the last hf command terminated because of a timeout you will most probably see nothing.\n");
void *argtable[] = {
arg_param_begin,
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
CLIParserFree(ctx);
return handle_hf_plot(true);
2020-10-24 11:56:47 +02:00
}
2021-04-19 21:43:32 +02:00
static int CmdHFList(const char *Cmd) {
return CmdTraceListAlias(Cmd, "hf", "raw");
}
static command_t CommandTable[] = {
2020-11-02 01:46:47 +01:00
2020-10-22 22:16:44 +02:00
{"--------", CmdHelp, AlwaysAvailable, "----------------------- " _CYAN_("High Frequency") " -----------------------"},
2020-12-06 03:22:20 +03:00
{"14a", CmdHF14A, AlwaysAvailable, "{ ISO14443A RFIDs... }"},
{"14b", CmdHF14B, AlwaysAvailable, "{ ISO14443B RFIDs... }"},
{"15", CmdHF15, AlwaysAvailable, "{ ISO15693 RFIDs... }"},
// {"cryptorf", CmdHFCryptoRF, AlwaysAvailable, "{ CryptoRF RFIDs... }"},
2021-05-28 18:54:44 +03:00
{"cipurse", CmdHFCipurse, AlwaysAvailable, "{ Cipurse transport Cards... }"},
2020-12-06 03:22:20 +03:00
{"epa", CmdHFEPA, AlwaysAvailable, "{ German Identification Card... }"},
{"emrtd", CmdHFeMRTD, AlwaysAvailable, "{ Machine Readable Travel Document... }"},
{"felica", CmdHFFelica, AlwaysAvailable, "{ ISO18092 / FeliCa RFIDs... }"},
{"fido", CmdHFFido, AlwaysAvailable, "{ FIDO and FIDO2 authenticators... }"},
2022-07-25 08:00:30 +02:00
{"fudan", CmdHFFudan, AlwaysAvailable, "{ Fudan RFIDs... }"},
2021-12-29 23:42:06 +13:00
{"gallagher", CmdHFGallagher, AlwaysAvailable, "{ Gallagher DESFire RFIDs... }"},
2020-12-06 03:22:20 +03:00
{"iclass", CmdHFiClass, AlwaysAvailable, "{ ICLASS RFIDs... }"},
2024-02-01 10:05:04 +01:00
{"ict", CmdHFICT, AlwaysAvailable, "{ ICT MFC/DESfire RFIDs... }"},
{"jooki", CmdHF_Jooki, AlwaysAvailable, "{ Jooki RFIDs... }"},
{"ksx6924", CmdHFKSX6924, AlwaysAvailable, "{ KS X 6924 (T-Money, Snapper+) RFIDs }"},
2020-12-06 03:22:20 +03:00
{"legic", CmdHFLegic, AlwaysAvailable, "{ LEGIC RFIDs... }"},
{"lto", CmdHFLTO, AlwaysAvailable, "{ LTO Cartridge Memory RFIDs... }"},
{"mf", CmdHFMF, AlwaysAvailable, "{ MIFARE RFIDs... }"},
{"mfp", CmdHFMFP, AlwaysAvailable, "{ MIFARE Plus RFIDs... }"},
{"mfu", CmdHFMFUltra, AlwaysAvailable, "{ MIFARE Ultralight RFIDs... }"},
{"mfdes", CmdHFMFDes, AlwaysAvailable, "{ MIFARE Desfire RFIDs... }"},
2022-04-09 18:48:13 +02:00
{"ntag424", CmdHF_ntag424, AlwaysAvailable, "{ NXP NTAG 4242 DNA RFIDs... }"},
2021-05-20 10:07:04 +02:00
{"seos", CmdHFSeos, AlwaysAvailable, "{ SEOS RFIDs... }"},
2021-05-30 14:55:58 +02:00
{"st25ta", CmdHFST25TA, AlwaysAvailable, "{ ST25TA RFIDs... }"},
{"tesla", CmdHFTESLA, AlwaysAvailable, "{ TESLA Cards... }"},
{"texkom", CmdHFTexkom, AlwaysAvailable, "{ Texkom RFIDs... }"},
2020-12-06 03:22:20 +03:00
{"thinfilm", CmdHFThinfilm, AlwaysAvailable, "{ Thinfilm RFIDs... }"},
{"topaz", CmdHFTopaz, AlwaysAvailable, "{ TOPAZ (NFC Type 1) RFIDs... }"},
{"vas", CmdHFVAS, AlwaysAvailable, "{ Apple Value Added Service }"},
#ifdef HAVE_GD
2020-12-06 03:22:20 +03:00
{"waveshare", CmdHFWaveshare, AlwaysAvailable, "{ Waveshare NFC ePaper... }"},
#endif
{"xerox", CmdHFXerox, AlwaysAvailable, "{ Fuji/Xerox cartridge RFIDs... }"},
2020-11-02 01:46:47 +01:00
{"-----------", CmdHelp, AlwaysAvailable, "--------------------- " _CYAN_("General") " ---------------------"},
2020-10-22 22:16:44 +02:00
{"help", CmdHelp, AlwaysAvailable, "This help"},
2021-04-19 21:43:32 +02:00
{"list", CmdHFList, AlwaysAvailable, "List protocol data in trace buffer"},
2020-01-12 16:45:24 +01:00
{"plot", CmdHFPlot, IfPm3Hfplot, "Plot signal"},
{"tune", CmdHFTune, IfPm3Present, "Continuously measure HF antenna tuning"},
2019-09-09 13:15:55 +02:00
{"search", CmdHFSearch, AlwaysAvailable, "Search for known HF tags"},
2021-01-04 23:06:06 +01:00
{"sniff", CmdHFSniff, IfPm3Hfsniff, "Generic HF Sniff"},
{NULL, NULL, NULL, NULL}
};
int CmdHF(const char *Cmd) {
2019-03-09 23:35:06 +01:00
clearCommandBuffer();
2019-04-19 00:47:51 +02:00
return CmdsParse(CommandTable, Cmd);
}
int CmdHelp(const char *Cmd) {
2019-04-10 12:23:40 +02:00
(void)Cmd; // Cmd is not used so far
2019-03-09 23:35:06 +01:00
CmdsHelp(CommandTable);
2019-08-03 23:36:55 +02:00
return PM3_SUCCESS;
}