[英]Can not get PACK with PWD_AUTH command of NTAG213 using PN532
[英]Can't authenticate block with PN532
我是Arduino的新手。 我正在嘗試將ID寫入我的NFC卡。 我使用了示例中的PN532庫和代碼。 除了authenticateBlock()
我走得更遠。 另外,哪個塊正在嘗試進行身份驗證? 我在輸出中看不到它。
輸出:
代碼是:
// This example writes a MIFARE memory block 0x08. It is tested with a new MIFARE 1K cards. Uses default keys.
// Note: Memory block 0 is readonly and contains manufacturer data. Do not write to Sector Trailer block
// unless you know what you are doing. Otherwise, the MIFARE card may be unusable in the future.
//Contributed by Seeed Technology Inc (www.seeedstudio.com)
#include <PN532.h>
#include <SPI.h>
/*Chip select pin can be connected to D10 or D9 which is hareware optional*/
/*if you the version of NFC Shield from SeeedStudio is v2.0.*/
#define PN532_CS 10
PN532 nfc(PN532_CS);
uint8_t written = 0;
#define NFC_DEMO_DEBUG 1
void setup(void) {
#ifdef NFC_DEMO_DEBUG
Serial.begin(9600);
Serial.println("Hello!");
#endif
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
#ifdef NFC_DEMO_DEBUG
Serial.print("Didn't find PN53x board");
#endif
while (1); // halt
}
#ifdef NFC_DEMO_DEBUG
// Got ok data, print it out!
Serial.print("Found chip PN5");
Serial.println((versiondata >> 24) & 0xFF, HEX);
Serial.print("Firmware ver. ");
Serial.print((versiondata >> 16) & 0xFF, DEC);
Serial.print('.');
Serial.println((versiondata >> 8) & 0xFF, DEC);
Serial.print("Supports ");
Serial.println(versiondata & 0xFF, HEX);
#endif
// configure board to read RFID tags and cards
nfc.SAMConfig();
}
void loop(void) {
uint32_t id;
// look for MiFare type cards
id = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A);
if (id != 0) {
#ifdef NFC_DEMO_DEBUG
Serial.print("Read card #");
Serial.println(id);
Serial.println();
#endif
uint8_t keys[] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
};
uint8_t writeBuffer[16];
for (uint8_t i = 0; i < 16; i ++) {
writeBuffer[i] = i; //Fill buffer with 0,1,2....F
}
if (nfc.authenticateBlock(1, id , 0x08, KEY_A, keys)) {
//authenticate block 0x08
//if authentication successful
if (written == 0) {
//Not written
written = nfc.writeMemoryBlock(1, 0x08, writeBuffer); // Write writeBuffer[] to block 0x08
if (written)
#ifdef NFC_DEMO_DEBUG
Serial.println("Write Successful");
#endif
}
uint8_t block[16];
//read memory block 0x08
if (nfc.readMemoryBlock(1, 0x08, block)) {
#ifdef NFC_DEMO_DEBUG
Serial.println("Read block 0x08:");
//if read operation is successful
for (uint8_t i = 0; i < 16; i++) {
//print memory block
Serial.print(block[i], HEX);
Serial.print(" ");
}
Serial.println();
#endif
}
}
}
delay(500);
}
SENS_RES(ATQA)= 0x0044,SEL_RES(SAK)= 0x00和UID = 0x04B9C9BA204B80的組合表明您的標簽是MIFARE Ultralight標簽或NTAG標簽。 但是,您在問題中顯示的代碼旨在訪問MIFARE Classic標簽。
MIFARE Ultralight / NTAG標簽不支持nfc.authenticateBlock()
(特定於MIFARE Classic)執行的身份驗證機制。 結果,代碼將在nfc.authenticateBlock()
上失敗。 由於您的標簽不支持該類型的身份驗證(盡管它可能支持其他機制),所以您可以嘗試跳過身份驗證步驟,而僅使用讀/寫方法。 對於您的標簽類型,它們應該可以工作(有一些限制,請參見在使用Adafruit PN532庫寫入RFID標簽的內存時字節數組被截斷 )。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.