mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 05:43:48 -07:00
hf felica sniff - now uses cliparser
This commit is contained in:
parent
b023602d83
commit
7574606080
3 changed files with 99 additions and 72 deletions
|
@ -1319,8 +1319,12 @@ static void PacketReceived(PacketCommandNG *packet) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_HF_FELICA_SNIFF: {
|
case CMD_HF_FELICA_SNIFF: {
|
||||||
felica_sniff(packet->oldarg[0], packet->oldarg[1]);
|
struct p {
|
||||||
reply_ng(CMD_HF_FELICA_SNIFF, PM3_SUCCESS, NULL, 0);
|
uint32_t samples;
|
||||||
|
uint32_t triggers;
|
||||||
|
} PACKED;
|
||||||
|
struct p *payload = (struct p *) packet->data.asBytes;
|
||||||
|
felica_sniff(payload->samples, payload->triggers);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_HF_FELICALITE_DUMP: {
|
case CMD_HF_FELICALITE_DUMP: {
|
||||||
|
|
|
@ -572,23 +572,53 @@ void felica_sendraw(PacketCommandNG *c) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip) {
|
void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip) {
|
||||||
int remFrames = (samplesToSkip) ? samplesToSkip : 0;
|
|
||||||
Dbprintf("Sniff Felica: Getting first %d frames, Skipping after %d triggers.\n", samplesToSkip, triggersToSkip);
|
|
||||||
clear_trace();
|
clear_trace();
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
iso18092_setup(FPGA_HF_ISO18092_FLAG_NOMOD);
|
iso18092_setup(FPGA_HF_ISO18092_FLAG_NOMOD);
|
||||||
|
|
||||||
LED_D_ON();
|
LED_D_ON();
|
||||||
uint16_t numbts = 0;
|
|
||||||
|
int retval = PM3_SUCCESS;
|
||||||
|
int remFrames = (samplesToSkip) ? samplesToSkip : 0;
|
||||||
int trigger_cnt = 0;
|
int trigger_cnt = 0;
|
||||||
uint32_t timeout = iso18092_get_timeout();
|
uint32_t timeout = iso18092_get_timeout();
|
||||||
bool isReaderFrame = true;
|
bool isReaderFrame = true;
|
||||||
while (!BUTTON_PRESS()) {
|
|
||||||
|
uint8_t flip = 0;
|
||||||
|
uint16_t checker = 0;
|
||||||
|
for (;;) {
|
||||||
|
|
||||||
WDT_HIT();
|
WDT_HIT();
|
||||||
|
|
||||||
|
// since simulation is a tight time critical loop,
|
||||||
|
// we only check for user request to end at iteration 3000, 9000.
|
||||||
|
if (flip == 3) {
|
||||||
|
if (data_available()) {
|
||||||
|
retval = PM3_EOPABORTED;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
flip = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checker >= 3000) {
|
||||||
|
|
||||||
|
if (BUTTON_PRESS()) {
|
||||||
|
retval = PM3_EOPABORTED;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
flip++;
|
||||||
|
checker = 0;
|
||||||
|
}
|
||||||
|
++checker;
|
||||||
|
|
||||||
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
|
||||||
|
|
||||||
uint8_t dist = (uint8_t)(AT91C_BASE_SSC->SSC_RHR);
|
uint8_t dist = (uint8_t)(AT91C_BASE_SSC->SSC_RHR);
|
||||||
Process18092Byte(dist);
|
Process18092Byte(dist);
|
||||||
|
|
||||||
if ((dist >= 178) && (++trigger_cnt > triggersToSkip)) {
|
if ((dist >= 178) && (++trigger_cnt > triggersToSkip)) {
|
||||||
Dbprintf("triggersToSkip kicked %d", dist);
|
Dbprintf("triggers To skip kicked %d", dist);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (FelicaFrame.state == STATE_FULL) {
|
if (FelicaFrame.state == STATE_FULL) {
|
||||||
|
@ -599,7 +629,7 @@ void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip) {
|
||||||
}
|
}
|
||||||
remFrames--;
|
remFrames--;
|
||||||
if (remFrames <= 0) {
|
if (remFrames <= 0) {
|
||||||
Dbprintf("Stop Sniffing - samplesToSkip reached!");
|
Dbprintf("Stop Sniffing - samples To skip reached!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
LogTrace(FelicaFrame.framebytes,
|
LogTrace(FelicaFrame.framebytes,
|
||||||
|
@ -609,7 +639,6 @@ void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip) {
|
||||||
NULL,
|
NULL,
|
||||||
isReaderFrame
|
isReaderFrame
|
||||||
);
|
);
|
||||||
numbts += FelicaFrame.len;
|
|
||||||
FelicaFrameReset();
|
FelicaFrameReset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -617,11 +646,9 @@ void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip) {
|
||||||
switch_off();
|
switch_off();
|
||||||
//reset framing
|
//reset framing
|
||||||
AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(8) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0);
|
AT91C_BASE_SSC->SSC_RFMR = SSC_FRAME_MODE_BITS_IN_WORD(8) | AT91C_SSC_MSBF | SSC_FRAME_MODE_WORDS_PER_TRANSFER(0);
|
||||||
set_tracelen(numbts);
|
|
||||||
set_tracelen(BigBuf_max_traceLen());
|
|
||||||
|
|
||||||
Dbprintf("Felica sniffing done, tracelen: %i, use " _YELLOW_("`hf felica list`") " for annotations", BigBuf_get_traceLen());
|
Dbprintf("Felica sniffing done, tracelen: %i", BigBuf_get_traceLen());
|
||||||
reply_mix(CMD_ACK, 1, numbts, 0, 0, 0);
|
reply_ng(CMD_HF_FELICA_SNIFF, retval, NULL, 0);
|
||||||
LED_D_OFF();
|
LED_D_OFF();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -121,20 +121,6 @@ static int usage_hf_felica_sim(void) {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int usage_hf_felica_sniff(void) {
|
|
||||||
PrintAndLogEx(NORMAL, "\nInfo: It get data from the field and saves it into command buffer. ");
|
|
||||||
PrintAndLogEx(NORMAL, " Buffer accessible from command 'hf felica list'");
|
|
||||||
PrintAndLogEx(NORMAL, "\nUsage: hf felica sniff [-h] [-s] [-t]");
|
|
||||||
PrintAndLogEx(NORMAL, " -h this help");
|
|
||||||
PrintAndLogEx(NORMAL, " -s samples to skip (decimal) max 9999");
|
|
||||||
PrintAndLogEx(NORMAL, " -t triggers to skip (decimal) max 9999");
|
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL, "Examples:");
|
|
||||||
PrintAndLogEx(NORMAL, " hf felica sniff");
|
|
||||||
PrintAndLogEx(NORMAL, " hf felica sniff -s 10 -t 10");
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int usage_hf_felica_request_service(void) {
|
static int usage_hf_felica_request_service(void) {
|
||||||
PrintAndLogEx(NORMAL, "\nInfo: Use this command to verify the existence of Area and Service, and to acquire Key Version:");
|
PrintAndLogEx(NORMAL, "\nInfo: Use this command to verify the existence of Area and Service, and to acquire Key Version:");
|
||||||
PrintAndLogEx(NORMAL, " - When the specified Area or Service exists, the card returns Key Version.");
|
PrintAndLogEx(NORMAL, " - When the specified Area or Service exists, the card returns Key Version.");
|
||||||
|
@ -1376,57 +1362,67 @@ static int CmdHFFelicaNotImplementedYet(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CmdHFFelicaSniff(const char *Cmd) {
|
static int CmdHFFelicaSniff(const char *Cmd) {
|
||||||
uint8_t paramCount = 0;
|
CLIParserContext *ctx;
|
||||||
uint64_t samples2skip = 0;
|
CLIParserInit(&ctx, "hf felica sniff",
|
||||||
uint64_t triggers2skip = 0;
|
"Collect data from the field and save into command buffer.\n"
|
||||||
strip_cmds(Cmd);
|
"Buffer accessible from `hf felica list`",
|
||||||
int i = 0;
|
"hf felica sniff\n"
|
||||||
while (Cmd[i] != '\0') {
|
"hf felica sniff -s 10 -t 19"
|
||||||
if (Cmd[i] == '-') {
|
);
|
||||||
switch (tolower(Cmd[i + 1])) {
|
void *argtable[] = {
|
||||||
case 'H':
|
arg_param_begin,
|
||||||
return usage_hf_felica_sniff();
|
arg_u64_0("s", "samples", "<dec>", "samples to skip"),
|
||||||
case 's':
|
arg_u64_0("t", "trig", "<dec>", "triggers to skip "),
|
||||||
paramCount++;
|
arg_param_end
|
||||||
if (param_getlength(Cmd, paramCount) < 5) {
|
};
|
||||||
samples2skip = param_get32ex(Cmd, paramCount++, 0, 10);
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
} else {
|
|
||||||
PrintAndLogEx(ERR, "Invalid samples number!");
|
struct p {
|
||||||
return PM3_EINVARG;
|
uint32_t samples;
|
||||||
}
|
uint32_t triggers;
|
||||||
break;
|
} PACKED payload;
|
||||||
case 't':
|
|
||||||
paramCount++;
|
payload.samples = arg_get_u32_def(ctx, 1, 10);
|
||||||
if (param_getlength(Cmd, paramCount) < 5) {
|
payload.triggers = arg_get_u32_def(ctx, 2, 5000);
|
||||||
triggers2skip = param_get32ex(Cmd, paramCount++, 0, 10);
|
CLIParserFree(ctx);
|
||||||
} else {
|
|
||||||
PrintAndLogEx(ERR, "Invalid triggers number!");
|
if (payload.samples > 9999 ){
|
||||||
return PM3_EINVARG;
|
payload.samples = 9999;
|
||||||
}
|
PrintAndLogEx(INFO, "Too large samples to skip value, using max value 9999");
|
||||||
break;
|
return PM3_EINVARG;
|
||||||
default:
|
|
||||||
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, paramCount));
|
|
||||||
return usage_hf_felica_sniff();
|
|
||||||
}
|
|
||||||
i += 2;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (samples2skip == 0) {
|
if (payload.triggers > 9999 ){
|
||||||
samples2skip = 10;
|
payload.triggers = 9999;
|
||||||
PrintAndLogEx(INFO, "Set default samples2skip: %" PRIu64, samples2skip);
|
PrintAndLogEx(INFO, "Too large trigger to skip value, using max value 9999");
|
||||||
|
return PM3_EINVARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (triggers2skip == 0) {
|
|
||||||
triggers2skip = 5000;
|
|
||||||
PrintAndLogEx(INFO, "Set default triggers2skip: %" PRIu64, triggers2skip);
|
|
||||||
}
|
|
||||||
|
|
||||||
PrintAndLogEx(INFO, "Start Sniffing now. You can stop sniffing with clicking the PM3 Button");
|
PrintAndLogEx(INFO, "Sniff Felica, getting first %" PRIu32 " frames, skipping after %" PRIu32 " triggers", payload.samples, payload.triggers );
|
||||||
PrintAndLogEx(INFO, "During sniffing, other pm3 commands may not response.");
|
PrintAndLogEx(INFO, "Press " _GREEN_("<Enter>") " or pm3-button to abort sniffing");
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommandMIX(CMD_HF_FELICA_SNIFF, samples2skip, triggers2skip, 0, NULL, 0);
|
SendCommandNG(CMD_HF_FELICA_SNIFF, (uint8_t *)&payload, sizeof(payload));
|
||||||
|
PacketResponseNG resp;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
if (kbd_enter_pressed()) {
|
||||||
|
SendCommandNG(CMD_BREAK_LOOP, NULL, 0);
|
||||||
|
PrintAndLogEx(DEBUG, "User aborted");
|
||||||
|
msleep(300);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (WaitForResponseTimeout(CMD_HF_FELICA_SNIFF, &resp, 1000)) {
|
||||||
|
if (resp.status == PM3_EOPABORTED) {
|
||||||
|
PrintAndLogEx(DEBUG, "Button pressed, user aborted");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PrintAndLogEx(HINT, "try `" _YELLOW_("hf felica list") "` to view");
|
||||||
|
PrintAndLogEx(INFO, "Done");
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue