mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 21:33:47 -07:00
CHG: 'hf 14b sim' better work flow on device side. not done yet.
This commit is contained in:
parent
7bcddfabde
commit
d51717fffd
2 changed files with 47 additions and 75 deletions
|
@ -19,6 +19,10 @@
|
||||||
#define TR1 0
|
#define TR1 0
|
||||||
// Frame Delay Time PICC to PCD (per 14443-3 Amendment 1)
|
// Frame Delay Time PICC to PCD (per 14443-3 Amendment 1)
|
||||||
#define TR2 0
|
#define TR2 0
|
||||||
|
|
||||||
|
// 4sample
|
||||||
|
#define SEND4STUFFBIT(x) ToSendStuffBit(x);ToSendStuffBit(x);ToSendStuffBit(x);ToSendStuffBit(x);
|
||||||
|
|
||||||
static void switch_off(void);
|
static void switch_off(void);
|
||||||
|
|
||||||
// the block number for the ISO14443-4 PCB (used with APDUs)
|
// the block number for the ISO14443-4 PCB (used with APDUs)
|
||||||
|
@ -218,77 +222,42 @@ static void CodeIso14443bAsTag(const uint8_t *cmd, int len) {
|
||||||
|
|
||||||
// Send SOF.
|
// Send SOF.
|
||||||
// 10-11 ETU * 4times samples ZEROS
|
// 10-11 ETU * 4times samples ZEROS
|
||||||
for(i = 0; i < 10; i++) {
|
for(i = 0; i < 10; i++) { SEND4STUFFBIT(0); }
|
||||||
ToSendStuffBit(0);
|
|
||||||
ToSendStuffBit(0);
|
|
||||||
ToSendStuffBit(0);
|
|
||||||
ToSendStuffBit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2-3 ETU * 4times samples ONES
|
// 2-3 ETU * 4times samples ONES
|
||||||
for(i = 0; i < 3; i++) {
|
for(i = 0; i < 3; i++) { SEND4STUFFBIT(1); }
|
||||||
ToSendStuffBit(1);
|
|
||||||
ToSendStuffBit(1);
|
|
||||||
ToSendStuffBit(1);
|
|
||||||
ToSendStuffBit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// data
|
// data
|
||||||
for(i = 0; i < len; ++i) {
|
for(i = 0; i < len; ++i) {
|
||||||
|
|
||||||
// Start bit
|
// Start bit
|
||||||
ToSendStuffBit(0);
|
SEND4STUFFBIT(0);
|
||||||
ToSendStuffBit(0);
|
|
||||||
ToSendStuffBit(0);
|
|
||||||
ToSendStuffBit(0);
|
|
||||||
|
|
||||||
// Data bits
|
// Data bits
|
||||||
b = cmd[i];
|
b = cmd[i];
|
||||||
for(j = 0; j < 8; ++j) {
|
for(j = 0; j < 8; ++j) {
|
||||||
if(b & 1) {
|
if(b & 1) {
|
||||||
ToSendStuffBit(1);
|
SEND4STUFFBIT(1);
|
||||||
ToSendStuffBit(1);
|
|
||||||
ToSendStuffBit(1);
|
|
||||||
ToSendStuffBit(1);
|
|
||||||
} else {
|
} else {
|
||||||
ToSendStuffBit(0);
|
SEND4STUFFBIT(0);
|
||||||
ToSendStuffBit(0);
|
|
||||||
ToSendStuffBit(0);
|
|
||||||
ToSendStuffBit(0);
|
|
||||||
}
|
}
|
||||||
b >>= 1;
|
b >>= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop bit
|
// Stop bit
|
||||||
ToSendStuffBit(1);
|
SEND4STUFFBIT(1);
|
||||||
ToSendStuffBit(1);
|
|
||||||
ToSendStuffBit(1);
|
|
||||||
ToSendStuffBit(1);
|
|
||||||
|
|
||||||
// Extra Guard bit
|
// Extra Guard bit
|
||||||
// For PICC it ranges 0-18us (1etu = 9us)
|
// For PICC it ranges 0-18us (1etu = 9us)
|
||||||
ToSendStuffBit(1);
|
SEND4STUFFBIT(1);
|
||||||
ToSendStuffBit(1);
|
|
||||||
ToSendStuffBit(1);
|
|
||||||
ToSendStuffBit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send EOF.
|
// Send EOF.
|
||||||
// 10-11 ETU * 4 sample rate = ZEROS
|
// 10-11 ETU * 4 sample rate = ZEROS
|
||||||
for(i = 0; i < 10; i++) {
|
for(i = 0; i < 10; i++) { SEND4STUFFBIT(0); }
|
||||||
ToSendStuffBit(0);
|
|
||||||
ToSendStuffBit(0);
|
|
||||||
ToSendStuffBit(0);
|
|
||||||
ToSendStuffBit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// why this?
|
// why this?
|
||||||
for(i = 0; i < 40; i++) {
|
for(i = 0; i < 40; i++) { SEND4STUFFBIT(1); }
|
||||||
ToSendStuffBit(1);
|
|
||||||
ToSendStuffBit(1);
|
|
||||||
ToSendStuffBit(1);
|
|
||||||
ToSendStuffBit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert from last byte pos to length
|
// Convert from last byte pos to length
|
||||||
++ToSendMax;
|
++ToSendMax;
|
||||||
|
@ -588,29 +557,6 @@ void SimulateIso14443bTag(uint32_t pupi) {
|
||||||
send halt response ( waiting for wupb )
|
send halt response ( waiting for wupb )
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( len == 7 && receivedCmd[0] == ISO14443B_HALT ) {
|
|
||||||
cardSTATE = SIM_HALTED;
|
|
||||||
} else if ( len == 11 && receivedCmd[0] == ISO14443B_ATTRIB ) {
|
|
||||||
cardSTATE = SIM_ACKNOWLEDGE;
|
|
||||||
} else {
|
|
||||||
// Todo:
|
|
||||||
// - SLOT MARKER
|
|
||||||
// - ISO7816
|
|
||||||
// - emulate with a memory dump
|
|
||||||
Dbprintf("new cmd from reader: len=%d, cmdsRecvd=%d", len, cmdsReceived);
|
|
||||||
|
|
||||||
// CRC Check
|
|
||||||
uint8_t b1, b2;
|
|
||||||
if (len >= 3){ // if crc exists
|
|
||||||
ComputeCrc14443(CRC_14443_B, receivedCmd, len-2, &b1, &b2);
|
|
||||||
if(b1 != receivedCmd[len-2] || b2 != receivedCmd[len-1])
|
|
||||||
DbpString("+++CRC fail");
|
|
||||||
else
|
|
||||||
DbpString("CRC passes");
|
|
||||||
}
|
|
||||||
cardSTATE = SIM_IDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(cardSTATE){
|
switch(cardSTATE){
|
||||||
case SIM_NOFIELD:
|
case SIM_NOFIELD:
|
||||||
case SIM_HALTED:
|
case SIM_HALTED:
|
||||||
|
@ -636,8 +582,32 @@ void SimulateIso14443bTag(uint32_t pupi) {
|
||||||
cardSTATE = SIM_IDLE;
|
cardSTATE = SIM_IDLE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
case SIM_WORK:{
|
||||||
|
if ( len == 7 && receivedCmd[0] == ISO14443B_HALT ) {
|
||||||
|
cardSTATE = SIM_HALTED;
|
||||||
|
} else if ( len == 11 && receivedCmd[0] == ISO14443B_ATTRIB ) {
|
||||||
|
cardSTATE = SIM_ACKNOWLEDGE;
|
||||||
|
} else {
|
||||||
|
// Todo:
|
||||||
|
// - SLOT MARKER
|
||||||
|
// - ISO7816
|
||||||
|
// - emulate with a memory dump
|
||||||
|
Dbprintf("new cmd from reader: len=%d, cmdsRecvd=%d", len, cmdsReceived);
|
||||||
|
|
||||||
|
// CRC Check
|
||||||
|
uint8_t b1, b2;
|
||||||
|
if (len >= 3){ // if crc exists
|
||||||
|
ComputeCrc14443(CRC_14443_B, receivedCmd, len-2, &b1, &b2);
|
||||||
|
if(b1 != receivedCmd[len-2] || b2 != receivedCmd[len-1])
|
||||||
|
DbpString("+++CRC fail");
|
||||||
|
else
|
||||||
|
DbpString("CRC passes");
|
||||||
|
}
|
||||||
|
cardSTATE = SIM_IDLE;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
++cmdsReceived;
|
++cmdsReceived;
|
||||||
|
|
|
@ -33,11 +33,13 @@ uint8_t iso14443b_select_card(iso14b_card_select_t* card);
|
||||||
uint8_t iso14443b_select_card_srx(iso14b_card_select_t* card);
|
uint8_t iso14443b_select_card_srx(iso14b_card_select_t* card);
|
||||||
|
|
||||||
|
|
||||||
#define SIM_NOFIELD 0
|
// States for 14B SIM command
|
||||||
#define SIM_IDLE 1
|
#define SIM_NOFIELD 0
|
||||||
#define SIM_HALTED 2
|
#define SIM_IDLE 1
|
||||||
#define SIM_SELECTING 3
|
#define SIM_HALTED 2
|
||||||
#define SIM_HALTING 4
|
#define SIM_SELECTING 3
|
||||||
|
#define SIM_HALTING 4
|
||||||
#define SIM_ACKNOWLEDGE 5
|
#define SIM_ACKNOWLEDGE 5
|
||||||
|
#define SIM_WORK 6
|
||||||
|
|
||||||
#endif /* __ISO14443B_H */
|
#endif /* __ISO14443B_H */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue