public class Rc522
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static byte |
AUTH_A
Authentication using Key A
|
static byte |
AUTH_B
Authentication using Key B
|
| Constructor and Description |
|---|
Rc522(android.content.Context context,
com.google.android.things.pio.SpiDevice spiDevice,
com.google.android.things.pio.Gpio resetPin)
Deprecated.
use
Rc522(SpiDevice, Gpio) instead. |
Rc522(com.google.android.things.pio.SpiDevice spiDevice,
com.google.android.things.pio.Gpio resetPin)
Initializes RC522 with the configured SPI port and pins.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
antiCollisionDetect()
Checks for collision errors
|
boolean |
authenticateCard(byte authMode,
byte address,
byte[] key)
Authenticates the use of a specific address.
|
boolean |
authenticateCard(byte authMode,
byte address,
byte[] key,
byte[] uid)
Deprecated.
use
authenticateCard(byte, byte, byte[]) instead |
static byte[] |
calculateAccessBits(byte[][] accessConditions)
Calculates the access bits for a sector trailer (bytes 6 to 7) based on Table 6 and Table 7
on MIFARE 1k's reference
|
static byte[] |
calculateAccessBits(byte[] c1,
byte[] c2,
byte[] c3)
Calculates the access bits for a sector trailer (bytes 6 to 7) based on Table 6 and Table 7
on MIFARE 1k's reference
|
static byte[][] |
calculateAccessConditions(byte[] accessBits)
Calculates the individual access conditions given the access bits
|
static java.lang.String |
dataToHexString(byte[] data)
Converts a data byte array to a string representing its 16 bytes in hexadecimal
|
boolean |
decreaseBlock(byte address,
int operand)
Decreases the value of a block by the specified operand.
|
java.lang.String |
dumpMifare1k()
Dumps all the data in all data blocks in MIFARE 1K cards with default authentication keys.
|
static byte |
getBlockAddress(byte sector,
byte block)
MIFARE tags blocks are organized in sectors, this calculates the address of a block in a
specific sector
|
static byte |
getBlockAddress(int sector,
int block)
MIFARE tags blocks are organized in sectors, this calculates the address of a block in a
specific sector
|
byte[] |
getUid()
Gets the UID of the last card that was successfully read.
|
java.lang.String |
getUidString()
Returns a string representation of the last read tag's UID, separated by '-'
|
java.lang.String |
getUidString(java.lang.String separator)
Returns a string representation of the last read tag's UID
|
byte[] |
getUuid()
Deprecated.
Method renamed, use
getUid() instead |
boolean |
increaseBlock(byte address,
int operand)
Increases the value of a block by the specified operand.
|
byte[] |
readBlock(byte address)
Deprecated.
Use
readBlock(byte, byte[]) as it can report read status |
boolean |
readBlock(byte address,
byte[] buffer)
Reads the current data stored in the tag's block.
|
java.lang.Integer |
readValue(byte address)
Reads a value block and converts the stored value
|
boolean |
request()
Requests for a tag
|
boolean |
request(byte requestMode)
Requests for a tag
|
boolean |
restoreBlock(byte address)
Writes on the transfer buffer the contents of a value block
|
boolean |
selectTag(byte[] uid)
Selects the tag to be used in following operations
|
void |
setDebugging(boolean debugging) |
void |
stopCrypto()
Ends operations that use crypto and cleans up
|
boolean |
transferBlock(byte address)
Writes the contents of the transfer buffer to a block
|
boolean |
write(byte address,
byte[] data)
Deprecated.
renamed to
writeBlock(byte, byte[]). |
boolean |
writeBlock(byte address,
byte[] data)
Writes data to a block in the tag.
|
boolean |
writeTrailer(byte sector,
byte[] keyA,
byte[] accessBits,
byte userData,
byte[] keyB)
Writes a sector's trailer's data.
|
boolean |
writeValue(byte address,
int value)
Writes a 32-bit signed integer to a value block in the required format
The format is specified in section 8.6.2.1 in MIFARE 1k's datasheet
Tag must be selected and block authenticated
|
public static final byte AUTH_A
public static final byte AUTH_B
@Deprecated
public Rc522(android.content.Context context,
com.google.android.things.pio.SpiDevice spiDevice,
com.google.android.things.pio.Gpio resetPin)
throws java.io.IOException
Rc522(SpiDevice, Gpio) instead.context - Parameter no longer used, use Rc522(SpiDevice, Gpio) instead.spiDevice - SPI port used on the boardresetPin - Pin connected to the RST pin on the RC522java.io.IOExceptionpublic Rc522(com.google.android.things.pio.SpiDevice spiDevice,
com.google.android.things.pio.Gpio resetPin)
throws java.io.IOException
spiDevice - SPI port used on the boardresetPin - Pin connected to the RST pin on the RC522java.io.IOExceptionpublic void setDebugging(boolean debugging)
public byte[] getUid()
@Deprecated public byte[] getUuid()
getUid() insteadpublic java.lang.String getUidString(java.lang.String separator)
separator - The character that separates each element of the uidpublic java.lang.String getUidString()
public boolean request()
public boolean request(byte requestMode)
requestMode - the type of request being madepublic boolean antiCollisionDetect()
public boolean selectTag(byte[] uid)
uid - Byte array containing the tag's uidpublic boolean authenticateCard(byte authMode,
byte address,
byte[] key)
@Deprecated
public boolean authenticateCard(byte authMode,
byte address,
byte[] key,
byte[] uid)
authenticateCard(byte, byte, byte[]) insteadpublic void stopCrypto()
public boolean readBlock(byte address,
byte[] buffer)
address - the address of the block to read data frombuffer - the byte array to store the read data to. Length must be 16@Deprecated public byte[] readBlock(byte address)
readBlock(byte, byte[]) as it can report read statusaddress - the byte address of the block to read frompublic boolean writeBlock(byte address,
byte[] data)
address - the byte address of the block to write todata - 16 byte array with the data that wants to be written@Deprecated
public boolean write(byte address,
byte[] data)
writeBlock(byte, byte[]).address - the byte address of the block to write todata - 16 byte array with the data that wants to be writtenpublic boolean increaseBlock(byte address,
int operand)
address - the block's addressoperand - the sum's operandpublic boolean decreaseBlock(byte address,
int operand)
address - the block's addressoperand - the substraction's operandpublic boolean transferBlock(byte address)
address - the address of the block to write topublic boolean restoreBlock(byte address)
address - the address of the block to read frompublic boolean writeValue(byte address,
int value)
address - the block's addressvalue - new value to be written to the block@Nullable public java.lang.Integer readValue(byte address)
address - the block's addresspublic boolean writeTrailer(byte sector,
byte[] keyA,
byte[] accessBits,
byte userData,
byte[] keyB)
sector - the sector's numberkeyA - the new key A that will be setaccessBits - the access bits that will be set. Can be obtained with calculateAccessBits(byte[], byte[], byte[])userData - a single byte containing user datakeyB - the new key B that will be setpublic static byte getBlockAddress(byte sector,
byte block)
sector - the sector numberblock - the sector's blockpublic static byte getBlockAddress(int sector,
int block)
sector - the sector numberblock - the sector's blockpublic static java.lang.String dataToHexString(byte[] data)
data - the byte array holding the datapublic java.lang.String dumpMifare1k()
selectTag(byte[]) before
This won't work if a sector's KEY A or access bits have been changedpublic static byte[] calculateAccessBits(byte[] c1,
byte[] c2,
byte[] c3)
c1 - byte array for the c1 values for block 0, 1, 2 and 3 respectivelyc2 - byte array for the c2 values for block 0, 1, 2 and 3 respectivelyc3 - byte array for the c3 values for block 0, 1, 2 and 3 respectivelypublic static byte[] calculateAccessBits(byte[][] accessConditions)
accessConditions - a 2d array containing the access conditions for each blockpublic static byte[][] calculateAccessConditions(byte[] accessBits)
accessBits - 3 bytes array containing the access bits of a sector trailer (bytes 6 to 7)