xref: /linux/include/uapi/linux/rfkill.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1607ca46eSDavid Howells /*
2607ca46eSDavid Howells  * Copyright (C) 2006 - 2007 Ivo van Doorn
3607ca46eSDavid Howells  * Copyright (C) 2007 Dmitry Torokhov
4607ca46eSDavid Howells  * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
5607ca46eSDavid Howells  *
6607ca46eSDavid Howells  * Permission to use, copy, modify, and/or distribute this software for any
7607ca46eSDavid Howells  * purpose with or without fee is hereby granted, provided that the above
8607ca46eSDavid Howells  * copyright notice and this permission notice appear in all copies.
9607ca46eSDavid Howells  *
10607ca46eSDavid Howells  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11607ca46eSDavid Howells  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12607ca46eSDavid Howells  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13607ca46eSDavid Howells  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14607ca46eSDavid Howells  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15607ca46eSDavid Howells  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16607ca46eSDavid Howells  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17607ca46eSDavid Howells  */
18607ca46eSDavid Howells #ifndef _UAPI__RFKILL_H
19607ca46eSDavid Howells #define _UAPI__RFKILL_H
20607ca46eSDavid Howells 
21607ca46eSDavid Howells 
22607ca46eSDavid Howells #include <linux/types.h>
23607ca46eSDavid Howells 
24607ca46eSDavid Howells /* define userspace visible states */
25607ca46eSDavid Howells #define RFKILL_STATE_SOFT_BLOCKED	0
26607ca46eSDavid Howells #define RFKILL_STATE_UNBLOCKED		1
27607ca46eSDavid Howells #define RFKILL_STATE_HARD_BLOCKED	2
28607ca46eSDavid Howells 
29607ca46eSDavid Howells /**
30607ca46eSDavid Howells  * enum rfkill_type - type of rfkill switch.
31607ca46eSDavid Howells  *
32607ca46eSDavid Howells  * @RFKILL_TYPE_ALL: toggles all switches (requests only - not a switch type)
33607ca46eSDavid Howells  * @RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device.
34607ca46eSDavid Howells  * @RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device.
35607ca46eSDavid Howells  * @RFKILL_TYPE_UWB: switch is on a ultra wideband device.
36607ca46eSDavid Howells  * @RFKILL_TYPE_WIMAX: switch is on a WiMAX device.
37607ca46eSDavid Howells  * @RFKILL_TYPE_WWAN: switch is on a wireless WAN device.
38607ca46eSDavid Howells  * @RFKILL_TYPE_GPS: switch is on a GPS device.
39607ca46eSDavid Howells  * @RFKILL_TYPE_FM: switch is on a FM radio device.
4044b3decbSSamuel Ortiz  * @RFKILL_TYPE_NFC: switch is on an NFC device.
41607ca46eSDavid Howells  * @NUM_RFKILL_TYPES: number of defined rfkill types
42607ca46eSDavid Howells  */
43607ca46eSDavid Howells enum rfkill_type {
44607ca46eSDavid Howells 	RFKILL_TYPE_ALL = 0,
45607ca46eSDavid Howells 	RFKILL_TYPE_WLAN,
46607ca46eSDavid Howells 	RFKILL_TYPE_BLUETOOTH,
47607ca46eSDavid Howells 	RFKILL_TYPE_UWB,
48607ca46eSDavid Howells 	RFKILL_TYPE_WIMAX,
49607ca46eSDavid Howells 	RFKILL_TYPE_WWAN,
50607ca46eSDavid Howells 	RFKILL_TYPE_GPS,
51607ca46eSDavid Howells 	RFKILL_TYPE_FM,
5244b3decbSSamuel Ortiz 	RFKILL_TYPE_NFC,
53607ca46eSDavid Howells 	NUM_RFKILL_TYPES,
54607ca46eSDavid Howells };
55607ca46eSDavid Howells 
56607ca46eSDavid Howells /**
57607ca46eSDavid Howells  * enum rfkill_operation - operation types
58607ca46eSDavid Howells  * @RFKILL_OP_ADD: a device was added
59607ca46eSDavid Howells  * @RFKILL_OP_DEL: a device was removed
60607ca46eSDavid Howells  * @RFKILL_OP_CHANGE: a device's state changed -- userspace changes one device
61607ca46eSDavid Howells  * @RFKILL_OP_CHANGE_ALL: userspace changes all devices (of a type, or all)
62d4634e8dSJoão Paulo Rechi Vita  *	into a state, also updating the default state used for devices that
63d4634e8dSJoão Paulo Rechi Vita  *	are hot-plugged later.
64607ca46eSDavid Howells  */
65607ca46eSDavid Howells enum rfkill_operation {
66607ca46eSDavid Howells 	RFKILL_OP_ADD = 0,
67607ca46eSDavid Howells 	RFKILL_OP_DEL,
68607ca46eSDavid Howells 	RFKILL_OP_CHANGE,
69607ca46eSDavid Howells 	RFKILL_OP_CHANGE_ALL,
70607ca46eSDavid Howells };
71607ca46eSDavid Howells 
72607ca46eSDavid Howells /**
7314486c82SEmmanuel Grumbach  * enum rfkill_hard_block_reasons - hard block reasons
7414486c82SEmmanuel Grumbach  * @RFKILL_HARD_BLOCK_SIGNAL: the hardware rfkill signal is active
7514486c82SEmmanuel Grumbach  * @RFKILL_HARD_BLOCK_NOT_OWNER: the NIC is not owned by the host
7614486c82SEmmanuel Grumbach  */
7714486c82SEmmanuel Grumbach enum rfkill_hard_block_reasons {
7814486c82SEmmanuel Grumbach 	RFKILL_HARD_BLOCK_SIGNAL	= 1 << 0,
7914486c82SEmmanuel Grumbach 	RFKILL_HARD_BLOCK_NOT_OWNER	= 1 << 1,
8014486c82SEmmanuel Grumbach };
8114486c82SEmmanuel Grumbach 
8214486c82SEmmanuel Grumbach /**
83607ca46eSDavid Howells  * struct rfkill_event - events for userspace on /dev/rfkill
84607ca46eSDavid Howells  * @idx: index of dev rfkill
85607ca46eSDavid Howells  * @type: type of the rfkill struct
86607ca46eSDavid Howells  * @op: operation code
87607ca46eSDavid Howells  * @hard: hard state (0/1)
88607ca46eSDavid Howells  * @soft: soft state (0/1)
89607ca46eSDavid Howells  *
90607ca46eSDavid Howells  * Structure used for userspace communication on /dev/rfkill,
91607ca46eSDavid Howells  * used for events from the kernel and control to the kernel.
92607ca46eSDavid Howells  */
93607ca46eSDavid Howells struct rfkill_event {
94607ca46eSDavid Howells 	__u32 idx;
95607ca46eSDavid Howells 	__u8  type;
96607ca46eSDavid Howells 	__u8  op;
9714486c82SEmmanuel Grumbach 	__u8  soft;
9814486c82SEmmanuel Grumbach 	__u8  hard;
9971826654SJohannes Berg } __attribute__((packed));
10071826654SJohannes Berg 
10171826654SJohannes Berg /**
10271826654SJohannes Berg  * struct rfkill_event_ext - events for userspace on /dev/rfkill
10371826654SJohannes Berg  * @idx: index of dev rfkill
10471826654SJohannes Berg  * @type: type of the rfkill struct
10571826654SJohannes Berg  * @op: operation code
10671826654SJohannes Berg  * @hard: hard state (0/1)
10771826654SJohannes Berg  * @soft: soft state (0/1)
10871826654SJohannes Berg  * @hard_block_reasons: valid if hard is set. One or several reasons from
10971826654SJohannes Berg  *	&enum rfkill_hard_block_reasons.
11071826654SJohannes Berg  *
11171826654SJohannes Berg  * Structure used for userspace communication on /dev/rfkill,
11271826654SJohannes Berg  * used for events from the kernel and control to the kernel.
11371826654SJohannes Berg  *
11471826654SJohannes Berg  * See the extensibility docs below.
11571826654SJohannes Berg  */
11671826654SJohannes Berg struct rfkill_event_ext {
11771826654SJohannes Berg 	__u32 idx;
11871826654SJohannes Berg 	__u8  type;
11971826654SJohannes Berg 	__u8  op;
12071826654SJohannes Berg 	__u8  soft;
12171826654SJohannes Berg 	__u8  hard;
12271826654SJohannes Berg 
12371826654SJohannes Berg 	/*
12471826654SJohannes Berg 	 * older kernels will accept/send only up to this point,
12571826654SJohannes Berg 	 * and if extended further up to any chunk marked below
12671826654SJohannes Berg 	 */
12771826654SJohannes Berg 
12814486c82SEmmanuel Grumbach 	__u8  hard_block_reasons;
129607ca46eSDavid Howells } __attribute__((packed));
130607ca46eSDavid Howells 
13171826654SJohannes Berg /**
13271826654SJohannes Berg  * DOC: Extensibility
133607ca46eSDavid Howells  *
13471826654SJohannes Berg  * Originally, we had planned to allow backward and forward compatible
13571826654SJohannes Berg  * changes by just adding fields at the end of the structure that are
13671826654SJohannes Berg  * then not reported on older kernels on read(), and not written to by
13771826654SJohannes Berg  * older kernels on write(), with the kernel reporting the size it did
13871826654SJohannes Berg  * accept as the result.
13971826654SJohannes Berg  *
14071826654SJohannes Berg  * This would have allowed userspace to detect on read() and write()
14171826654SJohannes Berg  * which kernel structure version it was dealing with, and if was just
14271826654SJohannes Berg  * recompiled it would have gotten the new fields, but obviously not
14371826654SJohannes Berg  * accessed them, but things should've continued to work.
14471826654SJohannes Berg  *
14571826654SJohannes Berg  * Unfortunately, while actually exercising this mechanism to add the
14671826654SJohannes Berg  * hard block reasons field, we found that userspace (notably systemd)
14771826654SJohannes Berg  * did all kinds of fun things not in line with this scheme:
14871826654SJohannes Berg  *
14971826654SJohannes Berg  * 1. treat the (expected) short writes as an error;
15071826654SJohannes Berg  * 2. ask to read sizeof(struct rfkill_event) but then compare the
15171826654SJohannes Berg  *    actual return value to RFKILL_EVENT_SIZE_V1 and treat any
15271826654SJohannes Berg  *    mismatch as an error.
15371826654SJohannes Berg  *
15471826654SJohannes Berg  * As a consequence, just recompiling with a new struct version caused
15571826654SJohannes Berg  * things to no longer work correctly on old and new kernels.
15671826654SJohannes Berg  *
15771826654SJohannes Berg  * Hence, we've rolled back &struct rfkill_event to the original version
15871826654SJohannes Berg  * and added &struct rfkill_event_ext. This effectively reverts to the
15971826654SJohannes Berg  * old behaviour for all userspace, unless it explicitly opts in to the
16071826654SJohannes Berg  * rules outlined here by using the new &struct rfkill_event_ext.
16171826654SJohannes Berg  *
16254f586a9SJohannes Berg  * Additionally, some other userspace (bluez, g-s-d) was reading with a
16354f586a9SJohannes Berg  * large size but as streaming reads rather than message-based, or with
16454f586a9SJohannes Berg  * too strict checks for the returned size. So eventually, we completely
16554f586a9SJohannes Berg  * reverted this, and extended messages need to be opted in to by using
16654f586a9SJohannes Berg  * an ioctl:
16754f586a9SJohannes Berg  *
16854f586a9SJohannes Berg  *  ioctl(fd, RFKILL_IOCTL_MAX_SIZE, sizeof(struct rfkill_event_ext));
16954f586a9SJohannes Berg  *
17054f586a9SJohannes Berg  * Userspace using &struct rfkill_event_ext and the ioctl must adhere to
17154f586a9SJohannes Berg  * the following rules:
17271826654SJohannes Berg  *
17371826654SJohannes Berg  * 1. accept short writes, optionally using them to detect that it's
17471826654SJohannes Berg  *    running on an older kernel;
17571826654SJohannes Berg  * 2. accept short reads, knowing that this means it's running on an
17671826654SJohannes Berg  *    older kernel;
17771826654SJohannes Berg  * 3. treat reads that are as long as requested as acceptable, not
17871826654SJohannes Berg  *    checking against RFKILL_EVENT_SIZE_V1 or such.
179607ca46eSDavid Howells  */
18071826654SJohannes Berg #define RFKILL_EVENT_SIZE_V1	sizeof(struct rfkill_event)
181607ca46eSDavid Howells 
182607ca46eSDavid Howells /* ioctl for turning off rfkill-input (if present) */
183607ca46eSDavid Howells #define RFKILL_IOC_MAGIC	'R'
184607ca46eSDavid Howells #define RFKILL_IOC_NOINPUT	1
185607ca46eSDavid Howells #define RFKILL_IOCTL_NOINPUT	_IO(RFKILL_IOC_MAGIC, RFKILL_IOC_NOINPUT)
18654f586a9SJohannes Berg #define RFKILL_IOC_MAX_SIZE	2
187*a36e07dfSGleb Fotengauer-Malinovskiy #define RFKILL_IOCTL_MAX_SIZE	_IOW(RFKILL_IOC_MAGIC, RFKILL_IOC_MAX_SIZE, __u32)
188607ca46eSDavid Howells 
189607ca46eSDavid Howells /* and that's all userspace gets */
190607ca46eSDavid Howells 
191607ca46eSDavid Howells #endif /* _UAPI__RFKILL_H */
192