public static bool unlock_card(NFC.nfc_device pnd) { byte[] abtRx = new byte[264]; int szRx; /* * if (magic2) * { * //printf("Don't use R/W with this card, this is not required!\n"); * return false; * }*/ byte[] abtHalt = { 0x50, 0x00, 0x00, 0x00 }; // special unlock command byte[] abtUnlock1 = { 0x40 }; byte[] abtUnlock2 = { 0x43 }; // Configure the CRC if (NFC.nfc_device_set_property_bool(pnd, NFC.nfc_property.NP_HANDLE_CRC, false) < 0) { NFC.nfc_perror(pnd, "nfc_configure"); return(false); } // Use raw send/receive methods if (NFC.nfc_device_set_property_bool(pnd, NFC.nfc_property.NP_EASY_FRAMING, false) < 0) { NFC.nfc_perror(pnd, "nfc_configure"); return(false); } ISO14443Subr.iso14443a_crc_append(abtHalt, 2); szRx = NFC.nfc_initiator_transceive_bytes(pnd, abtHalt, 4, abtRx, abtRx.Length, 0);//transmit_bytes(abtHalt, 4); // now send unlock if ((szRx = NFC.nfc_initiator_transceive_bits(pnd, abtUnlock1, 7, null, abtRx, abtRx.Length, null)) < 0)//!transmit_bits(abtUnlock1, 7) { //printf("unlock failure!\n"); return(false); } if ((szRx = NFC.nfc_initiator_transceive_bits(pnd, abtUnlock2, 1, null, abtRx, abtRx.Length, null)) < 0)//(!transmit_bytes(abtUnlock2, 1)) { //printf("unlock failure!\n"); return(false); } // reset reader // Configure the CRC if (NFC.nfc_device_set_property_bool(pnd, NFC.nfc_property.NP_HANDLE_CRC, true) < 0) { NFC.nfc_perror(pnd, "nfc_device_set_property_bool"); return(false); } // Switch off raw send/receive methods if (NFC.nfc_device_set_property_bool(pnd, NFC.nfc_property.NP_EASY_FRAMING, true) < 0) { NFC.nfc_perror(pnd, "nfc_device_set_property_bool"); return(false); } return(true); }
unlock_card() { /* * if (magic2) * { * //printf("Don't use R/W with this card, this is not required!\n"); * return false; * }*/ // Configure the CRC if (NFC.nfc_device_set_property_bool(pnd, NFC.nfc_property.NP_HANDLE_CRC, false) < 0) { NFC.nfc_perror(pnd, "nfc_configure"); return(false); } // Use raw send/receive methods if (NFC.nfc_device_set_property_bool(pnd, NFC.nfc_property.NP_EASY_FRAMING, false) < 0) { NFC.nfc_perror(pnd, "nfc_configure"); return(false); } ISO14443Subr.iso14443a_crc_append(abtHalt, 2); transmit_bytes(abtHalt, 4); // now send unlock if (!transmit_bits(abtUnlock1, 7)) { //printf("unlock failure!\n"); return(false); } if (!transmit_bytes(abtUnlock2, 1)) { //printf("unlock failure!\n"); return(false); } // reset reader // Configure the CRC if (NFC.nfc_device_set_property_bool(pnd, NFC.nfc_property.NP_HANDLE_CRC, true) < 0) { NFC.nfc_perror(pnd, "nfc_device_set_property_bool"); return(false); } // Switch off raw send/receive methods if (NFC.nfc_device_set_property_bool(pnd, NFC.nfc_property.NP_EASY_FRAMING, true) < 0) { NFC.nfc_perror(pnd, "nfc_device_set_property_bool"); return(false); } return(true); }
public static int get_rats(NFC.nfc_device pnd, NFC.nfc_target pnt, byte[] abtRx) { int res; byte[] abtRats = { 0xe0, 0x50 }; // Use raw send/receive methods if (NFC.nfc_device_set_property_bool(pnd, NFC.nfc_property.NP_EASY_FRAMING, false) < 0) { NFC.nfc_perror(pnd, "nfc_configure"); return(-1); } res = NFC.nfc_initiator_transceive_bytes(pnd, abtRats, abtRats.Length, abtRx, abtRx.Length, 0); if (res > 0) { // ISO14443-4 card, turn RF field off/on to access ISO14443-3 again if (NFC.nfc_device_set_property_bool(pnd, NFC.nfc_property.NP_ACTIVATE_FIELD, false) < 0) { NFC.nfc_perror(pnd, "nfc_configure"); return(-1); } if (NFC.nfc_device_set_property_bool(pnd, NFC.nfc_property.NP_ACTIVATE_FIELD, true) < 0) { NFC.nfc_perror(pnd, "nfc_configure"); return(-1); } } // Reselect tag after using get_rats, example: if (NFC.nfc_initiator_select_passive_target(pnd, nmMfClassic, null, 0, pnt) <= 0) { //printf("Error: tag disappeared\n"); //NFC.nfc_close(pnd); //NFC.nfc_exit(context); //exit(EXIT_FAILURE); return(-1); } return(res); }