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 | dc6382c | 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 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 399 | }; |
| 400 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 401 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 402 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 403 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 404 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 405 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 406 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 407 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 408 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 409 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 410 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 411 | }; |
| 412 | |
| 413 | /* policy for the key default flags */ |
| 414 | static const struct nla_policy |
| 415 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 416 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 417 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 418 | }; |
| 419 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 420 | /* policy for WoWLAN attributes */ |
| 421 | static const struct nla_policy |
| 422 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 423 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 424 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 425 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 426 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 427 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 428 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 429 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 430 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 431 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 432 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 433 | }; |
| 434 | |
| 435 | static const struct nla_policy |
| 436 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 437 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 438 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 439 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 440 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 441 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 442 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 443 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 444 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 445 | }, |
| 446 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 447 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 448 | }, |
| 449 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 450 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 451 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 452 | }; |
| 453 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 454 | /* policy for coalesce rule attributes */ |
| 455 | static const struct nla_policy |
| 456 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 457 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 458 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 459 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 460 | }; |
| 461 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 462 | /* policy for GTK rekey offload attributes */ |
| 463 | static const struct nla_policy |
| 464 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 465 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 466 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 467 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 468 | }; |
| 469 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 470 | static const struct nla_policy |
| 471 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 472 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 473 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 474 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 475 | }; |
| 476 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 477 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 478 | struct netlink_callback *cb, |
| 479 | struct cfg80211_registered_device **rdev, |
| 480 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 481 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 482 | int err; |
| 483 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 484 | rtnl_lock(); |
| 485 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 486 | if (!cb->args[0]) { |
| 487 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 488 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 489 | nl80211_policy); |
| 490 | if (err) |
| 491 | goto out_unlock; |
| 492 | |
| 493 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 494 | nl80211_fam.attrbuf); |
| 495 | if (IS_ERR(*wdev)) { |
| 496 | err = PTR_ERR(*wdev); |
| 497 | goto out_unlock; |
| 498 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 499 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 500 | /* 0 is the first index - add 1 to parse only once */ |
| 501 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 502 | cb->args[1] = (*wdev)->identifier; |
| 503 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 504 | /* subtract the 1 again here */ |
| 505 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 506 | struct wireless_dev *tmp; |
| 507 | |
| 508 | if (!wiphy) { |
| 509 | err = -ENODEV; |
| 510 | goto out_unlock; |
| 511 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 512 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 513 | *wdev = NULL; |
| 514 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 515 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 516 | if (tmp->identifier == cb->args[1]) { |
| 517 | *wdev = tmp; |
| 518 | break; |
| 519 | } |
| 520 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 521 | |
| 522 | if (!*wdev) { |
| 523 | err = -ENODEV; |
| 524 | goto out_unlock; |
| 525 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 526 | } |
| 527 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 528 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 529 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 530 | rtnl_unlock(); |
| 531 | return err; |
| 532 | } |
| 533 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 534 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 535 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 536 | rtnl_unlock(); |
| 537 | } |
| 538 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 539 | /* IE validation */ |
| 540 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 541 | { |
| 542 | const u8 *pos; |
| 543 | int len; |
| 544 | |
| 545 | if (!attr) |
| 546 | return true; |
| 547 | |
| 548 | pos = nla_data(attr); |
| 549 | len = nla_len(attr); |
| 550 | |
| 551 | while (len) { |
| 552 | u8 elemlen; |
| 553 | |
| 554 | if (len < 2) |
| 555 | return false; |
| 556 | len -= 2; |
| 557 | |
| 558 | elemlen = pos[1]; |
| 559 | if (elemlen > len) |
| 560 | return false; |
| 561 | |
| 562 | len -= elemlen; |
| 563 | pos += 2 + elemlen; |
| 564 | } |
| 565 | |
| 566 | return true; |
| 567 | } |
| 568 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 569 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 570 | 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] | 571 | int flags, u8 cmd) |
| 572 | { |
| 573 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 574 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 575 | } |
| 576 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 577 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 578 | struct ieee80211_channel *chan, |
| 579 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 580 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 581 | /* Some channels must be completely excluded from the |
| 582 | * list to protect old user-space tools from breaking |
| 583 | */ |
| 584 | if (!large && chan->flags & |
| 585 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 586 | return 0; |
| 587 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 588 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 589 | chan->center_freq)) |
| 590 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 591 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 592 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 593 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 594 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 595 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 596 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 597 | goto nla_put_failure; |
| 598 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 599 | goto nla_put_failure; |
| 600 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 601 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 602 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 603 | goto nla_put_failure; |
| 604 | if (large) { |
| 605 | u32 time; |
| 606 | |
| 607 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 608 | |
| 609 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 610 | chan->dfs_state)) |
| 611 | goto nla_put_failure; |
| 612 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 613 | time)) |
| 614 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 615 | if (nla_put_u32(msg, |
| 616 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 617 | chan->dfs_cac_ms)) |
| 618 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 619 | } |
| 620 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 621 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 622 | if (large) { |
| 623 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 624 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 625 | goto nla_put_failure; |
| 626 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 627 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 628 | goto nla_put_failure; |
| 629 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 630 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 631 | goto nla_put_failure; |
| 632 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 633 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 634 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 635 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 636 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 637 | goto nla_put_failure; |
| 638 | if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) && |
| 639 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT)) |
| 640 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 641 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 642 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 643 | goto nla_put_failure; |
| 644 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 645 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 646 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 647 | } |
| 648 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 649 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 650 | DBM_TO_MBM(chan->max_power))) |
| 651 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 652 | |
| 653 | return 0; |
| 654 | |
| 655 | nla_put_failure: |
| 656 | return -ENOBUFS; |
| 657 | } |
| 658 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 659 | /* netlink command implementations */ |
| 660 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 661 | struct key_parse { |
| 662 | struct key_params p; |
| 663 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 664 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 665 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 666 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 667 | }; |
| 668 | |
| 669 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 670 | { |
| 671 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 672 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 673 | nl80211_key_policy); |
| 674 | if (err) |
| 675 | return err; |
| 676 | |
| 677 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 678 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 679 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 680 | if (k->def) { |
| 681 | k->def_uni = true; |
| 682 | k->def_multi = true; |
| 683 | } |
| 684 | if (k->defmgmt) |
| 685 | k->def_multi = true; |
| 686 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 687 | if (tb[NL80211_KEY_IDX]) |
| 688 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 689 | |
| 690 | if (tb[NL80211_KEY_DATA]) { |
| 691 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 692 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 693 | } |
| 694 | |
| 695 | if (tb[NL80211_KEY_SEQ]) { |
| 696 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 697 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 698 | } |
| 699 | |
| 700 | if (tb[NL80211_KEY_CIPHER]) |
| 701 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 702 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 703 | if (tb[NL80211_KEY_TYPE]) { |
| 704 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 705 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 706 | return -EINVAL; |
| 707 | } |
| 708 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 709 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 710 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 711 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 712 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 713 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 714 | if (err) |
| 715 | return err; |
| 716 | |
| 717 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 718 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 719 | } |
| 720 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 721 | return 0; |
| 722 | } |
| 723 | |
| 724 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 725 | { |
| 726 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 727 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 728 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 729 | } |
| 730 | |
| 731 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 732 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 733 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 734 | } |
| 735 | |
| 736 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 737 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 738 | |
| 739 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 740 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 741 | |
| 742 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 743 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 744 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 745 | if (k->def) { |
| 746 | k->def_uni = true; |
| 747 | k->def_multi = true; |
| 748 | } |
| 749 | if (k->defmgmt) |
| 750 | k->def_multi = true; |
| 751 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 752 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 753 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 754 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 755 | return -EINVAL; |
| 756 | } |
| 757 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 758 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 759 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 760 | int err = nla_parse_nested( |
| 761 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 762 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 763 | nl80211_key_default_policy); |
| 764 | if (err) |
| 765 | return err; |
| 766 | |
| 767 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 768 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 769 | } |
| 770 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 771 | return 0; |
| 772 | } |
| 773 | |
| 774 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 775 | { |
| 776 | int err; |
| 777 | |
| 778 | memset(k, 0, sizeof(*k)); |
| 779 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 780 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 781 | |
| 782 | if (info->attrs[NL80211_ATTR_KEY]) |
| 783 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 784 | else |
| 785 | err = nl80211_parse_key_old(info, k); |
| 786 | |
| 787 | if (err) |
| 788 | return err; |
| 789 | |
| 790 | if (k->def && k->defmgmt) |
| 791 | return -EINVAL; |
| 792 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 793 | if (k->defmgmt) { |
| 794 | if (k->def_uni || !k->def_multi) |
| 795 | return -EINVAL; |
| 796 | } |
| 797 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 798 | if (k->idx != -1) { |
| 799 | if (k->defmgmt) { |
| 800 | if (k->idx < 4 || k->idx > 5) |
| 801 | return -EINVAL; |
| 802 | } else if (k->def) { |
| 803 | if (k->idx < 0 || k->idx > 3) |
| 804 | return -EINVAL; |
| 805 | } else { |
| 806 | if (k->idx < 0 || k->idx > 5) |
| 807 | return -EINVAL; |
| 808 | } |
| 809 | } |
| 810 | |
| 811 | return 0; |
| 812 | } |
| 813 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 814 | static struct cfg80211_cached_keys * |
| 815 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 816 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 817 | { |
| 818 | struct key_parse parse; |
| 819 | struct nlattr *key; |
| 820 | struct cfg80211_cached_keys *result; |
| 821 | int rem, err, def = 0; |
| 822 | |
| 823 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 824 | if (!result) |
| 825 | return ERR_PTR(-ENOMEM); |
| 826 | |
| 827 | result->def = -1; |
| 828 | result->defmgmt = -1; |
| 829 | |
| 830 | nla_for_each_nested(key, keys, rem) { |
| 831 | memset(&parse, 0, sizeof(parse)); |
| 832 | parse.idx = -1; |
| 833 | |
| 834 | err = nl80211_parse_key_new(key, &parse); |
| 835 | if (err) |
| 836 | goto error; |
| 837 | err = -EINVAL; |
| 838 | if (!parse.p.key) |
| 839 | goto error; |
| 840 | if (parse.idx < 0 || parse.idx > 4) |
| 841 | goto error; |
| 842 | if (parse.def) { |
| 843 | if (def) |
| 844 | goto error; |
| 845 | def = 1; |
| 846 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 847 | if (!parse.def_uni || !parse.def_multi) |
| 848 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 849 | } else if (parse.defmgmt) |
| 850 | goto error; |
| 851 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 852 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 853 | if (err) |
| 854 | goto error; |
| 855 | result->params[parse.idx].cipher = parse.p.cipher; |
| 856 | result->params[parse.idx].key_len = parse.p.key_len; |
| 857 | result->params[parse.idx].key = result->data[parse.idx]; |
| 858 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 859 | |
| 860 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 861 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 862 | if (no_ht) |
| 863 | *no_ht = true; |
| 864 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | return result; |
| 868 | error: |
| 869 | kfree(result); |
| 870 | return ERR_PTR(err); |
| 871 | } |
| 872 | |
| 873 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 874 | { |
| 875 | ASSERT_WDEV_LOCK(wdev); |
| 876 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 877 | switch (wdev->iftype) { |
| 878 | case NL80211_IFTYPE_AP: |
| 879 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 880 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 881 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 882 | break; |
| 883 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 884 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 885 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 886 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 887 | return -ENOLINK; |
| 888 | break; |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 889 | case NL80211_IFTYPE_UNSPECIFIED: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 890 | case NL80211_IFTYPE_OCB: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 891 | case NL80211_IFTYPE_MONITOR: |
| 892 | case NL80211_IFTYPE_P2P_DEVICE: |
| 893 | case NL80211_IFTYPE_WDS: |
| 894 | case NUM_NL80211_IFTYPES: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 895 | return -EINVAL; |
| 896 | } |
| 897 | |
| 898 | return 0; |
| 899 | } |
| 900 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 901 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 902 | struct nlattr *tb) |
| 903 | { |
| 904 | struct ieee80211_channel *chan; |
| 905 | |
| 906 | if (tb == NULL) |
| 907 | return NULL; |
| 908 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 909 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 910 | return NULL; |
| 911 | return chan; |
| 912 | } |
| 913 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 914 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 915 | { |
| 916 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 917 | int i; |
| 918 | |
| 919 | if (!nl_modes) |
| 920 | goto nla_put_failure; |
| 921 | |
| 922 | i = 0; |
| 923 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 924 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 925 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 926 | ifmodes >>= 1; |
| 927 | i++; |
| 928 | } |
| 929 | |
| 930 | nla_nest_end(msg, nl_modes); |
| 931 | return 0; |
| 932 | |
| 933 | nla_put_failure: |
| 934 | return -ENOBUFS; |
| 935 | } |
| 936 | |
| 937 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 938 | struct sk_buff *msg, |
| 939 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 940 | { |
| 941 | struct nlattr *nl_combis; |
| 942 | int i, j; |
| 943 | |
| 944 | nl_combis = nla_nest_start(msg, |
| 945 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 946 | if (!nl_combis) |
| 947 | goto nla_put_failure; |
| 948 | |
| 949 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 950 | const struct ieee80211_iface_combination *c; |
| 951 | struct nlattr *nl_combi, *nl_limits; |
| 952 | |
| 953 | c = &wiphy->iface_combinations[i]; |
| 954 | |
| 955 | nl_combi = nla_nest_start(msg, i + 1); |
| 956 | if (!nl_combi) |
| 957 | goto nla_put_failure; |
| 958 | |
| 959 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 960 | if (!nl_limits) |
| 961 | goto nla_put_failure; |
| 962 | |
| 963 | for (j = 0; j < c->n_limits; j++) { |
| 964 | struct nlattr *nl_limit; |
| 965 | |
| 966 | nl_limit = nla_nest_start(msg, j + 1); |
| 967 | if (!nl_limit) |
| 968 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 969 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 970 | c->limits[j].max)) |
| 971 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 972 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 973 | c->limits[j].types)) |
| 974 | goto nla_put_failure; |
| 975 | nla_nest_end(msg, nl_limit); |
| 976 | } |
| 977 | |
| 978 | nla_nest_end(msg, nl_limits); |
| 979 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 980 | if (c->beacon_int_infra_match && |
| 981 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 982 | goto nla_put_failure; |
| 983 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 984 | c->num_different_channels) || |
| 985 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 986 | c->max_interfaces)) |
| 987 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 988 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 989 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 990 | c->radar_detect_widths) || |
| 991 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 992 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 993 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 994 | |
| 995 | nla_nest_end(msg, nl_combi); |
| 996 | } |
| 997 | |
| 998 | nla_nest_end(msg, nl_combis); |
| 999 | |
| 1000 | return 0; |
| 1001 | nla_put_failure: |
| 1002 | return -ENOBUFS; |
| 1003 | } |
| 1004 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1005 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1006 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 1007 | struct sk_buff *msg) |
| 1008 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1009 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1010 | struct nlattr *nl_tcp; |
| 1011 | |
| 1012 | if (!tcp) |
| 1013 | return 0; |
| 1014 | |
| 1015 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 1016 | if (!nl_tcp) |
| 1017 | return -ENOBUFS; |
| 1018 | |
| 1019 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1020 | tcp->data_payload_max)) |
| 1021 | return -ENOBUFS; |
| 1022 | |
| 1023 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1024 | tcp->data_payload_max)) |
| 1025 | return -ENOBUFS; |
| 1026 | |
| 1027 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1028 | return -ENOBUFS; |
| 1029 | |
| 1030 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1031 | sizeof(*tcp->tok), tcp->tok)) |
| 1032 | return -ENOBUFS; |
| 1033 | |
| 1034 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1035 | tcp->data_interval_max)) |
| 1036 | return -ENOBUFS; |
| 1037 | |
| 1038 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1039 | tcp->wake_payload_max)) |
| 1040 | return -ENOBUFS; |
| 1041 | |
| 1042 | nla_nest_end(msg, nl_tcp); |
| 1043 | return 0; |
| 1044 | } |
| 1045 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1046 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1047 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1048 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1049 | { |
| 1050 | struct nlattr *nl_wowlan; |
| 1051 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1052 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1053 | return 0; |
| 1054 | |
| 1055 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1056 | if (!nl_wowlan) |
| 1057 | return -ENOBUFS; |
| 1058 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1059 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1060 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1061 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1062 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1063 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1064 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1065 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1066 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1067 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1068 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1069 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1070 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1071 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1072 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1073 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1074 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1075 | return -ENOBUFS; |
| 1076 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1077 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1078 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1079 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1080 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1081 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1082 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1083 | }; |
| 1084 | |
| 1085 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1086 | sizeof(pat), &pat)) |
| 1087 | return -ENOBUFS; |
| 1088 | } |
| 1089 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1090 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1091 | return -ENOBUFS; |
| 1092 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 1093 | /* TODO: send wowlan net detect */ |
| 1094 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1095 | nla_nest_end(msg, nl_wowlan); |
| 1096 | |
| 1097 | return 0; |
| 1098 | } |
| 1099 | #endif |
| 1100 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1101 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1102 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1103 | { |
| 1104 | struct nl80211_coalesce_rule_support rule; |
| 1105 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1106 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1107 | return 0; |
| 1108 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1109 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1110 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1111 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1112 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1113 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1114 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1115 | |
| 1116 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1117 | return -ENOBUFS; |
| 1118 | |
| 1119 | return 0; |
| 1120 | } |
| 1121 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1122 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1123 | struct ieee80211_supported_band *sband) |
| 1124 | { |
| 1125 | struct nlattr *nl_rates, *nl_rate; |
| 1126 | struct ieee80211_rate *rate; |
| 1127 | int i; |
| 1128 | |
| 1129 | /* add HT info */ |
| 1130 | if (sband->ht_cap.ht_supported && |
| 1131 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1132 | sizeof(sband->ht_cap.mcs), |
| 1133 | &sband->ht_cap.mcs) || |
| 1134 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1135 | sband->ht_cap.cap) || |
| 1136 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1137 | sband->ht_cap.ampdu_factor) || |
| 1138 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1139 | sband->ht_cap.ampdu_density))) |
| 1140 | return -ENOBUFS; |
| 1141 | |
| 1142 | /* add VHT info */ |
| 1143 | if (sband->vht_cap.vht_supported && |
| 1144 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1145 | sizeof(sband->vht_cap.vht_mcs), |
| 1146 | &sband->vht_cap.vht_mcs) || |
| 1147 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1148 | sband->vht_cap.cap))) |
| 1149 | return -ENOBUFS; |
| 1150 | |
| 1151 | /* add bitrates */ |
| 1152 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1153 | if (!nl_rates) |
| 1154 | return -ENOBUFS; |
| 1155 | |
| 1156 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1157 | nl_rate = nla_nest_start(msg, i); |
| 1158 | if (!nl_rate) |
| 1159 | return -ENOBUFS; |
| 1160 | |
| 1161 | rate = &sband->bitrates[i]; |
| 1162 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1163 | rate->bitrate)) |
| 1164 | return -ENOBUFS; |
| 1165 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1166 | nla_put_flag(msg, |
| 1167 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1168 | return -ENOBUFS; |
| 1169 | |
| 1170 | nla_nest_end(msg, nl_rate); |
| 1171 | } |
| 1172 | |
| 1173 | nla_nest_end(msg, nl_rates); |
| 1174 | |
| 1175 | return 0; |
| 1176 | } |
| 1177 | |
| 1178 | static int |
| 1179 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1180 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1181 | { |
| 1182 | u16 stypes; |
| 1183 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1184 | enum nl80211_iftype ift; |
| 1185 | int i; |
| 1186 | |
| 1187 | if (!mgmt_stypes) |
| 1188 | return 0; |
| 1189 | |
| 1190 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1191 | if (!nl_ifs) |
| 1192 | return -ENOBUFS; |
| 1193 | |
| 1194 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1195 | nl_ftypes = nla_nest_start(msg, ift); |
| 1196 | if (!nl_ftypes) |
| 1197 | return -ENOBUFS; |
| 1198 | i = 0; |
| 1199 | stypes = mgmt_stypes[ift].tx; |
| 1200 | while (stypes) { |
| 1201 | if ((stypes & 1) && |
| 1202 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1203 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1204 | return -ENOBUFS; |
| 1205 | stypes >>= 1; |
| 1206 | i++; |
| 1207 | } |
| 1208 | nla_nest_end(msg, nl_ftypes); |
| 1209 | } |
| 1210 | |
| 1211 | nla_nest_end(msg, nl_ifs); |
| 1212 | |
| 1213 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1214 | if (!nl_ifs) |
| 1215 | return -ENOBUFS; |
| 1216 | |
| 1217 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1218 | nl_ftypes = nla_nest_start(msg, ift); |
| 1219 | if (!nl_ftypes) |
| 1220 | return -ENOBUFS; |
| 1221 | i = 0; |
| 1222 | stypes = mgmt_stypes[ift].rx; |
| 1223 | while (stypes) { |
| 1224 | if ((stypes & 1) && |
| 1225 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1226 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1227 | return -ENOBUFS; |
| 1228 | stypes >>= 1; |
| 1229 | i++; |
| 1230 | } |
| 1231 | nla_nest_end(msg, nl_ftypes); |
| 1232 | } |
| 1233 | nla_nest_end(msg, nl_ifs); |
| 1234 | |
| 1235 | return 0; |
| 1236 | } |
| 1237 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1238 | struct nl80211_dump_wiphy_state { |
| 1239 | s64 filter_wiphy; |
| 1240 | long start; |
| 1241 | long split_start, band_start, chan_start; |
| 1242 | bool split; |
| 1243 | }; |
| 1244 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1245 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1246 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1247 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1248 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1249 | { |
| 1250 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1251 | struct nlattr *nl_bands, *nl_band; |
| 1252 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1253 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1254 | enum ieee80211_band band; |
| 1255 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1256 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1257 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1258 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1259 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1260 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1261 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1262 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1263 | return -ENOBUFS; |
| 1264 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1265 | if (WARN_ON(!state)) |
| 1266 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1267 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1268 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1269 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1270 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1271 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1272 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1273 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1274 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1275 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 1276 | goto finish; |
| 1277 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1278 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1279 | case 0: |
| 1280 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1281 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1282 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1283 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1284 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1285 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1286 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1287 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1288 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1289 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1290 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1291 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1292 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1293 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1294 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1295 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1296 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1297 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1298 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1299 | rdev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1300 | goto nla_put_failure; |
| 1301 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1302 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1303 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1304 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1305 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1306 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1307 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1308 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1309 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1310 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1311 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1312 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1313 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1314 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1315 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1316 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1317 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1318 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1319 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1320 | state->split_start++; |
| 1321 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1322 | break; |
| 1323 | case 1: |
| 1324 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1325 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 1326 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1327 | goto nla_put_failure; |
| 1328 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1329 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1330 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1331 | goto nla_put_failure; |
| 1332 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1333 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1334 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1335 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1336 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1337 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1338 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1339 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1340 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1341 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1342 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1343 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1344 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1345 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1346 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1347 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1348 | if ((rdev->wiphy.available_antennas_tx || |
| 1349 | rdev->wiphy.available_antennas_rx) && |
| 1350 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1351 | u32 tx_ant = 0, rx_ant = 0; |
| 1352 | int res; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1353 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1354 | if (!res) { |
| 1355 | if (nla_put_u32(msg, |
| 1356 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1357 | tx_ant) || |
| 1358 | nla_put_u32(msg, |
| 1359 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1360 | rx_ant)) |
| 1361 | goto nla_put_failure; |
| 1362 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1363 | } |
| 1364 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1365 | state->split_start++; |
| 1366 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1367 | break; |
| 1368 | case 2: |
| 1369 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1370 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1371 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1372 | state->split_start++; |
| 1373 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1374 | break; |
| 1375 | case 3: |
| 1376 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1377 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1378 | goto nla_put_failure; |
| 1379 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1380 | for (band = state->band_start; |
| 1381 | band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1382 | struct ieee80211_supported_band *sband; |
| 1383 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1384 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1385 | |
| 1386 | if (!sband) |
| 1387 | continue; |
| 1388 | |
| 1389 | nl_band = nla_nest_start(msg, band); |
| 1390 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1391 | goto nla_put_failure; |
| 1392 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1393 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1394 | case 0: |
| 1395 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1396 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1397 | state->chan_start++; |
| 1398 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1399 | break; |
| 1400 | default: |
| 1401 | /* add frequencies */ |
| 1402 | nl_freqs = nla_nest_start( |
| 1403 | msg, NL80211_BAND_ATTR_FREQS); |
| 1404 | if (!nl_freqs) |
| 1405 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1406 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1407 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1408 | i < sband->n_channels; |
| 1409 | i++) { |
| 1410 | nl_freq = nla_nest_start(msg, i); |
| 1411 | if (!nl_freq) |
| 1412 | goto nla_put_failure; |
| 1413 | |
| 1414 | chan = &sband->channels[i]; |
| 1415 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1416 | if (nl80211_msg_put_channel( |
| 1417 | msg, chan, |
| 1418 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1419 | goto nla_put_failure; |
| 1420 | |
| 1421 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1422 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1423 | break; |
| 1424 | } |
| 1425 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1426 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1427 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1428 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1429 | nla_nest_end(msg, nl_freqs); |
| 1430 | } |
| 1431 | |
| 1432 | nla_nest_end(msg, nl_band); |
| 1433 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1434 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1435 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1436 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1437 | band--; |
| 1438 | break; |
| 1439 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1440 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1441 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1442 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1443 | if (band < IEEE80211_NUM_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1444 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1445 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1446 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1447 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1448 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1449 | if (state->band_start == 0 && state->chan_start == 0) |
| 1450 | state->split_start++; |
| 1451 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1452 | break; |
| 1453 | case 4: |
| 1454 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1455 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1456 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1457 | |
| 1458 | i = 0; |
| 1459 | #define CMD(op, n) \ |
| 1460 | do { \ |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1461 | if (rdev->ops->op) { \ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1462 | i++; \ |
| 1463 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1464 | goto nla_put_failure; \ |
| 1465 | } \ |
| 1466 | } while (0) |
| 1467 | |
| 1468 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1469 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1470 | CMD(add_key, NEW_KEY); |
| 1471 | CMD(start_ap, START_AP); |
| 1472 | CMD(add_station, NEW_STATION); |
| 1473 | CMD(add_mpath, NEW_MPATH); |
| 1474 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1475 | CMD(change_bss, SET_BSS); |
| 1476 | CMD(auth, AUTHENTICATE); |
| 1477 | CMD(assoc, ASSOCIATE); |
| 1478 | CMD(deauth, DEAUTHENTICATE); |
| 1479 | CMD(disassoc, DISASSOCIATE); |
| 1480 | CMD(join_ibss, JOIN_IBSS); |
| 1481 | CMD(join_mesh, JOIN_MESH); |
| 1482 | CMD(set_pmksa, SET_PMKSA); |
| 1483 | CMD(del_pmksa, DEL_PMKSA); |
| 1484 | CMD(flush_pmksa, FLUSH_PMKSA); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1485 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1486 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1487 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1488 | CMD(mgmt_tx, FRAME); |
| 1489 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1490 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1491 | i++; |
| 1492 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1493 | goto nla_put_failure; |
| 1494 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1495 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1496 | rdev->ops->join_mesh) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1497 | i++; |
| 1498 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1499 | goto nla_put_failure; |
| 1500 | } |
| 1501 | CMD(set_wds_peer, SET_WDS_PEER); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1502 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1503 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1504 | CMD(tdls_oper, TDLS_OPER); |
| 1505 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1506 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1507 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1508 | CMD(probe_client, PROBE_CLIENT); |
| 1509 | CMD(set_noack_map, SET_NOACK_MAP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1510 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1511 | i++; |
| 1512 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1513 | goto nla_put_failure; |
| 1514 | } |
| 1515 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1516 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1517 | #ifdef CONFIG_NL80211_TESTMODE |
| 1518 | CMD(testmode_cmd, TESTMODE); |
| 1519 | #endif |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1520 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1521 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1522 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1523 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1524 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1525 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 1526 | if (rdev->wiphy.features & |
| 1527 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 1528 | CMD(add_tx_ts, ADD_TX_TS); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1529 | } |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1530 | /* add into the if now */ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1531 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1532 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1533 | if (rdev->ops->connect || rdev->ops->auth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1534 | i++; |
| 1535 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1536 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1537 | } |
| 1538 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1539 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1540 | i++; |
| 1541 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1542 | goto nla_put_failure; |
| 1543 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1544 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1545 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1546 | state->split_start++; |
| 1547 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1548 | break; |
| 1549 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1550 | if (rdev->ops->remain_on_channel && |
| 1551 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1552 | nla_put_u32(msg, |
| 1553 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1554 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1555 | goto nla_put_failure; |
| 1556 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1557 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1558 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1559 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1560 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1561 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1562 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1563 | state->split_start++; |
| 1564 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1565 | break; |
| 1566 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1567 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1568 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1569 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1570 | state->split_start++; |
| 1571 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1572 | break; |
| 1573 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1574 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1575 | #endif |
| 1576 | case 7: |
| 1577 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1578 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1579 | goto nla_put_failure; |
| 1580 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1581 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1582 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1583 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1584 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1585 | state->split_start++; |
| 1586 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1587 | break; |
| 1588 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1589 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1590 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1591 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1592 | goto nla_put_failure; |
| 1593 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1594 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1595 | /* |
| 1596 | * We can only add the per-channel limit information if the |
| 1597 | * dump is split, otherwise it makes it too big. Therefore |
| 1598 | * only advertise it in that case. |
| 1599 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1600 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1601 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1602 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1603 | goto nla_put_failure; |
| 1604 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1605 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1606 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1607 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 1608 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1609 | goto nla_put_failure; |
| 1610 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1611 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1612 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1613 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1614 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1615 | goto nla_put_failure; |
| 1616 | |
| 1617 | /* |
| 1618 | * Any information below this point is only available to |
| 1619 | * applications that can deal with it being split. This |
| 1620 | * helps ensure that newly added capabilities don't break |
| 1621 | * older tools by overrunning their buffers. |
| 1622 | * |
| 1623 | * We still increment split_start so that in the split |
| 1624 | * case we'll continue with more data in the next round, |
| 1625 | * but break unconditionally so unsplit data stops here. |
| 1626 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1627 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1628 | break; |
| 1629 | case 9: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1630 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1631 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1632 | rdev->wiphy.extended_capabilities_len, |
| 1633 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1634 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1635 | rdev->wiphy.extended_capabilities_len, |
| 1636 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1637 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1638 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1639 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1640 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1641 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 1642 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1643 | goto nla_put_failure; |
| 1644 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1645 | state->split_start++; |
| 1646 | break; |
| 1647 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1648 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1649 | goto nla_put_failure; |
| 1650 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1651 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1652 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1653 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1654 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1655 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1656 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1657 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1658 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1659 | goto nla_put_failure; |
| 1660 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1661 | state->split_start++; |
| 1662 | break; |
| 1663 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1664 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1665 | const struct nl80211_vendor_cmd_info *info; |
| 1666 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1667 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1668 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1669 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1670 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1671 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1672 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 1673 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1674 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1675 | goto nla_put_failure; |
| 1676 | } |
| 1677 | nla_nest_end(msg, nested); |
| 1678 | } |
| 1679 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1680 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1681 | const struct nl80211_vendor_cmd_info *info; |
| 1682 | struct nlattr *nested; |
| 1683 | |
| 1684 | nested = nla_nest_start(msg, |
| 1685 | NL80211_ATTR_VENDOR_EVENTS); |
| 1686 | if (!nested) |
| 1687 | goto nla_put_failure; |
| 1688 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1689 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 1690 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1691 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1692 | goto nla_put_failure; |
| 1693 | } |
| 1694 | nla_nest_end(msg, nested); |
| 1695 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 1696 | state->split_start++; |
| 1697 | break; |
| 1698 | case 12: |
| 1699 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 1700 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 1701 | rdev->wiphy.max_num_csa_counters)) |
| 1702 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1703 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1704 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1705 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1706 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1707 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1708 | finish: |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1709 | return genlmsg_end(msg, hdr); |
| 1710 | |
| 1711 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1712 | genlmsg_cancel(msg, hdr); |
| 1713 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1714 | } |
| 1715 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1716 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1717 | struct netlink_callback *cb, |
| 1718 | struct nl80211_dump_wiphy_state *state) |
| 1719 | { |
| 1720 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1721 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1722 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1723 | /* ignore parse errors for backward compatibility */ |
| 1724 | if (ret) |
| 1725 | return 0; |
| 1726 | |
| 1727 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1728 | if (tb[NL80211_ATTR_WIPHY]) |
| 1729 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1730 | if (tb[NL80211_ATTR_WDEV]) |
| 1731 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1732 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1733 | struct net_device *netdev; |
| 1734 | struct cfg80211_registered_device *rdev; |
| 1735 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1736 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1737 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1738 | if (!netdev) |
| 1739 | return -ENODEV; |
| 1740 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1741 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1742 | netdev->ieee80211_ptr->wiphy); |
| 1743 | state->filter_wiphy = rdev->wiphy_idx; |
| 1744 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1745 | } |
| 1746 | |
| 1747 | return 0; |
| 1748 | } |
| 1749 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1750 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1751 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1752 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1753 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1754 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1755 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1756 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1757 | if (!state) { |
| 1758 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1759 | if (!state) { |
| 1760 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1761 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1762 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1763 | state->filter_wiphy = -1; |
| 1764 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1765 | if (ret) { |
| 1766 | kfree(state); |
| 1767 | rtnl_unlock(); |
| 1768 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1769 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1770 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1771 | } |
| 1772 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1773 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1774 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1775 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1776 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1777 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1778 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1779 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1780 | continue; |
| 1781 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1782 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1783 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 1784 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1785 | NETLINK_CB(cb->skb).portid, |
| 1786 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1787 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1788 | if (ret < 0) { |
| 1789 | /* |
| 1790 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1791 | * or EMSGSIZE returned), this SKB is still |
| 1792 | * empty (so it's not too big because another |
| 1793 | * wiphy dataset is already in the skb) and |
| 1794 | * we've not tried to adjust the dump allocation |
| 1795 | * yet ... then adjust the alloc size to be |
| 1796 | * bigger, and return 1 but with the empty skb. |
| 1797 | * This results in an empty message being RX'ed |
| 1798 | * in userspace, but that is ignored. |
| 1799 | * |
| 1800 | * We can then retry with the larger buffer. |
| 1801 | */ |
| 1802 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1803 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1804 | cb->min_dump_alloc < 4096) { |
| 1805 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1806 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1807 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1808 | return 1; |
| 1809 | } |
| 1810 | idx--; |
| 1811 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1812 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1813 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1814 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1815 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1816 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1817 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1818 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1819 | |
| 1820 | return skb->len; |
| 1821 | } |
| 1822 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1823 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1824 | { |
| 1825 | kfree((void *)cb->args[0]); |
| 1826 | return 0; |
| 1827 | } |
| 1828 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1829 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1830 | { |
| 1831 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1832 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1833 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1834 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1835 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1836 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1837 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1838 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1839 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 1840 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1841 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1842 | nlmsg_free(msg); |
| 1843 | return -ENOBUFS; |
| 1844 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1845 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1846 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1847 | } |
| 1848 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1849 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1850 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1851 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1852 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1853 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1854 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1855 | }; |
| 1856 | |
| 1857 | static int parse_txq_params(struct nlattr *tb[], |
| 1858 | struct ieee80211_txq_params *txq_params) |
| 1859 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1860 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1861 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1862 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1863 | return -EINVAL; |
| 1864 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1865 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1866 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1867 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1868 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1869 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1870 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1871 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1872 | return -EINVAL; |
| 1873 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1874 | return 0; |
| 1875 | } |
| 1876 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1877 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1878 | { |
| 1879 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1880 | * You can only set the channel explicitly for WDS interfaces, |
| 1881 | * all others have their channel managed via their respective |
| 1882 | * "establish a connection" command (connect, join, ...) |
| 1883 | * |
| 1884 | * For AP/GO and mesh mode, the channel can be set with the |
| 1885 | * channel userspace API, but is only stored and passed to the |
| 1886 | * low-level driver when the AP starts or the mesh is joined. |
| 1887 | * This is for backward compatibility, userspace can also give |
| 1888 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1889 | * |
| 1890 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1891 | * whatever else is going on, so they have their own special |
| 1892 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1893 | */ |
| 1894 | return !wdev || |
| 1895 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1896 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1897 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1898 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1899 | } |
| 1900 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1901 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1902 | struct genl_info *info, |
| 1903 | struct cfg80211_chan_def *chandef) |
| 1904 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1905 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1906 | |
| 1907 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1908 | return -EINVAL; |
| 1909 | |
| 1910 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1911 | |
| 1912 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1913 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1914 | chandef->center_freq1 = control_freq; |
| 1915 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1916 | |
| 1917 | /* Primary channel not allowed */ |
| 1918 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1919 | return -EINVAL; |
| 1920 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1921 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1922 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1923 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1924 | chantype = nla_get_u32( |
| 1925 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1926 | |
| 1927 | switch (chantype) { |
| 1928 | case NL80211_CHAN_NO_HT: |
| 1929 | case NL80211_CHAN_HT20: |
| 1930 | case NL80211_CHAN_HT40PLUS: |
| 1931 | case NL80211_CHAN_HT40MINUS: |
| 1932 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1933 | chantype); |
| 1934 | break; |
| 1935 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1936 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1937 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1938 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1939 | chandef->width = |
| 1940 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1941 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1942 | chandef->center_freq1 = |
| 1943 | nla_get_u32( |
| 1944 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1945 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1946 | chandef->center_freq2 = |
| 1947 | nla_get_u32( |
| 1948 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1949 | } |
| 1950 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1951 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1952 | return -EINVAL; |
| 1953 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1954 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1955 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1956 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1957 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1958 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1959 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1960 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1961 | return -EINVAL; |
| 1962 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1963 | return 0; |
| 1964 | } |
| 1965 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1966 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1967 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1968 | struct genl_info *info) |
| 1969 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1970 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1971 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1972 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1973 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1974 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1975 | if (dev) |
| 1976 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1977 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1978 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1979 | if (wdev) |
| 1980 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1981 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1982 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1983 | if (result) |
| 1984 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1985 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1986 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1987 | case NL80211_IFTYPE_AP: |
| 1988 | case NL80211_IFTYPE_P2P_GO: |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1989 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1990 | result = -EINVAL; |
| 1991 | break; |
| 1992 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1993 | if (wdev->beacon_interval) { |
| 1994 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 1995 | !(rdev->wiphy.features & |
| 1996 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 1997 | result = -EBUSY; |
| 1998 | break; |
| 1999 | } |
| 2000 | |
| 2001 | /* Only allow dynamic channel width changes */ |
| 2002 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 2003 | result = -EBUSY; |
| 2004 | break; |
| 2005 | } |
| 2006 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 2007 | if (result) |
| 2008 | break; |
| 2009 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2010 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2011 | result = 0; |
| 2012 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2013 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2014 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2015 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2016 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2017 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2018 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2019 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2020 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2021 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2022 | |
| 2023 | return result; |
| 2024 | } |
| 2025 | |
| 2026 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 2027 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2028 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2029 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2030 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2031 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2032 | } |
| 2033 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2034 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 2035 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2036 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2037 | struct net_device *dev = info->user_ptr[1]; |
| 2038 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2039 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2040 | |
| 2041 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2042 | return -EINVAL; |
| 2043 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2044 | if (netif_running(dev)) |
| 2045 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2046 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2047 | if (!rdev->ops->set_wds_peer) |
| 2048 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2049 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2050 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 2051 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2052 | |
| 2053 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2054 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2055 | } |
| 2056 | |
| 2057 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2058 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2059 | { |
| 2060 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2061 | struct net_device *netdev = NULL; |
| 2062 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2063 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2064 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2065 | u32 changed; |
| 2066 | u8 retry_short = 0, retry_long = 0; |
| 2067 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2068 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2069 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2070 | ASSERT_RTNL(); |
| 2071 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2072 | /* |
| 2073 | * Try to find the wiphy and netdev. Normally this |
| 2074 | * function shouldn't need the netdev, but this is |
| 2075 | * done for backward compatibility -- previously |
| 2076 | * setting the channel was done per wiphy, but now |
| 2077 | * it is per netdev. Previous userland like hostapd |
| 2078 | * also passed a netdev to set_wiphy, so that it is |
| 2079 | * possible to let that go to the right netdev! |
| 2080 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2081 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2082 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2083 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2084 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2085 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2086 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2087 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2088 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2089 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2090 | } |
| 2091 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2092 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2093 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2094 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2095 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2096 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2097 | wdev = NULL; |
| 2098 | netdev = NULL; |
| 2099 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2100 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2101 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2102 | |
| 2103 | /* |
| 2104 | * end workaround code, by now the rdev is available |
| 2105 | * and locked, and wdev may or may not be NULL. |
| 2106 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2107 | |
| 2108 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2109 | result = cfg80211_dev_rename( |
| 2110 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2111 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2112 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2113 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2114 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2115 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2116 | struct ieee80211_txq_params txq_params; |
| 2117 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2118 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2119 | if (!rdev->ops->set_txq_params) |
| 2120 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2121 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2122 | if (!netdev) |
| 2123 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2124 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2125 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2126 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2127 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2128 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2129 | if (!netif_running(netdev)) |
| 2130 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2131 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2132 | nla_for_each_nested(nl_txq_params, |
| 2133 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2134 | rem_txq_params) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2135 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 2136 | nla_data(nl_txq_params), |
| 2137 | nla_len(nl_txq_params), |
| 2138 | txq_params_policy); |
| 2139 | if (result) |
| 2140 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2141 | result = parse_txq_params(tb, &txq_params); |
| 2142 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2143 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2144 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2145 | result = rdev_set_txq_params(rdev, netdev, |
| 2146 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 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 | } |
| 2150 | } |
| 2151 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2152 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2153 | result = __nl80211_set_channel( |
| 2154 | rdev, |
| 2155 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 2156 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2157 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2158 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2159 | } |
| 2160 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2161 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2162 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2163 | enum nl80211_tx_power_setting type; |
| 2164 | int idx, mbm = 0; |
| 2165 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2166 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2167 | txp_wdev = NULL; |
| 2168 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2169 | if (!rdev->ops->set_tx_power) |
| 2170 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2171 | |
| 2172 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2173 | type = nla_get_u32(info->attrs[idx]); |
| 2174 | |
| 2175 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2176 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2177 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2178 | |
| 2179 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2180 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2181 | mbm = nla_get_u32(info->attrs[idx]); |
| 2182 | } |
| 2183 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2184 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2185 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2186 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2187 | } |
| 2188 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2189 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2190 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2191 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2192 | if ((!rdev->wiphy.available_antennas_tx && |
| 2193 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2194 | !rdev->ops->set_antenna) |
| 2195 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2196 | |
| 2197 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2198 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2199 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2200 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2201 | * available antenna masks, except for the "all" mask */ |
| 2202 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2203 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2204 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2205 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2206 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2207 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2208 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2209 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2210 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2211 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2212 | } |
| 2213 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2214 | changed = 0; |
| 2215 | |
| 2216 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2217 | retry_short = nla_get_u8( |
| 2218 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2219 | if (retry_short == 0) |
| 2220 | return -EINVAL; |
| 2221 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2222 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2223 | } |
| 2224 | |
| 2225 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2226 | retry_long = nla_get_u8( |
| 2227 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2228 | if (retry_long == 0) |
| 2229 | return -EINVAL; |
| 2230 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2231 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2232 | } |
| 2233 | |
| 2234 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2235 | frag_threshold = nla_get_u32( |
| 2236 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2237 | if (frag_threshold < 256) |
| 2238 | return -EINVAL; |
| 2239 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2240 | if (frag_threshold != (u32) -1) { |
| 2241 | /* |
| 2242 | * Fragments (apart from the last one) are required to |
| 2243 | * have even length. Make the fragmentation code |
| 2244 | * simpler by stripping LSB should someone try to use |
| 2245 | * odd threshold value. |
| 2246 | */ |
| 2247 | frag_threshold &= ~0x1; |
| 2248 | } |
| 2249 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2250 | } |
| 2251 | |
| 2252 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2253 | rts_threshold = nla_get_u32( |
| 2254 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2255 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2256 | } |
| 2257 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2258 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2259 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 2260 | return -EINVAL; |
| 2261 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2262 | coverage_class = nla_get_u8( |
| 2263 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2264 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2265 | } |
| 2266 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2267 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 2268 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 2269 | return -EOPNOTSUPP; |
| 2270 | |
| 2271 | changed |= WIPHY_PARAM_DYN_ACK; |
| 2272 | } |
| 2273 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2274 | if (changed) { |
| 2275 | u8 old_retry_short, old_retry_long; |
| 2276 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2277 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2278 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2279 | if (!rdev->ops->set_wiphy_params) |
| 2280 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2281 | |
| 2282 | old_retry_short = rdev->wiphy.retry_short; |
| 2283 | old_retry_long = rdev->wiphy.retry_long; |
| 2284 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2285 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2286 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2287 | |
| 2288 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2289 | rdev->wiphy.retry_short = retry_short; |
| 2290 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2291 | rdev->wiphy.retry_long = retry_long; |
| 2292 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2293 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2294 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2295 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2296 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2297 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2298 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2299 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2300 | if (result) { |
| 2301 | rdev->wiphy.retry_short = old_retry_short; |
| 2302 | rdev->wiphy.retry_long = old_retry_long; |
| 2303 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2304 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2305 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2306 | } |
| 2307 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2308 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2309 | } |
| 2310 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2311 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2312 | { |
| 2313 | return (u64)wdev->identifier | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2314 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2315 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2316 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2317 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2318 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2319 | { |
Johannes Berg | 601555c | 2014-11-27 17:26:56 +0100 | [diff] [blame] | 2320 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 2321 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2322 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2323 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2324 | chandef->chan->center_freq)) |
| 2325 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2326 | switch (chandef->width) { |
| 2327 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2328 | case NL80211_CHAN_WIDTH_20: |
| 2329 | case NL80211_CHAN_WIDTH_40: |
| 2330 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2331 | cfg80211_get_chandef_type(chandef))) |
| 2332 | return -ENOBUFS; |
| 2333 | break; |
| 2334 | default: |
| 2335 | break; |
| 2336 | } |
| 2337 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2338 | return -ENOBUFS; |
| 2339 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2340 | return -ENOBUFS; |
| 2341 | if (chandef->center_freq2 && |
| 2342 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2343 | return -ENOBUFS; |
| 2344 | return 0; |
| 2345 | } |
| 2346 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2347 | 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] | 2348 | struct cfg80211_registered_device *rdev, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2349 | struct wireless_dev *wdev, bool removal) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2350 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2351 | struct net_device *dev = wdev->netdev; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2352 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2353 | void *hdr; |
| 2354 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2355 | if (removal) |
| 2356 | cmd = NL80211_CMD_DEL_INTERFACE; |
| 2357 | |
| 2358 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2359 | if (!hdr) |
| 2360 | return -1; |
| 2361 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2362 | if (dev && |
| 2363 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2364 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2365 | goto nla_put_failure; |
| 2366 | |
| 2367 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2368 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2369 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2370 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2371 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2372 | rdev->devlist_generation ^ |
| 2373 | (cfg80211_rdev_list_generation << 2))) |
| 2374 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2375 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2376 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2377 | int ret; |
| 2378 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2379 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2380 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2381 | if (ret == 0) { |
| 2382 | if (nl80211_send_chandef(msg, &chandef)) |
| 2383 | goto nla_put_failure; |
| 2384 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2385 | } |
| 2386 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2387 | if (wdev->ssid_len) { |
| 2388 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2389 | goto nla_put_failure; |
| 2390 | } |
| 2391 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2392 | return genlmsg_end(msg, hdr); |
| 2393 | |
| 2394 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2395 | genlmsg_cancel(msg, hdr); |
| 2396 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2397 | } |
| 2398 | |
| 2399 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2400 | { |
| 2401 | int wp_idx = 0; |
| 2402 | int if_idx = 0; |
| 2403 | int wp_start = cb->args[0]; |
| 2404 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2405 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2406 | struct wireless_dev *wdev; |
| 2407 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2408 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2409 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2410 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2411 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2412 | if (wp_idx < wp_start) { |
| 2413 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2414 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2415 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2416 | if_idx = 0; |
| 2417 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2418 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2419 | if (if_idx < if_start) { |
| 2420 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2421 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2422 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2423 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2424 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2425 | rdev, wdev, false) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2426 | goto out; |
| 2427 | } |
| 2428 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2429 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2430 | |
| 2431 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2432 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2433 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2434 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2435 | |
| 2436 | cb->args[0] = wp_idx; |
| 2437 | cb->args[1] = if_idx; |
| 2438 | |
| 2439 | return skb->len; |
| 2440 | } |
| 2441 | |
| 2442 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2443 | { |
| 2444 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2445 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2446 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2447 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2448 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2449 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2450 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2451 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2452 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2453 | rdev, wdev, false) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2454 | nlmsg_free(msg); |
| 2455 | return -ENOBUFS; |
| 2456 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2457 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2458 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2459 | } |
| 2460 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2461 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2462 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2463 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2464 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2465 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2466 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2467 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2468 | }; |
| 2469 | |
| 2470 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2471 | { |
| 2472 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2473 | int flag; |
| 2474 | |
| 2475 | *mntrflags = 0; |
| 2476 | |
| 2477 | if (!nla) |
| 2478 | return -EINVAL; |
| 2479 | |
| 2480 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2481 | nla, mntr_flags_policy)) |
| 2482 | return -EINVAL; |
| 2483 | |
| 2484 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2485 | if (flags[flag]) |
| 2486 | *mntrflags |= (1<<flag); |
| 2487 | |
| 2488 | return 0; |
| 2489 | } |
| 2490 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2491 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2492 | struct net_device *netdev, u8 use_4addr, |
| 2493 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2494 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2495 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2496 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2497 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2498 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2499 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2500 | |
| 2501 | switch (iftype) { |
| 2502 | case NL80211_IFTYPE_AP_VLAN: |
| 2503 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2504 | return 0; |
| 2505 | break; |
| 2506 | case NL80211_IFTYPE_STATION: |
| 2507 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2508 | return 0; |
| 2509 | break; |
| 2510 | default: |
| 2511 | break; |
| 2512 | } |
| 2513 | |
| 2514 | return -EOPNOTSUPP; |
| 2515 | } |
| 2516 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2517 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2518 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2519 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2520 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2521 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2522 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2523 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2524 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2525 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2526 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2527 | memset(¶ms, 0, sizeof(params)); |
| 2528 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2529 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2530 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2531 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2532 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2533 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2534 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2535 | if (ntype > NL80211_IFTYPE_MAX) |
| 2536 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2537 | } |
| 2538 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2539 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2540 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2541 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2542 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2543 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2544 | if (netif_running(dev)) |
| 2545 | return -EBUSY; |
| 2546 | |
| 2547 | wdev_lock(wdev); |
| 2548 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2549 | IEEE80211_MAX_MESH_ID_LEN); |
| 2550 | wdev->mesh_id_up_len = |
| 2551 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2552 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2553 | wdev->mesh_id_up_len); |
| 2554 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2555 | } |
| 2556 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2557 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2558 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2559 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2560 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2561 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2562 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2563 | } else { |
| 2564 | params.use_4addr = -1; |
| 2565 | } |
| 2566 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2567 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2568 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2569 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2570 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2571 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2572 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2573 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2574 | |
| 2575 | flags = &_flags; |
| 2576 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2577 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2578 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2579 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2580 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2581 | return -EOPNOTSUPP; |
| 2582 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2583 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2584 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2585 | else |
| 2586 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2587 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2588 | if (!err && params.use_4addr != -1) |
| 2589 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2590 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2591 | return err; |
| 2592 | } |
| 2593 | |
| 2594 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2595 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2596 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2597 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2598 | struct wireless_dev *wdev; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2599 | struct sk_buff *msg, *event; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2600 | int err; |
| 2601 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2602 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2603 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2604 | /* to avoid failing a new interface creation due to pending removal */ |
| 2605 | cfg80211_destroy_ifaces(rdev); |
| 2606 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2607 | memset(¶ms, 0, sizeof(params)); |
| 2608 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2609 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2610 | return -EINVAL; |
| 2611 | |
| 2612 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2613 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2614 | if (type > NL80211_IFTYPE_MAX) |
| 2615 | return -EINVAL; |
| 2616 | } |
| 2617 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2618 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2619 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2620 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2621 | |
Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 2622 | if ((type == NL80211_IFTYPE_P2P_DEVICE || |
| 2623 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 2624 | info->attrs[NL80211_ATTR_MAC]) { |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2625 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2626 | ETH_ALEN); |
| 2627 | if (!is_valid_ether_addr(params.macaddr)) |
| 2628 | return -EADDRNOTAVAIL; |
| 2629 | } |
| 2630 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2631 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2632 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2633 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2634 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2635 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2636 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2637 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2638 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2639 | if (!msg) |
| 2640 | return -ENOMEM; |
| 2641 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2642 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2643 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2644 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2645 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2646 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2647 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2648 | return -EOPNOTSUPP; |
| 2649 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2650 | wdev = rdev_add_virtual_intf(rdev, |
| 2651 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2652 | type, err ? NULL : &flags, ¶ms); |
Rafał Miłecki | d687cbb | 2014-11-14 18:43:28 +0100 | [diff] [blame] | 2653 | if (WARN_ON(!wdev)) { |
| 2654 | nlmsg_free(msg); |
| 2655 | return -EPROTO; |
| 2656 | } else if (IS_ERR(wdev)) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2657 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2658 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2659 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2660 | |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 2661 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2662 | wdev->owner_nlportid = info->snd_portid; |
| 2663 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2664 | switch (type) { |
| 2665 | case NL80211_IFTYPE_MESH_POINT: |
| 2666 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2667 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2668 | wdev_lock(wdev); |
| 2669 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2670 | IEEE80211_MAX_MESH_ID_LEN); |
| 2671 | wdev->mesh_id_up_len = |
| 2672 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2673 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2674 | wdev->mesh_id_up_len); |
| 2675 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2676 | break; |
| 2677 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2678 | /* |
| 2679 | * P2P Device doesn't have a netdev, so doesn't go |
| 2680 | * through the netdev notifier and must be added here |
| 2681 | */ |
| 2682 | mutex_init(&wdev->mtx); |
| 2683 | INIT_LIST_HEAD(&wdev->event_list); |
| 2684 | spin_lock_init(&wdev->event_lock); |
| 2685 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2686 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2687 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2688 | wdev->identifier = ++rdev->wdev_id; |
| 2689 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2690 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2691 | break; |
| 2692 | default: |
| 2693 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2694 | } |
| 2695 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2696 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2697 | rdev, wdev, false) < 0) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2698 | nlmsg_free(msg); |
| 2699 | return -ENOBUFS; |
| 2700 | } |
| 2701 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2702 | event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2703 | if (event) { |
| 2704 | if (nl80211_send_iface(event, 0, 0, 0, |
| 2705 | rdev, wdev, false) < 0) { |
| 2706 | nlmsg_free(event); |
| 2707 | goto out; |
| 2708 | } |
| 2709 | |
| 2710 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 2711 | event, 0, NL80211_MCGRP_CONFIG, |
| 2712 | GFP_KERNEL); |
| 2713 | } |
| 2714 | |
| 2715 | out: |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2716 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2717 | } |
| 2718 | |
| 2719 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2720 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2721 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2722 | struct wireless_dev *wdev = info->user_ptr[1]; |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2723 | struct sk_buff *msg; |
| 2724 | int status; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2725 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2726 | if (!rdev->ops->del_virtual_intf) |
| 2727 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2728 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2729 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2730 | if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) { |
| 2731 | nlmsg_free(msg); |
| 2732 | msg = NULL; |
| 2733 | } |
| 2734 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2735 | /* |
| 2736 | * If we remove a wireless device without a netdev then clear |
| 2737 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2738 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2739 | * since the wdev has been freed, unlike with a netdev where |
| 2740 | * we need the dev_put() for the netdev to really be freed. |
| 2741 | */ |
| 2742 | if (!wdev->netdev) |
| 2743 | info->user_ptr[1] = NULL; |
| 2744 | |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 2745 | status = rdev_del_virtual_intf(rdev, wdev); |
| 2746 | if (status >= 0 && msg) |
| 2747 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 2748 | msg, 0, NL80211_MCGRP_CONFIG, |
| 2749 | GFP_KERNEL); |
| 2750 | else |
| 2751 | nlmsg_free(msg); |
| 2752 | |
| 2753 | return status; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2754 | } |
| 2755 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2756 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2757 | { |
| 2758 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2759 | struct net_device *dev = info->user_ptr[1]; |
| 2760 | u16 noack_map; |
| 2761 | |
| 2762 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2763 | return -EINVAL; |
| 2764 | |
| 2765 | if (!rdev->ops->set_noack_map) |
| 2766 | return -EOPNOTSUPP; |
| 2767 | |
| 2768 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2769 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2770 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2771 | } |
| 2772 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2773 | struct get_key_cookie { |
| 2774 | struct sk_buff *msg; |
| 2775 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2776 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2777 | }; |
| 2778 | |
| 2779 | static void get_key_callback(void *c, struct key_params *params) |
| 2780 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2781 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2782 | struct get_key_cookie *cookie = c; |
| 2783 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2784 | if ((params->key && |
| 2785 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2786 | params->key_len, params->key)) || |
| 2787 | (params->seq && |
| 2788 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2789 | params->seq_len, params->seq)) || |
| 2790 | (params->cipher && |
| 2791 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2792 | params->cipher))) |
| 2793 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2794 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2795 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2796 | if (!key) |
| 2797 | goto nla_put_failure; |
| 2798 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2799 | if ((params->key && |
| 2800 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2801 | params->key_len, params->key)) || |
| 2802 | (params->seq && |
| 2803 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2804 | params->seq_len, params->seq)) || |
| 2805 | (params->cipher && |
| 2806 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2807 | params->cipher))) |
| 2808 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2809 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2810 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2811 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2812 | |
| 2813 | nla_nest_end(cookie->msg, key); |
| 2814 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2815 | return; |
| 2816 | nla_put_failure: |
| 2817 | cookie->error = 1; |
| 2818 | } |
| 2819 | |
| 2820 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2821 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2822 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2823 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2824 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2825 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2826 | const u8 *mac_addr = NULL; |
| 2827 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2828 | struct get_key_cookie cookie = { |
| 2829 | .error = 0, |
| 2830 | }; |
| 2831 | void *hdr; |
| 2832 | struct sk_buff *msg; |
| 2833 | |
| 2834 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2835 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2836 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2837 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2838 | return -EINVAL; |
| 2839 | |
| 2840 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2841 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2842 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2843 | pairwise = !!mac_addr; |
| 2844 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2845 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2846 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2847 | return -EINVAL; |
| 2848 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2849 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2850 | return -EINVAL; |
| 2851 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2852 | } |
| 2853 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2854 | if (!rdev->ops->get_key) |
| 2855 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2856 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2857 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2858 | if (!msg) |
| 2859 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2860 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2861 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2862 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2863 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 2864 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2865 | |
| 2866 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2867 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2868 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2869 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2870 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2871 | goto nla_put_failure; |
| 2872 | if (mac_addr && |
| 2873 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2874 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2875 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2876 | if (pairwise && mac_addr && |
| 2877 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2878 | return -ENOENT; |
| 2879 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2880 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2881 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2882 | |
| 2883 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2884 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2885 | |
| 2886 | if (cookie.error) |
| 2887 | goto nla_put_failure; |
| 2888 | |
| 2889 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2890 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2891 | |
| 2892 | nla_put_failure: |
| 2893 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2894 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2895 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2896 | return err; |
| 2897 | } |
| 2898 | |
| 2899 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2900 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2901 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2902 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2903 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2904 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2905 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2906 | err = nl80211_parse_key(info, &key); |
| 2907 | if (err) |
| 2908 | return err; |
| 2909 | |
| 2910 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2911 | return -EINVAL; |
| 2912 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2913 | /* only support setting default key */ |
| 2914 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2915 | return -EINVAL; |
| 2916 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2917 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2918 | |
| 2919 | if (key.def) { |
| 2920 | if (!rdev->ops->set_default_key) { |
| 2921 | err = -EOPNOTSUPP; |
| 2922 | goto out; |
| 2923 | } |
| 2924 | |
| 2925 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2926 | if (err) |
| 2927 | goto out; |
| 2928 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2929 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2930 | key.def_uni, key.def_multi); |
| 2931 | |
| 2932 | if (err) |
| 2933 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2934 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2935 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2936 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2937 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2938 | } else { |
| 2939 | if (key.def_uni || !key.def_multi) { |
| 2940 | err = -EINVAL; |
| 2941 | goto out; |
| 2942 | } |
| 2943 | |
| 2944 | if (!rdev->ops->set_default_mgmt_key) { |
| 2945 | err = -EOPNOTSUPP; |
| 2946 | goto out; |
| 2947 | } |
| 2948 | |
| 2949 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2950 | if (err) |
| 2951 | goto out; |
| 2952 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2953 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2954 | if (err) |
| 2955 | goto out; |
| 2956 | |
| 2957 | #ifdef CONFIG_CFG80211_WEXT |
| 2958 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2959 | #endif |
| 2960 | } |
| 2961 | |
| 2962 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2963 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2964 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2965 | return err; |
| 2966 | } |
| 2967 | |
| 2968 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2969 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2970 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2971 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2972 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2973 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2974 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2975 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2976 | err = nl80211_parse_key(info, &key); |
| 2977 | if (err) |
| 2978 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2979 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2980 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2981 | return -EINVAL; |
| 2982 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2983 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2984 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2985 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2986 | if (key.type == -1) { |
| 2987 | if (mac_addr) |
| 2988 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2989 | else |
| 2990 | key.type = NL80211_KEYTYPE_GROUP; |
| 2991 | } |
| 2992 | |
| 2993 | /* for now */ |
| 2994 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2995 | key.type != NL80211_KEYTYPE_GROUP) |
| 2996 | return -EINVAL; |
| 2997 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2998 | if (!rdev->ops->add_key) |
| 2999 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3000 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3001 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 3002 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3003 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3004 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3005 | |
| 3006 | wdev_lock(dev->ieee80211_ptr); |
| 3007 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 3008 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3009 | err = rdev_add_key(rdev, dev, key.idx, |
| 3010 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3011 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3012 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3013 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3014 | return err; |
| 3015 | } |
| 3016 | |
| 3017 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 3018 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3019 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3020 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3021 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3022 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3023 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3024 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3025 | err = nl80211_parse_key(info, &key); |
| 3026 | if (err) |
| 3027 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3028 | |
| 3029 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3030 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3031 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3032 | if (key.type == -1) { |
| 3033 | if (mac_addr) |
| 3034 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 3035 | else |
| 3036 | key.type = NL80211_KEYTYPE_GROUP; |
| 3037 | } |
| 3038 | |
| 3039 | /* for now */ |
| 3040 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 3041 | key.type != NL80211_KEYTYPE_GROUP) |
| 3042 | return -EINVAL; |
| 3043 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3044 | if (!rdev->ops->del_key) |
| 3045 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3046 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3047 | wdev_lock(dev->ieee80211_ptr); |
| 3048 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3049 | |
| 3050 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 3051 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3052 | err = -ENOENT; |
| 3053 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3054 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3055 | err = rdev_del_key(rdev, dev, key.idx, |
| 3056 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3057 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3058 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3059 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3060 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3061 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3062 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3063 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3064 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 3065 | } |
| 3066 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3067 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3068 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3069 | return err; |
| 3070 | } |
| 3071 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3072 | /* This function returns an error or the number of nested attributes */ |
| 3073 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 3074 | { |
| 3075 | struct nlattr *attr; |
| 3076 | int n_entries = 0, tmp; |
| 3077 | |
| 3078 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 3079 | if (nla_len(attr) != ETH_ALEN) |
| 3080 | return -EINVAL; |
| 3081 | |
| 3082 | n_entries++; |
| 3083 | } |
| 3084 | |
| 3085 | return n_entries; |
| 3086 | } |
| 3087 | |
| 3088 | /* |
| 3089 | * This function parses ACL information and allocates memory for ACL data. |
| 3090 | * On successful return, the calling function is responsible to free the |
| 3091 | * ACL buffer returned by this function. |
| 3092 | */ |
| 3093 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 3094 | struct genl_info *info) |
| 3095 | { |
| 3096 | enum nl80211_acl_policy acl_policy; |
| 3097 | struct nlattr *attr; |
| 3098 | struct cfg80211_acl_data *acl; |
| 3099 | int i = 0, n_entries, tmp; |
| 3100 | |
| 3101 | if (!wiphy->max_acl_mac_addrs) |
| 3102 | return ERR_PTR(-EOPNOTSUPP); |
| 3103 | |
| 3104 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 3105 | return ERR_PTR(-EINVAL); |
| 3106 | |
| 3107 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 3108 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 3109 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 3110 | return ERR_PTR(-EINVAL); |
| 3111 | |
| 3112 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 3113 | return ERR_PTR(-EINVAL); |
| 3114 | |
| 3115 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 3116 | if (n_entries < 0) |
| 3117 | return ERR_PTR(n_entries); |
| 3118 | |
| 3119 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 3120 | return ERR_PTR(-ENOTSUPP); |
| 3121 | |
| 3122 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 3123 | GFP_KERNEL); |
| 3124 | if (!acl) |
| 3125 | return ERR_PTR(-ENOMEM); |
| 3126 | |
| 3127 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 3128 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3129 | i++; |
| 3130 | } |
| 3131 | |
| 3132 | acl->n_acl_entries = n_entries; |
| 3133 | acl->acl_policy = acl_policy; |
| 3134 | |
| 3135 | return acl; |
| 3136 | } |
| 3137 | |
| 3138 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3139 | { |
| 3140 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3141 | struct net_device *dev = info->user_ptr[1]; |
| 3142 | struct cfg80211_acl_data *acl; |
| 3143 | int err; |
| 3144 | |
| 3145 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3146 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3147 | return -EOPNOTSUPP; |
| 3148 | |
| 3149 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3150 | return -EINVAL; |
| 3151 | |
| 3152 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3153 | if (IS_ERR(acl)) |
| 3154 | return PTR_ERR(acl); |
| 3155 | |
| 3156 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3157 | |
| 3158 | kfree(acl); |
| 3159 | |
| 3160 | return err; |
| 3161 | } |
| 3162 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3163 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3164 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3165 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3166 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3167 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3168 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3169 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3170 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3171 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3172 | return -EINVAL; |
| 3173 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3174 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3175 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3176 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3177 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3178 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3179 | if (!bcn->head_len) |
| 3180 | return -EINVAL; |
| 3181 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3182 | } |
| 3183 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3184 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3185 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3186 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3187 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3188 | } |
| 3189 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3190 | if (!haveinfo) |
| 3191 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3192 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3193 | if (attrs[NL80211_ATTR_IE]) { |
| 3194 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3195 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3196 | } |
| 3197 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3198 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3199 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3200 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3201 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3202 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3203 | } |
| 3204 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3205 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3206 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3207 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3208 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3209 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3210 | } |
| 3211 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3212 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3213 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3214 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3215 | } |
| 3216 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3217 | return 0; |
| 3218 | } |
| 3219 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3220 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3221 | struct cfg80211_ap_settings *params) |
| 3222 | { |
| 3223 | struct wireless_dev *wdev; |
| 3224 | bool ret = false; |
| 3225 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3226 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3227 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3228 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3229 | continue; |
| 3230 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3231 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3232 | continue; |
| 3233 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3234 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3235 | ret = true; |
| 3236 | break; |
| 3237 | } |
| 3238 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3239 | return ret; |
| 3240 | } |
| 3241 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3242 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3243 | enum nl80211_auth_type auth_type, |
| 3244 | enum nl80211_commands cmd) |
| 3245 | { |
| 3246 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3247 | return false; |
| 3248 | |
| 3249 | switch (cmd) { |
| 3250 | case NL80211_CMD_AUTHENTICATE: |
| 3251 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3252 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3253 | return false; |
| 3254 | return true; |
| 3255 | case NL80211_CMD_CONNECT: |
| 3256 | case NL80211_CMD_START_AP: |
| 3257 | /* SAE not supported yet */ |
| 3258 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3259 | return false; |
| 3260 | return true; |
| 3261 | default: |
| 3262 | return false; |
| 3263 | } |
| 3264 | } |
| 3265 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3266 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3267 | { |
| 3268 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3269 | struct net_device *dev = info->user_ptr[1]; |
| 3270 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3271 | struct cfg80211_ap_settings params; |
| 3272 | int err; |
| 3273 | |
| 3274 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3275 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3276 | return -EOPNOTSUPP; |
| 3277 | |
| 3278 | if (!rdev->ops->start_ap) |
| 3279 | return -EOPNOTSUPP; |
| 3280 | |
| 3281 | if (wdev->beacon_interval) |
| 3282 | return -EALREADY; |
| 3283 | |
| 3284 | memset(¶ms, 0, sizeof(params)); |
| 3285 | |
| 3286 | /* these are required for START_AP */ |
| 3287 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3288 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3289 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3290 | return -EINVAL; |
| 3291 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3292 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3293 | if (err) |
| 3294 | return err; |
| 3295 | |
| 3296 | params.beacon_interval = |
| 3297 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3298 | params.dtim_period = |
| 3299 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3300 | |
| 3301 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3302 | if (err) |
| 3303 | return err; |
| 3304 | |
| 3305 | /* |
| 3306 | * In theory, some of these attributes should be required here |
| 3307 | * but since they were not used when the command was originally |
| 3308 | * added, keep them optional for old user space programs to let |
| 3309 | * them continue to work with drivers that do not need the |
| 3310 | * additional information -- drivers must check! |
| 3311 | */ |
| 3312 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3313 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3314 | params.ssid_len = |
| 3315 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3316 | if (params.ssid_len == 0 || |
| 3317 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3318 | return -EINVAL; |
| 3319 | } |
| 3320 | |
| 3321 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3322 | params.hidden_ssid = nla_get_u32( |
| 3323 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3324 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3325 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3326 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3327 | return -EINVAL; |
| 3328 | } |
| 3329 | |
| 3330 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3331 | |
| 3332 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3333 | params.auth_type = nla_get_u32( |
| 3334 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3335 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3336 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3337 | return -EINVAL; |
| 3338 | } else |
| 3339 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3340 | |
| 3341 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3342 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3343 | if (err) |
| 3344 | return err; |
| 3345 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3346 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3347 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3348 | return -EOPNOTSUPP; |
| 3349 | params.inactivity_timeout = nla_get_u16( |
| 3350 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3351 | } |
| 3352 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3353 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3354 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3355 | return -EINVAL; |
| 3356 | params.p2p_ctwindow = |
| 3357 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3358 | if (params.p2p_ctwindow > 127) |
| 3359 | return -EINVAL; |
| 3360 | if (params.p2p_ctwindow != 0 && |
| 3361 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3362 | return -EINVAL; |
| 3363 | } |
| 3364 | |
| 3365 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3366 | u8 tmp; |
| 3367 | |
| 3368 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3369 | return -EINVAL; |
| 3370 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3371 | if (tmp > 1) |
| 3372 | return -EINVAL; |
| 3373 | params.p2p_opp_ps = tmp; |
| 3374 | if (params.p2p_opp_ps != 0 && |
| 3375 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3376 | return -EINVAL; |
| 3377 | } |
| 3378 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3379 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3380 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3381 | if (err) |
| 3382 | return err; |
| 3383 | } else if (wdev->preset_chandef.chan) { |
| 3384 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3385 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3386 | return -EINVAL; |
| 3387 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 3388 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
| 3389 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3390 | return -EINVAL; |
| 3391 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3392 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3393 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3394 | if (IS_ERR(params.acl)) |
| 3395 | return PTR_ERR(params.acl); |
| 3396 | } |
| 3397 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 3398 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 3399 | params.smps_mode = |
| 3400 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 3401 | switch (params.smps_mode) { |
| 3402 | case NL80211_SMPS_OFF: |
| 3403 | break; |
| 3404 | case NL80211_SMPS_STATIC: |
| 3405 | if (!(rdev->wiphy.features & |
| 3406 | NL80211_FEATURE_STATIC_SMPS)) |
| 3407 | return -EINVAL; |
| 3408 | break; |
| 3409 | case NL80211_SMPS_DYNAMIC: |
| 3410 | if (!(rdev->wiphy.features & |
| 3411 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 3412 | return -EINVAL; |
| 3413 | break; |
| 3414 | default: |
| 3415 | return -EINVAL; |
| 3416 | } |
| 3417 | } else { |
| 3418 | params.smps_mode = NL80211_SMPS_OFF; |
| 3419 | } |
| 3420 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3421 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3422 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3423 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3424 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3425 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 3426 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3427 | wdev->ssid_len = params.ssid_len; |
| 3428 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3429 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3430 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3431 | |
| 3432 | kfree(params.acl); |
| 3433 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3434 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3435 | } |
| 3436 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3437 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3438 | { |
| 3439 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3440 | struct net_device *dev = info->user_ptr[1]; |
| 3441 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3442 | struct cfg80211_beacon_data params; |
| 3443 | int err; |
| 3444 | |
| 3445 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3446 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3447 | return -EOPNOTSUPP; |
| 3448 | |
| 3449 | if (!rdev->ops->change_beacon) |
| 3450 | return -EOPNOTSUPP; |
| 3451 | |
| 3452 | if (!wdev->beacon_interval) |
| 3453 | return -EINVAL; |
| 3454 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3455 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3456 | if (err) |
| 3457 | return err; |
| 3458 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3459 | wdev_lock(wdev); |
| 3460 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 3461 | wdev_unlock(wdev); |
| 3462 | |
| 3463 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3464 | } |
| 3465 | |
| 3466 | 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] | 3467 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3468 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3469 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3470 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 3471 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3472 | } |
| 3473 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3474 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3475 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3476 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3477 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3478 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3479 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3480 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3481 | }; |
| 3482 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3483 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3484 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3485 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3486 | { |
| 3487 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3488 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3489 | int flag; |
| 3490 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3491 | /* |
| 3492 | * Try parsing the new attribute first so userspace |
| 3493 | * can specify both for older kernels. |
| 3494 | */ |
| 3495 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3496 | if (nla) { |
| 3497 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3498 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3499 | sta_flags = nla_data(nla); |
| 3500 | params->sta_flags_mask = sta_flags->mask; |
| 3501 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3502 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3503 | if ((params->sta_flags_mask | |
| 3504 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3505 | return -EINVAL; |
| 3506 | return 0; |
| 3507 | } |
| 3508 | |
| 3509 | /* if present, parse the old attribute */ |
| 3510 | |
| 3511 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3512 | if (!nla) |
| 3513 | return 0; |
| 3514 | |
| 3515 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3516 | nla, sta_flags_policy)) |
| 3517 | return -EINVAL; |
| 3518 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3519 | /* |
| 3520 | * Only allow certain flags for interface types so that |
| 3521 | * other attributes are silently ignored. Remember that |
| 3522 | * this is backward compatibility code with old userspace |
| 3523 | * and shouldn't be hit in other cases anyway. |
| 3524 | */ |
| 3525 | switch (iftype) { |
| 3526 | case NL80211_IFTYPE_AP: |
| 3527 | case NL80211_IFTYPE_AP_VLAN: |
| 3528 | case NL80211_IFTYPE_P2P_GO: |
| 3529 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3530 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3531 | BIT(NL80211_STA_FLAG_WME) | |
| 3532 | BIT(NL80211_STA_FLAG_MFP); |
| 3533 | break; |
| 3534 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3535 | case NL80211_IFTYPE_STATION: |
| 3536 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3537 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3538 | break; |
| 3539 | case NL80211_IFTYPE_MESH_POINT: |
| 3540 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3541 | BIT(NL80211_STA_FLAG_MFP) | |
| 3542 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3543 | default: |
| 3544 | return -EINVAL; |
| 3545 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3546 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3547 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3548 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3549 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3550 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3551 | /* no longer support new API additions in old API */ |
| 3552 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3553 | return -EINVAL; |
| 3554 | } |
| 3555 | } |
| 3556 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3557 | return 0; |
| 3558 | } |
| 3559 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3560 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3561 | int attr) |
| 3562 | { |
| 3563 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3564 | u32 bitrate; |
| 3565 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3566 | |
| 3567 | rate = nla_nest_start(msg, attr); |
| 3568 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3569 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3570 | |
| 3571 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3572 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3573 | /* report 16-bit bitrate only if we can */ |
| 3574 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3575 | if (bitrate > 0 && |
| 3576 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3577 | return false; |
| 3578 | if (bitrate_compat > 0 && |
| 3579 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3580 | return false; |
| 3581 | |
| 3582 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3583 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3584 | return false; |
| 3585 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3586 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3587 | return false; |
| 3588 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3589 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3590 | return false; |
| 3591 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3592 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3593 | return false; |
| 3594 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3595 | return false; |
| 3596 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3597 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3598 | return false; |
| 3599 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3600 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3601 | return false; |
| 3602 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3603 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3604 | return false; |
| 3605 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3606 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3607 | return false; |
| 3608 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3609 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3610 | return false; |
| 3611 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3612 | |
| 3613 | nla_nest_end(msg, rate); |
| 3614 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3615 | } |
| 3616 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3617 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3618 | int id) |
| 3619 | { |
| 3620 | void *attr; |
| 3621 | int i = 0; |
| 3622 | |
| 3623 | if (!mask) |
| 3624 | return true; |
| 3625 | |
| 3626 | attr = nla_nest_start(msg, id); |
| 3627 | if (!attr) |
| 3628 | return false; |
| 3629 | |
| 3630 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3631 | if (!(mask & BIT(i))) |
| 3632 | continue; |
| 3633 | |
| 3634 | if (nla_put_u8(msg, i, signal[i])) |
| 3635 | return false; |
| 3636 | } |
| 3637 | |
| 3638 | nla_nest_end(msg, attr); |
| 3639 | |
| 3640 | return true; |
| 3641 | } |
| 3642 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3643 | 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] | 3644 | int flags, |
| 3645 | struct cfg80211_registered_device *rdev, |
| 3646 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3647 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3648 | { |
| 3649 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3650 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3651 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3652 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3653 | if (!hdr) |
| 3654 | return -1; |
| 3655 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3656 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3657 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3658 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3659 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3660 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3661 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3662 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3663 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3664 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3665 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3666 | sinfo->connected_time)) |
| 3667 | goto nla_put_failure; |
| 3668 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3669 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3670 | sinfo->inactive_time)) |
| 3671 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3672 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3673 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3674 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3675 | (u32)sinfo->rx_bytes)) |
| 3676 | goto nla_put_failure; |
| 3677 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3678 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3679 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3680 | (u32)sinfo->tx_bytes)) |
| 3681 | goto nla_put_failure; |
| 3682 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3683 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3684 | sinfo->rx_bytes)) |
| 3685 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3686 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3687 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3688 | sinfo->tx_bytes)) |
| 3689 | goto nla_put_failure; |
| 3690 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3691 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3692 | goto nla_put_failure; |
| 3693 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3694 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3695 | goto nla_put_failure; |
| 3696 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3697 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3698 | sinfo->plink_state)) |
| 3699 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3700 | switch (rdev->wiphy.signal_type) { |
| 3701 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3702 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3703 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3704 | sinfo->signal)) |
| 3705 | goto nla_put_failure; |
| 3706 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3707 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3708 | sinfo->signal_avg)) |
| 3709 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3710 | break; |
| 3711 | default: |
| 3712 | break; |
| 3713 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3714 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3715 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3716 | sinfo->chain_signal, |
| 3717 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3718 | goto nla_put_failure; |
| 3719 | } |
| 3720 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3721 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3722 | sinfo->chain_signal_avg, |
| 3723 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3724 | goto nla_put_failure; |
| 3725 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3726 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3727 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3728 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3729 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3730 | } |
| 3731 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3732 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3733 | NL80211_STA_INFO_RX_BITRATE)) |
| 3734 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3735 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3736 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3737 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3738 | sinfo->rx_packets)) |
| 3739 | goto nla_put_failure; |
| 3740 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3741 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3742 | sinfo->tx_packets)) |
| 3743 | goto nla_put_failure; |
| 3744 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3745 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3746 | sinfo->tx_retries)) |
| 3747 | goto nla_put_failure; |
| 3748 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3749 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3750 | sinfo->tx_failed)) |
| 3751 | goto nla_put_failure; |
Antonio Quartulli | 867d849 | 2014-05-19 21:53:19 +0200 | [diff] [blame] | 3752 | if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) && |
| 3753 | nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT, |
| 3754 | sinfo->expected_throughput)) |
| 3755 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3756 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3757 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3758 | sinfo->beacon_loss_count)) |
| 3759 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3760 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3761 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3762 | sinfo->local_pm)) |
| 3763 | goto nla_put_failure; |
| 3764 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3765 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3766 | sinfo->peer_pm)) |
| 3767 | goto nla_put_failure; |
| 3768 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3769 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3770 | sinfo->nonpeer_pm)) |
| 3771 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3772 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3773 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3774 | if (!bss_param) |
| 3775 | goto nla_put_failure; |
| 3776 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3777 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3778 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3779 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3780 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3781 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3782 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3783 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3784 | sinfo->bss_param.dtim_period) || |
| 3785 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3786 | sinfo->bss_param.beacon_interval)) |
| 3787 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3788 | |
| 3789 | nla_nest_end(msg, bss_param); |
| 3790 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3791 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3792 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3793 | sizeof(struct nl80211_sta_flag_update), |
| 3794 | &sinfo->sta_flags)) |
| 3795 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3796 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3797 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3798 | sinfo->t_offset)) |
| 3799 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3800 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3801 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3802 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3803 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3804 | sinfo->assoc_req_ies)) |
| 3805 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3806 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3807 | return genlmsg_end(msg, hdr); |
| 3808 | |
| 3809 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3810 | genlmsg_cancel(msg, hdr); |
| 3811 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3812 | } |
| 3813 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3814 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3815 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3816 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3817 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3818 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3819 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3820 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3821 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3822 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3823 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3824 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3825 | if (err) |
| 3826 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3827 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3828 | if (!wdev->netdev) { |
| 3829 | err = -EINVAL; |
| 3830 | goto out_err; |
| 3831 | } |
| 3832 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3833 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3834 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3835 | goto out_err; |
| 3836 | } |
| 3837 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3838 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3839 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3840 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3841 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3842 | if (err == -ENOENT) |
| 3843 | break; |
| 3844 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3845 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3846 | |
| 3847 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3848 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3849 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3850 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3851 | &sinfo) < 0) |
| 3852 | goto out; |
| 3853 | |
| 3854 | sta_idx++; |
| 3855 | } |
| 3856 | |
| 3857 | |
| 3858 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3859 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3860 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3861 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3862 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3863 | |
| 3864 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3865 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3866 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3867 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3868 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3869 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3870 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3871 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3872 | struct sk_buff *msg; |
| 3873 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3874 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3875 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3876 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3877 | |
| 3878 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3879 | return -EINVAL; |
| 3880 | |
| 3881 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3882 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3883 | if (!rdev->ops->get_station) |
| 3884 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3885 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3886 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3887 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3888 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3889 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3890 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3891 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3892 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3893 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3894 | 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] | 3895 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3896 | nlmsg_free(msg); |
| 3897 | return -ENOBUFS; |
| 3898 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3899 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3900 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3901 | } |
| 3902 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3903 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3904 | struct station_parameters *params, |
| 3905 | enum cfg80211_station_type statype) |
| 3906 | { |
| 3907 | if (params->listen_interval != -1) |
| 3908 | return -EINVAL; |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 3909 | if (params->aid && |
| 3910 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3911 | return -EINVAL; |
| 3912 | |
| 3913 | /* When you run into this, adjust the code below for the new flag */ |
| 3914 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3915 | |
| 3916 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3917 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3918 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3919 | /* |
| 3920 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3921 | * code doesn't have the bug of including TDLS in the |
| 3922 | * mask everywhere. |
| 3923 | */ |
| 3924 | if (params->sta_flags_mask & |
| 3925 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3926 | BIT(NL80211_STA_FLAG_MFP) | |
| 3927 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3928 | return -EINVAL; |
| 3929 | break; |
| 3930 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3931 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3932 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3933 | return -EINVAL; |
| 3934 | /* ignore since it can't change */ |
| 3935 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3936 | break; |
| 3937 | default: |
| 3938 | /* disallow mesh-specific things */ |
| 3939 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3940 | return -EINVAL; |
| 3941 | if (params->local_pm) |
| 3942 | return -EINVAL; |
| 3943 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3944 | return -EINVAL; |
| 3945 | } |
| 3946 | |
| 3947 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3948 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3949 | /* TDLS can't be set, ... */ |
| 3950 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3951 | return -EINVAL; |
| 3952 | /* |
| 3953 | * ... but don't bother the driver with it. This works around |
| 3954 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3955 | * TLDS_PEER flag in the mask even for AP mode. |
| 3956 | */ |
| 3957 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3958 | } |
| 3959 | |
| 3960 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3961 | /* reject other things that can't change */ |
| 3962 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3963 | return -EINVAL; |
| 3964 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3965 | return -EINVAL; |
| 3966 | if (params->supported_rates) |
| 3967 | return -EINVAL; |
| 3968 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3969 | return -EINVAL; |
| 3970 | } |
| 3971 | |
| 3972 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3973 | if (params->vlan) |
| 3974 | return -EINVAL; |
| 3975 | } |
| 3976 | |
| 3977 | switch (statype) { |
| 3978 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3979 | /* Use this only for authorizing/unauthorizing a station */ |
| 3980 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3981 | return -EOPNOTSUPP; |
| 3982 | break; |
| 3983 | case CFG80211_STA_AP_CLIENT: |
| 3984 | /* accept only the listed bits */ |
| 3985 | if (params->sta_flags_mask & |
| 3986 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3987 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3988 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3989 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3990 | BIT(NL80211_STA_FLAG_WME) | |
| 3991 | BIT(NL80211_STA_FLAG_MFP))) |
| 3992 | return -EINVAL; |
| 3993 | |
| 3994 | /* but authenticated/associated only if driver handles it */ |
| 3995 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3996 | params->sta_flags_mask & |
| 3997 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3998 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3999 | return -EINVAL; |
| 4000 | break; |
| 4001 | case CFG80211_STA_IBSS: |
| 4002 | case CFG80211_STA_AP_STA: |
| 4003 | /* reject any changes other than AUTHORIZED */ |
| 4004 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 4005 | return -EINVAL; |
| 4006 | break; |
| 4007 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 4008 | /* reject any changes other than AUTHORIZED or WME */ |
| 4009 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 4010 | BIT(NL80211_STA_FLAG_WME))) |
| 4011 | return -EINVAL; |
| 4012 | /* force (at least) rates when authorizing */ |
| 4013 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 4014 | !params->supported_rates) |
| 4015 | return -EINVAL; |
| 4016 | break; |
| 4017 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 4018 | /* reject any changes */ |
| 4019 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4020 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4021 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 4022 | return -EINVAL; |
| 4023 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 4024 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4025 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 4026 | return -EINVAL; |
| 4027 | break; |
| 4028 | } |
| 4029 | |
| 4030 | return 0; |
| 4031 | } |
| 4032 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 4033 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4034 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 4035 | * 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] | 4036 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4037 | static struct net_device *get_vlan(struct genl_info *info, |
| 4038 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4039 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4040 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4041 | struct net_device *v; |
| 4042 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4043 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4044 | if (!vlanattr) |
| 4045 | return NULL; |
| 4046 | |
| 4047 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 4048 | if (!v) |
| 4049 | return ERR_PTR(-ENODEV); |
| 4050 | |
| 4051 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 4052 | ret = -EINVAL; |
| 4053 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4054 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4055 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4056 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 4057 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4058 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 4059 | ret = -EINVAL; |
| 4060 | goto error; |
| 4061 | } |
| 4062 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4063 | if (!netif_running(v)) { |
| 4064 | ret = -ENETDOWN; |
| 4065 | goto error; |
| 4066 | } |
| 4067 | |
| 4068 | return v; |
| 4069 | error: |
| 4070 | dev_put(v); |
| 4071 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4072 | } |
| 4073 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 4074 | static const struct nla_policy |
| 4075 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4076 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 4077 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 4078 | }; |
| 4079 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4080 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 4081 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4082 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4083 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 4084 | struct nlattr *nla; |
| 4085 | int err; |
| 4086 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4087 | /* parse WME attributes if present */ |
| 4088 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 4089 | return 0; |
| 4090 | |
| 4091 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 4092 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 4093 | nl80211_sta_wme_policy); |
| 4094 | if (err) |
| 4095 | return err; |
| 4096 | |
| 4097 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 4098 | params->uapsd_queues = nla_get_u8( |
| 4099 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 4100 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 4101 | return -EINVAL; |
| 4102 | |
| 4103 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 4104 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 4105 | |
| 4106 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 4107 | return -EINVAL; |
| 4108 | |
| 4109 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 4110 | |
| 4111 | return 0; |
| 4112 | } |
| 4113 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4114 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 4115 | struct station_parameters *params) |
| 4116 | { |
| 4117 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 4118 | params->supported_channels = |
| 4119 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4120 | params->supported_channels_len = |
| 4121 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4122 | /* |
| 4123 | * Need to include at least one (first channel, number of |
| 4124 | * channels) tuple for each subband, and must have proper |
| 4125 | * tuples for the rest of the data as well. |
| 4126 | */ |
| 4127 | if (params->supported_channels_len < 2) |
| 4128 | return -EINVAL; |
| 4129 | if (params->supported_channels_len % 2) |
| 4130 | return -EINVAL; |
| 4131 | } |
| 4132 | |
| 4133 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 4134 | params->supported_oper_classes = |
| 4135 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4136 | params->supported_oper_classes_len = |
| 4137 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4138 | /* |
| 4139 | * The value of the Length field of the Supported Operating |
| 4140 | * Classes element is between 2 and 253. |
| 4141 | */ |
| 4142 | if (params->supported_oper_classes_len < 2 || |
| 4143 | params->supported_oper_classes_len > 253) |
| 4144 | return -EINVAL; |
| 4145 | } |
| 4146 | return 0; |
| 4147 | } |
| 4148 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4149 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4150 | struct station_parameters *params) |
| 4151 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4152 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4153 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4154 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4155 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4156 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4157 | params->ht_capa = |
| 4158 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4159 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4160 | params->vht_capa = |
| 4161 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4162 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4163 | err = nl80211_parse_sta_channel_info(info, params); |
| 4164 | if (err) |
| 4165 | return err; |
| 4166 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4167 | return nl80211_parse_sta_wme(info, params); |
| 4168 | } |
| 4169 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4170 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4171 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4172 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4173 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4174 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4175 | u8 *mac_addr; |
| 4176 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4177 | |
| 4178 | memset(¶ms, 0, sizeof(params)); |
| 4179 | |
| 4180 | params.listen_interval = -1; |
| 4181 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4182 | if (!rdev->ops->change_station) |
| 4183 | return -EOPNOTSUPP; |
| 4184 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4185 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4186 | return -EINVAL; |
| 4187 | |
| 4188 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4189 | return -EINVAL; |
| 4190 | |
| 4191 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4192 | |
| 4193 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4194 | params.supported_rates = |
| 4195 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4196 | params.supported_rates_len = |
| 4197 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4198 | } |
| 4199 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4200 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4201 | params.capability = |
| 4202 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4203 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4204 | } |
| 4205 | |
| 4206 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4207 | params.ext_capab = |
| 4208 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4209 | params.ext_capab_len = |
| 4210 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4211 | } |
| 4212 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4213 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 4214 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4215 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4216 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4217 | return -EINVAL; |
| 4218 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4219 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4220 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4221 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4222 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4223 | return -EINVAL; |
| 4224 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4225 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4226 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4227 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4228 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4229 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4230 | return -EINVAL; |
| 4231 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4232 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4233 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4234 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4235 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4236 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4237 | |
| 4238 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4239 | pm > NL80211_MESH_POWER_MAX) |
| 4240 | return -EINVAL; |
| 4241 | |
| 4242 | params.local_pm = pm; |
| 4243 | } |
| 4244 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4245 | /* Include parameters for TDLS peer (will check later) */ |
| 4246 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4247 | if (err) |
| 4248 | return err; |
| 4249 | |
| 4250 | params.vlan = get_vlan(info, rdev); |
| 4251 | if (IS_ERR(params.vlan)) |
| 4252 | return PTR_ERR(params.vlan); |
| 4253 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4254 | switch (dev->ieee80211_ptr->iftype) { |
| 4255 | case NL80211_IFTYPE_AP: |
| 4256 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4257 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4258 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4259 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4260 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4261 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4262 | break; |
| 4263 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4264 | err = -EOPNOTSUPP; |
| 4265 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4266 | } |
| 4267 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4268 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4269 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4270 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4271 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4272 | if (params.vlan) |
| 4273 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4274 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4275 | return err; |
| 4276 | } |
| 4277 | |
| 4278 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4279 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4280 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4281 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4282 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4283 | struct station_parameters params; |
| 4284 | u8 *mac_addr = NULL; |
| 4285 | |
| 4286 | memset(¶ms, 0, sizeof(params)); |
| 4287 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4288 | if (!rdev->ops->add_station) |
| 4289 | return -EOPNOTSUPP; |
| 4290 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4291 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4292 | return -EINVAL; |
| 4293 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4294 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4295 | return -EINVAL; |
| 4296 | |
| 4297 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4298 | return -EINVAL; |
| 4299 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4300 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4301 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4302 | return -EINVAL; |
| 4303 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4304 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4305 | params.supported_rates = |
| 4306 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4307 | params.supported_rates_len = |
| 4308 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4309 | params.listen_interval = |
| 4310 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4311 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4312 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4313 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4314 | else |
| 4315 | 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] | 4316 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4317 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4318 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4319 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4320 | params.capability = |
| 4321 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4322 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4323 | } |
| 4324 | |
| 4325 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4326 | params.ext_capab = |
| 4327 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4328 | params.ext_capab_len = |
| 4329 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4330 | } |
| 4331 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4332 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4333 | params.ht_capa = |
| 4334 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4335 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4336 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4337 | params.vht_capa = |
| 4338 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4339 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4340 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4341 | params.opmode_notif_used = true; |
| 4342 | params.opmode_notif = |
| 4343 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4344 | } |
| 4345 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4346 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4347 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4348 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4349 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4350 | return -EINVAL; |
| 4351 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4352 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4353 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4354 | if (err) |
| 4355 | return err; |
| 4356 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4357 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4358 | if (err) |
| 4359 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4360 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4361 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4362 | return -EINVAL; |
| 4363 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4364 | /* When you run into this, adjust the code below for the new flag */ |
| 4365 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4366 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4367 | switch (dev->ieee80211_ptr->iftype) { |
| 4368 | case NL80211_IFTYPE_AP: |
| 4369 | case NL80211_IFTYPE_AP_VLAN: |
| 4370 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4371 | /* ignore WME attributes if iface/sta is not capable */ |
| 4372 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4373 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4374 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4375 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4376 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4377 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4378 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4379 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4380 | /* but don't bother the driver with it */ |
| 4381 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4382 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4383 | /* allow authenticated/associated only if driver handles it */ |
| 4384 | if (!(rdev->wiphy.features & |
| 4385 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4386 | params.sta_flags_mask & |
| 4387 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4388 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4389 | return -EINVAL; |
| 4390 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4391 | /* must be last in here for error handling */ |
| 4392 | params.vlan = get_vlan(info, rdev); |
| 4393 | if (IS_ERR(params.vlan)) |
| 4394 | return PTR_ERR(params.vlan); |
| 4395 | break; |
| 4396 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4397 | /* ignore uAPSD data */ |
| 4398 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4399 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4400 | /* associated is disallowed */ |
| 4401 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4402 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4403 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4404 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4405 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4406 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4407 | break; |
| 4408 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4409 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4410 | /* ignore uAPSD data */ |
| 4411 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4412 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4413 | /* these are disallowed */ |
| 4414 | if (params.sta_flags_mask & |
| 4415 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4416 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4417 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4418 | /* Only TDLS peers can be added */ |
| 4419 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4420 | return -EINVAL; |
| 4421 | /* Can only add if TDLS ... */ |
| 4422 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4423 | return -EOPNOTSUPP; |
| 4424 | /* ... with external setup is supported */ |
| 4425 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4426 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4427 | /* |
| 4428 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4429 | * as authorized, but it shouldn't yet be. |
| 4430 | */ |
| 4431 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4432 | break; |
| 4433 | default: |
| 4434 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4435 | } |
| 4436 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4437 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4438 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4439 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4440 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4441 | if (params.vlan) |
| 4442 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4443 | return err; |
| 4444 | } |
| 4445 | |
| 4446 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4447 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4448 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4449 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4450 | struct station_del_parameters params; |
| 4451 | |
| 4452 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4453 | |
| 4454 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4455 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4456 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4457 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4458 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4459 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4460 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4461 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4462 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4463 | if (!rdev->ops->del_station) |
| 4464 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4465 | |
Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 4466 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 4467 | params.subtype = |
| 4468 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 4469 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 4470 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 4471 | return -EINVAL; |
| 4472 | } else { |
| 4473 | /* Default to Deauthentication frame */ |
| 4474 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 4475 | } |
| 4476 | |
| 4477 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 4478 | params.reason_code = |
| 4479 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4480 | if (params.reason_code == 0) |
| 4481 | return -EINVAL; /* 0 is reserved */ |
| 4482 | } else { |
| 4483 | /* Default to reason code 2 */ |
| 4484 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 4485 | } |
| 4486 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4487 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4488 | } |
| 4489 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4490 | 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] | 4491 | int flags, struct net_device *dev, |
| 4492 | u8 *dst, u8 *next_hop, |
| 4493 | struct mpath_info *pinfo) |
| 4494 | { |
| 4495 | void *hdr; |
| 4496 | struct nlattr *pinfoattr; |
| 4497 | |
Henning Rogge | 1ef4c85 | 2014-11-04 16:14:58 +0100 | [diff] [blame] | 4498 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4499 | if (!hdr) |
| 4500 | return -1; |
| 4501 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4502 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4503 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4504 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4505 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4506 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4507 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4508 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4509 | if (!pinfoattr) |
| 4510 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4511 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4512 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4513 | pinfo->frame_qlen)) |
| 4514 | goto nla_put_failure; |
| 4515 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4516 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4517 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4518 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4519 | pinfo->metric)) || |
| 4520 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4521 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4522 | pinfo->exptime)) || |
| 4523 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4524 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4525 | pinfo->flags)) || |
| 4526 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4527 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4528 | pinfo->discovery_timeout)) || |
| 4529 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4530 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4531 | pinfo->discovery_retries))) |
| 4532 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4533 | |
| 4534 | nla_nest_end(msg, pinfoattr); |
| 4535 | |
| 4536 | return genlmsg_end(msg, hdr); |
| 4537 | |
| 4538 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4539 | genlmsg_cancel(msg, hdr); |
| 4540 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4541 | } |
| 4542 | |
| 4543 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4544 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4545 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4546 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4547 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4548 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4549 | u8 dst[ETH_ALEN]; |
| 4550 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4551 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4552 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4553 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4554 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4555 | if (err) |
| 4556 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4557 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4558 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4559 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4560 | goto out_err; |
| 4561 | } |
| 4562 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4563 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4564 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4565 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4566 | } |
| 4567 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4568 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4569 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4570 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4571 | if (err == -ENOENT) |
| 4572 | break; |
| 4573 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4574 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4575 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4576 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4577 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4578 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4579 | &pinfo) < 0) |
| 4580 | goto out; |
| 4581 | |
| 4582 | path_idx++; |
| 4583 | } |
| 4584 | |
| 4585 | |
| 4586 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4587 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4588 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4589 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4590 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4591 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4592 | } |
| 4593 | |
| 4594 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4595 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4596 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4597 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4598 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4599 | struct mpath_info pinfo; |
| 4600 | struct sk_buff *msg; |
| 4601 | u8 *dst = NULL; |
| 4602 | u8 next_hop[ETH_ALEN]; |
| 4603 | |
| 4604 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4605 | |
| 4606 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4607 | return -EINVAL; |
| 4608 | |
| 4609 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4610 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4611 | if (!rdev->ops->get_mpath) |
| 4612 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4613 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4614 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4615 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4616 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4617 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4618 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4619 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4620 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4621 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4622 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4623 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4624 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4625 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4626 | dev, dst, next_hop, &pinfo) < 0) { |
| 4627 | nlmsg_free(msg); |
| 4628 | return -ENOBUFS; |
| 4629 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4630 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4631 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4632 | } |
| 4633 | |
| 4634 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4635 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4636 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4637 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4638 | u8 *dst = NULL; |
| 4639 | u8 *next_hop = NULL; |
| 4640 | |
| 4641 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4642 | return -EINVAL; |
| 4643 | |
| 4644 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4645 | return -EINVAL; |
| 4646 | |
| 4647 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4648 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4649 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4650 | if (!rdev->ops->change_mpath) |
| 4651 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4652 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4653 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4654 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4655 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4656 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4657 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4658 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4659 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4660 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4661 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4662 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4663 | u8 *dst = NULL; |
| 4664 | u8 *next_hop = NULL; |
| 4665 | |
| 4666 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4667 | return -EINVAL; |
| 4668 | |
| 4669 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4670 | return -EINVAL; |
| 4671 | |
| 4672 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4673 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4674 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4675 | if (!rdev->ops->add_mpath) |
| 4676 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4677 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4678 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4679 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4680 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4681 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4682 | } |
| 4683 | |
| 4684 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4685 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4686 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4687 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4688 | u8 *dst = NULL; |
| 4689 | |
| 4690 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4691 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4692 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4693 | if (!rdev->ops->del_mpath) |
| 4694 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4695 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4696 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4697 | } |
| 4698 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 4699 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 4700 | { |
| 4701 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4702 | int err; |
| 4703 | struct net_device *dev = info->user_ptr[1]; |
| 4704 | struct mpath_info pinfo; |
| 4705 | struct sk_buff *msg; |
| 4706 | u8 *dst = NULL; |
| 4707 | u8 mpp[ETH_ALEN]; |
| 4708 | |
| 4709 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4710 | |
| 4711 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4712 | return -EINVAL; |
| 4713 | |
| 4714 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4715 | |
| 4716 | if (!rdev->ops->get_mpp) |
| 4717 | return -EOPNOTSUPP; |
| 4718 | |
| 4719 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4720 | return -EOPNOTSUPP; |
| 4721 | |
| 4722 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 4723 | if (err) |
| 4724 | return err; |
| 4725 | |
| 4726 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 4727 | if (!msg) |
| 4728 | return -ENOMEM; |
| 4729 | |
| 4730 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 4731 | dev, dst, mpp, &pinfo) < 0) { |
| 4732 | nlmsg_free(msg); |
| 4733 | return -ENOBUFS; |
| 4734 | } |
| 4735 | |
| 4736 | return genlmsg_reply(msg, info); |
| 4737 | } |
| 4738 | |
| 4739 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 4740 | struct netlink_callback *cb) |
| 4741 | { |
| 4742 | struct mpath_info pinfo; |
| 4743 | struct cfg80211_registered_device *rdev; |
| 4744 | struct wireless_dev *wdev; |
| 4745 | u8 dst[ETH_ALEN]; |
| 4746 | u8 mpp[ETH_ALEN]; |
| 4747 | int path_idx = cb->args[2]; |
| 4748 | int err; |
| 4749 | |
| 4750 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
| 4751 | if (err) |
| 4752 | return err; |
| 4753 | |
| 4754 | if (!rdev->ops->dump_mpp) { |
| 4755 | err = -EOPNOTSUPP; |
| 4756 | goto out_err; |
| 4757 | } |
| 4758 | |
| 4759 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 4760 | err = -EOPNOTSUPP; |
| 4761 | goto out_err; |
| 4762 | } |
| 4763 | |
| 4764 | while (1) { |
| 4765 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 4766 | mpp, &pinfo); |
| 4767 | if (err == -ENOENT) |
| 4768 | break; |
| 4769 | if (err) |
| 4770 | goto out_err; |
| 4771 | |
| 4772 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 4773 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4774 | wdev->netdev, dst, mpp, |
| 4775 | &pinfo) < 0) |
| 4776 | goto out; |
| 4777 | |
| 4778 | path_idx++; |
| 4779 | } |
| 4780 | |
| 4781 | out: |
| 4782 | cb->args[2] = path_idx; |
| 4783 | err = skb->len; |
| 4784 | out_err: |
| 4785 | nl80211_finish_wdev_dump(rdev); |
| 4786 | return err; |
| 4787 | } |
| 4788 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4789 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4790 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4791 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4792 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4793 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4794 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4795 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4796 | |
| 4797 | memset(¶ms, 0, sizeof(params)); |
| 4798 | /* default to not changing parameters */ |
| 4799 | params.use_cts_prot = -1; |
| 4800 | params.use_short_preamble = -1; |
| 4801 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4802 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4803 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4804 | params.p2p_ctwindow = -1; |
| 4805 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4806 | |
| 4807 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4808 | params.use_cts_prot = |
| 4809 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4810 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4811 | params.use_short_preamble = |
| 4812 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4813 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4814 | params.use_short_slot_time = |
| 4815 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4816 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4817 | params.basic_rates = |
| 4818 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4819 | params.basic_rates_len = |
| 4820 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4821 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4822 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4823 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4824 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4825 | params.ht_opmode = |
| 4826 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4827 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4828 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4829 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4830 | return -EINVAL; |
| 4831 | params.p2p_ctwindow = |
| 4832 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4833 | if (params.p2p_ctwindow < 0) |
| 4834 | return -EINVAL; |
| 4835 | if (params.p2p_ctwindow != 0 && |
| 4836 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4837 | return -EINVAL; |
| 4838 | } |
| 4839 | |
| 4840 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4841 | u8 tmp; |
| 4842 | |
| 4843 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4844 | return -EINVAL; |
| 4845 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4846 | if (tmp > 1) |
| 4847 | return -EINVAL; |
| 4848 | params.p2p_opp_ps = tmp; |
| 4849 | if (params.p2p_opp_ps && |
| 4850 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4851 | return -EINVAL; |
| 4852 | } |
| 4853 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4854 | if (!rdev->ops->change_bss) |
| 4855 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4856 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4857 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4858 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4859 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4860 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4861 | wdev_lock(wdev); |
| 4862 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 4863 | wdev_unlock(wdev); |
| 4864 | |
| 4865 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4866 | } |
| 4867 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4868 | 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] | 4869 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4870 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4871 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4872 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4873 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4874 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4875 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4876 | }; |
| 4877 | |
| 4878 | static int parse_reg_rule(struct nlattr *tb[], |
| 4879 | struct ieee80211_reg_rule *reg_rule) |
| 4880 | { |
| 4881 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4882 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4883 | |
| 4884 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4885 | return -EINVAL; |
| 4886 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4887 | return -EINVAL; |
| 4888 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4889 | return -EINVAL; |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4890 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4891 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4892 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4893 | return -EINVAL; |
| 4894 | |
| 4895 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4896 | |
| 4897 | freq_range->start_freq_khz = |
| 4898 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4899 | freq_range->end_freq_khz = |
| 4900 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4901 | freq_range->max_bandwidth_khz = |
| 4902 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4903 | |
| 4904 | power_rule->max_eirp = |
| 4905 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4906 | |
| 4907 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4908 | power_rule->max_antenna_gain = |
| 4909 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4910 | |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4911 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 4912 | reg_rule->dfs_cac_ms = |
| 4913 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 4914 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4915 | return 0; |
| 4916 | } |
| 4917 | |
| 4918 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4919 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4920 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4921 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4922 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4923 | /* |
| 4924 | * You should only get this when cfg80211 hasn't yet initialized |
| 4925 | * completely when built-in to the kernel right between the time |
| 4926 | * window between nl80211_init() and regulatory_init(), if that is |
| 4927 | * even possible. |
| 4928 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4929 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4930 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4931 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4932 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4933 | user_reg_hint_type = |
| 4934 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4935 | else |
| 4936 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4937 | |
| 4938 | switch (user_reg_hint_type) { |
| 4939 | case NL80211_USER_REG_HINT_USER: |
| 4940 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 4941 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4942 | return -EINVAL; |
| 4943 | |
| 4944 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4945 | return regulatory_hint_user(data, user_reg_hint_type); |
| 4946 | case NL80211_USER_REG_HINT_INDOOR: |
| 4947 | return regulatory_hint_indoor_user(); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4948 | default: |
| 4949 | return -EINVAL; |
| 4950 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4951 | } |
| 4952 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4953 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4954 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4955 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4956 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4957 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4958 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4959 | struct mesh_config cur_params; |
| 4960 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4961 | void *hdr; |
| 4962 | struct nlattr *pinfoattr; |
| 4963 | struct sk_buff *msg; |
| 4964 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4965 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4966 | return -EOPNOTSUPP; |
| 4967 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4968 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4969 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4970 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4971 | wdev_lock(wdev); |
| 4972 | /* If not connected, get default parameters */ |
| 4973 | if (!wdev->mesh_id_len) |
| 4974 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4975 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4976 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4977 | wdev_unlock(wdev); |
| 4978 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4979 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4980 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4981 | |
| 4982 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4983 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4984 | if (!msg) |
| 4985 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4986 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4987 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4988 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4989 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4990 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4991 | if (!pinfoattr) |
| 4992 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4993 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4994 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4995 | cur_params.dot11MeshRetryTimeout) || |
| 4996 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4997 | cur_params.dot11MeshConfirmTimeout) || |
| 4998 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4999 | cur_params.dot11MeshHoldingTimeout) || |
| 5000 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 5001 | cur_params.dot11MeshMaxPeerLinks) || |
| 5002 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 5003 | cur_params.dot11MeshMaxRetries) || |
| 5004 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 5005 | cur_params.dot11MeshTTL) || |
| 5006 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 5007 | cur_params.element_ttl) || |
| 5008 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 5009 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 5010 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 5011 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5012 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 5013 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 5014 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 5015 | cur_params.path_refresh_time) || |
| 5016 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 5017 | cur_params.min_discovery_timeout) || |
| 5018 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 5019 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 5020 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 5021 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 5022 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 5023 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 5024 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5025 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 5026 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5027 | cur_params.dot11MeshHWMPRootMode) || |
| 5028 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 5029 | cur_params.dot11MeshHWMPRannInterval) || |
| 5030 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 5031 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 5032 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 5033 | cur_params.dot11MeshForwarding) || |
| 5034 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 5035 | cur_params.rssi_threshold) || |
| 5036 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5037 | cur_params.ht_opmode) || |
| 5038 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5039 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 5040 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5041 | cur_params.dot11MeshHWMProotInterval) || |
| 5042 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5043 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 5044 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 5045 | cur_params.power_mode) || |
| 5046 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5047 | cur_params.dot11MeshAwakeWindowDuration) || |
| 5048 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5049 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5050 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5051 | nla_nest_end(msg, pinfoattr); |
| 5052 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5053 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5054 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5055 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5056 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5057 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5058 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5059 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5060 | } |
| 5061 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5062 | 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] | 5063 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 5064 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 5065 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 5066 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 5067 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 5068 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 5069 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5070 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5071 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5072 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 5073 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 5074 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 5075 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 5076 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5077 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5078 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 5079 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 5080 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 5081 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 5082 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5083 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 5084 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5085 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 5086 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5087 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5088 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 5089 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5090 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5091 | }; |
| 5092 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5093 | static const struct nla_policy |
| 5094 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5095 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5096 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 5097 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 5098 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5099 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5100 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5101 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5102 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5103 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5104 | }; |
| 5105 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5106 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5107 | struct mesh_config *cfg, |
| 5108 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5109 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5110 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5111 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5112 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5113 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 5114 | do { \ |
| 5115 | if (tb[attr]) { \ |
| 5116 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 5117 | return -EINVAL; \ |
| 5118 | cfg->param = fn(tb[attr]); \ |
| 5119 | mask |= (1 << (attr - 1)); \ |
| 5120 | } \ |
| 5121 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5122 | |
| 5123 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5124 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5125 | return -EINVAL; |
| 5126 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5127 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5128 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5129 | return -EINVAL; |
| 5130 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5131 | /* This makes sure that there aren't more than 32 mesh config |
| 5132 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 5133 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 5134 | |
| 5135 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5136 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5137 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 5138 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5139 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5140 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 5141 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5142 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5143 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 5144 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5145 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5146 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 5147 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5148 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5149 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 5150 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5151 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5152 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5153 | 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] | 5154 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 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, auto_open_plinks, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5157 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 5158 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5159 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 5160 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5161 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 5162 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5163 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5164 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 5165 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5166 | 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] | 5167 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 5168 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5169 | 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] | 5170 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 5171 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5172 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 5173 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5174 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 5175 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5176 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5177 | 1, 65535, mask, |
| 5178 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5179 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5180 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5181 | 1, 65535, mask, |
| 5182 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5183 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5184 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5185 | dot11MeshHWMPnetDiameterTraversalTime, |
| 5186 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5187 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5188 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5189 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 5190 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5191 | nla_get_u8); |
| 5192 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 5193 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5194 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 5195 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5196 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 5197 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5198 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5199 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5200 | mask, NL80211_MESHCONF_FORWARDING, |
| 5201 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5202 | 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] | 5203 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5204 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5205 | 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] | 5206 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 5207 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5208 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5209 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5210 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5211 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5212 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5213 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 5214 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5215 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5216 | dot11MeshHWMPconfirmationInterval, |
| 5217 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5218 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 5219 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5220 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 5221 | NL80211_MESH_POWER_ACTIVE, |
| 5222 | NL80211_MESH_POWER_MAX, |
| 5223 | mask, NL80211_MESHCONF_POWER_MODE, |
| 5224 | nla_get_u32); |
| 5225 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 5226 | 0, 65535, mask, |
| 5227 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5228 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 5229 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5230 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5231 | if (mask_out) |
| 5232 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5233 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5234 | return 0; |
| 5235 | |
| 5236 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 5237 | } |
| 5238 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5239 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 5240 | struct mesh_setup *setup) |
| 5241 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5242 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5243 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 5244 | |
| 5245 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 5246 | return -EINVAL; |
| 5247 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 5248 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 5249 | nl80211_mesh_setup_params_policy)) |
| 5250 | return -EINVAL; |
| 5251 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5252 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 5253 | setup->sync_method = |
| 5254 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 5255 | IEEE80211_SYNC_METHOD_VENDOR : |
| 5256 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 5257 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5258 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 5259 | setup->path_sel_proto = |
| 5260 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 5261 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 5262 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 5263 | |
| 5264 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 5265 | setup->path_metric = |
| 5266 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 5267 | IEEE80211_PATH_METRIC_VENDOR : |
| 5268 | IEEE80211_PATH_METRIC_AIRTIME; |
| 5269 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5270 | |
| 5271 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5272 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5273 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5274 | if (!is_valid_ie_attr(ieattr)) |
| 5275 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5276 | setup->ie = nla_data(ieattr); |
| 5277 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5278 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5279 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 5280 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 5281 | return -EINVAL; |
| 5282 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5283 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 5284 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5285 | if (setup->is_secure) |
| 5286 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5287 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5288 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 5289 | if (!setup->user_mpm) |
| 5290 | return -EINVAL; |
| 5291 | setup->auth_id = |
| 5292 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 5293 | } |
| 5294 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5295 | return 0; |
| 5296 | } |
| 5297 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5298 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5299 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5300 | { |
| 5301 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5302 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5303 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5304 | struct mesh_config cfg; |
| 5305 | u32 mask; |
| 5306 | int err; |
| 5307 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5308 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5309 | return -EOPNOTSUPP; |
| 5310 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5311 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5312 | return -EOPNOTSUPP; |
| 5313 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5314 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5315 | if (err) |
| 5316 | return err; |
| 5317 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5318 | wdev_lock(wdev); |
| 5319 | if (!wdev->mesh_id_len) |
| 5320 | err = -ENOLINK; |
| 5321 | |
| 5322 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5323 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5324 | |
| 5325 | wdev_unlock(wdev); |
| 5326 | |
| 5327 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5328 | } |
| 5329 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5330 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
| 5331 | struct sk_buff *msg) |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5332 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5333 | struct nlattr *nl_reg_rules; |
| 5334 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5335 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5336 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5337 | (regdom->dfs_region && |
| 5338 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5339 | goto nla_put_failure; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5340 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5341 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5342 | if (!nl_reg_rules) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5343 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5344 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5345 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5346 | struct nlattr *nl_reg_rule; |
| 5347 | const struct ieee80211_reg_rule *reg_rule; |
| 5348 | const struct ieee80211_freq_range *freq_range; |
| 5349 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5350 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5351 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5352 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5353 | freq_range = ®_rule->freq_range; |
| 5354 | power_rule = ®_rule->power_rule; |
| 5355 | |
| 5356 | nl_reg_rule = nla_nest_start(msg, i); |
| 5357 | if (!nl_reg_rule) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5358 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5359 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5360 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 5361 | if (!max_bandwidth_khz) |
| 5362 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 5363 | reg_rule); |
| 5364 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5365 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5366 | reg_rule->flags) || |
| 5367 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5368 | freq_range->start_freq_khz) || |
| 5369 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5370 | freq_range->end_freq_khz) || |
| 5371 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5372 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5373 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5374 | power_rule->max_antenna_gain) || |
| 5375 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 5376 | power_rule->max_eirp) || |
| 5377 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 5378 | reg_rule->dfs_cac_ms)) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5379 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5380 | |
| 5381 | nla_nest_end(msg, nl_reg_rule); |
| 5382 | } |
| 5383 | |
| 5384 | nla_nest_end(msg, nl_reg_rules); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5385 | return 0; |
| 5386 | |
| 5387 | nla_put_failure: |
| 5388 | return -EMSGSIZE; |
| 5389 | } |
| 5390 | |
| 5391 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) |
| 5392 | { |
| 5393 | const struct ieee80211_regdomain *regdom = NULL; |
| 5394 | struct cfg80211_registered_device *rdev; |
| 5395 | struct wiphy *wiphy = NULL; |
| 5396 | struct sk_buff *msg; |
| 5397 | void *hdr; |
| 5398 | |
| 5399 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 5400 | if (!msg) |
| 5401 | return -ENOBUFS; |
| 5402 | |
| 5403 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 5404 | NL80211_CMD_GET_REG); |
| 5405 | if (!hdr) |
| 5406 | goto put_failure; |
| 5407 | |
| 5408 | if (info->attrs[NL80211_ATTR_WIPHY]) { |
| 5409 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
| 5410 | if (IS_ERR(rdev)) { |
| 5411 | nlmsg_free(msg); |
| 5412 | return PTR_ERR(rdev); |
| 5413 | } |
| 5414 | |
| 5415 | wiphy = &rdev->wiphy; |
| 5416 | regdom = get_wiphy_regdom(wiphy); |
| 5417 | |
| 5418 | if (regdom && |
| 5419 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 5420 | goto nla_put_failure; |
| 5421 | } |
| 5422 | |
| 5423 | if (!wiphy && reg_last_request_cell_base() && |
| 5424 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5425 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5426 | goto nla_put_failure; |
| 5427 | |
| 5428 | rcu_read_lock(); |
| 5429 | |
| 5430 | if (!regdom) |
| 5431 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5432 | |
| 5433 | if (nl80211_put_regdom(regdom, msg)) |
| 5434 | goto nla_put_failure_rcu; |
| 5435 | |
| 5436 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5437 | |
| 5438 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5439 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5440 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5441 | nla_put_failure_rcu: |
| 5442 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5443 | nla_put_failure: |
| 5444 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5445 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5446 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5447 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5448 | } |
| 5449 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 5450 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
| 5451 | u32 seq, int flags, struct wiphy *wiphy, |
| 5452 | const struct ieee80211_regdomain *regdom) |
| 5453 | { |
| 5454 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
| 5455 | NL80211_CMD_GET_REG); |
| 5456 | |
| 5457 | if (!hdr) |
| 5458 | return -1; |
| 5459 | |
| 5460 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 5461 | |
| 5462 | if (nl80211_put_regdom(regdom, msg)) |
| 5463 | goto nla_put_failure; |
| 5464 | |
| 5465 | if (!wiphy && reg_last_request_cell_base() && |
| 5466 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5467 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5468 | goto nla_put_failure; |
| 5469 | |
| 5470 | if (wiphy && |
| 5471 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 5472 | goto nla_put_failure; |
| 5473 | |
| 5474 | return genlmsg_end(msg, hdr); |
| 5475 | |
| 5476 | nla_put_failure: |
| 5477 | genlmsg_cancel(msg, hdr); |
| 5478 | return -EMSGSIZE; |
| 5479 | } |
| 5480 | |
| 5481 | static int nl80211_get_reg_dump(struct sk_buff *skb, |
| 5482 | struct netlink_callback *cb) |
| 5483 | { |
| 5484 | const struct ieee80211_regdomain *regdom = NULL; |
| 5485 | struct cfg80211_registered_device *rdev; |
| 5486 | int err, reg_idx, start = cb->args[2]; |
| 5487 | |
| 5488 | rtnl_lock(); |
| 5489 | |
| 5490 | if (cfg80211_regdomain && start == 0) { |
| 5491 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 5492 | NLM_F_MULTI, NULL, |
| 5493 | rtnl_dereference(cfg80211_regdomain)); |
| 5494 | if (err < 0) |
| 5495 | goto out_err; |
| 5496 | } |
| 5497 | |
| 5498 | /* the global regdom is idx 0 */ |
| 5499 | reg_idx = 1; |
| 5500 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 5501 | regdom = get_wiphy_regdom(&rdev->wiphy); |
| 5502 | if (!regdom) |
| 5503 | continue; |
| 5504 | |
| 5505 | if (++reg_idx <= start) |
| 5506 | continue; |
| 5507 | |
| 5508 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 5509 | NLM_F_MULTI, &rdev->wiphy, regdom); |
| 5510 | if (err < 0) { |
| 5511 | reg_idx--; |
| 5512 | break; |
| 5513 | } |
| 5514 | } |
| 5515 | |
| 5516 | cb->args[2] = reg_idx; |
| 5517 | err = skb->len; |
| 5518 | out_err: |
| 5519 | rtnl_unlock(); |
| 5520 | return err; |
| 5521 | } |
| 5522 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5523 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5524 | { |
| 5525 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5526 | struct nlattr *nl_reg_rule; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 5527 | char *alpha2; |
| 5528 | int rem_reg_rules, r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5529 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5530 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 5531 | struct ieee80211_regdomain *rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5532 | |
| 5533 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5534 | return -EINVAL; |
| 5535 | |
| 5536 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5537 | return -EINVAL; |
| 5538 | |
| 5539 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5540 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5541 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5542 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5543 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5544 | 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] | 5545 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5546 | num_rules++; |
| 5547 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5548 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5549 | } |
| 5550 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5551 | if (!reg_is_valid_request(alpha2)) |
| 5552 | return -EINVAL; |
| 5553 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5554 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5555 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5556 | |
| 5557 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5558 | if (!rd) |
| 5559 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5560 | |
| 5561 | rd->n_reg_rules = num_rules; |
| 5562 | rd->alpha2[0] = alpha2[0]; |
| 5563 | rd->alpha2[1] = alpha2[1]; |
| 5564 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5565 | /* |
| 5566 | * Disable DFS master mode if the DFS region was |
| 5567 | * not supported or known on this kernel. |
| 5568 | */ |
| 5569 | if (reg_supported_dfs_region(dfs_region)) |
| 5570 | rd->dfs_region = dfs_region; |
| 5571 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5572 | 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] | 5573 | rem_reg_rules) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5574 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 5575 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5576 | reg_rule_policy); |
| 5577 | if (r) |
| 5578 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5579 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5580 | if (r) |
| 5581 | goto bad_reg; |
| 5582 | |
| 5583 | rule_idx++; |
| 5584 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5585 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5586 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5587 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5588 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5589 | } |
| 5590 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5591 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5592 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5593 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5594 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5595 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5596 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5597 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5598 | } |
| 5599 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5600 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5601 | { |
| 5602 | struct nlattr *attr1, *attr2; |
| 5603 | int n_channels = 0, tmp1, tmp2; |
| 5604 | |
| 5605 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5606 | n_channels++; |
| 5607 | /* |
| 5608 | * Some hardware has a limited channel list for |
| 5609 | * scanning, and it is pretty much nonsensical |
| 5610 | * to scan for a channel twice, so disallow that |
| 5611 | * and don't require drivers to check that the |
| 5612 | * channel list they get isn't longer than what |
| 5613 | * they can scan, as long as they can scan all |
| 5614 | * the channels they registered at once. |
| 5615 | */ |
| 5616 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5617 | if (attr1 != attr2 && |
| 5618 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5619 | return 0; |
| 5620 | } |
| 5621 | |
| 5622 | return n_channels; |
| 5623 | } |
| 5624 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 5625 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
| 5626 | u8 *mac_addr, u8 *mac_addr_mask) |
| 5627 | { |
| 5628 | int i; |
| 5629 | |
| 5630 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { |
| 5631 | memset(mac_addr, 0, ETH_ALEN); |
| 5632 | memset(mac_addr_mask, 0, ETH_ALEN); |
| 5633 | mac_addr[0] = 0x2; |
| 5634 | mac_addr_mask[0] = 0x3; |
| 5635 | |
| 5636 | return 0; |
| 5637 | } |
| 5638 | |
| 5639 | /* need both or none */ |
| 5640 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) |
| 5641 | return -EINVAL; |
| 5642 | |
| 5643 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); |
| 5644 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); |
| 5645 | |
| 5646 | /* don't allow or configure an mcast address */ |
| 5647 | if (!is_multicast_ether_addr(mac_addr_mask) || |
| 5648 | is_multicast_ether_addr(mac_addr)) |
| 5649 | return -EINVAL; |
| 5650 | |
| 5651 | /* |
| 5652 | * allow users to pass a MAC address that has bits set outside |
| 5653 | * of the mask, but don't bother drivers with having to deal |
| 5654 | * with such bits |
| 5655 | */ |
| 5656 | for (i = 0; i < ETH_ALEN; i++) |
| 5657 | mac_addr[i] &= mac_addr_mask[i]; |
| 5658 | |
| 5659 | return 0; |
| 5660 | } |
| 5661 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5662 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5663 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5664 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5665 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5666 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5667 | struct nlattr *attr; |
| 5668 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5669 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5670 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5671 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5672 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5673 | return -EINVAL; |
| 5674 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5675 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5676 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5677 | if (!rdev->ops->scan) |
| 5678 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5679 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 5680 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5681 | err = -EBUSY; |
| 5682 | goto unlock; |
| 5683 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5684 | |
| 5685 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5686 | n_channels = validate_scan_freqs( |
| 5687 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5688 | if (!n_channels) { |
| 5689 | err = -EINVAL; |
| 5690 | goto unlock; |
| 5691 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5692 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5693 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5694 | } |
| 5695 | |
| 5696 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5697 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5698 | n_ssids++; |
| 5699 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5700 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5701 | err = -EINVAL; |
| 5702 | goto unlock; |
| 5703 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5704 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5705 | if (info->attrs[NL80211_ATTR_IE]) |
| 5706 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5707 | else |
| 5708 | ie_len = 0; |
| 5709 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5710 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5711 | err = -EINVAL; |
| 5712 | goto unlock; |
| 5713 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5714 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5715 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5716 | + sizeof(*request->ssids) * n_ssids |
| 5717 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5718 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5719 | if (!request) { |
| 5720 | err = -ENOMEM; |
| 5721 | goto unlock; |
| 5722 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5723 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5724 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5725 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5726 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5727 | if (ie_len) { |
| 5728 | if (request->ssids) |
| 5729 | request->ie = (void *)(request->ssids + n_ssids); |
| 5730 | else |
| 5731 | request->ie = (void *)(request->channels + n_channels); |
| 5732 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5733 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5734 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5735 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5736 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5737 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5738 | struct ieee80211_channel *chan; |
| 5739 | |
| 5740 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5741 | |
| 5742 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5743 | err = -EINVAL; |
| 5744 | goto out_free; |
| 5745 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5746 | |
| 5747 | /* ignore disabled channels */ |
| 5748 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5749 | continue; |
| 5750 | |
| 5751 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5752 | i++; |
| 5753 | } |
| 5754 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5755 | enum ieee80211_band band; |
| 5756 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5757 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5758 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5759 | int j; |
| 5760 | if (!wiphy->bands[band]) |
| 5761 | continue; |
| 5762 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5763 | struct ieee80211_channel *chan; |
| 5764 | |
| 5765 | chan = &wiphy->bands[band]->channels[j]; |
| 5766 | |
| 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 | } |
| 5774 | } |
| 5775 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5776 | if (!i) { |
| 5777 | err = -EINVAL; |
| 5778 | goto out_free; |
| 5779 | } |
| 5780 | |
| 5781 | request->n_channels = i; |
| 5782 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5783 | i = 0; |
| 5784 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5785 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5786 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5787 | err = -EINVAL; |
| 5788 | goto out_free; |
| 5789 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5790 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5791 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5792 | i++; |
| 5793 | } |
| 5794 | } |
| 5795 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5796 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5797 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5798 | memcpy((void *)request->ie, |
| 5799 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5800 | request->ie_len); |
| 5801 | } |
| 5802 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5803 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5804 | if (wiphy->bands[i]) |
| 5805 | request->rates[i] = |
| 5806 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5807 | |
| 5808 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5809 | nla_for_each_nested(attr, |
| 5810 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5811 | tmp) { |
| 5812 | enum ieee80211_band band = nla_type(attr); |
| 5813 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5814 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5815 | err = -EINVAL; |
| 5816 | goto out_free; |
| 5817 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 5818 | |
| 5819 | if (!wiphy->bands[band]) |
| 5820 | continue; |
| 5821 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5822 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5823 | nla_data(attr), |
| 5824 | nla_len(attr), |
| 5825 | &request->rates[band]); |
| 5826 | if (err) |
| 5827 | goto out_free; |
| 5828 | } |
| 5829 | } |
| 5830 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5831 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5832 | request->flags = nla_get_u32( |
| 5833 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5834 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5835 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5836 | err = -EOPNOTSUPP; |
| 5837 | goto out_free; |
| 5838 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 5839 | |
| 5840 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 5841 | if (!(wiphy->features & |
| 5842 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { |
| 5843 | err = -EOPNOTSUPP; |
| 5844 | goto out_free; |
| 5845 | } |
| 5846 | |
| 5847 | if (wdev->current_bss) { |
| 5848 | err = -EOPNOTSUPP; |
| 5849 | goto out_free; |
| 5850 | } |
| 5851 | |
| 5852 | err = nl80211_parse_random_mac(info->attrs, |
| 5853 | request->mac_addr, |
| 5854 | request->mac_addr_mask); |
| 5855 | if (err) |
| 5856 | goto out_free; |
| 5857 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5858 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5859 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5860 | request->no_cck = |
| 5861 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5862 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5863 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5864 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5865 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5866 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5867 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5868 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5869 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5870 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5871 | nl80211_send_scan_start(rdev, wdev); |
| 5872 | if (wdev->netdev) |
| 5873 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5874 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5875 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5876 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5877 | kfree(request); |
| 5878 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5879 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5880 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5881 | return err; |
| 5882 | } |
| 5883 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5884 | static struct cfg80211_sched_scan_request * |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 5885 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5886 | struct nlattr **attrs) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5887 | { |
| 5888 | struct cfg80211_sched_scan_request *request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5889 | struct nlattr *attr; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5890 | 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] | 5891 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5892 | enum ieee80211_band band; |
| 5893 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5894 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5895 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5896 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5897 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
| 5898 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5899 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5900 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5901 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5902 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5903 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5904 | if (interval == 0) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5905 | return ERR_PTR(-EINVAL); |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5906 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5907 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5908 | n_channels = validate_scan_freqs( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5909 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5910 | if (!n_channels) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5911 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5912 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5913 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5914 | } |
| 5915 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5916 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5917 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5918 | tmp) |
| 5919 | n_ssids++; |
| 5920 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5921 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5922 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5923 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5924 | /* |
| 5925 | * First, count the number of 'real' matchsets. Due to an issue with |
| 5926 | * the old implementation, matchsets containing only the RSSI attribute |
| 5927 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 5928 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 5929 | * all APs with a strong RSSI. This is needed to be compatible with |
| 5930 | * older userspace that treated a matchset with only the RSSI as the |
| 5931 | * global RSSI for all other matchsets - if there are other matchsets. |
| 5932 | */ |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5933 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5934 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5935 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5936 | tmp) { |
| 5937 | struct nlattr *rssi; |
| 5938 | |
| 5939 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5940 | nla_data(attr), nla_len(attr), |
| 5941 | nl80211_match_policy); |
| 5942 | if (err) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5943 | return ERR_PTR(err); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5944 | /* add other standalone attributes here */ |
| 5945 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { |
| 5946 | n_match_sets++; |
| 5947 | continue; |
| 5948 | } |
| 5949 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5950 | if (rssi) |
| 5951 | default_match_rssi = nla_get_s32(rssi); |
| 5952 | } |
| 5953 | } |
| 5954 | |
| 5955 | /* However, if there's no other matchset, add the RSSI one */ |
| 5956 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 5957 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5958 | |
| 5959 | if (n_match_sets > wiphy->max_match_sets) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5960 | return ERR_PTR(-EINVAL); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5961 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5962 | if (attrs[NL80211_ATTR_IE]) |
| 5963 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5964 | else |
| 5965 | ie_len = 0; |
| 5966 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5967 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5968 | return ERR_PTR(-EINVAL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5969 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5970 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5971 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5972 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5973 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5974 | + ie_len, GFP_KERNEL); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 5975 | if (!request) |
| 5976 | return ERR_PTR(-ENOMEM); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5977 | |
| 5978 | if (n_ssids) |
| 5979 | request->ssids = (void *)&request->channels[n_channels]; |
| 5980 | request->n_ssids = n_ssids; |
| 5981 | if (ie_len) { |
| 5982 | if (request->ssids) |
| 5983 | request->ie = (void *)(request->ssids + n_ssids); |
| 5984 | else |
| 5985 | request->ie = (void *)(request->channels + n_channels); |
| 5986 | } |
| 5987 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5988 | if (n_match_sets) { |
| 5989 | if (request->ie) |
| 5990 | request->match_sets = (void *)(request->ie + ie_len); |
| 5991 | else if (request->ssids) |
| 5992 | request->match_sets = |
| 5993 | (void *)(request->ssids + n_ssids); |
| 5994 | else |
| 5995 | request->match_sets = |
| 5996 | (void *)(request->channels + n_channels); |
| 5997 | } |
| 5998 | request->n_match_sets = n_match_sets; |
| 5999 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6000 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6001 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6002 | /* user specified, bail out if channel not found */ |
| 6003 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6004 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6005 | tmp) { |
| 6006 | struct ieee80211_channel *chan; |
| 6007 | |
| 6008 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 6009 | |
| 6010 | if (!chan) { |
| 6011 | err = -EINVAL; |
| 6012 | goto out_free; |
| 6013 | } |
| 6014 | |
| 6015 | /* ignore disabled channels */ |
| 6016 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6017 | continue; |
| 6018 | |
| 6019 | request->channels[i] = chan; |
| 6020 | i++; |
| 6021 | } |
| 6022 | } else { |
| 6023 | /* all channels */ |
| 6024 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6025 | int j; |
| 6026 | if (!wiphy->bands[band]) |
| 6027 | continue; |
| 6028 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 6029 | struct ieee80211_channel *chan; |
| 6030 | |
| 6031 | chan = &wiphy->bands[band]->channels[j]; |
| 6032 | |
| 6033 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 6034 | continue; |
| 6035 | |
| 6036 | request->channels[i] = chan; |
| 6037 | i++; |
| 6038 | } |
| 6039 | } |
| 6040 | } |
| 6041 | |
| 6042 | if (!i) { |
| 6043 | err = -EINVAL; |
| 6044 | goto out_free; |
| 6045 | } |
| 6046 | |
| 6047 | request->n_channels = i; |
| 6048 | |
| 6049 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6050 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 6051 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6052 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6053 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6054 | err = -EINVAL; |
| 6055 | goto out_free; |
| 6056 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 6057 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6058 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 6059 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6060 | i++; |
| 6061 | } |
| 6062 | } |
| 6063 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6064 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6065 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6066 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6067 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6068 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 6069 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6070 | |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 6071 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 6072 | nla_data(attr), nla_len(attr), |
| 6073 | nl80211_match_policy); |
| 6074 | if (err) |
| 6075 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 6076 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6077 | if (ssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6078 | if (WARN_ON(i >= n_match_sets)) { |
| 6079 | /* this indicates a programming error, |
| 6080 | * the loop above should have verified |
| 6081 | * things properly |
| 6082 | */ |
| 6083 | err = -EINVAL; |
| 6084 | goto out_free; |
| 6085 | } |
| 6086 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6087 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 6088 | err = -EINVAL; |
| 6089 | goto out_free; |
| 6090 | } |
| 6091 | memcpy(request->match_sets[i].ssid.ssid, |
| 6092 | nla_data(ssid), nla_len(ssid)); |
| 6093 | request->match_sets[i].ssid.ssid_len = |
| 6094 | nla_len(ssid); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6095 | /* special attribute - old implemenation w/a */ |
| 6096 | request->match_sets[i].rssi_thold = |
| 6097 | default_match_rssi; |
| 6098 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 6099 | if (rssi) |
| 6100 | request->match_sets[i].rssi_thold = |
| 6101 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6102 | } |
| 6103 | i++; |
| 6104 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 6105 | |
| 6106 | /* there was no other matchset, so the RSSI one is alone */ |
| 6107 | if (i == 0) |
| 6108 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 6109 | |
| 6110 | request->min_rssi_thold = INT_MAX; |
| 6111 | for (i = 0; i < n_match_sets; i++) |
| 6112 | request->min_rssi_thold = |
| 6113 | min(request->match_sets[i].rssi_thold, |
| 6114 | request->min_rssi_thold); |
| 6115 | } else { |
| 6116 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 6117 | } |
| 6118 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 6119 | if (ie_len) { |
| 6120 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6121 | memcpy((void *)request->ie, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6122 | nla_data(attrs[NL80211_ATTR_IE]), |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6123 | request->ie_len); |
| 6124 | } |
| 6125 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6126 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6127 | request->flags = nla_get_u32( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6128 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 6129 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 6130 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6131 | err = -EOPNOTSUPP; |
| 6132 | goto out_free; |
| 6133 | } |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6134 | |
| 6135 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 6136 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; |
| 6137 | |
| 6138 | if (!wdev) /* must be net-detect */ |
| 6139 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 6140 | |
| 6141 | if (!(wiphy->features & flg)) { |
| 6142 | err = -EOPNOTSUPP; |
| 6143 | goto out_free; |
| 6144 | } |
| 6145 | |
| 6146 | if (wdev && wdev->current_bss) { |
| 6147 | err = -EOPNOTSUPP; |
| 6148 | goto out_free; |
| 6149 | } |
| 6150 | |
| 6151 | err = nl80211_parse_random_mac(attrs, request->mac_addr, |
| 6152 | request->mac_addr_mask); |
| 6153 | if (err) |
| 6154 | goto out_free; |
| 6155 | } |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 6156 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 6157 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 6158 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 6159 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6160 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6161 | return request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6162 | |
| 6163 | out_free: |
| 6164 | kfree(request); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6165 | return ERR_PTR(err); |
| 6166 | } |
| 6167 | |
| 6168 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 6169 | struct genl_info *info) |
| 6170 | { |
| 6171 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6172 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6173 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6174 | int err; |
| 6175 | |
| 6176 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 6177 | !rdev->ops->sched_scan_start) |
| 6178 | return -EOPNOTSUPP; |
| 6179 | |
| 6180 | if (rdev->sched_scan_req) |
| 6181 | return -EINPROGRESS; |
| 6182 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 6183 | rdev->sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 6184 | info->attrs); |
| 6185 | err = PTR_ERR_OR_ZERO(rdev->sched_scan_req); |
| 6186 | if (err) |
| 6187 | goto out_err; |
| 6188 | |
| 6189 | err = rdev_sched_scan_start(rdev, dev, rdev->sched_scan_req); |
| 6190 | if (err) |
| 6191 | goto out_free; |
| 6192 | |
| 6193 | rdev->sched_scan_req->dev = dev; |
| 6194 | rdev->sched_scan_req->wiphy = &rdev->wiphy; |
| 6195 | |
| 6196 | nl80211_send_sched_scan(rdev, dev, |
| 6197 | NL80211_CMD_START_SCHED_SCAN); |
| 6198 | return 0; |
| 6199 | |
| 6200 | out_free: |
| 6201 | kfree(rdev->sched_scan_req); |
| 6202 | out_err: |
| 6203 | rdev->sched_scan_req = NULL; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6204 | return err; |
| 6205 | } |
| 6206 | |
| 6207 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 6208 | struct genl_info *info) |
| 6209 | { |
| 6210 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6211 | |
| 6212 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 6213 | !rdev->ops->sched_scan_stop) |
| 6214 | return -EOPNOTSUPP; |
| 6215 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 6216 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 6217 | } |
| 6218 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6219 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 6220 | struct genl_info *info) |
| 6221 | { |
| 6222 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6223 | struct net_device *dev = info->user_ptr[1]; |
| 6224 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6225 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 6226 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6227 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6228 | int err; |
| 6229 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 6230 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 6231 | if (dfs_region == NL80211_DFS_UNSET) |
| 6232 | return -EINVAL; |
| 6233 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6234 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 6235 | if (err) |
| 6236 | return err; |
| 6237 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 6238 | if (netif_carrier_ok(dev)) |
| 6239 | return -EBUSY; |
| 6240 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6241 | if (wdev->cac_started) |
| 6242 | return -EBUSY; |
| 6243 | |
Luciano Coelho | 2beb6da | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6244 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 6245 | wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6246 | if (err < 0) |
| 6247 | return err; |
| 6248 | |
| 6249 | if (err == 0) |
| 6250 | return -EINVAL; |
| 6251 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 6252 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6253 | return -EINVAL; |
| 6254 | |
| 6255 | if (!rdev->ops->start_radar_detection) |
| 6256 | return -EOPNOTSUPP; |
| 6257 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6258 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 6259 | if (WARN_ON(!cac_time_ms)) |
| 6260 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 6261 | |
| 6262 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, |
| 6263 | cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6264 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 6265 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6266 | wdev->cac_started = true; |
| 6267 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6268 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6269 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6270 | return err; |
| 6271 | } |
| 6272 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6273 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 6274 | { |
| 6275 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6276 | struct net_device *dev = info->user_ptr[1]; |
| 6277 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6278 | struct cfg80211_csa_settings params; |
| 6279 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 6280 | * function is called under RTNL lock, so this should not be a problem. |
| 6281 | */ |
| 6282 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6283 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6284 | bool need_new_beacon = false; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6285 | int len, i; |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 6286 | u32 cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6287 | |
| 6288 | if (!rdev->ops->channel_switch || |
| 6289 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 6290 | return -EOPNOTSUPP; |
| 6291 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6292 | switch (dev->ieee80211_ptr->iftype) { |
| 6293 | case NL80211_IFTYPE_AP: |
| 6294 | case NL80211_IFTYPE_P2P_GO: |
| 6295 | need_new_beacon = true; |
| 6296 | |
| 6297 | /* useless if AP is not running */ |
| 6298 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6299 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6300 | break; |
| 6301 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6302 | if (!wdev->ssid_len) |
| 6303 | return -ENOTCONN; |
| 6304 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 6305 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6306 | if (!wdev->mesh_id_len) |
| 6307 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6308 | break; |
| 6309 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6310 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6311 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6312 | |
| 6313 | memset(¶ms, 0, sizeof(params)); |
| 6314 | |
| 6315 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6316 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 6317 | return -EINVAL; |
| 6318 | |
| 6319 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 6320 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6321 | return -EINVAL; |
| 6322 | |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 6323 | /* Even though the attribute is u32, the specification says |
| 6324 | * u8, so let's make sure we don't overflow. |
| 6325 | */ |
| 6326 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 6327 | if (cs_count > 255) |
| 6328 | return -EINVAL; |
| 6329 | |
| 6330 | params.count = cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6331 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6332 | if (!need_new_beacon) |
| 6333 | goto skip_beacons; |
| 6334 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6335 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 6336 | if (err) |
| 6337 | return err; |
| 6338 | |
| 6339 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 6340 | info->attrs[NL80211_ATTR_CSA_IES], |
| 6341 | nl80211_policy); |
| 6342 | if (err) |
| 6343 | return err; |
| 6344 | |
| 6345 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 6346 | if (err) |
| 6347 | return err; |
| 6348 | |
| 6349 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 6350 | return -EINVAL; |
| 6351 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6352 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 6353 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6354 | return -EINVAL; |
| 6355 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6356 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 6357 | if (rdev->wiphy.max_num_csa_counters && |
| 6358 | (params.n_counter_offsets_beacon > |
| 6359 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6360 | return -EINVAL; |
| 6361 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6362 | params.counter_offsets_beacon = |
| 6363 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 6364 | |
| 6365 | /* sanity checks - counters should fit and be the same */ |
| 6366 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 6367 | u16 offset = params.counter_offsets_beacon[i]; |
| 6368 | |
| 6369 | if (offset >= params.beacon_csa.tail_len) |
| 6370 | return -EINVAL; |
| 6371 | |
| 6372 | if (params.beacon_csa.tail[offset] != params.count) |
| 6373 | return -EINVAL; |
| 6374 | } |
| 6375 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6376 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6377 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 6378 | if (!len || (len % sizeof(u16))) |
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.n_counter_offsets_presp = len / sizeof(u16); |
| 6382 | if (rdev->wiphy.max_num_csa_counters && |
| 6383 | (params.n_counter_offsets_beacon > |
| 6384 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6385 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6386 | |
| 6387 | params.counter_offsets_presp = |
| 6388 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 6389 | |
| 6390 | /* sanity checks - counters should fit and be the same */ |
| 6391 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 6392 | u16 offset = params.counter_offsets_presp[i]; |
| 6393 | |
| 6394 | if (offset >= params.beacon_csa.probe_resp_len) |
| 6395 | return -EINVAL; |
| 6396 | |
| 6397 | if (params.beacon_csa.probe_resp[offset] != |
| 6398 | params.count) |
| 6399 | return -EINVAL; |
| 6400 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6401 | } |
| 6402 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6403 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6404 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 6405 | if (err) |
| 6406 | return err; |
| 6407 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 6408 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
| 6409 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6410 | return -EINVAL; |
| 6411 | |
Luciano Coelho | 2beb6da | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6412 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 6413 | ¶ms.chandef, |
| 6414 | wdev->iftype); |
| 6415 | if (err < 0) |
| 6416 | return err; |
| 6417 | |
Fabian Frederick | dcc6c2f | 2014-10-25 17:57:35 +0200 | [diff] [blame] | 6418 | if (err > 0) |
Luciano Coelho | 2beb6da | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6419 | params.radar_required = true; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6420 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6421 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 6422 | params.block_tx = true; |
| 6423 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6424 | wdev_lock(wdev); |
| 6425 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 6426 | wdev_unlock(wdev); |
| 6427 | |
| 6428 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6429 | } |
| 6430 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6431 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 6432 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6433 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6434 | struct wireless_dev *wdev, |
| 6435 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6436 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6437 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6438 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6439 | void *hdr; |
| 6440 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6441 | |
| 6442 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6443 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6444 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6445 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 6446 | if (!hdr) |
| 6447 | return -1; |
| 6448 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6449 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 6450 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6451 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 6452 | goto nla_put_failure; |
| 6453 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6454 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 6455 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6456 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 6457 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6458 | |
| 6459 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 6460 | if (!bss) |
| 6461 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6462 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6463 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6464 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6465 | |
| 6466 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6467 | /* indicate whether we have probe response data or not */ |
| 6468 | if (rcu_access_pointer(res->proberesp_ies) && |
| 6469 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 6470 | goto fail_unlock_rcu; |
| 6471 | |
| 6472 | /* this pointer prefers to be pointed to probe response data |
| 6473 | * but is always valid |
| 6474 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6475 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6476 | if (ies) { |
| 6477 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 6478 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6479 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 6480 | ies->len, ies->data)) |
| 6481 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6482 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6483 | |
| 6484 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6485 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6486 | if (ies && ies->from_beacon) { |
| 6487 | if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6488 | goto fail_unlock_rcu; |
| 6489 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 6490 | ies->len, ies->data)) |
| 6491 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6492 | } |
| 6493 | rcu_read_unlock(); |
| 6494 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6495 | if (res->beacon_interval && |
| 6496 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 6497 | goto nla_put_failure; |
| 6498 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 6499 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 6500 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6501 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 6502 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 6503 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6504 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 6505 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6506 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6507 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 6508 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6509 | break; |
| 6510 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6511 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 6512 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6513 | break; |
| 6514 | default: |
| 6515 | break; |
| 6516 | } |
| 6517 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6518 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6519 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6520 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6521 | if (intbss == wdev->current_bss && |
| 6522 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6523 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 6524 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6525 | break; |
| 6526 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6527 | if (intbss == wdev->current_bss && |
| 6528 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6529 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 6530 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6531 | break; |
| 6532 | default: |
| 6533 | break; |
| 6534 | } |
| 6535 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6536 | nla_nest_end(msg, bss); |
| 6537 | |
| 6538 | return genlmsg_end(msg, hdr); |
| 6539 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6540 | fail_unlock_rcu: |
| 6541 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6542 | nla_put_failure: |
| 6543 | genlmsg_cancel(msg, hdr); |
| 6544 | return -EMSGSIZE; |
| 6545 | } |
| 6546 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6547 | 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] | 6548 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6549 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6550 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6551 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6552 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6553 | int err; |
| 6554 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6555 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6556 | if (err) |
| 6557 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6558 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6559 | wdev_lock(wdev); |
| 6560 | spin_lock_bh(&rdev->bss_lock); |
| 6561 | cfg80211_bss_expire(rdev); |
| 6562 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6563 | cb->seq = rdev->bss_generation; |
| 6564 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6565 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6566 | if (++idx <= start) |
| 6567 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6568 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6569 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6570 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6571 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6572 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6573 | } |
| 6574 | } |
| 6575 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6576 | spin_unlock_bh(&rdev->bss_lock); |
| 6577 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6578 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6579 | cb->args[2] = idx; |
| 6580 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6581 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6582 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6583 | } |
| 6584 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6585 | 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] | 6586 | int flags, struct net_device *dev, |
| 6587 | struct survey_info *survey) |
| 6588 | { |
| 6589 | void *hdr; |
| 6590 | struct nlattr *infoattr; |
| 6591 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6592 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6593 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 6594 | if (!hdr) |
| 6595 | return -ENOMEM; |
| 6596 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6597 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 6598 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6599 | |
| 6600 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 6601 | if (!infoattr) |
| 6602 | goto nla_put_failure; |
| 6603 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6604 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 6605 | survey->channel->center_freq)) |
| 6606 | goto nla_put_failure; |
| 6607 | |
| 6608 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 6609 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 6610 | goto nla_put_failure; |
| 6611 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 6612 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 6613 | goto nla_put_failure; |
| 6614 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 6615 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 6616 | survey->channel_time)) |
| 6617 | goto nla_put_failure; |
| 6618 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 6619 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 6620 | survey->channel_time_busy)) |
| 6621 | goto nla_put_failure; |
| 6622 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 6623 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 6624 | survey->channel_time_ext_busy)) |
| 6625 | goto nla_put_failure; |
| 6626 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 6627 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 6628 | survey->channel_time_rx)) |
| 6629 | goto nla_put_failure; |
| 6630 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 6631 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 6632 | survey->channel_time_tx)) |
| 6633 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6634 | |
| 6635 | nla_nest_end(msg, infoattr); |
| 6636 | |
| 6637 | return genlmsg_end(msg, hdr); |
| 6638 | |
| 6639 | nla_put_failure: |
| 6640 | genlmsg_cancel(msg, hdr); |
| 6641 | return -EMSGSIZE; |
| 6642 | } |
| 6643 | |
| 6644 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 6645 | struct netlink_callback *cb) |
| 6646 | { |
| 6647 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6648 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6649 | struct wireless_dev *wdev; |
| 6650 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6651 | int res; |
| 6652 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6653 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6654 | if (res) |
| 6655 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6656 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6657 | if (!wdev->netdev) { |
| 6658 | res = -EINVAL; |
| 6659 | goto out_err; |
| 6660 | } |
| 6661 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6662 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6663 | res = -EOPNOTSUPP; |
| 6664 | goto out_err; |
| 6665 | } |
| 6666 | |
| 6667 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6668 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6669 | if (res == -ENOENT) |
| 6670 | break; |
| 6671 | if (res) |
| 6672 | goto out_err; |
| 6673 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6674 | /* Survey without a channel doesn't make sense */ |
| 6675 | if (!survey.channel) { |
| 6676 | res = -EINVAL; |
| 6677 | goto out; |
| 6678 | } |
| 6679 | |
Johannes Berg | ea9eba6 | 2014-11-21 15:24:31 +0100 | [diff] [blame] | 6680 | if (survey.channel->flags & IEEE80211_CHAN_DISABLED) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6681 | survey_idx++; |
| 6682 | continue; |
| 6683 | } |
| 6684 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6685 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6686 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6687 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6688 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6689 | goto out; |
| 6690 | survey_idx++; |
| 6691 | } |
| 6692 | |
| 6693 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6694 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6695 | res = skb->len; |
| 6696 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6697 | nl80211_finish_wdev_dump(rdev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6698 | return res; |
| 6699 | } |
| 6700 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6701 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 6702 | { |
| 6703 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 6704 | NL80211_WPA_VERSION_2)); |
| 6705 | } |
| 6706 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6707 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6708 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6709 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6710 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6711 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6712 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6713 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6714 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6715 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6716 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6717 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6718 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6719 | return -EINVAL; |
| 6720 | |
| 6721 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6722 | return -EINVAL; |
| 6723 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6724 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 6725 | return -EINVAL; |
| 6726 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6727 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 6728 | return -EINVAL; |
| 6729 | |
| 6730 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6731 | return -EINVAL; |
| 6732 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6733 | err = nl80211_parse_key(info, &key); |
| 6734 | if (err) |
| 6735 | return err; |
| 6736 | |
| 6737 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6738 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 6739 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6740 | if (!key.p.key || !key.p.key_len) |
| 6741 | return -EINVAL; |
| 6742 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 6743 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 6744 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 6745 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 6746 | return -EINVAL; |
| 6747 | if (key.idx > 4) |
| 6748 | return -EINVAL; |
| 6749 | } else { |
| 6750 | key.p.key_len = 0; |
| 6751 | key.p.key = NULL; |
| 6752 | } |
| 6753 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6754 | if (key.idx >= 0) { |
| 6755 | int i; |
| 6756 | bool ok = false; |
| 6757 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 6758 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 6759 | ok = true; |
| 6760 | break; |
| 6761 | } |
| 6762 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6763 | if (!ok) |
| 6764 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6765 | } |
| 6766 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6767 | if (!rdev->ops->auth) |
| 6768 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6769 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6770 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6771 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6772 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6773 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6774 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6775 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 6776 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6777 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6778 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6779 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6780 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6781 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6782 | |
| 6783 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6784 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6785 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6786 | } |
| 6787 | |
| 6788 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6789 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6790 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6791 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6792 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 6793 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 6794 | return -EINVAL; |
| 6795 | |
| 6796 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 6797 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 6798 | return -EINVAL; |
| 6799 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6800 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6801 | /* need to include at least Auth Transaction and Status Code */ |
| 6802 | if (sae_data_len < 4) |
| 6803 | return -EINVAL; |
| 6804 | } |
| 6805 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6806 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6807 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6808 | /* |
| 6809 | * Since we no longer track auth state, ignore |
| 6810 | * requests to only change local state. |
| 6811 | */ |
| 6812 | if (local_state_change) |
| 6813 | return 0; |
| 6814 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6815 | wdev_lock(dev->ieee80211_ptr); |
| 6816 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 6817 | ssid, ssid_len, ie, ie_len, |
| 6818 | key.p.key, key.p.key_len, key.idx, |
| 6819 | sae_data, sae_data_len); |
| 6820 | wdev_unlock(dev->ieee80211_ptr); |
| 6821 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6822 | } |
| 6823 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6824 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 6825 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6826 | struct cfg80211_crypto_settings *settings, |
| 6827 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6828 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6829 | memset(settings, 0, sizeof(*settings)); |
| 6830 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6831 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 6832 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6833 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 6834 | u16 proto; |
| 6835 | proto = nla_get_u16( |
| 6836 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 6837 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6838 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6839 | proto != ETH_P_PAE) |
| 6840 | return -EINVAL; |
| 6841 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6842 | settings->control_port_no_encrypt = true; |
| 6843 | } else |
| 6844 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6845 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6846 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6847 | void *data; |
| 6848 | int len, i; |
| 6849 | |
| 6850 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6851 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6852 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6853 | |
| 6854 | if (len % sizeof(u32)) |
| 6855 | return -EINVAL; |
| 6856 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6857 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6858 | return -EINVAL; |
| 6859 | |
| 6860 | memcpy(settings->ciphers_pairwise, data, len); |
| 6861 | |
| 6862 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6863 | if (!cfg80211_supported_cipher_suite( |
| 6864 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6865 | settings->ciphers_pairwise[i])) |
| 6866 | return -EINVAL; |
| 6867 | } |
| 6868 | |
| 6869 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6870 | settings->cipher_group = |
| 6871 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6872 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6873 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6874 | return -EINVAL; |
| 6875 | } |
| 6876 | |
| 6877 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6878 | settings->wpa_versions = |
| 6879 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6880 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6881 | return -EINVAL; |
| 6882 | } |
| 6883 | |
| 6884 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6885 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6886 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6887 | |
| 6888 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6889 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6890 | settings->n_akm_suites = len / sizeof(u32); |
| 6891 | |
| 6892 | if (len % sizeof(u32)) |
| 6893 | return -EINVAL; |
| 6894 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6895 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6896 | return -EINVAL; |
| 6897 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6898 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6899 | } |
| 6900 | |
| 6901 | return 0; |
| 6902 | } |
| 6903 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6904 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6905 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6906 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6907 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6908 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6909 | struct cfg80211_assoc_request req = {}; |
| 6910 | const u8 *bssid, *ssid; |
| 6911 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6912 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6913 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6914 | return -EINVAL; |
| 6915 | |
| 6916 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6917 | !info->attrs[NL80211_ATTR_SSID] || |
| 6918 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6919 | return -EINVAL; |
| 6920 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6921 | if (!rdev->ops->assoc) |
| 6922 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6923 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6924 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6925 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6926 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6927 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6928 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6929 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6930 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 6931 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6932 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6933 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6934 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6935 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6936 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6937 | |
| 6938 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6939 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6940 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6941 | } |
| 6942 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6943 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6944 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6945 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6946 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6947 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6948 | else if (mfp != NL80211_MFP_NO) |
| 6949 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6950 | } |
| 6951 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6952 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6953 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6954 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6955 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6956 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6957 | |
| 6958 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6959 | memcpy(&req.ht_capa_mask, |
| 6960 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6961 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6962 | |
| 6963 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6964 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6965 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6966 | memcpy(&req.ht_capa, |
| 6967 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6968 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6969 | } |
| 6970 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6971 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6972 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6973 | |
| 6974 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6975 | memcpy(&req.vht_capa_mask, |
| 6976 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6977 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6978 | |
| 6979 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6980 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6981 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6982 | memcpy(&req.vht_capa, |
| 6983 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6984 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6985 | } |
| 6986 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 6987 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
| 6988 | if (!(rdev->wiphy.features & |
| 6989 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || |
| 6990 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) |
| 6991 | return -EINVAL; |
| 6992 | req.flags |= ASSOC_REQ_USE_RRM; |
| 6993 | } |
| 6994 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6995 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6996 | if (!err) { |
| 6997 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6998 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6999 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7000 | wdev_unlock(dev->ieee80211_ptr); |
| 7001 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7002 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7003 | return err; |
| 7004 | } |
| 7005 | |
| 7006 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 7007 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7008 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7009 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7010 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7011 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7012 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7013 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7014 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7015 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7016 | return -EINVAL; |
| 7017 | |
| 7018 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7019 | return -EINVAL; |
| 7020 | |
| 7021 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7022 | return -EINVAL; |
| 7023 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7024 | if (!rdev->ops->deauth) |
| 7025 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7026 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7027 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7028 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7029 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7030 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7031 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7032 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7033 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7034 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7035 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7036 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 7037 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7038 | |
| 7039 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7040 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7041 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7042 | } |
| 7043 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7044 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7045 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7046 | wdev_lock(dev->ieee80211_ptr); |
| 7047 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 7048 | local_state_change); |
| 7049 | wdev_unlock(dev->ieee80211_ptr); |
| 7050 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7051 | } |
| 7052 | |
| 7053 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 7054 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7055 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7056 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7057 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7058 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7059 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7060 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7061 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7062 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7063 | return -EINVAL; |
| 7064 | |
| 7065 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7066 | return -EINVAL; |
| 7067 | |
| 7068 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7069 | return -EINVAL; |
| 7070 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7071 | if (!rdev->ops->disassoc) |
| 7072 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7073 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7074 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7075 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7076 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7077 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7078 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7079 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7080 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7081 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 7082 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7083 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 7084 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7085 | |
| 7086 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 7087 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7088 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7089 | } |
| 7090 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 7091 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 7092 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7093 | wdev_lock(dev->ieee80211_ptr); |
| 7094 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 7095 | local_state_change); |
| 7096 | wdev_unlock(dev->ieee80211_ptr); |
| 7097 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 7098 | } |
| 7099 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7100 | static bool |
| 7101 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 7102 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 7103 | int rateval) |
| 7104 | { |
| 7105 | struct wiphy *wiphy = &rdev->wiphy; |
| 7106 | bool found = false; |
| 7107 | int band, i; |
| 7108 | |
| 7109 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 7110 | struct ieee80211_supported_band *sband; |
| 7111 | |
| 7112 | sband = wiphy->bands[band]; |
| 7113 | if (!sband) |
| 7114 | continue; |
| 7115 | |
| 7116 | for (i = 0; i < sband->n_bitrates; i++) { |
| 7117 | if (sband->bitrates[i].bitrate == rateval) { |
| 7118 | mcast_rate[band] = i + 1; |
| 7119 | found = true; |
| 7120 | break; |
| 7121 | } |
| 7122 | } |
| 7123 | } |
| 7124 | |
| 7125 | return found; |
| 7126 | } |
| 7127 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7128 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 7129 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7130 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7131 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7132 | struct cfg80211_ibss_params ibss; |
| 7133 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7134 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7135 | int err; |
| 7136 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 7137 | memset(&ibss, 0, sizeof(ibss)); |
| 7138 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7139 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7140 | return -EINVAL; |
| 7141 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7142 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7143 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 7144 | return -EINVAL; |
| 7145 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 7146 | ibss.beacon_interval = 100; |
| 7147 | |
| 7148 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 7149 | ibss.beacon_interval = |
| 7150 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 7151 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 7152 | return -EINVAL; |
| 7153 | } |
| 7154 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7155 | if (!rdev->ops->join_ibss) |
| 7156 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7157 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7158 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 7159 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7160 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7161 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7162 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 7163 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7164 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 7165 | |
| 7166 | if (!is_valid_ether_addr(ibss.bssid)) |
| 7167 | return -EINVAL; |
| 7168 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7169 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7170 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7171 | |
| 7172 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7173 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7174 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7175 | } |
| 7176 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7177 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 7178 | if (err) |
| 7179 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 7180 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 7181 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 7182 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 7183 | return -EINVAL; |
| 7184 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7185 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 7186 | case NL80211_CHAN_WIDTH_5: |
| 7187 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7188 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 7189 | break; |
| 7190 | case NL80211_CHAN_WIDTH_20: |
| 7191 | case NL80211_CHAN_WIDTH_40: |
| 7192 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) |
| 7193 | break; |
| 7194 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 7195 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 7196 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 7197 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7198 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7199 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7200 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7201 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 7202 | u8 *rates = |
| 7203 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7204 | int n_rates = |
| 7205 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7206 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7207 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7208 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7209 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 7210 | &ibss.basic_rates); |
| 7211 | if (err) |
| 7212 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7213 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7214 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 7215 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7216 | memcpy(&ibss.ht_capa_mask, |
| 7217 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7218 | sizeof(ibss.ht_capa_mask)); |
| 7219 | |
| 7220 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 7221 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7222 | return -EINVAL; |
| 7223 | memcpy(&ibss.ht_capa, |
| 7224 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7225 | sizeof(ibss.ht_capa)); |
| 7226 | } |
| 7227 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 7228 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 7229 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 7230 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 7231 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 7232 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7233 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7234 | bool no_ht = false; |
| 7235 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7236 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7237 | info->attrs[NL80211_ATTR_KEYS], |
| 7238 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7239 | if (IS_ERR(connkeys)) |
| 7240 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7241 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 7242 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 7243 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7244 | kfree(connkeys); |
| 7245 | return -EINVAL; |
| 7246 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7247 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7248 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 7249 | ibss.control_port = |
| 7250 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 7251 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 7252 | ibss.userspace_handles_dfs = |
| 7253 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 7254 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7255 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7256 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7257 | kzfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7258 | return err; |
| 7259 | } |
| 7260 | |
| 7261 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 7262 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7263 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7264 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7265 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7266 | if (!rdev->ops->leave_ibss) |
| 7267 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7268 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7269 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 7270 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7271 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7272 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7273 | } |
| 7274 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7275 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 7276 | { |
| 7277 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7278 | struct net_device *dev = info->user_ptr[1]; |
| 7279 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 7280 | u32 nla_rate; |
| 7281 | int err; |
| 7282 | |
| 7283 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 7284 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 7285 | return -EOPNOTSUPP; |
| 7286 | |
| 7287 | if (!rdev->ops->set_mcast_rate) |
| 7288 | return -EOPNOTSUPP; |
| 7289 | |
| 7290 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 7291 | |
| 7292 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 7293 | return -EINVAL; |
| 7294 | |
| 7295 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 7296 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 7297 | return -EINVAL; |
| 7298 | |
| 7299 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 7300 | |
| 7301 | return err; |
| 7302 | } |
| 7303 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7304 | static struct sk_buff * |
| 7305 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
| 7306 | int approxlen, u32 portid, u32 seq, |
| 7307 | enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 7308 | enum nl80211_attrs attr, |
| 7309 | const struct nl80211_vendor_cmd_info *info, |
| 7310 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7311 | { |
| 7312 | struct sk_buff *skb; |
| 7313 | void *hdr; |
| 7314 | struct nlattr *data; |
| 7315 | |
| 7316 | skb = nlmsg_new(approxlen + 100, gfp); |
| 7317 | if (!skb) |
| 7318 | return NULL; |
| 7319 | |
| 7320 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 7321 | if (!hdr) { |
| 7322 | kfree_skb(skb); |
| 7323 | return NULL; |
| 7324 | } |
| 7325 | |
| 7326 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 7327 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 7328 | |
| 7329 | if (info) { |
| 7330 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 7331 | info->vendor_id)) |
| 7332 | goto nla_put_failure; |
| 7333 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 7334 | info->subcmd)) |
| 7335 | goto nla_put_failure; |
| 7336 | } |
| 7337 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7338 | data = nla_nest_start(skb, attr); |
| 7339 | |
| 7340 | ((void **)skb->cb)[0] = rdev; |
| 7341 | ((void **)skb->cb)[1] = hdr; |
| 7342 | ((void **)skb->cb)[2] = data; |
| 7343 | |
| 7344 | return skb; |
| 7345 | |
| 7346 | nla_put_failure: |
| 7347 | kfree_skb(skb); |
| 7348 | return NULL; |
| 7349 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7350 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7351 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
| 7352 | enum nl80211_commands cmd, |
| 7353 | enum nl80211_attrs attr, |
| 7354 | int vendor_event_idx, |
| 7355 | int approxlen, gfp_t gfp) |
| 7356 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 7357 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7358 | const struct nl80211_vendor_cmd_info *info; |
| 7359 | |
| 7360 | switch (cmd) { |
| 7361 | case NL80211_CMD_TESTMODE: |
| 7362 | if (WARN_ON(vendor_event_idx != -1)) |
| 7363 | return NULL; |
| 7364 | info = NULL; |
| 7365 | break; |
| 7366 | case NL80211_CMD_VENDOR: |
| 7367 | if (WARN_ON(vendor_event_idx < 0 || |
| 7368 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 7369 | return NULL; |
| 7370 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 7371 | break; |
| 7372 | default: |
| 7373 | WARN_ON(1); |
| 7374 | return NULL; |
| 7375 | } |
| 7376 | |
| 7377 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, |
| 7378 | cmd, attr, info, gfp); |
| 7379 | } |
| 7380 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 7381 | |
| 7382 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 7383 | { |
| 7384 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 7385 | void *hdr = ((void **)skb->cb)[1]; |
| 7386 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 7387 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 7388 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 7389 | /* clear CB data for netlink core to own from now on */ |
| 7390 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 7391 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7392 | nla_nest_end(skb, data); |
| 7393 | genlmsg_end(skb, hdr); |
| 7394 | |
| 7395 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 7396 | mcgrp = NL80211_MCGRP_VENDOR; |
| 7397 | |
| 7398 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 7399 | mcgrp, gfp); |
| 7400 | } |
| 7401 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 7402 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7403 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7404 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 7405 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7406 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7407 | struct wireless_dev *wdev = |
| 7408 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7409 | int err; |
| 7410 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7411 | if (!rdev->ops->testmode_cmd) |
| 7412 | return -EOPNOTSUPP; |
| 7413 | |
| 7414 | if (IS_ERR(wdev)) { |
| 7415 | err = PTR_ERR(wdev); |
| 7416 | if (err != -EINVAL) |
| 7417 | return err; |
| 7418 | wdev = NULL; |
| 7419 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 7420 | return -EINVAL; |
| 7421 | } |
| 7422 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7423 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 7424 | return -EINVAL; |
| 7425 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7426 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7427 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7428 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 7429 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7430 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7431 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7432 | return err; |
| 7433 | } |
| 7434 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7435 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 7436 | struct netlink_callback *cb) |
| 7437 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7438 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7439 | int err; |
| 7440 | long phy_idx; |
| 7441 | void *data = NULL; |
| 7442 | int data_len = 0; |
| 7443 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7444 | rtnl_lock(); |
| 7445 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7446 | if (cb->args[0]) { |
| 7447 | /* |
| 7448 | * 0 is a valid index, but not valid for args[0], |
| 7449 | * so we need to offset by 1. |
| 7450 | */ |
| 7451 | phy_idx = cb->args[0] - 1; |
| 7452 | } else { |
| 7453 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 7454 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 7455 | nl80211_policy); |
| 7456 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7457 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7458 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7459 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 7460 | nl80211_fam.attrbuf); |
| 7461 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7462 | err = PTR_ERR(rdev); |
| 7463 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7464 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7465 | phy_idx = rdev->wiphy_idx; |
| 7466 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7467 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7468 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 7469 | cb->args[1] = |
| 7470 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 7471 | } |
| 7472 | |
| 7473 | if (cb->args[1]) { |
| 7474 | data = nla_data((void *)cb->args[1]); |
| 7475 | data_len = nla_len((void *)cb->args[1]); |
| 7476 | } |
| 7477 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7478 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 7479 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7480 | err = -ENOENT; |
| 7481 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7482 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7483 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7484 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7485 | err = -EOPNOTSUPP; |
| 7486 | goto out_err; |
| 7487 | } |
| 7488 | |
| 7489 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7490 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7491 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 7492 | NL80211_CMD_TESTMODE); |
| 7493 | struct nlattr *tmdata; |
| 7494 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7495 | if (!hdr) |
| 7496 | break; |
| 7497 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7498 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7499 | genlmsg_cancel(skb, hdr); |
| 7500 | break; |
| 7501 | } |
| 7502 | |
| 7503 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 7504 | if (!tmdata) { |
| 7505 | genlmsg_cancel(skb, hdr); |
| 7506 | break; |
| 7507 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7508 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7509 | nla_nest_end(skb, tmdata); |
| 7510 | |
| 7511 | if (err == -ENOBUFS || err == -ENOENT) { |
| 7512 | genlmsg_cancel(skb, hdr); |
| 7513 | break; |
| 7514 | } else if (err) { |
| 7515 | genlmsg_cancel(skb, hdr); |
| 7516 | goto out_err; |
| 7517 | } |
| 7518 | |
| 7519 | genlmsg_end(skb, hdr); |
| 7520 | } |
| 7521 | |
| 7522 | err = skb->len; |
| 7523 | /* see above */ |
| 7524 | cb->args[0] = phy_idx + 1; |
| 7525 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7526 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7527 | return err; |
| 7528 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7529 | #endif |
| 7530 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7531 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 7532 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7533 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7534 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7535 | struct cfg80211_connect_params connect; |
| 7536 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7537 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7538 | int err; |
| 7539 | |
| 7540 | memset(&connect, 0, sizeof(connect)); |
| 7541 | |
| 7542 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7543 | return -EINVAL; |
| 7544 | |
| 7545 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 7546 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 7547 | return -EINVAL; |
| 7548 | |
| 7549 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 7550 | connect.auth_type = |
| 7551 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7552 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 7553 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7554 | return -EINVAL; |
| 7555 | } else |
| 7556 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 7557 | |
| 7558 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 7559 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7560 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7561 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7562 | if (err) |
| 7563 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7564 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7565 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7566 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7567 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7568 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7569 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7570 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 7571 | connect.bg_scan_period = -1; |
| 7572 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 7573 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 7574 | connect.bg_scan_period = |
| 7575 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 7576 | } |
| 7577 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7578 | if (info->attrs[NL80211_ATTR_MAC]) |
| 7579 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7580 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 7581 | connect.bssid_hint = |
| 7582 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7583 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7584 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7585 | |
| 7586 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7587 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7588 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7589 | } |
| 7590 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 7591 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 7592 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 7593 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 7594 | connect.mfp != NL80211_MFP_NO) |
| 7595 | return -EINVAL; |
| 7596 | } else { |
| 7597 | connect.mfp = NL80211_MFP_NO; |
| 7598 | } |
| 7599 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7600 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7601 | connect.channel = nl80211_get_valid_chan( |
| 7602 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7603 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7604 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7605 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7606 | connect.channel_hint = nl80211_get_valid_chan( |
| 7607 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 7608 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7609 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7610 | } |
| 7611 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7612 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 7613 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7614 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7615 | if (IS_ERR(connkeys)) |
| 7616 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7617 | } |
| 7618 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7619 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 7620 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 7621 | |
| 7622 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7623 | memcpy(&connect.ht_capa_mask, |
| 7624 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7625 | sizeof(connect.ht_capa_mask)); |
| 7626 | |
| 7627 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7628 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7629 | kzfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7630 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7631 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7632 | memcpy(&connect.ht_capa, |
| 7633 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7634 | sizeof(connect.ht_capa)); |
| 7635 | } |
| 7636 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7637 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 7638 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 7639 | |
| 7640 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 7641 | memcpy(&connect.vht_capa_mask, |
| 7642 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7643 | sizeof(connect.vht_capa_mask)); |
| 7644 | |
| 7645 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 7646 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7647 | kzfree(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7648 | return -EINVAL; |
| 7649 | } |
| 7650 | memcpy(&connect.vht_capa, |
| 7651 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7652 | sizeof(connect.vht_capa)); |
| 7653 | } |
| 7654 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 7655 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
| 7656 | if (!(rdev->wiphy.features & |
| 7657 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || |
| 7658 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) |
| 7659 | return -EINVAL; |
| 7660 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 7661 | } |
| 7662 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7663 | wdev_lock(dev->ieee80211_ptr); |
| 7664 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 7665 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7666 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7667 | kzfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7668 | return err; |
| 7669 | } |
| 7670 | |
| 7671 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 7672 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7673 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7674 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7675 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7676 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7677 | |
| 7678 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7679 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 7680 | else |
| 7681 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7682 | |
| 7683 | if (reason == 0) |
| 7684 | return -EINVAL; |
| 7685 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7686 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7687 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7688 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7689 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7690 | wdev_lock(dev->ieee80211_ptr); |
| 7691 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 7692 | wdev_unlock(dev->ieee80211_ptr); |
| 7693 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7694 | } |
| 7695 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7696 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 7697 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7698 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7699 | struct net *net; |
| 7700 | int err; |
| 7701 | u32 pid; |
| 7702 | |
| 7703 | if (!info->attrs[NL80211_ATTR_PID]) |
| 7704 | return -EINVAL; |
| 7705 | |
| 7706 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 7707 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7708 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7709 | if (IS_ERR(net)) |
| 7710 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7711 | |
| 7712 | err = 0; |
| 7713 | |
| 7714 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7715 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 7716 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7717 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7718 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7719 | return err; |
| 7720 | } |
| 7721 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7722 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7723 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7724 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7725 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 7726 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7727 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7728 | struct cfg80211_pmksa pmksa; |
| 7729 | |
| 7730 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 7731 | |
| 7732 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7733 | return -EINVAL; |
| 7734 | |
| 7735 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 7736 | return -EINVAL; |
| 7737 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7738 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 7739 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7740 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7741 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7742 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7743 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7744 | |
| 7745 | switch (info->genlhdr->cmd) { |
| 7746 | case NL80211_CMD_SET_PMKSA: |
| 7747 | rdev_ops = rdev->ops->set_pmksa; |
| 7748 | break; |
| 7749 | case NL80211_CMD_DEL_PMKSA: |
| 7750 | rdev_ops = rdev->ops->del_pmksa; |
| 7751 | break; |
| 7752 | default: |
| 7753 | WARN_ON(1); |
| 7754 | break; |
| 7755 | } |
| 7756 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7757 | if (!rdev_ops) |
| 7758 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7759 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7760 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7761 | } |
| 7762 | |
| 7763 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7764 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7765 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7766 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7767 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7768 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7769 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7770 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7771 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7772 | if (!rdev->ops->flush_pmksa) |
| 7773 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7774 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7775 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7776 | } |
| 7777 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7778 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 7779 | { |
| 7780 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7781 | struct net_device *dev = info->user_ptr[1]; |
| 7782 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7783 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7784 | u16 status_code; |
| 7785 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7786 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7787 | |
| 7788 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7789 | !rdev->ops->tdls_mgmt) |
| 7790 | return -EOPNOTSUPP; |
| 7791 | |
| 7792 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 7793 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 7794 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 7795 | !info->attrs[NL80211_ATTR_IE] || |
| 7796 | !info->attrs[NL80211_ATTR_MAC]) |
| 7797 | return -EINVAL; |
| 7798 | |
| 7799 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7800 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 7801 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 7802 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7803 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7804 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 7805 | peer_capability = |
| 7806 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7807 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7808 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7809 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7810 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7811 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 7812 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7813 | } |
| 7814 | |
| 7815 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 7816 | { |
| 7817 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7818 | struct net_device *dev = info->user_ptr[1]; |
| 7819 | enum nl80211_tdls_operation operation; |
| 7820 | u8 *peer; |
| 7821 | |
| 7822 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7823 | !rdev->ops->tdls_oper) |
| 7824 | return -EOPNOTSUPP; |
| 7825 | |
| 7826 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 7827 | !info->attrs[NL80211_ATTR_MAC]) |
| 7828 | return -EINVAL; |
| 7829 | |
| 7830 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 7831 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7832 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7833 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7834 | } |
| 7835 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7836 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 7837 | struct genl_info *info) |
| 7838 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7839 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7840 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7841 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7842 | struct sk_buff *msg; |
| 7843 | void *hdr; |
| 7844 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7845 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7846 | int err; |
| 7847 | |
| 7848 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7849 | !info->attrs[NL80211_ATTR_DURATION]) |
| 7850 | return -EINVAL; |
| 7851 | |
| 7852 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 7853 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7854 | if (!rdev->ops->remain_on_channel || |
| 7855 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7856 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7857 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7858 | /* |
| 7859 | * We should be on that channel for at least a minimum amount of |
| 7860 | * time (10ms) but no longer than the driver supports. |
| 7861 | */ |
| 7862 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7863 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 7864 | return -EINVAL; |
| 7865 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7866 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7867 | if (err) |
| 7868 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7869 | |
| 7870 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7871 | if (!msg) |
| 7872 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7873 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7874 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7875 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7876 | if (!hdr) { |
| 7877 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7878 | goto free_msg; |
| 7879 | } |
| 7880 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7881 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 7882 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7883 | |
| 7884 | if (err) |
| 7885 | goto free_msg; |
| 7886 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7887 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7888 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7889 | |
| 7890 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7891 | |
| 7892 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7893 | |
| 7894 | nla_put_failure: |
| 7895 | err = -ENOBUFS; |
| 7896 | free_msg: |
| 7897 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7898 | return err; |
| 7899 | } |
| 7900 | |
| 7901 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 7902 | struct genl_info *info) |
| 7903 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7904 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7905 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7906 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7907 | |
| 7908 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7909 | return -EINVAL; |
| 7910 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7911 | if (!rdev->ops->cancel_remain_on_channel) |
| 7912 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7913 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7914 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7915 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7916 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7917 | } |
| 7918 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7919 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7920 | u8 *rates, u8 rates_len) |
| 7921 | { |
| 7922 | u8 i; |
| 7923 | u32 mask = 0; |
| 7924 | |
| 7925 | for (i = 0; i < rates_len; i++) { |
| 7926 | int rate = (rates[i] & 0x7f) * 5; |
| 7927 | int ridx; |
| 7928 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 7929 | struct ieee80211_rate *srate = |
| 7930 | &sband->bitrates[ridx]; |
| 7931 | if (rate == srate->bitrate) { |
| 7932 | mask |= 1 << ridx; |
| 7933 | break; |
| 7934 | } |
| 7935 | } |
| 7936 | if (ridx == sband->n_bitrates) |
| 7937 | return 0; /* rate not found */ |
| 7938 | } |
| 7939 | |
| 7940 | return mask; |
| 7941 | } |
| 7942 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7943 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7944 | u8 *rates, u8 rates_len, |
| 7945 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 7946 | { |
| 7947 | u8 i; |
| 7948 | |
| 7949 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 7950 | |
| 7951 | for (i = 0; i < rates_len; i++) { |
| 7952 | int ridx, rbit; |
| 7953 | |
| 7954 | ridx = rates[i] / 8; |
| 7955 | rbit = BIT(rates[i] % 8); |
| 7956 | |
| 7957 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7958 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7959 | return false; |
| 7960 | |
| 7961 | /* check availability */ |
| 7962 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7963 | mcs[ridx] |= rbit; |
| 7964 | else |
| 7965 | return false; |
| 7966 | } |
| 7967 | |
| 7968 | return true; |
| 7969 | } |
| 7970 | |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7971 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 7972 | { |
| 7973 | u16 mcs_mask = 0; |
| 7974 | |
| 7975 | switch (vht_mcs_map) { |
| 7976 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 7977 | break; |
| 7978 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 7979 | mcs_mask = 0x00FF; |
| 7980 | break; |
| 7981 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 7982 | mcs_mask = 0x01FF; |
| 7983 | break; |
| 7984 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 7985 | mcs_mask = 0x03FF; |
| 7986 | break; |
| 7987 | default: |
| 7988 | break; |
| 7989 | } |
| 7990 | |
| 7991 | return mcs_mask; |
| 7992 | } |
| 7993 | |
| 7994 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 7995 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 7996 | { |
| 7997 | u8 nss; |
| 7998 | |
| 7999 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 8000 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 8001 | vht_mcs_map >>= 2; |
| 8002 | } |
| 8003 | } |
| 8004 | |
| 8005 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 8006 | struct nl80211_txrate_vht *txrate, |
| 8007 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 8008 | { |
| 8009 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 8010 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 8011 | u8 i; |
| 8012 | |
| 8013 | if (!sband->vht_cap.vht_supported) |
| 8014 | return false; |
| 8015 | |
| 8016 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 8017 | |
| 8018 | /* Build vht_mcs_mask from VHT capabilities */ |
| 8019 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 8020 | |
| 8021 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 8022 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 8023 | mcs[i] = txrate->mcs[i]; |
| 8024 | else |
| 8025 | return false; |
| 8026 | } |
| 8027 | |
| 8028 | return true; |
| 8029 | } |
| 8030 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 8031 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8032 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 8033 | .len = NL80211_MAX_SUPP_RATES }, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8034 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 8035 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8036 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 8037 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8038 | }; |
| 8039 | |
| 8040 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 8041 | struct genl_info *info) |
| 8042 | { |
| 8043 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8044 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8045 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8046 | int rem, i; |
| 8047 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8048 | struct nlattr *tx_rates; |
| 8049 | struct ieee80211_supported_band *sband; |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8050 | u16 vht_tx_mcs_map; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8051 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8052 | if (!rdev->ops->set_bitrate_mask) |
| 8053 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8054 | |
| 8055 | memset(&mask, 0, sizeof(mask)); |
| 8056 | /* Default to all rates enabled */ |
| 8057 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 8058 | sband = rdev->wiphy.bands[i]; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 8059 | |
| 8060 | if (!sband) |
| 8061 | continue; |
| 8062 | |
| 8063 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8064 | memcpy(mask.control[i].ht_mcs, |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 8065 | sband->ht_cap.mcs.rx_mask, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8066 | sizeof(mask.control[i].ht_mcs)); |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8067 | |
| 8068 | if (!sband->vht_cap.vht_supported) |
| 8069 | continue; |
| 8070 | |
| 8071 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 8072 | 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] | 8073 | } |
| 8074 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 8075 | /* if no rates are given set it back to the defaults */ |
| 8076 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 8077 | goto out; |
| 8078 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8079 | /* |
| 8080 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 8081 | * directly to the enum ieee80211_band values used in cfg80211. |
| 8082 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8083 | 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] | 8084 | 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] | 8085 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8086 | int err; |
| 8087 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8088 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 8089 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8090 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8091 | if (sband == NULL) |
| 8092 | return -EINVAL; |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8093 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 8094 | nla_len(tx_rates), nl80211_txattr_policy); |
| 8095 | if (err) |
| 8096 | return err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8097 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 8098 | mask.control[band].legacy = rateset_to_mask( |
| 8099 | sband, |
| 8100 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 8101 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 8102 | if ((mask.control[band].legacy == 0) && |
| 8103 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 8104 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8105 | } |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8106 | if (tb[NL80211_TXRATE_HT]) { |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8107 | if (!ht_rateset_to_mask( |
| 8108 | sband, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8109 | nla_data(tb[NL80211_TXRATE_HT]), |
| 8110 | nla_len(tb[NL80211_TXRATE_HT]), |
| 8111 | mask.control[band].ht_mcs)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8112 | return -EINVAL; |
| 8113 | } |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8114 | if (tb[NL80211_TXRATE_VHT]) { |
| 8115 | if (!vht_set_mcs_mask( |
| 8116 | sband, |
| 8117 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 8118 | mask.control[band].vht_mcs)) |
| 8119 | return -EINVAL; |
| 8120 | } |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 8121 | if (tb[NL80211_TXRATE_GI]) { |
| 8122 | mask.control[band].gi = |
| 8123 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 8124 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 8125 | return -EINVAL; |
| 8126 | } |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8127 | |
| 8128 | if (mask.control[band].legacy == 0) { |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8129 | /* don't allow empty legacy rates if HT or VHT |
| 8130 | * are not even supported. |
| 8131 | */ |
| 8132 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 8133 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8134 | return -EINVAL; |
| 8135 | |
| 8136 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 8137 | if (mask.control[band].ht_mcs[i]) |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8138 | goto out; |
| 8139 | |
| 8140 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 8141 | if (mask.control[band].vht_mcs[i]) |
| 8142 | goto out; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 8143 | |
| 8144 | /* legacy and mcs rates may not be both empty */ |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 8145 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8146 | } |
| 8147 | } |
| 8148 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 8149 | out: |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8150 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 8151 | } |
| 8152 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8153 | 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] | 8154 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8155 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8156 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8157 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8158 | |
| 8159 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 8160 | return -EINVAL; |
| 8161 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8162 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 8163 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8164 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8165 | switch (wdev->iftype) { |
| 8166 | case NL80211_IFTYPE_STATION: |
| 8167 | case NL80211_IFTYPE_ADHOC: |
| 8168 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8169 | case NL80211_IFTYPE_AP: |
| 8170 | case NL80211_IFTYPE_AP_VLAN: |
| 8171 | case NL80211_IFTYPE_MESH_POINT: |
| 8172 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8173 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8174 | break; |
| 8175 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8176 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8177 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8178 | |
| 8179 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8180 | if (!rdev->ops->mgmt_tx) |
| 8181 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8182 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8183 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8184 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 8185 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8186 | } |
| 8187 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 8188 | 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] | 8189 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8190 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8191 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8192 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8193 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 8194 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8195 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8196 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8197 | struct cfg80211_mgmt_tx_params params = { |
| 8198 | .dont_wait_for_ack = |
| 8199 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 8200 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8201 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8202 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8203 | return -EINVAL; |
| 8204 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8205 | if (!rdev->ops->mgmt_tx) |
| 8206 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8207 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8208 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8209 | case NL80211_IFTYPE_P2P_DEVICE: |
| 8210 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 8211 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8212 | case NL80211_IFTYPE_STATION: |
| 8213 | case NL80211_IFTYPE_ADHOC: |
| 8214 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8215 | case NL80211_IFTYPE_AP: |
| 8216 | case NL80211_IFTYPE_AP_VLAN: |
| 8217 | case NL80211_IFTYPE_MESH_POINT: |
| 8218 | case NL80211_IFTYPE_P2P_GO: |
| 8219 | break; |
| 8220 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8221 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8222 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8223 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8224 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8225 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8226 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8227 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8228 | |
| 8229 | /* |
| 8230 | * We should wait on the channel for at least a minimum amount |
| 8231 | * of time (10ms) but no longer than the driver supports. |
| 8232 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8233 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 8234 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8235 | return -EINVAL; |
| 8236 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8237 | } |
| 8238 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8239 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8240 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8241 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8242 | return -EINVAL; |
| 8243 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8244 | 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] | 8245 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8246 | /* get the channel if any has been specified, otherwise pass NULL to |
| 8247 | * the driver. The latter will use the current one |
| 8248 | */ |
| 8249 | chandef.chan = NULL; |
| 8250 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 8251 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8252 | if (err) |
| 8253 | return err; |
| 8254 | } |
| 8255 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8256 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8257 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8258 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 8259 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 8260 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 8261 | |
| 8262 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 8263 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 8264 | int i; |
| 8265 | |
| 8266 | if (len % sizeof(u16)) |
| 8267 | return -EINVAL; |
| 8268 | |
| 8269 | params.n_csa_offsets = len / sizeof(u16); |
| 8270 | params.csa_offsets = |
| 8271 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 8272 | |
| 8273 | /* check that all the offsets fit the frame */ |
| 8274 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 8275 | if (params.csa_offsets[i] >= params.len) |
| 8276 | return -EINVAL; |
| 8277 | } |
| 8278 | } |
| 8279 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8280 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8281 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8282 | if (!msg) |
| 8283 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8284 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8285 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8286 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8287 | if (!hdr) { |
| 8288 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8289 | goto free_msg; |
| 8290 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8291 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8292 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8293 | params.chan = chandef.chan; |
| 8294 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8295 | if (err) |
| 8296 | goto free_msg; |
| 8297 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8298 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8299 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8300 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8301 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8302 | genlmsg_end(msg, hdr); |
| 8303 | return genlmsg_reply(msg, info); |
| 8304 | } |
| 8305 | |
| 8306 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8307 | |
| 8308 | nla_put_failure: |
| 8309 | err = -ENOBUFS; |
| 8310 | free_msg: |
| 8311 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8312 | return err; |
| 8313 | } |
| 8314 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8315 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 8316 | { |
| 8317 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8318 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8319 | u64 cookie; |
| 8320 | |
| 8321 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 8322 | return -EINVAL; |
| 8323 | |
| 8324 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 8325 | return -EOPNOTSUPP; |
| 8326 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8327 | switch (wdev->iftype) { |
| 8328 | case NL80211_IFTYPE_STATION: |
| 8329 | case NL80211_IFTYPE_ADHOC: |
| 8330 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8331 | case NL80211_IFTYPE_AP: |
| 8332 | case NL80211_IFTYPE_AP_VLAN: |
| 8333 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8334 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8335 | break; |
| 8336 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8337 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8338 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8339 | |
| 8340 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 8341 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8342 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8343 | } |
| 8344 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8345 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 8346 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8347 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8348 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8349 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8350 | u8 ps_state; |
| 8351 | bool state; |
| 8352 | int err; |
| 8353 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8354 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 8355 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8356 | |
| 8357 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 8358 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8359 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 8360 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8361 | |
| 8362 | wdev = dev->ieee80211_ptr; |
| 8363 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8364 | if (!rdev->ops->set_power_mgmt) |
| 8365 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8366 | |
| 8367 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 8368 | |
| 8369 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8370 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8371 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8372 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8373 | if (!err) |
| 8374 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8375 | return err; |
| 8376 | } |
| 8377 | |
| 8378 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 8379 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8380 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8381 | enum nl80211_ps_state ps_state; |
| 8382 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8383 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8384 | struct sk_buff *msg; |
| 8385 | void *hdr; |
| 8386 | int err; |
| 8387 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8388 | wdev = dev->ieee80211_ptr; |
| 8389 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8390 | if (!rdev->ops->set_power_mgmt) |
| 8391 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8392 | |
| 8393 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8394 | if (!msg) |
| 8395 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8396 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8397 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8398 | NL80211_CMD_GET_POWER_SAVE); |
| 8399 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8400 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8401 | goto free_msg; |
| 8402 | } |
| 8403 | |
| 8404 | if (wdev->ps) |
| 8405 | ps_state = NL80211_PS_ENABLED; |
| 8406 | else |
| 8407 | ps_state = NL80211_PS_DISABLED; |
| 8408 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8409 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 8410 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8411 | |
| 8412 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8413 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8414 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8415 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8416 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8417 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8418 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8419 | return err; |
| 8420 | } |
| 8421 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 8422 | static const struct nla_policy |
| 8423 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8424 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 8425 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 8426 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8427 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 8428 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 8429 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8430 | }; |
| 8431 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8432 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8433 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8434 | { |
| 8435 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8436 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8437 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8438 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8439 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8440 | return -EINVAL; |
| 8441 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8442 | if (!rdev->ops->set_cqm_txe_config) |
| 8443 | return -EOPNOTSUPP; |
| 8444 | |
| 8445 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 8446 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8447 | return -EOPNOTSUPP; |
| 8448 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8449 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8450 | } |
| 8451 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8452 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 8453 | s32 threshold, u32 hysteresis) |
| 8454 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8455 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8456 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8457 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8458 | |
| 8459 | if (threshold > 0) |
| 8460 | return -EINVAL; |
| 8461 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8462 | /* disabling - hysteresis should also be zero then */ |
| 8463 | if (threshold == 0) |
| 8464 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8465 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8466 | if (!rdev->ops->set_cqm_rssi_config) |
| 8467 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8468 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8469 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8470 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8471 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8472 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8473 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8474 | } |
| 8475 | |
| 8476 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 8477 | { |
| 8478 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 8479 | struct nlattr *cqm; |
| 8480 | int err; |
| 8481 | |
| 8482 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8483 | if (!cqm) |
| 8484 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8485 | |
| 8486 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 8487 | nl80211_attr_cqm_policy); |
| 8488 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8489 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8490 | |
| 8491 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 8492 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8493 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 8494 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8495 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8496 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 8497 | } |
| 8498 | |
| 8499 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 8500 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 8501 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 8502 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 8503 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 8504 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 8505 | |
| 8506 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 8507 | } |
| 8508 | |
| 8509 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8510 | } |
| 8511 | |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 8512 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 8513 | { |
| 8514 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8515 | struct net_device *dev = info->user_ptr[1]; |
| 8516 | struct ocb_setup setup = {}; |
| 8517 | int err; |
| 8518 | |
| 8519 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 8520 | if (err) |
| 8521 | return err; |
| 8522 | |
| 8523 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 8524 | } |
| 8525 | |
| 8526 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 8527 | { |
| 8528 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8529 | struct net_device *dev = info->user_ptr[1]; |
| 8530 | |
| 8531 | return cfg80211_leave_ocb(rdev, dev); |
| 8532 | } |
| 8533 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8534 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8535 | { |
| 8536 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8537 | struct net_device *dev = info->user_ptr[1]; |
| 8538 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8539 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8540 | int err; |
| 8541 | |
| 8542 | /* start with default */ |
| 8543 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8544 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8545 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8546 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8547 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8548 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8549 | if (err) |
| 8550 | return err; |
| 8551 | } |
| 8552 | |
| 8553 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 8554 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 8555 | return -EINVAL; |
| 8556 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8557 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8558 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8559 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 8560 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 8561 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 8562 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 8563 | return -EINVAL; |
| 8564 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 8565 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 8566 | setup.beacon_interval = |
| 8567 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 8568 | if (setup.beacon_interval < 10 || |
| 8569 | setup.beacon_interval > 10000) |
| 8570 | return -EINVAL; |
| 8571 | } |
| 8572 | |
| 8573 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 8574 | setup.dtim_period = |
| 8575 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 8576 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 8577 | return -EINVAL; |
| 8578 | } |
| 8579 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8580 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 8581 | /* parse additional setup parameters if given */ |
| 8582 | err = nl80211_parse_mesh_setup(info, &setup); |
| 8583 | if (err) |
| 8584 | return err; |
| 8585 | } |
| 8586 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 8587 | if (setup.user_mpm) |
| 8588 | cfg.auto_open_plinks = false; |
| 8589 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8590 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8591 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 8592 | if (err) |
| 8593 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8594 | } else { |
| 8595 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8596 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8597 | } |
| 8598 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 8599 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 8600 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8601 | int n_rates = |
| 8602 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8603 | struct ieee80211_supported_band *sband; |
| 8604 | |
| 8605 | if (!setup.chandef.chan) |
| 8606 | return -EINVAL; |
| 8607 | |
| 8608 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 8609 | |
| 8610 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 8611 | &setup.basic_rates); |
| 8612 | if (err) |
| 8613 | return err; |
| 8614 | } |
| 8615 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8616 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8617 | } |
| 8618 | |
| 8619 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8620 | { |
| 8621 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8622 | struct net_device *dev = info->user_ptr[1]; |
| 8623 | |
| 8624 | return cfg80211_leave_mesh(rdev, dev); |
| 8625 | } |
| 8626 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8627 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8628 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 8629 | struct cfg80211_registered_device *rdev) |
| 8630 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8631 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8632 | struct nlattr *nl_pats, *nl_pat; |
| 8633 | int i, pat_len; |
| 8634 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8635 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8636 | return 0; |
| 8637 | |
| 8638 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 8639 | if (!nl_pats) |
| 8640 | return -ENOBUFS; |
| 8641 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8642 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8643 | nl_pat = nla_nest_start(msg, i + 1); |
| 8644 | if (!nl_pat) |
| 8645 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8646 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8647 | 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] | 8648 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8649 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8650 | wowlan->patterns[i].pattern) || |
| 8651 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8652 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8653 | return -ENOBUFS; |
| 8654 | nla_nest_end(msg, nl_pat); |
| 8655 | } |
| 8656 | nla_nest_end(msg, nl_pats); |
| 8657 | |
| 8658 | return 0; |
| 8659 | } |
| 8660 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8661 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 8662 | struct cfg80211_wowlan_tcp *tcp) |
| 8663 | { |
| 8664 | struct nlattr *nl_tcp; |
| 8665 | |
| 8666 | if (!tcp) |
| 8667 | return 0; |
| 8668 | |
| 8669 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 8670 | if (!nl_tcp) |
| 8671 | return -ENOBUFS; |
| 8672 | |
| 8673 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 8674 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 8675 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 8676 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 8677 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 8678 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 8679 | tcp->payload_len, tcp->payload) || |
| 8680 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 8681 | tcp->data_interval) || |
| 8682 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 8683 | tcp->wake_len, tcp->wake_data) || |
| 8684 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 8685 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 8686 | return -ENOBUFS; |
| 8687 | |
| 8688 | if (tcp->payload_seq.len && |
| 8689 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 8690 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 8691 | return -ENOBUFS; |
| 8692 | |
| 8693 | if (tcp->payload_tok.len && |
| 8694 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 8695 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 8696 | &tcp->payload_tok)) |
| 8697 | return -ENOBUFS; |
| 8698 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 8699 | nla_nest_end(msg, nl_tcp); |
| 8700 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8701 | return 0; |
| 8702 | } |
| 8703 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8704 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8705 | { |
| 8706 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8707 | struct sk_buff *msg; |
| 8708 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8709 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8710 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8711 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8712 | return -EOPNOTSUPP; |
| 8713 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8714 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8715 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8716 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 8717 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 8718 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 8719 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8720 | } |
| 8721 | |
| 8722 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8723 | if (!msg) |
| 8724 | return -ENOMEM; |
| 8725 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8726 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8727 | NL80211_CMD_GET_WOWLAN); |
| 8728 | if (!hdr) |
| 8729 | goto nla_put_failure; |
| 8730 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8731 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8732 | struct nlattr *nl_wowlan; |
| 8733 | |
| 8734 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 8735 | if (!nl_wowlan) |
| 8736 | goto nla_put_failure; |
| 8737 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8738 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8739 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8740 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8741 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8742 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8743 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8744 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8745 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8746 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8747 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8748 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8749 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8750 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8751 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 8752 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8753 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8754 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 8755 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8756 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8757 | if (nl80211_send_wowlan_tcp(msg, |
| 8758 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8759 | goto nla_put_failure; |
| 8760 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8761 | nla_nest_end(msg, nl_wowlan); |
| 8762 | } |
| 8763 | |
| 8764 | genlmsg_end(msg, hdr); |
| 8765 | return genlmsg_reply(msg, info); |
| 8766 | |
| 8767 | nla_put_failure: |
| 8768 | nlmsg_free(msg); |
| 8769 | return -ENOBUFS; |
| 8770 | } |
| 8771 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8772 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 8773 | struct nlattr *attr, |
| 8774 | struct cfg80211_wowlan *trig) |
| 8775 | { |
| 8776 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 8777 | struct cfg80211_wowlan_tcp *cfg; |
| 8778 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 8779 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 8780 | u32 size; |
| 8781 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 8782 | int err, port; |
| 8783 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8784 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8785 | return -EINVAL; |
| 8786 | |
| 8787 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 8788 | nla_data(attr), nla_len(attr), |
| 8789 | nl80211_wowlan_tcp_policy); |
| 8790 | if (err) |
| 8791 | return err; |
| 8792 | |
| 8793 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 8794 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 8795 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 8796 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 8797 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 8798 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 8799 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 8800 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 8801 | return -EINVAL; |
| 8802 | |
| 8803 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8804 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8805 | return -EINVAL; |
| 8806 | |
| 8807 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8808 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 8809 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8810 | return -EINVAL; |
| 8811 | |
| 8812 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8813 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8814 | return -EINVAL; |
| 8815 | |
| 8816 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 8817 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 8818 | return -EINVAL; |
| 8819 | |
| 8820 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 8821 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8822 | |
| 8823 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8824 | tokens_size = tokln - sizeof(*tok); |
| 8825 | |
| 8826 | if (!tok->len || tokens_size % tok->len) |
| 8827 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8828 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8829 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8830 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8831 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8832 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8833 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8834 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8835 | return -EINVAL; |
| 8836 | if (tok->offset + tok->len > data_size) |
| 8837 | return -EINVAL; |
| 8838 | } |
| 8839 | |
| 8840 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 8841 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8842 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8843 | return -EINVAL; |
| 8844 | if (seq->len == 0 || seq->len > 4) |
| 8845 | return -EINVAL; |
| 8846 | if (seq->len + seq->offset > data_size) |
| 8847 | return -EINVAL; |
| 8848 | } |
| 8849 | |
| 8850 | size = sizeof(*cfg); |
| 8851 | size += data_size; |
| 8852 | size += wake_size + wake_mask_size; |
| 8853 | size += tokens_size; |
| 8854 | |
| 8855 | cfg = kzalloc(size, GFP_KERNEL); |
| 8856 | if (!cfg) |
| 8857 | return -ENOMEM; |
| 8858 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 8859 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 8860 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 8861 | ETH_ALEN); |
| 8862 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 8863 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 8864 | else |
| 8865 | port = 0; |
| 8866 | #ifdef CONFIG_INET |
| 8867 | /* allocate a socket and port for it and use it */ |
| 8868 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 8869 | IPPROTO_TCP, &cfg->sock, 1); |
| 8870 | if (err) { |
| 8871 | kfree(cfg); |
| 8872 | return err; |
| 8873 | } |
| 8874 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 8875 | sock_release(cfg->sock); |
| 8876 | kfree(cfg); |
| 8877 | return -EADDRINUSE; |
| 8878 | } |
| 8879 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 8880 | #else |
| 8881 | if (!port) { |
| 8882 | kfree(cfg); |
| 8883 | return -EINVAL; |
| 8884 | } |
| 8885 | cfg->src_port = port; |
| 8886 | #endif |
| 8887 | |
| 8888 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 8889 | cfg->payload_len = data_size; |
| 8890 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 8891 | memcpy((void *)cfg->payload, |
| 8892 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 8893 | data_size); |
| 8894 | if (seq) |
| 8895 | cfg->payload_seq = *seq; |
| 8896 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 8897 | cfg->wake_len = wake_size; |
| 8898 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 8899 | memcpy((void *)cfg->wake_data, |
| 8900 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 8901 | wake_size); |
| 8902 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 8903 | data_size + wake_size; |
| 8904 | memcpy((void *)cfg->wake_mask, |
| 8905 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 8906 | wake_mask_size); |
| 8907 | if (tok) { |
| 8908 | cfg->tokens_size = tokens_size; |
| 8909 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 8910 | } |
| 8911 | |
| 8912 | trig->tcp = cfg; |
| 8913 | |
| 8914 | return 0; |
| 8915 | } |
| 8916 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 8917 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
| 8918 | const struct wiphy_wowlan_support *wowlan, |
| 8919 | struct nlattr *attr, |
| 8920 | struct cfg80211_wowlan *trig) |
| 8921 | { |
| 8922 | struct nlattr **tb; |
| 8923 | int err; |
| 8924 | |
| 8925 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); |
| 8926 | if (!tb) |
| 8927 | return -ENOMEM; |
| 8928 | |
| 8929 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { |
| 8930 | err = -EOPNOTSUPP; |
| 8931 | goto out; |
| 8932 | } |
| 8933 | |
| 8934 | err = nla_parse(tb, NL80211_ATTR_MAX, |
| 8935 | nla_data(attr), nla_len(attr), |
| 8936 | nl80211_policy); |
| 8937 | if (err) |
| 8938 | goto out; |
| 8939 | |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 8940 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 8941 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
| 8942 | if (err) |
| 8943 | trig->nd_config = NULL; |
| 8944 | |
| 8945 | out: |
| 8946 | kfree(tb); |
| 8947 | return err; |
| 8948 | } |
| 8949 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8950 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8951 | { |
| 8952 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8953 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8954 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8955 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8956 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8957 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8958 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8959 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8960 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8961 | return -EOPNOTSUPP; |
| 8962 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8963 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 8964 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8965 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8966 | goto set_wakeup; |
| 8967 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8968 | |
| 8969 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 8970 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8971 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8972 | nl80211_wowlan_policy); |
| 8973 | if (err) |
| 8974 | return err; |
| 8975 | |
| 8976 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 8977 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 8978 | return -EINVAL; |
| 8979 | new_triggers.any = true; |
| 8980 | } |
| 8981 | |
| 8982 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 8983 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 8984 | return -EINVAL; |
| 8985 | new_triggers.disconnect = true; |
| 8986 | } |
| 8987 | |
| 8988 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 8989 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 8990 | return -EINVAL; |
| 8991 | new_triggers.magic_pkt = true; |
| 8992 | } |
| 8993 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 8994 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 8995 | return -EINVAL; |
| 8996 | |
| 8997 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 8998 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 8999 | return -EINVAL; |
| 9000 | new_triggers.gtk_rekey_failure = true; |
| 9001 | } |
| 9002 | |
| 9003 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 9004 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 9005 | return -EINVAL; |
| 9006 | new_triggers.eap_identity_req = true; |
| 9007 | } |
| 9008 | |
| 9009 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 9010 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 9011 | return -EINVAL; |
| 9012 | new_triggers.four_way_handshake = true; |
| 9013 | } |
| 9014 | |
| 9015 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 9016 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 9017 | return -EINVAL; |
| 9018 | new_triggers.rfkill_release = true; |
| 9019 | } |
| 9020 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9021 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 9022 | struct nlattr *pat; |
| 9023 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9024 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9025 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9026 | |
| 9027 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 9028 | rem) |
| 9029 | n_patterns++; |
| 9030 | if (n_patterns > wowlan->n_patterns) |
| 9031 | return -EINVAL; |
| 9032 | |
| 9033 | new_triggers.patterns = kcalloc(n_patterns, |
| 9034 | sizeof(new_triggers.patterns[0]), |
| 9035 | GFP_KERNEL); |
| 9036 | if (!new_triggers.patterns) |
| 9037 | return -ENOMEM; |
| 9038 | |
| 9039 | new_triggers.n_patterns = n_patterns; |
| 9040 | i = 0; |
| 9041 | |
| 9042 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 9043 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9044 | u8 *mask_pat; |
| 9045 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9046 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 9047 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9048 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9049 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 9050 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9051 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9052 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9053 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9054 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9055 | goto error; |
| 9056 | if (pat_len > wowlan->pattern_max_len || |
| 9057 | pat_len < wowlan->pattern_min_len) |
| 9058 | goto error; |
| 9059 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9060 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9061 | pkt_offset = 0; |
| 9062 | else |
| 9063 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9064 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 9065 | if (pkt_offset > wowlan->max_pkt_offset) |
| 9066 | goto error; |
| 9067 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 9068 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9069 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 9070 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9071 | err = -ENOMEM; |
| 9072 | goto error; |
| 9073 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9074 | new_triggers.patterns[i].mask = mask_pat; |
| 9075 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9076 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9077 | mask_pat += mask_len; |
| 9078 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9079 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9080 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 9081 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9082 | pat_len); |
| 9083 | i++; |
| 9084 | } |
| 9085 | } |
| 9086 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9087 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 9088 | err = nl80211_parse_wowlan_tcp( |
| 9089 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 9090 | &new_triggers); |
| 9091 | if (err) |
| 9092 | goto error; |
| 9093 | } |
| 9094 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 9095 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
| 9096 | err = nl80211_parse_wowlan_nd( |
| 9097 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], |
| 9098 | &new_triggers); |
| 9099 | if (err) |
| 9100 | goto error; |
| 9101 | } |
| 9102 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9103 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 9104 | if (!ntrig) { |
| 9105 | err = -ENOMEM; |
| 9106 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9107 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9108 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9109 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9110 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 9111 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 9112 | if (rdev->ops->set_wakeup && |
| 9113 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 9114 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 9115 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9116 | return 0; |
| 9117 | error: |
| 9118 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 9119 | kfree(new_triggers.patterns[i].mask); |
| 9120 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 9121 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 9122 | sock_release(new_triggers.tcp->sock); |
| 9123 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9124 | return err; |
| 9125 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 9126 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 9127 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9128 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 9129 | struct cfg80211_registered_device *rdev) |
| 9130 | { |
| 9131 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 9132 | int i, j, pat_len; |
| 9133 | struct cfg80211_coalesce_rules *rule; |
| 9134 | |
| 9135 | if (!rdev->coalesce->n_rules) |
| 9136 | return 0; |
| 9137 | |
| 9138 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 9139 | if (!nl_rules) |
| 9140 | return -ENOBUFS; |
| 9141 | |
| 9142 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 9143 | nl_rule = nla_nest_start(msg, i + 1); |
| 9144 | if (!nl_rule) |
| 9145 | return -ENOBUFS; |
| 9146 | |
| 9147 | rule = &rdev->coalesce->rules[i]; |
| 9148 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 9149 | rule->delay)) |
| 9150 | return -ENOBUFS; |
| 9151 | |
| 9152 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 9153 | rule->condition)) |
| 9154 | return -ENOBUFS; |
| 9155 | |
| 9156 | nl_pats = nla_nest_start(msg, |
| 9157 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 9158 | if (!nl_pats) |
| 9159 | return -ENOBUFS; |
| 9160 | |
| 9161 | for (j = 0; j < rule->n_patterns; j++) { |
| 9162 | nl_pat = nla_nest_start(msg, j + 1); |
| 9163 | if (!nl_pat) |
| 9164 | return -ENOBUFS; |
| 9165 | pat_len = rule->patterns[j].pattern_len; |
| 9166 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 9167 | DIV_ROUND_UP(pat_len, 8), |
| 9168 | rule->patterns[j].mask) || |
| 9169 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 9170 | rule->patterns[j].pattern) || |
| 9171 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 9172 | rule->patterns[j].pkt_offset)) |
| 9173 | return -ENOBUFS; |
| 9174 | nla_nest_end(msg, nl_pat); |
| 9175 | } |
| 9176 | nla_nest_end(msg, nl_pats); |
| 9177 | nla_nest_end(msg, nl_rule); |
| 9178 | } |
| 9179 | nla_nest_end(msg, nl_rules); |
| 9180 | |
| 9181 | return 0; |
| 9182 | } |
| 9183 | |
| 9184 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 9185 | { |
| 9186 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9187 | struct sk_buff *msg; |
| 9188 | void *hdr; |
| 9189 | |
| 9190 | if (!rdev->wiphy.coalesce) |
| 9191 | return -EOPNOTSUPP; |
| 9192 | |
| 9193 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9194 | if (!msg) |
| 9195 | return -ENOMEM; |
| 9196 | |
| 9197 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 9198 | NL80211_CMD_GET_COALESCE); |
| 9199 | if (!hdr) |
| 9200 | goto nla_put_failure; |
| 9201 | |
| 9202 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 9203 | goto nla_put_failure; |
| 9204 | |
| 9205 | genlmsg_end(msg, hdr); |
| 9206 | return genlmsg_reply(msg, info); |
| 9207 | |
| 9208 | nla_put_failure: |
| 9209 | nlmsg_free(msg); |
| 9210 | return -ENOBUFS; |
| 9211 | } |
| 9212 | |
| 9213 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 9214 | { |
| 9215 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 9216 | int i, j; |
| 9217 | struct cfg80211_coalesce_rules *rule; |
| 9218 | |
| 9219 | if (!coalesce) |
| 9220 | return; |
| 9221 | |
| 9222 | for (i = 0; i < coalesce->n_rules; i++) { |
| 9223 | rule = &coalesce->rules[i]; |
| 9224 | for (j = 0; j < rule->n_patterns; j++) |
| 9225 | kfree(rule->patterns[j].mask); |
| 9226 | kfree(rule->patterns); |
| 9227 | } |
| 9228 | kfree(coalesce->rules); |
| 9229 | kfree(coalesce); |
| 9230 | rdev->coalesce = NULL; |
| 9231 | } |
| 9232 | |
| 9233 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 9234 | struct nlattr *rule, |
| 9235 | struct cfg80211_coalesce_rules *new_rule) |
| 9236 | { |
| 9237 | int err, i; |
| 9238 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 9239 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 9240 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 9241 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 9242 | |
| 9243 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 9244 | nla_len(rule), nl80211_coalesce_policy); |
| 9245 | if (err) |
| 9246 | return err; |
| 9247 | |
| 9248 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 9249 | new_rule->delay = |
| 9250 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 9251 | if (new_rule->delay > coalesce->max_delay) |
| 9252 | return -EINVAL; |
| 9253 | |
| 9254 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 9255 | new_rule->condition = |
| 9256 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 9257 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 9258 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 9259 | return -EINVAL; |
| 9260 | |
| 9261 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 9262 | return -EINVAL; |
| 9263 | |
| 9264 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 9265 | rem) |
| 9266 | n_patterns++; |
| 9267 | if (n_patterns > coalesce->n_patterns) |
| 9268 | return -EINVAL; |
| 9269 | |
| 9270 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 9271 | GFP_KERNEL); |
| 9272 | if (!new_rule->patterns) |
| 9273 | return -ENOMEM; |
| 9274 | |
| 9275 | new_rule->n_patterns = n_patterns; |
| 9276 | i = 0; |
| 9277 | |
| 9278 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 9279 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9280 | u8 *mask_pat; |
| 9281 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9282 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 9283 | nla_len(pat), NULL); |
| 9284 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 9285 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 9286 | return -EINVAL; |
| 9287 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 9288 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 9289 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 9290 | return -EINVAL; |
| 9291 | if (pat_len > coalesce->pattern_max_len || |
| 9292 | pat_len < coalesce->pattern_min_len) |
| 9293 | return -EINVAL; |
| 9294 | |
| 9295 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 9296 | pkt_offset = 0; |
| 9297 | else |
| 9298 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 9299 | if (pkt_offset > coalesce->max_pkt_offset) |
| 9300 | return -EINVAL; |
| 9301 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 9302 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9303 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 9304 | if (!mask_pat) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9305 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9306 | |
| 9307 | new_rule->patterns[i].mask = mask_pat; |
| 9308 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 9309 | mask_len); |
| 9310 | |
| 9311 | mask_pat += mask_len; |
| 9312 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9313 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9314 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 9315 | pat_len); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9316 | i++; |
| 9317 | } |
| 9318 | |
| 9319 | return 0; |
| 9320 | } |
| 9321 | |
| 9322 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 9323 | { |
| 9324 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9325 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 9326 | struct cfg80211_coalesce new_coalesce = {}; |
| 9327 | struct cfg80211_coalesce *n_coalesce; |
| 9328 | int err, rem_rule, n_rules = 0, i, j; |
| 9329 | struct nlattr *rule; |
| 9330 | struct cfg80211_coalesce_rules *tmp_rule; |
| 9331 | |
| 9332 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 9333 | return -EOPNOTSUPP; |
| 9334 | |
| 9335 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 9336 | cfg80211_rdev_free_coalesce(rdev); |
| 9337 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); |
| 9338 | return 0; |
| 9339 | } |
| 9340 | |
| 9341 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 9342 | rem_rule) |
| 9343 | n_rules++; |
| 9344 | if (n_rules > coalesce->n_rules) |
| 9345 | return -EINVAL; |
| 9346 | |
| 9347 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 9348 | GFP_KERNEL); |
| 9349 | if (!new_coalesce.rules) |
| 9350 | return -ENOMEM; |
| 9351 | |
| 9352 | new_coalesce.n_rules = n_rules; |
| 9353 | i = 0; |
| 9354 | |
| 9355 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 9356 | rem_rule) { |
| 9357 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 9358 | &new_coalesce.rules[i]); |
| 9359 | if (err) |
| 9360 | goto error; |
| 9361 | |
| 9362 | i++; |
| 9363 | } |
| 9364 | |
| 9365 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); |
| 9366 | if (err) |
| 9367 | goto error; |
| 9368 | |
| 9369 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 9370 | if (!n_coalesce) { |
| 9371 | err = -ENOMEM; |
| 9372 | goto error; |
| 9373 | } |
| 9374 | cfg80211_rdev_free_coalesce(rdev); |
| 9375 | rdev->coalesce = n_coalesce; |
| 9376 | |
| 9377 | return 0; |
| 9378 | error: |
| 9379 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 9380 | tmp_rule = &new_coalesce.rules[i]; |
| 9381 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 9382 | kfree(tmp_rule->patterns[j].mask); |
| 9383 | kfree(tmp_rule->patterns); |
| 9384 | } |
| 9385 | kfree(new_coalesce.rules); |
| 9386 | |
| 9387 | return err; |
| 9388 | } |
| 9389 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9390 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 9391 | { |
| 9392 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9393 | struct net_device *dev = info->user_ptr[1]; |
| 9394 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9395 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 9396 | struct cfg80211_gtk_rekey_data rekey_data; |
| 9397 | int err; |
| 9398 | |
| 9399 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 9400 | return -EINVAL; |
| 9401 | |
| 9402 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 9403 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 9404 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 9405 | nl80211_rekey_policy); |
| 9406 | if (err) |
| 9407 | return err; |
| 9408 | |
| 9409 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 9410 | return -ERANGE; |
| 9411 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 9412 | return -ERANGE; |
| 9413 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 9414 | return -ERANGE; |
| 9415 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 9416 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 9417 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 9418 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9419 | |
| 9420 | wdev_lock(wdev); |
| 9421 | if (!wdev->current_bss) { |
| 9422 | err = -ENOTCONN; |
| 9423 | goto out; |
| 9424 | } |
| 9425 | |
| 9426 | if (!rdev->ops->set_rekey_data) { |
| 9427 | err = -EOPNOTSUPP; |
| 9428 | goto out; |
| 9429 | } |
| 9430 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9431 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9432 | out: |
| 9433 | wdev_unlock(wdev); |
| 9434 | return err; |
| 9435 | } |
| 9436 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9437 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 9438 | struct genl_info *info) |
| 9439 | { |
| 9440 | struct net_device *dev = info->user_ptr[1]; |
| 9441 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9442 | |
| 9443 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 9444 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 9445 | return -EINVAL; |
| 9446 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9447 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9448 | return -EBUSY; |
| 9449 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9450 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9451 | return 0; |
| 9452 | } |
| 9453 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9454 | static int nl80211_probe_client(struct sk_buff *skb, |
| 9455 | struct genl_info *info) |
| 9456 | { |
| 9457 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9458 | struct net_device *dev = info->user_ptr[1]; |
| 9459 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9460 | struct sk_buff *msg; |
| 9461 | void *hdr; |
| 9462 | const u8 *addr; |
| 9463 | u64 cookie; |
| 9464 | int err; |
| 9465 | |
| 9466 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 9467 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 9468 | return -EOPNOTSUPP; |
| 9469 | |
| 9470 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9471 | return -EINVAL; |
| 9472 | |
| 9473 | if (!rdev->ops->probe_client) |
| 9474 | return -EOPNOTSUPP; |
| 9475 | |
| 9476 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9477 | if (!msg) |
| 9478 | return -ENOMEM; |
| 9479 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9480 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9481 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9482 | if (!hdr) { |
| 9483 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9484 | goto free_msg; |
| 9485 | } |
| 9486 | |
| 9487 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9488 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9489 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9490 | if (err) |
| 9491 | goto free_msg; |
| 9492 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9493 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9494 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9495 | |
| 9496 | genlmsg_end(msg, hdr); |
| 9497 | |
| 9498 | return genlmsg_reply(msg, info); |
| 9499 | |
| 9500 | nla_put_failure: |
| 9501 | err = -ENOBUFS; |
| 9502 | free_msg: |
| 9503 | nlmsg_free(msg); |
| 9504 | return err; |
| 9505 | } |
| 9506 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9507 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 9508 | { |
| 9509 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9510 | struct cfg80211_beacon_registration *reg, *nreg; |
| 9511 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9512 | |
| 9513 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 9514 | return -EOPNOTSUPP; |
| 9515 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9516 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 9517 | if (!nreg) |
| 9518 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9519 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9520 | /* First, check if already registered. */ |
| 9521 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9522 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 9523 | if (reg->nlportid == info->snd_portid) { |
| 9524 | rv = -EALREADY; |
| 9525 | goto out_err; |
| 9526 | } |
| 9527 | } |
| 9528 | /* Add it to the list */ |
| 9529 | nreg->nlportid = info->snd_portid; |
| 9530 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 9531 | |
| 9532 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9533 | |
| 9534 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9535 | out_err: |
| 9536 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9537 | kfree(nreg); |
| 9538 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9539 | } |
| 9540 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9541 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 9542 | { |
| 9543 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9544 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9545 | int err; |
| 9546 | |
| 9547 | if (!rdev->ops->start_p2p_device) |
| 9548 | return -EOPNOTSUPP; |
| 9549 | |
| 9550 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 9551 | return -EOPNOTSUPP; |
| 9552 | |
| 9553 | if (wdev->p2p_started) |
| 9554 | return 0; |
| 9555 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 9556 | if (rfkill_blocked(rdev->rfkill)) |
| 9557 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9558 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 9559 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9560 | if (err) |
| 9561 | return err; |
| 9562 | |
| 9563 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9564 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9565 | |
| 9566 | return 0; |
| 9567 | } |
| 9568 | |
| 9569 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 9570 | { |
| 9571 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9572 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9573 | |
| 9574 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 9575 | return -EOPNOTSUPP; |
| 9576 | |
| 9577 | if (!rdev->ops->stop_p2p_device) |
| 9578 | return -EOPNOTSUPP; |
| 9579 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 9580 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9581 | |
| 9582 | return 0; |
| 9583 | } |
| 9584 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9585 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 9586 | struct genl_info *info) |
| 9587 | { |
| 9588 | void *hdr; |
| 9589 | struct sk_buff *msg; |
| 9590 | |
| 9591 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9592 | if (!msg) |
| 9593 | return -ENOMEM; |
| 9594 | |
| 9595 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 9596 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 9597 | if (!hdr) |
| 9598 | goto nla_put_failure; |
| 9599 | |
| 9600 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 9601 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 9602 | goto nla_put_failure; |
| 9603 | |
| 9604 | genlmsg_end(msg, hdr); |
| 9605 | return genlmsg_reply(msg, info); |
| 9606 | |
| 9607 | nla_put_failure: |
| 9608 | kfree_skb(msg); |
| 9609 | return -ENOBUFS; |
| 9610 | } |
| 9611 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9612 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 9613 | { |
| 9614 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9615 | struct cfg80211_update_ft_ies_params ft_params; |
| 9616 | struct net_device *dev = info->user_ptr[1]; |
| 9617 | |
| 9618 | if (!rdev->ops->update_ft_ies) |
| 9619 | return -EOPNOTSUPP; |
| 9620 | |
| 9621 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 9622 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 9623 | return -EINVAL; |
| 9624 | |
| 9625 | memset(&ft_params, 0, sizeof(ft_params)); |
| 9626 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 9627 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9628 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9629 | |
| 9630 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 9631 | } |
| 9632 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9633 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 9634 | struct genl_info *info) |
| 9635 | { |
| 9636 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9637 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9638 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 9639 | u16 duration; |
| 9640 | int ret; |
| 9641 | |
| 9642 | if (!rdev->ops->crit_proto_start) |
| 9643 | return -EOPNOTSUPP; |
| 9644 | |
| 9645 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 9646 | return -EINVAL; |
| 9647 | |
| 9648 | if (rdev->crit_proto_nlportid) |
| 9649 | return -EBUSY; |
| 9650 | |
| 9651 | /* determine protocol if provided */ |
| 9652 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 9653 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 9654 | |
| 9655 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 9656 | return -EINVAL; |
| 9657 | |
| 9658 | /* timeout must be provided */ |
| 9659 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 9660 | return -EINVAL; |
| 9661 | |
| 9662 | duration = |
| 9663 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 9664 | |
| 9665 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 9666 | return -ERANGE; |
| 9667 | |
| 9668 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 9669 | if (!ret) |
| 9670 | rdev->crit_proto_nlportid = info->snd_portid; |
| 9671 | |
| 9672 | return ret; |
| 9673 | } |
| 9674 | |
| 9675 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 9676 | struct genl_info *info) |
| 9677 | { |
| 9678 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9679 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9680 | |
| 9681 | if (!rdev->ops->crit_proto_stop) |
| 9682 | return -EOPNOTSUPP; |
| 9683 | |
| 9684 | if (rdev->crit_proto_nlportid) { |
| 9685 | rdev->crit_proto_nlportid = 0; |
| 9686 | rdev_crit_proto_stop(rdev, wdev); |
| 9687 | } |
| 9688 | return 0; |
| 9689 | } |
| 9690 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9691 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 9692 | { |
| 9693 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9694 | struct wireless_dev *wdev = |
| 9695 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 9696 | int i, err; |
| 9697 | u32 vid, subcmd; |
| 9698 | |
| 9699 | if (!rdev->wiphy.vendor_commands) |
| 9700 | return -EOPNOTSUPP; |
| 9701 | |
| 9702 | if (IS_ERR(wdev)) { |
| 9703 | err = PTR_ERR(wdev); |
| 9704 | if (err != -EINVAL) |
| 9705 | return err; |
| 9706 | wdev = NULL; |
| 9707 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 9708 | return -EINVAL; |
| 9709 | } |
| 9710 | |
| 9711 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 9712 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 9713 | return -EINVAL; |
| 9714 | |
| 9715 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 9716 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 9717 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 9718 | const struct wiphy_vendor_command *vcmd; |
| 9719 | void *data = NULL; |
| 9720 | int len = 0; |
| 9721 | |
| 9722 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 9723 | |
| 9724 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 9725 | continue; |
| 9726 | |
| 9727 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 9728 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 9729 | if (!wdev) |
| 9730 | return -EINVAL; |
| 9731 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 9732 | !wdev->netdev) |
| 9733 | return -EINVAL; |
| 9734 | |
| 9735 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 9736 | if (wdev->netdev && |
| 9737 | !netif_running(wdev->netdev)) |
| 9738 | return -ENETDOWN; |
| 9739 | if (!wdev->netdev && !wdev->p2p_started) |
| 9740 | return -ENETDOWN; |
| 9741 | } |
| 9742 | } else { |
| 9743 | wdev = NULL; |
| 9744 | } |
| 9745 | |
| 9746 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 9747 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9748 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9749 | } |
| 9750 | |
| 9751 | rdev->cur_cmd_info = info; |
| 9752 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 9753 | data, len); |
| 9754 | rdev->cur_cmd_info = NULL; |
| 9755 | return err; |
| 9756 | } |
| 9757 | |
| 9758 | return -EOPNOTSUPP; |
| 9759 | } |
| 9760 | |
| 9761 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 9762 | enum nl80211_commands cmd, |
| 9763 | enum nl80211_attrs attr, |
| 9764 | int approxlen) |
| 9765 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 9766 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9767 | |
| 9768 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 9769 | return NULL; |
| 9770 | |
| 9771 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, |
| 9772 | rdev->cur_cmd_info->snd_portid, |
| 9773 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 9774 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9775 | } |
| 9776 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 9777 | |
| 9778 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 9779 | { |
| 9780 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 9781 | void *hdr = ((void **)skb->cb)[1]; |
| 9782 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 9783 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 9784 | /* clear CB data for netlink core to own from now on */ |
| 9785 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 9786 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9787 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 9788 | kfree_skb(skb); |
| 9789 | return -EINVAL; |
| 9790 | } |
| 9791 | |
| 9792 | nla_nest_end(skb, data); |
| 9793 | genlmsg_end(skb, hdr); |
| 9794 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 9795 | } |
| 9796 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 9797 | |
| 9798 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 9799 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 9800 | struct genl_info *info) |
| 9801 | { |
| 9802 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9803 | struct cfg80211_qos_map *qos_map = NULL; |
| 9804 | struct net_device *dev = info->user_ptr[1]; |
| 9805 | u8 *pos, len, num_des, des_len, des; |
| 9806 | int ret; |
| 9807 | |
| 9808 | if (!rdev->ops->set_qos_map) |
| 9809 | return -EOPNOTSUPP; |
| 9810 | |
| 9811 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 9812 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9813 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9814 | |
| 9815 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 9816 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 9817 | return -EINVAL; |
| 9818 | |
| 9819 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 9820 | if (!qos_map) |
| 9821 | return -ENOMEM; |
| 9822 | |
| 9823 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 9824 | if (num_des) { |
| 9825 | des_len = num_des * |
| 9826 | sizeof(struct cfg80211_dscp_exception); |
| 9827 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 9828 | qos_map->num_des = num_des; |
| 9829 | for (des = 0; des < num_des; des++) { |
| 9830 | if (qos_map->dscp_exception[des].up > 7) { |
| 9831 | kfree(qos_map); |
| 9832 | return -EINVAL; |
| 9833 | } |
| 9834 | } |
| 9835 | pos += des_len; |
| 9836 | } |
| 9837 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 9838 | } |
| 9839 | |
| 9840 | wdev_lock(dev->ieee80211_ptr); |
| 9841 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 9842 | if (!ret) |
| 9843 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 9844 | wdev_unlock(dev->ieee80211_ptr); |
| 9845 | |
| 9846 | kfree(qos_map); |
| 9847 | return ret; |
| 9848 | } |
| 9849 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 9850 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 9851 | { |
| 9852 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9853 | struct net_device *dev = info->user_ptr[1]; |
| 9854 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9855 | const u8 *peer; |
| 9856 | u8 tsid, up; |
| 9857 | u16 admitted_time = 0; |
| 9858 | int err; |
| 9859 | |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 9860 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 9861 | return -EOPNOTSUPP; |
| 9862 | |
| 9863 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 9864 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 9865 | return -EINVAL; |
| 9866 | |
| 9867 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 9868 | if (tsid >= IEEE80211_NUM_TIDS) |
| 9869 | return -EINVAL; |
| 9870 | |
| 9871 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
| 9872 | if (up >= IEEE80211_NUM_UPS) |
| 9873 | return -EINVAL; |
| 9874 | |
| 9875 | /* WMM uses TIDs 0-7 even for TSPEC */ |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 9876 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 9877 | /* TODO: handle 802.11 TSPEC/admission control |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 9878 | * need more attributes for that (e.g. BA session requirement); |
| 9879 | * change the WMM adminssion test above to allow both then |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 9880 | */ |
| 9881 | return -EINVAL; |
| 9882 | } |
| 9883 | |
| 9884 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9885 | |
| 9886 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 9887 | admitted_time = |
| 9888 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 9889 | if (!admitted_time) |
| 9890 | return -EINVAL; |
| 9891 | } |
| 9892 | |
| 9893 | wdev_lock(wdev); |
| 9894 | switch (wdev->iftype) { |
| 9895 | case NL80211_IFTYPE_STATION: |
| 9896 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9897 | if (wdev->current_bss) |
| 9898 | break; |
| 9899 | err = -ENOTCONN; |
| 9900 | goto out; |
| 9901 | default: |
| 9902 | err = -EOPNOTSUPP; |
| 9903 | goto out; |
| 9904 | } |
| 9905 | |
| 9906 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 9907 | |
| 9908 | out: |
| 9909 | wdev_unlock(wdev); |
| 9910 | return err; |
| 9911 | } |
| 9912 | |
| 9913 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 9914 | { |
| 9915 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9916 | struct net_device *dev = info->user_ptr[1]; |
| 9917 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9918 | const u8 *peer; |
| 9919 | u8 tsid; |
| 9920 | int err; |
| 9921 | |
| 9922 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 9923 | return -EINVAL; |
| 9924 | |
| 9925 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 9926 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9927 | |
| 9928 | wdev_lock(wdev); |
| 9929 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 9930 | wdev_unlock(wdev); |
| 9931 | |
| 9932 | return err; |
| 9933 | } |
| 9934 | |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 9935 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
| 9936 | struct genl_info *info) |
| 9937 | { |
| 9938 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9939 | struct net_device *dev = info->user_ptr[1]; |
| 9940 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9941 | struct cfg80211_chan_def chandef = {}; |
| 9942 | const u8 *addr; |
| 9943 | u8 oper_class; |
| 9944 | int err; |
| 9945 | |
| 9946 | if (!rdev->ops->tdls_channel_switch || |
| 9947 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 9948 | return -EOPNOTSUPP; |
| 9949 | |
| 9950 | switch (dev->ieee80211_ptr->iftype) { |
| 9951 | case NL80211_IFTYPE_STATION: |
| 9952 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9953 | break; |
| 9954 | default: |
| 9955 | return -EOPNOTSUPP; |
| 9956 | } |
| 9957 | |
| 9958 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 9959 | !info->attrs[NL80211_ATTR_OPER_CLASS]) |
| 9960 | return -EINVAL; |
| 9961 | |
| 9962 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 9963 | if (err) |
| 9964 | return err; |
| 9965 | |
| 9966 | /* |
| 9967 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 |
| 9968 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the |
| 9969 | * specification is not defined for them. |
| 9970 | */ |
| 9971 | if (chandef.chan->band == IEEE80211_BAND_2GHZ && |
| 9972 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 9973 | chandef.width != NL80211_CHAN_WIDTH_20) |
| 9974 | return -EINVAL; |
| 9975 | |
| 9976 | /* we will be active on the TDLS link */ |
| 9977 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, wdev->iftype)) |
| 9978 | return -EINVAL; |
| 9979 | |
| 9980 | /* don't allow switching to DFS channels */ |
| 9981 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) |
| 9982 | return -EINVAL; |
| 9983 | |
| 9984 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9985 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); |
| 9986 | |
| 9987 | wdev_lock(wdev); |
| 9988 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); |
| 9989 | wdev_unlock(wdev); |
| 9990 | |
| 9991 | return err; |
| 9992 | } |
| 9993 | |
| 9994 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, |
| 9995 | struct genl_info *info) |
| 9996 | { |
| 9997 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9998 | struct net_device *dev = info->user_ptr[1]; |
| 9999 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10000 | const u8 *addr; |
| 10001 | |
| 10002 | if (!rdev->ops->tdls_channel_switch || |
| 10003 | !rdev->ops->tdls_cancel_channel_switch || |
| 10004 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 10005 | return -EOPNOTSUPP; |
| 10006 | |
| 10007 | switch (dev->ieee80211_ptr->iftype) { |
| 10008 | case NL80211_IFTYPE_STATION: |
| 10009 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10010 | break; |
| 10011 | default: |
| 10012 | return -EOPNOTSUPP; |
| 10013 | } |
| 10014 | |
| 10015 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 10016 | return -EINVAL; |
| 10017 | |
| 10018 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10019 | |
| 10020 | wdev_lock(wdev); |
| 10021 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); |
| 10022 | wdev_unlock(wdev); |
| 10023 | |
| 10024 | return 0; |
| 10025 | } |
| 10026 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10027 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 10028 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 10029 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10030 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 10031 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 10032 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10033 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10034 | /* 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] | 10035 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 10036 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10037 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10038 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 10039 | 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] | 10040 | struct genl_info *info) |
| 10041 | { |
| 10042 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10043 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10044 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10045 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 10046 | |
| 10047 | if (rtnl) |
| 10048 | rtnl_lock(); |
| 10049 | |
| 10050 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 10051 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10052 | if (IS_ERR(rdev)) { |
| 10053 | if (rtnl) |
| 10054 | rtnl_unlock(); |
| 10055 | return PTR_ERR(rdev); |
| 10056 | } |
| 10057 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10058 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 10059 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10060 | ASSERT_RTNL(); |
| 10061 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10062 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 10063 | info->attrs); |
| 10064 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10065 | if (rtnl) |
| 10066 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10067 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10068 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10069 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10070 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10071 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10072 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10073 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 10074 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10075 | if (rtnl) |
| 10076 | rtnl_unlock(); |
| 10077 | return -EINVAL; |
| 10078 | } |
| 10079 | |
| 10080 | info->user_ptr[1] = dev; |
| 10081 | } else { |
| 10082 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10083 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 10084 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10085 | if (dev) { |
| 10086 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 10087 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10088 | if (rtnl) |
| 10089 | rtnl_unlock(); |
| 10090 | return -ENETDOWN; |
| 10091 | } |
| 10092 | |
| 10093 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10094 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 10095 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10096 | if (rtnl) |
| 10097 | rtnl_unlock(); |
| 10098 | return -ENETDOWN; |
| 10099 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10100 | } |
| 10101 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10102 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10103 | } |
| 10104 | |
| 10105 | return 0; |
| 10106 | } |
| 10107 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 10108 | 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] | 10109 | struct genl_info *info) |
| 10110 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 10111 | if (info->user_ptr[1]) { |
| 10112 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 10113 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 10114 | |
| 10115 | if (wdev->netdev) |
| 10116 | dev_put(wdev->netdev); |
| 10117 | } else { |
| 10118 | dev_put(info->user_ptr[1]); |
| 10119 | } |
| 10120 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10121 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10122 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 10123 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10124 | |
| 10125 | /* If needed, clear the netlink message payload from the SKB |
| 10126 | * as it might contain key data that shouldn't stick around on |
| 10127 | * the heap after the SKB is freed. The netlink message header |
| 10128 | * is still needed for further processing, so leave it intact. |
| 10129 | */ |
| 10130 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 10131 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 10132 | |
| 10133 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 10134 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10135 | } |
| 10136 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 10137 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10138 | { |
| 10139 | .cmd = NL80211_CMD_GET_WIPHY, |
| 10140 | .doit = nl80211_get_wiphy, |
| 10141 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 10142 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10143 | .policy = nl80211_policy, |
| 10144 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10145 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10146 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10147 | }, |
| 10148 | { |
| 10149 | .cmd = NL80211_CMD_SET_WIPHY, |
| 10150 | .doit = nl80211_set_wiphy, |
| 10151 | .policy = nl80211_policy, |
| 10152 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10153 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10154 | }, |
| 10155 | { |
| 10156 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 10157 | .doit = nl80211_get_interface, |
| 10158 | .dumpit = nl80211_dump_interface, |
| 10159 | .policy = nl80211_policy, |
| 10160 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10161 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 10162 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10163 | }, |
| 10164 | { |
| 10165 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 10166 | .doit = nl80211_set_interface, |
| 10167 | .policy = nl80211_policy, |
| 10168 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10169 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10170 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10171 | }, |
| 10172 | { |
| 10173 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 10174 | .doit = nl80211_new_interface, |
| 10175 | .policy = nl80211_policy, |
| 10176 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10177 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10178 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10179 | }, |
| 10180 | { |
| 10181 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 10182 | .doit = nl80211_del_interface, |
| 10183 | .policy = nl80211_policy, |
| 10184 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 10185 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10186 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10187 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10188 | { |
| 10189 | .cmd = NL80211_CMD_GET_KEY, |
| 10190 | .doit = nl80211_get_key, |
| 10191 | .policy = nl80211_policy, |
| 10192 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10193 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10194 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10195 | }, |
| 10196 | { |
| 10197 | .cmd = NL80211_CMD_SET_KEY, |
| 10198 | .doit = nl80211_set_key, |
| 10199 | .policy = nl80211_policy, |
| 10200 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10201 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10202 | NL80211_FLAG_NEED_RTNL | |
| 10203 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10204 | }, |
| 10205 | { |
| 10206 | .cmd = NL80211_CMD_NEW_KEY, |
| 10207 | .doit = nl80211_new_key, |
| 10208 | .policy = nl80211_policy, |
| 10209 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10210 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10211 | NL80211_FLAG_NEED_RTNL | |
| 10212 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10213 | }, |
| 10214 | { |
| 10215 | .cmd = NL80211_CMD_DEL_KEY, |
| 10216 | .doit = nl80211_del_key, |
| 10217 | .policy = nl80211_policy, |
| 10218 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10219 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10220 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 10221 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10222 | { |
| 10223 | .cmd = NL80211_CMD_SET_BEACON, |
| 10224 | .policy = nl80211_policy, |
| 10225 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10226 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10227 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10228 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10229 | }, |
| 10230 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10231 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10232 | .policy = nl80211_policy, |
| 10233 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10234 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10235 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10236 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10237 | }, |
| 10238 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10239 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10240 | .policy = nl80211_policy, |
| 10241 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 10242 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10243 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10244 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 10245 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10246 | { |
| 10247 | .cmd = NL80211_CMD_GET_STATION, |
| 10248 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10249 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10250 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10251 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10252 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10253 | }, |
| 10254 | { |
| 10255 | .cmd = NL80211_CMD_SET_STATION, |
| 10256 | .doit = nl80211_set_station, |
| 10257 | .policy = nl80211_policy, |
| 10258 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10259 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10260 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10261 | }, |
| 10262 | { |
| 10263 | .cmd = NL80211_CMD_NEW_STATION, |
| 10264 | .doit = nl80211_new_station, |
| 10265 | .policy = nl80211_policy, |
| 10266 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10267 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10268 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10269 | }, |
| 10270 | { |
| 10271 | .cmd = NL80211_CMD_DEL_STATION, |
| 10272 | .doit = nl80211_del_station, |
| 10273 | .policy = nl80211_policy, |
| 10274 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10275 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10276 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 10277 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10278 | { |
| 10279 | .cmd = NL80211_CMD_GET_MPATH, |
| 10280 | .doit = nl80211_get_mpath, |
| 10281 | .dumpit = nl80211_dump_mpath, |
| 10282 | .policy = nl80211_policy, |
| 10283 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10284 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10285 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10286 | }, |
| 10287 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 10288 | .cmd = NL80211_CMD_GET_MPP, |
| 10289 | .doit = nl80211_get_mpp, |
| 10290 | .dumpit = nl80211_dump_mpp, |
| 10291 | .policy = nl80211_policy, |
| 10292 | .flags = GENL_ADMIN_PERM, |
| 10293 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10294 | NL80211_FLAG_NEED_RTNL, |
| 10295 | }, |
| 10296 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10297 | .cmd = NL80211_CMD_SET_MPATH, |
| 10298 | .doit = nl80211_set_mpath, |
| 10299 | .policy = nl80211_policy, |
| 10300 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10301 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10302 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10303 | }, |
| 10304 | { |
| 10305 | .cmd = NL80211_CMD_NEW_MPATH, |
| 10306 | .doit = nl80211_new_mpath, |
| 10307 | .policy = nl80211_policy, |
| 10308 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10309 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10310 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10311 | }, |
| 10312 | { |
| 10313 | .cmd = NL80211_CMD_DEL_MPATH, |
| 10314 | .doit = nl80211_del_mpath, |
| 10315 | .policy = nl80211_policy, |
| 10316 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10317 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10318 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 10319 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 10320 | { |
| 10321 | .cmd = NL80211_CMD_SET_BSS, |
| 10322 | .doit = nl80211_set_bss, |
| 10323 | .policy = nl80211_policy, |
| 10324 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10325 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10326 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 10327 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10328 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 10329 | .cmd = NL80211_CMD_GET_REG, |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 10330 | .doit = nl80211_get_reg_do, |
| 10331 | .dumpit = nl80211_get_reg_dump, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 10332 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10333 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 10334 | /* can be retrieved by unprivileged users */ |
| 10335 | }, |
| 10336 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10337 | .cmd = NL80211_CMD_SET_REG, |
| 10338 | .doit = nl80211_set_reg, |
| 10339 | .policy = nl80211_policy, |
| 10340 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10341 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 10342 | }, |
| 10343 | { |
| 10344 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 10345 | .doit = nl80211_req_set_reg, |
| 10346 | .policy = nl80211_policy, |
| 10347 | .flags = GENL_ADMIN_PERM, |
| 10348 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10349 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 10350 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 10351 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10352 | .policy = nl80211_policy, |
| 10353 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10354 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10355 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10356 | }, |
| 10357 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 10358 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 10359 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10360 | .policy = nl80211_policy, |
| 10361 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10362 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10363 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 10364 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 10365 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10366 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 10367 | .doit = nl80211_trigger_scan, |
| 10368 | .policy = nl80211_policy, |
| 10369 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10370 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10371 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10372 | }, |
| 10373 | { |
| 10374 | .cmd = NL80211_CMD_GET_SCAN, |
| 10375 | .policy = nl80211_policy, |
| 10376 | .dumpit = nl80211_dump_scan, |
| 10377 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10378 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10379 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 10380 | .doit = nl80211_start_sched_scan, |
| 10381 | .policy = nl80211_policy, |
| 10382 | .flags = GENL_ADMIN_PERM, |
| 10383 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10384 | NL80211_FLAG_NEED_RTNL, |
| 10385 | }, |
| 10386 | { |
| 10387 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 10388 | .doit = nl80211_stop_sched_scan, |
| 10389 | .policy = nl80211_policy, |
| 10390 | .flags = GENL_ADMIN_PERM, |
| 10391 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10392 | NL80211_FLAG_NEED_RTNL, |
| 10393 | }, |
| 10394 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10395 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 10396 | .doit = nl80211_authenticate, |
| 10397 | .policy = nl80211_policy, |
| 10398 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10399 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10400 | NL80211_FLAG_NEED_RTNL | |
| 10401 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10402 | }, |
| 10403 | { |
| 10404 | .cmd = NL80211_CMD_ASSOCIATE, |
| 10405 | .doit = nl80211_associate, |
| 10406 | .policy = nl80211_policy, |
| 10407 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10408 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10409 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10410 | }, |
| 10411 | { |
| 10412 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 10413 | .doit = nl80211_deauthenticate, |
| 10414 | .policy = nl80211_policy, |
| 10415 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10416 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10417 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10418 | }, |
| 10419 | { |
| 10420 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 10421 | .doit = nl80211_disassociate, |
| 10422 | .policy = nl80211_policy, |
| 10423 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10424 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10425 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10426 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10427 | { |
| 10428 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 10429 | .doit = nl80211_join_ibss, |
| 10430 | .policy = nl80211_policy, |
| 10431 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10432 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10433 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10434 | }, |
| 10435 | { |
| 10436 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 10437 | .doit = nl80211_leave_ibss, |
| 10438 | .policy = nl80211_policy, |
| 10439 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10440 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10441 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10442 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10443 | #ifdef CONFIG_NL80211_TESTMODE |
| 10444 | { |
| 10445 | .cmd = NL80211_CMD_TESTMODE, |
| 10446 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10447 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10448 | .policy = nl80211_policy, |
| 10449 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10450 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10451 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10452 | }, |
| 10453 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10454 | { |
| 10455 | .cmd = NL80211_CMD_CONNECT, |
| 10456 | .doit = nl80211_connect, |
| 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, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10461 | }, |
| 10462 | { |
| 10463 | .cmd = NL80211_CMD_DISCONNECT, |
| 10464 | .doit = nl80211_disconnect, |
| 10465 | .policy = nl80211_policy, |
| 10466 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10467 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10468 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10469 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10470 | { |
| 10471 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 10472 | .doit = nl80211_wiphy_netns, |
| 10473 | .policy = nl80211_policy, |
| 10474 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10475 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10476 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10477 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 10478 | { |
| 10479 | .cmd = NL80211_CMD_GET_SURVEY, |
| 10480 | .policy = nl80211_policy, |
| 10481 | .dumpit = nl80211_dump_survey, |
| 10482 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10483 | { |
| 10484 | .cmd = NL80211_CMD_SET_PMKSA, |
| 10485 | .doit = nl80211_setdel_pmksa, |
| 10486 | .policy = nl80211_policy, |
| 10487 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10488 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10489 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10490 | }, |
| 10491 | { |
| 10492 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 10493 | .doit = nl80211_setdel_pmksa, |
| 10494 | .policy = nl80211_policy, |
| 10495 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10496 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10497 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10498 | }, |
| 10499 | { |
| 10500 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 10501 | .doit = nl80211_flush_pmksa, |
| 10502 | .policy = nl80211_policy, |
| 10503 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10504 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10505 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10506 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10507 | { |
| 10508 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 10509 | .doit = nl80211_remain_on_channel, |
| 10510 | .policy = nl80211_policy, |
| 10511 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10512 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10513 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10514 | }, |
| 10515 | { |
| 10516 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 10517 | .doit = nl80211_cancel_remain_on_channel, |
| 10518 | .policy = nl80211_policy, |
| 10519 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10520 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10521 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10522 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10523 | { |
| 10524 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 10525 | .doit = nl80211_set_tx_bitrate_mask, |
| 10526 | .policy = nl80211_policy, |
| 10527 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10528 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10529 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10530 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10531 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10532 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 10533 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10534 | .policy = nl80211_policy, |
| 10535 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10536 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10537 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10538 | }, |
| 10539 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10540 | .cmd = NL80211_CMD_FRAME, |
| 10541 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10542 | .policy = nl80211_policy, |
| 10543 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10544 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10545 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10546 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10547 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10548 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 10549 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 10550 | .policy = nl80211_policy, |
| 10551 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10552 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10553 | NL80211_FLAG_NEED_RTNL, |
| 10554 | }, |
| 10555 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10556 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 10557 | .doit = nl80211_set_power_save, |
| 10558 | .policy = nl80211_policy, |
| 10559 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10560 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10561 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10562 | }, |
| 10563 | { |
| 10564 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 10565 | .doit = nl80211_get_power_save, |
| 10566 | .policy = nl80211_policy, |
| 10567 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10568 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10569 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10570 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10571 | { |
| 10572 | .cmd = NL80211_CMD_SET_CQM, |
| 10573 | .doit = nl80211_set_cqm, |
| 10574 | .policy = nl80211_policy, |
| 10575 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10576 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10577 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10578 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 10579 | { |
| 10580 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 10581 | .doit = nl80211_set_channel, |
| 10582 | .policy = nl80211_policy, |
| 10583 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10584 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10585 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 10586 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 10587 | { |
| 10588 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 10589 | .doit = nl80211_set_wds_peer, |
| 10590 | .policy = nl80211_policy, |
| 10591 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 10592 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10593 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 10594 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10595 | { |
| 10596 | .cmd = NL80211_CMD_JOIN_MESH, |
| 10597 | .doit = nl80211_join_mesh, |
| 10598 | .policy = nl80211_policy, |
| 10599 | .flags = GENL_ADMIN_PERM, |
| 10600 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10601 | NL80211_FLAG_NEED_RTNL, |
| 10602 | }, |
| 10603 | { |
| 10604 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 10605 | .doit = nl80211_leave_mesh, |
| 10606 | .policy = nl80211_policy, |
| 10607 | .flags = GENL_ADMIN_PERM, |
| 10608 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10609 | NL80211_FLAG_NEED_RTNL, |
| 10610 | }, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 10611 | { |
| 10612 | .cmd = NL80211_CMD_JOIN_OCB, |
| 10613 | .doit = nl80211_join_ocb, |
| 10614 | .policy = nl80211_policy, |
| 10615 | .flags = GENL_ADMIN_PERM, |
| 10616 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10617 | NL80211_FLAG_NEED_RTNL, |
| 10618 | }, |
| 10619 | { |
| 10620 | .cmd = NL80211_CMD_LEAVE_OCB, |
| 10621 | .doit = nl80211_leave_ocb, |
| 10622 | .policy = nl80211_policy, |
| 10623 | .flags = GENL_ADMIN_PERM, |
| 10624 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10625 | NL80211_FLAG_NEED_RTNL, |
| 10626 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10627 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10628 | { |
| 10629 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 10630 | .doit = nl80211_get_wowlan, |
| 10631 | .policy = nl80211_policy, |
| 10632 | /* can be retrieved by unprivileged users */ |
| 10633 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10634 | NL80211_FLAG_NEED_RTNL, |
| 10635 | }, |
| 10636 | { |
| 10637 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 10638 | .doit = nl80211_set_wowlan, |
| 10639 | .policy = nl80211_policy, |
| 10640 | .flags = GENL_ADMIN_PERM, |
| 10641 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10642 | NL80211_FLAG_NEED_RTNL, |
| 10643 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10644 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10645 | { |
| 10646 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 10647 | .doit = nl80211_set_rekey_data, |
| 10648 | .policy = nl80211_policy, |
| 10649 | .flags = GENL_ADMIN_PERM, |
| 10650 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10651 | NL80211_FLAG_NEED_RTNL | |
| 10652 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10653 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10654 | { |
| 10655 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 10656 | .doit = nl80211_tdls_mgmt, |
| 10657 | .policy = nl80211_policy, |
| 10658 | .flags = GENL_ADMIN_PERM, |
| 10659 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10660 | NL80211_FLAG_NEED_RTNL, |
| 10661 | }, |
| 10662 | { |
| 10663 | .cmd = NL80211_CMD_TDLS_OPER, |
| 10664 | .doit = nl80211_tdls_oper, |
| 10665 | .policy = nl80211_policy, |
| 10666 | .flags = GENL_ADMIN_PERM, |
| 10667 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10668 | NL80211_FLAG_NEED_RTNL, |
| 10669 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10670 | { |
| 10671 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 10672 | .doit = nl80211_register_unexpected_frame, |
| 10673 | .policy = nl80211_policy, |
| 10674 | .flags = GENL_ADMIN_PERM, |
| 10675 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10676 | NL80211_FLAG_NEED_RTNL, |
| 10677 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10678 | { |
| 10679 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 10680 | .doit = nl80211_probe_client, |
| 10681 | .policy = nl80211_policy, |
| 10682 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10683 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10684 | NL80211_FLAG_NEED_RTNL, |
| 10685 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10686 | { |
| 10687 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 10688 | .doit = nl80211_register_beacons, |
| 10689 | .policy = nl80211_policy, |
| 10690 | .flags = GENL_ADMIN_PERM, |
| 10691 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10692 | NL80211_FLAG_NEED_RTNL, |
| 10693 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 10694 | { |
| 10695 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 10696 | .doit = nl80211_set_noack_map, |
| 10697 | .policy = nl80211_policy, |
| 10698 | .flags = GENL_ADMIN_PERM, |
| 10699 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10700 | NL80211_FLAG_NEED_RTNL, |
| 10701 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10702 | { |
| 10703 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 10704 | .doit = nl80211_start_p2p_device, |
| 10705 | .policy = nl80211_policy, |
| 10706 | .flags = GENL_ADMIN_PERM, |
| 10707 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 10708 | NL80211_FLAG_NEED_RTNL, |
| 10709 | }, |
| 10710 | { |
| 10711 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 10712 | .doit = nl80211_stop_p2p_device, |
| 10713 | .policy = nl80211_policy, |
| 10714 | .flags = GENL_ADMIN_PERM, |
| 10715 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10716 | NL80211_FLAG_NEED_RTNL, |
| 10717 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10718 | { |
| 10719 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 10720 | .doit = nl80211_set_mcast_rate, |
| 10721 | .policy = nl80211_policy, |
| 10722 | .flags = GENL_ADMIN_PERM, |
| 10723 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10724 | NL80211_FLAG_NEED_RTNL, |
| 10725 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 10726 | { |
| 10727 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 10728 | .doit = nl80211_set_mac_acl, |
| 10729 | .policy = nl80211_policy, |
| 10730 | .flags = GENL_ADMIN_PERM, |
| 10731 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10732 | NL80211_FLAG_NEED_RTNL, |
| 10733 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10734 | { |
| 10735 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 10736 | .doit = nl80211_start_radar_detection, |
| 10737 | .policy = nl80211_policy, |
| 10738 | .flags = GENL_ADMIN_PERM, |
| 10739 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10740 | NL80211_FLAG_NEED_RTNL, |
| 10741 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 10742 | { |
| 10743 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 10744 | .doit = nl80211_get_protocol_features, |
| 10745 | .policy = nl80211_policy, |
| 10746 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10747 | { |
| 10748 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 10749 | .doit = nl80211_update_ft_ies, |
| 10750 | .policy = nl80211_policy, |
| 10751 | .flags = GENL_ADMIN_PERM, |
| 10752 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10753 | NL80211_FLAG_NEED_RTNL, |
| 10754 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 10755 | { |
| 10756 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 10757 | .doit = nl80211_crit_protocol_start, |
| 10758 | .policy = nl80211_policy, |
| 10759 | .flags = GENL_ADMIN_PERM, |
| 10760 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10761 | NL80211_FLAG_NEED_RTNL, |
| 10762 | }, |
| 10763 | { |
| 10764 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 10765 | .doit = nl80211_crit_protocol_stop, |
| 10766 | .policy = nl80211_policy, |
| 10767 | .flags = GENL_ADMIN_PERM, |
| 10768 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10769 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10770 | }, |
| 10771 | { |
| 10772 | .cmd = NL80211_CMD_GET_COALESCE, |
| 10773 | .doit = nl80211_get_coalesce, |
| 10774 | .policy = nl80211_policy, |
| 10775 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10776 | NL80211_FLAG_NEED_RTNL, |
| 10777 | }, |
| 10778 | { |
| 10779 | .cmd = NL80211_CMD_SET_COALESCE, |
| 10780 | .doit = nl80211_set_coalesce, |
| 10781 | .policy = nl80211_policy, |
| 10782 | .flags = GENL_ADMIN_PERM, |
| 10783 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10784 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 10785 | }, |
| 10786 | { |
| 10787 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 10788 | .doit = nl80211_channel_switch, |
| 10789 | .policy = nl80211_policy, |
| 10790 | .flags = GENL_ADMIN_PERM, |
| 10791 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10792 | NL80211_FLAG_NEED_RTNL, |
| 10793 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10794 | { |
| 10795 | .cmd = NL80211_CMD_VENDOR, |
| 10796 | .doit = nl80211_vendor_cmd, |
| 10797 | .policy = nl80211_policy, |
| 10798 | .flags = GENL_ADMIN_PERM, |
| 10799 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10800 | NL80211_FLAG_NEED_RTNL, |
| 10801 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 10802 | { |
| 10803 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 10804 | .doit = nl80211_set_qos_map, |
| 10805 | .policy = nl80211_policy, |
| 10806 | .flags = GENL_ADMIN_PERM, |
| 10807 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10808 | NL80211_FLAG_NEED_RTNL, |
| 10809 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10810 | { |
| 10811 | .cmd = NL80211_CMD_ADD_TX_TS, |
| 10812 | .doit = nl80211_add_tx_ts, |
| 10813 | .policy = nl80211_policy, |
| 10814 | .flags = GENL_ADMIN_PERM, |
| 10815 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10816 | NL80211_FLAG_NEED_RTNL, |
| 10817 | }, |
| 10818 | { |
| 10819 | .cmd = NL80211_CMD_DEL_TX_TS, |
| 10820 | .doit = nl80211_del_tx_ts, |
| 10821 | .policy = nl80211_policy, |
| 10822 | .flags = GENL_ADMIN_PERM, |
| 10823 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10824 | NL80211_FLAG_NEED_RTNL, |
| 10825 | }, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 10826 | { |
| 10827 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, |
| 10828 | .doit = nl80211_tdls_channel_switch, |
| 10829 | .policy = nl80211_policy, |
| 10830 | .flags = GENL_ADMIN_PERM, |
| 10831 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10832 | NL80211_FLAG_NEED_RTNL, |
| 10833 | }, |
| 10834 | { |
| 10835 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, |
| 10836 | .doit = nl80211_tdls_cancel_channel_switch, |
| 10837 | .policy = nl80211_policy, |
| 10838 | .flags = GENL_ADMIN_PERM, |
| 10839 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10840 | NL80211_FLAG_NEED_RTNL, |
| 10841 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10842 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10843 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10844 | /* notification functions */ |
| 10845 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10846 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 10847 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10848 | { |
| 10849 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 10850 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10851 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10852 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 10853 | cmd != NL80211_CMD_DEL_WIPHY); |
| 10854 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10855 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10856 | if (!msg) |
| 10857 | return; |
| 10858 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10859 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10860 | nlmsg_free(msg); |
| 10861 | return; |
| 10862 | } |
| 10863 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10864 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10865 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10866 | } |
| 10867 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10868 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 10869 | struct cfg80211_registered_device *rdev) |
| 10870 | { |
| 10871 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 10872 | struct nlattr *nest; |
| 10873 | int i; |
| 10874 | |
| 10875 | if (WARN_ON(!req)) |
| 10876 | return 0; |
| 10877 | |
| 10878 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 10879 | if (!nest) |
| 10880 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10881 | for (i = 0; i < req->n_ssids; i++) { |
| 10882 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 10883 | goto nla_put_failure; |
| 10884 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10885 | nla_nest_end(msg, nest); |
| 10886 | |
| 10887 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 10888 | if (!nest) |
| 10889 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10890 | for (i = 0; i < req->n_channels; i++) { |
| 10891 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 10892 | goto nla_put_failure; |
| 10893 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10894 | nla_nest_end(msg, nest); |
| 10895 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10896 | if (req->ie && |
| 10897 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 10898 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10899 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 10900 | if (req->flags && |
| 10901 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 10902 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 10903 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10904 | return 0; |
| 10905 | nla_put_failure: |
| 10906 | return -ENOBUFS; |
| 10907 | } |
| 10908 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10909 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 10910 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10911 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10912 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10913 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10914 | { |
| 10915 | void *hdr; |
| 10916 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10917 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10918 | if (!hdr) |
| 10919 | return -1; |
| 10920 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10921 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10922 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10923 | wdev->netdev->ifindex)) || |
| 10924 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10925 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10926 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10927 | /* ignore errors and send incomplete event anyway */ |
| 10928 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10929 | |
| 10930 | return genlmsg_end(msg, hdr); |
| 10931 | |
| 10932 | nla_put_failure: |
| 10933 | genlmsg_cancel(msg, hdr); |
| 10934 | return -EMSGSIZE; |
| 10935 | } |
| 10936 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10937 | static int |
| 10938 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 10939 | struct cfg80211_registered_device *rdev, |
| 10940 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10941 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10942 | { |
| 10943 | void *hdr; |
| 10944 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10945 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10946 | if (!hdr) |
| 10947 | return -1; |
| 10948 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10949 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10950 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10951 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10952 | |
| 10953 | return genlmsg_end(msg, hdr); |
| 10954 | |
| 10955 | nla_put_failure: |
| 10956 | genlmsg_cancel(msg, hdr); |
| 10957 | return -EMSGSIZE; |
| 10958 | } |
| 10959 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10960 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10961 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10962 | { |
| 10963 | struct sk_buff *msg; |
| 10964 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10965 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10966 | if (!msg) |
| 10967 | return; |
| 10968 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10969 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10970 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 10971 | nlmsg_free(msg); |
| 10972 | return; |
| 10973 | } |
| 10974 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10975 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10976 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10977 | } |
| 10978 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10979 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 10980 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10981 | { |
| 10982 | struct sk_buff *msg; |
| 10983 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10984 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10985 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10986 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 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 | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10989 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 10990 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10991 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10992 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10993 | } |
| 10994 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10995 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10996 | } |
| 10997 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10998 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
| 10999 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11000 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11001 | if (!msg) |
| 11002 | return; |
| 11003 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11004 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11005 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 11006 | } |
| 11007 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11008 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 11009 | struct net_device *netdev) |
| 11010 | { |
| 11011 | struct sk_buff *msg; |
| 11012 | |
| 11013 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11014 | if (!msg) |
| 11015 | return; |
| 11016 | |
| 11017 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 11018 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 11019 | nlmsg_free(msg); |
| 11020 | return; |
| 11021 | } |
| 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); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11025 | } |
| 11026 | |
| 11027 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 11028 | struct net_device *netdev, u32 cmd) |
| 11029 | { |
| 11030 | struct sk_buff *msg; |
| 11031 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11032 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11033 | if (!msg) |
| 11034 | return; |
| 11035 | |
| 11036 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 11037 | nlmsg_free(msg); |
| 11038 | return; |
| 11039 | } |
| 11040 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11041 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11042 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 11043 | } |
| 11044 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame^] | 11045 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
| 11046 | struct regulatory_request *request) |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11047 | { |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11048 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11049 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 11050 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11051 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11052 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 11053 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 11054 | NL80211_REGDOM_TYPE_WORLD)) |
| 11055 | goto nla_put_failure; |
| 11056 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 11057 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 11058 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 11059 | goto nla_put_failure; |
| 11060 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 11061 | request->intersect) { |
| 11062 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 11063 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 11064 | goto nla_put_failure; |
| 11065 | } else { |
| 11066 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 11067 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 11068 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 11069 | request->alpha2)) |
| 11070 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11071 | } |
| 11072 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 11073 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
| 11074 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); |
| 11075 | |
| 11076 | if (wiphy && |
| 11077 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 11078 | goto nla_put_failure; |
| 11079 | } |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11080 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame^] | 11081 | return true; |
| 11082 | |
| 11083 | nla_put_failure: |
| 11084 | return false; |
| 11085 | } |
| 11086 | |
| 11087 | /* |
| 11088 | * This can happen on global regulatory changes or device specific settings |
| 11089 | * based on custom regulatory domains. |
| 11090 | */ |
| 11091 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, |
| 11092 | struct regulatory_request *request) |
| 11093 | { |
| 11094 | struct sk_buff *msg; |
| 11095 | void *hdr; |
| 11096 | |
| 11097 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11098 | if (!msg) |
| 11099 | return; |
| 11100 | |
| 11101 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); |
| 11102 | if (!hdr) { |
| 11103 | nlmsg_free(msg); |
| 11104 | return; |
| 11105 | } |
| 11106 | |
| 11107 | if (nl80211_reg_change_event_fill(msg, request) == false) |
| 11108 | goto nla_put_failure; |
| 11109 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11110 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11111 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 11112 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11113 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11114 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 11115 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 11116 | |
| 11117 | return; |
| 11118 | |
| 11119 | nla_put_failure: |
| 11120 | genlmsg_cancel(msg, hdr); |
| 11121 | nlmsg_free(msg); |
| 11122 | } |
| 11123 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11124 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 11125 | struct net_device *netdev, |
| 11126 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11127 | enum nl80211_commands cmd, gfp_t gfp, |
| 11128 | int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11129 | { |
| 11130 | struct sk_buff *msg; |
| 11131 | void *hdr; |
| 11132 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11133 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11134 | if (!msg) |
| 11135 | return; |
| 11136 | |
| 11137 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 11138 | if (!hdr) { |
| 11139 | nlmsg_free(msg); |
| 11140 | return; |
| 11141 | } |
| 11142 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11143 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11144 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11145 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 11146 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11147 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11148 | if (uapsd_queues >= 0) { |
| 11149 | struct nlattr *nla_wmm = |
| 11150 | nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 11151 | if (!nla_wmm) |
| 11152 | goto nla_put_failure; |
| 11153 | |
| 11154 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 11155 | uapsd_queues)) |
| 11156 | goto nla_put_failure; |
| 11157 | |
| 11158 | nla_nest_end(msg, nla_wmm); |
| 11159 | } |
| 11160 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11161 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11162 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11163 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11164 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11165 | return; |
| 11166 | |
| 11167 | nla_put_failure: |
| 11168 | genlmsg_cancel(msg, hdr); |
| 11169 | nlmsg_free(msg); |
| 11170 | } |
| 11171 | |
| 11172 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11173 | struct net_device *netdev, const u8 *buf, |
| 11174 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11175 | { |
| 11176 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11177 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11178 | } |
| 11179 | |
| 11180 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 11181 | struct net_device *netdev, const u8 *buf, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11182 | size_t len, gfp_t gfp, int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11183 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11184 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11185 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11186 | } |
| 11187 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 11188 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11189 | struct net_device *netdev, const u8 *buf, |
| 11190 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11191 | { |
| 11192 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11193 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11194 | } |
| 11195 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 11196 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 11197 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 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_DISASSOCIATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 11202 | } |
| 11203 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11204 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 11205 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11206 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11207 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11208 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11209 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11210 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 11211 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11212 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11213 | if (WARN_ON(len < 2)) |
| 11214 | return; |
| 11215 | |
| 11216 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 11217 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 11218 | else |
| 11219 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 11220 | |
| 11221 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 11222 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11223 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 11224 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 11225 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 11226 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 11227 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11228 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11229 | { |
| 11230 | struct sk_buff *msg; |
| 11231 | void *hdr; |
| 11232 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11233 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11234 | if (!msg) |
| 11235 | return; |
| 11236 | |
| 11237 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 11238 | if (!hdr) { |
| 11239 | nlmsg_free(msg); |
| 11240 | return; |
| 11241 | } |
| 11242 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11243 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11244 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11245 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 11246 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 11247 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11248 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11249 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11250 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11251 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11252 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11253 | return; |
| 11254 | |
| 11255 | nla_put_failure: |
| 11256 | genlmsg_cancel(msg, hdr); |
| 11257 | nlmsg_free(msg); |
| 11258 | } |
| 11259 | |
| 11260 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11261 | struct net_device *netdev, const u8 *addr, |
| 11262 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11263 | { |
| 11264 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11265 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11266 | } |
| 11267 | |
| 11268 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11269 | struct net_device *netdev, const u8 *addr, |
| 11270 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11271 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11272 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 11273 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 11274 | } |
| 11275 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11276 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 11277 | struct net_device *netdev, const u8 *bssid, |
| 11278 | const u8 *req_ie, size_t req_ie_len, |
| 11279 | const u8 *resp_ie, size_t resp_ie_len, |
| 11280 | u16 status, gfp_t gfp) |
| 11281 | { |
| 11282 | struct sk_buff *msg; |
| 11283 | void *hdr; |
| 11284 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11285 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11286 | if (!msg) |
| 11287 | return; |
| 11288 | |
| 11289 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 11290 | if (!hdr) { |
| 11291 | nlmsg_free(msg); |
| 11292 | return; |
| 11293 | } |
| 11294 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11295 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11296 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11297 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 11298 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 11299 | (req_ie && |
| 11300 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 11301 | (resp_ie && |
| 11302 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 11303 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11304 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11305 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11306 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11307 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11308 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11309 | return; |
| 11310 | |
| 11311 | nla_put_failure: |
| 11312 | genlmsg_cancel(msg, hdr); |
| 11313 | nlmsg_free(msg); |
| 11314 | |
| 11315 | } |
| 11316 | |
| 11317 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 11318 | struct net_device *netdev, const u8 *bssid, |
| 11319 | const u8 *req_ie, size_t req_ie_len, |
| 11320 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 11321 | { |
| 11322 | struct sk_buff *msg; |
| 11323 | void *hdr; |
| 11324 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11325 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11326 | if (!msg) |
| 11327 | return; |
| 11328 | |
| 11329 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 11330 | if (!hdr) { |
| 11331 | nlmsg_free(msg); |
| 11332 | return; |
| 11333 | } |
| 11334 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11335 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11336 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11337 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 11338 | (req_ie && |
| 11339 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 11340 | (resp_ie && |
| 11341 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 11342 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11343 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11344 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11345 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11346 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11347 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11348 | return; |
| 11349 | |
| 11350 | nla_put_failure: |
| 11351 | genlmsg_cancel(msg, hdr); |
| 11352 | nlmsg_free(msg); |
| 11353 | |
| 11354 | } |
| 11355 | |
| 11356 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 11357 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 11358 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11359 | { |
| 11360 | struct sk_buff *msg; |
| 11361 | void *hdr; |
| 11362 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11363 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11364 | if (!msg) |
| 11365 | return; |
| 11366 | |
| 11367 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 11368 | if (!hdr) { |
| 11369 | nlmsg_free(msg); |
| 11370 | return; |
| 11371 | } |
| 11372 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11373 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11374 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11375 | (from_ap && reason && |
| 11376 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 11377 | (from_ap && |
| 11378 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 11379 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 11380 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11381 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11382 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11383 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11384 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11385 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11386 | return; |
| 11387 | |
| 11388 | nla_put_failure: |
| 11389 | genlmsg_cancel(msg, hdr); |
| 11390 | nlmsg_free(msg); |
| 11391 | |
| 11392 | } |
| 11393 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11394 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 11395 | struct net_device *netdev, const u8 *bssid, |
| 11396 | gfp_t gfp) |
| 11397 | { |
| 11398 | struct sk_buff *msg; |
| 11399 | void *hdr; |
| 11400 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11401 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11402 | if (!msg) |
| 11403 | return; |
| 11404 | |
| 11405 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 11406 | if (!hdr) { |
| 11407 | nlmsg_free(msg); |
| 11408 | return; |
| 11409 | } |
| 11410 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11411 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11412 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11413 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 11414 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11415 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11416 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11417 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11418 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11419 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11420 | return; |
| 11421 | |
| 11422 | nla_put_failure: |
| 11423 | genlmsg_cancel(msg, hdr); |
| 11424 | nlmsg_free(msg); |
| 11425 | } |
| 11426 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11427 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 11428 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11429 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11430 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11431 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11432 | struct sk_buff *msg; |
| 11433 | void *hdr; |
| 11434 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11435 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 11436 | return; |
| 11437 | |
| 11438 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 11439 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11440 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11441 | if (!msg) |
| 11442 | return; |
| 11443 | |
| 11444 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 11445 | if (!hdr) { |
| 11446 | nlmsg_free(msg); |
| 11447 | return; |
| 11448 | } |
| 11449 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11450 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11451 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11452 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11453 | (ie_len && ie && |
| 11454 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 11455 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11456 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11457 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11458 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11459 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11460 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11461 | return; |
| 11462 | |
| 11463 | nla_put_failure: |
| 11464 | genlmsg_cancel(msg, hdr); |
| 11465 | nlmsg_free(msg); |
| 11466 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11467 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11468 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11469 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 11470 | struct net_device *netdev, const u8 *addr, |
| 11471 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11472 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11473 | { |
| 11474 | struct sk_buff *msg; |
| 11475 | void *hdr; |
| 11476 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11477 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11478 | if (!msg) |
| 11479 | return; |
| 11480 | |
| 11481 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 11482 | if (!hdr) { |
| 11483 | nlmsg_free(msg); |
| 11484 | return; |
| 11485 | } |
| 11486 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11487 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11488 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11489 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 11490 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 11491 | (key_id != -1 && |
| 11492 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 11493 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 11494 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11495 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11496 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11497 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11498 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11499 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11500 | return; |
| 11501 | |
| 11502 | nla_put_failure: |
| 11503 | genlmsg_cancel(msg, hdr); |
| 11504 | nlmsg_free(msg); |
| 11505 | } |
| 11506 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11507 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 11508 | struct ieee80211_channel *channel_before, |
| 11509 | struct ieee80211_channel *channel_after) |
| 11510 | { |
| 11511 | struct sk_buff *msg; |
| 11512 | void *hdr; |
| 11513 | struct nlattr *nl_freq; |
| 11514 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11515 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11516 | if (!msg) |
| 11517 | return; |
| 11518 | |
| 11519 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 11520 | if (!hdr) { |
| 11521 | nlmsg_free(msg); |
| 11522 | return; |
| 11523 | } |
| 11524 | |
| 11525 | /* |
| 11526 | * Since we are applying the beacon hint to a wiphy we know its |
| 11527 | * wiphy_idx is valid |
| 11528 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11529 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 11530 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11531 | |
| 11532 | /* Before */ |
| 11533 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 11534 | if (!nl_freq) |
| 11535 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 11536 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11537 | goto nla_put_failure; |
| 11538 | nla_nest_end(msg, nl_freq); |
| 11539 | |
| 11540 | /* After */ |
| 11541 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 11542 | if (!nl_freq) |
| 11543 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 11544 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11545 | goto nla_put_failure; |
| 11546 | nla_nest_end(msg, nl_freq); |
| 11547 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11548 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11549 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11550 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11551 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11552 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11553 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11554 | |
| 11555 | return; |
| 11556 | |
| 11557 | nla_put_failure: |
| 11558 | genlmsg_cancel(msg, hdr); |
| 11559 | nlmsg_free(msg); |
| 11560 | } |
| 11561 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11562 | static void nl80211_send_remain_on_chan_event( |
| 11563 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11564 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11565 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11566 | unsigned int duration, gfp_t gfp) |
| 11567 | { |
| 11568 | struct sk_buff *msg; |
| 11569 | void *hdr; |
| 11570 | |
| 11571 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11572 | if (!msg) |
| 11573 | return; |
| 11574 | |
| 11575 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 11576 | if (!hdr) { |
| 11577 | nlmsg_free(msg); |
| 11578 | return; |
| 11579 | } |
| 11580 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11581 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11582 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11583 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 11584 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11585 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11586 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 11587 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11588 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 11589 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11590 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11591 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 11592 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 11593 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11594 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11595 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11596 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11597 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11598 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11599 | return; |
| 11600 | |
| 11601 | nla_put_failure: |
| 11602 | genlmsg_cancel(msg, hdr); |
| 11603 | nlmsg_free(msg); |
| 11604 | } |
| 11605 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11606 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 11607 | struct ieee80211_channel *chan, |
| 11608 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11609 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11610 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11611 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11612 | |
| 11613 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11614 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11615 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11616 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11617 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11618 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11619 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11620 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 11621 | struct ieee80211_channel *chan, |
| 11622 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11623 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11624 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11625 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11626 | |
| 11627 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11628 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11629 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11630 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11631 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11632 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11633 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 11634 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11635 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11636 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11637 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11638 | struct sk_buff *msg; |
| 11639 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11640 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 11641 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11642 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11643 | if (!msg) |
| 11644 | return; |
| 11645 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 11646 | if (nl80211_send_station(msg, 0, 0, 0, |
| 11647 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11648 | nlmsg_free(msg); |
| 11649 | return; |
| 11650 | } |
| 11651 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11652 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11653 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11654 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11655 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11656 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11657 | 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] | 11658 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11659 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11660 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11661 | struct sk_buff *msg; |
| 11662 | void *hdr; |
| 11663 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11664 | trace_cfg80211_del_sta(dev, mac_addr); |
| 11665 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11666 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11667 | if (!msg) |
| 11668 | return; |
| 11669 | |
| 11670 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 11671 | if (!hdr) { |
| 11672 | nlmsg_free(msg); |
| 11673 | return; |
| 11674 | } |
| 11675 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11676 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11677 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 11678 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11679 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11680 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11681 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11682 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11683 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11684 | return; |
| 11685 | |
| 11686 | nla_put_failure: |
| 11687 | genlmsg_cancel(msg, hdr); |
| 11688 | nlmsg_free(msg); |
| 11689 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11690 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11691 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11692 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 11693 | enum nl80211_connect_failed_reason reason, |
| 11694 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11695 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11696 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11697 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11698 | struct sk_buff *msg; |
| 11699 | void *hdr; |
| 11700 | |
| 11701 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 11702 | if (!msg) |
| 11703 | return; |
| 11704 | |
| 11705 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 11706 | if (!hdr) { |
| 11707 | nlmsg_free(msg); |
| 11708 | return; |
| 11709 | } |
| 11710 | |
| 11711 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11712 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 11713 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 11714 | goto nla_put_failure; |
| 11715 | |
| 11716 | genlmsg_end(msg, hdr); |
| 11717 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11718 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11719 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11720 | return; |
| 11721 | |
| 11722 | nla_put_failure: |
| 11723 | genlmsg_cancel(msg, hdr); |
| 11724 | nlmsg_free(msg); |
| 11725 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11726 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11727 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11728 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 11729 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11730 | { |
| 11731 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11732 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11733 | struct sk_buff *msg; |
| 11734 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11735 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11736 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11737 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11738 | return false; |
| 11739 | |
| 11740 | msg = nlmsg_new(100, gfp); |
| 11741 | if (!msg) |
| 11742 | return true; |
| 11743 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11744 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11745 | if (!hdr) { |
| 11746 | nlmsg_free(msg); |
| 11747 | return true; |
| 11748 | } |
| 11749 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11750 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11751 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11752 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 11753 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11754 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11755 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11756 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11757 | return true; |
| 11758 | |
| 11759 | nla_put_failure: |
| 11760 | genlmsg_cancel(msg, hdr); |
| 11761 | nlmsg_free(msg); |
| 11762 | return true; |
| 11763 | } |
| 11764 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11765 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 11766 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11767 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11768 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11769 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11770 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11771 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 11772 | |
| 11773 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 11774 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 11775 | trace_cfg80211_return_bool(false); |
| 11776 | return false; |
| 11777 | } |
| 11778 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 11779 | addr, gfp); |
| 11780 | trace_cfg80211_return_bool(ret); |
| 11781 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11782 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11783 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 11784 | |
| 11785 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 11786 | const u8 *addr, gfp_t gfp) |
| 11787 | { |
| 11788 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11789 | bool ret; |
| 11790 | |
| 11791 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 11792 | |
| 11793 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 11794 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 11795 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 11796 | trace_cfg80211_return_bool(false); |
| 11797 | return false; |
| 11798 | } |
| 11799 | ret = __nl80211_unexpected_frame(dev, |
| 11800 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 11801 | addr, gfp); |
| 11802 | trace_cfg80211_return_bool(ret); |
| 11803 | return ret; |
| 11804 | } |
| 11805 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11806 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11807 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11808 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 11809 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 11810 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11811 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11812 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11813 | struct sk_buff *msg; |
| 11814 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11815 | |
| 11816 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11817 | if (!msg) |
| 11818 | return -ENOMEM; |
| 11819 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11820 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11821 | if (!hdr) { |
| 11822 | nlmsg_free(msg); |
| 11823 | return -ENOMEM; |
| 11824 | } |
| 11825 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11826 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11827 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11828 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 11829 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11830 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 11831 | (sig_dbm && |
| 11832 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 11833 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 11834 | (flags && |
| 11835 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11836 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11837 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11838 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11839 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11840 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11841 | |
| 11842 | nla_put_failure: |
| 11843 | genlmsg_cancel(msg, hdr); |
| 11844 | nlmsg_free(msg); |
| 11845 | return -ENOBUFS; |
| 11846 | } |
| 11847 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11848 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 11849 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11850 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11851 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11852 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11853 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11854 | struct sk_buff *msg; |
| 11855 | void *hdr; |
| 11856 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11857 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 11858 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11859 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11860 | if (!msg) |
| 11861 | return; |
| 11862 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11863 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11864 | if (!hdr) { |
| 11865 | nlmsg_free(msg); |
| 11866 | return; |
| 11867 | } |
| 11868 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11869 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11870 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11871 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 11872 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11873 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 11874 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11875 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11876 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11877 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11878 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11879 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11880 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11881 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11882 | return; |
| 11883 | |
| 11884 | nla_put_failure: |
| 11885 | genlmsg_cancel(msg, hdr); |
| 11886 | nlmsg_free(msg); |
| 11887 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11888 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11889 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11890 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
| 11891 | const char *mac, gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11892 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11893 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11894 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 11895 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11896 | void **cb; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11897 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11898 | if (!msg) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11899 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11900 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11901 | cb = (void **)msg->cb; |
| 11902 | |
| 11903 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11904 | if (!cb[0]) { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11905 | nlmsg_free(msg); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11906 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11907 | } |
| 11908 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11909 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11910 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11911 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11912 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11913 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11914 | goto nla_put_failure; |
| 11915 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11916 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11917 | if (!cb[1]) |
| 11918 | goto nla_put_failure; |
| 11919 | |
| 11920 | cb[2] = rdev; |
| 11921 | |
| 11922 | return msg; |
| 11923 | nla_put_failure: |
| 11924 | nlmsg_free(msg); |
| 11925 | return NULL; |
| 11926 | } |
| 11927 | |
| 11928 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) |
| 11929 | { |
| 11930 | void **cb = (void **)msg->cb; |
| 11931 | struct cfg80211_registered_device *rdev = cb[2]; |
| 11932 | |
| 11933 | nla_nest_end(msg, cb[1]); |
| 11934 | genlmsg_end(msg, cb[0]); |
| 11935 | |
| 11936 | memset(msg->cb, 0, sizeof(msg->cb)); |
| 11937 | |
| 11938 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 11939 | NL80211_MCGRP_MLME, gfp); |
| 11940 | } |
| 11941 | |
| 11942 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 11943 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 11944 | gfp_t gfp) |
| 11945 | { |
| 11946 | struct sk_buff *msg; |
| 11947 | |
| 11948 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 11949 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 11950 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
| 11951 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) |
| 11952 | return; |
| 11953 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11954 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 11955 | if (!msg) |
| 11956 | return; |
| 11957 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11958 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 11959 | rssi_event)) |
| 11960 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11961 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11962 | cfg80211_send_cqm(msg, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11963 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11964 | return; |
| 11965 | |
| 11966 | nla_put_failure: |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11967 | nlmsg_free(msg); |
| 11968 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11969 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11970 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 11971 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 11972 | const u8 *peer, u32 num_packets, |
| 11973 | u32 rate, u32 intvl, gfp_t gfp) |
| 11974 | { |
| 11975 | struct sk_buff *msg; |
| 11976 | |
| 11977 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 11978 | if (!msg) |
| 11979 | return; |
| 11980 | |
| 11981 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 11982 | goto nla_put_failure; |
| 11983 | |
| 11984 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 11985 | goto nla_put_failure; |
| 11986 | |
| 11987 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 11988 | goto nla_put_failure; |
| 11989 | |
| 11990 | cfg80211_send_cqm(msg, gfp); |
| 11991 | return; |
| 11992 | |
| 11993 | nla_put_failure: |
| 11994 | nlmsg_free(msg); |
| 11995 | } |
| 11996 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
| 11997 | |
| 11998 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 11999 | const u8 *peer, u32 num_packets, gfp_t gfp) |
| 12000 | { |
| 12001 | struct sk_buff *msg; |
| 12002 | |
| 12003 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 12004 | |
| 12005 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 12006 | if (!msg) |
| 12007 | return; |
| 12008 | |
| 12009 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 12010 | goto nla_put_failure; |
| 12011 | |
| 12012 | cfg80211_send_cqm(msg, gfp); |
| 12013 | return; |
| 12014 | |
| 12015 | nla_put_failure: |
| 12016 | nlmsg_free(msg); |
| 12017 | } |
| 12018 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
| 12019 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 12020 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
| 12021 | { |
| 12022 | struct sk_buff *msg; |
| 12023 | |
| 12024 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 12025 | if (!msg) |
| 12026 | return; |
| 12027 | |
| 12028 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) |
| 12029 | goto nla_put_failure; |
| 12030 | |
| 12031 | cfg80211_send_cqm(msg, gfp); |
| 12032 | return; |
| 12033 | |
| 12034 | nla_put_failure: |
| 12035 | nlmsg_free(msg); |
| 12036 | } |
| 12037 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); |
| 12038 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12039 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 12040 | struct net_device *netdev, const u8 *bssid, |
| 12041 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12042 | { |
| 12043 | struct sk_buff *msg; |
| 12044 | struct nlattr *rekey_attr; |
| 12045 | void *hdr; |
| 12046 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12047 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12048 | if (!msg) |
| 12049 | return; |
| 12050 | |
| 12051 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 12052 | if (!hdr) { |
| 12053 | nlmsg_free(msg); |
| 12054 | return; |
| 12055 | } |
| 12056 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12057 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12058 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12059 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 12060 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12061 | |
| 12062 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 12063 | if (!rekey_attr) |
| 12064 | goto nla_put_failure; |
| 12065 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12066 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 12067 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 12068 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12069 | |
| 12070 | nla_nest_end(msg, rekey_attr); |
| 12071 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12072 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12073 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12074 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12075 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12076 | return; |
| 12077 | |
| 12078 | nla_put_failure: |
| 12079 | genlmsg_cancel(msg, hdr); |
| 12080 | nlmsg_free(msg); |
| 12081 | } |
| 12082 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12083 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 12084 | const u8 *replay_ctr, gfp_t gfp) |
| 12085 | { |
| 12086 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12087 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12088 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12089 | |
| 12090 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 12091 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 12092 | } |
| 12093 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 12094 | |
| 12095 | static void |
| 12096 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 12097 | struct net_device *netdev, int index, |
| 12098 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12099 | { |
| 12100 | struct sk_buff *msg; |
| 12101 | struct nlattr *attr; |
| 12102 | void *hdr; |
| 12103 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12104 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12105 | if (!msg) |
| 12106 | return; |
| 12107 | |
| 12108 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 12109 | if (!hdr) { |
| 12110 | nlmsg_free(msg); |
| 12111 | return; |
| 12112 | } |
| 12113 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12114 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12115 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 12116 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12117 | |
| 12118 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 12119 | if (!attr) |
| 12120 | goto nla_put_failure; |
| 12121 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12122 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 12123 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 12124 | (preauth && |
| 12125 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 12126 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12127 | |
| 12128 | nla_nest_end(msg, attr); |
| 12129 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 12130 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12131 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12132 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12133 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 12134 | return; |
| 12135 | |
| 12136 | nla_put_failure: |
| 12137 | genlmsg_cancel(msg, hdr); |
| 12138 | nlmsg_free(msg); |
| 12139 | } |
| 12140 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12141 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 12142 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 12143 | { |
| 12144 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12145 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12146 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12147 | |
| 12148 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 12149 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 12150 | } |
| 12151 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 12152 | |
| 12153 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 12154 | struct net_device *netdev, |
| 12155 | struct cfg80211_chan_def *chandef, |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12156 | gfp_t gfp, |
| 12157 | enum nl80211_commands notif, |
| 12158 | u8 count) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12159 | { |
| 12160 | struct sk_buff *msg; |
| 12161 | void *hdr; |
| 12162 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12163 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12164 | if (!msg) |
| 12165 | return; |
| 12166 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12167 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12168 | if (!hdr) { |
| 12169 | nlmsg_free(msg); |
| 12170 | return; |
| 12171 | } |
| 12172 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 12173 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 12174 | goto nla_put_failure; |
| 12175 | |
| 12176 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 12177 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12178 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12179 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
| 12180 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) |
| 12181 | goto nla_put_failure; |
| 12182 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12183 | genlmsg_end(msg, hdr); |
| 12184 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12185 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12186 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 12187 | return; |
| 12188 | |
| 12189 | nla_put_failure: |
| 12190 | genlmsg_cancel(msg, hdr); |
| 12191 | nlmsg_free(msg); |
| 12192 | } |
| 12193 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12194 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 12195 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 12196 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12197 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12198 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12199 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12200 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 12201 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12202 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 12203 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12204 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 12205 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 12206 | wdev->preset_chandef = *chandef; |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12207 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 12208 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 12209 | } |
| 12210 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 12211 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 12212 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
| 12213 | struct cfg80211_chan_def *chandef, |
| 12214 | u8 count) |
| 12215 | { |
| 12216 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12217 | struct wiphy *wiphy = wdev->wiphy; |
| 12218 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 12219 | |
| 12220 | trace_cfg80211_ch_switch_started_notify(dev, chandef); |
| 12221 | |
| 12222 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 12223 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); |
| 12224 | } |
| 12225 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); |
| 12226 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 12227 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12228 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 12229 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12230 | enum nl80211_radar_event event, |
| 12231 | struct net_device *netdev, gfp_t gfp) |
| 12232 | { |
| 12233 | struct sk_buff *msg; |
| 12234 | void *hdr; |
| 12235 | |
| 12236 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12237 | if (!msg) |
| 12238 | return; |
| 12239 | |
| 12240 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 12241 | if (!hdr) { |
| 12242 | nlmsg_free(msg); |
| 12243 | return; |
| 12244 | } |
| 12245 | |
| 12246 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 12247 | goto nla_put_failure; |
| 12248 | |
| 12249 | /* NOP and radar events don't need a netdev parameter */ |
| 12250 | if (netdev) { |
| 12251 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 12252 | |
| 12253 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12254 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12255 | goto nla_put_failure; |
| 12256 | } |
| 12257 | |
| 12258 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 12259 | goto nla_put_failure; |
| 12260 | |
| 12261 | if (nl80211_send_chandef(msg, chandef)) |
| 12262 | goto nla_put_failure; |
| 12263 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12264 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12265 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12266 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12267 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 12268 | return; |
| 12269 | |
| 12270 | nla_put_failure: |
| 12271 | genlmsg_cancel(msg, hdr); |
| 12272 | nlmsg_free(msg); |
| 12273 | } |
| 12274 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12275 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 12276 | u64 cookie, bool acked, gfp_t gfp) |
| 12277 | { |
| 12278 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12279 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12280 | struct sk_buff *msg; |
| 12281 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12282 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 12283 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 12284 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 12285 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 12286 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12287 | if (!msg) |
| 12288 | return; |
| 12289 | |
| 12290 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 12291 | if (!hdr) { |
| 12292 | nlmsg_free(msg); |
| 12293 | return; |
| 12294 | } |
| 12295 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12296 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12297 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12298 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 12299 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 12300 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 12301 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12302 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12303 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12304 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12305 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12306 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12307 | return; |
| 12308 | |
| 12309 | nla_put_failure: |
| 12310 | genlmsg_cancel(msg, hdr); |
| 12311 | nlmsg_free(msg); |
| 12312 | } |
| 12313 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 12314 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12315 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 12316 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12317 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12318 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12319 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12320 | struct sk_buff *msg; |
| 12321 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12322 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12323 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 12324 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 12325 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12326 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 12327 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 12328 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 12329 | if (!msg) { |
| 12330 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 12331 | return; |
| 12332 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12333 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12334 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 12335 | if (!hdr) |
| 12336 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12337 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12338 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12339 | (freq && |
| 12340 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 12341 | (sig_dbm && |
| 12342 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 12343 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 12344 | goto nla_put_failure; |
| 12345 | |
| 12346 | genlmsg_end(msg, hdr); |
| 12347 | |
| 12348 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12349 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12350 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12351 | return; |
| 12352 | |
| 12353 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12354 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 12355 | if (hdr) |
| 12356 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12357 | nlmsg_free(msg); |
| 12358 | } |
| 12359 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 12360 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12361 | #ifdef CONFIG_PM |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12362 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
| 12363 | struct cfg80211_wowlan_wakeup *wakeup) |
| 12364 | { |
| 12365 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; |
| 12366 | struct nlattr *nl_results, *nl_match, *nl_freqs; |
| 12367 | int i, j; |
| 12368 | |
| 12369 | nl_results = nla_nest_start( |
| 12370 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); |
| 12371 | if (!nl_results) |
| 12372 | return -EMSGSIZE; |
| 12373 | |
| 12374 | for (i = 0; i < nd->n_matches; i++) { |
| 12375 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; |
| 12376 | |
| 12377 | nl_match = nla_nest_start(msg, i); |
| 12378 | if (!nl_match) |
| 12379 | break; |
| 12380 | |
| 12381 | /* The SSID attribute is optional in nl80211, but for |
| 12382 | * simplicity reasons it's always present in the |
| 12383 | * cfg80211 structure. If a driver can't pass the |
| 12384 | * SSID, that needs to be changed. A zero length SSID |
| 12385 | * is still a valid SSID (wildcard), so it cannot be |
| 12386 | * used for this purpose. |
| 12387 | */ |
| 12388 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, |
| 12389 | match->ssid.ssid)) { |
| 12390 | nla_nest_cancel(msg, nl_match); |
| 12391 | goto out; |
| 12392 | } |
| 12393 | |
| 12394 | if (match->n_channels) { |
| 12395 | nl_freqs = nla_nest_start( |
| 12396 | msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 12397 | if (!nl_freqs) { |
| 12398 | nla_nest_cancel(msg, nl_match); |
| 12399 | goto out; |
| 12400 | } |
| 12401 | |
| 12402 | for (j = 0; j < match->n_channels; j++) { |
| 12403 | if (nla_put_u32(msg, |
| 12404 | NL80211_ATTR_WIPHY_FREQ, |
| 12405 | match->channels[j])) { |
| 12406 | nla_nest_cancel(msg, nl_freqs); |
| 12407 | nla_nest_cancel(msg, nl_match); |
| 12408 | goto out; |
| 12409 | } |
| 12410 | } |
| 12411 | |
| 12412 | nla_nest_end(msg, nl_freqs); |
| 12413 | } |
| 12414 | |
| 12415 | nla_nest_end(msg, nl_match); |
| 12416 | } |
| 12417 | |
| 12418 | out: |
| 12419 | nla_nest_end(msg, nl_results); |
| 12420 | return 0; |
| 12421 | } |
| 12422 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12423 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 12424 | struct cfg80211_wowlan_wakeup *wakeup, |
| 12425 | gfp_t gfp) |
| 12426 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12427 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12428 | struct sk_buff *msg; |
| 12429 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12430 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12431 | |
| 12432 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 12433 | |
| 12434 | if (wakeup) |
| 12435 | size += wakeup->packet_present_len; |
| 12436 | |
| 12437 | msg = nlmsg_new(size, gfp); |
| 12438 | if (!msg) |
| 12439 | return; |
| 12440 | |
| 12441 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 12442 | if (!hdr) |
| 12443 | goto free_msg; |
| 12444 | |
| 12445 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12446 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12447 | goto free_msg; |
| 12448 | |
| 12449 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12450 | wdev->netdev->ifindex)) |
| 12451 | goto free_msg; |
| 12452 | |
| 12453 | if (wakeup) { |
| 12454 | struct nlattr *reasons; |
| 12455 | |
| 12456 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 12457 | if (!reasons) |
| 12458 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12459 | |
| 12460 | if (wakeup->disconnect && |
| 12461 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 12462 | goto free_msg; |
| 12463 | if (wakeup->magic_pkt && |
| 12464 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 12465 | goto free_msg; |
| 12466 | if (wakeup->gtk_rekey_failure && |
| 12467 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 12468 | goto free_msg; |
| 12469 | if (wakeup->eap_identity_req && |
| 12470 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 12471 | goto free_msg; |
| 12472 | if (wakeup->four_way_handshake && |
| 12473 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 12474 | goto free_msg; |
| 12475 | if (wakeup->rfkill_release && |
| 12476 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 12477 | goto free_msg; |
| 12478 | |
| 12479 | if (wakeup->pattern_idx >= 0 && |
| 12480 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 12481 | wakeup->pattern_idx)) |
| 12482 | goto free_msg; |
| 12483 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12484 | if (wakeup->tcp_match && |
| 12485 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 12486 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12487 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12488 | if (wakeup->tcp_connlost && |
| 12489 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 12490 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12491 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12492 | if (wakeup->tcp_nomoretokens && |
| 12493 | nla_put_flag(msg, |
| 12494 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 12495 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12496 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12497 | if (wakeup->packet) { |
| 12498 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 12499 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 12500 | |
| 12501 | if (!wakeup->packet_80211) { |
| 12502 | pkt_attr = |
| 12503 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 12504 | len_attr = |
| 12505 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 12506 | } |
| 12507 | |
| 12508 | if (wakeup->packet_len && |
| 12509 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 12510 | goto free_msg; |
| 12511 | |
| 12512 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 12513 | wakeup->packet)) |
| 12514 | goto free_msg; |
| 12515 | } |
| 12516 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12517 | if (wakeup->net_detect && |
| 12518 | cfg80211_net_detect_results(msg, wakeup)) |
| 12519 | goto free_msg; |
| 12520 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12521 | nla_nest_end(msg, reasons); |
| 12522 | } |
| 12523 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12524 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12525 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12526 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12527 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12528 | return; |
| 12529 | |
| 12530 | free_msg: |
| 12531 | nlmsg_free(msg); |
| 12532 | } |
| 12533 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 12534 | #endif |
| 12535 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12536 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 12537 | enum nl80211_tdls_operation oper, |
| 12538 | u16 reason_code, gfp_t gfp) |
| 12539 | { |
| 12540 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12541 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12542 | struct sk_buff *msg; |
| 12543 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12544 | |
| 12545 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 12546 | reason_code); |
| 12547 | |
| 12548 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12549 | if (!msg) |
| 12550 | return; |
| 12551 | |
| 12552 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 12553 | if (!hdr) { |
| 12554 | nlmsg_free(msg); |
| 12555 | return; |
| 12556 | } |
| 12557 | |
| 12558 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12559 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12560 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 12561 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 12562 | (reason_code > 0 && |
| 12563 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 12564 | goto nla_put_failure; |
| 12565 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12566 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12567 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12568 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12569 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12570 | return; |
| 12571 | |
| 12572 | nla_put_failure: |
| 12573 | genlmsg_cancel(msg, hdr); |
| 12574 | nlmsg_free(msg); |
| 12575 | } |
| 12576 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 12577 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12578 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 12579 | unsigned long state, |
| 12580 | void *_notify) |
| 12581 | { |
| 12582 | struct netlink_notify *notify = _notify; |
| 12583 | struct cfg80211_registered_device *rdev; |
| 12584 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12585 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12586 | |
| 12587 | if (state != NETLINK_URELEASE) |
| 12588 | return NOTIFY_DONE; |
| 12589 | |
| 12590 | rcu_read_lock(); |
| 12591 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12592 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12593 | bool schedule_destroy_work = false; |
| 12594 | |
| 12595 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12596 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12597 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12598 | if (wdev->owner_nlportid == notify->portid) |
| 12599 | schedule_destroy_work = true; |
| 12600 | } |
| 12601 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12602 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 12603 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 12604 | list) { |
| 12605 | if (reg->nlportid == notify->portid) { |
| 12606 | list_del(®->list); |
| 12607 | kfree(reg); |
| 12608 | break; |
| 12609 | } |
| 12610 | } |
| 12611 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12612 | |
| 12613 | if (schedule_destroy_work) { |
| 12614 | struct cfg80211_iface_destroy *destroy; |
| 12615 | |
| 12616 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); |
| 12617 | if (destroy) { |
| 12618 | destroy->nlportid = notify->portid; |
| 12619 | spin_lock(&rdev->destroy_list_lock); |
| 12620 | list_add(&destroy->list, &rdev->destroy_list); |
| 12621 | spin_unlock(&rdev->destroy_list_lock); |
| 12622 | schedule_work(&rdev->destroy_work); |
| 12623 | } |
| 12624 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12625 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12626 | |
| 12627 | rcu_read_unlock(); |
| 12628 | |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 12629 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12630 | } |
| 12631 | |
| 12632 | static struct notifier_block nl80211_netlink_notifier = { |
| 12633 | .notifier_call = nl80211_netlink_notify, |
| 12634 | }; |
| 12635 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12636 | void cfg80211_ft_event(struct net_device *netdev, |
| 12637 | struct cfg80211_ft_event_params *ft_event) |
| 12638 | { |
| 12639 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12640 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12641 | struct sk_buff *msg; |
| 12642 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12643 | |
| 12644 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 12645 | |
| 12646 | if (!ft_event->target_ap) |
| 12647 | return; |
| 12648 | |
| 12649 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12650 | if (!msg) |
| 12651 | return; |
| 12652 | |
| 12653 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12654 | if (!hdr) |
| 12655 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12656 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12657 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12658 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12659 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 12660 | goto out; |
| 12661 | |
| 12662 | if (ft_event->ies && |
| 12663 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 12664 | goto out; |
| 12665 | if (ft_event->ric_ies && |
| 12666 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 12667 | ft_event->ric_ies)) |
| 12668 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12669 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12670 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12671 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12672 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12673 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12674 | return; |
| 12675 | out: |
| 12676 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12677 | } |
| 12678 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 12679 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12680 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 12681 | { |
| 12682 | struct cfg80211_registered_device *rdev; |
| 12683 | struct sk_buff *msg; |
| 12684 | void *hdr; |
| 12685 | u32 nlportid; |
| 12686 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12687 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12688 | if (!rdev->crit_proto_nlportid) |
| 12689 | return; |
| 12690 | |
| 12691 | nlportid = rdev->crit_proto_nlportid; |
| 12692 | rdev->crit_proto_nlportid = 0; |
| 12693 | |
| 12694 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12695 | if (!msg) |
| 12696 | return; |
| 12697 | |
| 12698 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 12699 | if (!hdr) |
| 12700 | goto nla_put_failure; |
| 12701 | |
| 12702 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12703 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12704 | goto nla_put_failure; |
| 12705 | |
| 12706 | genlmsg_end(msg, hdr); |
| 12707 | |
| 12708 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 12709 | return; |
| 12710 | |
| 12711 | nla_put_failure: |
| 12712 | if (hdr) |
| 12713 | genlmsg_cancel(msg, hdr); |
| 12714 | nlmsg_free(msg); |
| 12715 | |
| 12716 | } |
| 12717 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 12718 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 12719 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 12720 | { |
| 12721 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12722 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 12723 | struct sk_buff *msg; |
| 12724 | void *hdr; |
| 12725 | |
| 12726 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12727 | if (!msg) |
| 12728 | return; |
| 12729 | |
| 12730 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 12731 | if (!hdr) |
| 12732 | goto out; |
| 12733 | |
| 12734 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12735 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
| 12736 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12737 | goto out; |
| 12738 | |
| 12739 | genlmsg_end(msg, hdr); |
| 12740 | |
| 12741 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 12742 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 12743 | return; |
| 12744 | out: |
| 12745 | nlmsg_free(msg); |
| 12746 | } |
| 12747 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12748 | /* initialisation/exit functions */ |
| 12749 | |
| 12750 | int nl80211_init(void) |
| 12751 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 12752 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12753 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12754 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
| 12755 | nl80211_mcgrps); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12756 | if (err) |
| 12757 | return err; |
| 12758 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12759 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 12760 | if (err) |
| 12761 | goto err_out; |
| 12762 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12763 | return 0; |
| 12764 | err_out: |
| 12765 | genl_unregister_family(&nl80211_fam); |
| 12766 | return err; |
| 12767 | } |
| 12768 | |
| 12769 | void nl80211_exit(void) |
| 12770 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12771 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12772 | genl_unregister_family(&nl80211_fam); |
| 12773 | } |