Commit | Line | Data |
---|---|---|
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 | ||
19d337df JB |
25 | |
26 | /* define userspace visible states */ | |
27 | #define RFKILL_STATE_SOFT_BLOCKED 0 | |
28 | #define RFKILL_STATE_UNBLOCKED 1 | |
29 | #define RFKILL_STATE_HARD_BLOCKED 2 | |
30 | ||
31 | /* and that's all userspace gets */ | |
32 | #ifdef __KERNEL__ | |
33 | /* don't allow anyone to use these in the kernel */ | |
34 | enum rfkill_user_states { | |
35 | RFKILL_USER_STATE_SOFT_BLOCKED = RFKILL_STATE_SOFT_BLOCKED, | |
36 | RFKILL_USER_STATE_UNBLOCKED = RFKILL_STATE_UNBLOCKED, | |
37 | RFKILL_USER_STATE_HARD_BLOCKED = RFKILL_STATE_HARD_BLOCKED, | |
38 | }; | |
39 | #undef RFKILL_STATE_SOFT_BLOCKED | |
40 | #undef RFKILL_STATE_UNBLOCKED | |
41 | #undef RFKILL_STATE_HARD_BLOCKED | |
42 | ||
cf4328cd ID |
43 | #include <linux/types.h> |
44 | #include <linux/kernel.h> | |
45 | #include <linux/list.h> | |
46 | #include <linux/mutex.h> | |
47 | #include <linux/device.h> | |
135900c1 | 48 | #include <linux/leds.h> |
cf4328cd ID |
49 | |
50 | /** | |
51 | * enum rfkill_type - type of rfkill switch. | |
19d337df JB |
52 | * |
53 | * @RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device. | |
54 | * @RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device. | |
55 | * @RFKILL_TYPE_UWB: switch is on a ultra wideband device. | |
56 | * @RFKILL_TYPE_WIMAX: switch is on a WiMAX device. | |
57 | * @RFKILL_TYPE_WWAN: switch is on a wireless WAN device. | |
58 | * @NUM_RFKILL_TYPES: number of defined rfkill types | |
cf4328cd ID |
59 | */ |
60 | enum rfkill_type { | |
19d337df | 61 | RFKILL_TYPE_WLAN, |
234a0ca6 | 62 | RFKILL_TYPE_BLUETOOTH, |
e0665486 | 63 | RFKILL_TYPE_UWB, |
303d9bf6 | 64 | RFKILL_TYPE_WIMAX, |
477576a0 | 65 | RFKILL_TYPE_WWAN, |
19d337df | 66 | NUM_RFKILL_TYPES, |
cf4328cd ID |
67 | }; |
68 | ||
19d337df JB |
69 | /* this is opaque */ |
70 | struct rfkill; | |
71 | ||
72 | /** | |
73 | * struct rfkill_ops - rfkill driver methods | |
74 | * | |
75 | * @poll: poll the rfkill block state(s) -- only assign this method | |
76 | * when you need polling. When called, simply call one of the | |
77 | * rfkill_set{,_hw,_sw}_state family of functions. If the hw | |
78 | * is getting unblocked you need to take into account the return | |
79 | * value of those functions to make sure the software block is | |
80 | * properly used. | |
81 | * @query: query the rfkill block state(s) and call exactly one of the | |
82 | * rfkill_set{,_hw,_sw}_state family of functions. Assign this | |
83 | * method if input events can cause hardware state changes to make | |
84 | * the rfkill core query your driver before setting a requested | |
85 | * block. | |
86 | * @set_block: turn the transmitter on (blocked == false) or off | |
87 | * (blocked == true) -- this is called only while the transmitter | |
88 | * is not hard-blocked, but note that the core's view of whether | |
89 | * the transmitter is hard-blocked might differ from your driver's | |
90 | * view due to race conditions, so it is possible that it is still | |
91 | * called at the same time as you are calling rfkill_set_hw_state(). | |
92 | * This callback must be assigned. | |
93 | */ | |
94 | struct rfkill_ops { | |
95 | void (*poll)(struct rfkill *rfkill, void *data); | |
96 | void (*query)(struct rfkill *rfkill, void *data); | |
97 | int (*set_block)(void *data, bool blocked); | |
cf4328cd ID |
98 | }; |
99 | ||
19d337df | 100 | #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE) |
cf4328cd | 101 | /** |
19d337df JB |
102 | * rfkill_alloc - allocate rfkill structure |
103 | * @name: name of the struct -- the string is not copied internally | |
104 | * @parent: device that has rf switch on it | |
105 | * @type: type of the switch (RFKILL_TYPE_*) | |
106 | * @ops: rfkill methods | |
107 | * @ops_data: data passed to each method | |
108 | * | |
109 | * This function should be called by the transmitter driver to allocate an | |
110 | * rfkill structure. Returns %NULL on failure. | |
cf4328cd | 111 | */ |
19d337df JB |
112 | struct rfkill * __must_check rfkill_alloc(const char *name, |
113 | struct device *parent, | |
114 | const enum rfkill_type type, | |
115 | const struct rfkill_ops *ops, | |
116 | void *ops_data); | |
cf4328cd | 117 | |
19d337df JB |
118 | /** |
119 | * rfkill_register - Register a rfkill structure. | |
120 | * @rfkill: rfkill structure to be registered | |
121 | * | |
122 | * This function should be called by the transmitter driver to register | |
123 | * the rfkill structure needs to be registered. Before calling this function | |
124 | * the driver needs to be ready to service method calls from rfkill. | |
125 | */ | |
126 | int __must_check rfkill_register(struct rfkill *rfkill); | |
135900c1 | 127 | |
19d337df JB |
128 | /** |
129 | * rfkill_pause_polling(struct rfkill *rfkill) | |
130 | * | |
131 | * Pause polling -- say transmitter is off for other reasons. | |
132 | * NOTE: not necessary for suspend/resume -- in that case the | |
133 | * core stops polling anyway | |
134 | */ | |
135 | void rfkill_pause_polling(struct rfkill *rfkill); | |
cf4328cd | 136 | |
19d337df JB |
137 | /** |
138 | * rfkill_resume_polling(struct rfkill *rfkill) | |
139 | * | |
140 | * Pause polling -- say transmitter is off for other reasons. | |
141 | * NOTE: not necessary for suspend/resume -- in that case the | |
142 | * core stops polling anyway | |
143 | */ | |
144 | void rfkill_resume_polling(struct rfkill *rfkill); | |
145 | ||
146 | ||
147 | /** | |
148 | * rfkill_unregister - Unregister a rfkill structure. | |
149 | * @rfkill: rfkill structure to be unregistered | |
150 | * | |
151 | * This function should be called by the network driver during device | |
152 | * teardown to destroy rfkill structure. Until it returns, the driver | |
153 | * needs to be able to service method calls. | |
154 | */ | |
cf4328cd ID |
155 | void rfkill_unregister(struct rfkill *rfkill); |
156 | ||
19d337df JB |
157 | /** |
158 | * rfkill_destroy - free rfkill structure | |
159 | * @rfkill: rfkill structure to be destroyed | |
160 | * | |
161 | * Destroys the rfkill structure. | |
162 | */ | |
163 | void rfkill_destroy(struct rfkill *rfkill); | |
164 | ||
165 | /** | |
166 | * rfkill_set_hw_state - Set the internal rfkill hardware block state | |
167 | * @rfkill: pointer to the rfkill class to modify. | |
168 | * @state: the current hardware block state to set | |
169 | * | |
170 | * rfkill drivers that get events when the hard-blocked state changes | |
171 | * use this function to notify the rfkill core (and through that also | |
172 | * userspace) of the current state -- they should also use this after | |
173 | * resume if the state could have changed. | |
174 | * | |
175 | * You need not (but may) call this function if poll_state is assigned. | |
176 | * | |
177 | * This function can be called in any context, even from within rfkill | |
178 | * callbacks. | |
179 | * | |
180 | * The function returns the combined block state (true if transmitter | |
181 | * should be blocked) so that drivers need not keep track of the soft | |
182 | * block state -- which they might not be able to. | |
183 | */ | |
184 | bool __must_check rfkill_set_hw_state(struct rfkill *rfkill, bool blocked); | |
185 | ||
186 | /** | |
187 | * rfkill_set_sw_state - Set the internal rfkill software block state | |
188 | * @rfkill: pointer to the rfkill class to modify. | |
189 | * @state: the current software block state to set | |
190 | * | |
191 | * rfkill drivers that get events when the soft-blocked state changes | |
192 | * (yes, some platforms directly act on input but allow changing again) | |
193 | * use this function to notify the rfkill core (and through that also | |
194 | * userspace) of the current state -- they should also use this after | |
195 | * resume if the state could have changed. | |
196 | * | |
197 | * This function can be called in any context, even from within rfkill | |
198 | * callbacks. | |
199 | * | |
200 | * The function returns the combined block state (true if transmitter | |
201 | * should be blocked). | |
202 | */ | |
203 | bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked); | |
204 | ||
205 | /** | |
206 | * rfkill_set_states - Set the internal rfkill block states | |
207 | * @rfkill: pointer to the rfkill class to modify. | |
208 | * @sw: the current software block state to set | |
209 | * @hw: the current hardware block state to set | |
210 | * | |
211 | * This function can be called in any context, even from within rfkill | |
212 | * callbacks. | |
213 | */ | |
214 | void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw); | |
801e49af | 215 | |
5005657c | 216 | /** |
19d337df JB |
217 | * rfkill_set_global_sw_state - set global sw block default |
218 | * @type: rfkill type to set default for | |
219 | * @blocked: default to set | |
5005657c | 220 | * |
19d337df JB |
221 | * This function sets the global default -- use at boot if your platform has |
222 | * an rfkill switch. If not early enough this call may be ignored. | |
223 | * | |
224 | * XXX: instead of ignoring -- how about just updating all currently | |
225 | * registered drivers? | |
5005657c | 226 | */ |
19d337df JB |
227 | void rfkill_set_global_sw_state(const enum rfkill_type type, bool blocked); |
228 | #else /* !RFKILL */ | |
229 | static inline struct rfkill * __must_check | |
230 | rfkill_alloc(const char *name, | |
231 | struct device *parent, | |
232 | const enum rfkill_type type, | |
233 | const struct rfkill_ops *ops, | |
234 | void *ops_data) | |
235 | { | |
236 | return ERR_PTR(-ENODEV); | |
237 | } | |
238 | ||
239 | static inline int __must_check rfkill_register(struct rfkill *rfkill) | |
240 | { | |
241 | if (rfkill == ERR_PTR(-ENODEV)) | |
242 | return 0; | |
243 | return -EINVAL; | |
244 | } | |
245 | ||
246 | static inline void rfkill_pause_polling(struct rfkill *rfkill) | |
247 | { | |
248 | } | |
249 | ||
250 | static inline void rfkill_resume_polling(struct rfkill *rfkill) | |
251 | { | |
252 | } | |
253 | ||
254 | static inline void rfkill_unregister(struct rfkill *rfkill) | |
255 | { | |
256 | } | |
257 | ||
258 | static inline void rfkill_destroy(struct rfkill *rfkill) | |
259 | { | |
260 | } | |
261 | ||
262 | static inline bool rfkill_set_hw_state(struct rfkill *rfkill, bool blocked) | |
263 | { | |
264 | return blocked; | |
265 | } | |
266 | ||
267 | static inline bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked) | |
268 | { | |
269 | return blocked; | |
270 | } | |
271 | ||
272 | static inline void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw) | |
273 | { | |
274 | } | |
275 | ||
276 | static inline void rfkill_set_global_sw_state(const enum rfkill_type type, | |
277 | bool blocked) | |
5005657c | 278 | { |
5005657c | 279 | } |
19d337df JB |
280 | #endif /* RFKILL || RFKILL_MODULE */ |
281 | ||
5005657c | 282 | |
19d337df | 283 | #ifdef CONFIG_RFKILL_LEDS |
135900c1 | 284 | /** |
19d337df | 285 | * rfkill_get_led_trigger_name - Get the LED trigger name for the button's LED. |
135900c1 | 286 | * This function might return a NULL pointer if registering of the |
19d337df | 287 | * LED trigger failed. Use this as "default_trigger" for the LED. |
135900c1 | 288 | */ |
19d337df JB |
289 | const char *rfkill_get_led_trigger_name(struct rfkill *rfkill); |
290 | ||
291 | /** | |
292 | * rfkill_set_led_trigger_name -- set the LED trigger name | |
293 | * @rfkill: rfkill struct | |
294 | * @name: LED trigger name | |
295 | * | |
296 | * This function sets the LED trigger name of the radio LED | |
297 | * trigger that rfkill creates. It is optional, but if called | |
298 | * must be called before rfkill_register() to be effective. | |
299 | */ | |
300 | void rfkill_set_led_trigger_name(struct rfkill *rfkill, const char *name); | |
135900c1 | 301 | #else |
19d337df JB |
302 | static inline const char *rfkill_get_led_trigger_name(struct rfkill *rfkill) |
303 | { | |
135900c1 | 304 | return NULL; |
135900c1 MB |
305 | } |
306 | ||
19d337df JB |
307 | static inline void |
308 | rfkill_set_led_trigger_name(struct rfkill *rfkill, const char *name) | |
309 | { | |
310 | } | |
311 | #endif | |
312 | ||
313 | #endif /* __KERNEL__ */ | |
314 | ||
cf4328cd | 315 | #endif /* RFKILL_H */ |