0001 .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
0002 .. c:namespace:: CEC
0003
0004 .. _CEC_TRANSMIT:
0005 .. _CEC_RECEIVE:
0006
0007 ***********************************
0008 ioctls CEC_RECEIVE and CEC_TRANSMIT
0009 ***********************************
0010
0011 Name
0012 ====
0013
0014 CEC_RECEIVE, CEC_TRANSMIT - Receive or transmit a CEC message
0015
0016 Synopsis
0017 ========
0018
0019 .. c:macro:: CEC_RECEIVE
0020
0021 ``int ioctl(int fd, CEC_RECEIVE, struct cec_msg *argp)``
0022
0023 .. c:macro:: CEC_TRANSMIT
0024
0025 ``int ioctl(int fd, CEC_TRANSMIT, struct cec_msg *argp)``
0026
0027 Arguments
0028 =========
0029
0030 ``fd``
0031 File descriptor returned by :c:func:`open()`.
0032
0033 ``argp``
0034 Pointer to struct cec_msg.
0035
0036 Description
0037 ===========
0038
0039 To receive a CEC message the application has to fill in the
0040 ``timeout`` field of struct :c:type:`cec_msg` and pass it to
0041 :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
0042 If the file descriptor is in non-blocking mode and there are no received
0043 messages pending, then it will return -1 and set errno to the ``EAGAIN``
0044 error code. If the file descriptor is in blocking mode and ``timeout``
0045 is non-zero and no message arrived within ``timeout`` milliseconds, then
0046 it will return -1 and set errno to the ``ETIMEDOUT`` error code.
0047
0048 A received message can be:
0049
0050 1. a message received from another CEC device (the ``sequence`` field will
0051 be 0, ``tx_status`` will be 0 and ``rx_status`` will be non-zero).
0052 2. the transmit result of an earlier non-blocking transmit (the ``sequence``
0053 field will be non-zero, ``tx_status`` will be non-zero and ``rx_status``
0054 will be 0).
0055 3. the reply to an earlier non-blocking transmit (the ``sequence`` field will
0056 be non-zero, ``tx_status`` will be 0 and ``rx_status`` will be non-zero).
0057
0058 To send a CEC message the application has to fill in the struct
0059 :c:type:`cec_msg` and pass it to :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`.
0060 The :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` is only available if
0061 ``CEC_CAP_TRANSMIT`` is set. If there is no more room in the transmit
0062 queue, then it will return -1 and set errno to the ``EBUSY`` error code.
0063 The transmit queue has enough room for 18 messages (about 1 second worth
0064 of 2-byte messages). Note that the CEC kernel framework will also reply
0065 to core messages (see :ref:`cec-core-processing`), so it is not a good
0066 idea to fully fill up the transmit queue.
0067
0068 If the file descriptor is in non-blocking mode then the transmit will
0069 return 0 and the result of the transmit will be available via
0070 :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>` once the transmit has finished.
0071 If a non-blocking transmit also specified waiting for a reply, then
0072 the reply will arrive in a later message. The ``sequence`` field can
0073 be used to associate both transmit results and replies with the original
0074 transmit.
0075
0076 Normally calling :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` when the physical
0077 address is invalid (due to e.g. a disconnect) will return ``ENONET``.
0078
0079 However, the CEC specification allows sending messages from 'Unregistered' to
0080 'TV' when the physical address is invalid since some TVs pull the hotplug detect
0081 pin of the HDMI connector low when they go into standby, or when switching to
0082 another input.
0083
0084 When the hotplug detect pin goes low the EDID disappears, and thus the
0085 physical address, but the cable is still connected and CEC still works.
0086 In order to detect/wake up the device it is allowed to send poll and 'Image/Text
0087 View On' messages from initiator 0xf ('Unregistered') to destination 0 ('TV').
0088
0089 .. tabularcolumns:: |p{1.0cm}|p{3.5cm}|p{12.8cm}|
0090
0091 .. c:type:: cec_msg
0092
0093 .. cssclass:: longtable
0094
0095 .. flat-table:: struct cec_msg
0096 :header-rows: 0
0097 :stub-columns: 0
0098 :widths: 1 1 16
0099
0100 * - __u64
0101 - ``tx_ts``
0102 - Timestamp in ns of when the last byte of the message was transmitted.
0103 The timestamp has been taken from the ``CLOCK_MONOTONIC`` clock. To access
0104 the same clock from userspace use :c:func:`clock_gettime`.
0105 * - __u64
0106 - ``rx_ts``
0107 - Timestamp in ns of when the last byte of the message was received.
0108 The timestamp has been taken from the ``CLOCK_MONOTONIC`` clock. To access
0109 the same clock from userspace use :c:func:`clock_gettime`.
0110 * - __u32
0111 - ``len``
0112 - The length of the message. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` this is filled in
0113 by the application. The driver will fill this in for
0114 :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` it will be
0115 filled in by the driver with the length of the reply message if ``reply`` was set.
0116 * - __u32
0117 - ``timeout``
0118 - The timeout in milliseconds. This is the time the device will wait
0119 for a message to be received before timing out. If it is set to 0,
0120 then it will wait indefinitely when it is called by :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
0121 If it is 0 and it is called by :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`,
0122 then it will be replaced by 1000 if the ``reply`` is non-zero or
0123 ignored if ``reply`` is 0.
0124 * - __u32
0125 - ``sequence``
0126 - A non-zero sequence number is automatically assigned by the CEC framework
0127 for all transmitted messages. It is used by the CEC framework when it queues
0128 the transmit result for a non-blocking transmit. This allows the application
0129 to associate the received message with the original transmit.
0130
0131 In addition, if a non-blocking transmit will wait for a reply (ii.e. ``timeout``
0132 was not 0), then the ``sequence`` field of the reply will be set to the sequence
0133 value of the original transmit. This allows the application to associate the
0134 received message with the original transmit.
0135 * - __u32
0136 - ``flags``
0137 - Flags. See :ref:`cec-msg-flags` for a list of available flags.
0138 * - __u8
0139 - ``msg[16]``
0140 - The message payload. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` this is filled in by the
0141 application. The driver will fill this in for :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
0142 For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` it will be filled in by the driver with
0143 the payload of the reply message if ``timeout`` was set.
0144 * - __u8
0145 - ``reply``
0146 - Wait until this message is replied. If ``reply`` is 0 and the
0147 ``timeout`` is 0, then don't wait for a reply but return after
0148 transmitting the message. Ignored by :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
0149 The case where ``reply`` is 0 (this is the opcode for the Feature Abort
0150 message) and ``timeout`` is non-zero is specifically allowed to make it
0151 possible to send a message and wait up to ``timeout`` milliseconds for a
0152 Feature Abort reply. In this case ``rx_status`` will either be set
0153 to :ref:`CEC_RX_STATUS_TIMEOUT <CEC-RX-STATUS-TIMEOUT>` or
0154 :ref:`CEC_RX_STATUS_FEATURE_ABORT <CEC-RX-STATUS-FEATURE-ABORT>`.
0155
0156 If the transmitter message is ``CEC_MSG_INITIATE_ARC`` then the ``reply``
0157 values ``CEC_MSG_REPORT_ARC_INITIATED`` and ``CEC_MSG_REPORT_ARC_TERMINATED``
0158 are processed differently: either value will match both possible replies.
0159 The reason is that the ``CEC_MSG_INITIATE_ARC`` message is the only CEC
0160 message that has two possible replies other than Feature Abort. The
0161 ``reply`` field will be updated with the actual reply so that it is
0162 synchronized with the contents of the received message.
0163 * - __u8
0164 - ``rx_status``
0165 - The status bits of the received message. See
0166 :ref:`cec-rx-status` for the possible status values.
0167 * - __u8
0168 - ``tx_status``
0169 - The status bits of the transmitted message. See
0170 :ref:`cec-tx-status` for the possible status values.
0171 When calling :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` in non-blocking mode,
0172 this field will be 0 if the transmit started, or non-0 if the transmit
0173 result is known immediately. The latter would be the case when attempting
0174 to transmit a Poll message to yourself. That results in a
0175 :ref:`CEC_TX_STATUS_NACK <CEC-TX-STATUS-NACK>` without ever actually
0176 transmitting the Poll message.
0177 * - __u8
0178 - ``tx_arb_lost_cnt``
0179 - A counter of the number of transmit attempts that resulted in the
0180 Arbitration Lost error. This is only set if the hardware supports
0181 this, otherwise it is always 0. This counter is only valid if the
0182 :ref:`CEC_TX_STATUS_ARB_LOST <CEC-TX-STATUS-ARB-LOST>` status bit is set.
0183 * - __u8
0184 - ``tx_nack_cnt``
0185 - A counter of the number of transmit attempts that resulted in the
0186 Not Acknowledged error. This is only set if the hardware supports
0187 this, otherwise it is always 0. This counter is only valid if the
0188 :ref:`CEC_TX_STATUS_NACK <CEC-TX-STATUS-NACK>` status bit is set.
0189 * - __u8
0190 - ``tx_low_drive_cnt``
0191 - A counter of the number of transmit attempts that resulted in the
0192 Arbitration Lost error. This is only set if the hardware supports
0193 this, otherwise it is always 0. This counter is only valid if the
0194 :ref:`CEC_TX_STATUS_LOW_DRIVE <CEC-TX-STATUS-LOW-DRIVE>` status bit is set.
0195 * - __u8
0196 - ``tx_error_cnt``
0197 - A counter of the number of transmit errors other than Arbitration
0198 Lost or Not Acknowledged. This is only set if the hardware
0199 supports this, otherwise it is always 0. This counter is only
0200 valid if the :ref:`CEC_TX_STATUS_ERROR <CEC-TX-STATUS-ERROR>` status bit is set.
0201
0202 .. tabularcolumns:: |p{6.2cm}|p{1.0cm}|p{10.1cm}|
0203
0204 .. _cec-msg-flags:
0205
0206 .. flat-table:: Flags for struct cec_msg
0207 :header-rows: 0
0208 :stub-columns: 0
0209 :widths: 3 1 4
0210
0211 * .. _`CEC-MSG-FL-REPLY-TO-FOLLOWERS`:
0212
0213 - ``CEC_MSG_FL_REPLY_TO_FOLLOWERS``
0214 - 1
0215 - If a CEC transmit expects a reply, then by default that reply is only sent to
0216 the filehandle that called :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`. If this
0217 flag is set, then the reply is also sent to all followers, if any. If the
0218 filehandle that called :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` is also a
0219 follower, then that filehandle will receive the reply twice: once as the
0220 result of the :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`, and once via
0221 :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
0222
0223 * .. _`CEC-MSG-FL-RAW`:
0224
0225 - ``CEC_MSG_FL_RAW``
0226 - 2
0227 - Normally CEC messages are validated before transmitting them. If this
0228 flag is set when :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` is called,
0229 then no validation takes place and the message is transmitted as-is.
0230 This is useful when debugging CEC issues.
0231 This flag is only allowed if the process has the ``CAP_SYS_RAWIO``
0232 capability. If that is not set, then the ``EPERM`` error code is
0233 returned.
0234
0235 .. tabularcolumns:: |p{5.6cm}|p{0.9cm}|p{10.8cm}|
0236
0237 .. _cec-tx-status:
0238
0239 .. flat-table:: CEC Transmit Status
0240 :header-rows: 0
0241 :stub-columns: 0
0242 :widths: 3 1 16
0243
0244 * .. _`CEC-TX-STATUS-OK`:
0245
0246 - ``CEC_TX_STATUS_OK``
0247 - 0x01
0248 - The message was transmitted successfully. This is mutually
0249 exclusive with :ref:`CEC_TX_STATUS_MAX_RETRIES <CEC-TX-STATUS-MAX-RETRIES>`.
0250 Other bits can still be set if earlier attempts met with failure before
0251 the transmit was eventually successful.
0252 * .. _`CEC-TX-STATUS-ARB-LOST`:
0253
0254 - ``CEC_TX_STATUS_ARB_LOST``
0255 - 0x02
0256 - CEC line arbitration was lost, i.e. another transmit started at the
0257 same time with a higher priority. Optional status, not all hardware
0258 can detect this error condition.
0259 * .. _`CEC-TX-STATUS-NACK`:
0260
0261 - ``CEC_TX_STATUS_NACK``
0262 - 0x04
0263 - Message was not acknowledged. Note that some hardware cannot tell apart
0264 a 'Not Acknowledged' status from other error conditions, i.e. the result
0265 of a transmit is just OK or FAIL. In that case this status will be
0266 returned when the transmit failed.
0267 * .. _`CEC-TX-STATUS-LOW-DRIVE`:
0268
0269 - ``CEC_TX_STATUS_LOW_DRIVE``
0270 - 0x08
0271 - Low drive was detected on the CEC bus. This indicates that a
0272 follower detected an error on the bus and requests a
0273 retransmission. Optional status, not all hardware can detect this
0274 error condition.
0275 * .. _`CEC-TX-STATUS-ERROR`:
0276
0277 - ``CEC_TX_STATUS_ERROR``
0278 - 0x10
0279 - Some error occurred. This is used for any errors that do not fit
0280 ``CEC_TX_STATUS_ARB_LOST`` or ``CEC_TX_STATUS_LOW_DRIVE``, either because
0281 the hardware could not tell which error occurred, or because the hardware
0282 tested for other conditions besides those two. Optional status.
0283 * .. _`CEC-TX-STATUS-MAX-RETRIES`:
0284
0285 - ``CEC_TX_STATUS_MAX_RETRIES``
0286 - 0x20
0287 - The transmit failed after one or more retries. This status bit is
0288 mutually exclusive with :ref:`CEC_TX_STATUS_OK <CEC-TX-STATUS-OK>`.
0289 Other bits can still be set to explain which failures were seen.
0290 * .. _`CEC-TX-STATUS-ABORTED`:
0291
0292 - ``CEC_TX_STATUS_ABORTED``
0293 - 0x40
0294 - The transmit was aborted due to an HDMI disconnect, or the adapter
0295 was unconfigured, or a transmit was interrupted, or the driver
0296 returned an error when attempting to start a transmit.
0297 * .. _`CEC-TX-STATUS-TIMEOUT`:
0298
0299 - ``CEC_TX_STATUS_TIMEOUT``
0300 - 0x80
0301 - The transmit timed out. This should not normally happen and this
0302 indicates a driver problem.
0303
0304 .. tabularcolumns:: |p{5.6cm}|p{0.9cm}|p{10.8cm}|
0305
0306 .. _cec-rx-status:
0307
0308 .. flat-table:: CEC Receive Status
0309 :header-rows: 0
0310 :stub-columns: 0
0311 :widths: 3 1 16
0312
0313 * .. _`CEC-RX-STATUS-OK`:
0314
0315 - ``CEC_RX_STATUS_OK``
0316 - 0x01
0317 - The message was received successfully.
0318 * .. _`CEC-RX-STATUS-TIMEOUT`:
0319
0320 - ``CEC_RX_STATUS_TIMEOUT``
0321 - 0x02
0322 - The reply to an earlier transmitted message timed out.
0323 * .. _`CEC-RX-STATUS-FEATURE-ABORT`:
0324
0325 - ``CEC_RX_STATUS_FEATURE_ABORT``
0326 - 0x04
0327 - The message was received successfully but the reply was
0328 ``CEC_MSG_FEATURE_ABORT``. This status is only set if this message
0329 was the reply to an earlier transmitted message.
0330 * .. _`CEC-RX-STATUS-ABORTED`:
0331
0332 - ``CEC_RX_STATUS_ABORTED``
0333 - 0x08
0334 - The wait for a reply to an earlier transmitted message was aborted
0335 because the HDMI cable was disconnected, the adapter was unconfigured
0336 or the :ref:`CEC_TRANSMIT <CEC_RECEIVE>` that waited for a
0337 reply was interrupted.
0338
0339
0340 Return Value
0341 ============
0342
0343 On success 0 is returned, on error -1 and the ``errno`` variable is set
0344 appropriately. The generic error codes are described at the
0345 :ref:`Generic Error Codes <gen-errors>` chapter.
0346
0347 The :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>` can return the following
0348 error codes:
0349
0350 EAGAIN
0351 No messages are in the receive queue, and the filehandle is in non-blocking mode.
0352
0353 ETIMEDOUT
0354 The ``timeout`` was reached while waiting for a message.
0355
0356 ERESTARTSYS
0357 The wait for a message was interrupted (e.g. by Ctrl-C).
0358
0359 The :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` can return the following
0360 error codes:
0361
0362 ENOTTY
0363 The ``CEC_CAP_TRANSMIT`` capability wasn't set, so this ioctl is not supported.
0364
0365 EPERM
0366 The CEC adapter is not configured, i.e. :ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`
0367 has never been called, or ``CEC_MSG_FL_RAW`` was used from a process that
0368 did not have the ``CAP_SYS_RAWIO`` capability.
0369
0370 ENONET
0371 The CEC adapter is not configured, i.e. :ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`
0372 was called, but the physical address is invalid so no logical address was claimed.
0373 An exception is made in this case for transmits from initiator 0xf ('Unregistered')
0374 to destination 0 ('TV'). In that case the transmit will proceed as usual.
0375
0376 EBUSY
0377 Another filehandle is in exclusive follower or initiator mode, or the filehandle
0378 is in mode ``CEC_MODE_NO_INITIATOR``. This is also returned if the transmit
0379 queue is full.
0380
0381 EINVAL
0382 The contents of struct :c:type:`cec_msg` is invalid.
0383
0384 ERESTARTSYS
0385 The wait for a successful transmit was interrupted (e.g. by Ctrl-C).