aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/rfkill.txt
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/rfkill.txt')
-rw-r--r--Documentation/rfkill.txt363
1 files changed, 308 insertions, 55 deletions
diff --git a/Documentation/rfkill.txt b/Documentation/rfkill.txt
index ec75d6d34785..cf230c1ad9ef 100644
--- a/Documentation/rfkill.txt
+++ b/Documentation/rfkill.txt
@@ -1,83 +1,328 @@
1rfkill - RF switch subsystem support 1rfkill - RF switch subsystem support
2==================================== 2====================================
3 3
41 Implementation details 41 Introduction
52 Driver support 52 Implementation details
63 Userspace support 63 Kernel driver guidelines
74 Kernel API
85 Userspace support
7 9
8=============================================================================== 10
91: Implementation details 111. Introduction:
10 12
11The rfkill switch subsystem exists to add a generic interface to circuitry that 13The rfkill switch subsystem exists to add a generic interface to circuitry that
12can enable or disable the RF output of a radio *transmitter* of any type. 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.
13 16
14When a rfkill switch is in the RFKILL_STATE_ON, the radio transmitter is 17The rfkill switch subsystem offers support for keys and switches often found on
15*enabled*. When the rfkill switch is in the RFKILL_STATE_OFF, the radio 18laptops to enable wireless devices like WiFi and Bluetooth to actually perform
16transmitter is *disabled*. 19an action.
17 20
18The rfkill switch subsystem offers support for keys often found on laptops 21The buttons to enable and disable the wireless transmitters are important in
19to enable wireless devices like WiFi and Bluetooth. 22situations where the user is for example using his laptop on a location where
23radio-frequency transmitters _must_ be disabled (e.g. airplanes).
20 24
21This is done by providing the user 3 possibilities: 25Because of this requirement, userspace support for the keys should not be made
22 1 - The rfkill system handles all events; userspace is not aware of events. 26mandatory. Because userspace might want to perform some additional smarter
23 2 - The rfkill system handles all events; userspace is informed about the events. 27tasks when the key is pressed, rfkill provides userspace the possibility to
24 3 - The rfkill system does not handle events; userspace handles all events. 28take over the task to handle the key events.
25 29
26The buttons to enable and disable the wireless radios are important in 30===============================================================================
27situations where the user is for example using his laptop on a location where 312: Implementation details
28wireless radios _must_ be disabled (e.g. airplanes). 32
29Because of this requirement, userspace support for the keys should not be 33The rfkill class provides kernel drivers with an interface that allows them to
30made mandatory. Because userspace might want to perform some additional smarter 34know when they should enable or disable a wireless network device transmitter.
31tasks when the key is pressed, rfkill still provides userspace the possibility 35
32to take over the task to handle the key events. 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.
33 48
34The system inside the kernel has been split into 2 separate sections: 49The system inside the kernel has been split into 2 separate sections:
35 1 - RFKILL 50 1 - RFKILL
36 2 - RFKILL_INPUT 51 2 - RFKILL_INPUT
37 52
38The first option enables rfkill support and will make sure userspace will 53The first option enables rfkill support and will make sure userspace will be
39be notified of any events through the input device. It also creates several 54notified of any events through uevents. It provides a notification chain for
40sysfs entries which can be used by userspace. See section "Userspace support". 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.
41 181
42The second option provides an rfkill input handler. This handler will 182When in doubt, do not issue input events. For drivers that should generate
43listen to all rfkill key events and will toggle the radio accordingly. 183input events in some platforms, but not in others (e.g. b43), the best solution
44With this option enabled userspace could either do nothing or simply 184is to NEVER generate input events in the first place. That work should be
45perform monitoring tasks. 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.
46 188
189
190Corner cases and examples:
47==================================== 191====================================
482: Driver support
49 192
50To build a driver with rfkill subsystem support, the driver should 1931. If the device is an input device that, because of hardware or firmware,
51depend on the Kconfig symbol RFKILL; it should _not_ depend on 194causes wireless transmitters to be blocked regardless of the kernel's will, it
52RKFILL_INPUT. 195is still just an input device, and NOT to be registered with the rfkill class.
53 196
54Unless key events trigger an interrupt to which the driver listens, polling 1972. If the wireless transmitter switch control is read-only, it is an input
55will be required to determine the key state changes. For this the input 198device and not to be registered with the rfkill class (and maybe not to be made
56layer providers the input-polldev handler. 199an input layer event source either, see below).
57 200
58A driver should implement a few steps to correctly make use of the 2013. If there is some other device driver *closer* to the actual hardware the
59rfkill subsystem. First for non-polling drivers: 202user interacted with (the button/switch/key) to issue an input event, THAT is
203the device driver that should be issuing input events.
60 204
61 - rfkill_allocate() 205E.g:
62 - input_allocate_device() 206 [RFKILL slider switch] -- [GPIO hardware] -- [WLAN card rf-kill input]
63 - rfkill_register() 207 (platform driver) (wireless card driver)
64 - input_register_device() 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.
65 276
66For polling drivers: 277There is no provision for a statically-allocated rfkill struct. You must
278use rfkill_allocate() to allocate one.
67 279
280You should:
68 - rfkill_allocate() 281 - rfkill_allocate()
69 - input_allocate_polled_device() 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)
70 - rfkill_register() 285 - rfkill_register()
71 - input_register_polled_device()
72 286
73When a key event has been detected, the correct event should be 287Please refer to the source for more documentation.
74sent over the input device which has been registered by the driver.
75 288
76==================================== 289===============================================================================
773: Userspace support 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
78 298
79For each key an input device will be created which will send out the correct 299The ABI for these variables is defined by the sysfs attributes. It is best
80key event when the rfkill key has been pressed. 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.
81 326
82The following sysfs entries will be created: 327The following sysfs entries will be created:
83 328
@@ -87,10 +332,18 @@ The following sysfs entries will be created:
87 claim: 1: Userspace handles events, 0: Kernel handles events 332 claim: 1: Userspace handles events, 0: Kernel handles events
88 333
89Both the "state" and "claim" entries are also writable. For the "state" entry 334Both the "state" and "claim" entries are also writable. For the "state" entry
90this means that when 1 or 0 is written all radios, not yet in the requested 335this means that when 1 or 0 is written, the device rfkill state (if not yet in
91state, will be will be toggled accordingly. 336the requested state), will be will be toggled accordingly.
337
92For the "claim" entry writing 1 to it means that the kernel no longer handles 338For the "claim" entry writing 1 to it means that the kernel no longer handles
93key events even though RFKILL_INPUT input was enabled. When "claim" has been 339key events even though RFKILL_INPUT input was enabled. When "claim" has been
94set to 0, userspace should make sure that it listens for the input events or 340set to 0, userspace should make sure that it listens for the input events or
95check the sysfs "state" entry regularly to correctly perform the required 341check the sysfs "state" entry regularly to correctly perform the required tasks
96tasks when the rkfill key is pressed. 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.