---
name: "lirc"
section: "4"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/lirc"
---

# lirc(4)

lirc devices

## NAME

lirc - lirc devices

## DESCRIPTION

The */dev/lirc\** character devices provide a low-level bidirectional interface to infra-red (IR) remotes. Most of these devices can receive, and some can send. When receiving or sending data, the driver works in two different modes depending on the underlying hardware.

Some hardware (typically TV-cards) decodes the IR signal internally and provides decoded button presses as scancode values. Drivers for this kind of hardware work in **LIRC\_MODE\_SCANCODE** mode. Such hardware usually does not support sending IR signals. Furthermore, such hardware can only decode a limited set of IR protocols, usually only the protocol of the specific remote which is bundled with, for example, a TV-card.

Other hardware provides a stream of pulse/space durations. Such drivers work in **LIRC\_MODE\_MODE2** mode. Such hardware can be used with (almost) any kind of remote. This type of hardware can also be used in **LIRC\_MODE\_SCANCODE** mode, in which case the kernel IR decoders will decode the IR. These decoders can be written in extended BPF (see [**bpf**(2)](/bpf/2.md)) and attached to the **lirc** device. Sometimes, this kind of hardware also supports sending IR data.

The **LIRC\_GET\_FEATURES** ioctl (see below) allows probing for whether receiving and sending is supported, and in which modes, amongst other features.

### Reading input with the LIRC\_MODE\_MODE2 mode

In the **LIRC\_MODE\_MODE2** mode, the data returned by [**read**(2)](/read/2.md) provides 32-bit values representing a space or a pulse duration. The time of the duration (microseconds) is encoded in the lower 24 bits. Pulse (also known as flash) indicates a duration of infrared light being detected, and space (also known as gap) indicates a duration with no infrared. If the duration of space exceeds the inactivity timeout, a special timeout package is delivered, which marks the end of a message. The upper 8 bits indicate the type of package:

- **LIRC\_MODE2\_SPACE**

  Value reflects a space duration (microseconds).

- **LIRC\_MODE2\_PULSE**

  Value reflects a pulse duration (microseconds).

- **LIRC\_MODE2\_FREQUENCY**

  Value reflects a frequency (Hz); see the **LIRC\_SET\_MEASURE\_CARRIER\_MODE** ioctl.

- **LIRC\_MODE2\_TIMEOUT**

  Value reflects a space duration (microseconds). The package reflects a timeout; see the **LIRC\_SET\_REC\_TIMEOUT\_REPORTS** ioctl.

- **LIRC\_MODE2\_OVERFLOW**

  The IR receiver encountered an overflow, and as a result data is missing (since Linux 5.18).

### Reading input with the LIRC\_MODE\_SCANCODE mode

In the **LIRC\_MODE\_SCANCODE** mode, the data returned by [**read**(2)](/read/2.md) reflects decoded button presses, in the struct *lirc\_scancode*. The scancode is stored in the *scancode* field, and the IR protocol is stored in *rc\_proto*. This field has one the values of the *enum rc\_proto*.

### Writing output with the LIRC\_MODE\_PULSE mode

The data written to the character device using [**write**(2)](/write/2.md) is a pulse/space sequence of integer values. Pulses and spaces are only marked implicitly by their position. The data must start and end with a pulse, thus it must always include an odd number of samples. The [**write**(2)](/write/2.md) function blocks until the data has been transmitted by the hardware. If more data is provided than the hardware can send, the [**write**(2)](/write/2.md) call fails with the error **EINVAL**.

### Writing output with the LIRC\_MODE\_SCANCODE mode

The data written to the character devices must be a single struct *lirc\_scancode*. The *scancode* and *rc\_proto* fields must be filled in, all other fields must be 0. The kernel IR encoders will convert the scancode to pulses and spaces. The protocol or scancode is invalid, or the **lirc** device cannot transmit.

## IOCTL COMMANDS

```
#include <linux/lirc.h>    /* But see BUGS */
int ioctl(int fd, int cmd, int *val);
```

The following [**ioctl**(2)](/ioctl/2.md) operations are provided by the **lirc** character device to probe or change specific **lirc** hardware settings.

### Always Supported Commands

*/dev/lirc*\* devices always support the following commands:

- **LIRC\_GET\_FEATURES** (*void*)

  Returns a bit mask of combined features bits; see FEATURES.

If a device returns an error code for **LIRC\_GET\_FEATURES**, it is safe to assume it is not a **lirc** device.

### Optional Commands

Some **lirc** devices support the commands listed below. Unless otherwise stated, these fail with the error **ENOTTY** if the operation isn't supported, or with the error **EINVAL** if the operation failed, or invalid arguments were provided. If a driver does not announce support of certain features, invoking the corresponding ioctls will fail with the error **ENOTTY**.

- **LIRC\_GET\_REC\_MODE** (*void*)

  If the **lirc** device has no receiver, this operation fails with the error **ENOTTY**. Otherwise, it returns the receive mode, which will be one of:

  - **LIRC\_MODE\_MODE2**

    The driver returns a sequence of pulse/space durations.

  - **LIRC\_MODE\_SCANCODE**

    The driver returns struct *lirc\_scancode* values, each of which represents a decoded button press.

- **LIRC\_SET\_REC\_MODE** (*int*)

  Set the receive mode. *val* is either **LIRC\_MODE\_SCANCODE** or **LIRC\_MODE\_MODE2**. If the **lirc** device has no receiver, this operation fails with the error **ENOTTY.**

- **LIRC\_GET\_SEND\_MODE** (*void*)

  Return the send mode. **LIRC\_MODE\_PULSE** or **LIRC\_MODE\_SCANCODE** is supported. If the **lirc** device cannot send, this operation fails with the error **ENOTTY.**

- **LIRC\_SET\_SEND\_MODE** (*int*)

  Set the send mode. *val* is either **LIRC\_MODE\_SCANCODE** or **LIRC\_MODE\_PULSE**. If the **lirc** device cannot send, this operation fails with the error **ENOTTY**.

- **LIRC\_SET\_SEND\_CARRIER** (*int*)

  Set the modulation frequency. The argument is the frequency (Hz).

- **LIRC\_SET\_SEND\_DUTY\_CYCLE** (*int*)

  Set the carrier duty cycle. *val* is a number in the range \[0,100\] which describes the pulse width as a percentage of the total cycle. Currently, no special meaning is defined for 0 or 100, but the values are reserved for future use.

- **LIRC\_GET\_MIN\_TIMEOUT(***void***)** **LIRC\_GET\_MAX\_TIMEOUT(***void***)**

  Some devices have internal timers that can be used to detect when there has been no IR activity for a long time. This can help [**lircd**(8)](/lircd/8.md) in detecting that an IR signal is finished and can speed up the decoding process. These operations return integer values with the minimum/maximum timeout that can be set (microseconds). Some devices have a fixed timeout. For such drivers, **LIRC\_GET\_MIN\_TIMEOUT** and **LIRC\_GET\_MAX\_TIMEOUT** will fail with the error **ENOTTY**.

- **LIRC\_SET\_REC\_TIMEOUT** (*int*)

  Set the integer value for IR inactivity timeout (microseconds). To be accepted, the value must be within the limits defined by **LIRC\_GET\_MIN\_TIMEOUT** and **LIRC\_GET\_MAX\_TIMEOUT**. A value of 0 (if supported by the hardware) disables all hardware timeouts and data should be reported as soon as possible. If the exact value cannot be set, then the next possible value *greater* than the given value should be set.

- **LIRC\_GET\_REC\_TIMEOUT** (*void*)

  Return the current inactivity timeout (microseconds). Available since Linux 4.18.

- **LIRC\_SET\_REC\_TIMEOUT\_REPORTS** (*int*)

  Enable (*val* is 1) or disable (*val* is 0) timeout packages in **LIRC\_MODE\_MODE2**. The behavior of this operation has varied across kernel versions:

  - •

    Since Linux 5.17: timeout packages are always enabled and this ioctl is a no-op.

  - •

    Since Linux 4.16: timeout packages are enabled by default. Each time the **lirc** device is opened, the **LIRC\_SET\_REC\_TIMEOUT** operation can be used to disable (and, if desired, to later re-enable) the timeout on the file descriptor.

  - •

    In Linux 4.15 and earlier: timeout packages are disabled by default, and enabling them (via **LIRC\_SET\_REC\_TIMEOUT**) on any file descriptor associated with the **lirc** device has the effect of enabling timeouts for all file descriptors referring to that device (until timeouts are disabled again).

- **LIRC\_SET\_REC\_CARRIER** (*int*)

  Set the upper bound of the receive carrier frequency (Hz). See **LIRC\_SET\_REC\_CARRIER\_RANGE**.

- **LIRC\_SET\_REC\_CARRIER\_RANGE** (*int*)

  Sets the lower bound of the receive carrier frequency (Hz). For this to take affect, first set the lower bound using the **LIRC\_SET\_REC\_CARRIER\_RANGE** ioctl, and then the upper bound using the **LIRC\_SET\_REC\_CARRIER** ioctl.

- **LIRC\_SET\_MEASURE\_CARRIER\_MODE** (*int*)

  Enable (*val* is 1) or disable (*val* is 0) the measure mode. If enabled, from the next key press on, the driver will send **LIRC\_MODE2\_FREQUENCY** packets. By default, this should be turned off.

- **LIRC\_GET\_REC\_RESOLUTION** (*void*)

  Return the driver resolution (microseconds).

- **LIRC\_SET\_TRANSMITTER\_MASK** (*int*)

  Enable the set of transmitters specified in *val*, which contains a bit mask where each enabled transmitter is a 1. The first transmitter is encoded by the least significant bit, and so on. When an invalid bit mask is given, for example a bit is set even though the device does not have so many transmitters, this operation returns the number of available transmitters and does nothing otherwise.

- **LIRC\_SET\_WIDEBAND\_RECEIVER** (*int*)

  Some devices are equipped with a special wide band receiver which is intended to be used to learn the output of an existing remote. This ioctl can be used to enable (*val* equals 1) or disable (*val* equals 0) this functionality. This might be useful for devices that otherwise have narrow band receivers that prevent them to be used with certain remotes. Wide band receivers may also be more precise. On the other hand, their disadvantage usually is reduced range of reception.

-

  Note: wide band receiver may be implicitly enabled if you enable carrier reports. In that case, it will be disabled as soon as you disable carrier reports. Trying to disable a wide band receiver while carrier reports are active will do nothing.

## FEATURES

the **LIRC\_GET\_FEATURES** ioctl returns a bit mask describing features of the driver. The following bits may be returned in the mask:

- **LIRC\_CAN\_REC\_MODE2**

  The driver is capable of receiving using **LIRC\_MODE\_MODE2**.

- **LIRC\_CAN\_REC\_SCANCODE**

  The driver is capable of receiving using **LIRC\_MODE\_SCANCODE**.

- **LIRC\_CAN\_SET\_SEND\_CARRIER**

  The driver supports changing the modulation frequency using **LIRC\_SET\_SEND\_CARRIER**.

- **LIRC\_CAN\_SET\_SEND\_DUTY\_CYCLE**

  The driver supports changing the duty cycle using **LIRC\_SET\_SEND\_DUTY\_CYCLE**.

- **LIRC\_CAN\_SET\_TRANSMITTER\_MASK**

  The driver supports changing the active transmitter(s) using **LIRC\_SET\_TRANSMITTER\_MASK**.

- **LIRC\_CAN\_SET\_REC\_CARRIER**

  The driver supports setting the receive carrier frequency using **LIRC\_SET\_REC\_CARRIER**. Any **lirc** device since the drivers were merged in Linux 2.6.36 must have **LIRC\_CAN\_SET\_REC\_CARRIER\_RANGE** set if **LIRC\_CAN\_SET\_REC\_CARRIER** feature is set.

- **LIRC\_CAN\_SET\_REC\_CARRIER\_RANGE**

  The driver supports **LIRC\_SET\_REC\_CARRIER\_RANGE**. The lower bound of the carrier must first be set using the **LIRC\_SET\_REC\_CARRIER\_RANGE** ioctl, before using the **LIRC\_SET\_REC\_CARRIER** ioctl to set the upper bound.

- **LIRC\_CAN\_GET\_REC\_RESOLUTION**

  The driver supports **LIRC\_GET\_REC\_RESOLUTION**.

- **LIRC\_CAN\_SET\_REC\_TIMEOUT**

  The driver supports **LIRC\_SET\_REC\_TIMEOUT**.

- **LIRC\_CAN\_MEASURE\_CARRIER**

  The driver supports measuring of the modulation frequency using **LIRC\_SET\_MEASURE\_CARRIER\_MODE**.

- **LIRC\_CAN\_USE\_WIDEBAND\_RECEIVER**

  The driver supports learning mode using **LIRC\_SET\_WIDEBAND\_RECEIVER**.

- **LIRC\_CAN\_SEND\_PULSE**

  The driver supports sending using **LIRC\_MODE\_PULSE** or **LIRC\_MODE\_SCANCODE**

## BUGS

Using these devices requires the kernel source header file *lirc.h*. This file is not available before Linux 4.6. Users of older kernels could use the file bundled in ⟨http:\\://www.lirc.org⟩.

## SEE ALSO

[**ir-ctl**(1)](/ir-ctl/1.md), [**lircd**(8)](/lircd/8.md), [**bpf**(2)](/bpf/2.md)

⟨https:\\://www.kernel.org/\\:doc/\\:html/\\:latest/\\:userspace\\-api/\\:media/\\:rc/\\:lirc\\-dev.html⟩
