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 |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 6 | * Copyright 2015-2017 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 }, |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 401 | [NL80211_ATTR_BANDS] = { .type = NLA_U32 }, |
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 }, |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 408 | [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 }, |
| 409 | [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = { |
| 410 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 411 | }, |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 412 | [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 }, |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 413 | [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY, |
| 414 | .len = FILS_ERP_MAX_USERNAME_LEN }, |
| 415 | [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY, |
| 416 | .len = FILS_ERP_MAX_REALM_LEN }, |
| 417 | [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 }, |
| 418 | [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY, |
| 419 | .len = FILS_ERP_MAX_RRK_LEN }, |
| 420 | [NL80211_ATTR_FILS_CACHE_ID] = { .len = 2 }, |
| 421 | [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 422 | }; |
| 423 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 424 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 425 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 426 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 427 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 428 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 429 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 430 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 431 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 432 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 433 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 434 | }; |
| 435 | |
| 436 | /* policy for the key default flags */ |
| 437 | static const struct nla_policy |
| 438 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 439 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 440 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 441 | }; |
| 442 | |
Johannes Berg | f83ace3 | 2016-10-17 08:04:07 +0200 | [diff] [blame] | 443 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 444 | /* policy for WoWLAN attributes */ |
| 445 | static const struct nla_policy |
| 446 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 447 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 448 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 449 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 450 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 451 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 452 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 453 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 454 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 455 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 456 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 457 | }; |
| 458 | |
| 459 | static const struct nla_policy |
| 460 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 461 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 462 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 463 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 464 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 465 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 466 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 467 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 468 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 469 | }, |
| 470 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 471 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 472 | }, |
| 473 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 474 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 475 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 476 | }; |
Johannes Berg | f83ace3 | 2016-10-17 08:04:07 +0200 | [diff] [blame] | 477 | #endif /* CONFIG_PM */ |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 478 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 479 | /* policy for coalesce rule attributes */ |
| 480 | static const struct nla_policy |
| 481 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 482 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 483 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 484 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 485 | }; |
| 486 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 487 | /* policy for GTK rekey offload attributes */ |
| 488 | static const struct nla_policy |
| 489 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 490 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 491 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 492 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 493 | }; |
| 494 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 495 | static const struct nla_policy |
| 496 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 497 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 498 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 499 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 500 | }; |
| 501 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 502 | static const struct nla_policy |
| 503 | nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { |
| 504 | [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, |
| 505 | [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, |
| 506 | }; |
| 507 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 508 | static const struct nla_policy |
| 509 | nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { |
| 510 | [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, |
| 511 | [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, |
| 512 | [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { |
| 513 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 514 | }, |
| 515 | }; |
| 516 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 517 | /* policy for NAN function attributes */ |
| 518 | static const struct nla_policy |
| 519 | nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { |
| 520 | [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 }, |
| 521 | [NL80211_NAN_FUNC_SERVICE_ID] = { .type = NLA_BINARY, |
| 522 | .len = NL80211_NAN_FUNC_SERVICE_ID_LEN }, |
| 523 | [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 }, |
| 524 | [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG }, |
| 525 | [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG }, |
| 526 | [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 }, |
| 527 | [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 }, |
| 528 | [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN }, |
| 529 | [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG }, |
| 530 | [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 }, |
| 531 | [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY, |
| 532 | .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN }, |
| 533 | [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED }, |
| 534 | [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 535 | [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 536 | [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 }, |
| 537 | [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 }, |
| 538 | }; |
| 539 | |
| 540 | /* policy for Service Response Filter attributes */ |
| 541 | static const struct nla_policy |
| 542 | nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = { |
| 543 | [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG }, |
| 544 | [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY, |
| 545 | .len = NL80211_NAN_FUNC_SRF_MAX_LEN }, |
| 546 | [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 }, |
| 547 | [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED }, |
| 548 | }; |
| 549 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 550 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 551 | struct netlink_callback *cb, |
| 552 | struct cfg80211_registered_device **rdev, |
| 553 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 554 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 555 | int err; |
| 556 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 557 | rtnl_lock(); |
| 558 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 559 | if (!cb->args[0]) { |
| 560 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 561 | genl_family_attrbuf(&nl80211_fam), |
| 562 | nl80211_fam.maxattr, nl80211_policy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 563 | if (err) |
| 564 | goto out_unlock; |
| 565 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 566 | *wdev = __cfg80211_wdev_from_attrs( |
| 567 | sock_net(skb->sk), |
| 568 | genl_family_attrbuf(&nl80211_fam)); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 569 | if (IS_ERR(*wdev)) { |
| 570 | err = PTR_ERR(*wdev); |
| 571 | goto out_unlock; |
| 572 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 573 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 574 | /* 0 is the first index - add 1 to parse only once */ |
| 575 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 576 | cb->args[1] = (*wdev)->identifier; |
| 577 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 578 | /* subtract the 1 again here */ |
| 579 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 580 | struct wireless_dev *tmp; |
| 581 | |
| 582 | if (!wiphy) { |
| 583 | err = -ENODEV; |
| 584 | goto out_unlock; |
| 585 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 586 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 587 | *wdev = NULL; |
| 588 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 589 | list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 590 | if (tmp->identifier == cb->args[1]) { |
| 591 | *wdev = tmp; |
| 592 | break; |
| 593 | } |
| 594 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 595 | |
| 596 | if (!*wdev) { |
| 597 | err = -ENODEV; |
| 598 | goto out_unlock; |
| 599 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 600 | } |
| 601 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 602 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 603 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 604 | rtnl_unlock(); |
| 605 | return err; |
| 606 | } |
| 607 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 608 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 609 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 610 | rtnl_unlock(); |
| 611 | } |
| 612 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 613 | /* IE validation */ |
| 614 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 615 | { |
| 616 | const u8 *pos; |
| 617 | int len; |
| 618 | |
| 619 | if (!attr) |
| 620 | return true; |
| 621 | |
| 622 | pos = nla_data(attr); |
| 623 | len = nla_len(attr); |
| 624 | |
| 625 | while (len) { |
| 626 | u8 elemlen; |
| 627 | |
| 628 | if (len < 2) |
| 629 | return false; |
| 630 | len -= 2; |
| 631 | |
| 632 | elemlen = pos[1]; |
| 633 | if (elemlen > len) |
| 634 | return false; |
| 635 | |
| 636 | len -= elemlen; |
| 637 | pos += 2 + elemlen; |
| 638 | } |
| 639 | |
| 640 | return true; |
| 641 | } |
| 642 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 643 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 644 | 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] | 645 | int flags, u8 cmd) |
| 646 | { |
| 647 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 648 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 649 | } |
| 650 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 651 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 652 | struct ieee80211_channel *chan, |
| 653 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 654 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 655 | /* Some channels must be completely excluded from the |
| 656 | * list to protect old user-space tools from breaking |
| 657 | */ |
| 658 | if (!large && chan->flags & |
| 659 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 660 | return 0; |
| 661 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 662 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 663 | chan->center_freq)) |
| 664 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 665 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 666 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 667 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 668 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 669 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 670 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 671 | goto nla_put_failure; |
| 672 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 673 | goto nla_put_failure; |
| 674 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 675 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 676 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 677 | goto nla_put_failure; |
| 678 | if (large) { |
| 679 | u32 time; |
| 680 | |
| 681 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 682 | |
| 683 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 684 | chan->dfs_state)) |
| 685 | goto nla_put_failure; |
| 686 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 687 | time)) |
| 688 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 689 | if (nla_put_u32(msg, |
| 690 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 691 | chan->dfs_cac_ms)) |
| 692 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 693 | } |
| 694 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 695 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 696 | if (large) { |
| 697 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 698 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 699 | goto nla_put_failure; |
| 700 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 701 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 702 | goto nla_put_failure; |
| 703 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 704 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 705 | goto nla_put_failure; |
| 706 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 707 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 708 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 709 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 710 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 711 | goto nla_put_failure; |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 712 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
| 713 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 714 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 715 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 716 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 717 | goto nla_put_failure; |
| 718 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 719 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 720 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 721 | } |
| 722 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 723 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 724 | DBM_TO_MBM(chan->max_power))) |
| 725 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 726 | |
| 727 | return 0; |
| 728 | |
| 729 | nla_put_failure: |
| 730 | return -ENOBUFS; |
| 731 | } |
| 732 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 733 | /* netlink command implementations */ |
| 734 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 735 | struct key_parse { |
| 736 | struct key_params p; |
| 737 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 738 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 739 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 740 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 741 | }; |
| 742 | |
| 743 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 744 | { |
| 745 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 746 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 747 | nl80211_key_policy); |
| 748 | if (err) |
| 749 | return err; |
| 750 | |
| 751 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 752 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 753 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 754 | if (k->def) { |
| 755 | k->def_uni = true; |
| 756 | k->def_multi = true; |
| 757 | } |
| 758 | if (k->defmgmt) |
| 759 | k->def_multi = true; |
| 760 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 761 | if (tb[NL80211_KEY_IDX]) |
| 762 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 763 | |
| 764 | if (tb[NL80211_KEY_DATA]) { |
| 765 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 766 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 767 | } |
| 768 | |
| 769 | if (tb[NL80211_KEY_SEQ]) { |
| 770 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 771 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 772 | } |
| 773 | |
| 774 | if (tb[NL80211_KEY_CIPHER]) |
| 775 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 776 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 777 | if (tb[NL80211_KEY_TYPE]) { |
| 778 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 779 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 780 | return -EINVAL; |
| 781 | } |
| 782 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 783 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 784 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 785 | |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 786 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 787 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 788 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 789 | if (err) |
| 790 | return err; |
| 791 | |
| 792 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 793 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 794 | } |
| 795 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 796 | return 0; |
| 797 | } |
| 798 | |
| 799 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 800 | { |
| 801 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 802 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 803 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 804 | } |
| 805 | |
| 806 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 807 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 808 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 809 | } |
| 810 | |
| 811 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 812 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 813 | |
| 814 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 815 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 816 | |
| 817 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 818 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 819 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 820 | if (k->def) { |
| 821 | k->def_uni = true; |
| 822 | k->def_multi = true; |
| 823 | } |
| 824 | if (k->defmgmt) |
| 825 | k->def_multi = true; |
| 826 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 827 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 828 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 829 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 830 | return -EINVAL; |
| 831 | } |
| 832 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 833 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 834 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 835 | int err = nla_parse_nested( |
| 836 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 837 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 838 | nl80211_key_default_policy); |
| 839 | if (err) |
| 840 | return err; |
| 841 | |
| 842 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 843 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 844 | } |
| 845 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 846 | return 0; |
| 847 | } |
| 848 | |
| 849 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 850 | { |
| 851 | int err; |
| 852 | |
| 853 | memset(k, 0, sizeof(*k)); |
| 854 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 855 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 856 | |
| 857 | if (info->attrs[NL80211_ATTR_KEY]) |
| 858 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 859 | else |
| 860 | err = nl80211_parse_key_old(info, k); |
| 861 | |
| 862 | if (err) |
| 863 | return err; |
| 864 | |
| 865 | if (k->def && k->defmgmt) |
| 866 | return -EINVAL; |
| 867 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 868 | if (k->defmgmt) { |
| 869 | if (k->def_uni || !k->def_multi) |
| 870 | return -EINVAL; |
| 871 | } |
| 872 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 873 | if (k->idx != -1) { |
| 874 | if (k->defmgmt) { |
| 875 | if (k->idx < 4 || k->idx > 5) |
| 876 | return -EINVAL; |
| 877 | } else if (k->def) { |
| 878 | if (k->idx < 0 || k->idx > 3) |
| 879 | return -EINVAL; |
| 880 | } else { |
| 881 | if (k->idx < 0 || k->idx > 5) |
| 882 | return -EINVAL; |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | return 0; |
| 887 | } |
| 888 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 889 | static struct cfg80211_cached_keys * |
| 890 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 891 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 892 | { |
| 893 | struct key_parse parse; |
| 894 | struct nlattr *key; |
| 895 | struct cfg80211_cached_keys *result; |
| 896 | int rem, err, def = 0; |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 897 | bool have_key = false; |
| 898 | |
| 899 | nla_for_each_nested(key, keys, rem) { |
| 900 | have_key = true; |
| 901 | break; |
| 902 | } |
| 903 | |
| 904 | if (!have_key) |
| 905 | return NULL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 906 | |
| 907 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 908 | if (!result) |
| 909 | return ERR_PTR(-ENOMEM); |
| 910 | |
| 911 | result->def = -1; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 912 | |
| 913 | nla_for_each_nested(key, keys, rem) { |
| 914 | memset(&parse, 0, sizeof(parse)); |
| 915 | parse.idx = -1; |
| 916 | |
| 917 | err = nl80211_parse_key_new(key, &parse); |
| 918 | if (err) |
| 919 | goto error; |
| 920 | err = -EINVAL; |
| 921 | if (!parse.p.key) |
| 922 | goto error; |
Johannes Berg | 42ee231 | 2016-09-13 15:51:03 +0200 | [diff] [blame] | 923 | if (parse.idx < 0 || parse.idx > 3) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 924 | goto error; |
| 925 | if (parse.def) { |
| 926 | if (def) |
| 927 | goto error; |
| 928 | def = 1; |
| 929 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 930 | if (!parse.def_uni || !parse.def_multi) |
| 931 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 932 | } else if (parse.defmgmt) |
| 933 | goto error; |
| 934 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 935 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 936 | if (err) |
| 937 | goto error; |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 938 | if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && |
| 939 | parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { |
| 940 | err = -EINVAL; |
| 941 | goto error; |
| 942 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 943 | result->params[parse.idx].cipher = parse.p.cipher; |
| 944 | result->params[parse.idx].key_len = parse.p.key_len; |
| 945 | result->params[parse.idx].key = result->data[parse.idx]; |
| 946 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 947 | |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 948 | /* must be WEP key if we got here */ |
| 949 | if (no_ht) |
| 950 | *no_ht = true; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 951 | } |
| 952 | |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 953 | if (result->def < 0) { |
| 954 | err = -EINVAL; |
| 955 | goto error; |
| 956 | } |
| 957 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 958 | return result; |
| 959 | error: |
| 960 | kfree(result); |
| 961 | return ERR_PTR(err); |
| 962 | } |
| 963 | |
| 964 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 965 | { |
| 966 | ASSERT_WDEV_LOCK(wdev); |
| 967 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 968 | switch (wdev->iftype) { |
| 969 | case NL80211_IFTYPE_AP: |
| 970 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 971 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 972 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 973 | break; |
| 974 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 975 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 976 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 977 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 978 | return -ENOLINK; |
| 979 | break; |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 980 | case NL80211_IFTYPE_UNSPECIFIED: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 981 | case NL80211_IFTYPE_OCB: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 982 | case NL80211_IFTYPE_MONITOR: |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 983 | case NL80211_IFTYPE_NAN: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 984 | case NL80211_IFTYPE_P2P_DEVICE: |
| 985 | case NL80211_IFTYPE_WDS: |
| 986 | case NUM_NL80211_IFTYPES: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 987 | return -EINVAL; |
| 988 | } |
| 989 | |
| 990 | return 0; |
| 991 | } |
| 992 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 993 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 994 | struct nlattr *tb) |
| 995 | { |
| 996 | struct ieee80211_channel *chan; |
| 997 | |
| 998 | if (tb == NULL) |
| 999 | return NULL; |
| 1000 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 1001 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 1002 | return NULL; |
| 1003 | return chan; |
| 1004 | } |
| 1005 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1006 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 1007 | { |
| 1008 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 1009 | int i; |
| 1010 | |
| 1011 | if (!nl_modes) |
| 1012 | goto nla_put_failure; |
| 1013 | |
| 1014 | i = 0; |
| 1015 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1016 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 1017 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1018 | ifmodes >>= 1; |
| 1019 | i++; |
| 1020 | } |
| 1021 | |
| 1022 | nla_nest_end(msg, nl_modes); |
| 1023 | return 0; |
| 1024 | |
| 1025 | nla_put_failure: |
| 1026 | return -ENOBUFS; |
| 1027 | } |
| 1028 | |
| 1029 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1030 | struct sk_buff *msg, |
| 1031 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1032 | { |
| 1033 | struct nlattr *nl_combis; |
| 1034 | int i, j; |
| 1035 | |
| 1036 | nl_combis = nla_nest_start(msg, |
| 1037 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 1038 | if (!nl_combis) |
| 1039 | goto nla_put_failure; |
| 1040 | |
| 1041 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 1042 | const struct ieee80211_iface_combination *c; |
| 1043 | struct nlattr *nl_combi, *nl_limits; |
| 1044 | |
| 1045 | c = &wiphy->iface_combinations[i]; |
| 1046 | |
| 1047 | nl_combi = nla_nest_start(msg, i + 1); |
| 1048 | if (!nl_combi) |
| 1049 | goto nla_put_failure; |
| 1050 | |
| 1051 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 1052 | if (!nl_limits) |
| 1053 | goto nla_put_failure; |
| 1054 | |
| 1055 | for (j = 0; j < c->n_limits; j++) { |
| 1056 | struct nlattr *nl_limit; |
| 1057 | |
| 1058 | nl_limit = nla_nest_start(msg, j + 1); |
| 1059 | if (!nl_limit) |
| 1060 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1061 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 1062 | c->limits[j].max)) |
| 1063 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1064 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 1065 | c->limits[j].types)) |
| 1066 | goto nla_put_failure; |
| 1067 | nla_nest_end(msg, nl_limit); |
| 1068 | } |
| 1069 | |
| 1070 | nla_nest_end(msg, nl_limits); |
| 1071 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1072 | if (c->beacon_int_infra_match && |
| 1073 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 1074 | goto nla_put_failure; |
| 1075 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 1076 | c->num_different_channels) || |
| 1077 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 1078 | c->max_interfaces)) |
| 1079 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1080 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 1081 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 1082 | c->radar_detect_widths) || |
| 1083 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 1084 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1085 | goto nla_put_failure; |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 1086 | if (c->beacon_int_min_gcd && |
| 1087 | nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD, |
| 1088 | c->beacon_int_min_gcd)) |
| 1089 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1090 | |
| 1091 | nla_nest_end(msg, nl_combi); |
| 1092 | } |
| 1093 | |
| 1094 | nla_nest_end(msg, nl_combis); |
| 1095 | |
| 1096 | return 0; |
| 1097 | nla_put_failure: |
| 1098 | return -ENOBUFS; |
| 1099 | } |
| 1100 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1101 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1102 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 1103 | struct sk_buff *msg) |
| 1104 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1105 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1106 | struct nlattr *nl_tcp; |
| 1107 | |
| 1108 | if (!tcp) |
| 1109 | return 0; |
| 1110 | |
| 1111 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 1112 | if (!nl_tcp) |
| 1113 | return -ENOBUFS; |
| 1114 | |
| 1115 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1116 | tcp->data_payload_max)) |
| 1117 | return -ENOBUFS; |
| 1118 | |
| 1119 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1120 | tcp->data_payload_max)) |
| 1121 | return -ENOBUFS; |
| 1122 | |
| 1123 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1124 | return -ENOBUFS; |
| 1125 | |
| 1126 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1127 | sizeof(*tcp->tok), tcp->tok)) |
| 1128 | return -ENOBUFS; |
| 1129 | |
| 1130 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1131 | tcp->data_interval_max)) |
| 1132 | return -ENOBUFS; |
| 1133 | |
| 1134 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1135 | tcp->wake_payload_max)) |
| 1136 | return -ENOBUFS; |
| 1137 | |
| 1138 | nla_nest_end(msg, nl_tcp); |
| 1139 | return 0; |
| 1140 | } |
| 1141 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1142 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1143 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1144 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1145 | { |
| 1146 | struct nlattr *nl_wowlan; |
| 1147 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1148 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1149 | return 0; |
| 1150 | |
| 1151 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1152 | if (!nl_wowlan) |
| 1153 | return -ENOBUFS; |
| 1154 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1155 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1156 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1157 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1158 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1159 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1160 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1161 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1162 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1163 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1164 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1165 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1166 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1167 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1168 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1169 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1170 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1171 | return -ENOBUFS; |
| 1172 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1173 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1174 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1175 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1176 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1177 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1178 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1179 | }; |
| 1180 | |
| 1181 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1182 | sizeof(pat), &pat)) |
| 1183 | return -ENOBUFS; |
| 1184 | } |
| 1185 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 1186 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
| 1187 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, |
| 1188 | rdev->wiphy.wowlan->max_nd_match_sets)) |
| 1189 | return -ENOBUFS; |
| 1190 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1191 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1192 | return -ENOBUFS; |
| 1193 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1194 | nla_nest_end(msg, nl_wowlan); |
| 1195 | |
| 1196 | return 0; |
| 1197 | } |
| 1198 | #endif |
| 1199 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1200 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1201 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1202 | { |
| 1203 | struct nl80211_coalesce_rule_support rule; |
| 1204 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1205 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1206 | return 0; |
| 1207 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1208 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1209 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1210 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1211 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1212 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1213 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1214 | |
| 1215 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1216 | return -ENOBUFS; |
| 1217 | |
| 1218 | return 0; |
| 1219 | } |
| 1220 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1221 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1222 | struct ieee80211_supported_band *sband) |
| 1223 | { |
| 1224 | struct nlattr *nl_rates, *nl_rate; |
| 1225 | struct ieee80211_rate *rate; |
| 1226 | int i; |
| 1227 | |
| 1228 | /* add HT info */ |
| 1229 | if (sband->ht_cap.ht_supported && |
| 1230 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1231 | sizeof(sband->ht_cap.mcs), |
| 1232 | &sband->ht_cap.mcs) || |
| 1233 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1234 | sband->ht_cap.cap) || |
| 1235 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1236 | sband->ht_cap.ampdu_factor) || |
| 1237 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1238 | sband->ht_cap.ampdu_density))) |
| 1239 | return -ENOBUFS; |
| 1240 | |
| 1241 | /* add VHT info */ |
| 1242 | if (sband->vht_cap.vht_supported && |
| 1243 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1244 | sizeof(sband->vht_cap.vht_mcs), |
| 1245 | &sband->vht_cap.vht_mcs) || |
| 1246 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1247 | sband->vht_cap.cap))) |
| 1248 | return -ENOBUFS; |
| 1249 | |
| 1250 | /* add bitrates */ |
| 1251 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1252 | if (!nl_rates) |
| 1253 | return -ENOBUFS; |
| 1254 | |
| 1255 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1256 | nl_rate = nla_nest_start(msg, i); |
| 1257 | if (!nl_rate) |
| 1258 | return -ENOBUFS; |
| 1259 | |
| 1260 | rate = &sband->bitrates[i]; |
| 1261 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1262 | rate->bitrate)) |
| 1263 | return -ENOBUFS; |
| 1264 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1265 | nla_put_flag(msg, |
| 1266 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1267 | return -ENOBUFS; |
| 1268 | |
| 1269 | nla_nest_end(msg, nl_rate); |
| 1270 | } |
| 1271 | |
| 1272 | nla_nest_end(msg, nl_rates); |
| 1273 | |
| 1274 | return 0; |
| 1275 | } |
| 1276 | |
| 1277 | static int |
| 1278 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1279 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1280 | { |
| 1281 | u16 stypes; |
| 1282 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1283 | enum nl80211_iftype ift; |
| 1284 | int i; |
| 1285 | |
| 1286 | if (!mgmt_stypes) |
| 1287 | return 0; |
| 1288 | |
| 1289 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1290 | if (!nl_ifs) |
| 1291 | return -ENOBUFS; |
| 1292 | |
| 1293 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1294 | nl_ftypes = nla_nest_start(msg, ift); |
| 1295 | if (!nl_ftypes) |
| 1296 | return -ENOBUFS; |
| 1297 | i = 0; |
| 1298 | stypes = mgmt_stypes[ift].tx; |
| 1299 | while (stypes) { |
| 1300 | if ((stypes & 1) && |
| 1301 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1302 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1303 | return -ENOBUFS; |
| 1304 | stypes >>= 1; |
| 1305 | i++; |
| 1306 | } |
| 1307 | nla_nest_end(msg, nl_ftypes); |
| 1308 | } |
| 1309 | |
| 1310 | nla_nest_end(msg, nl_ifs); |
| 1311 | |
| 1312 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1313 | if (!nl_ifs) |
| 1314 | return -ENOBUFS; |
| 1315 | |
| 1316 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1317 | nl_ftypes = nla_nest_start(msg, ift); |
| 1318 | if (!nl_ftypes) |
| 1319 | return -ENOBUFS; |
| 1320 | i = 0; |
| 1321 | stypes = mgmt_stypes[ift].rx; |
| 1322 | while (stypes) { |
| 1323 | if ((stypes & 1) && |
| 1324 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1325 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1326 | return -ENOBUFS; |
| 1327 | stypes >>= 1; |
| 1328 | i++; |
| 1329 | } |
| 1330 | nla_nest_end(msg, nl_ftypes); |
| 1331 | } |
| 1332 | nla_nest_end(msg, nl_ifs); |
| 1333 | |
| 1334 | return 0; |
| 1335 | } |
| 1336 | |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1337 | #define CMD(op, n) \ |
| 1338 | do { \ |
| 1339 | if (rdev->ops->op) { \ |
| 1340 | i++; \ |
| 1341 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1342 | goto nla_put_failure; \ |
| 1343 | } \ |
| 1344 | } while (0) |
| 1345 | |
| 1346 | static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev, |
| 1347 | struct sk_buff *msg) |
| 1348 | { |
| 1349 | int i = 0; |
| 1350 | |
| 1351 | /* |
| 1352 | * do *NOT* add anything into this function, new things need to be |
| 1353 | * advertised only to new versions of userspace that can deal with |
| 1354 | * the split (and they can't possibly care about new features... |
| 1355 | */ |
| 1356 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1357 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1358 | CMD(add_key, NEW_KEY); |
| 1359 | CMD(start_ap, START_AP); |
| 1360 | CMD(add_station, NEW_STATION); |
| 1361 | CMD(add_mpath, NEW_MPATH); |
| 1362 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1363 | CMD(change_bss, SET_BSS); |
| 1364 | CMD(auth, AUTHENTICATE); |
| 1365 | CMD(assoc, ASSOCIATE); |
| 1366 | CMD(deauth, DEAUTHENTICATE); |
| 1367 | CMD(disassoc, DISASSOCIATE); |
| 1368 | CMD(join_ibss, JOIN_IBSS); |
| 1369 | CMD(join_mesh, JOIN_MESH); |
| 1370 | CMD(set_pmksa, SET_PMKSA); |
| 1371 | CMD(del_pmksa, DEL_PMKSA); |
| 1372 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1373 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1374 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1375 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1376 | CMD(mgmt_tx, FRAME); |
| 1377 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1378 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1379 | i++; |
| 1380 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1381 | goto nla_put_failure; |
| 1382 | } |
| 1383 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1384 | rdev->ops->join_mesh) { |
| 1385 | i++; |
| 1386 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1387 | goto nla_put_failure; |
| 1388 | } |
| 1389 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1390 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1391 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1392 | CMD(tdls_oper, TDLS_OPER); |
| 1393 | } |
| 1394 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 1395 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1396 | CMD(probe_client, PROBE_CLIENT); |
| 1397 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1398 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1399 | i++; |
| 1400 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1401 | goto nla_put_failure; |
| 1402 | } |
| 1403 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1404 | CMD(set_mcast_rate, SET_MCAST_RATE); |
| 1405 | #ifdef CONFIG_NL80211_TESTMODE |
| 1406 | CMD(testmode_cmd, TESTMODE); |
| 1407 | #endif |
| 1408 | |
| 1409 | if (rdev->ops->connect || rdev->ops->auth) { |
| 1410 | i++; |
| 1411 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
| 1412 | goto nla_put_failure; |
| 1413 | } |
| 1414 | |
| 1415 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
| 1416 | i++; |
| 1417 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1418 | goto nla_put_failure; |
| 1419 | } |
| 1420 | |
| 1421 | return i; |
| 1422 | nla_put_failure: |
| 1423 | return -ENOBUFS; |
| 1424 | } |
| 1425 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1426 | struct nl80211_dump_wiphy_state { |
| 1427 | s64 filter_wiphy; |
| 1428 | long start; |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 1429 | long split_start, band_start, chan_start, capa_start; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1430 | bool split; |
| 1431 | }; |
| 1432 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1433 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1434 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1435 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1436 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1437 | { |
| 1438 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1439 | struct nlattr *nl_bands, *nl_band; |
| 1440 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1441 | struct nlattr *nl_cmds; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1442 | enum nl80211_band band; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1443 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1444 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1445 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1446 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1447 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1448 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1449 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1450 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1451 | return -ENOBUFS; |
| 1452 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1453 | if (WARN_ON(!state)) |
| 1454 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1455 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1456 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1457 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1458 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1459 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1460 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1461 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1462 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1463 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 1464 | goto finish; |
| 1465 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1466 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1467 | case 0: |
| 1468 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1469 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1470 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1471 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1472 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1473 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1474 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1475 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1476 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1477 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1478 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1479 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1480 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1481 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1482 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1483 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1484 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1485 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1486 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 1487 | rdev->wiphy.max_match_sets) || |
| 1488 | nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, |
| 1489 | rdev->wiphy.max_sched_scan_plans) || |
| 1490 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, |
| 1491 | rdev->wiphy.max_sched_scan_plan_interval) || |
| 1492 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, |
| 1493 | rdev->wiphy.max_sched_scan_plan_iterations)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1494 | goto nla_put_failure; |
| 1495 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1496 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1497 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1498 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1499 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1500 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1501 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1502 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1503 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1504 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1505 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1506 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1507 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1508 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1509 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1510 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1511 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1512 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1513 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1514 | state->split_start++; |
| 1515 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1516 | break; |
| 1517 | case 1: |
| 1518 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1519 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 1520 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1521 | goto nla_put_failure; |
| 1522 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1523 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1524 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1525 | goto nla_put_failure; |
| 1526 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1527 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1528 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1529 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1530 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1531 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1532 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1533 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1534 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1535 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1536 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1537 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1538 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1539 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1540 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1541 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1542 | if ((rdev->wiphy.available_antennas_tx || |
| 1543 | rdev->wiphy.available_antennas_rx) && |
| 1544 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1545 | u32 tx_ant = 0, rx_ant = 0; |
| 1546 | int res; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 1547 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1548 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1549 | if (!res) { |
| 1550 | if (nla_put_u32(msg, |
| 1551 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1552 | tx_ant) || |
| 1553 | nla_put_u32(msg, |
| 1554 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1555 | rx_ant)) |
| 1556 | goto nla_put_failure; |
| 1557 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1558 | } |
| 1559 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1560 | state->split_start++; |
| 1561 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1562 | break; |
| 1563 | case 2: |
| 1564 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1565 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1566 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1567 | state->split_start++; |
| 1568 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1569 | break; |
| 1570 | case 3: |
| 1571 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1572 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1573 | goto nla_put_failure; |
| 1574 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1575 | for (band = state->band_start; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1576 | band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1577 | struct ieee80211_supported_band *sband; |
| 1578 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1579 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1580 | |
| 1581 | if (!sband) |
| 1582 | continue; |
| 1583 | |
| 1584 | nl_band = nla_nest_start(msg, band); |
| 1585 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1586 | goto nla_put_failure; |
| 1587 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1588 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1589 | case 0: |
| 1590 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1591 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1592 | state->chan_start++; |
| 1593 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1594 | break; |
| 1595 | default: |
| 1596 | /* add frequencies */ |
| 1597 | nl_freqs = nla_nest_start( |
| 1598 | msg, NL80211_BAND_ATTR_FREQS); |
| 1599 | if (!nl_freqs) |
| 1600 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1601 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1602 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1603 | i < sband->n_channels; |
| 1604 | i++) { |
| 1605 | nl_freq = nla_nest_start(msg, i); |
| 1606 | if (!nl_freq) |
| 1607 | goto nla_put_failure; |
| 1608 | |
| 1609 | chan = &sband->channels[i]; |
| 1610 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1611 | if (nl80211_msg_put_channel( |
| 1612 | msg, chan, |
| 1613 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1614 | goto nla_put_failure; |
| 1615 | |
| 1616 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1617 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1618 | break; |
| 1619 | } |
| 1620 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1621 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1622 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1623 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1624 | nla_nest_end(msg, nl_freqs); |
| 1625 | } |
| 1626 | |
| 1627 | nla_nest_end(msg, nl_band); |
| 1628 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1629 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1630 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1631 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1632 | band--; |
| 1633 | break; |
| 1634 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1635 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1636 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1637 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1638 | if (band < NUM_NL80211_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1639 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1640 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1641 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1642 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1643 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1644 | if (state->band_start == 0 && state->chan_start == 0) |
| 1645 | state->split_start++; |
| 1646 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1647 | break; |
| 1648 | case 4: |
| 1649 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1650 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1651 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1652 | |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1653 | i = nl80211_add_commands_unsplit(rdev, msg); |
| 1654 | if (i < 0) |
| 1655 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1656 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1657 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1658 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1659 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1660 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1661 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 1662 | if (rdev->wiphy.features & |
| 1663 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 1664 | CMD(add_tx_ts, ADD_TX_TS); |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 1665 | CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST); |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 1666 | CMD(update_connect_params, UPDATE_CONNECT_PARAMS); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1667 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1668 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1669 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1670 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1671 | state->split_start++; |
| 1672 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1673 | break; |
| 1674 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1675 | if (rdev->ops->remain_on_channel && |
| 1676 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1677 | nla_put_u32(msg, |
| 1678 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1679 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1680 | goto nla_put_failure; |
| 1681 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1682 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1683 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1684 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1685 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1686 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1687 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1688 | state->split_start++; |
| 1689 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1690 | break; |
| 1691 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1692 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1693 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1694 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1695 | state->split_start++; |
| 1696 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1697 | break; |
| 1698 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1699 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1700 | #endif |
| 1701 | case 7: |
| 1702 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1703 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1704 | goto nla_put_failure; |
| 1705 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1706 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1707 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1708 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1709 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1710 | state->split_start++; |
| 1711 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1712 | break; |
| 1713 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1714 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1715 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1716 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1717 | goto nla_put_failure; |
| 1718 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1719 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1720 | /* |
| 1721 | * We can only add the per-channel limit information if the |
| 1722 | * dump is split, otherwise it makes it too big. Therefore |
| 1723 | * only advertise it in that case. |
| 1724 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1725 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1726 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1727 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1728 | goto nla_put_failure; |
| 1729 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1730 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1731 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1732 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 1733 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1734 | goto nla_put_failure; |
| 1735 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1736 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1737 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1738 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1739 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1740 | goto nla_put_failure; |
| 1741 | |
| 1742 | /* |
| 1743 | * Any information below this point is only available to |
| 1744 | * applications that can deal with it being split. This |
| 1745 | * helps ensure that newly added capabilities don't break |
| 1746 | * older tools by overrunning their buffers. |
| 1747 | * |
| 1748 | * We still increment split_start so that in the split |
| 1749 | * case we'll continue with more data in the next round, |
| 1750 | * but break unconditionally so unsplit data stops here. |
| 1751 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1752 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1753 | break; |
| 1754 | case 9: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1755 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1756 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1757 | rdev->wiphy.extended_capabilities_len, |
| 1758 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1759 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1760 | rdev->wiphy.extended_capabilities_len, |
| 1761 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1762 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1763 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1764 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1765 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1766 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 1767 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1768 | goto nla_put_failure; |
| 1769 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1770 | state->split_start++; |
| 1771 | break; |
| 1772 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1773 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1774 | goto nla_put_failure; |
| 1775 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1776 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1777 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1778 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1779 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1780 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1781 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1782 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1783 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1784 | goto nla_put_failure; |
| 1785 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1786 | state->split_start++; |
| 1787 | break; |
| 1788 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1789 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1790 | const struct nl80211_vendor_cmd_info *info; |
| 1791 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1792 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1793 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1794 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1795 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1796 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1797 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 1798 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1799 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1800 | goto nla_put_failure; |
| 1801 | } |
| 1802 | nla_nest_end(msg, nested); |
| 1803 | } |
| 1804 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1805 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1806 | const struct nl80211_vendor_cmd_info *info; |
| 1807 | struct nlattr *nested; |
| 1808 | |
| 1809 | nested = nla_nest_start(msg, |
| 1810 | NL80211_ATTR_VENDOR_EVENTS); |
| 1811 | if (!nested) |
| 1812 | goto nla_put_failure; |
| 1813 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1814 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 1815 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1816 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1817 | goto nla_put_failure; |
| 1818 | } |
| 1819 | nla_nest_end(msg, nested); |
| 1820 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 1821 | state->split_start++; |
| 1822 | break; |
| 1823 | case 12: |
| 1824 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 1825 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 1826 | rdev->wiphy.max_num_csa_counters)) |
| 1827 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1828 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 1829 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 1830 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 1831 | goto nla_put_failure; |
| 1832 | |
Gautam Kumar Shukla | d75bb06 | 2014-12-23 16:55:19 +0100 | [diff] [blame] | 1833 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
| 1834 | sizeof(rdev->wiphy.ext_features), |
| 1835 | rdev->wiphy.ext_features)) |
| 1836 | goto nla_put_failure; |
| 1837 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 1838 | if (rdev->wiphy.bss_select_support) { |
| 1839 | struct nlattr *nested; |
| 1840 | u32 bss_select_support = rdev->wiphy.bss_select_support; |
| 1841 | |
| 1842 | nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT); |
| 1843 | if (!nested) |
| 1844 | goto nla_put_failure; |
| 1845 | |
| 1846 | i = 0; |
| 1847 | while (bss_select_support) { |
| 1848 | if ((bss_select_support & 1) && |
| 1849 | nla_put_flag(msg, i)) |
| 1850 | goto nla_put_failure; |
| 1851 | i++; |
| 1852 | bss_select_support >>= 1; |
| 1853 | } |
| 1854 | nla_nest_end(msg, nested); |
| 1855 | } |
| 1856 | |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 1857 | state->split_start++; |
| 1858 | break; |
| 1859 | case 13: |
| 1860 | if (rdev->wiphy.num_iftype_ext_capab && |
| 1861 | rdev->wiphy.iftype_ext_capab) { |
| 1862 | struct nlattr *nested_ext_capab, *nested; |
| 1863 | |
| 1864 | nested = nla_nest_start(msg, |
| 1865 | NL80211_ATTR_IFTYPE_EXT_CAPA); |
| 1866 | if (!nested) |
| 1867 | goto nla_put_failure; |
| 1868 | |
| 1869 | for (i = state->capa_start; |
| 1870 | i < rdev->wiphy.num_iftype_ext_capab; i++) { |
| 1871 | const struct wiphy_iftype_ext_capab *capab; |
| 1872 | |
| 1873 | capab = &rdev->wiphy.iftype_ext_capab[i]; |
| 1874 | |
| 1875 | nested_ext_capab = nla_nest_start(msg, i); |
| 1876 | if (!nested_ext_capab || |
| 1877 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, |
| 1878 | capab->iftype) || |
| 1879 | nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 1880 | capab->extended_capabilities_len, |
| 1881 | capab->extended_capabilities) || |
| 1882 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 1883 | capab->extended_capabilities_len, |
| 1884 | capab->extended_capabilities_mask)) |
| 1885 | goto nla_put_failure; |
| 1886 | |
| 1887 | nla_nest_end(msg, nested_ext_capab); |
| 1888 | if (state->split) |
| 1889 | break; |
| 1890 | } |
| 1891 | nla_nest_end(msg, nested); |
| 1892 | if (i < rdev->wiphy.num_iftype_ext_capab) { |
| 1893 | state->capa_start = i + 1; |
| 1894 | break; |
| 1895 | } |
| 1896 | } |
| 1897 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 1898 | if (nla_put_u32(msg, NL80211_ATTR_BANDS, |
| 1899 | rdev->wiphy.nan_supported_bands)) |
| 1900 | goto nla_put_failure; |
| 1901 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1902 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1903 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1904 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1905 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1906 | finish: |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 1907 | genlmsg_end(msg, hdr); |
| 1908 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1909 | |
| 1910 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1911 | genlmsg_cancel(msg, hdr); |
| 1912 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1913 | } |
| 1914 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1915 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1916 | struct netlink_callback *cb, |
| 1917 | struct nl80211_dump_wiphy_state *state) |
| 1918 | { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 1919 | struct nlattr **tb = genl_family_attrbuf(&nl80211_fam); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1920 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1921 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1922 | /* ignore parse errors for backward compatibility */ |
| 1923 | if (ret) |
| 1924 | return 0; |
| 1925 | |
| 1926 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1927 | if (tb[NL80211_ATTR_WIPHY]) |
| 1928 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1929 | if (tb[NL80211_ATTR_WDEV]) |
| 1930 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1931 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1932 | struct net_device *netdev; |
| 1933 | struct cfg80211_registered_device *rdev; |
| 1934 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1935 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1936 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1937 | if (!netdev) |
| 1938 | return -ENODEV; |
| 1939 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1940 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1941 | netdev->ieee80211_ptr->wiphy); |
| 1942 | state->filter_wiphy = rdev->wiphy_idx; |
| 1943 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | return 0; |
| 1947 | } |
| 1948 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1949 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1950 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1951 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1952 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1953 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1954 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1955 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1956 | if (!state) { |
| 1957 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1958 | if (!state) { |
| 1959 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1960 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1961 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1962 | state->filter_wiphy = -1; |
| 1963 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1964 | if (ret) { |
| 1965 | kfree(state); |
| 1966 | rtnl_unlock(); |
| 1967 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1968 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1969 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1970 | } |
| 1971 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1972 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1973 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1974 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1975 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1976 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1977 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1978 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1979 | continue; |
| 1980 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1981 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1982 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 1983 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1984 | NETLINK_CB(cb->skb).portid, |
| 1985 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1986 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1987 | if (ret < 0) { |
| 1988 | /* |
| 1989 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1990 | * or EMSGSIZE returned), this SKB is still |
| 1991 | * empty (so it's not too big because another |
| 1992 | * wiphy dataset is already in the skb) and |
| 1993 | * we've not tried to adjust the dump allocation |
| 1994 | * yet ... then adjust the alloc size to be |
| 1995 | * bigger, and return 1 but with the empty skb. |
| 1996 | * This results in an empty message being RX'ed |
| 1997 | * in userspace, but that is ignored. |
| 1998 | * |
| 1999 | * We can then retry with the larger buffer. |
| 2000 | */ |
| 2001 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 2002 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2003 | cb->min_dump_alloc < 4096) { |
| 2004 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 2005 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 2006 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2007 | return 1; |
| 2008 | } |
| 2009 | idx--; |
| 2010 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2011 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2012 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2013 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2014 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2015 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2016 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2017 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2018 | |
| 2019 | return skb->len; |
| 2020 | } |
| 2021 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2022 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 2023 | { |
| 2024 | kfree((void *)cb->args[0]); |
| 2025 | return 0; |
| 2026 | } |
| 2027 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2028 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2029 | { |
| 2030 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2031 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2032 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2033 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2034 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2035 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2036 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2037 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2038 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 2039 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2040 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2041 | nlmsg_free(msg); |
| 2042 | return -ENOBUFS; |
| 2043 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2044 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2045 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2046 | } |
| 2047 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2048 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 2049 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 2050 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 2051 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 2052 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 2053 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 2054 | }; |
| 2055 | |
| 2056 | static int parse_txq_params(struct nlattr *tb[], |
| 2057 | struct ieee80211_txq_params *txq_params) |
| 2058 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2059 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2060 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 2061 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 2062 | return -EINVAL; |
| 2063 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2064 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2065 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 2066 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 2067 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 2068 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 2069 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2070 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 2071 | return -EINVAL; |
| 2072 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2073 | return 0; |
| 2074 | } |
| 2075 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2076 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 2077 | { |
| 2078 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2079 | * You can only set the channel explicitly for WDS interfaces, |
| 2080 | * all others have their channel managed via their respective |
| 2081 | * "establish a connection" command (connect, join, ...) |
| 2082 | * |
| 2083 | * For AP/GO and mesh mode, the channel can be set with the |
| 2084 | * channel userspace API, but is only stored and passed to the |
| 2085 | * low-level driver when the AP starts or the mesh is joined. |
| 2086 | * This is for backward compatibility, userspace can also give |
| 2087 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2088 | * |
| 2089 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2090 | * whatever else is going on, so they have their own special |
| 2091 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2092 | */ |
| 2093 | return !wdev || |
| 2094 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2095 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2096 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 2097 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2098 | } |
| 2099 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2100 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 2101 | struct genl_info *info, |
| 2102 | struct cfg80211_chan_def *chandef) |
| 2103 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 2104 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2105 | |
| 2106 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 2107 | return -EINVAL; |
| 2108 | |
| 2109 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 2110 | |
| 2111 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2112 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 2113 | chandef->center_freq1 = control_freq; |
| 2114 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2115 | |
| 2116 | /* Primary channel not allowed */ |
| 2117 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 2118 | return -EINVAL; |
| 2119 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2120 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 2121 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2122 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2123 | chantype = nla_get_u32( |
| 2124 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 2125 | |
| 2126 | switch (chantype) { |
| 2127 | case NL80211_CHAN_NO_HT: |
| 2128 | case NL80211_CHAN_HT20: |
| 2129 | case NL80211_CHAN_HT40PLUS: |
| 2130 | case NL80211_CHAN_HT40MINUS: |
| 2131 | cfg80211_chandef_create(chandef, chandef->chan, |
| 2132 | chantype); |
| 2133 | break; |
| 2134 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2135 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2136 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2137 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 2138 | chandef->width = |
| 2139 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 2140 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 2141 | chandef->center_freq1 = |
| 2142 | nla_get_u32( |
| 2143 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 2144 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 2145 | chandef->center_freq2 = |
| 2146 | nla_get_u32( |
| 2147 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 2148 | } |
| 2149 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2150 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2151 | return -EINVAL; |
| 2152 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2153 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 2154 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2155 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2156 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2157 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 2158 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 2159 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 2160 | return -EINVAL; |
| 2161 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2162 | return 0; |
| 2163 | } |
| 2164 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2165 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2166 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2167 | struct genl_info *info) |
| 2168 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2169 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2170 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2171 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2172 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2173 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2174 | if (dev) |
| 2175 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2176 | if (!nl80211_can_set_dev_channel(wdev)) |
| 2177 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2178 | if (wdev) |
| 2179 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2180 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2181 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 2182 | if (result) |
| 2183 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2184 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2185 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2186 | case NL80211_IFTYPE_AP: |
| 2187 | case NL80211_IFTYPE_P2P_GO: |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 2188 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 2189 | iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2190 | result = -EINVAL; |
| 2191 | break; |
| 2192 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2193 | if (wdev->beacon_interval) { |
| 2194 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 2195 | !(rdev->wiphy.features & |
| 2196 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 2197 | result = -EBUSY; |
| 2198 | break; |
| 2199 | } |
| 2200 | |
| 2201 | /* Only allow dynamic channel width changes */ |
| 2202 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 2203 | result = -EBUSY; |
| 2204 | break; |
| 2205 | } |
| 2206 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 2207 | if (result) |
| 2208 | break; |
| 2209 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2210 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2211 | result = 0; |
| 2212 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2213 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2214 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2215 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2216 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2217 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2218 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2219 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2220 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2221 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2222 | |
| 2223 | return result; |
| 2224 | } |
| 2225 | |
| 2226 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 2227 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2228 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2229 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2230 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2231 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2232 | } |
| 2233 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2234 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 2235 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2236 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2237 | struct net_device *dev = info->user_ptr[1]; |
| 2238 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2239 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2240 | |
| 2241 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2242 | return -EINVAL; |
| 2243 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2244 | if (netif_running(dev)) |
| 2245 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2246 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2247 | if (!rdev->ops->set_wds_peer) |
| 2248 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2249 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2250 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 2251 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2252 | |
| 2253 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2254 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2255 | } |
| 2256 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2257 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2258 | { |
| 2259 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2260 | struct net_device *netdev = NULL; |
| 2261 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2262 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2263 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2264 | u32 changed; |
| 2265 | u8 retry_short = 0, retry_long = 0; |
| 2266 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2267 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2268 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2269 | ASSERT_RTNL(); |
| 2270 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2271 | /* |
| 2272 | * Try to find the wiphy and netdev. Normally this |
| 2273 | * function shouldn't need the netdev, but this is |
| 2274 | * done for backward compatibility -- previously |
| 2275 | * setting the channel was done per wiphy, but now |
| 2276 | * it is per netdev. Previous userland like hostapd |
| 2277 | * also passed a netdev to set_wiphy, so that it is |
| 2278 | * possible to let that go to the right netdev! |
| 2279 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2280 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2281 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2282 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2283 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2284 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2285 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2286 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2287 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2288 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2289 | } |
| 2290 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2291 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2292 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2293 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2294 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2295 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2296 | wdev = NULL; |
| 2297 | netdev = NULL; |
| 2298 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2299 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2300 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2301 | |
| 2302 | /* |
| 2303 | * end workaround code, by now the rdev is available |
| 2304 | * and locked, and wdev may or may not be NULL. |
| 2305 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2306 | |
| 2307 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2308 | result = cfg80211_dev_rename( |
| 2309 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2310 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2311 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2312 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2313 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2314 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2315 | struct ieee80211_txq_params txq_params; |
| 2316 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2317 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2318 | if (!rdev->ops->set_txq_params) |
| 2319 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2320 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2321 | if (!netdev) |
| 2322 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2323 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2324 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2325 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2326 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2327 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2328 | if (!netif_running(netdev)) |
| 2329 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2330 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2331 | nla_for_each_nested(nl_txq_params, |
| 2332 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2333 | rem_txq_params) { |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 2334 | result = nla_parse_nested(tb, NL80211_TXQ_ATTR_MAX, |
| 2335 | nl_txq_params, |
| 2336 | txq_params_policy); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2337 | if (result) |
| 2338 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2339 | result = parse_txq_params(tb, &txq_params); |
| 2340 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2341 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2342 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2343 | result = rdev_set_txq_params(rdev, netdev, |
| 2344 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2345 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2346 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2347 | } |
| 2348 | } |
| 2349 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2350 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2351 | result = __nl80211_set_channel( |
| 2352 | rdev, |
| 2353 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 2354 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2355 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2356 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2357 | } |
| 2358 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2359 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2360 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2361 | enum nl80211_tx_power_setting type; |
| 2362 | int idx, mbm = 0; |
| 2363 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2364 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2365 | txp_wdev = NULL; |
| 2366 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2367 | if (!rdev->ops->set_tx_power) |
| 2368 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2369 | |
| 2370 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2371 | type = nla_get_u32(info->attrs[idx]); |
| 2372 | |
| 2373 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2374 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2375 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2376 | |
| 2377 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2378 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2379 | mbm = nla_get_u32(info->attrs[idx]); |
| 2380 | } |
| 2381 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2382 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2383 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2384 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2385 | } |
| 2386 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2387 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2388 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2389 | u32 tx_ant, rx_ant; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 2390 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2391 | if ((!rdev->wiphy.available_antennas_tx && |
| 2392 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2393 | !rdev->ops->set_antenna) |
| 2394 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2395 | |
| 2396 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2397 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2398 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2399 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2400 | * available antenna masks, except for the "all" mask */ |
| 2401 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2402 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2403 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2404 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2405 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2406 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2407 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2408 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2409 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2410 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2411 | } |
| 2412 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2413 | changed = 0; |
| 2414 | |
| 2415 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2416 | retry_short = nla_get_u8( |
| 2417 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2418 | if (retry_short == 0) |
| 2419 | return -EINVAL; |
| 2420 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2421 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2422 | } |
| 2423 | |
| 2424 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2425 | retry_long = nla_get_u8( |
| 2426 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2427 | if (retry_long == 0) |
| 2428 | return -EINVAL; |
| 2429 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2430 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2431 | } |
| 2432 | |
| 2433 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2434 | frag_threshold = nla_get_u32( |
| 2435 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2436 | if (frag_threshold < 256) |
| 2437 | return -EINVAL; |
| 2438 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2439 | if (frag_threshold != (u32) -1) { |
| 2440 | /* |
| 2441 | * Fragments (apart from the last one) are required to |
| 2442 | * have even length. Make the fragmentation code |
| 2443 | * simpler by stripping LSB should someone try to use |
| 2444 | * odd threshold value. |
| 2445 | */ |
| 2446 | frag_threshold &= ~0x1; |
| 2447 | } |
| 2448 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2449 | } |
| 2450 | |
| 2451 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2452 | rts_threshold = nla_get_u32( |
| 2453 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2454 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2455 | } |
| 2456 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2457 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2458 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 2459 | return -EINVAL; |
| 2460 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2461 | coverage_class = nla_get_u8( |
| 2462 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2463 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2464 | } |
| 2465 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2466 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 2467 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 2468 | return -EOPNOTSUPP; |
| 2469 | |
| 2470 | changed |= WIPHY_PARAM_DYN_ACK; |
| 2471 | } |
| 2472 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2473 | if (changed) { |
| 2474 | u8 old_retry_short, old_retry_long; |
| 2475 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2476 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2477 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2478 | if (!rdev->ops->set_wiphy_params) |
| 2479 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2480 | |
| 2481 | old_retry_short = rdev->wiphy.retry_short; |
| 2482 | old_retry_long = rdev->wiphy.retry_long; |
| 2483 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2484 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2485 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2486 | |
| 2487 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2488 | rdev->wiphy.retry_short = retry_short; |
| 2489 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2490 | rdev->wiphy.retry_long = retry_long; |
| 2491 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2492 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2493 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2494 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2495 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2496 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2497 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2498 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2499 | if (result) { |
| 2500 | rdev->wiphy.retry_short = old_retry_short; |
| 2501 | rdev->wiphy.retry_long = old_retry_long; |
| 2502 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2503 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2504 | rdev->wiphy.coverage_class = old_coverage_class; |
Michal Kazior | 9189ee3 | 2015-08-03 10:55:24 +0200 | [diff] [blame] | 2505 | return result; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2506 | } |
| 2507 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2508 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2509 | } |
| 2510 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2511 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2512 | { |
| 2513 | return (u64)wdev->identifier | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2514 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2515 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2516 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2517 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2518 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2519 | { |
Johannes Berg | 601555c | 2014-11-27 17:26:56 +0100 | [diff] [blame] | 2520 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 2521 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2522 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2523 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2524 | chandef->chan->center_freq)) |
| 2525 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2526 | switch (chandef->width) { |
| 2527 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2528 | case NL80211_CHAN_WIDTH_20: |
| 2529 | case NL80211_CHAN_WIDTH_40: |
| 2530 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2531 | cfg80211_get_chandef_type(chandef))) |
| 2532 | return -ENOBUFS; |
| 2533 | break; |
| 2534 | default: |
| 2535 | break; |
| 2536 | } |
| 2537 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2538 | return -ENOBUFS; |
| 2539 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2540 | return -ENOBUFS; |
| 2541 | if (chandef->center_freq2 && |
| 2542 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2543 | return -ENOBUFS; |
| 2544 | return 0; |
| 2545 | } |
| 2546 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2547 | 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] | 2548 | struct cfg80211_registered_device *rdev, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2549 | struct wireless_dev *wdev, bool removal) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2550 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2551 | struct net_device *dev = wdev->netdev; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2552 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2553 | void *hdr; |
| 2554 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2555 | if (removal) |
| 2556 | cmd = NL80211_CMD_DEL_INTERFACE; |
| 2557 | |
| 2558 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2559 | if (!hdr) |
| 2560 | return -1; |
| 2561 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2562 | if (dev && |
| 2563 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2564 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2565 | goto nla_put_failure; |
| 2566 | |
| 2567 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2568 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 2569 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 2570 | NL80211_ATTR_PAD) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2571 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2572 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2573 | rdev->devlist_generation ^ |
| 2574 | (cfg80211_rdev_list_generation << 2))) |
| 2575 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2576 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2577 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2578 | int ret; |
| 2579 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2580 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2581 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2582 | if (ret == 0) { |
| 2583 | if (nl80211_send_chandef(msg, &chandef)) |
| 2584 | goto nla_put_failure; |
| 2585 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2586 | } |
| 2587 | |
Rafał Miłecki | d55d0d5 | 2015-08-31 22:59:38 +0200 | [diff] [blame] | 2588 | if (rdev->ops->get_tx_power) { |
| 2589 | int dbm, ret; |
| 2590 | |
| 2591 | ret = rdev_get_tx_power(rdev, wdev, &dbm); |
| 2592 | if (ret == 0 && |
| 2593 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, |
| 2594 | DBM_TO_MBM(dbm))) |
| 2595 | goto nla_put_failure; |
| 2596 | } |
| 2597 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2598 | if (wdev->ssid_len) { |
| 2599 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2600 | goto nla_put_failure; |
| 2601 | } |
| 2602 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 2603 | genlmsg_end(msg, hdr); |
| 2604 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2605 | |
| 2606 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2607 | genlmsg_cancel(msg, hdr); |
| 2608 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2609 | } |
| 2610 | |
| 2611 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2612 | { |
| 2613 | int wp_idx = 0; |
| 2614 | int if_idx = 0; |
| 2615 | int wp_start = cb->args[0]; |
| 2616 | int if_start = cb->args[1]; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2617 | int filter_wiphy = -1; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2618 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2619 | struct wireless_dev *wdev; |
| 2620 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2621 | rtnl_lock(); |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2622 | if (!cb->args[2]) { |
| 2623 | struct nl80211_dump_wiphy_state state = { |
| 2624 | .filter_wiphy = -1, |
| 2625 | }; |
| 2626 | int ret; |
| 2627 | |
| 2628 | ret = nl80211_dump_wiphy_parse(skb, cb, &state); |
| 2629 | if (ret) |
| 2630 | return ret; |
| 2631 | |
| 2632 | filter_wiphy = state.filter_wiphy; |
| 2633 | |
| 2634 | /* |
| 2635 | * if filtering, set cb->args[2] to +1 since 0 is the default |
| 2636 | * value needed to determine that parsing is necessary. |
| 2637 | */ |
| 2638 | if (filter_wiphy >= 0) |
| 2639 | cb->args[2] = filter_wiphy + 1; |
| 2640 | else |
| 2641 | cb->args[2] = -1; |
| 2642 | } else if (cb->args[2] > 0) { |
| 2643 | filter_wiphy = cb->args[2] - 1; |
| 2644 | } |
| 2645 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2646 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2647 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2648 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2649 | if (wp_idx < wp_start) { |
| 2650 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2651 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2652 | } |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 2653 | |
| 2654 | if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) |
| 2655 | continue; |
| 2656 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2657 | if_idx = 0; |
| 2658 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 2659 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2660 | if (if_idx < if_start) { |
| 2661 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2662 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2663 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2664 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2665 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2666 | rdev, wdev, false) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2667 | goto out; |
| 2668 | } |
| 2669 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2670 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2671 | |
| 2672 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2673 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2674 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2675 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2676 | |
| 2677 | cb->args[0] = wp_idx; |
| 2678 | cb->args[1] = if_idx; |
| 2679 | |
| 2680 | return skb->len; |
| 2681 | } |
| 2682 | |
| 2683 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2684 | { |
| 2685 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2686 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2687 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2688 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2689 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2690 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2691 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2692 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2693 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2694 | rdev, wdev, false) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2695 | nlmsg_free(msg); |
| 2696 | return -ENOBUFS; |
| 2697 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2698 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2699 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2700 | } |
| 2701 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2702 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2703 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2704 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2705 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2706 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2707 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2708 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2709 | }; |
| 2710 | |
| 2711 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2712 | { |
| 2713 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2714 | int flag; |
| 2715 | |
| 2716 | *mntrflags = 0; |
| 2717 | |
| 2718 | if (!nla) |
| 2719 | return -EINVAL; |
| 2720 | |
| 2721 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2722 | nla, mntr_flags_policy)) |
| 2723 | return -EINVAL; |
| 2724 | |
| 2725 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2726 | if (flags[flag]) |
| 2727 | *mntrflags |= (1<<flag); |
| 2728 | |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 2729 | *mntrflags |= MONITOR_FLAG_CHANGED; |
| 2730 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2731 | return 0; |
| 2732 | } |
| 2733 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 2734 | static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev, |
| 2735 | enum nl80211_iftype type, |
| 2736 | struct genl_info *info, |
| 2737 | struct vif_params *params) |
| 2738 | { |
| 2739 | bool change = false; |
| 2740 | int err; |
| 2741 | |
| 2742 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
| 2743 | if (type != NL80211_IFTYPE_MONITOR) |
| 2744 | return -EINVAL; |
| 2745 | |
| 2746 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2747 | ¶ms->flags); |
| 2748 | if (err) |
| 2749 | return err; |
| 2750 | |
| 2751 | change = true; |
| 2752 | } |
| 2753 | |
| 2754 | if (params->flags & MONITOR_FLAG_ACTIVE && |
| 2755 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2756 | return -EOPNOTSUPP; |
| 2757 | |
| 2758 | if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { |
| 2759 | const u8 *mumimo_groups; |
| 2760 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 2761 | |
| 2762 | if (type != NL80211_IFTYPE_MONITOR) |
| 2763 | return -EINVAL; |
| 2764 | |
| 2765 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 2766 | return -EOPNOTSUPP; |
| 2767 | |
| 2768 | mumimo_groups = |
| 2769 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); |
| 2770 | |
| 2771 | /* bits 0 and 63 are reserved and must be zero */ |
| 2772 | if ((mumimo_groups[0] & BIT(7)) || |
| 2773 | (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(0))) |
| 2774 | return -EINVAL; |
| 2775 | |
| 2776 | params->vht_mumimo_groups = mumimo_groups; |
| 2777 | change = true; |
| 2778 | } |
| 2779 | |
| 2780 | if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { |
| 2781 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 2782 | |
| 2783 | if (type != NL80211_IFTYPE_MONITOR) |
| 2784 | return -EINVAL; |
| 2785 | |
| 2786 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 2787 | return -EOPNOTSUPP; |
| 2788 | |
| 2789 | params->vht_mumimo_follow_addr = |
| 2790 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]); |
| 2791 | change = true; |
| 2792 | } |
| 2793 | |
| 2794 | return change ? 1 : 0; |
| 2795 | } |
| 2796 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2797 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2798 | struct net_device *netdev, u8 use_4addr, |
| 2799 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2800 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2801 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2802 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2803 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2804 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2805 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2806 | |
| 2807 | switch (iftype) { |
| 2808 | case NL80211_IFTYPE_AP_VLAN: |
| 2809 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2810 | return 0; |
| 2811 | break; |
| 2812 | case NL80211_IFTYPE_STATION: |
| 2813 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2814 | return 0; |
| 2815 | break; |
| 2816 | default: |
| 2817 | break; |
| 2818 | } |
| 2819 | |
| 2820 | return -EOPNOTSUPP; |
| 2821 | } |
| 2822 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2823 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2824 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2825 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2826 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2827 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2828 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2829 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2830 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2831 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2832 | memset(¶ms, 0, sizeof(params)); |
| 2833 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2834 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2835 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2836 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2837 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2838 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2839 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2840 | if (ntype > NL80211_IFTYPE_MAX) |
| 2841 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2842 | } |
| 2843 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2844 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2845 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2846 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2847 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2848 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2849 | if (netif_running(dev)) |
| 2850 | return -EBUSY; |
| 2851 | |
| 2852 | wdev_lock(wdev); |
| 2853 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2854 | IEEE80211_MAX_MESH_ID_LEN); |
| 2855 | wdev->mesh_id_up_len = |
| 2856 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2857 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2858 | wdev->mesh_id_up_len); |
| 2859 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2860 | } |
| 2861 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2862 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2863 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2864 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2865 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2866 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2867 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2868 | } else { |
| 2869 | params.use_4addr = -1; |
| 2870 | } |
| 2871 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 2872 | err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms); |
| 2873 | if (err < 0) |
| 2874 | return err; |
| 2875 | if (err > 0) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2876 | change = true; |
Aviya Erenfeld | c6e6a0c | 2016-07-05 15:23:08 +0300 | [diff] [blame] | 2877 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2878 | if (change) |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 2879 | err = cfg80211_change_iface(rdev, dev, ntype, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2880 | else |
| 2881 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2882 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2883 | if (!err && params.use_4addr != -1) |
| 2884 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2885 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2886 | return err; |
| 2887 | } |
| 2888 | |
| 2889 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2890 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2891 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2892 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2893 | struct wireless_dev *wdev; |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 2894 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2895 | int err; |
| 2896 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
| 2897 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2898 | /* to avoid failing a new interface creation due to pending removal */ |
| 2899 | cfg80211_destroy_ifaces(rdev); |
| 2900 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2901 | memset(¶ms, 0, sizeof(params)); |
| 2902 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2903 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2904 | return -EINVAL; |
| 2905 | |
| 2906 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2907 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2908 | if (type > NL80211_IFTYPE_MAX) |
| 2909 | return -EINVAL; |
| 2910 | } |
| 2911 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2912 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2913 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2914 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2915 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 2916 | if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || |
Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 2917 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 2918 | info->attrs[NL80211_ATTR_MAC]) { |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2919 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2920 | ETH_ALEN); |
| 2921 | if (!is_valid_ether_addr(params.macaddr)) |
| 2922 | return -EADDRNOTAVAIL; |
| 2923 | } |
| 2924 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2925 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2926 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2927 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2928 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2929 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2930 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2931 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 2932 | err = nl80211_parse_mon_options(rdev, type, info, ¶ms); |
| 2933 | if (err < 0) |
| 2934 | return err; |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2935 | |
Johannes Berg | a18c719 | 2015-02-24 10:56:42 +0100 | [diff] [blame] | 2936 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2937 | if (!msg) |
| 2938 | return -ENOMEM; |
| 2939 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2940 | wdev = rdev_add_virtual_intf(rdev, |
| 2941 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 2942 | NET_NAME_USER, type, ¶ms); |
Rafał Miłecki | d687cbb | 2014-11-14 18:43:28 +0100 | [diff] [blame] | 2943 | if (WARN_ON(!wdev)) { |
| 2944 | nlmsg_free(msg); |
| 2945 | return -EPROTO; |
| 2946 | } else if (IS_ERR(wdev)) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2947 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2948 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2949 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2950 | |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 2951 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2952 | wdev->owner_nlportid = info->snd_portid; |
| 2953 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2954 | switch (type) { |
| 2955 | case NL80211_IFTYPE_MESH_POINT: |
| 2956 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2957 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2958 | wdev_lock(wdev); |
| 2959 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2960 | IEEE80211_MAX_MESH_ID_LEN); |
| 2961 | wdev->mesh_id_up_len = |
| 2962 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2963 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2964 | wdev->mesh_id_up_len); |
| 2965 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2966 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 2967 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2968 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2969 | /* |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 2970 | * 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] | 2971 | * through the netdev notifier and must be added here |
| 2972 | */ |
| 2973 | mutex_init(&wdev->mtx); |
| 2974 | INIT_LIST_HEAD(&wdev->event_list); |
| 2975 | spin_lock_init(&wdev->event_lock); |
| 2976 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2977 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2978 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2979 | wdev->identifier = ++rdev->wdev_id; |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 2980 | list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2981 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2982 | break; |
| 2983 | default: |
| 2984 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2985 | } |
| 2986 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2987 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2988 | rdev, wdev, false) < 0) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2989 | nlmsg_free(msg); |
| 2990 | return -ENOBUFS; |
| 2991 | } |
| 2992 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 2993 | /* |
| 2994 | * For wdevs which have no associated netdev object (e.g. of type |
| 2995 | * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here. |
| 2996 | * For all other types, the event will be generated from the |
| 2997 | * netdev notifier |
| 2998 | */ |
| 2999 | if (!wdev->netdev) |
| 3000 | nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE); |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 3001 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 3002 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3003 | } |
| 3004 | |
| 3005 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 3006 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3007 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3008 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3009 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3010 | if (!rdev->ops->del_virtual_intf) |
| 3011 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3012 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3013 | /* |
| 3014 | * If we remove a wireless device without a netdev then clear |
| 3015 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 3016 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 3017 | * since the wdev has been freed, unlike with a netdev where |
| 3018 | * we need the dev_put() for the netdev to really be freed. |
| 3019 | */ |
| 3020 | if (!wdev->netdev) |
| 3021 | info->user_ptr[1] = NULL; |
| 3022 | |
Denis Kenzior | 7f8ed01 | 2016-08-03 16:58:35 -0500 | [diff] [blame] | 3023 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3024 | } |
| 3025 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 3026 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 3027 | { |
| 3028 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3029 | struct net_device *dev = info->user_ptr[1]; |
| 3030 | u16 noack_map; |
| 3031 | |
| 3032 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 3033 | return -EINVAL; |
| 3034 | |
| 3035 | if (!rdev->ops->set_noack_map) |
| 3036 | return -EOPNOTSUPP; |
| 3037 | |
| 3038 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 3039 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3040 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 3041 | } |
| 3042 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3043 | struct get_key_cookie { |
| 3044 | struct sk_buff *msg; |
| 3045 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3046 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3047 | }; |
| 3048 | |
| 3049 | static void get_key_callback(void *c, struct key_params *params) |
| 3050 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3051 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3052 | struct get_key_cookie *cookie = c; |
| 3053 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3054 | if ((params->key && |
| 3055 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 3056 | params->key_len, params->key)) || |
| 3057 | (params->seq && |
| 3058 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 3059 | params->seq_len, params->seq)) || |
| 3060 | (params->cipher && |
| 3061 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 3062 | params->cipher))) |
| 3063 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3064 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3065 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 3066 | if (!key) |
| 3067 | goto nla_put_failure; |
| 3068 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3069 | if ((params->key && |
| 3070 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 3071 | params->key_len, params->key)) || |
| 3072 | (params->seq && |
| 3073 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 3074 | params->seq_len, params->seq)) || |
| 3075 | (params->cipher && |
| 3076 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 3077 | params->cipher))) |
| 3078 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3079 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3080 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 3081 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3082 | |
| 3083 | nla_nest_end(cookie->msg, key); |
| 3084 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3085 | return; |
| 3086 | nla_put_failure: |
| 3087 | cookie->error = 1; |
| 3088 | } |
| 3089 | |
| 3090 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 3091 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3092 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3093 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3094 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3095 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3096 | const u8 *mac_addr = NULL; |
| 3097 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3098 | struct get_key_cookie cookie = { |
| 3099 | .error = 0, |
| 3100 | }; |
| 3101 | void *hdr; |
| 3102 | struct sk_buff *msg; |
| 3103 | |
| 3104 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 3105 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 3106 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 3107 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3108 | return -EINVAL; |
| 3109 | |
| 3110 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3111 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3112 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3113 | pairwise = !!mac_addr; |
| 3114 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 3115 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 3116 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3117 | if (kt >= NUM_NL80211_KEYTYPES) |
| 3118 | return -EINVAL; |
| 3119 | if (kt != NL80211_KEYTYPE_GROUP && |
| 3120 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 3121 | return -EINVAL; |
| 3122 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 3123 | } |
| 3124 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3125 | if (!rdev->ops->get_key) |
| 3126 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3127 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3128 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3129 | return -ENOENT; |
| 3130 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3131 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3132 | if (!msg) |
| 3133 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3134 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3135 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3136 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 3137 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 3138 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3139 | |
| 3140 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3141 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3142 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3143 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3144 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 3145 | goto nla_put_failure; |
| 3146 | if (mac_addr && |
| 3147 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 3148 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3149 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3150 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 3151 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3152 | |
| 3153 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3154 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3155 | |
| 3156 | if (cookie.error) |
| 3157 | goto nla_put_failure; |
| 3158 | |
| 3159 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3160 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3161 | |
| 3162 | nla_put_failure: |
| 3163 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3164 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3165 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3166 | return err; |
| 3167 | } |
| 3168 | |
| 3169 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 3170 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3171 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3172 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3173 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3174 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3175 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3176 | err = nl80211_parse_key(info, &key); |
| 3177 | if (err) |
| 3178 | return err; |
| 3179 | |
| 3180 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3181 | return -EINVAL; |
| 3182 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3183 | /* only support setting default key */ |
| 3184 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3185 | return -EINVAL; |
| 3186 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3187 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3188 | |
| 3189 | if (key.def) { |
| 3190 | if (!rdev->ops->set_default_key) { |
| 3191 | err = -EOPNOTSUPP; |
| 3192 | goto out; |
| 3193 | } |
| 3194 | |
| 3195 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3196 | if (err) |
| 3197 | goto out; |
| 3198 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3199 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3200 | key.def_uni, key.def_multi); |
| 3201 | |
| 3202 | if (err) |
| 3203 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3204 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3205 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3206 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3207 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3208 | } else { |
| 3209 | if (key.def_uni || !key.def_multi) { |
| 3210 | err = -EINVAL; |
| 3211 | goto out; |
| 3212 | } |
| 3213 | |
| 3214 | if (!rdev->ops->set_default_mgmt_key) { |
| 3215 | err = -EOPNOTSUPP; |
| 3216 | goto out; |
| 3217 | } |
| 3218 | |
| 3219 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3220 | if (err) |
| 3221 | goto out; |
| 3222 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3223 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 3224 | if (err) |
| 3225 | goto out; |
| 3226 | |
| 3227 | #ifdef CONFIG_CFG80211_WEXT |
| 3228 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 3229 | #endif |
| 3230 | } |
| 3231 | |
| 3232 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3233 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3234 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3235 | return err; |
| 3236 | } |
| 3237 | |
| 3238 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 3239 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3240 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3241 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3242 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3243 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3244 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3245 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3246 | err = nl80211_parse_key(info, &key); |
| 3247 | if (err) |
| 3248 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3249 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3250 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3251 | return -EINVAL; |
| 3252 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3253 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3254 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3255 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3256 | if (key.type == -1) { |
| 3257 | if (mac_addr) |
| 3258 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3259 | else |
| 3260 | key.type = NL80211_KEYTYPE_GROUP; |
| 3261 | } |
| 3262 | |
| 3263 | /* for now */ |
| 3264 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3265 | key.type != NL80211_KEYTYPE_GROUP) |
| 3266 | return -EINVAL; |
| 3267 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3268 | if (!rdev->ops->add_key) |
| 3269 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3270 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3271 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 3272 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3273 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3274 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3275 | |
| 3276 | wdev_lock(dev->ieee80211_ptr); |
| 3277 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3278 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3279 | err = rdev_add_key(rdev, dev, key.idx, |
| 3280 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3281 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3282 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3283 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3284 | return err; |
| 3285 | } |
| 3286 | |
| 3287 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 3288 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3289 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3290 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3291 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3292 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3293 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3294 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3295 | err = nl80211_parse_key(info, &key); |
| 3296 | if (err) |
| 3297 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3298 | |
| 3299 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3300 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3301 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3302 | if (key.type == -1) { |
| 3303 | if (mac_addr) |
| 3304 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3305 | else |
| 3306 | key.type = NL80211_KEYTYPE_GROUP; |
| 3307 | } |
| 3308 | |
| 3309 | /* for now */ |
| 3310 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3311 | key.type != NL80211_KEYTYPE_GROUP) |
| 3312 | return -EINVAL; |
| 3313 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3314 | if (!rdev->ops->del_key) |
| 3315 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3316 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3317 | wdev_lock(dev->ieee80211_ptr); |
| 3318 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3319 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3320 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3321 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3322 | err = -ENOENT; |
| 3323 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3324 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3325 | err = rdev_del_key(rdev, dev, key.idx, |
| 3326 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3327 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3328 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3329 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3330 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3331 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3332 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3333 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3334 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 3335 | } |
| 3336 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3337 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3338 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3339 | return err; |
| 3340 | } |
| 3341 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3342 | /* This function returns an error or the number of nested attributes */ |
| 3343 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 3344 | { |
| 3345 | struct nlattr *attr; |
| 3346 | int n_entries = 0, tmp; |
| 3347 | |
| 3348 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 3349 | if (nla_len(attr) != ETH_ALEN) |
| 3350 | return -EINVAL; |
| 3351 | |
| 3352 | n_entries++; |
| 3353 | } |
| 3354 | |
| 3355 | return n_entries; |
| 3356 | } |
| 3357 | |
| 3358 | /* |
| 3359 | * This function parses ACL information and allocates memory for ACL data. |
| 3360 | * On successful return, the calling function is responsible to free the |
| 3361 | * ACL buffer returned by this function. |
| 3362 | */ |
| 3363 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 3364 | struct genl_info *info) |
| 3365 | { |
| 3366 | enum nl80211_acl_policy acl_policy; |
| 3367 | struct nlattr *attr; |
| 3368 | struct cfg80211_acl_data *acl; |
| 3369 | int i = 0, n_entries, tmp; |
| 3370 | |
| 3371 | if (!wiphy->max_acl_mac_addrs) |
| 3372 | return ERR_PTR(-EOPNOTSUPP); |
| 3373 | |
| 3374 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 3375 | return ERR_PTR(-EINVAL); |
| 3376 | |
| 3377 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 3378 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 3379 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 3380 | return ERR_PTR(-EINVAL); |
| 3381 | |
| 3382 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 3383 | return ERR_PTR(-EINVAL); |
| 3384 | |
| 3385 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 3386 | if (n_entries < 0) |
| 3387 | return ERR_PTR(n_entries); |
| 3388 | |
| 3389 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 3390 | return ERR_PTR(-ENOTSUPP); |
| 3391 | |
| 3392 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 3393 | GFP_KERNEL); |
| 3394 | if (!acl) |
| 3395 | return ERR_PTR(-ENOMEM); |
| 3396 | |
| 3397 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 3398 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3399 | i++; |
| 3400 | } |
| 3401 | |
| 3402 | acl->n_acl_entries = n_entries; |
| 3403 | acl->acl_policy = acl_policy; |
| 3404 | |
| 3405 | return acl; |
| 3406 | } |
| 3407 | |
| 3408 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3409 | { |
| 3410 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3411 | struct net_device *dev = info->user_ptr[1]; |
| 3412 | struct cfg80211_acl_data *acl; |
| 3413 | int err; |
| 3414 | |
| 3415 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3416 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3417 | return -EOPNOTSUPP; |
| 3418 | |
| 3419 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3420 | return -EINVAL; |
| 3421 | |
| 3422 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3423 | if (IS_ERR(acl)) |
| 3424 | return PTR_ERR(acl); |
| 3425 | |
| 3426 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3427 | |
| 3428 | kfree(acl); |
| 3429 | |
| 3430 | return err; |
| 3431 | } |
| 3432 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3433 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 3434 | u8 *rates, u8 rates_len) |
| 3435 | { |
| 3436 | u8 i; |
| 3437 | u32 mask = 0; |
| 3438 | |
| 3439 | for (i = 0; i < rates_len; i++) { |
| 3440 | int rate = (rates[i] & 0x7f) * 5; |
| 3441 | int ridx; |
| 3442 | |
| 3443 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 3444 | struct ieee80211_rate *srate = |
| 3445 | &sband->bitrates[ridx]; |
| 3446 | if (rate == srate->bitrate) { |
| 3447 | mask |= 1 << ridx; |
| 3448 | break; |
| 3449 | } |
| 3450 | } |
| 3451 | if (ridx == sband->n_bitrates) |
| 3452 | return 0; /* rate not found */ |
| 3453 | } |
| 3454 | |
| 3455 | return mask; |
| 3456 | } |
| 3457 | |
| 3458 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 3459 | u8 *rates, u8 rates_len, |
| 3460 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 3461 | { |
| 3462 | u8 i; |
| 3463 | |
| 3464 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 3465 | |
| 3466 | for (i = 0; i < rates_len; i++) { |
| 3467 | int ridx, rbit; |
| 3468 | |
| 3469 | ridx = rates[i] / 8; |
| 3470 | rbit = BIT(rates[i] % 8); |
| 3471 | |
| 3472 | /* check validity */ |
| 3473 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
| 3474 | return false; |
| 3475 | |
| 3476 | /* check availability */ |
| 3477 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 3478 | mcs[ridx] |= rbit; |
| 3479 | else |
| 3480 | return false; |
| 3481 | } |
| 3482 | |
| 3483 | return true; |
| 3484 | } |
| 3485 | |
| 3486 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 3487 | { |
| 3488 | u16 mcs_mask = 0; |
| 3489 | |
| 3490 | switch (vht_mcs_map) { |
| 3491 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 3492 | break; |
| 3493 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 3494 | mcs_mask = 0x00FF; |
| 3495 | break; |
| 3496 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 3497 | mcs_mask = 0x01FF; |
| 3498 | break; |
| 3499 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 3500 | mcs_mask = 0x03FF; |
| 3501 | break; |
| 3502 | default: |
| 3503 | break; |
| 3504 | } |
| 3505 | |
| 3506 | return mcs_mask; |
| 3507 | } |
| 3508 | |
| 3509 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 3510 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 3511 | { |
| 3512 | u8 nss; |
| 3513 | |
| 3514 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 3515 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 3516 | vht_mcs_map >>= 2; |
| 3517 | } |
| 3518 | } |
| 3519 | |
| 3520 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 3521 | struct nl80211_txrate_vht *txrate, |
| 3522 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 3523 | { |
| 3524 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 3525 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 3526 | u8 i; |
| 3527 | |
| 3528 | if (!sband->vht_cap.vht_supported) |
| 3529 | return false; |
| 3530 | |
| 3531 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 3532 | |
| 3533 | /* Build vht_mcs_mask from VHT capabilities */ |
| 3534 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 3535 | |
| 3536 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 3537 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 3538 | mcs[i] = txrate->mcs[i]; |
| 3539 | else |
| 3540 | return false; |
| 3541 | } |
| 3542 | |
| 3543 | return true; |
| 3544 | } |
| 3545 | |
| 3546 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
| 3547 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 3548 | .len = NL80211_MAX_SUPP_RATES }, |
| 3549 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 3550 | .len = NL80211_MAX_SUPP_HT_RATES }, |
| 3551 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
| 3552 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
| 3553 | }; |
| 3554 | |
| 3555 | static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, |
| 3556 | struct cfg80211_bitrate_mask *mask) |
| 3557 | { |
| 3558 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
| 3559 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3560 | int rem, i; |
| 3561 | struct nlattr *tx_rates; |
| 3562 | struct ieee80211_supported_band *sband; |
| 3563 | u16 vht_tx_mcs_map; |
| 3564 | |
| 3565 | memset(mask, 0, sizeof(*mask)); |
| 3566 | /* Default to all rates enabled */ |
| 3567 | for (i = 0; i < NUM_NL80211_BANDS; i++) { |
| 3568 | sband = rdev->wiphy.bands[i]; |
| 3569 | |
| 3570 | if (!sband) |
| 3571 | continue; |
| 3572 | |
| 3573 | mask->control[i].legacy = (1 << sband->n_bitrates) - 1; |
| 3574 | memcpy(mask->control[i].ht_mcs, |
| 3575 | sband->ht_cap.mcs.rx_mask, |
| 3576 | sizeof(mask->control[i].ht_mcs)); |
| 3577 | |
| 3578 | if (!sband->vht_cap.vht_supported) |
| 3579 | continue; |
| 3580 | |
| 3581 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 3582 | vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); |
| 3583 | } |
| 3584 | |
| 3585 | /* if no rates are given set it back to the defaults */ |
| 3586 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 3587 | goto out; |
| 3588 | |
| 3589 | /* The nested attribute uses enum nl80211_band as the index. This maps |
| 3590 | * directly to the enum nl80211_band values used in cfg80211. |
| 3591 | */ |
| 3592 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
| 3593 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
| 3594 | enum nl80211_band band = nla_type(tx_rates); |
| 3595 | int err; |
| 3596 | |
| 3597 | if (band < 0 || band >= NUM_NL80211_BANDS) |
| 3598 | return -EINVAL; |
| 3599 | sband = rdev->wiphy.bands[band]; |
| 3600 | if (sband == NULL) |
| 3601 | return -EINVAL; |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 3602 | err = nla_parse_nested(tb, NL80211_TXRATE_MAX, tx_rates, |
| 3603 | nl80211_txattr_policy); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3604 | if (err) |
| 3605 | return err; |
| 3606 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 3607 | mask->control[band].legacy = rateset_to_mask( |
| 3608 | sband, |
| 3609 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 3610 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
| 3611 | if ((mask->control[band].legacy == 0) && |
| 3612 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 3613 | return -EINVAL; |
| 3614 | } |
| 3615 | if (tb[NL80211_TXRATE_HT]) { |
| 3616 | if (!ht_rateset_to_mask( |
| 3617 | sband, |
| 3618 | nla_data(tb[NL80211_TXRATE_HT]), |
| 3619 | nla_len(tb[NL80211_TXRATE_HT]), |
| 3620 | mask->control[band].ht_mcs)) |
| 3621 | return -EINVAL; |
| 3622 | } |
| 3623 | if (tb[NL80211_TXRATE_VHT]) { |
| 3624 | if (!vht_set_mcs_mask( |
| 3625 | sband, |
| 3626 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 3627 | mask->control[band].vht_mcs)) |
| 3628 | return -EINVAL; |
| 3629 | } |
| 3630 | if (tb[NL80211_TXRATE_GI]) { |
| 3631 | mask->control[band].gi = |
| 3632 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 3633 | if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 3634 | return -EINVAL; |
| 3635 | } |
| 3636 | |
| 3637 | if (mask->control[band].legacy == 0) { |
| 3638 | /* don't allow empty legacy rates if HT or VHT |
| 3639 | * are not even supported. |
| 3640 | */ |
| 3641 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 3642 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
| 3643 | return -EINVAL; |
| 3644 | |
| 3645 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 3646 | if (mask->control[band].ht_mcs[i]) |
| 3647 | goto out; |
| 3648 | |
| 3649 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 3650 | if (mask->control[band].vht_mcs[i]) |
| 3651 | goto out; |
| 3652 | |
| 3653 | /* legacy and mcs rates may not be both empty */ |
| 3654 | return -EINVAL; |
| 3655 | } |
| 3656 | } |
| 3657 | |
| 3658 | out: |
| 3659 | return 0; |
| 3660 | } |
| 3661 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3662 | static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, |
| 3663 | enum nl80211_band band, |
| 3664 | struct cfg80211_bitrate_mask *beacon_rate) |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3665 | { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3666 | u32 count_ht, count_vht, i; |
| 3667 | u32 rate = beacon_rate->control[band].legacy; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3668 | |
| 3669 | /* Allow only one rate */ |
| 3670 | if (hweight32(rate) > 1) |
| 3671 | return -EINVAL; |
| 3672 | |
| 3673 | count_ht = 0; |
| 3674 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3675 | if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3676 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3677 | } else if (beacon_rate->control[band].ht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3678 | count_ht++; |
| 3679 | if (count_ht > 1) |
| 3680 | return -EINVAL; |
| 3681 | } |
| 3682 | if (count_ht && rate) |
| 3683 | return -EINVAL; |
| 3684 | } |
| 3685 | |
| 3686 | count_vht = 0; |
| 3687 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3688 | if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3689 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3690 | } else if (beacon_rate->control[band].vht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3691 | count_vht++; |
| 3692 | if (count_vht > 1) |
| 3693 | return -EINVAL; |
| 3694 | } |
| 3695 | if (count_vht && rate) |
| 3696 | return -EINVAL; |
| 3697 | } |
| 3698 | |
| 3699 | if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht)) |
| 3700 | return -EINVAL; |
| 3701 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 3702 | if (rate && |
| 3703 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 3704 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) |
| 3705 | return -EINVAL; |
| 3706 | if (count_ht && |
| 3707 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 3708 | NL80211_EXT_FEATURE_BEACON_RATE_HT)) |
| 3709 | return -EINVAL; |
| 3710 | if (count_vht && |
| 3711 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 3712 | NL80211_EXT_FEATURE_BEACON_RATE_VHT)) |
| 3713 | return -EINVAL; |
| 3714 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 3715 | return 0; |
| 3716 | } |
| 3717 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3718 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3719 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3720 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3721 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3722 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3723 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3724 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3725 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3726 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3727 | return -EINVAL; |
| 3728 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3729 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3730 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3731 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3732 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3733 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3734 | if (!bcn->head_len) |
| 3735 | return -EINVAL; |
| 3736 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3737 | } |
| 3738 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3739 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3740 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3741 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3742 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3743 | } |
| 3744 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3745 | if (!haveinfo) |
| 3746 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3747 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3748 | if (attrs[NL80211_ATTR_IE]) { |
| 3749 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3750 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3751 | } |
| 3752 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3753 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3754 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3755 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3756 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3757 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3758 | } |
| 3759 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3760 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3761 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3762 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3763 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3764 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3765 | } |
| 3766 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3767 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3768 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3769 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3770 | } |
| 3771 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3772 | return 0; |
| 3773 | } |
| 3774 | |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 3775 | static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params, |
| 3776 | const u8 *rates) |
| 3777 | { |
| 3778 | int i; |
| 3779 | |
| 3780 | if (!rates) |
| 3781 | return; |
| 3782 | |
| 3783 | for (i = 0; i < rates[1]; i++) { |
| 3784 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY) |
| 3785 | params->ht_required = true; |
| 3786 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY) |
| 3787 | params->vht_required = true; |
| 3788 | } |
| 3789 | } |
| 3790 | |
| 3791 | /* |
| 3792 | * Since the nl80211 API didn't include, from the beginning, attributes about |
| 3793 | * HT/VHT requirements/capabilities, we parse them out of the IEs for the |
| 3794 | * benefit of drivers that rebuild IEs in the firmware. |
| 3795 | */ |
| 3796 | static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params) |
| 3797 | { |
| 3798 | const struct cfg80211_beacon_data *bcn = ¶ms->beacon; |
| 3799 | size_t ies_len = bcn->beacon_ies_len; |
| 3800 | const u8 *ies = bcn->beacon_ies; |
| 3801 | const u8 *rates; |
| 3802 | const u8 *cap; |
| 3803 | |
| 3804 | rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len); |
| 3805 | nl80211_check_ap_rate_selectors(params, rates); |
| 3806 | |
| 3807 | rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len); |
| 3808 | nl80211_check_ap_rate_selectors(params, rates); |
| 3809 | |
| 3810 | cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len); |
| 3811 | if (cap && cap[1] >= sizeof(*params->ht_cap)) |
| 3812 | params->ht_cap = (void *)(cap + 2); |
| 3813 | cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len); |
| 3814 | if (cap && cap[1] >= sizeof(*params->vht_cap)) |
| 3815 | params->vht_cap = (void *)(cap + 2); |
| 3816 | } |
| 3817 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3818 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3819 | struct cfg80211_ap_settings *params) |
| 3820 | { |
| 3821 | struct wireless_dev *wdev; |
| 3822 | bool ret = false; |
| 3823 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 3824 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3825 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3826 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3827 | continue; |
| 3828 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3829 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3830 | continue; |
| 3831 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3832 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3833 | ret = true; |
| 3834 | break; |
| 3835 | } |
| 3836 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3837 | return ret; |
| 3838 | } |
| 3839 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3840 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3841 | enum nl80211_auth_type auth_type, |
| 3842 | enum nl80211_commands cmd) |
| 3843 | { |
| 3844 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3845 | return false; |
| 3846 | |
| 3847 | switch (cmd) { |
| 3848 | case NL80211_CMD_AUTHENTICATE: |
| 3849 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3850 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3851 | return false; |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 3852 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 3853 | NL80211_EXT_FEATURE_FILS_STA) && |
| 3854 | (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 3855 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 3856 | auth_type == NL80211_AUTHTYPE_FILS_PK)) |
| 3857 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3858 | return true; |
| 3859 | case NL80211_CMD_CONNECT: |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 3860 | /* SAE not supported yet */ |
| 3861 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3862 | return false; |
| 3863 | /* FILS with SK PFS or PK not supported yet */ |
| 3864 | if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 3865 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 3866 | return false; |
| 3867 | if (!wiphy_ext_feature_isset( |
| 3868 | &rdev->wiphy, |
| 3869 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 3870 | auth_type == NL80211_AUTHTYPE_FILS_SK) |
| 3871 | return false; |
| 3872 | return true; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3873 | case NL80211_CMD_START_AP: |
| 3874 | /* SAE not supported yet */ |
| 3875 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3876 | return false; |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 3877 | /* FILS not supported yet */ |
| 3878 | if (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 3879 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 3880 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 3881 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3882 | return true; |
| 3883 | default: |
| 3884 | return false; |
| 3885 | } |
| 3886 | } |
| 3887 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3888 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3889 | { |
| 3890 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3891 | struct net_device *dev = info->user_ptr[1]; |
| 3892 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3893 | struct cfg80211_ap_settings params; |
| 3894 | int err; |
| 3895 | |
| 3896 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3897 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3898 | return -EOPNOTSUPP; |
| 3899 | |
| 3900 | if (!rdev->ops->start_ap) |
| 3901 | return -EOPNOTSUPP; |
| 3902 | |
| 3903 | if (wdev->beacon_interval) |
| 3904 | return -EALREADY; |
| 3905 | |
| 3906 | memset(¶ms, 0, sizeof(params)); |
| 3907 | |
| 3908 | /* these are required for START_AP */ |
| 3909 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3910 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3911 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3912 | return -EINVAL; |
| 3913 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3914 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3915 | if (err) |
| 3916 | return err; |
| 3917 | |
| 3918 | params.beacon_interval = |
| 3919 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3920 | params.dtim_period = |
| 3921 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3922 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 3923 | err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype, |
| 3924 | params.beacon_interval); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3925 | if (err) |
| 3926 | return err; |
| 3927 | |
| 3928 | /* |
| 3929 | * In theory, some of these attributes should be required here |
| 3930 | * but since they were not used when the command was originally |
| 3931 | * added, keep them optional for old user space programs to let |
| 3932 | * them continue to work with drivers that do not need the |
| 3933 | * additional information -- drivers must check! |
| 3934 | */ |
| 3935 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3936 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3937 | params.ssid_len = |
| 3938 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3939 | if (params.ssid_len == 0 || |
| 3940 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3941 | return -EINVAL; |
| 3942 | } |
| 3943 | |
| 3944 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3945 | params.hidden_ssid = nla_get_u32( |
| 3946 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3947 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3948 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3949 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3950 | return -EINVAL; |
| 3951 | } |
| 3952 | |
| 3953 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3954 | |
| 3955 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3956 | params.auth_type = nla_get_u32( |
| 3957 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3958 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3959 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3960 | return -EINVAL; |
| 3961 | } else |
| 3962 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3963 | |
| 3964 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3965 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3966 | if (err) |
| 3967 | return err; |
| 3968 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3969 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3970 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3971 | return -EOPNOTSUPP; |
| 3972 | params.inactivity_timeout = nla_get_u16( |
| 3973 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3974 | } |
| 3975 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3976 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3977 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3978 | return -EINVAL; |
| 3979 | params.p2p_ctwindow = |
| 3980 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3981 | if (params.p2p_ctwindow > 127) |
| 3982 | return -EINVAL; |
| 3983 | if (params.p2p_ctwindow != 0 && |
| 3984 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3985 | return -EINVAL; |
| 3986 | } |
| 3987 | |
| 3988 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3989 | u8 tmp; |
| 3990 | |
| 3991 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3992 | return -EINVAL; |
| 3993 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3994 | if (tmp > 1) |
| 3995 | return -EINVAL; |
| 3996 | params.p2p_opp_ps = tmp; |
| 3997 | if (params.p2p_opp_ps != 0 && |
| 3998 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3999 | return -EINVAL; |
| 4000 | } |
| 4001 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 4002 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 4003 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 4004 | if (err) |
| 4005 | return err; |
| 4006 | } else if (wdev->preset_chandef.chan) { |
| 4007 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4008 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 4009 | return -EINVAL; |
| 4010 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 4011 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 4012 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 4013 | return -EINVAL; |
| 4014 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4015 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
| 4016 | err = nl80211_parse_tx_bitrate_mask(info, ¶ms.beacon_rate); |
| 4017 | if (err) |
| 4018 | return err; |
| 4019 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4020 | err = validate_beacon_tx_rate(rdev, params.chandef.chan->band, |
| 4021 | ¶ms.beacon_rate); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4022 | if (err) |
| 4023 | return err; |
| 4024 | } |
| 4025 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 4026 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 4027 | params.smps_mode = |
| 4028 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 4029 | switch (params.smps_mode) { |
| 4030 | case NL80211_SMPS_OFF: |
| 4031 | break; |
| 4032 | case NL80211_SMPS_STATIC: |
| 4033 | if (!(rdev->wiphy.features & |
| 4034 | NL80211_FEATURE_STATIC_SMPS)) |
| 4035 | return -EINVAL; |
| 4036 | break; |
| 4037 | case NL80211_SMPS_DYNAMIC: |
| 4038 | if (!(rdev->wiphy.features & |
| 4039 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 4040 | return -EINVAL; |
| 4041 | break; |
| 4042 | default: |
| 4043 | return -EINVAL; |
| 4044 | } |
| 4045 | } else { |
| 4046 | params.smps_mode = NL80211_SMPS_OFF; |
| 4047 | } |
| 4048 | |
Purushottam Kushwaha | 6e8ef84 | 2016-07-05 13:44:51 +0530 | [diff] [blame] | 4049 | params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
| 4050 | if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) |
| 4051 | return -EOPNOTSUPP; |
| 4052 | |
Ola Olsson | 4baf6be | 2015-10-29 07:04:58 +0100 | [diff] [blame] | 4053 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 4054 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 4055 | if (IS_ERR(params.acl)) |
| 4056 | return PTR_ERR(params.acl); |
| 4057 | } |
| 4058 | |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 4059 | nl80211_calculate_ap_params(¶ms); |
| 4060 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4061 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4062 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4063 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 4064 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4065 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 4066 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 4067 | wdev->ssid_len = params.ssid_len; |
| 4068 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4069 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4070 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 4071 | |
| 4072 | kfree(params.acl); |
| 4073 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 4074 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4075 | } |
| 4076 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4077 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 4078 | { |
| 4079 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4080 | struct net_device *dev = info->user_ptr[1]; |
| 4081 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4082 | struct cfg80211_beacon_data params; |
| 4083 | int err; |
| 4084 | |
| 4085 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4086 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4087 | return -EOPNOTSUPP; |
| 4088 | |
| 4089 | if (!rdev->ops->change_beacon) |
| 4090 | return -EOPNOTSUPP; |
| 4091 | |
| 4092 | if (!wdev->beacon_interval) |
| 4093 | return -EINVAL; |
| 4094 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4095 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4096 | if (err) |
| 4097 | return err; |
| 4098 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4099 | wdev_lock(wdev); |
| 4100 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 4101 | wdev_unlock(wdev); |
| 4102 | |
| 4103 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4104 | } |
| 4105 | |
| 4106 | 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] | 4107 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4108 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4109 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4110 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 4111 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4112 | } |
| 4113 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4114 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 4115 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 4116 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 4117 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 4118 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 4119 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 4120 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4121 | }; |
| 4122 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4123 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4124 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4125 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4126 | { |
| 4127 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4128 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4129 | int flag; |
| 4130 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4131 | /* |
| 4132 | * Try parsing the new attribute first so userspace |
| 4133 | * can specify both for older kernels. |
| 4134 | */ |
| 4135 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 4136 | if (nla) { |
| 4137 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4138 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4139 | sta_flags = nla_data(nla); |
| 4140 | params->sta_flags_mask = sta_flags->mask; |
| 4141 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4142 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4143 | if ((params->sta_flags_mask | |
| 4144 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 4145 | return -EINVAL; |
| 4146 | return 0; |
| 4147 | } |
| 4148 | |
| 4149 | /* if present, parse the old attribute */ |
| 4150 | |
| 4151 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4152 | if (!nla) |
| 4153 | return 0; |
| 4154 | |
| 4155 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 4156 | nla, sta_flags_policy)) |
| 4157 | return -EINVAL; |
| 4158 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4159 | /* |
| 4160 | * Only allow certain flags for interface types so that |
| 4161 | * other attributes are silently ignored. Remember that |
| 4162 | * this is backward compatibility code with old userspace |
| 4163 | * and shouldn't be hit in other cases anyway. |
| 4164 | */ |
| 4165 | switch (iftype) { |
| 4166 | case NL80211_IFTYPE_AP: |
| 4167 | case NL80211_IFTYPE_AP_VLAN: |
| 4168 | case NL80211_IFTYPE_P2P_GO: |
| 4169 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4170 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 4171 | BIT(NL80211_STA_FLAG_WME) | |
| 4172 | BIT(NL80211_STA_FLAG_MFP); |
| 4173 | break; |
| 4174 | case NL80211_IFTYPE_P2P_CLIENT: |
| 4175 | case NL80211_IFTYPE_STATION: |
| 4176 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4177 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4178 | break; |
| 4179 | case NL80211_IFTYPE_MESH_POINT: |
| 4180 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4181 | BIT(NL80211_STA_FLAG_MFP) | |
| 4182 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 4183 | default: |
| 4184 | return -EINVAL; |
| 4185 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4186 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 4187 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 4188 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 4189 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4190 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 4191 | /* no longer support new API additions in old API */ |
| 4192 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 4193 | return -EINVAL; |
| 4194 | } |
| 4195 | } |
| 4196 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4197 | return 0; |
| 4198 | } |
| 4199 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4200 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 4201 | int attr) |
| 4202 | { |
| 4203 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 4204 | u32 bitrate; |
| 4205 | u16 bitrate_compat; |
Matthias Kaehlcke | bbf67e4 | 2017-04-17 15:59:52 -0700 | [diff] [blame^] | 4206 | enum nl80211_rate_info rate_flg; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4207 | |
| 4208 | rate = nla_nest_start(msg, attr); |
| 4209 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4210 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4211 | |
| 4212 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 4213 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 4214 | /* report 16-bit bitrate only if we can */ |
| 4215 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4216 | if (bitrate > 0 && |
| 4217 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 4218 | return false; |
| 4219 | if (bitrate_compat > 0 && |
| 4220 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 4221 | return false; |
| 4222 | |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 4223 | switch (info->bw) { |
| 4224 | case RATE_INFO_BW_5: |
| 4225 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; |
| 4226 | break; |
| 4227 | case RATE_INFO_BW_10: |
| 4228 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; |
| 4229 | break; |
| 4230 | default: |
| 4231 | WARN_ON(1); |
| 4232 | /* fall through */ |
| 4233 | case RATE_INFO_BW_20: |
| 4234 | rate_flg = 0; |
| 4235 | break; |
| 4236 | case RATE_INFO_BW_40: |
| 4237 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; |
| 4238 | break; |
| 4239 | case RATE_INFO_BW_80: |
| 4240 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; |
| 4241 | break; |
| 4242 | case RATE_INFO_BW_160: |
| 4243 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; |
| 4244 | break; |
| 4245 | } |
| 4246 | |
| 4247 | if (rate_flg && nla_put_flag(msg, rate_flg)) |
| 4248 | return false; |
| 4249 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4250 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 4251 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 4252 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4253 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 4254 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 4255 | return false; |
| 4256 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 4257 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 4258 | return false; |
| 4259 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 4260 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 4261 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 4262 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 4263 | return false; |
| 4264 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4265 | |
| 4266 | nla_nest_end(msg, rate); |
| 4267 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4268 | } |
| 4269 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4270 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 4271 | int id) |
| 4272 | { |
| 4273 | void *attr; |
| 4274 | int i = 0; |
| 4275 | |
| 4276 | if (!mask) |
| 4277 | return true; |
| 4278 | |
| 4279 | attr = nla_nest_start(msg, id); |
| 4280 | if (!attr) |
| 4281 | return false; |
| 4282 | |
| 4283 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 4284 | if (!(mask & BIT(i))) |
| 4285 | continue; |
| 4286 | |
| 4287 | if (nla_put_u8(msg, i, signal[i])) |
| 4288 | return false; |
| 4289 | } |
| 4290 | |
| 4291 | nla_nest_end(msg, attr); |
| 4292 | |
| 4293 | return true; |
| 4294 | } |
| 4295 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4296 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
| 4297 | u32 seq, int flags, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4298 | struct cfg80211_registered_device *rdev, |
| 4299 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 4300 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4301 | { |
| 4302 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4303 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4304 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4305 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4306 | if (!hdr) |
| 4307 | return -1; |
| 4308 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4309 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4310 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 4311 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 4312 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4313 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4314 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 4315 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4316 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4317 | |
| 4318 | #define PUT_SINFO(attr, memb, type) do { \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4319 | BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ |
Mohammed Shafi Shajakhan | 739960f | 2016-04-07 19:59:34 +0530 | [diff] [blame] | 4320 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4321 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
| 4322 | sinfo->memb)) \ |
| 4323 | goto nla_put_failure; \ |
| 4324 | } while (0) |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4325 | #define PUT_SINFO_U64(attr, memb) do { \ |
| 4326 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ |
| 4327 | nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ |
| 4328 | sinfo->memb, NL80211_STA_INFO_PAD)) \ |
| 4329 | goto nla_put_failure; \ |
| 4330 | } while (0) |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4331 | |
| 4332 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); |
| 4333 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); |
| 4334 | |
| 4335 | if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) | |
| 4336 | BIT(NL80211_STA_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4337 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 4338 | (u32)sinfo->rx_bytes)) |
| 4339 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4340 | |
| 4341 | if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) | |
| 4342 | BIT(NL80211_STA_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 4343 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 4344 | (u32)sinfo->tx_bytes)) |
| 4345 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4346 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4347 | PUT_SINFO_U64(RX_BYTES64, rx_bytes); |
| 4348 | PUT_SINFO_U64(TX_BYTES64, tx_bytes); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4349 | PUT_SINFO(LLID, llid, u16); |
| 4350 | PUT_SINFO(PLID, plid, u16); |
| 4351 | PUT_SINFO(PLINK_STATE, plink_state, u8); |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4352 | PUT_SINFO_U64(RX_DURATION, rx_duration); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4353 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4354 | switch (rdev->wiphy.signal_type) { |
| 4355 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4356 | PUT_SINFO(SIGNAL, signal, u8); |
| 4357 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4358 | break; |
| 4359 | default: |
| 4360 | break; |
| 4361 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4362 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4363 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 4364 | sinfo->chain_signal, |
| 4365 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 4366 | goto nla_put_failure; |
| 4367 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4368 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 4369 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 4370 | sinfo->chain_signal_avg, |
| 4371 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 4372 | goto nla_put_failure; |
| 4373 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4374 | if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4375 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 4376 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 4377 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4378 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4379 | if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 4380 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 4381 | NL80211_STA_INFO_RX_BITRATE)) |
| 4382 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 4383 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4384 | |
| 4385 | PUT_SINFO(RX_PACKETS, rx_packets, u32); |
| 4386 | PUT_SINFO(TX_PACKETS, tx_packets, u32); |
| 4387 | PUT_SINFO(TX_RETRIES, tx_retries, u32); |
| 4388 | PUT_SINFO(TX_FAILED, tx_failed, u32); |
| 4389 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); |
| 4390 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); |
| 4391 | PUT_SINFO(LOCAL_PM, local_pm, u32); |
| 4392 | PUT_SINFO(PEER_PM, peer_pm, u32); |
| 4393 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); |
| 4394 | |
| 4395 | if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) { |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4396 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 4397 | if (!bss_param) |
| 4398 | goto nla_put_failure; |
| 4399 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4400 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 4401 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 4402 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 4403 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 4404 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 4405 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 4406 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 4407 | sinfo->bss_param.dtim_period) || |
| 4408 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 4409 | sinfo->bss_param.beacon_interval)) |
| 4410 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 4411 | |
| 4412 | nla_nest_end(msg, bss_param); |
| 4413 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4414 | if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4415 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 4416 | sizeof(struct nl80211_sta_flag_update), |
| 4417 | &sinfo->sta_flags)) |
| 4418 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4419 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4420 | PUT_SINFO_U64(T_OFFSET, t_offset); |
| 4421 | PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); |
| 4422 | PUT_SINFO_U64(BEACON_RX, rx_beacon); |
Johannes Berg | a76b194 | 2014-11-17 14:12:22 +0100 | [diff] [blame] | 4423 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4424 | |
| 4425 | #undef PUT_SINFO |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4426 | #undef PUT_SINFO_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4427 | |
| 4428 | if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) { |
| 4429 | struct nlattr *tidsattr; |
| 4430 | int tid; |
| 4431 | |
| 4432 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); |
| 4433 | if (!tidsattr) |
| 4434 | goto nla_put_failure; |
| 4435 | |
| 4436 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { |
| 4437 | struct cfg80211_tid_stats *tidstats; |
| 4438 | struct nlattr *tidattr; |
| 4439 | |
| 4440 | tidstats = &sinfo->pertid[tid]; |
| 4441 | |
| 4442 | if (!tidstats->filled) |
| 4443 | continue; |
| 4444 | |
| 4445 | tidattr = nla_nest_start(msg, tid + 1); |
| 4446 | if (!tidattr) |
| 4447 | goto nla_put_failure; |
| 4448 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4449 | #define PUT_TIDVAL_U64(attr, memb) do { \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4450 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4451 | nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ |
| 4452 | tidstats->memb, NL80211_TID_STATS_PAD)) \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4453 | goto nla_put_failure; \ |
| 4454 | } while (0) |
| 4455 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4456 | PUT_TIDVAL_U64(RX_MSDU, rx_msdu); |
| 4457 | PUT_TIDVAL_U64(TX_MSDU, tx_msdu); |
| 4458 | PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); |
| 4459 | PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4460 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 4461 | #undef PUT_TIDVAL_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 4462 | nla_nest_end(msg, tidattr); |
| 4463 | } |
| 4464 | |
| 4465 | nla_nest_end(msg, tidsattr); |
| 4466 | } |
| 4467 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4468 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4469 | |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 4470 | if (sinfo->assoc_req_ies_len && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4471 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 4472 | sinfo->assoc_req_ies)) |
| 4473 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 4474 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 4475 | genlmsg_end(msg, hdr); |
| 4476 | return 0; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4477 | |
| 4478 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4479 | genlmsg_cancel(msg, hdr); |
| 4480 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4481 | } |
| 4482 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4483 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4484 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4485 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4486 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4487 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4488 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4489 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4490 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4491 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4492 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4493 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4494 | if (err) |
| 4495 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4496 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4497 | if (!wdev->netdev) { |
| 4498 | err = -EINVAL; |
| 4499 | goto out_err; |
| 4500 | } |
| 4501 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4502 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4503 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4504 | goto out_err; |
| 4505 | } |
| 4506 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4507 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 4508 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4509 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4510 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4511 | if (err == -ENOENT) |
| 4512 | break; |
| 4513 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4514 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4515 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4516 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4517 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4518 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4519 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4520 | &sinfo) < 0) |
| 4521 | goto out; |
| 4522 | |
| 4523 | sta_idx++; |
| 4524 | } |
| 4525 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4526 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4527 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4528 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4529 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4530 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4531 | |
| 4532 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4533 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4534 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4535 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 4536 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4537 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4538 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4539 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4540 | struct sk_buff *msg; |
| 4541 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4542 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4543 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4544 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4545 | |
| 4546 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4547 | return -EINVAL; |
| 4548 | |
| 4549 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4550 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4551 | if (!rdev->ops->get_station) |
| 4552 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4553 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4554 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4555 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4556 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4557 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4558 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4559 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4560 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4561 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 4562 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
| 4563 | info->snd_portid, info->snd_seq, 0, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 4564 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4565 | nlmsg_free(msg); |
| 4566 | return -ENOBUFS; |
| 4567 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 4568 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4569 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4570 | } |
| 4571 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4572 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 4573 | struct station_parameters *params, |
| 4574 | enum cfg80211_station_type statype) |
| 4575 | { |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4576 | if (params->listen_interval != -1 && |
| 4577 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4578 | return -EINVAL; |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4579 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4580 | if (params->support_p2p_ps != -1 && |
| 4581 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
| 4582 | return -EINVAL; |
| 4583 | |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 4584 | if (params->aid && |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4585 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 4586 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4587 | return -EINVAL; |
| 4588 | |
| 4589 | /* When you run into this, adjust the code below for the new flag */ |
| 4590 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4591 | |
| 4592 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4593 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 4594 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4595 | /* |
| 4596 | * No ignoring the TDLS flag here -- the userspace mesh |
| 4597 | * code doesn't have the bug of including TDLS in the |
| 4598 | * mask everywhere. |
| 4599 | */ |
| 4600 | if (params->sta_flags_mask & |
| 4601 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4602 | BIT(NL80211_STA_FLAG_MFP) | |
| 4603 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4604 | return -EINVAL; |
| 4605 | break; |
| 4606 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4607 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4608 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4609 | return -EINVAL; |
| 4610 | /* ignore since it can't change */ |
| 4611 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4612 | break; |
| 4613 | default: |
| 4614 | /* disallow mesh-specific things */ |
| 4615 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 4616 | return -EINVAL; |
| 4617 | if (params->local_pm) |
| 4618 | return -EINVAL; |
| 4619 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4620 | return -EINVAL; |
| 4621 | } |
| 4622 | |
| 4623 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4624 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 4625 | /* TDLS can't be set, ... */ |
| 4626 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 4627 | return -EINVAL; |
| 4628 | /* |
| 4629 | * ... but don't bother the driver with it. This works around |
| 4630 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 4631 | * TLDS_PEER flag in the mask even for AP mode. |
| 4632 | */ |
| 4633 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 4634 | } |
| 4635 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4636 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 4637 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4638 | /* reject other things that can't change */ |
| 4639 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 4640 | return -EINVAL; |
| 4641 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 4642 | return -EINVAL; |
| 4643 | if (params->supported_rates) |
| 4644 | return -EINVAL; |
| 4645 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 4646 | return -EINVAL; |
| 4647 | } |
| 4648 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4649 | if (statype != CFG80211_STA_AP_CLIENT && |
| 4650 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4651 | if (params->vlan) |
| 4652 | return -EINVAL; |
| 4653 | } |
| 4654 | |
| 4655 | switch (statype) { |
| 4656 | case CFG80211_STA_AP_MLME_CLIENT: |
| 4657 | /* Use this only for authorizing/unauthorizing a station */ |
| 4658 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 4659 | return -EOPNOTSUPP; |
| 4660 | break; |
| 4661 | case CFG80211_STA_AP_CLIENT: |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 4662 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4663 | /* accept only the listed bits */ |
| 4664 | if (params->sta_flags_mask & |
| 4665 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4666 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4667 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4668 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 4669 | BIT(NL80211_STA_FLAG_WME) | |
| 4670 | BIT(NL80211_STA_FLAG_MFP))) |
| 4671 | return -EINVAL; |
| 4672 | |
| 4673 | /* but authenticated/associated only if driver handles it */ |
| 4674 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4675 | params->sta_flags_mask & |
| 4676 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4677 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4678 | return -EINVAL; |
| 4679 | break; |
| 4680 | case CFG80211_STA_IBSS: |
| 4681 | case CFG80211_STA_AP_STA: |
| 4682 | /* reject any changes other than AUTHORIZED */ |
| 4683 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 4684 | return -EINVAL; |
| 4685 | break; |
| 4686 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4687 | /* reject any changes other than AUTHORIZED or WME */ |
| 4688 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4689 | BIT(NL80211_STA_FLAG_WME))) |
| 4690 | return -EINVAL; |
| 4691 | /* force (at least) rates when authorizing */ |
| 4692 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 4693 | !params->supported_rates) |
| 4694 | return -EINVAL; |
| 4695 | break; |
| 4696 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4697 | /* reject any changes */ |
| 4698 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4699 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4700 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4701 | return -EINVAL; |
| 4702 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4703 | case CFG80211_STA_MESH_PEER_USER: |
Chun-Yeow Yeoh | 4292504 | 2015-04-18 01:30:02 +0800 | [diff] [blame] | 4704 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
| 4705 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4706 | return -EINVAL; |
| 4707 | break; |
| 4708 | } |
| 4709 | |
Beni Lev | 06f7c88 | 2016-07-19 19:28:56 +0300 | [diff] [blame] | 4710 | /* |
| 4711 | * Older kernel versions ignored this attribute entirely, so don't |
| 4712 | * reject attempts to update it but mark it as unused instead so the |
| 4713 | * driver won't look at the data. |
| 4714 | */ |
| 4715 | if (statype != CFG80211_STA_AP_CLIENT_UNASSOC && |
| 4716 | statype != CFG80211_STA_TDLS_PEER_SETUP) |
| 4717 | params->opmode_notif_used = false; |
| 4718 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4719 | return 0; |
| 4720 | } |
| 4721 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 4722 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4723 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 4724 | * 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] | 4725 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4726 | static struct net_device *get_vlan(struct genl_info *info, |
| 4727 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4728 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4729 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4730 | struct net_device *v; |
| 4731 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4732 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4733 | if (!vlanattr) |
| 4734 | return NULL; |
| 4735 | |
| 4736 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 4737 | if (!v) |
| 4738 | return ERR_PTR(-ENODEV); |
| 4739 | |
| 4740 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 4741 | ret = -EINVAL; |
| 4742 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4743 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4744 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4745 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 4746 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4747 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 4748 | ret = -EINVAL; |
| 4749 | goto error; |
| 4750 | } |
| 4751 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4752 | if (!netif_running(v)) { |
| 4753 | ret = -ENETDOWN; |
| 4754 | goto error; |
| 4755 | } |
| 4756 | |
| 4757 | return v; |
| 4758 | error: |
| 4759 | dev_put(v); |
| 4760 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4761 | } |
| 4762 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 4763 | static const struct nla_policy |
| 4764 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4765 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 4766 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 4767 | }; |
| 4768 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4769 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 4770 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4771 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4772 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 4773 | struct nlattr *nla; |
| 4774 | int err; |
| 4775 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4776 | /* parse WME attributes if present */ |
| 4777 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 4778 | return 0; |
| 4779 | |
| 4780 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 4781 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 4782 | nl80211_sta_wme_policy); |
| 4783 | if (err) |
| 4784 | return err; |
| 4785 | |
| 4786 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 4787 | params->uapsd_queues = nla_get_u8( |
| 4788 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 4789 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 4790 | return -EINVAL; |
| 4791 | |
| 4792 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 4793 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 4794 | |
| 4795 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 4796 | return -EINVAL; |
| 4797 | |
| 4798 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 4799 | |
| 4800 | return 0; |
| 4801 | } |
| 4802 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4803 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 4804 | struct station_parameters *params) |
| 4805 | { |
| 4806 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 4807 | params->supported_channels = |
| 4808 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4809 | params->supported_channels_len = |
| 4810 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4811 | /* |
| 4812 | * Need to include at least one (first channel, number of |
| 4813 | * channels) tuple for each subband, and must have proper |
| 4814 | * tuples for the rest of the data as well. |
| 4815 | */ |
| 4816 | if (params->supported_channels_len < 2) |
| 4817 | return -EINVAL; |
| 4818 | if (params->supported_channels_len % 2) |
| 4819 | return -EINVAL; |
| 4820 | } |
| 4821 | |
| 4822 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 4823 | params->supported_oper_classes = |
| 4824 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4825 | params->supported_oper_classes_len = |
| 4826 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4827 | /* |
| 4828 | * The value of the Length field of the Supported Operating |
| 4829 | * Classes element is between 2 and 253. |
| 4830 | */ |
| 4831 | if (params->supported_oper_classes_len < 2 || |
| 4832 | params->supported_oper_classes_len > 253) |
| 4833 | return -EINVAL; |
| 4834 | } |
| 4835 | return 0; |
| 4836 | } |
| 4837 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4838 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4839 | struct station_parameters *params) |
| 4840 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4841 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4842 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4843 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4844 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4845 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4846 | params->ht_capa = |
| 4847 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4848 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4849 | params->vht_capa = |
| 4850 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4851 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4852 | err = nl80211_parse_sta_channel_info(info, params); |
| 4853 | if (err) |
| 4854 | return err; |
| 4855 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4856 | return nl80211_parse_sta_wme(info, params); |
| 4857 | } |
| 4858 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4859 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4860 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4861 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4862 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4863 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4864 | u8 *mac_addr; |
| 4865 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4866 | |
| 4867 | memset(¶ms, 0, sizeof(params)); |
| 4868 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4869 | if (!rdev->ops->change_station) |
| 4870 | return -EOPNOTSUPP; |
| 4871 | |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4872 | /* |
| 4873 | * AID and listen_interval properties can be set only for unassociated |
| 4874 | * station. Include these parameters here and will check them in |
| 4875 | * cfg80211_check_station_change(). |
| 4876 | */ |
Ayala Beker | a9bc31e | 2015-11-26 16:26:12 +0100 | [diff] [blame] | 4877 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4878 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 4879 | |
| 4880 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4881 | params.listen_interval = |
| 4882 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 4883 | else |
| 4884 | params.listen_interval = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4885 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 4886 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
| 4887 | u8 tmp; |
| 4888 | |
| 4889 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 4890 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) |
| 4891 | return -EINVAL; |
| 4892 | |
| 4893 | params.support_p2p_ps = tmp; |
| 4894 | } else { |
| 4895 | params.support_p2p_ps = -1; |
| 4896 | } |
| 4897 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4898 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4899 | return -EINVAL; |
| 4900 | |
| 4901 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4902 | |
| 4903 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4904 | params.supported_rates = |
| 4905 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4906 | params.supported_rates_len = |
| 4907 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4908 | } |
| 4909 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4910 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4911 | params.capability = |
| 4912 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4913 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4914 | } |
| 4915 | |
| 4916 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4917 | params.ext_capab = |
| 4918 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4919 | params.ext_capab_len = |
| 4920 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4921 | } |
| 4922 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4923 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4924 | return -EINVAL; |
| 4925 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4926 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4927 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4928 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4929 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4930 | return -EINVAL; |
| 4931 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4932 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4933 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4934 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4935 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4936 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4937 | return -EINVAL; |
Masashi Honma | 7d27a0b | 2016-07-01 10:19:34 +0900 | [diff] [blame] | 4938 | if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) { |
| 4939 | params.peer_aid = nla_get_u16( |
| 4940 | info->attrs[NL80211_ATTR_MESH_PEER_AID]); |
| 4941 | if (params.peer_aid > IEEE80211_MAX_AID) |
| 4942 | return -EINVAL; |
| 4943 | } |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4944 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4945 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4946 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4947 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4948 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4949 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4950 | |
| 4951 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4952 | pm > NL80211_MESH_POWER_MAX) |
| 4953 | return -EINVAL; |
| 4954 | |
| 4955 | params.local_pm = pm; |
| 4956 | } |
| 4957 | |
Beni Lev | 06f7c88 | 2016-07-19 19:28:56 +0300 | [diff] [blame] | 4958 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4959 | params.opmode_notif_used = true; |
| 4960 | params.opmode_notif = |
| 4961 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4962 | } |
| 4963 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4964 | /* Include parameters for TDLS peer (will check later) */ |
| 4965 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4966 | if (err) |
| 4967 | return err; |
| 4968 | |
| 4969 | params.vlan = get_vlan(info, rdev); |
| 4970 | if (IS_ERR(params.vlan)) |
| 4971 | return PTR_ERR(params.vlan); |
| 4972 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4973 | switch (dev->ieee80211_ptr->iftype) { |
| 4974 | case NL80211_IFTYPE_AP: |
| 4975 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4976 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4977 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4978 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4979 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4980 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4981 | break; |
| 4982 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4983 | err = -EOPNOTSUPP; |
| 4984 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4985 | } |
| 4986 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4987 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4988 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4989 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4990 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4991 | if (params.vlan) |
| 4992 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4993 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4994 | return err; |
| 4995 | } |
| 4996 | |
| 4997 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4998 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4999 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5000 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5001 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5002 | struct station_parameters params; |
| 5003 | u8 *mac_addr = NULL; |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 5004 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5005 | BIT(NL80211_STA_FLAG_ASSOCIATED); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5006 | |
| 5007 | memset(¶ms, 0, sizeof(params)); |
| 5008 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5009 | if (!rdev->ops->add_station) |
| 5010 | return -EOPNOTSUPP; |
| 5011 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5012 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5013 | return -EINVAL; |
| 5014 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5015 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 5016 | return -EINVAL; |
| 5017 | |
| 5018 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 5019 | return -EINVAL; |
| 5020 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 5021 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 5022 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 5023 | return -EINVAL; |
| 5024 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5025 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5026 | params.supported_rates = |
| 5027 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 5028 | params.supported_rates_len = |
| 5029 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 5030 | params.listen_interval = |
| 5031 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 5032 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 5033 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
| 5034 | u8 tmp; |
| 5035 | |
| 5036 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 5037 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) |
| 5038 | return -EINVAL; |
| 5039 | |
| 5040 | params.support_p2p_ps = tmp; |
| 5041 | } else { |
| 5042 | /* |
| 5043 | * if not specified, assume it's supported for P2P GO interface, |
| 5044 | * and is NOT supported for AP interface |
| 5045 | */ |
| 5046 | params.support_p2p_ps = |
| 5047 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; |
| 5048 | } |
| 5049 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5050 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 5051 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5052 | else |
| 5053 | 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] | 5054 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 5055 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 5056 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 5057 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 5058 | params.capability = |
| 5059 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 5060 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 5061 | } |
| 5062 | |
| 5063 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 5064 | params.ext_capab = |
| 5065 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 5066 | params.ext_capab_len = |
| 5067 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 5068 | } |
| 5069 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 5070 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 5071 | params.ht_capa = |
| 5072 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5073 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 5074 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 5075 | params.vht_capa = |
| 5076 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 5077 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 5078 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 5079 | params.opmode_notif_used = true; |
| 5080 | params.opmode_notif = |
| 5081 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 5082 | } |
| 5083 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5084 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 5085 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5086 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 5087 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 5088 | return -EINVAL; |
| 5089 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 5090 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 5091 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 5092 | if (err) |
| 5093 | return err; |
| 5094 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5095 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 5096 | if (err) |
| 5097 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5098 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5099 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5100 | return -EINVAL; |
| 5101 | |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 5102 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
| 5103 | * as userspace might just pass through the capabilities from the IEs |
| 5104 | * directly, rather than enforcing this restriction and returning an |
| 5105 | * error in this case. |
| 5106 | */ |
| 5107 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { |
| 5108 | params.ht_capa = NULL; |
| 5109 | params.vht_capa = NULL; |
| 5110 | } |
| 5111 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5112 | /* When you run into this, adjust the code below for the new flag */ |
| 5113 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 5114 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5115 | switch (dev->ieee80211_ptr->iftype) { |
| 5116 | case NL80211_IFTYPE_AP: |
| 5117 | case NL80211_IFTYPE_AP_VLAN: |
| 5118 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5119 | /* ignore WME attributes if iface/sta is not capable */ |
| 5120 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 5121 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 5122 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 5123 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5124 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5125 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 5126 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 5127 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5128 | /* but don't bother the driver with it */ |
| 5129 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 5130 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5131 | /* allow authenticated/associated only if driver handles it */ |
| 5132 | if (!(rdev->wiphy.features & |
| 5133 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 5134 | params.sta_flags_mask & auth_assoc) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5135 | return -EINVAL; |
| 5136 | |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 5137 | /* Older userspace, or userspace wanting to be compatible with |
| 5138 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth |
| 5139 | * and assoc flags in the mask, but assumes the station will be |
| 5140 | * added as associated anyway since this was the required driver |
| 5141 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was |
| 5142 | * introduced. |
| 5143 | * In order to not bother drivers with this quirk in the API |
| 5144 | * set the flags in both the mask and set for new stations in |
| 5145 | * this case. |
| 5146 | */ |
| 5147 | if (!(params.sta_flags_mask & auth_assoc)) { |
| 5148 | params.sta_flags_mask |= auth_assoc; |
| 5149 | params.sta_flags_set |= auth_assoc; |
| 5150 | } |
| 5151 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5152 | /* must be last in here for error handling */ |
| 5153 | params.vlan = get_vlan(info, rdev); |
| 5154 | if (IS_ERR(params.vlan)) |
| 5155 | return PTR_ERR(params.vlan); |
| 5156 | break; |
| 5157 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5158 | /* ignore uAPSD data */ |
| 5159 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 5160 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5161 | /* associated is disallowed */ |
| 5162 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 5163 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5164 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 5165 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 5166 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 5167 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5168 | break; |
| 5169 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 5170 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 5171 | /* ignore uAPSD data */ |
| 5172 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 5173 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5174 | /* these are disallowed */ |
| 5175 | if (params.sta_flags_mask & |
| 5176 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 5177 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 5178 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5179 | /* Only TDLS peers can be added */ |
| 5180 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 5181 | return -EINVAL; |
| 5182 | /* Can only add if TDLS ... */ |
| 5183 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 5184 | return -EOPNOTSUPP; |
| 5185 | /* ... with external setup is supported */ |
| 5186 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 5187 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5188 | /* |
| 5189 | * Older wpa_supplicant versions always mark the TDLS peer |
| 5190 | * as authorized, but it shouldn't yet be. |
| 5191 | */ |
| 5192 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5193 | break; |
| 5194 | default: |
| 5195 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 5196 | } |
| 5197 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 5198 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5199 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5200 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5201 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5202 | if (params.vlan) |
| 5203 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5204 | return err; |
| 5205 | } |
| 5206 | |
| 5207 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 5208 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5209 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5210 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5211 | struct station_del_parameters params; |
| 5212 | |
| 5213 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5214 | |
| 5215 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5216 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5217 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 5218 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 5219 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5220 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5221 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5222 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 5223 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5224 | if (!rdev->ops->del_station) |
| 5225 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5226 | |
Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 5227 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 5228 | params.subtype = |
| 5229 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 5230 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 5231 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 5232 | return -EINVAL; |
| 5233 | } else { |
| 5234 | /* Default to Deauthentication frame */ |
| 5235 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 5236 | } |
| 5237 | |
| 5238 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 5239 | params.reason_code = |
| 5240 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 5241 | if (params.reason_code == 0) |
| 5242 | return -EINVAL; /* 0 is reserved */ |
| 5243 | } else { |
| 5244 | /* Default to reason code 2 */ |
| 5245 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 5246 | } |
| 5247 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 5248 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5249 | } |
| 5250 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5251 | 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] | 5252 | int flags, struct net_device *dev, |
| 5253 | u8 *dst, u8 *next_hop, |
| 5254 | struct mpath_info *pinfo) |
| 5255 | { |
| 5256 | void *hdr; |
| 5257 | struct nlattr *pinfoattr; |
| 5258 | |
Henning Rogge | 1ef4c85 | 2014-11-04 16:14:58 +0100 | [diff] [blame] | 5259 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5260 | if (!hdr) |
| 5261 | return -1; |
| 5262 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5263 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5264 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 5265 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 5266 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 5267 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 5268 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5269 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 5270 | if (!pinfoattr) |
| 5271 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5272 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 5273 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 5274 | pinfo->frame_qlen)) |
| 5275 | goto nla_put_failure; |
| 5276 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 5277 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 5278 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 5279 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 5280 | pinfo->metric)) || |
| 5281 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 5282 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 5283 | pinfo->exptime)) || |
| 5284 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 5285 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 5286 | pinfo->flags)) || |
| 5287 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 5288 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 5289 | pinfo->discovery_timeout)) || |
| 5290 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 5291 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 5292 | pinfo->discovery_retries))) |
| 5293 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5294 | |
| 5295 | nla_nest_end(msg, pinfoattr); |
| 5296 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 5297 | genlmsg_end(msg, hdr); |
| 5298 | return 0; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5299 | |
| 5300 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 5301 | genlmsg_cancel(msg, hdr); |
| 5302 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5303 | } |
| 5304 | |
| 5305 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5306 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5307 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5308 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5309 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5310 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5311 | u8 dst[ETH_ALEN]; |
| 5312 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5313 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5314 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5315 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5316 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5317 | if (err) |
| 5318 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5319 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5320 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5321 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5322 | goto out_err; |
| 5323 | } |
| 5324 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5325 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5326 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 5327 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5328 | } |
| 5329 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5330 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5331 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5332 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5333 | if (err == -ENOENT) |
| 5334 | break; |
| 5335 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5336 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5337 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5338 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5339 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5340 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5341 | &pinfo) < 0) |
| 5342 | goto out; |
| 5343 | |
| 5344 | path_idx++; |
| 5345 | } |
| 5346 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5347 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5348 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5349 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5350 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5351 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5352 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5353 | } |
| 5354 | |
| 5355 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5356 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5357 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5358 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5359 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5360 | struct mpath_info pinfo; |
| 5361 | struct sk_buff *msg; |
| 5362 | u8 *dst = NULL; |
| 5363 | u8 next_hop[ETH_ALEN]; |
| 5364 | |
| 5365 | memset(&pinfo, 0, sizeof(pinfo)); |
| 5366 | |
| 5367 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5368 | return -EINVAL; |
| 5369 | |
| 5370 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5371 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5372 | if (!rdev->ops->get_mpath) |
| 5373 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5374 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5375 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5376 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5377 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5378 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5379 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5380 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5381 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5382 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5383 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5384 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5385 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5386 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5387 | dev, dst, next_hop, &pinfo) < 0) { |
| 5388 | nlmsg_free(msg); |
| 5389 | return -ENOBUFS; |
| 5390 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5391 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5392 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5393 | } |
| 5394 | |
| 5395 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5396 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5397 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5398 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5399 | u8 *dst = NULL; |
| 5400 | u8 *next_hop = NULL; |
| 5401 | |
| 5402 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5403 | return -EINVAL; |
| 5404 | |
| 5405 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 5406 | return -EINVAL; |
| 5407 | |
| 5408 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5409 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 5410 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5411 | if (!rdev->ops->change_mpath) |
| 5412 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5413 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5414 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5415 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5416 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5417 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5418 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5419 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5420 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5421 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5422 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5423 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5424 | u8 *dst = NULL; |
| 5425 | u8 *next_hop = NULL; |
| 5426 | |
| 5427 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5428 | return -EINVAL; |
| 5429 | |
| 5430 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 5431 | return -EINVAL; |
| 5432 | |
| 5433 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5434 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 5435 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5436 | if (!rdev->ops->add_mpath) |
| 5437 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5438 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5439 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5440 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5441 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5442 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5443 | } |
| 5444 | |
| 5445 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 5446 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5447 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5448 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5449 | u8 *dst = NULL; |
| 5450 | |
| 5451 | if (info->attrs[NL80211_ATTR_MAC]) |
| 5452 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5453 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5454 | if (!rdev->ops->del_mpath) |
| 5455 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5456 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5457 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5458 | } |
| 5459 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 5460 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 5461 | { |
| 5462 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5463 | int err; |
| 5464 | struct net_device *dev = info->user_ptr[1]; |
| 5465 | struct mpath_info pinfo; |
| 5466 | struct sk_buff *msg; |
| 5467 | u8 *dst = NULL; |
| 5468 | u8 mpp[ETH_ALEN]; |
| 5469 | |
| 5470 | memset(&pinfo, 0, sizeof(pinfo)); |
| 5471 | |
| 5472 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5473 | return -EINVAL; |
| 5474 | |
| 5475 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5476 | |
| 5477 | if (!rdev->ops->get_mpp) |
| 5478 | return -EOPNOTSUPP; |
| 5479 | |
| 5480 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5481 | return -EOPNOTSUPP; |
| 5482 | |
| 5483 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 5484 | if (err) |
| 5485 | return err; |
| 5486 | |
| 5487 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5488 | if (!msg) |
| 5489 | return -ENOMEM; |
| 5490 | |
| 5491 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 5492 | dev, dst, mpp, &pinfo) < 0) { |
| 5493 | nlmsg_free(msg); |
| 5494 | return -ENOBUFS; |
| 5495 | } |
| 5496 | |
| 5497 | return genlmsg_reply(msg, info); |
| 5498 | } |
| 5499 | |
| 5500 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 5501 | struct netlink_callback *cb) |
| 5502 | { |
| 5503 | struct mpath_info pinfo; |
| 5504 | struct cfg80211_registered_device *rdev; |
| 5505 | struct wireless_dev *wdev; |
| 5506 | u8 dst[ETH_ALEN]; |
| 5507 | u8 mpp[ETH_ALEN]; |
| 5508 | int path_idx = cb->args[2]; |
| 5509 | int err; |
| 5510 | |
| 5511 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
| 5512 | if (err) |
| 5513 | return err; |
| 5514 | |
| 5515 | if (!rdev->ops->dump_mpp) { |
| 5516 | err = -EOPNOTSUPP; |
| 5517 | goto out_err; |
| 5518 | } |
| 5519 | |
| 5520 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 5521 | err = -EOPNOTSUPP; |
| 5522 | goto out_err; |
| 5523 | } |
| 5524 | |
| 5525 | while (1) { |
| 5526 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 5527 | mpp, &pinfo); |
| 5528 | if (err == -ENOENT) |
| 5529 | break; |
| 5530 | if (err) |
| 5531 | goto out_err; |
| 5532 | |
| 5533 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 5534 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 5535 | wdev->netdev, dst, mpp, |
| 5536 | &pinfo) < 0) |
| 5537 | goto out; |
| 5538 | |
| 5539 | path_idx++; |
| 5540 | } |
| 5541 | |
| 5542 | out: |
| 5543 | cb->args[2] = path_idx; |
| 5544 | err = skb->len; |
| 5545 | out_err: |
| 5546 | nl80211_finish_wdev_dump(rdev); |
| 5547 | return err; |
| 5548 | } |
| 5549 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5550 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 5551 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5552 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5553 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5554 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5555 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5556 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5557 | |
| 5558 | memset(¶ms, 0, sizeof(params)); |
| 5559 | /* default to not changing parameters */ |
| 5560 | params.use_cts_prot = -1; |
| 5561 | params.use_short_preamble = -1; |
| 5562 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 5563 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 5564 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5565 | params.p2p_ctwindow = -1; |
| 5566 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5567 | |
| 5568 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 5569 | params.use_cts_prot = |
| 5570 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 5571 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 5572 | params.use_short_preamble = |
| 5573 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 5574 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 5575 | params.use_short_slot_time = |
| 5576 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 5577 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 5578 | params.basic_rates = |
| 5579 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5580 | params.basic_rates_len = |
| 5581 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 5582 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 5583 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 5584 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 5585 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 5586 | params.ht_opmode = |
| 5587 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5588 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5589 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 5590 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5591 | return -EINVAL; |
| 5592 | params.p2p_ctwindow = |
| 5593 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 5594 | if (params.p2p_ctwindow < 0) |
| 5595 | return -EINVAL; |
| 5596 | if (params.p2p_ctwindow != 0 && |
| 5597 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 5598 | return -EINVAL; |
| 5599 | } |
| 5600 | |
| 5601 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 5602 | u8 tmp; |
| 5603 | |
| 5604 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5605 | return -EINVAL; |
| 5606 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 5607 | if (tmp > 1) |
| 5608 | return -EINVAL; |
| 5609 | params.p2p_opp_ps = tmp; |
| 5610 | if (params.p2p_opp_ps && |
| 5611 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 5612 | return -EINVAL; |
| 5613 | } |
| 5614 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5615 | if (!rdev->ops->change_bss) |
| 5616 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5617 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 5618 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5619 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5620 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5621 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5622 | wdev_lock(wdev); |
| 5623 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 5624 | wdev_unlock(wdev); |
| 5625 | |
| 5626 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 5627 | } |
| 5628 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5629 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5630 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5631 | char *data = NULL; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5632 | bool is_indoor; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5633 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5634 | u32 owner_nlportid; |
| 5635 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 5636 | /* |
| 5637 | * You should only get this when cfg80211 hasn't yet initialized |
| 5638 | * completely when built-in to the kernel right between the time |
| 5639 | * window between nl80211_init() and regulatory_init(), if that is |
| 5640 | * even possible. |
| 5641 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5642 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 5643 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 5644 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5645 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 5646 | user_reg_hint_type = |
| 5647 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 5648 | else |
| 5649 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 5650 | |
| 5651 | switch (user_reg_hint_type) { |
| 5652 | case NL80211_USER_REG_HINT_USER: |
| 5653 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 5654 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5655 | return -EINVAL; |
| 5656 | |
| 5657 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5658 | return regulatory_hint_user(data, user_reg_hint_type); |
| 5659 | case NL80211_USER_REG_HINT_INDOOR: |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 5660 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 5661 | owner_nlportid = info->snd_portid; |
| 5662 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; |
| 5663 | } else { |
| 5664 | owner_nlportid = 0; |
| 5665 | is_indoor = true; |
| 5666 | } |
| 5667 | |
| 5668 | return regulatory_hint_indoor(is_indoor, owner_nlportid); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5669 | default: |
| 5670 | return -EINVAL; |
| 5671 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5672 | } |
| 5673 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5674 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5675 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5676 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5677 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5678 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5679 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5680 | struct mesh_config cur_params; |
| 5681 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5682 | void *hdr; |
| 5683 | struct nlattr *pinfoattr; |
| 5684 | struct sk_buff *msg; |
| 5685 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5686 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5687 | return -EOPNOTSUPP; |
| 5688 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5689 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5690 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 5691 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5692 | wdev_lock(wdev); |
| 5693 | /* If not connected, get default parameters */ |
| 5694 | if (!wdev->mesh_id_len) |
| 5695 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 5696 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5697 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5698 | wdev_unlock(wdev); |
| 5699 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5700 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5701 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5702 | |
| 5703 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5704 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5705 | if (!msg) |
| 5706 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5707 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5708 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5709 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5710 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5711 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5712 | if (!pinfoattr) |
| 5713 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5714 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5715 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 5716 | cur_params.dot11MeshRetryTimeout) || |
| 5717 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 5718 | cur_params.dot11MeshConfirmTimeout) || |
| 5719 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 5720 | cur_params.dot11MeshHoldingTimeout) || |
| 5721 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 5722 | cur_params.dot11MeshMaxPeerLinks) || |
| 5723 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 5724 | cur_params.dot11MeshMaxRetries) || |
| 5725 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 5726 | cur_params.dot11MeshTTL) || |
| 5727 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 5728 | cur_params.element_ttl) || |
| 5729 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 5730 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 5731 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 5732 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5733 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 5734 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 5735 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 5736 | cur_params.path_refresh_time) || |
| 5737 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 5738 | cur_params.min_discovery_timeout) || |
| 5739 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 5740 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 5741 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 5742 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 5743 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 5744 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 5745 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5746 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 5747 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5748 | cur_params.dot11MeshHWMPRootMode) || |
| 5749 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 5750 | cur_params.dot11MeshHWMPRannInterval) || |
| 5751 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 5752 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 5753 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 5754 | cur_params.dot11MeshForwarding) || |
Masashi Honma | 335d534 | 2017-03-16 10:57:17 +0900 | [diff] [blame] | 5755 | nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 5756 | cur_params.rssi_threshold) || |
| 5757 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5758 | cur_params.ht_opmode) || |
| 5759 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5760 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 5761 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5762 | cur_params.dot11MeshHWMProotInterval) || |
| 5763 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5764 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 5765 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 5766 | cur_params.power_mode) || |
| 5767 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5768 | cur_params.dot11MeshAwakeWindowDuration) || |
| 5769 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5770 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5771 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5772 | nla_nest_end(msg, pinfoattr); |
| 5773 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5774 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5775 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5776 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5777 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5778 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5779 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5780 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5781 | } |
| 5782 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5783 | 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] | 5784 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 5785 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 5786 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 5787 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 5788 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 5789 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 5790 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5791 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5792 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5793 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 5794 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 5795 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 5796 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 5797 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5798 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5799 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 5800 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 5801 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 5802 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 5803 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5804 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 5805 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5806 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 5807 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5808 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5809 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 5810 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5811 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5812 | }; |
| 5813 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5814 | static const struct nla_policy |
| 5815 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5816 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5817 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 5818 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 5819 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5820 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5821 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5822 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5823 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5824 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5825 | }; |
| 5826 | |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5827 | static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out) |
| 5828 | { |
| 5829 | u8 val = nla_get_u8(nla); |
| 5830 | if (val < min || val > max) |
| 5831 | return -EINVAL; |
| 5832 | *out = val; |
| 5833 | return 0; |
| 5834 | } |
| 5835 | |
| 5836 | static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out) |
| 5837 | { |
| 5838 | u8 val = nla_get_u8(nla); |
| 5839 | if (val < min || val > max) |
| 5840 | return -EINVAL; |
| 5841 | *out = val; |
| 5842 | return 0; |
| 5843 | } |
| 5844 | |
| 5845 | static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out) |
| 5846 | { |
| 5847 | u16 val = nla_get_u16(nla); |
| 5848 | if (val < min || val > max) |
| 5849 | return -EINVAL; |
| 5850 | *out = val; |
| 5851 | return 0; |
| 5852 | } |
| 5853 | |
| 5854 | static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out) |
| 5855 | { |
| 5856 | u32 val = nla_get_u32(nla); |
| 5857 | if (val < min || val > max) |
| 5858 | return -EINVAL; |
| 5859 | *out = val; |
| 5860 | return 0; |
| 5861 | } |
| 5862 | |
| 5863 | static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out) |
| 5864 | { |
| 5865 | s32 val = nla_get_s32(nla); |
| 5866 | if (val < min || val > max) |
| 5867 | return -EINVAL; |
| 5868 | *out = val; |
| 5869 | return 0; |
| 5870 | } |
| 5871 | |
Johannes Berg | ff9a71a | 2016-08-11 14:59:53 +0200 | [diff] [blame] | 5872 | static int nl80211_check_power_mode(const struct nlattr *nla, |
| 5873 | enum nl80211_mesh_power_mode min, |
| 5874 | enum nl80211_mesh_power_mode max, |
| 5875 | enum nl80211_mesh_power_mode *out) |
| 5876 | { |
| 5877 | u32 val = nla_get_u32(nla); |
| 5878 | if (val < min || val > max) |
| 5879 | return -EINVAL; |
| 5880 | *out = val; |
| 5881 | return 0; |
| 5882 | } |
| 5883 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5884 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5885 | struct mesh_config *cfg, |
| 5886 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5887 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5888 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5889 | u32 mask = 0; |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 5890 | u16 ht_opmode; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5891 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5892 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 5893 | do { \ |
| 5894 | if (tb[attr]) { \ |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5895 | if (fn(tb[attr], min, max, &cfg->param)) \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5896 | return -EINVAL; \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5897 | mask |= (1 << (attr - 1)); \ |
| 5898 | } \ |
| 5899 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5900 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5901 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5902 | return -EINVAL; |
| 5903 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5904 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5905 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5906 | return -EINVAL; |
| 5907 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5908 | /* This makes sure that there aren't more than 32 mesh config |
| 5909 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 5910 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 5911 | |
| 5912 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5913 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5914 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5915 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5916 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5917 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5918 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5919 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5920 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5921 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5922 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5923 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5924 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5925 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5926 | mask, NL80211_MESHCONF_MAX_RETRIES, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5927 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5928 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5929 | mask, NL80211_MESHCONF_TTL, nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5930 | 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] | 5931 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5932 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5933 | 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] | 5934 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5935 | nl80211_check_bool); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5936 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 5937 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5938 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5939 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5940 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5941 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5942 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5943 | 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] | 5944 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5945 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5946 | 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] | 5947 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5948 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5949 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 5950 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5951 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5952 | nl80211_check_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5953 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5954 | 1, 65535, mask, |
| 5955 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5956 | nl80211_check_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5957 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5958 | 1, 65535, mask, |
| 5959 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5960 | nl80211_check_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5961 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5962 | dot11MeshHWMPnetDiameterTraversalTime, |
| 5963 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5964 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5965 | nl80211_check_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5966 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 5967 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5968 | nl80211_check_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5969 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 5970 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5971 | nl80211_check_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 5972 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5973 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 5974 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5975 | nl80211_check_bool); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5976 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5977 | mask, NL80211_MESHCONF_FORWARDING, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5978 | nl80211_check_bool); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5979 | 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] | 5980 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 5981 | nl80211_check_s32); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 5982 | /* |
| 5983 | * Check HT operation mode based on |
| 5984 | * IEEE 802.11 2012 8.4.2.59 HT Operation element. |
| 5985 | */ |
| 5986 | if (tb[NL80211_MESHCONF_HT_OPMODE]) { |
| 5987 | ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); |
| 5988 | |
| 5989 | if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | |
| 5990 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | |
| 5991 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 5992 | return -EINVAL; |
| 5993 | |
| 5994 | if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) && |
| 5995 | (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 5996 | return -EINVAL; |
| 5997 | |
| 5998 | switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) { |
| 5999 | case IEEE80211_HT_OP_MODE_PROTECTION_NONE: |
| 6000 | case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ: |
| 6001 | if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT) |
| 6002 | return -EINVAL; |
| 6003 | break; |
| 6004 | case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER: |
| 6005 | case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED: |
| 6006 | if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 6007 | return -EINVAL; |
| 6008 | break; |
| 6009 | } |
| 6010 | cfg->ht_opmode = ht_opmode; |
Masashi Honma | fd551ba | 2017-01-26 08:56:13 +0900 | [diff] [blame] | 6011 | mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1)); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 6012 | } |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 6013 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6014 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 6015 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6016 | nl80211_check_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6017 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 6018 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6019 | nl80211_check_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 6020 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6021 | dot11MeshHWMPconfirmationInterval, |
| 6022 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 6023 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6024 | nl80211_check_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 6025 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 6026 | NL80211_MESH_POWER_ACTIVE, |
| 6027 | NL80211_MESH_POWER_MAX, |
| 6028 | mask, NL80211_MESHCONF_POWER_MODE, |
Johannes Berg | ff9a71a | 2016-08-11 14:59:53 +0200 | [diff] [blame] | 6029 | nl80211_check_power_mode); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 6030 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 6031 | 0, 65535, mask, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6032 | NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16); |
Masashi Honma | 31f909a | 2015-02-24 22:42:16 +0900 | [diff] [blame] | 6033 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 6034 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
Arnd Bergmann | f151d9d | 2016-06-15 22:29:41 +0200 | [diff] [blame] | 6035 | nl80211_check_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6036 | if (mask_out) |
| 6037 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6038 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6039 | return 0; |
| 6040 | |
| 6041 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 6042 | } |
| 6043 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6044 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 6045 | struct mesh_setup *setup) |
| 6046 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 6047 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6048 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 6049 | |
| 6050 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 6051 | return -EINVAL; |
| 6052 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 6053 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 6054 | nl80211_mesh_setup_params_policy)) |
| 6055 | return -EINVAL; |
| 6056 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 6057 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 6058 | setup->sync_method = |
| 6059 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 6060 | IEEE80211_SYNC_METHOD_VENDOR : |
| 6061 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 6062 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6063 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 6064 | setup->path_sel_proto = |
| 6065 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 6066 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 6067 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 6068 | |
| 6069 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 6070 | setup->path_metric = |
| 6071 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 6072 | IEEE80211_PATH_METRIC_VENDOR : |
| 6073 | IEEE80211_PATH_METRIC_AIRTIME; |
| 6074 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 6075 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6076 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 6077 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6078 | if (!is_valid_ie_attr(ieattr)) |
| 6079 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 6080 | setup->ie = nla_data(ieattr); |
| 6081 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6082 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 6083 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 6084 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 6085 | return -EINVAL; |
| 6086 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 6087 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 6088 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 6089 | if (setup->is_secure) |
| 6090 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6091 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 6092 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 6093 | if (!setup->user_mpm) |
| 6094 | return -EINVAL; |
| 6095 | setup->auth_id = |
| 6096 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 6097 | } |
| 6098 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6099 | return 0; |
| 6100 | } |
| 6101 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6102 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6103 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6104 | { |
| 6105 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6106 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6107 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6108 | struct mesh_config cfg; |
| 6109 | u32 mask; |
| 6110 | int err; |
| 6111 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6112 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6113 | return -EOPNOTSUPP; |
| 6114 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6115 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6116 | return -EOPNOTSUPP; |
| 6117 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6118 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6119 | if (err) |
| 6120 | return err; |
| 6121 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6122 | wdev_lock(wdev); |
| 6123 | if (!wdev->mesh_id_len) |
| 6124 | err = -ENOLINK; |
| 6125 | |
| 6126 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6127 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6128 | |
| 6129 | wdev_unlock(wdev); |
| 6130 | |
| 6131 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6132 | } |
| 6133 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6134 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
| 6135 | struct sk_buff *msg) |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6136 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6137 | struct nlattr *nl_reg_rules; |
| 6138 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6139 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6140 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 6141 | (regdom->dfs_region && |
| 6142 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6143 | goto nla_put_failure; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6144 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6145 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 6146 | if (!nl_reg_rules) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6147 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6148 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6149 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6150 | struct nlattr *nl_reg_rule; |
| 6151 | const struct ieee80211_reg_rule *reg_rule; |
| 6152 | const struct ieee80211_freq_range *freq_range; |
| 6153 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6154 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6155 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6156 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6157 | freq_range = ®_rule->freq_range; |
| 6158 | power_rule = ®_rule->power_rule; |
| 6159 | |
| 6160 | nl_reg_rule = nla_nest_start(msg, i); |
| 6161 | if (!nl_reg_rule) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6162 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6163 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6164 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 6165 | if (!max_bandwidth_khz) |
| 6166 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 6167 | reg_rule); |
| 6168 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6169 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 6170 | reg_rule->flags) || |
| 6171 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 6172 | freq_range->start_freq_khz) || |
| 6173 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 6174 | freq_range->end_freq_khz) || |
| 6175 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 6176 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6177 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 6178 | power_rule->max_antenna_gain) || |
| 6179 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 6180 | power_rule->max_eirp) || |
| 6181 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 6182 | reg_rule->dfs_cac_ms)) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6183 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6184 | |
| 6185 | nla_nest_end(msg, nl_reg_rule); |
| 6186 | } |
| 6187 | |
| 6188 | nla_nest_end(msg, nl_reg_rules); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6189 | return 0; |
| 6190 | |
| 6191 | nla_put_failure: |
| 6192 | return -EMSGSIZE; |
| 6193 | } |
| 6194 | |
| 6195 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) |
| 6196 | { |
| 6197 | const struct ieee80211_regdomain *regdom = NULL; |
| 6198 | struct cfg80211_registered_device *rdev; |
| 6199 | struct wiphy *wiphy = NULL; |
| 6200 | struct sk_buff *msg; |
| 6201 | void *hdr; |
| 6202 | |
| 6203 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6204 | if (!msg) |
| 6205 | return -ENOBUFS; |
| 6206 | |
| 6207 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 6208 | NL80211_CMD_GET_REG); |
| 6209 | if (!hdr) |
| 6210 | goto put_failure; |
| 6211 | |
| 6212 | if (info->attrs[NL80211_ATTR_WIPHY]) { |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6213 | bool self_managed; |
| 6214 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6215 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
| 6216 | if (IS_ERR(rdev)) { |
| 6217 | nlmsg_free(msg); |
| 6218 | return PTR_ERR(rdev); |
| 6219 | } |
| 6220 | |
| 6221 | wiphy = &rdev->wiphy; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6222 | self_managed = wiphy->regulatory_flags & |
| 6223 | REGULATORY_WIPHY_SELF_MANAGED; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6224 | regdom = get_wiphy_regdom(wiphy); |
| 6225 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6226 | /* a self-managed-reg device must have a private regdom */ |
| 6227 | if (WARN_ON(!regdom && self_managed)) { |
| 6228 | nlmsg_free(msg); |
| 6229 | return -EINVAL; |
| 6230 | } |
| 6231 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6232 | if (regdom && |
| 6233 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 6234 | goto nla_put_failure; |
| 6235 | } |
| 6236 | |
| 6237 | if (!wiphy && reg_last_request_cell_base() && |
| 6238 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 6239 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 6240 | goto nla_put_failure; |
| 6241 | |
| 6242 | rcu_read_lock(); |
| 6243 | |
| 6244 | if (!regdom) |
| 6245 | regdom = rcu_dereference(cfg80211_regdomain); |
| 6246 | |
| 6247 | if (nl80211_put_regdom(regdom, msg)) |
| 6248 | goto nla_put_failure_rcu; |
| 6249 | |
| 6250 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6251 | |
| 6252 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6253 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6254 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6255 | nla_put_failure_rcu: |
| 6256 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6257 | nla_put_failure: |
| 6258 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 6259 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 6260 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6261 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 6262 | } |
| 6263 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6264 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
| 6265 | u32 seq, int flags, struct wiphy *wiphy, |
| 6266 | const struct ieee80211_regdomain *regdom) |
| 6267 | { |
| 6268 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
| 6269 | NL80211_CMD_GET_REG); |
| 6270 | |
| 6271 | if (!hdr) |
| 6272 | return -1; |
| 6273 | |
| 6274 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 6275 | |
| 6276 | if (nl80211_put_regdom(regdom, msg)) |
| 6277 | goto nla_put_failure; |
| 6278 | |
| 6279 | if (!wiphy && reg_last_request_cell_base() && |
| 6280 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 6281 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 6282 | goto nla_put_failure; |
| 6283 | |
| 6284 | if (wiphy && |
| 6285 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 6286 | goto nla_put_failure; |
| 6287 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 6288 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 6289 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 6290 | goto nla_put_failure; |
| 6291 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 6292 | genlmsg_end(msg, hdr); |
| 6293 | return 0; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 6294 | |
| 6295 | nla_put_failure: |
| 6296 | genlmsg_cancel(msg, hdr); |
| 6297 | return -EMSGSIZE; |
| 6298 | } |
| 6299 | |
| 6300 | static int nl80211_get_reg_dump(struct sk_buff *skb, |
| 6301 | struct netlink_callback *cb) |
| 6302 | { |
| 6303 | const struct ieee80211_regdomain *regdom = NULL; |
| 6304 | struct cfg80211_registered_device *rdev; |
| 6305 | int err, reg_idx, start = cb->args[2]; |
| 6306 | |
| 6307 | rtnl_lock(); |
| 6308 | |
| 6309 | if (cfg80211_regdomain && start == 0) { |
| 6310 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 6311 | NLM_F_MULTI, NULL, |
| 6312 | rtnl_dereference(cfg80211_regdomain)); |
| 6313 | if (err < 0) |
| 6314 | goto out_err; |
| 6315 | } |
| 6316 | |
| 6317 | /* the global regdom is idx 0 */ |
| 6318 | reg_idx = 1; |
| 6319 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 6320 | regdom = get_wiphy_regdom(&rdev->wiphy); |
| 6321 | if (!regdom) |
| 6322 | continue; |
| 6323 | |
| 6324 | if (++reg_idx <= start) |
| 6325 | continue; |
| 6326 | |
| 6327 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 6328 | NLM_F_MULTI, &rdev->wiphy, regdom); |
| 6329 | if (err < 0) { |
| 6330 | reg_idx--; |
| 6331 | break; |
| 6332 | } |
| 6333 | } |
| 6334 | |
| 6335 | cb->args[2] = reg_idx; |
| 6336 | err = skb->len; |
| 6337 | out_err: |
| 6338 | rtnl_unlock(); |
| 6339 | return err; |
| 6340 | } |
| 6341 | |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 6342 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
| 6343 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 6344 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 6345 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 6346 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 6347 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 6348 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 6349 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 6350 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
| 6351 | }; |
| 6352 | |
| 6353 | static int parse_reg_rule(struct nlattr *tb[], |
| 6354 | struct ieee80211_reg_rule *reg_rule) |
| 6355 | { |
| 6356 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 6357 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 6358 | |
| 6359 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 6360 | return -EINVAL; |
| 6361 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 6362 | return -EINVAL; |
| 6363 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 6364 | return -EINVAL; |
| 6365 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 6366 | return -EINVAL; |
| 6367 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 6368 | return -EINVAL; |
| 6369 | |
| 6370 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 6371 | |
| 6372 | freq_range->start_freq_khz = |
| 6373 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 6374 | freq_range->end_freq_khz = |
| 6375 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 6376 | freq_range->max_bandwidth_khz = |
| 6377 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 6378 | |
| 6379 | power_rule->max_eirp = |
| 6380 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 6381 | |
| 6382 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 6383 | power_rule->max_antenna_gain = |
| 6384 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 6385 | |
| 6386 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 6387 | reg_rule->dfs_cac_ms = |
| 6388 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 6389 | |
| 6390 | return 0; |
| 6391 | } |
| 6392 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6393 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 6394 | { |
| 6395 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 6396 | struct nlattr *nl_reg_rule; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 6397 | char *alpha2; |
| 6398 | int rem_reg_rules, r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6399 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 6400 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 6401 | struct ieee80211_regdomain *rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6402 | |
| 6403 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 6404 | return -EINVAL; |
| 6405 | |
| 6406 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 6407 | return -EINVAL; |
| 6408 | |
| 6409 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 6410 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 6411 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 6412 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 6413 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6414 | 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] | 6415 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6416 | num_rules++; |
| 6417 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 6418 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6419 | } |
| 6420 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 6421 | if (!reg_is_valid_request(alpha2)) |
| 6422 | return -EINVAL; |
| 6423 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6424 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 6425 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6426 | |
| 6427 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 6428 | if (!rd) |
| 6429 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6430 | |
| 6431 | rd->n_reg_rules = num_rules; |
| 6432 | rd->alpha2[0] = alpha2[0]; |
| 6433 | rd->alpha2[1] = alpha2[1]; |
| 6434 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 6435 | /* |
| 6436 | * Disable DFS master mode if the DFS region was |
| 6437 | * not supported or known on this kernel. |
| 6438 | */ |
| 6439 | if (reg_supported_dfs_region(dfs_region)) |
| 6440 | rd->dfs_region = dfs_region; |
| 6441 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6442 | 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] | 6443 | rem_reg_rules) { |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 6444 | r = nla_parse_nested(tb, NL80211_REG_RULE_ATTR_MAX, |
| 6445 | nl_reg_rule, reg_rule_policy); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 6446 | if (r) |
| 6447 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6448 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 6449 | if (r) |
| 6450 | goto bad_reg; |
| 6451 | |
| 6452 | rule_idx++; |
| 6453 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6454 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 6455 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6456 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6457 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6458 | } |
| 6459 | |
Johannes Berg | 0662799 | 2016-06-09 10:40:09 +0200 | [diff] [blame] | 6460 | /* set_regdom takes ownership of rd */ |
| 6461 | return set_regdom(rd, REGD_SOURCE_CRDA); |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 6462 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6463 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 6464 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6465 | } |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 6466 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6467 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6468 | static int validate_scan_freqs(struct nlattr *freqs) |
| 6469 | { |
| 6470 | struct nlattr *attr1, *attr2; |
| 6471 | int n_channels = 0, tmp1, tmp2; |
| 6472 | |
| 6473 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 6474 | n_channels++; |
| 6475 | /* |
| 6476 | * Some hardware has a limited channel list for |
| 6477 | * scanning, and it is pretty much nonsensical |
| 6478 | * to scan for a channel twice, so disallow that |
| 6479 | * and don't require drivers to check that the |
| 6480 | * channel list they get isn't longer than what |
| 6481 | * they can scan, as long as they can scan all |
| 6482 | * the channels they registered at once. |
| 6483 | */ |
| 6484 | nla_for_each_nested(attr2, freqs, tmp2) |
| 6485 | if (attr1 != attr2 && |
| 6486 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 6487 | return 0; |
| 6488 | } |
| 6489 | |
| 6490 | return n_channels; |
| 6491 | } |
| 6492 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6493 | 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] | 6494 | { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6495 | return b < NUM_NL80211_BANDS && wiphy->bands[b]; |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 6496 | } |
| 6497 | |
| 6498 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, |
| 6499 | struct cfg80211_bss_selection *bss_select) |
| 6500 | { |
| 6501 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; |
| 6502 | struct nlattr *nest; |
| 6503 | int err; |
| 6504 | bool found = false; |
| 6505 | int i; |
| 6506 | |
| 6507 | /* only process one nested attribute */ |
| 6508 | nest = nla_data(nla); |
| 6509 | if (!nla_ok(nest, nla_len(nest))) |
| 6510 | return -EINVAL; |
| 6511 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 6512 | err = nla_parse_nested(attr, NL80211_BSS_SELECT_ATTR_MAX, nest, |
| 6513 | nl80211_bss_select_policy); |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 6514 | if (err) |
| 6515 | return err; |
| 6516 | |
| 6517 | /* only one attribute may be given */ |
| 6518 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { |
| 6519 | if (attr[i]) { |
| 6520 | if (found) |
| 6521 | return -EINVAL; |
| 6522 | found = true; |
| 6523 | } |
| 6524 | } |
| 6525 | |
| 6526 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; |
| 6527 | |
| 6528 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) |
| 6529 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; |
| 6530 | |
| 6531 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { |
| 6532 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; |
| 6533 | bss_select->param.band_pref = |
| 6534 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); |
| 6535 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) |
| 6536 | return -EINVAL; |
| 6537 | } |
| 6538 | |
| 6539 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { |
| 6540 | struct nl80211_bss_select_rssi_adjust *adj_param; |
| 6541 | |
| 6542 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); |
| 6543 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; |
| 6544 | bss_select->param.adjust.band = adj_param->band; |
| 6545 | bss_select->param.adjust.delta = adj_param->delta; |
| 6546 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) |
| 6547 | return -EINVAL; |
| 6548 | } |
| 6549 | |
| 6550 | /* user-space did not provide behaviour attribute */ |
| 6551 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) |
| 6552 | return -EINVAL; |
| 6553 | |
| 6554 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) |
| 6555 | return -EINVAL; |
| 6556 | |
| 6557 | return 0; |
| 6558 | } |
| 6559 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6560 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
| 6561 | u8 *mac_addr, u8 *mac_addr_mask) |
| 6562 | { |
| 6563 | int i; |
| 6564 | |
| 6565 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { |
Joe Perches | d2beae1 | 2015-03-02 19:54:58 -0800 | [diff] [blame] | 6566 | eth_zero_addr(mac_addr); |
| 6567 | eth_zero_addr(mac_addr_mask); |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6568 | mac_addr[0] = 0x2; |
| 6569 | mac_addr_mask[0] = 0x3; |
| 6570 | |
| 6571 | return 0; |
| 6572 | } |
| 6573 | |
| 6574 | /* need both or none */ |
| 6575 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) |
| 6576 | return -EINVAL; |
| 6577 | |
| 6578 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); |
| 6579 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); |
| 6580 | |
| 6581 | /* don't allow or configure an mcast address */ |
| 6582 | if (!is_multicast_ether_addr(mac_addr_mask) || |
| 6583 | is_multicast_ether_addr(mac_addr)) |
| 6584 | return -EINVAL; |
| 6585 | |
| 6586 | /* |
| 6587 | * allow users to pass a MAC address that has bits set outside |
| 6588 | * of the mask, but don't bother drivers with having to deal |
| 6589 | * with such bits |
| 6590 | */ |
| 6591 | for (i = 0; i < ETH_ALEN; i++) |
| 6592 | mac_addr[i] &= mac_addr_mask[i]; |
| 6593 | |
| 6594 | return 0; |
| 6595 | } |
| 6596 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 6597 | static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev) |
| 6598 | { |
| 6599 | ASSERT_WDEV_LOCK(wdev); |
| 6600 | |
| 6601 | if (!cfg80211_beaconing_iface_active(wdev)) |
| 6602 | return true; |
| 6603 | |
| 6604 | if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR)) |
| 6605 | return true; |
| 6606 | |
| 6607 | return regulatory_pre_cac_allowed(wdev->wiphy); |
| 6608 | } |
| 6609 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6610 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 6611 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6612 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6613 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6614 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6615 | struct nlattr *attr; |
| 6616 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6617 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6618 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6619 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6620 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6621 | return -EINVAL; |
| 6622 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6623 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6624 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 6625 | if (wdev->iftype == NL80211_IFTYPE_NAN) |
| 6626 | return -EOPNOTSUPP; |
| 6627 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6628 | if (!rdev->ops->scan) |
| 6629 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6630 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 6631 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6632 | err = -EBUSY; |
| 6633 | goto unlock; |
| 6634 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6635 | |
| 6636 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 6637 | n_channels = validate_scan_freqs( |
| 6638 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6639 | if (!n_channels) { |
| 6640 | err = -EINVAL; |
| 6641 | goto unlock; |
| 6642 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6643 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 6644 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6645 | } |
| 6646 | |
| 6647 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 6648 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 6649 | n_ssids++; |
| 6650 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6651 | if (n_ssids > wiphy->max_scan_ssids) { |
| 6652 | err = -EINVAL; |
| 6653 | goto unlock; |
| 6654 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6655 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6656 | if (info->attrs[NL80211_ATTR_IE]) |
| 6657 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6658 | else |
| 6659 | ie_len = 0; |
| 6660 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6661 | if (ie_len > wiphy->max_scan_ie_len) { |
| 6662 | err = -EINVAL; |
| 6663 | goto unlock; |
| 6664 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 6665 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6666 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 6667 | + sizeof(*request->ssids) * n_ssids |
| 6668 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6669 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6670 | if (!request) { |
| 6671 | err = -ENOMEM; |
| 6672 | goto unlock; |
| 6673 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6674 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6675 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 6676 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6677 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6678 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6679 | if (n_ssids) |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6680 | request->ie = (void *)(request->ssids + n_ssids); |
| 6681 | else |
| 6682 | request->ie = (void *)(request->channels + n_channels); |
| 6683 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6684 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6685 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6686 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 6687 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6688 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6689 | struct ieee80211_channel *chan; |
| 6690 | |
| 6691 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 6692 | |
| 6693 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6694 | err = -EINVAL; |
| 6695 | goto out_free; |
| 6696 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6697 | |
| 6698 | /* ignore disabled channels */ |
| 6699 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6700 | continue; |
| 6701 | |
| 6702 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6703 | i++; |
| 6704 | } |
| 6705 | } else { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6706 | enum nl80211_band band; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6707 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6708 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6709 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6710 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 6711 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6712 | if (!wiphy->bands[band]) |
| 6713 | continue; |
| 6714 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6715 | struct ieee80211_channel *chan; |
| 6716 | |
| 6717 | chan = &wiphy->bands[band]->channels[j]; |
| 6718 | |
| 6719 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6720 | continue; |
| 6721 | |
| 6722 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6723 | i++; |
| 6724 | } |
| 6725 | } |
| 6726 | } |
| 6727 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 6728 | if (!i) { |
| 6729 | err = -EINVAL; |
| 6730 | goto out_free; |
| 6731 | } |
| 6732 | |
| 6733 | request->n_channels = i; |
| 6734 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 6735 | wdev_lock(wdev); |
| 6736 | if (!cfg80211_off_channel_oper_allowed(wdev)) { |
| 6737 | struct ieee80211_channel *chan; |
| 6738 | |
| 6739 | if (request->n_channels != 1) { |
| 6740 | wdev_unlock(wdev); |
| 6741 | err = -EBUSY; |
| 6742 | goto out_free; |
| 6743 | } |
| 6744 | |
| 6745 | chan = request->channels[0]; |
| 6746 | if (chan->center_freq != wdev->chandef.chan->center_freq) { |
| 6747 | wdev_unlock(wdev); |
| 6748 | err = -EBUSY; |
| 6749 | goto out_free; |
| 6750 | } |
| 6751 | } |
| 6752 | wdev_unlock(wdev); |
| 6753 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6754 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 6755 | if (n_ssids) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6756 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6757 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6758 | err = -EINVAL; |
| 6759 | goto out_free; |
| 6760 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6761 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6762 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6763 | i++; |
| 6764 | } |
| 6765 | } |
| 6766 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6767 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6768 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 6769 | memcpy((void *)request->ie, |
| 6770 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 6771 | request->ie_len); |
| 6772 | } |
| 6773 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6774 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 6775 | if (wiphy->bands[i]) |
| 6776 | request->rates[i] = |
| 6777 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6778 | |
| 6779 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 6780 | nla_for_each_nested(attr, |
| 6781 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 6782 | tmp) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6783 | enum nl80211_band band = nla_type(attr); |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6784 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 6785 | if (band < 0 || band >= NUM_NL80211_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6786 | err = -EINVAL; |
| 6787 | goto out_free; |
| 6788 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 6789 | |
| 6790 | if (!wiphy->bands[band]) |
| 6791 | continue; |
| 6792 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6793 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 6794 | nla_data(attr), |
| 6795 | nla_len(attr), |
| 6796 | &request->rates[band]); |
| 6797 | if (err) |
| 6798 | goto out_free; |
| 6799 | } |
| 6800 | } |
| 6801 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 6802 | if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { |
| 6803 | if (!wiphy_ext_feature_isset(wiphy, |
| 6804 | NL80211_EXT_FEATURE_SET_SCAN_DWELL)) { |
| 6805 | err = -EOPNOTSUPP; |
| 6806 | goto out_free; |
| 6807 | } |
| 6808 | |
| 6809 | request->duration = |
| 6810 | nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); |
| 6811 | request->duration_mandatory = |
| 6812 | nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); |
| 6813 | } |
| 6814 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6815 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6816 | request->flags = nla_get_u32( |
| 6817 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 6818 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 6819 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6820 | err = -EOPNOTSUPP; |
| 6821 | goto out_free; |
| 6822 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6823 | |
| 6824 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 6825 | if (!(wiphy->features & |
| 6826 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { |
| 6827 | err = -EOPNOTSUPP; |
| 6828 | goto out_free; |
| 6829 | } |
| 6830 | |
| 6831 | if (wdev->current_bss) { |
| 6832 | err = -EOPNOTSUPP; |
| 6833 | goto out_free; |
| 6834 | } |
| 6835 | |
| 6836 | err = nl80211_parse_random_mac(info->attrs, |
| 6837 | request->mac_addr, |
| 6838 | request->mac_addr_mask); |
| 6839 | if (err) |
| 6840 | goto out_free; |
| 6841 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6842 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6843 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 6844 | request->no_cck = |
| 6845 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 6846 | |
Vamsi Krishna | 2fa436b | 2016-12-02 23:59:08 +0200 | [diff] [blame] | 6847 | /* Initial implementation used NL80211_ATTR_MAC to set the specific |
| 6848 | * BSSID to scan for. This was problematic because that same attribute |
| 6849 | * was already used for another purpose (local random MAC address). The |
| 6850 | * NL80211_ATTR_BSSID attribute was added to fix this. For backwards |
| 6851 | * compatibility with older userspace components, also use the |
| 6852 | * NL80211_ATTR_MAC value here if it can be determined to be used for |
| 6853 | * the specific BSSID use case instead of the random MAC address |
| 6854 | * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use). |
| 6855 | */ |
| 6856 | if (info->attrs[NL80211_ATTR_BSSID]) |
| 6857 | memcpy(request->bssid, |
| 6858 | nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN); |
| 6859 | else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) && |
| 6860 | info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 818965d | 2016-02-26 22:12:47 +0200 | [diff] [blame] | 6861 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), |
| 6862 | ETH_ALEN); |
| 6863 | else |
| 6864 | eth_broadcast_addr(request->bssid); |
| 6865 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6866 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6867 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 6868 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6869 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6870 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6871 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6872 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6873 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 6874 | nl80211_send_scan_start(rdev, wdev); |
| 6875 | if (wdev->netdev) |
| 6876 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6877 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6878 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6879 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6880 | kfree(request); |
| 6881 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6882 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 6883 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6884 | return err; |
| 6885 | } |
| 6886 | |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 6887 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
| 6888 | { |
| 6889 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6890 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 6891 | |
| 6892 | if (!rdev->ops->abort_scan) |
| 6893 | return -EOPNOTSUPP; |
| 6894 | |
| 6895 | if (rdev->scan_msg) |
| 6896 | return 0; |
| 6897 | |
| 6898 | if (!rdev->scan_req) |
| 6899 | return -ENOENT; |
| 6900 | |
| 6901 | rdev_abort_scan(rdev, wdev); |
| 6902 | return 0; |
| 6903 | } |
| 6904 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6905 | static int |
| 6906 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, |
| 6907 | struct cfg80211_sched_scan_request *request, |
| 6908 | struct nlattr **attrs) |
| 6909 | { |
| 6910 | int tmp, err, i = 0; |
| 6911 | struct nlattr *attr; |
| 6912 | |
| 6913 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 6914 | u32 interval; |
| 6915 | |
| 6916 | /* |
| 6917 | * If scan plans are not specified, |
Arend Van Spriel | 5a88de5 | 2016-11-17 09:02:40 +0000 | [diff] [blame] | 6918 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6919 | * case one scan plan will be set with the specified scan |
| 6920 | * interval and infinite number of iterations. |
| 6921 | */ |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6922 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 6923 | if (!interval) |
| 6924 | return -EINVAL; |
| 6925 | |
| 6926 | request->scan_plans[0].interval = |
| 6927 | DIV_ROUND_UP(interval, MSEC_PER_SEC); |
| 6928 | if (!request->scan_plans[0].interval) |
| 6929 | return -EINVAL; |
| 6930 | |
| 6931 | if (request->scan_plans[0].interval > |
| 6932 | wiphy->max_sched_scan_plan_interval) |
| 6933 | request->scan_plans[0].interval = |
| 6934 | wiphy->max_sched_scan_plan_interval; |
| 6935 | |
| 6936 | return 0; |
| 6937 | } |
| 6938 | |
| 6939 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { |
| 6940 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; |
| 6941 | |
| 6942 | if (WARN_ON(i >= n_plans)) |
| 6943 | return -EINVAL; |
| 6944 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 6945 | err = nla_parse_nested(plan, NL80211_SCHED_SCAN_PLAN_MAX, |
| 6946 | attr, nl80211_plan_policy); |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6947 | if (err) |
| 6948 | return err; |
| 6949 | |
| 6950 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) |
| 6951 | return -EINVAL; |
| 6952 | |
| 6953 | request->scan_plans[i].interval = |
| 6954 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); |
| 6955 | if (!request->scan_plans[i].interval || |
| 6956 | request->scan_plans[i].interval > |
| 6957 | wiphy->max_sched_scan_plan_interval) |
| 6958 | return -EINVAL; |
| 6959 | |
| 6960 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { |
| 6961 | request->scan_plans[i].iterations = |
| 6962 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); |
| 6963 | if (!request->scan_plans[i].iterations || |
| 6964 | (request->scan_plans[i].iterations > |
| 6965 | wiphy->max_sched_scan_plan_iterations)) |
| 6966 | return -EINVAL; |
| 6967 | } else if (i < n_plans - 1) { |
| 6968 | /* |
| 6969 | * All scan plans but the last one must specify |
| 6970 | * a finite number of iterations |
| 6971 | */ |
| 6972 | return -EINVAL; |
| 6973 | } |
| 6974 | |
| 6975 | i++; |
| 6976 | } |
| 6977 | |
| 6978 | /* |
| 6979 | * The last scan plan must not specify the number of |
| 6980 | * iterations, it is supposed to run infinitely |
| 6981 | */ |
| 6982 | if (request->scan_plans[n_plans - 1].iterations) |
| 6983 | return -EINVAL; |
| 6984 | |
| 6985 | return 0; |
| 6986 | } |
| 6987 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6988 | static struct cfg80211_sched_scan_request * |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6989 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 6990 | struct nlattr **attrs, int max_match_sets) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6991 | { |
| 6992 | struct cfg80211_sched_scan_request *request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6993 | struct nlattr *attr; |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 6994 | 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] | 6995 | enum nl80211_band band; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6996 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6997 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6998 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6999 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7000 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
| 7001 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7002 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7003 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7004 | n_channels = validate_scan_freqs( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7005 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7006 | if (!n_channels) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7007 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7008 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 7009 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7010 | } |
| 7011 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7012 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 7013 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7014 | tmp) |
| 7015 | n_ssids++; |
| 7016 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 7017 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7018 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7019 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7020 | /* |
| 7021 | * First, count the number of 'real' matchsets. Due to an issue with |
| 7022 | * the old implementation, matchsets containing only the RSSI attribute |
| 7023 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 7024 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 7025 | * all APs with a strong RSSI. This is needed to be compatible with |
| 7026 | * older userspace that treated a matchset with only the RSSI as the |
| 7027 | * global RSSI for all other matchsets - if there are other matchsets. |
| 7028 | */ |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7029 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7030 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7031 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7032 | tmp) { |
| 7033 | struct nlattr *rssi; |
| 7034 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 7035 | err = nla_parse_nested(tb, |
| 7036 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 7037 | attr, nl80211_match_policy); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7038 | if (err) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7039 | return ERR_PTR(err); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7040 | /* add other standalone attributes here */ |
| 7041 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { |
| 7042 | n_match_sets++; |
| 7043 | continue; |
| 7044 | } |
| 7045 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 7046 | if (rssi) |
| 7047 | default_match_rssi = nla_get_s32(rssi); |
| 7048 | } |
| 7049 | } |
| 7050 | |
| 7051 | /* However, if there's no other matchset, add the RSSI one */ |
| 7052 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 7053 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7054 | |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 7055 | if (n_match_sets > max_match_sets) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7056 | return ERR_PTR(-EINVAL); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7057 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7058 | if (attrs[NL80211_ATTR_IE]) |
| 7059 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7060 | else |
| 7061 | ie_len = 0; |
| 7062 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 7063 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7064 | return ERR_PTR(-EINVAL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 7065 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7066 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 7067 | /* |
| 7068 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since |
| 7069 | * each scan plan already specifies its own interval |
| 7070 | */ |
| 7071 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 7072 | return ERR_PTR(-EINVAL); |
| 7073 | |
| 7074 | nla_for_each_nested(attr, |
| 7075 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) |
| 7076 | n_plans++; |
| 7077 | } else { |
| 7078 | /* |
| 7079 | * The scan interval attribute is kept for backward |
| 7080 | * compatibility. If no scan plans are specified and sched scan |
| 7081 | * interval is specified, one scan plan will be set with this |
| 7082 | * scan interval and infinite number of iterations. |
| 7083 | */ |
| 7084 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 7085 | return ERR_PTR(-EINVAL); |
| 7086 | |
| 7087 | n_plans = 1; |
| 7088 | } |
| 7089 | |
| 7090 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) |
| 7091 | return ERR_PTR(-EINVAL); |
| 7092 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 7093 | if (!wiphy_ext_feature_isset( |
| 7094 | wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) && |
| 7095 | (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] || |
| 7096 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST])) |
| 7097 | return ERR_PTR(-EINVAL); |
| 7098 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7099 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 7100 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7101 | + sizeof(*request->match_sets) * n_match_sets |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7102 | + sizeof(*request->scan_plans) * n_plans |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 7103 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7104 | + ie_len, GFP_KERNEL); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7105 | if (!request) |
| 7106 | return ERR_PTR(-ENOMEM); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7107 | |
| 7108 | if (n_ssids) |
| 7109 | request->ssids = (void *)&request->channels[n_channels]; |
| 7110 | request->n_ssids = n_ssids; |
| 7111 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7112 | if (n_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7113 | request->ie = (void *)(request->ssids + n_ssids); |
| 7114 | else |
| 7115 | request->ie = (void *)(request->channels + n_channels); |
| 7116 | } |
| 7117 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7118 | if (n_match_sets) { |
| 7119 | if (request->ie) |
| 7120 | request->match_sets = (void *)(request->ie + ie_len); |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7121 | else if (n_ssids) |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7122 | request->match_sets = |
| 7123 | (void *)(request->ssids + n_ssids); |
| 7124 | else |
| 7125 | request->match_sets = |
| 7126 | (void *)(request->channels + n_channels); |
| 7127 | } |
| 7128 | request->n_match_sets = n_match_sets; |
| 7129 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7130 | if (n_match_sets) |
| 7131 | request->scan_plans = (void *)(request->match_sets + |
| 7132 | n_match_sets); |
| 7133 | else if (request->ie) |
| 7134 | request->scan_plans = (void *)(request->ie + ie_len); |
| 7135 | else if (n_ssids) |
| 7136 | request->scan_plans = (void *)(request->ssids + n_ssids); |
| 7137 | else |
| 7138 | request->scan_plans = (void *)(request->channels + n_channels); |
| 7139 | |
| 7140 | request->n_scan_plans = n_plans; |
| 7141 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7142 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7143 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7144 | /* user specified, bail out if channel not found */ |
| 7145 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7146 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7147 | tmp) { |
| 7148 | struct ieee80211_channel *chan; |
| 7149 | |
| 7150 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 7151 | |
| 7152 | if (!chan) { |
| 7153 | err = -EINVAL; |
| 7154 | goto out_free; |
| 7155 | } |
| 7156 | |
| 7157 | /* ignore disabled channels */ |
| 7158 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 7159 | continue; |
| 7160 | |
| 7161 | request->channels[i] = chan; |
| 7162 | i++; |
| 7163 | } |
| 7164 | } else { |
| 7165 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7166 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7167 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 7168 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7169 | if (!wiphy->bands[band]) |
| 7170 | continue; |
| 7171 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 7172 | struct ieee80211_channel *chan; |
| 7173 | |
| 7174 | chan = &wiphy->bands[band]->channels[j]; |
| 7175 | |
| 7176 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 7177 | continue; |
| 7178 | |
| 7179 | request->channels[i] = chan; |
| 7180 | i++; |
| 7181 | } |
| 7182 | } |
| 7183 | } |
| 7184 | |
| 7185 | if (!i) { |
| 7186 | err = -EINVAL; |
| 7187 | goto out_free; |
| 7188 | } |
| 7189 | |
| 7190 | request->n_channels = i; |
| 7191 | |
| 7192 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7193 | if (n_ssids) { |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7194 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7195 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7196 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7197 | err = -EINVAL; |
| 7198 | goto out_free; |
| 7199 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7200 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7201 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 7202 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7203 | i++; |
| 7204 | } |
| 7205 | } |
| 7206 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7207 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7208 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7209 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7210 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7211 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 7212 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7213 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 7214 | err = nla_parse_nested(tb, |
| 7215 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 7216 | attr, nl80211_match_policy); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7217 | if (err) |
| 7218 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 7219 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7220 | if (ssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7221 | if (WARN_ON(i >= n_match_sets)) { |
| 7222 | /* this indicates a programming error, |
| 7223 | * the loop above should have verified |
| 7224 | * things properly |
| 7225 | */ |
| 7226 | err = -EINVAL; |
| 7227 | goto out_free; |
| 7228 | } |
| 7229 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7230 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 7231 | err = -EINVAL; |
| 7232 | goto out_free; |
| 7233 | } |
| 7234 | memcpy(request->match_sets[i].ssid.ssid, |
| 7235 | nla_data(ssid), nla_len(ssid)); |
| 7236 | request->match_sets[i].ssid.ssid_len = |
| 7237 | nla_len(ssid); |
Kirtika Ruchandani | 56ab364 | 2016-05-29 19:54:10 -0700 | [diff] [blame] | 7238 | /* special attribute - old implementation w/a */ |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7239 | request->match_sets[i].rssi_thold = |
| 7240 | default_match_rssi; |
| 7241 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 7242 | if (rssi) |
| 7243 | request->match_sets[i].rssi_thold = |
| 7244 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7245 | } |
| 7246 | i++; |
| 7247 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7248 | |
| 7249 | /* there was no other matchset, so the RSSI one is alone */ |
Luciano Coelho | f89f46c | 2014-12-01 11:32:09 +0200 | [diff] [blame] | 7250 | if (i == 0 && n_match_sets) |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 7251 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 7252 | |
| 7253 | request->min_rssi_thold = INT_MAX; |
| 7254 | for (i = 0; i < n_match_sets; i++) |
| 7255 | request->min_rssi_thold = |
| 7256 | min(request->match_sets[i].rssi_thold, |
| 7257 | request->min_rssi_thold); |
| 7258 | } else { |
| 7259 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 7260 | } |
| 7261 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 7262 | if (ie_len) { |
| 7263 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7264 | memcpy((void *)request->ie, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7265 | nla_data(attrs[NL80211_ATTR_IE]), |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7266 | request->ie_len); |
| 7267 | } |
| 7268 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7269 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 7270 | request->flags = nla_get_u32( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7271 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 7272 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 7273 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 7274 | err = -EOPNOTSUPP; |
| 7275 | goto out_free; |
| 7276 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7277 | |
| 7278 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 7279 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; |
| 7280 | |
| 7281 | if (!wdev) /* must be net-detect */ |
| 7282 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 7283 | |
| 7284 | if (!(wiphy->features & flg)) { |
| 7285 | err = -EOPNOTSUPP; |
| 7286 | goto out_free; |
| 7287 | } |
| 7288 | |
| 7289 | if (wdev && wdev->current_bss) { |
| 7290 | err = -EOPNOTSUPP; |
| 7291 | goto out_free; |
| 7292 | } |
| 7293 | |
| 7294 | err = nl80211_parse_random_mac(attrs, request->mac_addr, |
| 7295 | request->mac_addr_mask); |
| 7296 | if (err) |
| 7297 | goto out_free; |
| 7298 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 7299 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 7300 | |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 7301 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
| 7302 | request->delay = |
| 7303 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); |
| 7304 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 7305 | if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) { |
| 7306 | request->relative_rssi = nla_get_s8( |
| 7307 | attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]); |
| 7308 | request->relative_rssi_set = true; |
| 7309 | } |
| 7310 | |
| 7311 | if (request->relative_rssi_set && |
| 7312 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) { |
| 7313 | struct nl80211_bss_select_rssi_adjust *rssi_adjust; |
| 7314 | |
| 7315 | rssi_adjust = nla_data( |
| 7316 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]); |
| 7317 | request->rssi_adjust.band = rssi_adjust->band; |
| 7318 | request->rssi_adjust.delta = rssi_adjust->delta; |
| 7319 | if (!is_band_valid(wiphy, request->rssi_adjust.band)) { |
| 7320 | err = -EINVAL; |
| 7321 | goto out_free; |
| 7322 | } |
| 7323 | } |
| 7324 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 7325 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
| 7326 | if (err) |
| 7327 | goto out_free; |
| 7328 | |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 7329 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7330 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7331 | return request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7332 | |
| 7333 | out_free: |
| 7334 | kfree(request); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7335 | return ERR_PTR(err); |
| 7336 | } |
| 7337 | |
| 7338 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 7339 | struct genl_info *info) |
| 7340 | { |
| 7341 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7342 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7343 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7344 | struct cfg80211_sched_scan_request *sched_scan_req; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7345 | int err; |
| 7346 | |
| 7347 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 7348 | !rdev->ops->sched_scan_start) |
| 7349 | return -EOPNOTSUPP; |
| 7350 | |
| 7351 | if (rdev->sched_scan_req) |
| 7352 | return -EINPROGRESS; |
| 7353 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7354 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 7355 | info->attrs, |
| 7356 | rdev->wiphy.max_match_sets); |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7357 | |
| 7358 | err = PTR_ERR_OR_ZERO(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7359 | if (err) |
| 7360 | goto out_err; |
| 7361 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7362 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7363 | if (err) |
| 7364 | goto out_free; |
| 7365 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7366 | sched_scan_req->dev = dev; |
| 7367 | sched_scan_req->wiphy = &rdev->wiphy; |
| 7368 | |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 7369 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 7370 | sched_scan_req->owner_nlportid = info->snd_portid; |
| 7371 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7372 | rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7373 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 7374 | nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7375 | return 0; |
| 7376 | |
| 7377 | out_free: |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 7378 | kfree(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 7379 | out_err: |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7380 | return err; |
| 7381 | } |
| 7382 | |
| 7383 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 7384 | struct genl_info *info) |
| 7385 | { |
| 7386 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7387 | |
| 7388 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 7389 | !rdev->ops->sched_scan_stop) |
| 7390 | return -EOPNOTSUPP; |
| 7391 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7392 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 7393 | } |
| 7394 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7395 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 7396 | struct genl_info *info) |
| 7397 | { |
| 7398 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7399 | struct net_device *dev = info->user_ptr[1]; |
| 7400 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7401 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 7402 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 7403 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7404 | int err; |
| 7405 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 7406 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 7407 | if (dfs_region == NL80211_DFS_UNSET) |
| 7408 | return -EINVAL; |
| 7409 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7410 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7411 | if (err) |
| 7412 | return err; |
| 7413 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 7414 | if (netif_carrier_ok(dev)) |
| 7415 | return -EBUSY; |
| 7416 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7417 | if (wdev->cac_started) |
| 7418 | return -EBUSY; |
| 7419 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 7420 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 7421 | wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7422 | if (err < 0) |
| 7423 | return err; |
| 7424 | |
| 7425 | if (err == 0) |
| 7426 | return -EINVAL; |
| 7427 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 7428 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7429 | return -EINVAL; |
| 7430 | |
| 7431 | if (!rdev->ops->start_radar_detection) |
| 7432 | return -EOPNOTSUPP; |
| 7433 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 7434 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 7435 | if (WARN_ON(!cac_time_ms)) |
| 7436 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 7437 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 7438 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7439 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 7440 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7441 | wdev->cac_started = true; |
| 7442 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 7443 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7444 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 7445 | return err; |
| 7446 | } |
| 7447 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7448 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 7449 | { |
| 7450 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7451 | struct net_device *dev = info->user_ptr[1]; |
| 7452 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7453 | struct cfg80211_csa_settings params; |
| 7454 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 7455 | * function is called under RTNL lock, so this should not be a problem. |
| 7456 | */ |
| 7457 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7458 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7459 | bool need_new_beacon = false; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7460 | int len, i; |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 7461 | u32 cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7462 | |
| 7463 | if (!rdev->ops->channel_switch || |
| 7464 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 7465 | return -EOPNOTSUPP; |
| 7466 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7467 | switch (dev->ieee80211_ptr->iftype) { |
| 7468 | case NL80211_IFTYPE_AP: |
| 7469 | case NL80211_IFTYPE_P2P_GO: |
| 7470 | need_new_beacon = true; |
| 7471 | |
| 7472 | /* useless if AP is not running */ |
| 7473 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 7474 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7475 | break; |
| 7476 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 7477 | if (!wdev->ssid_len) |
| 7478 | return -ENOTCONN; |
| 7479 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 7480 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 7481 | if (!wdev->mesh_id_len) |
| 7482 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7483 | break; |
| 7484 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7485 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7486 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7487 | |
| 7488 | memset(¶ms, 0, sizeof(params)); |
| 7489 | |
| 7490 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7491 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 7492 | return -EINVAL; |
| 7493 | |
| 7494 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 7495 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7496 | return -EINVAL; |
| 7497 | |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 7498 | /* Even though the attribute is u32, the specification says |
| 7499 | * u8, so let's make sure we don't overflow. |
| 7500 | */ |
| 7501 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 7502 | if (cs_count > 255) |
| 7503 | return -EINVAL; |
| 7504 | |
| 7505 | params.count = cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7506 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7507 | if (!need_new_beacon) |
| 7508 | goto skip_beacons; |
| 7509 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7510 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 7511 | if (err) |
| 7512 | return err; |
| 7513 | |
| 7514 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 7515 | info->attrs[NL80211_ATTR_CSA_IES], |
| 7516 | nl80211_policy); |
| 7517 | if (err) |
| 7518 | return err; |
| 7519 | |
| 7520 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 7521 | if (err) |
| 7522 | return err; |
| 7523 | |
| 7524 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 7525 | return -EINVAL; |
| 7526 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7527 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 7528 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7529 | return -EINVAL; |
| 7530 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7531 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 7532 | if (rdev->wiphy.max_num_csa_counters && |
| 7533 | (params.n_counter_offsets_beacon > |
| 7534 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7535 | return -EINVAL; |
| 7536 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7537 | params.counter_offsets_beacon = |
| 7538 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 7539 | |
| 7540 | /* sanity checks - counters should fit and be the same */ |
| 7541 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 7542 | u16 offset = params.counter_offsets_beacon[i]; |
| 7543 | |
| 7544 | if (offset >= params.beacon_csa.tail_len) |
| 7545 | return -EINVAL; |
| 7546 | |
| 7547 | if (params.beacon_csa.tail[offset] != params.count) |
| 7548 | return -EINVAL; |
| 7549 | } |
| 7550 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7551 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7552 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 7553 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7554 | return -EINVAL; |
| 7555 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7556 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 7557 | if (rdev->wiphy.max_num_csa_counters && |
Johannes Berg | ad5987b | 2016-09-13 15:53:55 +0200 | [diff] [blame] | 7558 | (params.n_counter_offsets_presp > |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7559 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7560 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 7561 | |
| 7562 | params.counter_offsets_presp = |
| 7563 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 7564 | |
| 7565 | /* sanity checks - counters should fit and be the same */ |
| 7566 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 7567 | u16 offset = params.counter_offsets_presp[i]; |
| 7568 | |
| 7569 | if (offset >= params.beacon_csa.probe_resp_len) |
| 7570 | return -EINVAL; |
| 7571 | |
| 7572 | if (params.beacon_csa.probe_resp[offset] != |
| 7573 | params.count) |
| 7574 | return -EINVAL; |
| 7575 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7576 | } |
| 7577 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 7578 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7579 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 7580 | if (err) |
| 7581 | return err; |
| 7582 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 7583 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 7584 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7585 | return -EINVAL; |
| 7586 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 7587 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 7588 | ¶ms.chandef, |
| 7589 | wdev->iftype); |
| 7590 | if (err < 0) |
| 7591 | return err; |
| 7592 | |
Fabian Frederick | dcc6c2f | 2014-10-25 17:57:35 +0200 | [diff] [blame] | 7593 | if (err > 0) |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 7594 | params.radar_required = true; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7595 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7596 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 7597 | params.block_tx = true; |
| 7598 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 7599 | wdev_lock(wdev); |
| 7600 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 7601 | wdev_unlock(wdev); |
| 7602 | |
| 7603 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 7604 | } |
| 7605 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7606 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 7607 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7608 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7609 | struct wireless_dev *wdev, |
| 7610 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7611 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7612 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7613 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7614 | void *hdr; |
| 7615 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7616 | |
| 7617 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7618 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7619 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7620 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 7621 | if (!hdr) |
| 7622 | return -1; |
| 7623 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7624 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 7625 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7626 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 7627 | goto nla_put_failure; |
| 7628 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7629 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 7630 | goto nla_put_failure; |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7631 | if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 7632 | NL80211_ATTR_PAD)) |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7633 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7634 | |
| 7635 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 7636 | if (!bss) |
| 7637 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7638 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7639 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7640 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7641 | |
| 7642 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7643 | /* indicate whether we have probe response data or not */ |
| 7644 | if (rcu_access_pointer(res->proberesp_ies) && |
| 7645 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 7646 | goto fail_unlock_rcu; |
| 7647 | |
| 7648 | /* this pointer prefers to be pointed to probe response data |
| 7649 | * but is always valid |
| 7650 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7651 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7652 | if (ies) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7653 | if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, |
| 7654 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7655 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7656 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 7657 | ies->len, ies->data)) |
| 7658 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7659 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7660 | |
| 7661 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7662 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 7663 | if (ies && ies->from_beacon) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7664 | if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, |
| 7665 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7666 | goto fail_unlock_rcu; |
| 7667 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 7668 | ies->len, ies->data)) |
| 7669 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 7670 | } |
| 7671 | rcu_read_unlock(); |
| 7672 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7673 | if (res->beacon_interval && |
| 7674 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 7675 | goto nla_put_failure; |
| 7676 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 7677 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 7678 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7679 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 7680 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 7681 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7682 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 7683 | if (intbss->parent_tsf && |
| 7684 | (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, |
| 7685 | intbss->parent_tsf, NL80211_BSS_PAD) || |
| 7686 | nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, |
| 7687 | intbss->parent_bssid))) |
| 7688 | goto nla_put_failure; |
| 7689 | |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 7690 | if (intbss->ts_boottime && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7691 | nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
| 7692 | intbss->ts_boottime, NL80211_BSS_PAD)) |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 7693 | goto nla_put_failure; |
| 7694 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 7695 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7696 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7697 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 7698 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7699 | break; |
| 7700 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7701 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 7702 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7703 | break; |
| 7704 | default: |
| 7705 | break; |
| 7706 | } |
| 7707 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7708 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7709 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7710 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7711 | if (intbss == wdev->current_bss && |
| 7712 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 7713 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 7714 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7715 | break; |
| 7716 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7717 | if (intbss == wdev->current_bss && |
| 7718 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 7719 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 7720 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7721 | break; |
| 7722 | default: |
| 7723 | break; |
| 7724 | } |
| 7725 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7726 | nla_nest_end(msg, bss); |
| 7727 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 7728 | genlmsg_end(msg, hdr); |
| 7729 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7730 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 7731 | fail_unlock_rcu: |
| 7732 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7733 | nla_put_failure: |
| 7734 | genlmsg_cancel(msg, hdr); |
| 7735 | return -EMSGSIZE; |
| 7736 | } |
| 7737 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7738 | 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] | 7739 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7740 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7741 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7742 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7743 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7744 | int err; |
| 7745 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7746 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7747 | if (err) |
| 7748 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7749 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7750 | wdev_lock(wdev); |
| 7751 | spin_lock_bh(&rdev->bss_lock); |
| 7752 | cfg80211_bss_expire(rdev); |
| 7753 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7754 | cb->seq = rdev->bss_generation; |
| 7755 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7756 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7757 | if (++idx <= start) |
| 7758 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 7759 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7760 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7761 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7762 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7763 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7764 | } |
| 7765 | } |
| 7766 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 7767 | spin_unlock_bh(&rdev->bss_lock); |
| 7768 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7769 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7770 | cb->args[2] = idx; |
| 7771 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7772 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7773 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7774 | } |
| 7775 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7776 | 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] | 7777 | int flags, struct net_device *dev, |
| 7778 | bool allow_radio_stats, |
| 7779 | struct survey_info *survey) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7780 | { |
| 7781 | void *hdr; |
| 7782 | struct nlattr *infoattr; |
| 7783 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7784 | /* skip radio stats if userspace didn't request them */ |
| 7785 | if (!survey->channel && !allow_radio_stats) |
| 7786 | return 0; |
| 7787 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7788 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7789 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 7790 | if (!hdr) |
| 7791 | return -ENOMEM; |
| 7792 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7793 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 7794 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7795 | |
| 7796 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 7797 | if (!infoattr) |
| 7798 | goto nla_put_failure; |
| 7799 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7800 | if (survey->channel && |
| 7801 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7802 | survey->channel->center_freq)) |
| 7803 | goto nla_put_failure; |
| 7804 | |
| 7805 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 7806 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 7807 | goto nla_put_failure; |
| 7808 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 7809 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 7810 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7811 | if ((survey->filled & SURVEY_INFO_TIME) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7812 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, |
| 7813 | survey->time, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7814 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7815 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7816 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
| 7817 | survey->time_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7818 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7819 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7820 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
| 7821 | survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7822 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7823 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7824 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, |
| 7825 | survey->time_rx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7826 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 7827 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7828 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, |
| 7829 | survey->time_tx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7830 | goto nla_put_failure; |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 7831 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 7832 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
| 7833 | survey->time_scan, NL80211_SURVEY_INFO_PAD)) |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 7834 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7835 | |
| 7836 | nla_nest_end(msg, infoattr); |
| 7837 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 7838 | genlmsg_end(msg, hdr); |
| 7839 | return 0; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7840 | |
| 7841 | nla_put_failure: |
| 7842 | genlmsg_cancel(msg, hdr); |
| 7843 | return -EMSGSIZE; |
| 7844 | } |
| 7845 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7846 | 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] | 7847 | { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 7848 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7849 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7850 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7851 | struct wireless_dev *wdev; |
| 7852 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7853 | int res; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7854 | bool radio_stats; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7855 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7856 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7857 | if (res) |
| 7858 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7859 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7860 | /* prepare_wdev_dump parsed the attributes */ |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 7861 | radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7862 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7863 | if (!wdev->netdev) { |
| 7864 | res = -EINVAL; |
| 7865 | goto out_err; |
| 7866 | } |
| 7867 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7868 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7869 | res = -EOPNOTSUPP; |
| 7870 | goto out_err; |
| 7871 | } |
| 7872 | |
| 7873 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7874 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7875 | if (res == -ENOENT) |
| 7876 | break; |
| 7877 | if (res) |
| 7878 | goto out_err; |
| 7879 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7880 | /* don't send disabled channels, but do send non-channel data */ |
| 7881 | if (survey.channel && |
| 7882 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 7883 | survey_idx++; |
| 7884 | continue; |
| 7885 | } |
| 7886 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7887 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7888 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7889 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 7890 | wdev->netdev, radio_stats, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7891 | goto out; |
| 7892 | survey_idx++; |
| 7893 | } |
| 7894 | |
| 7895 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7896 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7897 | res = skb->len; |
| 7898 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7899 | nl80211_finish_wdev_dump(rdev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 7900 | return res; |
| 7901 | } |
| 7902 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7903 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 7904 | { |
| 7905 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 7906 | NL80211_WPA_VERSION_2)); |
| 7907 | } |
| 7908 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7909 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 7910 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7911 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7912 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7913 | struct ieee80211_channel *chan; |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 7914 | const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL; |
| 7915 | int err, ssid_len, ie_len = 0, auth_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7916 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7917 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7918 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7919 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7920 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7921 | return -EINVAL; |
| 7922 | |
| 7923 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7924 | return -EINVAL; |
| 7925 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 7926 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 7927 | return -EINVAL; |
| 7928 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7929 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 7930 | return -EINVAL; |
| 7931 | |
| 7932 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7933 | return -EINVAL; |
| 7934 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7935 | err = nl80211_parse_key(info, &key); |
| 7936 | if (err) |
| 7937 | return err; |
| 7938 | |
| 7939 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 7940 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 7941 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7942 | if (!key.p.key || !key.p.key_len) |
| 7943 | return -EINVAL; |
| 7944 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 7945 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 7946 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 7947 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 7948 | return -EINVAL; |
Johannes Berg | b6b5555 | 2016-09-13 16:25:58 +0200 | [diff] [blame] | 7949 | if (key.idx > 3) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7950 | return -EINVAL; |
| 7951 | } else { |
| 7952 | key.p.key_len = 0; |
| 7953 | key.p.key = NULL; |
| 7954 | } |
| 7955 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 7956 | if (key.idx >= 0) { |
| 7957 | int i; |
| 7958 | bool ok = false; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 7959 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 7960 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 7961 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 7962 | ok = true; |
| 7963 | break; |
| 7964 | } |
| 7965 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7966 | if (!ok) |
| 7967 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 7968 | } |
| 7969 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7970 | if (!rdev->ops->auth) |
| 7971 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7972 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7973 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7974 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7975 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7976 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7977 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7978 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 7979 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7980 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7981 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7982 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7983 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7984 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7985 | |
| 7986 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7987 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7988 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7989 | } |
| 7990 | |
| 7991 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7992 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7993 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7994 | |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 7995 | if ((auth_type == NL80211_AUTHTYPE_SAE || |
| 7996 | auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 7997 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 7998 | auth_type == NL80211_AUTHTYPE_FILS_PK) && |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 7999 | !info->attrs[NL80211_ATTR_AUTH_DATA]) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8000 | return -EINVAL; |
| 8001 | |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8002 | if (info->attrs[NL80211_ATTR_AUTH_DATA]) { |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 8003 | if (auth_type != NL80211_AUTHTYPE_SAE && |
| 8004 | auth_type != NL80211_AUTHTYPE_FILS_SK && |
| 8005 | auth_type != NL80211_AUTHTYPE_FILS_SK_PFS && |
| 8006 | auth_type != NL80211_AUTHTYPE_FILS_PK) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8007 | return -EINVAL; |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8008 | auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]); |
| 8009 | auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8010 | /* need to include at least Auth Transaction and Status Code */ |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8011 | if (auth_data_len < 4) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8012 | return -EINVAL; |
| 8013 | } |
| 8014 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8015 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 8016 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 8017 | /* |
| 8018 | * Since we no longer track auth state, ignore |
| 8019 | * requests to only change local state. |
| 8020 | */ |
| 8021 | if (local_state_change) |
| 8022 | return 0; |
| 8023 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8024 | wdev_lock(dev->ieee80211_ptr); |
| 8025 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 8026 | ssid, ssid_len, ie, ie_len, |
| 8027 | key.p.key, key.p.key_len, key.idx, |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 8028 | auth_data, auth_data_len); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8029 | wdev_unlock(dev->ieee80211_ptr); |
| 8030 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8031 | } |
| 8032 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8033 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 8034 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 8035 | struct cfg80211_crypto_settings *settings, |
| 8036 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8037 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 8038 | memset(settings, 0, sizeof(*settings)); |
| 8039 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8040 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 8041 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8042 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 8043 | u16 proto; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 8044 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8045 | proto = nla_get_u16( |
| 8046 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 8047 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 8048 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 8049 | proto != ETH_P_PAE) |
| 8050 | return -EINVAL; |
| 8051 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 8052 | settings->control_port_no_encrypt = true; |
| 8053 | } else |
| 8054 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 8055 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8056 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 8057 | void *data; |
| 8058 | int len, i; |
| 8059 | |
| 8060 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 8061 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 8062 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 8063 | |
| 8064 | if (len % sizeof(u32)) |
| 8065 | return -EINVAL; |
| 8066 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 8067 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8068 | return -EINVAL; |
| 8069 | |
| 8070 | memcpy(settings->ciphers_pairwise, data, len); |
| 8071 | |
| 8072 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 8073 | if (!cfg80211_supported_cipher_suite( |
| 8074 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8075 | settings->ciphers_pairwise[i])) |
| 8076 | return -EINVAL; |
| 8077 | } |
| 8078 | |
| 8079 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 8080 | settings->cipher_group = |
| 8081 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 8082 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 8083 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8084 | return -EINVAL; |
| 8085 | } |
| 8086 | |
| 8087 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 8088 | settings->wpa_versions = |
| 8089 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 8090 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 8091 | return -EINVAL; |
| 8092 | } |
| 8093 | |
| 8094 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 8095 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 8096 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8097 | |
| 8098 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 8099 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 8100 | settings->n_akm_suites = len / sizeof(u32); |
| 8101 | |
| 8102 | if (len % sizeof(u32)) |
| 8103 | return -EINVAL; |
| 8104 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 8105 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 8106 | return -EINVAL; |
| 8107 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8108 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8109 | } |
| 8110 | |
| 8111 | return 0; |
| 8112 | } |
| 8113 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8114 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 8115 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8116 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8117 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 8118 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8119 | struct cfg80211_assoc_request req = {}; |
| 8120 | const u8 *bssid, *ssid; |
| 8121 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8122 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8123 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8124 | return -EINVAL; |
| 8125 | |
| 8126 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8127 | !info->attrs[NL80211_ATTR_SSID] || |
| 8128 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8129 | return -EINVAL; |
| 8130 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8131 | if (!rdev->ops->assoc) |
| 8132 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8133 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8134 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8135 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8136 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8137 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8138 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8139 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8140 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 8141 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 8142 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8143 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8144 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8145 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8146 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8147 | |
| 8148 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8149 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8150 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8151 | } |
| 8152 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 8153 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 8154 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 8155 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 8156 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8157 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8158 | else if (mfp != NL80211_MFP_NO) |
| 8159 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 8160 | } |
| 8161 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 8162 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8163 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 8164 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8165 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8166 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8167 | |
| 8168 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8169 | memcpy(&req.ht_capa_mask, |
| 8170 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 8171 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8172 | |
| 8173 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8174 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8175 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8176 | memcpy(&req.ht_capa, |
| 8177 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 8178 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8179 | } |
| 8180 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8181 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8182 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8183 | |
| 8184 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8185 | memcpy(&req.vht_capa_mask, |
| 8186 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 8187 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8188 | |
| 8189 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8190 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8191 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8192 | memcpy(&req.vht_capa, |
| 8193 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 8194 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8195 | } |
| 8196 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8197 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 8198 | if (!((rdev->wiphy.features & |
| 8199 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 8200 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 8201 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 8202 | NL80211_EXT_FEATURE_RRM)) |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8203 | return -EINVAL; |
| 8204 | req.flags |= ASSOC_REQ_USE_RRM; |
| 8205 | } |
| 8206 | |
Jouni Malinen | 348bd45 | 2016-10-27 00:42:03 +0300 | [diff] [blame] | 8207 | if (info->attrs[NL80211_ATTR_FILS_KEK]) { |
| 8208 | req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 8209 | req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 8210 | if (!info->attrs[NL80211_ATTR_FILS_NONCES]) |
| 8211 | return -EINVAL; |
| 8212 | req.fils_nonces = |
| 8213 | nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); |
| 8214 | } |
| 8215 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8216 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8217 | if (!err) { |
| 8218 | wdev_lock(dev->ieee80211_ptr); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 8219 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 8220 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 8221 | ssid, ssid_len, &req); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 8222 | |
| 8223 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 8224 | dev->ieee80211_ptr->conn_owner_nlportid = |
| 8225 | info->snd_portid; |
| 8226 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 8227 | bssid, ETH_ALEN); |
| 8228 | } |
| 8229 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8230 | wdev_unlock(dev->ieee80211_ptr); |
| 8231 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8232 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8233 | return err; |
| 8234 | } |
| 8235 | |
| 8236 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 8237 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8238 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8239 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8240 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8241 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8242 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8243 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8244 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8245 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8246 | return -EINVAL; |
| 8247 | |
| 8248 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8249 | return -EINVAL; |
| 8250 | |
| 8251 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 8252 | return -EINVAL; |
| 8253 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8254 | if (!rdev->ops->deauth) |
| 8255 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8256 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8257 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8258 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8259 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8260 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8261 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8262 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8263 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 8264 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8265 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8266 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 8267 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8268 | |
| 8269 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8270 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8271 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8272 | } |
| 8273 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8274 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 8275 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8276 | wdev_lock(dev->ieee80211_ptr); |
| 8277 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 8278 | local_state_change); |
| 8279 | wdev_unlock(dev->ieee80211_ptr); |
| 8280 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8281 | } |
| 8282 | |
| 8283 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 8284 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8285 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8286 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8287 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8288 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8289 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8290 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8291 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8292 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8293 | return -EINVAL; |
| 8294 | |
| 8295 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 8296 | return -EINVAL; |
| 8297 | |
| 8298 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 8299 | return -EINVAL; |
| 8300 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8301 | if (!rdev->ops->disassoc) |
| 8302 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8303 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8304 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8305 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8306 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 8307 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8308 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8309 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8310 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 8311 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 8312 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8313 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 8314 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8315 | |
| 8316 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 8317 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8318 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8319 | } |
| 8320 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 8321 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 8322 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8323 | wdev_lock(dev->ieee80211_ptr); |
| 8324 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 8325 | local_state_change); |
| 8326 | wdev_unlock(dev->ieee80211_ptr); |
| 8327 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 8328 | } |
| 8329 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8330 | static bool |
| 8331 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8332 | int mcast_rate[NUM_NL80211_BANDS], |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8333 | int rateval) |
| 8334 | { |
| 8335 | struct wiphy *wiphy = &rdev->wiphy; |
| 8336 | bool found = false; |
| 8337 | int band, i; |
| 8338 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8339 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8340 | struct ieee80211_supported_band *sband; |
| 8341 | |
| 8342 | sband = wiphy->bands[band]; |
| 8343 | if (!sband) |
| 8344 | continue; |
| 8345 | |
| 8346 | for (i = 0; i < sband->n_bitrates; i++) { |
| 8347 | if (sband->bitrates[i].bitrate == rateval) { |
| 8348 | mcast_rate[band] = i + 1; |
| 8349 | found = true; |
| 8350 | break; |
| 8351 | } |
| 8352 | } |
| 8353 | } |
| 8354 | |
| 8355 | return found; |
| 8356 | } |
| 8357 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8358 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 8359 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8360 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8361 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8362 | struct cfg80211_ibss_params ibss; |
| 8363 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8364 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8365 | int err; |
| 8366 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8367 | memset(&ibss, 0, sizeof(ibss)); |
| 8368 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8369 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8370 | return -EINVAL; |
| 8371 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8372 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8373 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 8374 | return -EINVAL; |
| 8375 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8376 | ibss.beacon_interval = 100; |
| 8377 | |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 8378 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8379 | ibss.beacon_interval = |
| 8380 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 8381 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 8382 | err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC, |
| 8383 | ibss.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 8384 | if (err) |
| 8385 | return err; |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 8386 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8387 | if (!rdev->ops->join_ibss) |
| 8388 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8389 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8390 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 8391 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8392 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8393 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8394 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 8395 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8396 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 8397 | |
| 8398 | if (!is_valid_ether_addr(ibss.bssid)) |
| 8399 | return -EINVAL; |
| 8400 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8401 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8402 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 8403 | |
| 8404 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8405 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8406 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8407 | } |
| 8408 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8409 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 8410 | if (err) |
| 8411 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 8412 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 8413 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 8414 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 8415 | return -EINVAL; |
| 8416 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8417 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 8418 | case NL80211_CHAN_WIDTH_5: |
| 8419 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8420 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 8421 | break; |
| 8422 | case NL80211_CHAN_WIDTH_20: |
| 8423 | case NL80211_CHAN_WIDTH_40: |
Janusz.Dziedzic@tieto.com | ffc1199 | 2015-02-21 16:52:39 +0100 | [diff] [blame] | 8424 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 8425 | return -EINVAL; |
| 8426 | break; |
| 8427 | case NL80211_CHAN_WIDTH_80: |
| 8428 | case NL80211_CHAN_WIDTH_80P80: |
| 8429 | case NL80211_CHAN_WIDTH_160: |
| 8430 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 8431 | return -EINVAL; |
| 8432 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 8433 | NL80211_EXT_FEATURE_VHT_IBSS)) |
| 8434 | return -EINVAL; |
| 8435 | break; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8436 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 8437 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 8438 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 8439 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8440 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8441 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8442 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8443 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 8444 | u8 *rates = |
| 8445 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8446 | int n_rates = |
| 8447 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8448 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8449 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8450 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 8451 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 8452 | &ibss.basic_rates); |
| 8453 | if (err) |
| 8454 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8455 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8456 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 8457 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 8458 | memcpy(&ibss.ht_capa_mask, |
| 8459 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 8460 | sizeof(ibss.ht_capa_mask)); |
| 8461 | |
| 8462 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 8463 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 8464 | return -EINVAL; |
| 8465 | memcpy(&ibss.ht_capa, |
| 8466 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 8467 | sizeof(ibss.ht_capa)); |
| 8468 | } |
| 8469 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 8470 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 8471 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 8472 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 8473 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 8474 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8475 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8476 | bool no_ht = false; |
| 8477 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8478 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8479 | info->attrs[NL80211_ATTR_KEYS], |
| 8480 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8481 | if (IS_ERR(connkeys)) |
| 8482 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8483 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 8484 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 8485 | no_ht) { |
Ola Olsson | 5e950a7 | 2016-02-11 01:00:22 +0100 | [diff] [blame] | 8486 | kzfree(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8487 | return -EINVAL; |
| 8488 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8489 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8490 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 8491 | ibss.control_port = |
| 8492 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 8493 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 8494 | ibss.userspace_handles_dfs = |
| 8495 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 8496 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8497 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8498 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8499 | kzfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8500 | return err; |
| 8501 | } |
| 8502 | |
| 8503 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 8504 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8505 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8506 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8507 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8508 | if (!rdev->ops->leave_ibss) |
| 8509 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8510 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8511 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 8512 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8513 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8514 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 8515 | } |
| 8516 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8517 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 8518 | { |
| 8519 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8520 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8521 | int mcast_rate[NUM_NL80211_BANDS]; |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8522 | u32 nla_rate; |
| 8523 | int err; |
| 8524 | |
| 8525 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Bertold Van den Bergh | 876dc93 | 2015-08-05 16:02:21 +0200 | [diff] [blame] | 8526 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
| 8527 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8528 | return -EOPNOTSUPP; |
| 8529 | |
| 8530 | if (!rdev->ops->set_mcast_rate) |
| 8531 | return -EOPNOTSUPP; |
| 8532 | |
| 8533 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 8534 | |
| 8535 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 8536 | return -EINVAL; |
| 8537 | |
| 8538 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 8539 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 8540 | return -EINVAL; |
| 8541 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 8542 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8543 | |
| 8544 | return err; |
| 8545 | } |
| 8546 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8547 | static struct sk_buff * |
| 8548 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8549 | struct wireless_dev *wdev, int approxlen, |
| 8550 | u32 portid, u32 seq, enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 8551 | enum nl80211_attrs attr, |
| 8552 | const struct nl80211_vendor_cmd_info *info, |
| 8553 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8554 | { |
| 8555 | struct sk_buff *skb; |
| 8556 | void *hdr; |
| 8557 | struct nlattr *data; |
| 8558 | |
| 8559 | skb = nlmsg_new(approxlen + 100, gfp); |
| 8560 | if (!skb) |
| 8561 | return NULL; |
| 8562 | |
| 8563 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 8564 | if (!hdr) { |
| 8565 | kfree_skb(skb); |
| 8566 | return NULL; |
| 8567 | } |
| 8568 | |
| 8569 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 8570 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 8571 | |
| 8572 | if (info) { |
| 8573 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 8574 | info->vendor_id)) |
| 8575 | goto nla_put_failure; |
| 8576 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 8577 | info->subcmd)) |
| 8578 | goto nla_put_failure; |
| 8579 | } |
| 8580 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8581 | if (wdev) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8582 | if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 8583 | wdev_id(wdev), NL80211_ATTR_PAD)) |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8584 | goto nla_put_failure; |
| 8585 | if (wdev->netdev && |
| 8586 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, |
| 8587 | wdev->netdev->ifindex)) |
| 8588 | goto nla_put_failure; |
| 8589 | } |
| 8590 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8591 | data = nla_nest_start(skb, attr); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 8592 | if (!data) |
| 8593 | goto nla_put_failure; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8594 | |
| 8595 | ((void **)skb->cb)[0] = rdev; |
| 8596 | ((void **)skb->cb)[1] = hdr; |
| 8597 | ((void **)skb->cb)[2] = data; |
| 8598 | |
| 8599 | return skb; |
| 8600 | |
| 8601 | nla_put_failure: |
| 8602 | kfree_skb(skb); |
| 8603 | return NULL; |
| 8604 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 8605 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8606 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8607 | struct wireless_dev *wdev, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8608 | enum nl80211_commands cmd, |
| 8609 | enum nl80211_attrs attr, |
| 8610 | int vendor_event_idx, |
| 8611 | int approxlen, gfp_t gfp) |
| 8612 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 8613 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8614 | const struct nl80211_vendor_cmd_info *info; |
| 8615 | |
| 8616 | switch (cmd) { |
| 8617 | case NL80211_CMD_TESTMODE: |
| 8618 | if (WARN_ON(vendor_event_idx != -1)) |
| 8619 | return NULL; |
| 8620 | info = NULL; |
| 8621 | break; |
| 8622 | case NL80211_CMD_VENDOR: |
| 8623 | if (WARN_ON(vendor_event_idx < 0 || |
| 8624 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 8625 | return NULL; |
| 8626 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 8627 | break; |
| 8628 | default: |
| 8629 | WARN_ON(1); |
| 8630 | return NULL; |
| 8631 | } |
| 8632 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 8633 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8634 | cmd, attr, info, gfp); |
| 8635 | } |
| 8636 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 8637 | |
| 8638 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 8639 | { |
| 8640 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 8641 | void *hdr = ((void **)skb->cb)[1]; |
| 8642 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 8643 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 8644 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 8645 | /* clear CB data for netlink core to own from now on */ |
| 8646 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 8647 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 8648 | nla_nest_end(skb, data); |
| 8649 | genlmsg_end(skb, hdr); |
| 8650 | |
| 8651 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 8652 | mcgrp = NL80211_MCGRP_VENDOR; |
| 8653 | |
| 8654 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 8655 | mcgrp, gfp); |
| 8656 | } |
| 8657 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 8658 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8659 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8660 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 8661 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8662 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8663 | struct wireless_dev *wdev = |
| 8664 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8665 | int err; |
| 8666 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8667 | if (!rdev->ops->testmode_cmd) |
| 8668 | return -EOPNOTSUPP; |
| 8669 | |
| 8670 | if (IS_ERR(wdev)) { |
| 8671 | err = PTR_ERR(wdev); |
| 8672 | if (err != -EINVAL) |
| 8673 | return err; |
| 8674 | wdev = NULL; |
| 8675 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 8676 | return -EINVAL; |
| 8677 | } |
| 8678 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8679 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 8680 | return -EINVAL; |
| 8681 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8682 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 8683 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8684 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 8685 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 8686 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8687 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8688 | return err; |
| 8689 | } |
| 8690 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8691 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 8692 | struct netlink_callback *cb) |
| 8693 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8694 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8695 | int err; |
| 8696 | long phy_idx; |
| 8697 | void *data = NULL; |
| 8698 | int data_len = 0; |
| 8699 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8700 | rtnl_lock(); |
| 8701 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8702 | if (cb->args[0]) { |
| 8703 | /* |
| 8704 | * 0 is a valid index, but not valid for args[0], |
| 8705 | * so we need to offset by 1. |
| 8706 | */ |
| 8707 | phy_idx = cb->args[0] - 1; |
Luca Coelho | a4956dc | 2017-02-07 22:13:56 +0200 | [diff] [blame] | 8708 | |
| 8709 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 8710 | if (!rdev) { |
| 8711 | err = -ENOENT; |
| 8712 | goto out_err; |
| 8713 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8714 | } else { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 8715 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
| 8716 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8717 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 8718 | attrbuf, nl80211_fam.maxattr, nl80211_policy); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8719 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8720 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8721 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 8722 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8723 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8724 | err = PTR_ERR(rdev); |
| 8725 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8726 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8727 | phy_idx = rdev->wiphy_idx; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 8728 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 8729 | if (attrbuf[NL80211_ATTR_TESTDATA]) |
| 8730 | cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA]; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8731 | } |
| 8732 | |
| 8733 | if (cb->args[1]) { |
| 8734 | data = nla_data((void *)cb->args[1]); |
| 8735 | data_len = nla_len((void *)cb->args[1]); |
| 8736 | } |
| 8737 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 8738 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8739 | err = -EOPNOTSUPP; |
| 8740 | goto out_err; |
| 8741 | } |
| 8742 | |
| 8743 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8744 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8745 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 8746 | NL80211_CMD_TESTMODE); |
| 8747 | struct nlattr *tmdata; |
| 8748 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8749 | if (!hdr) |
| 8750 | break; |
| 8751 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8752 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8753 | genlmsg_cancel(skb, hdr); |
| 8754 | break; |
| 8755 | } |
| 8756 | |
| 8757 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 8758 | if (!tmdata) { |
| 8759 | genlmsg_cancel(skb, hdr); |
| 8760 | break; |
| 8761 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8762 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8763 | nla_nest_end(skb, tmdata); |
| 8764 | |
| 8765 | if (err == -ENOBUFS || err == -ENOENT) { |
| 8766 | genlmsg_cancel(skb, hdr); |
| 8767 | break; |
| 8768 | } else if (err) { |
| 8769 | genlmsg_cancel(skb, hdr); |
| 8770 | goto out_err; |
| 8771 | } |
| 8772 | |
| 8773 | genlmsg_end(skb, hdr); |
| 8774 | } |
| 8775 | |
| 8776 | err = skb->len; |
| 8777 | /* see above */ |
| 8778 | cb->args[0] = phy_idx + 1; |
| 8779 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8780 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 8781 | return err; |
| 8782 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 8783 | #endif |
| 8784 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8785 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 8786 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8787 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8788 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8789 | struct cfg80211_connect_params connect; |
| 8790 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8791 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8792 | int err; |
| 8793 | |
| 8794 | memset(&connect, 0, sizeof(connect)); |
| 8795 | |
| 8796 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 8797 | return -EINVAL; |
| 8798 | |
| 8799 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 8800 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 8801 | return -EINVAL; |
| 8802 | |
| 8803 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 8804 | connect.auth_type = |
| 8805 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 8806 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 8807 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8808 | return -EINVAL; |
| 8809 | } else |
| 8810 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 8811 | |
| 8812 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 8813 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 8814 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 8815 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8816 | if (err) |
| 8817 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8818 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8819 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8820 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8821 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8822 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8823 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8824 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 8825 | connect.bg_scan_period = -1; |
| 8826 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 8827 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 8828 | connect.bg_scan_period = |
| 8829 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 8830 | } |
| 8831 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8832 | if (info->attrs[NL80211_ATTR_MAC]) |
| 8833 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8834 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 8835 | connect.bssid_hint = |
| 8836 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8837 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 8838 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 8839 | |
| 8840 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8841 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 8842 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8843 | } |
| 8844 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 8845 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 8846 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 8847 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 8848 | connect.mfp != NL80211_MFP_NO) |
| 8849 | return -EINVAL; |
| 8850 | } else { |
| 8851 | connect.mfp = NL80211_MFP_NO; |
| 8852 | } |
| 8853 | |
Jouni Malinen | ba6fbac | 2016-03-29 13:53:27 +0300 | [diff] [blame] | 8854 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 8855 | connect.prev_bssid = |
| 8856 | nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 8857 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8858 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8859 | connect.channel = nl80211_get_valid_chan( |
| 8860 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 8861 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8862 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8863 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 8864 | connect.channel_hint = nl80211_get_valid_chan( |
| 8865 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 8866 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 8867 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8868 | } |
| 8869 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8870 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 8871 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 8872 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8873 | if (IS_ERR(connkeys)) |
| 8874 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8875 | } |
| 8876 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8877 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 8878 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 8879 | |
| 8880 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 8881 | memcpy(&connect.ht_capa_mask, |
| 8882 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 8883 | sizeof(connect.ht_capa_mask)); |
| 8884 | |
| 8885 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 8886 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8887 | kzfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8888 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 8889 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 8890 | memcpy(&connect.ht_capa, |
| 8891 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 8892 | sizeof(connect.ht_capa)); |
| 8893 | } |
| 8894 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8895 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 8896 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 8897 | |
| 8898 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 8899 | memcpy(&connect.vht_capa_mask, |
| 8900 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 8901 | sizeof(connect.vht_capa_mask)); |
| 8902 | |
| 8903 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 8904 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8905 | kzfree(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 8906 | return -EINVAL; |
| 8907 | } |
| 8908 | memcpy(&connect.vht_capa, |
| 8909 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 8910 | sizeof(connect.vht_capa)); |
| 8911 | } |
| 8912 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8913 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 8914 | if (!((rdev->wiphy.features & |
| 8915 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 8916 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 8917 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 8918 | NL80211_EXT_FEATURE_RRM)) { |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 8919 | kzfree(connkeys); |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8920 | return -EINVAL; |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 8921 | } |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 8922 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 8923 | } |
| 8924 | |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 8925 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8926 | if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 8927 | kzfree(connkeys); |
| 8928 | return -EOPNOTSUPP; |
| 8929 | } |
| 8930 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 8931 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { |
| 8932 | /* bss selection makes no sense if bssid is set */ |
| 8933 | if (connect.bssid) { |
| 8934 | kzfree(connkeys); |
| 8935 | return -EINVAL; |
| 8936 | } |
| 8937 | |
| 8938 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], |
| 8939 | wiphy, &connect.bss_select); |
| 8940 | if (err) { |
| 8941 | kzfree(connkeys); |
| 8942 | return err; |
| 8943 | } |
| 8944 | } |
| 8945 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 8946 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 8947 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 8948 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && |
| 8949 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && |
| 8950 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && |
| 8951 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 8952 | connect.fils_erp_username = |
| 8953 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 8954 | connect.fils_erp_username_len = |
| 8955 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 8956 | connect.fils_erp_realm = |
| 8957 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 8958 | connect.fils_erp_realm_len = |
| 8959 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 8960 | connect.fils_erp_next_seq_num = |
| 8961 | nla_get_u16( |
| 8962 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); |
| 8963 | connect.fils_erp_rrk = |
| 8964 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 8965 | connect.fils_erp_rrk_len = |
| 8966 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 8967 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || |
| 8968 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || |
| 8969 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || |
| 8970 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 8971 | kzfree(connkeys); |
| 8972 | return -EINVAL; |
| 8973 | } |
| 8974 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 8975 | wdev_lock(dev->ieee80211_ptr); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 8976 | |
Jouni Malinen | 4ce2bd9c4 | 2016-03-29 13:53:28 +0300 | [diff] [blame] | 8977 | err = cfg80211_connect(rdev, dev, &connect, connkeys, |
| 8978 | connect.prev_bssid); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 8979 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 8980 | kzfree(connkeys); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 8981 | |
| 8982 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 8983 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 8984 | if (connect.bssid) |
| 8985 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 8986 | connect.bssid, ETH_ALEN); |
| 8987 | else |
| 8988 | memset(dev->ieee80211_ptr->disconnect_bssid, |
| 8989 | 0, ETH_ALEN); |
| 8990 | } |
| 8991 | |
| 8992 | wdev_unlock(dev->ieee80211_ptr); |
| 8993 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 8994 | return err; |
| 8995 | } |
| 8996 | |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 8997 | static int nl80211_update_connect_params(struct sk_buff *skb, |
| 8998 | struct genl_info *info) |
| 8999 | { |
| 9000 | struct cfg80211_connect_params connect = {}; |
| 9001 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9002 | struct net_device *dev = info->user_ptr[1]; |
| 9003 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9004 | u32 changed = 0; |
| 9005 | int ret; |
| 9006 | |
| 9007 | if (!rdev->ops->update_connect_params) |
| 9008 | return -EOPNOTSUPP; |
| 9009 | |
| 9010 | if (info->attrs[NL80211_ATTR_IE]) { |
| 9011 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 9012 | return -EINVAL; |
| 9013 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9014 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9015 | changed |= UPDATE_ASSOC_IES; |
| 9016 | } |
| 9017 | |
| 9018 | wdev_lock(dev->ieee80211_ptr); |
| 9019 | if (!wdev->current_bss) |
| 9020 | ret = -ENOLINK; |
| 9021 | else |
| 9022 | ret = rdev_update_connect_params(rdev, dev, &connect, changed); |
| 9023 | wdev_unlock(dev->ieee80211_ptr); |
| 9024 | |
| 9025 | return ret; |
| 9026 | } |
| 9027 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9028 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 9029 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9030 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9031 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9032 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9033 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9034 | |
| 9035 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 9036 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 9037 | else |
| 9038 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 9039 | |
| 9040 | if (reason == 0) |
| 9041 | return -EINVAL; |
| 9042 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9043 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9044 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9045 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9046 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9047 | wdev_lock(dev->ieee80211_ptr); |
| 9048 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 9049 | wdev_unlock(dev->ieee80211_ptr); |
| 9050 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9051 | } |
| 9052 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9053 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 9054 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9055 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9056 | struct net *net; |
| 9057 | int err; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9058 | |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 9059 | if (info->attrs[NL80211_ATTR_PID]) { |
| 9060 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 9061 | |
| 9062 | net = get_net_ns_by_pid(pid); |
| 9063 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { |
| 9064 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); |
| 9065 | |
| 9066 | net = get_net_ns_by_fd(fd); |
| 9067 | } else { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9068 | return -EINVAL; |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 9069 | } |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9070 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9071 | if (IS_ERR(net)) |
| 9072 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9073 | |
| 9074 | err = 0; |
| 9075 | |
| 9076 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9077 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 9078 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9079 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9080 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9081 | return err; |
| 9082 | } |
| 9083 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9084 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 9085 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9086 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9087 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 9088 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9089 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9090 | struct cfg80211_pmksa pmksa; |
| 9091 | |
| 9092 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 9093 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9094 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 9095 | return -EINVAL; |
| 9096 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9097 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 9098 | |
| 9099 | if (info->attrs[NL80211_ATTR_MAC]) { |
| 9100 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9101 | } else if (info->attrs[NL80211_ATTR_SSID] && |
| 9102 | info->attrs[NL80211_ATTR_FILS_CACHE_ID] && |
| 9103 | (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA || |
| 9104 | info->attrs[NL80211_ATTR_PMK])) { |
| 9105 | pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 9106 | pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 9107 | pmksa.cache_id = |
| 9108 | nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]); |
| 9109 | } else { |
| 9110 | return -EINVAL; |
| 9111 | } |
| 9112 | if (info->attrs[NL80211_ATTR_PMK]) { |
| 9113 | pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 9114 | pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); |
| 9115 | } |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9116 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9117 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9118 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9119 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9120 | |
| 9121 | switch (info->genlhdr->cmd) { |
| 9122 | case NL80211_CMD_SET_PMKSA: |
| 9123 | rdev_ops = rdev->ops->set_pmksa; |
| 9124 | break; |
| 9125 | case NL80211_CMD_DEL_PMKSA: |
| 9126 | rdev_ops = rdev->ops->del_pmksa; |
| 9127 | break; |
| 9128 | default: |
| 9129 | WARN_ON(1); |
| 9130 | break; |
| 9131 | } |
| 9132 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9133 | if (!rdev_ops) |
| 9134 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9135 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9136 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9137 | } |
| 9138 | |
| 9139 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 9140 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9141 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9142 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9143 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9144 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9145 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9146 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9147 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9148 | if (!rdev->ops->flush_pmksa) |
| 9149 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9150 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9151 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9152 | } |
| 9153 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9154 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 9155 | { |
| 9156 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9157 | struct net_device *dev = info->user_ptr[1]; |
| 9158 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 9159 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9160 | u16 status_code; |
| 9161 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 9162 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9163 | |
| 9164 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 9165 | !rdev->ops->tdls_mgmt) |
| 9166 | return -EOPNOTSUPP; |
| 9167 | |
| 9168 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 9169 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 9170 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 9171 | !info->attrs[NL80211_ATTR_IE] || |
| 9172 | !info->attrs[NL80211_ATTR_MAC]) |
| 9173 | return -EINVAL; |
| 9174 | |
| 9175 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9176 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 9177 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 9178 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 9179 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 9180 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 9181 | peer_capability = |
| 9182 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9183 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9184 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 9185 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 9186 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9187 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 9188 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9189 | } |
| 9190 | |
| 9191 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 9192 | { |
| 9193 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9194 | struct net_device *dev = info->user_ptr[1]; |
| 9195 | enum nl80211_tdls_operation operation; |
| 9196 | u8 *peer; |
| 9197 | |
| 9198 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 9199 | !rdev->ops->tdls_oper) |
| 9200 | return -EOPNOTSUPP; |
| 9201 | |
| 9202 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 9203 | !info->attrs[NL80211_ATTR_MAC]) |
| 9204 | return -EINVAL; |
| 9205 | |
| 9206 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 9207 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9208 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9209 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 9210 | } |
| 9211 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9212 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 9213 | struct genl_info *info) |
| 9214 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9215 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9216 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9217 | struct cfg80211_chan_def chandef; |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 9218 | const struct cfg80211_chan_def *compat_chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9219 | struct sk_buff *msg; |
| 9220 | void *hdr; |
| 9221 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9222 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9223 | int err; |
| 9224 | |
| 9225 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 9226 | !info->attrs[NL80211_ATTR_DURATION]) |
| 9227 | return -EINVAL; |
| 9228 | |
| 9229 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 9230 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 9231 | if (!rdev->ops->remain_on_channel || |
| 9232 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9233 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9234 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 9235 | /* |
| 9236 | * We should be on that channel for at least a minimum amount of |
| 9237 | * time (10ms) but no longer than the driver supports. |
| 9238 | */ |
| 9239 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 9240 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 9241 | return -EINVAL; |
| 9242 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9243 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 9244 | if (err) |
| 9245 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9246 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 9247 | wdev_lock(wdev); |
| 9248 | if (!cfg80211_off_channel_oper_allowed(wdev) && |
| 9249 | !cfg80211_chandef_identical(&wdev->chandef, &chandef)) { |
| 9250 | compat_chandef = cfg80211_chandef_compatible(&wdev->chandef, |
| 9251 | &chandef); |
| 9252 | if (compat_chandef != &chandef) { |
| 9253 | wdev_unlock(wdev); |
| 9254 | return -EBUSY; |
| 9255 | } |
| 9256 | } |
| 9257 | wdev_unlock(wdev); |
| 9258 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9259 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9260 | if (!msg) |
| 9261 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9262 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9263 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9264 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9265 | if (!hdr) { |
| 9266 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9267 | goto free_msg; |
| 9268 | } |
| 9269 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9270 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 9271 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9272 | |
| 9273 | if (err) |
| 9274 | goto free_msg; |
| 9275 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9276 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 9277 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9278 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9279 | |
| 9280 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9281 | |
| 9282 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9283 | |
| 9284 | nla_put_failure: |
| 9285 | err = -ENOBUFS; |
| 9286 | free_msg: |
| 9287 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9288 | return err; |
| 9289 | } |
| 9290 | |
| 9291 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 9292 | struct genl_info *info) |
| 9293 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9294 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9295 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9296 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9297 | |
| 9298 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 9299 | return -EINVAL; |
| 9300 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9301 | if (!rdev->ops->cancel_remain_on_channel) |
| 9302 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9303 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9304 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 9305 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9306 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9307 | } |
| 9308 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9309 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 9310 | struct genl_info *info) |
| 9311 | { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9312 | struct cfg80211_bitrate_mask mask; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 9313 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9314 | struct net_device *dev = info->user_ptr[1]; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 9315 | int err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9316 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9317 | if (!rdev->ops->set_bitrate_mask) |
| 9318 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9319 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 9320 | err = nl80211_parse_tx_bitrate_mask(info, &mask); |
| 9321 | if (err) |
| 9322 | return err; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 9323 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9324 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9325 | } |
| 9326 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9327 | 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] | 9328 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9329 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9330 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9331 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9332 | |
| 9333 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 9334 | return -EINVAL; |
| 9335 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9336 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 9337 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9338 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9339 | switch (wdev->iftype) { |
| 9340 | case NL80211_IFTYPE_STATION: |
| 9341 | case NL80211_IFTYPE_ADHOC: |
| 9342 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9343 | case NL80211_IFTYPE_AP: |
| 9344 | case NL80211_IFTYPE_AP_VLAN: |
| 9345 | case NL80211_IFTYPE_MESH_POINT: |
| 9346 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9347 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9348 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 9349 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9350 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9351 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9352 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9353 | |
| 9354 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9355 | if (!rdev->ops->mgmt_tx) |
| 9356 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9357 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9358 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9359 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 9360 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9361 | } |
| 9362 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9363 | 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] | 9364 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9365 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9366 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9367 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9368 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 9369 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9370 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9371 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9372 | struct cfg80211_mgmt_tx_params params = { |
| 9373 | .dont_wait_for_ack = |
| 9374 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 9375 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9376 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9377 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9378 | return -EINVAL; |
| 9379 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9380 | if (!rdev->ops->mgmt_tx) |
| 9381 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9382 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9383 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 9384 | case NL80211_IFTYPE_P2P_DEVICE: |
| 9385 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 9386 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9387 | case NL80211_IFTYPE_STATION: |
| 9388 | case NL80211_IFTYPE_ADHOC: |
| 9389 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9390 | case NL80211_IFTYPE_AP: |
| 9391 | case NL80211_IFTYPE_AP_VLAN: |
| 9392 | case NL80211_IFTYPE_MESH_POINT: |
| 9393 | case NL80211_IFTYPE_P2P_GO: |
| 9394 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 9395 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9396 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9397 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9398 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9399 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9400 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 9401 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9402 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9403 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 9404 | |
| 9405 | /* |
| 9406 | * We should wait on the channel for at least a minimum amount |
| 9407 | * of time (10ms) but no longer than the driver supports. |
| 9408 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9409 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 9410 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 9411 | return -EINVAL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9412 | } |
| 9413 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9414 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9415 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9416 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 9417 | return -EINVAL; |
| 9418 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9419 | 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] | 9420 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 9421 | /* get the channel if any has been specified, otherwise pass NULL to |
| 9422 | * the driver. The latter will use the current one |
| 9423 | */ |
| 9424 | chandef.chan = NULL; |
| 9425 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 9426 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 9427 | if (err) |
| 9428 | return err; |
| 9429 | } |
| 9430 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9431 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 9432 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9433 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 9434 | wdev_lock(wdev); |
| 9435 | if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) { |
| 9436 | wdev_unlock(wdev); |
| 9437 | return -EBUSY; |
| 9438 | } |
| 9439 | wdev_unlock(wdev); |
| 9440 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 9441 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 9442 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 9443 | |
| 9444 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 9445 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 9446 | int i; |
| 9447 | |
| 9448 | if (len % sizeof(u16)) |
| 9449 | return -EINVAL; |
| 9450 | |
| 9451 | params.n_csa_offsets = len / sizeof(u16); |
| 9452 | params.csa_offsets = |
| 9453 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 9454 | |
| 9455 | /* check that all the offsets fit the frame */ |
| 9456 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 9457 | if (params.csa_offsets[i] >= params.len) |
| 9458 | return -EINVAL; |
| 9459 | } |
| 9460 | } |
| 9461 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9462 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9463 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9464 | if (!msg) |
| 9465 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9466 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9467 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9468 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9469 | if (!hdr) { |
| 9470 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9471 | goto free_msg; |
| 9472 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9473 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9474 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 9475 | params.chan = chandef.chan; |
| 9476 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9477 | if (err) |
| 9478 | goto free_msg; |
| 9479 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9480 | if (msg) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9481 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 9482 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9483 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9484 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 9485 | genlmsg_end(msg, hdr); |
| 9486 | return genlmsg_reply(msg, info); |
| 9487 | } |
| 9488 | |
| 9489 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9490 | |
| 9491 | nla_put_failure: |
| 9492 | err = -ENOBUFS; |
| 9493 | free_msg: |
| 9494 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9495 | return err; |
| 9496 | } |
| 9497 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9498 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 9499 | { |
| 9500 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9501 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9502 | u64 cookie; |
| 9503 | |
| 9504 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 9505 | return -EINVAL; |
| 9506 | |
| 9507 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 9508 | return -EOPNOTSUPP; |
| 9509 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9510 | switch (wdev->iftype) { |
| 9511 | case NL80211_IFTYPE_STATION: |
| 9512 | case NL80211_IFTYPE_ADHOC: |
| 9513 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9514 | case NL80211_IFTYPE_AP: |
| 9515 | case NL80211_IFTYPE_AP_VLAN: |
| 9516 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9517 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9518 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 9519 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9520 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9521 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9522 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9523 | |
| 9524 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 9525 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9526 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9527 | } |
| 9528 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9529 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 9530 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9531 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9532 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9533 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9534 | u8 ps_state; |
| 9535 | bool state; |
| 9536 | int err; |
| 9537 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9538 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 9539 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9540 | |
| 9541 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 9542 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9543 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 9544 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9545 | |
| 9546 | wdev = dev->ieee80211_ptr; |
| 9547 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9548 | if (!rdev->ops->set_power_mgmt) |
| 9549 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9550 | |
| 9551 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 9552 | |
| 9553 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9554 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9555 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9556 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9557 | if (!err) |
| 9558 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9559 | return err; |
| 9560 | } |
| 9561 | |
| 9562 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 9563 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9564 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9565 | enum nl80211_ps_state ps_state; |
| 9566 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9567 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9568 | struct sk_buff *msg; |
| 9569 | void *hdr; |
| 9570 | int err; |
| 9571 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9572 | wdev = dev->ieee80211_ptr; |
| 9573 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9574 | if (!rdev->ops->set_power_mgmt) |
| 9575 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9576 | |
| 9577 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9578 | if (!msg) |
| 9579 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9580 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9581 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9582 | NL80211_CMD_GET_POWER_SAVE); |
| 9583 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9584 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9585 | goto free_msg; |
| 9586 | } |
| 9587 | |
| 9588 | if (wdev->ps) |
| 9589 | ps_state = NL80211_PS_ENABLED; |
| 9590 | else |
| 9591 | ps_state = NL80211_PS_DISABLED; |
| 9592 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9593 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 9594 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9595 | |
| 9596 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9597 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9598 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9599 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9600 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9601 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9602 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9603 | return err; |
| 9604 | } |
| 9605 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 9606 | static const struct nla_policy |
| 9607 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9608 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9609 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 9610 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9611 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 9612 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 9613 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 9614 | [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9615 | }; |
| 9616 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9617 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 9618 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9619 | { |
| 9620 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9621 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9622 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9623 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 9624 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9625 | return -EINVAL; |
| 9626 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9627 | if (!rdev->ops->set_cqm_txe_config) |
| 9628 | return -EOPNOTSUPP; |
| 9629 | |
| 9630 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 9631 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9632 | return -EOPNOTSUPP; |
| 9633 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9634 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 9635 | } |
| 9636 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9637 | static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, |
| 9638 | struct net_device *dev) |
| 9639 | { |
| 9640 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9641 | s32 last, low, high; |
| 9642 | u32 hyst; |
| 9643 | int i, n; |
| 9644 | int err; |
| 9645 | |
| 9646 | /* RSSI reporting disabled? */ |
| 9647 | if (!wdev->cqm_config) |
| 9648 | return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0); |
| 9649 | |
| 9650 | /* |
| 9651 | * Obtain current RSSI value if possible, if not and no RSSI threshold |
| 9652 | * event has been received yet, we should receive an event after a |
| 9653 | * connection is established and enough beacons received to calculate |
| 9654 | * the average. |
| 9655 | */ |
| 9656 | if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss && |
| 9657 | rdev->ops->get_station) { |
| 9658 | struct station_info sinfo; |
| 9659 | u8 *mac_addr; |
| 9660 | |
| 9661 | mac_addr = wdev->current_bss->pub.bssid; |
| 9662 | |
| 9663 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
| 9664 | if (err) |
| 9665 | return err; |
| 9666 | |
| 9667 | if (sinfo.filled & BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG)) |
| 9668 | wdev->cqm_config->last_rssi_event_value = |
| 9669 | (s8) sinfo.rx_beacon_signal_avg; |
| 9670 | } |
| 9671 | |
| 9672 | last = wdev->cqm_config->last_rssi_event_value; |
| 9673 | hyst = wdev->cqm_config->rssi_hyst; |
| 9674 | n = wdev->cqm_config->n_rssi_thresholds; |
| 9675 | |
| 9676 | for (i = 0; i < n; i++) |
| 9677 | if (last < wdev->cqm_config->rssi_thresholds[i]) |
| 9678 | break; |
| 9679 | |
| 9680 | low = i > 0 ? |
| 9681 | (wdev->cqm_config->rssi_thresholds[i - 1] - hyst) : S32_MIN; |
| 9682 | high = i < n ? |
| 9683 | (wdev->cqm_config->rssi_thresholds[i] + hyst - 1) : S32_MAX; |
| 9684 | |
| 9685 | return rdev_set_cqm_rssi_range_config(rdev, dev, low, high); |
| 9686 | } |
| 9687 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9688 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9689 | const s32 *thresholds, int n_thresholds, |
| 9690 | u32 hysteresis) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9691 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9692 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9693 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9694 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9695 | int i, err; |
| 9696 | s32 prev = S32_MIN; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9697 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9698 | /* Check all values negative and sorted */ |
| 9699 | for (i = 0; i < n_thresholds; i++) { |
| 9700 | if (thresholds[i] > 0 || thresholds[i] <= prev) |
| 9701 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9702 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9703 | prev = thresholds[i]; |
| 9704 | } |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9705 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9706 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9707 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9708 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9709 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9710 | wdev_lock(wdev); |
| 9711 | cfg80211_cqm_config_free(wdev); |
| 9712 | wdev_unlock(wdev); |
| 9713 | |
| 9714 | if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) { |
| 9715 | if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */ |
| 9716 | return rdev_set_cqm_rssi_config(rdev, dev, 0, 0); |
| 9717 | |
| 9718 | return rdev_set_cqm_rssi_config(rdev, dev, |
| 9719 | thresholds[0], hysteresis); |
| 9720 | } |
| 9721 | |
| 9722 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 9723 | NL80211_EXT_FEATURE_CQM_RSSI_LIST)) |
| 9724 | return -EOPNOTSUPP; |
| 9725 | |
| 9726 | if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */ |
| 9727 | n_thresholds = 0; |
| 9728 | |
| 9729 | wdev_lock(wdev); |
| 9730 | if (n_thresholds) { |
| 9731 | struct cfg80211_cqm_config *cqm_config; |
| 9732 | |
| 9733 | cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) + |
| 9734 | n_thresholds * sizeof(s32), GFP_KERNEL); |
| 9735 | if (!cqm_config) { |
| 9736 | err = -ENOMEM; |
| 9737 | goto unlock; |
| 9738 | } |
| 9739 | |
| 9740 | cqm_config->rssi_hyst = hysteresis; |
| 9741 | cqm_config->n_rssi_thresholds = n_thresholds; |
| 9742 | memcpy(cqm_config->rssi_thresholds, thresholds, |
| 9743 | n_thresholds * sizeof(s32)); |
| 9744 | |
| 9745 | wdev->cqm_config = cqm_config; |
| 9746 | } |
| 9747 | |
| 9748 | err = cfg80211_cqm_rssi_update(rdev, dev); |
| 9749 | |
| 9750 | unlock: |
| 9751 | wdev_unlock(wdev); |
| 9752 | |
| 9753 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9754 | } |
| 9755 | |
| 9756 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 9757 | { |
| 9758 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 9759 | struct nlattr *cqm; |
| 9760 | int err; |
| 9761 | |
| 9762 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9763 | if (!cqm) |
| 9764 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9765 | |
| 9766 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 9767 | nl80211_attr_cqm_policy); |
| 9768 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9769 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9770 | |
| 9771 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 9772 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9773 | const s32 *thresholds = |
| 9774 | nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 9775 | int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9776 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9777 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 9778 | if (len % 4) |
| 9779 | return -EINVAL; |
| 9780 | |
| 9781 | return nl80211_set_cqm_rssi(info, thresholds, len / 4, |
| 9782 | hysteresis); |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 9783 | } |
| 9784 | |
| 9785 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 9786 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 9787 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 9788 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 9789 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 9790 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 9791 | |
| 9792 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 9793 | } |
| 9794 | |
| 9795 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 9796 | } |
| 9797 | |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 9798 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 9799 | { |
| 9800 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9801 | struct net_device *dev = info->user_ptr[1]; |
| 9802 | struct ocb_setup setup = {}; |
| 9803 | int err; |
| 9804 | |
| 9805 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 9806 | if (err) |
| 9807 | return err; |
| 9808 | |
| 9809 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 9810 | } |
| 9811 | |
| 9812 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 9813 | { |
| 9814 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9815 | struct net_device *dev = info->user_ptr[1]; |
| 9816 | |
| 9817 | return cfg80211_leave_ocb(rdev, dev); |
| 9818 | } |
| 9819 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9820 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 9821 | { |
| 9822 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9823 | struct net_device *dev = info->user_ptr[1]; |
| 9824 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9825 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9826 | int err; |
| 9827 | |
| 9828 | /* start with default */ |
| 9829 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9830 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9831 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9832 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9833 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9834 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9835 | if (err) |
| 9836 | return err; |
| 9837 | } |
| 9838 | |
| 9839 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 9840 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 9841 | return -EINVAL; |
| 9842 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9843 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 9844 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 9845 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 9846 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 9847 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 9848 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 9849 | return -EINVAL; |
| 9850 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 9851 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 9852 | setup.beacon_interval = |
| 9853 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 9854 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 9855 | err = cfg80211_validate_beacon_int(rdev, |
| 9856 | NL80211_IFTYPE_MESH_POINT, |
| 9857 | setup.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 9858 | if (err) |
| 9859 | return err; |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 9860 | } |
| 9861 | |
| 9862 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 9863 | setup.dtim_period = |
| 9864 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 9865 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 9866 | return -EINVAL; |
| 9867 | } |
| 9868 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9869 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 9870 | /* parse additional setup parameters if given */ |
| 9871 | err = nl80211_parse_mesh_setup(info, &setup); |
| 9872 | if (err) |
| 9873 | return err; |
| 9874 | } |
| 9875 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 9876 | if (setup.user_mpm) |
| 9877 | cfg.auto_open_plinks = false; |
| 9878 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9879 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9880 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 9881 | if (err) |
| 9882 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9883 | } else { |
| 9884 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9885 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 9886 | } |
| 9887 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 9888 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 9889 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 9890 | int n_rates = |
| 9891 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 9892 | struct ieee80211_supported_band *sband; |
| 9893 | |
| 9894 | if (!setup.chandef.chan) |
| 9895 | return -EINVAL; |
| 9896 | |
| 9897 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 9898 | |
| 9899 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 9900 | &setup.basic_rates); |
| 9901 | if (err) |
| 9902 | return err; |
| 9903 | } |
| 9904 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 9905 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
| 9906 | err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate); |
| 9907 | if (err) |
| 9908 | return err; |
| 9909 | |
| 9910 | err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, |
| 9911 | &setup.beacon_rate); |
| 9912 | if (err) |
| 9913 | return err; |
| 9914 | } |
| 9915 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 9916 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9917 | } |
| 9918 | |
| 9919 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 9920 | { |
| 9921 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9922 | struct net_device *dev = info->user_ptr[1]; |
| 9923 | |
| 9924 | return cfg80211_leave_mesh(rdev, dev); |
| 9925 | } |
| 9926 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9927 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9928 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 9929 | struct cfg80211_registered_device *rdev) |
| 9930 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9931 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9932 | struct nlattr *nl_pats, *nl_pat; |
| 9933 | int i, pat_len; |
| 9934 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9935 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9936 | return 0; |
| 9937 | |
| 9938 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 9939 | if (!nl_pats) |
| 9940 | return -ENOBUFS; |
| 9941 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9942 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9943 | nl_pat = nla_nest_start(msg, i + 1); |
| 9944 | if (!nl_pat) |
| 9945 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9946 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9947 | 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] | 9948 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9949 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 9950 | wowlan->patterns[i].pattern) || |
| 9951 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9952 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9953 | return -ENOBUFS; |
| 9954 | nla_nest_end(msg, nl_pat); |
| 9955 | } |
| 9956 | nla_nest_end(msg, nl_pats); |
| 9957 | |
| 9958 | return 0; |
| 9959 | } |
| 9960 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9961 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 9962 | struct cfg80211_wowlan_tcp *tcp) |
| 9963 | { |
| 9964 | struct nlattr *nl_tcp; |
| 9965 | |
| 9966 | if (!tcp) |
| 9967 | return 0; |
| 9968 | |
| 9969 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 9970 | if (!nl_tcp) |
| 9971 | return -ENOBUFS; |
| 9972 | |
Jiri Benc | 930345e | 2015-03-29 16:59:25 +0200 | [diff] [blame] | 9973 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 9974 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9975 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 9976 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 9977 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 9978 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 9979 | tcp->payload_len, tcp->payload) || |
| 9980 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 9981 | tcp->data_interval) || |
| 9982 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 9983 | tcp->wake_len, tcp->wake_data) || |
| 9984 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 9985 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 9986 | return -ENOBUFS; |
| 9987 | |
| 9988 | if (tcp->payload_seq.len && |
| 9989 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 9990 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 9991 | return -ENOBUFS; |
| 9992 | |
| 9993 | if (tcp->payload_tok.len && |
| 9994 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 9995 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 9996 | &tcp->payload_tok)) |
| 9997 | return -ENOBUFS; |
| 9998 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 9999 | nla_nest_end(msg, nl_tcp); |
| 10000 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10001 | return 0; |
| 10002 | } |
| 10003 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10004 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
| 10005 | struct cfg80211_sched_scan_request *req) |
| 10006 | { |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 10007 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10008 | int i; |
| 10009 | |
| 10010 | if (!req) |
| 10011 | return 0; |
| 10012 | |
| 10013 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); |
| 10014 | if (!nd) |
| 10015 | return -ENOBUFS; |
| 10016 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 10017 | if (req->n_scan_plans == 1 && |
| 10018 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, |
| 10019 | req->scan_plans[0].interval * 1000)) |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10020 | return -ENOBUFS; |
| 10021 | |
Luciano Coelho | 21fea56 | 2015-03-17 16:36:01 +0200 | [diff] [blame] | 10022 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
| 10023 | return -ENOBUFS; |
| 10024 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 10025 | if (req->relative_rssi_set) { |
| 10026 | struct nl80211_bss_select_rssi_adjust rssi_adjust; |
| 10027 | |
| 10028 | if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI, |
| 10029 | req->relative_rssi)) |
| 10030 | return -ENOBUFS; |
| 10031 | |
| 10032 | rssi_adjust.band = req->rssi_adjust.band; |
| 10033 | rssi_adjust.delta = req->rssi_adjust.delta; |
| 10034 | if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST, |
| 10035 | sizeof(rssi_adjust), &rssi_adjust)) |
| 10036 | return -ENOBUFS; |
| 10037 | } |
| 10038 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10039 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 10040 | if (!freqs) |
| 10041 | return -ENOBUFS; |
| 10042 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 10043 | for (i = 0; i < req->n_channels; i++) { |
| 10044 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 10045 | return -ENOBUFS; |
| 10046 | } |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10047 | |
| 10048 | nla_nest_end(msg, freqs); |
| 10049 | |
| 10050 | if (req->n_match_sets) { |
| 10051 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 10052 | if (!matches) |
| 10053 | return -ENOBUFS; |
| 10054 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10055 | for (i = 0; i < req->n_match_sets; i++) { |
| 10056 | match = nla_nest_start(msg, i); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 10057 | if (!match) |
| 10058 | return -ENOBUFS; |
| 10059 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 10060 | if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
| 10061 | req->match_sets[i].ssid.ssid_len, |
| 10062 | req->match_sets[i].ssid.ssid)) |
| 10063 | return -ENOBUFS; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10064 | nla_nest_end(msg, match); |
| 10065 | } |
| 10066 | nla_nest_end(msg, matches); |
| 10067 | } |
| 10068 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 10069 | scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
| 10070 | if (!scan_plans) |
| 10071 | return -ENOBUFS; |
| 10072 | |
| 10073 | for (i = 0; i < req->n_scan_plans; i++) { |
| 10074 | scan_plan = nla_nest_start(msg, i + 1); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 10075 | if (!scan_plan) |
| 10076 | return -ENOBUFS; |
| 10077 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 10078 | if (!scan_plan || |
| 10079 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, |
| 10080 | req->scan_plans[i].interval) || |
| 10081 | (req->scan_plans[i].iterations && |
| 10082 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, |
| 10083 | req->scan_plans[i].iterations))) |
| 10084 | return -ENOBUFS; |
| 10085 | nla_nest_end(msg, scan_plan); |
| 10086 | } |
| 10087 | nla_nest_end(msg, scan_plans); |
| 10088 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10089 | nla_nest_end(msg, nd); |
| 10090 | |
| 10091 | return 0; |
| 10092 | } |
| 10093 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10094 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 10095 | { |
| 10096 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10097 | struct sk_buff *msg; |
| 10098 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10099 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10100 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10101 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10102 | return -EOPNOTSUPP; |
| 10103 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10104 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10105 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10106 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 10107 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 10108 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 10109 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10110 | } |
| 10111 | |
| 10112 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10113 | if (!msg) |
| 10114 | return -ENOMEM; |
| 10115 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10116 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10117 | NL80211_CMD_GET_WOWLAN); |
| 10118 | if (!hdr) |
| 10119 | goto nla_put_failure; |
| 10120 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10121 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10122 | struct nlattr *nl_wowlan; |
| 10123 | |
| 10124 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 10125 | if (!nl_wowlan) |
| 10126 | goto nla_put_failure; |
| 10127 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10128 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10129 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10130 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10131 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10132 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10133 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10134 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10135 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10136 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10137 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10138 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10139 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10140 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10141 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 10142 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10143 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10144 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 10145 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10146 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10147 | if (nl80211_send_wowlan_tcp(msg, |
| 10148 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10149 | goto nla_put_failure; |
| 10150 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 10151 | if (nl80211_send_wowlan_nd( |
| 10152 | msg, |
| 10153 | rdev->wiphy.wowlan_config->nd_config)) |
| 10154 | goto nla_put_failure; |
| 10155 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10156 | nla_nest_end(msg, nl_wowlan); |
| 10157 | } |
| 10158 | |
| 10159 | genlmsg_end(msg, hdr); |
| 10160 | return genlmsg_reply(msg, info); |
| 10161 | |
| 10162 | nla_put_failure: |
| 10163 | nlmsg_free(msg); |
| 10164 | return -ENOBUFS; |
| 10165 | } |
| 10166 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10167 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 10168 | struct nlattr *attr, |
| 10169 | struct cfg80211_wowlan *trig) |
| 10170 | { |
| 10171 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 10172 | struct cfg80211_wowlan_tcp *cfg; |
| 10173 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 10174 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 10175 | u32 size; |
| 10176 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 10177 | int err, port; |
| 10178 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10179 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10180 | return -EINVAL; |
| 10181 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10182 | err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TCP, attr, |
| 10183 | nl80211_wowlan_tcp_policy); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10184 | if (err) |
| 10185 | return err; |
| 10186 | |
| 10187 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 10188 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 10189 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 10190 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 10191 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 10192 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 10193 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 10194 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 10195 | return -EINVAL; |
| 10196 | |
| 10197 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10198 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10199 | return -EINVAL; |
| 10200 | |
| 10201 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10202 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 10203 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10204 | return -EINVAL; |
| 10205 | |
| 10206 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10207 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10208 | return -EINVAL; |
| 10209 | |
| 10210 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 10211 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 10212 | return -EINVAL; |
| 10213 | |
| 10214 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 10215 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 10216 | |
| 10217 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 10218 | tokens_size = tokln - sizeof(*tok); |
| 10219 | |
| 10220 | if (!tok->len || tokens_size % tok->len) |
| 10221 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10222 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10223 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10224 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10225 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10226 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10227 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10228 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10229 | return -EINVAL; |
| 10230 | if (tok->offset + tok->len > data_size) |
| 10231 | return -EINVAL; |
| 10232 | } |
| 10233 | |
| 10234 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 10235 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10236 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10237 | return -EINVAL; |
| 10238 | if (seq->len == 0 || seq->len > 4) |
| 10239 | return -EINVAL; |
| 10240 | if (seq->len + seq->offset > data_size) |
| 10241 | return -EINVAL; |
| 10242 | } |
| 10243 | |
| 10244 | size = sizeof(*cfg); |
| 10245 | size += data_size; |
| 10246 | size += wake_size + wake_mask_size; |
| 10247 | size += tokens_size; |
| 10248 | |
| 10249 | cfg = kzalloc(size, GFP_KERNEL); |
| 10250 | if (!cfg) |
| 10251 | return -ENOMEM; |
Jiri Benc | 67b61f6 | 2015-03-29 16:59:26 +0200 | [diff] [blame] | 10252 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 10253 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10254 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 10255 | ETH_ALEN); |
| 10256 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 10257 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 10258 | else |
| 10259 | port = 0; |
| 10260 | #ifdef CONFIG_INET |
| 10261 | /* allocate a socket and port for it and use it */ |
| 10262 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 10263 | IPPROTO_TCP, &cfg->sock, 1); |
| 10264 | if (err) { |
| 10265 | kfree(cfg); |
| 10266 | return err; |
| 10267 | } |
| 10268 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 10269 | sock_release(cfg->sock); |
| 10270 | kfree(cfg); |
| 10271 | return -EADDRINUSE; |
| 10272 | } |
| 10273 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 10274 | #else |
| 10275 | if (!port) { |
| 10276 | kfree(cfg); |
| 10277 | return -EINVAL; |
| 10278 | } |
| 10279 | cfg->src_port = port; |
| 10280 | #endif |
| 10281 | |
| 10282 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 10283 | cfg->payload_len = data_size; |
| 10284 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 10285 | memcpy((void *)cfg->payload, |
| 10286 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 10287 | data_size); |
| 10288 | if (seq) |
| 10289 | cfg->payload_seq = *seq; |
| 10290 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 10291 | cfg->wake_len = wake_size; |
| 10292 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 10293 | memcpy((void *)cfg->wake_data, |
| 10294 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 10295 | wake_size); |
| 10296 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 10297 | data_size + wake_size; |
| 10298 | memcpy((void *)cfg->wake_mask, |
| 10299 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 10300 | wake_mask_size); |
| 10301 | if (tok) { |
| 10302 | cfg->tokens_size = tokens_size; |
| 10303 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 10304 | } |
| 10305 | |
| 10306 | trig->tcp = cfg; |
| 10307 | |
| 10308 | return 0; |
| 10309 | } |
| 10310 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10311 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
| 10312 | const struct wiphy_wowlan_support *wowlan, |
| 10313 | struct nlattr *attr, |
| 10314 | struct cfg80211_wowlan *trig) |
| 10315 | { |
| 10316 | struct nlattr **tb; |
| 10317 | int err; |
| 10318 | |
| 10319 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); |
| 10320 | if (!tb) |
| 10321 | return -ENOMEM; |
| 10322 | |
| 10323 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { |
| 10324 | err = -EOPNOTSUPP; |
| 10325 | goto out; |
| 10326 | } |
| 10327 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10328 | err = nla_parse_nested(tb, NL80211_ATTR_MAX, attr, nl80211_policy); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10329 | if (err) |
| 10330 | goto out; |
| 10331 | |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 10332 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb, |
| 10333 | wowlan->max_nd_match_sets); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10334 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
| 10335 | if (err) |
| 10336 | trig->nd_config = NULL; |
| 10337 | |
| 10338 | out: |
| 10339 | kfree(tb); |
| 10340 | return err; |
| 10341 | } |
| 10342 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10343 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 10344 | { |
| 10345 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10346 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10347 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10348 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10349 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10350 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10351 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10352 | bool regular = false; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10353 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 10354 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10355 | return -EOPNOTSUPP; |
| 10356 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10357 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 10358 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10359 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10360 | goto set_wakeup; |
| 10361 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10362 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10363 | err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TRIG, |
| 10364 | info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS], |
| 10365 | nl80211_wowlan_policy); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10366 | if (err) |
| 10367 | return err; |
| 10368 | |
| 10369 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 10370 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 10371 | return -EINVAL; |
| 10372 | new_triggers.any = true; |
| 10373 | } |
| 10374 | |
| 10375 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 10376 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 10377 | return -EINVAL; |
| 10378 | new_triggers.disconnect = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10379 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10380 | } |
| 10381 | |
| 10382 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 10383 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 10384 | return -EINVAL; |
| 10385 | new_triggers.magic_pkt = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10386 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10387 | } |
| 10388 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10389 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 10390 | return -EINVAL; |
| 10391 | |
| 10392 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 10393 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 10394 | return -EINVAL; |
| 10395 | new_triggers.gtk_rekey_failure = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10396 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10397 | } |
| 10398 | |
| 10399 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 10400 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 10401 | return -EINVAL; |
| 10402 | new_triggers.eap_identity_req = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10403 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10404 | } |
| 10405 | |
| 10406 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 10407 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 10408 | return -EINVAL; |
| 10409 | new_triggers.four_way_handshake = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10410 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10411 | } |
| 10412 | |
| 10413 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 10414 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 10415 | return -EINVAL; |
| 10416 | new_triggers.rfkill_release = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10417 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 10418 | } |
| 10419 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10420 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 10421 | struct nlattr *pat; |
| 10422 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10423 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10424 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10425 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10426 | regular = true; |
| 10427 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10428 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 10429 | rem) |
| 10430 | n_patterns++; |
| 10431 | if (n_patterns > wowlan->n_patterns) |
| 10432 | return -EINVAL; |
| 10433 | |
| 10434 | new_triggers.patterns = kcalloc(n_patterns, |
| 10435 | sizeof(new_triggers.patterns[0]), |
| 10436 | GFP_KERNEL); |
| 10437 | if (!new_triggers.patterns) |
| 10438 | return -ENOMEM; |
| 10439 | |
| 10440 | new_triggers.n_patterns = n_patterns; |
| 10441 | i = 0; |
| 10442 | |
| 10443 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 10444 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10445 | u8 *mask_pat; |
| 10446 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10447 | nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, |
| 10448 | NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10449 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10450 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 10451 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10452 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10453 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10454 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10455 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10456 | goto error; |
| 10457 | if (pat_len > wowlan->pattern_max_len || |
| 10458 | pat_len < wowlan->pattern_min_len) |
| 10459 | goto error; |
| 10460 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10461 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10462 | pkt_offset = 0; |
| 10463 | else |
| 10464 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10465 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 10466 | if (pkt_offset > wowlan->max_pkt_offset) |
| 10467 | goto error; |
| 10468 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 10469 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10470 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 10471 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10472 | err = -ENOMEM; |
| 10473 | goto error; |
| 10474 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10475 | new_triggers.patterns[i].mask = mask_pat; |
| 10476 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10477 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10478 | mask_pat += mask_len; |
| 10479 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10480 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10481 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 10482 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10483 | pat_len); |
| 10484 | i++; |
| 10485 | } |
| 10486 | } |
| 10487 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10488 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10489 | regular = true; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10490 | err = nl80211_parse_wowlan_tcp( |
| 10491 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 10492 | &new_triggers); |
| 10493 | if (err) |
| 10494 | goto error; |
| 10495 | } |
| 10496 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10497 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10498 | regular = true; |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 10499 | err = nl80211_parse_wowlan_nd( |
| 10500 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], |
| 10501 | &new_triggers); |
| 10502 | if (err) |
| 10503 | goto error; |
| 10504 | } |
| 10505 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 10506 | /* The 'any' trigger means the device continues operating more or less |
| 10507 | * as in its normal operation mode and wakes up the host on most of the |
| 10508 | * normal interrupts (like packet RX, ...) |
| 10509 | * It therefore makes little sense to combine with the more constrained |
| 10510 | * wakeup trigger modes. |
| 10511 | */ |
| 10512 | if (new_triggers.any && regular) { |
| 10513 | err = -EINVAL; |
| 10514 | goto error; |
| 10515 | } |
| 10516 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10517 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 10518 | if (!ntrig) { |
| 10519 | err = -ENOMEM; |
| 10520 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10521 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10522 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10523 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10524 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 10525 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 10526 | if (rdev->ops->set_wakeup && |
| 10527 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 10528 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 10529 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10530 | return 0; |
| 10531 | error: |
| 10532 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 10533 | kfree(new_triggers.patterns[i].mask); |
| 10534 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 10535 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 10536 | sock_release(new_triggers.tcp->sock); |
| 10537 | kfree(new_triggers.tcp); |
Ola Olsson | e5dbe07 | 2015-12-12 23:17:17 +0100 | [diff] [blame] | 10538 | kfree(new_triggers.nd_config); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10539 | return err; |
| 10540 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10541 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10542 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10543 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 10544 | struct cfg80211_registered_device *rdev) |
| 10545 | { |
| 10546 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 10547 | int i, j, pat_len; |
| 10548 | struct cfg80211_coalesce_rules *rule; |
| 10549 | |
| 10550 | if (!rdev->coalesce->n_rules) |
| 10551 | return 0; |
| 10552 | |
| 10553 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 10554 | if (!nl_rules) |
| 10555 | return -ENOBUFS; |
| 10556 | |
| 10557 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 10558 | nl_rule = nla_nest_start(msg, i + 1); |
| 10559 | if (!nl_rule) |
| 10560 | return -ENOBUFS; |
| 10561 | |
| 10562 | rule = &rdev->coalesce->rules[i]; |
| 10563 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 10564 | rule->delay)) |
| 10565 | return -ENOBUFS; |
| 10566 | |
| 10567 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 10568 | rule->condition)) |
| 10569 | return -ENOBUFS; |
| 10570 | |
| 10571 | nl_pats = nla_nest_start(msg, |
| 10572 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 10573 | if (!nl_pats) |
| 10574 | return -ENOBUFS; |
| 10575 | |
| 10576 | for (j = 0; j < rule->n_patterns; j++) { |
| 10577 | nl_pat = nla_nest_start(msg, j + 1); |
| 10578 | if (!nl_pat) |
| 10579 | return -ENOBUFS; |
| 10580 | pat_len = rule->patterns[j].pattern_len; |
| 10581 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 10582 | DIV_ROUND_UP(pat_len, 8), |
| 10583 | rule->patterns[j].mask) || |
| 10584 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 10585 | rule->patterns[j].pattern) || |
| 10586 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 10587 | rule->patterns[j].pkt_offset)) |
| 10588 | return -ENOBUFS; |
| 10589 | nla_nest_end(msg, nl_pat); |
| 10590 | } |
| 10591 | nla_nest_end(msg, nl_pats); |
| 10592 | nla_nest_end(msg, nl_rule); |
| 10593 | } |
| 10594 | nla_nest_end(msg, nl_rules); |
| 10595 | |
| 10596 | return 0; |
| 10597 | } |
| 10598 | |
| 10599 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 10600 | { |
| 10601 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10602 | struct sk_buff *msg; |
| 10603 | void *hdr; |
| 10604 | |
| 10605 | if (!rdev->wiphy.coalesce) |
| 10606 | return -EOPNOTSUPP; |
| 10607 | |
| 10608 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10609 | if (!msg) |
| 10610 | return -ENOMEM; |
| 10611 | |
| 10612 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 10613 | NL80211_CMD_GET_COALESCE); |
| 10614 | if (!hdr) |
| 10615 | goto nla_put_failure; |
| 10616 | |
| 10617 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 10618 | goto nla_put_failure; |
| 10619 | |
| 10620 | genlmsg_end(msg, hdr); |
| 10621 | return genlmsg_reply(msg, info); |
| 10622 | |
| 10623 | nla_put_failure: |
| 10624 | nlmsg_free(msg); |
| 10625 | return -ENOBUFS; |
| 10626 | } |
| 10627 | |
| 10628 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 10629 | { |
| 10630 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 10631 | int i, j; |
| 10632 | struct cfg80211_coalesce_rules *rule; |
| 10633 | |
| 10634 | if (!coalesce) |
| 10635 | return; |
| 10636 | |
| 10637 | for (i = 0; i < coalesce->n_rules; i++) { |
| 10638 | rule = &coalesce->rules[i]; |
| 10639 | for (j = 0; j < rule->n_patterns; j++) |
| 10640 | kfree(rule->patterns[j].mask); |
| 10641 | kfree(rule->patterns); |
| 10642 | } |
| 10643 | kfree(coalesce->rules); |
| 10644 | kfree(coalesce); |
| 10645 | rdev->coalesce = NULL; |
| 10646 | } |
| 10647 | |
| 10648 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 10649 | struct nlattr *rule, |
| 10650 | struct cfg80211_coalesce_rules *new_rule) |
| 10651 | { |
| 10652 | int err, i; |
| 10653 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 10654 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 10655 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 10656 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 10657 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10658 | err = nla_parse_nested(tb, NL80211_ATTR_COALESCE_RULE_MAX, rule, |
| 10659 | nl80211_coalesce_policy); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10660 | if (err) |
| 10661 | return err; |
| 10662 | |
| 10663 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 10664 | new_rule->delay = |
| 10665 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 10666 | if (new_rule->delay > coalesce->max_delay) |
| 10667 | return -EINVAL; |
| 10668 | |
| 10669 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 10670 | new_rule->condition = |
| 10671 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 10672 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 10673 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 10674 | return -EINVAL; |
| 10675 | |
| 10676 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 10677 | return -EINVAL; |
| 10678 | |
| 10679 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 10680 | rem) |
| 10681 | n_patterns++; |
| 10682 | if (n_patterns > coalesce->n_patterns) |
| 10683 | return -EINVAL; |
| 10684 | |
| 10685 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 10686 | GFP_KERNEL); |
| 10687 | if (!new_rule->patterns) |
| 10688 | return -ENOMEM; |
| 10689 | |
| 10690 | new_rule->n_patterns = n_patterns; |
| 10691 | i = 0; |
| 10692 | |
| 10693 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 10694 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10695 | u8 *mask_pat; |
| 10696 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10697 | nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, NULL); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10698 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 10699 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 10700 | return -EINVAL; |
| 10701 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 10702 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 10703 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 10704 | return -EINVAL; |
| 10705 | if (pat_len > coalesce->pattern_max_len || |
| 10706 | pat_len < coalesce->pattern_min_len) |
| 10707 | return -EINVAL; |
| 10708 | |
| 10709 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 10710 | pkt_offset = 0; |
| 10711 | else |
| 10712 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 10713 | if (pkt_offset > coalesce->max_pkt_offset) |
| 10714 | return -EINVAL; |
| 10715 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 10716 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10717 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 10718 | if (!mask_pat) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10719 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10720 | |
| 10721 | new_rule->patterns[i].mask = mask_pat; |
| 10722 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 10723 | mask_len); |
| 10724 | |
| 10725 | mask_pat += mask_len; |
| 10726 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10727 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 10728 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 10729 | pat_len); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10730 | i++; |
| 10731 | } |
| 10732 | |
| 10733 | return 0; |
| 10734 | } |
| 10735 | |
| 10736 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 10737 | { |
| 10738 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10739 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 10740 | struct cfg80211_coalesce new_coalesce = {}; |
| 10741 | struct cfg80211_coalesce *n_coalesce; |
| 10742 | int err, rem_rule, n_rules = 0, i, j; |
| 10743 | struct nlattr *rule; |
| 10744 | struct cfg80211_coalesce_rules *tmp_rule; |
| 10745 | |
| 10746 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 10747 | return -EOPNOTSUPP; |
| 10748 | |
| 10749 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 10750 | cfg80211_rdev_free_coalesce(rdev); |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 10751 | rdev_set_coalesce(rdev, NULL); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10752 | return 0; |
| 10753 | } |
| 10754 | |
| 10755 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 10756 | rem_rule) |
| 10757 | n_rules++; |
| 10758 | if (n_rules > coalesce->n_rules) |
| 10759 | return -EINVAL; |
| 10760 | |
| 10761 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 10762 | GFP_KERNEL); |
| 10763 | if (!new_coalesce.rules) |
| 10764 | return -ENOMEM; |
| 10765 | |
| 10766 | new_coalesce.n_rules = n_rules; |
| 10767 | i = 0; |
| 10768 | |
| 10769 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 10770 | rem_rule) { |
| 10771 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 10772 | &new_coalesce.rules[i]); |
| 10773 | if (err) |
| 10774 | goto error; |
| 10775 | |
| 10776 | i++; |
| 10777 | } |
| 10778 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 10779 | err = rdev_set_coalesce(rdev, &new_coalesce); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10780 | if (err) |
| 10781 | goto error; |
| 10782 | |
| 10783 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 10784 | if (!n_coalesce) { |
| 10785 | err = -ENOMEM; |
| 10786 | goto error; |
| 10787 | } |
| 10788 | cfg80211_rdev_free_coalesce(rdev); |
| 10789 | rdev->coalesce = n_coalesce; |
| 10790 | |
| 10791 | return 0; |
| 10792 | error: |
| 10793 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 10794 | tmp_rule = &new_coalesce.rules[i]; |
| 10795 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 10796 | kfree(tmp_rule->patterns[j].mask); |
| 10797 | kfree(tmp_rule->patterns); |
| 10798 | } |
| 10799 | kfree(new_coalesce.rules); |
| 10800 | |
| 10801 | return err; |
| 10802 | } |
| 10803 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10804 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 10805 | { |
| 10806 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10807 | struct net_device *dev = info->user_ptr[1]; |
| 10808 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10809 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 10810 | struct cfg80211_gtk_rekey_data rekey_data; |
| 10811 | int err; |
| 10812 | |
| 10813 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 10814 | return -EINVAL; |
| 10815 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 10816 | err = nla_parse_nested(tb, MAX_NL80211_REKEY_DATA, |
| 10817 | info->attrs[NL80211_ATTR_REKEY_DATA], |
| 10818 | nl80211_rekey_policy); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10819 | if (err) |
| 10820 | return err; |
| 10821 | |
| 10822 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 10823 | return -ERANGE; |
| 10824 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 10825 | return -ERANGE; |
| 10826 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 10827 | return -ERANGE; |
| 10828 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 10829 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 10830 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 10831 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10832 | |
| 10833 | wdev_lock(wdev); |
| 10834 | if (!wdev->current_bss) { |
| 10835 | err = -ENOTCONN; |
| 10836 | goto out; |
| 10837 | } |
| 10838 | |
| 10839 | if (!rdev->ops->set_rekey_data) { |
| 10840 | err = -EOPNOTSUPP; |
| 10841 | goto out; |
| 10842 | } |
| 10843 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10844 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10845 | out: |
| 10846 | wdev_unlock(wdev); |
| 10847 | return err; |
| 10848 | } |
| 10849 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10850 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 10851 | struct genl_info *info) |
| 10852 | { |
| 10853 | struct net_device *dev = info->user_ptr[1]; |
| 10854 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10855 | |
| 10856 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 10857 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 10858 | return -EINVAL; |
| 10859 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10860 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10861 | return -EBUSY; |
| 10862 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10863 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10864 | return 0; |
| 10865 | } |
| 10866 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10867 | static int nl80211_probe_client(struct sk_buff *skb, |
| 10868 | struct genl_info *info) |
| 10869 | { |
| 10870 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10871 | struct net_device *dev = info->user_ptr[1]; |
| 10872 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10873 | struct sk_buff *msg; |
| 10874 | void *hdr; |
| 10875 | const u8 *addr; |
| 10876 | u64 cookie; |
| 10877 | int err; |
| 10878 | |
| 10879 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 10880 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 10881 | return -EOPNOTSUPP; |
| 10882 | |
| 10883 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 10884 | return -EINVAL; |
| 10885 | |
| 10886 | if (!rdev->ops->probe_client) |
| 10887 | return -EOPNOTSUPP; |
| 10888 | |
| 10889 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10890 | if (!msg) |
| 10891 | return -ENOMEM; |
| 10892 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10893 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10894 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 10895 | if (!hdr) { |
| 10896 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10897 | goto free_msg; |
| 10898 | } |
| 10899 | |
| 10900 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10901 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10902 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10903 | if (err) |
| 10904 | goto free_msg; |
| 10905 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 10906 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 10907 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10908 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10909 | |
| 10910 | genlmsg_end(msg, hdr); |
| 10911 | |
| 10912 | return genlmsg_reply(msg, info); |
| 10913 | |
| 10914 | nla_put_failure: |
| 10915 | err = -ENOBUFS; |
| 10916 | free_msg: |
| 10917 | nlmsg_free(msg); |
| 10918 | return err; |
| 10919 | } |
| 10920 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10921 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 10922 | { |
| 10923 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10924 | struct cfg80211_beacon_registration *reg, *nreg; |
| 10925 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10926 | |
| 10927 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 10928 | return -EOPNOTSUPP; |
| 10929 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10930 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 10931 | if (!nreg) |
| 10932 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10933 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10934 | /* First, check if already registered. */ |
| 10935 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 10936 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 10937 | if (reg->nlportid == info->snd_portid) { |
| 10938 | rv = -EALREADY; |
| 10939 | goto out_err; |
| 10940 | } |
| 10941 | } |
| 10942 | /* Add it to the list */ |
| 10943 | nreg->nlportid = info->snd_portid; |
| 10944 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 10945 | |
| 10946 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10947 | |
| 10948 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 10949 | out_err: |
| 10950 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 10951 | kfree(nreg); |
| 10952 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10953 | } |
| 10954 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10955 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 10956 | { |
| 10957 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10958 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10959 | int err; |
| 10960 | |
| 10961 | if (!rdev->ops->start_p2p_device) |
| 10962 | return -EOPNOTSUPP; |
| 10963 | |
| 10964 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 10965 | return -EOPNOTSUPP; |
| 10966 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 10967 | if (wdev_running(wdev)) |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10968 | return 0; |
| 10969 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 10970 | if (rfkill_blocked(rdev->rfkill)) |
| 10971 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10972 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 10973 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10974 | if (err) |
| 10975 | return err; |
| 10976 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 10977 | wdev->is_running = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10978 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10979 | |
| 10980 | return 0; |
| 10981 | } |
| 10982 | |
| 10983 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 10984 | { |
| 10985 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10986 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10987 | |
| 10988 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 10989 | return -EOPNOTSUPP; |
| 10990 | |
| 10991 | if (!rdev->ops->stop_p2p_device) |
| 10992 | return -EOPNOTSUPP; |
| 10993 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 10994 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10995 | |
| 10996 | return 0; |
| 10997 | } |
| 10998 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 10999 | static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) |
| 11000 | { |
| 11001 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11002 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11003 | struct cfg80211_nan_conf conf = {}; |
| 11004 | int err; |
| 11005 | |
| 11006 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11007 | return -EOPNOTSUPP; |
| 11008 | |
Johannes Berg | eeb04a9 | 2016-11-21 13:55:48 +0100 | [diff] [blame] | 11009 | if (wdev_running(wdev)) |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11010 | return -EEXIST; |
| 11011 | |
| 11012 | if (rfkill_blocked(rdev->rfkill)) |
| 11013 | return -ERFKILL; |
| 11014 | |
| 11015 | if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) |
| 11016 | return -EINVAL; |
| 11017 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11018 | conf.master_pref = |
| 11019 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
| 11020 | if (!conf.master_pref) |
| 11021 | return -EINVAL; |
| 11022 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 11023 | if (info->attrs[NL80211_ATTR_BANDS]) { |
| 11024 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); |
| 11025 | |
| 11026 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) |
| 11027 | return -EOPNOTSUPP; |
| 11028 | |
| 11029 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) |
| 11030 | return -EINVAL; |
| 11031 | |
| 11032 | conf.bands = bands; |
| 11033 | } |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11034 | |
| 11035 | err = rdev_start_nan(rdev, wdev, &conf); |
| 11036 | if (err) |
| 11037 | return err; |
| 11038 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11039 | wdev->is_running = true; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11040 | rdev->opencount++; |
| 11041 | |
| 11042 | return 0; |
| 11043 | } |
| 11044 | |
| 11045 | static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) |
| 11046 | { |
| 11047 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11048 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11049 | |
| 11050 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11051 | return -EOPNOTSUPP; |
| 11052 | |
| 11053 | cfg80211_stop_nan(rdev, wdev); |
| 11054 | |
| 11055 | return 0; |
| 11056 | } |
| 11057 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11058 | static int validate_nan_filter(struct nlattr *filter_attr) |
| 11059 | { |
| 11060 | struct nlattr *attr; |
| 11061 | int len = 0, n_entries = 0, rem; |
| 11062 | |
| 11063 | nla_for_each_nested(attr, filter_attr, rem) { |
| 11064 | len += nla_len(attr); |
| 11065 | n_entries++; |
| 11066 | } |
| 11067 | |
| 11068 | if (len >= U8_MAX) |
| 11069 | return -EINVAL; |
| 11070 | |
| 11071 | return n_entries; |
| 11072 | } |
| 11073 | |
| 11074 | static int handle_nan_filter(struct nlattr *attr_filter, |
| 11075 | struct cfg80211_nan_func *func, |
| 11076 | bool tx) |
| 11077 | { |
| 11078 | struct nlattr *attr; |
| 11079 | int n_entries, rem, i; |
| 11080 | struct cfg80211_nan_func_filter *filter; |
| 11081 | |
| 11082 | n_entries = validate_nan_filter(attr_filter); |
| 11083 | if (n_entries < 0) |
| 11084 | return n_entries; |
| 11085 | |
| 11086 | BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); |
| 11087 | |
| 11088 | filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); |
| 11089 | if (!filter) |
| 11090 | return -ENOMEM; |
| 11091 | |
| 11092 | i = 0; |
| 11093 | nla_for_each_nested(attr, attr_filter, rem) { |
Thomas Graf | b15ca18 | 2016-10-26 10:53:16 +0200 | [diff] [blame] | 11094 | filter[i].filter = nla_memdup(attr, GFP_KERNEL); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11095 | filter[i].len = nla_len(attr); |
| 11096 | i++; |
| 11097 | } |
| 11098 | if (tx) { |
| 11099 | func->num_tx_filters = n_entries; |
| 11100 | func->tx_filters = filter; |
| 11101 | } else { |
| 11102 | func->num_rx_filters = n_entries; |
| 11103 | func->rx_filters = filter; |
| 11104 | } |
| 11105 | |
| 11106 | return 0; |
| 11107 | } |
| 11108 | |
| 11109 | static int nl80211_nan_add_func(struct sk_buff *skb, |
| 11110 | struct genl_info *info) |
| 11111 | { |
| 11112 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11113 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11114 | struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; |
| 11115 | struct cfg80211_nan_func *func; |
| 11116 | struct sk_buff *msg = NULL; |
| 11117 | void *hdr = NULL; |
| 11118 | int err = 0; |
| 11119 | |
| 11120 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11121 | return -EOPNOTSUPP; |
| 11122 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11123 | if (!wdev_running(wdev)) |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11124 | return -ENOTCONN; |
| 11125 | |
| 11126 | if (!info->attrs[NL80211_ATTR_NAN_FUNC]) |
| 11127 | return -EINVAL; |
| 11128 | |
| 11129 | if (wdev->owner_nlportid && |
| 11130 | wdev->owner_nlportid != info->snd_portid) |
| 11131 | return -ENOTCONN; |
| 11132 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 11133 | err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX, |
| 11134 | info->attrs[NL80211_ATTR_NAN_FUNC], |
| 11135 | nl80211_nan_func_policy); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11136 | if (err) |
| 11137 | return err; |
| 11138 | |
| 11139 | func = kzalloc(sizeof(*func), GFP_KERNEL); |
| 11140 | if (!func) |
| 11141 | return -ENOMEM; |
| 11142 | |
| 11143 | func->cookie = wdev->wiphy->cookie_counter++; |
| 11144 | |
| 11145 | if (!tb[NL80211_NAN_FUNC_TYPE] || |
| 11146 | nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) { |
| 11147 | err = -EINVAL; |
| 11148 | goto out; |
| 11149 | } |
| 11150 | |
| 11151 | |
| 11152 | func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); |
| 11153 | |
| 11154 | if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { |
| 11155 | err = -EINVAL; |
| 11156 | goto out; |
| 11157 | } |
| 11158 | |
| 11159 | memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), |
| 11160 | sizeof(func->service_id)); |
| 11161 | |
| 11162 | func->close_range = |
| 11163 | nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); |
| 11164 | |
| 11165 | if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { |
| 11166 | func->serv_spec_info_len = |
| 11167 | nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); |
| 11168 | func->serv_spec_info = |
| 11169 | kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), |
| 11170 | func->serv_spec_info_len, |
| 11171 | GFP_KERNEL); |
| 11172 | if (!func->serv_spec_info) { |
| 11173 | err = -ENOMEM; |
| 11174 | goto out; |
| 11175 | } |
| 11176 | } |
| 11177 | |
| 11178 | if (tb[NL80211_NAN_FUNC_TTL]) |
| 11179 | func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); |
| 11180 | |
| 11181 | switch (func->type) { |
| 11182 | case NL80211_NAN_FUNC_PUBLISH: |
| 11183 | if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { |
| 11184 | err = -EINVAL; |
| 11185 | goto out; |
| 11186 | } |
| 11187 | |
| 11188 | func->publish_type = |
| 11189 | nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); |
| 11190 | func->publish_bcast = |
| 11191 | nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); |
| 11192 | |
| 11193 | if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && |
| 11194 | func->publish_bcast) { |
| 11195 | err = -EINVAL; |
| 11196 | goto out; |
| 11197 | } |
| 11198 | break; |
| 11199 | case NL80211_NAN_FUNC_SUBSCRIBE: |
| 11200 | func->subscribe_active = |
| 11201 | nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); |
| 11202 | break; |
| 11203 | case NL80211_NAN_FUNC_FOLLOW_UP: |
| 11204 | if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || |
| 11205 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]) { |
| 11206 | err = -EINVAL; |
| 11207 | goto out; |
| 11208 | } |
| 11209 | |
| 11210 | func->followup_id = |
| 11211 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); |
| 11212 | func->followup_reqid = |
| 11213 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); |
| 11214 | memcpy(func->followup_dest.addr, |
| 11215 | nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), |
| 11216 | sizeof(func->followup_dest.addr)); |
| 11217 | if (func->ttl) { |
| 11218 | err = -EINVAL; |
| 11219 | goto out; |
| 11220 | } |
| 11221 | break; |
| 11222 | default: |
| 11223 | err = -EINVAL; |
| 11224 | goto out; |
| 11225 | } |
| 11226 | |
| 11227 | if (tb[NL80211_NAN_FUNC_SRF]) { |
| 11228 | struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; |
| 11229 | |
Johannes Berg | bfe2c7b | 2016-10-26 14:42:21 +0200 | [diff] [blame] | 11230 | err = nla_parse_nested(srf_tb, NL80211_NAN_SRF_ATTR_MAX, |
| 11231 | tb[NL80211_NAN_FUNC_SRF], |
| 11232 | nl80211_nan_srf_policy); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11233 | if (err) |
| 11234 | goto out; |
| 11235 | |
| 11236 | func->srf_include = |
| 11237 | nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); |
| 11238 | |
| 11239 | if (srf_tb[NL80211_NAN_SRF_BF]) { |
| 11240 | if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || |
| 11241 | !srf_tb[NL80211_NAN_SRF_BF_IDX]) { |
| 11242 | err = -EINVAL; |
| 11243 | goto out; |
| 11244 | } |
| 11245 | |
| 11246 | func->srf_bf_len = |
| 11247 | nla_len(srf_tb[NL80211_NAN_SRF_BF]); |
| 11248 | func->srf_bf = |
| 11249 | kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), |
| 11250 | func->srf_bf_len, GFP_KERNEL); |
| 11251 | if (!func->srf_bf) { |
| 11252 | err = -ENOMEM; |
| 11253 | goto out; |
| 11254 | } |
| 11255 | |
| 11256 | func->srf_bf_idx = |
| 11257 | nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); |
| 11258 | } else { |
| 11259 | struct nlattr *attr, *mac_attr = |
| 11260 | srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; |
| 11261 | int n_entries, rem, i = 0; |
| 11262 | |
| 11263 | if (!mac_attr) { |
| 11264 | err = -EINVAL; |
| 11265 | goto out; |
| 11266 | } |
| 11267 | |
| 11268 | n_entries = validate_acl_mac_addrs(mac_attr); |
| 11269 | if (n_entries <= 0) { |
| 11270 | err = -EINVAL; |
| 11271 | goto out; |
| 11272 | } |
| 11273 | |
| 11274 | func->srf_num_macs = n_entries; |
| 11275 | func->srf_macs = |
| 11276 | kzalloc(sizeof(*func->srf_macs) * n_entries, |
| 11277 | GFP_KERNEL); |
| 11278 | if (!func->srf_macs) { |
| 11279 | err = -ENOMEM; |
| 11280 | goto out; |
| 11281 | } |
| 11282 | |
| 11283 | nla_for_each_nested(attr, mac_attr, rem) |
| 11284 | memcpy(func->srf_macs[i++].addr, nla_data(attr), |
| 11285 | sizeof(*func->srf_macs)); |
| 11286 | } |
| 11287 | } |
| 11288 | |
| 11289 | if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { |
| 11290 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], |
| 11291 | func, true); |
| 11292 | if (err) |
| 11293 | goto out; |
| 11294 | } |
| 11295 | |
| 11296 | if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { |
| 11297 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], |
| 11298 | func, false); |
| 11299 | if (err) |
| 11300 | goto out; |
| 11301 | } |
| 11302 | |
| 11303 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11304 | if (!msg) { |
| 11305 | err = -ENOMEM; |
| 11306 | goto out; |
| 11307 | } |
| 11308 | |
| 11309 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 11310 | NL80211_CMD_ADD_NAN_FUNCTION); |
| 11311 | /* This can't really happen - we just allocated 4KB */ |
| 11312 | if (WARN_ON(!hdr)) { |
| 11313 | err = -ENOMEM; |
| 11314 | goto out; |
| 11315 | } |
| 11316 | |
| 11317 | err = rdev_add_nan_func(rdev, wdev, func); |
| 11318 | out: |
| 11319 | if (err < 0) { |
| 11320 | cfg80211_free_nan_func(func); |
| 11321 | nlmsg_free(msg); |
| 11322 | return err; |
| 11323 | } |
| 11324 | |
| 11325 | /* propagate the instance id and cookie to userspace */ |
| 11326 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, |
| 11327 | NL80211_ATTR_PAD)) |
| 11328 | goto nla_put_failure; |
| 11329 | |
| 11330 | func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); |
| 11331 | if (!func_attr) |
| 11332 | goto nla_put_failure; |
| 11333 | |
| 11334 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, |
| 11335 | func->instance_id)) |
| 11336 | goto nla_put_failure; |
| 11337 | |
| 11338 | nla_nest_end(msg, func_attr); |
| 11339 | |
| 11340 | genlmsg_end(msg, hdr); |
| 11341 | return genlmsg_reply(msg, info); |
| 11342 | |
| 11343 | nla_put_failure: |
| 11344 | nlmsg_free(msg); |
| 11345 | return -ENOBUFS; |
| 11346 | } |
| 11347 | |
| 11348 | static int nl80211_nan_del_func(struct sk_buff *skb, |
| 11349 | struct genl_info *info) |
| 11350 | { |
| 11351 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11352 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11353 | u64 cookie; |
| 11354 | |
| 11355 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11356 | return -EOPNOTSUPP; |
| 11357 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11358 | if (!wdev_running(wdev)) |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 11359 | return -ENOTCONN; |
| 11360 | |
| 11361 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 11362 | return -EINVAL; |
| 11363 | |
| 11364 | if (wdev->owner_nlportid && |
| 11365 | wdev->owner_nlportid != info->snd_portid) |
| 11366 | return -ENOTCONN; |
| 11367 | |
| 11368 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 11369 | |
| 11370 | rdev_del_nan_func(rdev, wdev, cookie); |
| 11371 | |
| 11372 | return 0; |
| 11373 | } |
| 11374 | |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 11375 | static int nl80211_nan_change_config(struct sk_buff *skb, |
| 11376 | struct genl_info *info) |
| 11377 | { |
| 11378 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11379 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11380 | struct cfg80211_nan_conf conf = {}; |
| 11381 | u32 changed = 0; |
| 11382 | |
| 11383 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 11384 | return -EOPNOTSUPP; |
| 11385 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11386 | if (!wdev_running(wdev)) |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 11387 | return -ENOTCONN; |
| 11388 | |
| 11389 | if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { |
| 11390 | conf.master_pref = |
| 11391 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
| 11392 | if (conf.master_pref <= 1 || conf.master_pref == 255) |
| 11393 | return -EINVAL; |
| 11394 | |
| 11395 | changed |= CFG80211_NAN_CONF_CHANGED_PREF; |
| 11396 | } |
| 11397 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 11398 | if (info->attrs[NL80211_ATTR_BANDS]) { |
| 11399 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); |
| 11400 | |
| 11401 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) |
| 11402 | return -EOPNOTSUPP; |
| 11403 | |
| 11404 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) |
| 11405 | return -EINVAL; |
| 11406 | |
| 11407 | conf.bands = bands; |
| 11408 | changed |= CFG80211_NAN_CONF_CHANGED_BANDS; |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 11409 | } |
| 11410 | |
| 11411 | if (!changed) |
| 11412 | return -EINVAL; |
| 11413 | |
| 11414 | return rdev_nan_change_conf(rdev, wdev, &conf, changed); |
| 11415 | } |
| 11416 | |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 11417 | void cfg80211_nan_match(struct wireless_dev *wdev, |
| 11418 | struct cfg80211_nan_match_params *match, gfp_t gfp) |
| 11419 | { |
| 11420 | struct wiphy *wiphy = wdev->wiphy; |
| 11421 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 11422 | struct nlattr *match_attr, *local_func_attr, *peer_func_attr; |
| 11423 | struct sk_buff *msg; |
| 11424 | void *hdr; |
| 11425 | |
| 11426 | if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) |
| 11427 | return; |
| 11428 | |
| 11429 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11430 | if (!msg) |
| 11431 | return; |
| 11432 | |
| 11433 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); |
| 11434 | if (!hdr) { |
| 11435 | nlmsg_free(msg); |
| 11436 | return; |
| 11437 | } |
| 11438 | |
| 11439 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11440 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11441 | wdev->netdev->ifindex)) || |
| 11442 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 11443 | NL80211_ATTR_PAD)) |
| 11444 | goto nla_put_failure; |
| 11445 | |
| 11446 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, |
| 11447 | NL80211_ATTR_PAD) || |
| 11448 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) |
| 11449 | goto nla_put_failure; |
| 11450 | |
| 11451 | match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH); |
| 11452 | if (!match_attr) |
| 11453 | goto nla_put_failure; |
| 11454 | |
| 11455 | local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL); |
| 11456 | if (!local_func_attr) |
| 11457 | goto nla_put_failure; |
| 11458 | |
| 11459 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) |
| 11460 | goto nla_put_failure; |
| 11461 | |
| 11462 | nla_nest_end(msg, local_func_attr); |
| 11463 | |
| 11464 | peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER); |
| 11465 | if (!peer_func_attr) |
| 11466 | goto nla_put_failure; |
| 11467 | |
| 11468 | if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || |
| 11469 | nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) |
| 11470 | goto nla_put_failure; |
| 11471 | |
| 11472 | if (match->info && match->info_len && |
| 11473 | nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, |
| 11474 | match->info)) |
| 11475 | goto nla_put_failure; |
| 11476 | |
| 11477 | nla_nest_end(msg, peer_func_attr); |
| 11478 | nla_nest_end(msg, match_attr); |
| 11479 | genlmsg_end(msg, hdr); |
| 11480 | |
| 11481 | if (!wdev->owner_nlportid) |
| 11482 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 11483 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 11484 | else |
| 11485 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 11486 | wdev->owner_nlportid); |
| 11487 | |
| 11488 | return; |
| 11489 | |
| 11490 | nla_put_failure: |
| 11491 | nlmsg_free(msg); |
| 11492 | } |
| 11493 | EXPORT_SYMBOL(cfg80211_nan_match); |
| 11494 | |
Ayala Beker | 368e5a7 | 2016-09-20 17:31:18 +0300 | [diff] [blame] | 11495 | void cfg80211_nan_func_terminated(struct wireless_dev *wdev, |
| 11496 | u8 inst_id, |
| 11497 | enum nl80211_nan_func_term_reason reason, |
| 11498 | u64 cookie, gfp_t gfp) |
| 11499 | { |
| 11500 | struct wiphy *wiphy = wdev->wiphy; |
| 11501 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 11502 | struct sk_buff *msg; |
| 11503 | struct nlattr *func_attr; |
| 11504 | void *hdr; |
| 11505 | |
| 11506 | if (WARN_ON(!inst_id)) |
| 11507 | return; |
| 11508 | |
| 11509 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11510 | if (!msg) |
| 11511 | return; |
| 11512 | |
| 11513 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); |
| 11514 | if (!hdr) { |
| 11515 | nlmsg_free(msg); |
| 11516 | return; |
| 11517 | } |
| 11518 | |
| 11519 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11520 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11521 | wdev->netdev->ifindex)) || |
| 11522 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 11523 | NL80211_ATTR_PAD)) |
| 11524 | goto nla_put_failure; |
| 11525 | |
| 11526 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 11527 | NL80211_ATTR_PAD)) |
| 11528 | goto nla_put_failure; |
| 11529 | |
| 11530 | func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); |
| 11531 | if (!func_attr) |
| 11532 | goto nla_put_failure; |
| 11533 | |
| 11534 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || |
| 11535 | nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) |
| 11536 | goto nla_put_failure; |
| 11537 | |
| 11538 | nla_nest_end(msg, func_attr); |
| 11539 | genlmsg_end(msg, hdr); |
| 11540 | |
| 11541 | if (!wdev->owner_nlportid) |
| 11542 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 11543 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 11544 | else |
| 11545 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 11546 | wdev->owner_nlportid); |
| 11547 | |
| 11548 | return; |
| 11549 | |
| 11550 | nla_put_failure: |
| 11551 | nlmsg_free(msg); |
| 11552 | } |
| 11553 | EXPORT_SYMBOL(cfg80211_nan_func_terminated); |
| 11554 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 11555 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 11556 | struct genl_info *info) |
| 11557 | { |
| 11558 | void *hdr; |
| 11559 | struct sk_buff *msg; |
| 11560 | |
| 11561 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11562 | if (!msg) |
| 11563 | return -ENOMEM; |
| 11564 | |
| 11565 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 11566 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 11567 | if (!hdr) |
| 11568 | goto nla_put_failure; |
| 11569 | |
| 11570 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 11571 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 11572 | goto nla_put_failure; |
| 11573 | |
| 11574 | genlmsg_end(msg, hdr); |
| 11575 | return genlmsg_reply(msg, info); |
| 11576 | |
| 11577 | nla_put_failure: |
| 11578 | kfree_skb(msg); |
| 11579 | return -ENOBUFS; |
| 11580 | } |
| 11581 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11582 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 11583 | { |
| 11584 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11585 | struct cfg80211_update_ft_ies_params ft_params; |
| 11586 | struct net_device *dev = info->user_ptr[1]; |
| 11587 | |
| 11588 | if (!rdev->ops->update_ft_ies) |
| 11589 | return -EOPNOTSUPP; |
| 11590 | |
| 11591 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 11592 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 11593 | return -EINVAL; |
| 11594 | |
| 11595 | memset(&ft_params, 0, sizeof(ft_params)); |
| 11596 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 11597 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 11598 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 11599 | |
| 11600 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 11601 | } |
| 11602 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 11603 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 11604 | struct genl_info *info) |
| 11605 | { |
| 11606 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11607 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11608 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 11609 | u16 duration; |
| 11610 | int ret; |
| 11611 | |
| 11612 | if (!rdev->ops->crit_proto_start) |
| 11613 | return -EOPNOTSUPP; |
| 11614 | |
| 11615 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 11616 | return -EINVAL; |
| 11617 | |
| 11618 | if (rdev->crit_proto_nlportid) |
| 11619 | return -EBUSY; |
| 11620 | |
| 11621 | /* determine protocol if provided */ |
| 11622 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 11623 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 11624 | |
| 11625 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 11626 | return -EINVAL; |
| 11627 | |
| 11628 | /* timeout must be provided */ |
| 11629 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 11630 | return -EINVAL; |
| 11631 | |
| 11632 | duration = |
| 11633 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 11634 | |
| 11635 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 11636 | return -ERANGE; |
| 11637 | |
| 11638 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 11639 | if (!ret) |
| 11640 | rdev->crit_proto_nlportid = info->snd_portid; |
| 11641 | |
| 11642 | return ret; |
| 11643 | } |
| 11644 | |
| 11645 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 11646 | struct genl_info *info) |
| 11647 | { |
| 11648 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11649 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 11650 | |
| 11651 | if (!rdev->ops->crit_proto_stop) |
| 11652 | return -EOPNOTSUPP; |
| 11653 | |
| 11654 | if (rdev->crit_proto_nlportid) { |
| 11655 | rdev->crit_proto_nlportid = 0; |
| 11656 | rdev_crit_proto_stop(rdev, wdev); |
| 11657 | } |
| 11658 | return 0; |
| 11659 | } |
| 11660 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11661 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 11662 | { |
| 11663 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11664 | struct wireless_dev *wdev = |
| 11665 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 11666 | int i, err; |
| 11667 | u32 vid, subcmd; |
| 11668 | |
| 11669 | if (!rdev->wiphy.vendor_commands) |
| 11670 | return -EOPNOTSUPP; |
| 11671 | |
| 11672 | if (IS_ERR(wdev)) { |
| 11673 | err = PTR_ERR(wdev); |
| 11674 | if (err != -EINVAL) |
| 11675 | return err; |
| 11676 | wdev = NULL; |
| 11677 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 11678 | return -EINVAL; |
| 11679 | } |
| 11680 | |
| 11681 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 11682 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 11683 | return -EINVAL; |
| 11684 | |
| 11685 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 11686 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 11687 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 11688 | const struct wiphy_vendor_command *vcmd; |
| 11689 | void *data = NULL; |
| 11690 | int len = 0; |
| 11691 | |
| 11692 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 11693 | |
| 11694 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 11695 | continue; |
| 11696 | |
| 11697 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 11698 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 11699 | if (!wdev) |
| 11700 | return -EINVAL; |
| 11701 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 11702 | !wdev->netdev) |
| 11703 | return -EINVAL; |
| 11704 | |
| 11705 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11706 | if (!wdev_running(wdev)) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11707 | return -ENETDOWN; |
| 11708 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11709 | |
| 11710 | if (!vcmd->doit) |
| 11711 | return -EOPNOTSUPP; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11712 | } else { |
| 11713 | wdev = NULL; |
| 11714 | } |
| 11715 | |
| 11716 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 11717 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 11718 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 11719 | } |
| 11720 | |
| 11721 | rdev->cur_cmd_info = info; |
| 11722 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 11723 | data, len); |
| 11724 | rdev->cur_cmd_info = NULL; |
| 11725 | return err; |
| 11726 | } |
| 11727 | |
| 11728 | return -EOPNOTSUPP; |
| 11729 | } |
| 11730 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11731 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
| 11732 | struct netlink_callback *cb, |
| 11733 | struct cfg80211_registered_device **rdev, |
| 11734 | struct wireless_dev **wdev) |
| 11735 | { |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11736 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11737 | u32 vid, subcmd; |
| 11738 | unsigned int i; |
| 11739 | int vcmd_idx = -1; |
| 11740 | int err; |
| 11741 | void *data = NULL; |
| 11742 | unsigned int data_len = 0; |
| 11743 | |
| 11744 | rtnl_lock(); |
| 11745 | |
| 11746 | if (cb->args[0]) { |
| 11747 | /* subtract the 1 again here */ |
| 11748 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
| 11749 | struct wireless_dev *tmp; |
| 11750 | |
| 11751 | if (!wiphy) { |
| 11752 | err = -ENODEV; |
| 11753 | goto out_unlock; |
| 11754 | } |
| 11755 | *rdev = wiphy_to_rdev(wiphy); |
| 11756 | *wdev = NULL; |
| 11757 | |
| 11758 | if (cb->args[1]) { |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 11759 | list_for_each_entry(tmp, &wiphy->wdev_list, list) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11760 | if (tmp->identifier == cb->args[1] - 1) { |
| 11761 | *wdev = tmp; |
| 11762 | break; |
| 11763 | } |
| 11764 | } |
| 11765 | } |
| 11766 | |
| 11767 | /* keep rtnl locked in successful case */ |
| 11768 | return 0; |
| 11769 | } |
| 11770 | |
| 11771 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11772 | attrbuf, nl80211_fam.maxattr, nl80211_policy); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11773 | if (err) |
| 11774 | goto out_unlock; |
| 11775 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11776 | if (!attrbuf[NL80211_ATTR_VENDOR_ID] || |
| 11777 | !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11778 | err = -EINVAL; |
| 11779 | goto out_unlock; |
| 11780 | } |
| 11781 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11782 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11783 | if (IS_ERR(*wdev)) |
| 11784 | *wdev = NULL; |
| 11785 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11786 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11787 | if (IS_ERR(*rdev)) { |
| 11788 | err = PTR_ERR(*rdev); |
| 11789 | goto out_unlock; |
| 11790 | } |
| 11791 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11792 | vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]); |
| 11793 | subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11794 | |
| 11795 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { |
| 11796 | const struct wiphy_vendor_command *vcmd; |
| 11797 | |
| 11798 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; |
| 11799 | |
| 11800 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 11801 | continue; |
| 11802 | |
| 11803 | if (!vcmd->dumpit) { |
| 11804 | err = -EOPNOTSUPP; |
| 11805 | goto out_unlock; |
| 11806 | } |
| 11807 | |
| 11808 | vcmd_idx = i; |
| 11809 | break; |
| 11810 | } |
| 11811 | |
| 11812 | if (vcmd_idx < 0) { |
| 11813 | err = -EOPNOTSUPP; |
| 11814 | goto out_unlock; |
| 11815 | } |
| 11816 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 11817 | if (attrbuf[NL80211_ATTR_VENDOR_DATA]) { |
| 11818 | data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 11819 | data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11820 | } |
| 11821 | |
| 11822 | /* 0 is the first index - add 1 to parse only once */ |
| 11823 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
| 11824 | /* add 1 to know if it was NULL */ |
| 11825 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; |
| 11826 | cb->args[2] = vcmd_idx; |
| 11827 | cb->args[3] = (unsigned long)data; |
| 11828 | cb->args[4] = data_len; |
| 11829 | |
| 11830 | /* keep rtnl locked in successful case */ |
| 11831 | return 0; |
| 11832 | out_unlock: |
| 11833 | rtnl_unlock(); |
| 11834 | return err; |
| 11835 | } |
| 11836 | |
| 11837 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, |
| 11838 | struct netlink_callback *cb) |
| 11839 | { |
| 11840 | struct cfg80211_registered_device *rdev; |
| 11841 | struct wireless_dev *wdev; |
| 11842 | unsigned int vcmd_idx; |
| 11843 | const struct wiphy_vendor_command *vcmd; |
| 11844 | void *data; |
| 11845 | int data_len; |
| 11846 | int err; |
| 11847 | struct nlattr *vendor_data; |
| 11848 | |
| 11849 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); |
| 11850 | if (err) |
| 11851 | return err; |
| 11852 | |
| 11853 | vcmd_idx = cb->args[2]; |
| 11854 | data = (void *)cb->args[3]; |
| 11855 | data_len = cb->args[4]; |
| 11856 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; |
| 11857 | |
| 11858 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 11859 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 11860 | if (!wdev) |
| 11861 | return -EINVAL; |
| 11862 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 11863 | !wdev->netdev) |
| 11864 | return -EINVAL; |
| 11865 | |
| 11866 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 11867 | if (!wdev_running(wdev)) |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11868 | return -ENETDOWN; |
| 11869 | } |
| 11870 | } |
| 11871 | |
| 11872 | while (1) { |
| 11873 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
| 11874 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 11875 | NL80211_CMD_VENDOR); |
| 11876 | if (!hdr) |
| 11877 | break; |
| 11878 | |
| 11879 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 11880 | (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 11881 | wdev_id(wdev), |
| 11882 | NL80211_ATTR_PAD))) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 11883 | genlmsg_cancel(skb, hdr); |
| 11884 | break; |
| 11885 | } |
| 11886 | |
| 11887 | vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA); |
| 11888 | if (!vendor_data) { |
| 11889 | genlmsg_cancel(skb, hdr); |
| 11890 | break; |
| 11891 | } |
| 11892 | |
| 11893 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, |
| 11894 | (unsigned long *)&cb->args[5]); |
| 11895 | nla_nest_end(skb, vendor_data); |
| 11896 | |
| 11897 | if (err == -ENOBUFS || err == -ENOENT) { |
| 11898 | genlmsg_cancel(skb, hdr); |
| 11899 | break; |
| 11900 | } else if (err) { |
| 11901 | genlmsg_cancel(skb, hdr); |
| 11902 | goto out; |
| 11903 | } |
| 11904 | |
| 11905 | genlmsg_end(skb, hdr); |
| 11906 | } |
| 11907 | |
| 11908 | err = skb->len; |
| 11909 | out: |
| 11910 | rtnl_unlock(); |
| 11911 | return err; |
| 11912 | } |
| 11913 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11914 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 11915 | enum nl80211_commands cmd, |
| 11916 | enum nl80211_attrs attr, |
| 11917 | int approxlen) |
| 11918 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11919 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11920 | |
| 11921 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 11922 | return NULL; |
| 11923 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 11924 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11925 | rdev->cur_cmd_info->snd_portid, |
| 11926 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 11927 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11928 | } |
| 11929 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 11930 | |
| 11931 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 11932 | { |
| 11933 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 11934 | void *hdr = ((void **)skb->cb)[1]; |
| 11935 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 11936 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 11937 | /* clear CB data for netlink core to own from now on */ |
| 11938 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 11939 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 11940 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 11941 | kfree_skb(skb); |
| 11942 | return -EINVAL; |
| 11943 | } |
| 11944 | |
| 11945 | nla_nest_end(skb, data); |
| 11946 | genlmsg_end(skb, hdr); |
| 11947 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 11948 | } |
| 11949 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 11950 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 11951 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 11952 | struct genl_info *info) |
| 11953 | { |
| 11954 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11955 | struct cfg80211_qos_map *qos_map = NULL; |
| 11956 | struct net_device *dev = info->user_ptr[1]; |
| 11957 | u8 *pos, len, num_des, des_len, des; |
| 11958 | int ret; |
| 11959 | |
| 11960 | if (!rdev->ops->set_qos_map) |
| 11961 | return -EOPNOTSUPP; |
| 11962 | |
| 11963 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 11964 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 11965 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 11966 | |
| 11967 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 11968 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 11969 | return -EINVAL; |
| 11970 | |
| 11971 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 11972 | if (!qos_map) |
| 11973 | return -ENOMEM; |
| 11974 | |
| 11975 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 11976 | if (num_des) { |
| 11977 | des_len = num_des * |
| 11978 | sizeof(struct cfg80211_dscp_exception); |
| 11979 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 11980 | qos_map->num_des = num_des; |
| 11981 | for (des = 0; des < num_des; des++) { |
| 11982 | if (qos_map->dscp_exception[des].up > 7) { |
| 11983 | kfree(qos_map); |
| 11984 | return -EINVAL; |
| 11985 | } |
| 11986 | } |
| 11987 | pos += des_len; |
| 11988 | } |
| 11989 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 11990 | } |
| 11991 | |
| 11992 | wdev_lock(dev->ieee80211_ptr); |
| 11993 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 11994 | if (!ret) |
| 11995 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 11996 | wdev_unlock(dev->ieee80211_ptr); |
| 11997 | |
| 11998 | kfree(qos_map); |
| 11999 | return ret; |
| 12000 | } |
| 12001 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12002 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 12003 | { |
| 12004 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12005 | struct net_device *dev = info->user_ptr[1]; |
| 12006 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12007 | const u8 *peer; |
| 12008 | u8 tsid, up; |
| 12009 | u16 admitted_time = 0; |
| 12010 | int err; |
| 12011 | |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 12012 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12013 | return -EOPNOTSUPP; |
| 12014 | |
| 12015 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 12016 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 12017 | return -EINVAL; |
| 12018 | |
| 12019 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 12020 | if (tsid >= IEEE80211_NUM_TIDS) |
| 12021 | return -EINVAL; |
| 12022 | |
| 12023 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
| 12024 | if (up >= IEEE80211_NUM_UPS) |
| 12025 | return -EINVAL; |
| 12026 | |
| 12027 | /* WMM uses TIDs 0-7 even for TSPEC */ |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 12028 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12029 | /* TODO: handle 802.11 TSPEC/admission control |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 12030 | * need more attributes for that (e.g. BA session requirement); |
| 12031 | * change the WMM adminssion test above to allow both then |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 12032 | */ |
| 12033 | return -EINVAL; |
| 12034 | } |
| 12035 | |
| 12036 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12037 | |
| 12038 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 12039 | admitted_time = |
| 12040 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 12041 | if (!admitted_time) |
| 12042 | return -EINVAL; |
| 12043 | } |
| 12044 | |
| 12045 | wdev_lock(wdev); |
| 12046 | switch (wdev->iftype) { |
| 12047 | case NL80211_IFTYPE_STATION: |
| 12048 | case NL80211_IFTYPE_P2P_CLIENT: |
| 12049 | if (wdev->current_bss) |
| 12050 | break; |
| 12051 | err = -ENOTCONN; |
| 12052 | goto out; |
| 12053 | default: |
| 12054 | err = -EOPNOTSUPP; |
| 12055 | goto out; |
| 12056 | } |
| 12057 | |
| 12058 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 12059 | |
| 12060 | out: |
| 12061 | wdev_unlock(wdev); |
| 12062 | return err; |
| 12063 | } |
| 12064 | |
| 12065 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 12066 | { |
| 12067 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12068 | struct net_device *dev = info->user_ptr[1]; |
| 12069 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12070 | const u8 *peer; |
| 12071 | u8 tsid; |
| 12072 | int err; |
| 12073 | |
| 12074 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 12075 | return -EINVAL; |
| 12076 | |
| 12077 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 12078 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12079 | |
| 12080 | wdev_lock(wdev); |
| 12081 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 12082 | wdev_unlock(wdev); |
| 12083 | |
| 12084 | return err; |
| 12085 | } |
| 12086 | |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12087 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
| 12088 | struct genl_info *info) |
| 12089 | { |
| 12090 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12091 | struct net_device *dev = info->user_ptr[1]; |
| 12092 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12093 | struct cfg80211_chan_def chandef = {}; |
| 12094 | const u8 *addr; |
| 12095 | u8 oper_class; |
| 12096 | int err; |
| 12097 | |
| 12098 | if (!rdev->ops->tdls_channel_switch || |
| 12099 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 12100 | return -EOPNOTSUPP; |
| 12101 | |
| 12102 | switch (dev->ieee80211_ptr->iftype) { |
| 12103 | case NL80211_IFTYPE_STATION: |
| 12104 | case NL80211_IFTYPE_P2P_CLIENT: |
| 12105 | break; |
| 12106 | default: |
| 12107 | return -EOPNOTSUPP; |
| 12108 | } |
| 12109 | |
| 12110 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 12111 | !info->attrs[NL80211_ATTR_OPER_CLASS]) |
| 12112 | return -EINVAL; |
| 12113 | |
| 12114 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 12115 | if (err) |
| 12116 | return err; |
| 12117 | |
| 12118 | /* |
| 12119 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 |
| 12120 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the |
| 12121 | * specification is not defined for them. |
| 12122 | */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 12123 | if (chandef.chan->band == NL80211_BAND_2GHZ && |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12124 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 12125 | chandef.width != NL80211_CHAN_WIDTH_20) |
| 12126 | return -EINVAL; |
| 12127 | |
| 12128 | /* we will be active on the TDLS link */ |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 12129 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 12130 | wdev->iftype)) |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 12131 | return -EINVAL; |
| 12132 | |
| 12133 | /* don't allow switching to DFS channels */ |
| 12134 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) |
| 12135 | return -EINVAL; |
| 12136 | |
| 12137 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12138 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); |
| 12139 | |
| 12140 | wdev_lock(wdev); |
| 12141 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); |
| 12142 | wdev_unlock(wdev); |
| 12143 | |
| 12144 | return err; |
| 12145 | } |
| 12146 | |
| 12147 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, |
| 12148 | struct genl_info *info) |
| 12149 | { |
| 12150 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12151 | struct net_device *dev = info->user_ptr[1]; |
| 12152 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12153 | const u8 *addr; |
| 12154 | |
| 12155 | if (!rdev->ops->tdls_channel_switch || |
| 12156 | !rdev->ops->tdls_cancel_channel_switch || |
| 12157 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 12158 | return -EOPNOTSUPP; |
| 12159 | |
| 12160 | switch (dev->ieee80211_ptr->iftype) { |
| 12161 | case NL80211_IFTYPE_STATION: |
| 12162 | case NL80211_IFTYPE_P2P_CLIENT: |
| 12163 | break; |
| 12164 | default: |
| 12165 | return -EOPNOTSUPP; |
| 12166 | } |
| 12167 | |
| 12168 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 12169 | return -EINVAL; |
| 12170 | |
| 12171 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12172 | |
| 12173 | wdev_lock(wdev); |
| 12174 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); |
| 12175 | wdev_unlock(wdev); |
| 12176 | |
| 12177 | return 0; |
| 12178 | } |
| 12179 | |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 12180 | static int nl80211_set_multicast_to_unicast(struct sk_buff *skb, |
| 12181 | struct genl_info *info) |
| 12182 | { |
| 12183 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12184 | struct net_device *dev = info->user_ptr[1]; |
| 12185 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12186 | const struct nlattr *nla; |
| 12187 | bool enabled; |
| 12188 | |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 12189 | if (!rdev->ops->set_multicast_to_unicast) |
| 12190 | return -EOPNOTSUPP; |
| 12191 | |
| 12192 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 12193 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 12194 | return -EOPNOTSUPP; |
| 12195 | |
| 12196 | nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED]; |
| 12197 | enabled = nla_get_flag(nla); |
| 12198 | |
| 12199 | return rdev_set_multicast_to_unicast(rdev, dev, enabled); |
| 12200 | } |
| 12201 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12202 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 12203 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 12204 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12205 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 12206 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 12207 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12208 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12209 | /* 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] | 12210 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 12211 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12212 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12213 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 12214 | 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] | 12215 | struct genl_info *info) |
| 12216 | { |
| 12217 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12218 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12219 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12220 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 12221 | |
| 12222 | if (rtnl) |
| 12223 | rtnl_lock(); |
| 12224 | |
| 12225 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 12226 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12227 | if (IS_ERR(rdev)) { |
| 12228 | if (rtnl) |
| 12229 | rtnl_unlock(); |
| 12230 | return PTR_ERR(rdev); |
| 12231 | } |
| 12232 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12233 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 12234 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12235 | ASSERT_RTNL(); |
| 12236 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12237 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 12238 | info->attrs); |
| 12239 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12240 | if (rtnl) |
| 12241 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12242 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12243 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12244 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12245 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12246 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12247 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12248 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 12249 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12250 | if (rtnl) |
| 12251 | rtnl_unlock(); |
| 12252 | return -EINVAL; |
| 12253 | } |
| 12254 | |
| 12255 | info->user_ptr[1] = dev; |
| 12256 | } else { |
| 12257 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12258 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 12259 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12260 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 12261 | !wdev_running(wdev)) { |
| 12262 | if (rtnl) |
| 12263 | rtnl_unlock(); |
| 12264 | return -ENETDOWN; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12265 | } |
| 12266 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12267 | if (dev) |
| 12268 | dev_hold(dev); |
| 12269 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12270 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12271 | } |
| 12272 | |
| 12273 | return 0; |
| 12274 | } |
| 12275 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 12276 | 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] | 12277 | struct genl_info *info) |
| 12278 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 12279 | if (info->user_ptr[1]) { |
| 12280 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 12281 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12282 | |
| 12283 | if (wdev->netdev) |
| 12284 | dev_put(wdev->netdev); |
| 12285 | } else { |
| 12286 | dev_put(info->user_ptr[1]); |
| 12287 | } |
| 12288 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12289 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12290 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 12291 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12292 | |
| 12293 | /* If needed, clear the netlink message payload from the SKB |
| 12294 | * as it might contain key data that shouldn't stick around on |
| 12295 | * the heap after the SKB is freed. The netlink message header |
| 12296 | * is still needed for further processing, so leave it intact. |
| 12297 | */ |
| 12298 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 12299 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 12300 | |
| 12301 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 12302 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12303 | } |
| 12304 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 12305 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12306 | { |
| 12307 | .cmd = NL80211_CMD_GET_WIPHY, |
| 12308 | .doit = nl80211_get_wiphy, |
| 12309 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 12310 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12311 | .policy = nl80211_policy, |
| 12312 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12313 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12314 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12315 | }, |
| 12316 | { |
| 12317 | .cmd = NL80211_CMD_SET_WIPHY, |
| 12318 | .doit = nl80211_set_wiphy, |
| 12319 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12320 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12321 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12322 | }, |
| 12323 | { |
| 12324 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 12325 | .doit = nl80211_get_interface, |
| 12326 | .dumpit = nl80211_dump_interface, |
| 12327 | .policy = nl80211_policy, |
| 12328 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12329 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 12330 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12331 | }, |
| 12332 | { |
| 12333 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 12334 | .doit = nl80211_set_interface, |
| 12335 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12336 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12337 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12338 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12339 | }, |
| 12340 | { |
| 12341 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 12342 | .doit = nl80211_new_interface, |
| 12343 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12344 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12345 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12346 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12347 | }, |
| 12348 | { |
| 12349 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 12350 | .doit = nl80211_del_interface, |
| 12351 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12352 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 12353 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12354 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12355 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12356 | { |
| 12357 | .cmd = NL80211_CMD_GET_KEY, |
| 12358 | .doit = nl80211_get_key, |
| 12359 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12360 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12361 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12362 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12363 | }, |
| 12364 | { |
| 12365 | .cmd = NL80211_CMD_SET_KEY, |
| 12366 | .doit = nl80211_set_key, |
| 12367 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12368 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12369 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12370 | NL80211_FLAG_NEED_RTNL | |
| 12371 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12372 | }, |
| 12373 | { |
| 12374 | .cmd = NL80211_CMD_NEW_KEY, |
| 12375 | .doit = nl80211_new_key, |
| 12376 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12377 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12378 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12379 | NL80211_FLAG_NEED_RTNL | |
| 12380 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12381 | }, |
| 12382 | { |
| 12383 | .cmd = NL80211_CMD_DEL_KEY, |
| 12384 | .doit = nl80211_del_key, |
| 12385 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12386 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12387 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12388 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 12389 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12390 | { |
| 12391 | .cmd = NL80211_CMD_SET_BEACON, |
| 12392 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12393 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12394 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12395 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12396 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12397 | }, |
| 12398 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12399 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12400 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12401 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12402 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12403 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12404 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12405 | }, |
| 12406 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12407 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12408 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12409 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 12410 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12411 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12412 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 12413 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12414 | { |
| 12415 | .cmd = NL80211_CMD_GET_STATION, |
| 12416 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12417 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12418 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12419 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12420 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12421 | }, |
| 12422 | { |
| 12423 | .cmd = NL80211_CMD_SET_STATION, |
| 12424 | .doit = nl80211_set_station, |
| 12425 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12426 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12427 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12428 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12429 | }, |
| 12430 | { |
| 12431 | .cmd = NL80211_CMD_NEW_STATION, |
| 12432 | .doit = nl80211_new_station, |
| 12433 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12434 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12435 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12436 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12437 | }, |
| 12438 | { |
| 12439 | .cmd = NL80211_CMD_DEL_STATION, |
| 12440 | .doit = nl80211_del_station, |
| 12441 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12442 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12443 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12444 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 12445 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12446 | { |
| 12447 | .cmd = NL80211_CMD_GET_MPATH, |
| 12448 | .doit = nl80211_get_mpath, |
| 12449 | .dumpit = nl80211_dump_mpath, |
| 12450 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12451 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12452 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12453 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12454 | }, |
| 12455 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 12456 | .cmd = NL80211_CMD_GET_MPP, |
| 12457 | .doit = nl80211_get_mpp, |
| 12458 | .dumpit = nl80211_dump_mpp, |
| 12459 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12460 | .flags = GENL_UNS_ADMIN_PERM, |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 12461 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12462 | NL80211_FLAG_NEED_RTNL, |
| 12463 | }, |
| 12464 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12465 | .cmd = NL80211_CMD_SET_MPATH, |
| 12466 | .doit = nl80211_set_mpath, |
| 12467 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12468 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12469 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12470 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12471 | }, |
| 12472 | { |
| 12473 | .cmd = NL80211_CMD_NEW_MPATH, |
| 12474 | .doit = nl80211_new_mpath, |
| 12475 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12476 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12477 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12478 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12479 | }, |
| 12480 | { |
| 12481 | .cmd = NL80211_CMD_DEL_MPATH, |
| 12482 | .doit = nl80211_del_mpath, |
| 12483 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12484 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12485 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12486 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 12487 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 12488 | { |
| 12489 | .cmd = NL80211_CMD_SET_BSS, |
| 12490 | .doit = nl80211_set_bss, |
| 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 | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12494 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 12495 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12496 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12497 | .cmd = NL80211_CMD_GET_REG, |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 12498 | .doit = nl80211_get_reg_do, |
| 12499 | .dumpit = nl80211_get_reg_dump, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12500 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12501 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12502 | /* can be retrieved by unprivileged users */ |
| 12503 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 12504 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 12505 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12506 | .cmd = NL80211_CMD_SET_REG, |
| 12507 | .doit = nl80211_set_reg, |
| 12508 | .policy = nl80211_policy, |
| 12509 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 12510 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12511 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 12512 | #endif |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12513 | { |
| 12514 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 12515 | .doit = nl80211_req_set_reg, |
| 12516 | .policy = nl80211_policy, |
| 12517 | .flags = GENL_ADMIN_PERM, |
| 12518 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12519 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 12520 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 12521 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12522 | .policy = nl80211_policy, |
| 12523 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12524 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12525 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12526 | }, |
| 12527 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 12528 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 12529 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12530 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12531 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12532 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12533 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 12534 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 12535 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12536 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 12537 | .doit = nl80211_trigger_scan, |
| 12538 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12539 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 12540 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12541 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12542 | }, |
| 12543 | { |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 12544 | .cmd = NL80211_CMD_ABORT_SCAN, |
| 12545 | .doit = nl80211_abort_scan, |
| 12546 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12547 | .flags = GENL_UNS_ADMIN_PERM, |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 12548 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12549 | NL80211_FLAG_NEED_RTNL, |
| 12550 | }, |
| 12551 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 12552 | .cmd = NL80211_CMD_GET_SCAN, |
| 12553 | .policy = nl80211_policy, |
| 12554 | .dumpit = nl80211_dump_scan, |
| 12555 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12556 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12557 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 12558 | .doit = nl80211_start_sched_scan, |
| 12559 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12560 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12561 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12562 | NL80211_FLAG_NEED_RTNL, |
| 12563 | }, |
| 12564 | { |
| 12565 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 12566 | .doit = nl80211_stop_sched_scan, |
| 12567 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12568 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 12569 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12570 | NL80211_FLAG_NEED_RTNL, |
| 12571 | }, |
| 12572 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12573 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 12574 | .doit = nl80211_authenticate, |
| 12575 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12576 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12577 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12578 | NL80211_FLAG_NEED_RTNL | |
| 12579 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12580 | }, |
| 12581 | { |
| 12582 | .cmd = NL80211_CMD_ASSOCIATE, |
| 12583 | .doit = nl80211_associate, |
| 12584 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12585 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12586 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12587 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12588 | }, |
| 12589 | { |
| 12590 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 12591 | .doit = nl80211_deauthenticate, |
| 12592 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12593 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12594 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12595 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12596 | }, |
| 12597 | { |
| 12598 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 12599 | .doit = nl80211_disassociate, |
| 12600 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12601 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12602 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12603 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 12604 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12605 | { |
| 12606 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 12607 | .doit = nl80211_join_ibss, |
| 12608 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12609 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12610 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12611 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12612 | }, |
| 12613 | { |
| 12614 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 12615 | .doit = nl80211_leave_ibss, |
| 12616 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12617 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12618 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12619 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 12620 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 12621 | #ifdef CONFIG_NL80211_TESTMODE |
| 12622 | { |
| 12623 | .cmd = NL80211_CMD_TESTMODE, |
| 12624 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 12625 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 12626 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12627 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12628 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12629 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 12630 | }, |
| 12631 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12632 | { |
| 12633 | .cmd = NL80211_CMD_CONNECT, |
| 12634 | .doit = nl80211_connect, |
| 12635 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12636 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12637 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12638 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12639 | }, |
| 12640 | { |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 12641 | .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS, |
| 12642 | .doit = nl80211_update_connect_params, |
| 12643 | .policy = nl80211_policy, |
| 12644 | .flags = GENL_ADMIN_PERM, |
| 12645 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12646 | NL80211_FLAG_NEED_RTNL, |
| 12647 | }, |
| 12648 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12649 | .cmd = NL80211_CMD_DISCONNECT, |
| 12650 | .doit = nl80211_disconnect, |
| 12651 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12652 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 12653 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12654 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 12655 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 12656 | { |
| 12657 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 12658 | .doit = nl80211_wiphy_netns, |
| 12659 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12660 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12661 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12662 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 12663 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 12664 | { |
| 12665 | .cmd = NL80211_CMD_GET_SURVEY, |
| 12666 | .policy = nl80211_policy, |
| 12667 | .dumpit = nl80211_dump_survey, |
| 12668 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12669 | { |
| 12670 | .cmd = NL80211_CMD_SET_PMKSA, |
| 12671 | .doit = nl80211_setdel_pmksa, |
| 12672 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12673 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12674 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12675 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12676 | }, |
| 12677 | { |
| 12678 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 12679 | .doit = nl80211_setdel_pmksa, |
| 12680 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12681 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12682 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12683 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12684 | }, |
| 12685 | { |
| 12686 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 12687 | .doit = nl80211_flush_pmksa, |
| 12688 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12689 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12690 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12691 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 12692 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12693 | { |
| 12694 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 12695 | .doit = nl80211_remain_on_channel, |
| 12696 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12697 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12698 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12699 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12700 | }, |
| 12701 | { |
| 12702 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 12703 | .doit = nl80211_cancel_remain_on_channel, |
| 12704 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12705 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12706 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12707 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 12708 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 12709 | { |
| 12710 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 12711 | .doit = nl80211_set_tx_bitrate_mask, |
| 12712 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12713 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12714 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12715 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 12716 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12717 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12718 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 12719 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12720 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12721 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12722 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12723 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12724 | }, |
| 12725 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 12726 | .cmd = NL80211_CMD_FRAME, |
| 12727 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12728 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12729 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12730 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12731 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12732 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12733 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 12734 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 12735 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 12736 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12737 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 12738 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 12739 | NL80211_FLAG_NEED_RTNL, |
| 12740 | }, |
| 12741 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12742 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 12743 | .doit = nl80211_set_power_save, |
| 12744 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12745 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12746 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12747 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12748 | }, |
| 12749 | { |
| 12750 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 12751 | .doit = nl80211_get_power_save, |
| 12752 | .policy = nl80211_policy, |
| 12753 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12754 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12755 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 12756 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12757 | { |
| 12758 | .cmd = NL80211_CMD_SET_CQM, |
| 12759 | .doit = nl80211_set_cqm, |
| 12760 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12761 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12762 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12763 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12764 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 12765 | { |
| 12766 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 12767 | .doit = nl80211_set_channel, |
| 12768 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12769 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 12770 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12771 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 12772 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 12773 | { |
| 12774 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 12775 | .doit = nl80211_set_wds_peer, |
| 12776 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12777 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 12778 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12779 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 12780 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12781 | { |
| 12782 | .cmd = NL80211_CMD_JOIN_MESH, |
| 12783 | .doit = nl80211_join_mesh, |
| 12784 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12785 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12786 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12787 | NL80211_FLAG_NEED_RTNL, |
| 12788 | }, |
| 12789 | { |
| 12790 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 12791 | .doit = nl80211_leave_mesh, |
| 12792 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12793 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12794 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12795 | NL80211_FLAG_NEED_RTNL, |
| 12796 | }, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 12797 | { |
| 12798 | .cmd = NL80211_CMD_JOIN_OCB, |
| 12799 | .doit = nl80211_join_ocb, |
| 12800 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12801 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 12802 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12803 | NL80211_FLAG_NEED_RTNL, |
| 12804 | }, |
| 12805 | { |
| 12806 | .cmd = NL80211_CMD_LEAVE_OCB, |
| 12807 | .doit = nl80211_leave_ocb, |
| 12808 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12809 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 12810 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12811 | NL80211_FLAG_NEED_RTNL, |
| 12812 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 12813 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12814 | { |
| 12815 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 12816 | .doit = nl80211_get_wowlan, |
| 12817 | .policy = nl80211_policy, |
| 12818 | /* can be retrieved by unprivileged users */ |
| 12819 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12820 | NL80211_FLAG_NEED_RTNL, |
| 12821 | }, |
| 12822 | { |
| 12823 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 12824 | .doit = nl80211_set_wowlan, |
| 12825 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12826 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12827 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12828 | NL80211_FLAG_NEED_RTNL, |
| 12829 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 12830 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12831 | { |
| 12832 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 12833 | .doit = nl80211_set_rekey_data, |
| 12834 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12835 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12836 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 12837 | NL80211_FLAG_NEED_RTNL | |
| 12838 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12839 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 12840 | { |
| 12841 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 12842 | .doit = nl80211_tdls_mgmt, |
| 12843 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12844 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 12845 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12846 | NL80211_FLAG_NEED_RTNL, |
| 12847 | }, |
| 12848 | { |
| 12849 | .cmd = NL80211_CMD_TDLS_OPER, |
| 12850 | .doit = nl80211_tdls_oper, |
| 12851 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12852 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 12853 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12854 | NL80211_FLAG_NEED_RTNL, |
| 12855 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12856 | { |
| 12857 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 12858 | .doit = nl80211_register_unexpected_frame, |
| 12859 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12860 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12861 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12862 | NL80211_FLAG_NEED_RTNL, |
| 12863 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12864 | { |
| 12865 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 12866 | .doit = nl80211_probe_client, |
| 12867 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12868 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 12869 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12870 | NL80211_FLAG_NEED_RTNL, |
| 12871 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12872 | { |
| 12873 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 12874 | .doit = nl80211_register_beacons, |
| 12875 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12876 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12877 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 12878 | NL80211_FLAG_NEED_RTNL, |
| 12879 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 12880 | { |
| 12881 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 12882 | .doit = nl80211_set_noack_map, |
| 12883 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12884 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 12885 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12886 | NL80211_FLAG_NEED_RTNL, |
| 12887 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12888 | { |
| 12889 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 12890 | .doit = nl80211_start_p2p_device, |
| 12891 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12892 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12893 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 12894 | NL80211_FLAG_NEED_RTNL, |
| 12895 | }, |
| 12896 | { |
| 12897 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 12898 | .doit = nl80211_stop_p2p_device, |
| 12899 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12900 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12901 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12902 | NL80211_FLAG_NEED_RTNL, |
| 12903 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 12904 | { |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12905 | .cmd = NL80211_CMD_START_NAN, |
| 12906 | .doit = nl80211_start_nan, |
| 12907 | .policy = nl80211_policy, |
| 12908 | .flags = GENL_ADMIN_PERM, |
| 12909 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 12910 | NL80211_FLAG_NEED_RTNL, |
| 12911 | }, |
| 12912 | { |
| 12913 | .cmd = NL80211_CMD_STOP_NAN, |
| 12914 | .doit = nl80211_stop_nan, |
| 12915 | .policy = nl80211_policy, |
| 12916 | .flags = GENL_ADMIN_PERM, |
| 12917 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12918 | NL80211_FLAG_NEED_RTNL, |
| 12919 | }, |
| 12920 | { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12921 | .cmd = NL80211_CMD_ADD_NAN_FUNCTION, |
| 12922 | .doit = nl80211_nan_add_func, |
| 12923 | .policy = nl80211_policy, |
| 12924 | .flags = GENL_ADMIN_PERM, |
| 12925 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12926 | NL80211_FLAG_NEED_RTNL, |
| 12927 | }, |
| 12928 | { |
| 12929 | .cmd = NL80211_CMD_DEL_NAN_FUNCTION, |
| 12930 | .doit = nl80211_nan_del_func, |
| 12931 | .policy = nl80211_policy, |
| 12932 | .flags = GENL_ADMIN_PERM, |
| 12933 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12934 | NL80211_FLAG_NEED_RTNL, |
| 12935 | }, |
| 12936 | { |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 12937 | .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, |
| 12938 | .doit = nl80211_nan_change_config, |
| 12939 | .policy = nl80211_policy, |
| 12940 | .flags = GENL_ADMIN_PERM, |
| 12941 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12942 | NL80211_FLAG_NEED_RTNL, |
| 12943 | }, |
| 12944 | { |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 12945 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 12946 | .doit = nl80211_set_mcast_rate, |
| 12947 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12948 | .flags = GENL_UNS_ADMIN_PERM, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 12949 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12950 | NL80211_FLAG_NEED_RTNL, |
| 12951 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 12952 | { |
| 12953 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 12954 | .doit = nl80211_set_mac_acl, |
| 12955 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12956 | .flags = GENL_UNS_ADMIN_PERM, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 12957 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 12958 | NL80211_FLAG_NEED_RTNL, |
| 12959 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12960 | { |
| 12961 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 12962 | .doit = nl80211_start_radar_detection, |
| 12963 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12964 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12965 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12966 | NL80211_FLAG_NEED_RTNL, |
| 12967 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 12968 | { |
| 12969 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 12970 | .doit = nl80211_get_protocol_features, |
| 12971 | .policy = nl80211_policy, |
| 12972 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12973 | { |
| 12974 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 12975 | .doit = nl80211_update_ft_ies, |
| 12976 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12977 | .flags = GENL_UNS_ADMIN_PERM, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12978 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 12979 | NL80211_FLAG_NEED_RTNL, |
| 12980 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12981 | { |
| 12982 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 12983 | .doit = nl80211_crit_protocol_start, |
| 12984 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12985 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12986 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12987 | NL80211_FLAG_NEED_RTNL, |
| 12988 | }, |
| 12989 | { |
| 12990 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 12991 | .doit = nl80211_crit_protocol_stop, |
| 12992 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 12993 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12994 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 12995 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12996 | }, |
| 12997 | { |
| 12998 | .cmd = NL80211_CMD_GET_COALESCE, |
| 12999 | .doit = nl80211_get_coalesce, |
| 13000 | .policy = nl80211_policy, |
| 13001 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13002 | NL80211_FLAG_NEED_RTNL, |
| 13003 | }, |
| 13004 | { |
| 13005 | .cmd = NL80211_CMD_SET_COALESCE, |
| 13006 | .doit = nl80211_set_coalesce, |
| 13007 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13008 | .flags = GENL_UNS_ADMIN_PERM, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 13009 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13010 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 13011 | }, |
| 13012 | { |
| 13013 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 13014 | .doit = nl80211_channel_switch, |
| 13015 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13016 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 13017 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13018 | NL80211_FLAG_NEED_RTNL, |
| 13019 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13020 | { |
| 13021 | .cmd = NL80211_CMD_VENDOR, |
| 13022 | .doit = nl80211_vendor_cmd, |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13023 | .dumpit = nl80211_vendor_cmd_dump, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13024 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13025 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13026 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 13027 | NL80211_FLAG_NEED_RTNL, |
| 13028 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 13029 | { |
| 13030 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 13031 | .doit = nl80211_set_qos_map, |
| 13032 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13033 | .flags = GENL_UNS_ADMIN_PERM, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 13034 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13035 | NL80211_FLAG_NEED_RTNL, |
| 13036 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13037 | { |
| 13038 | .cmd = NL80211_CMD_ADD_TX_TS, |
| 13039 | .doit = nl80211_add_tx_ts, |
| 13040 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13041 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13042 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13043 | NL80211_FLAG_NEED_RTNL, |
| 13044 | }, |
| 13045 | { |
| 13046 | .cmd = NL80211_CMD_DEL_TX_TS, |
| 13047 | .doit = nl80211_del_tx_ts, |
| 13048 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13049 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13050 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13051 | NL80211_FLAG_NEED_RTNL, |
| 13052 | }, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 13053 | { |
| 13054 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, |
| 13055 | .doit = nl80211_tdls_channel_switch, |
| 13056 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13057 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 13058 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13059 | NL80211_FLAG_NEED_RTNL, |
| 13060 | }, |
| 13061 | { |
| 13062 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, |
| 13063 | .doit = nl80211_tdls_cancel_channel_switch, |
| 13064 | .policy = nl80211_policy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 13065 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 13066 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 13067 | NL80211_FLAG_NEED_RTNL, |
| 13068 | }, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 13069 | { |
| 13070 | .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST, |
| 13071 | .doit = nl80211_set_multicast_to_unicast, |
| 13072 | .policy = nl80211_policy, |
| 13073 | .flags = GENL_UNS_ADMIN_PERM, |
| 13074 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 13075 | NL80211_FLAG_NEED_RTNL, |
| 13076 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13077 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13078 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 13079 | static struct genl_family nl80211_fam __ro_after_init = { |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 13080 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 13081 | .hdrsize = 0, /* no private header */ |
| 13082 | .version = 1, /* no particular meaning now */ |
| 13083 | .maxattr = NL80211_ATTR_MAX, |
| 13084 | .netnsok = true, |
| 13085 | .pre_doit = nl80211_pre_doit, |
| 13086 | .post_doit = nl80211_post_doit, |
| 13087 | .module = THIS_MODULE, |
| 13088 | .ops = nl80211_ops, |
| 13089 | .n_ops = ARRAY_SIZE(nl80211_ops), |
| 13090 | .mcgrps = nl80211_mcgrps, |
| 13091 | .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps), |
| 13092 | }; |
| 13093 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13094 | /* notification functions */ |
| 13095 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 13096 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 13097 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13098 | { |
| 13099 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 13100 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13101 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 13102 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 13103 | cmd != NL80211_CMD_DEL_WIPHY); |
| 13104 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 13105 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13106 | if (!msg) |
| 13107 | return; |
| 13108 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 13109 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13110 | nlmsg_free(msg); |
| 13111 | return; |
| 13112 | } |
| 13113 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13114 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13115 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 13116 | } |
| 13117 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 13118 | void nl80211_notify_iface(struct cfg80211_registered_device *rdev, |
| 13119 | struct wireless_dev *wdev, |
| 13120 | enum nl80211_commands cmd) |
| 13121 | { |
| 13122 | struct sk_buff *msg; |
| 13123 | |
| 13124 | WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && |
| 13125 | cmd != NL80211_CMD_DEL_INTERFACE); |
| 13126 | |
| 13127 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13128 | if (!msg) |
| 13129 | return; |
| 13130 | |
| 13131 | if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, |
| 13132 | cmd == NL80211_CMD_DEL_INTERFACE) < 0) { |
| 13133 | nlmsg_free(msg); |
| 13134 | return; |
| 13135 | } |
| 13136 | |
| 13137 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 13138 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
| 13139 | } |
| 13140 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13141 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 13142 | struct cfg80211_registered_device *rdev) |
| 13143 | { |
| 13144 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 13145 | struct nlattr *nest; |
| 13146 | int i; |
| 13147 | |
| 13148 | if (WARN_ON(!req)) |
| 13149 | return 0; |
| 13150 | |
| 13151 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 13152 | if (!nest) |
| 13153 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13154 | for (i = 0; i < req->n_ssids; i++) { |
| 13155 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 13156 | goto nla_put_failure; |
| 13157 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13158 | nla_nest_end(msg, nest); |
| 13159 | |
| 13160 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 13161 | if (!nest) |
| 13162 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13163 | for (i = 0; i < req->n_channels; i++) { |
| 13164 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 13165 | goto nla_put_failure; |
| 13166 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13167 | nla_nest_end(msg, nest); |
| 13168 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13169 | if (req->ie && |
| 13170 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 13171 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13172 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 13173 | if (req->flags && |
| 13174 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 13175 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 13176 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 13177 | if (req->info.scan_start_tsf && |
| 13178 | (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, |
| 13179 | req->info.scan_start_tsf, NL80211_BSS_PAD) || |
| 13180 | nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, |
| 13181 | req->info.tsf_bssid))) |
| 13182 | goto nla_put_failure; |
| 13183 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13184 | return 0; |
| 13185 | nla_put_failure: |
| 13186 | return -ENOBUFS; |
| 13187 | } |
| 13188 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 13189 | static int nl80211_prep_scan_msg(struct sk_buff *msg, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13190 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 13191 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13192 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13193 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13194 | { |
| 13195 | void *hdr; |
| 13196 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13197 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13198 | if (!hdr) |
| 13199 | return -1; |
| 13200 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13201 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 13202 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13203 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13204 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13205 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13206 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13207 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 13208 | /* ignore errors and send incomplete event anyway */ |
| 13209 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13210 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 13211 | genlmsg_end(msg, hdr); |
| 13212 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13213 | |
| 13214 | nla_put_failure: |
| 13215 | genlmsg_cancel(msg, hdr); |
| 13216 | return -EMSGSIZE; |
| 13217 | } |
| 13218 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13219 | static int |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 13220 | nl80211_prep_sched_scan_msg(struct sk_buff *msg, |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 13221 | struct cfg80211_sched_scan_request *req, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13222 | { |
| 13223 | void *hdr; |
| 13224 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 13225 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13226 | if (!hdr) |
| 13227 | return -1; |
| 13228 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 13229 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, |
| 13230 | wiphy_to_rdev(req->wiphy)->wiphy_idx) || |
| 13231 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) || |
| 13232 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid, |
| 13233 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13234 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13235 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 13236 | genlmsg_end(msg, hdr); |
| 13237 | return 0; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13238 | |
| 13239 | nla_put_failure: |
| 13240 | genlmsg_cancel(msg, hdr); |
| 13241 | return -EMSGSIZE; |
| 13242 | } |
| 13243 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13244 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 13245 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13246 | { |
| 13247 | struct sk_buff *msg; |
| 13248 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13249 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13250 | if (!msg) |
| 13251 | return; |
| 13252 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 13253 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13254 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 13255 | nlmsg_free(msg); |
| 13256 | return; |
| 13257 | } |
| 13258 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13259 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13260 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 13261 | } |
| 13262 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13263 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 13264 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13265 | { |
| 13266 | struct sk_buff *msg; |
| 13267 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 13268 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13269 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13270 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13271 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 13272 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13273 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 13274 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13275 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13276 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13277 | } |
| 13278 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 13279 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13280 | } |
| 13281 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 13282 | /* send message created by nl80211_build_scan_msg() */ |
| 13283 | void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev, |
| 13284 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13285 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13286 | if (!msg) |
| 13287 | return; |
| 13288 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13289 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13290 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 13291 | } |
| 13292 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 13293 | void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13294 | { |
| 13295 | struct sk_buff *msg; |
| 13296 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13297 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13298 | if (!msg) |
| 13299 | return; |
| 13300 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 13301 | if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13302 | nlmsg_free(msg); |
| 13303 | return; |
| 13304 | } |
| 13305 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 13306 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13307 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 13308 | } |
| 13309 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 13310 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
| 13311 | struct regulatory_request *request) |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13312 | { |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13313 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13314 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 13315 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13316 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13317 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 13318 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 13319 | NL80211_REGDOM_TYPE_WORLD)) |
| 13320 | goto nla_put_failure; |
| 13321 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 13322 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 13323 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 13324 | goto nla_put_failure; |
| 13325 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 13326 | request->intersect) { |
| 13327 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 13328 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 13329 | goto nla_put_failure; |
| 13330 | } else { |
| 13331 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 13332 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 13333 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 13334 | request->alpha2)) |
| 13335 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13336 | } |
| 13337 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 13338 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
| 13339 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); |
| 13340 | |
| 13341 | if (wiphy && |
| 13342 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 13343 | goto nla_put_failure; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 13344 | |
| 13345 | if (wiphy && |
| 13346 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 13347 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 13348 | goto nla_put_failure; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 13349 | } |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13350 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 13351 | return true; |
| 13352 | |
| 13353 | nla_put_failure: |
| 13354 | return false; |
| 13355 | } |
| 13356 | |
| 13357 | /* |
| 13358 | * This can happen on global regulatory changes or device specific settings |
| 13359 | * based on custom regulatory domains. |
| 13360 | */ |
| 13361 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, |
| 13362 | struct regulatory_request *request) |
| 13363 | { |
| 13364 | struct sk_buff *msg; |
| 13365 | void *hdr; |
| 13366 | |
| 13367 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13368 | if (!msg) |
| 13369 | return; |
| 13370 | |
| 13371 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); |
| 13372 | if (!hdr) { |
| 13373 | nlmsg_free(msg); |
| 13374 | return; |
| 13375 | } |
| 13376 | |
| 13377 | if (nl80211_reg_change_event_fill(msg, request) == false) |
| 13378 | goto nla_put_failure; |
| 13379 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13380 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13381 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 13382 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13383 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13384 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 13385 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 13386 | |
| 13387 | return; |
| 13388 | |
| 13389 | nla_put_failure: |
| 13390 | genlmsg_cancel(msg, hdr); |
| 13391 | nlmsg_free(msg); |
| 13392 | } |
| 13393 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13394 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 13395 | struct net_device *netdev, |
| 13396 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13397 | enum nl80211_commands cmd, gfp_t gfp, |
| 13398 | int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13399 | { |
| 13400 | struct sk_buff *msg; |
| 13401 | void *hdr; |
| 13402 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 13403 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13404 | if (!msg) |
| 13405 | return; |
| 13406 | |
| 13407 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 13408 | if (!hdr) { |
| 13409 | nlmsg_free(msg); |
| 13410 | return; |
| 13411 | } |
| 13412 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13413 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13414 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13415 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 13416 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13417 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13418 | if (uapsd_queues >= 0) { |
| 13419 | struct nlattr *nla_wmm = |
| 13420 | nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 13421 | if (!nla_wmm) |
| 13422 | goto nla_put_failure; |
| 13423 | |
| 13424 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 13425 | uapsd_queues)) |
| 13426 | goto nla_put_failure; |
| 13427 | |
| 13428 | nla_nest_end(msg, nla_wmm); |
| 13429 | } |
| 13430 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13431 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13432 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13433 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13434 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13435 | return; |
| 13436 | |
| 13437 | nla_put_failure: |
| 13438 | genlmsg_cancel(msg, hdr); |
| 13439 | nlmsg_free(msg); |
| 13440 | } |
| 13441 | |
| 13442 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13443 | struct net_device *netdev, const u8 *buf, |
| 13444 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13445 | { |
| 13446 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13447 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13448 | } |
| 13449 | |
| 13450 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 13451 | struct net_device *netdev, const u8 *buf, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13452 | size_t len, gfp_t gfp, int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13453 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13454 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13455 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13456 | } |
| 13457 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 13458 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13459 | struct net_device *netdev, const u8 *buf, |
| 13460 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13461 | { |
| 13462 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13463 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13464 | } |
| 13465 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 13466 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 13467 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13468 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13469 | { |
| 13470 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13471 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13472 | } |
| 13473 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13474 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 13475 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13476 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13477 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13478 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13479 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13480 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 13481 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13482 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13483 | if (WARN_ON(len < 2)) |
| 13484 | return; |
| 13485 | |
| 13486 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 13487 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 13488 | else |
| 13489 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 13490 | |
| 13491 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 13492 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13493 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 13494 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 13495 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 13496 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 13497 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13498 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13499 | { |
| 13500 | struct sk_buff *msg; |
| 13501 | void *hdr; |
| 13502 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13503 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13504 | if (!msg) |
| 13505 | return; |
| 13506 | |
| 13507 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 13508 | if (!hdr) { |
| 13509 | nlmsg_free(msg); |
| 13510 | return; |
| 13511 | } |
| 13512 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13513 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13514 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13515 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 13516 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 13517 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13518 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13519 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13520 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13521 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13522 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13523 | return; |
| 13524 | |
| 13525 | nla_put_failure: |
| 13526 | genlmsg_cancel(msg, hdr); |
| 13527 | nlmsg_free(msg); |
| 13528 | } |
| 13529 | |
| 13530 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13531 | struct net_device *netdev, const u8 *addr, |
| 13532 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13533 | { |
| 13534 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13535 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13536 | } |
| 13537 | |
| 13538 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13539 | struct net_device *netdev, const u8 *addr, |
| 13540 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13541 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13542 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 13543 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 13544 | } |
| 13545 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13546 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 13547 | struct net_device *netdev, |
| 13548 | struct cfg80211_connect_resp_params *cr, |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 13549 | gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13550 | { |
| 13551 | struct sk_buff *msg; |
| 13552 | void *hdr; |
| 13553 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 13554 | msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len + |
| 13555 | cr->fils_kek_len + cr->pmk_len + |
| 13556 | (cr->pmkid ? WLAN_PMKID_LEN : 0), gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13557 | if (!msg) |
| 13558 | return; |
| 13559 | |
| 13560 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 13561 | if (!hdr) { |
| 13562 | nlmsg_free(msg); |
| 13563 | return; |
| 13564 | } |
| 13565 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13566 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13567 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 13568 | (cr->bssid && |
| 13569 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) || |
Jouni Malinen | bf1ecd2 | 2016-05-31 00:16:50 +0300 | [diff] [blame] | 13570 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 13571 | cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : |
| 13572 | cr->status) || |
| 13573 | (cr->status < 0 && |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 13574 | (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 13575 | nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON, |
| 13576 | cr->timeout_reason))) || |
| 13577 | (cr->req_ie && |
| 13578 | nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) || |
| 13579 | (cr->resp_ie && |
| 13580 | nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len, |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 13581 | cr->resp_ie)) || |
| 13582 | (cr->update_erp_next_seq_num && |
| 13583 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
| 13584 | cr->fils_erp_next_seq_num)) || |
| 13585 | (cr->status == WLAN_STATUS_SUCCESS && |
| 13586 | ((cr->fils_kek && |
| 13587 | nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils_kek_len, |
| 13588 | cr->fils_kek)) || |
| 13589 | (cr->pmk && |
| 13590 | nla_put(msg, NL80211_ATTR_PMK, cr->pmk_len, cr->pmk)) || |
| 13591 | (cr->pmkid && |
| 13592 | nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->pmkid))))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13593 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13594 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13595 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13596 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13597 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13598 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13599 | return; |
| 13600 | |
| 13601 | nla_put_failure: |
| 13602 | genlmsg_cancel(msg, hdr); |
| 13603 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13604 | } |
| 13605 | |
| 13606 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 13607 | struct net_device *netdev, const u8 *bssid, |
| 13608 | const u8 *req_ie, size_t req_ie_len, |
| 13609 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 13610 | { |
| 13611 | struct sk_buff *msg; |
| 13612 | void *hdr; |
| 13613 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 13614 | msg = nlmsg_new(100 + req_ie_len + resp_ie_len, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13615 | if (!msg) |
| 13616 | return; |
| 13617 | |
| 13618 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 13619 | if (!hdr) { |
| 13620 | nlmsg_free(msg); |
| 13621 | return; |
| 13622 | } |
| 13623 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13624 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13625 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13626 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 13627 | (req_ie && |
| 13628 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 13629 | (resp_ie && |
| 13630 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 13631 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13632 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13633 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13634 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13635 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13636 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13637 | return; |
| 13638 | |
| 13639 | nla_put_failure: |
| 13640 | genlmsg_cancel(msg, hdr); |
| 13641 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13642 | } |
| 13643 | |
| 13644 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 13645 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 13646 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13647 | { |
| 13648 | struct sk_buff *msg; |
| 13649 | void *hdr; |
| 13650 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 13651 | msg = nlmsg_new(100 + ie_len, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13652 | if (!msg) |
| 13653 | return; |
| 13654 | |
| 13655 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 13656 | if (!hdr) { |
| 13657 | nlmsg_free(msg); |
| 13658 | return; |
| 13659 | } |
| 13660 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13661 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13662 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13663 | (from_ap && reason && |
| 13664 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 13665 | (from_ap && |
| 13666 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 13667 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 13668 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13669 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13670 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13671 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13672 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13673 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13674 | return; |
| 13675 | |
| 13676 | nla_put_failure: |
| 13677 | genlmsg_cancel(msg, hdr); |
| 13678 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 13679 | } |
| 13680 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13681 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 13682 | struct net_device *netdev, const u8 *bssid, |
| 13683 | gfp_t gfp) |
| 13684 | { |
| 13685 | struct sk_buff *msg; |
| 13686 | void *hdr; |
| 13687 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 13688 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13689 | if (!msg) |
| 13690 | return; |
| 13691 | |
| 13692 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 13693 | if (!hdr) { |
| 13694 | nlmsg_free(msg); |
| 13695 | return; |
| 13696 | } |
| 13697 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13698 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13699 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13700 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 13701 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13702 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13703 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13704 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13705 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13706 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 13707 | return; |
| 13708 | |
| 13709 | nla_put_failure: |
| 13710 | genlmsg_cancel(msg, hdr); |
| 13711 | nlmsg_free(msg); |
| 13712 | } |
| 13713 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13714 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 13715 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13716 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13717 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13718 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13719 | struct sk_buff *msg; |
| 13720 | void *hdr; |
| 13721 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13722 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 13723 | return; |
| 13724 | |
| 13725 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 13726 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 13727 | msg = nlmsg_new(100 + ie_len, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13728 | if (!msg) |
| 13729 | return; |
| 13730 | |
| 13731 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 13732 | if (!hdr) { |
| 13733 | nlmsg_free(msg); |
| 13734 | return; |
| 13735 | } |
| 13736 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13737 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13738 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 13739 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13740 | (ie_len && ie && |
| 13741 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 13742 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13743 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13744 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13745 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13746 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13747 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13748 | return; |
| 13749 | |
| 13750 | nla_put_failure: |
| 13751 | genlmsg_cancel(msg, hdr); |
| 13752 | nlmsg_free(msg); |
| 13753 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13754 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 13755 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13756 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 13757 | struct net_device *netdev, const u8 *addr, |
| 13758 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13759 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13760 | { |
| 13761 | struct sk_buff *msg; |
| 13762 | void *hdr; |
| 13763 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 13764 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13765 | if (!msg) |
| 13766 | return; |
| 13767 | |
| 13768 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 13769 | if (!hdr) { |
| 13770 | nlmsg_free(msg); |
| 13771 | return; |
| 13772 | } |
| 13773 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13774 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13775 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 13776 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 13777 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 13778 | (key_id != -1 && |
| 13779 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 13780 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 13781 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13782 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13783 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13784 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13785 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13786 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 13787 | return; |
| 13788 | |
| 13789 | nla_put_failure: |
| 13790 | genlmsg_cancel(msg, hdr); |
| 13791 | nlmsg_free(msg); |
| 13792 | } |
| 13793 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13794 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 13795 | struct ieee80211_channel *channel_before, |
| 13796 | struct ieee80211_channel *channel_after) |
| 13797 | { |
| 13798 | struct sk_buff *msg; |
| 13799 | void *hdr; |
| 13800 | struct nlattr *nl_freq; |
| 13801 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 13802 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13803 | if (!msg) |
| 13804 | return; |
| 13805 | |
| 13806 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 13807 | if (!hdr) { |
| 13808 | nlmsg_free(msg); |
| 13809 | return; |
| 13810 | } |
| 13811 | |
| 13812 | /* |
| 13813 | * Since we are applying the beacon hint to a wiphy we know its |
| 13814 | * wiphy_idx is valid |
| 13815 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13816 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 13817 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13818 | |
| 13819 | /* Before */ |
| 13820 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 13821 | if (!nl_freq) |
| 13822 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 13823 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13824 | goto nla_put_failure; |
| 13825 | nla_nest_end(msg, nl_freq); |
| 13826 | |
| 13827 | /* After */ |
| 13828 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 13829 | if (!nl_freq) |
| 13830 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 13831 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13832 | goto nla_put_failure; |
| 13833 | nla_nest_end(msg, nl_freq); |
| 13834 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13835 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13836 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 13837 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13838 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13839 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 13840 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 13841 | |
| 13842 | return; |
| 13843 | |
| 13844 | nla_put_failure: |
| 13845 | genlmsg_cancel(msg, hdr); |
| 13846 | nlmsg_free(msg); |
| 13847 | } |
| 13848 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13849 | static void nl80211_send_remain_on_chan_event( |
| 13850 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13851 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13852 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13853 | unsigned int duration, gfp_t gfp) |
| 13854 | { |
| 13855 | struct sk_buff *msg; |
| 13856 | void *hdr; |
| 13857 | |
| 13858 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13859 | if (!msg) |
| 13860 | return; |
| 13861 | |
| 13862 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 13863 | if (!hdr) { |
| 13864 | nlmsg_free(msg); |
| 13865 | return; |
| 13866 | } |
| 13867 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13868 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13869 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13870 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13871 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13872 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13873 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 13874 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 13875 | NL80211_CHAN_NO_HT) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13876 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 13877 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13878 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13879 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13880 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 13881 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 13882 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13883 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 13884 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13885 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13886 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13887 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13888 | return; |
| 13889 | |
| 13890 | nla_put_failure: |
| 13891 | genlmsg_cancel(msg, hdr); |
| 13892 | nlmsg_free(msg); |
| 13893 | } |
| 13894 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13895 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 13896 | struct ieee80211_channel *chan, |
| 13897 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13898 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13899 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13900 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13901 | |
| 13902 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13903 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 13904 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 13905 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13906 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13907 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13908 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13909 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 13910 | struct ieee80211_channel *chan, |
| 13911 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13912 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13913 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13914 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13915 | |
| 13916 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13917 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 13918 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13919 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13920 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 13921 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13922 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 13923 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 13924 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13925 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13926 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 13927 | struct sk_buff *msg; |
| 13928 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13929 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 13930 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13931 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 13932 | if (!msg) |
| 13933 | return; |
| 13934 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 13935 | 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] | 13936 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 13937 | nlmsg_free(msg); |
| 13938 | return; |
| 13939 | } |
| 13940 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13941 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13942 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 13943 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13944 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 13945 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 13946 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
| 13947 | struct station_info *sinfo, gfp_t gfp) |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13948 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13949 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13950 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13951 | struct sk_buff *msg; |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 13952 | struct station_info empty_sinfo = {}; |
| 13953 | |
| 13954 | if (!sinfo) |
| 13955 | sinfo = &empty_sinfo; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13956 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13957 | trace_cfg80211_del_sta(dev, mac_addr); |
| 13958 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 13959 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13960 | if (!msg) |
| 13961 | return; |
| 13962 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 13963 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
Johannes Berg | 5700712 | 2015-01-16 21:05:02 +0100 | [diff] [blame] | 13964 | rdev, dev, mac_addr, sinfo) < 0) { |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13965 | nlmsg_free(msg); |
| 13966 | return; |
| 13967 | } |
| 13968 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 13969 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 13970 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13971 | } |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 13972 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 13973 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13974 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 13975 | enum nl80211_connect_failed_reason reason, |
| 13976 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 13977 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 13978 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13979 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 13980 | struct sk_buff *msg; |
| 13981 | void *hdr; |
| 13982 | |
| 13983 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 13984 | if (!msg) |
| 13985 | return; |
| 13986 | |
| 13987 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 13988 | if (!hdr) { |
| 13989 | nlmsg_free(msg); |
| 13990 | return; |
| 13991 | } |
| 13992 | |
| 13993 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 13994 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 13995 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 13996 | goto nla_put_failure; |
| 13997 | |
| 13998 | genlmsg_end(msg, hdr); |
| 13999 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14000 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14001 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 14002 | return; |
| 14003 | |
| 14004 | nla_put_failure: |
| 14005 | genlmsg_cancel(msg, hdr); |
| 14006 | nlmsg_free(msg); |
| 14007 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14008 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 14009 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14010 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 14011 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14012 | { |
| 14013 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14014 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14015 | struct sk_buff *msg; |
| 14016 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14017 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14018 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14019 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14020 | return false; |
| 14021 | |
| 14022 | msg = nlmsg_new(100, gfp); |
| 14023 | if (!msg) |
| 14024 | return true; |
| 14025 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14026 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14027 | if (!hdr) { |
| 14028 | nlmsg_free(msg); |
| 14029 | return true; |
| 14030 | } |
| 14031 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14032 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14033 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 14034 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 14035 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14036 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14037 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14038 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14039 | return true; |
| 14040 | |
| 14041 | nla_put_failure: |
| 14042 | genlmsg_cancel(msg, hdr); |
| 14043 | nlmsg_free(msg); |
| 14044 | return true; |
| 14045 | } |
| 14046 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14047 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 14048 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14049 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14050 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14051 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14052 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14053 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 14054 | |
| 14055 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 14056 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 14057 | trace_cfg80211_return_bool(false); |
| 14058 | return false; |
| 14059 | } |
| 14060 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 14061 | addr, gfp); |
| 14062 | trace_cfg80211_return_bool(ret); |
| 14063 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14064 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14065 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 14066 | |
| 14067 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 14068 | const u8 *addr, gfp_t gfp) |
| 14069 | { |
| 14070 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14071 | bool ret; |
| 14072 | |
| 14073 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 14074 | |
| 14075 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 14076 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 14077 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 14078 | trace_cfg80211_return_bool(false); |
| 14079 | return false; |
| 14080 | } |
| 14081 | ret = __nl80211_unexpected_frame(dev, |
| 14082 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 14083 | addr, gfp); |
| 14084 | trace_cfg80211_return_bool(ret); |
| 14085 | return ret; |
| 14086 | } |
| 14087 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 14088 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14089 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14090 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 14091 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 14092 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14093 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14094 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14095 | struct sk_buff *msg; |
| 14096 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14097 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 14098 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14099 | if (!msg) |
| 14100 | return -ENOMEM; |
| 14101 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14102 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14103 | if (!hdr) { |
| 14104 | nlmsg_free(msg); |
| 14105 | return -ENOMEM; |
| 14106 | } |
| 14107 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14108 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14109 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 14110 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14111 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14112 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14113 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 14114 | (sig_dbm && |
| 14115 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 14116 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 14117 | (flags && |
| 14118 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14119 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14120 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14121 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14122 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14123 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14124 | |
| 14125 | nla_put_failure: |
| 14126 | genlmsg_cancel(msg, hdr); |
| 14127 | nlmsg_free(msg); |
| 14128 | return -ENOBUFS; |
| 14129 | } |
| 14130 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14131 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 14132 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14133 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14134 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14135 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14136 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14137 | struct sk_buff *msg; |
| 14138 | void *hdr; |
| 14139 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14140 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 14141 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 14142 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14143 | if (!msg) |
| 14144 | return; |
| 14145 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14146 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14147 | if (!hdr) { |
| 14148 | nlmsg_free(msg); |
| 14149 | return; |
| 14150 | } |
| 14151 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14152 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14153 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 14154 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14155 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14156 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14157 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14158 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 14159 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14160 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 14161 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14162 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14163 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14164 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14165 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14166 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14167 | return; |
| 14168 | |
| 14169 | nla_put_failure: |
| 14170 | genlmsg_cancel(msg, hdr); |
| 14171 | nlmsg_free(msg); |
| 14172 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14173 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14174 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14175 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
| 14176 | const char *mac, gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14177 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14178 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14179 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 14180 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 14181 | void **cb; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14182 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14183 | if (!msg) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14184 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14185 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14186 | cb = (void **)msg->cb; |
| 14187 | |
| 14188 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 14189 | if (!cb[0]) { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14190 | nlmsg_free(msg); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14191 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14192 | } |
| 14193 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14194 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14195 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14196 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14197 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14198 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14199 | goto nla_put_failure; |
| 14200 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14201 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 14202 | if (!cb[1]) |
| 14203 | goto nla_put_failure; |
| 14204 | |
| 14205 | cb[2] = rdev; |
| 14206 | |
| 14207 | return msg; |
| 14208 | nla_put_failure: |
| 14209 | nlmsg_free(msg); |
| 14210 | return NULL; |
| 14211 | } |
| 14212 | |
| 14213 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) |
| 14214 | { |
| 14215 | void **cb = (void **)msg->cb; |
| 14216 | struct cfg80211_registered_device *rdev = cb[2]; |
| 14217 | |
| 14218 | nla_nest_end(msg, cb[1]); |
| 14219 | genlmsg_end(msg, cb[0]); |
| 14220 | |
| 14221 | memset(msg->cb, 0, sizeof(msg->cb)); |
| 14222 | |
| 14223 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 14224 | NL80211_MCGRP_MLME, gfp); |
| 14225 | } |
| 14226 | |
| 14227 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 14228 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 14229 | s32 rssi_level, gfp_t gfp) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14230 | { |
| 14231 | struct sk_buff *msg; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 14232 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14233 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14234 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 14235 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14236 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 14237 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
| 14238 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) |
| 14239 | return; |
| 14240 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 14241 | if (wdev->cqm_config) { |
| 14242 | wdev->cqm_config->last_rssi_event_value = rssi_level; |
| 14243 | |
| 14244 | cfg80211_cqm_rssi_update(rdev, dev); |
| 14245 | |
| 14246 | if (rssi_level == 0) |
| 14247 | rssi_level = wdev->cqm_config->last_rssi_event_value; |
| 14248 | } |
| 14249 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14250 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 14251 | if (!msg) |
| 14252 | return; |
| 14253 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14254 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 14255 | rssi_event)) |
| 14256 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14257 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 14258 | if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL, |
| 14259 | rssi_level)) |
| 14260 | goto nla_put_failure; |
| 14261 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14262 | cfg80211_send_cqm(msg, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14263 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14264 | return; |
| 14265 | |
| 14266 | nla_put_failure: |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14267 | nlmsg_free(msg); |
| 14268 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14269 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14270 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 14271 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 14272 | const u8 *peer, u32 num_packets, |
| 14273 | u32 rate, u32 intvl, gfp_t gfp) |
| 14274 | { |
| 14275 | struct sk_buff *msg; |
| 14276 | |
| 14277 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 14278 | if (!msg) |
| 14279 | return; |
| 14280 | |
| 14281 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 14282 | goto nla_put_failure; |
| 14283 | |
| 14284 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 14285 | goto nla_put_failure; |
| 14286 | |
| 14287 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 14288 | goto nla_put_failure; |
| 14289 | |
| 14290 | cfg80211_send_cqm(msg, gfp); |
| 14291 | return; |
| 14292 | |
| 14293 | nla_put_failure: |
| 14294 | nlmsg_free(msg); |
| 14295 | } |
| 14296 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
| 14297 | |
| 14298 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 14299 | const u8 *peer, u32 num_packets, gfp_t gfp) |
| 14300 | { |
| 14301 | struct sk_buff *msg; |
| 14302 | |
| 14303 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 14304 | |
| 14305 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 14306 | if (!msg) |
| 14307 | return; |
| 14308 | |
| 14309 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 14310 | goto nla_put_failure; |
| 14311 | |
| 14312 | cfg80211_send_cqm(msg, gfp); |
| 14313 | return; |
| 14314 | |
| 14315 | nla_put_failure: |
| 14316 | nlmsg_free(msg); |
| 14317 | } |
| 14318 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
| 14319 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 14320 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
| 14321 | { |
| 14322 | struct sk_buff *msg; |
| 14323 | |
| 14324 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 14325 | if (!msg) |
| 14326 | return; |
| 14327 | |
| 14328 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) |
| 14329 | goto nla_put_failure; |
| 14330 | |
| 14331 | cfg80211_send_cqm(msg, gfp); |
| 14332 | return; |
| 14333 | |
| 14334 | nla_put_failure: |
| 14335 | nlmsg_free(msg); |
| 14336 | } |
| 14337 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); |
| 14338 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14339 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 14340 | struct net_device *netdev, const u8 *bssid, |
| 14341 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14342 | { |
| 14343 | struct sk_buff *msg; |
| 14344 | struct nlattr *rekey_attr; |
| 14345 | void *hdr; |
| 14346 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14347 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14348 | if (!msg) |
| 14349 | return; |
| 14350 | |
| 14351 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 14352 | if (!hdr) { |
| 14353 | nlmsg_free(msg); |
| 14354 | return; |
| 14355 | } |
| 14356 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14357 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14358 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 14359 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 14360 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14361 | |
| 14362 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 14363 | if (!rekey_attr) |
| 14364 | goto nla_put_failure; |
| 14365 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14366 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 14367 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 14368 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14369 | |
| 14370 | nla_nest_end(msg, rekey_attr); |
| 14371 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14372 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14373 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14374 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14375 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14376 | return; |
| 14377 | |
| 14378 | nla_put_failure: |
| 14379 | genlmsg_cancel(msg, hdr); |
| 14380 | nlmsg_free(msg); |
| 14381 | } |
| 14382 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14383 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 14384 | const u8 *replay_ctr, gfp_t gfp) |
| 14385 | { |
| 14386 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14387 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14388 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14389 | |
| 14390 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 14391 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 14392 | } |
| 14393 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 14394 | |
| 14395 | static void |
| 14396 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 14397 | struct net_device *netdev, int index, |
| 14398 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14399 | { |
| 14400 | struct sk_buff *msg; |
| 14401 | struct nlattr *attr; |
| 14402 | void *hdr; |
| 14403 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14404 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14405 | if (!msg) |
| 14406 | return; |
| 14407 | |
| 14408 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 14409 | if (!hdr) { |
| 14410 | nlmsg_free(msg); |
| 14411 | return; |
| 14412 | } |
| 14413 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14414 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14415 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 14416 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14417 | |
| 14418 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 14419 | if (!attr) |
| 14420 | goto nla_put_failure; |
| 14421 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14422 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 14423 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 14424 | (preauth && |
| 14425 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 14426 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14427 | |
| 14428 | nla_nest_end(msg, attr); |
| 14429 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 14430 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14431 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14432 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14433 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 14434 | return; |
| 14435 | |
| 14436 | nla_put_failure: |
| 14437 | genlmsg_cancel(msg, hdr); |
| 14438 | nlmsg_free(msg); |
| 14439 | } |
| 14440 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14441 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 14442 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 14443 | { |
| 14444 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14445 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14446 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14447 | |
| 14448 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 14449 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 14450 | } |
| 14451 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 14452 | |
| 14453 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 14454 | struct net_device *netdev, |
| 14455 | struct cfg80211_chan_def *chandef, |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14456 | gfp_t gfp, |
| 14457 | enum nl80211_commands notif, |
| 14458 | u8 count) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14459 | { |
| 14460 | struct sk_buff *msg; |
| 14461 | void *hdr; |
| 14462 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14463 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14464 | if (!msg) |
| 14465 | return; |
| 14466 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14467 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14468 | if (!hdr) { |
| 14469 | nlmsg_free(msg); |
| 14470 | return; |
| 14471 | } |
| 14472 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 14473 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 14474 | goto nla_put_failure; |
| 14475 | |
| 14476 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 14477 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14478 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14479 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
| 14480 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) |
| 14481 | goto nla_put_failure; |
| 14482 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14483 | genlmsg_end(msg, hdr); |
| 14484 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14485 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14486 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 14487 | return; |
| 14488 | |
| 14489 | nla_put_failure: |
| 14490 | genlmsg_cancel(msg, hdr); |
| 14491 | nlmsg_free(msg); |
| 14492 | } |
| 14493 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14494 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 14495 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 14496 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14497 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14498 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14499 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14500 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 14501 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14502 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 14503 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14504 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 14505 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 14506 | wdev->preset_chandef = *chandef; |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14507 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 14508 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 14509 | } |
| 14510 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 14511 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 14512 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
| 14513 | struct cfg80211_chan_def *chandef, |
| 14514 | u8 count) |
| 14515 | { |
| 14516 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14517 | struct wiphy *wiphy = wdev->wiphy; |
| 14518 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 14519 | |
| 14520 | trace_cfg80211_ch_switch_started_notify(dev, chandef); |
| 14521 | |
| 14522 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 14523 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); |
| 14524 | } |
| 14525 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); |
| 14526 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 14527 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14528 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 14529 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14530 | enum nl80211_radar_event event, |
| 14531 | struct net_device *netdev, gfp_t gfp) |
| 14532 | { |
| 14533 | struct sk_buff *msg; |
| 14534 | void *hdr; |
| 14535 | |
| 14536 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 14537 | if (!msg) |
| 14538 | return; |
| 14539 | |
| 14540 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 14541 | if (!hdr) { |
| 14542 | nlmsg_free(msg); |
| 14543 | return; |
| 14544 | } |
| 14545 | |
| 14546 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 14547 | goto nla_put_failure; |
| 14548 | |
| 14549 | /* NOP and radar events don't need a netdev parameter */ |
| 14550 | if (netdev) { |
| 14551 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 14552 | |
| 14553 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14554 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14555 | NL80211_ATTR_PAD)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14556 | goto nla_put_failure; |
| 14557 | } |
| 14558 | |
| 14559 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 14560 | goto nla_put_failure; |
| 14561 | |
| 14562 | if (nl80211_send_chandef(msg, chandef)) |
| 14563 | goto nla_put_failure; |
| 14564 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14565 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14566 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14567 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14568 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 14569 | return; |
| 14570 | |
| 14571 | nla_put_failure: |
| 14572 | genlmsg_cancel(msg, hdr); |
| 14573 | nlmsg_free(msg); |
| 14574 | } |
| 14575 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14576 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 14577 | u64 cookie, bool acked, gfp_t gfp) |
| 14578 | { |
| 14579 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14580 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14581 | struct sk_buff *msg; |
| 14582 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14583 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 14584 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 14585 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 14586 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 14587 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14588 | if (!msg) |
| 14589 | return; |
| 14590 | |
| 14591 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 14592 | if (!hdr) { |
| 14593 | nlmsg_free(msg); |
| 14594 | return; |
| 14595 | } |
| 14596 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14597 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14598 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 14599 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14600 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 14601 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 14602 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 14603 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14604 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14605 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14606 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14607 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14608 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14609 | return; |
| 14610 | |
| 14611 | nla_put_failure: |
| 14612 | genlmsg_cancel(msg, hdr); |
| 14613 | nlmsg_free(msg); |
| 14614 | } |
| 14615 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 14616 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14617 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 14618 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14619 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14620 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14621 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14622 | struct sk_buff *msg; |
| 14623 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14624 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14625 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 14626 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 14627 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14628 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 14629 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 14630 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 14631 | if (!msg) { |
| 14632 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 14633 | return; |
| 14634 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14635 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14636 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 14637 | if (!hdr) |
| 14638 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14639 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14640 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14641 | (freq && |
| 14642 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 14643 | (sig_dbm && |
| 14644 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 14645 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 14646 | goto nla_put_failure; |
| 14647 | |
| 14648 | genlmsg_end(msg, hdr); |
| 14649 | |
| 14650 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14651 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14652 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14653 | return; |
| 14654 | |
| 14655 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14656 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 14657 | if (hdr) |
| 14658 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14659 | nlmsg_free(msg); |
| 14660 | } |
| 14661 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 14662 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14663 | #ifdef CONFIG_PM |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 14664 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
| 14665 | struct cfg80211_wowlan_wakeup *wakeup) |
| 14666 | { |
| 14667 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; |
| 14668 | struct nlattr *nl_results, *nl_match, *nl_freqs; |
| 14669 | int i, j; |
| 14670 | |
| 14671 | nl_results = nla_nest_start( |
| 14672 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); |
| 14673 | if (!nl_results) |
| 14674 | return -EMSGSIZE; |
| 14675 | |
| 14676 | for (i = 0; i < nd->n_matches; i++) { |
| 14677 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; |
| 14678 | |
| 14679 | nl_match = nla_nest_start(msg, i); |
| 14680 | if (!nl_match) |
| 14681 | break; |
| 14682 | |
| 14683 | /* The SSID attribute is optional in nl80211, but for |
| 14684 | * simplicity reasons it's always present in the |
| 14685 | * cfg80211 structure. If a driver can't pass the |
| 14686 | * SSID, that needs to be changed. A zero length SSID |
| 14687 | * is still a valid SSID (wildcard), so it cannot be |
| 14688 | * used for this purpose. |
| 14689 | */ |
| 14690 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, |
| 14691 | match->ssid.ssid)) { |
| 14692 | nla_nest_cancel(msg, nl_match); |
| 14693 | goto out; |
| 14694 | } |
| 14695 | |
| 14696 | if (match->n_channels) { |
| 14697 | nl_freqs = nla_nest_start( |
| 14698 | msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 14699 | if (!nl_freqs) { |
| 14700 | nla_nest_cancel(msg, nl_match); |
| 14701 | goto out; |
| 14702 | } |
| 14703 | |
| 14704 | for (j = 0; j < match->n_channels; j++) { |
Samuel Tan | 5528fae8 | 2015-02-09 21:29:15 +0200 | [diff] [blame] | 14705 | if (nla_put_u32(msg, j, match->channels[j])) { |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 14706 | nla_nest_cancel(msg, nl_freqs); |
| 14707 | nla_nest_cancel(msg, nl_match); |
| 14708 | goto out; |
| 14709 | } |
| 14710 | } |
| 14711 | |
| 14712 | nla_nest_end(msg, nl_freqs); |
| 14713 | } |
| 14714 | |
| 14715 | nla_nest_end(msg, nl_match); |
| 14716 | } |
| 14717 | |
| 14718 | out: |
| 14719 | nla_nest_end(msg, nl_results); |
| 14720 | return 0; |
| 14721 | } |
| 14722 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14723 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 14724 | struct cfg80211_wowlan_wakeup *wakeup, |
| 14725 | gfp_t gfp) |
| 14726 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14727 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14728 | struct sk_buff *msg; |
| 14729 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14730 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14731 | |
| 14732 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 14733 | |
| 14734 | if (wakeup) |
| 14735 | size += wakeup->packet_present_len; |
| 14736 | |
| 14737 | msg = nlmsg_new(size, gfp); |
| 14738 | if (!msg) |
| 14739 | return; |
| 14740 | |
| 14741 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 14742 | if (!hdr) |
| 14743 | goto free_msg; |
| 14744 | |
| 14745 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14746 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 14747 | NL80211_ATTR_PAD)) |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14748 | goto free_msg; |
| 14749 | |
| 14750 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 14751 | wdev->netdev->ifindex)) |
| 14752 | goto free_msg; |
| 14753 | |
| 14754 | if (wakeup) { |
| 14755 | struct nlattr *reasons; |
| 14756 | |
| 14757 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 14758 | if (!reasons) |
| 14759 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14760 | |
| 14761 | if (wakeup->disconnect && |
| 14762 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 14763 | goto free_msg; |
| 14764 | if (wakeup->magic_pkt && |
| 14765 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 14766 | goto free_msg; |
| 14767 | if (wakeup->gtk_rekey_failure && |
| 14768 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 14769 | goto free_msg; |
| 14770 | if (wakeup->eap_identity_req && |
| 14771 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 14772 | goto free_msg; |
| 14773 | if (wakeup->four_way_handshake && |
| 14774 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 14775 | goto free_msg; |
| 14776 | if (wakeup->rfkill_release && |
| 14777 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 14778 | goto free_msg; |
| 14779 | |
| 14780 | if (wakeup->pattern_idx >= 0 && |
| 14781 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 14782 | wakeup->pattern_idx)) |
| 14783 | goto free_msg; |
| 14784 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14785 | if (wakeup->tcp_match && |
| 14786 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 14787 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 14788 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14789 | if (wakeup->tcp_connlost && |
| 14790 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 14791 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 14792 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14793 | if (wakeup->tcp_nomoretokens && |
| 14794 | nla_put_flag(msg, |
| 14795 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 14796 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 14797 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14798 | if (wakeup->packet) { |
| 14799 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 14800 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 14801 | |
| 14802 | if (!wakeup->packet_80211) { |
| 14803 | pkt_attr = |
| 14804 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 14805 | len_attr = |
| 14806 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 14807 | } |
| 14808 | |
| 14809 | if (wakeup->packet_len && |
| 14810 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 14811 | goto free_msg; |
| 14812 | |
| 14813 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 14814 | wakeup->packet)) |
| 14815 | goto free_msg; |
| 14816 | } |
| 14817 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 14818 | if (wakeup->net_detect && |
| 14819 | cfg80211_net_detect_results(msg, wakeup)) |
| 14820 | goto free_msg; |
| 14821 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14822 | nla_nest_end(msg, reasons); |
| 14823 | } |
| 14824 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14825 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14826 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14827 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14828 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 14829 | return; |
| 14830 | |
| 14831 | free_msg: |
| 14832 | nlmsg_free(msg); |
| 14833 | } |
| 14834 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 14835 | #endif |
| 14836 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 14837 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 14838 | enum nl80211_tdls_operation oper, |
| 14839 | u16 reason_code, gfp_t gfp) |
| 14840 | { |
| 14841 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14842 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 14843 | struct sk_buff *msg; |
| 14844 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 14845 | |
| 14846 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 14847 | reason_code); |
| 14848 | |
| 14849 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 14850 | if (!msg) |
| 14851 | return; |
| 14852 | |
| 14853 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 14854 | if (!hdr) { |
| 14855 | nlmsg_free(msg); |
| 14856 | return; |
| 14857 | } |
| 14858 | |
| 14859 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14860 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 14861 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 14862 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 14863 | (reason_code > 0 && |
| 14864 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 14865 | goto nla_put_failure; |
| 14866 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14867 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 14868 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14869 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14870 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 14871 | return; |
| 14872 | |
| 14873 | nla_put_failure: |
| 14874 | genlmsg_cancel(msg, hdr); |
| 14875 | nlmsg_free(msg); |
| 14876 | } |
| 14877 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 14878 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14879 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 14880 | unsigned long state, |
| 14881 | void *_notify) |
| 14882 | { |
| 14883 | struct netlink_notify *notify = _notify; |
| 14884 | struct cfg80211_registered_device *rdev; |
| 14885 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14886 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14887 | |
Dmitry Ivanov | 8f815cd | 2016-04-06 17:23:18 +0300 | [diff] [blame] | 14888 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14889 | return NOTIFY_DONE; |
| 14890 | |
| 14891 | rcu_read_lock(); |
| 14892 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14893 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 14894 | bool schedule_destroy_work = false; |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 14895 | struct cfg80211_sched_scan_request *sched_scan_req = |
| 14896 | rcu_dereference(rdev->sched_scan_req); |
| 14897 | |
| 14898 | if (sched_scan_req && notify->portid && |
Johannes Berg | 753aacf | 2017-01-05 10:57:14 +0100 | [diff] [blame] | 14899 | sched_scan_req->owner_nlportid == notify->portid) { |
| 14900 | sched_scan_req->owner_nlportid = 0; |
| 14901 | |
| 14902 | if (rdev->ops->sched_scan_stop && |
| 14903 | rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
| 14904 | schedule_work(&rdev->sched_scan_stop_wk); |
| 14905 | } |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 14906 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 14907 | list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 14908 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14909 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 14910 | if (wdev->owner_nlportid == notify->portid) |
| 14911 | schedule_destroy_work = true; |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 14912 | else if (wdev->conn_owner_nlportid == notify->portid) |
| 14913 | schedule_work(&wdev->disconnect_wk); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 14914 | } |
| 14915 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 14916 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 14917 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 14918 | list) { |
| 14919 | if (reg->nlportid == notify->portid) { |
| 14920 | list_del(®->list); |
| 14921 | kfree(reg); |
| 14922 | break; |
| 14923 | } |
| 14924 | } |
| 14925 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 14926 | |
| 14927 | if (schedule_destroy_work) { |
| 14928 | struct cfg80211_iface_destroy *destroy; |
| 14929 | |
| 14930 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); |
| 14931 | if (destroy) { |
| 14932 | destroy->nlportid = notify->portid; |
| 14933 | spin_lock(&rdev->destroy_list_lock); |
| 14934 | list_add(&destroy->list, &rdev->destroy_list); |
| 14935 | spin_unlock(&rdev->destroy_list_lock); |
| 14936 | schedule_work(&rdev->destroy_work); |
| 14937 | } |
| 14938 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14939 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14940 | |
| 14941 | rcu_read_unlock(); |
| 14942 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 14943 | /* |
| 14944 | * It is possible that the user space process that is controlling the |
| 14945 | * indoor setting disappeared, so notify the regulatory core. |
| 14946 | */ |
| 14947 | regulatory_netlink_notify(notify->portid); |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 14948 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14949 | } |
| 14950 | |
| 14951 | static struct notifier_block nl80211_netlink_notifier = { |
| 14952 | .notifier_call = nl80211_netlink_notify, |
| 14953 | }; |
| 14954 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14955 | void cfg80211_ft_event(struct net_device *netdev, |
| 14956 | struct cfg80211_ft_event_params *ft_event) |
| 14957 | { |
| 14958 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14959 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14960 | struct sk_buff *msg; |
| 14961 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14962 | |
| 14963 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 14964 | |
| 14965 | if (!ft_event->target_ap) |
| 14966 | return; |
| 14967 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 14968 | msg = nlmsg_new(100 + ft_event->ric_ies_len, GFP_KERNEL); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14969 | if (!msg) |
| 14970 | return; |
| 14971 | |
| 14972 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14973 | if (!hdr) |
| 14974 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14975 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14976 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 14977 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 14978 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 14979 | goto out; |
| 14980 | |
| 14981 | if (ft_event->ies && |
| 14982 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 14983 | goto out; |
| 14984 | if (ft_event->ric_ies && |
| 14985 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 14986 | ft_event->ric_ies)) |
| 14987 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14988 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 14989 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14990 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 14991 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 14992 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 14993 | return; |
| 14994 | out: |
| 14995 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 14996 | } |
| 14997 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 14998 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 14999 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 15000 | { |
| 15001 | struct cfg80211_registered_device *rdev; |
| 15002 | struct sk_buff *msg; |
| 15003 | void *hdr; |
| 15004 | u32 nlportid; |
| 15005 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15006 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15007 | if (!rdev->crit_proto_nlportid) |
| 15008 | return; |
| 15009 | |
| 15010 | nlportid = rdev->crit_proto_nlportid; |
| 15011 | rdev->crit_proto_nlportid = 0; |
| 15012 | |
| 15013 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 15014 | if (!msg) |
| 15015 | return; |
| 15016 | |
| 15017 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 15018 | if (!hdr) |
| 15019 | goto nla_put_failure; |
| 15020 | |
| 15021 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15022 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 15023 | NL80211_ATTR_PAD)) |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15024 | goto nla_put_failure; |
| 15025 | |
| 15026 | genlmsg_end(msg, hdr); |
| 15027 | |
| 15028 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 15029 | return; |
| 15030 | |
| 15031 | nla_put_failure: |
| 15032 | if (hdr) |
| 15033 | genlmsg_cancel(msg, hdr); |
| 15034 | nlmsg_free(msg); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15035 | } |
| 15036 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 15037 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 15038 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 15039 | { |
| 15040 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15041 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 15042 | struct sk_buff *msg; |
| 15043 | void *hdr; |
| 15044 | |
| 15045 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 15046 | if (!msg) |
| 15047 | return; |
| 15048 | |
| 15049 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 15050 | if (!hdr) |
| 15051 | goto out; |
| 15052 | |
| 15053 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15054 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15055 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 15056 | NL80211_ATTR_PAD)) |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 15057 | goto out; |
| 15058 | |
| 15059 | genlmsg_end(msg, hdr); |
| 15060 | |
| 15061 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 15062 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 15063 | return; |
| 15064 | out: |
| 15065 | nlmsg_free(msg); |
| 15066 | } |
| 15067 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15068 | /* initialisation/exit functions */ |
| 15069 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 15070 | int __init nl80211_init(void) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15071 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 15072 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15073 | |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 15074 | err = genl_register_family(&nl80211_fam); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15075 | if (err) |
| 15076 | return err; |
| 15077 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15078 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 15079 | if (err) |
| 15080 | goto err_out; |
| 15081 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15082 | return 0; |
| 15083 | err_out: |
| 15084 | genl_unregister_family(&nl80211_fam); |
| 15085 | return err; |
| 15086 | } |
| 15087 | |
| 15088 | void nl80211_exit(void) |
| 15089 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15090 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15091 | genl_unregister_family(&nl80211_fam); |
| 15092 | } |