1/*- 2 * Copyright (c) 2001 Atsushi Onoe 3 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 17 unchanged lines hidden (view full) --- 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: head/sys/net80211/ieee80211.c 152450 2005-11-15 05:56:32Z sam $"); |
35 36/* 37 * IEEE 802.11 generic handler 38 */ 39 40#include <sys/param.h> 41#include <sys/systm.h> 42#include <sys/kernel.h> --- 185 unchanged lines hidden (view full) --- 228 229 bpfdetach(ifp); 230 ether_ifdetach(ifp); 231} 232 233/* 234 * Convert MHz frequency to IEEE channel number. 235 */ |
236int |
237ieee80211_mhz2ieee(u_int freq, u_int flags) 238{ |
239#define IS_CHAN_IN_PUBLIC_SAFETY_BAND(_c) ((_c) > 4940 && (_c) < 4990) |
240 if (flags & IEEE80211_CHAN_2GHZ) { /* 2GHz band */ 241 if (freq == 2484) 242 return 14; 243 if (freq < 2484) |
244 return ((int) freq - 2407) / 5; |
245 else 246 return 15 + ((freq - 2512) / 20); 247 } else if (flags & IEEE80211_CHAN_5GHZ) { /* 5Ghz band */ |
248 if (IS_CHAN_IN_PUBLIC_SAFETY_BAND(freq)) 249 return ((freq * 10) + 250 (((freq % 5) == 2) ? 5 : 0) - 49400) / 5; 251 if (freq <= 5000) 252 return (freq - 4000) / 5; 253 else 254 return (freq - 5000) / 5; |
255 } else { /* either, guess */ 256 if (freq == 2484) 257 return 14; 258 if (freq < 2484) |
259 return ((int) freq - 2407) / 5; 260 if (freq < 5000) { 261 if (IS_CHAN_IN_PUBLIC_SAFETY_BAND(freq)) 262 return ((freq * 10) + 263 (((freq % 5) == 2) ? 5 : 0) - 49400)/5; 264 else if (freq > 4900) 265 return (freq - 4000) / 5; 266 else 267 return 15 + ((freq - 2512) / 20); 268 } |
269 return (freq - 5000) / 5; 270 } |
271#undef IS_CHAN_IN_PUBLIC_SAFETY_BAND |
272} 273 274/* 275 * Convert channel to IEEE channel number. 276 */ |
277int |
278ieee80211_chan2ieee(struct ieee80211com *ic, struct ieee80211_channel *c) 279{ 280 if (ic->ic_channels <= c && c <= &ic->ic_channels[IEEE80211_CHAN_MAX]) 281 return c - ic->ic_channels; 282 else if (c == IEEE80211_CHAN_ANYC) 283 return IEEE80211_CHAN_ANY; 284 else if (c != NULL) { 285 if_printf(ic->ic_ifp, "invalid channel freq %u flags %x\n", --- 750 unchanged lines hidden --- |