Blame view

include/linux/rfkill.h 9.89 KB
cf4328cd9   Ivo van Doorn   [NET]: rfkill: ad...
1
  /*
fe242cfd3   Ivo van Doorn   [RFKILL]: Move rf...
2
   * Copyright (C) 2006 - 2007 Ivo van Doorn
cf4328cd9   Ivo van Doorn   [NET]: rfkill: ad...
3
   * Copyright (C) 2007 Dmitry Torokhov
19d337dff   Johannes Berg   rfkill: rewrite
4
   * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
cf4328cd9   Ivo van Doorn   [NET]: rfkill: ad...
5
   *
8bc11b491   Johannes Berg   rfkill: relicense...
6
7
8
   * Permission to use, copy, modify, and/or distribute this software for any
   * purpose with or without fee is hereby granted, provided that the above
   * copyright notice and this permission notice appear in all copies.
cf4328cd9   Ivo van Doorn   [NET]: rfkill: ad...
9
   *
8bc11b491   Johannes Berg   rfkill: relicense...
10
11
12
13
14
15
16
   * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
   * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
   * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
   * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
   * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
   * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
   * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
cf4328cd9   Ivo van Doorn   [NET]: rfkill: ad...
17
   */
607ca46e9   David Howells   UAPI: (Scripted) ...
18
19
  #ifndef __RFKILL_H
  #define __RFKILL_H
cf4328cd9   Ivo van Doorn   [NET]: rfkill: ad...
20

607ca46e9   David Howells   UAPI: (Scripted) ...
21
  #include <uapi/linux/rfkill.h>
c64fb0162   Johannes Berg   rfkill: create us...
22

c64fb0162   Johannes Berg   rfkill: create us...
23
24
25
26
27
28
29
30
31
  /* don't allow anyone to use these in the kernel */
  enum rfkill_user_states {
  	RFKILL_USER_STATE_SOFT_BLOCKED	= RFKILL_STATE_SOFT_BLOCKED,
  	RFKILL_USER_STATE_UNBLOCKED	= RFKILL_STATE_UNBLOCKED,
  	RFKILL_USER_STATE_HARD_BLOCKED	= RFKILL_STATE_HARD_BLOCKED,
  };
  #undef RFKILL_STATE_SOFT_BLOCKED
  #undef RFKILL_STATE_UNBLOCKED
  #undef RFKILL_STATE_HARD_BLOCKED
c64fb0162   Johannes Berg   rfkill: create us...
32
33
34
  #include <linux/kernel.h>
  #include <linux/list.h>
  #include <linux/mutex.h>
c64fb0162   Johannes Berg   rfkill: create us...
35
  #include <linux/leds.h>
1506e30b5   Johannes Berg   rfkill: include e...
36
  #include <linux/err.h>
c64fb0162   Johannes Berg   rfkill: create us...
37

313162d0b   Paul Gortmaker   device.h: audit a...
38
  struct device;
19d337dff   Johannes Berg   rfkill: rewrite
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  /* this is opaque */
  struct rfkill;
  
  /**
   * struct rfkill_ops - rfkill driver methods
   *
   * @poll: poll the rfkill block state(s) -- only assign this method
   *	when you need polling. When called, simply call one of the
   *	rfkill_set{,_hw,_sw}_state family of functions. If the hw
   *	is getting unblocked you need to take into account the return
   *	value of those functions to make sure the software block is
   *	properly used.
   * @query: query the rfkill block state(s) and call exactly one of the
   *	rfkill_set{,_hw,_sw}_state family of functions. Assign this
   *	method if input events can cause hardware state changes to make
   *	the rfkill core query your driver before setting a requested
   *	block.
   * @set_block: turn the transmitter on (blocked == false) or off
c64fb0162   Johannes Berg   rfkill: create us...
57
   *	(blocked == true) -- ignore and return 0 when hard blocked.
19d337dff   Johannes Berg   rfkill: rewrite
58
59
60
61
62
63
   *	This callback must be assigned.
   */
  struct rfkill_ops {
  	void	(*poll)(struct rfkill *rfkill, void *data);
  	void	(*query)(struct rfkill *rfkill, void *data);
  	int	(*set_block)(void *data, bool blocked);
cf4328cd9   Ivo van Doorn   [NET]: rfkill: ad...
64
  };
19d337dff   Johannes Berg   rfkill: rewrite
65
  #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
cf4328cd9   Ivo van Doorn   [NET]: rfkill: ad...
66
  /**
19d337dff   Johannes Berg   rfkill: rewrite
67
68
69
70
71
72
73
74
75
   * rfkill_alloc - allocate rfkill structure
   * @name: name of the struct -- the string is not copied internally
   * @parent: device that has rf switch on it
   * @type: type of the switch (RFKILL_TYPE_*)
   * @ops: rfkill methods
   * @ops_data: data passed to each method
   *
   * This function should be called by the transmitter driver to allocate an
   * rfkill structure. Returns %NULL on failure.
cf4328cd9   Ivo van Doorn   [NET]: rfkill: ad...
76
   */
19d337dff   Johannes Berg   rfkill: rewrite
77
78
79
80
81
  struct rfkill * __must_check rfkill_alloc(const char *name,
  					  struct device *parent,
  					  const enum rfkill_type type,
  					  const struct rfkill_ops *ops,
  					  void *ops_data);
cf4328cd9   Ivo van Doorn   [NET]: rfkill: ad...
82

19d337dff   Johannes Berg   rfkill: rewrite
83
84
85
86
87
  /**
   * rfkill_register - Register a rfkill structure.
   * @rfkill: rfkill structure to be registered
   *
   * This function should be called by the transmitter driver to register
b3fa1329e   Alan Jenkins   rfkill: remove se...
88
89
90
   * the rfkill structure. Before calling this function the driver needs
   * to be ready to service method calls from rfkill.
   *
06d5caf47   Alan Jenkins   rfkill: don't res...
91
92
93
   * If rfkill_init_sw_state() is not called before registration,
   * set_block() will be called to initialize the software blocked state
   * to a default value.
b3fa1329e   Alan Jenkins   rfkill: remove se...
94
95
96
   *
   * If the hardware blocked state is not set before registration,
   * it is assumed to be unblocked.
19d337dff   Johannes Berg   rfkill: rewrite
97
98
   */
  int __must_check rfkill_register(struct rfkill *rfkill);
135900c18   Michael Buesch   [RFKILL]: Add sup...
99

19d337dff   Johannes Berg   rfkill: rewrite
100
101
102
103
104
  /**
   * rfkill_pause_polling(struct rfkill *rfkill)
   *
   * Pause polling -- say transmitter is off for other reasons.
   * NOTE: not necessary for suspend/resume -- in that case the
dd21dfc64   Johannes Berg   rfkill: disentang...
105
106
   * core stops polling anyway (but will also correctly handle
   * the case of polling having been paused before suspend.)
19d337dff   Johannes Berg   rfkill: rewrite
107
108
   */
  void rfkill_pause_polling(struct rfkill *rfkill);
cf4328cd9   Ivo van Doorn   [NET]: rfkill: ad...
109

19d337dff   Johannes Berg   rfkill: rewrite
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
  /**
   * rfkill_resume_polling(struct rfkill *rfkill)
   *
   * Pause polling -- say transmitter is off for other reasons.
   * NOTE: not necessary for suspend/resume -- in that case the
   * core stops polling anyway
   */
  void rfkill_resume_polling(struct rfkill *rfkill);
  
  
  /**
   * rfkill_unregister - Unregister a rfkill structure.
   * @rfkill: rfkill structure to be unregistered
   *
   * This function should be called by the network driver during device
   * teardown to destroy rfkill structure. Until it returns, the driver
   * needs to be able to service method calls.
   */
cf4328cd9   Ivo van Doorn   [NET]: rfkill: ad...
128
  void rfkill_unregister(struct rfkill *rfkill);
19d337dff   Johannes Berg   rfkill: rewrite
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
  /**
   * rfkill_destroy - free rfkill structure
   * @rfkill: rfkill structure to be destroyed
   *
   * Destroys the rfkill structure.
   */
  void rfkill_destroy(struct rfkill *rfkill);
  
  /**
   * rfkill_set_hw_state - Set the internal rfkill hardware block state
   * @rfkill: pointer to the rfkill class to modify.
   * @state: the current hardware block state to set
   *
   * rfkill drivers that get events when the hard-blocked state changes
   * use this function to notify the rfkill core (and through that also
908209c16   Alan Jenkins   rfkill: don't imp...
144
   * userspace) of the current state.  They should also use this after
19d337dff   Johannes Berg   rfkill: rewrite
145
146
147
148
149
150
151
152
153
154
155
   * resume if the state could have changed.
   *
   * You need not (but may) call this function if poll_state is assigned.
   *
   * This function can be called in any context, even from within rfkill
   * callbacks.
   *
   * The function returns the combined block state (true if transmitter
   * should be blocked) so that drivers need not keep track of the soft
   * block state -- which they might not be able to.
   */
e56f09753   Alan Jenkins   rfkill: remove to...
156
  bool rfkill_set_hw_state(struct rfkill *rfkill, bool blocked);
19d337dff   Johannes Berg   rfkill: rewrite
157
158
159
160
161
162
163
164
165
  
  /**
   * rfkill_set_sw_state - Set the internal rfkill software block state
   * @rfkill: pointer to the rfkill class to modify.
   * @state: the current software block state to set
   *
   * rfkill drivers that get events when the soft-blocked state changes
   * (yes, some platforms directly act on input but allow changing again)
   * use this function to notify the rfkill core (and through that also
06d5caf47   Alan Jenkins   rfkill: don't res...
166
167
168
169
170
   * userspace) of the current state.
   *
   * Drivers should also call this function after resume if the state has
   * been changed by the user.  This only makes sense for "persistent"
   * devices (see rfkill_init_sw_state()).
19d337dff   Johannes Berg   rfkill: rewrite
171
172
173
174
175
176
177
178
179
180
   *
   * This function can be called in any context, even from within rfkill
   * callbacks.
   *
   * The function returns the combined block state (true if transmitter
   * should be blocked).
   */
  bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked);
  
  /**
06d5caf47   Alan Jenkins   rfkill: don't res...
181
182
183
184
185
186
187
188
189
   * rfkill_init_sw_state - Initialize persistent software block state
   * @rfkill: pointer to the rfkill class to modify.
   * @state: the current software block state to set
   *
   * rfkill drivers that preserve their software block state over power off
   * use this function to notify the rfkill core (and through that also
   * userspace) of their initial state.  It should only be used before
   * registration.
   *
464902e81   Alan Jenkins   rfkill: export pe...
190
191
192
   * In addition, it marks the device as "persistent", an attribute which
   * can be read by userspace.  Persistent devices are expected to preserve
   * their own state when suspended.
06d5caf47   Alan Jenkins   rfkill: don't res...
193
194
195
196
   */
  void rfkill_init_sw_state(struct rfkill *rfkill, bool blocked);
  
  /**
19d337dff   Johannes Berg   rfkill: rewrite
197
198
199
200
201
202
203
204
205
   * rfkill_set_states - Set the internal rfkill block states
   * @rfkill: pointer to the rfkill class to modify.
   * @sw: the current software block state to set
   * @hw: the current hardware block state to set
   *
   * This function can be called in any context, even from within rfkill
   * callbacks.
   */
  void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw);
801e49af4   Henrique de Moraes Holschuh   rfkill: add read-...
206

135900c18   Michael Buesch   [RFKILL]: Add sup...
207
  /**
6081162e2   Johannes Berg   rfkill: add funct...
208
209
210
211
212
   * rfkill_blocked - query rfkill block
   *
   * @rfkill: rfkill struct to query
   */
  bool rfkill_blocked(struct rfkill *rfkill);
648b50dd6   Heikki Krogerus   net: rfkill: add ...
213
214
215
216
217
218
219
220
  
  /**
   * rfkill_find_type - Helpper for finding rfkill type by name
   * @name: the name of the type
   *
   * Returns enum rfkill_type that conrresponds the name.
   */
  enum rfkill_type rfkill_find_type(const char *name);
19d337dff   Johannes Berg   rfkill: rewrite
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
  #else /* !RFKILL */
  static inline struct rfkill * __must_check
  rfkill_alloc(const char *name,
  	     struct device *parent,
  	     const enum rfkill_type type,
  	     const struct rfkill_ops *ops,
  	     void *ops_data)
  {
  	return ERR_PTR(-ENODEV);
  }
  
  static inline int __must_check rfkill_register(struct rfkill *rfkill)
  {
  	if (rfkill == ERR_PTR(-ENODEV))
  		return 0;
  	return -EINVAL;
  }
  
  static inline void rfkill_pause_polling(struct rfkill *rfkill)
  {
  }
  
  static inline void rfkill_resume_polling(struct rfkill *rfkill)
  {
  }
  
  static inline void rfkill_unregister(struct rfkill *rfkill)
  {
  }
  
  static inline void rfkill_destroy(struct rfkill *rfkill)
  {
  }
  
  static inline bool rfkill_set_hw_state(struct rfkill *rfkill, bool blocked)
  {
  	return blocked;
  }
  
  static inline bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked)
  {
  	return blocked;
  }
06d5caf47   Alan Jenkins   rfkill: don't res...
264
265
266
  static inline void rfkill_init_sw_state(struct rfkill *rfkill, bool blocked)
  {
  }
19d337dff   Johannes Berg   rfkill: rewrite
267
268
269
  static inline void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw)
  {
  }
6081162e2   Johannes Berg   rfkill: add funct...
270
271
272
273
  static inline bool rfkill_blocked(struct rfkill *rfkill)
  {
  	return false;
  }
648b50dd6   Heikki Krogerus   net: rfkill: add ...
274
275
276
277
278
  
  static inline enum rfkill_type rfkill_find_type(const char *name)
  {
  	return RFKILL_TYPE_ALL;
  }
19d337dff   Johannes Berg   rfkill: rewrite
279
  #endif /* RFKILL || RFKILL_MODULE */
06d7de831   AceLan Kao   Revert "rfkill: r...
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
  
  #ifdef CONFIG_RFKILL_LEDS
  /**
   * rfkill_get_led_trigger_name - Get the LED trigger name for the button's LED.
   * This function might return a NULL pointer if registering of the
   * LED trigger failed. Use this as "default_trigger" for the LED.
   */
  const char *rfkill_get_led_trigger_name(struct rfkill *rfkill);
  
  /**
   * rfkill_set_led_trigger_name -- set the LED trigger name
   * @rfkill: rfkill struct
   * @name: LED trigger name
   *
   * This function sets the LED trigger name of the radio LED
   * trigger that rfkill creates. It is optional, but if called
   * must be called before rfkill_register() to be effective.
   */
  void rfkill_set_led_trigger_name(struct rfkill *rfkill, const char *name);
  #else
  static inline const char *rfkill_get_led_trigger_name(struct rfkill *rfkill)
  {
  	return NULL;
  }
  
  static inline void
  rfkill_set_led_trigger_name(struct rfkill *rfkill, const char *name)
  {
  }
  #endif
cf4328cd9   Ivo van Doorn   [NET]: rfkill: ad...
310
  #endif /* RFKILL_H */