Skip to content

Commit c896d85

Browse files
Nick PellyAndroid (Google) Code Review
authored andcommitted
Merge "Add operands to mifare classic increment, decrement." into gingerbread
2 parents da01b4a + 1e233af commit c896d85

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

api/current.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101305,6 +101305,8 @@
101305101305
>
101306101306
<parameter name="blockIndex" type="int">
101307101307
</parameter>
101308+
<parameter name="value" type="int">
101309+
</parameter>
101308101310
<exception name="IOException" type="java.io.IOException">
101309101311
</exception>
101310101312
</method>
@@ -101390,6 +101392,8 @@
101390101392
>
101391101393
<parameter name="blockIndex" type="int">
101392101394
</parameter>
101395+
<parameter name="value" type="int">
101396+
</parameter>
101393101397
<exception name="IOException" type="java.io.IOException">
101394101398
</exception>
101395101399
</method>

core/java/android/nfc/tech/MifareClassic.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import android.os.RemoteException;
2222

2323
import java.io.IOException;
24+
import java.nio.ByteBuffer;
2425

2526
/**
2627
* Technology class representing MIFARE Classic tags (also known as MIFARE Standard).
@@ -32,8 +33,8 @@
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
*/
3839
public 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

Comments
 (0)