GNU Linux-libre 4.14.290-gnu1
[releases.git] / drivers / net / wireless / broadcom / 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_70MHZ_APART                  14
33 #define CH_50MHZ_APART                  10
34 #define CH_30MHZ_APART                  6
35 #define CH_20MHZ_APART                  4
36 #define CH_10MHZ_APART                  2
37 #define CH_5MHZ_APART                   1 /* 2G band channels are 5 Mhz apart */
38 #define CH_MIN_2G_CHANNEL               1
39 #define CH_MAX_2G_CHANNEL               14      /* Max channel in 2G band */
40 #define CH_MIN_5G_CHANNEL               34
41
42 /* bandstate array indices */
43 #define BAND_2G_INDEX           0       /* wlc->bandstate[x] index */
44 #define BAND_5G_INDEX           1       /* wlc->bandstate[x] index */
45
46 /*
47  * max # supported channels. The max channel no is 216, this is that + 1
48  * rounded up to a multiple of NBBY (8). DO NOT MAKE it > 255: channels are
49  * u8's all over
50 */
51 #define MAXCHANNEL              224
52
53 #define WL_CHANSPEC_CHAN_MASK           0x00ff
54 #define WL_CHANSPEC_CHAN_SHIFT          0
55
56 #define WL_CHANSPEC_CTL_SB_MASK         0x0300
57 #define WL_CHANSPEC_CTL_SB_SHIFT             8
58 #define WL_CHANSPEC_CTL_SB_LOWER        0x0100
59 #define WL_CHANSPEC_CTL_SB_UPPER        0x0200
60 #define WL_CHANSPEC_CTL_SB_NONE         0x0300
61
62 #define WL_CHANSPEC_BW_MASK             0x0C00
63 #define WL_CHANSPEC_BW_SHIFT                10
64 #define WL_CHANSPEC_BW_10               0x0400
65 #define WL_CHANSPEC_BW_20               0x0800
66 #define WL_CHANSPEC_BW_40               0x0C00
67 #define WL_CHANSPEC_BW_80               0x2000
68
69 #define WL_CHANSPEC_BAND_MASK           0xf000
70 #define WL_CHANSPEC_BAND_SHIFT          12
71 #define WL_CHANSPEC_BAND_5G             0x1000
72 #define WL_CHANSPEC_BAND_2G             0x2000
73 #define INVCHANSPEC                     255
74
75 #define WL_CHAN_VALID_HW                (1 << 0) /* valid with current HW */
76 #define WL_CHAN_VALID_SW                (1 << 1) /* valid with country sett. */
77 #define WL_CHAN_BAND_5G                 (1 << 2) /* 5GHz-band channel */
78 #define WL_CHAN_RADAR                   (1 << 3) /* radar sensitive  channel */
79 #define WL_CHAN_INACTIVE                (1 << 4) /* inactive due to radar */
80 #define WL_CHAN_PASSIVE                 (1 << 5) /* channel in passive mode */
81 #define WL_CHAN_RESTRICTED              (1 << 6) /* restricted use channel */
82
83 /* values for band specific 40MHz capabilities  */
84 #define WLC_N_BW_20ALL                  0
85 #define WLC_N_BW_40ALL                  1
86 #define WLC_N_BW_20IN2G_40IN5G          2
87
88 #define WLC_BW_20MHZ_BIT                BIT(0)
89 #define WLC_BW_40MHZ_BIT                BIT(1)
90 #define WLC_BW_80MHZ_BIT                BIT(2)
91 #define WLC_BW_160MHZ_BIT               BIT(3)
92
93 /* Bandwidth capabilities */
94 #define WLC_BW_CAP_20MHZ                (WLC_BW_20MHZ_BIT)
95 #define WLC_BW_CAP_40MHZ                (WLC_BW_40MHZ_BIT|WLC_BW_20MHZ_BIT)
96 #define WLC_BW_CAP_80MHZ                (WLC_BW_80MHZ_BIT|WLC_BW_40MHZ_BIT| \
97                                          WLC_BW_20MHZ_BIT)
98 #define WLC_BW_CAP_160MHZ               (WLC_BW_160MHZ_BIT|WLC_BW_80MHZ_BIT| \
99                                          WLC_BW_40MHZ_BIT|WLC_BW_20MHZ_BIT)
100 #define WLC_BW_CAP_UNRESTRICTED         0xFF
101
102 /* band types */
103 #define WLC_BAND_AUTO                   0       /* auto-select */
104 #define WLC_BAND_5G                     1       /* 5 Ghz */
105 #define WLC_BAND_2G                     2       /* 2.4 Ghz */
106 #define WLC_BAND_ALL                    3       /* all bands */
107
108 #define CHSPEC_CHANNEL(chspec)  ((u8)((chspec) & WL_CHANSPEC_CHAN_MASK))
109 #define CHSPEC_BAND(chspec)     ((chspec) & WL_CHANSPEC_BAND_MASK)
110
111 #define CHSPEC_CTL_SB(chspec)   ((chspec) & WL_CHANSPEC_CTL_SB_MASK)
112 #define CHSPEC_BW(chspec)       ((chspec) & WL_CHANSPEC_BW_MASK)
113
114 #define CHSPEC_IS10(chspec) \
115         (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_10)
116
117 #define CHSPEC_IS20(chspec) \
118         (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_20)
119
120 #define CHSPEC_IS40(chspec) \
121         (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_40)
122
123 #define CHSPEC_IS80(chspec) \
124         (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_80)
125
126 #define CHSPEC_IS5G(chspec) \
127         (((chspec) & WL_CHANSPEC_BAND_MASK) == WL_CHANSPEC_BAND_5G)
128
129 #define CHSPEC_IS2G(chspec) \
130         (((chspec) & WL_CHANSPEC_BAND_MASK) == WL_CHANSPEC_BAND_2G)
131
132 #define CHSPEC_SB_NONE(chspec) \
133         (((chspec) & WL_CHANSPEC_CTL_SB_MASK) == WL_CHANSPEC_CTL_SB_NONE)
134
135 #define CHSPEC_SB_UPPER(chspec) \
136         (((chspec) & WL_CHANSPEC_CTL_SB_MASK) == WL_CHANSPEC_CTL_SB_UPPER)
137
138 #define CHSPEC_SB_LOWER(chspec) \
139         (((chspec) & WL_CHANSPEC_CTL_SB_MASK) == WL_CHANSPEC_CTL_SB_LOWER)
140
141 #define CHSPEC_CTL_CHAN(chspec) \
142         ((CHSPEC_SB_LOWER(chspec)) ? \
143         (lower_20_sb(((chspec) & WL_CHANSPEC_CHAN_MASK))) : \
144         (upper_20_sb(((chspec) & WL_CHANSPEC_CHAN_MASK))))
145
146 #define CHSPEC2BAND(chspec) (CHSPEC_IS5G(chspec) ? BRCM_BAND_5G : BRCM_BAND_2G)
147
148 #define CHANSPEC_STR_LEN    8
149
150 static inline int lower_20_sb(int channel)
151 {
152         return channel > CH_10MHZ_APART ? (channel - CH_10MHZ_APART) : 0;
153 }
154
155 static inline int upper_20_sb(int channel)
156 {
157         return (channel < (MAXCHANNEL - CH_10MHZ_APART)) ?
158                channel + CH_10MHZ_APART : 0;
159 }
160
161 static inline int chspec_bandunit(u16 chspec)
162 {
163         return CHSPEC_IS5G(chspec) ? BAND_5G_INDEX : BAND_2G_INDEX;
164 }
165
166 static inline u16 ch20mhz_chspec(int channel)
167 {
168         u16 rc = channel <= CH_MAX_2G_CHANNEL ?
169                  WL_CHANSPEC_BAND_2G : WL_CHANSPEC_BAND_5G;
170
171         return  (u16)((u16)channel | WL_CHANSPEC_BW_20 |
172                       WL_CHANSPEC_CTL_SB_NONE | rc);
173 }
174
175 static inline int next_20mhz_chan(int channel)
176 {
177         return channel < (MAXCHANNEL - CH_20MHZ_APART) ?
178                channel + CH_20MHZ_APART : 0;
179 }
180
181 /* defined rate in 500kbps */
182 #define BRCM_MAXRATE    108     /* in 500kbps units */
183 #define BRCM_RATE_1M    2       /* in 500kbps units */
184 #define BRCM_RATE_2M    4       /* in 500kbps units */
185 #define BRCM_RATE_5M5   11      /* in 500kbps units */
186 #define BRCM_RATE_11M   22      /* in 500kbps units */
187 #define BRCM_RATE_6M    12      /* in 500kbps units */
188 #define BRCM_RATE_9M    18      /* in 500kbps units */
189 #define BRCM_RATE_12M   24      /* in 500kbps units */
190 #define BRCM_RATE_18M   36      /* in 500kbps units */
191 #define BRCM_RATE_24M   48      /* in 500kbps units */
192 #define BRCM_RATE_36M   72      /* in 500kbps units */
193 #define BRCM_RATE_48M   96      /* in 500kbps units */
194 #define BRCM_RATE_54M   108     /* in 500kbps units */
195
196 #define BRCM_2G_25MHZ_OFFSET            5       /* 2.4GHz band channel offset */
197
198 #define MCSSET_LEN      16
199
200 static inline bool ac_bitmap_tst(u8 bitmap, int prec)
201 {
202         return (bitmap & (1 << (prec))) != 0;
203 }
204
205 /* Enumerate crypto algorithms */
206 #define CRYPTO_ALGO_OFF                 0
207 #define CRYPTO_ALGO_WEP1                1
208 #define CRYPTO_ALGO_TKIP                2
209 #define CRYPTO_ALGO_WEP128              3
210 #define CRYPTO_ALGO_AES_CCM             4
211 #define CRYPTO_ALGO_AES_RESERVED1       5
212 #define CRYPTO_ALGO_AES_RESERVED2       6
213 #define CRYPTO_ALGO_NALG                7
214
215 /* wireless security bitvec */
216
217 #define WEP_ENABLED             0x0001
218 #define TKIP_ENABLED            0x0002
219 #define AES_ENABLED             0x0004
220 #define WSEC_SWFLAG             0x0008
221 /* to go into transition mode without setting wep */
222 #define SES_OW_ENABLED          0x0040
223 /* MFP */
224 #define MFP_CAPABLE             0x0200
225 #define MFP_REQUIRED            0x0400
226
227 /* WPA authentication mode bitvec */
228 #define WPA_AUTH_DISABLED       0x0000  /* Legacy (i.e., non-WPA) */
229 #define WPA_AUTH_NONE           0x0001  /* none (IBSS) */
230 #define WPA_AUTH_UNSPECIFIED    0x0002  /* over 802.1x */
231 #define WPA_AUTH_PSK            0x0004  /* Pre-shared key */
232 #define WPA_AUTH_RESERVED1      0x0008
233 #define WPA_AUTH_RESERVED2      0x0010
234
235 #define WPA2_AUTH_RESERVED1     0x0020
236 #define WPA2_AUTH_UNSPECIFIED   0x0040  /* over 802.1x */
237 #define WPA2_AUTH_PSK           0x0080  /* Pre-shared key */
238 #define WPA2_AUTH_RESERVED3     0x0200
239 #define WPA2_AUTH_RESERVED4     0x0400
240 #define WPA2_AUTH_RESERVED5     0x0800
241 #define WPA2_AUTH_1X_SHA256     0x1000  /* 1X with SHA256 key derivation */
242 #define WPA2_AUTH_PSK_SHA256    0x8000  /* PSK with SHA256 key derivation */
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 #endif                          /* _BRCMU_WIFI_H_ */