mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-03-17 18:50:32 +08:00
style
This commit is contained in:
parent
da2aa2c55f
commit
1ee3679a98
6 changed files with 45 additions and 55 deletions
|
@ -451,23 +451,23 @@ void FpgaWriteConfWord(uint8_t v) {
|
||||||
void SetAdcMuxFor(uint32_t whichGpio) {
|
void SetAdcMuxFor(uint32_t whichGpio) {
|
||||||
|
|
||||||
#ifndef WITH_FPC
|
#ifndef WITH_FPC
|
||||||
// When compiled without FPC support
|
// When compiled without FPC support
|
||||||
AT91C_BASE_PIOA->PIO_OER =
|
AT91C_BASE_PIOA->PIO_OER =
|
||||||
GPIO_MUXSEL_HIPKD |
|
GPIO_MUXSEL_HIPKD |
|
||||||
GPIO_MUXSEL_LOPKD |
|
GPIO_MUXSEL_LOPKD |
|
||||||
GPIO_MUXSEL_LORAW |
|
GPIO_MUXSEL_LORAW |
|
||||||
GPIO_MUXSEL_HIRAW;
|
GPIO_MUXSEL_HIRAW;
|
||||||
|
|
||||||
AT91C_BASE_PIOA->PIO_PER =
|
AT91C_BASE_PIOA->PIO_PER =
|
||||||
GPIO_MUXSEL_HIPKD |
|
GPIO_MUXSEL_HIPKD |
|
||||||
GPIO_MUXSEL_LOPKD |
|
GPIO_MUXSEL_LOPKD |
|
||||||
GPIO_MUXSEL_LORAW |
|
GPIO_MUXSEL_LORAW |
|
||||||
GPIO_MUXSEL_HIRAW;
|
GPIO_MUXSEL_HIRAW;
|
||||||
|
|
||||||
LOW(GPIO_MUXSEL_HIPKD);
|
LOW(GPIO_MUXSEL_HIPKD);
|
||||||
LOW(GPIO_MUXSEL_LOPKD);
|
LOW(GPIO_MUXSEL_LOPKD);
|
||||||
LOW(GPIO_MUXSEL_HIRAW);
|
LOW(GPIO_MUXSEL_HIRAW);
|
||||||
LOW(GPIO_MUXSEL_LORAW);
|
LOW(GPIO_MUXSEL_LORAW);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
// FPC serial uses HIRAW/LOWRAW pins, so they are excluded here.
|
// FPC serial uses HIRAW/LOWRAW pins, so they are excluded here.
|
||||||
|
|
|
@ -172,9 +172,9 @@ static bool MifareSimInit(uint16_t flags, uint8_t *datain, tag_response_info_t *
|
||||||
static uint8_t rSAK[] = {0x00, 0x00, 0x00}; // Current SAK, CRC
|
static uint8_t rSAK[] = {0x00, 0x00, 0x00}; // Current SAK, CRC
|
||||||
static uint8_t rSAKuid[] = {0x04, 0xda, 0x17}; // UID incomplete cascade bit, CRC
|
static uint8_t rSAKuid[] = {0x04, 0xda, 0x17}; // UID incomplete cascade bit, CRC
|
||||||
|
|
||||||
// RATS answer for 2K NXP mifare classic (with CRC)
|
// RATS answer for 2K NXP mifare classic (with CRC)
|
||||||
static uint8_t rRATS[] = {0x0c, 0x75, 0x77, 0x80, 0x02, 0xc1, 0x05, 0x2f, 0x2f, 0x01, 0xbc, 0xd6, 0x60, 0xd3};
|
static uint8_t rRATS[] = {0x0c, 0x75, 0x77, 0x80, 0x02, 0xc1, 0x05, 0x2f, 0x2f, 0x01, 0xbc, 0xd6, 0x60, 0xd3};
|
||||||
|
|
||||||
*uid_len = 0;
|
*uid_len = 0;
|
||||||
|
|
||||||
// By default use 1K tag
|
// By default use 1K tag
|
||||||
|
@ -184,7 +184,7 @@ static bool MifareSimInit(uint16_t flags, uint8_t *datain, tag_response_info_t *
|
||||||
//by default RATS not supported
|
//by default RATS not supported
|
||||||
*rats_len = 0;
|
*rats_len = 0;
|
||||||
*rats = NULL;
|
*rats = NULL;
|
||||||
|
|
||||||
// -- Determine the UID
|
// -- Determine the UID
|
||||||
// Can be set from emulator memory or incoming data
|
// Can be set from emulator memory or incoming data
|
||||||
// Length: 4,7,or 10 bytes
|
// Length: 4,7,or 10 bytes
|
||||||
|
@ -197,23 +197,21 @@ static bool MifareSimInit(uint16_t flags, uint8_t *datain, tag_response_info_t *
|
||||||
// If uid size defined, copy only uid from EMUL to use, backward compatibility for 'hf_colin.c', 'hf_mattyrun.c'
|
// If uid size defined, copy only uid from EMUL to use, backward compatibility for 'hf_colin.c', 'hf_mattyrun.c'
|
||||||
if ((flags & (FLAG_4B_UID_IN_DATA | FLAG_7B_UID_IN_DATA | FLAG_10B_UID_IN_DATA)) != 0) {
|
if ((flags & (FLAG_4B_UID_IN_DATA | FLAG_7B_UID_IN_DATA | FLAG_10B_UID_IN_DATA)) != 0) {
|
||||||
memcpy(datain, block0, 10); // load 10bytes from EMUL to the datain pointer. to be used below.
|
memcpy(datain, block0, 10); // load 10bytes from EMUL to the datain pointer. to be used below.
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Check for 4 bytes uid: bcc corrected and single size uid bits in ATQA
|
// Check for 4 bytes uid: bcc corrected and single size uid bits in ATQA
|
||||||
if ((block0[0] ^ block0[1] ^ block0[2] ^ block0[3]) == block0[4] && (block0[6] & 0xc0) == 0) {
|
if ((block0[0] ^ block0[1] ^ block0[2] ^ block0[3]) == block0[4] && (block0[6] & 0xc0) == 0) {
|
||||||
flags |= FLAG_4B_UID_IN_DATA;
|
flags |= FLAG_4B_UID_IN_DATA;
|
||||||
memcpy(datain, block0, 4);
|
memcpy(datain, block0, 4);
|
||||||
rSAK[0] = block0[5];
|
rSAK[0] = block0[5];
|
||||||
memcpy(rATQA, &block0[6], sizeof(rATQA));
|
memcpy(rATQA, &block0[6], sizeof(rATQA));
|
||||||
}
|
}
|
||||||
// Check for 7 bytes UID: double size uid bits in ATQA
|
// Check for 7 bytes UID: double size uid bits in ATQA
|
||||||
else if ((block0[8] & 0xc0) == 0x40) {
|
else if ((block0[8] & 0xc0) == 0x40) {
|
||||||
flags |= FLAG_7B_UID_IN_DATA;
|
flags |= FLAG_7B_UID_IN_DATA;
|
||||||
memcpy(datain, block0, 7);
|
memcpy(datain, block0, 7);
|
||||||
rSAK[0] = block0[7];
|
rSAK[0] = block0[7];
|
||||||
memcpy(rATQA, &block0[8], sizeof(rATQA));
|
memcpy(rATQA, &block0[8], sizeof(rATQA));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Dbprintf("[-] ERROR: Invalid dump. UID/SAK/ATQA not found");
|
Dbprintf("[-] ERROR: Invalid dump. UID/SAK/ATQA not found");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -227,20 +225,17 @@ static bool MifareSimInit(uint16_t flags, uint8_t *datain, tag_response_info_t *
|
||||||
memcpy(rATQA, rATQA_Mini, sizeof(rATQA));
|
memcpy(rATQA, rATQA_Mini, sizeof(rATQA));
|
||||||
rSAK[0] = rSAK_Mini;
|
rSAK[0] = rSAK_Mini;
|
||||||
Dbprintf("Mifare Mini");
|
Dbprintf("Mifare Mini");
|
||||||
}
|
} else if ((flags & FLAG_MF_1K) == FLAG_MF_1K) {
|
||||||
else if ((flags & FLAG_MF_1K) == FLAG_MF_1K) {
|
|
||||||
memcpy(rATQA, rATQA_1k, sizeof(rATQA));
|
memcpy(rATQA, rATQA_1k, sizeof(rATQA));
|
||||||
rSAK[0] = rSAK_1k;
|
rSAK[0] = rSAK_1k;
|
||||||
Dbprintf("Mifare 1K");
|
Dbprintf("Mifare 1K");
|
||||||
}
|
} else if ((flags & FLAG_MF_2K) == FLAG_MF_2K) {
|
||||||
else if ((flags & FLAG_MF_2K) == FLAG_MF_2K) {
|
|
||||||
memcpy(rATQA, rATQA_2k, sizeof(rATQA));
|
memcpy(rATQA, rATQA_2k, sizeof(rATQA));
|
||||||
rSAK[0] = rSAK_2k;
|
rSAK[0] = rSAK_2k;
|
||||||
*rats = rRATS;
|
*rats = rRATS;
|
||||||
*rats_len = sizeof(rRATS);
|
*rats_len = sizeof(rRATS);
|
||||||
Dbprintf("Mifare 2K with RATS support");
|
Dbprintf("Mifare 2K with RATS support");
|
||||||
}
|
} else if ((flags & FLAG_MF_4K) == FLAG_MF_4K) {
|
||||||
else if ((flags & FLAG_MF_4K) == FLAG_MF_4K) {
|
|
||||||
memcpy(rATQA, rATQA_4k, sizeof(rATQA));
|
memcpy(rATQA, rATQA_4k, sizeof(rATQA));
|
||||||
rSAK[0] = rSAK_4k;
|
rSAK[0] = rSAK_4k;
|
||||||
Dbprintf("Mifare 4K");
|
Dbprintf("Mifare 4K");
|
||||||
|
@ -312,8 +307,7 @@ static bool MifareSimInit(uint16_t flags, uint8_t *datain, tag_response_info_t *
|
||||||
|
|
||||||
// Correct uid size bits in ATQA
|
// Correct uid size bits in ATQA
|
||||||
rATQA[0] = (rATQA[0] & 0x3f) | 0x80; // triple size uid
|
rATQA[0] = (rATQA[0] & 0x3f) | 0x80; // triple size uid
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Dbprintf("[-] ERROR: UID size not defined");
|
Dbprintf("[-] ERROR: UID size not defined");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -948,18 +942,16 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t
|
||||||
memcpy(response, rats, rats_len);
|
memcpy(response, rats, rats_len);
|
||||||
mf_crypto1_encrypt(pcs, response, rats_len, response_par);
|
mf_crypto1_encrypt(pcs, response, rats_len, response_par);
|
||||||
EmSendCmdPar(response, rats_len, response_par);
|
EmSendCmdPar(response, rats_len, response_par);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
EmSendCmd(rats, rats_len);
|
EmSendCmd(rats, rats_len);
|
||||||
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RCV RATS => ACK");
|
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RCV RATS => ACK");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA);
|
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA);
|
||||||
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RCV RATS => NACK");
|
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RCV RATS => NACK");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// case MFEMUL_WORK => ISO14443A_CMD_NXP_DESELECT
|
// case MFEMUL_WORK => ISO14443A_CMD_NXP_DESELECT
|
||||||
if (receivedCmd_len == 3 && receivedCmd_dec[0] == ISO14443A_CMD_NXP_DESELECT) {
|
if (receivedCmd_len == 3 && receivedCmd_dec[0] == ISO14443A_CMD_NXP_DESELECT) {
|
||||||
if (rats && rats_len) {
|
if (rats && rats_len) {
|
||||||
|
@ -968,12 +960,10 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t
|
||||||
memcpy(response, receivedCmd_dec, receivedCmd_len);
|
memcpy(response, receivedCmd_dec, receivedCmd_len);
|
||||||
mf_crypto1_encrypt(pcs, response, receivedCmd_len, response_par);
|
mf_crypto1_encrypt(pcs, response, receivedCmd_len, response_par);
|
||||||
EmSendCmdPar(response, receivedCmd_len, response_par);
|
EmSendCmdPar(response, receivedCmd_len, response_par);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
EmSendCmd(receivedCmd_dec, receivedCmd_len);
|
EmSendCmd(receivedCmd_dec, receivedCmd_len);
|
||||||
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RCV NXP DESELECT => ACK");
|
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RCV NXP DESELECT => ACK");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA);
|
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA);
|
||||||
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RCV NXP DESELECT => NACK");
|
if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("[MFEMUL_WORK] RCV NXP DESELECT => NACK");
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ void SendCommand(UsbCommand *c) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (offline) {
|
if (offline) {
|
||||||
PrintAndLogEx(WARNING, "Sending bytes to Proxmark3 failed." _YELLOW_("offline") );
|
PrintAndLogEx(WARNING, "Sending bytes to Proxmark3 failed." _YELLOW_("offline"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,7 +275,7 @@ __attribute__((force_align_arg_pointer))
|
||||||
if (txBuffer_pending) {
|
if (txBuffer_pending) {
|
||||||
if (!uart_send(sp, (uint8_t *) &txBuffer, sizeof(UsbCommand))) {
|
if (!uart_send(sp, (uint8_t *) &txBuffer, sizeof(UsbCommand))) {
|
||||||
//counter_to_offline++;
|
//counter_to_offline++;
|
||||||
PrintAndLogEx(WARNING, "sending bytes to Proxmark3 device" _RED_("failed") );
|
PrintAndLogEx(WARNING, "sending bytes to Proxmark3 device" _RED_("failed"));
|
||||||
}
|
}
|
||||||
txBuffer_pending = false;
|
txBuffer_pending = false;
|
||||||
|
|
||||||
|
|
|
@ -287,8 +287,8 @@ static int CmdEMVGPO(const char *Cmd) {
|
||||||
PrintAndLogEx(ERR, "Can't create PDOL data.");
|
PrintAndLogEx(ERR, "Can't create PDOL data.");
|
||||||
tlvdb_free(tmp_ext);
|
tlvdb_free(tmp_ext);
|
||||||
tlvdb_free(tlvRoot);
|
tlvdb_free(tlvRoot);
|
||||||
if ( pdol_data_tlv != &data_tlv);
|
if (pdol_data_tlv != &data_tlv);
|
||||||
free(pdol_data_tlv);
|
free(pdol_data_tlv);
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
PrintAndLogEx(INFO, "PDOL data[%d]: %s", pdol_data_tlv_data_len, sprint_hex(pdol_data_tlv_data, pdol_data_tlv_data_len));
|
PrintAndLogEx(INFO, "PDOL data[%d]: %s", pdol_data_tlv_data_len, sprint_hex(pdol_data_tlv_data, pdol_data_tlv_data_len));
|
||||||
|
@ -1278,9 +1278,9 @@ static int CmdEMVExec(const char *Cmd) {
|
||||||
// authorization response code from acquirer
|
// authorization response code from acquirer
|
||||||
const char HostResponse[] = "00"; // 0x3030
|
const char HostResponse[] = "00"; // 0x3030
|
||||||
size_t HostResponseLen = sizeof(HostResponse) - 1;
|
size_t HostResponseLen = sizeof(HostResponse) - 1;
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL, "Host Response: `%s`", HostResponse);
|
PrintAndLogEx(NORMAL, "Host Response: `%s`", HostResponse);
|
||||||
|
|
||||||
tlvdb_change_or_add_node(tlvRoot, 0x8a, HostResponseLen, (const unsigned char *)HostResponse);
|
tlvdb_change_or_add_node(tlvRoot, 0x8a, HostResponseLen, (const unsigned char *)HostResponse);
|
||||||
|
|
||||||
if (CryptoVersion == 10) {
|
if (CryptoVersion == 10) {
|
||||||
|
|
|
@ -253,7 +253,7 @@ static size_t crypto_pk_polarssl_get_nbits(const struct crypto_pk *_cp) {
|
||||||
static unsigned char *crypto_pk_polarssl_get_parameter(const struct crypto_pk *_cp, unsigned param, size_t *plen) {
|
static unsigned char *crypto_pk_polarssl_get_parameter(const struct crypto_pk *_cp, unsigned param, size_t *plen) {
|
||||||
struct crypto_pk_polarssl *cp = (struct crypto_pk_polarssl *)_cp;
|
struct crypto_pk_polarssl *cp = (struct crypto_pk_polarssl *)_cp;
|
||||||
unsigned char *result = NULL;
|
unsigned char *result = NULL;
|
||||||
int res;
|
int res;
|
||||||
switch (param) {
|
switch (param) {
|
||||||
// mod
|
// mod
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -261,10 +261,10 @@ static unsigned char *crypto_pk_polarssl_get_parameter(const struct crypto_pk *_
|
||||||
result = malloc(*plen);
|
result = malloc(*plen);
|
||||||
memset(result, 0x00, *plen);
|
memset(result, 0x00, *plen);
|
||||||
res = mbedtls_mpi_write_binary(&cp->ctx.N, result, *plen);
|
res = mbedtls_mpi_write_binary(&cp->ctx.N, result, *plen);
|
||||||
if ( res == 0 ) {
|
if (res == 0) {
|
||||||
printf("Error write_binary.");
|
printf("Error write_binary.");
|
||||||
result = 0;
|
result = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// exp
|
// exp
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -272,9 +272,9 @@ static unsigned char *crypto_pk_polarssl_get_parameter(const struct crypto_pk *_
|
||||||
result = malloc(*plen);
|
result = malloc(*plen);
|
||||||
memset(result, 0x00, *plen);
|
memset(result, 0x00, *plen);
|
||||||
res = mbedtls_mpi_write_binary(&cp->ctx.E, result, *plen);
|
res = mbedtls_mpi_write_binary(&cp->ctx.E, result, *plen);
|
||||||
if ( res == 0 ) {
|
if (res == 0) {
|
||||||
printf("Error write_binary.");
|
printf("Error write_binary.");
|
||||||
result = 0;
|
result = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -65,15 +65,15 @@ static RetType write_to_buffer(void *cookie, const char *data, LenType len) {
|
||||||
if (newsize >= b->alloc) { // NB! one extra byte is needed to avoid buffer overflow at close_buffer
|
if (newsize >= b->alloc) { // NB! one extra byte is needed to avoid buffer overflow at close_buffer
|
||||||
// make room
|
// make room
|
||||||
size_t newalloc = newsize + newsize / 2 + 1; // give 50% more room
|
size_t newalloc = newsize + newsize / 2 + 1; // give 50% more room
|
||||||
|
|
||||||
char *tmp = realloc(ptr, newalloc);
|
char *tmp = realloc(ptr, newalloc);
|
||||||
if ( tmp == NULL ) {
|
if (tmp == NULL) {
|
||||||
free(ptr);
|
free(ptr);
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
ptr = tmp;
|
ptr = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
b->alloc = newalloc;
|
b->alloc = newalloc;
|
||||||
*b->ptr = ptr;
|
*b->ptr = ptr;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue