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 
lower_20_sb(int channel)116 static inline int lower_20_sb(int channel)
117 {
118 	return channel > CH_10MHZ_APART ? (channel - CH_10MHZ_APART) : 0;
119 }
120 
upper_20_sb(int channel)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 
chspec_bandunit(u16 chspec)127 static inline int chspec_bandunit(u16 chspec)
128 {
129 	return CHSPEC_IS5G(chspec) ? BAND_5G_INDEX : BAND_2G_INDEX;
130 }
131 
ch20mhz_chspec(int channel)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 
next_20mhz_chan(int channel)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 
ac_bitmap_tst(u8 bitmap,int prec)166 static inline bool ac_bitmap_tst(u8 bitmap, int prec)
167 {
168 	return (bitmap & (1 << (prec))) != 0;
169 }
170 
171 /* Enumerate crypto algorithms */
172 #define	CRYPTO_ALGO_OFF			0
173 #define	CRYPTO_ALGO_WEP1		1
174 #define	CRYPTO_ALGO_TKIP		2
175 #define	CRYPTO_ALGO_WEP128		3
176 #define CRYPTO_ALGO_AES_CCM		4
177 #define CRYPTO_ALGO_AES_RESERVED1	5
178 #define CRYPTO_ALGO_AES_RESERVED2	6
179 #define CRYPTO_ALGO_NALG		7
180 
181 /* wireless security bitvec */
182 
183 #define WEP_ENABLED		0x0001
184 #define TKIP_ENABLED		0x0002
185 #define AES_ENABLED		0x0004
186 #define WSEC_SWFLAG		0x0008
187 /* to go into transition mode without setting wep */
188 #define SES_OW_ENABLED		0x0040
189 
190 /* WPA authentication mode bitvec */
191 #define WPA_AUTH_DISABLED	0x0000	/* Legacy (i.e., non-WPA) */
192 #define WPA_AUTH_NONE		0x0001	/* none (IBSS) */
193 #define WPA_AUTH_UNSPECIFIED	0x0002	/* over 802.1x */
194 #define WPA_AUTH_PSK		0x0004	/* Pre-shared key */
195 #define WPA_AUTH_RESERVED1	0x0008
196 #define WPA_AUTH_RESERVED2	0x0010
197 
198 #define WPA2_AUTH_RESERVED1	0x0020
199 #define WPA2_AUTH_UNSPECIFIED	0x0040	/* over 802.1x */
200 #define WPA2_AUTH_PSK		0x0080	/* Pre-shared key */
201 #define WPA2_AUTH_RESERVED3	0x0200
202 #define WPA2_AUTH_RESERVED4	0x0400
203 #define WPA2_AUTH_RESERVED5	0x0800
204 
205 /* pmkid */
206 #define	MAXPMKID		16
207 
208 #define DOT11_DEFAULT_RTS_LEN		2347
209 #define DOT11_DEFAULT_FRAG_LEN		2346
210 
211 #define DOT11_ICV_AES_LEN		8
212 #define DOT11_QOS_LEN			2
213 #define DOT11_IV_MAX_LEN		8
214 #define DOT11_A4_HDR_LEN		30
215 
216 #define HT_CAP_RX_STBC_NO		0x0
217 #define HT_CAP_RX_STBC_ONE_STREAM	0x1
218 
219 struct pmkid {
220 	u8 BSSID[ETH_ALEN];
221 	u8 PMKID[WLAN_PMKID_LEN];
222 };
223 
224 struct pmkid_list {
225 	__le32 npmkid;
226 	struct pmkid pmkid[1];
227 };
228 
229 struct pmkid_cand {
230 	u8 BSSID[ETH_ALEN];
231 	u8 preauth;
232 };
233 
234 struct pmkid_cand_list {
235 	u32 npmkid_cand;
236 	struct pmkid_cand pmkid_cand[1];
237 };
238 
239 #endif				/* _BRCMU_WIFI_H_ */
240