aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/rfkill.txt
diff options
context:
space:
mode:
authorHenrique de Moraes Holschuh <hmh@hmh.eng.br>2008-06-23 16:46:43 -0400
committerJohn W. Linville <linville@tuxdriver.com>2008-06-26 14:21:22 -0400
commitf7983f7301d530cb3f3a02618c944f6d108d11df (patch)
tree2e9fda4ae35c127db018634fa084641d0e8c9200 /Documentation/rfkill.txt
parent5005657cbd0fd6f277f807c0612a6b6d4396a02c (diff)
rfkill: improve documentation for kernel drivers
Improve the documentation of how to use the rfkill class in kernel drivers, based on the doubts that came up in a thread in linux-wireless. Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br> Acked-by: Ivo van Doorn <IvDoorn@gmail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'Documentation/rfkill.txt')
-rw-r--r--Documentation/rfkill.txt261
1 files changed, 201 insertions, 60 deletions
diff --git a/Documentation/rfkill.txt b/Documentation/rfkill.txt
index 5316cea95ce0..0843ed0163a5 100644
--- a/Documentation/rfkill.txt
+++ b/Documentation/rfkill.txt
@@ -4,6 +4,9 @@ rfkill - RF switch subsystem support
41 Introduction 41 Introduction
52 Implementation details 52 Implementation details
63 Kernel driver guidelines 63 Kernel driver guidelines
73.1 wireless device drivers
83.2 platform/switch drivers
93.3 input device drivers
74 Kernel API 104 Kernel API
85 Userspace support 115 Userspace support
9 12
@@ -14,9 +17,14 @@ The rfkill switch subsystem exists to add a generic interface to circuitry that
14can enable or disable the signal output of a wireless *transmitter* of any 17can 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. 18type. By far, the most common use is to disable radio-frequency transmitters.
16 19
17The rfkill switch subsystem offers support for keys and switches often found on 20Note that disabling the signal output means that the the transmitter is to be
18laptops to enable wireless devices like WiFi and Bluetooth to actually perform 21made to not emit any energy when "blocked". rfkill is not about blocking data
19an action. 22transmissions, it is about blocking energy emission.
23
24The rfkill subsystem offers support for keys and switches often found on
25laptops to enable wireless devices like WiFi and Bluetooth, so that these keys
26and switches actually perform an action in all wireless devices of a given type
27attached to the system.
20 28
21The buttons to enable and disable the wireless transmitters are important in 29The 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 30situations where the user is for example using his laptop on a location where
@@ -30,40 +38,81 @@ take over the task to handle the key events.
30=============================================================================== 38===============================================================================
312: Implementation details 392: Implementation details
32 40
41The rfkill subsystem is composed of various components: the rfkill class, the
42rfkill-input module (an input layer handler), and some specific input layer
43events.
44
33The rfkill class provides kernel drivers with an interface that allows them to 45The rfkill class provides kernel drivers with an interface that allows them to
34know when they should enable or disable a wireless network device transmitter. 46know when they should enable or disable a wireless network device transmitter.
47This is enabled by the CONFIG_RFKILL Kconfig option.
48
49The rfkill class support makes sure userspace will be notified of all state
50changes on rfkill devices through uevents. It provides a notification chain
51for interested parties in the kernel to also get notified of rfkill state
52changes in other drivers. It creates several sysfs entries which can be used
53by userspace. See section "Userspace support".
35 54
36The rfkill-input module provides the kernel with the ability to implement a 55The 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) 56basic 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 57related to rfkill functionality. It is an in-kernel implementation of default
39policy of reacting to rfkill-related input events and neither mandatory nor 58policy of reacting to rfkill-related input events and neither mandatory nor
40required for wireless drivers to operate. 59required for wireless drivers to operate. It is enabled by the
60CONFIG_RFKILL_INPUT Kconfig option.
61
62rfkill-input is a rfkill-related events input layer handler. This handler will
63listen to all rfkill key events and will change the rfkill state of the
64wireless devices accordingly. With this option enabled userspace could either
65do nothing or simply perform monitoring tasks.
41 66
42The rfkill-input module also provides EPO (emergency power-off) functionality 67The rfkill-input module also provides EPO (emergency power-off) functionality
43for all wireless transmitters. This function cannot be overriden, and it is 68for all wireless transmitters. This function cannot be overridden, and it is
44always active. rfkill EPO is related to *_RFKILL_ALL input events. 69always active. rfkill EPO is related to *_RFKILL_ALL input layer events.
70
71
72Important terms for the rfkill subsystem:
73
74In order to avoid confusion, we avoid the term "switch" in rfkill when it is
75referring to an electronic control circuit that enables or disables a
76transmitter. We reserve it for the physical device a human manipulates
77(which is an input device, by the way):
78
79rfkill 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
85rfkill controller:
45 86
46All state changes on rfkill devices are propagated by the rfkill class to a 87 A hardware circuit that controls the state of a rfkill line, which a
47notification chain and also to userspace through uevents. 88 kernel driver can interact with *to modify* that state (i.e. it has
89 either write-only or read/write access).
48 90
49The system inside the kernel has been split into 2 separate sections: 91rfkill line:
50 1 - RFKILL
51 2 - RFKILL_INPUT
52 92
53The first option enables rfkill support and will make sure userspace will be 93 An input channel (hardware or software) of a wireless device, which
54notified of any events through uevents. It provides a notification chain for 94 causes a wireless transmitter to stop emitting energy (BLOCK) when it
55interested parties in the kernel to also get notified of rfkill state changes 95 is active. Point of view is extremely important here: rfkill lines are
56in other drivers. It creates several sysfs entries which can be used by 96 always seen from the PoV of a wireless device (and its driver).
57userspace. See section "Userspace support".
58 97
59The second option provides an rfkill input handler. This handler will listen to 98soft rfkill line/software rfkill line:
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 99
63When a rfkill switch is in the RFKILL_STATE_UNBLOCKED, the wireless transmitter 100 A rfkill line the wireless device driver can directly change the state
64(radio TX circuit for example) is *enabled*. When the rfkill switch is in the 101 of. Related to rfkill_state RFKILL_STATE_SOFT_BLOCKED.
65RFKILL_STATE_SOFT_BLOCKED or RFKILL_STATE_HARD_BLOCKED, the wireless 102
66transmitter is to be *blocked* from operating. 103hard 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
110The enum rfkill_state describes the rfkill state of a transmitter:
111
112When a rfkill line or rfkill controller is in the RFKILL_STATE_UNBLOCKED state,
113the wireless transmitter (radio TX circuit for example) is *enabled*. When the
114it is in the RFKILL_STATE_SOFT_BLOCKED or RFKILL_STATE_HARD_BLOCKED, the
115wireless transmitter is to be *blocked* from operating.
67 116
68RFKILL_STATE_SOFT_BLOCKED indicates that a call to toggle_radio() can change 117RFKILL_STATE_SOFT_BLOCKED indicates that a call to toggle_radio() can change
69that state. RFKILL_STATE_HARD_BLOCKED indicates that a call to toggle_radio() 118that state. RFKILL_STATE_HARD_BLOCKED indicates that a call to toggle_radio()
@@ -92,12 +141,12 @@ Kernel Input layer:
92 used to issue *commands* for the system to change behaviour, and these 141 used to issue *commands* for the system to change behaviour, and these
93 commands may or may not be carried out by some kernel driver or 142 commands may or may not be carried out by some kernel driver or
94 userspace application. It follows that doing user feedback based only 143 userspace application. It follows that doing user feedback based only
95 on input events is broken, there is no guarantee that an input event 144 on input events is broken, as there is no guarantee that an input event
96 will be acted upon. 145 will be acted upon.
97 146
98 Most wireless communication device drivers implementing rfkill 147 Most wireless communication device drivers implementing rfkill
99 functionality MUST NOT generate these events, and have no reason to 148 functionality MUST NOT generate these events, and have no reason to
100 register themselves with the input layer. This is a common 149 register themselves with the input layer. Doing otherwise is a common
101 misconception. There is an API to propagate rfkill status change 150 misconception. There is an API to propagate rfkill status change
102 information, and it is NOT the input layer. 151 information, and it is NOT the input layer.
103 152
@@ -117,11 +166,22 @@ rfkill class:
117 166
118 THE RFKILL CLASS NEVER ISSUES INPUT EVENTS. THE RFKILL CLASS DOES 167 THE RFKILL CLASS NEVER ISSUES INPUT EVENTS. THE RFKILL CLASS DOES
119 NOT LISTEN TO INPUT EVENTS. NO DRIVER USING THE RFKILL CLASS SHALL 168 NOT LISTEN TO INPUT EVENTS. NO DRIVER USING THE RFKILL CLASS SHALL
120 EVER LISTEN TO, OR ACT ON RFKILL INPUT EVENTS. 169 EVER LISTEN TO, OR ACT ON RFKILL INPUT EVENTS. Doing otherwise is
170 a layering violation.
121 171
122 Most wireless data communication drivers in the kernel have just to 172 Most wireless data communication drivers in the kernel have just to
123 implement the rfkill class API to work properly. Interfacing to the 173 implement the rfkill class API to work properly. Interfacing to the
124 input layer is not often required (and is very often a *bug*). 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
125 185
126Userspace input handlers (uevents) or kernel input handlers (rfkill-input): 186Userspace input handlers (uevents) or kernel input handlers (rfkill-input):
127 187
@@ -153,24 +213,34 @@ rfkill notifier chain:
153=============================================================================== 213===============================================================================
1543: Kernel driver guidelines 2143: Kernel driver guidelines
155 215
216Remember: point-of-view is everything for a driver that connects to the rfkill
217subsystem. All the details below must be measured/perceived from the point of
218view of the specific driver being modified.
219
156The first thing one needs to know is whether his driver should be talking to 220The first thing one needs to know is whether his driver should be talking to
157the rfkill class or to the input layer. 221the rfkill class or to the input layer. In rare cases (platform drivers), it
222could happen that you need to do both, as platform drivers often handle a
223variety of devices in the same driver.
158 224
159Do not mistake input devices for rfkill devices. The only type of "rfkill 225Do not mistake input devices for rfkill controllers. The only type of "rfkill
160switch" device that is to be registered with the rfkill class are those 226switch" device that is to be registered with the rfkill class are those
161directly controlling the circuits that cause a wireless transmitter to stop 227directly controlling the circuits that cause a wireless transmitter to stop
162working (or the software equivalent of them). Every other kind of "rfkill 228working (or the software equivalent of them), i.e. what we call a rfkill
163switch" is just an input device and MUST NOT be registered with the rfkill 229controller. Every other kind of "rfkill switch" is just an input device and
164class. 230MUST NOT be registered with the rfkill class.
165 231
166A driver should register a device with the rfkill class when ALL of the 232A driver should register a device with the rfkill class when ALL of the
167following conditions are met: 233following conditions are met (they define a rfkill controller):
168 234
1691. The device is/controls a data communications wireless transmitter; 2351. The device is/controls a data communications wireless transmitter;
170 236
1712. The kernel can interact with the hardware/firmware to CHANGE the wireless 2372. The kernel can interact with the hardware/firmware to CHANGE the wireless
172 transmitter state (block/unblock TX operation); 238 transmitter state (block/unblock TX operation);
173 239
2403. The transmitter can be made to not emit any energy when "blocked":
241 rfkill is not about blocking data transmissions, it is about blocking
242 energy emission;
243
174A driver should register a device with the input subsystem to issue 244A driver should register a device with the input subsystem to issue
175rfkill-related events (KEY_WLAN, KEY_BLUETOOTH, KEY_WWAN, KEY_WIMAX, 245rfkill-related events (KEY_WLAN, KEY_BLUETOOTH, KEY_WWAN, KEY_WIMAX,
176SW_RFKILL_ALL, etc) when ALL of the folowing conditions are met: 246SW_RFKILL_ALL, etc) when ALL of the folowing conditions are met:
@@ -186,9 +256,7 @@ SW_RFKILL_ALL, etc) when ALL of the folowing conditions are met:
1862. It is NOT slaved to another device, i.e. there is no other device that 2562. It is NOT slaved to another device, i.e. there is no other device that
187 issues rfkill-related input events in preference to this one. 257 issues rfkill-related input events in preference to this one.
188 258
189 Typically, the ACPI "radio kill" switch of a laptop is the master input 259 Please refer to the corner cases and examples section for more details.
190 device to issue rfkill events, and, e.g., the WLAN card is just a slave
191 device that gets disabled by its hardware radio-kill input pin.
192 260
193When in doubt, do not issue input events. For drivers that should generate 261When in doubt, do not issue input events. For drivers that should generate
194input events in some platforms, but not in others (e.g. b43), the best solution 262input events in some platforms, but not in others (e.g. b43), the best solution
@@ -252,26 +320,102 @@ Add the SW_* events you need for switches, do NOT try to emulate a button using
252KEY_* events just because there is no such SW_* event yet. Do NOT try to use, 320KEY_* events just because there is no such SW_* event yet. Do NOT try to use,
253for example, KEY_BLUETOOTH when you should be using SW_BLUETOOTH instead. 321for example, KEY_BLUETOOTH when you should be using SW_BLUETOOTH instead.
254 322
2552. Input device switches (sources of EV_SW events) DO store their current 3232. Input device switches (sources of EV_SW events) DO store their current state
256state, and that state CAN be queried from userspace through IOCTLs. There is 324(so you *must* initialize it by issuing a gratuitous input layer event on
257no sysfs interface for this, but that doesn't mean you should break things 325driver start-up and also when resuming from sleep), and that state CAN be
258trying to hook it to the rfkill class to get a sysfs interface :-) 326queried from userspace through IOCTLs. There is no sysfs interface for this,
327but that doesn't mean you should break things trying to hook it to the rfkill
328class to get a sysfs interface :-)
329
3303. Do not issue *_RFKILL_ALL events by default, unless you are sure it is the
331correct event for your switch/button. These events are emergency power-off
332events when they are trying to turn the transmitters off. An example of an
333input device which SHOULD generate *_RFKILL_ALL events is the wireless-kill
334switch in a laptop which is NOT a hotkey, but a real switch that kills radios
335in hardware, even if the O.S. has gone to lunch. An example of an input device
336which SHOULD NOT generate *_RFKILL_ALL events by default, is any sort of hot
337key that does nothing by itself, as well as any hot key that is type-specific
338(e.g. the one for WLAN).
259 339
2603. Do not issue *_RFKILL_ALL events, unless you are sure it is the correct
261event for your switch/button. These events are emergency power-off events when
262they are trying to turn the transmitters off. An example of an input device
263which SHOULD generate *_RFKILL_ALL events is the wireless-kill switch in a
264laptop which is NOT a hotkey, but a real switch that kills radios in hardware,
265even if the O.S. has gone to lunch. An example of an input device which SHOULD
266NOT generate *_RFKILL_ALL events is any sort of hot key that does nothing by
267itself, as well as any hot key that is type-specific (e.g. the one for WLAN).
268 340
3413.1 Guidelines for wireless device drivers
342------------------------------------------
343
3441. Each independent transmitter in a wireless device (usually there is only one
345transmitter per device) should have a SINGLE rfkill class attached to it.
346
3472. If the device does not have any sort of hardware assistance to allow the
348driver to rfkill the device, the driver should emulate it by taking all actions
349required to silence the transmitter.
350
3513. If it is impossible to silence the transmitter (i.e. it still emits energy,
352even if it is just in brief pulses, when there is no data to transmit and there
353is no hardware support to turn it off) do NOT lie to the users. Do not attach
354it to a rfkill class. The rfkill subsystem does not deal with data
355transmission, it deals with energy emission. If the transmitter is emitting
356energy, it is not blocked in rfkill terms.
357
3584. It doesn't matter if the device has multiple rfkill input lines affecting
359the same transmitter, their combined state is to be exported as a single state
360per transmitter (see rule 1).
361
362This rule exists because users of the rfkill subsystem expect to get (and set,
363when possible) the overall transmitter rfkill state, not of a particular rfkill
364line.
365
366Example of a WLAN wireless driver connected to the rfkill subsystem:
367--------------------------------------------------------------------
368
369A certain WLAN card has one input pin that causes it to block the transmitter
370and makes the status of that input pin available (only for reading!) to the
371kernel driver. This is a hard rfkill input line (it cannot be overridden by
372the kernel driver).
373
374The card also has one PCI register that, if manipulated by the driver, causes
375it to block the transmitter. This is a soft rfkill input line.
376
377It has also a thermal protection circuitry that shuts down its transmitter if
378the card overheats, and makes the status of that protection available (only for
379reading!) to the kernel driver. This is also a hard rfkill input line.
380
381If either one of these rfkill lines are active, the transmitter is blocked by
382the hardware and forced offline.
383
384The driver should allocate and attach to its struct device *ONE* instance of
385the rfkill class (there is only one transmitter).
386
387It can implement the get_state() hook, and return RFKILL_STATE_HARD_BLOCKED if
388either one of its two hard rfkill input lines are active. If the two hard
389rfkill lines are inactive, it must return RFKILL_STATE_SOFT_BLOCKED if its soft
390rfkill input line is active. Only if none of the rfkill input lines are
391active, will it return RFKILL_STATE_UNBLOCKED.
392
393If it doesn't implement the get_state() hook, it must make sure that its calls
394to rfkill_force_state() are enough to keep the status always up-to-date, and it
395must do a rfkill_force_state() on resume from sleep.
396
397Every time the driver gets a notification from the card that one of its rfkill
398lines changed state (polling might be needed on badly designed cards that don't
399generate interrupts for such events), it recomputes the rfkill state as per
400above, and calls rfkill_force_state() to update it.
401
402The driver should implement the toggle_radio() hook, that:
403
4041. Returns an error if one of the hardware rfkill lines are active, and the
405caller asked for RFKILL_STATE_UNBLOCKED.
406
4072. Activates the soft rfkill line if the caller asked for state
408RFKILL_STATE_SOFT_BLOCKED. It should do this even if one of the hard rfkill
409lines are active, effectively double-blocking the transmitter.
410
4113. Deactivates the soft rfkill line if none of the hardware rfkill lines are
412active and the caller asked for RFKILL_STATE_UNBLOCKED.
269 413
270=============================================================================== 414===============================================================================
2714: Kernel API 4154: Kernel API
272 416
273To build a driver with rfkill subsystem support, the driver should depend on 417To build a driver with rfkill subsystem support, the driver should depend on
274the Kconfig symbol RFKILL; it should _not_ depend on RKFILL_INPUT. 418(or select) the Kconfig symbol RFKILL; it should _not_ depend on RKFILL_INPUT.
275 419
276The hardware the driver talks to may be write-only (where the current state 420The hardware the driver talks to may be write-only (where the current state
277of the hardware is unknown), or read-write (where the hardware can be queried 421of the hardware is unknown), or read-write (where the hardware can be queried
@@ -338,10 +482,10 @@ is *absolute*; do NOT violate it.
338******IMPORTANT****** 482******IMPORTANT******
339 483
340Userspace must not assume it is the only source of control for rfkill switches. 484Userspace must not assume it is the only source of control for rfkill switches.
341Their state CAN and WILL change on its own, due to firmware actions, direct 485Their state CAN and WILL change due to firmware actions, direct user actions,
342user actions, and the rfkill-input EPO override for *_RFKILL_ALL. 486and the rfkill-input EPO override for *_RFKILL_ALL.
343 487
344When rfkill-input is not active, userspace must initiate an rfkill status 488When rfkill-input is not active, userspace must initiate a rfkill status
345change by writing to the "state" attribute in order for anything to happen. 489change by writing to the "state" attribute in order for anything to happen.
346 490
347Take particular care to implement EV_SW SW_RFKILL_ALL properly. When that 491Take particular care to implement EV_SW SW_RFKILL_ALL properly. When that
@@ -354,19 +498,16 @@ The following sysfs entries will be created:
354 type: Name of the key type ("wlan", "bluetooth", etc). 498 type: Name of the key type ("wlan", "bluetooth", etc).
355 state: Current state of the transmitter 499 state: Current state of the transmitter
356 0: RFKILL_STATE_SOFT_BLOCKED 500 0: RFKILL_STATE_SOFT_BLOCKED
357 transmitter is forced off, but you can override it 501 transmitter is forced off, but one can override it
358 by a write to the state attribute, or through input 502 by a write to the state attribute;
359 events (if rfkill-input is loaded).
360 1: RFKILL_STATE_UNBLOCKED 503 1: RFKILL_STATE_UNBLOCKED
361 transmiter is NOT forced off, and may operate if 504 transmiter is NOT forced off, and may operate if
362 all other conditions for such operation are met 505 all other conditions for such operation are met
363 (such as interface is up and configured, etc). 506 (such as interface is up and configured, etc);
364 2: RFKILL_STATE_HARD_BLOCKED 507 2: RFKILL_STATE_HARD_BLOCKED
365 transmitter is forced off by something outside of 508 transmitter is forced off by something outside of
366 the driver's control. 509 the driver's control. One cannot set a device to
367 510 this state through writes to the state attribute;
368 You cannot set a device to this state through
369 writes to the state attribute.
370 claim: 1: Userspace handles events, 0: Kernel handles events 511 claim: 1: Userspace handles events, 0: Kernel handles events
371 512
372Both the "state" and "claim" entries are also writable. For the "state" entry 513Both the "state" and "claim" entries are also writable. For the "state" entry