nl80211: use GFP_ATOMIC for michael mic failure message
[linux-2.6-block.git] / include / linux / rfkill.h
CommitLineData
cf4328cd
ID
1#ifndef __RFKILL_H
2#define __RFKILL_H
3
4/*
fe242cfd 5 * Copyright (C) 2006 - 2007 Ivo van Doorn
cf4328cd
ID
6 * Copyright (C) 2007 Dmitry Torokhov
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
24#include <linux/types.h>
25#include <linux/kernel.h>
26#include <linux/list.h>
27#include <linux/mutex.h>
28#include <linux/device.h>
135900c1 29#include <linux/leds.h>
cf4328cd
ID
30
31/**
32 * enum rfkill_type - type of rfkill switch.
279632be
MB
33 * RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device.
34 * RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device.
35 * RFKILL_TYPE_UWB: switch is on a ultra wideband device.
303d9bf6 36 * RFKILL_TYPE_WIMAX: switch is on a WiMAX device.
477576a0 37 * RFKILL_TYPE_WWAN: switch is on a wireless WAN device.
cf4328cd
ID
38 */
39enum rfkill_type {
234a0ca6
ID
40 RFKILL_TYPE_WLAN ,
41 RFKILL_TYPE_BLUETOOTH,
e0665486 42 RFKILL_TYPE_UWB,
303d9bf6 43 RFKILL_TYPE_WIMAX,
477576a0 44 RFKILL_TYPE_WWAN,
234a0ca6 45 RFKILL_TYPE_MAX,
cf4328cd
ID
46};
47
48enum rfkill_state {
5005657c
HMH
49 RFKILL_STATE_SOFT_BLOCKED = 0, /* Radio output blocked */
50 RFKILL_STATE_UNBLOCKED = 1, /* Radio output allowed */
51 RFKILL_STATE_HARD_BLOCKED = 2, /* Output blocked, non-overrideable */
96c87607 52 RFKILL_STATE_MAX, /* marker for last valid state */
cf4328cd
ID
53};
54
55/**
56 * struct rfkill - rfkill control structure.
57 * @name: Name of the switch.
58 * @type: Radio type which the button controls, the value stored
59 * here should be a value from enum rfkill_type.
5005657c 60 * @state: State of the switch, "UNBLOCKED" means radio can operate.
f1b23361
HMH
61 * @mutex: Guards switch state transitions. It serializes callbacks
62 * and also protects the state.
cf4328cd
ID
63 * @data: Pointer to the RF button drivers private data which will be
64 * passed along when toggling radio state.
65 * @toggle_radio(): Mandatory handler to control state of the radio.
5005657c
HMH
66 * only RFKILL_STATE_SOFT_BLOCKED and RFKILL_STATE_UNBLOCKED are
67 * valid parameters.
801e49af
HMH
68 * @get_state(): handler to read current radio state from hardware,
69 * may be called from atomic context, should return 0 on success.
5005657c
HMH
70 * Either this handler OR judicious use of rfkill_force_state() is
71 * MANDATORY for any driver capable of RFKILL_STATE_HARD_BLOCKED.
135900c1 72 * @led_trigger: A LED trigger for this button's LED.
cf4328cd
ID
73 * @dev: Device structure integrating the switch into device tree.
74 * @node: Used to place switch into list of all switches known to the
75 * the system.
76 *
77 * This structure represents a RF switch located on a network device.
78 */
79struct rfkill {
c36befb5 80 const char *name;
cf4328cd
ID
81 enum rfkill_type type;
82
f1b23361
HMH
83 /* the mutex serializes callbacks and also protects
84 * the state */
cf4328cd 85 struct mutex mutex;
f1b23361 86 enum rfkill_state state;
cf4328cd
ID
87 void *data;
88 int (*toggle_radio)(void *data, enum rfkill_state state);
801e49af 89 int (*get_state)(void *data, enum rfkill_state *state);
cf4328cd 90
135900c1
MB
91#ifdef CONFIG_RFKILL_LEDS
92 struct led_trigger led_trigger;
93#endif
94
cf4328cd
ID
95 struct device dev;
96 struct list_head node;
f80b5e99 97 enum rfkill_state state_for_resume;
cf4328cd
ID
98};
99#define to_rfkill(d) container_of(d, struct rfkill, dev)
100
77fba13c
HMH
101struct rfkill * __must_check rfkill_allocate(struct device *parent,
102 enum rfkill_type type);
cf4328cd 103void rfkill_free(struct rfkill *rfkill);
77fba13c 104int __must_check rfkill_register(struct rfkill *rfkill);
cf4328cd
ID
105void rfkill_unregister(struct rfkill *rfkill);
106
801e49af 107int rfkill_force_state(struct rfkill *rfkill, enum rfkill_state state);
99619201 108int rfkill_set_default(enum rfkill_type type, enum rfkill_state state);
801e49af 109
5005657c
HMH
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 */
117static 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
135900c1
MB
123/**
124 * rfkill_get_led_name - Get the LED trigger name for the button's LED.
125 * This function might return a NULL pointer if registering of the
126 * LED trigger failed.
127 * Use this as "default_trigger" for the LED.
128 */
129static inline char *rfkill_get_led_name(struct rfkill *rfkill)
130{
131#ifdef CONFIG_RFKILL_LEDS
132 return (char *)(rfkill->led_trigger.name);
133#else
134 return NULL;
135#endif
136}
137
cf4328cd 138#endif /* RFKILL_H */