aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/rfkill.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/rfkill.h')
-rw-r--r--include/linux/rfkill.h387
1 files changed, 294 insertions, 93 deletions
diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
index 164332cbb77c..16e39c7a67fc 100644
--- a/include/linux/rfkill.h
+++ b/include/linux/rfkill.h
@@ -4,6 +4,7 @@
4/* 4/*
5 * Copyright (C) 2006 - 2007 Ivo van Doorn 5 * Copyright (C) 2006 - 2007 Ivo van Doorn
6 * Copyright (C) 2007 Dmitry Torokhov 6 * Copyright (C) 2007 Dmitry Torokhov
7 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
@@ -22,131 +23,331 @@
22 */ 23 */
23 24
24#include <linux/types.h> 25#include <linux/types.h>
25#include <linux/kernel.h> 26
26#include <linux/list.h> 27/* define userspace visible states */
27#include <linux/mutex.h> 28#define RFKILL_STATE_SOFT_BLOCKED 0
28#include <linux/device.h> 29#define RFKILL_STATE_UNBLOCKED 1
29#include <linux/leds.h> 30#define RFKILL_STATE_HARD_BLOCKED 2
30 31
31/** 32/**
32 * enum rfkill_type - type of rfkill switch. 33 * enum rfkill_type - type of rfkill switch.
33 * RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device. 34 *
34 * RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device. 35 * @RFKILL_TYPE_ALL: toggles all switches (userspace only)
35 * RFKILL_TYPE_UWB: switch is on a ultra wideband device. 36 * @RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device.
36 * RFKILL_TYPE_WIMAX: switch is on a WiMAX device. 37 * @RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device.
37 * RFKILL_TYPE_WWAN: switch is on a wireless WAN device. 38 * @RFKILL_TYPE_UWB: switch is on a ultra wideband device.
39 * @RFKILL_TYPE_WIMAX: switch is on a WiMAX device.
40 * @RFKILL_TYPE_WWAN: switch is on a wireless WAN device.
41 * @NUM_RFKILL_TYPES: number of defined rfkill types
38 */ 42 */
39enum rfkill_type { 43enum rfkill_type {
40 RFKILL_TYPE_WLAN , 44 RFKILL_TYPE_ALL = 0,
45 RFKILL_TYPE_WLAN,
41 RFKILL_TYPE_BLUETOOTH, 46 RFKILL_TYPE_BLUETOOTH,
42 RFKILL_TYPE_UWB, 47 RFKILL_TYPE_UWB,
43 RFKILL_TYPE_WIMAX, 48 RFKILL_TYPE_WIMAX,
44 RFKILL_TYPE_WWAN, 49 RFKILL_TYPE_WWAN,
45 RFKILL_TYPE_MAX, 50 NUM_RFKILL_TYPES,
46}; 51};
47 52
48enum rfkill_state { 53/**
49 RFKILL_STATE_SOFT_BLOCKED = 0, /* Radio output blocked */ 54 * enum rfkill_operation - operation types
50 RFKILL_STATE_UNBLOCKED = 1, /* Radio output allowed */ 55 * @RFKILL_OP_ADD: a device was added
51 RFKILL_STATE_HARD_BLOCKED = 2, /* Output blocked, non-overrideable */ 56 * @RFKILL_OP_DEL: a device was removed
52 RFKILL_STATE_MAX, /* marker for last valid state */ 57 * @RFKILL_OP_CHANGE: a device's state changed -- userspace changes one device
58 * @RFKILL_OP_CHANGE_ALL: userspace changes all devices (of a type, or all)
59 */
60enum rfkill_operation {
61 RFKILL_OP_ADD = 0,
62 RFKILL_OP_DEL,
63 RFKILL_OP_CHANGE,
64 RFKILL_OP_CHANGE_ALL,
53}; 65};
54 66
55/* 67/**
56 * These are DEPRECATED, drivers using them should be verified to 68 * struct rfkill_event - events for userspace on /dev/rfkill
57 * comply with the rfkill usage guidelines in Documentation/rfkill.txt 69 * @idx: index of dev rfkill
58 * and then converted to use the new names for rfkill_state 70 * @type: type of the rfkill struct
59 */ 71 * @op: operation code
60#define RFKILL_STATE_OFF RFKILL_STATE_SOFT_BLOCKED 72 * @hard: hard state (0/1)
61#define RFKILL_STATE_ON RFKILL_STATE_UNBLOCKED 73 * @soft: soft state (0/1)
62 74 *
63/** 75 * Structure used for userspace communication on /dev/rfkill,
64 * struct rfkill - rfkill control structure. 76 * used for events from the kernel and control to the kernel.
65 * @name: Name of the switch. 77 */
66 * @type: Radio type which the button controls, the value stored 78struct rfkill_event {
67 * here should be a value from enum rfkill_type. 79 __u32 idx;
68 * @state: State of the switch, "UNBLOCKED" means radio can operate. 80 __u8 type;
69 * @user_claim_unsupported: Whether the hardware supports exclusive 81 __u8 op;
70 * RF-kill control by userspace. Set this before registering. 82 __u8 soft, hard;
71 * @user_claim: Set when the switch is controlled exlusively by userspace. 83} __packed;
72 * @mutex: Guards switch state transitions. It serializes callbacks
73 * and also protects the state.
74 * @data: Pointer to the RF button drivers private data which will be
75 * passed along when toggling radio state.
76 * @toggle_radio(): Mandatory handler to control state of the radio.
77 * only RFKILL_STATE_SOFT_BLOCKED and RFKILL_STATE_UNBLOCKED are
78 * valid parameters.
79 * @get_state(): handler to read current radio state from hardware,
80 * may be called from atomic context, should return 0 on success.
81 * Either this handler OR judicious use of rfkill_force_state() is
82 * MANDATORY for any driver capable of RFKILL_STATE_HARD_BLOCKED.
83 * @led_trigger: A LED trigger for this button's LED.
84 * @dev: Device structure integrating the switch into device tree.
85 * @node: Used to place switch into list of all switches known to the
86 * the system.
87 *
88 * This structure represents a RF switch located on a network device.
89 */
90struct rfkill {
91 const char *name;
92 enum rfkill_type type;
93
94 bool user_claim_unsupported;
95 bool user_claim;
96
97 /* the mutex serializes callbacks and also protects
98 * the state */
99 struct mutex mutex;
100 enum rfkill_state state;
101 void *data;
102 int (*toggle_radio)(void *data, enum rfkill_state state);
103 int (*get_state)(void *data, enum rfkill_state *state);
104 84
105#ifdef CONFIG_RFKILL_LEDS 85/* ioctl for turning off rfkill-input (if present) */
106 struct led_trigger led_trigger; 86#define RFKILL_IOC_MAGIC 'R'
107#endif 87#define RFKILL_IOC_NOINPUT 1
88#define RFKILL_IOCTL_NOINPUT _IO(RFKILL_IOC_MAGIC, RFKILL_IOC_NOINPUT)
89
90/* and that's all userspace gets */
91#ifdef __KERNEL__
92/* don't allow anyone to use these in the kernel */
93enum rfkill_user_states {
94 RFKILL_USER_STATE_SOFT_BLOCKED = RFKILL_STATE_SOFT_BLOCKED,
95 RFKILL_USER_STATE_UNBLOCKED = RFKILL_STATE_UNBLOCKED,
96 RFKILL_USER_STATE_HARD_BLOCKED = RFKILL_STATE_HARD_BLOCKED,
97};
98#undef RFKILL_STATE_SOFT_BLOCKED
99#undef RFKILL_STATE_UNBLOCKED
100#undef RFKILL_STATE_HARD_BLOCKED
101
102#include <linux/types.h>
103#include <linux/kernel.h>
104#include <linux/list.h>
105#include <linux/mutex.h>
106#include <linux/device.h>
107#include <linux/leds.h>
108#include <linux/err.h>
109
110/* this is opaque */
111struct rfkill;
108 112
109 struct device dev; 113/**
110 struct list_head node; 114 * struct rfkill_ops - rfkill driver methods
111 enum rfkill_state state_for_resume; 115 *
116 * @poll: poll the rfkill block state(s) -- only assign this method
117 * when you need polling. When called, simply call one of the
118 * rfkill_set{,_hw,_sw}_state family of functions. If the hw
119 * is getting unblocked you need to take into account the return
120 * value of those functions to make sure the software block is
121 * properly used.
122 * @query: query the rfkill block state(s) and call exactly one of the
123 * rfkill_set{,_hw,_sw}_state family of functions. Assign this
124 * method if input events can cause hardware state changes to make
125 * the rfkill core query your driver before setting a requested
126 * block.
127 * @set_block: turn the transmitter on (blocked == false) or off
128 * (blocked == true) -- ignore and return 0 when hard blocked.
129 * This callback must be assigned.
130 */
131struct rfkill_ops {
132 void (*poll)(struct rfkill *rfkill, void *data);
133 void (*query)(struct rfkill *rfkill, void *data);
134 int (*set_block)(void *data, bool blocked);
112}; 135};
113#define to_rfkill(d) container_of(d, struct rfkill, dev)
114 136
115struct rfkill * __must_check rfkill_allocate(struct device *parent, 137#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
116 enum rfkill_type type); 138/**
117void rfkill_free(struct rfkill *rfkill); 139 * rfkill_alloc - allocate rfkill structure
140 * @name: name of the struct -- the string is not copied internally
141 * @parent: device that has rf switch on it
142 * @type: type of the switch (RFKILL_TYPE_*)
143 * @ops: rfkill methods
144 * @ops_data: data passed to each method
145 *
146 * This function should be called by the transmitter driver to allocate an
147 * rfkill structure. Returns %NULL on failure.
148 */
149struct rfkill * __must_check rfkill_alloc(const char *name,
150 struct device *parent,
151 const enum rfkill_type type,
152 const struct rfkill_ops *ops,
153 void *ops_data);
154
155/**
156 * rfkill_register - Register a rfkill structure.
157 * @rfkill: rfkill structure to be registered
158 *
159 * This function should be called by the transmitter driver to register
160 * the rfkill structure. Before calling this function the driver needs
161 * to be ready to service method calls from rfkill.
162 *
163 * If the software blocked state is not set before registration,
164 * set_block will be called to initialize it to a default value.
165 *
166 * If the hardware blocked state is not set before registration,
167 * it is assumed to be unblocked.
168 */
118int __must_check rfkill_register(struct rfkill *rfkill); 169int __must_check rfkill_register(struct rfkill *rfkill);
170
171/**
172 * rfkill_pause_polling(struct rfkill *rfkill)
173 *
174 * Pause polling -- say transmitter is off for other reasons.
175 * NOTE: not necessary for suspend/resume -- in that case the
176 * core stops polling anyway
177 */
178void rfkill_pause_polling(struct rfkill *rfkill);
179
180/**
181 * rfkill_resume_polling(struct rfkill *rfkill)
182 *
183 * Pause polling -- say transmitter is off for other reasons.
184 * NOTE: not necessary for suspend/resume -- in that case the
185 * core stops polling anyway
186 */
187void rfkill_resume_polling(struct rfkill *rfkill);
188
189
190/**
191 * rfkill_unregister - Unregister a rfkill structure.
192 * @rfkill: rfkill structure to be unregistered
193 *
194 * This function should be called by the network driver during device
195 * teardown to destroy rfkill structure. Until it returns, the driver
196 * needs to be able to service method calls.
197 */
119void rfkill_unregister(struct rfkill *rfkill); 198void rfkill_unregister(struct rfkill *rfkill);
120 199
121int rfkill_force_state(struct rfkill *rfkill, enum rfkill_state state); 200/**
122int rfkill_set_default(enum rfkill_type type, enum rfkill_state state); 201 * rfkill_destroy - free rfkill structure
202 * @rfkill: rfkill structure to be destroyed
203 *
204 * Destroys the rfkill structure.
205 */
206void rfkill_destroy(struct rfkill *rfkill);
207
208/**
209 * rfkill_set_hw_state - Set the internal rfkill hardware block state
210 * @rfkill: pointer to the rfkill class to modify.
211 * @state: the current hardware block state to set
212 *
213 * rfkill drivers that get events when the hard-blocked state changes
214 * use this function to notify the rfkill core (and through that also
215 * userspace) of the current state. They should also use this after
216 * resume if the state could have changed.
217 *
218 * You need not (but may) call this function if poll_state is assigned.
219 *
220 * This function can be called in any context, even from within rfkill
221 * callbacks.
222 *
223 * The function returns the combined block state (true if transmitter
224 * should be blocked) so that drivers need not keep track of the soft
225 * block state -- which they might not be able to.
226 */
227bool __must_check rfkill_set_hw_state(struct rfkill *rfkill, bool blocked);
228
229/**
230 * rfkill_set_sw_state - Set the internal rfkill software block state
231 * @rfkill: pointer to the rfkill class to modify.
232 * @state: the current software block state to set
233 *
234 * rfkill drivers that get events when the soft-blocked state changes
235 * (yes, some platforms directly act on input but allow changing again)
236 * use this function to notify the rfkill core (and through that also
237 * userspace) of the current state. It is not necessary to notify on
238 * resume; since hibernation can always change the soft-blocked state,
239 * the rfkill core will unconditionally restore the previous state.
240 *
241 * This function can be called in any context, even from within rfkill
242 * callbacks.
243 *
244 * The function returns the combined block state (true if transmitter
245 * should be blocked).
246 */
247bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked);
248
249/**
250 * rfkill_set_states - Set the internal rfkill block states
251 * @rfkill: pointer to the rfkill class to modify.
252 * @sw: the current software block state to set
253 * @hw: the current hardware block state to set
254 *
255 * This function can be called in any context, even from within rfkill
256 * callbacks.
257 */
258void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw);
123 259
124/** 260/**
125 * rfkill_state_complement - return complementar state 261 * rfkill_blocked - query rfkill block
126 * @state: state to return the complement of
127 * 262 *
128 * Returns RFKILL_STATE_SOFT_BLOCKED if @state is RFKILL_STATE_UNBLOCKED, 263 * @rfkill: rfkill struct to query
129 * returns RFKILL_STATE_UNBLOCKED otherwise.
130 */ 264 */
131static inline enum rfkill_state rfkill_state_complement(enum rfkill_state state) 265bool rfkill_blocked(struct rfkill *rfkill);
266#else /* !RFKILL */
267static inline struct rfkill * __must_check
268rfkill_alloc(const char *name,
269 struct device *parent,
270 const enum rfkill_type type,
271 const struct rfkill_ops *ops,
272 void *ops_data)
273{
274 return ERR_PTR(-ENODEV);
275}
276
277static inline int __must_check rfkill_register(struct rfkill *rfkill)
278{
279 if (rfkill == ERR_PTR(-ENODEV))
280 return 0;
281 return -EINVAL;
282}
283
284static inline void rfkill_pause_polling(struct rfkill *rfkill)
285{
286}
287
288static inline void rfkill_resume_polling(struct rfkill *rfkill)
289{
290}
291
292static inline void rfkill_unregister(struct rfkill *rfkill)
293{
294}
295
296static inline void rfkill_destroy(struct rfkill *rfkill)
297{
298}
299
300static inline bool rfkill_set_hw_state(struct rfkill *rfkill, bool blocked)
301{
302 return blocked;
303}
304
305static inline bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked)
132{ 306{
133 return (state == RFKILL_STATE_UNBLOCKED) ? 307 return blocked;
134 RFKILL_STATE_SOFT_BLOCKED : RFKILL_STATE_UNBLOCKED;
135} 308}
136 309
310static inline void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw)
311{
312}
313
314static inline bool rfkill_blocked(struct rfkill *rfkill)
315{
316 return false;
317}
318#endif /* RFKILL || RFKILL_MODULE */
319
320
321#ifdef CONFIG_RFKILL_LEDS
137/** 322/**
138 * rfkill_get_led_name - Get the LED trigger name for the button's LED. 323 * rfkill_get_led_trigger_name - Get the LED trigger name for the button's LED.
139 * This function might return a NULL pointer if registering of the 324 * This function might return a NULL pointer if registering of the
140 * LED trigger failed. 325 * LED trigger failed. Use this as "default_trigger" for the LED.
141 * Use this as "default_trigger" for the LED.
142 */ 326 */
143static inline char *rfkill_get_led_name(struct rfkill *rfkill) 327const char *rfkill_get_led_trigger_name(struct rfkill *rfkill);
144{ 328
145#ifdef CONFIG_RFKILL_LEDS 329/**
146 return (char *)(rfkill->led_trigger.name); 330 * rfkill_set_led_trigger_name -- set the LED trigger name
331 * @rfkill: rfkill struct
332 * @name: LED trigger name
333 *
334 * This function sets the LED trigger name of the radio LED
335 * trigger that rfkill creates. It is optional, but if called
336 * must be called before rfkill_register() to be effective.
337 */
338void rfkill_set_led_trigger_name(struct rfkill *rfkill, const char *name);
147#else 339#else
340static inline const char *rfkill_get_led_trigger_name(struct rfkill *rfkill)
341{
148 return NULL; 342 return NULL;
149#endif
150} 343}
151 344
345static inline void
346rfkill_set_led_trigger_name(struct rfkill *rfkill, const char *name)
347{
348}
349#endif
350
351#endif /* __KERNEL__ */
352
152#endif /* RFKILL_H */ 353#endif /* RFKILL_H */