aboutsummaryrefslogtreecommitdiffstats
path: root/net/wireless
diff options
context:
space:
mode:
authorJohn W. Linville <linville@tuxdriver.com>2010-12-13 15:20:45 -0500
committerJohn W. Linville <linville@tuxdriver.com>2010-12-13 15:20:45 -0500
commit1d212aa96e1b63459486f729af9a3fa38768b801 (patch)
treee91e74db57a5bb7884b4681cdb788d405ec8f10f /net/wireless
parent8c4877a4128e7931077b024a891a4b284d8756a3 (diff)
parentb7613370db5ba66ad81e41cd3a5417fde4d5e03c (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-next-2.6 into for-davem
Diffstat (limited to 'net/wireless')
-rw-r--r--net/wireless/Makefile2
-rw-r--r--net/wireless/core.c15
-rw-r--r--net/wireless/core.h13
-rw-r--r--net/wireless/mesh.c140
-rw-r--r--net/wireless/nl80211.c212
-rw-r--r--net/wireless/util.c1
6 files changed, 337 insertions, 46 deletions
diff --git a/net/wireless/Makefile b/net/wireless/Makefile
index e77e508126fa..55a28ab21db9 100644
--- a/net/wireless/Makefile
+++ b/net/wireless/Makefile
@@ -10,7 +10,7 @@ obj-$(CONFIG_WEXT_SPY) += wext-spy.o
10obj-$(CONFIG_WEXT_PRIV) += wext-priv.o 10obj-$(CONFIG_WEXT_PRIV) += wext-priv.o
11 11
12cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o scan.o nl80211.o 12cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o scan.o nl80211.o
13cfg80211-y += mlme.o ibss.o sme.o chan.o ethtool.o 13cfg80211-y += mlme.o ibss.o sme.o chan.o ethtool.o mesh.o
14cfg80211-$(CONFIG_CFG80211_DEBUGFS) += debugfs.o 14cfg80211-$(CONFIG_CFG80211_DEBUGFS) += debugfs.o
15cfg80211-$(CONFIG_CFG80211_WEXT) += wext-compat.o wext-sme.o 15cfg80211-$(CONFIG_CFG80211_WEXT) += wext-compat.o wext-sme.o
16cfg80211-$(CONFIG_CFG80211_INTERNAL_REGDB) += regdb.o 16cfg80211-$(CONFIG_CFG80211_INTERNAL_REGDB) += regdb.o
diff --git a/net/wireless/core.c b/net/wireless/core.c
index 630bcf0a2f04..79772fcc37bc 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -332,6 +332,7 @@ struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv)
332 WARN_ON(ops->add_virtual_intf && !ops->del_virtual_intf); 332 WARN_ON(ops->add_virtual_intf && !ops->del_virtual_intf);
333 WARN_ON(ops->add_station && !ops->del_station); 333 WARN_ON(ops->add_station && !ops->del_station);
334 WARN_ON(ops->add_mpath && !ops->del_mpath); 334 WARN_ON(ops->add_mpath && !ops->del_mpath);
335 WARN_ON(ops->join_mesh && !ops->leave_mesh);
335 336
336 alloc_size = sizeof(*rdev) + sizeof_priv; 337 alloc_size = sizeof(*rdev) + sizeof_priv;
337 338
@@ -752,6 +753,9 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
752 cfg80211_mlme_down(rdev, dev); 753 cfg80211_mlme_down(rdev, dev);
753 wdev_unlock(wdev); 754 wdev_unlock(wdev);
754 break; 755 break;
756 case NL80211_IFTYPE_MESH_POINT:
757 cfg80211_leave_mesh(rdev, dev);
758 break;
755 default: 759 default:
756 break; 760 break;
757 } 761 }
@@ -775,20 +779,27 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
775 } 779 }
776 cfg80211_lock_rdev(rdev); 780 cfg80211_lock_rdev(rdev);
777 mutex_lock(&rdev->devlist_mtx); 781 mutex_lock(&rdev->devlist_mtx);
778#ifdef CONFIG_CFG80211_WEXT
779 wdev_lock(wdev); 782 wdev_lock(wdev);
780 switch (wdev->iftype) { 783 switch (wdev->iftype) {
784#ifdef CONFIG_CFG80211_WEXT
781 case NL80211_IFTYPE_ADHOC: 785 case NL80211_IFTYPE_ADHOC:
782 cfg80211_ibss_wext_join(rdev, wdev); 786 cfg80211_ibss_wext_join(rdev, wdev);
783 break; 787 break;
784 case NL80211_IFTYPE_STATION: 788 case NL80211_IFTYPE_STATION:
785 cfg80211_mgd_wext_connect(rdev, wdev); 789 cfg80211_mgd_wext_connect(rdev, wdev);
786 break; 790 break;
791#endif
792 case NL80211_IFTYPE_MESH_POINT:
793 /* backward compat code ... */
794 if (wdev->mesh_id_up_len)
795 __cfg80211_join_mesh(rdev, dev, wdev->ssid,
796 wdev->mesh_id_up_len,
797 &default_mesh_config);
798 break;
787 default: 799 default:
788 break; 800 break;
789 } 801 }
790 wdev_unlock(wdev); 802 wdev_unlock(wdev);
791#endif
792 rdev->opencount++; 803 rdev->opencount++;
793 mutex_unlock(&rdev->devlist_mtx); 804 mutex_unlock(&rdev->devlist_mtx);
794 cfg80211_unlock_rdev(rdev); 805 cfg80211_unlock_rdev(rdev);
diff --git a/net/wireless/core.h b/net/wireless/core.h
index ee80ad8dc655..743203bb61ac 100644
--- a/net/wireless/core.h
+++ b/net/wireless/core.h
@@ -285,6 +285,19 @@ void __cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid);
285int cfg80211_ibss_wext_join(struct cfg80211_registered_device *rdev, 285int cfg80211_ibss_wext_join(struct cfg80211_registered_device *rdev,
286 struct wireless_dev *wdev); 286 struct wireless_dev *wdev);
287 287
288/* mesh */
289extern const struct mesh_config default_mesh_config;
290int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
291 struct net_device *dev,
292 const u8 *mesh_id, u8 mesh_id_len,
293 const struct mesh_config *conf);
294int cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
295 struct net_device *dev,
296 const u8 *mesh_id, u8 mesh_id_len,
297 const struct mesh_config *conf);
298int cfg80211_leave_mesh(struct cfg80211_registered_device *rdev,
299 struct net_device *dev);
300
288/* MLME */ 301/* MLME */
289int __cfg80211_mlme_auth(struct cfg80211_registered_device *rdev, 302int __cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
290 struct net_device *dev, 303 struct net_device *dev,
diff --git a/net/wireless/mesh.c b/net/wireless/mesh.c
new file mode 100644
index 000000000000..e0b9747fe50a
--- /dev/null
+++ b/net/wireless/mesh.c
@@ -0,0 +1,140 @@
1#include <linux/ieee80211.h>
2#include <net/cfg80211.h>
3#include "core.h"
4
5/* Default values, timeouts in ms */
6#define MESH_TTL 31
7#define MESH_DEFAULT_ELEMENT_TTL 31
8#define MESH_MAX_RETR 3
9#define MESH_RET_T 100
10#define MESH_CONF_T 100
11#define MESH_HOLD_T 100
12
13#define MESH_PATH_TIMEOUT 5000
14
15/*
16 * Minimum interval between two consecutive PREQs originated by the same
17 * interface
18 */
19#define MESH_PREQ_MIN_INT 10
20#define MESH_DIAM_TRAVERSAL_TIME 50
21
22/*
23 * A path will be refreshed if it is used PATH_REFRESH_TIME milliseconds
24 * before timing out. This way it will remain ACTIVE and no data frames
25 * will be unnecessarily held in the pending queue.
26 */
27#define MESH_PATH_REFRESH_TIME 1000
28#define MESH_MIN_DISCOVERY_TIMEOUT (2 * MESH_DIAM_TRAVERSAL_TIME)
29
30/* Default maximum number of established plinks per interface */
31#define MESH_MAX_ESTAB_PLINKS 32
32
33#define MESH_MAX_PREQ_RETRIES 4
34
35
36const struct mesh_config default_mesh_config = {
37 .dot11MeshRetryTimeout = MESH_RET_T,
38 .dot11MeshConfirmTimeout = MESH_CONF_T,
39 .dot11MeshHoldingTimeout = MESH_HOLD_T,
40 .dot11MeshMaxRetries = MESH_MAX_RETR,
41 .dot11MeshTTL = MESH_TTL,
42 .element_ttl = MESH_DEFAULT_ELEMENT_TTL,
43 .auto_open_plinks = true,
44 .dot11MeshMaxPeerLinks = MESH_MAX_ESTAB_PLINKS,
45 .dot11MeshHWMPactivePathTimeout = MESH_PATH_TIMEOUT,
46 .dot11MeshHWMPpreqMinInterval = MESH_PREQ_MIN_INT,
47 .dot11MeshHWMPnetDiameterTraversalTime = MESH_DIAM_TRAVERSAL_TIME,
48 .dot11MeshHWMPmaxPREQretries = MESH_MAX_PREQ_RETRIES,
49 .path_refresh_time = MESH_PATH_REFRESH_TIME,
50 .min_discovery_timeout = MESH_MIN_DISCOVERY_TIMEOUT,
51};
52
53
54int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
55 struct net_device *dev,
56 const u8 *mesh_id, u8 mesh_id_len,
57 const struct mesh_config *conf)
58{
59 struct wireless_dev *wdev = dev->ieee80211_ptr;
60 struct mesh_setup setup = {
61 .mesh_id = mesh_id,
62 .mesh_id_len = mesh_id_len,
63 };
64 int err;
65
66 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != IEEE80211_MAX_MESH_ID_LEN);
67
68 ASSERT_WDEV_LOCK(wdev);
69
70 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
71 return -EOPNOTSUPP;
72
73 if (wdev->mesh_id_len)
74 return -EALREADY;
75
76 if (!mesh_id_len)
77 return -EINVAL;
78
79 if (!rdev->ops->join_mesh)
80 return -EOPNOTSUPP;
81
82 err = rdev->ops->join_mesh(&rdev->wiphy, dev, conf, &setup);
83 if (!err) {
84 memcpy(wdev->ssid, mesh_id, mesh_id_len);
85 wdev->mesh_id_len = mesh_id_len;
86 }
87
88 return err;
89}
90
91int cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
92 struct net_device *dev,
93 const u8 *mesh_id, u8 mesh_id_len,
94 const struct mesh_config *conf)
95{
96 struct wireless_dev *wdev = dev->ieee80211_ptr;
97 int err;
98
99 wdev_lock(wdev);
100 err = __cfg80211_join_mesh(rdev, dev, mesh_id, mesh_id_len, conf);
101 wdev_unlock(wdev);
102
103 return err;
104}
105
106static int __cfg80211_leave_mesh(struct cfg80211_registered_device *rdev,
107 struct net_device *dev)
108{
109 struct wireless_dev *wdev = dev->ieee80211_ptr;
110 int err;
111
112 ASSERT_WDEV_LOCK(wdev);
113
114 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
115 return -EOPNOTSUPP;
116
117 if (!rdev->ops->leave_mesh)
118 return -EOPNOTSUPP;
119
120 if (!wdev->mesh_id_len)
121 return -ENOTCONN;
122
123 err = rdev->ops->leave_mesh(&rdev->wiphy, dev);
124 if (!err)
125 wdev->mesh_id_len = 0;
126 return err;
127}
128
129int cfg80211_leave_mesh(struct cfg80211_registered_device *rdev,
130 struct net_device *dev)
131{
132 struct wireless_dev *wdev = dev->ieee80211_ptr;
133 int err;
134
135 wdev_lock(wdev);
136 err = __cfg80211_leave_mesh(rdev, dev);
137 wdev_unlock(wdev);
138
139 return err;
140}
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 960be4e650f0..c3f80e565365 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -121,6 +121,7 @@ static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
121 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, 121 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
122 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, 122 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
123 .len = NL80211_MAX_SUPP_RATES }, 123 .len = NL80211_MAX_SUPP_RATES },
124 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
124 125
125 [NL80211_ATTR_MESH_PARAMS] = { .type = NLA_NESTED }, 126 [NL80211_ATTR_MESH_PARAMS] = { .type = NLA_NESTED },
126 127
@@ -661,13 +662,14 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
661 CMD(add_beacon, NEW_BEACON); 662 CMD(add_beacon, NEW_BEACON);
662 CMD(add_station, NEW_STATION); 663 CMD(add_station, NEW_STATION);
663 CMD(add_mpath, NEW_MPATH); 664 CMD(add_mpath, NEW_MPATH);
664 CMD(set_mesh_params, SET_MESH_PARAMS); 665 CMD(update_mesh_params, SET_MESH_PARAMS);
665 CMD(change_bss, SET_BSS); 666 CMD(change_bss, SET_BSS);
666 CMD(auth, AUTHENTICATE); 667 CMD(auth, AUTHENTICATE);
667 CMD(assoc, ASSOCIATE); 668 CMD(assoc, ASSOCIATE);
668 CMD(deauth, DEAUTHENTICATE); 669 CMD(deauth, DEAUTHENTICATE);
669 CMD(disassoc, DISASSOCIATE); 670 CMD(disassoc, DISASSOCIATE);
670 CMD(join_ibss, JOIN_IBSS); 671 CMD(join_ibss, JOIN_IBSS);
672 CMD(join_mesh, JOIN_MESH);
671 CMD(set_pmksa, SET_PMKSA); 673 CMD(set_pmksa, SET_PMKSA);
672 CMD(del_pmksa, DEL_PMKSA); 674 CMD(del_pmksa, DEL_PMKSA);
673 CMD(flush_pmksa, FLUSH_PMKSA); 675 CMD(flush_pmksa, FLUSH_PMKSA);
@@ -1324,11 +1326,21 @@ static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
1324 } 1326 }
1325 1327
1326 if (info->attrs[NL80211_ATTR_MESH_ID]) { 1328 if (info->attrs[NL80211_ATTR_MESH_ID]) {
1329 struct wireless_dev *wdev = dev->ieee80211_ptr;
1330
1327 if (ntype != NL80211_IFTYPE_MESH_POINT) 1331 if (ntype != NL80211_IFTYPE_MESH_POINT)
1328 return -EINVAL; 1332 return -EINVAL;
1329 params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); 1333 if (netif_running(dev))
1330 params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); 1334 return -EBUSY;
1331 change = true; 1335
1336 wdev_lock(wdev);
1337 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1338 IEEE80211_MAX_MESH_ID_LEN);
1339 wdev->mesh_id_up_len =
1340 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1341 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1342 wdev->mesh_id_up_len);
1343 wdev_unlock(wdev);
1332 } 1344 }
1333 1345
1334 if (info->attrs[NL80211_ATTR_4ADDR]) { 1346 if (info->attrs[NL80211_ATTR_4ADDR]) {
@@ -1368,6 +1380,7 @@ static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1368{ 1380{
1369 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 1381 struct cfg80211_registered_device *rdev = info->user_ptr[0];
1370 struct vif_params params; 1382 struct vif_params params;
1383 struct net_device *dev;
1371 int err; 1384 int err;
1372 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; 1385 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
1373 u32 flags; 1386 u32 flags;
@@ -1387,12 +1400,6 @@ static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1387 !(rdev->wiphy.interface_modes & (1 << type))) 1400 !(rdev->wiphy.interface_modes & (1 << type)))
1388 return -EOPNOTSUPP; 1401 return -EOPNOTSUPP;
1389 1402
1390 if (type == NL80211_IFTYPE_MESH_POINT &&
1391 info->attrs[NL80211_ATTR_MESH_ID]) {
1392 params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
1393 params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1394 }
1395
1396 if (info->attrs[NL80211_ATTR_4ADDR]) { 1403 if (info->attrs[NL80211_ATTR_4ADDR]) {
1397 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); 1404 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
1398 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); 1405 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
@@ -1403,11 +1410,27 @@ static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
1403 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? 1410 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
1404 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, 1411 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
1405 &flags); 1412 &flags);
1406 err = rdev->ops->add_virtual_intf(&rdev->wiphy, 1413 dev = rdev->ops->add_virtual_intf(&rdev->wiphy,
1407 nla_data(info->attrs[NL80211_ATTR_IFNAME]), 1414 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
1408 type, err ? NULL : &flags, &params); 1415 type, err ? NULL : &flags, &params);
1416 if (IS_ERR(dev))
1417 return PTR_ERR(dev);
1409 1418
1410 return err; 1419 if (type == NL80211_IFTYPE_MESH_POINT &&
1420 info->attrs[NL80211_ATTR_MESH_ID]) {
1421 struct wireless_dev *wdev = dev->ieee80211_ptr;
1422
1423 wdev_lock(wdev);
1424 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
1425 IEEE80211_MAX_MESH_ID_LEN);
1426 wdev->mesh_id_up_len =
1427 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
1428 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
1429 wdev->mesh_id_up_len);
1430 wdev_unlock(wdev);
1431 }
1432
1433 return 0;
1411} 1434}
1412 1435
1413static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) 1436static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
@@ -1874,6 +1897,9 @@ static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
1874 if (sinfo->filled & STATION_INFO_SIGNAL) 1897 if (sinfo->filled & STATION_INFO_SIGNAL)
1875 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, 1898 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL,
1876 sinfo->signal); 1899 sinfo->signal);
1900 if (sinfo->filled & STATION_INFO_SIGNAL_AVG)
1901 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG,
1902 sinfo->signal_avg);
1877 if (sinfo->filled & STATION_INFO_TX_BITRATE) { 1903 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
1878 txrate = nla_nest_start(msg, NL80211_STA_INFO_TX_BITRATE); 1904 txrate = nla_nest_start(msg, NL80211_STA_INFO_TX_BITRATE);
1879 if (!txrate) 1905 if (!txrate)
@@ -2437,6 +2463,7 @@ static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
2437 params.use_short_preamble = -1; 2463 params.use_short_preamble = -1;
2438 params.use_short_slot_time = -1; 2464 params.use_short_slot_time = -1;
2439 params.ap_isolate = -1; 2465 params.ap_isolate = -1;
2466 params.ht_opmode = -1;
2440 2467
2441 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) 2468 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
2442 params.use_cts_prot = 2469 params.use_cts_prot =
@@ -2455,6 +2482,9 @@ static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
2455 } 2482 }
2456 if (info->attrs[NL80211_ATTR_AP_ISOLATE]) 2483 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
2457 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); 2484 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
2485 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
2486 params.ht_opmode =
2487 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
2458 2488
2459 if (!rdev->ops->change_bss) 2489 if (!rdev->ops->change_bss)
2460 return -EOPNOTSUPP; 2490 return -EOPNOTSUPP;
@@ -2540,21 +2570,32 @@ static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
2540} 2570}
2541 2571
2542static int nl80211_get_mesh_params(struct sk_buff *skb, 2572static int nl80211_get_mesh_params(struct sk_buff *skb,
2543 struct genl_info *info) 2573 struct genl_info *info)
2544{ 2574{
2545 struct cfg80211_registered_device *rdev = info->user_ptr[0]; 2575 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2546 struct mesh_config cur_params;
2547 int err;
2548 struct net_device *dev = info->user_ptr[1]; 2576 struct net_device *dev = info->user_ptr[1];
2577 struct wireless_dev *wdev = dev->ieee80211_ptr;
2578 struct mesh_config cur_params;
2579 int err = 0;
2549 void *hdr; 2580 void *hdr;
2550 struct nlattr *pinfoattr; 2581 struct nlattr *pinfoattr;
2551 struct sk_buff *msg; 2582 struct sk_buff *msg;
2552 2583
2584 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
2585 return -EOPNOTSUPP;
2586
2553 if (!rdev->ops->get_mesh_params) 2587 if (!rdev->ops->get_mesh_params)
2554 return -EOPNOTSUPP; 2588 return -EOPNOTSUPP;
2555 2589
2556 /* Get the mesh params */ 2590 wdev_lock(wdev);
2557 err = rdev->ops->get_mesh_params(&rdev->wiphy, dev, &cur_params); 2591 /* If not connected, get default parameters */
2592 if (!wdev->mesh_id_len)
2593 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
2594 else
2595 err = rdev->ops->get_mesh_params(&rdev->wiphy, dev,
2596 &cur_params);
2597 wdev_unlock(wdev);
2598
2558 if (err) 2599 if (err)
2559 return err; 2600 return err;
2560 2601
@@ -2582,6 +2623,8 @@ static int nl80211_get_mesh_params(struct sk_buff *skb,
2582 cur_params.dot11MeshMaxRetries); 2623 cur_params.dot11MeshMaxRetries);
2583 NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, 2624 NLA_PUT_U8(msg, NL80211_MESHCONF_TTL,
2584 cur_params.dot11MeshTTL); 2625 cur_params.dot11MeshTTL);
2626 NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL,
2627 cur_params.element_ttl);
2585 NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, 2628 NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
2586 cur_params.auto_open_plinks); 2629 cur_params.auto_open_plinks);
2587 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, 2630 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
@@ -2608,14 +2651,6 @@ static int nl80211_get_mesh_params(struct sk_buff *skb,
2608 return -ENOBUFS; 2651 return -ENOBUFS;
2609} 2652}
2610 2653
2611#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2612do {\
2613 if (table[attr_num]) {\
2614 cfg.param = nla_fn(table[attr_num]); \
2615 mask |= (1 << (attr_num - 1)); \
2616 } \
2617} while (0);\
2618
2619static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { 2654static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
2620 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, 2655 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
2621 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, 2656 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
@@ -2623,6 +2658,7 @@ static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_A
2623 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, 2658 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
2624 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, 2659 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
2625 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, 2660 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
2661 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
2626 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, 2662 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
2627 2663
2628 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, 2664 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
@@ -2633,31 +2669,34 @@ static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_A
2633 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, 2669 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
2634}; 2670};
2635 2671
2636static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info) 2672static int nl80211_parse_mesh_params(struct genl_info *info,
2673 struct mesh_config *cfg,
2674 u32 *mask_out)
2637{ 2675{
2638 u32 mask;
2639 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2640 struct net_device *dev = info->user_ptr[1];
2641 struct mesh_config cfg;
2642 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; 2676 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
2643 struct nlattr *parent_attr; 2677 u32 mask = 0;
2678
2679#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2680do {\
2681 if (table[attr_num]) {\
2682 cfg->param = nla_fn(table[attr_num]); \
2683 mask |= (1 << (attr_num - 1)); \
2684 } \
2685} while (0);\
2686
2644 2687
2645 parent_attr = info->attrs[NL80211_ATTR_MESH_PARAMS]; 2688 if (!info->attrs[NL80211_ATTR_MESH_PARAMS])
2646 if (!parent_attr)
2647 return -EINVAL; 2689 return -EINVAL;
2648 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, 2690 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
2649 parent_attr, nl80211_meshconf_params_policy)) 2691 info->attrs[NL80211_ATTR_MESH_PARAMS],
2692 nl80211_meshconf_params_policy))
2650 return -EINVAL; 2693 return -EINVAL;
2651 2694
2652 if (!rdev->ops->set_mesh_params)
2653 return -EOPNOTSUPP;
2654
2655 /* This makes sure that there aren't more than 32 mesh config 2695 /* This makes sure that there aren't more than 32 mesh config
2656 * parameters (otherwise our bitfield scheme would not work.) */ 2696 * parameters (otherwise our bitfield scheme would not work.) */
2657 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); 2697 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
2658 2698
2659 /* Fill in the params struct */ 2699 /* Fill in the params struct */
2660 mask = 0;
2661 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 2700 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
2662 mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); 2701 mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
2663 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 2702 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
@@ -2670,6 +2709,8 @@ static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info)
2670 mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); 2709 mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
2671 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 2710 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
2672 mask, NL80211_MESHCONF_TTL, nla_get_u8); 2711 mask, NL80211_MESHCONF_TTL, nla_get_u8);
2712 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl,
2713 mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
2673 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 2714 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
2674 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); 2715 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8);
2675 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 2716 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
@@ -2695,11 +2736,45 @@ static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info)
2695 NL80211_MESHCONF_HWMP_ROOTMODE, 2736 NL80211_MESHCONF_HWMP_ROOTMODE,
2696 nla_get_u8); 2737 nla_get_u8);
2697 2738
2698 /* Apply changes */ 2739 if (mask_out)
2699 return rdev->ops->set_mesh_params(&rdev->wiphy, dev, &cfg, mask); 2740 *mask_out = mask;
2700} 2741 return 0;
2701 2742
2702#undef FILL_IN_MESH_PARAM_IF_SET 2743#undef FILL_IN_MESH_PARAM_IF_SET
2744}
2745
2746static int nl80211_update_mesh_params(struct sk_buff *skb,
2747 struct genl_info *info)
2748{
2749 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2750 struct net_device *dev = info->user_ptr[1];
2751 struct wireless_dev *wdev = dev->ieee80211_ptr;
2752 struct mesh_config cfg;
2753 u32 mask;
2754 int err;
2755
2756 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
2757 return -EOPNOTSUPP;
2758
2759 if (!rdev->ops->update_mesh_params)
2760 return -EOPNOTSUPP;
2761
2762 err = nl80211_parse_mesh_params(info, &cfg, &mask);
2763 if (err)
2764 return err;
2765
2766 wdev_lock(wdev);
2767 if (!wdev->mesh_id_len)
2768 err = -ENOLINK;
2769
2770 if (!err)
2771 err = rdev->ops->update_mesh_params(&rdev->wiphy, dev,
2772 mask, &cfg);
2773
2774 wdev_unlock(wdev);
2775
2776 return err;
2777}
2703 2778
2704static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) 2779static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
2705{ 2780{
@@ -4482,6 +4557,41 @@ out:
4482 return err; 4557 return err;
4483} 4558}
4484 4559
4560static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
4561{
4562 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4563 struct net_device *dev = info->user_ptr[1];
4564 struct mesh_config cfg;
4565 int err;
4566
4567 /* start with default */
4568 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
4569
4570 if (info->attrs[NL80211_ATTR_MESH_PARAMS]) {
4571 /* and parse parameters if given */
4572 err = nl80211_parse_mesh_params(info, &cfg, NULL);
4573 if (err)
4574 return err;
4575 }
4576
4577 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
4578 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
4579 return -EINVAL;
4580
4581 return cfg80211_join_mesh(rdev, dev,
4582 nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
4583 nla_len(info->attrs[NL80211_ATTR_MESH_ID]),
4584 &cfg);
4585}
4586
4587static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
4588{
4589 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4590 struct net_device *dev = info->user_ptr[1];
4591
4592 return cfg80211_leave_mesh(rdev, dev);
4593}
4594
4485#define NL80211_FLAG_NEED_WIPHY 0x01 4595#define NL80211_FLAG_NEED_WIPHY 0x01
4486#define NL80211_FLAG_NEED_NETDEV 0x02 4596#define NL80211_FLAG_NEED_NETDEV 0x02
4487#define NL80211_FLAG_NEED_RTNL 0x04 4597#define NL80211_FLAG_NEED_RTNL 0x04
@@ -4746,10 +4856,10 @@ static struct genl_ops nl80211_ops[] = {
4746 }, 4856 },
4747 { 4857 {
4748 .cmd = NL80211_CMD_SET_MESH_PARAMS, 4858 .cmd = NL80211_CMD_SET_MESH_PARAMS,
4749 .doit = nl80211_set_mesh_params, 4859 .doit = nl80211_update_mesh_params,
4750 .policy = nl80211_policy, 4860 .policy = nl80211_policy,
4751 .flags = GENL_ADMIN_PERM, 4861 .flags = GENL_ADMIN_PERM,
4752 .internal_flags = NL80211_FLAG_NEED_NETDEV | 4862 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
4753 NL80211_FLAG_NEED_RTNL, 4863 NL80211_FLAG_NEED_RTNL,
4754 }, 4864 },
4755 { 4865 {
@@ -4964,6 +5074,22 @@ static struct genl_ops nl80211_ops[] = {
4964 .internal_flags = NL80211_FLAG_NEED_NETDEV | 5074 .internal_flags = NL80211_FLAG_NEED_NETDEV |
4965 NL80211_FLAG_NEED_RTNL, 5075 NL80211_FLAG_NEED_RTNL,
4966 }, 5076 },
5077 {
5078 .cmd = NL80211_CMD_JOIN_MESH,
5079 .doit = nl80211_join_mesh,
5080 .policy = nl80211_policy,
5081 .flags = GENL_ADMIN_PERM,
5082 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5083 NL80211_FLAG_NEED_RTNL,
5084 },
5085 {
5086 .cmd = NL80211_CMD_LEAVE_MESH,
5087 .doit = nl80211_leave_mesh,
5088 .policy = nl80211_policy,
5089 .flags = GENL_ADMIN_PERM,
5090 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
5091 NL80211_FLAG_NEED_RTNL,
5092 },
4967}; 5093};
4968 5094
4969static struct genl_multicast_group nl80211_mlme_mcgrp = { 5095static struct genl_multicast_group nl80211_mlme_mcgrp = {
diff --git a/net/wireless/util.c b/net/wireless/util.c
index fee020b15a4e..4de624ca4c63 100644
--- a/net/wireless/util.c
+++ b/net/wireless/util.c
@@ -792,6 +792,7 @@ int cfg80211_change_iface(struct cfg80211_registered_device *rdev,
792 792
793 if (ntype != otype) { 793 if (ntype != otype) {
794 dev->ieee80211_ptr->use_4addr = false; 794 dev->ieee80211_ptr->use_4addr = false;
795 dev->ieee80211_ptr->mesh_id_up_len = 0;
795 796
796 switch (otype) { 797 switch (otype) {
797 case NL80211_IFTYPE_ADHOC: 798 case NL80211_IFTYPE_ADHOC: