]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/linux/rfkill.h
bnx2: no need to check before vfreeing
[net-next-2.6.git] / include / linux / rfkill.h
CommitLineData
cf4328cd
ID
1#ifndef __RFKILL_H
2#define __RFKILL_H
3
4/*
fe242cfd 5 * Copyright (C) 2006 - 2007 Ivo van Doorn
cf4328cd 6 * Copyright (C) 2007 Dmitry Torokhov
19d337df 7 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
cf4328cd
ID
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the
21 * Free Software Foundation, Inc.,
22 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 */
24
c64fb016 25#include <linux/types.h>
19d337df
JB
26
27/* define userspace visible states */
28#define RFKILL_STATE_SOFT_BLOCKED 0
29#define RFKILL_STATE_UNBLOCKED 1
30#define RFKILL_STATE_HARD_BLOCKED 2
31
cf4328cd
ID
32/**
33 * enum rfkill_type - type of rfkill switch.
19d337df 34 *
c64fb016 35 * @RFKILL_TYPE_ALL: toggles all switches (userspace only)
19d337df
JB
36 * @RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device.
37 * @RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth 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
cf4328cd
ID
42 */
43enum rfkill_type {
c64fb016 44 RFKILL_TYPE_ALL = 0,
19d337df 45 RFKILL_TYPE_WLAN,
234a0ca6 46 RFKILL_TYPE_BLUETOOTH,
e0665486 47 RFKILL_TYPE_UWB,
303d9bf6 48 RFKILL_TYPE_WIMAX,
477576a0 49 RFKILL_TYPE_WWAN,
19d337df 50 NUM_RFKILL_TYPES,
cf4328cd
ID
51};
52
c64fb016
JB
53/**
54 * enum rfkill_operation - operation types
55 * @RFKILL_OP_ADD: a device was added
56 * @RFKILL_OP_DEL: a device was removed
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,
65};
66
67/**
68 * struct rfkill_event - events for userspace on /dev/rfkill
69 * @idx: index of dev rfkill
70 * @type: type of the rfkill struct
71 * @op: operation code
72 * @hard: hard state (0/1)
73 * @soft: soft state (0/1)
74 *
75 * Structure used for userspace communication on /dev/rfkill,
76 * used for events from the kernel and control to the kernel.
77 */
78struct rfkill_event {
79 __u32 idx;
80 __u8 type;
81 __u8 op;
82 __u8 soft, hard;
83} __packed;
84
85/* ioctl for turning off rfkill-input (if present) */
86#define RFKILL_IOC_MAGIC 'R'
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
19d337df
JB
109/* this is opaque */
110struct rfkill;
111
112/**
113 * struct rfkill_ops - rfkill driver methods
114 *
115 * @poll: poll the rfkill block state(s) -- only assign this method
116 * when you need polling. When called, simply call one of the
117 * rfkill_set{,_hw,_sw}_state family of functions. If the hw
118 * is getting unblocked you need to take into account the return
119 * value of those functions to make sure the software block is
120 * properly used.
121 * @query: query the rfkill block state(s) and call exactly one of the
122 * rfkill_set{,_hw,_sw}_state family of functions. Assign this
123 * method if input events can cause hardware state changes to make
124 * the rfkill core query your driver before setting a requested
125 * block.
126 * @set_block: turn the transmitter on (blocked == false) or off
c64fb016 127 * (blocked == true) -- ignore and return 0 when hard blocked.
19d337df
JB
128 * This callback must be assigned.
129 */
130struct rfkill_ops {
131 void (*poll)(struct rfkill *rfkill, void *data);
132 void (*query)(struct rfkill *rfkill, void *data);
133 int (*set_block)(void *data, bool blocked);
cf4328cd
ID
134};
135
19d337df 136#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
cf4328cd 137/**
19d337df
JB
138 * rfkill_alloc - allocate rfkill structure
139 * @name: name of the struct -- the string is not copied internally
140 * @parent: device that has rf switch on it
141 * @type: type of the switch (RFKILL_TYPE_*)
142 * @ops: rfkill methods
143 * @ops_data: data passed to each method
144 *
145 * This function should be called by the transmitter driver to allocate an
146 * rfkill structure. Returns %NULL on failure.
cf4328cd 147 */
19d337df
JB
148struct rfkill * __must_check rfkill_alloc(const char *name,
149 struct device *parent,
150 const enum rfkill_type type,
151 const struct rfkill_ops *ops,
152 void *ops_data);
cf4328cd 153
19d337df
JB
154/**
155 * rfkill_register - Register a rfkill structure.
156 * @rfkill: rfkill structure to be registered
157 *
158 * This function should be called by the transmitter driver to register
159 * the rfkill structure needs to be registered. Before calling this function
160 * the driver needs to be ready to service method calls from rfkill.
161 */
162int __must_check rfkill_register(struct rfkill *rfkill);
135900c1 163
19d337df
JB
164/**
165 * rfkill_pause_polling(struct rfkill *rfkill)
166 *
167 * Pause polling -- say transmitter is off for other reasons.
168 * NOTE: not necessary for suspend/resume -- in that case the
169 * core stops polling anyway
170 */
171void rfkill_pause_polling(struct rfkill *rfkill);
cf4328cd 172
19d337df
JB
173/**
174 * rfkill_resume_polling(struct rfkill *rfkill)
175 *
176 * Pause polling -- say transmitter is off for other reasons.
177 * NOTE: not necessary for suspend/resume -- in that case the
178 * core stops polling anyway
179 */
180void rfkill_resume_polling(struct rfkill *rfkill);
181
182
183/**
184 * rfkill_unregister - Unregister a rfkill structure.
185 * @rfkill: rfkill structure to be unregistered
186 *
187 * This function should be called by the network driver during device
188 * teardown to destroy rfkill structure. Until it returns, the driver
189 * needs to be able to service method calls.
190 */
cf4328cd
ID
191void rfkill_unregister(struct rfkill *rfkill);
192
19d337df
JB
193/**
194 * rfkill_destroy - free rfkill structure
195 * @rfkill: rfkill structure to be destroyed
196 *
197 * Destroys the rfkill structure.
198 */
199void rfkill_destroy(struct rfkill *rfkill);
200
201/**
202 * rfkill_set_hw_state - Set the internal rfkill hardware block state
203 * @rfkill: pointer to the rfkill class to modify.
204 * @state: the current hardware block state to set
205 *
206 * rfkill drivers that get events when the hard-blocked state changes
207 * use this function to notify the rfkill core (and through that also
208 * userspace) of the current state -- they should also use this after
209 * resume if the state could have changed.
210 *
211 * You need not (but may) call this function if poll_state is assigned.
212 *
213 * This function can be called in any context, even from within rfkill
214 * callbacks.
215 *
216 * The function returns the combined block state (true if transmitter
217 * should be blocked) so that drivers need not keep track of the soft
218 * block state -- which they might not be able to.
219 */
220bool __must_check rfkill_set_hw_state(struct rfkill *rfkill, bool blocked);
221
222/**
223 * rfkill_set_sw_state - Set the internal rfkill software block state
224 * @rfkill: pointer to the rfkill class to modify.
225 * @state: the current software block state to set
226 *
227 * rfkill drivers that get events when the soft-blocked state changes
228 * (yes, some platforms directly act on input but allow changing again)
229 * use this function to notify the rfkill core (and through that also
230 * userspace) of the current state -- they should also use this after
231 * resume if the state could have changed.
232 *
233 * This function can be called in any context, even from within rfkill
234 * callbacks.
235 *
236 * The function returns the combined block state (true if transmitter
237 * should be blocked).
238 */
239bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked);
240
241/**
242 * rfkill_set_states - Set the internal rfkill block states
243 * @rfkill: pointer to the rfkill class to modify.
244 * @sw: the current software block state to set
245 * @hw: the current hardware block state to set
246 *
247 * This function can be called in any context, even from within rfkill
248 * callbacks.
249 */
250void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw);
801e49af 251
5005657c 252/**
19d337df
JB
253 * rfkill_set_global_sw_state - set global sw block default
254 * @type: rfkill type to set default for
255 * @blocked: default to set
5005657c 256 *
19d337df
JB
257 * This function sets the global default -- use at boot if your platform has
258 * an rfkill switch. If not early enough this call may be ignored.
259 *
260 * XXX: instead of ignoring -- how about just updating all currently
261 * registered drivers?
5005657c 262 */
19d337df 263void rfkill_set_global_sw_state(const enum rfkill_type type, bool blocked);
6081162e
JB
264
265/**
266 * rfkill_blocked - query rfkill block
267 *
268 * @rfkill: rfkill struct to query
269 */
270bool rfkill_blocked(struct rfkill *rfkill);
19d337df
JB
271#else /* !RFKILL */
272static inline struct rfkill * __must_check
273rfkill_alloc(const char *name,
274 struct device *parent,
275 const enum rfkill_type type,
276 const struct rfkill_ops *ops,
277 void *ops_data)
278{
279 return ERR_PTR(-ENODEV);
280}
281
282static inline int __must_check rfkill_register(struct rfkill *rfkill)
283{
284 if (rfkill == ERR_PTR(-ENODEV))
285 return 0;
286 return -EINVAL;
287}
288
289static inline void rfkill_pause_polling(struct rfkill *rfkill)
290{
291}
292
293static inline void rfkill_resume_polling(struct rfkill *rfkill)
294{
295}
296
297static inline void rfkill_unregister(struct rfkill *rfkill)
298{
299}
300
301static inline void rfkill_destroy(struct rfkill *rfkill)
302{
303}
304
305static inline bool rfkill_set_hw_state(struct rfkill *rfkill, bool blocked)
306{
307 return blocked;
308}
309
310static inline bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked)
311{
312 return blocked;
313}
314
315static inline void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw)
316{
317}
318
319static inline void rfkill_set_global_sw_state(const enum rfkill_type type,
320 bool blocked)
5005657c 321{
5005657c 322}
6081162e
JB
323
324static inline bool rfkill_blocked(struct rfkill *rfkill)
325{
326 return false;
327}
19d337df
JB
328#endif /* RFKILL || RFKILL_MODULE */
329
5005657c 330
19d337df 331#ifdef CONFIG_RFKILL_LEDS
135900c1 332/**
19d337df 333 * rfkill_get_led_trigger_name - Get the LED trigger name for the button's LED.
135900c1 334 * This function might return a NULL pointer if registering of the
19d337df 335 * LED trigger failed. Use this as "default_trigger" for the LED.
135900c1 336 */
19d337df
JB
337const char *rfkill_get_led_trigger_name(struct rfkill *rfkill);
338
339/**
340 * rfkill_set_led_trigger_name -- set the LED trigger name
341 * @rfkill: rfkill struct
342 * @name: LED trigger name
343 *
344 * This function sets the LED trigger name of the radio LED
345 * trigger that rfkill creates. It is optional, but if called
346 * must be called before rfkill_register() to be effective.
347 */
348void rfkill_set_led_trigger_name(struct rfkill *rfkill, const char *name);
135900c1 349#else
19d337df
JB
350static inline const char *rfkill_get_led_trigger_name(struct rfkill *rfkill)
351{
135900c1 352 return NULL;
135900c1
MB
353}
354
19d337df
JB
355static inline void
356rfkill_set_led_trigger_name(struct rfkill *rfkill, const char *name)
357{
358}
359#endif
360
361#endif /* __KERNEL__ */
362
cf4328cd 363#endif /* RFKILL_H */