rfkill.txt 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. rfkill - RF kill switch support
  2. ===============================
  3. 1. Introduction
  4. 2. Implementation details
  5. 3. Kernel driver guidelines
  6. 4. Kernel API
  7. 5. Userspace support
  8. 1. Introduction
  9. The rfkill subsystem provides a generic interface to disabling any radio
  10. transmitter in the system. When a transmitter is blocked, it shall not
  11. radiate any power.
  12. The subsystem also provides the ability to react on button presses and
  13. disable all transmitters of a certain type (or all). This is intended for
  14. situations where transmitters need to be turned off, for example on
  15. aircraft.
  16. 2. Implementation details
  17. The rfkill subsystem is composed of various components: the rfkill class, the
  18. rfkill-input module (an input layer handler), and some specific input layer
  19. events.
  20. The rfkill class is provided for kernel drivers to register their radio
  21. transmitter with the kernel, provide methods for turning it on and off and,
  22. optionally, letting the system know about hardware-disabled states that may
  23. be implemented on the device. This code is enabled with the CONFIG_RFKILL
  24. Kconfig option, which drivers can "select".
  25. The rfkill class code also notifies userspace of state changes, this is
  26. achieved via uevents. It also provides some sysfs files for userspace to
  27. check the status of radio transmitters. See the "Userspace support" section
  28. below.
  29. The rfkill-input code implements a basic response to rfkill buttons -- it
  30. implements turning on/off all devices of a certain class (or all).
  31. When the device is hard-blocked (either by a call to rfkill_set_hw_state()
  32. or from query_hw_block) set_block() will be invoked but drivers can well
  33. ignore the method call since they can use the return value of the function
  34. rfkill_set_hw_state() to sync the software state instead of keeping track
  35. of calls to set_block().
  36. The entire functionality is spread over more than one subsystem:
  37. * The kernel input layer generates KEY_WWAN, KEY_WLAN etc. and
  38. SW_RFKILL_ALL -- when the user presses a button. Drivers for radio
  39. transmitters generally do not register to the input layer, unless the
  40. device really provides an input device (i.e. a button that has no
  41. effect other than generating a button press event)
  42. * The rfkill-input code hooks up to these events and switches the soft-block
  43. of the various radio transmitters, depending on the button type.
  44. * The rfkill drivers turn off/on their transmitters as requested.
  45. * The rfkill class will generate userspace notifications (uevents) to tell
  46. userspace what the current state is.
  47. 3. Kernel driver guidelines
  48. Drivers for radio transmitters normally implement only the rfkill class.
  49. These drivers may not unblock the transmitter based on own decisions, they
  50. should act on information provided by the rfkill class only.
  51. Platform drivers might implement input devices if the rfkill button is just
  52. that, a button. If that button influences the hardware then you need to
  53. implement an rfkill class instead. This also applies if the platform provides
  54. a way to turn on/off the transmitter(s).
  55. During suspend/hibernation, transmitters should only be left enabled when
  56. wake-on wlan or similar functionality requires it and the device wasn't
  57. blocked before suspend/hibernate. Note that it may be necessary to update
  58. the rfkill subsystem's idea of what the current state is at resume time if
  59. the state may have changed over suspend.
  60. 4. Kernel API
  61. To build a driver with rfkill subsystem support, the driver should depend on
  62. (or select) the Kconfig symbol RFKILL.
  63. The hardware the driver talks to may be write-only (where the current state
  64. of the hardware is unknown), or read-write (where the hardware can be queried
  65. about its current state).
  66. Calling rfkill_set_hw_state() when a state change happens is required from
  67. rfkill drivers that control devices that can be hard-blocked unless they also
  68. assign the poll_hw_block() callback (then the rfkill core will poll the
  69. device). Don't do this unless you cannot get the event in any other way.
  70. 5. Userspace support
  71. The following sysfs entries exist for every rfkill device:
  72. name: Name assigned by driver to this key (interface or driver name).
  73. type: Name of the key type ("wlan", "bluetooth", etc).
  74. state: Current state of the transmitter
  75. 0: RFKILL_STATE_SOFT_BLOCKED
  76. transmitter is turned off by software
  77. 1: RFKILL_STATE_UNBLOCKED
  78. transmiter is (potentially) active
  79. 2: RFKILL_STATE_HARD_BLOCKED
  80. transmitter is forced off by something outside of
  81. the driver's control.
  82. claim: 0: Kernel handles events (currently always reads that value)
  83. rfkill devices also issue uevents (with an action of "change"), with the
  84. following environment variables set:
  85. RFKILL_NAME
  86. RFKILL_STATE
  87. RFKILL_TYPE
  88. The contents of these variables corresponds to the "name", "state" and
  89. "type" sysfs files explained above.