rfkill.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #ifndef __RFKILL_H
  2. #define __RFKILL_H
  3. /*
  4. * Copyright (C) 2006 - 2007 Ivo van Doorn
  5. * Copyright (C) 2007 Dmitry Torokhov
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the
  19. * Free Software Foundation, Inc.,
  20. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. #include <linux/types.h>
  23. #include <linux/kernel.h>
  24. #include <linux/list.h>
  25. #include <linux/mutex.h>
  26. #include <linux/device.h>
  27. #include <linux/leds.h>
  28. /**
  29. * enum rfkill_type - type of rfkill switch.
  30. * RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device.
  31. * RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device.
  32. * RFKILL_TYPE_UWB: switch is on a ultra wideband device.
  33. * RFKILL_TYPE_WIMAX: switch is on a WiMAX device.
  34. * RFKILL_TYPE_WWAN: switch is on a wireless WAN device.
  35. */
  36. enum rfkill_type {
  37. RFKILL_TYPE_WLAN ,
  38. RFKILL_TYPE_BLUETOOTH,
  39. RFKILL_TYPE_UWB,
  40. RFKILL_TYPE_WIMAX,
  41. RFKILL_TYPE_WWAN,
  42. RFKILL_TYPE_MAX,
  43. };
  44. enum rfkill_state {
  45. RFKILL_STATE_SOFT_BLOCKED = 0, /* Radio output blocked */
  46. RFKILL_STATE_UNBLOCKED = 1, /* Radio output allowed */
  47. RFKILL_STATE_HARD_BLOCKED = 2, /* Output blocked, non-overrideable */
  48. RFKILL_STATE_MAX, /* marker for last valid state */
  49. };
  50. /*
  51. * These are DEPRECATED, drivers using them should be verified to
  52. * comply with the rfkill usage guidelines in Documentation/rfkill.txt
  53. * and then converted to use the new names for rfkill_state
  54. */
  55. #define RFKILL_STATE_OFF RFKILL_STATE_SOFT_BLOCKED
  56. #define RFKILL_STATE_ON RFKILL_STATE_UNBLOCKED
  57. /**
  58. * struct rfkill - rfkill control structure.
  59. * @name: Name of the switch.
  60. * @type: Radio type which the button controls, the value stored
  61. * here should be a value from enum rfkill_type.
  62. * @state: State of the switch, "UNBLOCKED" means radio can operate.
  63. * @user_claim_unsupported: Whether the hardware supports exclusive
  64. * RF-kill control by userspace. Set this before registering.
  65. * @user_claim: Set when the switch is controlled exlusively by userspace.
  66. * @mutex: Guards switch state transitions. It serializes callbacks
  67. * and also protects the state.
  68. * @data: Pointer to the RF button drivers private data which will be
  69. * passed along when toggling radio state.
  70. * @toggle_radio(): Mandatory handler to control state of the radio.
  71. * only RFKILL_STATE_SOFT_BLOCKED and RFKILL_STATE_UNBLOCKED are
  72. * valid parameters.
  73. * @get_state(): handler to read current radio state from hardware,
  74. * may be called from atomic context, should return 0 on success.
  75. * Either this handler OR judicious use of rfkill_force_state() is
  76. * MANDATORY for any driver capable of RFKILL_STATE_HARD_BLOCKED.
  77. * @led_trigger: A LED trigger for this button's LED.
  78. * @dev: Device structure integrating the switch into device tree.
  79. * @node: Used to place switch into list of all switches known to the
  80. * the system.
  81. *
  82. * This structure represents a RF switch located on a network device.
  83. */
  84. struct rfkill {
  85. const char *name;
  86. enum rfkill_type type;
  87. bool user_claim_unsupported;
  88. bool user_claim;
  89. /* the mutex serializes callbacks and also protects
  90. * the state */
  91. struct mutex mutex;
  92. enum rfkill_state state;
  93. void *data;
  94. int (*toggle_radio)(void *data, enum rfkill_state state);
  95. int (*get_state)(void *data, enum rfkill_state *state);
  96. #ifdef CONFIG_RFKILL_LEDS
  97. struct led_trigger led_trigger;
  98. #endif
  99. struct device dev;
  100. struct list_head node;
  101. };
  102. #define to_rfkill(d) container_of(d, struct rfkill, dev)
  103. struct rfkill * __must_check rfkill_allocate(struct device *parent,
  104. enum rfkill_type type);
  105. void rfkill_free(struct rfkill *rfkill);
  106. int __must_check rfkill_register(struct rfkill *rfkill);
  107. void rfkill_unregister(struct rfkill *rfkill);
  108. int rfkill_force_state(struct rfkill *rfkill, enum rfkill_state state);
  109. int rfkill_set_default(enum rfkill_type type, enum rfkill_state state);
  110. /**
  111. * rfkill_state_complement - return complementar state
  112. * @state: state to return the complement of
  113. *
  114. * Returns RFKILL_STATE_SOFT_BLOCKED if @state is RFKILL_STATE_UNBLOCKED,
  115. * returns RFKILL_STATE_UNBLOCKED otherwise.
  116. */
  117. static inline enum rfkill_state rfkill_state_complement(enum rfkill_state state)
  118. {
  119. return (state == RFKILL_STATE_UNBLOCKED) ?
  120. RFKILL_STATE_SOFT_BLOCKED : RFKILL_STATE_UNBLOCKED;
  121. }
  122. /**
  123. * rfkill_get_led_name - Get the LED trigger name for the button's LED.
  124. * This function might return a NULL pointer if registering of the
  125. * LED trigger failed.
  126. * Use this as "default_trigger" for the LED.
  127. */
  128. static inline char *rfkill_get_led_name(struct rfkill *rfkill)
  129. {
  130. #ifdef CONFIG_RFKILL_LEDS
  131. return (char *)(rfkill->led_trigger.name);
  132. #else
  133. return NULL;
  134. #endif
  135. }
  136. /* rfkill notification chain */
  137. #define RFKILL_STATE_CHANGED 0x0001 /* state of a normal rfkill
  138. switch has changed */
  139. int register_rfkill_notifier(struct notifier_block *nb);
  140. int unregister_rfkill_notifier(struct notifier_block *nb);
  141. #endif /* RFKILL_H */