rfkill.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * Copyright (C) 2006 - 2007 Ivo van Doorn
  3. * Copyright (C) 2007 Dmitry Torokhov
  4. * Copyright 2009 Johannes Berg <[email protected]>
  5. *
  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.
  9. *
  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.
  17. */
  18. #ifndef _UAPI__RFKILL_H
  19. #define _UAPI__RFKILL_H
  20. #include <linux/types.h>
  21. /* define userspace visible states */
  22. #define RFKILL_STATE_SOFT_BLOCKED 0
  23. #define RFKILL_STATE_UNBLOCKED 1
  24. #define RFKILL_STATE_HARD_BLOCKED 2
  25. /**
  26. * enum rfkill_type - type of rfkill switch.
  27. *
  28. * @RFKILL_TYPE_ALL: toggles all switches (requests only - not a switch type)
  29. * @RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device.
  30. * @RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device.
  31. * @RFKILL_TYPE_UWB: switch is on a ultra wideband device.
  32. * @RFKILL_TYPE_WIMAX: switch is on a WiMAX device.
  33. * @RFKILL_TYPE_WWAN: switch is on a wireless WAN device.
  34. * @RFKILL_TYPE_GPS: switch is on a GPS device.
  35. * @RFKILL_TYPE_FM: switch is on a FM radio device.
  36. * @RFKILL_TYPE_NFC: switch is on an NFC device.
  37. * @NUM_RFKILL_TYPES: number of defined rfkill types
  38. */
  39. enum rfkill_type {
  40. RFKILL_TYPE_ALL = 0,
  41. RFKILL_TYPE_WLAN,
  42. RFKILL_TYPE_BLUETOOTH,
  43. RFKILL_TYPE_UWB,
  44. RFKILL_TYPE_WIMAX,
  45. RFKILL_TYPE_WWAN,
  46. RFKILL_TYPE_GPS,
  47. RFKILL_TYPE_FM,
  48. RFKILL_TYPE_NFC,
  49. NUM_RFKILL_TYPES,
  50. };
  51. /**
  52. * enum rfkill_operation - operation types
  53. * @RFKILL_OP_ADD: a device was added
  54. * @RFKILL_OP_DEL: a device was removed
  55. * @RFKILL_OP_CHANGE: a device's state changed -- userspace changes one device
  56. * @RFKILL_OP_CHANGE_ALL: userspace changes all devices (of a type, or all)
  57. * into a state, also updating the default state used for devices that
  58. * are hot-plugged later.
  59. */
  60. enum rfkill_operation {
  61. RFKILL_OP_ADD = 0,
  62. RFKILL_OP_DEL,
  63. RFKILL_OP_CHANGE,
  64. RFKILL_OP_CHANGE_ALL,
  65. };
  66. /**
  67. * enum rfkill_hard_block_reasons - hard block reasons
  68. * @RFKILL_HARD_BLOCK_SIGNAL: the hardware rfkill signal is active
  69. * @RFKILL_HARD_BLOCK_NOT_OWNER: the NIC is not owned by the host
  70. */
  71. enum rfkill_hard_block_reasons {
  72. RFKILL_HARD_BLOCK_SIGNAL = 1 << 0,
  73. RFKILL_HARD_BLOCK_NOT_OWNER = 1 << 1,
  74. };
  75. /**
  76. * struct rfkill_event - events for userspace on /dev/rfkill
  77. * @idx: index of dev rfkill
  78. * @type: type of the rfkill struct
  79. * @op: operation code
  80. * @hard: hard state (0/1)
  81. * @soft: soft state (0/1)
  82. *
  83. * Structure used for userspace communication on /dev/rfkill,
  84. * used for events from the kernel and control to the kernel.
  85. */
  86. struct rfkill_event {
  87. __u32 idx;
  88. __u8 type;
  89. __u8 op;
  90. __u8 soft;
  91. __u8 hard;
  92. } __attribute__((packed));
  93. /**
  94. * struct rfkill_event_ext - events for userspace on /dev/rfkill
  95. * @idx: index of dev rfkill
  96. * @type: type of the rfkill struct
  97. * @op: operation code
  98. * @hard: hard state (0/1)
  99. * @soft: soft state (0/1)
  100. * @hard_block_reasons: valid if hard is set. One or several reasons from
  101. * &enum rfkill_hard_block_reasons.
  102. *
  103. * Structure used for userspace communication on /dev/rfkill,
  104. * used for events from the kernel and control to the kernel.
  105. *
  106. * See the extensibility docs below.
  107. */
  108. struct rfkill_event_ext {
  109. __u32 idx;
  110. __u8 type;
  111. __u8 op;
  112. __u8 soft;
  113. __u8 hard;
  114. /*
  115. * older kernels will accept/send only up to this point,
  116. * and if extended further up to any chunk marked below
  117. */
  118. __u8 hard_block_reasons;
  119. } __attribute__((packed));
  120. /**
  121. * DOC: Extensibility
  122. *
  123. * Originally, we had planned to allow backward and forward compatible
  124. * changes by just adding fields at the end of the structure that are
  125. * then not reported on older kernels on read(), and not written to by
  126. * older kernels on write(), with the kernel reporting the size it did
  127. * accept as the result.
  128. *
  129. * This would have allowed userspace to detect on read() and write()
  130. * which kernel structure version it was dealing with, and if was just
  131. * recompiled it would have gotten the new fields, but obviously not
  132. * accessed them, but things should've continued to work.
  133. *
  134. * Unfortunately, while actually exercising this mechanism to add the
  135. * hard block reasons field, we found that userspace (notably systemd)
  136. * did all kinds of fun things not in line with this scheme:
  137. *
  138. * 1. treat the (expected) short writes as an error;
  139. * 2. ask to read sizeof(struct rfkill_event) but then compare the
  140. * actual return value to RFKILL_EVENT_SIZE_V1 and treat any
  141. * mismatch as an error.
  142. *
  143. * As a consequence, just recompiling with a new struct version caused
  144. * things to no longer work correctly on old and new kernels.
  145. *
  146. * Hence, we've rolled back &struct rfkill_event to the original version
  147. * and added &struct rfkill_event_ext. This effectively reverts to the
  148. * old behaviour for all userspace, unless it explicitly opts in to the
  149. * rules outlined here by using the new &struct rfkill_event_ext.
  150. *
  151. * Additionally, some other userspace (bluez, g-s-d) was reading with a
  152. * large size but as streaming reads rather than message-based, or with
  153. * too strict checks for the returned size. So eventually, we completely
  154. * reverted this, and extended messages need to be opted in to by using
  155. * an ioctl:
  156. *
  157. * ioctl(fd, RFKILL_IOCTL_MAX_SIZE, sizeof(struct rfkill_event_ext));
  158. *
  159. * Userspace using &struct rfkill_event_ext and the ioctl must adhere to
  160. * the following rules:
  161. *
  162. * 1. accept short writes, optionally using them to detect that it's
  163. * running on an older kernel;
  164. * 2. accept short reads, knowing that this means it's running on an
  165. * older kernel;
  166. * 3. treat reads that are as long as requested as acceptable, not
  167. * checking against RFKILL_EVENT_SIZE_V1 or such.
  168. */
  169. #define RFKILL_EVENT_SIZE_V1 sizeof(struct rfkill_event)
  170. /* ioctl for turning off rfkill-input (if present) */
  171. #define RFKILL_IOC_MAGIC 'R'
  172. #define RFKILL_IOC_NOINPUT 1
  173. #define RFKILL_IOCTL_NOINPUT _IO(RFKILL_IOC_MAGIC, RFKILL_IOC_NOINPUT)
  174. #define RFKILL_IOC_MAX_SIZE 2
  175. #define RFKILL_IOCTL_MAX_SIZE _IOW(RFKILL_IOC_MAGIC, RFKILL_IOC_MAX_SIZE, __u32)
  176. /* and that's all userspace gets */
  177. #endif /* _UAPI__RFKILL_H */