1*baa293e9SMauro Carvalho Chehab=============================== 2*baa293e9SMauro Carvalho Chehabrfkill - RF kill switch support 3*baa293e9SMauro Carvalho Chehab=============================== 4*baa293e9SMauro Carvalho Chehab 5*baa293e9SMauro Carvalho Chehab 6*baa293e9SMauro Carvalho Chehab.. contents:: 7*baa293e9SMauro Carvalho Chehab :depth: 2 8*baa293e9SMauro Carvalho Chehab 9*baa293e9SMauro Carvalho ChehabIntroduction 10*baa293e9SMauro Carvalho Chehab============ 11*baa293e9SMauro Carvalho Chehab 12*baa293e9SMauro Carvalho ChehabThe rfkill subsystem provides a generic interface for disabling any radio 13*baa293e9SMauro Carvalho Chehabtransmitter in the system. When a transmitter is blocked, it shall not 14*baa293e9SMauro Carvalho Chehabradiate any power. 15*baa293e9SMauro Carvalho Chehab 16*baa293e9SMauro Carvalho ChehabThe subsystem also provides the ability to react on button presses and 17*baa293e9SMauro Carvalho Chehabdisable all transmitters of a certain type (or all). This is intended for 18*baa293e9SMauro Carvalho Chehabsituations where transmitters need to be turned off, for example on 19*baa293e9SMauro Carvalho Chehabaircraft. 20*baa293e9SMauro Carvalho Chehab 21*baa293e9SMauro Carvalho ChehabThe rfkill subsystem has a concept of "hard" and "soft" block, which 22*baa293e9SMauro Carvalho Chehabdiffer little in their meaning (block == transmitters off) but rather in 23*baa293e9SMauro Carvalho Chehabwhether they can be changed or not: 24*baa293e9SMauro Carvalho Chehab 25*baa293e9SMauro Carvalho Chehab - hard block 26*baa293e9SMauro Carvalho Chehab read-only radio block that cannot be overridden by software 27*baa293e9SMauro Carvalho Chehab 28*baa293e9SMauro Carvalho Chehab - soft block 29*baa293e9SMauro Carvalho Chehab writable radio block (need not be readable) that is set by 30*baa293e9SMauro Carvalho Chehab the system software. 31*baa293e9SMauro Carvalho Chehab 32*baa293e9SMauro Carvalho ChehabThe rfkill subsystem has two parameters, rfkill.default_state and 33*baa293e9SMauro Carvalho Chehabrfkill.master_switch_mode, which are documented in 34*baa293e9SMauro Carvalho Chehabadmin-guide/kernel-parameters.rst. 35*baa293e9SMauro Carvalho Chehab 36*baa293e9SMauro Carvalho Chehab 37*baa293e9SMauro Carvalho ChehabImplementation details 38*baa293e9SMauro Carvalho Chehab====================== 39*baa293e9SMauro Carvalho Chehab 40*baa293e9SMauro Carvalho ChehabThe rfkill subsystem is composed of three main components: 41*baa293e9SMauro Carvalho Chehab 42*baa293e9SMauro Carvalho Chehab * the rfkill core, 43*baa293e9SMauro Carvalho Chehab * the deprecated rfkill-input module (an input layer handler, being 44*baa293e9SMauro Carvalho Chehab replaced by userspace policy code) and 45*baa293e9SMauro Carvalho Chehab * the rfkill drivers. 46*baa293e9SMauro Carvalho Chehab 47*baa293e9SMauro Carvalho ChehabThe rfkill core provides API for kernel drivers to register their radio 48*baa293e9SMauro Carvalho Chehabtransmitter with the kernel, methods for turning it on and off, and letting 49*baa293e9SMauro Carvalho Chehabthe system know about hardware-disabled states that may be implemented on 50*baa293e9SMauro Carvalho Chehabthe device. 51*baa293e9SMauro Carvalho Chehab 52*baa293e9SMauro Carvalho ChehabThe rfkill core code also notifies userspace of state changes, and provides 53*baa293e9SMauro Carvalho Chehabways for userspace to query the current states. See the "Userspace support" 54*baa293e9SMauro Carvalho Chehabsection below. 55*baa293e9SMauro Carvalho Chehab 56*baa293e9SMauro Carvalho ChehabWhen the device is hard-blocked (either by a call to rfkill_set_hw_state() 57*baa293e9SMauro Carvalho Chehabor from query_hw_block), set_block() will be invoked for additional software 58*baa293e9SMauro Carvalho Chehabblock, but drivers can ignore the method call since they can use the return 59*baa293e9SMauro Carvalho Chehabvalue of the function rfkill_set_hw_state() to sync the software state 60*baa293e9SMauro Carvalho Chehabinstead of keeping track of calls to set_block(). In fact, drivers should 61*baa293e9SMauro Carvalho Chehabuse the return value of rfkill_set_hw_state() unless the hardware actually 62*baa293e9SMauro Carvalho Chehabkeeps track of soft and hard block separately. 63*baa293e9SMauro Carvalho Chehab 64*baa293e9SMauro Carvalho Chehab 65*baa293e9SMauro Carvalho ChehabKernel API 66*baa293e9SMauro Carvalho Chehab========== 67*baa293e9SMauro Carvalho Chehab 68*baa293e9SMauro Carvalho ChehabDrivers for radio transmitters normally implement an rfkill driver. 69*baa293e9SMauro Carvalho Chehab 70*baa293e9SMauro Carvalho ChehabPlatform drivers might implement input devices if the rfkill button is just 71*baa293e9SMauro Carvalho Chehabthat, a button. If that button influences the hardware then you need to 72*baa293e9SMauro Carvalho Chehabimplement an rfkill driver instead. This also applies if the platform provides 73*baa293e9SMauro Carvalho Chehaba way to turn on/off the transmitter(s). 74*baa293e9SMauro Carvalho Chehab 75*baa293e9SMauro Carvalho ChehabFor some platforms, it is possible that the hardware state changes during 76*baa293e9SMauro Carvalho Chehabsuspend/hibernation, in which case it will be necessary to update the rfkill 77*baa293e9SMauro Carvalho Chehabcore with the current state at resume time. 78*baa293e9SMauro Carvalho Chehab 79*baa293e9SMauro Carvalho ChehabTo create an rfkill driver, driver's Kconfig needs to have:: 80*baa293e9SMauro Carvalho Chehab 81*baa293e9SMauro Carvalho Chehab depends on RFKILL || !RFKILL 82*baa293e9SMauro Carvalho Chehab 83*baa293e9SMauro Carvalho Chehabto ensure the driver cannot be built-in when rfkill is modular. The !RFKILL 84*baa293e9SMauro Carvalho Chehabcase allows the driver to be built when rfkill is not configured, in which 85*baa293e9SMauro Carvalho Chehabcase all rfkill API can still be used but will be provided by static inlines 86*baa293e9SMauro Carvalho Chehabwhich compile to almost nothing. 87*baa293e9SMauro Carvalho Chehab 88*baa293e9SMauro Carvalho ChehabCalling rfkill_set_hw_state() when a state change happens is required from 89*baa293e9SMauro Carvalho Chehabrfkill drivers that control devices that can be hard-blocked unless they also 90*baa293e9SMauro Carvalho Chehabassign the poll_hw_block() callback (then the rfkill core will poll the 91*baa293e9SMauro Carvalho Chehabdevice). Don't do this unless you cannot get the event in any other way. 92*baa293e9SMauro Carvalho Chehab 93*baa293e9SMauro Carvalho Chehabrfkill provides per-switch LED triggers, which can be used to drive LEDs 94*baa293e9SMauro Carvalho Chehabaccording to the switch state (LED_FULL when blocked, LED_OFF otherwise). 95*baa293e9SMauro Carvalho Chehab 96*baa293e9SMauro Carvalho Chehab 97*baa293e9SMauro Carvalho ChehabUserspace support 98*baa293e9SMauro Carvalho Chehab================= 99*baa293e9SMauro Carvalho Chehab 100*baa293e9SMauro Carvalho ChehabThe recommended userspace interface to use is /dev/rfkill, which is a misc 101*baa293e9SMauro Carvalho Chehabcharacter device that allows userspace to obtain and set the state of rfkill 102*baa293e9SMauro Carvalho Chehabdevices and sets of devices. It also notifies userspace about device addition 103*baa293e9SMauro Carvalho Chehaband removal. The API is a simple read/write API that is defined in 104*baa293e9SMauro Carvalho Chehablinux/rfkill.h, with one ioctl that allows turning off the deprecated input 105*baa293e9SMauro Carvalho Chehabhandler in the kernel for the transition period. 106*baa293e9SMauro Carvalho Chehab 107*baa293e9SMauro Carvalho ChehabExcept for the one ioctl, communication with the kernel is done via read() 108*baa293e9SMauro Carvalho Chehaband write() of instances of 'struct rfkill_event'. In this structure, the 109*baa293e9SMauro Carvalho Chehabsoft and hard block are properly separated (unlike sysfs, see below) and 110*baa293e9SMauro Carvalho Chehabuserspace is able to get a consistent snapshot of all rfkill devices in the 111*baa293e9SMauro Carvalho Chehabsystem. Also, it is possible to switch all rfkill drivers (or all drivers of 112*baa293e9SMauro Carvalho Chehaba specified type) into a state which also updates the default state for 113*baa293e9SMauro Carvalho Chehabhotplugged devices. 114*baa293e9SMauro Carvalho Chehab 115*baa293e9SMauro Carvalho ChehabAfter an application opens /dev/rfkill, it can read the current state of all 116*baa293e9SMauro Carvalho Chehabdevices. Changes can be obtained by either polling the descriptor for 117*baa293e9SMauro Carvalho Chehabhotplug or state change events or by listening for uevents emitted by the 118*baa293e9SMauro Carvalho Chehabrfkill core framework. 119*baa293e9SMauro Carvalho Chehab 120*baa293e9SMauro Carvalho ChehabAdditionally, each rfkill device is registered in sysfs and emits uevents. 121*baa293e9SMauro Carvalho Chehab 122*baa293e9SMauro Carvalho Chehabrfkill devices issue uevents (with an action of "change"), with the following 123*baa293e9SMauro Carvalho Chehabenvironment variables set:: 124*baa293e9SMauro Carvalho Chehab 125*baa293e9SMauro Carvalho Chehab RFKILL_NAME 126*baa293e9SMauro Carvalho Chehab RFKILL_STATE 127*baa293e9SMauro Carvalho Chehab RFKILL_TYPE 128*baa293e9SMauro Carvalho Chehab 129*baa293e9SMauro Carvalho ChehabThe content of these variables corresponds to the "name", "state" and 130*baa293e9SMauro Carvalho Chehab"type" sysfs files explained above. 131*baa293e9SMauro Carvalho Chehab 132*baa293e9SMauro Carvalho ChehabFor further details consult Documentation/ABI/stable/sysfs-class-rfkill. 133