1 .. Permission is granted to copy, distribute and/or modify this
2 .. document under the terms of the GNU Free Documentation License,
3 .. Version 1.1 or any later version published by the Free Software
4 .. Foundation, with no Invariant Sections, no Front-Cover Texts
5 .. and no Back-Cover Texts. A copy of the license is included at
6 .. Documentation/media/uapi/fdl-appendix.rst.
8 .. TODO: replace it to GFDL-1.1-or-later WITH no-invariant-sections
13 ***********************************
14 ioctls CEC_RECEIVE and CEC_TRANSMIT
15 ***********************************
20 CEC_RECEIVE, CEC_TRANSMIT - Receive or transmit a CEC message
26 .. c:function:: int ioctl( int fd, CEC_RECEIVE, struct cec_msg \*argp )
29 .. c:function:: int ioctl( int fd, CEC_TRANSMIT, struct cec_msg \*argp )
36 File descriptor returned by :c:func:`open() <cec-open>`.
39 Pointer to struct cec_msg.
44 To receive a CEC message the application has to fill in the
45 ``timeout`` field of struct :c:type:`cec_msg` and pass it to
46 :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
47 If the file descriptor is in non-blocking mode and there are no received
48 messages pending, then it will return -1 and set errno to the ``EAGAIN``
49 error code. If the file descriptor is in blocking mode and ``timeout``
50 is non-zero and no message arrived within ``timeout`` milliseconds, then
51 it will return -1 and set errno to the ``ETIMEDOUT`` error code.
53 A received message can be:
55 1. a message received from another CEC device (the ``sequence`` field will
57 2. the result of an earlier non-blocking transmit (the ``sequence`` field will
60 To send a CEC message the application has to fill in the struct
61 :c:type:`cec_msg` and pass it to :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`.
62 The :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` is only available if
63 ``CEC_CAP_TRANSMIT`` is set. If there is no more room in the transmit
64 queue, then it will return -1 and set errno to the ``EBUSY`` error code.
65 The transmit queue has enough room for 18 messages (about 1 second worth
66 of 2-byte messages). Note that the CEC kernel framework will also reply
67 to core messages (see :ref:`cec-core-processing`), so it is not a good
68 idea to fully fill up the transmit queue.
70 If the file descriptor is in non-blocking mode then the transmit will
71 return 0 and the result of the transmit will be available via
72 :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>` once the transmit has finished
73 (including waiting for a reply, if requested).
75 The ``sequence`` field is filled in for every transmit and this can be
76 checked against the received messages to find the corresponding transmit
79 Normally calling :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` when the physical
80 address is invalid (due to e.g. a disconnect) will return ``ENONET``.
82 However, the CEC specification allows sending messages from 'Unregistered' to
83 'TV' when the physical address is invalid since some TVs pull the hotplug detect
84 pin of the HDMI connector low when they go into standby, or when switching to
87 When the hotplug detect pin goes low the EDID disappears, and thus the
88 physical address, but the cable is still connected and CEC still works.
89 In order to detect/wake up the device it is allowed to send poll and 'Image/Text
90 View On' messages from initiator 0xf ('Unregistered') to destination 0 ('TV').
92 .. tabularcolumns:: |p{1.0cm}|p{3.5cm}|p{13.0cm}|
96 .. cssclass:: longtable
98 .. flat-table:: struct cec_msg
105 - Timestamp in ns of when the last byte of the message was transmitted.
106 The timestamp has been taken from the ``CLOCK_MONOTONIC`` clock. To access
107 the same clock from userspace use :c:func:`clock_gettime`.
110 - Timestamp in ns of when the last byte of the message was received.
111 The timestamp has been taken from the ``CLOCK_MONOTONIC`` clock. To access
112 the same clock from userspace use :c:func:`clock_gettime`.
115 - The length of the message. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` this is filled in
116 by the application. The driver will fill this in for
117 :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` it will be
118 filled in by the driver with the length of the reply message if ``reply`` was set.
121 - The timeout in milliseconds. This is the time the device will wait
122 for a message to be received before timing out. If it is set to 0,
123 then it will wait indefinitely when it is called by :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
124 If it is 0 and it is called by :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`,
125 then it will be replaced by 1000 if the ``reply`` is non-zero or
126 ignored if ``reply`` is 0.
129 - A non-zero sequence number is automatically assigned by the CEC framework
130 for all transmitted messages. It is used by the CEC framework when it queues
131 the transmit result (when transmit was called in non-blocking mode). This
132 allows the application to associate the received message with the original
136 - Flags. See :ref:`cec-msg-flags` for a list of available flags.
139 - The status bits of the transmitted message. See
140 :ref:`cec-tx-status` for the possible status values. It is 0 if
141 this message was received, not transmitted.
144 - The message payload. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` this is filled in by the
145 application. The driver will fill this in for :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
146 For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` it will be filled in by the driver with
147 the payload of the reply message if ``timeout`` was set.
150 - Wait until this message is replied. If ``reply`` is 0 and the
151 ``timeout`` is 0, then don't wait for a reply but return after
152 transmitting the message. Ignored by :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
153 The case where ``reply`` is 0 (this is the opcode for the Feature Abort
154 message) and ``timeout`` is non-zero is specifically allowed to make it
155 possible to send a message and wait up to ``timeout`` milliseconds for a
156 Feature Abort reply. In this case ``rx_status`` will either be set
157 to :ref:`CEC_RX_STATUS_TIMEOUT <CEC-RX-STATUS-TIMEOUT>` or
158 :ref:`CEC_RX_STATUS_FEATURE_ABORT <CEC-RX-STATUS-FEATURE-ABORT>`.
160 If the transmitter message is ``CEC_MSG_INITIATE_ARC`` then the ``reply``
161 values ``CEC_MSG_REPORT_ARC_INITIATED`` and ``CEC_MSG_REPORT_ARC_TERMINATED``
162 are processed differently: either value will match both possible replies.
163 The reason is that the ``CEC_MSG_INITIATE_ARC`` message is the only CEC
164 message that has two possible replies other than Feature Abort. The
165 ``reply`` field will be updated with the actual reply so that it is
166 synchronized with the contents of the received message.
169 - The status bits of the received message. See
170 :ref:`cec-rx-status` for the possible status values. It is 0 if
171 this message was transmitted, not received, unless this is the
172 reply to a transmitted message. In that case both ``rx_status``
173 and ``tx_status`` are set.
176 - The status bits of the transmitted message. See
177 :ref:`cec-tx-status` for the possible status values. It is 0 if
178 this message was received, not transmitted.
180 - ``tx_arb_lost_cnt``
181 - A counter of the number of transmit attempts that resulted in the
182 Arbitration Lost error. This is only set if the hardware supports
183 this, otherwise it is always 0. This counter is only valid if the
184 :ref:`CEC_TX_STATUS_ARB_LOST <CEC-TX-STATUS-ARB-LOST>` status bit is set.
187 - A counter of the number of transmit attempts that resulted in the
188 Not Acknowledged error. This is only set if the hardware supports
189 this, otherwise it is always 0. This counter is only valid if the
190 :ref:`CEC_TX_STATUS_NACK <CEC-TX-STATUS-NACK>` status bit is set.
192 - ``tx_low_drive_cnt``
193 - A counter of the number of transmit attempts that resulted in the
194 Arbitration Lost error. This is only set if the hardware supports
195 this, otherwise it is always 0. This counter is only valid if the
196 :ref:`CEC_TX_STATUS_LOW_DRIVE <CEC-TX-STATUS-LOW-DRIVE>` status bit is set.
199 - A counter of the number of transmit errors other than Arbitration
200 Lost or Not Acknowledged. This is only set if the hardware
201 supports this, otherwise it is always 0. This counter is only
202 valid if the :ref:`CEC_TX_STATUS_ERROR <CEC-TX-STATUS-ERROR>` status bit is set.
205 .. tabularcolumns:: |p{6.2cm}|p{1.0cm}|p{10.3cm}|
209 .. flat-table:: Flags for struct cec_msg
214 * .. _`CEC-MSG-FL-REPLY-TO-FOLLOWERS`:
216 - ``CEC_MSG_FL_REPLY_TO_FOLLOWERS``
218 - If a CEC transmit expects a reply, then by default that reply is only sent to
219 the filehandle that called :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`. If this
220 flag is set, then the reply is also sent to all followers, if any. If the
221 filehandle that called :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` is also a
222 follower, then that filehandle will receive the reply twice: once as the
223 result of the :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`, and once via
224 :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
226 * .. _`CEC-MSG-FL-RAW`:
230 - Normally CEC messages are validated before transmitting them. If this
231 flag is set when :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` is called,
232 then no validation takes place and the message is transmitted as-is.
233 This is useful when debugging CEC issues.
234 This flag is only allowed if the process has the ``CAP_SYS_RAWIO``
235 capability. If that is not set, then the ``EPERM`` error code is
239 .. tabularcolumns:: |p{5.6cm}|p{0.9cm}|p{11.0cm}|
243 .. flat-table:: CEC Transmit Status
248 * .. _`CEC-TX-STATUS-OK`:
250 - ``CEC_TX_STATUS_OK``
252 - The message was transmitted successfully. This is mutually
253 exclusive with :ref:`CEC_TX_STATUS_MAX_RETRIES <CEC-TX-STATUS-MAX-RETRIES>`.
254 Other bits can still be set if earlier attempts met with failure before
255 the transmit was eventually successful.
256 * .. _`CEC-TX-STATUS-ARB-LOST`:
258 - ``CEC_TX_STATUS_ARB_LOST``
260 - CEC line arbitration was lost, i.e. another transmit started at the
261 same time with a higher priority. Optional status, not all hardware
262 can detect this error condition.
263 * .. _`CEC-TX-STATUS-NACK`:
265 - ``CEC_TX_STATUS_NACK``
267 - Message was not acknowledged. Note that some hardware cannot tell apart
268 a 'Not Acknowledged' status from other error conditions, i.e. the result
269 of a transmit is just OK or FAIL. In that case this status will be
270 returned when the transmit failed.
271 * .. _`CEC-TX-STATUS-LOW-DRIVE`:
273 - ``CEC_TX_STATUS_LOW_DRIVE``
275 - Low drive was detected on the CEC bus. This indicates that a
276 follower detected an error on the bus and requests a
277 retransmission. Optional status, not all hardware can detect this
279 * .. _`CEC-TX-STATUS-ERROR`:
281 - ``CEC_TX_STATUS_ERROR``
283 - Some error occurred. This is used for any errors that do not fit
284 ``CEC_TX_STATUS_ARB_LOST`` or ``CEC_TX_STATUS_LOW_DRIVE``, either because
285 the hardware could not tell which error occurred, or because the hardware
286 tested for other conditions besides those two. Optional status.
287 * .. _`CEC-TX-STATUS-MAX-RETRIES`:
289 - ``CEC_TX_STATUS_MAX_RETRIES``
291 - The transmit failed after one or more retries. This status bit is
292 mutually exclusive with :ref:`CEC_TX_STATUS_OK <CEC-TX-STATUS-OK>`.
293 Other bits can still be set to explain which failures were seen.
294 * .. _`CEC-TX-STATUS-ABORTED`:
296 - ``CEC_TX_STATUS_ABORTED``
298 - The transmit was aborted due to an HDMI disconnect, or the adapter
299 was unconfigured, or a transmit was interrupted, or the driver
300 returned an error when attempting to start a transmit.
301 * .. _`CEC-TX-STATUS-TIMEOUT`:
303 - ``CEC_TX_STATUS_TIMEOUT``
305 - The transmit timed out. This should not normally happen and this
306 indicates a driver problem.
309 .. tabularcolumns:: |p{5.6cm}|p{0.9cm}|p{11.0cm}|
313 .. flat-table:: CEC Receive Status
318 * .. _`CEC-RX-STATUS-OK`:
320 - ``CEC_RX_STATUS_OK``
322 - The message was received successfully.
323 * .. _`CEC-RX-STATUS-TIMEOUT`:
325 - ``CEC_RX_STATUS_TIMEOUT``
327 - The reply to an earlier transmitted message timed out.
328 * .. _`CEC-RX-STATUS-FEATURE-ABORT`:
330 - ``CEC_RX_STATUS_FEATURE_ABORT``
332 - The message was received successfully but the reply was
333 ``CEC_MSG_FEATURE_ABORT``. This status is only set if this message
334 was the reply to an earlier transmitted message.
335 * .. _`CEC-RX-STATUS-ABORTED`:
337 - ``CEC_RX_STATUS_ABORTED``
339 - The wait for a reply to an earlier transmitted message was aborted
340 because the HDMI cable was disconnected, the adapter was unconfigured
341 or the :ref:`CEC_TRANSMIT <CEC_RECEIVE>` that waited for a
342 reply was interrupted.
349 On success 0 is returned, on error -1 and the ``errno`` variable is set
350 appropriately. The generic error codes are described at the
351 :ref:`Generic Error Codes <gen-errors>` chapter.
353 The :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>` can return the following
357 No messages are in the receive queue, and the filehandle is in non-blocking mode.
360 The ``timeout`` was reached while waiting for a message.
363 The wait for a message was interrupted (e.g. by Ctrl-C).
365 The :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` can return the following
369 The ``CEC_CAP_TRANSMIT`` capability wasn't set, so this ioctl is not supported.
372 The CEC adapter is not configured, i.e. :ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`
373 has never been called, or ``CEC_MSG_FL_RAW`` was used from a process that
374 did not have the ``CAP_SYS_RAWIO`` capability.
377 The CEC adapter is not configured, i.e. :ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`
378 was called, but the physical address is invalid so no logical address was claimed.
379 An exception is made in this case for transmits from initiator 0xf ('Unregistered')
380 to destination 0 ('TV'). In that case the transmit will proceed as usual.
383 Another filehandle is in exclusive follower or initiator mode, or the filehandle
384 is in mode ``CEC_MODE_NO_INITIATOR``. This is also returned if the transmit
388 The contents of struct :c:type:`cec_msg` is invalid.
391 The wait for a successful transmit was interrupted (e.g. by Ctrl-C).