diff options
author | Johannes Berg <johannes@sipsolutions.net> | 2009-06-02 07:01:37 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2009-06-03 14:06:13 -0400 |
commit | 19d337dff95cbf76edd3ad95c0cee2732c3e1ec5 (patch) | |
tree | 33326eeb09cb9664cc8427a5dc7cd2b08b5a57c3 /Documentation/rfkill.txt | |
parent | 0f6399c4c525b518644a9b09f8d6fb125a418c4d (diff) |
rfkill: rewrite
This patch completely rewrites the rfkill core to address
the following deficiencies:
* all rfkill drivers need to implement polling where necessary
rather than having one central implementation
* updating the rfkill state cannot be done from arbitrary
contexts, forcing drivers to use schedule_work and requiring
lots of code
* rfkill drivers need to keep track of soft/hard blocked
internally -- the core should do this
* the rfkill API has many unexpected quirks, for example being
asymmetric wrt. alloc/free and register/unregister
* rfkill can call back into a driver from within a function the
driver called -- this is prone to deadlocks and generally
should be avoided
* rfkill-input pointlessly is a separate module
* drivers need to #ifdef rfkill functions (unless they want to
depend on or select RFKILL) -- rfkill should provide inlines
that do nothing if it isn't compiled in
* the rfkill structure is not opaque -- drivers need to initialise
it correctly (lots of sanity checking code required) -- instead
force drivers to pass the right variables to rfkill_alloc()
* the documentation is hard to read because it always assumes the
reader is completely clueless and contains way TOO MANY CAPS
* the rfkill code needlessly uses a lot of locks and atomic
operations in locked sections
* fix LED trigger to actually change the LED when the radio state
changes -- this wasn't done before
Tested-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br> [thinkpad]
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'Documentation/rfkill.txt')
-rw-r--r-- | Documentation/rfkill.txt | 597 |
1 files changed, 78 insertions, 519 deletions
diff --git a/Documentation/rfkill.txt b/Documentation/rfkill.txt index 40c3a3f10816..de941e309d47 100644 --- a/Documentation/rfkill.txt +++ b/Documentation/rfkill.txt | |||
@@ -1,571 +1,130 @@ | |||
1 | rfkill - RF switch subsystem support | 1 | rfkill - RF kill switch support |
2 | ==================================== | 2 | =============================== |
3 | 3 | ||
4 | 1 Introduction | 4 | 1. Introduction |
5 | 2 Implementation details | 5 | 2. Implementation details |
6 | 3 Kernel driver guidelines | 6 | 3. Kernel driver guidelines |
7 | 3.1 wireless device drivers | 7 | 4. Kernel API |
8 | 3.2 platform/switch drivers | 8 | 5. Userspace support |
9 | 3.3 input device drivers | ||
10 | 4 Kernel API | ||
11 | 5 Userspace support | ||
12 | 9 | ||
13 | 10 | ||
14 | 1. Introduction: | 11 | 1. Introduction |
15 | 12 | ||
16 | The rfkill switch subsystem exists to add a generic interface to circuitry that | 13 | The rfkill subsystem provides a generic interface to disabling any radio |
17 | can enable or disable the signal output of a wireless *transmitter* of any | 14 | transmitter in the system. When a transmitter is blocked, it shall not |
18 | type. By far, the most common use is to disable radio-frequency transmitters. | 15 | radiate any power. |
19 | 16 | ||
20 | Note that disabling the signal output means that the the transmitter is to be | 17 | The subsystem also provides the ability to react on button presses and |
21 | made to not emit any energy when "blocked". rfkill is not about blocking data | 18 | disable all transmitters of a certain type (or all). This is intended for |
22 | transmissions, it is about blocking energy emission. | 19 | situations where transmitters need to be turned off, for example on |
20 | aircraft. | ||
23 | 21 | ||
24 | The rfkill subsystem offers support for keys and switches often found on | ||
25 | laptops to enable wireless devices like WiFi and Bluetooth, so that these keys | ||
26 | and switches actually perform an action in all wireless devices of a given type | ||
27 | attached to the system. | ||
28 | 22 | ||
29 | The buttons to enable and disable the wireless transmitters are important in | ||
30 | situations where the user is for example using his laptop on a location where | ||
31 | radio-frequency transmitters _must_ be disabled (e.g. airplanes). | ||
32 | 23 | ||
33 | Because of this requirement, userspace support for the keys should not be made | 24 | 2. Implementation details |
34 | mandatory. Because userspace might want to perform some additional smarter | ||
35 | tasks when the key is pressed, rfkill provides userspace the possibility to | ||
36 | take over the task to handle the key events. | ||
37 | |||
38 | =============================================================================== | ||
39 | 2: Implementation details | ||
40 | 25 | ||
41 | The rfkill subsystem is composed of various components: the rfkill class, the | 26 | The rfkill subsystem is composed of various components: the rfkill class, the |
42 | rfkill-input module (an input layer handler), and some specific input layer | 27 | rfkill-input module (an input layer handler), and some specific input layer |
43 | events. | 28 | events. |
44 | 29 | ||
45 | The rfkill class provides kernel drivers with an interface that allows them to | 30 | The rfkill class is provided for kernel drivers to register their radio |
46 | know when they should enable or disable a wireless network device transmitter. | 31 | transmitter with the kernel, provide methods for turning it on and off and, |
47 | This is enabled by the CONFIG_RFKILL Kconfig option. | 32 | optionally, letting the system know about hardware-disabled states that may |
48 | 33 | be implemented on the device. This code is enabled with the CONFIG_RFKILL | |
49 | The rfkill class support makes sure userspace will be notified of all state | 34 | Kconfig option, which drivers can "select". |
50 | changes on rfkill devices through uevents. It provides a notification chain | ||
51 | for interested parties in the kernel to also get notified of rfkill state | ||
52 | changes in other drivers. It creates several sysfs entries which can be used | ||
53 | by userspace. See section "Userspace support". | ||
54 | |||
55 | The rfkill-input module provides the kernel with the ability to implement a | ||
56 | basic response when the user presses a key or button (or toggles a switch) | ||
57 | related to rfkill functionality. It is an in-kernel implementation of default | ||
58 | policy of reacting to rfkill-related input events and neither mandatory nor | ||
59 | required for wireless drivers to operate. It is enabled by the | ||
60 | CONFIG_RFKILL_INPUT Kconfig option. | ||
61 | |||
62 | rfkill-input is a rfkill-related events input layer handler. This handler will | ||
63 | listen to all rfkill key events and will change the rfkill state of the | ||
64 | wireless devices accordingly. With this option enabled userspace could either | ||
65 | do nothing or simply perform monitoring tasks. | ||
66 | |||
67 | The rfkill-input module also provides EPO (emergency power-off) functionality | ||
68 | for all wireless transmitters. This function cannot be overridden, and it is | ||
69 | always active. rfkill EPO is related to *_RFKILL_ALL input layer events. | ||
70 | |||
71 | |||
72 | Important terms for the rfkill subsystem: | ||
73 | |||
74 | In order to avoid confusion, we avoid the term "switch" in rfkill when it is | ||
75 | referring to an electronic control circuit that enables or disables a | ||
76 | transmitter. We reserve it for the physical device a human manipulates | ||
77 | (which is an input device, by the way): | ||
78 | |||
79 | rfkill switch: | ||
80 | |||
81 | A physical device a human manipulates. Its state can be perceived by | ||
82 | the kernel either directly (through a GPIO pin, ACPI GPE) or by its | ||
83 | effect on a rfkill line of a wireless device. | ||
84 | |||
85 | rfkill controller: | ||
86 | |||
87 | A hardware circuit that controls the state of a rfkill line, which a | ||
88 | kernel driver can interact with *to modify* that state (i.e. it has | ||
89 | either write-only or read/write access). | ||
90 | |||
91 | rfkill line: | ||
92 | |||
93 | An input channel (hardware or software) of a wireless device, which | ||
94 | causes a wireless transmitter to stop emitting energy (BLOCK) when it | ||
95 | is active. Point of view is extremely important here: rfkill lines are | ||
96 | always seen from the PoV of a wireless device (and its driver). | ||
97 | |||
98 | soft rfkill line/software rfkill line: | ||
99 | |||
100 | A rfkill line the wireless device driver can directly change the state | ||
101 | of. Related to rfkill_state RFKILL_STATE_SOFT_BLOCKED. | ||
102 | |||
103 | hard rfkill line/hardware rfkill line: | ||
104 | |||
105 | A rfkill line that works fully in hardware or firmware, and that cannot | ||
106 | be overridden by the kernel driver. The hardware device or the | ||
107 | firmware just exports its status to the driver, but it is read-only. | ||
108 | Related to rfkill_state RFKILL_STATE_HARD_BLOCKED. | ||
109 | |||
110 | The enum rfkill_state describes the rfkill state of a transmitter: | ||
111 | |||
112 | When a rfkill line or rfkill controller is in the RFKILL_STATE_UNBLOCKED state, | ||
113 | the wireless transmitter (radio TX circuit for example) is *enabled*. When the | ||
114 | it is in the RFKILL_STATE_SOFT_BLOCKED or RFKILL_STATE_HARD_BLOCKED, the | ||
115 | wireless transmitter is to be *blocked* from operating. | ||
116 | |||
117 | RFKILL_STATE_SOFT_BLOCKED indicates that a call to toggle_radio() can change | ||
118 | that state. RFKILL_STATE_HARD_BLOCKED indicates that a call to toggle_radio() | ||
119 | will not be able to change the state and will return with a suitable error if | ||
120 | attempts are made to set the state to RFKILL_STATE_UNBLOCKED. | ||
121 | |||
122 | RFKILL_STATE_HARD_BLOCKED is used by drivers to signal that the device is | ||
123 | locked in the BLOCKED state by a hardwire rfkill line (typically an input pin | ||
124 | that, when active, forces the transmitter to be disabled) which the driver | ||
125 | CANNOT override. | ||
126 | |||
127 | Full rfkill functionality requires two different subsystems to cooperate: the | ||
128 | input layer and the rfkill class. The input layer issues *commands* to the | ||
129 | entire system requesting that devices registered to the rfkill class change | ||
130 | state. The way this interaction happens is not complex, but it is not obvious | ||
131 | either: | ||
132 | |||
133 | Kernel Input layer: | ||
134 | |||
135 | * Generates KEY_WWAN, KEY_WLAN, KEY_BLUETOOTH, SW_RFKILL_ALL, and | ||
136 | other such events when the user presses certain keys, buttons, or | ||
137 | toggles certain physical switches. | ||
138 | |||
139 | THE INPUT LAYER IS NEVER USED TO PROPAGATE STATUS, NOTIFICATIONS OR THE | ||
140 | KIND OF STUFF AN ON-SCREEN-DISPLAY APPLICATION WOULD REPORT. It is | ||
141 | used to issue *commands* for the system to change behaviour, and these | ||
142 | commands may or may not be carried out by some kernel driver or | ||
143 | userspace application. It follows that doing user feedback based only | ||
144 | on input events is broken, as there is no guarantee that an input event | ||
145 | will be acted upon. | ||
146 | |||
147 | Most wireless communication device drivers implementing rfkill | ||
148 | functionality MUST NOT generate these events, and have no reason to | ||
149 | register themselves with the input layer. Doing otherwise is a common | ||
150 | misconception. There is an API to propagate rfkill status change | ||
151 | information, and it is NOT the input layer. | ||
152 | |||
153 | rfkill class: | ||
154 | |||
155 | * Calls a hook in a driver to effectively change the wireless | ||
156 | transmitter state; | ||
157 | * Keeps track of the wireless transmitter state (with help from | ||
158 | the driver); | ||
159 | * Generates userspace notifications (uevents) and a call to a | ||
160 | notification chain (kernel) when there is a wireless transmitter | ||
161 | state change; | ||
162 | * Connects a wireless communications driver with the common rfkill | ||
163 | control system, which, for example, allows actions such as | ||
164 | "switch all bluetooth devices offline" to be carried out by | ||
165 | userspace or by rfkill-input. | ||
166 | |||
167 | THE RFKILL CLASS NEVER ISSUES INPUT EVENTS. THE RFKILL CLASS DOES | ||
168 | NOT LISTEN TO INPUT EVENTS. NO DRIVER USING THE RFKILL CLASS SHALL | ||
169 | EVER LISTEN TO, OR ACT ON RFKILL INPUT EVENTS. Doing otherwise is | ||
170 | a layering violation. | ||
171 | |||
172 | Most wireless data communication drivers in the kernel have just to | ||
173 | implement the rfkill class API to work properly. Interfacing to the | ||
174 | input layer is not often required (and is very often a *bug*) on | ||
175 | wireless drivers. | ||
176 | |||
177 | Platform drivers often have to attach to the input layer to *issue* | ||
178 | (but never to listen to) rfkill events for rfkill switches, and also to | ||
179 | the rfkill class to export a control interface for the platform rfkill | ||
180 | controllers to the rfkill subsystem. This does NOT mean the rfkill | ||
181 | switch is attached to a rfkill class (doing so is almost always wrong). | ||
182 | It just means the same kernel module is the driver for different | ||
183 | devices (rfkill switches and rfkill controllers). | ||
184 | |||
185 | |||
186 | Userspace input handlers (uevents) or kernel input handlers (rfkill-input): | ||
187 | |||
188 | * Implements the policy of what should happen when one of the input | ||
189 | layer events related to rfkill operation is received. | ||
190 | * Uses the sysfs interface (userspace) or private rfkill API calls | ||
191 | to tell the devices registered with the rfkill class to change | ||
192 | their state (i.e. translates the input layer event into real | ||
193 | action). | ||
194 | |||
195 | * rfkill-input implements EPO by handling EV_SW SW_RFKILL_ALL 0 | ||
196 | (power off all transmitters) in a special way: it ignores any | ||
197 | overrides and local state cache and forces all transmitters to the | ||
198 | RFKILL_STATE_SOFT_BLOCKED state (including those which are already | ||
199 | supposed to be BLOCKED). | ||
200 | * rfkill EPO will remain active until rfkill-input receives an | ||
201 | EV_SW SW_RFKILL_ALL 1 event. While the EPO is active, transmitters | ||
202 | are locked in the blocked state (rfkill will refuse to unblock them). | ||
203 | * rfkill-input implements different policies that the user can | ||
204 | select for handling EV_SW SW_RFKILL_ALL 1. It will unlock rfkill, | ||
205 | and either do nothing (leave transmitters blocked, but now unlocked), | ||
206 | restore the transmitters to their state before the EPO, or unblock | ||
207 | them all. | ||
208 | |||
209 | Userspace uevent handler or kernel platform-specific drivers hooked to the | ||
210 | rfkill notifier chain: | ||
211 | |||
212 | * Taps into the rfkill notifier chain or to KOBJ_CHANGE uevents, | ||
213 | in order to know when a device that is registered with the rfkill | ||
214 | class changes state; | ||
215 | * Issues feedback notifications to the user; | ||
216 | * In the rare platforms where this is required, synthesizes an input | ||
217 | event to command all *OTHER* rfkill devices to also change their | ||
218 | statues when a specific rfkill device changes state. | ||
219 | |||
220 | |||
221 | =============================================================================== | ||
222 | 3: Kernel driver guidelines | ||
223 | |||
224 | Remember: point-of-view is everything for a driver that connects to the rfkill | ||
225 | subsystem. All the details below must be measured/perceived from the point of | ||
226 | view of the specific driver being modified. | ||
227 | |||
228 | The first thing one needs to know is whether his driver should be talking to | ||
229 | the rfkill class or to the input layer. In rare cases (platform drivers), it | ||
230 | could happen that you need to do both, as platform drivers often handle a | ||
231 | variety of devices in the same driver. | ||
232 | |||
233 | Do not mistake input devices for rfkill controllers. The only type of "rfkill | ||
234 | switch" device that is to be registered with the rfkill class are those | ||
235 | directly controlling the circuits that cause a wireless transmitter to stop | ||
236 | working (or the software equivalent of them), i.e. what we call a rfkill | ||
237 | controller. Every other kind of "rfkill switch" is just an input device and | ||
238 | MUST NOT be registered with the rfkill class. | ||
239 | |||
240 | A driver should register a device with the rfkill class when ALL of the | ||
241 | following conditions are met (they define a rfkill controller): | ||
242 | |||
243 | 1. The device is/controls a data communications wireless transmitter; | ||
244 | |||
245 | 2. The kernel can interact with the hardware/firmware to CHANGE the wireless | ||
246 | transmitter state (block/unblock TX operation); | ||
247 | |||
248 | 3. The transmitter can be made to not emit any energy when "blocked": | ||
249 | rfkill is not about blocking data transmissions, it is about blocking | ||
250 | energy emission; | ||
251 | |||
252 | A driver should register a device with the input subsystem to issue | ||
253 | rfkill-related events (KEY_WLAN, KEY_BLUETOOTH, KEY_WWAN, KEY_WIMAX, | ||
254 | SW_RFKILL_ALL, etc) when ALL of the folowing conditions are met: | ||
255 | |||
256 | 1. It is directly related to some physical device the user interacts with, to | ||
257 | command the O.S./firmware/hardware to enable/disable a data communications | ||
258 | wireless transmitter. | ||
259 | |||
260 | Examples of the physical device are: buttons, keys and switches the user | ||
261 | will press/touch/slide/switch to enable or disable the wireless | ||
262 | communication device. | ||
263 | |||
264 | 2. It is NOT slaved to another device, i.e. there is no other device that | ||
265 | issues rfkill-related input events in preference to this one. | ||
266 | |||
267 | Please refer to the corner cases and examples section for more details. | ||
268 | |||
269 | When in doubt, do not issue input events. For drivers that should generate | ||
270 | input events in some platforms, but not in others (e.g. b43), the best solution | ||
271 | is to NEVER generate input events in the first place. That work should be | ||
272 | deferred to a platform-specific kernel module (which will know when to generate | ||
273 | events through the rfkill notifier chain) or to userspace. This avoids the | ||
274 | usual maintenance problems with DMI whitelisting. | ||
275 | |||
276 | |||
277 | Corner cases and examples: | ||
278 | ==================================== | ||
279 | |||
280 | 1. If the device is an input device that, because of hardware or firmware, | ||
281 | causes wireless transmitters to be blocked regardless of the kernel's will, it | ||
282 | is still just an input device, and NOT to be registered with the rfkill class. | ||
283 | |||
284 | 2. If the wireless transmitter switch control is read-only, it is an input | ||
285 | device and not to be registered with the rfkill class (and maybe not to be made | ||
286 | an input layer event source either, see below). | ||
287 | |||
288 | 3. If there is some other device driver *closer* to the actual hardware the | ||
289 | user interacted with (the button/switch/key) to issue an input event, THAT is | ||
290 | the device driver that should be issuing input events. | ||
291 | |||
292 | E.g: | ||
293 | [RFKILL slider switch] -- [GPIO hardware] -- [WLAN card rf-kill input] | ||
294 | (platform driver) (wireless card driver) | ||
295 | |||
296 | The user is closer to the RFKILL slide switch plaform driver, so the driver | ||
297 | which must issue input events is the platform driver looking at the GPIO | ||
298 | hardware, and NEVER the wireless card driver (which is just a slave). It is | ||
299 | very likely that there are other leaves than just the WLAN card rf-kill input | ||
300 | (e.g. a bluetooth card, etc)... | ||
301 | |||
302 | On the other hand, some embedded devices do this: | ||
303 | |||
304 | [RFKILL slider switch] -- [WLAN card rf-kill input] | ||
305 | (wireless card driver) | ||
306 | |||
307 | In this situation, the wireless card driver *could* register itself as an input | ||
308 | device and issue rf-kill related input events... but in order to AVOID the need | ||
309 | for DMI whitelisting, the wireless card driver does NOT do it. Userspace (HAL) | ||
310 | or a platform driver (that exists only on these embedded devices) will do the | ||
311 | dirty job of issuing the input events. | ||
312 | |||
313 | |||
314 | COMMON MISTAKES in kernel drivers, related to rfkill: | ||
315 | ==================================== | ||
316 | |||
317 | 1. NEVER confuse input device keys and buttons with input device switches. | ||
318 | |||
319 | 1a. Switches are always set or reset. They report the current state | ||
320 | (on position or off position). | ||
321 | |||
322 | 1b. Keys and buttons are either in the pressed or not-pressed state, and | ||
323 | that's it. A "button" that latches down when you press it, and | ||
324 | unlatches when you press it again is in fact a switch as far as input | ||
325 | devices go. | ||
326 | |||
327 | Add the SW_* events you need for switches, do NOT try to emulate a button using | ||
328 | KEY_* events just because there is no such SW_* event yet. Do NOT try to use, | ||
329 | for example, KEY_BLUETOOTH when you should be using SW_BLUETOOTH instead. | ||
330 | |||
331 | 2. Input device switches (sources of EV_SW events) DO store their current state | ||
332 | (so you *must* initialize it by issuing a gratuitous input layer event on | ||
333 | driver start-up and also when resuming from sleep), and that state CAN be | ||
334 | queried from userspace through IOCTLs. There is no sysfs interface for this, | ||
335 | but that doesn't mean you should break things trying to hook it to the rfkill | ||
336 | class to get a sysfs interface :-) | ||
337 | |||
338 | 3. Do not issue *_RFKILL_ALL events by default, unless you are sure it is the | ||
339 | correct event for your switch/button. These events are emergency power-off | ||
340 | events when they are trying to turn the transmitters off. An example of an | ||
341 | input device which SHOULD generate *_RFKILL_ALL events is the wireless-kill | ||
342 | switch in a laptop which is NOT a hotkey, but a real sliding/rocker switch. | ||
343 | An example of an input device which SHOULD NOT generate *_RFKILL_ALL events by | ||
344 | default, is any sort of hot key that is type-specific (e.g. the one for WLAN). | ||
345 | |||
346 | |||
347 | 3.1 Guidelines for wireless device drivers | ||
348 | ------------------------------------------ | ||
349 | |||
350 | (in this text, rfkill->foo means the foo field of struct rfkill). | ||
351 | |||
352 | 1. Each independent transmitter in a wireless device (usually there is only one | ||
353 | transmitter per device) should have a SINGLE rfkill class attached to it. | ||
354 | |||
355 | 2. If the device does not have any sort of hardware assistance to allow the | ||
356 | driver to rfkill the device, the driver should emulate it by taking all actions | ||
357 | required to silence the transmitter. | ||
358 | |||
359 | 3. If it is impossible to silence the transmitter (i.e. it still emits energy, | ||
360 | even if it is just in brief pulses, when there is no data to transmit and there | ||
361 | is no hardware support to turn it off) do NOT lie to the users. Do not attach | ||
362 | it to a rfkill class. The rfkill subsystem does not deal with data | ||
363 | transmission, it deals with energy emission. If the transmitter is emitting | ||
364 | energy, it is not blocked in rfkill terms. | ||
365 | |||
366 | 4. It doesn't matter if the device has multiple rfkill input lines affecting | ||
367 | the same transmitter, their combined state is to be exported as a single state | ||
368 | per transmitter (see rule 1). | ||
369 | |||
370 | This rule exists because users of the rfkill subsystem expect to get (and set, | ||
371 | when possible) the overall transmitter rfkill state, not of a particular rfkill | ||
372 | line. | ||
373 | 35 | ||
374 | 5. The wireless device driver MUST NOT leave the transmitter enabled during | 36 | The rfkill class code also notifies userspace of state changes, this is |
375 | suspend and hibernation unless: | 37 | achieved via uevents. It also provides some sysfs files for userspace to |
38 | check the status of radio transmitters. See the "Userspace support" section | ||
39 | below. | ||
376 | 40 | ||
377 | 5.1. The transmitter has to be enabled for some sort of functionality | ||
378 | like wake-on-wireless-packet or autonomous packed forwarding in a mesh | ||
379 | network, and that functionality is enabled for this suspend/hibernation | ||
380 | cycle. | ||
381 | 41 | ||
382 | AND | 42 | The rfkill-input code implements a basic response to rfkill buttons -- it |
43 | implements turning on/off all devices of a certain class (or all). | ||
383 | 44 | ||
384 | 5.2. The device was not on a user-requested BLOCKED state before | 45 | When the device is hard-blocked (either by a call to rfkill_set_hw_state() |
385 | the suspend (i.e. the driver must NOT unblock a device, not even | 46 | or from query_hw_block) set_block() will be invoked but drivers can well |
386 | to support wake-on-wireless-packet or remain in the mesh). | 47 | ignore the method call since they can use the return value of the function |
48 | rfkill_set_hw_state() to sync the software state instead of keeping track | ||
49 | of calls to set_block(). | ||
387 | 50 | ||
388 | In other words, there is absolutely no allowed scenario where a driver can | ||
389 | automatically take action to unblock a rfkill controller (obviously, this deals | ||
390 | with scenarios where soft-blocking or both soft and hard blocking is happening. | ||
391 | Scenarios where hardware rfkill lines are the only ones blocking the | ||
392 | transmitter are outside of this rule, since the wireless device driver does not | ||
393 | control its input hardware rfkill lines in the first place). | ||
394 | 51 | ||
395 | 6. During resume, rfkill will try to restore its previous state. | 52 | The entire functionality is spread over more than one subsystem: |
396 | 53 | ||
397 | 7. After a rfkill class is suspended, it will *not* call rfkill->toggle_radio | 54 | * The kernel input layer generates KEY_WWAN, KEY_WLAN etc. and |
398 | until it is resumed. | 55 | SW_RFKILL_ALL -- when the user presses a button. Drivers for radio |
56 | transmitters generally do not register to the input layer, unless the | ||
57 | device really provides an input device (i.e. a button that has no | ||
58 | effect other than generating a button press event) | ||
399 | 59 | ||
60 | * The rfkill-input code hooks up to these events and switches the soft-block | ||
61 | of the various radio transmitters, depending on the button type. | ||
400 | 62 | ||
401 | Example of a WLAN wireless driver connected to the rfkill subsystem: | 63 | * The rfkill drivers turn off/on their transmitters as requested. |
402 | -------------------------------------------------------------------- | ||
403 | 64 | ||
404 | A certain WLAN card has one input pin that causes it to block the transmitter | 65 | * The rfkill class will generate userspace notifications (uevents) to tell |
405 | and makes the status of that input pin available (only for reading!) to the | 66 | userspace what the current state is. |
406 | kernel driver. This is a hard rfkill input line (it cannot be overridden by | ||
407 | the kernel driver). | ||
408 | 67 | ||
409 | The card also has one PCI register that, if manipulated by the driver, causes | ||
410 | it to block the transmitter. This is a soft rfkill input line. | ||
411 | 68 | ||
412 | It has also a thermal protection circuitry that shuts down its transmitter if | ||
413 | the card overheats, and makes the status of that protection available (only for | ||
414 | reading!) to the kernel driver. This is also a hard rfkill input line. | ||
415 | 69 | ||
416 | If either one of these rfkill lines are active, the transmitter is blocked by | 70 | 3. Kernel driver guidelines |
417 | the hardware and forced offline. | ||
418 | 71 | ||
419 | The driver should allocate and attach to its struct device *ONE* instance of | ||
420 | the rfkill class (there is only one transmitter). | ||
421 | 72 | ||
422 | It can implement the get_state() hook, and return RFKILL_STATE_HARD_BLOCKED if | 73 | Drivers for radio transmitters normally implement only the rfkill class. |
423 | either one of its two hard rfkill input lines are active. If the two hard | 74 | These drivers may not unblock the transmitter based on own decisions, they |
424 | rfkill lines are inactive, it must return RFKILL_STATE_SOFT_BLOCKED if its soft | 75 | should act on information provided by the rfkill class only. |
425 | rfkill input line is active. Only if none of the rfkill input lines are | ||
426 | active, will it return RFKILL_STATE_UNBLOCKED. | ||
427 | 76 | ||
428 | Since the device has a hardware rfkill line, it IS subject to state changes | 77 | Platform drivers might implement input devices if the rfkill button is just |
429 | external to rfkill. Therefore, the driver must make sure that it calls | 78 | that, a button. If that button influences the hardware then you need to |
430 | rfkill_force_state() to keep the status always up-to-date, and it must do a | 79 | implement an rfkill class instead. This also applies if the platform provides |
431 | rfkill_force_state() on resume from sleep. | 80 | a way to turn on/off the transmitter(s). |
432 | 81 | ||
433 | Every time the driver gets a notification from the card that one of its rfkill | 82 | During suspend/hibernation, transmitters should only be left enabled when |
434 | lines changed state (polling might be needed on badly designed cards that don't | 83 | wake-on wlan or similar functionality requires it and the device wasn't |
435 | generate interrupts for such events), it recomputes the rfkill state as per | 84 | blocked before suspend/hibernate. Note that it may be necessary to update |
436 | above, and calls rfkill_force_state() to update it. | 85 | the rfkill subsystem's idea of what the current state is at resume time if |
86 | the state may have changed over suspend. | ||
437 | 87 | ||
438 | The driver should implement the toggle_radio() hook, that: | ||
439 | 88 | ||
440 | 1. Returns an error if one of the hardware rfkill lines are active, and the | ||
441 | caller asked for RFKILL_STATE_UNBLOCKED. | ||
442 | 89 | ||
443 | 2. Activates the soft rfkill line if the caller asked for state | 90 | 4. Kernel API |
444 | RFKILL_STATE_SOFT_BLOCKED. It should do this even if one of the hard rfkill | ||
445 | lines are active, effectively double-blocking the transmitter. | ||
446 | |||
447 | 3. Deactivates the soft rfkill line if none of the hardware rfkill lines are | ||
448 | active and the caller asked for RFKILL_STATE_UNBLOCKED. | ||
449 | |||
450 | =============================================================================== | ||
451 | 4: Kernel API | ||
452 | 91 | ||
453 | To build a driver with rfkill subsystem support, the driver should depend on | 92 | To build a driver with rfkill subsystem support, the driver should depend on |
454 | (or select) the Kconfig symbol RFKILL; it should _not_ depend on RKFILL_INPUT. | 93 | (or select) the Kconfig symbol RFKILL. |
455 | 94 | ||
456 | The hardware the driver talks to may be write-only (where the current state | 95 | The hardware the driver talks to may be write-only (where the current state |
457 | of the hardware is unknown), or read-write (where the hardware can be queried | 96 | of the hardware is unknown), or read-write (where the hardware can be queried |
458 | about its current state). | 97 | about its current state). |
459 | 98 | ||
460 | The rfkill class will call the get_state hook of a device every time it needs | 99 | Calling rfkill_set_hw_state() when a state change happens is required from |
461 | to know the *real* current state of the hardware. This can happen often, but | 100 | rfkill drivers that control devices that can be hard-blocked unless they also |
462 | it does not do any polling, so it is not enough on hardware that is subject | 101 | assign the poll_hw_block() callback (then the rfkill core will poll the |
463 | to state changes outside of the rfkill subsystem. | 102 | device). Don't do this unless you cannot get the event in any other way. |
464 | |||
465 | Therefore, calling rfkill_force_state() when a state change happens is | ||
466 | mandatory when the device has a hardware rfkill line, or when something else | ||
467 | like the firmware could cause its state to be changed without going through the | ||
468 | rfkill class. | ||
469 | |||
470 | Some hardware provides events when its status changes. In these cases, it is | ||
471 | best for the driver to not provide a get_state hook, and instead register the | ||
472 | rfkill class *already* with the correct status, and keep it updated using | ||
473 | rfkill_force_state() when it gets an event from the hardware. | ||
474 | |||
475 | rfkill_force_state() must be used on the device resume handlers to update the | ||
476 | rfkill status, should there be any chance of the device status changing during | ||
477 | the sleep. | ||
478 | |||
479 | There is no provision for a statically-allocated rfkill struct. You must | ||
480 | use rfkill_allocate() to allocate one. | ||
481 | |||
482 | You should: | ||
483 | - rfkill_allocate() | ||
484 | - modify rfkill fields (flags, name) | ||
485 | - modify state to the current hardware state (THIS IS THE ONLY TIME | ||
486 | YOU CAN ACCESS state DIRECTLY) | ||
487 | - rfkill_register() | ||
488 | 103 | ||
489 | The only way to set a device to the RFKILL_STATE_HARD_BLOCKED state is through | ||
490 | a suitable return of get_state() or through rfkill_force_state(). | ||
491 | 104 | ||
492 | When a device is in the RFKILL_STATE_HARD_BLOCKED state, the only way to switch | ||
493 | it to a different state is through a suitable return of get_state() or through | ||
494 | rfkill_force_state(). | ||
495 | 105 | ||
496 | If toggle_radio() is called to set a device to state RFKILL_STATE_SOFT_BLOCKED | 106 | 5. Userspace support |
497 | when that device is already at the RFKILL_STATE_HARD_BLOCKED state, it should | ||
498 | not return an error. Instead, it should try to double-block the transmitter, | ||
499 | so that its state will change from RFKILL_STATE_HARD_BLOCKED to | ||
500 | RFKILL_STATE_SOFT_BLOCKED should the hardware blocking cease. | ||
501 | |||
502 | Please refer to the source for more documentation. | ||
503 | |||
504 | =============================================================================== | ||
505 | 5: Userspace support | ||
506 | |||
507 | rfkill devices issue uevents (with an action of "change"), with the following | ||
508 | environment variables set: | ||
509 | |||
510 | RFKILL_NAME | ||
511 | RFKILL_STATE | ||
512 | RFKILL_TYPE | ||
513 | 107 | ||
514 | The ABI for these variables is defined by the sysfs attributes. It is best | 108 | The following sysfs entries exist for every rfkill device: |
515 | to take a quick look at the source to make sure of the possible values. | ||
516 | |||
517 | It is expected that HAL will trap those, and bridge them to DBUS, etc. These | ||
518 | events CAN and SHOULD be used to give feedback to the user about the rfkill | ||
519 | status of the system. | ||
520 | |||
521 | Input devices may issue events that are related to rfkill. These are the | ||
522 | various KEY_* events and SW_* events supported by rfkill-input.c. | ||
523 | |||
524 | Userspace may not change the state of an rfkill switch in response to an | ||
525 | input event, it should refrain from changing states entirely. | ||
526 | |||
527 | Userspace cannot assume it is the only source of control for rfkill switches. | ||
528 | Their state can change due to firmware actions, direct user actions, and the | ||
529 | rfkill-input EPO override for *_RFKILL_ALL. | ||
530 | |||
531 | When rfkill-input is not active, userspace must initiate a rfkill status | ||
532 | change by writing to the "state" attribute in order for anything to happen. | ||
533 | |||
534 | Take particular care to implement EV_SW SW_RFKILL_ALL properly. When that | ||
535 | switch is set to OFF, *every* rfkill device *MUST* be immediately put into the | ||
536 | RFKILL_STATE_SOFT_BLOCKED state, no questions asked. | ||
537 | |||
538 | The following sysfs entries will be created: | ||
539 | 109 | ||
540 | name: Name assigned by driver to this key (interface or driver name). | 110 | name: Name assigned by driver to this key (interface or driver name). |
541 | type: Name of the key type ("wlan", "bluetooth", etc). | 111 | type: Name of the key type ("wlan", "bluetooth", etc). |
542 | state: Current state of the transmitter | 112 | state: Current state of the transmitter |
543 | 0: RFKILL_STATE_SOFT_BLOCKED | 113 | 0: RFKILL_STATE_SOFT_BLOCKED |
544 | transmitter is forced off, but one can override it | 114 | transmitter is turned off by software |
545 | by a write to the state attribute; | ||
546 | 1: RFKILL_STATE_UNBLOCKED | 115 | 1: RFKILL_STATE_UNBLOCKED |
547 | transmiter is NOT forced off, and may operate if | 116 | transmiter is (potentially) active |
548 | all other conditions for such operation are met | ||
549 | (such as interface is up and configured, etc); | ||
550 | 2: RFKILL_STATE_HARD_BLOCKED | 117 | 2: RFKILL_STATE_HARD_BLOCKED |
551 | transmitter is forced off by something outside of | 118 | transmitter is forced off by something outside of |
552 | the driver's control. One cannot set a device to | 119 | the driver's control. |
553 | this state through writes to the state attribute; | 120 | claim: 0: Kernel handles events (currently always reads that value) |
554 | claim: 1: Userspace handles events, 0: Kernel handles events | 121 | |
555 | 122 | rfkill devices also issue uevents (with an action of "change"), with the | |
556 | Both the "state" and "claim" entries are also writable. For the "state" entry | 123 | following environment variables set: |
557 | this means that when 1 or 0 is written, the device rfkill state (if not yet in | 124 | |
558 | the requested state), will be will be toggled accordingly. | 125 | RFKILL_NAME |
559 | 126 | RFKILL_STATE | |
560 | For the "claim" entry writing 1 to it means that the kernel no longer handles | 127 | RFKILL_TYPE |
561 | key events even though RFKILL_INPUT input was enabled. When "claim" has been | 128 | |
562 | set to 0, userspace should make sure that it listens for the input events or | 129 | The contents of these variables corresponds to the "name", "state" and |
563 | check the sysfs "state" entry regularly to correctly perform the required tasks | 130 | "type" sysfs files explained above. |
564 | when the rkfill key is pressed. | ||
565 | |||
566 | A note about input devices and EV_SW events: | ||
567 | |||
568 | In order to know the current state of an input device switch (like | ||
569 | SW_RFKILL_ALL), you will need to use an IOCTL. That information is not | ||
570 | available through sysfs in a generic way at this time, and it is not available | ||
571 | through the rfkill class AT ALL. | ||