Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 2740f0c | 2014-09-03 15:24:58 +0300 | [diff] [blame] | 5 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 6 | * Copyright 2015-2016 Intel Deutschland GmbH |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/if.h> |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13 | #include <linux/list.h> |
| 14 | #include <linux/if_ether.h> |
| 15 | #include <linux/ieee80211.h> |
| 16 | #include <linux/nl80211.h> |
| 17 | #include <linux/rtnetlink.h> |
| 18 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 19 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 20 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 21 | #include <net/genetlink.h> |
| 22 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 23 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 24 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 25 | #include "core.h" |
| 26 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 27 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 28 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 29 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 30 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 31 | struct genl_info *info, |
| 32 | struct cfg80211_crypto_settings *settings, |
| 33 | int cipher_limit); |
| 34 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 35 | /* the netlink family */ |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 36 | static struct genl_family nl80211_fam; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 37 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 38 | /* multicast groups */ |
| 39 | enum nl80211_multicast_groups { |
| 40 | NL80211_MCGRP_CONFIG, |
| 41 | NL80211_MCGRP_SCAN, |
| 42 | NL80211_MCGRP_REGULATORY, |
| 43 | NL80211_MCGRP_MLME, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 44 | NL80211_MCGRP_VENDOR, |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 45 | NL80211_MCGRP_NAN, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 46 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
| 47 | }; |
| 48 | |
| 49 | static const struct genl_multicast_group nl80211_mcgrps[] = { |
Johannes Berg | 71b836e | 2014-12-23 17:17:38 +0100 | [diff] [blame] | 50 | [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, |
| 51 | [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, |
| 52 | [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, |
| 53 | [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, |
| 54 | [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 55 | [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN }, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 56 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 71b836e | 2014-12-23 17:17:38 +0100 | [diff] [blame] | 57 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 58 | #endif |
| 59 | }; |
| 60 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 61 | /* returns ERR_PTR values */ |
| 62 | static struct wireless_dev * |
| 63 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 64 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 65 | struct cfg80211_registered_device *rdev; |
| 66 | struct wireless_dev *result = NULL; |
| 67 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 68 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 69 | u64 wdev_id; |
| 70 | int wiphy_idx = -1; |
| 71 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 72 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 73 | ASSERT_RTNL(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 74 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 75 | if (!have_ifidx && !have_wdev_id) |
| 76 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 77 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 78 | if (have_ifidx) |
| 79 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 80 | if (have_wdev_id) { |
| 81 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 82 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 83 | } |
| 84 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 85 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 86 | struct wireless_dev *wdev; |
| 87 | |
| 88 | if (wiphy_net(&rdev->wiphy) != netns) |
| 89 | continue; |
| 90 | |
| 91 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 92 | continue; |
| 93 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 94 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 95 | if (have_ifidx && wdev->netdev && |
| 96 | wdev->netdev->ifindex == ifidx) { |
| 97 | result = wdev; |
| 98 | break; |
| 99 | } |
| 100 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 101 | result = wdev; |
| 102 | break; |
| 103 | } |
| 104 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 105 | |
| 106 | if (result) |
| 107 | break; |
| 108 | } |
| 109 | |
| 110 | if (result) |
| 111 | return result; |
| 112 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 113 | } |
| 114 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 115 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 116 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 117 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 118 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 119 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 120 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 121 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 122 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 123 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 124 | !attrs[NL80211_ATTR_IFINDEX] && |
| 125 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 126 | return ERR_PTR(-EINVAL); |
| 127 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 128 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 129 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 130 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 131 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 132 | if (attrs[NL80211_ATTR_WDEV]) { |
| 133 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 134 | struct wireless_dev *wdev; |
| 135 | bool found = false; |
| 136 | |
| 137 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 138 | if (tmp) { |
| 139 | /* make sure wdev exists */ |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 140 | list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 141 | if (wdev->identifier != (u32)wdev_id) |
| 142 | continue; |
| 143 | found = true; |
| 144 | break; |
| 145 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 146 | |
| 147 | if (!found) |
| 148 | tmp = NULL; |
| 149 | |
| 150 | if (rdev && tmp != rdev) |
| 151 | return ERR_PTR(-EINVAL); |
| 152 | rdev = tmp; |
| 153 | } |
| 154 | } |
| 155 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 156 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 157 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 158 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 159 | netdev = __dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 160 | if (netdev) { |
| 161 | if (netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 162 | tmp = wiphy_to_rdev( |
| 163 | netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 164 | else |
| 165 | tmp = NULL; |
| 166 | |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 167 | /* not wireless device -- return error */ |
| 168 | if (!tmp) |
| 169 | return ERR_PTR(-EINVAL); |
| 170 | |
| 171 | /* mismatch -- return error */ |
| 172 | if (rdev && tmp != rdev) |
| 173 | return ERR_PTR(-EINVAL); |
| 174 | |
| 175 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 176 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 177 | } |
| 178 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 179 | if (!rdev) |
| 180 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 181 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 182 | if (netns != wiphy_net(&rdev->wiphy)) |
| 183 | return ERR_PTR(-ENODEV); |
| 184 | |
| 185 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | /* |
| 189 | * This function returns a pointer to the driver |
| 190 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 191 | * |
| 192 | * The result of this can be a PTR_ERR and hence must |
| 193 | * be checked with IS_ERR() for errors. |
| 194 | */ |
| 195 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 196 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 197 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 198 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 199 | } |
| 200 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 201 | /* policy for the attributes */ |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 202 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 203 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 204 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 205 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 206 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 207 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 208 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 209 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 210 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 211 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 212 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 213 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 214 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 215 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 216 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 217 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 218 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 219 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 220 | |
| 221 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 222 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 223 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 224 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 225 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 226 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 227 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 228 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 229 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 230 | .len = WLAN_MAX_KEY_LEN }, |
| 231 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 232 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 233 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 234 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 235 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 236 | |
| 237 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 238 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 239 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 240 | .len = IEEE80211_MAX_DATA_LEN }, |
| 241 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 242 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 243 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 244 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 245 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 246 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 247 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 248 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 249 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 250 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 251 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 252 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 253 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 254 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 255 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 256 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 257 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 258 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 259 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 260 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 261 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 262 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 263 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 264 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 265 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 266 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 267 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 268 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 269 | |
| 270 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 271 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 272 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 273 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 274 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 275 | |
| 276 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 277 | .len = IEEE80211_MAX_SSID_LEN }, |
| 278 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 279 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 280 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 281 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 282 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 283 | [NL80211_ATTR_STA_FLAGS2] = { |
| 284 | .len = sizeof(struct nl80211_sta_flag_update), |
| 285 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 286 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 287 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 288 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 289 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 290 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 291 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 292 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 293 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 294 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 295 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 296 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 297 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 298 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 299 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 300 | .len = IEEE80211_MAX_DATA_LEN }, |
| 301 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 302 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 303 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 304 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 305 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 306 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 307 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 308 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 309 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 310 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 311 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 312 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 313 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 314 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 315 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 316 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 317 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 318 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 319 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 320 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 321 | .len = IEEE80211_MAX_DATA_LEN }, |
| 322 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 323 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 324 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 325 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 326 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 327 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 328 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 329 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 330 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 331 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 332 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 333 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 334 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 335 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 336 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 337 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 338 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 339 | .len = NL80211_HT_CAPABILITY_LEN |
| 340 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 341 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 342 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 343 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 344 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 345 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 346 | [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 347 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 348 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 349 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 350 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 351 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 352 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 353 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 354 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 355 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 356 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 357 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 358 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 359 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 360 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 361 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 362 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 363 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 364 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 365 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 366 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 367 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
| 368 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 369 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
| 370 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 371 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 372 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 373 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 374 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 375 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 376 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
| 377 | .len = IEEE80211_QOS_MAP_LEN_MAX }, |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 378 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
| 379 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 380 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 381 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 382 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 383 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 384 | [NL80211_ATTR_TSID] = { .type = NLA_U8 }, |
| 385 | [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 }, |
| 386 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 387 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 388 | [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN }, |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 389 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 390 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 391 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 392 | [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 393 | [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 394 | [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 395 | [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 }, |
Aviya Erenfeld | c6e6a0c | 2016-07-05 15:23:08 +0300 | [diff] [blame] | 396 | [NL80211_ATTR_MU_MIMO_GROUP_DATA] = { |
| 397 | .len = VHT_MUMIMO_GROUPS_DATA_LEN |
| 398 | }, |
| 399 | [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN }, |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 400 | [NL80211_ATTR_NAN_MASTER_PREF] = { .type = NLA_U8 }, |
| 401 | [NL80211_ATTR_NAN_DUAL] = { .type = NLA_U8 }, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 402 | [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED }, |
Jouni Malinen | 348bd45 | 2016-10-27 00:42:03 +0300 | [diff] [blame] | 403 | [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY, |
| 404 | .len = FILS_MAX_KEK_LEN }, |
| 405 | [NL80211_ATTR_FILS_NONCES] = { .len = 2 * FILS_NONCE_LEN }, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 406 | [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, }, |
Vamsi Krishna | 2fa436b | 2016-12-02 23:59:08 +0200 | [diff] [blame^] | 407 | [NL80211_ATTR_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 408 | }; |
| 409 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 410 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 411 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 412 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 413 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 414 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 415 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 416 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 417 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 418 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 419 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 420 | }; |
| 421 | |
| 422 | /* policy for the key default flags */ |
| 423 | static const struct nla_policy |
| 424 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 425 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 426 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 427 | }; |
| 428 | |
Johannes Berg | f83ace3 | 2016-10-17 08:04:07 +0200 | [diff] [blame] | 429 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 430 | /* policy for WoWLAN attributes */ |
| 431 | static const struct nla_policy |
| 432 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 433 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 434 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 435 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 436 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 437 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 438 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 439 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 440 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 441 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 442 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 443 | }; |
| 444 | |
| 445 | static const struct nla_policy |
| 446 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 447 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 448 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 449 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 450 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 451 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 452 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 453 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 454 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 455 | }, |
| 456 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 457 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 458 | }, |
| 459 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 460 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 461 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 462 | }; |
Johannes Berg | f83ace3 | 2016-10-17 08:04:07 +0200 | [diff] [blame] | 463 | #endif /* CONFIG_PM */ |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 464 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 465 | /* policy for coalesce rule attributes */ |
| 466 | static const struct nla_policy |
| 467 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 468 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 469 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 470 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 471 | }; |
| 472 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 473 | /* policy for GTK rekey offload attributes */ |
| 474 | static const struct nla_policy |
| 475 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 476 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 477 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 478 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 479 | }; |
| 480 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 481 | static const struct nla_policy |
| 482 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 483 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 484 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 485 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 486 | }; |
| 487 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 488 | static const struct nla_policy |
| 489 | nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { |
| 490 | [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, |
| 491 | [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, |
| 492 | }; |
| 493 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 494 | static const struct nla_policy |
| 495 | nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { |
| 496 | [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, |
| 497 | [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, |
| 498 | [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { |
| 499 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 500 | }, |
| 501 | }; |
| 502 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 503 | /* policy for NAN function attributes */ |
| 504 | static const struct nla_policy |
| 505 | nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { |
| 506 | [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 }, |
| 507 | [NL80211_NAN_FUNC_SERVICE_ID] = { .type = NLA_BINARY, |
| 508 | .len = NL80211_NAN_FUNC_SERVICE_ID_LEN }, |
| 509 | [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 }, |
| 510 | [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG }, |
| 511 | [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG }, |
| 512 | [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 }, |
| 513 | [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 }, |
| 514 | [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN }, |
| 515 | [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG }, |
| 516 | [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 }, |
| 517 | [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY, |
| 518 | .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN }, |
| 519 | [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED }, |
| 520 | [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 521 | [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 522 | [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 }, |
| 523 | [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 }, |
| 524 | }; |
| 525 | |
| 526 | /* policy for Service Response Filter attributes */ |
| 527 | static const struct nla_policy |
| 528 | nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = { |
| 529 | [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG }, |
| 530 | [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY, |
| 531 | .len = NL80211_NAN_FUNC_SRF_MAX_LEN }, |
| 532 | [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 }, |
| 533 | [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED }, |
| 534 | }; |
| 535 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 536 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 537 | struct netlink_callback *cb, |
| 538 | struct cfg80211_registered_device **rdev, |
| 539 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 540 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 541 | int err; |
| 542 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 543 | rtnl_lock(); |
| 544 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 545 | if (!cb->args[0]) { |
| 546 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 547 | genl_family_attrbuf(&nl80211_fam), |
| 548 | nl80211_fam.maxattr, nl80211_policy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 549 | if (err) |
| 550 | goto out_unlock; |
| 551 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 552 | *wdev = __cfg80211_wdev_from_attrs( |
| 553 | sock_net(skb->sk), |
| 554 | genl_family_attrbuf(&nl80211_fam)); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 555 | if (IS_ERR(*wdev)) { |
| 556 | err = PTR_ERR(*wdev); |
| 557 | goto out_unlock; |
| 558 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 559 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 560 | /* 0 is the first index - add 1 to parse only once */ |
| 561 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 562 | cb->args[1] = (*wdev)->identifier; |
| 563 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 564 | /* subtract the 1 again here */ |
| 565 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 566 | struct wireless_dev *tmp; |
| 567 | |
| 568 | if (!wiphy) { |
| 569 | err = -ENODEV; |
| 570 | goto out_unlock; |
| 571 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 572 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 573 | *wdev = NULL; |
| 574 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 575 | list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 576 | if (tmp->identifier == cb->args[1]) { |
| 577 | *wdev = tmp; |
| 578 | break; |
| 579 | } |
| 580 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 581 | |
| 582 | if (!*wdev) { |
| 583 | err = -ENODEV; |
| 584 | goto out_unlock; |
| 585 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 586 | } |
| 587 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 588 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 589 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 590 | rtnl_unlock(); |
| 591 | return err; |
| 592 | } |
| 593 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 594 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 595 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 596 | rtnl_unlock(); |
| 597 | } |
| 598 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 599 | /* IE validation */ |
| 600 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 601 | { |
| 602 | const u8 *pos; |
| 603 | int len; |
| 604 | |
| 605 | if (!attr) |
| 606 | return true; |
| 607 | |
| 608 | pos = nla_data(attr); |
| 609 | len = nla_len(attr); |
| 610 | |
| 611 | while (len) { |
| 612 | u8 elemlen; |
| 613 | |
| 614 | if (len < 2) |
| 615 | return false; |
| 616 | len -= 2; |
| 617 | |
| 618 | elemlen = pos[1]; |
| 619 | if (elemlen > len) |
| 620 | return false; |
| 621 | |
| 622 | len -= elemlen; |
| 623 | pos += 2 + elemlen; |
| 624 | } |
| 625 | |
| 626 | return true; |
| 627 | } |
| 628 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 629 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 630 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 631 | int flags, u8 cmd) |
| 632 | { |
| 633 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 634 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 635 | } |
| 636 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 637 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 638 | struct ieee80211_channel *chan, |
| 639 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 640 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 641 | /* Some channels must be completely excluded from the |
| 642 | * list to protect old user-space tools from breaking |
| 643 | */ |
| 644 | if (!large && chan->flags & |
| 645 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 646 | return 0; |
| 647 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 648 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 649 | chan->center_freq)) |
| 650 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 651 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 652 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 653 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 654 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 655 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 656 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 657 | goto nla_put_failure; |
| 658 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 659 | goto nla_put_failure; |
| 660 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 661 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 662 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 663 | goto nla_put_failure; |
| 664 | if (large) { |
| 665 | u32 time; |
| 666 | |
| 667 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 668 | |
| 669 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 670 | chan->dfs_state)) |
| 671 | goto nla_put_failure; |
| 672 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 673 | time)) |
| 674 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 675 | if (nla_put_u32(msg, |
| 676 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 677 | chan->dfs_cac_ms)) |
| 678 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 679 | } |
| 680 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 681 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 682 | if (large) { |
| 683 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 684 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 685 | goto nla_put_failure; |
| 686 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 687 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 688 | goto nla_put_failure; |
| 689 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 690 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 691 | goto nla_put_failure; |
| 692 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 693 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 694 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 695 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 696 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 697 | goto nla_put_failure; |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 698 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
| 699 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 700 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 701 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 702 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 703 | goto nla_put_failure; |
| 704 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 705 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 706 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 707 | } |
| 708 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 709 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 710 | DBM_TO_MBM(chan->max_power))) |
| 711 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 712 | |
| 713 | return 0; |
| 714 | |
| 715 | nla_put_failure: |
| 716 | return -ENOBUFS; |
| 717 | } |
| 718 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 719 | /* netlink command implementations */ |
| 720 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 721 | struct key_parse { |
| 722 | struct key_params p; |
| 723 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 724 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 725 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 726 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 727 | }; |
| 728 | |
| 729 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 730 | { |
| 731 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 732 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 733 | nl80211_key_policy); |
| 734 | if (err) |
| 735 | return err; |
| 736 | |
| 737 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 738 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 739 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 740 | if (k->def) { |
| 741 | k->def_uni = true; |
| 742 | k->def_multi = true; |
| 743 | } |
| 744 | if (k->defmgmt) |
| 745 | k->def_multi = true; |
| 746 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 747 | if (tb[NL80211_KEY_IDX]) |
| 748 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 749 | |
| 750 | if (tb[NL80211_KEY_DATA]) { |
| 751 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 752 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 753 | } |
| 754 | |
| 755 | if (tb[NL80211_KEY_SEQ]) { |
| 756 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 757 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 758 | } |
| 759 | |
| 760 | if (tb[NL80211_KEY_CIPHER]) |
| 761 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 762 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 763 | if (tb[NL80211_KEY_TYPE]) { |
| 764 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 765 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 766 | return -EINVAL; |
| 767 | } |
| 768 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 769 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 770 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 771 | |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 772 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 773 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 774 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 775 | if (err) |
| 776 | return err; |
| 777 | |
| 778 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 779 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 780 | } |
| 781 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 782 | return 0; |
| 783 | } |
| 784 | |
| 785 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 786 | { |
| 787 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 788 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 789 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 790 | } |
| 791 | |
| 792 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 793 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 794 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 795 | } |
| 796 | |
| 797 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 798 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 799 | |
| 800 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 801 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 802 | |
| 803 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 804 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 805 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 806 | if (k->def) { |
| 807 | k->def_uni = true; |
| 808 | k->def_multi = true; |
| 809 | } |
| 810 | if (k->defmgmt) |
| 811 | k->def_multi = true; |
| 812 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 813 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 814 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 815 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 816 | return -EINVAL; |
| 817 | } |
| 818 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 819 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 820 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 821 | int err = nla_parse_nested( |
| 822 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 823 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 824 | nl80211_key_default_policy); |
| 825 | if (err) |
| 826 | return err; |
| 827 | |
| 828 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 829 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 830 | } |
| 831 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 832 | return 0; |
| 833 | } |
| 834 | |
| 835 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 836 | { |
| 837 | int err; |
| 838 | |
| 839 | memset(k, 0, sizeof(*k)); |
| 840 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 841 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 842 | |
| 843 | if (info->attrs[NL80211_ATTR_KEY]) |
| 844 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 845 | else |
| 846 | err = nl80211_parse_key_old(info, k); |
| 847 | |
| 848 | if (err) |
| 849 | return err; |
| 850 | |
| 851 | if (k->def && k->defmgmt) |
| 852 | return -EINVAL; |
| 853 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 854 | if (k->defmgmt) { |
| 855 | if (k->def_uni || !k->def_multi) |
| 856 | return -EINVAL; |
| 857 | } |
| 858 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 859 | if (k->idx != -1) { |
| 860 | if (k->defmgmt) { |
| 861 | if (k->idx < 4 || k->idx > 5) |
| 862 | return -EINVAL; |
| 863 | } else if (k->def) { |
| 864 | if (k->idx < 0 || k->idx > 3) |
| 865 | return -EINVAL; |
| 866 | } else { |
| 867 | if (k->idx < 0 || k->idx > 5) |
| 868 | return -EINVAL; |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | return 0; |
| 873 | } |
| 874 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 875 | static struct cfg80211_cached_keys * |
| 876 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 877 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 878 | { |
| 879 | struct key_parse parse; |
| 880 | struct nlattr *key; |
| 881 | struct cfg80211_cached_keys *result; |
| 882 | int rem, err, def = 0; |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 883 | bool have_key = false; |
| 884 | |
| 885 | nla_for_each_nested(key, keys, rem) { |
| 886 | have_key = true; |
| 887 | break; |
| 888 | } |
| 889 | |
| 890 | if (!have_key) |
| 891 | return NULL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 892 | |
| 893 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 894 | if (!result) |
| 895 | return ERR_PTR(-ENOMEM); |
| 896 | |
| 897 | result->def = -1; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 898 | |
| 899 | nla_for_each_nested(key, keys, rem) { |
| 900 | memset(&parse, 0, sizeof(parse)); |
| 901 | parse.idx = -1; |
| 902 | |
| 903 | err = nl80211_parse_key_new(key, &parse); |
| 904 | if (err) |
| 905 | goto error; |
| 906 | err = -EINVAL; |
| 907 | if (!parse.p.key) |
| 908 | goto error; |
Johannes Berg | 42ee231 | 2016-09-13 15:51:03 +0200 | [diff] [blame] | 909 | if (parse.idx < 0 || parse.idx > 3) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 910 | goto error; |
| 911 | if (parse.def) { |
| 912 | if (def) |
| 913 | goto error; |
| 914 | def = 1; |
| 915 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 916 | if (!parse.def_uni || !parse.def_multi) |
| 917 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 918 | } else if (parse.defmgmt) |
| 919 | goto error; |
| 920 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 921 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 922 | if (err) |
| 923 | goto error; |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 924 | if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && |
| 925 | parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { |
| 926 | err = -EINVAL; |
| 927 | goto error; |
| 928 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 929 | result->params[parse.idx].cipher = parse.p.cipher; |
| 930 | result->params[parse.idx].key_len = parse.p.key_len; |
| 931 | result->params[parse.idx].key = result->data[parse.idx]; |
| 932 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 933 | |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 934 | /* must be WEP key if we got here */ |
| 935 | if (no_ht) |
| 936 | *no_ht = true; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 937 | } |
| 938 | |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 939 | if (result->def < 0) { |
| 940 | err = -EINVAL; |
| 941 | goto error; |
| 942 | } |
| 943 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 944 | return result; |
| 945 | error: |
| 946 | kfree(result); |
| 947 | return ERR_PTR(err); |
| 948 | } |
| 949 | |
| 950 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 951 | { |
| 952 | ASSERT_WDEV_LOCK(wdev); |
| 953 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 954 | switch (wdev->iftype) { |
| 955 | case NL80211_IFTYPE_AP: |
| 956 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 957 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 958 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 959 | break; |
| 960 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 961 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 962 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 963 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 964 | return -ENOLINK; |
| 965 | break; |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 966 | case NL80211_IFTYPE_UNSPECIFIED: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 967 | case NL80211_IFTYPE_OCB: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 968 | case NL80211_IFTYPE_MONITOR: |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 969 | case NL80211_IFTYPE_NAN: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 970 | case NL80211_IFTYPE_P2P_DEVICE: |
| 971 | case NL80211_IFTYPE_WDS: |
| 972 | case NUM_NL80211_IFTYPES: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 973 | return -EINVAL; |
| 974 | } |
| 975 | |
| 976 | return 0; |
| 977 | } |
| 978 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 979 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 980 | struct nlattr *tb) |
| 981 | { |
| 982 | struct ieee80211_channel *chan; |
| 983 | |
| 984 | if (tb == NULL) |
| 985 | return NULL; |
| 986 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 987 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 988 | return NULL; |
| 989 | return chan; |
| 990 | } |
| 991 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 992 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 993 | { |
| 994 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 995 | int i; |
| 996 | |
| 997 | if (!nl_modes) |
| 998 | goto nla_put_failure; |
| 999 | |
| 1000 | i = 0; |
| 1001 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1002 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 1003 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1004 | ifmodes >>= 1; |
| 1005 | i++; |
| 1006 | } |
| 1007 | |
| 1008 | nla_nest_end(msg, nl_modes); |
| 1009 | return 0; |
| 1010 | |
| 1011 | nla_put_failure: |
| 1012 | return -ENOBUFS; |
| 1013 | } |
| 1014 | |
| 1015 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1016 | struct sk_buff *msg, |
| 1017 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1018 | { |
| 1019 | struct nlattr *nl_combis; |
| 1020 | int i, j; |
| 1021 | |
| 1022 | nl_combis = nla_nest_start(msg, |
| 1023 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 1024 | if (!nl_combis) |
| 1025 | goto nla_put_failure; |
| 1026 | |
| 1027 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 1028 | const struct ieee80211_iface_combination *c; |
| 1029 | struct nlattr *nl_combi, *nl_limits; |
| 1030 | |
| 1031 | c = &wiphy->iface_combinations[i]; |
| 1032 | |
| 1033 | nl_combi = nla_nest_start(msg, i + 1); |
| 1034 | if (!nl_combi) |
| 1035 | goto nla_put_failure; |
| 1036 | |
| 1037 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 1038 | if (!nl_limits) |
| 1039 | goto nla_put_failure; |
| 1040 | |
| 1041 | for (j = 0; j < c->n_limits; j++) { |
| 1042 | struct nlattr *nl_limit; |
| 1043 | |
| 1044 | nl_limit = nla_nest_start(msg, j + 1); |
| 1045 | if (!nl_limit) |
| 1046 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1047 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 1048 | c->limits[j].max)) |
| 1049 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1050 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 1051 | c->limits[j].types)) |
| 1052 | goto nla_put_failure; |
| 1053 | nla_nest_end(msg, nl_limit); |
| 1054 | } |
| 1055 | |
| 1056 | nla_nest_end(msg, nl_limits); |
| 1057 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1058 | if (c->beacon_int_infra_match && |
| 1059 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 1060 | goto nla_put_failure; |
| 1061 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 1062 | c->num_different_channels) || |
| 1063 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 1064 | c->max_interfaces)) |
| 1065 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1066 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 1067 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 1068 | c->radar_detect_widths) || |
| 1069 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 1070 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1071 | goto nla_put_failure; |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 1072 | if (c->beacon_int_min_gcd && |
| 1073 | nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD, |
| 1074 | c->beacon_int_min_gcd)) |
| 1075 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1076 | |
| 1077 | nla_nest_end(msg, nl_combi); |
| 1078 | } |
| 1079 | |
| 1080 | nla_nest_end(msg, nl_combis); |
| 1081 | |
| 1082 | return 0; |
| 1083 | nla_put_failure: |
| 1084 | return -ENOBUFS; |
| 1085 | } |
| 1086 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1087 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1088 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 1089 | struct sk_buff *msg) |
| 1090 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1091 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1092 | struct nlattr *nl_tcp; |
| 1093 | |
| 1094 | if (!tcp) |
| 1095 | return 0; |
| 1096 | |
| 1097 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 1098 | if (!nl_tcp) |
| 1099 | return -ENOBUFS; |
| 1100 | |
| 1101 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1102 | tcp->data_payload_max)) |
| 1103 | return -ENOBUFS; |
| 1104 | |
| 1105 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1106 | tcp->data_payload_max)) |
| 1107 | return -ENOBUFS; |
| 1108 | |
| 1109 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1110 | return -ENOBUFS; |
| 1111 | |
| 1112 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1113 | sizeof(*tcp->tok), tcp->tok)) |
| 1114 | return -ENOBUFS; |
| 1115 | |
| 1116 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1117 | tcp->data_interval_max)) |
| 1118 | return -ENOBUFS; |
| 1119 | |
| 1120 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1121 | tcp->wake_payload_max)) |
| 1122 | return -ENOBUFS; |
| 1123 | |
| 1124 | nla_nest_end(msg, nl_tcp); |
| 1125 | return 0; |
| 1126 | } |
| 1127 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1128 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1129 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1130 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1131 | { |
| 1132 | struct nlattr *nl_wowlan; |
| 1133 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1134 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1135 | return 0; |
| 1136 | |
| 1137 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1138 | if (!nl_wowlan) |
| 1139 | return -ENOBUFS; |
| 1140 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1141 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1142 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1143 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1144 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1145 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1146 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1147 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1148 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1149 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1150 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1151 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1152 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1153 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1154 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1155 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1156 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1157 | return -ENOBUFS; |
| 1158 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1159 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1160 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1161 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1162 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1163 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1164 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1165 | }; |
| 1166 | |
| 1167 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1168 | sizeof(pat), &pat)) |
| 1169 | return -ENOBUFS; |
| 1170 | } |
| 1171 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 1172 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
| 1173 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, |
| 1174 | rdev->wiphy.wowlan->max_nd_match_sets)) |
| 1175 | return -ENOBUFS; |
| 1176 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1177 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1178 | return -ENOBUFS; |
| 1179 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1180 | nla_nest_end(msg, nl_wowlan); |
| 1181 | |
| 1182 | return 0; |
| 1183 | } |
| 1184 | #endif |
| 1185 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1186 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1187 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1188 | { |
| 1189 | struct nl80211_coalesce_rule_support rule; |
| 1190 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1191 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1192 | return 0; |
| 1193 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1194 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1195 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1196 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1197 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1198 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1199 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1200 | |
| 1201 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1202 | return -ENOBUFS; |
| 1203 | |
| 1204 | return 0; |
| 1205 | } |
| 1206 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1207 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1208 | struct ieee80211_supported_band *sband) |
| 1209 | { |
| 1210 | struct nlattr *nl_rates, *nl_rate; |
| 1211 | struct ieee80211_rate *rate; |
| 1212 | int i; |
| 1213 | |
| 1214 | /* add HT info */ |
| 1215 | if (sband->ht_cap.ht_supported && |
| 1216 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1217 | sizeof(sband->ht_cap.mcs), |
| 1218 | &sband->ht_cap.mcs) || |
| 1219 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1220 | sband->ht_cap.cap) || |
| 1221 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1222 | sband->ht_cap.ampdu_factor) || |
| 1223 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1224 | sband->ht_cap.ampdu_density))) |
| 1225 | return -ENOBUFS; |
| 1226 | |
| 1227 | /* add VHT info */ |
| 1228 | if (sband->vht_cap.vht_supported && |
| 1229 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1230 | sizeof(sband->vht_cap.vht_mcs), |
| 1231 | &sband->vht_cap.vht_mcs) || |
| 1232 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1233 | sband->vht_cap.cap))) |
| 1234 | return -ENOBUFS; |
| 1235 | |
| 1236 | /* add bitrates */ |
| 1237 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1238 | if (!nl_rates) |
| 1239 | return -ENOBUFS; |
| 1240 | |
| 1241 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1242 | nl_rate = nla_nest_start(msg, i); |
| 1243 | if (!nl_rate) |
| 1244 | return -ENOBUFS; |
| 1245 | |
| 1246 | rate = &sband->bitrates[i]; |
| 1247 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1248 | rate->bitrate)) |
| 1249 | return -ENOBUFS; |
| 1250 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1251 | nla_put_flag(msg, |
| 1252 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1253 | return -ENOBUFS; |
| 1254 | |
| 1255 | nla_nest_end(msg, nl_rate); |
| 1256 | } |
| 1257 | |
| 1258 | nla_nest_end(msg, nl_rates); |
| 1259 | |
| 1260 | return 0; |
| 1261 | } |
| 1262 | |
| 1263 | static int |
| 1264 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1265 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1266 | { |
| 1267 | u16 stypes; |
| 1268 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1269 | enum nl80211_iftype ift; |
| 1270 | int i; |
| 1271 | |
| 1272 | if (!mgmt_stypes) |
| 1273 | return 0; |
| 1274 | |
| 1275 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1276 | if (!nl_ifs) |
| 1277 | return -ENOBUFS; |
| 1278 | |
| 1279 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1280 | nl_ftypes = nla_nest_start(msg, ift); |
| 1281 | if (!nl_ftypes) |
| 1282 | return -ENOBUFS; |
| 1283 | i = 0; |
| 1284 | stypes = mgmt_stypes[ift].tx; |
| 1285 | while (stypes) { |
| 1286 | if ((stypes & 1) && |
| 1287 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1288 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1289 | return -ENOBUFS; |
| 1290 | stypes >>= 1; |
| 1291 | i++; |
| 1292 | } |
| 1293 | nla_nest_end(msg, nl_ftypes); |
| 1294 | } |
| 1295 | |
| 1296 | nla_nest_end(msg, nl_ifs); |
| 1297 | |
| 1298 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1299 | if (!nl_ifs) |
| 1300 | return -ENOBUFS; |
| 1301 | |
| 1302 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1303 | nl_ftypes = nla_nest_start(msg, ift); |
| 1304 | if (!nl_ftypes) |
| 1305 | return -ENOBUFS; |
| 1306 | i = 0; |
| 1307 | stypes = mgmt_stypes[ift].rx; |
| 1308 | while (stypes) { |
| 1309 | if ((stypes & 1) && |
| 1310 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1311 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1312 | return -ENOBUFS; |
| 1313 | stypes >>= 1; |
| 1314 | i++; |
| 1315 | } |
| 1316 | nla_nest_end(msg, nl_ftypes); |
| 1317 | } |
| 1318 | nla_nest_end(msg, nl_ifs); |
| 1319 | |
| 1320 | return 0; |
| 1321 | } |
| 1322 | |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1323 | #define CMD(op, n) \ |
| 1324 | do { \ |
| 1325 | if (rdev->ops->op) { \ |
| 1326 | i++; \ |
| 1327 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1328 | goto nla_put_failure; \ |
| 1329 | } \ |
| 1330 | } while (0) |
| 1331 | |
| 1332 | static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev, |
| 1333 | struct sk_buff *msg) |
| 1334 | { |
| 1335 | int i = 0; |
| 1336 | |
| 1337 | /* |
| 1338 | * do *NOT* add anything into this function, new things need to be |
| 1339 | * advertised only to new versions of userspace that can deal with |
| 1340 | * the split (and they can't possibly care about new features... |
| 1341 | */ |
| 1342 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1343 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1344 | CMD(add_key, NEW_KEY); |
| 1345 | CMD(start_ap, START_AP); |
| 1346 | CMD(add_station, NEW_STATION); |
| 1347 | CMD(add_mpath, NEW_MPATH); |
| 1348 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1349 | CMD(change_bss, SET_BSS); |
| 1350 | CMD(auth, AUTHENTICATE); |
| 1351 | CMD(assoc, ASSOCIATE); |
| 1352 | CMD(deauth, DEAUTHENTICATE); |
| 1353 | CMD(disassoc, DISASSOCIATE); |
| 1354 | CMD(join_ibss, JOIN_IBSS); |
| 1355 | CMD(join_mesh, JOIN_MESH); |
| 1356 | CMD(set_pmksa, SET_PMKSA); |
| 1357 | CMD(del_pmksa, DEL_PMKSA); |
| 1358 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1359 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1360 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1361 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1362 | CMD(mgmt_tx, FRAME); |
| 1363 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1364 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1365 | i++; |
| 1366 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1367 | goto nla_put_failure; |
| 1368 | } |
| 1369 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1370 | rdev->ops->join_mesh) { |
| 1371 | i++; |
| 1372 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1373 | goto nla_put_failure; |
| 1374 | } |
| 1375 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1376 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1377 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1378 | CMD(tdls_oper, TDLS_OPER); |
| 1379 | } |
| 1380 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1381 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1382 | CMD(probe_client, PROBE_CLIENT); |
| 1383 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1384 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1385 | i++; |
| 1386 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1387 | goto nla_put_failure; |
| 1388 | } |
| 1389 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1390 | CMD(set_mcast_rate, SET_MCAST_RATE); |
| 1391 | #ifdef CONFIG_NL80211_TESTMODE |
| 1392 | CMD(testmode_cmd, TESTMODE); |
| 1393 | #endif |
| 1394 | |
| 1395 | if (rdev->ops->connect || rdev->ops->auth) { |
| 1396 | i++; |
| 1397 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
| 1398 | goto nla_put_failure; |
| 1399 | } |
| 1400 | |
| 1401 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
| 1402 | i++; |
| 1403 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1404 | goto nla_put_failure; |
| 1405 | } |
| 1406 | |
| 1407 | return i; |
| 1408 | nla_put_failure: |
| 1409 | return -ENOBUFS; |
| 1410 | } |
| 1411 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1412 | struct nl80211_dump_wiphy_state { |
| 1413 | s64 filter_wiphy; |
| 1414 | long start; |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 1415 | long split_start, band_start, chan_start, capa_start; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1416 | bool split; |
| 1417 | }; |
| 1418 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1419 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1420 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1421 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1422 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1423 | { |
| 1424 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1425 | struct nlattr *nl_bands, *nl_band; |
| 1426 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1427 | struct nlattr *nl_cmds; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1428 | enum nl80211_band band; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1429 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1430 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1431 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1432 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1433 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1434 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1435 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1436 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1437 | return -ENOBUFS; |
| 1438 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1439 | if (WARN_ON(!state)) |
| 1440 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1441 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1442 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1443 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1444 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1445 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1446 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1447 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1448 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1449 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 1450 | goto finish; |
| 1451 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1452 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1453 | case 0: |
| 1454 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1455 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1456 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1457 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1458 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1459 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1460 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1461 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1462 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1463 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1464 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1465 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1466 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1467 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1468 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1469 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1470 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1471 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1472 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 1473 | rdev->wiphy.max_match_sets) || |
| 1474 | nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, |
| 1475 | rdev->wiphy.max_sched_scan_plans) || |
| 1476 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, |
| 1477 | rdev->wiphy.max_sched_scan_plan_interval) || |
| 1478 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, |
| 1479 | rdev->wiphy.max_sched_scan_plan_iterations)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1480 | goto nla_put_failure; |
| 1481 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1482 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1483 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1484 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1485 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1486 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1487 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1488 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1489 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1490 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1491 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1492 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1493 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1494 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1495 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1496 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1497 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1498 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1499 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1500 | state->split_start++; |
| 1501 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1502 | break; |
| 1503 | case 1: |
| 1504 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1505 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 1506 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1507 | goto nla_put_failure; |
| 1508 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1509 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1510 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1511 | goto nla_put_failure; |
| 1512 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1513 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1514 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1515 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1516 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1517 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1518 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1519 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1520 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1521 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1522 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1523 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1524 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1525 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1526 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1527 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1528 | if ((rdev->wiphy.available_antennas_tx || |
| 1529 | rdev->wiphy.available_antennas_rx) && |
| 1530 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1531 | u32 tx_ant = 0, rx_ant = 0; |
| 1532 | int res; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 1533 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1534 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1535 | if (!res) { |
| 1536 | if (nla_put_u32(msg, |
| 1537 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1538 | tx_ant) || |
| 1539 | nla_put_u32(msg, |
| 1540 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1541 | rx_ant)) |
| 1542 | goto nla_put_failure; |
| 1543 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1544 | } |
| 1545 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1546 | state->split_start++; |
| 1547 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1548 | break; |
| 1549 | case 2: |
| 1550 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1551 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1552 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1553 | state->split_start++; |
| 1554 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1555 | break; |
| 1556 | case 3: |
| 1557 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1558 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1559 | goto nla_put_failure; |
| 1560 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1561 | for (band = state->band_start; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1562 | band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1563 | struct ieee80211_supported_band *sband; |
| 1564 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1565 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1566 | |
| 1567 | if (!sband) |
| 1568 | continue; |
| 1569 | |
| 1570 | nl_band = nla_nest_start(msg, band); |
| 1571 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1572 | goto nla_put_failure; |
| 1573 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1574 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1575 | case 0: |
| 1576 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1577 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1578 | state->chan_start++; |
| 1579 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1580 | break; |
| 1581 | default: |
| 1582 | /* add frequencies */ |
| 1583 | nl_freqs = nla_nest_start( |
| 1584 | msg, NL80211_BAND_ATTR_FREQS); |
| 1585 | if (!nl_freqs) |
| 1586 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1587 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1588 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1589 | i < sband->n_channels; |
| 1590 | i++) { |
| 1591 | nl_freq = nla_nest_start(msg, i); |
| 1592 | if (!nl_freq) |
| 1593 | goto nla_put_failure; |
| 1594 | |
| 1595 | chan = &sband->channels[i]; |
| 1596 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1597 | if (nl80211_msg_put_channel( |
| 1598 | msg, chan, |
| 1599 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1600 | goto nla_put_failure; |
| 1601 | |
| 1602 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1603 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1604 | break; |
| 1605 | } |
| 1606 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1607 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1608 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1609 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1610 | nla_nest_end(msg, nl_freqs); |
| 1611 | } |
| 1612 | |
| 1613 | nla_nest_end(msg, nl_band); |
| 1614 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1615 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1616 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1617 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1618 | band--; |
| 1619 | break; |
| 1620 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1621 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1622 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1623 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1624 | if (band < NUM_NL80211_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1625 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1626 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1627 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1628 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1629 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1630 | if (state->band_start == 0 && state->chan_start == 0) |
| 1631 | state->split_start++; |
| 1632 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1633 | break; |
| 1634 | case 4: |
| 1635 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1636 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1637 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1638 | |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1639 | i = nl80211_add_commands_unsplit(rdev, msg); |
| 1640 | if (i < 0) |
| 1641 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1642 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1643 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1644 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1645 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1646 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1647 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 1648 | if (rdev->wiphy.features & |
| 1649 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 1650 | CMD(add_tx_ts, ADD_TX_TS); |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 1651 | CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST); |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 1652 | CMD(update_connect_params, UPDATE_CONNECT_PARAMS); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1653 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1654 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1655 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1656 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1657 | state->split_start++; |
| 1658 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1659 | break; |
| 1660 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1661 | if (rdev->ops->remain_on_channel && |
| 1662 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1663 | nla_put_u32(msg, |
| 1664 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1665 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1666 | goto nla_put_failure; |
| 1667 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1668 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1669 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1670 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1671 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1672 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1673 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1674 | state->split_start++; |
| 1675 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1676 | break; |
| 1677 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1678 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1679 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1680 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1681 | state->split_start++; |
| 1682 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1683 | break; |
| 1684 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1685 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1686 | #endif |
| 1687 | case 7: |
| 1688 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1689 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1690 | goto nla_put_failure; |
| 1691 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1692 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1693 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1694 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1695 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1696 | state->split_start++; |
| 1697 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1698 | break; |
| 1699 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1700 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1701 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1702 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1703 | goto nla_put_failure; |
| 1704 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1705 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1706 | /* |
| 1707 | * We can only add the per-channel limit information if the |
| 1708 | * dump is split, otherwise it makes it too big. Therefore |
| 1709 | * only advertise it in that case. |
| 1710 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1711 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1712 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1713 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1714 | goto nla_put_failure; |
| 1715 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1716 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1717 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1718 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 1719 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1720 | goto nla_put_failure; |
| 1721 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1722 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1723 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1724 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1725 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1726 | goto nla_put_failure; |
| 1727 | |
| 1728 | /* |
| 1729 | * Any information below this point is only available to |
| 1730 | * applications that can deal with it being split. This |
| 1731 | * helps ensure that newly added capabilities don't break |
| 1732 | * older tools by overrunning their buffers. |
| 1733 | * |
| 1734 | * We still increment split_start so that in the split |
| 1735 | * case we'll continue with more data in the next round, |
| 1736 | * but break unconditionally so unsplit data stops here. |
| 1737 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1738 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1739 | break; |
| 1740 | case 9: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1741 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1742 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1743 | rdev->wiphy.extended_capabilities_len, |
| 1744 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1745 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1746 | rdev->wiphy.extended_capabilities_len, |
| 1747 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1748 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1749 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1750 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1751 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1752 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 1753 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1754 | goto nla_put_failure; |
| 1755 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1756 | state->split_start++; |
| 1757 | break; |
| 1758 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1759 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1760 | goto nla_put_failure; |
| 1761 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1762 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1763 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1764 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1765 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1766 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1767 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1768 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1769 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1770 | goto nla_put_failure; |
| 1771 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1772 | state->split_start++; |
| 1773 | break; |
| 1774 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1775 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1776 | const struct nl80211_vendor_cmd_info *info; |
| 1777 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1778 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1779 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1780 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1781 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1782 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1783 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 1784 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1785 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1786 | goto nla_put_failure; |
| 1787 | } |
| 1788 | nla_nest_end(msg, nested); |
| 1789 | } |
| 1790 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1791 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1792 | const struct nl80211_vendor_cmd_info *info; |
| 1793 | struct nlattr *nested; |
| 1794 | |
| 1795 | nested = nla_nest_start(msg, |
| 1796 | NL80211_ATTR_VENDOR_EVENTS); |
| 1797 | if (!nested) |
| 1798 | goto nla_put_failure; |
| 1799 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1800 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 1801 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1802 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1803 | goto nla_put_failure; |
| 1804 | } |
| 1805 | nla_nest_end(msg, nested); |
| 1806 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 1807 | state->split_start++; |
| 1808 | break; |
| 1809 | case 12: |
| 1810 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 1811 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 1812 | rdev->wiphy.max_num_csa_counters)) |
| 1813 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1814 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 1815 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 1816 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 1817 | goto nla_put_failure; |
| 1818 | |
Gautam Kumar Shukla | d75bb06 | 2014-12-23 16:55:19 +0100 | [diff] [blame] | 1819 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
| 1820 | sizeof(rdev->wiphy.ext_features), |
| 1821 | rdev->wiphy.ext_features)) |
| 1822 | goto nla_put_failure; |
| 1823 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 1824 | if (rdev->wiphy.bss_select_support) { |
| 1825 | struct nlattr *nested; |
| 1826 | u32 bss_select_support = rdev->wiphy.bss_select_support; |
| 1827 | |
| 1828 | nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT); |
| 1829 | if (!nested) |
| 1830 | goto nla_put_failure; |
| 1831 | |
| 1832 | i = 0; |
| 1833 | while (bss_select_support) { |
| 1834 | if ((bss_select_support & 1) && |
| 1835 | nla_put_flag(msg, i)) |
| 1836 | goto nla_put_failure; |
| 1837 | i++; |
| 1838 | bss_select_support >>= 1; |
| 1839 | } |
| 1840 | nla_nest_end(msg, nested); |
| 1841 | } |
| 1842 | |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 1843 | state->split_start++; |
| 1844 | break; |
| 1845 | case 13: |
| 1846 | if (rdev->wiphy.num_iftype_ext_capab && |
| 1847 | rdev->wiphy.iftype_ext_capab) { |
| 1848 | struct nlattr *nested_ext_capab, *nested; |
| 1849 | |
| 1850 | nested = nla_nest_start(msg, |
| 1851 | NL80211_ATTR_IFTYPE_EXT_CAPA); |
| 1852 | if (!nested) |
| 1853 | goto nla_put_failure; |
| 1854 | |
| 1855 | for (i = state->capa_start; |
| 1856 | i < rdev->wiphy.num_iftype_ext_capab; i++) { |
| 1857 | const struct wiphy_iftype_ext_capab *capab; |
| 1858 | |
| 1859 | capab = &rdev->wiphy.iftype_ext_capab[i]; |
| 1860 | |
| 1861 | nested_ext_capab = nla_nest_start(msg, i); |
| 1862 | if (!nested_ext_capab || |
| 1863 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, |
| 1864 | capab->iftype) || |
| 1865 | nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1866 | capab->extended_capabilities_len, |
| 1867 | capab->extended_capabilities) || |
| 1868 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1869 | capab->extended_capabilities_len, |
| 1870 | capab->extended_capabilities_mask)) |
| 1871 | goto nla_put_failure; |
| 1872 | |
| 1873 | nla_nest_end(msg, nested_ext_capab); |
| 1874 | if (state->split) |
| 1875 | break; |
| 1876 | } |
| 1877 | nla_nest_end(msg, nested); |
| 1878 | if (i < rdev->wiphy.num_iftype_ext_capab) { |
| 1879 | state->capa_start = i + 1; |
| 1880 | break; |
| 1881 | } |
| 1882 | } |
| 1883 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1884 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1885 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1886 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1887 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1888 | finish: |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 1889 | genlmsg_end(msg, hdr); |
| 1890 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1891 | |
| 1892 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1893 | genlmsg_cancel(msg, hdr); |
| 1894 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1895 | } |
| 1896 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1897 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1898 | struct netlink_callback *cb, |
| 1899 | struct nl80211_dump_wiphy_state *state) |
| 1900 | { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 1901 | struct nlattr **tb = genl_family_attrbuf(&nl80211_fam); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1902 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1903 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1904 | /* ignore parse errors for backward compatibility */ |
| 1905 | if (ret) |
| 1906 | return 0; |
| 1907 | |
| 1908 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1909 | if (tb[NL80211_ATTR_WIPHY]) |
| 1910 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1911 | if (tb[NL80211_ATTR_WDEV]) |
| 1912 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1913 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1914 | struct net_device *netdev; |
| 1915 | struct cfg80211_registered_device *rdev; |
| 1916 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1917 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1918 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1919 | if (!netdev) |
| 1920 | return -ENODEV; |
| 1921 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1922 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1923 | netdev->ieee80211_ptr->wiphy); |
| 1924 | state->filter_wiphy = rdev->wiphy_idx; |
| 1925 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1926 | } |
| 1927 | |
| 1928 | return 0; |
| 1929 | } |
| 1930 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1931 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1932 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1933 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1934 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1935 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1936 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1937 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1938 | if (!state) { |
| 1939 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1940 | if (!state) { |
| 1941 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1942 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1943 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1944 | state->filter_wiphy = -1; |
| 1945 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1946 | if (ret) { |
| 1947 | kfree(state); |
| 1948 | rtnl_unlock(); |
| 1949 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1950 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1951 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1952 | } |
| 1953 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1954 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1955 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1956 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1957 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1958 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1959 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1960 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1961 | continue; |
| 1962 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1963 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1964 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 1965 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1966 | NETLINK_CB(cb->skb).portid, |
| 1967 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1968 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1969 | if (ret < 0) { |
| 1970 | /* |
| 1971 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1972 | * or EMSGSIZE returned), this SKB is still |
| 1973 | * empty (so it's not too big because another |
| 1974 | * wiphy dataset is already in the skb) and |
| 1975 | * we've not tried to adjust the dump allocation |
| 1976 | * yet ... then adjust the alloc size to be |
| 1977 | * bigger, and return 1 but with the empty skb. |
| 1978 | * This results in an empty message being RX'ed |
| 1979 | * in userspace, but that is ignored. |
| 1980 | * |
| 1981 | * We can then retry with the larger buffer. |
| 1982 | */ |
| 1983 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1984 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1985 | cb->min_dump_alloc < 4096) { |
| 1986 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1987 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1988 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1989 | return 1; |
| 1990 | } |
| 1991 | idx--; |
| 1992 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1993 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1994 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1995 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1996 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1997 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1998 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1999 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2000 | |
| 2001 | return skb->len; |
| 2002 | } |
| 2003 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2004 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 2005 | { |
| 2006 | kfree((void *)cb->args[0]); |
| 2007 | return 0; |
| 2008 | } |
| 2009 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2010 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2011 | { |
| 2012 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2013 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2014 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2015 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2016 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2017 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2018 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2019 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2020 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 2021 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2022 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2023 | nlmsg_free(msg); |
| 2024 | return -ENOBUFS; |
| 2025 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2026 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2027 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2028 | } |
| 2029 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2030 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 2031 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 2032 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 2033 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 2034 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 2035 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 2036 | }; |
| 2037 | |
| 2038 | static int parse_txq_params(struct nlattr *tb[], |
| 2039 | struct ieee80211_txq_params *txq_params) |
| 2040 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2041 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2042 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 2043 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 2044 | return -EINVAL; |
| 2045 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2046 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2047 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 2048 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 2049 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 2050 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 2051 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2052 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 2053 | return -EINVAL; |
| 2054 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2055 | return 0; |
| 2056 | } |
| 2057 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2058 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 2059 | { |
| 2060 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2061 | * You can only set the channel explicitly for WDS interfaces, |
| 2062 | * all others have their channel managed via their respective |
| 2063 | * "establish a connection" command (connect, join, ...) |
| 2064 | * |
| 2065 | * For AP/GO and mesh mode, the channel can be set with the |
| 2066 | * channel userspace API, but is only stored and passed to the |
| 2067 | * low-level driver when the AP starts or the mesh is joined. |
| 2068 | * This is for backward compatibility, userspace can also give |
| 2069 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2070 | * |
| 2071 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2072 | * whatever else is going on, so they have their own special |
| 2073 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2074 | */ |
| 2075 | return !wdev || |
| 2076 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2077 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2078 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 2079 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2080 | } |
| 2081 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2082 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 2083 | struct genl_info *info, |
| 2084 | struct cfg80211_chan_def *chandef) |
| 2085 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 2086 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2087 | |
| 2088 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 2089 | return -EINVAL; |
| 2090 | |
| 2091 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 2092 | |
| 2093 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2094 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 2095 | chandef->center_freq1 = control_freq; |
| 2096 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2097 | |
| 2098 | /* Primary channel not allowed */ |
| 2099 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 2100 | return -EINVAL; |
| 2101 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2102 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 2103 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2104 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2105 | chantype = nla_get_u32( |
| 2106 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 2107 | |
| 2108 | switch (chantype) { |
| 2109 | case NL80211_CHAN_NO_HT: |
| 2110 | case NL80211_CHAN_HT20: |
| 2111 | case NL80211_CHAN_HT40PLUS: |
| 2112 | case NL80211_CHAN_HT40MINUS: |
| 2113 | cfg80211_chandef_create(chandef, chandef->chan, |
| 2114 | chantype); |
| 2115 | break; |
| 2116 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2117 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2118 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2119 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 2120 | chandef->width = |
| 2121 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 2122 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 2123 | chandef->center_freq1 = |
| 2124 | nla_get_u32( |
| 2125 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 2126 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 2127 | chandef->center_freq2 = |
| 2128 | nla_get_u32( |
| 2129 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 2130 | } |
| 2131 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2132 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2133 | return -EINVAL; |
| 2134 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2135 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 2136 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2137 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2138 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2139 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 2140 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 2141 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 2142 | return -EINVAL; |
| 2143 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2144 | return 0; |
| 2145 | } |
| 2146 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2147 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2148 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2149 | struct genl_info *info) |
| 2150 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2151 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2152 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2153 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2154 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2155 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2156 | if (dev) |
| 2157 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2158 | if (!nl80211_can_set_dev_channel(wdev)) |
| 2159 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2160 | if (wdev) |
| 2161 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2162 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2163 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 2164 | if (result) |
| 2165 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2166 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2167 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2168 | case NL80211_IFTYPE_AP: |
| 2169 | case NL80211_IFTYPE_P2P_GO: |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 2170 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 2171 | iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2172 | result = -EINVAL; |
| 2173 | break; |
| 2174 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2175 | if (wdev->beacon_interval) { |
| 2176 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 2177 | !(rdev->wiphy.features & |
| 2178 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 2179 | result = -EBUSY; |
| 2180 | break; |
| 2181 | } |
| 2182 | |
| 2183 | /* Only allow dynamic channel width changes */ |
| 2184 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 2185 | result = -EBUSY; |
| 2186 | break; |
| 2187 | } |
| 2188 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 2189 | if (result) |
| 2190 | break; |
| 2191 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2192 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2193 | result = 0; |
| 2194 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2195 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2196 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2197 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2198 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2199 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2200 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2201 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2202 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2203 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2204 | |
| 2205 | return result; |
| 2206 | } |
| 2207 | |
| 2208 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 2209 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2210 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2211 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2212 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2213 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2214 | } |
| 2215 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2216 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 2217 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2218 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2219 | struct net_device *dev = info->user_ptr[1]; |
| 2220 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2221 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2222 | |
| 2223 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2224 | return -EINVAL; |
| 2225 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2226 | if (netif_running(dev)) |
| 2227 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2228 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2229 | if (!rdev->ops->set_wds_peer) |
| 2230 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2231 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2232 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 2233 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2234 | |
| 2235 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2236 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2237 | } |
| 2238 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2239 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2240 | { |
| 2241 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2242 | struct net_device *netdev = NULL; |
| 2243 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2244 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2245 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2246 | u32 changed; |
| 2247 | u8 retry_short = 0, retry_long = 0; |
| 2248 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2249 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2250 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2251 | ASSERT_RTNL(); |
| 2252 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2253 | /* |
| 2254 | * Try to find the wiphy and netdev. Normally this |
| 2255 | * function shouldn't need the netdev, but this is |
| 2256 | * done for backward compatibility -- previously |
| 2257 | * setting the channel was done per wiphy, but now |
| 2258 | * it is per netdev. Previous userland like hostapd |
| 2259 | * also passed a netdev to set_wiphy, so that it is |
| 2260 | * possible to let that go to the right netdev! |
| 2261 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2262 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2263 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2264 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2265 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2266 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2267 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2268 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2269 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2270 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2271 | } |
| 2272 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2273 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2274 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2275 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2276 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2277 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2278 | wdev = NULL; |
| 2279 | netdev = NULL; |
| 2280 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2281 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2282 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2283 | |
| 2284 | /* |
| 2285 | * end workaround code, by now the rdev is available |
| 2286 | * and locked, and wdev may or may not be NULL. |
| 2287 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2288 | |
| 2289 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2290 | result = cfg80211_dev_rename( |
| 2291 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2292 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2293 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2294 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2295 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2296 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2297 | struct ieee80211_txq_params txq_params; |
| 2298 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2299 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2300 | if (!rdev->ops->set_txq_params) |
| 2301 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2302 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2303 | if (!netdev) |
| 2304 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2305 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2306 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2307 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2308 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2309 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2310 | if (!netif_running(netdev)) |
| 2311 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2312 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2313 | nla_for_each_nested(nl_txq_params, |
| 2314 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2315 | rem_txq_params) { |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 2316 | result = nla_parse_nested(tb, NL80211_TXQ_ATTR_MAX, |
| 2317 | nl_txq_params, |
| 2318 | txq_params_policy); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2319 | if (result) |
| 2320 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2321 | result = parse_txq_params(tb, &txq_params); |
| 2322 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2323 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2324 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2325 | result = rdev_set_txq_params(rdev, netdev, |
| 2326 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2327 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2328 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2329 | } |
| 2330 | } |
| 2331 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2332 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2333 | result = __nl80211_set_channel( |
| 2334 | rdev, |
| 2335 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 2336 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2337 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2338 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2339 | } |
| 2340 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2341 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2342 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2343 | enum nl80211_tx_power_setting type; |
| 2344 | int idx, mbm = 0; |
| 2345 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2346 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2347 | txp_wdev = NULL; |
| 2348 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2349 | if (!rdev->ops->set_tx_power) |
| 2350 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2351 | |
| 2352 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2353 | type = nla_get_u32(info->attrs[idx]); |
| 2354 | |
| 2355 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2356 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2357 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2358 | |
| 2359 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2360 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2361 | mbm = nla_get_u32(info->attrs[idx]); |
| 2362 | } |
| 2363 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2364 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2365 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2366 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2367 | } |
| 2368 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2369 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2370 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2371 | u32 tx_ant, rx_ant; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 2372 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2373 | if ((!rdev->wiphy.available_antennas_tx && |
| 2374 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2375 | !rdev->ops->set_antenna) |
| 2376 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2377 | |
| 2378 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2379 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2380 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2381 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2382 | * available antenna masks, except for the "all" mask */ |
| 2383 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2384 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2385 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2386 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2387 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2388 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2389 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2390 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2391 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2392 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2393 | } |
| 2394 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2395 | changed = 0; |
| 2396 | |
| 2397 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2398 | retry_short = nla_get_u8( |
| 2399 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2400 | if (retry_short == 0) |
| 2401 | return -EINVAL; |
| 2402 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2403 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2404 | } |
| 2405 | |
| 2406 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2407 | retry_long = nla_get_u8( |
| 2408 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2409 | if (retry_long == 0) |
| 2410 | return -EINVAL; |
| 2411 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2412 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2413 | } |
| 2414 | |
| 2415 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2416 | frag_threshold = nla_get_u32( |
| 2417 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2418 | if (frag_threshold < 256) |
| 2419 | return -EINVAL; |
| 2420 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2421 | if (frag_threshold != (u32) -1) { |
| 2422 | /* |
| 2423 | * Fragments (apart from the last one) are required to |
| 2424 | * have even length. Make the fragmentation code |
| 2425 | * simpler by stripping LSB should someone try to use |
| 2426 | * odd threshold value. |
| 2427 | */ |
| 2428 | frag_threshold &= ~0x1; |
| 2429 | } |
| 2430 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2431 | } |
| 2432 | |
| 2433 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2434 | rts_threshold = nla_get_u32( |
| 2435 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2436 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2437 | } |
| 2438 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2439 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2440 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 2441 | return -EINVAL; |
| 2442 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2443 | coverage_class = nla_get_u8( |
| 2444 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2445 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2446 | } |
| 2447 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2448 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 2449 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 2450 | return -EOPNOTSUPP; |
| 2451 | |
| 2452 | changed |= WIPHY_PARAM_DYN_ACK; |
| 2453 | } |
| 2454 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2455 | if (changed) { |
| 2456 | u8 old_retry_short, old_retry_long; |
| 2457 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2458 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2459 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2460 | if (!rdev->ops->set_wiphy_params) |
| 2461 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2462 | |
| 2463 | old_retry_short = rdev->wiphy.retry_short; |
| 2464 | old_retry_long = rdev->wiphy.retry_long; |
| 2465 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2466 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2467 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2468 | |
| 2469 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2470 | rdev->wiphy.retry_short = retry_short; |
| 2471 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2472 | rdev->wiphy.retry_long = retry_long; |
| 2473 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2474 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2475 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2476 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2477 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2478 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2479 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2480 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2481 | if (result) { |
| 2482 | rdev->wiphy.retry_short = old_retry_short; |
| 2483 | rdev->wiphy.retry_long = old_retry_long; |
| 2484 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2485 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2486 | rdev->wiphy.coverage_class = old_coverage_class; |
Michal Kazior | 9189ee3 | 2015-08-03 10:55:24 +0200 | [diff] [blame] | 2487 | return result; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2488 | } |
| 2489 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2490 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2491 | } |
| 2492 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2493 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2494 | { |
| 2495 | return (u64)wdev->identifier | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2496 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2497 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2498 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2499 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2500 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2501 | { |
Johannes Berg | 601555c | 2014-11-27 17:26:56 +0100 | [diff] [blame] | 2502 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 2503 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2504 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2505 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2506 | chandef->chan->center_freq)) |
| 2507 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2508 | switch (chandef->width) { |
| 2509 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2510 | case NL80211_CHAN_WIDTH_20: |
| 2511 | case NL80211_CHAN_WIDTH_40: |
| 2512 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2513 | cfg80211_get_chandef_type(chandef))) |
| 2514 | return -ENOBUFS; |
| 2515 | break; |
| 2516 | default: |
| 2517 | break; |
| 2518 | } |
| 2519 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2520 | return -ENOBUFS; |
| 2521 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2522 | return -ENOBUFS; |
| 2523 | if (chandef->center_freq2 && |
| 2524 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2525 | return -ENOBUFS; |
| 2526 | return 0; |
| 2527 | } |
| 2528 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2529 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 2530 | struct cfg80211_registered_device *rdev, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2531 | struct wireless_dev *wdev, bool removal) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2532 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2533 | struct net_device *dev = wdev->netdev; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2534 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2535 | void *hdr; |
| 2536 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2537 | if (removal) |
| 2538 | cmd = NL80211_CMD_DEL_INTERFACE; |
| 2539 | |
| 2540 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2541 | if (!hdr) |
| 2542 | return -1; |
| 2543 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2544 | if (dev && |
| 2545 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2546 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2547 | goto nla_put_failure; |
| 2548 | |
| 2549 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2550 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 2551 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 2552 | NL80211_ATTR_PAD) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2553 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2554 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2555 | rdev->devlist_generation ^ |
| 2556 | (cfg80211_rdev_list_generation << 2))) |
| 2557 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2558 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2559 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2560 | int ret; |
| 2561 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2562 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2563 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2564 | if (ret == 0) { |
| 2565 | if (nl80211_send_chandef(msg, &chandef)) |
| 2566 | goto nla_put_failure; |
| 2567 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2568 | } |
| 2569 | |
Rafał Miłecki | d55d0d5 | 2015-08-31 22:59:38 +0200 | [diff] [blame] | 2570 | if (rdev->ops->get_tx_power) { |
| 2571 | int dbm, ret; |
| 2572 | |
| 2573 | ret = rdev_get_tx_power(rdev, wdev, &dbm); |
| 2574 | if (ret == 0 && |
| 2575 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, |
| 2576 | DBM_TO_MBM(dbm))) |
| 2577 | goto nla_put_failure; |
| 2578 | } |
| 2579 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2580 | if (wdev->ssid_len) { |
| 2581 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2582 | goto nla_put_failure; |
| 2583 | } |
| 2584 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 2585 | genlmsg_end(msg, hdr); |
| 2586 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2587 | |
| 2588 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2589 | genlmsg_cancel(msg, hdr); |
| 2590 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2591 | } |
| 2592 | |
| 2593 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2594 | { |
| 2595 | int wp_idx = 0; |
| 2596 | int if_idx = 0; |
| 2597 | int wp_start = cb->args[0]; |
| 2598 | int if_start = cb->args[1]; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2599 | int filter_wiphy = -1; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2600 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2601 | struct wireless_dev *wdev; |
| 2602 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2603 | rtnl_lock(); |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2604 | if (!cb->args[2]) { |
| 2605 | struct nl80211_dump_wiphy_state state = { |
| 2606 | .filter_wiphy = -1, |
| 2607 | }; |
| 2608 | int ret; |
| 2609 | |
| 2610 | ret = nl80211_dump_wiphy_parse(skb, cb, &state); |
| 2611 | if (ret) |
| 2612 | return ret; |
| 2613 | |
| 2614 | filter_wiphy = state.filter_wiphy; |
| 2615 | |
| 2616 | /* |
| 2617 | * if filtering, set cb->args[2] to +1 since 0 is the default |
| 2618 | * value needed to determine that parsing is necessary. |
| 2619 | */ |
| 2620 | if (filter_wiphy >= 0) |
| 2621 | cb->args[2] = filter_wiphy + 1; |
| 2622 | else |
| 2623 | cb->args[2] = -1; |
| 2624 | } else if (cb->args[2] > 0) { |
| 2625 | filter_wiphy = cb->args[2] - 1; |
| 2626 | } |
| 2627 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2628 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2629 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2630 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2631 | if (wp_idx < wp_start) { |
| 2632 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2633 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2634 | } |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2635 | |
| 2636 | if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) |
| 2637 | continue; |
| 2638 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2639 | if_idx = 0; |
| 2640 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 2641 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2642 | if (if_idx < if_start) { |
| 2643 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2644 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2645 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2646 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2647 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2648 | rdev, wdev, false) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2649 | goto out; |
| 2650 | } |
| 2651 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2652 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2653 | |
| 2654 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2655 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2656 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2657 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2658 | |
| 2659 | cb->args[0] = wp_idx; |
| 2660 | cb->args[1] = if_idx; |
| 2661 | |
| 2662 | return skb->len; |
| 2663 | } |
| 2664 | |
| 2665 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2666 | { |
| 2667 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2668 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2669 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2670 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2671 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2672 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2673 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2674 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2675 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2676 | rdev, wdev, false) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2677 | nlmsg_free(msg); |
| 2678 | return -ENOBUFS; |
| 2679 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2680 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2681 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2682 | } |
| 2683 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2684 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2685 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2686 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2687 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2688 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2689 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2690 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2691 | }; |
| 2692 | |
| 2693 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2694 | { |
| 2695 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2696 | int flag; |
| 2697 | |
| 2698 | *mntrflags = 0; |
| 2699 | |
| 2700 | if (!nla) |
| 2701 | return -EINVAL; |
| 2702 | |
| 2703 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2704 | nla, mntr_flags_policy)) |
| 2705 | return -EINVAL; |
| 2706 | |
| 2707 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2708 | if (flags[flag]) |
| 2709 | *mntrflags |= (1<<flag); |
| 2710 | |
| 2711 | return 0; |
| 2712 | } |
| 2713 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2714 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2715 | struct net_device *netdev, u8 use_4addr, |
| 2716 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2717 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2718 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2719 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2720 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2721 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2722 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2723 | |
| 2724 | switch (iftype) { |
| 2725 | case NL80211_IFTYPE_AP_VLAN: |
| 2726 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2727 | return 0; |
| 2728 | break; |
| 2729 | case NL80211_IFTYPE_STATION: |
| 2730 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2731 | return 0; |
| 2732 | break; |
| 2733 | default: |
| 2734 | break; |
| 2735 | } |
| 2736 | |
| 2737 | return -EOPNOTSUPP; |
| 2738 | } |
| 2739 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2740 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2741 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2742 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2743 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2744 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2745 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2746 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2747 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2748 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2749 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2750 | memset(¶ms, 0, sizeof(params)); |
| 2751 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2752 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2753 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2754 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2755 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2756 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2757 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2758 | if (ntype > NL80211_IFTYPE_MAX) |
| 2759 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2760 | } |
| 2761 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2762 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2763 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2764 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2765 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2766 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2767 | if (netif_running(dev)) |
| 2768 | return -EBUSY; |
| 2769 | |
| 2770 | wdev_lock(wdev); |
| 2771 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2772 | IEEE80211_MAX_MESH_ID_LEN); |
| 2773 | wdev->mesh_id_up_len = |
| 2774 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2775 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2776 | wdev->mesh_id_up_len); |
| 2777 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2778 | } |
| 2779 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2780 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2781 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2782 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2783 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2784 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2785 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2786 | } else { |
| 2787 | params.use_4addr = -1; |
| 2788 | } |
| 2789 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2790 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2791 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2792 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2793 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2794 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2795 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2796 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2797 | |
| 2798 | flags = &_flags; |
| 2799 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2800 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2801 | |
Aviya Erenfeld | c6e6a0c | 2016-07-05 15:23:08 +0300 | [diff] [blame] | 2802 | if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { |
| 2803 | const u8 *mumimo_groups; |
| 2804 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 2805 | |
| 2806 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 2807 | return -EOPNOTSUPP; |
| 2808 | |
| 2809 | mumimo_groups = |
| 2810 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); |
| 2811 | |
| 2812 | /* bits 0 and 63 are reserved and must be zero */ |
| 2813 | if ((mumimo_groups[0] & BIT(7)) || |
| 2814 | (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(0))) |
| 2815 | return -EINVAL; |
| 2816 | |
| 2817 | memcpy(params.vht_mumimo_groups, mumimo_groups, |
| 2818 | VHT_MUMIMO_GROUPS_DATA_LEN); |
| 2819 | change = true; |
| 2820 | } |
| 2821 | |
| 2822 | if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { |
| 2823 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 2824 | |
| 2825 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 2826 | return -EOPNOTSUPP; |
| 2827 | |
| 2828 | nla_memcpy(params.macaddr, |
| 2829 | info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR], |
| 2830 | ETH_ALEN); |
| 2831 | change = true; |
| 2832 | } |
| 2833 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2834 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2835 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2836 | return -EOPNOTSUPP; |
| 2837 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2838 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2839 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2840 | else |
| 2841 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2842 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2843 | if (!err && params.use_4addr != -1) |
| 2844 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2845 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2846 | return err; |
| 2847 | } |
| 2848 | |
| 2849 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2850 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2851 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2852 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2853 | struct wireless_dev *wdev; |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 2854 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2855 | int err; |
| 2856 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2857 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2858 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2859 | /* to avoid failing a new interface creation due to pending removal */ |
| 2860 | cfg80211_destroy_ifaces(rdev); |
| 2861 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2862 | memset(¶ms, 0, sizeof(params)); |
| 2863 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2864 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2865 | return -EINVAL; |
| 2866 | |
| 2867 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2868 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2869 | if (type > NL80211_IFTYPE_MAX) |
| 2870 | return -EINVAL; |
| 2871 | } |
| 2872 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2873 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2874 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2875 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2876 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 2877 | if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || |
Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 2878 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 2879 | info->attrs[NL80211_ATTR_MAC]) { |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2880 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2881 | ETH_ALEN); |
| 2882 | if (!is_valid_ether_addr(params.macaddr)) |
| 2883 | return -EADDRNOTAVAIL; |
| 2884 | } |
| 2885 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2886 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2887 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2888 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2889 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2890 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2891 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2892 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2893 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2894 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2895 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2896 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2897 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2898 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2899 | return -EOPNOTSUPP; |
| 2900 | |
Johannes Berg | a18c719 | 2015-02-24 10:56:42 +0100 | [diff] [blame] | 2901 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2902 | if (!msg) |
| 2903 | return -ENOMEM; |
| 2904 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2905 | wdev = rdev_add_virtual_intf(rdev, |
| 2906 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 2907 | NET_NAME_USER, type, err ? NULL : &flags, |
| 2908 | ¶ms); |
Rafał Miłecki | d687cbb | 2014-11-14 18:43:28 +0100 | [diff] [blame] | 2909 | if (WARN_ON(!wdev)) { |
| 2910 | nlmsg_free(msg); |
| 2911 | return -EPROTO; |
| 2912 | } else if (IS_ERR(wdev)) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2913 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2914 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2915 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2916 | |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 2917 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2918 | wdev->owner_nlportid = info->snd_portid; |
| 2919 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2920 | switch (type) { |
| 2921 | case NL80211_IFTYPE_MESH_POINT: |
| 2922 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2923 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2924 | wdev_lock(wdev); |
| 2925 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2926 | IEEE80211_MAX_MESH_ID_LEN); |
| 2927 | wdev->mesh_id_up_len = |
| 2928 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2929 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2930 | wdev->mesh_id_up_len); |
| 2931 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2932 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 2933 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2934 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2935 | /* |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 2936 | * P2P Device and NAN do not have a netdev, so don't go |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2937 | * through the netdev notifier and must be added here |
| 2938 | */ |
| 2939 | mutex_init(&wdev->mtx); |
| 2940 | INIT_LIST_HEAD(&wdev->event_list); |
| 2941 | spin_lock_init(&wdev->event_lock); |
| 2942 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2943 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2944 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2945 | wdev->identifier = ++rdev->wdev_id; |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 2946 | list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2947 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2948 | break; |
| 2949 | default: |
| 2950 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2951 | } |
| 2952 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2953 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2954 | rdev, wdev, false) < 0) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2955 | nlmsg_free(msg); |
| 2956 | return -ENOBUFS; |
| 2957 | } |
| 2958 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 2959 | /* |
| 2960 | * For wdevs which have no associated netdev object (e.g. of type |
| 2961 | * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here. |
| 2962 | * For all other types, the event will be generated from the |
| 2963 | * netdev notifier |
| 2964 | */ |
| 2965 | if (!wdev->netdev) |
| 2966 | nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE); |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2967 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2968 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2969 | } |
| 2970 | |
| 2971 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2972 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2973 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2974 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2975 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2976 | if (!rdev->ops->del_virtual_intf) |
| 2977 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2978 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2979 | /* |
| 2980 | * If we remove a wireless device without a netdev then clear |
| 2981 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2982 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2983 | * since the wdev has been freed, unlike with a netdev where |
| 2984 | * we need the dev_put() for the netdev to really be freed. |
| 2985 | */ |
| 2986 | if (!wdev->netdev) |
| 2987 | info->user_ptr[1] = NULL; |
| 2988 | |
Denis Kenzior | 7f8ed01 | 2016-08-03 16:58:35 -0500 | [diff] [blame] | 2989 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2990 | } |
| 2991 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2992 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2993 | { |
| 2994 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2995 | struct net_device *dev = info->user_ptr[1]; |
| 2996 | u16 noack_map; |
| 2997 | |
| 2998 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2999 | return -EINVAL; |
| 3000 | |
| 3001 | if (!rdev->ops->set_noack_map) |
| 3002 | return -EOPNOTSUPP; |
| 3003 | |
| 3004 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 3005 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3006 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 3007 | } |
| 3008 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3009 | struct get_key_cookie { |
| 3010 | struct sk_buff *msg; |
| 3011 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3012 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3013 | }; |
| 3014 | |
| 3015 | static void get_key_callback(void *c, struct key_params *params) |
| 3016 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3017 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3018 | struct get_key_cookie *cookie = c; |
| 3019 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3020 | if ((params->key && |
| 3021 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 3022 | params->key_len, params->key)) || |
| 3023 | (params->seq && |
| 3024 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 3025 | params->seq_len, params->seq)) || |
| 3026 | (params->cipher && |
| 3027 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 3028 | params->cipher))) |
| 3029 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3030 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3031 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 3032 | if (!key) |
| 3033 | goto nla_put_failure; |
| 3034 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3035 | if ((params->key && |
| 3036 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 3037 | params->key_len, params->key)) || |
| 3038 | (params->seq && |
| 3039 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 3040 | params->seq_len, params->seq)) || |
| 3041 | (params->cipher && |
| 3042 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 3043 | params->cipher))) |
| 3044 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3045 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3046 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 3047 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3048 | |
| 3049 | nla_nest_end(cookie->msg, key); |
| 3050 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3051 | return; |
| 3052 | nla_put_failure: |
| 3053 | cookie->error = 1; |
| 3054 | } |
| 3055 | |
| 3056 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 3057 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3058 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3059 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3060 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3061 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3062 | const u8 *mac_addr = NULL; |
| 3063 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3064 | struct get_key_cookie cookie = { |
| 3065 | .error = 0, |
| 3066 | }; |
| 3067 | void *hdr; |
| 3068 | struct sk_buff *msg; |
| 3069 | |
| 3070 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 3071 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 3072 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 3073 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3074 | return -EINVAL; |
| 3075 | |
| 3076 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3077 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3078 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3079 | pairwise = !!mac_addr; |
| 3080 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 3081 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 3082 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3083 | if (kt >= NUM_NL80211_KEYTYPES) |
| 3084 | return -EINVAL; |
| 3085 | if (kt != NL80211_KEYTYPE_GROUP && |
| 3086 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 3087 | return -EINVAL; |
| 3088 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 3089 | } |
| 3090 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3091 | if (!rdev->ops->get_key) |
| 3092 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3093 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3094 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3095 | return -ENOENT; |
| 3096 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3097 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3098 | if (!msg) |
| 3099 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3100 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3101 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3102 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 3103 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 3104 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3105 | |
| 3106 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3107 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3108 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3109 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3110 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 3111 | goto nla_put_failure; |
| 3112 | if (mac_addr && |
| 3113 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 3114 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3115 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3116 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 3117 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3118 | |
| 3119 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3120 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3121 | |
| 3122 | if (cookie.error) |
| 3123 | goto nla_put_failure; |
| 3124 | |
| 3125 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3126 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3127 | |
| 3128 | nla_put_failure: |
| 3129 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3130 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3131 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3132 | return err; |
| 3133 | } |
| 3134 | |
| 3135 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 3136 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3137 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3138 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3139 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3140 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3141 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3142 | err = nl80211_parse_key(info, &key); |
| 3143 | if (err) |
| 3144 | return err; |
| 3145 | |
| 3146 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3147 | return -EINVAL; |
| 3148 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3149 | /* only support setting default key */ |
| 3150 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3151 | return -EINVAL; |
| 3152 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3153 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3154 | |
| 3155 | if (key.def) { |
| 3156 | if (!rdev->ops->set_default_key) { |
| 3157 | err = -EOPNOTSUPP; |
| 3158 | goto out; |
| 3159 | } |
| 3160 | |
| 3161 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3162 | if (err) |
| 3163 | goto out; |
| 3164 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3165 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3166 | key.def_uni, key.def_multi); |
| 3167 | |
| 3168 | if (err) |
| 3169 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3170 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3171 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3172 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3173 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3174 | } else { |
| 3175 | if (key.def_uni || !key.def_multi) { |
| 3176 | err = -EINVAL; |
| 3177 | goto out; |
| 3178 | } |
| 3179 | |
| 3180 | if (!rdev->ops->set_default_mgmt_key) { |
| 3181 | err = -EOPNOTSUPP; |
| 3182 | goto out; |
| 3183 | } |
| 3184 | |
| 3185 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3186 | if (err) |
| 3187 | goto out; |
| 3188 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3189 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3190 | if (err) |
| 3191 | goto out; |
| 3192 | |
| 3193 | #ifdef CONFIG_CFG80211_WEXT |
| 3194 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 3195 | #endif |
| 3196 | } |
| 3197 | |
| 3198 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3199 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3200 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3201 | return err; |
| 3202 | } |
| 3203 | |
| 3204 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 3205 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3206 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3207 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3208 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3209 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3210 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3211 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3212 | err = nl80211_parse_key(info, &key); |
| 3213 | if (err) |
| 3214 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3215 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3216 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3217 | return -EINVAL; |
| 3218 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3219 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3220 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3221 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3222 | if (key.type == -1) { |
| 3223 | if (mac_addr) |
| 3224 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3225 | else |
| 3226 | key.type = NL80211_KEYTYPE_GROUP; |
| 3227 | } |
| 3228 | |
| 3229 | /* for now */ |
| 3230 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3231 | key.type != NL80211_KEYTYPE_GROUP) |
| 3232 | return -EINVAL; |
| 3233 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3234 | if (!rdev->ops->add_key) |
| 3235 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3236 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3237 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 3238 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3239 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3240 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3241 | |
| 3242 | wdev_lock(dev->ieee80211_ptr); |
| 3243 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3244 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3245 | err = rdev_add_key(rdev, dev, key.idx, |
| 3246 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3247 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3248 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3249 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3250 | return err; |
| 3251 | } |
| 3252 | |
| 3253 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 3254 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3255 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3256 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3257 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3258 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3259 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3260 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3261 | err = nl80211_parse_key(info, &key); |
| 3262 | if (err) |
| 3263 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3264 | |
| 3265 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3266 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3267 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3268 | if (key.type == -1) { |
| 3269 | if (mac_addr) |
| 3270 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3271 | else |
| 3272 | key.type = NL80211_KEYTYPE_GROUP; |
| 3273 | } |
| 3274 | |
| 3275 | /* for now */ |
| 3276 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3277 | key.type != NL80211_KEYTYPE_GROUP) |
| 3278 | return -EINVAL; |
| 3279 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3280 | if (!rdev->ops->del_key) |
| 3281 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3282 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3283 | wdev_lock(dev->ieee80211_ptr); |
| 3284 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3285 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3286 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3287 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3288 | err = -ENOENT; |
| 3289 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3290 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3291 | err = rdev_del_key(rdev, dev, key.idx, |
| 3292 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3293 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3294 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3295 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3296 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3297 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3298 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3299 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3300 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 3301 | } |
| 3302 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3303 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3304 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3305 | return err; |
| 3306 | } |
| 3307 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3308 | /* This function returns an error or the number of nested attributes */ |
| 3309 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 3310 | { |
| 3311 | struct nlattr *attr; |
| 3312 | int n_entries = 0, tmp; |
| 3313 | |
| 3314 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 3315 | if (nla_len(attr) != ETH_ALEN) |
| 3316 | return -EINVAL; |
| 3317 | |
| 3318 | n_entries++; |
| 3319 | } |
| 3320 | |
| 3321 | return n_entries; |
| 3322 | } |
| 3323 | |
| 3324 | /* |
| 3325 | * This function parses ACL information and allocates memory for ACL data. |
| 3326 | * On successful return, the calling function is responsible to free the |
| 3327 | * ACL buffer returned by this function. |
| 3328 | */ |
| 3329 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 3330 | struct genl_info *info) |
| 3331 | { |
| 3332 | enum nl80211_acl_policy acl_policy; |
| 3333 | struct nlattr *attr; |
| 3334 | struct cfg80211_acl_data *acl; |
| 3335 | int i = 0, n_entries, tmp; |
| 3336 | |
| 3337 | if (!wiphy->max_acl_mac_addrs) |
| 3338 | return ERR_PTR(-EOPNOTSUPP); |
| 3339 | |
| 3340 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 3341 | return ERR_PTR(-EINVAL); |
| 3342 | |
| 3343 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 3344 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 3345 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 3346 | return ERR_PTR(-EINVAL); |
| 3347 | |
| 3348 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 3349 | return ERR_PTR(-EINVAL); |
| 3350 | |
| 3351 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 3352 | if (n_entries < 0) |
| 3353 | return ERR_PTR(n_entries); |
| 3354 | |
| 3355 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 3356 | return ERR_PTR(-ENOTSUPP); |
| 3357 | |
| 3358 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 3359 | GFP_KERNEL); |
| 3360 | if (!acl) |
| 3361 | return ERR_PTR(-ENOMEM); |
| 3362 | |
| 3363 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 3364 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3365 | i++; |
| 3366 | } |
| 3367 | |
| 3368 | acl->n_acl_entries = n_entries; |
| 3369 | acl->acl_policy = acl_policy; |
| 3370 | |
| 3371 | return acl; |
| 3372 | } |
| 3373 | |
| 3374 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3375 | { |
| 3376 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3377 | struct net_device *dev = info->user_ptr[1]; |
| 3378 | struct cfg80211_acl_data *acl; |
| 3379 | int err; |
| 3380 | |
| 3381 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3382 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3383 | return -EOPNOTSUPP; |
| 3384 | |
| 3385 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3386 | return -EINVAL; |
| 3387 | |
| 3388 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3389 | if (IS_ERR(acl)) |
| 3390 | return PTR_ERR(acl); |
| 3391 | |
| 3392 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3393 | |
| 3394 | kfree(acl); |
| 3395 | |
| 3396 | return err; |
| 3397 | } |
| 3398 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3399 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 3400 | u8 *rates, u8 rates_len) |
| 3401 | { |
| 3402 | u8 i; |
| 3403 | u32 mask = 0; |
| 3404 | |
| 3405 | for (i = 0; i < rates_len; i++) { |
| 3406 | int rate = (rates[i] & 0x7f) * 5; |
| 3407 | int ridx; |
| 3408 | |
| 3409 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 3410 | struct ieee80211_rate *srate = |
| 3411 | &sband->bitrates[ridx]; |
| 3412 | if (rate == srate->bitrate) { |
| 3413 | mask |= 1 << ridx; |
| 3414 | break; |
| 3415 | } |
| 3416 | } |
| 3417 | if (ridx == sband->n_bitrates) |
| 3418 | return 0; /* rate not found */ |
| 3419 | } |
| 3420 | |
| 3421 | return mask; |
| 3422 | } |
| 3423 | |
| 3424 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 3425 | u8 *rates, u8 rates_len, |
| 3426 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 3427 | { |
| 3428 | u8 i; |
| 3429 | |
| 3430 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 3431 | |
| 3432 | for (i = 0; i < rates_len; i++) { |
| 3433 | int ridx, rbit; |
| 3434 | |
| 3435 | ridx = rates[i] / 8; |
| 3436 | rbit = BIT(rates[i] % 8); |
| 3437 | |
| 3438 | /* check validity */ |
| 3439 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
| 3440 | return false; |
| 3441 | |
| 3442 | /* check availability */ |
| 3443 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 3444 | mcs[ridx] |= rbit; |
| 3445 | else |
| 3446 | return false; |
| 3447 | } |
| 3448 | |
| 3449 | return true; |
| 3450 | } |
| 3451 | |
| 3452 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 3453 | { |
| 3454 | u16 mcs_mask = 0; |
| 3455 | |
| 3456 | switch (vht_mcs_map) { |
| 3457 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 3458 | break; |
| 3459 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 3460 | mcs_mask = 0x00FF; |
| 3461 | break; |
| 3462 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 3463 | mcs_mask = 0x01FF; |
| 3464 | break; |
| 3465 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 3466 | mcs_mask = 0x03FF; |
| 3467 | break; |
| 3468 | default: |
| 3469 | break; |
| 3470 | } |
| 3471 | |
| 3472 | return mcs_mask; |
| 3473 | } |
| 3474 | |
| 3475 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 3476 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 3477 | { |
| 3478 | u8 nss; |
| 3479 | |
| 3480 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 3481 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 3482 | vht_mcs_map >>= 2; |
| 3483 | } |
| 3484 | } |
| 3485 | |
| 3486 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 3487 | struct nl80211_txrate_vht *txrate, |
| 3488 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 3489 | { |
| 3490 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 3491 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 3492 | u8 i; |
| 3493 | |
| 3494 | if (!sband->vht_cap.vht_supported) |
| 3495 | return false; |
| 3496 | |
| 3497 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 3498 | |
| 3499 | /* Build vht_mcs_mask from VHT capabilities */ |
| 3500 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 3501 | |
| 3502 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 3503 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 3504 | mcs[i] = txrate->mcs[i]; |
| 3505 | else |
| 3506 | return false; |
| 3507 | } |
| 3508 | |
| 3509 | return true; |
| 3510 | } |
| 3511 | |
| 3512 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
| 3513 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 3514 | .len = NL80211_MAX_SUPP_RATES }, |
| 3515 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 3516 | .len = NL80211_MAX_SUPP_HT_RATES }, |
| 3517 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
| 3518 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
| 3519 | }; |
| 3520 | |
| 3521 | static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, |
| 3522 | struct cfg80211_bitrate_mask *mask) |
| 3523 | { |
| 3524 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
| 3525 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3526 | int rem, i; |
| 3527 | struct nlattr *tx_rates; |
| 3528 | struct ieee80211_supported_band *sband; |
| 3529 | u16 vht_tx_mcs_map; |
| 3530 | |
| 3531 | memset(mask, 0, sizeof(*mask)); |
| 3532 | /* Default to all rates enabled */ |
| 3533 | for (i = 0; i < NUM_NL80211_BANDS; i++) { |
| 3534 | sband = rdev->wiphy.bands[i]; |
| 3535 | |
| 3536 | if (!sband) |
| 3537 | continue; |
| 3538 | |
| 3539 | mask->control[i].legacy = (1 << sband->n_bitrates) - 1; |
| 3540 | memcpy(mask->control[i].ht_mcs, |
| 3541 | sband->ht_cap.mcs.rx_mask, |
| 3542 | sizeof(mask->control[i].ht_mcs)); |
| 3543 | |
| 3544 | if (!sband->vht_cap.vht_supported) |
| 3545 | continue; |
| 3546 | |
| 3547 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 3548 | vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); |
| 3549 | } |
| 3550 | |
| 3551 | /* if no rates are given set it back to the defaults */ |
| 3552 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 3553 | goto out; |
| 3554 | |
| 3555 | /* The nested attribute uses enum nl80211_band as the index. This maps |
| 3556 | * directly to the enum nl80211_band values used in cfg80211. |
| 3557 | */ |
| 3558 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
| 3559 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
| 3560 | enum nl80211_band band = nla_type(tx_rates); |
| 3561 | int err; |
| 3562 | |
| 3563 | if (band < 0 || band >= NUM_NL80211_BANDS) |
| 3564 | return -EINVAL; |
| 3565 | sband = rdev->wiphy.bands[band]; |
| 3566 | if (sband == NULL) |
| 3567 | return -EINVAL; |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 3568 | err = nla_parse_nested(tb, NL80211_TXRATE_MAX, tx_rates, |
| 3569 | nl80211_txattr_policy); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3570 | if (err) |
| 3571 | return err; |
| 3572 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 3573 | mask->control[band].legacy = rateset_to_mask( |
| 3574 | sband, |
| 3575 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 3576 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
| 3577 | if ((mask->control[band].legacy == 0) && |
| 3578 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 3579 | return -EINVAL; |
| 3580 | } |
| 3581 | if (tb[NL80211_TXRATE_HT]) { |
| 3582 | if (!ht_rateset_to_mask( |
| 3583 | sband, |
| 3584 | nla_data(tb[NL80211_TXRATE_HT]), |
| 3585 | nla_len(tb[NL80211_TXRATE_HT]), |
| 3586 | mask->control[band].ht_mcs)) |
| 3587 | return -EINVAL; |
| 3588 | } |
| 3589 | if (tb[NL80211_TXRATE_VHT]) { |
| 3590 | if (!vht_set_mcs_mask( |
| 3591 | sband, |
| 3592 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 3593 | mask->control[band].vht_mcs)) |
| 3594 | return -EINVAL; |
| 3595 | } |
| 3596 | if (tb[NL80211_TXRATE_GI]) { |
| 3597 | mask->control[band].gi = |
| 3598 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 3599 | if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 3600 | return -EINVAL; |
| 3601 | } |
| 3602 | |
| 3603 | if (mask->control[band].legacy == 0) { |
| 3604 | /* don't allow empty legacy rates if HT or VHT |
| 3605 | * are not even supported. |
| 3606 | */ |
| 3607 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 3608 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
| 3609 | return -EINVAL; |
| 3610 | |
| 3611 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 3612 | if (mask->control[band].ht_mcs[i]) |
| 3613 | goto out; |
| 3614 | |
| 3615 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 3616 | if (mask->control[band].vht_mcs[i]) |
| 3617 | goto out; |
| 3618 | |
| 3619 | /* legacy and mcs rates may not be both empty */ |
| 3620 | return -EINVAL; |
| 3621 | } |
| 3622 | } |
| 3623 | |
| 3624 | out: |
| 3625 | return 0; |
| 3626 | } |
| 3627 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3628 | static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, |
| 3629 | enum nl80211_band band, |
| 3630 | struct cfg80211_bitrate_mask *beacon_rate) |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3631 | { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3632 | u32 count_ht, count_vht, i; |
| 3633 | u32 rate = beacon_rate->control[band].legacy; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3634 | |
| 3635 | /* Allow only one rate */ |
| 3636 | if (hweight32(rate) > 1) |
| 3637 | return -EINVAL; |
| 3638 | |
| 3639 | count_ht = 0; |
| 3640 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3641 | if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3642 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3643 | } else if (beacon_rate->control[band].ht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3644 | count_ht++; |
| 3645 | if (count_ht > 1) |
| 3646 | return -EINVAL; |
| 3647 | } |
| 3648 | if (count_ht && rate) |
| 3649 | return -EINVAL; |
| 3650 | } |
| 3651 | |
| 3652 | count_vht = 0; |
| 3653 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3654 | if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3655 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3656 | } else if (beacon_rate->control[band].vht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3657 | count_vht++; |
| 3658 | if (count_vht > 1) |
| 3659 | return -EINVAL; |
| 3660 | } |
| 3661 | if (count_vht && rate) |
| 3662 | return -EINVAL; |
| 3663 | } |
| 3664 | |
| 3665 | if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht)) |
| 3666 | return -EINVAL; |
| 3667 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3668 | if (rate && |
| 3669 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 3670 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) |
| 3671 | return -EINVAL; |
| 3672 | if (count_ht && |
| 3673 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 3674 | NL80211_EXT_FEATURE_BEACON_RATE_HT)) |
| 3675 | return -EINVAL; |
| 3676 | if (count_vht && |
| 3677 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 3678 | NL80211_EXT_FEATURE_BEACON_RATE_VHT)) |
| 3679 | return -EINVAL; |
| 3680 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3681 | return 0; |
| 3682 | } |
| 3683 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3684 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3685 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3686 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3687 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3688 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3689 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3690 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3691 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3692 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3693 | return -EINVAL; |
| 3694 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3695 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3696 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3697 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3698 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3699 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3700 | if (!bcn->head_len) |
| 3701 | return -EINVAL; |
| 3702 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3703 | } |
| 3704 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3705 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3706 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3707 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3708 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3709 | } |
| 3710 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3711 | if (!haveinfo) |
| 3712 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3713 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3714 | if (attrs[NL80211_ATTR_IE]) { |
| 3715 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3716 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3717 | } |
| 3718 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3719 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3720 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3721 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3722 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3723 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3724 | } |
| 3725 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3726 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3727 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3728 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3729 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3730 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3731 | } |
| 3732 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3733 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3734 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3735 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3736 | } |
| 3737 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3738 | return 0; |
| 3739 | } |
| 3740 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3741 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3742 | struct cfg80211_ap_settings *params) |
| 3743 | { |
| 3744 | struct wireless_dev *wdev; |
| 3745 | bool ret = false; |
| 3746 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 3747 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3748 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3749 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3750 | continue; |
| 3751 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3752 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3753 | continue; |
| 3754 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3755 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3756 | ret = true; |
| 3757 | break; |
| 3758 | } |
| 3759 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3760 | return ret; |
| 3761 | } |
| 3762 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3763 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3764 | enum nl80211_auth_type auth_type, |
| 3765 | enum nl80211_commands cmd) |
| 3766 | { |
| 3767 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3768 | return false; |
| 3769 | |
| 3770 | switch (cmd) { |
| 3771 | case NL80211_CMD_AUTHENTICATE: |
| 3772 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3773 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3774 | return false; |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 3775 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 3776 | NL80211_EXT_FEATURE_FILS_STA) && |
| 3777 | (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 3778 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 3779 | auth_type == NL80211_AUTHTYPE_FILS_PK)) |
| 3780 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3781 | return true; |
| 3782 | case NL80211_CMD_CONNECT: |
| 3783 | case NL80211_CMD_START_AP: |
| 3784 | /* SAE not supported yet */ |
| 3785 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3786 | return false; |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 3787 | /* FILS not supported yet */ |
| 3788 | if (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 3789 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 3790 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 3791 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3792 | return true; |
| 3793 | default: |
| 3794 | return false; |
| 3795 | } |
| 3796 | } |
| 3797 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3798 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3799 | { |
| 3800 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3801 | struct net_device *dev = info->user_ptr[1]; |
| 3802 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3803 | struct cfg80211_ap_settings params; |
| 3804 | int err; |
| 3805 | |
| 3806 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3807 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3808 | return -EOPNOTSUPP; |
| 3809 | |
| 3810 | if (!rdev->ops->start_ap) |
| 3811 | return -EOPNOTSUPP; |
| 3812 | |
| 3813 | if (wdev->beacon_interval) |
| 3814 | return -EALREADY; |
| 3815 | |
| 3816 | memset(¶ms, 0, sizeof(params)); |
| 3817 | |
| 3818 | /* these are required for START_AP */ |
| 3819 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3820 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3821 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3822 | return -EINVAL; |
| 3823 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3824 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3825 | if (err) |
| 3826 | return err; |
| 3827 | |
| 3828 | params.beacon_interval = |
| 3829 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3830 | params.dtim_period = |
| 3831 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3832 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 3833 | err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype, |
| 3834 | params.beacon_interval); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3835 | if (err) |
| 3836 | return err; |
| 3837 | |
| 3838 | /* |
| 3839 | * In theory, some of these attributes should be required here |
| 3840 | * but since they were not used when the command was originally |
| 3841 | * added, keep them optional for old user space programs to let |
| 3842 | * them continue to work with drivers that do not need the |
| 3843 | * additional information -- drivers must check! |
| 3844 | */ |
| 3845 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3846 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3847 | params.ssid_len = |
| 3848 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3849 | if (params.ssid_len == 0 || |
| 3850 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3851 | return -EINVAL; |
| 3852 | } |
| 3853 | |
| 3854 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3855 | params.hidden_ssid = nla_get_u32( |
| 3856 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3857 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3858 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3859 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3860 | return -EINVAL; |
| 3861 | } |
| 3862 | |
| 3863 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3864 | |
| 3865 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3866 | params.auth_type = nla_get_u32( |
| 3867 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3868 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3869 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3870 | return -EINVAL; |
| 3871 | } else |
| 3872 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3873 | |
| 3874 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3875 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3876 | if (err) |
| 3877 | return err; |
| 3878 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3879 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3880 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3881 | return -EOPNOTSUPP; |
| 3882 | params.inactivity_timeout = nla_get_u16( |
| 3883 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3884 | } |
| 3885 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3886 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3887 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3888 | return -EINVAL; |
| 3889 | params.p2p_ctwindow = |
| 3890 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3891 | if (params.p2p_ctwindow > 127) |
| 3892 | return -EINVAL; |
| 3893 | if (params.p2p_ctwindow != 0 && |
| 3894 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3895 | return -EINVAL; |
| 3896 | } |
| 3897 | |
| 3898 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3899 | u8 tmp; |
| 3900 | |
| 3901 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3902 | return -EINVAL; |
| 3903 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3904 | if (tmp > 1) |
| 3905 | return -EINVAL; |
| 3906 | params.p2p_opp_ps = tmp; |
| 3907 | if (params.p2p_opp_ps != 0 && |
| 3908 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3909 | return -EINVAL; |
| 3910 | } |
| 3911 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3912 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3913 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3914 | if (err) |
| 3915 | return err; |
| 3916 | } else if (wdev->preset_chandef.chan) { |
| 3917 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3918 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3919 | return -EINVAL; |
| 3920 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 3921 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 3922 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3923 | return -EINVAL; |
| 3924 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3925 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
| 3926 | err = nl80211_parse_tx_bitrate_mask(info, ¶ms.beacon_rate); |
| 3927 | if (err) |
| 3928 | return err; |
| 3929 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3930 | err = validate_beacon_tx_rate(rdev, params.chandef.chan->band, |
| 3931 | ¶ms.beacon_rate); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3932 | if (err) |
| 3933 | return err; |
| 3934 | } |
| 3935 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 3936 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 3937 | params.smps_mode = |
| 3938 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 3939 | switch (params.smps_mode) { |
| 3940 | case NL80211_SMPS_OFF: |
| 3941 | break; |
| 3942 | case NL80211_SMPS_STATIC: |
| 3943 | if (!(rdev->wiphy.features & |
| 3944 | NL80211_FEATURE_STATIC_SMPS)) |
| 3945 | return -EINVAL; |
| 3946 | break; |
| 3947 | case NL80211_SMPS_DYNAMIC: |
| 3948 | if (!(rdev->wiphy.features & |
| 3949 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 3950 | return -EINVAL; |
| 3951 | break; |
| 3952 | default: |
| 3953 | return -EINVAL; |
| 3954 | } |
| 3955 | } else { |
| 3956 | params.smps_mode = NL80211_SMPS_OFF; |
| 3957 | } |
| 3958 | |
Purushottam Kushwaha | 6e8ef84 | 2016-07-05 13:44:51 +0530 | [diff] [blame] | 3959 | params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
| 3960 | if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) |
| 3961 | return -EOPNOTSUPP; |
| 3962 | |
Ola Olsson | 4baf6be | 2015-10-29 07:04:58 +0100 | [diff] [blame] | 3963 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3964 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3965 | if (IS_ERR(params.acl)) |
| 3966 | return PTR_ERR(params.acl); |
| 3967 | } |
| 3968 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3969 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3970 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3971 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3972 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3973 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 3974 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3975 | wdev->ssid_len = params.ssid_len; |
| 3976 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3977 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3978 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3979 | |
| 3980 | kfree(params.acl); |
| 3981 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3982 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3983 | } |
| 3984 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3985 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3986 | { |
| 3987 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3988 | struct net_device *dev = info->user_ptr[1]; |
| 3989 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3990 | struct cfg80211_beacon_data params; |
| 3991 | int err; |
| 3992 | |
| 3993 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3994 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3995 | return -EOPNOTSUPP; |
| 3996 | |
| 3997 | if (!rdev->ops->change_beacon) |
| 3998 | return -EOPNOTSUPP; |
| 3999 | |
| 4000 | if (!wdev->beacon_interval) |
| 4001 | return -EINVAL; |
| 4002 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4003 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4004 | if (err) |
| 4005 | return err; |
| 4006 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4007 | wdev_lock(wdev); |
| 4008 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 4009 | wdev_unlock(wdev); |
| 4010 | |
| 4011 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4012 | } |
| 4013 | |
| 4014 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4015 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4016 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4017 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4018 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 4019 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4020 | } |
| 4021 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4022 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 4023 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 4024 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 4025 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 4026 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 4027 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 4028 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4029 | }; |
| 4030 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4031 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4032 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4033 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4034 | { |
| 4035 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4036 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4037 | int flag; |
| 4038 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4039 | /* |
| 4040 | * Try parsing the new attribute first so userspace |
| 4041 | * can specify both for older kernels. |
| 4042 | */ |
| 4043 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 4044 | if (nla) { |
| 4045 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4046 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4047 | sta_flags = nla_data(nla); |
| 4048 | params->sta_flags_mask = sta_flags->mask; |
| 4049 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4050 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4051 | if ((params->sta_flags_mask | |
| 4052 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 4053 | return -EINVAL; |
| 4054 | return 0; |
| 4055 | } |
| 4056 | |
| 4057 | /* if present, parse the old attribute */ |
| 4058 | |
| 4059 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4060 | if (!nla) |
| 4061 | return 0; |
| 4062 | |
| 4063 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 4064 | nla, sta_flags_policy)) |
| 4065 | return -EINVAL; |
| 4066 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4067 | /* |
| 4068 | * Only allow certain flags for interface types so that |
| 4069 | * other attributes are silently ignored. Remember that |
| 4070 | * this is backward compatibility code with old userspace |
| 4071 | * and shouldn't be hit in other cases anyway. |
| 4072 | */ |
| 4073 | switch (iftype) { |
| 4074 | case NL80211_IFTYPE_AP: |
| 4075 | case NL80211_IFTYPE_AP_VLAN: |
| 4076 | case NL80211_IFTYPE_P2P_GO: |
| 4077 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4078 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 4079 | BIT(NL80211_STA_FLAG_WME) | |
| 4080 | BIT(NL80211_STA_FLAG_MFP); |
| 4081 | break; |
| 4082 | case NL80211_IFTYPE_P2P_CLIENT: |
| 4083 | case NL80211_IFTYPE_STATION: |
| 4084 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4085 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4086 | break; |
| 4087 | case NL80211_IFTYPE_MESH_POINT: |
| 4088 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4089 | BIT(NL80211_STA_FLAG_MFP) | |
| 4090 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 4091 | default: |
| 4092 | return -EINVAL; |
| 4093 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4094 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 4095 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 4096 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4097 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4098 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 4099 | /* no longer support new API additions in old API */ |
| 4100 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 4101 | return -EINVAL; |
| 4102 | } |
| 4103 | } |
| 4104 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4105 | return 0; |
| 4106 | } |
| 4107 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4108 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 4109 | int attr) |
| 4110 | { |
| 4111 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 4112 | u32 bitrate; |
| 4113 | u16 bitrate_compat; |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 4114 | enum nl80211_attrs rate_flg; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4115 | |
| 4116 | rate = nla_nest_start(msg, attr); |
| 4117 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4118 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4119 | |
| 4120 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 4121 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 4122 | /* report 16-bit bitrate only if we can */ |
| 4123 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4124 | if (bitrate > 0 && |
| 4125 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 4126 | return false; |
| 4127 | if (bitrate_compat > 0 && |
| 4128 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 4129 | return false; |
| 4130 | |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 4131 | switch (info->bw) { |
| 4132 | case RATE_INFO_BW_5: |
| 4133 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; |
| 4134 | break; |
| 4135 | case RATE_INFO_BW_10: |
| 4136 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; |
| 4137 | break; |
| 4138 | default: |
| 4139 | WARN_ON(1); |
| 4140 | /* fall through */ |
| 4141 | case RATE_INFO_BW_20: |
| 4142 | rate_flg = 0; |
| 4143 | break; |
| 4144 | case RATE_INFO_BW_40: |
| 4145 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; |
| 4146 | break; |
| 4147 | case RATE_INFO_BW_80: |
| 4148 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; |
| 4149 | break; |
| 4150 | case RATE_INFO_BW_160: |
| 4151 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; |
| 4152 | break; |
| 4153 | } |
| 4154 | |
| 4155 | if (rate_flg && nla_put_flag(msg, rate_flg)) |
| 4156 | return false; |
| 4157 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4158 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 4159 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 4160 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4161 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 4162 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 4163 | return false; |
| 4164 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 4165 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 4166 | return false; |
| 4167 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 4168 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4169 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 4170 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 4171 | return false; |
| 4172 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4173 | |
| 4174 | nla_nest_end(msg, rate); |
| 4175 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4176 | } |
| 4177 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4178 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 4179 | int id) |
| 4180 | { |
| 4181 | void *attr; |
| 4182 | int i = 0; |
| 4183 | |
| 4184 | if (!mask) |
| 4185 | return true; |
| 4186 | |
| 4187 | attr = nla_nest_start(msg, id); |
| 4188 | if (!attr) |
| 4189 | return false; |
| 4190 | |
| 4191 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 4192 | if (!(mask & BIT(i))) |
| 4193 | continue; |
| 4194 | |
| 4195 | if (nla_put_u8(msg, i, signal[i])) |
| 4196 | return false; |
| 4197 | } |
| 4198 | |
| 4199 | nla_nest_end(msg, attr); |
| 4200 | |
| 4201 | return true; |
| 4202 | } |
| 4203 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4204 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
| 4205 | u32 seq, int flags, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4206 | struct cfg80211_registered_device *rdev, |
| 4207 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 4208 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4209 | { |
| 4210 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4211 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4212 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4213 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4214 | if (!hdr) |
| 4215 | return -1; |
| 4216 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4217 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4218 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 4219 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 4220 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4221 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4222 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 4223 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4224 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4225 | |
| 4226 | #define PUT_SINFO(attr, memb, type) do { \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4227 | BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ |
Mohammed Shafi Shajakhan | 739960f | 2016-04-07 19:59:34 +0530 | [diff] [blame] | 4228 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4229 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
| 4230 | sinfo->memb)) \ |
| 4231 | goto nla_put_failure; \ |
| 4232 | } while (0) |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4233 | #define PUT_SINFO_U64(attr, memb) do { \ |
| 4234 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ |
| 4235 | nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ |
| 4236 | sinfo->memb, NL80211_STA_INFO_PAD)) \ |
| 4237 | goto nla_put_failure; \ |
| 4238 | } while (0) |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4239 | |
| 4240 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); |
| 4241 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); |
| 4242 | |
| 4243 | if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) | |
| 4244 | BIT(NL80211_STA_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4245 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 4246 | (u32)sinfo->rx_bytes)) |
| 4247 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4248 | |
| 4249 | if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) | |
| 4250 | BIT(NL80211_STA_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 4251 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 4252 | (u32)sinfo->tx_bytes)) |
| 4253 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4254 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4255 | PUT_SINFO_U64(RX_BYTES64, rx_bytes); |
| 4256 | PUT_SINFO_U64(TX_BYTES64, tx_bytes); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4257 | PUT_SINFO(LLID, llid, u16); |
| 4258 | PUT_SINFO(PLID, plid, u16); |
| 4259 | PUT_SINFO(PLINK_STATE, plink_state, u8); |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4260 | PUT_SINFO_U64(RX_DURATION, rx_duration); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4261 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4262 | switch (rdev->wiphy.signal_type) { |
| 4263 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4264 | PUT_SINFO(SIGNAL, signal, u8); |
| 4265 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4266 | break; |
| 4267 | default: |
| 4268 | break; |
| 4269 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4270 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4271 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 4272 | sinfo->chain_signal, |
| 4273 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 4274 | goto nla_put_failure; |
| 4275 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4276 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4277 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 4278 | sinfo->chain_signal_avg, |
| 4279 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 4280 | goto nla_put_failure; |
| 4281 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4282 | if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4283 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 4284 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 4285 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4286 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4287 | if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4288 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 4289 | NL80211_STA_INFO_RX_BITRATE)) |
| 4290 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 4291 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4292 | |
| 4293 | PUT_SINFO(RX_PACKETS, rx_packets, u32); |
| 4294 | PUT_SINFO(TX_PACKETS, tx_packets, u32); |
| 4295 | PUT_SINFO(TX_RETRIES, tx_retries, u32); |
| 4296 | PUT_SINFO(TX_FAILED, tx_failed, u32); |
| 4297 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); |
| 4298 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); |
| 4299 | PUT_SINFO(LOCAL_PM, local_pm, u32); |
| 4300 | PUT_SINFO(PEER_PM, peer_pm, u32); |
| 4301 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); |
| 4302 | |
| 4303 | if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) { |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4304 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 4305 | if (!bss_param) |
| 4306 | goto nla_put_failure; |
| 4307 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4308 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 4309 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 4310 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 4311 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 4312 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 4313 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 4314 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 4315 | sinfo->bss_param.dtim_period) || |
| 4316 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 4317 | sinfo->bss_param.beacon_interval)) |
| 4318 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4319 | |
| 4320 | nla_nest_end(msg, bss_param); |
| 4321 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4322 | if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4323 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 4324 | sizeof(struct nl80211_sta_flag_update), |
| 4325 | &sinfo->sta_flags)) |
| 4326 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4327 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4328 | PUT_SINFO_U64(T_OFFSET, t_offset); |
| 4329 | PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); |
| 4330 | PUT_SINFO_U64(BEACON_RX, rx_beacon); |
Johannes Berg | a76b194 | 2014-11-17 14:12:22 +0100 | [diff] [blame] | 4331 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4332 | |
| 4333 | #undef PUT_SINFO |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4334 | #undef PUT_SINFO_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4335 | |
| 4336 | if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) { |
| 4337 | struct nlattr *tidsattr; |
| 4338 | int tid; |
| 4339 | |
| 4340 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); |
| 4341 | if (!tidsattr) |
| 4342 | goto nla_put_failure; |
| 4343 | |
| 4344 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { |
| 4345 | struct cfg80211_tid_stats *tidstats; |
| 4346 | struct nlattr *tidattr; |
| 4347 | |
| 4348 | tidstats = &sinfo->pertid[tid]; |
| 4349 | |
| 4350 | if (!tidstats->filled) |
| 4351 | continue; |
| 4352 | |
| 4353 | tidattr = nla_nest_start(msg, tid + 1); |
| 4354 | if (!tidattr) |
| 4355 | goto nla_put_failure; |
| 4356 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4357 | #define PUT_TIDVAL_U64(attr, memb) do { \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4358 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4359 | nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ |
| 4360 | tidstats->memb, NL80211_TID_STATS_PAD)) \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4361 | goto nla_put_failure; \ |
| 4362 | } while (0) |
| 4363 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4364 | PUT_TIDVAL_U64(RX_MSDU, rx_msdu); |
| 4365 | PUT_TIDVAL_U64(TX_MSDU, tx_msdu); |
| 4366 | PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); |
| 4367 | PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4368 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4369 | #undef PUT_TIDVAL_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4370 | nla_nest_end(msg, tidattr); |
| 4371 | } |
| 4372 | |
| 4373 | nla_nest_end(msg, tidsattr); |
| 4374 | } |
| 4375 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4376 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4377 | |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4378 | if (sinfo->assoc_req_ies_len && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4379 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 4380 | sinfo->assoc_req_ies)) |
| 4381 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 4382 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 4383 | genlmsg_end(msg, hdr); |
| 4384 | return 0; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4385 | |
| 4386 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4387 | genlmsg_cancel(msg, hdr); |
| 4388 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4389 | } |
| 4390 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4391 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4392 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4393 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4394 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4395 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4396 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4397 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4398 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4399 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4400 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4401 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4402 | if (err) |
| 4403 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4404 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4405 | if (!wdev->netdev) { |
| 4406 | err = -EINVAL; |
| 4407 | goto out_err; |
| 4408 | } |
| 4409 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4410 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4411 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4412 | goto out_err; |
| 4413 | } |
| 4414 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4415 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 4416 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4417 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4418 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4419 | if (err == -ENOENT) |
| 4420 | break; |
| 4421 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4422 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4423 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4424 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4425 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4426 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4427 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4428 | &sinfo) < 0) |
| 4429 | goto out; |
| 4430 | |
| 4431 | sta_idx++; |
| 4432 | } |
| 4433 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4434 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4435 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4436 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4437 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4438 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4439 | |
| 4440 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4441 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4442 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4443 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 4444 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4445 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4446 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4447 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4448 | struct sk_buff *msg; |
| 4449 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4450 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4451 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4452 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4453 | |
| 4454 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4455 | return -EINVAL; |
| 4456 | |
| 4457 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4458 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4459 | if (!rdev->ops->get_station) |
| 4460 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4461 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4462 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4463 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4464 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4465 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4466 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4467 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4468 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4469 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4470 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
| 4471 | info->snd_portid, info->snd_seq, 0, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4472 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4473 | nlmsg_free(msg); |
| 4474 | return -ENOBUFS; |
| 4475 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4476 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4477 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4478 | } |
| 4479 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4480 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 4481 | struct station_parameters *params, |
| 4482 | enum cfg80211_station_type statype) |
| 4483 | { |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4484 | if (params->listen_interval != -1 && |
| 4485 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4486 | return -EINVAL; |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4487 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4488 | if (params->support_p2p_ps != -1 && |
| 4489 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
| 4490 | return -EINVAL; |
| 4491 | |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 4492 | if (params->aid && |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4493 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 4494 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4495 | return -EINVAL; |
| 4496 | |
| 4497 | /* When you run into this, adjust the code below for the new flag */ |
| 4498 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4499 | |
| 4500 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4501 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 4502 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4503 | /* |
| 4504 | * No ignoring the TDLS flag here -- the userspace mesh |
| 4505 | * code doesn't have the bug of including TDLS in the |
| 4506 | * mask everywhere. |
| 4507 | */ |
| 4508 | if (params->sta_flags_mask & |
| 4509 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4510 | BIT(NL80211_STA_FLAG_MFP) | |
| 4511 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4512 | return -EINVAL; |
| 4513 | break; |
| 4514 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4515 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4516 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4517 | return -EINVAL; |
| 4518 | /* ignore since it can't change */ |
| 4519 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4520 | break; |
| 4521 | default: |
| 4522 | /* disallow mesh-specific things */ |
| 4523 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 4524 | return -EINVAL; |
| 4525 | if (params->local_pm) |
| 4526 | return -EINVAL; |
| 4527 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4528 | return -EINVAL; |
| 4529 | } |
| 4530 | |
| 4531 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4532 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 4533 | /* TDLS can't be set, ... */ |
| 4534 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 4535 | return -EINVAL; |
| 4536 | /* |
| 4537 | * ... but don't bother the driver with it. This works around |
| 4538 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 4539 | * TLDS_PEER flag in the mask even for AP mode. |
| 4540 | */ |
| 4541 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4542 | } |
| 4543 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4544 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4545 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4546 | /* reject other things that can't change */ |
| 4547 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 4548 | return -EINVAL; |
| 4549 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 4550 | return -EINVAL; |
| 4551 | if (params->supported_rates) |
| 4552 | return -EINVAL; |
| 4553 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 4554 | return -EINVAL; |
| 4555 | } |
| 4556 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4557 | if (statype != CFG80211_STA_AP_CLIENT && |
| 4558 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4559 | if (params->vlan) |
| 4560 | return -EINVAL; |
| 4561 | } |
| 4562 | |
| 4563 | switch (statype) { |
| 4564 | case CFG80211_STA_AP_MLME_CLIENT: |
| 4565 | /* Use this only for authorizing/unauthorizing a station */ |
| 4566 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4567 | return -EOPNOTSUPP; |
| 4568 | break; |
| 4569 | case CFG80211_STA_AP_CLIENT: |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4570 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4571 | /* accept only the listed bits */ |
| 4572 | if (params->sta_flags_mask & |
| 4573 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4574 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4575 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4576 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 4577 | BIT(NL80211_STA_FLAG_WME) | |
| 4578 | BIT(NL80211_STA_FLAG_MFP))) |
| 4579 | return -EINVAL; |
| 4580 | |
| 4581 | /* but authenticated/associated only if driver handles it */ |
| 4582 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4583 | params->sta_flags_mask & |
| 4584 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4585 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4586 | return -EINVAL; |
| 4587 | break; |
| 4588 | case CFG80211_STA_IBSS: |
| 4589 | case CFG80211_STA_AP_STA: |
| 4590 | /* reject any changes other than AUTHORIZED */ |
| 4591 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 4592 | return -EINVAL; |
| 4593 | break; |
| 4594 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4595 | /* reject any changes other than AUTHORIZED or WME */ |
| 4596 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4597 | BIT(NL80211_STA_FLAG_WME))) |
| 4598 | return -EINVAL; |
| 4599 | /* force (at least) rates when authorizing */ |
| 4600 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 4601 | !params->supported_rates) |
| 4602 | return -EINVAL; |
| 4603 | break; |
| 4604 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4605 | /* reject any changes */ |
| 4606 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4607 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4608 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4609 | return -EINVAL; |
| 4610 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4611 | case CFG80211_STA_MESH_PEER_USER: |
Chun-Yeow Yeoh | 4292504 | 2015-04-18 01:30:02 +0800 | [diff] [blame] | 4612 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
| 4613 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4614 | return -EINVAL; |
| 4615 | break; |
| 4616 | } |
| 4617 | |
| 4618 | return 0; |
| 4619 | } |
| 4620 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 4621 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4622 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 4623 | * Get vlan interface making sure it is running and on the right wiphy. |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4624 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4625 | static struct net_device *get_vlan(struct genl_info *info, |
| 4626 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4627 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4628 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4629 | struct net_device *v; |
| 4630 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4631 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4632 | if (!vlanattr) |
| 4633 | return NULL; |
| 4634 | |
| 4635 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 4636 | if (!v) |
| 4637 | return ERR_PTR(-ENODEV); |
| 4638 | |
| 4639 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 4640 | ret = -EINVAL; |
| 4641 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4642 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4643 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4644 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 4645 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4646 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 4647 | ret = -EINVAL; |
| 4648 | goto error; |
| 4649 | } |
| 4650 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4651 | if (!netif_running(v)) { |
| 4652 | ret = -ENETDOWN; |
| 4653 | goto error; |
| 4654 | } |
| 4655 | |
| 4656 | return v; |
| 4657 | error: |
| 4658 | dev_put(v); |
| 4659 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4660 | } |
| 4661 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 4662 | static const struct nla_policy |
| 4663 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4664 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 4665 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 4666 | }; |
| 4667 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4668 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 4669 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4670 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4671 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 4672 | struct nlattr *nla; |
| 4673 | int err; |
| 4674 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4675 | /* parse WME attributes if present */ |
| 4676 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 4677 | return 0; |
| 4678 | |
| 4679 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 4680 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 4681 | nl80211_sta_wme_policy); |
| 4682 | if (err) |
| 4683 | return err; |
| 4684 | |
| 4685 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 4686 | params->uapsd_queues = nla_get_u8( |
| 4687 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 4688 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 4689 | return -EINVAL; |
| 4690 | |
| 4691 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 4692 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 4693 | |
| 4694 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 4695 | return -EINVAL; |
| 4696 | |
| 4697 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 4698 | |
| 4699 | return 0; |
| 4700 | } |
| 4701 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4702 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 4703 | struct station_parameters *params) |
| 4704 | { |
| 4705 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 4706 | params->supported_channels = |
| 4707 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4708 | params->supported_channels_len = |
| 4709 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4710 | /* |
| 4711 | * Need to include at least one (first channel, number of |
| 4712 | * channels) tuple for each subband, and must have proper |
| 4713 | * tuples for the rest of the data as well. |
| 4714 | */ |
| 4715 | if (params->supported_channels_len < 2) |
| 4716 | return -EINVAL; |
| 4717 | if (params->supported_channels_len % 2) |
| 4718 | return -EINVAL; |
| 4719 | } |
| 4720 | |
| 4721 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 4722 | params->supported_oper_classes = |
| 4723 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4724 | params->supported_oper_classes_len = |
| 4725 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4726 | /* |
| 4727 | * The value of the Length field of the Supported Operating |
| 4728 | * Classes element is between 2 and 253. |
| 4729 | */ |
| 4730 | if (params->supported_oper_classes_len < 2 || |
| 4731 | params->supported_oper_classes_len > 253) |
| 4732 | return -EINVAL; |
| 4733 | } |
| 4734 | return 0; |
| 4735 | } |
| 4736 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4737 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4738 | struct station_parameters *params) |
| 4739 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4740 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4741 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4742 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4743 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4744 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4745 | params->ht_capa = |
| 4746 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4747 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4748 | params->vht_capa = |
| 4749 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4750 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4751 | err = nl80211_parse_sta_channel_info(info, params); |
| 4752 | if (err) |
| 4753 | return err; |
| 4754 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4755 | return nl80211_parse_sta_wme(info, params); |
| 4756 | } |
| 4757 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4758 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4759 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4760 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4761 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4762 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4763 | u8 *mac_addr; |
| 4764 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4765 | |
| 4766 | memset(¶ms, 0, sizeof(params)); |
| 4767 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4768 | if (!rdev->ops->change_station) |
| 4769 | return -EOPNOTSUPP; |
| 4770 | |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4771 | /* |
| 4772 | * AID and listen_interval properties can be set only for unassociated |
| 4773 | * station. Include these parameters here and will check them in |
| 4774 | * cfg80211_check_station_change(). |
| 4775 | */ |
Ayala Beker | a9bc31e | 2015-11-26 16:26:12 +0100 | [diff] [blame] | 4776 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4777 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4778 | |
| 4779 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4780 | params.listen_interval = |
| 4781 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 4782 | else |
| 4783 | params.listen_interval = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4784 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4785 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
| 4786 | u8 tmp; |
| 4787 | |
| 4788 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 4789 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) |
| 4790 | return -EINVAL; |
| 4791 | |
| 4792 | params.support_p2p_ps = tmp; |
| 4793 | } else { |
| 4794 | params.support_p2p_ps = -1; |
| 4795 | } |
| 4796 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4797 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4798 | return -EINVAL; |
| 4799 | |
| 4800 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4801 | |
| 4802 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4803 | params.supported_rates = |
| 4804 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4805 | params.supported_rates_len = |
| 4806 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4807 | } |
| 4808 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4809 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4810 | params.capability = |
| 4811 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4812 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4813 | } |
| 4814 | |
| 4815 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4816 | params.ext_capab = |
| 4817 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4818 | params.ext_capab_len = |
| 4819 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4820 | } |
| 4821 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4822 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4823 | return -EINVAL; |
| 4824 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4825 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4826 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4827 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4828 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4829 | return -EINVAL; |
| 4830 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4831 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4832 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4833 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4834 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4835 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4836 | return -EINVAL; |
Masashi Honma | 7d27a0b | 2016-07-01 10:19:34 +0900 | [diff] [blame] | 4837 | if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) { |
| 4838 | params.peer_aid = nla_get_u16( |
| 4839 | info->attrs[NL80211_ATTR_MESH_PEER_AID]); |
| 4840 | if (params.peer_aid > IEEE80211_MAX_AID) |
| 4841 | return -EINVAL; |
| 4842 | } |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4843 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4844 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4845 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4846 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4847 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4848 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4849 | |
| 4850 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4851 | pm > NL80211_MESH_POWER_MAX) |
| 4852 | return -EINVAL; |
| 4853 | |
| 4854 | params.local_pm = pm; |
| 4855 | } |
| 4856 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4857 | /* Include parameters for TDLS peer (will check later) */ |
| 4858 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4859 | if (err) |
| 4860 | return err; |
| 4861 | |
| 4862 | params.vlan = get_vlan(info, rdev); |
| 4863 | if (IS_ERR(params.vlan)) |
| 4864 | return PTR_ERR(params.vlan); |
| 4865 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4866 | switch (dev->ieee80211_ptr->iftype) { |
| 4867 | case NL80211_IFTYPE_AP: |
| 4868 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4869 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4870 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4871 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4872 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4873 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4874 | break; |
| 4875 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4876 | err = -EOPNOTSUPP; |
| 4877 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4878 | } |
| 4879 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4880 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4881 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4882 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4883 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4884 | if (params.vlan) |
| 4885 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4886 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4887 | return err; |
| 4888 | } |
| 4889 | |
| 4890 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4891 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4892 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4893 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4894 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4895 | struct station_parameters params; |
| 4896 | u8 *mac_addr = NULL; |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 4897 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4898 | BIT(NL80211_STA_FLAG_ASSOCIATED); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4899 | |
| 4900 | memset(¶ms, 0, sizeof(params)); |
| 4901 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4902 | if (!rdev->ops->add_station) |
| 4903 | return -EOPNOTSUPP; |
| 4904 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4905 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4906 | return -EINVAL; |
| 4907 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4908 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4909 | return -EINVAL; |
| 4910 | |
| 4911 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4912 | return -EINVAL; |
| 4913 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4914 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4915 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4916 | return -EINVAL; |
| 4917 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4918 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4919 | params.supported_rates = |
| 4920 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4921 | params.supported_rates_len = |
| 4922 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4923 | params.listen_interval = |
| 4924 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4925 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4926 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
| 4927 | u8 tmp; |
| 4928 | |
| 4929 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 4930 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) |
| 4931 | return -EINVAL; |
| 4932 | |
| 4933 | params.support_p2p_ps = tmp; |
| 4934 | } else { |
| 4935 | /* |
| 4936 | * if not specified, assume it's supported for P2P GO interface, |
| 4937 | * and is NOT supported for AP interface |
| 4938 | */ |
| 4939 | params.support_p2p_ps = |
| 4940 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; |
| 4941 | } |
| 4942 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4943 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4944 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4945 | else |
| 4946 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4947 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4948 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4949 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4950 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4951 | params.capability = |
| 4952 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4953 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4954 | } |
| 4955 | |
| 4956 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4957 | params.ext_capab = |
| 4958 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4959 | params.ext_capab_len = |
| 4960 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4961 | } |
| 4962 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4963 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4964 | params.ht_capa = |
| 4965 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4966 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4967 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4968 | params.vht_capa = |
| 4969 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4970 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4971 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4972 | params.opmode_notif_used = true; |
| 4973 | params.opmode_notif = |
| 4974 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4975 | } |
| 4976 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4977 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4978 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4979 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4980 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4981 | return -EINVAL; |
| 4982 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4983 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4984 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4985 | if (err) |
| 4986 | return err; |
| 4987 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4988 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4989 | if (err) |
| 4990 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4991 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4992 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4993 | return -EINVAL; |
| 4994 | |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 4995 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
| 4996 | * as userspace might just pass through the capabilities from the IEs |
| 4997 | * directly, rather than enforcing this restriction and returning an |
| 4998 | * error in this case. |
| 4999 | */ |
| 5000 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { |
| 5001 | params.ht_capa = NULL; |
| 5002 | params.vht_capa = NULL; |
| 5003 | } |
| 5004 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5005 | /* When you run into this, adjust the code below for the new flag */ |
| 5006 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 5007 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5008 | switch (dev->ieee80211_ptr->iftype) { |
| 5009 | case NL80211_IFTYPE_AP: |
| 5010 | case NL80211_IFTYPE_AP_VLAN: |
| 5011 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5012 | /* ignore WME attributes if iface/sta is not capable */ |
| 5013 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 5014 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 5015 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 5016 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5017 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5018 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 5019 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 5020 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5021 | /* but don't bother the driver with it */ |
| 5022 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 5023 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5024 | /* allow authenticated/associated only if driver handles it */ |
| 5025 | if (!(rdev->wiphy.features & |
| 5026 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 5027 | params.sta_flags_mask & auth_assoc) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5028 | return -EINVAL; |
| 5029 | |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 5030 | /* Older userspace, or userspace wanting to be compatible with |
| 5031 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth |
| 5032 | * and assoc flags in the mask, but assumes the station will be |
| 5033 | * added as associated anyway since this was the required driver |
| 5034 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was |
| 5035 | * introduced. |
| 5036 | * In order to not bother drivers with this quirk in the API |
| 5037 | * set the flags in both the mask and set for new stations in |
| 5038 | * this case. |
| 5039 | */ |
| 5040 | if (!(params.sta_flags_mask & auth_assoc)) { |
| 5041 | params.sta_flags_mask |= auth_assoc; |
| 5042 | params.sta_flags_set |= auth_assoc; |
| 5043 | } |
| 5044 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5045 | /* must be last in here for error handling */ |
| 5046 | params.vlan = get_vlan(info, rdev); |
| 5047 | if (IS_ERR(params.vlan)) |
| 5048 | return PTR_ERR(params.vlan); |
| 5049 | break; |
| 5050 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5051 | /* ignore uAPSD data */ |
| 5052 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 5053 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5054 | /* associated is disallowed */ |
| 5055 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 5056 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5057 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5058 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 5059 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 5060 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5061 | break; |
| 5062 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 5063 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5064 | /* ignore uAPSD data */ |
| 5065 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 5066 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5067 | /* these are disallowed */ |
| 5068 | if (params.sta_flags_mask & |
| 5069 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 5070 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5071 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5072 | /* Only TDLS peers can be added */ |
| 5073 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 5074 | return -EINVAL; |
| 5075 | /* Can only add if TDLS ... */ |
| 5076 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 5077 | return -EOPNOTSUPP; |
| 5078 | /* ... with external setup is supported */ |
| 5079 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 5080 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5081 | /* |
| 5082 | * Older wpa_supplicant versions always mark the TDLS peer |
| 5083 | * as authorized, but it shouldn't yet be. |
| 5084 | */ |
| 5085 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5086 | break; |
| 5087 | default: |
| 5088 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 5089 | } |
| 5090 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5091 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5092 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5093 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5094 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5095 | if (params.vlan) |
| 5096 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5097 | return err; |
| 5098 | } |
| 5099 | |
| 5100 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 5101 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5102 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5103 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5104 | struct station_del_parameters params; |
| 5105 | |
| 5106 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5107 | |
| 5108 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5109 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5110 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 5111 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 5112 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5113 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5114 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5115 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 5116 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5117 | if (!rdev->ops->del_station) |
| 5118 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5119 | |
Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 5120 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 5121 | params.subtype = |
| 5122 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 5123 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 5124 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 5125 | return -EINVAL; |
| 5126 | } else { |
| 5127 | /* Default to Deauthentication frame */ |
| 5128 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 5129 | } |
| 5130 | |
| 5131 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 5132 | params.reason_code = |
| 5133 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5134 | if (params.reason_code == 0) |
| 5135 | return -EINVAL; /* 0 is reserved */ |
| 5136 | } else { |
| 5137 | /* Default to reason code 2 */ |
| 5138 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 5139 | } |
| 5140 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5141 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5142 | } |
| 5143 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5144 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5145 | int flags, struct net_device *dev, |
| 5146 | u8 *dst, u8 *next_hop, |
| 5147 | struct mpath_info *pinfo) |
| 5148 | { |
| 5149 | void *hdr; |
| 5150 | struct nlattr *pinfoattr; |
| 5151 | |
Henning Rogge | 1ef4c85 | 2014-11-04 16:14:58 +0100 | [diff] [blame] | 5152 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5153 | if (!hdr) |
| 5154 | return -1; |
| 5155 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5156 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5157 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 5158 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 5159 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 5160 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 5161 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5162 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 5163 | if (!pinfoattr) |
| 5164 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5165 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 5166 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 5167 | pinfo->frame_qlen)) |
| 5168 | goto nla_put_failure; |
| 5169 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 5170 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 5171 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 5172 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 5173 | pinfo->metric)) || |
| 5174 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 5175 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 5176 | pinfo->exptime)) || |
| 5177 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 5178 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 5179 | pinfo->flags)) || |
| 5180 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 5181 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 5182 | pinfo->discovery_timeout)) || |
| 5183 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 5184 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 5185 | pinfo->discovery_retries))) |
| 5186 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5187 | |
| 5188 | nla_nest_end(msg, pinfoattr); |
| 5189 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 5190 | genlmsg_end(msg, hdr); |
| 5191 | return 0; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5192 | |
| 5193 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 5194 | genlmsg_cancel(msg, hdr); |
| 5195 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5196 | } |
| 5197 | |
| 5198 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5199 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5200 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5201 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5202 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5203 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5204 | u8 dst[ETH_ALEN]; |
| 5205 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5206 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5207 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5208 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5209 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5210 | if (err) |
| 5211 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5212 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5213 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5214 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5215 | goto out_err; |
| 5216 | } |
| 5217 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5218 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5219 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 5220 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5221 | } |
| 5222 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5223 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5224 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5225 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5226 | if (err == -ENOENT) |
| 5227 | break; |
| 5228 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5229 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5230 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5231 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5232 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5233 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5234 | &pinfo) < 0) |
| 5235 | goto out; |
| 5236 | |
| 5237 | path_idx++; |
| 5238 | } |
| 5239 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5240 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5241 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5242 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5243 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5244 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5245 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5246 | } |
| 5247 | |
| 5248 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5249 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5250 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5251 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5252 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5253 | struct mpath_info pinfo; |
| 5254 | struct sk_buff *msg; |
| 5255 | u8 *dst = NULL; |
| 5256 | u8 next_hop[ETH_ALEN]; |
| 5257 | |
| 5258 | memset(&pinfo, 0, sizeof(pinfo)); |
| 5259 | |
| 5260 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5261 | return -EINVAL; |
| 5262 | |
| 5263 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5264 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5265 | if (!rdev->ops->get_mpath) |
| 5266 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5267 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5268 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5269 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5270 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5271 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5272 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5273 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5274 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5275 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5276 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5277 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5278 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5279 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5280 | dev, dst, next_hop, &pinfo) < 0) { |
| 5281 | nlmsg_free(msg); |
| 5282 | return -ENOBUFS; |
| 5283 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5284 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5285 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5286 | } |
| 5287 | |
| 5288 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5289 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5290 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5291 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5292 | u8 *dst = NULL; |
| 5293 | u8 *next_hop = NULL; |
| 5294 | |
| 5295 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5296 | return -EINVAL; |
| 5297 | |
| 5298 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 5299 | return -EINVAL; |
| 5300 | |
| 5301 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5302 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 5303 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5304 | if (!rdev->ops->change_mpath) |
| 5305 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5306 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5307 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5308 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5309 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5310 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5311 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5312 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5313 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5314 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5315 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5316 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5317 | u8 *dst = NULL; |
| 5318 | u8 *next_hop = NULL; |
| 5319 | |
| 5320 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5321 | return -EINVAL; |
| 5322 | |
| 5323 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 5324 | return -EINVAL; |
| 5325 | |
| 5326 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5327 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 5328 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5329 | if (!rdev->ops->add_mpath) |
| 5330 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5331 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5332 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5333 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5334 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5335 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5336 | } |
| 5337 | |
| 5338 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5339 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5340 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5341 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5342 | u8 *dst = NULL; |
| 5343 | |
| 5344 | if (info->attrs[NL80211_ATTR_MAC]) |
| 5345 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5346 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5347 | if (!rdev->ops->del_mpath) |
| 5348 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5349 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5350 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5351 | } |
| 5352 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5353 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 5354 | { |
| 5355 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5356 | int err; |
| 5357 | struct net_device *dev = info->user_ptr[1]; |
| 5358 | struct mpath_info pinfo; |
| 5359 | struct sk_buff *msg; |
| 5360 | u8 *dst = NULL; |
| 5361 | u8 mpp[ETH_ALEN]; |
| 5362 | |
| 5363 | memset(&pinfo, 0, sizeof(pinfo)); |
| 5364 | |
| 5365 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5366 | return -EINVAL; |
| 5367 | |
| 5368 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5369 | |
| 5370 | if (!rdev->ops->get_mpp) |
| 5371 | return -EOPNOTSUPP; |
| 5372 | |
| 5373 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5374 | return -EOPNOTSUPP; |
| 5375 | |
| 5376 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 5377 | if (err) |
| 5378 | return err; |
| 5379 | |
| 5380 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5381 | if (!msg) |
| 5382 | return -ENOMEM; |
| 5383 | |
| 5384 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 5385 | dev, dst, mpp, &pinfo) < 0) { |
| 5386 | nlmsg_free(msg); |
| 5387 | return -ENOBUFS; |
| 5388 | } |
| 5389 | |
| 5390 | return genlmsg_reply(msg, info); |
| 5391 | } |
| 5392 | |
| 5393 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 5394 | struct netlink_callback *cb) |
| 5395 | { |
| 5396 | struct mpath_info pinfo; |
| 5397 | struct cfg80211_registered_device *rdev; |
| 5398 | struct wireless_dev *wdev; |
| 5399 | u8 dst[ETH_ALEN]; |
| 5400 | u8 mpp[ETH_ALEN]; |
| 5401 | int path_idx = cb->args[2]; |
| 5402 | int err; |
| 5403 | |
| 5404 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
| 5405 | if (err) |
| 5406 | return err; |
| 5407 | |
| 5408 | if (!rdev->ops->dump_mpp) { |
| 5409 | err = -EOPNOTSUPP; |
| 5410 | goto out_err; |
| 5411 | } |
| 5412 | |
| 5413 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 5414 | err = -EOPNOTSUPP; |
| 5415 | goto out_err; |
| 5416 | } |
| 5417 | |
| 5418 | while (1) { |
| 5419 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 5420 | mpp, &pinfo); |
| 5421 | if (err == -ENOENT) |
| 5422 | break; |
| 5423 | if (err) |
| 5424 | goto out_err; |
| 5425 | |
| 5426 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 5427 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5428 | wdev->netdev, dst, mpp, |
| 5429 | &pinfo) < 0) |
| 5430 | goto out; |
| 5431 | |
| 5432 | path_idx++; |
| 5433 | } |
| 5434 | |
| 5435 | out: |
| 5436 | cb->args[2] = path_idx; |
| 5437 | err = skb->len; |
| 5438 | out_err: |
| 5439 | nl80211_finish_wdev_dump(rdev); |
| 5440 | return err; |
| 5441 | } |
| 5442 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5443 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 5444 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5445 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5446 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5447 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5448 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5449 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5450 | |
| 5451 | memset(¶ms, 0, sizeof(params)); |
| 5452 | /* default to not changing parameters */ |
| 5453 | params.use_cts_prot = -1; |
| 5454 | params.use_short_preamble = -1; |
| 5455 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 5456 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 5457 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5458 | params.p2p_ctwindow = -1; |
| 5459 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5460 | |
| 5461 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 5462 | params.use_cts_prot = |
| 5463 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 5464 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 5465 | params.use_short_preamble = |
| 5466 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 5467 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 5468 | params.use_short_slot_time = |
| 5469 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 5470 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5471 | params.basic_rates = |
| 5472 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5473 | params.basic_rates_len = |
| 5474 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5475 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 5476 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 5477 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 5478 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 5479 | params.ht_opmode = |
| 5480 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5481 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5482 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 5483 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5484 | return -EINVAL; |
| 5485 | params.p2p_ctwindow = |
| 5486 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 5487 | if (params.p2p_ctwindow < 0) |
| 5488 | return -EINVAL; |
| 5489 | if (params.p2p_ctwindow != 0 && |
| 5490 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 5491 | return -EINVAL; |
| 5492 | } |
| 5493 | |
| 5494 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 5495 | u8 tmp; |
| 5496 | |
| 5497 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5498 | return -EINVAL; |
| 5499 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 5500 | if (tmp > 1) |
| 5501 | return -EINVAL; |
| 5502 | params.p2p_opp_ps = tmp; |
| 5503 | if (params.p2p_opp_ps && |
| 5504 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 5505 | return -EINVAL; |
| 5506 | } |
| 5507 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5508 | if (!rdev->ops->change_bss) |
| 5509 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5510 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5511 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5512 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5513 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5514 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5515 | wdev_lock(wdev); |
| 5516 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 5517 | wdev_unlock(wdev); |
| 5518 | |
| 5519 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5520 | } |
| 5521 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5522 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5523 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5524 | char *data = NULL; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5525 | bool is_indoor; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5526 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5527 | u32 owner_nlportid; |
| 5528 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 5529 | /* |
| 5530 | * You should only get this when cfg80211 hasn't yet initialized |
| 5531 | * completely when built-in to the kernel right between the time |
| 5532 | * window between nl80211_init() and regulatory_init(), if that is |
| 5533 | * even possible. |
| 5534 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5535 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 5536 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 5537 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5538 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 5539 | user_reg_hint_type = |
| 5540 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 5541 | else |
| 5542 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 5543 | |
| 5544 | switch (user_reg_hint_type) { |
| 5545 | case NL80211_USER_REG_HINT_USER: |
| 5546 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 5547 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5548 | return -EINVAL; |
| 5549 | |
| 5550 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5551 | return regulatory_hint_user(data, user_reg_hint_type); |
| 5552 | case NL80211_USER_REG_HINT_INDOOR: |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5553 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 5554 | owner_nlportid = info->snd_portid; |
| 5555 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; |
| 5556 | } else { |
| 5557 | owner_nlportid = 0; |
| 5558 | is_indoor = true; |
| 5559 | } |
| 5560 | |
| 5561 | return regulatory_hint_indoor(is_indoor, owner_nlportid); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5562 | default: |
| 5563 | return -EINVAL; |
| 5564 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5565 | } |
| 5566 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5567 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5568 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5569 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5570 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5571 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5572 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5573 | struct mesh_config cur_params; |
| 5574 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5575 | void *hdr; |
| 5576 | struct nlattr *pinfoattr; |
| 5577 | struct sk_buff *msg; |
| 5578 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5579 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5580 | return -EOPNOTSUPP; |
| 5581 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5582 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5583 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 5584 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5585 | wdev_lock(wdev); |
| 5586 | /* If not connected, get default parameters */ |
| 5587 | if (!wdev->mesh_id_len) |
| 5588 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 5589 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5590 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5591 | wdev_unlock(wdev); |
| 5592 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5593 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5594 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5595 | |
| 5596 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5597 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5598 | if (!msg) |
| 5599 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5600 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5601 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5602 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5603 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5604 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5605 | if (!pinfoattr) |
| 5606 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5607 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5608 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 5609 | cur_params.dot11MeshRetryTimeout) || |
| 5610 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 5611 | cur_params.dot11MeshConfirmTimeout) || |
| 5612 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 5613 | cur_params.dot11MeshHoldingTimeout) || |
| 5614 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 5615 | cur_params.dot11MeshMaxPeerLinks) || |
| 5616 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 5617 | cur_params.dot11MeshMaxRetries) || |
| 5618 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 5619 | cur_params.dot11MeshTTL) || |
| 5620 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 5621 | cur_params.element_ttl) || |
| 5622 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 5623 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 5624 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 5625 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5626 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 5627 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 5628 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 5629 | cur_params.path_refresh_time) || |
| 5630 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 5631 | cur_params.min_discovery_timeout) || |
| 5632 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 5633 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 5634 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 5635 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 5636 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 5637 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 5638 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5639 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 5640 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5641 | cur_params.dot11MeshHWMPRootMode) || |
| 5642 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 5643 | cur_params.dot11MeshHWMPRannInterval) || |
| 5644 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 5645 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 5646 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 5647 | cur_params.dot11MeshForwarding) || |
| 5648 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 5649 | cur_params.rssi_threshold) || |
| 5650 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5651 | cur_params.ht_opmode) || |
| 5652 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5653 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 5654 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5655 | cur_params.dot11MeshHWMProotInterval) || |
| 5656 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5657 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 5658 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 5659 | cur_params.power_mode) || |
| 5660 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5661 | cur_params.dot11MeshAwakeWindowDuration) || |
| 5662 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5663 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5664 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5665 | nla_nest_end(msg, pinfoattr); |
| 5666 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5667 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5668 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5669 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5670 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5671 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5672 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5673 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5674 | } |
| 5675 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5676 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5677 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 5678 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 5679 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 5680 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 5681 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 5682 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 5683 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5684 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5685 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5686 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 5687 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 5688 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 5689 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 5690 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5691 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5692 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 5693 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 5694 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 5695 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 5696 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5697 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 5698 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5699 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 5700 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5701 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5702 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 5703 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5704 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5705 | }; |
| 5706 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5707 | static const struct nla_policy |
| 5708 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5709 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5710 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 5711 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 5712 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5713 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5714 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5715 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5716 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5717 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5718 | }; |
| 5719 | |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5720 | static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out) |
| 5721 | { |
| 5722 | u8 val = nla_get_u8(nla); |
| 5723 | if (val < min || val > max) |
| 5724 | return -EINVAL; |
| 5725 | *out = val; |
| 5726 | return 0; |
| 5727 | } |
| 5728 | |
| 5729 | static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out) |
| 5730 | { |
| 5731 | u8 val = nla_get_u8(nla); |
| 5732 | if (val < min || val > max) |
| 5733 | return -EINVAL; |
| 5734 | *out = val; |
| 5735 | return 0; |
| 5736 | } |
| 5737 | |
| 5738 | static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out) |
| 5739 | { |
| 5740 | u16 val = nla_get_u16(nla); |
| 5741 | if (val < min || val > max) |
| 5742 | return -EINVAL; |
| 5743 | *out = val; |
| 5744 | return 0; |
| 5745 | } |
| 5746 | |
| 5747 | static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out) |
| 5748 | { |
| 5749 | u32 val = nla_get_u32(nla); |
| 5750 | if (val < min || val > max) |
| 5751 | return -EINVAL; |
| 5752 | *out = val; |
| 5753 | return 0; |
| 5754 | } |
| 5755 | |
| 5756 | static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out) |
| 5757 | { |
| 5758 | s32 val = nla_get_s32(nla); |
| 5759 | if (val < min || val > max) |
| 5760 | return -EINVAL; |
| 5761 | *out = val; |
| 5762 | return 0; |
| 5763 | } |
| 5764 | |
Johannes Berg | ff9a71a | 2016-08-11 14:59:53 +0200 | [diff] [blame] | 5765 | static int nl80211_check_power_mode(const struct nlattr *nla, |
| 5766 | enum nl80211_mesh_power_mode min, |
| 5767 | enum nl80211_mesh_power_mode max, |
| 5768 | enum nl80211_mesh_power_mode *out) |
| 5769 | { |
| 5770 | u32 val = nla_get_u32(nla); |
| 5771 | if (val < min || val > max) |
| 5772 | return -EINVAL; |
| 5773 | *out = val; |
| 5774 | return 0; |
| 5775 | } |
| 5776 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5777 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5778 | struct mesh_config *cfg, |
| 5779 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5780 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5781 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5782 | u32 mask = 0; |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 5783 | u16 ht_opmode; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5784 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5785 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 5786 | do { \ |
| 5787 | if (tb[attr]) { \ |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5788 | if (fn(tb[attr], min, max, &cfg->param)) \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5789 | return -EINVAL; \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5790 | mask |= (1 << (attr - 1)); \ |
| 5791 | } \ |
| 5792 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5793 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5794 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5795 | return -EINVAL; |
| 5796 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5797 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5798 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5799 | return -EINVAL; |
| 5800 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5801 | /* This makes sure that there aren't more than 32 mesh config |
| 5802 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 5803 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 5804 | |
| 5805 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5806 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5807 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5808 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5809 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5810 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5811 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5812 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5813 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5814 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5815 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5816 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5817 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5818 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5819 | mask, NL80211_MESHCONF_MAX_RETRIES, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5820 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5821 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5822 | mask, NL80211_MESHCONF_TTL, nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5823 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5824 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5825 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5826 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5827 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5828 | nl80211_check_bool); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5829 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 5830 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5831 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5832 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5833 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5834 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5835 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5836 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5837 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5838 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5839 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5840 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5841 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5842 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 5843 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5844 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5845 | nl80211_check_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5846 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5847 | 1, 65535, mask, |
| 5848 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5849 | nl80211_check_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5850 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5851 | 1, 65535, mask, |
| 5852 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5853 | nl80211_check_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5854 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5855 | dot11MeshHWMPnetDiameterTraversalTime, |
| 5856 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5857 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5858 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5859 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 5860 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5861 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5862 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 5863 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5864 | nl80211_check_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 5865 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5866 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 5867 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5868 | nl80211_check_bool); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5869 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5870 | mask, NL80211_MESHCONF_FORWARDING, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5871 | nl80211_check_bool); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5872 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5873 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5874 | nl80211_check_s32); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 5875 | /* |
| 5876 | * Check HT operation mode based on |
| 5877 | * IEEE 802.11 2012 8.4.2.59 HT Operation element. |
| 5878 | */ |
| 5879 | if (tb[NL80211_MESHCONF_HT_OPMODE]) { |
| 5880 | ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); |
| 5881 | |
| 5882 | if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | |
| 5883 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | |
| 5884 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 5885 | return -EINVAL; |
| 5886 | |
| 5887 | if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) && |
| 5888 | (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 5889 | return -EINVAL; |
| 5890 | |
| 5891 | switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) { |
| 5892 | case IEEE80211_HT_OP_MODE_PROTECTION_NONE: |
| 5893 | case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ: |
| 5894 | if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT) |
| 5895 | return -EINVAL; |
| 5896 | break; |
| 5897 | case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER: |
| 5898 | case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED: |
| 5899 | if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 5900 | return -EINVAL; |
| 5901 | break; |
| 5902 | } |
| 5903 | cfg->ht_opmode = ht_opmode; |
| 5904 | } |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5905 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5906 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5907 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5908 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5909 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5910 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5911 | nl80211_check_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5912 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5913 | dot11MeshHWMPconfirmationInterval, |
| 5914 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5915 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5916 | nl80211_check_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5917 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 5918 | NL80211_MESH_POWER_ACTIVE, |
| 5919 | NL80211_MESH_POWER_MAX, |
| 5920 | mask, NL80211_MESHCONF_POWER_MODE, |
Johannes Berg | ff9a71a | 2016-08-11 14:59:53 +0200 | [diff] [blame] | 5921 | nl80211_check_power_mode); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5922 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 5923 | 0, 65535, mask, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5924 | NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16); |
Masashi Honma | 31f909a | 2015-02-24 22:42:16 +0900 | [diff] [blame] | 5925 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5926 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5927 | nl80211_check_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5928 | if (mask_out) |
| 5929 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5930 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5931 | return 0; |
| 5932 | |
| 5933 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 5934 | } |
| 5935 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5936 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 5937 | struct mesh_setup *setup) |
| 5938 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5939 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5940 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 5941 | |
| 5942 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 5943 | return -EINVAL; |
| 5944 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 5945 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 5946 | nl80211_mesh_setup_params_policy)) |
| 5947 | return -EINVAL; |
| 5948 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5949 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 5950 | setup->sync_method = |
| 5951 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 5952 | IEEE80211_SYNC_METHOD_VENDOR : |
| 5953 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 5954 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5955 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 5956 | setup->path_sel_proto = |
| 5957 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 5958 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 5959 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 5960 | |
| 5961 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 5962 | setup->path_metric = |
| 5963 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 5964 | IEEE80211_PATH_METRIC_VENDOR : |
| 5965 | IEEE80211_PATH_METRIC_AIRTIME; |
| 5966 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5967 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5968 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5969 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5970 | if (!is_valid_ie_attr(ieattr)) |
| 5971 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5972 | setup->ie = nla_data(ieattr); |
| 5973 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5974 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5975 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 5976 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 5977 | return -EINVAL; |
| 5978 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5979 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 5980 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5981 | if (setup->is_secure) |
| 5982 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5983 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5984 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 5985 | if (!setup->user_mpm) |
| 5986 | return -EINVAL; |
| 5987 | setup->auth_id = |
| 5988 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 5989 | } |
| 5990 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5991 | return 0; |
| 5992 | } |
| 5993 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5994 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5995 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5996 | { |
| 5997 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5998 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5999 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6000 | struct mesh_config cfg; |
| 6001 | u32 mask; |
| 6002 | int err; |
| 6003 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6004 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6005 | return -EOPNOTSUPP; |
| 6006 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6007 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6008 | return -EOPNOTSUPP; |
| 6009 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6010 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6011 | if (err) |
| 6012 | return err; |
| 6013 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6014 | wdev_lock(wdev); |
| 6015 | if (!wdev->mesh_id_len) |
| 6016 | err = -ENOLINK; |
| 6017 | |
| 6018 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6019 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6020 | |
| 6021 | wdev_unlock(wdev); |
| 6022 | |
| 6023 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6024 | } |
| 6025 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6026 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
| 6027 | struct sk_buff *msg) |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6028 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6029 | struct nlattr *nl_reg_rules; |
| 6030 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6031 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6032 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 6033 | (regdom->dfs_region && |
| 6034 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6035 | goto nla_put_failure; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6036 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6037 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 6038 | if (!nl_reg_rules) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6039 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6040 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6041 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6042 | struct nlattr *nl_reg_rule; |
| 6043 | const struct ieee80211_reg_rule *reg_rule; |
| 6044 | const struct ieee80211_freq_range *freq_range; |
| 6045 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6046 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6047 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6048 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6049 | freq_range = ®_rule->freq_range; |
| 6050 | power_rule = ®_rule->power_rule; |
| 6051 | |
| 6052 | nl_reg_rule = nla_nest_start(msg, i); |
| 6053 | if (!nl_reg_rule) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6054 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6055 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6056 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 6057 | if (!max_bandwidth_khz) |
| 6058 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 6059 | reg_rule); |
| 6060 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6061 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 6062 | reg_rule->flags) || |
| 6063 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 6064 | freq_range->start_freq_khz) || |
| 6065 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 6066 | freq_range->end_freq_khz) || |
| 6067 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6068 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6069 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 6070 | power_rule->max_antenna_gain) || |
| 6071 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 6072 | power_rule->max_eirp) || |
| 6073 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 6074 | reg_rule->dfs_cac_ms)) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6075 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6076 | |
| 6077 | nla_nest_end(msg, nl_reg_rule); |
| 6078 | } |
| 6079 | |
| 6080 | nla_nest_end(msg, nl_reg_rules); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6081 | return 0; |
| 6082 | |
| 6083 | nla_put_failure: |
| 6084 | return -EMSGSIZE; |
| 6085 | } |
| 6086 | |
| 6087 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) |
| 6088 | { |
| 6089 | const struct ieee80211_regdomain *regdom = NULL; |
| 6090 | struct cfg80211_registered_device *rdev; |
| 6091 | struct wiphy *wiphy = NULL; |
| 6092 | struct sk_buff *msg; |
| 6093 | void *hdr; |
| 6094 | |
| 6095 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6096 | if (!msg) |
| 6097 | return -ENOBUFS; |
| 6098 | |
| 6099 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 6100 | NL80211_CMD_GET_REG); |
| 6101 | if (!hdr) |
| 6102 | goto put_failure; |
| 6103 | |
| 6104 | if (info->attrs[NL80211_ATTR_WIPHY]) { |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6105 | bool self_managed; |
| 6106 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6107 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
| 6108 | if (IS_ERR(rdev)) { |
| 6109 | nlmsg_free(msg); |
| 6110 | return PTR_ERR(rdev); |
| 6111 | } |
| 6112 | |
| 6113 | wiphy = &rdev->wiphy; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6114 | self_managed = wiphy->regulatory_flags & |
| 6115 | REGULATORY_WIPHY_SELF_MANAGED; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6116 | regdom = get_wiphy_regdom(wiphy); |
| 6117 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6118 | /* a self-managed-reg device must have a private regdom */ |
| 6119 | if (WARN_ON(!regdom && self_managed)) { |
| 6120 | nlmsg_free(msg); |
| 6121 | return -EINVAL; |
| 6122 | } |
| 6123 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6124 | if (regdom && |
| 6125 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 6126 | goto nla_put_failure; |
| 6127 | } |
| 6128 | |
| 6129 | if (!wiphy && reg_last_request_cell_base() && |
| 6130 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 6131 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 6132 | goto nla_put_failure; |
| 6133 | |
| 6134 | rcu_read_lock(); |
| 6135 | |
| 6136 | if (!regdom) |
| 6137 | regdom = rcu_dereference(cfg80211_regdomain); |
| 6138 | |
| 6139 | if (nl80211_put_regdom(regdom, msg)) |
| 6140 | goto nla_put_failure_rcu; |
| 6141 | |
| 6142 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6143 | |
| 6144 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6145 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6146 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6147 | nla_put_failure_rcu: |
| 6148 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6149 | nla_put_failure: |
| 6150 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 6151 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 6152 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6153 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6154 | } |
| 6155 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6156 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
| 6157 | u32 seq, int flags, struct wiphy *wiphy, |
| 6158 | const struct ieee80211_regdomain *regdom) |
| 6159 | { |
| 6160 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
| 6161 | NL80211_CMD_GET_REG); |
| 6162 | |
| 6163 | if (!hdr) |
| 6164 | return -1; |
| 6165 | |
| 6166 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 6167 | |
| 6168 | if (nl80211_put_regdom(regdom, msg)) |
| 6169 | goto nla_put_failure; |
| 6170 | |
| 6171 | if (!wiphy && reg_last_request_cell_base() && |
| 6172 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 6173 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 6174 | goto nla_put_failure; |
| 6175 | |
| 6176 | if (wiphy && |
| 6177 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 6178 | goto nla_put_failure; |
| 6179 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6180 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 6181 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 6182 | goto nla_put_failure; |
| 6183 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 6184 | genlmsg_end(msg, hdr); |
| 6185 | return 0; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6186 | |
| 6187 | nla_put_failure: |
| 6188 | genlmsg_cancel(msg, hdr); |
| 6189 | return -EMSGSIZE; |
| 6190 | } |
| 6191 | |
| 6192 | static int nl80211_get_reg_dump(struct sk_buff *skb, |
| 6193 | struct netlink_callback *cb) |
| 6194 | { |
| 6195 | const struct ieee80211_regdomain *regdom = NULL; |
| 6196 | struct cfg80211_registered_device *rdev; |
| 6197 | int err, reg_idx, start = cb->args[2]; |
| 6198 | |
| 6199 | rtnl_lock(); |
| 6200 | |
| 6201 | if (cfg80211_regdomain && start == 0) { |
| 6202 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 6203 | NLM_F_MULTI, NULL, |
| 6204 | rtnl_dereference(cfg80211_regdomain)); |
| 6205 | if (err < 0) |
| 6206 | goto out_err; |
| 6207 | } |
| 6208 | |
| 6209 | /* the global regdom is idx 0 */ |
| 6210 | reg_idx = 1; |
| 6211 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 6212 | regdom = get_wiphy_regdom(&rdev->wiphy); |
| 6213 | if (!regdom) |
| 6214 | continue; |
| 6215 | |
| 6216 | if (++reg_idx <= start) |
| 6217 | continue; |
| 6218 | |
| 6219 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 6220 | NLM_F_MULTI, &rdev->wiphy, regdom); |
| 6221 | if (err < 0) { |
| 6222 | reg_idx--; |
| 6223 | break; |
| 6224 | } |
| 6225 | } |
| 6226 | |
| 6227 | cb->args[2] = reg_idx; |
| 6228 | err = skb->len; |
| 6229 | out_err: |
| 6230 | rtnl_unlock(); |
| 6231 | return err; |
| 6232 | } |
| 6233 | |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 6234 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
| 6235 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 6236 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 6237 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 6238 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 6239 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 6240 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 6241 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 6242 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
| 6243 | }; |
| 6244 | |
| 6245 | static int parse_reg_rule(struct nlattr *tb[], |
| 6246 | struct ieee80211_reg_rule *reg_rule) |
| 6247 | { |
| 6248 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 6249 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 6250 | |
| 6251 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 6252 | return -EINVAL; |
| 6253 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 6254 | return -EINVAL; |
| 6255 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 6256 | return -EINVAL; |
| 6257 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 6258 | return -EINVAL; |
| 6259 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 6260 | return -EINVAL; |
| 6261 | |
| 6262 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 6263 | |
| 6264 | freq_range->start_freq_khz = |
| 6265 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 6266 | freq_range->end_freq_khz = |
| 6267 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 6268 | freq_range->max_bandwidth_khz = |
| 6269 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 6270 | |
| 6271 | power_rule->max_eirp = |
| 6272 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 6273 | |
| 6274 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 6275 | power_rule->max_antenna_gain = |
| 6276 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 6277 | |
| 6278 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 6279 | reg_rule->dfs_cac_ms = |
| 6280 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 6281 | |
| 6282 | return 0; |
| 6283 | } |
| 6284 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6285 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 6286 | { |
| 6287 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 6288 | struct nlattr *nl_reg_rule; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 6289 | char *alpha2; |
| 6290 | int rem_reg_rules, r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6291 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 6292 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 6293 | struct ieee80211_regdomain *rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6294 | |
| 6295 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 6296 | return -EINVAL; |
| 6297 | |
| 6298 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 6299 | return -EINVAL; |
| 6300 | |
| 6301 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 6302 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 6303 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 6304 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 6305 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6306 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 6307 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6308 | num_rules++; |
| 6309 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 6310 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6311 | } |
| 6312 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 6313 | if (!reg_is_valid_request(alpha2)) |
| 6314 | return -EINVAL; |
| 6315 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6316 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 6317 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6318 | |
| 6319 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 6320 | if (!rd) |
| 6321 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6322 | |
| 6323 | rd->n_reg_rules = num_rules; |
| 6324 | rd->alpha2[0] = alpha2[0]; |
| 6325 | rd->alpha2[1] = alpha2[1]; |
| 6326 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 6327 | /* |
| 6328 | * Disable DFS master mode if the DFS region was |
| 6329 | * not supported or known on this kernel. |
| 6330 | */ |
| 6331 | if (reg_supported_dfs_region(dfs_region)) |
| 6332 | rd->dfs_region = dfs_region; |
| 6333 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6334 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 6335 | rem_reg_rules) { |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 6336 | r = nla_parse_nested(tb, NL80211_REG_RULE_ATTR_MAX, |
| 6337 | nl_reg_rule, reg_rule_policy); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 6338 | if (r) |
| 6339 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6340 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 6341 | if (r) |
| 6342 | goto bad_reg; |
| 6343 | |
| 6344 | rule_idx++; |
| 6345 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6346 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 6347 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6348 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6349 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6350 | } |
| 6351 | |
Johannes Berg | 0662799 | 2016-06-09 10:40:09 +0200 | [diff] [blame] | 6352 | /* set_regdom takes ownership of rd */ |
| 6353 | return set_regdom(rd, REGD_SOURCE_CRDA); |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 6354 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6355 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6356 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6357 | } |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 6358 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6359 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6360 | static int validate_scan_freqs(struct nlattr *freqs) |
| 6361 | { |
| 6362 | struct nlattr *attr1, *attr2; |
| 6363 | int n_channels = 0, tmp1, tmp2; |
| 6364 | |
| 6365 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 6366 | n_channels++; |
| 6367 | /* |
| 6368 | * Some hardware has a limited channel list for |
| 6369 | * scanning, and it is pretty much nonsensical |
| 6370 | * to scan for a channel twice, so disallow that |
| 6371 | * and don't require drivers to check that the |
| 6372 | * channel list they get isn't longer than what |
| 6373 | * they can scan, as long as they can scan all |
| 6374 | * the channels they registered at once. |
| 6375 | */ |
| 6376 | nla_for_each_nested(attr2, freqs, tmp2) |
| 6377 | if (attr1 != attr2 && |
| 6378 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 6379 | return 0; |
| 6380 | } |
| 6381 | |
| 6382 | return n_channels; |
| 6383 | } |
| 6384 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6385 | static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b) |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 6386 | { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6387 | return b < NUM_NL80211_BANDS && wiphy->bands[b]; |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 6388 | } |
| 6389 | |
| 6390 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, |
| 6391 | struct cfg80211_bss_selection *bss_select) |
| 6392 | { |
| 6393 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; |
| 6394 | struct nlattr *nest; |
| 6395 | int err; |
| 6396 | bool found = false; |
| 6397 | int i; |
| 6398 | |
| 6399 | /* only process one nested attribute */ |
| 6400 | nest = nla_data(nla); |
| 6401 | if (!nla_ok(nest, nla_len(nest))) |
| 6402 | return -EINVAL; |
| 6403 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 6404 | err = nla_parse_nested(attr, NL80211_BSS_SELECT_ATTR_MAX, nest, |
| 6405 | nl80211_bss_select_policy); |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 6406 | if (err) |
| 6407 | return err; |
| 6408 | |
| 6409 | /* only one attribute may be given */ |
| 6410 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { |
| 6411 | if (attr[i]) { |
| 6412 | if (found) |
| 6413 | return -EINVAL; |
| 6414 | found = true; |
| 6415 | } |
| 6416 | } |
| 6417 | |
| 6418 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; |
| 6419 | |
| 6420 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) |
| 6421 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; |
| 6422 | |
| 6423 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { |
| 6424 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; |
| 6425 | bss_select->param.band_pref = |
| 6426 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); |
| 6427 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) |
| 6428 | return -EINVAL; |
| 6429 | } |
| 6430 | |
| 6431 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { |
| 6432 | struct nl80211_bss_select_rssi_adjust *adj_param; |
| 6433 | |
| 6434 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); |
| 6435 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; |
| 6436 | bss_select->param.adjust.band = adj_param->band; |
| 6437 | bss_select->param.adjust.delta = adj_param->delta; |
| 6438 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) |
| 6439 | return -EINVAL; |
| 6440 | } |
| 6441 | |
| 6442 | /* user-space did not provide behaviour attribute */ |
| 6443 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) |
| 6444 | return -EINVAL; |
| 6445 | |
| 6446 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) |
| 6447 | return -EINVAL; |
| 6448 | |
| 6449 | return 0; |
| 6450 | } |
| 6451 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6452 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
| 6453 | u8 *mac_addr, u8 *mac_addr_mask) |
| 6454 | { |
| 6455 | int i; |
| 6456 | |
| 6457 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { |
Joe Perches | d2beae1 | 2015-03-02 19:54:58 -0800 | [diff] [blame] | 6458 | eth_zero_addr(mac_addr); |
| 6459 | eth_zero_addr(mac_addr_mask); |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6460 | mac_addr[0] = 0x2; |
| 6461 | mac_addr_mask[0] = 0x3; |
| 6462 | |
| 6463 | return 0; |
| 6464 | } |
| 6465 | |
| 6466 | /* need both or none */ |
| 6467 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) |
| 6468 | return -EINVAL; |
| 6469 | |
| 6470 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); |
| 6471 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); |
| 6472 | |
| 6473 | /* don't allow or configure an mcast address */ |
| 6474 | if (!is_multicast_ether_addr(mac_addr_mask) || |
| 6475 | is_multicast_ether_addr(mac_addr)) |
| 6476 | return -EINVAL; |
| 6477 | |
| 6478 | /* |
| 6479 | * allow users to pass a MAC address that has bits set outside |
| 6480 | * of the mask, but don't bother drivers with having to deal |
| 6481 | * with such bits |
| 6482 | */ |
| 6483 | for (i = 0; i < ETH_ALEN; i++) |
| 6484 | mac_addr[i] &= mac_addr_mask[i]; |
| 6485 | |
| 6486 | return 0; |
| 6487 | } |
| 6488 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6489 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 6490 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6491 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6492 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6493 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6494 | struct nlattr *attr; |
| 6495 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6496 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6497 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6498 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6499 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6500 | return -EINVAL; |
| 6501 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6502 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6503 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 6504 | if (wdev->iftype == NL80211_IFTYPE_NAN) |
| 6505 | return -EOPNOTSUPP; |
| 6506 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6507 | if (!rdev->ops->scan) |
| 6508 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6509 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 6510 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6511 | err = -EBUSY; |
| 6512 | goto unlock; |
| 6513 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6514 | |
| 6515 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6516 | n_channels = validate_scan_freqs( |
| 6517 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6518 | if (!n_channels) { |
| 6519 | err = -EINVAL; |
| 6520 | goto unlock; |
| 6521 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6522 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 6523 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6524 | } |
| 6525 | |
| 6526 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 6527 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 6528 | n_ssids++; |
| 6529 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6530 | if (n_ssids > wiphy->max_scan_ssids) { |
| 6531 | err = -EINVAL; |
| 6532 | goto unlock; |
| 6533 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6534 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6535 | if (info->attrs[NL80211_ATTR_IE]) |
| 6536 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6537 | else |
| 6538 | ie_len = 0; |
| 6539 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6540 | if (ie_len > wiphy->max_scan_ie_len) { |
| 6541 | err = -EINVAL; |
| 6542 | goto unlock; |
| 6543 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 6544 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6545 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6546 | + sizeof(*request->ssids) * n_ssids |
| 6547 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6548 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6549 | if (!request) { |
| 6550 | err = -ENOMEM; |
| 6551 | goto unlock; |
| 6552 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6553 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6554 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 6555 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6556 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6557 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6558 | if (n_ssids) |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6559 | request->ie = (void *)(request->ssids + n_ssids); |
| 6560 | else |
| 6561 | request->ie = (void *)(request->channels + n_channels); |
| 6562 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6563 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6564 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6565 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 6566 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6567 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6568 | struct ieee80211_channel *chan; |
| 6569 | |
| 6570 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 6571 | |
| 6572 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6573 | err = -EINVAL; |
| 6574 | goto out_free; |
| 6575 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6576 | |
| 6577 | /* ignore disabled channels */ |
| 6578 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6579 | continue; |
| 6580 | |
| 6581 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6582 | i++; |
| 6583 | } |
| 6584 | } else { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6585 | enum nl80211_band band; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6586 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6587 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6588 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6589 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 6590 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6591 | if (!wiphy->bands[band]) |
| 6592 | continue; |
| 6593 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6594 | struct ieee80211_channel *chan; |
| 6595 | |
| 6596 | chan = &wiphy->bands[band]->channels[j]; |
| 6597 | |
| 6598 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6599 | continue; |
| 6600 | |
| 6601 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6602 | i++; |
| 6603 | } |
| 6604 | } |
| 6605 | } |
| 6606 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6607 | if (!i) { |
| 6608 | err = -EINVAL; |
| 6609 | goto out_free; |
| 6610 | } |
| 6611 | |
| 6612 | request->n_channels = i; |
| 6613 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6614 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6615 | if (n_ssids) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6616 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6617 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6618 | err = -EINVAL; |
| 6619 | goto out_free; |
| 6620 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6621 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6622 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6623 | i++; |
| 6624 | } |
| 6625 | } |
| 6626 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6627 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6628 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 6629 | memcpy((void *)request->ie, |
| 6630 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6631 | request->ie_len); |
| 6632 | } |
| 6633 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6634 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 6635 | if (wiphy->bands[i]) |
| 6636 | request->rates[i] = |
| 6637 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6638 | |
| 6639 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 6640 | nla_for_each_nested(attr, |
| 6641 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 6642 | tmp) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6643 | enum nl80211_band band = nla_type(attr); |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6644 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6645 | if (band < 0 || band >= NUM_NL80211_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6646 | err = -EINVAL; |
| 6647 | goto out_free; |
| 6648 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 6649 | |
| 6650 | if (!wiphy->bands[band]) |
| 6651 | continue; |
| 6652 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6653 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 6654 | nla_data(attr), |
| 6655 | nla_len(attr), |
| 6656 | &request->rates[band]); |
| 6657 | if (err) |
| 6658 | goto out_free; |
| 6659 | } |
| 6660 | } |
| 6661 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 6662 | if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { |
| 6663 | if (!wiphy_ext_feature_isset(wiphy, |
| 6664 | NL80211_EXT_FEATURE_SET_SCAN_DWELL)) { |
| 6665 | err = -EOPNOTSUPP; |
| 6666 | goto out_free; |
| 6667 | } |
| 6668 | |
| 6669 | request->duration = |
| 6670 | nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); |
| 6671 | request->duration_mandatory = |
| 6672 | nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); |
| 6673 | } |
| 6674 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6675 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6676 | request->flags = nla_get_u32( |
| 6677 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 6678 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 6679 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6680 | err = -EOPNOTSUPP; |
| 6681 | goto out_free; |
| 6682 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6683 | |
| 6684 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 6685 | if (!(wiphy->features & |
| 6686 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { |
| 6687 | err = -EOPNOTSUPP; |
| 6688 | goto out_free; |
| 6689 | } |
| 6690 | |
| 6691 | if (wdev->current_bss) { |
| 6692 | err = -EOPNOTSUPP; |
| 6693 | goto out_free; |
| 6694 | } |
| 6695 | |
| 6696 | err = nl80211_parse_random_mac(info->attrs, |
| 6697 | request->mac_addr, |
| 6698 | request->mac_addr_mask); |
| 6699 | if (err) |
| 6700 | goto out_free; |
| 6701 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6702 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6703 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6704 | request->no_cck = |
| 6705 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6706 | |
Vamsi Krishna | 2fa436b | 2016-12-02 23:59:08 +0200 | [diff] [blame^] | 6707 | /* Initial implementation used NL80211_ATTR_MAC to set the specific |
| 6708 | * BSSID to scan for. This was problematic because that same attribute |
| 6709 | * was already used for another purpose (local random MAC address). The |
| 6710 | * NL80211_ATTR_BSSID attribute was added to fix this. For backwards |
| 6711 | * compatibility with older userspace components, also use the |
| 6712 | * NL80211_ATTR_MAC value here if it can be determined to be used for |
| 6713 | * the specific BSSID use case instead of the random MAC address |
| 6714 | * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use). |
| 6715 | */ |
| 6716 | if (info->attrs[NL80211_ATTR_BSSID]) |
| 6717 | memcpy(request->bssid, |
| 6718 | nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN); |
| 6719 | else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) && |
| 6720 | info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 818965d | 2016-02-26 22:12:47 +0200 | [diff] [blame] | 6721 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), |
| 6722 | ETH_ALEN); |
| 6723 | else |
| 6724 | eth_broadcast_addr(request->bssid); |
| 6725 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6726 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6727 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 6728 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6729 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6730 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6731 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6732 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6733 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6734 | nl80211_send_scan_start(rdev, wdev); |
| 6735 | if (wdev->netdev) |
| 6736 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6737 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6738 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6739 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6740 | kfree(request); |
| 6741 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6742 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6743 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6744 | return err; |
| 6745 | } |
| 6746 | |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 6747 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
| 6748 | { |
| 6749 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6750 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 6751 | |
| 6752 | if (!rdev->ops->abort_scan) |
| 6753 | return -EOPNOTSUPP; |
| 6754 | |
| 6755 | if (rdev->scan_msg) |
| 6756 | return 0; |
| 6757 | |
| 6758 | if (!rdev->scan_req) |
| 6759 | return -ENOENT; |
| 6760 | |
| 6761 | rdev_abort_scan(rdev, wdev); |
| 6762 | return 0; |
| 6763 | } |
| 6764 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6765 | static int |
| 6766 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, |
| 6767 | struct cfg80211_sched_scan_request *request, |
| 6768 | struct nlattr **attrs) |
| 6769 | { |
| 6770 | int tmp, err, i = 0; |
| 6771 | struct nlattr *attr; |
| 6772 | |
| 6773 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 6774 | u32 interval; |
| 6775 | |
| 6776 | /* |
| 6777 | * If scan plans are not specified, |
| 6778 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this |
| 6779 | * case one scan plan will be set with the specified scan |
| 6780 | * interval and infinite number of iterations. |
| 6781 | */ |
| 6782 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 6783 | return -EINVAL; |
| 6784 | |
| 6785 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 6786 | if (!interval) |
| 6787 | return -EINVAL; |
| 6788 | |
| 6789 | request->scan_plans[0].interval = |
| 6790 | DIV_ROUND_UP(interval, MSEC_PER_SEC); |
| 6791 | if (!request->scan_plans[0].interval) |
| 6792 | return -EINVAL; |
| 6793 | |
| 6794 | if (request->scan_plans[0].interval > |
| 6795 | wiphy->max_sched_scan_plan_interval) |
| 6796 | request->scan_plans[0].interval = |
| 6797 | wiphy->max_sched_scan_plan_interval; |
| 6798 | |
| 6799 | return 0; |
| 6800 | } |
| 6801 | |
| 6802 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { |
| 6803 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; |
| 6804 | |
| 6805 | if (WARN_ON(i >= n_plans)) |
| 6806 | return -EINVAL; |
| 6807 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 6808 | err = nla_parse_nested(plan, NL80211_SCHED_SCAN_PLAN_MAX, |
| 6809 | attr, nl80211_plan_policy); |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6810 | if (err) |
| 6811 | return err; |
| 6812 | |
| 6813 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) |
| 6814 | return -EINVAL; |
| 6815 | |
| 6816 | request->scan_plans[i].interval = |
| 6817 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); |
| 6818 | if (!request->scan_plans[i].interval || |
| 6819 | request->scan_plans[i].interval > |
| 6820 | wiphy->max_sched_scan_plan_interval) |
| 6821 | return -EINVAL; |
| 6822 | |
| 6823 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { |
| 6824 | request->scan_plans[i].iterations = |
| 6825 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); |
| 6826 | if (!request->scan_plans[i].iterations || |
| 6827 | (request->scan_plans[i].iterations > |
| 6828 | wiphy->max_sched_scan_plan_iterations)) |
| 6829 | return -EINVAL; |
| 6830 | } else if (i < n_plans - 1) { |
| 6831 | /* |
| 6832 | * All scan plans but the last one must specify |
| 6833 | * a finite number of iterations |
| 6834 | */ |
| 6835 | return -EINVAL; |
| 6836 | } |
| 6837 | |
| 6838 | i++; |
| 6839 | } |
| 6840 | |
| 6841 | /* |
| 6842 | * The last scan plan must not specify the number of |
| 6843 | * iterations, it is supposed to run infinitely |
| 6844 | */ |
| 6845 | if (request->scan_plans[n_plans - 1].iterations) |
| 6846 | return -EINVAL; |
| 6847 | |
| 6848 | return 0; |
| 6849 | } |
| 6850 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6851 | static struct cfg80211_sched_scan_request * |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6852 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6853 | struct nlattr **attrs) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6854 | { |
| 6855 | struct cfg80211_sched_scan_request *request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6856 | struct nlattr *attr; |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6857 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6858 | enum nl80211_band band; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6859 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6860 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6861 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6862 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6863 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
| 6864 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6865 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6866 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6867 | n_channels = validate_scan_freqs( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6868 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6869 | if (!n_channels) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6870 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6871 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 6872 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6873 | } |
| 6874 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6875 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 6876 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6877 | tmp) |
| 6878 | n_ssids++; |
| 6879 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 6880 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6881 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6882 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6883 | /* |
| 6884 | * First, count the number of 'real' matchsets. Due to an issue with |
| 6885 | * the old implementation, matchsets containing only the RSSI attribute |
| 6886 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 6887 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 6888 | * all APs with a strong RSSI. This is needed to be compatible with |
| 6889 | * older userspace that treated a matchset with only the RSSI as the |
| 6890 | * global RSSI for all other matchsets - if there are other matchsets. |
| 6891 | */ |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6892 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6893 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6894 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6895 | tmp) { |
| 6896 | struct nlattr *rssi; |
| 6897 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 6898 | err = nla_parse_nested(tb, |
| 6899 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 6900 | attr, nl80211_match_policy); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6901 | if (err) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6902 | return ERR_PTR(err); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6903 | /* add other standalone attributes here */ |
| 6904 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { |
| 6905 | n_match_sets++; |
| 6906 | continue; |
| 6907 | } |
| 6908 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 6909 | if (rssi) |
| 6910 | default_match_rssi = nla_get_s32(rssi); |
| 6911 | } |
| 6912 | } |
| 6913 | |
| 6914 | /* However, if there's no other matchset, add the RSSI one */ |
| 6915 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 6916 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6917 | |
| 6918 | if (n_match_sets > wiphy->max_match_sets) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6919 | return ERR_PTR(-EINVAL); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6920 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6921 | if (attrs[NL80211_ATTR_IE]) |
| 6922 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6923 | else |
| 6924 | ie_len = 0; |
| 6925 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 6926 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6927 | return ERR_PTR(-EINVAL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 6928 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6929 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 6930 | /* |
| 6931 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since |
| 6932 | * each scan plan already specifies its own interval |
| 6933 | */ |
| 6934 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 6935 | return ERR_PTR(-EINVAL); |
| 6936 | |
| 6937 | nla_for_each_nested(attr, |
| 6938 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) |
| 6939 | n_plans++; |
| 6940 | } else { |
| 6941 | /* |
| 6942 | * The scan interval attribute is kept for backward |
| 6943 | * compatibility. If no scan plans are specified and sched scan |
| 6944 | * interval is specified, one scan plan will be set with this |
| 6945 | * scan interval and infinite number of iterations. |
| 6946 | */ |
| 6947 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 6948 | return ERR_PTR(-EINVAL); |
| 6949 | |
| 6950 | n_plans = 1; |
| 6951 | } |
| 6952 | |
| 6953 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) |
| 6954 | return ERR_PTR(-EINVAL); |
| 6955 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6956 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6957 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6958 | + sizeof(*request->match_sets) * n_match_sets |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6959 | + sizeof(*request->scan_plans) * n_plans |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6960 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6961 | + ie_len, GFP_KERNEL); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6962 | if (!request) |
| 6963 | return ERR_PTR(-ENOMEM); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6964 | |
| 6965 | if (n_ssids) |
| 6966 | request->ssids = (void *)&request->channels[n_channels]; |
| 6967 | request->n_ssids = n_ssids; |
| 6968 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6969 | if (n_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6970 | request->ie = (void *)(request->ssids + n_ssids); |
| 6971 | else |
| 6972 | request->ie = (void *)(request->channels + n_channels); |
| 6973 | } |
| 6974 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6975 | if (n_match_sets) { |
| 6976 | if (request->ie) |
| 6977 | request->match_sets = (void *)(request->ie + ie_len); |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6978 | else if (n_ssids) |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6979 | request->match_sets = |
| 6980 | (void *)(request->ssids + n_ssids); |
| 6981 | else |
| 6982 | request->match_sets = |
| 6983 | (void *)(request->channels + n_channels); |
| 6984 | } |
| 6985 | request->n_match_sets = n_match_sets; |
| 6986 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6987 | if (n_match_sets) |
| 6988 | request->scan_plans = (void *)(request->match_sets + |
| 6989 | n_match_sets); |
| 6990 | else if (request->ie) |
| 6991 | request->scan_plans = (void *)(request->ie + ie_len); |
| 6992 | else if (n_ssids) |
| 6993 | request->scan_plans = (void *)(request->ssids + n_ssids); |
| 6994 | else |
| 6995 | request->scan_plans = (void *)(request->channels + n_channels); |
| 6996 | |
| 6997 | request->n_scan_plans = n_plans; |
| 6998 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6999 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7000 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7001 | /* user specified, bail out if channel not found */ |
| 7002 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7003 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7004 | tmp) { |
| 7005 | struct ieee80211_channel *chan; |
| 7006 | |
| 7007 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 7008 | |
| 7009 | if (!chan) { |
| 7010 | err = -EINVAL; |
| 7011 | goto out_free; |
| 7012 | } |
| 7013 | |
| 7014 | /* ignore disabled channels */ |
| 7015 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 7016 | continue; |
| 7017 | |
| 7018 | request->channels[i] = chan; |
| 7019 | i++; |
| 7020 | } |
| 7021 | } else { |
| 7022 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7023 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7024 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 7025 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7026 | if (!wiphy->bands[band]) |
| 7027 | continue; |
| 7028 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 7029 | struct ieee80211_channel *chan; |
| 7030 | |
| 7031 | chan = &wiphy->bands[band]->channels[j]; |
| 7032 | |
| 7033 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 7034 | continue; |
| 7035 | |
| 7036 | request->channels[i] = chan; |
| 7037 | i++; |
| 7038 | } |
| 7039 | } |
| 7040 | } |
| 7041 | |
| 7042 | if (!i) { |
| 7043 | err = -EINVAL; |
| 7044 | goto out_free; |
| 7045 | } |
| 7046 | |
| 7047 | request->n_channels = i; |
| 7048 | |
| 7049 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7050 | if (n_ssids) { |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7051 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7052 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7053 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7054 | err = -EINVAL; |
| 7055 | goto out_free; |
| 7056 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7057 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7058 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 7059 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7060 | i++; |
| 7061 | } |
| 7062 | } |
| 7063 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7064 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7065 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7066 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7067 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7068 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 7069 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7070 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 7071 | err = nla_parse_nested(tb, |
| 7072 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 7073 | attr, nl80211_match_policy); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7074 | if (err) |
| 7075 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 7076 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7077 | if (ssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7078 | if (WARN_ON(i >= n_match_sets)) { |
| 7079 | /* this indicates a programming error, |
| 7080 | * the loop above should have verified |
| 7081 | * things properly |
| 7082 | */ |
| 7083 | err = -EINVAL; |
| 7084 | goto out_free; |
| 7085 | } |
| 7086 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7087 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 7088 | err = -EINVAL; |
| 7089 | goto out_free; |
| 7090 | } |
| 7091 | memcpy(request->match_sets[i].ssid.ssid, |
| 7092 | nla_data(ssid), nla_len(ssid)); |
| 7093 | request->match_sets[i].ssid.ssid_len = |
| 7094 | nla_len(ssid); |
Kirtika Ruchandani | 56ab364 | 2016-05-29 19:54:10 -0700 | [diff] [blame] | 7095 | /* special attribute - old implementation w/a */ |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7096 | request->match_sets[i].rssi_thold = |
| 7097 | default_match_rssi; |
| 7098 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 7099 | if (rssi) |
| 7100 | request->match_sets[i].rssi_thold = |
| 7101 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7102 | } |
| 7103 | i++; |
| 7104 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7105 | |
| 7106 | /* there was no other matchset, so the RSSI one is alone */ |
Luciano Coelho | f89f46c | 2014-12-01 11:32:09 +0200 | [diff] [blame] | 7107 | if (i == 0 && n_match_sets) |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7108 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 7109 | |
| 7110 | request->min_rssi_thold = INT_MAX; |
| 7111 | for (i = 0; i < n_match_sets; i++) |
| 7112 | request->min_rssi_thold = |
| 7113 | min(request->match_sets[i].rssi_thold, |
| 7114 | request->min_rssi_thold); |
| 7115 | } else { |
| 7116 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7117 | } |
| 7118 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 7119 | if (ie_len) { |
| 7120 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7121 | memcpy((void *)request->ie, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7122 | nla_data(attrs[NL80211_ATTR_IE]), |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7123 | request->ie_len); |
| 7124 | } |
| 7125 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7126 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 7127 | request->flags = nla_get_u32( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7128 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 7129 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 7130 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 7131 | err = -EOPNOTSUPP; |
| 7132 | goto out_free; |
| 7133 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7134 | |
| 7135 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 7136 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; |
| 7137 | |
| 7138 | if (!wdev) /* must be net-detect */ |
| 7139 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 7140 | |
| 7141 | if (!(wiphy->features & flg)) { |
| 7142 | err = -EOPNOTSUPP; |
| 7143 | goto out_free; |
| 7144 | } |
| 7145 | |
| 7146 | if (wdev && wdev->current_bss) { |
| 7147 | err = -EOPNOTSUPP; |
| 7148 | goto out_free; |
| 7149 | } |
| 7150 | |
| 7151 | err = nl80211_parse_random_mac(attrs, request->mac_addr, |
| 7152 | request->mac_addr_mask); |
| 7153 | if (err) |
| 7154 | goto out_free; |
| 7155 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 7156 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 7157 | |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 7158 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
| 7159 | request->delay = |
| 7160 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); |
| 7161 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7162 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
| 7163 | if (err) |
| 7164 | goto out_free; |
| 7165 | |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 7166 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7167 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7168 | return request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7169 | |
| 7170 | out_free: |
| 7171 | kfree(request); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7172 | return ERR_PTR(err); |
| 7173 | } |
| 7174 | |
| 7175 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 7176 | struct genl_info *info) |
| 7177 | { |
| 7178 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7179 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7180 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7181 | struct cfg80211_sched_scan_request *sched_scan_req; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7182 | int err; |
| 7183 | |
| 7184 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 7185 | !rdev->ops->sched_scan_start) |
| 7186 | return -EOPNOTSUPP; |
| 7187 | |
| 7188 | if (rdev->sched_scan_req) |
| 7189 | return -EINPROGRESS; |
| 7190 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7191 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
| 7192 | info->attrs); |
| 7193 | |
| 7194 | err = PTR_ERR_OR_ZERO(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7195 | if (err) |
| 7196 | goto out_err; |
| 7197 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7198 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7199 | if (err) |
| 7200 | goto out_free; |
| 7201 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7202 | sched_scan_req->dev = dev; |
| 7203 | sched_scan_req->wiphy = &rdev->wiphy; |
| 7204 | |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 7205 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 7206 | sched_scan_req->owner_nlportid = info->snd_portid; |
| 7207 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7208 | rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7209 | |
| 7210 | nl80211_send_sched_scan(rdev, dev, |
| 7211 | NL80211_CMD_START_SCHED_SCAN); |
| 7212 | return 0; |
| 7213 | |
| 7214 | out_free: |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7215 | kfree(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7216 | out_err: |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7217 | return err; |
| 7218 | } |
| 7219 | |
| 7220 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 7221 | struct genl_info *info) |
| 7222 | { |
| 7223 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7224 | |
| 7225 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 7226 | !rdev->ops->sched_scan_stop) |
| 7227 | return -EOPNOTSUPP; |
| 7228 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7229 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7230 | } |
| 7231 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7232 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 7233 | struct genl_info *info) |
| 7234 | { |
| 7235 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7236 | struct net_device *dev = info->user_ptr[1]; |
| 7237 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7238 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 7239 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 7240 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7241 | int err; |
| 7242 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 7243 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 7244 | if (dfs_region == NL80211_DFS_UNSET) |
| 7245 | return -EINVAL; |
| 7246 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7247 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7248 | if (err) |
| 7249 | return err; |
| 7250 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 7251 | if (netif_carrier_ok(dev)) |
| 7252 | return -EBUSY; |
| 7253 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7254 | if (wdev->cac_started) |
| 7255 | return -EBUSY; |
| 7256 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 7257 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 7258 | wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7259 | if (err < 0) |
| 7260 | return err; |
| 7261 | |
| 7262 | if (err == 0) |
| 7263 | return -EINVAL; |
| 7264 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 7265 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7266 | return -EINVAL; |
| 7267 | |
| 7268 | if (!rdev->ops->start_radar_detection) |
| 7269 | return -EOPNOTSUPP; |
| 7270 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 7271 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 7272 | if (WARN_ON(!cac_time_ms)) |
| 7273 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 7274 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 7275 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7276 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 7277 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7278 | wdev->cac_started = true; |
| 7279 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 7280 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7281 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7282 | return err; |
| 7283 | } |
| 7284 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7285 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 7286 | { |
| 7287 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7288 | struct net_device *dev = info->user_ptr[1]; |
| 7289 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7290 | struct cfg80211_csa_settings params; |
| 7291 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 7292 | * function is called under RTNL lock, so this should not be a problem. |
| 7293 | */ |
| 7294 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7295 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7296 | bool need_new_beacon = false; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7297 | int len, i; |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 7298 | u32 cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7299 | |
| 7300 | if (!rdev->ops->channel_switch || |
| 7301 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 7302 | return -EOPNOTSUPP; |
| 7303 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7304 | switch (dev->ieee80211_ptr->iftype) { |
| 7305 | case NL80211_IFTYPE_AP: |
| 7306 | case NL80211_IFTYPE_P2P_GO: |
| 7307 | need_new_beacon = true; |
| 7308 | |
| 7309 | /* useless if AP is not running */ |
| 7310 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 7311 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7312 | break; |
| 7313 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 7314 | if (!wdev->ssid_len) |
| 7315 | return -ENOTCONN; |
| 7316 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 7317 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 7318 | if (!wdev->mesh_id_len) |
| 7319 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7320 | break; |
| 7321 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7322 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7323 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7324 | |
| 7325 | memset(¶ms, 0, sizeof(params)); |
| 7326 | |
| 7327 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7328 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 7329 | return -EINVAL; |
| 7330 | |
| 7331 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 7332 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7333 | return -EINVAL; |
| 7334 | |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 7335 | /* Even though the attribute is u32, the specification says |
| 7336 | * u8, so let's make sure we don't overflow. |
| 7337 | */ |
| 7338 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 7339 | if (cs_count > 255) |
| 7340 | return -EINVAL; |
| 7341 | |
| 7342 | params.count = cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7343 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7344 | if (!need_new_beacon) |
| 7345 | goto skip_beacons; |
| 7346 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7347 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 7348 | if (err) |
| 7349 | return err; |
| 7350 | |
| 7351 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 7352 | info->attrs[NL80211_ATTR_CSA_IES], |
| 7353 | nl80211_policy); |
| 7354 | if (err) |
| 7355 | return err; |
| 7356 | |
| 7357 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 7358 | if (err) |
| 7359 | return err; |
| 7360 | |
| 7361 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 7362 | return -EINVAL; |
| 7363 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7364 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 7365 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7366 | return -EINVAL; |
| 7367 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7368 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 7369 | if (rdev->wiphy.max_num_csa_counters && |
| 7370 | (params.n_counter_offsets_beacon > |
| 7371 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7372 | return -EINVAL; |
| 7373 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7374 | params.counter_offsets_beacon = |
| 7375 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 7376 | |
| 7377 | /* sanity checks - counters should fit and be the same */ |
| 7378 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 7379 | u16 offset = params.counter_offsets_beacon[i]; |
| 7380 | |
| 7381 | if (offset >= params.beacon_csa.tail_len) |
| 7382 | return -EINVAL; |
| 7383 | |
| 7384 | if (params.beacon_csa.tail[offset] != params.count) |
| 7385 | return -EINVAL; |
| 7386 | } |
| 7387 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7388 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7389 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 7390 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7391 | return -EINVAL; |
| 7392 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7393 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 7394 | if (rdev->wiphy.max_num_csa_counters && |
Johannes Berg | ad5987b | 2016-09-13 15:53:55 +0200 | [diff] [blame] | 7395 | (params.n_counter_offsets_presp > |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7396 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7397 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7398 | |
| 7399 | params.counter_offsets_presp = |
| 7400 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 7401 | |
| 7402 | /* sanity checks - counters should fit and be the same */ |
| 7403 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 7404 | u16 offset = params.counter_offsets_presp[i]; |
| 7405 | |
| 7406 | if (offset >= params.beacon_csa.probe_resp_len) |
| 7407 | return -EINVAL; |
| 7408 | |
| 7409 | if (params.beacon_csa.probe_resp[offset] != |
| 7410 | params.count) |
| 7411 | return -EINVAL; |
| 7412 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7413 | } |
| 7414 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7415 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7416 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 7417 | if (err) |
| 7418 | return err; |
| 7419 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 7420 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 7421 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7422 | return -EINVAL; |
| 7423 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 7424 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 7425 | ¶ms.chandef, |
| 7426 | wdev->iftype); |
| 7427 | if (err < 0) |
| 7428 | return err; |
| 7429 | |
Fabian Frederick | dcc6c2f | 2014-10-25 17:57:35 +0200 | [diff] [blame] | 7430 | if (err > 0) |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 7431 | params.radar_required = true; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7432 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7433 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 7434 | params.block_tx = true; |
| 7435 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 7436 | wdev_lock(wdev); |
| 7437 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 7438 | wdev_unlock(wdev); |
| 7439 | |
| 7440 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7441 | } |
| 7442 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7443 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 7444 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7445 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7446 | struct wireless_dev *wdev, |
| 7447 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7448 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7449 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7450 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7451 | void *hdr; |
| 7452 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7453 | |
| 7454 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7455 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7456 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7457 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 7458 | if (!hdr) |
| 7459 | return -1; |
| 7460 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7461 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 7462 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7463 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 7464 | goto nla_put_failure; |
| 7465 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7466 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 7467 | goto nla_put_failure; |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7468 | if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 7469 | NL80211_ATTR_PAD)) |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7470 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7471 | |
| 7472 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 7473 | if (!bss) |
| 7474 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7475 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7476 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7477 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7478 | |
| 7479 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7480 | /* indicate whether we have probe response data or not */ |
| 7481 | if (rcu_access_pointer(res->proberesp_ies) && |
| 7482 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 7483 | goto fail_unlock_rcu; |
| 7484 | |
| 7485 | /* this pointer prefers to be pointed to probe response data |
| 7486 | * but is always valid |
| 7487 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7488 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7489 | if (ies) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7490 | if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, |
| 7491 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7492 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7493 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 7494 | ies->len, ies->data)) |
| 7495 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7496 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7497 | |
| 7498 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7499 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7500 | if (ies && ies->from_beacon) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7501 | if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, |
| 7502 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7503 | goto fail_unlock_rcu; |
| 7504 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 7505 | ies->len, ies->data)) |
| 7506 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7507 | } |
| 7508 | rcu_read_unlock(); |
| 7509 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7510 | if (res->beacon_interval && |
| 7511 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 7512 | goto nla_put_failure; |
| 7513 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 7514 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 7515 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7516 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 7517 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 7518 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7519 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 7520 | if (intbss->parent_tsf && |
| 7521 | (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, |
| 7522 | intbss->parent_tsf, NL80211_BSS_PAD) || |
| 7523 | nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, |
| 7524 | intbss->parent_bssid))) |
| 7525 | goto nla_put_failure; |
| 7526 | |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 7527 | if (intbss->ts_boottime && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7528 | nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
| 7529 | intbss->ts_boottime, NL80211_BSS_PAD)) |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 7530 | goto nla_put_failure; |
| 7531 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 7532 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7533 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7534 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 7535 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7536 | break; |
| 7537 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7538 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 7539 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7540 | break; |
| 7541 | default: |
| 7542 | break; |
| 7543 | } |
| 7544 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7545 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7546 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7547 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7548 | if (intbss == wdev->current_bss && |
| 7549 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 7550 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 7551 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7552 | break; |
| 7553 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7554 | if (intbss == wdev->current_bss && |
| 7555 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 7556 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 7557 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7558 | break; |
| 7559 | default: |
| 7560 | break; |
| 7561 | } |
| 7562 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7563 | nla_nest_end(msg, bss); |
| 7564 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 7565 | genlmsg_end(msg, hdr); |
| 7566 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7567 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7568 | fail_unlock_rcu: |
| 7569 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7570 | nla_put_failure: |
| 7571 | genlmsg_cancel(msg, hdr); |
| 7572 | return -EMSGSIZE; |
| 7573 | } |
| 7574 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7575 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7576 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7577 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7578 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7579 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7580 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7581 | int err; |
| 7582 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7583 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7584 | if (err) |
| 7585 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7586 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7587 | wdev_lock(wdev); |
| 7588 | spin_lock_bh(&rdev->bss_lock); |
| 7589 | cfg80211_bss_expire(rdev); |
| 7590 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7591 | cb->seq = rdev->bss_generation; |
| 7592 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7593 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7594 | if (++idx <= start) |
| 7595 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7596 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7597 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7598 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7599 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7600 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7601 | } |
| 7602 | } |
| 7603 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7604 | spin_unlock_bh(&rdev->bss_lock); |
| 7605 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7606 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7607 | cb->args[2] = idx; |
| 7608 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7609 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7610 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7611 | } |
| 7612 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7613 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7614 | int flags, struct net_device *dev, |
| 7615 | bool allow_radio_stats, |
| 7616 | struct survey_info *survey) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7617 | { |
| 7618 | void *hdr; |
| 7619 | struct nlattr *infoattr; |
| 7620 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7621 | /* skip radio stats if userspace didn't request them */ |
| 7622 | if (!survey->channel && !allow_radio_stats) |
| 7623 | return 0; |
| 7624 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7625 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7626 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 7627 | if (!hdr) |
| 7628 | return -ENOMEM; |
| 7629 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7630 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 7631 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7632 | |
| 7633 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 7634 | if (!infoattr) |
| 7635 | goto nla_put_failure; |
| 7636 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7637 | if (survey->channel && |
| 7638 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7639 | survey->channel->center_freq)) |
| 7640 | goto nla_put_failure; |
| 7641 | |
| 7642 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 7643 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 7644 | goto nla_put_failure; |
| 7645 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 7646 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 7647 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7648 | if ((survey->filled & SURVEY_INFO_TIME) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7649 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, |
| 7650 | survey->time, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7651 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7652 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7653 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
| 7654 | survey->time_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7655 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7656 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7657 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
| 7658 | survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7659 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7660 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7661 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, |
| 7662 | survey->time_rx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7663 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7664 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7665 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, |
| 7666 | survey->time_tx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7667 | goto nla_put_failure; |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 7668 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7669 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
| 7670 | survey->time_scan, NL80211_SURVEY_INFO_PAD)) |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 7671 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7672 | |
| 7673 | nla_nest_end(msg, infoattr); |
| 7674 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 7675 | genlmsg_end(msg, hdr); |
| 7676 | return 0; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7677 | |
| 7678 | nla_put_failure: |
| 7679 | genlmsg_cancel(msg, hdr); |
| 7680 | return -EMSGSIZE; |
| 7681 | } |
| 7682 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7683 | static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7684 | { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 7685 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7686 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7687 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7688 | struct wireless_dev *wdev; |
| 7689 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7690 | int res; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7691 | bool radio_stats; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7692 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7693 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7694 | if (res) |
| 7695 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7696 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7697 | /* prepare_wdev_dump parsed the attributes */ |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 7698 | radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7699 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7700 | if (!wdev->netdev) { |
| 7701 | res = -EINVAL; |
| 7702 | goto out_err; |
| 7703 | } |
| 7704 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7705 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7706 | res = -EOPNOTSUPP; |
| 7707 | goto out_err; |
| 7708 | } |
| 7709 | |
| 7710 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7711 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7712 | if (res == -ENOENT) |
| 7713 | break; |
| 7714 | if (res) |
| 7715 | goto out_err; |
| 7716 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7717 | /* don't send disabled channels, but do send non-channel data */ |
| 7718 | if (survey.channel && |
| 7719 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 7720 | survey_idx++; |
| 7721 | continue; |
| 7722 | } |
| 7723 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7724 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7725 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7726 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7727 | wdev->netdev, radio_stats, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7728 | goto out; |
| 7729 | survey_idx++; |
| 7730 | } |
| 7731 | |
| 7732 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7733 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7734 | res = skb->len; |
| 7735 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7736 | nl80211_finish_wdev_dump(rdev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7737 | return res; |
| 7738 | } |
| 7739 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7740 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 7741 | { |
| 7742 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 7743 | NL80211_WPA_VERSION_2)); |
| 7744 | } |
| 7745 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7746 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 7747 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7748 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7749 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7750 | struct ieee80211_channel *chan; |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 7751 | const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL; |
| 7752 | int err, ssid_len, ie_len = 0, auth_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7753 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7754 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7755 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7756 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7757 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7758 | return -EINVAL; |
| 7759 | |
| 7760 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7761 | return -EINVAL; |
| 7762 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 7763 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 7764 | return -EINVAL; |
| 7765 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7766 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 7767 | return -EINVAL; |
| 7768 | |
| 7769 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7770 | return -EINVAL; |
| 7771 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7772 | err = nl80211_parse_key(info, &key); |
| 7773 | if (err) |
| 7774 | return err; |
| 7775 | |
| 7776 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 7777 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 7778 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7779 | if (!key.p.key || !key.p.key_len) |
| 7780 | return -EINVAL; |
| 7781 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 7782 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 7783 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 7784 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 7785 | return -EINVAL; |
Johannes Berg | b6b5555 | 2016-09-13 16:25:58 +0200 | [diff] [blame] | 7786 | if (key.idx > 3) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7787 | return -EINVAL; |
| 7788 | } else { |
| 7789 | key.p.key_len = 0; |
| 7790 | key.p.key = NULL; |
| 7791 | } |
| 7792 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 7793 | if (key.idx >= 0) { |
| 7794 | int i; |
| 7795 | bool ok = false; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 7796 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 7797 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 7798 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 7799 | ok = true; |
| 7800 | break; |
| 7801 | } |
| 7802 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7803 | if (!ok) |
| 7804 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 7805 | } |
| 7806 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7807 | if (!rdev->ops->auth) |
| 7808 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7809 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7810 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7811 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7812 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7813 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7814 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7815 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 7816 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7817 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7818 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7819 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7820 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7821 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7822 | |
| 7823 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7824 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7825 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7826 | } |
| 7827 | |
| 7828 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7829 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7830 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7831 | |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 7832 | if ((auth_type == NL80211_AUTHTYPE_SAE || |
| 7833 | auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 7834 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 7835 | auth_type == NL80211_AUTHTYPE_FILS_PK) && |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 7836 | !info->attrs[NL80211_ATTR_AUTH_DATA]) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7837 | return -EINVAL; |
| 7838 | |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 7839 | if (info->attrs[NL80211_ATTR_AUTH_DATA]) { |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 7840 | if (auth_type != NL80211_AUTHTYPE_SAE && |
| 7841 | auth_type != NL80211_AUTHTYPE_FILS_SK && |
| 7842 | auth_type != NL80211_AUTHTYPE_FILS_SK_PFS && |
| 7843 | auth_type != NL80211_AUTHTYPE_FILS_PK) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7844 | return -EINVAL; |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 7845 | auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]); |
| 7846 | auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7847 | /* need to include at least Auth Transaction and Status Code */ |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 7848 | if (auth_data_len < 4) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7849 | return -EINVAL; |
| 7850 | } |
| 7851 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7852 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7853 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 7854 | /* |
| 7855 | * Since we no longer track auth state, ignore |
| 7856 | * requests to only change local state. |
| 7857 | */ |
| 7858 | if (local_state_change) |
| 7859 | return 0; |
| 7860 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7861 | wdev_lock(dev->ieee80211_ptr); |
| 7862 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 7863 | ssid, ssid_len, ie, ie_len, |
| 7864 | key.p.key, key.p.key_len, key.idx, |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 7865 | auth_data, auth_data_len); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7866 | wdev_unlock(dev->ieee80211_ptr); |
| 7867 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7868 | } |
| 7869 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7870 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 7871 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7872 | struct cfg80211_crypto_settings *settings, |
| 7873 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7874 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 7875 | memset(settings, 0, sizeof(*settings)); |
| 7876 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7877 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 7878 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7879 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 7880 | u16 proto; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 7881 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7882 | proto = nla_get_u16( |
| 7883 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 7884 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 7885 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 7886 | proto != ETH_P_PAE) |
| 7887 | return -EINVAL; |
| 7888 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 7889 | settings->control_port_no_encrypt = true; |
| 7890 | } else |
| 7891 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 7892 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7893 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 7894 | void *data; |
| 7895 | int len, i; |
| 7896 | |
| 7897 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 7898 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 7899 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 7900 | |
| 7901 | if (len % sizeof(u32)) |
| 7902 | return -EINVAL; |
| 7903 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7904 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7905 | return -EINVAL; |
| 7906 | |
| 7907 | memcpy(settings->ciphers_pairwise, data, len); |
| 7908 | |
| 7909 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 7910 | if (!cfg80211_supported_cipher_suite( |
| 7911 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7912 | settings->ciphers_pairwise[i])) |
| 7913 | return -EINVAL; |
| 7914 | } |
| 7915 | |
| 7916 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 7917 | settings->cipher_group = |
| 7918 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 7919 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 7920 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7921 | return -EINVAL; |
| 7922 | } |
| 7923 | |
| 7924 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 7925 | settings->wpa_versions = |
| 7926 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 7927 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 7928 | return -EINVAL; |
| 7929 | } |
| 7930 | |
| 7931 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 7932 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 7933 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7934 | |
| 7935 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 7936 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 7937 | settings->n_akm_suites = len / sizeof(u32); |
| 7938 | |
| 7939 | if (len % sizeof(u32)) |
| 7940 | return -EINVAL; |
| 7941 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 7942 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 7943 | return -EINVAL; |
| 7944 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7945 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7946 | } |
| 7947 | |
| 7948 | return 0; |
| 7949 | } |
| 7950 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7951 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 7952 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7953 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7954 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 7955 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7956 | struct cfg80211_assoc_request req = {}; |
| 7957 | const u8 *bssid, *ssid; |
| 7958 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7959 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7960 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7961 | return -EINVAL; |
| 7962 | |
| 7963 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7964 | !info->attrs[NL80211_ATTR_SSID] || |
| 7965 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7966 | return -EINVAL; |
| 7967 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7968 | if (!rdev->ops->assoc) |
| 7969 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7970 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7971 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7972 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7973 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7974 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7975 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7976 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7977 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 7978 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7979 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7980 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7981 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7982 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7983 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7984 | |
| 7985 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7986 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7987 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7988 | } |
| 7989 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7990 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 7991 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7992 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 7993 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7994 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7995 | else if (mfp != NL80211_MFP_NO) |
| 7996 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 7997 | } |
| 7998 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 7999 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8000 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 8001 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8002 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8003 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8004 | |
| 8005 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8006 | memcpy(&req.ht_capa_mask, |
| 8007 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 8008 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8009 | |
| 8010 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8011 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8012 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8013 | memcpy(&req.ht_capa, |
| 8014 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 8015 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8016 | } |
| 8017 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8018 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8019 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8020 | |
| 8021 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8022 | memcpy(&req.vht_capa_mask, |
| 8023 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 8024 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8025 | |
| 8026 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8027 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8028 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8029 | memcpy(&req.vht_capa, |
| 8030 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 8031 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8032 | } |
| 8033 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8034 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 8035 | if (!((rdev->wiphy.features & |
| 8036 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 8037 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 8038 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 8039 | NL80211_EXT_FEATURE_RRM)) |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8040 | return -EINVAL; |
| 8041 | req.flags |= ASSOC_REQ_USE_RRM; |
| 8042 | } |
| 8043 | |
Jouni Malinen | 348bd45 | 2016-10-27 00:42:03 +0300 | [diff] [blame] | 8044 | if (info->attrs[NL80211_ATTR_FILS_KEK]) { |
| 8045 | req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 8046 | req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 8047 | if (!info->attrs[NL80211_ATTR_FILS_NONCES]) |
| 8048 | return -EINVAL; |
| 8049 | req.fils_nonces = |
| 8050 | nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); |
| 8051 | } |
| 8052 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8053 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8054 | if (!err) { |
| 8055 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8056 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 8057 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8058 | wdev_unlock(dev->ieee80211_ptr); |
| 8059 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8060 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8061 | return err; |
| 8062 | } |
| 8063 | |
| 8064 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 8065 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8066 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8067 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8068 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8069 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8070 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8071 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8072 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8073 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8074 | return -EINVAL; |
| 8075 | |
| 8076 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8077 | return -EINVAL; |
| 8078 | |
| 8079 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 8080 | return -EINVAL; |
| 8081 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8082 | if (!rdev->ops->deauth) |
| 8083 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8084 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8085 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8086 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8087 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8088 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8089 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8090 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8091 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 8092 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8093 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8094 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 8095 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8096 | |
| 8097 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8098 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8099 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8100 | } |
| 8101 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8102 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 8103 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8104 | wdev_lock(dev->ieee80211_ptr); |
| 8105 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 8106 | local_state_change); |
| 8107 | wdev_unlock(dev->ieee80211_ptr); |
| 8108 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8109 | } |
| 8110 | |
| 8111 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 8112 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8113 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8114 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8115 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8116 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8117 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8118 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8119 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8120 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8121 | return -EINVAL; |
| 8122 | |
| 8123 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8124 | return -EINVAL; |
| 8125 | |
| 8126 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 8127 | return -EINVAL; |
| 8128 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8129 | if (!rdev->ops->disassoc) |
| 8130 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8131 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8132 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8133 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8134 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8135 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8136 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8137 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8138 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 8139 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8140 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8141 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 8142 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8143 | |
| 8144 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8145 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8146 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8147 | } |
| 8148 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8149 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 8150 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8151 | wdev_lock(dev->ieee80211_ptr); |
| 8152 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 8153 | local_state_change); |
| 8154 | wdev_unlock(dev->ieee80211_ptr); |
| 8155 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8156 | } |
| 8157 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8158 | static bool |
| 8159 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8160 | int mcast_rate[NUM_NL80211_BANDS], |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8161 | int rateval) |
| 8162 | { |
| 8163 | struct wiphy *wiphy = &rdev->wiphy; |
| 8164 | bool found = false; |
| 8165 | int band, i; |
| 8166 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8167 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8168 | struct ieee80211_supported_band *sband; |
| 8169 | |
| 8170 | sband = wiphy->bands[band]; |
| 8171 | if (!sband) |
| 8172 | continue; |
| 8173 | |
| 8174 | for (i = 0; i < sband->n_bitrates; i++) { |
| 8175 | if (sband->bitrates[i].bitrate == rateval) { |
| 8176 | mcast_rate[band] = i + 1; |
| 8177 | found = true; |
| 8178 | break; |
| 8179 | } |
| 8180 | } |
| 8181 | } |
| 8182 | |
| 8183 | return found; |
| 8184 | } |
| 8185 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8186 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 8187 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8188 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8189 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8190 | struct cfg80211_ibss_params ibss; |
| 8191 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8192 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8193 | int err; |
| 8194 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8195 | memset(&ibss, 0, sizeof(ibss)); |
| 8196 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8197 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8198 | return -EINVAL; |
| 8199 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8200 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8201 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 8202 | return -EINVAL; |
| 8203 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8204 | ibss.beacon_interval = 100; |
| 8205 | |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 8206 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8207 | ibss.beacon_interval = |
| 8208 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 8209 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 8210 | err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC, |
| 8211 | ibss.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 8212 | if (err) |
| 8213 | return err; |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8214 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8215 | if (!rdev->ops->join_ibss) |
| 8216 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8217 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8218 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 8219 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8220 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8221 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8222 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 8223 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8224 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 8225 | |
| 8226 | if (!is_valid_ether_addr(ibss.bssid)) |
| 8227 | return -EINVAL; |
| 8228 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8229 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8230 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 8231 | |
| 8232 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8233 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8234 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8235 | } |
| 8236 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8237 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 8238 | if (err) |
| 8239 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 8240 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 8241 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 8242 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 8243 | return -EINVAL; |
| 8244 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8245 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 8246 | case NL80211_CHAN_WIDTH_5: |
| 8247 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8248 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 8249 | break; |
| 8250 | case NL80211_CHAN_WIDTH_20: |
| 8251 | case NL80211_CHAN_WIDTH_40: |
Janusz.Dziedzic@tieto.com | ffc1199 | 2015-02-21 16:52:39 +0100 | [diff] [blame] | 8252 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 8253 | return -EINVAL; |
| 8254 | break; |
| 8255 | case NL80211_CHAN_WIDTH_80: |
| 8256 | case NL80211_CHAN_WIDTH_80P80: |
| 8257 | case NL80211_CHAN_WIDTH_160: |
| 8258 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 8259 | return -EINVAL; |
| 8260 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 8261 | NL80211_EXT_FEATURE_VHT_IBSS)) |
| 8262 | return -EINVAL; |
| 8263 | break; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8264 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 8265 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8266 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 8267 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8268 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8269 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8270 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8271 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 8272 | u8 *rates = |
| 8273 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8274 | int n_rates = |
| 8275 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8276 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8277 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8278 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 8279 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 8280 | &ibss.basic_rates); |
| 8281 | if (err) |
| 8282 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8283 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8284 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 8285 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 8286 | memcpy(&ibss.ht_capa_mask, |
| 8287 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 8288 | sizeof(ibss.ht_capa_mask)); |
| 8289 | |
| 8290 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 8291 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 8292 | return -EINVAL; |
| 8293 | memcpy(&ibss.ht_capa, |
| 8294 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 8295 | sizeof(ibss.ht_capa)); |
| 8296 | } |
| 8297 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8298 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 8299 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 8300 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 8301 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8302 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8303 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8304 | bool no_ht = false; |
| 8305 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8306 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8307 | info->attrs[NL80211_ATTR_KEYS], |
| 8308 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8309 | if (IS_ERR(connkeys)) |
| 8310 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8311 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 8312 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 8313 | no_ht) { |
Ola Olsson | 5e950a7 | 2016-02-11 01:00:22 +0100 | [diff] [blame] | 8314 | kzfree(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8315 | return -EINVAL; |
| 8316 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8317 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8318 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 8319 | ibss.control_port = |
| 8320 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 8321 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 8322 | ibss.userspace_handles_dfs = |
| 8323 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 8324 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8325 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8326 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8327 | kzfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8328 | return err; |
| 8329 | } |
| 8330 | |
| 8331 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 8332 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8333 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8334 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8335 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8336 | if (!rdev->ops->leave_ibss) |
| 8337 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8338 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8339 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 8340 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8341 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8342 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8343 | } |
| 8344 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8345 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 8346 | { |
| 8347 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8348 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8349 | int mcast_rate[NUM_NL80211_BANDS]; |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8350 | u32 nla_rate; |
| 8351 | int err; |
| 8352 | |
| 8353 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Bertold Van den Bergh | 876dc93 | 2015-08-05 16:02:21 +0200 | [diff] [blame] | 8354 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
| 8355 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8356 | return -EOPNOTSUPP; |
| 8357 | |
| 8358 | if (!rdev->ops->set_mcast_rate) |
| 8359 | return -EOPNOTSUPP; |
| 8360 | |
| 8361 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 8362 | |
| 8363 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 8364 | return -EINVAL; |
| 8365 | |
| 8366 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 8367 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 8368 | return -EINVAL; |
| 8369 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 8370 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8371 | |
| 8372 | return err; |
| 8373 | } |
| 8374 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8375 | static struct sk_buff * |
| 8376 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8377 | struct wireless_dev *wdev, int approxlen, |
| 8378 | u32 portid, u32 seq, enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 8379 | enum nl80211_attrs attr, |
| 8380 | const struct nl80211_vendor_cmd_info *info, |
| 8381 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8382 | { |
| 8383 | struct sk_buff *skb; |
| 8384 | void *hdr; |
| 8385 | struct nlattr *data; |
| 8386 | |
| 8387 | skb = nlmsg_new(approxlen + 100, gfp); |
| 8388 | if (!skb) |
| 8389 | return NULL; |
| 8390 | |
| 8391 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 8392 | if (!hdr) { |
| 8393 | kfree_skb(skb); |
| 8394 | return NULL; |
| 8395 | } |
| 8396 | |
| 8397 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 8398 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 8399 | |
| 8400 | if (info) { |
| 8401 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 8402 | info->vendor_id)) |
| 8403 | goto nla_put_failure; |
| 8404 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 8405 | info->subcmd)) |
| 8406 | goto nla_put_failure; |
| 8407 | } |
| 8408 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8409 | if (wdev) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8410 | if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 8411 | wdev_id(wdev), NL80211_ATTR_PAD)) |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8412 | goto nla_put_failure; |
| 8413 | if (wdev->netdev && |
| 8414 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, |
| 8415 | wdev->netdev->ifindex)) |
| 8416 | goto nla_put_failure; |
| 8417 | } |
| 8418 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8419 | data = nla_nest_start(skb, attr); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 8420 | if (!data) |
| 8421 | goto nla_put_failure; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8422 | |
| 8423 | ((void **)skb->cb)[0] = rdev; |
| 8424 | ((void **)skb->cb)[1] = hdr; |
| 8425 | ((void **)skb->cb)[2] = data; |
| 8426 | |
| 8427 | return skb; |
| 8428 | |
| 8429 | nla_put_failure: |
| 8430 | kfree_skb(skb); |
| 8431 | return NULL; |
| 8432 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8433 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8434 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8435 | struct wireless_dev *wdev, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8436 | enum nl80211_commands cmd, |
| 8437 | enum nl80211_attrs attr, |
| 8438 | int vendor_event_idx, |
| 8439 | int approxlen, gfp_t gfp) |
| 8440 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 8441 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8442 | const struct nl80211_vendor_cmd_info *info; |
| 8443 | |
| 8444 | switch (cmd) { |
| 8445 | case NL80211_CMD_TESTMODE: |
| 8446 | if (WARN_ON(vendor_event_idx != -1)) |
| 8447 | return NULL; |
| 8448 | info = NULL; |
| 8449 | break; |
| 8450 | case NL80211_CMD_VENDOR: |
| 8451 | if (WARN_ON(vendor_event_idx < 0 || |
| 8452 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 8453 | return NULL; |
| 8454 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 8455 | break; |
| 8456 | default: |
| 8457 | WARN_ON(1); |
| 8458 | return NULL; |
| 8459 | } |
| 8460 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8461 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8462 | cmd, attr, info, gfp); |
| 8463 | } |
| 8464 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 8465 | |
| 8466 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 8467 | { |
| 8468 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 8469 | void *hdr = ((void **)skb->cb)[1]; |
| 8470 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 8471 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 8472 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 8473 | /* clear CB data for netlink core to own from now on */ |
| 8474 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 8475 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8476 | nla_nest_end(skb, data); |
| 8477 | genlmsg_end(skb, hdr); |
| 8478 | |
| 8479 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 8480 | mcgrp = NL80211_MCGRP_VENDOR; |
| 8481 | |
| 8482 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 8483 | mcgrp, gfp); |
| 8484 | } |
| 8485 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 8486 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8487 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8488 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 8489 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8490 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8491 | struct wireless_dev *wdev = |
| 8492 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8493 | int err; |
| 8494 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8495 | if (!rdev->ops->testmode_cmd) |
| 8496 | return -EOPNOTSUPP; |
| 8497 | |
| 8498 | if (IS_ERR(wdev)) { |
| 8499 | err = PTR_ERR(wdev); |
| 8500 | if (err != -EINVAL) |
| 8501 | return err; |
| 8502 | wdev = NULL; |
| 8503 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 8504 | return -EINVAL; |
| 8505 | } |
| 8506 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8507 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 8508 | return -EINVAL; |
| 8509 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8510 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8511 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8512 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 8513 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8514 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8515 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8516 | return err; |
| 8517 | } |
| 8518 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8519 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 8520 | struct netlink_callback *cb) |
| 8521 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8522 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8523 | int err; |
| 8524 | long phy_idx; |
| 8525 | void *data = NULL; |
| 8526 | int data_len = 0; |
| 8527 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8528 | rtnl_lock(); |
| 8529 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8530 | if (cb->args[0]) { |
| 8531 | /* |
| 8532 | * 0 is a valid index, but not valid for args[0], |
| 8533 | * so we need to offset by 1. |
| 8534 | */ |
| 8535 | phy_idx = cb->args[0] - 1; |
| 8536 | } else { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 8537 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
| 8538 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8539 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 8540 | attrbuf, nl80211_fam.maxattr, nl80211_policy); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8541 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8542 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8543 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 8544 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8545 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8546 | err = PTR_ERR(rdev); |
| 8547 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8548 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8549 | phy_idx = rdev->wiphy_idx; |
| 8550 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8551 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 8552 | if (attrbuf[NL80211_ATTR_TESTDATA]) |
| 8553 | cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA]; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8554 | } |
| 8555 | |
| 8556 | if (cb->args[1]) { |
| 8557 | data = nla_data((void *)cb->args[1]); |
| 8558 | data_len = nla_len((void *)cb->args[1]); |
| 8559 | } |
| 8560 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8561 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 8562 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8563 | err = -ENOENT; |
| 8564 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8565 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8566 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8567 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8568 | err = -EOPNOTSUPP; |
| 8569 | goto out_err; |
| 8570 | } |
| 8571 | |
| 8572 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8573 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8574 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 8575 | NL80211_CMD_TESTMODE); |
| 8576 | struct nlattr *tmdata; |
| 8577 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8578 | if (!hdr) |
| 8579 | break; |
| 8580 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8581 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8582 | genlmsg_cancel(skb, hdr); |
| 8583 | break; |
| 8584 | } |
| 8585 | |
| 8586 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 8587 | if (!tmdata) { |
| 8588 | genlmsg_cancel(skb, hdr); |
| 8589 | break; |
| 8590 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8591 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8592 | nla_nest_end(skb, tmdata); |
| 8593 | |
| 8594 | if (err == -ENOBUFS || err == -ENOENT) { |
| 8595 | genlmsg_cancel(skb, hdr); |
| 8596 | break; |
| 8597 | } else if (err) { |
| 8598 | genlmsg_cancel(skb, hdr); |
| 8599 | goto out_err; |
| 8600 | } |
| 8601 | |
| 8602 | genlmsg_end(skb, hdr); |
| 8603 | } |
| 8604 | |
| 8605 | err = skb->len; |
| 8606 | /* see above */ |
| 8607 | cb->args[0] = phy_idx + 1; |
| 8608 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8609 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8610 | return err; |
| 8611 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8612 | #endif |
| 8613 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8614 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 8615 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8616 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8617 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8618 | struct cfg80211_connect_params connect; |
| 8619 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8620 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8621 | int err; |
| 8622 | |
| 8623 | memset(&connect, 0, sizeof(connect)); |
| 8624 | |
| 8625 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8626 | return -EINVAL; |
| 8627 | |
| 8628 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 8629 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 8630 | return -EINVAL; |
| 8631 | |
| 8632 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 8633 | connect.auth_type = |
| 8634 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8635 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 8636 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8637 | return -EINVAL; |
| 8638 | } else |
| 8639 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 8640 | |
| 8641 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 8642 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8643 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 8644 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8645 | if (err) |
| 8646 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8647 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8648 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8649 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8650 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8651 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8652 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8653 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 8654 | connect.bg_scan_period = -1; |
| 8655 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 8656 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 8657 | connect.bg_scan_period = |
| 8658 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 8659 | } |
| 8660 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8661 | if (info->attrs[NL80211_ATTR_MAC]) |
| 8662 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8663 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 8664 | connect.bssid_hint = |
| 8665 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8666 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8667 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 8668 | |
| 8669 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8670 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8671 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8672 | } |
| 8673 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 8674 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 8675 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 8676 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 8677 | connect.mfp != NL80211_MFP_NO) |
| 8678 | return -EINVAL; |
| 8679 | } else { |
| 8680 | connect.mfp = NL80211_MFP_NO; |
| 8681 | } |
| 8682 | |
Jouni Malinen | ba6fbac | 2016-03-29 13:53:27 +0300 | [diff] [blame] | 8683 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 8684 | connect.prev_bssid = |
| 8685 | nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 8686 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8687 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8688 | connect.channel = nl80211_get_valid_chan( |
| 8689 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 8690 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8691 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8692 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8693 | connect.channel_hint = nl80211_get_valid_chan( |
| 8694 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 8695 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8696 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8697 | } |
| 8698 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8699 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 8700 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8701 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8702 | if (IS_ERR(connkeys)) |
| 8703 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8704 | } |
| 8705 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8706 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 8707 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 8708 | |
| 8709 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 8710 | memcpy(&connect.ht_capa_mask, |
| 8711 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 8712 | sizeof(connect.ht_capa_mask)); |
| 8713 | |
| 8714 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 8715 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8716 | kzfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8717 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 8718 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8719 | memcpy(&connect.ht_capa, |
| 8720 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 8721 | sizeof(connect.ht_capa)); |
| 8722 | } |
| 8723 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8724 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 8725 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 8726 | |
| 8727 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 8728 | memcpy(&connect.vht_capa_mask, |
| 8729 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 8730 | sizeof(connect.vht_capa_mask)); |
| 8731 | |
| 8732 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 8733 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8734 | kzfree(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8735 | return -EINVAL; |
| 8736 | } |
| 8737 | memcpy(&connect.vht_capa, |
| 8738 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 8739 | sizeof(connect.vht_capa)); |
| 8740 | } |
| 8741 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8742 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 8743 | if (!((rdev->wiphy.features & |
| 8744 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 8745 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 8746 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 8747 | NL80211_EXT_FEATURE_RRM)) { |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 8748 | kzfree(connkeys); |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8749 | return -EINVAL; |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 8750 | } |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8751 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 8752 | } |
| 8753 | |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 8754 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8755 | if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 8756 | kzfree(connkeys); |
| 8757 | return -EOPNOTSUPP; |
| 8758 | } |
| 8759 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 8760 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { |
| 8761 | /* bss selection makes no sense if bssid is set */ |
| 8762 | if (connect.bssid) { |
| 8763 | kzfree(connkeys); |
| 8764 | return -EINVAL; |
| 8765 | } |
| 8766 | |
| 8767 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], |
| 8768 | wiphy, &connect.bss_select); |
| 8769 | if (err) { |
| 8770 | kzfree(connkeys); |
| 8771 | return err; |
| 8772 | } |
| 8773 | } |
| 8774 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8775 | wdev_lock(dev->ieee80211_ptr); |
Jouni Malinen | 4ce2bd9c4 | 2016-03-29 13:53:28 +0300 | [diff] [blame] | 8776 | err = cfg80211_connect(rdev, dev, &connect, connkeys, |
| 8777 | connect.prev_bssid); |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8778 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8779 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8780 | kzfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8781 | return err; |
| 8782 | } |
| 8783 | |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 8784 | static int nl80211_update_connect_params(struct sk_buff *skb, |
| 8785 | struct genl_info *info) |
| 8786 | { |
| 8787 | struct cfg80211_connect_params connect = {}; |
| 8788 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8789 | struct net_device *dev = info->user_ptr[1]; |
| 8790 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8791 | u32 changed = 0; |
| 8792 | int ret; |
| 8793 | |
| 8794 | if (!rdev->ops->update_connect_params) |
| 8795 | return -EOPNOTSUPP; |
| 8796 | |
| 8797 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8798 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8799 | return -EINVAL; |
| 8800 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8801 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8802 | changed |= UPDATE_ASSOC_IES; |
| 8803 | } |
| 8804 | |
| 8805 | wdev_lock(dev->ieee80211_ptr); |
| 8806 | if (!wdev->current_bss) |
| 8807 | ret = -ENOLINK; |
| 8808 | else |
| 8809 | ret = rdev_update_connect_params(rdev, dev, &connect, changed); |
| 8810 | wdev_unlock(dev->ieee80211_ptr); |
| 8811 | |
| 8812 | return ret; |
| 8813 | } |
| 8814 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8815 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 8816 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8817 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8818 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8819 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8820 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8821 | |
| 8822 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 8823 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 8824 | else |
| 8825 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 8826 | |
| 8827 | if (reason == 0) |
| 8828 | return -EINVAL; |
| 8829 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8830 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8831 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8832 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8833 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8834 | wdev_lock(dev->ieee80211_ptr); |
| 8835 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 8836 | wdev_unlock(dev->ieee80211_ptr); |
| 8837 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8838 | } |
| 8839 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8840 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 8841 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8842 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8843 | struct net *net; |
| 8844 | int err; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8845 | |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 8846 | if (info->attrs[NL80211_ATTR_PID]) { |
| 8847 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 8848 | |
| 8849 | net = get_net_ns_by_pid(pid); |
| 8850 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { |
| 8851 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); |
| 8852 | |
| 8853 | net = get_net_ns_by_fd(fd); |
| 8854 | } else { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8855 | return -EINVAL; |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 8856 | } |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8857 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8858 | if (IS_ERR(net)) |
| 8859 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8860 | |
| 8861 | err = 0; |
| 8862 | |
| 8863 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8864 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 8865 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8866 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8867 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 8868 | return err; |
| 8869 | } |
| 8870 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8871 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 8872 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8873 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8874 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 8875 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8876 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8877 | struct cfg80211_pmksa pmksa; |
| 8878 | |
| 8879 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 8880 | |
| 8881 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8882 | return -EINVAL; |
| 8883 | |
| 8884 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 8885 | return -EINVAL; |
| 8886 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8887 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 8888 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8889 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8890 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8891 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8892 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8893 | |
| 8894 | switch (info->genlhdr->cmd) { |
| 8895 | case NL80211_CMD_SET_PMKSA: |
| 8896 | rdev_ops = rdev->ops->set_pmksa; |
| 8897 | break; |
| 8898 | case NL80211_CMD_DEL_PMKSA: |
| 8899 | rdev_ops = rdev->ops->del_pmksa; |
| 8900 | break; |
| 8901 | default: |
| 8902 | WARN_ON(1); |
| 8903 | break; |
| 8904 | } |
| 8905 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8906 | if (!rdev_ops) |
| 8907 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8908 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8909 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8910 | } |
| 8911 | |
| 8912 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 8913 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8914 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8915 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8916 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8917 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8918 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8919 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8920 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8921 | if (!rdev->ops->flush_pmksa) |
| 8922 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8923 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8924 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 8925 | } |
| 8926 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8927 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 8928 | { |
| 8929 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8930 | struct net_device *dev = info->user_ptr[1]; |
| 8931 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 8932 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8933 | u16 status_code; |
| 8934 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 8935 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8936 | |
| 8937 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 8938 | !rdev->ops->tdls_mgmt) |
| 8939 | return -EOPNOTSUPP; |
| 8940 | |
| 8941 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 8942 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 8943 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 8944 | !info->attrs[NL80211_ATTR_IE] || |
| 8945 | !info->attrs[NL80211_ATTR_MAC]) |
| 8946 | return -EINVAL; |
| 8947 | |
| 8948 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8949 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 8950 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 8951 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 8952 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 8953 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 8954 | peer_capability = |
| 8955 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8956 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8957 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 8958 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 8959 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8960 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 8961 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8962 | } |
| 8963 | |
| 8964 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 8965 | { |
| 8966 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8967 | struct net_device *dev = info->user_ptr[1]; |
| 8968 | enum nl80211_tdls_operation operation; |
| 8969 | u8 *peer; |
| 8970 | |
| 8971 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 8972 | !rdev->ops->tdls_oper) |
| 8973 | return -EOPNOTSUPP; |
| 8974 | |
| 8975 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 8976 | !info->attrs[NL80211_ATTR_MAC]) |
| 8977 | return -EINVAL; |
| 8978 | |
| 8979 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 8980 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 8981 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8982 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 8983 | } |
| 8984 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8985 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 8986 | struct genl_info *info) |
| 8987 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8988 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8989 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8990 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8991 | struct sk_buff *msg; |
| 8992 | void *hdr; |
| 8993 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8994 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 8995 | int err; |
| 8996 | |
| 8997 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 8998 | !info->attrs[NL80211_ATTR_DURATION]) |
| 8999 | return -EINVAL; |
| 9000 | |
| 9001 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 9002 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 9003 | if (!rdev->ops->remain_on_channel || |
| 9004 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9005 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9006 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 9007 | /* |
| 9008 | * We should be on that channel for at least a minimum amount of |
| 9009 | * time (10ms) but no longer than the driver supports. |
| 9010 | */ |
| 9011 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 9012 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 9013 | return -EINVAL; |
| 9014 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9015 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 9016 | if (err) |
| 9017 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9018 | |
| 9019 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9020 | if (!msg) |
| 9021 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9022 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9023 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9024 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9025 | if (!hdr) { |
| 9026 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9027 | goto free_msg; |
| 9028 | } |
| 9029 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9030 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 9031 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9032 | |
| 9033 | if (err) |
| 9034 | goto free_msg; |
| 9035 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9036 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 9037 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9038 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9039 | |
| 9040 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9041 | |
| 9042 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9043 | |
| 9044 | nla_put_failure: |
| 9045 | err = -ENOBUFS; |
| 9046 | free_msg: |
| 9047 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9048 | return err; |
| 9049 | } |
| 9050 | |
| 9051 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 9052 | struct genl_info *info) |
| 9053 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9054 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9055 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9056 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9057 | |
| 9058 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 9059 | return -EINVAL; |
| 9060 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9061 | if (!rdev->ops->cancel_remain_on_channel) |
| 9062 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9063 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9064 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 9065 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9066 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9067 | } |
| 9068 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9069 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 9070 | struct genl_info *info) |
| 9071 | { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9072 | struct cfg80211_bitrate_mask mask; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 9073 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9074 | struct net_device *dev = info->user_ptr[1]; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 9075 | int err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9076 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9077 | if (!rdev->ops->set_bitrate_mask) |
| 9078 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9079 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 9080 | err = nl80211_parse_tx_bitrate_mask(info, &mask); |
| 9081 | if (err) |
| 9082 | return err; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 9083 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9084 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9085 | } |
| 9086 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9087 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9088 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9089 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9090 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9091 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9092 | |
| 9093 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 9094 | return -EINVAL; |
| 9095 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9096 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 9097 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9098 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9099 | switch (wdev->iftype) { |
| 9100 | case NL80211_IFTYPE_STATION: |
| 9101 | case NL80211_IFTYPE_ADHOC: |
| 9102 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9103 | case NL80211_IFTYPE_AP: |
| 9104 | case NL80211_IFTYPE_AP_VLAN: |
| 9105 | case NL80211_IFTYPE_MESH_POINT: |
| 9106 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9107 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9108 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 9109 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9110 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9111 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9112 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9113 | |
| 9114 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9115 | if (!rdev->ops->mgmt_tx) |
| 9116 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9117 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9118 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9119 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 9120 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9121 | } |
| 9122 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9123 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9124 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9125 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9126 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9127 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9128 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 9129 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9130 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9131 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9132 | struct cfg80211_mgmt_tx_params params = { |
| 9133 | .dont_wait_for_ack = |
| 9134 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 9135 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9136 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9137 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9138 | return -EINVAL; |
| 9139 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9140 | if (!rdev->ops->mgmt_tx) |
| 9141 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9142 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9143 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 9144 | case NL80211_IFTYPE_P2P_DEVICE: |
| 9145 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 9146 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9147 | case NL80211_IFTYPE_STATION: |
| 9148 | case NL80211_IFTYPE_ADHOC: |
| 9149 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9150 | case NL80211_IFTYPE_AP: |
| 9151 | case NL80211_IFTYPE_AP_VLAN: |
| 9152 | case NL80211_IFTYPE_MESH_POINT: |
| 9153 | case NL80211_IFTYPE_P2P_GO: |
| 9154 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 9155 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9156 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9157 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9158 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9159 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9160 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 9161 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9162 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9163 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 9164 | |
| 9165 | /* |
| 9166 | * We should wait on the channel for at least a minimum amount |
| 9167 | * of time (10ms) but no longer than the driver supports. |
| 9168 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9169 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 9170 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 9171 | return -EINVAL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9172 | } |
| 9173 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9174 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9175 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9176 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 9177 | return -EINVAL; |
| 9178 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9179 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 9180 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 9181 | /* get the channel if any has been specified, otherwise pass NULL to |
| 9182 | * the driver. The latter will use the current one |
| 9183 | */ |
| 9184 | chandef.chan = NULL; |
| 9185 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 9186 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 9187 | if (err) |
| 9188 | return err; |
| 9189 | } |
| 9190 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9191 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 9192 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9193 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 9194 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 9195 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 9196 | |
| 9197 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 9198 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 9199 | int i; |
| 9200 | |
| 9201 | if (len % sizeof(u16)) |
| 9202 | return -EINVAL; |
| 9203 | |
| 9204 | params.n_csa_offsets = len / sizeof(u16); |
| 9205 | params.csa_offsets = |
| 9206 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 9207 | |
| 9208 | /* check that all the offsets fit the frame */ |
| 9209 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 9210 | if (params.csa_offsets[i] >= params.len) |
| 9211 | return -EINVAL; |
| 9212 | } |
| 9213 | } |
| 9214 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9215 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9216 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9217 | if (!msg) |
| 9218 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9219 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9220 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9221 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9222 | if (!hdr) { |
| 9223 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9224 | goto free_msg; |
| 9225 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9226 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9227 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9228 | params.chan = chandef.chan; |
| 9229 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9230 | if (err) |
| 9231 | goto free_msg; |
| 9232 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9233 | if (msg) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9234 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 9235 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9236 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9237 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9238 | genlmsg_end(msg, hdr); |
| 9239 | return genlmsg_reply(msg, info); |
| 9240 | } |
| 9241 | |
| 9242 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9243 | |
| 9244 | nla_put_failure: |
| 9245 | err = -ENOBUFS; |
| 9246 | free_msg: |
| 9247 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9248 | return err; |
| 9249 | } |
| 9250 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9251 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 9252 | { |
| 9253 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9254 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9255 | u64 cookie; |
| 9256 | |
| 9257 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 9258 | return -EINVAL; |
| 9259 | |
| 9260 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 9261 | return -EOPNOTSUPP; |
| 9262 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9263 | switch (wdev->iftype) { |
| 9264 | case NL80211_IFTYPE_STATION: |
| 9265 | case NL80211_IFTYPE_ADHOC: |
| 9266 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9267 | case NL80211_IFTYPE_AP: |
| 9268 | case NL80211_IFTYPE_AP_VLAN: |
| 9269 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9270 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9271 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 9272 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9273 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9274 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9275 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9276 | |
| 9277 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 9278 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9279 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9280 | } |
| 9281 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9282 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 9283 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9284 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9285 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9286 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9287 | u8 ps_state; |
| 9288 | bool state; |
| 9289 | int err; |
| 9290 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9291 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 9292 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9293 | |
| 9294 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 9295 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9296 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 9297 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9298 | |
| 9299 | wdev = dev->ieee80211_ptr; |
| 9300 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9301 | if (!rdev->ops->set_power_mgmt) |
| 9302 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9303 | |
| 9304 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 9305 | |
| 9306 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9307 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9308 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9309 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9310 | if (!err) |
| 9311 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9312 | return err; |
| 9313 | } |
| 9314 | |
| 9315 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 9316 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9317 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9318 | enum nl80211_ps_state ps_state; |
| 9319 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9320 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9321 | struct sk_buff *msg; |
| 9322 | void *hdr; |
| 9323 | int err; |
| 9324 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9325 | wdev = dev->ieee80211_ptr; |
| 9326 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9327 | if (!rdev->ops->set_power_mgmt) |
| 9328 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9329 | |
| 9330 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9331 | if (!msg) |
| 9332 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9333 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9334 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9335 | NL80211_CMD_GET_POWER_SAVE); |
| 9336 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9337 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9338 | goto free_msg; |
| 9339 | } |
| 9340 | |
| 9341 | if (wdev->ps) |
| 9342 | ps_state = NL80211_PS_ENABLED; |
| 9343 | else |
| 9344 | ps_state = NL80211_PS_DISABLED; |
| 9345 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9346 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 9347 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9348 | |
| 9349 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9350 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9351 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9352 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9353 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9354 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9355 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9356 | return err; |
| 9357 | } |
| 9358 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 9359 | static const struct nla_policy |
| 9360 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9361 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 9362 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 9363 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9364 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 9365 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 9366 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9367 | }; |
| 9368 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9369 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 9370 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9371 | { |
| 9372 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9373 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9374 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9375 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 9376 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9377 | return -EINVAL; |
| 9378 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9379 | if (!rdev->ops->set_cqm_txe_config) |
| 9380 | return -EOPNOTSUPP; |
| 9381 | |
| 9382 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 9383 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9384 | return -EOPNOTSUPP; |
| 9385 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9386 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9387 | } |
| 9388 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9389 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 9390 | s32 threshold, u32 hysteresis) |
| 9391 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9392 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9393 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9394 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9395 | |
| 9396 | if (threshold > 0) |
| 9397 | return -EINVAL; |
| 9398 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9399 | /* disabling - hysteresis should also be zero then */ |
| 9400 | if (threshold == 0) |
| 9401 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9402 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9403 | if (!rdev->ops->set_cqm_rssi_config) |
| 9404 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9405 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9406 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9407 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9408 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9409 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9410 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9411 | } |
| 9412 | |
| 9413 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 9414 | { |
| 9415 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 9416 | struct nlattr *cqm; |
| 9417 | int err; |
| 9418 | |
| 9419 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9420 | if (!cqm) |
| 9421 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9422 | |
| 9423 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 9424 | nl80211_attr_cqm_policy); |
| 9425 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9426 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9427 | |
| 9428 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 9429 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9430 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 9431 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9432 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9433 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 9434 | } |
| 9435 | |
| 9436 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 9437 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 9438 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 9439 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 9440 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 9441 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 9442 | |
| 9443 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 9444 | } |
| 9445 | |
| 9446 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9447 | } |
| 9448 | |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 9449 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 9450 | { |
| 9451 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9452 | struct net_device *dev = info->user_ptr[1]; |
| 9453 | struct ocb_setup setup = {}; |
| 9454 | int err; |
| 9455 | |
| 9456 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 9457 | if (err) |
| 9458 | return err; |
| 9459 | |
| 9460 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 9461 | } |
| 9462 | |
| 9463 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 9464 | { |
| 9465 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9466 | struct net_device *dev = info->user_ptr[1]; |
| 9467 | |
| 9468 | return cfg80211_leave_ocb(rdev, dev); |
| 9469 | } |
| 9470 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9471 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 9472 | { |
| 9473 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9474 | struct net_device *dev = info->user_ptr[1]; |
| 9475 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9476 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9477 | int err; |
| 9478 | |
| 9479 | /* start with default */ |
| 9480 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9481 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9482 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9483 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9484 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9485 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9486 | if (err) |
| 9487 | return err; |
| 9488 | } |
| 9489 | |
| 9490 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 9491 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 9492 | return -EINVAL; |
| 9493 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9494 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 9495 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 9496 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 9497 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 9498 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 9499 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 9500 | return -EINVAL; |
| 9501 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 9502 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 9503 | setup.beacon_interval = |
| 9504 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 9505 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 9506 | err = cfg80211_validate_beacon_int(rdev, |
| 9507 | NL80211_IFTYPE_MESH_POINT, |
| 9508 | setup.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 9509 | if (err) |
| 9510 | return err; |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 9511 | } |
| 9512 | |
| 9513 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 9514 | setup.dtim_period = |
| 9515 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 9516 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 9517 | return -EINVAL; |
| 9518 | } |
| 9519 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9520 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 9521 | /* parse additional setup parameters if given */ |
| 9522 | err = nl80211_parse_mesh_setup(info, &setup); |
| 9523 | if (err) |
| 9524 | return err; |
| 9525 | } |
| 9526 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 9527 | if (setup.user_mpm) |
| 9528 | cfg.auto_open_plinks = false; |
| 9529 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9530 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9531 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 9532 | if (err) |
| 9533 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9534 | } else { |
| 9535 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9536 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9537 | } |
| 9538 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 9539 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 9540 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 9541 | int n_rates = |
| 9542 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 9543 | struct ieee80211_supported_band *sband; |
| 9544 | |
| 9545 | if (!setup.chandef.chan) |
| 9546 | return -EINVAL; |
| 9547 | |
| 9548 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 9549 | |
| 9550 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 9551 | &setup.basic_rates); |
| 9552 | if (err) |
| 9553 | return err; |
| 9554 | } |
| 9555 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 9556 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
| 9557 | err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate); |
| 9558 | if (err) |
| 9559 | return err; |
| 9560 | |
| 9561 | err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, |
| 9562 | &setup.beacon_rate); |
| 9563 | if (err) |
| 9564 | return err; |
| 9565 | } |
| 9566 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9567 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9568 | } |
| 9569 | |
| 9570 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 9571 | { |
| 9572 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9573 | struct net_device *dev = info->user_ptr[1]; |
| 9574 | |
| 9575 | return cfg80211_leave_mesh(rdev, dev); |
| 9576 | } |
| 9577 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9578 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9579 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 9580 | struct cfg80211_registered_device *rdev) |
| 9581 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9582 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9583 | struct nlattr *nl_pats, *nl_pat; |
| 9584 | int i, pat_len; |
| 9585 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9586 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9587 | return 0; |
| 9588 | |
| 9589 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 9590 | if (!nl_pats) |
| 9591 | return -ENOBUFS; |
| 9592 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9593 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9594 | nl_pat = nla_nest_start(msg, i + 1); |
| 9595 | if (!nl_pat) |
| 9596 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9597 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9598 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9599 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9600 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 9601 | wowlan->patterns[i].pattern) || |
| 9602 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9603 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9604 | return -ENOBUFS; |
| 9605 | nla_nest_end(msg, nl_pat); |
| 9606 | } |
| 9607 | nla_nest_end(msg, nl_pats); |
| 9608 | |
| 9609 | return 0; |
| 9610 | } |
| 9611 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9612 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 9613 | struct cfg80211_wowlan_tcp *tcp) |
| 9614 | { |
| 9615 | struct nlattr *nl_tcp; |
| 9616 | |
| 9617 | if (!tcp) |
| 9618 | return 0; |
| 9619 | |
| 9620 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 9621 | if (!nl_tcp) |
| 9622 | return -ENOBUFS; |
| 9623 | |
Jiri Benc | 930345e | 2015-03-29 16:59:25 +0200 | [diff] [blame] | 9624 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 9625 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9626 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 9627 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 9628 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 9629 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 9630 | tcp->payload_len, tcp->payload) || |
| 9631 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 9632 | tcp->data_interval) || |
| 9633 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 9634 | tcp->wake_len, tcp->wake_data) || |
| 9635 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 9636 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 9637 | return -ENOBUFS; |
| 9638 | |
| 9639 | if (tcp->payload_seq.len && |
| 9640 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 9641 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 9642 | return -ENOBUFS; |
| 9643 | |
| 9644 | if (tcp->payload_tok.len && |
| 9645 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 9646 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 9647 | &tcp->payload_tok)) |
| 9648 | return -ENOBUFS; |
| 9649 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 9650 | nla_nest_end(msg, nl_tcp); |
| 9651 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9652 | return 0; |
| 9653 | } |
| 9654 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9655 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
| 9656 | struct cfg80211_sched_scan_request *req) |
| 9657 | { |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9658 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9659 | int i; |
| 9660 | |
| 9661 | if (!req) |
| 9662 | return 0; |
| 9663 | |
| 9664 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); |
| 9665 | if (!nd) |
| 9666 | return -ENOBUFS; |
| 9667 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9668 | if (req->n_scan_plans == 1 && |
| 9669 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, |
| 9670 | req->scan_plans[0].interval * 1000)) |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9671 | return -ENOBUFS; |
| 9672 | |
Luciano Coelho | 21fea56 | 2015-03-17 16:36:01 +0200 | [diff] [blame] | 9673 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
| 9674 | return -ENOBUFS; |
| 9675 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9676 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 9677 | if (!freqs) |
| 9678 | return -ENOBUFS; |
| 9679 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 9680 | for (i = 0; i < req->n_channels; i++) { |
| 9681 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 9682 | return -ENOBUFS; |
| 9683 | } |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9684 | |
| 9685 | nla_nest_end(msg, freqs); |
| 9686 | |
| 9687 | if (req->n_match_sets) { |
| 9688 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 9689 | if (!matches) |
| 9690 | return -ENOBUFS; |
| 9691 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9692 | for (i = 0; i < req->n_match_sets; i++) { |
| 9693 | match = nla_nest_start(msg, i); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 9694 | if (!match) |
| 9695 | return -ENOBUFS; |
| 9696 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 9697 | if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
| 9698 | req->match_sets[i].ssid.ssid_len, |
| 9699 | req->match_sets[i].ssid.ssid)) |
| 9700 | return -ENOBUFS; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9701 | nla_nest_end(msg, match); |
| 9702 | } |
| 9703 | nla_nest_end(msg, matches); |
| 9704 | } |
| 9705 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9706 | scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
| 9707 | if (!scan_plans) |
| 9708 | return -ENOBUFS; |
| 9709 | |
| 9710 | for (i = 0; i < req->n_scan_plans; i++) { |
| 9711 | scan_plan = nla_nest_start(msg, i + 1); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 9712 | if (!scan_plan) |
| 9713 | return -ENOBUFS; |
| 9714 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9715 | if (!scan_plan || |
| 9716 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, |
| 9717 | req->scan_plans[i].interval) || |
| 9718 | (req->scan_plans[i].iterations && |
| 9719 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, |
| 9720 | req->scan_plans[i].iterations))) |
| 9721 | return -ENOBUFS; |
| 9722 | nla_nest_end(msg, scan_plan); |
| 9723 | } |
| 9724 | nla_nest_end(msg, scan_plans); |
| 9725 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9726 | nla_nest_end(msg, nd); |
| 9727 | |
| 9728 | return 0; |
| 9729 | } |
| 9730 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9731 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 9732 | { |
| 9733 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9734 | struct sk_buff *msg; |
| 9735 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9736 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9737 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9738 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9739 | return -EOPNOTSUPP; |
| 9740 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9741 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9742 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9743 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 9744 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 9745 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 9746 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9747 | } |
| 9748 | |
| 9749 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9750 | if (!msg) |
| 9751 | return -ENOMEM; |
| 9752 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9753 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9754 | NL80211_CMD_GET_WOWLAN); |
| 9755 | if (!hdr) |
| 9756 | goto nla_put_failure; |
| 9757 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9758 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9759 | struct nlattr *nl_wowlan; |
| 9760 | |
| 9761 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 9762 | if (!nl_wowlan) |
| 9763 | goto nla_put_failure; |
| 9764 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9765 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9766 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9767 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9768 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9769 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9770 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9771 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9772 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9773 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9774 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9775 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9776 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9777 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9778 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 9779 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9780 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9781 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 9782 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9783 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9784 | if (nl80211_send_wowlan_tcp(msg, |
| 9785 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9786 | goto nla_put_failure; |
| 9787 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 9788 | if (nl80211_send_wowlan_nd( |
| 9789 | msg, |
| 9790 | rdev->wiphy.wowlan_config->nd_config)) |
| 9791 | goto nla_put_failure; |
| 9792 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9793 | nla_nest_end(msg, nl_wowlan); |
| 9794 | } |
| 9795 | |
| 9796 | genlmsg_end(msg, hdr); |
| 9797 | return genlmsg_reply(msg, info); |
| 9798 | |
| 9799 | nla_put_failure: |
| 9800 | nlmsg_free(msg); |
| 9801 | return -ENOBUFS; |
| 9802 | } |
| 9803 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9804 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 9805 | struct nlattr *attr, |
| 9806 | struct cfg80211_wowlan *trig) |
| 9807 | { |
| 9808 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 9809 | struct cfg80211_wowlan_tcp *cfg; |
| 9810 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 9811 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 9812 | u32 size; |
| 9813 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 9814 | int err, port; |
| 9815 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9816 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9817 | return -EINVAL; |
| 9818 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 9819 | err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TCP, attr, |
| 9820 | nl80211_wowlan_tcp_policy); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9821 | if (err) |
| 9822 | return err; |
| 9823 | |
| 9824 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 9825 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 9826 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 9827 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 9828 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 9829 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 9830 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 9831 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 9832 | return -EINVAL; |
| 9833 | |
| 9834 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9835 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9836 | return -EINVAL; |
| 9837 | |
| 9838 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9839 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 9840 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9841 | return -EINVAL; |
| 9842 | |
| 9843 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9844 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9845 | return -EINVAL; |
| 9846 | |
| 9847 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 9848 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 9849 | return -EINVAL; |
| 9850 | |
| 9851 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 9852 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 9853 | |
| 9854 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 9855 | tokens_size = tokln - sizeof(*tok); |
| 9856 | |
| 9857 | if (!tok->len || tokens_size % tok->len) |
| 9858 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9859 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9860 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9861 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9862 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9863 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9864 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9865 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9866 | return -EINVAL; |
| 9867 | if (tok->offset + tok->len > data_size) |
| 9868 | return -EINVAL; |
| 9869 | } |
| 9870 | |
| 9871 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 9872 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9873 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9874 | return -EINVAL; |
| 9875 | if (seq->len == 0 || seq->len > 4) |
| 9876 | return -EINVAL; |
| 9877 | if (seq->len + seq->offset > data_size) |
| 9878 | return -EINVAL; |
| 9879 | } |
| 9880 | |
| 9881 | size = sizeof(*cfg); |
| 9882 | size += data_size; |
| 9883 | size += wake_size + wake_mask_size; |
| 9884 | size += tokens_size; |
| 9885 | |
| 9886 | cfg = kzalloc(size, GFP_KERNEL); |
| 9887 | if (!cfg) |
| 9888 | return -ENOMEM; |
Jiri Benc | 67b61f6 | 2015-03-29 16:59:26 +0200 | [diff] [blame] | 9889 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 9890 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9891 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 9892 | ETH_ALEN); |
| 9893 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 9894 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 9895 | else |
| 9896 | port = 0; |
| 9897 | #ifdef CONFIG_INET |
| 9898 | /* allocate a socket and port for it and use it */ |
| 9899 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 9900 | IPPROTO_TCP, &cfg->sock, 1); |
| 9901 | if (err) { |
| 9902 | kfree(cfg); |
| 9903 | return err; |
| 9904 | } |
| 9905 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 9906 | sock_release(cfg->sock); |
| 9907 | kfree(cfg); |
| 9908 | return -EADDRINUSE; |
| 9909 | } |
| 9910 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 9911 | #else |
| 9912 | if (!port) { |
| 9913 | kfree(cfg); |
| 9914 | return -EINVAL; |
| 9915 | } |
| 9916 | cfg->src_port = port; |
| 9917 | #endif |
| 9918 | |
| 9919 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 9920 | cfg->payload_len = data_size; |
| 9921 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 9922 | memcpy((void *)cfg->payload, |
| 9923 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 9924 | data_size); |
| 9925 | if (seq) |
| 9926 | cfg->payload_seq = *seq; |
| 9927 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 9928 | cfg->wake_len = wake_size; |
| 9929 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 9930 | memcpy((void *)cfg->wake_data, |
| 9931 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 9932 | wake_size); |
| 9933 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 9934 | data_size + wake_size; |
| 9935 | memcpy((void *)cfg->wake_mask, |
| 9936 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 9937 | wake_mask_size); |
| 9938 | if (tok) { |
| 9939 | cfg->tokens_size = tokens_size; |
| 9940 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 9941 | } |
| 9942 | |
| 9943 | trig->tcp = cfg; |
| 9944 | |
| 9945 | return 0; |
| 9946 | } |
| 9947 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9948 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
| 9949 | const struct wiphy_wowlan_support *wowlan, |
| 9950 | struct nlattr *attr, |
| 9951 | struct cfg80211_wowlan *trig) |
| 9952 | { |
| 9953 | struct nlattr **tb; |
| 9954 | int err; |
| 9955 | |
| 9956 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); |
| 9957 | if (!tb) |
| 9958 | return -ENOMEM; |
| 9959 | |
| 9960 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { |
| 9961 | err = -EOPNOTSUPP; |
| 9962 | goto out; |
| 9963 | } |
| 9964 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 9965 | err = nla_parse_nested(tb, NL80211_ATTR_MAX, attr, nl80211_policy); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9966 | if (err) |
| 9967 | goto out; |
| 9968 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 9969 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9970 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
| 9971 | if (err) |
| 9972 | trig->nd_config = NULL; |
| 9973 | |
| 9974 | out: |
| 9975 | kfree(tb); |
| 9976 | return err; |
| 9977 | } |
| 9978 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9979 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 9980 | { |
| 9981 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9982 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9983 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9984 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9985 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9986 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9987 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 9988 | bool regular = false; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9989 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 9990 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9991 | return -EOPNOTSUPP; |
| 9992 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9993 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 9994 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9995 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9996 | goto set_wakeup; |
| 9997 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9998 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 9999 | err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TRIG, |
| 10000 | info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS], |
| 10001 | nl80211_wowlan_policy); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10002 | if (err) |
| 10003 | return err; |
| 10004 | |
| 10005 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 10006 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 10007 | return -EINVAL; |
| 10008 | new_triggers.any = true; |
| 10009 | } |
| 10010 | |
| 10011 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 10012 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 10013 | return -EINVAL; |
| 10014 | new_triggers.disconnect = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10015 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10016 | } |
| 10017 | |
| 10018 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 10019 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 10020 | return -EINVAL; |
| 10021 | new_triggers.magic_pkt = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10022 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10023 | } |
| 10024 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10025 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 10026 | return -EINVAL; |
| 10027 | |
| 10028 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 10029 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 10030 | return -EINVAL; |
| 10031 | new_triggers.gtk_rekey_failure = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10032 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10033 | } |
| 10034 | |
| 10035 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 10036 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 10037 | return -EINVAL; |
| 10038 | new_triggers.eap_identity_req = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10039 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10040 | } |
| 10041 | |
| 10042 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 10043 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 10044 | return -EINVAL; |
| 10045 | new_triggers.four_way_handshake = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10046 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10047 | } |
| 10048 | |
| 10049 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 10050 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 10051 | return -EINVAL; |
| 10052 | new_triggers.rfkill_release = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10053 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10054 | } |
| 10055 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10056 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 10057 | struct nlattr *pat; |
| 10058 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10059 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10060 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10061 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10062 | regular = true; |
| 10063 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10064 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 10065 | rem) |
| 10066 | n_patterns++; |
| 10067 | if (n_patterns > wowlan->n_patterns) |
| 10068 | return -EINVAL; |
| 10069 | |
| 10070 | new_triggers.patterns = kcalloc(n_patterns, |
| 10071 | sizeof(new_triggers.patterns[0]), |
| 10072 | GFP_KERNEL); |
| 10073 | if (!new_triggers.patterns) |
| 10074 | return -ENOMEM; |
| 10075 | |
| 10076 | new_triggers.n_patterns = n_patterns; |
| 10077 | i = 0; |
| 10078 | |
| 10079 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 10080 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10081 | u8 *mask_pat; |
| 10082 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10083 | nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, |
| 10084 | NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10085 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10086 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 10087 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10088 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10089 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10090 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10091 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10092 | goto error; |
| 10093 | if (pat_len > wowlan->pattern_max_len || |
| 10094 | pat_len < wowlan->pattern_min_len) |
| 10095 | goto error; |
| 10096 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10097 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10098 | pkt_offset = 0; |
| 10099 | else |
| 10100 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10101 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10102 | if (pkt_offset > wowlan->max_pkt_offset) |
| 10103 | goto error; |
| 10104 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 10105 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10106 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 10107 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10108 | err = -ENOMEM; |
| 10109 | goto error; |
| 10110 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10111 | new_triggers.patterns[i].mask = mask_pat; |
| 10112 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10113 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10114 | mask_pat += mask_len; |
| 10115 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10116 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10117 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10118 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10119 | pat_len); |
| 10120 | i++; |
| 10121 | } |
| 10122 | } |
| 10123 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10124 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10125 | regular = true; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10126 | err = nl80211_parse_wowlan_tcp( |
| 10127 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 10128 | &new_triggers); |
| 10129 | if (err) |
| 10130 | goto error; |
| 10131 | } |
| 10132 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10133 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10134 | regular = true; |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10135 | err = nl80211_parse_wowlan_nd( |
| 10136 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], |
| 10137 | &new_triggers); |
| 10138 | if (err) |
| 10139 | goto error; |
| 10140 | } |
| 10141 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10142 | /* The 'any' trigger means the device continues operating more or less |
| 10143 | * as in its normal operation mode and wakes up the host on most of the |
| 10144 | * normal interrupts (like packet RX, ...) |
| 10145 | * It therefore makes little sense to combine with the more constrained |
| 10146 | * wakeup trigger modes. |
| 10147 | */ |
| 10148 | if (new_triggers.any && regular) { |
| 10149 | err = -EINVAL; |
| 10150 | goto error; |
| 10151 | } |
| 10152 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10153 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 10154 | if (!ntrig) { |
| 10155 | err = -ENOMEM; |
| 10156 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10157 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10158 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10159 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10160 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10161 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10162 | if (rdev->ops->set_wakeup && |
| 10163 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 10164 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 10165 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10166 | return 0; |
| 10167 | error: |
| 10168 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 10169 | kfree(new_triggers.patterns[i].mask); |
| 10170 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10171 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 10172 | sock_release(new_triggers.tcp->sock); |
| 10173 | kfree(new_triggers.tcp); |
Ola Olsson | e5dbe07 | 2015-12-12 23:17:17 +0100 | [diff] [blame] | 10174 | kfree(new_triggers.nd_config); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10175 | return err; |
| 10176 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10177 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10178 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10179 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 10180 | struct cfg80211_registered_device *rdev) |
| 10181 | { |
| 10182 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 10183 | int i, j, pat_len; |
| 10184 | struct cfg80211_coalesce_rules *rule; |
| 10185 | |
| 10186 | if (!rdev->coalesce->n_rules) |
| 10187 | return 0; |
| 10188 | |
| 10189 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 10190 | if (!nl_rules) |
| 10191 | return -ENOBUFS; |
| 10192 | |
| 10193 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 10194 | nl_rule = nla_nest_start(msg, i + 1); |
| 10195 | if (!nl_rule) |
| 10196 | return -ENOBUFS; |
| 10197 | |
| 10198 | rule = &rdev->coalesce->rules[i]; |
| 10199 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 10200 | rule->delay)) |
| 10201 | return -ENOBUFS; |
| 10202 | |
| 10203 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 10204 | rule->condition)) |
| 10205 | return -ENOBUFS; |
| 10206 | |
| 10207 | nl_pats = nla_nest_start(msg, |
| 10208 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 10209 | if (!nl_pats) |
| 10210 | return -ENOBUFS; |
| 10211 | |
| 10212 | for (j = 0; j < rule->n_patterns; j++) { |
| 10213 | nl_pat = nla_nest_start(msg, j + 1); |
| 10214 | if (!nl_pat) |
| 10215 | return -ENOBUFS; |
| 10216 | pat_len = rule->patterns[j].pattern_len; |
| 10217 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 10218 | DIV_ROUND_UP(pat_len, 8), |
| 10219 | rule->patterns[j].mask) || |
| 10220 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 10221 | rule->patterns[j].pattern) || |
| 10222 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 10223 | rule->patterns[j].pkt_offset)) |
| 10224 | return -ENOBUFS; |
| 10225 | nla_nest_end(msg, nl_pat); |
| 10226 | } |
| 10227 | nla_nest_end(msg, nl_pats); |
| 10228 | nla_nest_end(msg, nl_rule); |
| 10229 | } |
| 10230 | nla_nest_end(msg, nl_rules); |
| 10231 | |
| 10232 | return 0; |
| 10233 | } |
| 10234 | |
| 10235 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 10236 | { |
| 10237 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10238 | struct sk_buff *msg; |
| 10239 | void *hdr; |
| 10240 | |
| 10241 | if (!rdev->wiphy.coalesce) |
| 10242 | return -EOPNOTSUPP; |
| 10243 | |
| 10244 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10245 | if (!msg) |
| 10246 | return -ENOMEM; |
| 10247 | |
| 10248 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 10249 | NL80211_CMD_GET_COALESCE); |
| 10250 | if (!hdr) |
| 10251 | goto nla_put_failure; |
| 10252 | |
| 10253 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 10254 | goto nla_put_failure; |
| 10255 | |
| 10256 | genlmsg_end(msg, hdr); |
| 10257 | return genlmsg_reply(msg, info); |
| 10258 | |
| 10259 | nla_put_failure: |
| 10260 | nlmsg_free(msg); |
| 10261 | return -ENOBUFS; |
| 10262 | } |
| 10263 | |
| 10264 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 10265 | { |
| 10266 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 10267 | int i, j; |
| 10268 | struct cfg80211_coalesce_rules *rule; |
| 10269 | |
| 10270 | if (!coalesce) |
| 10271 | return; |
| 10272 | |
| 10273 | for (i = 0; i < coalesce->n_rules; i++) { |
| 10274 | rule = &coalesce->rules[i]; |
| 10275 | for (j = 0; j < rule->n_patterns; j++) |
| 10276 | kfree(rule->patterns[j].mask); |
| 10277 | kfree(rule->patterns); |
| 10278 | } |
| 10279 | kfree(coalesce->rules); |
| 10280 | kfree(coalesce); |
| 10281 | rdev->coalesce = NULL; |
| 10282 | } |
| 10283 | |
| 10284 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 10285 | struct nlattr *rule, |
| 10286 | struct cfg80211_coalesce_rules *new_rule) |
| 10287 | { |
| 10288 | int err, i; |
| 10289 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 10290 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 10291 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 10292 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 10293 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10294 | err = nla_parse_nested(tb, NL80211_ATTR_COALESCE_RULE_MAX, rule, |
| 10295 | nl80211_coalesce_policy); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10296 | if (err) |
| 10297 | return err; |
| 10298 | |
| 10299 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 10300 | new_rule->delay = |
| 10301 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 10302 | if (new_rule->delay > coalesce->max_delay) |
| 10303 | return -EINVAL; |
| 10304 | |
| 10305 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 10306 | new_rule->condition = |
| 10307 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 10308 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 10309 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 10310 | return -EINVAL; |
| 10311 | |
| 10312 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 10313 | return -EINVAL; |
| 10314 | |
| 10315 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 10316 | rem) |
| 10317 | n_patterns++; |
| 10318 | if (n_patterns > coalesce->n_patterns) |
| 10319 | return -EINVAL; |
| 10320 | |
| 10321 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 10322 | GFP_KERNEL); |
| 10323 | if (!new_rule->patterns) |
| 10324 | return -ENOMEM; |
| 10325 | |
| 10326 | new_rule->n_patterns = n_patterns; |
| 10327 | i = 0; |
| 10328 | |
| 10329 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 10330 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10331 | u8 *mask_pat; |
| 10332 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10333 | nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, NULL); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10334 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 10335 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 10336 | return -EINVAL; |
| 10337 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 10338 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 10339 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 10340 | return -EINVAL; |
| 10341 | if (pat_len > coalesce->pattern_max_len || |
| 10342 | pat_len < coalesce->pattern_min_len) |
| 10343 | return -EINVAL; |
| 10344 | |
| 10345 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 10346 | pkt_offset = 0; |
| 10347 | else |
| 10348 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 10349 | if (pkt_offset > coalesce->max_pkt_offset) |
| 10350 | return -EINVAL; |
| 10351 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 10352 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10353 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 10354 | if (!mask_pat) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10355 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10356 | |
| 10357 | new_rule->patterns[i].mask = mask_pat; |
| 10358 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 10359 | mask_len); |
| 10360 | |
| 10361 | mask_pat += mask_len; |
| 10362 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10363 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10364 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 10365 | pat_len); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10366 | i++; |
| 10367 | } |
| 10368 | |
| 10369 | return 0; |
| 10370 | } |
| 10371 | |
| 10372 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 10373 | { |
| 10374 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10375 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 10376 | struct cfg80211_coalesce new_coalesce = {}; |
| 10377 | struct cfg80211_coalesce *n_coalesce; |
| 10378 | int err, rem_rule, n_rules = 0, i, j; |
| 10379 | struct nlattr *rule; |
| 10380 | struct cfg80211_coalesce_rules *tmp_rule; |
| 10381 | |
| 10382 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 10383 | return -EOPNOTSUPP; |
| 10384 | |
| 10385 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 10386 | cfg80211_rdev_free_coalesce(rdev); |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 10387 | rdev_set_coalesce(rdev, NULL); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10388 | return 0; |
| 10389 | } |
| 10390 | |
| 10391 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 10392 | rem_rule) |
| 10393 | n_rules++; |
| 10394 | if (n_rules > coalesce->n_rules) |
| 10395 | return -EINVAL; |
| 10396 | |
| 10397 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 10398 | GFP_KERNEL); |
| 10399 | if (!new_coalesce.rules) |
| 10400 | return -ENOMEM; |
| 10401 | |
| 10402 | new_coalesce.n_rules = n_rules; |
| 10403 | i = 0; |
| 10404 | |
| 10405 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 10406 | rem_rule) { |
| 10407 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 10408 | &new_coalesce.rules[i]); |
| 10409 | if (err) |
| 10410 | goto error; |
| 10411 | |
| 10412 | i++; |
| 10413 | } |
| 10414 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 10415 | err = rdev_set_coalesce(rdev, &new_coalesce); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10416 | if (err) |
| 10417 | goto error; |
| 10418 | |
| 10419 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 10420 | if (!n_coalesce) { |
| 10421 | err = -ENOMEM; |
| 10422 | goto error; |
| 10423 | } |
| 10424 | cfg80211_rdev_free_coalesce(rdev); |
| 10425 | rdev->coalesce = n_coalesce; |
| 10426 | |
| 10427 | return 0; |
| 10428 | error: |
| 10429 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 10430 | tmp_rule = &new_coalesce.rules[i]; |
| 10431 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 10432 | kfree(tmp_rule->patterns[j].mask); |
| 10433 | kfree(tmp_rule->patterns); |
| 10434 | } |
| 10435 | kfree(new_coalesce.rules); |
| 10436 | |
| 10437 | return err; |
| 10438 | } |
| 10439 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10440 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 10441 | { |
| 10442 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10443 | struct net_device *dev = info->user_ptr[1]; |
| 10444 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10445 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 10446 | struct cfg80211_gtk_rekey_data rekey_data; |
| 10447 | int err; |
| 10448 | |
| 10449 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 10450 | return -EINVAL; |
| 10451 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10452 | err = nla_parse_nested(tb, MAX_NL80211_REKEY_DATA, |
| 10453 | info->attrs[NL80211_ATTR_REKEY_DATA], |
| 10454 | nl80211_rekey_policy); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10455 | if (err) |
| 10456 | return err; |
| 10457 | |
| 10458 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 10459 | return -ERANGE; |
| 10460 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 10461 | return -ERANGE; |
| 10462 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 10463 | return -ERANGE; |
| 10464 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 10465 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 10466 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 10467 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10468 | |
| 10469 | wdev_lock(wdev); |
| 10470 | if (!wdev->current_bss) { |
| 10471 | err = -ENOTCONN; |
| 10472 | goto out; |
| 10473 | } |
| 10474 | |
| 10475 | if (!rdev->ops->set_rekey_data) { |
| 10476 | err = -EOPNOTSUPP; |
| 10477 | goto out; |
| 10478 | } |
| 10479 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10480 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10481 | out: |
| 10482 | wdev_unlock(wdev); |
| 10483 | return err; |
| 10484 | } |
| 10485 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10486 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 10487 | struct genl_info *info) |
| 10488 | { |
| 10489 | struct net_device *dev = info->user_ptr[1]; |
| 10490 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10491 | |
| 10492 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 10493 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 10494 | return -EINVAL; |
| 10495 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10496 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10497 | return -EBUSY; |
| 10498 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10499 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10500 | return 0; |
| 10501 | } |
| 10502 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10503 | static int nl80211_probe_client(struct sk_buff *skb, |
| 10504 | struct genl_info *info) |
| 10505 | { |
| 10506 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10507 | struct net_device *dev = info->user_ptr[1]; |
| 10508 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10509 | struct sk_buff *msg; |
| 10510 | void *hdr; |
| 10511 | const u8 *addr; |
| 10512 | u64 cookie; |
| 10513 | int err; |
| 10514 | |
| 10515 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 10516 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 10517 | return -EOPNOTSUPP; |
| 10518 | |
| 10519 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 10520 | return -EINVAL; |
| 10521 | |
| 10522 | if (!rdev->ops->probe_client) |
| 10523 | return -EOPNOTSUPP; |
| 10524 | |
| 10525 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10526 | if (!msg) |
| 10527 | return -ENOMEM; |
| 10528 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10529 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10530 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 10531 | if (!hdr) { |
| 10532 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10533 | goto free_msg; |
| 10534 | } |
| 10535 | |
| 10536 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10537 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10538 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10539 | if (err) |
| 10540 | goto free_msg; |
| 10541 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 10542 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 10543 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10544 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10545 | |
| 10546 | genlmsg_end(msg, hdr); |
| 10547 | |
| 10548 | return genlmsg_reply(msg, info); |
| 10549 | |
| 10550 | nla_put_failure: |
| 10551 | err = -ENOBUFS; |
| 10552 | free_msg: |
| 10553 | nlmsg_free(msg); |
| 10554 | return err; |
| 10555 | } |
| 10556 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10557 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 10558 | { |
| 10559 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10560 | struct cfg80211_beacon_registration *reg, *nreg; |
| 10561 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10562 | |
| 10563 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 10564 | return -EOPNOTSUPP; |
| 10565 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10566 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 10567 | if (!nreg) |
| 10568 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10569 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10570 | /* First, check if already registered. */ |
| 10571 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10572 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 10573 | if (reg->nlportid == info->snd_portid) { |
| 10574 | rv = -EALREADY; |
| 10575 | goto out_err; |
| 10576 | } |
| 10577 | } |
| 10578 | /* Add it to the list */ |
| 10579 | nreg->nlportid = info->snd_portid; |
| 10580 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 10581 | |
| 10582 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10583 | |
| 10584 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10585 | out_err: |
| 10586 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10587 | kfree(nreg); |
| 10588 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10589 | } |
| 10590 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10591 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 10592 | { |
| 10593 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10594 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10595 | int err; |
| 10596 | |
| 10597 | if (!rdev->ops->start_p2p_device) |
| 10598 | return -EOPNOTSUPP; |
| 10599 | |
| 10600 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 10601 | return -EOPNOTSUPP; |
| 10602 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 10603 | if (wdev_running(wdev)) |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10604 | return 0; |
| 10605 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 10606 | if (rfkill_blocked(rdev->rfkill)) |
| 10607 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10608 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 10609 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10610 | if (err) |
| 10611 | return err; |
| 10612 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 10613 | wdev->is_running = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10614 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10615 | |
| 10616 | return 0; |
| 10617 | } |
| 10618 | |
| 10619 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 10620 | { |
| 10621 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10622 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10623 | |
| 10624 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 10625 | return -EOPNOTSUPP; |
| 10626 | |
| 10627 | if (!rdev->ops->stop_p2p_device) |
| 10628 | return -EOPNOTSUPP; |
| 10629 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 10630 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10631 | |
| 10632 | return 0; |
| 10633 | } |
| 10634 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 10635 | static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) |
| 10636 | { |
| 10637 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10638 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10639 | struct cfg80211_nan_conf conf = {}; |
| 10640 | int err; |
| 10641 | |
| 10642 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 10643 | return -EOPNOTSUPP; |
| 10644 | |
Johannes Berg | eeb04a9 | 2016-11-21 13:55:48 +0100 | [diff] [blame] | 10645 | if (wdev_running(wdev)) |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 10646 | return -EEXIST; |
| 10647 | |
| 10648 | if (rfkill_blocked(rdev->rfkill)) |
| 10649 | return -ERFKILL; |
| 10650 | |
| 10651 | if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) |
| 10652 | return -EINVAL; |
| 10653 | |
| 10654 | if (!info->attrs[NL80211_ATTR_NAN_DUAL]) |
| 10655 | return -EINVAL; |
| 10656 | |
| 10657 | conf.master_pref = |
| 10658 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
| 10659 | if (!conf.master_pref) |
| 10660 | return -EINVAL; |
| 10661 | |
| 10662 | conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]); |
| 10663 | |
| 10664 | err = rdev_start_nan(rdev, wdev, &conf); |
| 10665 | if (err) |
| 10666 | return err; |
| 10667 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 10668 | wdev->is_running = true; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 10669 | rdev->opencount++; |
| 10670 | |
| 10671 | return 0; |
| 10672 | } |
| 10673 | |
| 10674 | static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) |
| 10675 | { |
| 10676 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10677 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10678 | |
| 10679 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 10680 | return -EOPNOTSUPP; |
| 10681 | |
| 10682 | cfg80211_stop_nan(rdev, wdev); |
| 10683 | |
| 10684 | return 0; |
| 10685 | } |
| 10686 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 10687 | static int validate_nan_filter(struct nlattr *filter_attr) |
| 10688 | { |
| 10689 | struct nlattr *attr; |
| 10690 | int len = 0, n_entries = 0, rem; |
| 10691 | |
| 10692 | nla_for_each_nested(attr, filter_attr, rem) { |
| 10693 | len += nla_len(attr); |
| 10694 | n_entries++; |
| 10695 | } |
| 10696 | |
| 10697 | if (len >= U8_MAX) |
| 10698 | return -EINVAL; |
| 10699 | |
| 10700 | return n_entries; |
| 10701 | } |
| 10702 | |
| 10703 | static int handle_nan_filter(struct nlattr *attr_filter, |
| 10704 | struct cfg80211_nan_func *func, |
| 10705 | bool tx) |
| 10706 | { |
| 10707 | struct nlattr *attr; |
| 10708 | int n_entries, rem, i; |
| 10709 | struct cfg80211_nan_func_filter *filter; |
| 10710 | |
| 10711 | n_entries = validate_nan_filter(attr_filter); |
| 10712 | if (n_entries < 0) |
| 10713 | return n_entries; |
| 10714 | |
| 10715 | BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); |
| 10716 | |
| 10717 | filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); |
| 10718 | if (!filter) |
| 10719 | return -ENOMEM; |
| 10720 | |
| 10721 | i = 0; |
| 10722 | nla_for_each_nested(attr, attr_filter, rem) { |
Thomas Graf | b15ca18 | 2016-10-26 10:53:16 +0200 | [diff] [blame] | 10723 | filter[i].filter = nla_memdup(attr, GFP_KERNEL); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 10724 | filter[i].len = nla_len(attr); |
| 10725 | i++; |
| 10726 | } |
| 10727 | if (tx) { |
| 10728 | func->num_tx_filters = n_entries; |
| 10729 | func->tx_filters = filter; |
| 10730 | } else { |
| 10731 | func->num_rx_filters = n_entries; |
| 10732 | func->rx_filters = filter; |
| 10733 | } |
| 10734 | |
| 10735 | return 0; |
| 10736 | } |
| 10737 | |
| 10738 | static int nl80211_nan_add_func(struct sk_buff *skb, |
| 10739 | struct genl_info *info) |
| 10740 | { |
| 10741 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10742 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10743 | struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; |
| 10744 | struct cfg80211_nan_func *func; |
| 10745 | struct sk_buff *msg = NULL; |
| 10746 | void *hdr = NULL; |
| 10747 | int err = 0; |
| 10748 | |
| 10749 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 10750 | return -EOPNOTSUPP; |
| 10751 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 10752 | if (!wdev_running(wdev)) |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 10753 | return -ENOTCONN; |
| 10754 | |
| 10755 | if (!info->attrs[NL80211_ATTR_NAN_FUNC]) |
| 10756 | return -EINVAL; |
| 10757 | |
| 10758 | if (wdev->owner_nlportid && |
| 10759 | wdev->owner_nlportid != info->snd_portid) |
| 10760 | return -ENOTCONN; |
| 10761 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10762 | err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX, |
| 10763 | info->attrs[NL80211_ATTR_NAN_FUNC], |
| 10764 | nl80211_nan_func_policy); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 10765 | if (err) |
| 10766 | return err; |
| 10767 | |
| 10768 | func = kzalloc(sizeof(*func), GFP_KERNEL); |
| 10769 | if (!func) |
| 10770 | return -ENOMEM; |
| 10771 | |
| 10772 | func->cookie = wdev->wiphy->cookie_counter++; |
| 10773 | |
| 10774 | if (!tb[NL80211_NAN_FUNC_TYPE] || |
| 10775 | nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) { |
| 10776 | err = -EINVAL; |
| 10777 | goto out; |
| 10778 | } |
| 10779 | |
| 10780 | |
| 10781 | func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); |
| 10782 | |
| 10783 | if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { |
| 10784 | err = -EINVAL; |
| 10785 | goto out; |
| 10786 | } |
| 10787 | |
| 10788 | memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), |
| 10789 | sizeof(func->service_id)); |
| 10790 | |
| 10791 | func->close_range = |
| 10792 | nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); |
| 10793 | |
| 10794 | if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { |
| 10795 | func->serv_spec_info_len = |
| 10796 | nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); |
| 10797 | func->serv_spec_info = |
| 10798 | kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), |
| 10799 | func->serv_spec_info_len, |
| 10800 | GFP_KERNEL); |
| 10801 | if (!func->serv_spec_info) { |
| 10802 | err = -ENOMEM; |
| 10803 | goto out; |
| 10804 | } |
| 10805 | } |
| 10806 | |
| 10807 | if (tb[NL80211_NAN_FUNC_TTL]) |
| 10808 | func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); |
| 10809 | |
| 10810 | switch (func->type) { |
| 10811 | case NL80211_NAN_FUNC_PUBLISH: |
| 10812 | if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { |
| 10813 | err = -EINVAL; |
| 10814 | goto out; |
| 10815 | } |
| 10816 | |
| 10817 | func->publish_type = |
| 10818 | nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); |
| 10819 | func->publish_bcast = |
| 10820 | nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); |
| 10821 | |
| 10822 | if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && |
| 10823 | func->publish_bcast) { |
| 10824 | err = -EINVAL; |
| 10825 | goto out; |
| 10826 | } |
| 10827 | break; |
| 10828 | case NL80211_NAN_FUNC_SUBSCRIBE: |
| 10829 | func->subscribe_active = |
| 10830 | nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); |
| 10831 | break; |
| 10832 | case NL80211_NAN_FUNC_FOLLOW_UP: |
| 10833 | if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || |
| 10834 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]) { |
| 10835 | err = -EINVAL; |
| 10836 | goto out; |
| 10837 | } |
| 10838 | |
| 10839 | func->followup_id = |
| 10840 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); |
| 10841 | func->followup_reqid = |
| 10842 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); |
| 10843 | memcpy(func->followup_dest.addr, |
| 10844 | nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), |
| 10845 | sizeof(func->followup_dest.addr)); |
| 10846 | if (func->ttl) { |
| 10847 | err = -EINVAL; |
| 10848 | goto out; |
| 10849 | } |
| 10850 | break; |
| 10851 | default: |
| 10852 | err = -EINVAL; |
| 10853 | goto out; |
| 10854 | } |
| 10855 | |
| 10856 | if (tb[NL80211_NAN_FUNC_SRF]) { |
| 10857 | struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; |
| 10858 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10859 | err = nla_parse_nested(srf_tb, NL80211_NAN_SRF_ATTR_MAX, |
| 10860 | tb[NL80211_NAN_FUNC_SRF], |
| 10861 | nl80211_nan_srf_policy); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 10862 | if (err) |
| 10863 | goto out; |
| 10864 | |
| 10865 | func->srf_include = |
| 10866 | nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); |
| 10867 | |
| 10868 | if (srf_tb[NL80211_NAN_SRF_BF]) { |
| 10869 | if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || |
| 10870 | !srf_tb[NL80211_NAN_SRF_BF_IDX]) { |
| 10871 | err = -EINVAL; |
| 10872 | goto out; |
| 10873 | } |
| 10874 | |
| 10875 | func->srf_bf_len = |
| 10876 | nla_len(srf_tb[NL80211_NAN_SRF_BF]); |
| 10877 | func->srf_bf = |
| 10878 | kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), |
| 10879 | func->srf_bf_len, GFP_KERNEL); |
| 10880 | if (!func->srf_bf) { |
| 10881 | err = -ENOMEM; |
| 10882 | goto out; |
| 10883 | } |
| 10884 | |
| 10885 | func->srf_bf_idx = |
| 10886 | nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); |
| 10887 | } else { |
| 10888 | struct nlattr *attr, *mac_attr = |
| 10889 | srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; |
| 10890 | int n_entries, rem, i = 0; |
| 10891 | |
| 10892 | if (!mac_attr) { |
| 10893 | err = -EINVAL; |
| 10894 | goto out; |
| 10895 | } |
| 10896 | |
| 10897 | n_entries = validate_acl_mac_addrs(mac_attr); |
| 10898 | if (n_entries <= 0) { |
| 10899 | err = -EINVAL; |
| 10900 | goto out; |
| 10901 | } |
| 10902 | |
| 10903 | func->srf_num_macs = n_entries; |
| 10904 | func->srf_macs = |
| 10905 | kzalloc(sizeof(*func->srf_macs) * n_entries, |
| 10906 | GFP_KERNEL); |
| 10907 | if (!func->srf_macs) { |
| 10908 | err = -ENOMEM; |
| 10909 | goto out; |
| 10910 | } |
| 10911 | |
| 10912 | nla_for_each_nested(attr, mac_attr, rem) |
| 10913 | memcpy(func->srf_macs[i++].addr, nla_data(attr), |
| 10914 | sizeof(*func->srf_macs)); |
| 10915 | } |
| 10916 | } |
| 10917 | |
| 10918 | if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { |
| 10919 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], |
| 10920 | func, true); |
| 10921 | if (err) |
| 10922 | goto out; |
| 10923 | } |
| 10924 | |
| 10925 | if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { |
| 10926 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], |
| 10927 | func, false); |
| 10928 | if (err) |
| 10929 | goto out; |
| 10930 | } |
| 10931 | |
| 10932 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10933 | if (!msg) { |
| 10934 | err = -ENOMEM; |
| 10935 | goto out; |
| 10936 | } |
| 10937 | |
| 10938 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 10939 | NL80211_CMD_ADD_NAN_FUNCTION); |
| 10940 | /* This can't really happen - we just allocated 4KB */ |
| 10941 | if (WARN_ON(!hdr)) { |
| 10942 | err = -ENOMEM; |
| 10943 | goto out; |
| 10944 | } |
| 10945 | |
| 10946 | err = rdev_add_nan_func(rdev, wdev, func); |
| 10947 | out: |
| 10948 | if (err < 0) { |
| 10949 | cfg80211_free_nan_func(func); |
| 10950 | nlmsg_free(msg); |
| 10951 | return err; |
| 10952 | } |
| 10953 | |
| 10954 | /* propagate the instance id and cookie to userspace */ |
| 10955 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, |
| 10956 | NL80211_ATTR_PAD)) |
| 10957 | goto nla_put_failure; |
| 10958 | |
| 10959 | func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); |
| 10960 | if (!func_attr) |
| 10961 | goto nla_put_failure; |
| 10962 | |
| 10963 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, |
| 10964 | func->instance_id)) |
| 10965 | goto nla_put_failure; |
| 10966 | |
| 10967 | nla_nest_end(msg, func_attr); |
| 10968 | |
| 10969 | genlmsg_end(msg, hdr); |
| 10970 | return genlmsg_reply(msg, info); |
| 10971 | |
| 10972 | nla_put_failure: |
| 10973 | nlmsg_free(msg); |
| 10974 | return -ENOBUFS; |
| 10975 | } |
| 10976 | |
| 10977 | static int nl80211_nan_del_func(struct sk_buff *skb, |
| 10978 | struct genl_info *info) |
| 10979 | { |
| 10980 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10981 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10982 | u64 cookie; |
| 10983 | |
| 10984 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 10985 | return -EOPNOTSUPP; |
| 10986 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 10987 | if (!wdev_running(wdev)) |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 10988 | return -ENOTCONN; |
| 10989 | |
| 10990 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 10991 | return -EINVAL; |
| 10992 | |
| 10993 | if (wdev->owner_nlportid && |
| 10994 | wdev->owner_nlportid != info->snd_portid) |
| 10995 | return -ENOTCONN; |
| 10996 | |
| 10997 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 10998 | |
| 10999 | rdev_del_nan_func(rdev, wdev, cookie); |
| 11000 | |
| 11001 | return 0; |
| 11002 | } |
| 11003 | |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 11004 | static int nl80211_nan_change_config(struct sk_buff *skb, |
| 11005 | struct genl_info *info) |
| 11006 | { |
| 11007 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11008 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11009 | struct cfg80211_nan_conf conf = {}; |
| 11010 | u32 changed = 0; |
| 11011 | |
| 11012 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11013 | return -EOPNOTSUPP; |
| 11014 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11015 | if (!wdev_running(wdev)) |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 11016 | return -ENOTCONN; |
| 11017 | |
| 11018 | if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { |
| 11019 | conf.master_pref = |
| 11020 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
| 11021 | if (conf.master_pref <= 1 || conf.master_pref == 255) |
| 11022 | return -EINVAL; |
| 11023 | |
| 11024 | changed |= CFG80211_NAN_CONF_CHANGED_PREF; |
| 11025 | } |
| 11026 | |
| 11027 | if (info->attrs[NL80211_ATTR_NAN_DUAL]) { |
| 11028 | conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]); |
| 11029 | changed |= CFG80211_NAN_CONF_CHANGED_DUAL; |
| 11030 | } |
| 11031 | |
| 11032 | if (!changed) |
| 11033 | return -EINVAL; |
| 11034 | |
| 11035 | return rdev_nan_change_conf(rdev, wdev, &conf, changed); |
| 11036 | } |
| 11037 | |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 11038 | void cfg80211_nan_match(struct wireless_dev *wdev, |
| 11039 | struct cfg80211_nan_match_params *match, gfp_t gfp) |
| 11040 | { |
| 11041 | struct wiphy *wiphy = wdev->wiphy; |
| 11042 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 11043 | struct nlattr *match_attr, *local_func_attr, *peer_func_attr; |
| 11044 | struct sk_buff *msg; |
| 11045 | void *hdr; |
| 11046 | |
| 11047 | if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) |
| 11048 | return; |
| 11049 | |
| 11050 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11051 | if (!msg) |
| 11052 | return; |
| 11053 | |
| 11054 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); |
| 11055 | if (!hdr) { |
| 11056 | nlmsg_free(msg); |
| 11057 | return; |
| 11058 | } |
| 11059 | |
| 11060 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11061 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11062 | wdev->netdev->ifindex)) || |
| 11063 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 11064 | NL80211_ATTR_PAD)) |
| 11065 | goto nla_put_failure; |
| 11066 | |
| 11067 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, |
| 11068 | NL80211_ATTR_PAD) || |
| 11069 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) |
| 11070 | goto nla_put_failure; |
| 11071 | |
| 11072 | match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH); |
| 11073 | if (!match_attr) |
| 11074 | goto nla_put_failure; |
| 11075 | |
| 11076 | local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL); |
| 11077 | if (!local_func_attr) |
| 11078 | goto nla_put_failure; |
| 11079 | |
| 11080 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) |
| 11081 | goto nla_put_failure; |
| 11082 | |
| 11083 | nla_nest_end(msg, local_func_attr); |
| 11084 | |
| 11085 | peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER); |
| 11086 | if (!peer_func_attr) |
| 11087 | goto nla_put_failure; |
| 11088 | |
| 11089 | if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || |
| 11090 | nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) |
| 11091 | goto nla_put_failure; |
| 11092 | |
| 11093 | if (match->info && match->info_len && |
| 11094 | nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, |
| 11095 | match->info)) |
| 11096 | goto nla_put_failure; |
| 11097 | |
| 11098 | nla_nest_end(msg, peer_func_attr); |
| 11099 | nla_nest_end(msg, match_attr); |
| 11100 | genlmsg_end(msg, hdr); |
| 11101 | |
| 11102 | if (!wdev->owner_nlportid) |
| 11103 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 11104 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 11105 | else |
| 11106 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 11107 | wdev->owner_nlportid); |
| 11108 | |
| 11109 | return; |
| 11110 | |
| 11111 | nla_put_failure: |
| 11112 | nlmsg_free(msg); |
| 11113 | } |
| 11114 | EXPORT_SYMBOL(cfg80211_nan_match); |
| 11115 | |
Ayala Beker | 368e5a7 | 2016-09-20 17:31:18 +0300 | [diff] [blame] | 11116 | void cfg80211_nan_func_terminated(struct wireless_dev *wdev, |
| 11117 | u8 inst_id, |
| 11118 | enum nl80211_nan_func_term_reason reason, |
| 11119 | u64 cookie, gfp_t gfp) |
| 11120 | { |
| 11121 | struct wiphy *wiphy = wdev->wiphy; |
| 11122 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 11123 | struct sk_buff *msg; |
| 11124 | struct nlattr *func_attr; |
| 11125 | void *hdr; |
| 11126 | |
| 11127 | if (WARN_ON(!inst_id)) |
| 11128 | return; |
| 11129 | |
| 11130 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11131 | if (!msg) |
| 11132 | return; |
| 11133 | |
| 11134 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); |
| 11135 | if (!hdr) { |
| 11136 | nlmsg_free(msg); |
| 11137 | return; |
| 11138 | } |
| 11139 | |
| 11140 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11141 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11142 | wdev->netdev->ifindex)) || |
| 11143 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 11144 | NL80211_ATTR_PAD)) |
| 11145 | goto nla_put_failure; |
| 11146 | |
| 11147 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 11148 | NL80211_ATTR_PAD)) |
| 11149 | goto nla_put_failure; |
| 11150 | |
| 11151 | func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); |
| 11152 | if (!func_attr) |
| 11153 | goto nla_put_failure; |
| 11154 | |
| 11155 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || |
| 11156 | nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) |
| 11157 | goto nla_put_failure; |
| 11158 | |
| 11159 | nla_nest_end(msg, func_attr); |
| 11160 | genlmsg_end(msg, hdr); |
| 11161 | |
| 11162 | if (!wdev->owner_nlportid) |
| 11163 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 11164 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 11165 | else |
| 11166 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 11167 | wdev->owner_nlportid); |
| 11168 | |
| 11169 | return; |
| 11170 | |
| 11171 | nla_put_failure: |
| 11172 | nlmsg_free(msg); |
| 11173 | } |
| 11174 | EXPORT_SYMBOL(cfg80211_nan_func_terminated); |
| 11175 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 11176 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 11177 | struct genl_info *info) |
| 11178 | { |
| 11179 | void *hdr; |
| 11180 | struct sk_buff *msg; |
| 11181 | |
| 11182 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11183 | if (!msg) |
| 11184 | return -ENOMEM; |
| 11185 | |
| 11186 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 11187 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 11188 | if (!hdr) |
| 11189 | goto nla_put_failure; |
| 11190 | |
| 11191 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 11192 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 11193 | goto nla_put_failure; |
| 11194 | |
| 11195 | genlmsg_end(msg, hdr); |
| 11196 | return genlmsg_reply(msg, info); |
| 11197 | |
| 11198 | nla_put_failure: |
| 11199 | kfree_skb(msg); |
| 11200 | return -ENOBUFS; |
| 11201 | } |
| 11202 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11203 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 11204 | { |
| 11205 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11206 | struct cfg80211_update_ft_ies_params ft_params; |
| 11207 | struct net_device *dev = info->user_ptr[1]; |
| 11208 | |
| 11209 | if (!rdev->ops->update_ft_ies) |
| 11210 | return -EOPNOTSUPP; |
| 11211 | |
| 11212 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 11213 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 11214 | return -EINVAL; |
| 11215 | |
| 11216 | memset(&ft_params, 0, sizeof(ft_params)); |
| 11217 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 11218 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 11219 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 11220 | |
| 11221 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 11222 | } |
| 11223 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11224 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 11225 | struct genl_info *info) |
| 11226 | { |
| 11227 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11228 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11229 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 11230 | u16 duration; |
| 11231 | int ret; |
| 11232 | |
| 11233 | if (!rdev->ops->crit_proto_start) |
| 11234 | return -EOPNOTSUPP; |
| 11235 | |
| 11236 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 11237 | return -EINVAL; |
| 11238 | |
| 11239 | if (rdev->crit_proto_nlportid) |
| 11240 | return -EBUSY; |
| 11241 | |
| 11242 | /* determine protocol if provided */ |
| 11243 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 11244 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 11245 | |
| 11246 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 11247 | return -EINVAL; |
| 11248 | |
| 11249 | /* timeout must be provided */ |
| 11250 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 11251 | return -EINVAL; |
| 11252 | |
| 11253 | duration = |
| 11254 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 11255 | |
| 11256 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 11257 | return -ERANGE; |
| 11258 | |
| 11259 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 11260 | if (!ret) |
| 11261 | rdev->crit_proto_nlportid = info->snd_portid; |
| 11262 | |
| 11263 | return ret; |
| 11264 | } |
| 11265 | |
| 11266 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 11267 | struct genl_info *info) |
| 11268 | { |
| 11269 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11270 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11271 | |
| 11272 | if (!rdev->ops->crit_proto_stop) |
| 11273 | return -EOPNOTSUPP; |
| 11274 | |
| 11275 | if (rdev->crit_proto_nlportid) { |
| 11276 | rdev->crit_proto_nlportid = 0; |
| 11277 | rdev_crit_proto_stop(rdev, wdev); |
| 11278 | } |
| 11279 | return 0; |
| 11280 | } |
| 11281 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11282 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 11283 | { |
| 11284 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11285 | struct wireless_dev *wdev = |
| 11286 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 11287 | int i, err; |
| 11288 | u32 vid, subcmd; |
| 11289 | |
| 11290 | if (!rdev->wiphy.vendor_commands) |
| 11291 | return -EOPNOTSUPP; |
| 11292 | |
| 11293 | if (IS_ERR(wdev)) { |
| 11294 | err = PTR_ERR(wdev); |
| 11295 | if (err != -EINVAL) |
| 11296 | return err; |
| 11297 | wdev = NULL; |
| 11298 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 11299 | return -EINVAL; |
| 11300 | } |
| 11301 | |
| 11302 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 11303 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 11304 | return -EINVAL; |
| 11305 | |
| 11306 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 11307 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 11308 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 11309 | const struct wiphy_vendor_command *vcmd; |
| 11310 | void *data = NULL; |
| 11311 | int len = 0; |
| 11312 | |
| 11313 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 11314 | |
| 11315 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 11316 | continue; |
| 11317 | |
| 11318 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 11319 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 11320 | if (!wdev) |
| 11321 | return -EINVAL; |
| 11322 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 11323 | !wdev->netdev) |
| 11324 | return -EINVAL; |
| 11325 | |
| 11326 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11327 | if (!wdev_running(wdev)) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11328 | return -ENETDOWN; |
| 11329 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11330 | |
| 11331 | if (!vcmd->doit) |
| 11332 | return -EOPNOTSUPP; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11333 | } else { |
| 11334 | wdev = NULL; |
| 11335 | } |
| 11336 | |
| 11337 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 11338 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 11339 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 11340 | } |
| 11341 | |
| 11342 | rdev->cur_cmd_info = info; |
| 11343 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 11344 | data, len); |
| 11345 | rdev->cur_cmd_info = NULL; |
| 11346 | return err; |
| 11347 | } |
| 11348 | |
| 11349 | return -EOPNOTSUPP; |
| 11350 | } |
| 11351 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11352 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
| 11353 | struct netlink_callback *cb, |
| 11354 | struct cfg80211_registered_device **rdev, |
| 11355 | struct wireless_dev **wdev) |
| 11356 | { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11357 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11358 | u32 vid, subcmd; |
| 11359 | unsigned int i; |
| 11360 | int vcmd_idx = -1; |
| 11361 | int err; |
| 11362 | void *data = NULL; |
| 11363 | unsigned int data_len = 0; |
| 11364 | |
| 11365 | rtnl_lock(); |
| 11366 | |
| 11367 | if (cb->args[0]) { |
| 11368 | /* subtract the 1 again here */ |
| 11369 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
| 11370 | struct wireless_dev *tmp; |
| 11371 | |
| 11372 | if (!wiphy) { |
| 11373 | err = -ENODEV; |
| 11374 | goto out_unlock; |
| 11375 | } |
| 11376 | *rdev = wiphy_to_rdev(wiphy); |
| 11377 | *wdev = NULL; |
| 11378 | |
| 11379 | if (cb->args[1]) { |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 11380 | list_for_each_entry(tmp, &wiphy->wdev_list, list) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11381 | if (tmp->identifier == cb->args[1] - 1) { |
| 11382 | *wdev = tmp; |
| 11383 | break; |
| 11384 | } |
| 11385 | } |
| 11386 | } |
| 11387 | |
| 11388 | /* keep rtnl locked in successful case */ |
| 11389 | return 0; |
| 11390 | } |
| 11391 | |
| 11392 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11393 | attrbuf, nl80211_fam.maxattr, nl80211_policy); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11394 | if (err) |
| 11395 | goto out_unlock; |
| 11396 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11397 | if (!attrbuf[NL80211_ATTR_VENDOR_ID] || |
| 11398 | !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11399 | err = -EINVAL; |
| 11400 | goto out_unlock; |
| 11401 | } |
| 11402 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11403 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11404 | if (IS_ERR(*wdev)) |
| 11405 | *wdev = NULL; |
| 11406 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11407 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11408 | if (IS_ERR(*rdev)) { |
| 11409 | err = PTR_ERR(*rdev); |
| 11410 | goto out_unlock; |
| 11411 | } |
| 11412 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11413 | vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]); |
| 11414 | subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11415 | |
| 11416 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { |
| 11417 | const struct wiphy_vendor_command *vcmd; |
| 11418 | |
| 11419 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; |
| 11420 | |
| 11421 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 11422 | continue; |
| 11423 | |
| 11424 | if (!vcmd->dumpit) { |
| 11425 | err = -EOPNOTSUPP; |
| 11426 | goto out_unlock; |
| 11427 | } |
| 11428 | |
| 11429 | vcmd_idx = i; |
| 11430 | break; |
| 11431 | } |
| 11432 | |
| 11433 | if (vcmd_idx < 0) { |
| 11434 | err = -EOPNOTSUPP; |
| 11435 | goto out_unlock; |
| 11436 | } |
| 11437 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11438 | if (attrbuf[NL80211_ATTR_VENDOR_DATA]) { |
| 11439 | data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 11440 | data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11441 | } |
| 11442 | |
| 11443 | /* 0 is the first index - add 1 to parse only once */ |
| 11444 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
| 11445 | /* add 1 to know if it was NULL */ |
| 11446 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; |
| 11447 | cb->args[2] = vcmd_idx; |
| 11448 | cb->args[3] = (unsigned long)data; |
| 11449 | cb->args[4] = data_len; |
| 11450 | |
| 11451 | /* keep rtnl locked in successful case */ |
| 11452 | return 0; |
| 11453 | out_unlock: |
| 11454 | rtnl_unlock(); |
| 11455 | return err; |
| 11456 | } |
| 11457 | |
| 11458 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, |
| 11459 | struct netlink_callback *cb) |
| 11460 | { |
| 11461 | struct cfg80211_registered_device *rdev; |
| 11462 | struct wireless_dev *wdev; |
| 11463 | unsigned int vcmd_idx; |
| 11464 | const struct wiphy_vendor_command *vcmd; |
| 11465 | void *data; |
| 11466 | int data_len; |
| 11467 | int err; |
| 11468 | struct nlattr *vendor_data; |
| 11469 | |
| 11470 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); |
| 11471 | if (err) |
| 11472 | return err; |
| 11473 | |
| 11474 | vcmd_idx = cb->args[2]; |
| 11475 | data = (void *)cb->args[3]; |
| 11476 | data_len = cb->args[4]; |
| 11477 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; |
| 11478 | |
| 11479 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 11480 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 11481 | if (!wdev) |
| 11482 | return -EINVAL; |
| 11483 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 11484 | !wdev->netdev) |
| 11485 | return -EINVAL; |
| 11486 | |
| 11487 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11488 | if (!wdev_running(wdev)) |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11489 | return -ENETDOWN; |
| 11490 | } |
| 11491 | } |
| 11492 | |
| 11493 | while (1) { |
| 11494 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
| 11495 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 11496 | NL80211_CMD_VENDOR); |
| 11497 | if (!hdr) |
| 11498 | break; |
| 11499 | |
| 11500 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 11501 | (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 11502 | wdev_id(wdev), |
| 11503 | NL80211_ATTR_PAD))) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11504 | genlmsg_cancel(skb, hdr); |
| 11505 | break; |
| 11506 | } |
| 11507 | |
| 11508 | vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA); |
| 11509 | if (!vendor_data) { |
| 11510 | genlmsg_cancel(skb, hdr); |
| 11511 | break; |
| 11512 | } |
| 11513 | |
| 11514 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, |
| 11515 | (unsigned long *)&cb->args[5]); |
| 11516 | nla_nest_end(skb, vendor_data); |
| 11517 | |
| 11518 | if (err == -ENOBUFS || err == -ENOENT) { |
| 11519 | genlmsg_cancel(skb, hdr); |
| 11520 | break; |
| 11521 | } else if (err) { |
| 11522 | genlmsg_cancel(skb, hdr); |
| 11523 | goto out; |
| 11524 | } |
| 11525 | |
| 11526 | genlmsg_end(skb, hdr); |
| 11527 | } |
| 11528 | |
| 11529 | err = skb->len; |
| 11530 | out: |
| 11531 | rtnl_unlock(); |
| 11532 | return err; |
| 11533 | } |
| 11534 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11535 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 11536 | enum nl80211_commands cmd, |
| 11537 | enum nl80211_attrs attr, |
| 11538 | int approxlen) |
| 11539 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11540 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11541 | |
| 11542 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 11543 | return NULL; |
| 11544 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 11545 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11546 | rdev->cur_cmd_info->snd_portid, |
| 11547 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 11548 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11549 | } |
| 11550 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 11551 | |
| 11552 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 11553 | { |
| 11554 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 11555 | void *hdr = ((void **)skb->cb)[1]; |
| 11556 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 11557 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 11558 | /* clear CB data for netlink core to own from now on */ |
| 11559 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 11560 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11561 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 11562 | kfree_skb(skb); |
| 11563 | return -EINVAL; |
| 11564 | } |
| 11565 | |
| 11566 | nla_nest_end(skb, data); |
| 11567 | genlmsg_end(skb, hdr); |
| 11568 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 11569 | } |
| 11570 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 11571 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 11572 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 11573 | struct genl_info *info) |
| 11574 | { |
| 11575 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11576 | struct cfg80211_qos_map *qos_map = NULL; |
| 11577 | struct net_device *dev = info->user_ptr[1]; |
| 11578 | u8 *pos, len, num_des, des_len, des; |
| 11579 | int ret; |
| 11580 | |
| 11581 | if (!rdev->ops->set_qos_map) |
| 11582 | return -EOPNOTSUPP; |
| 11583 | |
| 11584 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 11585 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 11586 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 11587 | |
| 11588 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 11589 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 11590 | return -EINVAL; |
| 11591 | |
| 11592 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 11593 | if (!qos_map) |
| 11594 | return -ENOMEM; |
| 11595 | |
| 11596 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 11597 | if (num_des) { |
| 11598 | des_len = num_des * |
| 11599 | sizeof(struct cfg80211_dscp_exception); |
| 11600 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 11601 | qos_map->num_des = num_des; |
| 11602 | for (des = 0; des < num_des; des++) { |
| 11603 | if (qos_map->dscp_exception[des].up > 7) { |
| 11604 | kfree(qos_map); |
| 11605 | return -EINVAL; |
| 11606 | } |
| 11607 | } |
| 11608 | pos += des_len; |
| 11609 | } |
| 11610 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 11611 | } |
| 11612 | |
| 11613 | wdev_lock(dev->ieee80211_ptr); |
| 11614 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 11615 | if (!ret) |
| 11616 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 11617 | wdev_unlock(dev->ieee80211_ptr); |
| 11618 | |
| 11619 | kfree(qos_map); |
| 11620 | return ret; |
| 11621 | } |
| 11622 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 11623 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 11624 | { |
| 11625 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11626 | struct net_device *dev = info->user_ptr[1]; |
| 11627 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11628 | const u8 *peer; |
| 11629 | u8 tsid, up; |
| 11630 | u16 admitted_time = 0; |
| 11631 | int err; |
| 11632 | |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 11633 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 11634 | return -EOPNOTSUPP; |
| 11635 | |
| 11636 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 11637 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 11638 | return -EINVAL; |
| 11639 | |
| 11640 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 11641 | if (tsid >= IEEE80211_NUM_TIDS) |
| 11642 | return -EINVAL; |
| 11643 | |
| 11644 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
| 11645 | if (up >= IEEE80211_NUM_UPS) |
| 11646 | return -EINVAL; |
| 11647 | |
| 11648 | /* WMM uses TIDs 0-7 even for TSPEC */ |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 11649 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 11650 | /* TODO: handle 802.11 TSPEC/admission control |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 11651 | * need more attributes for that (e.g. BA session requirement); |
| 11652 | * change the WMM adminssion test above to allow both then |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 11653 | */ |
| 11654 | return -EINVAL; |
| 11655 | } |
| 11656 | |
| 11657 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 11658 | |
| 11659 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 11660 | admitted_time = |
| 11661 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 11662 | if (!admitted_time) |
| 11663 | return -EINVAL; |
| 11664 | } |
| 11665 | |
| 11666 | wdev_lock(wdev); |
| 11667 | switch (wdev->iftype) { |
| 11668 | case NL80211_IFTYPE_STATION: |
| 11669 | case NL80211_IFTYPE_P2P_CLIENT: |
| 11670 | if (wdev->current_bss) |
| 11671 | break; |
| 11672 | err = -ENOTCONN; |
| 11673 | goto out; |
| 11674 | default: |
| 11675 | err = -EOPNOTSUPP; |
| 11676 | goto out; |
| 11677 | } |
| 11678 | |
| 11679 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 11680 | |
| 11681 | out: |
| 11682 | wdev_unlock(wdev); |
| 11683 | return err; |
| 11684 | } |
| 11685 | |
| 11686 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 11687 | { |
| 11688 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11689 | struct net_device *dev = info->user_ptr[1]; |
| 11690 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11691 | const u8 *peer; |
| 11692 | u8 tsid; |
| 11693 | int err; |
| 11694 | |
| 11695 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 11696 | return -EINVAL; |
| 11697 | |
| 11698 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 11699 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 11700 | |
| 11701 | wdev_lock(wdev); |
| 11702 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 11703 | wdev_unlock(wdev); |
| 11704 | |
| 11705 | return err; |
| 11706 | } |
| 11707 | |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 11708 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
| 11709 | struct genl_info *info) |
| 11710 | { |
| 11711 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11712 | struct net_device *dev = info->user_ptr[1]; |
| 11713 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11714 | struct cfg80211_chan_def chandef = {}; |
| 11715 | const u8 *addr; |
| 11716 | u8 oper_class; |
| 11717 | int err; |
| 11718 | |
| 11719 | if (!rdev->ops->tdls_channel_switch || |
| 11720 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 11721 | return -EOPNOTSUPP; |
| 11722 | |
| 11723 | switch (dev->ieee80211_ptr->iftype) { |
| 11724 | case NL80211_IFTYPE_STATION: |
| 11725 | case NL80211_IFTYPE_P2P_CLIENT: |
| 11726 | break; |
| 11727 | default: |
| 11728 | return -EOPNOTSUPP; |
| 11729 | } |
| 11730 | |
| 11731 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 11732 | !info->attrs[NL80211_ATTR_OPER_CLASS]) |
| 11733 | return -EINVAL; |
| 11734 | |
| 11735 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 11736 | if (err) |
| 11737 | return err; |
| 11738 | |
| 11739 | /* |
| 11740 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 |
| 11741 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the |
| 11742 | * specification is not defined for them. |
| 11743 | */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 11744 | if (chandef.chan->band == NL80211_BAND_2GHZ && |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 11745 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 11746 | chandef.width != NL80211_CHAN_WIDTH_20) |
| 11747 | return -EINVAL; |
| 11748 | |
| 11749 | /* we will be active on the TDLS link */ |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 11750 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 11751 | wdev->iftype)) |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 11752 | return -EINVAL; |
| 11753 | |
| 11754 | /* don't allow switching to DFS channels */ |
| 11755 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) |
| 11756 | return -EINVAL; |
| 11757 | |
| 11758 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 11759 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); |
| 11760 | |
| 11761 | wdev_lock(wdev); |
| 11762 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); |
| 11763 | wdev_unlock(wdev); |
| 11764 | |
| 11765 | return err; |
| 11766 | } |
| 11767 | |
| 11768 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, |
| 11769 | struct genl_info *info) |
| 11770 | { |
| 11771 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11772 | struct net_device *dev = info->user_ptr[1]; |
| 11773 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11774 | const u8 *addr; |
| 11775 | |
| 11776 | if (!rdev->ops->tdls_channel_switch || |
| 11777 | !rdev->ops->tdls_cancel_channel_switch || |
| 11778 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 11779 | return -EOPNOTSUPP; |
| 11780 | |
| 11781 | switch (dev->ieee80211_ptr->iftype) { |
| 11782 | case NL80211_IFTYPE_STATION: |
| 11783 | case NL80211_IFTYPE_P2P_CLIENT: |
| 11784 | break; |
| 11785 | default: |
| 11786 | return -EOPNOTSUPP; |
| 11787 | } |
| 11788 | |
| 11789 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 11790 | return -EINVAL; |
| 11791 | |
| 11792 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 11793 | |
| 11794 | wdev_lock(wdev); |
| 11795 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); |
| 11796 | wdev_unlock(wdev); |
| 11797 | |
| 11798 | return 0; |
| 11799 | } |
| 11800 | |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 11801 | static int nl80211_set_multicast_to_unicast(struct sk_buff *skb, |
| 11802 | struct genl_info *info) |
| 11803 | { |
| 11804 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11805 | struct net_device *dev = info->user_ptr[1]; |
| 11806 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11807 | const struct nlattr *nla; |
| 11808 | bool enabled; |
| 11809 | |
| 11810 | if (netif_running(dev)) |
| 11811 | return -EBUSY; |
| 11812 | |
| 11813 | if (!rdev->ops->set_multicast_to_unicast) |
| 11814 | return -EOPNOTSUPP; |
| 11815 | |
| 11816 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 11817 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 11818 | return -EOPNOTSUPP; |
| 11819 | |
| 11820 | nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED]; |
| 11821 | enabled = nla_get_flag(nla); |
| 11822 | |
| 11823 | return rdev_set_multicast_to_unicast(rdev, dev, enabled); |
| 11824 | } |
| 11825 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11826 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 11827 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 11828 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11829 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 11830 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 11831 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11832 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11833 | /* If a netdev is associated, it must be UP, P2P must be started */ |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11834 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 11835 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11836 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11837 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 11838 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11839 | struct genl_info *info) |
| 11840 | { |
| 11841 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11842 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11843 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11844 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 11845 | |
| 11846 | if (rtnl) |
| 11847 | rtnl_lock(); |
| 11848 | |
| 11849 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 11850 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11851 | if (IS_ERR(rdev)) { |
| 11852 | if (rtnl) |
| 11853 | rtnl_unlock(); |
| 11854 | return PTR_ERR(rdev); |
| 11855 | } |
| 11856 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11857 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 11858 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 11859 | ASSERT_RTNL(); |
| 11860 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11861 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 11862 | info->attrs); |
| 11863 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11864 | if (rtnl) |
| 11865 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11866 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11867 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11868 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11869 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11870 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11871 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11872 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 11873 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11874 | if (rtnl) |
| 11875 | rtnl_unlock(); |
| 11876 | return -EINVAL; |
| 11877 | } |
| 11878 | |
| 11879 | info->user_ptr[1] = dev; |
| 11880 | } else { |
| 11881 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11882 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 11883 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11884 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 11885 | !wdev_running(wdev)) { |
| 11886 | if (rtnl) |
| 11887 | rtnl_unlock(); |
| 11888 | return -ENETDOWN; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11889 | } |
| 11890 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11891 | if (dev) |
| 11892 | dev_hold(dev); |
| 11893 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11894 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11895 | } |
| 11896 | |
| 11897 | return 0; |
| 11898 | } |
| 11899 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 11900 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11901 | struct genl_info *info) |
| 11902 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 11903 | if (info->user_ptr[1]) { |
| 11904 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 11905 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11906 | |
| 11907 | if (wdev->netdev) |
| 11908 | dev_put(wdev->netdev); |
| 11909 | } else { |
| 11910 | dev_put(info->user_ptr[1]); |
| 11911 | } |
| 11912 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11913 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11914 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 11915 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11916 | |
| 11917 | /* If needed, clear the netlink message payload from the SKB |
| 11918 | * as it might contain key data that shouldn't stick around on |
| 11919 | * the heap after the SKB is freed. The netlink message header |
| 11920 | * is still needed for further processing, so leave it intact. |
| 11921 | */ |
| 11922 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 11923 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 11924 | |
| 11925 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 11926 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11927 | } |
| 11928 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 11929 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11930 | { |
| 11931 | .cmd = NL80211_CMD_GET_WIPHY, |
| 11932 | .doit = nl80211_get_wiphy, |
| 11933 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 11934 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11935 | .policy = nl80211_policy, |
| 11936 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 11937 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11938 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11939 | }, |
| 11940 | { |
| 11941 | .cmd = NL80211_CMD_SET_WIPHY, |
| 11942 | .doit = nl80211_set_wiphy, |
| 11943 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11944 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11945 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11946 | }, |
| 11947 | { |
| 11948 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 11949 | .doit = nl80211_get_interface, |
| 11950 | .dumpit = nl80211_dump_interface, |
| 11951 | .policy = nl80211_policy, |
| 11952 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 11953 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 11954 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11955 | }, |
| 11956 | { |
| 11957 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 11958 | .doit = nl80211_set_interface, |
| 11959 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11960 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11961 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 11962 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11963 | }, |
| 11964 | { |
| 11965 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 11966 | .doit = nl80211_new_interface, |
| 11967 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11968 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11969 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 11970 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11971 | }, |
| 11972 | { |
| 11973 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 11974 | .doit = nl80211_del_interface, |
| 11975 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11976 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 11977 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11978 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 11979 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 11980 | { |
| 11981 | .cmd = NL80211_CMD_GET_KEY, |
| 11982 | .doit = nl80211_get_key, |
| 11983 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11984 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 11985 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11986 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 11987 | }, |
| 11988 | { |
| 11989 | .cmd = NL80211_CMD_SET_KEY, |
| 11990 | .doit = nl80211_set_key, |
| 11991 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 11992 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 11993 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 11994 | NL80211_FLAG_NEED_RTNL | |
| 11995 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 11996 | }, |
| 11997 | { |
| 11998 | .cmd = NL80211_CMD_NEW_KEY, |
| 11999 | .doit = nl80211_new_key, |
| 12000 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12001 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12002 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12003 | NL80211_FLAG_NEED_RTNL | |
| 12004 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12005 | }, |
| 12006 | { |
| 12007 | .cmd = NL80211_CMD_DEL_KEY, |
| 12008 | .doit = nl80211_del_key, |
| 12009 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12010 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12011 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12012 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12013 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12014 | { |
| 12015 | .cmd = NL80211_CMD_SET_BEACON, |
| 12016 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12017 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12018 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12019 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12020 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12021 | }, |
| 12022 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12023 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12024 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12025 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12026 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12027 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12028 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12029 | }, |
| 12030 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12031 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12032 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12033 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12034 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12035 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12036 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12037 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12038 | { |
| 12039 | .cmd = NL80211_CMD_GET_STATION, |
| 12040 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12041 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12042 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12043 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12044 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12045 | }, |
| 12046 | { |
| 12047 | .cmd = NL80211_CMD_SET_STATION, |
| 12048 | .doit = nl80211_set_station, |
| 12049 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12050 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12051 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12052 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12053 | }, |
| 12054 | { |
| 12055 | .cmd = NL80211_CMD_NEW_STATION, |
| 12056 | .doit = nl80211_new_station, |
| 12057 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12058 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12059 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12060 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12061 | }, |
| 12062 | { |
| 12063 | .cmd = NL80211_CMD_DEL_STATION, |
| 12064 | .doit = nl80211_del_station, |
| 12065 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12066 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12067 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12068 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12069 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12070 | { |
| 12071 | .cmd = NL80211_CMD_GET_MPATH, |
| 12072 | .doit = nl80211_get_mpath, |
| 12073 | .dumpit = nl80211_dump_mpath, |
| 12074 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12075 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12076 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12077 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12078 | }, |
| 12079 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 12080 | .cmd = NL80211_CMD_GET_MPP, |
| 12081 | .doit = nl80211_get_mpp, |
| 12082 | .dumpit = nl80211_dump_mpp, |
| 12083 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12084 | .flags = GENL_UNS_ADMIN_PERM, |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 12085 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12086 | NL80211_FLAG_NEED_RTNL, |
| 12087 | }, |
| 12088 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12089 | .cmd = NL80211_CMD_SET_MPATH, |
| 12090 | .doit = nl80211_set_mpath, |
| 12091 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12092 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12093 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12094 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12095 | }, |
| 12096 | { |
| 12097 | .cmd = NL80211_CMD_NEW_MPATH, |
| 12098 | .doit = nl80211_new_mpath, |
| 12099 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12100 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12101 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12102 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12103 | }, |
| 12104 | { |
| 12105 | .cmd = NL80211_CMD_DEL_MPATH, |
| 12106 | .doit = nl80211_del_mpath, |
| 12107 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12108 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12109 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12110 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12111 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 12112 | { |
| 12113 | .cmd = NL80211_CMD_SET_BSS, |
| 12114 | .doit = nl80211_set_bss, |
| 12115 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12116 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12117 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12118 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 12119 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12120 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12121 | .cmd = NL80211_CMD_GET_REG, |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 12122 | .doit = nl80211_get_reg_do, |
| 12123 | .dumpit = nl80211_get_reg_dump, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12124 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12125 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12126 | /* can be retrieved by unprivileged users */ |
| 12127 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 12128 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12129 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12130 | .cmd = NL80211_CMD_SET_REG, |
| 12131 | .doit = nl80211_set_reg, |
| 12132 | .policy = nl80211_policy, |
| 12133 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12134 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12135 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 12136 | #endif |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12137 | { |
| 12138 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 12139 | .doit = nl80211_req_set_reg, |
| 12140 | .policy = nl80211_policy, |
| 12141 | .flags = GENL_ADMIN_PERM, |
| 12142 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12143 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 12144 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 12145 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12146 | .policy = nl80211_policy, |
| 12147 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12148 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12149 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12150 | }, |
| 12151 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 12152 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 12153 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12154 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12155 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12156 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12157 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12158 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 12159 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12160 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 12161 | .doit = nl80211_trigger_scan, |
| 12162 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12163 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 12164 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12165 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12166 | }, |
| 12167 | { |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 12168 | .cmd = NL80211_CMD_ABORT_SCAN, |
| 12169 | .doit = nl80211_abort_scan, |
| 12170 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12171 | .flags = GENL_UNS_ADMIN_PERM, |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 12172 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12173 | NL80211_FLAG_NEED_RTNL, |
| 12174 | }, |
| 12175 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12176 | .cmd = NL80211_CMD_GET_SCAN, |
| 12177 | .policy = nl80211_policy, |
| 12178 | .dumpit = nl80211_dump_scan, |
| 12179 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12180 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12181 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 12182 | .doit = nl80211_start_sched_scan, |
| 12183 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12184 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12185 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12186 | NL80211_FLAG_NEED_RTNL, |
| 12187 | }, |
| 12188 | { |
| 12189 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 12190 | .doit = nl80211_stop_sched_scan, |
| 12191 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12192 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12193 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12194 | NL80211_FLAG_NEED_RTNL, |
| 12195 | }, |
| 12196 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12197 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 12198 | .doit = nl80211_authenticate, |
| 12199 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12200 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12201 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12202 | NL80211_FLAG_NEED_RTNL | |
| 12203 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12204 | }, |
| 12205 | { |
| 12206 | .cmd = NL80211_CMD_ASSOCIATE, |
| 12207 | .doit = nl80211_associate, |
| 12208 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12209 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12210 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12211 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12212 | }, |
| 12213 | { |
| 12214 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 12215 | .doit = nl80211_deauthenticate, |
| 12216 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12217 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12218 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12219 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12220 | }, |
| 12221 | { |
| 12222 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 12223 | .doit = nl80211_disassociate, |
| 12224 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12225 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12226 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12227 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12228 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12229 | { |
| 12230 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 12231 | .doit = nl80211_join_ibss, |
| 12232 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12233 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12234 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12235 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12236 | }, |
| 12237 | { |
| 12238 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 12239 | .doit = nl80211_leave_ibss, |
| 12240 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12241 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12242 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12243 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12244 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 12245 | #ifdef CONFIG_NL80211_TESTMODE |
| 12246 | { |
| 12247 | .cmd = NL80211_CMD_TESTMODE, |
| 12248 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 12249 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 12250 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12251 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12252 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12253 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 12254 | }, |
| 12255 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12256 | { |
| 12257 | .cmd = NL80211_CMD_CONNECT, |
| 12258 | .doit = nl80211_connect, |
| 12259 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12260 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12261 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12262 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12263 | }, |
| 12264 | { |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 12265 | .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS, |
| 12266 | .doit = nl80211_update_connect_params, |
| 12267 | .policy = nl80211_policy, |
| 12268 | .flags = GENL_ADMIN_PERM, |
| 12269 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12270 | NL80211_FLAG_NEED_RTNL, |
| 12271 | }, |
| 12272 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12273 | .cmd = NL80211_CMD_DISCONNECT, |
| 12274 | .doit = nl80211_disconnect, |
| 12275 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12276 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12277 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12278 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12279 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 12280 | { |
| 12281 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 12282 | .doit = nl80211_wiphy_netns, |
| 12283 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12284 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12285 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12286 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 12287 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 12288 | { |
| 12289 | .cmd = NL80211_CMD_GET_SURVEY, |
| 12290 | .policy = nl80211_policy, |
| 12291 | .dumpit = nl80211_dump_survey, |
| 12292 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12293 | { |
| 12294 | .cmd = NL80211_CMD_SET_PMKSA, |
| 12295 | .doit = nl80211_setdel_pmksa, |
| 12296 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12297 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12298 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12299 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12300 | }, |
| 12301 | { |
| 12302 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 12303 | .doit = nl80211_setdel_pmksa, |
| 12304 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12305 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12306 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12307 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12308 | }, |
| 12309 | { |
| 12310 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 12311 | .doit = nl80211_flush_pmksa, |
| 12312 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12313 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12314 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12315 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12316 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12317 | { |
| 12318 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 12319 | .doit = nl80211_remain_on_channel, |
| 12320 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12321 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12322 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12323 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12324 | }, |
| 12325 | { |
| 12326 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 12327 | .doit = nl80211_cancel_remain_on_channel, |
| 12328 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12329 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12330 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12331 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12332 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 12333 | { |
| 12334 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 12335 | .doit = nl80211_set_tx_bitrate_mask, |
| 12336 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12337 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12338 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12339 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 12340 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12341 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12342 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 12343 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12344 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12345 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12346 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12347 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12348 | }, |
| 12349 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12350 | .cmd = NL80211_CMD_FRAME, |
| 12351 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12352 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12353 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12354 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12355 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12356 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12357 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 12358 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 12359 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 12360 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12361 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12362 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 12363 | NL80211_FLAG_NEED_RTNL, |
| 12364 | }, |
| 12365 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12366 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 12367 | .doit = nl80211_set_power_save, |
| 12368 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12369 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12370 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12371 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12372 | }, |
| 12373 | { |
| 12374 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 12375 | .doit = nl80211_get_power_save, |
| 12376 | .policy = nl80211_policy, |
| 12377 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12378 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12379 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12380 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12381 | { |
| 12382 | .cmd = NL80211_CMD_SET_CQM, |
| 12383 | .doit = nl80211_set_cqm, |
| 12384 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12385 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12386 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12387 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12388 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 12389 | { |
| 12390 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 12391 | .doit = nl80211_set_channel, |
| 12392 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12393 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12394 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12395 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 12396 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 12397 | { |
| 12398 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 12399 | .doit = nl80211_set_wds_peer, |
| 12400 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12401 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 12402 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12403 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 12404 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12405 | { |
| 12406 | .cmd = NL80211_CMD_JOIN_MESH, |
| 12407 | .doit = nl80211_join_mesh, |
| 12408 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12409 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12410 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12411 | NL80211_FLAG_NEED_RTNL, |
| 12412 | }, |
| 12413 | { |
| 12414 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 12415 | .doit = nl80211_leave_mesh, |
| 12416 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12417 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12418 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12419 | NL80211_FLAG_NEED_RTNL, |
| 12420 | }, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 12421 | { |
| 12422 | .cmd = NL80211_CMD_JOIN_OCB, |
| 12423 | .doit = nl80211_join_ocb, |
| 12424 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12425 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 12426 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12427 | NL80211_FLAG_NEED_RTNL, |
| 12428 | }, |
| 12429 | { |
| 12430 | .cmd = NL80211_CMD_LEAVE_OCB, |
| 12431 | .doit = nl80211_leave_ocb, |
| 12432 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12433 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 12434 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12435 | NL80211_FLAG_NEED_RTNL, |
| 12436 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 12437 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12438 | { |
| 12439 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 12440 | .doit = nl80211_get_wowlan, |
| 12441 | .policy = nl80211_policy, |
| 12442 | /* can be retrieved by unprivileged users */ |
| 12443 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12444 | NL80211_FLAG_NEED_RTNL, |
| 12445 | }, |
| 12446 | { |
| 12447 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 12448 | .doit = nl80211_set_wowlan, |
| 12449 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12450 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12451 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12452 | NL80211_FLAG_NEED_RTNL, |
| 12453 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 12454 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12455 | { |
| 12456 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 12457 | .doit = nl80211_set_rekey_data, |
| 12458 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12459 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12460 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12461 | NL80211_FLAG_NEED_RTNL | |
| 12462 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12463 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 12464 | { |
| 12465 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 12466 | .doit = nl80211_tdls_mgmt, |
| 12467 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12468 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 12469 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12470 | NL80211_FLAG_NEED_RTNL, |
| 12471 | }, |
| 12472 | { |
| 12473 | .cmd = NL80211_CMD_TDLS_OPER, |
| 12474 | .doit = nl80211_tdls_oper, |
| 12475 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12476 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 12477 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12478 | NL80211_FLAG_NEED_RTNL, |
| 12479 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12480 | { |
| 12481 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 12482 | .doit = nl80211_register_unexpected_frame, |
| 12483 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12484 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12485 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12486 | NL80211_FLAG_NEED_RTNL, |
| 12487 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12488 | { |
| 12489 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 12490 | .doit = nl80211_probe_client, |
| 12491 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12492 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12493 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12494 | NL80211_FLAG_NEED_RTNL, |
| 12495 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12496 | { |
| 12497 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 12498 | .doit = nl80211_register_beacons, |
| 12499 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12500 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12501 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12502 | NL80211_FLAG_NEED_RTNL, |
| 12503 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 12504 | { |
| 12505 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 12506 | .doit = nl80211_set_noack_map, |
| 12507 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12508 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 12509 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12510 | NL80211_FLAG_NEED_RTNL, |
| 12511 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12512 | { |
| 12513 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 12514 | .doit = nl80211_start_p2p_device, |
| 12515 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12516 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12517 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 12518 | NL80211_FLAG_NEED_RTNL, |
| 12519 | }, |
| 12520 | { |
| 12521 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 12522 | .doit = nl80211_stop_p2p_device, |
| 12523 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12524 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12525 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12526 | NL80211_FLAG_NEED_RTNL, |
| 12527 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 12528 | { |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12529 | .cmd = NL80211_CMD_START_NAN, |
| 12530 | .doit = nl80211_start_nan, |
| 12531 | .policy = nl80211_policy, |
| 12532 | .flags = GENL_ADMIN_PERM, |
| 12533 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 12534 | NL80211_FLAG_NEED_RTNL, |
| 12535 | }, |
| 12536 | { |
| 12537 | .cmd = NL80211_CMD_STOP_NAN, |
| 12538 | .doit = nl80211_stop_nan, |
| 12539 | .policy = nl80211_policy, |
| 12540 | .flags = GENL_ADMIN_PERM, |
| 12541 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12542 | NL80211_FLAG_NEED_RTNL, |
| 12543 | }, |
| 12544 | { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12545 | .cmd = NL80211_CMD_ADD_NAN_FUNCTION, |
| 12546 | .doit = nl80211_nan_add_func, |
| 12547 | .policy = nl80211_policy, |
| 12548 | .flags = GENL_ADMIN_PERM, |
| 12549 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12550 | NL80211_FLAG_NEED_RTNL, |
| 12551 | }, |
| 12552 | { |
| 12553 | .cmd = NL80211_CMD_DEL_NAN_FUNCTION, |
| 12554 | .doit = nl80211_nan_del_func, |
| 12555 | .policy = nl80211_policy, |
| 12556 | .flags = GENL_ADMIN_PERM, |
| 12557 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12558 | NL80211_FLAG_NEED_RTNL, |
| 12559 | }, |
| 12560 | { |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 12561 | .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, |
| 12562 | .doit = nl80211_nan_change_config, |
| 12563 | .policy = nl80211_policy, |
| 12564 | .flags = GENL_ADMIN_PERM, |
| 12565 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12566 | NL80211_FLAG_NEED_RTNL, |
| 12567 | }, |
| 12568 | { |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 12569 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 12570 | .doit = nl80211_set_mcast_rate, |
| 12571 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12572 | .flags = GENL_UNS_ADMIN_PERM, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 12573 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12574 | NL80211_FLAG_NEED_RTNL, |
| 12575 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 12576 | { |
| 12577 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 12578 | .doit = nl80211_set_mac_acl, |
| 12579 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12580 | .flags = GENL_UNS_ADMIN_PERM, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 12581 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12582 | NL80211_FLAG_NEED_RTNL, |
| 12583 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12584 | { |
| 12585 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 12586 | .doit = nl80211_start_radar_detection, |
| 12587 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12588 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12589 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12590 | NL80211_FLAG_NEED_RTNL, |
| 12591 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 12592 | { |
| 12593 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 12594 | .doit = nl80211_get_protocol_features, |
| 12595 | .policy = nl80211_policy, |
| 12596 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12597 | { |
| 12598 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 12599 | .doit = nl80211_update_ft_ies, |
| 12600 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12601 | .flags = GENL_UNS_ADMIN_PERM, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12602 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12603 | NL80211_FLAG_NEED_RTNL, |
| 12604 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12605 | { |
| 12606 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 12607 | .doit = nl80211_crit_protocol_start, |
| 12608 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12609 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12610 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12611 | NL80211_FLAG_NEED_RTNL, |
| 12612 | }, |
| 12613 | { |
| 12614 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 12615 | .doit = nl80211_crit_protocol_stop, |
| 12616 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12617 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12618 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12619 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12620 | }, |
| 12621 | { |
| 12622 | .cmd = NL80211_CMD_GET_COALESCE, |
| 12623 | .doit = nl80211_get_coalesce, |
| 12624 | .policy = nl80211_policy, |
| 12625 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12626 | NL80211_FLAG_NEED_RTNL, |
| 12627 | }, |
| 12628 | { |
| 12629 | .cmd = NL80211_CMD_SET_COALESCE, |
| 12630 | .doit = nl80211_set_coalesce, |
| 12631 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12632 | .flags = GENL_UNS_ADMIN_PERM, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12633 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12634 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 12635 | }, |
| 12636 | { |
| 12637 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 12638 | .doit = nl80211_channel_switch, |
| 12639 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12640 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 12641 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12642 | NL80211_FLAG_NEED_RTNL, |
| 12643 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12644 | { |
| 12645 | .cmd = NL80211_CMD_VENDOR, |
| 12646 | .doit = nl80211_vendor_cmd, |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 12647 | .dumpit = nl80211_vendor_cmd_dump, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12648 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12649 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 12650 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12651 | NL80211_FLAG_NEED_RTNL, |
| 12652 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 12653 | { |
| 12654 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 12655 | .doit = nl80211_set_qos_map, |
| 12656 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12657 | .flags = GENL_UNS_ADMIN_PERM, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 12658 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12659 | NL80211_FLAG_NEED_RTNL, |
| 12660 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12661 | { |
| 12662 | .cmd = NL80211_CMD_ADD_TX_TS, |
| 12663 | .doit = nl80211_add_tx_ts, |
| 12664 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12665 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12666 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12667 | NL80211_FLAG_NEED_RTNL, |
| 12668 | }, |
| 12669 | { |
| 12670 | .cmd = NL80211_CMD_DEL_TX_TS, |
| 12671 | .doit = nl80211_del_tx_ts, |
| 12672 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12673 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12674 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12675 | NL80211_FLAG_NEED_RTNL, |
| 12676 | }, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12677 | { |
| 12678 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, |
| 12679 | .doit = nl80211_tdls_channel_switch, |
| 12680 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12681 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12682 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12683 | NL80211_FLAG_NEED_RTNL, |
| 12684 | }, |
| 12685 | { |
| 12686 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, |
| 12687 | .doit = nl80211_tdls_cancel_channel_switch, |
| 12688 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12689 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12690 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12691 | NL80211_FLAG_NEED_RTNL, |
| 12692 | }, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 12693 | { |
| 12694 | .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST, |
| 12695 | .doit = nl80211_set_multicast_to_unicast, |
| 12696 | .policy = nl80211_policy, |
| 12697 | .flags = GENL_UNS_ADMIN_PERM, |
| 12698 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12699 | NL80211_FLAG_NEED_RTNL, |
| 12700 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12701 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12702 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 12703 | static struct genl_family nl80211_fam __ro_after_init = { |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 12704 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 12705 | .hdrsize = 0, /* no private header */ |
| 12706 | .version = 1, /* no particular meaning now */ |
| 12707 | .maxattr = NL80211_ATTR_MAX, |
| 12708 | .netnsok = true, |
| 12709 | .pre_doit = nl80211_pre_doit, |
| 12710 | .post_doit = nl80211_post_doit, |
| 12711 | .module = THIS_MODULE, |
| 12712 | .ops = nl80211_ops, |
| 12713 | .n_ops = ARRAY_SIZE(nl80211_ops), |
| 12714 | .mcgrps = nl80211_mcgrps, |
| 12715 | .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps), |
| 12716 | }; |
| 12717 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12718 | /* notification functions */ |
| 12719 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 12720 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 12721 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12722 | { |
| 12723 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 12724 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12725 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 12726 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 12727 | cmd != NL80211_CMD_DEL_WIPHY); |
| 12728 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 12729 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12730 | if (!msg) |
| 12731 | return; |
| 12732 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 12733 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12734 | nlmsg_free(msg); |
| 12735 | return; |
| 12736 | } |
| 12737 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12738 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12739 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12740 | } |
| 12741 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 12742 | void nl80211_notify_iface(struct cfg80211_registered_device *rdev, |
| 12743 | struct wireless_dev *wdev, |
| 12744 | enum nl80211_commands cmd) |
| 12745 | { |
| 12746 | struct sk_buff *msg; |
| 12747 | |
| 12748 | WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && |
| 12749 | cmd != NL80211_CMD_DEL_INTERFACE); |
| 12750 | |
| 12751 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12752 | if (!msg) |
| 12753 | return; |
| 12754 | |
| 12755 | if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, |
| 12756 | cmd == NL80211_CMD_DEL_INTERFACE) < 0) { |
| 12757 | nlmsg_free(msg); |
| 12758 | return; |
| 12759 | } |
| 12760 | |
| 12761 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 12762 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
| 12763 | } |
| 12764 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 12765 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 12766 | struct cfg80211_registered_device *rdev) |
| 12767 | { |
| 12768 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 12769 | struct nlattr *nest; |
| 12770 | int i; |
| 12771 | |
| 12772 | if (WARN_ON(!req)) |
| 12773 | return 0; |
| 12774 | |
| 12775 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 12776 | if (!nest) |
| 12777 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12778 | for (i = 0; i < req->n_ssids; i++) { |
| 12779 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 12780 | goto nla_put_failure; |
| 12781 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 12782 | nla_nest_end(msg, nest); |
| 12783 | |
| 12784 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 12785 | if (!nest) |
| 12786 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12787 | for (i = 0; i < req->n_channels; i++) { |
| 12788 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 12789 | goto nla_put_failure; |
| 12790 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 12791 | nla_nest_end(msg, nest); |
| 12792 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12793 | if (req->ie && |
| 12794 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 12795 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 12796 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12797 | if (req->flags && |
| 12798 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 12799 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 12800 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 12801 | if (req->info.scan_start_tsf && |
| 12802 | (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, |
| 12803 | req->info.scan_start_tsf, NL80211_BSS_PAD) || |
| 12804 | nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, |
| 12805 | req->info.tsf_bssid))) |
| 12806 | goto nla_put_failure; |
| 12807 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 12808 | return 0; |
| 12809 | nla_put_failure: |
| 12810 | return -ENOBUFS; |
| 12811 | } |
| 12812 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 12813 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 12814 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 12815 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12816 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 12817 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12818 | { |
| 12819 | void *hdr; |
| 12820 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12821 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12822 | if (!hdr) |
| 12823 | return -1; |
| 12824 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12825 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 12826 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12827 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 12828 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 12829 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12830 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12831 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 12832 | /* ignore errors and send incomplete event anyway */ |
| 12833 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12834 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 12835 | genlmsg_end(msg, hdr); |
| 12836 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12837 | |
| 12838 | nla_put_failure: |
| 12839 | genlmsg_cancel(msg, hdr); |
| 12840 | return -EMSGSIZE; |
| 12841 | } |
| 12842 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12843 | static int |
| 12844 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 12845 | struct cfg80211_registered_device *rdev, |
| 12846 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12847 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12848 | { |
| 12849 | void *hdr; |
| 12850 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12851 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12852 | if (!hdr) |
| 12853 | return -1; |
| 12854 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12855 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12856 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 12857 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12858 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 12859 | genlmsg_end(msg, hdr); |
| 12860 | return 0; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12861 | |
| 12862 | nla_put_failure: |
| 12863 | genlmsg_cancel(msg, hdr); |
| 12864 | return -EMSGSIZE; |
| 12865 | } |
| 12866 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 12867 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 12868 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 12869 | { |
| 12870 | struct sk_buff *msg; |
| 12871 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12872 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 12873 | if (!msg) |
| 12874 | return; |
| 12875 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 12876 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 12877 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 12878 | nlmsg_free(msg); |
| 12879 | return; |
| 12880 | } |
| 12881 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12882 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12883 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 12884 | } |
| 12885 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 12886 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 12887 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12888 | { |
| 12889 | struct sk_buff *msg; |
| 12890 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 12891 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12892 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 12893 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12894 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 12895 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 12896 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 12897 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12898 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 12899 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12900 | } |
| 12901 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 12902 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12903 | } |
| 12904 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 12905 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
| 12906 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12907 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12908 | if (!msg) |
| 12909 | return; |
| 12910 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12911 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12912 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12913 | } |
| 12914 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12915 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 12916 | struct net_device *netdev) |
| 12917 | { |
| 12918 | struct sk_buff *msg; |
| 12919 | |
| 12920 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12921 | if (!msg) |
| 12922 | return; |
| 12923 | |
| 12924 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 12925 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 12926 | nlmsg_free(msg); |
| 12927 | return; |
| 12928 | } |
| 12929 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12930 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12931 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12932 | } |
| 12933 | |
| 12934 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 12935 | struct net_device *netdev, u32 cmd) |
| 12936 | { |
| 12937 | struct sk_buff *msg; |
| 12938 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12939 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12940 | if (!msg) |
| 12941 | return; |
| 12942 | |
| 12943 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 12944 | nlmsg_free(msg); |
| 12945 | return; |
| 12946 | } |
| 12947 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12948 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12949 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12950 | } |
| 12951 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 12952 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
| 12953 | struct regulatory_request *request) |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12954 | { |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12955 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12956 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 12957 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12958 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12959 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 12960 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 12961 | NL80211_REGDOM_TYPE_WORLD)) |
| 12962 | goto nla_put_failure; |
| 12963 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 12964 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 12965 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 12966 | goto nla_put_failure; |
| 12967 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 12968 | request->intersect) { |
| 12969 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 12970 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 12971 | goto nla_put_failure; |
| 12972 | } else { |
| 12973 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 12974 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 12975 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 12976 | request->alpha2)) |
| 12977 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12978 | } |
| 12979 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 12980 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
| 12981 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); |
| 12982 | |
| 12983 | if (wiphy && |
| 12984 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 12985 | goto nla_put_failure; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 12986 | |
| 12987 | if (wiphy && |
| 12988 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 12989 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 12990 | goto nla_put_failure; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 12991 | } |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 12992 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 12993 | return true; |
| 12994 | |
| 12995 | nla_put_failure: |
| 12996 | return false; |
| 12997 | } |
| 12998 | |
| 12999 | /* |
| 13000 | * This can happen on global regulatory changes or device specific settings |
| 13001 | * based on custom regulatory domains. |
| 13002 | */ |
| 13003 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, |
| 13004 | struct regulatory_request *request) |
| 13005 | { |
| 13006 | struct sk_buff *msg; |
| 13007 | void *hdr; |
| 13008 | |
| 13009 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13010 | if (!msg) |
| 13011 | return; |
| 13012 | |
| 13013 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); |
| 13014 | if (!hdr) { |
| 13015 | nlmsg_free(msg); |
| 13016 | return; |
| 13017 | } |
| 13018 | |
| 13019 | if (nl80211_reg_change_event_fill(msg, request) == false) |
| 13020 | goto nla_put_failure; |
| 13021 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13022 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13023 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 13024 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13025 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13026 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 13027 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13028 | |
| 13029 | return; |
| 13030 | |
| 13031 | nla_put_failure: |
| 13032 | genlmsg_cancel(msg, hdr); |
| 13033 | nlmsg_free(msg); |
| 13034 | } |
| 13035 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13036 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 13037 | struct net_device *netdev, |
| 13038 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13039 | enum nl80211_commands cmd, gfp_t gfp, |
| 13040 | int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13041 | { |
| 13042 | struct sk_buff *msg; |
| 13043 | void *hdr; |
| 13044 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13045 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13046 | if (!msg) |
| 13047 | return; |
| 13048 | |
| 13049 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 13050 | if (!hdr) { |
| 13051 | nlmsg_free(msg); |
| 13052 | return; |
| 13053 | } |
| 13054 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13055 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13056 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13057 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 13058 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13059 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13060 | if (uapsd_queues >= 0) { |
| 13061 | struct nlattr *nla_wmm = |
| 13062 | nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 13063 | if (!nla_wmm) |
| 13064 | goto nla_put_failure; |
| 13065 | |
| 13066 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 13067 | uapsd_queues)) |
| 13068 | goto nla_put_failure; |
| 13069 | |
| 13070 | nla_nest_end(msg, nla_wmm); |
| 13071 | } |
| 13072 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13073 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13074 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13075 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13076 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13077 | return; |
| 13078 | |
| 13079 | nla_put_failure: |
| 13080 | genlmsg_cancel(msg, hdr); |
| 13081 | nlmsg_free(msg); |
| 13082 | } |
| 13083 | |
| 13084 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13085 | struct net_device *netdev, const u8 *buf, |
| 13086 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13087 | { |
| 13088 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13089 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13090 | } |
| 13091 | |
| 13092 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 13093 | struct net_device *netdev, const u8 *buf, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13094 | size_t len, gfp_t gfp, int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13095 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13096 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13097 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13098 | } |
| 13099 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 13100 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13101 | struct net_device *netdev, const u8 *buf, |
| 13102 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13103 | { |
| 13104 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13105 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13106 | } |
| 13107 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 13108 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 13109 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13110 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13111 | { |
| 13112 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13113 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13114 | } |
| 13115 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13116 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 13117 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13118 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13119 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13120 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13121 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13122 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 13123 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13124 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13125 | if (WARN_ON(len < 2)) |
| 13126 | return; |
| 13127 | |
| 13128 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 13129 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 13130 | else |
| 13131 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 13132 | |
| 13133 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13134 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13135 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13136 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13137 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 13138 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 13139 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13140 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13141 | { |
| 13142 | struct sk_buff *msg; |
| 13143 | void *hdr; |
| 13144 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13145 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13146 | if (!msg) |
| 13147 | return; |
| 13148 | |
| 13149 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 13150 | if (!hdr) { |
| 13151 | nlmsg_free(msg); |
| 13152 | return; |
| 13153 | } |
| 13154 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13155 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13156 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13157 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 13158 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 13159 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13160 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13161 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13162 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13163 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13164 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13165 | return; |
| 13166 | |
| 13167 | nla_put_failure: |
| 13168 | genlmsg_cancel(msg, hdr); |
| 13169 | nlmsg_free(msg); |
| 13170 | } |
| 13171 | |
| 13172 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13173 | struct net_device *netdev, const u8 *addr, |
| 13174 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13175 | { |
| 13176 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13177 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13178 | } |
| 13179 | |
| 13180 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13181 | struct net_device *netdev, const u8 *addr, |
| 13182 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13183 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13184 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 13185 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13186 | } |
| 13187 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13188 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 13189 | struct net_device *netdev, const u8 *bssid, |
| 13190 | const u8 *req_ie, size_t req_ie_len, |
| 13191 | const u8 *resp_ie, size_t resp_ie_len, |
Jouni Malinen | bf1ecd2 | 2016-05-31 00:16:50 +0300 | [diff] [blame] | 13192 | int status, gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13193 | { |
| 13194 | struct sk_buff *msg; |
| 13195 | void *hdr; |
| 13196 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13197 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13198 | if (!msg) |
| 13199 | return; |
| 13200 | |
| 13201 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 13202 | if (!hdr) { |
| 13203 | nlmsg_free(msg); |
| 13204 | return; |
| 13205 | } |
| 13206 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13207 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13208 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13209 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
Jouni Malinen | bf1ecd2 | 2016-05-31 00:16:50 +0300 | [diff] [blame] | 13210 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, |
| 13211 | status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : |
| 13212 | status) || |
| 13213 | (status < 0 && nla_put_flag(msg, NL80211_ATTR_TIMED_OUT)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13214 | (req_ie && |
| 13215 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 13216 | (resp_ie && |
| 13217 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 13218 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13219 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13220 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13221 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13222 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13223 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13224 | return; |
| 13225 | |
| 13226 | nla_put_failure: |
| 13227 | genlmsg_cancel(msg, hdr); |
| 13228 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13229 | } |
| 13230 | |
| 13231 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 13232 | struct net_device *netdev, const u8 *bssid, |
| 13233 | const u8 *req_ie, size_t req_ie_len, |
| 13234 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 13235 | { |
| 13236 | struct sk_buff *msg; |
| 13237 | void *hdr; |
| 13238 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13239 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13240 | if (!msg) |
| 13241 | return; |
| 13242 | |
| 13243 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 13244 | if (!hdr) { |
| 13245 | nlmsg_free(msg); |
| 13246 | return; |
| 13247 | } |
| 13248 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13249 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13250 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13251 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 13252 | (req_ie && |
| 13253 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 13254 | (resp_ie && |
| 13255 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 13256 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13257 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13258 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13259 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13260 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13261 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13262 | return; |
| 13263 | |
| 13264 | nla_put_failure: |
| 13265 | genlmsg_cancel(msg, hdr); |
| 13266 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13267 | } |
| 13268 | |
| 13269 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 13270 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 13271 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13272 | { |
| 13273 | struct sk_buff *msg; |
| 13274 | void *hdr; |
| 13275 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13276 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13277 | if (!msg) |
| 13278 | return; |
| 13279 | |
| 13280 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 13281 | if (!hdr) { |
| 13282 | nlmsg_free(msg); |
| 13283 | return; |
| 13284 | } |
| 13285 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13286 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13287 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13288 | (from_ap && reason && |
| 13289 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 13290 | (from_ap && |
| 13291 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 13292 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 13293 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13294 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13295 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13296 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13297 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13298 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13299 | return; |
| 13300 | |
| 13301 | nla_put_failure: |
| 13302 | genlmsg_cancel(msg, hdr); |
| 13303 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13304 | } |
| 13305 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13306 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 13307 | struct net_device *netdev, const u8 *bssid, |
| 13308 | gfp_t gfp) |
| 13309 | { |
| 13310 | struct sk_buff *msg; |
| 13311 | void *hdr; |
| 13312 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 13313 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13314 | if (!msg) |
| 13315 | return; |
| 13316 | |
| 13317 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 13318 | if (!hdr) { |
| 13319 | nlmsg_free(msg); |
| 13320 | return; |
| 13321 | } |
| 13322 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13323 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13324 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13325 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 13326 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13327 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13328 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13329 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13330 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13331 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13332 | return; |
| 13333 | |
| 13334 | nla_put_failure: |
| 13335 | genlmsg_cancel(msg, hdr); |
| 13336 | nlmsg_free(msg); |
| 13337 | } |
| 13338 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13339 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 13340 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13341 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13342 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13343 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13344 | struct sk_buff *msg; |
| 13345 | void *hdr; |
| 13346 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13347 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 13348 | return; |
| 13349 | |
| 13350 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 13351 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13352 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13353 | if (!msg) |
| 13354 | return; |
| 13355 | |
| 13356 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 13357 | if (!hdr) { |
| 13358 | nlmsg_free(msg); |
| 13359 | return; |
| 13360 | } |
| 13361 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13362 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13363 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 13364 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13365 | (ie_len && ie && |
| 13366 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 13367 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13368 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13369 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13370 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13371 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13372 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13373 | return; |
| 13374 | |
| 13375 | nla_put_failure: |
| 13376 | genlmsg_cancel(msg, hdr); |
| 13377 | nlmsg_free(msg); |
| 13378 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13379 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13380 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13381 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 13382 | struct net_device *netdev, const u8 *addr, |
| 13383 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13384 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13385 | { |
| 13386 | struct sk_buff *msg; |
| 13387 | void *hdr; |
| 13388 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13389 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13390 | if (!msg) |
| 13391 | return; |
| 13392 | |
| 13393 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 13394 | if (!hdr) { |
| 13395 | nlmsg_free(msg); |
| 13396 | return; |
| 13397 | } |
| 13398 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13399 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13400 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13401 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 13402 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 13403 | (key_id != -1 && |
| 13404 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 13405 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 13406 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13407 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13408 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13409 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13410 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13411 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13412 | return; |
| 13413 | |
| 13414 | nla_put_failure: |
| 13415 | genlmsg_cancel(msg, hdr); |
| 13416 | nlmsg_free(msg); |
| 13417 | } |
| 13418 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13419 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 13420 | struct ieee80211_channel *channel_before, |
| 13421 | struct ieee80211_channel *channel_after) |
| 13422 | { |
| 13423 | struct sk_buff *msg; |
| 13424 | void *hdr; |
| 13425 | struct nlattr *nl_freq; |
| 13426 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 13427 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13428 | if (!msg) |
| 13429 | return; |
| 13430 | |
| 13431 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 13432 | if (!hdr) { |
| 13433 | nlmsg_free(msg); |
| 13434 | return; |
| 13435 | } |
| 13436 | |
| 13437 | /* |
| 13438 | * Since we are applying the beacon hint to a wiphy we know its |
| 13439 | * wiphy_idx is valid |
| 13440 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13441 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 13442 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13443 | |
| 13444 | /* Before */ |
| 13445 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 13446 | if (!nl_freq) |
| 13447 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 13448 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13449 | goto nla_put_failure; |
| 13450 | nla_nest_end(msg, nl_freq); |
| 13451 | |
| 13452 | /* After */ |
| 13453 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 13454 | if (!nl_freq) |
| 13455 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 13456 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13457 | goto nla_put_failure; |
| 13458 | nla_nest_end(msg, nl_freq); |
| 13459 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13460 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13461 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 13462 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13463 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13464 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 13465 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13466 | |
| 13467 | return; |
| 13468 | |
| 13469 | nla_put_failure: |
| 13470 | genlmsg_cancel(msg, hdr); |
| 13471 | nlmsg_free(msg); |
| 13472 | } |
| 13473 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13474 | static void nl80211_send_remain_on_chan_event( |
| 13475 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13476 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13477 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13478 | unsigned int duration, gfp_t gfp) |
| 13479 | { |
| 13480 | struct sk_buff *msg; |
| 13481 | void *hdr; |
| 13482 | |
| 13483 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13484 | if (!msg) |
| 13485 | return; |
| 13486 | |
| 13487 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 13488 | if (!hdr) { |
| 13489 | nlmsg_free(msg); |
| 13490 | return; |
| 13491 | } |
| 13492 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13493 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13494 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13495 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13496 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13497 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13498 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 13499 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 13500 | NL80211_CHAN_NO_HT) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13501 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 13502 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13503 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13504 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13505 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 13506 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 13507 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13508 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13509 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13510 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13511 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13512 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13513 | return; |
| 13514 | |
| 13515 | nla_put_failure: |
| 13516 | genlmsg_cancel(msg, hdr); |
| 13517 | nlmsg_free(msg); |
| 13518 | } |
| 13519 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13520 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 13521 | struct ieee80211_channel *chan, |
| 13522 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13523 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13524 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13525 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13526 | |
| 13527 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13528 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13529 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 13530 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13531 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13532 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13533 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13534 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 13535 | struct ieee80211_channel *chan, |
| 13536 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13537 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13538 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13539 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13540 | |
| 13541 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13542 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 13543 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13544 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13545 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13546 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13547 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 13548 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 13549 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13550 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13551 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 13552 | struct sk_buff *msg; |
| 13553 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13554 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 13555 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13556 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 13557 | if (!msg) |
| 13558 | return; |
| 13559 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 13560 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 13561 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 13562 | nlmsg_free(msg); |
| 13563 | return; |
| 13564 | } |
| 13565 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13566 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13567 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 13568 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13569 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 13570 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 13571 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
| 13572 | struct station_info *sinfo, gfp_t gfp) |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13573 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13574 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13575 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13576 | struct sk_buff *msg; |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 13577 | struct station_info empty_sinfo = {}; |
| 13578 | |
| 13579 | if (!sinfo) |
| 13580 | sinfo = &empty_sinfo; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13581 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13582 | trace_cfg80211_del_sta(dev, mac_addr); |
| 13583 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13584 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13585 | if (!msg) |
| 13586 | return; |
| 13587 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 13588 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
Johannes Berg | 5700712 | 2015-01-16 21:05:02 +0100 | [diff] [blame] | 13589 | rdev, dev, mac_addr, sinfo) < 0) { |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13590 | nlmsg_free(msg); |
| 13591 | return; |
| 13592 | } |
| 13593 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13594 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13595 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13596 | } |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 13597 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13598 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13599 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 13600 | enum nl80211_connect_failed_reason reason, |
| 13601 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 13602 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13603 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13604 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 13605 | struct sk_buff *msg; |
| 13606 | void *hdr; |
| 13607 | |
| 13608 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 13609 | if (!msg) |
| 13610 | return; |
| 13611 | |
| 13612 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 13613 | if (!hdr) { |
| 13614 | nlmsg_free(msg); |
| 13615 | return; |
| 13616 | } |
| 13617 | |
| 13618 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 13619 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 13620 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 13621 | goto nla_put_failure; |
| 13622 | |
| 13623 | genlmsg_end(msg, hdr); |
| 13624 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13625 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13626 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 13627 | return; |
| 13628 | |
| 13629 | nla_put_failure: |
| 13630 | genlmsg_cancel(msg, hdr); |
| 13631 | nlmsg_free(msg); |
| 13632 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13633 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 13634 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 13635 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 13636 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13637 | { |
| 13638 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13639 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13640 | struct sk_buff *msg; |
| 13641 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13642 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13643 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13644 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13645 | return false; |
| 13646 | |
| 13647 | msg = nlmsg_new(100, gfp); |
| 13648 | if (!msg) |
| 13649 | return true; |
| 13650 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 13651 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13652 | if (!hdr) { |
| 13653 | nlmsg_free(msg); |
| 13654 | return true; |
| 13655 | } |
| 13656 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13657 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13658 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 13659 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 13660 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13661 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 13662 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13663 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13664 | return true; |
| 13665 | |
| 13666 | nla_put_failure: |
| 13667 | genlmsg_cancel(msg, hdr); |
| 13668 | nlmsg_free(msg); |
| 13669 | return true; |
| 13670 | } |
| 13671 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13672 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 13673 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 13674 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13675 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13676 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 13677 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13678 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 13679 | |
| 13680 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 13681 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 13682 | trace_cfg80211_return_bool(false); |
| 13683 | return false; |
| 13684 | } |
| 13685 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 13686 | addr, gfp); |
| 13687 | trace_cfg80211_return_bool(ret); |
| 13688 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 13689 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13690 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 13691 | |
| 13692 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 13693 | const u8 *addr, gfp_t gfp) |
| 13694 | { |
| 13695 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13696 | bool ret; |
| 13697 | |
| 13698 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 13699 | |
| 13700 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 13701 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 13702 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 13703 | trace_cfg80211_return_bool(false); |
| 13704 | return false; |
| 13705 | } |
| 13706 | ret = __nl80211_unexpected_frame(dev, |
| 13707 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 13708 | addr, gfp); |
| 13709 | trace_cfg80211_return_bool(ret); |
| 13710 | return ret; |
| 13711 | } |
| 13712 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 13713 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 13714 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13715 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 13716 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 13717 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13718 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13719 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13720 | struct sk_buff *msg; |
| 13721 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13722 | |
| 13723 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13724 | if (!msg) |
| 13725 | return -ENOMEM; |
| 13726 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 13727 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13728 | if (!hdr) { |
| 13729 | nlmsg_free(msg); |
| 13730 | return -ENOMEM; |
| 13731 | } |
| 13732 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13733 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13734 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13735 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13736 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13737 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13738 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 13739 | (sig_dbm && |
| 13740 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 13741 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 13742 | (flags && |
| 13743 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13744 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13745 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13746 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13747 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13748 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13749 | |
| 13750 | nla_put_failure: |
| 13751 | genlmsg_cancel(msg, hdr); |
| 13752 | nlmsg_free(msg); |
| 13753 | return -ENOBUFS; |
| 13754 | } |
| 13755 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13756 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 13757 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13758 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13759 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13760 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13761 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13762 | struct sk_buff *msg; |
| 13763 | void *hdr; |
| 13764 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13765 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 13766 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13767 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13768 | if (!msg) |
| 13769 | return; |
| 13770 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 13771 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13772 | if (!hdr) { |
| 13773 | nlmsg_free(msg); |
| 13774 | return; |
| 13775 | } |
| 13776 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13777 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13778 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13779 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13780 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13781 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13782 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13783 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 13784 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13785 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 13786 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13787 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13788 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13789 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13790 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13791 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13792 | return; |
| 13793 | |
| 13794 | nla_put_failure: |
| 13795 | genlmsg_cancel(msg, hdr); |
| 13796 | nlmsg_free(msg); |
| 13797 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13798 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 13799 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 13800 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
| 13801 | const char *mac, gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13802 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13803 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 13804 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 13805 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13806 | void **cb; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13807 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13808 | if (!msg) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 13809 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13810 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 13811 | cb = (void **)msg->cb; |
| 13812 | |
| 13813 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 13814 | if (!cb[0]) { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13815 | nlmsg_free(msg); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 13816 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13817 | } |
| 13818 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13819 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13820 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13821 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13822 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 13823 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13824 | goto nla_put_failure; |
| 13825 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 13826 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 13827 | if (!cb[1]) |
| 13828 | goto nla_put_failure; |
| 13829 | |
| 13830 | cb[2] = rdev; |
| 13831 | |
| 13832 | return msg; |
| 13833 | nla_put_failure: |
| 13834 | nlmsg_free(msg); |
| 13835 | return NULL; |
| 13836 | } |
| 13837 | |
| 13838 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) |
| 13839 | { |
| 13840 | void **cb = (void **)msg->cb; |
| 13841 | struct cfg80211_registered_device *rdev = cb[2]; |
| 13842 | |
| 13843 | nla_nest_end(msg, cb[1]); |
| 13844 | genlmsg_end(msg, cb[0]); |
| 13845 | |
| 13846 | memset(msg->cb, 0, sizeof(msg->cb)); |
| 13847 | |
| 13848 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 13849 | NL80211_MCGRP_MLME, gfp); |
| 13850 | } |
| 13851 | |
| 13852 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 13853 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 13854 | gfp_t gfp) |
| 13855 | { |
| 13856 | struct sk_buff *msg; |
| 13857 | |
| 13858 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 13859 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 13860 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
| 13861 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) |
| 13862 | return; |
| 13863 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 13864 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 13865 | if (!msg) |
| 13866 | return; |
| 13867 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13868 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 13869 | rssi_event)) |
| 13870 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13871 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 13872 | cfg80211_send_cqm(msg, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13873 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13874 | return; |
| 13875 | |
| 13876 | nla_put_failure: |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13877 | nlmsg_free(msg); |
| 13878 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13879 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 13880 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 13881 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 13882 | const u8 *peer, u32 num_packets, |
| 13883 | u32 rate, u32 intvl, gfp_t gfp) |
| 13884 | { |
| 13885 | struct sk_buff *msg; |
| 13886 | |
| 13887 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 13888 | if (!msg) |
| 13889 | return; |
| 13890 | |
| 13891 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 13892 | goto nla_put_failure; |
| 13893 | |
| 13894 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 13895 | goto nla_put_failure; |
| 13896 | |
| 13897 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 13898 | goto nla_put_failure; |
| 13899 | |
| 13900 | cfg80211_send_cqm(msg, gfp); |
| 13901 | return; |
| 13902 | |
| 13903 | nla_put_failure: |
| 13904 | nlmsg_free(msg); |
| 13905 | } |
| 13906 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
| 13907 | |
| 13908 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 13909 | const u8 *peer, u32 num_packets, gfp_t gfp) |
| 13910 | { |
| 13911 | struct sk_buff *msg; |
| 13912 | |
| 13913 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 13914 | |
| 13915 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 13916 | if (!msg) |
| 13917 | return; |
| 13918 | |
| 13919 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 13920 | goto nla_put_failure; |
| 13921 | |
| 13922 | cfg80211_send_cqm(msg, gfp); |
| 13923 | return; |
| 13924 | |
| 13925 | nla_put_failure: |
| 13926 | nlmsg_free(msg); |
| 13927 | } |
| 13928 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
| 13929 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 13930 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
| 13931 | { |
| 13932 | struct sk_buff *msg; |
| 13933 | |
| 13934 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 13935 | if (!msg) |
| 13936 | return; |
| 13937 | |
| 13938 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) |
| 13939 | goto nla_put_failure; |
| 13940 | |
| 13941 | cfg80211_send_cqm(msg, gfp); |
| 13942 | return; |
| 13943 | |
| 13944 | nla_put_failure: |
| 13945 | nlmsg_free(msg); |
| 13946 | } |
| 13947 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); |
| 13948 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13949 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 13950 | struct net_device *netdev, const u8 *bssid, |
| 13951 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13952 | { |
| 13953 | struct sk_buff *msg; |
| 13954 | struct nlattr *rekey_attr; |
| 13955 | void *hdr; |
| 13956 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13957 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13958 | if (!msg) |
| 13959 | return; |
| 13960 | |
| 13961 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 13962 | if (!hdr) { |
| 13963 | nlmsg_free(msg); |
| 13964 | return; |
| 13965 | } |
| 13966 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13967 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13968 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13969 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 13970 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13971 | |
| 13972 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 13973 | if (!rekey_attr) |
| 13974 | goto nla_put_failure; |
| 13975 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13976 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 13977 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 13978 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13979 | |
| 13980 | nla_nest_end(msg, rekey_attr); |
| 13981 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13982 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13983 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13984 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13985 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13986 | return; |
| 13987 | |
| 13988 | nla_put_failure: |
| 13989 | genlmsg_cancel(msg, hdr); |
| 13990 | nlmsg_free(msg); |
| 13991 | } |
| 13992 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13993 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 13994 | const u8 *replay_ctr, gfp_t gfp) |
| 13995 | { |
| 13996 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13997 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13998 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13999 | |
| 14000 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 14001 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 14002 | } |
| 14003 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 14004 | |
| 14005 | static void |
| 14006 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 14007 | struct net_device *netdev, int index, |
| 14008 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14009 | { |
| 14010 | struct sk_buff *msg; |
| 14011 | struct nlattr *attr; |
| 14012 | void *hdr; |
| 14013 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14014 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14015 | if (!msg) |
| 14016 | return; |
| 14017 | |
| 14018 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 14019 | if (!hdr) { |
| 14020 | nlmsg_free(msg); |
| 14021 | return; |
| 14022 | } |
| 14023 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14024 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14025 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 14026 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14027 | |
| 14028 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 14029 | if (!attr) |
| 14030 | goto nla_put_failure; |
| 14031 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14032 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 14033 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 14034 | (preauth && |
| 14035 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 14036 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14037 | |
| 14038 | nla_nest_end(msg, attr); |
| 14039 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14040 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14041 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14042 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14043 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14044 | return; |
| 14045 | |
| 14046 | nla_put_failure: |
| 14047 | genlmsg_cancel(msg, hdr); |
| 14048 | nlmsg_free(msg); |
| 14049 | } |
| 14050 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14051 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 14052 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 14053 | { |
| 14054 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14055 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14056 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14057 | |
| 14058 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 14059 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 14060 | } |
| 14061 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 14062 | |
| 14063 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 14064 | struct net_device *netdev, |
| 14065 | struct cfg80211_chan_def *chandef, |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14066 | gfp_t gfp, |
| 14067 | enum nl80211_commands notif, |
| 14068 | u8 count) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14069 | { |
| 14070 | struct sk_buff *msg; |
| 14071 | void *hdr; |
| 14072 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14073 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14074 | if (!msg) |
| 14075 | return; |
| 14076 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14077 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14078 | if (!hdr) { |
| 14079 | nlmsg_free(msg); |
| 14080 | return; |
| 14081 | } |
| 14082 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 14083 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 14084 | goto nla_put_failure; |
| 14085 | |
| 14086 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 14087 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14088 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14089 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
| 14090 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) |
| 14091 | goto nla_put_failure; |
| 14092 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14093 | genlmsg_end(msg, hdr); |
| 14094 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14095 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14096 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14097 | return; |
| 14098 | |
| 14099 | nla_put_failure: |
| 14100 | genlmsg_cancel(msg, hdr); |
| 14101 | nlmsg_free(msg); |
| 14102 | } |
| 14103 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14104 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 14105 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 14106 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14107 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14108 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14109 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14110 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 14111 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14112 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 14113 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14114 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 14115 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 14116 | wdev->preset_chandef = *chandef; |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14117 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 14118 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14119 | } |
| 14120 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 14121 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14122 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
| 14123 | struct cfg80211_chan_def *chandef, |
| 14124 | u8 count) |
| 14125 | { |
| 14126 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14127 | struct wiphy *wiphy = wdev->wiphy; |
| 14128 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 14129 | |
| 14130 | trace_cfg80211_ch_switch_started_notify(dev, chandef); |
| 14131 | |
| 14132 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 14133 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); |
| 14134 | } |
| 14135 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); |
| 14136 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 14137 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14138 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 14139 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14140 | enum nl80211_radar_event event, |
| 14141 | struct net_device *netdev, gfp_t gfp) |
| 14142 | { |
| 14143 | struct sk_buff *msg; |
| 14144 | void *hdr; |
| 14145 | |
| 14146 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 14147 | if (!msg) |
| 14148 | return; |
| 14149 | |
| 14150 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 14151 | if (!hdr) { |
| 14152 | nlmsg_free(msg); |
| 14153 | return; |
| 14154 | } |
| 14155 | |
| 14156 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 14157 | goto nla_put_failure; |
| 14158 | |
| 14159 | /* NOP and radar events don't need a netdev parameter */ |
| 14160 | if (netdev) { |
| 14161 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 14162 | |
| 14163 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14164 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14165 | NL80211_ATTR_PAD)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14166 | goto nla_put_failure; |
| 14167 | } |
| 14168 | |
| 14169 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 14170 | goto nla_put_failure; |
| 14171 | |
| 14172 | if (nl80211_send_chandef(msg, chandef)) |
| 14173 | goto nla_put_failure; |
| 14174 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14175 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14176 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14177 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14178 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14179 | return; |
| 14180 | |
| 14181 | nla_put_failure: |
| 14182 | genlmsg_cancel(msg, hdr); |
| 14183 | nlmsg_free(msg); |
| 14184 | } |
| 14185 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14186 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 14187 | u64 cookie, bool acked, gfp_t gfp) |
| 14188 | { |
| 14189 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14190 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14191 | struct sk_buff *msg; |
| 14192 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14193 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 14194 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 14195 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14196 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 14197 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14198 | if (!msg) |
| 14199 | return; |
| 14200 | |
| 14201 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 14202 | if (!hdr) { |
| 14203 | nlmsg_free(msg); |
| 14204 | return; |
| 14205 | } |
| 14206 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14207 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14208 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 14209 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14210 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 14211 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14212 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 14213 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14214 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14215 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14216 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14217 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14218 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14219 | return; |
| 14220 | |
| 14221 | nla_put_failure: |
| 14222 | genlmsg_cancel(msg, hdr); |
| 14223 | nlmsg_free(msg); |
| 14224 | } |
| 14225 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 14226 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14227 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 14228 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14229 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14230 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14231 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14232 | struct sk_buff *msg; |
| 14233 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14234 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14235 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 14236 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 14237 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14238 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 14239 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 14240 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 14241 | if (!msg) { |
| 14242 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 14243 | return; |
| 14244 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14245 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14246 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 14247 | if (!hdr) |
| 14248 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14249 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14250 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14251 | (freq && |
| 14252 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 14253 | (sig_dbm && |
| 14254 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 14255 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 14256 | goto nla_put_failure; |
| 14257 | |
| 14258 | genlmsg_end(msg, hdr); |
| 14259 | |
| 14260 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14261 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14262 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14263 | return; |
| 14264 | |
| 14265 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14266 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 14267 | if (hdr) |
| 14268 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14269 | nlmsg_free(msg); |
| 14270 | } |
| 14271 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 14272 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14273 | #ifdef CONFIG_PM |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 14274 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
| 14275 | struct cfg80211_wowlan_wakeup *wakeup) |
| 14276 | { |
| 14277 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; |
| 14278 | struct nlattr *nl_results, *nl_match, *nl_freqs; |
| 14279 | int i, j; |
| 14280 | |
| 14281 | nl_results = nla_nest_start( |
| 14282 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); |
| 14283 | if (!nl_results) |
| 14284 | return -EMSGSIZE; |
| 14285 | |
| 14286 | for (i = 0; i < nd->n_matches; i++) { |
| 14287 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; |
| 14288 | |
| 14289 | nl_match = nla_nest_start(msg, i); |
| 14290 | if (!nl_match) |
| 14291 | break; |
| 14292 | |
| 14293 | /* The SSID attribute is optional in nl80211, but for |
| 14294 | * simplicity reasons it's always present in the |
| 14295 | * cfg80211 structure. If a driver can't pass the |
| 14296 | * SSID, that needs to be changed. A zero length SSID |
| 14297 | * is still a valid SSID (wildcard), so it cannot be |
| 14298 | * used for this purpose. |
| 14299 | */ |
| 14300 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, |
| 14301 | match->ssid.ssid)) { |
| 14302 | nla_nest_cancel(msg, nl_match); |
| 14303 | goto out; |
| 14304 | } |
| 14305 | |
| 14306 | if (match->n_channels) { |
| 14307 | nl_freqs = nla_nest_start( |
| 14308 | msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 14309 | if (!nl_freqs) { |
| 14310 | nla_nest_cancel(msg, nl_match); |
| 14311 | goto out; |
| 14312 | } |
| 14313 | |
| 14314 | for (j = 0; j < match->n_channels; j++) { |
Samuel Tan | 5528fae8 | 2015-02-09 21:29:15 +0200 | [diff] [blame] | 14315 | if (nla_put_u32(msg, j, match->channels[j])) { |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 14316 | nla_nest_cancel(msg, nl_freqs); |
| 14317 | nla_nest_cancel(msg, nl_match); |
| 14318 | goto out; |
| 14319 | } |
| 14320 | } |
| 14321 | |
| 14322 | nla_nest_end(msg, nl_freqs); |
| 14323 | } |
| 14324 | |
| 14325 | nla_nest_end(msg, nl_match); |
| 14326 | } |
| 14327 | |
| 14328 | out: |
| 14329 | nla_nest_end(msg, nl_results); |
| 14330 | return 0; |
| 14331 | } |
| 14332 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14333 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 14334 | struct cfg80211_wowlan_wakeup *wakeup, |
| 14335 | gfp_t gfp) |
| 14336 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14337 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14338 | struct sk_buff *msg; |
| 14339 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14340 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14341 | |
| 14342 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 14343 | |
| 14344 | if (wakeup) |
| 14345 | size += wakeup->packet_present_len; |
| 14346 | |
| 14347 | msg = nlmsg_new(size, gfp); |
| 14348 | if (!msg) |
| 14349 | return; |
| 14350 | |
| 14351 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 14352 | if (!hdr) |
| 14353 | goto free_msg; |
| 14354 | |
| 14355 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14356 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14357 | NL80211_ATTR_PAD)) |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14358 | goto free_msg; |
| 14359 | |
| 14360 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 14361 | wdev->netdev->ifindex)) |
| 14362 | goto free_msg; |
| 14363 | |
| 14364 | if (wakeup) { |
| 14365 | struct nlattr *reasons; |
| 14366 | |
| 14367 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 14368 | if (!reasons) |
| 14369 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14370 | |
| 14371 | if (wakeup->disconnect && |
| 14372 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 14373 | goto free_msg; |
| 14374 | if (wakeup->magic_pkt && |
| 14375 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 14376 | goto free_msg; |
| 14377 | if (wakeup->gtk_rekey_failure && |
| 14378 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 14379 | goto free_msg; |
| 14380 | if (wakeup->eap_identity_req && |
| 14381 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 14382 | goto free_msg; |
| 14383 | if (wakeup->four_way_handshake && |
| 14384 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 14385 | goto free_msg; |
| 14386 | if (wakeup->rfkill_release && |
| 14387 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 14388 | goto free_msg; |
| 14389 | |
| 14390 | if (wakeup->pattern_idx >= 0 && |
| 14391 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 14392 | wakeup->pattern_idx)) |
| 14393 | goto free_msg; |
| 14394 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14395 | if (wakeup->tcp_match && |
| 14396 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 14397 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 14398 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14399 | if (wakeup->tcp_connlost && |
| 14400 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 14401 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 14402 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14403 | if (wakeup->tcp_nomoretokens && |
| 14404 | nla_put_flag(msg, |
| 14405 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 14406 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 14407 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14408 | if (wakeup->packet) { |
| 14409 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 14410 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 14411 | |
| 14412 | if (!wakeup->packet_80211) { |
| 14413 | pkt_attr = |
| 14414 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 14415 | len_attr = |
| 14416 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 14417 | } |
| 14418 | |
| 14419 | if (wakeup->packet_len && |
| 14420 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 14421 | goto free_msg; |
| 14422 | |
| 14423 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 14424 | wakeup->packet)) |
| 14425 | goto free_msg; |
| 14426 | } |
| 14427 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 14428 | if (wakeup->net_detect && |
| 14429 | cfg80211_net_detect_results(msg, wakeup)) |
| 14430 | goto free_msg; |
| 14431 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14432 | nla_nest_end(msg, reasons); |
| 14433 | } |
| 14434 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14435 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14436 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14437 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14438 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14439 | return; |
| 14440 | |
| 14441 | free_msg: |
| 14442 | nlmsg_free(msg); |
| 14443 | } |
| 14444 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 14445 | #endif |
| 14446 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 14447 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 14448 | enum nl80211_tdls_operation oper, |
| 14449 | u16 reason_code, gfp_t gfp) |
| 14450 | { |
| 14451 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14452 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 14453 | struct sk_buff *msg; |
| 14454 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 14455 | |
| 14456 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 14457 | reason_code); |
| 14458 | |
| 14459 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 14460 | if (!msg) |
| 14461 | return; |
| 14462 | |
| 14463 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 14464 | if (!hdr) { |
| 14465 | nlmsg_free(msg); |
| 14466 | return; |
| 14467 | } |
| 14468 | |
| 14469 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14470 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 14471 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 14472 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 14473 | (reason_code > 0 && |
| 14474 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 14475 | goto nla_put_failure; |
| 14476 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14477 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 14478 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14479 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14480 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 14481 | return; |
| 14482 | |
| 14483 | nla_put_failure: |
| 14484 | genlmsg_cancel(msg, hdr); |
| 14485 | nlmsg_free(msg); |
| 14486 | } |
| 14487 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 14488 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14489 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 14490 | unsigned long state, |
| 14491 | void *_notify) |
| 14492 | { |
| 14493 | struct netlink_notify *notify = _notify; |
| 14494 | struct cfg80211_registered_device *rdev; |
| 14495 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14496 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14497 | |
Dmitry Ivanov | 8f815cd | 2016-04-06 17:23:18 +0300 | [diff] [blame] | 14498 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14499 | return NOTIFY_DONE; |
| 14500 | |
| 14501 | rcu_read_lock(); |
| 14502 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14503 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 14504 | bool schedule_destroy_work = false; |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 14505 | bool schedule_scan_stop = false; |
| 14506 | struct cfg80211_sched_scan_request *sched_scan_req = |
| 14507 | rcu_dereference(rdev->sched_scan_req); |
| 14508 | |
| 14509 | if (sched_scan_req && notify->portid && |
| 14510 | sched_scan_req->owner_nlportid == notify->portid) |
| 14511 | schedule_scan_stop = true; |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 14512 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 14513 | list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14514 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14515 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 14516 | if (wdev->owner_nlportid == notify->portid) |
| 14517 | schedule_destroy_work = true; |
| 14518 | } |
| 14519 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14520 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 14521 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 14522 | list) { |
| 14523 | if (reg->nlportid == notify->portid) { |
| 14524 | list_del(®->list); |
| 14525 | kfree(reg); |
| 14526 | break; |
| 14527 | } |
| 14528 | } |
| 14529 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 14530 | |
| 14531 | if (schedule_destroy_work) { |
| 14532 | struct cfg80211_iface_destroy *destroy; |
| 14533 | |
| 14534 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); |
| 14535 | if (destroy) { |
| 14536 | destroy->nlportid = notify->portid; |
| 14537 | spin_lock(&rdev->destroy_list_lock); |
| 14538 | list_add(&destroy->list, &rdev->destroy_list); |
| 14539 | spin_unlock(&rdev->destroy_list_lock); |
| 14540 | schedule_work(&rdev->destroy_work); |
| 14541 | } |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 14542 | } else if (schedule_scan_stop) { |
| 14543 | sched_scan_req->owner_nlportid = 0; |
| 14544 | |
| 14545 | if (rdev->ops->sched_scan_stop && |
| 14546 | rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 14547 | schedule_work(&rdev->sched_scan_stop_wk); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 14548 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14549 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14550 | |
| 14551 | rcu_read_unlock(); |
| 14552 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 14553 | /* |
| 14554 | * It is possible that the user space process that is controlling the |
| 14555 | * indoor setting disappeared, so notify the regulatory core. |
| 14556 | */ |
| 14557 | regulatory_netlink_notify(notify->portid); |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 14558 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14559 | } |
| 14560 | |
| 14561 | static struct notifier_block nl80211_netlink_notifier = { |
| 14562 | .notifier_call = nl80211_netlink_notify, |
| 14563 | }; |
| 14564 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14565 | void cfg80211_ft_event(struct net_device *netdev, |
| 14566 | struct cfg80211_ft_event_params *ft_event) |
| 14567 | { |
| 14568 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14569 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14570 | struct sk_buff *msg; |
| 14571 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14572 | |
| 14573 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 14574 | |
| 14575 | if (!ft_event->target_ap) |
| 14576 | return; |
| 14577 | |
| 14578 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 14579 | if (!msg) |
| 14580 | return; |
| 14581 | |
| 14582 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14583 | if (!hdr) |
| 14584 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14585 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14586 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14587 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 14588 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 14589 | goto out; |
| 14590 | |
| 14591 | if (ft_event->ies && |
| 14592 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 14593 | goto out; |
| 14594 | if (ft_event->ric_ies && |
| 14595 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 14596 | ft_event->ric_ies)) |
| 14597 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14598 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14599 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14600 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14601 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14602 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14603 | return; |
| 14604 | out: |
| 14605 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14606 | } |
| 14607 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 14608 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 14609 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 14610 | { |
| 14611 | struct cfg80211_registered_device *rdev; |
| 14612 | struct sk_buff *msg; |
| 14613 | void *hdr; |
| 14614 | u32 nlportid; |
| 14615 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14616 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 14617 | if (!rdev->crit_proto_nlportid) |
| 14618 | return; |
| 14619 | |
| 14620 | nlportid = rdev->crit_proto_nlportid; |
| 14621 | rdev->crit_proto_nlportid = 0; |
| 14622 | |
| 14623 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 14624 | if (!msg) |
| 14625 | return; |
| 14626 | |
| 14627 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 14628 | if (!hdr) |
| 14629 | goto nla_put_failure; |
| 14630 | |
| 14631 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14632 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14633 | NL80211_ATTR_PAD)) |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 14634 | goto nla_put_failure; |
| 14635 | |
| 14636 | genlmsg_end(msg, hdr); |
| 14637 | |
| 14638 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 14639 | return; |
| 14640 | |
| 14641 | nla_put_failure: |
| 14642 | if (hdr) |
| 14643 | genlmsg_cancel(msg, hdr); |
| 14644 | nlmsg_free(msg); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 14645 | } |
| 14646 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 14647 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 14648 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 14649 | { |
| 14650 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14651 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 14652 | struct sk_buff *msg; |
| 14653 | void *hdr; |
| 14654 | |
| 14655 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 14656 | if (!msg) |
| 14657 | return; |
| 14658 | |
| 14659 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 14660 | if (!hdr) |
| 14661 | goto out; |
| 14662 | |
| 14663 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14664 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14665 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14666 | NL80211_ATTR_PAD)) |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 14667 | goto out; |
| 14668 | |
| 14669 | genlmsg_end(msg, hdr); |
| 14670 | |
| 14671 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 14672 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 14673 | return; |
| 14674 | out: |
| 14675 | nlmsg_free(msg); |
| 14676 | } |
| 14677 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14678 | /* initialisation/exit functions */ |
| 14679 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 14680 | int __init nl80211_init(void) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14681 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 14682 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14683 | |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 14684 | err = genl_register_family(&nl80211_fam); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14685 | if (err) |
| 14686 | return err; |
| 14687 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14688 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 14689 | if (err) |
| 14690 | goto err_out; |
| 14691 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14692 | return 0; |
| 14693 | err_out: |
| 14694 | genl_unregister_family(&nl80211_fam); |
| 14695 | return err; |
| 14696 | } |
| 14697 | |
| 14698 | void nl80211_exit(void) |
| 14699 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14700 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14701 | genl_unregister_family(&nl80211_fam); |
| 14702 | } |