Android NfcV get information command returns only one byte

回眸只為那壹抹淺笑 提交于 2020-01-04 13:40:16

问题


I'm writing an app for reading binary infos of NFC tags. Here's the code of the NFC intent handler function:

protected void onNewIntent(@NonNull Intent intent)
{
    try
    {
        Tag    tag     = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
        NfcV   nfcV    = NfcV.get(tag);
        byte[] cmdInfo = new byte[]{(byte) 0x02, (byte) 0x2b}; // 'Get info' command
        byte[] answer  = nfcV.transceive(cmdInfo); // Read info from tag.

        ...
    }
    catch(IOException e)
    {
        ...
    }
}

If I run this function reading an NFC tag on a Samsung S3 Neo everything works fine, the answer variable is filled with the expected data:

00 04 4B A0 14 01 00 A0 07 E0 F3 07

Howewer if I run the same function reading the same NFC tag on a Huawei P8lite the answer variable is filled with only one byte:

03

In case of an error, the ISO 15693-3 standard says that I should receive something like

01 03

I.e. at least two bytes, where the second byte is the error code. So the answer I'm actually getting is theoretically not possible.

What am I doing wrong? Does it depend on the mobile hardware? And how can I fix it?


回答1:


Since you are not using an addressed command (Address_flag not set, no UID field in request). You should not receive any resonse at all if an optional command is not supported by the tag (not even an error code). Hence you should neither receive 03 nor 01 03 according to the standard.

Note that NFC chipsets in Android devices often have limitations when it comes to ISO/IEC 15693 and do not support the complete standard. For instance, some chipsets are known to have issues with non-addressed commands. You could work around that by using the addressed version of the command:

Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
NfcV nfcV = NfcV.get(tag);
byte[] cmdInfo = new byte[]{
        (byte)0x20,
        (byte)0x2B,
        (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 };
System.arraycopy(tag.getId(), 0, cmdInfo, 2, 8);
byte[] answer = nfcV.transceive(cmdInfo);

You might also want to test with different settings for the Data_rate_flag since the NFC chipset on your device might have problems with VICCs responding with at high data rate.



来源:https://stackoverflow.com/questions/36951077/android-nfcv-get-information-command-returns-only-one-byte

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