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 | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/if.h> |
| 9 | #include <linux/module.h> |
| 10 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 11 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12 | #include <linux/list.h> |
| 13 | #include <linux/if_ether.h> |
| 14 | #include <linux/ieee80211.h> |
| 15 | #include <linux/nl80211.h> |
| 16 | #include <linux/rtnetlink.h> |
| 17 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 18 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 19 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 20 | #include <net/genetlink.h> |
| 21 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 22 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 23 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 24 | #include "core.h" |
| 25 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 26 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 27 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 28 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 29 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 30 | struct genl_info *info, |
| 31 | struct cfg80211_crypto_settings *settings, |
| 32 | int cipher_limit); |
| 33 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 34 | 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] | 35 | struct genl_info *info); |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 36 | 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] | 37 | struct genl_info *info); |
| 38 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 39 | /* the netlink family */ |
| 40 | static struct genl_family nl80211_fam = { |
Marcel Holtmann | fb4e156 | 2013-04-28 16:22:06 -0700 | [diff] [blame] | 41 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 42 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 43 | .hdrsize = 0, /* no private header */ |
| 44 | .version = 1, /* no particular meaning now */ |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 45 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 46 | .netnsok = true, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 47 | .pre_doit = nl80211_pre_doit, |
| 48 | .post_doit = nl80211_post_doit, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 49 | }; |
| 50 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 51 | /* multicast groups */ |
| 52 | enum nl80211_multicast_groups { |
| 53 | NL80211_MCGRP_CONFIG, |
| 54 | NL80211_MCGRP_SCAN, |
| 55 | NL80211_MCGRP_REGULATORY, |
| 56 | NL80211_MCGRP_MLME, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 57 | NL80211_MCGRP_VENDOR, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 58 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
| 59 | }; |
| 60 | |
| 61 | static const struct genl_multicast_group nl80211_mcgrps[] = { |
| 62 | [NL80211_MCGRP_CONFIG] = { .name = "config", }, |
| 63 | [NL80211_MCGRP_SCAN] = { .name = "scan", }, |
| 64 | [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", }, |
| 65 | [NL80211_MCGRP_MLME] = { .name = "mlme", }, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 66 | [NL80211_MCGRP_VENDOR] = { .name = "vendor", }, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 67 | #ifdef CONFIG_NL80211_TESTMODE |
| 68 | [NL80211_MCGRP_TESTMODE] = { .name = "testmode", } |
| 69 | #endif |
| 70 | }; |
| 71 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 72 | /* returns ERR_PTR values */ |
| 73 | static struct wireless_dev * |
| 74 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 75 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 76 | struct cfg80211_registered_device *rdev; |
| 77 | struct wireless_dev *result = NULL; |
| 78 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 79 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 80 | u64 wdev_id; |
| 81 | int wiphy_idx = -1; |
| 82 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 83 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 84 | ASSERT_RTNL(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 85 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 86 | if (!have_ifidx && !have_wdev_id) |
| 87 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 88 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 89 | if (have_ifidx) |
| 90 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 91 | if (have_wdev_id) { |
| 92 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 93 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 94 | } |
| 95 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 96 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 97 | struct wireless_dev *wdev; |
| 98 | |
| 99 | if (wiphy_net(&rdev->wiphy) != netns) |
| 100 | continue; |
| 101 | |
| 102 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 103 | continue; |
| 104 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 105 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
| 106 | if (have_ifidx && wdev->netdev && |
| 107 | wdev->netdev->ifindex == ifidx) { |
| 108 | result = wdev; |
| 109 | break; |
| 110 | } |
| 111 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 112 | result = wdev; |
| 113 | break; |
| 114 | } |
| 115 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 116 | |
| 117 | if (result) |
| 118 | break; |
| 119 | } |
| 120 | |
| 121 | if (result) |
| 122 | return result; |
| 123 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 124 | } |
| 125 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 126 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 127 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 128 | { |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 129 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 130 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 131 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 132 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 133 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 134 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 135 | !attrs[NL80211_ATTR_IFINDEX] && |
| 136 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 137 | return ERR_PTR(-EINVAL); |
| 138 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 139 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 140 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 141 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 142 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 143 | if (attrs[NL80211_ATTR_WDEV]) { |
| 144 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 145 | struct wireless_dev *wdev; |
| 146 | bool found = false; |
| 147 | |
| 148 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 149 | if (tmp) { |
| 150 | /* make sure wdev exists */ |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 151 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
| 152 | if (wdev->identifier != (u32)wdev_id) |
| 153 | continue; |
| 154 | found = true; |
| 155 | break; |
| 156 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 157 | |
| 158 | if (!found) |
| 159 | tmp = NULL; |
| 160 | |
| 161 | if (rdev && tmp != rdev) |
| 162 | return ERR_PTR(-EINVAL); |
| 163 | rdev = tmp; |
| 164 | } |
| 165 | } |
| 166 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 167 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 168 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 169 | netdev = __dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 170 | if (netdev) { |
| 171 | if (netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 172 | tmp = wiphy_to_rdev( |
| 173 | netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 174 | else |
| 175 | tmp = NULL; |
| 176 | |
Johannes Berg | 7fee477 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 177 | /* not wireless device -- return error */ |
| 178 | if (!tmp) |
| 179 | return ERR_PTR(-EINVAL); |
| 180 | |
| 181 | /* mismatch -- return error */ |
| 182 | if (rdev && tmp != rdev) |
| 183 | return ERR_PTR(-EINVAL); |
| 184 | |
| 185 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 186 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 187 | } |
| 188 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 189 | if (!rdev) |
| 190 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 191 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 192 | if (netns != wiphy_net(&rdev->wiphy)) |
| 193 | return ERR_PTR(-ENODEV); |
| 194 | |
| 195 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | /* |
| 199 | * This function returns a pointer to the driver |
| 200 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 201 | * |
| 202 | * The result of this can be a PTR_ERR and hence must |
| 203 | * be checked with IS_ERR() for errors. |
| 204 | */ |
| 205 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 206 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 207 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 208 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 209 | } |
| 210 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 211 | /* policy for the attributes */ |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 212 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 213 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 214 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 215 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 216 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 217 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 218 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 219 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 220 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 221 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
| 222 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 223 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 224 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 225 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 226 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 227 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 228 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 229 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 230 | |
| 231 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 232 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 233 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 234 | |
Eliad Peller | e007b85 | 2011-11-24 18:13:56 +0200 | [diff] [blame] | 235 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
| 236 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 237 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 238 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 239 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 240 | .len = WLAN_MAX_KEY_LEN }, |
| 241 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 242 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 243 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 244 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 245 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 246 | |
| 247 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 248 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 249 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 250 | .len = IEEE80211_MAX_DATA_LEN }, |
| 251 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 252 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 253 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 254 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 255 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 256 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 257 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 258 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 259 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 260 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 261 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 262 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 263 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 264 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 265 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 266 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 267 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 268 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 269 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 270 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 271 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 272 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 273 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 274 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 275 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 276 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 277 | |
Johannes Berg | 6c73941 | 2011-11-03 09:27:01 +0100 | [diff] [blame] | 278 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 279 | |
| 280 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 281 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 282 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 283 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 284 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 285 | |
| 286 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 287 | .len = IEEE80211_MAX_SSID_LEN }, |
| 288 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 289 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 290 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 291 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 292 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 293 | [NL80211_ATTR_STA_FLAGS2] = { |
| 294 | .len = sizeof(struct nl80211_sta_flag_update), |
| 295 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 296 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 297 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 298 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 299 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 300 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 301 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 302 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 303 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 304 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
| 305 | .len = WLAN_PMKID_LEN }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 306 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 307 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 308 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 309 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 310 | .len = IEEE80211_MAX_DATA_LEN }, |
| 311 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 312 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 313 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 314 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 315 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 316 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 317 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 318 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 319 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 320 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 321 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 322 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 323 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 324 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 325 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 326 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 327 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 328 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 32e9de8 | 2011-08-10 23:53:31 +0300 | [diff] [blame] | 329 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 330 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
| 331 | .len = IEEE80211_MAX_DATA_LEN }, |
| 332 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, |
| 333 | .len = IEEE80211_MAX_DATA_LEN }, |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 334 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 335 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 336 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 337 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 338 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 339 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 340 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 341 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 342 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 343 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 344 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 345 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 346 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 347 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 348 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 349 | .len = NL80211_HT_CAPABILITY_LEN |
| 350 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 351 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 352 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 353 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 354 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 355 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 356 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 357 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 358 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 359 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
| 360 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 361 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 362 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 363 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 364 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 365 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 366 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 367 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 368 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 369 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 370 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 371 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 372 | .len = IEEE80211_MAX_DATA_LEN }, |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 373 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 374 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 375 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 376 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 377 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
| 378 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 379 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
| 380 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 381 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 382 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 383 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 384 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 385 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 386 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
| 387 | .len = IEEE80211_QOS_MAP_LEN_MAX }, |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 388 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
| 389 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 390 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 391 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 392 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 393 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 394 | [NL80211_ATTR_TSID] = { .type = NLA_U8 }, |
| 395 | [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 }, |
| 396 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 397 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 398 | [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN }, |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame^] | 399 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 400 | }; |
| 401 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 402 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 403 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 404 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 405 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 406 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 407 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 408 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 409 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 410 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 411 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 412 | }; |
| 413 | |
| 414 | /* policy for the key default flags */ |
| 415 | static const struct nla_policy |
| 416 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 417 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 418 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 419 | }; |
| 420 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 421 | /* policy for WoWLAN attributes */ |
| 422 | static const struct nla_policy |
| 423 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 424 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 425 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 426 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 427 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 428 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 429 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 430 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 431 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 432 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 433 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 434 | }; |
| 435 | |
| 436 | static const struct nla_policy |
| 437 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 438 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 439 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 440 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 441 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 442 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 443 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 444 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 445 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 446 | }, |
| 447 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 448 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 449 | }, |
| 450 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 451 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 452 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 453 | }; |
| 454 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 455 | /* policy for coalesce rule attributes */ |
| 456 | static const struct nla_policy |
| 457 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 458 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 459 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 460 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 461 | }; |
| 462 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 463 | /* policy for GTK rekey offload attributes */ |
| 464 | static const struct nla_policy |
| 465 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 466 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 467 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 468 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 469 | }; |
| 470 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 471 | static const struct nla_policy |
| 472 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 473 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 474 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 475 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 476 | }; |
| 477 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 478 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 479 | struct netlink_callback *cb, |
| 480 | struct cfg80211_registered_device **rdev, |
| 481 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 482 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 483 | int err; |
| 484 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 485 | rtnl_lock(); |
| 486 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 487 | if (!cb->args[0]) { |
| 488 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 489 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 490 | nl80211_policy); |
| 491 | if (err) |
| 492 | goto out_unlock; |
| 493 | |
| 494 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 495 | nl80211_fam.attrbuf); |
| 496 | if (IS_ERR(*wdev)) { |
| 497 | err = PTR_ERR(*wdev); |
| 498 | goto out_unlock; |
| 499 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 500 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 501 | /* 0 is the first index - add 1 to parse only once */ |
| 502 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 503 | cb->args[1] = (*wdev)->identifier; |
| 504 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 505 | /* subtract the 1 again here */ |
| 506 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 507 | struct wireless_dev *tmp; |
| 508 | |
| 509 | if (!wiphy) { |
| 510 | err = -ENODEV; |
| 511 | goto out_unlock; |
| 512 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 513 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 514 | *wdev = NULL; |
| 515 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 516 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 517 | if (tmp->identifier == cb->args[1]) { |
| 518 | *wdev = tmp; |
| 519 | break; |
| 520 | } |
| 521 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 522 | |
| 523 | if (!*wdev) { |
| 524 | err = -ENODEV; |
| 525 | goto out_unlock; |
| 526 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 527 | } |
| 528 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 529 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 530 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 531 | rtnl_unlock(); |
| 532 | return err; |
| 533 | } |
| 534 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 535 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 536 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 537 | rtnl_unlock(); |
| 538 | } |
| 539 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 540 | /* IE validation */ |
| 541 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 542 | { |
| 543 | const u8 *pos; |
| 544 | int len; |
| 545 | |
| 546 | if (!attr) |
| 547 | return true; |
| 548 | |
| 549 | pos = nla_data(attr); |
| 550 | len = nla_len(attr); |
| 551 | |
| 552 | while (len) { |
| 553 | u8 elemlen; |
| 554 | |
| 555 | if (len < 2) |
| 556 | return false; |
| 557 | len -= 2; |
| 558 | |
| 559 | elemlen = pos[1]; |
| 560 | if (elemlen > len) |
| 561 | return false; |
| 562 | |
| 563 | len -= elemlen; |
| 564 | pos += 2 + elemlen; |
| 565 | } |
| 566 | |
| 567 | return true; |
| 568 | } |
| 569 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 570 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 571 | 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] | 572 | int flags, u8 cmd) |
| 573 | { |
| 574 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 575 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 576 | } |
| 577 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 578 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 579 | struct ieee80211_channel *chan, |
| 580 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 581 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 582 | /* Some channels must be completely excluded from the |
| 583 | * list to protect old user-space tools from breaking |
| 584 | */ |
| 585 | if (!large && chan->flags & |
| 586 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 587 | return 0; |
| 588 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 589 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 590 | chan->center_freq)) |
| 591 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 592 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 593 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 594 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 595 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 596 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 597 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 598 | goto nla_put_failure; |
| 599 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 600 | goto nla_put_failure; |
| 601 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 602 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 603 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 604 | goto nla_put_failure; |
| 605 | if (large) { |
| 606 | u32 time; |
| 607 | |
| 608 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 609 | |
| 610 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 611 | chan->dfs_state)) |
| 612 | goto nla_put_failure; |
| 613 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 614 | time)) |
| 615 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 616 | if (nla_put_u32(msg, |
| 617 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 618 | chan->dfs_cac_ms)) |
| 619 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 620 | } |
| 621 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 622 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 623 | if (large) { |
| 624 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 625 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 626 | goto nla_put_failure; |
| 627 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 628 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 629 | goto nla_put_failure; |
| 630 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 631 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 632 | goto nla_put_failure; |
| 633 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 634 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 635 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 636 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 637 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 638 | goto nla_put_failure; |
| 639 | if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) && |
| 640 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT)) |
| 641 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 642 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 643 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 644 | goto nla_put_failure; |
| 645 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 646 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 647 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 648 | } |
| 649 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 650 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 651 | DBM_TO_MBM(chan->max_power))) |
| 652 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 653 | |
| 654 | return 0; |
| 655 | |
| 656 | nla_put_failure: |
| 657 | return -ENOBUFS; |
| 658 | } |
| 659 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 660 | /* netlink command implementations */ |
| 661 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 662 | struct key_parse { |
| 663 | struct key_params p; |
| 664 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 665 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 666 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 667 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 668 | }; |
| 669 | |
| 670 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 671 | { |
| 672 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 673 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 674 | nl80211_key_policy); |
| 675 | if (err) |
| 676 | return err; |
| 677 | |
| 678 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 679 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 680 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 681 | if (k->def) { |
| 682 | k->def_uni = true; |
| 683 | k->def_multi = true; |
| 684 | } |
| 685 | if (k->defmgmt) |
| 686 | k->def_multi = true; |
| 687 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 688 | if (tb[NL80211_KEY_IDX]) |
| 689 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 690 | |
| 691 | if (tb[NL80211_KEY_DATA]) { |
| 692 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 693 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 694 | } |
| 695 | |
| 696 | if (tb[NL80211_KEY_SEQ]) { |
| 697 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 698 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 699 | } |
| 700 | |
| 701 | if (tb[NL80211_KEY_CIPHER]) |
| 702 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 703 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 704 | if (tb[NL80211_KEY_TYPE]) { |
| 705 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 706 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 707 | return -EINVAL; |
| 708 | } |
| 709 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 710 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 711 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 712 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 713 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 714 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 715 | if (err) |
| 716 | return err; |
| 717 | |
| 718 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 719 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 720 | } |
| 721 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 722 | return 0; |
| 723 | } |
| 724 | |
| 725 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 726 | { |
| 727 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 728 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 729 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 730 | } |
| 731 | |
| 732 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 733 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 734 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 735 | } |
| 736 | |
| 737 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 738 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 739 | |
| 740 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 741 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 742 | |
| 743 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 744 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 745 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 746 | if (k->def) { |
| 747 | k->def_uni = true; |
| 748 | k->def_multi = true; |
| 749 | } |
| 750 | if (k->defmgmt) |
| 751 | k->def_multi = true; |
| 752 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 753 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 754 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 755 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 756 | return -EINVAL; |
| 757 | } |
| 758 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 759 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 760 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 761 | int err = nla_parse_nested( |
| 762 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 763 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 764 | nl80211_key_default_policy); |
| 765 | if (err) |
| 766 | return err; |
| 767 | |
| 768 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 769 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 770 | } |
| 771 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 772 | return 0; |
| 773 | } |
| 774 | |
| 775 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 776 | { |
| 777 | int err; |
| 778 | |
| 779 | memset(k, 0, sizeof(*k)); |
| 780 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 781 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 782 | |
| 783 | if (info->attrs[NL80211_ATTR_KEY]) |
| 784 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 785 | else |
| 786 | err = nl80211_parse_key_old(info, k); |
| 787 | |
| 788 | if (err) |
| 789 | return err; |
| 790 | |
| 791 | if (k->def && k->defmgmt) |
| 792 | return -EINVAL; |
| 793 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 794 | if (k->defmgmt) { |
| 795 | if (k->def_uni || !k->def_multi) |
| 796 | return -EINVAL; |
| 797 | } |
| 798 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 799 | if (k->idx != -1) { |
| 800 | if (k->defmgmt) { |
| 801 | if (k->idx < 4 || k->idx > 5) |
| 802 | return -EINVAL; |
| 803 | } else if (k->def) { |
| 804 | if (k->idx < 0 || k->idx > 3) |
| 805 | return -EINVAL; |
| 806 | } else { |
| 807 | if (k->idx < 0 || k->idx > 5) |
| 808 | return -EINVAL; |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | return 0; |
| 813 | } |
| 814 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 815 | static struct cfg80211_cached_keys * |
| 816 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 817 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 818 | { |
| 819 | struct key_parse parse; |
| 820 | struct nlattr *key; |
| 821 | struct cfg80211_cached_keys *result; |
| 822 | int rem, err, def = 0; |
| 823 | |
| 824 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 825 | if (!result) |
| 826 | return ERR_PTR(-ENOMEM); |
| 827 | |
| 828 | result->def = -1; |
| 829 | result->defmgmt = -1; |
| 830 | |
| 831 | nla_for_each_nested(key, keys, rem) { |
| 832 | memset(&parse, 0, sizeof(parse)); |
| 833 | parse.idx = -1; |
| 834 | |
| 835 | err = nl80211_parse_key_new(key, &parse); |
| 836 | if (err) |
| 837 | goto error; |
| 838 | err = -EINVAL; |
| 839 | if (!parse.p.key) |
| 840 | goto error; |
| 841 | if (parse.idx < 0 || parse.idx > 4) |
| 842 | goto error; |
| 843 | if (parse.def) { |
| 844 | if (def) |
| 845 | goto error; |
| 846 | def = 1; |
| 847 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 848 | if (!parse.def_uni || !parse.def_multi) |
| 849 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 850 | } else if (parse.defmgmt) |
| 851 | goto error; |
| 852 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 853 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 854 | if (err) |
| 855 | goto error; |
| 856 | result->params[parse.idx].cipher = parse.p.cipher; |
| 857 | result->params[parse.idx].key_len = parse.p.key_len; |
| 858 | result->params[parse.idx].key = result->data[parse.idx]; |
| 859 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 860 | |
| 861 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 862 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 863 | if (no_ht) |
| 864 | *no_ht = true; |
| 865 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | return result; |
| 869 | error: |
| 870 | kfree(result); |
| 871 | return ERR_PTR(err); |
| 872 | } |
| 873 | |
| 874 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 875 | { |
| 876 | ASSERT_WDEV_LOCK(wdev); |
| 877 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 878 | switch (wdev->iftype) { |
| 879 | case NL80211_IFTYPE_AP: |
| 880 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 881 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 882 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 883 | break; |
| 884 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 885 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 886 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 887 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 888 | return -ENOLINK; |
| 889 | break; |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 890 | case NL80211_IFTYPE_UNSPECIFIED: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 891 | case NL80211_IFTYPE_OCB: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 892 | case NL80211_IFTYPE_MONITOR: |
| 893 | case NL80211_IFTYPE_P2P_DEVICE: |
| 894 | case NL80211_IFTYPE_WDS: |
| 895 | case NUM_NL80211_IFTYPES: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 896 | return -EINVAL; |
| 897 | } |
| 898 | |
| 899 | return 0; |
| 900 | } |
| 901 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 902 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 903 | struct nlattr *tb) |
| 904 | { |
| 905 | struct ieee80211_channel *chan; |
| 906 | |
| 907 | if (tb == NULL) |
| 908 | return NULL; |
| 909 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 910 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 911 | return NULL; |
| 912 | return chan; |
| 913 | } |
| 914 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 915 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 916 | { |
| 917 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 918 | int i; |
| 919 | |
| 920 | if (!nl_modes) |
| 921 | goto nla_put_failure; |
| 922 | |
| 923 | i = 0; |
| 924 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 925 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 926 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 927 | ifmodes >>= 1; |
| 928 | i++; |
| 929 | } |
| 930 | |
| 931 | nla_nest_end(msg, nl_modes); |
| 932 | return 0; |
| 933 | |
| 934 | nla_put_failure: |
| 935 | return -ENOBUFS; |
| 936 | } |
| 937 | |
| 938 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 939 | struct sk_buff *msg, |
| 940 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 941 | { |
| 942 | struct nlattr *nl_combis; |
| 943 | int i, j; |
| 944 | |
| 945 | nl_combis = nla_nest_start(msg, |
| 946 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 947 | if (!nl_combis) |
| 948 | goto nla_put_failure; |
| 949 | |
| 950 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 951 | const struct ieee80211_iface_combination *c; |
| 952 | struct nlattr *nl_combi, *nl_limits; |
| 953 | |
| 954 | c = &wiphy->iface_combinations[i]; |
| 955 | |
| 956 | nl_combi = nla_nest_start(msg, i + 1); |
| 957 | if (!nl_combi) |
| 958 | goto nla_put_failure; |
| 959 | |
| 960 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 961 | if (!nl_limits) |
| 962 | goto nla_put_failure; |
| 963 | |
| 964 | for (j = 0; j < c->n_limits; j++) { |
| 965 | struct nlattr *nl_limit; |
| 966 | |
| 967 | nl_limit = nla_nest_start(msg, j + 1); |
| 968 | if (!nl_limit) |
| 969 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 970 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 971 | c->limits[j].max)) |
| 972 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 973 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 974 | c->limits[j].types)) |
| 975 | goto nla_put_failure; |
| 976 | nla_nest_end(msg, nl_limit); |
| 977 | } |
| 978 | |
| 979 | nla_nest_end(msg, nl_limits); |
| 980 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 981 | if (c->beacon_int_infra_match && |
| 982 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 983 | goto nla_put_failure; |
| 984 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 985 | c->num_different_channels) || |
| 986 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 987 | c->max_interfaces)) |
| 988 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 989 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 990 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 991 | c->radar_detect_widths) || |
| 992 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 993 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 994 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 995 | |
| 996 | nla_nest_end(msg, nl_combi); |
| 997 | } |
| 998 | |
| 999 | nla_nest_end(msg, nl_combis); |
| 1000 | |
| 1001 | return 0; |
| 1002 | nla_put_failure: |
| 1003 | return -ENOBUFS; |
| 1004 | } |
| 1005 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1006 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1007 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 1008 | struct sk_buff *msg) |
| 1009 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1010 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1011 | struct nlattr *nl_tcp; |
| 1012 | |
| 1013 | if (!tcp) |
| 1014 | return 0; |
| 1015 | |
| 1016 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 1017 | if (!nl_tcp) |
| 1018 | return -ENOBUFS; |
| 1019 | |
| 1020 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1021 | tcp->data_payload_max)) |
| 1022 | return -ENOBUFS; |
| 1023 | |
| 1024 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1025 | tcp->data_payload_max)) |
| 1026 | return -ENOBUFS; |
| 1027 | |
| 1028 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1029 | return -ENOBUFS; |
| 1030 | |
| 1031 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1032 | sizeof(*tcp->tok), tcp->tok)) |
| 1033 | return -ENOBUFS; |
| 1034 | |
| 1035 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1036 | tcp->data_interval_max)) |
| 1037 | return -ENOBUFS; |
| 1038 | |
| 1039 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1040 | tcp->wake_payload_max)) |
| 1041 | return -ENOBUFS; |
| 1042 | |
| 1043 | nla_nest_end(msg, nl_tcp); |
| 1044 | return 0; |
| 1045 | } |
| 1046 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1047 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1048 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1049 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1050 | { |
| 1051 | struct nlattr *nl_wowlan; |
| 1052 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1053 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1054 | return 0; |
| 1055 | |
| 1056 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1057 | if (!nl_wowlan) |
| 1058 | return -ENOBUFS; |
| 1059 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1060 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1061 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1062 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1063 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1064 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1065 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1066 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1067 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1068 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1069 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1070 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1071 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1072 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1073 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1074 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1075 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1076 | return -ENOBUFS; |
| 1077 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1078 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1079 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1080 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1081 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1082 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1083 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1084 | }; |
| 1085 | |
| 1086 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1087 | sizeof(pat), &pat)) |
| 1088 | return -ENOBUFS; |
| 1089 | } |
| 1090 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1091 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1092 | return -ENOBUFS; |
| 1093 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 1094 | /* TODO: send wowlan net detect */ |
| 1095 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1096 | nla_nest_end(msg, nl_wowlan); |
| 1097 | |
| 1098 | return 0; |
| 1099 | } |
| 1100 | #endif |
| 1101 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1102 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1103 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1104 | { |
| 1105 | struct nl80211_coalesce_rule_support rule; |
| 1106 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1107 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1108 | return 0; |
| 1109 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1110 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1111 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1112 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1113 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1114 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1115 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1116 | |
| 1117 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1118 | return -ENOBUFS; |
| 1119 | |
| 1120 | return 0; |
| 1121 | } |
| 1122 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1123 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1124 | struct ieee80211_supported_band *sband) |
| 1125 | { |
| 1126 | struct nlattr *nl_rates, *nl_rate; |
| 1127 | struct ieee80211_rate *rate; |
| 1128 | int i; |
| 1129 | |
| 1130 | /* add HT info */ |
| 1131 | if (sband->ht_cap.ht_supported && |
| 1132 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1133 | sizeof(sband->ht_cap.mcs), |
| 1134 | &sband->ht_cap.mcs) || |
| 1135 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1136 | sband->ht_cap.cap) || |
| 1137 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1138 | sband->ht_cap.ampdu_factor) || |
| 1139 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1140 | sband->ht_cap.ampdu_density))) |
| 1141 | return -ENOBUFS; |
| 1142 | |
| 1143 | /* add VHT info */ |
| 1144 | if (sband->vht_cap.vht_supported && |
| 1145 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1146 | sizeof(sband->vht_cap.vht_mcs), |
| 1147 | &sband->vht_cap.vht_mcs) || |
| 1148 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1149 | sband->vht_cap.cap))) |
| 1150 | return -ENOBUFS; |
| 1151 | |
| 1152 | /* add bitrates */ |
| 1153 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1154 | if (!nl_rates) |
| 1155 | return -ENOBUFS; |
| 1156 | |
| 1157 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1158 | nl_rate = nla_nest_start(msg, i); |
| 1159 | if (!nl_rate) |
| 1160 | return -ENOBUFS; |
| 1161 | |
| 1162 | rate = &sband->bitrates[i]; |
| 1163 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1164 | rate->bitrate)) |
| 1165 | return -ENOBUFS; |
| 1166 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1167 | nla_put_flag(msg, |
| 1168 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1169 | return -ENOBUFS; |
| 1170 | |
| 1171 | nla_nest_end(msg, nl_rate); |
| 1172 | } |
| 1173 | |
| 1174 | nla_nest_end(msg, nl_rates); |
| 1175 | |
| 1176 | return 0; |
| 1177 | } |
| 1178 | |
| 1179 | static int |
| 1180 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1181 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1182 | { |
| 1183 | u16 stypes; |
| 1184 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1185 | enum nl80211_iftype ift; |
| 1186 | int i; |
| 1187 | |
| 1188 | if (!mgmt_stypes) |
| 1189 | return 0; |
| 1190 | |
| 1191 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1192 | if (!nl_ifs) |
| 1193 | return -ENOBUFS; |
| 1194 | |
| 1195 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1196 | nl_ftypes = nla_nest_start(msg, ift); |
| 1197 | if (!nl_ftypes) |
| 1198 | return -ENOBUFS; |
| 1199 | i = 0; |
| 1200 | stypes = mgmt_stypes[ift].tx; |
| 1201 | while (stypes) { |
| 1202 | if ((stypes & 1) && |
| 1203 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1204 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1205 | return -ENOBUFS; |
| 1206 | stypes >>= 1; |
| 1207 | i++; |
| 1208 | } |
| 1209 | nla_nest_end(msg, nl_ftypes); |
| 1210 | } |
| 1211 | |
| 1212 | nla_nest_end(msg, nl_ifs); |
| 1213 | |
| 1214 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1215 | if (!nl_ifs) |
| 1216 | return -ENOBUFS; |
| 1217 | |
| 1218 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1219 | nl_ftypes = nla_nest_start(msg, ift); |
| 1220 | if (!nl_ftypes) |
| 1221 | return -ENOBUFS; |
| 1222 | i = 0; |
| 1223 | stypes = mgmt_stypes[ift].rx; |
| 1224 | while (stypes) { |
| 1225 | if ((stypes & 1) && |
| 1226 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1227 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1228 | return -ENOBUFS; |
| 1229 | stypes >>= 1; |
| 1230 | i++; |
| 1231 | } |
| 1232 | nla_nest_end(msg, nl_ftypes); |
| 1233 | } |
| 1234 | nla_nest_end(msg, nl_ifs); |
| 1235 | |
| 1236 | return 0; |
| 1237 | } |
| 1238 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1239 | struct nl80211_dump_wiphy_state { |
| 1240 | s64 filter_wiphy; |
| 1241 | long start; |
| 1242 | long split_start, band_start, chan_start; |
| 1243 | bool split; |
| 1244 | }; |
| 1245 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1246 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1247 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1248 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1249 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1250 | { |
| 1251 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1252 | struct nlattr *nl_bands, *nl_band; |
| 1253 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1254 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1255 | enum ieee80211_band band; |
| 1256 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1257 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1258 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1259 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1260 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1261 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1262 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1263 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1264 | return -ENOBUFS; |
| 1265 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1266 | if (WARN_ON(!state)) |
| 1267 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1268 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1269 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1270 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1271 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1272 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1273 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1274 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1275 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1276 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 1277 | goto finish; |
| 1278 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1279 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1280 | case 0: |
| 1281 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1282 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1283 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1284 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1285 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1286 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1287 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1288 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1289 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1290 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1291 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1292 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1293 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1294 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1295 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1296 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1297 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1298 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1299 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1300 | rdev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1301 | goto nla_put_failure; |
| 1302 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1303 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1304 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1305 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1306 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1307 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1308 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1309 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1310 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1311 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1312 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1313 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1314 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1315 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1316 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1317 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1318 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1319 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1320 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1321 | state->split_start++; |
| 1322 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1323 | break; |
| 1324 | case 1: |
| 1325 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1326 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 1327 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1328 | goto nla_put_failure; |
| 1329 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1330 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1331 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1332 | goto nla_put_failure; |
| 1333 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1334 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1335 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1336 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1337 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1338 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1339 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1340 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1341 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1342 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1343 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1344 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1345 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1346 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1347 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1348 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1349 | if ((rdev->wiphy.available_antennas_tx || |
| 1350 | rdev->wiphy.available_antennas_rx) && |
| 1351 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1352 | u32 tx_ant = 0, rx_ant = 0; |
| 1353 | int res; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1354 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1355 | if (!res) { |
| 1356 | if (nla_put_u32(msg, |
| 1357 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1358 | tx_ant) || |
| 1359 | nla_put_u32(msg, |
| 1360 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1361 | rx_ant)) |
| 1362 | goto nla_put_failure; |
| 1363 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1364 | } |
| 1365 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1366 | state->split_start++; |
| 1367 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1368 | break; |
| 1369 | case 2: |
| 1370 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1371 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1372 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1373 | state->split_start++; |
| 1374 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1375 | break; |
| 1376 | case 3: |
| 1377 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1378 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1379 | goto nla_put_failure; |
| 1380 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1381 | for (band = state->band_start; |
| 1382 | band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1383 | struct ieee80211_supported_band *sband; |
| 1384 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1385 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1386 | |
| 1387 | if (!sband) |
| 1388 | continue; |
| 1389 | |
| 1390 | nl_band = nla_nest_start(msg, band); |
| 1391 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1392 | goto nla_put_failure; |
| 1393 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1394 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1395 | case 0: |
| 1396 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1397 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1398 | state->chan_start++; |
| 1399 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1400 | break; |
| 1401 | default: |
| 1402 | /* add frequencies */ |
| 1403 | nl_freqs = nla_nest_start( |
| 1404 | msg, NL80211_BAND_ATTR_FREQS); |
| 1405 | if (!nl_freqs) |
| 1406 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1407 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1408 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1409 | i < sband->n_channels; |
| 1410 | i++) { |
| 1411 | nl_freq = nla_nest_start(msg, i); |
| 1412 | if (!nl_freq) |
| 1413 | goto nla_put_failure; |
| 1414 | |
| 1415 | chan = &sband->channels[i]; |
| 1416 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1417 | if (nl80211_msg_put_channel( |
| 1418 | msg, chan, |
| 1419 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1420 | goto nla_put_failure; |
| 1421 | |
| 1422 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1423 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1424 | break; |
| 1425 | } |
| 1426 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1427 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1428 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1429 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1430 | nla_nest_end(msg, nl_freqs); |
| 1431 | } |
| 1432 | |
| 1433 | nla_nest_end(msg, nl_band); |
| 1434 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1435 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1436 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1437 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1438 | band--; |
| 1439 | break; |
| 1440 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1441 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1442 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1443 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1444 | if (band < IEEE80211_NUM_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1445 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1446 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1447 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1448 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1449 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1450 | if (state->band_start == 0 && state->chan_start == 0) |
| 1451 | state->split_start++; |
| 1452 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1453 | break; |
| 1454 | case 4: |
| 1455 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1456 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1457 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1458 | |
| 1459 | i = 0; |
| 1460 | #define CMD(op, n) \ |
| 1461 | do { \ |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1462 | if (rdev->ops->op) { \ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1463 | i++; \ |
| 1464 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1465 | goto nla_put_failure; \ |
| 1466 | } \ |
| 1467 | } while (0) |
| 1468 | |
| 1469 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1470 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1471 | CMD(add_key, NEW_KEY); |
| 1472 | CMD(start_ap, START_AP); |
| 1473 | CMD(add_station, NEW_STATION); |
| 1474 | CMD(add_mpath, NEW_MPATH); |
| 1475 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1476 | CMD(change_bss, SET_BSS); |
| 1477 | CMD(auth, AUTHENTICATE); |
| 1478 | CMD(assoc, ASSOCIATE); |
| 1479 | CMD(deauth, DEAUTHENTICATE); |
| 1480 | CMD(disassoc, DISASSOCIATE); |
| 1481 | CMD(join_ibss, JOIN_IBSS); |
| 1482 | CMD(join_mesh, JOIN_MESH); |
| 1483 | CMD(set_pmksa, SET_PMKSA); |
| 1484 | CMD(del_pmksa, DEL_PMKSA); |
| 1485 | CMD(flush_pmksa, FLUSH_PMKSA); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1486 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1487 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1488 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1489 | CMD(mgmt_tx, FRAME); |
| 1490 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1491 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1492 | i++; |
| 1493 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1494 | goto nla_put_failure; |
| 1495 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1496 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1497 | rdev->ops->join_mesh) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1498 | i++; |
| 1499 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1500 | goto nla_put_failure; |
| 1501 | } |
| 1502 | CMD(set_wds_peer, SET_WDS_PEER); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1503 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1504 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1505 | CMD(tdls_oper, TDLS_OPER); |
| 1506 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1507 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1508 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1509 | CMD(probe_client, PROBE_CLIENT); |
| 1510 | CMD(set_noack_map, SET_NOACK_MAP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1511 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1512 | i++; |
| 1513 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1514 | goto nla_put_failure; |
| 1515 | } |
| 1516 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1517 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1518 | #ifdef CONFIG_NL80211_TESTMODE |
| 1519 | CMD(testmode_cmd, TESTMODE); |
| 1520 | #endif |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1521 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1522 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1523 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1524 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1525 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1526 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 1527 | if (rdev->wiphy.features & |
| 1528 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 1529 | CMD(add_tx_ts, ADD_TX_TS); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1530 | } |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1531 | /* add into the if now */ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1532 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1533 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1534 | if (rdev->ops->connect || rdev->ops->auth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1535 | i++; |
| 1536 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1537 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1538 | } |
| 1539 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1540 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1541 | i++; |
| 1542 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1543 | goto nla_put_failure; |
| 1544 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1545 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1546 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1547 | state->split_start++; |
| 1548 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1549 | break; |
| 1550 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1551 | if (rdev->ops->remain_on_channel && |
| 1552 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1553 | nla_put_u32(msg, |
| 1554 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1555 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1556 | goto nla_put_failure; |
| 1557 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1558 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1559 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1560 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1561 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1562 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1563 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1564 | state->split_start++; |
| 1565 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1566 | break; |
| 1567 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1568 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1569 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1570 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1571 | state->split_start++; |
| 1572 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1573 | break; |
| 1574 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1575 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1576 | #endif |
| 1577 | case 7: |
| 1578 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1579 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1580 | goto nla_put_failure; |
| 1581 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1582 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1583 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1584 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1585 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1586 | state->split_start++; |
| 1587 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1588 | break; |
| 1589 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1590 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1591 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1592 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1593 | goto nla_put_failure; |
| 1594 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1595 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1596 | /* |
| 1597 | * We can only add the per-channel limit information if the |
| 1598 | * dump is split, otherwise it makes it too big. Therefore |
| 1599 | * only advertise it in that case. |
| 1600 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1601 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1602 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1603 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1604 | goto nla_put_failure; |
| 1605 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1606 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1607 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1608 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 1609 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1610 | goto nla_put_failure; |
| 1611 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1612 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1613 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1614 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1615 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1616 | goto nla_put_failure; |
| 1617 | |
| 1618 | /* |
| 1619 | * Any information below this point is only available to |
| 1620 | * applications that can deal with it being split. This |
| 1621 | * helps ensure that newly added capabilities don't break |
| 1622 | * older tools by overrunning their buffers. |
| 1623 | * |
| 1624 | * We still increment split_start so that in the split |
| 1625 | * case we'll continue with more data in the next round, |
| 1626 | * but break unconditionally so unsplit data stops here. |
| 1627 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1628 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1629 | break; |
| 1630 | case 9: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1631 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1632 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1633 | rdev->wiphy.extended_capabilities_len, |
| 1634 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1635 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1636 | rdev->wiphy.extended_capabilities_len, |
| 1637 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1638 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1639 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1640 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1641 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1642 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 1643 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1644 | goto nla_put_failure; |
| 1645 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1646 | state->split_start++; |
| 1647 | break; |
| 1648 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1649 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1650 | goto nla_put_failure; |
| 1651 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1652 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1653 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1654 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1655 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1656 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1657 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1658 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1659 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1660 | goto nla_put_failure; |
| 1661 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1662 | state->split_start++; |
| 1663 | break; |
| 1664 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1665 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1666 | const struct nl80211_vendor_cmd_info *info; |
| 1667 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1668 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1669 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1670 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1671 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1672 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1673 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 1674 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1675 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1676 | goto nla_put_failure; |
| 1677 | } |
| 1678 | nla_nest_end(msg, nested); |
| 1679 | } |
| 1680 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1681 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1682 | const struct nl80211_vendor_cmd_info *info; |
| 1683 | struct nlattr *nested; |
| 1684 | |
| 1685 | nested = nla_nest_start(msg, |
| 1686 | NL80211_ATTR_VENDOR_EVENTS); |
| 1687 | if (!nested) |
| 1688 | goto nla_put_failure; |
| 1689 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1690 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 1691 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1692 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1693 | goto nla_put_failure; |
| 1694 | } |
| 1695 | nla_nest_end(msg, nested); |
| 1696 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 1697 | state->split_start++; |
| 1698 | break; |
| 1699 | case 12: |
| 1700 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 1701 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 1702 | rdev->wiphy.max_num_csa_counters)) |
| 1703 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1704 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame^] | 1705 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 1706 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 1707 | goto nla_put_failure; |
| 1708 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1709 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1710 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1711 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1712 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1713 | finish: |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1714 | return genlmsg_end(msg, hdr); |
| 1715 | |
| 1716 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1717 | genlmsg_cancel(msg, hdr); |
| 1718 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1719 | } |
| 1720 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1721 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1722 | struct netlink_callback *cb, |
| 1723 | struct nl80211_dump_wiphy_state *state) |
| 1724 | { |
| 1725 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1726 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1727 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1728 | /* ignore parse errors for backward compatibility */ |
| 1729 | if (ret) |
| 1730 | return 0; |
| 1731 | |
| 1732 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1733 | if (tb[NL80211_ATTR_WIPHY]) |
| 1734 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1735 | if (tb[NL80211_ATTR_WDEV]) |
| 1736 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1737 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1738 | struct net_device *netdev; |
| 1739 | struct cfg80211_registered_device *rdev; |
| 1740 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1741 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1742 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1743 | if (!netdev) |
| 1744 | return -ENODEV; |
| 1745 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1746 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1747 | netdev->ieee80211_ptr->wiphy); |
| 1748 | state->filter_wiphy = rdev->wiphy_idx; |
| 1749 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | return 0; |
| 1753 | } |
| 1754 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1755 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1756 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1757 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1758 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1759 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1760 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1761 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1762 | if (!state) { |
| 1763 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1764 | if (!state) { |
| 1765 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1766 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1767 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1768 | state->filter_wiphy = -1; |
| 1769 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1770 | if (ret) { |
| 1771 | kfree(state); |
| 1772 | rtnl_unlock(); |
| 1773 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1774 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1775 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1776 | } |
| 1777 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1778 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1779 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1780 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1781 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1782 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1783 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1784 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1785 | continue; |
| 1786 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1787 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1788 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 1789 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1790 | NETLINK_CB(cb->skb).portid, |
| 1791 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1792 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1793 | if (ret < 0) { |
| 1794 | /* |
| 1795 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1796 | * or EMSGSIZE returned), this SKB is still |
| 1797 | * empty (so it's not too big because another |
| 1798 | * wiphy dataset is already in the skb) and |
| 1799 | * we've not tried to adjust the dump allocation |
| 1800 | * yet ... then adjust the alloc size to be |
| 1801 | * bigger, and return 1 but with the empty skb. |
| 1802 | * This results in an empty message being RX'ed |
| 1803 | * in userspace, but that is ignored. |
| 1804 | * |
| 1805 | * We can then retry with the larger buffer. |
| 1806 | */ |
| 1807 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1808 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1809 | cb->min_dump_alloc < 4096) { |
| 1810 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1811 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1812 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1813 | return 1; |
| 1814 | } |
| 1815 | idx--; |
| 1816 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1817 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1818 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1819 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1820 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1821 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1822 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1823 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1824 | |
| 1825 | return skb->len; |
| 1826 | } |
| 1827 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1828 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1829 | { |
| 1830 | kfree((void *)cb->args[0]); |
| 1831 | return 0; |
| 1832 | } |
| 1833 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1834 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1835 | { |
| 1836 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1837 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1838 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1839 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1840 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1841 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1842 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1843 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1844 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 1845 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1846 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1847 | nlmsg_free(msg); |
| 1848 | return -ENOBUFS; |
| 1849 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1850 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1851 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1852 | } |
| 1853 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1854 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1855 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1856 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1857 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1858 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1859 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1860 | }; |
| 1861 | |
| 1862 | static int parse_txq_params(struct nlattr *tb[], |
| 1863 | struct ieee80211_txq_params *txq_params) |
| 1864 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1865 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1866 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1867 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1868 | return -EINVAL; |
| 1869 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1870 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1871 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1872 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1873 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1874 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1875 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1876 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1877 | return -EINVAL; |
| 1878 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1879 | return 0; |
| 1880 | } |
| 1881 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1882 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1883 | { |
| 1884 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1885 | * You can only set the channel explicitly for WDS interfaces, |
| 1886 | * all others have their channel managed via their respective |
| 1887 | * "establish a connection" command (connect, join, ...) |
| 1888 | * |
| 1889 | * For AP/GO and mesh mode, the channel can be set with the |
| 1890 | * channel userspace API, but is only stored and passed to the |
| 1891 | * low-level driver when the AP starts or the mesh is joined. |
| 1892 | * This is for backward compatibility, userspace can also give |
| 1893 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1894 | * |
| 1895 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1896 | * whatever else is going on, so they have their own special |
| 1897 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1898 | */ |
| 1899 | return !wdev || |
| 1900 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1901 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1902 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1903 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1904 | } |
| 1905 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1906 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1907 | struct genl_info *info, |
| 1908 | struct cfg80211_chan_def *chandef) |
| 1909 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1910 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1911 | |
| 1912 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1913 | return -EINVAL; |
| 1914 | |
| 1915 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1916 | |
| 1917 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1918 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1919 | chandef->center_freq1 = control_freq; |
| 1920 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1921 | |
| 1922 | /* Primary channel not allowed */ |
| 1923 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1924 | return -EINVAL; |
| 1925 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1926 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1927 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1928 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1929 | chantype = nla_get_u32( |
| 1930 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1931 | |
| 1932 | switch (chantype) { |
| 1933 | case NL80211_CHAN_NO_HT: |
| 1934 | case NL80211_CHAN_HT20: |
| 1935 | case NL80211_CHAN_HT40PLUS: |
| 1936 | case NL80211_CHAN_HT40MINUS: |
| 1937 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1938 | chantype); |
| 1939 | break; |
| 1940 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1941 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1942 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1943 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1944 | chandef->width = |
| 1945 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1946 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1947 | chandef->center_freq1 = |
| 1948 | nla_get_u32( |
| 1949 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1950 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1951 | chandef->center_freq2 = |
| 1952 | nla_get_u32( |
| 1953 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1954 | } |
| 1955 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1956 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1957 | return -EINVAL; |
| 1958 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1959 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1960 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1961 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1962 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1963 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1964 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1965 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1966 | return -EINVAL; |
| 1967 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1968 | return 0; |
| 1969 | } |
| 1970 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1971 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1972 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1973 | struct genl_info *info) |
| 1974 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1975 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1976 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1977 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1978 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1979 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1980 | if (dev) |
| 1981 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1982 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1983 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1984 | if (wdev) |
| 1985 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1986 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1987 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1988 | if (result) |
| 1989 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1990 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1991 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1992 | case NL80211_IFTYPE_AP: |
| 1993 | case NL80211_IFTYPE_P2P_GO: |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1994 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1995 | result = -EINVAL; |
| 1996 | break; |
| 1997 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1998 | if (wdev->beacon_interval) { |
| 1999 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 2000 | !(rdev->wiphy.features & |
| 2001 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 2002 | result = -EBUSY; |
| 2003 | break; |
| 2004 | } |
| 2005 | |
| 2006 | /* Only allow dynamic channel width changes */ |
| 2007 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 2008 | result = -EBUSY; |
| 2009 | break; |
| 2010 | } |
| 2011 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 2012 | if (result) |
| 2013 | break; |
| 2014 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2015 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2016 | result = 0; |
| 2017 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2018 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2019 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2020 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2021 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2022 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2023 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2024 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2025 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2026 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2027 | |
| 2028 | return result; |
| 2029 | } |
| 2030 | |
| 2031 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 2032 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2033 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2034 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2035 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2036 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2037 | } |
| 2038 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2039 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 2040 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2041 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2042 | struct net_device *dev = info->user_ptr[1]; |
| 2043 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2044 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2045 | |
| 2046 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2047 | return -EINVAL; |
| 2048 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2049 | if (netif_running(dev)) |
| 2050 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2051 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2052 | if (!rdev->ops->set_wds_peer) |
| 2053 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2054 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2055 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 2056 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2057 | |
| 2058 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2059 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2063 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2064 | { |
| 2065 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2066 | struct net_device *netdev = NULL; |
| 2067 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2068 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2069 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2070 | u32 changed; |
| 2071 | u8 retry_short = 0, retry_long = 0; |
| 2072 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2073 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2074 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2075 | ASSERT_RTNL(); |
| 2076 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2077 | /* |
| 2078 | * Try to find the wiphy and netdev. Normally this |
| 2079 | * function shouldn't need the netdev, but this is |
| 2080 | * done for backward compatibility -- previously |
| 2081 | * setting the channel was done per wiphy, but now |
| 2082 | * it is per netdev. Previous userland like hostapd |
| 2083 | * also passed a netdev to set_wiphy, so that it is |
| 2084 | * possible to let that go to the right netdev! |
| 2085 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2086 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2087 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2088 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2089 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2090 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2091 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2092 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2093 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2094 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2095 | } |
| 2096 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2097 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2098 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2099 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2100 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2101 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2102 | wdev = NULL; |
| 2103 | netdev = NULL; |
| 2104 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2105 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2106 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2107 | |
| 2108 | /* |
| 2109 | * end workaround code, by now the rdev is available |
| 2110 | * and locked, and wdev may or may not be NULL. |
| 2111 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2112 | |
| 2113 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2114 | result = cfg80211_dev_rename( |
| 2115 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2116 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2117 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2118 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2119 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2120 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2121 | struct ieee80211_txq_params txq_params; |
| 2122 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2123 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2124 | if (!rdev->ops->set_txq_params) |
| 2125 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2126 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2127 | if (!netdev) |
| 2128 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2129 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2130 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2131 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2132 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2133 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2134 | if (!netif_running(netdev)) |
| 2135 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2136 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2137 | nla_for_each_nested(nl_txq_params, |
| 2138 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2139 | rem_txq_params) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2140 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 2141 | nla_data(nl_txq_params), |
| 2142 | nla_len(nl_txq_params), |
| 2143 | txq_params_policy); |
| 2144 | if (result) |
| 2145 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2146 | result = parse_txq_params(tb, &txq_params); |
| 2147 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2148 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2149 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2150 | result = rdev_set_txq_params(rdev, netdev, |
| 2151 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2152 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2153 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2154 | } |
| 2155 | } |
| 2156 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2157 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2158 | result = __nl80211_set_channel( |
| 2159 | rdev, |
| 2160 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 2161 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2162 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2163 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2164 | } |
| 2165 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2166 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2167 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2168 | enum nl80211_tx_power_setting type; |
| 2169 | int idx, mbm = 0; |
| 2170 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2171 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2172 | txp_wdev = NULL; |
| 2173 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2174 | if (!rdev->ops->set_tx_power) |
| 2175 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2176 | |
| 2177 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2178 | type = nla_get_u32(info->attrs[idx]); |
| 2179 | |
| 2180 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2181 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2182 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2183 | |
| 2184 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2185 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2186 | mbm = nla_get_u32(info->attrs[idx]); |
| 2187 | } |
| 2188 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2189 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2190 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2191 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2192 | } |
| 2193 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2194 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2195 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2196 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2197 | if ((!rdev->wiphy.available_antennas_tx && |
| 2198 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2199 | !rdev->ops->set_antenna) |
| 2200 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2201 | |
| 2202 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2203 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2204 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2205 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2206 | * available antenna masks, except for the "all" mask */ |
| 2207 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2208 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2209 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2210 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2211 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2212 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2213 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2214 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2215 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2216 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2217 | } |
| 2218 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2219 | changed = 0; |
| 2220 | |
| 2221 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2222 | retry_short = nla_get_u8( |
| 2223 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2224 | if (retry_short == 0) |
| 2225 | return -EINVAL; |
| 2226 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2227 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2228 | } |
| 2229 | |
| 2230 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2231 | retry_long = nla_get_u8( |
| 2232 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2233 | if (retry_long == 0) |
| 2234 | return -EINVAL; |
| 2235 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2236 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2237 | } |
| 2238 | |
| 2239 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2240 | frag_threshold = nla_get_u32( |
| 2241 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2242 | if (frag_threshold < 256) |
| 2243 | return -EINVAL; |
| 2244 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2245 | if (frag_threshold != (u32) -1) { |
| 2246 | /* |
| 2247 | * Fragments (apart from the last one) are required to |
| 2248 | * have even length. Make the fragmentation code |
| 2249 | * simpler by stripping LSB should someone try to use |
| 2250 | * odd threshold value. |
| 2251 | */ |
| 2252 | frag_threshold &= ~0x1; |
| 2253 | } |
| 2254 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2255 | } |
| 2256 | |
| 2257 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2258 | rts_threshold = nla_get_u32( |
| 2259 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2260 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2261 | } |
| 2262 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2263 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2264 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 2265 | return -EINVAL; |
| 2266 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2267 | coverage_class = nla_get_u8( |
| 2268 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2269 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2270 | } |
| 2271 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2272 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 2273 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 2274 | return -EOPNOTSUPP; |
| 2275 | |
| 2276 | changed |= WIPHY_PARAM_DYN_ACK; |
| 2277 | } |
| 2278 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2279 | if (changed) { |
| 2280 | u8 old_retry_short, old_retry_long; |
| 2281 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2282 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2283 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2284 | if (!rdev->ops->set_wiphy_params) |
| 2285 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2286 | |
| 2287 | old_retry_short = rdev->wiphy.retry_short; |
| 2288 | old_retry_long = rdev->wiphy.retry_long; |
| 2289 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2290 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2291 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2292 | |
| 2293 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2294 | rdev->wiphy.retry_short = retry_short; |
| 2295 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2296 | rdev->wiphy.retry_long = retry_long; |
| 2297 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2298 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2299 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2300 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2301 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2302 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2303 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2304 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2305 | if (result) { |
| 2306 | rdev->wiphy.retry_short = old_retry_short; |
| 2307 | rdev->wiphy.retry_long = old_retry_long; |
| 2308 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2309 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2310 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2311 | } |
| 2312 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2313 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2314 | } |
| 2315 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2316 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2317 | { |
| 2318 | return (u64)wdev->identifier | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2319 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2320 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2321 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2322 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2323 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2324 | { |
Johannes Berg | 601555c | 2014-11-27 17:26:56 +0100 | [diff] [blame] | 2325 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 2326 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2327 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2328 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2329 | chandef->chan->center_freq)) |
| 2330 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2331 | switch (chandef->width) { |
| 2332 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2333 | case NL80211_CHAN_WIDTH_20: |
| 2334 | case NL80211_CHAN_WIDTH_40: |
| 2335 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2336 | cfg80211_get_chandef_type(chandef))) |
| 2337 | return -ENOBUFS; |
| 2338 | break; |
| 2339 | default: |
| 2340 | break; |
| 2341 | } |
| 2342 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2343 | return -ENOBUFS; |
| 2344 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2345 | return -ENOBUFS; |
| 2346 | if (chandef->center_freq2 && |
| 2347 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2348 | return -ENOBUFS; |
| 2349 | return 0; |
| 2350 | } |
| 2351 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2352 | 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] | 2353 | struct cfg80211_registered_device *rdev, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2354 | struct wireless_dev *wdev, bool removal) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2355 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2356 | struct net_device *dev = wdev->netdev; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2357 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2358 | void *hdr; |
| 2359 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2360 | if (removal) |
| 2361 | cmd = NL80211_CMD_DEL_INTERFACE; |
| 2362 | |
| 2363 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2364 | if (!hdr) |
| 2365 | return -1; |
| 2366 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2367 | if (dev && |
| 2368 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2369 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2370 | goto nla_put_failure; |
| 2371 | |
| 2372 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2373 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2374 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2375 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2376 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2377 | rdev->devlist_generation ^ |
| 2378 | (cfg80211_rdev_list_generation << 2))) |
| 2379 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2380 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2381 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2382 | int ret; |
| 2383 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2384 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2385 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2386 | if (ret == 0) { |
| 2387 | if (nl80211_send_chandef(msg, &chandef)) |
| 2388 | goto nla_put_failure; |
| 2389 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2390 | } |
| 2391 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2392 | if (wdev->ssid_len) { |
| 2393 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2394 | goto nla_put_failure; |
| 2395 | } |
| 2396 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2397 | return genlmsg_end(msg, hdr); |
| 2398 | |
| 2399 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2400 | genlmsg_cancel(msg, hdr); |
| 2401 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2402 | } |
| 2403 | |
| 2404 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2405 | { |
| 2406 | int wp_idx = 0; |
| 2407 | int if_idx = 0; |
| 2408 | int wp_start = cb->args[0]; |
| 2409 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2410 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2411 | struct wireless_dev *wdev; |
| 2412 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2413 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2414 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2415 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2416 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2417 | if (wp_idx < wp_start) { |
| 2418 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2419 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2420 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2421 | if_idx = 0; |
| 2422 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2423 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2424 | if (if_idx < if_start) { |
| 2425 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2426 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2427 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2428 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2429 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2430 | rdev, wdev, false) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2431 | goto out; |
| 2432 | } |
| 2433 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2434 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2435 | |
| 2436 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2437 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2438 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2439 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2440 | |
| 2441 | cb->args[0] = wp_idx; |
| 2442 | cb->args[1] = if_idx; |
| 2443 | |
| 2444 | return skb->len; |
| 2445 | } |
| 2446 | |
| 2447 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2448 | { |
| 2449 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2450 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2451 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2452 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2453 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2454 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2455 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2456 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2457 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2458 | rdev, wdev, false) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2459 | nlmsg_free(msg); |
| 2460 | return -ENOBUFS; |
| 2461 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2462 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2463 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2464 | } |
| 2465 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2466 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2467 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2468 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2469 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2470 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2471 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2472 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2473 | }; |
| 2474 | |
| 2475 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2476 | { |
| 2477 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2478 | int flag; |
| 2479 | |
| 2480 | *mntrflags = 0; |
| 2481 | |
| 2482 | if (!nla) |
| 2483 | return -EINVAL; |
| 2484 | |
| 2485 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2486 | nla, mntr_flags_policy)) |
| 2487 | return -EINVAL; |
| 2488 | |
| 2489 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2490 | if (flags[flag]) |
| 2491 | *mntrflags |= (1<<flag); |
| 2492 | |
| 2493 | return 0; |
| 2494 | } |
| 2495 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2496 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2497 | struct net_device *netdev, u8 use_4addr, |
| 2498 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2499 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2500 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2501 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2502 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2503 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2504 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2505 | |
| 2506 | switch (iftype) { |
| 2507 | case NL80211_IFTYPE_AP_VLAN: |
| 2508 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2509 | return 0; |
| 2510 | break; |
| 2511 | case NL80211_IFTYPE_STATION: |
| 2512 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2513 | return 0; |
| 2514 | break; |
| 2515 | default: |
| 2516 | break; |
| 2517 | } |
| 2518 | |
| 2519 | return -EOPNOTSUPP; |
| 2520 | } |
| 2521 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2522 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2523 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2524 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2525 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2526 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2527 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2528 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2529 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2530 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2531 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2532 | memset(¶ms, 0, sizeof(params)); |
| 2533 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2534 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2535 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2536 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2537 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2538 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2539 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2540 | if (ntype > NL80211_IFTYPE_MAX) |
| 2541 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2542 | } |
| 2543 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2544 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2545 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2546 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2547 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2548 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2549 | if (netif_running(dev)) |
| 2550 | return -EBUSY; |
| 2551 | |
| 2552 | wdev_lock(wdev); |
| 2553 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2554 | IEEE80211_MAX_MESH_ID_LEN); |
| 2555 | wdev->mesh_id_up_len = |
| 2556 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2557 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2558 | wdev->mesh_id_up_len); |
| 2559 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2560 | } |
| 2561 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2562 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2563 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2564 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2565 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2566 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2567 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2568 | } else { |
| 2569 | params.use_4addr = -1; |
| 2570 | } |
| 2571 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2572 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2573 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2574 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2575 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2576 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2577 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2578 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2579 | |
| 2580 | flags = &_flags; |
| 2581 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2582 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2583 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2584 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2585 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2586 | return -EOPNOTSUPP; |
| 2587 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2588 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2589 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2590 | else |
| 2591 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2592 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2593 | if (!err && params.use_4addr != -1) |
| 2594 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2595 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2596 | return err; |
| 2597 | } |
| 2598 | |
| 2599 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2600 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2601 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2602 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2603 | struct wireless_dev *wdev; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2604 | struct sk_buff *msg, *event; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2605 | int err; |
| 2606 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2607 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2608 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2609 | /* to avoid failing a new interface creation due to pending removal */ |
| 2610 | cfg80211_destroy_ifaces(rdev); |
| 2611 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2612 | memset(¶ms, 0, sizeof(params)); |
| 2613 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2614 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2615 | return -EINVAL; |
| 2616 | |
| 2617 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2618 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2619 | if (type > NL80211_IFTYPE_MAX) |
| 2620 | return -EINVAL; |
| 2621 | } |
| 2622 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2623 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2624 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2625 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2626 | |
Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 2627 | if ((type == NL80211_IFTYPE_P2P_DEVICE || |
| 2628 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 2629 | info->attrs[NL80211_ATTR_MAC]) { |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2630 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2631 | ETH_ALEN); |
| 2632 | if (!is_valid_ether_addr(params.macaddr)) |
| 2633 | return -EADDRNOTAVAIL; |
| 2634 | } |
| 2635 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2636 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2637 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2638 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2639 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2640 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2641 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2642 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2643 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2644 | if (!msg) |
| 2645 | return -ENOMEM; |
| 2646 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2647 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2648 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2649 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2650 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2651 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2652 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2653 | return -EOPNOTSUPP; |
| 2654 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2655 | wdev = rdev_add_virtual_intf(rdev, |
| 2656 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2657 | type, err ? NULL : &flags, ¶ms); |
Rafał Miłecki | d687cbb | 2014-11-14 18:43:28 +0100 | [diff] [blame] | 2658 | if (WARN_ON(!wdev)) { |
| 2659 | nlmsg_free(msg); |
| 2660 | return -EPROTO; |
| 2661 | } else if (IS_ERR(wdev)) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2662 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2663 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2664 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2665 | |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 2666 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2667 | wdev->owner_nlportid = info->snd_portid; |
| 2668 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2669 | switch (type) { |
| 2670 | case NL80211_IFTYPE_MESH_POINT: |
| 2671 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2672 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2673 | wdev_lock(wdev); |
| 2674 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2675 | IEEE80211_MAX_MESH_ID_LEN); |
| 2676 | wdev->mesh_id_up_len = |
| 2677 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2678 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2679 | wdev->mesh_id_up_len); |
| 2680 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2681 | break; |
| 2682 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2683 | /* |
| 2684 | * P2P Device doesn't have a netdev, so doesn't go |
| 2685 | * through the netdev notifier and must be added here |
| 2686 | */ |
| 2687 | mutex_init(&wdev->mtx); |
| 2688 | INIT_LIST_HEAD(&wdev->event_list); |
| 2689 | spin_lock_init(&wdev->event_lock); |
| 2690 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2691 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2692 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2693 | wdev->identifier = ++rdev->wdev_id; |
| 2694 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2695 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2696 | break; |
| 2697 | default: |
| 2698 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2699 | } |
| 2700 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2701 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2702 | rdev, wdev, false) < 0) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2703 | nlmsg_free(msg); |
| 2704 | return -ENOBUFS; |
| 2705 | } |
| 2706 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2707 | event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2708 | if (event) { |
| 2709 | if (nl80211_send_iface(event, 0, 0, 0, |
| 2710 | rdev, wdev, false) < 0) { |
| 2711 | nlmsg_free(event); |
| 2712 | goto out; |
| 2713 | } |
| 2714 | |
| 2715 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 2716 | event, 0, NL80211_MCGRP_CONFIG, |
| 2717 | GFP_KERNEL); |
| 2718 | } |
| 2719 | |
| 2720 | out: |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2721 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2722 | } |
| 2723 | |
| 2724 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2725 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2726 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2727 | struct wireless_dev *wdev = info->user_ptr[1]; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2728 | struct sk_buff *msg; |
| 2729 | int status; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2730 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2731 | if (!rdev->ops->del_virtual_intf) |
| 2732 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2733 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2734 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2735 | if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) { |
| 2736 | nlmsg_free(msg); |
| 2737 | msg = NULL; |
| 2738 | } |
| 2739 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2740 | /* |
| 2741 | * If we remove a wireless device without a netdev then clear |
| 2742 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2743 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2744 | * since the wdev has been freed, unlike with a netdev where |
| 2745 | * we need the dev_put() for the netdev to really be freed. |
| 2746 | */ |
| 2747 | if (!wdev->netdev) |
| 2748 | info->user_ptr[1] = NULL; |
| 2749 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2750 | status = rdev_del_virtual_intf(rdev, wdev); |
| 2751 | if (status >= 0 && msg) |
| 2752 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 2753 | msg, 0, NL80211_MCGRP_CONFIG, |
| 2754 | GFP_KERNEL); |
| 2755 | else |
| 2756 | nlmsg_free(msg); |
| 2757 | |
| 2758 | return status; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2759 | } |
| 2760 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2761 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2762 | { |
| 2763 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2764 | struct net_device *dev = info->user_ptr[1]; |
| 2765 | u16 noack_map; |
| 2766 | |
| 2767 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2768 | return -EINVAL; |
| 2769 | |
| 2770 | if (!rdev->ops->set_noack_map) |
| 2771 | return -EOPNOTSUPP; |
| 2772 | |
| 2773 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2774 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2775 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2776 | } |
| 2777 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2778 | struct get_key_cookie { |
| 2779 | struct sk_buff *msg; |
| 2780 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2781 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2782 | }; |
| 2783 | |
| 2784 | static void get_key_callback(void *c, struct key_params *params) |
| 2785 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2786 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2787 | struct get_key_cookie *cookie = c; |
| 2788 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2789 | if ((params->key && |
| 2790 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2791 | params->key_len, params->key)) || |
| 2792 | (params->seq && |
| 2793 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2794 | params->seq_len, params->seq)) || |
| 2795 | (params->cipher && |
| 2796 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2797 | params->cipher))) |
| 2798 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2799 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2800 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2801 | if (!key) |
| 2802 | goto nla_put_failure; |
| 2803 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2804 | if ((params->key && |
| 2805 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2806 | params->key_len, params->key)) || |
| 2807 | (params->seq && |
| 2808 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2809 | params->seq_len, params->seq)) || |
| 2810 | (params->cipher && |
| 2811 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2812 | params->cipher))) |
| 2813 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2814 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2815 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2816 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2817 | |
| 2818 | nla_nest_end(cookie->msg, key); |
| 2819 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2820 | return; |
| 2821 | nla_put_failure: |
| 2822 | cookie->error = 1; |
| 2823 | } |
| 2824 | |
| 2825 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2826 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2827 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2828 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2829 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2830 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2831 | const u8 *mac_addr = NULL; |
| 2832 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2833 | struct get_key_cookie cookie = { |
| 2834 | .error = 0, |
| 2835 | }; |
| 2836 | void *hdr; |
| 2837 | struct sk_buff *msg; |
| 2838 | |
| 2839 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2840 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2841 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2842 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2843 | return -EINVAL; |
| 2844 | |
| 2845 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2846 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2847 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2848 | pairwise = !!mac_addr; |
| 2849 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2850 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2851 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2852 | return -EINVAL; |
| 2853 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2854 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2855 | return -EINVAL; |
| 2856 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2857 | } |
| 2858 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2859 | if (!rdev->ops->get_key) |
| 2860 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2861 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2862 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2863 | if (!msg) |
| 2864 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2865 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2866 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2867 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2868 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 2869 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2870 | |
| 2871 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2872 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2873 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2874 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2875 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2876 | goto nla_put_failure; |
| 2877 | if (mac_addr && |
| 2878 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2879 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2880 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2881 | if (pairwise && mac_addr && |
| 2882 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2883 | return -ENOENT; |
| 2884 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2885 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2886 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2887 | |
| 2888 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2889 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2890 | |
| 2891 | if (cookie.error) |
| 2892 | goto nla_put_failure; |
| 2893 | |
| 2894 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2895 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2896 | |
| 2897 | nla_put_failure: |
| 2898 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2899 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2900 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2901 | return err; |
| 2902 | } |
| 2903 | |
| 2904 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2905 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2906 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2907 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2908 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2909 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2910 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2911 | err = nl80211_parse_key(info, &key); |
| 2912 | if (err) |
| 2913 | return err; |
| 2914 | |
| 2915 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2916 | return -EINVAL; |
| 2917 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2918 | /* only support setting default key */ |
| 2919 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2920 | return -EINVAL; |
| 2921 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2922 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2923 | |
| 2924 | if (key.def) { |
| 2925 | if (!rdev->ops->set_default_key) { |
| 2926 | err = -EOPNOTSUPP; |
| 2927 | goto out; |
| 2928 | } |
| 2929 | |
| 2930 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2931 | if (err) |
| 2932 | goto out; |
| 2933 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2934 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2935 | key.def_uni, key.def_multi); |
| 2936 | |
| 2937 | if (err) |
| 2938 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2939 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2940 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2941 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2942 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2943 | } else { |
| 2944 | if (key.def_uni || !key.def_multi) { |
| 2945 | err = -EINVAL; |
| 2946 | goto out; |
| 2947 | } |
| 2948 | |
| 2949 | if (!rdev->ops->set_default_mgmt_key) { |
| 2950 | err = -EOPNOTSUPP; |
| 2951 | goto out; |
| 2952 | } |
| 2953 | |
| 2954 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2955 | if (err) |
| 2956 | goto out; |
| 2957 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2958 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2959 | if (err) |
| 2960 | goto out; |
| 2961 | |
| 2962 | #ifdef CONFIG_CFG80211_WEXT |
| 2963 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2964 | #endif |
| 2965 | } |
| 2966 | |
| 2967 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2968 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2969 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2970 | return err; |
| 2971 | } |
| 2972 | |
| 2973 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2974 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2975 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2976 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2977 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2978 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2979 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2980 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2981 | err = nl80211_parse_key(info, &key); |
| 2982 | if (err) |
| 2983 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2984 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2985 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2986 | return -EINVAL; |
| 2987 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2988 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2989 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2990 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2991 | if (key.type == -1) { |
| 2992 | if (mac_addr) |
| 2993 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2994 | else |
| 2995 | key.type = NL80211_KEYTYPE_GROUP; |
| 2996 | } |
| 2997 | |
| 2998 | /* for now */ |
| 2999 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3000 | key.type != NL80211_KEYTYPE_GROUP) |
| 3001 | return -EINVAL; |
| 3002 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3003 | if (!rdev->ops->add_key) |
| 3004 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3005 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3006 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 3007 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3008 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3009 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3010 | |
| 3011 | wdev_lock(dev->ieee80211_ptr); |
| 3012 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3013 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3014 | err = rdev_add_key(rdev, dev, key.idx, |
| 3015 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3016 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3017 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3018 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3019 | return err; |
| 3020 | } |
| 3021 | |
| 3022 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 3023 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3024 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3025 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3026 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3027 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3028 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3029 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3030 | err = nl80211_parse_key(info, &key); |
| 3031 | if (err) |
| 3032 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3033 | |
| 3034 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3035 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3036 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3037 | if (key.type == -1) { |
| 3038 | if (mac_addr) |
| 3039 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3040 | else |
| 3041 | key.type = NL80211_KEYTYPE_GROUP; |
| 3042 | } |
| 3043 | |
| 3044 | /* for now */ |
| 3045 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3046 | key.type != NL80211_KEYTYPE_GROUP) |
| 3047 | return -EINVAL; |
| 3048 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3049 | if (!rdev->ops->del_key) |
| 3050 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3051 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3052 | wdev_lock(dev->ieee80211_ptr); |
| 3053 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3054 | |
| 3055 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 3056 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3057 | err = -ENOENT; |
| 3058 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3059 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3060 | err = rdev_del_key(rdev, dev, key.idx, |
| 3061 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3062 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3063 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3064 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3065 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3066 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3067 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3068 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3069 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 3070 | } |
| 3071 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3072 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3073 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3074 | return err; |
| 3075 | } |
| 3076 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3077 | /* This function returns an error or the number of nested attributes */ |
| 3078 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 3079 | { |
| 3080 | struct nlattr *attr; |
| 3081 | int n_entries = 0, tmp; |
| 3082 | |
| 3083 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 3084 | if (nla_len(attr) != ETH_ALEN) |
| 3085 | return -EINVAL; |
| 3086 | |
| 3087 | n_entries++; |
| 3088 | } |
| 3089 | |
| 3090 | return n_entries; |
| 3091 | } |
| 3092 | |
| 3093 | /* |
| 3094 | * This function parses ACL information and allocates memory for ACL data. |
| 3095 | * On successful return, the calling function is responsible to free the |
| 3096 | * ACL buffer returned by this function. |
| 3097 | */ |
| 3098 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 3099 | struct genl_info *info) |
| 3100 | { |
| 3101 | enum nl80211_acl_policy acl_policy; |
| 3102 | struct nlattr *attr; |
| 3103 | struct cfg80211_acl_data *acl; |
| 3104 | int i = 0, n_entries, tmp; |
| 3105 | |
| 3106 | if (!wiphy->max_acl_mac_addrs) |
| 3107 | return ERR_PTR(-EOPNOTSUPP); |
| 3108 | |
| 3109 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 3110 | return ERR_PTR(-EINVAL); |
| 3111 | |
| 3112 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 3113 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 3114 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 3115 | return ERR_PTR(-EINVAL); |
| 3116 | |
| 3117 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 3118 | return ERR_PTR(-EINVAL); |
| 3119 | |
| 3120 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 3121 | if (n_entries < 0) |
| 3122 | return ERR_PTR(n_entries); |
| 3123 | |
| 3124 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 3125 | return ERR_PTR(-ENOTSUPP); |
| 3126 | |
| 3127 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 3128 | GFP_KERNEL); |
| 3129 | if (!acl) |
| 3130 | return ERR_PTR(-ENOMEM); |
| 3131 | |
| 3132 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 3133 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3134 | i++; |
| 3135 | } |
| 3136 | |
| 3137 | acl->n_acl_entries = n_entries; |
| 3138 | acl->acl_policy = acl_policy; |
| 3139 | |
| 3140 | return acl; |
| 3141 | } |
| 3142 | |
| 3143 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3144 | { |
| 3145 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3146 | struct net_device *dev = info->user_ptr[1]; |
| 3147 | struct cfg80211_acl_data *acl; |
| 3148 | int err; |
| 3149 | |
| 3150 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3151 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3152 | return -EOPNOTSUPP; |
| 3153 | |
| 3154 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3155 | return -EINVAL; |
| 3156 | |
| 3157 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3158 | if (IS_ERR(acl)) |
| 3159 | return PTR_ERR(acl); |
| 3160 | |
| 3161 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3162 | |
| 3163 | kfree(acl); |
| 3164 | |
| 3165 | return err; |
| 3166 | } |
| 3167 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3168 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3169 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3170 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3171 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3172 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3173 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3174 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3175 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3176 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3177 | return -EINVAL; |
| 3178 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3179 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3180 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3181 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3182 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3183 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3184 | if (!bcn->head_len) |
| 3185 | return -EINVAL; |
| 3186 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3187 | } |
| 3188 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3189 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3190 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3191 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3192 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3193 | } |
| 3194 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3195 | if (!haveinfo) |
| 3196 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3197 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3198 | if (attrs[NL80211_ATTR_IE]) { |
| 3199 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3200 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3201 | } |
| 3202 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3203 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3204 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3205 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3206 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3207 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3208 | } |
| 3209 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3210 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3211 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3212 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3213 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3214 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3215 | } |
| 3216 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3217 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3218 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3219 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3220 | } |
| 3221 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3222 | return 0; |
| 3223 | } |
| 3224 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3225 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3226 | struct cfg80211_ap_settings *params) |
| 3227 | { |
| 3228 | struct wireless_dev *wdev; |
| 3229 | bool ret = false; |
| 3230 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3231 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3232 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3233 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3234 | continue; |
| 3235 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3236 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3237 | continue; |
| 3238 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3239 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3240 | ret = true; |
| 3241 | break; |
| 3242 | } |
| 3243 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3244 | return ret; |
| 3245 | } |
| 3246 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3247 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3248 | enum nl80211_auth_type auth_type, |
| 3249 | enum nl80211_commands cmd) |
| 3250 | { |
| 3251 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3252 | return false; |
| 3253 | |
| 3254 | switch (cmd) { |
| 3255 | case NL80211_CMD_AUTHENTICATE: |
| 3256 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3257 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3258 | return false; |
| 3259 | return true; |
| 3260 | case NL80211_CMD_CONNECT: |
| 3261 | case NL80211_CMD_START_AP: |
| 3262 | /* SAE not supported yet */ |
| 3263 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3264 | return false; |
| 3265 | return true; |
| 3266 | default: |
| 3267 | return false; |
| 3268 | } |
| 3269 | } |
| 3270 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3271 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3272 | { |
| 3273 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3274 | struct net_device *dev = info->user_ptr[1]; |
| 3275 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3276 | struct cfg80211_ap_settings params; |
| 3277 | int err; |
| 3278 | |
| 3279 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3280 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3281 | return -EOPNOTSUPP; |
| 3282 | |
| 3283 | if (!rdev->ops->start_ap) |
| 3284 | return -EOPNOTSUPP; |
| 3285 | |
| 3286 | if (wdev->beacon_interval) |
| 3287 | return -EALREADY; |
| 3288 | |
| 3289 | memset(¶ms, 0, sizeof(params)); |
| 3290 | |
| 3291 | /* these are required for START_AP */ |
| 3292 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3293 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3294 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3295 | return -EINVAL; |
| 3296 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3297 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3298 | if (err) |
| 3299 | return err; |
| 3300 | |
| 3301 | params.beacon_interval = |
| 3302 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3303 | params.dtim_period = |
| 3304 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3305 | |
| 3306 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3307 | if (err) |
| 3308 | return err; |
| 3309 | |
| 3310 | /* |
| 3311 | * In theory, some of these attributes should be required here |
| 3312 | * but since they were not used when the command was originally |
| 3313 | * added, keep them optional for old user space programs to let |
| 3314 | * them continue to work with drivers that do not need the |
| 3315 | * additional information -- drivers must check! |
| 3316 | */ |
| 3317 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3318 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3319 | params.ssid_len = |
| 3320 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3321 | if (params.ssid_len == 0 || |
| 3322 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3323 | return -EINVAL; |
| 3324 | } |
| 3325 | |
| 3326 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3327 | params.hidden_ssid = nla_get_u32( |
| 3328 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3329 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3330 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3331 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3332 | return -EINVAL; |
| 3333 | } |
| 3334 | |
| 3335 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3336 | |
| 3337 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3338 | params.auth_type = nla_get_u32( |
| 3339 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3340 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3341 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3342 | return -EINVAL; |
| 3343 | } else |
| 3344 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3345 | |
| 3346 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3347 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3348 | if (err) |
| 3349 | return err; |
| 3350 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3351 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3352 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3353 | return -EOPNOTSUPP; |
| 3354 | params.inactivity_timeout = nla_get_u16( |
| 3355 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3356 | } |
| 3357 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3358 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3359 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3360 | return -EINVAL; |
| 3361 | params.p2p_ctwindow = |
| 3362 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3363 | if (params.p2p_ctwindow > 127) |
| 3364 | return -EINVAL; |
| 3365 | if (params.p2p_ctwindow != 0 && |
| 3366 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3367 | return -EINVAL; |
| 3368 | } |
| 3369 | |
| 3370 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3371 | u8 tmp; |
| 3372 | |
| 3373 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3374 | return -EINVAL; |
| 3375 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3376 | if (tmp > 1) |
| 3377 | return -EINVAL; |
| 3378 | params.p2p_opp_ps = tmp; |
| 3379 | if (params.p2p_opp_ps != 0 && |
| 3380 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3381 | return -EINVAL; |
| 3382 | } |
| 3383 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3384 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3385 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3386 | if (err) |
| 3387 | return err; |
| 3388 | } else if (wdev->preset_chandef.chan) { |
| 3389 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3390 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3391 | return -EINVAL; |
| 3392 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 3393 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
| 3394 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3395 | return -EINVAL; |
| 3396 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3397 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3398 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3399 | if (IS_ERR(params.acl)) |
| 3400 | return PTR_ERR(params.acl); |
| 3401 | } |
| 3402 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 3403 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 3404 | params.smps_mode = |
| 3405 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 3406 | switch (params.smps_mode) { |
| 3407 | case NL80211_SMPS_OFF: |
| 3408 | break; |
| 3409 | case NL80211_SMPS_STATIC: |
| 3410 | if (!(rdev->wiphy.features & |
| 3411 | NL80211_FEATURE_STATIC_SMPS)) |
| 3412 | return -EINVAL; |
| 3413 | break; |
| 3414 | case NL80211_SMPS_DYNAMIC: |
| 3415 | if (!(rdev->wiphy.features & |
| 3416 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 3417 | return -EINVAL; |
| 3418 | break; |
| 3419 | default: |
| 3420 | return -EINVAL; |
| 3421 | } |
| 3422 | } else { |
| 3423 | params.smps_mode = NL80211_SMPS_OFF; |
| 3424 | } |
| 3425 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3426 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3427 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3428 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3429 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3430 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 3431 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3432 | wdev->ssid_len = params.ssid_len; |
| 3433 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3434 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3435 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3436 | |
| 3437 | kfree(params.acl); |
| 3438 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3439 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3440 | } |
| 3441 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3442 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3443 | { |
| 3444 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3445 | struct net_device *dev = info->user_ptr[1]; |
| 3446 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3447 | struct cfg80211_beacon_data params; |
| 3448 | int err; |
| 3449 | |
| 3450 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3451 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3452 | return -EOPNOTSUPP; |
| 3453 | |
| 3454 | if (!rdev->ops->change_beacon) |
| 3455 | return -EOPNOTSUPP; |
| 3456 | |
| 3457 | if (!wdev->beacon_interval) |
| 3458 | return -EINVAL; |
| 3459 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3460 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3461 | if (err) |
| 3462 | return err; |
| 3463 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3464 | wdev_lock(wdev); |
| 3465 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 3466 | wdev_unlock(wdev); |
| 3467 | |
| 3468 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3469 | } |
| 3470 | |
| 3471 | 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] | 3472 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3473 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3474 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3475 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 3476 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3477 | } |
| 3478 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3479 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3480 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3481 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3482 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3483 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3484 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3485 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3486 | }; |
| 3487 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3488 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3489 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3490 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3491 | { |
| 3492 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3493 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3494 | int flag; |
| 3495 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3496 | /* |
| 3497 | * Try parsing the new attribute first so userspace |
| 3498 | * can specify both for older kernels. |
| 3499 | */ |
| 3500 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3501 | if (nla) { |
| 3502 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3503 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3504 | sta_flags = nla_data(nla); |
| 3505 | params->sta_flags_mask = sta_flags->mask; |
| 3506 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3507 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3508 | if ((params->sta_flags_mask | |
| 3509 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3510 | return -EINVAL; |
| 3511 | return 0; |
| 3512 | } |
| 3513 | |
| 3514 | /* if present, parse the old attribute */ |
| 3515 | |
| 3516 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3517 | if (!nla) |
| 3518 | return 0; |
| 3519 | |
| 3520 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3521 | nla, sta_flags_policy)) |
| 3522 | return -EINVAL; |
| 3523 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3524 | /* |
| 3525 | * Only allow certain flags for interface types so that |
| 3526 | * other attributes are silently ignored. Remember that |
| 3527 | * this is backward compatibility code with old userspace |
| 3528 | * and shouldn't be hit in other cases anyway. |
| 3529 | */ |
| 3530 | switch (iftype) { |
| 3531 | case NL80211_IFTYPE_AP: |
| 3532 | case NL80211_IFTYPE_AP_VLAN: |
| 3533 | case NL80211_IFTYPE_P2P_GO: |
| 3534 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3535 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3536 | BIT(NL80211_STA_FLAG_WME) | |
| 3537 | BIT(NL80211_STA_FLAG_MFP); |
| 3538 | break; |
| 3539 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3540 | case NL80211_IFTYPE_STATION: |
| 3541 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3542 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3543 | break; |
| 3544 | case NL80211_IFTYPE_MESH_POINT: |
| 3545 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3546 | BIT(NL80211_STA_FLAG_MFP) | |
| 3547 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3548 | default: |
| 3549 | return -EINVAL; |
| 3550 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3551 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3552 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3553 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3554 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3555 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3556 | /* no longer support new API additions in old API */ |
| 3557 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3558 | return -EINVAL; |
| 3559 | } |
| 3560 | } |
| 3561 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3562 | return 0; |
| 3563 | } |
| 3564 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3565 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3566 | int attr) |
| 3567 | { |
| 3568 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3569 | u32 bitrate; |
| 3570 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3571 | |
| 3572 | rate = nla_nest_start(msg, attr); |
| 3573 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3574 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3575 | |
| 3576 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3577 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3578 | /* report 16-bit bitrate only if we can */ |
| 3579 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3580 | if (bitrate > 0 && |
| 3581 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3582 | return false; |
| 3583 | if (bitrate_compat > 0 && |
| 3584 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3585 | return false; |
| 3586 | |
| 3587 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3588 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3589 | return false; |
| 3590 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3591 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3592 | return false; |
| 3593 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3594 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3595 | return false; |
| 3596 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3597 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3598 | return false; |
| 3599 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3600 | return false; |
| 3601 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3602 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3603 | return false; |
| 3604 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3605 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3606 | return false; |
| 3607 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3608 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3609 | return false; |
| 3610 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3611 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3612 | return false; |
| 3613 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3614 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3615 | return false; |
| 3616 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3617 | |
| 3618 | nla_nest_end(msg, rate); |
| 3619 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3620 | } |
| 3621 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3622 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3623 | int id) |
| 3624 | { |
| 3625 | void *attr; |
| 3626 | int i = 0; |
| 3627 | |
| 3628 | if (!mask) |
| 3629 | return true; |
| 3630 | |
| 3631 | attr = nla_nest_start(msg, id); |
| 3632 | if (!attr) |
| 3633 | return false; |
| 3634 | |
| 3635 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3636 | if (!(mask & BIT(i))) |
| 3637 | continue; |
| 3638 | |
| 3639 | if (nla_put_u8(msg, i, signal[i])) |
| 3640 | return false; |
| 3641 | } |
| 3642 | |
| 3643 | nla_nest_end(msg, attr); |
| 3644 | |
| 3645 | return true; |
| 3646 | } |
| 3647 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3648 | static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3649 | int flags, |
| 3650 | struct cfg80211_registered_device *rdev, |
| 3651 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3652 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3653 | { |
| 3654 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3655 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3656 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3657 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3658 | if (!hdr) |
| 3659 | return -1; |
| 3660 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3661 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3662 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3663 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3664 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3665 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3666 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3667 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3668 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3669 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3670 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3671 | sinfo->connected_time)) |
| 3672 | goto nla_put_failure; |
| 3673 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3674 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3675 | sinfo->inactive_time)) |
| 3676 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3677 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3678 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3679 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3680 | (u32)sinfo->rx_bytes)) |
| 3681 | goto nla_put_failure; |
| 3682 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3683 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3684 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3685 | (u32)sinfo->tx_bytes)) |
| 3686 | goto nla_put_failure; |
| 3687 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3688 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3689 | sinfo->rx_bytes)) |
| 3690 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3691 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3692 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3693 | sinfo->tx_bytes)) |
| 3694 | goto nla_put_failure; |
| 3695 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3696 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3697 | goto nla_put_failure; |
| 3698 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3699 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3700 | goto nla_put_failure; |
| 3701 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3702 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3703 | sinfo->plink_state)) |
| 3704 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3705 | switch (rdev->wiphy.signal_type) { |
| 3706 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3707 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3708 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3709 | sinfo->signal)) |
| 3710 | goto nla_put_failure; |
| 3711 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3712 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3713 | sinfo->signal_avg)) |
| 3714 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3715 | break; |
| 3716 | default: |
| 3717 | break; |
| 3718 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3719 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3720 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3721 | sinfo->chain_signal, |
| 3722 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3723 | goto nla_put_failure; |
| 3724 | } |
| 3725 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3726 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3727 | sinfo->chain_signal_avg, |
| 3728 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3729 | goto nla_put_failure; |
| 3730 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3731 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3732 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3733 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3734 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3735 | } |
| 3736 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3737 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3738 | NL80211_STA_INFO_RX_BITRATE)) |
| 3739 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3740 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3741 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3742 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3743 | sinfo->rx_packets)) |
| 3744 | goto nla_put_failure; |
| 3745 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3746 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3747 | sinfo->tx_packets)) |
| 3748 | goto nla_put_failure; |
| 3749 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3750 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3751 | sinfo->tx_retries)) |
| 3752 | goto nla_put_failure; |
| 3753 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3754 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3755 | sinfo->tx_failed)) |
| 3756 | goto nla_put_failure; |
Antonio Quartulli | 867d849 | 2014-05-19 21:53:19 +0200 | [diff] [blame] | 3757 | if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) && |
| 3758 | nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT, |
| 3759 | sinfo->expected_throughput)) |
| 3760 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3761 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3762 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3763 | sinfo->beacon_loss_count)) |
| 3764 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3765 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3766 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3767 | sinfo->local_pm)) |
| 3768 | goto nla_put_failure; |
| 3769 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3770 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3771 | sinfo->peer_pm)) |
| 3772 | goto nla_put_failure; |
| 3773 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3774 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3775 | sinfo->nonpeer_pm)) |
| 3776 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3777 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3778 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3779 | if (!bss_param) |
| 3780 | goto nla_put_failure; |
| 3781 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3782 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3783 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3784 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3785 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3786 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3787 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3788 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3789 | sinfo->bss_param.dtim_period) || |
| 3790 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3791 | sinfo->bss_param.beacon_interval)) |
| 3792 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3793 | |
| 3794 | nla_nest_end(msg, bss_param); |
| 3795 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3796 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3797 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3798 | sizeof(struct nl80211_sta_flag_update), |
| 3799 | &sinfo->sta_flags)) |
| 3800 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3801 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3802 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3803 | sinfo->t_offset)) |
| 3804 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3805 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3806 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3807 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3808 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3809 | sinfo->assoc_req_ies)) |
| 3810 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3811 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3812 | return genlmsg_end(msg, hdr); |
| 3813 | |
| 3814 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3815 | genlmsg_cancel(msg, hdr); |
| 3816 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3817 | } |
| 3818 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3819 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3820 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3821 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3822 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3823 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3824 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3825 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3826 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3827 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3828 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3829 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3830 | if (err) |
| 3831 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3832 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3833 | if (!wdev->netdev) { |
| 3834 | err = -EINVAL; |
| 3835 | goto out_err; |
| 3836 | } |
| 3837 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3838 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3839 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3840 | goto out_err; |
| 3841 | } |
| 3842 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3843 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3844 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3845 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3846 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3847 | if (err == -ENOENT) |
| 3848 | break; |
| 3849 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3850 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3851 | |
| 3852 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3853 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3854 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3855 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3856 | &sinfo) < 0) |
| 3857 | goto out; |
| 3858 | |
| 3859 | sta_idx++; |
| 3860 | } |
| 3861 | |
| 3862 | |
| 3863 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3864 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3865 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3866 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3867 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3868 | |
| 3869 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3870 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3871 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3872 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3873 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3874 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3875 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3876 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3877 | struct sk_buff *msg; |
| 3878 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3879 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3880 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3881 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3882 | |
| 3883 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3884 | return -EINVAL; |
| 3885 | |
| 3886 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3887 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3888 | if (!rdev->ops->get_station) |
| 3889 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3890 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3891 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3892 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3893 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3894 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3895 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3896 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3897 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3898 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3899 | if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3900 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3901 | nlmsg_free(msg); |
| 3902 | return -ENOBUFS; |
| 3903 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3904 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3905 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3906 | } |
| 3907 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3908 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3909 | struct station_parameters *params, |
| 3910 | enum cfg80211_station_type statype) |
| 3911 | { |
| 3912 | if (params->listen_interval != -1) |
| 3913 | return -EINVAL; |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 3914 | if (params->aid && |
| 3915 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3916 | return -EINVAL; |
| 3917 | |
| 3918 | /* When you run into this, adjust the code below for the new flag */ |
| 3919 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3920 | |
| 3921 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3922 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3923 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3924 | /* |
| 3925 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3926 | * code doesn't have the bug of including TDLS in the |
| 3927 | * mask everywhere. |
| 3928 | */ |
| 3929 | if (params->sta_flags_mask & |
| 3930 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3931 | BIT(NL80211_STA_FLAG_MFP) | |
| 3932 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3933 | return -EINVAL; |
| 3934 | break; |
| 3935 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3936 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3937 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3938 | return -EINVAL; |
| 3939 | /* ignore since it can't change */ |
| 3940 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3941 | break; |
| 3942 | default: |
| 3943 | /* disallow mesh-specific things */ |
| 3944 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3945 | return -EINVAL; |
| 3946 | if (params->local_pm) |
| 3947 | return -EINVAL; |
| 3948 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3949 | return -EINVAL; |
| 3950 | } |
| 3951 | |
| 3952 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3953 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3954 | /* TDLS can't be set, ... */ |
| 3955 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3956 | return -EINVAL; |
| 3957 | /* |
| 3958 | * ... but don't bother the driver with it. This works around |
| 3959 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3960 | * TLDS_PEER flag in the mask even for AP mode. |
| 3961 | */ |
| 3962 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3963 | } |
| 3964 | |
| 3965 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3966 | /* reject other things that can't change */ |
| 3967 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3968 | return -EINVAL; |
| 3969 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3970 | return -EINVAL; |
| 3971 | if (params->supported_rates) |
| 3972 | return -EINVAL; |
| 3973 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3974 | return -EINVAL; |
| 3975 | } |
| 3976 | |
| 3977 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3978 | if (params->vlan) |
| 3979 | return -EINVAL; |
| 3980 | } |
| 3981 | |
| 3982 | switch (statype) { |
| 3983 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3984 | /* Use this only for authorizing/unauthorizing a station */ |
| 3985 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3986 | return -EOPNOTSUPP; |
| 3987 | break; |
| 3988 | case CFG80211_STA_AP_CLIENT: |
| 3989 | /* accept only the listed bits */ |
| 3990 | if (params->sta_flags_mask & |
| 3991 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3992 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3993 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3994 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3995 | BIT(NL80211_STA_FLAG_WME) | |
| 3996 | BIT(NL80211_STA_FLAG_MFP))) |
| 3997 | return -EINVAL; |
| 3998 | |
| 3999 | /* but authenticated/associated only if driver handles it */ |
| 4000 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4001 | params->sta_flags_mask & |
| 4002 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4003 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4004 | return -EINVAL; |
| 4005 | break; |
| 4006 | case CFG80211_STA_IBSS: |
| 4007 | case CFG80211_STA_AP_STA: |
| 4008 | /* reject any changes other than AUTHORIZED */ |
| 4009 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 4010 | return -EINVAL; |
| 4011 | break; |
| 4012 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4013 | /* reject any changes other than AUTHORIZED or WME */ |
| 4014 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4015 | BIT(NL80211_STA_FLAG_WME))) |
| 4016 | return -EINVAL; |
| 4017 | /* force (at least) rates when authorizing */ |
| 4018 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 4019 | !params->supported_rates) |
| 4020 | return -EINVAL; |
| 4021 | break; |
| 4022 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4023 | /* reject any changes */ |
| 4024 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4025 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4026 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4027 | return -EINVAL; |
| 4028 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4029 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4030 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 4031 | return -EINVAL; |
| 4032 | break; |
| 4033 | } |
| 4034 | |
| 4035 | return 0; |
| 4036 | } |
| 4037 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 4038 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4039 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 4040 | * 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] | 4041 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4042 | static struct net_device *get_vlan(struct genl_info *info, |
| 4043 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4044 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4045 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4046 | struct net_device *v; |
| 4047 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4048 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4049 | if (!vlanattr) |
| 4050 | return NULL; |
| 4051 | |
| 4052 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 4053 | if (!v) |
| 4054 | return ERR_PTR(-ENODEV); |
| 4055 | |
| 4056 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 4057 | ret = -EINVAL; |
| 4058 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4059 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4060 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4061 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 4062 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4063 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 4064 | ret = -EINVAL; |
| 4065 | goto error; |
| 4066 | } |
| 4067 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4068 | if (!netif_running(v)) { |
| 4069 | ret = -ENETDOWN; |
| 4070 | goto error; |
| 4071 | } |
| 4072 | |
| 4073 | return v; |
| 4074 | error: |
| 4075 | dev_put(v); |
| 4076 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4077 | } |
| 4078 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 4079 | static const struct nla_policy |
| 4080 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4081 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 4082 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 4083 | }; |
| 4084 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4085 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 4086 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4087 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4088 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 4089 | struct nlattr *nla; |
| 4090 | int err; |
| 4091 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4092 | /* parse WME attributes if present */ |
| 4093 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 4094 | return 0; |
| 4095 | |
| 4096 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 4097 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 4098 | nl80211_sta_wme_policy); |
| 4099 | if (err) |
| 4100 | return err; |
| 4101 | |
| 4102 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 4103 | params->uapsd_queues = nla_get_u8( |
| 4104 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 4105 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 4106 | return -EINVAL; |
| 4107 | |
| 4108 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 4109 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 4110 | |
| 4111 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 4112 | return -EINVAL; |
| 4113 | |
| 4114 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 4115 | |
| 4116 | return 0; |
| 4117 | } |
| 4118 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4119 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 4120 | struct station_parameters *params) |
| 4121 | { |
| 4122 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 4123 | params->supported_channels = |
| 4124 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4125 | params->supported_channels_len = |
| 4126 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4127 | /* |
| 4128 | * Need to include at least one (first channel, number of |
| 4129 | * channels) tuple for each subband, and must have proper |
| 4130 | * tuples for the rest of the data as well. |
| 4131 | */ |
| 4132 | if (params->supported_channels_len < 2) |
| 4133 | return -EINVAL; |
| 4134 | if (params->supported_channels_len % 2) |
| 4135 | return -EINVAL; |
| 4136 | } |
| 4137 | |
| 4138 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 4139 | params->supported_oper_classes = |
| 4140 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4141 | params->supported_oper_classes_len = |
| 4142 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4143 | /* |
| 4144 | * The value of the Length field of the Supported Operating |
| 4145 | * Classes element is between 2 and 253. |
| 4146 | */ |
| 4147 | if (params->supported_oper_classes_len < 2 || |
| 4148 | params->supported_oper_classes_len > 253) |
| 4149 | return -EINVAL; |
| 4150 | } |
| 4151 | return 0; |
| 4152 | } |
| 4153 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4154 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4155 | struct station_parameters *params) |
| 4156 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4157 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4158 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4159 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4160 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4161 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4162 | params->ht_capa = |
| 4163 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4164 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4165 | params->vht_capa = |
| 4166 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4167 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4168 | err = nl80211_parse_sta_channel_info(info, params); |
| 4169 | if (err) |
| 4170 | return err; |
| 4171 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4172 | return nl80211_parse_sta_wme(info, params); |
| 4173 | } |
| 4174 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4175 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4176 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4177 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4178 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4179 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4180 | u8 *mac_addr; |
| 4181 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4182 | |
| 4183 | memset(¶ms, 0, sizeof(params)); |
| 4184 | |
| 4185 | params.listen_interval = -1; |
| 4186 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4187 | if (!rdev->ops->change_station) |
| 4188 | return -EOPNOTSUPP; |
| 4189 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4190 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4191 | return -EINVAL; |
| 4192 | |
| 4193 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4194 | return -EINVAL; |
| 4195 | |
| 4196 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4197 | |
| 4198 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4199 | params.supported_rates = |
| 4200 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4201 | params.supported_rates_len = |
| 4202 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4203 | } |
| 4204 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4205 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4206 | params.capability = |
| 4207 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4208 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4209 | } |
| 4210 | |
| 4211 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4212 | params.ext_capab = |
| 4213 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4214 | params.ext_capab_len = |
| 4215 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4216 | } |
| 4217 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4218 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 4219 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4220 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4221 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4222 | return -EINVAL; |
| 4223 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4224 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4225 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4226 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4227 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4228 | return -EINVAL; |
| 4229 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4230 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4231 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4232 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4233 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4234 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4235 | return -EINVAL; |
| 4236 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4237 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4238 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4239 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4240 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4241 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4242 | |
| 4243 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4244 | pm > NL80211_MESH_POWER_MAX) |
| 4245 | return -EINVAL; |
| 4246 | |
| 4247 | params.local_pm = pm; |
| 4248 | } |
| 4249 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4250 | /* Include parameters for TDLS peer (will check later) */ |
| 4251 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4252 | if (err) |
| 4253 | return err; |
| 4254 | |
| 4255 | params.vlan = get_vlan(info, rdev); |
| 4256 | if (IS_ERR(params.vlan)) |
| 4257 | return PTR_ERR(params.vlan); |
| 4258 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4259 | switch (dev->ieee80211_ptr->iftype) { |
| 4260 | case NL80211_IFTYPE_AP: |
| 4261 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4262 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4263 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4264 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4265 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4266 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4267 | break; |
| 4268 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4269 | err = -EOPNOTSUPP; |
| 4270 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4271 | } |
| 4272 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4273 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4274 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4275 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4276 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4277 | if (params.vlan) |
| 4278 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4279 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4280 | return err; |
| 4281 | } |
| 4282 | |
| 4283 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4284 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4285 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4286 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4287 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4288 | struct station_parameters params; |
| 4289 | u8 *mac_addr = NULL; |
| 4290 | |
| 4291 | memset(¶ms, 0, sizeof(params)); |
| 4292 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4293 | if (!rdev->ops->add_station) |
| 4294 | return -EOPNOTSUPP; |
| 4295 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4296 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4297 | return -EINVAL; |
| 4298 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4299 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4300 | return -EINVAL; |
| 4301 | |
| 4302 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4303 | return -EINVAL; |
| 4304 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4305 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4306 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4307 | return -EINVAL; |
| 4308 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4309 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4310 | params.supported_rates = |
| 4311 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4312 | params.supported_rates_len = |
| 4313 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4314 | params.listen_interval = |
| 4315 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4316 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4317 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4318 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4319 | else |
| 4320 | 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] | 4321 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4322 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4323 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4324 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4325 | params.capability = |
| 4326 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4327 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4328 | } |
| 4329 | |
| 4330 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4331 | params.ext_capab = |
| 4332 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4333 | params.ext_capab_len = |
| 4334 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4335 | } |
| 4336 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4337 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4338 | params.ht_capa = |
| 4339 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4340 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4341 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4342 | params.vht_capa = |
| 4343 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4344 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4345 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4346 | params.opmode_notif_used = true; |
| 4347 | params.opmode_notif = |
| 4348 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4349 | } |
| 4350 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4351 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4352 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4353 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4354 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4355 | return -EINVAL; |
| 4356 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4357 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4358 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4359 | if (err) |
| 4360 | return err; |
| 4361 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4362 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4363 | if (err) |
| 4364 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4365 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4366 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4367 | return -EINVAL; |
| 4368 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4369 | /* When you run into this, adjust the code below for the new flag */ |
| 4370 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4371 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4372 | switch (dev->ieee80211_ptr->iftype) { |
| 4373 | case NL80211_IFTYPE_AP: |
| 4374 | case NL80211_IFTYPE_AP_VLAN: |
| 4375 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4376 | /* ignore WME attributes if iface/sta is not capable */ |
| 4377 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4378 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4379 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4380 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4381 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4382 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4383 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4384 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4385 | /* but don't bother the driver with it */ |
| 4386 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4387 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4388 | /* allow authenticated/associated only if driver handles it */ |
| 4389 | if (!(rdev->wiphy.features & |
| 4390 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4391 | params.sta_flags_mask & |
| 4392 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4393 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4394 | return -EINVAL; |
| 4395 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4396 | /* must be last in here for error handling */ |
| 4397 | params.vlan = get_vlan(info, rdev); |
| 4398 | if (IS_ERR(params.vlan)) |
| 4399 | return PTR_ERR(params.vlan); |
| 4400 | break; |
| 4401 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4402 | /* ignore uAPSD data */ |
| 4403 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4404 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4405 | /* associated is disallowed */ |
| 4406 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4407 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4408 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4409 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4410 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4411 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4412 | break; |
| 4413 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4414 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4415 | /* ignore uAPSD data */ |
| 4416 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4417 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4418 | /* these are disallowed */ |
| 4419 | if (params.sta_flags_mask & |
| 4420 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4421 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4422 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4423 | /* Only TDLS peers can be added */ |
| 4424 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4425 | return -EINVAL; |
| 4426 | /* Can only add if TDLS ... */ |
| 4427 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4428 | return -EOPNOTSUPP; |
| 4429 | /* ... with external setup is supported */ |
| 4430 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4431 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4432 | /* |
| 4433 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4434 | * as authorized, but it shouldn't yet be. |
| 4435 | */ |
| 4436 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4437 | break; |
| 4438 | default: |
| 4439 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4440 | } |
| 4441 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4442 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4443 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4444 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4445 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4446 | if (params.vlan) |
| 4447 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4448 | return err; |
| 4449 | } |
| 4450 | |
| 4451 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4452 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4453 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4454 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4455 | struct station_del_parameters params; |
| 4456 | |
| 4457 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4458 | |
| 4459 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4460 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4461 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4462 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4463 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4464 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4465 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4466 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4467 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4468 | if (!rdev->ops->del_station) |
| 4469 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4470 | |
Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 4471 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 4472 | params.subtype = |
| 4473 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 4474 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 4475 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 4476 | return -EINVAL; |
| 4477 | } else { |
| 4478 | /* Default to Deauthentication frame */ |
| 4479 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 4480 | } |
| 4481 | |
| 4482 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 4483 | params.reason_code = |
| 4484 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4485 | if (params.reason_code == 0) |
| 4486 | return -EINVAL; /* 0 is reserved */ |
| 4487 | } else { |
| 4488 | /* Default to reason code 2 */ |
| 4489 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 4490 | } |
| 4491 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4492 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4493 | } |
| 4494 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4495 | 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] | 4496 | int flags, struct net_device *dev, |
| 4497 | u8 *dst, u8 *next_hop, |
| 4498 | struct mpath_info *pinfo) |
| 4499 | { |
| 4500 | void *hdr; |
| 4501 | struct nlattr *pinfoattr; |
| 4502 | |
Henning Rogge | 1ef4c85 | 2014-11-04 16:14:58 +0100 | [diff] [blame] | 4503 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4504 | if (!hdr) |
| 4505 | return -1; |
| 4506 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4507 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4508 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4509 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4510 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4511 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4512 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4513 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4514 | if (!pinfoattr) |
| 4515 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4516 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4517 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4518 | pinfo->frame_qlen)) |
| 4519 | goto nla_put_failure; |
| 4520 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4521 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4522 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4523 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4524 | pinfo->metric)) || |
| 4525 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4526 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4527 | pinfo->exptime)) || |
| 4528 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4529 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4530 | pinfo->flags)) || |
| 4531 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4532 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4533 | pinfo->discovery_timeout)) || |
| 4534 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4535 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4536 | pinfo->discovery_retries))) |
| 4537 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4538 | |
| 4539 | nla_nest_end(msg, pinfoattr); |
| 4540 | |
| 4541 | return genlmsg_end(msg, hdr); |
| 4542 | |
| 4543 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4544 | genlmsg_cancel(msg, hdr); |
| 4545 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4546 | } |
| 4547 | |
| 4548 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4549 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4550 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4551 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4552 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4553 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4554 | u8 dst[ETH_ALEN]; |
| 4555 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4556 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4557 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4558 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4559 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4560 | if (err) |
| 4561 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4562 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4563 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4564 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4565 | goto out_err; |
| 4566 | } |
| 4567 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4568 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4569 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4570 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4571 | } |
| 4572 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4573 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4574 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4575 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4576 | if (err == -ENOENT) |
| 4577 | break; |
| 4578 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4579 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4580 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4581 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4582 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4583 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4584 | &pinfo) < 0) |
| 4585 | goto out; |
| 4586 | |
| 4587 | path_idx++; |
| 4588 | } |
| 4589 | |
| 4590 | |
| 4591 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4592 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4593 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4594 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4595 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4596 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4597 | } |
| 4598 | |
| 4599 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4600 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4601 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4602 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4603 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4604 | struct mpath_info pinfo; |
| 4605 | struct sk_buff *msg; |
| 4606 | u8 *dst = NULL; |
| 4607 | u8 next_hop[ETH_ALEN]; |
| 4608 | |
| 4609 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4610 | |
| 4611 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4612 | return -EINVAL; |
| 4613 | |
| 4614 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4615 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4616 | if (!rdev->ops->get_mpath) |
| 4617 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4618 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4619 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4620 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4621 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4622 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4623 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4624 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4625 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4626 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4627 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4628 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4629 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4630 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4631 | dev, dst, next_hop, &pinfo) < 0) { |
| 4632 | nlmsg_free(msg); |
| 4633 | return -ENOBUFS; |
| 4634 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4635 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4636 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4637 | } |
| 4638 | |
| 4639 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4640 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4641 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4642 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4643 | u8 *dst = NULL; |
| 4644 | u8 *next_hop = NULL; |
| 4645 | |
| 4646 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4647 | return -EINVAL; |
| 4648 | |
| 4649 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4650 | return -EINVAL; |
| 4651 | |
| 4652 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4653 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4654 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4655 | if (!rdev->ops->change_mpath) |
| 4656 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4657 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4658 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4659 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4660 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4661 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4662 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4663 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4664 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4665 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4666 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4667 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4668 | u8 *dst = NULL; |
| 4669 | u8 *next_hop = NULL; |
| 4670 | |
| 4671 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4672 | return -EINVAL; |
| 4673 | |
| 4674 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4675 | return -EINVAL; |
| 4676 | |
| 4677 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4678 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4679 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4680 | if (!rdev->ops->add_mpath) |
| 4681 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4682 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4683 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4684 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4685 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4686 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4687 | } |
| 4688 | |
| 4689 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4690 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4691 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4692 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4693 | u8 *dst = NULL; |
| 4694 | |
| 4695 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4696 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4697 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4698 | if (!rdev->ops->del_mpath) |
| 4699 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4700 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4701 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4702 | } |
| 4703 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 4704 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 4705 | { |
| 4706 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4707 | int err; |
| 4708 | struct net_device *dev = info->user_ptr[1]; |
| 4709 | struct mpath_info pinfo; |
| 4710 | struct sk_buff *msg; |
| 4711 | u8 *dst = NULL; |
| 4712 | u8 mpp[ETH_ALEN]; |
| 4713 | |
| 4714 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4715 | |
| 4716 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4717 | return -EINVAL; |
| 4718 | |
| 4719 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4720 | |
| 4721 | if (!rdev->ops->get_mpp) |
| 4722 | return -EOPNOTSUPP; |
| 4723 | |
| 4724 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4725 | return -EOPNOTSUPP; |
| 4726 | |
| 4727 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 4728 | if (err) |
| 4729 | return err; |
| 4730 | |
| 4731 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 4732 | if (!msg) |
| 4733 | return -ENOMEM; |
| 4734 | |
| 4735 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 4736 | dev, dst, mpp, &pinfo) < 0) { |
| 4737 | nlmsg_free(msg); |
| 4738 | return -ENOBUFS; |
| 4739 | } |
| 4740 | |
| 4741 | return genlmsg_reply(msg, info); |
| 4742 | } |
| 4743 | |
| 4744 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 4745 | struct netlink_callback *cb) |
| 4746 | { |
| 4747 | struct mpath_info pinfo; |
| 4748 | struct cfg80211_registered_device *rdev; |
| 4749 | struct wireless_dev *wdev; |
| 4750 | u8 dst[ETH_ALEN]; |
| 4751 | u8 mpp[ETH_ALEN]; |
| 4752 | int path_idx = cb->args[2]; |
| 4753 | int err; |
| 4754 | |
| 4755 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
| 4756 | if (err) |
| 4757 | return err; |
| 4758 | |
| 4759 | if (!rdev->ops->dump_mpp) { |
| 4760 | err = -EOPNOTSUPP; |
| 4761 | goto out_err; |
| 4762 | } |
| 4763 | |
| 4764 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 4765 | err = -EOPNOTSUPP; |
| 4766 | goto out_err; |
| 4767 | } |
| 4768 | |
| 4769 | while (1) { |
| 4770 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 4771 | mpp, &pinfo); |
| 4772 | if (err == -ENOENT) |
| 4773 | break; |
| 4774 | if (err) |
| 4775 | goto out_err; |
| 4776 | |
| 4777 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 4778 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4779 | wdev->netdev, dst, mpp, |
| 4780 | &pinfo) < 0) |
| 4781 | goto out; |
| 4782 | |
| 4783 | path_idx++; |
| 4784 | } |
| 4785 | |
| 4786 | out: |
| 4787 | cb->args[2] = path_idx; |
| 4788 | err = skb->len; |
| 4789 | out_err: |
| 4790 | nl80211_finish_wdev_dump(rdev); |
| 4791 | return err; |
| 4792 | } |
| 4793 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4794 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4795 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4796 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4797 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4798 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4799 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4800 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4801 | |
| 4802 | memset(¶ms, 0, sizeof(params)); |
| 4803 | /* default to not changing parameters */ |
| 4804 | params.use_cts_prot = -1; |
| 4805 | params.use_short_preamble = -1; |
| 4806 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4807 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4808 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4809 | params.p2p_ctwindow = -1; |
| 4810 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4811 | |
| 4812 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4813 | params.use_cts_prot = |
| 4814 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4815 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4816 | params.use_short_preamble = |
| 4817 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4818 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4819 | params.use_short_slot_time = |
| 4820 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4821 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4822 | params.basic_rates = |
| 4823 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4824 | params.basic_rates_len = |
| 4825 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4826 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4827 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4828 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4829 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4830 | params.ht_opmode = |
| 4831 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4832 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4833 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4834 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4835 | return -EINVAL; |
| 4836 | params.p2p_ctwindow = |
| 4837 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4838 | if (params.p2p_ctwindow < 0) |
| 4839 | return -EINVAL; |
| 4840 | if (params.p2p_ctwindow != 0 && |
| 4841 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4842 | return -EINVAL; |
| 4843 | } |
| 4844 | |
| 4845 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4846 | u8 tmp; |
| 4847 | |
| 4848 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4849 | return -EINVAL; |
| 4850 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4851 | if (tmp > 1) |
| 4852 | return -EINVAL; |
| 4853 | params.p2p_opp_ps = tmp; |
| 4854 | if (params.p2p_opp_ps && |
| 4855 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4856 | return -EINVAL; |
| 4857 | } |
| 4858 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4859 | if (!rdev->ops->change_bss) |
| 4860 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4861 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4862 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4863 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4864 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4865 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4866 | wdev_lock(wdev); |
| 4867 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 4868 | wdev_unlock(wdev); |
| 4869 | |
| 4870 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4871 | } |
| 4872 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4873 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4874 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4875 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4876 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4877 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4878 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4879 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4880 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4881 | }; |
| 4882 | |
| 4883 | static int parse_reg_rule(struct nlattr *tb[], |
| 4884 | struct ieee80211_reg_rule *reg_rule) |
| 4885 | { |
| 4886 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4887 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4888 | |
| 4889 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4890 | return -EINVAL; |
| 4891 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4892 | return -EINVAL; |
| 4893 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4894 | return -EINVAL; |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4895 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4896 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4897 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4898 | return -EINVAL; |
| 4899 | |
| 4900 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4901 | |
| 4902 | freq_range->start_freq_khz = |
| 4903 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4904 | freq_range->end_freq_khz = |
| 4905 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4906 | freq_range->max_bandwidth_khz = |
| 4907 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4908 | |
| 4909 | power_rule->max_eirp = |
| 4910 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4911 | |
| 4912 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4913 | power_rule->max_antenna_gain = |
| 4914 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4915 | |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4916 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 4917 | reg_rule->dfs_cac_ms = |
| 4918 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 4919 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4920 | return 0; |
| 4921 | } |
| 4922 | |
| 4923 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4924 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4925 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4926 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4927 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4928 | /* |
| 4929 | * You should only get this when cfg80211 hasn't yet initialized |
| 4930 | * completely when built-in to the kernel right between the time |
| 4931 | * window between nl80211_init() and regulatory_init(), if that is |
| 4932 | * even possible. |
| 4933 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4934 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4935 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4936 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4937 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4938 | user_reg_hint_type = |
| 4939 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4940 | else |
| 4941 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4942 | |
| 4943 | switch (user_reg_hint_type) { |
| 4944 | case NL80211_USER_REG_HINT_USER: |
| 4945 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 4946 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4947 | return -EINVAL; |
| 4948 | |
| 4949 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4950 | return regulatory_hint_user(data, user_reg_hint_type); |
| 4951 | case NL80211_USER_REG_HINT_INDOOR: |
| 4952 | return regulatory_hint_indoor_user(); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4953 | default: |
| 4954 | return -EINVAL; |
| 4955 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4956 | } |
| 4957 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4958 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4959 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4960 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4961 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4962 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4963 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4964 | struct mesh_config cur_params; |
| 4965 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4966 | void *hdr; |
| 4967 | struct nlattr *pinfoattr; |
| 4968 | struct sk_buff *msg; |
| 4969 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4970 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4971 | return -EOPNOTSUPP; |
| 4972 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4973 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4974 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4975 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4976 | wdev_lock(wdev); |
| 4977 | /* If not connected, get default parameters */ |
| 4978 | if (!wdev->mesh_id_len) |
| 4979 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4980 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4981 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4982 | wdev_unlock(wdev); |
| 4983 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4984 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4985 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4986 | |
| 4987 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4988 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4989 | if (!msg) |
| 4990 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4991 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4992 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4993 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4994 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4995 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4996 | if (!pinfoattr) |
| 4997 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4998 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4999 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 5000 | cur_params.dot11MeshRetryTimeout) || |
| 5001 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 5002 | cur_params.dot11MeshConfirmTimeout) || |
| 5003 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 5004 | cur_params.dot11MeshHoldingTimeout) || |
| 5005 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 5006 | cur_params.dot11MeshMaxPeerLinks) || |
| 5007 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 5008 | cur_params.dot11MeshMaxRetries) || |
| 5009 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 5010 | cur_params.dot11MeshTTL) || |
| 5011 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 5012 | cur_params.element_ttl) || |
| 5013 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 5014 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 5015 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 5016 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5017 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 5018 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 5019 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 5020 | cur_params.path_refresh_time) || |
| 5021 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 5022 | cur_params.min_discovery_timeout) || |
| 5023 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 5024 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 5025 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 5026 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 5027 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 5028 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 5029 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5030 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 5031 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5032 | cur_params.dot11MeshHWMPRootMode) || |
| 5033 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 5034 | cur_params.dot11MeshHWMPRannInterval) || |
| 5035 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 5036 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 5037 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 5038 | cur_params.dot11MeshForwarding) || |
| 5039 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 5040 | cur_params.rssi_threshold) || |
| 5041 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5042 | cur_params.ht_opmode) || |
| 5043 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5044 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 5045 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5046 | cur_params.dot11MeshHWMProotInterval) || |
| 5047 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5048 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 5049 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 5050 | cur_params.power_mode) || |
| 5051 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5052 | cur_params.dot11MeshAwakeWindowDuration) || |
| 5053 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5054 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5055 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5056 | nla_nest_end(msg, pinfoattr); |
| 5057 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5058 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5059 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5060 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5061 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5062 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5063 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5064 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5065 | } |
| 5066 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5067 | 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] | 5068 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 5069 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 5070 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 5071 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 5072 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 5073 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 5074 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5075 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5076 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5077 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 5078 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 5079 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 5080 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 5081 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5082 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5083 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 5084 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 5085 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 5086 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 5087 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5088 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 5089 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5090 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 5091 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5092 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5093 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 5094 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5095 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5096 | }; |
| 5097 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5098 | static const struct nla_policy |
| 5099 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5100 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5101 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 5102 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 5103 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5104 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5105 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5106 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5107 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5108 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5109 | }; |
| 5110 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5111 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5112 | struct mesh_config *cfg, |
| 5113 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5114 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5115 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5116 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5117 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5118 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 5119 | do { \ |
| 5120 | if (tb[attr]) { \ |
| 5121 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 5122 | return -EINVAL; \ |
| 5123 | cfg->param = fn(tb[attr]); \ |
| 5124 | mask |= (1 << (attr - 1)); \ |
| 5125 | } \ |
| 5126 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5127 | |
| 5128 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5129 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5130 | return -EINVAL; |
| 5131 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5132 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5133 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5134 | return -EINVAL; |
| 5135 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5136 | /* This makes sure that there aren't more than 32 mesh config |
| 5137 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 5138 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 5139 | |
| 5140 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5141 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5142 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 5143 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5144 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5145 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 5146 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5147 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5148 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 5149 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5150 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5151 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 5152 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5153 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5154 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 5155 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5156 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5157 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5158 | 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] | 5159 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 5160 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5161 | 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] | 5162 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 5163 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5164 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 5165 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5166 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 5167 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5168 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5169 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 5170 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5171 | 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] | 5172 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 5173 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5174 | 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] | 5175 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 5176 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5177 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 5178 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5179 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 5180 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5181 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5182 | 1, 65535, mask, |
| 5183 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5184 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5185 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5186 | 1, 65535, mask, |
| 5187 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5188 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5189 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5190 | dot11MeshHWMPnetDiameterTraversalTime, |
| 5191 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5192 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5193 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5194 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 5195 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5196 | nla_get_u8); |
| 5197 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 5198 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5199 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 5200 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5201 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 5202 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5203 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5204 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5205 | mask, NL80211_MESHCONF_FORWARDING, |
| 5206 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5207 | 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] | 5208 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5209 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5210 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5211 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 5212 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5213 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5214 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5215 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5216 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5217 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5218 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 5219 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5220 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5221 | dot11MeshHWMPconfirmationInterval, |
| 5222 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5223 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 5224 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5225 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 5226 | NL80211_MESH_POWER_ACTIVE, |
| 5227 | NL80211_MESH_POWER_MAX, |
| 5228 | mask, NL80211_MESHCONF_POWER_MODE, |
| 5229 | nla_get_u32); |
| 5230 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 5231 | 0, 65535, mask, |
| 5232 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5233 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 5234 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5235 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5236 | if (mask_out) |
| 5237 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5238 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5239 | return 0; |
| 5240 | |
| 5241 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 5242 | } |
| 5243 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5244 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 5245 | struct mesh_setup *setup) |
| 5246 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5247 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5248 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 5249 | |
| 5250 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 5251 | return -EINVAL; |
| 5252 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 5253 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 5254 | nl80211_mesh_setup_params_policy)) |
| 5255 | return -EINVAL; |
| 5256 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5257 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 5258 | setup->sync_method = |
| 5259 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 5260 | IEEE80211_SYNC_METHOD_VENDOR : |
| 5261 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 5262 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5263 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 5264 | setup->path_sel_proto = |
| 5265 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 5266 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 5267 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 5268 | |
| 5269 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 5270 | setup->path_metric = |
| 5271 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 5272 | IEEE80211_PATH_METRIC_VENDOR : |
| 5273 | IEEE80211_PATH_METRIC_AIRTIME; |
| 5274 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5275 | |
| 5276 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5277 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5278 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5279 | if (!is_valid_ie_attr(ieattr)) |
| 5280 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5281 | setup->ie = nla_data(ieattr); |
| 5282 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5283 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5284 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 5285 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 5286 | return -EINVAL; |
| 5287 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5288 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 5289 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5290 | if (setup->is_secure) |
| 5291 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5292 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5293 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 5294 | if (!setup->user_mpm) |
| 5295 | return -EINVAL; |
| 5296 | setup->auth_id = |
| 5297 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 5298 | } |
| 5299 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5300 | return 0; |
| 5301 | } |
| 5302 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5303 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5304 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5305 | { |
| 5306 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5307 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5308 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5309 | struct mesh_config cfg; |
| 5310 | u32 mask; |
| 5311 | int err; |
| 5312 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5313 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5314 | return -EOPNOTSUPP; |
| 5315 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5316 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5317 | return -EOPNOTSUPP; |
| 5318 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5319 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5320 | if (err) |
| 5321 | return err; |
| 5322 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5323 | wdev_lock(wdev); |
| 5324 | if (!wdev->mesh_id_len) |
| 5325 | err = -ENOLINK; |
| 5326 | |
| 5327 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5328 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5329 | |
| 5330 | wdev_unlock(wdev); |
| 5331 | |
| 5332 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5333 | } |
| 5334 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5335 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
| 5336 | struct sk_buff *msg) |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5337 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5338 | struct nlattr *nl_reg_rules; |
| 5339 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5340 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5341 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5342 | (regdom->dfs_region && |
| 5343 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5344 | goto nla_put_failure; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5345 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5346 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5347 | if (!nl_reg_rules) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5348 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5349 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5350 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5351 | struct nlattr *nl_reg_rule; |
| 5352 | const struct ieee80211_reg_rule *reg_rule; |
| 5353 | const struct ieee80211_freq_range *freq_range; |
| 5354 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5355 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5356 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5357 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5358 | freq_range = ®_rule->freq_range; |
| 5359 | power_rule = ®_rule->power_rule; |
| 5360 | |
| 5361 | nl_reg_rule = nla_nest_start(msg, i); |
| 5362 | if (!nl_reg_rule) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5363 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5364 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5365 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 5366 | if (!max_bandwidth_khz) |
| 5367 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 5368 | reg_rule); |
| 5369 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5370 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5371 | reg_rule->flags) || |
| 5372 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5373 | freq_range->start_freq_khz) || |
| 5374 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5375 | freq_range->end_freq_khz) || |
| 5376 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5377 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5378 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5379 | power_rule->max_antenna_gain) || |
| 5380 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 5381 | power_rule->max_eirp) || |
| 5382 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 5383 | reg_rule->dfs_cac_ms)) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5384 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5385 | |
| 5386 | nla_nest_end(msg, nl_reg_rule); |
| 5387 | } |
| 5388 | |
| 5389 | nla_nest_end(msg, nl_reg_rules); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5390 | return 0; |
| 5391 | |
| 5392 | nla_put_failure: |
| 5393 | return -EMSGSIZE; |
| 5394 | } |
| 5395 | |
| 5396 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) |
| 5397 | { |
| 5398 | const struct ieee80211_regdomain *regdom = NULL; |
| 5399 | struct cfg80211_registered_device *rdev; |
| 5400 | struct wiphy *wiphy = NULL; |
| 5401 | struct sk_buff *msg; |
| 5402 | void *hdr; |
| 5403 | |
| 5404 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5405 | if (!msg) |
| 5406 | return -ENOBUFS; |
| 5407 | |
| 5408 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 5409 | NL80211_CMD_GET_REG); |
| 5410 | if (!hdr) |
| 5411 | goto put_failure; |
| 5412 | |
| 5413 | if (info->attrs[NL80211_ATTR_WIPHY]) { |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame^] | 5414 | bool self_managed; |
| 5415 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5416 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
| 5417 | if (IS_ERR(rdev)) { |
| 5418 | nlmsg_free(msg); |
| 5419 | return PTR_ERR(rdev); |
| 5420 | } |
| 5421 | |
| 5422 | wiphy = &rdev->wiphy; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame^] | 5423 | self_managed = wiphy->regulatory_flags & |
| 5424 | REGULATORY_WIPHY_SELF_MANAGED; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5425 | regdom = get_wiphy_regdom(wiphy); |
| 5426 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame^] | 5427 | /* a self-managed-reg device must have a private regdom */ |
| 5428 | if (WARN_ON(!regdom && self_managed)) { |
| 5429 | nlmsg_free(msg); |
| 5430 | return -EINVAL; |
| 5431 | } |
| 5432 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5433 | if (regdom && |
| 5434 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 5435 | goto nla_put_failure; |
| 5436 | } |
| 5437 | |
| 5438 | if (!wiphy && reg_last_request_cell_base() && |
| 5439 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5440 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5441 | goto nla_put_failure; |
| 5442 | |
| 5443 | rcu_read_lock(); |
| 5444 | |
| 5445 | if (!regdom) |
| 5446 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5447 | |
| 5448 | if (nl80211_put_regdom(regdom, msg)) |
| 5449 | goto nla_put_failure_rcu; |
| 5450 | |
| 5451 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5452 | |
| 5453 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5454 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5455 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5456 | nla_put_failure_rcu: |
| 5457 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5458 | nla_put_failure: |
| 5459 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5460 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5461 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5462 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5463 | } |
| 5464 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5465 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
| 5466 | u32 seq, int flags, struct wiphy *wiphy, |
| 5467 | const struct ieee80211_regdomain *regdom) |
| 5468 | { |
| 5469 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
| 5470 | NL80211_CMD_GET_REG); |
| 5471 | |
| 5472 | if (!hdr) |
| 5473 | return -1; |
| 5474 | |
| 5475 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5476 | |
| 5477 | if (nl80211_put_regdom(regdom, msg)) |
| 5478 | goto nla_put_failure; |
| 5479 | |
| 5480 | if (!wiphy && reg_last_request_cell_base() && |
| 5481 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5482 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5483 | goto nla_put_failure; |
| 5484 | |
| 5485 | if (wiphy && |
| 5486 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 5487 | goto nla_put_failure; |
| 5488 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame^] | 5489 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 5490 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 5491 | goto nla_put_failure; |
| 5492 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5493 | return genlmsg_end(msg, hdr); |
| 5494 | |
| 5495 | nla_put_failure: |
| 5496 | genlmsg_cancel(msg, hdr); |
| 5497 | return -EMSGSIZE; |
| 5498 | } |
| 5499 | |
| 5500 | static int nl80211_get_reg_dump(struct sk_buff *skb, |
| 5501 | struct netlink_callback *cb) |
| 5502 | { |
| 5503 | const struct ieee80211_regdomain *regdom = NULL; |
| 5504 | struct cfg80211_registered_device *rdev; |
| 5505 | int err, reg_idx, start = cb->args[2]; |
| 5506 | |
| 5507 | rtnl_lock(); |
| 5508 | |
| 5509 | if (cfg80211_regdomain && start == 0) { |
| 5510 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 5511 | NLM_F_MULTI, NULL, |
| 5512 | rtnl_dereference(cfg80211_regdomain)); |
| 5513 | if (err < 0) |
| 5514 | goto out_err; |
| 5515 | } |
| 5516 | |
| 5517 | /* the global regdom is idx 0 */ |
| 5518 | reg_idx = 1; |
| 5519 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 5520 | regdom = get_wiphy_regdom(&rdev->wiphy); |
| 5521 | if (!regdom) |
| 5522 | continue; |
| 5523 | |
| 5524 | if (++reg_idx <= start) |
| 5525 | continue; |
| 5526 | |
| 5527 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 5528 | NLM_F_MULTI, &rdev->wiphy, regdom); |
| 5529 | if (err < 0) { |
| 5530 | reg_idx--; |
| 5531 | break; |
| 5532 | } |
| 5533 | } |
| 5534 | |
| 5535 | cb->args[2] = reg_idx; |
| 5536 | err = skb->len; |
| 5537 | out_err: |
| 5538 | rtnl_unlock(); |
| 5539 | return err; |
| 5540 | } |
| 5541 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5542 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5543 | { |
| 5544 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5545 | struct nlattr *nl_reg_rule; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 5546 | char *alpha2; |
| 5547 | int rem_reg_rules, r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5548 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5549 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 5550 | struct ieee80211_regdomain *rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5551 | |
| 5552 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5553 | return -EINVAL; |
| 5554 | |
| 5555 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5556 | return -EINVAL; |
| 5557 | |
| 5558 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5559 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5560 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5561 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5562 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5563 | 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] | 5564 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5565 | num_rules++; |
| 5566 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5567 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5568 | } |
| 5569 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5570 | if (!reg_is_valid_request(alpha2)) |
| 5571 | return -EINVAL; |
| 5572 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5573 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5574 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5575 | |
| 5576 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5577 | if (!rd) |
| 5578 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5579 | |
| 5580 | rd->n_reg_rules = num_rules; |
| 5581 | rd->alpha2[0] = alpha2[0]; |
| 5582 | rd->alpha2[1] = alpha2[1]; |
| 5583 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5584 | /* |
| 5585 | * Disable DFS master mode if the DFS region was |
| 5586 | * not supported or known on this kernel. |
| 5587 | */ |
| 5588 | if (reg_supported_dfs_region(dfs_region)) |
| 5589 | rd->dfs_region = dfs_region; |
| 5590 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5591 | 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] | 5592 | rem_reg_rules) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5593 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 5594 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5595 | reg_rule_policy); |
| 5596 | if (r) |
| 5597 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5598 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5599 | if (r) |
| 5600 | goto bad_reg; |
| 5601 | |
| 5602 | rule_idx++; |
| 5603 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5604 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5605 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5606 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5607 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5608 | } |
| 5609 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5610 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5611 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5612 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5613 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5614 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5615 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5616 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5617 | } |
| 5618 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5619 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5620 | { |
| 5621 | struct nlattr *attr1, *attr2; |
| 5622 | int n_channels = 0, tmp1, tmp2; |
| 5623 | |
| 5624 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5625 | n_channels++; |
| 5626 | /* |
| 5627 | * Some hardware has a limited channel list for |
| 5628 | * scanning, and it is pretty much nonsensical |
| 5629 | * to scan for a channel twice, so disallow that |
| 5630 | * and don't require drivers to check that the |
| 5631 | * channel list they get isn't longer than what |
| 5632 | * they can scan, as long as they can scan all |
| 5633 | * the channels they registered at once. |
| 5634 | */ |
| 5635 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5636 | if (attr1 != attr2 && |
| 5637 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5638 | return 0; |
| 5639 | } |
| 5640 | |
| 5641 | return n_channels; |
| 5642 | } |
| 5643 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 5644 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
| 5645 | u8 *mac_addr, u8 *mac_addr_mask) |
| 5646 | { |
| 5647 | int i; |
| 5648 | |
| 5649 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { |
| 5650 | memset(mac_addr, 0, ETH_ALEN); |
| 5651 | memset(mac_addr_mask, 0, ETH_ALEN); |
| 5652 | mac_addr[0] = 0x2; |
| 5653 | mac_addr_mask[0] = 0x3; |
| 5654 | |
| 5655 | return 0; |
| 5656 | } |
| 5657 | |
| 5658 | /* need both or none */ |
| 5659 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) |
| 5660 | return -EINVAL; |
| 5661 | |
| 5662 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); |
| 5663 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); |
| 5664 | |
| 5665 | /* don't allow or configure an mcast address */ |
| 5666 | if (!is_multicast_ether_addr(mac_addr_mask) || |
| 5667 | is_multicast_ether_addr(mac_addr)) |
| 5668 | return -EINVAL; |
| 5669 | |
| 5670 | /* |
| 5671 | * allow users to pass a MAC address that has bits set outside |
| 5672 | * of the mask, but don't bother drivers with having to deal |
| 5673 | * with such bits |
| 5674 | */ |
| 5675 | for (i = 0; i < ETH_ALEN; i++) |
| 5676 | mac_addr[i] &= mac_addr_mask[i]; |
| 5677 | |
| 5678 | return 0; |
| 5679 | } |
| 5680 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5681 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5682 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5683 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5684 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5685 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5686 | struct nlattr *attr; |
| 5687 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5688 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5689 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5690 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5691 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5692 | return -EINVAL; |
| 5693 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5694 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5695 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5696 | if (!rdev->ops->scan) |
| 5697 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5698 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 5699 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5700 | err = -EBUSY; |
| 5701 | goto unlock; |
| 5702 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5703 | |
| 5704 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5705 | n_channels = validate_scan_freqs( |
| 5706 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5707 | if (!n_channels) { |
| 5708 | err = -EINVAL; |
| 5709 | goto unlock; |
| 5710 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5711 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5712 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5713 | } |
| 5714 | |
| 5715 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5716 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5717 | n_ssids++; |
| 5718 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5719 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5720 | err = -EINVAL; |
| 5721 | goto unlock; |
| 5722 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5723 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5724 | if (info->attrs[NL80211_ATTR_IE]) |
| 5725 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5726 | else |
| 5727 | ie_len = 0; |
| 5728 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5729 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5730 | err = -EINVAL; |
| 5731 | goto unlock; |
| 5732 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5733 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5734 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5735 | + sizeof(*request->ssids) * n_ssids |
| 5736 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5737 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5738 | if (!request) { |
| 5739 | err = -ENOMEM; |
| 5740 | goto unlock; |
| 5741 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5742 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5743 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5744 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5745 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5746 | if (ie_len) { |
| 5747 | if (request->ssids) |
| 5748 | request->ie = (void *)(request->ssids + n_ssids); |
| 5749 | else |
| 5750 | request->ie = (void *)(request->channels + n_channels); |
| 5751 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5752 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5753 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5754 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5755 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5756 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5757 | struct ieee80211_channel *chan; |
| 5758 | |
| 5759 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5760 | |
| 5761 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5762 | err = -EINVAL; |
| 5763 | goto out_free; |
| 5764 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5765 | |
| 5766 | /* ignore disabled channels */ |
| 5767 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5768 | continue; |
| 5769 | |
| 5770 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5771 | i++; |
| 5772 | } |
| 5773 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5774 | enum ieee80211_band band; |
| 5775 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5776 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5777 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5778 | int j; |
| 5779 | if (!wiphy->bands[band]) |
| 5780 | continue; |
| 5781 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5782 | struct ieee80211_channel *chan; |
| 5783 | |
| 5784 | chan = &wiphy->bands[band]->channels[j]; |
| 5785 | |
| 5786 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5787 | continue; |
| 5788 | |
| 5789 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5790 | i++; |
| 5791 | } |
| 5792 | } |
| 5793 | } |
| 5794 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5795 | if (!i) { |
| 5796 | err = -EINVAL; |
| 5797 | goto out_free; |
| 5798 | } |
| 5799 | |
| 5800 | request->n_channels = i; |
| 5801 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5802 | i = 0; |
| 5803 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5804 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5805 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5806 | err = -EINVAL; |
| 5807 | goto out_free; |
| 5808 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5809 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5810 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5811 | i++; |
| 5812 | } |
| 5813 | } |
| 5814 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5815 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5816 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5817 | memcpy((void *)request->ie, |
| 5818 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5819 | request->ie_len); |
| 5820 | } |
| 5821 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5822 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5823 | if (wiphy->bands[i]) |
| 5824 | request->rates[i] = |
| 5825 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5826 | |
| 5827 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5828 | nla_for_each_nested(attr, |
| 5829 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5830 | tmp) { |
| 5831 | enum ieee80211_band band = nla_type(attr); |
| 5832 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5833 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5834 | err = -EINVAL; |
| 5835 | goto out_free; |
| 5836 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 5837 | |
| 5838 | if (!wiphy->bands[band]) |
| 5839 | continue; |
| 5840 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5841 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5842 | nla_data(attr), |
| 5843 | nla_len(attr), |
| 5844 | &request->rates[band]); |
| 5845 | if (err) |
| 5846 | goto out_free; |
| 5847 | } |
| 5848 | } |
| 5849 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5850 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5851 | request->flags = nla_get_u32( |
| 5852 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5853 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5854 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5855 | err = -EOPNOTSUPP; |
| 5856 | goto out_free; |
| 5857 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 5858 | |
| 5859 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 5860 | if (!(wiphy->features & |
| 5861 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { |
| 5862 | err = -EOPNOTSUPP; |
| 5863 | goto out_free; |
| 5864 | } |
| 5865 | |
| 5866 | if (wdev->current_bss) { |
| 5867 | err = -EOPNOTSUPP; |
| 5868 | goto out_free; |
| 5869 | } |
| 5870 | |
| 5871 | err = nl80211_parse_random_mac(info->attrs, |
| 5872 | request->mac_addr, |
| 5873 | request->mac_addr_mask); |
| 5874 | if (err) |
| 5875 | goto out_free; |
| 5876 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5877 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5878 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5879 | request->no_cck = |
| 5880 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5881 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5882 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5883 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5884 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5885 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5886 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5887 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5888 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5889 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5890 | nl80211_send_scan_start(rdev, wdev); |
| 5891 | if (wdev->netdev) |
| 5892 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5893 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5894 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5895 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5896 | kfree(request); |
| 5897 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5898 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5899 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5900 | return err; |
| 5901 | } |
| 5902 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5903 | static struct cfg80211_sched_scan_request * |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 5904 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5905 | struct nlattr **attrs) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5906 | { |
| 5907 | struct cfg80211_sched_scan_request *request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5908 | struct nlattr *attr; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5909 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5910 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5911 | enum ieee80211_band band; |
| 5912 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5913 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5914 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5915 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5916 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
| 5917 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5918 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5919 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5920 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5921 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5922 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5923 | if (interval == 0) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5924 | return ERR_PTR(-EINVAL); |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5925 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5926 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5927 | n_channels = validate_scan_freqs( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5928 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5929 | if (!n_channels) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5930 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5931 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5932 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5933 | } |
| 5934 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5935 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5936 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5937 | tmp) |
| 5938 | n_ssids++; |
| 5939 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5940 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5941 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5942 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5943 | /* |
| 5944 | * First, count the number of 'real' matchsets. Due to an issue with |
| 5945 | * the old implementation, matchsets containing only the RSSI attribute |
| 5946 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 5947 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 5948 | * all APs with a strong RSSI. This is needed to be compatible with |
| 5949 | * older userspace that treated a matchset with only the RSSI as the |
| 5950 | * global RSSI for all other matchsets - if there are other matchsets. |
| 5951 | */ |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5952 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5953 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5954 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5955 | tmp) { |
| 5956 | struct nlattr *rssi; |
| 5957 | |
| 5958 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5959 | nla_data(attr), nla_len(attr), |
| 5960 | nl80211_match_policy); |
| 5961 | if (err) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5962 | return ERR_PTR(err); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5963 | /* add other standalone attributes here */ |
| 5964 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { |
| 5965 | n_match_sets++; |
| 5966 | continue; |
| 5967 | } |
| 5968 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5969 | if (rssi) |
| 5970 | default_match_rssi = nla_get_s32(rssi); |
| 5971 | } |
| 5972 | } |
| 5973 | |
| 5974 | /* However, if there's no other matchset, add the RSSI one */ |
| 5975 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 5976 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5977 | |
| 5978 | if (n_match_sets > wiphy->max_match_sets) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5979 | return ERR_PTR(-EINVAL); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5980 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5981 | if (attrs[NL80211_ATTR_IE]) |
| 5982 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5983 | else |
| 5984 | ie_len = 0; |
| 5985 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5986 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5987 | return ERR_PTR(-EINVAL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5988 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5989 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5990 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5991 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5992 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5993 | + ie_len, GFP_KERNEL); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5994 | if (!request) |
| 5995 | return ERR_PTR(-ENOMEM); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5996 | |
| 5997 | if (n_ssids) |
| 5998 | request->ssids = (void *)&request->channels[n_channels]; |
| 5999 | request->n_ssids = n_ssids; |
| 6000 | if (ie_len) { |
| 6001 | if (request->ssids) |
| 6002 | request->ie = (void *)(request->ssids + n_ssids); |
| 6003 | else |
| 6004 | request->ie = (void *)(request->channels + n_channels); |
| 6005 | } |
| 6006 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6007 | if (n_match_sets) { |
| 6008 | if (request->ie) |
| 6009 | request->match_sets = (void *)(request->ie + ie_len); |
| 6010 | else if (request->ssids) |
| 6011 | request->match_sets = |
| 6012 | (void *)(request->ssids + n_ssids); |
| 6013 | else |
| 6014 | request->match_sets = |
| 6015 | (void *)(request->channels + n_channels); |
| 6016 | } |
| 6017 | request->n_match_sets = n_match_sets; |
| 6018 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6019 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6020 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6021 | /* user specified, bail out if channel not found */ |
| 6022 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6023 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6024 | tmp) { |
| 6025 | struct ieee80211_channel *chan; |
| 6026 | |
| 6027 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 6028 | |
| 6029 | if (!chan) { |
| 6030 | err = -EINVAL; |
| 6031 | goto out_free; |
| 6032 | } |
| 6033 | |
| 6034 | /* ignore disabled channels */ |
| 6035 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6036 | continue; |
| 6037 | |
| 6038 | request->channels[i] = chan; |
| 6039 | i++; |
| 6040 | } |
| 6041 | } else { |
| 6042 | /* all channels */ |
| 6043 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6044 | int j; |
| 6045 | if (!wiphy->bands[band]) |
| 6046 | continue; |
| 6047 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 6048 | struct ieee80211_channel *chan; |
| 6049 | |
| 6050 | chan = &wiphy->bands[band]->channels[j]; |
| 6051 | |
| 6052 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6053 | continue; |
| 6054 | |
| 6055 | request->channels[i] = chan; |
| 6056 | i++; |
| 6057 | } |
| 6058 | } |
| 6059 | } |
| 6060 | |
| 6061 | if (!i) { |
| 6062 | err = -EINVAL; |
| 6063 | goto out_free; |
| 6064 | } |
| 6065 | |
| 6066 | request->n_channels = i; |
| 6067 | |
| 6068 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6069 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 6070 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6071 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6072 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6073 | err = -EINVAL; |
| 6074 | goto out_free; |
| 6075 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6076 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6077 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 6078 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6079 | i++; |
| 6080 | } |
| 6081 | } |
| 6082 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6083 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6084 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6085 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6086 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6087 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 6088 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6089 | |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 6090 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 6091 | nla_data(attr), nla_len(attr), |
| 6092 | nl80211_match_policy); |
| 6093 | if (err) |
| 6094 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 6095 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6096 | if (ssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6097 | if (WARN_ON(i >= n_match_sets)) { |
| 6098 | /* this indicates a programming error, |
| 6099 | * the loop above should have verified |
| 6100 | * things properly |
| 6101 | */ |
| 6102 | err = -EINVAL; |
| 6103 | goto out_free; |
| 6104 | } |
| 6105 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6106 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 6107 | err = -EINVAL; |
| 6108 | goto out_free; |
| 6109 | } |
| 6110 | memcpy(request->match_sets[i].ssid.ssid, |
| 6111 | nla_data(ssid), nla_len(ssid)); |
| 6112 | request->match_sets[i].ssid.ssid_len = |
| 6113 | nla_len(ssid); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6114 | /* special attribute - old implemenation w/a */ |
| 6115 | request->match_sets[i].rssi_thold = |
| 6116 | default_match_rssi; |
| 6117 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 6118 | if (rssi) |
| 6119 | request->match_sets[i].rssi_thold = |
| 6120 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6121 | } |
| 6122 | i++; |
| 6123 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6124 | |
| 6125 | /* there was no other matchset, so the RSSI one is alone */ |
| 6126 | if (i == 0) |
| 6127 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 6128 | |
| 6129 | request->min_rssi_thold = INT_MAX; |
| 6130 | for (i = 0; i < n_match_sets; i++) |
| 6131 | request->min_rssi_thold = |
| 6132 | min(request->match_sets[i].rssi_thold, |
| 6133 | request->min_rssi_thold); |
| 6134 | } else { |
| 6135 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6136 | } |
| 6137 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 6138 | if (ie_len) { |
| 6139 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6140 | memcpy((void *)request->ie, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6141 | nla_data(attrs[NL80211_ATTR_IE]), |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6142 | request->ie_len); |
| 6143 | } |
| 6144 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6145 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6146 | request->flags = nla_get_u32( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6147 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 6148 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 6149 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6150 | err = -EOPNOTSUPP; |
| 6151 | goto out_free; |
| 6152 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6153 | |
| 6154 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 6155 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; |
| 6156 | |
| 6157 | if (!wdev) /* must be net-detect */ |
| 6158 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 6159 | |
| 6160 | if (!(wiphy->features & flg)) { |
| 6161 | err = -EOPNOTSUPP; |
| 6162 | goto out_free; |
| 6163 | } |
| 6164 | |
| 6165 | if (wdev && wdev->current_bss) { |
| 6166 | err = -EOPNOTSUPP; |
| 6167 | goto out_free; |
| 6168 | } |
| 6169 | |
| 6170 | err = nl80211_parse_random_mac(attrs, request->mac_addr, |
| 6171 | request->mac_addr_mask); |
| 6172 | if (err) |
| 6173 | goto out_free; |
| 6174 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6175 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6176 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 6177 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 6178 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6179 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6180 | return request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6181 | |
| 6182 | out_free: |
| 6183 | kfree(request); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6184 | return ERR_PTR(err); |
| 6185 | } |
| 6186 | |
| 6187 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 6188 | struct genl_info *info) |
| 6189 | { |
| 6190 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6191 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6192 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6193 | int err; |
| 6194 | |
| 6195 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 6196 | !rdev->ops->sched_scan_start) |
| 6197 | return -EOPNOTSUPP; |
| 6198 | |
| 6199 | if (rdev->sched_scan_req) |
| 6200 | return -EINPROGRESS; |
| 6201 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6202 | rdev->sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6203 | info->attrs); |
| 6204 | err = PTR_ERR_OR_ZERO(rdev->sched_scan_req); |
| 6205 | if (err) |
| 6206 | goto out_err; |
| 6207 | |
| 6208 | err = rdev_sched_scan_start(rdev, dev, rdev->sched_scan_req); |
| 6209 | if (err) |
| 6210 | goto out_free; |
| 6211 | |
| 6212 | rdev->sched_scan_req->dev = dev; |
| 6213 | rdev->sched_scan_req->wiphy = &rdev->wiphy; |
| 6214 | |
| 6215 | nl80211_send_sched_scan(rdev, dev, |
| 6216 | NL80211_CMD_START_SCHED_SCAN); |
| 6217 | return 0; |
| 6218 | |
| 6219 | out_free: |
| 6220 | kfree(rdev->sched_scan_req); |
| 6221 | out_err: |
| 6222 | rdev->sched_scan_req = NULL; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6223 | return err; |
| 6224 | } |
| 6225 | |
| 6226 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 6227 | struct genl_info *info) |
| 6228 | { |
| 6229 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6230 | |
| 6231 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 6232 | !rdev->ops->sched_scan_stop) |
| 6233 | return -EOPNOTSUPP; |
| 6234 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6235 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6236 | } |
| 6237 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6238 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 6239 | struct genl_info *info) |
| 6240 | { |
| 6241 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6242 | struct net_device *dev = info->user_ptr[1]; |
| 6243 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6244 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 6245 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6246 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6247 | int err; |
| 6248 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 6249 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 6250 | if (dfs_region == NL80211_DFS_UNSET) |
| 6251 | return -EINVAL; |
| 6252 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6253 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6254 | if (err) |
| 6255 | return err; |
| 6256 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 6257 | if (netif_carrier_ok(dev)) |
| 6258 | return -EBUSY; |
| 6259 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6260 | if (wdev->cac_started) |
| 6261 | return -EBUSY; |
| 6262 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6263 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 6264 | wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6265 | if (err < 0) |
| 6266 | return err; |
| 6267 | |
| 6268 | if (err == 0) |
| 6269 | return -EINVAL; |
| 6270 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 6271 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6272 | return -EINVAL; |
| 6273 | |
| 6274 | if (!rdev->ops->start_radar_detection) |
| 6275 | return -EOPNOTSUPP; |
| 6276 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6277 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 6278 | if (WARN_ON(!cac_time_ms)) |
| 6279 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 6280 | |
| 6281 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, |
| 6282 | cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6283 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 6284 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6285 | wdev->cac_started = true; |
| 6286 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6287 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6288 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6289 | return err; |
| 6290 | } |
| 6291 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6292 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 6293 | { |
| 6294 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6295 | struct net_device *dev = info->user_ptr[1]; |
| 6296 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6297 | struct cfg80211_csa_settings params; |
| 6298 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 6299 | * function is called under RTNL lock, so this should not be a problem. |
| 6300 | */ |
| 6301 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6302 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6303 | bool need_new_beacon = false; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6304 | int len, i; |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 6305 | u32 cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6306 | |
| 6307 | if (!rdev->ops->channel_switch || |
| 6308 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 6309 | return -EOPNOTSUPP; |
| 6310 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6311 | switch (dev->ieee80211_ptr->iftype) { |
| 6312 | case NL80211_IFTYPE_AP: |
| 6313 | case NL80211_IFTYPE_P2P_GO: |
| 6314 | need_new_beacon = true; |
| 6315 | |
| 6316 | /* useless if AP is not running */ |
| 6317 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6318 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6319 | break; |
| 6320 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6321 | if (!wdev->ssid_len) |
| 6322 | return -ENOTCONN; |
| 6323 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 6324 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6325 | if (!wdev->mesh_id_len) |
| 6326 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6327 | break; |
| 6328 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6329 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6330 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6331 | |
| 6332 | memset(¶ms, 0, sizeof(params)); |
| 6333 | |
| 6334 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6335 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 6336 | return -EINVAL; |
| 6337 | |
| 6338 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 6339 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6340 | return -EINVAL; |
| 6341 | |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 6342 | /* Even though the attribute is u32, the specification says |
| 6343 | * u8, so let's make sure we don't overflow. |
| 6344 | */ |
| 6345 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 6346 | if (cs_count > 255) |
| 6347 | return -EINVAL; |
| 6348 | |
| 6349 | params.count = cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6350 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6351 | if (!need_new_beacon) |
| 6352 | goto skip_beacons; |
| 6353 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6354 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 6355 | if (err) |
| 6356 | return err; |
| 6357 | |
| 6358 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 6359 | info->attrs[NL80211_ATTR_CSA_IES], |
| 6360 | nl80211_policy); |
| 6361 | if (err) |
| 6362 | return err; |
| 6363 | |
| 6364 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 6365 | if (err) |
| 6366 | return err; |
| 6367 | |
| 6368 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 6369 | return -EINVAL; |
| 6370 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6371 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 6372 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6373 | return -EINVAL; |
| 6374 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6375 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 6376 | if (rdev->wiphy.max_num_csa_counters && |
| 6377 | (params.n_counter_offsets_beacon > |
| 6378 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6379 | return -EINVAL; |
| 6380 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6381 | params.counter_offsets_beacon = |
| 6382 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 6383 | |
| 6384 | /* sanity checks - counters should fit and be the same */ |
| 6385 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 6386 | u16 offset = params.counter_offsets_beacon[i]; |
| 6387 | |
| 6388 | if (offset >= params.beacon_csa.tail_len) |
| 6389 | return -EINVAL; |
| 6390 | |
| 6391 | if (params.beacon_csa.tail[offset] != params.count) |
| 6392 | return -EINVAL; |
| 6393 | } |
| 6394 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6395 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6396 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 6397 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6398 | return -EINVAL; |
| 6399 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6400 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 6401 | if (rdev->wiphy.max_num_csa_counters && |
| 6402 | (params.n_counter_offsets_beacon > |
| 6403 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6404 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6405 | |
| 6406 | params.counter_offsets_presp = |
| 6407 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 6408 | |
| 6409 | /* sanity checks - counters should fit and be the same */ |
| 6410 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 6411 | u16 offset = params.counter_offsets_presp[i]; |
| 6412 | |
| 6413 | if (offset >= params.beacon_csa.probe_resp_len) |
| 6414 | return -EINVAL; |
| 6415 | |
| 6416 | if (params.beacon_csa.probe_resp[offset] != |
| 6417 | params.count) |
| 6418 | return -EINVAL; |
| 6419 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6420 | } |
| 6421 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6422 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6423 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 6424 | if (err) |
| 6425 | return err; |
| 6426 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 6427 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
| 6428 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6429 | return -EINVAL; |
| 6430 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6431 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 6432 | ¶ms.chandef, |
| 6433 | wdev->iftype); |
| 6434 | if (err < 0) |
| 6435 | return err; |
| 6436 | |
Fabian Frederick | dcc6c2f | 2014-10-25 17:57:35 +0200 | [diff] [blame] | 6437 | if (err > 0) |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6438 | params.radar_required = true; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6439 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6440 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 6441 | params.block_tx = true; |
| 6442 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6443 | wdev_lock(wdev); |
| 6444 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 6445 | wdev_unlock(wdev); |
| 6446 | |
| 6447 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6448 | } |
| 6449 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6450 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 6451 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6452 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6453 | struct wireless_dev *wdev, |
| 6454 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6455 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6456 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6457 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6458 | void *hdr; |
| 6459 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6460 | |
| 6461 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6462 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6463 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6464 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 6465 | if (!hdr) |
| 6466 | return -1; |
| 6467 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6468 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 6469 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6470 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 6471 | goto nla_put_failure; |
| 6472 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6473 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 6474 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6475 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 6476 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6477 | |
| 6478 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 6479 | if (!bss) |
| 6480 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6481 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6482 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6483 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6484 | |
| 6485 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6486 | /* indicate whether we have probe response data or not */ |
| 6487 | if (rcu_access_pointer(res->proberesp_ies) && |
| 6488 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 6489 | goto fail_unlock_rcu; |
| 6490 | |
| 6491 | /* this pointer prefers to be pointed to probe response data |
| 6492 | * but is always valid |
| 6493 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6494 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6495 | if (ies) { |
| 6496 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 6497 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6498 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 6499 | ies->len, ies->data)) |
| 6500 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6501 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6502 | |
| 6503 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6504 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6505 | if (ies && ies->from_beacon) { |
| 6506 | if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6507 | goto fail_unlock_rcu; |
| 6508 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 6509 | ies->len, ies->data)) |
| 6510 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6511 | } |
| 6512 | rcu_read_unlock(); |
| 6513 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6514 | if (res->beacon_interval && |
| 6515 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 6516 | goto nla_put_failure; |
| 6517 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 6518 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 6519 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6520 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 6521 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 6522 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6523 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 6524 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6525 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6526 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 6527 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6528 | break; |
| 6529 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6530 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 6531 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6532 | break; |
| 6533 | default: |
| 6534 | break; |
| 6535 | } |
| 6536 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6537 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6538 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6539 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6540 | if (intbss == wdev->current_bss && |
| 6541 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6542 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 6543 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6544 | break; |
| 6545 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6546 | if (intbss == wdev->current_bss && |
| 6547 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6548 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 6549 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6550 | break; |
| 6551 | default: |
| 6552 | break; |
| 6553 | } |
| 6554 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6555 | nla_nest_end(msg, bss); |
| 6556 | |
| 6557 | return genlmsg_end(msg, hdr); |
| 6558 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6559 | fail_unlock_rcu: |
| 6560 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6561 | nla_put_failure: |
| 6562 | genlmsg_cancel(msg, hdr); |
| 6563 | return -EMSGSIZE; |
| 6564 | } |
| 6565 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6566 | 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] | 6567 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6568 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6569 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6570 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6571 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6572 | int err; |
| 6573 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6574 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6575 | if (err) |
| 6576 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6577 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6578 | wdev_lock(wdev); |
| 6579 | spin_lock_bh(&rdev->bss_lock); |
| 6580 | cfg80211_bss_expire(rdev); |
| 6581 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6582 | cb->seq = rdev->bss_generation; |
| 6583 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6584 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6585 | if (++idx <= start) |
| 6586 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6587 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6588 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6589 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6590 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6591 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6592 | } |
| 6593 | } |
| 6594 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6595 | spin_unlock_bh(&rdev->bss_lock); |
| 6596 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6597 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6598 | cb->args[2] = idx; |
| 6599 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6600 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6601 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6602 | } |
| 6603 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6604 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6605 | int flags, struct net_device *dev, |
| 6606 | struct survey_info *survey) |
| 6607 | { |
| 6608 | void *hdr; |
| 6609 | struct nlattr *infoattr; |
| 6610 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6611 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6612 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 6613 | if (!hdr) |
| 6614 | return -ENOMEM; |
| 6615 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6616 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 6617 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6618 | |
| 6619 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 6620 | if (!infoattr) |
| 6621 | goto nla_put_failure; |
| 6622 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6623 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 6624 | survey->channel->center_freq)) |
| 6625 | goto nla_put_failure; |
| 6626 | |
| 6627 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 6628 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 6629 | goto nla_put_failure; |
| 6630 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 6631 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 6632 | goto nla_put_failure; |
| 6633 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 6634 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 6635 | survey->channel_time)) |
| 6636 | goto nla_put_failure; |
| 6637 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 6638 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 6639 | survey->channel_time_busy)) |
| 6640 | goto nla_put_failure; |
| 6641 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 6642 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 6643 | survey->channel_time_ext_busy)) |
| 6644 | goto nla_put_failure; |
| 6645 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 6646 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 6647 | survey->channel_time_rx)) |
| 6648 | goto nla_put_failure; |
| 6649 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 6650 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 6651 | survey->channel_time_tx)) |
| 6652 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6653 | |
| 6654 | nla_nest_end(msg, infoattr); |
| 6655 | |
| 6656 | return genlmsg_end(msg, hdr); |
| 6657 | |
| 6658 | nla_put_failure: |
| 6659 | genlmsg_cancel(msg, hdr); |
| 6660 | return -EMSGSIZE; |
| 6661 | } |
| 6662 | |
| 6663 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 6664 | struct netlink_callback *cb) |
| 6665 | { |
| 6666 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6667 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6668 | struct wireless_dev *wdev; |
| 6669 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6670 | int res; |
| 6671 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6672 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6673 | if (res) |
| 6674 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6675 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6676 | if (!wdev->netdev) { |
| 6677 | res = -EINVAL; |
| 6678 | goto out_err; |
| 6679 | } |
| 6680 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6681 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6682 | res = -EOPNOTSUPP; |
| 6683 | goto out_err; |
| 6684 | } |
| 6685 | |
| 6686 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6687 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6688 | if (res == -ENOENT) |
| 6689 | break; |
| 6690 | if (res) |
| 6691 | goto out_err; |
| 6692 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6693 | /* Survey without a channel doesn't make sense */ |
| 6694 | if (!survey.channel) { |
| 6695 | res = -EINVAL; |
| 6696 | goto out; |
| 6697 | } |
| 6698 | |
Johannes Berg | ea9eba6 | 2014-11-21 15:24:31 +0100 | [diff] [blame] | 6699 | if (survey.channel->flags & IEEE80211_CHAN_DISABLED) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6700 | survey_idx++; |
| 6701 | continue; |
| 6702 | } |
| 6703 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6704 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6705 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6706 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6707 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6708 | goto out; |
| 6709 | survey_idx++; |
| 6710 | } |
| 6711 | |
| 6712 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6713 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6714 | res = skb->len; |
| 6715 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6716 | nl80211_finish_wdev_dump(rdev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6717 | return res; |
| 6718 | } |
| 6719 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6720 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 6721 | { |
| 6722 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 6723 | NL80211_WPA_VERSION_2)); |
| 6724 | } |
| 6725 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6726 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6727 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6728 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6729 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6730 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6731 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6732 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6733 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6734 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6735 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6736 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6737 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6738 | return -EINVAL; |
| 6739 | |
| 6740 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6741 | return -EINVAL; |
| 6742 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6743 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 6744 | return -EINVAL; |
| 6745 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6746 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 6747 | return -EINVAL; |
| 6748 | |
| 6749 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6750 | return -EINVAL; |
| 6751 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6752 | err = nl80211_parse_key(info, &key); |
| 6753 | if (err) |
| 6754 | return err; |
| 6755 | |
| 6756 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6757 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 6758 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6759 | if (!key.p.key || !key.p.key_len) |
| 6760 | return -EINVAL; |
| 6761 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 6762 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 6763 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 6764 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 6765 | return -EINVAL; |
| 6766 | if (key.idx > 4) |
| 6767 | return -EINVAL; |
| 6768 | } else { |
| 6769 | key.p.key_len = 0; |
| 6770 | key.p.key = NULL; |
| 6771 | } |
| 6772 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6773 | if (key.idx >= 0) { |
| 6774 | int i; |
| 6775 | bool ok = false; |
| 6776 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 6777 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 6778 | ok = true; |
| 6779 | break; |
| 6780 | } |
| 6781 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6782 | if (!ok) |
| 6783 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6784 | } |
| 6785 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6786 | if (!rdev->ops->auth) |
| 6787 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6788 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6789 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6790 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6791 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6792 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6793 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6794 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 6795 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6796 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6797 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6798 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6799 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6800 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6801 | |
| 6802 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6803 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6804 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6805 | } |
| 6806 | |
| 6807 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6808 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6809 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6810 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6811 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 6812 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 6813 | return -EINVAL; |
| 6814 | |
| 6815 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 6816 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 6817 | return -EINVAL; |
| 6818 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6819 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6820 | /* need to include at least Auth Transaction and Status Code */ |
| 6821 | if (sae_data_len < 4) |
| 6822 | return -EINVAL; |
| 6823 | } |
| 6824 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6825 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6826 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6827 | /* |
| 6828 | * Since we no longer track auth state, ignore |
| 6829 | * requests to only change local state. |
| 6830 | */ |
| 6831 | if (local_state_change) |
| 6832 | return 0; |
| 6833 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6834 | wdev_lock(dev->ieee80211_ptr); |
| 6835 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 6836 | ssid, ssid_len, ie, ie_len, |
| 6837 | key.p.key, key.p.key_len, key.idx, |
| 6838 | sae_data, sae_data_len); |
| 6839 | wdev_unlock(dev->ieee80211_ptr); |
| 6840 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6841 | } |
| 6842 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6843 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 6844 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6845 | struct cfg80211_crypto_settings *settings, |
| 6846 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6847 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6848 | memset(settings, 0, sizeof(*settings)); |
| 6849 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6850 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 6851 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6852 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 6853 | u16 proto; |
| 6854 | proto = nla_get_u16( |
| 6855 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 6856 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6857 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6858 | proto != ETH_P_PAE) |
| 6859 | return -EINVAL; |
| 6860 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6861 | settings->control_port_no_encrypt = true; |
| 6862 | } else |
| 6863 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6864 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6865 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6866 | void *data; |
| 6867 | int len, i; |
| 6868 | |
| 6869 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6870 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6871 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6872 | |
| 6873 | if (len % sizeof(u32)) |
| 6874 | return -EINVAL; |
| 6875 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6876 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6877 | return -EINVAL; |
| 6878 | |
| 6879 | memcpy(settings->ciphers_pairwise, data, len); |
| 6880 | |
| 6881 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6882 | if (!cfg80211_supported_cipher_suite( |
| 6883 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6884 | settings->ciphers_pairwise[i])) |
| 6885 | return -EINVAL; |
| 6886 | } |
| 6887 | |
| 6888 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6889 | settings->cipher_group = |
| 6890 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6891 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6892 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6893 | return -EINVAL; |
| 6894 | } |
| 6895 | |
| 6896 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6897 | settings->wpa_versions = |
| 6898 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6899 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6900 | return -EINVAL; |
| 6901 | } |
| 6902 | |
| 6903 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6904 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6905 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6906 | |
| 6907 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6908 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6909 | settings->n_akm_suites = len / sizeof(u32); |
| 6910 | |
| 6911 | if (len % sizeof(u32)) |
| 6912 | return -EINVAL; |
| 6913 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6914 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6915 | return -EINVAL; |
| 6916 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6917 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6918 | } |
| 6919 | |
| 6920 | return 0; |
| 6921 | } |
| 6922 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6923 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6924 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6925 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6926 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6927 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6928 | struct cfg80211_assoc_request req = {}; |
| 6929 | const u8 *bssid, *ssid; |
| 6930 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6931 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6932 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6933 | return -EINVAL; |
| 6934 | |
| 6935 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6936 | !info->attrs[NL80211_ATTR_SSID] || |
| 6937 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6938 | return -EINVAL; |
| 6939 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6940 | if (!rdev->ops->assoc) |
| 6941 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6942 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6943 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6944 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6945 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6946 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6947 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6948 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6949 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 6950 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6951 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6952 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6953 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6954 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6955 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6956 | |
| 6957 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6958 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6959 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6960 | } |
| 6961 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6962 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6963 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6964 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6965 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6966 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6967 | else if (mfp != NL80211_MFP_NO) |
| 6968 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6969 | } |
| 6970 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6971 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6972 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6973 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6974 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6975 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6976 | |
| 6977 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6978 | memcpy(&req.ht_capa_mask, |
| 6979 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6980 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6981 | |
| 6982 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6983 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6984 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6985 | memcpy(&req.ht_capa, |
| 6986 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6987 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6988 | } |
| 6989 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6990 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6991 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6992 | |
| 6993 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6994 | memcpy(&req.vht_capa_mask, |
| 6995 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6996 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6997 | |
| 6998 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6999 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7000 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7001 | memcpy(&req.vht_capa, |
| 7002 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7003 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7004 | } |
| 7005 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 7006 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
| 7007 | if (!(rdev->wiphy.features & |
| 7008 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || |
| 7009 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) |
| 7010 | return -EINVAL; |
| 7011 | req.flags |= ASSOC_REQ_USE_RRM; |
| 7012 | } |
| 7013 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7014 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7015 | if (!err) { |
| 7016 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 7017 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 7018 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7019 | wdev_unlock(dev->ieee80211_ptr); |
| 7020 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7021 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7022 | return err; |
| 7023 | } |
| 7024 | |
| 7025 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 7026 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7027 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7028 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7029 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7030 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7031 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7032 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7033 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7034 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7035 | return -EINVAL; |
| 7036 | |
| 7037 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7038 | return -EINVAL; |
| 7039 | |
| 7040 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7041 | return -EINVAL; |
| 7042 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7043 | if (!rdev->ops->deauth) |
| 7044 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7045 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7046 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7047 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7048 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7049 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7050 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7051 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7052 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7053 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7054 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7055 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 7056 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7057 | |
| 7058 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7059 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7060 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7061 | } |
| 7062 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7063 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7064 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7065 | wdev_lock(dev->ieee80211_ptr); |
| 7066 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 7067 | local_state_change); |
| 7068 | wdev_unlock(dev->ieee80211_ptr); |
| 7069 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7070 | } |
| 7071 | |
| 7072 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 7073 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7074 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7075 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7076 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7077 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7078 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7079 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7080 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7081 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7082 | return -EINVAL; |
| 7083 | |
| 7084 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7085 | return -EINVAL; |
| 7086 | |
| 7087 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7088 | return -EINVAL; |
| 7089 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7090 | if (!rdev->ops->disassoc) |
| 7091 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7092 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7093 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7094 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7095 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7096 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7097 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7098 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7099 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7100 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7101 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7102 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 7103 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7104 | |
| 7105 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7106 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7107 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7108 | } |
| 7109 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7110 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7111 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7112 | wdev_lock(dev->ieee80211_ptr); |
| 7113 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 7114 | local_state_change); |
| 7115 | wdev_unlock(dev->ieee80211_ptr); |
| 7116 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7117 | } |
| 7118 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7119 | static bool |
| 7120 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 7121 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 7122 | int rateval) |
| 7123 | { |
| 7124 | struct wiphy *wiphy = &rdev->wiphy; |
| 7125 | bool found = false; |
| 7126 | int band, i; |
| 7127 | |
| 7128 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 7129 | struct ieee80211_supported_band *sband; |
| 7130 | |
| 7131 | sband = wiphy->bands[band]; |
| 7132 | if (!sband) |
| 7133 | continue; |
| 7134 | |
| 7135 | for (i = 0; i < sband->n_bitrates; i++) { |
| 7136 | if (sband->bitrates[i].bitrate == rateval) { |
| 7137 | mcast_rate[band] = i + 1; |
| 7138 | found = true; |
| 7139 | break; |
| 7140 | } |
| 7141 | } |
| 7142 | } |
| 7143 | |
| 7144 | return found; |
| 7145 | } |
| 7146 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7147 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 7148 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7149 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7150 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7151 | struct cfg80211_ibss_params ibss; |
| 7152 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7153 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7154 | int err; |
| 7155 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 7156 | memset(&ibss, 0, sizeof(ibss)); |
| 7157 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7158 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7159 | return -EINVAL; |
| 7160 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7161 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7162 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 7163 | return -EINVAL; |
| 7164 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 7165 | ibss.beacon_interval = 100; |
| 7166 | |
| 7167 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7168 | ibss.beacon_interval = |
| 7169 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7170 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 7171 | return -EINVAL; |
| 7172 | } |
| 7173 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7174 | if (!rdev->ops->join_ibss) |
| 7175 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7176 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7177 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 7178 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7179 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7180 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7181 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 7182 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7183 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 7184 | |
| 7185 | if (!is_valid_ether_addr(ibss.bssid)) |
| 7186 | return -EINVAL; |
| 7187 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7188 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7189 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7190 | |
| 7191 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7192 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7193 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7194 | } |
| 7195 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7196 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 7197 | if (err) |
| 7198 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 7199 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 7200 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 7201 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 7202 | return -EINVAL; |
| 7203 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7204 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 7205 | case NL80211_CHAN_WIDTH_5: |
| 7206 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7207 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 7208 | break; |
| 7209 | case NL80211_CHAN_WIDTH_20: |
| 7210 | case NL80211_CHAN_WIDTH_40: |
| 7211 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) |
| 7212 | break; |
| 7213 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 7214 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7215 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 7216 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7217 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7218 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7219 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7220 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 7221 | u8 *rates = |
| 7222 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7223 | int n_rates = |
| 7224 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7225 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7226 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7227 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7228 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 7229 | &ibss.basic_rates); |
| 7230 | if (err) |
| 7231 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7232 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7233 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 7234 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7235 | memcpy(&ibss.ht_capa_mask, |
| 7236 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7237 | sizeof(ibss.ht_capa_mask)); |
| 7238 | |
| 7239 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 7240 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7241 | return -EINVAL; |
| 7242 | memcpy(&ibss.ht_capa, |
| 7243 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7244 | sizeof(ibss.ht_capa)); |
| 7245 | } |
| 7246 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7247 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7248 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 7249 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7250 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7251 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7252 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7253 | bool no_ht = false; |
| 7254 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7255 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7256 | info->attrs[NL80211_ATTR_KEYS], |
| 7257 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7258 | if (IS_ERR(connkeys)) |
| 7259 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7260 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 7261 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 7262 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7263 | kfree(connkeys); |
| 7264 | return -EINVAL; |
| 7265 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7266 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7267 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 7268 | ibss.control_port = |
| 7269 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 7270 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 7271 | ibss.userspace_handles_dfs = |
| 7272 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 7273 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7274 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7275 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7276 | kzfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7277 | return err; |
| 7278 | } |
| 7279 | |
| 7280 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 7281 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7282 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7283 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7284 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7285 | if (!rdev->ops->leave_ibss) |
| 7286 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7287 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7288 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 7289 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7290 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7291 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7292 | } |
| 7293 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7294 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 7295 | { |
| 7296 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7297 | struct net_device *dev = info->user_ptr[1]; |
| 7298 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 7299 | u32 nla_rate; |
| 7300 | int err; |
| 7301 | |
| 7302 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 7303 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 7304 | return -EOPNOTSUPP; |
| 7305 | |
| 7306 | if (!rdev->ops->set_mcast_rate) |
| 7307 | return -EOPNOTSUPP; |
| 7308 | |
| 7309 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 7310 | |
| 7311 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 7312 | return -EINVAL; |
| 7313 | |
| 7314 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 7315 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 7316 | return -EINVAL; |
| 7317 | |
| 7318 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 7319 | |
| 7320 | return err; |
| 7321 | } |
| 7322 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7323 | static struct sk_buff * |
| 7324 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
| 7325 | int approxlen, u32 portid, u32 seq, |
| 7326 | enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 7327 | enum nl80211_attrs attr, |
| 7328 | const struct nl80211_vendor_cmd_info *info, |
| 7329 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7330 | { |
| 7331 | struct sk_buff *skb; |
| 7332 | void *hdr; |
| 7333 | struct nlattr *data; |
| 7334 | |
| 7335 | skb = nlmsg_new(approxlen + 100, gfp); |
| 7336 | if (!skb) |
| 7337 | return NULL; |
| 7338 | |
| 7339 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 7340 | if (!hdr) { |
| 7341 | kfree_skb(skb); |
| 7342 | return NULL; |
| 7343 | } |
| 7344 | |
| 7345 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 7346 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 7347 | |
| 7348 | if (info) { |
| 7349 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 7350 | info->vendor_id)) |
| 7351 | goto nla_put_failure; |
| 7352 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 7353 | info->subcmd)) |
| 7354 | goto nla_put_failure; |
| 7355 | } |
| 7356 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7357 | data = nla_nest_start(skb, attr); |
| 7358 | |
| 7359 | ((void **)skb->cb)[0] = rdev; |
| 7360 | ((void **)skb->cb)[1] = hdr; |
| 7361 | ((void **)skb->cb)[2] = data; |
| 7362 | |
| 7363 | return skb; |
| 7364 | |
| 7365 | nla_put_failure: |
| 7366 | kfree_skb(skb); |
| 7367 | return NULL; |
| 7368 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7369 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7370 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
| 7371 | enum nl80211_commands cmd, |
| 7372 | enum nl80211_attrs attr, |
| 7373 | int vendor_event_idx, |
| 7374 | int approxlen, gfp_t gfp) |
| 7375 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 7376 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7377 | const struct nl80211_vendor_cmd_info *info; |
| 7378 | |
| 7379 | switch (cmd) { |
| 7380 | case NL80211_CMD_TESTMODE: |
| 7381 | if (WARN_ON(vendor_event_idx != -1)) |
| 7382 | return NULL; |
| 7383 | info = NULL; |
| 7384 | break; |
| 7385 | case NL80211_CMD_VENDOR: |
| 7386 | if (WARN_ON(vendor_event_idx < 0 || |
| 7387 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 7388 | return NULL; |
| 7389 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 7390 | break; |
| 7391 | default: |
| 7392 | WARN_ON(1); |
| 7393 | return NULL; |
| 7394 | } |
| 7395 | |
| 7396 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, |
| 7397 | cmd, attr, info, gfp); |
| 7398 | } |
| 7399 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 7400 | |
| 7401 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 7402 | { |
| 7403 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 7404 | void *hdr = ((void **)skb->cb)[1]; |
| 7405 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 7406 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 7407 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 7408 | /* clear CB data for netlink core to own from now on */ |
| 7409 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 7410 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7411 | nla_nest_end(skb, data); |
| 7412 | genlmsg_end(skb, hdr); |
| 7413 | |
| 7414 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 7415 | mcgrp = NL80211_MCGRP_VENDOR; |
| 7416 | |
| 7417 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 7418 | mcgrp, gfp); |
| 7419 | } |
| 7420 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 7421 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7422 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7423 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 7424 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7425 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7426 | struct wireless_dev *wdev = |
| 7427 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7428 | int err; |
| 7429 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7430 | if (!rdev->ops->testmode_cmd) |
| 7431 | return -EOPNOTSUPP; |
| 7432 | |
| 7433 | if (IS_ERR(wdev)) { |
| 7434 | err = PTR_ERR(wdev); |
| 7435 | if (err != -EINVAL) |
| 7436 | return err; |
| 7437 | wdev = NULL; |
| 7438 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 7439 | return -EINVAL; |
| 7440 | } |
| 7441 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7442 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 7443 | return -EINVAL; |
| 7444 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7445 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7446 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7447 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 7448 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7449 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7450 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7451 | return err; |
| 7452 | } |
| 7453 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7454 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 7455 | struct netlink_callback *cb) |
| 7456 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7457 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7458 | int err; |
| 7459 | long phy_idx; |
| 7460 | void *data = NULL; |
| 7461 | int data_len = 0; |
| 7462 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7463 | rtnl_lock(); |
| 7464 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7465 | if (cb->args[0]) { |
| 7466 | /* |
| 7467 | * 0 is a valid index, but not valid for args[0], |
| 7468 | * so we need to offset by 1. |
| 7469 | */ |
| 7470 | phy_idx = cb->args[0] - 1; |
| 7471 | } else { |
| 7472 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 7473 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 7474 | nl80211_policy); |
| 7475 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7476 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7477 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7478 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 7479 | nl80211_fam.attrbuf); |
| 7480 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7481 | err = PTR_ERR(rdev); |
| 7482 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7483 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7484 | phy_idx = rdev->wiphy_idx; |
| 7485 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7486 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7487 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 7488 | cb->args[1] = |
| 7489 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 7490 | } |
| 7491 | |
| 7492 | if (cb->args[1]) { |
| 7493 | data = nla_data((void *)cb->args[1]); |
| 7494 | data_len = nla_len((void *)cb->args[1]); |
| 7495 | } |
| 7496 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7497 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 7498 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7499 | err = -ENOENT; |
| 7500 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7501 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7502 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7503 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7504 | err = -EOPNOTSUPP; |
| 7505 | goto out_err; |
| 7506 | } |
| 7507 | |
| 7508 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7509 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7510 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 7511 | NL80211_CMD_TESTMODE); |
| 7512 | struct nlattr *tmdata; |
| 7513 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7514 | if (!hdr) |
| 7515 | break; |
| 7516 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7517 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7518 | genlmsg_cancel(skb, hdr); |
| 7519 | break; |
| 7520 | } |
| 7521 | |
| 7522 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 7523 | if (!tmdata) { |
| 7524 | genlmsg_cancel(skb, hdr); |
| 7525 | break; |
| 7526 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7527 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7528 | nla_nest_end(skb, tmdata); |
| 7529 | |
| 7530 | if (err == -ENOBUFS || err == -ENOENT) { |
| 7531 | genlmsg_cancel(skb, hdr); |
| 7532 | break; |
| 7533 | } else if (err) { |
| 7534 | genlmsg_cancel(skb, hdr); |
| 7535 | goto out_err; |
| 7536 | } |
| 7537 | |
| 7538 | genlmsg_end(skb, hdr); |
| 7539 | } |
| 7540 | |
| 7541 | err = skb->len; |
| 7542 | /* see above */ |
| 7543 | cb->args[0] = phy_idx + 1; |
| 7544 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7545 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7546 | return err; |
| 7547 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7548 | #endif |
| 7549 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7550 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 7551 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7552 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7553 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7554 | struct cfg80211_connect_params connect; |
| 7555 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7556 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7557 | int err; |
| 7558 | |
| 7559 | memset(&connect, 0, sizeof(connect)); |
| 7560 | |
| 7561 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7562 | return -EINVAL; |
| 7563 | |
| 7564 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 7565 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 7566 | return -EINVAL; |
| 7567 | |
| 7568 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 7569 | connect.auth_type = |
| 7570 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7571 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 7572 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7573 | return -EINVAL; |
| 7574 | } else |
| 7575 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 7576 | |
| 7577 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 7578 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7579 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7580 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7581 | if (err) |
| 7582 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7583 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7584 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7585 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7586 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7587 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7588 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7589 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 7590 | connect.bg_scan_period = -1; |
| 7591 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 7592 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 7593 | connect.bg_scan_period = |
| 7594 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 7595 | } |
| 7596 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7597 | if (info->attrs[NL80211_ATTR_MAC]) |
| 7598 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7599 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 7600 | connect.bssid_hint = |
| 7601 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7602 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7603 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7604 | |
| 7605 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7606 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7607 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7608 | } |
| 7609 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 7610 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 7611 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 7612 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 7613 | connect.mfp != NL80211_MFP_NO) |
| 7614 | return -EINVAL; |
| 7615 | } else { |
| 7616 | connect.mfp = NL80211_MFP_NO; |
| 7617 | } |
| 7618 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7619 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7620 | connect.channel = nl80211_get_valid_chan( |
| 7621 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7622 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7623 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7624 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7625 | connect.channel_hint = nl80211_get_valid_chan( |
| 7626 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 7627 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7628 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7629 | } |
| 7630 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7631 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 7632 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7633 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7634 | if (IS_ERR(connkeys)) |
| 7635 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7636 | } |
| 7637 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7638 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 7639 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 7640 | |
| 7641 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7642 | memcpy(&connect.ht_capa_mask, |
| 7643 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7644 | sizeof(connect.ht_capa_mask)); |
| 7645 | |
| 7646 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7647 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7648 | kzfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7649 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7650 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7651 | memcpy(&connect.ht_capa, |
| 7652 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7653 | sizeof(connect.ht_capa)); |
| 7654 | } |
| 7655 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7656 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 7657 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 7658 | |
| 7659 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 7660 | memcpy(&connect.vht_capa_mask, |
| 7661 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7662 | sizeof(connect.vht_capa_mask)); |
| 7663 | |
| 7664 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 7665 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7666 | kzfree(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7667 | return -EINVAL; |
| 7668 | } |
| 7669 | memcpy(&connect.vht_capa, |
| 7670 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7671 | sizeof(connect.vht_capa)); |
| 7672 | } |
| 7673 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 7674 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
| 7675 | if (!(rdev->wiphy.features & |
| 7676 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || |
| 7677 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) |
| 7678 | return -EINVAL; |
| 7679 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 7680 | } |
| 7681 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7682 | wdev_lock(dev->ieee80211_ptr); |
| 7683 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 7684 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7685 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7686 | kzfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7687 | return err; |
| 7688 | } |
| 7689 | |
| 7690 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 7691 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7692 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7693 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7694 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7695 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7696 | |
| 7697 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7698 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 7699 | else |
| 7700 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7701 | |
| 7702 | if (reason == 0) |
| 7703 | return -EINVAL; |
| 7704 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7705 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7706 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7707 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7708 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7709 | wdev_lock(dev->ieee80211_ptr); |
| 7710 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 7711 | wdev_unlock(dev->ieee80211_ptr); |
| 7712 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7713 | } |
| 7714 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7715 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 7716 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7717 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7718 | struct net *net; |
| 7719 | int err; |
| 7720 | u32 pid; |
| 7721 | |
| 7722 | if (!info->attrs[NL80211_ATTR_PID]) |
| 7723 | return -EINVAL; |
| 7724 | |
| 7725 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 7726 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7727 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7728 | if (IS_ERR(net)) |
| 7729 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7730 | |
| 7731 | err = 0; |
| 7732 | |
| 7733 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7734 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 7735 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7736 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7737 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7738 | return err; |
| 7739 | } |
| 7740 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7741 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7742 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7743 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7744 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 7745 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7746 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7747 | struct cfg80211_pmksa pmksa; |
| 7748 | |
| 7749 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 7750 | |
| 7751 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7752 | return -EINVAL; |
| 7753 | |
| 7754 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 7755 | return -EINVAL; |
| 7756 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7757 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 7758 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7759 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7760 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7761 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7762 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7763 | |
| 7764 | switch (info->genlhdr->cmd) { |
| 7765 | case NL80211_CMD_SET_PMKSA: |
| 7766 | rdev_ops = rdev->ops->set_pmksa; |
| 7767 | break; |
| 7768 | case NL80211_CMD_DEL_PMKSA: |
| 7769 | rdev_ops = rdev->ops->del_pmksa; |
| 7770 | break; |
| 7771 | default: |
| 7772 | WARN_ON(1); |
| 7773 | break; |
| 7774 | } |
| 7775 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7776 | if (!rdev_ops) |
| 7777 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7778 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7779 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7780 | } |
| 7781 | |
| 7782 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7783 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7784 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7785 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7786 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7787 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7788 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7789 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7790 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7791 | if (!rdev->ops->flush_pmksa) |
| 7792 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7793 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7794 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7795 | } |
| 7796 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7797 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 7798 | { |
| 7799 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7800 | struct net_device *dev = info->user_ptr[1]; |
| 7801 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7802 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7803 | u16 status_code; |
| 7804 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7805 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7806 | |
| 7807 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7808 | !rdev->ops->tdls_mgmt) |
| 7809 | return -EOPNOTSUPP; |
| 7810 | |
| 7811 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 7812 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 7813 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 7814 | !info->attrs[NL80211_ATTR_IE] || |
| 7815 | !info->attrs[NL80211_ATTR_MAC]) |
| 7816 | return -EINVAL; |
| 7817 | |
| 7818 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7819 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 7820 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 7821 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7822 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7823 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 7824 | peer_capability = |
| 7825 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7826 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7827 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7828 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7829 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7830 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 7831 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7832 | } |
| 7833 | |
| 7834 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 7835 | { |
| 7836 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7837 | struct net_device *dev = info->user_ptr[1]; |
| 7838 | enum nl80211_tdls_operation operation; |
| 7839 | u8 *peer; |
| 7840 | |
| 7841 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7842 | !rdev->ops->tdls_oper) |
| 7843 | return -EOPNOTSUPP; |
| 7844 | |
| 7845 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 7846 | !info->attrs[NL80211_ATTR_MAC]) |
| 7847 | return -EINVAL; |
| 7848 | |
| 7849 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 7850 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7851 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7852 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7853 | } |
| 7854 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7855 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 7856 | struct genl_info *info) |
| 7857 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7858 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7859 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7860 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7861 | struct sk_buff *msg; |
| 7862 | void *hdr; |
| 7863 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7864 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7865 | int err; |
| 7866 | |
| 7867 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7868 | !info->attrs[NL80211_ATTR_DURATION]) |
| 7869 | return -EINVAL; |
| 7870 | |
| 7871 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 7872 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7873 | if (!rdev->ops->remain_on_channel || |
| 7874 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7875 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7876 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7877 | /* |
| 7878 | * We should be on that channel for at least a minimum amount of |
| 7879 | * time (10ms) but no longer than the driver supports. |
| 7880 | */ |
| 7881 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7882 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 7883 | return -EINVAL; |
| 7884 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7885 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7886 | if (err) |
| 7887 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7888 | |
| 7889 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7890 | if (!msg) |
| 7891 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7892 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7893 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7894 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7895 | if (!hdr) { |
| 7896 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7897 | goto free_msg; |
| 7898 | } |
| 7899 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7900 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 7901 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7902 | |
| 7903 | if (err) |
| 7904 | goto free_msg; |
| 7905 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7906 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7907 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7908 | |
| 7909 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7910 | |
| 7911 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7912 | |
| 7913 | nla_put_failure: |
| 7914 | err = -ENOBUFS; |
| 7915 | free_msg: |
| 7916 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7917 | return err; |
| 7918 | } |
| 7919 | |
| 7920 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 7921 | struct genl_info *info) |
| 7922 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7923 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7924 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7925 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7926 | |
| 7927 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7928 | return -EINVAL; |
| 7929 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7930 | if (!rdev->ops->cancel_remain_on_channel) |
| 7931 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7932 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7933 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7934 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7935 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7936 | } |
| 7937 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7938 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7939 | u8 *rates, u8 rates_len) |
| 7940 | { |
| 7941 | u8 i; |
| 7942 | u32 mask = 0; |
| 7943 | |
| 7944 | for (i = 0; i < rates_len; i++) { |
| 7945 | int rate = (rates[i] & 0x7f) * 5; |
| 7946 | int ridx; |
| 7947 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 7948 | struct ieee80211_rate *srate = |
| 7949 | &sband->bitrates[ridx]; |
| 7950 | if (rate == srate->bitrate) { |
| 7951 | mask |= 1 << ridx; |
| 7952 | break; |
| 7953 | } |
| 7954 | } |
| 7955 | if (ridx == sband->n_bitrates) |
| 7956 | return 0; /* rate not found */ |
| 7957 | } |
| 7958 | |
| 7959 | return mask; |
| 7960 | } |
| 7961 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7962 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7963 | u8 *rates, u8 rates_len, |
| 7964 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 7965 | { |
| 7966 | u8 i; |
| 7967 | |
| 7968 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 7969 | |
| 7970 | for (i = 0; i < rates_len; i++) { |
| 7971 | int ridx, rbit; |
| 7972 | |
| 7973 | ridx = rates[i] / 8; |
| 7974 | rbit = BIT(rates[i] % 8); |
| 7975 | |
| 7976 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7977 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7978 | return false; |
| 7979 | |
| 7980 | /* check availability */ |
| 7981 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7982 | mcs[ridx] |= rbit; |
| 7983 | else |
| 7984 | return false; |
| 7985 | } |
| 7986 | |
| 7987 | return true; |
| 7988 | } |
| 7989 | |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7990 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 7991 | { |
| 7992 | u16 mcs_mask = 0; |
| 7993 | |
| 7994 | switch (vht_mcs_map) { |
| 7995 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 7996 | break; |
| 7997 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 7998 | mcs_mask = 0x00FF; |
| 7999 | break; |
| 8000 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 8001 | mcs_mask = 0x01FF; |
| 8002 | break; |
| 8003 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 8004 | mcs_mask = 0x03FF; |
| 8005 | break; |
| 8006 | default: |
| 8007 | break; |
| 8008 | } |
| 8009 | |
| 8010 | return mcs_mask; |
| 8011 | } |
| 8012 | |
| 8013 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 8014 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 8015 | { |
| 8016 | u8 nss; |
| 8017 | |
| 8018 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 8019 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 8020 | vht_mcs_map >>= 2; |
| 8021 | } |
| 8022 | } |
| 8023 | |
| 8024 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 8025 | struct nl80211_txrate_vht *txrate, |
| 8026 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 8027 | { |
| 8028 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 8029 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 8030 | u8 i; |
| 8031 | |
| 8032 | if (!sband->vht_cap.vht_supported) |
| 8033 | return false; |
| 8034 | |
| 8035 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 8036 | |
| 8037 | /* Build vht_mcs_mask from VHT capabilities */ |
| 8038 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 8039 | |
| 8040 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 8041 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 8042 | mcs[i] = txrate->mcs[i]; |
| 8043 | else |
| 8044 | return false; |
| 8045 | } |
| 8046 | |
| 8047 | return true; |
| 8048 | } |
| 8049 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 8050 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8051 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 8052 | .len = NL80211_MAX_SUPP_RATES }, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8053 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 8054 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8055 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 8056 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8057 | }; |
| 8058 | |
| 8059 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 8060 | struct genl_info *info) |
| 8061 | { |
| 8062 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8063 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8064 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8065 | int rem, i; |
| 8066 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8067 | struct nlattr *tx_rates; |
| 8068 | struct ieee80211_supported_band *sband; |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8069 | u16 vht_tx_mcs_map; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8070 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8071 | if (!rdev->ops->set_bitrate_mask) |
| 8072 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8073 | |
| 8074 | memset(&mask, 0, sizeof(mask)); |
| 8075 | /* Default to all rates enabled */ |
| 8076 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 8077 | sband = rdev->wiphy.bands[i]; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 8078 | |
| 8079 | if (!sband) |
| 8080 | continue; |
| 8081 | |
| 8082 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8083 | memcpy(mask.control[i].ht_mcs, |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 8084 | sband->ht_cap.mcs.rx_mask, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8085 | sizeof(mask.control[i].ht_mcs)); |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8086 | |
| 8087 | if (!sband->vht_cap.vht_supported) |
| 8088 | continue; |
| 8089 | |
| 8090 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 8091 | vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8092 | } |
| 8093 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 8094 | /* if no rates are given set it back to the defaults */ |
| 8095 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 8096 | goto out; |
| 8097 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8098 | /* |
| 8099 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 8100 | * directly to the enum ieee80211_band values used in cfg80211. |
| 8101 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8102 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8103 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8104 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8105 | int err; |
| 8106 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8107 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 8108 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8109 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8110 | if (sband == NULL) |
| 8111 | return -EINVAL; |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8112 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 8113 | nla_len(tx_rates), nl80211_txattr_policy); |
| 8114 | if (err) |
| 8115 | return err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8116 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 8117 | mask.control[band].legacy = rateset_to_mask( |
| 8118 | sband, |
| 8119 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 8120 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 8121 | if ((mask.control[band].legacy == 0) && |
| 8122 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 8123 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8124 | } |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8125 | if (tb[NL80211_TXRATE_HT]) { |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8126 | if (!ht_rateset_to_mask( |
| 8127 | sband, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8128 | nla_data(tb[NL80211_TXRATE_HT]), |
| 8129 | nla_len(tb[NL80211_TXRATE_HT]), |
| 8130 | mask.control[band].ht_mcs)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8131 | return -EINVAL; |
| 8132 | } |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8133 | if (tb[NL80211_TXRATE_VHT]) { |
| 8134 | if (!vht_set_mcs_mask( |
| 8135 | sband, |
| 8136 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 8137 | mask.control[band].vht_mcs)) |
| 8138 | return -EINVAL; |
| 8139 | } |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 8140 | if (tb[NL80211_TXRATE_GI]) { |
| 8141 | mask.control[band].gi = |
| 8142 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 8143 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 8144 | return -EINVAL; |
| 8145 | } |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8146 | |
| 8147 | if (mask.control[band].legacy == 0) { |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8148 | /* don't allow empty legacy rates if HT or VHT |
| 8149 | * are not even supported. |
| 8150 | */ |
| 8151 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 8152 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8153 | return -EINVAL; |
| 8154 | |
| 8155 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8156 | if (mask.control[band].ht_mcs[i]) |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8157 | goto out; |
| 8158 | |
| 8159 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 8160 | if (mask.control[band].vht_mcs[i]) |
| 8161 | goto out; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8162 | |
| 8163 | /* legacy and mcs rates may not be both empty */ |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8164 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8165 | } |
| 8166 | } |
| 8167 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 8168 | out: |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8169 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8170 | } |
| 8171 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8172 | 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] | 8173 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8174 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8175 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8176 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8177 | |
| 8178 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 8179 | return -EINVAL; |
| 8180 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8181 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 8182 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8183 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8184 | switch (wdev->iftype) { |
| 8185 | case NL80211_IFTYPE_STATION: |
| 8186 | case NL80211_IFTYPE_ADHOC: |
| 8187 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8188 | case NL80211_IFTYPE_AP: |
| 8189 | case NL80211_IFTYPE_AP_VLAN: |
| 8190 | case NL80211_IFTYPE_MESH_POINT: |
| 8191 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8192 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8193 | break; |
| 8194 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8195 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8196 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8197 | |
| 8198 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8199 | if (!rdev->ops->mgmt_tx) |
| 8200 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8201 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8202 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8203 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 8204 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8205 | } |
| 8206 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8207 | 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] | 8208 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8209 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8210 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8211 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8212 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 8213 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8214 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8215 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8216 | struct cfg80211_mgmt_tx_params params = { |
| 8217 | .dont_wait_for_ack = |
| 8218 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 8219 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8220 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8221 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8222 | return -EINVAL; |
| 8223 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8224 | if (!rdev->ops->mgmt_tx) |
| 8225 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8226 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8227 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8228 | case NL80211_IFTYPE_P2P_DEVICE: |
| 8229 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 8230 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8231 | case NL80211_IFTYPE_STATION: |
| 8232 | case NL80211_IFTYPE_ADHOC: |
| 8233 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8234 | case NL80211_IFTYPE_AP: |
| 8235 | case NL80211_IFTYPE_AP_VLAN: |
| 8236 | case NL80211_IFTYPE_MESH_POINT: |
| 8237 | case NL80211_IFTYPE_P2P_GO: |
| 8238 | break; |
| 8239 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8240 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8241 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8242 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8243 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8244 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8245 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8246 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8247 | |
| 8248 | /* |
| 8249 | * We should wait on the channel for at least a minimum amount |
| 8250 | * of time (10ms) but no longer than the driver supports. |
| 8251 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8252 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 8253 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8254 | return -EINVAL; |
| 8255 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8256 | } |
| 8257 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8258 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8259 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8260 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8261 | return -EINVAL; |
| 8262 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8263 | 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] | 8264 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8265 | /* get the channel if any has been specified, otherwise pass NULL to |
| 8266 | * the driver. The latter will use the current one |
| 8267 | */ |
| 8268 | chandef.chan = NULL; |
| 8269 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 8270 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8271 | if (err) |
| 8272 | return err; |
| 8273 | } |
| 8274 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8275 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8276 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8277 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 8278 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 8279 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 8280 | |
| 8281 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 8282 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 8283 | int i; |
| 8284 | |
| 8285 | if (len % sizeof(u16)) |
| 8286 | return -EINVAL; |
| 8287 | |
| 8288 | params.n_csa_offsets = len / sizeof(u16); |
| 8289 | params.csa_offsets = |
| 8290 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 8291 | |
| 8292 | /* check that all the offsets fit the frame */ |
| 8293 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 8294 | if (params.csa_offsets[i] >= params.len) |
| 8295 | return -EINVAL; |
| 8296 | } |
| 8297 | } |
| 8298 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8299 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8300 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8301 | if (!msg) |
| 8302 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8303 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8304 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8305 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8306 | if (!hdr) { |
| 8307 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8308 | goto free_msg; |
| 8309 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8310 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8311 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8312 | params.chan = chandef.chan; |
| 8313 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8314 | if (err) |
| 8315 | goto free_msg; |
| 8316 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8317 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8318 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8319 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8320 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8321 | genlmsg_end(msg, hdr); |
| 8322 | return genlmsg_reply(msg, info); |
| 8323 | } |
| 8324 | |
| 8325 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8326 | |
| 8327 | nla_put_failure: |
| 8328 | err = -ENOBUFS; |
| 8329 | free_msg: |
| 8330 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8331 | return err; |
| 8332 | } |
| 8333 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8334 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 8335 | { |
| 8336 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8337 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8338 | u64 cookie; |
| 8339 | |
| 8340 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 8341 | return -EINVAL; |
| 8342 | |
| 8343 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 8344 | return -EOPNOTSUPP; |
| 8345 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8346 | switch (wdev->iftype) { |
| 8347 | case NL80211_IFTYPE_STATION: |
| 8348 | case NL80211_IFTYPE_ADHOC: |
| 8349 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8350 | case NL80211_IFTYPE_AP: |
| 8351 | case NL80211_IFTYPE_AP_VLAN: |
| 8352 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8353 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8354 | break; |
| 8355 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8356 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8357 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8358 | |
| 8359 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 8360 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8361 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8362 | } |
| 8363 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8364 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 8365 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8366 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8367 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8368 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8369 | u8 ps_state; |
| 8370 | bool state; |
| 8371 | int err; |
| 8372 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8373 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 8374 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8375 | |
| 8376 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 8377 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8378 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 8379 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8380 | |
| 8381 | wdev = dev->ieee80211_ptr; |
| 8382 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8383 | if (!rdev->ops->set_power_mgmt) |
| 8384 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8385 | |
| 8386 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 8387 | |
| 8388 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8389 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8390 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8391 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8392 | if (!err) |
| 8393 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8394 | return err; |
| 8395 | } |
| 8396 | |
| 8397 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 8398 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8399 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8400 | enum nl80211_ps_state ps_state; |
| 8401 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8402 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8403 | struct sk_buff *msg; |
| 8404 | void *hdr; |
| 8405 | int err; |
| 8406 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8407 | wdev = dev->ieee80211_ptr; |
| 8408 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8409 | if (!rdev->ops->set_power_mgmt) |
| 8410 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8411 | |
| 8412 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8413 | if (!msg) |
| 8414 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8415 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8416 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8417 | NL80211_CMD_GET_POWER_SAVE); |
| 8418 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8419 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8420 | goto free_msg; |
| 8421 | } |
| 8422 | |
| 8423 | if (wdev->ps) |
| 8424 | ps_state = NL80211_PS_ENABLED; |
| 8425 | else |
| 8426 | ps_state = NL80211_PS_DISABLED; |
| 8427 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8428 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 8429 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8430 | |
| 8431 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8432 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8433 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8434 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8435 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8436 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8437 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8438 | return err; |
| 8439 | } |
| 8440 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 8441 | static const struct nla_policy |
| 8442 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8443 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 8444 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 8445 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8446 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 8447 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 8448 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8449 | }; |
| 8450 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8451 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8452 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8453 | { |
| 8454 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8455 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8456 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8457 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8458 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8459 | return -EINVAL; |
| 8460 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8461 | if (!rdev->ops->set_cqm_txe_config) |
| 8462 | return -EOPNOTSUPP; |
| 8463 | |
| 8464 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 8465 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8466 | return -EOPNOTSUPP; |
| 8467 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8468 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8469 | } |
| 8470 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8471 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 8472 | s32 threshold, u32 hysteresis) |
| 8473 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8474 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8475 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8476 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8477 | |
| 8478 | if (threshold > 0) |
| 8479 | return -EINVAL; |
| 8480 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8481 | /* disabling - hysteresis should also be zero then */ |
| 8482 | if (threshold == 0) |
| 8483 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8484 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8485 | if (!rdev->ops->set_cqm_rssi_config) |
| 8486 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8487 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8488 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8489 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8490 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8491 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8492 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8493 | } |
| 8494 | |
| 8495 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 8496 | { |
| 8497 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 8498 | struct nlattr *cqm; |
| 8499 | int err; |
| 8500 | |
| 8501 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8502 | if (!cqm) |
| 8503 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8504 | |
| 8505 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 8506 | nl80211_attr_cqm_policy); |
| 8507 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8508 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8509 | |
| 8510 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 8511 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8512 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 8513 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8514 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8515 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 8516 | } |
| 8517 | |
| 8518 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 8519 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 8520 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 8521 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 8522 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 8523 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 8524 | |
| 8525 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 8526 | } |
| 8527 | |
| 8528 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8529 | } |
| 8530 | |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 8531 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 8532 | { |
| 8533 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8534 | struct net_device *dev = info->user_ptr[1]; |
| 8535 | struct ocb_setup setup = {}; |
| 8536 | int err; |
| 8537 | |
| 8538 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 8539 | if (err) |
| 8540 | return err; |
| 8541 | |
| 8542 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 8543 | } |
| 8544 | |
| 8545 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 8546 | { |
| 8547 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8548 | struct net_device *dev = info->user_ptr[1]; |
| 8549 | |
| 8550 | return cfg80211_leave_ocb(rdev, dev); |
| 8551 | } |
| 8552 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8553 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8554 | { |
| 8555 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8556 | struct net_device *dev = info->user_ptr[1]; |
| 8557 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8558 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8559 | int err; |
| 8560 | |
| 8561 | /* start with default */ |
| 8562 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8563 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8564 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8565 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8566 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8567 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8568 | if (err) |
| 8569 | return err; |
| 8570 | } |
| 8571 | |
| 8572 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 8573 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 8574 | return -EINVAL; |
| 8575 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8576 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8577 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8578 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 8579 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 8580 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 8581 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 8582 | return -EINVAL; |
| 8583 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 8584 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 8585 | setup.beacon_interval = |
| 8586 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 8587 | if (setup.beacon_interval < 10 || |
| 8588 | setup.beacon_interval > 10000) |
| 8589 | return -EINVAL; |
| 8590 | } |
| 8591 | |
| 8592 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 8593 | setup.dtim_period = |
| 8594 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 8595 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 8596 | return -EINVAL; |
| 8597 | } |
| 8598 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8599 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 8600 | /* parse additional setup parameters if given */ |
| 8601 | err = nl80211_parse_mesh_setup(info, &setup); |
| 8602 | if (err) |
| 8603 | return err; |
| 8604 | } |
| 8605 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 8606 | if (setup.user_mpm) |
| 8607 | cfg.auto_open_plinks = false; |
| 8608 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8609 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8610 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 8611 | if (err) |
| 8612 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8613 | } else { |
| 8614 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8615 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8616 | } |
| 8617 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 8618 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 8619 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8620 | int n_rates = |
| 8621 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8622 | struct ieee80211_supported_band *sband; |
| 8623 | |
| 8624 | if (!setup.chandef.chan) |
| 8625 | return -EINVAL; |
| 8626 | |
| 8627 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 8628 | |
| 8629 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 8630 | &setup.basic_rates); |
| 8631 | if (err) |
| 8632 | return err; |
| 8633 | } |
| 8634 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8635 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8636 | } |
| 8637 | |
| 8638 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8639 | { |
| 8640 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8641 | struct net_device *dev = info->user_ptr[1]; |
| 8642 | |
| 8643 | return cfg80211_leave_mesh(rdev, dev); |
| 8644 | } |
| 8645 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8646 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8647 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 8648 | struct cfg80211_registered_device *rdev) |
| 8649 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8650 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8651 | struct nlattr *nl_pats, *nl_pat; |
| 8652 | int i, pat_len; |
| 8653 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8654 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8655 | return 0; |
| 8656 | |
| 8657 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 8658 | if (!nl_pats) |
| 8659 | return -ENOBUFS; |
| 8660 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8661 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8662 | nl_pat = nla_nest_start(msg, i + 1); |
| 8663 | if (!nl_pat) |
| 8664 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8665 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8666 | 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] | 8667 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8668 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8669 | wowlan->patterns[i].pattern) || |
| 8670 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8671 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8672 | return -ENOBUFS; |
| 8673 | nla_nest_end(msg, nl_pat); |
| 8674 | } |
| 8675 | nla_nest_end(msg, nl_pats); |
| 8676 | |
| 8677 | return 0; |
| 8678 | } |
| 8679 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8680 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 8681 | struct cfg80211_wowlan_tcp *tcp) |
| 8682 | { |
| 8683 | struct nlattr *nl_tcp; |
| 8684 | |
| 8685 | if (!tcp) |
| 8686 | return 0; |
| 8687 | |
| 8688 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 8689 | if (!nl_tcp) |
| 8690 | return -ENOBUFS; |
| 8691 | |
| 8692 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 8693 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 8694 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 8695 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 8696 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 8697 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 8698 | tcp->payload_len, tcp->payload) || |
| 8699 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 8700 | tcp->data_interval) || |
| 8701 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 8702 | tcp->wake_len, tcp->wake_data) || |
| 8703 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 8704 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 8705 | return -ENOBUFS; |
| 8706 | |
| 8707 | if (tcp->payload_seq.len && |
| 8708 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 8709 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 8710 | return -ENOBUFS; |
| 8711 | |
| 8712 | if (tcp->payload_tok.len && |
| 8713 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 8714 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 8715 | &tcp->payload_tok)) |
| 8716 | return -ENOBUFS; |
| 8717 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 8718 | nla_nest_end(msg, nl_tcp); |
| 8719 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8720 | return 0; |
| 8721 | } |
| 8722 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8723 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8724 | { |
| 8725 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8726 | struct sk_buff *msg; |
| 8727 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8728 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8729 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8730 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8731 | return -EOPNOTSUPP; |
| 8732 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8733 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8734 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8735 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 8736 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 8737 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 8738 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8739 | } |
| 8740 | |
| 8741 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8742 | if (!msg) |
| 8743 | return -ENOMEM; |
| 8744 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8745 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8746 | NL80211_CMD_GET_WOWLAN); |
| 8747 | if (!hdr) |
| 8748 | goto nla_put_failure; |
| 8749 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8750 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8751 | struct nlattr *nl_wowlan; |
| 8752 | |
| 8753 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 8754 | if (!nl_wowlan) |
| 8755 | goto nla_put_failure; |
| 8756 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8757 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8758 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8759 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8760 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8761 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8762 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8763 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8764 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8765 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8766 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8767 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8768 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8769 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8770 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 8771 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8772 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8773 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 8774 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8775 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8776 | if (nl80211_send_wowlan_tcp(msg, |
| 8777 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8778 | goto nla_put_failure; |
| 8779 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8780 | nla_nest_end(msg, nl_wowlan); |
| 8781 | } |
| 8782 | |
| 8783 | genlmsg_end(msg, hdr); |
| 8784 | return genlmsg_reply(msg, info); |
| 8785 | |
| 8786 | nla_put_failure: |
| 8787 | nlmsg_free(msg); |
| 8788 | return -ENOBUFS; |
| 8789 | } |
| 8790 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8791 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 8792 | struct nlattr *attr, |
| 8793 | struct cfg80211_wowlan *trig) |
| 8794 | { |
| 8795 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 8796 | struct cfg80211_wowlan_tcp *cfg; |
| 8797 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 8798 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 8799 | u32 size; |
| 8800 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 8801 | int err, port; |
| 8802 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8803 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8804 | return -EINVAL; |
| 8805 | |
| 8806 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 8807 | nla_data(attr), nla_len(attr), |
| 8808 | nl80211_wowlan_tcp_policy); |
| 8809 | if (err) |
| 8810 | return err; |
| 8811 | |
| 8812 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 8813 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 8814 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 8815 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 8816 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 8817 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 8818 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 8819 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 8820 | return -EINVAL; |
| 8821 | |
| 8822 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8823 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8824 | return -EINVAL; |
| 8825 | |
| 8826 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8827 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 8828 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8829 | return -EINVAL; |
| 8830 | |
| 8831 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8832 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8833 | return -EINVAL; |
| 8834 | |
| 8835 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 8836 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 8837 | return -EINVAL; |
| 8838 | |
| 8839 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 8840 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8841 | |
| 8842 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8843 | tokens_size = tokln - sizeof(*tok); |
| 8844 | |
| 8845 | if (!tok->len || tokens_size % tok->len) |
| 8846 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8847 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8848 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8849 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8850 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8851 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8852 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8853 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8854 | return -EINVAL; |
| 8855 | if (tok->offset + tok->len > data_size) |
| 8856 | return -EINVAL; |
| 8857 | } |
| 8858 | |
| 8859 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 8860 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8861 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8862 | return -EINVAL; |
| 8863 | if (seq->len == 0 || seq->len > 4) |
| 8864 | return -EINVAL; |
| 8865 | if (seq->len + seq->offset > data_size) |
| 8866 | return -EINVAL; |
| 8867 | } |
| 8868 | |
| 8869 | size = sizeof(*cfg); |
| 8870 | size += data_size; |
| 8871 | size += wake_size + wake_mask_size; |
| 8872 | size += tokens_size; |
| 8873 | |
| 8874 | cfg = kzalloc(size, GFP_KERNEL); |
| 8875 | if (!cfg) |
| 8876 | return -ENOMEM; |
| 8877 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 8878 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 8879 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 8880 | ETH_ALEN); |
| 8881 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 8882 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 8883 | else |
| 8884 | port = 0; |
| 8885 | #ifdef CONFIG_INET |
| 8886 | /* allocate a socket and port for it and use it */ |
| 8887 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 8888 | IPPROTO_TCP, &cfg->sock, 1); |
| 8889 | if (err) { |
| 8890 | kfree(cfg); |
| 8891 | return err; |
| 8892 | } |
| 8893 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 8894 | sock_release(cfg->sock); |
| 8895 | kfree(cfg); |
| 8896 | return -EADDRINUSE; |
| 8897 | } |
| 8898 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 8899 | #else |
| 8900 | if (!port) { |
| 8901 | kfree(cfg); |
| 8902 | return -EINVAL; |
| 8903 | } |
| 8904 | cfg->src_port = port; |
| 8905 | #endif |
| 8906 | |
| 8907 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 8908 | cfg->payload_len = data_size; |
| 8909 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 8910 | memcpy((void *)cfg->payload, |
| 8911 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 8912 | data_size); |
| 8913 | if (seq) |
| 8914 | cfg->payload_seq = *seq; |
| 8915 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 8916 | cfg->wake_len = wake_size; |
| 8917 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 8918 | memcpy((void *)cfg->wake_data, |
| 8919 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 8920 | wake_size); |
| 8921 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 8922 | data_size + wake_size; |
| 8923 | memcpy((void *)cfg->wake_mask, |
| 8924 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 8925 | wake_mask_size); |
| 8926 | if (tok) { |
| 8927 | cfg->tokens_size = tokens_size; |
| 8928 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 8929 | } |
| 8930 | |
| 8931 | trig->tcp = cfg; |
| 8932 | |
| 8933 | return 0; |
| 8934 | } |
| 8935 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 8936 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
| 8937 | const struct wiphy_wowlan_support *wowlan, |
| 8938 | struct nlattr *attr, |
| 8939 | struct cfg80211_wowlan *trig) |
| 8940 | { |
| 8941 | struct nlattr **tb; |
| 8942 | int err; |
| 8943 | |
| 8944 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); |
| 8945 | if (!tb) |
| 8946 | return -ENOMEM; |
| 8947 | |
| 8948 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { |
| 8949 | err = -EOPNOTSUPP; |
| 8950 | goto out; |
| 8951 | } |
| 8952 | |
| 8953 | err = nla_parse(tb, NL80211_ATTR_MAX, |
| 8954 | nla_data(attr), nla_len(attr), |
| 8955 | nl80211_policy); |
| 8956 | if (err) |
| 8957 | goto out; |
| 8958 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 8959 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 8960 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
| 8961 | if (err) |
| 8962 | trig->nd_config = NULL; |
| 8963 | |
| 8964 | out: |
| 8965 | kfree(tb); |
| 8966 | return err; |
| 8967 | } |
| 8968 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8969 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8970 | { |
| 8971 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8972 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8973 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8974 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8975 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8976 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8977 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8978 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8979 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8980 | return -EOPNOTSUPP; |
| 8981 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8982 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 8983 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8984 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8985 | goto set_wakeup; |
| 8986 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8987 | |
| 8988 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 8989 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8990 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8991 | nl80211_wowlan_policy); |
| 8992 | if (err) |
| 8993 | return err; |
| 8994 | |
| 8995 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 8996 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 8997 | return -EINVAL; |
| 8998 | new_triggers.any = true; |
| 8999 | } |
| 9000 | |
| 9001 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 9002 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 9003 | return -EINVAL; |
| 9004 | new_triggers.disconnect = true; |
| 9005 | } |
| 9006 | |
| 9007 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 9008 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 9009 | return -EINVAL; |
| 9010 | new_triggers.magic_pkt = true; |
| 9011 | } |
| 9012 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 9013 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 9014 | return -EINVAL; |
| 9015 | |
| 9016 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 9017 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 9018 | return -EINVAL; |
| 9019 | new_triggers.gtk_rekey_failure = true; |
| 9020 | } |
| 9021 | |
| 9022 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 9023 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 9024 | return -EINVAL; |
| 9025 | new_triggers.eap_identity_req = true; |
| 9026 | } |
| 9027 | |
| 9028 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 9029 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 9030 | return -EINVAL; |
| 9031 | new_triggers.four_way_handshake = true; |
| 9032 | } |
| 9033 | |
| 9034 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 9035 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 9036 | return -EINVAL; |
| 9037 | new_triggers.rfkill_release = true; |
| 9038 | } |
| 9039 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9040 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 9041 | struct nlattr *pat; |
| 9042 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9043 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9044 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9045 | |
| 9046 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 9047 | rem) |
| 9048 | n_patterns++; |
| 9049 | if (n_patterns > wowlan->n_patterns) |
| 9050 | return -EINVAL; |
| 9051 | |
| 9052 | new_triggers.patterns = kcalloc(n_patterns, |
| 9053 | sizeof(new_triggers.patterns[0]), |
| 9054 | GFP_KERNEL); |
| 9055 | if (!new_triggers.patterns) |
| 9056 | return -ENOMEM; |
| 9057 | |
| 9058 | new_triggers.n_patterns = n_patterns; |
| 9059 | i = 0; |
| 9060 | |
| 9061 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 9062 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9063 | u8 *mask_pat; |
| 9064 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9065 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 9066 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9067 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9068 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 9069 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9070 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9071 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9072 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9073 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9074 | goto error; |
| 9075 | if (pat_len > wowlan->pattern_max_len || |
| 9076 | pat_len < wowlan->pattern_min_len) |
| 9077 | goto error; |
| 9078 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9079 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9080 | pkt_offset = 0; |
| 9081 | else |
| 9082 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9083 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9084 | if (pkt_offset > wowlan->max_pkt_offset) |
| 9085 | goto error; |
| 9086 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 9087 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9088 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 9089 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9090 | err = -ENOMEM; |
| 9091 | goto error; |
| 9092 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9093 | new_triggers.patterns[i].mask = mask_pat; |
| 9094 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9095 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9096 | mask_pat += mask_len; |
| 9097 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9098 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9099 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9100 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9101 | pat_len); |
| 9102 | i++; |
| 9103 | } |
| 9104 | } |
| 9105 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9106 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 9107 | err = nl80211_parse_wowlan_tcp( |
| 9108 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 9109 | &new_triggers); |
| 9110 | if (err) |
| 9111 | goto error; |
| 9112 | } |
| 9113 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9114 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
| 9115 | err = nl80211_parse_wowlan_nd( |
| 9116 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], |
| 9117 | &new_triggers); |
| 9118 | if (err) |
| 9119 | goto error; |
| 9120 | } |
| 9121 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9122 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 9123 | if (!ntrig) { |
| 9124 | err = -ENOMEM; |
| 9125 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9126 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9127 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9128 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9129 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9130 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9131 | if (rdev->ops->set_wakeup && |
| 9132 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 9133 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 9134 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9135 | return 0; |
| 9136 | error: |
| 9137 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 9138 | kfree(new_triggers.patterns[i].mask); |
| 9139 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9140 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 9141 | sock_release(new_triggers.tcp->sock); |
| 9142 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9143 | return err; |
| 9144 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9145 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9146 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9147 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 9148 | struct cfg80211_registered_device *rdev) |
| 9149 | { |
| 9150 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 9151 | int i, j, pat_len; |
| 9152 | struct cfg80211_coalesce_rules *rule; |
| 9153 | |
| 9154 | if (!rdev->coalesce->n_rules) |
| 9155 | return 0; |
| 9156 | |
| 9157 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 9158 | if (!nl_rules) |
| 9159 | return -ENOBUFS; |
| 9160 | |
| 9161 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 9162 | nl_rule = nla_nest_start(msg, i + 1); |
| 9163 | if (!nl_rule) |
| 9164 | return -ENOBUFS; |
| 9165 | |
| 9166 | rule = &rdev->coalesce->rules[i]; |
| 9167 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 9168 | rule->delay)) |
| 9169 | return -ENOBUFS; |
| 9170 | |
| 9171 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 9172 | rule->condition)) |
| 9173 | return -ENOBUFS; |
| 9174 | |
| 9175 | nl_pats = nla_nest_start(msg, |
| 9176 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 9177 | if (!nl_pats) |
| 9178 | return -ENOBUFS; |
| 9179 | |
| 9180 | for (j = 0; j < rule->n_patterns; j++) { |
| 9181 | nl_pat = nla_nest_start(msg, j + 1); |
| 9182 | if (!nl_pat) |
| 9183 | return -ENOBUFS; |
| 9184 | pat_len = rule->patterns[j].pattern_len; |
| 9185 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 9186 | DIV_ROUND_UP(pat_len, 8), |
| 9187 | rule->patterns[j].mask) || |
| 9188 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 9189 | rule->patterns[j].pattern) || |
| 9190 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 9191 | rule->patterns[j].pkt_offset)) |
| 9192 | return -ENOBUFS; |
| 9193 | nla_nest_end(msg, nl_pat); |
| 9194 | } |
| 9195 | nla_nest_end(msg, nl_pats); |
| 9196 | nla_nest_end(msg, nl_rule); |
| 9197 | } |
| 9198 | nla_nest_end(msg, nl_rules); |
| 9199 | |
| 9200 | return 0; |
| 9201 | } |
| 9202 | |
| 9203 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 9204 | { |
| 9205 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9206 | struct sk_buff *msg; |
| 9207 | void *hdr; |
| 9208 | |
| 9209 | if (!rdev->wiphy.coalesce) |
| 9210 | return -EOPNOTSUPP; |
| 9211 | |
| 9212 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9213 | if (!msg) |
| 9214 | return -ENOMEM; |
| 9215 | |
| 9216 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 9217 | NL80211_CMD_GET_COALESCE); |
| 9218 | if (!hdr) |
| 9219 | goto nla_put_failure; |
| 9220 | |
| 9221 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 9222 | goto nla_put_failure; |
| 9223 | |
| 9224 | genlmsg_end(msg, hdr); |
| 9225 | return genlmsg_reply(msg, info); |
| 9226 | |
| 9227 | nla_put_failure: |
| 9228 | nlmsg_free(msg); |
| 9229 | return -ENOBUFS; |
| 9230 | } |
| 9231 | |
| 9232 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 9233 | { |
| 9234 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 9235 | int i, j; |
| 9236 | struct cfg80211_coalesce_rules *rule; |
| 9237 | |
| 9238 | if (!coalesce) |
| 9239 | return; |
| 9240 | |
| 9241 | for (i = 0; i < coalesce->n_rules; i++) { |
| 9242 | rule = &coalesce->rules[i]; |
| 9243 | for (j = 0; j < rule->n_patterns; j++) |
| 9244 | kfree(rule->patterns[j].mask); |
| 9245 | kfree(rule->patterns); |
| 9246 | } |
| 9247 | kfree(coalesce->rules); |
| 9248 | kfree(coalesce); |
| 9249 | rdev->coalesce = NULL; |
| 9250 | } |
| 9251 | |
| 9252 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 9253 | struct nlattr *rule, |
| 9254 | struct cfg80211_coalesce_rules *new_rule) |
| 9255 | { |
| 9256 | int err, i; |
| 9257 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 9258 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 9259 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 9260 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 9261 | |
| 9262 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 9263 | nla_len(rule), nl80211_coalesce_policy); |
| 9264 | if (err) |
| 9265 | return err; |
| 9266 | |
| 9267 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 9268 | new_rule->delay = |
| 9269 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 9270 | if (new_rule->delay > coalesce->max_delay) |
| 9271 | return -EINVAL; |
| 9272 | |
| 9273 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 9274 | new_rule->condition = |
| 9275 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 9276 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 9277 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 9278 | return -EINVAL; |
| 9279 | |
| 9280 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 9281 | return -EINVAL; |
| 9282 | |
| 9283 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 9284 | rem) |
| 9285 | n_patterns++; |
| 9286 | if (n_patterns > coalesce->n_patterns) |
| 9287 | return -EINVAL; |
| 9288 | |
| 9289 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 9290 | GFP_KERNEL); |
| 9291 | if (!new_rule->patterns) |
| 9292 | return -ENOMEM; |
| 9293 | |
| 9294 | new_rule->n_patterns = n_patterns; |
| 9295 | i = 0; |
| 9296 | |
| 9297 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 9298 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9299 | u8 *mask_pat; |
| 9300 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9301 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 9302 | nla_len(pat), NULL); |
| 9303 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 9304 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 9305 | return -EINVAL; |
| 9306 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 9307 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 9308 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 9309 | return -EINVAL; |
| 9310 | if (pat_len > coalesce->pattern_max_len || |
| 9311 | pat_len < coalesce->pattern_min_len) |
| 9312 | return -EINVAL; |
| 9313 | |
| 9314 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 9315 | pkt_offset = 0; |
| 9316 | else |
| 9317 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 9318 | if (pkt_offset > coalesce->max_pkt_offset) |
| 9319 | return -EINVAL; |
| 9320 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 9321 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9322 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 9323 | if (!mask_pat) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9324 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9325 | |
| 9326 | new_rule->patterns[i].mask = mask_pat; |
| 9327 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 9328 | mask_len); |
| 9329 | |
| 9330 | mask_pat += mask_len; |
| 9331 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9332 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9333 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 9334 | pat_len); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9335 | i++; |
| 9336 | } |
| 9337 | |
| 9338 | return 0; |
| 9339 | } |
| 9340 | |
| 9341 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 9342 | { |
| 9343 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9344 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 9345 | struct cfg80211_coalesce new_coalesce = {}; |
| 9346 | struct cfg80211_coalesce *n_coalesce; |
| 9347 | int err, rem_rule, n_rules = 0, i, j; |
| 9348 | struct nlattr *rule; |
| 9349 | struct cfg80211_coalesce_rules *tmp_rule; |
| 9350 | |
| 9351 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 9352 | return -EOPNOTSUPP; |
| 9353 | |
| 9354 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 9355 | cfg80211_rdev_free_coalesce(rdev); |
| 9356 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); |
| 9357 | return 0; |
| 9358 | } |
| 9359 | |
| 9360 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 9361 | rem_rule) |
| 9362 | n_rules++; |
| 9363 | if (n_rules > coalesce->n_rules) |
| 9364 | return -EINVAL; |
| 9365 | |
| 9366 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 9367 | GFP_KERNEL); |
| 9368 | if (!new_coalesce.rules) |
| 9369 | return -ENOMEM; |
| 9370 | |
| 9371 | new_coalesce.n_rules = n_rules; |
| 9372 | i = 0; |
| 9373 | |
| 9374 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 9375 | rem_rule) { |
| 9376 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 9377 | &new_coalesce.rules[i]); |
| 9378 | if (err) |
| 9379 | goto error; |
| 9380 | |
| 9381 | i++; |
| 9382 | } |
| 9383 | |
| 9384 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); |
| 9385 | if (err) |
| 9386 | goto error; |
| 9387 | |
| 9388 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 9389 | if (!n_coalesce) { |
| 9390 | err = -ENOMEM; |
| 9391 | goto error; |
| 9392 | } |
| 9393 | cfg80211_rdev_free_coalesce(rdev); |
| 9394 | rdev->coalesce = n_coalesce; |
| 9395 | |
| 9396 | return 0; |
| 9397 | error: |
| 9398 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 9399 | tmp_rule = &new_coalesce.rules[i]; |
| 9400 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 9401 | kfree(tmp_rule->patterns[j].mask); |
| 9402 | kfree(tmp_rule->patterns); |
| 9403 | } |
| 9404 | kfree(new_coalesce.rules); |
| 9405 | |
| 9406 | return err; |
| 9407 | } |
| 9408 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9409 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 9410 | { |
| 9411 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9412 | struct net_device *dev = info->user_ptr[1]; |
| 9413 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9414 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 9415 | struct cfg80211_gtk_rekey_data rekey_data; |
| 9416 | int err; |
| 9417 | |
| 9418 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 9419 | return -EINVAL; |
| 9420 | |
| 9421 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 9422 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 9423 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 9424 | nl80211_rekey_policy); |
| 9425 | if (err) |
| 9426 | return err; |
| 9427 | |
| 9428 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 9429 | return -ERANGE; |
| 9430 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 9431 | return -ERANGE; |
| 9432 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 9433 | return -ERANGE; |
| 9434 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 9435 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 9436 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 9437 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9438 | |
| 9439 | wdev_lock(wdev); |
| 9440 | if (!wdev->current_bss) { |
| 9441 | err = -ENOTCONN; |
| 9442 | goto out; |
| 9443 | } |
| 9444 | |
| 9445 | if (!rdev->ops->set_rekey_data) { |
| 9446 | err = -EOPNOTSUPP; |
| 9447 | goto out; |
| 9448 | } |
| 9449 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9450 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9451 | out: |
| 9452 | wdev_unlock(wdev); |
| 9453 | return err; |
| 9454 | } |
| 9455 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9456 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 9457 | struct genl_info *info) |
| 9458 | { |
| 9459 | struct net_device *dev = info->user_ptr[1]; |
| 9460 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9461 | |
| 9462 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 9463 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 9464 | return -EINVAL; |
| 9465 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9466 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9467 | return -EBUSY; |
| 9468 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9469 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9470 | return 0; |
| 9471 | } |
| 9472 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9473 | static int nl80211_probe_client(struct sk_buff *skb, |
| 9474 | struct genl_info *info) |
| 9475 | { |
| 9476 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9477 | struct net_device *dev = info->user_ptr[1]; |
| 9478 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9479 | struct sk_buff *msg; |
| 9480 | void *hdr; |
| 9481 | const u8 *addr; |
| 9482 | u64 cookie; |
| 9483 | int err; |
| 9484 | |
| 9485 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 9486 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 9487 | return -EOPNOTSUPP; |
| 9488 | |
| 9489 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9490 | return -EINVAL; |
| 9491 | |
| 9492 | if (!rdev->ops->probe_client) |
| 9493 | return -EOPNOTSUPP; |
| 9494 | |
| 9495 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9496 | if (!msg) |
| 9497 | return -ENOMEM; |
| 9498 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9499 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9500 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9501 | if (!hdr) { |
| 9502 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9503 | goto free_msg; |
| 9504 | } |
| 9505 | |
| 9506 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9507 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9508 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9509 | if (err) |
| 9510 | goto free_msg; |
| 9511 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9512 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9513 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9514 | |
| 9515 | genlmsg_end(msg, hdr); |
| 9516 | |
| 9517 | return genlmsg_reply(msg, info); |
| 9518 | |
| 9519 | nla_put_failure: |
| 9520 | err = -ENOBUFS; |
| 9521 | free_msg: |
| 9522 | nlmsg_free(msg); |
| 9523 | return err; |
| 9524 | } |
| 9525 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9526 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 9527 | { |
| 9528 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9529 | struct cfg80211_beacon_registration *reg, *nreg; |
| 9530 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9531 | |
| 9532 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 9533 | return -EOPNOTSUPP; |
| 9534 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9535 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 9536 | if (!nreg) |
| 9537 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9538 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9539 | /* First, check if already registered. */ |
| 9540 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9541 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 9542 | if (reg->nlportid == info->snd_portid) { |
| 9543 | rv = -EALREADY; |
| 9544 | goto out_err; |
| 9545 | } |
| 9546 | } |
| 9547 | /* Add it to the list */ |
| 9548 | nreg->nlportid = info->snd_portid; |
| 9549 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 9550 | |
| 9551 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9552 | |
| 9553 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9554 | out_err: |
| 9555 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9556 | kfree(nreg); |
| 9557 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9558 | } |
| 9559 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9560 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 9561 | { |
| 9562 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9563 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9564 | int err; |
| 9565 | |
| 9566 | if (!rdev->ops->start_p2p_device) |
| 9567 | return -EOPNOTSUPP; |
| 9568 | |
| 9569 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 9570 | return -EOPNOTSUPP; |
| 9571 | |
| 9572 | if (wdev->p2p_started) |
| 9573 | return 0; |
| 9574 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 9575 | if (rfkill_blocked(rdev->rfkill)) |
| 9576 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9577 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 9578 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9579 | if (err) |
| 9580 | return err; |
| 9581 | |
| 9582 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9583 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9584 | |
| 9585 | return 0; |
| 9586 | } |
| 9587 | |
| 9588 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 9589 | { |
| 9590 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9591 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9592 | |
| 9593 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 9594 | return -EOPNOTSUPP; |
| 9595 | |
| 9596 | if (!rdev->ops->stop_p2p_device) |
| 9597 | return -EOPNOTSUPP; |
| 9598 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 9599 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9600 | |
| 9601 | return 0; |
| 9602 | } |
| 9603 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9604 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 9605 | struct genl_info *info) |
| 9606 | { |
| 9607 | void *hdr; |
| 9608 | struct sk_buff *msg; |
| 9609 | |
| 9610 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9611 | if (!msg) |
| 9612 | return -ENOMEM; |
| 9613 | |
| 9614 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 9615 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 9616 | if (!hdr) |
| 9617 | goto nla_put_failure; |
| 9618 | |
| 9619 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 9620 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 9621 | goto nla_put_failure; |
| 9622 | |
| 9623 | genlmsg_end(msg, hdr); |
| 9624 | return genlmsg_reply(msg, info); |
| 9625 | |
| 9626 | nla_put_failure: |
| 9627 | kfree_skb(msg); |
| 9628 | return -ENOBUFS; |
| 9629 | } |
| 9630 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9631 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 9632 | { |
| 9633 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9634 | struct cfg80211_update_ft_ies_params ft_params; |
| 9635 | struct net_device *dev = info->user_ptr[1]; |
| 9636 | |
| 9637 | if (!rdev->ops->update_ft_ies) |
| 9638 | return -EOPNOTSUPP; |
| 9639 | |
| 9640 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 9641 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 9642 | return -EINVAL; |
| 9643 | |
| 9644 | memset(&ft_params, 0, sizeof(ft_params)); |
| 9645 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 9646 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9647 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9648 | |
| 9649 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 9650 | } |
| 9651 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9652 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 9653 | struct genl_info *info) |
| 9654 | { |
| 9655 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9656 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9657 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 9658 | u16 duration; |
| 9659 | int ret; |
| 9660 | |
| 9661 | if (!rdev->ops->crit_proto_start) |
| 9662 | return -EOPNOTSUPP; |
| 9663 | |
| 9664 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 9665 | return -EINVAL; |
| 9666 | |
| 9667 | if (rdev->crit_proto_nlportid) |
| 9668 | return -EBUSY; |
| 9669 | |
| 9670 | /* determine protocol if provided */ |
| 9671 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 9672 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 9673 | |
| 9674 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 9675 | return -EINVAL; |
| 9676 | |
| 9677 | /* timeout must be provided */ |
| 9678 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 9679 | return -EINVAL; |
| 9680 | |
| 9681 | duration = |
| 9682 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 9683 | |
| 9684 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 9685 | return -ERANGE; |
| 9686 | |
| 9687 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 9688 | if (!ret) |
| 9689 | rdev->crit_proto_nlportid = info->snd_portid; |
| 9690 | |
| 9691 | return ret; |
| 9692 | } |
| 9693 | |
| 9694 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 9695 | struct genl_info *info) |
| 9696 | { |
| 9697 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9698 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9699 | |
| 9700 | if (!rdev->ops->crit_proto_stop) |
| 9701 | return -EOPNOTSUPP; |
| 9702 | |
| 9703 | if (rdev->crit_proto_nlportid) { |
| 9704 | rdev->crit_proto_nlportid = 0; |
| 9705 | rdev_crit_proto_stop(rdev, wdev); |
| 9706 | } |
| 9707 | return 0; |
| 9708 | } |
| 9709 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9710 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 9711 | { |
| 9712 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9713 | struct wireless_dev *wdev = |
| 9714 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 9715 | int i, err; |
| 9716 | u32 vid, subcmd; |
| 9717 | |
| 9718 | if (!rdev->wiphy.vendor_commands) |
| 9719 | return -EOPNOTSUPP; |
| 9720 | |
| 9721 | if (IS_ERR(wdev)) { |
| 9722 | err = PTR_ERR(wdev); |
| 9723 | if (err != -EINVAL) |
| 9724 | return err; |
| 9725 | wdev = NULL; |
| 9726 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 9727 | return -EINVAL; |
| 9728 | } |
| 9729 | |
| 9730 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 9731 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 9732 | return -EINVAL; |
| 9733 | |
| 9734 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 9735 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 9736 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 9737 | const struct wiphy_vendor_command *vcmd; |
| 9738 | void *data = NULL; |
| 9739 | int len = 0; |
| 9740 | |
| 9741 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 9742 | |
| 9743 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 9744 | continue; |
| 9745 | |
| 9746 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 9747 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 9748 | if (!wdev) |
| 9749 | return -EINVAL; |
| 9750 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 9751 | !wdev->netdev) |
| 9752 | return -EINVAL; |
| 9753 | |
| 9754 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 9755 | if (wdev->netdev && |
| 9756 | !netif_running(wdev->netdev)) |
| 9757 | return -ENETDOWN; |
| 9758 | if (!wdev->netdev && !wdev->p2p_started) |
| 9759 | return -ENETDOWN; |
| 9760 | } |
| 9761 | } else { |
| 9762 | wdev = NULL; |
| 9763 | } |
| 9764 | |
| 9765 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 9766 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9767 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9768 | } |
| 9769 | |
| 9770 | rdev->cur_cmd_info = info; |
| 9771 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 9772 | data, len); |
| 9773 | rdev->cur_cmd_info = NULL; |
| 9774 | return err; |
| 9775 | } |
| 9776 | |
| 9777 | return -EOPNOTSUPP; |
| 9778 | } |
| 9779 | |
| 9780 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 9781 | enum nl80211_commands cmd, |
| 9782 | enum nl80211_attrs attr, |
| 9783 | int approxlen) |
| 9784 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 9785 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9786 | |
| 9787 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 9788 | return NULL; |
| 9789 | |
| 9790 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, |
| 9791 | rdev->cur_cmd_info->snd_portid, |
| 9792 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 9793 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9794 | } |
| 9795 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 9796 | |
| 9797 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 9798 | { |
| 9799 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 9800 | void *hdr = ((void **)skb->cb)[1]; |
| 9801 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 9802 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 9803 | /* clear CB data for netlink core to own from now on */ |
| 9804 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 9805 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9806 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 9807 | kfree_skb(skb); |
| 9808 | return -EINVAL; |
| 9809 | } |
| 9810 | |
| 9811 | nla_nest_end(skb, data); |
| 9812 | genlmsg_end(skb, hdr); |
| 9813 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 9814 | } |
| 9815 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 9816 | |
| 9817 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 9818 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 9819 | struct genl_info *info) |
| 9820 | { |
| 9821 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9822 | struct cfg80211_qos_map *qos_map = NULL; |
| 9823 | struct net_device *dev = info->user_ptr[1]; |
| 9824 | u8 *pos, len, num_des, des_len, des; |
| 9825 | int ret; |
| 9826 | |
| 9827 | if (!rdev->ops->set_qos_map) |
| 9828 | return -EOPNOTSUPP; |
| 9829 | |
| 9830 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 9831 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9832 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9833 | |
| 9834 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 9835 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 9836 | return -EINVAL; |
| 9837 | |
| 9838 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 9839 | if (!qos_map) |
| 9840 | return -ENOMEM; |
| 9841 | |
| 9842 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 9843 | if (num_des) { |
| 9844 | des_len = num_des * |
| 9845 | sizeof(struct cfg80211_dscp_exception); |
| 9846 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 9847 | qos_map->num_des = num_des; |
| 9848 | for (des = 0; des < num_des; des++) { |
| 9849 | if (qos_map->dscp_exception[des].up > 7) { |
| 9850 | kfree(qos_map); |
| 9851 | return -EINVAL; |
| 9852 | } |
| 9853 | } |
| 9854 | pos += des_len; |
| 9855 | } |
| 9856 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 9857 | } |
| 9858 | |
| 9859 | wdev_lock(dev->ieee80211_ptr); |
| 9860 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 9861 | if (!ret) |
| 9862 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 9863 | wdev_unlock(dev->ieee80211_ptr); |
| 9864 | |
| 9865 | kfree(qos_map); |
| 9866 | return ret; |
| 9867 | } |
| 9868 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 9869 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 9870 | { |
| 9871 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9872 | struct net_device *dev = info->user_ptr[1]; |
| 9873 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9874 | const u8 *peer; |
| 9875 | u8 tsid, up; |
| 9876 | u16 admitted_time = 0; |
| 9877 | int err; |
| 9878 | |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 9879 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 9880 | return -EOPNOTSUPP; |
| 9881 | |
| 9882 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 9883 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 9884 | return -EINVAL; |
| 9885 | |
| 9886 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 9887 | if (tsid >= IEEE80211_NUM_TIDS) |
| 9888 | return -EINVAL; |
| 9889 | |
| 9890 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
| 9891 | if (up >= IEEE80211_NUM_UPS) |
| 9892 | return -EINVAL; |
| 9893 | |
| 9894 | /* WMM uses TIDs 0-7 even for TSPEC */ |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 9895 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 9896 | /* TODO: handle 802.11 TSPEC/admission control |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 9897 | * need more attributes for that (e.g. BA session requirement); |
| 9898 | * change the WMM adminssion test above to allow both then |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 9899 | */ |
| 9900 | return -EINVAL; |
| 9901 | } |
| 9902 | |
| 9903 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9904 | |
| 9905 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 9906 | admitted_time = |
| 9907 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 9908 | if (!admitted_time) |
| 9909 | return -EINVAL; |
| 9910 | } |
| 9911 | |
| 9912 | wdev_lock(wdev); |
| 9913 | switch (wdev->iftype) { |
| 9914 | case NL80211_IFTYPE_STATION: |
| 9915 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9916 | if (wdev->current_bss) |
| 9917 | break; |
| 9918 | err = -ENOTCONN; |
| 9919 | goto out; |
| 9920 | default: |
| 9921 | err = -EOPNOTSUPP; |
| 9922 | goto out; |
| 9923 | } |
| 9924 | |
| 9925 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 9926 | |
| 9927 | out: |
| 9928 | wdev_unlock(wdev); |
| 9929 | return err; |
| 9930 | } |
| 9931 | |
| 9932 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 9933 | { |
| 9934 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9935 | struct net_device *dev = info->user_ptr[1]; |
| 9936 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9937 | const u8 *peer; |
| 9938 | u8 tsid; |
| 9939 | int err; |
| 9940 | |
| 9941 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 9942 | return -EINVAL; |
| 9943 | |
| 9944 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 9945 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9946 | |
| 9947 | wdev_lock(wdev); |
| 9948 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 9949 | wdev_unlock(wdev); |
| 9950 | |
| 9951 | return err; |
| 9952 | } |
| 9953 | |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 9954 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
| 9955 | struct genl_info *info) |
| 9956 | { |
| 9957 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9958 | struct net_device *dev = info->user_ptr[1]; |
| 9959 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9960 | struct cfg80211_chan_def chandef = {}; |
| 9961 | const u8 *addr; |
| 9962 | u8 oper_class; |
| 9963 | int err; |
| 9964 | |
| 9965 | if (!rdev->ops->tdls_channel_switch || |
| 9966 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 9967 | return -EOPNOTSUPP; |
| 9968 | |
| 9969 | switch (dev->ieee80211_ptr->iftype) { |
| 9970 | case NL80211_IFTYPE_STATION: |
| 9971 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9972 | break; |
| 9973 | default: |
| 9974 | return -EOPNOTSUPP; |
| 9975 | } |
| 9976 | |
| 9977 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 9978 | !info->attrs[NL80211_ATTR_OPER_CLASS]) |
| 9979 | return -EINVAL; |
| 9980 | |
| 9981 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 9982 | if (err) |
| 9983 | return err; |
| 9984 | |
| 9985 | /* |
| 9986 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 |
| 9987 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the |
| 9988 | * specification is not defined for them. |
| 9989 | */ |
| 9990 | if (chandef.chan->band == IEEE80211_BAND_2GHZ && |
| 9991 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 9992 | chandef.width != NL80211_CHAN_WIDTH_20) |
| 9993 | return -EINVAL; |
| 9994 | |
| 9995 | /* we will be active on the TDLS link */ |
| 9996 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, wdev->iftype)) |
| 9997 | return -EINVAL; |
| 9998 | |
| 9999 | /* don't allow switching to DFS channels */ |
| 10000 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) |
| 10001 | return -EINVAL; |
| 10002 | |
| 10003 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10004 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); |
| 10005 | |
| 10006 | wdev_lock(wdev); |
| 10007 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); |
| 10008 | wdev_unlock(wdev); |
| 10009 | |
| 10010 | return err; |
| 10011 | } |
| 10012 | |
| 10013 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, |
| 10014 | struct genl_info *info) |
| 10015 | { |
| 10016 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10017 | struct net_device *dev = info->user_ptr[1]; |
| 10018 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10019 | const u8 *addr; |
| 10020 | |
| 10021 | if (!rdev->ops->tdls_channel_switch || |
| 10022 | !rdev->ops->tdls_cancel_channel_switch || |
| 10023 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 10024 | return -EOPNOTSUPP; |
| 10025 | |
| 10026 | switch (dev->ieee80211_ptr->iftype) { |
| 10027 | case NL80211_IFTYPE_STATION: |
| 10028 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10029 | break; |
| 10030 | default: |
| 10031 | return -EOPNOTSUPP; |
| 10032 | } |
| 10033 | |
| 10034 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 10035 | return -EINVAL; |
| 10036 | |
| 10037 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10038 | |
| 10039 | wdev_lock(wdev); |
| 10040 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); |
| 10041 | wdev_unlock(wdev); |
| 10042 | |
| 10043 | return 0; |
| 10044 | } |
| 10045 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10046 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 10047 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 10048 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10049 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 10050 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 10051 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10052 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10053 | /* 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] | 10054 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 10055 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10056 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10057 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 10058 | 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] | 10059 | struct genl_info *info) |
| 10060 | { |
| 10061 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10062 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10063 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10064 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 10065 | |
| 10066 | if (rtnl) |
| 10067 | rtnl_lock(); |
| 10068 | |
| 10069 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 10070 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10071 | if (IS_ERR(rdev)) { |
| 10072 | if (rtnl) |
| 10073 | rtnl_unlock(); |
| 10074 | return PTR_ERR(rdev); |
| 10075 | } |
| 10076 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10077 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 10078 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10079 | ASSERT_RTNL(); |
| 10080 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10081 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 10082 | info->attrs); |
| 10083 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10084 | if (rtnl) |
| 10085 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10086 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10087 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10088 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10089 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10090 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10091 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10092 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 10093 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10094 | if (rtnl) |
| 10095 | rtnl_unlock(); |
| 10096 | return -EINVAL; |
| 10097 | } |
| 10098 | |
| 10099 | info->user_ptr[1] = dev; |
| 10100 | } else { |
| 10101 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10102 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10103 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10104 | if (dev) { |
| 10105 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 10106 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10107 | if (rtnl) |
| 10108 | rtnl_unlock(); |
| 10109 | return -ENETDOWN; |
| 10110 | } |
| 10111 | |
| 10112 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10113 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 10114 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10115 | if (rtnl) |
| 10116 | rtnl_unlock(); |
| 10117 | return -ENETDOWN; |
| 10118 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10119 | } |
| 10120 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10121 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10122 | } |
| 10123 | |
| 10124 | return 0; |
| 10125 | } |
| 10126 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 10127 | 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] | 10128 | struct genl_info *info) |
| 10129 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10130 | if (info->user_ptr[1]) { |
| 10131 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 10132 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10133 | |
| 10134 | if (wdev->netdev) |
| 10135 | dev_put(wdev->netdev); |
| 10136 | } else { |
| 10137 | dev_put(info->user_ptr[1]); |
| 10138 | } |
| 10139 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10140 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10141 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 10142 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10143 | |
| 10144 | /* If needed, clear the netlink message payload from the SKB |
| 10145 | * as it might contain key data that shouldn't stick around on |
| 10146 | * the heap after the SKB is freed. The netlink message header |
| 10147 | * is still needed for further processing, so leave it intact. |
| 10148 | */ |
| 10149 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 10150 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 10151 | |
| 10152 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 10153 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10154 | } |
| 10155 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 10156 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10157 | { |
| 10158 | .cmd = NL80211_CMD_GET_WIPHY, |
| 10159 | .doit = nl80211_get_wiphy, |
| 10160 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 10161 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10162 | .policy = nl80211_policy, |
| 10163 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10164 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10165 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10166 | }, |
| 10167 | { |
| 10168 | .cmd = NL80211_CMD_SET_WIPHY, |
| 10169 | .doit = nl80211_set_wiphy, |
| 10170 | .policy = nl80211_policy, |
| 10171 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10172 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10173 | }, |
| 10174 | { |
| 10175 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 10176 | .doit = nl80211_get_interface, |
| 10177 | .dumpit = nl80211_dump_interface, |
| 10178 | .policy = nl80211_policy, |
| 10179 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10180 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 10181 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10182 | }, |
| 10183 | { |
| 10184 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 10185 | .doit = nl80211_set_interface, |
| 10186 | .policy = nl80211_policy, |
| 10187 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10188 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10189 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10190 | }, |
| 10191 | { |
| 10192 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 10193 | .doit = nl80211_new_interface, |
| 10194 | .policy = nl80211_policy, |
| 10195 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10196 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10197 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10198 | }, |
| 10199 | { |
| 10200 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 10201 | .doit = nl80211_del_interface, |
| 10202 | .policy = nl80211_policy, |
| 10203 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 10204 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10205 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10206 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10207 | { |
| 10208 | .cmd = NL80211_CMD_GET_KEY, |
| 10209 | .doit = nl80211_get_key, |
| 10210 | .policy = nl80211_policy, |
| 10211 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10212 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10213 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10214 | }, |
| 10215 | { |
| 10216 | .cmd = NL80211_CMD_SET_KEY, |
| 10217 | .doit = nl80211_set_key, |
| 10218 | .policy = nl80211_policy, |
| 10219 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10220 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10221 | NL80211_FLAG_NEED_RTNL | |
| 10222 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10223 | }, |
| 10224 | { |
| 10225 | .cmd = NL80211_CMD_NEW_KEY, |
| 10226 | .doit = nl80211_new_key, |
| 10227 | .policy = nl80211_policy, |
| 10228 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10229 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10230 | NL80211_FLAG_NEED_RTNL | |
| 10231 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10232 | }, |
| 10233 | { |
| 10234 | .cmd = NL80211_CMD_DEL_KEY, |
| 10235 | .doit = nl80211_del_key, |
| 10236 | .policy = nl80211_policy, |
| 10237 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10238 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10239 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10240 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10241 | { |
| 10242 | .cmd = NL80211_CMD_SET_BEACON, |
| 10243 | .policy = nl80211_policy, |
| 10244 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10245 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10246 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10247 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10248 | }, |
| 10249 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10250 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10251 | .policy = nl80211_policy, |
| 10252 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10253 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10254 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10255 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10256 | }, |
| 10257 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10258 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10259 | .policy = nl80211_policy, |
| 10260 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10261 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10262 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10263 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10264 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10265 | { |
| 10266 | .cmd = NL80211_CMD_GET_STATION, |
| 10267 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10268 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10269 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10270 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10271 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10272 | }, |
| 10273 | { |
| 10274 | .cmd = NL80211_CMD_SET_STATION, |
| 10275 | .doit = nl80211_set_station, |
| 10276 | .policy = nl80211_policy, |
| 10277 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10278 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10279 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10280 | }, |
| 10281 | { |
| 10282 | .cmd = NL80211_CMD_NEW_STATION, |
| 10283 | .doit = nl80211_new_station, |
| 10284 | .policy = nl80211_policy, |
| 10285 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10286 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10287 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10288 | }, |
| 10289 | { |
| 10290 | .cmd = NL80211_CMD_DEL_STATION, |
| 10291 | .doit = nl80211_del_station, |
| 10292 | .policy = nl80211_policy, |
| 10293 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10294 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10295 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10296 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10297 | { |
| 10298 | .cmd = NL80211_CMD_GET_MPATH, |
| 10299 | .doit = nl80211_get_mpath, |
| 10300 | .dumpit = nl80211_dump_mpath, |
| 10301 | .policy = nl80211_policy, |
| 10302 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10303 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10304 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10305 | }, |
| 10306 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 10307 | .cmd = NL80211_CMD_GET_MPP, |
| 10308 | .doit = nl80211_get_mpp, |
| 10309 | .dumpit = nl80211_dump_mpp, |
| 10310 | .policy = nl80211_policy, |
| 10311 | .flags = GENL_ADMIN_PERM, |
| 10312 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10313 | NL80211_FLAG_NEED_RTNL, |
| 10314 | }, |
| 10315 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10316 | .cmd = NL80211_CMD_SET_MPATH, |
| 10317 | .doit = nl80211_set_mpath, |
| 10318 | .policy = nl80211_policy, |
| 10319 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10320 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10321 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10322 | }, |
| 10323 | { |
| 10324 | .cmd = NL80211_CMD_NEW_MPATH, |
| 10325 | .doit = nl80211_new_mpath, |
| 10326 | .policy = nl80211_policy, |
| 10327 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10328 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10329 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10330 | }, |
| 10331 | { |
| 10332 | .cmd = NL80211_CMD_DEL_MPATH, |
| 10333 | .doit = nl80211_del_mpath, |
| 10334 | .policy = nl80211_policy, |
| 10335 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10336 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10337 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10338 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 10339 | { |
| 10340 | .cmd = NL80211_CMD_SET_BSS, |
| 10341 | .doit = nl80211_set_bss, |
| 10342 | .policy = nl80211_policy, |
| 10343 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10344 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10345 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 10346 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10347 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 10348 | .cmd = NL80211_CMD_GET_REG, |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 10349 | .doit = nl80211_get_reg_do, |
| 10350 | .dumpit = nl80211_get_reg_dump, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 10351 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10352 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 10353 | /* can be retrieved by unprivileged users */ |
| 10354 | }, |
| 10355 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10356 | .cmd = NL80211_CMD_SET_REG, |
| 10357 | .doit = nl80211_set_reg, |
| 10358 | .policy = nl80211_policy, |
| 10359 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10360 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10361 | }, |
| 10362 | { |
| 10363 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 10364 | .doit = nl80211_req_set_reg, |
| 10365 | .policy = nl80211_policy, |
| 10366 | .flags = GENL_ADMIN_PERM, |
| 10367 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10368 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 10369 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 10370 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10371 | .policy = nl80211_policy, |
| 10372 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10373 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10374 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10375 | }, |
| 10376 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 10377 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 10378 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10379 | .policy = nl80211_policy, |
| 10380 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10381 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10382 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10383 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 10384 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10385 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 10386 | .doit = nl80211_trigger_scan, |
| 10387 | .policy = nl80211_policy, |
| 10388 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10389 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10390 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10391 | }, |
| 10392 | { |
| 10393 | .cmd = NL80211_CMD_GET_SCAN, |
| 10394 | .policy = nl80211_policy, |
| 10395 | .dumpit = nl80211_dump_scan, |
| 10396 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10397 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10398 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 10399 | .doit = nl80211_start_sched_scan, |
| 10400 | .policy = nl80211_policy, |
| 10401 | .flags = GENL_ADMIN_PERM, |
| 10402 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10403 | NL80211_FLAG_NEED_RTNL, |
| 10404 | }, |
| 10405 | { |
| 10406 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 10407 | .doit = nl80211_stop_sched_scan, |
| 10408 | .policy = nl80211_policy, |
| 10409 | .flags = GENL_ADMIN_PERM, |
| 10410 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10411 | NL80211_FLAG_NEED_RTNL, |
| 10412 | }, |
| 10413 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10414 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 10415 | .doit = nl80211_authenticate, |
| 10416 | .policy = nl80211_policy, |
| 10417 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10418 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10419 | NL80211_FLAG_NEED_RTNL | |
| 10420 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10421 | }, |
| 10422 | { |
| 10423 | .cmd = NL80211_CMD_ASSOCIATE, |
| 10424 | .doit = nl80211_associate, |
| 10425 | .policy = nl80211_policy, |
| 10426 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10427 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10428 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10429 | }, |
| 10430 | { |
| 10431 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 10432 | .doit = nl80211_deauthenticate, |
| 10433 | .policy = nl80211_policy, |
| 10434 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10435 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10436 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10437 | }, |
| 10438 | { |
| 10439 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 10440 | .doit = nl80211_disassociate, |
| 10441 | .policy = nl80211_policy, |
| 10442 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10443 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10444 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10445 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10446 | { |
| 10447 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 10448 | .doit = nl80211_join_ibss, |
| 10449 | .policy = nl80211_policy, |
| 10450 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10451 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10452 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10453 | }, |
| 10454 | { |
| 10455 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 10456 | .doit = nl80211_leave_ibss, |
| 10457 | .policy = nl80211_policy, |
| 10458 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10459 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10460 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10461 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10462 | #ifdef CONFIG_NL80211_TESTMODE |
| 10463 | { |
| 10464 | .cmd = NL80211_CMD_TESTMODE, |
| 10465 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10466 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10467 | .policy = nl80211_policy, |
| 10468 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10469 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10470 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10471 | }, |
| 10472 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10473 | { |
| 10474 | .cmd = NL80211_CMD_CONNECT, |
| 10475 | .doit = nl80211_connect, |
| 10476 | .policy = nl80211_policy, |
| 10477 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10478 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10479 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10480 | }, |
| 10481 | { |
| 10482 | .cmd = NL80211_CMD_DISCONNECT, |
| 10483 | .doit = nl80211_disconnect, |
| 10484 | .policy = nl80211_policy, |
| 10485 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10486 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10487 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10488 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10489 | { |
| 10490 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 10491 | .doit = nl80211_wiphy_netns, |
| 10492 | .policy = nl80211_policy, |
| 10493 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10494 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10495 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10496 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 10497 | { |
| 10498 | .cmd = NL80211_CMD_GET_SURVEY, |
| 10499 | .policy = nl80211_policy, |
| 10500 | .dumpit = nl80211_dump_survey, |
| 10501 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10502 | { |
| 10503 | .cmd = NL80211_CMD_SET_PMKSA, |
| 10504 | .doit = nl80211_setdel_pmksa, |
| 10505 | .policy = nl80211_policy, |
| 10506 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10507 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10508 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10509 | }, |
| 10510 | { |
| 10511 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 10512 | .doit = nl80211_setdel_pmksa, |
| 10513 | .policy = nl80211_policy, |
| 10514 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10515 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10516 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10517 | }, |
| 10518 | { |
| 10519 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 10520 | .doit = nl80211_flush_pmksa, |
| 10521 | .policy = nl80211_policy, |
| 10522 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10523 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10524 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10525 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10526 | { |
| 10527 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 10528 | .doit = nl80211_remain_on_channel, |
| 10529 | .policy = nl80211_policy, |
| 10530 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10531 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10532 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10533 | }, |
| 10534 | { |
| 10535 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 10536 | .doit = nl80211_cancel_remain_on_channel, |
| 10537 | .policy = nl80211_policy, |
| 10538 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10539 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10540 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10541 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10542 | { |
| 10543 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 10544 | .doit = nl80211_set_tx_bitrate_mask, |
| 10545 | .policy = nl80211_policy, |
| 10546 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10547 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10548 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10549 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10550 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10551 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 10552 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10553 | .policy = nl80211_policy, |
| 10554 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10555 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10556 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10557 | }, |
| 10558 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10559 | .cmd = NL80211_CMD_FRAME, |
| 10560 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10561 | .policy = nl80211_policy, |
| 10562 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10563 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10564 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10565 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10566 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10567 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 10568 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 10569 | .policy = nl80211_policy, |
| 10570 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10571 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10572 | NL80211_FLAG_NEED_RTNL, |
| 10573 | }, |
| 10574 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10575 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 10576 | .doit = nl80211_set_power_save, |
| 10577 | .policy = nl80211_policy, |
| 10578 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10579 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10580 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10581 | }, |
| 10582 | { |
| 10583 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 10584 | .doit = nl80211_get_power_save, |
| 10585 | .policy = nl80211_policy, |
| 10586 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10587 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10588 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10589 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10590 | { |
| 10591 | .cmd = NL80211_CMD_SET_CQM, |
| 10592 | .doit = nl80211_set_cqm, |
| 10593 | .policy = nl80211_policy, |
| 10594 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10595 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10596 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10597 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 10598 | { |
| 10599 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 10600 | .doit = nl80211_set_channel, |
| 10601 | .policy = nl80211_policy, |
| 10602 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10603 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10604 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 10605 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 10606 | { |
| 10607 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 10608 | .doit = nl80211_set_wds_peer, |
| 10609 | .policy = nl80211_policy, |
| 10610 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 10611 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10612 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 10613 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10614 | { |
| 10615 | .cmd = NL80211_CMD_JOIN_MESH, |
| 10616 | .doit = nl80211_join_mesh, |
| 10617 | .policy = nl80211_policy, |
| 10618 | .flags = GENL_ADMIN_PERM, |
| 10619 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10620 | NL80211_FLAG_NEED_RTNL, |
| 10621 | }, |
| 10622 | { |
| 10623 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 10624 | .doit = nl80211_leave_mesh, |
| 10625 | .policy = nl80211_policy, |
| 10626 | .flags = GENL_ADMIN_PERM, |
| 10627 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10628 | NL80211_FLAG_NEED_RTNL, |
| 10629 | }, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 10630 | { |
| 10631 | .cmd = NL80211_CMD_JOIN_OCB, |
| 10632 | .doit = nl80211_join_ocb, |
| 10633 | .policy = nl80211_policy, |
| 10634 | .flags = GENL_ADMIN_PERM, |
| 10635 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10636 | NL80211_FLAG_NEED_RTNL, |
| 10637 | }, |
| 10638 | { |
| 10639 | .cmd = NL80211_CMD_LEAVE_OCB, |
| 10640 | .doit = nl80211_leave_ocb, |
| 10641 | .policy = nl80211_policy, |
| 10642 | .flags = GENL_ADMIN_PERM, |
| 10643 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10644 | NL80211_FLAG_NEED_RTNL, |
| 10645 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10646 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10647 | { |
| 10648 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 10649 | .doit = nl80211_get_wowlan, |
| 10650 | .policy = nl80211_policy, |
| 10651 | /* can be retrieved by unprivileged users */ |
| 10652 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10653 | NL80211_FLAG_NEED_RTNL, |
| 10654 | }, |
| 10655 | { |
| 10656 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 10657 | .doit = nl80211_set_wowlan, |
| 10658 | .policy = nl80211_policy, |
| 10659 | .flags = GENL_ADMIN_PERM, |
| 10660 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10661 | NL80211_FLAG_NEED_RTNL, |
| 10662 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10663 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10664 | { |
| 10665 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 10666 | .doit = nl80211_set_rekey_data, |
| 10667 | .policy = nl80211_policy, |
| 10668 | .flags = GENL_ADMIN_PERM, |
| 10669 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10670 | NL80211_FLAG_NEED_RTNL | |
| 10671 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10672 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10673 | { |
| 10674 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 10675 | .doit = nl80211_tdls_mgmt, |
| 10676 | .policy = nl80211_policy, |
| 10677 | .flags = GENL_ADMIN_PERM, |
| 10678 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10679 | NL80211_FLAG_NEED_RTNL, |
| 10680 | }, |
| 10681 | { |
| 10682 | .cmd = NL80211_CMD_TDLS_OPER, |
| 10683 | .doit = nl80211_tdls_oper, |
| 10684 | .policy = nl80211_policy, |
| 10685 | .flags = GENL_ADMIN_PERM, |
| 10686 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10687 | NL80211_FLAG_NEED_RTNL, |
| 10688 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10689 | { |
| 10690 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 10691 | .doit = nl80211_register_unexpected_frame, |
| 10692 | .policy = nl80211_policy, |
| 10693 | .flags = GENL_ADMIN_PERM, |
| 10694 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10695 | NL80211_FLAG_NEED_RTNL, |
| 10696 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10697 | { |
| 10698 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 10699 | .doit = nl80211_probe_client, |
| 10700 | .policy = nl80211_policy, |
| 10701 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10702 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10703 | NL80211_FLAG_NEED_RTNL, |
| 10704 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10705 | { |
| 10706 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 10707 | .doit = nl80211_register_beacons, |
| 10708 | .policy = nl80211_policy, |
| 10709 | .flags = GENL_ADMIN_PERM, |
| 10710 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10711 | NL80211_FLAG_NEED_RTNL, |
| 10712 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 10713 | { |
| 10714 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 10715 | .doit = nl80211_set_noack_map, |
| 10716 | .policy = nl80211_policy, |
| 10717 | .flags = GENL_ADMIN_PERM, |
| 10718 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10719 | NL80211_FLAG_NEED_RTNL, |
| 10720 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10721 | { |
| 10722 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 10723 | .doit = nl80211_start_p2p_device, |
| 10724 | .policy = nl80211_policy, |
| 10725 | .flags = GENL_ADMIN_PERM, |
| 10726 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 10727 | NL80211_FLAG_NEED_RTNL, |
| 10728 | }, |
| 10729 | { |
| 10730 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 10731 | .doit = nl80211_stop_p2p_device, |
| 10732 | .policy = nl80211_policy, |
| 10733 | .flags = GENL_ADMIN_PERM, |
| 10734 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10735 | NL80211_FLAG_NEED_RTNL, |
| 10736 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10737 | { |
| 10738 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 10739 | .doit = nl80211_set_mcast_rate, |
| 10740 | .policy = nl80211_policy, |
| 10741 | .flags = GENL_ADMIN_PERM, |
| 10742 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10743 | NL80211_FLAG_NEED_RTNL, |
| 10744 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 10745 | { |
| 10746 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 10747 | .doit = nl80211_set_mac_acl, |
| 10748 | .policy = nl80211_policy, |
| 10749 | .flags = GENL_ADMIN_PERM, |
| 10750 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10751 | NL80211_FLAG_NEED_RTNL, |
| 10752 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10753 | { |
| 10754 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 10755 | .doit = nl80211_start_radar_detection, |
| 10756 | .policy = nl80211_policy, |
| 10757 | .flags = GENL_ADMIN_PERM, |
| 10758 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10759 | NL80211_FLAG_NEED_RTNL, |
| 10760 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 10761 | { |
| 10762 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 10763 | .doit = nl80211_get_protocol_features, |
| 10764 | .policy = nl80211_policy, |
| 10765 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10766 | { |
| 10767 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 10768 | .doit = nl80211_update_ft_ies, |
| 10769 | .policy = nl80211_policy, |
| 10770 | .flags = GENL_ADMIN_PERM, |
| 10771 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10772 | NL80211_FLAG_NEED_RTNL, |
| 10773 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 10774 | { |
| 10775 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 10776 | .doit = nl80211_crit_protocol_start, |
| 10777 | .policy = nl80211_policy, |
| 10778 | .flags = GENL_ADMIN_PERM, |
| 10779 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10780 | NL80211_FLAG_NEED_RTNL, |
| 10781 | }, |
| 10782 | { |
| 10783 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 10784 | .doit = nl80211_crit_protocol_stop, |
| 10785 | .policy = nl80211_policy, |
| 10786 | .flags = GENL_ADMIN_PERM, |
| 10787 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10788 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10789 | }, |
| 10790 | { |
| 10791 | .cmd = NL80211_CMD_GET_COALESCE, |
| 10792 | .doit = nl80211_get_coalesce, |
| 10793 | .policy = nl80211_policy, |
| 10794 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10795 | NL80211_FLAG_NEED_RTNL, |
| 10796 | }, |
| 10797 | { |
| 10798 | .cmd = NL80211_CMD_SET_COALESCE, |
| 10799 | .doit = nl80211_set_coalesce, |
| 10800 | .policy = nl80211_policy, |
| 10801 | .flags = GENL_ADMIN_PERM, |
| 10802 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10803 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 10804 | }, |
| 10805 | { |
| 10806 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 10807 | .doit = nl80211_channel_switch, |
| 10808 | .policy = nl80211_policy, |
| 10809 | .flags = GENL_ADMIN_PERM, |
| 10810 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10811 | NL80211_FLAG_NEED_RTNL, |
| 10812 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10813 | { |
| 10814 | .cmd = NL80211_CMD_VENDOR, |
| 10815 | .doit = nl80211_vendor_cmd, |
| 10816 | .policy = nl80211_policy, |
| 10817 | .flags = GENL_ADMIN_PERM, |
| 10818 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10819 | NL80211_FLAG_NEED_RTNL, |
| 10820 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 10821 | { |
| 10822 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 10823 | .doit = nl80211_set_qos_map, |
| 10824 | .policy = nl80211_policy, |
| 10825 | .flags = GENL_ADMIN_PERM, |
| 10826 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10827 | NL80211_FLAG_NEED_RTNL, |
| 10828 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10829 | { |
| 10830 | .cmd = NL80211_CMD_ADD_TX_TS, |
| 10831 | .doit = nl80211_add_tx_ts, |
| 10832 | .policy = nl80211_policy, |
| 10833 | .flags = GENL_ADMIN_PERM, |
| 10834 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10835 | NL80211_FLAG_NEED_RTNL, |
| 10836 | }, |
| 10837 | { |
| 10838 | .cmd = NL80211_CMD_DEL_TX_TS, |
| 10839 | .doit = nl80211_del_tx_ts, |
| 10840 | .policy = nl80211_policy, |
| 10841 | .flags = GENL_ADMIN_PERM, |
| 10842 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10843 | NL80211_FLAG_NEED_RTNL, |
| 10844 | }, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 10845 | { |
| 10846 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, |
| 10847 | .doit = nl80211_tdls_channel_switch, |
| 10848 | .policy = nl80211_policy, |
| 10849 | .flags = GENL_ADMIN_PERM, |
| 10850 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10851 | NL80211_FLAG_NEED_RTNL, |
| 10852 | }, |
| 10853 | { |
| 10854 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, |
| 10855 | .doit = nl80211_tdls_cancel_channel_switch, |
| 10856 | .policy = nl80211_policy, |
| 10857 | .flags = GENL_ADMIN_PERM, |
| 10858 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10859 | NL80211_FLAG_NEED_RTNL, |
| 10860 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10861 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10862 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10863 | /* notification functions */ |
| 10864 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10865 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 10866 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10867 | { |
| 10868 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 10869 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10870 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10871 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 10872 | cmd != NL80211_CMD_DEL_WIPHY); |
| 10873 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10874 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10875 | if (!msg) |
| 10876 | return; |
| 10877 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10878 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10879 | nlmsg_free(msg); |
| 10880 | return; |
| 10881 | } |
| 10882 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10883 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10884 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10885 | } |
| 10886 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10887 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 10888 | struct cfg80211_registered_device *rdev) |
| 10889 | { |
| 10890 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 10891 | struct nlattr *nest; |
| 10892 | int i; |
| 10893 | |
| 10894 | if (WARN_ON(!req)) |
| 10895 | return 0; |
| 10896 | |
| 10897 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 10898 | if (!nest) |
| 10899 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10900 | for (i = 0; i < req->n_ssids; i++) { |
| 10901 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 10902 | goto nla_put_failure; |
| 10903 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10904 | nla_nest_end(msg, nest); |
| 10905 | |
| 10906 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 10907 | if (!nest) |
| 10908 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10909 | for (i = 0; i < req->n_channels; i++) { |
| 10910 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 10911 | goto nla_put_failure; |
| 10912 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10913 | nla_nest_end(msg, nest); |
| 10914 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10915 | if (req->ie && |
| 10916 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 10917 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10918 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 10919 | if (req->flags && |
| 10920 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 10921 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 10922 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10923 | return 0; |
| 10924 | nla_put_failure: |
| 10925 | return -ENOBUFS; |
| 10926 | } |
| 10927 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10928 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 10929 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10930 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10931 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10932 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10933 | { |
| 10934 | void *hdr; |
| 10935 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10936 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10937 | if (!hdr) |
| 10938 | return -1; |
| 10939 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10940 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10941 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10942 | wdev->netdev->ifindex)) || |
| 10943 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10944 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10945 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10946 | /* ignore errors and send incomplete event anyway */ |
| 10947 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10948 | |
| 10949 | return genlmsg_end(msg, hdr); |
| 10950 | |
| 10951 | nla_put_failure: |
| 10952 | genlmsg_cancel(msg, hdr); |
| 10953 | return -EMSGSIZE; |
| 10954 | } |
| 10955 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10956 | static int |
| 10957 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 10958 | struct cfg80211_registered_device *rdev, |
| 10959 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10960 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10961 | { |
| 10962 | void *hdr; |
| 10963 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10964 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10965 | if (!hdr) |
| 10966 | return -1; |
| 10967 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10968 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10969 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10970 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10971 | |
| 10972 | return genlmsg_end(msg, hdr); |
| 10973 | |
| 10974 | nla_put_failure: |
| 10975 | genlmsg_cancel(msg, hdr); |
| 10976 | return -EMSGSIZE; |
| 10977 | } |
| 10978 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10979 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10980 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10981 | { |
| 10982 | struct sk_buff *msg; |
| 10983 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10984 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10985 | if (!msg) |
| 10986 | return; |
| 10987 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10988 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10989 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 10990 | nlmsg_free(msg); |
| 10991 | return; |
| 10992 | } |
| 10993 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10994 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10995 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10996 | } |
| 10997 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10998 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 10999 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11000 | { |
| 11001 | struct sk_buff *msg; |
| 11002 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11003 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11004 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11005 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11006 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 11007 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11008 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 11009 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11010 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11011 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11012 | } |
| 11013 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11014 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11015 | } |
| 11016 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 11017 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
| 11018 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11019 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11020 | if (!msg) |
| 11021 | return; |
| 11022 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11023 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11024 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11025 | } |
| 11026 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11027 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 11028 | struct net_device *netdev) |
| 11029 | { |
| 11030 | struct sk_buff *msg; |
| 11031 | |
| 11032 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11033 | if (!msg) |
| 11034 | return; |
| 11035 | |
| 11036 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 11037 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 11038 | nlmsg_free(msg); |
| 11039 | return; |
| 11040 | } |
| 11041 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11042 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11043 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11044 | } |
| 11045 | |
| 11046 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 11047 | struct net_device *netdev, u32 cmd) |
| 11048 | { |
| 11049 | struct sk_buff *msg; |
| 11050 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11051 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11052 | if (!msg) |
| 11053 | return; |
| 11054 | |
| 11055 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 11056 | nlmsg_free(msg); |
| 11057 | return; |
| 11058 | } |
| 11059 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11060 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11061 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11062 | } |
| 11063 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 11064 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
| 11065 | struct regulatory_request *request) |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11066 | { |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11067 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11068 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 11069 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11070 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11071 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 11072 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 11073 | NL80211_REGDOM_TYPE_WORLD)) |
| 11074 | goto nla_put_failure; |
| 11075 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 11076 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 11077 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 11078 | goto nla_put_failure; |
| 11079 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 11080 | request->intersect) { |
| 11081 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 11082 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 11083 | goto nla_put_failure; |
| 11084 | } else { |
| 11085 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 11086 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 11087 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 11088 | request->alpha2)) |
| 11089 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11090 | } |
| 11091 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 11092 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
| 11093 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); |
| 11094 | |
| 11095 | if (wiphy && |
| 11096 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 11097 | goto nla_put_failure; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame^] | 11098 | |
| 11099 | if (wiphy && |
| 11100 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 11101 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 11102 | goto nla_put_failure; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 11103 | } |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11104 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 11105 | return true; |
| 11106 | |
| 11107 | nla_put_failure: |
| 11108 | return false; |
| 11109 | } |
| 11110 | |
| 11111 | /* |
| 11112 | * This can happen on global regulatory changes or device specific settings |
| 11113 | * based on custom regulatory domains. |
| 11114 | */ |
| 11115 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, |
| 11116 | struct regulatory_request *request) |
| 11117 | { |
| 11118 | struct sk_buff *msg; |
| 11119 | void *hdr; |
| 11120 | |
| 11121 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11122 | if (!msg) |
| 11123 | return; |
| 11124 | |
| 11125 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); |
| 11126 | if (!hdr) { |
| 11127 | nlmsg_free(msg); |
| 11128 | return; |
| 11129 | } |
| 11130 | |
| 11131 | if (nl80211_reg_change_event_fill(msg, request) == false) |
| 11132 | goto nla_put_failure; |
| 11133 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11134 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11135 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 11136 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11137 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11138 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 11139 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11140 | |
| 11141 | return; |
| 11142 | |
| 11143 | nla_put_failure: |
| 11144 | genlmsg_cancel(msg, hdr); |
| 11145 | nlmsg_free(msg); |
| 11146 | } |
| 11147 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11148 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 11149 | struct net_device *netdev, |
| 11150 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11151 | enum nl80211_commands cmd, gfp_t gfp, |
| 11152 | int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11153 | { |
| 11154 | struct sk_buff *msg; |
| 11155 | void *hdr; |
| 11156 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11157 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11158 | if (!msg) |
| 11159 | return; |
| 11160 | |
| 11161 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 11162 | if (!hdr) { |
| 11163 | nlmsg_free(msg); |
| 11164 | return; |
| 11165 | } |
| 11166 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11167 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11168 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11169 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 11170 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11171 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11172 | if (uapsd_queues >= 0) { |
| 11173 | struct nlattr *nla_wmm = |
| 11174 | nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 11175 | if (!nla_wmm) |
| 11176 | goto nla_put_failure; |
| 11177 | |
| 11178 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 11179 | uapsd_queues)) |
| 11180 | goto nla_put_failure; |
| 11181 | |
| 11182 | nla_nest_end(msg, nla_wmm); |
| 11183 | } |
| 11184 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11185 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11186 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11187 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11188 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11189 | return; |
| 11190 | |
| 11191 | nla_put_failure: |
| 11192 | genlmsg_cancel(msg, hdr); |
| 11193 | nlmsg_free(msg); |
| 11194 | } |
| 11195 | |
| 11196 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11197 | struct net_device *netdev, const u8 *buf, |
| 11198 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11199 | { |
| 11200 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11201 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11202 | } |
| 11203 | |
| 11204 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 11205 | struct net_device *netdev, const u8 *buf, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11206 | size_t len, gfp_t gfp, int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11207 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11208 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11209 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11210 | } |
| 11211 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 11212 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11213 | struct net_device *netdev, const u8 *buf, |
| 11214 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11215 | { |
| 11216 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11217 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11218 | } |
| 11219 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 11220 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 11221 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11222 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11223 | { |
| 11224 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11225 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11226 | } |
| 11227 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11228 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 11229 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11230 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11231 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11232 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11233 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11234 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 11235 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11236 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11237 | if (WARN_ON(len < 2)) |
| 11238 | return; |
| 11239 | |
| 11240 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 11241 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 11242 | else |
| 11243 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 11244 | |
| 11245 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11246 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11247 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11248 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11249 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 11250 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 11251 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11252 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11253 | { |
| 11254 | struct sk_buff *msg; |
| 11255 | void *hdr; |
| 11256 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11257 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11258 | if (!msg) |
| 11259 | return; |
| 11260 | |
| 11261 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 11262 | if (!hdr) { |
| 11263 | nlmsg_free(msg); |
| 11264 | return; |
| 11265 | } |
| 11266 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11267 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11268 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11269 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 11270 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 11271 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11272 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11273 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11274 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11275 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11276 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11277 | return; |
| 11278 | |
| 11279 | nla_put_failure: |
| 11280 | genlmsg_cancel(msg, hdr); |
| 11281 | nlmsg_free(msg); |
| 11282 | } |
| 11283 | |
| 11284 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11285 | struct net_device *netdev, const u8 *addr, |
| 11286 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11287 | { |
| 11288 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11289 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11290 | } |
| 11291 | |
| 11292 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11293 | struct net_device *netdev, const u8 *addr, |
| 11294 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11295 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11296 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 11297 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11298 | } |
| 11299 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11300 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 11301 | struct net_device *netdev, const u8 *bssid, |
| 11302 | const u8 *req_ie, size_t req_ie_len, |
| 11303 | const u8 *resp_ie, size_t resp_ie_len, |
| 11304 | u16 status, gfp_t gfp) |
| 11305 | { |
| 11306 | struct sk_buff *msg; |
| 11307 | void *hdr; |
| 11308 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11309 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11310 | if (!msg) |
| 11311 | return; |
| 11312 | |
| 11313 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 11314 | if (!hdr) { |
| 11315 | nlmsg_free(msg); |
| 11316 | return; |
| 11317 | } |
| 11318 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11319 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11320 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11321 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 11322 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 11323 | (req_ie && |
| 11324 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 11325 | (resp_ie && |
| 11326 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 11327 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11328 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11329 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11330 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11331 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11332 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11333 | return; |
| 11334 | |
| 11335 | nla_put_failure: |
| 11336 | genlmsg_cancel(msg, hdr); |
| 11337 | nlmsg_free(msg); |
| 11338 | |
| 11339 | } |
| 11340 | |
| 11341 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 11342 | struct net_device *netdev, const u8 *bssid, |
| 11343 | const u8 *req_ie, size_t req_ie_len, |
| 11344 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 11345 | { |
| 11346 | struct sk_buff *msg; |
| 11347 | void *hdr; |
| 11348 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11349 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11350 | if (!msg) |
| 11351 | return; |
| 11352 | |
| 11353 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 11354 | if (!hdr) { |
| 11355 | nlmsg_free(msg); |
| 11356 | return; |
| 11357 | } |
| 11358 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11359 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11360 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11361 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 11362 | (req_ie && |
| 11363 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 11364 | (resp_ie && |
| 11365 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 11366 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11367 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11368 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11369 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11370 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11371 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11372 | return; |
| 11373 | |
| 11374 | nla_put_failure: |
| 11375 | genlmsg_cancel(msg, hdr); |
| 11376 | nlmsg_free(msg); |
| 11377 | |
| 11378 | } |
| 11379 | |
| 11380 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 11381 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 11382 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11383 | { |
| 11384 | struct sk_buff *msg; |
| 11385 | void *hdr; |
| 11386 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11387 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11388 | if (!msg) |
| 11389 | return; |
| 11390 | |
| 11391 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 11392 | if (!hdr) { |
| 11393 | nlmsg_free(msg); |
| 11394 | return; |
| 11395 | } |
| 11396 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11397 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11398 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11399 | (from_ap && reason && |
| 11400 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 11401 | (from_ap && |
| 11402 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 11403 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 11404 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11405 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11406 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11407 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11408 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11409 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11410 | return; |
| 11411 | |
| 11412 | nla_put_failure: |
| 11413 | genlmsg_cancel(msg, hdr); |
| 11414 | nlmsg_free(msg); |
| 11415 | |
| 11416 | } |
| 11417 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11418 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 11419 | struct net_device *netdev, const u8 *bssid, |
| 11420 | gfp_t gfp) |
| 11421 | { |
| 11422 | struct sk_buff *msg; |
| 11423 | void *hdr; |
| 11424 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11425 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11426 | if (!msg) |
| 11427 | return; |
| 11428 | |
| 11429 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 11430 | if (!hdr) { |
| 11431 | nlmsg_free(msg); |
| 11432 | return; |
| 11433 | } |
| 11434 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11435 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11436 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11437 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 11438 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11439 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11440 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11441 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11442 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11443 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11444 | return; |
| 11445 | |
| 11446 | nla_put_failure: |
| 11447 | genlmsg_cancel(msg, hdr); |
| 11448 | nlmsg_free(msg); |
| 11449 | } |
| 11450 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11451 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 11452 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11453 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11454 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11455 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11456 | struct sk_buff *msg; |
| 11457 | void *hdr; |
| 11458 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11459 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 11460 | return; |
| 11461 | |
| 11462 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 11463 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11464 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11465 | if (!msg) |
| 11466 | return; |
| 11467 | |
| 11468 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 11469 | if (!hdr) { |
| 11470 | nlmsg_free(msg); |
| 11471 | return; |
| 11472 | } |
| 11473 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11474 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11475 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11476 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11477 | (ie_len && ie && |
| 11478 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 11479 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11480 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11481 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11482 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11483 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11484 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11485 | return; |
| 11486 | |
| 11487 | nla_put_failure: |
| 11488 | genlmsg_cancel(msg, hdr); |
| 11489 | nlmsg_free(msg); |
| 11490 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11491 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11492 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11493 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 11494 | struct net_device *netdev, const u8 *addr, |
| 11495 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11496 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11497 | { |
| 11498 | struct sk_buff *msg; |
| 11499 | void *hdr; |
| 11500 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11501 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11502 | if (!msg) |
| 11503 | return; |
| 11504 | |
| 11505 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 11506 | if (!hdr) { |
| 11507 | nlmsg_free(msg); |
| 11508 | return; |
| 11509 | } |
| 11510 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11511 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11512 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11513 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 11514 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 11515 | (key_id != -1 && |
| 11516 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 11517 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 11518 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11519 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11520 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11521 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11522 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11523 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11524 | return; |
| 11525 | |
| 11526 | nla_put_failure: |
| 11527 | genlmsg_cancel(msg, hdr); |
| 11528 | nlmsg_free(msg); |
| 11529 | } |
| 11530 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11531 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 11532 | struct ieee80211_channel *channel_before, |
| 11533 | struct ieee80211_channel *channel_after) |
| 11534 | { |
| 11535 | struct sk_buff *msg; |
| 11536 | void *hdr; |
| 11537 | struct nlattr *nl_freq; |
| 11538 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11539 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11540 | if (!msg) |
| 11541 | return; |
| 11542 | |
| 11543 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 11544 | if (!hdr) { |
| 11545 | nlmsg_free(msg); |
| 11546 | return; |
| 11547 | } |
| 11548 | |
| 11549 | /* |
| 11550 | * Since we are applying the beacon hint to a wiphy we know its |
| 11551 | * wiphy_idx is valid |
| 11552 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11553 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 11554 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11555 | |
| 11556 | /* Before */ |
| 11557 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 11558 | if (!nl_freq) |
| 11559 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 11560 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11561 | goto nla_put_failure; |
| 11562 | nla_nest_end(msg, nl_freq); |
| 11563 | |
| 11564 | /* After */ |
| 11565 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 11566 | if (!nl_freq) |
| 11567 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 11568 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11569 | goto nla_put_failure; |
| 11570 | nla_nest_end(msg, nl_freq); |
| 11571 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11572 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11573 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11574 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11575 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11576 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11577 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11578 | |
| 11579 | return; |
| 11580 | |
| 11581 | nla_put_failure: |
| 11582 | genlmsg_cancel(msg, hdr); |
| 11583 | nlmsg_free(msg); |
| 11584 | } |
| 11585 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11586 | static void nl80211_send_remain_on_chan_event( |
| 11587 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11588 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11589 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11590 | unsigned int duration, gfp_t gfp) |
| 11591 | { |
| 11592 | struct sk_buff *msg; |
| 11593 | void *hdr; |
| 11594 | |
| 11595 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11596 | if (!msg) |
| 11597 | return; |
| 11598 | |
| 11599 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 11600 | if (!hdr) { |
| 11601 | nlmsg_free(msg); |
| 11602 | return; |
| 11603 | } |
| 11604 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11605 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11606 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11607 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 11608 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11609 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11610 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 11611 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11612 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 11613 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11614 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11615 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 11616 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 11617 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11618 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11619 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11620 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11621 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11622 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11623 | return; |
| 11624 | |
| 11625 | nla_put_failure: |
| 11626 | genlmsg_cancel(msg, hdr); |
| 11627 | nlmsg_free(msg); |
| 11628 | } |
| 11629 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11630 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 11631 | struct ieee80211_channel *chan, |
| 11632 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11633 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11634 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11635 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11636 | |
| 11637 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11638 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11639 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11640 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11641 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11642 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11643 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11644 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 11645 | struct ieee80211_channel *chan, |
| 11646 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11647 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11648 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11649 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11650 | |
| 11651 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11652 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11653 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11654 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11655 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11656 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11657 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 11658 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11659 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11660 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11661 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11662 | struct sk_buff *msg; |
| 11663 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11664 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 11665 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11666 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11667 | if (!msg) |
| 11668 | return; |
| 11669 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 11670 | if (nl80211_send_station(msg, 0, 0, 0, |
| 11671 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11672 | nlmsg_free(msg); |
| 11673 | return; |
| 11674 | } |
| 11675 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11676 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11677 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11678 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11679 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11680 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11681 | void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp) |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11682 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11683 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11684 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11685 | struct sk_buff *msg; |
| 11686 | void *hdr; |
| 11687 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11688 | trace_cfg80211_del_sta(dev, mac_addr); |
| 11689 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11690 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11691 | if (!msg) |
| 11692 | return; |
| 11693 | |
| 11694 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 11695 | if (!hdr) { |
| 11696 | nlmsg_free(msg); |
| 11697 | return; |
| 11698 | } |
| 11699 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11700 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11701 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 11702 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11703 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11704 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11705 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11706 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11707 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11708 | return; |
| 11709 | |
| 11710 | nla_put_failure: |
| 11711 | genlmsg_cancel(msg, hdr); |
| 11712 | nlmsg_free(msg); |
| 11713 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11714 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11715 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11716 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 11717 | enum nl80211_connect_failed_reason reason, |
| 11718 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11719 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11720 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11721 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11722 | struct sk_buff *msg; |
| 11723 | void *hdr; |
| 11724 | |
| 11725 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 11726 | if (!msg) |
| 11727 | return; |
| 11728 | |
| 11729 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 11730 | if (!hdr) { |
| 11731 | nlmsg_free(msg); |
| 11732 | return; |
| 11733 | } |
| 11734 | |
| 11735 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11736 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 11737 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 11738 | goto nla_put_failure; |
| 11739 | |
| 11740 | genlmsg_end(msg, hdr); |
| 11741 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11742 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11743 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11744 | return; |
| 11745 | |
| 11746 | nla_put_failure: |
| 11747 | genlmsg_cancel(msg, hdr); |
| 11748 | nlmsg_free(msg); |
| 11749 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11750 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11751 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11752 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 11753 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11754 | { |
| 11755 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11756 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11757 | struct sk_buff *msg; |
| 11758 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11759 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11760 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11761 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11762 | return false; |
| 11763 | |
| 11764 | msg = nlmsg_new(100, gfp); |
| 11765 | if (!msg) |
| 11766 | return true; |
| 11767 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11768 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11769 | if (!hdr) { |
| 11770 | nlmsg_free(msg); |
| 11771 | return true; |
| 11772 | } |
| 11773 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11774 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11775 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11776 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 11777 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11778 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11779 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11780 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11781 | return true; |
| 11782 | |
| 11783 | nla_put_failure: |
| 11784 | genlmsg_cancel(msg, hdr); |
| 11785 | nlmsg_free(msg); |
| 11786 | return true; |
| 11787 | } |
| 11788 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11789 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 11790 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11791 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11792 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11793 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11794 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11795 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 11796 | |
| 11797 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 11798 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 11799 | trace_cfg80211_return_bool(false); |
| 11800 | return false; |
| 11801 | } |
| 11802 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 11803 | addr, gfp); |
| 11804 | trace_cfg80211_return_bool(ret); |
| 11805 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11806 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11807 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 11808 | |
| 11809 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 11810 | const u8 *addr, gfp_t gfp) |
| 11811 | { |
| 11812 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11813 | bool ret; |
| 11814 | |
| 11815 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 11816 | |
| 11817 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 11818 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 11819 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 11820 | trace_cfg80211_return_bool(false); |
| 11821 | return false; |
| 11822 | } |
| 11823 | ret = __nl80211_unexpected_frame(dev, |
| 11824 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 11825 | addr, gfp); |
| 11826 | trace_cfg80211_return_bool(ret); |
| 11827 | return ret; |
| 11828 | } |
| 11829 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11830 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11831 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11832 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 11833 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 11834 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11835 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11836 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11837 | struct sk_buff *msg; |
| 11838 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11839 | |
| 11840 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11841 | if (!msg) |
| 11842 | return -ENOMEM; |
| 11843 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11844 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11845 | if (!hdr) { |
| 11846 | nlmsg_free(msg); |
| 11847 | return -ENOMEM; |
| 11848 | } |
| 11849 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11850 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11851 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11852 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 11853 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11854 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 11855 | (sig_dbm && |
| 11856 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 11857 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 11858 | (flags && |
| 11859 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11860 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11861 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11862 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11863 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11864 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11865 | |
| 11866 | nla_put_failure: |
| 11867 | genlmsg_cancel(msg, hdr); |
| 11868 | nlmsg_free(msg); |
| 11869 | return -ENOBUFS; |
| 11870 | } |
| 11871 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11872 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 11873 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11874 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11875 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11876 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11877 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11878 | struct sk_buff *msg; |
| 11879 | void *hdr; |
| 11880 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11881 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 11882 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11883 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11884 | if (!msg) |
| 11885 | return; |
| 11886 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11887 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11888 | if (!hdr) { |
| 11889 | nlmsg_free(msg); |
| 11890 | return; |
| 11891 | } |
| 11892 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11893 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11894 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11895 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 11896 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11897 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 11898 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11899 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11900 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11901 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11902 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11903 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11904 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11905 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11906 | return; |
| 11907 | |
| 11908 | nla_put_failure: |
| 11909 | genlmsg_cancel(msg, hdr); |
| 11910 | nlmsg_free(msg); |
| 11911 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11912 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11913 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11914 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
| 11915 | const char *mac, gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11916 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11917 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11918 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 11919 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11920 | void **cb; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11921 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11922 | if (!msg) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11923 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11924 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11925 | cb = (void **)msg->cb; |
| 11926 | |
| 11927 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11928 | if (!cb[0]) { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11929 | nlmsg_free(msg); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11930 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11931 | } |
| 11932 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11933 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11934 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11935 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11936 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11937 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11938 | goto nla_put_failure; |
| 11939 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11940 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11941 | if (!cb[1]) |
| 11942 | goto nla_put_failure; |
| 11943 | |
| 11944 | cb[2] = rdev; |
| 11945 | |
| 11946 | return msg; |
| 11947 | nla_put_failure: |
| 11948 | nlmsg_free(msg); |
| 11949 | return NULL; |
| 11950 | } |
| 11951 | |
| 11952 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) |
| 11953 | { |
| 11954 | void **cb = (void **)msg->cb; |
| 11955 | struct cfg80211_registered_device *rdev = cb[2]; |
| 11956 | |
| 11957 | nla_nest_end(msg, cb[1]); |
| 11958 | genlmsg_end(msg, cb[0]); |
| 11959 | |
| 11960 | memset(msg->cb, 0, sizeof(msg->cb)); |
| 11961 | |
| 11962 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 11963 | NL80211_MCGRP_MLME, gfp); |
| 11964 | } |
| 11965 | |
| 11966 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 11967 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 11968 | gfp_t gfp) |
| 11969 | { |
| 11970 | struct sk_buff *msg; |
| 11971 | |
| 11972 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 11973 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 11974 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
| 11975 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) |
| 11976 | return; |
| 11977 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11978 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 11979 | if (!msg) |
| 11980 | return; |
| 11981 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11982 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 11983 | rssi_event)) |
| 11984 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11985 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11986 | cfg80211_send_cqm(msg, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11987 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11988 | return; |
| 11989 | |
| 11990 | nla_put_failure: |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11991 | nlmsg_free(msg); |
| 11992 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11993 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11994 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11995 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 11996 | const u8 *peer, u32 num_packets, |
| 11997 | u32 rate, u32 intvl, gfp_t gfp) |
| 11998 | { |
| 11999 | struct sk_buff *msg; |
| 12000 | |
| 12001 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 12002 | if (!msg) |
| 12003 | return; |
| 12004 | |
| 12005 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 12006 | goto nla_put_failure; |
| 12007 | |
| 12008 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 12009 | goto nla_put_failure; |
| 12010 | |
| 12011 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 12012 | goto nla_put_failure; |
| 12013 | |
| 12014 | cfg80211_send_cqm(msg, gfp); |
| 12015 | return; |
| 12016 | |
| 12017 | nla_put_failure: |
| 12018 | nlmsg_free(msg); |
| 12019 | } |
| 12020 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
| 12021 | |
| 12022 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 12023 | const u8 *peer, u32 num_packets, gfp_t gfp) |
| 12024 | { |
| 12025 | struct sk_buff *msg; |
| 12026 | |
| 12027 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 12028 | |
| 12029 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 12030 | if (!msg) |
| 12031 | return; |
| 12032 | |
| 12033 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 12034 | goto nla_put_failure; |
| 12035 | |
| 12036 | cfg80211_send_cqm(msg, gfp); |
| 12037 | return; |
| 12038 | |
| 12039 | nla_put_failure: |
| 12040 | nlmsg_free(msg); |
| 12041 | } |
| 12042 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
| 12043 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 12044 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
| 12045 | { |
| 12046 | struct sk_buff *msg; |
| 12047 | |
| 12048 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 12049 | if (!msg) |
| 12050 | return; |
| 12051 | |
| 12052 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) |
| 12053 | goto nla_put_failure; |
| 12054 | |
| 12055 | cfg80211_send_cqm(msg, gfp); |
| 12056 | return; |
| 12057 | |
| 12058 | nla_put_failure: |
| 12059 | nlmsg_free(msg); |
| 12060 | } |
| 12061 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); |
| 12062 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12063 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 12064 | struct net_device *netdev, const u8 *bssid, |
| 12065 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12066 | { |
| 12067 | struct sk_buff *msg; |
| 12068 | struct nlattr *rekey_attr; |
| 12069 | void *hdr; |
| 12070 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12071 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12072 | if (!msg) |
| 12073 | return; |
| 12074 | |
| 12075 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 12076 | if (!hdr) { |
| 12077 | nlmsg_free(msg); |
| 12078 | return; |
| 12079 | } |
| 12080 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12081 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12082 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12083 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 12084 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12085 | |
| 12086 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 12087 | if (!rekey_attr) |
| 12088 | goto nla_put_failure; |
| 12089 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12090 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 12091 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 12092 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12093 | |
| 12094 | nla_nest_end(msg, rekey_attr); |
| 12095 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12096 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12097 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12098 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12099 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12100 | return; |
| 12101 | |
| 12102 | nla_put_failure: |
| 12103 | genlmsg_cancel(msg, hdr); |
| 12104 | nlmsg_free(msg); |
| 12105 | } |
| 12106 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12107 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 12108 | const u8 *replay_ctr, gfp_t gfp) |
| 12109 | { |
| 12110 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12111 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12112 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12113 | |
| 12114 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 12115 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 12116 | } |
| 12117 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 12118 | |
| 12119 | static void |
| 12120 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 12121 | struct net_device *netdev, int index, |
| 12122 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12123 | { |
| 12124 | struct sk_buff *msg; |
| 12125 | struct nlattr *attr; |
| 12126 | void *hdr; |
| 12127 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12128 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12129 | if (!msg) |
| 12130 | return; |
| 12131 | |
| 12132 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 12133 | if (!hdr) { |
| 12134 | nlmsg_free(msg); |
| 12135 | return; |
| 12136 | } |
| 12137 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12138 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12139 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 12140 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12141 | |
| 12142 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 12143 | if (!attr) |
| 12144 | goto nla_put_failure; |
| 12145 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12146 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 12147 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 12148 | (preauth && |
| 12149 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 12150 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12151 | |
| 12152 | nla_nest_end(msg, attr); |
| 12153 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12154 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12155 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12156 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12157 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12158 | return; |
| 12159 | |
| 12160 | nla_put_failure: |
| 12161 | genlmsg_cancel(msg, hdr); |
| 12162 | nlmsg_free(msg); |
| 12163 | } |
| 12164 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12165 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 12166 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 12167 | { |
| 12168 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12169 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12170 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12171 | |
| 12172 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 12173 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 12174 | } |
| 12175 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 12176 | |
| 12177 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 12178 | struct net_device *netdev, |
| 12179 | struct cfg80211_chan_def *chandef, |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12180 | gfp_t gfp, |
| 12181 | enum nl80211_commands notif, |
| 12182 | u8 count) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12183 | { |
| 12184 | struct sk_buff *msg; |
| 12185 | void *hdr; |
| 12186 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12187 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12188 | if (!msg) |
| 12189 | return; |
| 12190 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12191 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12192 | if (!hdr) { |
| 12193 | nlmsg_free(msg); |
| 12194 | return; |
| 12195 | } |
| 12196 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 12197 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 12198 | goto nla_put_failure; |
| 12199 | |
| 12200 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 12201 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12202 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12203 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
| 12204 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) |
| 12205 | goto nla_put_failure; |
| 12206 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12207 | genlmsg_end(msg, hdr); |
| 12208 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12209 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12210 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12211 | return; |
| 12212 | |
| 12213 | nla_put_failure: |
| 12214 | genlmsg_cancel(msg, hdr); |
| 12215 | nlmsg_free(msg); |
| 12216 | } |
| 12217 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12218 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 12219 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 12220 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12221 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12222 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12223 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12224 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 12225 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12226 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 12227 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12228 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 12229 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 12230 | wdev->preset_chandef = *chandef; |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12231 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 12232 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12233 | } |
| 12234 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 12235 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12236 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
| 12237 | struct cfg80211_chan_def *chandef, |
| 12238 | u8 count) |
| 12239 | { |
| 12240 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12241 | struct wiphy *wiphy = wdev->wiphy; |
| 12242 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 12243 | |
| 12244 | trace_cfg80211_ch_switch_started_notify(dev, chandef); |
| 12245 | |
| 12246 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 12247 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); |
| 12248 | } |
| 12249 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); |
| 12250 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 12251 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12252 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 12253 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12254 | enum nl80211_radar_event event, |
| 12255 | struct net_device *netdev, gfp_t gfp) |
| 12256 | { |
| 12257 | struct sk_buff *msg; |
| 12258 | void *hdr; |
| 12259 | |
| 12260 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12261 | if (!msg) |
| 12262 | return; |
| 12263 | |
| 12264 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 12265 | if (!hdr) { |
| 12266 | nlmsg_free(msg); |
| 12267 | return; |
| 12268 | } |
| 12269 | |
| 12270 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 12271 | goto nla_put_failure; |
| 12272 | |
| 12273 | /* NOP and radar events don't need a netdev parameter */ |
| 12274 | if (netdev) { |
| 12275 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 12276 | |
| 12277 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12278 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12279 | goto nla_put_failure; |
| 12280 | } |
| 12281 | |
| 12282 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 12283 | goto nla_put_failure; |
| 12284 | |
| 12285 | if (nl80211_send_chandef(msg, chandef)) |
| 12286 | goto nla_put_failure; |
| 12287 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12288 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12289 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12290 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12291 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12292 | return; |
| 12293 | |
| 12294 | nla_put_failure: |
| 12295 | genlmsg_cancel(msg, hdr); |
| 12296 | nlmsg_free(msg); |
| 12297 | } |
| 12298 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12299 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 12300 | u64 cookie, bool acked, gfp_t gfp) |
| 12301 | { |
| 12302 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12303 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12304 | struct sk_buff *msg; |
| 12305 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12306 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 12307 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 12308 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12309 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 12310 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12311 | if (!msg) |
| 12312 | return; |
| 12313 | |
| 12314 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 12315 | if (!hdr) { |
| 12316 | nlmsg_free(msg); |
| 12317 | return; |
| 12318 | } |
| 12319 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12320 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12321 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12322 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 12323 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 12324 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 12325 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12326 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12327 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12328 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12329 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12330 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12331 | return; |
| 12332 | |
| 12333 | nla_put_failure: |
| 12334 | genlmsg_cancel(msg, hdr); |
| 12335 | nlmsg_free(msg); |
| 12336 | } |
| 12337 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 12338 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12339 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 12340 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12341 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12342 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12343 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12344 | struct sk_buff *msg; |
| 12345 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12346 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12347 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 12348 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 12349 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12350 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 12351 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 12352 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 12353 | if (!msg) { |
| 12354 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 12355 | return; |
| 12356 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12357 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12358 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 12359 | if (!hdr) |
| 12360 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12361 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12362 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12363 | (freq && |
| 12364 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 12365 | (sig_dbm && |
| 12366 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 12367 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 12368 | goto nla_put_failure; |
| 12369 | |
| 12370 | genlmsg_end(msg, hdr); |
| 12371 | |
| 12372 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12373 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12374 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12375 | return; |
| 12376 | |
| 12377 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12378 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 12379 | if (hdr) |
| 12380 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12381 | nlmsg_free(msg); |
| 12382 | } |
| 12383 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 12384 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12385 | #ifdef CONFIG_PM |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12386 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
| 12387 | struct cfg80211_wowlan_wakeup *wakeup) |
| 12388 | { |
| 12389 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; |
| 12390 | struct nlattr *nl_results, *nl_match, *nl_freqs; |
| 12391 | int i, j; |
| 12392 | |
| 12393 | nl_results = nla_nest_start( |
| 12394 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); |
| 12395 | if (!nl_results) |
| 12396 | return -EMSGSIZE; |
| 12397 | |
| 12398 | for (i = 0; i < nd->n_matches; i++) { |
| 12399 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; |
| 12400 | |
| 12401 | nl_match = nla_nest_start(msg, i); |
| 12402 | if (!nl_match) |
| 12403 | break; |
| 12404 | |
| 12405 | /* The SSID attribute is optional in nl80211, but for |
| 12406 | * simplicity reasons it's always present in the |
| 12407 | * cfg80211 structure. If a driver can't pass the |
| 12408 | * SSID, that needs to be changed. A zero length SSID |
| 12409 | * is still a valid SSID (wildcard), so it cannot be |
| 12410 | * used for this purpose. |
| 12411 | */ |
| 12412 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, |
| 12413 | match->ssid.ssid)) { |
| 12414 | nla_nest_cancel(msg, nl_match); |
| 12415 | goto out; |
| 12416 | } |
| 12417 | |
| 12418 | if (match->n_channels) { |
| 12419 | nl_freqs = nla_nest_start( |
| 12420 | msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 12421 | if (!nl_freqs) { |
| 12422 | nla_nest_cancel(msg, nl_match); |
| 12423 | goto out; |
| 12424 | } |
| 12425 | |
| 12426 | for (j = 0; j < match->n_channels; j++) { |
| 12427 | if (nla_put_u32(msg, |
| 12428 | NL80211_ATTR_WIPHY_FREQ, |
| 12429 | match->channels[j])) { |
| 12430 | nla_nest_cancel(msg, nl_freqs); |
| 12431 | nla_nest_cancel(msg, nl_match); |
| 12432 | goto out; |
| 12433 | } |
| 12434 | } |
| 12435 | |
| 12436 | nla_nest_end(msg, nl_freqs); |
| 12437 | } |
| 12438 | |
| 12439 | nla_nest_end(msg, nl_match); |
| 12440 | } |
| 12441 | |
| 12442 | out: |
| 12443 | nla_nest_end(msg, nl_results); |
| 12444 | return 0; |
| 12445 | } |
| 12446 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12447 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 12448 | struct cfg80211_wowlan_wakeup *wakeup, |
| 12449 | gfp_t gfp) |
| 12450 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12451 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12452 | struct sk_buff *msg; |
| 12453 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12454 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12455 | |
| 12456 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 12457 | |
| 12458 | if (wakeup) |
| 12459 | size += wakeup->packet_present_len; |
| 12460 | |
| 12461 | msg = nlmsg_new(size, gfp); |
| 12462 | if (!msg) |
| 12463 | return; |
| 12464 | |
| 12465 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 12466 | if (!hdr) |
| 12467 | goto free_msg; |
| 12468 | |
| 12469 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12470 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12471 | goto free_msg; |
| 12472 | |
| 12473 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12474 | wdev->netdev->ifindex)) |
| 12475 | goto free_msg; |
| 12476 | |
| 12477 | if (wakeup) { |
| 12478 | struct nlattr *reasons; |
| 12479 | |
| 12480 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 12481 | if (!reasons) |
| 12482 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12483 | |
| 12484 | if (wakeup->disconnect && |
| 12485 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 12486 | goto free_msg; |
| 12487 | if (wakeup->magic_pkt && |
| 12488 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 12489 | goto free_msg; |
| 12490 | if (wakeup->gtk_rekey_failure && |
| 12491 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 12492 | goto free_msg; |
| 12493 | if (wakeup->eap_identity_req && |
| 12494 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 12495 | goto free_msg; |
| 12496 | if (wakeup->four_way_handshake && |
| 12497 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 12498 | goto free_msg; |
| 12499 | if (wakeup->rfkill_release && |
| 12500 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 12501 | goto free_msg; |
| 12502 | |
| 12503 | if (wakeup->pattern_idx >= 0 && |
| 12504 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 12505 | wakeup->pattern_idx)) |
| 12506 | goto free_msg; |
| 12507 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12508 | if (wakeup->tcp_match && |
| 12509 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 12510 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12511 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12512 | if (wakeup->tcp_connlost && |
| 12513 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 12514 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12515 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12516 | if (wakeup->tcp_nomoretokens && |
| 12517 | nla_put_flag(msg, |
| 12518 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 12519 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12520 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12521 | if (wakeup->packet) { |
| 12522 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 12523 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 12524 | |
| 12525 | if (!wakeup->packet_80211) { |
| 12526 | pkt_attr = |
| 12527 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 12528 | len_attr = |
| 12529 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 12530 | } |
| 12531 | |
| 12532 | if (wakeup->packet_len && |
| 12533 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 12534 | goto free_msg; |
| 12535 | |
| 12536 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 12537 | wakeup->packet)) |
| 12538 | goto free_msg; |
| 12539 | } |
| 12540 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12541 | if (wakeup->net_detect && |
| 12542 | cfg80211_net_detect_results(msg, wakeup)) |
| 12543 | goto free_msg; |
| 12544 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12545 | nla_nest_end(msg, reasons); |
| 12546 | } |
| 12547 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12548 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12549 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12550 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12551 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12552 | return; |
| 12553 | |
| 12554 | free_msg: |
| 12555 | nlmsg_free(msg); |
| 12556 | } |
| 12557 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 12558 | #endif |
| 12559 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12560 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 12561 | enum nl80211_tdls_operation oper, |
| 12562 | u16 reason_code, gfp_t gfp) |
| 12563 | { |
| 12564 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12565 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12566 | struct sk_buff *msg; |
| 12567 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12568 | |
| 12569 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 12570 | reason_code); |
| 12571 | |
| 12572 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12573 | if (!msg) |
| 12574 | return; |
| 12575 | |
| 12576 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 12577 | if (!hdr) { |
| 12578 | nlmsg_free(msg); |
| 12579 | return; |
| 12580 | } |
| 12581 | |
| 12582 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12583 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12584 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 12585 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 12586 | (reason_code > 0 && |
| 12587 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 12588 | goto nla_put_failure; |
| 12589 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12590 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12591 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12592 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12593 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12594 | return; |
| 12595 | |
| 12596 | nla_put_failure: |
| 12597 | genlmsg_cancel(msg, hdr); |
| 12598 | nlmsg_free(msg); |
| 12599 | } |
| 12600 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 12601 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12602 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 12603 | unsigned long state, |
| 12604 | void *_notify) |
| 12605 | { |
| 12606 | struct netlink_notify *notify = _notify; |
| 12607 | struct cfg80211_registered_device *rdev; |
| 12608 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12609 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12610 | |
| 12611 | if (state != NETLINK_URELEASE) |
| 12612 | return NOTIFY_DONE; |
| 12613 | |
| 12614 | rcu_read_lock(); |
| 12615 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12616 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12617 | bool schedule_destroy_work = false; |
| 12618 | |
| 12619 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12620 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12621 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12622 | if (wdev->owner_nlportid == notify->portid) |
| 12623 | schedule_destroy_work = true; |
| 12624 | } |
| 12625 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12626 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 12627 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 12628 | list) { |
| 12629 | if (reg->nlportid == notify->portid) { |
| 12630 | list_del(®->list); |
| 12631 | kfree(reg); |
| 12632 | break; |
| 12633 | } |
| 12634 | } |
| 12635 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12636 | |
| 12637 | if (schedule_destroy_work) { |
| 12638 | struct cfg80211_iface_destroy *destroy; |
| 12639 | |
| 12640 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); |
| 12641 | if (destroy) { |
| 12642 | destroy->nlportid = notify->portid; |
| 12643 | spin_lock(&rdev->destroy_list_lock); |
| 12644 | list_add(&destroy->list, &rdev->destroy_list); |
| 12645 | spin_unlock(&rdev->destroy_list_lock); |
| 12646 | schedule_work(&rdev->destroy_work); |
| 12647 | } |
| 12648 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12649 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12650 | |
| 12651 | rcu_read_unlock(); |
| 12652 | |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 12653 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12654 | } |
| 12655 | |
| 12656 | static struct notifier_block nl80211_netlink_notifier = { |
| 12657 | .notifier_call = nl80211_netlink_notify, |
| 12658 | }; |
| 12659 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12660 | void cfg80211_ft_event(struct net_device *netdev, |
| 12661 | struct cfg80211_ft_event_params *ft_event) |
| 12662 | { |
| 12663 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12664 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12665 | struct sk_buff *msg; |
| 12666 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12667 | |
| 12668 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 12669 | |
| 12670 | if (!ft_event->target_ap) |
| 12671 | return; |
| 12672 | |
| 12673 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12674 | if (!msg) |
| 12675 | return; |
| 12676 | |
| 12677 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12678 | if (!hdr) |
| 12679 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12680 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12681 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12682 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12683 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 12684 | goto out; |
| 12685 | |
| 12686 | if (ft_event->ies && |
| 12687 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 12688 | goto out; |
| 12689 | if (ft_event->ric_ies && |
| 12690 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 12691 | ft_event->ric_ies)) |
| 12692 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12693 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12694 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12695 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12696 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12697 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12698 | return; |
| 12699 | out: |
| 12700 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12701 | } |
| 12702 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 12703 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12704 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 12705 | { |
| 12706 | struct cfg80211_registered_device *rdev; |
| 12707 | struct sk_buff *msg; |
| 12708 | void *hdr; |
| 12709 | u32 nlportid; |
| 12710 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12711 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12712 | if (!rdev->crit_proto_nlportid) |
| 12713 | return; |
| 12714 | |
| 12715 | nlportid = rdev->crit_proto_nlportid; |
| 12716 | rdev->crit_proto_nlportid = 0; |
| 12717 | |
| 12718 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12719 | if (!msg) |
| 12720 | return; |
| 12721 | |
| 12722 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 12723 | if (!hdr) |
| 12724 | goto nla_put_failure; |
| 12725 | |
| 12726 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12727 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12728 | goto nla_put_failure; |
| 12729 | |
| 12730 | genlmsg_end(msg, hdr); |
| 12731 | |
| 12732 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 12733 | return; |
| 12734 | |
| 12735 | nla_put_failure: |
| 12736 | if (hdr) |
| 12737 | genlmsg_cancel(msg, hdr); |
| 12738 | nlmsg_free(msg); |
| 12739 | |
| 12740 | } |
| 12741 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 12742 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 12743 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 12744 | { |
| 12745 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12746 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 12747 | struct sk_buff *msg; |
| 12748 | void *hdr; |
| 12749 | |
| 12750 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12751 | if (!msg) |
| 12752 | return; |
| 12753 | |
| 12754 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 12755 | if (!hdr) |
| 12756 | goto out; |
| 12757 | |
| 12758 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12759 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
| 12760 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12761 | goto out; |
| 12762 | |
| 12763 | genlmsg_end(msg, hdr); |
| 12764 | |
| 12765 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 12766 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 12767 | return; |
| 12768 | out: |
| 12769 | nlmsg_free(msg); |
| 12770 | } |
| 12771 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12772 | /* initialisation/exit functions */ |
| 12773 | |
| 12774 | int nl80211_init(void) |
| 12775 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 12776 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12777 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12778 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
| 12779 | nl80211_mcgrps); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12780 | if (err) |
| 12781 | return err; |
| 12782 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12783 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 12784 | if (err) |
| 12785 | goto err_out; |
| 12786 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12787 | return 0; |
| 12788 | err_out: |
| 12789 | genl_unregister_family(&nl80211_fam); |
| 12790 | return err; |
| 12791 | } |
| 12792 | |
| 12793 | void nl80211_exit(void) |
| 12794 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12795 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12796 | genl_unregister_family(&nl80211_fam); |
| 12797 | } |