linux/Documentation/rfkill.txt
<<
>>
Prefs
   1rfkill - RF switch subsystem support
   2====================================
   3
   41 Introduction
   52 Implementation details
   63 Kernel driver guidelines
   73.1 wireless device drivers
   83.2 platform/switch drivers
   93.3 input device drivers
  104 Kernel API
  115 Userspace support
  12
  13
  141. Introduction:
  15
  16The rfkill switch subsystem exists to add a generic interface to circuitry that
  17can enable or disable the signal output of a wireless *transmitter* of any
  18type.  By far, the most common use is to disable radio-frequency transmitters.
  19
  20Note that disabling the signal output means that the the transmitter is to be
  21made to not emit any energy when "blocked".  rfkill is not about blocking data
  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.
  28
  29The buttons to enable and disable the wireless transmitters are important in
  30situations where the user is for example using his laptop on a location where
  31radio-frequency transmitters _must_ be disabled (e.g. airplanes).
  32
  33Because of this requirement, userspace support for the keys should not be made
  34mandatory.  Because userspace might want to perform some additional smarter
  35tasks when the key is pressed, rfkill provides userspace the possibility to
  36take over the task to handle the key events.
  37
  38===============================================================================
  392: Implementation details
  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
  45The rfkill class provides kernel drivers with an interface that allows them to
  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".
  54
  55The rfkill-input module provides the kernel with the ability to implement a
  56basic response when the user presses a key or button (or toggles a switch)
  57related to rfkill functionality.  It is an in-kernel implementation of default
  58policy of reacting to rfkill-related input events and neither mandatory nor
  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.
  66
  67The rfkill-input module also provides EPO (emergency power-off) functionality
  68for all wireless transmitters.  This function cannot be overridden, and it is
  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:
  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
  91rfkill 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
  98soft 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
 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.
 116
 117RFKILL_STATE_SOFT_BLOCKED indicates that a call to toggle_radio() can change
 118that state.  RFKILL_STATE_HARD_BLOCKED indicates that a call to toggle_radio()
 119will not be able to change the state and will return with a suitable error if
 120attempts are made to set the state to RFKILL_STATE_UNBLOCKED.
 121
 122RFKILL_STATE_HARD_BLOCKED is used by drivers to signal that the device is
 123locked in the BLOCKED state by a hardwire rfkill line (typically an input pin
 124that, when active, forces the transmitter to be disabled) which the driver
 125CANNOT override.
 126
 127Full rfkill functionality requires two different subsystems to cooperate: the
 128input layer and the rfkill class.  The input layer issues *commands* to the
 129entire system requesting that devices registered to the rfkill class change
 130state.  The way this interaction happens is not complex, but it is not obvious
 131either:
 132
 133Kernel 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
 153rfkill 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
 186Userspace 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
 209Userspace uevent handler or kernel platform-specific drivers hooked to the
 210rfkill 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===============================================================================
 2223: Kernel driver guidelines
 223
 224Remember: point-of-view is everything for a driver that connects to the rfkill
 225subsystem.  All the details below must be measured/perceived from the point of
 226view of the specific driver being modified.
 227
 228The first thing one needs to know is whether his driver should be talking to
 229the rfkill class or to the input layer.  In rare cases (platform drivers), it
 230could happen that you need to do both, as platform drivers often handle a
 231variety of devices in the same driver.
 232
 233Do not mistake input devices for rfkill controllers.  The only type of "rfkill
 234switch" device that is to be registered with the rfkill class are those
 235directly controlling the circuits that cause a wireless transmitter to stop
 236working (or the software equivalent of them), i.e. what we call a rfkill
 237controller.  Every other kind of "rfkill switch" is just an input device and
 238MUST NOT be registered with the rfkill class.
 239
 240A driver should register a device with the rfkill class when ALL of the
 241following conditions are met (they define a rfkill controller):
 242
 2431. The device is/controls a data communications wireless transmitter;
 244
 2452. The kernel can interact with the hardware/firmware to CHANGE the wireless
 246   transmitter state (block/unblock TX operation);
 247
 2483. 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
 252A driver should register a device with the input subsystem to issue
 253rfkill-related events (KEY_WLAN, KEY_BLUETOOTH, KEY_WWAN, KEY_WIMAX,
 254SW_RFKILL_ALL, etc) when ALL of the folowing conditions are met:
 255
 2561. 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
 2642. 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
 269When in doubt, do not issue input events.  For drivers that should generate
 270input events in some platforms, but not in others (e.g. b43), the best solution
 271is to NEVER generate input events in the first place.  That work should be
 272deferred to a platform-specific kernel module (which will know when to generate
 273events through the rfkill notifier chain) or to userspace.  This avoids the
 274usual maintenance problems with DMI whitelisting.
 275
 276
 277Corner cases and examples:
 278====================================
 279
 2801. If the device is an input device that, because of hardware or firmware,
 281causes wireless transmitters to be blocked regardless of the kernel's will, it
 282is still just an input device, and NOT to be registered with the rfkill class.
 283
 2842. If the wireless transmitter switch control is read-only, it is an input
 285device and not to be registered with the rfkill class (and maybe not to be made
 286an input layer event source either, see below).
 287
 2883. If there is some other device driver *closer* to the actual hardware the
 289user interacted with (the button/switch/key) to issue an input event, THAT is
 290the device driver that should be issuing input events.
 291
 292E.g:
 293  [RFKILL slider switch] -- [GPIO hardware] -- [WLAN card rf-kill input]
 294                           (platform driver)    (wireless card driver)
 295
 296The user is closer to the RFKILL slide switch plaform driver, so the driver
 297which must issue input events is the platform driver looking at the GPIO
 298hardware, and NEVER the wireless card driver (which is just a slave).  It is
 299very likely that there are other leaves than just the WLAN card rf-kill input
 300(e.g. a bluetooth card, etc)...
 301
 302On the other hand, some embedded devices do this:
 303
 304  [RFKILL slider switch] -- [WLAN card rf-kill input]
 305                             (wireless card driver)
 306
 307In this situation, the wireless card driver *could* register itself as an input
 308device and issue rf-kill related input events... but in order to AVOID the need
 309for DMI whitelisting, the wireless card driver does NOT do it.  Userspace (HAL)
 310or a platform driver (that exists only on these embedded devices) will do the
 311dirty job of issuing the input events.
 312
 313
 314COMMON MISTAKES in kernel drivers, related to rfkill:
 315====================================
 316
 3171. 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
 327Add the SW_* events you need for switches, do NOT try to emulate a button using
 328KEY_* events just because there is no such SW_* event yet.  Do NOT try to use,
 329for example, KEY_BLUETOOTH when you should be using SW_BLUETOOTH instead.
 330
 3312. 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
 333driver start-up and also when resuming from sleep), and that state CAN be
 334queried from userspace through IOCTLs.  There is no sysfs interface for this,
 335but that doesn't mean you should break things trying to hook it to the rfkill
 336class to get a sysfs interface :-)
 337
 3383. Do not issue *_RFKILL_ALL events by default, unless you are sure it is the
 339correct event for your switch/button.  These events are emergency power-off
 340events when they are trying to turn the transmitters off.  An example of an
 341input device which SHOULD generate *_RFKILL_ALL events is the wireless-kill
 342switch in a laptop which is NOT a hotkey, but a real sliding/rocker switch.
 343An example of an input device which SHOULD NOT generate *_RFKILL_ALL events by
 344default, is any sort of hot key that is type-specific (e.g. the one for WLAN).
 345
 346
 3473.1 Guidelines for wireless device drivers
 348------------------------------------------
 349
 350(in this text, rfkill->foo means the foo field of struct rfkill).
 351
 3521. Each independent transmitter in a wireless device (usually there is only one
 353transmitter per device) should have a SINGLE rfkill class attached to it.
 354
 3552. If the device does not have any sort of hardware assistance to allow the
 356driver to rfkill the device, the driver should emulate it by taking all actions
 357required to silence the transmitter.
 358
 3593. If it is impossible to silence the transmitter (i.e. it still emits energy,
 360even if it is just in brief pulses, when there is no data to transmit and there
 361is no hardware support to turn it off) do NOT lie to the users.  Do not attach
 362it to a rfkill class.  The rfkill subsystem does not deal with data
 363transmission, it deals with energy emission.  If the transmitter is emitting
 364energy, it is not blocked in rfkill terms.
 365
 3664. It doesn't matter if the device has multiple rfkill input lines affecting
 367the same transmitter, their combined state is to be exported as a single state
 368per transmitter (see rule 1).
 369
 370This rule exists because users of the rfkill subsystem expect to get (and set,
 371when possible) the overall transmitter rfkill state, not of a particular rfkill
 372line.
 373
 3745. The wireless device driver MUST NOT leave the transmitter enabled during
 375suspend and hibernation unless:
 376
 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
 382AND
 383
 384        5.2. The device was not on a user-requested BLOCKED state before
 385        the suspend (i.e. the driver must NOT unblock a device, not even
 386        to support wake-on-wireless-packet or remain in the mesh).
 387
 388In other words, there is absolutely no allowed scenario where a driver can
 389automatically take action to unblock a rfkill controller (obviously, this deals
 390with scenarios where soft-blocking or both soft and hard blocking is happening.
 391Scenarios where hardware rfkill lines are the only ones blocking the
 392transmitter are outside of this rule, since the wireless device driver does not
 393control its input hardware rfkill lines in the first place).
 394
 3956. During resume, rfkill will try to restore its previous state.
 396
 3977. After a rfkill class is suspended, it will *not* call rfkill->toggle_radio
 398until it is resumed.
 399
 400
 401Example of a WLAN wireless driver connected to the rfkill subsystem:
 402--------------------------------------------------------------------
 403
 404A certain WLAN card has one input pin that causes it to block the transmitter
 405and makes the status of that input pin available (only for reaf="DM)ktation/rfkill.txt#L275" id="L275" class="lne" name="L36ut.
<54="lin4" nameMON MISTAKES  or to uer wor botce has multiple r   ne ina>enee197 denFKILL_ALL events by
 208
 >A ceer strtain WLPCId driver *an inpif405nipurnel dbyhe suspend ,e input="L208"> 208
 211
In oma"> 2ots and econtrolryhe devicutuot; thollinssion.  If tergency power-off
 >A ce97 405and makes the 2ots and e that input pin avargency power-off
r botce has multiple rthe first place).
 365
 318
  often haollihe foo ce the *ONE*ing S hard from the point of
7. After(device (usually tmission.  If the first place).
 321
r botce has multiple rware rhile t energy emiwo>r borgency power-off
          RFKILL_STAiapollilockrgency power-off
       UNKILL_STthe first place).
 227
 227
 356e througBLOC,he suspend (i.e. 05">, unles the tivate rfkill API calls
and ma. Switup-to-dr not-prepini.e. doers often handle a
 232
contimehe suspend (getifaoIssues feedbasured/per>A ces theuld hapolliof a particular rfkill
direcmighenee1SW_*eansnFKadlILL_sigter,>A cs335"> 33664articular rfkill
is to Ntthrupt/a>3.1use tources ,si. recomlti> 405 337
rfkill subsystem:
 239
 239
       UNKILL_STthe first place).
 242
 405A a rfasr auton ted as a single state
          RFKILL_STis jusice, thmbedded ="L360">uld happen Sceniof a particular rfkill
 346
 346
A a rfasr auton 98       UNKILL_STthe first place).
 349
 2API================
 242
wheK317;ransmce, th_Iss_h52npu RKF/a> INPUTthe first place).
 255
thealke tramaynee1write contlessehe act9 DO store their current state
 259
7. Afters sus, it   emget_re itthings 401contimehansfirst="L259"> 259
 230 259
 259
transmitter a connected to the the first place).
 394
 39"L210_state_re it()t        ides a rfki "> 230sst a slave).  It is
 2atoryin brief  t matter ifaontrol its input hardhe3.1  bri be 28elll class are those
ev class are those
7. Aftethe first place).
 369
 340ollihedeuwaa rfkis the ipensos> 277"> 364<="L369"> 369
="L356"> 3a>enprovsmize iet_re itthingot-prepg SW_Bd driver *anv class are those
7. After*allably*to be regi="L339">hedeuwot-preneep4 36updivedemulate a button using
 339 394
KEY_ice dthat ex t mattep andesm driveless updiveranv class are those
2edeuwaa rfk not mitter enabled during
 318
 318
 381
--speify/all trao meas (flagwot4" c)fkill subsystem:
--speify/hedes traact9 DO stor"> 361in theTHISnISeTHE ONLY TIMEfkill subsystem:
thYOU, andACCESSa>in thDIRECTLY)fkill subsystem:
 318
 318
 291
1. Ire rfkis clos       HARDFKILL_STA thei,rfkill linwa, rfksslidi="L291"> 291
eifut evtA their com 273 291
 295
 357<36          RFKILL_ST="L295"> 295
 295
enreware istthroo the  SW_B,ransmce, tume, rfk 269le-e thely od to silence to get (and set,
          RFKILL_STAmce, thdevr"> 361 ence to this one.
 301
 267   Pleaput layxamples se1
 403
  ================
 306
 325u="L340"(o be istomaticater  A &q, rfki  A &q),to be regifo abstter enabled during
 369
      fkill subsystem:
 TYP fkill subsystem:
 313
 ABI.f236 2vari inpitr (obfinl dbyhe su>classattribti> is just  (e.g="L313"> 313
, unleter a ca>3. If ivaluut device switches.
 316
 316
 400
 331="L273"> the its ernel drivers, rur switchthe actual hardware the
 328Add 6  l dbyh="Docu-multi.cthe first place).
 313
 313
 313
.f236 313
 330
KE the sandesss you arll linput layake="L393">availll tranh input device switches.
 3, rfki duaytrall the hat by ta, di339"> NOT m by ta,device switches.
 394
KE>(so yNOT tall transmiuw="L394"> 394
.t events.xamp ny28k th> 230 device switches.
 337
, tate, not cthe aoh * rfkillehes (su32 NOT generaproperlynorW"ehas on="L337"> 337
if<36co*tall trace the *s de*iver mmed yNOlinltistny for reaf="DM)ktation/rfkill.txt#L275" id5on/rfkill5txt#L340" id="L340" clas5="lin54 name98          RFKILL_STAmtmitter  not oib. Kesr a device switches.
 301
 313
4" c: N" csort gnl dbyh="L356"> 3dded any ( to get a amp="L356"4" c) device switches.
 ypc: N" csakes suany sypc (  A &qwla.  A &q,hat'300(  A &q,hbluetdevice switches.
mtmit: CDO store the happen it to block the transmitter
          RFKILL_ST="L295"> 295
 ssion.  If thestateans f is NOuld The 97 >.nel's will, it
byha1write>   Pleap the attribti>;l's will, it
       UNKILL_STl's will, it
 ssion. If theturnstateans f ifkil05y operiver ergency power-off
 it 388"> ="Ldioib. K>3.1use toperivticathe meel's will, it
(use tass to get a ed ua>driv317 ssion.  If thestateans f>byh be 28transmittel's will, it
 /a>="L35623 ="L393" enOuee ina>en<36 /ilihedes t 273   Pleap the attribti>;l's will, it
 2rtdrivs ="L340l's will, it
 259
 313
 313
Add ="L36L3ss, unles the tiliver. K>3.1or  multis/a>Add vargency power-off
class  A &qleep)  A &qu>
 3esrs="L313"> 313
 369
 331 301
An example of ="L342"( 378="L301"> 301



/a> crigiisl"LXR/lock61LXR/communitynameoller (fkilris. lxr@d="ux.noname.
lxr.d="ux.no kindlILhos l dbyhevice swihttp://www.7">pocu-d="ato.no">R">pocu L="ato ASnameolprovsmir hapL="ux ="Lsthe ulata>npperivticif<3r1