PageRenderTime 63ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/Documentation/media/uapi/cec/cec-ioc-receive.rst

https://github.com/ido/linux
ReStructuredText | 344 lines | 277 code | 67 blank | 0 comment | 0 complexity | 7012102cadf5b80138eef9dd0c10c1f5 MD5 | raw file
  1. .. -*- coding: utf-8; mode: rst -*-
  2. .. _CEC_TRANSMIT:
  3. .. _CEC_RECEIVE:
  4. ***********************************
  5. ioctls CEC_RECEIVE and CEC_TRANSMIT
  6. ***********************************
  7. Name
  8. ====
  9. CEC_RECEIVE, CEC_TRANSMIT - Receive or transmit a CEC message
  10. Synopsis
  11. ========
  12. .. c:function:: int ioctl( int fd, CEC_RECEIVE, struct cec_msg *argp )
  13. :name: CEC_RECEIVE
  14. .. c:function:: int ioctl( int fd, CEC_TRANSMIT, struct cec_msg *argp )
  15. :name: CEC_TRANSMIT
  16. Arguments
  17. =========
  18. ``fd``
  19. File descriptor returned by :c:func:`open() <cec-open>`.
  20. ``argp``
  21. Pointer to struct cec_msg.
  22. Description
  23. ===========
  24. To receive a CEC message the application has to fill in the
  25. ``timeout`` field of struct :c:type:`cec_msg` and pass it to
  26. :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
  27. If the file descriptor is in non-blocking mode and there are no received
  28. messages pending, then it will return -1 and set errno to the ``EAGAIN``
  29. error code. If the file descriptor is in blocking mode and ``timeout``
  30. is non-zero and no message arrived within ``timeout`` milliseconds, then
  31. it will return -1 and set errno to the ``ETIMEDOUT`` error code.
  32. A received message can be:
  33. 1. a message received from another CEC device (the ``sequence`` field will
  34. be 0).
  35. 2. the result of an earlier non-blocking transmit (the ``sequence`` field will
  36. be non-zero).
  37. To send a CEC message the application has to fill in the struct
  38. :c:type:`cec_msg` and pass it to :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`.
  39. The :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` is only available if
  40. ``CEC_CAP_TRANSMIT`` is set. If there is no more room in the transmit
  41. queue, then it will return -1 and set errno to the ``EBUSY`` error code.
  42. The transmit queue has enough room for 18 messages (about 1 second worth
  43. of 2-byte messages). Note that the CEC kernel framework will also reply
  44. to core messages (see :ref:`cec-core-processing`), so it is not a good
  45. idea to fully fill up the transmit queue.
  46. If the file descriptor is in non-blocking mode then the transmit will
  47. return 0 and the result of the transmit will be available via
  48. :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>` once the transmit has finished
  49. (including waiting for a reply, if requested).
  50. The ``sequence`` field is filled in for every transmit and this can be
  51. checked against the received messages to find the corresponding transmit
  52. result.
  53. Normally calling :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` when the physical
  54. address is invalid (due to e.g. a disconnect) will return ``ENONET``.
  55. However, the CEC specification allows sending messages from 'Unregistered' to
  56. 'TV' when the physical address is invalid since some TVs pull the hotplug detect
  57. pin of the HDMI connector low when they go into standby, or when switching to
  58. another input.
  59. When the hotplug detect pin goes low the EDID disappears, and thus the
  60. physical address, but the cable is still connected and CEC still works.
  61. In order to detect/wake up the device it is allowed to send poll and 'Image/Text
  62. View On' messages from initiator 0xf ('Unregistered') to destination 0 ('TV').
  63. .. tabularcolumns:: |p{1.0cm}|p{3.5cm}|p{13.0cm}|
  64. .. c:type:: cec_msg
  65. .. cssclass:: longtable
  66. .. flat-table:: struct cec_msg
  67. :header-rows: 0
  68. :stub-columns: 0
  69. :widths: 1 1 16
  70. * - __u64
  71. - ``tx_ts``
  72. - Timestamp in ns of when the last byte of the message was transmitted.
  73. The timestamp has been taken from the ``CLOCK_MONOTONIC`` clock. To access
  74. the same clock from userspace use :c:func:`clock_gettime`.
  75. * - __u64
  76. - ``rx_ts``
  77. - Timestamp in ns of when the last byte of the message was received.
  78. The timestamp has been taken from the ``CLOCK_MONOTONIC`` clock. To access
  79. the same clock from userspace use :c:func:`clock_gettime`.
  80. * - __u32
  81. - ``len``
  82. - The length of the message. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` this is filled in
  83. by the application. The driver will fill this in for
  84. :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` it will be
  85. filled in by the driver with the length of the reply message if ``reply`` was set.
  86. * - __u32
  87. - ``timeout``
  88. - The timeout in milliseconds. This is the time the device will wait
  89. for a message to be received before timing out. If it is set to 0,
  90. then it will wait indefinitely when it is called by :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
  91. If it is 0 and it is called by :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`,
  92. then it will be replaced by 1000 if the ``reply`` is non-zero or
  93. ignored if ``reply`` is 0.
  94. * - __u32
  95. - ``sequence``
  96. - A non-zero sequence number is automatically assigned by the CEC framework
  97. for all transmitted messages. It is used by the CEC framework when it queues
  98. the transmit result (when transmit was called in non-blocking mode). This
  99. allows the application to associate the received message with the original
  100. transmit.
  101. * - __u32
  102. - ``flags``
  103. - Flags. See :ref:`cec-msg-flags` for a list of available flags.
  104. * - __u8
  105. - ``tx_status``
  106. - The status bits of the transmitted message. See
  107. :ref:`cec-tx-status` for the possible status values. It is 0 if
  108. this messages was received, not transmitted.
  109. * - __u8
  110. - ``msg[16]``
  111. - The message payload. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` this is filled in by the
  112. application. The driver will fill this in for :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
  113. For :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` it will be filled in by the driver with
  114. the payload of the reply message if ``timeout`` was set.
  115. * - __u8
  116. - ``reply``
  117. - Wait until this message is replied. If ``reply`` is 0 and the
  118. ``timeout`` is 0, then don't wait for a reply but return after
  119. transmitting the message. Ignored by :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
  120. The case where ``reply`` is 0 (this is the opcode for the Feature Abort
  121. message) and ``timeout`` is non-zero is specifically allowed to make it
  122. possible to send a message and wait up to ``timeout`` milliseconds for a
  123. Feature Abort reply. In this case ``rx_status`` will either be set
  124. to :ref:`CEC_RX_STATUS_TIMEOUT <CEC-RX-STATUS-TIMEOUT>` or
  125. :ref:`CEC_RX_STATUS_FEATURE_ABORT <CEC-RX-STATUS-FEATURE-ABORT>`.
  126. If the transmitter message is ``CEC_MSG_INITIATE_ARC`` then the ``reply``
  127. values ``CEC_MSG_REPORT_ARC_INITIATED`` and ``CEC_MSG_REPORT_ARC_TERMINATED``
  128. are processed differently: either value will match both possible replies.
  129. The reason is that the ``CEC_MSG_INITIATE_ARC`` message is the only CEC
  130. message that has two possible replies other than Feature Abort. The
  131. ``reply`` field will be updated with the actual reply so that it is
  132. synchronized with the contents of the received message.
  133. * - __u8
  134. - ``rx_status``
  135. - The status bits of the received message. See
  136. :ref:`cec-rx-status` for the possible status values. It is 0 if
  137. this message was transmitted, not received, unless this is the
  138. reply to a transmitted message. In that case both ``rx_status``
  139. and ``tx_status`` are set.
  140. * - __u8
  141. - ``tx_status``
  142. - The status bits of the transmitted message. See
  143. :ref:`cec-tx-status` for the possible status values. It is 0 if
  144. this messages was received, not transmitted.
  145. * - __u8
  146. - ``tx_arb_lost_cnt``
  147. - A counter of the number of transmit attempts that resulted in the
  148. Arbitration Lost error. This is only set if the hardware supports
  149. this, otherwise it is always 0. This counter is only valid if the
  150. :ref:`CEC_TX_STATUS_ARB_LOST <CEC-TX-STATUS-ARB-LOST>` status bit is set.
  151. * - __u8
  152. - ``tx_nack_cnt``
  153. - A counter of the number of transmit attempts that resulted in the
  154. Not Acknowledged error. This is only set if the hardware supports
  155. this, otherwise it is always 0. This counter is only valid if the
  156. :ref:`CEC_TX_STATUS_NACK <CEC-TX-STATUS-NACK>` status bit is set.
  157. * - __u8
  158. - ``tx_low_drive_cnt``
  159. - A counter of the number of transmit attempts that resulted in the
  160. Arbitration Lost error. This is only set if the hardware supports
  161. this, otherwise it is always 0. This counter is only valid if the
  162. :ref:`CEC_TX_STATUS_LOW_DRIVE <CEC-TX-STATUS-LOW-DRIVE>` status bit is set.
  163. * - __u8
  164. - ``tx_error_cnt``
  165. - A counter of the number of transmit errors other than Arbitration
  166. Lost or Not Acknowledged. This is only set if the hardware
  167. supports this, otherwise it is always 0. This counter is only
  168. valid if the :ref:`CEC_TX_STATUS_ERROR <CEC-TX-STATUS-ERROR>` status bit is set.
  169. .. tabularcolumns:: |p{6.2cm}|p{1.0cm}|p{10.3cm}|
  170. .. _cec-msg-flags:
  171. .. flat-table:: Flags for struct cec_msg
  172. :header-rows: 0
  173. :stub-columns: 0
  174. :widths: 3 1 4
  175. * .. _`CEC-MSG-FL-REPLY-TO-FOLLOWERS`:
  176. - ``CEC_MSG_FL_REPLY_TO_FOLLOWERS``
  177. - 1
  178. - If a CEC transmit expects a reply, then by default that reply is only sent to
  179. the filehandle that called :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`. If this
  180. flag is set, then the reply is also sent to all followers, if any. If the
  181. filehandle that called :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` is also a
  182. follower, then that filehandle will receive the reply twice: once as the
  183. result of the :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`, and once via
  184. :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>`.
  185. .. tabularcolumns:: |p{5.6cm}|p{0.9cm}|p{11.0cm}|
  186. .. _cec-tx-status:
  187. .. flat-table:: CEC Transmit Status
  188. :header-rows: 0
  189. :stub-columns: 0
  190. :widths: 3 1 16
  191. * .. _`CEC-TX-STATUS-OK`:
  192. - ``CEC_TX_STATUS_OK``
  193. - 0x01
  194. - The message was transmitted successfully. This is mutually
  195. exclusive with :ref:`CEC_TX_STATUS_MAX_RETRIES <CEC-TX-STATUS-MAX-RETRIES>`. Other bits can still
  196. be set if earlier attempts met with failure before the transmit
  197. was eventually successful.
  198. * .. _`CEC-TX-STATUS-ARB-LOST`:
  199. - ``CEC_TX_STATUS_ARB_LOST``
  200. - 0x02
  201. - CEC line arbitration was lost.
  202. * .. _`CEC-TX-STATUS-NACK`:
  203. - ``CEC_TX_STATUS_NACK``
  204. - 0x04
  205. - Message was not acknowledged.
  206. * .. _`CEC-TX-STATUS-LOW-DRIVE`:
  207. - ``CEC_TX_STATUS_LOW_DRIVE``
  208. - 0x08
  209. - Low drive was detected on the CEC bus. This indicates that a
  210. follower detected an error on the bus and requests a
  211. retransmission.
  212. * .. _`CEC-TX-STATUS-ERROR`:
  213. - ``CEC_TX_STATUS_ERROR``
  214. - 0x10
  215. - Some error occurred. This is used for any errors that do not fit
  216. the previous two, either because the hardware could not tell which
  217. error occurred, or because the hardware tested for other
  218. conditions besides those two.
  219. * .. _`CEC-TX-STATUS-MAX-RETRIES`:
  220. - ``CEC_TX_STATUS_MAX_RETRIES``
  221. - 0x20
  222. - The transmit failed after one or more retries. This status bit is
  223. mutually exclusive with :ref:`CEC_TX_STATUS_OK <CEC-TX-STATUS-OK>`. Other bits can still
  224. be set to explain which failures were seen.
  225. .. tabularcolumns:: |p{5.6cm}|p{0.9cm}|p{11.0cm}|
  226. .. _cec-rx-status:
  227. .. flat-table:: CEC Receive Status
  228. :header-rows: 0
  229. :stub-columns: 0
  230. :widths: 3 1 16
  231. * .. _`CEC-RX-STATUS-OK`:
  232. - ``CEC_RX_STATUS_OK``
  233. - 0x01
  234. - The message was received successfully.
  235. * .. _`CEC-RX-STATUS-TIMEOUT`:
  236. - ``CEC_RX_STATUS_TIMEOUT``
  237. - 0x02
  238. - The reply to an earlier transmitted message timed out.
  239. * .. _`CEC-RX-STATUS-FEATURE-ABORT`:
  240. - ``CEC_RX_STATUS_FEATURE_ABORT``
  241. - 0x04
  242. - The message was received successfully but the reply was
  243. ``CEC_MSG_FEATURE_ABORT``. This status is only set if this message
  244. was the reply to an earlier transmitted message.
  245. Return Value
  246. ============
  247. On success 0 is returned, on error -1 and the ``errno`` variable is set
  248. appropriately. The generic error codes are described at the
  249. :ref:`Generic Error Codes <gen-errors>` chapter.
  250. The :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>` can return the following
  251. error codes:
  252. EAGAIN
  253. No messages are in the receive queue, and the filehandle is in non-blocking mode.
  254. ETIMEDOUT
  255. The ``timeout`` was reached while waiting for a message.
  256. ERESTARTSYS
  257. The wait for a message was interrupted (e.g. by Ctrl-C).
  258. The :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>` can return the following
  259. error codes:
  260. ENOTTY
  261. The ``CEC_CAP_TRANSMIT`` capability wasn't set, so this ioctl is not supported.
  262. EPERM
  263. The CEC adapter is not configured, i.e. :ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`
  264. has never been called.
  265. ENONET
  266. The CEC adapter is not configured, i.e. :ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`
  267. was called, but the physical address is invalid so no logical address was claimed.
  268. An exception is made in this case for transmits from initiator 0xf ('Unregistered')
  269. to destination 0 ('TV'). In that case the transmit will proceed as usual.
  270. EBUSY
  271. Another filehandle is in exclusive follower or initiator mode, or the filehandle
  272. is in mode ``CEC_MODE_NO_INITIATOR``. This is also returned if the transmit
  273. queue is full.
  274. EINVAL
  275. The contents of struct :c:type:`cec_msg` is invalid.
  276. ERESTARTSYS
  277. The wait for a successful transmit was interrupted (e.g. by Ctrl-C).