# Remote control

---

# file: uapi/v4l/keytable.c

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> Reference for file: uapi/v4l/keytable.c.

<a id="rst-file-uapi-v4l-keytable-c"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->



```c
/* keytable.c - This program allows checking/replacing keys at IR

   Copyright (C) 2006-2009 Mauro Carvalho Chehab <mchehab@kernel.org>

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
 */

#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <linux/input.h>
#include <sys/ioctl.h>

#include "parse.h"

void prtcode (int *codes)
{
        struct parse_key *p;

        for (p=keynames;p->name!=NULL;p++) {
                if (p->value == (unsigned)codes[1]) {
                        printf("scancode 0x%04x = %s (0x%02x)\\n", codes[0], p->name, codes[1]);
                        return;
                }
        }

        if (isprint (codes[1]))
                printf("scancode %d = '%c' (0x%02x)\\n", codes[0], codes[1], codes[1]);
        else
                printf("scancode %d = 0x%02x\\n", codes[0], codes[1]);
}

int parse_code(char *string)
{
        struct parse_key *p;

        for (p=keynames;p->name!=NULL;p++) {
                if (!strcasecmp(p->name, string)) {
                        return p->value;
                }
        }
        return -1;
}

int main (int argc, char *argv[])
{
        int fd;
        unsigned int i, j;
        int codes[2];

        if (argc<2 || argc>4) {
                printf ("usage: %s <device> to get table; or\\n"
                        "       %s <device> <scancode> <keycode>\\n"
                        "       %s <device> <keycode_file>n",*argv,*argv,*argv);
                return -1;
        }

        if ((fd = open(argv[1], O_RDONLY)) < 0) {
                perror("Couldn't open input device");
                return(-1);
        }

        if (argc==4) {
                int value;

                value=parse_code(argv[3]);

                if (value==-1) {
                        value = strtol(argv[3], NULL, 0);
                        if (errno)
                                perror("value");
                }

                codes [0] = (unsigned) strtol(argv[2], NULL, 0);
                codes [1] = (unsigned) value;

                if(ioctl(fd, EVIOCSKEYCODE, codes))
                        perror ("EVIOCSKEYCODE");

                if(ioctl(fd, EVIOCGKEYCODE, codes)==0)
                        prtcode(codes);
                return 0;
        }

        if (argc==3) {
                FILE *fin;
                int value;
                char *scancode, *keycode, s[2048];

                fin=fopen(argv[2],"r");
                if (fin==NULL) {
                        perror ("opening keycode file");
                        return -1;
                }

                /* Clears old table */
                for (j = 0; j < 256; j++) {
                        for (i = 0; i < 256; i++) {
                                codes[0] = (j << 8) | i;
                                codes[1] = KEY_RESERVED;
                                ioctl(fd, EVIOCSKEYCODE, codes);
                        }
                }

                while (fgets(s,sizeof(s),fin)) {
                        scancode=strtok(s,"\\n\\t =:");
                        if (!scancode) {
                                perror ("parsing input file scancode");
                                return -1;
                        }
                        if (!strcasecmp(scancode, "scancode")) {
                                scancode = strtok(NULL,"\\n\\t =:");
                                if (!scancode) {
                                        perror ("parsing input file scancode");
                                        return -1;
                                }
                        }

                        keycode=strtok(NULL,"\\n\\t =:(");
                        if (!keycode) {
                                perror ("parsing input file keycode");
                                return -1;
                        }

                        // printf ("parsing %s=%s:", scancode, keycode);
                        value=parse_code(keycode);
                        // printf ("\\tvalue=%d\\n",value);

                        if (value==-1) {
                                value = strtol(keycode, NULL, 0);
                                if (errno)
                                        perror("value");
                        }

                        codes [0] = (unsigned) strtol(scancode, NULL, 0);
                        codes [1] = (unsigned) value;

                        // printf("\\t%04x=%04x\\n",codes[0], codes[1]);
                        if(ioctl(fd, EVIOCSKEYCODE, codes)) {
                                fprintf(stderr, "Setting scancode 0x%04x with 0x%04x via ",codes[0], codes[1]);
                                perror ("EVIOCSKEYCODE");
                        }

                        if(ioctl(fd, EVIOCGKEYCODE, codes)==0)
                                prtcode(codes);
                }
                return 0;
        }

        /* Get scancode table */
        for (j = 0; j < 256; j++) {
                for (i = 0; i < 256; i++) {
                        codes[0] = (j << 8) | i;
                        if (!ioctl(fd, EVIOCGKEYCODE, codes) && codes[1] != KEY_RESERVED)
                                prtcode(codes);
                }
        }
        return 0;
}
```

---

# Introduction

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC stands for Linux Infrared Remote Control. The LIRC device interface is a bi-directional interface for transporting raw IR and decoded scancodes data between userspace and kernelspace. Fundamentally, it is just a chardev (/dev/lircX,…

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<a id="rst-introduction"></a>
<a id="rst-lirc-dev-intro"></a>

## Introduction

LIRC stands for Linux Infrared Remote Control. The LIRC device interface is a bi-directional interface for transporting raw IR and decoded scancodes data between userspace and kernelspace. Fundamentally, it is just a chardev (/dev/lircX, for X = 0, 1, 2, ...), with a number of standard struct file_operations defined on it. With respect to transporting raw IR and decoded scancodes to and fro, the essential fops are read, write and ioctl.

It is also possible to attach a BPF program to a LIRC device for decoding raw IR into scancodes.

Example dmesg output upon a driver registering w/LIRC:



```none
$ dmesg |grep lirc_dev
rc rc0: lirc_dev: driver mceusb registered at minor = 0, raw IR receiver, raw IR transmitter
```

What you should see for a chardev:



```none
$ ls -l /dev/lirc*
crw-rw---- 1 root root 248, 0 Jul 2 22:20 /dev/lirc0
```

Note that the package [v4l-utils](<https://git.linuxtv.org/v4l-utils.git/>)<a id="rst-v4l-utils"></a> contains tools for working with LIRC devices:

> - ir-ctl: can receive raw IR and transmit IR, as well as query LIRC device features.
>
> - ir-keytable: can load keymaps; allows you to set IR kernel protocols; load BPF IR decoders and test IR decoding. Some BPF IR decoders are also provided.

<a id="rst-lirc-modes-1"></a>
<a id="rst-lirc-modes"></a>

## LIRC modes

LIRC supports some modes of receiving and sending IR codes, as shown on the following table.

<a id="rst-lirc-scancode-flag-repeat"></a>
<a id="rst-lirc-scancode-flag-toggle"></a>
<a id="rst-lirc-mode-scancode"></a>

`LIRC_MODE_SCANCODE`

> This mode is for both sending and receiving IR.
>
> For transmitting (aka sending), create a struct lirc_scancode with the desired scancode set in the `scancode` member, `rc_proto` set to the [IR protocol](</kernel/userspace/userspace-api/media-rc/rc-protos.md#rst-remote-controllers-protocols>), and all other members set to 0. Write this struct to the lirc device.
>
> For receiving, you read struct lirc_scancode from the LIRC device. The `scancode` field is set to the received scancode and the [IR protocol](</kernel/userspace/userspace-api/media-rc/rc-protos.md#rst-remote-controllers-protocols>) is set in `rc_proto`. If the scancode maps to a valid key code, this is set in the `keycode` field, else it is set to `KEY_RESERVED`.
>
> The `flags` can have `LIRC_SCANCODE_FLAG_TOGGLE` set if the toggle bit is set in protocols that support it (e.g. rc-5 and rc-6), or `LIRC_SCANCODE_FLAG_REPEAT` for when a repeat is received for protocols that support it (e.g. nec).
>
> In the Sanyo and NEC protocol, if you hold a button on remote, rather than repeating the entire scancode, the remote sends a shorter message with no scancode, which just means button is held, a "repeat". When this is received, the `LIRC_SCANCODE_FLAG_REPEAT` is set and the scancode and keycode is repeated.
>
> With nec, there is no way to distinguish "button hold" from "repeatedly pressing the same button". The rc-5 and rc-6 protocols have a toggle bit. When a button is released and pressed again, the toggle bit is inverted. If the toggle bit is set, the `LIRC_SCANCODE_FLAG_TOGGLE` is set.
>
> The `timestamp` field is filled with the time nanoseconds (in `CLOCK_MONOTONIC`) when the scancode was decoded.

<a id="rst-lirc-mode-mode2"></a>

`LIRC_MODE_MODE2`

> The driver returns a sequence of pulse and space codes to userspace, as a series of u32 values.
>
> This mode is used only for IR receive.
>
> The upper 8 bits determine the packet type, and the lower 24 bits the payload. Use `LIRC_VALUE()` macro to get the payload, and the macro `LIRC_MODE2()` will give you the type, which is one of:
>
> `LIRC_MODE2_PULSE`
>
> > Signifies the presence of IR in microseconds, also known as *flash*.
>
> `LIRC_MODE2_SPACE`
>
> > Signifies absence of IR in microseconds, also known as *gap*.
>
> `LIRC_MODE2_FREQUENCY`
>
> > If measurement of the carrier frequency was enabled with [ioctl LIRC_SET_MEASURE_CARRIER_MODE](</kernel/userspace/userspace-api/media-rc/lirc-set-measure-carrier-mode.md#rst-lirc-set-measure-carrier-mode>) then this packet gives you the carrier frequency in Hertz.
>
> `LIRC_MODE2_TIMEOUT`
>
> > When the timeout set with [ioctl LIRC_GET_REC_TIMEOUT and LIRC_SET_REC_TIMEOUT](</kernel/userspace/userspace-api/media-rc/lirc-set-rec-timeout.md#rst-lirc-set-rec-timeout>) expires due to no IR being detected, this packet will be sent, with the number of microseconds with no IR.
>
> `LIRC_MODE2_OVERFLOW`
>
> > Signifies that the IR receiver encounter an overflow, and some IR is missing. The IR data after this should be correct again. The actual value is not important, but this is set to 0xffffff by the kernel for compatibility with lircd.

<a id="rst-lirc-mode-pulse"></a>

`LIRC_MODE_PULSE`

> In pulse mode, a sequence of pulse/space integer values are written to the lirc device using [LIRC write()](</kernel/userspace/userspace-api/media-rc/lirc-write.md#rst-lirc-write>).
>
> The values are alternating pulse and space lengths, in microseconds. The first and last entry must be a pulse, so there must be an odd number of entries.
>
> This mode is used only for IR send.

<a id="rst-data-types-used-by-lirc-mode-scancode"></a>

## Data types used by LIRC_MODE_SCANCODE


#### <a id="c-struct-lirc_scancode"></a>`struct lirc_scancode`

decoded scancode with protocol for use with LIRC_MODE_SCANCODE

**Definition**

```c
struct lirc_scancode {
    __u64 timestamp;
    __u16 flags;
    __u16 rc_proto;
    __u32 keycode;
    __u64 scancode;
};
```

**Members**

- `timestamp`: Timestamp in nanoseconds using CLOCK_MONOTONIC when IR
  was decoded.
- `flags`: should be 0 for transmit. When receiving scancodes,
  LIRC_SCANCODE_FLAG_TOGGLE or LIRC_SCANCODE_FLAG_REPEAT can be set
  depending on the protocol
- `rc_proto`: see enum rc_proto
- `keycode`: the translated keycode. Set to 0 for transmit.
- `scancode`: the scancode received or to be sent

#### <a id="c-enum-rc_proto"></a>`enum rc_proto`

the Remote Controller protocol

**Constants**

- `RC_PROTO_UNKNOWN`: Protocol not known
- `RC_PROTO_OTHER`: Protocol known but proprietary
- `RC_PROTO_RC5`: Philips RC5 protocol
- `RC_PROTO_RC5X_20`: Philips RC5x 20 bit protocol
- `RC_PROTO_RC5_SZ`: StreamZap variant of RC5
- `RC_PROTO_JVC`: JVC protocol
- `RC_PROTO_SONY12`: Sony 12 bit protocol
- `RC_PROTO_SONY15`: Sony 15 bit protocol
- `RC_PROTO_SONY20`: Sony 20 bit protocol
- `RC_PROTO_NEC`: NEC protocol
- `RC_PROTO_NECX`: Extended NEC protocol
- `RC_PROTO_NEC32`: NEC 32 bit protocol
- `RC_PROTO_SANYO`: Sanyo protocol
- `RC_PROTO_MCIR2_KBD`: RC6-ish MCE keyboard
- `RC_PROTO_MCIR2_MSE`: RC6-ish MCE mouse
- `RC_PROTO_RC6_0`: Philips RC6-0-16 protocol
- `RC_PROTO_RC6_6A_20`: Philips RC6-6A-20 protocol
- `RC_PROTO_RC6_6A_24`: Philips RC6-6A-24 protocol
- `RC_PROTO_RC6_6A_32`: Philips RC6-6A-32 protocol
- `RC_PROTO_RC6_MCE`: MCE (Philips RC6-6A-32 subtype) protocol
- `RC_PROTO_SHARP`: Sharp protocol
- `RC_PROTO_XMP`: XMP protocol
- `RC_PROTO_CEC`: CEC protocol
- `RC_PROTO_IMON`: iMon Pad protocol
- `RC_PROTO_RCMM12`: RC-MM protocol 12 bits
- `RC_PROTO_RCMM24`: RC-MM protocol 24 bits
- `RC_PROTO_RCMM32`: RC-MM protocol 32 bits
- `RC_PROTO_XBOX_DVD`: Xbox DVD Movie Playback Kit protocol
- `RC_PROTO_MAX`: Maximum value of enum rc_proto


<a id="rst-bpf-based-ir-decoder"></a>

## BPF based IR decoder

The kernel has support for decoding the most common [IR protocols](</kernel/userspace/userspace-api/media-rc/rc-protos.md#rst-remote-controllers-protocols>), but there are many protocols which are not supported. To support these, it is possible to load an BPF program which does the decoding. This can only be done on LIRC devices which support reading raw IR.

First, using the [bpf(2)](<http://man7.org/linux/man-pages/man2/bpf.2.html>) syscall with the `BPF_LOAD_PROG` argument, program must be loaded of type `BPF_PROG_TYPE_LIRC_MODE2`. Once attached to the LIRC device, this program will be called for each pulse, space or timeout event on the LIRC device. The context for the BPF program is a pointer to a unsigned int, which is a [LIRC_MODE_MODE2](<#rst-lirc-mode-mode2>) value. When the program has decoded the scancode, it can be submitted using the BPF functions `bpf_rc_keydown()` or `bpf_rc_repeat()`. Mouse or pointer movements can be reported using `bpf_rc_pointer_rel()`.

Once you have the file descriptor for the `BPF_PROG_TYPE_LIRC_MODE2` BPF program, it can be attached to the LIRC device using the [bpf(2)](<http://man7.org/linux/man-pages/man2/bpf.2.html>) syscall. The target must be the file descriptor for the LIRC device, and the attach type must be `BPF_LIRC_MODE2`. No more than 64 BPF programs can be attached to a single LIRC device at a time.

<a id="rst-bpf-2"></a>

---

# LIRC Device Interface

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> Reference for LIRC Device Interface.

<a id="rst-lirc-device-interface"></a>
<a id="rst-lirc-dev"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

- [Introduction](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md>)
- [LIRC Function Reference](</kernel/userspace/userspace-api/media-rc/lirc-func.md>)
- [lirc-header](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/rc/lirc-header.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)

---

# LIRC Function Reference

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> Reference for LIRC Function Reference.

<a id="rst-lirc-function-reference"></a>
<a id="rst-lirc-func"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

- [LIRC read()](</kernel/userspace/userspace-api/media-rc/lirc-read.md>)
- [LIRC write()](</kernel/userspace/userspace-api/media-rc/lirc-write.md>)
- [ioctl LIRC_GET_FEATURES](</kernel/userspace/userspace-api/media-rc/lirc-get-features.md>)
- [ioctls LIRC_GET_SEND_MODE and LIRC_SET_SEND_MODE](</kernel/userspace/userspace-api/media-rc/lirc-get-send-mode.md>)
- [ioctls LIRC_GET_REC_MODE and LIRC_SET_REC_MODE](</kernel/userspace/userspace-api/media-rc/lirc-get-rec-mode.md>)
- [ioctl LIRC_GET_REC_RESOLUTION](</kernel/userspace/userspace-api/media-rc/lirc-get-rec-resolution.md>)
- [ioctl LIRC_SET_SEND_DUTY_CYCLE](</kernel/userspace/userspace-api/media-rc/lirc-set-send-duty-cycle.md>)
- [ioctls LIRC_GET_MIN_TIMEOUT and LIRC_GET_MAX_TIMEOUT](</kernel/userspace/userspace-api/media-rc/lirc-get-timeout.md>)
- [ioctl LIRC_GET_REC_TIMEOUT and LIRC_SET_REC_TIMEOUT](</kernel/userspace/userspace-api/media-rc/lirc-set-rec-timeout.md>)
- [ioctl LIRC_SET_REC_CARRIER](</kernel/userspace/userspace-api/media-rc/lirc-set-rec-carrier.md>)
- [ioctl LIRC_SET_REC_CARRIER_RANGE](</kernel/userspace/userspace-api/media-rc/lirc-set-rec-carrier-range.md>)
- [ioctl LIRC_SET_SEND_CARRIER](</kernel/userspace/userspace-api/media-rc/lirc-set-send-carrier.md>)
- [ioctl LIRC_SET_TRANSMITTER_MASK](</kernel/userspace/userspace-api/media-rc/lirc-set-transmitter-mask.md>)
- [ioctl LIRC_SET_MEASURE_CARRIER_MODE](</kernel/userspace/userspace-api/media-rc/lirc-set-measure-carrier-mode.md>)
- [ioctl LIRC_SET_WIDEBAND_RECEIVER](</kernel/userspace/userspace-api/media-rc/lirc-set-wideband-receiver.md>)

---

# ioctl LIRC_GET_FEATURES

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_GET_FEATURES - Get the underlying hardware device's features

<a id="rst-ioctl-lirc-get-features"></a>
<a id="rst-lirc-get-features"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

<a id="rst-name"></a>

## Name

LIRC_GET_FEATURES - Get the underlying hardware device's features

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-LIRC_GET_FEATURES"></a>

```c
LIRC_GET_FEATURES
```

`int ioctl(int fd, LIRC_GET_FEATURES, __u32 *features)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`features`**

  Bitmask with the LIRC features.

<a id="rst-description"></a>

## Description

Get the underlying hardware device's features. If a driver does not announce support of certain features, calling of the corresponding ioctls is undefined.

<a id="rst-lirc-features"></a>

## LIRC features

<a id="rst-lirc-can-rec-raw"></a>

`LIRC_CAN_REC_RAW`

> Unused. Kept just to avoid breaking uAPI.

<a id="rst-lirc-can-rec-pulse"></a>

`LIRC_CAN_REC_PULSE`

> Unused. Kept just to avoid breaking uAPI. [LIRC_MODE_PULSE](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-pulse>) can only be used for transmitting.

<a id="rst-lirc-can-rec-mode2"></a>

`LIRC_CAN_REC_MODE2`

> This is raw IR driver for receiving. This means that [LIRC_MODE_MODE2](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-mode2>) is used. This also implies that [LIRC_MODE_SCANCODE](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-scancode>) is also supported, as long as the kernel is recent enough. Use the [ioctls LIRC_GET_REC_MODE and LIRC_SET_REC_MODE](</kernel/userspace/userspace-api/media-rc/lirc-get-rec-mode.md#rst-lirc-set-rec-mode>) to switch modes.

<a id="rst-lirc-can-rec-lirccode"></a>

`LIRC_CAN_REC_LIRCCODE`

> Unused. Kept just to avoid breaking uAPI.

<a id="rst-lirc-can-rec-scancode"></a>

`LIRC_CAN_REC_SCANCODE`

> This is a scancode driver for receiving. This means that [LIRC_MODE_SCANCODE](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-scancode>) is used.

<a id="rst-lirc-can-set-send-carrier"></a>

`LIRC_CAN_SET_SEND_CARRIER`

> The driver supports changing the modulation frequency via [ioctl LIRC_SET_SEND_CARRIER](</kernel/userspace/userspace-api/media-rc/lirc-set-send-carrier.md#rst-lirc-set-send-carrier>).

<a id="rst-lirc-can-set-send-duty-cycle"></a>

`LIRC_CAN_SET_SEND_DUTY_CYCLE`

> The driver supports changing the duty cycle using [ioctl LIRC_SET_SEND_DUTY_CYCLE](</kernel/userspace/userspace-api/media-rc/lirc-set-send-duty-cycle.md#rst-lirc-set-send-duty-cycle>).

<a id="rst-lirc-can-set-transmitter-mask"></a>

`LIRC_CAN_SET_TRANSMITTER_MASK`

> The driver supports changing the active transmitter(s) using [ioctl LIRC_SET_TRANSMITTER_MASK](</kernel/userspace/userspace-api/media-rc/lirc-set-transmitter-mask.md#rst-lirc-set-transmitter-mask>).

<a id="rst-lirc-can-set-rec-carrier"></a>

`LIRC_CAN_SET_REC_CARRIER`

> The driver supports setting the receive carrier frequency using [ioctl LIRC_SET_REC_CARRIER](</kernel/userspace/userspace-api/media-rc/lirc-set-rec-carrier.md#rst-lirc-set-rec-carrier>).

<a id="rst-lirc-can-set-rec-carrier-range"></a>

`LIRC_CAN_SET_REC_CARRIER_RANGE`

> The driver supports [ioctl LIRC_SET_REC_CARRIER_RANGE](</kernel/userspace/userspace-api/media-rc/lirc-set-rec-carrier-range.md#rst-lirc-set-rec-carrier-range>).

<a id="rst-lirc-can-get-rec-resolution"></a>

`LIRC_CAN_GET_REC_RESOLUTION`

> The driver supports [ioctl LIRC_GET_REC_RESOLUTION](</kernel/userspace/userspace-api/media-rc/lirc-get-rec-resolution.md#rst-lirc-get-rec-resolution>).

<a id="rst-lirc-can-set-rec-timeout"></a>

`LIRC_CAN_SET_REC_TIMEOUT`

> The driver supports [ioctl LIRC_SET_REC_TIMEOUT](</kernel/userspace/userspace-api/media-rc/lirc-set-rec-timeout.md#rst-lirc-set-rec-timeout>).

<a id="rst-lirc-can-measure-carrier"></a>

`LIRC_CAN_MEASURE_CARRIER`

> The driver supports measuring of the modulation frequency using [ioctl LIRC_SET_MEASURE_CARRIER_MODE](</kernel/userspace/userspace-api/media-rc/lirc-set-measure-carrier-mode.md#rst-lirc-set-measure-carrier-mode>).

<a id="rst-lirc-can-use-wideband-receiver"></a>

`LIRC_CAN_USE_WIDEBAND_RECEIVER`

> The driver supports learning mode using [ioctl LIRC_SET_WIDEBAND_RECEIVER](</kernel/userspace/userspace-api/media-rc/lirc-set-wideband-receiver.md#rst-lirc-set-wideband-receiver>).

<a id="rst-lirc-can-send-raw"></a>

`LIRC_CAN_SEND_RAW`

> Unused. Kept just to avoid breaking uAPI.

<a id="rst-lirc-can-send-pulse"></a>

`LIRC_CAN_SEND_PULSE`

> The driver supports sending (also called as IR blasting or IR TX) using [LIRC_MODE_PULSE](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-pulse>). This implies that [LIRC_MODE_SCANCODE](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-scancode>) is also supported for transmit, as long as the kernel is recent enough. Use the [ioctls LIRC_GET_SEND_MODE and LIRC_SET_SEND_MODE](</kernel/userspace/userspace-api/media-rc/lirc-get-send-mode.md#rst-lirc-set-send-mode>) to switch modes.

<a id="rst-lirc-can-send-mode2"></a>

`LIRC_CAN_SEND_MODE2`

> Unused. Kept just to avoid breaking uAPI. [LIRC_MODE_MODE2](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-mode2>) can only be used for receiving.

<a id="rst-lirc-can-send-lirccode"></a>

`LIRC_CAN_SEND_LIRCCODE`

> Unused. Kept just to avoid breaking uAPI.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctls LIRC_GET_REC_MODE and LIRC_SET_REC_MODE

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_GET_REC_MODE/LIRC_SET_REC_MODE - Get/set current receive mode.

<a id="rst-ioctls-lirc-get-rec-mode-and-lirc-set-rec-mode"></a>
<a id="rst-lirc-set-rec-mode"></a>
<a id="rst-lirc-get-rec-mode"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

<a id="rst-name"></a>

## Name

LIRC_GET_REC_MODE/LIRC_SET_REC_MODE - Get/set current receive mode.

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-LIRC_GET_REC_MODE"></a>

```c
LIRC_GET_REC_MODE
```

`int ioctl(int fd, LIRC_GET_REC_MODE, __u32 *mode)`





<a id="c-LIRC_SET_REC_MODE"></a>

```c
LIRC_SET_REC_MODE
```

`int ioctl(int fd, LIRC_SET_REC_MODE, __u32 *mode)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`mode`**

  Mode used for receive.

<a id="rst-description"></a>

## Description

Get and set the current receive mode. Only [LIRC_MODE_MODE2](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-mode2>) and [LIRC_MODE_SCANCODE](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-scancode>) are supported. Use [ioctl LIRC_GET_FEATURES](</kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-get-features>) to find out which modes the driver supports.

<a id="rst-return-value"></a>

## Return Value

<!-- tabularcolumns: |p{2.5cm}|p{15.0cm}| -->


<table>
<tbody>
<tr>
<td>


`ENODEV`

</td>
<td>


Device not available.

</td>
</tr>
<tr>
<td>


`ENOTTY`

</td>
<td>


Device does not support receiving.

</td>
</tr>
<tr>
<td>


`EINVAL`

</td>
<td>


Invalid mode or invalid mode for this device.

</td>
</tr>
</tbody>
</table>

---

# ioctl LIRC_GET_REC_RESOLUTION

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_GET_REC_RESOLUTION - Obtain the value of receive resolution, in microseconds.

<a id="rst-ioctl-lirc-get-rec-resolution"></a>
<a id="rst-lirc-get-rec-resolution"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

<a id="rst-name"></a>

## Name

LIRC_GET_REC_RESOLUTION - Obtain the value of receive resolution, in microseconds.

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-LIRC_GET_REC_RESOLUTION"></a>

```c
LIRC_GET_REC_RESOLUTION
```

`int ioctl(int fd, LIRC_GET_REC_RESOLUTION, __u32 *microseconds)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`microseconds`**

  Resolution, in microseconds.

<a id="rst-description"></a>

## Description

Some receivers have maximum resolution which is defined by internal sample rate or data format limitations. E.g. it's common that signals can only be reported in 50 microsecond steps.

This ioctl returns the integer value with such resolution, with can be used by userspace applications like lircd to automatically adjust the tolerance value.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctls LIRC_GET_SEND_MODE and LIRC_SET_SEND_MODE

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_GET_SEND_MODE/LIRC_SET_SEND_MODE - Get/set current transmit mode.

<a id="rst-ioctls-lirc-get-send-mode-and-lirc-set-send-mode"></a>
<a id="rst-lirc-set-send-mode"></a>
<a id="rst-lirc-get-send-mode"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

<a id="rst-name"></a>

## Name

LIRC_GET_SEND_MODE/LIRC_SET_SEND_MODE - Get/set current transmit mode.

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-LIRC_GET_SEND_MODE"></a>

```c
LIRC_GET_SEND_MODE
```

`int ioctl(int fd, LIRC_GET_SEND_MODE, __u32 *mode)`





<a id="c-LIRC_SET_SEND_MODE"></a>

```c
LIRC_SET_SEND_MODE
```

`int ioctl(int fd, LIRC_SET_SEND_MODE, __u32 *mode)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`mode`**

  The mode used for transmitting.

<a id="rst-description"></a>

## Description

Get/set current transmit mode.

Only [LIRC_MODE_PULSE](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-pulse>) and [LIRC_MODE_SCANCODE](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-scancode>) are supported by for IR send, depending on the driver. Use [ioctl LIRC_GET_FEATURES](</kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-get-features>) to find out which modes the driver supports.

<a id="rst-return-value"></a>

## Return Value

<!-- tabularcolumns: |p{2.5cm}|p{15.0cm}| -->


<table>
<tbody>
<tr>
<td>


`ENODEV`

</td>
<td>


Device not available.

</td>
</tr>
<tr>
<td>


`ENOTTY`

</td>
<td>


Device does not support transmitting.

</td>
</tr>
<tr>
<td>


`EINVAL`

</td>
<td>


Invalid mode or invalid mode for this device.

</td>
</tr>
</tbody>
</table>

---

# ioctls LIRC_GET_MIN_TIMEOUT and LIRC_GET_MAX_TIMEOUT

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_GET_MIN_TIMEOUT / LIRC_GET_MAX_TIMEOUT - Obtain the possible timeout range for IR receive.

<a id="rst-ioctls-lirc-get-min-timeout-and-lirc-get-max-timeout"></a>
<a id="rst-lirc-get-max-timeout"></a>
<a id="rst-lirc-get-min-timeout"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

<a id="rst-name"></a>

## Name

LIRC_GET_MIN_TIMEOUT / LIRC_GET_MAX_TIMEOUT - Obtain the possible timeout range for IR receive.

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-LIRC_GET_MIN_TIMEOUT"></a>

```c
LIRC_GET_MIN_TIMEOUT
```

`int ioctl(int fd, LIRC_GET_MIN_TIMEOUT, __u32 *timeout)`





<a id="c-LIRC_GET_MAX_TIMEOUT"></a>

```c
LIRC_GET_MAX_TIMEOUT
```

`int ioctl(int fd, LIRC_GET_MAX_TIMEOUT, __u32 *timeout)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`timeout`**

  Timeout, in microseconds.

<a id="rst-description"></a>

## Description

Some devices have internal timers that can be used to detect when there's no IR activity for a long time. This can help lircd in detecting that a IR signal is finished and can speed up the decoding process. Returns an integer value with the minimum/maximum timeout that can be set.

> [!NOTE]
>
> Some devices have a fixed timeout, in that case both ioctls will return the same value even though the timeout cannot be changed via [ioctl LIRC_GET_REC_TIMEOUT and LIRC_SET_REC_TIMEOUT](</kernel/userspace/userspace-api/media-rc/lirc-set-rec-timeout.md#rst-lirc-set-rec-timeout>).

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# LIRC uAPI symbols

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> Reference for LIRC uAPI symbols.

<a id="rst-lirc-uapi-symbols"></a>
<a id="rst-lirc-header"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->


## Enumerations

- [`rc_proto`](/kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#c-enum-rc_proto): `include/uapi/linux/lirc.h`, line 205

## IOCTL Commands

- [`LIRC_GET_FEATURES`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-get-features): `include/uapi/linux/lirc.h`, line 96
- [`LIRC_GET_MAX_TIMEOUT`](/kernel/userspace/userspace-api/media-rc/lirc-get-timeout.md#rst-lirc-get-max-timeout): `include/uapi/linux/lirc.h`, line 103
- [`LIRC_GET_MIN_TIMEOUT`](/kernel/userspace/userspace-api/media-rc/lirc-get-timeout.md#rst-lirc-get-min-timeout): `include/uapi/linux/lirc.h`, line 102
- [`LIRC_GET_REC_MODE`](/kernel/userspace/userspace-api/media-rc/lirc-get-rec-mode.md#rst-lirc-get-rec-mode): `include/uapi/linux/lirc.h`, line 99
- [`LIRC_GET_REC_RESOLUTION`](/kernel/userspace/userspace-api/media-rc/lirc-get-rec-resolution.md#rst-lirc-get-rec-resolution): `include/uapi/linux/lirc.h`, line 100
- [`LIRC_GET_REC_TIMEOUT`](/kernel/userspace/userspace-api/media-rc/lirc-set-rec-timeout.md#rst-lirc-get-rec-timeout): `include/uapi/linux/lirc.h`, line 144
- [`LIRC_GET_SEND_MODE`](/kernel/userspace/userspace-api/media-rc/lirc-get-send-mode.md#rst-lirc-get-send-mode): `include/uapi/linux/lirc.h`, line 98
- [`LIRC_SET_MEASURE_CARRIER_MODE`](/kernel/userspace/userspace-api/media-rc/lirc-set-measure-carrier-mode.md#rst-lirc-set-measure-carrier-mode): `include/uapi/linux/lirc.h`, line 130
- [`LIRC_SET_REC_CARRIER`](/kernel/userspace/userspace-api/media-rc/lirc-set-rec-carrier.md#rst-lirc-set-rec-carrier): `include/uapi/linux/lirc.h`, line 112
- [`LIRC_SET_REC_CARRIER_RANGE`](/kernel/userspace/userspace-api/media-rc/lirc-set-rec-carrier-range.md#rst-lirc-set-rec-carrier-range): `include/uapi/linux/lirc.h`, line 136
- [`LIRC_SET_REC_MODE`](/kernel/userspace/userspace-api/media-rc/lirc-get-rec-mode.md#rst-lirc-set-rec-mode): `include/uapi/linux/lirc.h`, line 109
- [`LIRC_SET_REC_TIMEOUT`](/kernel/userspace/userspace-api/media-rc/lirc-set-rec-timeout.md#rst-lirc-set-rec-timeout): `include/uapi/linux/lirc.h`, line 121
- [`LIRC_SET_SEND_CARRIER`](/kernel/userspace/userspace-api/media-rc/lirc-set-send-carrier.md#rst-lirc-set-send-carrier): `include/uapi/linux/lirc.h`, line 111
- [`LIRC_SET_SEND_DUTY_CYCLE`](/kernel/userspace/userspace-api/media-rc/lirc-set-send-duty-cycle.md#rst-lirc-set-send-duty-cycle): `include/uapi/linux/lirc.h`, line 113
- [`LIRC_SET_SEND_MODE`](/kernel/userspace/userspace-api/media-rc/lirc-get-send-mode.md#rst-lirc-set-send-mode): `include/uapi/linux/lirc.h`, line 108
- [`LIRC_SET_TRANSMITTER_MASK`](/kernel/userspace/userspace-api/media-rc/lirc-set-transmitter-mask.md#rst-lirc-set-transmitter-mask): `include/uapi/linux/lirc.h`, line 114
- [`LIRC_SET_WIDEBAND_RECEIVER`](/kernel/userspace/userspace-api/media-rc/lirc-set-wideband-receiver.md#rst-lirc-set-wideband-receiver): `include/uapi/linux/lirc.h`, line 138

## Macros and Definitions

- [`LIRC_CAN_GET_REC_RESOLUTION`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-get-rec-resolution): `include/uapi/linux/lirc.h`, line 78
- [`LIRC_CAN_MEASURE_CARRIER`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-measure-carrier): `include/uapi/linux/lirc.h`, line 81
- [`LIRC_CAN_REC_LIRCCODE`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-rec-lirccode): `include/uapi/linux/lirc.h`, line 71
- [`LIRC_CAN_REC_MODE2`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-rec-mode2): `include/uapi/linux/lirc.h`, line 69
- [`LIRC_CAN_REC_PULSE`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-rec-pulse): `include/uapi/linux/lirc.h`, line 68
- [`LIRC_CAN_REC_RAW`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-rec-raw): `include/uapi/linux/lirc.h`, line 67
- [`LIRC_CAN_REC_SCANCODE`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-rec-scancode): `include/uapi/linux/lirc.h`, line 70
- [`LIRC_CAN_SEND_LIRCCODE`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-send-lirccode): `include/uapi/linux/lirc.h`, line 59
- [`LIRC_CAN_SEND_MODE2`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-send-mode2): `include/uapi/linux/lirc.h`, line 58
- [`LIRC_CAN_SEND_PULSE`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-send-pulse): `include/uapi/linux/lirc.h`, line 57
- [`LIRC_CAN_SEND_RAW`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-send-raw): `include/uapi/linux/lirc.h`, line 56
- [`LIRC_CAN_SET_REC_CARRIER`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-set-rec-carrier): `include/uapi/linux/lirc.h`, line 75
- [`LIRC_CAN_SET_REC_CARRIER_RANGE`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-set-rec-carrier-range): `include/uapi/linux/lirc.h`, line 77
- [`LIRC_CAN_SET_REC_TIMEOUT`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-set-rec-timeout): `include/uapi/linux/lirc.h`, line 79
- [`LIRC_CAN_SET_SEND_CARRIER`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-set-send-carrier): `include/uapi/linux/lirc.h`, line 63
- [`LIRC_CAN_SET_SEND_DUTY_CYCLE`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-set-send-duty-cycle): `include/uapi/linux/lirc.h`, line 64
- [`LIRC_CAN_SET_TRANSMITTER_MASK`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-set-transmitter-mask): `include/uapi/linux/lirc.h`, line 65
- [`LIRC_CAN_USE_WIDEBAND_RECEIVER`](/kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-use-wideband-receiver): `include/uapi/linux/lirc.h`, line 82
- [`LIRC_MODE2_FREQUENCY`](/kernel/userspace/userspace-api/media-rc/lirc-set-measure-carrier-mode.md#rst-lirc-mode2-frequency): `include/uapi/linux/lirc.h`, line 17
- [`LIRC_MODE_MODE2`](/kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-mode2): `include/uapi/linux/lirc.h`, line 51
- [`LIRC_MODE_PULSE`](/kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-pulse): `include/uapi/linux/lirc.h`, line 50
- [`LIRC_MODE_SCANCODE`](/kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-scancode): `include/uapi/linux/lirc.h`, line 52
- [`LIRC_SCANCODE_FLAG_REPEAT`](/kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-scancode-flag-repeat): `include/uapi/linux/lirc.h`, line 170
- [`LIRC_SCANCODE_FLAG_TOGGLE`](/kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-scancode-flag-toggle): `include/uapi/linux/lirc.h`, line 168

## Structures

- [`lirc_scancode`](/kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#c-struct-lirc_scancode): `include/uapi/linux/lirc.h`, line 159

---

# LIRC read()

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> lirc-read - Read from a LIRC device

<a id="rst-lirc-read-1"></a>
<a id="rst-lirc-read"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

<a id="rst-name"></a>

## Name

lirc-read - Read from a LIRC device

<a id="rst-synopsis"></a>

## Synopsis



```c
#include <unistd.h>
```





<a id="c-read"></a>

```c
ssize_t read( int fd, void *buf, size_t count )
```

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`buf`**

  Buffer to be filled

- **`count`**

  Max number of bytes to read

<a id="rst-description"></a>

## Description

`read()` attempts to read up to `count` bytes from file descriptor `fd` into the buffer starting at `buf`.  If `count` is zero, `read()` returns zero and has no other results. If `count` is greater than `SSIZE_MAX`, the result is unspecified.

The exact format of the data depends on what [LIRC modes](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-modes>) a driver uses. Use [ioctl LIRC_GET_FEATURES](</kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-get-features>) to get the supported mode, and use [ioctls LIRC_GET_REC_MODE and LIRC_SET_REC_MODE](</kernel/userspace/userspace-api/media-rc/lirc-get-rec-mode.md#rst-lirc-set-rec-mode>) set the current active mode.

The mode [LIRC_MODE_MODE2](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-mode2>) is for raw IR, in which packets containing an unsigned int value describing an IR signal are read from the chardev.

Alternatively, [LIRC_MODE_SCANCODE](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-scancode>) can be available, in this mode scancodes which are either decoded by software decoders, or by hardware decoders. The `rc_proto` member is set to the [IR protocol](</kernel/userspace/userspace-api/media-rc/rc-protos.md#rst-remote-controllers-protocols>) used for transmission, and `scancode` to the decoded scancode, and the `keycode` set to the keycode or `KEY_RESERVED`.

<a id="rst-return-value"></a>

## Return Value

On success, the number of bytes read is returned. It is not an error if this number is smaller than the number of bytes requested, or the amount of data required for one frame.  On error, -1 is returned, and the `errno` variable is set appropriately.

---

# ioctl LIRC_SET_MEASURE_CARRIER_MODE

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_SET_MEASURE_CARRIER_MODE - enable or disable measure mode

<a id="rst-ioctl-lirc-set-measure-carrier-mode"></a>
<a id="rst-lirc-set-measure-carrier-mode"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

<a id="rst-name"></a>

## Name

LIRC_SET_MEASURE_CARRIER_MODE - enable or disable measure mode

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-LIRC_SET_MEASURE_CARRIER_MODE"></a>

```c
LIRC_SET_MEASURE_CARRIER_MODE
```

`int ioctl(int fd, LIRC_SET_MEASURE_CARRIER_MODE, __u32 *enable)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`enable`**

  enable = 1 means enable measure mode, enable = 0 means disable measure mode.

<a id="rst-description"></a>

## Description

<a id="rst-lirc-mode2-frequency"></a>

Enable or disable 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.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl LIRC_SET_REC_CARRIER_RANGE

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_SET_REC_CARRIER_RANGE - Set lower bound of the carrier used to modulate IR receive.

<a id="rst-ioctl-lirc-set-rec-carrier-range"></a>
<a id="rst-lirc-set-rec-carrier-range"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

<a id="rst-name"></a>

## Name

LIRC_SET_REC_CARRIER_RANGE - Set lower bound of the carrier used to modulate IR receive.

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-LIRC_SET_REC_CARRIER_RANGE"></a>

```c
LIRC_SET_REC_CARRIER_RANGE
```

`int ioctl(int fd, LIRC_SET_REC_CARRIER_RANGE, __u32 *frequency)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`frequency`**

  Frequency of the carrier that modulates PWM data, in Hz.

<a id="rst-description"></a>

## Description

This ioctl sets the upper range of carrier frequency that will be recognized by the IR receiver.

> [!NOTE]
>
> To set a range use [LIRC_SET_REC_CARRIER_RANGE](<#rst-lirc-set-rec-carrier-range>) with the lower bound first and later call [LIRC_SET_REC_CARRIER](</kernel/userspace/userspace-api/media-rc/lirc-set-rec-carrier.md#rst-lirc-set-rec-carrier>) with the upper bound.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl LIRC_SET_REC_CARRIER

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_SET_REC_CARRIER - Set carrier used to modulate IR receive.

<a id="rst-ioctl-lirc-set-rec-carrier"></a>
<a id="rst-lirc-set-rec-carrier"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

<a id="rst-name"></a>

## Name

LIRC_SET_REC_CARRIER - Set carrier used to modulate IR receive.

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-LIRC_SET_REC_CARRIER"></a>

```c
LIRC_SET_REC_CARRIER
```

`int ioctl(int fd, LIRC_SET_REC_CARRIER, __u32 *frequency)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`frequency`**

  Frequency of the carrier that modulates PWM data, in Hz.

<a id="rst-description"></a>

## Description

Set receive carrier used to modulate IR PWM pulses and spaces.

> [!NOTE]
>
> If called together with [ioctl LIRC_SET_REC_CARRIER_RANGE](</kernel/userspace/userspace-api/media-rc/lirc-set-rec-carrier-range.md#rst-lirc-set-rec-carrier-range>), this ioctl sets the upper bound frequency that will be recognized by the device.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl LIRC_GET_REC_TIMEOUT and LIRC_SET_REC_TIMEOUT

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_GET_REC_TIMEOUT/LIRC_SET_REC_TIMEOUT - Get/set the integer value for IR inactivity timeout.

<a id="rst-ioctl-lirc-get-rec-timeout-and-lirc-set-rec-timeout"></a>
<a id="rst-lirc-get-rec-timeout"></a>
<a id="rst-lirc-set-rec-timeout"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

<a id="rst-name"></a>

## Name

LIRC_GET_REC_TIMEOUT/LIRC_SET_REC_TIMEOUT - Get/set the integer value for IR inactivity timeout.

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-LIRC_GET_REC_TIMEOUT"></a>

```c
LIRC_GET_REC_TIMEOUT
```

`int ioctl(int fd, LIRC_GET_REC_TIMEOUT, __u32 *timeout)`





<a id="c-LIRC_SET_REC_TIMEOUT"></a>

```c
LIRC_SET_REC_TIMEOUT
```

`int ioctl(int fd, LIRC_SET_REC_TIMEOUT, __u32 *timeout)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`timeout`**

  Timeout, in microseconds.

<a id="rst-description"></a>

## Description

Get and set the integer value for IR inactivity timeout.

If supported by the hardware, setting it to 0  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.

> [!NOTE]
>
> The range of supported timeout is given by [ioctls LIRC_GET_MIN_TIMEOUT and LIRC_GET_MAX_TIMEOUT](</kernel/userspace/userspace-api/media-rc/lirc-get-timeout.md#rst-lirc-get-min-timeout>).

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl LIRC_SET_SEND_CARRIER

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_SET_SEND_CARRIER - Set send carrier used to modulate IR TX.

<a id="rst-ioctl-lirc-set-send-carrier"></a>
<a id="rst-lirc-set-send-carrier"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

<a id="rst-name"></a>

## Name

LIRC_SET_SEND_CARRIER - Set send carrier used to modulate IR TX.

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-LIRC_SET_SEND_CARRIER"></a>

```c
LIRC_SET_SEND_CARRIER
```

`int ioctl(int fd, LIRC_SET_SEND_CARRIER, __u32 *frequency)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`frequency`**

  Frequency of the carrier to be modulated, in Hz.

<a id="rst-description"></a>

## Description

Set send carrier used to modulate IR PWM pulses and spaces.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl LIRC_SET_SEND_DUTY_CYCLE

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_SET_SEND_DUTY_CYCLE - Set the duty cycle of the carrier signal for IR transmit.

<a id="rst-ioctl-lirc-set-send-duty-cycle"></a>
<a id="rst-lirc-set-send-duty-cycle"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

<a id="rst-name"></a>

## Name

LIRC_SET_SEND_DUTY_CYCLE - Set the duty cycle of the carrier signal for IR transmit.

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-LIRC_SET_SEND_DUTY_CYCLE"></a>

```c
LIRC_SET_SEND_DUTY_CYCLE
```

`int ioctl(int fd, LIRC_SET_SEND_DUTY_CYCLE, __u32 *duty_cycle)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`duty_cycle`**

  Duty cycle, describing the pulse width in percent (from 1 to 99) of the total cycle. Values 0 and 100 are reserved.

<a id="rst-description"></a>

## Description

Get/set the duty cycle of the carrier signal for IR transmit.

Currently, no special meaning is defined for 0 or 100, but this could be used to switch off carrier generation in the future, so these values should be reserved.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl LIRC_SET_TRANSMITTER_MASK

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_SET_TRANSMITTER_MASK - Enables send codes on a given set of transmitters

<a id="rst-ioctl-lirc-set-transmitter-mask"></a>
<a id="rst-lirc-set-transmitter-mask"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

<a id="rst-name"></a>

## Name

LIRC_SET_TRANSMITTER_MASK - Enables send codes on a given set of transmitters

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-LIRC_SET_TRANSMITTER_MASK"></a>

```c
LIRC_SET_TRANSMITTER_MASK
```

`int ioctl(int fd, LIRC_SET_TRANSMITTER_MASK, __u32 *mask)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`mask`**

  Mask with channels to enable tx. Channel 0 is the least significant bit.

<a id="rst-description"></a>

## Description

Some IR TX devices have multiple output channels, in such case, [LIRC_CAN_SET_TRANSMITTER_MASK](</kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-can-set-transmitter-mask>) is returned via [ioctl LIRC_GET_FEATURES](</kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-get-features>) and this ioctl sets what channels will send IR codes.

This ioctl enables the given set of transmitters. The first transmitter is encoded by the least significant bit and so on.

When an invalid bit mask is given, i.e. a bit is set, even though the device does not have so many transitters, then this ioctl returns the number of available transitters and does nothing otherwise.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# ioctl LIRC_SET_WIDEBAND_RECEIVER

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> LIRC_SET_WIDEBAND_RECEIVER - enable wide band receiver.

<a id="rst-ioctl-lirc-set-wideband-receiver"></a>
<a id="rst-lirc-set-wideband-receiver"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

<a id="rst-name"></a>

## Name

LIRC_SET_WIDEBAND_RECEIVER - enable wide band receiver.

<a id="rst-synopsis"></a>

## Synopsis





<a id="c-LIRC_SET_WIDEBAND_RECEIVER"></a>

```c
LIRC_SET_WIDEBAND_RECEIVER
```

`int ioctl(int fd, LIRC_SET_WIDEBAND_RECEIVER, __u32 *enable)`

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by open().

- **`enable`**

  enable = 1 means enable wideband receiver, enable = 0 means disable wideband receiver.

<a id="rst-description"></a>

## Description

Some receivers are equipped with special wide band receiver which is intended to be used to learn output of existing remote. This ioctl allows enabling or disabling it.

This might be useful of receivers that have otherwise narrow band receiver that prevents them to be used with some remotes. Wide band receiver might also be more precise. On the other hand its disadvantage it usually reduced range of reception.

> [!NOTE]
>
> Wide band receiver might 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 wide band receiver while carrier reports are active will do nothing.

<a id="rst-return-value"></a>

## Return Value

On success 0 is returned, on error -1 and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# LIRC write()

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> lirc-write - Write to a LIRC device

<a id="rst-lirc-write-1"></a>
<a id="rst-lirc-write"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- c:namespace: RC -->

<a id="rst-name"></a>

## Name

lirc-write - Write to a LIRC device

<a id="rst-synopsis"></a>

## Synopsis



```c
#include <unistd.h>
```





<a id="c-write"></a>

```c
ssize_t write( int fd, void *buf, size_t count )
```

<a id="rst-arguments"></a>

## Arguments

- **`fd`**

  File descriptor returned by `open()`.

- **`buf`**

  Buffer with data to be written

- **`count`**

  Number of bytes at the buffer

<a id="rst-description"></a>

## Description

`write()` writes up to `count` bytes to the device referenced by the file descriptor `fd` from the buffer starting at `buf`.

The exact format of the data depends on what mode a driver is in, use [ioctl LIRC_GET_FEATURES](</kernel/userspace/userspace-api/media-rc/lirc-get-features.md#rst-lirc-get-features>) to get the supported modes and use [ioctls LIRC_GET_SEND_MODE and LIRC_SET_SEND_MODE](</kernel/userspace/userspace-api/media-rc/lirc-get-send-mode.md#rst-lirc-set-send-mode>) set the mode.

When in [LIRC_MODE_PULSE](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-pulse>) mode, the data written to the chardev 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, therefore, the data must always include an uneven number of samples. The write function blocks until the data has been transmitted by the hardware. If more data is provided than the hardware can send, the driver returns `EINVAL`.

When in [LIRC_MODE_SCANCODE](</kernel/userspace/userspace-api/media-rc/lirc-dev-intro.md#rst-lirc-mode-scancode>) mode, one `struct lirc_scancode` must be written to the chardev at a time, else `EINVAL` is returned. Set the desired scancode in the `scancode` member, and the [IR protocol](</kernel/userspace/userspace-api/media-rc/rc-protos.md#rst-remote-controllers-protocols>) in the `rc_proto`: member. All other members must be set to 0, else `EINVAL` is returned. If there is no protocol encoder for the protocol or the scancode is not valid for the specified protocol, `EINVAL` is returned. The write function blocks until the scancode is transmitted by the hardware.

<a id="rst-return-value"></a>

## Return Value

On success, the number of bytes written is returned. It is not an error if this number is smaller than the number of bytes requested, or the amount of data required for one frame.  On error, -1 is returned, and the `errno` variable is set appropriately. The generic error codes are described at the [Generic Error Codes](</kernel/userspace/userspace-api/media/gen-errors.md#rst-gen-errors-1>) chapter.

---

# Introduction

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> Currently, most analog and digital devices have a Infrared input for remote controllers. Each manufacturer has their own type of control. It is not rare for the same manufacturer to ship different types of controls, depending on the device.

<a id="rst-introduction"></a>
<a id="rst-remote-controllers-intro"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

Currently, most analog and digital devices have a Infrared input for remote controllers. Each manufacturer has their own type of control. It is not rare for the same manufacturer to ship different types of controls, depending on the device.

A Remote Controller interface is mapped as a normal evdev/input interface, just like a keyboard or a mouse. So, it uses all ioctls already defined for any other input devices.

However, remove controllers are more flexible than a normal input device, as the IR receiver (and/or transmitter) can be used in conjunction with a wide variety of different IR remotes.

In order to allow flexibility, the Remote Controller subsystem allows controlling the RC-specific attributes via [the sysfs class nodes](</kernel/userspace/userspace-api/media-rc/rc-sysfs-nodes.md#rst-remote-controllers-sysfs-nodes>).

---

# Remote Controller Protocols and Scancodes

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> IR is encoded as a series of pulses and spaces, using a protocol. These protocols can encode e.g. an address (which device should respond) and a command: what it should do. The values for these are not always consistent across different…

<a id="rst-remote-controller-protocols-and-scancodes"></a>
<a id="rst-remote-controllers-protocols"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

IR is encoded as a series of pulses and spaces, using a protocol. These protocols can encode e.g. an address (which device should respond) and a command: what it should do. The values for these are not always consistent across different devices for a given protocol.

Therefore out the output of the IR decoder is a scancode; a single u32 value. Using keymap tables this can be mapped to linux key codes.

Other things can be encoded too. Some IR protocols encode a toggle bit; this is to distinguish whether the same button is being held down, or has been released and pressed again. If has been released and pressed again, the toggle bit will invert from one IR message to the next.

Some remotes have a pointer-type device which can used to control the mouse; some air conditioning systems can have their target temperature target set in IR.

The following are the protocols the kernel knows about and also lists how scancodes are encoded for each protocol.

<a id="rst-rc-5-rc-proto-rc5"></a>

## rc-5 (RC_PROTO_RC5)

This IR protocol uses manchester encoding to encode 14 bits. There is a detailed description here [https://www.sbprojects.net/knowledge/ir/rc5.php](<https://www.sbprojects.net/knowledge/ir/rc5.php>).

The scancode encoding is *not* consistent with the lirc daemon (lircd) rc5 protocol, or the manchester BPF decoder.


<table>
<caption>rc5 bits scancode mapping</caption>
<tbody>
<tr>
<td>


rc-5 bit

</td>
<td>


scancode bit

</td>
<td>


description

</td>
</tr>
<tr>
<td>


1

</td>
<td>


none

</td>
<td>


Start bit, always set

</td>
</tr>
<tr>
<td>


1

</td>
<td>


6 (inverted)

</td>
<td>


2nd start bit in rc5,  re-used as 6th command bit

</td>
</tr>
<tr>
<td>


1

</td>
<td>


none

</td>
<td>


Toggle bit

</td>
</tr>
<tr>
<td>


5

</td>
<td>


8 to 13

</td>
<td>


Address

</td>
</tr>
<tr>
<td>


6

</td>
<td>


0 to 5

</td>
<td>


Command

</td>
</tr>
</tbody>
</table>

There is a variant of rc5 called either rc5x or extended rc5 where there the second stop bit is the 6th command bit, but inverted. This is done so it the scancodes and encoding is compatible with existing schemes. This bit is stored in bit 6 of the scancode, inverted. This is done to keep it compatible with plain rc-5 where there are two start bits.

<a id="rst-rc-5-sz-rc-proto-rc5-sz"></a>

## rc-5-sz (RC_PROTO_RC5_SZ)

This is much like rc-5 but one bit longer. The scancode is encoded differently.


<table>
<caption>rc-5-sz bits scancode mapping</caption>
<tbody>
<tr>
<td>


rc-5-sz bits

</td>
<td>


scancode bit

</td>
<td>


description

</td>
</tr>
<tr>
<td>


1

</td>
<td>


none

</td>
<td>


Start bit, always set

</td>
</tr>
<tr>
<td>


1

</td>
<td>


13

</td>
<td>


Address bit

</td>
</tr>
<tr>
<td>


1

</td>
<td>


none

</td>
<td>


Toggle bit

</td>
</tr>
<tr>
<td>


6

</td>
<td>


6 to 11

</td>
<td>


Address

</td>
</tr>
<tr>
<td>


6

</td>
<td>


0 to 5

</td>
<td>


Command

</td>
</tr>
</tbody>
</table>

<a id="rst-rc-5x-20-rc-proto-rc5x-20"></a>

## rc-5x-20 (RC_PROTO_RC5X_20)

This rc-5 extended to encoded 20 bits. The is a 3555 microseconds space after the 8th bit.


<table>
<caption>rc-5x-20 bits scancode mapping</caption>
<tbody>
<tr>
<td>


rc-5-sz bits

</td>
<td>


scancode bit

</td>
<td>


description

</td>
</tr>
<tr>
<td>


1

</td>
<td>


none

</td>
<td>


Start bit, always set

</td>
</tr>
<tr>
<td>


1

</td>
<td>


14

</td>
<td>


Address bit

</td>
</tr>
<tr>
<td>


1

</td>
<td>


none

</td>
<td>


Toggle bit

</td>
</tr>
<tr>
<td>


5

</td>
<td>


16 to 20

</td>
<td>


Address

</td>
</tr>
<tr>
<td>


6

</td>
<td>


8 to 13

</td>
<td>


Address

</td>
</tr>
<tr>
<td>


6

</td>
<td>


0 to 5

</td>
<td>


Command

</td>
</tr>
</tbody>
</table>

<a id="rst-jvc-rc-proto-jvc"></a>

## jvc (RC_PROTO_JVC)

The jvc protocol is much like nec, without the inverted values. It is described here [https://www.sbprojects.net/knowledge/ir/jvc.php](<https://www.sbprojects.net/knowledge/ir/jvc.php>).

The scancode is a 16 bits value, where the address is the lower 8 bits and the command the higher 8 bits; this is reversed from IR order.

<a id="rst-sony-12-rc-proto-sony12"></a>

## sony-12 (RC_PROTO_SONY12)

The sony protocol is a pulse-width encoding. There are three variants, which just differ in number of bits and scancode encoding.


<table>
<caption>sony-12 bits scancode mapping</caption>
<tbody>
<tr>
<td>


sony-12 bits

</td>
<td>


scancode bit

</td>
<td>


description

</td>
</tr>
<tr>
<td>


5

</td>
<td>


16 to 20

</td>
<td>


device

</td>
</tr>
<tr>
<td>


7

</td>
<td>


0 to 6

</td>
<td>


function

</td>
</tr>
</tbody>
</table>

<a id="rst-sony-15-rc-proto-sony15"></a>

## sony-15 (RC_PROTO_SONY15)

The sony protocol is a pulse-width encoding. There are three variants, which just differ in number of bits and scancode encoding.


<table>
<caption>sony-12 bits scancode mapping</caption>
<tbody>
<tr>
<td>


sony-12 bits

</td>
<td>


scancode bit

</td>
<td>


description

</td>
</tr>
<tr>
<td>


8

</td>
<td>


16 to 23

</td>
<td>


device

</td>
</tr>
<tr>
<td>


7

</td>
<td>


0 to 6

</td>
<td>


function

</td>
</tr>
</tbody>
</table>

<a id="rst-sony-20-rc-proto-sony20"></a>

## sony-20 (RC_PROTO_SONY20)

The sony protocol is a pulse-width encoding. There are three variants, which just differ in number of bits and scancode encoding.


<table>
<caption>sony-20 bits scancode mapping</caption>
<tbody>
<tr>
<td>


sony-20 bits

</td>
<td>


scancode bit

</td>
<td>


description

</td>
</tr>
<tr>
<td>


5

</td>
<td>


16 to 20

</td>
<td>


device

</td>
</tr>
<tr>
<td>


7

</td>
<td>


0 to 7

</td>
<td>


device

</td>
</tr>
<tr>
<td>


8

</td>
<td>


8 to 15

</td>
<td>


extended bits

</td>
</tr>
</tbody>
</table>

<a id="rst-nec-rc-proto-nec"></a>

## nec (RC_PROTO_NEC)

The nec protocol encodes an 8 bit address and an 8 bit command. It is described here [https://www.sbprojects.net/knowledge/ir/nec.php](<https://www.sbprojects.net/knowledge/ir/nec.php>). Note that the protocol sends least significant bit first.

As a check, the nec protocol sends the address and command twice; the second time it is inverted. This is done for verification.

A plain nec IR message has 16 bits; the high 8 bits are the address and the low 8 bits are the command.

<a id="rst-nec-x-rc-proto-necx"></a>

## nec-x (RC_PROTO_NECX)

Extended nec has a 16 bit address and a 8 bit command. This is encoded as a 24 bit value as you would expect, with the lower 8 bits the command and the upper 16 bits the address.

<a id="rst-nec-32-rc-proto-nec32"></a>

## nec-32 (RC_PROTO_NEC32)

nec-32 does not send an inverted address or an inverted command; the entire message, all 32 bits, are used.

For this to be decoded correctly, the second 8 bits must not be the inverted value of the first, and also the last 8 bits must not be the inverted value of the third 8 bit value.

The scancode has a somewhat unusual encoding.


<table>
<caption>nec-32 bits scancode mapping</caption>
<tbody>
<tr>
<td>


nec-32 bits

</td>
<td>


scancode bit

</td>
</tr>
<tr>
<td>


First 8 bits

</td>
<td>


16 to 23

</td>
</tr>
<tr>
<td>


Second 8 bits

</td>
<td>


24 to 31

</td>
</tr>
<tr>
<td>


Third 8 bits

</td>
<td>


0 to 7

</td>
</tr>
<tr>
<td>


Fourth 8 bits

</td>
<td>


8 to 15

</td>
</tr>
</tbody>
</table>

<a id="rst-sanyo-rc-proto-sanyo"></a>

## sanyo (RC_PROTO_SANYO)

The sanyo protocol is like the nec protocol, but with 13 bits address rather than 8 bits. Both the address and the command are followed by their inverted versions, but these are not present in the scancodes.

Bis 8 to 20 of the scancode is the 13 bits address, and the lower 8 bits are the command.

<a id="rst-mcir2-kbd-rc-proto-mcir2-kbd"></a>

## mcir2-kbd (RC_PROTO_MCIR2_KBD)

This protocol is generated by the Microsoft MCE keyboard for keyboard events. Refer to the ir-mce_kbd-decoder.c to see how it is encoded.

<a id="rst-mcir2-mse-rc-proto-mcir2-mse"></a>

## mcir2-mse (RC_PROTO_MCIR2_MSE)

This protocol is generated by the Microsoft MCE keyboard for pointer events. Refer to the ir-mce_kbd-decoder.c to see how it is encoded.

<a id="rst-rc-6-0-rc-proto-rc6-0"></a>

## rc-6-0 (RC_PROTO_RC6_0)

This is the rc-6 in mode 0. rc-6 is described here [https://www.sbprojects.net/knowledge/ir/rc6.php](<https://www.sbprojects.net/knowledge/ir/rc6.php>). The scancode is the exact 16 bits as in the protocol. There is also a toggle bit.

<a id="rst-rc-6-6a-20-rc-proto-rc6-6a-20"></a>

## rc-6-6a-20 (RC_PROTO_RC6_6A_20)

This is the rc-6 in mode 6a, 20 bits. rc-6 is described here [https://www.sbprojects.net/knowledge/ir/rc6.php](<https://www.sbprojects.net/knowledge/ir/rc6.php>). The scancode is the exact 20 bits as in the protocol. There is also a toggle bit.

<a id="rst-rc-6-6a-24-rc-proto-rc6-6a-24"></a>

## rc-6-6a-24 (RC_PROTO_RC6_6A_24)

This is the rc-6 in mode 6a, 24 bits. rc-6 is described here [https://www.sbprojects.net/knowledge/ir/rc6.php](<https://www.sbprojects.net/knowledge/ir/rc6.php>). The scancode is the exact 24 bits as in the protocol. There is also a toggle bit.

<a id="rst-rc-6-6a-32-rc-proto-rc6-6a-32"></a>

## rc-6-6a-32 (RC_PROTO_RC6_6A_32)

This is the rc-6 in mode 6a, 32 bits. rc-6 is described here [https://www.sbprojects.net/knowledge/ir/rc6.php](<https://www.sbprojects.net/knowledge/ir/rc6.php>). The upper 16 bits are the vendor, and the lower 16 bits are the vendor-specific bits. This protocol is for the non-Microsoft MCE variant (vendor \!= 0x800f).

<a id="rst-rc-6-mce-rc-proto-rc6-mce"></a>

## rc-6-mce (RC_PROTO_RC6_MCE)

This is the rc-6 in mode 6a, 32 bits. The upper 16 bits are the vendor, and the lower 16 bits are the vendor-specific bits. This protocol is for the Microsoft MCE variant (vendor = 0x800f). The toggle bit in the protocol itself is ignored, and the 16th bit should be takes as the toggle bit.

<a id="rst-sharp-rc-proto-sharp"></a>

## sharp (RC_PROTO_SHARP)

This is a protocol used by Sharp VCRs, is described here [https://www.sbprojects.net/knowledge/ir/sharp.php](<https://www.sbprojects.net/knowledge/ir/sharp.php>). There is a very long (40ms) space between the normal and inverted values, and some IR receivers cannot decode this.

There is a 5 bit address and a 8 bit command. In the scancode the address is in bits 8 to 12, and the command in bits 0 to 7.

<a id="rst-xmp-rc-proto-xmp"></a>

## xmp (RC_PROTO_XMP)

This protocol has several versions and only version 1 is supported. Refer to the decoder (ir-xmp-decoder.c) to see how it is encoded.

<a id="rst-cec-rc-proto-cec"></a>

## cec (RC_PROTO_CEC)

This is not an IR protocol, this is a protocol over CEC. The CEC infrastructure uses rc-core for handling CEC commands, so that they can easily be remapped.

<a id="rst-imon-rc-proto-imon"></a>

## imon (RC_PROTO_IMON)

This protocol is used by Antec Veris/SoundGraph iMON remotes.

The protocol describes both button presses and pointer movements. The protocol encodes 31 bits, and the scancode is simply the 31 bits with the top bit always 0.

<a id="rst-rc-mm-12-rc-proto-rcmm12"></a>

## rc-mm-12 (RC_PROTO_RCMM12)

The rc-mm protocol is described here [https://www.sbprojects.net/knowledge/ir/rcmm.php](<https://www.sbprojects.net/knowledge/ir/rcmm.php>). The scancode is simply the 12 bits.

<a id="rst-rc-mm-24-rc-proto-rcmm24"></a>

## rc-mm-24 (RC_PROTO_RCMM24)

The rc-mm protocol is described here [https://www.sbprojects.net/knowledge/ir/rcmm.php](<https://www.sbprojects.net/knowledge/ir/rcmm.php>). The scancode is simply the 24 bits.

<a id="rst-rc-mm-32-rc-proto-rcmm32"></a>

## rc-mm-32 (RC_PROTO_RCMM32)

The rc-mm protocol is described here [https://www.sbprojects.net/knowledge/ir/rcmm.php](<https://www.sbprojects.net/knowledge/ir/rcmm.php>). The scancode is simply the 32 bits.

<a id="rst-xbox-dvd-rc-proto-xbox-dvd"></a>

## xbox-dvd (RC_PROTO_XBOX_DVD)

This protocol is used by Xbox DVD Remote, which was made for the original Xbox. There is no in-kernel decoder or encoder for this protocol. The usb device decodes the protocol. There is a BPF decoder available in v4l-utils.

---

# Remote Controller's sysfs nodes

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> As defined at Documentation/ABI/testing/sysfs-class-rc, those are the sysfs nodes that control the Remote Controllers:

<a id="rst-remote-controller-s-sysfs-nodes"></a>
<a id="rst-remote-controllers-sysfs-nodes"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

As defined at Documentation/ABI/testing/sysfs-class-rc, those are the sysfs nodes that control the Remote Controllers:

<a id="rst-sys-class-rc-1"></a>
<a id="rst-sys-class-rc"></a>

## /sys/class/rc/

The `/sys/class/rc/` class sub-directory belongs to the Remote Controller core and provides a sysfs interface for configuring infrared remote controller receivers.

<a id="rst-sys-class-rc-rcn-1"></a>
<a id="rst-sys-class-rc-rcn"></a>

## /sys/class/rc/rcN/

A `/sys/class/rc/rcN` directory is created for each remote control receiver device where N is the number of the receiver.

<a id="rst-sys-class-rc-rcn-protocols-1"></a>
<a id="rst-sys-class-rc-rcn-protocols"></a>

## /sys/class/rc/rcN/protocols

Reading this file returns a list of available protocols, something like:



```text
rc5 [rc6] nec jvc [sony]
```

Enabled protocols are shown in \[\] brackets.

Writing "+proto" will add a protocol to the list of enabled protocols.

Writing "-proto" will remove a protocol from the list of enabled protocols.

Writing "proto" will enable only "proto".

Writing "none" will disable all protocols.

Write fails with `EINVAL` if an invalid protocol combination or unknown protocol name is used.

<a id="rst-sys-class-rc-rcn-filter-1"></a>
<a id="rst-sys-class-rc-rcn-filter"></a>

## /sys/class/rc/rcN/filter

Sets the scancode filter expected value.

Use in combination with `/sys/class/rc/rcN/filter_mask` to set the expected value of the bits set in the filter mask. If the hardware supports it then scancodes which do not match the filter will be ignored. Otherwise the write will fail with an error.

This value may be reset to 0 if the current protocol is altered.

<a id="rst-sys-class-rc-rcn-filter-mask-1"></a>
<a id="rst-sys-class-rc-rcn-filter-mask"></a>

## /sys/class/rc/rcN/filter_mask

Sets the scancode filter mask of bits to compare. Use in combination with `/sys/class/rc/rcN/filter` to set the bits of the scancode which should be compared against the expected value. A value of 0 disables the filter to allow all valid scancodes to be processed.

If the hardware supports it then scancodes which do not match the filter will be ignored. Otherwise the write will fail with an error.

This value may be reset to 0 if the current protocol is altered.

<a id="rst-sys-class-rc-rcn-wakeup-protocols-1"></a>
<a id="rst-sys-class-rc-rcn-wakeup-protocols"></a>

## /sys/class/rc/rcN/wakeup_protocols

Reading this file returns a list of available protocols to use for the wakeup filter, something like:



```text
rc-5 nec nec-x rc-6-0 rc-6-6a-24 [rc-6-6a-32] rc-6-mce
```

Note that protocol variants are listed, so `nec`, `sony`, `rc-5`, `rc-6` have their different bit length encodings listed if available.

Note that all protocol variants are listed.

The enabled wakeup protocol is shown in \[\] brackets.

Only one protocol can be selected at a time.

Writing "proto" will use "proto" for wakeup events.

Writing "none" will disable wakeup.

Write fails with `EINVAL` if an invalid protocol combination or unknown protocol name is used, or if wakeup is not supported by the hardware.

<a id="rst-sys-class-rc-rcn-wakeup-filter-1"></a>
<a id="rst-sys-class-rc-rcn-wakeup-filter"></a>

## /sys/class/rc/rcN/wakeup_filter

Sets the scancode wakeup filter expected value. Use in combination with `/sys/class/rc/rcN/wakeup_filter_mask` to set the expected value of the bits set in the wakeup filter mask to trigger a system wake event.

If the hardware supports it and wakeup_filter_mask is not 0 then scancodes which match the filter will wake the system from e.g. suspend to RAM or power off. Otherwise the write will fail with an error.

This value may be reset to 0 if the wakeup protocol is altered.

<a id="rst-sys-class-rc-rcn-wakeup-filter-mask-1"></a>
<a id="rst-sys-class-rc-rcn-wakeup-filter-mask"></a>

## /sys/class/rc/rcN/wakeup_filter_mask

Sets the scancode wakeup filter mask of bits to compare. Use in combination with `/sys/class/rc/rcN/wakeup_filter` to set the bits of the scancode which should be compared against the expected value to trigger a system wake event.

If the hardware supports it and wakeup_filter_mask is not 0 then scancodes which match the filter will wake the system from e.g. suspend to RAM or power off. Otherwise the write will fail with an error.

This value may be reset to 0 if the wakeup protocol is altered.

---

# Changing default Remote Controller mappings

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> The event interface provides two ioctls to be used against the /dev/input/event device, to allow changing the default keymapping.

<a id="rst-changing-default-remote-controller-mappings"></a>
<a id="rst-remote-controllers-table-change"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

The event interface provides two ioctls to be used against the /dev/input/event device, to allow changing the default keymapping.

This program demonstrates how to replace the keymap tables.

- [file: uapi/v4l/keytable.c](</kernel/userspace/userspace-api/media-rc/keytable-c.md>)

---

# Remote controller tables

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> Unfortunately, for several years, there was no effort to create uniform IR keycodes for different devices. This caused the same IR keyname to be mapped completely differently on different IR devices. This resulted that the same IR keyname…

<a id="rst-remote-controller-tables"></a>
<a id="rst-remote-controllers-tables"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

Unfortunately, for several years, there was no effort to create uniform IR keycodes for different devices. This caused the same IR keyname to be mapped completely differently on different IR devices. This resulted that the same IR keyname to be mapped completely different on different IR's. Due to that, V4L2 API now specifies a standard for mapping Media keys on IR.

This standard should be used by both V4L/DVB drivers and userspace applications

The modules register the remote as keyboard within the linux input layer. This means that the IR key strokes will look like normal keyboard key strokes (if CONFIG\_INPUT\_KEYBOARD is enabled). Using the event devices (CONFIG\_INPUT\_EVDEV) it is possible for applications to access the remote via /dev/input/event devices.

<a id="rst-rc-standard-keymap"></a>



<!-- tabularcolumns: |p{4.4cm}|p{4.4cm}|p{8.5cm}| -->


<table>
<caption>

IR default keymapping

</caption>
<tbody>
<tr>
<td>



Key code

</td>
<td>



Meaning

</td>
<td>



Key examples on IR

</td>
</tr>
<tr>
<td colspan="3">



<strong>Numeric keys</strong>

</td>
</tr>
<tr>
<td>



`KEY_NUMERIC_0`

</td>
<td>



Keyboard digit 0

</td>
<td>



0

</td>
</tr>
<tr>
<td>



`KEY_NUMERIC_1`

</td>
<td>



Keyboard digit 1

</td>
<td>



1

</td>
</tr>
<tr>
<td>



`KEY_NUMERIC_2`

</td>
<td>



Keyboard digit 2

</td>
<td>



2

</td>
</tr>
<tr>
<td>



`KEY_NUMERIC_3`

</td>
<td>



Keyboard digit 3

</td>
<td>



3

</td>
</tr>
<tr>
<td>



`KEY_NUMERIC_4`

</td>
<td>



Keyboard digit 4

</td>
<td>



4

</td>
</tr>
<tr>
<td>



`KEY_NUMERIC_5`

</td>
<td>



Keyboard digit 5

</td>
<td>



5

</td>
</tr>
<tr>
<td>



`KEY_NUMERIC_6`

</td>
<td>



Keyboard digit 6

</td>
<td>



6

</td>
</tr>
<tr>
<td>



`KEY_NUMERIC_7`

</td>
<td>



Keyboard digit 7

</td>
<td>



7

</td>
</tr>
<tr>
<td>



`KEY_NUMERIC_8`

</td>
<td>



Keyboard digit 8

</td>
<td>



8

</td>
</tr>
<tr>
<td>



`KEY_NUMERIC_9`

</td>
<td>



Keyboard digit 9

</td>
<td>



9

</td>
</tr>
<tr>
<td colspan="3">



<strong>Movie play control</strong>

</td>
</tr>
<tr>
<td>



`KEY_FORWARD`

</td>
<td>



Instantly advance in time

</td>
<td>



&gt;&gt; / FORWARD

</td>
</tr>
<tr>
<td>



`KEY_BACK`

</td>
<td>



Instantly go back in time

</td>
<td>



&lt;&lt;&lt; / BACK

</td>
</tr>
<tr>
<td>



`KEY_FASTFORWARD`

</td>
<td>



Play movie faster

</td>
<td>



```pycon
>>> / FORWARD
```

</td>
</tr>
<tr>
<td>



`KEY_REWIND`

</td>
<td>



Play movie back

</td>
<td>



REWIND / BACKWARD

</td>
</tr>
<tr>
<td>



`KEY_NEXT`

</td>
<td>



Select next chapter / sub-chapter / interval

</td>
<td>



NEXT / SKIP

</td>
</tr>
<tr>
<td>



`KEY_PREVIOUS`

</td>
<td>



Select previous chapter / sub-chapter / interval

</td>
<td>



&lt;&lt; / PREV / PREVIOUS

</td>
</tr>
<tr>
<td>



`KEY_AGAIN`

</td>
<td>



Repeat the video or a video interval

</td>
<td>



REPEAT / LOOP / RECALL

</td>
</tr>
<tr>
<td>



`KEY_PAUSE`

</td>
<td>



Pause stream

</td>
<td>



PAUSE / FREEZE

</td>
</tr>
<tr>
<td>



`KEY_PLAY`

</td>
<td>



Play movie at the normal timeshift

</td>
<td>



NORMAL TIMESHIFT / LIVE / &gt;

</td>
</tr>
<tr>
<td>



`KEY_PLAYPAUSE`

</td>
<td>



Alternate between play and pause

</td>
<td>



PLAY / PAUSE

</td>
</tr>
<tr>
<td>



`KEY_STOP`

</td>
<td>



Stop stream

</td>
<td>



STOP

</td>
</tr>
<tr>
<td>



`KEY_RECORD`

</td>
<td>



Start/stop recording stream

</td>
<td>



CAPTURE / REC / RECORD/PAUSE

</td>
</tr>
<tr>
<td>



`KEY_CAMERA`

</td>
<td>



Take a picture of the image

</td>
<td>



CAMERA ICON / CAPTURE / SNAPSHOT

</td>
</tr>
<tr>
<td>



`KEY_SHUFFLE`

</td>
<td>



Enable shuffle mode

</td>
<td>



SHUFFLE

</td>
</tr>
<tr>
<td>



`KEY_TIME`

</td>
<td>



Activate time shift mode

</td>
<td>



TIME SHIFT

</td>
</tr>
<tr>
<td>



`KEY_TITLE`

</td>
<td>



Allow changing the chapter

</td>
<td>



CHAPTER

</td>
</tr>
<tr>
<td>



`KEY_SUBTITLE`

</td>
<td>



Allow changing the subtitle

</td>
<td>



SUBTITLE

</td>
</tr>
<tr>
<td colspan="3">



<strong>Image control</strong>

</td>
</tr>
<tr>
<td>



`KEY_BRIGHTNESSDOWN`

</td>
<td>



Decrease Brightness

</td>
<td>



BRIGHTNESS DECREASE

</td>
</tr>
<tr>
<td>



`KEY_BRIGHTNESSUP`

</td>
<td>



Increase Brightness

</td>
<td>



BRIGHTNESS INCREASE

</td>
</tr>
<tr>
<td>



`KEY_ANGLE`

</td>
<td>



Switch video camera angle (on videos with more than one angle stored)

</td>
<td>



ANGLE / SWAP

</td>
</tr>
<tr>
<td>



`KEY_EPG`

</td>
<td>



Open the Elecrowonic Play Guide (EPG)

</td>
<td>



EPG / GUIDE

</td>
</tr>
<tr>
<td>



`KEY_TEXT`

</td>
<td>



Activate/change closed caption mode

</td>
<td>



CLOSED CAPTION/TELETEXT / DVD TEXT / TELETEXT / TTX

</td>
</tr>
<tr>
<td colspan="3">



<strong>Audio control</strong>

</td>
</tr>
<tr>
<td>



`KEY_AUDIO`

</td>
<td>



Change audio source

</td>
<td>



AUDIO SOURCE / AUDIO / MUSIC

</td>
</tr>
<tr>
<td>



`KEY_MUTE`

</td>
<td>



Mute/unmute audio

</td>
<td>



MUTE / DEMUTE / UNMUTE

</td>
</tr>
<tr>
<td>



`KEY_VOLUMEDOWN`

</td>
<td>



Decrease volume

</td>
<td>



VOLUME- / VOLUME DOWN

</td>
</tr>
<tr>
<td>



`KEY_VOLUMEUP`

</td>
<td>



Increase volume

</td>
<td>



VOLUME+ / VOLUME UP

</td>
</tr>
<tr>
<td>



`KEY_MODE`

</td>
<td>



Change sound mode

</td>
<td>



MONO/STEREO

</td>
</tr>
<tr>
<td>



`KEY_LANGUAGE`

</td>
<td>



Select Language

</td>
<td>



1ST / 2ND LANGUAGE / DVD LANG / MTS/SAP / MTS SEL

</td>
</tr>
<tr>
<td colspan="3">



<strong>Channel control</strong>

</td>
</tr>
<tr>
<td>



`KEY_CHANNEL`

</td>
<td>



Go to the next favorite channel

</td>
<td>



ALT / CHANNEL / CH SURFING / SURF / FAV

</td>
</tr>
<tr>
<td>



`KEY_CHANNELDOWN`

</td>
<td>



Decrease channel sequentially

</td>
<td>



CHANNEL - / CHANNEL DOWN / DOWN

</td>
</tr>
<tr>
<td>



`KEY_CHANNELUP`

</td>
<td>



Increase channel sequentially

</td>
<td>



CHANNEL + / CHANNEL UP / UP

</td>
</tr>
<tr>
<td>



`KEY_DIGITS`

</td>
<td>



Use more than one digit for channel

</td>
<td>



PLUS / 100/ 1xx / xxx / -/-- / Single Double Triple Digit

</td>
</tr>
<tr>
<td>



`KEY_SEARCH`

</td>
<td>



Start channel autoscan

</td>
<td>



SCAN / AUTOSCAN

</td>
</tr>
<tr>
<td colspan="3">



<strong>Colored keys</strong>

</td>
</tr>
<tr>
<td>



`KEY_BLUE`

</td>
<td>



IR Blue key

</td>
<td>



BLUE

</td>
</tr>
<tr>
<td>



`KEY_GREEN`

</td>
<td>



IR Green Key

</td>
<td>



GREEN

</td>
</tr>
<tr>
<td>



`KEY_RED`

</td>
<td>



IR Red key

</td>
<td>



RED

</td>
</tr>
<tr>
<td>



`KEY_YELLOW`

</td>
<td>



IR Yellow key

</td>
<td>



YELLOW

</td>
</tr>
<tr>
<td colspan="3">



<strong>Media selection</strong>

</td>
</tr>
<tr>
<td>



`KEY_CD`

</td>
<td>



Change input source to Compact Disc

</td>
<td>



CD

</td>
</tr>
<tr>
<td>



`KEY_DVD`

</td>
<td>



Change input to DVD

</td>
<td>



DVD / DVD MENU

</td>
</tr>
<tr>
<td>



`KEY_EJECTCLOSECD`

</td>
<td>



Open/close the CD/DVD player

</td>
<td>



-&gt; ) / CLOSE / OPEN

</td>
</tr>
<tr>
<td>



`KEY_MEDIA`

</td>
<td>



Turn on/off Media application

</td>
<td>



PC/TV / TURN ON/OFF APP

</td>
</tr>
<tr>
<td>



`KEY_PC`

</td>
<td>



Selects from TV to PC

</td>
<td>



PC

</td>
</tr>
<tr>
<td>



`KEY_RADIO`

</td>
<td>



Put into AM/FM radio mode

</td>
<td>



RADIO / TV/FM / TV/RADIO / FM / FM/RADIO

</td>
</tr>
<tr>
<td>



`KEY_TV`

</td>
<td>



Select tv mode

</td>
<td>



TV / LIVE TV

</td>
</tr>
<tr>
<td>



`KEY_TV2`

</td>
<td>



Select Cable mode

</td>
<td>



AIR/CBL

</td>
</tr>
<tr>
<td>



`KEY_VCR`

</td>
<td>



Select VCR mode

</td>
<td>



VCR MODE / DTR

</td>
</tr>
<tr>
<td>



`KEY_VIDEO`

</td>
<td>



Alternate between input modes

</td>
<td>



SOURCE / SELECT / DISPLAY / SWITCH INPUTS / VIDEO

</td>
</tr>
<tr>
<td colspan="3">



<strong>Power control</strong>

</td>
</tr>
<tr>
<td>



`KEY_POWER`

</td>
<td>



Turn on/off computer

</td>
<td>



SYSTEM POWER / COMPUTER POWER

</td>
</tr>
<tr>
<td>



`KEY_POWER2`

</td>
<td>



Turn on/off application

</td>
<td>



TV ON/OFF / POWER

</td>
</tr>
<tr>
<td>



`KEY_SLEEP`

</td>
<td>



Activate sleep timer

</td>
<td>



SLEEP / SLEEP TIMER

</td>
</tr>
<tr>
<td>



`KEY_SUSPEND`

</td>
<td>



Put computer into suspend mode

</td>
<td>



STANDBY / SUSPEND

</td>
</tr>
<tr>
<td colspan="3">



<strong>Window control</strong>

</td>
</tr>
<tr>
<td>



`KEY_CLEAR`

</td>
<td>



Stop stream and return to default input video/audio

</td>
<td>



CLEAR / RESET / BOSS KEY

</td>
</tr>
<tr>
<td>



`KEY_CYCLEWINDOWS`

</td>
<td>



Minimize windows and move to the next one

</td>
<td>



ALT-TAB / MINIMIZE / DESKTOP

</td>
</tr>
<tr>
<td>



`KEY_FAVORITES`

</td>
<td>



Open the favorites stream window

</td>
<td>



TV WALL / Favorites

</td>
</tr>
<tr>
<td>



`KEY_MENU`

</td>
<td>



Call application menu

</td>
<td>



2ND CONTROLS (USA: MENU) / DVD/MENU / SHOW/HIDE CTRL

</td>
</tr>
<tr>
<td>



`KEY_NEW`

</td>
<td>



Open/Close Picture in Picture

</td>
<td>



PIP

</td>
</tr>
<tr>
<td>



`KEY_OK`

</td>
<td>



Send a confirmation code to application

</td>
<td>



OK / ENTER / RETURN

</td>
</tr>
<tr>
<td>



`KEY_ASPECT_RATIO`

</td>
<td>



Select screen aspect ratio

</td>
<td>



4:3 16:9 SELECT

</td>
</tr>
<tr>
<td>



`KEY_FULL_SCREEN`

</td>
<td>



Put device into zoom/full screen mode

</td>
<td>



ZOOM / FULL SCREEN / ZOOM+ / HIDE PANEL / SWITCH

</td>
</tr>
<tr>
<td colspan="3">



<strong>Navigation keys</strong>

</td>
</tr>
<tr>
<td>



`KEY_ESC`

</td>
<td>



Cancel current operation

</td>
<td>



CANCEL / BACK

</td>
</tr>
<tr>
<td>



`KEY_HELP`

</td>
<td>



Open a Help window

</td>
<td>



HELP

</td>
</tr>
<tr>
<td>



`KEY_HOMEPAGE`

</td>
<td>



Navigate to Homepage

</td>
<td>



HOME

</td>
</tr>
<tr>
<td>



`KEY_INFO`

</td>
<td>



Open On Screen Display

</td>
<td>



DISPLAY INFORMATION / OSD

</td>
</tr>
<tr>
<td>



`KEY_WWW`

</td>
<td>



Open the default browser

</td>
<td>



WEB

</td>
</tr>
<tr>
<td>



`KEY_UP`

</td>
<td>



Up key

</td>
<td>



UP

</td>
</tr>
<tr>
<td>



`KEY_DOWN`

</td>
<td>



Down key

</td>
<td>



DOWN

</td>
</tr>
<tr>
<td>



`KEY_LEFT`

</td>
<td>



Left key

</td>
<td>



LEFT

</td>
</tr>
<tr>
<td>



`KEY_RIGHT`

</td>
<td>



Right key

</td>
<td>



RIGHT

</td>
</tr>
<tr>
<td colspan="3">



<strong>Miscellaneous keys</strong>

</td>
</tr>
<tr>
<td>



`KEY_DOT`

</td>
<td>



Return a dot

</td>
<td>



.

</td>
</tr>
<tr>
<td>



`KEY_FN`

</td>
<td>



Select a function

</td>
<td>



FUNCTION

</td>
</tr>
</tbody>
</table>

It should be noted that, sometimes, there some fundamental missing keys at some cheaper IR's. Due to that, it is recommended to:

<a id="rst-rc-keymap-notes"></a>


<table>
<caption>

Notes

</caption>
<tbody>
<tr>
<td>



On simpler IR's, without separate channel keys, you need to map UP as `KEY_CHANNELUP`

</td>
</tr>
<tr>
<td>



On simpler IR's, without separate channel keys, you need to map DOWN as `KEY_CHANNELDOWN`

</td>
</tr>
<tr>
<td>



On simpler IR's, without separate volume keys, you need to map LEFT as `KEY_VOLUMEDOWN`

</td>
</tr>
<tr>
<td>



On simpler IR's, without separate volume keys, you need to map RIGHT as `KEY_VOLUMEUP`

</td>
</tr>
</tbody>
</table>

---

# Part III - Remote Controller API

_Peios Kernel / Userspace interfaces / System and device interfaces / Remote control_

> Authors:

<a id="rst-part-iii-remote-controller-api"></a>
<a id="rst-remote-controllers"></a>

<!-- SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later -->

<!-- This data file has been placed in the public domain. -->

<!-- Derived from the Unicode character mappings available from
<http://www.w3.org/2003/entities/xml/>.
Processed by unicode2rstsubs.py, part of Docutils:
<https://docutils.sourceforge.io>. -->

**Table of Contents**

1. [Introduction](</kernel/userspace/userspace-api/media-rc/rc-intro.md>)
2. [Remote Controller's sysfs nodes](</kernel/userspace/userspace-api/media-rc/rc-sysfs-nodes.md>)
3. [Remote Controller Protocols and Scancodes](</kernel/userspace/userspace-api/media-rc/rc-protos.md>)
4. [Remote controller tables](<https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/userspace-api/media/rc/rc-tables.rst?id=9021cc14f7d98b4a1d2c932f52c5343d4d0f6b92>)
5. [Changing default Remote Controller mappings](</kernel/userspace/userspace-api/media-rc/rc-table-change.md>)
6. [LIRC Device Interface](</kernel/userspace/userspace-api/media-rc/lirc-dev.md>)

<a id="rst-revision-and-copyright"></a>

## Revision and Copyright

Authors:

- Carvalho Chehab, Mauro &lt;[mchehab@kernel.org](<mailto:mchehab@kernel.org>)&gt;

> - Initial version.

**Copyright** © 2009-2016 : Mauro Carvalho Chehab

<a id="rst-revision-history"></a>

## Revision History

**revision:** 3.15 / 2014-02-06 (*mcc*)

Added the interface description and the RC sysfs class description.

**revision:** 1.0 / 2009-09-06 (*mcc*)

Initial revision
