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); }
transmit_bits(byte[] pbtTx, int szTxBits)//const const { // Show transmitted command //printf("Sent bits: "); //print_hex_bits(pbtTx, szTxBits); // Transmit the bit frame command, we don't use the arbitrary parity feature if ((szRxBits = NFC.nfc_initiator_transceive_bits(pnd, pbtTx, szTxBits, null, abtRx, abtRx.Length, null)) < 0) { return(false); } // Show received answer //printf("Received bits: "); //print_hex_bits(abtRx, szRxBits); // Succesful transfer return(true); }