2009-08-07 09:22:35 -06:00
|
|
|
/*
|
|
|
|
* This file contains helper code to handle channel
|
|
|
|
* settings and keeping track of what is possible at
|
|
|
|
* any point in time.
|
|
|
|
*
|
|
|
|
* Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
|
|
|
|
*/
|
|
|
|
|
2011-11-30 08:56:32 -07:00
|
|
|
#include <linux/export.h>
|
2009-08-07 09:22:35 -06:00
|
|
|
#include <net/cfg80211.h>
|
|
|
|
#include "core.h"
|
|
|
|
|
2009-12-23 05:15:41 -07:00
|
|
|
struct ieee80211_channel *
|
|
|
|
rdev_freq_to_chan(struct cfg80211_registered_device *rdev,
|
2009-08-07 09:22:35 -06:00
|
|
|
int freq, enum nl80211_channel_type channel_type)
|
|
|
|
{
|
|
|
|
struct ieee80211_channel *chan;
|
|
|
|
struct ieee80211_sta_ht_cap *ht_cap;
|
|
|
|
|
|
|
|
chan = ieee80211_get_channel(&rdev->wiphy, freq);
|
|
|
|
|
|
|
|
/* Primary channel not allowed */
|
|
|
|
if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
|
2009-12-23 05:15:41 -07:00
|
|
|
return NULL;
|
2009-08-07 09:22:35 -06:00
|
|
|
|
|
|
|
if (channel_type == NL80211_CHAN_HT40MINUS &&
|
|
|
|
chan->flags & IEEE80211_CHAN_NO_HT40MINUS)
|
2009-12-23 05:15:41 -07:00
|
|
|
return NULL;
|
2009-08-07 09:22:35 -06:00
|
|
|
else if (channel_type == NL80211_CHAN_HT40PLUS &&
|
|
|
|
chan->flags & IEEE80211_CHAN_NO_HT40PLUS)
|
2009-12-23 05:15:41 -07:00
|
|
|
return NULL;
|
2009-08-07 09:22:35 -06:00
|
|
|
|
|
|
|
ht_cap = &rdev->wiphy.bands[chan->band]->ht_cap;
|
|
|
|
|
|
|
|
if (channel_type != NL80211_CHAN_NO_HT) {
|
|
|
|
if (!ht_cap->ht_supported)
|
2009-12-23 05:15:41 -07:00
|
|
|
return NULL;
|
2009-08-07 09:22:35 -06:00
|
|
|
|
2010-05-17 09:30:59 -06:00
|
|
|
if (channel_type != NL80211_CHAN_HT20 &&
|
|
|
|
(!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) ||
|
|
|
|
ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT))
|
2009-12-23 05:15:41 -07:00
|
|
|
return NULL;
|
2009-08-07 09:22:35 -06:00
|
|
|
}
|
|
|
|
|
2009-12-23 05:15:41 -07:00
|
|
|
return chan;
|
|
|
|
}
|
|
|
|
|
2011-11-30 08:56:32 -07:00
|
|
|
int cfg80211_can_beacon_sec_chan(struct wiphy *wiphy,
|
|
|
|
struct ieee80211_channel *chan,
|
|
|
|
enum nl80211_channel_type channel_type)
|
2010-11-12 17:31:23 -07:00
|
|
|
{
|
|
|
|
struct ieee80211_channel *sec_chan;
|
|
|
|
int diff;
|
|
|
|
|
|
|
|
switch (channel_type) {
|
|
|
|
case NL80211_CHAN_HT40PLUS:
|
|
|
|
diff = 20;
|
2010-11-17 14:34:37 -07:00
|
|
|
break;
|
2010-11-12 17:31:23 -07:00
|
|
|
case NL80211_CHAN_HT40MINUS:
|
|
|
|
diff = -20;
|
2010-11-17 14:34:37 -07:00
|
|
|
break;
|
2010-11-12 17:31:23 -07:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
sec_chan = ieee80211_get_channel(wiphy, chan->center_freq + diff);
|
|
|
|
if (!sec_chan)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* we'll need a DFS capability later */
|
|
|
|
if (sec_chan->flags & (IEEE80211_CHAN_DISABLED |
|
|
|
|
IEEE80211_CHAN_PASSIVE_SCAN |
|
|
|
|
IEEE80211_CHAN_NO_IBSS |
|
|
|
|
IEEE80211_CHAN_RADAR))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2011-11-30 08:56:32 -07:00
|
|
|
EXPORT_SYMBOL(cfg80211_can_beacon_sec_chan);
|
2010-11-12 17:31:23 -07:00
|
|
|
|
cfg80211/mac80211: better channel handling
Currently (all tested with hwsim) you can do stupid
things like setting up an AP on a certain channel,
then adding another virtual interface and making
that associate on another channel -- this will make
the beaconing to move channel but obviously without
the necessary IEs data update.
In order to improve this situation, first make the
configuration APIs (cfg80211 and nl80211) aware of
multi-channel operation -- we'll eventually need
that in the future anyway. There's one userland API
change and one API addition. The API change is that
now SET_WIPHY must be called with virtual interface
index rather than only wiphy index in order to take
effect for that interface -- luckily all current
users (hostapd) do that. For monitor interfaces, the
old setting is preserved, but monitors are always
slaved to other devices anyway so no guarantees.
The second userland API change is the introduction
of a per virtual interface SET_CHANNEL command, that
hostapd should use going forward to make it easier
to understand what's going on (it can automatically
detect a kernel with this command).
Other than mac80211, no existing cfg80211 drivers
are affected by this change because they only allow
a single virtual interface.
mac80211, however, now needs to be aware that the
channel settings are per interface now, and needs
to disallow (for now) real multi-channel operation,
which is another important part of this patch.
One of the immediate benefits is that you can now
start hostapd to operate on a hardware that already
has a connection on another virtual interface, as
long as you specify the same channel.
Note that two things are left unhandled (this is an
improvement -- not a complete fix):
* different HT/no-HT modes
currently you could start an HT AP and then
connect to a non-HT network on the same channel
which would configure the hardware for no HT;
that can be fixed fairly easily
* CSA
An AP we're connected to on a virtual interface
might indicate switching channels, and in that
case we would follow it, regardless of how many
other interfaces are operating; this requires
more effort to fix but is pretty rare after all
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2010-05-05 07:25:02 -06:00
|
|
|
int cfg80211_set_freq(struct cfg80211_registered_device *rdev,
|
|
|
|
struct wireless_dev *wdev, int freq,
|
|
|
|
enum nl80211_channel_type channel_type)
|
2009-12-23 05:15:41 -07:00
|
|
|
{
|
|
|
|
struct ieee80211_channel *chan;
|
|
|
|
int result;
|
|
|
|
|
2010-05-15 07:46:17 -06:00
|
|
|
if (wdev && wdev->iftype == NL80211_IFTYPE_MONITOR)
|
cfg80211/mac80211: better channel handling
Currently (all tested with hwsim) you can do stupid
things like setting up an AP on a certain channel,
then adding another virtual interface and making
that associate on another channel -- this will make
the beaconing to move channel but obviously without
the necessary IEs data update.
In order to improve this situation, first make the
configuration APIs (cfg80211 and nl80211) aware of
multi-channel operation -- we'll eventually need
that in the future anyway. There's one userland API
change and one API addition. The API change is that
now SET_WIPHY must be called with virtual interface
index rather than only wiphy index in order to take
effect for that interface -- luckily all current
users (hostapd) do that. For monitor interfaces, the
old setting is preserved, but monitors are always
slaved to other devices anyway so no guarantees.
The second userland API change is the introduction
of a per virtual interface SET_CHANNEL command, that
hostapd should use going forward to make it easier
to understand what's going on (it can automatically
detect a kernel with this command).
Other than mac80211, no existing cfg80211 drivers
are affected by this change because they only allow
a single virtual interface.
mac80211, however, now needs to be aware that the
channel settings are per interface now, and needs
to disallow (for now) real multi-channel operation,
which is another important part of this patch.
One of the immediate benefits is that you can now
start hostapd to operate on a hardware that already
has a connection on another virtual interface, as
long as you specify the same channel.
Note that two things are left unhandled (this is an
improvement -- not a complete fix):
* different HT/no-HT modes
currently you could start an HT AP and then
connect to a non-HT network on the same channel
which would configure the hardware for no HT;
that can be fixed fairly easily
* CSA
An AP we're connected to on a virtual interface
might indicate switching channels, and in that
case we would follow it, regardless of how many
other interfaces are operating; this requires
more effort to fix but is pretty rare after all
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2010-05-05 07:25:02 -06:00
|
|
|
wdev = NULL;
|
|
|
|
|
|
|
|
if (wdev) {
|
|
|
|
ASSERT_WDEV_LOCK(wdev);
|
|
|
|
|
|
|
|
if (!netif_running(wdev->netdev))
|
|
|
|
return -ENETDOWN;
|
|
|
|
}
|
2009-12-23 05:15:41 -07:00
|
|
|
|
|
|
|
if (!rdev->ops->set_channel)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
chan = rdev_freq_to_chan(rdev, freq, channel_type);
|
|
|
|
if (!chan)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2010-11-12 17:31:23 -07:00
|
|
|
/* Both channels should be able to initiate communication */
|
|
|
|
if (wdev && (wdev->iftype == NL80211_IFTYPE_ADHOC ||
|
|
|
|
wdev->iftype == NL80211_IFTYPE_AP ||
|
|
|
|
wdev->iftype == NL80211_IFTYPE_AP_VLAN ||
|
|
|
|
wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
|
|
|
|
wdev->iftype == NL80211_IFTYPE_P2P_GO)) {
|
|
|
|
switch (channel_type) {
|
|
|
|
case NL80211_CHAN_HT40PLUS:
|
|
|
|
case NL80211_CHAN_HT40MINUS:
|
2011-11-30 08:56:32 -07:00
|
|
|
if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, chan,
|
|
|
|
channel_type)) {
|
2010-11-12 17:31:23 -07:00
|
|
|
printk(KERN_DEBUG
|
|
|
|
"cfg80211: Secondary channel not "
|
|
|
|
"allowed to initiate communication\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
cfg80211/mac80211: better channel handling
Currently (all tested with hwsim) you can do stupid
things like setting up an AP on a certain channel,
then adding another virtual interface and making
that associate on another channel -- this will make
the beaconing to move channel but obviously without
the necessary IEs data update.
In order to improve this situation, first make the
configuration APIs (cfg80211 and nl80211) aware of
multi-channel operation -- we'll eventually need
that in the future anyway. There's one userland API
change and one API addition. The API change is that
now SET_WIPHY must be called with virtual interface
index rather than only wiphy index in order to take
effect for that interface -- luckily all current
users (hostapd) do that. For monitor interfaces, the
old setting is preserved, but monitors are always
slaved to other devices anyway so no guarantees.
The second userland API change is the introduction
of a per virtual interface SET_CHANNEL command, that
hostapd should use going forward to make it easier
to understand what's going on (it can automatically
detect a kernel with this command).
Other than mac80211, no existing cfg80211 drivers
are affected by this change because they only allow
a single virtual interface.
mac80211, however, now needs to be aware that the
channel settings are per interface now, and needs
to disallow (for now) real multi-channel operation,
which is another important part of this patch.
One of the immediate benefits is that you can now
start hostapd to operate on a hardware that already
has a connection on another virtual interface, as
long as you specify the same channel.
Note that two things are left unhandled (this is an
improvement -- not a complete fix):
* different HT/no-HT modes
currently you could start an HT AP and then
connect to a non-HT network on the same channel
which would configure the hardware for no HT;
that can be fixed fairly easily
* CSA
An AP we're connected to on a virtual interface
might indicate switching channels, and in that
case we would follow it, regardless of how many
other interfaces are operating; this requires
more effort to fix but is pretty rare after all
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2010-05-05 07:25:02 -06:00
|
|
|
result = rdev->ops->set_channel(&rdev->wiphy,
|
|
|
|
wdev ? wdev->netdev : NULL,
|
|
|
|
chan, channel_type);
|
2009-08-07 09:22:35 -06:00
|
|
|
if (result)
|
|
|
|
return result;
|
|
|
|
|
cfg80211/mac80211: better channel handling
Currently (all tested with hwsim) you can do stupid
things like setting up an AP on a certain channel,
then adding another virtual interface and making
that associate on another channel -- this will make
the beaconing to move channel but obviously without
the necessary IEs data update.
In order to improve this situation, first make the
configuration APIs (cfg80211 and nl80211) aware of
multi-channel operation -- we'll eventually need
that in the future anyway. There's one userland API
change and one API addition. The API change is that
now SET_WIPHY must be called with virtual interface
index rather than only wiphy index in order to take
effect for that interface -- luckily all current
users (hostapd) do that. For monitor interfaces, the
old setting is preserved, but monitors are always
slaved to other devices anyway so no guarantees.
The second userland API change is the introduction
of a per virtual interface SET_CHANNEL command, that
hostapd should use going forward to make it easier
to understand what's going on (it can automatically
detect a kernel with this command).
Other than mac80211, no existing cfg80211 drivers
are affected by this change because they only allow
a single virtual interface.
mac80211, however, now needs to be aware that the
channel settings are per interface now, and needs
to disallow (for now) real multi-channel operation,
which is another important part of this patch.
One of the immediate benefits is that you can now
start hostapd to operate on a hardware that already
has a connection on another virtual interface, as
long as you specify the same channel.
Note that two things are left unhandled (this is an
improvement -- not a complete fix):
* different HT/no-HT modes
currently you could start an HT AP and then
connect to a non-HT network on the same channel
which would configure the hardware for no HT;
that can be fixed fairly easily
* CSA
An AP we're connected to on a virtual interface
might indicate switching channels, and in that
case we would follow it, regardless of how many
other interfaces are operating; this requires
more effort to fix but is pretty rare after all
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
2010-05-05 07:25:02 -06:00
|
|
|
if (wdev)
|
|
|
|
wdev->channel = chan;
|
2009-08-07 09:22:35 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|