Name

CEC_RECEIVE, CEC_TRANSMIT — Receive or transmit a CEC message

Synopsis

int ioctl(int fd,
 int request,
 struct cec_msg *argp);
 

Arguments

fd

File descriptor returned by open().

request

CEC_RECEIVE, CEC_TRANSMIT

argp

Description

Note: this documents the proposed CEC API. This API is not yet finalized and is currently only available as a staging kernel module.

To receive a CEC message the application has to fill in the cec_msg structure and pass it to the CEC_RECEIVE ioctl. CEC_RECEIVE is only available if CEC_CAP_RECEIVE is set. 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.

To send a CEC message the application has to fill in the cec_msg structure and pass it to the CEC_TRANSMIT 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.

Table M.16. struct cec_msg

__u64tsTimestamp of when the message was transmitted in ns in the case of CEC_TRANSMIT with reply set to 0, or the timestamp of the received message in all other cases.
__u32lenThe length of the message. For CEC_TRANSMIT this is filled in by the application. The driver will fill this in for CEC_RECEIVE and for CEC_TRANSMIT it will be filled in with the length of the reply message if reply was set.
__u32timeoutThe 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 CEC_RECEIVE. If it is 0 and it is called by CEC_TRANSMIT, then it will be replaced by 1000 if the reply is non-zero or ignored if reply is 0.
__u32sequenceThe sequence number is automatically assigned by the CEC framework for all transmitted messages. It can be later used by the framework to generate an event if a reply for a message was requested and the message was transmitted in a non-blocking mode.
__u32flagsFlags. No flags are defined yet, so set this to 0.
__u8rx_statusThe status bits of the received message. See Table M.18, “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.
__u8tx_statusThe status bits of the transmitted message. See Table M.17, “CEC Transmit Status” for the possible status values. It is 0 if this messages was received, not transmitted.
__u8msg[16]The message payload. For CEC_TRANSMIT this is filled in by the application. The driver will fill this in for CEC_RECEIVE and for CEC_TRANSMIT it will be filled in with the payload of the reply message if reply was set.
__u8replyWait 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. If there was an error as indicated by a non-zero tx_status field, then reply and timeout are both set to 0 by the driver. Ignored by 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 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.
__u8tx_arb_lost_cntA 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.
__u8tx_nack_cntA 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.
__u8tx_low_drive_cntA 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.
__u8tx_error_cntA 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.

Table M.17. CEC Transmit Status

CEC_TX_STATUS_OK0x01The 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_LOST0x02CEC line arbitration was lost.
CEC_TX_STATUS_NACK0x04Message was not acknowledged.
CEC_TX_STATUS_LOW_DRIVE0x08Low 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_ERROR0x10Some 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_RETRIES0x20The 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.

Table M.18. CEC Receive Status

CEC_RX_STATUS_OK0x01The message was received successfully.
CEC_RX_STATUS_TIMEOUT0x02The reply to an earlier transmitted message timed out.
CEC_RX_STATUS_FEATURE_ABORT0x04The 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.

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.