kernel_optimize_test/net/wireless/util.c
Johannes Berg 8318d78a44 cfg80211 API for channels/bitrates, mac80211 and driver conversion
This patch creates new cfg80211 wiphy API for channel and bitrate
registration and converts mac80211 and drivers to the new API. The
old mac80211 API is completely ripped out. All drivers (except ath5k)
are updated to the new API, in many cases I expect that optimisations
can be done.

Along with the regulatory code I've also ripped out the
IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED flag, I believe it to be
unnecessary if the hardware simply gives us whatever channels it wants
to support and we then enable/disable them as required, which is pretty
much required for travelling.

Additionally, the patch adds proper "basic" rate handling for STA
mode interface, AP mode interface will have to have new API added
to allow userspace to set the basic rate set, currently it'll be
empty... However, the basic rate handling will need to be moved to
the BSS conf stuff.

I do expect there to be bugs in this, especially wrt. transmit
power handling where I'm basically clueless about how it should work.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2008-02-29 15:19:32 -05:00

99 lines
2.2 KiB
C

/*
* Wireless utility functions
*
* Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
*/
#include <net/wireless.h>
#include <asm/bitops.h>
#include "core.h"
int ieee80211_channel_to_frequency(int chan)
{
if (chan < 14)
return 2407 + chan * 5;
if (chan == 14)
return 2484;
/* FIXME: 802.11j 17.3.8.3.2 */
return (chan + 1000) * 5;
}
EXPORT_SYMBOL(ieee80211_channel_to_frequency);
int ieee80211_frequency_to_channel(int freq)
{
if (freq == 2484)
return 14;
if (freq < 2484)
return (freq - 2407) / 5;
/* FIXME: 802.11j 17.3.8.3.2 */
return freq/5 - 1000;
}
EXPORT_SYMBOL(ieee80211_frequency_to_channel);
static void set_mandatory_flags_band(struct ieee80211_supported_band *sband,
enum ieee80211_band band)
{
int i, want;
switch (band) {
case IEEE80211_BAND_5GHZ:
want = 3;
for (i = 0; i < sband->n_bitrates; i++) {
if (sband->bitrates[i].bitrate == 60 ||
sband->bitrates[i].bitrate == 120 ||
sband->bitrates[i].bitrate == 240) {
sband->bitrates[i].flags |=
IEEE80211_RATE_MANDATORY_A;
want--;
}
}
WARN_ON(want);
break;
case IEEE80211_BAND_2GHZ:
want = 7;
for (i = 0; i < sband->n_bitrates; i++) {
if (sband->bitrates[i].bitrate == 10) {
sband->bitrates[i].flags |=
IEEE80211_RATE_MANDATORY_B |
IEEE80211_RATE_MANDATORY_G;
want--;
}
if (sband->bitrates[i].bitrate == 20 ||
sband->bitrates[i].bitrate == 55 ||
sband->bitrates[i].bitrate == 110 ||
sband->bitrates[i].bitrate == 60 ||
sband->bitrates[i].bitrate == 120 ||
sband->bitrates[i].bitrate == 240) {
sband->bitrates[i].flags |=
IEEE80211_RATE_MANDATORY_G;
want--;
}
if (sband->bitrates[i].bitrate == 10 ||
sband->bitrates[i].bitrate == 20 ||
sband->bitrates[i].bitrate == 55 ||
sband->bitrates[i].bitrate == 110)
sband->bitrates[i].flags |=
IEEE80211_RATE_ERP_G;
}
WARN_ON(want != 0 && want != 6);
break;
case IEEE80211_NUM_BANDS:
WARN_ON(1);
break;
}
}
void ieee80211_set_bitrate_flags(struct wiphy *wiphy)
{
enum ieee80211_band band;
for (band = 0; band < IEEE80211_NUM_BANDS; band++)
if (wiphy->bands[band])
set_mandatory_flags_band(wiphy->bands[band], band);
}