2 * Misc utility routines used by kernel or app-level.
3 * Contents are wifi-specific, used by any kernel or app-level
4 * software that might want wifi things as it grows.
6 * Copyright (C) 1999-2010, 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.
25 * $Id: bcmwifi.c,v 1.18.24.2.4.1 2009/09/25 00:32:01 Exp $
34 #define strtoul(nptr, endptr, base) bcm_strtoul((nptr), (endptr), (base))
35 #define tolower(c) (bcm_isupper((c)) ? ((c) + 'a' - 'A') : (c))
43 #if defined(WIN32) && (defined(BCMDLL) || defined(WLMDLL))
44 #include <bcmstdlib.h>
52 wf_chspec_ntoa(chanspec_t chspec, char *buf)
54 const char *band, *bw, *sb;
60 channel = CHSPEC_CHANNEL(chspec);
62 if ((CHSPEC_IS2G(chspec) && channel > CH_MAX_2G_CHANNEL) ||
63 (CHSPEC_IS5G(chspec) && channel <= CH_MAX_2G_CHANNEL))
64 band = (CHSPEC_IS2G(chspec)) ? "b" : "a";
65 if (CHSPEC_IS40(chspec)) {
66 if (CHSPEC_SB_UPPER(chspec)) {
68 channel += CH_10MHZ_APART;
71 channel -= CH_10MHZ_APART;
73 } else if (CHSPEC_IS10(chspec)) {
78 snprintf(buf, 6, "%d%s%s%s", channel, band, bw, sb);
84 wf_chspec_aton(char *a)
87 uint channel, band, bw, ctl_sb;
90 channel = strtoul(a, &endp, 10);
96 if (channel > MAXCHANNEL)
99 band = ((channel <= CH_MAX_2G_CHANNEL) ? WL_CHANSPEC_BAND_2G : WL_CHANSPEC_BAND_5G);
100 bw = WL_CHANSPEC_BW_20;
101 ctl_sb = WL_CHANSPEC_CTL_SB_NONE;
110 if (c == 'a' || c == 'b') {
111 band = (c == 'a') ? WL_CHANSPEC_BAND_5G : WL_CHANSPEC_BAND_2G;
120 bw = WL_CHANSPEC_BW_10;
121 } else if (c == 'l') {
122 bw = WL_CHANSPEC_BW_40;
123 ctl_sb = WL_CHANSPEC_CTL_SB_LOWER;
125 if (channel <= (MAXCHANNEL - CH_20MHZ_APART))
126 channel += CH_10MHZ_APART;
129 } else if (c == 'u') {
130 bw = WL_CHANSPEC_BW_40;
131 ctl_sb = WL_CHANSPEC_CTL_SB_UPPER;
133 if (channel > CH_20MHZ_APART)
134 channel -= CH_10MHZ_APART;
142 return (channel | band | bw | ctl_sb);
147 wf_mhz2channel(uint freq, uint start_factor)
154 if (start_factor == 0) {
155 if (freq >= 2400 && freq <= 2500)
156 start_factor = WF_CHAN_FACTOR_2_4_G;
157 else if (freq >= 5000 && freq <= 6000)
158 start_factor = WF_CHAN_FACTOR_5_G;
161 if (freq == 2484 && start_factor == WF_CHAN_FACTOR_2_4_G)
164 base = start_factor / 2;
167 if ((freq < base) || (freq > base + 1000))
170 offset = freq - base;
174 if (offset != (ch * 5))
178 if (start_factor == WF_CHAN_FACTOR_2_4_G && (ch < 1 || ch > 13))
186 wf_channel2mhz(uint ch, uint start_factor)
190 if ((start_factor == WF_CHAN_FACTOR_2_4_G && (ch < 1 || ch > 14)) ||
193 if ((start_factor == WF_CHAN_FACTOR_2_4_G) && (ch == 14))
196 freq = ch * 5 + start_factor / 2;