am b134223f: Make Mifare Classic increment/decrement operands little endian

* commit 'b134223f91c8801d577cb72e92a37cb65fec717a':
  Make Mifare Classic increment/decrement operands little endian
This commit is contained in:
Nick Pelly
2011-01-25 08:41:35 -08:00
committed by Android Git Automerger

View File

@@ -22,6 +22,7 @@ import android.os.RemoteException;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder;
/** /**
* Technology class representing MIFARE Classic tags (also known as MIFARE Standard). * 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 { public void increment(int blockIndex, int value) throws IOException {
validateBlock(blockIndex); validateBlock(blockIndex);
validateValueOperand(value);
checkConnected(); checkConnected();
ByteBuffer cmd = ByteBuffer.allocate(6); ByteBuffer cmd = ByteBuffer.allocate(6);
cmd.order(ByteOrder.LITTLE_ENDIAN);
cmd.put( (byte) 0xC1 ); cmd.put( (byte) 0xC1 );
cmd.put( (byte) blockIndex ); cmd.put( (byte) blockIndex );
cmd.putInt(value); // ByteBuffer does the correct big endian translation cmd.putInt(value);
transceive(cmd.array(), false); transceive(cmd.array(), false);
} }
@@ -345,16 +348,24 @@ public final class MifareClassic extends BasicTagTechnology {
*/ */
public void decrement(int blockIndex, int value) throws IOException { public void decrement(int blockIndex, int value) throws IOException {
validateBlock(blockIndex); validateBlock(blockIndex);
validateValueOperand(value);
checkConnected(); checkConnected();
ByteBuffer cmd = ByteBuffer.allocate(6); ByteBuffer cmd = ByteBuffer.allocate(6);
cmd.order(ByteOrder.LITTLE_ENDIAN);
cmd.put( (byte) 0xC0 ); cmd.put( (byte) 0xC0 );
cmd.put( (byte) blockIndex ); cmd.put( (byte) blockIndex );
cmd.putInt(value); // ByteBuffer does the correct big endian translation cmd.putInt(value);
transceive(cmd.array(), false); 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. * Copy from temporary memory to value block.
* @param blockIndex * @param blockIndex