1 .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
7 ***********************************
8 ioctls CEC_RECEIVE and CEC_TRANSMIT
9 ***********************************
14 CEC_RECEIVE, CEC_TRANSMIT - Receive or transmit a CEC message
19 .. c:macro:: CEC_RECEIVE
21 ``int ioctl(int fd, CEC_RECEIVE, struct cec_msg *argp)``
23 .. c:macro:: CEC_TRANSMIT
25 ``int ioctl(int fd, CEC_TRANSMIT, struct cec_msg *argp)``
31 File descriptor returned by :c:func:`open()`.
34 Pointer to struct cec_msg.
39 To receive a CEC message the application has to fill in the
40 ``timeout`` field of struct :c:type:`cec_msg` and pass it to
41 :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
42 If the file descriptor is in non-blocking mode and there are no received
43 messages pending, then it will return -1 and set errno to the ``EAGAIN``
44 error code. If the file descriptor is in blocking mode and ``timeout``
45 is non-zero and no message arrived within ``timeout`` milliseconds, then
46 it will return -1 and set errno to the ``ETIMEDOUT`` error code.
48 A received message can be:
50 1. a message received from another CEC device (the ``sequence`` field will
51 be 0, ``tx_status`` will be 0 and ``rx_status`` will be non-zero).
52 2. the transmit result of an earlier non-blocking transmit (the ``sequence``
53 field will be non-zero, ``tx_status`` will be non-zero and ``rx_status``
55 3. the reply to an earlier non-blocking transmit (the ``sequence`` field will
56 be non-zero, ``tx_status`` will be 0 and ``rx_status`` will be non-zero).
58 To send a CEC message the application has to fill in the struct
59 :c:type:`cec_msg` and pass it to :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`.
60 The :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` is only available if
61 ``CEC_CAP_TRANSMIT`` is set. If there is no more room in the transmit
62 queue, then it will return -1 and set errno to the ``EBUSY`` error code.
63 The transmit queue has enough room for 18 messages (about 1 second worth
64 of 2-byte messages). Note that the CEC kernel framework will also reply
65 to core messages (see :ref:`cec-core-processing`), so it is not a good
66 idea to fully fill up the transmit queue.
68 If the file descriptor is in non-blocking mode then the transmit will
69 return 0 and the result of the transmit will be available via
70 :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>` once the transmit has finished.
71 If a non-blocking transmit also specified waiting for a reply, then
72 the reply will arrive in a later message. The ``sequence`` field can
73 be used to associate both transmit results and replies with the original
76 Normally calling :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` when the physical
77 address is invalid (due to e.g. a disconnect) will return ``ENONET``.
79 However, the CEC specification allows sending messages from 'Unregistered' to
80 'TV' when the physical address is invalid since some TVs pull the hotplug detect
81 pin of the HDMI connector low when they go into standby, or when switching to
84 When the hotplug detect pin goes low the EDID disappears, and thus the
85 physical address, but the cable is still connected and CEC still works.
86 In order to detect/wake up the device it is allowed to send poll and 'Image/Text
87 View On' messages from initiator 0xf ('Unregistered') to destination 0 ('TV').
89 .. tabularcolumns:: |p{1.0cm}|p{3.5cm}|p{12.8cm}|
93 .. cssclass:: longtable
95 .. flat-table:: struct cec_msg
102 - Timestamp in ns of when the last byte of the message was transmitted.
103 The timestamp has been taken from the ``CLOCK_MONOTONIC`` clock. To access
104 the same clock from userspace use :c:func:`clock_gettime`.
107 - Timestamp in ns of when the last byte of the message was received.
108 The timestamp has been taken from the ``CLOCK_MONOTONIC`` clock. To access
109 the same clock from userspace use :c:func:`clock_gettime`.
112 - The length of the message. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` this is filled in
113 by the application. The driver will fill this in for
114 :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` it will be
115 filled in by the driver with the length of the reply message if ``reply`` was set.
118 - The timeout in milliseconds. This is the time the device will wait
119 for a message to be received before timing out. If it is set to 0,
120 then it will wait indefinitely when it is called by :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
121 If it is 0 and it is called by :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`,
122 then it will be replaced by 1000 if the ``reply`` is non-zero or
123 ignored if ``reply`` is 0.
126 - A non-zero sequence number is automatically assigned by the CEC framework
127 for all transmitted messages. It is used by the CEC framework when it queues
128 the transmit result for a non-blocking transmit. This allows the application
129 to associate the received message with the original transmit.
131 In addition, if a non-blocking transmit will wait for a reply (ii.e. ``timeout``
132 was not 0), then the ``sequence`` field of the reply will be set to the sequence
133 value of the original transmit. This allows the application to associate the
134 received message with the original transmit.
137 - Flags. See :ref:`cec-msg-flags` for a list of available flags.
140 - The message payload. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` this is filled in by the
141 application. The driver will fill this in for :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
142 For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` it will be filled in by the driver with
143 the payload of the reply message if ``timeout`` was set.
146 - Wait until this message is replied. If ``reply`` is 0 and the
147 ``timeout`` is 0, then don't wait for a reply but return after
148 transmitting the message. Ignored by :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
149 The case where ``reply`` is 0 (this is the opcode for the Feature Abort
150 message) and ``timeout`` is non-zero is specifically allowed to make it
151 possible to send a message and wait up to ``timeout`` milliseconds for a
152 Feature Abort reply. In this case ``rx_status`` will either be set
153 to :ref:`CEC_RX_STATUS_TIMEOUT <CEC-RX-STATUS-TIMEOUT>` or
154 :ref:`CEC_RX_STATUS_FEATURE_ABORT <CEC-RX-STATUS-FEATURE-ABORT>`.
156 If the transmitter message is ``CEC_MSG_INITIATE_ARC`` then the ``reply``
157 values ``CEC_MSG_REPORT_ARC_INITIATED`` and ``CEC_MSG_REPORT_ARC_TERMINATED``
158 are processed differently: either value will match both possible replies.
159 The reason is that the ``CEC_MSG_INITIATE_ARC`` message is the only CEC
160 message that has two possible replies other than Feature Abort. The
161 ``reply`` field will be updated with the actual reply so that it is
162 synchronized with the contents of the received message.
165 - The status bits of the received message. See
166 :ref:`cec-rx-status` for the possible status values.
169 - The status bits of the transmitted message. See
170 :ref:`cec-tx-status` for the possible status values.
171 When calling :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` in non-blocking mode,
172 this field will be 0 if the transmit started, or non-0 if the transmit
173 result is known immediately. The latter would be the case when attempting
174 to transmit a Poll message to yourself. That results in a
175 :ref:`CEC_TX_STATUS_NACK <CEC-TX-STATUS-NACK>` without ever actually
176 transmitting the Poll message.
178 - ``tx_arb_lost_cnt``
179 - A counter of the number of transmit attempts that resulted in the
180 Arbitration Lost error. This is only set if the hardware supports
181 this, otherwise it is always 0. This counter is only valid if the
182 :ref:`CEC_TX_STATUS_ARB_LOST <CEC-TX-STATUS-ARB-LOST>` status bit is set.
185 - A counter of the number of transmit attempts that resulted in the
186 Not Acknowledged error. This is only set if the hardware supports
187 this, otherwise it is always 0. This counter is only valid if the
188 :ref:`CEC_TX_STATUS_NACK <CEC-TX-STATUS-NACK>` status bit is set.
190 - ``tx_low_drive_cnt``
191 - A counter of the number of transmit attempts that resulted in the
192 Arbitration Lost error. This is only set if the hardware supports
193 this, otherwise it is always 0. This counter is only valid if the
194 :ref:`CEC_TX_STATUS_LOW_DRIVE <CEC-TX-STATUS-LOW-DRIVE>` status bit is set.
197 - A counter of the number of transmit errors other than Arbitration
198 Lost or Not Acknowledged. This is only set if the hardware
199 supports this, otherwise it is always 0. This counter is only
200 valid if the :ref:`CEC_TX_STATUS_ERROR <CEC-TX-STATUS-ERROR>` status bit is set.
202 .. tabularcolumns:: |p{6.2cm}|p{1.0cm}|p{10.1cm}|
206 .. flat-table:: Flags for struct cec_msg
211 * .. _`CEC-MSG-FL-REPLY-TO-FOLLOWERS`:
213 - ``CEC_MSG_FL_REPLY_TO_FOLLOWERS``
215 - If a CEC transmit expects a reply, then by default that reply is only sent to
216 the filehandle that called :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`. If this
217 flag is set, then the reply is also sent to all followers, if any. If the
218 filehandle that called :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` is also a
219 follower, then that filehandle will receive the reply twice: once as the
220 result of the :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`, and once via
221 :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
223 * .. _`CEC-MSG-FL-RAW`:
227 - Normally CEC messages are validated before transmitting them. If this
228 flag is set when :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` is called,
229 then no validation takes place and the message is transmitted as-is.
230 This is useful when debugging CEC issues.
231 This flag is only allowed if the process has the ``CAP_SYS_RAWIO``
232 capability. If that is not set, then the ``EPERM`` error code is
235 .. tabularcolumns:: |p{5.6cm}|p{0.9cm}|p{10.8cm}|
239 .. flat-table:: CEC Transmit Status
244 * .. _`CEC-TX-STATUS-OK`:
246 - ``CEC_TX_STATUS_OK``
248 - The message was transmitted successfully. This is mutually
249 exclusive with :ref:`CEC_TX_STATUS_MAX_RETRIES <CEC-TX-STATUS-MAX-RETRIES>`.
250 Other bits can still be set if earlier attempts met with failure before
251 the transmit was eventually successful.
252 * .. _`CEC-TX-STATUS-ARB-LOST`:
254 - ``CEC_TX_STATUS_ARB_LOST``
256 - CEC line arbitration was lost, i.e. another transmit started at the
257 same time with a higher priority. Optional status, not all hardware
258 can detect this error condition.
259 * .. _`CEC-TX-STATUS-NACK`:
261 - ``CEC_TX_STATUS_NACK``
263 - Message was not acknowledged. Note that some hardware cannot tell apart
264 a 'Not Acknowledged' status from other error conditions, i.e. the result
265 of a transmit is just OK or FAIL. In that case this status will be
266 returned when the transmit failed.
267 * .. _`CEC-TX-STATUS-LOW-DRIVE`:
269 - ``CEC_TX_STATUS_LOW_DRIVE``
271 - Low drive was detected on the CEC bus. This indicates that a
272 follower detected an error on the bus and requests a
273 retransmission. Optional status, not all hardware can detect this
275 * .. _`CEC-TX-STATUS-ERROR`:
277 - ``CEC_TX_STATUS_ERROR``
279 - Some error occurred. This is used for any errors that do not fit
280 ``CEC_TX_STATUS_ARB_LOST`` or ``CEC_TX_STATUS_LOW_DRIVE``, either because
281 the hardware could not tell which error occurred, or because the hardware
282 tested for other conditions besides those two. Optional status.
283 * .. _`CEC-TX-STATUS-MAX-RETRIES`:
285 - ``CEC_TX_STATUS_MAX_RETRIES``
287 - The transmit failed after one or more retries. This status bit is
288 mutually exclusive with :ref:`CEC_TX_STATUS_OK <CEC-TX-STATUS-OK>`.
289 Other bits can still be set to explain which failures were seen.
290 * .. _`CEC-TX-STATUS-ABORTED`:
292 - ``CEC_TX_STATUS_ABORTED``
294 - The transmit was aborted due to an HDMI disconnect, or the adapter
295 was unconfigured, or a transmit was interrupted, or the driver
296 returned an error when attempting to start a transmit.
297 * .. _`CEC-TX-STATUS-TIMEOUT`:
299 - ``CEC_TX_STATUS_TIMEOUT``
301 - The transmit timed out. This should not normally happen and this
302 indicates a driver problem.
304 .. tabularcolumns:: |p{5.6cm}|p{0.9cm}|p{10.8cm}|
308 .. flat-table:: CEC Receive Status
313 * .. _`CEC-RX-STATUS-OK`:
315 - ``CEC_RX_STATUS_OK``
317 - The message was received successfully.
318 * .. _`CEC-RX-STATUS-TIMEOUT`:
320 - ``CEC_RX_STATUS_TIMEOUT``
322 - The reply to an earlier transmitted message timed out.
323 * .. _`CEC-RX-STATUS-FEATURE-ABORT`:
325 - ``CEC_RX_STATUS_FEATURE_ABORT``
327 - The message was received successfully but the reply was
328 ``CEC_MSG_FEATURE_ABORT``. This status is only set if this message
329 was the reply to an earlier transmitted message.
330 * .. _`CEC-RX-STATUS-ABORTED`:
332 - ``CEC_RX_STATUS_ABORTED``
334 - The wait for a reply to an earlier transmitted message was aborted
335 because the HDMI cable was disconnected, the adapter was unconfigured
336 or the :ref:`CEC_TRANSMIT <CEC_RECEIVE>` that waited for a
337 reply was interrupted.
343 On success 0 is returned, on error -1 and the ``errno`` variable is set
344 appropriately. The generic error codes are described at the
345 :ref:`Generic Error Codes <gen-errors>` chapter.
347 The :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>` can return the following
351 No messages are in the receive queue, and the filehandle is in non-blocking mode.
354 The ``timeout`` was reached while waiting for a message.
357 The wait for a message was interrupted (e.g. by Ctrl-C).
359 The :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` can return the following
363 The ``CEC_CAP_TRANSMIT`` capability wasn't set, so this ioctl is not supported.
366 The CEC adapter is not configured, i.e. :ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`
367 has never been called, or ``CEC_MSG_FL_RAW`` was used from a process that
368 did not have the ``CAP_SYS_RAWIO`` capability.
371 The CEC adapter is not configured, i.e. :ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`
372 was called, but the physical address is invalid so no logical address was claimed.
373 An exception is made in this case for transmits from initiator 0xf ('Unregistered')
374 to destination 0 ('TV'). In that case the transmit will proceed as usual.
377 Another filehandle is in exclusive follower or initiator mode, or the filehandle
378 is in mode ``CEC_MODE_NO_INITIATOR``. This is also returned if the transmit
382 The contents of struct :c:type:`cec_msg` is invalid.
385 The wait for a successful transmit was interrupted (e.g. by Ctrl-C).