# LIRC(4) - man - phpMan

[LIRC(4)](https://www.chedong.com/phpMan.php/man/LIRC/4/markdown)                               Linux Programmer's Manual                              [LIRC(4)](https://www.chedong.com/phpMan.php/man/LIRC/4/markdown)



## 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 send‐
       ing 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 but‐
       ton 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  re‐
       mote 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.  Sometimes, this kind of hardware also supports sending IR data.   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)](https://www.chedong.com/phpMan.php/man/bpf/2/markdown)) and attached to the **lirc** device.

       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)](https://www.chedong.com/phpMan.php/man/read/2/markdown) provides 32-bit values representing
       a space or a pulse duration.  The time of the duration (microseconds) is encoded in the lower
       24 bits.  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.

   **Reading** **input** **with** **the** **LIRC**___**MODE**___**SCANCODE** **mode**
       In the **LIRC**___**MODE**___**SCANCODE** mode, the data returned by [**read**(2)](https://www.chedong.com/phpMan.php/man/read/2/markdown) reflects decoded button presses,
       in the struct _lirc_scancode_.  The scancode is stored in the _scancode_ field, and the IR proto‐
       col 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)](https://www.chedong.com/phpMan.php/man/write/2/markdown) 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)](https://www.chedong.com/phpMan.php/man/write/2/markdown)
       function blocks until the data has been transmitted by the hardware.  If more  data  is  pro‐
       vided than the hardware can send, the [**write**(2)](https://www.chedong.com/phpMan.php/man/write/2/markdown) 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 _scan__‐
       _code_ and _rc_proto_ fields must 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
       The LIRC device's ioctl definition is bound  by  the  ioctl  function  definition  of  _struct_
       _file_operations_,  leaving  us with an _unsigned_ _int_ for the ioctl command and an _unsigned_ _long_
       for the argument.  For the purposes of ioctl portability across 32-bit and  64-bit  architec‐
       tures, these values are capped to their 32-bit sizes.

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

       The  following  ioctls  can be used to probe or change specific **lirc** hardware settings.  Many
       require a third argument, usually an _int_.  referred to below as _val_.

### 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 oper‐
       ation  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**.   Oth‐
              erwise, 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 de‐
                     coded 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  de‐
              fined 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)](https://www.chedong.com/phpMan.php/man/lircd/8/markdown) in detecting that an  IR  signal  is
              finished  and can speed up the decoding process.  These operations return integer val‐
              ues 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**___**TIME**‐‐
              **OUT**.  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  be‐
              havior of this operation has varied across kernel versions:

              *  Since  Linux  4.16: each time the **lirc** **device** **is** **opened,** timeout reports are by de‐
                 fault enabled for the resulting file descriptor.  The  **LIRC**___**SET**___**REC**___**TIMEOUT**  opera‐
                 tion  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 reports are disabled by  default,  and  enabling
                 them (via **LIRC**___**SET**___**REC**___**TIMEOUT**) on any file descriptor associated with the **lirc** de‐
                 vice 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**___**CAR**‐‐
              **RIER**___**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 up‐
              per 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 num‐
              ber 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  de‐
              vices that otherwise have narrow band receivers that prevent them to be used with cer‐
              tain 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 dis‐
              able 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 fol‐
       lowing 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**___**TRANSMIT**‐‐
              **TER**___**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  kernel  release  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**___**CAR**‐‐
              **RIER**___**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  avail‐
       able  before  kernel  release  4.6.   Users  of  older  kernels could use the file bundled in
       ⟨<http://www.lirc.org>⟩.

## SEE ALSO
       [**ir-ctl**(1)](https://www.chedong.com/phpMan.php/man/ir-ctl/1/markdown), [**lircd**(8)](https://www.chedong.com/phpMan.php/man/lircd/8/markdown), [**bpf**(2)](https://www.chedong.com/phpMan.php/man/bpf/2/markdown)

       <https://www.kernel.org/doc/html/latest/media/uapi/rc/lirc-dev.html>

## COLOPHON
       This page is part of release 5.10 of the Linux  _man-pages_  project.   A  description  of  the
       project,  information about reporting bugs, and the latest version of this page, can be found
       at <https://www.kernel.org/doc/man-pages/>.



Linux                                        2019-03-06                                      [LIRC(4)](https://www.chedong.com/phpMan.php/man/LIRC/4/markdown)
