hf felica rqresponse - now uses cliparser

This commit is contained in:
iceman1001 2021-04-12 22:49:19 +02:00
commit 4d2f8a3bd5
2 changed files with 47 additions and 51 deletions

View file

@ -131,16 +131,6 @@ static int usage_hf_felica_sim(void) {
} }
*/ */
static int usage_hf_felica_request_response(void) {
PrintAndLogEx(NORMAL, "\nInfo: Use this command to verify the existence of a card and its Mode.");
PrintAndLogEx(NORMAL, " - Current Mode of the card is returned.");
PrintAndLogEx(NORMAL, "\nUsage: hf felica rqresponse [-h]");
PrintAndLogEx(NORMAL, " -h this help");
PrintAndLogEx(NORMAL, " -i <0A0B0C ... hex> set custom IDm to use");
PrintAndLogEx(NORMAL, " hf felica rqresponse -i 01100910c11bc407");
return PM3_SUCCESS;
}
static int usage_hf_felica_read_without_encryption(void) { static int usage_hf_felica_read_without_encryption(void) {
PrintAndLogEx(NORMAL, "\nInfo: Use this command to read Block Data from authentication-not-required Service."); PrintAndLogEx(NORMAL, "\nInfo: Use this command to read Block Data from authentication-not-required Service.");
PrintAndLogEx(NORMAL, " - Mode shall be Mode0."); PrintAndLogEx(NORMAL, " - Mode shall be Mode0.");
@ -1023,60 +1013,68 @@ static int CmdHFFelicaReadWithoutEncryption(const char *Cmd) {
* @return client result code. * @return client result code.
*/ */
static int CmdHFFelicaRequestResponse(const char *Cmd) { static int CmdHFFelicaRequestResponse(const char *Cmd) {
uint8_t data[PM3_CMD_DATA_SIZE];
bool custom_IDm = false; CLIParserContext *ctx;
strip_cmds(Cmd); CLIParserInit(&ctx, "hf felica rqresponse",
uint16_t datalen = 10; // Length (1), Command ID (1), IDm (8) "Use this command to verify the existence of a card and its Mode.\n"
uint8_t paramCount = 0; " - current mode of the card is returned",
uint8_t flags = 0; "hf felica rqresponse -i 11100910C11BC407\n"
int i = 0; );
while (Cmd[i] != '\0') { void *argtable[] = {
if (Cmd[i] == '-') { arg_param_begin,
switch (tolower(Cmd[i + 1])) { arg_str0("i", NULL, "<hex>", "set custom IDm"),
case 'h': arg_param_end
return usage_hf_felica_request_response(); };
case 'i': CLIExecWithReturn(ctx, Cmd, argtable, true);
paramCount++;
custom_IDm = true; uint8_t idm[8] = {0};
if (!add_param(Cmd, paramCount, data, 2, 16)) { int ilen = 0;
int res = CLIParamHexToBuf(arg_get_str(ctx, 1), idm, sizeof(idm), &ilen);
if (res) {
CLIParserFree(ctx);
return PM3_EINVARG; return PM3_EINVARG;
} }
paramCount++;
i += 16; CLIParserFree(ctx);
break;
default: uint8_t data[PM3_CMD_DATA_SIZE];
return usage_hf_felica_request_response();
}
}
i++;
}
data[0] = 0x0A; // Static length data[0] = 0x0A; // Static length
data[1] = 0x04; // Command ID data[1] = 0x04; // Command ID
bool custom_IDm = false;
if (ilen) {
custom_IDm = true;
memcpy(data + 2, idm, sizeof(idm));
}
uint8_t datalen = 10; // Length (1), Command ID (1), IDm (8)
if (!custom_IDm && !check_last_idm(data, datalen)) { if (!custom_IDm && !check_last_idm(data, datalen)) {
return PM3_EINVARG; return PM3_EINVARG;
} }
AddCrc(data, datalen); AddCrc(data, datalen);
datalen += 2; datalen += 2;
flags |= FELICA_APPEND_CRC;
flags |= FELICA_RAW; uint8_t flags = (FELICA_APPEND_CRC | FELICA_RAW);
clear_and_send_command(flags, datalen, data, 0); clear_and_send_command(flags, datalen, data, 0);
PacketResponseNG resp; PacketResponseNG resp;
if (!waitCmdFelica(0, &resp, 1)) { if (waitCmdFelica(0, &resp, 1) == false) {
PrintAndLogEx(ERR, "\nGot no response from card"); PrintAndLogEx(ERR, "Got no response from card");
return PM3_ERFTRANS; return PM3_ERFTRANS;
} else { }
felica_request_request_response_t rq_response; felica_request_request_response_t rq_response;
memcpy(&rq_response, (felica_request_request_response_t *)resp.data.asBytes, sizeof(felica_request_request_response_t)); memcpy(&rq_response, (felica_request_request_response_t *)resp.data.asBytes, sizeof(felica_request_request_response_t));
if (rq_response.frame_response.IDm[0] != 0) { if (rq_response.frame_response.IDm[0] != 0) {
PrintAndLogEx(SUCCESS, "\nGot Request Response:"); PrintAndLogEx(SUCCESS, "Request Response");
PrintAndLogEx(SUCCESS, "IDm: %s", sprint_hex(rq_response.frame_response.IDm, sizeof(rq_response.frame_response.IDm))); PrintAndLogEx(SUCCESS, "IDm...... %s", sprint_hex(rq_response.frame_response.IDm, sizeof(rq_response.frame_response.IDm)));
PrintAndLogEx(SUCCESS, " -Mode: %s\n\n", sprint_hex(rq_response.mode, sizeof(rq_response.mode))); PrintAndLogEx(SUCCESS, " Mode... %s", sprint_hex(rq_response.mode, sizeof(rq_response.mode)));
}
} }
return PM3_SUCCESS; return PM3_SUCCESS;
} }
/** /**
* Command parser for rqspecver * Command parser for rqspecver
* @param Cmd input data of the user. * @param Cmd input data of the user.
@ -1192,7 +1190,6 @@ static int CmdHFFelicaRequestSpecificationVersion(const char *Cmd) {
return PM3_SUCCESS; return PM3_SUCCESS;
} }
/** /**
* Command parser for resetmode * Command parser for resetmode
* @param Cmd input data of the user. * @param Cmd input data of the user.

View file

@ -9,7 +9,6 @@ hf 15 writeafi
hf 15 writedsfid hf 15 writedsfid
hf felica rdunencrypted hf felica rdunencrypted
hf felica wrunencrypted hf felica wrunencrypted
hf felica rqresponse
hf felica scsvcode hf felica scsvcode
hf felica auth1 hf felica auth1
hf felica auth2 hf felica auth2