Skip to content

Commit e600f98

Browse files
committed
Improved linux support, Fedora regular && atomic specifically
1 parent 8c446b4 commit e600f98

File tree

4 files changed

+638
-127
lines changed

4 files changed

+638
-127
lines changed

README.md

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,16 @@ sudo systemctl enable --now pcscd
8989
tar -xzf nfc-agent_*_linux_amd64.tar.gz
9090
sudo mv nfc-agent /usr/local/bin/
9191

92-
# Install PC/SC daemon
93-
sudo pacman -S pcsclite ccid # Arch (ccid provides USB reader drivers)
94-
sudo systemctl enable --now pcscd
92+
# Install PC/SC daemon and drivers
93+
sudo pacman -S pcsclite ccid
94+
95+
# For ACS readers (ACR122U, ACR1252U, etc.), install the ACS-specific driver from AUR:
96+
yay -S acsccid # or: paru -S acsccid
9597

96-
# Add your user to the pcscd group for reader access
97-
sudo usermod -a -G pcscd $USER
98-
# Log out and back in for group changes to take effect
98+
sudo systemctl enable --now pcscd
9999
```
100100

101-
> **Note:** Unlike the `.deb` and `.rpm` packages, the tar.gz installation requires manual setup of the PC/SC daemon and user permissions. If you see "No readers found", ensure `pcscd` is running (`systemctl status pcscd`) and that you've logged out/in after adding yourself to the `pcscd` group.
101+
> **Note:** Unlike the `.deb` and `.rpm` packages, the tar.gz installation requires manual setup of the PC/SC daemon. If you see "No readers found", ensure `pcscd` is running (`systemctl status pcscd`).
102102
103103
## Quick Start
104104

@@ -275,19 +275,40 @@ NFC Agent uses the PC/SC (Personal Computer/Smart Card) interface to communicate
275275
```
276276
3. Try unplugging and reconnecting the reader
277277

278+
**Linux: Kernel NFC modules conflict (ACR122U)**
279+
280+
The Linux kernel's NFC subsystem (`pn533_usb`) may claim ACR122U readers before pcscd can access them. Check with:
281+
```bash
282+
lsmod | grep pn533
283+
```
284+
285+
If modules are loaded, unload them and blacklist:
286+
```bash
287+
# Temporary fix
288+
sudo modprobe -r pn533_usb pn533 nfc
289+
sudo systemctl restart pcscd
290+
291+
# Permanent fix - create blacklist file
292+
echo -e "blacklist pn533_usb\nblacklist pn533\nblacklist nfc" | sudo tee /etc/modprobe.d/blacklist-pn533.conf
293+
```
294+
295+
**Arch Linux with ACS readers:** Install the `acsccid` driver from AUR:
296+
```bash
297+
yay -S acsccid
298+
sudo systemctl restart pcscd
299+
```
300+
278301
### "Failed to connect to card"
279302

280303
1. Ensure the card is placed correctly on the reader
281304
2. Some readers have an LED that indicates card detection
282305
3. Try a different card to rule out card issues
283306

284-
### Linux: Permission denied
307+
### Linux: "Rejected unauthorized PC/SC client"
285308

286-
Add your user to the `pcscd` group or run with elevated privileges:
287-
```bash
288-
sudo usermod -a -G pcscd $USER
289-
# Log out and back in for changes to take effect
290-
```
309+
On modern Linux distributions (Fedora, Silverblue, etc.), PC/SC access is controlled by Polkit. NFC Agent must run as part of your graphical session to be authorized.
310+
311+
**Solution:** Run `nfc-agent` directly from your terminal or use `nfc-agent install` to set up XDG autostart (starts automatically when you log in to your desktop).
291312

292313
## Contributing
293314

debug-pcsc.sh

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
#!/bin/bash
2+
# NFC Agent PC/SC Debug Script
3+
# Run this script to diagnose NFC reader detection issues
4+
5+
set -e
6+
7+
echo "========================================"
8+
echo "NFC Agent PC/SC Debug Report"
9+
echo "========================================"
10+
echo "Date: $(date)"
11+
echo "Hostname: $(hostname)"
12+
echo ""
13+
14+
# OS Info
15+
echo "=== OS Information ==="
16+
cat /etc/os-release | grep -E "^(NAME|VERSION|ID)="
17+
echo ""
18+
19+
# Check if running in container
20+
echo "=== Container Check ==="
21+
if [ -f /run/.containerenv ]; then
22+
echo "WARNING: Running inside a container!"
23+
cat /run/.containerenv
24+
elif [ -f /run/host/container-manager ]; then
25+
echo "Container manager: $(cat /run/host/container-manager)"
26+
else
27+
echo "Not running in a container (good)"
28+
fi
29+
echo ""
30+
31+
# USB Devices
32+
echo "=== USB Devices (NFC/Smartcard related) ==="
33+
lsusb 2>/dev/null | grep -iE "(acs|acr|smartcard|card reader|nfc|072f|04e6|076b|1a44)" || echo "No NFC/smartcard USB devices found"
34+
echo ""
35+
echo "All USB devices:"
36+
lsusb 2>/dev/null || echo "lsusb not available"
37+
echo ""
38+
39+
# Check for conflicting kernel modules
40+
echo "=== Kernel NFC Modules (potential conflict!) ==="
41+
if lsmod | grep -qE "(pn533|nfc)"; then
42+
echo "WARNING: NFC kernel modules are loaded!"
43+
lsmod | grep -E "(pn533|nfc)"
44+
echo ""
45+
echo "These modules may claim your reader before pcscd can access it."
46+
echo "To fix: sudo modprobe -r pn533_usb pn533 nfc"
47+
echo "To make permanent: create /etc/modprobe.d/blacklist-pn533.conf with:"
48+
echo " blacklist pn533_usb"
49+
echo " blacklist pn533"
50+
echo " blacklist nfc"
51+
else
52+
echo "No conflicting NFC kernel modules loaded (good)"
53+
fi
54+
echo ""
55+
56+
# pcscd status
57+
echo "=== pcscd Service Status ==="
58+
systemctl status pcscd --no-pager 2>&1 | head -20 || echo "Could not get pcscd status"
59+
echo ""
60+
61+
# pcscd socket
62+
echo "=== pcscd Socket ==="
63+
ls -la /run/pcscd/ 2>/dev/null || echo "/run/pcscd/ not found - pcscd may not be running"
64+
echo ""
65+
66+
# Installed packages
67+
echo "=== Installed PC/SC Packages ==="
68+
if command -v rpm &>/dev/null; then
69+
rpm -qa | grep -iE "(pcsc|ccid|scard)" 2>/dev/null || echo "No PC/SC packages found via rpm"
70+
fi
71+
if command -v rpm-ostree &>/dev/null; then
72+
echo ""
73+
echo "rpm-ostree layered packages:"
74+
rpm-ostree status 2>/dev/null | grep -A20 "Layered packages:" | head -25 || echo "No layered packages"
75+
fi
76+
echo ""
77+
78+
# Polkit check
79+
echo "=== Polkit Authorization Test ==="
80+
if command -v pkcheck &>/dev/null; then
81+
echo "Testing org.debian.pcsc-lite.access_pcsc for current process..."
82+
if pkcheck --action-id org.debian.pcsc-lite.access_pcsc --process $$ 2>&1; then
83+
echo "SUCCESS: Current session is authorized for PC/SC access"
84+
else
85+
echo "FAILED: Current session is NOT authorized for PC/SC access"
86+
echo ""
87+
echo "This is likely the issue! Your session is not recognized as 'active' by polkit."
88+
echo "Solutions:"
89+
echo " 1. Run nfc-agent directly from a terminal in your graphical session"
90+
echo " 2. Use 'nfc-agent install' to set up XDG autostart"
91+
fi
92+
else
93+
echo "pkcheck not available"
94+
fi
95+
echo ""
96+
97+
# Session info
98+
echo "=== Session Information ==="
99+
echo "Current user: $(whoami) (UID: $(id -u))"
100+
echo "Groups: $(groups)"
101+
loginctl list-sessions --no-legend 2>/dev/null || echo "loginctl not available"
102+
echo ""
103+
if command -v loginctl &>/dev/null; then
104+
SESSION_ID=$(loginctl list-sessions --no-legend 2>/dev/null | grep "$(whoami)" | head -1 | awk '{print $1}')
105+
if [ -n "$SESSION_ID" ]; then
106+
echo "Session $SESSION_ID details:"
107+
loginctl show-session "$SESSION_ID" 2>/dev/null | grep -E "^(Active|State|Class|Type|Seat|Remote|Display)=" || true
108+
fi
109+
fi
110+
echo ""
111+
112+
# pcsc_scan test
113+
echo "=== pcsc_scan Test (5 seconds) ==="
114+
if command -v pcsc_scan &>/dev/null; then
115+
timeout 5 pcsc_scan 2>&1 || true
116+
else
117+
echo "pcsc_scan not installed. Install with:"
118+
echo " Fedora: sudo dnf install pcsc-tools"
119+
echo " Arch: sudo pacman -S pcsc-tools"
120+
echo " rpm-ostree: sudo rpm-ostree install pcsc-tools"
121+
fi
122+
echo ""
123+
124+
# Direct scard test using our debug utility
125+
echo "=== Direct PC/SC Connection Test ==="
126+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
127+
if [ -f "$SCRIPT_DIR/nfc-agent" ]; then
128+
echo "Testing with nfc-agent binary..."
129+
timeout 5 "$SCRIPT_DIR/nfc-agent" --no-tray &
130+
AGENT_PID=$!
131+
sleep 2
132+
133+
echo "Querying readers via API:"
134+
curl -s http://127.0.0.1:32145/v1/readers 2>/dev/null || echo "Could not connect to nfc-agent API"
135+
echo ""
136+
137+
echo "Querying logs:"
138+
curl -s http://127.0.0.1:32145/v1/logs 2>/dev/null | head -50 || echo "Could not get logs"
139+
140+
kill $AGENT_PID 2>/dev/null || true
141+
else
142+
echo "nfc-agent binary not found in script directory"
143+
fi
144+
echo ""
145+
146+
# pcscd journal logs
147+
echo "=== Recent pcscd Logs ==="
148+
journalctl -u pcscd --no-pager -n 30 2>/dev/null || echo "Could not get pcscd journal logs"
149+
echo ""
150+
151+
# Summary
152+
echo "========================================"
153+
echo "Debug Summary"
154+
echo "========================================"
155+
echo ""
156+
echo "Common issues and solutions:"
157+
echo ""
158+
echo "1. KERNEL NFC MODULES CONFLICT (most common for ACR122U!)"
159+
echo " - The pn533_usb module claims the reader before pcscd"
160+
echo " - Fix: sudo modprobe -r pn533_usb pn533 nfc"
161+
echo " - Permanent: echo 'blacklist pn533_usb' | sudo tee /etc/modprobe.d/blacklist-pn533.conf"
162+
echo ""
163+
echo "2. NO USB DEVICE DETECTED"
164+
echo " - Check USB cable and connection"
165+
echo " - Try a different USB port"
166+
echo " - Run 'lsusb' to verify device is visible"
167+
echo ""
168+
echo "3. PCSCD NOT RUNNING"
169+
echo " - Run: sudo systemctl enable --now pcscd"
170+
echo ""
171+
echo "4. POLKIT AUTHORIZATION FAILED"
172+
echo " - Run nfc-agent from a graphical terminal (not SSH, not a container)"
173+
echo " - Use 'nfc-agent install' for XDG autostart"
174+
echo ""
175+
echo "5. MISSING DRIVERS (rpm-ostree systems)"
176+
echo " - Run: sudo rpm-ostree install pcsc-lite pcsc-lite-ccid"
177+
echo " - Reboot after installation"
178+
echo ""
179+
echo "6. ACS READERS ON ARCH LINUX"
180+
echo " - Install acsccid from AUR: yay -S acsccid"
181+
echo ""

0 commit comments

Comments
 (0)