Nokia Extensions for JSR-257

com.nokia.nfc.nxp.mfstd
Interface MFBlock

All Superinterfaces:
MFDataArea
All Known Subinterfaces:
MFManufacturerBlock, MFSectorTrailer

public interface MFBlock
extends MFDataArea

Base interface for handling Mifare Standard card blocks. There are three supported block types:

Note that when managing value blocks there is no separate transfer method for writing the internal data register to a block. The increment(MFKey, int) and decrement(MFKey, int) method do this automatically.

See Also:
MFDataArea, MFManufacturerBlock, MFSectorTrailer

Field Summary
static int BLOCK_LEN
          Length of a block in bytes.
static int BLOCKTYPE_DATA
          Data block type.
static int BLOCKTYPE_MANUFACTURER
          Manufacturer block type.
static int BLOCKTYPE_TRAILER
          Sector trailer block type.
static int MAX_DIFF
          Maximum value for a decrement or increment operation.
static int MIN_DIFF
          Minimum value for a decrement or increment operation.
 
Method Summary
 int copyFrom(MFKey key, int blockNo)
          Copies the contents of the specified value block to this block.
 int copyTo(MFKey key, int blockNo)
          Copies the value contents of this block to the specified value block.
 int decrement(MFKey key, int decrement)
          Decrements the value by an amount specified by the given positive integer decrement.
 int getBlockIndex()
          Returns the index of this block within the sector.
 int getBlockType()
          Returns the type of this block.
 int increment(MFKey key, int increment)
          Increments the value by an amount specified by the given positive integer increment.
 boolean isValueBlock(MFKey key)
          Returns true if this block is a data block which is formatted as a value block.
 MFValue readValue(MFKey key)
          Reads the block as a value block and returns the contents as a MFValue object.
 void writeValue(MFKey key, MFValue newValue)
          Writes the value specified by newValue to a value block.
 
Methods inherited from interface com.nokia.nfc.nxp.mfstd.MFDataArea
read, size, toString, write, write
 

Field Detail

MIN_DIFF

static final int MIN_DIFF
Minimum value for a decrement or increment operation.

See Also:
Constant Field Values

MAX_DIFF

static final int MAX_DIFF
Maximum value for a decrement or increment operation.

See Also:
Constant Field Values

BLOCK_LEN

static final int BLOCK_LEN
Length of a block in bytes.

See Also:
Constant Field Values

BLOCKTYPE_TRAILER

static final int BLOCKTYPE_TRAILER
Sector trailer block type. Indicates that this block object is an instance of the MFSectorTrailer class.

See Also:
Constant Field Values

BLOCKTYPE_MANUFACTURER

static final int BLOCKTYPE_MANUFACTURER
Manufacturer block type. Indicates that this block object is an instance of the MFManufacturerBlock class.

See Also:
Constant Field Values

BLOCKTYPE_DATA

static final int BLOCKTYPE_DATA
Data block type. Indicates that this block is intended for storing data.

See Also:
Constant Field Values
Method Detail

getBlockType

int getBlockType()
Returns the type of this block. The return value is one of the following values:

Returns:
the type of this block.

getBlockIndex

int getBlockIndex()
Returns the index of this block within the sector. The return values range from 0 to MFSector.getBlockCount() - 1.

Returns:
the index of this block.

isValueBlock

boolean isValueBlock(MFKey key)
                     throws MFStandardException,
                            java.io.IOException
Returns true if this block is a data block which is formatted as a value block.

Parameters:
key - the authentication key. If null then the device's default keys are used.
Returns:
true if this block is a value block and false if it is not.
Throws:
MFStandardException - if authentication fails.
java.io.IOException - if a connection error occurs.

readValue

MFValue readValue(MFKey key)
                  throws MFStandardException,
                         java.io.IOException
Reads the block as a value block and returns the contents as a MFValue object. If the block is not a value block then null is returned.

Parameters:
key - the authentication key. If null then the device's default keys are used.
Returns:
either a MFValue object or null
Throws:
MFStandardException - if authentication fails.
java.io.IOException - if a connection error occurs.

writeValue

void writeValue(MFKey key,
                MFValue newValue)
                throws MFStandardException,
                       java.io.IOException
Writes the value specified by newValue to a value block. The block will be formatted as a value block if it isn't already.

Parameters:
key - the authentication key. If null then the device's default keys are used.
newValue - new value block contents
Throws:
MFStandardException - if authentication fails.
java.io.IOException - if a connection error occurs.
java.lang.NullPointerException - if newValue is null.

increment

int increment(MFKey key,
              int increment)
              throws MFStandardException,
                     java.io.IOException
Increments the value by an amount specified by the given positive integer increment. Valid values for increment range from 0 to 2147483647.

Parameters:
key - the authentication key. If null then the device's default keys are used.
increment - the amount to increment the existing value.
Returns:
the new value of this block.
Throws:
MFStandardException - if authentication fails or if the block is not a value block or if the increment was too large.
java.io.IOException - if a connection error occurs.
java.lang.IllegalArgumentException - if the increment is not valid.

decrement

int decrement(MFKey key,
              int decrement)
              throws MFStandardException,
                     java.io.IOException
Decrements the value by an amount specified by the given positive integer decrement. Valid values for decrement range from 0 to 2147483647.

Parameters:
key - the authentication key. If null then the device's default keys are used.
decrement - the amount to increment the existing value.
Returns:
the new value of this block.
Throws:
MFStandardException - if authentication fails or if the block is not a value block or if the decrement was too large.
java.io.IOException - if a connection error occurs.
java.lang.IllegalArgumentException - if the decrement is not valid.

copyTo

int copyTo(MFKey key,
           int blockNo)
           throws MFStandardException,
                  java.io.IOException

Copies the value contents of this block to the specified value block. If the specified block, blockNo, points to the same block as this MFBlock object represents then an MFStandardException is thrown.

This operation combines the transfer/restore functionality: first execute restore and then transfer.

Note that only one authentication key can be specified. If the source and destination blocks are in different sectors then the specified authentication key will be used for both sectors.

Parameters:
key - the authentication key. If null then the device's default keys are used.
blockNo - the block index to where the content should be transferred to.
Returns:
the new value of the specified block.
Throws:
MFStandardException - if authentication fails or if this block is not a value block.
java.io.IOException - if a connection error occurs.
java.lang.IllegalArgumentException - if the blockNo is not valid.

copyFrom

int copyFrom(MFKey key,
             int blockNo)
             throws MFStandardException,
                    java.io.IOException

Copies the contents of the specified value block to this block. If the specified block, blockNo, points to the same block as this MFBlock object represents then an MFStandardException is thrown.

This operation combines the transfer/restore functionality: first execute transfer and then restore.

Note that only one authentication key can be specified. If the source and destination blocks are in different sectors then the specified authentication key will be used for both sectors.

Parameters:
key - the authentication key. If null then the device's default keys are used.
blockNo - the block index to where the content should be transferred from.
Returns:
the new value of this block.
Throws:
MFStandardException - if authentication fails or if the source block is not a value block.
java.io.IOException - if a connection error occurs.
java.lang.IllegalArgumentException - if the blockNo is not valid.

Nokia Extensions for JSR-257

Copyright � 2010 Nokia Corporation. All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.