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 */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 212 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
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 }, |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 391 | [NL80211_ATTR_IFACE_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 | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 398 | }; |
| 399 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 400 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 401 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 402 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 403 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 404 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 405 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 406 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 407 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 408 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 409 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 410 | }; |
| 411 | |
| 412 | /* policy for the key default flags */ |
| 413 | static const struct nla_policy |
| 414 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 415 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 416 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 417 | }; |
| 418 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 419 | /* policy for WoWLAN attributes */ |
| 420 | static const struct nla_policy |
| 421 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 422 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 423 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 424 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 425 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 426 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 427 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 428 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 429 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 430 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 431 | }; |
| 432 | |
| 433 | static const struct nla_policy |
| 434 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 435 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 436 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 437 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 438 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 439 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 440 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 441 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 442 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 443 | }, |
| 444 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 445 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 446 | }, |
| 447 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 448 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 449 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 450 | }; |
| 451 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 452 | /* policy for coalesce rule attributes */ |
| 453 | static const struct nla_policy |
| 454 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 455 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 456 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 457 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 458 | }; |
| 459 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 460 | /* policy for GTK rekey offload attributes */ |
| 461 | static const struct nla_policy |
| 462 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 463 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 464 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 465 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 466 | }; |
| 467 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 468 | static const struct nla_policy |
| 469 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 470 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 471 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 472 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 473 | }; |
| 474 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 475 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 476 | struct netlink_callback *cb, |
| 477 | struct cfg80211_registered_device **rdev, |
| 478 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 479 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 480 | int err; |
| 481 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 482 | rtnl_lock(); |
| 483 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 484 | if (!cb->args[0]) { |
| 485 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 486 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 487 | nl80211_policy); |
| 488 | if (err) |
| 489 | goto out_unlock; |
| 490 | |
| 491 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 492 | nl80211_fam.attrbuf); |
| 493 | if (IS_ERR(*wdev)) { |
| 494 | err = PTR_ERR(*wdev); |
| 495 | goto out_unlock; |
| 496 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 497 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 498 | /* 0 is the first index - add 1 to parse only once */ |
| 499 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 500 | cb->args[1] = (*wdev)->identifier; |
| 501 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 502 | /* subtract the 1 again here */ |
| 503 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 504 | struct wireless_dev *tmp; |
| 505 | |
| 506 | if (!wiphy) { |
| 507 | err = -ENODEV; |
| 508 | goto out_unlock; |
| 509 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 510 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 511 | *wdev = NULL; |
| 512 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 513 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 514 | if (tmp->identifier == cb->args[1]) { |
| 515 | *wdev = tmp; |
| 516 | break; |
| 517 | } |
| 518 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 519 | |
| 520 | if (!*wdev) { |
| 521 | err = -ENODEV; |
| 522 | goto out_unlock; |
| 523 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 524 | } |
| 525 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 526 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 527 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 528 | rtnl_unlock(); |
| 529 | return err; |
| 530 | } |
| 531 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 532 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 533 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 534 | rtnl_unlock(); |
| 535 | } |
| 536 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 537 | /* IE validation */ |
| 538 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 539 | { |
| 540 | const u8 *pos; |
| 541 | int len; |
| 542 | |
| 543 | if (!attr) |
| 544 | return true; |
| 545 | |
| 546 | pos = nla_data(attr); |
| 547 | len = nla_len(attr); |
| 548 | |
| 549 | while (len) { |
| 550 | u8 elemlen; |
| 551 | |
| 552 | if (len < 2) |
| 553 | return false; |
| 554 | len -= 2; |
| 555 | |
| 556 | elemlen = pos[1]; |
| 557 | if (elemlen > len) |
| 558 | return false; |
| 559 | |
| 560 | len -= elemlen; |
| 561 | pos += 2 + elemlen; |
| 562 | } |
| 563 | |
| 564 | return true; |
| 565 | } |
| 566 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 567 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 568 | 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] | 569 | int flags, u8 cmd) |
| 570 | { |
| 571 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 572 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 573 | } |
| 574 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 575 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 576 | struct ieee80211_channel *chan, |
| 577 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 578 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 579 | /* Some channels must be completely excluded from the |
| 580 | * list to protect old user-space tools from breaking |
| 581 | */ |
| 582 | if (!large && chan->flags & |
| 583 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 584 | return 0; |
| 585 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 586 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 587 | chan->center_freq)) |
| 588 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 589 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 590 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 591 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 592 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 593 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 594 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 595 | goto nla_put_failure; |
| 596 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 597 | goto nla_put_failure; |
| 598 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 599 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 600 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 601 | goto nla_put_failure; |
| 602 | if (large) { |
| 603 | u32 time; |
| 604 | |
| 605 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 606 | |
| 607 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 608 | chan->dfs_state)) |
| 609 | goto nla_put_failure; |
| 610 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 611 | time)) |
| 612 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 613 | if (nla_put_u32(msg, |
| 614 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 615 | chan->dfs_cac_ms)) |
| 616 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 617 | } |
| 618 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 619 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 620 | if (large) { |
| 621 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 622 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 623 | goto nla_put_failure; |
| 624 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 625 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 626 | goto nla_put_failure; |
| 627 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 628 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 629 | goto nla_put_failure; |
| 630 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 631 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 632 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 633 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 634 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 635 | goto nla_put_failure; |
| 636 | if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) && |
| 637 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT)) |
| 638 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 639 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 640 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 641 | goto nla_put_failure; |
| 642 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 643 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 644 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 645 | } |
| 646 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 647 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 648 | DBM_TO_MBM(chan->max_power))) |
| 649 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 650 | |
| 651 | return 0; |
| 652 | |
| 653 | nla_put_failure: |
| 654 | return -ENOBUFS; |
| 655 | } |
| 656 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 657 | /* netlink command implementations */ |
| 658 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 659 | struct key_parse { |
| 660 | struct key_params p; |
| 661 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 662 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 663 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 664 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 665 | }; |
| 666 | |
| 667 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 668 | { |
| 669 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 670 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 671 | nl80211_key_policy); |
| 672 | if (err) |
| 673 | return err; |
| 674 | |
| 675 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 676 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 677 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 678 | if (k->def) { |
| 679 | k->def_uni = true; |
| 680 | k->def_multi = true; |
| 681 | } |
| 682 | if (k->defmgmt) |
| 683 | k->def_multi = true; |
| 684 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 685 | if (tb[NL80211_KEY_IDX]) |
| 686 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 687 | |
| 688 | if (tb[NL80211_KEY_DATA]) { |
| 689 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 690 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 691 | } |
| 692 | |
| 693 | if (tb[NL80211_KEY_SEQ]) { |
| 694 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 695 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 696 | } |
| 697 | |
| 698 | if (tb[NL80211_KEY_CIPHER]) |
| 699 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 700 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 701 | if (tb[NL80211_KEY_TYPE]) { |
| 702 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 703 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 704 | return -EINVAL; |
| 705 | } |
| 706 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 707 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 708 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 709 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 710 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 711 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 712 | if (err) |
| 713 | return err; |
| 714 | |
| 715 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 716 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 717 | } |
| 718 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 719 | return 0; |
| 720 | } |
| 721 | |
| 722 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 723 | { |
| 724 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 725 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 726 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 727 | } |
| 728 | |
| 729 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 730 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 731 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 732 | } |
| 733 | |
| 734 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 735 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 736 | |
| 737 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 738 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 739 | |
| 740 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 741 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 742 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 743 | if (k->def) { |
| 744 | k->def_uni = true; |
| 745 | k->def_multi = true; |
| 746 | } |
| 747 | if (k->defmgmt) |
| 748 | k->def_multi = true; |
| 749 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 750 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 751 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 752 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 753 | return -EINVAL; |
| 754 | } |
| 755 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 756 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 757 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 758 | int err = nla_parse_nested( |
| 759 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 760 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 761 | nl80211_key_default_policy); |
| 762 | if (err) |
| 763 | return err; |
| 764 | |
| 765 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 766 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 767 | } |
| 768 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 769 | return 0; |
| 770 | } |
| 771 | |
| 772 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 773 | { |
| 774 | int err; |
| 775 | |
| 776 | memset(k, 0, sizeof(*k)); |
| 777 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 778 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 779 | |
| 780 | if (info->attrs[NL80211_ATTR_KEY]) |
| 781 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 782 | else |
| 783 | err = nl80211_parse_key_old(info, k); |
| 784 | |
| 785 | if (err) |
| 786 | return err; |
| 787 | |
| 788 | if (k->def && k->defmgmt) |
| 789 | return -EINVAL; |
| 790 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 791 | if (k->defmgmt) { |
| 792 | if (k->def_uni || !k->def_multi) |
| 793 | return -EINVAL; |
| 794 | } |
| 795 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 796 | if (k->idx != -1) { |
| 797 | if (k->defmgmt) { |
| 798 | if (k->idx < 4 || k->idx > 5) |
| 799 | return -EINVAL; |
| 800 | } else if (k->def) { |
| 801 | if (k->idx < 0 || k->idx > 3) |
| 802 | return -EINVAL; |
| 803 | } else { |
| 804 | if (k->idx < 0 || k->idx > 5) |
| 805 | return -EINVAL; |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | return 0; |
| 810 | } |
| 811 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 812 | static struct cfg80211_cached_keys * |
| 813 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 814 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 815 | { |
| 816 | struct key_parse parse; |
| 817 | struct nlattr *key; |
| 818 | struct cfg80211_cached_keys *result; |
| 819 | int rem, err, def = 0; |
| 820 | |
| 821 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 822 | if (!result) |
| 823 | return ERR_PTR(-ENOMEM); |
| 824 | |
| 825 | result->def = -1; |
| 826 | result->defmgmt = -1; |
| 827 | |
| 828 | nla_for_each_nested(key, keys, rem) { |
| 829 | memset(&parse, 0, sizeof(parse)); |
| 830 | parse.idx = -1; |
| 831 | |
| 832 | err = nl80211_parse_key_new(key, &parse); |
| 833 | if (err) |
| 834 | goto error; |
| 835 | err = -EINVAL; |
| 836 | if (!parse.p.key) |
| 837 | goto error; |
| 838 | if (parse.idx < 0 || parse.idx > 4) |
| 839 | goto error; |
| 840 | if (parse.def) { |
| 841 | if (def) |
| 842 | goto error; |
| 843 | def = 1; |
| 844 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 845 | if (!parse.def_uni || !parse.def_multi) |
| 846 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 847 | } else if (parse.defmgmt) |
| 848 | goto error; |
| 849 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 850 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 851 | if (err) |
| 852 | goto error; |
| 853 | result->params[parse.idx].cipher = parse.p.cipher; |
| 854 | result->params[parse.idx].key_len = parse.p.key_len; |
| 855 | result->params[parse.idx].key = result->data[parse.idx]; |
| 856 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 857 | |
| 858 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 859 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 860 | if (no_ht) |
| 861 | *no_ht = true; |
| 862 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | return result; |
| 866 | error: |
| 867 | kfree(result); |
| 868 | return ERR_PTR(err); |
| 869 | } |
| 870 | |
| 871 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 872 | { |
| 873 | ASSERT_WDEV_LOCK(wdev); |
| 874 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 875 | switch (wdev->iftype) { |
| 876 | case NL80211_IFTYPE_AP: |
| 877 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 878 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 879 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 880 | break; |
| 881 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 882 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 883 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 884 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 885 | return -ENOLINK; |
| 886 | break; |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 887 | case NL80211_IFTYPE_UNSPECIFIED: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame^] | 888 | case NL80211_IFTYPE_OCB: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 889 | case NL80211_IFTYPE_MONITOR: |
| 890 | case NL80211_IFTYPE_P2P_DEVICE: |
| 891 | case NL80211_IFTYPE_WDS: |
| 892 | case NUM_NL80211_IFTYPES: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 893 | return -EINVAL; |
| 894 | } |
| 895 | |
| 896 | return 0; |
| 897 | } |
| 898 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 899 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 900 | struct nlattr *tb) |
| 901 | { |
| 902 | struct ieee80211_channel *chan; |
| 903 | |
| 904 | if (tb == NULL) |
| 905 | return NULL; |
| 906 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 907 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 908 | return NULL; |
| 909 | return chan; |
| 910 | } |
| 911 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 912 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 913 | { |
| 914 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 915 | int i; |
| 916 | |
| 917 | if (!nl_modes) |
| 918 | goto nla_put_failure; |
| 919 | |
| 920 | i = 0; |
| 921 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 922 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 923 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 924 | ifmodes >>= 1; |
| 925 | i++; |
| 926 | } |
| 927 | |
| 928 | nla_nest_end(msg, nl_modes); |
| 929 | return 0; |
| 930 | |
| 931 | nla_put_failure: |
| 932 | return -ENOBUFS; |
| 933 | } |
| 934 | |
| 935 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 936 | struct sk_buff *msg, |
| 937 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 938 | { |
| 939 | struct nlattr *nl_combis; |
| 940 | int i, j; |
| 941 | |
| 942 | nl_combis = nla_nest_start(msg, |
| 943 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 944 | if (!nl_combis) |
| 945 | goto nla_put_failure; |
| 946 | |
| 947 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 948 | const struct ieee80211_iface_combination *c; |
| 949 | struct nlattr *nl_combi, *nl_limits; |
| 950 | |
| 951 | c = &wiphy->iface_combinations[i]; |
| 952 | |
| 953 | nl_combi = nla_nest_start(msg, i + 1); |
| 954 | if (!nl_combi) |
| 955 | goto nla_put_failure; |
| 956 | |
| 957 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 958 | if (!nl_limits) |
| 959 | goto nla_put_failure; |
| 960 | |
| 961 | for (j = 0; j < c->n_limits; j++) { |
| 962 | struct nlattr *nl_limit; |
| 963 | |
| 964 | nl_limit = nla_nest_start(msg, j + 1); |
| 965 | if (!nl_limit) |
| 966 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 967 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 968 | c->limits[j].max)) |
| 969 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 970 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 971 | c->limits[j].types)) |
| 972 | goto nla_put_failure; |
| 973 | nla_nest_end(msg, nl_limit); |
| 974 | } |
| 975 | |
| 976 | nla_nest_end(msg, nl_limits); |
| 977 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 978 | if (c->beacon_int_infra_match && |
| 979 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 980 | goto nla_put_failure; |
| 981 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 982 | c->num_different_channels) || |
| 983 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 984 | c->max_interfaces)) |
| 985 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 986 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 987 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 988 | c->radar_detect_widths) || |
| 989 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 990 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 991 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 992 | |
| 993 | nla_nest_end(msg, nl_combi); |
| 994 | } |
| 995 | |
| 996 | nla_nest_end(msg, nl_combis); |
| 997 | |
| 998 | return 0; |
| 999 | nla_put_failure: |
| 1000 | return -ENOBUFS; |
| 1001 | } |
| 1002 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1003 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1004 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 1005 | struct sk_buff *msg) |
| 1006 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1007 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1008 | struct nlattr *nl_tcp; |
| 1009 | |
| 1010 | if (!tcp) |
| 1011 | return 0; |
| 1012 | |
| 1013 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 1014 | if (!nl_tcp) |
| 1015 | return -ENOBUFS; |
| 1016 | |
| 1017 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1018 | tcp->data_payload_max)) |
| 1019 | return -ENOBUFS; |
| 1020 | |
| 1021 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1022 | tcp->data_payload_max)) |
| 1023 | return -ENOBUFS; |
| 1024 | |
| 1025 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1026 | return -ENOBUFS; |
| 1027 | |
| 1028 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1029 | sizeof(*tcp->tok), tcp->tok)) |
| 1030 | return -ENOBUFS; |
| 1031 | |
| 1032 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1033 | tcp->data_interval_max)) |
| 1034 | return -ENOBUFS; |
| 1035 | |
| 1036 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1037 | tcp->wake_payload_max)) |
| 1038 | return -ENOBUFS; |
| 1039 | |
| 1040 | nla_nest_end(msg, nl_tcp); |
| 1041 | return 0; |
| 1042 | } |
| 1043 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1044 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1045 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1046 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1047 | { |
| 1048 | struct nlattr *nl_wowlan; |
| 1049 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1050 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1051 | return 0; |
| 1052 | |
| 1053 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1054 | if (!nl_wowlan) |
| 1055 | return -ENOBUFS; |
| 1056 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1057 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1058 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1059 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1060 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1061 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1062 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1063 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1064 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1065 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1066 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1067 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1068 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1069 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1070 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1071 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1072 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1073 | return -ENOBUFS; |
| 1074 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1075 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1076 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1077 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1078 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1079 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1080 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1081 | }; |
| 1082 | |
| 1083 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1084 | sizeof(pat), &pat)) |
| 1085 | return -ENOBUFS; |
| 1086 | } |
| 1087 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1088 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1089 | return -ENOBUFS; |
| 1090 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1091 | nla_nest_end(msg, nl_wowlan); |
| 1092 | |
| 1093 | return 0; |
| 1094 | } |
| 1095 | #endif |
| 1096 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1097 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1098 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1099 | { |
| 1100 | struct nl80211_coalesce_rule_support rule; |
| 1101 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1102 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1103 | return 0; |
| 1104 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1105 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1106 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1107 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1108 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1109 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1110 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1111 | |
| 1112 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1113 | return -ENOBUFS; |
| 1114 | |
| 1115 | return 0; |
| 1116 | } |
| 1117 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1118 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1119 | struct ieee80211_supported_band *sband) |
| 1120 | { |
| 1121 | struct nlattr *nl_rates, *nl_rate; |
| 1122 | struct ieee80211_rate *rate; |
| 1123 | int i; |
| 1124 | |
| 1125 | /* add HT info */ |
| 1126 | if (sband->ht_cap.ht_supported && |
| 1127 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1128 | sizeof(sband->ht_cap.mcs), |
| 1129 | &sband->ht_cap.mcs) || |
| 1130 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1131 | sband->ht_cap.cap) || |
| 1132 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1133 | sband->ht_cap.ampdu_factor) || |
| 1134 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1135 | sband->ht_cap.ampdu_density))) |
| 1136 | return -ENOBUFS; |
| 1137 | |
| 1138 | /* add VHT info */ |
| 1139 | if (sband->vht_cap.vht_supported && |
| 1140 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1141 | sizeof(sband->vht_cap.vht_mcs), |
| 1142 | &sband->vht_cap.vht_mcs) || |
| 1143 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1144 | sband->vht_cap.cap))) |
| 1145 | return -ENOBUFS; |
| 1146 | |
| 1147 | /* add bitrates */ |
| 1148 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1149 | if (!nl_rates) |
| 1150 | return -ENOBUFS; |
| 1151 | |
| 1152 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1153 | nl_rate = nla_nest_start(msg, i); |
| 1154 | if (!nl_rate) |
| 1155 | return -ENOBUFS; |
| 1156 | |
| 1157 | rate = &sband->bitrates[i]; |
| 1158 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1159 | rate->bitrate)) |
| 1160 | return -ENOBUFS; |
| 1161 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1162 | nla_put_flag(msg, |
| 1163 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1164 | return -ENOBUFS; |
| 1165 | |
| 1166 | nla_nest_end(msg, nl_rate); |
| 1167 | } |
| 1168 | |
| 1169 | nla_nest_end(msg, nl_rates); |
| 1170 | |
| 1171 | return 0; |
| 1172 | } |
| 1173 | |
| 1174 | static int |
| 1175 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1176 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1177 | { |
| 1178 | u16 stypes; |
| 1179 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1180 | enum nl80211_iftype ift; |
| 1181 | int i; |
| 1182 | |
| 1183 | if (!mgmt_stypes) |
| 1184 | return 0; |
| 1185 | |
| 1186 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1187 | if (!nl_ifs) |
| 1188 | return -ENOBUFS; |
| 1189 | |
| 1190 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1191 | nl_ftypes = nla_nest_start(msg, ift); |
| 1192 | if (!nl_ftypes) |
| 1193 | return -ENOBUFS; |
| 1194 | i = 0; |
| 1195 | stypes = mgmt_stypes[ift].tx; |
| 1196 | while (stypes) { |
| 1197 | if ((stypes & 1) && |
| 1198 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1199 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1200 | return -ENOBUFS; |
| 1201 | stypes >>= 1; |
| 1202 | i++; |
| 1203 | } |
| 1204 | nla_nest_end(msg, nl_ftypes); |
| 1205 | } |
| 1206 | |
| 1207 | nla_nest_end(msg, nl_ifs); |
| 1208 | |
| 1209 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1210 | if (!nl_ifs) |
| 1211 | return -ENOBUFS; |
| 1212 | |
| 1213 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1214 | nl_ftypes = nla_nest_start(msg, ift); |
| 1215 | if (!nl_ftypes) |
| 1216 | return -ENOBUFS; |
| 1217 | i = 0; |
| 1218 | stypes = mgmt_stypes[ift].rx; |
| 1219 | while (stypes) { |
| 1220 | if ((stypes & 1) && |
| 1221 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1222 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1223 | return -ENOBUFS; |
| 1224 | stypes >>= 1; |
| 1225 | i++; |
| 1226 | } |
| 1227 | nla_nest_end(msg, nl_ftypes); |
| 1228 | } |
| 1229 | nla_nest_end(msg, nl_ifs); |
| 1230 | |
| 1231 | return 0; |
| 1232 | } |
| 1233 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1234 | struct nl80211_dump_wiphy_state { |
| 1235 | s64 filter_wiphy; |
| 1236 | long start; |
| 1237 | long split_start, band_start, chan_start; |
| 1238 | bool split; |
| 1239 | }; |
| 1240 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1241 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1242 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1243 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1244 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1245 | { |
| 1246 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1247 | struct nlattr *nl_bands, *nl_band; |
| 1248 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1249 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1250 | enum ieee80211_band band; |
| 1251 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1252 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1253 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1254 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1255 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1256 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1257 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1258 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1259 | return -ENOBUFS; |
| 1260 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1261 | if (WARN_ON(!state)) |
| 1262 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1263 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1264 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1265 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1266 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1267 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1268 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1269 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1270 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1271 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 1272 | goto finish; |
| 1273 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1274 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1275 | case 0: |
| 1276 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1277 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1278 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1279 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1280 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1281 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1282 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1283 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1284 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1285 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1286 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1287 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1288 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1289 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1290 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1291 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1292 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1293 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1294 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1295 | rdev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1296 | goto nla_put_failure; |
| 1297 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1298 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1299 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1300 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1301 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1302 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1303 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1304 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1305 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1306 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1307 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1308 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1309 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1310 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1311 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1312 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1313 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1314 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1315 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1316 | state->split_start++; |
| 1317 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1318 | break; |
| 1319 | case 1: |
| 1320 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1321 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 1322 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1323 | goto nla_put_failure; |
| 1324 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1325 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1326 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1327 | goto nla_put_failure; |
| 1328 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1329 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1330 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1331 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1332 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1333 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1334 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1335 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1336 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1337 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1338 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1339 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1340 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1341 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1342 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1343 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1344 | if ((rdev->wiphy.available_antennas_tx || |
| 1345 | rdev->wiphy.available_antennas_rx) && |
| 1346 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1347 | u32 tx_ant = 0, rx_ant = 0; |
| 1348 | int res; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1349 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1350 | if (!res) { |
| 1351 | if (nla_put_u32(msg, |
| 1352 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1353 | tx_ant) || |
| 1354 | nla_put_u32(msg, |
| 1355 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1356 | rx_ant)) |
| 1357 | goto nla_put_failure; |
| 1358 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1359 | } |
| 1360 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1361 | state->split_start++; |
| 1362 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1363 | break; |
| 1364 | case 2: |
| 1365 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1366 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1367 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1368 | state->split_start++; |
| 1369 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1370 | break; |
| 1371 | case 3: |
| 1372 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1373 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1374 | goto nla_put_failure; |
| 1375 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1376 | for (band = state->band_start; |
| 1377 | band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1378 | struct ieee80211_supported_band *sband; |
| 1379 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1380 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1381 | |
| 1382 | if (!sband) |
| 1383 | continue; |
| 1384 | |
| 1385 | nl_band = nla_nest_start(msg, band); |
| 1386 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1387 | goto nla_put_failure; |
| 1388 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1389 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1390 | case 0: |
| 1391 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1392 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1393 | state->chan_start++; |
| 1394 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1395 | break; |
| 1396 | default: |
| 1397 | /* add frequencies */ |
| 1398 | nl_freqs = nla_nest_start( |
| 1399 | msg, NL80211_BAND_ATTR_FREQS); |
| 1400 | if (!nl_freqs) |
| 1401 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1402 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1403 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1404 | i < sband->n_channels; |
| 1405 | i++) { |
| 1406 | nl_freq = nla_nest_start(msg, i); |
| 1407 | if (!nl_freq) |
| 1408 | goto nla_put_failure; |
| 1409 | |
| 1410 | chan = &sband->channels[i]; |
| 1411 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1412 | if (nl80211_msg_put_channel( |
| 1413 | msg, chan, |
| 1414 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1415 | goto nla_put_failure; |
| 1416 | |
| 1417 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1418 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1419 | break; |
| 1420 | } |
| 1421 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1422 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1423 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1424 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1425 | nla_nest_end(msg, nl_freqs); |
| 1426 | } |
| 1427 | |
| 1428 | nla_nest_end(msg, nl_band); |
| 1429 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1430 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1431 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1432 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1433 | band--; |
| 1434 | break; |
| 1435 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1436 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1437 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1438 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1439 | if (band < IEEE80211_NUM_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1440 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1441 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1442 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1443 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1444 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1445 | if (state->band_start == 0 && state->chan_start == 0) |
| 1446 | state->split_start++; |
| 1447 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1448 | break; |
| 1449 | case 4: |
| 1450 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1451 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1452 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1453 | |
| 1454 | i = 0; |
| 1455 | #define CMD(op, n) \ |
| 1456 | do { \ |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1457 | if (rdev->ops->op) { \ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1458 | i++; \ |
| 1459 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1460 | goto nla_put_failure; \ |
| 1461 | } \ |
| 1462 | } while (0) |
| 1463 | |
| 1464 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1465 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1466 | CMD(add_key, NEW_KEY); |
| 1467 | CMD(start_ap, START_AP); |
| 1468 | CMD(add_station, NEW_STATION); |
| 1469 | CMD(add_mpath, NEW_MPATH); |
| 1470 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1471 | CMD(change_bss, SET_BSS); |
| 1472 | CMD(auth, AUTHENTICATE); |
| 1473 | CMD(assoc, ASSOCIATE); |
| 1474 | CMD(deauth, DEAUTHENTICATE); |
| 1475 | CMD(disassoc, DISASSOCIATE); |
| 1476 | CMD(join_ibss, JOIN_IBSS); |
| 1477 | CMD(join_mesh, JOIN_MESH); |
| 1478 | CMD(set_pmksa, SET_PMKSA); |
| 1479 | CMD(del_pmksa, DEL_PMKSA); |
| 1480 | CMD(flush_pmksa, FLUSH_PMKSA); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1481 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1482 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1483 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1484 | CMD(mgmt_tx, FRAME); |
| 1485 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1486 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1487 | i++; |
| 1488 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1489 | goto nla_put_failure; |
| 1490 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1491 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1492 | rdev->ops->join_mesh) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1493 | i++; |
| 1494 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1495 | goto nla_put_failure; |
| 1496 | } |
| 1497 | CMD(set_wds_peer, SET_WDS_PEER); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1498 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1499 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1500 | CMD(tdls_oper, TDLS_OPER); |
| 1501 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1502 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1503 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1504 | CMD(probe_client, PROBE_CLIENT); |
| 1505 | CMD(set_noack_map, SET_NOACK_MAP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1506 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1507 | i++; |
| 1508 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1509 | goto nla_put_failure; |
| 1510 | } |
| 1511 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1512 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1513 | #ifdef CONFIG_NL80211_TESTMODE |
| 1514 | CMD(testmode_cmd, TESTMODE); |
| 1515 | #endif |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1516 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1517 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1518 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1519 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1520 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1521 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 1522 | if (rdev->wiphy.features & |
| 1523 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 1524 | CMD(add_tx_ts, ADD_TX_TS); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1525 | } |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1526 | /* add into the if now */ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1527 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1528 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1529 | if (rdev->ops->connect || rdev->ops->auth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1530 | i++; |
| 1531 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1532 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1533 | } |
| 1534 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1535 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1536 | i++; |
| 1537 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1538 | goto nla_put_failure; |
| 1539 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1540 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1541 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1542 | state->split_start++; |
| 1543 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1544 | break; |
| 1545 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1546 | if (rdev->ops->remain_on_channel && |
| 1547 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1548 | nla_put_u32(msg, |
| 1549 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1550 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1551 | goto nla_put_failure; |
| 1552 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1553 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1554 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1555 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1556 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1557 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1558 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1559 | state->split_start++; |
| 1560 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1561 | break; |
| 1562 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1563 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1564 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1565 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1566 | state->split_start++; |
| 1567 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1568 | break; |
| 1569 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1570 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1571 | #endif |
| 1572 | case 7: |
| 1573 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1574 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1575 | goto nla_put_failure; |
| 1576 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1577 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1578 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1579 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1580 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1581 | state->split_start++; |
| 1582 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1583 | break; |
| 1584 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1585 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1586 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1587 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1588 | goto nla_put_failure; |
| 1589 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1590 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1591 | /* |
| 1592 | * We can only add the per-channel limit information if the |
| 1593 | * dump is split, otherwise it makes it too big. Therefore |
| 1594 | * only advertise it in that case. |
| 1595 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1596 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1597 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1598 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1599 | goto nla_put_failure; |
| 1600 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1601 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1602 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1603 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 1604 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1605 | goto nla_put_failure; |
| 1606 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1607 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1608 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1609 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1610 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1611 | goto nla_put_failure; |
| 1612 | |
| 1613 | /* |
| 1614 | * Any information below this point is only available to |
| 1615 | * applications that can deal with it being split. This |
| 1616 | * helps ensure that newly added capabilities don't break |
| 1617 | * older tools by overrunning their buffers. |
| 1618 | * |
| 1619 | * We still increment split_start so that in the split |
| 1620 | * case we'll continue with more data in the next round, |
| 1621 | * but break unconditionally so unsplit data stops here. |
| 1622 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1623 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1624 | break; |
| 1625 | case 9: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1626 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1627 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1628 | rdev->wiphy.extended_capabilities_len, |
| 1629 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1630 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1631 | rdev->wiphy.extended_capabilities_len, |
| 1632 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1633 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1634 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1635 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1636 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1637 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 1638 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1639 | goto nla_put_failure; |
| 1640 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1641 | state->split_start++; |
| 1642 | break; |
| 1643 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1644 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1645 | goto nla_put_failure; |
| 1646 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1647 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1648 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1649 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1650 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1651 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1652 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1653 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1654 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1655 | goto nla_put_failure; |
| 1656 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1657 | state->split_start++; |
| 1658 | break; |
| 1659 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1660 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1661 | const struct nl80211_vendor_cmd_info *info; |
| 1662 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1663 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1664 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1665 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1666 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1667 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1668 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 1669 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1670 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1671 | goto nla_put_failure; |
| 1672 | } |
| 1673 | nla_nest_end(msg, nested); |
| 1674 | } |
| 1675 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1676 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1677 | const struct nl80211_vendor_cmd_info *info; |
| 1678 | struct nlattr *nested; |
| 1679 | |
| 1680 | nested = nla_nest_start(msg, |
| 1681 | NL80211_ATTR_VENDOR_EVENTS); |
| 1682 | if (!nested) |
| 1683 | goto nla_put_failure; |
| 1684 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1685 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 1686 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1687 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1688 | goto nla_put_failure; |
| 1689 | } |
| 1690 | nla_nest_end(msg, nested); |
| 1691 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 1692 | state->split_start++; |
| 1693 | break; |
| 1694 | case 12: |
| 1695 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 1696 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 1697 | rdev->wiphy.max_num_csa_counters)) |
| 1698 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1699 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1700 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1701 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1702 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1703 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1704 | finish: |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1705 | return genlmsg_end(msg, hdr); |
| 1706 | |
| 1707 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1708 | genlmsg_cancel(msg, hdr); |
| 1709 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1710 | } |
| 1711 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1712 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1713 | struct netlink_callback *cb, |
| 1714 | struct nl80211_dump_wiphy_state *state) |
| 1715 | { |
| 1716 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1717 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1718 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1719 | /* ignore parse errors for backward compatibility */ |
| 1720 | if (ret) |
| 1721 | return 0; |
| 1722 | |
| 1723 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1724 | if (tb[NL80211_ATTR_WIPHY]) |
| 1725 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1726 | if (tb[NL80211_ATTR_WDEV]) |
| 1727 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1728 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1729 | struct net_device *netdev; |
| 1730 | struct cfg80211_registered_device *rdev; |
| 1731 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1732 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1733 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1734 | if (!netdev) |
| 1735 | return -ENODEV; |
| 1736 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1737 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1738 | netdev->ieee80211_ptr->wiphy); |
| 1739 | state->filter_wiphy = rdev->wiphy_idx; |
| 1740 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | return 0; |
| 1744 | } |
| 1745 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1746 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1747 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1748 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1749 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1750 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1751 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1752 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1753 | if (!state) { |
| 1754 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1755 | if (!state) { |
| 1756 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1757 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1758 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1759 | state->filter_wiphy = -1; |
| 1760 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1761 | if (ret) { |
| 1762 | kfree(state); |
| 1763 | rtnl_unlock(); |
| 1764 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1765 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1766 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1767 | } |
| 1768 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1769 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1770 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1771 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1772 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1773 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1774 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1775 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1776 | continue; |
| 1777 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1778 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1779 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 1780 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1781 | NETLINK_CB(cb->skb).portid, |
| 1782 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1783 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1784 | if (ret < 0) { |
| 1785 | /* |
| 1786 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1787 | * or EMSGSIZE returned), this SKB is still |
| 1788 | * empty (so it's not too big because another |
| 1789 | * wiphy dataset is already in the skb) and |
| 1790 | * we've not tried to adjust the dump allocation |
| 1791 | * yet ... then adjust the alloc size to be |
| 1792 | * bigger, and return 1 but with the empty skb. |
| 1793 | * This results in an empty message being RX'ed |
| 1794 | * in userspace, but that is ignored. |
| 1795 | * |
| 1796 | * We can then retry with the larger buffer. |
| 1797 | */ |
| 1798 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1799 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1800 | cb->min_dump_alloc < 4096) { |
| 1801 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1802 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1803 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1804 | return 1; |
| 1805 | } |
| 1806 | idx--; |
| 1807 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1808 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1809 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1810 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1811 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1812 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1813 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1814 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1815 | |
| 1816 | return skb->len; |
| 1817 | } |
| 1818 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1819 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1820 | { |
| 1821 | kfree((void *)cb->args[0]); |
| 1822 | return 0; |
| 1823 | } |
| 1824 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1825 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1826 | { |
| 1827 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1828 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1829 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1830 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1831 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1832 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1833 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1834 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1835 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 1836 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1837 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1838 | nlmsg_free(msg); |
| 1839 | return -ENOBUFS; |
| 1840 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1841 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1842 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1843 | } |
| 1844 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1845 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1846 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1847 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1848 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1849 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1850 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1851 | }; |
| 1852 | |
| 1853 | static int parse_txq_params(struct nlattr *tb[], |
| 1854 | struct ieee80211_txq_params *txq_params) |
| 1855 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1856 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1857 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1858 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1859 | return -EINVAL; |
| 1860 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1861 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1862 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1863 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1864 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1865 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1866 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1867 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1868 | return -EINVAL; |
| 1869 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1870 | return 0; |
| 1871 | } |
| 1872 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1873 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1874 | { |
| 1875 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1876 | * You can only set the channel explicitly for WDS interfaces, |
| 1877 | * all others have their channel managed via their respective |
| 1878 | * "establish a connection" command (connect, join, ...) |
| 1879 | * |
| 1880 | * For AP/GO and mesh mode, the channel can be set with the |
| 1881 | * channel userspace API, but is only stored and passed to the |
| 1882 | * low-level driver when the AP starts or the mesh is joined. |
| 1883 | * This is for backward compatibility, userspace can also give |
| 1884 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1885 | * |
| 1886 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1887 | * whatever else is going on, so they have their own special |
| 1888 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1889 | */ |
| 1890 | return !wdev || |
| 1891 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1892 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1893 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1894 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1895 | } |
| 1896 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1897 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1898 | struct genl_info *info, |
| 1899 | struct cfg80211_chan_def *chandef) |
| 1900 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1901 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1902 | |
| 1903 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1904 | return -EINVAL; |
| 1905 | |
| 1906 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1907 | |
| 1908 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1909 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1910 | chandef->center_freq1 = control_freq; |
| 1911 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1912 | |
| 1913 | /* Primary channel not allowed */ |
| 1914 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1915 | return -EINVAL; |
| 1916 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1917 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1918 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1919 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1920 | chantype = nla_get_u32( |
| 1921 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1922 | |
| 1923 | switch (chantype) { |
| 1924 | case NL80211_CHAN_NO_HT: |
| 1925 | case NL80211_CHAN_HT20: |
| 1926 | case NL80211_CHAN_HT40PLUS: |
| 1927 | case NL80211_CHAN_HT40MINUS: |
| 1928 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1929 | chantype); |
| 1930 | break; |
| 1931 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1932 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1933 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1934 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1935 | chandef->width = |
| 1936 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1937 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1938 | chandef->center_freq1 = |
| 1939 | nla_get_u32( |
| 1940 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1941 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1942 | chandef->center_freq2 = |
| 1943 | nla_get_u32( |
| 1944 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1945 | } |
| 1946 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1947 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1948 | return -EINVAL; |
| 1949 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1950 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1951 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1952 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1953 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1954 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1955 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1956 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1957 | return -EINVAL; |
| 1958 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1959 | return 0; |
| 1960 | } |
| 1961 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1962 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1963 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1964 | struct genl_info *info) |
| 1965 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1966 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1967 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1968 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1969 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1970 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1971 | if (dev) |
| 1972 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1973 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1974 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1975 | if (wdev) |
| 1976 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1977 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1978 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1979 | if (result) |
| 1980 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1981 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1982 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1983 | case NL80211_IFTYPE_AP: |
| 1984 | case NL80211_IFTYPE_P2P_GO: |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1985 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1986 | result = -EINVAL; |
| 1987 | break; |
| 1988 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1989 | if (wdev->beacon_interval) { |
| 1990 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 1991 | !(rdev->wiphy.features & |
| 1992 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 1993 | result = -EBUSY; |
| 1994 | break; |
| 1995 | } |
| 1996 | |
| 1997 | /* Only allow dynamic channel width changes */ |
| 1998 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 1999 | result = -EBUSY; |
| 2000 | break; |
| 2001 | } |
| 2002 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 2003 | if (result) |
| 2004 | break; |
| 2005 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2006 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2007 | result = 0; |
| 2008 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2009 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2010 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2011 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2012 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2013 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2014 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2015 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2016 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2017 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2018 | |
| 2019 | return result; |
| 2020 | } |
| 2021 | |
| 2022 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 2023 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2024 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2025 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2026 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2027 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2028 | } |
| 2029 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2030 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 2031 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2032 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2033 | struct net_device *dev = info->user_ptr[1]; |
| 2034 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2035 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2036 | |
| 2037 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2038 | return -EINVAL; |
| 2039 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2040 | if (netif_running(dev)) |
| 2041 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2042 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2043 | if (!rdev->ops->set_wds_peer) |
| 2044 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2045 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2046 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 2047 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2048 | |
| 2049 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2050 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2051 | } |
| 2052 | |
| 2053 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2054 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2055 | { |
| 2056 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2057 | struct net_device *netdev = NULL; |
| 2058 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2059 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2060 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2061 | u32 changed; |
| 2062 | u8 retry_short = 0, retry_long = 0; |
| 2063 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2064 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2065 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2066 | ASSERT_RTNL(); |
| 2067 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2068 | /* |
| 2069 | * Try to find the wiphy and netdev. Normally this |
| 2070 | * function shouldn't need the netdev, but this is |
| 2071 | * done for backward compatibility -- previously |
| 2072 | * setting the channel was done per wiphy, but now |
| 2073 | * it is per netdev. Previous userland like hostapd |
| 2074 | * also passed a netdev to set_wiphy, so that it is |
| 2075 | * possible to let that go to the right netdev! |
| 2076 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2077 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2078 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2079 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2080 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2081 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2082 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2083 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2084 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2085 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2086 | } |
| 2087 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2088 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2089 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2090 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2091 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2092 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2093 | wdev = NULL; |
| 2094 | netdev = NULL; |
| 2095 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2096 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2097 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2098 | |
| 2099 | /* |
| 2100 | * end workaround code, by now the rdev is available |
| 2101 | * and locked, and wdev may or may not be NULL. |
| 2102 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2103 | |
| 2104 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2105 | result = cfg80211_dev_rename( |
| 2106 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2107 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2108 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2109 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2110 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2111 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2112 | struct ieee80211_txq_params txq_params; |
| 2113 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2114 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2115 | if (!rdev->ops->set_txq_params) |
| 2116 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2117 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2118 | if (!netdev) |
| 2119 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2120 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2121 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2122 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2123 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2124 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2125 | if (!netif_running(netdev)) |
| 2126 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2127 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2128 | nla_for_each_nested(nl_txq_params, |
| 2129 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2130 | rem_txq_params) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2131 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 2132 | nla_data(nl_txq_params), |
| 2133 | nla_len(nl_txq_params), |
| 2134 | txq_params_policy); |
| 2135 | if (result) |
| 2136 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2137 | result = parse_txq_params(tb, &txq_params); |
| 2138 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2139 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2140 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2141 | result = rdev_set_txq_params(rdev, netdev, |
| 2142 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2143 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2144 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2145 | } |
| 2146 | } |
| 2147 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2148 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2149 | result = __nl80211_set_channel( |
| 2150 | rdev, |
| 2151 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 2152 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2153 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2154 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2155 | } |
| 2156 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2157 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2158 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2159 | enum nl80211_tx_power_setting type; |
| 2160 | int idx, mbm = 0; |
| 2161 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2162 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2163 | txp_wdev = NULL; |
| 2164 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2165 | if (!rdev->ops->set_tx_power) |
| 2166 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2167 | |
| 2168 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2169 | type = nla_get_u32(info->attrs[idx]); |
| 2170 | |
| 2171 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2172 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2173 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2174 | |
| 2175 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2176 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2177 | mbm = nla_get_u32(info->attrs[idx]); |
| 2178 | } |
| 2179 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2180 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2181 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2182 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2183 | } |
| 2184 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2185 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2186 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2187 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2188 | if ((!rdev->wiphy.available_antennas_tx && |
| 2189 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2190 | !rdev->ops->set_antenna) |
| 2191 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2192 | |
| 2193 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2194 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2195 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2196 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2197 | * available antenna masks, except for the "all" mask */ |
| 2198 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2199 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2200 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2201 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2202 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2203 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2204 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2205 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2206 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2207 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2208 | } |
| 2209 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2210 | changed = 0; |
| 2211 | |
| 2212 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2213 | retry_short = nla_get_u8( |
| 2214 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2215 | if (retry_short == 0) |
| 2216 | return -EINVAL; |
| 2217 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2218 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2219 | } |
| 2220 | |
| 2221 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2222 | retry_long = nla_get_u8( |
| 2223 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2224 | if (retry_long == 0) |
| 2225 | return -EINVAL; |
| 2226 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2227 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2228 | } |
| 2229 | |
| 2230 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2231 | frag_threshold = nla_get_u32( |
| 2232 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2233 | if (frag_threshold < 256) |
| 2234 | return -EINVAL; |
| 2235 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2236 | if (frag_threshold != (u32) -1) { |
| 2237 | /* |
| 2238 | * Fragments (apart from the last one) are required to |
| 2239 | * have even length. Make the fragmentation code |
| 2240 | * simpler by stripping LSB should someone try to use |
| 2241 | * odd threshold value. |
| 2242 | */ |
| 2243 | frag_threshold &= ~0x1; |
| 2244 | } |
| 2245 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2246 | } |
| 2247 | |
| 2248 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2249 | rts_threshold = nla_get_u32( |
| 2250 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2251 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2252 | } |
| 2253 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2254 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2255 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 2256 | return -EINVAL; |
| 2257 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2258 | coverage_class = nla_get_u8( |
| 2259 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2260 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2261 | } |
| 2262 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2263 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 2264 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 2265 | return -EOPNOTSUPP; |
| 2266 | |
| 2267 | changed |= WIPHY_PARAM_DYN_ACK; |
| 2268 | } |
| 2269 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2270 | if (changed) { |
| 2271 | u8 old_retry_short, old_retry_long; |
| 2272 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2273 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2274 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2275 | if (!rdev->ops->set_wiphy_params) |
| 2276 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2277 | |
| 2278 | old_retry_short = rdev->wiphy.retry_short; |
| 2279 | old_retry_long = rdev->wiphy.retry_long; |
| 2280 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2281 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2282 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2283 | |
| 2284 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2285 | rdev->wiphy.retry_short = retry_short; |
| 2286 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2287 | rdev->wiphy.retry_long = retry_long; |
| 2288 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2289 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2290 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2291 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2292 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2293 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2294 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2295 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2296 | if (result) { |
| 2297 | rdev->wiphy.retry_short = old_retry_short; |
| 2298 | rdev->wiphy.retry_long = old_retry_long; |
| 2299 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2300 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2301 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2302 | } |
| 2303 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2304 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2305 | } |
| 2306 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2307 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2308 | { |
| 2309 | return (u64)wdev->identifier | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2310 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2311 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2312 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2313 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2314 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2315 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2316 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2317 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2318 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2319 | chandef->chan->center_freq)) |
| 2320 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2321 | switch (chandef->width) { |
| 2322 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2323 | case NL80211_CHAN_WIDTH_20: |
| 2324 | case NL80211_CHAN_WIDTH_40: |
| 2325 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2326 | cfg80211_get_chandef_type(chandef))) |
| 2327 | return -ENOBUFS; |
| 2328 | break; |
| 2329 | default: |
| 2330 | break; |
| 2331 | } |
| 2332 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2333 | return -ENOBUFS; |
| 2334 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2335 | return -ENOBUFS; |
| 2336 | if (chandef->center_freq2 && |
| 2337 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2338 | return -ENOBUFS; |
| 2339 | return 0; |
| 2340 | } |
| 2341 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2342 | 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] | 2343 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2344 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2345 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2346 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2347 | void *hdr; |
| 2348 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2349 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2350 | if (!hdr) |
| 2351 | return -1; |
| 2352 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2353 | if (dev && |
| 2354 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2355 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2356 | goto nla_put_failure; |
| 2357 | |
| 2358 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2359 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2360 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2361 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2362 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2363 | rdev->devlist_generation ^ |
| 2364 | (cfg80211_rdev_list_generation << 2))) |
| 2365 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2366 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2367 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2368 | int ret; |
| 2369 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2370 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2371 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2372 | if (ret == 0) { |
| 2373 | if (nl80211_send_chandef(msg, &chandef)) |
| 2374 | goto nla_put_failure; |
| 2375 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2376 | } |
| 2377 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2378 | if (wdev->ssid_len) { |
| 2379 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2380 | goto nla_put_failure; |
| 2381 | } |
| 2382 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2383 | return genlmsg_end(msg, hdr); |
| 2384 | |
| 2385 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2386 | genlmsg_cancel(msg, hdr); |
| 2387 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2388 | } |
| 2389 | |
| 2390 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2391 | { |
| 2392 | int wp_idx = 0; |
| 2393 | int if_idx = 0; |
| 2394 | int wp_start = cb->args[0]; |
| 2395 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2396 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2397 | struct wireless_dev *wdev; |
| 2398 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2399 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2400 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2401 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2402 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2403 | if (wp_idx < wp_start) { |
| 2404 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2405 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2406 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2407 | if_idx = 0; |
| 2408 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2409 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2410 | if (if_idx < if_start) { |
| 2411 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2412 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2413 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2414 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2415 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2416 | rdev, wdev) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2417 | goto out; |
| 2418 | } |
| 2419 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2420 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2421 | |
| 2422 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2423 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2424 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2425 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2426 | |
| 2427 | cb->args[0] = wp_idx; |
| 2428 | cb->args[1] = if_idx; |
| 2429 | |
| 2430 | return skb->len; |
| 2431 | } |
| 2432 | |
| 2433 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2434 | { |
| 2435 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2436 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2437 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2438 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2439 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2440 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2441 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2442 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2443 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2444 | rdev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2445 | nlmsg_free(msg); |
| 2446 | return -ENOBUFS; |
| 2447 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2448 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2449 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2450 | } |
| 2451 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2452 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2453 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2454 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2455 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2456 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2457 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2458 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2459 | }; |
| 2460 | |
| 2461 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2462 | { |
| 2463 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2464 | int flag; |
| 2465 | |
| 2466 | *mntrflags = 0; |
| 2467 | |
| 2468 | if (!nla) |
| 2469 | return -EINVAL; |
| 2470 | |
| 2471 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2472 | nla, mntr_flags_policy)) |
| 2473 | return -EINVAL; |
| 2474 | |
| 2475 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2476 | if (flags[flag]) |
| 2477 | *mntrflags |= (1<<flag); |
| 2478 | |
| 2479 | return 0; |
| 2480 | } |
| 2481 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2482 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2483 | struct net_device *netdev, u8 use_4addr, |
| 2484 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2485 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2486 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2487 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2488 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2489 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2490 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2491 | |
| 2492 | switch (iftype) { |
| 2493 | case NL80211_IFTYPE_AP_VLAN: |
| 2494 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2495 | return 0; |
| 2496 | break; |
| 2497 | case NL80211_IFTYPE_STATION: |
| 2498 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2499 | return 0; |
| 2500 | break; |
| 2501 | default: |
| 2502 | break; |
| 2503 | } |
| 2504 | |
| 2505 | return -EOPNOTSUPP; |
| 2506 | } |
| 2507 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2508 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2509 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2510 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2511 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2512 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2513 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2514 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2515 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2516 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2517 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2518 | memset(¶ms, 0, sizeof(params)); |
| 2519 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2520 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2521 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2522 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2523 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2524 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2525 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2526 | if (ntype > NL80211_IFTYPE_MAX) |
| 2527 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2528 | } |
| 2529 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2530 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2531 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2532 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2533 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2534 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2535 | if (netif_running(dev)) |
| 2536 | return -EBUSY; |
| 2537 | |
| 2538 | wdev_lock(wdev); |
| 2539 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2540 | IEEE80211_MAX_MESH_ID_LEN); |
| 2541 | wdev->mesh_id_up_len = |
| 2542 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2543 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2544 | wdev->mesh_id_up_len); |
| 2545 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2546 | } |
| 2547 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2548 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2549 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2550 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2551 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2552 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2553 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2554 | } else { |
| 2555 | params.use_4addr = -1; |
| 2556 | } |
| 2557 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2558 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2559 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2560 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2561 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2562 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2563 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2564 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2565 | |
| 2566 | flags = &_flags; |
| 2567 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2568 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2569 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2570 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2571 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2572 | return -EOPNOTSUPP; |
| 2573 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2574 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2575 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2576 | else |
| 2577 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2578 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2579 | if (!err && params.use_4addr != -1) |
| 2580 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2581 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2582 | return err; |
| 2583 | } |
| 2584 | |
| 2585 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2586 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2587 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2588 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2589 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2590 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2591 | int err; |
| 2592 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2593 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2594 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2595 | /* to avoid failing a new interface creation due to pending removal */ |
| 2596 | cfg80211_destroy_ifaces(rdev); |
| 2597 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2598 | memset(¶ms, 0, sizeof(params)); |
| 2599 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2600 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2601 | return -EINVAL; |
| 2602 | |
| 2603 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2604 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2605 | if (type > NL80211_IFTYPE_MAX) |
| 2606 | return -EINVAL; |
| 2607 | } |
| 2608 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2609 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2610 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2611 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2612 | |
Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 2613 | if ((type == NL80211_IFTYPE_P2P_DEVICE || |
| 2614 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 2615 | info->attrs[NL80211_ATTR_MAC]) { |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2616 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2617 | ETH_ALEN); |
| 2618 | if (!is_valid_ether_addr(params.macaddr)) |
| 2619 | return -EADDRNOTAVAIL; |
| 2620 | } |
| 2621 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2622 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2623 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2624 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2625 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2626 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2627 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2628 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2629 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2630 | if (!msg) |
| 2631 | return -ENOMEM; |
| 2632 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2633 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2634 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2635 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2636 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2637 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2638 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2639 | return -EOPNOTSUPP; |
| 2640 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2641 | wdev = rdev_add_virtual_intf(rdev, |
| 2642 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2643 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2644 | if (IS_ERR(wdev)) { |
| 2645 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2646 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2647 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2648 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2649 | if (info->attrs[NL80211_ATTR_IFACE_SOCKET_OWNER]) |
| 2650 | wdev->owner_nlportid = info->snd_portid; |
| 2651 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2652 | switch (type) { |
| 2653 | case NL80211_IFTYPE_MESH_POINT: |
| 2654 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2655 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2656 | wdev_lock(wdev); |
| 2657 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2658 | IEEE80211_MAX_MESH_ID_LEN); |
| 2659 | wdev->mesh_id_up_len = |
| 2660 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2661 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2662 | wdev->mesh_id_up_len); |
| 2663 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2664 | break; |
| 2665 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2666 | /* |
| 2667 | * P2P Device doesn't have a netdev, so doesn't go |
| 2668 | * through the netdev notifier and must be added here |
| 2669 | */ |
| 2670 | mutex_init(&wdev->mtx); |
| 2671 | INIT_LIST_HEAD(&wdev->event_list); |
| 2672 | spin_lock_init(&wdev->event_lock); |
| 2673 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2674 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2675 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2676 | wdev->identifier = ++rdev->wdev_id; |
| 2677 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2678 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2679 | break; |
| 2680 | default: |
| 2681 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2682 | } |
| 2683 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2684 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2685 | rdev, wdev) < 0) { |
| 2686 | nlmsg_free(msg); |
| 2687 | return -ENOBUFS; |
| 2688 | } |
| 2689 | |
| 2690 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2691 | } |
| 2692 | |
| 2693 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2694 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2695 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2696 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2697 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2698 | if (!rdev->ops->del_virtual_intf) |
| 2699 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2700 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2701 | /* |
| 2702 | * If we remove a wireless device without a netdev then clear |
| 2703 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2704 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2705 | * since the wdev has been freed, unlike with a netdev where |
| 2706 | * we need the dev_put() for the netdev to really be freed. |
| 2707 | */ |
| 2708 | if (!wdev->netdev) |
| 2709 | info->user_ptr[1] = NULL; |
| 2710 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2711 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2712 | } |
| 2713 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2714 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2715 | { |
| 2716 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2717 | struct net_device *dev = info->user_ptr[1]; |
| 2718 | u16 noack_map; |
| 2719 | |
| 2720 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2721 | return -EINVAL; |
| 2722 | |
| 2723 | if (!rdev->ops->set_noack_map) |
| 2724 | return -EOPNOTSUPP; |
| 2725 | |
| 2726 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2727 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2728 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2729 | } |
| 2730 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2731 | struct get_key_cookie { |
| 2732 | struct sk_buff *msg; |
| 2733 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2734 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2735 | }; |
| 2736 | |
| 2737 | static void get_key_callback(void *c, struct key_params *params) |
| 2738 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2739 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2740 | struct get_key_cookie *cookie = c; |
| 2741 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2742 | if ((params->key && |
| 2743 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2744 | params->key_len, params->key)) || |
| 2745 | (params->seq && |
| 2746 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2747 | params->seq_len, params->seq)) || |
| 2748 | (params->cipher && |
| 2749 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2750 | params->cipher))) |
| 2751 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2752 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2753 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2754 | if (!key) |
| 2755 | goto nla_put_failure; |
| 2756 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2757 | if ((params->key && |
| 2758 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2759 | params->key_len, params->key)) || |
| 2760 | (params->seq && |
| 2761 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2762 | params->seq_len, params->seq)) || |
| 2763 | (params->cipher && |
| 2764 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2765 | params->cipher))) |
| 2766 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2767 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2768 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2769 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2770 | |
| 2771 | nla_nest_end(cookie->msg, key); |
| 2772 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2773 | return; |
| 2774 | nla_put_failure: |
| 2775 | cookie->error = 1; |
| 2776 | } |
| 2777 | |
| 2778 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2779 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2780 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2781 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2782 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2783 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2784 | const u8 *mac_addr = NULL; |
| 2785 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2786 | struct get_key_cookie cookie = { |
| 2787 | .error = 0, |
| 2788 | }; |
| 2789 | void *hdr; |
| 2790 | struct sk_buff *msg; |
| 2791 | |
| 2792 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2793 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2794 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2795 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2796 | return -EINVAL; |
| 2797 | |
| 2798 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2799 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2800 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2801 | pairwise = !!mac_addr; |
| 2802 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2803 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2804 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2805 | return -EINVAL; |
| 2806 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2807 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2808 | return -EINVAL; |
| 2809 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2810 | } |
| 2811 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2812 | if (!rdev->ops->get_key) |
| 2813 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2814 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2815 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2816 | if (!msg) |
| 2817 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2818 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2819 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2820 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2821 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 2822 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2823 | |
| 2824 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2825 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2826 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2827 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2828 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2829 | goto nla_put_failure; |
| 2830 | if (mac_addr && |
| 2831 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2832 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2833 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2834 | if (pairwise && mac_addr && |
| 2835 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2836 | return -ENOENT; |
| 2837 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2838 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2839 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2840 | |
| 2841 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2842 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2843 | |
| 2844 | if (cookie.error) |
| 2845 | goto nla_put_failure; |
| 2846 | |
| 2847 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2848 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2849 | |
| 2850 | nla_put_failure: |
| 2851 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2852 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2853 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2854 | return err; |
| 2855 | } |
| 2856 | |
| 2857 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2858 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2859 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2860 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2861 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2862 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2863 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2864 | err = nl80211_parse_key(info, &key); |
| 2865 | if (err) |
| 2866 | return err; |
| 2867 | |
| 2868 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2869 | return -EINVAL; |
| 2870 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2871 | /* only support setting default key */ |
| 2872 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2873 | return -EINVAL; |
| 2874 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2875 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2876 | |
| 2877 | if (key.def) { |
| 2878 | if (!rdev->ops->set_default_key) { |
| 2879 | err = -EOPNOTSUPP; |
| 2880 | goto out; |
| 2881 | } |
| 2882 | |
| 2883 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2884 | if (err) |
| 2885 | goto out; |
| 2886 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2887 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2888 | key.def_uni, key.def_multi); |
| 2889 | |
| 2890 | if (err) |
| 2891 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2892 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2893 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2894 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2895 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2896 | } else { |
| 2897 | if (key.def_uni || !key.def_multi) { |
| 2898 | err = -EINVAL; |
| 2899 | goto out; |
| 2900 | } |
| 2901 | |
| 2902 | if (!rdev->ops->set_default_mgmt_key) { |
| 2903 | err = -EOPNOTSUPP; |
| 2904 | goto out; |
| 2905 | } |
| 2906 | |
| 2907 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2908 | if (err) |
| 2909 | goto out; |
| 2910 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2911 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2912 | if (err) |
| 2913 | goto out; |
| 2914 | |
| 2915 | #ifdef CONFIG_CFG80211_WEXT |
| 2916 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2917 | #endif |
| 2918 | } |
| 2919 | |
| 2920 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2921 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2922 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2923 | return err; |
| 2924 | } |
| 2925 | |
| 2926 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2927 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2928 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2929 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2930 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2931 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2932 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2933 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2934 | err = nl80211_parse_key(info, &key); |
| 2935 | if (err) |
| 2936 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2937 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2938 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2939 | return -EINVAL; |
| 2940 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2941 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2942 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2943 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2944 | if (key.type == -1) { |
| 2945 | if (mac_addr) |
| 2946 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2947 | else |
| 2948 | key.type = NL80211_KEYTYPE_GROUP; |
| 2949 | } |
| 2950 | |
| 2951 | /* for now */ |
| 2952 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2953 | key.type != NL80211_KEYTYPE_GROUP) |
| 2954 | return -EINVAL; |
| 2955 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2956 | if (!rdev->ops->add_key) |
| 2957 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2958 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2959 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2960 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2961 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2962 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2963 | |
| 2964 | wdev_lock(dev->ieee80211_ptr); |
| 2965 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2966 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2967 | err = rdev_add_key(rdev, dev, key.idx, |
| 2968 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2969 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2970 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2971 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2972 | return err; |
| 2973 | } |
| 2974 | |
| 2975 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2976 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2977 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2978 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2979 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2980 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2981 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2982 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2983 | err = nl80211_parse_key(info, &key); |
| 2984 | if (err) |
| 2985 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2986 | |
| 2987 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2988 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2989 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2990 | if (key.type == -1) { |
| 2991 | if (mac_addr) |
| 2992 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2993 | else |
| 2994 | key.type = NL80211_KEYTYPE_GROUP; |
| 2995 | } |
| 2996 | |
| 2997 | /* for now */ |
| 2998 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2999 | key.type != NL80211_KEYTYPE_GROUP) |
| 3000 | return -EINVAL; |
| 3001 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3002 | if (!rdev->ops->del_key) |
| 3003 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3004 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3005 | wdev_lock(dev->ieee80211_ptr); |
| 3006 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3007 | |
| 3008 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 3009 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3010 | err = -ENOENT; |
| 3011 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3012 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3013 | err = rdev_del_key(rdev, dev, key.idx, |
| 3014 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3015 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3016 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3017 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3018 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3019 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3020 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3021 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3022 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 3023 | } |
| 3024 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3025 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3026 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3027 | return err; |
| 3028 | } |
| 3029 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3030 | /* This function returns an error or the number of nested attributes */ |
| 3031 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 3032 | { |
| 3033 | struct nlattr *attr; |
| 3034 | int n_entries = 0, tmp; |
| 3035 | |
| 3036 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 3037 | if (nla_len(attr) != ETH_ALEN) |
| 3038 | return -EINVAL; |
| 3039 | |
| 3040 | n_entries++; |
| 3041 | } |
| 3042 | |
| 3043 | return n_entries; |
| 3044 | } |
| 3045 | |
| 3046 | /* |
| 3047 | * This function parses ACL information and allocates memory for ACL data. |
| 3048 | * On successful return, the calling function is responsible to free the |
| 3049 | * ACL buffer returned by this function. |
| 3050 | */ |
| 3051 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 3052 | struct genl_info *info) |
| 3053 | { |
| 3054 | enum nl80211_acl_policy acl_policy; |
| 3055 | struct nlattr *attr; |
| 3056 | struct cfg80211_acl_data *acl; |
| 3057 | int i = 0, n_entries, tmp; |
| 3058 | |
| 3059 | if (!wiphy->max_acl_mac_addrs) |
| 3060 | return ERR_PTR(-EOPNOTSUPP); |
| 3061 | |
| 3062 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 3063 | return ERR_PTR(-EINVAL); |
| 3064 | |
| 3065 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 3066 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 3067 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 3068 | return ERR_PTR(-EINVAL); |
| 3069 | |
| 3070 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 3071 | return ERR_PTR(-EINVAL); |
| 3072 | |
| 3073 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 3074 | if (n_entries < 0) |
| 3075 | return ERR_PTR(n_entries); |
| 3076 | |
| 3077 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 3078 | return ERR_PTR(-ENOTSUPP); |
| 3079 | |
| 3080 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 3081 | GFP_KERNEL); |
| 3082 | if (!acl) |
| 3083 | return ERR_PTR(-ENOMEM); |
| 3084 | |
| 3085 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 3086 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3087 | i++; |
| 3088 | } |
| 3089 | |
| 3090 | acl->n_acl_entries = n_entries; |
| 3091 | acl->acl_policy = acl_policy; |
| 3092 | |
| 3093 | return acl; |
| 3094 | } |
| 3095 | |
| 3096 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3097 | { |
| 3098 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3099 | struct net_device *dev = info->user_ptr[1]; |
| 3100 | struct cfg80211_acl_data *acl; |
| 3101 | int err; |
| 3102 | |
| 3103 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3104 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3105 | return -EOPNOTSUPP; |
| 3106 | |
| 3107 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3108 | return -EINVAL; |
| 3109 | |
| 3110 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3111 | if (IS_ERR(acl)) |
| 3112 | return PTR_ERR(acl); |
| 3113 | |
| 3114 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3115 | |
| 3116 | kfree(acl); |
| 3117 | |
| 3118 | return err; |
| 3119 | } |
| 3120 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3121 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3122 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3123 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3124 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3125 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3126 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3127 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3128 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3129 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3130 | return -EINVAL; |
| 3131 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3132 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3133 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3134 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3135 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3136 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3137 | if (!bcn->head_len) |
| 3138 | return -EINVAL; |
| 3139 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3140 | } |
| 3141 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3142 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3143 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3144 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3145 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3146 | } |
| 3147 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3148 | if (!haveinfo) |
| 3149 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3150 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3151 | if (attrs[NL80211_ATTR_IE]) { |
| 3152 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3153 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3154 | } |
| 3155 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3156 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3157 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3158 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3159 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3160 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3161 | } |
| 3162 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3163 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3164 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3165 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3166 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3167 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3168 | } |
| 3169 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3170 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3171 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3172 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3173 | } |
| 3174 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3175 | return 0; |
| 3176 | } |
| 3177 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3178 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3179 | struct cfg80211_ap_settings *params) |
| 3180 | { |
| 3181 | struct wireless_dev *wdev; |
| 3182 | bool ret = false; |
| 3183 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3184 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3185 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3186 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3187 | continue; |
| 3188 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3189 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3190 | continue; |
| 3191 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3192 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3193 | ret = true; |
| 3194 | break; |
| 3195 | } |
| 3196 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3197 | return ret; |
| 3198 | } |
| 3199 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3200 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3201 | enum nl80211_auth_type auth_type, |
| 3202 | enum nl80211_commands cmd) |
| 3203 | { |
| 3204 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3205 | return false; |
| 3206 | |
| 3207 | switch (cmd) { |
| 3208 | case NL80211_CMD_AUTHENTICATE: |
| 3209 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3210 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3211 | return false; |
| 3212 | return true; |
| 3213 | case NL80211_CMD_CONNECT: |
| 3214 | case NL80211_CMD_START_AP: |
| 3215 | /* SAE not supported yet */ |
| 3216 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3217 | return false; |
| 3218 | return true; |
| 3219 | default: |
| 3220 | return false; |
| 3221 | } |
| 3222 | } |
| 3223 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3224 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3225 | { |
| 3226 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3227 | struct net_device *dev = info->user_ptr[1]; |
| 3228 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3229 | struct cfg80211_ap_settings params; |
| 3230 | int err; |
| 3231 | |
| 3232 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3233 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3234 | return -EOPNOTSUPP; |
| 3235 | |
| 3236 | if (!rdev->ops->start_ap) |
| 3237 | return -EOPNOTSUPP; |
| 3238 | |
| 3239 | if (wdev->beacon_interval) |
| 3240 | return -EALREADY; |
| 3241 | |
| 3242 | memset(¶ms, 0, sizeof(params)); |
| 3243 | |
| 3244 | /* these are required for START_AP */ |
| 3245 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3246 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3247 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3248 | return -EINVAL; |
| 3249 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3250 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3251 | if (err) |
| 3252 | return err; |
| 3253 | |
| 3254 | params.beacon_interval = |
| 3255 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3256 | params.dtim_period = |
| 3257 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3258 | |
| 3259 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3260 | if (err) |
| 3261 | return err; |
| 3262 | |
| 3263 | /* |
| 3264 | * In theory, some of these attributes should be required here |
| 3265 | * but since they were not used when the command was originally |
| 3266 | * added, keep them optional for old user space programs to let |
| 3267 | * them continue to work with drivers that do not need the |
| 3268 | * additional information -- drivers must check! |
| 3269 | */ |
| 3270 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3271 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3272 | params.ssid_len = |
| 3273 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3274 | if (params.ssid_len == 0 || |
| 3275 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3276 | return -EINVAL; |
| 3277 | } |
| 3278 | |
| 3279 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3280 | params.hidden_ssid = nla_get_u32( |
| 3281 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3282 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3283 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3284 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3285 | return -EINVAL; |
| 3286 | } |
| 3287 | |
| 3288 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3289 | |
| 3290 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3291 | params.auth_type = nla_get_u32( |
| 3292 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3293 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3294 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3295 | return -EINVAL; |
| 3296 | } else |
| 3297 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3298 | |
| 3299 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3300 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3301 | if (err) |
| 3302 | return err; |
| 3303 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3304 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3305 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3306 | return -EOPNOTSUPP; |
| 3307 | params.inactivity_timeout = nla_get_u16( |
| 3308 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3309 | } |
| 3310 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3311 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3312 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3313 | return -EINVAL; |
| 3314 | params.p2p_ctwindow = |
| 3315 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3316 | if (params.p2p_ctwindow > 127) |
| 3317 | return -EINVAL; |
| 3318 | if (params.p2p_ctwindow != 0 && |
| 3319 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3320 | return -EINVAL; |
| 3321 | } |
| 3322 | |
| 3323 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3324 | u8 tmp; |
| 3325 | |
| 3326 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3327 | return -EINVAL; |
| 3328 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3329 | if (tmp > 1) |
| 3330 | return -EINVAL; |
| 3331 | params.p2p_opp_ps = tmp; |
| 3332 | if (params.p2p_opp_ps != 0 && |
| 3333 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3334 | return -EINVAL; |
| 3335 | } |
| 3336 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3337 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3338 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3339 | if (err) |
| 3340 | return err; |
| 3341 | } else if (wdev->preset_chandef.chan) { |
| 3342 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3343 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3344 | return -EINVAL; |
| 3345 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 3346 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
| 3347 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3348 | return -EINVAL; |
| 3349 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3350 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3351 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3352 | if (IS_ERR(params.acl)) |
| 3353 | return PTR_ERR(params.acl); |
| 3354 | } |
| 3355 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 3356 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 3357 | params.smps_mode = |
| 3358 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 3359 | switch (params.smps_mode) { |
| 3360 | case NL80211_SMPS_OFF: |
| 3361 | break; |
| 3362 | case NL80211_SMPS_STATIC: |
| 3363 | if (!(rdev->wiphy.features & |
| 3364 | NL80211_FEATURE_STATIC_SMPS)) |
| 3365 | return -EINVAL; |
| 3366 | break; |
| 3367 | case NL80211_SMPS_DYNAMIC: |
| 3368 | if (!(rdev->wiphy.features & |
| 3369 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 3370 | return -EINVAL; |
| 3371 | break; |
| 3372 | default: |
| 3373 | return -EINVAL; |
| 3374 | } |
| 3375 | } else { |
| 3376 | params.smps_mode = NL80211_SMPS_OFF; |
| 3377 | } |
| 3378 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3379 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3380 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3381 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3382 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3383 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 3384 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3385 | wdev->ssid_len = params.ssid_len; |
| 3386 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3387 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3388 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3389 | |
| 3390 | kfree(params.acl); |
| 3391 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3392 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3393 | } |
| 3394 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3395 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3396 | { |
| 3397 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3398 | struct net_device *dev = info->user_ptr[1]; |
| 3399 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3400 | struct cfg80211_beacon_data params; |
| 3401 | int err; |
| 3402 | |
| 3403 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3404 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3405 | return -EOPNOTSUPP; |
| 3406 | |
| 3407 | if (!rdev->ops->change_beacon) |
| 3408 | return -EOPNOTSUPP; |
| 3409 | |
| 3410 | if (!wdev->beacon_interval) |
| 3411 | return -EINVAL; |
| 3412 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3413 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3414 | if (err) |
| 3415 | return err; |
| 3416 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3417 | wdev_lock(wdev); |
| 3418 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 3419 | wdev_unlock(wdev); |
| 3420 | |
| 3421 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3422 | } |
| 3423 | |
| 3424 | 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] | 3425 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3426 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3427 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3428 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 3429 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3430 | } |
| 3431 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3432 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3433 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3434 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3435 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3436 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3437 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3438 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3439 | }; |
| 3440 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3441 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3442 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3443 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3444 | { |
| 3445 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3446 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3447 | int flag; |
| 3448 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3449 | /* |
| 3450 | * Try parsing the new attribute first so userspace |
| 3451 | * can specify both for older kernels. |
| 3452 | */ |
| 3453 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3454 | if (nla) { |
| 3455 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3456 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3457 | sta_flags = nla_data(nla); |
| 3458 | params->sta_flags_mask = sta_flags->mask; |
| 3459 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3460 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3461 | if ((params->sta_flags_mask | |
| 3462 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3463 | return -EINVAL; |
| 3464 | return 0; |
| 3465 | } |
| 3466 | |
| 3467 | /* if present, parse the old attribute */ |
| 3468 | |
| 3469 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3470 | if (!nla) |
| 3471 | return 0; |
| 3472 | |
| 3473 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3474 | nla, sta_flags_policy)) |
| 3475 | return -EINVAL; |
| 3476 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3477 | /* |
| 3478 | * Only allow certain flags for interface types so that |
| 3479 | * other attributes are silently ignored. Remember that |
| 3480 | * this is backward compatibility code with old userspace |
| 3481 | * and shouldn't be hit in other cases anyway. |
| 3482 | */ |
| 3483 | switch (iftype) { |
| 3484 | case NL80211_IFTYPE_AP: |
| 3485 | case NL80211_IFTYPE_AP_VLAN: |
| 3486 | case NL80211_IFTYPE_P2P_GO: |
| 3487 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3488 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3489 | BIT(NL80211_STA_FLAG_WME) | |
| 3490 | BIT(NL80211_STA_FLAG_MFP); |
| 3491 | break; |
| 3492 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3493 | case NL80211_IFTYPE_STATION: |
| 3494 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3495 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3496 | break; |
| 3497 | case NL80211_IFTYPE_MESH_POINT: |
| 3498 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3499 | BIT(NL80211_STA_FLAG_MFP) | |
| 3500 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3501 | default: |
| 3502 | return -EINVAL; |
| 3503 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3504 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3505 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3506 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3507 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3508 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3509 | /* no longer support new API additions in old API */ |
| 3510 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3511 | return -EINVAL; |
| 3512 | } |
| 3513 | } |
| 3514 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3515 | return 0; |
| 3516 | } |
| 3517 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3518 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3519 | int attr) |
| 3520 | { |
| 3521 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3522 | u32 bitrate; |
| 3523 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3524 | |
| 3525 | rate = nla_nest_start(msg, attr); |
| 3526 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3527 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3528 | |
| 3529 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3530 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3531 | /* report 16-bit bitrate only if we can */ |
| 3532 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3533 | if (bitrate > 0 && |
| 3534 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3535 | return false; |
| 3536 | if (bitrate_compat > 0 && |
| 3537 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3538 | return false; |
| 3539 | |
| 3540 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3541 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3542 | return false; |
| 3543 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3544 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3545 | return false; |
| 3546 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3547 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3548 | return false; |
| 3549 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3550 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3551 | return false; |
| 3552 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3553 | return false; |
| 3554 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3555 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3556 | return false; |
| 3557 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3558 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3559 | return false; |
| 3560 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3561 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3562 | return false; |
| 3563 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3564 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3565 | return false; |
| 3566 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3567 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3568 | return false; |
| 3569 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3570 | |
| 3571 | nla_nest_end(msg, rate); |
| 3572 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3573 | } |
| 3574 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3575 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3576 | int id) |
| 3577 | { |
| 3578 | void *attr; |
| 3579 | int i = 0; |
| 3580 | |
| 3581 | if (!mask) |
| 3582 | return true; |
| 3583 | |
| 3584 | attr = nla_nest_start(msg, id); |
| 3585 | if (!attr) |
| 3586 | return false; |
| 3587 | |
| 3588 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3589 | if (!(mask & BIT(i))) |
| 3590 | continue; |
| 3591 | |
| 3592 | if (nla_put_u8(msg, i, signal[i])) |
| 3593 | return false; |
| 3594 | } |
| 3595 | |
| 3596 | nla_nest_end(msg, attr); |
| 3597 | |
| 3598 | return true; |
| 3599 | } |
| 3600 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3601 | 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] | 3602 | int flags, |
| 3603 | struct cfg80211_registered_device *rdev, |
| 3604 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3605 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3606 | { |
| 3607 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3608 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3609 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3610 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3611 | if (!hdr) |
| 3612 | return -1; |
| 3613 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3614 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3615 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3616 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3617 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3618 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3619 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3620 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3621 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3622 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3623 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3624 | sinfo->connected_time)) |
| 3625 | goto nla_put_failure; |
| 3626 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3627 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3628 | sinfo->inactive_time)) |
| 3629 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3630 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3631 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3632 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3633 | (u32)sinfo->rx_bytes)) |
| 3634 | goto nla_put_failure; |
| 3635 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3636 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3637 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3638 | (u32)sinfo->tx_bytes)) |
| 3639 | goto nla_put_failure; |
| 3640 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3641 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3642 | sinfo->rx_bytes)) |
| 3643 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3644 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3645 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3646 | sinfo->tx_bytes)) |
| 3647 | goto nla_put_failure; |
| 3648 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3649 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3650 | goto nla_put_failure; |
| 3651 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3652 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3653 | goto nla_put_failure; |
| 3654 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3655 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3656 | sinfo->plink_state)) |
| 3657 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3658 | switch (rdev->wiphy.signal_type) { |
| 3659 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3660 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3661 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3662 | sinfo->signal)) |
| 3663 | goto nla_put_failure; |
| 3664 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3665 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3666 | sinfo->signal_avg)) |
| 3667 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3668 | break; |
| 3669 | default: |
| 3670 | break; |
| 3671 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3672 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3673 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3674 | sinfo->chain_signal, |
| 3675 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3676 | goto nla_put_failure; |
| 3677 | } |
| 3678 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3679 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3680 | sinfo->chain_signal_avg, |
| 3681 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3682 | goto nla_put_failure; |
| 3683 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3684 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3685 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3686 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3687 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3688 | } |
| 3689 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3690 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3691 | NL80211_STA_INFO_RX_BITRATE)) |
| 3692 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3693 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3694 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3695 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3696 | sinfo->rx_packets)) |
| 3697 | goto nla_put_failure; |
| 3698 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3699 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3700 | sinfo->tx_packets)) |
| 3701 | goto nla_put_failure; |
| 3702 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3703 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3704 | sinfo->tx_retries)) |
| 3705 | goto nla_put_failure; |
| 3706 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3707 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3708 | sinfo->tx_failed)) |
| 3709 | goto nla_put_failure; |
Antonio Quartulli | 867d849 | 2014-05-19 21:53:19 +0200 | [diff] [blame] | 3710 | if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) && |
| 3711 | nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT, |
| 3712 | sinfo->expected_throughput)) |
| 3713 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3714 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3715 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3716 | sinfo->beacon_loss_count)) |
| 3717 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3718 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3719 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3720 | sinfo->local_pm)) |
| 3721 | goto nla_put_failure; |
| 3722 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3723 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3724 | sinfo->peer_pm)) |
| 3725 | goto nla_put_failure; |
| 3726 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3727 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3728 | sinfo->nonpeer_pm)) |
| 3729 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3730 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3731 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3732 | if (!bss_param) |
| 3733 | goto nla_put_failure; |
| 3734 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3735 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3736 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3737 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3738 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3739 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3740 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3741 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3742 | sinfo->bss_param.dtim_period) || |
| 3743 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3744 | sinfo->bss_param.beacon_interval)) |
| 3745 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3746 | |
| 3747 | nla_nest_end(msg, bss_param); |
| 3748 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3749 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3750 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3751 | sizeof(struct nl80211_sta_flag_update), |
| 3752 | &sinfo->sta_flags)) |
| 3753 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3754 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3755 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3756 | sinfo->t_offset)) |
| 3757 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3758 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3759 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3760 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3761 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3762 | sinfo->assoc_req_ies)) |
| 3763 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3764 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3765 | return genlmsg_end(msg, hdr); |
| 3766 | |
| 3767 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3768 | genlmsg_cancel(msg, hdr); |
| 3769 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3770 | } |
| 3771 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3772 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3773 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3774 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3775 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3776 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3777 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3778 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3779 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3780 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3781 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3782 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3783 | if (err) |
| 3784 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3785 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3786 | if (!wdev->netdev) { |
| 3787 | err = -EINVAL; |
| 3788 | goto out_err; |
| 3789 | } |
| 3790 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3791 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3792 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3793 | goto out_err; |
| 3794 | } |
| 3795 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3796 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3797 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3798 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3799 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3800 | if (err == -ENOENT) |
| 3801 | break; |
| 3802 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3803 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3804 | |
| 3805 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3806 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3807 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3808 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3809 | &sinfo) < 0) |
| 3810 | goto out; |
| 3811 | |
| 3812 | sta_idx++; |
| 3813 | } |
| 3814 | |
| 3815 | |
| 3816 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3817 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3818 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3819 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3820 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3821 | |
| 3822 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3823 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3824 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3825 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3826 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3827 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3828 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3829 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3830 | struct sk_buff *msg; |
| 3831 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3832 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3833 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3834 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3835 | |
| 3836 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3837 | return -EINVAL; |
| 3838 | |
| 3839 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3840 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3841 | if (!rdev->ops->get_station) |
| 3842 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3843 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3844 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3845 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3846 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3847 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3848 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3849 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3850 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3851 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3852 | 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] | 3853 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3854 | nlmsg_free(msg); |
| 3855 | return -ENOBUFS; |
| 3856 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3857 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3858 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3859 | } |
| 3860 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3861 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3862 | struct station_parameters *params, |
| 3863 | enum cfg80211_station_type statype) |
| 3864 | { |
| 3865 | if (params->listen_interval != -1) |
| 3866 | return -EINVAL; |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 3867 | if (params->aid && |
| 3868 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3869 | return -EINVAL; |
| 3870 | |
| 3871 | /* When you run into this, adjust the code below for the new flag */ |
| 3872 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3873 | |
| 3874 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3875 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3876 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3877 | /* |
| 3878 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3879 | * code doesn't have the bug of including TDLS in the |
| 3880 | * mask everywhere. |
| 3881 | */ |
| 3882 | if (params->sta_flags_mask & |
| 3883 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3884 | BIT(NL80211_STA_FLAG_MFP) | |
| 3885 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3886 | return -EINVAL; |
| 3887 | break; |
| 3888 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3889 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3890 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3891 | return -EINVAL; |
| 3892 | /* ignore since it can't change */ |
| 3893 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3894 | break; |
| 3895 | default: |
| 3896 | /* disallow mesh-specific things */ |
| 3897 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3898 | return -EINVAL; |
| 3899 | if (params->local_pm) |
| 3900 | return -EINVAL; |
| 3901 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3902 | return -EINVAL; |
| 3903 | } |
| 3904 | |
| 3905 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3906 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3907 | /* TDLS can't be set, ... */ |
| 3908 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3909 | return -EINVAL; |
| 3910 | /* |
| 3911 | * ... but don't bother the driver with it. This works around |
| 3912 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3913 | * TLDS_PEER flag in the mask even for AP mode. |
| 3914 | */ |
| 3915 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3916 | } |
| 3917 | |
| 3918 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3919 | /* reject other things that can't change */ |
| 3920 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3921 | return -EINVAL; |
| 3922 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3923 | return -EINVAL; |
| 3924 | if (params->supported_rates) |
| 3925 | return -EINVAL; |
| 3926 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3927 | return -EINVAL; |
| 3928 | } |
| 3929 | |
| 3930 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3931 | if (params->vlan) |
| 3932 | return -EINVAL; |
| 3933 | } |
| 3934 | |
| 3935 | switch (statype) { |
| 3936 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3937 | /* Use this only for authorizing/unauthorizing a station */ |
| 3938 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3939 | return -EOPNOTSUPP; |
| 3940 | break; |
| 3941 | case CFG80211_STA_AP_CLIENT: |
| 3942 | /* accept only the listed bits */ |
| 3943 | if (params->sta_flags_mask & |
| 3944 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3945 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3946 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3947 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3948 | BIT(NL80211_STA_FLAG_WME) | |
| 3949 | BIT(NL80211_STA_FLAG_MFP))) |
| 3950 | return -EINVAL; |
| 3951 | |
| 3952 | /* but authenticated/associated only if driver handles it */ |
| 3953 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3954 | params->sta_flags_mask & |
| 3955 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3956 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3957 | return -EINVAL; |
| 3958 | break; |
| 3959 | case CFG80211_STA_IBSS: |
| 3960 | case CFG80211_STA_AP_STA: |
| 3961 | /* reject any changes other than AUTHORIZED */ |
| 3962 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3963 | return -EINVAL; |
| 3964 | break; |
| 3965 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3966 | /* reject any changes other than AUTHORIZED or WME */ |
| 3967 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3968 | BIT(NL80211_STA_FLAG_WME))) |
| 3969 | return -EINVAL; |
| 3970 | /* force (at least) rates when authorizing */ |
| 3971 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3972 | !params->supported_rates) |
| 3973 | return -EINVAL; |
| 3974 | break; |
| 3975 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3976 | /* reject any changes */ |
| 3977 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3978 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3979 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3980 | return -EINVAL; |
| 3981 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3982 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3983 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3984 | return -EINVAL; |
| 3985 | break; |
| 3986 | } |
| 3987 | |
| 3988 | return 0; |
| 3989 | } |
| 3990 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3991 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3992 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3993 | * 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] | 3994 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3995 | static struct net_device *get_vlan(struct genl_info *info, |
| 3996 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3997 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3998 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3999 | struct net_device *v; |
| 4000 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4001 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4002 | if (!vlanattr) |
| 4003 | return NULL; |
| 4004 | |
| 4005 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 4006 | if (!v) |
| 4007 | return ERR_PTR(-ENODEV); |
| 4008 | |
| 4009 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 4010 | ret = -EINVAL; |
| 4011 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4012 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4013 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4014 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 4015 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4016 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 4017 | ret = -EINVAL; |
| 4018 | goto error; |
| 4019 | } |
| 4020 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 4021 | if (!netif_running(v)) { |
| 4022 | ret = -ENETDOWN; |
| 4023 | goto error; |
| 4024 | } |
| 4025 | |
| 4026 | return v; |
| 4027 | error: |
| 4028 | dev_put(v); |
| 4029 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4030 | } |
| 4031 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 4032 | static const struct nla_policy |
| 4033 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4034 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 4035 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 4036 | }; |
| 4037 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4038 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 4039 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4040 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4041 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 4042 | struct nlattr *nla; |
| 4043 | int err; |
| 4044 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4045 | /* parse WME attributes if present */ |
| 4046 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 4047 | return 0; |
| 4048 | |
| 4049 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 4050 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 4051 | nl80211_sta_wme_policy); |
| 4052 | if (err) |
| 4053 | return err; |
| 4054 | |
| 4055 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 4056 | params->uapsd_queues = nla_get_u8( |
| 4057 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 4058 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 4059 | return -EINVAL; |
| 4060 | |
| 4061 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 4062 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 4063 | |
| 4064 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 4065 | return -EINVAL; |
| 4066 | |
| 4067 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 4068 | |
| 4069 | return 0; |
| 4070 | } |
| 4071 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4072 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 4073 | struct station_parameters *params) |
| 4074 | { |
| 4075 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 4076 | params->supported_channels = |
| 4077 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4078 | params->supported_channels_len = |
| 4079 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4080 | /* |
| 4081 | * Need to include at least one (first channel, number of |
| 4082 | * channels) tuple for each subband, and must have proper |
| 4083 | * tuples for the rest of the data as well. |
| 4084 | */ |
| 4085 | if (params->supported_channels_len < 2) |
| 4086 | return -EINVAL; |
| 4087 | if (params->supported_channels_len % 2) |
| 4088 | return -EINVAL; |
| 4089 | } |
| 4090 | |
| 4091 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 4092 | params->supported_oper_classes = |
| 4093 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4094 | params->supported_oper_classes_len = |
| 4095 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4096 | /* |
| 4097 | * The value of the Length field of the Supported Operating |
| 4098 | * Classes element is between 2 and 253. |
| 4099 | */ |
| 4100 | if (params->supported_oper_classes_len < 2 || |
| 4101 | params->supported_oper_classes_len > 253) |
| 4102 | return -EINVAL; |
| 4103 | } |
| 4104 | return 0; |
| 4105 | } |
| 4106 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4107 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4108 | struct station_parameters *params) |
| 4109 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4110 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4111 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4112 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4113 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4114 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4115 | params->ht_capa = |
| 4116 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4117 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4118 | params->vht_capa = |
| 4119 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4120 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4121 | err = nl80211_parse_sta_channel_info(info, params); |
| 4122 | if (err) |
| 4123 | return err; |
| 4124 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4125 | return nl80211_parse_sta_wme(info, params); |
| 4126 | } |
| 4127 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4128 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4129 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4130 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4131 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4132 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4133 | u8 *mac_addr; |
| 4134 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4135 | |
| 4136 | memset(¶ms, 0, sizeof(params)); |
| 4137 | |
| 4138 | params.listen_interval = -1; |
| 4139 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4140 | if (!rdev->ops->change_station) |
| 4141 | return -EOPNOTSUPP; |
| 4142 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4143 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4144 | return -EINVAL; |
| 4145 | |
| 4146 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4147 | return -EINVAL; |
| 4148 | |
| 4149 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4150 | |
| 4151 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4152 | params.supported_rates = |
| 4153 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4154 | params.supported_rates_len = |
| 4155 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4156 | } |
| 4157 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4158 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4159 | params.capability = |
| 4160 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4161 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4162 | } |
| 4163 | |
| 4164 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4165 | params.ext_capab = |
| 4166 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4167 | params.ext_capab_len = |
| 4168 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4169 | } |
| 4170 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4171 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 4172 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4173 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4174 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4175 | return -EINVAL; |
| 4176 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4177 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4178 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4179 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4180 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4181 | return -EINVAL; |
| 4182 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4183 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4184 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4185 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4186 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4187 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4188 | return -EINVAL; |
| 4189 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4190 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4191 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4192 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4193 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4194 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4195 | |
| 4196 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4197 | pm > NL80211_MESH_POWER_MAX) |
| 4198 | return -EINVAL; |
| 4199 | |
| 4200 | params.local_pm = pm; |
| 4201 | } |
| 4202 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4203 | /* Include parameters for TDLS peer (will check later) */ |
| 4204 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4205 | if (err) |
| 4206 | return err; |
| 4207 | |
| 4208 | params.vlan = get_vlan(info, rdev); |
| 4209 | if (IS_ERR(params.vlan)) |
| 4210 | return PTR_ERR(params.vlan); |
| 4211 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4212 | switch (dev->ieee80211_ptr->iftype) { |
| 4213 | case NL80211_IFTYPE_AP: |
| 4214 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4215 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4216 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4217 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4218 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4219 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4220 | break; |
| 4221 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4222 | err = -EOPNOTSUPP; |
| 4223 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4224 | } |
| 4225 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4226 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4227 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4228 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4229 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4230 | if (params.vlan) |
| 4231 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4232 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4233 | return err; |
| 4234 | } |
| 4235 | |
| 4236 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4237 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4238 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4239 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4240 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4241 | struct station_parameters params; |
| 4242 | u8 *mac_addr = NULL; |
| 4243 | |
| 4244 | memset(¶ms, 0, sizeof(params)); |
| 4245 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4246 | if (!rdev->ops->add_station) |
| 4247 | return -EOPNOTSUPP; |
| 4248 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4249 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4250 | return -EINVAL; |
| 4251 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4252 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4253 | return -EINVAL; |
| 4254 | |
| 4255 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4256 | return -EINVAL; |
| 4257 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4258 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4259 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4260 | return -EINVAL; |
| 4261 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4262 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4263 | params.supported_rates = |
| 4264 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4265 | params.supported_rates_len = |
| 4266 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4267 | params.listen_interval = |
| 4268 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4269 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4270 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4271 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4272 | else |
| 4273 | 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] | 4274 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4275 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4276 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4277 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4278 | params.capability = |
| 4279 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4280 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4281 | } |
| 4282 | |
| 4283 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4284 | params.ext_capab = |
| 4285 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4286 | params.ext_capab_len = |
| 4287 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4288 | } |
| 4289 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4290 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4291 | params.ht_capa = |
| 4292 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4293 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4294 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4295 | params.vht_capa = |
| 4296 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4297 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4298 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4299 | params.opmode_notif_used = true; |
| 4300 | params.opmode_notif = |
| 4301 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4302 | } |
| 4303 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4304 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4305 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4306 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4307 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4308 | return -EINVAL; |
| 4309 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4310 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4311 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4312 | if (err) |
| 4313 | return err; |
| 4314 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4315 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4316 | if (err) |
| 4317 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4318 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4319 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4320 | return -EINVAL; |
| 4321 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4322 | /* When you run into this, adjust the code below for the new flag */ |
| 4323 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4324 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4325 | switch (dev->ieee80211_ptr->iftype) { |
| 4326 | case NL80211_IFTYPE_AP: |
| 4327 | case NL80211_IFTYPE_AP_VLAN: |
| 4328 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4329 | /* ignore WME attributes if iface/sta is not capable */ |
| 4330 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4331 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4332 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4333 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4334 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4335 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4336 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4337 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4338 | /* but don't bother the driver with it */ |
| 4339 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4340 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4341 | /* allow authenticated/associated only if driver handles it */ |
| 4342 | if (!(rdev->wiphy.features & |
| 4343 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4344 | params.sta_flags_mask & |
| 4345 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4346 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4347 | return -EINVAL; |
| 4348 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4349 | /* must be last in here for error handling */ |
| 4350 | params.vlan = get_vlan(info, rdev); |
| 4351 | if (IS_ERR(params.vlan)) |
| 4352 | return PTR_ERR(params.vlan); |
| 4353 | break; |
| 4354 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4355 | /* ignore uAPSD data */ |
| 4356 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4357 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4358 | /* associated is disallowed */ |
| 4359 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4360 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4361 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4362 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4363 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4364 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4365 | break; |
| 4366 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4367 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4368 | /* ignore uAPSD data */ |
| 4369 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4370 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4371 | /* these are disallowed */ |
| 4372 | if (params.sta_flags_mask & |
| 4373 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4374 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4375 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4376 | /* Only TDLS peers can be added */ |
| 4377 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4378 | return -EINVAL; |
| 4379 | /* Can only add if TDLS ... */ |
| 4380 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4381 | return -EOPNOTSUPP; |
| 4382 | /* ... with external setup is supported */ |
| 4383 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4384 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4385 | /* |
| 4386 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4387 | * as authorized, but it shouldn't yet be. |
| 4388 | */ |
| 4389 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4390 | break; |
| 4391 | default: |
| 4392 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4393 | } |
| 4394 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4395 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4396 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4397 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4398 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4399 | if (params.vlan) |
| 4400 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4401 | return err; |
| 4402 | } |
| 4403 | |
| 4404 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4405 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4406 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4407 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4408 | struct station_del_parameters params; |
| 4409 | |
| 4410 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4411 | |
| 4412 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4413 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4414 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4415 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4416 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4417 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4418 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4419 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4420 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4421 | if (!rdev->ops->del_station) |
| 4422 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4423 | |
Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 4424 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 4425 | params.subtype = |
| 4426 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 4427 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 4428 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 4429 | return -EINVAL; |
| 4430 | } else { |
| 4431 | /* Default to Deauthentication frame */ |
| 4432 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 4433 | } |
| 4434 | |
| 4435 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 4436 | params.reason_code = |
| 4437 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4438 | if (params.reason_code == 0) |
| 4439 | return -EINVAL; /* 0 is reserved */ |
| 4440 | } else { |
| 4441 | /* Default to reason code 2 */ |
| 4442 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 4443 | } |
| 4444 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 4445 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4446 | } |
| 4447 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4448 | 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] | 4449 | int flags, struct net_device *dev, |
| 4450 | u8 *dst, u8 *next_hop, |
| 4451 | struct mpath_info *pinfo) |
| 4452 | { |
| 4453 | void *hdr; |
| 4454 | struct nlattr *pinfoattr; |
| 4455 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4456 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4457 | if (!hdr) |
| 4458 | return -1; |
| 4459 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4460 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4461 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4462 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4463 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4464 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4465 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4466 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4467 | if (!pinfoattr) |
| 4468 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4469 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4470 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4471 | pinfo->frame_qlen)) |
| 4472 | goto nla_put_failure; |
| 4473 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4474 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4475 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4476 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4477 | pinfo->metric)) || |
| 4478 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4479 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4480 | pinfo->exptime)) || |
| 4481 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4482 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4483 | pinfo->flags)) || |
| 4484 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4485 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4486 | pinfo->discovery_timeout)) || |
| 4487 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4488 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4489 | pinfo->discovery_retries))) |
| 4490 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4491 | |
| 4492 | nla_nest_end(msg, pinfoattr); |
| 4493 | |
| 4494 | return genlmsg_end(msg, hdr); |
| 4495 | |
| 4496 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4497 | genlmsg_cancel(msg, hdr); |
| 4498 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4499 | } |
| 4500 | |
| 4501 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4502 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4503 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4504 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4505 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4506 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4507 | u8 dst[ETH_ALEN]; |
| 4508 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4509 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4510 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4511 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4512 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4513 | if (err) |
| 4514 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4515 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4516 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4517 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4518 | goto out_err; |
| 4519 | } |
| 4520 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4521 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4522 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4523 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4524 | } |
| 4525 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4526 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4527 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4528 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4529 | if (err == -ENOENT) |
| 4530 | break; |
| 4531 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4532 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4533 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4534 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4535 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4536 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4537 | &pinfo) < 0) |
| 4538 | goto out; |
| 4539 | |
| 4540 | path_idx++; |
| 4541 | } |
| 4542 | |
| 4543 | |
| 4544 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4545 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4546 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4547 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4548 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4549 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4550 | } |
| 4551 | |
| 4552 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4553 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4554 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4555 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4556 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4557 | struct mpath_info pinfo; |
| 4558 | struct sk_buff *msg; |
| 4559 | u8 *dst = NULL; |
| 4560 | u8 next_hop[ETH_ALEN]; |
| 4561 | |
| 4562 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4563 | |
| 4564 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4565 | return -EINVAL; |
| 4566 | |
| 4567 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4568 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4569 | if (!rdev->ops->get_mpath) |
| 4570 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4571 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4572 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4573 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4574 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4575 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4576 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4577 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4578 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4579 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4580 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4581 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4582 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4583 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4584 | dev, dst, next_hop, &pinfo) < 0) { |
| 4585 | nlmsg_free(msg); |
| 4586 | return -ENOBUFS; |
| 4587 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4588 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4589 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4590 | } |
| 4591 | |
| 4592 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4593 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4594 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4595 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4596 | u8 *dst = NULL; |
| 4597 | u8 *next_hop = NULL; |
| 4598 | |
| 4599 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4600 | return -EINVAL; |
| 4601 | |
| 4602 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4603 | return -EINVAL; |
| 4604 | |
| 4605 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4606 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4607 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4608 | if (!rdev->ops->change_mpath) |
| 4609 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4610 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4611 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4612 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4613 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4614 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4615 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4616 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4617 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4618 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4619 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4620 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4621 | u8 *dst = NULL; |
| 4622 | u8 *next_hop = NULL; |
| 4623 | |
| 4624 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4625 | return -EINVAL; |
| 4626 | |
| 4627 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4628 | return -EINVAL; |
| 4629 | |
| 4630 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4631 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4632 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4633 | if (!rdev->ops->add_mpath) |
| 4634 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4635 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4636 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4637 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4638 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4639 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4640 | } |
| 4641 | |
| 4642 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4643 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4644 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4645 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4646 | u8 *dst = NULL; |
| 4647 | |
| 4648 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4649 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4650 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4651 | if (!rdev->ops->del_mpath) |
| 4652 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4653 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4654 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4655 | } |
| 4656 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 4657 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 4658 | { |
| 4659 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4660 | int err; |
| 4661 | struct net_device *dev = info->user_ptr[1]; |
| 4662 | struct mpath_info pinfo; |
| 4663 | struct sk_buff *msg; |
| 4664 | u8 *dst = NULL; |
| 4665 | u8 mpp[ETH_ALEN]; |
| 4666 | |
| 4667 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4668 | |
| 4669 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4670 | return -EINVAL; |
| 4671 | |
| 4672 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4673 | |
| 4674 | if (!rdev->ops->get_mpp) |
| 4675 | return -EOPNOTSUPP; |
| 4676 | |
| 4677 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4678 | return -EOPNOTSUPP; |
| 4679 | |
| 4680 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 4681 | if (err) |
| 4682 | return err; |
| 4683 | |
| 4684 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 4685 | if (!msg) |
| 4686 | return -ENOMEM; |
| 4687 | |
| 4688 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 4689 | dev, dst, mpp, &pinfo) < 0) { |
| 4690 | nlmsg_free(msg); |
| 4691 | return -ENOBUFS; |
| 4692 | } |
| 4693 | |
| 4694 | return genlmsg_reply(msg, info); |
| 4695 | } |
| 4696 | |
| 4697 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 4698 | struct netlink_callback *cb) |
| 4699 | { |
| 4700 | struct mpath_info pinfo; |
| 4701 | struct cfg80211_registered_device *rdev; |
| 4702 | struct wireless_dev *wdev; |
| 4703 | u8 dst[ETH_ALEN]; |
| 4704 | u8 mpp[ETH_ALEN]; |
| 4705 | int path_idx = cb->args[2]; |
| 4706 | int err; |
| 4707 | |
| 4708 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
| 4709 | if (err) |
| 4710 | return err; |
| 4711 | |
| 4712 | if (!rdev->ops->dump_mpp) { |
| 4713 | err = -EOPNOTSUPP; |
| 4714 | goto out_err; |
| 4715 | } |
| 4716 | |
| 4717 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 4718 | err = -EOPNOTSUPP; |
| 4719 | goto out_err; |
| 4720 | } |
| 4721 | |
| 4722 | while (1) { |
| 4723 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 4724 | mpp, &pinfo); |
| 4725 | if (err == -ENOENT) |
| 4726 | break; |
| 4727 | if (err) |
| 4728 | goto out_err; |
| 4729 | |
| 4730 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 4731 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 4732 | wdev->netdev, dst, mpp, |
| 4733 | &pinfo) < 0) |
| 4734 | goto out; |
| 4735 | |
| 4736 | path_idx++; |
| 4737 | } |
| 4738 | |
| 4739 | out: |
| 4740 | cb->args[2] = path_idx; |
| 4741 | err = skb->len; |
| 4742 | out_err: |
| 4743 | nl80211_finish_wdev_dump(rdev); |
| 4744 | return err; |
| 4745 | } |
| 4746 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4747 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4748 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4749 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4750 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4751 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4752 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4753 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4754 | |
| 4755 | memset(¶ms, 0, sizeof(params)); |
| 4756 | /* default to not changing parameters */ |
| 4757 | params.use_cts_prot = -1; |
| 4758 | params.use_short_preamble = -1; |
| 4759 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4760 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4761 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4762 | params.p2p_ctwindow = -1; |
| 4763 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4764 | |
| 4765 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4766 | params.use_cts_prot = |
| 4767 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4768 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4769 | params.use_short_preamble = |
| 4770 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4771 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4772 | params.use_short_slot_time = |
| 4773 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4774 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4775 | params.basic_rates = |
| 4776 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4777 | params.basic_rates_len = |
| 4778 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4779 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4780 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4781 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4782 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4783 | params.ht_opmode = |
| 4784 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4785 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4786 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4787 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4788 | return -EINVAL; |
| 4789 | params.p2p_ctwindow = |
| 4790 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4791 | if (params.p2p_ctwindow < 0) |
| 4792 | return -EINVAL; |
| 4793 | if (params.p2p_ctwindow != 0 && |
| 4794 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4795 | return -EINVAL; |
| 4796 | } |
| 4797 | |
| 4798 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4799 | u8 tmp; |
| 4800 | |
| 4801 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4802 | return -EINVAL; |
| 4803 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4804 | if (tmp > 1) |
| 4805 | return -EINVAL; |
| 4806 | params.p2p_opp_ps = tmp; |
| 4807 | if (params.p2p_opp_ps && |
| 4808 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4809 | return -EINVAL; |
| 4810 | } |
| 4811 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4812 | if (!rdev->ops->change_bss) |
| 4813 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4814 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4815 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4816 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4817 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4818 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4819 | wdev_lock(wdev); |
| 4820 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 4821 | wdev_unlock(wdev); |
| 4822 | |
| 4823 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4824 | } |
| 4825 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4826 | 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] | 4827 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4828 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4829 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4830 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4831 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4832 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4833 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4834 | }; |
| 4835 | |
| 4836 | static int parse_reg_rule(struct nlattr *tb[], |
| 4837 | struct ieee80211_reg_rule *reg_rule) |
| 4838 | { |
| 4839 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4840 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4841 | |
| 4842 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4843 | return -EINVAL; |
| 4844 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4845 | return -EINVAL; |
| 4846 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4847 | return -EINVAL; |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4848 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4849 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4850 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4851 | return -EINVAL; |
| 4852 | |
| 4853 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4854 | |
| 4855 | freq_range->start_freq_khz = |
| 4856 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4857 | freq_range->end_freq_khz = |
| 4858 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4859 | freq_range->max_bandwidth_khz = |
| 4860 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4861 | |
| 4862 | power_rule->max_eirp = |
| 4863 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4864 | |
| 4865 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4866 | power_rule->max_antenna_gain = |
| 4867 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4868 | |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4869 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 4870 | reg_rule->dfs_cac_ms = |
| 4871 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 4872 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4873 | return 0; |
| 4874 | } |
| 4875 | |
| 4876 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4877 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4878 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4879 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4880 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4881 | /* |
| 4882 | * You should only get this when cfg80211 hasn't yet initialized |
| 4883 | * completely when built-in to the kernel right between the time |
| 4884 | * window between nl80211_init() and regulatory_init(), if that is |
| 4885 | * even possible. |
| 4886 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4887 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4888 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4889 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4890 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4891 | user_reg_hint_type = |
| 4892 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4893 | else |
| 4894 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4895 | |
| 4896 | switch (user_reg_hint_type) { |
| 4897 | case NL80211_USER_REG_HINT_USER: |
| 4898 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 4899 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4900 | return -EINVAL; |
| 4901 | |
| 4902 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4903 | return regulatory_hint_user(data, user_reg_hint_type); |
| 4904 | case NL80211_USER_REG_HINT_INDOOR: |
| 4905 | return regulatory_hint_indoor_user(); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4906 | default: |
| 4907 | return -EINVAL; |
| 4908 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4909 | } |
| 4910 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4911 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4912 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4913 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4914 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4915 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4916 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4917 | struct mesh_config cur_params; |
| 4918 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4919 | void *hdr; |
| 4920 | struct nlattr *pinfoattr; |
| 4921 | struct sk_buff *msg; |
| 4922 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4923 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4924 | return -EOPNOTSUPP; |
| 4925 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4926 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4927 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4928 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4929 | wdev_lock(wdev); |
| 4930 | /* If not connected, get default parameters */ |
| 4931 | if (!wdev->mesh_id_len) |
| 4932 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4933 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4934 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4935 | wdev_unlock(wdev); |
| 4936 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4937 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4938 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4939 | |
| 4940 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4941 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4942 | if (!msg) |
| 4943 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4944 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4945 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4946 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4947 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4948 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4949 | if (!pinfoattr) |
| 4950 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4951 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4952 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4953 | cur_params.dot11MeshRetryTimeout) || |
| 4954 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4955 | cur_params.dot11MeshConfirmTimeout) || |
| 4956 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4957 | cur_params.dot11MeshHoldingTimeout) || |
| 4958 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4959 | cur_params.dot11MeshMaxPeerLinks) || |
| 4960 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4961 | cur_params.dot11MeshMaxRetries) || |
| 4962 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4963 | cur_params.dot11MeshTTL) || |
| 4964 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4965 | cur_params.element_ttl) || |
| 4966 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4967 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4968 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4969 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4970 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4971 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4972 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4973 | cur_params.path_refresh_time) || |
| 4974 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4975 | cur_params.min_discovery_timeout) || |
| 4976 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4977 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4978 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4979 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4980 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4981 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4982 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4983 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4984 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4985 | cur_params.dot11MeshHWMPRootMode) || |
| 4986 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4987 | cur_params.dot11MeshHWMPRannInterval) || |
| 4988 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4989 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4990 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4991 | cur_params.dot11MeshForwarding) || |
| 4992 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4993 | cur_params.rssi_threshold) || |
| 4994 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4995 | cur_params.ht_opmode) || |
| 4996 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4997 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4998 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4999 | cur_params.dot11MeshHWMProotInterval) || |
| 5000 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5001 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 5002 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 5003 | cur_params.power_mode) || |
| 5004 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5005 | cur_params.dot11MeshAwakeWindowDuration) || |
| 5006 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5007 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5008 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5009 | nla_nest_end(msg, pinfoattr); |
| 5010 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5011 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5012 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5013 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5014 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5015 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5016 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5017 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5018 | } |
| 5019 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 5020 | 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] | 5021 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 5022 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 5023 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 5024 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 5025 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 5026 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 5027 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5028 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5029 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5030 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 5031 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 5032 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 5033 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 5034 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5035 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5036 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 5037 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 5038 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 5039 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 5040 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5041 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 5042 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5043 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 5044 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5045 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5046 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 5047 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5048 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5049 | }; |
| 5050 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5051 | static const struct nla_policy |
| 5052 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5053 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5054 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 5055 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 5056 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5057 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5058 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5059 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5060 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5061 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5062 | }; |
| 5063 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5064 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5065 | struct mesh_config *cfg, |
| 5066 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5067 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5068 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5069 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5070 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5071 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 5072 | do { \ |
| 5073 | if (tb[attr]) { \ |
| 5074 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 5075 | return -EINVAL; \ |
| 5076 | cfg->param = fn(tb[attr]); \ |
| 5077 | mask |= (1 << (attr - 1)); \ |
| 5078 | } \ |
| 5079 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5080 | |
| 5081 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5082 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5083 | return -EINVAL; |
| 5084 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5085 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5086 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5087 | return -EINVAL; |
| 5088 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5089 | /* This makes sure that there aren't more than 32 mesh config |
| 5090 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 5091 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 5092 | |
| 5093 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5094 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5095 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 5096 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5097 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5098 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 5099 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5100 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5101 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 5102 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5103 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5104 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 5105 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5106 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5107 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 5108 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5109 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5110 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5111 | 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] | 5112 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 5113 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5114 | 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] | 5115 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 5116 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5117 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 5118 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5119 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 5120 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5121 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5122 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 5123 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5124 | 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] | 5125 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 5126 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5127 | 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] | 5128 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 5129 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5130 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 5131 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5132 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 5133 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5134 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5135 | 1, 65535, mask, |
| 5136 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5137 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 5138 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5139 | 1, 65535, mask, |
| 5140 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5141 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5142 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5143 | dot11MeshHWMPnetDiameterTraversalTime, |
| 5144 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5145 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5146 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5147 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 5148 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5149 | nla_get_u8); |
| 5150 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 5151 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5152 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 5153 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5154 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 5155 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5156 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5157 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5158 | mask, NL80211_MESHCONF_FORWARDING, |
| 5159 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5160 | 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] | 5161 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5162 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5163 | 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] | 5164 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 5165 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5166 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5167 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5168 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5169 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5170 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5171 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 5172 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5173 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5174 | dot11MeshHWMPconfirmationInterval, |
| 5175 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5176 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 5177 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5178 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 5179 | NL80211_MESH_POWER_ACTIVE, |
| 5180 | NL80211_MESH_POWER_MAX, |
| 5181 | mask, NL80211_MESHCONF_POWER_MODE, |
| 5182 | nla_get_u32); |
| 5183 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 5184 | 0, 65535, mask, |
| 5185 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5186 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 5187 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5188 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5189 | if (mask_out) |
| 5190 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5191 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5192 | return 0; |
| 5193 | |
| 5194 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 5195 | } |
| 5196 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5197 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 5198 | struct mesh_setup *setup) |
| 5199 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5200 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5201 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 5202 | |
| 5203 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 5204 | return -EINVAL; |
| 5205 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 5206 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 5207 | nl80211_mesh_setup_params_policy)) |
| 5208 | return -EINVAL; |
| 5209 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5210 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 5211 | setup->sync_method = |
| 5212 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 5213 | IEEE80211_SYNC_METHOD_VENDOR : |
| 5214 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 5215 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5216 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 5217 | setup->path_sel_proto = |
| 5218 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 5219 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 5220 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 5221 | |
| 5222 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 5223 | setup->path_metric = |
| 5224 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 5225 | IEEE80211_PATH_METRIC_VENDOR : |
| 5226 | IEEE80211_PATH_METRIC_AIRTIME; |
| 5227 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5228 | |
| 5229 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5230 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5231 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5232 | if (!is_valid_ie_attr(ieattr)) |
| 5233 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5234 | setup->ie = nla_data(ieattr); |
| 5235 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5236 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5237 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 5238 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 5239 | return -EINVAL; |
| 5240 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5241 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 5242 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5243 | if (setup->is_secure) |
| 5244 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5245 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5246 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 5247 | if (!setup->user_mpm) |
| 5248 | return -EINVAL; |
| 5249 | setup->auth_id = |
| 5250 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 5251 | } |
| 5252 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5253 | return 0; |
| 5254 | } |
| 5255 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5256 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5257 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5258 | { |
| 5259 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5260 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5261 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5262 | struct mesh_config cfg; |
| 5263 | u32 mask; |
| 5264 | int err; |
| 5265 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5266 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5267 | return -EOPNOTSUPP; |
| 5268 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5269 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5270 | return -EOPNOTSUPP; |
| 5271 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5272 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5273 | if (err) |
| 5274 | return err; |
| 5275 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5276 | wdev_lock(wdev); |
| 5277 | if (!wdev->mesh_id_len) |
| 5278 | err = -ENOLINK; |
| 5279 | |
| 5280 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5281 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5282 | |
| 5283 | wdev_unlock(wdev); |
| 5284 | |
| 5285 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5286 | } |
| 5287 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5288 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 5289 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5290 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5291 | struct sk_buff *msg; |
| 5292 | void *hdr = NULL; |
| 5293 | struct nlattr *nl_reg_rules; |
| 5294 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5295 | |
| 5296 | if (!cfg80211_regdomain) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5297 | return -EINVAL; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5298 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5299 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5300 | if (!msg) |
| 5301 | return -ENOBUFS; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5302 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5303 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5304 | NL80211_CMD_GET_REG); |
| 5305 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5306 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5307 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5308 | if (reg_last_request_cell_base() && |
| 5309 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5310 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5311 | goto nla_put_failure; |
| 5312 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5313 | rcu_read_lock(); |
| 5314 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5315 | |
| 5316 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5317 | (regdom->dfs_region && |
| 5318 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 5319 | goto nla_put_failure_rcu; |
| 5320 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5321 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5322 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5323 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5324 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5325 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5326 | struct nlattr *nl_reg_rule; |
| 5327 | const struct ieee80211_reg_rule *reg_rule; |
| 5328 | const struct ieee80211_freq_range *freq_range; |
| 5329 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5330 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5331 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5332 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5333 | freq_range = ®_rule->freq_range; |
| 5334 | power_rule = ®_rule->power_rule; |
| 5335 | |
| 5336 | nl_reg_rule = nla_nest_start(msg, i); |
| 5337 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5338 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5339 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5340 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 5341 | if (!max_bandwidth_khz) |
| 5342 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 5343 | reg_rule); |
| 5344 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5345 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5346 | reg_rule->flags) || |
| 5347 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5348 | freq_range->start_freq_khz) || |
| 5349 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5350 | freq_range->end_freq_khz) || |
| 5351 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5352 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5353 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5354 | power_rule->max_antenna_gain) || |
| 5355 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 5356 | power_rule->max_eirp) || |
| 5357 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 5358 | reg_rule->dfs_cac_ms)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5359 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5360 | |
| 5361 | nla_nest_end(msg, nl_reg_rule); |
| 5362 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5363 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5364 | |
| 5365 | nla_nest_end(msg, nl_reg_rules); |
| 5366 | |
| 5367 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5368 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5369 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5370 | nla_put_failure_rcu: |
| 5371 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5372 | nla_put_failure: |
| 5373 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5374 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5375 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5376 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5377 | } |
| 5378 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5379 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5380 | { |
| 5381 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5382 | struct nlattr *nl_reg_rule; |
| 5383 | char *alpha2 = NULL; |
| 5384 | int rem_reg_rules = 0, r = 0; |
| 5385 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5386 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5387 | struct ieee80211_regdomain *rd = NULL; |
| 5388 | |
| 5389 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5390 | return -EINVAL; |
| 5391 | |
| 5392 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5393 | return -EINVAL; |
| 5394 | |
| 5395 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5396 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5397 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5398 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5399 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5400 | 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] | 5401 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5402 | num_rules++; |
| 5403 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5404 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5405 | } |
| 5406 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5407 | if (!reg_is_valid_request(alpha2)) |
| 5408 | return -EINVAL; |
| 5409 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5410 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5411 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5412 | |
| 5413 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5414 | if (!rd) |
| 5415 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5416 | |
| 5417 | rd->n_reg_rules = num_rules; |
| 5418 | rd->alpha2[0] = alpha2[0]; |
| 5419 | rd->alpha2[1] = alpha2[1]; |
| 5420 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5421 | /* |
| 5422 | * Disable DFS master mode if the DFS region was |
| 5423 | * not supported or known on this kernel. |
| 5424 | */ |
| 5425 | if (reg_supported_dfs_region(dfs_region)) |
| 5426 | rd->dfs_region = dfs_region; |
| 5427 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5428 | 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] | 5429 | rem_reg_rules) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5430 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 5431 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5432 | reg_rule_policy); |
| 5433 | if (r) |
| 5434 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5435 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5436 | if (r) |
| 5437 | goto bad_reg; |
| 5438 | |
| 5439 | rule_idx++; |
| 5440 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5441 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5442 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5443 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5444 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5445 | } |
| 5446 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5447 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5448 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5449 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5450 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5451 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5452 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5453 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5454 | } |
| 5455 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5456 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5457 | { |
| 5458 | struct nlattr *attr1, *attr2; |
| 5459 | int n_channels = 0, tmp1, tmp2; |
| 5460 | |
| 5461 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5462 | n_channels++; |
| 5463 | /* |
| 5464 | * Some hardware has a limited channel list for |
| 5465 | * scanning, and it is pretty much nonsensical |
| 5466 | * to scan for a channel twice, so disallow that |
| 5467 | * and don't require drivers to check that the |
| 5468 | * channel list they get isn't longer than what |
| 5469 | * they can scan, as long as they can scan all |
| 5470 | * the channels they registered at once. |
| 5471 | */ |
| 5472 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5473 | if (attr1 != attr2 && |
| 5474 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5475 | return 0; |
| 5476 | } |
| 5477 | |
| 5478 | return n_channels; |
| 5479 | } |
| 5480 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5481 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5482 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5483 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5484 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5485 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5486 | struct nlattr *attr; |
| 5487 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5488 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5489 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5490 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5491 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5492 | return -EINVAL; |
| 5493 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5494 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5495 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5496 | if (!rdev->ops->scan) |
| 5497 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5498 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 5499 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5500 | err = -EBUSY; |
| 5501 | goto unlock; |
| 5502 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5503 | |
| 5504 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5505 | n_channels = validate_scan_freqs( |
| 5506 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5507 | if (!n_channels) { |
| 5508 | err = -EINVAL; |
| 5509 | goto unlock; |
| 5510 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5511 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5512 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5513 | } |
| 5514 | |
| 5515 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5516 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5517 | n_ssids++; |
| 5518 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5519 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5520 | err = -EINVAL; |
| 5521 | goto unlock; |
| 5522 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5523 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5524 | if (info->attrs[NL80211_ATTR_IE]) |
| 5525 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5526 | else |
| 5527 | ie_len = 0; |
| 5528 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5529 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5530 | err = -EINVAL; |
| 5531 | goto unlock; |
| 5532 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5533 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5534 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5535 | + sizeof(*request->ssids) * n_ssids |
| 5536 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5537 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5538 | if (!request) { |
| 5539 | err = -ENOMEM; |
| 5540 | goto unlock; |
| 5541 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5542 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5543 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5544 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5545 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5546 | if (ie_len) { |
| 5547 | if (request->ssids) |
| 5548 | request->ie = (void *)(request->ssids + n_ssids); |
| 5549 | else |
| 5550 | request->ie = (void *)(request->channels + n_channels); |
| 5551 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5552 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5553 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5554 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5555 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5556 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5557 | struct ieee80211_channel *chan; |
| 5558 | |
| 5559 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5560 | |
| 5561 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5562 | err = -EINVAL; |
| 5563 | goto out_free; |
| 5564 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5565 | |
| 5566 | /* ignore disabled channels */ |
| 5567 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5568 | continue; |
| 5569 | |
| 5570 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5571 | i++; |
| 5572 | } |
| 5573 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5574 | enum ieee80211_band band; |
| 5575 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5576 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5577 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5578 | int j; |
| 5579 | if (!wiphy->bands[band]) |
| 5580 | continue; |
| 5581 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5582 | struct ieee80211_channel *chan; |
| 5583 | |
| 5584 | chan = &wiphy->bands[band]->channels[j]; |
| 5585 | |
| 5586 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5587 | continue; |
| 5588 | |
| 5589 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5590 | i++; |
| 5591 | } |
| 5592 | } |
| 5593 | } |
| 5594 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5595 | if (!i) { |
| 5596 | err = -EINVAL; |
| 5597 | goto out_free; |
| 5598 | } |
| 5599 | |
| 5600 | request->n_channels = i; |
| 5601 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5602 | i = 0; |
| 5603 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5604 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5605 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5606 | err = -EINVAL; |
| 5607 | goto out_free; |
| 5608 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5609 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5610 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5611 | i++; |
| 5612 | } |
| 5613 | } |
| 5614 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5615 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5616 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5617 | memcpy((void *)request->ie, |
| 5618 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5619 | request->ie_len); |
| 5620 | } |
| 5621 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5622 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5623 | if (wiphy->bands[i]) |
| 5624 | request->rates[i] = |
| 5625 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5626 | |
| 5627 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5628 | nla_for_each_nested(attr, |
| 5629 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5630 | tmp) { |
| 5631 | enum ieee80211_band band = nla_type(attr); |
| 5632 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5633 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5634 | err = -EINVAL; |
| 5635 | goto out_free; |
| 5636 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 5637 | |
| 5638 | if (!wiphy->bands[band]) |
| 5639 | continue; |
| 5640 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5641 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5642 | nla_data(attr), |
| 5643 | nla_len(attr), |
| 5644 | &request->rates[band]); |
| 5645 | if (err) |
| 5646 | goto out_free; |
| 5647 | } |
| 5648 | } |
| 5649 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5650 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5651 | request->flags = nla_get_u32( |
| 5652 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5653 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5654 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5655 | err = -EOPNOTSUPP; |
| 5656 | goto out_free; |
| 5657 | } |
| 5658 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5659 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5660 | request->no_cck = |
| 5661 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5662 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5663 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5664 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5665 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5666 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5667 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5668 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5669 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5670 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5671 | nl80211_send_scan_start(rdev, wdev); |
| 5672 | if (wdev->netdev) |
| 5673 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5674 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5675 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5676 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5677 | kfree(request); |
| 5678 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5679 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5680 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5681 | return err; |
| 5682 | } |
| 5683 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5684 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5685 | struct genl_info *info) |
| 5686 | { |
| 5687 | struct cfg80211_sched_scan_request *request; |
| 5688 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5689 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5690 | struct nlattr *attr; |
| 5691 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5692 | 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] | 5693 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5694 | enum ieee80211_band band; |
| 5695 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5696 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5697 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5698 | |
| 5699 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5700 | !rdev->ops->sched_scan_start) |
| 5701 | return -EOPNOTSUPP; |
| 5702 | |
| 5703 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5704 | return -EINVAL; |
| 5705 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5706 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5707 | return -EINVAL; |
| 5708 | |
| 5709 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5710 | if (interval == 0) |
| 5711 | return -EINVAL; |
| 5712 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5713 | wiphy = &rdev->wiphy; |
| 5714 | |
| 5715 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5716 | n_channels = validate_scan_freqs( |
| 5717 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5718 | if (!n_channels) |
| 5719 | return -EINVAL; |
| 5720 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5721 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5722 | } |
| 5723 | |
| 5724 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5725 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5726 | tmp) |
| 5727 | n_ssids++; |
| 5728 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5729 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5730 | return -EINVAL; |
| 5731 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5732 | /* |
| 5733 | * First, count the number of 'real' matchsets. Due to an issue with |
| 5734 | * the old implementation, matchsets containing only the RSSI attribute |
| 5735 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 5736 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 5737 | * all APs with a strong RSSI. This is needed to be compatible with |
| 5738 | * older userspace that treated a matchset with only the RSSI as the |
| 5739 | * global RSSI for all other matchsets - if there are other matchsets. |
| 5740 | */ |
| 5741 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5742 | nla_for_each_nested(attr, |
| 5743 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5744 | tmp) { |
| 5745 | struct nlattr *rssi; |
| 5746 | |
| 5747 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5748 | nla_data(attr), nla_len(attr), |
| 5749 | nl80211_match_policy); |
| 5750 | if (err) |
| 5751 | return err; |
| 5752 | /* add other standalone attributes here */ |
| 5753 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { |
| 5754 | n_match_sets++; |
| 5755 | continue; |
| 5756 | } |
| 5757 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5758 | if (rssi) |
| 5759 | default_match_rssi = nla_get_s32(rssi); |
| 5760 | } |
| 5761 | } |
| 5762 | |
| 5763 | /* However, if there's no other matchset, add the RSSI one */ |
| 5764 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 5765 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5766 | |
| 5767 | if (n_match_sets > wiphy->max_match_sets) |
| 5768 | return -EINVAL; |
| 5769 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5770 | if (info->attrs[NL80211_ATTR_IE]) |
| 5771 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5772 | else |
| 5773 | ie_len = 0; |
| 5774 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5775 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5776 | return -EINVAL; |
| 5777 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5778 | if (rdev->sched_scan_req) { |
| 5779 | err = -EINPROGRESS; |
| 5780 | goto out; |
| 5781 | } |
| 5782 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5783 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5784 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5785 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5786 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5787 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5788 | if (!request) { |
| 5789 | err = -ENOMEM; |
| 5790 | goto out; |
| 5791 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5792 | |
| 5793 | if (n_ssids) |
| 5794 | request->ssids = (void *)&request->channels[n_channels]; |
| 5795 | request->n_ssids = n_ssids; |
| 5796 | if (ie_len) { |
| 5797 | if (request->ssids) |
| 5798 | request->ie = (void *)(request->ssids + n_ssids); |
| 5799 | else |
| 5800 | request->ie = (void *)(request->channels + n_channels); |
| 5801 | } |
| 5802 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5803 | if (n_match_sets) { |
| 5804 | if (request->ie) |
| 5805 | request->match_sets = (void *)(request->ie + ie_len); |
| 5806 | else if (request->ssids) |
| 5807 | request->match_sets = |
| 5808 | (void *)(request->ssids + n_ssids); |
| 5809 | else |
| 5810 | request->match_sets = |
| 5811 | (void *)(request->channels + n_channels); |
| 5812 | } |
| 5813 | request->n_match_sets = n_match_sets; |
| 5814 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5815 | i = 0; |
| 5816 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5817 | /* user specified, bail out if channel not found */ |
| 5818 | nla_for_each_nested(attr, |
| 5819 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5820 | tmp) { |
| 5821 | struct ieee80211_channel *chan; |
| 5822 | |
| 5823 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5824 | |
| 5825 | if (!chan) { |
| 5826 | err = -EINVAL; |
| 5827 | goto out_free; |
| 5828 | } |
| 5829 | |
| 5830 | /* ignore disabled channels */ |
| 5831 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5832 | continue; |
| 5833 | |
| 5834 | request->channels[i] = chan; |
| 5835 | i++; |
| 5836 | } |
| 5837 | } else { |
| 5838 | /* all channels */ |
| 5839 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5840 | int j; |
| 5841 | if (!wiphy->bands[band]) |
| 5842 | continue; |
| 5843 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5844 | struct ieee80211_channel *chan; |
| 5845 | |
| 5846 | chan = &wiphy->bands[band]->channels[j]; |
| 5847 | |
| 5848 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5849 | continue; |
| 5850 | |
| 5851 | request->channels[i] = chan; |
| 5852 | i++; |
| 5853 | } |
| 5854 | } |
| 5855 | } |
| 5856 | |
| 5857 | if (!i) { |
| 5858 | err = -EINVAL; |
| 5859 | goto out_free; |
| 5860 | } |
| 5861 | |
| 5862 | request->n_channels = i; |
| 5863 | |
| 5864 | i = 0; |
| 5865 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5866 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5867 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5868 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5869 | err = -EINVAL; |
| 5870 | goto out_free; |
| 5871 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5872 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5873 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5874 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5875 | i++; |
| 5876 | } |
| 5877 | } |
| 5878 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5879 | i = 0; |
| 5880 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5881 | nla_for_each_nested(attr, |
| 5882 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5883 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5884 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5885 | |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5886 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5887 | nla_data(attr), nla_len(attr), |
| 5888 | nl80211_match_policy); |
| 5889 | if (err) |
| 5890 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5891 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5892 | if (ssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5893 | if (WARN_ON(i >= n_match_sets)) { |
| 5894 | /* this indicates a programming error, |
| 5895 | * the loop above should have verified |
| 5896 | * things properly |
| 5897 | */ |
| 5898 | err = -EINVAL; |
| 5899 | goto out_free; |
| 5900 | } |
| 5901 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5902 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5903 | err = -EINVAL; |
| 5904 | goto out_free; |
| 5905 | } |
| 5906 | memcpy(request->match_sets[i].ssid.ssid, |
| 5907 | nla_data(ssid), nla_len(ssid)); |
| 5908 | request->match_sets[i].ssid.ssid_len = |
| 5909 | nla_len(ssid); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5910 | /* special attribute - old implemenation w/a */ |
| 5911 | request->match_sets[i].rssi_thold = |
| 5912 | default_match_rssi; |
| 5913 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5914 | if (rssi) |
| 5915 | request->match_sets[i].rssi_thold = |
| 5916 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5917 | } |
| 5918 | i++; |
| 5919 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5920 | |
| 5921 | /* there was no other matchset, so the RSSI one is alone */ |
| 5922 | if (i == 0) |
| 5923 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 5924 | |
| 5925 | request->min_rssi_thold = INT_MAX; |
| 5926 | for (i = 0; i < n_match_sets; i++) |
| 5927 | request->min_rssi_thold = |
| 5928 | min(request->match_sets[i].rssi_thold, |
| 5929 | request->min_rssi_thold); |
| 5930 | } else { |
| 5931 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5932 | } |
| 5933 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 5934 | if (ie_len) { |
| 5935 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5936 | memcpy((void *)request->ie, |
| 5937 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5938 | request->ie_len); |
| 5939 | } |
| 5940 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5941 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5942 | request->flags = nla_get_u32( |
| 5943 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5944 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5945 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5946 | err = -EOPNOTSUPP; |
| 5947 | goto out_free; |
| 5948 | } |
| 5949 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5950 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5951 | request->dev = dev; |
| 5952 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5953 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5954 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5955 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5956 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5957 | if (!err) { |
| 5958 | rdev->sched_scan_req = request; |
| 5959 | nl80211_send_sched_scan(rdev, dev, |
| 5960 | NL80211_CMD_START_SCHED_SCAN); |
| 5961 | goto out; |
| 5962 | } |
| 5963 | |
| 5964 | out_free: |
| 5965 | kfree(request); |
| 5966 | out: |
| 5967 | return err; |
| 5968 | } |
| 5969 | |
| 5970 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5971 | struct genl_info *info) |
| 5972 | { |
| 5973 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5974 | |
| 5975 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5976 | !rdev->ops->sched_scan_stop) |
| 5977 | return -EOPNOTSUPP; |
| 5978 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5979 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5980 | } |
| 5981 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5982 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5983 | struct genl_info *info) |
| 5984 | { |
| 5985 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5986 | struct net_device *dev = info->user_ptr[1]; |
| 5987 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5988 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5989 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 5990 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5991 | int err; |
| 5992 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5993 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 5994 | if (dfs_region == NL80211_DFS_UNSET) |
| 5995 | return -EINVAL; |
| 5996 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5997 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5998 | if (err) |
| 5999 | return err; |
| 6000 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 6001 | if (netif_carrier_ok(dev)) |
| 6002 | return -EBUSY; |
| 6003 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6004 | if (wdev->cac_started) |
| 6005 | return -EBUSY; |
| 6006 | |
Luciano Coelho | 2beb6da | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6007 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 6008 | wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6009 | if (err < 0) |
| 6010 | return err; |
| 6011 | |
| 6012 | if (err == 0) |
| 6013 | return -EINVAL; |
| 6014 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 6015 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6016 | return -EINVAL; |
| 6017 | |
| 6018 | if (!rdev->ops->start_radar_detection) |
| 6019 | return -EOPNOTSUPP; |
| 6020 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6021 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 6022 | if (WARN_ON(!cac_time_ms)) |
| 6023 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 6024 | |
| 6025 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, |
| 6026 | cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6027 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 6028 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6029 | wdev->cac_started = true; |
| 6030 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 6031 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6032 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 6033 | return err; |
| 6034 | } |
| 6035 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6036 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 6037 | { |
| 6038 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6039 | struct net_device *dev = info->user_ptr[1]; |
| 6040 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6041 | struct cfg80211_csa_settings params; |
| 6042 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 6043 | * function is called under RTNL lock, so this should not be a problem. |
| 6044 | */ |
| 6045 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6046 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6047 | bool need_new_beacon = false; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6048 | int len, i; |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 6049 | u32 cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6050 | |
| 6051 | if (!rdev->ops->channel_switch || |
| 6052 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 6053 | return -EOPNOTSUPP; |
| 6054 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6055 | switch (dev->ieee80211_ptr->iftype) { |
| 6056 | case NL80211_IFTYPE_AP: |
| 6057 | case NL80211_IFTYPE_P2P_GO: |
| 6058 | need_new_beacon = true; |
| 6059 | |
| 6060 | /* useless if AP is not running */ |
| 6061 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6062 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6063 | break; |
| 6064 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6065 | if (!wdev->ssid_len) |
| 6066 | return -ENOTCONN; |
| 6067 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 6068 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 6069 | if (!wdev->mesh_id_len) |
| 6070 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6071 | break; |
| 6072 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6073 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6074 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6075 | |
| 6076 | memset(¶ms, 0, sizeof(params)); |
| 6077 | |
| 6078 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 6079 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 6080 | return -EINVAL; |
| 6081 | |
| 6082 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 6083 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6084 | return -EINVAL; |
| 6085 | |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 6086 | /* Even though the attribute is u32, the specification says |
| 6087 | * u8, so let's make sure we don't overflow. |
| 6088 | */ |
| 6089 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 6090 | if (cs_count > 255) |
| 6091 | return -EINVAL; |
| 6092 | |
| 6093 | params.count = cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6094 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6095 | if (!need_new_beacon) |
| 6096 | goto skip_beacons; |
| 6097 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6098 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 6099 | if (err) |
| 6100 | return err; |
| 6101 | |
| 6102 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 6103 | info->attrs[NL80211_ATTR_CSA_IES], |
| 6104 | nl80211_policy); |
| 6105 | if (err) |
| 6106 | return err; |
| 6107 | |
| 6108 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 6109 | if (err) |
| 6110 | return err; |
| 6111 | |
| 6112 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 6113 | return -EINVAL; |
| 6114 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6115 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 6116 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6117 | return -EINVAL; |
| 6118 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6119 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 6120 | if (rdev->wiphy.max_num_csa_counters && |
| 6121 | (params.n_counter_offsets_beacon > |
| 6122 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6123 | return -EINVAL; |
| 6124 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6125 | params.counter_offsets_beacon = |
| 6126 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 6127 | |
| 6128 | /* sanity checks - counters should fit and be the same */ |
| 6129 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 6130 | u16 offset = params.counter_offsets_beacon[i]; |
| 6131 | |
| 6132 | if (offset >= params.beacon_csa.tail_len) |
| 6133 | return -EINVAL; |
| 6134 | |
| 6135 | if (params.beacon_csa.tail[offset] != params.count) |
| 6136 | return -EINVAL; |
| 6137 | } |
| 6138 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6139 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6140 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 6141 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6142 | return -EINVAL; |
| 6143 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6144 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 6145 | if (rdev->wiphy.max_num_csa_counters && |
| 6146 | (params.n_counter_offsets_beacon > |
| 6147 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6148 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 6149 | |
| 6150 | params.counter_offsets_presp = |
| 6151 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 6152 | |
| 6153 | /* sanity checks - counters should fit and be the same */ |
| 6154 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 6155 | u16 offset = params.counter_offsets_presp[i]; |
| 6156 | |
| 6157 | if (offset >= params.beacon_csa.probe_resp_len) |
| 6158 | return -EINVAL; |
| 6159 | |
| 6160 | if (params.beacon_csa.probe_resp[offset] != |
| 6161 | params.count) |
| 6162 | return -EINVAL; |
| 6163 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6164 | } |
| 6165 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6166 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6167 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 6168 | if (err) |
| 6169 | return err; |
| 6170 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 6171 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
| 6172 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6173 | return -EINVAL; |
| 6174 | |
Luciano Coelho | 2beb6da | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6175 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 6176 | ¶ms.chandef, |
| 6177 | wdev->iftype); |
| 6178 | if (err < 0) |
| 6179 | return err; |
| 6180 | |
Fabian Frederick | dcc6c2f | 2014-10-25 17:57:35 +0200 | [diff] [blame] | 6181 | if (err > 0) |
Luciano Coelho | 2beb6da | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6182 | params.radar_required = true; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6183 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6184 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 6185 | params.block_tx = true; |
| 6186 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6187 | wdev_lock(wdev); |
| 6188 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 6189 | wdev_unlock(wdev); |
| 6190 | |
| 6191 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6192 | } |
| 6193 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6194 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 6195 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6196 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6197 | struct wireless_dev *wdev, |
| 6198 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6199 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6200 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6201 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6202 | void *hdr; |
| 6203 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6204 | |
| 6205 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6206 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6207 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6208 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 6209 | if (!hdr) |
| 6210 | return -1; |
| 6211 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6212 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 6213 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6214 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 6215 | goto nla_put_failure; |
| 6216 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6217 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 6218 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6219 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 6220 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6221 | |
| 6222 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 6223 | if (!bss) |
| 6224 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6225 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6226 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6227 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6228 | |
| 6229 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6230 | /* indicate whether we have probe response data or not */ |
| 6231 | if (rcu_access_pointer(res->proberesp_ies) && |
| 6232 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 6233 | goto fail_unlock_rcu; |
| 6234 | |
| 6235 | /* this pointer prefers to be pointed to probe response data |
| 6236 | * but is always valid |
| 6237 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6238 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6239 | if (ies) { |
| 6240 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 6241 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6242 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 6243 | ies->len, ies->data)) |
| 6244 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6245 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6246 | |
| 6247 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6248 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6249 | if (ies && ies->from_beacon) { |
| 6250 | if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6251 | goto fail_unlock_rcu; |
| 6252 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 6253 | ies->len, ies->data)) |
| 6254 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6255 | } |
| 6256 | rcu_read_unlock(); |
| 6257 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6258 | if (res->beacon_interval && |
| 6259 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 6260 | goto nla_put_failure; |
| 6261 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 6262 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 6263 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6264 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 6265 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 6266 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6267 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 6268 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6269 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6270 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 6271 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6272 | break; |
| 6273 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6274 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 6275 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6276 | break; |
| 6277 | default: |
| 6278 | break; |
| 6279 | } |
| 6280 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6281 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6282 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6283 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6284 | if (intbss == wdev->current_bss && |
| 6285 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6286 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 6287 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6288 | break; |
| 6289 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6290 | if (intbss == wdev->current_bss && |
| 6291 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6292 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 6293 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6294 | break; |
| 6295 | default: |
| 6296 | break; |
| 6297 | } |
| 6298 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6299 | nla_nest_end(msg, bss); |
| 6300 | |
| 6301 | return genlmsg_end(msg, hdr); |
| 6302 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6303 | fail_unlock_rcu: |
| 6304 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6305 | nla_put_failure: |
| 6306 | genlmsg_cancel(msg, hdr); |
| 6307 | return -EMSGSIZE; |
| 6308 | } |
| 6309 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6310 | 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] | 6311 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6312 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6313 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6314 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6315 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6316 | int err; |
| 6317 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6318 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6319 | if (err) |
| 6320 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6321 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6322 | wdev_lock(wdev); |
| 6323 | spin_lock_bh(&rdev->bss_lock); |
| 6324 | cfg80211_bss_expire(rdev); |
| 6325 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6326 | cb->seq = rdev->bss_generation; |
| 6327 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6328 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6329 | if (++idx <= start) |
| 6330 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6331 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6332 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6333 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6334 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6335 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6336 | } |
| 6337 | } |
| 6338 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6339 | spin_unlock_bh(&rdev->bss_lock); |
| 6340 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6341 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6342 | cb->args[2] = idx; |
| 6343 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6344 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6345 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6346 | } |
| 6347 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6348 | 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] | 6349 | int flags, struct net_device *dev, |
| 6350 | struct survey_info *survey) |
| 6351 | { |
| 6352 | void *hdr; |
| 6353 | struct nlattr *infoattr; |
| 6354 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6355 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6356 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 6357 | if (!hdr) |
| 6358 | return -ENOMEM; |
| 6359 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6360 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 6361 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6362 | |
| 6363 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 6364 | if (!infoattr) |
| 6365 | goto nla_put_failure; |
| 6366 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6367 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 6368 | survey->channel->center_freq)) |
| 6369 | goto nla_put_failure; |
| 6370 | |
| 6371 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 6372 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 6373 | goto nla_put_failure; |
| 6374 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 6375 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 6376 | goto nla_put_failure; |
| 6377 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 6378 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 6379 | survey->channel_time)) |
| 6380 | goto nla_put_failure; |
| 6381 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 6382 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 6383 | survey->channel_time_busy)) |
| 6384 | goto nla_put_failure; |
| 6385 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 6386 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 6387 | survey->channel_time_ext_busy)) |
| 6388 | goto nla_put_failure; |
| 6389 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 6390 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 6391 | survey->channel_time_rx)) |
| 6392 | goto nla_put_failure; |
| 6393 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 6394 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 6395 | survey->channel_time_tx)) |
| 6396 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6397 | |
| 6398 | nla_nest_end(msg, infoattr); |
| 6399 | |
| 6400 | return genlmsg_end(msg, hdr); |
| 6401 | |
| 6402 | nla_put_failure: |
| 6403 | genlmsg_cancel(msg, hdr); |
| 6404 | return -EMSGSIZE; |
| 6405 | } |
| 6406 | |
| 6407 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 6408 | struct netlink_callback *cb) |
| 6409 | { |
| 6410 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6411 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6412 | struct wireless_dev *wdev; |
| 6413 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6414 | int res; |
| 6415 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6416 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6417 | if (res) |
| 6418 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6419 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6420 | if (!wdev->netdev) { |
| 6421 | res = -EINVAL; |
| 6422 | goto out_err; |
| 6423 | } |
| 6424 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6425 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6426 | res = -EOPNOTSUPP; |
| 6427 | goto out_err; |
| 6428 | } |
| 6429 | |
| 6430 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6431 | struct ieee80211_channel *chan; |
| 6432 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6433 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6434 | if (res == -ENOENT) |
| 6435 | break; |
| 6436 | if (res) |
| 6437 | goto out_err; |
| 6438 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6439 | /* Survey without a channel doesn't make sense */ |
| 6440 | if (!survey.channel) { |
| 6441 | res = -EINVAL; |
| 6442 | goto out; |
| 6443 | } |
| 6444 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6445 | chan = ieee80211_get_channel(&rdev->wiphy, |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6446 | survey.channel->center_freq); |
| 6447 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 6448 | survey_idx++; |
| 6449 | continue; |
| 6450 | } |
| 6451 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6452 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6453 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6454 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6455 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6456 | goto out; |
| 6457 | survey_idx++; |
| 6458 | } |
| 6459 | |
| 6460 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6461 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6462 | res = skb->len; |
| 6463 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6464 | nl80211_finish_wdev_dump(rdev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6465 | return res; |
| 6466 | } |
| 6467 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6468 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 6469 | { |
| 6470 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 6471 | NL80211_WPA_VERSION_2)); |
| 6472 | } |
| 6473 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6474 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6475 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6476 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6477 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6478 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6479 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6480 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6481 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6482 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6483 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6484 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6485 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6486 | return -EINVAL; |
| 6487 | |
| 6488 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6489 | return -EINVAL; |
| 6490 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6491 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 6492 | return -EINVAL; |
| 6493 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6494 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 6495 | return -EINVAL; |
| 6496 | |
| 6497 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6498 | return -EINVAL; |
| 6499 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6500 | err = nl80211_parse_key(info, &key); |
| 6501 | if (err) |
| 6502 | return err; |
| 6503 | |
| 6504 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6505 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 6506 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6507 | if (!key.p.key || !key.p.key_len) |
| 6508 | return -EINVAL; |
| 6509 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 6510 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 6511 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 6512 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 6513 | return -EINVAL; |
| 6514 | if (key.idx > 4) |
| 6515 | return -EINVAL; |
| 6516 | } else { |
| 6517 | key.p.key_len = 0; |
| 6518 | key.p.key = NULL; |
| 6519 | } |
| 6520 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6521 | if (key.idx >= 0) { |
| 6522 | int i; |
| 6523 | bool ok = false; |
| 6524 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 6525 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 6526 | ok = true; |
| 6527 | break; |
| 6528 | } |
| 6529 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6530 | if (!ok) |
| 6531 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6532 | } |
| 6533 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6534 | if (!rdev->ops->auth) |
| 6535 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6536 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6537 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6538 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6539 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6540 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6541 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6542 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 6543 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6544 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6545 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6546 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6547 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6548 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6549 | |
| 6550 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6551 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6552 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6553 | } |
| 6554 | |
| 6555 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6556 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6557 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6558 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6559 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 6560 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 6561 | return -EINVAL; |
| 6562 | |
| 6563 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 6564 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 6565 | return -EINVAL; |
| 6566 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6567 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6568 | /* need to include at least Auth Transaction and Status Code */ |
| 6569 | if (sae_data_len < 4) |
| 6570 | return -EINVAL; |
| 6571 | } |
| 6572 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6573 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6574 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6575 | /* |
| 6576 | * Since we no longer track auth state, ignore |
| 6577 | * requests to only change local state. |
| 6578 | */ |
| 6579 | if (local_state_change) |
| 6580 | return 0; |
| 6581 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6582 | wdev_lock(dev->ieee80211_ptr); |
| 6583 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 6584 | ssid, ssid_len, ie, ie_len, |
| 6585 | key.p.key, key.p.key_len, key.idx, |
| 6586 | sae_data, sae_data_len); |
| 6587 | wdev_unlock(dev->ieee80211_ptr); |
| 6588 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6589 | } |
| 6590 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6591 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 6592 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6593 | struct cfg80211_crypto_settings *settings, |
| 6594 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6595 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6596 | memset(settings, 0, sizeof(*settings)); |
| 6597 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6598 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 6599 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6600 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 6601 | u16 proto; |
| 6602 | proto = nla_get_u16( |
| 6603 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 6604 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6605 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6606 | proto != ETH_P_PAE) |
| 6607 | return -EINVAL; |
| 6608 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6609 | settings->control_port_no_encrypt = true; |
| 6610 | } else |
| 6611 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6612 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6613 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6614 | void *data; |
| 6615 | int len, i; |
| 6616 | |
| 6617 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6618 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6619 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6620 | |
| 6621 | if (len % sizeof(u32)) |
| 6622 | return -EINVAL; |
| 6623 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6624 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6625 | return -EINVAL; |
| 6626 | |
| 6627 | memcpy(settings->ciphers_pairwise, data, len); |
| 6628 | |
| 6629 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6630 | if (!cfg80211_supported_cipher_suite( |
| 6631 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6632 | settings->ciphers_pairwise[i])) |
| 6633 | return -EINVAL; |
| 6634 | } |
| 6635 | |
| 6636 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6637 | settings->cipher_group = |
| 6638 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6639 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6640 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6641 | return -EINVAL; |
| 6642 | } |
| 6643 | |
| 6644 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6645 | settings->wpa_versions = |
| 6646 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6647 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6648 | return -EINVAL; |
| 6649 | } |
| 6650 | |
| 6651 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6652 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6653 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6654 | |
| 6655 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6656 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6657 | settings->n_akm_suites = len / sizeof(u32); |
| 6658 | |
| 6659 | if (len % sizeof(u32)) |
| 6660 | return -EINVAL; |
| 6661 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6662 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6663 | return -EINVAL; |
| 6664 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6665 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6666 | } |
| 6667 | |
| 6668 | return 0; |
| 6669 | } |
| 6670 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6671 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6672 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6673 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6674 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6675 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6676 | struct cfg80211_assoc_request req = {}; |
| 6677 | const u8 *bssid, *ssid; |
| 6678 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6679 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6680 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6681 | return -EINVAL; |
| 6682 | |
| 6683 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6684 | !info->attrs[NL80211_ATTR_SSID] || |
| 6685 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6686 | return -EINVAL; |
| 6687 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6688 | if (!rdev->ops->assoc) |
| 6689 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6690 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6691 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6692 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6693 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6694 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6695 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6696 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6697 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 6698 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6699 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6700 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6701 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6702 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6703 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6704 | |
| 6705 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6706 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6707 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6708 | } |
| 6709 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6710 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6711 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6712 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6713 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6714 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6715 | else if (mfp != NL80211_MFP_NO) |
| 6716 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6717 | } |
| 6718 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6719 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6720 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6721 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6722 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6723 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6724 | |
| 6725 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6726 | memcpy(&req.ht_capa_mask, |
| 6727 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6728 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6729 | |
| 6730 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6731 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6732 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6733 | memcpy(&req.ht_capa, |
| 6734 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6735 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6736 | } |
| 6737 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6738 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6739 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6740 | |
| 6741 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6742 | memcpy(&req.vht_capa_mask, |
| 6743 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6744 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6745 | |
| 6746 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6747 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6748 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6749 | memcpy(&req.vht_capa, |
| 6750 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6751 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6752 | } |
| 6753 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 6754 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
| 6755 | if (!(rdev->wiphy.features & |
| 6756 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || |
| 6757 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) |
| 6758 | return -EINVAL; |
| 6759 | req.flags |= ASSOC_REQ_USE_RRM; |
| 6760 | } |
| 6761 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6762 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6763 | if (!err) { |
| 6764 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6765 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6766 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6767 | wdev_unlock(dev->ieee80211_ptr); |
| 6768 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6769 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6770 | return err; |
| 6771 | } |
| 6772 | |
| 6773 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6774 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6775 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6776 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6777 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6778 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6779 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6780 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6781 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6782 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6783 | return -EINVAL; |
| 6784 | |
| 6785 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6786 | return -EINVAL; |
| 6787 | |
| 6788 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6789 | return -EINVAL; |
| 6790 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6791 | if (!rdev->ops->deauth) |
| 6792 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6793 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6794 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6795 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6796 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6797 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6798 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6799 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6800 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6801 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6802 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6803 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6804 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6805 | |
| 6806 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6807 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6808 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6809 | } |
| 6810 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6811 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6812 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6813 | wdev_lock(dev->ieee80211_ptr); |
| 6814 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6815 | local_state_change); |
| 6816 | wdev_unlock(dev->ieee80211_ptr); |
| 6817 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6818 | } |
| 6819 | |
| 6820 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 6821 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6822 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6823 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6824 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6825 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6826 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6827 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6828 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6829 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6830 | return -EINVAL; |
| 6831 | |
| 6832 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6833 | return -EINVAL; |
| 6834 | |
| 6835 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6836 | return -EINVAL; |
| 6837 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6838 | if (!rdev->ops->disassoc) |
| 6839 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6840 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6841 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6842 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6843 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6844 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6845 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6846 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6847 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6848 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6849 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6850 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6851 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6852 | |
| 6853 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6854 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6855 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6856 | } |
| 6857 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6858 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6859 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6860 | wdev_lock(dev->ieee80211_ptr); |
| 6861 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6862 | local_state_change); |
| 6863 | wdev_unlock(dev->ieee80211_ptr); |
| 6864 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6865 | } |
| 6866 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6867 | static bool |
| 6868 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6869 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6870 | int rateval) |
| 6871 | { |
| 6872 | struct wiphy *wiphy = &rdev->wiphy; |
| 6873 | bool found = false; |
| 6874 | int band, i; |
| 6875 | |
| 6876 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6877 | struct ieee80211_supported_band *sband; |
| 6878 | |
| 6879 | sband = wiphy->bands[band]; |
| 6880 | if (!sband) |
| 6881 | continue; |
| 6882 | |
| 6883 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6884 | if (sband->bitrates[i].bitrate == rateval) { |
| 6885 | mcast_rate[band] = i + 1; |
| 6886 | found = true; |
| 6887 | break; |
| 6888 | } |
| 6889 | } |
| 6890 | } |
| 6891 | |
| 6892 | return found; |
| 6893 | } |
| 6894 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6895 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6896 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6897 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6898 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6899 | struct cfg80211_ibss_params ibss; |
| 6900 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6901 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6902 | int err; |
| 6903 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6904 | memset(&ibss, 0, sizeof(ibss)); |
| 6905 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6906 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6907 | return -EINVAL; |
| 6908 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6909 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6910 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6911 | return -EINVAL; |
| 6912 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6913 | ibss.beacon_interval = 100; |
| 6914 | |
| 6915 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6916 | ibss.beacon_interval = |
| 6917 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6918 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6919 | return -EINVAL; |
| 6920 | } |
| 6921 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6922 | if (!rdev->ops->join_ibss) |
| 6923 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6924 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6925 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6926 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6927 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6928 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6929 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6930 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6931 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6932 | |
| 6933 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6934 | return -EINVAL; |
| 6935 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6936 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6937 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6938 | |
| 6939 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6940 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6941 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6942 | } |
| 6943 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6944 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6945 | if (err) |
| 6946 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6947 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 6948 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 6949 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6950 | return -EINVAL; |
| 6951 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6952 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 6953 | case NL80211_CHAN_WIDTH_5: |
| 6954 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6955 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 6956 | break; |
| 6957 | case NL80211_CHAN_WIDTH_20: |
| 6958 | case NL80211_CHAN_WIDTH_40: |
| 6959 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) |
| 6960 | break; |
| 6961 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6962 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6963 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6964 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6965 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6966 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6967 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6968 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6969 | u8 *rates = |
| 6970 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6971 | int n_rates = |
| 6972 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6973 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6974 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6975 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6976 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6977 | &ibss.basic_rates); |
| 6978 | if (err) |
| 6979 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6980 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6981 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 6982 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6983 | memcpy(&ibss.ht_capa_mask, |
| 6984 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6985 | sizeof(ibss.ht_capa_mask)); |
| 6986 | |
| 6987 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 6988 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6989 | return -EINVAL; |
| 6990 | memcpy(&ibss.ht_capa, |
| 6991 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6992 | sizeof(ibss.ht_capa)); |
| 6993 | } |
| 6994 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6995 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6996 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6997 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6998 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6999 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7000 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7001 | bool no_ht = false; |
| 7002 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7003 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7004 | info->attrs[NL80211_ATTR_KEYS], |
| 7005 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7006 | if (IS_ERR(connkeys)) |
| 7007 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7008 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 7009 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 7010 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7011 | kfree(connkeys); |
| 7012 | return -EINVAL; |
| 7013 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7014 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7015 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 7016 | ibss.control_port = |
| 7017 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 7018 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 7019 | ibss.userspace_handles_dfs = |
| 7020 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 7021 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7022 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7023 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7024 | kzfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7025 | return err; |
| 7026 | } |
| 7027 | |
| 7028 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 7029 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7030 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7031 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7032 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7033 | if (!rdev->ops->leave_ibss) |
| 7034 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7035 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7036 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 7037 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7038 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7039 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 7040 | } |
| 7041 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7042 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 7043 | { |
| 7044 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7045 | struct net_device *dev = info->user_ptr[1]; |
| 7046 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 7047 | u32 nla_rate; |
| 7048 | int err; |
| 7049 | |
| 7050 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 7051 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 7052 | return -EOPNOTSUPP; |
| 7053 | |
| 7054 | if (!rdev->ops->set_mcast_rate) |
| 7055 | return -EOPNOTSUPP; |
| 7056 | |
| 7057 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 7058 | |
| 7059 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 7060 | return -EINVAL; |
| 7061 | |
| 7062 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 7063 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 7064 | return -EINVAL; |
| 7065 | |
| 7066 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 7067 | |
| 7068 | return err; |
| 7069 | } |
| 7070 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7071 | static struct sk_buff * |
| 7072 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
| 7073 | int approxlen, u32 portid, u32 seq, |
| 7074 | enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 7075 | enum nl80211_attrs attr, |
| 7076 | const struct nl80211_vendor_cmd_info *info, |
| 7077 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7078 | { |
| 7079 | struct sk_buff *skb; |
| 7080 | void *hdr; |
| 7081 | struct nlattr *data; |
| 7082 | |
| 7083 | skb = nlmsg_new(approxlen + 100, gfp); |
| 7084 | if (!skb) |
| 7085 | return NULL; |
| 7086 | |
| 7087 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 7088 | if (!hdr) { |
| 7089 | kfree_skb(skb); |
| 7090 | return NULL; |
| 7091 | } |
| 7092 | |
| 7093 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 7094 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 7095 | |
| 7096 | if (info) { |
| 7097 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 7098 | info->vendor_id)) |
| 7099 | goto nla_put_failure; |
| 7100 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 7101 | info->subcmd)) |
| 7102 | goto nla_put_failure; |
| 7103 | } |
| 7104 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7105 | data = nla_nest_start(skb, attr); |
| 7106 | |
| 7107 | ((void **)skb->cb)[0] = rdev; |
| 7108 | ((void **)skb->cb)[1] = hdr; |
| 7109 | ((void **)skb->cb)[2] = data; |
| 7110 | |
| 7111 | return skb; |
| 7112 | |
| 7113 | nla_put_failure: |
| 7114 | kfree_skb(skb); |
| 7115 | return NULL; |
| 7116 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 7117 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7118 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
| 7119 | enum nl80211_commands cmd, |
| 7120 | enum nl80211_attrs attr, |
| 7121 | int vendor_event_idx, |
| 7122 | int approxlen, gfp_t gfp) |
| 7123 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 7124 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7125 | const struct nl80211_vendor_cmd_info *info; |
| 7126 | |
| 7127 | switch (cmd) { |
| 7128 | case NL80211_CMD_TESTMODE: |
| 7129 | if (WARN_ON(vendor_event_idx != -1)) |
| 7130 | return NULL; |
| 7131 | info = NULL; |
| 7132 | break; |
| 7133 | case NL80211_CMD_VENDOR: |
| 7134 | if (WARN_ON(vendor_event_idx < 0 || |
| 7135 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 7136 | return NULL; |
| 7137 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 7138 | break; |
| 7139 | default: |
| 7140 | WARN_ON(1); |
| 7141 | return NULL; |
| 7142 | } |
| 7143 | |
| 7144 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, |
| 7145 | cmd, attr, info, gfp); |
| 7146 | } |
| 7147 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 7148 | |
| 7149 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 7150 | { |
| 7151 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 7152 | void *hdr = ((void **)skb->cb)[1]; |
| 7153 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 7154 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 7155 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 7156 | /* clear CB data for netlink core to own from now on */ |
| 7157 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 7158 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 7159 | nla_nest_end(skb, data); |
| 7160 | genlmsg_end(skb, hdr); |
| 7161 | |
| 7162 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 7163 | mcgrp = NL80211_MCGRP_VENDOR; |
| 7164 | |
| 7165 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 7166 | mcgrp, gfp); |
| 7167 | } |
| 7168 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 7169 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7170 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7171 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 7172 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7173 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7174 | struct wireless_dev *wdev = |
| 7175 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7176 | int err; |
| 7177 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7178 | if (!rdev->ops->testmode_cmd) |
| 7179 | return -EOPNOTSUPP; |
| 7180 | |
| 7181 | if (IS_ERR(wdev)) { |
| 7182 | err = PTR_ERR(wdev); |
| 7183 | if (err != -EINVAL) |
| 7184 | return err; |
| 7185 | wdev = NULL; |
| 7186 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 7187 | return -EINVAL; |
| 7188 | } |
| 7189 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7190 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 7191 | return -EINVAL; |
| 7192 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7193 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7194 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7195 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 7196 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7197 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7198 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7199 | return err; |
| 7200 | } |
| 7201 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7202 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 7203 | struct netlink_callback *cb) |
| 7204 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7205 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7206 | int err; |
| 7207 | long phy_idx; |
| 7208 | void *data = NULL; |
| 7209 | int data_len = 0; |
| 7210 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7211 | rtnl_lock(); |
| 7212 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7213 | if (cb->args[0]) { |
| 7214 | /* |
| 7215 | * 0 is a valid index, but not valid for args[0], |
| 7216 | * so we need to offset by 1. |
| 7217 | */ |
| 7218 | phy_idx = cb->args[0] - 1; |
| 7219 | } else { |
| 7220 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 7221 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 7222 | nl80211_policy); |
| 7223 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7224 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7225 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7226 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 7227 | nl80211_fam.attrbuf); |
| 7228 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7229 | err = PTR_ERR(rdev); |
| 7230 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7231 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7232 | phy_idx = rdev->wiphy_idx; |
| 7233 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7234 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7235 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 7236 | cb->args[1] = |
| 7237 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 7238 | } |
| 7239 | |
| 7240 | if (cb->args[1]) { |
| 7241 | data = nla_data((void *)cb->args[1]); |
| 7242 | data_len = nla_len((void *)cb->args[1]); |
| 7243 | } |
| 7244 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7245 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 7246 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7247 | err = -ENOENT; |
| 7248 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7249 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7250 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7251 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7252 | err = -EOPNOTSUPP; |
| 7253 | goto out_err; |
| 7254 | } |
| 7255 | |
| 7256 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7257 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7258 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 7259 | NL80211_CMD_TESTMODE); |
| 7260 | struct nlattr *tmdata; |
| 7261 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7262 | if (!hdr) |
| 7263 | break; |
| 7264 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7265 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7266 | genlmsg_cancel(skb, hdr); |
| 7267 | break; |
| 7268 | } |
| 7269 | |
| 7270 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 7271 | if (!tmdata) { |
| 7272 | genlmsg_cancel(skb, hdr); |
| 7273 | break; |
| 7274 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7275 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7276 | nla_nest_end(skb, tmdata); |
| 7277 | |
| 7278 | if (err == -ENOBUFS || err == -ENOENT) { |
| 7279 | genlmsg_cancel(skb, hdr); |
| 7280 | break; |
| 7281 | } else if (err) { |
| 7282 | genlmsg_cancel(skb, hdr); |
| 7283 | goto out_err; |
| 7284 | } |
| 7285 | |
| 7286 | genlmsg_end(skb, hdr); |
| 7287 | } |
| 7288 | |
| 7289 | err = skb->len; |
| 7290 | /* see above */ |
| 7291 | cb->args[0] = phy_idx + 1; |
| 7292 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7293 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7294 | return err; |
| 7295 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7296 | #endif |
| 7297 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7298 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 7299 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7300 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7301 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7302 | struct cfg80211_connect_params connect; |
| 7303 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7304 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7305 | int err; |
| 7306 | |
| 7307 | memset(&connect, 0, sizeof(connect)); |
| 7308 | |
| 7309 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7310 | return -EINVAL; |
| 7311 | |
| 7312 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 7313 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 7314 | return -EINVAL; |
| 7315 | |
| 7316 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 7317 | connect.auth_type = |
| 7318 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7319 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 7320 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7321 | return -EINVAL; |
| 7322 | } else |
| 7323 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 7324 | |
| 7325 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 7326 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7327 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7328 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7329 | if (err) |
| 7330 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7331 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7332 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7333 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7334 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7335 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7336 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7337 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 7338 | connect.bg_scan_period = -1; |
| 7339 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 7340 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 7341 | connect.bg_scan_period = |
| 7342 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 7343 | } |
| 7344 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7345 | if (info->attrs[NL80211_ATTR_MAC]) |
| 7346 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7347 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 7348 | connect.bssid_hint = |
| 7349 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7350 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7351 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7352 | |
| 7353 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7354 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7355 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7356 | } |
| 7357 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 7358 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 7359 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 7360 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 7361 | connect.mfp != NL80211_MFP_NO) |
| 7362 | return -EINVAL; |
| 7363 | } else { |
| 7364 | connect.mfp = NL80211_MFP_NO; |
| 7365 | } |
| 7366 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7367 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7368 | connect.channel = nl80211_get_valid_chan( |
| 7369 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7370 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7371 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7372 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7373 | connect.channel_hint = nl80211_get_valid_chan( |
| 7374 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 7375 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7376 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7377 | } |
| 7378 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7379 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 7380 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7381 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7382 | if (IS_ERR(connkeys)) |
| 7383 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7384 | } |
| 7385 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7386 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 7387 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 7388 | |
| 7389 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7390 | memcpy(&connect.ht_capa_mask, |
| 7391 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7392 | sizeof(connect.ht_capa_mask)); |
| 7393 | |
| 7394 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7395 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7396 | kzfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7397 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7398 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7399 | memcpy(&connect.ht_capa, |
| 7400 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7401 | sizeof(connect.ht_capa)); |
| 7402 | } |
| 7403 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7404 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 7405 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 7406 | |
| 7407 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 7408 | memcpy(&connect.vht_capa_mask, |
| 7409 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7410 | sizeof(connect.vht_capa_mask)); |
| 7411 | |
| 7412 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 7413 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7414 | kzfree(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7415 | return -EINVAL; |
| 7416 | } |
| 7417 | memcpy(&connect.vht_capa, |
| 7418 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7419 | sizeof(connect.vht_capa)); |
| 7420 | } |
| 7421 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 7422 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
| 7423 | if (!(rdev->wiphy.features & |
| 7424 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || |
| 7425 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) |
| 7426 | return -EINVAL; |
| 7427 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 7428 | } |
| 7429 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7430 | wdev_lock(dev->ieee80211_ptr); |
| 7431 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 7432 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7433 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7434 | kzfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7435 | return err; |
| 7436 | } |
| 7437 | |
| 7438 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 7439 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7440 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7441 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7442 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7443 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7444 | |
| 7445 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7446 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 7447 | else |
| 7448 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7449 | |
| 7450 | if (reason == 0) |
| 7451 | return -EINVAL; |
| 7452 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7453 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7454 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7455 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7456 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7457 | wdev_lock(dev->ieee80211_ptr); |
| 7458 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 7459 | wdev_unlock(dev->ieee80211_ptr); |
| 7460 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7461 | } |
| 7462 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7463 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 7464 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7465 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7466 | struct net *net; |
| 7467 | int err; |
| 7468 | u32 pid; |
| 7469 | |
| 7470 | if (!info->attrs[NL80211_ATTR_PID]) |
| 7471 | return -EINVAL; |
| 7472 | |
| 7473 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 7474 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7475 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7476 | if (IS_ERR(net)) |
| 7477 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7478 | |
| 7479 | err = 0; |
| 7480 | |
| 7481 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7482 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 7483 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7484 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7485 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7486 | return err; |
| 7487 | } |
| 7488 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7489 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7490 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7491 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7492 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 7493 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7494 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7495 | struct cfg80211_pmksa pmksa; |
| 7496 | |
| 7497 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 7498 | |
| 7499 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7500 | return -EINVAL; |
| 7501 | |
| 7502 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 7503 | return -EINVAL; |
| 7504 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7505 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 7506 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7507 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7508 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7509 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7510 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7511 | |
| 7512 | switch (info->genlhdr->cmd) { |
| 7513 | case NL80211_CMD_SET_PMKSA: |
| 7514 | rdev_ops = rdev->ops->set_pmksa; |
| 7515 | break; |
| 7516 | case NL80211_CMD_DEL_PMKSA: |
| 7517 | rdev_ops = rdev->ops->del_pmksa; |
| 7518 | break; |
| 7519 | default: |
| 7520 | WARN_ON(1); |
| 7521 | break; |
| 7522 | } |
| 7523 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7524 | if (!rdev_ops) |
| 7525 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7526 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7527 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7528 | } |
| 7529 | |
| 7530 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7531 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7532 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7533 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7534 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7535 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7536 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7537 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7538 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7539 | if (!rdev->ops->flush_pmksa) |
| 7540 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7541 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7542 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7543 | } |
| 7544 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7545 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 7546 | { |
| 7547 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7548 | struct net_device *dev = info->user_ptr[1]; |
| 7549 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7550 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7551 | u16 status_code; |
| 7552 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7553 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7554 | |
| 7555 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7556 | !rdev->ops->tdls_mgmt) |
| 7557 | return -EOPNOTSUPP; |
| 7558 | |
| 7559 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 7560 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 7561 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 7562 | !info->attrs[NL80211_ATTR_IE] || |
| 7563 | !info->attrs[NL80211_ATTR_MAC]) |
| 7564 | return -EINVAL; |
| 7565 | |
| 7566 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7567 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 7568 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 7569 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7570 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7571 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 7572 | peer_capability = |
| 7573 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7574 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7575 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7576 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7577 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7578 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 7579 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7580 | } |
| 7581 | |
| 7582 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 7583 | { |
| 7584 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7585 | struct net_device *dev = info->user_ptr[1]; |
| 7586 | enum nl80211_tdls_operation operation; |
| 7587 | u8 *peer; |
| 7588 | |
| 7589 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7590 | !rdev->ops->tdls_oper) |
| 7591 | return -EOPNOTSUPP; |
| 7592 | |
| 7593 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 7594 | !info->attrs[NL80211_ATTR_MAC]) |
| 7595 | return -EINVAL; |
| 7596 | |
| 7597 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 7598 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7599 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7600 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7601 | } |
| 7602 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7603 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 7604 | struct genl_info *info) |
| 7605 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7606 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7607 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7608 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7609 | struct sk_buff *msg; |
| 7610 | void *hdr; |
| 7611 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7612 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7613 | int err; |
| 7614 | |
| 7615 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7616 | !info->attrs[NL80211_ATTR_DURATION]) |
| 7617 | return -EINVAL; |
| 7618 | |
| 7619 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 7620 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7621 | if (!rdev->ops->remain_on_channel || |
| 7622 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7623 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7624 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7625 | /* |
| 7626 | * We should be on that channel for at least a minimum amount of |
| 7627 | * time (10ms) but no longer than the driver supports. |
| 7628 | */ |
| 7629 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7630 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 7631 | return -EINVAL; |
| 7632 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7633 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7634 | if (err) |
| 7635 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7636 | |
| 7637 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7638 | if (!msg) |
| 7639 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7640 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7641 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7642 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7643 | if (!hdr) { |
| 7644 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7645 | goto free_msg; |
| 7646 | } |
| 7647 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7648 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 7649 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7650 | |
| 7651 | if (err) |
| 7652 | goto free_msg; |
| 7653 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7654 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7655 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7656 | |
| 7657 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7658 | |
| 7659 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7660 | |
| 7661 | nla_put_failure: |
| 7662 | err = -ENOBUFS; |
| 7663 | free_msg: |
| 7664 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7665 | return err; |
| 7666 | } |
| 7667 | |
| 7668 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 7669 | struct genl_info *info) |
| 7670 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7671 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7672 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7673 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7674 | |
| 7675 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7676 | return -EINVAL; |
| 7677 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7678 | if (!rdev->ops->cancel_remain_on_channel) |
| 7679 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7680 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7681 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7682 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7683 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7684 | } |
| 7685 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7686 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7687 | u8 *rates, u8 rates_len) |
| 7688 | { |
| 7689 | u8 i; |
| 7690 | u32 mask = 0; |
| 7691 | |
| 7692 | for (i = 0; i < rates_len; i++) { |
| 7693 | int rate = (rates[i] & 0x7f) * 5; |
| 7694 | int ridx; |
| 7695 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 7696 | struct ieee80211_rate *srate = |
| 7697 | &sband->bitrates[ridx]; |
| 7698 | if (rate == srate->bitrate) { |
| 7699 | mask |= 1 << ridx; |
| 7700 | break; |
| 7701 | } |
| 7702 | } |
| 7703 | if (ridx == sband->n_bitrates) |
| 7704 | return 0; /* rate not found */ |
| 7705 | } |
| 7706 | |
| 7707 | return mask; |
| 7708 | } |
| 7709 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7710 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7711 | u8 *rates, u8 rates_len, |
| 7712 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 7713 | { |
| 7714 | u8 i; |
| 7715 | |
| 7716 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 7717 | |
| 7718 | for (i = 0; i < rates_len; i++) { |
| 7719 | int ridx, rbit; |
| 7720 | |
| 7721 | ridx = rates[i] / 8; |
| 7722 | rbit = BIT(rates[i] % 8); |
| 7723 | |
| 7724 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7725 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7726 | return false; |
| 7727 | |
| 7728 | /* check availability */ |
| 7729 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7730 | mcs[ridx] |= rbit; |
| 7731 | else |
| 7732 | return false; |
| 7733 | } |
| 7734 | |
| 7735 | return true; |
| 7736 | } |
| 7737 | |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7738 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 7739 | { |
| 7740 | u16 mcs_mask = 0; |
| 7741 | |
| 7742 | switch (vht_mcs_map) { |
| 7743 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 7744 | break; |
| 7745 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 7746 | mcs_mask = 0x00FF; |
| 7747 | break; |
| 7748 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 7749 | mcs_mask = 0x01FF; |
| 7750 | break; |
| 7751 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 7752 | mcs_mask = 0x03FF; |
| 7753 | break; |
| 7754 | default: |
| 7755 | break; |
| 7756 | } |
| 7757 | |
| 7758 | return mcs_mask; |
| 7759 | } |
| 7760 | |
| 7761 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 7762 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 7763 | { |
| 7764 | u8 nss; |
| 7765 | |
| 7766 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 7767 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 7768 | vht_mcs_map >>= 2; |
| 7769 | } |
| 7770 | } |
| 7771 | |
| 7772 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 7773 | struct nl80211_txrate_vht *txrate, |
| 7774 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 7775 | { |
| 7776 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7777 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 7778 | u8 i; |
| 7779 | |
| 7780 | if (!sband->vht_cap.vht_supported) |
| 7781 | return false; |
| 7782 | |
| 7783 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 7784 | |
| 7785 | /* Build vht_mcs_mask from VHT capabilities */ |
| 7786 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 7787 | |
| 7788 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 7789 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 7790 | mcs[i] = txrate->mcs[i]; |
| 7791 | else |
| 7792 | return false; |
| 7793 | } |
| 7794 | |
| 7795 | return true; |
| 7796 | } |
| 7797 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7798 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7799 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7800 | .len = NL80211_MAX_SUPP_RATES }, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7801 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 7802 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7803 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 7804 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7805 | }; |
| 7806 | |
| 7807 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7808 | struct genl_info *info) |
| 7809 | { |
| 7810 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7811 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7812 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7813 | int rem, i; |
| 7814 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7815 | struct nlattr *tx_rates; |
| 7816 | struct ieee80211_supported_band *sband; |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7817 | u16 vht_tx_mcs_map; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7818 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7819 | if (!rdev->ops->set_bitrate_mask) |
| 7820 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7821 | |
| 7822 | memset(&mask, 0, sizeof(mask)); |
| 7823 | /* Default to all rates enabled */ |
| 7824 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7825 | sband = rdev->wiphy.bands[i]; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7826 | |
| 7827 | if (!sband) |
| 7828 | continue; |
| 7829 | |
| 7830 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7831 | memcpy(mask.control[i].ht_mcs, |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7832 | sband->ht_cap.mcs.rx_mask, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7833 | sizeof(mask.control[i].ht_mcs)); |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7834 | |
| 7835 | if (!sband->vht_cap.vht_supported) |
| 7836 | continue; |
| 7837 | |
| 7838 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7839 | 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] | 7840 | } |
| 7841 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7842 | /* if no rates are given set it back to the defaults */ |
| 7843 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 7844 | goto out; |
| 7845 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7846 | /* |
| 7847 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7848 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7849 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7850 | 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] | 7851 | 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] | 7852 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7853 | int err; |
| 7854 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7855 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7856 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7857 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7858 | if (sband == NULL) |
| 7859 | return -EINVAL; |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7860 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7861 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7862 | if (err) |
| 7863 | return err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7864 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7865 | mask.control[band].legacy = rateset_to_mask( |
| 7866 | sband, |
| 7867 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7868 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7869 | if ((mask.control[band].legacy == 0) && |
| 7870 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7871 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7872 | } |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7873 | if (tb[NL80211_TXRATE_HT]) { |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7874 | if (!ht_rateset_to_mask( |
| 7875 | sband, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7876 | nla_data(tb[NL80211_TXRATE_HT]), |
| 7877 | nla_len(tb[NL80211_TXRATE_HT]), |
| 7878 | mask.control[band].ht_mcs)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7879 | return -EINVAL; |
| 7880 | } |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7881 | if (tb[NL80211_TXRATE_VHT]) { |
| 7882 | if (!vht_set_mcs_mask( |
| 7883 | sband, |
| 7884 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 7885 | mask.control[band].vht_mcs)) |
| 7886 | return -EINVAL; |
| 7887 | } |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 7888 | if (tb[NL80211_TXRATE_GI]) { |
| 7889 | mask.control[band].gi = |
| 7890 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 7891 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 7892 | return -EINVAL; |
| 7893 | } |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7894 | |
| 7895 | if (mask.control[band].legacy == 0) { |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7896 | /* don't allow empty legacy rates if HT or VHT |
| 7897 | * are not even supported. |
| 7898 | */ |
| 7899 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 7900 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7901 | return -EINVAL; |
| 7902 | |
| 7903 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7904 | if (mask.control[band].ht_mcs[i]) |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7905 | goto out; |
| 7906 | |
| 7907 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 7908 | if (mask.control[band].vht_mcs[i]) |
| 7909 | goto out; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7910 | |
| 7911 | /* legacy and mcs rates may not be both empty */ |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7912 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7913 | } |
| 7914 | } |
| 7915 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7916 | out: |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7917 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7918 | } |
| 7919 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7920 | 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] | 7921 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7922 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7923 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7924 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7925 | |
| 7926 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7927 | return -EINVAL; |
| 7928 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7929 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7930 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7931 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7932 | switch (wdev->iftype) { |
| 7933 | case NL80211_IFTYPE_STATION: |
| 7934 | case NL80211_IFTYPE_ADHOC: |
| 7935 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7936 | case NL80211_IFTYPE_AP: |
| 7937 | case NL80211_IFTYPE_AP_VLAN: |
| 7938 | case NL80211_IFTYPE_MESH_POINT: |
| 7939 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7940 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7941 | break; |
| 7942 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7943 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7944 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7945 | |
| 7946 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7947 | if (!rdev->ops->mgmt_tx) |
| 7948 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7949 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7950 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7951 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7952 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7953 | } |
| 7954 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7955 | 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] | 7956 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7957 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7958 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7959 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7960 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7961 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7962 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7963 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7964 | struct cfg80211_mgmt_tx_params params = { |
| 7965 | .dont_wait_for_ack = |
| 7966 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 7967 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7968 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7969 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7970 | return -EINVAL; |
| 7971 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7972 | if (!rdev->ops->mgmt_tx) |
| 7973 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7974 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7975 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7976 | case NL80211_IFTYPE_P2P_DEVICE: |
| 7977 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7978 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7979 | case NL80211_IFTYPE_STATION: |
| 7980 | case NL80211_IFTYPE_ADHOC: |
| 7981 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7982 | case NL80211_IFTYPE_AP: |
| 7983 | case NL80211_IFTYPE_AP_VLAN: |
| 7984 | case NL80211_IFTYPE_MESH_POINT: |
| 7985 | case NL80211_IFTYPE_P2P_GO: |
| 7986 | break; |
| 7987 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7988 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7989 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7990 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7991 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7992 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7993 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7994 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7995 | |
| 7996 | /* |
| 7997 | * We should wait on the channel for at least a minimum amount |
| 7998 | * of time (10ms) but no longer than the driver supports. |
| 7999 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8000 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 8001 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 8002 | return -EINVAL; |
| 8003 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8004 | } |
| 8005 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8006 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8007 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8008 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 8009 | return -EINVAL; |
| 8010 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8011 | 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] | 8012 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8013 | /* get the channel if any has been specified, otherwise pass NULL to |
| 8014 | * the driver. The latter will use the current one |
| 8015 | */ |
| 8016 | chandef.chan = NULL; |
| 8017 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 8018 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8019 | if (err) |
| 8020 | return err; |
| 8021 | } |
| 8022 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8023 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 8024 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8025 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 8026 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 8027 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 8028 | |
| 8029 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 8030 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 8031 | int i; |
| 8032 | |
| 8033 | if (len % sizeof(u16)) |
| 8034 | return -EINVAL; |
| 8035 | |
| 8036 | params.n_csa_offsets = len / sizeof(u16); |
| 8037 | params.csa_offsets = |
| 8038 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 8039 | |
| 8040 | /* check that all the offsets fit the frame */ |
| 8041 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 8042 | if (params.csa_offsets[i] >= params.len) |
| 8043 | return -EINVAL; |
| 8044 | } |
| 8045 | } |
| 8046 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8047 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8048 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8049 | if (!msg) |
| 8050 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8051 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8052 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8053 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 8054 | if (!hdr) { |
| 8055 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8056 | goto free_msg; |
| 8057 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8058 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8059 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 8060 | params.chan = chandef.chan; |
| 8061 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8062 | if (err) |
| 8063 | goto free_msg; |
| 8064 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8065 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8066 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 8067 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8068 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 8069 | genlmsg_end(msg, hdr); |
| 8070 | return genlmsg_reply(msg, info); |
| 8071 | } |
| 8072 | |
| 8073 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8074 | |
| 8075 | nla_put_failure: |
| 8076 | err = -ENOBUFS; |
| 8077 | free_msg: |
| 8078 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 8079 | return err; |
| 8080 | } |
| 8081 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8082 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 8083 | { |
| 8084 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8085 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8086 | u64 cookie; |
| 8087 | |
| 8088 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 8089 | return -EINVAL; |
| 8090 | |
| 8091 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 8092 | return -EOPNOTSUPP; |
| 8093 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8094 | switch (wdev->iftype) { |
| 8095 | case NL80211_IFTYPE_STATION: |
| 8096 | case NL80211_IFTYPE_ADHOC: |
| 8097 | case NL80211_IFTYPE_P2P_CLIENT: |
| 8098 | case NL80211_IFTYPE_AP: |
| 8099 | case NL80211_IFTYPE_AP_VLAN: |
| 8100 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 8101 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8102 | break; |
| 8103 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8104 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 8105 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8106 | |
| 8107 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 8108 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8109 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 8110 | } |
| 8111 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8112 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 8113 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8114 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8115 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8116 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8117 | u8 ps_state; |
| 8118 | bool state; |
| 8119 | int err; |
| 8120 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8121 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 8122 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8123 | |
| 8124 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 8125 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8126 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 8127 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8128 | |
| 8129 | wdev = dev->ieee80211_ptr; |
| 8130 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8131 | if (!rdev->ops->set_power_mgmt) |
| 8132 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8133 | |
| 8134 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 8135 | |
| 8136 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8137 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8138 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8139 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8140 | if (!err) |
| 8141 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8142 | return err; |
| 8143 | } |
| 8144 | |
| 8145 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 8146 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8147 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8148 | enum nl80211_ps_state ps_state; |
| 8149 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8150 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8151 | struct sk_buff *msg; |
| 8152 | void *hdr; |
| 8153 | int err; |
| 8154 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8155 | wdev = dev->ieee80211_ptr; |
| 8156 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8157 | if (!rdev->ops->set_power_mgmt) |
| 8158 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8159 | |
| 8160 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8161 | if (!msg) |
| 8162 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8163 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8164 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8165 | NL80211_CMD_GET_POWER_SAVE); |
| 8166 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8167 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8168 | goto free_msg; |
| 8169 | } |
| 8170 | |
| 8171 | if (wdev->ps) |
| 8172 | ps_state = NL80211_PS_ENABLED; |
| 8173 | else |
| 8174 | ps_state = NL80211_PS_DISABLED; |
| 8175 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8176 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 8177 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8178 | |
| 8179 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8180 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8181 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8182 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8183 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8184 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8185 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8186 | return err; |
| 8187 | } |
| 8188 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 8189 | static const struct nla_policy |
| 8190 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8191 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 8192 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 8193 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8194 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 8195 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 8196 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8197 | }; |
| 8198 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8199 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8200 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8201 | { |
| 8202 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8203 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8204 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8205 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8206 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8207 | return -EINVAL; |
| 8208 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8209 | if (!rdev->ops->set_cqm_txe_config) |
| 8210 | return -EOPNOTSUPP; |
| 8211 | |
| 8212 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 8213 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8214 | return -EOPNOTSUPP; |
| 8215 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8216 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8217 | } |
| 8218 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8219 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 8220 | s32 threshold, u32 hysteresis) |
| 8221 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8222 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8223 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8224 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8225 | |
| 8226 | if (threshold > 0) |
| 8227 | return -EINVAL; |
| 8228 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8229 | /* disabling - hysteresis should also be zero then */ |
| 8230 | if (threshold == 0) |
| 8231 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8232 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8233 | if (!rdev->ops->set_cqm_rssi_config) |
| 8234 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8235 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8236 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8237 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8238 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8239 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8240 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8241 | } |
| 8242 | |
| 8243 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 8244 | { |
| 8245 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 8246 | struct nlattr *cqm; |
| 8247 | int err; |
| 8248 | |
| 8249 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8250 | if (!cqm) |
| 8251 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8252 | |
| 8253 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 8254 | nl80211_attr_cqm_policy); |
| 8255 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8256 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8257 | |
| 8258 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 8259 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8260 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 8261 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8262 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8263 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 8264 | } |
| 8265 | |
| 8266 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 8267 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 8268 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 8269 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 8270 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 8271 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 8272 | |
| 8273 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 8274 | } |
| 8275 | |
| 8276 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8277 | } |
| 8278 | |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame^] | 8279 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 8280 | { |
| 8281 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8282 | struct net_device *dev = info->user_ptr[1]; |
| 8283 | struct ocb_setup setup = {}; |
| 8284 | int err; |
| 8285 | |
| 8286 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 8287 | if (err) |
| 8288 | return err; |
| 8289 | |
| 8290 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 8291 | } |
| 8292 | |
| 8293 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 8294 | { |
| 8295 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8296 | struct net_device *dev = info->user_ptr[1]; |
| 8297 | |
| 8298 | return cfg80211_leave_ocb(rdev, dev); |
| 8299 | } |
| 8300 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8301 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8302 | { |
| 8303 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8304 | struct net_device *dev = info->user_ptr[1]; |
| 8305 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8306 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8307 | int err; |
| 8308 | |
| 8309 | /* start with default */ |
| 8310 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8311 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8312 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8313 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8314 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8315 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8316 | if (err) |
| 8317 | return err; |
| 8318 | } |
| 8319 | |
| 8320 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 8321 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 8322 | return -EINVAL; |
| 8323 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8324 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8325 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8326 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 8327 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 8328 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 8329 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 8330 | return -EINVAL; |
| 8331 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 8332 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 8333 | setup.beacon_interval = |
| 8334 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 8335 | if (setup.beacon_interval < 10 || |
| 8336 | setup.beacon_interval > 10000) |
| 8337 | return -EINVAL; |
| 8338 | } |
| 8339 | |
| 8340 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 8341 | setup.dtim_period = |
| 8342 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 8343 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 8344 | return -EINVAL; |
| 8345 | } |
| 8346 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8347 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 8348 | /* parse additional setup parameters if given */ |
| 8349 | err = nl80211_parse_mesh_setup(info, &setup); |
| 8350 | if (err) |
| 8351 | return err; |
| 8352 | } |
| 8353 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 8354 | if (setup.user_mpm) |
| 8355 | cfg.auto_open_plinks = false; |
| 8356 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8357 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8358 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 8359 | if (err) |
| 8360 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8361 | } else { |
| 8362 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8363 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8364 | } |
| 8365 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 8366 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 8367 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8368 | int n_rates = |
| 8369 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8370 | struct ieee80211_supported_band *sband; |
| 8371 | |
| 8372 | if (!setup.chandef.chan) |
| 8373 | return -EINVAL; |
| 8374 | |
| 8375 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 8376 | |
| 8377 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 8378 | &setup.basic_rates); |
| 8379 | if (err) |
| 8380 | return err; |
| 8381 | } |
| 8382 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8383 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8384 | } |
| 8385 | |
| 8386 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8387 | { |
| 8388 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8389 | struct net_device *dev = info->user_ptr[1]; |
| 8390 | |
| 8391 | return cfg80211_leave_mesh(rdev, dev); |
| 8392 | } |
| 8393 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8394 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8395 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 8396 | struct cfg80211_registered_device *rdev) |
| 8397 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8398 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8399 | struct nlattr *nl_pats, *nl_pat; |
| 8400 | int i, pat_len; |
| 8401 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8402 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8403 | return 0; |
| 8404 | |
| 8405 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 8406 | if (!nl_pats) |
| 8407 | return -ENOBUFS; |
| 8408 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8409 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8410 | nl_pat = nla_nest_start(msg, i + 1); |
| 8411 | if (!nl_pat) |
| 8412 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8413 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8414 | 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] | 8415 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8416 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8417 | wowlan->patterns[i].pattern) || |
| 8418 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8419 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8420 | return -ENOBUFS; |
| 8421 | nla_nest_end(msg, nl_pat); |
| 8422 | } |
| 8423 | nla_nest_end(msg, nl_pats); |
| 8424 | |
| 8425 | return 0; |
| 8426 | } |
| 8427 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8428 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 8429 | struct cfg80211_wowlan_tcp *tcp) |
| 8430 | { |
| 8431 | struct nlattr *nl_tcp; |
| 8432 | |
| 8433 | if (!tcp) |
| 8434 | return 0; |
| 8435 | |
| 8436 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 8437 | if (!nl_tcp) |
| 8438 | return -ENOBUFS; |
| 8439 | |
| 8440 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 8441 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 8442 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 8443 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 8444 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 8445 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 8446 | tcp->payload_len, tcp->payload) || |
| 8447 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 8448 | tcp->data_interval) || |
| 8449 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 8450 | tcp->wake_len, tcp->wake_data) || |
| 8451 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 8452 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 8453 | return -ENOBUFS; |
| 8454 | |
| 8455 | if (tcp->payload_seq.len && |
| 8456 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 8457 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 8458 | return -ENOBUFS; |
| 8459 | |
| 8460 | if (tcp->payload_tok.len && |
| 8461 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 8462 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 8463 | &tcp->payload_tok)) |
| 8464 | return -ENOBUFS; |
| 8465 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 8466 | nla_nest_end(msg, nl_tcp); |
| 8467 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8468 | return 0; |
| 8469 | } |
| 8470 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8471 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8472 | { |
| 8473 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8474 | struct sk_buff *msg; |
| 8475 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8476 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8477 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8478 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8479 | return -EOPNOTSUPP; |
| 8480 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8481 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8482 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8483 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 8484 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 8485 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 8486 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8487 | } |
| 8488 | |
| 8489 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8490 | if (!msg) |
| 8491 | return -ENOMEM; |
| 8492 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8493 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8494 | NL80211_CMD_GET_WOWLAN); |
| 8495 | if (!hdr) |
| 8496 | goto nla_put_failure; |
| 8497 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8498 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8499 | struct nlattr *nl_wowlan; |
| 8500 | |
| 8501 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 8502 | if (!nl_wowlan) |
| 8503 | goto nla_put_failure; |
| 8504 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8505 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8506 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8507 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8508 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8509 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8510 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8511 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8512 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8513 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8514 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8515 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8516 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8517 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8518 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 8519 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8520 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8521 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 8522 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8523 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8524 | if (nl80211_send_wowlan_tcp(msg, |
| 8525 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8526 | goto nla_put_failure; |
| 8527 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8528 | nla_nest_end(msg, nl_wowlan); |
| 8529 | } |
| 8530 | |
| 8531 | genlmsg_end(msg, hdr); |
| 8532 | return genlmsg_reply(msg, info); |
| 8533 | |
| 8534 | nla_put_failure: |
| 8535 | nlmsg_free(msg); |
| 8536 | return -ENOBUFS; |
| 8537 | } |
| 8538 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8539 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 8540 | struct nlattr *attr, |
| 8541 | struct cfg80211_wowlan *trig) |
| 8542 | { |
| 8543 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 8544 | struct cfg80211_wowlan_tcp *cfg; |
| 8545 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 8546 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 8547 | u32 size; |
| 8548 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 8549 | int err, port; |
| 8550 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8551 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8552 | return -EINVAL; |
| 8553 | |
| 8554 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 8555 | nla_data(attr), nla_len(attr), |
| 8556 | nl80211_wowlan_tcp_policy); |
| 8557 | if (err) |
| 8558 | return err; |
| 8559 | |
| 8560 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 8561 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 8562 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 8563 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 8564 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 8565 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 8566 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 8567 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 8568 | return -EINVAL; |
| 8569 | |
| 8570 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8571 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8572 | return -EINVAL; |
| 8573 | |
| 8574 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8575 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 8576 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8577 | return -EINVAL; |
| 8578 | |
| 8579 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8580 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8581 | return -EINVAL; |
| 8582 | |
| 8583 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 8584 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 8585 | return -EINVAL; |
| 8586 | |
| 8587 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 8588 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8589 | |
| 8590 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8591 | tokens_size = tokln - sizeof(*tok); |
| 8592 | |
| 8593 | if (!tok->len || tokens_size % tok->len) |
| 8594 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8595 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8596 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8597 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8598 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8599 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8600 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8601 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8602 | return -EINVAL; |
| 8603 | if (tok->offset + tok->len > data_size) |
| 8604 | return -EINVAL; |
| 8605 | } |
| 8606 | |
| 8607 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 8608 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8609 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8610 | return -EINVAL; |
| 8611 | if (seq->len == 0 || seq->len > 4) |
| 8612 | return -EINVAL; |
| 8613 | if (seq->len + seq->offset > data_size) |
| 8614 | return -EINVAL; |
| 8615 | } |
| 8616 | |
| 8617 | size = sizeof(*cfg); |
| 8618 | size += data_size; |
| 8619 | size += wake_size + wake_mask_size; |
| 8620 | size += tokens_size; |
| 8621 | |
| 8622 | cfg = kzalloc(size, GFP_KERNEL); |
| 8623 | if (!cfg) |
| 8624 | return -ENOMEM; |
| 8625 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 8626 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 8627 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 8628 | ETH_ALEN); |
| 8629 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 8630 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 8631 | else |
| 8632 | port = 0; |
| 8633 | #ifdef CONFIG_INET |
| 8634 | /* allocate a socket and port for it and use it */ |
| 8635 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 8636 | IPPROTO_TCP, &cfg->sock, 1); |
| 8637 | if (err) { |
| 8638 | kfree(cfg); |
| 8639 | return err; |
| 8640 | } |
| 8641 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 8642 | sock_release(cfg->sock); |
| 8643 | kfree(cfg); |
| 8644 | return -EADDRINUSE; |
| 8645 | } |
| 8646 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 8647 | #else |
| 8648 | if (!port) { |
| 8649 | kfree(cfg); |
| 8650 | return -EINVAL; |
| 8651 | } |
| 8652 | cfg->src_port = port; |
| 8653 | #endif |
| 8654 | |
| 8655 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 8656 | cfg->payload_len = data_size; |
| 8657 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 8658 | memcpy((void *)cfg->payload, |
| 8659 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 8660 | data_size); |
| 8661 | if (seq) |
| 8662 | cfg->payload_seq = *seq; |
| 8663 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 8664 | cfg->wake_len = wake_size; |
| 8665 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 8666 | memcpy((void *)cfg->wake_data, |
| 8667 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 8668 | wake_size); |
| 8669 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 8670 | data_size + wake_size; |
| 8671 | memcpy((void *)cfg->wake_mask, |
| 8672 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 8673 | wake_mask_size); |
| 8674 | if (tok) { |
| 8675 | cfg->tokens_size = tokens_size; |
| 8676 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 8677 | } |
| 8678 | |
| 8679 | trig->tcp = cfg; |
| 8680 | |
| 8681 | return 0; |
| 8682 | } |
| 8683 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8684 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8685 | { |
| 8686 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8687 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8688 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8689 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8690 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8691 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8692 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8693 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8694 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8695 | return -EOPNOTSUPP; |
| 8696 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8697 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 8698 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8699 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8700 | goto set_wakeup; |
| 8701 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8702 | |
| 8703 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 8704 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8705 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8706 | nl80211_wowlan_policy); |
| 8707 | if (err) |
| 8708 | return err; |
| 8709 | |
| 8710 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 8711 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 8712 | return -EINVAL; |
| 8713 | new_triggers.any = true; |
| 8714 | } |
| 8715 | |
| 8716 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 8717 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 8718 | return -EINVAL; |
| 8719 | new_triggers.disconnect = true; |
| 8720 | } |
| 8721 | |
| 8722 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 8723 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 8724 | return -EINVAL; |
| 8725 | new_triggers.magic_pkt = true; |
| 8726 | } |
| 8727 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 8728 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 8729 | return -EINVAL; |
| 8730 | |
| 8731 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 8732 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 8733 | return -EINVAL; |
| 8734 | new_triggers.gtk_rekey_failure = true; |
| 8735 | } |
| 8736 | |
| 8737 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 8738 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 8739 | return -EINVAL; |
| 8740 | new_triggers.eap_identity_req = true; |
| 8741 | } |
| 8742 | |
| 8743 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 8744 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 8745 | return -EINVAL; |
| 8746 | new_triggers.four_way_handshake = true; |
| 8747 | } |
| 8748 | |
| 8749 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 8750 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 8751 | return -EINVAL; |
| 8752 | new_triggers.rfkill_release = true; |
| 8753 | } |
| 8754 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8755 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 8756 | struct nlattr *pat; |
| 8757 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8758 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8759 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8760 | |
| 8761 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8762 | rem) |
| 8763 | n_patterns++; |
| 8764 | if (n_patterns > wowlan->n_patterns) |
| 8765 | return -EINVAL; |
| 8766 | |
| 8767 | new_triggers.patterns = kcalloc(n_patterns, |
| 8768 | sizeof(new_triggers.patterns[0]), |
| 8769 | GFP_KERNEL); |
| 8770 | if (!new_triggers.patterns) |
| 8771 | return -ENOMEM; |
| 8772 | |
| 8773 | new_triggers.n_patterns = n_patterns; |
| 8774 | i = 0; |
| 8775 | |
| 8776 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8777 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8778 | u8 *mask_pat; |
| 8779 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8780 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8781 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8782 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8783 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8784 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8785 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8786 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8787 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8788 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8789 | goto error; |
| 8790 | if (pat_len > wowlan->pattern_max_len || |
| 8791 | pat_len < wowlan->pattern_min_len) |
| 8792 | goto error; |
| 8793 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8794 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8795 | pkt_offset = 0; |
| 8796 | else |
| 8797 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8798 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8799 | if (pkt_offset > wowlan->max_pkt_offset) |
| 8800 | goto error; |
| 8801 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 8802 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8803 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8804 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8805 | err = -ENOMEM; |
| 8806 | goto error; |
| 8807 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8808 | new_triggers.patterns[i].mask = mask_pat; |
| 8809 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8810 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8811 | mask_pat += mask_len; |
| 8812 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8813 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8814 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8815 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8816 | pat_len); |
| 8817 | i++; |
| 8818 | } |
| 8819 | } |
| 8820 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8821 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 8822 | err = nl80211_parse_wowlan_tcp( |
| 8823 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 8824 | &new_triggers); |
| 8825 | if (err) |
| 8826 | goto error; |
| 8827 | } |
| 8828 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8829 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 8830 | if (!ntrig) { |
| 8831 | err = -ENOMEM; |
| 8832 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8833 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8834 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8835 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8836 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8837 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8838 | if (rdev->ops->set_wakeup && |
| 8839 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 8840 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 8841 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8842 | return 0; |
| 8843 | error: |
| 8844 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 8845 | kfree(new_triggers.patterns[i].mask); |
| 8846 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8847 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 8848 | sock_release(new_triggers.tcp->sock); |
| 8849 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8850 | return err; |
| 8851 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8852 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8853 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8854 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 8855 | struct cfg80211_registered_device *rdev) |
| 8856 | { |
| 8857 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 8858 | int i, j, pat_len; |
| 8859 | struct cfg80211_coalesce_rules *rule; |
| 8860 | |
| 8861 | if (!rdev->coalesce->n_rules) |
| 8862 | return 0; |
| 8863 | |
| 8864 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 8865 | if (!nl_rules) |
| 8866 | return -ENOBUFS; |
| 8867 | |
| 8868 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 8869 | nl_rule = nla_nest_start(msg, i + 1); |
| 8870 | if (!nl_rule) |
| 8871 | return -ENOBUFS; |
| 8872 | |
| 8873 | rule = &rdev->coalesce->rules[i]; |
| 8874 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 8875 | rule->delay)) |
| 8876 | return -ENOBUFS; |
| 8877 | |
| 8878 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 8879 | rule->condition)) |
| 8880 | return -ENOBUFS; |
| 8881 | |
| 8882 | nl_pats = nla_nest_start(msg, |
| 8883 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 8884 | if (!nl_pats) |
| 8885 | return -ENOBUFS; |
| 8886 | |
| 8887 | for (j = 0; j < rule->n_patterns; j++) { |
| 8888 | nl_pat = nla_nest_start(msg, j + 1); |
| 8889 | if (!nl_pat) |
| 8890 | return -ENOBUFS; |
| 8891 | pat_len = rule->patterns[j].pattern_len; |
| 8892 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 8893 | DIV_ROUND_UP(pat_len, 8), |
| 8894 | rule->patterns[j].mask) || |
| 8895 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8896 | rule->patterns[j].pattern) || |
| 8897 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 8898 | rule->patterns[j].pkt_offset)) |
| 8899 | return -ENOBUFS; |
| 8900 | nla_nest_end(msg, nl_pat); |
| 8901 | } |
| 8902 | nla_nest_end(msg, nl_pats); |
| 8903 | nla_nest_end(msg, nl_rule); |
| 8904 | } |
| 8905 | nla_nest_end(msg, nl_rules); |
| 8906 | |
| 8907 | return 0; |
| 8908 | } |
| 8909 | |
| 8910 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8911 | { |
| 8912 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8913 | struct sk_buff *msg; |
| 8914 | void *hdr; |
| 8915 | |
| 8916 | if (!rdev->wiphy.coalesce) |
| 8917 | return -EOPNOTSUPP; |
| 8918 | |
| 8919 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8920 | if (!msg) |
| 8921 | return -ENOMEM; |
| 8922 | |
| 8923 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8924 | NL80211_CMD_GET_COALESCE); |
| 8925 | if (!hdr) |
| 8926 | goto nla_put_failure; |
| 8927 | |
| 8928 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 8929 | goto nla_put_failure; |
| 8930 | |
| 8931 | genlmsg_end(msg, hdr); |
| 8932 | return genlmsg_reply(msg, info); |
| 8933 | |
| 8934 | nla_put_failure: |
| 8935 | nlmsg_free(msg); |
| 8936 | return -ENOBUFS; |
| 8937 | } |
| 8938 | |
| 8939 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 8940 | { |
| 8941 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 8942 | int i, j; |
| 8943 | struct cfg80211_coalesce_rules *rule; |
| 8944 | |
| 8945 | if (!coalesce) |
| 8946 | return; |
| 8947 | |
| 8948 | for (i = 0; i < coalesce->n_rules; i++) { |
| 8949 | rule = &coalesce->rules[i]; |
| 8950 | for (j = 0; j < rule->n_patterns; j++) |
| 8951 | kfree(rule->patterns[j].mask); |
| 8952 | kfree(rule->patterns); |
| 8953 | } |
| 8954 | kfree(coalesce->rules); |
| 8955 | kfree(coalesce); |
| 8956 | rdev->coalesce = NULL; |
| 8957 | } |
| 8958 | |
| 8959 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 8960 | struct nlattr *rule, |
| 8961 | struct cfg80211_coalesce_rules *new_rule) |
| 8962 | { |
| 8963 | int err, i; |
| 8964 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8965 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 8966 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 8967 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 8968 | |
| 8969 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 8970 | nla_len(rule), nl80211_coalesce_policy); |
| 8971 | if (err) |
| 8972 | return err; |
| 8973 | |
| 8974 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 8975 | new_rule->delay = |
| 8976 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 8977 | if (new_rule->delay > coalesce->max_delay) |
| 8978 | return -EINVAL; |
| 8979 | |
| 8980 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 8981 | new_rule->condition = |
| 8982 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 8983 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 8984 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 8985 | return -EINVAL; |
| 8986 | |
| 8987 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 8988 | return -EINVAL; |
| 8989 | |
| 8990 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8991 | rem) |
| 8992 | n_patterns++; |
| 8993 | if (n_patterns > coalesce->n_patterns) |
| 8994 | return -EINVAL; |
| 8995 | |
| 8996 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 8997 | GFP_KERNEL); |
| 8998 | if (!new_rule->patterns) |
| 8999 | return -ENOMEM; |
| 9000 | |
| 9001 | new_rule->n_patterns = n_patterns; |
| 9002 | i = 0; |
| 9003 | |
| 9004 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 9005 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9006 | u8 *mask_pat; |
| 9007 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9008 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 9009 | nla_len(pat), NULL); |
| 9010 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 9011 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 9012 | return -EINVAL; |
| 9013 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 9014 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 9015 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 9016 | return -EINVAL; |
| 9017 | if (pat_len > coalesce->pattern_max_len || |
| 9018 | pat_len < coalesce->pattern_min_len) |
| 9019 | return -EINVAL; |
| 9020 | |
| 9021 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 9022 | pkt_offset = 0; |
| 9023 | else |
| 9024 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 9025 | if (pkt_offset > coalesce->max_pkt_offset) |
| 9026 | return -EINVAL; |
| 9027 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 9028 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9029 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 9030 | if (!mask_pat) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9031 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9032 | |
| 9033 | new_rule->patterns[i].mask = mask_pat; |
| 9034 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 9035 | mask_len); |
| 9036 | |
| 9037 | mask_pat += mask_len; |
| 9038 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9039 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 9040 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 9041 | pat_len); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 9042 | i++; |
| 9043 | } |
| 9044 | |
| 9045 | return 0; |
| 9046 | } |
| 9047 | |
| 9048 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 9049 | { |
| 9050 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9051 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 9052 | struct cfg80211_coalesce new_coalesce = {}; |
| 9053 | struct cfg80211_coalesce *n_coalesce; |
| 9054 | int err, rem_rule, n_rules = 0, i, j; |
| 9055 | struct nlattr *rule; |
| 9056 | struct cfg80211_coalesce_rules *tmp_rule; |
| 9057 | |
| 9058 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 9059 | return -EOPNOTSUPP; |
| 9060 | |
| 9061 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 9062 | cfg80211_rdev_free_coalesce(rdev); |
| 9063 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); |
| 9064 | return 0; |
| 9065 | } |
| 9066 | |
| 9067 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 9068 | rem_rule) |
| 9069 | n_rules++; |
| 9070 | if (n_rules > coalesce->n_rules) |
| 9071 | return -EINVAL; |
| 9072 | |
| 9073 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 9074 | GFP_KERNEL); |
| 9075 | if (!new_coalesce.rules) |
| 9076 | return -ENOMEM; |
| 9077 | |
| 9078 | new_coalesce.n_rules = n_rules; |
| 9079 | i = 0; |
| 9080 | |
| 9081 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 9082 | rem_rule) { |
| 9083 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 9084 | &new_coalesce.rules[i]); |
| 9085 | if (err) |
| 9086 | goto error; |
| 9087 | |
| 9088 | i++; |
| 9089 | } |
| 9090 | |
| 9091 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); |
| 9092 | if (err) |
| 9093 | goto error; |
| 9094 | |
| 9095 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 9096 | if (!n_coalesce) { |
| 9097 | err = -ENOMEM; |
| 9098 | goto error; |
| 9099 | } |
| 9100 | cfg80211_rdev_free_coalesce(rdev); |
| 9101 | rdev->coalesce = n_coalesce; |
| 9102 | |
| 9103 | return 0; |
| 9104 | error: |
| 9105 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 9106 | tmp_rule = &new_coalesce.rules[i]; |
| 9107 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 9108 | kfree(tmp_rule->patterns[j].mask); |
| 9109 | kfree(tmp_rule->patterns); |
| 9110 | } |
| 9111 | kfree(new_coalesce.rules); |
| 9112 | |
| 9113 | return err; |
| 9114 | } |
| 9115 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9116 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 9117 | { |
| 9118 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9119 | struct net_device *dev = info->user_ptr[1]; |
| 9120 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9121 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 9122 | struct cfg80211_gtk_rekey_data rekey_data; |
| 9123 | int err; |
| 9124 | |
| 9125 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 9126 | return -EINVAL; |
| 9127 | |
| 9128 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 9129 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 9130 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 9131 | nl80211_rekey_policy); |
| 9132 | if (err) |
| 9133 | return err; |
| 9134 | |
| 9135 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 9136 | return -ERANGE; |
| 9137 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 9138 | return -ERANGE; |
| 9139 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 9140 | return -ERANGE; |
| 9141 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 9142 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 9143 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 9144 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9145 | |
| 9146 | wdev_lock(wdev); |
| 9147 | if (!wdev->current_bss) { |
| 9148 | err = -ENOTCONN; |
| 9149 | goto out; |
| 9150 | } |
| 9151 | |
| 9152 | if (!rdev->ops->set_rekey_data) { |
| 9153 | err = -EOPNOTSUPP; |
| 9154 | goto out; |
| 9155 | } |
| 9156 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9157 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 9158 | out: |
| 9159 | wdev_unlock(wdev); |
| 9160 | return err; |
| 9161 | } |
| 9162 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9163 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 9164 | struct genl_info *info) |
| 9165 | { |
| 9166 | struct net_device *dev = info->user_ptr[1]; |
| 9167 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9168 | |
| 9169 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 9170 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 9171 | return -EINVAL; |
| 9172 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9173 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9174 | return -EBUSY; |
| 9175 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9176 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9177 | return 0; |
| 9178 | } |
| 9179 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9180 | static int nl80211_probe_client(struct sk_buff *skb, |
| 9181 | struct genl_info *info) |
| 9182 | { |
| 9183 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9184 | struct net_device *dev = info->user_ptr[1]; |
| 9185 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9186 | struct sk_buff *msg; |
| 9187 | void *hdr; |
| 9188 | const u8 *addr; |
| 9189 | u64 cookie; |
| 9190 | int err; |
| 9191 | |
| 9192 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 9193 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 9194 | return -EOPNOTSUPP; |
| 9195 | |
| 9196 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9197 | return -EINVAL; |
| 9198 | |
| 9199 | if (!rdev->ops->probe_client) |
| 9200 | return -EOPNOTSUPP; |
| 9201 | |
| 9202 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9203 | if (!msg) |
| 9204 | return -ENOMEM; |
| 9205 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9206 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9207 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9208 | if (!hdr) { |
| 9209 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9210 | goto free_msg; |
| 9211 | } |
| 9212 | |
| 9213 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9214 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9215 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9216 | if (err) |
| 9217 | goto free_msg; |
| 9218 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9219 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9220 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9221 | |
| 9222 | genlmsg_end(msg, hdr); |
| 9223 | |
| 9224 | return genlmsg_reply(msg, info); |
| 9225 | |
| 9226 | nla_put_failure: |
| 9227 | err = -ENOBUFS; |
| 9228 | free_msg: |
| 9229 | nlmsg_free(msg); |
| 9230 | return err; |
| 9231 | } |
| 9232 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9233 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 9234 | { |
| 9235 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9236 | struct cfg80211_beacon_registration *reg, *nreg; |
| 9237 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9238 | |
| 9239 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 9240 | return -EOPNOTSUPP; |
| 9241 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9242 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 9243 | if (!nreg) |
| 9244 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9245 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9246 | /* First, check if already registered. */ |
| 9247 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9248 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 9249 | if (reg->nlportid == info->snd_portid) { |
| 9250 | rv = -EALREADY; |
| 9251 | goto out_err; |
| 9252 | } |
| 9253 | } |
| 9254 | /* Add it to the list */ |
| 9255 | nreg->nlportid = info->snd_portid; |
| 9256 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 9257 | |
| 9258 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9259 | |
| 9260 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9261 | out_err: |
| 9262 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9263 | kfree(nreg); |
| 9264 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9265 | } |
| 9266 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9267 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 9268 | { |
| 9269 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9270 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9271 | int err; |
| 9272 | |
| 9273 | if (!rdev->ops->start_p2p_device) |
| 9274 | return -EOPNOTSUPP; |
| 9275 | |
| 9276 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 9277 | return -EOPNOTSUPP; |
| 9278 | |
| 9279 | if (wdev->p2p_started) |
| 9280 | return 0; |
| 9281 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 9282 | if (rfkill_blocked(rdev->rfkill)) |
| 9283 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9284 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 9285 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9286 | if (err) |
| 9287 | return err; |
| 9288 | |
| 9289 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9290 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9291 | |
| 9292 | return 0; |
| 9293 | } |
| 9294 | |
| 9295 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 9296 | { |
| 9297 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9298 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9299 | |
| 9300 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 9301 | return -EOPNOTSUPP; |
| 9302 | |
| 9303 | if (!rdev->ops->stop_p2p_device) |
| 9304 | return -EOPNOTSUPP; |
| 9305 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 9306 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9307 | |
| 9308 | return 0; |
| 9309 | } |
| 9310 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9311 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 9312 | struct genl_info *info) |
| 9313 | { |
| 9314 | void *hdr; |
| 9315 | struct sk_buff *msg; |
| 9316 | |
| 9317 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9318 | if (!msg) |
| 9319 | return -ENOMEM; |
| 9320 | |
| 9321 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 9322 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 9323 | if (!hdr) |
| 9324 | goto nla_put_failure; |
| 9325 | |
| 9326 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 9327 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 9328 | goto nla_put_failure; |
| 9329 | |
| 9330 | genlmsg_end(msg, hdr); |
| 9331 | return genlmsg_reply(msg, info); |
| 9332 | |
| 9333 | nla_put_failure: |
| 9334 | kfree_skb(msg); |
| 9335 | return -ENOBUFS; |
| 9336 | } |
| 9337 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9338 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 9339 | { |
| 9340 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9341 | struct cfg80211_update_ft_ies_params ft_params; |
| 9342 | struct net_device *dev = info->user_ptr[1]; |
| 9343 | |
| 9344 | if (!rdev->ops->update_ft_ies) |
| 9345 | return -EOPNOTSUPP; |
| 9346 | |
| 9347 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 9348 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 9349 | return -EINVAL; |
| 9350 | |
| 9351 | memset(&ft_params, 0, sizeof(ft_params)); |
| 9352 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 9353 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9354 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9355 | |
| 9356 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 9357 | } |
| 9358 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9359 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 9360 | struct genl_info *info) |
| 9361 | { |
| 9362 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9363 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9364 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 9365 | u16 duration; |
| 9366 | int ret; |
| 9367 | |
| 9368 | if (!rdev->ops->crit_proto_start) |
| 9369 | return -EOPNOTSUPP; |
| 9370 | |
| 9371 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 9372 | return -EINVAL; |
| 9373 | |
| 9374 | if (rdev->crit_proto_nlportid) |
| 9375 | return -EBUSY; |
| 9376 | |
| 9377 | /* determine protocol if provided */ |
| 9378 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 9379 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 9380 | |
| 9381 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 9382 | return -EINVAL; |
| 9383 | |
| 9384 | /* timeout must be provided */ |
| 9385 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 9386 | return -EINVAL; |
| 9387 | |
| 9388 | duration = |
| 9389 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 9390 | |
| 9391 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 9392 | return -ERANGE; |
| 9393 | |
| 9394 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 9395 | if (!ret) |
| 9396 | rdev->crit_proto_nlportid = info->snd_portid; |
| 9397 | |
| 9398 | return ret; |
| 9399 | } |
| 9400 | |
| 9401 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 9402 | struct genl_info *info) |
| 9403 | { |
| 9404 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9405 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9406 | |
| 9407 | if (!rdev->ops->crit_proto_stop) |
| 9408 | return -EOPNOTSUPP; |
| 9409 | |
| 9410 | if (rdev->crit_proto_nlportid) { |
| 9411 | rdev->crit_proto_nlportid = 0; |
| 9412 | rdev_crit_proto_stop(rdev, wdev); |
| 9413 | } |
| 9414 | return 0; |
| 9415 | } |
| 9416 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9417 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 9418 | { |
| 9419 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9420 | struct wireless_dev *wdev = |
| 9421 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 9422 | int i, err; |
| 9423 | u32 vid, subcmd; |
| 9424 | |
| 9425 | if (!rdev->wiphy.vendor_commands) |
| 9426 | return -EOPNOTSUPP; |
| 9427 | |
| 9428 | if (IS_ERR(wdev)) { |
| 9429 | err = PTR_ERR(wdev); |
| 9430 | if (err != -EINVAL) |
| 9431 | return err; |
| 9432 | wdev = NULL; |
| 9433 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 9434 | return -EINVAL; |
| 9435 | } |
| 9436 | |
| 9437 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 9438 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 9439 | return -EINVAL; |
| 9440 | |
| 9441 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 9442 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 9443 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 9444 | const struct wiphy_vendor_command *vcmd; |
| 9445 | void *data = NULL; |
| 9446 | int len = 0; |
| 9447 | |
| 9448 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 9449 | |
| 9450 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 9451 | continue; |
| 9452 | |
| 9453 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 9454 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 9455 | if (!wdev) |
| 9456 | return -EINVAL; |
| 9457 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 9458 | !wdev->netdev) |
| 9459 | return -EINVAL; |
| 9460 | |
| 9461 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 9462 | if (wdev->netdev && |
| 9463 | !netif_running(wdev->netdev)) |
| 9464 | return -ENETDOWN; |
| 9465 | if (!wdev->netdev && !wdev->p2p_started) |
| 9466 | return -ENETDOWN; |
| 9467 | } |
| 9468 | } else { |
| 9469 | wdev = NULL; |
| 9470 | } |
| 9471 | |
| 9472 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 9473 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9474 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9475 | } |
| 9476 | |
| 9477 | rdev->cur_cmd_info = info; |
| 9478 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 9479 | data, len); |
| 9480 | rdev->cur_cmd_info = NULL; |
| 9481 | return err; |
| 9482 | } |
| 9483 | |
| 9484 | return -EOPNOTSUPP; |
| 9485 | } |
| 9486 | |
| 9487 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 9488 | enum nl80211_commands cmd, |
| 9489 | enum nl80211_attrs attr, |
| 9490 | int approxlen) |
| 9491 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 9492 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9493 | |
| 9494 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 9495 | return NULL; |
| 9496 | |
| 9497 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, |
| 9498 | rdev->cur_cmd_info->snd_portid, |
| 9499 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 9500 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9501 | } |
| 9502 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 9503 | |
| 9504 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 9505 | { |
| 9506 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 9507 | void *hdr = ((void **)skb->cb)[1]; |
| 9508 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 9509 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 9510 | /* clear CB data for netlink core to own from now on */ |
| 9511 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 9512 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9513 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 9514 | kfree_skb(skb); |
| 9515 | return -EINVAL; |
| 9516 | } |
| 9517 | |
| 9518 | nla_nest_end(skb, data); |
| 9519 | genlmsg_end(skb, hdr); |
| 9520 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 9521 | } |
| 9522 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 9523 | |
| 9524 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 9525 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 9526 | struct genl_info *info) |
| 9527 | { |
| 9528 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9529 | struct cfg80211_qos_map *qos_map = NULL; |
| 9530 | struct net_device *dev = info->user_ptr[1]; |
| 9531 | u8 *pos, len, num_des, des_len, des; |
| 9532 | int ret; |
| 9533 | |
| 9534 | if (!rdev->ops->set_qos_map) |
| 9535 | return -EOPNOTSUPP; |
| 9536 | |
| 9537 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 9538 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9539 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9540 | |
| 9541 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 9542 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 9543 | return -EINVAL; |
| 9544 | |
| 9545 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 9546 | if (!qos_map) |
| 9547 | return -ENOMEM; |
| 9548 | |
| 9549 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 9550 | if (num_des) { |
| 9551 | des_len = num_des * |
| 9552 | sizeof(struct cfg80211_dscp_exception); |
| 9553 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 9554 | qos_map->num_des = num_des; |
| 9555 | for (des = 0; des < num_des; des++) { |
| 9556 | if (qos_map->dscp_exception[des].up > 7) { |
| 9557 | kfree(qos_map); |
| 9558 | return -EINVAL; |
| 9559 | } |
| 9560 | } |
| 9561 | pos += des_len; |
| 9562 | } |
| 9563 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 9564 | } |
| 9565 | |
| 9566 | wdev_lock(dev->ieee80211_ptr); |
| 9567 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 9568 | if (!ret) |
| 9569 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 9570 | wdev_unlock(dev->ieee80211_ptr); |
| 9571 | |
| 9572 | kfree(qos_map); |
| 9573 | return ret; |
| 9574 | } |
| 9575 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 9576 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 9577 | { |
| 9578 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9579 | struct net_device *dev = info->user_ptr[1]; |
| 9580 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9581 | const u8 *peer; |
| 9582 | u8 tsid, up; |
| 9583 | u16 admitted_time = 0; |
| 9584 | int err; |
| 9585 | |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 9586 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 9587 | return -EOPNOTSUPP; |
| 9588 | |
| 9589 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 9590 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 9591 | return -EINVAL; |
| 9592 | |
| 9593 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 9594 | if (tsid >= IEEE80211_NUM_TIDS) |
| 9595 | return -EINVAL; |
| 9596 | |
| 9597 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
| 9598 | if (up >= IEEE80211_NUM_UPS) |
| 9599 | return -EINVAL; |
| 9600 | |
| 9601 | /* WMM uses TIDs 0-7 even for TSPEC */ |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 9602 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 9603 | /* TODO: handle 802.11 TSPEC/admission control |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 9604 | * need more attributes for that (e.g. BA session requirement); |
| 9605 | * change the WMM adminssion test above to allow both then |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 9606 | */ |
| 9607 | return -EINVAL; |
| 9608 | } |
| 9609 | |
| 9610 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9611 | |
| 9612 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 9613 | admitted_time = |
| 9614 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 9615 | if (!admitted_time) |
| 9616 | return -EINVAL; |
| 9617 | } |
| 9618 | |
| 9619 | wdev_lock(wdev); |
| 9620 | switch (wdev->iftype) { |
| 9621 | case NL80211_IFTYPE_STATION: |
| 9622 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9623 | if (wdev->current_bss) |
| 9624 | break; |
| 9625 | err = -ENOTCONN; |
| 9626 | goto out; |
| 9627 | default: |
| 9628 | err = -EOPNOTSUPP; |
| 9629 | goto out; |
| 9630 | } |
| 9631 | |
| 9632 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 9633 | |
| 9634 | out: |
| 9635 | wdev_unlock(wdev); |
| 9636 | return err; |
| 9637 | } |
| 9638 | |
| 9639 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 9640 | { |
| 9641 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9642 | struct net_device *dev = info->user_ptr[1]; |
| 9643 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9644 | const u8 *peer; |
| 9645 | u8 tsid; |
| 9646 | int err; |
| 9647 | |
| 9648 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 9649 | return -EINVAL; |
| 9650 | |
| 9651 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 9652 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9653 | |
| 9654 | wdev_lock(wdev); |
| 9655 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 9656 | wdev_unlock(wdev); |
| 9657 | |
| 9658 | return err; |
| 9659 | } |
| 9660 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9661 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 9662 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 9663 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9664 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 9665 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 9666 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9667 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9668 | /* 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] | 9669 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 9670 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 9671 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9672 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9673 | 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] | 9674 | struct genl_info *info) |
| 9675 | { |
| 9676 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9677 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9678 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9679 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 9680 | |
| 9681 | if (rtnl) |
| 9682 | rtnl_lock(); |
| 9683 | |
| 9684 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 9685 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9686 | if (IS_ERR(rdev)) { |
| 9687 | if (rtnl) |
| 9688 | rtnl_unlock(); |
| 9689 | return PTR_ERR(rdev); |
| 9690 | } |
| 9691 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9692 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 9693 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9694 | ASSERT_RTNL(); |
| 9695 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9696 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 9697 | info->attrs); |
| 9698 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9699 | if (rtnl) |
| 9700 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9701 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9702 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9703 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9704 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 9705 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9706 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9707 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 9708 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9709 | if (rtnl) |
| 9710 | rtnl_unlock(); |
| 9711 | return -EINVAL; |
| 9712 | } |
| 9713 | |
| 9714 | info->user_ptr[1] = dev; |
| 9715 | } else { |
| 9716 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9717 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9718 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9719 | if (dev) { |
| 9720 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 9721 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9722 | if (rtnl) |
| 9723 | rtnl_unlock(); |
| 9724 | return -ENETDOWN; |
| 9725 | } |
| 9726 | |
| 9727 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9728 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 9729 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9730 | if (rtnl) |
| 9731 | rtnl_unlock(); |
| 9732 | return -ENETDOWN; |
| 9733 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9734 | } |
| 9735 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9736 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9737 | } |
| 9738 | |
| 9739 | return 0; |
| 9740 | } |
| 9741 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9742 | 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] | 9743 | struct genl_info *info) |
| 9744 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9745 | if (info->user_ptr[1]) { |
| 9746 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 9747 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9748 | |
| 9749 | if (wdev->netdev) |
| 9750 | dev_put(wdev->netdev); |
| 9751 | } else { |
| 9752 | dev_put(info->user_ptr[1]); |
| 9753 | } |
| 9754 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 9755 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9756 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 9757 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 9758 | |
| 9759 | /* If needed, clear the netlink message payload from the SKB |
| 9760 | * as it might contain key data that shouldn't stick around on |
| 9761 | * the heap after the SKB is freed. The netlink message header |
| 9762 | * is still needed for further processing, so leave it intact. |
| 9763 | */ |
| 9764 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 9765 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 9766 | |
| 9767 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 9768 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9769 | } |
| 9770 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 9771 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9772 | { |
| 9773 | .cmd = NL80211_CMD_GET_WIPHY, |
| 9774 | .doit = nl80211_get_wiphy, |
| 9775 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9776 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9777 | .policy = nl80211_policy, |
| 9778 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9779 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9780 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9781 | }, |
| 9782 | { |
| 9783 | .cmd = NL80211_CMD_SET_WIPHY, |
| 9784 | .doit = nl80211_set_wiphy, |
| 9785 | .policy = nl80211_policy, |
| 9786 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9787 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9788 | }, |
| 9789 | { |
| 9790 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 9791 | .doit = nl80211_get_interface, |
| 9792 | .dumpit = nl80211_dump_interface, |
| 9793 | .policy = nl80211_policy, |
| 9794 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9795 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9796 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9797 | }, |
| 9798 | { |
| 9799 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 9800 | .doit = nl80211_set_interface, |
| 9801 | .policy = nl80211_policy, |
| 9802 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9803 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9804 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9805 | }, |
| 9806 | { |
| 9807 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 9808 | .doit = nl80211_new_interface, |
| 9809 | .policy = nl80211_policy, |
| 9810 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9811 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9812 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9813 | }, |
| 9814 | { |
| 9815 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 9816 | .doit = nl80211_del_interface, |
| 9817 | .policy = nl80211_policy, |
| 9818 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 9819 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9820 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9821 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9822 | { |
| 9823 | .cmd = NL80211_CMD_GET_KEY, |
| 9824 | .doit = nl80211_get_key, |
| 9825 | .policy = nl80211_policy, |
| 9826 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9827 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9828 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9829 | }, |
| 9830 | { |
| 9831 | .cmd = NL80211_CMD_SET_KEY, |
| 9832 | .doit = nl80211_set_key, |
| 9833 | .policy = nl80211_policy, |
| 9834 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9835 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 9836 | NL80211_FLAG_NEED_RTNL | |
| 9837 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9838 | }, |
| 9839 | { |
| 9840 | .cmd = NL80211_CMD_NEW_KEY, |
| 9841 | .doit = nl80211_new_key, |
| 9842 | .policy = nl80211_policy, |
| 9843 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9844 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 9845 | NL80211_FLAG_NEED_RTNL | |
| 9846 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9847 | }, |
| 9848 | { |
| 9849 | .cmd = NL80211_CMD_DEL_KEY, |
| 9850 | .doit = nl80211_del_key, |
| 9851 | .policy = nl80211_policy, |
| 9852 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9853 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9854 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9855 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9856 | { |
| 9857 | .cmd = NL80211_CMD_SET_BEACON, |
| 9858 | .policy = nl80211_policy, |
| 9859 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9860 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9861 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9862 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9863 | }, |
| 9864 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9865 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9866 | .policy = nl80211_policy, |
| 9867 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9868 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9869 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9870 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9871 | }, |
| 9872 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9873 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9874 | .policy = nl80211_policy, |
| 9875 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9876 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9877 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9878 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9879 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9880 | { |
| 9881 | .cmd = NL80211_CMD_GET_STATION, |
| 9882 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9883 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9884 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9885 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9886 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9887 | }, |
| 9888 | { |
| 9889 | .cmd = NL80211_CMD_SET_STATION, |
| 9890 | .doit = nl80211_set_station, |
| 9891 | .policy = nl80211_policy, |
| 9892 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9893 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9894 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9895 | }, |
| 9896 | { |
| 9897 | .cmd = NL80211_CMD_NEW_STATION, |
| 9898 | .doit = nl80211_new_station, |
| 9899 | .policy = nl80211_policy, |
| 9900 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9901 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9902 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9903 | }, |
| 9904 | { |
| 9905 | .cmd = NL80211_CMD_DEL_STATION, |
| 9906 | .doit = nl80211_del_station, |
| 9907 | .policy = nl80211_policy, |
| 9908 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9909 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9910 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9911 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9912 | { |
| 9913 | .cmd = NL80211_CMD_GET_MPATH, |
| 9914 | .doit = nl80211_get_mpath, |
| 9915 | .dumpit = nl80211_dump_mpath, |
| 9916 | .policy = nl80211_policy, |
| 9917 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9918 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9919 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9920 | }, |
| 9921 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 9922 | .cmd = NL80211_CMD_GET_MPP, |
| 9923 | .doit = nl80211_get_mpp, |
| 9924 | .dumpit = nl80211_dump_mpp, |
| 9925 | .policy = nl80211_policy, |
| 9926 | .flags = GENL_ADMIN_PERM, |
| 9927 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9928 | NL80211_FLAG_NEED_RTNL, |
| 9929 | }, |
| 9930 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9931 | .cmd = NL80211_CMD_SET_MPATH, |
| 9932 | .doit = nl80211_set_mpath, |
| 9933 | .policy = nl80211_policy, |
| 9934 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9935 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9936 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9937 | }, |
| 9938 | { |
| 9939 | .cmd = NL80211_CMD_NEW_MPATH, |
| 9940 | .doit = nl80211_new_mpath, |
| 9941 | .policy = nl80211_policy, |
| 9942 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9943 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9944 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9945 | }, |
| 9946 | { |
| 9947 | .cmd = NL80211_CMD_DEL_MPATH, |
| 9948 | .doit = nl80211_del_mpath, |
| 9949 | .policy = nl80211_policy, |
| 9950 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9951 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9952 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9953 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9954 | { |
| 9955 | .cmd = NL80211_CMD_SET_BSS, |
| 9956 | .doit = nl80211_set_bss, |
| 9957 | .policy = nl80211_policy, |
| 9958 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9959 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9960 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9961 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9962 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9963 | .cmd = NL80211_CMD_GET_REG, |
| 9964 | .doit = nl80211_get_reg, |
| 9965 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9966 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9967 | /* can be retrieved by unprivileged users */ |
| 9968 | }, |
| 9969 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9970 | .cmd = NL80211_CMD_SET_REG, |
| 9971 | .doit = nl80211_set_reg, |
| 9972 | .policy = nl80211_policy, |
| 9973 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9974 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9975 | }, |
| 9976 | { |
| 9977 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 9978 | .doit = nl80211_req_set_reg, |
| 9979 | .policy = nl80211_policy, |
| 9980 | .flags = GENL_ADMIN_PERM, |
| 9981 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9982 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9983 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 9984 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9985 | .policy = nl80211_policy, |
| 9986 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9987 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9988 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9989 | }, |
| 9990 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9991 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 9992 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9993 | .policy = nl80211_policy, |
| 9994 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9995 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9996 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9997 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 9998 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9999 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 10000 | .doit = nl80211_trigger_scan, |
| 10001 | .policy = nl80211_policy, |
| 10002 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10003 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10004 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10005 | }, |
| 10006 | { |
| 10007 | .cmd = NL80211_CMD_GET_SCAN, |
| 10008 | .policy = nl80211_policy, |
| 10009 | .dumpit = nl80211_dump_scan, |
| 10010 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10011 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10012 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 10013 | .doit = nl80211_start_sched_scan, |
| 10014 | .policy = nl80211_policy, |
| 10015 | .flags = GENL_ADMIN_PERM, |
| 10016 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10017 | NL80211_FLAG_NEED_RTNL, |
| 10018 | }, |
| 10019 | { |
| 10020 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 10021 | .doit = nl80211_stop_sched_scan, |
| 10022 | .policy = nl80211_policy, |
| 10023 | .flags = GENL_ADMIN_PERM, |
| 10024 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10025 | NL80211_FLAG_NEED_RTNL, |
| 10026 | }, |
| 10027 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10028 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 10029 | .doit = nl80211_authenticate, |
| 10030 | .policy = nl80211_policy, |
| 10031 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10032 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10033 | NL80211_FLAG_NEED_RTNL | |
| 10034 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10035 | }, |
| 10036 | { |
| 10037 | .cmd = NL80211_CMD_ASSOCIATE, |
| 10038 | .doit = nl80211_associate, |
| 10039 | .policy = nl80211_policy, |
| 10040 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10041 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10042 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10043 | }, |
| 10044 | { |
| 10045 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 10046 | .doit = nl80211_deauthenticate, |
| 10047 | .policy = nl80211_policy, |
| 10048 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10049 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10050 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10051 | }, |
| 10052 | { |
| 10053 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 10054 | .doit = nl80211_disassociate, |
| 10055 | .policy = nl80211_policy, |
| 10056 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10057 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10058 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10059 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10060 | { |
| 10061 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 10062 | .doit = nl80211_join_ibss, |
| 10063 | .policy = nl80211_policy, |
| 10064 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10065 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10066 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10067 | }, |
| 10068 | { |
| 10069 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 10070 | .doit = nl80211_leave_ibss, |
| 10071 | .policy = nl80211_policy, |
| 10072 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10073 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10074 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10075 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10076 | #ifdef CONFIG_NL80211_TESTMODE |
| 10077 | { |
| 10078 | .cmd = NL80211_CMD_TESTMODE, |
| 10079 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10080 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10081 | .policy = nl80211_policy, |
| 10082 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10083 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10084 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10085 | }, |
| 10086 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10087 | { |
| 10088 | .cmd = NL80211_CMD_CONNECT, |
| 10089 | .doit = nl80211_connect, |
| 10090 | .policy = nl80211_policy, |
| 10091 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10092 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10093 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10094 | }, |
| 10095 | { |
| 10096 | .cmd = NL80211_CMD_DISCONNECT, |
| 10097 | .doit = nl80211_disconnect, |
| 10098 | .policy = nl80211_policy, |
| 10099 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 10100 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10101 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10102 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10103 | { |
| 10104 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 10105 | .doit = nl80211_wiphy_netns, |
| 10106 | .policy = nl80211_policy, |
| 10107 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10108 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10109 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10110 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 10111 | { |
| 10112 | .cmd = NL80211_CMD_GET_SURVEY, |
| 10113 | .policy = nl80211_policy, |
| 10114 | .dumpit = nl80211_dump_survey, |
| 10115 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10116 | { |
| 10117 | .cmd = NL80211_CMD_SET_PMKSA, |
| 10118 | .doit = nl80211_setdel_pmksa, |
| 10119 | .policy = nl80211_policy, |
| 10120 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10121 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10122 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10123 | }, |
| 10124 | { |
| 10125 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 10126 | .doit = nl80211_setdel_pmksa, |
| 10127 | .policy = nl80211_policy, |
| 10128 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10129 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10130 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10131 | }, |
| 10132 | { |
| 10133 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 10134 | .doit = nl80211_flush_pmksa, |
| 10135 | .policy = nl80211_policy, |
| 10136 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10137 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10138 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10139 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10140 | { |
| 10141 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 10142 | .doit = nl80211_remain_on_channel, |
| 10143 | .policy = nl80211_policy, |
| 10144 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10145 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10146 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10147 | }, |
| 10148 | { |
| 10149 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 10150 | .doit = nl80211_cancel_remain_on_channel, |
| 10151 | .policy = nl80211_policy, |
| 10152 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10153 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10154 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10155 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10156 | { |
| 10157 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 10158 | .doit = nl80211_set_tx_bitrate_mask, |
| 10159 | .policy = nl80211_policy, |
| 10160 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10161 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10162 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10163 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10164 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10165 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 10166 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10167 | .policy = nl80211_policy, |
| 10168 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10169 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10170 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10171 | }, |
| 10172 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10173 | .cmd = NL80211_CMD_FRAME, |
| 10174 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10175 | .policy = nl80211_policy, |
| 10176 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10177 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10178 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10179 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10180 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10181 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 10182 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 10183 | .policy = nl80211_policy, |
| 10184 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10185 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10186 | NL80211_FLAG_NEED_RTNL, |
| 10187 | }, |
| 10188 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10189 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 10190 | .doit = nl80211_set_power_save, |
| 10191 | .policy = nl80211_policy, |
| 10192 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10193 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10194 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10195 | }, |
| 10196 | { |
| 10197 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 10198 | .doit = nl80211_get_power_save, |
| 10199 | .policy = nl80211_policy, |
| 10200 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10201 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10202 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10203 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10204 | { |
| 10205 | .cmd = NL80211_CMD_SET_CQM, |
| 10206 | .doit = nl80211_set_cqm, |
| 10207 | .policy = nl80211_policy, |
| 10208 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10209 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10210 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10211 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 10212 | { |
| 10213 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 10214 | .doit = nl80211_set_channel, |
| 10215 | .policy = nl80211_policy, |
| 10216 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10217 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10218 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 10219 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 10220 | { |
| 10221 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 10222 | .doit = nl80211_set_wds_peer, |
| 10223 | .policy = nl80211_policy, |
| 10224 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 10225 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10226 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 10227 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10228 | { |
| 10229 | .cmd = NL80211_CMD_JOIN_MESH, |
| 10230 | .doit = nl80211_join_mesh, |
| 10231 | .policy = nl80211_policy, |
| 10232 | .flags = GENL_ADMIN_PERM, |
| 10233 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10234 | NL80211_FLAG_NEED_RTNL, |
| 10235 | }, |
| 10236 | { |
| 10237 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 10238 | .doit = nl80211_leave_mesh, |
| 10239 | .policy = nl80211_policy, |
| 10240 | .flags = GENL_ADMIN_PERM, |
| 10241 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10242 | NL80211_FLAG_NEED_RTNL, |
| 10243 | }, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame^] | 10244 | { |
| 10245 | .cmd = NL80211_CMD_JOIN_OCB, |
| 10246 | .doit = nl80211_join_ocb, |
| 10247 | .policy = nl80211_policy, |
| 10248 | .flags = GENL_ADMIN_PERM, |
| 10249 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10250 | NL80211_FLAG_NEED_RTNL, |
| 10251 | }, |
| 10252 | { |
| 10253 | .cmd = NL80211_CMD_LEAVE_OCB, |
| 10254 | .doit = nl80211_leave_ocb, |
| 10255 | .policy = nl80211_policy, |
| 10256 | .flags = GENL_ADMIN_PERM, |
| 10257 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10258 | NL80211_FLAG_NEED_RTNL, |
| 10259 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10260 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10261 | { |
| 10262 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 10263 | .doit = nl80211_get_wowlan, |
| 10264 | .policy = nl80211_policy, |
| 10265 | /* can be retrieved by unprivileged users */ |
| 10266 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10267 | NL80211_FLAG_NEED_RTNL, |
| 10268 | }, |
| 10269 | { |
| 10270 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 10271 | .doit = nl80211_set_wowlan, |
| 10272 | .policy = nl80211_policy, |
| 10273 | .flags = GENL_ADMIN_PERM, |
| 10274 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10275 | NL80211_FLAG_NEED_RTNL, |
| 10276 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10277 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10278 | { |
| 10279 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 10280 | .doit = nl80211_set_rekey_data, |
| 10281 | .policy = nl80211_policy, |
| 10282 | .flags = GENL_ADMIN_PERM, |
| 10283 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10284 | NL80211_FLAG_NEED_RTNL | |
| 10285 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10286 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10287 | { |
| 10288 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 10289 | .doit = nl80211_tdls_mgmt, |
| 10290 | .policy = nl80211_policy, |
| 10291 | .flags = GENL_ADMIN_PERM, |
| 10292 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10293 | NL80211_FLAG_NEED_RTNL, |
| 10294 | }, |
| 10295 | { |
| 10296 | .cmd = NL80211_CMD_TDLS_OPER, |
| 10297 | .doit = nl80211_tdls_oper, |
| 10298 | .policy = nl80211_policy, |
| 10299 | .flags = GENL_ADMIN_PERM, |
| 10300 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10301 | NL80211_FLAG_NEED_RTNL, |
| 10302 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10303 | { |
| 10304 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 10305 | .doit = nl80211_register_unexpected_frame, |
| 10306 | .policy = nl80211_policy, |
| 10307 | .flags = GENL_ADMIN_PERM, |
| 10308 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10309 | NL80211_FLAG_NEED_RTNL, |
| 10310 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10311 | { |
| 10312 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 10313 | .doit = nl80211_probe_client, |
| 10314 | .policy = nl80211_policy, |
| 10315 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10316 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10317 | NL80211_FLAG_NEED_RTNL, |
| 10318 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10319 | { |
| 10320 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 10321 | .doit = nl80211_register_beacons, |
| 10322 | .policy = nl80211_policy, |
| 10323 | .flags = GENL_ADMIN_PERM, |
| 10324 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10325 | NL80211_FLAG_NEED_RTNL, |
| 10326 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 10327 | { |
| 10328 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 10329 | .doit = nl80211_set_noack_map, |
| 10330 | .policy = nl80211_policy, |
| 10331 | .flags = GENL_ADMIN_PERM, |
| 10332 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10333 | NL80211_FLAG_NEED_RTNL, |
| 10334 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10335 | { |
| 10336 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 10337 | .doit = nl80211_start_p2p_device, |
| 10338 | .policy = nl80211_policy, |
| 10339 | .flags = GENL_ADMIN_PERM, |
| 10340 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 10341 | NL80211_FLAG_NEED_RTNL, |
| 10342 | }, |
| 10343 | { |
| 10344 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 10345 | .doit = nl80211_stop_p2p_device, |
| 10346 | .policy = nl80211_policy, |
| 10347 | .flags = GENL_ADMIN_PERM, |
| 10348 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10349 | NL80211_FLAG_NEED_RTNL, |
| 10350 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10351 | { |
| 10352 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 10353 | .doit = nl80211_set_mcast_rate, |
| 10354 | .policy = nl80211_policy, |
| 10355 | .flags = GENL_ADMIN_PERM, |
| 10356 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10357 | NL80211_FLAG_NEED_RTNL, |
| 10358 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 10359 | { |
| 10360 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 10361 | .doit = nl80211_set_mac_acl, |
| 10362 | .policy = nl80211_policy, |
| 10363 | .flags = GENL_ADMIN_PERM, |
| 10364 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10365 | NL80211_FLAG_NEED_RTNL, |
| 10366 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10367 | { |
| 10368 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 10369 | .doit = nl80211_start_radar_detection, |
| 10370 | .policy = nl80211_policy, |
| 10371 | .flags = GENL_ADMIN_PERM, |
| 10372 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10373 | NL80211_FLAG_NEED_RTNL, |
| 10374 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 10375 | { |
| 10376 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 10377 | .doit = nl80211_get_protocol_features, |
| 10378 | .policy = nl80211_policy, |
| 10379 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10380 | { |
| 10381 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 10382 | .doit = nl80211_update_ft_ies, |
| 10383 | .policy = nl80211_policy, |
| 10384 | .flags = GENL_ADMIN_PERM, |
| 10385 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10386 | NL80211_FLAG_NEED_RTNL, |
| 10387 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 10388 | { |
| 10389 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 10390 | .doit = nl80211_crit_protocol_start, |
| 10391 | .policy = nl80211_policy, |
| 10392 | .flags = GENL_ADMIN_PERM, |
| 10393 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10394 | NL80211_FLAG_NEED_RTNL, |
| 10395 | }, |
| 10396 | { |
| 10397 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 10398 | .doit = nl80211_crit_protocol_stop, |
| 10399 | .policy = nl80211_policy, |
| 10400 | .flags = GENL_ADMIN_PERM, |
| 10401 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10402 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10403 | }, |
| 10404 | { |
| 10405 | .cmd = NL80211_CMD_GET_COALESCE, |
| 10406 | .doit = nl80211_get_coalesce, |
| 10407 | .policy = nl80211_policy, |
| 10408 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10409 | NL80211_FLAG_NEED_RTNL, |
| 10410 | }, |
| 10411 | { |
| 10412 | .cmd = NL80211_CMD_SET_COALESCE, |
| 10413 | .doit = nl80211_set_coalesce, |
| 10414 | .policy = nl80211_policy, |
| 10415 | .flags = GENL_ADMIN_PERM, |
| 10416 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10417 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 10418 | }, |
| 10419 | { |
| 10420 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 10421 | .doit = nl80211_channel_switch, |
| 10422 | .policy = nl80211_policy, |
| 10423 | .flags = GENL_ADMIN_PERM, |
| 10424 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10425 | NL80211_FLAG_NEED_RTNL, |
| 10426 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10427 | { |
| 10428 | .cmd = NL80211_CMD_VENDOR, |
| 10429 | .doit = nl80211_vendor_cmd, |
| 10430 | .policy = nl80211_policy, |
| 10431 | .flags = GENL_ADMIN_PERM, |
| 10432 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10433 | NL80211_FLAG_NEED_RTNL, |
| 10434 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 10435 | { |
| 10436 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 10437 | .doit = nl80211_set_qos_map, |
| 10438 | .policy = nl80211_policy, |
| 10439 | .flags = GENL_ADMIN_PERM, |
| 10440 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10441 | NL80211_FLAG_NEED_RTNL, |
| 10442 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10443 | { |
| 10444 | .cmd = NL80211_CMD_ADD_TX_TS, |
| 10445 | .doit = nl80211_add_tx_ts, |
| 10446 | .policy = nl80211_policy, |
| 10447 | .flags = GENL_ADMIN_PERM, |
| 10448 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10449 | NL80211_FLAG_NEED_RTNL, |
| 10450 | }, |
| 10451 | { |
| 10452 | .cmd = NL80211_CMD_DEL_TX_TS, |
| 10453 | .doit = nl80211_del_tx_ts, |
| 10454 | .policy = nl80211_policy, |
| 10455 | .flags = GENL_ADMIN_PERM, |
| 10456 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10457 | NL80211_FLAG_NEED_RTNL, |
| 10458 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10459 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10460 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10461 | /* notification functions */ |
| 10462 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10463 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 10464 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10465 | { |
| 10466 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 10467 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10468 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10469 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 10470 | cmd != NL80211_CMD_DEL_WIPHY); |
| 10471 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10472 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10473 | if (!msg) |
| 10474 | return; |
| 10475 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10476 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10477 | nlmsg_free(msg); |
| 10478 | return; |
| 10479 | } |
| 10480 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10481 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10482 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10483 | } |
| 10484 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10485 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 10486 | struct cfg80211_registered_device *rdev) |
| 10487 | { |
| 10488 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 10489 | struct nlattr *nest; |
| 10490 | int i; |
| 10491 | |
| 10492 | if (WARN_ON(!req)) |
| 10493 | return 0; |
| 10494 | |
| 10495 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 10496 | if (!nest) |
| 10497 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10498 | for (i = 0; i < req->n_ssids; i++) { |
| 10499 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 10500 | goto nla_put_failure; |
| 10501 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10502 | nla_nest_end(msg, nest); |
| 10503 | |
| 10504 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 10505 | if (!nest) |
| 10506 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10507 | for (i = 0; i < req->n_channels; i++) { |
| 10508 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 10509 | goto nla_put_failure; |
| 10510 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10511 | nla_nest_end(msg, nest); |
| 10512 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10513 | if (req->ie && |
| 10514 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 10515 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10516 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 10517 | if (req->flags && |
| 10518 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 10519 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 10520 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10521 | return 0; |
| 10522 | nla_put_failure: |
| 10523 | return -ENOBUFS; |
| 10524 | } |
| 10525 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10526 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 10527 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10528 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10529 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10530 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10531 | { |
| 10532 | void *hdr; |
| 10533 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10534 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10535 | if (!hdr) |
| 10536 | return -1; |
| 10537 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10538 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10539 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10540 | wdev->netdev->ifindex)) || |
| 10541 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10542 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10543 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10544 | /* ignore errors and send incomplete event anyway */ |
| 10545 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10546 | |
| 10547 | return genlmsg_end(msg, hdr); |
| 10548 | |
| 10549 | nla_put_failure: |
| 10550 | genlmsg_cancel(msg, hdr); |
| 10551 | return -EMSGSIZE; |
| 10552 | } |
| 10553 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10554 | static int |
| 10555 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 10556 | struct cfg80211_registered_device *rdev, |
| 10557 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10558 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10559 | { |
| 10560 | void *hdr; |
| 10561 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10562 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10563 | if (!hdr) |
| 10564 | return -1; |
| 10565 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10566 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10567 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10568 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10569 | |
| 10570 | return genlmsg_end(msg, hdr); |
| 10571 | |
| 10572 | nla_put_failure: |
| 10573 | genlmsg_cancel(msg, hdr); |
| 10574 | return -EMSGSIZE; |
| 10575 | } |
| 10576 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10577 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10578 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10579 | { |
| 10580 | struct sk_buff *msg; |
| 10581 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10582 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10583 | if (!msg) |
| 10584 | return; |
| 10585 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10586 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10587 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 10588 | nlmsg_free(msg); |
| 10589 | return; |
| 10590 | } |
| 10591 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10592 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10593 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10594 | } |
| 10595 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10596 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 10597 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10598 | { |
| 10599 | struct sk_buff *msg; |
| 10600 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10601 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10602 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10603 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10604 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10605 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10606 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 10607 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10608 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10609 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10610 | } |
| 10611 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10612 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10613 | } |
| 10614 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10615 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
| 10616 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10617 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10618 | if (!msg) |
| 10619 | return; |
| 10620 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10621 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10622 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10623 | } |
| 10624 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10625 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 10626 | struct net_device *netdev) |
| 10627 | { |
| 10628 | struct sk_buff *msg; |
| 10629 | |
| 10630 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10631 | if (!msg) |
| 10632 | return; |
| 10633 | |
| 10634 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 10635 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 10636 | nlmsg_free(msg); |
| 10637 | return; |
| 10638 | } |
| 10639 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10640 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10641 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10642 | } |
| 10643 | |
| 10644 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 10645 | struct net_device *netdev, u32 cmd) |
| 10646 | { |
| 10647 | struct sk_buff *msg; |
| 10648 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10649 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10650 | if (!msg) |
| 10651 | return; |
| 10652 | |
| 10653 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 10654 | nlmsg_free(msg); |
| 10655 | return; |
| 10656 | } |
| 10657 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10658 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10659 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10660 | } |
| 10661 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10662 | /* |
| 10663 | * This can happen on global regulatory changes or device specific settings |
| 10664 | * based on custom world regulatory domains. |
| 10665 | */ |
| 10666 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 10667 | { |
| 10668 | struct sk_buff *msg; |
| 10669 | void *hdr; |
| 10670 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10671 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10672 | if (!msg) |
| 10673 | return; |
| 10674 | |
| 10675 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 10676 | if (!hdr) { |
| 10677 | nlmsg_free(msg); |
| 10678 | return; |
| 10679 | } |
| 10680 | |
| 10681 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10682 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 10683 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10684 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10685 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 10686 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10687 | NL80211_REGDOM_TYPE_WORLD)) |
| 10688 | goto nla_put_failure; |
| 10689 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 10690 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10691 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 10692 | goto nla_put_failure; |
| 10693 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 10694 | request->intersect) { |
| 10695 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10696 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 10697 | goto nla_put_failure; |
| 10698 | } else { |
| 10699 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10700 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 10701 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 10702 | request->alpha2)) |
| 10703 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10704 | } |
| 10705 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 10706 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10707 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 10708 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10709 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10710 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10711 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10712 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10713 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10714 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10715 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10716 | |
| 10717 | return; |
| 10718 | |
| 10719 | nla_put_failure: |
| 10720 | genlmsg_cancel(msg, hdr); |
| 10721 | nlmsg_free(msg); |
| 10722 | } |
| 10723 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10724 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 10725 | struct net_device *netdev, |
| 10726 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 10727 | enum nl80211_commands cmd, gfp_t gfp, |
| 10728 | int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10729 | { |
| 10730 | struct sk_buff *msg; |
| 10731 | void *hdr; |
| 10732 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10733 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10734 | if (!msg) |
| 10735 | return; |
| 10736 | |
| 10737 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10738 | if (!hdr) { |
| 10739 | nlmsg_free(msg); |
| 10740 | return; |
| 10741 | } |
| 10742 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10743 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10744 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10745 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 10746 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10747 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 10748 | if (uapsd_queues >= 0) { |
| 10749 | struct nlattr *nla_wmm = |
| 10750 | nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 10751 | if (!nla_wmm) |
| 10752 | goto nla_put_failure; |
| 10753 | |
| 10754 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 10755 | uapsd_queues)) |
| 10756 | goto nla_put_failure; |
| 10757 | |
| 10758 | nla_nest_end(msg, nla_wmm); |
| 10759 | } |
| 10760 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10761 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10762 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10763 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10764 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10765 | return; |
| 10766 | |
| 10767 | nla_put_failure: |
| 10768 | genlmsg_cancel(msg, hdr); |
| 10769 | nlmsg_free(msg); |
| 10770 | } |
| 10771 | |
| 10772 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10773 | struct net_device *netdev, const u8 *buf, |
| 10774 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10775 | { |
| 10776 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 10777 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10778 | } |
| 10779 | |
| 10780 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 10781 | struct net_device *netdev, const u8 *buf, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 10782 | size_t len, gfp_t gfp, int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10783 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10784 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 10785 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10786 | } |
| 10787 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10788 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10789 | struct net_device *netdev, const u8 *buf, |
| 10790 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10791 | { |
| 10792 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 10793 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10794 | } |
| 10795 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10796 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 10797 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10798 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10799 | { |
| 10800 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 10801 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10802 | } |
| 10803 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10804 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 10805 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10806 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10807 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10808 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10809 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10810 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 10811 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10812 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10813 | if (WARN_ON(len < 2)) |
| 10814 | return; |
| 10815 | |
| 10816 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 10817 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 10818 | else |
| 10819 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 10820 | |
| 10821 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 10822 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10823 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10824 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10825 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 10826 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 10827 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10828 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10829 | { |
| 10830 | struct sk_buff *msg; |
| 10831 | void *hdr; |
| 10832 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10833 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10834 | if (!msg) |
| 10835 | return; |
| 10836 | |
| 10837 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10838 | if (!hdr) { |
| 10839 | nlmsg_free(msg); |
| 10840 | return; |
| 10841 | } |
| 10842 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10843 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10844 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10845 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 10846 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10847 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10848 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10849 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10850 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10851 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10852 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10853 | return; |
| 10854 | |
| 10855 | nla_put_failure: |
| 10856 | genlmsg_cancel(msg, hdr); |
| 10857 | nlmsg_free(msg); |
| 10858 | } |
| 10859 | |
| 10860 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10861 | struct net_device *netdev, const u8 *addr, |
| 10862 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10863 | { |
| 10864 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10865 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10866 | } |
| 10867 | |
| 10868 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10869 | struct net_device *netdev, const u8 *addr, |
| 10870 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10871 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10872 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 10873 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10874 | } |
| 10875 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10876 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 10877 | struct net_device *netdev, const u8 *bssid, |
| 10878 | const u8 *req_ie, size_t req_ie_len, |
| 10879 | const u8 *resp_ie, size_t resp_ie_len, |
| 10880 | u16 status, gfp_t gfp) |
| 10881 | { |
| 10882 | struct sk_buff *msg; |
| 10883 | void *hdr; |
| 10884 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10885 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10886 | if (!msg) |
| 10887 | return; |
| 10888 | |
| 10889 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 10890 | if (!hdr) { |
| 10891 | nlmsg_free(msg); |
| 10892 | return; |
| 10893 | } |
| 10894 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10895 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10896 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10897 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 10898 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 10899 | (req_ie && |
| 10900 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10901 | (resp_ie && |
| 10902 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10903 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10904 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10905 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10906 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10907 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10908 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10909 | return; |
| 10910 | |
| 10911 | nla_put_failure: |
| 10912 | genlmsg_cancel(msg, hdr); |
| 10913 | nlmsg_free(msg); |
| 10914 | |
| 10915 | } |
| 10916 | |
| 10917 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 10918 | struct net_device *netdev, const u8 *bssid, |
| 10919 | const u8 *req_ie, size_t req_ie_len, |
| 10920 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 10921 | { |
| 10922 | struct sk_buff *msg; |
| 10923 | void *hdr; |
| 10924 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10925 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10926 | if (!msg) |
| 10927 | return; |
| 10928 | |
| 10929 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 10930 | if (!hdr) { |
| 10931 | nlmsg_free(msg); |
| 10932 | return; |
| 10933 | } |
| 10934 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10935 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10936 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10937 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 10938 | (req_ie && |
| 10939 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10940 | (resp_ie && |
| 10941 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10942 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10943 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10944 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10945 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10946 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10947 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10948 | return; |
| 10949 | |
| 10950 | nla_put_failure: |
| 10951 | genlmsg_cancel(msg, hdr); |
| 10952 | nlmsg_free(msg); |
| 10953 | |
| 10954 | } |
| 10955 | |
| 10956 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 10957 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 10958 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10959 | { |
| 10960 | struct sk_buff *msg; |
| 10961 | void *hdr; |
| 10962 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10963 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10964 | if (!msg) |
| 10965 | return; |
| 10966 | |
| 10967 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 10968 | if (!hdr) { |
| 10969 | nlmsg_free(msg); |
| 10970 | return; |
| 10971 | } |
| 10972 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10973 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10974 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10975 | (from_ap && reason && |
| 10976 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 10977 | (from_ap && |
| 10978 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 10979 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 10980 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10981 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10982 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10983 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10984 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10985 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10986 | return; |
| 10987 | |
| 10988 | nla_put_failure: |
| 10989 | genlmsg_cancel(msg, hdr); |
| 10990 | nlmsg_free(msg); |
| 10991 | |
| 10992 | } |
| 10993 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10994 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 10995 | struct net_device *netdev, const u8 *bssid, |
| 10996 | gfp_t gfp) |
| 10997 | { |
| 10998 | struct sk_buff *msg; |
| 10999 | void *hdr; |
| 11000 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11001 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11002 | if (!msg) |
| 11003 | return; |
| 11004 | |
| 11005 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 11006 | if (!hdr) { |
| 11007 | nlmsg_free(msg); |
| 11008 | return; |
| 11009 | } |
| 11010 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11011 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11012 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11013 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 11014 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11015 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11016 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11017 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11018 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11019 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 11020 | return; |
| 11021 | |
| 11022 | nla_put_failure: |
| 11023 | genlmsg_cancel(msg, hdr); |
| 11024 | nlmsg_free(msg); |
| 11025 | } |
| 11026 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11027 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 11028 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11029 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11030 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11031 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11032 | struct sk_buff *msg; |
| 11033 | void *hdr; |
| 11034 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11035 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 11036 | return; |
| 11037 | |
| 11038 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 11039 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11040 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11041 | if (!msg) |
| 11042 | return; |
| 11043 | |
| 11044 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 11045 | if (!hdr) { |
| 11046 | nlmsg_free(msg); |
| 11047 | return; |
| 11048 | } |
| 11049 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11050 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11051 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11052 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11053 | (ie_len && ie && |
| 11054 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 11055 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11056 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11057 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11058 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11059 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11060 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11061 | return; |
| 11062 | |
| 11063 | nla_put_failure: |
| 11064 | genlmsg_cancel(msg, hdr); |
| 11065 | nlmsg_free(msg); |
| 11066 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11067 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 11068 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11069 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 11070 | struct net_device *netdev, const u8 *addr, |
| 11071 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11072 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11073 | { |
| 11074 | struct sk_buff *msg; |
| 11075 | void *hdr; |
| 11076 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 11077 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11078 | if (!msg) |
| 11079 | return; |
| 11080 | |
| 11081 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 11082 | if (!hdr) { |
| 11083 | nlmsg_free(msg); |
| 11084 | return; |
| 11085 | } |
| 11086 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11087 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11088 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11089 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 11090 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 11091 | (key_id != -1 && |
| 11092 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 11093 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 11094 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11095 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11096 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11097 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11098 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11099 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 11100 | return; |
| 11101 | |
| 11102 | nla_put_failure: |
| 11103 | genlmsg_cancel(msg, hdr); |
| 11104 | nlmsg_free(msg); |
| 11105 | } |
| 11106 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11107 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 11108 | struct ieee80211_channel *channel_before, |
| 11109 | struct ieee80211_channel *channel_after) |
| 11110 | { |
| 11111 | struct sk_buff *msg; |
| 11112 | void *hdr; |
| 11113 | struct nlattr *nl_freq; |
| 11114 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 11115 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11116 | if (!msg) |
| 11117 | return; |
| 11118 | |
| 11119 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 11120 | if (!hdr) { |
| 11121 | nlmsg_free(msg); |
| 11122 | return; |
| 11123 | } |
| 11124 | |
| 11125 | /* |
| 11126 | * Since we are applying the beacon hint to a wiphy we know its |
| 11127 | * wiphy_idx is valid |
| 11128 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11129 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 11130 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11131 | |
| 11132 | /* Before */ |
| 11133 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 11134 | if (!nl_freq) |
| 11135 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 11136 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11137 | goto nla_put_failure; |
| 11138 | nla_nest_end(msg, nl_freq); |
| 11139 | |
| 11140 | /* After */ |
| 11141 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 11142 | if (!nl_freq) |
| 11143 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 11144 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11145 | goto nla_put_failure; |
| 11146 | nla_nest_end(msg, nl_freq); |
| 11147 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11148 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11149 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11150 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11151 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11152 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11153 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 11154 | |
| 11155 | return; |
| 11156 | |
| 11157 | nla_put_failure: |
| 11158 | genlmsg_cancel(msg, hdr); |
| 11159 | nlmsg_free(msg); |
| 11160 | } |
| 11161 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11162 | static void nl80211_send_remain_on_chan_event( |
| 11163 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11164 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11165 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11166 | unsigned int duration, gfp_t gfp) |
| 11167 | { |
| 11168 | struct sk_buff *msg; |
| 11169 | void *hdr; |
| 11170 | |
| 11171 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11172 | if (!msg) |
| 11173 | return; |
| 11174 | |
| 11175 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 11176 | if (!hdr) { |
| 11177 | nlmsg_free(msg); |
| 11178 | return; |
| 11179 | } |
| 11180 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11181 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11182 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11183 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 11184 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11185 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11186 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 11187 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11188 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 11189 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11190 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11191 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 11192 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 11193 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11194 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11195 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11196 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11197 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11198 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11199 | return; |
| 11200 | |
| 11201 | nla_put_failure: |
| 11202 | genlmsg_cancel(msg, hdr); |
| 11203 | nlmsg_free(msg); |
| 11204 | } |
| 11205 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11206 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 11207 | struct ieee80211_channel *chan, |
| 11208 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11209 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11210 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11211 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11212 | |
| 11213 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11214 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11215 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11216 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11217 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11218 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11219 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11220 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 11221 | struct ieee80211_channel *chan, |
| 11222 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11223 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11224 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11225 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11226 | |
| 11227 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11228 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11229 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11230 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11231 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11232 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11233 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 11234 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11235 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11236 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11237 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11238 | struct sk_buff *msg; |
| 11239 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11240 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 11241 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11242 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11243 | if (!msg) |
| 11244 | return; |
| 11245 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 11246 | if (nl80211_send_station(msg, 0, 0, 0, |
| 11247 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11248 | nlmsg_free(msg); |
| 11249 | return; |
| 11250 | } |
| 11251 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11252 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11253 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11254 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11255 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11256 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11257 | 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] | 11258 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11259 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11260 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11261 | struct sk_buff *msg; |
| 11262 | void *hdr; |
| 11263 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11264 | trace_cfg80211_del_sta(dev, mac_addr); |
| 11265 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11266 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11267 | if (!msg) |
| 11268 | return; |
| 11269 | |
| 11270 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 11271 | if (!hdr) { |
| 11272 | nlmsg_free(msg); |
| 11273 | return; |
| 11274 | } |
| 11275 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11276 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11277 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 11278 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11279 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11280 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11281 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11282 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11283 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11284 | return; |
| 11285 | |
| 11286 | nla_put_failure: |
| 11287 | genlmsg_cancel(msg, hdr); |
| 11288 | nlmsg_free(msg); |
| 11289 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11290 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11291 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11292 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 11293 | enum nl80211_connect_failed_reason reason, |
| 11294 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11295 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11296 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11297 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11298 | struct sk_buff *msg; |
| 11299 | void *hdr; |
| 11300 | |
| 11301 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 11302 | if (!msg) |
| 11303 | return; |
| 11304 | |
| 11305 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 11306 | if (!hdr) { |
| 11307 | nlmsg_free(msg); |
| 11308 | return; |
| 11309 | } |
| 11310 | |
| 11311 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11312 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 11313 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 11314 | goto nla_put_failure; |
| 11315 | |
| 11316 | genlmsg_end(msg, hdr); |
| 11317 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11318 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11319 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11320 | return; |
| 11321 | |
| 11322 | nla_put_failure: |
| 11323 | genlmsg_cancel(msg, hdr); |
| 11324 | nlmsg_free(msg); |
| 11325 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11326 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11327 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11328 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 11329 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11330 | { |
| 11331 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11332 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11333 | struct sk_buff *msg; |
| 11334 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11335 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11336 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11337 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11338 | return false; |
| 11339 | |
| 11340 | msg = nlmsg_new(100, gfp); |
| 11341 | if (!msg) |
| 11342 | return true; |
| 11343 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11344 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11345 | if (!hdr) { |
| 11346 | nlmsg_free(msg); |
| 11347 | return true; |
| 11348 | } |
| 11349 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11350 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11351 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11352 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 11353 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11354 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11355 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11356 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11357 | return true; |
| 11358 | |
| 11359 | nla_put_failure: |
| 11360 | genlmsg_cancel(msg, hdr); |
| 11361 | nlmsg_free(msg); |
| 11362 | return true; |
| 11363 | } |
| 11364 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11365 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 11366 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11367 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11368 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11369 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11370 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11371 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 11372 | |
| 11373 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 11374 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 11375 | trace_cfg80211_return_bool(false); |
| 11376 | return false; |
| 11377 | } |
| 11378 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 11379 | addr, gfp); |
| 11380 | trace_cfg80211_return_bool(ret); |
| 11381 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11382 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11383 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 11384 | |
| 11385 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 11386 | const u8 *addr, gfp_t gfp) |
| 11387 | { |
| 11388 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11389 | bool ret; |
| 11390 | |
| 11391 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 11392 | |
| 11393 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 11394 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 11395 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 11396 | trace_cfg80211_return_bool(false); |
| 11397 | return false; |
| 11398 | } |
| 11399 | ret = __nl80211_unexpected_frame(dev, |
| 11400 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 11401 | addr, gfp); |
| 11402 | trace_cfg80211_return_bool(ret); |
| 11403 | return ret; |
| 11404 | } |
| 11405 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11406 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11407 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11408 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 11409 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 11410 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11411 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11412 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11413 | struct sk_buff *msg; |
| 11414 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11415 | |
| 11416 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11417 | if (!msg) |
| 11418 | return -ENOMEM; |
| 11419 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11420 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11421 | if (!hdr) { |
| 11422 | nlmsg_free(msg); |
| 11423 | return -ENOMEM; |
| 11424 | } |
| 11425 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11426 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11427 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11428 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 11429 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11430 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 11431 | (sig_dbm && |
| 11432 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 11433 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 11434 | (flags && |
| 11435 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11436 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11437 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11438 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11439 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11440 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11441 | |
| 11442 | nla_put_failure: |
| 11443 | genlmsg_cancel(msg, hdr); |
| 11444 | nlmsg_free(msg); |
| 11445 | return -ENOBUFS; |
| 11446 | } |
| 11447 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11448 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 11449 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11450 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11451 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11452 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11453 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11454 | struct sk_buff *msg; |
| 11455 | void *hdr; |
| 11456 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11457 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 11458 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11459 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11460 | if (!msg) |
| 11461 | return; |
| 11462 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11463 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11464 | if (!hdr) { |
| 11465 | nlmsg_free(msg); |
| 11466 | return; |
| 11467 | } |
| 11468 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11469 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11470 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11471 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 11472 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11473 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 11474 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11475 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11476 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11477 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11478 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11479 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11480 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11481 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11482 | return; |
| 11483 | |
| 11484 | nla_put_failure: |
| 11485 | genlmsg_cancel(msg, hdr); |
| 11486 | nlmsg_free(msg); |
| 11487 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11488 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11489 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11490 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 11491 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 11492 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11493 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11494 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11495 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11496 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11497 | struct sk_buff *msg; |
| 11498 | struct nlattr *pinfoattr; |
| 11499 | void *hdr; |
| 11500 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11501 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 11502 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11503 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11504 | if (!msg) |
| 11505 | return; |
| 11506 | |
| 11507 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11508 | if (!hdr) { |
| 11509 | nlmsg_free(msg); |
| 11510 | return; |
| 11511 | } |
| 11512 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11513 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11514 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11515 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11516 | |
| 11517 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11518 | if (!pinfoattr) |
| 11519 | goto nla_put_failure; |
| 11520 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11521 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 11522 | rssi_event)) |
| 11523 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11524 | |
| 11525 | nla_nest_end(msg, pinfoattr); |
| 11526 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11527 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11528 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11529 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11530 | NL80211_MCGRP_MLME, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11531 | return; |
| 11532 | |
| 11533 | nla_put_failure: |
| 11534 | genlmsg_cancel(msg, hdr); |
| 11535 | nlmsg_free(msg); |
| 11536 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11537 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11538 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11539 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 11540 | struct net_device *netdev, const u8 *bssid, |
| 11541 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11542 | { |
| 11543 | struct sk_buff *msg; |
| 11544 | struct nlattr *rekey_attr; |
| 11545 | void *hdr; |
| 11546 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11547 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11548 | if (!msg) |
| 11549 | return; |
| 11550 | |
| 11551 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 11552 | if (!hdr) { |
| 11553 | nlmsg_free(msg); |
| 11554 | return; |
| 11555 | } |
| 11556 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11557 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11558 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11559 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 11560 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11561 | |
| 11562 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 11563 | if (!rekey_attr) |
| 11564 | goto nla_put_failure; |
| 11565 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11566 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 11567 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 11568 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11569 | |
| 11570 | nla_nest_end(msg, rekey_attr); |
| 11571 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11572 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11573 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11574 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11575 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11576 | return; |
| 11577 | |
| 11578 | nla_put_failure: |
| 11579 | genlmsg_cancel(msg, hdr); |
| 11580 | nlmsg_free(msg); |
| 11581 | } |
| 11582 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11583 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 11584 | const u8 *replay_ctr, gfp_t gfp) |
| 11585 | { |
| 11586 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11587 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11588 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11589 | |
| 11590 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 11591 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 11592 | } |
| 11593 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 11594 | |
| 11595 | static void |
| 11596 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 11597 | struct net_device *netdev, int index, |
| 11598 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11599 | { |
| 11600 | struct sk_buff *msg; |
| 11601 | struct nlattr *attr; |
| 11602 | void *hdr; |
| 11603 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11604 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11605 | if (!msg) |
| 11606 | return; |
| 11607 | |
| 11608 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 11609 | if (!hdr) { |
| 11610 | nlmsg_free(msg); |
| 11611 | return; |
| 11612 | } |
| 11613 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11614 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11615 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11616 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11617 | |
| 11618 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 11619 | if (!attr) |
| 11620 | goto nla_put_failure; |
| 11621 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11622 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 11623 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 11624 | (preauth && |
| 11625 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 11626 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11627 | |
| 11628 | nla_nest_end(msg, attr); |
| 11629 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11630 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11631 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11632 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11633 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11634 | return; |
| 11635 | |
| 11636 | nla_put_failure: |
| 11637 | genlmsg_cancel(msg, hdr); |
| 11638 | nlmsg_free(msg); |
| 11639 | } |
| 11640 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11641 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 11642 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 11643 | { |
| 11644 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11645 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11646 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11647 | |
| 11648 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 11649 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 11650 | } |
| 11651 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 11652 | |
| 11653 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 11654 | struct net_device *netdev, |
| 11655 | struct cfg80211_chan_def *chandef, |
| 11656 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11657 | { |
| 11658 | struct sk_buff *msg; |
| 11659 | void *hdr; |
| 11660 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11661 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11662 | if (!msg) |
| 11663 | return; |
| 11664 | |
| 11665 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 11666 | if (!hdr) { |
| 11667 | nlmsg_free(msg); |
| 11668 | return; |
| 11669 | } |
| 11670 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11671 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11672 | goto nla_put_failure; |
| 11673 | |
| 11674 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 11675 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11676 | |
| 11677 | genlmsg_end(msg, hdr); |
| 11678 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11679 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11680 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11681 | return; |
| 11682 | |
| 11683 | nla_put_failure: |
| 11684 | genlmsg_cancel(msg, hdr); |
| 11685 | nlmsg_free(msg); |
| 11686 | } |
| 11687 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11688 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 11689 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11690 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11691 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11692 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11693 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11694 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11695 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11696 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11697 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11698 | |
| 11699 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 11700 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
Chun-Yeow Yeoh | b8456a1 | 2013-10-17 15:55:02 -0700 | [diff] [blame] | 11701 | wdev->iftype != NL80211_IFTYPE_ADHOC && |
| 11702 | wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11703 | return; |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11704 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 11705 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 11706 | wdev->preset_chandef = *chandef; |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11707 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11708 | } |
| 11709 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 11710 | |
| 11711 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 11712 | const u8 *peer, u32 num_packets, |
| 11713 | u32 rate, u32 intvl, gfp_t gfp) |
| 11714 | { |
| 11715 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11716 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11717 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11718 | struct sk_buff *msg; |
| 11719 | struct nlattr *pinfoattr; |
| 11720 | void *hdr; |
| 11721 | |
| 11722 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 11723 | if (!msg) |
| 11724 | return; |
| 11725 | |
| 11726 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11727 | if (!hdr) { |
| 11728 | nlmsg_free(msg); |
| 11729 | return; |
| 11730 | } |
| 11731 | |
| 11732 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11733 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11734 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11735 | goto nla_put_failure; |
| 11736 | |
| 11737 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11738 | if (!pinfoattr) |
| 11739 | goto nla_put_failure; |
| 11740 | |
| 11741 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 11742 | goto nla_put_failure; |
| 11743 | |
| 11744 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 11745 | goto nla_put_failure; |
| 11746 | |
| 11747 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 11748 | goto nla_put_failure; |
| 11749 | |
| 11750 | nla_nest_end(msg, pinfoattr); |
| 11751 | |
| 11752 | genlmsg_end(msg, hdr); |
| 11753 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11754 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11755 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11756 | return; |
| 11757 | |
| 11758 | nla_put_failure: |
| 11759 | genlmsg_cancel(msg, hdr); |
| 11760 | nlmsg_free(msg); |
| 11761 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11762 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11763 | |
| 11764 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11765 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 11766 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11767 | enum nl80211_radar_event event, |
| 11768 | struct net_device *netdev, gfp_t gfp) |
| 11769 | { |
| 11770 | struct sk_buff *msg; |
| 11771 | void *hdr; |
| 11772 | |
| 11773 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11774 | if (!msg) |
| 11775 | return; |
| 11776 | |
| 11777 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 11778 | if (!hdr) { |
| 11779 | nlmsg_free(msg); |
| 11780 | return; |
| 11781 | } |
| 11782 | |
| 11783 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 11784 | goto nla_put_failure; |
| 11785 | |
| 11786 | /* NOP and radar events don't need a netdev parameter */ |
| 11787 | if (netdev) { |
| 11788 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 11789 | |
| 11790 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11791 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11792 | goto nla_put_failure; |
| 11793 | } |
| 11794 | |
| 11795 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 11796 | goto nla_put_failure; |
| 11797 | |
| 11798 | if (nl80211_send_chandef(msg, chandef)) |
| 11799 | goto nla_put_failure; |
| 11800 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11801 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11802 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11803 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11804 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11805 | return; |
| 11806 | |
| 11807 | nla_put_failure: |
| 11808 | genlmsg_cancel(msg, hdr); |
| 11809 | nlmsg_free(msg); |
| 11810 | } |
| 11811 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11812 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 11813 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11814 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11815 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11816 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11817 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11818 | struct sk_buff *msg; |
| 11819 | struct nlattr *pinfoattr; |
| 11820 | void *hdr; |
| 11821 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11822 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 11823 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11824 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11825 | if (!msg) |
| 11826 | return; |
| 11827 | |
| 11828 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11829 | if (!hdr) { |
| 11830 | nlmsg_free(msg); |
| 11831 | return; |
| 11832 | } |
| 11833 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11834 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11835 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11836 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11837 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11838 | |
| 11839 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11840 | if (!pinfoattr) |
| 11841 | goto nla_put_failure; |
| 11842 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11843 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 11844 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11845 | |
| 11846 | nla_nest_end(msg, pinfoattr); |
| 11847 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11848 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11849 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11850 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11851 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11852 | return; |
| 11853 | |
| 11854 | nla_put_failure: |
| 11855 | genlmsg_cancel(msg, hdr); |
| 11856 | nlmsg_free(msg); |
| 11857 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11858 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11859 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11860 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 11861 | u64 cookie, bool acked, gfp_t gfp) |
| 11862 | { |
| 11863 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11864 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11865 | struct sk_buff *msg; |
| 11866 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11867 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11868 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 11869 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11870 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11871 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11872 | if (!msg) |
| 11873 | return; |
| 11874 | |
| 11875 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 11876 | if (!hdr) { |
| 11877 | nlmsg_free(msg); |
| 11878 | return; |
| 11879 | } |
| 11880 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11881 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11882 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11883 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 11884 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11885 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11886 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11887 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11888 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11889 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11890 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11891 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11892 | return; |
| 11893 | |
| 11894 | nla_put_failure: |
| 11895 | genlmsg_cancel(msg, hdr); |
| 11896 | nlmsg_free(msg); |
| 11897 | } |
| 11898 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 11899 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11900 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 11901 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11902 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11903 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11904 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11905 | struct sk_buff *msg; |
| 11906 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11907 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11908 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11909 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 11910 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11911 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11912 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 11913 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 11914 | if (!msg) { |
| 11915 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11916 | return; |
| 11917 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11918 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11919 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 11920 | if (!hdr) |
| 11921 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11922 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11923 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11924 | (freq && |
| 11925 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 11926 | (sig_dbm && |
| 11927 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 11928 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 11929 | goto nla_put_failure; |
| 11930 | |
| 11931 | genlmsg_end(msg, hdr); |
| 11932 | |
| 11933 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11934 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11935 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11936 | return; |
| 11937 | |
| 11938 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11939 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11940 | if (hdr) |
| 11941 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11942 | nlmsg_free(msg); |
| 11943 | } |
| 11944 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 11945 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11946 | #ifdef CONFIG_PM |
| 11947 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 11948 | struct cfg80211_wowlan_wakeup *wakeup, |
| 11949 | gfp_t gfp) |
| 11950 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11951 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11952 | struct sk_buff *msg; |
| 11953 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11954 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11955 | |
| 11956 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 11957 | |
| 11958 | if (wakeup) |
| 11959 | size += wakeup->packet_present_len; |
| 11960 | |
| 11961 | msg = nlmsg_new(size, gfp); |
| 11962 | if (!msg) |
| 11963 | return; |
| 11964 | |
| 11965 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 11966 | if (!hdr) |
| 11967 | goto free_msg; |
| 11968 | |
| 11969 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11970 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11971 | goto free_msg; |
| 11972 | |
| 11973 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11974 | wdev->netdev->ifindex)) |
| 11975 | goto free_msg; |
| 11976 | |
| 11977 | if (wakeup) { |
| 11978 | struct nlattr *reasons; |
| 11979 | |
| 11980 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 11981 | if (!reasons) |
| 11982 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11983 | |
| 11984 | if (wakeup->disconnect && |
| 11985 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 11986 | goto free_msg; |
| 11987 | if (wakeup->magic_pkt && |
| 11988 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 11989 | goto free_msg; |
| 11990 | if (wakeup->gtk_rekey_failure && |
| 11991 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 11992 | goto free_msg; |
| 11993 | if (wakeup->eap_identity_req && |
| 11994 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 11995 | goto free_msg; |
| 11996 | if (wakeup->four_way_handshake && |
| 11997 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 11998 | goto free_msg; |
| 11999 | if (wakeup->rfkill_release && |
| 12000 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 12001 | goto free_msg; |
| 12002 | |
| 12003 | if (wakeup->pattern_idx >= 0 && |
| 12004 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 12005 | wakeup->pattern_idx)) |
| 12006 | goto free_msg; |
| 12007 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12008 | if (wakeup->tcp_match && |
| 12009 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 12010 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12011 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12012 | if (wakeup->tcp_connlost && |
| 12013 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 12014 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12015 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12016 | if (wakeup->tcp_nomoretokens && |
| 12017 | nla_put_flag(msg, |
| 12018 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 12019 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12020 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12021 | if (wakeup->packet) { |
| 12022 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 12023 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 12024 | |
| 12025 | if (!wakeup->packet_80211) { |
| 12026 | pkt_attr = |
| 12027 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 12028 | len_attr = |
| 12029 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 12030 | } |
| 12031 | |
| 12032 | if (wakeup->packet_len && |
| 12033 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 12034 | goto free_msg; |
| 12035 | |
| 12036 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 12037 | wakeup->packet)) |
| 12038 | goto free_msg; |
| 12039 | } |
| 12040 | |
| 12041 | nla_nest_end(msg, reasons); |
| 12042 | } |
| 12043 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12044 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12045 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12046 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12047 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 12048 | return; |
| 12049 | |
| 12050 | free_msg: |
| 12051 | nlmsg_free(msg); |
| 12052 | } |
| 12053 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 12054 | #endif |
| 12055 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12056 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 12057 | enum nl80211_tdls_operation oper, |
| 12058 | u16 reason_code, gfp_t gfp) |
| 12059 | { |
| 12060 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12061 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12062 | struct sk_buff *msg; |
| 12063 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12064 | |
| 12065 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 12066 | reason_code); |
| 12067 | |
| 12068 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12069 | if (!msg) |
| 12070 | return; |
| 12071 | |
| 12072 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 12073 | if (!hdr) { |
| 12074 | nlmsg_free(msg); |
| 12075 | return; |
| 12076 | } |
| 12077 | |
| 12078 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12079 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 12080 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 12081 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 12082 | (reason_code > 0 && |
| 12083 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 12084 | goto nla_put_failure; |
| 12085 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12086 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12087 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12088 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12089 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 12090 | return; |
| 12091 | |
| 12092 | nla_put_failure: |
| 12093 | genlmsg_cancel(msg, hdr); |
| 12094 | nlmsg_free(msg); |
| 12095 | } |
| 12096 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 12097 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12098 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 12099 | unsigned long state, |
| 12100 | void *_notify) |
| 12101 | { |
| 12102 | struct netlink_notify *notify = _notify; |
| 12103 | struct cfg80211_registered_device *rdev; |
| 12104 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12105 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12106 | |
| 12107 | if (state != NETLINK_URELEASE) |
| 12108 | return NOTIFY_DONE; |
| 12109 | |
| 12110 | rcu_read_lock(); |
| 12111 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12112 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12113 | bool schedule_destroy_work = false; |
| 12114 | |
| 12115 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12116 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12117 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12118 | if (wdev->owner_nlportid == notify->portid) |
| 12119 | schedule_destroy_work = true; |
| 12120 | } |
| 12121 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12122 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 12123 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 12124 | list) { |
| 12125 | if (reg->nlportid == notify->portid) { |
| 12126 | list_del(®->list); |
| 12127 | kfree(reg); |
| 12128 | break; |
| 12129 | } |
| 12130 | } |
| 12131 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 12132 | |
| 12133 | if (schedule_destroy_work) { |
| 12134 | struct cfg80211_iface_destroy *destroy; |
| 12135 | |
| 12136 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); |
| 12137 | if (destroy) { |
| 12138 | destroy->nlportid = notify->portid; |
| 12139 | spin_lock(&rdev->destroy_list_lock); |
| 12140 | list_add(&destroy->list, &rdev->destroy_list); |
| 12141 | spin_unlock(&rdev->destroy_list_lock); |
| 12142 | schedule_work(&rdev->destroy_work); |
| 12143 | } |
| 12144 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12145 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12146 | |
| 12147 | rcu_read_unlock(); |
| 12148 | |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 12149 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12150 | } |
| 12151 | |
| 12152 | static struct notifier_block nl80211_netlink_notifier = { |
| 12153 | .notifier_call = nl80211_netlink_notify, |
| 12154 | }; |
| 12155 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12156 | void cfg80211_ft_event(struct net_device *netdev, |
| 12157 | struct cfg80211_ft_event_params *ft_event) |
| 12158 | { |
| 12159 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12160 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12161 | struct sk_buff *msg; |
| 12162 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12163 | |
| 12164 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 12165 | |
| 12166 | if (!ft_event->target_ap) |
| 12167 | return; |
| 12168 | |
| 12169 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12170 | if (!msg) |
| 12171 | return; |
| 12172 | |
| 12173 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12174 | if (!hdr) |
| 12175 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12176 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12177 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12178 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 12179 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 12180 | goto out; |
| 12181 | |
| 12182 | if (ft_event->ies && |
| 12183 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 12184 | goto out; |
| 12185 | if (ft_event->ric_ies && |
| 12186 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 12187 | ft_event->ric_ies)) |
| 12188 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12189 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 12190 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12191 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 12192 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12193 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 12194 | return; |
| 12195 | out: |
| 12196 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 12197 | } |
| 12198 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 12199 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12200 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 12201 | { |
| 12202 | struct cfg80211_registered_device *rdev; |
| 12203 | struct sk_buff *msg; |
| 12204 | void *hdr; |
| 12205 | u32 nlportid; |
| 12206 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12207 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12208 | if (!rdev->crit_proto_nlportid) |
| 12209 | return; |
| 12210 | |
| 12211 | nlportid = rdev->crit_proto_nlportid; |
| 12212 | rdev->crit_proto_nlportid = 0; |
| 12213 | |
| 12214 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12215 | if (!msg) |
| 12216 | return; |
| 12217 | |
| 12218 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 12219 | if (!hdr) |
| 12220 | goto nla_put_failure; |
| 12221 | |
| 12222 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12223 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12224 | goto nla_put_failure; |
| 12225 | |
| 12226 | genlmsg_end(msg, hdr); |
| 12227 | |
| 12228 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 12229 | return; |
| 12230 | |
| 12231 | nla_put_failure: |
| 12232 | if (hdr) |
| 12233 | genlmsg_cancel(msg, hdr); |
| 12234 | nlmsg_free(msg); |
| 12235 | |
| 12236 | } |
| 12237 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 12238 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 12239 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 12240 | { |
| 12241 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12242 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 12243 | struct sk_buff *msg; |
| 12244 | void *hdr; |
| 12245 | |
| 12246 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12247 | if (!msg) |
| 12248 | return; |
| 12249 | |
| 12250 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 12251 | if (!hdr) |
| 12252 | goto out; |
| 12253 | |
| 12254 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12255 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
| 12256 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12257 | goto out; |
| 12258 | |
| 12259 | genlmsg_end(msg, hdr); |
| 12260 | |
| 12261 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 12262 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 12263 | return; |
| 12264 | out: |
| 12265 | nlmsg_free(msg); |
| 12266 | } |
| 12267 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12268 | /* initialisation/exit functions */ |
| 12269 | |
| 12270 | int nl80211_init(void) |
| 12271 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 12272 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12273 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12274 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
| 12275 | nl80211_mcgrps); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12276 | if (err) |
| 12277 | return err; |
| 12278 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12279 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 12280 | if (err) |
| 12281 | goto err_out; |
| 12282 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12283 | return 0; |
| 12284 | err_out: |
| 12285 | genl_unregister_family(&nl80211_fam); |
| 12286 | return err; |
| 12287 | } |
| 12288 | |
| 12289 | void nl80211_exit(void) |
| 12290 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12291 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12292 | genl_unregister_family(&nl80211_fam); |
| 12293 | } |