blob: d9f0e3bf326a34de2ce730a68768fc4f8befd2a3 [file] [log] [blame]
Nicholas Flintham1e3d3112013-04-10 10:48:38 +01001#ifndef __RFKILL_H
2#define __RFKILL_H
3
4/*
5 * Copyright (C) 2006 - 2007 Ivo van Doorn
6 * Copyright (C) 2007 Dmitry Torokhov
7 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
8 *
9 * Permission to use, copy, modify, and/or distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 */
21
22#include <linux/types.h>
23
24#define RFKILL_STATE_SOFT_BLOCKED 0
25#define RFKILL_STATE_UNBLOCKED 1
26#define RFKILL_STATE_HARD_BLOCKED 2
27
28enum rfkill_type {
29 RFKILL_TYPE_ALL = 0,
30 RFKILL_TYPE_WLAN,
31 RFKILL_TYPE_BLUETOOTH,
32 RFKILL_TYPE_UWB,
33 RFKILL_TYPE_WIMAX,
34 RFKILL_TYPE_WWAN,
35 RFKILL_TYPE_GPS,
36 RFKILL_TYPE_FM,
37 NUM_RFKILL_TYPES,
38};
39
40enum rfkill_operation {
41 RFKILL_OP_ADD = 0,
42 RFKILL_OP_DEL,
43 RFKILL_OP_CHANGE,
44 RFKILL_OP_CHANGE_ALL,
45};
46
47struct rfkill_event {
48 __u32 idx;
49 __u8 type;
50 __u8 op;
51 __u8 soft, hard;
52} __attribute__((packed));
53
54#define RFKILL_EVENT_SIZE_V1 8
55
56#define RFKILL_IOC_MAGIC 'R'
57#define RFKILL_IOC_NOINPUT 1
58#define RFKILL_IOCTL_NOINPUT _IO(RFKILL_IOC_MAGIC, RFKILL_IOC_NOINPUT)
59
60#ifdef __KERNEL__
61enum rfkill_user_states {
62 RFKILL_USER_STATE_SOFT_BLOCKED = RFKILL_STATE_SOFT_BLOCKED,
63 RFKILL_USER_STATE_UNBLOCKED = RFKILL_STATE_UNBLOCKED,
64 RFKILL_USER_STATE_HARD_BLOCKED = RFKILL_STATE_HARD_BLOCKED,
65};
66#undef RFKILL_STATE_SOFT_BLOCKED
67#undef RFKILL_STATE_UNBLOCKED
68#undef RFKILL_STATE_HARD_BLOCKED
69
70#include <linux/kernel.h>
71#include <linux/list.h>
72#include <linux/mutex.h>
73#include <linux/leds.h>
74#include <linux/err.h>
75
76struct device;
77struct rfkill;
78
79struct rfkill_ops {
80 void (*poll)(struct rfkill *rfkill, void *data);
81 void (*query)(struct rfkill *rfkill, void *data);
82 int (*set_block)(void *data, bool blocked);
83};
84
85#if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
86struct rfkill * __must_check rfkill_alloc(const char *name,
87 struct device *parent,
88 const enum rfkill_type type,
89 const struct rfkill_ops *ops,
90 void *ops_data);
91
92int __must_check rfkill_register(struct rfkill *rfkill);
93
94void rfkill_pause_polling(struct rfkill *rfkill);
95
96#ifdef CONFIG_RFKILL_PM
97void rfkill_resume_polling(struct rfkill *rfkill);
98#else
99static inline void rfkill_resume_polling(struct rfkill *rfkill) { }
100#endif
101
102void rfkill_unregister(struct rfkill *rfkill);
103
104void rfkill_destroy(struct rfkill *rfkill);
105
106bool rfkill_set_hw_state(struct rfkill *rfkill, bool blocked);
107
108bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked);
109
110void rfkill_init_sw_state(struct rfkill *rfkill, bool blocked);
111
112void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw);
113
114bool rfkill_blocked(struct rfkill *rfkill);
115#else
116static inline struct rfkill * __must_check
117rfkill_alloc(const char *name,
118 struct device *parent,
119 const enum rfkill_type type,
120 const struct rfkill_ops *ops,
121 void *ops_data)
122{
123 return ERR_PTR(-ENODEV);
124}
125
126static inline int __must_check rfkill_register(struct rfkill *rfkill)
127{
128 if (rfkill == ERR_PTR(-ENODEV))
129 return 0;
130 return -EINVAL;
131}
132
133static inline void rfkill_pause_polling(struct rfkill *rfkill)
134{
135}
136
137static inline void rfkill_resume_polling(struct rfkill *rfkill)
138{
139}
140
141static inline void rfkill_unregister(struct rfkill *rfkill)
142{
143}
144
145static inline void rfkill_destroy(struct rfkill *rfkill)
146{
147}
148
149static inline bool rfkill_set_hw_state(struct rfkill *rfkill, bool blocked)
150{
151 return blocked;
152}
153
154static inline bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked)
155{
156 return blocked;
157}
158
159static inline void rfkill_init_sw_state(struct rfkill *rfkill, bool blocked)
160{
161}
162
163static inline void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw)
164{
165}
166
167static inline bool rfkill_blocked(struct rfkill *rfkill)
168{
169 return false;
170}
171#endif
172
173#endif
174
175#endif