简体   繁体   English

使用 PN532 和 ArduinoMega 从 android 手机读取 NFC UID

[英]Reading NFC UID from android phone with PN532 and ArduinoMega

I am trying to use the PN532 to read my NFC UID from phone(Samsung Galaxy S10), but i receive just 08 and another 3 digits of random values.I read that a value that start with 08 is a RID(Random ID).我正在尝试使用 PN532 从手机(三星 Galaxy S10)读取我的 NFC UID,但我只收到 08 和另外 3 位随机值。我读到以 08 开头的值是 RID(随机 ID)。 Is there any possible way to read just a unique value, or use the PN532 to read something that is unique from my phones NFC?是否有任何可能的方法来读取唯一值,或使用 PN532 从我的手机 NFC 中读取唯一值? I want to use that value to compare it with a constant in my code and send an impulse to a relay to open a door.我想使用该值将其与我的代码中的常量进行比较,并向继电器发送一个脉冲以打开一扇门。 This code is from da Adafruit_PN532 library.此代码来自 da Adafruit_PN532 库。

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_PN532.h>

#define PN532_IRQ   (2)
#define PN532_RESET (3)  // Not connected by default on the NFC Shield

// Or use this line for a breakout or shield with an I2C connection:
Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);

void setup(void) {
  Serial.begin(115200);
  Serial.println("Hello!");

  nfc.begin();

  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1); // halt
  }

  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);

  // configure board to read RFID tags
  nfc.SAMConfig();

  Serial.println("Waiting for an ISO14443A Card ...");
}


void loop(void) {
  uint8_t success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
  uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)

  // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
  // 'uid' will be populated with the UID, and uidLength will indicate
  // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

  if (success) {
    // Display some basic information about the card
    Serial.println("Found an ISO14443A card");
    Serial.print("  UID Length: "); Serial.print(uidLength, DEC); Serial.println(" bytes");
    Serial.print("  UID Value: ");
    nfc.PrintHex(uid, uidLength);

    if (uidLength == 4) {
      // We probably have a Mifare Classic card ...
      uint32_t cardid = uid[0];
      cardid <<= 8;
      cardid |= uid[1];
      cardid <<= 8;
      cardid |= uid[2];
      cardid <<= 8;
      cardid |= uid[3];
      Serial.print("Seems to be a Mifare Classic card #");
      Serial.println(cardid);
    }
    delay(2000);
  }
}

Do not use the NFC UID for any security purpose, as you can see a phone does give a random one for privacy purposes.不要将 NFC UID 用于任何安全目的,因为您可以看到手机出于隐私目的确实会随机提供一个。

The NFC UID is designed only to help reading hardware deal with handling sending data to the right card when multiple different Tags are in range. NFC UID 仅用于帮助读取硬件处理当多个不同标签在范围内时向正确卡发送数据的处理。 There is no guarantee that the UID is actually Unique and that it cannot duplicated (even with Tag that are supposed to have it programmed at the factory you can buy clones from China where they can be programmed by the end user).不能保证 UID 实际上是唯一的并且不能复制(即使使用应该在工厂对其进行编程的标签,您也可以从中国购买克隆,最终用户可以对其进行编程)。

It is better to use cryptographic methods with data stored on a tag or emulated Tag if using a phone to provide uniqueness to use a Tag for anything with security implications.如果使用电话提供唯一性以将标签用于具有安全隐患的任何事物,则最好使用加密方法与存储在标签或模拟标签上的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM