Skip to content Skip to sidebar Skip to footer

Nfc - Help To Exchange Data Between Rc522 & Android Hce

I will explain my project : I have my RC522 and a door connected on my Arduino UNO. I can currently open the door with a MIFARE classic. But now I want to open it with my Android s

Solution 1:

It's an (well commented) open-source project. Just have a look to source code, for instance If you use MIFARE_Read function of MFRC522.cpp

MFRC522::StatusCode MFRC522::MIFARE_Read(   byte blockAddr,     ///< MIFARE Classic: The block (0-0xff) number. MIFARE Ultralight: The first page to return data from.
                                            byte *buffer,       ///< The buffer to store the data in
                                            byte *bufferSize    ///< Buffer size, at least 18 bytes. Also number of bytes returned if STATUS_OK.
                                        ) {
    MFRC522::StatusCode result;

    // Sanity checkif (buffer == NULL || *bufferSize < 18) {
        return STATUS_NO_ROOM;
    }

    // Build command buffer
    buffer[0] = PICC_CMD_MF_READ;
    buffer[1] = blockAddr;
    // Calculate CRC_A
    result = PCD_CalculateCRC(buffer, 2, &buffer[2]);
    if (result != STATUS_OK) {
        return result;
    }

    // Transmit the buffer and receive the response, validate CRC_A.return PCD_TransceiveData(buffer, 4, buffer, bufferSize, NULL, 0, true);
} // End MIFARE_Read()

You could see function PCD_TransceiveData is called and check source of this function:

/**
 * Executes the Transceive command.
 * CRC validation can only be done if backData and backLen are specified.
 * 
 * @return STATUS_OK on success, STATUS_??? otherwise.
 */
MFRC522::StatusCode MFRC522::PCD_TransceiveData(    byte *sendData,     ///< Pointer to the data to transfer to the FIFO.byte sendLen,       ///< Number of bytes to transfer to the FIFO.byte *backData,     ///< NULL or pointer to buffer if data should be read back after executing the command.byte *backLen,      ///< In: Max number of bytes to write to *backData. Out: The number of bytes returned.byte *validBits,    ///< In/Out: The number of valid bits in the last byte. 0 for 8 valid bits. Default NULL.byte rxAlign,       ///< In: Defines the bit position in backData[0] for the first bit received. Default 0.bool checkCRC       ///< In: True => The last two bytes of the response is assumed to be a CRC_A that must be validated.
                                 ) {
    byte waitIRq = 0x30;        // RxIRq and IdleIRqreturn PCD_CommunicateWithPICC(PCD_Transceive, waitIRq, sendData, sendLen, backData, backLen, validBits, rxAlign, checkCRC);
} // End PCD_TransceiveData()

You could called PCD_TransceiveData or PCD_CommunicateWithPICC functions.

UPDATE

You put 0 values for parameters: "backData", "backLen", and "validBits". validBits could be null. backData and backLen must be defined as byte.

UPDATE2

If you have a look at library support protocols It supports ISO/IEC 14443-3 (type A) and not supports ISO/IEC 14443-4 (type B).

If you have a look at Android HCE documentation :

Specifically, Android 4.4 supports emulating cards that are based on the NFC-Forum ISO-DEP specification (based on ISO/IEC 14443-4) and process Application Protocol Data Units (APDUs) as defined in the ISO/IEC 7816-4 specification. Android mandates emulating ISO-DEP only on top of the Nfc-A (ISO/IEC 14443-3 Type A) technology. Support for Nfc-B (ISO/IEC 14443-4 Type B) technology is optional. The layering of all these specifications is shown in the figure 3

In this post: HCE support for ISO/IEC 14443-3 Type B?

Looking at devices in the field, some devices use Type A for HCE and some seem to use Type B. So it's basically the device manufacturer who decides if Type A or Type B is used. The Android API provides no means for the app developer to influence this.

So you have to check with another Android NFC device if your device emulate ISO/IEC 14443-3 (Type A) or ISO/IEC 14443-4 (Type B). You could use NfcTagInfo application on other android device to check this.

Post a Comment for "Nfc - Help To Exchange Data Between Rc522 & Android Hce"