public class MifarePlusSL3 extends TagTechBase
{@code Example Usage: public class MainActivity extends Activity implements EMDKListener { SecureNfcManager secureNfcManager; EMDKManager emdkManager; SamType samType; MifarePlusSL3 mifarePlusSl3;
Modifier and Type | Method and Description |
---|---|
void |
decrement(boolean macOnResponse,
short blockNumber,
int value)
Decrements contents of given value block by specified value and stores
result in transfer buffer.
|
void |
decrementTransfer(boolean macOnResponse,
short srcblockNumber,
short destBlockNumber,
int value)
Performs combined operation of decrement() and transfer() on specified
value block.
|
void |
disable()
Disables I/O operations to the tag from IsoDep object, closes connection
to SAM, and releases resources.
|
void |
enable(android.nfc.Tag tag)
Enable I/O operations to the tag from IsoDep object and SAM
communication.
|
byte[] |
firstAuthentication(short keyBlockNo,
SamKey samkey,
byte[] samDiverseParams,
byte[] pcdCap2)
Performs 'First authentication' on specified block number using SAM key.
|
void |
followingAuthentication(short keyBlockNo,
SamKey samkey,
byte[] samDiverseParams)
Performs 'Following authentication' on specified block number using SAM
key.
|
void |
increment(boolean macOnResponse,
short blockNumber,
int value)
Increments contents of given value block by specified value and stores
result in transfer buffer.
|
void |
incrementTransfer(boolean macOnResponse,
short srcblockNumber,
short destBlockNumber,
int value)
Performs combined operation of increment() and transfer() on specified
value block.
|
boolean |
isEnabled()
Checks if the connection with the tag is enabled or not.This is a
synchronous call.
|
boolean |
isValueBlock(boolean macOnResponse,
short blockNumber)
Validates whether specified block is value block or not.This call should
be preceded with the first authentication.
|
byte[] |
readBlock(boolean isEncrypted,
boolean macOnCmd,
boolean macOnResponse,
short blockNumber,
short numOfBlocks)
Reads specified number of blocks starting from specified block number.
|
int |
readValue(boolean encrypted,
boolean macOnCmd,
boolean macOnResponse,
short blockNumber)
Reads value from specified value block.This call should be preceded with
the first authentication.
|
void |
resetAuthentication()
Resets authentication status of card.
|
void |
restore(boolean macOnResponse,
short blockNumber)
Restores transfer buffer i.e.
|
void |
transfer(boolean macOnResponse,
short blockNumber)
Transfers contents of value block stored in transfer buffer to specified
block.
|
void |
writeBlock(boolean encrypted,
boolean macOnResponse,
short blockNo,
byte[] blockData)
Writes specified number of blocks starting from specified block number.
|
void |
writeValue(boolean encrypted,
boolean macOnResponse,
short blockNumber,
int value)
Writes value to a specified value block.This call should be preceded with
the first authentication.
|
public void enable(android.nfc.Tag tag) throws MifarePlusSL3Exception
tag
- Contactless tag already detected by device. We get this
through the EXTRA_TAG information from the intent.MifarePlusSL3Exception
- The exception will be thrown if it fails to enable the tag.public void disable() throws MifarePlusSL3Exception
MifarePlusSL3Exception
- The exception will be thrown if it fails to disable the tag.public byte[] firstAuthentication(short keyBlockNo, SamKey samkey, byte[] samDiverseParams, byte[] pcdCap2) throws MifarePlusSL3Exception
This is an I/O operation and will block until complete. It must not be called from the main application thread.
keyBlockNo
- Key Block Number of the block to be authenticated.(range
0x4000 to 0x404F depending card size). keyBlockNo represent a
key in the card which is the same key that SamKey represent in
the SAM.samkey
- SAM key to be used for authentication. Only AES key should be
used.samDiverseParams
- Diversification parameters for current key. If present, then
valid length of this parameter is between 1 to 31 bytes. If
diversification is not required by current key then this
parameter should be NULL. This parameter is not supported
currently,application should pass null.pcdCap2
- Capabilities of PCD. If present, then valid length of this
parameter is between 1 to 6 bytes, where all bytes should be
0x00. Values other than 0x00 are reserved for future use. If
PCD capabilities are not required then this parameter should
be NULL.MifarePlusSL3Exception
- The exception will be thrown if it fails to perform firstAuthentication on the tag.
{@code Example Usage: SamKey lSamKey = new SamKey(); lSamKey.keyNum = 0x10; lSamKey.keyVer = 0x00; mifarePlusSl3.firstAuthentication(blockNo_of_the_key,lSamKey, null, null);
public void followingAuthentication(short keyBlockNo, SamKey samkey, byte[] samDiverseParams) throws MifarePlusSL3Exception
This is an I/O operation and will block until complete. It must not be called from the main application thread.
keyBlockNo
- Key Block Number of the block to be authenticated.(range
0x4000 to 0x404F depending card size) . keyBlockNo represent a
key in the card which is the same key that SamKey represent in
the SAM.samkey
- SAM key to be used for authentication. Only AES key should be
used.samDiverseParams
- Diversification parameters for current key. If present, then
valid length of this parameter is between 1 to 31 bytes. If
diversification is not required by current key then this
parameter should be NULL. This parameter is not supported
currently, there application should pass null.MifarePlusSL3Exception
- The exception will be thrown if it fails to perform followingAuthentication on the tag.
{@code Example Usage: SamKey lSamKey = new SamKey(); lSamKey.keyNum = 0x10; lSamKey.keyVer = 0x00; byte[] rawdata = mifarePlusSl3.firstAuthentication( blockNo_of_the_key, lSamKey, null, null); mifarePlusSl3,followingAuthentication( blockNo_of_the_key, lSamKey, null);
public void resetAuthentication() throws MifarePlusSL3Exception
This is an I/O operation and will block until complete. It must not be called from the main application thread.
MifarePlusSL3Exception
- The exception will be thrown if it fails to perform resetAuthentication on the tag.public byte[] readBlock(boolean isEncrypted, boolean macOnCmd, boolean macOnResponse, short blockNumber, short numOfBlocks) throws MifarePlusSL3Exception
isEncrypted
- false: Communication between device and card will be plain
true: Communication between device and card will be encryptedmacOnCmd
- false: Command sent to card will not be MACed true: Command
sent to card will be MACedmacOnResponse
- false: Response received from card will not be MACed true:
Response received from card will be MACedblockNumber
- Card block number from which multiple blocks have to be read.
(range 0x00 to 0xFF depending card size)numOfBlocks
- Number of blocks to be read. Maximum of 216 blocks can be
read, which excludes sector trailer.MifarePlusSL3Exception
- The exception will be thrown if it fails to read the data from the block.
Note: 1. The specified blocks must be authenticated before
calling the read, otherwise the read will fail. 2. If
specified blocks are located in different sectors and are not
authenticated with same key, then also read will fail. 3.
Mifare Plus S tag supports only below values of parameters
(as per datasheet): encrypted: false macOnCmd: true
macOnResponse: true 4. Parameter macOnCmd: Value false is not
allowed for Mifare Plus X, hence user should pass true.
{@code Example Usage: SamKey lSamKey = new SamKey(); lSamKey.keyNum = 0x10; lSamKey.keyVer = 0x00; mifarePlusSl3.firstAuthentication( blockNo_of_the_key, lSamKey, null, null); byte[] data = mifarePlusSl3.readBlock(true, true, true, BLOCK_NO, NumberOfBlocksToBeRead);
public void writeBlock(boolean encrypted, boolean macOnResponse, short blockNo, byte[] blockData) throws MifarePlusSL3Exception
encrypted
- false: Communication between device and card will be plain
true: Communication between device and card will be encryptedmacOnResponse
- false: Response received from card will not be MACed true:
Response received from card will be MACedblockNo
- Card block number from which multiple blocks have to be
written(range 0x00 to 0xFF depending card size)blockData
- Data to be written. Maximum of upto 3 blocks can be written,
length of data to be written can either be 16/32/48 bytes.MifarePlusSL3Exception
- The exception will be thrown if it fails to write the data to the block.
Note: 1. The specified blocks must be authenticated before
calling the write, otherwise the write will fail. 2. If
specified blocks are located in different sectors and are not
authenticated with same key, then also write will fail. 3.
Mifare Plus S tag supports only below values of parameters
(as per datasheet): encrypted: false macOnCmd: true macOnRsp:
true
{@code Example Usage: SamKey lSamKey = new SamKey(); lSamKey.keyNum = 0x10; lSamKey.keyVer = 0x00; mifarePlusSl3.firstAuthentication( blockNo_of_the_key, lSamKey, null, null); mifarePlusSl3.writeBlock(true, true, BLOCK_NO, dataToBeWritten);
public boolean isValueBlock(boolean macOnResponse, short blockNumber) throws MifarePlusSL3Exception
macOnResponse
- false: Response received from card will not be MACed true:
Response received from card will be MACedblockNumber
- Block number to be validatedMifarePlusSL3Exception
- The exception will be thrown if it fails to perform the value block check on the given block number.
{@code Example Usage: SamKey lSamKey = new SamKey(); lSamKey.keyNum = 0x10; lSamKey.keyVer = 0x00; mifarePlusSl3.firstAuthentication( blockNo_of_the_key, lSamKey, null, null); boolean value= mifarePlusSl3.isValueBlock(false,BLOCK_NO);
public int readValue(boolean encrypted, boolean macOnCmd, boolean macOnResponse, short blockNumber) throws MifarePlusSL3Exception
encrypted
- false: Communication between device and card will be plain
true: Communication between device and card will be encryptedmacOnCmd
- false: Command sent to card will not be MACed true: Command
sent to card will be MACedmacOnResponse
- false: Response received from card will not be MACed true:
Response received from card will be MACedblockNumber
- Card value block number to be read. (range 0x00 to 0xFF
depending card size)MifarePlusSL3Exception
- The exception will be thrown if it fails to read the value from the block.
Note: 1. If sector of specified value block is not already
authenticated then readValue will fail. 2. If specified block
is not value block then readValue will fail. 3. Mifare Plus S
tag supports only these values of parameters (as per
datasheet): encrypted: false macOnCmd: true macOnRsp: true
{@code Example Usage: SamKey lSamKey = new SamKey(); lSamKey.keyNum = 0x10; lSamKey.keyVer = 0x00; mifarePlusSl3.firstAuthentication( blockNo_of_the_key, lSamKey, null, null); int value = mifarePlusSl3.readValue(false, true, true, VALUE_BLOCK_NO);
public void writeValue(boolean encrypted, boolean macOnResponse, short blockNumber, int value) throws MifarePlusSL3Exception
encrypted
- false: Communication between device and card will be plain
true: Communication between device and card will be encryptedmacOnResponse
- false: Response received from card will not be MACed true:
Response received from card will be MACedblockNumber
- Card value block number to be written(range 0x00 to 0xFF
depending card size)value
- Value to be writtenMifarePlusSL3Exception
- The exception will be thrown if it fails to write the value to the block.
Note: 1. If sector of specified block is not already
authenticated then writeValue will fail. 2. This API should
be called when the specified data block to value block 3. To
perform operation on value block such as
increment(),incrementTransfer(),
decrementTransfer(),decrement(),transfer(),restore(), we need
to call API writeValue() first. 4. Mifare Plus S tag supports
only these values of parameters (as per datasheet):
encrypted: false macOnCmd: true macOnResponse: true.
{@code Example Usage: SamKey lSamKey = new SamKey(); lSamKey.keyNum = 0x10; lSamKey.keyVer = 0x00; mifarePlusSl3.firstAuthentication( blockNo_of_the_key, lSamKey, null, null); mifarePlusSl3.writeValue(false,true, VALUE_BLOCK_NO, Value_To_Be_Written);
public void increment(boolean macOnResponse, short blockNumber, int value) throws MifarePlusSL3Exception
macOnResponse
- false: Response received from card will not be MACed true:
Response received from card will be MACedblockNumber
- Card value block to be incremented(range 0x00 to 0xFF
depending card size)value
- Value to be incrementedMifarePlusSL3Exception
- The exception will be thrown if it fails to increment the value in the block.
Note: 1. If sector of specified value block is not already
authenticated then increment will fail. 2. If specified block
is not value block then increment will fail.
{@code Example Usage: SamKey lSamKey = new SamKey(); lSamKey.keyNum = 0x10; lSamKey.keyVer = 0x00; mifarePlusSl3.firstAuthentication( blockNo_of_the_key, lSamKey, null, null); mifarePlusSl3.increment(true,VALUE_BLOCK_NO, value); mifarePlusSl3.transfer(true,VALUE_BLOCK_NO);
public void decrement(boolean macOnResponse, short blockNumber, int value) throws MifarePlusSL3Exception
macOnResponse
- false: Response received from card will not be MACed true:
Response received from card will be MACedblockNumber
- Card value block to be decremented(range 0x00 to 0xFF
depending card size)value
- Value to be decrementedMifarePlusSL3Exception
- The exception will be thrown if it fails to decrement the value in the block.
Note: 1. If sector of specified value block is not already
authenticated then decrement will fail. 2. If specified block
is not value block then decrement will fail.public void restore(boolean macOnResponse, short blockNumber) throws MifarePlusSL3Exception
macOnResponse
- false: Response received from card will not be MACed true:
Response received from card will be MACedblockNumber
- Card value block to be decremented(range 0x00 to 0xFF
depending card size)MifarePlusSL3Exception
- The exception will be thrown if it fails to restore the value from the block to the transfer buffer.
Note: 1. If sector of specified value block is not already
authenticated then restore will fail. 2. If specified block
is not value block then restore will fail.public void transfer(boolean macOnResponse, short blockNumber) throws MifarePlusSL3Exception
macOnResponse
- false: Response received from card will not be MACed true:
Response received from card will be MACedblockNumber
- Card block whose contents is replaced by transfer buffer(range
0x00 to 0xFF depending card size).MifarePlusSL3Exception
- The exception will be thrown if it fails to transfer the value from the transferbuffer to the block.
Note: 1. If sector of specified value block is not already
authenticated then transfer will fail. 2. If specified block
is not value block then transfer will fail.public void incrementTransfer(boolean macOnResponse, short srcblockNumber, short destBlockNumber, int value) throws MifarePlusSL3Exception
macOnResponse
- false: Response received from card will not be MACed true:
Response received from card will be MACedsrcblockNumber
- Source block for incrementdestBlockNumber
- Destination block for transfervalue
- Value to be addedMifarePlusSL3Exception
- The exception will be thrown if it fails to do incrementTransfer on the block.
Note: 1. If sector of specified value block is not already
authenticated then API will fail. 2. If source block is not
value block then API will fail.
{@code Example Usage: SamKey lSamKey = new SamKey(); lSamKey.keyNum = 0x10; lSamKey.keyVer = 0x00; mifarePlusSl3.firstAuthentication( blockNo_of_the_key, lSamKey, null, null); mifarePlusSl3.incrementTransfer(true, VALUE_BLOCK_NO, VALUE_BLOCK_NO value);
public void decrementTransfer(boolean macOnResponse, short srcblockNumber, short destBlockNumber, int value) throws MifarePlusSL3Exception
macOnResponse
- false: Response received from card will not be MACed true:
Response received from card will be MACedsrcblockNumber
- Source block for incrementdestBlockNumber
- Destination block for transfervalue
- Value to be subtractedMifarePlusSL3Exception
- The exception will be thrown if it fails to do decrementTransfer on the block.
Note: 1. If sector of specified value block is not already
authenticated then API will fail. 2. If source block is not
value block then API will fail.public boolean isEnabled() throws MifarePlusSL3Exception
MifarePlusSL3Exception
- The exception will be thrown if the emdk is not opened.