+void DropField() {
+ UsbCommand c = {CMD_READER_ISO_14443a, {0, 0, 0}};
+ SendCommand(&c);
+}
+
+int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen) {
+ static bool responseNum = false;
+ uint16_t cmdc = 0;
+ *dataoutlen = 0;
+
+ if (activateField) {
+ responseNum = false;
+ UsbCommand resp;
+
+ // Anticollision + SELECT card
+ UsbCommand ca = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_DISCONNECT | ISO14A_CLEAR_TRACE, 0, 0}};
+ SendCommand(&ca);
+ if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
+ PrintAndLog("14aRAW ERROR: Proxmark connection timeout.");
+ return 1;
+ }
+
+ // check result
+ if (resp.arg[0] == 0) {
+ PrintAndLog("14aRAW ERROR: No card in field.");
+ return 1;
+ }
+
+ if (resp.arg[0] != 1 && resp.arg[0] != 2) {
+ PrintAndLog("14aRAW ERROR: card not in iso14443-4. res=%d.", resp.arg[0]);
+ return 1;
+ }
+
+ if (resp.arg[0] == 2) { // 0: couldn't read, 1: OK, with ATS, 2: OK, no ATS, 3: proprietary Anticollision
+ // get ATS
+ UsbCommand cr = {CMD_READER_ISO_14443a, {ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT, 2, 0}};
+ uint8_t rats[] = { 0xE0, 0x80 }; // FSDI=8 (FSD=256), CID=0
+ memcpy(cr.d.asBytes, rats, 2);
+ SendCommand(&cr);
+ if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
+ PrintAndLog("14aRAW ERROR: Proxmark connection timeout.");
+ return 1;
+ }
+
+ if (resp.arg[0] <= 0) { // ats_len
+ PrintAndLog("14aRAW ERROR: Can't get ATS.");
+ return 1;
+ }
+ }
+ }