@@ -150,9 +150,9 @@ void MFRC522::PCD_ClearRegisterBitMask( byte reg, ///< The register to update. O
*
* @return STATUS_OK on success, STATUS_??? otherwise.
*/
byt e MFRC522 : : PCD_CalculateCRC ( byte * data , ///< In: Pointer to the data to transfer to the FIFO for CRC calculation.
byte length , ///< In: The number of bytes to transfer.
byte * result ///< Out: Pointer to result buffer. Result is written to result[0..1], low byte first.
MFRC522 : : StatusCod e MFRC522 : : PCD_CalculateCRC ( byte * data , ///< In: Pointer to the data to transfer to the FIFO for CRC calculation.
byte length , ///< In: The number of bytes to transfer.
byte * result ///< Out: Pointer to result buffer. Result is written to result[0..1], low byte first.
) {
PCD_WriteRegister ( CommandReg , PCD_Idle ) ; // Stop any active command.
PCD_WriteRegister ( DivIrqReg , 0x04 ) ; // Clear the CRCIRq interrupt request bit
@@ -192,13 +192,13 @@ void MFRC522::PCD_Init() {
// Set the chipSelectPin as digital output, do not select the slave yet
pinMode ( _chipSelectPin , OUTPUT ) ;
digitalWrite ( _chipSelectPin , HIGH ) ;
// Set the resetPowerDownPin as digital output, do not reset or power down.
pinMode ( _resetPowerDownPin , OUTPUT ) ;
// Set SPI bus to work with MFRC522 chip.
setSPIConfig ( ) ;
if ( digitalRead ( _resetPowerDownPin ) = = LOW ) { //The MFRC522 chip is in power down mode.
digitalWrite ( _resetPowerDownPin , HIGH ) ; // Exit power down mode. This triggers a hard reset.
// Section 8.8.2 in the datasheet says the oscillator start-up time is the start up time of the crystal + 37,74<37> s. Let us be generous: 50ms.
@@ -225,8 +225,8 @@ void MFRC522::PCD_Init() {
* Initializes the MFRC522 chip.
*/
void MFRC522 : : PCD_Init ( byte chipSelectPin , ///< Arduino pin connected to MFRC522's SPI slave select input (Pin 24, NSS, active low)
byte resetPowerDownPin ///< Arduino pin connected to MFRC522's reset and power down input (Pin 6, NRSTPD, active low)
) {
byte resetPowerDownPin ///< Arduino pin connected to MFRC522's reset and power down input (Pin 6, NRSTPD, active low)
) {
_chipSelectPin = chipSelectPin ;
_resetPowerDownPin = resetPowerDownPin ;
// Set the chipSelectPin as digital output, do not select the slave yet
@@ -377,13 +377,13 @@ bool MFRC522::PCD_PerformSelfTest() {
*
* @return STATUS_OK on success, STATUS_??? otherwise.
*/
byt e MFRC522 : : PCD_TransceiveData ( byte * sendData , ///< Pointer to the data to transfer to the FIFO.
byte sendLen , ///< Number of bytes to transfer to the FIFO.
byte * backData , ///< NULL or pointer to buffer if data should be read back after executing the command.
byte * backLen , ///< In: Max number of bytes to write to *backData. Out: The number of bytes returned.
byte * validBits , ///< In/Out: The number of valid bits in the last byte. 0 for 8 valid bits. Default NULL.
byte rxAlign , ///< In: Defines the bit position in backData[0] for the first bit received. Default 0.
bool checkCRC ///< In: True => The last two bytes of the response is assumed to be a CRC_A that must be validated.
MFRC522 : : StatusCod e MFRC522 : : PCD_TransceiveData ( byte * sendData , ///< Pointer to the data to transfer to the FIFO.
byte sendLen , ///< Number of bytes to transfer to the FIFO.
byte * backData , ///< NULL or pointer to buffer if data should be read back after executing the command.
byte * backLen , ///< In: Max number of bytes to write to *backData. Out: The number of bytes returned.
byte * validBits , ///< In/Out: The number of valid bits in the last byte. 0 for 8 valid bits. Default NULL.
byte rxAlign , ///< In: Defines the bit position in backData[0] for the first bit received. Default 0.
bool checkCRC ///< In: True => The last two bytes of the response is assumed to be a CRC_A that must be validated.
) {
byte waitIRq = 0x30 ; // RxIRq and IdleIRq
return PCD_CommunicateWithPICC ( PCD_Transceive , waitIRq , sendData , sendLen , backData , backLen , validBits , rxAlign , checkCRC ) ;
@@ -395,15 +395,15 @@ byte MFRC522::PCD_TransceiveData( byte *sendData, ///< Pointer to the data to t
*
* @return STATUS_OK on success, STATUS_??? otherwise.
*/
byt e MFRC522 : : PCD_CommunicateWithPICC ( byte command , ///< The command to execute. One of the PCD_Command enums.
byte waitIRq , ///< The bits in the ComIrqReg register that signals successful completion of the command.
byte * sendData , ///< Pointer to the data to transfer to the FIFO.
byte sendLen , ///< Number of bytes to transfer to the FIFO.
byte * backData , ///< NULL or pointer to buffer if data should be read back after executing the command.
byte * backLen , ///< In: Max number of bytes to write to *backData. Out: The number of bytes returned.
byte * validBits , ///< In/Out: The number of valid bits in the last byte. 0 for 8 valid bits.
byte rxAlign , ///< In: Defines the bit position in backData[0] for the first bit received. Default 0.
bool checkCRC ///< In: True => The last two bytes of the response is assumed to be a CRC_A that must be validated.
MFRC522 : : StatusCod e MFRC522 : : PCD_CommunicateWithPICC ( byte command , ///< The command to execute. One of the PCD_Command enums.
byte waitIRq , ///< The bits in the ComIrqReg register that signals successful completion of the command.
byte * sendData , ///< Pointer to the data to transfer to the FIFO.
byte sendLen , ///< Number of bytes to transfer to the FIFO.
byte * backData , ///< NULL or pointer to buffer if data should be read back after executing the command.
byte * backLen , ///< In: Max number of bytes to write to *backData. Out: The number of bytes returned.
byte * validBits , ///< In/Out: The number of valid bits in the last byte. 0 for 8 valid bits.
byte rxAlign , ///< In: Defines the bit position in backData[0] for the first bit received. Default 0.
bool checkCRC ///< In: True => The last two bytes of the response is assumed to be a CRC_A that must be validated.
) {
byte n , _validBits ;
unsigned int i ;
@@ -476,9 +476,9 @@ byte MFRC522::PCD_CommunicateWithPICC( byte command, ///< The command to execut
}
// Verify CRC_A - do our own calculation and store the control in controlBuffer.
byte controlBuffer [ 2 ] ;
n = PCD_CalculateCRC ( & backData [ 0 ] , * backLen - 2 , & controlBuffer [ 0 ] ) ;
if ( n ! = STATUS_OK ) {
return n ;
MFRC522 : : StatusCode status = PCD_CalculateCRC ( & backData [ 0 ] , * backLen - 2 , & controlBuffer [ 0 ] ) ;
if ( status ! = STATUS_OK ) {
return status ;
}
if ( ( backData [ * backLen - 2 ] ! = controlBuffer [ 0 ] ) | | ( backData [ * backLen - 1 ] ! = controlBuffer [ 1 ] ) ) {
return STATUS_CRC_WRONG ;
@@ -494,9 +494,9 @@ byte MFRC522::PCD_CommunicateWithPICC( byte command, ///< The command to execut
*
* @return STATUS_OK on success, STATUS_??? otherwise.
*/
byt e MFRC522 : : PICC_RequestA ( byte * bufferATQA , ///< The buffer to store the ATQA (Answer to request) in
byte * bufferSize ///< Buffer size, at least two bytes. Also number of bytes returned if STATUS_OK.
) {
MFRC522 : : StatusCod e MFRC522 : : PICC_RequestA ( byte * bufferATQA , ///< The buffer to store the ATQA (Answer to request) in
byte * bufferSize ///< Buffer size, at least two bytes. Also number of bytes returned if STATUS_OK.
) {
return PICC_REQA_or_WUPA ( PICC_CMD_REQA , bufferATQA , bufferSize ) ;
} // End PICC_RequestA()
@@ -506,9 +506,9 @@ byte MFRC522::PICC_RequestA(byte *bufferATQA, ///< The buffer to store the ATQA
*
* @return STATUS_OK on success, STATUS_??? otherwise.
*/
byt e MFRC522 : : PICC_WakeupA ( byte * bufferATQA , ///< The buffer to store the ATQA (Answer to request) in
byte * bufferSize ///< Buffer size, at least two bytes. Also number of bytes returned if STATUS_OK.
) {
MFRC522 : : StatusCod e MFRC522 : : PICC_WakeupA ( byte * bufferATQA , ///< The buffer to store the ATQA (Answer to request) in
byte * bufferSize ///< Buffer size, at least two bytes. Also number of bytes returned if STATUS_OK.
) {
return PICC_REQA_or_WUPA ( PICC_CMD_WUPA , bufferATQA , bufferSize ) ;
} // End PICC_WakeupA()
@@ -518,12 +518,12 @@ byte MFRC522::PICC_WakeupA( byte *bufferATQA, ///< The buffer to store the ATQA
*
* @return STATUS_OK on success, STATUS_??? otherwise.
*/
byt e MFRC522 : : PICC_REQA_or_WUPA ( byte command , ///< The command to send - PICC_CMD_REQA or PICC_CMD_WUPA
byte * bufferATQA , ///< The buffer to store the ATQA (Answer to request) in
byte * bufferSize ///< Buffer size, at least two bytes. Also number of bytes returned if STATUS_OK.
) {
MFRC522 : : StatusCod e MFRC522 : : PICC_REQA_or_WUPA ( byte command , ///< The command to send - PICC_CMD_REQA or PICC_CMD_WUPA
byte * bufferATQA , ///< The buffer to store the ATQA (Answer to request) in
byte * bufferSize ///< Buffer size, at least two bytes. Also number of bytes returned if STATUS_OK.
) {
byte validBits ;
byt e status ;
MFRC522 : : StatusCod e status ;
if ( bufferATQA = = NULL | | * bufferSize < 2 ) { // The ATQA response is 2 bytes long.
return STATUS_NO_ROOM ;
@@ -557,14 +557,14 @@ byte MFRC522::PICC_REQA_or_WUPA( byte command, ///< The command to send - PICC
*
* @return STATUS_OK on success, STATUS_??? otherwise.
*/
byt e MFRC522 : : PICC_Select ( Uid * uid , ///< Pointer to Uid struct. Normally output, but can also be used to supply a known UID.
byte validBits ///< The number of known UID bits supplied in *uid. Normally 0. If set you must also supply uid->size.
) {
MFRC522 : : StatusCod e MFRC522 : : PICC_Select ( Uid * uid , ///< Pointer to Uid struct. Normally output, but can also be used to supply a known UID.
byte validBits ///< The number of known UID bits supplied in *uid. Normally 0. If set you must also supply uid->size.
) {
bool uidComplete ;
bool selectDone ;
bool useCascadeTag ;
byte cascadeLevel = 1 ;
byt e result ;
MFRC522 : : StatusCod e result ;
byte count ;
byte index ;
byte uidIndex ; // The first index in uid->uidByte[] that is used in the current Cascade Level.
@@ -698,8 +698,8 @@ byte MFRC522::PICC_Select( Uid *uid, ///< Pointer to Uid struct. Normally outp
// Transmit the buffer and receive the response.
result = PCD_TransceiveData ( buffer , bufferUsed , responseBuffer , & responseLength , & txLastBits , rxAlign ) ;
if ( result = = STATUS_COLLISION ) { // More than one PICC in the field => collision.
result = PCD_ReadRegister ( CollReg ) ; // CollReg[7..0] bits are: ValuesAfterColl reserved CollPosNotValid CollPos[4:0]
if ( result & 0x20 ) { // CollPosNotValid
byte valueOfCollReg = PCD_ReadRegister ( CollReg ) ; // CollReg[7..0] bits are: ValuesAfterColl reserved CollPosNotValid CollPos[4:0]
if ( valueOfCollReg & 0x20 ) { // CollPosNotValid
return STATUS_COLLISION ; // Without a valid collision position we cannot continue
}
byte collisionPos = result & 0x1F ; // Values 0-31, 0 means bit 32.
@@ -772,8 +772,8 @@ byte MFRC522::PICC_Select( Uid *uid, ///< Pointer to Uid struct. Normally outp
*
* @return STATUS_OK on success, STATUS_??? otherwise.
*/
byt e MFRC522 : : PICC_HaltA ( ) {
byt e result ;
MFRC522 : : StatusCod e MFRC522 : : PICC_HaltA ( ) {
MFRC522 : : StatusCod e result ;
byte buffer [ 4 ] ;
// Build command buffer
@@ -817,11 +817,11 @@ byte MFRC522::PICC_HaltA() {
*
* @return STATUS_OK on success, STATUS_??? otherwise. Probably STATUS_TIMEOUT if you supply the wrong key.
*/
byt e MFRC522 : : PCD_Authenticate ( byte command , ///< PICC_CMD_MF_AUTH_KEY_A or PICC_CMD_MF_AUTH_KEY_B
byte blockAddr , ///< The block number. See numbering in the comments in the .h file.
MIFARE_Key * key , ///< Pointer to the Crypteo1 key to use (6 bytes)
Uid * uid ///< Pointer to Uid struct. The first 4 bytes of the UID is used.
) {
MFRC522 : : StatusCod e MFRC522 : : PCD_Authenticate ( byte command , ///< PICC_CMD_MF_AUTH_KEY_A or PICC_CMD_MF_AUTH_KEY_B
byte blockAddr , ///< The block number. See numbering in the comments in the .h file.
MIFARE_Key * key , ///< Pointer to the Crypteo1 key to use (6 bytes)
Uid * uid ///< Pointer to Uid struct. The first 4 bytes of the UID is used.
) {
byte waitIRq = 0x10 ; // IdleIRq
// Build command buffer
@@ -864,11 +864,11 @@ void MFRC522::PCD_StopCrypto1() {
*
* @return STATUS_OK on success, STATUS_??? otherwise.
*/
byt e MFRC522 : : MIFARE_Read ( byte blockAddr , ///< MIFARE Classic: The block (0-0xff) number. MIFARE Ultralight: The first page to return data from.
byte * buffer , ///< The buffer to store the data in
byte * bufferSize ///< Buffer size, at least 18 bytes. Also number of bytes returned if STATUS_OK.
) {
byt e result ;
MFRC522 : : StatusCod e MFRC522 : : MIFARE_Read ( byte blockAddr , ///< MIFARE Classic: The block (0-0xff) number. MIFARE Ultralight: The first page to return data from.
byte * buffer , ///< The buffer to store the data in
byte * bufferSize ///< Buffer size, at least 18 bytes. Also number of bytes returned if STATUS_OK.
) {
MFRC522 : : StatusCod e result ;
// Sanity check
if ( buffer = = NULL | | * bufferSize < 18 ) {
@@ -899,11 +899,11 @@ byte MFRC522::MIFARE_Read( byte blockAddr, ///< MIFARE Classic: The block (0-0x
* *
* @return STATUS_OK on success, STATUS_??? otherwise.
*/
byt e MFRC522 : : MIFARE_Write ( byte blockAddr , ///< MIFARE Classic: The block (0-0xff) number. MIFARE Ultralight: The page (2-15) to write to.
byte * buffer , ///< The 16 bytes to write to the PICC
byte bufferSize ///< Buffer size, must be at least 16 bytes. Exactly 16 bytes are written.
) {
byt e result ;
MFRC522 : : StatusCod e MFRC522 : : MIFARE_Write ( byte blockAddr , ///< MIFARE Classic: The block (0-0xff) number. MIFARE Ultralight: The page (2-15) to write to.
byte * buffer , ///< The 16 bytes to write to the PICC
byte bufferSize ///< Buffer size, must be at least 16 bytes. Exactly 16 bytes are written.
) {
MFRC522 : : StatusCod e result ;
// Sanity check
if ( buffer = = NULL | | bufferSize < 16 ) {
@@ -934,11 +934,11 @@ byte MFRC522::MIFARE_Write( byte blockAddr, ///< MIFARE Classic: The block (0-0x
*
* @return STATUS_OK on success, STATUS_??? otherwise.
*/
byt e MFRC522 : : MIFARE_Ultralight_Write ( byte page , ///< The page (2-15) to write to.
byte * buffer , ///< The 4 bytes to write to the PICC
byte bufferSize ///< Buffer size, must be at least 4 bytes. Exactly 4 bytes are written.
) {
byt e result ;
MFRC522 : : StatusCod e MFRC522 : : MIFARE_Ultralight_Write ( byte page , ///< The page (2-15) to write to.
byte * buffer , ///< The 4 bytes to write to the PICC
byte bufferSize ///< Buffer size, must be at least 4 bytes. Exactly 4 bytes are written.
) {
MFRC522 : : StatusCod e result ;
// Sanity check
if ( buffer = = NULL | | bufferSize < 4 ) {
@@ -967,9 +967,9 @@ byte MFRC522::MIFARE_Ultralight_Write( byte page, ///< The page (2-15) to writ
*
* @return STATUS_OK on success, STATUS_??? otherwise.
*/
byt e MFRC522 : : MIFARE_Decrement ( byte blockAddr , ///< The block (0-0xff) number.
long delta ///< This number is subtracted from the value of block blockAddr.
) {
MFRC522 : : StatusCod e MFRC522 : : MIFARE_Decrement ( byte blockAddr , ///< The block (0-0xff) number.
long delta ///< This number is subtracted from the value of block blockAddr.
) {
return MIFARE_TwoStepHelper ( PICC_CMD_MF_DECREMENT , blockAddr , delta ) ;
} // End MIFARE_Decrement()
@@ -981,9 +981,9 @@ byte MFRC522::MIFARE_Decrement( byte blockAddr, ///< The block (0-0xff) number.
*
* @return STATUS_OK on success, STATUS_??? otherwise.
*/
byt e MFRC522 : : MIFARE_Increment ( byte blockAddr , ///< The block (0-0xff) number.
long delta ///< This number is added to the value of block blockAddr.
) {
MFRC522 : : StatusCod e MFRC522 : : MIFARE_Increment ( byte blockAddr , ///< The block (0-0xff) number.
long delta ///< This number is added to the value of block blockAddr.
) {
return MIFARE_TwoStepHelper ( PICC_CMD_MF_INCREMENT , blockAddr , delta ) ;
} // End MIFARE_Increment()
@@ -995,8 +995,8 @@ byte MFRC522::MIFARE_Increment( byte blockAddr, ///< The block (0-0xff) number.
*
* @return STATUS_OK on success, STATUS_??? otherwise.
*/
byt e MFRC522 : : MIFARE_Restore ( byte blockAddr ///< The block (0-0xff) number.
) {
MFRC522 : : StatusCod e MFRC522 : : MIFARE_Restore ( byte blockAddr ///< The block (0-0xff) number.
) {
// The datasheet describes Restore as a two step operation, but does not explain what data to transfer in step 2.
// Doing only a single step does not work, so I chose to transfer 0L in step two.
return MIFARE_TwoStepHelper ( PICC_CMD_MF_RESTORE , blockAddr , 0L ) ;
@@ -1007,11 +1007,11 @@ byte MFRC522::MIFARE_Restore( byte blockAddr ///< The block (0-0xff) number.
*
* @return STATUS_OK on success, STATUS_??? otherwise.
*/
byt e MFRC522 : : MIFARE_TwoStepHelper ( byte command , ///< The command to use
byte blockAddr , ///< The block (0-0xff) number.
long data ///< The data to transfer in step 2
) {
byt e result ;
MFRC522 : : StatusCod e MFRC522 : : MIFARE_TwoStepHelper ( byte command , ///< The command to use
byte blockAddr , ///< The block (0-0xff) number.
long data ///< The data to transfer in step 2
) {
MFRC522 : : StatusCod e result ;
byte cmdBuffer [ 2 ] ; // We only need room for 2 bytes.
// Step 1: Tell the PICC the command and block address
@@ -1038,9 +1038,9 @@ byte MFRC522::MIFARE_TwoStepHelper( byte command, ///< The command to use
*
* @return STATUS_OK on success, STATUS_??? otherwise.
*/
byt e MFRC522 : : MIFARE_Transfer ( byte blockAddr ///< The block (0-0xff) number.
) {
byt e result ;
MFRC522 : : StatusCod e MFRC522 : : MIFARE_Transfer ( byte blockAddr ///< The block (0-0xff) number.
) {
MFRC522 : : StatusCod e result ;
byte cmdBuffer [ 2 ] ; // We only need room for 2 bytes.
// Tell the PICC we want to transfer the result into block blockAddr.
@@ -1064,8 +1064,8 @@ byte MFRC522::MIFARE_Transfer( byte blockAddr ///< The block (0-0xff) number.
* @param[out] value Current value of the Value Block.
* @return STATUS_OK on success, STATUS_??? otherwise.
*/
byt e MFRC522 : : MIFARE_GetValue ( byte blockAddr , long * value ) {
byt e status ;
MFRC522 : : StatusCod e MFRC522 : : MIFARE_GetValue ( byte blockAddr , long * value ) {
MFRC522 : : StatusCod e status ;
byte buffer [ 18 ] ;
byte size = sizeof ( buffer ) ;
@@ -1089,7 +1089,7 @@ byte MFRC522::MIFARE_GetValue(byte blockAddr, long *value) {
* @param[in] value New value of the Value Block.
* @return STATUS_OK on success, STATUS_??? otherwise.
*/
byt e MFRC522 : : MIFARE_SetValue ( byte blockAddr , long value ) {
MFRC522 : : StatusCod e MFRC522 : : MIFARE_SetValue ( byte blockAddr , long value ) {
byte buffer [ 18 ] ;
// Translate the long into 4 bytes; repeated 2x in value block
@@ -1120,11 +1120,11 @@ byte MFRC522::MIFARE_SetValue(byte blockAddr, long value) {
*
* @return STATUS_OK on success, STATUS_??? otherwise.
*/
byt e MFRC522 : : PCD_MIFARE_Transceive ( byte * sendData , ///< Pointer to the data to transfer to the FIFO. Do NOT include the CRC_A.
byte sendLen , ///< Number of bytes in sendData.
bool acceptTimeout ///< True => A timeout is also success
) {
byt e result ;
MFRC522 : : StatusCod e MFRC522 : : PCD_MIFARE_Transceive ( byte * sendData , ///< Pointer to the data to transfer to the FIFO. Do NOT include the CRC_A.
byte sendLen , ///< Number of bytes in sendData.
bool acceptTimeout ///< True => A timeout is also success
) {
MFRC522 : : StatusCod e result ;
byte cmdBuffer [ 18 ] ; // We need room for 16 bytes data and 2 bytes CRC_A.
// Sanity check
@@ -1166,19 +1166,19 @@ byte MFRC522::PCD_MIFARE_Transceive( byte *sendData, ///< Pointer to the data t
*
* @return const __FlashStringHelper *
*/
const __FlashStringHelper * MFRC522 : : GetStatusCodeName ( byt e code ///< One of the StatusCode enums.
const __FlashStringHelper * MFRC522 : : GetStatusCodeName ( MFRC522 : : StatusCod e code ///< One of the StatusCode enums.
) {
switch ( code ) {
case STATUS_OK : return F ( " Success. " ) ; break ;
case STATUS_ERROR : return F ( " Error in communication. " ) ; break ;
case STATUS_COLLISION : return F ( " Collission detected. " ) ; break ;
case STATUS_TIMEOUT : return F ( " Timeout in communication. " ) ; break ;
case STATUS_NO_ROOM : return F ( " A buffer is not big enough. " ) ; break ;
case STATUS_INTERNAL_ERROR : return F ( " Internal error in the code. Should not happen. " ) ; break ;
case STATUS_INVALID : return F ( " Invalid argument. " ) ; break ;
case STATUS_CRC_WRONG : return F ( " The CRC_A does not match. " ) ; break ;
case STATUS_MIFARE_NACK : return F ( " A MIFARE PICC responded with NAK. " ) ; break ;
default : return F ( " Unknown error " ) ; break ;
case STATUS_OK : return F ( " Success. " ) ;
case STATUS_ERROR : return F ( " Error in communication. " ) ;
case STATUS_COLLISION : return F ( " Collission detected. " ) ;
case STATUS_TIMEOUT : return F ( " Timeout in communication. " ) ;
case STATUS_NO_ROOM : return F ( " A buffer is not big enough. " ) ;
case STATUS_INTERNAL_ERROR : return F ( " Internal error in the code. Should not happen. " ) ;
case STATUS_INVALID : return F ( " Invalid argument. " ) ;
case STATUS_CRC_WRONG : return F ( " The CRC_A does not match. " ) ;
case STATUS_MIFARE_NACK : return F ( " A MIFARE PICC responded with NAK. " ) ;
default : return F ( " Unknown error " ) ;
}
} // End GetStatusCodeName()
@@ -1187,35 +1187,26 @@ const __FlashStringHelper *MFRC522::GetStatusCodeName(byte code ///< One of the
*
* @return PICC_Type
*/
byt e MFRC522 : : PICC_GetType ( byte sak ///< The SAK byte returned from PICC_Select().
) {
if ( sak & 0x04 ) { // UID not complete
return PICC_TYPE_NOT_COMPLETE ;
}
//http://www.nxp.com/documents/application_note/AN10833.pdf
//3.2 Coding of Select Acknowledge (SAK)
//ignore 8-bit
sak & = 0x7F ;
MFRC522 : : PICC_Typ e MFRC522 : : PICC_GetType ( byte sak ///< The SAK byte returned from PICC_Select().
) {
// http://www.nxp.com/documents/application_note/AN10833.pdf
// 3.2 Coding of Select Acknowledge (SAK)
// ignore 8-bit (iso14443 starts with LSBit = bit 1)
// fixes wrong type for manufacturer Infineon (http://nfc-tools.org/index.php?title=ISO14443A)
sak & = 0x7F ;
switch ( sak ) {
case 0x09 : return PICC_TYPE_MIFARE_MINI ; break ;
case 0x08 : return PICC_TYPE_MIFARE_1K ; break ;
case 0x1 8 : return PICC_TYPE_MIFARE_4 K ; break ;
case 0x00 : return PICC_TYPE_MIFARE_UL ; break ;
case 0x04 : return PICC_TYPE_NOT_COMPLETE ; // UID not complete
case 0x09 : return PICC_TYPE_MIFARE_MINI ;
case 0x0 8 : return PICC_TYPE_MIFARE_1 K ;
case 0x18 : return PICC_TYPE_MIFARE_4K ;
case 0x00 : return PICC_TYPE_MIFARE_UL ;
case 0x10 :
case 0x11 : return PICC_TYPE_MIFARE_PLUS ; break ;
case 0x01 : return PICC_TYPE_TNP3XXX ; break ;
default : b reak ;
case 0x11 : return PICC_TYPE_MIFARE_PLUS ;
case 0x01 : return PICC_TYPE_TNP3XXX ;
case 0x20 : return PICC_TYPE_ISO_14443_4 ;
case 0x40 : return PICC_TYPE_ISO_18092 ;
default : return PICC_TYPE_UNKNOWN ;
}
if ( sak & 0x20 ) {
return PICC_TYPE_ISO_14443_4 ;
}
if ( sak & 0x40 ) {
return PICC_TYPE_ISO_18092 ;
}
return PICC_TYPE_UNKNOWN ;
} // End PICC_GetType()
/**
@@ -1224,19 +1215,19 @@ byte MFRC522::PICC_GetType(byte sak ///< The SAK byte returned from PICC_Select
* @return const __FlashStringHelper *
*/
const __FlashStringHelper * MFRC522 : : PICC_GetTypeName ( byte piccType ///< One of the PICC_Type enums.
) {
) {
switch ( piccType ) {
case PICC_TYPE_ISO_14443_4 : return F ( " PICC compliant with ISO/IEC 14443-4 " ) ; break ;
case PICC_TYPE_ISO_18092 : return F ( " PICC compliant with ISO/IEC 18092 (NFC) " ) ; break ;
case PICC_TYPE_MIFARE_MINI : return F ( " MIFARE Mini, 320 bytes " ) ; break ;
case PICC_TYPE_MIFARE_1K : return F ( " MIFARE 1KB " ) ; break ;
case PICC_TYPE_MIFARE_4K : return F ( " MIFARE 4KB " ) ; break ;
case PICC_TYPE_MIFARE_UL : return F ( " MIFARE Ultralight or Ultralight C " ) ; break ;
case PICC_TYPE_MIFARE_PLUS : return F ( " MIFARE Plus " ) ; break ;
case PICC_TYPE_TNP3XXX : return F ( " MIFARE TNP3XXX " ) ; break ;
case PICC_TYPE_NOT_COMPLETE : return F ( " SAK indicates UID is not complete. " ) ; break ;
case PICC_TYPE_ISO_14443_4 : return F ( " PICC compliant with ISO/IEC 14443-4 " ) ;
case PICC_TYPE_ISO_18092 : return F ( " PICC compliant with ISO/IEC 18092 (NFC) " ) ;
case PICC_TYPE_MIFARE_MINI : return F ( " MIFARE Mini, 320 bytes " ) ;
case PICC_TYPE_MIFARE_1K : return F ( " MIFARE 1KB " ) ;
case PICC_TYPE_MIFARE_4K : return F ( " MIFARE 4KB " ) ;
case PICC_TYPE_MIFARE_UL : return F ( " MIFARE Ultralight or Ultralight C " ) ;
case PICC_TYPE_MIFARE_PLUS : return F ( " MIFARE Plus " ) ;
case PICC_TYPE_TNP3XXX : return F ( " MIFARE TNP3XXX " ) ;
case PICC_TYPE_NOT_COMPLETE : return F ( " SAK indicates UID is not complete. " ) ;
case PICC_TYPE_UNKNOWN :
default : return F ( " Unknown type " ) ; break ;
default : return F ( " Unknown type " ) ;
}
} // End PICC_GetTypeName()
@@ -1347,7 +1338,7 @@ void MFRC522::PICC_DumpMifareClassicSectorToSerial(Uid *uid, ///< Pointer to U
MIFARE_Key * key , ///< Key A for the sector.
byte sector ///< The sector to dump, 0..39.
) {
byt e status ;
MFRC522 : : StatusCod e status ;
byte firstBlock ; // Address of lowest address to dump actually last block dumped)
byte no_of_blocks ; // Number of blocks in sector
bool isSectorTrailer ; // Set to true while handling the "last" (ie highest address) in the sector.
@@ -1491,7 +1482,7 @@ void MFRC522::PICC_DumpMifareClassicSectorToSerial(Uid *uid, ///< Pointer to U
* Dumps memory contents of a MIFARE Ultralight PICC.
*/
void MFRC522 : : PICC_DumpMifareUltralightToSerial ( ) {
byt e status ;
MFRC522 : : StatusCod e status ;
byte byteCount ;
byte buffer [ 18 ] ;
byte i ;
@@ -1575,7 +1566,7 @@ bool MFRC522::MIFARE_OpenUidBackdoor(bool logErrors) {
this will contain amount of valid response bits. */
byte response [ 32 ] ; // Card's response is written here
byte received ;
byt e status = PCD_TransceiveData ( & cmd , ( byte ) 1 , response , & received , & validBits , ( byte ) 0 , false ) ; // 40
MFRC522 : : StatusCod e status = PCD_TransceiveData ( & cmd , ( byte ) 1 , response , & received , & validBits , ( byte ) 0 , false ) ; // 40
if ( status ! = STATUS_OK ) {
if ( logErrors ) {
Serial . println ( F ( " Card did not respond to 0x40 after HALT command. Are you sure it is a UID changeable one? " ) ) ;
@@ -1641,7 +1632,7 @@ bool MFRC522::MIFARE_SetUid(byte *newUid, byte uidSize, bool logErrors) {
// Authenticate for reading
MIFARE_Key key = { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF } ;
byt e status = PCD_Authenticate ( MFRC522 : : PICC_CMD_MF_AUTH_KEY_A , ( byte ) 1 , & key , & uid ) ;
MFRC522 : : StatusCod e status = PCD_Authenticate ( MFRC522 : : PICC_CMD_MF_AUTH_KEY_A , ( byte ) 1 , & key , & uid ) ;
if ( status ! = STATUS_OK ) {
if ( status = = STATUS_TIMEOUT ) {
@@ -1737,7 +1728,7 @@ bool MFRC522::MIFARE_UnbrickUidSector(bool logErrors) {
byte block0_buffer [ ] = { 0x01 , 0x02 , 0x03 , 0x04 , 0x04 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 } ;
// Write modified block 0 back to card
byt e status = MIFARE_Write ( ( byte ) 0 , block0_buffer , ( byte ) 16 ) ;
MFRC522 : : StatusCod e status = MIFARE_Write ( ( byte ) 0 , block0_buffer , ( byte ) 16 ) ;
if ( status ! = STATUS_OK ) {
if ( logErrors ) {
Serial . print ( F ( " MIFARE_Write() failed: " ) ) ;