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.h410
1 files changed, 317 insertions, 93 deletions
diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
index 164332cbb77c..e73e2429a1b1 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,354 @@
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)
108 89
109 struct device dev; 90/* and that's all userspace gets */
110 struct list_head node; 91#ifdef __KERNEL__
111 enum rfkill_state state_for_resume; 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,
112}; 97};
113#define to_rfkill(d) container_of(d, struct rfkill, dev) 98#undef RFKILL_STATE_SOFT_BLOCKED
99#undef RFKILL_STATE_UNBLOCKED
100#undef RFKILL_STATE_HARD_BLOCKED
114 101
115struct rfkill * __must_check rfkill_allocate(struct device *parent, 102#include <linux/types.h>
116 enum rfkill_type type); 103#include <linux/kernel.h>
117void rfkill_free(struct rfkill *rfkill); 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;
112
113/**
114 * struct rfkill_ops - rfkill driver methods
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);
135};
136
137#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
138/**
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 rfkill_init_sw_state() is not called before registration,
164 * set_block() will be called to initialize the software blocked state
165 * to a default value.
166 *
167 * If the hardware blocked state is not set before registration,
168 * it is assumed to be unblocked.
169 */
118int __must_check rfkill_register(struct rfkill *rfkill); 170int __must_check rfkill_register(struct rfkill *rfkill);
171
172/**
173 * rfkill_pause_polling(struct rfkill *rfkill)
174 *
175 * Pause polling -- say transmitter is off for other reasons.
176 * NOTE: not necessary for suspend/resume -- in that case the
177 * core stops polling anyway
178 */
179void rfkill_pause_polling(struct rfkill *rfkill);
180
181/**
182 * rfkill_resume_polling(struct rfkill *rfkill)
183 *
184 * Pause polling -- say transmitter is off for other reasons.
185 * NOTE: not necessary for suspend/resume -- in that case the
186 * core stops polling anyway
187 */
188void rfkill_resume_polling(struct rfkill *rfkill);
189
190
191/**
192 * rfkill_unregister - Unregister a rfkill structure.
193 * @rfkill: rfkill structure to be unregistered
194 *
195 * This function should be called by the network driver during device
196 * teardown to destroy rfkill structure. Until it returns, the driver
197 * needs to be able to service method calls.
198 */
119void rfkill_unregister(struct rfkill *rfkill); 199void rfkill_unregister(struct rfkill *rfkill);
120 200
121int rfkill_force_state(struct rfkill *rfkill, enum rfkill_state state); 201/**
122int rfkill_set_default(enum rfkill_type type, enum rfkill_state state); 202 * rfkill_destroy - free rfkill structure
203 * @rfkill: rfkill structure to be destroyed
204 *
205 * Destroys the rfkill structure.
206 */
207void rfkill_destroy(struct rfkill *rfkill);
123 208
124/** 209/**
125 * rfkill_state_complement - return complementar state 210 * rfkill_set_hw_state - Set the internal rfkill hardware block state
126 * @state: state to return the complement of 211 * @rfkill: pointer to the rfkill class to modify.
212 * @state: the current hardware block state to set
213 *
214 * rfkill drivers that get events when the hard-blocked state changes
215 * use this function to notify the rfkill core (and through that also
216 * userspace) of the current state. They should also use this after
217 * resume if the state could have changed.
127 * 218 *
128 * Returns RFKILL_STATE_SOFT_BLOCKED if @state is RFKILL_STATE_UNBLOCKED, 219 * You need not (but may) call this function if poll_state is assigned.
129 * returns RFKILL_STATE_UNBLOCKED otherwise. 220 *
221 * This function can be called in any context, even from within rfkill
222 * callbacks.
223 *
224 * The function returns the combined block state (true if transmitter
225 * should be blocked) so that drivers need not keep track of the soft
226 * block state -- which they might not be able to.
130 */ 227 */
131static inline enum rfkill_state rfkill_state_complement(enum rfkill_state state) 228bool __must_check rfkill_set_hw_state(struct rfkill *rfkill, bool blocked);
229
230/**
231 * rfkill_set_sw_state - Set the internal rfkill software block state
232 * @rfkill: pointer to the rfkill class to modify.
233 * @state: the current software block state to set
234 *
235 * rfkill drivers that get events when the soft-blocked state changes
236 * (yes, some platforms directly act on input but allow changing again)
237 * use this function to notify the rfkill core (and through that also
238 * userspace) of the current state.
239 *
240 * Drivers should also call this function after resume if the state has
241 * been changed by the user. This only makes sense for "persistent"
242 * devices (see rfkill_init_sw_state()).
243 *
244 * This function can be called in any context, even from within rfkill
245 * callbacks.
246 *
247 * The function returns the combined block state (true if transmitter
248 * should be blocked).
249 */
250bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked);
251
252/**
253 * rfkill_init_sw_state - Initialize persistent software block state
254 * @rfkill: pointer to the rfkill class to modify.
255 * @state: the current software block state to set
256 *
257 * rfkill drivers that preserve their software block state over power off
258 * use this function to notify the rfkill core (and through that also
259 * userspace) of their initial state. It should only be used before
260 * registration.
261 *
262 * In addition, it marks the device as "persistent", an attribute which
263 * can be read by userspace. Persistent devices are expected to preserve
264 * their own state when suspended.
265 */
266void rfkill_init_sw_state(struct rfkill *rfkill, bool blocked);
267
268/**
269 * rfkill_set_states - Set the internal rfkill block states
270 * @rfkill: pointer to the rfkill class to modify.
271 * @sw: the current software block state to set
272 * @hw: the current hardware block state to set
273 *
274 * This function can be called in any context, even from within rfkill
275 * callbacks.
276 */
277void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw);
278
279/**
280 * rfkill_blocked - query rfkill block
281 *
282 * @rfkill: rfkill struct to query
283 */
284bool rfkill_blocked(struct rfkill *rfkill);
285#else /* !RFKILL */
286static inline struct rfkill * __must_check
287rfkill_alloc(const char *name,
288 struct device *parent,
289 const enum rfkill_type type,
290 const struct rfkill_ops *ops,
291 void *ops_data)
292{
293 return ERR_PTR(-ENODEV);
294}
295
296static inline int __must_check rfkill_register(struct rfkill *rfkill)
297{
298 if (rfkill == ERR_PTR(-ENODEV))
299 return 0;
300 return -EINVAL;
301}
302
303static inline void rfkill_pause_polling(struct rfkill *rfkill)
304{
305}
306
307static inline void rfkill_resume_polling(struct rfkill *rfkill)
308{
309}
310
311static inline void rfkill_unregister(struct rfkill *rfkill)
312{
313}
314
315static inline void rfkill_destroy(struct rfkill *rfkill)
132{ 316{
133 return (state == RFKILL_STATE_UNBLOCKED) ?
134 RFKILL_STATE_SOFT_BLOCKED : RFKILL_STATE_UNBLOCKED;
135} 317}
136 318
319static inline bool rfkill_set_hw_state(struct rfkill *rfkill, bool blocked)
320{
321 return blocked;
322}
323
324static inline bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked)
325{
326 return blocked;
327}
328
329static inline void rfkill_init_sw_state(struct rfkill *rfkill, bool blocked)
330{
331}
332
333static inline void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw)
334{
335}
336
337static inline bool rfkill_blocked(struct rfkill *rfkill)
338{
339 return false;
340}
341#endif /* RFKILL || RFKILL_MODULE */
342
343
344#ifdef CONFIG_RFKILL_LEDS
137/** 345/**
138 * rfkill_get_led_name - Get the LED trigger name for the button's LED. 346 * 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 347 * This function might return a NULL pointer if registering of the
140 * LED trigger failed. 348 * LED trigger failed. Use this as "default_trigger" for the LED.
141 * Use this as "default_trigger" for the LED.
142 */ 349 */
143static inline char *rfkill_get_led_name(struct rfkill *rfkill) 350const char *rfkill_get_led_trigger_name(struct rfkill *rfkill);
144{ 351
145#ifdef CONFIG_RFKILL_LEDS 352/**
146 return (char *)(rfkill->led_trigger.name); 353 * rfkill_set_led_trigger_name -- set the LED trigger name
354 * @rfkill: rfkill struct
355 * @name: LED trigger name
356 *
357 * This function sets the LED trigger name of the radio LED
358 * trigger that rfkill creates. It is optional, but if called
359 * must be called before rfkill_register() to be effective.
360 */
361void rfkill_set_led_trigger_name(struct rfkill *rfkill, const char *name);
147#else 362#else
363static inline const char *rfkill_get_led_trigger_name(struct rfkill *rfkill)
364{
148 return NULL; 365 return NULL;
149#endif
150} 366}
151 367
368static inline void
369rfkill_set_led_trigger_name(struct rfkill *rfkill, const char *name)
370{
371}
372#endif
373
374#endif /* __KERNEL__ */
375
152#endif /* RFKILL_H */ 376#endif /* RFKILL_H */