2121import android .os .RemoteException ;
2222
2323import java .io .IOException ;
24+ import java .nio .ByteBuffer ;
2425
2526/**
2627 * Technology class representing MIFARE Classic tags (also known as MIFARE Standard).
3233 * 16 bytes, but the number of sectors and the sector size varies by product. MIFARE has encryption
3334 * built in and each sector has two keys associated with it, as well as ACLs to determine what
3435 * level acess each key grants. Before operating on a sector you must call either
35- * {@link #authenticateSector (int, byte[], boolean )} or
36- * {@link #authenticateBlock (int, byte[], boolean )} to gain authorize your request.
36+ * {@link #authenticateSectorWithKeyA (int, byte[])} or
37+ * {@link #authenticateSectorWithKeyB (int, byte[])} to gain authorization for your request.
3738 */
3839public final class MifareClassic extends BasicTagTechnology {
3940 /**
@@ -322,35 +323,41 @@ public void writeBlock(int blockIndex, byte[] data) throws IOException {
322323
323324 /**
324325 * Increment a value block, and store the result in temporary memory.
325- * @param block
326+ * @param blockIndex
326327 * @throws IOException
327328 */
328- public void increment (int blockIndex ) throws IOException {
329+ public void increment (int blockIndex , int value ) throws IOException {
329330 validateBlock (blockIndex );
330331 checkConnected ();
331332
332- byte [] cmd = { (byte ) 0xC1 , (byte ) blockIndex };
333+ ByteBuffer cmd = ByteBuffer .allocate (6 );
334+ cmd .put ( (byte ) 0xC1 );
335+ cmd .put ( (byte ) blockIndex );
336+ cmd .putInt (value ); // ByteBuffer does the correct big endian translation
333337
334- transceive (cmd , false );
338+ transceive (cmd . array () , false );
335339 }
336340
337341 /**
338342 * Decrement a value block, and store the result in temporary memory.
339- * @param block
343+ * @param blockIndex
340344 * @throws IOException
341345 */
342- public void decrement (int blockIndex ) throws IOException {
346+ public void decrement (int blockIndex , int value ) throws IOException {
343347 validateBlock (blockIndex );
344348 checkConnected ();
345349
346- byte [] cmd = { (byte ) 0xC0 , (byte ) blockIndex };
350+ ByteBuffer cmd = ByteBuffer .allocate (6 );
351+ cmd .put ( (byte ) 0xC0 );
352+ cmd .put ( (byte ) blockIndex );
353+ cmd .putInt (value ); // ByteBuffer does the correct big endian translation
347354
348- transceive (cmd , false );
355+ transceive (cmd . array () , false );
349356 }
350357
351358 /**
352359 * Copy from temporary memory to value block.
353- * @param block
360+ * @param blockIndex
354361 * @throws IOException
355362 */
356363 public void transfer (int blockIndex ) throws IOException {
@@ -364,7 +371,7 @@ public void transfer(int blockIndex) throws IOException {
364371
365372 /**
366373 * Copy from value block to temporary memory.
367- * @param block
374+ * @param blockIndex
368375 * @throws IOException
369376 */
370377 public void restore (int blockIndex ) throws IOException {
0 commit comments