Iso7816Exchange: avoid sending systematically typeA APDUs firstly on typeB tags
This commit is contained in:
1 parent
11334f9440
commit
56daa155b5
7 files changed
+44
-6
No files matched your search
@@ -31,6 +31,16 @@ bool GetAPDULogging(void) {
|
||||
return APDULogging;
|
||||
}
|
||||
|
||||
static isodep_state_t isodep_state = ISODEP_INACTIVE;
|
||||
|
||||
void SetISODEPState(isodep_state_t state) {
|
||||
isodep_state = state;
|
||||
}
|
||||
|
||||
isodep_state_t GetISODEPState(void) {
|
||||
return isodep_state;
|
||||
}
|
||||
|
||||
int Iso7816ExchangeEx(Iso7816CommandChannel channel, bool ActivateField, bool LeaveFieldON, sAPDU apdu, bool IncludeLe, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw) {
|
||||
uint8_t data[APDU_RES_LEN] = {0};
|
||||
|
||||
@@ -56,11 +66,26 @@ int Iso7816ExchangeEx(Iso7816CommandChannel channel, bool ActivateField, bool Le
|
||||
|
||||
switch (channel) {
|
||||
case CC_CONTACTLESS:
|
||||
res = ExchangeAPDU14a(data, datalen, ActivateField, LeaveFieldON, Result, (int)MaxResultLen, (int *)ResultLen);
|
||||
switch (GetISODEPState()) {
|
||||
case ISODEP_NFCA:
|
||||
res = ExchangeAPDU14a(data, datalen, ActivateField, LeaveFieldON, Result, (int)MaxResultLen, (int *)ResultLen);
|
||||
break;
|
||||
case ISODEP_NFCB:
|
||||
res = exchange_14b_apdu(data, datalen, ActivateField, LeaveFieldON, Result, (int)MaxResultLen, (int *)ResultLen, 4000);
|
||||
break;
|
||||
case ISODEP_INACTIVE:
|
||||
if (! ActivateField) {
|
||||
PrintAndLogEx(FAILED, "Field currently inactive, cannot send an APDU");
|
||||
return PM3_EIO;
|
||||
}
|
||||
res = ExchangeAPDU14a(data, datalen, ActivateField, LeaveFieldON, Result, (int)MaxResultLen, (int *)ResultLen);
|
||||
if (res != PM3_SUCCESS) {
|
||||
res = exchange_14b_apdu(data, datalen, ActivateField, LeaveFieldON, Result, (int)MaxResultLen, (int *)ResultLen, 4000);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (res != PM3_SUCCESS) {
|
||||
res = exchange_14b_apdu(data, datalen, ActivateField, LeaveFieldON, Result, (int)MaxResultLen, (int *)ResultLen, 4000);
|
||||
if (res != PM3_SUCCESS)
|
||||
return res;
|
||||
return res;
|
||||
}
|
||||
break;
|
||||
case CC_CONTACT:
|
||||
|
||||
@@ -20,6 +20,12 @@
|
||||
#define APDU_RES_LEN 260
|
||||
#define APDU_AID_LEN 50
|
||||
|
||||
typedef enum {
|
||||
ISODEP_INACTIVE = 0,
|
||||
ISODEP_NFCA,
|
||||
ISODEP_NFCB,
|
||||
} isodep_state_t;
|
||||
|
||||
typedef enum {
|
||||
CC_CONTACTLESS,
|
||||
CC_CONTACT
|
||||
@@ -28,6 +34,9 @@ typedef enum {
|
||||
void SetAPDULogging(bool logging);
|
||||
bool GetAPDULogging(void);
|
||||
|
||||
void SetISODEPState(isodep_state_t state);
|
||||
isodep_state_t GetISODEPState(void);
|
||||
|
||||
// exchange
|
||||
int Iso7816Exchange(Iso7816CommandChannel channel, bool LeaveFieldON, sAPDU apdu, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw);
|
||||
int Iso7816ExchangeEx(Iso7816CommandChannel channel, bool ActivateField, bool LeaveFieldON, sAPDU apdu, bool IncludeLe, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw);
|
||||
|
||||
Reference in new issue
Block a user