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