← Documents Documentation/userspace-api/media/cec/cec-ioc-g-mode.rst GitHub 원문 ↗

Linux 6.18.37 · Userspace API / Media / CEC

ioctls CEC_G_MODE와 CEC_S_MODE

CEC filehandle의 initiator·follower·monitor mode, exclusive access와 core message 처리 규칙을 설명합니다.

Source pathDocumentation/userspace-api/media/cec/cec-ioc-g-mode.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

cec-ioc-g-mode.rst:1-294

이 API는 CEC adapter를 여러 응용 프로그램이 함께 사용할 때 message 송신권, 수신 처리 책임과 debugging 관찰권을 filehandle별로 조정합니다. 하위 nibble의 initiator mode와 상위 nibble의 follower·monitor mode를 결합하며, exclusive role 충돌은 EBUSY, 잘못된 조합이나 adapter capability 부족은 EINVAL, monitor 권한 부족은 EPERM으로 구분합니다. 원문 EPERM 항목의 CAP_NET_ADMIN 문장은 앞선 규칙과 모순되므로 주의가 필요합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2 .. c:namespace:: CEC
3
4 .. _CEC_MODE:
5 .. _CEC_G_MODE:
6 .. _CEC_S_MODE:
7
8 ********************************
9 ioctls CEC_G_MODE and CEC_S_MODE
10 ********************************
11
12 CEC_G_MODE, CEC_S_MODE - Get or set exclusive use of the CEC adapter
13
14 Synopsis
15 ========
16
17 .. c:macro:: CEC_G_MODE
18
19 ``int ioctl(int fd, CEC_G_MODE, __u32 *argp)``
20
21 .. c:macro:: CEC_S_MODE
22
23 ``int ioctl(int fd, CEC_S_MODE, __u32 *argp)``
24
25 Arguments
26 =========
27
28 ``fd``
29 File descriptor returned by :c:func:`open()`.
30
31 ``argp``
32 Pointer to CEC mode.
33
34 Description
35 ===========
36
37 By default any filehandle can use :ref:`CEC_TRANSMIT`, but in order to prevent
38 applications from stepping on each others toes it must be possible to
39 obtain exclusive access to the CEC adapter. This ioctl sets the
40 filehandle to initiator and/or follower mode which can be exclusive
41 depending on the chosen mode. The initiator is the filehandle that is
42 used to initiate messages, i.e. it commands other CEC devices. The
43 follower is the filehandle that receives messages sent to the CEC
44 adapter and processes them. The same filehandle can be both initiator
45 and follower, or this role can be taken by two different filehandles.
46
47 When a CEC message is received, then the CEC framework will decide how
48 it will be processed. If the message is a reply to an earlier
49 transmitted message, then the reply is sent back to the filehandle that
50 is waiting for it. In addition the CEC framework will process it.
51
52 If the message is not a reply, then the CEC framework will process it
53 first. If there is no follower, then the message is just discarded and a
54 feature abort is sent back to the initiator if the framework couldn't
55 process it. If there is a follower, then the message is passed on to the
56 follower who will use :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>` to dequeue
57 the new message. The framework expects the follower to make the right
58 decisions.
59
60 The CEC framework will process core messages unless requested otherwise
61 by the follower. The follower can enable the passthrough mode. In that
62 case, the CEC framework will pass on most core messages without
63 processing them and the follower will have to implement those messages.
64 There are some messages that the core will always process, regardless of
65 the passthrough mode. See :ref:`cec-core-processing` for details.
66
67 If there is no initiator, then any CEC filehandle can use
68 :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`. If there is an exclusive
69 initiator then only that initiator can call
70 :ref:`CEC_TRANSMIT`. The follower can of course
71 always call :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`.
72
73 Available initiator modes are:
74
75 .. tabularcolumns:: |p{5.6cm}|p{0.9cm}|p{10.8cm}|
76
77 .. _cec-mode-initiator_e:
78
79 .. flat-table:: Initiator Modes
80 :header-rows: 0
81 :stub-columns: 0
82 :widths: 3 1 16
83
84 * .. _`CEC-MODE-NO-INITIATOR`:
85
86 - ``CEC_MODE_NO_INITIATOR``
87 - 0x0
88 - This is not an initiator, i.e. it cannot transmit CEC messages or
89 make any other changes to the CEC adapter.
90 * .. _`CEC-MODE-INITIATOR`:
91
92 - ``CEC_MODE_INITIATOR``
93 - 0x1
94 - This is an initiator (the default when the device is opened) and
95 it can transmit CEC messages and make changes to the CEC adapter,
96 unless there is an exclusive initiator.
97 * .. _`CEC-MODE-EXCL-INITIATOR`:
98
99 - ``CEC_MODE_EXCL_INITIATOR``
100 - 0x2
101 - This is an exclusive initiator and this file descriptor is the
102 only one that can transmit CEC messages and make changes to the
103 CEC adapter. If someone else is already the exclusive initiator
104 then an attempt to become one will return the ``EBUSY`` error code
105 error.
106
107 Available follower modes are:
108
109 .. tabularcolumns:: |p{6.6cm}|p{0.9cm}|p{9.8cm}|
110
111 .. _cec-mode-follower_e:
112
113 .. cssclass:: longtable
114
115 .. flat-table:: Follower Modes
116 :header-rows: 0
117 :stub-columns: 0
118 :widths: 3 1 16
119
120 * .. _`CEC-MODE-NO-FOLLOWER`:
121
122 - ``CEC_MODE_NO_FOLLOWER``
123 - 0x00
124 - This is not a follower (the default when the device is opened).
125 * .. _`CEC-MODE-FOLLOWER`:
126
127 - ``CEC_MODE_FOLLOWER``
128 - 0x10
129 - This is a follower and it will receive CEC messages unless there
130 is an exclusive follower. You cannot become a follower if
131 :ref:`CEC_CAP_TRANSMIT <CEC-CAP-TRANSMIT>` is not set or if :ref:`CEC_MODE_NO_INITIATOR <CEC-MODE-NO-INITIATOR>`
132 was specified, the ``EINVAL`` error code is returned in that case.
133 * .. _`CEC-MODE-EXCL-FOLLOWER`:
134
135 - ``CEC_MODE_EXCL_FOLLOWER``
136 - 0x20
137 - This is an exclusive follower and only this file descriptor will
138 receive CEC messages for processing. If someone else is already
139 the exclusive follower then an attempt to become one will return
140 the ``EBUSY`` error code. You cannot become a follower if
141 :ref:`CEC_CAP_TRANSMIT <CEC-CAP-TRANSMIT>` is not set or if :ref:`CEC_MODE_NO_INITIATOR <CEC-MODE-NO-INITIATOR>`
142 was specified, the ``EINVAL`` error code is returned in that case.
143 * .. _`CEC-MODE-EXCL-FOLLOWER-PASSTHRU`:
144
145 - ``CEC_MODE_EXCL_FOLLOWER_PASSTHRU``
146 - 0x30
147 - This is an exclusive follower and only this file descriptor will
148 receive CEC messages for processing. In addition it will put the
149 CEC device into passthrough mode, allowing the exclusive follower
150 to handle most core messages instead of relying on the CEC
151 framework for that. If someone else is already the exclusive
152 follower then an attempt to become one will return the ``EBUSY`` error
153 code. You cannot become a follower if :ref:`CEC_CAP_TRANSMIT <CEC-CAP-TRANSMIT>`
154 is not set or if :ref:`CEC_MODE_NO_INITIATOR <CEC-MODE-NO-INITIATOR>` was specified,
155 the ``EINVAL`` error code is returned in that case.
156 * .. _`CEC-MODE-MONITOR-PIN`:
157
158 - ``CEC_MODE_MONITOR_PIN``
159 - 0xd0
160 - Put the file descriptor into pin monitoring mode. Can only be used in
161 combination with :ref:`CEC_MODE_NO_INITIATOR <CEC-MODE-NO-INITIATOR>`,
162 otherwise the ``EINVAL`` error code will be returned.
163 This mode requires that the :ref:`CEC_CAP_MONITOR_PIN <CEC-CAP-MONITOR-PIN>`
164 capability is set, otherwise the ``EINVAL`` error code is returned.
165 While in pin monitoring mode this file descriptor can receive the
166 ``CEC_EVENT_PIN_CEC_LOW`` and ``CEC_EVENT_PIN_CEC_HIGH`` events to see the
167 low-level CEC pin transitions. This is very useful for debugging.
168 This mode is only allowed if the process has the ``CAP_NET_ADMIN``
169 capability. If that is not set, then the ``EPERM`` error code is returned.
170 * .. _`CEC-MODE-MONITOR`:
171
172 - ``CEC_MODE_MONITOR``
173 - 0xe0
174 - Put the file descriptor into monitor mode. Can only be used in
175 combination with :ref:`CEC_MODE_NO_INITIATOR <CEC-MODE-NO-INITIATOR>`,
176 otherwise the ``EINVAL`` error code will be returned.
177 In monitor mode all messages this CEC
178 device transmits and all messages it receives (both broadcast
179 messages and directed messages for one its logical addresses) will
180 be reported. This is very useful for debugging. This is only
181 allowed if the process has the ``CAP_NET_ADMIN`` capability. If
182 that is not set, then the ``EPERM`` error code is returned.
183 * .. _`CEC-MODE-MONITOR-ALL`:
184
185 - ``CEC_MODE_MONITOR_ALL``
186 - 0xf0
187 - Put the file descriptor into 'monitor all' mode. Can only be used
188 in combination with :ref:`CEC_MODE_NO_INITIATOR <CEC-MODE-NO-INITIATOR>`, otherwise
189 the ``EINVAL`` error code will be returned. In 'monitor all' mode all messages
190 this CEC device transmits and all messages it receives, including
191 directed messages for other CEC devices, will be reported. This is
192 very useful for debugging, but not all devices support this. This
193 mode requires that the :ref:`CEC_CAP_MONITOR_ALL <CEC-CAP-MONITOR-ALL>` capability is set,
194 otherwise the ``EINVAL`` error code is returned. This is only allowed if
195 the process has the ``CAP_NET_ADMIN`` capability. If that is not
196 set, then the ``EPERM`` error code is returned.
197
198 Core message processing details:
199
200 .. tabularcolumns:: |p{6.6cm}|p{10.9cm}|
201
202 .. _cec-core-processing:
203
204 .. flat-table:: Core Message Processing
205 :header-rows: 0
206 :stub-columns: 0
207 :widths: 1 8
208
209 * .. _`CEC-MSG-GET-CEC-VERSION`:
210
211 - ``CEC_MSG_GET_CEC_VERSION``
212 - The core will return the CEC version that was set with
213 :ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`,
214 except when in passthrough mode. In passthrough mode the core
215 does nothing and this message has to be handled by a follower
216 instead.
217 * .. _`CEC-MSG-GIVE-DEVICE-VENDOR-ID`:
218
219 - ``CEC_MSG_GIVE_DEVICE_VENDOR_ID``
220 - The core will return the vendor ID that was set with
221 :ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`,
222 except when in passthrough mode. In passthrough mode the core
223 does nothing and this message has to be handled by a follower
224 instead.
225 * .. _`CEC-MSG-ABORT`:
226
227 - ``CEC_MSG_ABORT``
228 - The core will return a Feature Abort message with reason
229 'Feature Refused' as per the specification, except when in
230 passthrough mode. In passthrough mode the core does nothing
231 and this message has to be handled by a follower instead.
232 * .. _`CEC-MSG-GIVE-PHYSICAL-ADDR`:
233
234 - ``CEC_MSG_GIVE_PHYSICAL_ADDR``
235 - The core will report the current physical address, except when
236 in passthrough mode. In passthrough mode the core does nothing
237 and this message has to be handled by a follower instead.
238 * .. _`CEC-MSG-GIVE-OSD-NAME`:
239
240 - ``CEC_MSG_GIVE_OSD_NAME``
241 - The core will report the current OSD name that was set with
242 :ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`,
243 except when in passthrough mode. In passthrough mode the core
244 does nothing and this message has to be handled by a follower
245 instead.
246 * .. _`CEC-MSG-GIVE-FEATURES`:
247
248 - ``CEC_MSG_GIVE_FEATURES``
249 - The core will do nothing if the CEC version is older than 2.0,
250 otherwise it will report the current features that were set with
251 :ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`,
252 except when in passthrough mode. In passthrough mode the core
253 does nothing (for any CEC version) and this message has to be handled
254 by a follower instead.
255 * .. _`CEC-MSG-USER-CONTROL-PRESSED`:
256
257 - ``CEC_MSG_USER_CONTROL_PRESSED``
258 - If :ref:`CEC_CAP_RC <CEC-CAP-RC>` is set and if
259 :ref:`CEC_LOG_ADDRS_FL_ALLOW_RC_PASSTHRU <CEC-LOG-ADDRS-FL-ALLOW-RC-PASSTHRU>`
260 is set, then generate a remote control key
261 press. This message is always passed on to the follower(s).
262 * .. _`CEC-MSG-USER-CONTROL-RELEASED`:
263
264 - ``CEC_MSG_USER_CONTROL_RELEASED``
265 - If :ref:`CEC_CAP_RC <CEC-CAP-RC>` is set and if
266 :ref:`CEC_LOG_ADDRS_FL_ALLOW_RC_PASSTHRU <CEC-LOG-ADDRS-FL-ALLOW-RC-PASSTHRU>`
267 is set, then generate a remote control key
268 release. This message is always passed on to the follower(s).
269 * .. _`CEC-MSG-REPORT-PHYSICAL-ADDR`:
270
271 - ``CEC_MSG_REPORT_PHYSICAL_ADDR``
272 - The CEC framework will make note of the reported physical address
273 and then just pass the message on to the follower(s).
274
275
276 Return Value
277 ============
278
279 On success 0 is returned, on error -1 and the ``errno`` variable is set
280 appropriately. The generic error codes are described at the
281 :ref:`Generic Error Codes <gen-errors>` chapter.
282
283 The :ref:`ioctl CEC_S_MODE <CEC_S_MODE>` can return the following
284 error codes:
285
286 EINVAL
287 The requested mode is invalid.
288
289 EPERM
290 Monitor mode is requested, but the process does have the ``CAP_NET_ADMIN``
291 capability.
292
293 EBUSY
294 Someone else is already an exclusive follower or initiator.
295

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

이름, 선언과 인자

1-35

이 문서는 CEC namespace의 `CEC_G_MODE`와 `CEC_S_MODE` ioctl을 정의합니다. 두 ioctl은 CEC adapter를 배타적으로 사용할 수 있는 filehandle mode를 각각 조회하거나 설정합니다.

조회 호출 형식은 `int ioctl(int fd, CEC_G_MODE, __u32 *argp)`이고 설정 호출은 같은 인자에서 request만 `CEC_S_MODE`로 바뀝니다.

`fd`는 `open()`이 반환한 file descriptor이며, `argp`는 조회하거나 설정할 32-bit CEC mode를 가리키는 pointer입니다.

CEC mode ioctl
항목설명
CEC_G_MODE현재 filehandle의 CEC mode 조회
CEC_S_MODE현재 filehandle의 CEC mode 설정
fdopen()이 반환한 CEC file descriptor
argp__u32 CEC mode pointer

두 request는 같은 __u32 mode 표현을 공유합니다.

.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
.. c:namespace:: CEC

.. _CEC_MODE:
.. _CEC_G_MODE:
.. _CEC_S_MODE:

********************************
ioctls CEC_G_MODE and CEC_S_MODE
********************************

CEC_G_MODE, CEC_S_MODE - Get or set exclusive use of the CEC adapter

Synopsis
========

.. c:macro:: CEC_G_MODE

``int ioctl(int fd, CEC_G_MODE, __u32 *argp)``

.. c:macro:: CEC_S_MODE

``int ioctl(int fd, CEC_S_MODE, __u32 *argp)``

Arguments
=========

``fd``
    File descriptor returned by :c:func:`open()`.

``argp``
    Pointer to CEC mode.

Description
===========

Initiator·follower 역할과 message 전달

36-72

기본적으로 모든 filehandle이 `CEC_TRANSMIT`을 사용할 수 있지만, 여러 응용 프로그램이 서로 간섭하지 않도록 CEC adapter에 대한 exclusive access가 필요할 수 있습니다. `CEC_S_MODE`는 filehandle을 initiator와 follower 중 하나 또는 둘 다로 만들며, 선택한 mode에 따라 각 역할은 exclusive가 될 수 있습니다.

initiator는 다른 CEC device에 명령하는 message를 시작하는 filehandle이고, follower는 CEC adapter로 전송된 message를 받아 처리하는 filehandle입니다. 한 filehandle이 두 역할을 모두 맡을 수도 있고 서로 다른 두 filehandle이 나누어 맡을 수도 있습니다.

수신 message가 앞서 전송한 message의 reply라면 reply를 기다리던 filehandle로 돌려보내며 CEC framework도 그 message를 처리합니다.

reply가 아니면 framework가 먼저 처리합니다. follower가 없고 framework도 처리하지 못했다면 message를 버리고 initiator에 Feature Abort를 보냅니다. follower가 있으면 follower의 queue로 전달하며 follower는 `CEC_RECEIVE`로 dequeue한 뒤 올바른 처리를 결정해야 합니다.

CEC framework는 follower가 달리 요청하지 않는 한 core message를 처리합니다. follower가 passthrough mode를 켜면 대부분의 core message를 처리하지 않고 넘기므로 follower가 직접 구현해야 합니다. 다만 passthrough와 관계없이 core가 항상 처리하는 일부 message가 있으며 뒤의 `cec-core-processing` 표가 이를 구분합니다.

exclusive initiator가 없으면 어떤 CEC filehandle도 `CEC_TRANSMIT`을 호출할 수 있습니다. exclusive initiator가 있으면 그 initiator만 호출할 수 있지만 follower는 항상 `CEC_TRANSMIT`을 호출할 수 있습니다.

수신 CEC message 분배
CEC message 수신이전 transmit의 reply인지 판정reply이면 대기 중 filehandle에 반환하고 framework도 처리reply가 아니면 framework가 먼저 처리follower가 있으면 CEC_RECEIVE queue로 전달follower가 없고 미처리이면 discard 후 Feature Abort

reply 여부와 follower 존재 여부에 따라 전달 경로가 달라집니다.

역할별 책임
항목설명
initiatormessage 시작, adapter 변경, CEC_TRANSMIT
follower수신 message dequeue와 응답 결정
passthrough followerframework 대신 대부분의 core message 구현
exclusive initiator일반 filehandle의 transmit과 adapter 변경 차단

initiator와 follower는 독립적으로 또는 같은 descriptor에서 결합할 수 있습니다.


By default any filehandle can use :ref:`CEC_TRANSMIT`, but in order to prevent
applications from stepping on each others toes it must be possible to
obtain exclusive access to the CEC adapter. This ioctl sets the
filehandle to initiator and/or follower mode which can be exclusive
depending on the chosen mode. The initiator is the filehandle that is
used to initiate messages, i.e. it commands other CEC devices. The
follower is the filehandle that receives messages sent to the CEC
adapter and processes them. The same filehandle can be both initiator
and follower, or this role can be taken by two different filehandles.

When a CEC message is received, then the CEC framework will decide how
it will be processed. If the message is a reply to an earlier
transmitted message, then the reply is sent back to the filehandle that
is waiting for it. In addition the CEC framework will process it.

If the message is not a reply, then the CEC framework will process it
first. If there is no follower, then the message is just discarded and a
feature abort is sent back to the initiator if the framework couldn't
process it. If there is a follower, then the message is passed on to the
follower who will use :ref:`ioctl CEC_RECEIVE <CEC_RECEIVE>` to dequeue
the new message. The framework expects the follower to make the right
decisions.

The CEC framework will process core messages unless requested otherwise
by the follower. The follower can enable the passthrough mode. In that
case, the CEC framework will pass on most core messages without
processing them and the follower will have to implement those messages.
There are some messages that the core will always process, regardless of
the passthrough mode. See :ref:`cec-core-processing` for details.

If there is no initiator, then any CEC filehandle can use
:ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`. If there is an exclusive
initiator then only that initiator can call
:ref:`CEC_TRANSMIT`. The follower can of course
always call :ref:`ioctl CEC_TRANSMIT <CEC_TRANSMIT>`.

Initiator mode

73-106

initiator mode는 하위 4 bit에 들어가며 `CEC_MODE_NO_INITIATOR`, `CEC_MODE_INITIATOR`, `CEC_MODE_EXCL_INITIATOR` 세 값을 사용합니다.

`CEC_MODE_NO_INITIATOR`(0x0)는 initiator가 아니므로 CEC message를 전송하거나 CEC adapter의 다른 설정을 바꿀 수 없습니다.

`CEC_MODE_INITIATOR`(0x1)는 device를 열 때의 기본값입니다. exclusive initiator가 없는 동안 CEC message를 전송하고 adapter를 변경할 수 있습니다.

`CEC_MODE_EXCL_INITIATOR`(0x2)는 이 file descriptor 하나만 message를 전송하고 adapter를 변경하게 합니다. 다른 descriptor가 이미 exclusive initiator라면 새 요청은 `EBUSY`로 실패합니다.

Initiator mode 값
Mode동작
CEC_MODE_NO_INITIATOR0x0전송·adapter 변경 불가
CEC_MODE_INITIATOR0x1기본 mode, exclusive initiator가 없을 때 전송·변경 가능
CEC_MODE_EXCL_INITIATOR0x2유일한 전송·변경 descriptor, 충돌 시 EBUSY

배타성은 transmit과 adapter 변경 권한에 함께 적용됩니다.

Exclusive initiator 획득
CEC_S_MODE에 CEC_MODE_EXCL_INITIATOR 포함기존 exclusive initiator 확인없으면 현재 fd가 유일한 initiator가 됨있으면 EBUSY 반환

이미 소유자가 있는지에 따라 설정 결과가 정해집니다.

Available initiator modes are:

.. tabularcolumns:: |p{5.6cm}|p{0.9cm}|p{10.8cm}|

.. _cec-mode-initiator_e:

.. flat-table:: Initiator Modes
    :header-rows:  0
    :stub-columns: 0
    :widths:       3 1 16

    * .. _`CEC-MODE-NO-INITIATOR`:

      - ``CEC_MODE_NO_INITIATOR``
      - 0x0
      - This is not an initiator, i.e. it cannot transmit CEC messages or
	make any other changes to the CEC adapter.
    * .. _`CEC-MODE-INITIATOR`:

      - ``CEC_MODE_INITIATOR``
      - 0x1
      - This is an initiator (the default when the device is opened) and
	it can transmit CEC messages and make changes to the CEC adapter,
	unless there is an exclusive initiator.
    * .. _`CEC-MODE-EXCL-INITIATOR`:

      - ``CEC_MODE_EXCL_INITIATOR``
      - 0x2
      - This is an exclusive initiator and this file descriptor is the
	only one that can transmit CEC messages and make changes to the
	CEC adapter. If someone else is already the exclusive initiator
	then an attempt to become one will return the ``EBUSY`` error code
	error.

Follower와 passthrough mode

107-155

follower mode는 상위 nibble에 들어갑니다. device를 열 때 기본값인 `CEC_MODE_NO_FOLLOWER`(0x00)는 follower가 아닙니다.

`CEC_MODE_FOLLOWER`(0x10)는 exclusive follower가 없을 때 CEC message를 받습니다. `CEC_CAP_TRANSMIT` capability가 없거나 initiator mode로 `CEC_MODE_NO_INITIATOR`를 지정했다면 follower가 될 수 없고 `EINVAL`을 반환합니다.

`CEC_MODE_EXCL_FOLLOWER`(0x20)는 이 file descriptor만 처리할 CEC message를 받게 합니다. 다른 exclusive follower가 있으면 `EBUSY`이며, capability와 initiator 조합에 대한 `EINVAL` 조건은 일반 follower와 같습니다.

`CEC_MODE_EXCL_FOLLOWER_PASSTHRU`(0x30)는 exclusive follower에 passthrough를 더합니다. 이 descriptor만 message를 받고, 대부분의 core message를 CEC framework 대신 직접 처리합니다. 기존 exclusive follower가 있으면 `EBUSY`, `CEC_CAP_TRANSMIT`이 없거나 `CEC_MODE_NO_INITIATOR`와 결합하면 `EINVAL`입니다.

Follower mode 값
Mode동작
CEC_MODE_NO_FOLLOWER0x00기본값, follower 아님
CEC_MODE_FOLLOWER0x10exclusive follower가 없을 때 message 수신
CEC_MODE_EXCL_FOLLOWER0x20현재 fd만 처리용 message 수신
CEC_MODE_EXCL_FOLLOWER_PASSTHRU0x30exclusive 수신과 대부분의 core message 직접 처리

follower mode는 수신 소유권과 core 처리 책임을 결정합니다.

Follower 설정 실패 조건
항목설명
CEC_CAP_TRANSMIT 없음EINVAL
CEC_MODE_NO_INITIATOR와 결합EINVAL
기존 exclusive follower와 충돌EBUSY

모든 follower mode에 capability와 initiator 조합 제약이 적용됩니다.

Available follower modes are:

.. tabularcolumns:: |p{6.6cm}|p{0.9cm}|p{9.8cm}|

.. _cec-mode-follower_e:

.. cssclass:: longtable

.. flat-table:: Follower Modes
    :header-rows:  0
    :stub-columns: 0
    :widths:       3 1 16

    * .. _`CEC-MODE-NO-FOLLOWER`:

      - ``CEC_MODE_NO_FOLLOWER``
      - 0x00
      - This is not a follower (the default when the device is opened).
    * .. _`CEC-MODE-FOLLOWER`:

      - ``CEC_MODE_FOLLOWER``
      - 0x10
      - This is a follower and it will receive CEC messages unless there
	is an exclusive follower. You cannot become a follower if
	:ref:`CEC_CAP_TRANSMIT <CEC-CAP-TRANSMIT>` is not set or if :ref:`CEC_MODE_NO_INITIATOR <CEC-MODE-NO-INITIATOR>`
	was specified, the ``EINVAL`` error code is returned in that case.
    * .. _`CEC-MODE-EXCL-FOLLOWER`:

      - ``CEC_MODE_EXCL_FOLLOWER``
      - 0x20
      - This is an exclusive follower and only this file descriptor will
	receive CEC messages for processing. If someone else is already
	the exclusive follower then an attempt to become one will return
	the ``EBUSY`` error code. You cannot become a follower if
	:ref:`CEC_CAP_TRANSMIT <CEC-CAP-TRANSMIT>` is not set or if :ref:`CEC_MODE_NO_INITIATOR <CEC-MODE-NO-INITIATOR>`
	was specified, the ``EINVAL`` error code is returned in that case.
    * .. _`CEC-MODE-EXCL-FOLLOWER-PASSTHRU`:

      - ``CEC_MODE_EXCL_FOLLOWER_PASSTHRU``
      - 0x30
      - This is an exclusive follower and only this file descriptor will
	receive CEC messages for processing. In addition it will put the
	CEC device into passthrough mode, allowing the exclusive follower
	to handle most core messages instead of relying on the CEC
	framework for that. If someone else is already the exclusive
	follower then an attempt to become one will return the ``EBUSY`` error
	code. You cannot become a follower if :ref:`CEC_CAP_TRANSMIT <CEC-CAP-TRANSMIT>`
	is not set or if :ref:`CEC_MODE_NO_INITIATOR <CEC-MODE-NO-INITIATOR>` was specified,
	the ``EINVAL`` error code is returned in that case.

Pin monitor와 message monitor mode

156-197

`CEC_MODE_MONITOR_PIN`(0xd0)은 low-level CEC pin transition을 관찰합니다. `CEC_MODE_NO_INITIATOR`와만 결합할 수 있으며, 그렇지 않으면 `EINVAL`입니다. `CEC_CAP_MONITOR_PIN` capability도 필수이고 없으면 `EINVAL`입니다.

pin monitoring 중에는 `CEC_EVENT_PIN_CEC_LOW`와 `CEC_EVENT_PIN_CEC_HIGH` event로 CEC pin의 low/high 전이를 받을 수 있어 debugging에 유용합니다. 이 mode는 process가 `CAP_NET_ADMIN` capability를 가질 때만 허용되며, 없으면 `EPERM`입니다.

`CEC_MODE_MONITOR`(0xe0)은 해당 CEC device가 전송한 모든 message와 수신한 broadcast message 및 자기 logical address 대상 directed message를 보고합니다. `CEC_MODE_NO_INITIATOR`와만 결합할 수 있고 `CAP_NET_ADMIN`이 필요하며 위반 시 각각 `EINVAL`과 `EPERM`입니다.

`CEC_MODE_MONITOR_ALL`(0xf0)은 다른 CEC device를 대상으로 한 directed message까지 포함하여 adapter가 볼 수 있는 모든 송수신 message를 보고합니다. 모든 device가 이 기능을 지원하는 것은 아니며 `CEC_CAP_MONITOR_ALL`이 없으면 `EINVAL`입니다. 이 mode 역시 `CEC_MODE_NO_INITIATOR`와 `CAP_NET_ADMIN`이 필요합니다.

Monitor mode 비교
Mode관찰 범위필수 조건
CEC_MODE_MONITOR_PIN0xd0CEC pin edgeCEC_CAP_MONITOR_PIN + CAP_NET_ADMIN
CEC_MODE_MONITOR0xe0자기 adapter 송신과 자기 대상·broadcast 수신CAP_NET_ADMIN
CEC_MODE_MONITOR_ALL0xf0다른 device 대상 directed message까지CEC_CAP_MONITOR_ALL + CAP_NET_ADMIN

세 mode의 관찰 범위와 capability 요구 사항을 구분합니다.

Monitor mode 검증
CEC_MODE_NO_INITIATOR 조합 확인요청 mode별 CEC_CAP_MONITOR_PIN 또는 CEC_CAP_MONITOR_ALL 확인CAP_NET_ADMIN 확인조건 충족 시 monitoring 시작조합·capability 오류는 EINVAL, 권한 오류는 EPERM

mode 조합, adapter capability, process 권한을 차례로 검사합니다.

    * .. _`CEC-MODE-MONITOR-PIN`:

      - ``CEC_MODE_MONITOR_PIN``
      - 0xd0
      - Put the file descriptor into pin monitoring mode. Can only be used in
	combination with :ref:`CEC_MODE_NO_INITIATOR <CEC-MODE-NO-INITIATOR>`,
	otherwise the ``EINVAL`` error code will be returned.
	This mode requires that the :ref:`CEC_CAP_MONITOR_PIN <CEC-CAP-MONITOR-PIN>`
	capability is set, otherwise the ``EINVAL`` error code is returned.
	While in pin monitoring mode this file descriptor can receive the
	``CEC_EVENT_PIN_CEC_LOW`` and ``CEC_EVENT_PIN_CEC_HIGH`` events to see the
	low-level CEC pin transitions. This is very useful for debugging.
	This mode is only allowed if the process has the ``CAP_NET_ADMIN``
	capability. If that is not set, then the ``EPERM`` error code is returned.
    * .. _`CEC-MODE-MONITOR`:

      - ``CEC_MODE_MONITOR``
      - 0xe0
      - Put the file descriptor into monitor mode. Can only be used in
	combination with :ref:`CEC_MODE_NO_INITIATOR <CEC-MODE-NO-INITIATOR>`,
	otherwise the ``EINVAL`` error code will be returned.
	In monitor mode all messages this CEC
	device transmits and all messages it receives (both broadcast
	messages and directed messages for one its logical addresses) will
	be reported. This is very useful for debugging. This is only
	allowed if the process has the ``CAP_NET_ADMIN`` capability. If
	that is not set, then the ``EPERM`` error code is returned.
    * .. _`CEC-MODE-MONITOR-ALL`:

      - ``CEC_MODE_MONITOR_ALL``
      - 0xf0
      - Put the file descriptor into 'monitor all' mode. Can only be used
	in combination with :ref:`CEC_MODE_NO_INITIATOR <CEC-MODE-NO-INITIATOR>`, otherwise
	the ``EINVAL`` error code will be returned. In 'monitor all' mode all messages
	this CEC device transmits and all messages it receives, including
	directed messages for other CEC devices, will be reported. This is
	very useful for debugging, but not all devices support this. This
	mode requires that the :ref:`CEC_CAP_MONITOR_ALL <CEC-CAP-MONITOR-ALL>` capability is set,
	otherwise the ``EINVAL`` error code is returned. This is only allowed if
	the process has the ``CAP_NET_ADMIN`` capability. If that is not
	set, then the ``EPERM`` error code is returned.

Core가 처리하는 identity message

198-245

다음 표는 CEC framework의 core message 처리 규칙을 설명합니다. passthrough mode에서는 표시된 identity query를 core가 처리하지 않으므로 follower가 대신 응답해야 합니다.

`CEC_MSG_GET_CEC_VERSION`은 `CEC_ADAP_S_LOG_ADDRS`로 설정한 CEC version을 응답합니다. `CEC_MSG_GIVE_DEVICE_VENDOR_ID`는 같은 ioctl로 설정한 vendor ID를 응답합니다.

`CEC_MSG_ABORT`에는 specification에 따라 reason이 `Feature Refused`인 Feature Abort를 돌려줍니다.

`CEC_MSG_GIVE_PHYSICAL_ADDR`에는 현재 physical address를 보고하고, `CEC_MSG_GIVE_OSD_NAME`에는 `CEC_ADAP_S_LOG_ADDRS`로 설정한 현재 OSD name을 보고합니다.

이 다섯 message는 모두 passthrough mode에서 core가 아무 작업도 하지 않으며 follower가 처리해야 합니다.

Core identity message 처리
Message일반 modePassthrough mode
CEC_MSG_GET_CEC_VERSION설정된 CEC version 반환follower가 처리
CEC_MSG_GIVE_DEVICE_VENDOR_ID설정된 vendor ID 반환follower가 처리
CEC_MSG_ABORTFeature Refused reason의 Feature Abort 반환follower가 처리
CEC_MSG_GIVE_PHYSICAL_ADDR현재 physical address 보고follower가 처리
CEC_MSG_GIVE_OSD_NAME설정된 현재 OSD name 보고follower가 처리

passthrough가 아니면 framework가 표의 응답을 생성합니다.

Core message processing details:

.. tabularcolumns:: |p{6.6cm}|p{10.9cm}|

.. _cec-core-processing:

.. flat-table:: Core Message Processing
    :header-rows:  0
    :stub-columns: 0
    :widths: 1 8

    * .. _`CEC-MSG-GET-CEC-VERSION`:

      - ``CEC_MSG_GET_CEC_VERSION``
      - The core will return the CEC version that was set with
	:ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`,
	except when in passthrough mode. In passthrough mode the core
	does nothing and this message has to be handled by a follower
	instead.
    * .. _`CEC-MSG-GIVE-DEVICE-VENDOR-ID`:

      - ``CEC_MSG_GIVE_DEVICE_VENDOR_ID``
      - The core will return the vendor ID that was set with
	:ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`,
	except when in passthrough mode. In passthrough mode the core
	does nothing and this message has to be handled by a follower
	instead.
    * .. _`CEC-MSG-ABORT`:

      - ``CEC_MSG_ABORT``
      - The core will return a Feature Abort message with reason
        'Feature Refused' as per the specification, except when in
	passthrough mode. In passthrough mode the core does nothing
	and this message has to be handled by a follower instead.
    * .. _`CEC-MSG-GIVE-PHYSICAL-ADDR`:

      - ``CEC_MSG_GIVE_PHYSICAL_ADDR``
      - The core will report the current physical address, except when
        in passthrough mode. In passthrough mode the core does nothing
	and this message has to be handled by a follower instead.
    * .. _`CEC-MSG-GIVE-OSD-NAME`:

      - ``CEC_MSG_GIVE_OSD_NAME``
      - The core will report the current OSD name that was set with
	:ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`,
	except when in passthrough mode. In passthrough mode the core
	does nothing and this message has to be handled by a follower
	instead.

Feature·remote-control·topology message

246-274

`CEC_MSG_GIVE_FEATURES`는 CEC version이 2.0보다 낮으면 아무 작업도 하지 않습니다. 2.0 이상이면 `CEC_ADAP_S_LOG_ADDRS`로 설정한 현재 features를 보고합니다. passthrough mode에서는 CEC version과 관계없이 core가 아무 작업도 하지 않으므로 follower가 처리해야 합니다.

`CEC_MSG_USER_CONTROL_PRESSED`는 `CEC_CAP_RC`와 `CEC_LOG_ADDRS_FL_ALLOW_RC_PASSTHRU`가 모두 설정된 경우 remote-control key press를 생성합니다. `CEC_MSG_USER_CONTROL_RELEASED`는 같은 조건에서 key release를 생성합니다.

두 user-control message는 core의 key event 생성 여부와 관계없이 항상 follower에게도 전달됩니다.

`CEC_MSG_REPORT_PHYSICAL_ADDR`을 받으면 CEC framework가 보고된 physical address를 기록한 뒤 follower에게 그대로 전달합니다.

나머지 core message 처리
MessageCore 동작Follower 전달
CEC_MSG_GIVE_FEATURESCEC 2.0 이상이면 현재 features 보고passthrough에서는 follower가 처리
CEC_MSG_USER_CONTROL_PRESSED조건 충족 시 remote key press 생성항상 follower에도 전달
CEC_MSG_USER_CONTROL_RELEASED조건 충족 시 remote key release 생성항상 follower에도 전달
CEC_MSG_REPORT_PHYSICAL_ADDRreported physical address 기록기록 후 follower에 전달

CEC version, RC capability와 passthrough flag가 동작을 결정합니다.

Remote-control passthrough
USER_CONTROL_PRESSED 또는 RELEASED 수신CEC_CAP_RC 확인CEC_LOG_ADDRS_FL_ALLOW_RC_PASSTHRU 확인조건 충족 시 key press 또는 release 생성message는 항상 follower에도 전달

두 설정이 모두 켜졌을 때 input key event가 만들어집니다.

    * .. _`CEC-MSG-GIVE-FEATURES`:

      - ``CEC_MSG_GIVE_FEATURES``
      - The core will do nothing if the CEC version is older than 2.0,
        otherwise it will report the current features that were set with
	:ref:`ioctl CEC_ADAP_S_LOG_ADDRS <CEC_ADAP_S_LOG_ADDRS>`,
	except when in passthrough mode. In passthrough mode the core
	does nothing (for any CEC version) and this message has to be handled
	by a follower instead.
    * .. _`CEC-MSG-USER-CONTROL-PRESSED`:

      - ``CEC_MSG_USER_CONTROL_PRESSED``
      - If :ref:`CEC_CAP_RC <CEC-CAP-RC>` is set and if
        :ref:`CEC_LOG_ADDRS_FL_ALLOW_RC_PASSTHRU <CEC-LOG-ADDRS-FL-ALLOW-RC-PASSTHRU>`
	is set, then generate a remote control key
	press. This message is always passed on to the follower(s).
    * .. _`CEC-MSG-USER-CONTROL-RELEASED`:

      - ``CEC_MSG_USER_CONTROL_RELEASED``
      - If :ref:`CEC_CAP_RC <CEC-CAP-RC>` is set and if
        :ref:`CEC_LOG_ADDRS_FL_ALLOW_RC_PASSTHRU <CEC-LOG-ADDRS-FL-ALLOW-RC-PASSTHRU>`
        is set, then generate a remote control key
	release. This message is always passed on to the follower(s).
    * .. _`CEC-MSG-REPORT-PHYSICAL-ADDR`:

      - ``CEC_MSG_REPORT_PHYSICAL_ADDR``
      - The CEC framework will make note of the reported physical address
	and then just pass the message on to the follower(s).

반환값과 오류

275-294

성공하면 0, 오류이면 -1을 반환하고 `errno`를 설정합니다. 공통 오류는 Generic Error Codes 장을 따릅니다.

`CEC_S_MODE`에서 `EINVAL`은 요청한 mode가 유효하지 않음을 뜻하고, `EBUSY`는 다른 filehandle이 이미 exclusive follower 또는 exclusive initiator임을 뜻합니다.

원문 289–291행의 `EPERM` 설명은 monitor mode를 요청했지만 process가 `CAP_NET_ADMIN` capability를 ‘가지고 있다’고 적습니다. 이는 168–169행, 181–182행, 194–196행의 ‘capability가 없으면 EPERM’ 규칙과 반대입니다. 번역 본문은 원문 문장을 보존하며, 실제 동작을 판단할 때는 앞선 mode 설명과 kernel 구현을 함께 확인해야 합니다.

CEC_S_MODE 오류
항목설명
EINVAL요청 mode가 유효하지 않음
EPERM원문은 CAP_NET_ADMIN을 가지고 있다고 표기하며 앞선 설명과 불일치
EBUSY다른 descriptor가 이미 exclusive follower 또는 initiator

mode 형식, 권한, exclusive 소유권 충돌을 구분합니다.


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
:ref:`Generic Error Codes <gen-errors>` chapter.

The :ref:`ioctl CEC_S_MODE <CEC_S_MODE>` can return the following
error codes:

EINVAL
    The requested mode is invalid.

EPERM
    Monitor mode is requested, but the process does have the ``CAP_NET_ADMIN``
    capability.

EBUSY
    Someone else is already an exclusive follower or initiator.