Classes | |
struct | MIFARE_Key |
struct | Uid |
Public Member Functions | |
void | PCD_WriteRegister (PCD_Register reg, byte value) |
void | PCD_WriteRegister (PCD_Register reg, byte count, byte *values) |
byte | PCD_ReadRegister (PCD_Register reg) |
void | PCD_ReadRegister (PCD_Register reg, byte count, byte *values, byte rxAlign=0) |
void | PCD_SetRegisterBitMask (PCD_Register reg, byte mask) |
void | PCD_ClearRegisterBitMask (PCD_Register reg, byte mask) |
StatusCode | PCD_CalculateCRC (byte *data, byte length, byte *result) |
void | PCD_Init () |
void | PCD_Init (byte chipSelectPin, byte resetPowerDownPin) |
void | PCD_Reset () |
void | PCD_AntennaOn () |
void | PCD_AntennaOff () |
byte | PCD_GetAntennaGain () |
void | PCD_SetAntennaGain (byte mask) |
bool | PCD_PerformSelfTest () |
StatusCode | PCD_TransceiveData (byte *sendData, byte sendLen, byte *backData, byte *backLen, byte *validBits=nullptr, byte rxAlign=0, bool checkCRC=false) |
StatusCode | PCD_CommunicateWithPICC (byte command, byte waitIRq, byte *sendData, byte sendLen, byte *backData=nullptr, byte *backLen=nullptr, byte *validBits=nullptr, byte rxAlign=0, bool checkCRC=false) |
StatusCode | PICC_RequestA (byte *bufferATQA, byte *bufferSize) |
StatusCode | PICC_WakeupA (byte *bufferATQA, byte *bufferSize) |
StatusCode | PICC_REQA_or_WUPA (byte command, byte *bufferATQA, byte *bufferSize) |
virtual StatusCode | PICC_Select (Uid *uid, byte validBits=0) |
StatusCode | PICC_HaltA () |
StatusCode | PCD_Authenticate (byte command, byte blockAddr, MIFARE_Key *key, Uid *uid) |
void | PCD_StopCrypto1 () |
StatusCode | MIFARE_Read (byte blockAddr, byte *buffer, byte *bufferSize) |
StatusCode | MIFARE_Write (byte blockAddr, byte *buffer, byte bufferSize) |
StatusCode | MIFARE_Ultralight_Write (byte page, byte *buffer, byte bufferSize) |
StatusCode | MIFARE_Decrement (byte blockAddr, int32_t delta) |
StatusCode | MIFARE_Increment (byte blockAddr, int32_t delta) |
StatusCode | MIFARE_Restore (byte blockAddr) |
StatusCode | MIFARE_Transfer (byte blockAddr) |
StatusCode | MIFARE_GetValue (byte blockAddr, int32_t *value) |
StatusCode | MIFARE_SetValue (byte blockAddr, int32_t value) |
StatusCode | PCD_NTAG216_AUTH (byte *passWord, byte pACK[]) |
StatusCode | PCD_MIFARE_Transceive (byte *sendData, byte sendLen, bool acceptTimeout=false) |
void | PCD_DumpVersionToSerial () |
void | PICC_DumpToSerial (Uid *uid) |
void | PICC_DumpDetailsToSerial (Uid *uid) |
void | PICC_DumpMifareClassicToSerial (Uid *uid, PICC_Type piccType, MIFARE_Key *key) |
void | PICC_DumpMifareClassicSectorToSerial (Uid *uid, MIFARE_Key *key, byte sector) |
void | PICC_DumpMifareUltralightToSerial () |
void | MIFARE_SetAccessBits (byte *accessBitBuffer, byte g0, byte g1, byte g2, byte g3) |
virtual bool | PICC_IsNewCardPresent () |
virtual bool | PICC_ReadCardSerial () |
Static Public Member Functions | |
static PICC_Type | PICC_GetType (byte sak) |
Public Attributes | |
Uid | uid |
Static Public Attributes | |
static constexpr byte | FIFO_SIZE = 64 |
static constexpr uint8_t | UNUSED_PIN = UINT8_MAX |
Protected Member Functions | |
StatusCode | MIFARE_TwoStepHelper (byte command, byte blockAddr, int32_t data) |
Protected Attributes | |
byte | _chipSelectPin |
byte | _resetPowerDownPin |
SPI | m_spi |
MFRC522::StatusCode MFRC522::MIFARE_Decrement | ( | byte | blockAddr, |
int32_t | delta | ||
) |
MIFARE Decrement subtracts the delta from the value of the addressed block, and stores the result in a volatile memory. For MIFARE Classic only. The sector containing the block must be authenticated before calling this function. Only for blocks in "value block" mode, ie with access bits [C1 C2 C3] = [110] or [001]. Use MIFARE_Transfer() to store the result in a block.
blockAddr | The block (0-0xff) number. |
delta | This number is subtracted from the value of block blockAddr. |
MFRC522::StatusCode MFRC522::MIFARE_GetValue | ( | byte | blockAddr, |
int32_t * | value | ||
) |
Helper routine to read the current value from a Value Block.
Only for MIFARE Classic and only for blocks in "value block" mode, that is: with access bits [C1 C2 C3] = [110] or [001]. The sector containing the block must be authenticated before calling this function.
[in] | blockAddr | The block (0x00-0xff) number. |
[out] | value | Current value of the Value Block. |
MFRC522::StatusCode MFRC522::MIFARE_Increment | ( | byte | blockAddr, |
int32_t | delta | ||
) |
MIFARE Increment adds the delta to the value of the addressed block, and stores the result in a volatile memory. For MIFARE Classic only. The sector containing the block must be authenticated before calling this function. Only for blocks in "value block" mode, ie with access bits [C1 C2 C3] = [110] or [001]. Use MIFARE_Transfer() to store the result in a block.
blockAddr | The block (0-0xff) number. |
delta | This number is added to the value of block blockAddr. |
MFRC522::StatusCode MFRC522::MIFARE_Read | ( | byte | blockAddr, |
byte * | buffer, | ||
byte * | bufferSize | ||
) |
Reads 16 bytes (+ 2 bytes CRC_A) from the active PICC.
For MIFARE Classic the sector containing the block must be authenticated before calling this function.
For MIFARE Ultralight only addresses 00h to 0Fh are decoded. The MF0ICU1 returns a NAK for higher addresses. The MF0ICU1 responds to the READ command by sending 16 bytes starting from the page address defined by the command argument. For example; if blockAddr is 03h then pages 03h, 04h, 05h, 06h are returned. A roll-back is implemented: If blockAddr is 0Eh, then the contents of pages 0Eh, 0Fh, 00h and 01h are returned.
The buffer must be at least 18 bytes because a CRC_A is also returned. Checks the CRC_A before returning STATUS_OK.
blockAddr | MIFARE Classic: The block (0-0xff) number. MIFARE Ultralight: The first page to return data from. |
buffer | The buffer to store the data in |
bufferSize | Buffer size, at least 18 bytes. Also number of bytes returned if STATUS_OK. |
MFRC522::StatusCode MFRC522::MIFARE_Restore | ( | byte | blockAddr | ) |
MIFARE Restore copies the value of the addressed block into a volatile memory. For MIFARE Classic only. The sector containing the block must be authenticated before calling this function. Only for blocks in "value block" mode, ie with access bits [C1 C2 C3] = [110] or [001]. Use MIFARE_Transfer() to store the result in a block.
blockAddr | The block (0-0xff) number. |
void MFRC522::MIFARE_SetAccessBits | ( | byte * | accessBitBuffer, |
byte | g0, | ||
byte | g1, | ||
byte | g2, | ||
byte | g3 | ||
) |
Calculates the bit pattern needed for the specified access bits. In the [C1 C2 C3] tuples C1 is MSB (=4) and C3 is LSB (=1).
accessBitBuffer | Pointer to byte 6, 7 and 8 in the sector trailer. Bytes [0..2] will be set. |
g0 | Access bits [C1 C2 C3] for block 0 (for sectors 0-31) or blocks 0-4 (for sectors 32-39) |
g1 | Access bits C1 C2 C3] for block 1 (for sectors 0-31) or blocks 5-9 (for sectors 32-39) |
g2 | Access bits C1 C2 C3] for block 2 (for sectors 0-31) or blocks 10-14 (for sectors 32-39) |
g3 | Access bits C1 C2 C3] for the sector trailer, block 3 (for sectors 0-31) or block 15 (for sectors 32-39) |
MFRC522::StatusCode MFRC522::MIFARE_SetValue | ( | byte | blockAddr, |
int32_t | value | ||
) |
Helper routine to write a specific value into a Value Block.
Only for MIFARE Classic and only for blocks in "value block" mode, that is: with access bits [C1 C2 C3] = [110] or [001]. The sector containing the block must be authenticated before calling this function.
[in] | blockAddr | The block (0x00-0xff) number. |
[in] | value | New value of the Value Block. |
MFRC522::StatusCode MFRC522::MIFARE_Transfer | ( | byte | blockAddr | ) |
MIFARE Transfer writes the value stored in the volatile memory into one MIFARE Classic block. For MIFARE Classic only. The sector containing the block must be authenticated before calling this function. Only for blocks in "value block" mode, ie with access bits [C1 C2 C3] = [110] or [001].
blockAddr | The block (0-0xff) number. |
|
protected |
Helper function for the two-step MIFARE Classic protocol operations Decrement, Increment and Restore.
command | The command to use |
blockAddr | The block (0-0xff) number. |
data | The data to transfer in step 2 |
MFRC522::StatusCode MFRC522::MIFARE_Ultralight_Write | ( | byte | page, |
byte * | buffer, | ||
byte | bufferSize | ||
) |
Writes a 4 byte page to the active MIFARE Ultralight PICC.
page | The page (2-15) to write to. |
buffer | The 4 bytes to write to the PICC |
bufferSize | Buffer size, must be at least 4 bytes. Exactly 4 bytes are written. |
MFRC522::StatusCode MFRC522::MIFARE_Write | ( | byte | blockAddr, |
byte * | buffer, | ||
byte | bufferSize | ||
) |
Writes 16 bytes to the active PICC.
For MIFARE Classic the sector containing the block must be authenticated before calling this function.
For MIFARE Ultralight the operation is called "COMPATIBILITY WRITE". Even though 16 bytes are transferred to the Ultralight PICC, only the least significant 4 bytes (bytes 0 to 3) are written to the specified address. It is recommended to set the remaining bytes 04h to 0Fh to all logic 0.
blockAddr | MIFARE Classic: The block (0-0xff) number. MIFARE Ultralight: The page (2-15) to write to. |
buffer | The 16 bytes to write to the PICC |
bufferSize | Buffer size, must be at least 16 bytes. Exactly 16 bytes are written. |
void MFRC522::PCD_AntennaOff | ( | ) |
Turns the antenna off by disabling pins TX1 and TX2.
void MFRC522::PCD_AntennaOn | ( | ) |
Turns the antenna on by enabling pins TX1 and TX2. After a reset these pins are disabled.
MFRC522::StatusCode MFRC522::PCD_Authenticate | ( | byte | command, |
byte | blockAddr, | ||
MIFARE_Key * | key, | ||
Uid * | uid | ||
) |
Executes the MFRC522 MFAuthent command. This command manages MIFARE authentication to enable a secure communication to any MIFARE Mini, MIFARE 1K and MIFARE 4K card. The authentication is described in the MFRC522 datasheet section 10.3.1.9 and http://www.nxp.com/documents/data_sheet/MF1S503x.pdf section 10.1. For use with MIFARE Classic PICCs. The PICC must be selected - ie in state ACTIVE(*) - before calling this function. Remember to call PCD_StopCrypto1() after communicating with the authenticated PICC - otherwise no new communications can start.
All keys are set to FFFFFFFFFFFFh at chip delivery.
command | PICC_CMD_MF_AUTH_KEY_A or PICC_CMD_MF_AUTH_KEY_B |
blockAddr | The block number. See numbering in the comments in the .h file. |
key | Pointer to the Crypteo1 key to use (6 bytes) |
uid | Pointer to Uid struct. The first 4 bytes of the UID is used. |
MFRC522::StatusCode MFRC522::PCD_CalculateCRC | ( | byte * | data, |
byte | length, | ||
byte * | result | ||
) |
Use the CRC coprocessor in the MFRC522 to calculate a CRC_A.
data | In: Pointer to the data to transfer to the FIFO for CRC calculation. |
length | In: The number of bytes to transfer. |
result | Out: Pointer to result buffer. Result is written to result[0..1], low byte first. |
void MFRC522::PCD_ClearRegisterBitMask | ( | PCD_Register | reg, |
byte | mask | ||
) |
Clears the bits given in mask from register reg.
reg | The register to update. One of the PCD_Register enums. |
mask | The bits to clear. |
MFRC522::StatusCode MFRC522::PCD_CommunicateWithPICC | ( | byte | command, |
byte | waitIRq, | ||
byte * | sendData, | ||
byte | sendLen, | ||
byte * | backData = nullptr , |
||
byte * | backLen = nullptr , |
||
byte * | validBits = nullptr , |
||
byte | rxAlign = 0 , |
||
bool | checkCRC = false |
||
) |
Transfers data to the MFRC522 FIFO, executes a command, waits for completion and transfers data back from the FIFO. CRC validation can only be done if backData and backLen are specified.
command | The command to execute. One of the PCD_Command enums. |
waitIRq | The bits in the ComIrqReg register that signals successful completion of the command. |
sendData | Pointer to the data to transfer to the FIFO. |
sendLen | Number of bytes to transfer to the FIFO. |
backData | nullptr or pointer to buffer if data should be read back after executing the command. |
backLen | In: Max number of bytes to write to *backData. Out: The number of bytes returned. |
validBits | In/Out: The number of valid bits in the last byte. 0 for 8 valid bits. |
rxAlign | In: Defines the bit position in backData[0] for the first bit received. Default 0. |
checkCRC | In: True => The last two bytes of the response is assumed to be a CRC_A that must be validated. |
void MFRC522::PCD_DumpVersionToSerial | ( | ) |
Dumps debug info about the connected PCD to Serial. Shows all known firmware versions
byte MFRC522::PCD_GetAntennaGain | ( | ) |
Get the current MFRC522 Receiver Gain (RxGain[2:0]) value. See 9.3.3.6 / table 98 in http://www.nxp.com/documents/data_sheet/MFRC522.pdf NOTE: Return value scrubbed with (0x07<<4)=01110000b as RCFfgReg may use reserved bits.
void MFRC522::PCD_Init | ( | ) |
Initializes the MFRC522 chip.
void MFRC522::PCD_Init | ( | byte | chipSelectPin, |
byte | resetPowerDownPin | ||
) |
MFRC522::StatusCode MFRC522::PCD_MIFARE_Transceive | ( | byte * | sendData, |
byte | sendLen, | ||
bool | acceptTimeout = false |
||
) |
Wrapper for MIFARE protocol communication. Adds CRC_A, executes the Transceive command and checks that the response is MF_ACK or a timeout.
sendData | Pointer to the data to transfer to the FIFO. Do NOT include the CRC_A. |
sendLen | Number of bytes in sendData. |
acceptTimeout | True => A timeout is also success |
MFRC522::StatusCode MFRC522::PCD_NTAG216_AUTH | ( | byte * | passWord, |
byte | pACK[] | ||
) |
Authenticate with a NTAG216.
Only for NTAG216. First implemented by Gargantuanman.
[in] | passWord | password. |
[in] | pACK | result success???. |
bool MFRC522::PCD_PerformSelfTest | ( | ) |
Performs a self-test of the MFRC522 See 16.1.1 in http://www.nxp.com/documents/data_sheet/MFRC522.pdf
byte MFRC522::PCD_ReadRegister | ( | PCD_Register | reg | ) |
Reads a byte from the specified register in the MFRC522 chip. The interface is described in the datasheet section 8.1.2.
reg | The register to read from. One of the PCD_Register enums. |
void MFRC522::PCD_ReadRegister | ( | PCD_Register | reg, |
byte | count, | ||
byte * | values, | ||
byte | rxAlign = 0 |
||
) |
Reads a number of bytes from the specified register in the MFRC522 chip. The interface is described in the datasheet section 8.1.2.
reg | The register to read from. One of the PCD_Register enums. |
count | The number of bytes to read |
values | Byte array to store the values in. |
rxAlign | Only bit positions rxAlign..7 in values[0] are updated. |
void MFRC522::PCD_Reset | ( | ) |
Performs a soft reset on the MFRC522 chip and waits for it to be ready again.
void MFRC522::PCD_SetAntennaGain | ( | byte | mask | ) |
Set the MFRC522 Receiver Gain (RxGain) to value specified by given mask. See 9.3.3.6 / table 98 in http://www.nxp.com/documents/data_sheet/MFRC522.pdf NOTE: Given mask is scrubbed with (0x07<<4)=01110000b as RCFfgReg may use reserved bits.
void MFRC522::PCD_SetRegisterBitMask | ( | PCD_Register | reg, |
byte | mask | ||
) |
Sets the bits given in mask in register reg.
reg | The register to update. One of the PCD_Register enums. |
mask | The bits to set. |
void MFRC522::PCD_StopCrypto1 | ( | ) |
Used to exit the PCD from its authenticated state. Remember to call this function after communicating with an authenticated PICC - otherwise no new communications can start.
MFRC522::StatusCode MFRC522::PCD_TransceiveData | ( | byte * | sendData, |
byte | sendLen, | ||
byte * | backData, | ||
byte * | backLen, | ||
byte * | validBits = nullptr , |
||
byte | rxAlign = 0 , |
||
bool | checkCRC = false |
||
) |
Executes the Transceive command. CRC validation can only be done if backData and backLen are specified.
sendData | Pointer to the data to transfer to the FIFO. |
sendLen | Number of bytes to transfer to the FIFO. |
backData | nullptr or pointer to buffer if data should be read back after executing the command. |
backLen | In: Max number of bytes to write to *backData. Out: The number of bytes returned. |
validBits | In/Out: The number of valid bits in the last byte. 0 for 8 valid bits. Default nullptr. |
rxAlign | In: Defines the bit position in backData[0] for the first bit received. Default 0. |
checkCRC | In: True => The last two bytes of the response is assumed to be a CRC_A that must be validated. |
void MFRC522::PCD_WriteRegister | ( | PCD_Register | reg, |
byte | value | ||
) |
Writes a byte to the specified register in the MFRC522 chip. The interface is described in the datasheet section 8.1.2.
reg | The register to write to. One of the PCD_Register enums. |
value | The value to write. |
void MFRC522::PCD_WriteRegister | ( | PCD_Register | reg, |
byte | count, | ||
byte * | values | ||
) |
Writes a number of bytes to the specified register in the MFRC522 chip. The interface is described in the datasheet section 8.1.2.
reg | The register to write to. One of the PCD_Register enums. |
count | The number of bytes to write to the register |
values | The values to write. Byte array. |
void MFRC522::PICC_DumpDetailsToSerial | ( | Uid * | uid | ) |
Dumps card info (UID,SAK,Type) about the selected PICC to Serial.
uid | Pointer to Uid struct returned from a successful PICC_Select(). kept for backward compatibility |
void MFRC522::PICC_DumpMifareClassicSectorToSerial | ( | Uid * | uid, |
MIFARE_Key * | key, | ||
byte | sector | ||
) |
Dumps memory contents of a sector of a MIFARE Classic PICC. Uses PCD_Authenticate(), MIFARE_Read() and PCD_StopCrypto1. Always uses PICC_CMD_MF_AUTH_KEY_A because only Key A can always read the sector trailer access bits.
uid | Pointer to Uid struct returned from a successful PICC_Select(). |
key | Key A for the sector. |
sector | The sector to dump, 0..39. |
void MFRC522::PICC_DumpMifareClassicToSerial | ( | Uid * | uid, |
PICC_Type | piccType, | ||
MIFARE_Key * | key | ||
) |
Dumps memory contents of a MIFARE Classic PICC. On success the PICC is halted after dumping the data.
uid | Pointer to Uid struct returned from a successful PICC_Select(). |
piccType | One of the PICC_Type enums. |
key | Key A used for all sectors. |
void MFRC522::PICC_DumpMifareUltralightToSerial | ( | ) |
Dumps memory contents of a MIFARE Ultralight PICC.
void MFRC522::PICC_DumpToSerial | ( | Uid * | uid | ) |
Dumps debug info about the selected PICC to Serial. On success the PICC is halted after dumping the data. For MIFARE Classic the factory default key of 0xFFFFFFFFFFFF is tried.
uid | Pointer to Uid struct returned from a successful PICC_Select(). Kept for bakward compatibility |
|
static |
Translates the SAK (Select Acknowledge) to a PICC type.
sak | The SAK byte returned from PICC_Select(). |
MFRC522::StatusCode MFRC522::PICC_HaltA | ( | ) |
Instructs a PICC in state ACTIVE(*) to go to state HALT.
|
virtual |
Returns true if a PICC responds to PICC_CMD_REQA. Only "new" cards in state IDLE are invited. Sleeping cards in state HALT are ignored.
|
virtual |
Simple wrapper around PICC_Select. Returns true if a UID could be read. Remember to call PICC_IsNewCardPresent(), PICC_RequestA() or PICC_WakeupA() first. The read UID is available in the class variable uid.
MFRC522::StatusCode MFRC522::PICC_REQA_or_WUPA | ( | byte | command, |
byte * | bufferATQA, | ||
byte * | bufferSize | ||
) |
Transmits REQA or WUPA commands. Beware: When two PICCs are in the field at the same time I often get STATUS_TIMEOUT - probably due do bad antenna design.
command | The command to send - PICC_CMD_REQA or PICC_CMD_WUPA |
bufferATQA | The buffer to store the ATQA (Answer to request) in |
bufferSize | Buffer size, at least two bytes. Also number of bytes returned if STATUS_OK. |
MFRC522::StatusCode MFRC522::PICC_RequestA | ( | byte * | bufferATQA, |
byte * | bufferSize | ||
) |
Transmits a REQuest command, Type A. Invites PICCs in state IDLE to go to READY and prepare for anticollision or selection. 7 bit frame. Beware: When two PICCs are in the field at the same time I often get STATUS_TIMEOUT - probably due do bad antenna design.
bufferATQA | The buffer to store the ATQA (Answer to request) in |
bufferSize | Buffer size, at least two bytes. Also number of bytes returned if STATUS_OK. |
|
virtual |
Transmits SELECT/ANTICOLLISION commands to select a single PICC. Before calling this function the PICCs must be placed in the READY(*) state by calling PICC_RequestA() or PICC_WakeupA(). On success:
A PICC UID consists of 4, 7 or 10 bytes. Only 4 bytes can be specified in a SELECT command, so for the longer UIDs two or three iterations are used: UID size Number of UID bytes Cascade levels Example of PICC ======== =================== ============== =============== single 4 1 MIFARE Classic double 7 2 MIFARE Ultralight triple 10 3 Not currently in use?
MFRC522::StatusCode MFRC522::PICC_WakeupA | ( | byte * | bufferATQA, |
byte * | bufferSize | ||
) |
Transmits a Wake-UP command, Type A. Invites PICCs in state IDLE and HALT to go to READY(*) and prepare for anticollision or selection. 7 bit frame. Beware: When two PICCs are in the field at the same time I often get STATUS_TIMEOUT - probably due do bad antenna design.
bufferATQA | The buffer to store the ATQA (Answer to request) in |
bufferSize | Buffer size, at least two bytes. Also number of bytes returned if STATUS_OK. |