10. ioctls CEC_RECEIVE and CEC_TRANSMIT

10.1. Name

CEC_RECEIVE, CEC_TRANSMIT - Receive or transmit a CEC message

10.2. Synopsis

int ioctl(int fd, CEC_RECEIVE, struct cec_msg *argp)
int ioctl(int fd, CEC_TRANSMIT, struct cec_msg *argp)

10.3. Arguments

fd
File descriptor returned by open().
argp
Pointer to struct cec_msg.

10.4. Description

To receive a CEC message the application has to fill in the timeout field of struct cec_msg and pass it to ioctl CEC_RECEIVE. If the file descriptor is in non-blocking mode and there are no received messages pending, then it will return -1 and set errno to the EAGAIN error code. If the file descriptor is in blocking mode and timeout is non-zero and no message arrived within timeout milliseconds, then it will return -1 and set errno to the ETIMEDOUT error code.

A received message can be:

  1. a message received from another CEC device (the sequence field will be 0).
  2. the result of an earlier non-blocking transmit (the sequence field will be non-zero).

To send a CEC message the application has to fill in the struct :c:type:` cec_msg` and pass it to ioctl CEC_TRANSMIT. The ioctl CEC_TRANSMIT is only available if CEC_CAP_TRANSMIT is set. If there is no more room in the transmit queue, then it will return -1 and set errno to the EBUSY error code. The transmit queue has enough room for 18 messages (about 1 second worth of 2-byte messages). Note that the CEC kernel framework will also reply to core messages (see :ref:cec-core-processing), so it is not a good idea to fully fill up the transmit queue.

If the file descriptor is in non-blocking mode then the transmit will return 0 and the result of the transmit will be available via ioctl CEC_RECEIVE once the transmit has finished (including waiting for a reply, if requested).

The sequence field is filled in for every transmit and this can be checked against the received messages to find the corresponding transmit result.

cec_msg
struct cec_msg
__u64 tx_ts Timestamp in ns of when the last byte of the message was transmitted. The timestamp has been taken from the CLOCK_MONOTONIC clock. To access the same clock from userspace use clock_gettime().
__u64 rx_ts Timestamp in ns of when the last byte of the message was received. The timestamp has been taken from the CLOCK_MONOTONIC clock. To access the same clock from userspace use clock_gettime().
__u32 len The length of the message. For ioctl CEC_TRANSMIT this is filled in by the application. The driver will fill this in for ioctl CEC_RECEIVE. For ioctl CEC_TRANSMIT it will be filled in by the driver with the length of the reply message if reply was set.
__u32 timeout The timeout in milliseconds. This is the time the device will wait for a message to be received before timing out. If it is set to 0, then it will wait indefinitely when it is called by ioctl CEC_RECEIVE. If it is 0 and it is called by ioctl CEC_TRANSMIT, then it will be replaced by 1000 if the reply is non-zero or ignored if reply is 0.
__u32 sequence A non-zero sequence number is automatically assigned by the CEC framework for all transmitted messages. It is used by the CEC framework when it queues the transmit result (when transmit was called in non-blocking mode). This allows the application to associate the received message with the original transmit.
__u32 flags Flags. See Flags for struct cec_msg for a list of available flags.
__u8 tx_status The status bits of the transmitted message. See CEC Transmit Status for the possible status values. It is 0 if this messages was received, not transmitted.
__u8 msg[16] The message payload. For ioctl CEC_TRANSMIT this is filled in by the application. The driver will fill this in for ioctl CEC_RECEIVE. For ioctl CEC_TRANSMIT it will be filled in by the driver with the payload of the reply message if timeout was set.
__u8 reply

Wait until this message is replied. If reply is 0 and the timeout is 0, then don’t wait for a reply but return after transmitting the message. Ignored by ioctl CEC_RECEIVE. The case where reply is 0 (this is the opcode for the Feature Abort message) and timeout is non-zero is specifically allowed to make it possible to send a message and wait up to timeout milliseconds for a Feature Abort reply. In this case rx_status will either be set to CEC_RX_STATUS_TIMEOUT or CEC_RX_STATUS_FEATURE_ABORT.

If the transmitter message is CEC_MSG_INITIATE_ARC then the reply values CEC_MSG_REPORT_ARC_INITIATED and CEC_MSG_REPORT_ARC_TERMINATED are processed differently: either value will match both possible replies. The reason is that the CEC_MSG_INITIATE_ARC message is the only CEC message that has two possible replies other than Feature Abort. The reply field will be updated with the actual reply so that it is synchronized with the contents of the received message.

__u8 rx_status The status bits of the received message. See CEC Receive Status for the possible status values. It is 0 if this message was transmitted, not received, unless this is the reply to a transmitted message. In that case both rx_status and tx_status are set.
__u8 tx_status The status bits of the transmitted message. See CEC Transmit Status for the possible status values. It is 0 if this messages was received, not transmitted.
__u8 tx_arb_lost_cnt A counter of the number of transmit attempts that resulted in the Arbitration Lost error. This is only set if the hardware supports this, otherwise it is always 0. This counter is only valid if the CEC_TX_STATUS_ARB_LOST status bit is set.
__u8 tx_nack_cnt A counter of the number of transmit attempts that resulted in the Not Acknowledged error. This is only set if the hardware supports this, otherwise it is always 0. This counter is only valid if the CEC_TX_STATUS_NACK status bit is set.
__u8 tx_low_drive_cnt A counter of the number of transmit attempts that resulted in the Arbitration Lost error. This is only set if the hardware supports this, otherwise it is always 0. This counter is only valid if the CEC_TX_STATUS_LOW_DRIVE status bit is set.
__u8 tx_error_cnt A counter of the number of transmit errors other than Arbitration Lost or Not Acknowledged. This is only set if the hardware supports this, otherwise it is always 0. This counter is only valid if the CEC_TX_STATUS_ERROR status bit is set.
Flags for struct cec_msg
CEC_MSG_FL_REPLY_TO_FOLLOWERS 1

If a CEC transmit expects a reply, then by default that reply is only sent to the filehandle that called ioctl CEC_TRANSMIT. If this flag is set, then the reply is also sent to all followers, if any. If the filehandle that called ioctl CEC_TRANSMIT is also a follower, then that filehandle will receive the reply twice: once as the result of the ioctl CEC_TRANSMIT, and once via ioctl CEC_RECEIVE.

CEC Transmit Status
CEC_TX_STATUS_OK 0x01

The message was transmitted successfully. This is mutually exclusive with CEC_TX_STATUS_MAX_RETRIES. Other bits can still be set if earlier attempts met with failure before the transmit was eventually successful.

CEC_TX_STATUS_ARB_LOST 0x02

CEC line arbitration was lost.

CEC_TX_STATUS_NACK 0x04

Message was not acknowledged.

CEC_TX_STATUS_LOW_DRIVE 0x08

Low drive was detected on the CEC bus. This indicates that a follower detected an error on the bus and requests a retransmission.

CEC_TX_STATUS_ERROR 0x10

Some error occurred. This is used for any errors that do not fit the previous two, either because the hardware could not tell which error occurred, or because the hardware tested for other conditions besides those two.

CEC_TX_STATUS_MAX_RETRIES 0x20

The transmit failed after one or more retries. This status bit is mutually exclusive with CEC_TX_STATUS_OK. Other bits can still be set to explain which failures were seen.

CEC Receive Status
CEC_RX_STATUS_OK 0x01

The message was received successfully.

CEC_RX_STATUS_TIMEOUT 0x02

The reply to an earlier transmitted message timed out.

CEC_RX_STATUS_FEATURE_ABORT 0x04

The message was received successfully but the reply was CEC_MSG_FEATURE_ABORT. This status is only set if this message was the reply to an earlier transmitted message.

10.5. 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 chapter.

Table Of Contents

Previous topic

9. ioctls CEC_G_MODE and CEC_S_MODE

Next topic

3. CEC Header File

This Page