Search code examples
react-nativenfccore-nfc

Android NFC: How to setup password and auth on NFC TAG?


I have ntag213, using react-native-nfc-manager and using it with andriod, at documentation for my tag https://www.nxp.com/docs/en/data-sheet/NTAG213_215_216.pdf I understand firstly I need to authenticate first with command 0x1B to 0x2B and my password: 0xFF1FFFFF

let cmd = Platform.OS === 'ios' ? NfcManager.sendMifareCommandIOS : NfcManager.transceive; resp = await cmd(0x1B,0x2B,0xFF1FFFFF);

But I got error on my screen and dont understand next steps after auth. Please explain how it works enter image description here


Solution

  • I think there are 2 problems with the command you are trying to send.

    1) transceive only takes a byte array and 0xFF1FFFFF is not a byte array but a big number which would need a double to store.

    Thus you are trying to send (byte,byte,double) and the error message it cannot cast the double to an array.

    2) the pwd_auth command only take a byte array of 5 bytes, 1 byte command + 4 bytes password so don't know why you have 0x2B in there.

    So Try

    let cmd = Platform.OS === 'ios' ? NfcManager.sendMifareCommandIOS : NfcManager.transceive; resp = await cmd([0x1B,0xFF,0x1F,0xFF,0xFF]);

    Then check that you the PACK is correct and that you did not get a NACK

    I don't use passwords in my App but I believe you are then authenticated to send normal commands until you close the connection or the card goes out of range.