Skip to content

Commit cc1d280

Browse files
jmberg-intellinvjw
authored andcommitted
cfg80211: provide channel to join_mesh function
Just like the AP mode patch, instead of setting the channel and then joining the mesh network, provide the channel to join the network on to the join_mesh() function. Like in AP mode, you can also give the channel to the join-mesh nl80211 command now. Unlike AP mode, it picks a default channel if none was given. As libertas uses mesh mode interfaces but has no join_mesh callback and we can't simply break it, keep some compatibility code for that case and configure the channel directly for it. In the non-libertas case, where we store the channel until join, allow setting it while the interface is down. Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
1 parent 685d12a commit cc1d280

6 files changed

Lines changed: 148 additions & 15 deletions

File tree

‎include/net/cfg80211.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,8 @@ struct mesh_config {
831831

832832
/**
833833
* struct mesh_setup - 802.11s mesh setup configuration
834+
* @channel: the channel to start the mesh network on
835+
* @channel_type: the channel type to use
834836
* @mesh_id: the mesh ID
835837
* @mesh_id_len: length of the mesh ID, at least 1 and at most 32 bytes
836838
* @sync_method: which synchronization method to use
@@ -845,6 +847,8 @@ struct mesh_config {
845847
* These parameters are fixed when the mesh is created.
846848
*/
847849
struct mesh_setup {
850+
struct ieee80211_channel *channel;
851+
enum nl80211_channel_type channel_type;
848852
const u8 *mesh_id;
849853
u8 mesh_id_len;
850854
u8 sync_method;

‎net/mac80211/cfg.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,12 @@ static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
15981598
err = copy_mesh_setup(ifmsh, setup);
15991599
if (err)
16001600
return err;
1601+
1602+
err = ieee80211_set_channel(wiphy, dev, setup->channel,
1603+
setup->channel_type);
1604+
if (err)
1605+
return err;
1606+
16011607
ieee80211_start_mesh(sdata);
16021608

16031609
return 0;

‎net/wireless/core.h‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,17 @@ extern const struct mesh_config default_mesh_config;
303303
extern const struct mesh_setup default_mesh_setup;
304304
int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
305305
struct net_device *dev,
306-
const struct mesh_setup *setup,
306+
struct mesh_setup *setup,
307307
const struct mesh_config *conf);
308308
int cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
309309
struct net_device *dev,
310-
const struct mesh_setup *setup,
310+
struct mesh_setup *setup,
311311
const struct mesh_config *conf);
312312
int cfg80211_leave_mesh(struct cfg80211_registered_device *rdev,
313313
struct net_device *dev);
314+
int cfg80211_set_mesh_freq(struct cfg80211_registered_device *rdev,
315+
struct wireless_dev *wdev, int freq,
316+
enum nl80211_channel_type channel_type);
314317

315318
/* MLME */
316319
int __cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,

‎net/wireless/mesh.c‎

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ const struct mesh_config default_mesh_config = {
6565
};
6666

6767
const struct mesh_setup default_mesh_setup = {
68+
/* cfg80211_join_mesh() will pick a channel if needed */
69+
.channel = NULL,
70+
.channel_type = NL80211_CHAN_NO_HT,
6871
.sync_method = IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET,
6972
.path_sel_proto = IEEE80211_PATH_PROTOCOL_HWMP,
7073
.path_metric = IEEE80211_PATH_METRIC_AIRTIME,
@@ -75,7 +78,7 @@ const struct mesh_setup default_mesh_setup = {
7578

7679
int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
7780
struct net_device *dev,
78-
const struct mesh_setup *setup,
81+
struct mesh_setup *setup,
7982
const struct mesh_config *conf)
8083
{
8184
struct wireless_dev *wdev = dev->ieee80211_ptr;
@@ -101,6 +104,51 @@ int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
101104
if (!rdev->ops->join_mesh)
102105
return -EOPNOTSUPP;
103106

107+
if (!setup->channel) {
108+
/* if no channel explicitly given, use preset channel */
109+
setup->channel = wdev->preset_chan;
110+
setup->channel_type = wdev->preset_chantype;
111+
}
112+
113+
if (!setup->channel) {
114+
/* if we don't have that either, use the first usable channel */
115+
enum ieee80211_band band;
116+
117+
for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
118+
struct ieee80211_supported_band *sband;
119+
struct ieee80211_channel *chan;
120+
int i;
121+
122+
sband = rdev->wiphy.bands[band];
123+
if (!sband)
124+
continue;
125+
126+
for (i = 0; i < sband->n_channels; i++) {
127+
chan = &sband->channels[i];
128+
if (chan->flags & (IEEE80211_CHAN_NO_IBSS |
129+
IEEE80211_CHAN_PASSIVE_SCAN |
130+
IEEE80211_CHAN_DISABLED |
131+
IEEE80211_CHAN_RADAR))
132+
continue;
133+
setup->channel = chan;
134+
break;
135+
}
136+
137+
if (setup->channel)
138+
break;
139+
}
140+
141+
/* no usable channel ... */
142+
if (!setup->channel)
143+
return -EINVAL;
144+
145+
setup->channel_type = NL80211_CHAN_NO_HT;
146+
}
147+
148+
if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, setup->channel,
149+
setup->channel_type))
150+
return -EINVAL;
151+
104152
err = rdev->ops->join_mesh(&rdev->wiphy, dev, conf, setup);
105153
if (!err) {
106154
memcpy(wdev->ssid, setup->mesh_id, setup->mesh_id_len);
@@ -112,7 +160,7 @@ int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
112160

113161
int cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
114162
struct net_device *dev,
115-
const struct mesh_setup *setup,
163+
struct mesh_setup *setup,
116164
const struct mesh_config *conf)
117165
{
118166
struct wireless_dev *wdev = dev->ieee80211_ptr;
@@ -125,6 +173,45 @@ int cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
125173
return err;
126174
}
127175

176+
int cfg80211_set_mesh_freq(struct cfg80211_registered_device *rdev,
177+
struct wireless_dev *wdev, int freq,
178+
enum nl80211_channel_type channel_type)
179+
{
180+
struct ieee80211_channel *channel;
181+
182+
/*
183+
* Workaround for libertas (only!), it puts the interface
184+
* into mesh mode but doesn't implement join_mesh. Instead,
185+
* it is configured via sysfs and then joins the mesh when
186+
* you set the channel. Note that the libertas mesh isn't
187+
* compatible with 802.11 mesh.
188+
*/
189+
if (!rdev->ops->join_mesh) {
190+
int err;
191+
192+
if (!netif_running(wdev->netdev))
193+
return -ENETDOWN;
194+
wdev_lock(wdev);
195+
err = cfg80211_set_freq(rdev, wdev, freq, channel_type);
196+
wdev_unlock(wdev);
197+
198+
return err;
199+
}
200+
201+
if (wdev->mesh_id_len)
202+
return -EBUSY;
203+
204+
channel = rdev_freq_to_chan(rdev, freq, channel_type);
205+
if (!channel || !cfg80211_can_beacon_sec_chan(&rdev->wiphy,
206+
channel,
207+
channel_type)) {
208+
return -EINVAL;
209+
}
210+
wdev->preset_chan = channel;
211+
wdev->preset_chantype = channel_type;
212+
return 0;
213+
}
214+
128215
void cfg80211_notify_new_peer_candidate(struct net_device *dev,
129216
const u8 *macaddr, const u8* ie, u8 ie_len, gfp_t gfp)
130217
{

‎net/wireless/nl80211.c‎

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,8 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
921921
if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
922922
goto nla_put_failure;
923923
}
924-
if (dev->ops->set_channel || dev->ops->start_ap) {
924+
if (dev->ops->set_channel || dev->ops->start_ap ||
925+
dev->ops->join_mesh) {
925926
i++;
926927
if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
927928
goto nla_put_failure;
@@ -1166,17 +1167,19 @@ static int parse_txq_params(struct nlattr *tb[],
11661167
static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
11671168
{
11681169
/*
1169-
* You can only set the channel explicitly for AP and
1170-
* mesh type interfaces; all others have their channel
1171-
* managed via their respective "establish a connection"
1172-
* command (connect, join, ...)
1170+
* You can only set the channel explicitly for WDS interfaces,
1171+
* all others have their channel managed via their respective
1172+
* "establish a connection" command (connect, join, ...)
1173+
*
1174+
* For AP/GO and mesh mode, the channel can be set with the
1175+
* channel userspace API, but is only stored and passed to the
1176+
* low-level driver when the AP starts or the mesh is joined.
1177+
* This is for backward compatibility, userspace can also give
1178+
* the channel in the start-ap or join-mesh commands instead.
11731179
*
11741180
* Monitors are special as they are normally slaved to
11751181
* whatever else is going on, so they behave as though
11761182
* you tried setting the wiphy channel itself.
1177-
*
1178-
* For AP/GO modes, it's only for compatibility, you can
1179-
* also give the channel to the start-AP command.
11801183
*/
11811184
return !wdev ||
11821185
wdev->iftype == NL80211_IFTYPE_AP ||
@@ -1246,6 +1249,9 @@ static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
12461249
wdev->preset_chantype = channel_type;
12471250
result = 0;
12481251
break;
1252+
case NL80211_IFTYPE_MESH_POINT:
1253+
result = cfg80211_set_mesh_freq(rdev, wdev, freq, channel_type);
1254+
break;
12491255
default:
12501256
wdev_lock(wdev);
12511257
result = cfg80211_set_freq(rdev, wdev, freq, channel_type);
@@ -1335,8 +1341,7 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
13351341
result = 0;
13361342

13371343
mutex_lock(&rdev->mtx);
1338-
} else if (netif_running(netdev) &&
1339-
nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
1344+
} else if (nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
13401345
wdev = netdev->ieee80211_ptr;
13411346
else
13421347
wdev = NULL;
@@ -6080,6 +6085,24 @@ static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
60806085
return err;
60816086
}
60826087

6088+
if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6089+
enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
6090+
6091+
if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
6092+
!nl80211_valid_channel_type(info, &channel_type))
6093+
return -EINVAL;
6094+
6095+
setup.channel = rdev_freq_to_chan(rdev,
6096+
nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
6097+
channel_type);
6098+
if (!setup.channel)
6099+
return -EINVAL;
6100+
setup.channel_type = channel_type;
6101+
} else {
6102+
/* cfg80211_join_mesh() will sort it out */
6103+
setup.channel = NULL;
6104+
}
6105+
60836106
return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
60846107
}
60856108

‎net/wireless/wext-compat.c‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,6 @@ static int cfg80211_wext_siwfreq(struct net_device *dev,
796796
case NL80211_IFTYPE_ADHOC:
797797
return cfg80211_ibss_wext_siwfreq(dev, info, wextfreq, extra);
798798
case NL80211_IFTYPE_MONITOR:
799-
case NL80211_IFTYPE_MESH_POINT:
800799
freq = cfg80211_wext_freq(wdev->wiphy, wextfreq);
801800
if (freq < 0)
802801
return freq;
@@ -808,6 +807,17 @@ static int cfg80211_wext_siwfreq(struct net_device *dev,
808807
wdev_unlock(wdev);
809808
mutex_unlock(&rdev->devlist_mtx);
810809
return err;
810+
case NL80211_IFTYPE_MESH_POINT:
811+
freq = cfg80211_wext_freq(wdev->wiphy, wextfreq);
812+
if (freq < 0)
813+
return freq;
814+
if (freq == 0)
815+
return -EINVAL;
816+
mutex_lock(&rdev->devlist_mtx);
817+
err = cfg80211_set_mesh_freq(rdev, wdev, freq,
818+
NL80211_CHAN_NO_HT);
819+
mutex_unlock(&rdev->devlist_mtx);
820+
return err;
811821
default:
812822
return -EOPNOTSUPP;
813823
}

0 commit comments

Comments
 (0)