- // if (!iso14443a_select_card(uid, &card_info, NULL)) {
- // Dbprintf("Epa: Can't select card");
- // return -1;
- // }
-
- uint8_t wupa[] = { 0x26 }; // 0x26 - REQA 0x52 - WAKE-UP
- uint8_t sel_all[] = { 0x93,0x20 };
- uint8_t sel_uid[] = { 0x93,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
- uint8_t rats[] = { 0xE0,0x81,0x00,0x00 }; // FSD=256, FSDI=8, CID=1
-
- uint8_t *resp = ((uint8_t *)BigBuf) + RECV_RESP_OFFSET;
- uint8_t *resp_par = ((uint8_t *)BigBuf) + RECV_RESP_PAR_OFFSET;
-
- byte_t uid_resp[4];
- size_t uid_resp_len = 4;
-
- uint8_t sak = 0x04; // cascade uid
- int len;
-
- // Broadcast for a card, WUPA (0x52) will force response from all cards in the field
- ReaderTransmitBitsPar(wupa,7,0, NULL);
-
- // Receive the ATQA
- if(!ReaderReceive(resp, resp_par)) return -1;
-
- // SELECT_ALL
- ReaderTransmit(sel_all,sizeof(sel_all), NULL);
- if (!ReaderReceive(resp, resp_par)) return -1;
-
- // uid response from tag
- memcpy(uid_resp,resp,uid_resp_len);
-
- // Construct SELECT UID command
- // transmitting a full UID (1 Byte cmd, 1 Byte NVB, 4 Byte UID, 1 Byte BCC, 2 Bytes CRC)
- memcpy(sel_uid+2,uid_resp,4); // the UID
- sel_uid[6] = sel_uid[2] ^ sel_uid[3] ^ sel_uid[4] ^ sel_uid[5]; // calculate and add BCC
- AppendCrc14443a(sel_uid,7); // calculate and add CRC
- ReaderTransmit(sel_uid,sizeof(sel_uid), NULL);
-
- // Receive the SAK
- if (!ReaderReceive(resp, resp_par)) return -1;
- sak = resp[0];
-
- // Request for answer to select
- AppendCrc14443a(rats, 2);
- ReaderTransmit(rats, sizeof(rats), NULL);
-
- if ( !(len = ReaderReceive(resp, resp_par) )) return -1;
-
- // populate the collected data.
- memcpy( card->uid, uid_resp, uid_resp_len);
- card->uidlen += uid_resp_len;
- card->sak = sak;
- card->ats_len = len;
- memcpy(card->ats, resp, sizeof(card->ats));
-
-
- // send the PPS request
- // ReaderTransmit((uint8_t *)pps, sizeof(pps), NULL);
- // uint8_t pps_response[3];
- // uint8_t pps_response_par[1];
- // return_code = ReaderReceive(pps_response,pps_response_par);
- // if (return_code != 3 || pps_response[0] != 0xD0) {
- // return return_code == 0 ? 2 : return_code;
- // }
-
- return -1;
-}
\ No newline at end of file
+ return_code = iso14443a_select_card(uid, &card_a_info, NULL, true, 0);
+ if (return_code == 1) {
+ // send the PPS request
+ ReaderTransmit((uint8_t *)pps, sizeof(pps), NULL);
+ return_code = ReaderReceive(pps_response, pps_response_par);
+ if (return_code != 3 || pps_response[0] != 0xD0) {
+ return return_code == 0 ? 2 : return_code;
+ }
+ Dbprintf("ISO 14443 Type A");
+ iso_type = 'a';
+ return 0;
+ }
+
+ // if we're here, there is no type A card, so we look for type B
+ // power up the field
+ iso14443b_setup();
+ // select the card
+ return_code = iso14443b_select_card( &card_b_info );
+ if (return_code == 1) {
+ Dbprintf("ISO 14443 Type B");
+ iso_type = 'b';
+ return 0;
+ }
+ Dbprintf("No card found.");
+ return 1;
+}