|
Nokia Extensions for JSR-257 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.nokia.nfc.nxp.mfstd.MFAccessBits
public class MFAccessBits
A class for handling Mifare Standard card's access bits.
Access to certain block - either data or trailer - is defined using access bits
C1
, C2
and C3
. Combination of these bits
define what operations are allowed and which keys should be used during
these operations.
This class provides separate methods for setting trailer block and data block access conditions. For specifying data block access conditions only the indices 0 to 2 are allowed. For the last 8 Mifare Standard 4k sectors the access conditions are defined in units of 5 blocks. So the block index 0 defines access conditions for the data blocks 0-4, block index 1 for data blocks 5-9 and block index 2 for data blocks 10-14.
Detailed description of access conditions and bit combinations can be found from Mifare Standard Card Data sheets.
Field Summary | |
---|---|
static int |
C1
The constant corresponding to access bit C1. |
static int |
C2
The constant corresponding to access bit C2. |
static int |
C3
The constant corresponding to access bit C3. |
static int |
KEY_A
Authentication key type A. |
static int |
KEY_B
Authentication key type B. |
Constructor Summary | |
---|---|
MFAccessBits()
Creates a MFAccessBits instance so that the access bits are in transport configuration: for data blocks all access bits (C1, C2, C3) are 0 and the trailer access bits are 0, 0 and 1. |
|
MFAccessBits(byte[] accessBits)
Creates a MFAccessBits instance based on the given access bit bytes. |
|
MFAccessBits(byte[] accessBits,
int offset)
Creates a MFAccessBits instance based on the given access bit bytes. |
|
MFAccessBits(int accessBits)
Creates a MFAccessBits instance based on the given access bits. |
Method Summary | |
---|---|
boolean |
canDecrement(int keyType,
int blockIndex)
Tests whether the access conditions are set so that with a authentication key of type keyType one can
decrement the value in block defined by blockIndex . |
boolean |
canIncrement(int keyType,
int blockIndex)
Tests whether the access conditions are set so that with a authentication key of type keyType one can
increment the value in block defined by blockIndex . |
boolean |
canRead(int keyType,
int blockIndex)
Tests whether the access conditions are set so that with a authentication key of type keyType one can read
data from the block defined by blockIndex . |
boolean |
canReadAccessBits(int keyType)
Tests whether the access conditions are set so that with a authentication key of type keyType one can
read the access bits from sector trailer. |
boolean |
canReadKeyA(int keyType)
Tests whether the access conditions are set so that with a authentication key of type keyType one can
read the Key A from sector trailer. |
boolean |
canReadKeyB(int keyType)
Tests whether the access conditions are set so that with a authentication key of type keyType one can
read the Key A from sector trailer. |
boolean |
canRestore(int keyType,
int blockIndex)
Tests whether the access conditions are set so that with a authentication key of type keyType one can
restore the value from block defined by blockIndex . |
boolean |
canTransfer(int keyType,
int blockIndex)
Tests whether the access conditions are set so that with a authentication key of type keyType one can
transfer the value to block defined by blockIndex . |
boolean |
canWrite(int keyType,
int blockIndex)
Tests whether the access conditions are set so that with a authentication key of type keyType one can write
data to block defined by blockIndex . |
boolean |
canWriteAccessBits(int keyType)
Tests whether the access conditions are set so that with a authentication key of type keyType one can
read the access bits from sector trailer. |
boolean |
canWriteKeyA(int keyType)
Tests whether the access conditions are set so that with a authentication key of type keyType one can
write the Key A in sector trailer. |
boolean |
canWriteKeyB(int keyType)
Tests whether the access conditions are set so that with a authentication key of type keyType one can
write the Key B in sector trailer. |
boolean |
equals(java.lang.Object obj)
Tests if the given object equal to this object. |
int |
getAccessBitsForBlock(int blockIndex)
Returns access bits for specified block. |
int |
hashCode()
Returns a hashcode for this MFAccessBits object. |
void |
setAccessBitsForBlock(boolean c1,
boolean c2,
boolean c3,
int blockIndex)
Sets the access bits for the specified data block(s). |
void |
setAccessBitsForBlock(int accessBits,
int blockIndex)
Sets the access bits for the specified data block(s). |
void |
setAccessBitsForDataBlocks(boolean c1,
boolean c2,
boolean c3)
Sets the access bits for all data blocks. |
void |
setAccessBitsForTrailer(boolean c1,
boolean c2,
boolean c3)
Sets the accessbits for the sector trailer block. |
byte[] |
toByteArray()
Returns the defined access bits as a byte array that can be used for writing the sector trailer. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int KEY_A
public static final int KEY_B
public static final int C1
public static final int C2
public static final int C3
Constructor Detail |
---|
public MFAccessBits()
public MFAccessBits(byte[] accessBits)
accessBits
array are read as
the sixth, seventh and eight byte of the sector trailer.
accessBits
- the access bit bytes.
java.lang.NullPointerException
- if the accessBits
array is null
.
java.lang.ArrayIndexOutOfBoundsException
- if the array length is less than 3.
java.lang.IllegalArgumentException
- if the access bits are not set correctly.public MFAccessBits(byte[] accessBits, int offset)
offset
of the
accessBits
array are read as the sixth, seventh and
eight byte of the sector trailer.
accessBits
- the access bit bytes.offset
- the index of the first access bit byte in the array.
java.lang.NullPointerException
- if the accessBits
array is null
.
java.lang.ArrayIndexOutOfBoundsException
- if the offset
is
< 0
or > accessBits.length-3
.
java.lang.IllegalArgumentException
- if the access bits are not set correctly.public MFAccessBits(int accessBits)
accessBits
- the access bits as a integer.
java.lang.IllegalArgumentException
- if the access bits are not set correctly.Method Detail |
---|
public byte[] toByteArray()
public int getAccessBitsForBlock(int blockIndex)
C1
, C2
and C3
.
blockIndex
- index of the block.
java.lang.IllegalArgumentException
- if the blockIndex
is not valid.public void setAccessBitsForBlock(int accessBits, int blockIndex)
accessBits
value must be a bitmask that is a combination
of C1
, C2
and C3
.
accessBits
- a bitmask defining the access bits.blockIndex
- index of the block.
java.lang.IllegalArgumentException
- if the blockIndex
is not valid.public void setAccessBitsForBlock(boolean c1, boolean c2, boolean c3, int blockIndex)
c1
- the access bit C1.c2
- the access bit C2.c3
- the access bit C3.blockIndex
- index of the block.
java.lang.IllegalArgumentException
- if the blockIndex
is not valid.public void setAccessBitsForDataBlocks(boolean c1, boolean c2, boolean c3)
c1
- the access bit C1.c2
- the access bit C2.c3
- the access bit C3.public void setAccessBitsForTrailer(boolean c1, boolean c2, boolean c3)
c1
- the access bit C1.c2
- the access bit C2.c3
- the access bit C3.public boolean canWrite(int keyType, int blockIndex)
keyType
one can write
data to block defined by blockIndex
. For the trailer
this method will always return false
.
keyType
- the authentication key type.blockIndex
- index of the block.
true
if data can be written and false
if not.public boolean canRead(int keyType, int blockIndex)
keyType
one can read
data from the block defined by blockIndex
. For the trailer
this method will always return false
.
keyType
- the authentication key type.blockIndex
- index of the block.
true
if data can be read and false
if not.public boolean canIncrement(int keyType, int blockIndex)
keyType
one can
increment the value in block defined by blockIndex
.
For the trailer this method will always return false
.
keyType
- the authentication key type.blockIndex
- index of the block.
true
if data can be written and false
if not.public boolean canDecrement(int keyType, int blockIndex)
keyType
one can
decrement the value in block defined by blockIndex
.
For the trailer this method will always return false
.
keyType
- the authentication key type.blockIndex
- index of the block.
true
if data can be written and false
if not.public boolean canTransfer(int keyType, int blockIndex)
keyType
one can
transfer the value to block defined by blockIndex
.
For the trailer this method will always return false
.
keyType
- the authentication key type.blockIndex
- index of the block.
true
if data can be written and false
if not.public boolean canRestore(int keyType, int blockIndex)
keyType
one can
restore the value from block defined by blockIndex
.
For the trailer this method will always return false
.
keyType
- the authentication key type.blockIndex
- index of the block.
true
if data can be written and false
if not.public boolean canReadKeyA(int keyType)
keyType
one can
read the Key A from sector trailer. This method always returns false
keyType
- the authentication key type.
false
as reading Key A is never allowed.public boolean canWriteKeyA(int keyType)
keyType
one can
write the Key A in sector trailer.
keyType
- the authentication key type.
true
if Key A can be written and false
if not.public boolean canReadKeyB(int keyType)
keyType
one can
read the Key A from sector trailer.
keyType
- the authentication key type.
true
if Key B can be read and false
if not.public boolean canWriteKeyB(int keyType)
keyType
one can
write the Key B in sector trailer.
keyType
- the authentication key type.
true
if Key B can be written and false
if not.public boolean canReadAccessBits(int keyType)
keyType
one can
read the access bits from sector trailer. Access bits can always
be read with Key A.
keyType
- the authentication key type.
true
if access bits can be read and false
if not.public boolean canWriteAccessBits(int keyType)
keyType
one can
read the access bits from sector trailer. Access bits can always
be read with Key A.
keyType
- the authentication key type.
true
if access bits can be read and false
if not.public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
true
if the objects are equal and false
if not.public int hashCode()
hashCode
in class java.lang.Object
Object.hashCode()
|
Nokia Extensions for JSR-257 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |