Skip to content

Commit

Permalink
codestyle and move new code to right pos
Browse files Browse the repository at this point in the history
- add doc and author
  • Loading branch information
Rotzbua committed Jan 4, 2016
1 parent 8188a10 commit 345f66a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 34 deletions.
76 changes: 43 additions & 33 deletions MFRC522.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,49 @@ MFRC522::StatusCode MFRC522::MIFARE_SetValue(byte blockAddr, long value) {
return MIFARE_Write(blockAddr, buffer, 16);
} // End MIFARE_SetValue()

/**
* Authenticate with a NTAG216.
*
* Only for NTAG216. First implemented by Gargantuanman.
*
* @param[in] passWord password.
* @param[in] pACK result success???.
* @return STATUS_OK on success, STATUS_??? otherwise.
*/
MFRC522::StatusCode MFRC522::PCD_NTAG216_AUTH(byte* passWord, byte pACK[]) //Authenticate with 32bit password
{
MFRC522::StatusCode result;
byte cmdBuffer[18]; // We need room for 16 bytes data and 2 bytes CRC_A.

cmdBuffer[0] = 0x1B; //Comando de autentificacion

for (byte i = 0; i<4; i++)
cmdBuffer[i+1] = passWord[i];

result = PCD_CalculateCRC(cmdBuffer, 5, &cmdBuffer[5]);

if (result!=STATUS_OK) {
return result;
}

// Transceive the data, store the reply in cmdBuffer[]
byte waitIRq = 0x30; // RxIRq and IdleIRq
byte cmdBufferSize = sizeof(cmdBuffer);
byte validBits = 0;
byte rxlength = 5;
result = PCD_CommunicateWithPICC(PCD_Transceive, waitIRq, cmdBuffer, 7, cmdBuffer, &rxlength, &validBits);

pACK[0] = cmdBuffer[0];
pACK[1] = cmdBuffer[1];

if (result!=STATUS_OK) {
return result;
}

return STATUS_OK;
} // End PCD_NTAG216_AUTH()


/////////////////////////////////////////////////////////////////////////////////////
// Support functions
/////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1768,36 +1811,3 @@ bool MFRC522::PICC_ReadCardSerial() {
byte result = PICC_Select(&uid);
return (result == STATUS_OK);
} // End

MFRC522::StatusCode MFRC522::PCD_NTAG216_AUTH(byte *passWord, byte pACK[]) //Authenticate with 32bit password
{
MFRC522::StatusCode result;
byte cmdBuffer[18]; // We need room for 16 bytes data and 2 bytes CRC_A.

cmdBuffer[0] = 0x1B; //Comando de autentificacion

for(byte i = 0; i < 4; i++)
cmdBuffer[i + 1] = passWord[i];

result = PCD_CalculateCRC(cmdBuffer, 5, &cmdBuffer[5]);

if (result != STATUS_OK) {
return result;
}

// Transceive the data, store the reply in cmdBuffer[]
byte waitIRq = 0x30; // RxIRq and IdleIRq
byte cmdBufferSize = sizeof(cmdBuffer);
byte validBits = 0;
byte rxlength = 5;
result = PCD_CommunicateWithPICC(PCD_Transceive, waitIRq, cmdBuffer, 7, cmdBuffer, &rxlength, &validBits);

pACK[0] = cmdBuffer[0];
pACK[1] = cmdBuffer[1];

if (result != STATUS_OK) {
return result;
}

return STATUS_OK;
}
1 change: 0 additions & 1 deletion MFRC522.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ class MFRC522 {
MFRC522::StatusCode MIFARE_GetValue(byte blockAddr, long *value);
MFRC522::StatusCode MIFARE_SetValue(byte blockAddr, long value);
MFRC522::StatusCode PCD_NTAG216_AUTH(byte *passWord, byte pACK[]);


/////////////////////////////////////////////////////////////////////////////////////
// Support functions
Expand Down

0 comments on commit 345f66a

Please sign in to comment.