首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用PN532验证块

无法使用PN532验证块
EN

Stack Overflow用户
提问于 2018-03-21 10:42:46
回答 1查看 1.8K关注 0票数 0

我对Arduino很陌生。我正试图在我的NFC卡上写一个ID。我使用了示例中的PN532库和代码。我不能比authenticateBlock()更进一步。另外,哪个块试图进行身份验证?从输出上看不出来。

输出:

  • 发现1个标签
  • 社会福利署回应: 0x44
  • Sel响应: 0x0
  • 0x4 0xB9 0xC9 0xBA 0x20 0x4B 0x80
  • 读卡器#3122678656

守则是:

代码语言:javascript
复制
// 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);
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-22 09:26:32

SENS_RES (ATQA) = 0x0044、SEL_RES (SAK) = 0x00和UID = 0x04B9C9BA204B80的组合表明您的标记是MIFARE超光速标记或NTAG标记。但是,您在问题中显示的代码是为访问MIFARE经典标记而设计的。

MIFARE /NTAG标记不支持nfc.authenticateBlock()执行的身份验证机制(这是MIFARE特有的)。因此,代码将在nfc.authenticateBlock()上失败。由于您的标记不支持这种类型的身份验证(虽然它可能支持不同的机制),所以您可以尝试跳过身份验证步骤,只使用读/写方法。对于标记类型,这些应该可以工作(有一些限制,请参阅Byte array gets truncated when writing to memory of RFID tag using Adafruit PN532 library)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49404170

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档