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 2006, Broadcom Corporation
9 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
10 * the contents of this file may not be disclosed to third parties, copied
11 * or duplicated in any form, in whole or in part, without the prior
12 * written permission of Broadcom Corporation.
21 #define strtoul(nptr, endptr, base) bcm_strtoul((nptr), (endptr), (base))
22 #define tolower(c) (bcm_isupper((c)) ? ((c) + 'a' - 'A') : (c))
27 #endif /* BCMDRIVER */
30 /* Chanspec ASCII representation:
31 * <channel><band><bandwidth><ctl-sideband>
34 * <channel>: channel number of the 10MHz or 20MHz channel,
35 * or control sideband channel of 40MHz channel.
36 * <band>: A for 5GHz, B for 2.4GHz
37 * <bandwidth>: N for 10MHz, nothing for 20MHz or 40MHz
38 * (ctl-sideband spec implies 40MHz)
39 * <ctl-sideband>: U for upper, L for lower
41 * <band> may be omitted on input, and will be assumed to be
42 * 2.4GHz if channel number <= 14.
46 /* given a chanspec and a string buffer, format the chanspec as a
47 * string, and return the original pointer a. On error, return's NULL
50 wf_chspec_ntoa(chanspec_t chspec, char *buf)
52 const char *band, *bw, *sb;
57 channel = CHSPEC_CHANNEL(chspec);
58 band = (CHSPEC_IS2G(chspec)) ? "b" : "a";
59 if (CHSPEC_IS40(chspec)) {
60 if (CHSPEC_SB_UPPER(chspec)) {
62 channel += CH_10MHZ_APART;
65 channel -= CH_10MHZ_APART;
67 } else if (CHSPEC_IS10(chspec)) {
71 sprintf(buf, "%d%s%s%s", channel, band, bw, sb);
75 /* given a chanspec string, convert to a chanspec.
80 wf_chspec_aton(char *a)
83 uint channel, band, bw, ctl_sb;
84 bool band_set = FALSE, bw_set = FALSE, ctl_sb_set = FALSE;
87 channel = strtoul(a, &endp, 10);
91 if (channel > MAXCHANNEL)
94 band = ((channel <= WLC_MAX_2G_CHANNEL) ? WL_CHANSPEC_BAND_2G : WL_CHANSPEC_BAND_5G);
95 bw = WL_CHANSPEC_BW_20;
96 ctl_sb = WL_CHANSPEC_CTL_SB_NONE;
99 while (*a != 0 && error != -1) {
100 switch (tolower((int)*a)) {
104 band = (tolower((int)*a) == 'a') ?
105 WL_CHANSPEC_BAND_5G : WL_CHANSPEC_BAND_2G;
113 bw = WL_CHANSPEC_BW_10;
121 if (!ctl_sb_set && !bw_set) {
122 ctl_sb = (tolower((int)*a) == 'l') ?
123 WL_CHANSPEC_CTL_SB_LOWER : WL_CHANSPEC_CTL_SB_UPPER;
125 if (ctl_sb == WL_CHANSPEC_CTL_SB_LOWER)
126 channel = UPPER_20_SB(channel);
128 channel = LOWER_20_SB(channel);
129 bw = WL_CHANSPEC_BW_40;
144 if (bw_set && (bw == WL_CHANSPEC_BW_40) && !ctl_sb_set)
147 if (ctl_sb_set && !bw_set)
151 return ((channel | band | bw | ctl_sb));