Skip to content

Commit f444de0

Browse files
jmberglinvjw
authored andcommitted
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>
1 parent ac8dd50 commit f444de0

16 files changed

Lines changed: 300 additions & 108 deletions

File tree

‎drivers/net/wireless/libertas/cfg.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ static const u32 cipher_suites[] = {
7878

7979

8080
static int lbs_cfg_set_channel(struct wiphy *wiphy,
81+
struct net_device *netdev,
8182
struct ieee80211_channel *chan,
8283
enum nl80211_channel_type channel_type)
8384
{

‎drivers/net/wireless/orinoco/cfg.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ static int orinoco_scan(struct wiphy *wiphy, struct net_device *dev,
159159
}
160160

161161
static int orinoco_set_channel(struct wiphy *wiphy,
162+
struct net_device *netdev,
162163
struct ieee80211_channel *chan,
163164
enum nl80211_channel_type channel_type)
164165
{

‎drivers/net/wireless/rndis_wlan.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ static int rndis_join_ibss(struct wiphy *wiphy, struct net_device *dev,
534534

535535
static int rndis_leave_ibss(struct wiphy *wiphy, struct net_device *dev);
536536

537-
static int rndis_set_channel(struct wiphy *wiphy,
537+
static int rndis_set_channel(struct wiphy *wiphy, struct net_device *dev,
538538
struct ieee80211_channel *chan, enum nl80211_channel_type channel_type);
539539

540540
static int rndis_add_key(struct wiphy *wiphy, struct net_device *netdev,
@@ -2290,7 +2290,7 @@ static int rndis_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
22902290
return deauthenticate(usbdev);
22912291
}
22922292

2293-
static int rndis_set_channel(struct wiphy *wiphy,
2293+
static int rndis_set_channel(struct wiphy *wiphy, struct net_device *netdev,
22942294
struct ieee80211_channel *chan, enum nl80211_channel_type channel_type)
22952295
{
22962296
struct rndis_wlan_private *priv = wiphy_priv(wiphy);

‎include/linux/nl80211.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
* %NL80211_ATTR_WIPHY_CHANNEL_TYPE, %NL80211_ATTR_WIPHY_RETRY_SHORT,
5353
* %NL80211_ATTR_WIPHY_RETRY_LONG, %NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
5454
* and/or %NL80211_ATTR_WIPHY_RTS_THRESHOLD.
55+
* However, for setting the channel, see %NL80211_CMD_SET_CHANNEL
56+
* instead, the support here is for backward compatibility only.
5557
* @NL80211_CMD_NEW_WIPHY: Newly created wiphy, response to get request
5658
* or rename notification. Has attributes %NL80211_ATTR_WIPHY and
5759
* %NL80211_ATTR_WIPHY_NAME.
@@ -329,6 +331,15 @@
329331
* @NL80211_CMD_NOTIFY_CQM: Connection quality monitor notification. This
330332
* command is used as an event to indicate the that a trigger level was
331333
* reached.
334+
* @NL80211_CMD_SET_CHANNEL: Set the channel (using %NL80211_ATTR_WIPHY_FREQ
335+
* and %NL80211_ATTR_WIPHY_CHANNEL_TYPE) the given interface (identifed
336+
* by %NL80211_ATTR_IFINDEX) shall operate on.
337+
* In case multiple channels are supported by the device, the mechanism
338+
* with which it switches channels is implementation-defined.
339+
* When a monitor interface is given, it can only switch channel while
340+
* no other interfaces are operating to avoid disturbing the operation
341+
* of any other interfaces, and other interfaces will again take
342+
* precedence when they are used.
332343
*
333344
* @NL80211_CMD_MAX: highest used command number
334345
* @__NL80211_CMD_AFTER_LAST: internal use
@@ -428,6 +439,8 @@ enum nl80211_commands {
428439
NL80211_CMD_SET_CQM,
429440
NL80211_CMD_NOTIFY_CQM,
430441

442+
NL80211_CMD_SET_CHANNEL,
443+
431444
/* add new commands above here */
432445

433446
/* used to define NL80211_CMD_MAX below */

‎include/net/cfg80211.h‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,11 @@ struct cfg80211_pmksa {
966966
*
967967
* @set_txq_params: Set TX queue parameters
968968
*
969-
* @set_channel: Set channel
969+
* @set_channel: Set channel for a given wireless interface. Some devices
970+
* may support multi-channel operation (by channel hopping) so cfg80211
971+
* doesn't verify much. Note, however, that the passed netdev may be
972+
* %NULL as well if the user requested changing the channel for the
973+
* device itself, or for a monitor interface.
970974
*
971975
* @scan: Request to do a scan. If returning zero, the scan request is given
972976
* the driver, and will be valid until passed to cfg80211_scan_done().
@@ -1095,7 +1099,7 @@ struct cfg80211_ops {
10951099
int (*set_txq_params)(struct wiphy *wiphy,
10961100
struct ieee80211_txq_params *params);
10971101

1098-
int (*set_channel)(struct wiphy *wiphy,
1102+
int (*set_channel)(struct wiphy *wiphy, struct net_device *dev,
10991103
struct ieee80211_channel *chan,
11001104
enum nl80211_channel_type channel_type);
11011105

@@ -1461,6 +1465,8 @@ struct cfg80211_cached_keys;
14611465
* @list: (private) Used to collect the interfaces
14621466
* @netdev: (private) Used to reference back to the netdev
14631467
* @current_bss: (private) Used by the internal configuration code
1468+
* @channel: (private) Used by the internal configuration code to track
1469+
* user-set AP, monitor and WDS channels for wireless extensions
14641470
* @bssid: (private) Used by the internal configuration code
14651471
* @ssid: (private) Used by the internal configuration code
14661472
* @ssid_len: (private) Used by the internal configuration code
@@ -1507,6 +1513,7 @@ struct wireless_dev {
15071513
struct cfg80211_internal_bss *authtry_bsses[MAX_AUTH_BSSES];
15081514
struct cfg80211_internal_bss *auth_bsses[MAX_AUTH_BSSES];
15091515
struct cfg80211_internal_bss *current_bss; /* associated / joined */
1516+
struct ieee80211_channel *channel;
15101517

15111518
bool ps;
15121519
int ps_timeout;

‎net/mac80211/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ mac80211-y := \
2323
key.o \
2424
util.o \
2525
wme.o \
26-
event.o
26+
event.o \
27+
chan.o
2728

2829
mac80211-$(CONFIG_MAC80211_LEDS) += led.o
2930
mac80211-$(CONFIG_MAC80211_DEBUGFS) += \

‎net/mac80211/cfg.c‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,11 +1161,24 @@ static int ieee80211_set_txq_params(struct wiphy *wiphy,
11611161
}
11621162

11631163
static int ieee80211_set_channel(struct wiphy *wiphy,
1164+
struct net_device *netdev,
11641165
struct ieee80211_channel *chan,
11651166
enum nl80211_channel_type channel_type)
11661167
{
11671168
struct ieee80211_local *local = wiphy_priv(wiphy);
11681169

1170+
switch (ieee80211_get_channel_mode(local, NULL)) {
1171+
case CHAN_MODE_HOPPING:
1172+
return -EBUSY;
1173+
case CHAN_MODE_FIXED:
1174+
if (local->oper_channel == chan &&
1175+
local->oper_channel_type == channel_type)
1176+
return 0;
1177+
return -EBUSY;
1178+
case CHAN_MODE_UNDEFINED:
1179+
break;
1180+
}
1181+
11691182
local->oper_channel = chan;
11701183
local->oper_channel_type = channel_type;
11711184

@@ -1213,6 +1226,20 @@ static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
12131226
static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
12141227
struct cfg80211_assoc_request *req)
12151228
{
1229+
struct ieee80211_local *local = wiphy_priv(wiphy);
1230+
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1231+
1232+
switch (ieee80211_get_channel_mode(local, sdata)) {
1233+
case CHAN_MODE_HOPPING:
1234+
return -EBUSY;
1235+
case CHAN_MODE_FIXED:
1236+
if (local->oper_channel == req->bss->channel)
1237+
break;
1238+
return -EBUSY;
1239+
case CHAN_MODE_UNDEFINED:
1240+
break;
1241+
}
1242+
12161243
return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
12171244
}
12181245

@@ -1235,8 +1262,22 @@ static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
12351262
static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
12361263
struct cfg80211_ibss_params *params)
12371264
{
1265+
struct ieee80211_local *local = wiphy_priv(wiphy);
12381266
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
12391267

1268+
switch (ieee80211_get_channel_mode(local, sdata)) {
1269+
case CHAN_MODE_HOPPING:
1270+
return -EBUSY;
1271+
case CHAN_MODE_FIXED:
1272+
if (!params->channel_fixed)
1273+
return -EBUSY;
1274+
if (local->oper_channel == params->channel)
1275+
break;
1276+
return -EBUSY;
1277+
case CHAN_MODE_UNDEFINED:
1278+
break;
1279+
}
1280+
12401281
return ieee80211_ibss_join(sdata, params);
12411282
}
12421283

‎net/mac80211/chan.c‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* mac80211 - channel management
3+
*/
4+
5+
#include "ieee80211_i.h"
6+
7+
enum ieee80211_chan_mode
8+
__ieee80211_get_channel_mode(struct ieee80211_local *local,
9+
struct ieee80211_sub_if_data *ignore)
10+
{
11+
struct ieee80211_sub_if_data *sdata;
12+
13+
WARN_ON(!mutex_is_locked(&local->iflist_mtx));
14+
15+
list_for_each_entry(sdata, &local->interfaces, list) {
16+
if (sdata == ignore)
17+
continue;
18+
19+
if (!ieee80211_sdata_running(sdata))
20+
continue;
21+
22+
if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
23+
continue;
24+
25+
if (sdata->vif.type == NL80211_IFTYPE_STATION &&
26+
!sdata->u.mgd.associated)
27+
continue;
28+
29+
if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
30+
if (!sdata->u.ibss.ssid_len)
31+
continue;
32+
if (!sdata->u.ibss.fixed_channel)
33+
return CHAN_MODE_HOPPING;
34+
}
35+
36+
if (sdata->vif.type == NL80211_IFTYPE_AP &&
37+
!sdata->u.ap.beacon)
38+
continue;
39+
40+
return CHAN_MODE_FIXED;
41+
}
42+
43+
return CHAN_MODE_UNDEFINED;
44+
}
45+
46+
enum ieee80211_chan_mode
47+
ieee80211_get_channel_mode(struct ieee80211_local *local,
48+
struct ieee80211_sub_if_data *ignore)
49+
{
50+
enum ieee80211_chan_mode mode;
51+
52+
mutex_lock(&local->iflist_mtx);
53+
mode = __ieee80211_get_channel_mode(local, ignore);
54+
mutex_unlock(&local->iflist_mtx);
55+
56+
return mode;
57+
}

‎net/mac80211/ieee80211_i.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,17 @@ int ieee80211_wk_remain_on_channel(struct ieee80211_sub_if_data *sdata,
12291229
int ieee80211_wk_cancel_remain_on_channel(
12301230
struct ieee80211_sub_if_data *sdata, u64 cookie);
12311231

1232+
/* channel management */
1233+
enum ieee80211_chan_mode {
1234+
CHAN_MODE_UNDEFINED,
1235+
CHAN_MODE_HOPPING,
1236+
CHAN_MODE_FIXED,
1237+
};
1238+
1239+
enum ieee80211_chan_mode
1240+
ieee80211_get_channel_mode(struct ieee80211_local *local,
1241+
struct ieee80211_sub_if_data *ignore);
1242+
12321243
#ifdef CONFIG_MAC80211_NOINLINE
12331244
#define debug_noinline noinline
12341245
#else

‎net/wireless/chan.c‎

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,6 @@
99
#include <net/cfg80211.h>
1010
#include "core.h"
1111

12-
struct ieee80211_channel *
13-
rdev_fixed_channel(struct cfg80211_registered_device *rdev,
14-
struct wireless_dev *for_wdev)
15-
{
16-
struct wireless_dev *wdev;
17-
struct ieee80211_channel *result = NULL;
18-
19-
WARN_ON(!mutex_is_locked(&rdev->devlist_mtx));
20-
21-
list_for_each_entry(wdev, &rdev->netdev_list, list) {
22-
if (wdev == for_wdev)
23-
continue;
24-
25-
/*
26-
* Lock manually to tell lockdep about allowed
27-
* nesting here if for_wdev->mtx is held already.
28-
* This is ok as it's all under the rdev devlist
29-
* mutex and as such can only be done once at any
30-
* given time.
31-
*/
32-
mutex_lock_nested(&wdev->mtx, SINGLE_DEPTH_NESTING);
33-
if (wdev->current_bss)
34-
result = wdev->current_bss->pub.channel;
35-
wdev_unlock(wdev);
36-
37-
if (result)
38-
break;
39-
}
40-
41-
return result;
42-
}
43-
4412
struct ieee80211_channel *
4513
rdev_freq_to_chan(struct cfg80211_registered_device *rdev,
4614
int freq, enum nl80211_channel_type channel_type)
@@ -75,15 +43,22 @@ rdev_freq_to_chan(struct cfg80211_registered_device *rdev,
7543
return chan;
7644
}
7745

78-
int rdev_set_freq(struct cfg80211_registered_device *rdev,
79-
struct wireless_dev *for_wdev,
80-
int freq, enum nl80211_channel_type channel_type)
46+
int cfg80211_set_freq(struct cfg80211_registered_device *rdev,
47+
struct wireless_dev *wdev, int freq,
48+
enum nl80211_channel_type channel_type)
8149
{
8250
struct ieee80211_channel *chan;
8351
int result;
8452

85-
if (rdev_fixed_channel(rdev, for_wdev))
86-
return -EBUSY;
53+
if (wdev->iftype == NL80211_IFTYPE_MONITOR)
54+
wdev = NULL;
55+
56+
if (wdev) {
57+
ASSERT_WDEV_LOCK(wdev);
58+
59+
if (!netif_running(wdev->netdev))
60+
return -ENETDOWN;
61+
}
8762

8863
if (!rdev->ops->set_channel)
8964
return -EOPNOTSUPP;
@@ -92,11 +67,14 @@ int rdev_set_freq(struct cfg80211_registered_device *rdev,
9267
if (!chan)
9368
return -EINVAL;
9469

95-
result = rdev->ops->set_channel(&rdev->wiphy, chan, channel_type);
70+
result = rdev->ops->set_channel(&rdev->wiphy,
71+
wdev ? wdev->netdev : NULL,
72+
chan, channel_type);
9673
if (result)
9774
return result;
9875

99-
rdev->channel = chan;
76+
if (wdev)
77+
wdev->channel = chan;
10078

10179
return 0;
10280
}

0 commit comments

Comments
 (0)