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 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 397 | }; |
| 398 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 399 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 400 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 401 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 402 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 403 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 404 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 405 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 406 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 407 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 408 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
| 409 | }; |
| 410 | |
| 411 | /* policy for the key default flags */ |
| 412 | static const struct nla_policy |
| 413 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 414 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 415 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 416 | }; |
| 417 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 418 | /* policy for WoWLAN attributes */ |
| 419 | static const struct nla_policy |
| 420 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 421 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 422 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 423 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 424 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 425 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 426 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 427 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 428 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 429 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
| 430 | }; |
| 431 | |
| 432 | static const struct nla_policy |
| 433 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 434 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 435 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
| 436 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, |
| 437 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 438 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
| 439 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, |
| 440 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 441 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 442 | }, |
| 443 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 444 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 445 | }, |
| 446 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
| 447 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, |
| 448 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 449 | }; |
| 450 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 451 | /* policy for coalesce rule attributes */ |
| 452 | static const struct nla_policy |
| 453 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 454 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
| 455 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, |
| 456 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 457 | }; |
| 458 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 459 | /* policy for GTK rekey offload attributes */ |
| 460 | static const struct nla_policy |
| 461 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
| 462 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, |
| 463 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, |
| 464 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, |
| 465 | }; |
| 466 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 467 | static const struct nla_policy |
| 468 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 469 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 470 | .len = IEEE80211_MAX_SSID_LEN }, |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 471 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 472 | }; |
| 473 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 474 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
| 475 | struct netlink_callback *cb, |
| 476 | struct cfg80211_registered_device **rdev, |
| 477 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 478 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 479 | int err; |
| 480 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 481 | rtnl_lock(); |
| 482 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 483 | if (!cb->args[0]) { |
| 484 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 485 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 486 | nl80211_policy); |
| 487 | if (err) |
| 488 | goto out_unlock; |
| 489 | |
| 490 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
| 491 | nl80211_fam.attrbuf); |
| 492 | if (IS_ERR(*wdev)) { |
| 493 | err = PTR_ERR(*wdev); |
| 494 | goto out_unlock; |
| 495 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 496 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 497 | /* 0 is the first index - add 1 to parse only once */ |
| 498 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 499 | cb->args[1] = (*wdev)->identifier; |
| 500 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 501 | /* subtract the 1 again here */ |
| 502 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 503 | struct wireless_dev *tmp; |
| 504 | |
| 505 | if (!wiphy) { |
| 506 | err = -ENODEV; |
| 507 | goto out_unlock; |
| 508 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 509 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 510 | *wdev = NULL; |
| 511 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 512 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
| 513 | if (tmp->identifier == cb->args[1]) { |
| 514 | *wdev = tmp; |
| 515 | break; |
| 516 | } |
| 517 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 518 | |
| 519 | if (!*wdev) { |
| 520 | err = -ENODEV; |
| 521 | goto out_unlock; |
| 522 | } |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 523 | } |
| 524 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 525 | return 0; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 526 | out_unlock: |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 527 | rtnl_unlock(); |
| 528 | return err; |
| 529 | } |
| 530 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 531 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 532 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 533 | rtnl_unlock(); |
| 534 | } |
| 535 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 536 | /* IE validation */ |
| 537 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 538 | { |
| 539 | const u8 *pos; |
| 540 | int len; |
| 541 | |
| 542 | if (!attr) |
| 543 | return true; |
| 544 | |
| 545 | pos = nla_data(attr); |
| 546 | len = nla_len(attr); |
| 547 | |
| 548 | while (len) { |
| 549 | u8 elemlen; |
| 550 | |
| 551 | if (len < 2) |
| 552 | return false; |
| 553 | len -= 2; |
| 554 | |
| 555 | elemlen = pos[1]; |
| 556 | if (elemlen > len) |
| 557 | return false; |
| 558 | |
| 559 | len -= elemlen; |
| 560 | pos += 2 + elemlen; |
| 561 | } |
| 562 | |
| 563 | return true; |
| 564 | } |
| 565 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 566 | /* message building helper */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 567 | 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] | 568 | int flags, u8 cmd) |
| 569 | { |
| 570 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 571 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 572 | } |
| 573 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 574 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 575 | struct ieee80211_channel *chan, |
| 576 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 577 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 578 | /* Some channels must be completely excluded from the |
| 579 | * list to protect old user-space tools from breaking |
| 580 | */ |
| 581 | if (!large && chan->flags & |
| 582 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 583 | return 0; |
| 584 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 585 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 586 | chan->center_freq)) |
| 587 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 588 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 589 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 590 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 591 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 592 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 593 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 594 | goto nla_put_failure; |
| 595 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 596 | goto nla_put_failure; |
| 597 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 598 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 599 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 600 | goto nla_put_failure; |
| 601 | if (large) { |
| 602 | u32 time; |
| 603 | |
| 604 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 605 | |
| 606 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 607 | chan->dfs_state)) |
| 608 | goto nla_put_failure; |
| 609 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 610 | time)) |
| 611 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 612 | if (nla_put_u32(msg, |
| 613 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 614 | chan->dfs_cac_ms)) |
| 615 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 616 | } |
| 617 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 618 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 619 | if (large) { |
| 620 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 621 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 622 | goto nla_put_failure; |
| 623 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 624 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 625 | goto nla_put_failure; |
| 626 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 627 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 628 | goto nla_put_failure; |
| 629 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 630 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 631 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 632 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 633 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 634 | goto nla_put_failure; |
| 635 | if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) && |
| 636 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT)) |
| 637 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 638 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 639 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 640 | goto nla_put_failure; |
| 641 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 642 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 643 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 644 | } |
| 645 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 646 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 647 | DBM_TO_MBM(chan->max_power))) |
| 648 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 649 | |
| 650 | return 0; |
| 651 | |
| 652 | nla_put_failure: |
| 653 | return -ENOBUFS; |
| 654 | } |
| 655 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 656 | /* netlink command implementations */ |
| 657 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 658 | struct key_parse { |
| 659 | struct key_params p; |
| 660 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 661 | int type; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 662 | bool def, defmgmt; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 663 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 664 | }; |
| 665 | |
| 666 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 667 | { |
| 668 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 669 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 670 | nl80211_key_policy); |
| 671 | if (err) |
| 672 | return err; |
| 673 | |
| 674 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 675 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 676 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 677 | if (k->def) { |
| 678 | k->def_uni = true; |
| 679 | k->def_multi = true; |
| 680 | } |
| 681 | if (k->defmgmt) |
| 682 | k->def_multi = true; |
| 683 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 684 | if (tb[NL80211_KEY_IDX]) |
| 685 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 686 | |
| 687 | if (tb[NL80211_KEY_DATA]) { |
| 688 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 689 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 690 | } |
| 691 | |
| 692 | if (tb[NL80211_KEY_SEQ]) { |
| 693 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 694 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 695 | } |
| 696 | |
| 697 | if (tb[NL80211_KEY_CIPHER]) |
| 698 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 699 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 700 | if (tb[NL80211_KEY_TYPE]) { |
| 701 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
| 702 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 703 | return -EINVAL; |
| 704 | } |
| 705 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 706 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 707 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 2da8f41 | 2012-01-20 13:52:37 +0100 | [diff] [blame] | 708 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 709 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 710 | nl80211_key_default_policy); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 711 | if (err) |
| 712 | return err; |
| 713 | |
| 714 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 715 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 716 | } |
| 717 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 718 | return 0; |
| 719 | } |
| 720 | |
| 721 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 722 | { |
| 723 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 724 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 725 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 726 | } |
| 727 | |
| 728 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 729 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 730 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 731 | } |
| 732 | |
| 733 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 734 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 735 | |
| 736 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 737 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 738 | |
| 739 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 740 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 741 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 742 | if (k->def) { |
| 743 | k->def_uni = true; |
| 744 | k->def_multi = true; |
| 745 | } |
| 746 | if (k->defmgmt) |
| 747 | k->def_multi = true; |
| 748 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 749 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 750 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 751 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) |
| 752 | return -EINVAL; |
| 753 | } |
| 754 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 755 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 756 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
| 757 | int err = nla_parse_nested( |
| 758 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 759 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 760 | nl80211_key_default_policy); |
| 761 | if (err) |
| 762 | return err; |
| 763 | |
| 764 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 765 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 766 | } |
| 767 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 768 | return 0; |
| 769 | } |
| 770 | |
| 771 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 772 | { |
| 773 | int err; |
| 774 | |
| 775 | memset(k, 0, sizeof(*k)); |
| 776 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 777 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 778 | |
| 779 | if (info->attrs[NL80211_ATTR_KEY]) |
| 780 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 781 | else |
| 782 | err = nl80211_parse_key_old(info, k); |
| 783 | |
| 784 | if (err) |
| 785 | return err; |
| 786 | |
| 787 | if (k->def && k->defmgmt) |
| 788 | return -EINVAL; |
| 789 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 790 | if (k->defmgmt) { |
| 791 | if (k->def_uni || !k->def_multi) |
| 792 | return -EINVAL; |
| 793 | } |
| 794 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 795 | if (k->idx != -1) { |
| 796 | if (k->defmgmt) { |
| 797 | if (k->idx < 4 || k->idx > 5) |
| 798 | return -EINVAL; |
| 799 | } else if (k->def) { |
| 800 | if (k->idx < 0 || k->idx > 3) |
| 801 | return -EINVAL; |
| 802 | } else { |
| 803 | if (k->idx < 0 || k->idx > 5) |
| 804 | return -EINVAL; |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | return 0; |
| 809 | } |
| 810 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 811 | static struct cfg80211_cached_keys * |
| 812 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 813 | struct nlattr *keys, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 814 | { |
| 815 | struct key_parse parse; |
| 816 | struct nlattr *key; |
| 817 | struct cfg80211_cached_keys *result; |
| 818 | int rem, err, def = 0; |
| 819 | |
| 820 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 821 | if (!result) |
| 822 | return ERR_PTR(-ENOMEM); |
| 823 | |
| 824 | result->def = -1; |
| 825 | result->defmgmt = -1; |
| 826 | |
| 827 | nla_for_each_nested(key, keys, rem) { |
| 828 | memset(&parse, 0, sizeof(parse)); |
| 829 | parse.idx = -1; |
| 830 | |
| 831 | err = nl80211_parse_key_new(key, &parse); |
| 832 | if (err) |
| 833 | goto error; |
| 834 | err = -EINVAL; |
| 835 | if (!parse.p.key) |
| 836 | goto error; |
| 837 | if (parse.idx < 0 || parse.idx > 4) |
| 838 | goto error; |
| 839 | if (parse.def) { |
| 840 | if (def) |
| 841 | goto error; |
| 842 | def = 1; |
| 843 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 844 | if (!parse.def_uni || !parse.def_multi) |
| 845 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 846 | } else if (parse.defmgmt) |
| 847 | goto error; |
| 848 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 849 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 850 | if (err) |
| 851 | goto error; |
| 852 | result->params[parse.idx].cipher = parse.p.cipher; |
| 853 | result->params[parse.idx].key_len = parse.p.key_len; |
| 854 | result->params[parse.idx].key = result->data[parse.idx]; |
| 855 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 856 | |
| 857 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 858 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { |
| 859 | if (no_ht) |
| 860 | *no_ht = true; |
| 861 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | return result; |
| 865 | error: |
| 866 | kfree(result); |
| 867 | return ERR_PTR(err); |
| 868 | } |
| 869 | |
| 870 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 871 | { |
| 872 | ASSERT_WDEV_LOCK(wdev); |
| 873 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 874 | switch (wdev->iftype) { |
| 875 | case NL80211_IFTYPE_AP: |
| 876 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 877 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 878 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 879 | break; |
| 880 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 881 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 882 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 883 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 884 | return -ENOLINK; |
| 885 | break; |
| 886 | default: |
| 887 | return -EINVAL; |
| 888 | } |
| 889 | |
| 890 | return 0; |
| 891 | } |
| 892 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 893 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
| 894 | struct nlattr *tb) |
| 895 | { |
| 896 | struct ieee80211_channel *chan; |
| 897 | |
| 898 | if (tb == NULL) |
| 899 | return NULL; |
| 900 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); |
| 901 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 902 | return NULL; |
| 903 | return chan; |
| 904 | } |
| 905 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 906 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 907 | { |
| 908 | struct nlattr *nl_modes = nla_nest_start(msg, attr); |
| 909 | int i; |
| 910 | |
| 911 | if (!nl_modes) |
| 912 | goto nla_put_failure; |
| 913 | |
| 914 | i = 0; |
| 915 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 916 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 917 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 918 | ifmodes >>= 1; |
| 919 | i++; |
| 920 | } |
| 921 | |
| 922 | nla_nest_end(msg, nl_modes); |
| 923 | return 0; |
| 924 | |
| 925 | nla_put_failure: |
| 926 | return -ENOBUFS; |
| 927 | } |
| 928 | |
| 929 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 930 | struct sk_buff *msg, |
| 931 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 932 | { |
| 933 | struct nlattr *nl_combis; |
| 934 | int i, j; |
| 935 | |
| 936 | nl_combis = nla_nest_start(msg, |
| 937 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
| 938 | if (!nl_combis) |
| 939 | goto nla_put_failure; |
| 940 | |
| 941 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 942 | const struct ieee80211_iface_combination *c; |
| 943 | struct nlattr *nl_combi, *nl_limits; |
| 944 | |
| 945 | c = &wiphy->iface_combinations[i]; |
| 946 | |
| 947 | nl_combi = nla_nest_start(msg, i + 1); |
| 948 | if (!nl_combi) |
| 949 | goto nla_put_failure; |
| 950 | |
| 951 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); |
| 952 | if (!nl_limits) |
| 953 | goto nla_put_failure; |
| 954 | |
| 955 | for (j = 0; j < c->n_limits; j++) { |
| 956 | struct nlattr *nl_limit; |
| 957 | |
| 958 | nl_limit = nla_nest_start(msg, j + 1); |
| 959 | if (!nl_limit) |
| 960 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 961 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 962 | c->limits[j].max)) |
| 963 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 964 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 965 | c->limits[j].types)) |
| 966 | goto nla_put_failure; |
| 967 | nla_nest_end(msg, nl_limit); |
| 968 | } |
| 969 | |
| 970 | nla_nest_end(msg, nl_limits); |
| 971 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 972 | if (c->beacon_int_infra_match && |
| 973 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 974 | goto nla_put_failure; |
| 975 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 976 | c->num_different_channels) || |
| 977 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 978 | c->max_interfaces)) |
| 979 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 980 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 981 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 982 | c->radar_detect_widths) || |
| 983 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 984 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 985 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 986 | |
| 987 | nla_nest_end(msg, nl_combi); |
| 988 | } |
| 989 | |
| 990 | nla_nest_end(msg, nl_combis); |
| 991 | |
| 992 | return 0; |
| 993 | nla_put_failure: |
| 994 | return -ENOBUFS; |
| 995 | } |
| 996 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 997 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 998 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 999 | struct sk_buff *msg) |
| 1000 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1001 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1002 | struct nlattr *nl_tcp; |
| 1003 | |
| 1004 | if (!tcp) |
| 1005 | return 0; |
| 1006 | |
| 1007 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 1008 | if (!nl_tcp) |
| 1009 | return -ENOBUFS; |
| 1010 | |
| 1011 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1012 | tcp->data_payload_max)) |
| 1013 | return -ENOBUFS; |
| 1014 | |
| 1015 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1016 | tcp->data_payload_max)) |
| 1017 | return -ENOBUFS; |
| 1018 | |
| 1019 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1020 | return -ENOBUFS; |
| 1021 | |
| 1022 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1023 | sizeof(*tcp->tok), tcp->tok)) |
| 1024 | return -ENOBUFS; |
| 1025 | |
| 1026 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1027 | tcp->data_interval_max)) |
| 1028 | return -ENOBUFS; |
| 1029 | |
| 1030 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1031 | tcp->wake_payload_max)) |
| 1032 | return -ENOBUFS; |
| 1033 | |
| 1034 | nla_nest_end(msg, nl_tcp); |
| 1035 | return 0; |
| 1036 | } |
| 1037 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1038 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1039 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1040 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1041 | { |
| 1042 | struct nlattr *nl_wowlan; |
| 1043 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1044 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1045 | return 0; |
| 1046 | |
| 1047 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
| 1048 | if (!nl_wowlan) |
| 1049 | return -ENOBUFS; |
| 1050 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1051 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1052 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1053 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1054 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1055 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1056 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1057 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1058 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1059 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1060 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1061 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1062 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1063 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1064 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1065 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1066 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1067 | return -ENOBUFS; |
| 1068 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1069 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1070 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1071 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1072 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1073 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1074 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1075 | }; |
| 1076 | |
| 1077 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1078 | sizeof(pat), &pat)) |
| 1079 | return -ENOBUFS; |
| 1080 | } |
| 1081 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1082 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1083 | return -ENOBUFS; |
| 1084 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1085 | nla_nest_end(msg, nl_wowlan); |
| 1086 | |
| 1087 | return 0; |
| 1088 | } |
| 1089 | #endif |
| 1090 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1091 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1092 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1093 | { |
| 1094 | struct nl80211_coalesce_rule_support rule; |
| 1095 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1096 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1097 | return 0; |
| 1098 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1099 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1100 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1101 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1102 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1103 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1104 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1105 | |
| 1106 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1107 | return -ENOBUFS; |
| 1108 | |
| 1109 | return 0; |
| 1110 | } |
| 1111 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1112 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1113 | struct ieee80211_supported_band *sband) |
| 1114 | { |
| 1115 | struct nlattr *nl_rates, *nl_rate; |
| 1116 | struct ieee80211_rate *rate; |
| 1117 | int i; |
| 1118 | |
| 1119 | /* add HT info */ |
| 1120 | if (sband->ht_cap.ht_supported && |
| 1121 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1122 | sizeof(sband->ht_cap.mcs), |
| 1123 | &sband->ht_cap.mcs) || |
| 1124 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1125 | sband->ht_cap.cap) || |
| 1126 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1127 | sband->ht_cap.ampdu_factor) || |
| 1128 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1129 | sband->ht_cap.ampdu_density))) |
| 1130 | return -ENOBUFS; |
| 1131 | |
| 1132 | /* add VHT info */ |
| 1133 | if (sband->vht_cap.vht_supported && |
| 1134 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1135 | sizeof(sband->vht_cap.vht_mcs), |
| 1136 | &sband->vht_cap.vht_mcs) || |
| 1137 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1138 | sband->vht_cap.cap))) |
| 1139 | return -ENOBUFS; |
| 1140 | |
| 1141 | /* add bitrates */ |
| 1142 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 1143 | if (!nl_rates) |
| 1144 | return -ENOBUFS; |
| 1145 | |
| 1146 | for (i = 0; i < sband->n_bitrates; i++) { |
| 1147 | nl_rate = nla_nest_start(msg, i); |
| 1148 | if (!nl_rate) |
| 1149 | return -ENOBUFS; |
| 1150 | |
| 1151 | rate = &sband->bitrates[i]; |
| 1152 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1153 | rate->bitrate)) |
| 1154 | return -ENOBUFS; |
| 1155 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1156 | nla_put_flag(msg, |
| 1157 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1158 | return -ENOBUFS; |
| 1159 | |
| 1160 | nla_nest_end(msg, nl_rate); |
| 1161 | } |
| 1162 | |
| 1163 | nla_nest_end(msg, nl_rates); |
| 1164 | |
| 1165 | return 0; |
| 1166 | } |
| 1167 | |
| 1168 | static int |
| 1169 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1170 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1171 | { |
| 1172 | u16 stypes; |
| 1173 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1174 | enum nl80211_iftype ift; |
| 1175 | int i; |
| 1176 | |
| 1177 | if (!mgmt_stypes) |
| 1178 | return 0; |
| 1179 | |
| 1180 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
| 1181 | if (!nl_ifs) |
| 1182 | return -ENOBUFS; |
| 1183 | |
| 1184 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1185 | nl_ftypes = nla_nest_start(msg, ift); |
| 1186 | if (!nl_ftypes) |
| 1187 | return -ENOBUFS; |
| 1188 | i = 0; |
| 1189 | stypes = mgmt_stypes[ift].tx; |
| 1190 | while (stypes) { |
| 1191 | if ((stypes & 1) && |
| 1192 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1193 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1194 | return -ENOBUFS; |
| 1195 | stypes >>= 1; |
| 1196 | i++; |
| 1197 | } |
| 1198 | nla_nest_end(msg, nl_ftypes); |
| 1199 | } |
| 1200 | |
| 1201 | nla_nest_end(msg, nl_ifs); |
| 1202 | |
| 1203 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
| 1204 | if (!nl_ifs) |
| 1205 | return -ENOBUFS; |
| 1206 | |
| 1207 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
| 1208 | nl_ftypes = nla_nest_start(msg, ift); |
| 1209 | if (!nl_ftypes) |
| 1210 | return -ENOBUFS; |
| 1211 | i = 0; |
| 1212 | stypes = mgmt_stypes[ift].rx; |
| 1213 | while (stypes) { |
| 1214 | if ((stypes & 1) && |
| 1215 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1216 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1217 | return -ENOBUFS; |
| 1218 | stypes >>= 1; |
| 1219 | i++; |
| 1220 | } |
| 1221 | nla_nest_end(msg, nl_ftypes); |
| 1222 | } |
| 1223 | nla_nest_end(msg, nl_ifs); |
| 1224 | |
| 1225 | return 0; |
| 1226 | } |
| 1227 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1228 | struct nl80211_dump_wiphy_state { |
| 1229 | s64 filter_wiphy; |
| 1230 | long start; |
| 1231 | long split_start, band_start, chan_start; |
| 1232 | bool split; |
| 1233 | }; |
| 1234 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1235 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1236 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1237 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1238 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1239 | { |
| 1240 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1241 | struct nlattr *nl_bands, *nl_band; |
| 1242 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1243 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1244 | enum ieee80211_band band; |
| 1245 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1246 | int i; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1247 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1248 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1249 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1250 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1251 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1252 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1253 | return -ENOBUFS; |
| 1254 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1255 | if (WARN_ON(!state)) |
| 1256 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1257 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1258 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1259 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1260 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1261 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1262 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1263 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1264 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1265 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 1266 | goto finish; |
| 1267 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1268 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1269 | case 0: |
| 1270 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1271 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1272 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1273 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1274 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1275 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1276 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1277 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1278 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1279 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1280 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1281 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1282 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1283 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1284 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1285 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1286 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1287 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1288 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1289 | rdev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1290 | goto nla_put_failure; |
| 1291 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1292 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1293 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 1294 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1295 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1296 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 1297 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1298 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1299 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 1300 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1301 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1302 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 1303 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1304 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1305 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 1306 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1307 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1308 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1309 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1310 | state->split_start++; |
| 1311 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1312 | break; |
| 1313 | case 1: |
| 1314 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1315 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 1316 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 1317 | goto nla_put_failure; |
| 1318 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1319 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1320 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1321 | goto nla_put_failure; |
| 1322 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1323 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1324 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 1325 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1326 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1327 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1328 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1329 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1330 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1331 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1332 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1333 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1334 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1335 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1336 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 1337 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1338 | if ((rdev->wiphy.available_antennas_tx || |
| 1339 | rdev->wiphy.available_antennas_rx) && |
| 1340 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1341 | u32 tx_ant = 0, rx_ant = 0; |
| 1342 | int res; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1343 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1344 | if (!res) { |
| 1345 | if (nla_put_u32(msg, |
| 1346 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 1347 | tx_ant) || |
| 1348 | nla_put_u32(msg, |
| 1349 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 1350 | rx_ant)) |
| 1351 | goto nla_put_failure; |
| 1352 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1353 | } |
| 1354 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1355 | state->split_start++; |
| 1356 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1357 | break; |
| 1358 | case 2: |
| 1359 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1360 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1361 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1362 | state->split_start++; |
| 1363 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1364 | break; |
| 1365 | case 3: |
| 1366 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 1367 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1368 | goto nla_put_failure; |
| 1369 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1370 | for (band = state->band_start; |
| 1371 | band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1372 | struct ieee80211_supported_band *sband; |
| 1373 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1374 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1375 | |
| 1376 | if (!sband) |
| 1377 | continue; |
| 1378 | |
| 1379 | nl_band = nla_nest_start(msg, band); |
| 1380 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1381 | goto nla_put_failure; |
| 1382 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1383 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1384 | case 0: |
| 1385 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 1386 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1387 | state->chan_start++; |
| 1388 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1389 | break; |
| 1390 | default: |
| 1391 | /* add frequencies */ |
| 1392 | nl_freqs = nla_nest_start( |
| 1393 | msg, NL80211_BAND_ATTR_FREQS); |
| 1394 | if (!nl_freqs) |
| 1395 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1396 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1397 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1398 | i < sband->n_channels; |
| 1399 | i++) { |
| 1400 | nl_freq = nla_nest_start(msg, i); |
| 1401 | if (!nl_freq) |
| 1402 | goto nla_put_failure; |
| 1403 | |
| 1404 | chan = &sband->channels[i]; |
| 1405 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1406 | if (nl80211_msg_put_channel( |
| 1407 | msg, chan, |
| 1408 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1409 | goto nla_put_failure; |
| 1410 | |
| 1411 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1412 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1413 | break; |
| 1414 | } |
| 1415 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1416 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1417 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1418 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1419 | nla_nest_end(msg, nl_freqs); |
| 1420 | } |
| 1421 | |
| 1422 | nla_nest_end(msg, nl_band); |
| 1423 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1424 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1425 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1426 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1427 | band--; |
| 1428 | break; |
| 1429 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1430 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1431 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1432 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1433 | if (band < IEEE80211_NUM_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1434 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1435 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1436 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 1437 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1438 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1439 | if (state->band_start == 0 && state->chan_start == 0) |
| 1440 | state->split_start++; |
| 1441 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1442 | break; |
| 1443 | case 4: |
| 1444 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 1445 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1446 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1447 | |
| 1448 | i = 0; |
| 1449 | #define CMD(op, n) \ |
| 1450 | do { \ |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1451 | if (rdev->ops->op) { \ |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1452 | i++; \ |
| 1453 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1454 | goto nla_put_failure; \ |
| 1455 | } \ |
| 1456 | } while (0) |
| 1457 | |
| 1458 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1459 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1460 | CMD(add_key, NEW_KEY); |
| 1461 | CMD(start_ap, START_AP); |
| 1462 | CMD(add_station, NEW_STATION); |
| 1463 | CMD(add_mpath, NEW_MPATH); |
| 1464 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1465 | CMD(change_bss, SET_BSS); |
| 1466 | CMD(auth, AUTHENTICATE); |
| 1467 | CMD(assoc, ASSOCIATE); |
| 1468 | CMD(deauth, DEAUTHENTICATE); |
| 1469 | CMD(disassoc, DISASSOCIATE); |
| 1470 | CMD(join_ibss, JOIN_IBSS); |
| 1471 | CMD(join_mesh, JOIN_MESH); |
| 1472 | CMD(set_pmksa, SET_PMKSA); |
| 1473 | CMD(del_pmksa, DEL_PMKSA); |
| 1474 | CMD(flush_pmksa, FLUSH_PMKSA); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1475 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1476 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1477 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1478 | CMD(mgmt_tx, FRAME); |
| 1479 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1480 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1481 | i++; |
| 1482 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1483 | goto nla_put_failure; |
| 1484 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1485 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1486 | rdev->ops->join_mesh) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1487 | i++; |
| 1488 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1489 | goto nla_put_failure; |
| 1490 | } |
| 1491 | CMD(set_wds_peer, SET_WDS_PEER); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1492 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1493 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1494 | CMD(tdls_oper, TDLS_OPER); |
| 1495 | } |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1496 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1497 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1498 | CMD(probe_client, PROBE_CLIENT); |
| 1499 | CMD(set_noack_map, SET_NOACK_MAP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1500 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1501 | i++; |
| 1502 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1503 | goto nla_put_failure; |
| 1504 | } |
| 1505 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1506 | CMD(set_mcast_rate, SET_MCAST_RATE); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1507 | #ifdef CONFIG_NL80211_TESTMODE |
| 1508 | CMD(testmode_cmd, TESTMODE); |
| 1509 | #endif |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1510 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1511 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 1512 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1513 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 1514 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1515 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 1516 | if (rdev->wiphy.flags & |
| 1517 | WIPHY_FLAG_SUPPORTS_WMM_ADMISSION) |
| 1518 | CMD(add_tx_ts, ADD_TX_TS); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 1519 | } |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 1520 | /* add into the if now */ |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 1521 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 1522 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1523 | if (rdev->ops->connect || rdev->ops->auth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1524 | i++; |
| 1525 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1526 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1527 | } |
| 1528 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1529 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1530 | i++; |
| 1531 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1532 | goto nla_put_failure; |
| 1533 | } |
Johannes Berg | 74b70a4 | 2010-08-24 12:15:53 +0200 | [diff] [blame] | 1534 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1535 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1536 | state->split_start++; |
| 1537 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1538 | break; |
| 1539 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1540 | if (rdev->ops->remain_on_channel && |
| 1541 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1542 | nla_put_u32(msg, |
| 1543 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1544 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1545 | goto nla_put_failure; |
| 1546 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1547 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1548 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 1549 | goto nla_put_failure; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1550 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1551 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 1552 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1553 | state->split_start++; |
| 1554 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1555 | break; |
| 1556 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 1557 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1558 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1559 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1560 | state->split_start++; |
| 1561 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1562 | break; |
| 1563 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1564 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1565 | #endif |
| 1566 | case 7: |
| 1567 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1568 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1569 | goto nla_put_failure; |
| 1570 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1571 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1572 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1573 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1574 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1575 | state->split_start++; |
| 1576 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1577 | break; |
| 1578 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1579 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1580 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1581 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1582 | goto nla_put_failure; |
| 1583 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1584 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1585 | /* |
| 1586 | * We can only add the per-channel limit information if the |
| 1587 | * dump is split, otherwise it makes it too big. Therefore |
| 1588 | * only advertise it in that case. |
| 1589 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1590 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1591 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 1592 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1593 | goto nla_put_failure; |
| 1594 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1595 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1596 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1597 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 1598 | rdev->wiphy.ht_capa_mod_mask)) |
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.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 1602 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1603 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1604 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1605 | goto nla_put_failure; |
| 1606 | |
| 1607 | /* |
| 1608 | * Any information below this point is only available to |
| 1609 | * applications that can deal with it being split. This |
| 1610 | * helps ensure that newly added capabilities don't break |
| 1611 | * older tools by overrunning their buffers. |
| 1612 | * |
| 1613 | * We still increment split_start so that in the split |
| 1614 | * case we'll continue with more data in the next round, |
| 1615 | * but break unconditionally so unsplit data stops here. |
| 1616 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1617 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1618 | break; |
| 1619 | case 9: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1620 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1621 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1622 | rdev->wiphy.extended_capabilities_len, |
| 1623 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1624 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1625 | rdev->wiphy.extended_capabilities_len, |
| 1626 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1627 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1628 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1629 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1630 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1631 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 1632 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 1633 | goto nla_put_failure; |
| 1634 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1635 | state->split_start++; |
| 1636 | break; |
| 1637 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1638 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1639 | goto nla_put_failure; |
| 1640 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1641 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1642 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 1643 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 1644 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1645 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1646 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1647 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1648 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 1649 | goto nla_put_failure; |
| 1650 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1651 | state->split_start++; |
| 1652 | break; |
| 1653 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1654 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1655 | const struct nl80211_vendor_cmd_info *info; |
| 1656 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1657 | |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1658 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 1659 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 1660 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1661 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1662 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 1663 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1664 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1665 | goto nla_put_failure; |
| 1666 | } |
| 1667 | nla_nest_end(msg, nested); |
| 1668 | } |
| 1669 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1670 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1671 | const struct nl80211_vendor_cmd_info *info; |
| 1672 | struct nlattr *nested; |
| 1673 | |
| 1674 | nested = nla_nest_start(msg, |
| 1675 | NL80211_ATTR_VENDOR_EVENTS); |
| 1676 | if (!nested) |
| 1677 | goto nla_put_failure; |
| 1678 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1679 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 1680 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 1681 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 1682 | goto nla_put_failure; |
| 1683 | } |
| 1684 | nla_nest_end(msg, nested); |
| 1685 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 1686 | state->split_start++; |
| 1687 | break; |
| 1688 | case 12: |
| 1689 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 1690 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 1691 | rdev->wiphy.max_num_csa_counters)) |
| 1692 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 1693 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1694 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1695 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1696 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 1697 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1698 | finish: |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1699 | return genlmsg_end(msg, hdr); |
| 1700 | |
| 1701 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1702 | genlmsg_cancel(msg, hdr); |
| 1703 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1704 | } |
| 1705 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1706 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 1707 | struct netlink_callback *cb, |
| 1708 | struct nl80211_dump_wiphy_state *state) |
| 1709 | { |
| 1710 | struct nlattr **tb = nl80211_fam.attrbuf; |
| 1711 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1712 | tb, nl80211_fam.maxattr, nl80211_policy); |
| 1713 | /* ignore parse errors for backward compatibility */ |
| 1714 | if (ret) |
| 1715 | return 0; |
| 1716 | |
| 1717 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 1718 | if (tb[NL80211_ATTR_WIPHY]) |
| 1719 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 1720 | if (tb[NL80211_ATTR_WDEV]) |
| 1721 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 1722 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 1723 | struct net_device *netdev; |
| 1724 | struct cfg80211_registered_device *rdev; |
| 1725 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 1726 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 1727 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1728 | if (!netdev) |
| 1729 | return -ENODEV; |
| 1730 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 1731 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1732 | netdev->ieee80211_ptr->wiphy); |
| 1733 | state->filter_wiphy = rdev->wiphy_idx; |
| 1734 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1735 | } |
| 1736 | |
| 1737 | return 0; |
| 1738 | } |
| 1739 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1740 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 1741 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1742 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1743 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1744 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 1745 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1746 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1747 | if (!state) { |
| 1748 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 1749 | if (!state) { |
| 1750 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1751 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1752 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1753 | state->filter_wiphy = -1; |
| 1754 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 1755 | if (ret) { |
| 1756 | kfree(state); |
| 1757 | rtnl_unlock(); |
| 1758 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1759 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1760 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1761 | } |
| 1762 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1763 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 1764 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1765 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1766 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1767 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1768 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1769 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1770 | continue; |
| 1771 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 1772 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1773 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 1774 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1775 | NETLINK_CB(cb->skb).portid, |
| 1776 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1777 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1778 | if (ret < 0) { |
| 1779 | /* |
| 1780 | * If sending the wiphy data didn't fit (ENOBUFS |
| 1781 | * or EMSGSIZE returned), this SKB is still |
| 1782 | * empty (so it's not too big because another |
| 1783 | * wiphy dataset is already in the skb) and |
| 1784 | * we've not tried to adjust the dump allocation |
| 1785 | * yet ... then adjust the alloc size to be |
| 1786 | * bigger, and return 1 but with the empty skb. |
| 1787 | * This results in an empty message being RX'ed |
| 1788 | * in userspace, but that is ignored. |
| 1789 | * |
| 1790 | * We can then retry with the larger buffer. |
| 1791 | */ |
| 1792 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1793 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1794 | cb->min_dump_alloc < 4096) { |
| 1795 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 1796 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 1797 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1798 | return 1; |
| 1799 | } |
| 1800 | idx--; |
| 1801 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1802 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1803 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1804 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1805 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 1806 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1807 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1808 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1809 | |
| 1810 | return skb->len; |
| 1811 | } |
| 1812 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1813 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 1814 | { |
| 1815 | kfree((void *)cb->args[0]); |
| 1816 | return 0; |
| 1817 | } |
| 1818 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1819 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 1820 | { |
| 1821 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1822 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1823 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1824 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 1825 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1826 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1827 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1828 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 1829 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 1830 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 1831 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 1832 | nlmsg_free(msg); |
| 1833 | return -ENOBUFS; |
| 1834 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1835 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1836 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1837 | } |
| 1838 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1839 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 1840 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 1841 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 1842 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 1843 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 1844 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 1845 | }; |
| 1846 | |
| 1847 | static int parse_txq_params(struct nlattr *tb[], |
| 1848 | struct ieee80211_txq_params *txq_params) |
| 1849 | { |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1850 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1851 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 1852 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 1853 | return -EINVAL; |
| 1854 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1855 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1856 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 1857 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 1858 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 1859 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 1860 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 1861 | if (txq_params->ac >= NL80211_NUM_ACS) |
| 1862 | return -EINVAL; |
| 1863 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1864 | return 0; |
| 1865 | } |
| 1866 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1867 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 1868 | { |
| 1869 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 1870 | * You can only set the channel explicitly for WDS interfaces, |
| 1871 | * all others have their channel managed via their respective |
| 1872 | * "establish a connection" command (connect, join, ...) |
| 1873 | * |
| 1874 | * For AP/GO and mesh mode, the channel can be set with the |
| 1875 | * channel userspace API, but is only stored and passed to the |
| 1876 | * low-level driver when the AP starts or the mesh is joined. |
| 1877 | * This is for backward compatibility, userspace can also give |
| 1878 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1879 | * |
| 1880 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1881 | * whatever else is going on, so they have their own special |
| 1882 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1883 | */ |
| 1884 | return !wdev || |
| 1885 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1886 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1887 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 1888 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1889 | } |
| 1890 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1891 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 1892 | struct genl_info *info, |
| 1893 | struct cfg80211_chan_def *chandef) |
| 1894 | { |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 1895 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1896 | |
| 1897 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 1898 | return -EINVAL; |
| 1899 | |
| 1900 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 1901 | |
| 1902 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1903 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 1904 | chandef->center_freq1 = control_freq; |
| 1905 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1906 | |
| 1907 | /* Primary channel not allowed */ |
| 1908 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) |
| 1909 | return -EINVAL; |
| 1910 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1911 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1912 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1913 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1914 | chantype = nla_get_u32( |
| 1915 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1916 | |
| 1917 | switch (chantype) { |
| 1918 | case NL80211_CHAN_NO_HT: |
| 1919 | case NL80211_CHAN_HT20: |
| 1920 | case NL80211_CHAN_HT40PLUS: |
| 1921 | case NL80211_CHAN_HT40MINUS: |
| 1922 | cfg80211_chandef_create(chandef, chandef->chan, |
| 1923 | chantype); |
| 1924 | break; |
| 1925 | default: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1926 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1927 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1928 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 1929 | chandef->width = |
| 1930 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
| 1931 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) |
| 1932 | chandef->center_freq1 = |
| 1933 | nla_get_u32( |
| 1934 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); |
| 1935 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) |
| 1936 | chandef->center_freq2 = |
| 1937 | nla_get_u32( |
| 1938 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); |
| 1939 | } |
| 1940 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1941 | if (!cfg80211_chandef_valid(chandef)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1942 | return -EINVAL; |
| 1943 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 1944 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
| 1945 | IEEE80211_CHAN_DISABLED)) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1946 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 1947 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 1948 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 1949 | chandef->width == NL80211_CHAN_WIDTH_10) && |
| 1950 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) |
| 1951 | return -EINVAL; |
| 1952 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1953 | return 0; |
| 1954 | } |
| 1955 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1956 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1957 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1958 | struct genl_info *info) |
| 1959 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1960 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1961 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1962 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1963 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1964 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1965 | if (dev) |
| 1966 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1967 | if (!nl80211_can_set_dev_channel(wdev)) |
| 1968 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1969 | if (wdev) |
| 1970 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1971 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 1972 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 1973 | if (result) |
| 1974 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1975 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 1976 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1977 | case NL80211_IFTYPE_AP: |
| 1978 | case NL80211_IFTYPE_P2P_GO: |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 1979 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 1980 | result = -EINVAL; |
| 1981 | break; |
| 1982 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 1983 | if (wdev->beacon_interval) { |
| 1984 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 1985 | !(rdev->wiphy.features & |
| 1986 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 1987 | result = -EBUSY; |
| 1988 | break; |
| 1989 | } |
| 1990 | |
| 1991 | /* Only allow dynamic channel width changes */ |
| 1992 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 1993 | result = -EBUSY; |
| 1994 | break; |
| 1995 | } |
| 1996 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 1997 | if (result) |
| 1998 | break; |
| 1999 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2000 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2001 | result = 0; |
| 2002 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2003 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2004 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2005 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2006 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2007 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2008 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2009 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2010 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2011 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2012 | |
| 2013 | return result; |
| 2014 | } |
| 2015 | |
| 2016 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 2017 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2018 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2019 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2020 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2021 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2022 | } |
| 2023 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2024 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 2025 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2026 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2027 | struct net_device *dev = info->user_ptr[1]; |
| 2028 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2029 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2030 | |
| 2031 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2032 | return -EINVAL; |
| 2033 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2034 | if (netif_running(dev)) |
| 2035 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2036 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2037 | if (!rdev->ops->set_wds_peer) |
| 2038 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2039 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2040 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 2041 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2042 | |
| 2043 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2044 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2045 | } |
| 2046 | |
| 2047 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2048 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2049 | { |
| 2050 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2051 | struct net_device *netdev = NULL; |
| 2052 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 2053 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2054 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2055 | u32 changed; |
| 2056 | u8 retry_short = 0, retry_long = 0; |
| 2057 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2058 | u8 coverage_class = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2059 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2060 | ASSERT_RTNL(); |
| 2061 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2062 | /* |
| 2063 | * Try to find the wiphy and netdev. Normally this |
| 2064 | * function shouldn't need the netdev, but this is |
| 2065 | * done for backward compatibility -- previously |
| 2066 | * setting the channel was done per wiphy, but now |
| 2067 | * it is per netdev. Previous userland like hostapd |
| 2068 | * also passed a netdev to set_wiphy, so that it is |
| 2069 | * possible to let that go to the right netdev! |
| 2070 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2071 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2072 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 2073 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 2074 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2075 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2076 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2077 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2078 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2079 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2080 | } |
| 2081 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2082 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 2083 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 2084 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2085 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2086 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2087 | wdev = NULL; |
| 2088 | netdev = NULL; |
| 2089 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 2090 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2091 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2092 | |
| 2093 | /* |
| 2094 | * end workaround code, by now the rdev is available |
| 2095 | * and locked, and wdev may or may not be NULL. |
| 2096 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2097 | |
| 2098 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2099 | result = cfg80211_dev_rename( |
| 2100 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2101 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 2102 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2103 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2104 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2105 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 2106 | struct ieee80211_txq_params txq_params; |
| 2107 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 2108 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2109 | if (!rdev->ops->set_txq_params) |
| 2110 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2111 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2112 | if (!netdev) |
| 2113 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2114 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2115 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2116 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 2117 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 2118 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2119 | if (!netif_running(netdev)) |
| 2120 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 2121 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2122 | nla_for_each_nested(nl_txq_params, |
| 2123 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 2124 | rem_txq_params) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 2125 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 2126 | nla_data(nl_txq_params), |
| 2127 | nla_len(nl_txq_params), |
| 2128 | txq_params_policy); |
| 2129 | if (result) |
| 2130 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2131 | result = parse_txq_params(tb, &txq_params); |
| 2132 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2133 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2134 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2135 | result = rdev_set_txq_params(rdev, netdev, |
| 2136 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2137 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2138 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2139 | } |
| 2140 | } |
| 2141 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2142 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2143 | result = __nl80211_set_channel( |
| 2144 | rdev, |
| 2145 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 2146 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2147 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2148 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 2149 | } |
| 2150 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2151 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2152 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2153 | enum nl80211_tx_power_setting type; |
| 2154 | int idx, mbm = 0; |
| 2155 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2156 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 2157 | txp_wdev = NULL; |
| 2158 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2159 | if (!rdev->ops->set_tx_power) |
| 2160 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2161 | |
| 2162 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 2163 | type = nla_get_u32(info->attrs[idx]); |
| 2164 | |
| 2165 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2166 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 2167 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2168 | |
| 2169 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 2170 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 2171 | mbm = nla_get_u32(info->attrs[idx]); |
| 2172 | } |
| 2173 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2174 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2175 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2176 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 2177 | } |
| 2178 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2179 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 2180 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 2181 | u32 tx_ant, rx_ant; |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2182 | if ((!rdev->wiphy.available_antennas_tx && |
| 2183 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2184 | !rdev->ops->set_antenna) |
| 2185 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2186 | |
| 2187 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 2188 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 2189 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2190 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2191 | * available antenna masks, except for the "all" mask */ |
| 2192 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2193 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 2194 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2195 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 2196 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 2197 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 2198 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2199 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2200 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2201 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 2202 | } |
| 2203 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2204 | changed = 0; |
| 2205 | |
| 2206 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 2207 | retry_short = nla_get_u8( |
| 2208 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2209 | if (retry_short == 0) |
| 2210 | return -EINVAL; |
| 2211 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2212 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 2213 | } |
| 2214 | |
| 2215 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 2216 | retry_long = nla_get_u8( |
| 2217 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2218 | if (retry_long == 0) |
| 2219 | return -EINVAL; |
| 2220 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2221 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 2222 | } |
| 2223 | |
| 2224 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 2225 | frag_threshold = nla_get_u32( |
| 2226 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2227 | if (frag_threshold < 256) |
| 2228 | return -EINVAL; |
| 2229 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2230 | if (frag_threshold != (u32) -1) { |
| 2231 | /* |
| 2232 | * Fragments (apart from the last one) are required to |
| 2233 | * have even length. Make the fragmentation code |
| 2234 | * simpler by stripping LSB should someone try to use |
| 2235 | * odd threshold value. |
| 2236 | */ |
| 2237 | frag_threshold &= ~0x1; |
| 2238 | } |
| 2239 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 2240 | } |
| 2241 | |
| 2242 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 2243 | rts_threshold = nla_get_u32( |
| 2244 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 2245 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 2246 | } |
| 2247 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2248 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2249 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 2250 | return -EINVAL; |
| 2251 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2252 | coverage_class = nla_get_u8( |
| 2253 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 2254 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 2255 | } |
| 2256 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 2257 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 2258 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 2259 | return -EOPNOTSUPP; |
| 2260 | |
| 2261 | changed |= WIPHY_PARAM_DYN_ACK; |
| 2262 | } |
| 2263 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2264 | if (changed) { |
| 2265 | u8 old_retry_short, old_retry_long; |
| 2266 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2267 | u8 old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2268 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2269 | if (!rdev->ops->set_wiphy_params) |
| 2270 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2271 | |
| 2272 | old_retry_short = rdev->wiphy.retry_short; |
| 2273 | old_retry_long = rdev->wiphy.retry_long; |
| 2274 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 2275 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2276 | old_coverage_class = rdev->wiphy.coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2277 | |
| 2278 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 2279 | rdev->wiphy.retry_short = retry_short; |
| 2280 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 2281 | rdev->wiphy.retry_long = retry_long; |
| 2282 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 2283 | rdev->wiphy.frag_threshold = frag_threshold; |
| 2284 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 2285 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2286 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 2287 | rdev->wiphy.coverage_class = coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2288 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2289 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2290 | if (result) { |
| 2291 | rdev->wiphy.retry_short = old_retry_short; |
| 2292 | rdev->wiphy.retry_long = old_retry_long; |
| 2293 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 2294 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 2295 | rdev->wiphy.coverage_class = old_coverage_class; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2296 | } |
| 2297 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2298 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2299 | } |
| 2300 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2301 | static inline u64 wdev_id(struct wireless_dev *wdev) |
| 2302 | { |
| 2303 | return (u64)wdev->identifier | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2304 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2305 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2306 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2307 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 2308 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2309 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2310 | WARN_ON(!cfg80211_chandef_valid(chandef)); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2311 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2312 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 2313 | chandef->chan->center_freq)) |
| 2314 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2315 | switch (chandef->width) { |
| 2316 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 2317 | case NL80211_CHAN_WIDTH_20: |
| 2318 | case NL80211_CHAN_WIDTH_40: |
| 2319 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 2320 | cfg80211_get_chandef_type(chandef))) |
| 2321 | return -ENOBUFS; |
| 2322 | break; |
| 2323 | default: |
| 2324 | break; |
| 2325 | } |
| 2326 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 2327 | return -ENOBUFS; |
| 2328 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 2329 | return -ENOBUFS; |
| 2330 | if (chandef->center_freq2 && |
| 2331 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2332 | return -ENOBUFS; |
| 2333 | return 0; |
| 2334 | } |
| 2335 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2336 | 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] | 2337 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2338 | struct wireless_dev *wdev) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2339 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2340 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2341 | void *hdr; |
| 2342 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2343 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2344 | if (!hdr) |
| 2345 | return -1; |
| 2346 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2347 | if (dev && |
| 2348 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2349 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2350 | goto nla_put_failure; |
| 2351 | |
| 2352 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 2353 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 2354 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2355 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2356 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 2357 | rdev->devlist_generation ^ |
| 2358 | (cfg80211_rdev_list_generation << 2))) |
| 2359 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2360 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2361 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2362 | int ret; |
| 2363 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 2364 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2365 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 2366 | if (ret == 0) { |
| 2367 | if (nl80211_send_chandef(msg, &chandef)) |
| 2368 | goto nla_put_failure; |
| 2369 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 2370 | } |
| 2371 | |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 2372 | if (wdev->ssid_len) { |
| 2373 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
| 2374 | goto nla_put_failure; |
| 2375 | } |
| 2376 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2377 | return genlmsg_end(msg, hdr); |
| 2378 | |
| 2379 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2380 | genlmsg_cancel(msg, hdr); |
| 2381 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2382 | } |
| 2383 | |
| 2384 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 2385 | { |
| 2386 | int wp_idx = 0; |
| 2387 | int if_idx = 0; |
| 2388 | int wp_start = cb->args[0]; |
| 2389 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2390 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2391 | struct wireless_dev *wdev; |
| 2392 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2393 | rtnl_lock(); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2394 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2395 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2396 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2397 | if (wp_idx < wp_start) { |
| 2398 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2399 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2400 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2401 | if_idx = 0; |
| 2402 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 2403 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2404 | if (if_idx < if_start) { |
| 2405 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2406 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2407 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2408 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2409 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2410 | rdev, wdev) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2411 | goto out; |
| 2412 | } |
| 2413 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2414 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2415 | |
| 2416 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2417 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2418 | out: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2419 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2420 | |
| 2421 | cb->args[0] = wp_idx; |
| 2422 | cb->args[1] = if_idx; |
| 2423 | |
| 2424 | return skb->len; |
| 2425 | } |
| 2426 | |
| 2427 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 2428 | { |
| 2429 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2430 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 2431 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2432 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2433 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2434 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2435 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2436 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2437 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2438 | rdev, wdev) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2439 | nlmsg_free(msg); |
| 2440 | return -ENOBUFS; |
| 2441 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2442 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2443 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2444 | } |
| 2445 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2446 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 2447 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 2448 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 2449 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 2450 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 2451 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2452 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2453 | }; |
| 2454 | |
| 2455 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 2456 | { |
| 2457 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 2458 | int flag; |
| 2459 | |
| 2460 | *mntrflags = 0; |
| 2461 | |
| 2462 | if (!nla) |
| 2463 | return -EINVAL; |
| 2464 | |
| 2465 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 2466 | nla, mntr_flags_policy)) |
| 2467 | return -EINVAL; |
| 2468 | |
| 2469 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 2470 | if (flags[flag]) |
| 2471 | *mntrflags |= (1<<flag); |
| 2472 | |
| 2473 | return 0; |
| 2474 | } |
| 2475 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2476 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2477 | struct net_device *netdev, u8 use_4addr, |
| 2478 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2479 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2480 | if (!use_4addr) { |
Jiri Pirko | f350a0a8 | 2010-06-15 06:50:45 +0000 | [diff] [blame] | 2481 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2482 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2483 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2484 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2485 | |
| 2486 | switch (iftype) { |
| 2487 | case NL80211_IFTYPE_AP_VLAN: |
| 2488 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 2489 | return 0; |
| 2490 | break; |
| 2491 | case NL80211_IFTYPE_STATION: |
| 2492 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 2493 | return 0; |
| 2494 | break; |
| 2495 | default: |
| 2496 | break; |
| 2497 | } |
| 2498 | |
| 2499 | return -EOPNOTSUPP; |
| 2500 | } |
| 2501 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2502 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 2503 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2504 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2505 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 2506 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2507 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2508 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2509 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2510 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2511 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2512 | memset(¶ms, 0, sizeof(params)); |
| 2513 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2514 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2515 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2516 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2517 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 2518 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2519 | change = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2520 | if (ntype > NL80211_IFTYPE_MAX) |
| 2521 | return -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 2522 | } |
| 2523 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2524 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2525 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 2526 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2527 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 2528 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2529 | if (netif_running(dev)) |
| 2530 | return -EBUSY; |
| 2531 | |
| 2532 | wdev_lock(wdev); |
| 2533 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2534 | IEEE80211_MAX_MESH_ID_LEN); |
| 2535 | wdev->mesh_id_up_len = |
| 2536 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2537 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2538 | wdev->mesh_id_up_len); |
| 2539 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2540 | } |
| 2541 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2542 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 2543 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 2544 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2545 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2546 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2547 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2548 | } else { |
| 2549 | params.use_4addr = -1; |
| 2550 | } |
| 2551 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2552 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2553 | if (ntype != NL80211_IFTYPE_MONITOR) |
| 2554 | return -EINVAL; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2555 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 2556 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2557 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2558 | return err; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2559 | |
| 2560 | flags = &_flags; |
| 2561 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 2562 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2563 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2564 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2565 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2566 | return -EOPNOTSUPP; |
| 2567 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2568 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 2569 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 2570 | else |
| 2571 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 2572 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2573 | if (!err && params.use_4addr != -1) |
| 2574 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 2575 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2576 | return err; |
| 2577 | } |
| 2578 | |
| 2579 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 2580 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2581 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2582 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2583 | struct wireless_dev *wdev; |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2584 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2585 | int err; |
| 2586 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2587 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2588 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2589 | /* to avoid failing a new interface creation due to pending removal */ |
| 2590 | cfg80211_destroy_ifaces(rdev); |
| 2591 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2592 | memset(¶ms, 0, sizeof(params)); |
| 2593 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2594 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 2595 | return -EINVAL; |
| 2596 | |
| 2597 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 2598 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 2599 | if (type > NL80211_IFTYPE_MAX) |
| 2600 | return -EINVAL; |
| 2601 | } |
| 2602 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2603 | if (!rdev->ops->add_virtual_intf || |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2604 | !(rdev->wiphy.interface_modes & (1 << type))) |
| 2605 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2606 | |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 2607 | if (type == NL80211_IFTYPE_P2P_DEVICE && info->attrs[NL80211_ATTR_MAC]) { |
| 2608 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 2609 | ETH_ALEN); |
| 2610 | if (!is_valid_ether_addr(params.macaddr)) |
| 2611 | return -EADDRNOTAVAIL; |
| 2612 | } |
| 2613 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2614 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2615 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 2616 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2617 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2618 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 2619 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 2620 | |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2621 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 2622 | if (!msg) |
| 2623 | return -ENOMEM; |
| 2624 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 2625 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 2626 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 2627 | &flags); |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2628 | |
Luciano Coelho | 1800329 | 2013-08-29 13:26:57 +0300 | [diff] [blame] | 2629 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 2630 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 2631 | return -EOPNOTSUPP; |
| 2632 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2633 | wdev = rdev_add_virtual_intf(rdev, |
| 2634 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
| 2635 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2636 | if (IS_ERR(wdev)) { |
| 2637 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2638 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2639 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2640 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 2641 | if (info->attrs[NL80211_ATTR_IFACE_SOCKET_OWNER]) |
| 2642 | wdev->owner_nlportid = info->snd_portid; |
| 2643 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2644 | switch (type) { |
| 2645 | case NL80211_IFTYPE_MESH_POINT: |
| 2646 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 2647 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2648 | wdev_lock(wdev); |
| 2649 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 2650 | IEEE80211_MAX_MESH_ID_LEN); |
| 2651 | wdev->mesh_id_up_len = |
| 2652 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 2653 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 2654 | wdev->mesh_id_up_len); |
| 2655 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2656 | break; |
| 2657 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2658 | /* |
| 2659 | * P2P Device doesn't have a netdev, so doesn't go |
| 2660 | * through the netdev notifier and must be added here |
| 2661 | */ |
| 2662 | mutex_init(&wdev->mtx); |
| 2663 | INIT_LIST_HEAD(&wdev->event_list); |
| 2664 | spin_lock_init(&wdev->event_lock); |
| 2665 | INIT_LIST_HEAD(&wdev->mgmt_registrations); |
| 2666 | spin_lock_init(&wdev->mgmt_registrations_lock); |
| 2667 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2668 | wdev->identifier = ++rdev->wdev_id; |
| 2669 | list_add_rcu(&wdev->list, &rdev->wdev_list); |
| 2670 | rdev->devlist_generation++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 2671 | break; |
| 2672 | default: |
| 2673 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2674 | } |
| 2675 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2676 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 2677 | rdev, wdev) < 0) { |
| 2678 | nlmsg_free(msg); |
| 2679 | return -ENOBUFS; |
| 2680 | } |
| 2681 | |
| 2682 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2683 | } |
| 2684 | |
| 2685 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 2686 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2687 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2688 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2689 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2690 | if (!rdev->ops->del_virtual_intf) |
| 2691 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2692 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 2693 | /* |
| 2694 | * If we remove a wireless device without a netdev then clear |
| 2695 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 2696 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 2697 | * since the wdev has been freed, unlike with a netdev where |
| 2698 | * we need the dev_put() for the netdev to really be freed. |
| 2699 | */ |
| 2700 | if (!wdev->netdev) |
| 2701 | info->user_ptr[1] = NULL; |
| 2702 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2703 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2704 | } |
| 2705 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2706 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 2707 | { |
| 2708 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2709 | struct net_device *dev = info->user_ptr[1]; |
| 2710 | u16 noack_map; |
| 2711 | |
| 2712 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 2713 | return -EINVAL; |
| 2714 | |
| 2715 | if (!rdev->ops->set_noack_map) |
| 2716 | return -EOPNOTSUPP; |
| 2717 | |
| 2718 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 2719 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2720 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 2721 | } |
| 2722 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2723 | struct get_key_cookie { |
| 2724 | struct sk_buff *msg; |
| 2725 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2726 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2727 | }; |
| 2728 | |
| 2729 | static void get_key_callback(void *c, struct key_params *params) |
| 2730 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2731 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2732 | struct get_key_cookie *cookie = c; |
| 2733 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2734 | if ((params->key && |
| 2735 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 2736 | params->key_len, params->key)) || |
| 2737 | (params->seq && |
| 2738 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 2739 | params->seq_len, params->seq)) || |
| 2740 | (params->cipher && |
| 2741 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 2742 | params->cipher))) |
| 2743 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2744 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2745 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 2746 | if (!key) |
| 2747 | goto nla_put_failure; |
| 2748 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2749 | if ((params->key && |
| 2750 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 2751 | params->key_len, params->key)) || |
| 2752 | (params->seq && |
| 2753 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 2754 | params->seq_len, params->seq)) || |
| 2755 | (params->cipher && |
| 2756 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 2757 | params->cipher))) |
| 2758 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2759 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2760 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
| 2761 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2762 | |
| 2763 | nla_nest_end(cookie->msg, key); |
| 2764 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2765 | return; |
| 2766 | nla_put_failure: |
| 2767 | cookie->error = 1; |
| 2768 | } |
| 2769 | |
| 2770 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 2771 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2772 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2773 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2774 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2775 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2776 | const u8 *mac_addr = NULL; |
| 2777 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2778 | struct get_key_cookie cookie = { |
| 2779 | .error = 0, |
| 2780 | }; |
| 2781 | void *hdr; |
| 2782 | struct sk_buff *msg; |
| 2783 | |
| 2784 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 2785 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 2786 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 2787 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2788 | return -EINVAL; |
| 2789 | |
| 2790 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2791 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2792 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2793 | pairwise = !!mac_addr; |
| 2794 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 2795 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
| 2796 | if (kt >= NUM_NL80211_KEYTYPES) |
| 2797 | return -EINVAL; |
| 2798 | if (kt != NL80211_KEYTYPE_GROUP && |
| 2799 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 2800 | return -EINVAL; |
| 2801 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 2802 | } |
| 2803 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2804 | if (!rdev->ops->get_key) |
| 2805 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2806 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2807 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2808 | if (!msg) |
| 2809 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2810 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 2811 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2812 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 2813 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 2814 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2815 | |
| 2816 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2817 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2818 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2819 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 2820 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2821 | goto nla_put_failure; |
| 2822 | if (mac_addr && |
| 2823 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 2824 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2825 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2826 | if (pairwise && mac_addr && |
| 2827 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 2828 | return -ENOENT; |
| 2829 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2830 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 2831 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2832 | |
| 2833 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2834 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2835 | |
| 2836 | if (cookie.error) |
| 2837 | goto nla_put_failure; |
| 2838 | |
| 2839 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2840 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2841 | |
| 2842 | nla_put_failure: |
| 2843 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 2844 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2845 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2846 | return err; |
| 2847 | } |
| 2848 | |
| 2849 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 2850 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2851 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2852 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2853 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2854 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2855 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2856 | err = nl80211_parse_key(info, &key); |
| 2857 | if (err) |
| 2858 | return err; |
| 2859 | |
| 2860 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2861 | return -EINVAL; |
| 2862 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2863 | /* only support setting default key */ |
| 2864 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2865 | return -EINVAL; |
| 2866 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2867 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2868 | |
| 2869 | if (key.def) { |
| 2870 | if (!rdev->ops->set_default_key) { |
| 2871 | err = -EOPNOTSUPP; |
| 2872 | goto out; |
| 2873 | } |
| 2874 | |
| 2875 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2876 | if (err) |
| 2877 | goto out; |
| 2878 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2879 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2880 | key.def_uni, key.def_multi); |
| 2881 | |
| 2882 | if (err) |
| 2883 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2884 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 2885 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2886 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 2887 | #endif |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2888 | } else { |
| 2889 | if (key.def_uni || !key.def_multi) { |
| 2890 | err = -EINVAL; |
| 2891 | goto out; |
| 2892 | } |
| 2893 | |
| 2894 | if (!rdev->ops->set_default_mgmt_key) { |
| 2895 | err = -EOPNOTSUPP; |
| 2896 | goto out; |
| 2897 | } |
| 2898 | |
| 2899 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2900 | if (err) |
| 2901 | goto out; |
| 2902 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2903 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 2904 | if (err) |
| 2905 | goto out; |
| 2906 | |
| 2907 | #ifdef CONFIG_CFG80211_WEXT |
| 2908 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 2909 | #endif |
| 2910 | } |
| 2911 | |
| 2912 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2913 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2914 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2915 | return err; |
| 2916 | } |
| 2917 | |
| 2918 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 2919 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2920 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2921 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2922 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2923 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2924 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2925 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2926 | err = nl80211_parse_key(info, &key); |
| 2927 | if (err) |
| 2928 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2929 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2930 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2931 | return -EINVAL; |
| 2932 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2933 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2934 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2935 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2936 | if (key.type == -1) { |
| 2937 | if (mac_addr) |
| 2938 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2939 | else |
| 2940 | key.type = NL80211_KEYTYPE_GROUP; |
| 2941 | } |
| 2942 | |
| 2943 | /* for now */ |
| 2944 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2945 | key.type != NL80211_KEYTYPE_GROUP) |
| 2946 | return -EINVAL; |
| 2947 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2948 | if (!rdev->ops->add_key) |
| 2949 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2950 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2951 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 2952 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2953 | mac_addr)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2954 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2955 | |
| 2956 | wdev_lock(dev->ieee80211_ptr); |
| 2957 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 2958 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 2959 | err = rdev_add_key(rdev, dev, key.idx, |
| 2960 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 2961 | mac_addr, &key.p); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2962 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2963 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2964 | return err; |
| 2965 | } |
| 2966 | |
| 2967 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 2968 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2969 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2970 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2971 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2972 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2973 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2974 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 2975 | err = nl80211_parse_key(info, &key); |
| 2976 | if (err) |
| 2977 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2978 | |
| 2979 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2980 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2981 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2982 | if (key.type == -1) { |
| 2983 | if (mac_addr) |
| 2984 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 2985 | else |
| 2986 | key.type = NL80211_KEYTYPE_GROUP; |
| 2987 | } |
| 2988 | |
| 2989 | /* for now */ |
| 2990 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 2991 | key.type != NL80211_KEYTYPE_GROUP) |
| 2992 | return -EINVAL; |
| 2993 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2994 | if (!rdev->ops->del_key) |
| 2995 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2996 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2997 | wdev_lock(dev->ieee80211_ptr); |
| 2998 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 2999 | |
| 3000 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && |
| 3001 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3002 | err = -ENOENT; |
| 3003 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3004 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3005 | err = rdev_del_key(rdev, dev, key.idx, |
| 3006 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 3007 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3008 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 3009 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3010 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3011 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3012 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3013 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3014 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 3015 | } |
| 3016 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3017 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 3018 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3019 | return err; |
| 3020 | } |
| 3021 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3022 | /* This function returns an error or the number of nested attributes */ |
| 3023 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 3024 | { |
| 3025 | struct nlattr *attr; |
| 3026 | int n_entries = 0, tmp; |
| 3027 | |
| 3028 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 3029 | if (nla_len(attr) != ETH_ALEN) |
| 3030 | return -EINVAL; |
| 3031 | |
| 3032 | n_entries++; |
| 3033 | } |
| 3034 | |
| 3035 | return n_entries; |
| 3036 | } |
| 3037 | |
| 3038 | /* |
| 3039 | * This function parses ACL information and allocates memory for ACL data. |
| 3040 | * On successful return, the calling function is responsible to free the |
| 3041 | * ACL buffer returned by this function. |
| 3042 | */ |
| 3043 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 3044 | struct genl_info *info) |
| 3045 | { |
| 3046 | enum nl80211_acl_policy acl_policy; |
| 3047 | struct nlattr *attr; |
| 3048 | struct cfg80211_acl_data *acl; |
| 3049 | int i = 0, n_entries, tmp; |
| 3050 | |
| 3051 | if (!wiphy->max_acl_mac_addrs) |
| 3052 | return ERR_PTR(-EOPNOTSUPP); |
| 3053 | |
| 3054 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 3055 | return ERR_PTR(-EINVAL); |
| 3056 | |
| 3057 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 3058 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 3059 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 3060 | return ERR_PTR(-EINVAL); |
| 3061 | |
| 3062 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 3063 | return ERR_PTR(-EINVAL); |
| 3064 | |
| 3065 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 3066 | if (n_entries < 0) |
| 3067 | return ERR_PTR(n_entries); |
| 3068 | |
| 3069 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 3070 | return ERR_PTR(-ENOTSUPP); |
| 3071 | |
| 3072 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), |
| 3073 | GFP_KERNEL); |
| 3074 | if (!acl) |
| 3075 | return ERR_PTR(-ENOMEM); |
| 3076 | |
| 3077 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 3078 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 3079 | i++; |
| 3080 | } |
| 3081 | |
| 3082 | acl->n_acl_entries = n_entries; |
| 3083 | acl->acl_policy = acl_policy; |
| 3084 | |
| 3085 | return acl; |
| 3086 | } |
| 3087 | |
| 3088 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 3089 | { |
| 3090 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3091 | struct net_device *dev = info->user_ptr[1]; |
| 3092 | struct cfg80211_acl_data *acl; |
| 3093 | int err; |
| 3094 | |
| 3095 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3096 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3097 | return -EOPNOTSUPP; |
| 3098 | |
| 3099 | if (!dev->ieee80211_ptr->beacon_interval) |
| 3100 | return -EINVAL; |
| 3101 | |
| 3102 | acl = parse_acl_data(&rdev->wiphy, info); |
| 3103 | if (IS_ERR(acl)) |
| 3104 | return PTR_ERR(acl); |
| 3105 | |
| 3106 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 3107 | |
| 3108 | kfree(acl); |
| 3109 | |
| 3110 | return err; |
| 3111 | } |
| 3112 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3113 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3114 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3115 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3116 | bool haveinfo = false; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3117 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3118 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
| 3119 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || |
| 3120 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || |
| 3121 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3122 | return -EINVAL; |
| 3123 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3124 | memset(bcn, 0, sizeof(*bcn)); |
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 (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 3127 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 3128 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3129 | if (!bcn->head_len) |
| 3130 | return -EINVAL; |
| 3131 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3132 | } |
| 3133 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3134 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 3135 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 3136 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3137 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3138 | } |
| 3139 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3140 | if (!haveinfo) |
| 3141 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3142 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3143 | if (attrs[NL80211_ATTR_IE]) { |
| 3144 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 3145 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3146 | } |
| 3147 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3148 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3149 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3150 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3151 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3152 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3153 | } |
| 3154 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3155 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3156 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3157 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3158 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3159 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 3160 | } |
| 3161 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3162 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 3163 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 3164 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 3165 | } |
| 3166 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3167 | return 0; |
| 3168 | } |
| 3169 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3170 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 3171 | struct cfg80211_ap_settings *params) |
| 3172 | { |
| 3173 | struct wireless_dev *wdev; |
| 3174 | bool ret = false; |
| 3175 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 3176 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3177 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 3178 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 3179 | continue; |
| 3180 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3181 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3182 | continue; |
| 3183 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3184 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3185 | ret = true; |
| 3186 | break; |
| 3187 | } |
| 3188 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3189 | return ret; |
| 3190 | } |
| 3191 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3192 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 3193 | enum nl80211_auth_type auth_type, |
| 3194 | enum nl80211_commands cmd) |
| 3195 | { |
| 3196 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 3197 | return false; |
| 3198 | |
| 3199 | switch (cmd) { |
| 3200 | case NL80211_CMD_AUTHENTICATE: |
| 3201 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 3202 | auth_type == NL80211_AUTHTYPE_SAE) |
| 3203 | return false; |
| 3204 | return true; |
| 3205 | case NL80211_CMD_CONNECT: |
| 3206 | case NL80211_CMD_START_AP: |
| 3207 | /* SAE not supported yet */ |
| 3208 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 3209 | return false; |
| 3210 | return true; |
| 3211 | default: |
| 3212 | return false; |
| 3213 | } |
| 3214 | } |
| 3215 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3216 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 3217 | { |
| 3218 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3219 | struct net_device *dev = info->user_ptr[1]; |
| 3220 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3221 | struct cfg80211_ap_settings params; |
| 3222 | int err; |
| 3223 | |
| 3224 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3225 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3226 | return -EOPNOTSUPP; |
| 3227 | |
| 3228 | if (!rdev->ops->start_ap) |
| 3229 | return -EOPNOTSUPP; |
| 3230 | |
| 3231 | if (wdev->beacon_interval) |
| 3232 | return -EALREADY; |
| 3233 | |
| 3234 | memset(¶ms, 0, sizeof(params)); |
| 3235 | |
| 3236 | /* these are required for START_AP */ |
| 3237 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 3238 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 3239 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 3240 | return -EINVAL; |
| 3241 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3242 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3243 | if (err) |
| 3244 | return err; |
| 3245 | |
| 3246 | params.beacon_interval = |
| 3247 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3248 | params.dtim_period = |
| 3249 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 3250 | |
| 3251 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); |
| 3252 | if (err) |
| 3253 | return err; |
| 3254 | |
| 3255 | /* |
| 3256 | * In theory, some of these attributes should be required here |
| 3257 | * but since they were not used when the command was originally |
| 3258 | * added, keep them optional for old user space programs to let |
| 3259 | * them continue to work with drivers that do not need the |
| 3260 | * additional information -- drivers must check! |
| 3261 | */ |
| 3262 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 3263 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3264 | params.ssid_len = |
| 3265 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3266 | if (params.ssid_len == 0 || |
| 3267 | params.ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3268 | return -EINVAL; |
| 3269 | } |
| 3270 | |
| 3271 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { |
| 3272 | params.hidden_ssid = nla_get_u32( |
| 3273 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
| 3274 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && |
| 3275 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && |
| 3276 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) |
| 3277 | return -EINVAL; |
| 3278 | } |
| 3279 | |
| 3280 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 3281 | |
| 3282 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3283 | params.auth_type = nla_get_u32( |
| 3284 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 3285 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 3286 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3287 | return -EINVAL; |
| 3288 | } else |
| 3289 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3290 | |
| 3291 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 3292 | NL80211_MAX_NR_CIPHER_SUITES); |
| 3293 | if (err) |
| 3294 | return err; |
| 3295 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 3296 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 3297 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 3298 | return -EOPNOTSUPP; |
| 3299 | params.inactivity_timeout = nla_get_u16( |
| 3300 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 3301 | } |
| 3302 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 3303 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 3304 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3305 | return -EINVAL; |
| 3306 | params.p2p_ctwindow = |
| 3307 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 3308 | if (params.p2p_ctwindow > 127) |
| 3309 | return -EINVAL; |
| 3310 | if (params.p2p_ctwindow != 0 && |
| 3311 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 3312 | return -EINVAL; |
| 3313 | } |
| 3314 | |
| 3315 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 3316 | u8 tmp; |
| 3317 | |
| 3318 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3319 | return -EINVAL; |
| 3320 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 3321 | if (tmp > 1) |
| 3322 | return -EINVAL; |
| 3323 | params.p2p_opp_ps = tmp; |
| 3324 | if (params.p2p_opp_ps != 0 && |
| 3325 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 3326 | return -EINVAL; |
| 3327 | } |
| 3328 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3329 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3330 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 3331 | if (err) |
| 3332 | return err; |
| 3333 | } else if (wdev->preset_chandef.chan) { |
| 3334 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3335 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3336 | return -EINVAL; |
| 3337 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 3338 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
| 3339 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3340 | return -EINVAL; |
| 3341 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3342 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 3343 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 3344 | if (IS_ERR(params.acl)) |
| 3345 | return PTR_ERR(params.acl); |
| 3346 | } |
| 3347 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3348 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3349 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3350 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3351 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3352 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 3353 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 3354 | wdev->ssid_len = params.ssid_len; |
| 3355 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 3356 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3357 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 3358 | |
| 3359 | kfree(params.acl); |
| 3360 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 3361 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3362 | } |
| 3363 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3364 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 3365 | { |
| 3366 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3367 | struct net_device *dev = info->user_ptr[1]; |
| 3368 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3369 | struct cfg80211_beacon_data params; |
| 3370 | int err; |
| 3371 | |
| 3372 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3373 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3374 | return -EOPNOTSUPP; |
| 3375 | |
| 3376 | if (!rdev->ops->change_beacon) |
| 3377 | return -EOPNOTSUPP; |
| 3378 | |
| 3379 | if (!wdev->beacon_interval) |
| 3380 | return -EINVAL; |
| 3381 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 3382 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3383 | if (err) |
| 3384 | return err; |
| 3385 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 3386 | wdev_lock(wdev); |
| 3387 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 3388 | wdev_unlock(wdev); |
| 3389 | |
| 3390 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3391 | } |
| 3392 | |
| 3393 | 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] | 3394 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3395 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3396 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3397 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 3398 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3399 | } |
| 3400 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3401 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 3402 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 3403 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 3404 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 3405 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 3406 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 3407 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3408 | }; |
| 3409 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3410 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3411 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3412 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3413 | { |
| 3414 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3415 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3416 | int flag; |
| 3417 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3418 | /* |
| 3419 | * Try parsing the new attribute first so userspace |
| 3420 | * can specify both for older kernels. |
| 3421 | */ |
| 3422 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 3423 | if (nla) { |
| 3424 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3425 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3426 | sta_flags = nla_data(nla); |
| 3427 | params->sta_flags_mask = sta_flags->mask; |
| 3428 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3429 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3430 | if ((params->sta_flags_mask | |
| 3431 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 3432 | return -EINVAL; |
| 3433 | return 0; |
| 3434 | } |
| 3435 | |
| 3436 | /* if present, parse the old attribute */ |
| 3437 | |
| 3438 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3439 | if (!nla) |
| 3440 | return 0; |
| 3441 | |
| 3442 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 3443 | nla, sta_flags_policy)) |
| 3444 | return -EINVAL; |
| 3445 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 3446 | /* |
| 3447 | * Only allow certain flags for interface types so that |
| 3448 | * other attributes are silently ignored. Remember that |
| 3449 | * this is backward compatibility code with old userspace |
| 3450 | * and shouldn't be hit in other cases anyway. |
| 3451 | */ |
| 3452 | switch (iftype) { |
| 3453 | case NL80211_IFTYPE_AP: |
| 3454 | case NL80211_IFTYPE_AP_VLAN: |
| 3455 | case NL80211_IFTYPE_P2P_GO: |
| 3456 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3457 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3458 | BIT(NL80211_STA_FLAG_WME) | |
| 3459 | BIT(NL80211_STA_FLAG_MFP); |
| 3460 | break; |
| 3461 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3462 | case NL80211_IFTYPE_STATION: |
| 3463 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3464 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3465 | break; |
| 3466 | case NL80211_IFTYPE_MESH_POINT: |
| 3467 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3468 | BIT(NL80211_STA_FLAG_MFP) | |
| 3469 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3470 | default: |
| 3471 | return -EINVAL; |
| 3472 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3473 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3474 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 3475 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 3476 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3477 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 3478 | /* no longer support new API additions in old API */ |
| 3479 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 3480 | return -EINVAL; |
| 3481 | } |
| 3482 | } |
| 3483 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3484 | return 0; |
| 3485 | } |
| 3486 | |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3487 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
| 3488 | int attr) |
| 3489 | { |
| 3490 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3491 | u32 bitrate; |
| 3492 | u16 bitrate_compat; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3493 | |
| 3494 | rate = nla_nest_start(msg, attr); |
| 3495 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3496 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3497 | |
| 3498 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 3499 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 3500 | /* report 16-bit bitrate only if we can */ |
| 3501 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 3502 | if (bitrate > 0 && |
| 3503 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 3504 | return false; |
| 3505 | if (bitrate_compat > 0 && |
| 3506 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 3507 | return false; |
| 3508 | |
| 3509 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 3510 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 3511 | return false; |
| 3512 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3513 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3514 | return false; |
| 3515 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3516 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3517 | return false; |
| 3518 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 3519 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 3520 | return false; |
| 3521 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 3522 | return false; |
| 3523 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH && |
| 3524 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) |
| 3525 | return false; |
| 3526 | if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH && |
| 3527 | nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH)) |
| 3528 | return false; |
| 3529 | if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH && |
| 3530 | nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH)) |
| 3531 | return false; |
| 3532 | if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH && |
| 3533 | nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH)) |
| 3534 | return false; |
| 3535 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 3536 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 3537 | return false; |
| 3538 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3539 | |
| 3540 | nla_nest_end(msg, rate); |
| 3541 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3542 | } |
| 3543 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3544 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 3545 | int id) |
| 3546 | { |
| 3547 | void *attr; |
| 3548 | int i = 0; |
| 3549 | |
| 3550 | if (!mask) |
| 3551 | return true; |
| 3552 | |
| 3553 | attr = nla_nest_start(msg, id); |
| 3554 | if (!attr) |
| 3555 | return false; |
| 3556 | |
| 3557 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 3558 | if (!(mask & BIT(i))) |
| 3559 | continue; |
| 3560 | |
| 3561 | if (nla_put_u8(msg, i, signal[i])) |
| 3562 | return false; |
| 3563 | } |
| 3564 | |
| 3565 | nla_nest_end(msg, attr); |
| 3566 | |
| 3567 | return true; |
| 3568 | } |
| 3569 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3570 | 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] | 3571 | int flags, |
| 3572 | struct cfg80211_registered_device *rdev, |
| 3573 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 3574 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3575 | { |
| 3576 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3577 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3578 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3579 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3580 | if (!hdr) |
| 3581 | return -1; |
| 3582 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3583 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3584 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 3585 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 3586 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3587 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3588 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 3589 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3590 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3591 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
| 3592 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, |
| 3593 | sinfo->connected_time)) |
| 3594 | goto nla_put_failure; |
| 3595 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && |
| 3596 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 3597 | sinfo->inactive_time)) |
| 3598 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3599 | if ((sinfo->filled & (STATION_INFO_RX_BYTES | |
| 3600 | STATION_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3601 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3602 | (u32)sinfo->rx_bytes)) |
| 3603 | goto nla_put_failure; |
| 3604 | if ((sinfo->filled & (STATION_INFO_TX_BYTES | |
Felix Fietkau | 4325d72 | 2013-05-23 15:05:59 +0200 | [diff] [blame] | 3605 | STATION_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3606 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 3607 | (u32)sinfo->tx_bytes)) |
| 3608 | goto nla_put_failure; |
| 3609 | if ((sinfo->filled & STATION_INFO_RX_BYTES64) && |
| 3610 | nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3611 | sinfo->rx_bytes)) |
| 3612 | goto nla_put_failure; |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 3613 | if ((sinfo->filled & STATION_INFO_TX_BYTES64) && |
| 3614 | nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3615 | sinfo->tx_bytes)) |
| 3616 | goto nla_put_failure; |
| 3617 | if ((sinfo->filled & STATION_INFO_LLID) && |
| 3618 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) |
| 3619 | goto nla_put_failure; |
| 3620 | if ((sinfo->filled & STATION_INFO_PLID) && |
| 3621 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) |
| 3622 | goto nla_put_failure; |
| 3623 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && |
| 3624 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 3625 | sinfo->plink_state)) |
| 3626 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3627 | switch (rdev->wiphy.signal_type) { |
| 3628 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3629 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
| 3630 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, |
| 3631 | sinfo->signal)) |
| 3632 | goto nla_put_failure; |
| 3633 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && |
| 3634 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, |
| 3635 | sinfo->signal_avg)) |
| 3636 | goto nla_put_failure; |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 3637 | break; |
| 3638 | default: |
| 3639 | break; |
| 3640 | } |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 3641 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) { |
| 3642 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3643 | sinfo->chain_signal, |
| 3644 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 3645 | goto nla_put_failure; |
| 3646 | } |
| 3647 | if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) { |
| 3648 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 3649 | sinfo->chain_signal_avg, |
| 3650 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 3651 | goto nla_put_failure; |
| 3652 | } |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3653 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3654 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 3655 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3656 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 3657 | } |
| 3658 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { |
| 3659 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 3660 | NL80211_STA_INFO_RX_BITRATE)) |
| 3661 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 3662 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3663 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
| 3664 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 3665 | sinfo->rx_packets)) |
| 3666 | goto nla_put_failure; |
| 3667 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && |
| 3668 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 3669 | sinfo->tx_packets)) |
| 3670 | goto nla_put_failure; |
| 3671 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && |
| 3672 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, |
| 3673 | sinfo->tx_retries)) |
| 3674 | goto nla_put_failure; |
| 3675 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && |
| 3676 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, |
| 3677 | sinfo->tx_failed)) |
| 3678 | goto nla_put_failure; |
Antonio Quartulli | 867d849 | 2014-05-19 21:53:19 +0200 | [diff] [blame] | 3679 | if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) && |
| 3680 | nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT, |
| 3681 | sinfo->expected_throughput)) |
| 3682 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3683 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && |
| 3684 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, |
| 3685 | sinfo->beacon_loss_count)) |
| 3686 | goto nla_put_failure; |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 3687 | if ((sinfo->filled & STATION_INFO_LOCAL_PM) && |
| 3688 | nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM, |
| 3689 | sinfo->local_pm)) |
| 3690 | goto nla_put_failure; |
| 3691 | if ((sinfo->filled & STATION_INFO_PEER_PM) && |
| 3692 | nla_put_u32(msg, NL80211_STA_INFO_PEER_PM, |
| 3693 | sinfo->peer_pm)) |
| 3694 | goto nla_put_failure; |
| 3695 | if ((sinfo->filled & STATION_INFO_NONPEER_PM) && |
| 3696 | nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM, |
| 3697 | sinfo->nonpeer_pm)) |
| 3698 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3699 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
| 3700 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
| 3701 | if (!bss_param) |
| 3702 | goto nla_put_failure; |
| 3703 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3704 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 3705 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 3706 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 3707 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 3708 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 3709 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 3710 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 3711 | sinfo->bss_param.dtim_period) || |
| 3712 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 3713 | sinfo->bss_param.beacon_interval)) |
| 3714 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 3715 | |
| 3716 | nla_nest_end(msg, bss_param); |
| 3717 | } |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3718 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
| 3719 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 3720 | sizeof(struct nl80211_sta_flag_update), |
| 3721 | &sinfo->sta_flags)) |
| 3722 | goto nla_put_failure; |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 3723 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
| 3724 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, |
| 3725 | sinfo->t_offset)) |
| 3726 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3727 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3728 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3729 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
| 3730 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 3731 | sinfo->assoc_req_ies)) |
| 3732 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 3733 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3734 | return genlmsg_end(msg, hdr); |
| 3735 | |
| 3736 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3737 | genlmsg_cancel(msg, hdr); |
| 3738 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3739 | } |
| 3740 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3741 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3742 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3743 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3744 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3745 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3746 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3747 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3748 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3749 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3750 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3751 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 3752 | if (err) |
| 3753 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3754 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3755 | if (!wdev->netdev) { |
| 3756 | err = -EINVAL; |
| 3757 | goto out_err; |
| 3758 | } |
| 3759 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3760 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3761 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3762 | goto out_err; |
| 3763 | } |
| 3764 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3765 | while (1) { |
Jouni Malinen | f612ced | 2011-08-11 11:46:22 +0300 | [diff] [blame] | 3766 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3767 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3768 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3769 | if (err == -ENOENT) |
| 3770 | break; |
| 3771 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3772 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3773 | |
| 3774 | if (nl80211_send_station(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3775 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3776 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3777 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3778 | &sinfo) < 0) |
| 3779 | goto out; |
| 3780 | |
| 3781 | sta_idx++; |
| 3782 | } |
| 3783 | |
| 3784 | |
| 3785 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 3786 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3787 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3788 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3789 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3790 | |
| 3791 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3792 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3793 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3794 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 3795 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3796 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3797 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3798 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3799 | struct sk_buff *msg; |
| 3800 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3801 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3802 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3803 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3804 | |
| 3805 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3806 | return -EINVAL; |
| 3807 | |
| 3808 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3809 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3810 | if (!rdev->ops->get_station) |
| 3811 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3812 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3813 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3814 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3815 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3816 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3817 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3818 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3819 | return -ENOMEM; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3820 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3821 | 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] | 3822 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3823 | nlmsg_free(msg); |
| 3824 | return -ENOBUFS; |
| 3825 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 3826 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3827 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3828 | } |
| 3829 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3830 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 3831 | struct station_parameters *params, |
| 3832 | enum cfg80211_station_type statype) |
| 3833 | { |
| 3834 | if (params->listen_interval != -1) |
| 3835 | return -EINVAL; |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 3836 | if (params->aid && |
| 3837 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3838 | return -EINVAL; |
| 3839 | |
| 3840 | /* When you run into this, adjust the code below for the new flag */ |
| 3841 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 3842 | |
| 3843 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3844 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 3845 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3846 | /* |
| 3847 | * No ignoring the TDLS flag here -- the userspace mesh |
| 3848 | * code doesn't have the bug of including TDLS in the |
| 3849 | * mask everywhere. |
| 3850 | */ |
| 3851 | if (params->sta_flags_mask & |
| 3852 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3853 | BIT(NL80211_STA_FLAG_MFP) | |
| 3854 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3855 | return -EINVAL; |
| 3856 | break; |
| 3857 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3858 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3859 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 3860 | return -EINVAL; |
| 3861 | /* ignore since it can't change */ |
| 3862 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3863 | break; |
| 3864 | default: |
| 3865 | /* disallow mesh-specific things */ |
| 3866 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3867 | return -EINVAL; |
| 3868 | if (params->local_pm) |
| 3869 | return -EINVAL; |
| 3870 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3871 | return -EINVAL; |
| 3872 | } |
| 3873 | |
| 3874 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 3875 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 3876 | /* TDLS can't be set, ... */ |
| 3877 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 3878 | return -EINVAL; |
| 3879 | /* |
| 3880 | * ... but don't bother the driver with it. This works around |
| 3881 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 3882 | * TLDS_PEER flag in the mask even for AP mode. |
| 3883 | */ |
| 3884 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 3885 | } |
| 3886 | |
| 3887 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { |
| 3888 | /* reject other things that can't change */ |
| 3889 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 3890 | return -EINVAL; |
| 3891 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 3892 | return -EINVAL; |
| 3893 | if (params->supported_rates) |
| 3894 | return -EINVAL; |
| 3895 | if (params->ext_capab || params->ht_capa || params->vht_capa) |
| 3896 | return -EINVAL; |
| 3897 | } |
| 3898 | |
| 3899 | if (statype != CFG80211_STA_AP_CLIENT) { |
| 3900 | if (params->vlan) |
| 3901 | return -EINVAL; |
| 3902 | } |
| 3903 | |
| 3904 | switch (statype) { |
| 3905 | case CFG80211_STA_AP_MLME_CLIENT: |
| 3906 | /* Use this only for authorizing/unauthorizing a station */ |
| 3907 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 3908 | return -EOPNOTSUPP; |
| 3909 | break; |
| 3910 | case CFG80211_STA_AP_CLIENT: |
| 3911 | /* accept only the listed bits */ |
| 3912 | if (params->sta_flags_mask & |
| 3913 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3914 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3915 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 3916 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 3917 | BIT(NL80211_STA_FLAG_WME) | |
| 3918 | BIT(NL80211_STA_FLAG_MFP))) |
| 3919 | return -EINVAL; |
| 3920 | |
| 3921 | /* but authenticated/associated only if driver handles it */ |
| 3922 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 3923 | params->sta_flags_mask & |
| 3924 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 3925 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 3926 | return -EINVAL; |
| 3927 | break; |
| 3928 | case CFG80211_STA_IBSS: |
| 3929 | case CFG80211_STA_AP_STA: |
| 3930 | /* reject any changes other than AUTHORIZED */ |
| 3931 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 3932 | return -EINVAL; |
| 3933 | break; |
| 3934 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 3935 | /* reject any changes other than AUTHORIZED or WME */ |
| 3936 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 3937 | BIT(NL80211_STA_FLAG_WME))) |
| 3938 | return -EINVAL; |
| 3939 | /* force (at least) rates when authorizing */ |
| 3940 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 3941 | !params->supported_rates) |
| 3942 | return -EINVAL; |
| 3943 | break; |
| 3944 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 3945 | /* reject any changes */ |
| 3946 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3947 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3948 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 3949 | return -EINVAL; |
| 3950 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 3951 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3952 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 3953 | return -EINVAL; |
| 3954 | break; |
| 3955 | } |
| 3956 | |
| 3957 | return 0; |
| 3958 | } |
| 3959 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 3960 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3961 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 3962 | * 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] | 3963 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3964 | static struct net_device *get_vlan(struct genl_info *info, |
| 3965 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3966 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3967 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3968 | struct net_device *v; |
| 3969 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3970 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3971 | if (!vlanattr) |
| 3972 | return NULL; |
| 3973 | |
| 3974 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 3975 | if (!v) |
| 3976 | return ERR_PTR(-ENODEV); |
| 3977 | |
| 3978 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 3979 | ret = -EINVAL; |
| 3980 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3981 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3982 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 3983 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 3984 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 3985 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3986 | ret = -EINVAL; |
| 3987 | goto error; |
| 3988 | } |
| 3989 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 3990 | if (!netif_running(v)) { |
| 3991 | ret = -ENETDOWN; |
| 3992 | goto error; |
| 3993 | } |
| 3994 | |
| 3995 | return v; |
| 3996 | error: |
| 3997 | dev_put(v); |
| 3998 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3999 | } |
| 4000 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 4001 | static const struct nla_policy |
| 4002 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4003 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 4004 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 4005 | }; |
| 4006 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4007 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 4008 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4009 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4010 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 4011 | struct nlattr *nla; |
| 4012 | int err; |
| 4013 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4014 | /* parse WME attributes if present */ |
| 4015 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 4016 | return 0; |
| 4017 | |
| 4018 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
| 4019 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, |
| 4020 | nl80211_sta_wme_policy); |
| 4021 | if (err) |
| 4022 | return err; |
| 4023 | |
| 4024 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 4025 | params->uapsd_queues = nla_get_u8( |
| 4026 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 4027 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 4028 | return -EINVAL; |
| 4029 | |
| 4030 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 4031 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 4032 | |
| 4033 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 4034 | return -EINVAL; |
| 4035 | |
| 4036 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 4037 | |
| 4038 | return 0; |
| 4039 | } |
| 4040 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4041 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 4042 | struct station_parameters *params) |
| 4043 | { |
| 4044 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 4045 | params->supported_channels = |
| 4046 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4047 | params->supported_channels_len = |
| 4048 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 4049 | /* |
| 4050 | * Need to include at least one (first channel, number of |
| 4051 | * channels) tuple for each subband, and must have proper |
| 4052 | * tuples for the rest of the data as well. |
| 4053 | */ |
| 4054 | if (params->supported_channels_len < 2) |
| 4055 | return -EINVAL; |
| 4056 | if (params->supported_channels_len % 2) |
| 4057 | return -EINVAL; |
| 4058 | } |
| 4059 | |
| 4060 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 4061 | params->supported_oper_classes = |
| 4062 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4063 | params->supported_oper_classes_len = |
| 4064 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 4065 | /* |
| 4066 | * The value of the Length field of the Supported Operating |
| 4067 | * Classes element is between 2 and 253. |
| 4068 | */ |
| 4069 | if (params->supported_oper_classes_len < 2 || |
| 4070 | params->supported_oper_classes_len > 253) |
| 4071 | return -EINVAL; |
| 4072 | } |
| 4073 | return 0; |
| 4074 | } |
| 4075 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4076 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 4077 | struct station_parameters *params) |
| 4078 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4079 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4080 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4081 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 4082 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4083 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4084 | params->ht_capa = |
| 4085 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 4086 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4087 | params->vht_capa = |
| 4088 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4089 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4090 | err = nl80211_parse_sta_channel_info(info, params); |
| 4091 | if (err) |
| 4092 | return err; |
| 4093 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4094 | return nl80211_parse_sta_wme(info, params); |
| 4095 | } |
| 4096 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4097 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 4098 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4099 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4100 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4101 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4102 | u8 *mac_addr; |
| 4103 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4104 | |
| 4105 | memset(¶ms, 0, sizeof(params)); |
| 4106 | |
| 4107 | params.listen_interval = -1; |
| 4108 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4109 | if (!rdev->ops->change_station) |
| 4110 | return -EOPNOTSUPP; |
| 4111 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4112 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 4113 | return -EINVAL; |
| 4114 | |
| 4115 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4116 | return -EINVAL; |
| 4117 | |
| 4118 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4119 | |
| 4120 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 4121 | params.supported_rates = |
| 4122 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4123 | params.supported_rates_len = |
| 4124 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4125 | } |
| 4126 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4127 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4128 | params.capability = |
| 4129 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4130 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4131 | } |
| 4132 | |
| 4133 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4134 | params.ext_capab = |
| 4135 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4136 | params.ext_capab_len = |
| 4137 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4138 | } |
| 4139 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 4140 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 4141 | return -EINVAL; |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4142 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4143 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4144 | return -EINVAL; |
| 4145 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4146 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4147 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4148 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4149 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4150 | return -EINVAL; |
| 4151 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4152 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4153 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4154 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4155 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
| 4156 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) |
| 4157 | return -EINVAL; |
| 4158 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 4159 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 4160 | |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4161 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
| 4162 | enum nl80211_mesh_power_mode pm = nla_get_u32( |
| 4163 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 4164 | |
| 4165 | if (pm <= NL80211_MESH_POWER_UNKNOWN || |
| 4166 | pm > NL80211_MESH_POWER_MAX) |
| 4167 | return -EINVAL; |
| 4168 | |
| 4169 | params.local_pm = pm; |
| 4170 | } |
| 4171 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4172 | /* Include parameters for TDLS peer (will check later) */ |
| 4173 | err = nl80211_set_station_tdls(info, ¶ms); |
| 4174 | if (err) |
| 4175 | return err; |
| 4176 | |
| 4177 | params.vlan = get_vlan(info, rdev); |
| 4178 | if (IS_ERR(params.vlan)) |
| 4179 | return PTR_ERR(params.vlan); |
| 4180 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4181 | switch (dev->ieee80211_ptr->iftype) { |
| 4182 | case NL80211_IFTYPE_AP: |
| 4183 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4184 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4185 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4186 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 4187 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4188 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 4189 | break; |
| 4190 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4191 | err = -EOPNOTSUPP; |
| 4192 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 4193 | } |
| 4194 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4195 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4196 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4197 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4198 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4199 | if (params.vlan) |
| 4200 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4201 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4202 | return err; |
| 4203 | } |
| 4204 | |
| 4205 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 4206 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4207 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4208 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4209 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4210 | struct station_parameters params; |
| 4211 | u8 *mac_addr = NULL; |
| 4212 | |
| 4213 | memset(¶ms, 0, sizeof(params)); |
| 4214 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4215 | if (!rdev->ops->add_station) |
| 4216 | return -EOPNOTSUPP; |
| 4217 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4218 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4219 | return -EINVAL; |
| 4220 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4221 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 4222 | return -EINVAL; |
| 4223 | |
| 4224 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 4225 | return -EINVAL; |
| 4226 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4227 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 4228 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 4229 | return -EINVAL; |
| 4230 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4231 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4232 | params.supported_rates = |
| 4233 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4234 | params.supported_rates_len = |
| 4235 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 4236 | params.listen_interval = |
| 4237 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4238 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4239 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 4240 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4241 | else |
| 4242 | 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] | 4243 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 4244 | return -EINVAL; |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 4245 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 4246 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 4247 | params.capability = |
| 4248 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 4249 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 4250 | } |
| 4251 | |
| 4252 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 4253 | params.ext_capab = |
| 4254 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4255 | params.ext_capab_len = |
| 4256 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 4257 | } |
| 4258 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 4259 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 4260 | params.ht_capa = |
| 4261 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4262 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 4263 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 4264 | params.vht_capa = |
| 4265 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 4266 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 4267 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 4268 | params.opmode_notif_used = true; |
| 4269 | params.opmode_notif = |
| 4270 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 4271 | } |
| 4272 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4273 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4274 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 4275 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 4276 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) |
| 4277 | return -EINVAL; |
| 4278 | } |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 4279 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 4280 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 4281 | if (err) |
| 4282 | return err; |
| 4283 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 4284 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 4285 | if (err) |
| 4286 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4287 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 4288 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4289 | return -EINVAL; |
| 4290 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4291 | /* When you run into this, adjust the code below for the new flag */ |
| 4292 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 4293 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4294 | switch (dev->ieee80211_ptr->iftype) { |
| 4295 | case NL80211_IFTYPE_AP: |
| 4296 | case NL80211_IFTYPE_AP_VLAN: |
| 4297 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4298 | /* ignore WME attributes if iface/sta is not capable */ |
| 4299 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 4300 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 4301 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4302 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4303 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4304 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4305 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4306 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4307 | /* but don't bother the driver with it */ |
| 4308 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4309 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4310 | /* allow authenticated/associated only if driver handles it */ |
| 4311 | if (!(rdev->wiphy.features & |
| 4312 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 4313 | params.sta_flags_mask & |
| 4314 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 4315 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 4316 | return -EINVAL; |
| 4317 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4318 | /* must be last in here for error handling */ |
| 4319 | params.vlan = get_vlan(info, rdev); |
| 4320 | if (IS_ERR(params.vlan)) |
| 4321 | return PTR_ERR(params.vlan); |
| 4322 | break; |
| 4323 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4324 | /* ignore uAPSD data */ |
| 4325 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4326 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4327 | /* associated is disallowed */ |
| 4328 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 4329 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4330 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 4331 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 4332 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 4333 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4334 | break; |
| 4335 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 4336 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 4337 | /* ignore uAPSD data */ |
| 4338 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 4339 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4340 | /* these are disallowed */ |
| 4341 | if (params.sta_flags_mask & |
| 4342 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4343 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 4344 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4345 | /* Only TDLS peers can be added */ |
| 4346 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 4347 | return -EINVAL; |
| 4348 | /* Can only add if TDLS ... */ |
| 4349 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 4350 | return -EOPNOTSUPP; |
| 4351 | /* ... with external setup is supported */ |
| 4352 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 4353 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 4354 | /* |
| 4355 | * Older wpa_supplicant versions always mark the TDLS peer |
| 4356 | * as authorized, but it shouldn't yet be. |
| 4357 | */ |
| 4358 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4359 | break; |
| 4360 | default: |
| 4361 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 4362 | } |
| 4363 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 4364 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4365 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4366 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4367 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4368 | if (params.vlan) |
| 4369 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4370 | return err; |
| 4371 | } |
| 4372 | |
| 4373 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 4374 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4375 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4376 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4377 | u8 *mac_addr = NULL; |
| 4378 | |
| 4379 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4380 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4381 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4382 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Marco Porsch | d5d9de0 | 2010-03-30 10:00:16 +0200 | [diff] [blame] | 4383 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4384 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4385 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4386 | return -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 4387 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4388 | if (!rdev->ops->del_station) |
| 4389 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4390 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4391 | return rdev_del_station(rdev, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4392 | } |
| 4393 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4394 | 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] | 4395 | int flags, struct net_device *dev, |
| 4396 | u8 *dst, u8 *next_hop, |
| 4397 | struct mpath_info *pinfo) |
| 4398 | { |
| 4399 | void *hdr; |
| 4400 | struct nlattr *pinfoattr; |
| 4401 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4402 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4403 | if (!hdr) |
| 4404 | return -1; |
| 4405 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4406 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4407 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 4408 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 4409 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 4410 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 4411 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4412 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 4413 | if (!pinfoattr) |
| 4414 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4415 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 4416 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 4417 | pinfo->frame_qlen)) |
| 4418 | goto nla_put_failure; |
| 4419 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 4420 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 4421 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 4422 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 4423 | pinfo->metric)) || |
| 4424 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 4425 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 4426 | pinfo->exptime)) || |
| 4427 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 4428 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 4429 | pinfo->flags)) || |
| 4430 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 4431 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 4432 | pinfo->discovery_timeout)) || |
| 4433 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 4434 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 4435 | pinfo->discovery_retries))) |
| 4436 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4437 | |
| 4438 | nla_nest_end(msg, pinfoattr); |
| 4439 | |
| 4440 | return genlmsg_end(msg, hdr); |
| 4441 | |
| 4442 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 4443 | genlmsg_cancel(msg, hdr); |
| 4444 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4445 | } |
| 4446 | |
| 4447 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4448 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4449 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4450 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4451 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4452 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4453 | u8 dst[ETH_ALEN]; |
| 4454 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4455 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4456 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4457 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4458 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 4459 | if (err) |
| 4460 | return err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4461 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4462 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4463 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4464 | goto out_err; |
| 4465 | } |
| 4466 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4467 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4468 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 4469 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4470 | } |
| 4471 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4472 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4473 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4474 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4475 | if (err == -ENOENT) |
| 4476 | break; |
| 4477 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4478 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4479 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4480 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4481 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4482 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4483 | &pinfo) < 0) |
| 4484 | goto out; |
| 4485 | |
| 4486 | path_idx++; |
| 4487 | } |
| 4488 | |
| 4489 | |
| 4490 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 4491 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4492 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4493 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 4494 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 4495 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4496 | } |
| 4497 | |
| 4498 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4499 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4500 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4501 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4502 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4503 | struct mpath_info pinfo; |
| 4504 | struct sk_buff *msg; |
| 4505 | u8 *dst = NULL; |
| 4506 | u8 next_hop[ETH_ALEN]; |
| 4507 | |
| 4508 | memset(&pinfo, 0, sizeof(pinfo)); |
| 4509 | |
| 4510 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4511 | return -EINVAL; |
| 4512 | |
| 4513 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4514 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4515 | if (!rdev->ops->get_mpath) |
| 4516 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4517 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4518 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4519 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4520 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4521 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4522 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4523 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4524 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4525 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4526 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4527 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4528 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4529 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4530 | dev, dst, next_hop, &pinfo) < 0) { |
| 4531 | nlmsg_free(msg); |
| 4532 | return -ENOBUFS; |
| 4533 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4534 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4535 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4536 | } |
| 4537 | |
| 4538 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4539 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4540 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4541 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4542 | u8 *dst = NULL; |
| 4543 | u8 *next_hop = NULL; |
| 4544 | |
| 4545 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4546 | return -EINVAL; |
| 4547 | |
| 4548 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4549 | return -EINVAL; |
| 4550 | |
| 4551 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4552 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4553 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4554 | if (!rdev->ops->change_mpath) |
| 4555 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4556 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4557 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4558 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4559 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4560 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4561 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4562 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4563 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4564 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4565 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4566 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4567 | u8 *dst = NULL; |
| 4568 | u8 *next_hop = NULL; |
| 4569 | |
| 4570 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 4571 | return -EINVAL; |
| 4572 | |
| 4573 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 4574 | return -EINVAL; |
| 4575 | |
| 4576 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4577 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 4578 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4579 | if (!rdev->ops->add_mpath) |
| 4580 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4581 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4582 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4583 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4584 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4585 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4586 | } |
| 4587 | |
| 4588 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 4589 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4590 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4591 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4592 | u8 *dst = NULL; |
| 4593 | |
| 4594 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4595 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4596 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4597 | if (!rdev->ops->del_mpath) |
| 4598 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4599 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4600 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4601 | } |
| 4602 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4603 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 4604 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4605 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4606 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4607 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4608 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4609 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4610 | |
| 4611 | memset(¶ms, 0, sizeof(params)); |
| 4612 | /* default to not changing parameters */ |
| 4613 | params.use_cts_prot = -1; |
| 4614 | params.use_short_preamble = -1; |
| 4615 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4616 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4617 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4618 | params.p2p_ctwindow = -1; |
| 4619 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4620 | |
| 4621 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 4622 | params.use_cts_prot = |
| 4623 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 4624 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 4625 | params.use_short_preamble = |
| 4626 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 4627 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 4628 | params.use_short_slot_time = |
| 4629 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 4630 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 4631 | params.basic_rates = |
| 4632 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4633 | params.basic_rates_len = |
| 4634 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 4635 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 4636 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 4637 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 4638 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 4639 | params.ht_opmode = |
| 4640 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4641 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4642 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4643 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4644 | return -EINVAL; |
| 4645 | params.p2p_ctwindow = |
| 4646 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
| 4647 | if (params.p2p_ctwindow < 0) |
| 4648 | return -EINVAL; |
| 4649 | if (params.p2p_ctwindow != 0 && |
| 4650 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4651 | return -EINVAL; |
| 4652 | } |
| 4653 | |
| 4654 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4655 | u8 tmp; |
| 4656 | |
| 4657 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4658 | return -EINVAL; |
| 4659 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
| 4660 | if (tmp > 1) |
| 4661 | return -EINVAL; |
| 4662 | params.p2p_opp_ps = tmp; |
| 4663 | if (params.p2p_opp_ps && |
| 4664 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4665 | return -EINVAL; |
| 4666 | } |
| 4667 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4668 | if (!rdev->ops->change_bss) |
| 4669 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4670 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 4671 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4672 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4673 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 4674 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 4675 | wdev_lock(wdev); |
| 4676 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 4677 | wdev_unlock(wdev); |
| 4678 | |
| 4679 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4680 | } |
| 4681 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4682 | 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] | 4683 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 4684 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 4685 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 4686 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 4687 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 4688 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4689 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4690 | }; |
| 4691 | |
| 4692 | static int parse_reg_rule(struct nlattr *tb[], |
| 4693 | struct ieee80211_reg_rule *reg_rule) |
| 4694 | { |
| 4695 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 4696 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 4697 | |
| 4698 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 4699 | return -EINVAL; |
| 4700 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 4701 | return -EINVAL; |
| 4702 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 4703 | return -EINVAL; |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4704 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 4705 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4706 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 4707 | return -EINVAL; |
| 4708 | |
| 4709 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 4710 | |
| 4711 | freq_range->start_freq_khz = |
| 4712 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 4713 | freq_range->end_freq_khz = |
| 4714 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
Janusz Dziedzic | b0dfd2e | 2014-02-20 13:52:16 +0100 | [diff] [blame] | 4715 | freq_range->max_bandwidth_khz = |
| 4716 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4717 | |
| 4718 | power_rule->max_eirp = |
| 4719 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 4720 | |
| 4721 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 4722 | power_rule->max_antenna_gain = |
| 4723 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 4724 | |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 4725 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 4726 | reg_rule->dfs_cac_ms = |
| 4727 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 4728 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4729 | return 0; |
| 4730 | } |
| 4731 | |
| 4732 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 4733 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4734 | char *data = NULL; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4735 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4736 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4737 | /* |
| 4738 | * You should only get this when cfg80211 hasn't yet initialized |
| 4739 | * completely when built-in to the kernel right between the time |
| 4740 | * window between nl80211_init() and regulatory_init(), if that is |
| 4741 | * even possible. |
| 4742 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 4743 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 4744 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 4745 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4746 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 4747 | user_reg_hint_type = |
| 4748 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 4749 | else |
| 4750 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 4751 | |
| 4752 | switch (user_reg_hint_type) { |
| 4753 | case NL80211_USER_REG_HINT_USER: |
| 4754 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 4755 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 4756 | return -EINVAL; |
| 4757 | |
| 4758 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 4759 | return regulatory_hint_user(data, user_reg_hint_type); |
| 4760 | case NL80211_USER_REG_HINT_INDOOR: |
| 4761 | return regulatory_hint_indoor_user(); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 4762 | default: |
| 4763 | return -EINVAL; |
| 4764 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4765 | } |
| 4766 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4767 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4768 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4769 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4770 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4771 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4772 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4773 | struct mesh_config cur_params; |
| 4774 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4775 | void *hdr; |
| 4776 | struct nlattr *pinfoattr; |
| 4777 | struct sk_buff *msg; |
| 4778 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4779 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 4780 | return -EOPNOTSUPP; |
| 4781 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4782 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4783 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 4784 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4785 | wdev_lock(wdev); |
| 4786 | /* If not connected, get default parameters */ |
| 4787 | if (!wdev->mesh_id_len) |
| 4788 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 4789 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4790 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4791 | wdev_unlock(wdev); |
| 4792 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4793 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4794 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4795 | |
| 4796 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4797 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4798 | if (!msg) |
| 4799 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4800 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4801 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4802 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4803 | goto out; |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4804 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4805 | if (!pinfoattr) |
| 4806 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4807 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4808 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4809 | cur_params.dot11MeshRetryTimeout) || |
| 4810 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4811 | cur_params.dot11MeshConfirmTimeout) || |
| 4812 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4813 | cur_params.dot11MeshHoldingTimeout) || |
| 4814 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4815 | cur_params.dot11MeshMaxPeerLinks) || |
| 4816 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 4817 | cur_params.dot11MeshMaxRetries) || |
| 4818 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 4819 | cur_params.dot11MeshTTL) || |
| 4820 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 4821 | cur_params.element_ttl) || |
| 4822 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4823 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 4824 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4825 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4826 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4827 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 4828 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4829 | cur_params.path_refresh_time) || |
| 4830 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4831 | cur_params.min_discovery_timeout) || |
| 4832 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4833 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 4834 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 4835 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 4836 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 4837 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 4838 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 4839 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 4840 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 4841 | cur_params.dot11MeshHWMPRootMode) || |
| 4842 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 4843 | cur_params.dot11MeshHWMPRannInterval) || |
| 4844 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 4845 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 4846 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 4847 | cur_params.dot11MeshForwarding) || |
| 4848 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 4849 | cur_params.rssi_threshold) || |
| 4850 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4851 | cur_params.ht_opmode) || |
| 4852 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 4853 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 4854 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4855 | cur_params.dot11MeshHWMProotInterval) || |
| 4856 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4857 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 4858 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 4859 | cur_params.power_mode) || |
| 4860 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4861 | cur_params.dot11MeshAwakeWindowDuration) || |
| 4862 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 4863 | cur_params.plink_timeout)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4864 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4865 | nla_nest_end(msg, pinfoattr); |
| 4866 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4867 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4868 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4869 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4870 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 4871 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 4872 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4873 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4874 | } |
| 4875 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 4876 | 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] | 4877 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 4878 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 4879 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 4880 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 4881 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 4882 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 4883 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4884 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4885 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4886 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 4887 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 4888 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 4889 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 4890 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4891 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4892 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 4893 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 4894 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 4895 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 4896 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4897 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
| 4898 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 4899 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
| 4900 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 4901 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 4902 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
| 4903 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 4904 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4905 | }; |
| 4906 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4907 | static const struct nla_policy |
| 4908 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 4909 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4910 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 4911 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 4912 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 4913 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 4914 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 4915 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4916 | .len = IEEE80211_MAX_DATA_LEN }, |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 4917 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 4918 | }; |
| 4919 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4920 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4921 | struct mesh_config *cfg, |
| 4922 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4923 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4924 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4925 | u32 mask = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4926 | |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4927 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
| 4928 | do { \ |
| 4929 | if (tb[attr]) { \ |
| 4930 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ |
| 4931 | return -EINVAL; \ |
| 4932 | cfg->param = fn(tb[attr]); \ |
| 4933 | mask |= (1 << (attr - 1)); \ |
| 4934 | } \ |
| 4935 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4936 | |
| 4937 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4938 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4939 | return -EINVAL; |
| 4940 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 4941 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 4942 | nl80211_meshconf_params_policy)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4943 | return -EINVAL; |
| 4944 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4945 | /* This makes sure that there aren't more than 32 mesh config |
| 4946 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 4947 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 4948 | |
| 4949 | /* Fill in the params struct */ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4950 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4951 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 4952 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4953 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4954 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 4955 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4956 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4957 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 4958 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4959 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4960 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 4961 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4962 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4963 | mask, NL80211_MESHCONF_MAX_RETRIES, |
| 4964 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4965 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4966 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4967 | 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] | 4968 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
| 4969 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4970 | 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] | 4971 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 4972 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4973 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
| 4974 | 1, 255, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4975 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 4976 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4977 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4978 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 4979 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4980 | 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] | 4981 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 4982 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4983 | 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] | 4984 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 4985 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4986 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 4987 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4988 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 4989 | nla_get_u32); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4990 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4991 | 1, 65535, mask, |
| 4992 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4993 | nla_get_u16); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 4994 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4995 | 1, 65535, mask, |
| 4996 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 4997 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4998 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 4999 | dot11MeshHWMPnetDiameterTraversalTime, |
| 5000 | 1, 65535, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5001 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 5002 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5003 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
| 5004 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 5005 | nla_get_u8); |
| 5006 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
| 5007 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5008 | nla_get_u16); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 5009 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5010 | dot11MeshGateAnnouncementProtocol, 0, 1, |
| 5011 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5012 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5013 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 5014 | mask, NL80211_MESHCONF_FORWARDING, |
| 5015 | nla_get_u8); |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5016 | 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] | 5017 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
Chun-Yeow Yeoh | 83374fe | 2013-07-11 18:24:03 +0800 | [diff] [blame] | 5018 | nla_get_s32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5019 | 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] | 5020 | mask, NL80211_MESHCONF_HT_OPMODE, |
| 5021 | nla_get_u16); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5022 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5023 | 1, 65535, mask, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5024 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 5025 | nla_get_u32); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5026 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 5027 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 5028 | nla_get_u16); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5029 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 5030 | dot11MeshHWMPconfirmationInterval, |
| 5031 | 1, 65535, mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 5032 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
| 5033 | nla_get_u16); |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 5034 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
| 5035 | NL80211_MESH_POWER_ACTIVE, |
| 5036 | NL80211_MESH_POWER_MAX, |
| 5037 | mask, NL80211_MESHCONF_POWER_MODE, |
| 5038 | nla_get_u32); |
| 5039 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
| 5040 | 0, 65535, mask, |
| 5041 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 5042 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff, |
| 5043 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 5044 | nla_get_u32); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5045 | if (mask_out) |
| 5046 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5047 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5048 | return 0; |
| 5049 | |
| 5050 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 5051 | } |
| 5052 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5053 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 5054 | struct mesh_setup *setup) |
| 5055 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5056 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5057 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 5058 | |
| 5059 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 5060 | return -EINVAL; |
| 5061 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, |
| 5062 | info->attrs[NL80211_ATTR_MESH_SETUP], |
| 5063 | nl80211_mesh_setup_params_policy)) |
| 5064 | return -EINVAL; |
| 5065 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 5066 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 5067 | setup->sync_method = |
| 5068 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 5069 | IEEE80211_SYNC_METHOD_VENDOR : |
| 5070 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 5071 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5072 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 5073 | setup->path_sel_proto = |
| 5074 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 5075 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 5076 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 5077 | |
| 5078 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 5079 | setup->path_metric = |
| 5080 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 5081 | IEEE80211_PATH_METRIC_VENDOR : |
| 5082 | IEEE80211_PATH_METRIC_AIRTIME; |
| 5083 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5084 | |
| 5085 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5086 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5087 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5088 | if (!is_valid_ie_attr(ieattr)) |
| 5089 | return -EINVAL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 5090 | setup->ie = nla_data(ieattr); |
| 5091 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5092 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5093 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 5094 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 5095 | return -EINVAL; |
| 5096 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 5097 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 5098 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 5099 | if (setup->is_secure) |
| 5100 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5101 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 5102 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 5103 | if (!setup->user_mpm) |
| 5104 | return -EINVAL; |
| 5105 | setup->auth_id = |
| 5106 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 5107 | } |
| 5108 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 5109 | return 0; |
| 5110 | } |
| 5111 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5112 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5113 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5114 | { |
| 5115 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5116 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5117 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5118 | struct mesh_config cfg; |
| 5119 | u32 mask; |
| 5120 | int err; |
| 5121 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5122 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 5123 | return -EOPNOTSUPP; |
| 5124 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5125 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5126 | return -EOPNOTSUPP; |
| 5127 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 5128 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 5129 | if (err) |
| 5130 | return err; |
| 5131 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5132 | wdev_lock(wdev); |
| 5133 | if (!wdev->mesh_id_len) |
| 5134 | err = -ENOLINK; |
| 5135 | |
| 5136 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5137 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 5138 | |
| 5139 | wdev_unlock(wdev); |
| 5140 | |
| 5141 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 5142 | } |
| 5143 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5144 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 5145 | { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5146 | const struct ieee80211_regdomain *regdom; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5147 | struct sk_buff *msg; |
| 5148 | void *hdr = NULL; |
| 5149 | struct nlattr *nl_reg_rules; |
| 5150 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5151 | |
| 5152 | if (!cfg80211_regdomain) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5153 | return -EINVAL; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5154 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5155 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5156 | if (!msg) |
| 5157 | return -ENOBUFS; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5158 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5159 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5160 | NL80211_CMD_GET_REG); |
| 5161 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5162 | goto put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5163 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 5164 | if (reg_last_request_cell_base() && |
| 5165 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 5166 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 5167 | goto nla_put_failure; |
| 5168 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5169 | rcu_read_lock(); |
| 5170 | regdom = rcu_dereference(cfg80211_regdomain); |
| 5171 | |
| 5172 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 5173 | (regdom->dfs_region && |
| 5174 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
| 5175 | goto nla_put_failure_rcu; |
| 5176 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5177 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 5178 | if (!nl_reg_rules) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5179 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5180 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5181 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5182 | struct nlattr *nl_reg_rule; |
| 5183 | const struct ieee80211_reg_rule *reg_rule; |
| 5184 | const struct ieee80211_freq_range *freq_range; |
| 5185 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5186 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5187 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5188 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5189 | freq_range = ®_rule->freq_range; |
| 5190 | power_rule = ®_rule->power_rule; |
| 5191 | |
| 5192 | nl_reg_rule = nla_nest_start(msg, i); |
| 5193 | if (!nl_reg_rule) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5194 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5195 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5196 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 5197 | if (!max_bandwidth_khz) |
| 5198 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 5199 | reg_rule); |
| 5200 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5201 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 5202 | reg_rule->flags) || |
| 5203 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 5204 | freq_range->start_freq_khz) || |
| 5205 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 5206 | freq_range->end_freq_khz) || |
| 5207 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 5208 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5209 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 5210 | power_rule->max_antenna_gain) || |
| 5211 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 5212 | power_rule->max_eirp) || |
| 5213 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 5214 | reg_rule->dfs_cac_ms)) |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5215 | goto nla_put_failure_rcu; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5216 | |
| 5217 | nla_nest_end(msg, nl_reg_rule); |
| 5218 | } |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5219 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5220 | |
| 5221 | nla_nest_end(msg, nl_reg_rules); |
| 5222 | |
| 5223 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5224 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5225 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 5226 | nla_put_failure_rcu: |
| 5227 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5228 | nla_put_failure: |
| 5229 | genlmsg_cancel(msg, hdr); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 5230 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 5231 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5232 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 5233 | } |
| 5234 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5235 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 5236 | { |
| 5237 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 5238 | struct nlattr *nl_reg_rule; |
| 5239 | char *alpha2 = NULL; |
| 5240 | int rem_reg_rules = 0, r = 0; |
| 5241 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 5242 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5243 | struct ieee80211_regdomain *rd = NULL; |
| 5244 | |
| 5245 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 5246 | return -EINVAL; |
| 5247 | |
| 5248 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 5249 | return -EINVAL; |
| 5250 | |
| 5251 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 5252 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5253 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 5254 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 5255 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5256 | 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] | 5257 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5258 | num_rules++; |
| 5259 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 5260 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5261 | } |
| 5262 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 5263 | if (!reg_is_valid_request(alpha2)) |
| 5264 | return -EINVAL; |
| 5265 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5266 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5267 | num_rules * sizeof(struct ieee80211_reg_rule); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5268 | |
| 5269 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5270 | if (!rd) |
| 5271 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5272 | |
| 5273 | rd->n_reg_rules = num_rules; |
| 5274 | rd->alpha2[0] = alpha2[0]; |
| 5275 | rd->alpha2[1] = alpha2[1]; |
| 5276 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 5277 | /* |
| 5278 | * Disable DFS master mode if the DFS region was |
| 5279 | * not supported or known on this kernel. |
| 5280 | */ |
| 5281 | if (reg_supported_dfs_region(dfs_region)) |
| 5282 | rd->dfs_region = dfs_region; |
| 5283 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5284 | 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] | 5285 | rem_reg_rules) { |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5286 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 5287 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 5288 | reg_rule_policy); |
| 5289 | if (r) |
| 5290 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5291 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 5292 | if (r) |
| 5293 | goto bad_reg; |
| 5294 | |
| 5295 | rule_idx++; |
| 5296 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5297 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 5298 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5299 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5300 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5301 | } |
| 5302 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5303 | r = set_regdom(rd); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 5304 | /* set_regdom took ownership */ |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 5305 | rd = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5306 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 5307 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5308 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 5309 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5310 | } |
| 5311 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5312 | static int validate_scan_freqs(struct nlattr *freqs) |
| 5313 | { |
| 5314 | struct nlattr *attr1, *attr2; |
| 5315 | int n_channels = 0, tmp1, tmp2; |
| 5316 | |
| 5317 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 5318 | n_channels++; |
| 5319 | /* |
| 5320 | * Some hardware has a limited channel list for |
| 5321 | * scanning, and it is pretty much nonsensical |
| 5322 | * to scan for a channel twice, so disallow that |
| 5323 | * and don't require drivers to check that the |
| 5324 | * channel list they get isn't longer than what |
| 5325 | * they can scan, as long as they can scan all |
| 5326 | * the channels they registered at once. |
| 5327 | */ |
| 5328 | nla_for_each_nested(attr2, freqs, tmp2) |
| 5329 | if (attr1 != attr2 && |
| 5330 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 5331 | return 0; |
| 5332 | } |
| 5333 | |
| 5334 | return n_channels; |
| 5335 | } |
| 5336 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5337 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 5338 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5339 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5340 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5341 | struct cfg80211_scan_request *request; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5342 | struct nlattr *attr; |
| 5343 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5344 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5345 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5346 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 5347 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5348 | return -EINVAL; |
| 5349 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5350 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5351 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5352 | if (!rdev->ops->scan) |
| 5353 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5354 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 5355 | if (rdev->scan_req || rdev->scan_msg) { |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5356 | err = -EBUSY; |
| 5357 | goto unlock; |
| 5358 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5359 | |
| 5360 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 5361 | n_channels = validate_scan_freqs( |
| 5362 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5363 | if (!n_channels) { |
| 5364 | err = -EINVAL; |
| 5365 | goto unlock; |
| 5366 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5367 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5368 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5369 | } |
| 5370 | |
| 5371 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5372 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 5373 | n_ssids++; |
| 5374 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5375 | if (n_ssids > wiphy->max_scan_ssids) { |
| 5376 | err = -EINVAL; |
| 5377 | goto unlock; |
| 5378 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5379 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5380 | if (info->attrs[NL80211_ATTR_IE]) |
| 5381 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5382 | else |
| 5383 | ie_len = 0; |
| 5384 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5385 | if (ie_len > wiphy->max_scan_ie_len) { |
| 5386 | err = -EINVAL; |
| 5387 | goto unlock; |
| 5388 | } |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 5389 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5390 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5391 | + sizeof(*request->ssids) * n_ssids |
| 5392 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5393 | + ie_len, GFP_KERNEL); |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5394 | if (!request) { |
| 5395 | err = -ENOMEM; |
| 5396 | goto unlock; |
| 5397 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5398 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5399 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 5400 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5401 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5402 | if (ie_len) { |
| 5403 | if (request->ssids) |
| 5404 | request->ie = (void *)(request->ssids + n_ssids); |
| 5405 | else |
| 5406 | request->ie = (void *)(request->channels + n_channels); |
| 5407 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5408 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5409 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5410 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5411 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5412 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5413 | struct ieee80211_channel *chan; |
| 5414 | |
| 5415 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5416 | |
| 5417 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5418 | err = -EINVAL; |
| 5419 | goto out_free; |
| 5420 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5421 | |
| 5422 | /* ignore disabled channels */ |
| 5423 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5424 | continue; |
| 5425 | |
| 5426 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5427 | i++; |
| 5428 | } |
| 5429 | } else { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5430 | enum ieee80211_band band; |
| 5431 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5432 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5433 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5434 | int j; |
| 5435 | if (!wiphy->bands[band]) |
| 5436 | continue; |
| 5437 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5438 | struct ieee80211_channel *chan; |
| 5439 | |
| 5440 | chan = &wiphy->bands[band]->channels[j]; |
| 5441 | |
| 5442 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5443 | continue; |
| 5444 | |
| 5445 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5446 | i++; |
| 5447 | } |
| 5448 | } |
| 5449 | } |
| 5450 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 5451 | if (!i) { |
| 5452 | err = -EINVAL; |
| 5453 | goto out_free; |
| 5454 | } |
| 5455 | |
| 5456 | request->n_channels = i; |
| 5457 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5458 | i = 0; |
| 5459 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5460 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5461 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5462 | err = -EINVAL; |
| 5463 | goto out_free; |
| 5464 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5465 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5466 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5467 | i++; |
| 5468 | } |
| 5469 | } |
| 5470 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5471 | if (info->attrs[NL80211_ATTR_IE]) { |
| 5472 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 5473 | memcpy((void *)request->ie, |
| 5474 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 5475 | request->ie_len); |
| 5476 | } |
| 5477 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5478 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 5479 | if (wiphy->bands[i]) |
| 5480 | request->rates[i] = |
| 5481 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5482 | |
| 5483 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 5484 | nla_for_each_nested(attr, |
| 5485 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 5486 | tmp) { |
| 5487 | enum ieee80211_band band = nla_type(attr); |
| 5488 | |
Dan Carpenter | 8440462 | 2011-07-29 11:52:18 +0300 | [diff] [blame] | 5489 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5490 | err = -EINVAL; |
| 5491 | goto out_free; |
| 5492 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 5493 | |
| 5494 | if (!wiphy->bands[band]) |
| 5495 | continue; |
| 5496 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 5497 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 5498 | nla_data(attr), |
| 5499 | nla_len(attr), |
| 5500 | &request->rates[band]); |
| 5501 | if (err) |
| 5502 | goto out_free; |
| 5503 | } |
| 5504 | } |
| 5505 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5506 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5507 | request->flags = nla_get_u32( |
| 5508 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5509 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5510 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5511 | err = -EOPNOTSUPP; |
| 5512 | goto out_free; |
| 5513 | } |
| 5514 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5515 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 5516 | request->no_cck = |
| 5517 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 5518 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5519 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5520 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5521 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5522 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5523 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5524 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5525 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5526 | if (!err) { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 5527 | nl80211_send_scan_start(rdev, wdev); |
| 5528 | if (wdev->netdev) |
| 5529 | dev_hold(wdev->netdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5530 | } else { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5531 | out_free: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 5532 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5533 | kfree(request); |
| 5534 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5535 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 5536 | unlock: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5537 | return err; |
| 5538 | } |
| 5539 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5540 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 5541 | struct genl_info *info) |
| 5542 | { |
| 5543 | struct cfg80211_sched_scan_request *request; |
| 5544 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5545 | struct net_device *dev = info->user_ptr[1]; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5546 | struct nlattr *attr; |
| 5547 | struct wiphy *wiphy; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5548 | 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] | 5549 | u32 interval; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5550 | enum ieee80211_band band; |
| 5551 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5552 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5553 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5554 | |
| 5555 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5556 | !rdev->ops->sched_scan_start) |
| 5557 | return -EOPNOTSUPP; |
| 5558 | |
| 5559 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 5560 | return -EINVAL; |
| 5561 | |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5562 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 5563 | return -EINVAL; |
| 5564 | |
| 5565 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 5566 | if (interval == 0) |
| 5567 | return -EINVAL; |
| 5568 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5569 | wiphy = &rdev->wiphy; |
| 5570 | |
| 5571 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5572 | n_channels = validate_scan_freqs( |
| 5573 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
| 5574 | if (!n_channels) |
| 5575 | return -EINVAL; |
| 5576 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 5577 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5578 | } |
| 5579 | |
| 5580 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 5581 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5582 | tmp) |
| 5583 | n_ssids++; |
| 5584 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 5585 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5586 | return -EINVAL; |
| 5587 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5588 | /* |
| 5589 | * First, count the number of 'real' matchsets. Due to an issue with |
| 5590 | * the old implementation, matchsets containing only the RSSI attribute |
| 5591 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 5592 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 5593 | * all APs with a strong RSSI. This is needed to be compatible with |
| 5594 | * older userspace that treated a matchset with only the RSSI as the |
| 5595 | * global RSSI for all other matchsets - if there are other matchsets. |
| 5596 | */ |
| 5597 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5598 | nla_for_each_nested(attr, |
| 5599 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5600 | tmp) { |
| 5601 | struct nlattr *rssi; |
| 5602 | |
| 5603 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5604 | nla_data(attr), nla_len(attr), |
| 5605 | nl80211_match_policy); |
| 5606 | if (err) |
| 5607 | return err; |
| 5608 | /* add other standalone attributes here */ |
| 5609 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { |
| 5610 | n_match_sets++; |
| 5611 | continue; |
| 5612 | } |
| 5613 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5614 | if (rssi) |
| 5615 | default_match_rssi = nla_get_s32(rssi); |
| 5616 | } |
| 5617 | } |
| 5618 | |
| 5619 | /* However, if there's no other matchset, add the RSSI one */ |
| 5620 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 5621 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5622 | |
| 5623 | if (n_match_sets > wiphy->max_match_sets) |
| 5624 | return -EINVAL; |
| 5625 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5626 | if (info->attrs[NL80211_ATTR_IE]) |
| 5627 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 5628 | else |
| 5629 | ie_len = 0; |
| 5630 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 5631 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5632 | return -EINVAL; |
| 5633 | |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5634 | if (rdev->sched_scan_req) { |
| 5635 | err = -EINPROGRESS; |
| 5636 | goto out; |
| 5637 | } |
| 5638 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5639 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5640 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5641 | + sizeof(*request->match_sets) * n_match_sets |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 5642 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5643 | + ie_len, GFP_KERNEL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 5644 | if (!request) { |
| 5645 | err = -ENOMEM; |
| 5646 | goto out; |
| 5647 | } |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5648 | |
| 5649 | if (n_ssids) |
| 5650 | request->ssids = (void *)&request->channels[n_channels]; |
| 5651 | request->n_ssids = n_ssids; |
| 5652 | if (ie_len) { |
| 5653 | if (request->ssids) |
| 5654 | request->ie = (void *)(request->ssids + n_ssids); |
| 5655 | else |
| 5656 | request->ie = (void *)(request->channels + n_channels); |
| 5657 | } |
| 5658 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5659 | if (n_match_sets) { |
| 5660 | if (request->ie) |
| 5661 | request->match_sets = (void *)(request->ie + ie_len); |
| 5662 | else if (request->ssids) |
| 5663 | request->match_sets = |
| 5664 | (void *)(request->ssids + n_ssids); |
| 5665 | else |
| 5666 | request->match_sets = |
| 5667 | (void *)(request->channels + n_channels); |
| 5668 | } |
| 5669 | request->n_match_sets = n_match_sets; |
| 5670 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5671 | i = 0; |
| 5672 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 5673 | /* user specified, bail out if channel not found */ |
| 5674 | nla_for_each_nested(attr, |
| 5675 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
| 5676 | tmp) { |
| 5677 | struct ieee80211_channel *chan; |
| 5678 | |
| 5679 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 5680 | |
| 5681 | if (!chan) { |
| 5682 | err = -EINVAL; |
| 5683 | goto out_free; |
| 5684 | } |
| 5685 | |
| 5686 | /* ignore disabled channels */ |
| 5687 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5688 | continue; |
| 5689 | |
| 5690 | request->channels[i] = chan; |
| 5691 | i++; |
| 5692 | } |
| 5693 | } else { |
| 5694 | /* all channels */ |
| 5695 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 5696 | int j; |
| 5697 | if (!wiphy->bands[band]) |
| 5698 | continue; |
| 5699 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 5700 | struct ieee80211_channel *chan; |
| 5701 | |
| 5702 | chan = &wiphy->bands[band]->channels[j]; |
| 5703 | |
| 5704 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 5705 | continue; |
| 5706 | |
| 5707 | request->channels[i] = chan; |
| 5708 | i++; |
| 5709 | } |
| 5710 | } |
| 5711 | } |
| 5712 | |
| 5713 | if (!i) { |
| 5714 | err = -EINVAL; |
| 5715 | goto out_free; |
| 5716 | } |
| 5717 | |
| 5718 | request->n_channels = i; |
| 5719 | |
| 5720 | i = 0; |
| 5721 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 5722 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
| 5723 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5724 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5725 | err = -EINVAL; |
| 5726 | goto out_free; |
| 5727 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 5728 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5729 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 5730 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5731 | i++; |
| 5732 | } |
| 5733 | } |
| 5734 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5735 | i = 0; |
| 5736 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
| 5737 | nla_for_each_nested(attr, |
| 5738 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
| 5739 | tmp) { |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 5740 | struct nlattr *ssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5741 | |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 5742 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 5743 | nla_data(attr), nla_len(attr), |
| 5744 | nl80211_match_policy); |
| 5745 | if (err) |
| 5746 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 5747 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5748 | if (ssid) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5749 | if (WARN_ON(i >= n_match_sets)) { |
| 5750 | /* this indicates a programming error, |
| 5751 | * the loop above should have verified |
| 5752 | * things properly |
| 5753 | */ |
| 5754 | err = -EINVAL; |
| 5755 | goto out_free; |
| 5756 | } |
| 5757 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5758 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
| 5759 | err = -EINVAL; |
| 5760 | goto out_free; |
| 5761 | } |
| 5762 | memcpy(request->match_sets[i].ssid.ssid, |
| 5763 | nla_data(ssid), nla_len(ssid)); |
| 5764 | request->match_sets[i].ssid.ssid_len = |
| 5765 | nla_len(ssid); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5766 | /* special attribute - old implemenation w/a */ |
| 5767 | request->match_sets[i].rssi_thold = |
| 5768 | default_match_rssi; |
| 5769 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 5770 | if (rssi) |
| 5771 | request->match_sets[i].rssi_thold = |
| 5772 | nla_get_s32(rssi); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5773 | } |
| 5774 | i++; |
| 5775 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 5776 | |
| 5777 | /* there was no other matchset, so the RSSI one is alone */ |
| 5778 | if (i == 0) |
| 5779 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 5780 | |
| 5781 | request->min_rssi_thold = INT_MAX; |
| 5782 | for (i = 0; i < n_match_sets; i++) |
| 5783 | request->min_rssi_thold = |
| 5784 | min(request->match_sets[i].rssi_thold, |
| 5785 | request->min_rssi_thold); |
| 5786 | } else { |
| 5787 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 5788 | } |
| 5789 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 5790 | if (ie_len) { |
| 5791 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5792 | memcpy((void *)request->ie, |
| 5793 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 5794 | request->ie_len); |
| 5795 | } |
| 5796 | |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5797 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5798 | request->flags = nla_get_u32( |
| 5799 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); |
Johannes Berg | 00c3a6e | 2013-10-26 17:14:38 +0200 | [diff] [blame] | 5800 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 5801 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { |
Sam Leffler | 46856bb | 2012-10-11 21:03:32 -0700 | [diff] [blame] | 5802 | err = -EOPNOTSUPP; |
| 5803 | goto out_free; |
| 5804 | } |
| 5805 | } |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 5806 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5807 | request->dev = dev; |
| 5808 | request->wiphy = &rdev->wiphy; |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 5809 | request->interval = interval; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 5810 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5811 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5812 | err = rdev_sched_scan_start(rdev, dev, request); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5813 | if (!err) { |
| 5814 | rdev->sched_scan_req = request; |
| 5815 | nl80211_send_sched_scan(rdev, dev, |
| 5816 | NL80211_CMD_START_SCHED_SCAN); |
| 5817 | goto out; |
| 5818 | } |
| 5819 | |
| 5820 | out_free: |
| 5821 | kfree(request); |
| 5822 | out: |
| 5823 | return err; |
| 5824 | } |
| 5825 | |
| 5826 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 5827 | struct genl_info *info) |
| 5828 | { |
| 5829 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5830 | |
| 5831 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || |
| 5832 | !rdev->ops->sched_scan_stop) |
| 5833 | return -EOPNOTSUPP; |
| 5834 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 5835 | return __cfg80211_stop_sched_scan(rdev, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 5836 | } |
| 5837 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5838 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 5839 | struct genl_info *info) |
| 5840 | { |
| 5841 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5842 | struct net_device *dev = info->user_ptr[1]; |
| 5843 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5844 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5845 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 5846 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5847 | int err; |
| 5848 | |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 5849 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
| 5850 | if (dfs_region == NL80211_DFS_UNSET) |
| 5851 | return -EINVAL; |
| 5852 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5853 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 5854 | if (err) |
| 5855 | return err; |
| 5856 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 5857 | if (netif_carrier_ok(dev)) |
| 5858 | return -EBUSY; |
| 5859 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5860 | if (wdev->cac_started) |
| 5861 | return -EBUSY; |
| 5862 | |
Luciano Coelho | 2beb6da | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 5863 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 5864 | wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5865 | if (err < 0) |
| 5866 | return err; |
| 5867 | |
| 5868 | if (err == 0) |
| 5869 | return -EINVAL; |
| 5870 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 5871 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5872 | return -EINVAL; |
| 5873 | |
| 5874 | if (!rdev->ops->start_radar_detection) |
| 5875 | return -EOPNOTSUPP; |
| 5876 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 5877 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 5878 | if (WARN_ON(!cac_time_ms)) |
| 5879 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 5880 | |
| 5881 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, |
| 5882 | cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5883 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 5884 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5885 | wdev->cac_started = true; |
| 5886 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 5887 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5888 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 5889 | return err; |
| 5890 | } |
| 5891 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5892 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 5893 | { |
| 5894 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5895 | struct net_device *dev = info->user_ptr[1]; |
| 5896 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5897 | struct cfg80211_csa_settings params; |
| 5898 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 5899 | * function is called under RTNL lock, so this should not be a problem. |
| 5900 | */ |
| 5901 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
| 5902 | u8 radar_detect_width = 0; |
| 5903 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5904 | bool need_new_beacon = false; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 5905 | int len, i; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5906 | |
| 5907 | if (!rdev->ops->channel_switch || |
| 5908 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 5909 | return -EOPNOTSUPP; |
| 5910 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5911 | switch (dev->ieee80211_ptr->iftype) { |
| 5912 | case NL80211_IFTYPE_AP: |
| 5913 | case NL80211_IFTYPE_P2P_GO: |
| 5914 | need_new_beacon = true; |
| 5915 | |
| 5916 | /* useless if AP is not running */ |
| 5917 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 5918 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5919 | break; |
| 5920 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 5921 | if (!wdev->ssid_len) |
| 5922 | return -ENOTCONN; |
| 5923 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 5924 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 5925 | if (!wdev->mesh_id_len) |
| 5926 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5927 | break; |
| 5928 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5929 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5930 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5931 | |
| 5932 | memset(¶ms, 0, sizeof(params)); |
| 5933 | |
| 5934 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 5935 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 5936 | return -EINVAL; |
| 5937 | |
| 5938 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 5939 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5940 | return -EINVAL; |
| 5941 | |
| 5942 | params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 5943 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 5944 | if (!need_new_beacon) |
| 5945 | goto skip_beacons; |
| 5946 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5947 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
| 5948 | if (err) |
| 5949 | return err; |
| 5950 | |
| 5951 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, |
| 5952 | info->attrs[NL80211_ATTR_CSA_IES], |
| 5953 | nl80211_policy); |
| 5954 | if (err) |
| 5955 | return err; |
| 5956 | |
| 5957 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); |
| 5958 | if (err) |
| 5959 | return err; |
| 5960 | |
| 5961 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 5962 | return -EINVAL; |
| 5963 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 5964 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 5965 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5966 | return -EINVAL; |
| 5967 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 5968 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 5969 | if (rdev->wiphy.max_num_csa_counters && |
| 5970 | (params.n_counter_offsets_beacon > |
| 5971 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5972 | return -EINVAL; |
| 5973 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 5974 | params.counter_offsets_beacon = |
| 5975 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 5976 | |
| 5977 | /* sanity checks - counters should fit and be the same */ |
| 5978 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 5979 | u16 offset = params.counter_offsets_beacon[i]; |
| 5980 | |
| 5981 | if (offset >= params.beacon_csa.tail_len) |
| 5982 | return -EINVAL; |
| 5983 | |
| 5984 | if (params.beacon_csa.tail[offset] != params.count) |
| 5985 | return -EINVAL; |
| 5986 | } |
| 5987 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5988 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 5989 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 5990 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5991 | return -EINVAL; |
| 5992 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 5993 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 5994 | if (rdev->wiphy.max_num_csa_counters && |
| 5995 | (params.n_counter_offsets_beacon > |
| 5996 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 5997 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 5998 | |
| 5999 | params.counter_offsets_presp = |
| 6000 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 6001 | |
| 6002 | /* sanity checks - counters should fit and be the same */ |
| 6003 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 6004 | u16 offset = params.counter_offsets_presp[i]; |
| 6005 | |
| 6006 | if (offset >= params.beacon_csa.probe_resp_len) |
| 6007 | return -EINVAL; |
| 6008 | |
| 6009 | if (params.beacon_csa.probe_resp[offset] != |
| 6010 | params.count) |
| 6011 | return -EINVAL; |
| 6012 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6013 | } |
| 6014 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 6015 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6016 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 6017 | if (err) |
| 6018 | return err; |
| 6019 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 6020 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
| 6021 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6022 | return -EINVAL; |
| 6023 | |
Luciano Coelho | 2beb6da | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 6024 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 6025 | ¶ms.chandef, |
| 6026 | wdev->iftype); |
| 6027 | if (err < 0) |
| 6028 | return err; |
| 6029 | |
| 6030 | if (err > 0) { |
| 6031 | radar_detect_width = BIT(params.chandef.width); |
| 6032 | params.radar_required = true; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6033 | } |
| 6034 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6035 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 6036 | params.block_tx = true; |
| 6037 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6038 | wdev_lock(wdev); |
| 6039 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 6040 | wdev_unlock(wdev); |
| 6041 | |
| 6042 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 6043 | } |
| 6044 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6045 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 6046 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6047 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6048 | struct wireless_dev *wdev, |
| 6049 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6050 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6051 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6052 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6053 | void *hdr; |
| 6054 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6055 | |
| 6056 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6057 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6058 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6059 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 6060 | if (!hdr) |
| 6061 | return -1; |
| 6062 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6063 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
| 6064 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6065 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 6066 | goto nla_put_failure; |
| 6067 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6068 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 6069 | goto nla_put_failure; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6070 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 6071 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6072 | |
| 6073 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 6074 | if (!bss) |
| 6075 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6076 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6077 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6078 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6079 | |
| 6080 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6081 | /* indicate whether we have probe response data or not */ |
| 6082 | if (rcu_access_pointer(res->proberesp_ies) && |
| 6083 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 6084 | goto fail_unlock_rcu; |
| 6085 | |
| 6086 | /* this pointer prefers to be pointed to probe response data |
| 6087 | * but is always valid |
| 6088 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6089 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6090 | if (ies) { |
| 6091 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) |
| 6092 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6093 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 6094 | ies->len, ies->data)) |
| 6095 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6096 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6097 | |
| 6098 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6099 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 6100 | if (ies && ies->from_beacon) { |
| 6101 | if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6102 | goto fail_unlock_rcu; |
| 6103 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 6104 | ies->len, ies->data)) |
| 6105 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 6106 | } |
| 6107 | rcu_read_unlock(); |
| 6108 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6109 | if (res->beacon_interval && |
| 6110 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 6111 | goto nla_put_failure; |
| 6112 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 6113 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 6114 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6115 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 6116 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 6117 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6118 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 6119 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6120 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6121 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 6122 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6123 | break; |
| 6124 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6125 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 6126 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6127 | break; |
| 6128 | default: |
| 6129 | break; |
| 6130 | } |
| 6131 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6132 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6133 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6134 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6135 | if (intbss == wdev->current_bss && |
| 6136 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6137 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 6138 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6139 | break; |
| 6140 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6141 | if (intbss == wdev->current_bss && |
| 6142 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 6143 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 6144 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6145 | break; |
| 6146 | default: |
| 6147 | break; |
| 6148 | } |
| 6149 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6150 | nla_nest_end(msg, bss); |
| 6151 | |
| 6152 | return genlmsg_end(msg, hdr); |
| 6153 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 6154 | fail_unlock_rcu: |
| 6155 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6156 | nla_put_failure: |
| 6157 | genlmsg_cancel(msg, hdr); |
| 6158 | return -EMSGSIZE; |
| 6159 | } |
| 6160 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6161 | 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] | 6162 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6163 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6164 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6165 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6166 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6167 | int err; |
| 6168 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6169 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6170 | if (err) |
| 6171 | return err; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6172 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6173 | wdev_lock(wdev); |
| 6174 | spin_lock_bh(&rdev->bss_lock); |
| 6175 | cfg80211_bss_expire(rdev); |
| 6176 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6177 | cb->seq = rdev->bss_generation; |
| 6178 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6179 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6180 | if (++idx <= start) |
| 6181 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 6182 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6183 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6184 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6185 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6186 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6187 | } |
| 6188 | } |
| 6189 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 6190 | spin_unlock_bh(&rdev->bss_lock); |
| 6191 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6192 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6193 | cb->args[2] = idx; |
| 6194 | nl80211_finish_wdev_dump(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6195 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6196 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 6197 | } |
| 6198 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6199 | 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] | 6200 | int flags, struct net_device *dev, |
| 6201 | struct survey_info *survey) |
| 6202 | { |
| 6203 | void *hdr; |
| 6204 | struct nlattr *infoattr; |
| 6205 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6206 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6207 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 6208 | if (!hdr) |
| 6209 | return -ENOMEM; |
| 6210 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6211 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 6212 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6213 | |
| 6214 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); |
| 6215 | if (!infoattr) |
| 6216 | goto nla_put_failure; |
| 6217 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6218 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
| 6219 | survey->channel->center_freq)) |
| 6220 | goto nla_put_failure; |
| 6221 | |
| 6222 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 6223 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 6224 | goto nla_put_failure; |
| 6225 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 6226 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 6227 | goto nla_put_failure; |
| 6228 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && |
| 6229 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, |
| 6230 | survey->channel_time)) |
| 6231 | goto nla_put_failure; |
| 6232 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && |
| 6233 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, |
| 6234 | survey->channel_time_busy)) |
| 6235 | goto nla_put_failure; |
| 6236 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && |
| 6237 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, |
| 6238 | survey->channel_time_ext_busy)) |
| 6239 | goto nla_put_failure; |
| 6240 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && |
| 6241 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, |
| 6242 | survey->channel_time_rx)) |
| 6243 | goto nla_put_failure; |
| 6244 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && |
| 6245 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, |
| 6246 | survey->channel_time_tx)) |
| 6247 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6248 | |
| 6249 | nla_nest_end(msg, infoattr); |
| 6250 | |
| 6251 | return genlmsg_end(msg, hdr); |
| 6252 | |
| 6253 | nla_put_failure: |
| 6254 | genlmsg_cancel(msg, hdr); |
| 6255 | return -EMSGSIZE; |
| 6256 | } |
| 6257 | |
| 6258 | static int nl80211_dump_survey(struct sk_buff *skb, |
| 6259 | struct netlink_callback *cb) |
| 6260 | { |
| 6261 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6262 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6263 | struct wireless_dev *wdev; |
| 6264 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6265 | int res; |
| 6266 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6267 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6268 | if (res) |
| 6269 | return res; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6270 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6271 | if (!wdev->netdev) { |
| 6272 | res = -EINVAL; |
| 6273 | goto out_err; |
| 6274 | } |
| 6275 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6276 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6277 | res = -EOPNOTSUPP; |
| 6278 | goto out_err; |
| 6279 | } |
| 6280 | |
| 6281 | while (1) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6282 | struct ieee80211_channel *chan; |
| 6283 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6284 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6285 | if (res == -ENOENT) |
| 6286 | break; |
| 6287 | if (res) |
| 6288 | goto out_err; |
| 6289 | |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6290 | /* Survey without a channel doesn't make sense */ |
| 6291 | if (!survey.channel) { |
| 6292 | res = -EINVAL; |
| 6293 | goto out; |
| 6294 | } |
| 6295 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6296 | chan = ieee80211_get_channel(&rdev->wiphy, |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 6297 | survey.channel->center_freq); |
| 6298 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { |
| 6299 | survey_idx++; |
| 6300 | continue; |
| 6301 | } |
| 6302 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6303 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6304 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6305 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6306 | wdev->netdev, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6307 | goto out; |
| 6308 | survey_idx++; |
| 6309 | } |
| 6310 | |
| 6311 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6312 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6313 | res = skb->len; |
| 6314 | out_err: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6315 | nl80211_finish_wdev_dump(rdev); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 6316 | return res; |
| 6317 | } |
| 6318 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6319 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 6320 | { |
| 6321 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 6322 | NL80211_WPA_VERSION_2)); |
| 6323 | } |
| 6324 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6325 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 6326 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6327 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6328 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6329 | struct ieee80211_channel *chan; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6330 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
| 6331 | int err, ssid_len, ie_len = 0, sae_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6332 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6333 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6334 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6335 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6336 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6337 | return -EINVAL; |
| 6338 | |
| 6339 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6340 | return -EINVAL; |
| 6341 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 6342 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 6343 | return -EINVAL; |
| 6344 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6345 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 6346 | return -EINVAL; |
| 6347 | |
| 6348 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 6349 | return -EINVAL; |
| 6350 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6351 | err = nl80211_parse_key(info, &key); |
| 6352 | if (err) |
| 6353 | return err; |
| 6354 | |
| 6355 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 6356 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 6357 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6358 | if (!key.p.key || !key.p.key_len) |
| 6359 | return -EINVAL; |
| 6360 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 6361 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 6362 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 6363 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 6364 | return -EINVAL; |
| 6365 | if (key.idx > 4) |
| 6366 | return -EINVAL; |
| 6367 | } else { |
| 6368 | key.p.key_len = 0; |
| 6369 | key.p.key = NULL; |
| 6370 | } |
| 6371 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6372 | if (key.idx >= 0) { |
| 6373 | int i; |
| 6374 | bool ok = false; |
| 6375 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 6376 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 6377 | ok = true; |
| 6378 | break; |
| 6379 | } |
| 6380 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6381 | if (!ok) |
| 6382 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 6383 | } |
| 6384 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6385 | if (!rdev->ops->auth) |
| 6386 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6387 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6388 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6389 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6390 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6391 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6392 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6393 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 6394 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6395 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6396 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6397 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6398 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6399 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6400 | |
| 6401 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6402 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6403 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6404 | } |
| 6405 | |
| 6406 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6407 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6408 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6409 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 6410 | if (auth_type == NL80211_AUTHTYPE_SAE && |
| 6411 | !info->attrs[NL80211_ATTR_SAE_DATA]) |
| 6412 | return -EINVAL; |
| 6413 | |
| 6414 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { |
| 6415 | if (auth_type != NL80211_AUTHTYPE_SAE) |
| 6416 | return -EINVAL; |
| 6417 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6418 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); |
| 6419 | /* need to include at least Auth Transaction and Status Code */ |
| 6420 | if (sae_data_len < 4) |
| 6421 | return -EINVAL; |
| 6422 | } |
| 6423 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6424 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6425 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 6426 | /* |
| 6427 | * Since we no longer track auth state, ignore |
| 6428 | * requests to only change local state. |
| 6429 | */ |
| 6430 | if (local_state_change) |
| 6431 | return 0; |
| 6432 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6433 | wdev_lock(dev->ieee80211_ptr); |
| 6434 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 6435 | ssid, ssid_len, ie, ie_len, |
| 6436 | key.p.key, key.p.key_len, key.idx, |
| 6437 | sae_data, sae_data_len); |
| 6438 | wdev_unlock(dev->ieee80211_ptr); |
| 6439 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6440 | } |
| 6441 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6442 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 6443 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6444 | struct cfg80211_crypto_settings *settings, |
| 6445 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6446 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 6447 | memset(settings, 0, sizeof(*settings)); |
| 6448 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6449 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 6450 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 6451 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 6452 | u16 proto; |
| 6453 | proto = nla_get_u16( |
| 6454 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 6455 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 6456 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 6457 | proto != ETH_P_PAE) |
| 6458 | return -EINVAL; |
| 6459 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 6460 | settings->control_port_no_encrypt = true; |
| 6461 | } else |
| 6462 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 6463 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6464 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 6465 | void *data; |
| 6466 | int len, i; |
| 6467 | |
| 6468 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6469 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 6470 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 6471 | |
| 6472 | if (len % sizeof(u32)) |
| 6473 | return -EINVAL; |
| 6474 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 6475 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6476 | return -EINVAL; |
| 6477 | |
| 6478 | memcpy(settings->ciphers_pairwise, data, len); |
| 6479 | |
| 6480 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6481 | if (!cfg80211_supported_cipher_suite( |
| 6482 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6483 | settings->ciphers_pairwise[i])) |
| 6484 | return -EINVAL; |
| 6485 | } |
| 6486 | |
| 6487 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 6488 | settings->cipher_group = |
| 6489 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 6490 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 6491 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6492 | return -EINVAL; |
| 6493 | } |
| 6494 | |
| 6495 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 6496 | settings->wpa_versions = |
| 6497 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 6498 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 6499 | return -EINVAL; |
| 6500 | } |
| 6501 | |
| 6502 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 6503 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 6504 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6505 | |
| 6506 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6507 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 6508 | settings->n_akm_suites = len / sizeof(u32); |
| 6509 | |
| 6510 | if (len % sizeof(u32)) |
| 6511 | return -EINVAL; |
| 6512 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 6513 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 6514 | return -EINVAL; |
| 6515 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6516 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 6517 | } |
| 6518 | |
| 6519 | return 0; |
| 6520 | } |
| 6521 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6522 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 6523 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6524 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6525 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 6526 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6527 | struct cfg80211_assoc_request req = {}; |
| 6528 | const u8 *bssid, *ssid; |
| 6529 | int err, ssid_len = 0; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6530 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6531 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6532 | return -EINVAL; |
| 6533 | |
| 6534 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6535 | !info->attrs[NL80211_ATTR_SSID] || |
| 6536 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6537 | return -EINVAL; |
| 6538 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6539 | if (!rdev->ops->assoc) |
| 6540 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6541 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6542 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6543 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6544 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6545 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6546 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6547 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 6548 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
| 6549 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 6550 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6551 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6552 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6553 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6554 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6555 | |
| 6556 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6557 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6558 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6559 | } |
| 6560 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6561 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6562 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6563 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 6564 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6565 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6566 | else if (mfp != NL80211_MFP_NO) |
| 6567 | return -EINVAL; |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 6568 | } |
| 6569 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6570 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6571 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 6572 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6573 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6574 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6575 | |
| 6576 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6577 | memcpy(&req.ht_capa_mask, |
| 6578 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6579 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6580 | |
| 6581 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6582 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6583 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6584 | memcpy(&req.ht_capa, |
| 6585 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6586 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 6587 | } |
| 6588 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6589 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6590 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6591 | |
| 6592 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6593 | memcpy(&req.vht_capa_mask, |
| 6594 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 6595 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6596 | |
| 6597 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6598 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6599 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6600 | memcpy(&req.vht_capa, |
| 6601 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 6602 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 6603 | } |
| 6604 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 6605 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
| 6606 | if (!(rdev->wiphy.features & |
| 6607 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || |
| 6608 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) |
| 6609 | return -EINVAL; |
| 6610 | req.flags |= ASSOC_REQ_USE_RRM; |
| 6611 | } |
| 6612 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6613 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6614 | if (!err) { |
| 6615 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 6616 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 6617 | ssid, ssid_len, &req); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6618 | wdev_unlock(dev->ieee80211_ptr); |
| 6619 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6620 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6621 | return err; |
| 6622 | } |
| 6623 | |
| 6624 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 6625 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6626 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6627 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6628 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6629 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6630 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6631 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6632 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6633 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6634 | return -EINVAL; |
| 6635 | |
| 6636 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6637 | return -EINVAL; |
| 6638 | |
| 6639 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6640 | return -EINVAL; |
| 6641 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6642 | if (!rdev->ops->deauth) |
| 6643 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6644 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6645 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6646 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6647 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6648 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6649 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6650 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6651 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6652 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6653 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6654 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6655 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6656 | |
| 6657 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6658 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6659 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6660 | } |
| 6661 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6662 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6663 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6664 | wdev_lock(dev->ieee80211_ptr); |
| 6665 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6666 | local_state_change); |
| 6667 | wdev_unlock(dev->ieee80211_ptr); |
| 6668 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6669 | } |
| 6670 | |
| 6671 | static int nl80211_disassociate(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 | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6675 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6676 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6677 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6678 | bool local_state_change; |
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]) |
| 6684 | return -EINVAL; |
| 6685 | |
| 6686 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 6687 | return -EINVAL; |
| 6688 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6689 | if (!rdev->ops->disassoc) |
| 6690 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6691 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6692 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6693 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 6694 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6695 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6696 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6697 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6698 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6699 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 6700 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6701 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 6702 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6703 | |
| 6704 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 6705 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6706 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6707 | } |
| 6708 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 6709 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 6710 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 6711 | wdev_lock(dev->ieee80211_ptr); |
| 6712 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 6713 | local_state_change); |
| 6714 | wdev_unlock(dev->ieee80211_ptr); |
| 6715 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 6716 | } |
| 6717 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6718 | static bool |
| 6719 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
| 6720 | int mcast_rate[IEEE80211_NUM_BANDS], |
| 6721 | int rateval) |
| 6722 | { |
| 6723 | struct wiphy *wiphy = &rdev->wiphy; |
| 6724 | bool found = false; |
| 6725 | int band, i; |
| 6726 | |
| 6727 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 6728 | struct ieee80211_supported_band *sband; |
| 6729 | |
| 6730 | sband = wiphy->bands[band]; |
| 6731 | if (!sband) |
| 6732 | continue; |
| 6733 | |
| 6734 | for (i = 0; i < sband->n_bitrates; i++) { |
| 6735 | if (sband->bitrates[i].bitrate == rateval) { |
| 6736 | mcast_rate[band] = i + 1; |
| 6737 | found = true; |
| 6738 | break; |
| 6739 | } |
| 6740 | } |
| 6741 | } |
| 6742 | |
| 6743 | return found; |
| 6744 | } |
| 6745 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6746 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6747 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6748 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6749 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6750 | struct cfg80211_ibss_params ibss; |
| 6751 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6752 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6753 | int err; |
| 6754 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6755 | memset(&ibss, 0, sizeof(ibss)); |
| 6756 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6757 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 6758 | return -EINVAL; |
| 6759 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6760 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6761 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 6762 | return -EINVAL; |
| 6763 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 6764 | ibss.beacon_interval = 100; |
| 6765 | |
| 6766 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 6767 | ibss.beacon_interval = |
| 6768 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 6769 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 6770 | return -EINVAL; |
| 6771 | } |
| 6772 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6773 | if (!rdev->ops->join_ibss) |
| 6774 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6775 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6776 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6777 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6778 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 6779 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6780 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6781 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6782 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 6783 | |
| 6784 | if (!is_valid_ether_addr(ibss.bssid)) |
| 6785 | return -EINVAL; |
| 6786 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6787 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 6788 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 6789 | |
| 6790 | if (info->attrs[NL80211_ATTR_IE]) { |
| 6791 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 6792 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 6793 | } |
| 6794 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6795 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 6796 | if (err) |
| 6797 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6798 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 6799 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 6800 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 6801 | return -EINVAL; |
| 6802 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6803 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 6804 | case NL80211_CHAN_WIDTH_5: |
| 6805 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6806 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 6807 | break; |
| 6808 | case NL80211_CHAN_WIDTH_20: |
| 6809 | case NL80211_CHAN_WIDTH_40: |
| 6810 | if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS) |
| 6811 | break; |
| 6812 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6813 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 6814 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 6815 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6816 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6817 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6818 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6819 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6820 | u8 *rates = |
| 6821 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6822 | int n_rates = |
| 6823 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6824 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 6825 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6826 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 6827 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 6828 | &ibss.basic_rates); |
| 6829 | if (err) |
| 6830 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6831 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6832 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 6833 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6834 | memcpy(&ibss.ht_capa_mask, |
| 6835 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 6836 | sizeof(ibss.ht_capa_mask)); |
| 6837 | |
| 6838 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 6839 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 6840 | return -EINVAL; |
| 6841 | memcpy(&ibss.ht_capa, |
| 6842 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 6843 | sizeof(ibss.ht_capa)); |
| 6844 | } |
| 6845 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 6846 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 6847 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 6848 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 6849 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 6850 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6851 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6852 | bool no_ht = false; |
| 6853 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6854 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6855 | info->attrs[NL80211_ATTR_KEYS], |
| 6856 | &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6857 | if (IS_ERR(connkeys)) |
| 6858 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6859 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 6860 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 6861 | no_ht) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 6862 | kfree(connkeys); |
| 6863 | return -EINVAL; |
| 6864 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6865 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6866 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6867 | ibss.control_port = |
| 6868 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 6869 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 6870 | ibss.userspace_handles_dfs = |
| 6871 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 6872 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6873 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 6874 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 6875 | kzfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6876 | return err; |
| 6877 | } |
| 6878 | |
| 6879 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 6880 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6881 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6882 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6883 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6884 | if (!rdev->ops->leave_ibss) |
| 6885 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6886 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6887 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 6888 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6889 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6890 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 6891 | } |
| 6892 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6893 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 6894 | { |
| 6895 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6896 | struct net_device *dev = info->user_ptr[1]; |
| 6897 | int mcast_rate[IEEE80211_NUM_BANDS]; |
| 6898 | u32 nla_rate; |
| 6899 | int err; |
| 6900 | |
| 6901 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
| 6902 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6903 | return -EOPNOTSUPP; |
| 6904 | |
| 6905 | if (!rdev->ops->set_mcast_rate) |
| 6906 | return -EOPNOTSUPP; |
| 6907 | |
| 6908 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 6909 | |
| 6910 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 6911 | return -EINVAL; |
| 6912 | |
| 6913 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 6914 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 6915 | return -EINVAL; |
| 6916 | |
| 6917 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); |
| 6918 | |
| 6919 | return err; |
| 6920 | } |
| 6921 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6922 | static struct sk_buff * |
| 6923 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
| 6924 | int approxlen, u32 portid, u32 seq, |
| 6925 | enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 6926 | enum nl80211_attrs attr, |
| 6927 | const struct nl80211_vendor_cmd_info *info, |
| 6928 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6929 | { |
| 6930 | struct sk_buff *skb; |
| 6931 | void *hdr; |
| 6932 | struct nlattr *data; |
| 6933 | |
| 6934 | skb = nlmsg_new(approxlen + 100, gfp); |
| 6935 | if (!skb) |
| 6936 | return NULL; |
| 6937 | |
| 6938 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 6939 | if (!hdr) { |
| 6940 | kfree_skb(skb); |
| 6941 | return NULL; |
| 6942 | } |
| 6943 | |
| 6944 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 6945 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 6946 | |
| 6947 | if (info) { |
| 6948 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 6949 | info->vendor_id)) |
| 6950 | goto nla_put_failure; |
| 6951 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 6952 | info->subcmd)) |
| 6953 | goto nla_put_failure; |
| 6954 | } |
| 6955 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 6956 | data = nla_nest_start(skb, attr); |
| 6957 | |
| 6958 | ((void **)skb->cb)[0] = rdev; |
| 6959 | ((void **)skb->cb)[1] = hdr; |
| 6960 | ((void **)skb->cb)[2] = data; |
| 6961 | |
| 6962 | return skb; |
| 6963 | |
| 6964 | nla_put_failure: |
| 6965 | kfree_skb(skb); |
| 6966 | return NULL; |
| 6967 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 6968 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 6969 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
| 6970 | enum nl80211_commands cmd, |
| 6971 | enum nl80211_attrs attr, |
| 6972 | int vendor_event_idx, |
| 6973 | int approxlen, gfp_t gfp) |
| 6974 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 6975 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 6976 | const struct nl80211_vendor_cmd_info *info; |
| 6977 | |
| 6978 | switch (cmd) { |
| 6979 | case NL80211_CMD_TESTMODE: |
| 6980 | if (WARN_ON(vendor_event_idx != -1)) |
| 6981 | return NULL; |
| 6982 | info = NULL; |
| 6983 | break; |
| 6984 | case NL80211_CMD_VENDOR: |
| 6985 | if (WARN_ON(vendor_event_idx < 0 || |
| 6986 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 6987 | return NULL; |
| 6988 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 6989 | break; |
| 6990 | default: |
| 6991 | WARN_ON(1); |
| 6992 | return NULL; |
| 6993 | } |
| 6994 | |
| 6995 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0, |
| 6996 | cmd, attr, info, gfp); |
| 6997 | } |
| 6998 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 6999 | |
| 7000 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 7001 | { |
| 7002 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 7003 | void *hdr = ((void **)skb->cb)[1]; |
| 7004 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 7005 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 7006 | |
| 7007 | nla_nest_end(skb, data); |
| 7008 | genlmsg_end(skb, hdr); |
| 7009 | |
| 7010 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 7011 | mcgrp = NL80211_MCGRP_VENDOR; |
| 7012 | |
| 7013 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, |
| 7014 | mcgrp, gfp); |
| 7015 | } |
| 7016 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 7017 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7018 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7019 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 7020 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7021 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7022 | struct wireless_dev *wdev = |
| 7023 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7024 | int err; |
| 7025 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7026 | if (!rdev->ops->testmode_cmd) |
| 7027 | return -EOPNOTSUPP; |
| 7028 | |
| 7029 | if (IS_ERR(wdev)) { |
| 7030 | err = PTR_ERR(wdev); |
| 7031 | if (err != -EINVAL) |
| 7032 | return err; |
| 7033 | wdev = NULL; |
| 7034 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 7035 | return -EINVAL; |
| 7036 | } |
| 7037 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7038 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 7039 | return -EINVAL; |
| 7040 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7041 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 7042 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7043 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 7044 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 7045 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7046 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7047 | return err; |
| 7048 | } |
| 7049 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7050 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 7051 | struct netlink_callback *cb) |
| 7052 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7053 | struct cfg80211_registered_device *rdev; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7054 | int err; |
| 7055 | long phy_idx; |
| 7056 | void *data = NULL; |
| 7057 | int data_len = 0; |
| 7058 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7059 | rtnl_lock(); |
| 7060 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7061 | if (cb->args[0]) { |
| 7062 | /* |
| 7063 | * 0 is a valid index, but not valid for args[0], |
| 7064 | * so we need to offset by 1. |
| 7065 | */ |
| 7066 | phy_idx = cb->args[0] - 1; |
| 7067 | } else { |
| 7068 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 7069 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 7070 | nl80211_policy); |
| 7071 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7072 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7073 | |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7074 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
| 7075 | nl80211_fam.attrbuf); |
| 7076 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7077 | err = PTR_ERR(rdev); |
| 7078 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7079 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7080 | phy_idx = rdev->wiphy_idx; |
| 7081 | rdev = NULL; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 7082 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7083 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
| 7084 | cb->args[1] = |
| 7085 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; |
| 7086 | } |
| 7087 | |
| 7088 | if (cb->args[1]) { |
| 7089 | data = nla_data((void *)cb->args[1]); |
| 7090 | data_len = nla_len((void *)cb->args[1]); |
| 7091 | } |
| 7092 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7093 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 7094 | if (!rdev) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7095 | err = -ENOENT; |
| 7096 | goto out_err; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7097 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7098 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 7099 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7100 | err = -EOPNOTSUPP; |
| 7101 | goto out_err; |
| 7102 | } |
| 7103 | |
| 7104 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7105 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7106 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 7107 | NL80211_CMD_TESTMODE); |
| 7108 | struct nlattr *tmdata; |
| 7109 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7110 | if (!hdr) |
| 7111 | break; |
| 7112 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7113 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7114 | genlmsg_cancel(skb, hdr); |
| 7115 | break; |
| 7116 | } |
| 7117 | |
| 7118 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 7119 | if (!tmdata) { |
| 7120 | genlmsg_cancel(skb, hdr); |
| 7121 | break; |
| 7122 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7123 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7124 | nla_nest_end(skb, tmdata); |
| 7125 | |
| 7126 | if (err == -ENOBUFS || err == -ENOENT) { |
| 7127 | genlmsg_cancel(skb, hdr); |
| 7128 | break; |
| 7129 | } else if (err) { |
| 7130 | genlmsg_cancel(skb, hdr); |
| 7131 | goto out_err; |
| 7132 | } |
| 7133 | |
| 7134 | genlmsg_end(skb, hdr); |
| 7135 | } |
| 7136 | |
| 7137 | err = skb->len; |
| 7138 | /* see above */ |
| 7139 | cb->args[0] = phy_idx + 1; |
| 7140 | out_err: |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7141 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 7142 | return err; |
| 7143 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 7144 | #endif |
| 7145 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7146 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 7147 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7148 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7149 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7150 | struct cfg80211_connect_params connect; |
| 7151 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7152 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7153 | int err; |
| 7154 | |
| 7155 | memset(&connect, 0, sizeof(connect)); |
| 7156 | |
| 7157 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 7158 | return -EINVAL; |
| 7159 | |
| 7160 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 7161 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 7162 | return -EINVAL; |
| 7163 | |
| 7164 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 7165 | connect.auth_type = |
| 7166 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 7167 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 7168 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7169 | return -EINVAL; |
| 7170 | } else |
| 7171 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 7172 | |
| 7173 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 7174 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 7175 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 7176 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7177 | if (err) |
| 7178 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7179 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7180 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7181 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7182 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7183 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7184 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7185 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 7186 | connect.bg_scan_period = -1; |
| 7187 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 7188 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 7189 | connect.bg_scan_period = |
| 7190 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 7191 | } |
| 7192 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7193 | if (info->attrs[NL80211_ATTR_MAC]) |
| 7194 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7195 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 7196 | connect.bssid_hint = |
| 7197 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7198 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 7199 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 7200 | |
| 7201 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7202 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 7203 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7204 | } |
| 7205 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 7206 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 7207 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 7208 | if (connect.mfp != NL80211_MFP_REQUIRED && |
| 7209 | connect.mfp != NL80211_MFP_NO) |
| 7210 | return -EINVAL; |
| 7211 | } else { |
| 7212 | connect.mfp = NL80211_MFP_NO; |
| 7213 | } |
| 7214 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7215 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7216 | connect.channel = nl80211_get_valid_chan( |
| 7217 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 7218 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7219 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7220 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 7221 | connect.channel_hint = nl80211_get_valid_chan( |
| 7222 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 7223 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 7224 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7225 | } |
| 7226 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7227 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 7228 | connkeys = nl80211_parse_connkeys(rdev, |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 7229 | info->attrs[NL80211_ATTR_KEYS], NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7230 | if (IS_ERR(connkeys)) |
| 7231 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7232 | } |
| 7233 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7234 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 7235 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 7236 | |
| 7237 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 7238 | memcpy(&connect.ht_capa_mask, |
| 7239 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 7240 | sizeof(connect.ht_capa_mask)); |
| 7241 | |
| 7242 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7243 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7244 | kzfree(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7245 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 7246 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 7247 | memcpy(&connect.ht_capa, |
| 7248 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 7249 | sizeof(connect.ht_capa)); |
| 7250 | } |
| 7251 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7252 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 7253 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 7254 | |
| 7255 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 7256 | memcpy(&connect.vht_capa_mask, |
| 7257 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 7258 | sizeof(connect.vht_capa_mask)); |
| 7259 | |
| 7260 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 7261 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7262 | kzfree(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 7263 | return -EINVAL; |
| 7264 | } |
| 7265 | memcpy(&connect.vht_capa, |
| 7266 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 7267 | sizeof(connect.vht_capa)); |
| 7268 | } |
| 7269 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 7270 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
| 7271 | if (!(rdev->wiphy.features & |
| 7272 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || |
| 7273 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) |
| 7274 | return -EINVAL; |
| 7275 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 7276 | } |
| 7277 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7278 | wdev_lock(dev->ieee80211_ptr); |
| 7279 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); |
| 7280 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 7281 | if (err) |
Johannes Berg | b47f610 | 2014-09-10 13:39:54 +0300 | [diff] [blame] | 7282 | kzfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7283 | return err; |
| 7284 | } |
| 7285 | |
| 7286 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 7287 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7288 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7289 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7290 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7291 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7292 | |
| 7293 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 7294 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 7295 | else |
| 7296 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7297 | |
| 7298 | if (reason == 0) |
| 7299 | return -EINVAL; |
| 7300 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7301 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7302 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7303 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7304 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 7305 | wdev_lock(dev->ieee80211_ptr); |
| 7306 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 7307 | wdev_unlock(dev->ieee80211_ptr); |
| 7308 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 7309 | } |
| 7310 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7311 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 7312 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7313 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7314 | struct net *net; |
| 7315 | int err; |
| 7316 | u32 pid; |
| 7317 | |
| 7318 | if (!info->attrs[NL80211_ATTR_PID]) |
| 7319 | return -EINVAL; |
| 7320 | |
| 7321 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 7322 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7323 | net = get_net_ns_by_pid(pid); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7324 | if (IS_ERR(net)) |
| 7325 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7326 | |
| 7327 | err = 0; |
| 7328 | |
| 7329 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7330 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 7331 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7332 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7333 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 7334 | return err; |
| 7335 | } |
| 7336 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7337 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7338 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7339 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7340 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 7341 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7342 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7343 | struct cfg80211_pmksa pmksa; |
| 7344 | |
| 7345 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 7346 | |
| 7347 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7348 | return -EINVAL; |
| 7349 | |
| 7350 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 7351 | return -EINVAL; |
| 7352 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7353 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 7354 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7355 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7356 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7357 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7358 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7359 | |
| 7360 | switch (info->genlhdr->cmd) { |
| 7361 | case NL80211_CMD_SET_PMKSA: |
| 7362 | rdev_ops = rdev->ops->set_pmksa; |
| 7363 | break; |
| 7364 | case NL80211_CMD_DEL_PMKSA: |
| 7365 | rdev_ops = rdev->ops->del_pmksa; |
| 7366 | break; |
| 7367 | default: |
| 7368 | WARN_ON(1); |
| 7369 | break; |
| 7370 | } |
| 7371 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7372 | if (!rdev_ops) |
| 7373 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7374 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7375 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7376 | } |
| 7377 | |
| 7378 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 7379 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7380 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7381 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7382 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7383 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7384 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 7385 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7386 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7387 | if (!rdev->ops->flush_pmksa) |
| 7388 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7389 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7390 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 7391 | } |
| 7392 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7393 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 7394 | { |
| 7395 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7396 | struct net_device *dev = info->user_ptr[1]; |
| 7397 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7398 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7399 | u16 status_code; |
| 7400 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7401 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7402 | |
| 7403 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7404 | !rdev->ops->tdls_mgmt) |
| 7405 | return -EOPNOTSUPP; |
| 7406 | |
| 7407 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 7408 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 7409 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 7410 | !info->attrs[NL80211_ATTR_IE] || |
| 7411 | !info->attrs[NL80211_ATTR_MAC]) |
| 7412 | return -EINVAL; |
| 7413 | |
| 7414 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7415 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 7416 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 7417 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7418 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7419 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 7420 | peer_capability = |
| 7421 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7422 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7423 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 7424 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 7425 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7426 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 7427 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7428 | } |
| 7429 | |
| 7430 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 7431 | { |
| 7432 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7433 | struct net_device *dev = info->user_ptr[1]; |
| 7434 | enum nl80211_tdls_operation operation; |
| 7435 | u8 *peer; |
| 7436 | |
| 7437 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 7438 | !rdev->ops->tdls_oper) |
| 7439 | return -EOPNOTSUPP; |
| 7440 | |
| 7441 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 7442 | !info->attrs[NL80211_ATTR_MAC]) |
| 7443 | return -EINVAL; |
| 7444 | |
| 7445 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 7446 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7447 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7448 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 7449 | } |
| 7450 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7451 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 7452 | struct genl_info *info) |
| 7453 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7454 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7455 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7456 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7457 | struct sk_buff *msg; |
| 7458 | void *hdr; |
| 7459 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7460 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7461 | int err; |
| 7462 | |
| 7463 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 7464 | !info->attrs[NL80211_ATTR_DURATION]) |
| 7465 | return -EINVAL; |
| 7466 | |
| 7467 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 7468 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7469 | if (!rdev->ops->remain_on_channel || |
| 7470 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7471 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7472 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7473 | /* |
| 7474 | * We should be on that channel for at least a minimum amount of |
| 7475 | * time (10ms) but no longer than the driver supports. |
| 7476 | */ |
| 7477 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7478 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 7479 | return -EINVAL; |
| 7480 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7481 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7482 | if (err) |
| 7483 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7484 | |
| 7485 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7486 | if (!msg) |
| 7487 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7488 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7489 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7490 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7491 | if (!hdr) { |
| 7492 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7493 | goto free_msg; |
| 7494 | } |
| 7495 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7496 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 7497 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7498 | |
| 7499 | if (err) |
| 7500 | goto free_msg; |
| 7501 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7502 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7503 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7504 | |
| 7505 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7506 | |
| 7507 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7508 | |
| 7509 | nla_put_failure: |
| 7510 | err = -ENOBUFS; |
| 7511 | free_msg: |
| 7512 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7513 | return err; |
| 7514 | } |
| 7515 | |
| 7516 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 7517 | struct genl_info *info) |
| 7518 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7519 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7520 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7521 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7522 | |
| 7523 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7524 | return -EINVAL; |
| 7525 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7526 | if (!rdev->ops->cancel_remain_on_channel) |
| 7527 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7528 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7529 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7530 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7531 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 7532 | } |
| 7533 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7534 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7535 | u8 *rates, u8 rates_len) |
| 7536 | { |
| 7537 | u8 i; |
| 7538 | u32 mask = 0; |
| 7539 | |
| 7540 | for (i = 0; i < rates_len; i++) { |
| 7541 | int rate = (rates[i] & 0x7f) * 5; |
| 7542 | int ridx; |
| 7543 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 7544 | struct ieee80211_rate *srate = |
| 7545 | &sband->bitrates[ridx]; |
| 7546 | if (rate == srate->bitrate) { |
| 7547 | mask |= 1 << ridx; |
| 7548 | break; |
| 7549 | } |
| 7550 | } |
| 7551 | if (ridx == sband->n_bitrates) |
| 7552 | return 0; /* rate not found */ |
| 7553 | } |
| 7554 | |
| 7555 | return mask; |
| 7556 | } |
| 7557 | |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7558 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 7559 | u8 *rates, u8 rates_len, |
| 7560 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 7561 | { |
| 7562 | u8 i; |
| 7563 | |
| 7564 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 7565 | |
| 7566 | for (i = 0; i < rates_len; i++) { |
| 7567 | int ridx, rbit; |
| 7568 | |
| 7569 | ridx = rates[i] / 8; |
| 7570 | rbit = BIT(rates[i] % 8); |
| 7571 | |
| 7572 | /* check validity */ |
Dan Carpenter | 910570b5 | 2012-02-01 10:42:11 +0300 | [diff] [blame] | 7573 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7574 | return false; |
| 7575 | |
| 7576 | /* check availability */ |
| 7577 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 7578 | mcs[ridx] |= rbit; |
| 7579 | else |
| 7580 | return false; |
| 7581 | } |
| 7582 | |
| 7583 | return true; |
| 7584 | } |
| 7585 | |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7586 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 7587 | { |
| 7588 | u16 mcs_mask = 0; |
| 7589 | |
| 7590 | switch (vht_mcs_map) { |
| 7591 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 7592 | break; |
| 7593 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 7594 | mcs_mask = 0x00FF; |
| 7595 | break; |
| 7596 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 7597 | mcs_mask = 0x01FF; |
| 7598 | break; |
| 7599 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 7600 | mcs_mask = 0x03FF; |
| 7601 | break; |
| 7602 | default: |
| 7603 | break; |
| 7604 | } |
| 7605 | |
| 7606 | return mcs_mask; |
| 7607 | } |
| 7608 | |
| 7609 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 7610 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 7611 | { |
| 7612 | u8 nss; |
| 7613 | |
| 7614 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 7615 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 7616 | vht_mcs_map >>= 2; |
| 7617 | } |
| 7618 | } |
| 7619 | |
| 7620 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 7621 | struct nl80211_txrate_vht *txrate, |
| 7622 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 7623 | { |
| 7624 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7625 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 7626 | u8 i; |
| 7627 | |
| 7628 | if (!sband->vht_cap.vht_supported) |
| 7629 | return false; |
| 7630 | |
| 7631 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 7632 | |
| 7633 | /* Build vht_mcs_mask from VHT capabilities */ |
| 7634 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 7635 | |
| 7636 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 7637 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 7638 | mcs[i] = txrate->mcs[i]; |
| 7639 | else |
| 7640 | return false; |
| 7641 | } |
| 7642 | |
| 7643 | return true; |
| 7644 | } |
| 7645 | |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 7646 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7647 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 7648 | .len = NL80211_MAX_SUPP_RATES }, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7649 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 7650 | .len = NL80211_MAX_SUPP_HT_RATES }, |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7651 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 7652 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7653 | }; |
| 7654 | |
| 7655 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 7656 | struct genl_info *info) |
| 7657 | { |
| 7658 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7659 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7660 | struct cfg80211_bitrate_mask mask; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7661 | int rem, i; |
| 7662 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7663 | struct nlattr *tx_rates; |
| 7664 | struct ieee80211_supported_band *sband; |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7665 | u16 vht_tx_mcs_map; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7666 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7667 | if (!rdev->ops->set_bitrate_mask) |
| 7668 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7669 | |
| 7670 | memset(&mask, 0, sizeof(mask)); |
| 7671 | /* Default to all rates enabled */ |
| 7672 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { |
| 7673 | sband = rdev->wiphy.bands[i]; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7674 | |
| 7675 | if (!sband) |
| 7676 | continue; |
| 7677 | |
| 7678 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7679 | memcpy(mask.control[i].ht_mcs, |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 7680 | sband->ht_cap.mcs.rx_mask, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7681 | sizeof(mask.control[i].ht_mcs)); |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7682 | |
| 7683 | if (!sband->vht_cap.vht_supported) |
| 7684 | continue; |
| 7685 | |
| 7686 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 7687 | 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] | 7688 | } |
| 7689 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7690 | /* if no rates are given set it back to the defaults */ |
| 7691 | if (!info->attrs[NL80211_ATTR_TX_RATES]) |
| 7692 | goto out; |
| 7693 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7694 | /* |
| 7695 | * The nested attribute uses enum nl80211_band as the index. This maps |
| 7696 | * directly to the enum ieee80211_band values used in cfg80211. |
| 7697 | */ |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7698 | 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] | 7699 | 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] | 7700 | enum ieee80211_band band = nla_type(tx_rates); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7701 | int err; |
| 7702 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7703 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
| 7704 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7705 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7706 | if (sband == NULL) |
| 7707 | return -EINVAL; |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7708 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
| 7709 | nla_len(tx_rates), nl80211_txattr_policy); |
| 7710 | if (err) |
| 7711 | return err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7712 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 7713 | mask.control[band].legacy = rateset_to_mask( |
| 7714 | sband, |
| 7715 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 7716 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
Bala Shanmugam | 218d2e2 | 2012-04-20 19:12:58 +0530 | [diff] [blame] | 7717 | if ((mask.control[band].legacy == 0) && |
| 7718 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 7719 | return -EINVAL; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7720 | } |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7721 | if (tb[NL80211_TXRATE_HT]) { |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7722 | if (!ht_rateset_to_mask( |
| 7723 | sband, |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7724 | nla_data(tb[NL80211_TXRATE_HT]), |
| 7725 | nla_len(tb[NL80211_TXRATE_HT]), |
| 7726 | mask.control[band].ht_mcs)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7727 | return -EINVAL; |
| 7728 | } |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7729 | if (tb[NL80211_TXRATE_VHT]) { |
| 7730 | if (!vht_set_mcs_mask( |
| 7731 | sband, |
| 7732 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 7733 | mask.control[band].vht_mcs)) |
| 7734 | return -EINVAL; |
| 7735 | } |
Janusz Dziedzic | 0b9323f | 2014-01-08 08:46:02 +0100 | [diff] [blame] | 7736 | if (tb[NL80211_TXRATE_GI]) { |
| 7737 | mask.control[band].gi = |
| 7738 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 7739 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 7740 | return -EINVAL; |
| 7741 | } |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7742 | |
| 7743 | if (mask.control[band].legacy == 0) { |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7744 | /* don't allow empty legacy rates if HT or VHT |
| 7745 | * are not even supported. |
| 7746 | */ |
| 7747 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 7748 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7749 | return -EINVAL; |
| 7750 | |
| 7751 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 7752 | if (mask.control[band].ht_mcs[i]) |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7753 | goto out; |
| 7754 | |
| 7755 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 7756 | if (mask.control[band].vht_mcs[i]) |
| 7757 | goto out; |
Simon Wunderlich | 24db78c | 2012-01-28 17:25:32 +0100 | [diff] [blame] | 7758 | |
| 7759 | /* legacy and mcs rates may not be both empty */ |
Janusz Dziedzic | 204e35a | 2013-12-05 20:42:58 +0100 | [diff] [blame] | 7760 | return -EINVAL; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7761 | } |
| 7762 | } |
| 7763 | |
Janusz Dziedzic | b9243ab | 2013-12-05 10:02:14 +0100 | [diff] [blame] | 7764 | out: |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7765 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 7766 | } |
| 7767 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7768 | 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] | 7769 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7770 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7771 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7772 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7773 | |
| 7774 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 7775 | return -EINVAL; |
| 7776 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7777 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 7778 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7779 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7780 | switch (wdev->iftype) { |
| 7781 | case NL80211_IFTYPE_STATION: |
| 7782 | case NL80211_IFTYPE_ADHOC: |
| 7783 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7784 | case NL80211_IFTYPE_AP: |
| 7785 | case NL80211_IFTYPE_AP_VLAN: |
| 7786 | case NL80211_IFTYPE_MESH_POINT: |
| 7787 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7788 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7789 | break; |
| 7790 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7791 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7792 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7793 | |
| 7794 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7795 | if (!rdev->ops->mgmt_tx) |
| 7796 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7797 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7798 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7799 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 7800 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7801 | } |
| 7802 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 7803 | 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] | 7804 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7805 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7806 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7807 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7808 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 7809 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7810 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7811 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7812 | struct cfg80211_mgmt_tx_params params = { |
| 7813 | .dont_wait_for_ack = |
| 7814 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 7815 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7816 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 7817 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7818 | return -EINVAL; |
| 7819 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7820 | if (!rdev->ops->mgmt_tx) |
| 7821 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7822 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7823 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7824 | case NL80211_IFTYPE_P2P_DEVICE: |
| 7825 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 7826 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7827 | case NL80211_IFTYPE_STATION: |
| 7828 | case NL80211_IFTYPE_ADHOC: |
| 7829 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7830 | case NL80211_IFTYPE_AP: |
| 7831 | case NL80211_IFTYPE_AP_VLAN: |
| 7832 | case NL80211_IFTYPE_MESH_POINT: |
| 7833 | case NL80211_IFTYPE_P2P_GO: |
| 7834 | break; |
| 7835 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7836 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7837 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7838 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7839 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7840 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7841 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7842 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7843 | |
| 7844 | /* |
| 7845 | * We should wait on the channel for at least a minimum amount |
| 7846 | * of time (10ms) but no longer than the driver supports. |
| 7847 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7848 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 7849 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 7850 | return -EINVAL; |
| 7851 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7852 | } |
| 7853 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7854 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7855 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7856 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 7857 | return -EINVAL; |
| 7858 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7859 | 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] | 7860 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7861 | /* get the channel if any has been specified, otherwise pass NULL to |
| 7862 | * the driver. The latter will use the current one |
| 7863 | */ |
| 7864 | chandef.chan = NULL; |
| 7865 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 7866 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 7867 | if (err) |
| 7868 | return err; |
| 7869 | } |
| 7870 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7871 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 7872 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7873 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 7874 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 7875 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 7876 | |
| 7877 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 7878 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 7879 | int i; |
| 7880 | |
| 7881 | if (len % sizeof(u16)) |
| 7882 | return -EINVAL; |
| 7883 | |
| 7884 | params.n_csa_offsets = len / sizeof(u16); |
| 7885 | params.csa_offsets = |
| 7886 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 7887 | |
| 7888 | /* check that all the offsets fit the frame */ |
| 7889 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 7890 | if (params.csa_offsets[i] >= params.len) |
| 7891 | return -EINVAL; |
| 7892 | } |
| 7893 | } |
| 7894 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7895 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7896 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7897 | if (!msg) |
| 7898 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7899 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7900 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7901 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 7902 | if (!hdr) { |
| 7903 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7904 | goto free_msg; |
| 7905 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7906 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7907 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 7908 | params.chan = chandef.chan; |
| 7909 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7910 | if (err) |
| 7911 | goto free_msg; |
| 7912 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7913 | if (msg) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7914 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 7915 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7916 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 7917 | genlmsg_end(msg, hdr); |
| 7918 | return genlmsg_reply(msg, info); |
| 7919 | } |
| 7920 | |
| 7921 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7922 | |
| 7923 | nla_put_failure: |
| 7924 | err = -ENOBUFS; |
| 7925 | free_msg: |
| 7926 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 7927 | return err; |
| 7928 | } |
| 7929 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7930 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 7931 | { |
| 7932 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7933 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7934 | u64 cookie; |
| 7935 | |
| 7936 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 7937 | return -EINVAL; |
| 7938 | |
| 7939 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 7940 | return -EOPNOTSUPP; |
| 7941 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7942 | switch (wdev->iftype) { |
| 7943 | case NL80211_IFTYPE_STATION: |
| 7944 | case NL80211_IFTYPE_ADHOC: |
| 7945 | case NL80211_IFTYPE_P2P_CLIENT: |
| 7946 | case NL80211_IFTYPE_AP: |
| 7947 | case NL80211_IFTYPE_AP_VLAN: |
| 7948 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 7949 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7950 | break; |
| 7951 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7952 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 7953 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7954 | |
| 7955 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 7956 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7957 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 7958 | } |
| 7959 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7960 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7961 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7962 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7963 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7964 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7965 | u8 ps_state; |
| 7966 | bool state; |
| 7967 | int err; |
| 7968 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7969 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 7970 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7971 | |
| 7972 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 7973 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7974 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
| 7975 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7976 | |
| 7977 | wdev = dev->ieee80211_ptr; |
| 7978 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7979 | if (!rdev->ops->set_power_mgmt) |
| 7980 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7981 | |
| 7982 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 7983 | |
| 7984 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7985 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7986 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7987 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7988 | if (!err) |
| 7989 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7990 | return err; |
| 7991 | } |
| 7992 | |
| 7993 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 7994 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7995 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7996 | enum nl80211_ps_state ps_state; |
| 7997 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7998 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 7999 | struct sk_buff *msg; |
| 8000 | void *hdr; |
| 8001 | int err; |
| 8002 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8003 | wdev = dev->ieee80211_ptr; |
| 8004 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8005 | if (!rdev->ops->set_power_mgmt) |
| 8006 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8007 | |
| 8008 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8009 | if (!msg) |
| 8010 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8011 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8012 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8013 | NL80211_CMD_GET_POWER_SAVE); |
| 8014 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8015 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8016 | goto free_msg; |
| 8017 | } |
| 8018 | |
| 8019 | if (wdev->ps) |
| 8020 | ps_state = NL80211_PS_ENABLED; |
| 8021 | else |
| 8022 | ps_state = NL80211_PS_DISABLED; |
| 8023 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8024 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 8025 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8026 | |
| 8027 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8028 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8029 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8030 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8031 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8032 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8033 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 8034 | return err; |
| 8035 | } |
| 8036 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 8037 | static const struct nla_policy |
| 8038 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8039 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
| 8040 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 8041 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8042 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 8043 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 8044 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8045 | }; |
| 8046 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8047 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8048 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8049 | { |
| 8050 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8051 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8052 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8053 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 8054 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8055 | return -EINVAL; |
| 8056 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8057 | if (!rdev->ops->set_cqm_txe_config) |
| 8058 | return -EOPNOTSUPP; |
| 8059 | |
| 8060 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 8061 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8062 | return -EOPNOTSUPP; |
| 8063 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8064 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 8065 | } |
| 8066 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8067 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
| 8068 | s32 threshold, u32 hysteresis) |
| 8069 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8070 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8071 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8072 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8073 | |
| 8074 | if (threshold > 0) |
| 8075 | return -EINVAL; |
| 8076 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8077 | /* disabling - hysteresis should also be zero then */ |
| 8078 | if (threshold == 0) |
| 8079 | hysteresis = 0; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8080 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8081 | if (!rdev->ops->set_cqm_rssi_config) |
| 8082 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8083 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8084 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8085 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 8086 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8087 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8088 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8089 | } |
| 8090 | |
| 8091 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 8092 | { |
| 8093 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 8094 | struct nlattr *cqm; |
| 8095 | int err; |
| 8096 | |
| 8097 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8098 | if (!cqm) |
| 8099 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8100 | |
| 8101 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 8102 | nl80211_attr_cqm_policy); |
| 8103 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8104 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8105 | |
| 8106 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 8107 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8108 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 8109 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8110 | |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 8111 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
| 8112 | } |
| 8113 | |
| 8114 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 8115 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 8116 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 8117 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 8118 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 8119 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 8120 | |
| 8121 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 8122 | } |
| 8123 | |
| 8124 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 8125 | } |
| 8126 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8127 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8128 | { |
| 8129 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8130 | struct net_device *dev = info->user_ptr[1]; |
| 8131 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8132 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8133 | int err; |
| 8134 | |
| 8135 | /* start with default */ |
| 8136 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8137 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8138 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8139 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8140 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 8141 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8142 | if (err) |
| 8143 | return err; |
| 8144 | } |
| 8145 | |
| 8146 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 8147 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 8148 | return -EINVAL; |
| 8149 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8150 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8151 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 8152 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 8153 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 8154 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 8155 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 8156 | return -EINVAL; |
| 8157 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 8158 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 8159 | setup.beacon_interval = |
| 8160 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 8161 | if (setup.beacon_interval < 10 || |
| 8162 | setup.beacon_interval > 10000) |
| 8163 | return -EINVAL; |
| 8164 | } |
| 8165 | |
| 8166 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 8167 | setup.dtim_period = |
| 8168 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 8169 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 8170 | return -EINVAL; |
| 8171 | } |
| 8172 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8173 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 8174 | /* parse additional setup parameters if given */ |
| 8175 | err = nl80211_parse_mesh_setup(info, &setup); |
| 8176 | if (err) |
| 8177 | return err; |
| 8178 | } |
| 8179 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 8180 | if (setup.user_mpm) |
| 8181 | cfg.auto_open_plinks = false; |
| 8182 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8183 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8184 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 8185 | if (err) |
| 8186 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8187 | } else { |
| 8188 | /* cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 8189 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 8190 | } |
| 8191 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 8192 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 8193 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8194 | int n_rates = |
| 8195 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 8196 | struct ieee80211_supported_band *sband; |
| 8197 | |
| 8198 | if (!setup.chandef.chan) |
| 8199 | return -EINVAL; |
| 8200 | |
| 8201 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 8202 | |
| 8203 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 8204 | &setup.basic_rates); |
| 8205 | if (err) |
| 8206 | return err; |
| 8207 | } |
| 8208 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 8209 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 8210 | } |
| 8211 | |
| 8212 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 8213 | { |
| 8214 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8215 | struct net_device *dev = info->user_ptr[1]; |
| 8216 | |
| 8217 | return cfg80211_leave_mesh(rdev, dev); |
| 8218 | } |
| 8219 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8220 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8221 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 8222 | struct cfg80211_registered_device *rdev) |
| 8223 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8224 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8225 | struct nlattr *nl_pats, *nl_pat; |
| 8226 | int i, pat_len; |
| 8227 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8228 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8229 | return 0; |
| 8230 | |
| 8231 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
| 8232 | if (!nl_pats) |
| 8233 | return -ENOBUFS; |
| 8234 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8235 | for (i = 0; i < wowlan->n_patterns; i++) { |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8236 | nl_pat = nla_nest_start(msg, i + 1); |
| 8237 | if (!nl_pat) |
| 8238 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8239 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8240 | 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] | 8241 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8242 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8243 | wowlan->patterns[i].pattern) || |
| 8244 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8245 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8246 | return -ENOBUFS; |
| 8247 | nla_nest_end(msg, nl_pat); |
| 8248 | } |
| 8249 | nla_nest_end(msg, nl_pats); |
| 8250 | |
| 8251 | return 0; |
| 8252 | } |
| 8253 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8254 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 8255 | struct cfg80211_wowlan_tcp *tcp) |
| 8256 | { |
| 8257 | struct nlattr *nl_tcp; |
| 8258 | |
| 8259 | if (!tcp) |
| 8260 | return 0; |
| 8261 | |
| 8262 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
| 8263 | if (!nl_tcp) |
| 8264 | return -ENOBUFS; |
| 8265 | |
| 8266 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 8267 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
| 8268 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 8269 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 8270 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 8271 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 8272 | tcp->payload_len, tcp->payload) || |
| 8273 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 8274 | tcp->data_interval) || |
| 8275 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 8276 | tcp->wake_len, tcp->wake_data) || |
| 8277 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 8278 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 8279 | return -ENOBUFS; |
| 8280 | |
| 8281 | if (tcp->payload_seq.len && |
| 8282 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 8283 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 8284 | return -ENOBUFS; |
| 8285 | |
| 8286 | if (tcp->payload_tok.len && |
| 8287 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 8288 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 8289 | &tcp->payload_tok)) |
| 8290 | return -ENOBUFS; |
| 8291 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 8292 | nla_nest_end(msg, nl_tcp); |
| 8293 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8294 | return 0; |
| 8295 | } |
| 8296 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8297 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8298 | { |
| 8299 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8300 | struct sk_buff *msg; |
| 8301 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8302 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8303 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8304 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8305 | return -EOPNOTSUPP; |
| 8306 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8307 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8308 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8309 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 8310 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 8311 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 8312 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8313 | } |
| 8314 | |
| 8315 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8316 | if (!msg) |
| 8317 | return -ENOMEM; |
| 8318 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8319 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8320 | NL80211_CMD_GET_WOWLAN); |
| 8321 | if (!hdr) |
| 8322 | goto nla_put_failure; |
| 8323 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8324 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8325 | struct nlattr *nl_wowlan; |
| 8326 | |
| 8327 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
| 8328 | if (!nl_wowlan) |
| 8329 | goto nla_put_failure; |
| 8330 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8331 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8332 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8333 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8334 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8335 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8336 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8337 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8338 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8339 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8340 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8341 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8342 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8343 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8344 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 8345 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8346 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8347 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 8348 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8349 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8350 | if (nl80211_send_wowlan_tcp(msg, |
| 8351 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8352 | goto nla_put_failure; |
| 8353 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8354 | nla_nest_end(msg, nl_wowlan); |
| 8355 | } |
| 8356 | |
| 8357 | genlmsg_end(msg, hdr); |
| 8358 | return genlmsg_reply(msg, info); |
| 8359 | |
| 8360 | nla_put_failure: |
| 8361 | nlmsg_free(msg); |
| 8362 | return -ENOBUFS; |
| 8363 | } |
| 8364 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8365 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 8366 | struct nlattr *attr, |
| 8367 | struct cfg80211_wowlan *trig) |
| 8368 | { |
| 8369 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 8370 | struct cfg80211_wowlan_tcp *cfg; |
| 8371 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 8372 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 8373 | u32 size; |
| 8374 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 8375 | int err, port; |
| 8376 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8377 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8378 | return -EINVAL; |
| 8379 | |
| 8380 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, |
| 8381 | nla_data(attr), nla_len(attr), |
| 8382 | nl80211_wowlan_tcp_policy); |
| 8383 | if (err) |
| 8384 | return err; |
| 8385 | |
| 8386 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 8387 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 8388 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 8389 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 8390 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 8391 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 8392 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 8393 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 8394 | return -EINVAL; |
| 8395 | |
| 8396 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8397 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8398 | return -EINVAL; |
| 8399 | |
| 8400 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8401 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 8402 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8403 | return -EINVAL; |
| 8404 | |
| 8405 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8406 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8407 | return -EINVAL; |
| 8408 | |
| 8409 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 8410 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 8411 | return -EINVAL; |
| 8412 | |
| 8413 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 8414 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8415 | |
| 8416 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 8417 | tokens_size = tokln - sizeof(*tok); |
| 8418 | |
| 8419 | if (!tok->len || tokens_size % tok->len) |
| 8420 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8421 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8422 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8423 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8424 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8425 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8426 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8427 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8428 | return -EINVAL; |
| 8429 | if (tok->offset + tok->len > data_size) |
| 8430 | return -EINVAL; |
| 8431 | } |
| 8432 | |
| 8433 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 8434 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8435 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8436 | return -EINVAL; |
| 8437 | if (seq->len == 0 || seq->len > 4) |
| 8438 | return -EINVAL; |
| 8439 | if (seq->len + seq->offset > data_size) |
| 8440 | return -EINVAL; |
| 8441 | } |
| 8442 | |
| 8443 | size = sizeof(*cfg); |
| 8444 | size += data_size; |
| 8445 | size += wake_size + wake_mask_size; |
| 8446 | size += tokens_size; |
| 8447 | |
| 8448 | cfg = kzalloc(size, GFP_KERNEL); |
| 8449 | if (!cfg) |
| 8450 | return -ENOMEM; |
| 8451 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 8452 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
| 8453 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 8454 | ETH_ALEN); |
| 8455 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 8456 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 8457 | else |
| 8458 | port = 0; |
| 8459 | #ifdef CONFIG_INET |
| 8460 | /* allocate a socket and port for it and use it */ |
| 8461 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 8462 | IPPROTO_TCP, &cfg->sock, 1); |
| 8463 | if (err) { |
| 8464 | kfree(cfg); |
| 8465 | return err; |
| 8466 | } |
| 8467 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 8468 | sock_release(cfg->sock); |
| 8469 | kfree(cfg); |
| 8470 | return -EADDRINUSE; |
| 8471 | } |
| 8472 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 8473 | #else |
| 8474 | if (!port) { |
| 8475 | kfree(cfg); |
| 8476 | return -EINVAL; |
| 8477 | } |
| 8478 | cfg->src_port = port; |
| 8479 | #endif |
| 8480 | |
| 8481 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 8482 | cfg->payload_len = data_size; |
| 8483 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 8484 | memcpy((void *)cfg->payload, |
| 8485 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 8486 | data_size); |
| 8487 | if (seq) |
| 8488 | cfg->payload_seq = *seq; |
| 8489 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 8490 | cfg->wake_len = wake_size; |
| 8491 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 8492 | memcpy((void *)cfg->wake_data, |
| 8493 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 8494 | wake_size); |
| 8495 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 8496 | data_size + wake_size; |
| 8497 | memcpy((void *)cfg->wake_mask, |
| 8498 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 8499 | wake_mask_size); |
| 8500 | if (tok) { |
| 8501 | cfg->tokens_size = tokens_size; |
| 8502 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 8503 | } |
| 8504 | |
| 8505 | trig->tcp = cfg; |
| 8506 | |
| 8507 | return 0; |
| 8508 | } |
| 8509 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8510 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 8511 | { |
| 8512 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8513 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8514 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8515 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8516 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8517 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8518 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8519 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 8520 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8521 | return -EOPNOTSUPP; |
| 8522 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8523 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 8524 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8525 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8526 | goto set_wakeup; |
| 8527 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8528 | |
| 8529 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, |
| 8530 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8531 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), |
| 8532 | nl80211_wowlan_policy); |
| 8533 | if (err) |
| 8534 | return err; |
| 8535 | |
| 8536 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 8537 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 8538 | return -EINVAL; |
| 8539 | new_triggers.any = true; |
| 8540 | } |
| 8541 | |
| 8542 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 8543 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 8544 | return -EINVAL; |
| 8545 | new_triggers.disconnect = true; |
| 8546 | } |
| 8547 | |
| 8548 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 8549 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 8550 | return -EINVAL; |
| 8551 | new_triggers.magic_pkt = true; |
| 8552 | } |
| 8553 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 8554 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 8555 | return -EINVAL; |
| 8556 | |
| 8557 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 8558 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 8559 | return -EINVAL; |
| 8560 | new_triggers.gtk_rekey_failure = true; |
| 8561 | } |
| 8562 | |
| 8563 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 8564 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 8565 | return -EINVAL; |
| 8566 | new_triggers.eap_identity_req = true; |
| 8567 | } |
| 8568 | |
| 8569 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 8570 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 8571 | return -EINVAL; |
| 8572 | new_triggers.four_way_handshake = true; |
| 8573 | } |
| 8574 | |
| 8575 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 8576 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 8577 | return -EINVAL; |
| 8578 | new_triggers.rfkill_release = true; |
| 8579 | } |
| 8580 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8581 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 8582 | struct nlattr *pat; |
| 8583 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8584 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8585 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8586 | |
| 8587 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8588 | rem) |
| 8589 | n_patterns++; |
| 8590 | if (n_patterns > wowlan->n_patterns) |
| 8591 | return -EINVAL; |
| 8592 | |
| 8593 | new_triggers.patterns = kcalloc(n_patterns, |
| 8594 | sizeof(new_triggers.patterns[0]), |
| 8595 | GFP_KERNEL); |
| 8596 | if (!new_triggers.patterns) |
| 8597 | return -ENOMEM; |
| 8598 | |
| 8599 | new_triggers.n_patterns = n_patterns; |
| 8600 | i = 0; |
| 8601 | |
| 8602 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 8603 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8604 | u8 *mask_pat; |
| 8605 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8606 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8607 | nla_len(pat), NULL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8608 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8609 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8610 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8611 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8612 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8613 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8614 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8615 | goto error; |
| 8616 | if (pat_len > wowlan->pattern_max_len || |
| 8617 | pat_len < wowlan->pattern_min_len) |
| 8618 | goto error; |
| 8619 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8620 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8621 | pkt_offset = 0; |
| 8622 | else |
| 8623 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8624 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 8625 | if (pkt_offset > wowlan->max_pkt_offset) |
| 8626 | goto error; |
| 8627 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 8628 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8629 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8630 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8631 | err = -ENOMEM; |
| 8632 | goto error; |
| 8633 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8634 | new_triggers.patterns[i].mask = mask_pat; |
| 8635 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8636 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8637 | mask_pat += mask_len; |
| 8638 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8639 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8640 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 8641 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8642 | pat_len); |
| 8643 | i++; |
| 8644 | } |
| 8645 | } |
| 8646 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8647 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
| 8648 | err = nl80211_parse_wowlan_tcp( |
| 8649 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 8650 | &new_triggers); |
| 8651 | if (err) |
| 8652 | goto error; |
| 8653 | } |
| 8654 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8655 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 8656 | if (!ntrig) { |
| 8657 | err = -ENOMEM; |
| 8658 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8659 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8660 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8661 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8662 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 8663 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 8664 | if (rdev->ops->set_wakeup && |
| 8665 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 8666 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 8667 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8668 | return 0; |
| 8669 | error: |
| 8670 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 8671 | kfree(new_triggers.patterns[i].mask); |
| 8672 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 8673 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 8674 | sock_release(new_triggers.tcp->sock); |
| 8675 | kfree(new_triggers.tcp); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8676 | return err; |
| 8677 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 8678 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 8679 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8680 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 8681 | struct cfg80211_registered_device *rdev) |
| 8682 | { |
| 8683 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 8684 | int i, j, pat_len; |
| 8685 | struct cfg80211_coalesce_rules *rule; |
| 8686 | |
| 8687 | if (!rdev->coalesce->n_rules) |
| 8688 | return 0; |
| 8689 | |
| 8690 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); |
| 8691 | if (!nl_rules) |
| 8692 | return -ENOBUFS; |
| 8693 | |
| 8694 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
| 8695 | nl_rule = nla_nest_start(msg, i + 1); |
| 8696 | if (!nl_rule) |
| 8697 | return -ENOBUFS; |
| 8698 | |
| 8699 | rule = &rdev->coalesce->rules[i]; |
| 8700 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 8701 | rule->delay)) |
| 8702 | return -ENOBUFS; |
| 8703 | |
| 8704 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 8705 | rule->condition)) |
| 8706 | return -ENOBUFS; |
| 8707 | |
| 8708 | nl_pats = nla_nest_start(msg, |
| 8709 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
| 8710 | if (!nl_pats) |
| 8711 | return -ENOBUFS; |
| 8712 | |
| 8713 | for (j = 0; j < rule->n_patterns; j++) { |
| 8714 | nl_pat = nla_nest_start(msg, j + 1); |
| 8715 | if (!nl_pat) |
| 8716 | return -ENOBUFS; |
| 8717 | pat_len = rule->patterns[j].pattern_len; |
| 8718 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 8719 | DIV_ROUND_UP(pat_len, 8), |
| 8720 | rule->patterns[j].mask) || |
| 8721 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 8722 | rule->patterns[j].pattern) || |
| 8723 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 8724 | rule->patterns[j].pkt_offset)) |
| 8725 | return -ENOBUFS; |
| 8726 | nla_nest_end(msg, nl_pat); |
| 8727 | } |
| 8728 | nla_nest_end(msg, nl_pats); |
| 8729 | nla_nest_end(msg, nl_rule); |
| 8730 | } |
| 8731 | nla_nest_end(msg, nl_rules); |
| 8732 | |
| 8733 | return 0; |
| 8734 | } |
| 8735 | |
| 8736 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8737 | { |
| 8738 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8739 | struct sk_buff *msg; |
| 8740 | void *hdr; |
| 8741 | |
| 8742 | if (!rdev->wiphy.coalesce) |
| 8743 | return -EOPNOTSUPP; |
| 8744 | |
| 8745 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 8746 | if (!msg) |
| 8747 | return -ENOMEM; |
| 8748 | |
| 8749 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 8750 | NL80211_CMD_GET_COALESCE); |
| 8751 | if (!hdr) |
| 8752 | goto nla_put_failure; |
| 8753 | |
| 8754 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 8755 | goto nla_put_failure; |
| 8756 | |
| 8757 | genlmsg_end(msg, hdr); |
| 8758 | return genlmsg_reply(msg, info); |
| 8759 | |
| 8760 | nla_put_failure: |
| 8761 | nlmsg_free(msg); |
| 8762 | return -ENOBUFS; |
| 8763 | } |
| 8764 | |
| 8765 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 8766 | { |
| 8767 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 8768 | int i, j; |
| 8769 | struct cfg80211_coalesce_rules *rule; |
| 8770 | |
| 8771 | if (!coalesce) |
| 8772 | return; |
| 8773 | |
| 8774 | for (i = 0; i < coalesce->n_rules; i++) { |
| 8775 | rule = &coalesce->rules[i]; |
| 8776 | for (j = 0; j < rule->n_patterns; j++) |
| 8777 | kfree(rule->patterns[j].mask); |
| 8778 | kfree(rule->patterns); |
| 8779 | } |
| 8780 | kfree(coalesce->rules); |
| 8781 | kfree(coalesce); |
| 8782 | rdev->coalesce = NULL; |
| 8783 | } |
| 8784 | |
| 8785 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 8786 | struct nlattr *rule, |
| 8787 | struct cfg80211_coalesce_rules *new_rule) |
| 8788 | { |
| 8789 | int err, i; |
| 8790 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8791 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 8792 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 8793 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 8794 | |
| 8795 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), |
| 8796 | nla_len(rule), nl80211_coalesce_policy); |
| 8797 | if (err) |
| 8798 | return err; |
| 8799 | |
| 8800 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 8801 | new_rule->delay = |
| 8802 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 8803 | if (new_rule->delay > coalesce->max_delay) |
| 8804 | return -EINVAL; |
| 8805 | |
| 8806 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 8807 | new_rule->condition = |
| 8808 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
| 8809 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && |
| 8810 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) |
| 8811 | return -EINVAL; |
| 8812 | |
| 8813 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 8814 | return -EINVAL; |
| 8815 | |
| 8816 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8817 | rem) |
| 8818 | n_patterns++; |
| 8819 | if (n_patterns > coalesce->n_patterns) |
| 8820 | return -EINVAL; |
| 8821 | |
| 8822 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 8823 | GFP_KERNEL); |
| 8824 | if (!new_rule->patterns) |
| 8825 | return -ENOMEM; |
| 8826 | |
| 8827 | new_rule->n_patterns = n_patterns; |
| 8828 | i = 0; |
| 8829 | |
| 8830 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 8831 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8832 | u8 *mask_pat; |
| 8833 | |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8834 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
| 8835 | nla_len(pat), NULL); |
| 8836 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 8837 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 8838 | return -EINVAL; |
| 8839 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 8840 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 8841 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 8842 | return -EINVAL; |
| 8843 | if (pat_len > coalesce->pattern_max_len || |
| 8844 | pat_len < coalesce->pattern_min_len) |
| 8845 | return -EINVAL; |
| 8846 | |
| 8847 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 8848 | pkt_offset = 0; |
| 8849 | else |
| 8850 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 8851 | if (pkt_offset > coalesce->max_pkt_offset) |
| 8852 | return -EINVAL; |
| 8853 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 8854 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8855 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 8856 | if (!mask_pat) |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8857 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8858 | |
| 8859 | new_rule->patterns[i].mask = mask_pat; |
| 8860 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 8861 | mask_len); |
| 8862 | |
| 8863 | mask_pat += mask_len; |
| 8864 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8865 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 8866 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 8867 | pat_len); |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 8868 | i++; |
| 8869 | } |
| 8870 | |
| 8871 | return 0; |
| 8872 | } |
| 8873 | |
| 8874 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 8875 | { |
| 8876 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8877 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 8878 | struct cfg80211_coalesce new_coalesce = {}; |
| 8879 | struct cfg80211_coalesce *n_coalesce; |
| 8880 | int err, rem_rule, n_rules = 0, i, j; |
| 8881 | struct nlattr *rule; |
| 8882 | struct cfg80211_coalesce_rules *tmp_rule; |
| 8883 | |
| 8884 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 8885 | return -EOPNOTSUPP; |
| 8886 | |
| 8887 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 8888 | cfg80211_rdev_free_coalesce(rdev); |
| 8889 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); |
| 8890 | return 0; |
| 8891 | } |
| 8892 | |
| 8893 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8894 | rem_rule) |
| 8895 | n_rules++; |
| 8896 | if (n_rules > coalesce->n_rules) |
| 8897 | return -EINVAL; |
| 8898 | |
| 8899 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 8900 | GFP_KERNEL); |
| 8901 | if (!new_coalesce.rules) |
| 8902 | return -ENOMEM; |
| 8903 | |
| 8904 | new_coalesce.n_rules = n_rules; |
| 8905 | i = 0; |
| 8906 | |
| 8907 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 8908 | rem_rule) { |
| 8909 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 8910 | &new_coalesce.rules[i]); |
| 8911 | if (err) |
| 8912 | goto error; |
| 8913 | |
| 8914 | i++; |
| 8915 | } |
| 8916 | |
| 8917 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); |
| 8918 | if (err) |
| 8919 | goto error; |
| 8920 | |
| 8921 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 8922 | if (!n_coalesce) { |
| 8923 | err = -ENOMEM; |
| 8924 | goto error; |
| 8925 | } |
| 8926 | cfg80211_rdev_free_coalesce(rdev); |
| 8927 | rdev->coalesce = n_coalesce; |
| 8928 | |
| 8929 | return 0; |
| 8930 | error: |
| 8931 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 8932 | tmp_rule = &new_coalesce.rules[i]; |
| 8933 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 8934 | kfree(tmp_rule->patterns[j].mask); |
| 8935 | kfree(tmp_rule->patterns); |
| 8936 | } |
| 8937 | kfree(new_coalesce.rules); |
| 8938 | |
| 8939 | return err; |
| 8940 | } |
| 8941 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8942 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 8943 | { |
| 8944 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8945 | struct net_device *dev = info->user_ptr[1]; |
| 8946 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8947 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 8948 | struct cfg80211_gtk_rekey_data rekey_data; |
| 8949 | int err; |
| 8950 | |
| 8951 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 8952 | return -EINVAL; |
| 8953 | |
| 8954 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, |
| 8955 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8956 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), |
| 8957 | nl80211_rekey_policy); |
| 8958 | if (err) |
| 8959 | return err; |
| 8960 | |
| 8961 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
| 8962 | return -ERANGE; |
| 8963 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) |
| 8964 | return -ERANGE; |
| 8965 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) |
| 8966 | return -ERANGE; |
| 8967 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 8968 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 8969 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 8970 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8971 | |
| 8972 | wdev_lock(wdev); |
| 8973 | if (!wdev->current_bss) { |
| 8974 | err = -ENOTCONN; |
| 8975 | goto out; |
| 8976 | } |
| 8977 | |
| 8978 | if (!rdev->ops->set_rekey_data) { |
| 8979 | err = -EOPNOTSUPP; |
| 8980 | goto out; |
| 8981 | } |
| 8982 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8983 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 8984 | out: |
| 8985 | wdev_unlock(wdev); |
| 8986 | return err; |
| 8987 | } |
| 8988 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 8989 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 8990 | struct genl_info *info) |
| 8991 | { |
| 8992 | struct net_device *dev = info->user_ptr[1]; |
| 8993 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8994 | |
| 8995 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 8996 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 8997 | return -EINVAL; |
| 8998 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8999 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9000 | return -EBUSY; |
| 9001 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9002 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 9003 | return 0; |
| 9004 | } |
| 9005 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9006 | static int nl80211_probe_client(struct sk_buff *skb, |
| 9007 | struct genl_info *info) |
| 9008 | { |
| 9009 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9010 | struct net_device *dev = info->user_ptr[1]; |
| 9011 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9012 | struct sk_buff *msg; |
| 9013 | void *hdr; |
| 9014 | const u8 *addr; |
| 9015 | u64 cookie; |
| 9016 | int err; |
| 9017 | |
| 9018 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 9019 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 9020 | return -EOPNOTSUPP; |
| 9021 | |
| 9022 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9023 | return -EINVAL; |
| 9024 | |
| 9025 | if (!rdev->ops->probe_client) |
| 9026 | return -EOPNOTSUPP; |
| 9027 | |
| 9028 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9029 | if (!msg) |
| 9030 | return -ENOMEM; |
| 9031 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9032 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9033 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 9034 | if (!hdr) { |
| 9035 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9036 | goto free_msg; |
| 9037 | } |
| 9038 | |
| 9039 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9040 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 9041 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9042 | if (err) |
| 9043 | goto free_msg; |
| 9044 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9045 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 9046 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 9047 | |
| 9048 | genlmsg_end(msg, hdr); |
| 9049 | |
| 9050 | return genlmsg_reply(msg, info); |
| 9051 | |
| 9052 | nla_put_failure: |
| 9053 | err = -ENOBUFS; |
| 9054 | free_msg: |
| 9055 | nlmsg_free(msg); |
| 9056 | return err; |
| 9057 | } |
| 9058 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9059 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 9060 | { |
| 9061 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9062 | struct cfg80211_beacon_registration *reg, *nreg; |
| 9063 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9064 | |
| 9065 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 9066 | return -EOPNOTSUPP; |
| 9067 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9068 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 9069 | if (!nreg) |
| 9070 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9071 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9072 | /* First, check if already registered. */ |
| 9073 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 9074 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 9075 | if (reg->nlportid == info->snd_portid) { |
| 9076 | rv = -EALREADY; |
| 9077 | goto out_err; |
| 9078 | } |
| 9079 | } |
| 9080 | /* Add it to the list */ |
| 9081 | nreg->nlportid = info->snd_portid; |
| 9082 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 9083 | |
| 9084 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9085 | |
| 9086 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 9087 | out_err: |
| 9088 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 9089 | kfree(nreg); |
| 9090 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 9091 | } |
| 9092 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9093 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 9094 | { |
| 9095 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9096 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9097 | int err; |
| 9098 | |
| 9099 | if (!rdev->ops->start_p2p_device) |
| 9100 | return -EOPNOTSUPP; |
| 9101 | |
| 9102 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 9103 | return -EOPNOTSUPP; |
| 9104 | |
| 9105 | if (wdev->p2p_started) |
| 9106 | return 0; |
| 9107 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 9108 | if (rfkill_blocked(rdev->rfkill)) |
| 9109 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9110 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 9111 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9112 | if (err) |
| 9113 | return err; |
| 9114 | |
| 9115 | wdev->p2p_started = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9116 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9117 | |
| 9118 | return 0; |
| 9119 | } |
| 9120 | |
| 9121 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 9122 | { |
| 9123 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9124 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9125 | |
| 9126 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 9127 | return -EOPNOTSUPP; |
| 9128 | |
| 9129 | if (!rdev->ops->stop_p2p_device) |
| 9130 | return -EOPNOTSUPP; |
| 9131 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 9132 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9133 | |
| 9134 | return 0; |
| 9135 | } |
| 9136 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 9137 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 9138 | struct genl_info *info) |
| 9139 | { |
| 9140 | void *hdr; |
| 9141 | struct sk_buff *msg; |
| 9142 | |
| 9143 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 9144 | if (!msg) |
| 9145 | return -ENOMEM; |
| 9146 | |
| 9147 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 9148 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 9149 | if (!hdr) |
| 9150 | goto nla_put_failure; |
| 9151 | |
| 9152 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 9153 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 9154 | goto nla_put_failure; |
| 9155 | |
| 9156 | genlmsg_end(msg, hdr); |
| 9157 | return genlmsg_reply(msg, info); |
| 9158 | |
| 9159 | nla_put_failure: |
| 9160 | kfree_skb(msg); |
| 9161 | return -ENOBUFS; |
| 9162 | } |
| 9163 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 9164 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 9165 | { |
| 9166 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9167 | struct cfg80211_update_ft_ies_params ft_params; |
| 9168 | struct net_device *dev = info->user_ptr[1]; |
| 9169 | |
| 9170 | if (!rdev->ops->update_ft_ies) |
| 9171 | return -EOPNOTSUPP; |
| 9172 | |
| 9173 | if (!info->attrs[NL80211_ATTR_MDID] || |
| 9174 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 9175 | return -EINVAL; |
| 9176 | |
| 9177 | memset(&ft_params, 0, sizeof(ft_params)); |
| 9178 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 9179 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9180 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9181 | |
| 9182 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 9183 | } |
| 9184 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 9185 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 9186 | struct genl_info *info) |
| 9187 | { |
| 9188 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9189 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9190 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 9191 | u16 duration; |
| 9192 | int ret; |
| 9193 | |
| 9194 | if (!rdev->ops->crit_proto_start) |
| 9195 | return -EOPNOTSUPP; |
| 9196 | |
| 9197 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 9198 | return -EINVAL; |
| 9199 | |
| 9200 | if (rdev->crit_proto_nlportid) |
| 9201 | return -EBUSY; |
| 9202 | |
| 9203 | /* determine protocol if provided */ |
| 9204 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 9205 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 9206 | |
| 9207 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 9208 | return -EINVAL; |
| 9209 | |
| 9210 | /* timeout must be provided */ |
| 9211 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 9212 | return -EINVAL; |
| 9213 | |
| 9214 | duration = |
| 9215 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 9216 | |
| 9217 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) |
| 9218 | return -ERANGE; |
| 9219 | |
| 9220 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 9221 | if (!ret) |
| 9222 | rdev->crit_proto_nlportid = info->snd_portid; |
| 9223 | |
| 9224 | return ret; |
| 9225 | } |
| 9226 | |
| 9227 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 9228 | struct genl_info *info) |
| 9229 | { |
| 9230 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9231 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9232 | |
| 9233 | if (!rdev->ops->crit_proto_stop) |
| 9234 | return -EOPNOTSUPP; |
| 9235 | |
| 9236 | if (rdev->crit_proto_nlportid) { |
| 9237 | rdev->crit_proto_nlportid = 0; |
| 9238 | rdev_crit_proto_stop(rdev, wdev); |
| 9239 | } |
| 9240 | return 0; |
| 9241 | } |
| 9242 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9243 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 9244 | { |
| 9245 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9246 | struct wireless_dev *wdev = |
| 9247 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 9248 | int i, err; |
| 9249 | u32 vid, subcmd; |
| 9250 | |
| 9251 | if (!rdev->wiphy.vendor_commands) |
| 9252 | return -EOPNOTSUPP; |
| 9253 | |
| 9254 | if (IS_ERR(wdev)) { |
| 9255 | err = PTR_ERR(wdev); |
| 9256 | if (err != -EINVAL) |
| 9257 | return err; |
| 9258 | wdev = NULL; |
| 9259 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 9260 | return -EINVAL; |
| 9261 | } |
| 9262 | |
| 9263 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 9264 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 9265 | return -EINVAL; |
| 9266 | |
| 9267 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 9268 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 9269 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 9270 | const struct wiphy_vendor_command *vcmd; |
| 9271 | void *data = NULL; |
| 9272 | int len = 0; |
| 9273 | |
| 9274 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 9275 | |
| 9276 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 9277 | continue; |
| 9278 | |
| 9279 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 9280 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 9281 | if (!wdev) |
| 9282 | return -EINVAL; |
| 9283 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 9284 | !wdev->netdev) |
| 9285 | return -EINVAL; |
| 9286 | |
| 9287 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
| 9288 | if (wdev->netdev && |
| 9289 | !netif_running(wdev->netdev)) |
| 9290 | return -ENETDOWN; |
| 9291 | if (!wdev->netdev && !wdev->p2p_started) |
| 9292 | return -ENETDOWN; |
| 9293 | } |
| 9294 | } else { |
| 9295 | wdev = NULL; |
| 9296 | } |
| 9297 | |
| 9298 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 9299 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9300 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 9301 | } |
| 9302 | |
| 9303 | rdev->cur_cmd_info = info; |
| 9304 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, |
| 9305 | data, len); |
| 9306 | rdev->cur_cmd_info = NULL; |
| 9307 | return err; |
| 9308 | } |
| 9309 | |
| 9310 | return -EOPNOTSUPP; |
| 9311 | } |
| 9312 | |
| 9313 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 9314 | enum nl80211_commands cmd, |
| 9315 | enum nl80211_attrs attr, |
| 9316 | int approxlen) |
| 9317 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 9318 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9319 | |
| 9320 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 9321 | return NULL; |
| 9322 | |
| 9323 | return __cfg80211_alloc_vendor_skb(rdev, approxlen, |
| 9324 | rdev->cur_cmd_info->snd_portid, |
| 9325 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 9326 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9327 | } |
| 9328 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 9329 | |
| 9330 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 9331 | { |
| 9332 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 9333 | void *hdr = ((void **)skb->cb)[1]; |
| 9334 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 9335 | |
| 9336 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 9337 | kfree_skb(skb); |
| 9338 | return -EINVAL; |
| 9339 | } |
| 9340 | |
| 9341 | nla_nest_end(skb, data); |
| 9342 | genlmsg_end(skb, hdr); |
| 9343 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 9344 | } |
| 9345 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 9346 | |
| 9347 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 9348 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 9349 | struct genl_info *info) |
| 9350 | { |
| 9351 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9352 | struct cfg80211_qos_map *qos_map = NULL; |
| 9353 | struct net_device *dev = info->user_ptr[1]; |
| 9354 | u8 *pos, len, num_des, des_len, des; |
| 9355 | int ret; |
| 9356 | |
| 9357 | if (!rdev->ops->set_qos_map) |
| 9358 | return -EOPNOTSUPP; |
| 9359 | |
| 9360 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 9361 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9362 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 9363 | |
| 9364 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || |
| 9365 | len > IEEE80211_QOS_MAP_LEN_MAX) |
| 9366 | return -EINVAL; |
| 9367 | |
| 9368 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 9369 | if (!qos_map) |
| 9370 | return -ENOMEM; |
| 9371 | |
| 9372 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 9373 | if (num_des) { |
| 9374 | des_len = num_des * |
| 9375 | sizeof(struct cfg80211_dscp_exception); |
| 9376 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 9377 | qos_map->num_des = num_des; |
| 9378 | for (des = 0; des < num_des; des++) { |
| 9379 | if (qos_map->dscp_exception[des].up > 7) { |
| 9380 | kfree(qos_map); |
| 9381 | return -EINVAL; |
| 9382 | } |
| 9383 | } |
| 9384 | pos += des_len; |
| 9385 | } |
| 9386 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 9387 | } |
| 9388 | |
| 9389 | wdev_lock(dev->ieee80211_ptr); |
| 9390 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 9391 | if (!ret) |
| 9392 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 9393 | wdev_unlock(dev->ieee80211_ptr); |
| 9394 | |
| 9395 | kfree(qos_map); |
| 9396 | return ret; |
| 9397 | } |
| 9398 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 9399 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 9400 | { |
| 9401 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9402 | struct net_device *dev = info->user_ptr[1]; |
| 9403 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9404 | const u8 *peer; |
| 9405 | u8 tsid, up; |
| 9406 | u16 admitted_time = 0; |
| 9407 | int err; |
| 9408 | |
| 9409 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_WMM_ADMISSION)) |
| 9410 | return -EOPNOTSUPP; |
| 9411 | |
| 9412 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 9413 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 9414 | return -EINVAL; |
| 9415 | |
| 9416 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 9417 | if (tsid >= IEEE80211_NUM_TIDS) |
| 9418 | return -EINVAL; |
| 9419 | |
| 9420 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
| 9421 | if (up >= IEEE80211_NUM_UPS) |
| 9422 | return -EINVAL; |
| 9423 | |
| 9424 | /* WMM uses TIDs 0-7 even for TSPEC */ |
| 9425 | if (tsid < IEEE80211_FIRST_TSPEC_TSID) { |
| 9426 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_WMM_ADMISSION)) |
| 9427 | return -EINVAL; |
| 9428 | } else { |
| 9429 | /* TODO: handle 802.11 TSPEC/admission control |
| 9430 | * need more attributes for that (e.g. BA session requirement) |
| 9431 | */ |
| 9432 | return -EINVAL; |
| 9433 | } |
| 9434 | |
| 9435 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9436 | |
| 9437 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 9438 | admitted_time = |
| 9439 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 9440 | if (!admitted_time) |
| 9441 | return -EINVAL; |
| 9442 | } |
| 9443 | |
| 9444 | wdev_lock(wdev); |
| 9445 | switch (wdev->iftype) { |
| 9446 | case NL80211_IFTYPE_STATION: |
| 9447 | case NL80211_IFTYPE_P2P_CLIENT: |
| 9448 | if (wdev->current_bss) |
| 9449 | break; |
| 9450 | err = -ENOTCONN; |
| 9451 | goto out; |
| 9452 | default: |
| 9453 | err = -EOPNOTSUPP; |
| 9454 | goto out; |
| 9455 | } |
| 9456 | |
| 9457 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 9458 | |
| 9459 | out: |
| 9460 | wdev_unlock(wdev); |
| 9461 | return err; |
| 9462 | } |
| 9463 | |
| 9464 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 9465 | { |
| 9466 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9467 | struct net_device *dev = info->user_ptr[1]; |
| 9468 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9469 | const u8 *peer; |
| 9470 | u8 tsid; |
| 9471 | int err; |
| 9472 | |
| 9473 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 9474 | return -EINVAL; |
| 9475 | |
| 9476 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 9477 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 9478 | |
| 9479 | wdev_lock(wdev); |
| 9480 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 9481 | wdev_unlock(wdev); |
| 9482 | |
| 9483 | return err; |
| 9484 | } |
| 9485 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9486 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 9487 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 9488 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9489 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 9490 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 9491 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9492 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9493 | /* 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] | 9494 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 9495 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 9496 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9497 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9498 | 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] | 9499 | struct genl_info *info) |
| 9500 | { |
| 9501 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9502 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9503 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9504 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 9505 | |
| 9506 | if (rtnl) |
| 9507 | rtnl_lock(); |
| 9508 | |
| 9509 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 9510 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9511 | if (IS_ERR(rdev)) { |
| 9512 | if (rtnl) |
| 9513 | rtnl_unlock(); |
| 9514 | return PTR_ERR(rdev); |
| 9515 | } |
| 9516 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9517 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 9518 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9519 | ASSERT_RTNL(); |
| 9520 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9521 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 9522 | info->attrs); |
| 9523 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9524 | if (rtnl) |
| 9525 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9526 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9527 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9528 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9529 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 9530 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9531 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9532 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 9533 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9534 | if (rtnl) |
| 9535 | rtnl_unlock(); |
| 9536 | return -EINVAL; |
| 9537 | } |
| 9538 | |
| 9539 | info->user_ptr[1] = dev; |
| 9540 | } else { |
| 9541 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9542 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 9543 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9544 | if (dev) { |
| 9545 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 9546 | !netif_running(dev)) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9547 | if (rtnl) |
| 9548 | rtnl_unlock(); |
| 9549 | return -ENETDOWN; |
| 9550 | } |
| 9551 | |
| 9552 | dev_hold(dev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9553 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
| 9554 | if (!wdev->p2p_started) { |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 9555 | if (rtnl) |
| 9556 | rtnl_unlock(); |
| 9557 | return -ENETDOWN; |
| 9558 | } |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9559 | } |
| 9560 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9561 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9562 | } |
| 9563 | |
| 9564 | return 0; |
| 9565 | } |
| 9566 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 9567 | 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] | 9568 | struct genl_info *info) |
| 9569 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 9570 | if (info->user_ptr[1]) { |
| 9571 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 9572 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 9573 | |
| 9574 | if (wdev->netdev) |
| 9575 | dev_put(wdev->netdev); |
| 9576 | } else { |
| 9577 | dev_put(info->user_ptr[1]); |
| 9578 | } |
| 9579 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 9580 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9581 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 9582 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 9583 | |
| 9584 | /* If needed, clear the netlink message payload from the SKB |
| 9585 | * as it might contain key data that shouldn't stick around on |
| 9586 | * the heap after the SKB is freed. The netlink message header |
| 9587 | * is still needed for further processing, so leave it intact. |
| 9588 | */ |
| 9589 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 9590 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 9591 | |
| 9592 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 9593 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9594 | } |
| 9595 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 9596 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9597 | { |
| 9598 | .cmd = NL80211_CMD_GET_WIPHY, |
| 9599 | .doit = nl80211_get_wiphy, |
| 9600 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 9601 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9602 | .policy = nl80211_policy, |
| 9603 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9604 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9605 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9606 | }, |
| 9607 | { |
| 9608 | .cmd = NL80211_CMD_SET_WIPHY, |
| 9609 | .doit = nl80211_set_wiphy, |
| 9610 | .policy = nl80211_policy, |
| 9611 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9612 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9613 | }, |
| 9614 | { |
| 9615 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 9616 | .doit = nl80211_get_interface, |
| 9617 | .dumpit = nl80211_dump_interface, |
| 9618 | .policy = nl80211_policy, |
| 9619 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9620 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 9621 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9622 | }, |
| 9623 | { |
| 9624 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 9625 | .doit = nl80211_set_interface, |
| 9626 | .policy = nl80211_policy, |
| 9627 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9628 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9629 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9630 | }, |
| 9631 | { |
| 9632 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 9633 | .doit = nl80211_new_interface, |
| 9634 | .policy = nl80211_policy, |
| 9635 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9636 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9637 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9638 | }, |
| 9639 | { |
| 9640 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 9641 | .doit = nl80211_del_interface, |
| 9642 | .policy = nl80211_policy, |
| 9643 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 9644 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9645 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9646 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9647 | { |
| 9648 | .cmd = NL80211_CMD_GET_KEY, |
| 9649 | .doit = nl80211_get_key, |
| 9650 | .policy = nl80211_policy, |
| 9651 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9652 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9653 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9654 | }, |
| 9655 | { |
| 9656 | .cmd = NL80211_CMD_SET_KEY, |
| 9657 | .doit = nl80211_set_key, |
| 9658 | .policy = nl80211_policy, |
| 9659 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9660 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 9661 | NL80211_FLAG_NEED_RTNL | |
| 9662 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9663 | }, |
| 9664 | { |
| 9665 | .cmd = NL80211_CMD_NEW_KEY, |
| 9666 | .doit = nl80211_new_key, |
| 9667 | .policy = nl80211_policy, |
| 9668 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9669 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 9670 | NL80211_FLAG_NEED_RTNL | |
| 9671 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9672 | }, |
| 9673 | { |
| 9674 | .cmd = NL80211_CMD_DEL_KEY, |
| 9675 | .doit = nl80211_del_key, |
| 9676 | .policy = nl80211_policy, |
| 9677 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9678 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9679 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 9680 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9681 | { |
| 9682 | .cmd = NL80211_CMD_SET_BEACON, |
| 9683 | .policy = nl80211_policy, |
| 9684 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9685 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9686 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9687 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9688 | }, |
| 9689 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9690 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9691 | .policy = nl80211_policy, |
| 9692 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9693 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9694 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9695 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9696 | }, |
| 9697 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9698 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9699 | .policy = nl80211_policy, |
| 9700 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 9701 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9702 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9703 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 9704 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9705 | { |
| 9706 | .cmd = NL80211_CMD_GET_STATION, |
| 9707 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9708 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9709 | .policy = nl80211_policy, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9710 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9711 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9712 | }, |
| 9713 | { |
| 9714 | .cmd = NL80211_CMD_SET_STATION, |
| 9715 | .doit = nl80211_set_station, |
| 9716 | .policy = nl80211_policy, |
| 9717 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9718 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9719 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9720 | }, |
| 9721 | { |
| 9722 | .cmd = NL80211_CMD_NEW_STATION, |
| 9723 | .doit = nl80211_new_station, |
| 9724 | .policy = nl80211_policy, |
| 9725 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9726 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9727 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9728 | }, |
| 9729 | { |
| 9730 | .cmd = NL80211_CMD_DEL_STATION, |
| 9731 | .doit = nl80211_del_station, |
| 9732 | .policy = nl80211_policy, |
| 9733 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9734 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9735 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 9736 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9737 | { |
| 9738 | .cmd = NL80211_CMD_GET_MPATH, |
| 9739 | .doit = nl80211_get_mpath, |
| 9740 | .dumpit = nl80211_dump_mpath, |
| 9741 | .policy = nl80211_policy, |
| 9742 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9743 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9744 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9745 | }, |
| 9746 | { |
| 9747 | .cmd = NL80211_CMD_SET_MPATH, |
| 9748 | .doit = nl80211_set_mpath, |
| 9749 | .policy = nl80211_policy, |
| 9750 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9751 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9752 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9753 | }, |
| 9754 | { |
| 9755 | .cmd = NL80211_CMD_NEW_MPATH, |
| 9756 | .doit = nl80211_new_mpath, |
| 9757 | .policy = nl80211_policy, |
| 9758 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9759 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9760 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9761 | }, |
| 9762 | { |
| 9763 | .cmd = NL80211_CMD_DEL_MPATH, |
| 9764 | .doit = nl80211_del_mpath, |
| 9765 | .policy = nl80211_policy, |
| 9766 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9767 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9768 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 9769 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9770 | { |
| 9771 | .cmd = NL80211_CMD_SET_BSS, |
| 9772 | .doit = nl80211_set_bss, |
| 9773 | .policy = nl80211_policy, |
| 9774 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9775 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9776 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 9777 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9778 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9779 | .cmd = NL80211_CMD_GET_REG, |
| 9780 | .doit = nl80211_get_reg, |
| 9781 | .policy = nl80211_policy, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9782 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 9783 | /* can be retrieved by unprivileged users */ |
| 9784 | }, |
| 9785 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9786 | .cmd = NL80211_CMD_SET_REG, |
| 9787 | .doit = nl80211_set_reg, |
| 9788 | .policy = nl80211_policy, |
| 9789 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 9790 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 9791 | }, |
| 9792 | { |
| 9793 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 9794 | .doit = nl80211_req_set_reg, |
| 9795 | .policy = nl80211_policy, |
| 9796 | .flags = GENL_ADMIN_PERM, |
| 9797 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9798 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9799 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
| 9800 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9801 | .policy = nl80211_policy, |
| 9802 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9803 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9804 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9805 | }, |
| 9806 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 9807 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
| 9808 | .doit = nl80211_update_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9809 | .policy = nl80211_policy, |
| 9810 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 9811 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9812 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 9813 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 9814 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9815 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 9816 | .doit = nl80211_trigger_scan, |
| 9817 | .policy = nl80211_policy, |
| 9818 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 9819 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9820 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9821 | }, |
| 9822 | { |
| 9823 | .cmd = NL80211_CMD_GET_SCAN, |
| 9824 | .policy = nl80211_policy, |
| 9825 | .dumpit = nl80211_dump_scan, |
| 9826 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9827 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9828 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
| 9829 | .doit = nl80211_start_sched_scan, |
| 9830 | .policy = nl80211_policy, |
| 9831 | .flags = GENL_ADMIN_PERM, |
| 9832 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9833 | NL80211_FLAG_NEED_RTNL, |
| 9834 | }, |
| 9835 | { |
| 9836 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
| 9837 | .doit = nl80211_stop_sched_scan, |
| 9838 | .policy = nl80211_policy, |
| 9839 | .flags = GENL_ADMIN_PERM, |
| 9840 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 9841 | NL80211_FLAG_NEED_RTNL, |
| 9842 | }, |
| 9843 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9844 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 9845 | .doit = nl80211_authenticate, |
| 9846 | .policy = nl80211_policy, |
| 9847 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9848 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 9849 | NL80211_FLAG_NEED_RTNL | |
| 9850 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9851 | }, |
| 9852 | { |
| 9853 | .cmd = NL80211_CMD_ASSOCIATE, |
| 9854 | .doit = nl80211_associate, |
| 9855 | .policy = nl80211_policy, |
| 9856 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9857 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9858 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9859 | }, |
| 9860 | { |
| 9861 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 9862 | .doit = nl80211_deauthenticate, |
| 9863 | .policy = nl80211_policy, |
| 9864 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9865 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9866 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9867 | }, |
| 9868 | { |
| 9869 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 9870 | .doit = nl80211_disassociate, |
| 9871 | .policy = nl80211_policy, |
| 9872 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9873 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9874 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9875 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9876 | { |
| 9877 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 9878 | .doit = nl80211_join_ibss, |
| 9879 | .policy = nl80211_policy, |
| 9880 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9881 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9882 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9883 | }, |
| 9884 | { |
| 9885 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 9886 | .doit = nl80211_leave_ibss, |
| 9887 | .policy = nl80211_policy, |
| 9888 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9889 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9890 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9891 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9892 | #ifdef CONFIG_NL80211_TESTMODE |
| 9893 | { |
| 9894 | .cmd = NL80211_CMD_TESTMODE, |
| 9895 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 9896 | .dumpit = nl80211_testmode_dump, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9897 | .policy = nl80211_policy, |
| 9898 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9899 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9900 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 9901 | }, |
| 9902 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9903 | { |
| 9904 | .cmd = NL80211_CMD_CONNECT, |
| 9905 | .doit = nl80211_connect, |
| 9906 | .policy = nl80211_policy, |
| 9907 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9908 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9909 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9910 | }, |
| 9911 | { |
| 9912 | .cmd = NL80211_CMD_DISCONNECT, |
| 9913 | .doit = nl80211_disconnect, |
| 9914 | .policy = nl80211_policy, |
| 9915 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 9916 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9917 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9918 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9919 | { |
| 9920 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 9921 | .doit = nl80211_wiphy_netns, |
| 9922 | .policy = nl80211_policy, |
| 9923 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9924 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 9925 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 9926 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9927 | { |
| 9928 | .cmd = NL80211_CMD_GET_SURVEY, |
| 9929 | .policy = nl80211_policy, |
| 9930 | .dumpit = nl80211_dump_survey, |
| 9931 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9932 | { |
| 9933 | .cmd = NL80211_CMD_SET_PMKSA, |
| 9934 | .doit = nl80211_setdel_pmksa, |
| 9935 | .policy = nl80211_policy, |
| 9936 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9937 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9938 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9939 | }, |
| 9940 | { |
| 9941 | .cmd = NL80211_CMD_DEL_PMKSA, |
| 9942 | .doit = nl80211_setdel_pmksa, |
| 9943 | .policy = nl80211_policy, |
| 9944 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9945 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9946 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9947 | }, |
| 9948 | { |
| 9949 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
| 9950 | .doit = nl80211_flush_pmksa, |
| 9951 | .policy = nl80211_policy, |
| 9952 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 9953 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9954 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 9955 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9956 | { |
| 9957 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
| 9958 | .doit = nl80211_remain_on_channel, |
| 9959 | .policy = nl80211_policy, |
| 9960 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9961 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9962 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9963 | }, |
| 9964 | { |
| 9965 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
| 9966 | .doit = nl80211_cancel_remain_on_channel, |
| 9967 | .policy = nl80211_policy, |
| 9968 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9969 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9970 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 9971 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9972 | { |
| 9973 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
| 9974 | .doit = nl80211_set_tx_bitrate_mask, |
| 9975 | .policy = nl80211_policy, |
| 9976 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9977 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 9978 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 9979 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9980 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9981 | .cmd = NL80211_CMD_REGISTER_FRAME, |
| 9982 | .doit = nl80211_register_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9983 | .policy = nl80211_policy, |
| 9984 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9985 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9986 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9987 | }, |
| 9988 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 9989 | .cmd = NL80211_CMD_FRAME, |
| 9990 | .doit = nl80211_tx_mgmt, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9991 | .policy = nl80211_policy, |
| 9992 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 9993 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9994 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 9995 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 9996 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 9997 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
| 9998 | .doit = nl80211_tx_mgmt_cancel_wait, |
| 9999 | .policy = nl80211_policy, |
| 10000 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10001 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10002 | NL80211_FLAG_NEED_RTNL, |
| 10003 | }, |
| 10004 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10005 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
| 10006 | .doit = nl80211_set_power_save, |
| 10007 | .policy = nl80211_policy, |
| 10008 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10009 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10010 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10011 | }, |
| 10012 | { |
| 10013 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
| 10014 | .doit = nl80211_get_power_save, |
| 10015 | .policy = nl80211_policy, |
| 10016 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10017 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10018 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 10019 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10020 | { |
| 10021 | .cmd = NL80211_CMD_SET_CQM, |
| 10022 | .doit = nl80211_set_cqm, |
| 10023 | .policy = nl80211_policy, |
| 10024 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10025 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10026 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 10027 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 10028 | { |
| 10029 | .cmd = NL80211_CMD_SET_CHANNEL, |
| 10030 | .doit = nl80211_set_channel, |
| 10031 | .policy = nl80211_policy, |
| 10032 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10033 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10034 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 10035 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 10036 | { |
| 10037 | .cmd = NL80211_CMD_SET_WDS_PEER, |
| 10038 | .doit = nl80211_set_wds_peer, |
| 10039 | .policy = nl80211_policy, |
| 10040 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 10041 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10042 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 10043 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 10044 | { |
| 10045 | .cmd = NL80211_CMD_JOIN_MESH, |
| 10046 | .doit = nl80211_join_mesh, |
| 10047 | .policy = nl80211_policy, |
| 10048 | .flags = GENL_ADMIN_PERM, |
| 10049 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10050 | NL80211_FLAG_NEED_RTNL, |
| 10051 | }, |
| 10052 | { |
| 10053 | .cmd = NL80211_CMD_LEAVE_MESH, |
| 10054 | .doit = nl80211_leave_mesh, |
| 10055 | .policy = nl80211_policy, |
| 10056 | .flags = GENL_ADMIN_PERM, |
| 10057 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10058 | NL80211_FLAG_NEED_RTNL, |
| 10059 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10060 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 10061 | { |
| 10062 | .cmd = NL80211_CMD_GET_WOWLAN, |
| 10063 | .doit = nl80211_get_wowlan, |
| 10064 | .policy = nl80211_policy, |
| 10065 | /* can be retrieved by unprivileged users */ |
| 10066 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10067 | NL80211_FLAG_NEED_RTNL, |
| 10068 | }, |
| 10069 | { |
| 10070 | .cmd = NL80211_CMD_SET_WOWLAN, |
| 10071 | .doit = nl80211_set_wowlan, |
| 10072 | .policy = nl80211_policy, |
| 10073 | .flags = GENL_ADMIN_PERM, |
| 10074 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10075 | NL80211_FLAG_NEED_RTNL, |
| 10076 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 10077 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10078 | { |
| 10079 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
| 10080 | .doit = nl80211_set_rekey_data, |
| 10081 | .policy = nl80211_policy, |
| 10082 | .flags = GENL_ADMIN_PERM, |
| 10083 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 10084 | NL80211_FLAG_NEED_RTNL | |
| 10085 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 10086 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10087 | { |
| 10088 | .cmd = NL80211_CMD_TDLS_MGMT, |
| 10089 | .doit = nl80211_tdls_mgmt, |
| 10090 | .policy = nl80211_policy, |
| 10091 | .flags = GENL_ADMIN_PERM, |
| 10092 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10093 | NL80211_FLAG_NEED_RTNL, |
| 10094 | }, |
| 10095 | { |
| 10096 | .cmd = NL80211_CMD_TDLS_OPER, |
| 10097 | .doit = nl80211_tdls_oper, |
| 10098 | .policy = nl80211_policy, |
| 10099 | .flags = GENL_ADMIN_PERM, |
| 10100 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10101 | NL80211_FLAG_NEED_RTNL, |
| 10102 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 10103 | { |
| 10104 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
| 10105 | .doit = nl80211_register_unexpected_frame, |
| 10106 | .policy = nl80211_policy, |
| 10107 | .flags = GENL_ADMIN_PERM, |
| 10108 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10109 | NL80211_FLAG_NEED_RTNL, |
| 10110 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10111 | { |
| 10112 | .cmd = NL80211_CMD_PROBE_CLIENT, |
| 10113 | .doit = nl80211_probe_client, |
| 10114 | .policy = nl80211_policy, |
| 10115 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 10116 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 10117 | NL80211_FLAG_NEED_RTNL, |
| 10118 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 10119 | { |
| 10120 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
| 10121 | .doit = nl80211_register_beacons, |
| 10122 | .policy = nl80211_policy, |
| 10123 | .flags = GENL_ADMIN_PERM, |
| 10124 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10125 | NL80211_FLAG_NEED_RTNL, |
| 10126 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 10127 | { |
| 10128 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
| 10129 | .doit = nl80211_set_noack_map, |
| 10130 | .policy = nl80211_policy, |
| 10131 | .flags = GENL_ADMIN_PERM, |
| 10132 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10133 | NL80211_FLAG_NEED_RTNL, |
| 10134 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10135 | { |
| 10136 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
| 10137 | .doit = nl80211_start_p2p_device, |
| 10138 | .policy = nl80211_policy, |
| 10139 | .flags = GENL_ADMIN_PERM, |
| 10140 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 10141 | NL80211_FLAG_NEED_RTNL, |
| 10142 | }, |
| 10143 | { |
| 10144 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
| 10145 | .doit = nl80211_stop_p2p_device, |
| 10146 | .policy = nl80211_policy, |
| 10147 | .flags = GENL_ADMIN_PERM, |
| 10148 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10149 | NL80211_FLAG_NEED_RTNL, |
| 10150 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10151 | { |
| 10152 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
| 10153 | .doit = nl80211_set_mcast_rate, |
| 10154 | .policy = nl80211_policy, |
| 10155 | .flags = GENL_ADMIN_PERM, |
| 10156 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10157 | NL80211_FLAG_NEED_RTNL, |
| 10158 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 10159 | { |
| 10160 | .cmd = NL80211_CMD_SET_MAC_ACL, |
| 10161 | .doit = nl80211_set_mac_acl, |
| 10162 | .policy = nl80211_policy, |
| 10163 | .flags = GENL_ADMIN_PERM, |
| 10164 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 10165 | NL80211_FLAG_NEED_RTNL, |
| 10166 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 10167 | { |
| 10168 | .cmd = NL80211_CMD_RADAR_DETECT, |
| 10169 | .doit = nl80211_start_radar_detection, |
| 10170 | .policy = nl80211_policy, |
| 10171 | .flags = GENL_ADMIN_PERM, |
| 10172 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10173 | NL80211_FLAG_NEED_RTNL, |
| 10174 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 10175 | { |
| 10176 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
| 10177 | .doit = nl80211_get_protocol_features, |
| 10178 | .policy = nl80211_policy, |
| 10179 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 10180 | { |
| 10181 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
| 10182 | .doit = nl80211_update_ft_ies, |
| 10183 | .policy = nl80211_policy, |
| 10184 | .flags = GENL_ADMIN_PERM, |
| 10185 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10186 | NL80211_FLAG_NEED_RTNL, |
| 10187 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 10188 | { |
| 10189 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
| 10190 | .doit = nl80211_crit_protocol_start, |
| 10191 | .policy = nl80211_policy, |
| 10192 | .flags = GENL_ADMIN_PERM, |
| 10193 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10194 | NL80211_FLAG_NEED_RTNL, |
| 10195 | }, |
| 10196 | { |
| 10197 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
| 10198 | .doit = nl80211_crit_protocol_stop, |
| 10199 | .policy = nl80211_policy, |
| 10200 | .flags = GENL_ADMIN_PERM, |
| 10201 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 10202 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99 | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 10203 | }, |
| 10204 | { |
| 10205 | .cmd = NL80211_CMD_GET_COALESCE, |
| 10206 | .doit = nl80211_get_coalesce, |
| 10207 | .policy = nl80211_policy, |
| 10208 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10209 | NL80211_FLAG_NEED_RTNL, |
| 10210 | }, |
| 10211 | { |
| 10212 | .cmd = NL80211_CMD_SET_COALESCE, |
| 10213 | .doit = nl80211_set_coalesce, |
| 10214 | .policy = nl80211_policy, |
| 10215 | .flags = GENL_ADMIN_PERM, |
| 10216 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10217 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 10218 | }, |
| 10219 | { |
| 10220 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
| 10221 | .doit = nl80211_channel_switch, |
| 10222 | .policy = nl80211_policy, |
| 10223 | .flags = GENL_ADMIN_PERM, |
| 10224 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10225 | NL80211_FLAG_NEED_RTNL, |
| 10226 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10227 | { |
| 10228 | .cmd = NL80211_CMD_VENDOR, |
| 10229 | .doit = nl80211_vendor_cmd, |
| 10230 | .policy = nl80211_policy, |
| 10231 | .flags = GENL_ADMIN_PERM, |
| 10232 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 10233 | NL80211_FLAG_NEED_RTNL, |
| 10234 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 10235 | { |
| 10236 | .cmd = NL80211_CMD_SET_QOS_MAP, |
| 10237 | .doit = nl80211_set_qos_map, |
| 10238 | .policy = nl80211_policy, |
| 10239 | .flags = GENL_ADMIN_PERM, |
| 10240 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10241 | NL80211_FLAG_NEED_RTNL, |
| 10242 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 10243 | { |
| 10244 | .cmd = NL80211_CMD_ADD_TX_TS, |
| 10245 | .doit = nl80211_add_tx_ts, |
| 10246 | .policy = nl80211_policy, |
| 10247 | .flags = GENL_ADMIN_PERM, |
| 10248 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10249 | NL80211_FLAG_NEED_RTNL, |
| 10250 | }, |
| 10251 | { |
| 10252 | .cmd = NL80211_CMD_DEL_TX_TS, |
| 10253 | .doit = nl80211_del_tx_ts, |
| 10254 | .policy = nl80211_policy, |
| 10255 | .flags = GENL_ADMIN_PERM, |
| 10256 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 10257 | NL80211_FLAG_NEED_RTNL, |
| 10258 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10259 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10260 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10261 | /* notification functions */ |
| 10262 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10263 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 10264 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10265 | { |
| 10266 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 10267 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10268 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10269 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 10270 | cmd != NL80211_CMD_DEL_WIPHY); |
| 10271 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10272 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10273 | if (!msg) |
| 10274 | return; |
| 10275 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 10276 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10277 | nlmsg_free(msg); |
| 10278 | return; |
| 10279 | } |
| 10280 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10281 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10282 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10283 | } |
| 10284 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10285 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 10286 | struct cfg80211_registered_device *rdev) |
| 10287 | { |
| 10288 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 10289 | struct nlattr *nest; |
| 10290 | int i; |
| 10291 | |
| 10292 | if (WARN_ON(!req)) |
| 10293 | return 0; |
| 10294 | |
| 10295 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 10296 | if (!nest) |
| 10297 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10298 | for (i = 0; i < req->n_ssids; i++) { |
| 10299 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 10300 | goto nla_put_failure; |
| 10301 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10302 | nla_nest_end(msg, nest); |
| 10303 | |
| 10304 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 10305 | if (!nest) |
| 10306 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10307 | for (i = 0; i < req->n_channels; i++) { |
| 10308 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 10309 | goto nla_put_failure; |
| 10310 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10311 | nla_nest_end(msg, nest); |
| 10312 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10313 | if (req->ie && |
| 10314 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 10315 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10316 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 10317 | if (req->flags && |
| 10318 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 10319 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 10320 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10321 | return 0; |
| 10322 | nla_put_failure: |
| 10323 | return -ENOBUFS; |
| 10324 | } |
| 10325 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10326 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 10327 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10328 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10329 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10330 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10331 | { |
| 10332 | void *hdr; |
| 10333 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10334 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10335 | if (!hdr) |
| 10336 | return -1; |
| 10337 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10338 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10339 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10340 | wdev->netdev->ifindex)) || |
| 10341 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10342 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10343 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 10344 | /* ignore errors and send incomplete event anyway */ |
| 10345 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10346 | |
| 10347 | return genlmsg_end(msg, hdr); |
| 10348 | |
| 10349 | nla_put_failure: |
| 10350 | genlmsg_cancel(msg, hdr); |
| 10351 | return -EMSGSIZE; |
| 10352 | } |
| 10353 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10354 | static int |
| 10355 | nl80211_send_sched_scan_msg(struct sk_buff *msg, |
| 10356 | struct cfg80211_registered_device *rdev, |
| 10357 | struct net_device *netdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10358 | u32 portid, u32 seq, int flags, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10359 | { |
| 10360 | void *hdr; |
| 10361 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10362 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10363 | if (!hdr) |
| 10364 | return -1; |
| 10365 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10366 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10367 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 10368 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10369 | |
| 10370 | return genlmsg_end(msg, hdr); |
| 10371 | |
| 10372 | nla_put_failure: |
| 10373 | genlmsg_cancel(msg, hdr); |
| 10374 | return -EMSGSIZE; |
| 10375 | } |
| 10376 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10377 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10378 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10379 | { |
| 10380 | struct sk_buff *msg; |
| 10381 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10382 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10383 | if (!msg) |
| 10384 | return; |
| 10385 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10386 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10387 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 10388 | nlmsg_free(msg); |
| 10389 | return; |
| 10390 | } |
| 10391 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10392 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10393 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 10394 | } |
| 10395 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10396 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 10397 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10398 | { |
| 10399 | struct sk_buff *msg; |
| 10400 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10401 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10402 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10403 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10404 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 10405 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10406 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 10407 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10408 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10409 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10410 | } |
| 10411 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10412 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10413 | } |
| 10414 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 10415 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
| 10416 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10417 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10418 | if (!msg) |
| 10419 | return; |
| 10420 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10421 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10422 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 10423 | } |
| 10424 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10425 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
| 10426 | struct net_device *netdev) |
| 10427 | { |
| 10428 | struct sk_buff *msg; |
| 10429 | |
| 10430 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10431 | if (!msg) |
| 10432 | return; |
| 10433 | |
| 10434 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 10435 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { |
| 10436 | nlmsg_free(msg); |
| 10437 | return; |
| 10438 | } |
| 10439 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10440 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10441 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10442 | } |
| 10443 | |
| 10444 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, |
| 10445 | struct net_device *netdev, u32 cmd) |
| 10446 | { |
| 10447 | struct sk_buff *msg; |
| 10448 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10449 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10450 | if (!msg) |
| 10451 | return; |
| 10452 | |
| 10453 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { |
| 10454 | nlmsg_free(msg); |
| 10455 | return; |
| 10456 | } |
| 10457 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10458 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10459 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 10460 | } |
| 10461 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10462 | /* |
| 10463 | * This can happen on global regulatory changes or device specific settings |
| 10464 | * based on custom world regulatory domains. |
| 10465 | */ |
| 10466 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 10467 | { |
| 10468 | struct sk_buff *msg; |
| 10469 | void *hdr; |
| 10470 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10471 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10472 | if (!msg) |
| 10473 | return; |
| 10474 | |
| 10475 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 10476 | if (!hdr) { |
| 10477 | nlmsg_free(msg); |
| 10478 | return; |
| 10479 | } |
| 10480 | |
| 10481 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10482 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 10483 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10484 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10485 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 10486 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10487 | NL80211_REGDOM_TYPE_WORLD)) |
| 10488 | goto nla_put_failure; |
| 10489 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 10490 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10491 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 10492 | goto nla_put_failure; |
| 10493 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 10494 | request->intersect) { |
| 10495 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10496 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 10497 | goto nla_put_failure; |
| 10498 | } else { |
| 10499 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 10500 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 10501 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 10502 | request->alpha2)) |
| 10503 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10504 | } |
| 10505 | |
Johannes Berg | f417376 | 2012-12-03 18:23:37 +0100 | [diff] [blame] | 10506 | if (request->wiphy_idx != WIPHY_IDX_INVALID && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10507 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 10508 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10509 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10510 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10511 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10512 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10513 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10514 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 10515 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 10516 | |
| 10517 | return; |
| 10518 | |
| 10519 | nla_put_failure: |
| 10520 | genlmsg_cancel(msg, hdr); |
| 10521 | nlmsg_free(msg); |
| 10522 | } |
| 10523 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10524 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 10525 | struct net_device *netdev, |
| 10526 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame^] | 10527 | enum nl80211_commands cmd, gfp_t gfp, |
| 10528 | int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10529 | { |
| 10530 | struct sk_buff *msg; |
| 10531 | void *hdr; |
| 10532 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10533 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10534 | if (!msg) |
| 10535 | return; |
| 10536 | |
| 10537 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10538 | if (!hdr) { |
| 10539 | nlmsg_free(msg); |
| 10540 | return; |
| 10541 | } |
| 10542 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10543 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10544 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10545 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) |
| 10546 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10547 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame^] | 10548 | if (uapsd_queues >= 0) { |
| 10549 | struct nlattr *nla_wmm = |
| 10550 | nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 10551 | if (!nla_wmm) |
| 10552 | goto nla_put_failure; |
| 10553 | |
| 10554 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 10555 | uapsd_queues)) |
| 10556 | goto nla_put_failure; |
| 10557 | |
| 10558 | nla_nest_end(msg, nla_wmm); |
| 10559 | } |
| 10560 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10561 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10562 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10563 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10564 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10565 | return; |
| 10566 | |
| 10567 | nla_put_failure: |
| 10568 | genlmsg_cancel(msg, hdr); |
| 10569 | nlmsg_free(msg); |
| 10570 | } |
| 10571 | |
| 10572 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10573 | struct net_device *netdev, const u8 *buf, |
| 10574 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10575 | { |
| 10576 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame^] | 10577 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10578 | } |
| 10579 | |
| 10580 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 10581 | struct net_device *netdev, const u8 *buf, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame^] | 10582 | size_t len, gfp_t gfp, int uapsd_queues) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10583 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10584 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame^] | 10585 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10586 | } |
| 10587 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10588 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10589 | struct net_device *netdev, const u8 *buf, |
| 10590 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10591 | { |
| 10592 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame^] | 10593 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10594 | } |
| 10595 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 10596 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 10597 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10598 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10599 | { |
| 10600 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame^] | 10601 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 10602 | } |
| 10603 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10604 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 10605 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10606 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10607 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 10608 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10609 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10610 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 10611 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10612 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10613 | if (WARN_ON(len < 2)) |
| 10614 | return; |
| 10615 | |
| 10616 | if (ieee80211_is_deauth(mgmt->frame_control)) |
| 10617 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
| 10618 | else |
| 10619 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
| 10620 | |
| 10621 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame^] | 10622 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10623 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 10624 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 10625 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 10626 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 10627 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10628 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10629 | { |
| 10630 | struct sk_buff *msg; |
| 10631 | void *hdr; |
| 10632 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10633 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10634 | if (!msg) |
| 10635 | return; |
| 10636 | |
| 10637 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10638 | if (!hdr) { |
| 10639 | nlmsg_free(msg); |
| 10640 | return; |
| 10641 | } |
| 10642 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10643 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10644 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10645 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 10646 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 10647 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10648 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10649 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10650 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10651 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10652 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10653 | return; |
| 10654 | |
| 10655 | nla_put_failure: |
| 10656 | genlmsg_cancel(msg, hdr); |
| 10657 | nlmsg_free(msg); |
| 10658 | } |
| 10659 | |
| 10660 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10661 | struct net_device *netdev, const u8 *addr, |
| 10662 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10663 | { |
| 10664 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10665 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10666 | } |
| 10667 | |
| 10668 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10669 | struct net_device *netdev, const u8 *addr, |
| 10670 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10671 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10672 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 10673 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 10674 | } |
| 10675 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10676 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 10677 | struct net_device *netdev, const u8 *bssid, |
| 10678 | const u8 *req_ie, size_t req_ie_len, |
| 10679 | const u8 *resp_ie, size_t resp_ie_len, |
| 10680 | u16 status, gfp_t gfp) |
| 10681 | { |
| 10682 | struct sk_buff *msg; |
| 10683 | void *hdr; |
| 10684 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10685 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10686 | if (!msg) |
| 10687 | return; |
| 10688 | |
| 10689 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 10690 | if (!hdr) { |
| 10691 | nlmsg_free(msg); |
| 10692 | return; |
| 10693 | } |
| 10694 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10695 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10696 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10697 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || |
| 10698 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || |
| 10699 | (req_ie && |
| 10700 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10701 | (resp_ie && |
| 10702 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10703 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10704 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10705 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10706 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10707 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10708 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10709 | return; |
| 10710 | |
| 10711 | nla_put_failure: |
| 10712 | genlmsg_cancel(msg, hdr); |
| 10713 | nlmsg_free(msg); |
| 10714 | |
| 10715 | } |
| 10716 | |
| 10717 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 10718 | struct net_device *netdev, const u8 *bssid, |
| 10719 | const u8 *req_ie, size_t req_ie_len, |
| 10720 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 10721 | { |
| 10722 | struct sk_buff *msg; |
| 10723 | void *hdr; |
| 10724 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10725 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10726 | if (!msg) |
| 10727 | return; |
| 10728 | |
| 10729 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 10730 | if (!hdr) { |
| 10731 | nlmsg_free(msg); |
| 10732 | return; |
| 10733 | } |
| 10734 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10735 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10736 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10737 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
| 10738 | (req_ie && |
| 10739 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || |
| 10740 | (resp_ie && |
| 10741 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) |
| 10742 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10743 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10744 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10745 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10746 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10747 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10748 | return; |
| 10749 | |
| 10750 | nla_put_failure: |
| 10751 | genlmsg_cancel(msg, hdr); |
| 10752 | nlmsg_free(msg); |
| 10753 | |
| 10754 | } |
| 10755 | |
| 10756 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 10757 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503dd | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 10758 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10759 | { |
| 10760 | struct sk_buff *msg; |
| 10761 | void *hdr; |
| 10762 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 10763 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10764 | if (!msg) |
| 10765 | return; |
| 10766 | |
| 10767 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 10768 | if (!hdr) { |
| 10769 | nlmsg_free(msg); |
| 10770 | return; |
| 10771 | } |
| 10772 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10773 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10774 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10775 | (from_ap && reason && |
| 10776 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 10777 | (from_ap && |
| 10778 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 10779 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 10780 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10781 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10782 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10783 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10784 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10785 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10786 | return; |
| 10787 | |
| 10788 | nla_put_failure: |
| 10789 | genlmsg_cancel(msg, hdr); |
| 10790 | nlmsg_free(msg); |
| 10791 | |
| 10792 | } |
| 10793 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10794 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 10795 | struct net_device *netdev, const u8 *bssid, |
| 10796 | gfp_t gfp) |
| 10797 | { |
| 10798 | struct sk_buff *msg; |
| 10799 | void *hdr; |
| 10800 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10801 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10802 | if (!msg) |
| 10803 | return; |
| 10804 | |
| 10805 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 10806 | if (!hdr) { |
| 10807 | nlmsg_free(msg); |
| 10808 | return; |
| 10809 | } |
| 10810 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10811 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10812 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10813 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 10814 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10815 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10816 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10817 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10818 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10819 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10820 | return; |
| 10821 | |
| 10822 | nla_put_failure: |
| 10823 | genlmsg_cancel(msg, hdr); |
| 10824 | nlmsg_free(msg); |
| 10825 | } |
| 10826 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10827 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
| 10828 | const u8* ie, u8 ie_len, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10829 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10830 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10831 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10832 | struct sk_buff *msg; |
| 10833 | void *hdr; |
| 10834 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10835 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 10836 | return; |
| 10837 | |
| 10838 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 10839 | |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10840 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10841 | if (!msg) |
| 10842 | return; |
| 10843 | |
| 10844 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 10845 | if (!hdr) { |
| 10846 | nlmsg_free(msg); |
| 10847 | return; |
| 10848 | } |
| 10849 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10850 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10851 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 10852 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10853 | (ie_len && ie && |
| 10854 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) |
| 10855 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10856 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10857 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10858 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10859 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10860 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10861 | return; |
| 10862 | |
| 10863 | nla_put_failure: |
| 10864 | genlmsg_cancel(msg, hdr); |
| 10865 | nlmsg_free(msg); |
| 10866 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 10867 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 10868 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10869 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 10870 | struct net_device *netdev, const u8 *addr, |
| 10871 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10872 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10873 | { |
| 10874 | struct sk_buff *msg; |
| 10875 | void *hdr; |
| 10876 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 10877 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10878 | if (!msg) |
| 10879 | return; |
| 10880 | |
| 10881 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 10882 | if (!hdr) { |
| 10883 | nlmsg_free(msg); |
| 10884 | return; |
| 10885 | } |
| 10886 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10887 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 10888 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 10889 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 10890 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 10891 | (key_id != -1 && |
| 10892 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 10893 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 10894 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10895 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10896 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10897 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10898 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10899 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 10900 | return; |
| 10901 | |
| 10902 | nla_put_failure: |
| 10903 | genlmsg_cancel(msg, hdr); |
| 10904 | nlmsg_free(msg); |
| 10905 | } |
| 10906 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10907 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 10908 | struct ieee80211_channel *channel_before, |
| 10909 | struct ieee80211_channel *channel_after) |
| 10910 | { |
| 10911 | struct sk_buff *msg; |
| 10912 | void *hdr; |
| 10913 | struct nlattr *nl_freq; |
| 10914 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 10915 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10916 | if (!msg) |
| 10917 | return; |
| 10918 | |
| 10919 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 10920 | if (!hdr) { |
| 10921 | nlmsg_free(msg); |
| 10922 | return; |
| 10923 | } |
| 10924 | |
| 10925 | /* |
| 10926 | * Since we are applying the beacon hint to a wiphy we know its |
| 10927 | * wiphy_idx is valid |
| 10928 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10929 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 10930 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10931 | |
| 10932 | /* Before */ |
| 10933 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 10934 | if (!nl_freq) |
| 10935 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10936 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10937 | goto nla_put_failure; |
| 10938 | nla_nest_end(msg, nl_freq); |
| 10939 | |
| 10940 | /* After */ |
| 10941 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 10942 | if (!nl_freq) |
| 10943 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 10944 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10945 | goto nla_put_failure; |
| 10946 | nla_nest_end(msg, nl_freq); |
| 10947 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10948 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10949 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10950 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10951 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10952 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10953 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 10954 | |
| 10955 | return; |
| 10956 | |
| 10957 | nla_put_failure: |
| 10958 | genlmsg_cancel(msg, hdr); |
| 10959 | nlmsg_free(msg); |
| 10960 | } |
| 10961 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10962 | static void nl80211_send_remain_on_chan_event( |
| 10963 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10964 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10965 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10966 | unsigned int duration, gfp_t gfp) |
| 10967 | { |
| 10968 | struct sk_buff *msg; |
| 10969 | void *hdr; |
| 10970 | |
| 10971 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 10972 | if (!msg) |
| 10973 | return; |
| 10974 | |
| 10975 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 10976 | if (!hdr) { |
| 10977 | nlmsg_free(msg); |
| 10978 | return; |
| 10979 | } |
| 10980 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10981 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10982 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 10983 | wdev->netdev->ifindex)) || |
Johannes Berg | 00f5335 | 2012-07-17 11:53:12 +0200 | [diff] [blame] | 10984 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10985 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 10986 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 10987 | NL80211_CHAN_NO_HT) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10988 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
| 10989 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10990 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10991 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 10992 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 10993 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10994 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 10995 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10996 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 10997 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 10998 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10999 | return; |
| 11000 | |
| 11001 | nla_put_failure: |
| 11002 | genlmsg_cancel(msg, hdr); |
| 11003 | nlmsg_free(msg); |
| 11004 | } |
| 11005 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11006 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 11007 | struct ieee80211_channel *chan, |
| 11008 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11009 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11010 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11011 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11012 | |
| 11013 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11014 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11015 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11016 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11017 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11018 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11019 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11020 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 11021 | struct ieee80211_channel *chan, |
| 11022 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11023 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11024 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11025 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11026 | |
| 11027 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11028 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 11029 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11030 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11031 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11032 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11033 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 11034 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11035 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11036 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11037 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11038 | struct sk_buff *msg; |
| 11039 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11040 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 11041 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11042 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11043 | if (!msg) |
| 11044 | return; |
| 11045 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 11046 | if (nl80211_send_station(msg, 0, 0, 0, |
| 11047 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11048 | nlmsg_free(msg); |
| 11049 | return; |
| 11050 | } |
| 11051 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11052 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11053 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11054 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11055 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 11056 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11057 | 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] | 11058 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11059 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11060 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11061 | struct sk_buff *msg; |
| 11062 | void *hdr; |
| 11063 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11064 | trace_cfg80211_del_sta(dev, mac_addr); |
| 11065 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11066 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11067 | if (!msg) |
| 11068 | return; |
| 11069 | |
| 11070 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); |
| 11071 | if (!hdr) { |
| 11072 | nlmsg_free(msg); |
| 11073 | return; |
| 11074 | } |
| 11075 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11076 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11077 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 11078 | goto nla_put_failure; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11079 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11080 | genlmsg_end(msg, hdr); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11081 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11082 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11083 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11084 | return; |
| 11085 | |
| 11086 | nla_put_failure: |
| 11087 | genlmsg_cancel(msg, hdr); |
| 11088 | nlmsg_free(msg); |
| 11089 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11090 | EXPORT_SYMBOL(cfg80211_del_sta); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 11091 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11092 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 11093 | enum nl80211_connect_failed_reason reason, |
| 11094 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11095 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11096 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11097 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11098 | struct sk_buff *msg; |
| 11099 | void *hdr; |
| 11100 | |
| 11101 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 11102 | if (!msg) |
| 11103 | return; |
| 11104 | |
| 11105 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 11106 | if (!hdr) { |
| 11107 | nlmsg_free(msg); |
| 11108 | return; |
| 11109 | } |
| 11110 | |
| 11111 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11112 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 11113 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 11114 | goto nla_put_failure; |
| 11115 | |
| 11116 | genlmsg_end(msg, hdr); |
| 11117 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11118 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11119 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11120 | return; |
| 11121 | |
| 11122 | nla_put_failure: |
| 11123 | genlmsg_cancel(msg, hdr); |
| 11124 | nlmsg_free(msg); |
| 11125 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11126 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 11127 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11128 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 11129 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11130 | { |
| 11131 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11132 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11133 | struct sk_buff *msg; |
| 11134 | void *hdr; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11135 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11136 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11137 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11138 | return false; |
| 11139 | |
| 11140 | msg = nlmsg_new(100, gfp); |
| 11141 | if (!msg) |
| 11142 | return true; |
| 11143 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11144 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11145 | if (!hdr) { |
| 11146 | nlmsg_free(msg); |
| 11147 | return true; |
| 11148 | } |
| 11149 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11150 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11151 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11152 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 11153 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11154 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11155 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11156 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 11157 | return true; |
| 11158 | |
| 11159 | nla_put_failure: |
| 11160 | genlmsg_cancel(msg, hdr); |
| 11161 | nlmsg_free(msg); |
| 11162 | return true; |
| 11163 | } |
| 11164 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11165 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 11166 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11167 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11168 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11169 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11170 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11171 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 11172 | |
| 11173 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 11174 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 11175 | trace_cfg80211_return_bool(false); |
| 11176 | return false; |
| 11177 | } |
| 11178 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 11179 | addr, gfp); |
| 11180 | trace_cfg80211_return_bool(ret); |
| 11181 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11182 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11183 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 11184 | |
| 11185 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 11186 | const u8 *addr, gfp_t gfp) |
| 11187 | { |
| 11188 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11189 | bool ret; |
| 11190 | |
| 11191 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 11192 | |
| 11193 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 11194 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 11195 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 11196 | trace_cfg80211_return_bool(false); |
| 11197 | return false; |
| 11198 | } |
| 11199 | ret = __nl80211_unexpected_frame(dev, |
| 11200 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 11201 | addr, gfp); |
| 11202 | trace_cfg80211_return_bool(ret); |
| 11203 | return ret; |
| 11204 | } |
| 11205 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 11206 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11207 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11208 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 11209 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 11210 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11211 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11212 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11213 | struct sk_buff *msg; |
| 11214 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11215 | |
| 11216 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11217 | if (!msg) |
| 11218 | return -ENOMEM; |
| 11219 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11220 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11221 | if (!hdr) { |
| 11222 | nlmsg_free(msg); |
| 11223 | return -ENOMEM; |
| 11224 | } |
| 11225 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11226 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11227 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11228 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 11229 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11230 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 11231 | (sig_dbm && |
| 11232 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 11233 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 11234 | (flags && |
| 11235 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11236 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11237 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11238 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11239 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11240 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11241 | |
| 11242 | nla_put_failure: |
| 11243 | genlmsg_cancel(msg, hdr); |
| 11244 | nlmsg_free(msg); |
| 11245 | return -ENOBUFS; |
| 11246 | } |
| 11247 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11248 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 11249 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11250 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11251 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11252 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11253 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11254 | struct sk_buff *msg; |
| 11255 | void *hdr; |
| 11256 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11257 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 11258 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11259 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11260 | if (!msg) |
| 11261 | return; |
| 11262 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11263 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11264 | if (!hdr) { |
| 11265 | nlmsg_free(msg); |
| 11266 | return; |
| 11267 | } |
| 11268 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11269 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11270 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11271 | netdev->ifindex)) || |
Ilan Peer | a838490 | 2013-05-08 16:35:55 +0300 | [diff] [blame] | 11272 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11273 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 11274 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11275 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11276 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11277 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11278 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11279 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11280 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11281 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11282 | return; |
| 11283 | |
| 11284 | nla_put_failure: |
| 11285 | genlmsg_cancel(msg, hdr); |
| 11286 | nlmsg_free(msg); |
| 11287 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11288 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11289 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11290 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 11291 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 11292 | gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11293 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11294 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11295 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11296 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11297 | struct sk_buff *msg; |
| 11298 | struct nlattr *pinfoattr; |
| 11299 | void *hdr; |
| 11300 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11301 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); |
| 11302 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11303 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11304 | if (!msg) |
| 11305 | return; |
| 11306 | |
| 11307 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11308 | if (!hdr) { |
| 11309 | nlmsg_free(msg); |
| 11310 | return; |
| 11311 | } |
| 11312 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11313 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11314 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11315 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11316 | |
| 11317 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11318 | if (!pinfoattr) |
| 11319 | goto nla_put_failure; |
| 11320 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11321 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 11322 | rssi_event)) |
| 11323 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11324 | |
| 11325 | nla_nest_end(msg, pinfoattr); |
| 11326 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11327 | genlmsg_end(msg, hdr); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11328 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11329 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11330 | NL80211_MCGRP_MLME, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11331 | return; |
| 11332 | |
| 11333 | nla_put_failure: |
| 11334 | genlmsg_cancel(msg, hdr); |
| 11335 | nlmsg_free(msg); |
| 11336 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11337 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11338 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11339 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 11340 | struct net_device *netdev, const u8 *bssid, |
| 11341 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11342 | { |
| 11343 | struct sk_buff *msg; |
| 11344 | struct nlattr *rekey_attr; |
| 11345 | void *hdr; |
| 11346 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11347 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11348 | if (!msg) |
| 11349 | return; |
| 11350 | |
| 11351 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 11352 | if (!hdr) { |
| 11353 | nlmsg_free(msg); |
| 11354 | return; |
| 11355 | } |
| 11356 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11357 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11358 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11359 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 11360 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11361 | |
| 11362 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); |
| 11363 | if (!rekey_attr) |
| 11364 | goto nla_put_failure; |
| 11365 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11366 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 11367 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 11368 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11369 | |
| 11370 | nla_nest_end(msg, rekey_attr); |
| 11371 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11372 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11373 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11374 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11375 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 11376 | return; |
| 11377 | |
| 11378 | nla_put_failure: |
| 11379 | genlmsg_cancel(msg, hdr); |
| 11380 | nlmsg_free(msg); |
| 11381 | } |
| 11382 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11383 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 11384 | const u8 *replay_ctr, gfp_t gfp) |
| 11385 | { |
| 11386 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11387 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11388 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11389 | |
| 11390 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 11391 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 11392 | } |
| 11393 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 11394 | |
| 11395 | static void |
| 11396 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 11397 | struct net_device *netdev, int index, |
| 11398 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11399 | { |
| 11400 | struct sk_buff *msg; |
| 11401 | struct nlattr *attr; |
| 11402 | void *hdr; |
| 11403 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11404 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11405 | if (!msg) |
| 11406 | return; |
| 11407 | |
| 11408 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 11409 | if (!hdr) { |
| 11410 | nlmsg_free(msg); |
| 11411 | return; |
| 11412 | } |
| 11413 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11414 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11415 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11416 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11417 | |
| 11418 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
| 11419 | if (!attr) |
| 11420 | goto nla_put_failure; |
| 11421 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11422 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 11423 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 11424 | (preauth && |
| 11425 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 11426 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11427 | |
| 11428 | nla_nest_end(msg, attr); |
| 11429 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11430 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11431 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11432 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11433 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 11434 | return; |
| 11435 | |
| 11436 | nla_put_failure: |
| 11437 | genlmsg_cancel(msg, hdr); |
| 11438 | nlmsg_free(msg); |
| 11439 | } |
| 11440 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11441 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 11442 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 11443 | { |
| 11444 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11445 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11446 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11447 | |
| 11448 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 11449 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 11450 | } |
| 11451 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 11452 | |
| 11453 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 11454 | struct net_device *netdev, |
| 11455 | struct cfg80211_chan_def *chandef, |
| 11456 | gfp_t gfp) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11457 | { |
| 11458 | struct sk_buff *msg; |
| 11459 | void *hdr; |
| 11460 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11461 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11462 | if (!msg) |
| 11463 | return; |
| 11464 | |
| 11465 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); |
| 11466 | if (!hdr) { |
| 11467 | nlmsg_free(msg); |
| 11468 | return; |
| 11469 | } |
| 11470 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11471 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 11472 | goto nla_put_failure; |
| 11473 | |
| 11474 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 11475 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11476 | |
| 11477 | genlmsg_end(msg, hdr); |
| 11478 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11479 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11480 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 11481 | return; |
| 11482 | |
| 11483 | nla_put_failure: |
| 11484 | genlmsg_cancel(msg, hdr); |
| 11485 | nlmsg_free(msg); |
| 11486 | } |
| 11487 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11488 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 11489 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11490 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11491 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11492 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11493 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11494 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11495 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11496 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11497 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11498 | |
| 11499 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 11500 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
Chun-Yeow Yeoh | b8456a1 | 2013-10-17 15:55:02 -0700 | [diff] [blame] | 11501 | wdev->iftype != NL80211_IFTYPE_ADHOC && |
| 11502 | wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 11503 | return; |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11504 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 11505 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 11506 | wdev->preset_chandef = *chandef; |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11507 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11508 | } |
| 11509 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 11510 | |
| 11511 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 11512 | const u8 *peer, u32 num_packets, |
| 11513 | u32 rate, u32 intvl, gfp_t gfp) |
| 11514 | { |
| 11515 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11516 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11517 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11518 | struct sk_buff *msg; |
| 11519 | struct nlattr *pinfoattr; |
| 11520 | void *hdr; |
| 11521 | |
| 11522 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 11523 | if (!msg) |
| 11524 | return; |
| 11525 | |
| 11526 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11527 | if (!hdr) { |
| 11528 | nlmsg_free(msg); |
| 11529 | return; |
| 11530 | } |
| 11531 | |
| 11532 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11533 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11534 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11535 | goto nla_put_failure; |
| 11536 | |
| 11537 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11538 | if (!pinfoattr) |
| 11539 | goto nla_put_failure; |
| 11540 | |
| 11541 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 11542 | goto nla_put_failure; |
| 11543 | |
| 11544 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 11545 | goto nla_put_failure; |
| 11546 | |
| 11547 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 11548 | goto nla_put_failure; |
| 11549 | |
| 11550 | nla_nest_end(msg, pinfoattr); |
| 11551 | |
| 11552 | genlmsg_end(msg, hdr); |
| 11553 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11554 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11555 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11556 | return; |
| 11557 | |
| 11558 | nla_put_failure: |
| 11559 | genlmsg_cancel(msg, hdr); |
| 11560 | nlmsg_free(msg); |
| 11561 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11562 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11563 | |
| 11564 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11565 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 11566 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11567 | enum nl80211_radar_event event, |
| 11568 | struct net_device *netdev, gfp_t gfp) |
| 11569 | { |
| 11570 | struct sk_buff *msg; |
| 11571 | void *hdr; |
| 11572 | |
| 11573 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11574 | if (!msg) |
| 11575 | return; |
| 11576 | |
| 11577 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 11578 | if (!hdr) { |
| 11579 | nlmsg_free(msg); |
| 11580 | return; |
| 11581 | } |
| 11582 | |
| 11583 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 11584 | goto nla_put_failure; |
| 11585 | |
| 11586 | /* NOP and radar events don't need a netdev parameter */ |
| 11587 | if (netdev) { |
| 11588 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 11589 | |
| 11590 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11591 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11592 | goto nla_put_failure; |
| 11593 | } |
| 11594 | |
| 11595 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 11596 | goto nla_put_failure; |
| 11597 | |
| 11598 | if (nl80211_send_chandef(msg, chandef)) |
| 11599 | goto nla_put_failure; |
| 11600 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11601 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11602 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11603 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11604 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 11605 | return; |
| 11606 | |
| 11607 | nla_put_failure: |
| 11608 | genlmsg_cancel(msg, hdr); |
| 11609 | nlmsg_free(msg); |
| 11610 | } |
| 11611 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11612 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 11613 | const u8 *peer, u32 num_packets, gfp_t gfp) |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11614 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11615 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11616 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11617 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11618 | struct sk_buff *msg; |
| 11619 | struct nlattr *pinfoattr; |
| 11620 | void *hdr; |
| 11621 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11622 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 11623 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11624 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11625 | if (!msg) |
| 11626 | return; |
| 11627 | |
| 11628 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 11629 | if (!hdr) { |
| 11630 | nlmsg_free(msg); |
| 11631 | return; |
| 11632 | } |
| 11633 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11634 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11635 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11636 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) |
| 11637 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11638 | |
| 11639 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); |
| 11640 | if (!pinfoattr) |
| 11641 | goto nla_put_failure; |
| 11642 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11643 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 11644 | goto nla_put_failure; |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11645 | |
| 11646 | nla_nest_end(msg, pinfoattr); |
| 11647 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 11648 | genlmsg_end(msg, hdr); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11649 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11650 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11651 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11652 | return; |
| 11653 | |
| 11654 | nla_put_failure: |
| 11655 | genlmsg_cancel(msg, hdr); |
| 11656 | nlmsg_free(msg); |
| 11657 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 11658 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
Johannes Berg | c063dbf | 2010-11-24 08:10:05 +0100 | [diff] [blame] | 11659 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11660 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
| 11661 | u64 cookie, bool acked, gfp_t gfp) |
| 11662 | { |
| 11663 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11664 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11665 | struct sk_buff *msg; |
| 11666 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11667 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11668 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 11669 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 11670 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11671 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11672 | if (!msg) |
| 11673 | return; |
| 11674 | |
| 11675 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 11676 | if (!hdr) { |
| 11677 | nlmsg_free(msg); |
| 11678 | return; |
| 11679 | } |
| 11680 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11681 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11682 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11683 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 11684 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || |
| 11685 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 11686 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11687 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11688 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11689 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11690 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11691 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 11692 | return; |
| 11693 | |
| 11694 | nla_put_failure: |
| 11695 | genlmsg_cancel(msg, hdr); |
| 11696 | nlmsg_free(msg); |
| 11697 | } |
| 11698 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 11699 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11700 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
| 11701 | const u8 *frame, size_t len, |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11702 | int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11703 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11704 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11705 | struct sk_buff *msg; |
| 11706 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11707 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11708 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 11709 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 11710 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11711 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11712 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 11713 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 11714 | if (!msg) { |
| 11715 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11716 | return; |
| 11717 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11718 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11719 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 11720 | if (!hdr) |
| 11721 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11722 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11723 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11724 | (freq && |
| 11725 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 11726 | (sig_dbm && |
| 11727 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 11728 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 11729 | goto nla_put_failure; |
| 11730 | |
| 11731 | genlmsg_end(msg, hdr); |
| 11732 | |
| 11733 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11734 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11735 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11736 | return; |
| 11737 | |
| 11738 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11739 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 11740 | if (hdr) |
| 11741 | genlmsg_cancel(msg, hdr); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11742 | nlmsg_free(msg); |
| 11743 | } |
| 11744 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); |
| 11745 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11746 | #ifdef CONFIG_PM |
| 11747 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 11748 | struct cfg80211_wowlan_wakeup *wakeup, |
| 11749 | gfp_t gfp) |
| 11750 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11751 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11752 | struct sk_buff *msg; |
| 11753 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11754 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11755 | |
| 11756 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 11757 | |
| 11758 | if (wakeup) |
| 11759 | size += wakeup->packet_present_len; |
| 11760 | |
| 11761 | msg = nlmsg_new(size, gfp); |
| 11762 | if (!msg) |
| 11763 | return; |
| 11764 | |
| 11765 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 11766 | if (!hdr) |
| 11767 | goto free_msg; |
| 11768 | |
| 11769 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11770 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 11771 | goto free_msg; |
| 11772 | |
| 11773 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 11774 | wdev->netdev->ifindex)) |
| 11775 | goto free_msg; |
| 11776 | |
| 11777 | if (wakeup) { |
| 11778 | struct nlattr *reasons; |
| 11779 | |
| 11780 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 11781 | if (!reasons) |
| 11782 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11783 | |
| 11784 | if (wakeup->disconnect && |
| 11785 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 11786 | goto free_msg; |
| 11787 | if (wakeup->magic_pkt && |
| 11788 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 11789 | goto free_msg; |
| 11790 | if (wakeup->gtk_rekey_failure && |
| 11791 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 11792 | goto free_msg; |
| 11793 | if (wakeup->eap_identity_req && |
| 11794 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 11795 | goto free_msg; |
| 11796 | if (wakeup->four_way_handshake && |
| 11797 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 11798 | goto free_msg; |
| 11799 | if (wakeup->rfkill_release && |
| 11800 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 11801 | goto free_msg; |
| 11802 | |
| 11803 | if (wakeup->pattern_idx >= 0 && |
| 11804 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 11805 | wakeup->pattern_idx)) |
| 11806 | goto free_msg; |
| 11807 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11808 | if (wakeup->tcp_match && |
| 11809 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 11810 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11811 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11812 | if (wakeup->tcp_connlost && |
| 11813 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 11814 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11815 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11816 | if (wakeup->tcp_nomoretokens && |
| 11817 | nla_put_flag(msg, |
| 11818 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 11819 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11820 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11821 | if (wakeup->packet) { |
| 11822 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 11823 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 11824 | |
| 11825 | if (!wakeup->packet_80211) { |
| 11826 | pkt_attr = |
| 11827 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 11828 | len_attr = |
| 11829 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 11830 | } |
| 11831 | |
| 11832 | if (wakeup->packet_len && |
| 11833 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 11834 | goto free_msg; |
| 11835 | |
| 11836 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 11837 | wakeup->packet)) |
| 11838 | goto free_msg; |
| 11839 | } |
| 11840 | |
| 11841 | nla_nest_end(msg, reasons); |
| 11842 | } |
| 11843 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11844 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11845 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11846 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11847 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 11848 | return; |
| 11849 | |
| 11850 | free_msg: |
| 11851 | nlmsg_free(msg); |
| 11852 | } |
| 11853 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 11854 | #endif |
| 11855 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11856 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 11857 | enum nl80211_tdls_operation oper, |
| 11858 | u16 reason_code, gfp_t gfp) |
| 11859 | { |
| 11860 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11861 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11862 | struct sk_buff *msg; |
| 11863 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11864 | |
| 11865 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 11866 | reason_code); |
| 11867 | |
| 11868 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 11869 | if (!msg) |
| 11870 | return; |
| 11871 | |
| 11872 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 11873 | if (!hdr) { |
| 11874 | nlmsg_free(msg); |
| 11875 | return; |
| 11876 | } |
| 11877 | |
| 11878 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11879 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 11880 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 11881 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 11882 | (reason_code > 0 && |
| 11883 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 11884 | goto nla_put_failure; |
| 11885 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11886 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11887 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11888 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11889 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 11890 | return; |
| 11891 | |
| 11892 | nla_put_failure: |
| 11893 | genlmsg_cancel(msg, hdr); |
| 11894 | nlmsg_free(msg); |
| 11895 | } |
| 11896 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 11897 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11898 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 11899 | unsigned long state, |
| 11900 | void *_notify) |
| 11901 | { |
| 11902 | struct netlink_notify *notify = _notify; |
| 11903 | struct cfg80211_registered_device *rdev; |
| 11904 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11905 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11906 | |
| 11907 | if (state != NETLINK_URELEASE) |
| 11908 | return NOTIFY_DONE; |
| 11909 | |
| 11910 | rcu_read_lock(); |
| 11911 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11912 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 11913 | bool schedule_destroy_work = false; |
| 11914 | |
| 11915 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11916 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11917 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 11918 | if (wdev->owner_nlportid == notify->portid) |
| 11919 | schedule_destroy_work = true; |
| 11920 | } |
| 11921 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 11922 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 11923 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 11924 | list) { |
| 11925 | if (reg->nlportid == notify->portid) { |
| 11926 | list_del(®->list); |
| 11927 | kfree(reg); |
| 11928 | break; |
| 11929 | } |
| 11930 | } |
| 11931 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 11932 | |
| 11933 | if (schedule_destroy_work) { |
| 11934 | struct cfg80211_iface_destroy *destroy; |
| 11935 | |
| 11936 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); |
| 11937 | if (destroy) { |
| 11938 | destroy->nlportid = notify->portid; |
| 11939 | spin_lock(&rdev->destroy_list_lock); |
| 11940 | list_add(&destroy->list, &rdev->destroy_list); |
| 11941 | spin_unlock(&rdev->destroy_list_lock); |
| 11942 | schedule_work(&rdev->destroy_work); |
| 11943 | } |
| 11944 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 11945 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11946 | |
| 11947 | rcu_read_unlock(); |
| 11948 | |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 11949 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11950 | } |
| 11951 | |
| 11952 | static struct notifier_block nl80211_netlink_notifier = { |
| 11953 | .notifier_call = nl80211_netlink_notify, |
| 11954 | }; |
| 11955 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11956 | void cfg80211_ft_event(struct net_device *netdev, |
| 11957 | struct cfg80211_ft_event_params *ft_event) |
| 11958 | { |
| 11959 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 11960 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11961 | struct sk_buff *msg; |
| 11962 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11963 | |
| 11964 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 11965 | |
| 11966 | if (!ft_event->target_ap) |
| 11967 | return; |
| 11968 | |
| 11969 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11970 | if (!msg) |
| 11971 | return; |
| 11972 | |
| 11973 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11974 | if (!hdr) |
| 11975 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11976 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11977 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 11978 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 11979 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 11980 | goto out; |
| 11981 | |
| 11982 | if (ft_event->ies && |
| 11983 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 11984 | goto out; |
| 11985 | if (ft_event->ric_ies && |
| 11986 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 11987 | ft_event->ric_ies)) |
| 11988 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11989 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 11990 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11991 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 11992 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 11993 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 11994 | return; |
| 11995 | out: |
| 11996 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 11997 | } |
| 11998 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 11999 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12000 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 12001 | { |
| 12002 | struct cfg80211_registered_device *rdev; |
| 12003 | struct sk_buff *msg; |
| 12004 | void *hdr; |
| 12005 | u32 nlportid; |
| 12006 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12007 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 12008 | if (!rdev->crit_proto_nlportid) |
| 12009 | return; |
| 12010 | |
| 12011 | nlportid = rdev->crit_proto_nlportid; |
| 12012 | rdev->crit_proto_nlportid = 0; |
| 12013 | |
| 12014 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12015 | if (!msg) |
| 12016 | return; |
| 12017 | |
| 12018 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 12019 | if (!hdr) |
| 12020 | goto nla_put_failure; |
| 12021 | |
| 12022 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12023 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12024 | goto nla_put_failure; |
| 12025 | |
| 12026 | genlmsg_end(msg, hdr); |
| 12027 | |
| 12028 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 12029 | return; |
| 12030 | |
| 12031 | nla_put_failure: |
| 12032 | if (hdr) |
| 12033 | genlmsg_cancel(msg, hdr); |
| 12034 | nlmsg_free(msg); |
| 12035 | |
| 12036 | } |
| 12037 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 12038 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 12039 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 12040 | { |
| 12041 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 12042 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 12043 | struct sk_buff *msg; |
| 12044 | void *hdr; |
| 12045 | |
| 12046 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12047 | if (!msg) |
| 12048 | return; |
| 12049 | |
| 12050 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 12051 | if (!hdr) |
| 12052 | goto out; |
| 12053 | |
| 12054 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12055 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
| 12056 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
| 12057 | goto out; |
| 12058 | |
| 12059 | genlmsg_end(msg, hdr); |
| 12060 | |
| 12061 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 12062 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 12063 | return; |
| 12064 | out: |
| 12065 | nlmsg_free(msg); |
| 12066 | } |
| 12067 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12068 | /* initialisation/exit functions */ |
| 12069 | |
| 12070 | int nl80211_init(void) |
| 12071 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 12072 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12073 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 12074 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
| 12075 | nl80211_mcgrps); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12076 | if (err) |
| 12077 | return err; |
| 12078 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12079 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 12080 | if (err) |
| 12081 | goto err_out; |
| 12082 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12083 | return 0; |
| 12084 | err_out: |
| 12085 | genl_unregister_family(&nl80211_fam); |
| 12086 | return err; |
| 12087 | } |
| 12088 | |
| 12089 | void nl80211_exit(void) |
| 12090 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 12091 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 12092 | genl_unregister_family(&nl80211_fam); |
| 12093 | } |