Skip to content
Alejandro Mora edited this page May 8, 2026 · 1 revision

Linux Daemon (infrafid)

infrafid is the server-side component of InfraFi. It listens for IR transmissions from the Flipper Zero, decodes the WiFi credentials, and uses them to connect the Linux machine to a WiFi network.


Building

Requires GCC and Linux kernel headers (linux/lirc.h).

cd daemon
make

To install and enable as a systemd service:

sudo ./install.sh

The installer:

  1. Detects LIRC or evdev hardware
  2. Configures the IR receiver for RC-6 and NEC protocols
  3. Creates a udev rule (/etc/udev/rules.d/99-infrafid-ir.rules) to persist protocol config across reboots
  4. Builds and installs the binary
  5. Enables and starts the infrafid.service

CLI Reference

Usage: infrafid [options]

Options:
  -d, --device PATH       LIRC device for RX (default: /dev/lirc0)
  -e, --evdev PATH        Use evdev input device for RX (NEC via MSC_RAW)
  -s, --serial PATH       Serial device for Arduino IR transceiver
  -a, --ack-device PATH   LIRC device for ACK TX (default: same as --device)
  -f, --foreground        Run in foreground (don't daemonize)
  -v, --verbose           Verbose/debug logging
  -V, --version           Show version and exit
  -h, --help              Show help

Mutually exclusive: --evdev and --serial cannot be used together.


Usage Examples

# LIRC receiver, foreground with verbose logging (most common for testing)
sudo infrafid -f -v

# Different RX device
sudo infrafid -d /dev/lirc1 -f -v

# Separate TX device for ACK (RX on lirc0, ACK on lirc1)
sudo infrafid -d /dev/lirc0 -a /dev/lirc1

# Arduino serial backend (handles both RX and TX ACK)
sudo infrafid -s /dev/ttyACM0 -f -v

# Arduino RX with separate LIRC device for ACK TX
sudo infrafid -s /dev/ttyACM0 -a /dev/lirc1

# evdev input (e.g. Squeezebox Touch)
sudo infrafid -e /dev/input/event1 -f -v

Receiver Backends

LIRC (-d /dev/lirc0)

The default backend. Opens the LIRC device in LIRC_MODE_SCANCODE mode, which uses kernel-level RC-6/NEC decoding. This avoids the hardware FIFO overflow problems that occur with raw mode on small CIR chips like the ITE8708.

Requires /dev/lirc0 (or specified device) and the corresponding kernel RC decoder enabled.

evdev (-e /dev/input/eventN)

For devices that expose IR via the Linux input subsystem using MSC_RAW events. NEC protocol only, using FAB4-style bit ordering (as found on Squeezebox Touch and similar embedded Linux devices).

Serial / Arduino (-s /dev/ttyACMx)

For use with an Arduino Pro Micro running the InfraFi firmware. The daemon opens the serial device, performs a handshake with the Arduino, and reads decoded RC-6 scancodes from it. The same connection is used to command the Arduino's IR LED for ACK transmission.

See Arduino Firmware for setup details.


ACK Transmission

After a connection attempt (success or failure), the daemon can send an IR response back to the Flipper. The response uses the same frame format as the incoming transmission.

  • Success payload: OK:192.168.1.102 (includes the assigned IP)
  • Failure payload: FAIL

The Flipper waits up to 30 seconds for an ACK before timing out. ACK must be enabled in the Flipper app settings.

ACK with LIRC TX:

sudo infrafid -d /dev/lirc0 -a /dev/lirc1

ACK with Arduino serial (both RX and TX on same connection):

sudo infrafid -s /dev/ttyACM0

If the TX device cannot be opened, ACK is silently disabled and the daemon continues operating in RX-only mode.


Network Management

infrafid supports two network management systems and automatically detects which one is active:

NetworkManager (preferred)

If nmcli is available and NetworkManager is running, the daemon uses it:

nmcli device wifi connect "<SSID>" password "<password>"

For hidden networks:

nmcli device wifi connect "<SSID>" password "<password>" hidden yes

ifupdown (fallback)

If NetworkManager is not detected, the daemon falls back to writing /etc/network/interfaces and running ifdown/ifup.


Rollback on Failure

Before attempting to connect to a new network, the daemon saves the currently active SSID. If the connection attempt fails:

  1. The daemon sends a FAIL ACK to the Flipper.
  2. It attempts to reconnect to the previous network using the saved SSID.
  3. If rollback also fails, a warning is logged and manual intervention may be needed.

This prevents the machine from being left disconnected if bad credentials are sent.


Systemd Service

The systemd unit file is installed at /etc/systemd/system/infrafid.service.

systemctl status infrafid      # Check service status
systemctl restart infrafid     # Restart
journalctl -u infrafid -f      # Follow logs

Service configuration: To pass custom arguments to the daemon, create /etc/default/infrafid:

# /etc/default/infrafid
INFRAFID_ARGS="--serial /dev/ttyACM0 --verbose"

Then restart the service.


Logging

infrafid logs to syslog (facility LOG_DAEMON). When run with -f (foreground), logs also print to stderr.

With -v (verbose), debug-level messages are included, including raw scancode values.

# View recent logs
journalctl -u infrafid --since "1 hour ago"

# Follow live
journalctl -u infrafid -f

Source Layout

daemon/
  main.c          # Entry point: CLI parsing, main loop, credential handling
  wfr_lirc.h/c    # LIRC scancode reader (/dev/lirc0, LIRC_MODE_SCANCODE)
  wfr_evdev.h/c   # evdev input reader (/dev/input/eventN, NEC via MSC_RAW)
  wfr_serial.h/c  # Serial backend for Arduino transceiver
  wfr_decode.h/c  # IR scancode reassembler (START/DATA/END -> payload + CRC check)
  wfr_network.h/c # WiFi connector (NetworkManager/ifupdown) with rollback
  wfr_ack.h/c     # LIRC TX ACK sender
  Makefile
  infrafid.service
  install.sh

Clone this wiki locally