Why I can't read ST M24LR64 as NDEF messages with Android NFC

北城以北 提交于 2020-01-05 02:56:29

问题


M24LR64 IC from STMicroelectronics supports ISO 15693 protocol, also called NfcV in Android NFC. When I placed my Nexus S phone (Android 4.0.4) near to my prototype tag board, I could hear a beep, and saw a message fired by the logcat:

no tag fallback activity found for Intent { act = android.nfc.action.TAG_DISCOVERED}

I wondered why the android dispatched the ACTION_TAG_DISCOVERED intent, not the ACTION_NDEF_DISCOVERED, because I had constructured the ndef format messages following the ST application note. And I can read the NDEF message with the ST own reader software called NfcV-Reader.

Then I composed a demo program in android to verify the problem. When I registered intent with this AndroidManifest.xml

<intent-filter>
    <action android:name="android.nfc.action.NDEF_DISCOVERED" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

I can't receive the NFC message. When I modified with this

I can receive the NFC message from Android system. But when I checked the NDEF message with the expression

Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);

the rawMsgs variable is null! So I reviewed the ST NfcV-Reader source code, and found that it had processed all the data from M24LR64 EEPROM with read block. That means raw data read, do not use off-the-shelf utility from Android NFC and NDEF.

protected Void doInBackground(Void... params)
{
    DataDevice dataDevice = (DataDevice)getApplication();
    fullNdefMessage = null;
    byte[] resultBlock0 = new byte[4];
    byte[] resultBlock1 = new byte[8];
    cpt = 0;

    resultBlock0 = null;
    while ((resultBlock0 == null || resultBlock0[0] == 1)&& cpt<1500)
    {
        resultBlock0 = NFCCommand.SendReadSingleBlockCommand(dataDevice.getCurrentTag(), new byte[]{0x00,0x00}, dataDevice);
        cpt ++;
        Log.v("CPT ", " CPT Read Block 0 ===> " + String.valueOf(cpt));
    }

    //if CC0 = E1h & CC1 = right version
    if(resultBlock0[0]==(byte)0x00 && resultBlock0[1]==(byte)0xE1 && resultBlock0[2]==(byte)0x40)
    {
        //NDEF TAG Format valid
        cpt = 0;
        resultBlock1 = null;

        while ((resultBlock1 == null || resultBlock1[0] == 1) && cpt < 10)
        {
            resultBlock1 = NFCCommand.SendReadMultipleBlockCommand(dataDevice.getCurrentTag(),new byte[]{0x00,0x01}, (byte)0x02, dataDevice);
        }
        if(resultBlock1[1]==(byte)0x03 && resultBlock1[6]==(byte)0x54) // Text message
        {
            if(resultBlock1[5]<0)
                numberOfBlockToRead = ((resultBlock1[5] + 256 + 14)/4);
            else
                numberOfBlockToRead = ((resultBlock1[5] + 14)/4);
        }
        else if(resultBlock1[1]==(byte)0x03 && resultBlock1[6]==(byte)0x55) // URL message
        {
            if(resultBlock1[1]<0)
                numberOfBlockToRead = ((resultBlock1[2] + 256 + 12)/4);
            else
                numberOfBlockToRead = ((resultBlock1[2] + 12)/4);
        }
    }
    else
    {
        //Not NDEF TAG Format
        numberOfBlockToRead = 0;
    }

    bNumberOfBlock = Helper.ConvertIntTo2bytesHexaFormat(numberOfBlockToRead);

    cpt = 0;
    if(numberOfBlockToRead <32)
    {
        while ((fullNdefMessage == null || fullNdefMessage[0] == 1) && cpt < 10 && numberOfBlockToRead != 0)
        {
            fullNdefMessage = NFCCommand.SendReadMultipleBlockCommandCustom(dataDevice.getCurrentTag(),new byte[]{0x00,0x00}, bNumberOfBlock[1], dataDevice);
            cpt++;
        }
    }
    else
    {
        while ((fullNdefMessage == null || fullNdefMessage[0] == 1) && cpt < 10 && numberOfBlockToRead != 0)
        {
            fullNdefMessage = NFCCommand.SendReadMultipleBlockCommandCustom2(dataDevice.getCurrentTag(),new byte[]{0x00,0x00}, bNumberOfBlock, dataDevice);
            cpt++;
            Log.i("CPT ", "***** " + String.valueOf(cpt));
        }
    }

    return null;
}

My question is whether I can use the android NDEF facility but not raw block read and write to process my NFC tag with ISO 15693? How can I format my data in M24LR64 EEPROM?


回答1:


The M24LR64 and the similar LRiS64K chips do not support the standard ISO 15693 read commands. (They can easily be recognized from their tag ID, though.) ST has defined and published recently a way to store NDEF messages on such tags. This is done in a way quite similar to how it is done on NXP ICODE SLI tags, for which Android provides support. However, currently, the NFC software stack in Android provides no support for NDEF on ST NfcV tags.

UPDATE:

The Nexus 4 now has support for NDEF storage on other NfcV tags besides NXP ICODE. There is now support for NDEF storage on TI Tag-it HF-I tags and ST tags like LRi2K.




回答2:


Oh well. ISO15693.

There are a lot of ISO15693 tags out there, and they differ in the way memory can be read and written from it (one-byte vs. two byte addressing to name a common difference). There is a standard but lots of different variations are out in the wild. for the M24LR64 chip two byte addressing is necessary.

Unfortunately there is no way to ask such a tag which variant it speaks, so the only way for the NFC software to identify it is to have a list of known tags and their quirks in the NFC software.

And guess what: The NFC stack that usually comes with android does not know about the M24LR64 tag, so it can't read/write NDEF data.

That's the reason why you have to use raw read/write commands. This otoh works perfectly.




回答3:


There are standards, but they are not compatible... Read the raw data is fine, stick to that for the moment. You can also check the ST reference Android code for ideas. I think it clarifies a lot.



来源:https://stackoverflow.com/questions/10277337/why-i-cant-read-st-m24lr64-as-ndef-messages-with-android-nfc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!