Jump to content

NFC

From ArchWiki

Near-field communication devices have become pretty easy to operate and read out under Linux. This page explains how to quickly set up the most common NFC scanners.

Installation

Install ccid, libnfc, acsccid, pcsclite and pcsc-tools.

The pcsclite package ships a pcscd.socket which will cause the pcscd server to start when a program requests it. Alternatively, you can manually start/enable the pcscd.service.

After installing libnfc, it is important that you re-plug your card reader as it ships with a few udev rules and kernel module blacklist that need to load before loading the actual driver.

Scanning an NFC card

Now everything should already be in place for a test scan. Plug in your NFC reader and run pcsc_scan. This tool will try to communicate with your scanner and also poll for any NFC cards placed on your scanner. If you try to scan a card after the tool has found your scanner, you should see events printed on your terminal.

$ pcsc_scan
Using reader plug'n play mechanism
Scanning present readers...
0: ACS ACR122U 00 00
 
Sun Sep  5 05:15:10 2021
 Reader 0: ACS ACR122U 00 00
  Event number: 0
  Card state: Card removed,

Supported devices

See https://ccid.apdu.fr/#readers for a list of scanners supported by ccid and https://nfc-tools.github.io/resources/ by libnfc.

Troubleshooting

In case things do not seem to work, investigate the log of pcscd.service

NXP NCI 2.0 controllers (PN7150/PN7160) — tags not detected

Some laptops (notably ASUS ROG models with a Keystone slot) have a built-in NXP NFC controller connected via I2C. The kernel driver nxp-nci_i2c may load successfully and RF polling appears active in dmesg, but no tags are ever discovered.

This is caused by three bugs in the upstream nci and nxp-nci kernel modules affecting NCI 2.0 protocol handling. As of kernel 6.18, these are not yet fixed upstream.

Check if you are affected:

$ dmesg | grep -i nxp-nci
$ cat /sys/class/nfc/nfc*/name

If RF polling starts but RF_INTF_ACTIVATED_NTF never appears, see linux-nxp-nfc-fix for patched DKMS modules.

Known ACPI IDs: NXP1001, NXP1002, NXP3001, NXP7471.