mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-14 18:48:13 -07:00
chg: 'sc reader' - hooked up atr.
This commit is contained in:
parent
89352c47c1
commit
fca841122f
6 changed files with 174 additions and 83 deletions
|
@ -1023,22 +1023,12 @@ void UsbPacketReceived(uint8_t *packet, int len) {
|
|||
#endif
|
||||
|
||||
#ifdef WITH_SMARTCARD
|
||||
case CMD_SMART_SEND: {
|
||||
|
||||
I2C_init();
|
||||
I2C_Reset_EnterMainProgram();
|
||||
|
||||
// sample:
|
||||
// [C0 02 C1] A0 A4 00 00 02
|
||||
// asBytes = A0 A4 00 00 02
|
||||
// arg0 = len 5
|
||||
I2C_BufferWrite(c->d.asBytes, c->arg[0], I2C_DEVICE_CMD_SEND, I2C_DEVICE_ADDRESS_MAIN);
|
||||
|
||||
uint8_t resp[255] = {0};
|
||||
uint8_t len = I2C_BufferRead(resp, 255, I2C_DEVICE_CMD_READ, I2C_DEVICE_ADDRESS_MAIN);
|
||||
Dbhexdump(len, resp, false);
|
||||
|
||||
cmd_send(CMD_ACK, len, 0, 0, resp, len);
|
||||
case CMD_SMART_ATR: {
|
||||
SmartCardAtr();
|
||||
break;
|
||||
}
|
||||
case CMD_SMART_RAW: {
|
||||
SmartCardRaw(c->arg[0], c->d.asBytes);
|
||||
break;
|
||||
}
|
||||
case CMD_SMART_UPLOAD: {
|
||||
|
@ -1049,63 +1039,7 @@ void UsbPacketReceived(uint8_t *packet, int len) {
|
|||
break;
|
||||
}
|
||||
case CMD_SMART_UPGRADE: {
|
||||
|
||||
#define I2C_BLOCK_SIZE 128
|
||||
// write. Sector0, with 11,22,33,44
|
||||
// erase is 128bytes.
|
||||
|
||||
StartTicks();
|
||||
I2C_init();
|
||||
I2C_Reset_EnterBootloader();
|
||||
|
||||
bool isOK = true;
|
||||
uint8_t res = 0;
|
||||
uint16_t length = c->arg[0];
|
||||
uint16_t pos = 0;
|
||||
uint8_t *fwdata = BigBuf_get_addr();
|
||||
uint8_t *verfiydata = BigBuf_malloc(I2C_BLOCK_SIZE);
|
||||
|
||||
while (length) {
|
||||
|
||||
uint8_t msb = (pos >> 8) & 0xFF;
|
||||
uint8_t lsb = pos & 0xFF;
|
||||
|
||||
Dbprintf("FW %02X %02X", msb, lsb);
|
||||
|
||||
size_t size = MIN(I2C_BLOCK_SIZE, length);
|
||||
|
||||
// write
|
||||
res = I2C_WriteFW(fwdata+pos, size, msb, lsb, I2C_DEVICE_ADDRESS_BOOT);
|
||||
if ( !res ) {
|
||||
Dbprintf("Writing failed");
|
||||
isOK = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// writing takes time.
|
||||
WaitMS(50);
|
||||
|
||||
// read
|
||||
res = I2C_ReadFW(verfiydata, size, msb, lsb, I2C_DEVICE_ADDRESS_BOOT);
|
||||
if ( res == 0) {
|
||||
Dbprintf("Reading back failed");
|
||||
isOK = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// cmp
|
||||
if ( 0 != memcmp(fwdata+pos, verfiydata, size)) {
|
||||
Dbprintf("not equal data");
|
||||
isOK = false;
|
||||
break;
|
||||
}
|
||||
|
||||
length -= size;
|
||||
pos += size;
|
||||
}
|
||||
|
||||
cmd_send(CMD_ACK, isOK, pos, 0, 0, 0);
|
||||
StopTicks();
|
||||
SmartCardUpgrade(c->arg[0]);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue