summaryrefslogtreecommitdiffstats
path: root/core/java/android/nfc/tech
diff options
context:
space:
mode:
authorNick Pelly <npelly@google.com>2011-01-25 07:45:07 -0800
committerNick Pelly <npelly@google.com>2011-01-25 07:45:07 -0800
commitb134223f91c8801d577cb72e92a37cb65fec717a (patch)
treee5837efbb3306dca2f31e899d938b1baae9d09d2 /core/java/android/nfc/tech
parentcc019c0caa0dd984404dea4d6623ae9d7b8474f1 (diff)
downloadframeworks_base-b134223f91c8801d577cb72e92a37cb65fec717a.zip
frameworks_base-b134223f91c8801d577cb72e92a37cb65fec717a.tar.gz
frameworks_base-b134223f91c8801d577cb72e92a37cb65fec717a.tar.bz2
Make Mifare Classic increment/decrement operands little endian
Also make sure they are non-negative. This is not documented in Mifare Classic spec, but based on findings from NXP: - Operand should be stored in little-endian format in the transceive buffer - Tag ignores the sign bit on the operand, its effectively 31-bit unsigned - Overflow and underflow generates an error. Change-Id: Id3389b3894ded732c4b00d564ca53f5df651359e
Diffstat (limited to 'core/java/android/nfc/tech')
-rw-r--r--core/java/android/nfc/tech/MifareClassic.java15
1 files changed, 13 insertions, 2 deletions
diff --git a/core/java/android/nfc/tech/MifareClassic.java b/core/java/android/nfc/tech/MifareClassic.java
index 1b383f1..34fd7cf 100644
--- a/core/java/android/nfc/tech/MifareClassic.java
+++ b/core/java/android/nfc/tech/MifareClassic.java
@@ -22,6 +22,7 @@ import android.os.RemoteException;
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
/**
* Technology class representing MIFARE Classic tags (also known as MIFARE Standard).
@@ -328,12 +329,14 @@ public final class MifareClassic extends BasicTagTechnology {
*/
public void increment(int blockIndex, int value) throws IOException {
validateBlock(blockIndex);
+ validateValueOperand(value);
checkConnected();
ByteBuffer cmd = ByteBuffer.allocate(6);
+ cmd.order(ByteOrder.LITTLE_ENDIAN);
cmd.put( (byte) 0xC1 );
cmd.put( (byte) blockIndex );
- cmd.putInt(value); // ByteBuffer does the correct big endian translation
+ cmd.putInt(value);
transceive(cmd.array(), false);
}
@@ -345,16 +348,24 @@ public final class MifareClassic extends BasicTagTechnology {
*/
public void decrement(int blockIndex, int value) throws IOException {
validateBlock(blockIndex);
+ validateValueOperand(value);
checkConnected();
ByteBuffer cmd = ByteBuffer.allocate(6);
+ cmd.order(ByteOrder.LITTLE_ENDIAN);
cmd.put( (byte) 0xC0 );
cmd.put( (byte) blockIndex );
- cmd.putInt(value); // ByteBuffer does the correct big endian translation
+ cmd.putInt(value);
transceive(cmd.array(), false);
}
+ private void validateValueOperand(int value) {
+ if (value < 0) {
+ throw new IllegalArgumentException("value operand negative");
+ }
+ }
+
/**
* Copy from temporary memory to value block.
* @param blockIndex