public interface MifareUltralightCard extends MemoryCard
MifareUltralightCard
interface for Mifare UltraLight cards, also known as MF0, a type of memory card.
MIFARE Ultralight cards are divided into two main types:
Original MIFARE Ultralight (MF0ICU1):
- Consists of a 64-byte EEPROM.
- The first 4 blocks (OTP area, manufacturer data, and locking bits) are readable, with some bits writable.
- The next 12 blocks form the user read/write area.
- Refer to the NXP data sheet MF0ICU1 for more details.
MIFARE Ultralight C (MF0ICU2):
- Features a 192-byte EEPROM.
- The first 4 blocks include OTP, manufacturer data, and locking bits.
- Followed by 36 blocks as the user read/write area.
- The next 4 blocks contain additional locking bits, counters, and authentication configuration, all readable.
- The final 4 blocks are dedicated to the authentication key and are not readable.
- For further information, consult the NXP data sheet MF0ICU2.
PROTOCOL_RFCARD_TYPE_A, PROTOCOL_RFCARD_TYPE_B, PROTOCOL_T_0, PROTOCOL_T_1, PROTOCOL_UNKNOWN, STATUS_ABSENT, STATUS_CONNECTED, STATUS_DISCONNECTED
Modifier and Type | Method and Description |
---|---|
byte[] |
read(int blockIndex)
Reads 4 consecutive blocks (16 bytes) from a MIFARE Ultralight card.
|
byte[] |
transmit(byte[] apdu,
int operation)
Transmits a level 3 command to the card and receives the response.
|
boolean |
verifyKey(byte[] key)
Authenticates the card using a 16-byte key.
|
void |
write(int blockIndex,
byte[] data)
Writes data to a single block (4 bytes) on a MIFARE Ultralight card.
|
getCardStatus, getID, getIDInfo, getProtocol
byte[] read(int blockIndex) throws DeviceException
This method is designed to optimize the reading process by fetching 4 blocks in a single command, reducing the total number of commands needed to read the entire tag.
If the reading request extends beyond the last readable block, the card automatically wraps around to the beginning. For instance: - On a standard MIFARE Ultralight tag (blocks 0x00 to 0x0F), reading from block 0x0E returns blocks 0x0E, 0x0F, 0x00, and 0x01. - On a MIFARE Ultralight C tag (blocks 0x00 to 0x2B), reading from block 0x2A returns blocks 0x2A, 0x2B, 0x00, and 0x01.
blockIndex
- The index of the first block to read. Must be within the range of readable blocks for the specific card type.DeviceException
- for standard device-related errors as documented in DeviceException
.void write(int blockIndex, byte[] data) throws DeviceException
blockIndex
- The index of the block to be written.data
- The data to write, contained in a 4-byte array.DeviceException
- for standard device-related errors as documented in DeviceException
.boolean verifyKey(byte[] key) throws DeviceException
This method is an I/O operation and will block until completion. Note: Do not call from the main application thread to avoid blocking it. If 'close()' is called from another thread, a blocked call will be canceled with IOException.
key
- The 16-byte authentication key.DeviceException
- for standard device-related errors as documented in DeviceException
.byte[] transmit(byte[] apdu, int operation) throws DeviceException
This method sends an APDU command and returns the card's response. The operation parameter sets the command mode (default 0, set to 16 to disable CRC and parity). Note: Throws an exception if the card's power state is not ON.
apdu
- The data buffer for the command.operation
- The operation mode for the command.DeviceException
- for standard device-related errors as documented in DeviceException
.