mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-22 06:13:27 -07:00
sc cleanup - add init to all sc commands...
because cmds won't work until the first init happens. (multiple inits don't appear to affect it negatively)
This commit is contained in:
parent
68e93fa639
commit
49d92e3c7e
5 changed files with 109 additions and 105 deletions
|
@ -361,12 +361,15 @@ void SendStatus(void)
|
||||||
{
|
{
|
||||||
BigBuf_print_status();
|
BigBuf_print_status();
|
||||||
Fpga_print_status();
|
Fpga_print_status();
|
||||||
|
#ifdef WITH_SMARTCARD
|
||||||
|
I2C_print_status();
|
||||||
|
#endif
|
||||||
printConfig(); //LF Sampling config
|
printConfig(); //LF Sampling config
|
||||||
printUSBSpeed();
|
printUSBSpeed();
|
||||||
Dbprintf("Various");
|
Dbprintf("Various");
|
||||||
Dbprintf(" MF_DBGLEVEL......%d", MF_DBGLEVEL);
|
Dbprintf(" MF_DBGLEVEL........%d", MF_DBGLEVEL);
|
||||||
Dbprintf(" ToSendMax........%d",ToSendMax);
|
Dbprintf(" ToSendMax..........%d", ToSendMax);
|
||||||
Dbprintf(" ToSendBit........%d",ToSendBit);
|
Dbprintf(" ToSendBit..........%d", ToSendBit);
|
||||||
|
|
||||||
cmd_send(CMD_ACK,1,0,0,0,0);
|
cmd_send(CMD_ACK,1,0,0,0,0);
|
||||||
}
|
}
|
||||||
|
@ -1262,10 +1265,6 @@ void UsbPacketReceived(uint8_t *packet, int len)
|
||||||
SmartCardAtr();
|
SmartCardAtr();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CMD_SMART_SETBAUD:{
|
|
||||||
SmartCardSetBaud(c->arg[0]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case CMD_SMART_SETCLOCK:{
|
case CMD_SMART_SETCLOCK:{
|
||||||
SmartCardSetClock(c->arg[0]);
|
SmartCardSetClock(c->arg[0]);
|
||||||
break;
|
break;
|
||||||
|
|
73
armsrc/i2c.c
73
armsrc/i2c.c
|
@ -13,17 +13,17 @@
|
||||||
#include "string.h" //for memset memcmp
|
#include "string.h" //for memset memcmp
|
||||||
|
|
||||||
// 定义连接引脚
|
// 定义连接引脚
|
||||||
#define GPIO_RST AT91C_PIO_PA1
|
#define GPIO_RST AT91C_PIO_PA1
|
||||||
#define GPIO_SCL AT91C_PIO_PA5
|
#define GPIO_SCL AT91C_PIO_PA5
|
||||||
#define GPIO_SDA AT91C_PIO_PA7
|
#define GPIO_SDA AT91C_PIO_PA7
|
||||||
|
|
||||||
#define SCL_H HIGH(GPIO_SCL)
|
#define SCL_H HIGH(GPIO_SCL)
|
||||||
#define SCL_L LOW(GPIO_SCL)
|
#define SCL_L LOW(GPIO_SCL)
|
||||||
#define SDA_H HIGH(GPIO_SDA)
|
#define SDA_H HIGH(GPIO_SDA)
|
||||||
#define SDA_L LOW(GPIO_SDA)
|
#define SDA_L LOW(GPIO_SDA)
|
||||||
|
|
||||||
#define SCL_read (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SCL)
|
#define SCL_read (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SCL)
|
||||||
#define SDA_read (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SDA)
|
#define SDA_read (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SDA)
|
||||||
|
|
||||||
#define I2C_ERROR "I2C_WaitAck Error"
|
#define I2C_ERROR "I2C_WaitAck Error"
|
||||||
|
|
||||||
|
@ -37,10 +37,10 @@ void __attribute__((optimize("O0"))) I2CSpinDelayClk(uint16_t delay) {
|
||||||
for (c = delay * 2; c; c--) {};
|
for (c = delay * 2; c; c--) {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 通讯延迟函数 communication delay function
|
// 通讯延迟函数 communication delay function
|
||||||
#define I2C_DELAY_1CLK I2CSpinDelayClk(1)
|
#define I2C_DELAY_1CLK I2CSpinDelayClk(1)
|
||||||
#define I2C_DELAY_2CLK I2CSpinDelayClk(2)
|
#define I2C_DELAY_2CLK I2CSpinDelayClk(2)
|
||||||
#define I2C_DELAY_XCLK(x) I2CSpinDelayClk((x))
|
#define I2C_DELAY_XCLK(x) I2CSpinDelayClk((x))
|
||||||
|
|
||||||
|
|
||||||
#define ISO7618_MAX_FRAME 255
|
#define ISO7618_MAX_FRAME 255
|
||||||
|
@ -53,7 +53,7 @@ void I2C_init(void) {
|
||||||
|
|
||||||
// 配置 I2C 引脚,开启上拉,开漏输出
|
// 配置 I2C 引脚,开启上拉,开漏输出
|
||||||
// Configure I2C pin, open up, open leakage
|
// Configure I2C pin, open up, open leakage
|
||||||
AT91C_BASE_PIOA->PIO_PPUER |= (GPIO_SCL | GPIO_SDA); // 打开上拉 Open up the pull up
|
AT91C_BASE_PIOA->PIO_PPUER |= (GPIO_SCL | GPIO_SDA); // 打开上拉 Open up the pull up
|
||||||
AT91C_BASE_PIOA->PIO_MDER |= (GPIO_SCL | GPIO_SDA);
|
AT91C_BASE_PIOA->PIO_MDER |= (GPIO_SCL | GPIO_SDA);
|
||||||
|
|
||||||
// 默认三根线全部拉高
|
// 默认三根线全部拉高
|
||||||
|
@ -90,11 +90,11 @@ void I2C_SetResetStatus(uint8_t LineRST, uint8_t LineSCK, uint8_t LineSDA) {
|
||||||
// Reset the SIM_Adapter, then enter the main program
|
// Reset the SIM_Adapter, then enter the main program
|
||||||
// Note: the SIM_Adapter will not enter the main program after power up. Please run this function before use SIM_Adapter.
|
// Note: the SIM_Adapter will not enter the main program after power up. Please run this function before use SIM_Adapter.
|
||||||
void I2C_Reset_EnterMainProgram(void) {
|
void I2C_Reset_EnterMainProgram(void) {
|
||||||
I2C_SetResetStatus(0, 0, 0); // 拉低复位线
|
I2C_SetResetStatus(0, 0, 0); // 拉低复位线
|
||||||
SpinDelay(30);
|
SpinDelay(30);
|
||||||
I2C_SetResetStatus(1, 0, 0); // 解除复位
|
I2C_SetResetStatus(1, 0, 0); // 解除复位
|
||||||
SpinDelay(30);
|
SpinDelay(30);
|
||||||
I2C_SetResetStatus(1, 1, 1); // 拉高数据线
|
I2C_SetResetStatus(1, 1, 1); // 拉高数据线
|
||||||
SpinDelay(10);
|
SpinDelay(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,16 +102,16 @@ void I2C_Reset_EnterMainProgram(void) {
|
||||||
// Reset the SIM_Adapter, then enter the bootloader program
|
// Reset the SIM_Adapter, then enter the bootloader program
|
||||||
// Reserve:For firmware update.
|
// Reserve:For firmware update.
|
||||||
void I2C_Reset_EnterBootloader(void) {
|
void I2C_Reset_EnterBootloader(void) {
|
||||||
I2C_SetResetStatus(0, 1, 1); // 拉低复位线
|
I2C_SetResetStatus(0, 1, 1); // 拉低复位线
|
||||||
SpinDelay(100);
|
SpinDelay(100);
|
||||||
I2C_SetResetStatus(1, 1, 1); // 解除复位
|
I2C_SetResetStatus(1, 1, 1); // 解除复位
|
||||||
SpinDelay(10);
|
SpinDelay(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 等待时钟变高
|
// 等待时钟变高
|
||||||
// Wait for the clock to go High.
|
// Wait for the clock to go High.
|
||||||
bool WaitSCL_H_delay(uint32_t delay) {
|
bool WaitSCL_H_delay(uint32_t delay) {
|
||||||
while (delay--) {
|
while (delay--) {
|
||||||
if (SCL_read) {
|
if (SCL_read) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ bool WaitSCL_H(void) {
|
||||||
|
|
||||||
// Wait max 300ms or until SCL goes LOW.
|
// Wait max 300ms or until SCL goes LOW.
|
||||||
// Which ever comes first
|
// Which ever comes first
|
||||||
bool WaitSCL_L_300ms(void){
|
bool WaitSCL_L_300ms(void) {
|
||||||
volatile uint16_t delay = 300;
|
volatile uint16_t delay = 300;
|
||||||
while ( delay-- ) {
|
while ( delay-- ) {
|
||||||
// exit on SCL LOW
|
// exit on SCL LOW
|
||||||
|
@ -211,7 +211,7 @@ bool I2C_WaitAck(void) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void I2C_SendByte(uint8_t data) {
|
void I2C_SendByte(uint8_t data) {
|
||||||
uint8_t i = 8;
|
uint8_t i = 8;
|
||||||
|
|
||||||
while (i--) {
|
while (i--) {
|
||||||
|
@ -238,7 +238,7 @@ uint8_t I2C_ReadByte(void) {
|
||||||
uint8_t i = 8, b = 0;
|
uint8_t i = 8, b = 0;
|
||||||
|
|
||||||
SDA_H;
|
SDA_H;
|
||||||
while (i--) {
|
while (i--) {
|
||||||
b <<= 1;
|
b <<= 1;
|
||||||
SCL_L; I2C_DELAY_2CLK;
|
SCL_L; I2C_DELAY_2CLK;
|
||||||
SCL_H;
|
SCL_H;
|
||||||
|
@ -256,7 +256,7 @@ uint8_t I2C_ReadByte(void) {
|
||||||
// Sends one byte ( command to be written, SlaveDevice address)
|
// Sends one byte ( command to be written, SlaveDevice address)
|
||||||
bool I2C_WriteCmd(uint8_t device_cmd, uint8_t device_address) {
|
bool I2C_WriteCmd(uint8_t device_cmd, uint8_t device_address) {
|
||||||
bool bBreak = true;
|
bool bBreak = true;
|
||||||
do {
|
do {
|
||||||
if (!I2C_Start())
|
if (!I2C_Start())
|
||||||
return false;
|
return false;
|
||||||
//[C0]
|
//[C0]
|
||||||
|
@ -272,7 +272,7 @@ bool I2C_WriteCmd(uint8_t device_cmd, uint8_t device_address) {
|
||||||
} while (false);
|
} while (false);
|
||||||
|
|
||||||
I2C_Stop();
|
I2C_Stop();
|
||||||
if (bBreak) {
|
if (bBreak) {
|
||||||
if ( MF_DBGLEVEL > 3 ) DbpString(I2C_ERROR);
|
if ( MF_DBGLEVEL > 3 ) DbpString(I2C_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -283,7 +283,7 @@ bool I2C_WriteCmd(uint8_t device_cmd, uint8_t device_address) {
|
||||||
// Sends 1 byte data (Data to be written, command to be written , SlaveDevice address ).
|
// Sends 1 byte data (Data to be written, command to be written , SlaveDevice address ).
|
||||||
bool I2C_WriteByte(uint8_t data, uint8_t device_cmd, uint8_t device_address) {
|
bool I2C_WriteByte(uint8_t data, uint8_t device_cmd, uint8_t device_address) {
|
||||||
bool bBreak = true;
|
bool bBreak = true;
|
||||||
do {
|
do {
|
||||||
if (!I2C_Start())
|
if (!I2C_Start())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -303,7 +303,7 @@ bool I2C_WriteByte(uint8_t data, uint8_t device_cmd, uint8_t device_address) {
|
||||||
} while (false);
|
} while (false);
|
||||||
|
|
||||||
I2C_Stop();
|
I2C_Stop();
|
||||||
if (bBreak) {
|
if (bBreak) {
|
||||||
if ( MF_DBGLEVEL > 3 ) DbpString(I2C_ERROR);
|
if ( MF_DBGLEVEL > 3 ) DbpString(I2C_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -342,7 +342,7 @@ bool I2C_BufferWrite(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t dev
|
||||||
} while (false);
|
} while (false);
|
||||||
|
|
||||||
I2C_Stop();
|
I2C_Stop();
|
||||||
if (bBreak) {
|
if (bBreak) {
|
||||||
if ( MF_DBGLEVEL > 3 ) DbpString(I2C_ERROR);
|
if ( MF_DBGLEVEL > 3 ) DbpString(I2C_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -385,7 +385,7 @@ uint8_t I2C_BufferRead(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t d
|
||||||
bBreak = false;
|
bBreak = false;
|
||||||
} while (false);
|
} while (false);
|
||||||
|
|
||||||
if (bBreak) {
|
if (bBreak) {
|
||||||
I2C_Stop();
|
I2C_Stop();
|
||||||
if ( MF_DBGLEVEL > 3 ) DbpString(I2C_ERROR);
|
if ( MF_DBGLEVEL > 3 ) DbpString(I2C_ERROR);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -453,7 +453,7 @@ uint8_t I2C_ReadFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t
|
||||||
bBreak = false;
|
bBreak = false;
|
||||||
} while (false);
|
} while (false);
|
||||||
|
|
||||||
if (bBreak) {
|
if (bBreak) {
|
||||||
I2C_Stop();
|
I2C_Stop();
|
||||||
if ( MF_DBGLEVEL > 3 ) DbpString(I2C_ERROR);
|
if ( MF_DBGLEVEL > 3 ) DbpString(I2C_ERROR);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -515,7 +515,7 @@ bool I2C_WriteFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t d
|
||||||
} while (false);
|
} while (false);
|
||||||
|
|
||||||
I2C_Stop();
|
I2C_Stop();
|
||||||
if (bBreak) {
|
if (bBreak) {
|
||||||
if ( MF_DBGLEVEL > 3 ) DbpString(I2C_ERROR);
|
if ( MF_DBGLEVEL > 3 ) DbpString(I2C_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -529,7 +529,7 @@ void I2C_print_status(void) {
|
||||||
I2C_Reset_EnterMainProgram();
|
I2C_Reset_EnterMainProgram();
|
||||||
uint8_t len = I2C_BufferRead(resp, sizeof(resp), I2C_DEVICE_CMD_GETVERSION, I2C_DEVICE_ADDRESS_MAIN);
|
uint8_t len = I2C_BufferRead(resp, sizeof(resp), I2C_DEVICE_CMD_GETVERSION, I2C_DEVICE_ADDRESS_MAIN);
|
||||||
if ( len > 0 )
|
if ( len > 0 )
|
||||||
Dbprintf(" version.................v%x.%02x", resp[0], resp[1]);
|
Dbprintf(" version.................v%x.%02x", resp[0], resp[1]);
|
||||||
else
|
else
|
||||||
DbpString(" version.................FAILED");
|
DbpString(" version.................FAILED");
|
||||||
}
|
}
|
||||||
|
@ -584,6 +584,7 @@ void SmartCardAtr(void) {
|
||||||
LED_D_ON();
|
LED_D_ON();
|
||||||
clear_trace();
|
clear_trace();
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
|
I2C_init();
|
||||||
I2C_Reset_EnterMainProgram();
|
I2C_Reset_EnterMainProgram();
|
||||||
bool isOK = GetATR( &card );
|
bool isOK = GetATR( &card );
|
||||||
cmd_send(CMD_ACK, isOK, sizeof(smart_card_atr_t), 0, &card, sizeof(smart_card_atr_t));
|
cmd_send(CMD_ACK, isOK, sizeof(smart_card_atr_t), 0, &card, sizeof(smart_card_atr_t));
|
||||||
|
@ -606,6 +607,7 @@ void SmartCardRaw( uint64_t arg0, uint64_t arg1, uint8_t *data ) {
|
||||||
|
|
||||||
if ((flags & SC_CONNECT)) {
|
if ((flags & SC_CONNECT)) {
|
||||||
|
|
||||||
|
I2C_init();
|
||||||
I2C_Reset_EnterMainProgram();
|
I2C_Reset_EnterMainProgram();
|
||||||
|
|
||||||
if ( !(flags & SC_NO_SELECT) ) {
|
if ( !(flags & SC_NO_SELECT) ) {
|
||||||
|
@ -646,6 +648,7 @@ void SmartCardUpgrade(uint64_t arg0) {
|
||||||
// write. Sector0, with 11,22,33,44
|
// write. Sector0, with 11,22,33,44
|
||||||
// erase is 128bytes, and takes 50ms to execute
|
// erase is 128bytes, and takes 50ms to execute
|
||||||
|
|
||||||
|
I2C_init();
|
||||||
I2C_Reset_EnterBootloader();
|
I2C_Reset_EnterBootloader();
|
||||||
|
|
||||||
bool isOK = true;
|
bool isOK = true;
|
||||||
|
@ -697,12 +700,14 @@ void SmartCardUpgrade(uint64_t arg0) {
|
||||||
LED_C_OFF();
|
LED_C_OFF();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SmartCardSetBaud(uint64_t arg0) {
|
// unfinished (or not needed?)
|
||||||
}
|
//void SmartCardSetBaud(uint64_t arg0) {
|
||||||
|
//}
|
||||||
|
|
||||||
void SmartCardSetClock(uint64_t arg0) {
|
void SmartCardSetClock(uint64_t arg0) {
|
||||||
LED_D_ON();
|
LED_D_ON();
|
||||||
set_tracing(true);
|
set_tracing(true);
|
||||||
|
I2C_init();
|
||||||
I2C_Reset_EnterMainProgram();
|
I2C_Reset_EnterMainProgram();
|
||||||
|
|
||||||
// Send SIM CLC
|
// Send SIM CLC
|
||||||
|
|
|
@ -46,14 +46,13 @@ uint8_t I2C_BufferRead(uint8_t *data, uint8_t len, uint8_t device_cmd, uint8_t d
|
||||||
uint8_t I2C_ReadFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t device_address);
|
uint8_t I2C_ReadFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t device_address);
|
||||||
bool I2C_WriteFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t device_address);
|
bool I2C_WriteFW(uint8_t *data, uint8_t len, uint8_t msb, uint8_t lsb, uint8_t device_address);
|
||||||
|
|
||||||
//
|
|
||||||
bool GetATR(smart_card_atr_t *card_ptr);
|
bool GetATR(smart_card_atr_t *card_ptr);
|
||||||
|
|
||||||
// generice functions
|
// generic functions
|
||||||
void SmartCardAtr(void);
|
void SmartCardAtr(void);
|
||||||
void SmartCardRaw(uint64_t arg0, uint64_t arg1, uint8_t *data);
|
void SmartCardRaw(uint64_t arg0, uint64_t arg1, uint8_t *data);
|
||||||
void SmartCardUpgrade(uint64_t arg0);
|
void SmartCardUpgrade(uint64_t arg0);
|
||||||
void SmartCardSetBaud(uint64_t arg0);
|
//void SmartCardSetBaud(uint64_t arg0);
|
||||||
void SmartCardSetClock(uint64_t arg0);
|
void SmartCardSetClock(uint64_t arg0);
|
||||||
void I2C_print_status(void);
|
void I2C_print_status(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -606,7 +606,7 @@ int ScTraceList(const char *Cmd) {
|
||||||
uint32_t traceLen = 0;
|
uint32_t traceLen = 0;
|
||||||
|
|
||||||
if (loadFromFile) {
|
if (loadFromFile) {
|
||||||
#define TRACE_CHUNK_SIZE (1<<16) // 64K to start with. Will be enough for BigBuf and some room for future extensions
|
#define TRACE_CHUNK_SIZE (1<<16) // 64K to start with. Will be enough for BigBuf and some room for future extensions
|
||||||
FILE *tracefile = NULL;
|
FILE *tracefile = NULL;
|
||||||
size_t bytes_read;
|
size_t bytes_read;
|
||||||
trace = malloc(TRACE_CHUNK_SIZE);
|
trace = malloc(TRACE_CHUNK_SIZE);
|
||||||
|
|
|
@ -68,6 +68,7 @@ typedef struct{
|
||||||
#define CMD_SMART_UPGRADE 0x0141
|
#define CMD_SMART_UPGRADE 0x0141
|
||||||
#define CMD_SMART_UPLOAD 0x0142
|
#define CMD_SMART_UPLOAD 0x0142
|
||||||
#define CMD_SMART_ATR 0x0143
|
#define CMD_SMART_ATR 0x0143
|
||||||
|
// CMD_SMART_SETBAUD is unused for now
|
||||||
#define CMD_SMART_SETBAUD 0x0144
|
#define CMD_SMART_SETBAUD 0x0144
|
||||||
#define CMD_SMART_SETCLOCK 0x0145
|
#define CMD_SMART_SETCLOCK 0x0145
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue