Skip to content

Instantly share code, notes, and snippets.

@pjobson
Last active January 15, 2025 04:48
Show Gist options
  • Save pjobson/de187415b301f9e4407cc6e16c002379 to your computer and use it in GitHub Desktop.
Save pjobson/de187415b301f9e4407cc6e16c002379 to your computer and use it in GitHub Desktop.
Installing USB Advanced Card Systems, Ltd ACR122U NFC Reader / Writer (Debian, Mint, Ubuntu)

Installing USB Advanced Card Systems, Ltd ACR122U NFC Reader / Writer (Debian, Mint, Ubuntu)

ACR122U

Intro

I've found a lot of conflicting information on getting one of these up and running on Debian/Ubuntu/Mint, this is a guide to what I did to get mine working. This was tested on Orange Pi 1.0.2 Bookworm aarch64 and Linux Mint 21.3 x86_64.

The OrangePi (and possibly other SBC devices) does not provide enough power to the USB port to activate the reader. You will need to get a powered USB hub.

End of Life / Clone Note

GoToTags the original manufacturer of ACR122U devices no longer manages them. All devices currently listed on Amazon/eBay/AliExpress are clones of the original. The company reasonably does not offer support for these clones.

Citation: nfc-tools/libnfc#659

Device

These are cheap NFC reader/writers you can get on Amazon and AliExpress with various weird branding for $10-$30.
They're frequented branded as NFC Reader Writer USB NFC Smart IC Card Reader Writer Copier Duplicator Contactless 13.56MHz 424kbps for FeliCa NFC Tags. They're all essentiall the same USB device using a ACR122U chip.

This should appear as the following using lsusb -v.

Bus 001 Device 003: ID 072f:2200 Advanced Card Systems, Ltd ACR122U
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x072f Advanced Card Systems, Ltd
  idProduct          0x2200 ACR122U
  bcdDevice            2.14
  iManufacturer           1 ACS
  iProduct                2 ACR122U PICC Interface
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x005d
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              200mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           3
      bInterfaceClass        11 Chip/SmartCard
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              0 
      ChipCard Interface Descriptor:
        bLength                54
        bDescriptorType        33
        bcdCCID              1.00
        nMaxSlotIndex           0
        bVoltageSupport         7  5.0V 3.0V 1.8V 
        dwProtocols             2  T=1
        dwDefaultClock       4000
        dwMaxiumumClock      4000
        bNumClockSupported      0
        dwDataRate          10752 bps
        dwMaxDataRate      250000 bps
        bNumDataRatesSupp.      0
        dwMaxIFSD             256
        dwSyncProtocols  00000000 
        dwMechanical     00000000 
        dwFeatures       00020040
          Auto parameter negotiation made by CCID
          Short APDU level exchange
        dwMaxCCIDMsgLen       271
        bClassGetResponse      00
        bClassEnvelope         00
        wlcdLayout           none
        bPINSupport             0 
        bMaxCCIDBusySlots       1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval              50
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1
Device Status:     0x0002
  (Bus Powered)
  Remote Wakeup Enabled

Install

purge libnfc6, ignore if not found

sudo apt purge libnfc6 

disable / remove these, ignore if not found

sudo modprobe -r pn533_usb
sudo modprobe -r pn533
sudo modprobe -r nfc

remove thes mods from the kernel, ignore if not found

sudo rmmod pn533_usb
sudo rmmod pn533
sudo rmmod nfc

blacklist these

sudo touch /etc/modprobe.d/blacklist-libnfc.conf
echo "blacklist nfc"       | sudo tee -a /etc/modprobe.d/blacklist-libnfc.conf > /dev/null
echo "blacklist pn533"     | sudo tee -a /etc/modprobe.d/blacklist-libnfc.conf > /dev/null
echo "blacklist pn533_usb" | sudo tee -a /etc/modprobe.d/blacklist-libnfc.conf > /dev/null

install some packages

sudo apt install -y \
  pcscd pcsc-tools \
  libacsccid1 libtool libusb-dev  \
  libpcsclite-dev libnfc-dev \
  build-essential libssl-dev \
  libusb-1.0-0-dev libglib2.0-dev \
  doxygen

clone modified libnfc, build, and install

Errors

You will need to use this modified libnfc to avoid some errors from the regular distributed libnfc.

If you use stock, you'll see stuff like.

nfc-list uses libnfc 1.7.1
error   libnfc.driver.acr122_usb    Unable to set alternate setting on USB interface (Connection timed out)
nfc-list: ERROR: Unable to open NFC device: acr122_usb:004:005

nfc-list uses libnfc 1.7.1
error   libnfc.driver.acr122_usb    Unable to set alternate setting on USB interface (Connection timed out)
nfc-list: ERROR: Unable to open NFC device: acr122_usb:004:007
nfc-list: ERROR: Unable to open NFC device: acr122_pcsc:ACS ACR122U 00 00

nfc-list uses libnfc 1.7.1
error   libnfc.driver.acr122_usb    Unable to set alternate setting on USB interface (Connection timed out)
nfc-list: ERROR: Unable to open NFC device: acr122_usb:004:007
error   libnfc.driver.acr122_pcsc   No ACR122 firmware received, Error: 80100016
nfc-list: ERROR: Unable to open NFC device: acr122_pcsc:ACS ACR122U 00 00

Install

I did try building from the original source here and had no luck. I forked my branch as listed to clone from jpwidera/libnfc in case the original is deleted or removed.

git clone https://github.com/pjobson/libnfc.git
cd libnfc
./make_release.sh
./configure
sudo make
sudo make install
cd ..
rm -rf libnfc

add /usr/local/lib to usr-local-lib.conf

sudo sh -c "echo /usr/local/lib > /etc/ld.so.conf.d/usr-local-lib.conf"
sudo ldconfig

chmod the /dev/bus/usb path

This fixes a permissionns error and we will give your user access below.

Error Message: Unable to claim USB interface (Operation not permitted)

sudo chgrp -R plugdev /dev/bus/usb
sudo chmod -R g+w /dev/bus/usb

add user to plugdev

sudo usermod -aG plugdev $USER

PC/SC Smart Card Daemon

sudo systemctl enable pcscd
sudo systemctl status pcscd

Should return:

● pcscd.service - PC/SC Smart Card Daemon
     Loaded: loaded (/lib/systemd/system/pcscd.service; indirect; vendor preset: enabled)
     Active: active (running) since Tue 2025-01-14 23:44:16 EST; 2s ago
TriggeredBy: ● pcscd.socket
       Docs: man:pcscd(8)
   Main PID: 3932739 (pcscd)
      Tasks: 3 (limit: 45347)
     Memory: 896.0K
        CPU: 19ms
     CGroup: /system.slice/pcscd.service
             └─3932739 /usr/sbin/pcscd --foreground --auto-exit

Jan 14 23:44:16 fourninefive systemd[1]: Started PC/SC Smart Card Daemon.

Test

List NFC targets

nfc-list

Should return:

nfc-list uses libnfc libnfc-1.7.1-226-g07f9182
NFC device: ACS / ACR122U PICC Interface opened

Scan NFC devices

nfc-scan-device

Should return:

nfc-scan-device uses libnfc 1.7.1
1 NFC device(s) found:
- ACS / ACR122U PICC Interface:
    acr122_usb:002:012

Scan

pcsc_scan

Should show...

PC/SC device scanner
V 1.6.2 (c) 2001-2022, Ludovic Rousseau <[email protected]>
Using reader plug'n play mechanism
Scanning present readers...
0: ACS ACR122U 00 00

Sun Dec 29 00:45:36 2024
 Reader 0: ACS ACR122U 00 00
  Event number: 0
  Card state: Card removed, 
  ATR: 3B 00

ATR: 3B 00
+ TS = 3B --> Direct Convention
+ T0 = 00, Y(1): 0000, K: 0 (historical bytes)

This will cycle until you tap a card, then should update the state to Card inserted and show the card's data. For example here is a generic card I got from AliExpress.

Mon Dec 30 04:18:46 2024
 Reader 0: ACS ACR122U 00 00
  Event number: 3
  Card state: Card inserted,
  ATR: 3B 8F 80 01 80 4F 0C A0 00 00 03 06 03 00 01 00 00 00 00 6A

ATR: 3B 8F 80 01 80 4F 0C A0 00 00 03 06 03 00 01 00 00 00 00 6A
+ TS = 3B --> Direct Convention
+ T0 = 8F, Y(1): 1000, K: 15 (historical bytes)
  TD(1) = 80 --> Y(i+1) = 1000, Protocol T = 0
-----
  TD(2) = 01 --> Y(i+1) = 0000, Protocol T = 1
-----
+ Historical bytes: 80 4F 0C A0 00 00 03 06 03 00 01 00 00 00 00
  Category indicator byte: 80 (compact TLV data object)
    Tag: 4, len: F (initial access data)
      Initial access data: 0C A0 00 00 03 06 03 00 01 00 00 00 00
+ TCK = 6A (correct checksum)

Possibly identified card (using /usr/share/pcsc/smartcard_list.txt):
3B 8F 80 01 80 4F 0C A0 00 00 03 06 03 00 01 00 00 00 00 6A
3B 8F 80 01 80 4F 0C A0 00 00 03 06 .. 00 01 00 00 00 00 ..
  MIFARE Classic 1K (as per PCSC std part3)
3B 8F 80 01 80 4F 0C A0 00 00 03 06 03 00 01 00 00 00 00 6A
3B 8F 80 01 80 4F 0C A0 00 00 03 06 03 .. .. 00 00 00 00 ..
  RFID - ISO 14443 Type A Part 3 (as per PCSC std part3)
3B 8F 80 01 80 4F 0C A0 00 00 03 06 03 00 01 00 00 00 00 6A
  NXP/Philips MIFARE Classic 1K (as per PCSC std part3)
  http://www.nxp.com/#/pip/pip=[pfp=41863]|pp=[t=pfp,i=41863]
  Oyster card - Transport for London (first-gen)
  https://en.wikipedia.org/wiki/Oyster_card
  ACOS5/1k Mirfare
  vivotech ViVOcard Contactless Test Card
  Bangkok BTS Sky SmartPass
  Mifare Classic 1K (block 0 re-writeable)
  Electic vehicle charging card of the German Telekom, acting as EMSP GetCharge
  Electic vehicle charging card of the EMSP Stadtwerke Muenchen (SWM), ladenetz.de, Germany
  Electic vehicle charging card of the EMSP EinfachStromLaden of Maingau-Energie, Germany
  Scouter carsharing customer card in Germany
  https://scouter.de/

Then when the card it removed, it should update the state back to Card removed.

Mon Dec 30 04:18:47 2024
 Reader 0: ACS ACR122U 00 00
  Event number: 4
  Card state: Card removed,

Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment