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 (C) 1999-2011, Broadcom Corporation
8 * Unless you and Broadcom execute a separate written software license
9 * agreement governing use of this software, this software is licensed to you
10 * under the terms of the GNU General Public License version 2 (the "GPL"),
11 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
12 * following added to such license:
14 * As a special exception, the copyright holders of this software give you
15 * permission to link this software with independent modules, and to copy and
16 * distribute the resulting executable under terms of your choice, provided that
17 * you also meet, for each linked independent module, the terms and conditions of
18 * the license of that module. An independent module is a module which is not
19 * derived from this software. The special exception does not apply to any
20 * modifications of the software.
22 * Notwithstanding the above, under no circumstances may you combine this
23 * software in any way with any other Broadcom software provided under a license
24 * other than the GPL, without Broadcom's express prior written consent.
26 * $Id: bcmwifi.h,v 1.29.6.3 2010-08-03 17:47:04 $
33 /* A chanspec holds the channel number, band, bandwidth and control sideband */
34 typedef uint16 chanspec_t;
37 #define CH_UPPER_SB 0x01
38 #define CH_LOWER_SB 0x02
39 #define CH_EWA_VALID 0x04
40 #define CH_20MHZ_APART 4
41 #define CH_10MHZ_APART 2
42 #define CH_5MHZ_APART 1 /* 2G band channels are 5 Mhz apart */
43 #define CH_MAX_2G_CHANNEL 14 /* Max channel in 2G band */
44 #define WLC_MAX_2G_CHANNEL CH_MAX_2G_CHANNEL /* legacy define */
45 #define MAXCHANNEL 224 /* max # supported channels. The max channel no is 216,
46 * this is that + 1 rounded up to a multiple of NBBY (8).
47 * DO NOT MAKE it > 255: channels are uint8's all over
50 #define WL_CHANSPEC_CHAN_MASK 0x00ff
51 #define WL_CHANSPEC_CHAN_SHIFT 0
53 #define WL_CHANSPEC_CTL_SB_MASK 0x0300
54 #define WL_CHANSPEC_CTL_SB_SHIFT 8
55 #define WL_CHANSPEC_CTL_SB_LOWER 0x0100
56 #define WL_CHANSPEC_CTL_SB_UPPER 0x0200
57 #define WL_CHANSPEC_CTL_SB_NONE 0x0300
59 #define WL_CHANSPEC_BW_MASK 0x0C00
60 #define WL_CHANSPEC_BW_SHIFT 10
61 #define WL_CHANSPEC_BW_10 0x0400
62 #define WL_CHANSPEC_BW_20 0x0800
63 #define WL_CHANSPEC_BW_40 0x0C00
65 #define WL_CHANSPEC_BAND_MASK 0xf000
66 #define WL_CHANSPEC_BAND_SHIFT 12
67 #define WL_CHANSPEC_BAND_5G 0x1000
68 #define WL_CHANSPEC_BAND_2G 0x2000
69 #define INVCHANSPEC 255
71 /* used to calculate the chan_freq = chan_factor * 500Mhz + 5 * chan_number */
72 #define WF_CHAN_FACTOR_2_4_G 4814 /* 2.4 GHz band, 2407 MHz */
73 #define WF_CHAN_FACTOR_5_G 10000 /* 5 GHz band, 5000 MHz */
74 #define WF_CHAN_FACTOR_4_G 8000 /* 4.9 GHz band for Japan */
77 #define LOWER_20_SB(channel) (((channel) > CH_10MHZ_APART) ? ((channel) - CH_10MHZ_APART) : 0)
78 #define UPPER_20_SB(channel) (((channel) < (MAXCHANNEL - CH_10MHZ_APART)) ? \
79 ((channel) + CH_10MHZ_APART) : 0)
80 #define CHSPEC_WLCBANDUNIT(chspec) (CHSPEC_IS5G(chspec) ? BAND_5G_INDEX : BAND_2G_INDEX)
81 #define CH20MHZ_CHSPEC(channel) (chanspec_t)((chanspec_t)(channel) | WL_CHANSPEC_BW_20 | \
82 WL_CHANSPEC_CTL_SB_NONE | (((channel) <= CH_MAX_2G_CHANNEL) ? \
83 WL_CHANSPEC_BAND_2G : WL_CHANSPEC_BAND_5G))
84 #define NEXT_20MHZ_CHAN(channel) (((channel) < (MAXCHANNEL - CH_20MHZ_APART)) ? \
85 ((channel) + CH_20MHZ_APART) : 0)
86 #define CH40MHZ_CHSPEC(channel, ctlsb) (chanspec_t) \
87 ((channel) | (ctlsb) | WL_CHANSPEC_BW_40 | \
88 ((channel) <= CH_MAX_2G_CHANNEL ? WL_CHANSPEC_BAND_2G : \
90 #define CHSPEC_CHANNEL(chspec) ((uint8)((chspec) & WL_CHANSPEC_CHAN_MASK))
91 #define CHSPEC_BAND(chspec) ((chspec) & WL_CHANSPEC_BAND_MASK)
93 /* chanspec stores radio channel & flags to indicate control channel location, i.e. upper/lower */
94 #define CHSPEC_CTL_SB(chspec) (chspec & WL_CHANSPEC_CTL_SB_MASK)
95 #define CHSPEC_BW(chspec) (chspec & WL_CHANSPEC_BW_MASK)
97 #ifdef WL11N_20MHZONLY
99 #define CHSPEC_IS10(chspec) 0
100 #define CHSPEC_IS20(chspec) 1
102 #define CHSPEC_IS40(chspec) 0
105 #else /* !WL11N_20MHZONLY */
107 #define CHSPEC_IS10(chspec) (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_10)
108 #define CHSPEC_IS20(chspec) (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_20)
110 #define CHSPEC_IS40(chspec) (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_40)
113 #endif /* !WL11N_20MHZONLY */
115 #define CHSPEC_IS20_UNCOND(chspec) (((chspec) & WL_CHANSPEC_BW_MASK) == WL_CHANSPEC_BW_20)
117 #define CHSPEC_IS5G(chspec) (((chspec) & WL_CHANSPEC_BAND_MASK) == WL_CHANSPEC_BAND_5G)
118 #define CHSPEC_IS2G(chspec) (((chspec) & WL_CHANSPEC_BAND_MASK) == WL_CHANSPEC_BAND_2G)
119 #define CHSPEC_SB_NONE(chspec) (((chspec) & WL_CHANSPEC_CTL_SB_MASK) == WL_CHANSPEC_CTL_SB_NONE)
120 #define CHSPEC_SB_UPPER(chspec) (((chspec) & WL_CHANSPEC_CTL_SB_MASK) == WL_CHANSPEC_CTL_SB_UPPER)
121 #define CHSPEC_SB_LOWER(chspec) (((chspec) & WL_CHANSPEC_CTL_SB_MASK) == WL_CHANSPEC_CTL_SB_LOWER)
122 #define CHSPEC_CTL_CHAN(chspec) ((CHSPEC_SB_LOWER(chspec)) ? \
123 (LOWER_20_SB(((chspec) & WL_CHANSPEC_CHAN_MASK))) : \
124 (UPPER_20_SB(((chspec) & WL_CHANSPEC_CHAN_MASK))))
125 #define CHSPEC2WLC_BAND(chspec) (CHSPEC_IS5G(chspec) ? WLC_BAND_5G : WLC_BAND_2G)
127 #define CHANSPEC_STR_LEN 8
129 /* defined rate in 500kbps */
130 #define WLC_MAXRATE 108 /* in 500kbps units */
131 #define WLC_RATE_1M 2 /* in 500kbps units */
132 #define WLC_RATE_2M 4 /* in 500kbps units */
133 #define WLC_RATE_5M5 11 /* in 500kbps units */
134 #define WLC_RATE_11M 22 /* in 500kbps units */
135 #define WLC_RATE_6M 12 /* in 500kbps units */
136 #define WLC_RATE_9M 18 /* in 500kbps units */
137 #define WLC_RATE_12M 24 /* in 500kbps units */
138 #define WLC_RATE_18M 36 /* in 500kbps units */
139 #define WLC_RATE_24M 48 /* in 500kbps units */
140 #define WLC_RATE_36M 72 /* in 500kbps units */
141 #define WLC_RATE_48M 96 /* in 500kbps units */
142 #define WLC_RATE_54M 108 /* in 500kbps units */
144 #define WLC_2G_25MHZ_OFFSET 5 /* 2.4GHz band channel offset */
147 * Convert chanspec to ascii string
148 * @param chspec chanspec format
149 * @param buf ascii string of chanspec
150 * @return pointer to buf with room for at least CHANSPEC_STR_LEN bytes
152 extern char * wf_chspec_ntoa(chanspec_t chspec, char *buf);
155 * Convert ascii string to chanspec
156 * @param a pointer to input string
157 * @return >= 0 if successful or 0 otherwise
159 extern chanspec_t wf_chspec_aton(char *a);
162 * Verify the chanspec is using a legal set of parameters, i.e. that the
163 * chanspec specified a band, bw, ctl_sb and channel and that the
164 * combination could be legal given any set of circumstances.
165 * RETURNS: TRUE is the chanspec is malformed, false if it looks good.
167 extern bool wf_chspec_malformed(chanspec_t chanspec);
170 * This function returns the channel number that control traffic is being sent on, for legacy
171 * channels this is just the channel number, for 40MHZ channels it is the upper or lowre 20MHZ
172 * sideband depending on the chanspec selected
174 extern uint8 wf_chspec_ctlchan(chanspec_t chspec);
177 * This function returns the chanspec that control traffic is being sent on, for legacy
178 * channels this is just the chanspec, for 40MHZ channels it is the upper or lowre 20MHZ
179 * sideband depending on the chanspec selected
181 extern chanspec_t wf_chspec_ctlchspec(chanspec_t chspec);
184 * Return the channel number for a given frequency and base frequency.
185 * The returned channel number is relative to the given base frequency.
186 * If the given base frequency is zero, a base frequency of 5 GHz is assumed for
187 * frequencies from 5 - 6 GHz, and 2.407 GHz is assumed for 2.4 - 2.5 GHz.
189 * Frequency is specified in MHz.
190 * The base frequency is specified as (start_factor * 500 kHz).
191 * Constants WF_CHAN_FACTOR_2_4_G, WF_CHAN_FACTOR_5_G are defined for
192 * 2.4 GHz and 5 GHz bands.
194 * The returned channel will be in the range [1, 14] in the 2.4 GHz band
195 * and [0, 200] otherwise.
196 * -1 is returned if the start_factor is WF_CHAN_FACTOR_2_4_G and the
197 * frequency is not a 2.4 GHz channel, or if the frequency is not and even
198 * multiple of 5 MHz from the base frequency to the base plus 1 GHz.
200 * Reference 802.11 REVma, section 17.3.8.3, and 802.11B section 18.4.6.2
202 extern int wf_mhz2channel(uint freq, uint start_factor);
205 * Return the center frequency in MHz of the given channel and base frequency.
206 * The channel number is interpreted relative to the given base frequency.
208 * The valid channel range is [1, 14] in the 2.4 GHz band and [0, 200] otherwise.
209 * The base frequency is specified as (start_factor * 500 kHz).
210 * Constants WF_CHAN_FACTOR_2_4_G, WF_CHAN_FACTOR_5_G are defined for
211 * 2.4 GHz and 5 GHz bands.
212 * The channel range of [1, 14] is only checked for a start_factor of
213 * WF_CHAN_FACTOR_2_4_G (4814).
214 * Odd start_factors produce channels on .5 MHz boundaries, in which case
215 * the answer is rounded down to an integral MHz.
216 * -1 is returned for an out of range channel.
218 * Reference 802.11 REVma, section 17.3.8.3, and 802.11B section 18.4.6.2
220 extern int wf_channel2mhz(uint channel, uint start_factor);
222 #endif /* _bcmwifi_h_ */