Using libnfc with PN532Killer

Prerequisites

  1. Hardware
    • PN532Killer or any PN532-based NFC reader
    • NFC cards (e.g., Mifare Classic 1K/4K)
  2. System Requirements
    • Windows / Linux / macOS (with Homebrew installed)
    • Terminal (e.g., iTerm2 or macOS Terminal)

Step 1: Install libnfc

Install libnfc via Homebrew:

brew install libnfc

Step 2: Connect PN532Killer and Identify Port

  1. Connect the PN532Killer to your Mac via USB.
  2. List available USB serial ports using:
ls /dev/tty.usb*

Example output:

/dev/tty.usbmodem14201

Note the port name (e.g., tty.usbmodem14201).

Step 3: Configure libnfc

  1. Edit the libnfc configuration file:
sudo nano /usr/local/etc/nfc/libnfc.conf
  1. Update the configuration (replace with your actual port):
device.name = "PN532Killer"
device.connstring = "pn532_uart:/dev/tty.usbmodem14201"

Save and exit

Step 4: Verify Device Connection

Test the NFC reader with:

nfc-list

Successful output example:

nfc-list uses libnfc 1.8.0
NFC device: pn532 opened
No NFC device found.  # Displayed if no card is detected

Step 5: Basic Operations

1. Read Card Information

Place a card near the reader and run:

nfc-list

Example output:

1 ISO14443A passive target(s) found:
ISO/IEC 14443A (106 kbps) target:
    ATQA (SENS_RES): 00  04
       UID (NFCID1): aa  bb  cc  dd
      SAK (SEL_RES): 08

2. Read/Write Mifare Classic Cards

  • Read card data to a file:
nfc-mfclassic r a dump.mfd
  • r: Read operation
  • a: Authenticate with Key A
  • dump.mfd: Output filename
    • Write data to a card:
nfc-mfclassic w a dump.mfd

3. Modify UID of Gen1A Cards

Use nfc-mfsetuid to change the UID (only works with writable Gen1A cards):

nfc-mfsetuid 11223344 -q
  • 11223344: New UID (4-byte hex, e.g., 11 22 33 44)
  • -q: Quiet mode (optional)

Verify the change:

nfc-list

Example output:

UID (NFCID1): 11  22  33  44

Troubleshooting

  1. Permission Denied
    If encountering Permission denied, run:
sudo chmod 777 /dev/tty.usbmodem*
  1. Device Not Found
    • Ensure the USB connection is stable
    • Verify the port name in libnfc.conf
  2. UID Modification Fails
    • Confirm the card is Gen1A and supports UID writing
    • Use -f to force writing (use cautiously):
nfc-mfsetuid 11223344 -f

Important Notes

  • Legal Compliance: Modifying UIDs may violate local laws. Ensure ethical use.
  • Backup Data: Always back up card data before operations.
  • Compatibility: Gen2 cards (e.g., Mifare Classic 1K) typically have locked UIDs.

For advanced features, refer to the libnfc documentation.