tags - android nfc - mifare classic 1k Increment operation tranceive failed -
i want store integer value , increment or decrement api function.
i have readed card utility , content of block 5: 
it seems there not value block.
this 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 given sector:" + firstblock); //set value = 0 byte[] zerovalue = {0, 0, 0, 0, 0,0,0,0,0,0,0,0,0,0,0,0,}; //save value mclassic.writeblock(firstblock, zerovalue); //increment value , store this.mclassic.increment(firstblock, 1); this.mclassic.transfer(firstblock); // read incremented value converting in integer bytearray b = readsector(firstblock); data = b.tobytearray(); value = 0; (int = 0; < data.length; i++) { value = (value << 8) + (data[i] & 0xff); } log.i("mifare classic", "after increment " + value); } mclassic.close(); i have returned tranceive failed @ this.mclassic.increment(firstblock, 1); don't understand doing wrong...who can me? lot.
the mifare 1k data-integrity check on value-block. zerovalue block unfortunately not valid value-block. therefore tag complains , error.
you can find format in mifare datasheets (worth reading!)
however, format of value-block simple:
byte 0..3: 32 bit value in little endian byte 4..7: copy of byte 0..3, inverted bits (aka. xor 255) byte 8..11: copy of byte 0..3 byte 12: index of backup block (can value) byte 13: copy of byte 12 inverted bits (aka. xor 255) byte 14: copy of byte 12 byte 15: copy of byte 13 if store 32 bit value using format above, code work.
Comments
Post a Comment