2.11. ioctls CEC_RECEIVE and CEC_TRANSMIT¶
2.11.1. Name¶
CEC_RECEIVE, CEC_TRANSMIT - Receive or transmit a CEC message
2.11.2. Synopsis¶
-
CEC_RECEIVE¶
int ioctl(int fd, CEC_RECEIVE, struct cec_msg *argp)
-
CEC_TRANSMIT¶
int ioctl(int fd, CEC_TRANSMIT, struct cec_msg *argp)
2.11.3. Arguments¶
fd
File descriptor returned by
open()
.argp
Pointer to
struct cec_msg
.
2.11.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:
a message received from another CEC device (the
sequence
field will be 0,tx_status
will be 0 andrx_status
will be non-zero).the transmit result of an earlier non-blocking transmit (the
sequence
field will be non-zero,tx_status
will be non-zero andrx_status
will be 0).the reply to an earlier non-blocking transmit (the
sequence
field will be non-zero,tx_status
will be 0 andrx_status
will be non-zero).
To send a CEC message the application has to fill in the struct
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 Core Message 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.
If a non-blocking transmit also specified waiting for a reply, then
the reply will arrive in a later message. The sequence
field can
be used to associate both transmit results and replies with the original
transmit.
Normally calling ioctl CEC_TRANSMIT when the physical
address is invalid (due to e.g. a disconnect) will return ENONET
.
However, the CEC specification allows sending messages from 'Unregistered' to 'TV' when the physical address is invalid since some TVs pull the hotplug detect pin of the HDMI connector low when they go into standby, or when switching to another input.
When the hotplug detect pin goes low the EDID disappears, and thus the physical address, but the cable is still connected and CEC still works. In order to detect/wake up the device it is allowed to send poll and 'Image/Text View On' messages from initiator 0xf ('Unregistered') to destination 0 ('TV').
-
type cec_msg¶
__u64 |
|
Timestamp in ns of when the last byte of the message was transmitted.
The timestamp has been taken from the |
__u64 |
|
Timestamp in ns of when the last byte of the message was received.
The timestamp has been taken from the |
__u32 |
|
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 |
__u32 |
|
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 |
__u32 |
|
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 for a non-blocking transmit. This allows the application to associate the received message with the original transmit. In addition, if a non-blocking transmit will wait for a reply (ii.e. |
__u32 |
|
Flags. See Flags for struct cec_msg for a list of available flags. |
__u8 |
|
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 |
__u8 |
|
Wait until this message is replied. If If the transmitter message is |
__u8 |
|
The status bits of the received message. See CEC Receive Status for the possible status values. |
__u8 |
|
The status bits of the transmitted message. See CEC Transmit Status for the possible status values. When calling ioctl CEC_TRANSMIT in non-blocking mode, this field will be 0 if the transmit started, or non-0 if the transmit result is known immediately. The latter would be the case when attempting to transmit a Poll message to yourself. That results in a CEC_TX_STATUS_NACK without ever actually transmitting the Poll message. |
__u8 |
|
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 |
|
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 |
|
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 |
|
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. |
|
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. |
|
2 |
Normally CEC messages are validated before transmitting them. If this
flag is set when ioctl CEC_TRANSMIT is called,
then no validation takes place and the message is transmitted as-is.
This is useful when debugging CEC issues.
This flag is only allowed if the process has the |
|
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. |
|
0x02 |
CEC line arbitration was lost, i.e. another transmit started at the same time with a higher priority. Optional status, not all hardware can detect this error condition. |
|
0x04 |
Message was not acknowledged. Note that some hardware cannot tell apart a 'Not Acknowledged' status from other error conditions, i.e. the result of a transmit is just OK or FAIL. In that case this status will be returned when the transmit failed. |
|
0x08 |
Low drive was detected on the CEC bus. This indicates that a follower detected an error on the bus and requests a retransmission. Optional status, not all hardware can detect this error condition. |
|
0x10 |
Some error occurred. This is used for any errors that do not fit
|
|
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. |
|
0x40 |
The transmit was aborted due to an HDMI disconnect, or the adapter was unconfigured, or a transmit was interrupted, or the driver returned an error when attempting to start a transmit. |
|
0x80 |
The transmit timed out. This should not normally happen and this indicates a driver problem. |
|
0x01 |
The message was received successfully. |
|
0x02 |
The reply to an earlier transmitted message timed out. |
|
0x04 |
The message was received successfully but the reply was
|
|
0x08 |
The wait for a reply to an earlier transmitted message was aborted because the HDMI cable was disconnected, the adapter was unconfigured or the CEC_TRANSMIT that waited for a reply was interrupted. |
2.11.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.
The ioctl CEC_RECEIVE can return the following error codes:
- EAGAIN
No messages are in the receive queue, and the filehandle is in non-blocking mode.
- ETIMEDOUT
The
timeout
was reached while waiting for a message.- ERESTARTSYS
The wait for a message was interrupted (e.g. by Ctrl-C).
The ioctl CEC_TRANSMIT can return the following error codes:
- ENOTTY
The
CEC_CAP_TRANSMIT
capability wasn't set, so this ioctl is not supported.- EPERM
The CEC adapter is not configured, i.e. ioctl CEC_ADAP_S_LOG_ADDRS has never been called, or
CEC_MSG_FL_RAW
was used from a process that did not have theCAP_SYS_RAWIO
capability.- ENONET
The CEC adapter is not configured, i.e. ioctl CEC_ADAP_S_LOG_ADDRS was called, but the physical address is invalid so no logical address was claimed. An exception is made in this case for transmits from initiator 0xf ('Unregistered') to destination 0 ('TV'). In that case the transmit will proceed as usual.
- EBUSY
Another filehandle is in exclusive follower or initiator mode, or the filehandle is in mode
CEC_MODE_NO_INITIATOR
. This is also returned if the transmit queue is full.- EINVAL
The contents of struct
cec_msg
is invalid.- ERESTARTSYS
The wait for a successful transmit was interrupted (e.g. by Ctrl-C).