Skip to content

Commit 5d8af28

Browse files
committed
Make blacklist universal for linux
1 parent 94bc7aa commit 5d8af28

File tree

4 files changed

+34
-48
lines changed

4 files changed

+34
-48
lines changed

.goreleaser.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ nfpms:
6464
- src: ./build/linux/nfc-agent.desktop
6565
dst: /usr/share/applications/nfc-agent.desktop
6666
type: config
67+
- src: ./build/linux/blacklist-nfc-pn533.conf
68+
dst: /etc/modprobe.d/blacklist-nfc-pn533.conf
69+
type: config
6770
scripts:
6871
postinstall: ./build/linux/postinstall.sh
6972

README.md

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -100,38 +100,22 @@ sudo systemctl enable --now pcscd
100100

101101
> **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
103-
**Atomic Linux Distributions (Fedora Silverblue, Kinoite, etc.) with Distrobox:**
103+
**Kernel Module Fix (tar.gz installations only)**
104104

105-
For immutable/atomic distributions, you can run NFC Agent inside a distrobox container while applying kernel fixes on the host OS:
105+
The `.deb` and `.rpm` packages automatically install the kernel module blacklist and unload conflicting modules. For tar.gz installations, you need to do this manually:
106106

107-
1. **On the host OS** - Apply the kernel module blacklist (required for ACR122U and similar readers):
108-
```bash
109-
# Create blacklist file on the host
110-
echo -e "blacklist pn533_usb\nblacklist pn533\nblacklist nfc" | sudo tee /etc/modprobe.d/blacklist-pn533.conf
111-
112-
# Unload modules if currently loaded
113-
sudo modprobe -r pn533_usb pn533 nfc 2>/dev/null || true
114-
115-
# Restart PC/SC daemon on host
116-
sudo systemctl restart pcscd
117-
```
118-
119-
2. **Inside distrobox** - Install the package:
120-
```bash
121-
# Enter your distrobox container (e.g., Fedora-based)
122-
distrobox enter fedora
107+
```bash
108+
# Blacklist conflicting kernel modules
109+
echo -e "blacklist pn533_usb\nblacklist pn533\nblacklist nfc" | sudo tee /etc/modprobe.d/blacklist-nfc-pn533.conf
123110

124-
# Install the RPM package
125-
sudo dnf install ./NFC-Agent-*.rpm
126-
```
111+
# Unload modules if currently loaded
112+
sudo modprobe -r pn533_usb pn533 nfc 2>/dev/null || true
127113

128-
3. **Run from distrobox** - Start NFC Agent from within the container:
129-
```bash
130-
distrobox enter fedora
131-
nfc-agent
132-
```
114+
# Restart PC/SC daemon
115+
sudo systemctl restart pcscd
116+
```
133117

134-
> **Note:** The kernel module blacklist must be applied on the host OS because the kernel is shared between the host and containers. The pcscd service also runs on the host and is accessible from within distrobox.
118+
> **Atomic Distributions (Fedora Silverblue, Kinoite, etc.):** You can run NFC Agent inside a distrobox container. Install the `.rpm` package in the container—the blacklist file will be installed to the shared `/etc/modprobe.d/` on the host. Alternatively, apply the kernel module fix manually on the host OS, then run `nfc-agent` from the container.
135119
136120
## Quick Start
137121

@@ -308,28 +292,11 @@ NFC Agent uses the PC/SC (Personal Computer/Smart Card) interface to communicate
308292
```
309293
3. Try unplugging and reconnecting the reader
310294

311-
**Linux: Kernel NFC modules conflict (ACR122U)**
312-
313-
The Linux kernel's NFC subsystem (`pn533_usb`) may claim ACR122U readers before pcscd can access them. Check with:
314-
```bash
315-
lsmod | grep pn533
316-
```
295+
**Linux: Kernel NFC modules conflict**
317296

318-
If modules are loaded, unload them and blacklist:
319-
```bash
320-
# Temporary fix
321-
sudo modprobe -r pn533_usb pn533 nfc
322-
sudo systemctl restart pcscd
297+
The Linux kernel's NFC subsystem may claim certain readers before pcscd can access them. The `.deb` and `.rpm` packages handle this automatically. For tar.gz installations, check with `lsmod | grep pn533`—if modules are loaded, follow the **Kernel Module Fix** steps in the [Linux installation section](#linux).
323298

324-
# Permanent fix - create blacklist file
325-
echo -e "blacklist pn533_usb\nblacklist pn533\nblacklist nfc" | sudo tee /etc/modprobe.d/blacklist-pn533.conf
326-
```
327-
328-
**Arch Linux with ACS readers:** Install the `acsccid` driver from AUR:
329-
```bash
330-
yay -S acsccid
331-
sudo systemctl restart pcscd
332-
```
299+
**Arch Linux with ACS readers:** Install the `acsccid` driver from AUR (`yay -S acsccid`) and restart pcscd.
333300

334301
### "Failed to connect to card"
335302

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Blacklist kernel NFC modules that conflict with PC/SC daemon (pcscd)
2+
# These modules may claim NFC readers (especially ACR122U) before pcscd can access them
3+
# Installed by NFC Agent package
4+
5+
blacklist pn533_usb
6+
blacklist pn533
7+
blacklist nfc

build/linux/postinstall.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
#!/bin/bash
22
# Post-installation script for NFC Agent
33

4+
# Unload kernel NFC modules that conflict with pcscd (if loaded)
5+
# The blacklist config file prevents them from loading on next boot
6+
if lsmod | grep -q pn533; then
7+
echo "Unloading conflicting kernel NFC modules..."
8+
modprobe -r pn533_usb 2>/dev/null || true
9+
modprobe -r pn533 2>/dev/null || true
10+
modprobe -r nfc 2>/dev/null || true
11+
fi
12+
413
# Ensure pcscd is running (required for NFC readers)
514
if command -v systemctl &> /dev/null; then
615
# Enable and start pcscd if available
716
systemctl enable pcscd 2>/dev/null || true
8-
systemctl start pcscd 2>/dev/null || true
17+
systemctl restart pcscd 2>/dev/null || true
918
fi
1019

1120
# Copy systemd user service to system location for all users

0 commit comments

Comments
 (0)