net: wireless: add brcm80211 drivers
[pandora-kernel.git] / drivers / net / wireless / brcm80211 / include / brcmu_wifi.h
1 /*
2  * Copyright (c) 2010 Broadcom Corporation
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #ifndef _BRCMU_WIFI_H_
18 #define _BRCMU_WIFI_H_
19
20 #include <linux/if_ether.h>             /* for ETH_ALEN */
21 #include <linux/ieee80211.h>            /* for WLAN_PMKID_LEN */
22
23 /*
24  * A chanspec (u16) holds the channel number, band, bandwidth and control
25  * sideband
26  */
27
28 /* channel defines */
29 #define CH_UPPER_SB                     0x01
30 #define CH_LOWER_SB                     0x02
31 #define CH_EWA_VALID                    0x04
32 #define CH_20MHZ_APART                  4
33 #define CH_10MHZ_APART                  2
34 #define CH_5MHZ_APART                   1 /* 2G band channels are 5 Mhz apart */
35 #define CH_MAX_2G_CHANNEL               14      /* Max channel in 2G band */
36 #define BRCM_MAX_2G_CHANNEL     CH_MAX_2G_CHANNEL       /* legacy define */
37
38 /* bandstate array indices */
39 #define BAND_2G_INDEX           0       /* wlc->bandstate[x] index */
40 #define BAND_5G_INDEX           1       /* wlc->bandstate[x] index */
41
42 /*
43  * max # supported channels. The max channel no is 216, this is that + 1
44  * rounded up to a multiple of NBBY (8). DO NOT MAKE it > 255: channels are
45  * u8's all over
46 */
47 #define MAXCHANNEL              224
48
49 #define WL_CHANSPEC_CHAN_MASK           0x00ff
50 #define WL_CHANSPEC_CHAN_SHIFT          0
51
52 #define WL_CHANSPEC_CTL_SB_MASK         0x0300
53 #define WL_CHANSPEC_CTL_SB_SHIFT             8
54 #define WL_CHANSPEC_CTL_SB_LOWER        0x0100
55 #define WL_CHANSPEC_CTL_SB_UPPER        0x0200
56 #define WL_CHANSPEC_CTL_SB_NONE         0x0300
57
58 #define WL_CHANSPEC_BW_MASK             0x0C00
59 #define WL_CHANSPEC_BW_SHIFT                10
60 #define WL_CHANSPEC_BW_10               0x0400
61 #define WL_CHANSPEC_BW_20               0x0800
62 #define WL_CHANSPEC_BW_40               0x0C00
63
64 #define WL_CHANSPEC_BAND_MASK           0xf000
65 #define WL_CHANSPEC_BAND_SHIFT          12
66 #define WL_CHANSPEC_BAND_5G             0x1000
67 #define WL_CHANSPEC_BAND_2G             0x2000
68 #define INVCHANSPEC                     255
69
70 /* used to calculate the chan_freq = chan_factor * 500Mhz + 5 * chan_number */
71 #define WF_CHAN_FACTOR_2_4_G            4814    /* 2.4 GHz band, 2407 MHz */
72 #define WF_CHAN_FACTOR_5_G              10000   /* 5   GHz band, 5000 MHz */
73 #define WF_CHAN_FACTOR_4_G              8000    /* 4.9 GHz band for Japan */
74
75 #define CHSPEC_CHANNEL(chspec)  ((u8)((chspec) & WL_CHANSPEC_CHAN_MASK))
76 #define CHSPEC_BAND(chspec)     ((chspec) & WL_CHANSPEC_BAND_MASK)
77
78 #define CHSPEC_CTL_SB(chspec)   ((chspec) & WL_CHANSPEC_CTL_SB_MASK)
79 #define CHSPEC_BW(chspec)       ((chspec) & WL_CHANSPEC_BW_MASK)
80
81 #define CHSPEC_IS10(chspec) \
82         (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_10)
83
84 #define CHSPEC_IS20(chspec) \
85         (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_20)
86
87 #ifndef CHSPEC_IS40
88 #define CHSPEC_IS40(chspec) \
89         (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_40)
90 #endif
91
92 #define CHSPEC_IS5G(chspec) \
93         (((chspec) & WL_CHANSPEC_BAND_MASK) == WL_CHANSPEC_BAND_5G)
94
95 #define CHSPEC_IS2G(chspec) \
96         (((chspec) & WL_CHANSPEC_BAND_MASK) == WL_CHANSPEC_BAND_2G)
97
98 #define CHSPEC_SB_NONE(chspec) \
99         (((chspec) & WL_CHANSPEC_CTL_SB_MASK) == WL_CHANSPEC_CTL_SB_NONE)
100
101 #define CHSPEC_SB_UPPER(chspec) \
102         (((chspec) & WL_CHANSPEC_CTL_SB_MASK) == WL_CHANSPEC_CTL_SB_UPPER)
103
104 #define CHSPEC_SB_LOWER(chspec) \
105         (((chspec) & WL_CHANSPEC_CTL_SB_MASK) == WL_CHANSPEC_CTL_SB_LOWER)
106
107 #define CHSPEC_CTL_CHAN(chspec) \
108         ((CHSPEC_SB_LOWER(chspec)) ? \
109         (lower_20_sb(((chspec) & WL_CHANSPEC_CHAN_MASK))) : \
110         (upper_20_sb(((chspec) & WL_CHANSPEC_CHAN_MASK))))
111
112 #define CHSPEC2BAND(chspec) (CHSPEC_IS5G(chspec) ? BRCM_BAND_5G : BRCM_BAND_2G)
113
114 #define CHANSPEC_STR_LEN    8
115
116 static inline int lower_20_sb(int channel)
117 {
118         return channel > CH_10MHZ_APART ? (channel - CH_10MHZ_APART) : 0;
119 }
120
121 static inline int upper_20_sb(int channel)
122 {
123         return (channel < (MAXCHANNEL - CH_10MHZ_APART)) ?
124                channel + CH_10MHZ_APART : 0;
125 }
126
127 static inline int chspec_bandunit(u16 chspec)
128 {
129         return CHSPEC_IS5G(chspec) ? BAND_5G_INDEX : BAND_2G_INDEX;
130 }
131
132 static inline u16 ch20mhz_chspec(int channel)
133 {
134         u16 rc = channel <= CH_MAX_2G_CHANNEL ?
135                  WL_CHANSPEC_BAND_2G : WL_CHANSPEC_BAND_5G;
136
137         return  (u16)((u16)channel | WL_CHANSPEC_BW_20 |
138                       WL_CHANSPEC_CTL_SB_NONE | rc);
139 }
140
141 static inline int next_20mhz_chan(int channel)
142 {
143         return channel < (MAXCHANNEL - CH_20MHZ_APART) ?
144                channel + CH_20MHZ_APART : 0;
145 }
146
147 /* defined rate in 500kbps */
148 #define BRCM_MAXRATE    108     /* in 500kbps units */
149 #define BRCM_RATE_1M    2       /* in 500kbps units */
150 #define BRCM_RATE_2M    4       /* in 500kbps units */
151 #define BRCM_RATE_5M5   11      /* in 500kbps units */
152 #define BRCM_RATE_11M   22      /* in 500kbps units */
153 #define BRCM_RATE_6M    12      /* in 500kbps units */
154 #define BRCM_RATE_9M    18      /* in 500kbps units */
155 #define BRCM_RATE_12M   24      /* in 500kbps units */
156 #define BRCM_RATE_18M   36      /* in 500kbps units */
157 #define BRCM_RATE_24M   48      /* in 500kbps units */
158 #define BRCM_RATE_36M   72      /* in 500kbps units */
159 #define BRCM_RATE_48M   96      /* in 500kbps units */
160 #define BRCM_RATE_54M   108     /* in 500kbps units */
161
162 #define BRCM_2G_25MHZ_OFFSET            5       /* 2.4GHz band channel offset */
163
164 #define MCSSET_LEN      16
165
166 static inline bool ac_bitmap_tst(u8 bitmap, int prec)
167 {
168         return (bitmap & (1 << (prec))) != 0;
169 }
170
171 /*
172  * Verify the chanspec is using a legal set of parameters, i.e. that the
173  * chanspec specified a band, bw, ctl_sb and channel and that the
174  * combination could be legal given any set of circumstances.
175  * RETURNS: true is the chanspec is malformed, false if it looks good.
176  */
177 extern bool brcmu_chspec_malformed(u16 chanspec);
178
179 /*
180  * This function returns the channel number that control traffic is being sent
181  * on, for legacy channels this is just the channel number, for 40MHZ channels
182  * it is the upper or lower 20MHZ sideband depending on the chanspec selected.
183  */
184 extern u8 brcmu_chspec_ctlchan(u16 chspec);
185
186 /*
187  * Return the channel number for a given frequency and base frequency.
188  * The returned channel number is relative to the given base frequency.
189  * If the given base frequency is zero, a base frequency of 5 GHz is assumed for
190  * frequencies from 5 - 6 GHz, and 2.407 GHz is assumed for 2.4 - 2.5 GHz.
191  *
192  * Frequency is specified in MHz.
193  * The base frequency is specified as (start_factor * 500 kHz).
194  * Constants WF_CHAN_FACTOR_2_4_G, WF_CHAN_FACTOR_5_G are defined for
195  * 2.4 GHz and 5 GHz bands.
196  *
197  * The returned channel will be in the range [1, 14] in the 2.4 GHz band
198  * and [0, 200] otherwise.
199  * -1 is returned if the start_factor is WF_CHAN_FACTOR_2_4_G and the
200  * frequency is not a 2.4 GHz channel, or if the frequency is not and even
201  * multiple of 5 MHz from the base frequency to the base plus 1 GHz.
202  *
203  * Reference 802.11 REVma, section 17.3.8.3, and 802.11B section 18.4.6.2
204  */
205 extern int brcmu_mhz2channel(uint freq, uint start_factor);
206
207 /* Enumerate crypto algorithms */
208 #define CRYPTO_ALGO_OFF                 0
209 #define CRYPTO_ALGO_WEP1                1
210 #define CRYPTO_ALGO_TKIP                2
211 #define CRYPTO_ALGO_WEP128              3
212 #define CRYPTO_ALGO_AES_CCM             4
213 #define CRYPTO_ALGO_AES_RESERVED1       5
214 #define CRYPTO_ALGO_AES_RESERVED2       6
215 #define CRYPTO_ALGO_NALG                7
216
217 /* wireless security bitvec */
218
219 #define WEP_ENABLED             0x0001
220 #define TKIP_ENABLED            0x0002
221 #define AES_ENABLED             0x0004
222 #define WSEC_SWFLAG             0x0008
223 /* to go into transition mode without setting wep */
224 #define SES_OW_ENABLED          0x0040
225
226 /* WPA authentication mode bitvec */
227 #define WPA_AUTH_DISABLED       0x0000  /* Legacy (i.e., non-WPA) */
228 #define WPA_AUTH_NONE           0x0001  /* none (IBSS) */
229 #define WPA_AUTH_UNSPECIFIED    0x0002  /* over 802.1x */
230 #define WPA_AUTH_PSK            0x0004  /* Pre-shared key */
231 #define WPA_AUTH_RESERVED1      0x0008
232 #define WPA_AUTH_RESERVED2      0x0010
233
234 #define WPA2_AUTH_RESERVED1     0x0020
235 #define WPA2_AUTH_UNSPECIFIED   0x0040  /* over 802.1x */
236 #define WPA2_AUTH_PSK           0x0080  /* Pre-shared key */
237 #define WPA2_AUTH_RESERVED3     0x0200
238 #define WPA2_AUTH_RESERVED4     0x0400
239 #define WPA2_AUTH_RESERVED5     0x0800
240
241 /* pmkid */
242 #define MAXPMKID                16
243
244 #define DOT11_DEFAULT_RTS_LEN           2347
245 #define DOT11_DEFAULT_FRAG_LEN          2346
246
247 #define DOT11_ICV_AES_LEN               8
248 #define DOT11_QOS_LEN                   2
249 #define DOT11_IV_MAX_LEN                8
250 #define DOT11_A4_HDR_LEN                30
251
252 #define HT_CAP_RX_STBC_NO               0x0
253 #define HT_CAP_RX_STBC_ONE_STREAM       0x1
254
255 struct pmkid {
256         u8 BSSID[ETH_ALEN];
257         u8 PMKID[WLAN_PMKID_LEN];
258 };
259
260 struct pmkid_list {
261         u32 npmkid;
262         struct pmkid pmkid[1];
263 };
264
265 struct pmkid_cand {
266         u8 BSSID[ETH_ALEN];
267         u8 preauth;
268 };
269
270 struct pmkid_cand_list {
271         u32 npmkid_cand;
272         struct pmkid_cand pmkid_cand[1];
273 };
274
275 #endif                          /* _BRCMU_WIFI_H_ */