2 * Misc utility routines for WL and Apps
3 * This header file housing the define and function prototype use by
4 * both the wl driver, tools & Apps.
6 * $Copyright Open Broadcom Corporation$
8 * $Id: bcmwifi_channels.h 309193 2012-01-19 00:03:57Z $
11 #ifndef _bcmwifi_channels_h_
12 #define _bcmwifi_channels_h_
16 typedef uint16 chanspec_t;
19 #define CH_UPPER_SB 0x01
20 #define CH_LOWER_SB 0x02
21 #define CH_EWA_VALID 0x04
22 #define CH_80MHZ_APART 16
23 #define CH_40MHZ_APART 8
24 #define CH_20MHZ_APART 4
25 #define CH_10MHZ_APART 2
26 #define CH_5MHZ_APART 1
27 #define CH_MAX_2G_CHANNEL 14
28 #define MAXCHANNEL 224
29 #define CHSPEC_CTLOVLP(sp1, sp2, sep) (ABS(wf_chspec_ctlchan(sp1) - wf_chspec_ctlchan(sp2)) < \
38 #define WL_CHANSPEC_CHAN_MASK 0x00ff
39 #define WL_CHANSPEC_CHAN_SHIFT 0
41 #define WL_CHANSPEC_CTL_SB_MASK 0x0300
42 #define WL_CHANSPEC_CTL_SB_SHIFT 8
43 #define WL_CHANSPEC_CTL_SB_LOWER 0x0100
44 #define WL_CHANSPEC_CTL_SB_UPPER 0x0200
45 #define WL_CHANSPEC_CTL_SB_NONE 0x0300
47 #define WL_CHANSPEC_BW_MASK 0x0C00
48 #define WL_CHANSPEC_BW_SHIFT 10
49 #define WL_CHANSPEC_BW_10 0x0400
50 #define WL_CHANSPEC_BW_20 0x0800
51 #define WL_CHANSPEC_BW_40 0x0C00
53 #define WL_CHANSPEC_BAND_MASK 0xf000
54 #define WL_CHANSPEC_BAND_SHIFT 12
55 #ifdef WL_CHANSPEC_BAND_5G
56 #undef WL_CHANSPEC_BAND_5G
58 #ifdef WL_CHANSPEC_BAND_2G
59 #undef WL_CHANSPEC_BAND_2G
61 #define WL_CHANSPEC_BAND_5G 0x1000
62 #define WL_CHANSPEC_BAND_2G 0x2000
63 #define INVCHANSPEC 255
66 #define LOWER_20_SB(channel) (((channel) > CH_10MHZ_APART) ? ((channel) - CH_10MHZ_APART) : 0)
67 #define UPPER_20_SB(channel) (((channel) < (MAXCHANNEL - CH_10MHZ_APART)) ? \
68 ((channel) + CH_10MHZ_APART) : 0)
70 #define LL_20_SB(channel) (((channel) > 3 * CH_10MHZ_APART) ? ((channel) - 3 * CH_10MHZ_APART) : 0)
71 #define UU_20_SB(channel) (((channel) < (MAXCHANNEL - 3 * CH_10MHZ_APART)) ? \
72 ((channel) + 3 * CH_10MHZ_APART) : 0)
73 #define LU_20_SB(channel) LOWER_20_SB(channel)
74 #define UL_20_SB(channel) UPPER_20_SB(channel)
76 #define CHSPEC_WLCBANDUNIT(chspec) (CHSPEC_IS5G(chspec) ? BAND_5G_INDEX : BAND_2G_INDEX)
77 #define CH20MHZ_CHSPEC(channel) (chanspec_t)((chanspec_t)(channel) | WL_CHANSPEC_BW_20 | \
78 WL_CHANSPEC_CTL_SB_NONE | (((channel) <= CH_MAX_2G_CHANNEL) ? \
79 WL_CHANSPEC_BAND_2G : WL_CHANSPEC_BAND_5G))
80 #define NEXT_20MHZ_CHAN(channel) (((channel) < (MAXCHANNEL - CH_20MHZ_APART)) ? \
81 ((channel) + CH_20MHZ_APART) : 0)
82 #define CH40MHZ_CHSPEC(channel, ctlsb) (chanspec_t) \
83 ((channel) | (ctlsb) | WL_CHANSPEC_BW_40 | \
84 ((channel) <= CH_MAX_2G_CHANNEL ? WL_CHANSPEC_BAND_2G : \
86 #define CHSPEC_CHANNEL(chspec) ((uint8)((chspec) & WL_CHANSPEC_CHAN_MASK))
87 #define CHSPEC_BAND(chspec) ((chspec) & WL_CHANSPEC_BAND_MASK)
90 #define CHSPEC_CTL_SB(chspec) ((chspec) & WL_CHANSPEC_CTL_SB_MASK)
91 #define CHSPEC_BW(chspec) ((chspec) & WL_CHANSPEC_BW_MASK)
93 #ifdef WL11N_20MHZONLY
95 #define CHSPEC_IS10(chspec) 0
96 #define CHSPEC_IS20(chspec) 1
98 #define CHSPEC_IS40(chspec) 0
103 #define CHSPEC_IS10(chspec) (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_10)
104 #define CHSPEC_IS20(chspec) (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_20)
106 #define CHSPEC_IS40(chspec) (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_40)
111 #define CHSPEC_IS5G(chspec) (((chspec) & WL_CHANSPEC_BAND_MASK) == WL_CHANSPEC_BAND_5G)
112 #define CHSPEC_IS2G(chspec) (((chspec) & WL_CHANSPEC_BAND_MASK) == WL_CHANSPEC_BAND_2G)
113 #define CHSPEC_SB_NONE(chspec) (((chspec) & WL_CHANSPEC_CTL_SB_MASK) == WL_CHANSPEC_CTL_SB_NONE)
114 #define CHSPEC_SB_UPPER(chspec) (((chspec) & WL_CHANSPEC_CTL_SB_MASK) == WL_CHANSPEC_CTL_SB_UPPER)
115 #define CHSPEC_SB_LOWER(chspec) (((chspec) & WL_CHANSPEC_CTL_SB_MASK) == WL_CHANSPEC_CTL_SB_LOWER)
116 #define CHSPEC_CTL_CHAN(chspec) ((CHSPEC_SB_LOWER(chspec)) ? \
117 (LOWER_20_SB(((chspec) & WL_CHANSPEC_CHAN_MASK))) : \
118 (UPPER_20_SB(((chspec) & WL_CHANSPEC_CHAN_MASK))))
119 #define CHSPEC2WLC_BAND(chspec) (CHSPEC_IS5G(chspec) ? WLC_BAND_5G : WLC_BAND_2G)
121 #define CHANSPEC_STR_LEN 8
125 #define WL_CHANSPEC_CHAN_MASK 0x00ff
126 #define WL_CHANSPEC_CHAN_SHIFT 0
127 #define WL_CHANSPEC_CHAN1_MASK 0x000f
128 #define WL_CHANSPEC_CHAN1_SHIFT 0
129 #define WL_CHANSPEC_CHAN2_MASK 0x00f0
130 #define WL_CHANSPEC_CHAN2_SHIFT 4
132 #define WL_CHANSPEC_CTL_SB_MASK 0x0700
133 #define WL_CHANSPEC_CTL_SB_SHIFT 8
134 #define WL_CHANSPEC_CTL_SB_LLL 0x0000
135 #define WL_CHANSPEC_CTL_SB_LLU 0x0100
136 #define WL_CHANSPEC_CTL_SB_LUL 0x0200
137 #define WL_CHANSPEC_CTL_SB_LUU 0x0300
138 #define WL_CHANSPEC_CTL_SB_ULL 0x0400
139 #define WL_CHANSPEC_CTL_SB_ULU 0x0500
140 #define WL_CHANSPEC_CTL_SB_UUL 0x0600
141 #define WL_CHANSPEC_CTL_SB_UUU 0x0700
142 #define WL_CHANSPEC_CTL_SB_LL WL_CHANSPEC_CTL_SB_LLL
143 #define WL_CHANSPEC_CTL_SB_LU WL_CHANSPEC_CTL_SB_LLU
144 #define WL_CHANSPEC_CTL_SB_UL WL_CHANSPEC_CTL_SB_LUL
145 #define WL_CHANSPEC_CTL_SB_UU WL_CHANSPEC_CTL_SB_LUU
146 #define WL_CHANSPEC_CTL_SB_L WL_CHANSPEC_CTL_SB_LLL
147 #define WL_CHANSPEC_CTL_SB_U WL_CHANSPEC_CTL_SB_LLU
148 #define WL_CHANSPEC_CTL_SB_LOWER WL_CHANSPEC_CTL_SB_LLL
149 #define WL_CHANSPEC_CTL_SB_UPPER WL_CHANSPEC_CTL_SB_LLU
151 #define WL_CHANSPEC_BW_MASK 0x3800
152 #define WL_CHANSPEC_BW_SHIFT 11
153 #define WL_CHANSPEC_BW_5 0x0000
154 #define WL_CHANSPEC_BW_10 0x0800
155 #define WL_CHANSPEC_BW_20 0x1000
156 #define WL_CHANSPEC_BW_40 0x1800
157 #define WL_CHANSPEC_BW_80 0x2000
158 #define WL_CHANSPEC_BW_160 0x2800
159 #define WL_CHANSPEC_BW_8080 0x3000
161 #define WL_CHANSPEC_BAND_MASK 0xc000
162 #define WL_CHANSPEC_BAND_SHIFT 14
163 #define WL_CHANSPEC_BAND_2G 0x0000
164 #define WL_CHANSPEC_BAND_3G 0x4000
165 #define WL_CHANSPEC_BAND_4G 0x8000
166 #define WL_CHANSPEC_BAND_5G 0xc000
167 #define INVCHANSPEC 255
170 #define LOWER_20_SB(channel) (((channel) > CH_10MHZ_APART) ? \
171 ((channel) - CH_10MHZ_APART) : 0)
172 #define UPPER_20_SB(channel) (((channel) < (MAXCHANNEL - CH_10MHZ_APART)) ? \
173 ((channel) + CH_10MHZ_APART) : 0)
175 #define LL_20_SB(channel) (((channel) > 3 * CH_10MHZ_APART) ? ((channel) - 3 * CH_10MHZ_APART) : 0)
176 #define UU_20_SB(channel) (((channel) < (MAXCHANNEL - 3 * CH_10MHZ_APART)) ? \
177 ((channel) + 3 * CH_10MHZ_APART) : 0)
178 #define LU_20_SB(channel) LOWER_20_SB(channel)
179 #define UL_20_SB(channel) UPPER_20_SB(channel)
181 #define LOWER_40_SB(channel) ((channel) - CH_20MHZ_APART)
182 #define UPPER_40_SB(channel) ((channel) + CH_20MHZ_APART)
183 #define CHSPEC_WLCBANDUNIT(chspec) (CHSPEC_IS5G(chspec) ? BAND_5G_INDEX : BAND_2G_INDEX)
184 #define CH20MHZ_CHSPEC(channel) (chanspec_t)((chanspec_t)(channel) | WL_CHANSPEC_BW_20 | \
185 (((channel) <= CH_MAX_2G_CHANNEL) ? \
186 WL_CHANSPEC_BAND_2G : WL_CHANSPEC_BAND_5G))
187 #define NEXT_20MHZ_CHAN(channel) (((channel) < (MAXCHANNEL - CH_20MHZ_APART)) ? \
188 ((channel) + CH_20MHZ_APART) : 0)
189 #define CH40MHZ_CHSPEC(channel, ctlsb) (chanspec_t) \
190 ((channel) | (ctlsb) | WL_CHANSPEC_BW_40 | \
191 ((channel) <= CH_MAX_2G_CHANNEL ? WL_CHANSPEC_BAND_2G : \
192 WL_CHANSPEC_BAND_5G))
193 #define CH80MHZ_CHSPEC(channel, ctlsb) (chanspec_t) \
194 ((channel) | (ctlsb) | \
195 WL_CHANSPEC_BW_80 | WL_CHANSPEC_BAND_5G)
196 #define CH160MHZ_CHSPEC(channel, ctlsb) (chanspec_t) \
197 ((channel) | (ctlsb) | \
198 WL_CHANSPEC_BW_160 | WL_CHANSPEC_BAND_5G)
201 #define CHSPEC_CHANNEL(chspec) ((uint8)((chspec) & WL_CHANSPEC_CHAN_MASK))
202 #define CHSPEC_CHAN1(chspec) ((chspec) & WL_CHANSPEC_CHAN1_MASK)
203 #define CHSPEC_CHAN2(chspec) ((chspec) & WL_CHANSPEC_CHAN2_MASK)
204 #define CHSPEC_BAND(chspec) ((chspec) & WL_CHANSPEC_BAND_MASK)
205 #define CHSPEC_CTL_SB(chspec) ((chspec) & WL_CHANSPEC_CTL_SB_MASK)
206 #define CHSPEC_BW(chspec) ((chspec) & WL_CHANSPEC_BW_MASK)
208 #ifdef WL11N_20MHZONLY
210 #define CHSPEC_IS10(chspec) 0
211 #define CHSPEC_IS20(chspec) 1
213 #define CHSPEC_IS40(chspec) 0
216 #define CHSPEC_IS80(chspec) 0
219 #define CHSPEC_IS160(chspec) 0
221 #ifndef CHSPEC_IS8080
222 #define CHSPEC_IS8080(chspec) 0
227 #define CHSPEC_IS10(chspec) (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_10)
228 #define CHSPEC_IS20(chspec) (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_20)
230 #define CHSPEC_IS40(chspec) (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_40)
233 #define CHSPEC_IS80(chspec) (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_80)
236 #define CHSPEC_IS160(chspec) (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_160)
238 #ifndef CHSPEC_IS8080
239 #define CHSPEC_IS8080(chspec) (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_8080)
244 #define CHSPEC_IS5G(chspec) (((chspec) & WL_CHANSPEC_BAND_MASK) == WL_CHANSPEC_BAND_5G)
245 #define CHSPEC_IS2G(chspec) (((chspec) & WL_CHANSPEC_BAND_MASK) == WL_CHANSPEC_BAND_2G)
246 #define CHSPEC_SB_UPPER(chspec) \
247 ((((chspec) & WL_CHANSPEC_CTL_SB_MASK) == WL_CHANSPEC_CTL_SB_UPPER) && \
248 (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_40))
249 #define CHSPEC_SB_LOWER(chspec) \
250 ((((chspec) & WL_CHANSPEC_CTL_SB_MASK) == WL_CHANSPEC_CTL_SB_LOWER) && \
251 (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_40))
252 #define CHSPEC2WLC_BAND(chspec) (CHSPEC_IS5G(chspec) ? WLC_BAND_5G : WLC_BAND_2G)
255 #define CHANSPEC_STR_LEN 20
259 #define WL_LCHANSPEC_CHAN_MASK 0x00ff
260 #define WL_LCHANSPEC_CHAN_SHIFT 0
262 #define WL_LCHANSPEC_CTL_SB_MASK 0x0300
263 #define WL_LCHANSPEC_CTL_SB_SHIFT 8
264 #define WL_LCHANSPEC_CTL_SB_LOWER 0x0100
265 #define WL_LCHANSPEC_CTL_SB_UPPER 0x0200
266 #define WL_LCHANSPEC_CTL_SB_NONE 0x0300
268 #define WL_LCHANSPEC_BW_MASK 0x0C00
269 #define WL_LCHANSPEC_BW_SHIFT 10
270 #define WL_LCHANSPEC_BW_10 0x0400
271 #define WL_LCHANSPEC_BW_20 0x0800
272 #define WL_LCHANSPEC_BW_40 0x0C00
274 #define WL_LCHANSPEC_BAND_MASK 0xf000
275 #define WL_LCHANSPEC_BAND_SHIFT 12
276 #define WL_LCHANSPEC_BAND_5G 0x1000
277 #define WL_LCHANSPEC_BAND_2G 0x2000
279 #define LCHSPEC_CHANNEL(chspec) ((uint8)((chspec) & WL_LCHANSPEC_CHAN_MASK))
280 #define LCHSPEC_BAND(chspec) ((chspec) & WL_LCHANSPEC_BAND_MASK)
281 #define LCHSPEC_CTL_SB(chspec) ((chspec) & WL_LCHANSPEC_CTL_SB_MASK)
282 #define LCHSPEC_BW(chspec) ((chspec) & WL_LCHANSPEC_BW_MASK)
283 #define LCHSPEC_IS10(chspec) (((chspec) & WL_LCHANSPEC_BW_MASK) == WL_LCHANSPEC_BW_10)
284 #define LCHSPEC_IS20(chspec) (((chspec) & WL_LCHANSPEC_BW_MASK) == WL_LCHANSPEC_BW_20)
285 #define LCHSPEC_IS40(chspec) (((chspec) & WL_LCHANSPEC_BW_MASK) == WL_LCHANSPEC_BW_40)
286 #define LCHSPEC_IS5G(chspec) (((chspec) & WL_LCHANSPEC_BAND_MASK) == WL_LCHANSPEC_BAND_5G)
287 #define LCHSPEC_IS2G(chspec) (((chspec) & WL_LCHANSPEC_BAND_MASK) == WL_LCHANSPEC_BAND_2G)
289 #define LCHSPEC_CREATE(chan, band, bw, sb) ((uint16)((chan) | (sb) | (bw) | (band)))
291 #define CH20MHZ_LCHSPEC(channel) \
292 (chanspec_t)((chanspec_t)(channel) | WL_LCHANSPEC_BW_20 | \
293 WL_LCHANSPEC_CTL_SB_NONE | (((channel) <= CH_MAX_2G_CHANNEL) ? \
294 WL_LCHANSPEC_BAND_2G : WL_LCHANSPEC_BAND_5G))
301 #define WF_CHAN_FACTOR_2_4_G 4814
304 #define WF_CHAN_FACTOR_5_G 10000
307 #define WF_CHAN_FACTOR_4_G 8000
309 #define WLC_2G_25MHZ_OFFSET 5
312 extern char * wf_chspec_ntoa(chanspec_t chspec, char *buf);
315 extern chanspec_t wf_chspec_aton(const char *a);
318 extern bool wf_chspec_malformed(chanspec_t chanspec);
321 extern bool wf_chspec_valid(chanspec_t chanspec);
324 extern uint8 wf_chspec_ctlchan(chanspec_t chspec);
327 extern chanspec_t wf_chspec_ctlchspec(chanspec_t chspec);
330 extern chanspec_t wf_chspec_primary40_chspec(chanspec_t chspec);
333 extern int wf_mhz2channel(uint freq, uint start_factor);
336 extern int wf_channel2mhz(uint channel, uint start_factor);
339 extern uint16 wf_channel2chspec(uint ctl_ch, uint bw);
341 extern uint wf_channel2freq(uint channel);
342 extern uint wf_freq2channel(uint freq);