]>
Commit | Line | Data |
---|---|---|
cf4328cd | 1 | /* |
fe242cfd | 2 | * Copyright (C) 2006 - 2007 Ivo van Doorn |
cf4328cd | 3 | * Copyright (C) 2007 Dmitry Torokhov |
19d337df | 4 | * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> |
cf4328cd | 5 | * |
8bc11b49 JB |
6 | * Permission to use, copy, modify, and/or distribute this software for any |
7 | * purpose with or without fee is hereby granted, provided that the above | |
8 | * copyright notice and this permission notice appear in all copies. | |
cf4328cd | 9 | * |
8bc11b49 JB |
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
cf4328cd | 17 | */ |
607ca46e DH |
18 | #ifndef __RFKILL_H |
19 | #define __RFKILL_H | |
cf4328cd | 20 | |
607ca46e | 21 | #include <uapi/linux/rfkill.h> |
c64fb016 | 22 | |
c64fb016 JB |
23 | /* don't allow anyone to use these in the kernel */ |
24 | enum rfkill_user_states { | |
25 | RFKILL_USER_STATE_SOFT_BLOCKED = RFKILL_STATE_SOFT_BLOCKED, | |
26 | RFKILL_USER_STATE_UNBLOCKED = RFKILL_STATE_UNBLOCKED, | |
27 | RFKILL_USER_STATE_HARD_BLOCKED = RFKILL_STATE_HARD_BLOCKED, | |
28 | }; | |
29 | #undef RFKILL_STATE_SOFT_BLOCKED | |
30 | #undef RFKILL_STATE_UNBLOCKED | |
31 | #undef RFKILL_STATE_HARD_BLOCKED | |
32 | ||
c64fb016 JB |
33 | #include <linux/kernel.h> |
34 | #include <linux/list.h> | |
35 | #include <linux/mutex.h> | |
c64fb016 | 36 | #include <linux/leds.h> |
1506e30b | 37 | #include <linux/err.h> |
c64fb016 | 38 | |
313162d0 | 39 | struct device; |
19d337df JB |
40 | /* this is opaque */ |
41 | struct rfkill; | |
42 | ||
43 | /** | |
44 | * struct rfkill_ops - rfkill driver methods | |
45 | * | |
46 | * @poll: poll the rfkill block state(s) -- only assign this method | |
47 | * when you need polling. When called, simply call one of the | |
48 | * rfkill_set{,_hw,_sw}_state family of functions. If the hw | |
49 | * is getting unblocked you need to take into account the return | |
50 | * value of those functions to make sure the software block is | |
51 | * properly used. | |
52 | * @query: query the rfkill block state(s) and call exactly one of the | |
53 | * rfkill_set{,_hw,_sw}_state family of functions. Assign this | |
54 | * method if input events can cause hardware state changes to make | |
55 | * the rfkill core query your driver before setting a requested | |
56 | * block. | |
57 | * @set_block: turn the transmitter on (blocked == false) or off | |
c64fb016 | 58 | * (blocked == true) -- ignore and return 0 when hard blocked. |
19d337df JB |
59 | * This callback must be assigned. |
60 | */ | |
61 | struct rfkill_ops { | |
62 | void (*poll)(struct rfkill *rfkill, void *data); | |
63 | void (*query)(struct rfkill *rfkill, void *data); | |
64 | int (*set_block)(void *data, bool blocked); | |
cf4328cd ID |
65 | }; |
66 | ||
19d337df | 67 | #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE) |
cf4328cd | 68 | /** |
2d4f545c | 69 | * rfkill_alloc - Allocate rfkill structure |
19d337df JB |
70 | * @name: name of the struct -- the string is not copied internally |
71 | * @parent: device that has rf switch on it | |
72 | * @type: type of the switch (RFKILL_TYPE_*) | |
73 | * @ops: rfkill methods | |
74 | * @ops_data: data passed to each method | |
75 | * | |
76 | * This function should be called by the transmitter driver to allocate an | |
77 | * rfkill structure. Returns %NULL on failure. | |
cf4328cd | 78 | */ |
19d337df JB |
79 | struct rfkill * __must_check rfkill_alloc(const char *name, |
80 | struct device *parent, | |
81 | const enum rfkill_type type, | |
82 | const struct rfkill_ops *ops, | |
83 | void *ops_data); | |
cf4328cd | 84 | |
19d337df JB |
85 | /** |
86 | * rfkill_register - Register a rfkill structure. | |
87 | * @rfkill: rfkill structure to be registered | |
88 | * | |
89 | * This function should be called by the transmitter driver to register | |
b3fa1329 AJ |
90 | * the rfkill structure. Before calling this function the driver needs |
91 | * to be ready to service method calls from rfkill. | |
92 | * | |
06d5caf4 AJ |
93 | * If rfkill_init_sw_state() is not called before registration, |
94 | * set_block() will be called to initialize the software blocked state | |
95 | * to a default value. | |
b3fa1329 AJ |
96 | * |
97 | * If the hardware blocked state is not set before registration, | |
98 | * it is assumed to be unblocked. | |
19d337df JB |
99 | */ |
100 | int __must_check rfkill_register(struct rfkill *rfkill); | |
135900c1 | 101 | |
19d337df JB |
102 | /** |
103 | * rfkill_pause_polling(struct rfkill *rfkill) | |
104 | * | |
105 | * Pause polling -- say transmitter is off for other reasons. | |
106 | * NOTE: not necessary for suspend/resume -- in that case the | |
dd21dfc6 JB |
107 | * core stops polling anyway (but will also correctly handle |
108 | * the case of polling having been paused before suspend.) | |
19d337df JB |
109 | */ |
110 | void rfkill_pause_polling(struct rfkill *rfkill); | |
cf4328cd | 111 | |
19d337df JB |
112 | /** |
113 | * rfkill_resume_polling(struct rfkill *rfkill) | |
114 | * | |
2d4f545c | 115 | * Resume polling |
19d337df JB |
116 | * NOTE: not necessary for suspend/resume -- in that case the |
117 | * core stops polling anyway | |
118 | */ | |
119 | void rfkill_resume_polling(struct rfkill *rfkill); | |
120 | ||
121 | ||
122 | /** | |
123 | * rfkill_unregister - Unregister a rfkill structure. | |
124 | * @rfkill: rfkill structure to be unregistered | |
125 | * | |
126 | * This function should be called by the network driver during device | |
127 | * teardown to destroy rfkill structure. Until it returns, the driver | |
128 | * needs to be able to service method calls. | |
129 | */ | |
cf4328cd ID |
130 | void rfkill_unregister(struct rfkill *rfkill); |
131 | ||
19d337df | 132 | /** |
2d4f545c | 133 | * rfkill_destroy - Free rfkill structure |
19d337df JB |
134 | * @rfkill: rfkill structure to be destroyed |
135 | * | |
136 | * Destroys the rfkill structure. | |
137 | */ | |
138 | void rfkill_destroy(struct rfkill *rfkill); | |
139 | ||
14486c82 EG |
140 | /** |
141 | * rfkill_set_hw_state_reason - Set the internal rfkill hardware block state | |
142 | * with a reason | |
143 | * @rfkill: pointer to the rfkill class to modify. | |
144 | * @blocked: the current hardware block state to set | |
145 | * @reason: one of &enum rfkill_hard_block_reasons | |
146 | * | |
147 | * Prefer to use rfkill_set_hw_state if you don't need any special reason. | |
148 | */ | |
149 | bool rfkill_set_hw_state_reason(struct rfkill *rfkill, | |
150 | bool blocked, unsigned long reason); | |
19d337df JB |
151 | /** |
152 | * rfkill_set_hw_state - Set the internal rfkill hardware block state | |
153 | * @rfkill: pointer to the rfkill class to modify. | |
2d4f545c | 154 | * @blocked: the current hardware block state to set |
19d337df JB |
155 | * |
156 | * rfkill drivers that get events when the hard-blocked state changes | |
157 | * use this function to notify the rfkill core (and through that also | |
908209c1 | 158 | * userspace) of the current state. They should also use this after |
19d337df JB |
159 | * resume if the state could have changed. |
160 | * | |
161 | * You need not (but may) call this function if poll_state is assigned. | |
162 | * | |
163 | * This function can be called in any context, even from within rfkill | |
164 | * callbacks. | |
165 | * | |
166 | * The function returns the combined block state (true if transmitter | |
167 | * should be blocked) so that drivers need not keep track of the soft | |
168 | * block state -- which they might not be able to. | |
169 | */ | |
14486c82 EG |
170 | static inline bool rfkill_set_hw_state(struct rfkill *rfkill, bool blocked) |
171 | { | |
172 | return rfkill_set_hw_state_reason(rfkill, blocked, | |
173 | RFKILL_HARD_BLOCK_SIGNAL); | |
174 | } | |
19d337df JB |
175 | |
176 | /** | |
177 | * rfkill_set_sw_state - Set the internal rfkill software block state | |
178 | * @rfkill: pointer to the rfkill class to modify. | |
2d4f545c | 179 | * @blocked: the current software block state to set |
19d337df JB |
180 | * |
181 | * rfkill drivers that get events when the soft-blocked state changes | |
182 | * (yes, some platforms directly act on input but allow changing again) | |
183 | * use this function to notify the rfkill core (and through that also | |
06d5caf4 AJ |
184 | * userspace) of the current state. |
185 | * | |
186 | * Drivers should also call this function after resume if the state has | |
187 | * been changed by the user. This only makes sense for "persistent" | |
188 | * devices (see rfkill_init_sw_state()). | |
19d337df JB |
189 | * |
190 | * This function can be called in any context, even from within rfkill | |
191 | * callbacks. | |
192 | * | |
193 | * The function returns the combined block state (true if transmitter | |
194 | * should be blocked). | |
195 | */ | |
196 | bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked); | |
197 | ||
06d5caf4 AJ |
198 | /** |
199 | * rfkill_init_sw_state - Initialize persistent software block state | |
200 | * @rfkill: pointer to the rfkill class to modify. | |
2d4f545c | 201 | * @blocked: the current software block state to set |
06d5caf4 AJ |
202 | * |
203 | * rfkill drivers that preserve their software block state over power off | |
204 | * use this function to notify the rfkill core (and through that also | |
205 | * userspace) of their initial state. It should only be used before | |
206 | * registration. | |
207 | * | |
464902e8 AJ |
208 | * In addition, it marks the device as "persistent", an attribute which |
209 | * can be read by userspace. Persistent devices are expected to preserve | |
210 | * their own state when suspended. | |
06d5caf4 AJ |
211 | */ |
212 | void rfkill_init_sw_state(struct rfkill *rfkill, bool blocked); | |
213 | ||
19d337df JB |
214 | /** |
215 | * rfkill_set_states - Set the internal rfkill block states | |
216 | * @rfkill: pointer to the rfkill class to modify. | |
217 | * @sw: the current software block state to set | |
218 | * @hw: the current hardware block state to set | |
219 | * | |
220 | * This function can be called in any context, even from within rfkill | |
221 | * callbacks. | |
222 | */ | |
223 | void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw); | |
801e49af | 224 | |
6081162e | 225 | /** |
2d4f545c | 226 | * rfkill_blocked - Query rfkill block state |
6081162e JB |
227 | * |
228 | * @rfkill: rfkill struct to query | |
229 | */ | |
230 | bool rfkill_blocked(struct rfkill *rfkill); | |
648b50dd HK |
231 | |
232 | /** | |
2d4f545c | 233 | * rfkill_find_type - Helper for finding rfkill type by name |
648b50dd HK |
234 | * @name: the name of the type |
235 | * | |
2d4f545c | 236 | * Returns enum rfkill_type that corresponds to the name. |
648b50dd HK |
237 | */ |
238 | enum rfkill_type rfkill_find_type(const char *name); | |
239 | ||
19d337df JB |
240 | #else /* !RFKILL */ |
241 | static inline struct rfkill * __must_check | |
242 | rfkill_alloc(const char *name, | |
243 | struct device *parent, | |
244 | const enum rfkill_type type, | |
245 | const struct rfkill_ops *ops, | |
246 | void *ops_data) | |
247 | { | |
248 | return ERR_PTR(-ENODEV); | |
249 | } | |
250 | ||
251 | static inline int __must_check rfkill_register(struct rfkill *rfkill) | |
252 | { | |
253 | if (rfkill == ERR_PTR(-ENODEV)) | |
254 | return 0; | |
255 | return -EINVAL; | |
256 | } | |
257 | ||
258 | static inline void rfkill_pause_polling(struct rfkill *rfkill) | |
259 | { | |
260 | } | |
261 | ||
262 | static inline void rfkill_resume_polling(struct rfkill *rfkill) | |
263 | { | |
264 | } | |
265 | ||
266 | static inline void rfkill_unregister(struct rfkill *rfkill) | |
267 | { | |
268 | } | |
269 | ||
270 | static inline void rfkill_destroy(struct rfkill *rfkill) | |
271 | { | |
272 | } | |
273 | ||
14486c82 EG |
274 | static inline bool rfkill_set_hw_state_reason(struct rfkill *rfkill, |
275 | bool blocked, | |
276 | unsigned long reason) | |
277 | { | |
278 | return blocked; | |
279 | } | |
280 | ||
19d337df JB |
281 | static inline bool rfkill_set_hw_state(struct rfkill *rfkill, bool blocked) |
282 | { | |
283 | return blocked; | |
284 | } | |
285 | ||
286 | static inline bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked) | |
287 | { | |
288 | return blocked; | |
289 | } | |
290 | ||
06d5caf4 AJ |
291 | static inline void rfkill_init_sw_state(struct rfkill *rfkill, bool blocked) |
292 | { | |
293 | } | |
294 | ||
19d337df JB |
295 | static inline void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw) |
296 | { | |
297 | } | |
298 | ||
6081162e JB |
299 | static inline bool rfkill_blocked(struct rfkill *rfkill) |
300 | { | |
301 | return false; | |
302 | } | |
648b50dd HK |
303 | |
304 | static inline enum rfkill_type rfkill_find_type(const char *name) | |
305 | { | |
306 | return RFKILL_TYPE_ALL; | |
307 | } | |
308 | ||
19d337df JB |
309 | #endif /* RFKILL || RFKILL_MODULE */ |
310 | ||
06d7de83 AK |
311 | |
312 | #ifdef CONFIG_RFKILL_LEDS | |
313 | /** | |
314 | * rfkill_get_led_trigger_name - Get the LED trigger name for the button's LED. | |
315 | * This function might return a NULL pointer if registering of the | |
316 | * LED trigger failed. Use this as "default_trigger" for the LED. | |
317 | */ | |
318 | const char *rfkill_get_led_trigger_name(struct rfkill *rfkill); | |
319 | ||
320 | /** | |
2d4f545c | 321 | * rfkill_set_led_trigger_name - Set the LED trigger name |
06d7de83 AK |
322 | * @rfkill: rfkill struct |
323 | * @name: LED trigger name | |
324 | * | |
325 | * This function sets the LED trigger name of the radio LED | |
326 | * trigger that rfkill creates. It is optional, but if called | |
327 | * must be called before rfkill_register() to be effective. | |
328 | */ | |
329 | void rfkill_set_led_trigger_name(struct rfkill *rfkill, const char *name); | |
330 | #else | |
331 | static inline const char *rfkill_get_led_trigger_name(struct rfkill *rfkill) | |
332 | { | |
333 | return NULL; | |
334 | } | |
335 | ||
336 | static inline void | |
337 | rfkill_set_led_trigger_name(struct rfkill *rfkill, const char *name) | |
338 | { | |
339 | } | |
340 | #endif | |
341 | ||
cf4328cd | 342 | #endif /* RFKILL_H */ |