rfkill: document rw rfkill switches and clarify input subsystem interactions
[linux-2.6-block.git] / Documentation / rfkill.txt
CommitLineData
dac24ab3
ID
1rfkill - RF switch subsystem support
2====================================
3
dc288520
HMH
41 Introduction
52 Implementation details
63 Kernel driver guidelines
74 Kernel API
85 Userspace support
dac24ab3 9
dc288520
HMH
10
111. Introduction:
dac24ab3 12
f3146aff 13The rfkill switch subsystem exists to add a generic interface to circuitry that
dc288520
HMH
14can enable or disable the signal output of a wireless *transmitter* of any
15type. By far, the most common use is to disable radio-frequency transmitters.
f3146aff 16
dc288520
HMH
17The rfkill switch subsystem offers support for keys and switches often found on
18laptops to enable wireless devices like WiFi and Bluetooth to actually perform
19an action.
f3146aff 20
dc288520
HMH
21The buttons to enable and disable the wireless transmitters are important in
22situations where the user is for example using his laptop on a location where
23radio-frequency transmitters _must_ be disabled (e.g. airplanes).
dac24ab3 24
dc288520
HMH
25Because of this requirement, userspace support for the keys should not be made
26mandatory. Because userspace might want to perform some additional smarter
27tasks when the key is pressed, rfkill provides userspace the possibility to
28take over the task to handle the key events.
dac24ab3 29
dc288520
HMH
30===============================================================================
312: Implementation details
32
33The rfkill class provides kernel drivers with an interface that allows them to
34know when they should enable or disable a wireless network device transmitter.
35
36The rfkill-input module provides the kernel with the ability to implement a
37basic response when the user presses a key or button (or toggles a switch)
38related to rfkill functionality. It is an in-kernel implementation of default
39policy of reacting to rfkill-related input events and neither mandatory nor
40required for wireless drivers to operate.
41
42The rfkill-input module also provides EPO (emergency power-off) functionality
43for all wireless transmitters. This function cannot be overriden, and it is
44always active. rfkill EPO is related to *_RFKILL_ALL input events.
45
46All state changes on rfkill devices are propagated by the rfkill class to a
47notification chain and also to userspace through uevents.
dac24ab3
ID
48
49The system inside the kernel has been split into 2 separate sections:
50 1 - RFKILL
51 2 - RFKILL_INPUT
52
dc288520
HMH
53The first option enables rfkill support and will make sure userspace will be
54notified of any events through uevents. It provides a notification chain for
55interested parties in the kernel to also get notified of rfkill state changes
56in other drivers. It creates several sysfs entries which can be used by
57userspace. See section "Userspace support".
58
59The second option provides an rfkill input handler. This handler will listen to
60all rfkill key events and will toggle the radio accordingly. With this option
61enabled userspace could either do nothing or simply perform monitoring tasks.
62
63When a rfkill switch is in the RFKILL_STATE_ON, the wireless transmitter (radio
64TX circuit for example) is *enabled*. When the rfkill switch is in the
65RFKILL_STATE_OFF, the wireless transmitter is to be *blocked* from operating.
66
67Full rfkill functionality requires two different subsystems to cooperate: the
68input layer and the rfkill class. The input layer issues *commands* to the
69entire system requesting that devices registered to the rfkill class change
70state. The way this interaction happens is not complex, but it is not obvious
71either:
72
73Kernel Input layer:
74
75 * Generates KEY_WWAN, KEY_WLAN, KEY_BLUETOOTH, SW_RFKILL_ALL, and
76 other such events when the user presses certain keys, buttons, or
77 toggles certain physical switches.
78
79 THE INPUT LAYER IS NEVER USED TO PROPAGATE STATUS, NOTIFICATIONS OR THE
80 KIND OF STUFF AN ON-SCREEN-DISPLAY APPLICATION WOULD REPORT. It is
81 used to issue *commands* for the system to change behaviour, and these
82 commands may or may not be carried out by some kernel driver or
83 userspace application. It follows that doing user feedback based only
84 on input events is broken, there is no guarantee that an input event
85 will be acted upon.
86
87 Most wireless communication device drivers implementing rfkill
88 functionality MUST NOT generate these events, and have no reason to
89 register themselves with the input layer. This is a common
90 misconception. There is an API to propagate rfkill status change
91 information, and it is NOT the input layer.
92
93rfkill class:
94
95 * Calls a hook in a driver to effectively change the wireless
96 transmitter state;
97 * Keeps track of the wireless transmitter state (with help from
98 the driver);
99 * Generates userspace notifications (uevents) and a call to a
100 notification chain (kernel) when there is a wireless transmitter
101 state change;
102 * Connects a wireless communications driver with the common rfkill
103 control system, which, for example, allows actions such as
104 "switch all bluetooth devices offline" to be carried out by
105 userspace or by rfkill-input.
106
107 THE RFKILL CLASS NEVER ISSUES INPUT EVENTS. THE RFKILL CLASS DOES
108 NOT LISTEN TO INPUT EVENTS. NO DRIVER USING THE RFKILL CLASS SHALL
109 EVER LISTEN TO, OR ACT ON RFKILL INPUT EVENTS.
110
111 Most wireless data communication drivers in the kernel have just to
112 implement the rfkill class API to work properly. Interfacing to the
113 input layer is not often required (and is very often a *bug*).
114
115Userspace input handlers (uevents) or kernel input handlers (rfkill-input):
116
117 * Implements the policy of what should happen when one of the input
118 layer events related to rfkill operation is received.
119 * Uses the sysfs interface (userspace) or private rfkill API calls
120 to tell the devices registered with the rfkill class to change
121 their state (i.e. translates the input layer event into real
122 action).
123 * rfkill-input implements EPO by handling EV_SW SW_RFKILL_ALL 0
124 (power off all transmitters) in a special way: it ignores any
125 overrides and local state cache and forces all transmitters to
126 the OFF state (including those which are already supposed to be
127 OFF). Note that the opposite event (power on all transmitters)
128 is handled normally.
129
130Userspace uevent handler or kernel platform-specific drivers hooked to the
131rfkill notifier chain:
132
133 * Taps into the rfkill notifier chain or to KOBJ_CHANGE uevents,
134 in order to know when a device that is registered with the rfkill
135 class changes state;
136 * Issues feedback notifications to the user;
137 * In the rare platforms where this is required, synthesizes an input
138 event to command all *OTHER* rfkill devices to also change their
139 statues when a specific rfkill device changes state.
140
141
142===============================================================================
1433: Kernel driver guidelines
144
145The first thing one needs to know is whether his driver should be talking to
146the rfkill class or to the input layer.
147
148Do not mistake input devices for rfkill devices. The only type of "rfkill
149switch" device that is to be registered with the rfkill class are those
150directly controlling the circuits that cause a wireless transmitter to stop
151working (or the software equivalent of them). Every other kind of "rfkill
152switch" is just an input device and MUST NOT be registered with the rfkill
153class.
154
155A driver should register a device with the rfkill class when ALL of the
156following conditions are met:
157
1581. The device is/controls a data communications wireless transmitter;
159
1602. The kernel can interact with the hardware/firmware to CHANGE the wireless
161 transmitter state (block/unblock TX operation);
162
163A driver should register a device with the input subsystem to issue
164rfkill-related events (KEY_WLAN, KEY_BLUETOOTH, KEY_WWAN, KEY_WIMAX,
165SW_RFKILL_ALL, etc) when ALL of the folowing conditions are met:
166
1671. It is directly related to some physical device the user interacts with, to
168 command the O.S./firmware/hardware to enable/disable a data communications
169 wireless transmitter.
170
171 Examples of the physical device are: buttons, keys and switches the user
172 will press/touch/slide/switch to enable or disable the wireless
173 communication device.
174
1752. It is NOT slaved to another device, i.e. there is no other device that
176 issues rfkill-related input events in preference to this one.
177
178 Typically, the ACPI "radio kill" switch of a laptop is the master input
179 device to issue rfkill events, and, e.g., the WLAN card is just a slave
180 device that gets disabled by its hardware radio-kill input pin.
dac24ab3 181
dc288520
HMH
182When in doubt, do not issue input events. For drivers that should generate
183input events in some platforms, but not in others (e.g. b43), the best solution
184is to NEVER generate input events in the first place. That work should be
185deferred to a platform-specific kernel module (which will know when to generate
186events through the rfkill notifier chain) or to userspace. This avoids the
187usual maintenance problems with DMI whitelisting.
dac24ab3 188
dc288520
HMH
189
190Corner cases and examples:
dac24ab3 191====================================
dac24ab3 192
dc288520
HMH
1931. If the device is an input device that, because of hardware or firmware,
194causes wireless transmitters to be blocked regardless of the kernel's will, it
195is still just an input device, and NOT to be registered with the rfkill class.
dac24ab3 196
dc288520
HMH
1972. If the wireless transmitter switch control is read-only, it is an input
198device and not to be registered with the rfkill class (and maybe not to be made
199an input layer event source either, see below).
dac24ab3 200
dc288520
HMH
2013. If there is some other device driver *closer* to the actual hardware the
202user interacted with (the button/switch/key) to issue an input event, THAT is
203the device driver that should be issuing input events.
dac24ab3 204
dc288520
HMH
205E.g:
206 [RFKILL slider switch] -- [GPIO hardware] -- [WLAN card rf-kill input]
207 (platform driver) (wireless card driver)
208
209The user is closer to the RFKILL slide switch plaform driver, so the driver
210which must issue input events is the platform driver looking at the GPIO
211hardware, and NEVER the wireless card driver (which is just a slave). It is
212very likely that there are other leaves than just the WLAN card rf-kill input
213(e.g. a bluetooth card, etc)...
214
215On the other hand, some embedded devices do this:
216
217 [RFKILL slider switch] -- [WLAN card rf-kill input]
218 (wireless card driver)
219
220In this situation, the wireless card driver *could* register itself as an input
221device and issue rf-kill related input events... but in order to AVOID the need
222for DMI whitelisting, the wireless card driver does NOT do it. Userspace (HAL)
223or a platform driver (that exists only on these embedded devices) will do the
224dirty job of issuing the input events.
225
226
227COMMON MISTAKES in kernel drivers, related to rfkill:
228====================================
229
2301. NEVER confuse input device keys and buttons with input device switches.
231
232 1a. Switches are always set or reset. They report the current state
233 (on position or off position).
234
235 1b. Keys and buttons are either in the pressed or not-pressed state, and
236 that's it. A "button" that latches down when you press it, and
237 unlatches when you press it again is in fact a switch as far as input
238 devices go.
239
240Add the SW_* events you need for switches, do NOT try to emulate a button using
241KEY_* events just because there is no such SW_* event yet. Do NOT try to use,
242for example, KEY_BLUETOOTH when you should be using SW_BLUETOOTH instead.
243
2442. Input device switches (sources of EV_SW events) DO store their current
245state, and that state CAN be queried from userspace through IOCTLs. There is
246no sysfs interface for this, but that doesn't mean you should break things
247trying to hook it to the rfkill class to get a sysfs interface :-)
248
2493. Do not issue *_RFKILL_ALL events, unless you are sure it is the correct
250event for your switch/button. These events are emergency power-off events when
251they are trying to turn the transmitters off. An example of an input device
252which SHOULD generate *_RFKILL_ALL events is the wireless-kill switch in a
253laptop which is NOT a hotkey, but a real switch that kills radios in hardware,
254even if the O.S. has gone to lunch. An example of an input device which SHOULD
255NOT generate *_RFKILL_ALL events is any sort of hot key that does nothing by
256itself, as well as any hot key that is type-specific (e.g. the one for WLAN).
257
258
259===============================================================================
2604: Kernel API
261
262To build a driver with rfkill subsystem support, the driver should depend on
263the Kconfig symbol RFKILL; it should _not_ depend on RKFILL_INPUT.
264
265The hardware the driver talks to may be write-only (where the current state
266of the hardware is unknown), or read-write (where the hardware can be queried
267about its current state).
268
269The rfkill class will call the get_state hook of a device every time it needs
270to know the *real* current state of the hardware. This can happen often.
271
272Some hardware provides events when its status changes. In these cases, it is
273best for the driver to not provide a get_state hook, and instead register the
274rfkill class *already* with the correct status, and keep it updated using
275rfkill_force_state() when it gets an event from the hardware.
dac24ab3 276
dc288520
HMH
277There is no provision for a statically-allocated rfkill struct. You must
278use rfkill_allocate() to allocate one.
dac24ab3 279
dc288520 280You should:
dac24ab3 281 - rfkill_allocate()
dc288520
HMH
282 - modify rfkill fields (flags, name)
283 - modify state to the current hardware state (THIS IS THE ONLY TIME
284 YOU CAN ACCESS state DIRECTLY)
dac24ab3 285 - rfkill_register()
dac24ab3 286
dc288520 287Please refer to the source for more documentation.
dac24ab3 288
dc288520
HMH
289===============================================================================
2905: Userspace support
291
292rfkill devices issue uevents (with an action of "change"), with the following
293environment variables set:
294
295RFKILL_NAME
296RFKILL_STATE
297RFKILL_TYPE
dac24ab3 298
dc288520
HMH
299The ABI for these variables is defined by the sysfs attributes. It is best
300to take a quick look at the source to make sure of the possible values.
301
302It is expected that HAL will trap those, and bridge them to DBUS, etc. These
303events CAN and SHOULD be used to give feedback to the user about the rfkill
304status of the system.
305
306Input devices may issue events that are related to rfkill. These are the
307various KEY_* events and SW_* events supported by rfkill-input.c.
308
309******IMPORTANT******
310When rfkill-input is ACTIVE, userspace is NOT TO CHANGE THE STATE OF AN RFKILL
311SWITCH IN RESPONSE TO AN INPUT EVENT also handled by rfkill-input, unless it
312has set to true the user_claim attribute for that particular switch. This rule
313is *absolute*; do NOT violate it.
314******IMPORTANT******
315
316Userspace must not assume it is the only source of control for rfkill switches.
317Their state CAN and WILL change on its own, due to firmware actions, direct
318user actions, and the rfkill-input EPO override for *_RFKILL_ALL.
319
320When rfkill-input is not active, userspace must initiate an rfkill status
321change by writing to the "state" attribute in order for anything to happen.
322
323Take particular care to implement EV_SW SW_RFKILL_ALL properly. When that
324switch is set to OFF, *every* rfkill device *MUST* be immediately put into the
325OFF state, no questions asked.
dac24ab3
ID
326
327The following sysfs entries will be created:
328
329 name: Name assigned by driver to this key (interface or driver name).
330 type: Name of the key type ("wlan", "bluetooth", etc).
331 state: Current state of the key. 1: On, 0: Off.
332 claim: 1: Userspace handles events, 0: Kernel handles events
333
334Both the "state" and "claim" entries are also writable. For the "state" entry
dc288520
HMH
335this means that when 1 or 0 is written, the device rfkill state (if not yet in
336the requested state), will be will be toggled accordingly.
337
dac24ab3
ID
338For the "claim" entry writing 1 to it means that the kernel no longer handles
339key events even though RFKILL_INPUT input was enabled. When "claim" has been
340set to 0, userspace should make sure that it listens for the input events or
dc288520
HMH
341check the sysfs "state" entry regularly to correctly perform the required tasks
342when the rkfill key is pressed.
343
344A note about input devices and EV_SW events:
345
346In order to know the current state of an input device switch (like
347SW_RFKILL_ALL), you will need to use an IOCTL. That information is not
348available through sysfs in a generic way at this time, and it is not available
349through the rfkill class AT ALL.