#include "emvcmd.h"
static emvtags currentcard; //use to hold emv tags for the reader/card during communications
-static tUart Uart;
+//static tUart Uart;
// The FPGA will report its internal sending delay in
uint16_t FpgaSendQueueDelay;
//variables used for timing purposes:
//these are in ssp_clk cycles:
//static uint32_t NextTransferTime;
-static uint32_t LastTimeProxToAirStart;
+//static uint32_t LastTimeProxToAirStart;
//static uint32_t LastProxToAirDuration;
//load individual tag into current card
int EMVGetChallenge(emvtags* inputcard)
{
uint8_t receivedAnswer[MAX_FRAME_SIZE];
- //uint8_t receivedAnswerPar[MAX_PARITY_SIZE];
//variables
//tlvtag inputtag; //create the tag structure
//perform select
uint8_t cdolcommandlen = 0;
tlvtag temptag;
- //uint8_t receivedAnswerPar[MAX_PARITY_SIZE];
if(currentcard.tag_8C_len > 0) {
emv_generateDOL(currentcard.tag_8C, currentcard.tag_8C_len, ¤tcard, cdolcommand, &cdolcommandlen); }
else{
else if((currentcard.tag_9F66[0] & 0x80) == 0x80) {
if((currentcard.tag_9F66[1] & 0x80) == 1) { //CVN17
cardMode = VISA_CVN17;
- }
- else{
+ } else {
cardMode = VISA_DCVV;
- }
+ }
}
EMVSelectAID(currentcard.tag_4F,currentcard.tag_4F_len, ¤tcard); //perform second AID command
EMVReadRecord(4,2,¤tcard);
}
//EMVGetChallenge(¤tcard);
- //memcpy(currentcard.tag_9F4C,&responsebuffer[1],8); // ICC UN
+ //memcpy(currentcard.tag_9F4C,&responsebuffer[1],8); // ICC UN
EMVGenerateAC(0x81,¤tcard);
Dbprintf("CARDMODE=%i",cardMode);
//-----------------------------------------------------------------------------
void SimulateEMVcard()
{
+ /*
+
//uint8_t sak; //select ACKnowledge
uint16_t readerPacketLen = 64; //reader packet length - provided by RATS, default to 64 bytes if RATS not supported
currentblock = receivedCmd[0] & 0x01;
if(receivedCmd[0] == 0x26) { // Received a REQUEST
- p_response = &responses[ATR]; order = REQA;
+ p_response = &responses[ATR]; order = ISO14443A_CMD_REQA;
} else if(receivedCmd[0] == 0x52) { // Received a WAKEUP
- p_response = &responses[ATR]; order = WUPA;
+ p_response = &responses[ATR]; order = ISO14443A_CMD_WUPA;
} else if(receivedCmd[1] == 0x20 && receivedCmd[0] == 0x93) { // Received request for UID (cascade 1)
- p_response = &responses[UID1]; order = SELUID1;
+ p_response = &responses[UID1]; order = ISO14443A_CMD_ANTICOLL_OR_SELECT;
} else if(receivedCmd[1] == 0x20 && receivedCmd[0] == 0x95) { // Received request for UID (cascade 2)
- p_response = &responses[UID2]; order = SELUID2;
+ p_response = &responses[UID2]; order = ISO14443A_CMD_ANTICOLL_OR_SELECT_2;
} else if(receivedCmd[1] == 0x70 && receivedCmd[0] == 0x93) { // Received a SELECT (cascade 1)
- p_response = &responses[SELACK1]; order = SEL1;
+ p_response = &responses[SELACK1]; order = ISO14443A_CMD_ANTICOLL_OR_SELECT;
} else if(receivedCmd[1] == 0x70 && receivedCmd[0] == 0x95) { // Received a SELECT (cascade 2)
- p_response = &responses[SELACK2]; order = SEL2;
+ p_response = &responses[SELACK2]; order = ISO14443A_CMD_ANTICOLL_OR_SELECT_2;
} else if((receivedCmd[0] & 0xA2) == 0xA2){ //R-Block received
if(previousblock == currentblock){ //rule 11, retransmit last block
p_response = &dynamic_response_info;
Dbprintf("%x %x %x", happened, happened2, cmdsRecvd);
LED_A_OFF();
BigBuf_free_keep_EM();
+
+ */
}
#include "emvdataels.h"
-//Known AIDs
-struct tagdescription {
- uint8_t tag[2];
- char description[255];
-};
-
const uint8_t AID_VISA[] = {0xa0,0x00,0x00,0x00,0x03};
const uint8_t AID_VISA_DB[] = {0xa0,0x00,0x00,0x00,0x03,0x10,0x10};
const uint8_t AID_VISA_C[] = {0xa0,0x00,0x00,0x00,0x03,0x10,0x10,0x01};
const uint8_t PIN_BLOCKED2[] = {0x69,0x84};
const uint8_t PIN_WRONG[] = {0x63};
-const tagdescription EMV_TAG_LIST[] = {
+const tagdescription_t EMV_TAG_LIST[62] = {
{"\x4f\x00","Application Identifier (AID)"},
{"\x50\x00","Application Label"},
{"\x57\x00","Track 2 Equivalent Data"},
#include <stdint.h>
-typedef struct tagdescription tagdescription;
+//Known AIDs
+typedef struct {
+ uint8_t tag[2];
+ char description[255];
+} __attribute__((__packed__)) tagdescription_t;
//Known AIDs
extern const uint8_t AID_VISA[5];
-extern const uint8_t AID_VISA_DB[7] ;
-extern const uint8_t AID_VISA_C[8] ;
-extern const uint8_t AID_VISA_D[8] ;
-extern const uint8_t AID_VISA_E[7] ;
-extern const uint8_t AID_VISA_I[7] ;
-extern const uint8_t AID_VISA_P[7] ;
+extern const uint8_t AID_VISA_DB[7];
+extern const uint8_t AID_VISA_C[8];
+extern const uint8_t AID_VISA_D[8];
+extern const uint8_t AID_VISA_E[7];
+extern const uint8_t AID_VISA_I[7];
+extern const uint8_t AID_VISA_P[7];
extern const uint8_t AID_VISA_ATM[8];
extern const uint8_t AID_MASTERCARD[7];
extern const uint8_t AID_MAESTRO[7];
extern const uint8_t AID_MAESTRO_TEST[5];
extern const uint8_t AID_SELF_SERVICE[6];
extern const uint8_t AID_AMEX[5];
-extern const uint8_t AID_EXPRESSPAY[];
+extern const uint8_t AID_EXPRESSPAY[8];
extern const uint8_t AID_LINK[7];
extern const uint8_t AID_ALIAS[7];
//Master data file for PSE
-extern const uint8_t DF_PSE[];
-extern const tagdescription EMV_TAG_LIST[62]; //SW1 return values
-extern const uint8_t SW1_RESPONSE_BYTES[];
-extern const uint8_t SW1_WRONG_LENGTH[] ;
-extern const uint8_t SW12_OK[];
-extern const uint8_t SW12_NOT_SUPPORTED[] ;
-extern const uint8_t SW12_NOT_FOUND[];
-extern const uint8_t SW12_COND_NOT_SAT[];
-extern const uint8_t PIN_BLOCKED[] ;
-extern const uint8_t PIN_BLOCKED2[] ;
-extern const uint8_t PIN_WRONG[] ;
+extern const uint8_t DF_PSE[14];
+extern const uint8_t SW1_RESPONSE_BYTES[1];
+extern const uint8_t SW1_WRONG_LENGTH[1];
+extern const uint8_t SW12_OK[2];
+extern const uint8_t SW12_NOT_SUPPORTED[2];
+extern const uint8_t SW12_NOT_FOUND[2];
+extern const uint8_t SW12_COND_NOT_SAT[2];
+extern const uint8_t PIN_BLOCKED[2];
+extern const uint8_t PIN_BLOCKED2[2];
+extern const uint8_t PIN_WRONG[1];
+
+extern const tagdescription_t EMV_TAG_LIST[62]; //SW1 return values
//AIP bitmasks details
#define AIP_CHIP_SUPPORTED 0x80
//function to
int emv_settag(uint32_t tag, uint8_t *datain, emvtags *currentcard){
char binarydata[255] = {0};
- //if((strlen((const char *)datain)%2) != 0){ //must be an even string
+
+ /*
+ // if((strlen((const char *)datain)%2) != 0){ //must be an even string
// return -1;
- //}
- //if(strlen((const char *)datain) > 255) {
+ // }
+ // if(strlen((const char *)datain) > 255) {
// return -1;
- //}
- uint8_t datalen = strlen((const char *)datain) / 2; //length of datain
- for(int i=0;i<strlen((const char *)datain);i+=2){
+ // }
+ */
+
+ uint8_t datalen = strlen((const char *)datain) / 2; //length of datain
+ for(int i = 0; i < strlen((const char *)datain); i += 2){
binarydata[i/2] |= (char)hex2int(datain[i]) << 4;
binarydata[i/2] |= (char)hex2int(datain[i+1]);
}
selectCmd[4] = AID_len;
memcpy(&(selectCmd[5]), AID, AID_len);
selectCmd[selectCmd_len-1] = 0x00;
- return iso14_apdu(selectCmd,selectCmd_len,false, 0,data);
+ return iso14_apdu(selectCmd, selectCmd_len, data);
}
//perform READ RECORD
readRecordCmd[2] = recordnumber;
readRecordCmd[3] = ((sfi << 3) | 0x04);
readRecordCmd[4] = 0x00;
- return iso14_apdu(readRecordCmd,readRecordCmd_len,false,0,data);
+ return iso14_apdu(readRecordCmd, readRecordCmd_len, data);
}
int emv_getprocessingoptions(uint8_t* pdol, uint8_t pdol_len, void* data)
memcpy(&(processingCmd[7]), pdol, pdol_len);}
processingCmd[processingCmd_len] = 0x00;
//Dbhexdump(processingCmd_len, processingCmd, false);
- return iso14_apdu(processingCmd,processingCmd_len,false, 0, data);
+ return iso14_apdu(processingCmd, processingCmd_len, data);
}
int emv_computecryptogram(uint8_t* UDOL, uint8_t UDOL_len, void *data)
memcpy(&(cryptogramCmd[5]), UDOL, UDOL_len);
cryptogramCmd[cryptogramCmd_len-1] = 0x00;
- return iso14_apdu(cryptogramCmd,cryptogramCmd_len,false, 0,data);
+ return iso14_apdu(cryptogramCmd, cryptogramCmd_len, data);
}
int emv_getchallenge(void *data)
challengeCmd[3] = 0x00;
challengeCmd[4] = 0x00;
- return iso14_apdu(challengeCmd,challengeCmd_len,false, 0,data);
+ return iso14_apdu(challengeCmd, challengeCmd_len, data);
}
int emv_loopback(uint8_t* transData , uint8_t transData_len, void *data)
loopbackCmd[3] = 0x00;
loopbackCmd[4] = loopbackCmd_len;
memcpy(&(loopbackCmd[5]), transData, transData_len);
- return iso14_apdu(loopbackCmd,loopbackCmd_len,false, 0,data);
+ return iso14_apdu(loopbackCmd, loopbackCmd_len, data);
}
//generateAC
memcpy(&(acCmd[5]), cdolinput, cdolinputlen);
acCmd[acCmd_len-1] = 0x00;
Dbhexdump(acCmd_len, acCmd,false);
- return iso14_apdu(acCmd,acCmd_len,false,0,data);
+ return iso14_apdu(acCmd, acCmd_len, data);
}
-int emv_decodeAFL(uint8_t* AFL, uint8_t AFLlen )
-{
-
+int emv_decodeAFL(uint8_t* AFL, uint8_t AFLlen ){
return 0;
}
return (data[2] << 16) | (data[1] << 8) | data[0];
}
+//convert hex digit to integer
+uint8_t hex2int(char hexchar){
+ switch(hexchar){
+ case '0': return 0; break;
+ case '1': return 1; break;
+ case '2': return 2; break;
+ case '3': return 3; break;
+ case '4': return 4; break;
+ case '5': return 5; break;
+ case '6': return 6; break;
+ case '7': return 7; break;
+ case '8': return 8; break;
+ case '9': return 9; break;
+ case 'a':
+ case 'A': return 10; break;
+ case 'b':
+ case 'B': return 11; break;
+ case 'c':
+ case 'C': return 12; break;
+ case 'd':
+ case 'D': return 13; break;
+ case 'e':
+ case 'E': return 14; break;
+ case 'f':
+ case 'F': return 15; break;
+ default:
+ return 0;
+ }
+}
+
void LEDsoff() {
LED_A_OFF();
LED_B_OFF();
void rol(uint8_t *data, const size_t len);
void lsl (uint8_t *data, size_t len);
int32_t le24toh (uint8_t data[3]);
+uint8_t hex2int(char hexchar);
void LED(int led, int ms);
void LEDsoff();
prx = rx;
if (txcmd_pending) {
- if ( !uart_send(sp, (byte_t*) &txcmd, sizeof(UsbCommand))) {
+ bool res = uart_send(sp, (byte_t*) &txcmd, sizeof(UsbCommand));
+ if (!res) {
PrintAndLog("Sending bytes to proxmark failed");
}
txcmd_pending = false;