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 2007, 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))
23 #elif defined(__IOPOS__)
25 #define strtoul(nptr, endptr, base) bcm_strtoul((nptr), (endptr), (base))
26 #define tolower(c) (bcm_tolower((c)))
31 #endif /* BCMDRIVER */
34 /* Chanspec ASCII representation:
35 * <channel><band><bandwidth><ctl-sideband>
38 * <channel>: channel number of the 10MHz or 20MHz channel,
39 * or control sideband channel of 40MHz channel.
40 * <band>: A for 5GHz, B for 2.4GHz
41 * <bandwidth>: N for 10MHz, nothing for 20MHz or 40MHz
42 * (ctl-sideband spec implies 40MHz)
43 * <ctl-sideband>: U for upper, L for lower
45 * <band> may be omitted on input, and will be assumed to be
46 * 2.4GHz if channel number <= 14.
50 /* given a chanspec and a string buffer, format the chanspec as a
51 * string, and return the original pointer a. On error, return's NULL
54 wf_chspec_ntoa(chanspec_t chspec
, char *buf
)
56 const char *band
, *bw
, *sb
;
61 channel
= CHSPEC_CHANNEL(chspec
);
62 band
= (CHSPEC_IS2G(chspec
)) ? "b" : "a";
63 if (CHSPEC_IS40(chspec
)) {
64 if (CHSPEC_SB_UPPER(chspec
)) {
66 channel
+= CH_10MHZ_APART
;
69 channel
-= CH_10MHZ_APART
;
71 } else if (CHSPEC_IS10(chspec
)) {
75 sprintf(buf
, "%d%s%s%s", channel
, band
, bw
, sb
);
79 /* given a chanspec string, convert to a chanspec.
84 wf_chspec_aton(char *a
)
87 uint channel
, band
, bw
, ctl_sb
;
88 bool band_set
= FALSE
, bw_set
= FALSE
, ctl_sb_set
= FALSE
;
91 channel
= strtoul(a
, &endp
, 10);
95 if (channel
> MAXCHANNEL
)
98 band
= ((channel
<= WLC_MAX_2G_CHANNEL
) ? WL_CHANSPEC_BAND_2G
: WL_CHANSPEC_BAND_5G
);
99 bw
= WL_CHANSPEC_BW_20
;
100 ctl_sb
= WL_CHANSPEC_CTL_SB_NONE
;
103 while (*a
!= 0 && error
!= -1) {
104 switch (tolower((int)*a
)) {
108 band
= (tolower((int)*a
) == 'a') ?
109 WL_CHANSPEC_BAND_5G
: WL_CHANSPEC_BAND_2G
;
117 bw
= WL_CHANSPEC_BW_10
;
125 if (!ctl_sb_set
&& !bw_set
) {
126 ctl_sb
= (tolower((int)*a
) == 'l') ?
127 WL_CHANSPEC_CTL_SB_LOWER
: WL_CHANSPEC_CTL_SB_UPPER
;
129 if (ctl_sb
== WL_CHANSPEC_CTL_SB_LOWER
)
130 channel
= UPPER_20_SB(channel
);
132 channel
= LOWER_20_SB(channel
);
133 bw
= WL_CHANSPEC_BW_40
;
148 if (bw_set
&& (bw
== WL_CHANSPEC_BW_40
) && !ctl_sb_set
)
151 if (ctl_sb_set
&& !bw_set
)
155 return ((channel
| band
| bw
| ctl_sb
));
160 #ifdef CONFIG_NET_RADIO
161 /* channel info structure */
163 uint chan
; /* channel number */
164 uint freq
; /* in Mhz */
167 static chan_info_t chan_info
[] = {
228 freq2channel(uint freq
)
232 for (i
= 0; i
< (int)ARRAYSIZE(chan_info
); i
++) {
233 if (chan_info
[i
].freq
== freq
)
234 return (chan_info
[i
].chan
);
240 channel2freq(uint channel
)
244 for (i
= 0; i
< ARRAYSIZE(chan_info
); i
++)
245 if (chan_info
[i
].chan
== channel
)
246 return (chan_info
[i
].freq
);
249 #endif /* CONFIG_NET_RADIO */