rfkill.h 9.8 KB

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