mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-14 18:48:13 -07:00
smart raw - now use NG.\nhf iclass config - added more support for keyrollning (WIP)\n
This commit is contained in:
parent
4fb28e5149
commit
8a05a4d1d7
14 changed files with 485 additions and 262 deletions
|
@ -109,7 +109,7 @@ static bool have_aa2(void) {
|
|||
return memcmp(aa2_key, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 8);
|
||||
}
|
||||
|
||||
static uint8_t get_pagemap(const picopass_hdr *hdr) {
|
||||
static uint8_t get_pagemap(const picopass_hdr_t *hdr) {
|
||||
return (hdr->conf.fuses & (FUSE_CRYPT0 | FUSE_CRYPT1)) >> 3;
|
||||
}
|
||||
|
||||
|
@ -322,7 +322,7 @@ static int reader_dump_mode(void) {
|
|||
set_tracing(false);
|
||||
|
||||
|
||||
picopass_hdr *hdr = (picopass_hdr *)card_data;
|
||||
picopass_hdr_t *hdr = (picopass_hdr_t *)card_data;
|
||||
|
||||
// select tag.
|
||||
uint32_t eof_time = 0;
|
||||
|
@ -458,7 +458,7 @@ static int dump_sim_mode(void) {
|
|||
set_tracing(false);
|
||||
|
||||
|
||||
picopass_hdr *hdr = (picopass_hdr *)card_data;
|
||||
picopass_hdr_t *hdr = (picopass_hdr_t *)card_data;
|
||||
|
||||
// select tag.
|
||||
uint32_t eof_time = 0;
|
||||
|
|
|
@ -1746,7 +1746,7 @@ static void PacketReceived(PacketCommandNG *packet) {
|
|||
break;
|
||||
}
|
||||
case CMD_SMART_RAW: {
|
||||
SmartCardRaw(packet->oldarg[0], packet->oldarg[1], packet->data.asBytes);
|
||||
SmartCardRaw((smart_card_raw_t*)packet->data.asBytes);
|
||||
break;
|
||||
}
|
||||
case CMD_SMART_UPLOAD: {
|
||||
|
|
71
armsrc/i2c.c
71
armsrc/i2c.c
|
@ -32,15 +32,13 @@
|
|||
|
||||
#define I2C_ERROR "I2C_WaitAck Error"
|
||||
|
||||
//static
|
||||
|
||||
// Direct use the loop to delay. 6 instructions loop, Masterclock 48MHz,
|
||||
// delay=1 is about 200kbps
|
||||
// timer.
|
||||
// I2CSpinDelayClk(4) = 12.31us
|
||||
// I2CSpinDelayClk(1) = 3.07us
|
||||
static volatile uint32_t c;
|
||||
static void __attribute__((optimize("O0"))) I2CSpinDelayClk(uint16_t delay) {
|
||||
volatile uint32_t c;
|
||||
for (c = delay * 2; c; c--) {};
|
||||
}
|
||||
|
||||
|
@ -101,7 +99,7 @@ void I2C_init(void) {
|
|||
AT91C_BASE_PIOA->PIO_PER |= (GPIO_SCL | GPIO_SDA | GPIO_RST);
|
||||
|
||||
bool isok = (SCL_read && SDA_read);
|
||||
if (!isok)
|
||||
if (isok == false)
|
||||
I2C_recovery();
|
||||
}
|
||||
|
||||
|
@ -161,7 +159,7 @@ static bool WaitSCL_H_delay(uint32_t delay) {
|
|||
// 5000 * 3.07us = 15350us. 15.35ms
|
||||
// 15000 * 3.07us = 46050us. 46.05ms
|
||||
static bool WaitSCL_H(void) {
|
||||
return WaitSCL_H_delay(10000);
|
||||
return WaitSCL_H_delay(15000);
|
||||
}
|
||||
|
||||
static bool WaitSCL_L_delay(uint32_t delay) {
|
||||
|
@ -175,14 +173,14 @@ static bool WaitSCL_L_delay(uint32_t delay) {
|
|||
}
|
||||
// 5000 * 3.07us = 15350us. 15.35ms
|
||||
static bool WaitSCL_L(void) {
|
||||
return WaitSCL_L_delay(10000);
|
||||
return WaitSCL_L_delay(15000);
|
||||
}
|
||||
|
||||
// Wait max 1800ms or until SCL goes LOW.
|
||||
// It timeout reading response from card
|
||||
// Which ever comes first
|
||||
static bool WaitSCL_L_timeout(void) {
|
||||
volatile uint32_t delay = 1800;
|
||||
volatile uint32_t delay = 1700;
|
||||
while (delay--) {
|
||||
// exit on SCL LOW
|
||||
if (!SCL_read)
|
||||
|
@ -195,7 +193,8 @@ static bool WaitSCL_L_timeout(void) {
|
|||
|
||||
static bool I2C_Start(void) {
|
||||
|
||||
I2C_DELAY_XCLK(4);
|
||||
I2C_DELAY_2CLK;
|
||||
I2C_DELAY_2CLK;
|
||||
SDA_H;
|
||||
I2C_DELAY_1CLK;
|
||||
SCL_H;
|
||||
|
@ -220,7 +219,7 @@ static bool I2C_WaitForSim(void) {
|
|||
// 8051 speaks with smart card.
|
||||
// 1000*50*3.07 = 153.5ms
|
||||
// 1byte transfer == 1ms with max frame being 256bytes
|
||||
return WaitSCL_H_delay(10 * 1000 * 50);
|
||||
return WaitSCL_H_delay(1000 * 300);
|
||||
}
|
||||
|
||||
// send i2c STOP
|
||||
|
@ -233,7 +232,10 @@ static void I2C_Stop(void) {
|
|||
I2C_DELAY_2CLK;
|
||||
if (!WaitSCL_H()) return;
|
||||
SDA_H;
|
||||
I2C_DELAY_XCLK(8);
|
||||
I2C_DELAY_2CLK;
|
||||
I2C_DELAY_2CLK;
|
||||
I2C_DELAY_2CLK;
|
||||
I2C_DELAY_2CLK;
|
||||
}
|
||||
|
||||
// Send i2c ACK
|
||||
|
@ -653,7 +655,7 @@ bool sc_rx_bytes(uint8_t *dest, uint8_t *destlen) {
|
|||
|
||||
bool GetATR(smart_card_atr_t *card_ptr, bool verbose) {
|
||||
|
||||
if (!card_ptr)
|
||||
if (card_ptr == NULL)
|
||||
return false;
|
||||
|
||||
card_ptr->atr_len = 0;
|
||||
|
@ -710,53 +712,62 @@ void SmartCardAtr(void) {
|
|||
set_tracing(true);
|
||||
I2C_Reset_EnterMainProgram();
|
||||
smart_card_atr_t card;
|
||||
int res = GetATR(&card, true) ? PM3_SUCCESS : PM3_ETIMEOUT;
|
||||
if (res == PM3_ETIMEOUT) {
|
||||
I2C_Reset_EnterMainProgram();
|
||||
if (GetATR(&card, true)) {
|
||||
reply_ng(CMD_SMART_ATR, PM3_SUCCESS, (uint8_t *)&card, sizeof(smart_card_atr_t));
|
||||
} else {
|
||||
reply_ng(CMD_SMART_ATR, PM3_ETIMEOUT, NULL, 0);
|
||||
}
|
||||
reply_ng(CMD_SMART_ATR, res, (uint8_t *)&card, sizeof(smart_card_atr_t));
|
||||
set_tracing(false);
|
||||
LEDsoff();
|
||||
// StopTicks();
|
||||
}
|
||||
|
||||
void SmartCardRaw(uint64_t arg0, uint64_t arg1, uint8_t *data) {
|
||||
|
||||
void SmartCardRaw(smart_card_raw_t *p) {
|
||||
LED_D_ON();
|
||||
|
||||
uint8_t len = 0;
|
||||
uint8_t *resp = BigBuf_malloc(ISO7618_MAX_FRAME);
|
||||
smartcard_command_t flags = arg0;
|
||||
// check if alloacted...
|
||||
smartcard_command_t flags = p->flags;
|
||||
|
||||
if ((flags & SC_CLEARLOG) == SC_CLEARLOG)
|
||||
clear_trace();
|
||||
|
||||
if ((flags & SC_LOG) == SC_LOG)
|
||||
set_tracing(true);
|
||||
else
|
||||
else
|
||||
set_tracing(false);
|
||||
|
||||
if ((flags & SC_CONNECT)) {
|
||||
if ((flags & SC_CONNECT) == SC_CONNECT) {
|
||||
|
||||
I2C_Reset_EnterMainProgram();
|
||||
|
||||
if ((flags & SC_SELECT)) {
|
||||
if ((flags & SC_SELECT) == SC_SELECT) {
|
||||
smart_card_atr_t card;
|
||||
bool gotATR = GetATR(&card, true);
|
||||
//reply_old(CMD_ACK, gotATR, sizeof(smart_card_atr_t), 0, &card, sizeof(smart_card_atr_t));
|
||||
if (!gotATR)
|
||||
if (gotATR == false) {
|
||||
reply_ng(CMD_SMART_RAW, PM3_ESOFT, NULL, 0);
|
||||
goto OUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((flags & SC_RAW) || (flags & SC_RAW_T0)) {
|
||||
|
||||
LogTrace(data, arg1, 0, 0, NULL, true);
|
||||
LogTrace(p->data, p->len, 0, 0, NULL, true);
|
||||
|
||||
// Send raw bytes
|
||||
// asBytes = A0 A4 00 00 02
|
||||
// arg1 = len 5
|
||||
bool res = I2C_BufferWrite(data, arg1, ((flags & SC_RAW_T0) ? I2C_DEVICE_CMD_SEND_T0 : I2C_DEVICE_CMD_SEND), I2C_DEVICE_ADDRESS_MAIN);
|
||||
if (!res && DBGLEVEL > 3) DbpString(I2C_ERROR);
|
||||
bool res = I2C_BufferWrite(
|
||||
p->data,
|
||||
p->len,
|
||||
((flags & SC_RAW_T0) ? I2C_DEVICE_CMD_SEND_T0 : I2C_DEVICE_CMD_SEND),
|
||||
I2C_DEVICE_ADDRESS_MAIN
|
||||
);
|
||||
if (res == false && DBGLEVEL > 3) {
|
||||
DbpString(I2C_ERROR);
|
||||
reply_ng(CMD_SMART_RAW, PM3_ESOFT, NULL, 0);
|
||||
goto OUT;
|
||||
}
|
||||
|
||||
// read bytes from module
|
||||
len = ISO7618_MAX_FRAME;
|
||||
|
@ -767,8 +778,10 @@ void SmartCardRaw(uint64_t arg0, uint64_t arg1, uint8_t *data) {
|
|||
len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
reply_ng(CMD_SMART_RAW, PM3_SUCCESS, resp, len);
|
||||
|
||||
OUT:
|
||||
reply_mix(CMD_ACK, len, 0, 0, resp, len);
|
||||
BigBuf_free();
|
||||
set_tracing(false);
|
||||
LEDsoff();
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define __I2C_H
|
||||
|
||||
#include "common.h"
|
||||
#include "mifare.h"
|
||||
#include "pm3_cmd.h"
|
||||
|
||||
#define I2C_DEVICE_ADDRESS_BOOT 0xB0
|
||||
#define I2C_DEVICE_ADDRESS_MAIN 0xC0
|
||||
|
@ -39,7 +39,7 @@ bool GetATR(smart_card_atr_t *card_ptr, bool verbose);
|
|||
|
||||
// generice functions
|
||||
void SmartCardAtr(void);
|
||||
void SmartCardRaw(uint64_t arg0, uint64_t arg1, uint8_t *data);
|
||||
void SmartCardRaw(smart_card_raw_t *packet);
|
||||
void SmartCardUpgrade(uint64_t arg0);
|
||||
void SmartCardSetBaud(uint64_t arg0);
|
||||
void SmartCardSetClock(uint64_t arg0);
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
#include "ticks.h"
|
||||
#include "iso15693.h"
|
||||
|
||||
static uint8_t get_pagemap(const picopass_hdr *hdr) {
|
||||
static uint8_t get_pagemap(const picopass_hdr_t *hdr) {
|
||||
return (hdr->conf.fuses & (FUSE_CRYPT0 | FUSE_CRYPT1)) >> 3;
|
||||
}
|
||||
|
||||
|
@ -217,7 +217,7 @@ void iclass_simulate(uint8_t sim_type, uint8_t num_csns, bool send_reply, uint8_
|
|||
|
||||
//This is 'full sim' mode, where we use the emulator storage for data.
|
||||
//ie: BigBuf_get_EM_addr should be previously filled with data from the "eload" command
|
||||
picopass_hdr *hdr = (picopass_hdr *)BigBuf_get_EM_addr();
|
||||
picopass_hdr_t *hdr = (picopass_hdr_t *)BigBuf_get_EM_addr();
|
||||
uint8_t pagemap = get_pagemap(hdr);
|
||||
if (pagemap == PICOPASS_NON_SECURE_PAGEMODE) {
|
||||
do_iclass_simulation_nonsec();
|
||||
|
@ -1275,7 +1275,7 @@ static bool iclass_send_cmd_with_retries(uint8_t *cmd, size_t cmdsize, uint8_t *
|
|||
* @return false = fail
|
||||
* true = Got all.
|
||||
*/
|
||||
static bool select_iclass_tag_ex(picopass_hdr *hdr, bool use_credit_key, uint32_t *eof_time, uint8_t *status) {
|
||||
static bool select_iclass_tag_ex(picopass_hdr_t *hdr, bool use_credit_key, uint32_t *eof_time, uint8_t *status) {
|
||||
|
||||
static uint8_t act_all[] = { ICLASS_CMD_ACTALL };
|
||||
static uint8_t identify[] = { ICLASS_CMD_READ_OR_IDENTIFY, 0x00, 0x73, 0x33 };
|
||||
|
@ -1393,7 +1393,7 @@ static bool select_iclass_tag_ex(picopass_hdr *hdr, bool use_credit_key, uint32_
|
|||
return true;
|
||||
}
|
||||
|
||||
bool select_iclass_tag(picopass_hdr *hdr, bool use_credit_key, uint32_t *eof_time) {
|
||||
bool select_iclass_tag(picopass_hdr_t *hdr, bool use_credit_key, uint32_t *eof_time) {
|
||||
uint8_t result = 0;
|
||||
return select_iclass_tag_ex(hdr, use_credit_key, eof_time, &result);
|
||||
}
|
||||
|
@ -1402,7 +1402,7 @@ bool select_iclass_tag(picopass_hdr *hdr, bool use_credit_key, uint32_t *eof_tim
|
|||
// turn off afterwards
|
||||
void ReaderIClass(uint8_t flags) {
|
||||
|
||||
picopass_hdr hdr = {0};
|
||||
picopass_hdr_t hdr = {0};
|
||||
// uint8_t last_csn[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
uint8_t resp[ICLASS_BUFFER_SIZE] = {0};
|
||||
memset(resp, 0xFF, sizeof(resp));
|
||||
|
@ -1470,7 +1470,7 @@ void ReaderIClass(uint8_t flags) {
|
|||
switch_off();
|
||||
}
|
||||
|
||||
bool authenticate_iclass_tag(iclass_auth_req_t *payload, picopass_hdr *hdr, uint32_t *start_time, uint32_t *eof_time, uint8_t *mac_out) {
|
||||
bool authenticate_iclass_tag(iclass_auth_req_t *payload, picopass_hdr_t *hdr, uint32_t *start_time, uint32_t *eof_time, uint8_t *mac_out) {
|
||||
|
||||
uint8_t cmd_check[9] = { ICLASS_CMD_CHECK };
|
||||
uint8_t mac[4] = {0};
|
||||
|
@ -1538,7 +1538,7 @@ void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain) {
|
|||
readcheck_cc[0] = 0x10 | ICLASS_CMD_READCHECK;
|
||||
|
||||
// select card / e-purse
|
||||
picopass_hdr hdr = {0};
|
||||
picopass_hdr_t hdr = {0};
|
||||
|
||||
iclass_premac_t *keys = (iclass_premac_t *)datain;
|
||||
|
||||
|
@ -1628,7 +1628,7 @@ void iClass_ReadBlock(uint8_t *msg) {
|
|||
|
||||
// select tag.
|
||||
uint32_t eof_time = 0;
|
||||
picopass_hdr hdr = {0};
|
||||
picopass_hdr_t hdr = {0};
|
||||
bool res = select_iclass_tag(&hdr, payload->use_credit_key, &eof_time);
|
||||
if (res == false) {
|
||||
if (payload->send_reply) {
|
||||
|
@ -1701,7 +1701,7 @@ void iClass_Dump(uint8_t *msg) {
|
|||
|
||||
// select tag.
|
||||
uint32_t eof_time = 0;
|
||||
picopass_hdr hdr = {0};
|
||||
picopass_hdr_t hdr = {0};
|
||||
bool res = select_iclass_tag(&hdr, req->use_credit_key, &eof_time);
|
||||
if (res == false) {
|
||||
if (req->send_reply) {
|
||||
|
@ -1828,7 +1828,7 @@ void iClass_WriteBlock(uint8_t *msg) {
|
|||
|
||||
// select tag.
|
||||
uint32_t eof_time = 0;
|
||||
picopass_hdr hdr = {0};
|
||||
picopass_hdr_t hdr = {0};
|
||||
uint8_t res = select_iclass_tag(&hdr, payload->req.use_credit_key, &eof_time);
|
||||
if (res == false) {
|
||||
goto out;
|
||||
|
@ -1950,7 +1950,7 @@ void iClass_Restore(iclass_restore_req_t *msg) {
|
|||
|
||||
uint16_t written = 0;
|
||||
uint32_t eof_time = 0;
|
||||
picopass_hdr hdr = {0};
|
||||
picopass_hdr_t hdr = {0};
|
||||
|
||||
// select
|
||||
bool res = select_iclass_tag(&hdr, msg->req.use_credit_key, &eof_time);
|
||||
|
|
|
@ -34,6 +34,6 @@ bool iclass_auth(iclass_auth_req_t *payload, uint8_t *out);
|
|||
void iClass_ReadBlock(uint8_t *msg);
|
||||
bool iclass_read_block(uint16_t blockno, uint8_t *data, uint32_t *start_time, uint32_t *eof_time);
|
||||
|
||||
bool select_iclass_tag(picopass_hdr *hdr, bool use_credit_key, uint32_t *eof_time);
|
||||
bool authenticate_iclass_tag(iclass_auth_req_t *payload, picopass_hdr *hdr, uint32_t *start_time, uint32_t *eof_time, uint8_t *mac_out);
|
||||
bool select_iclass_tag(picopass_hdr_t *hdr, bool use_credit_key, uint32_t *eof_time);
|
||||
bool authenticate_iclass_tag(iclass_auth_req_t *payload, picopass_hdr_t *hdr, uint32_t *start_time, uint32_t *eof_time, uint8_t *mac_out);
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue