1 |
62 |
marcus.erl |
/******************************************************************************
|
2 |
|
|
*
|
3 |
|
|
* Copyright(c) 2003 - 2007 Intel Corporation. All rights reserved.
|
4 |
|
|
*
|
5 |
|
|
* Portions of this file are derived from the ipw3945 project, as well
|
6 |
|
|
* as portions of the ieee80211 subsystem header files.
|
7 |
|
|
*
|
8 |
|
|
* This program is free software; you can redistribute it and/or modify it
|
9 |
|
|
* under the terms of version 2 of the GNU General Public License as
|
10 |
|
|
* published by the Free Software Foundation.
|
11 |
|
|
*
|
12 |
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
13 |
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14 |
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
15 |
|
|
* more details.
|
16 |
|
|
*
|
17 |
|
|
* You should have received a copy of the GNU General Public License along with
|
18 |
|
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
19 |
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
|
20 |
|
|
*
|
21 |
|
|
* The full GNU General Public License is included in this distribution in the
|
22 |
|
|
* file called LICENSE.
|
23 |
|
|
*
|
24 |
|
|
* Contact Information:
|
25 |
|
|
* James P. Ketrenos <ipw2100-admin@linux.intel.com>
|
26 |
|
|
* Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
|
27 |
|
|
*
|
28 |
|
|
*****************************************************************************/
|
29 |
|
|
|
30 |
|
|
#ifndef __iwl_helpers_h__
|
31 |
|
|
#define __iwl_helpers_h__
|
32 |
|
|
|
33 |
|
|
#include <linux/ctype.h>
|
34 |
|
|
|
35 |
|
|
/*
|
36 |
|
|
* The structures defined by the hardware/uCode interface
|
37 |
|
|
* have bit-wise operations. For each bit-field there is
|
38 |
|
|
* a data symbol in the structure, the start bit position
|
39 |
|
|
* and the length of the bit-field.
|
40 |
|
|
*
|
41 |
|
|
* iwl_get_bits and iwl_set_bits will return or set the
|
42 |
|
|
* appropriate bits on a 32-bit value.
|
43 |
|
|
*
|
44 |
|
|
* IWL_GET_BITS and IWL_SET_BITS use symbol expansion to
|
45 |
|
|
* expand out to the appropriate call to iwl_get_bits
|
46 |
|
|
* and iwl_set_bits without having to reference all of the
|
47 |
|
|
* numerical constants and defines provided in the hardware
|
48 |
|
|
* definition
|
49 |
|
|
*/
|
50 |
|
|
|
51 |
|
|
/**
|
52 |
|
|
* iwl_get_bits - Extract a hardware bit-field value
|
53 |
|
|
* @src: source hardware value (__le32)
|
54 |
|
|
* @pos: bit-position (0-based) of first bit of value
|
55 |
|
|
* @len: length of bit-field
|
56 |
|
|
*
|
57 |
|
|
* iwl_get_bits will return the bit-field in cpu endian ordering.
|
58 |
|
|
*
|
59 |
|
|
* NOTE: If used from IWL_GET_BITS then pos and len are compile-constants and
|
60 |
|
|
* will collapse to minimal code by the compiler.
|
61 |
|
|
*/
|
62 |
|
|
static inline u32 iwl_get_bits(__le32 src, u8 pos, u8 len)
|
63 |
|
|
{
|
64 |
|
|
u32 tmp = le32_to_cpu(src);
|
65 |
|
|
|
66 |
|
|
tmp >>= pos;
|
67 |
|
|
tmp &= (1UL << len) - 1;
|
68 |
|
|
return tmp;
|
69 |
|
|
}
|
70 |
|
|
|
71 |
|
|
/**
|
72 |
|
|
* iwl_set_bits - Set a hardware bit-field value
|
73 |
|
|
* @dst: Address of __le32 hardware value
|
74 |
|
|
* @pos: bit-position (0-based) of first bit of value
|
75 |
|
|
* @len: length of bit-field
|
76 |
|
|
* @val: cpu endian value to encode into the bit-field
|
77 |
|
|
*
|
78 |
|
|
* iwl_set_bits will encode val into dst, masked to be len bits long at bit
|
79 |
|
|
* position pos.
|
80 |
|
|
*
|
81 |
|
|
* NOTE: If used IWL_SET_BITS pos and len will be compile-constants and
|
82 |
|
|
* will collapse to minimal code by the compiler.
|
83 |
|
|
*/
|
84 |
|
|
static inline void iwl_set_bits(__le32 *dst, u8 pos, u8 len, int val)
|
85 |
|
|
{
|
86 |
|
|
u32 tmp = le32_to_cpu(*dst);
|
87 |
|
|
|
88 |
|
|
tmp &= ~(((1UL << len) - 1) << pos);
|
89 |
|
|
tmp |= (val & ((1UL << len) - 1)) << pos;
|
90 |
|
|
*dst = cpu_to_le32(tmp);
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
static inline void iwl_set_bits16(__le16 *dst, u8 pos, u8 len, int val)
|
94 |
|
|
{
|
95 |
|
|
u16 tmp = le16_to_cpu(*dst);
|
96 |
|
|
|
97 |
|
|
tmp &= ~((1UL << (pos + len)) - (1UL << pos));
|
98 |
|
|
tmp |= (val & ((1UL << len) - 1)) << pos;
|
99 |
|
|
*dst = cpu_to_le16(tmp);
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
/*
|
103 |
|
|
* The bit-field definitions in iwl-xxxx-hw.h are in the form of:
|
104 |
|
|
*
|
105 |
|
|
* struct example {
|
106 |
|
|
* __le32 val1;
|
107 |
|
|
* #define IWL_name_POS 8
|
108 |
|
|
* #define IWL_name_LEN 4
|
109 |
|
|
* #define IWL_name_SYM val1
|
110 |
|
|
* };
|
111 |
|
|
*
|
112 |
|
|
* The IWL_SET_BITS and IWL_GET_BITS macros are provided to allow the driver
|
113 |
|
|
* to call:
|
114 |
|
|
*
|
115 |
|
|
* struct example bar;
|
116 |
|
|
* u32 val = IWL_GET_BITS(bar, name);
|
117 |
|
|
* val = val * 2;
|
118 |
|
|
* IWL_SET_BITS(bar, name, val);
|
119 |
|
|
*
|
120 |
|
|
* All cpu / host ordering, masking, and shifts are performed by the macros
|
121 |
|
|
* and iwl_{get,set}_bits.
|
122 |
|
|
*
|
123 |
|
|
*/
|
124 |
|
|
#define IWL_SET_BITS(s, sym, v) \
|
125 |
|
|
iwl_set_bits(&(s).IWL_ ## sym ## _SYM, IWL_ ## sym ## _POS, \
|
126 |
|
|
IWL_ ## sym ## _LEN, (v))
|
127 |
|
|
|
128 |
|
|
#define IWL_SET_BITS16(s, sym, v) \
|
129 |
|
|
iwl_set_bits16(&(s).IWL_ ## sym ## _SYM, IWL_ ## sym ## _POS, \
|
130 |
|
|
IWL_ ## sym ## _LEN, (v))
|
131 |
|
|
|
132 |
|
|
#define IWL_GET_BITS(s, sym) \
|
133 |
|
|
iwl_get_bits((s).IWL_ ## sym ## _SYM, IWL_ ## sym ## _POS, \
|
134 |
|
|
IWL_ ## sym ## _LEN)
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
#define KELVIN_TO_CELSIUS(x) ((x)-273)
|
138 |
|
|
#define CELSIUS_TO_KELVIN(x) ((x)+273)
|
139 |
|
|
|
140 |
|
|
#define IEEE80211_CHAN_W_RADAR_DETECT 0x00000010
|
141 |
|
|
|
142 |
|
|
static inline struct ieee80211_conf *ieee80211_get_hw_conf(
|
143 |
|
|
struct ieee80211_hw *hw)
|
144 |
|
|
{
|
145 |
|
|
return &hw->conf;
|
146 |
|
|
}
|
147 |
|
|
|
148 |
|
|
#define QOS_CONTROL_LEN 2
|
149 |
|
|
|
150 |
|
|
#define IEEE80211_STYPE_BACK_REQ 0x0080
|
151 |
|
|
#define IEEE80211_STYPE_BACK 0x0090
|
152 |
|
|
|
153 |
|
|
|
154 |
|
|
static inline int ieee80211_is_management(u16 fc)
|
155 |
|
|
{
|
156 |
|
|
return (fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT;
|
157 |
|
|
}
|
158 |
|
|
|
159 |
|
|
static inline int ieee80211_is_control(u16 fc)
|
160 |
|
|
{
|
161 |
|
|
return (fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL;
|
162 |
|
|
}
|
163 |
|
|
|
164 |
|
|
static inline int ieee80211_is_data(u16 fc)
|
165 |
|
|
{
|
166 |
|
|
return (fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA;
|
167 |
|
|
}
|
168 |
|
|
|
169 |
|
|
static inline int ieee80211_is_back_request(u16 fc)
|
170 |
|
|
{
|
171 |
|
|
return ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) &&
|
172 |
|
|
((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BACK_REQ);
|
173 |
|
|
}
|
174 |
|
|
|
175 |
|
|
static inline int ieee80211_is_probe_response(u16 fc)
|
176 |
|
|
{
|
177 |
|
|
return ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
|
178 |
|
|
((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP);
|
179 |
|
|
}
|
180 |
|
|
|
181 |
|
|
static inline int ieee80211_is_probe_request(u16 fc)
|
182 |
|
|
{
|
183 |
|
|
return ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
|
184 |
|
|
((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_REQ);
|
185 |
|
|
}
|
186 |
|
|
|
187 |
|
|
static inline int ieee80211_is_beacon(u16 fc)
|
188 |
|
|
{
|
189 |
|
|
return ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
|
190 |
|
|
((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON);
|
191 |
|
|
}
|
192 |
|
|
|
193 |
|
|
static inline int ieee80211_is_atim(u16 fc)
|
194 |
|
|
{
|
195 |
|
|
return ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
|
196 |
|
|
((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ATIM);
|
197 |
|
|
}
|
198 |
|
|
|
199 |
|
|
static inline int ieee80211_is_assoc_request(u16 fc)
|
200 |
|
|
{
|
201 |
|
|
return ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
|
202 |
|
|
((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ);
|
203 |
|
|
}
|
204 |
|
|
|
205 |
|
|
static inline int ieee80211_is_assoc_response(u16 fc)
|
206 |
|
|
{
|
207 |
|
|
return ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
|
208 |
|
|
((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_RESP);
|
209 |
|
|
}
|
210 |
|
|
|
211 |
|
|
static inline int ieee80211_is_auth(u16 fc)
|
212 |
|
|
{
|
213 |
|
|
return ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
|
214 |
|
|
((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ);
|
215 |
|
|
}
|
216 |
|
|
|
217 |
|
|
static inline int ieee80211_is_deauth(u16 fc)
|
218 |
|
|
{
|
219 |
|
|
return ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
|
220 |
|
|
((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ);
|
221 |
|
|
}
|
222 |
|
|
|
223 |
|
|
static inline int ieee80211_is_disassoc(u16 fc)
|
224 |
|
|
{
|
225 |
|
|
return ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
|
226 |
|
|
((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ);
|
227 |
|
|
}
|
228 |
|
|
|
229 |
|
|
static inline int ieee80211_is_reassoc_request(u16 fc)
|
230 |
|
|
{
|
231 |
|
|
return ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
|
232 |
|
|
((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ);
|
233 |
|
|
}
|
234 |
|
|
|
235 |
|
|
static inline int ieee80211_is_reassoc_response(u16 fc)
|
236 |
|
|
{
|
237 |
|
|
return ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) &&
|
238 |
|
|
((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_RESP);
|
239 |
|
|
}
|
240 |
|
|
|
241 |
|
|
static inline int iwl_check_bits(unsigned long field, unsigned long mask)
|
242 |
|
|
{
|
243 |
|
|
return ((field & mask) == mask) ? 1 : 0;
|
244 |
|
|
}
|
245 |
|
|
|
246 |
|
|
static inline unsigned long elapsed_jiffies(unsigned long start,
|
247 |
|
|
unsigned long end)
|
248 |
|
|
{
|
249 |
|
|
if (end > start)
|
250 |
|
|
return end - start;
|
251 |
|
|
|
252 |
|
|
return end + (MAX_JIFFY_OFFSET - start);
|
253 |
|
|
}
|
254 |
|
|
|
255 |
|
|
#endif /* __iwl_helpers_h__ */
|