Android的NFC - MIFARE经典1K递增操作tranceive失败 [英] android nfc - mifare classic 1k Increment operation tranceive failed

查看:1183
本文介绍了Android的NFC - MIFARE经典1K递增操作tranceive失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要存储一个整数值和增量或API函数递减它。

I want to store an integer value and increment or decrement it with API function.

我已经readed与实用的卡,这是块5的内容:

I have readed the card with an utility and this is the content of block 5:

似乎没有任何值块。

这是我的code:

    int sector = 5;
    this.mClassic.connect();
    boolean success = this.mClassic.authenticateSectorWithKeyA(sector, MifareClassic.KEY_DEFAULT );

        if(success){
            int firstBlock = mClassic.sectorToBlock(sector);
            Log.i("MIFARE CLASSIC", "first block of the given sector:" + firstBlock);


            //set the value = 0
            byte[] zeroValue = {0, 0, 0, 0, 0,0,0,0,0,0,0,0,0,0,0,0,};
            //save this value 
                            mClassic.writeBlock(firstBlock, zeroValue);

            //increment the value and store it
            this.mClassic.increment(firstBlock, 1);
            this.mClassic.transfer(firstBlock);

            // read the incremented value by converting it in integer from bytearray
            b = readSector(firstBlock);
            data = b.toByteArray();
            value = 0;
            for (int i = 0; i < data.length; i++)
            {
               value = (value << 8) + (data[i] & 0xff);
            }
            Log.i("MIFARE CLASSIC", "After increment " + value);
        }
        mClassic.close();

我回来了 tranceive失败 this.mClassic.increment(firstBlock,1);
我不明白我在做什么错了?谁可以帮我?
非常感谢。

I have returned tranceive failed at this.mClassic.increment(firstBlock, 1); I don't understand what I am doing wrong...who can help me? Thanks a lot.

推荐答案

对Mifare 1K确实值块上的数据完整性检查。您的零值块是不幸的是没有一个有效的价值块。因此,标签和抱怨你得到一个错误。

The Mifare 1K does a data-integrity check on the value-block. Your zeroValue block is unfortunately not a valid value-block. Therefore the tag complains and you get an error.

您可以找到在MIFARE数据表格式(值得一读!)

You can find the format in the Mifare Datasheets (worth reading!)

但是,值块的格式是简单的:

However, the format of the value-block is simple:

byte 0..3:   32 bit value in little endian
byte 4..7:   copy of byte 0..3, with inverted bits (aka. XOR 255)
byte 8..11:  copy of byte 0..3
byte 12:     index of backup block (can be any value)
byte 13:     copy of byte 12 with inverted bits (aka. XOR 255)
byte 14:     copy of byte 12
byte 15:     copy of byte 13

如果您通过上述格式存储您的32位值,你的code将极有可能只是工作。

If you store your 32 bit value using the format above, your code will very likely just work.

这篇关于Android的NFC - MIFARE经典1K递增操作tranceive失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆